提示模板
pi 可以创建提示模板。请它为你的工作流构建一个。
提示模板是扩展为完整提示的 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 禁用发现。
---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可选。设置后,提示会在自动完成下拉菜单中显示在 description 之前。
在前言中使用 argument-hint 在自动完成中显示预期参数。必填参数用 <尖括号>,可选参数用 [方括号]:
---description: Review PRs from URLs with structured issue and code analysisargument-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 # Expands review.md/component Button # Expands with argument/component Button "click handler" # Multiple arguments模板支持位置参数、默认值和简单切片:
$1、$2、… 位置参数$@或$ARGUMENTS表示所有参数拼接${1:-default}当参数 1 存在且非空时使用,否则用default${@:N}从第 N 个位置起的参数(1 索引)${@:N:L}从 N 开始的 L 个参数
示例:
---description: Create a component---Create a React component named $1 with features: $@默认值对可选参数很有用:
Summarize the current state in ${1:-7} bullet points.用法:/component Button "onClick handler" "disabled support"
prompts/中的模板发现是非递归的。- 若要在子目录中使用模板,请通过
prompts设置或包清单显式添加。