Skip to content

Prompt 模板 ​

Prompt 模板是 Markdown 代码片段,可展开为完整提示。在编辑器中输入 /name 即可调用模板,其中 name 是去掉 .md 的文件名。

位置 ​

Pi 从以下位置加载提示模板:

  • 全局:~/.pi/agent/prompts/*.md
  • 项目:.pi/prompts/*.md
  • 包:prompts/ 目录或 package.json 中的 pi.prompts 条目
  • 设置:prompts 数组包含文件或目录
  • CLI:--prompt-template <path>(可重复)

使用 --no-prompt-templates 禁用发现。

格式 ​

markdown
---
description: Review staged git changes
---
Review the staged changes (`git diff --cached`). Focus on:
- Bugs and logic errors
- Security issues
- Error handling gaps
  • 文件名变为命令名称。review.md 变成 /review。
  • description 是可选的。如果缺失,则使用第一个非空行。
  • argument-hint 是可选的。设置时,提示会在自动补全下拉框中显示在描述之前。

参数提示 ​

在 frontmatter 中使用 argument-hint 在自动补全中显示预期参数。使用 <尖括号> 表示必需参数,[方括号] 表示可选参数:

markdown
---
description: Review PRs from URLs with structured issue and code analysis
argument-hint: "<PR-URL>"
---

这会在自动补全下拉框中渲染为:

→ pr   <PR-URL>       — Review PRs from URLs with structured issue and code analysis
  is   <issue>        — Analyze GitHub issues (bugs or feature requests)
  wr   [instructions] — Finish the current task end-to-end
  cl   — Audit changelog entries before release

使用 ​

在编辑器中输入 / 后跟模板名称。自动补全会显示可用的模板及其描述。

/review                           # 展开 review.md
/component Button                 # 带参数的展开
/component Button "click handler" # 多个参数

参数 ​

模板支持位置参数和简单切片:

  • $1、$2... 位置参数
  • $@ 或 $ARGUMENTS 表示所有参数连接
  • ${@:N} 表示从第 N 个位置开始的参数(1 索引)
  • ${@:N:L} 表示从 N 开始的 L 个参数

示例:

markdown
---
description: Create a component
---
Create a React component named $1 with features: $@

使用:/component Button "onClick handler" "disabled support"

加载规则 ​

  • prompts/ 中的模板发现是非递归的。
  • 如果想加载子目录中的模板,请通过 prompts 设置或包清单显式添加。

Pi 编码助手中文文档