Pi 官方文档
提示词模板
pi 可以创建提示词模板。让它为你的工作流搭一个。
提示词模板
提示词模板是一些 Markdown 片段,会展开成完整的 prompt。 在编辑器里输入 /name 来调用模板,其中 name 是去掉 .md 后的文件名。
位置
Pi 会从这些位置加载提示词模板:
- 全局:
~/.pi/agent/prompts/*.md - 项目:
.pi/prompts/*.md(只有在项目被信任后才会加载) - Packages:
prompts/目录,或package.json里的pi.prompts条目 - Settings:包含文件或目录的
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是可选的。设置后,自动补全下拉框里会先显示这个提示,再显示描述。
参数提示
在 frontmatter 里使用 argument-hint,可以在自动补全中显示预期参数。必填参数用 <angle brackets>,可选参数用 [square brackets]:
---
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 # 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设置或 Package 清单显式添加。