@aliou/pi-guardrails

中文文档
0.22.0发布于 2026/11/04MITES Module构建来源已验证近 30 天下载 5520

banner

原始使用文档
文档目录11 节
  1. Install
  2. First run
  3. Included extensions
  4. guardrails
  5. path-access
  6. permission-gate
  7. herdr
  8. Extension events
  9. Configuration
  10. Similar but different
  11. Development

banner

Guardrails

[!WARNING] I am not responsible for any issues, damage, or data loss caused by agents, even when using Guardrails. Guardrails is not a sandbox and does not guarantee safety. You are responsible for adding and maintaining rules that prevent dangerous operations in your environment; do not rely on the defaults alone.

Guardrails adds safety checks to Pi so agents are less likely to read secrets, write protected files, access paths outside the workspace, or run dangerous shell commands by accident.

The package installs four Pi extensions:

  • guardrails — file protection policies, settings, onboarding, and examples.
  • path-access — controlling access outside the current workspace.
  • permission-gate — confirming or blocking risky shell commands.
  • herdr — reporting Guardrails approval prompts to Herdr.

Install

pi install npm:@aliou/pi-guardrails

First run

After installing, run the onboarding command to choose a starting setup: /guardrails:onboarding. You can change everything later with /guardrails:settings.

Guardrails onboarding walkthrough

Included extensions

guardrails

Protects files like .env, private keys, local credentials, database dumps, or any project-specific path you do not want Pi to read or modify without clear intent. Rules respect the current working directory by default and are configurable in the settings UI.

Guardrails policies and settings walkthrough

Use /guardrails:examples to add common policy and command presets without replacing your existing config.

Guardrails examples command walkthrough

path-access

Checks tool calls that target paths outside the current working directory. It can allow, block, or ask before Pi accesses files elsewhere on your machine; in ask mode, you can allow a file or a directory once, for the session, or always. By default, checks apply to both reads and writes outside the workspace, and "always" grants are saved to the project config — both are configurable through /guardrails:settings.

Guardrails path access prompt walkthrough

permission-gate

Detects dangerous bash commands before they run — recursive deletes, privileged commands, disk formatting, broad permission changes, and any custom patterns you configure. You can allow once, allow for the session, deny, or decline and stop, which also aborts the current turn. Auto-deny patterns can set terminate: true to end the agent's turn after blocking, so it does not retry the blocked command.

Command, policy, and path checks also look inside command and process substitutions, so a risky call wrapped in $(...) is still caught.

Guardrails permission gate walkthrough

herdr

The included Herdr adapter reports active Guardrails approval prompts through Herdr's herdr:blocked event, so Herdr can show the Pi pane as blocked while a prompt waits for a decision. It has no configuration and no effect unless Herdr's Pi integration is active.

Approval prompts also report blocked program status (OSC 7501) natively through the blocked option of ctx.ui.custom(), so terminals such as Rex show Pi as blocked while a prompt waits; no extension is needed for that anymore.

Extension events

Guardrails emits paired events on Pi's shared event bus: guardrails:prompt:opened when an interactive prompt starts waiting for input and guardrails:prompt:closed when it stops. Both carry the same prompt.id for correlation.

Configuration

Most configuration happens through the interactive settings UI (/guardrails:settings). Advanced users can edit the settings file directly:

  • Global: ~/.pi/agent/extensions/guardrails.json
  • Project: .pi/extensions/guardrails.json

Project settings apply only after Pi trusts the folder (/trust, then restart Pi). Until then, untrusted project files are ignored and left unchanged, while global settings and built-in protections still apply. Set pathAccess.alwaysScope to "global" to save "always" path grants without trusting the project.

Saved files include a $schema field for editor autocomplete and validation; the schema is committed at schema.json.

Similar but different

Pi is designed to make agent safety extensible. Guardrails focuses on deterministic, configurable file policies, path access control, and dangerous-command prompts. See pi.dev/packages for the full registry.

Closest alternatives:

You can also make your own: start from the Pi permission gate example and ask Pi to customize it for your workflow.

Development

pnpm test         # Run tests
pnpm test:watch   # Run tests in watch mode
pnpm typecheck    # Type check
pnpm lint         # Lint
pnpm format       # Format
pnpm gen:schema   # Regenerate schema.json
pnpm check:schema # Verify schema.json is current

版本与发布记录

@aliou/pi-guardrails 共发布 53 个版本,首次发布于 2026/01/26;过去 12 个月发布了 53 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.22.0latest2026/11/042 天前
0.21.02026/10/289 天前
0.20.02026/10/2413 天前
0.19.02026/09/261 个月前
0.18.12026/09/251 个月前
0.18.02026/09/181 个月前

其他发布通道:legacy → 0.1.0。

关于 @aliou/pi-guardrails 的常见问题

如何安装 @aliou/pi-guardrails?

在项目目录运行 npm install @aliou/pi-guardrails,或使用 pnpm add / yarn add / bun add。

@aliou/pi-guardrails 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aliou__pi-guardrails 是否存在。

@aliou/pi-guardrails 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aliou/pi-guardrails 可以商用吗?

@aliou/pi-guardrails 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aliou/pi-guardrails 的下载量有多少?

根据 npm 官方下载统计,@aliou/pi-guardrails 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,520 次,日均约 184 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aliou/pi-guardrails 还在维护吗?

最新版本 0.22.0 发布于 2026/11/04(2 天前);至今共发布 53 个版本,其中过去 12 个月发布了 53 个;首次发布于 2026/01/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。