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

Prompt Templates

pi 可以创建 prompt templates。要求它为您的工作流程构建一个。

提示模板是 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 设置或包清单显式添加它们。