Pi 包
pi 可以创建 pi 包。请它为你的用例构建一个。
Pi 包将扩展、技能、提示模板和主题打包,以便通过 npm 或 git 分享。包可在 package.json 的 pi 键下声明资源,或使用约定目录。
安全: Pi 包以完整系统权限运行。扩展执行任意代码,技能可指示模型执行任何操作,包括运行可执行文件。安装第三方包前请审查源代码。
pi install git:github.com/user/repo@v1pi install https://github.com/user/repo # raw URLs work toopi install /absolute/path/to/packagepi install ./relative/path/to/package
pi remove npm:@foo/barpi list # show installed packages from settingspi update # update pi onlypi update --all # update pi, update packages, and reconcile pinned git refspi update --extensions # update packages and reconcile pinned git refs onlypi update --self # update pi onlypi update --self --force # reinstall pi even if currentpi update npm:@foo/bar # update one packagepi update --extension npm:@foo/bar这些命令管理 pi 包,pi update 也可更新 pi CLI 安装。要卸载 pi 本身,请参阅快速开始。
默认情况下,install 和 remove 写入用户设置(~/.pi/agent/settings.json)。使用 -l 写入项目设置(.pi/settings.json)。项目设置可与团队共享,项目受信任后 pi 会在启动时自动安装缺失的包。
要在不安装的情况下试用包,使用 --extension 或 -e。这仅将包安装到当前运行的临时目录:
pi -e npm:@foo/barpi -e git:github.com/user/repoPi 在设置和 pi install 中接受三种来源类型。
npm:@scope/[email protected]npm:pkg- 带版本的 spec 会被固定,包更新(
pi update --extensions、pi update --all)会跳过。 - 用户安装位于
~/.pi/agent/npm/。 - 项目安装位于
.pi/npm/。 - 在
settings.json中设置npmCommand可将 npm 包查找和安装操作固定到特定包装命令,如mise或asdf。
示例:
{ "npmCommand": ["mise", "exec", "node@20", "--", "npm"]}git:github.com/user/repo@v1git:[email protected]:user/repo@v1https://github.com/user/repo@v1ssh://[email protected]/user/repo@v1- 无
git:前缀时,仅接受协议 URL(https://、http://、ssh://、git://)。 - 有
git:前缀时,接受简写格式,包括github.com/user/repo和[email protected]:user/repo。 - 支持 HTTPS 和 SSH URL。
- SSH URL 自动使用你配置的 SSH 密钥(遵循
~/.ssh/config)。 - 对于非交互运行(如 CI),可设置
GIT_TERMINAL_PROMPT=0禁用凭证提示,并设置GIT_SSH_COMMAND(如ssh -o BatchMode=yes -o ConnectTimeout=5)以快速失败。 - ref 为固定的 tag 或 commit。
pi update --extensions和pi update --all不会将其移到新 ref,但会协调现有克隆到配置的 ref。 - 使用
pi install git:host/user/repo@new-ref更新设置并将现有包移到新固定 ref。 - 克隆到
~/.pi/agent/git/<host>/<path>(全局)或.pi/git/<host>/<path>(项目)。 - 协调更改检出时,pi 会 reset 并 clean 克隆,若存在
package.json则运行npm install。
SSH 示例:
# git@host:path shorthand (requires git: prefix)
# ssh:// protocol format
# With version ref/absolute/path/to/package./relative/path/to/package本地路径指向磁盘上的文件或目录,添加到设置时不复制。相对路径相对于其所在的设置文件解析。若路径是文件,则作为单个扩展加载。若是目录,pi 使用包规则加载资源。
创建 Pi 包
Section titled “创建 Pi 包”在 package.json 中添加 pi 清单或使用约定目录。包含 pi-package 关键词以便被发现。
{ "name": "my-package", "keywords": ["pi-package"], "pi": { "extensions": ["./extensions"], "skills": ["./skills"], "prompts": ["./prompts"], "themes": ["./themes"] }}路径相对于包根目录。数组支持 glob 模式和 !exclusions。
包画廊 显示标记为 pi-package 的包。添加 video 或 image 字段以显示预览:
{ "name": "my-package", "keywords": ["pi-package"], "pi": { "extensions": ["./extensions"], "video": "https://example.com/demo.mp4", "image": "https://example.com/screenshot.png" }}- video:仅 MP4。桌面端悬停时自动播放。点击打开全屏播放器。
- image:PNG、JPEG、GIF 或 WebP。显示为静态预览。
若两者都设置,video 优先。
若无 pi 清单,pi 从这些目录自动发现资源:
extensions/加载.ts和.js文件skills/递归查找SKILL.md文件夹,并将顶层.md文件作为技能加载prompts/加载.md文件themes/加载.json文件
第三方运行时依赖应放在 package.json 的 dependencies 中。不注册扩展、技能、提示模板或主题的依赖也属于 dependencies。pi 从 npm 或 git 安装包时会运行 npm install,因此这些依赖会自动安装。
Pi 为扩展和技能打包核心包。若你导入以下任一包,请在 peerDependencies 中列出并设 "*" 范围,不要打包它们:@earendil-works/pi-ai、@earendil-works/pi-agent-core、@earendil-works/pi-coding-agent、@earendil-works/pi-tui、typebox。
其他 pi 包必须打包在你的 tarball 中。将它们加入 dependencies 和 bundledDependencies,然后通过 node_modules/ 路径引用其资源。Pi 使用独立模块根加载包,因此独立安装不会冲突或共享模块。
示例:
{ "dependencies": { "shitty-extensions": "^1.0.1" }, "bundledDependencies": ["shitty-extensions"], "pi": { "extensions": ["extensions", "node_modules/shitty-extensions/extensions"], "skills": ["skills", "node_modules/shitty-extensions/skills"] }}在设置中使用对象形式过滤包加载内容:
{ "packages": [ "npm:simple-pkg", { "source": "npm:my-package", "extensions": ["extensions/*.ts", "!extensions/legacy.ts"], "skills": [], "prompts": ["prompts/review.md"], "themes": ["+themes/legacy.json"] } ]}+path 和 -path 是相对于包根目录的精确路径。
- 省略键则加载该类型的全部。
- 使用
[]则不加载该类型的任何内容。 !pattern排除匹配项。+path强制包含精确路径。-path强制排除精确路径。- 过滤器在清单之上叠加,缩小已允许的内容。
启用与禁用资源
Section titled “启用与禁用资源”使用 pi config 启用或禁用已安装包和本地目录中的扩展、技能、提示模板和主题。适用于全局(~/.pi/agent)和项目(.pi/)作用域。
作用域与去重
Section titled “作用域与去重”包可出现在全局和项目设置中。若同一包出现在两者中,项目条目优先。身份由以下决定:
- npm:包名
- git:不含 ref 的仓库 URL
- local:解析后的绝对路径