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 設定或包清單顯式新增它們。