Pi 的配置、扩展、平台设置和 API 参考。

Prompt Templates

pi 可以创建 Prompt Templates。可以让它为你的工作流生成一个模板。

Prompt Templates 是可扩展为完整 Prompt 的 Markdown 片段。在编辑器中输入 /name 即可调用模板,其中 name 是去掉 .md 后缀的文件名。

位置

Pi 从以下位置加载 Prompt Templates:

  • 全局:~/.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 是可选的。设置后,提示将显示在自动完成下拉列表中的描述之前。

参数提示

在 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} 使用 arg 1,否则 default
  • ${@:-default}${ARGUMENTS:-default} 在存在/非空时使用所有参数,否则 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 设置或包清单显式添加它们。