跳至内容

提示模板

创建于 2025-07-16·更新于 2026-07-16

pi 可以创建提示模板。让它为你构建一个工作流模板。

提示模板是 Markdown 片段,会展开为完整的提示词。在编辑器中输入 /name 即可调用模板,其中 name 是不含 .md 扩展名的文件名。

位置 Locations

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

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

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

格式 Format

---
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 为可选字段。设置后,提示信息会显示在自动补全下拉菜单的描述之前。

参数提示 Argument Hints

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

---
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

用法 Usage

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

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

参数 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"

加载规则 Loading Rules

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