@czottmann/pi-automode

中文文档
1.17.0发布于 2026/09/22MITES Module构建来源已验证近 30 天下载 2552

Claude Code-style auto mode guardrail for pi.

原始使用文档
文档目录13 节
  1. Compatibility
  2. Install
  3. Commands
  4. Agent diagnostics
  5. Status line
  6. Docs
  7. What runs before the classifier
  8. Examples
  9. Known limits
  10. Development
  11. Publishing
  12. Release tag must point at the version bump
  13. Author

pi-automode

Claude Code-style auto mode for Pi.

This is a guardrail extension. It intercepts agent tool calls before execution and blocks actions that match permission deny rules, deterministic hard-deny checks, or the auto-mode classifier's block decision.

It is not a sandbox. Extensions run in the Pi process. A malicious extension can do anything that your user account can do.

Pi-automode does not guard user ! or !! shell commands. It guards only agent tool calls. Use it to reduce unsafe autonomous tool use. Do not use it as an OS security boundary.

Compatibility

Pi-automode supports Pi and Oh My Pi (OMP) 18. It automatically uses OMP's legacy completion API. The integration needs no OMP-specific configuration.

Install

From npm:

pi install npm:@czottmann/pi-automode

From a local checkout:

pi install .

For one run from a local checkout:

pi -e ./extensions/auto-mode.ts

Commands

/automode status    # current state, rules, and classifier
/automode on        # re-enable for this session
/automode off       # disable for this session
/automode reload    # reload config from disk
/automode reset     # reset denial counters only
/automode defaults  # print the built-in rule lists
/automode config    # effective config, resolved log file path, + diagnostics
/automode denials   # denial history for this session
/automode model     # open classifier model selector and save to ~/.pi/agent/extensions/pi-automode/config.json
/automode model provider/model-id # save classifier model to ~/.pi/agent/extensions/pi-automode/config.json

/auto-mode is an alias.

Agent diagnostics

The package registers one model-callable, read-only tool:

automode_inspect accepts one action:

  • status: active state and counters
  • config: active effective configuration, log path, and diagnostics
  • defaults: built-in rule lists
  • denials: recent denial timestamps, kinds, and tool names

The tool reads the same in-memory configuration and state that the guardrail enforces. Permission and deterministic checks run before the bypass.

The bypass does not change automode counters, persisted state, or observability logs. The extension verifies the source of the tool before it applies the exemption. Thus, a name collision does not exempt a tool from another extension.

The tool cannot enable or disable auto mode. It cannot reload configuration, reset state, select a model, or change configuration.

Pi sends tool output to the current model. The status and denials views omit denial reasons and action payloads.

If a diagnosis requires a reason, inspect a known-safe entry in the local observability log. The config view includes effective rule text. It removes raw JSON parser details from diagnostics.

Do not put credentials or other secrets in automode rules.

The bundled automode-diagnostics skill uses this tool to diagnose unexpected decisions without asking the user to copy output from slash commands. Configuration edits and automode state changes remain user-controlled. See Agent diagnostics for the inspection contract, privacy limits, and diagnosis workflow.

Status line

When the Pi TUI is available, the extension renders a persistent status line:

AM ● a:12 d:2 ca:5 cd:1
  • AM — auto-mode prefix. ● means enabled. ○ means disabled through configuration or /automode off.
  • a: — actions allowed so far (checked minus denied).
  • d: — actions denied so far, for any reason (permission rule, deterministic hard-deny, or classifier).
  • ca: / cd: — classifier decisions split into allowed and denied. These segments appear after the first classifier call. d: counts all denials, so d: is always >= cd:.

Docs

What runs before the classifier

The extension blocks these before any allow or classifier decision:

  • permissions.deny matches
  • declined permissions.ask matches
  • shell profile writes
  • SSH authorized_keys writes
  • cron, launch agent, and system service persistence
  • TLS/certificate/auth weakening patterns
  • root, home, and system-path destructive deletes. Subtrees of validated launcher-declared temp directories are treated as disposable. Declared roots that alias HOME, /, or a system root, or that contain HOME, are rejected instead.
  • edits to .pi/automode*, .pi auto-mode files, and this extension's safety-control files

After these checks, pi-automode applies permissions.allow. Protected write and edit targets continue to the classifier.

Accepted ask rules also continue to the classifier. They cannot use an allow tier. Pi-automode then allows the read-only tools read, grep, find, and ls. Every remaining action goes to the classifier.

A permissions.allow rule intentionally skips classifier policy, including classifier hard_deny rules. Use narrow patterns and user-owned configuration. Deterministic hard-deny and path controls remain unconditional.

Set classifyReadOnlyTools: true (default false) to route read-only tools through the classifier. This configuration value increases model calls, latency, and session cost.

Pi-automode blocks a deniedPaths match before classifier review or an allow tier. Thus, file tools cannot send matching secret or system paths to the model.

The list does not govern bash. The classifier and deterministic hard-deny checks govern shell access to these paths.

The value allowInsideWorkingDirectory: true allows file access inside the working directory locally. Pi-automode sends all outside file access to the classifier, including reads.

Classification starts with a conservative one-token filter. If the filter requests review, pi-automode requests one internal classifier_decision tool call.

The tool exists only in the nested classifier request. It is not registered with pi.registerTool(), and the main agent cannot call it.

Pi AI requests schema-constrained sampling with strict: "prefer". Supported providers enforce the schema during generation. Pi-automode validates every returned tool call locally.

Both stages receive the complete current tool input in a dedicated message. Transcript truncation cannot remove action content. If the exact input cannot fit in the classifier context, auto mode blocks the call.

Both stages use a classifier-specific session key. They request short cache retention from providers that support it. A missing model, provider failure, or invalid response blocks the action. Pi-automode parses Bash structure with unbash before permission and deterministic hard-deny checks. The analysis includes nested commands and literal shell-wrapper scripts. A Bash parse error blocks the action.

Examples

  • examples/automode.local.json: copy to .pi/automode.local.json in a project and edit the domains, buckets, and source-control org.
  • Permission recipes: use narrow examples for common permission and classifier-policy changes.

Known limits

Claude Code's real classifier and exact built-in rules are private. This package implements the documented precedence and configuration behavior, with a local classifier prompt and deterministic hard-deny checks.

Development

npm run check
npm test
npm pack --dry-run

The tests cover these safety-sensitive areas:

  • scoped permission matching
  • the permissions.allow tier and its precedence
  • configuration-source precedence and diagnostics
  • $defaults behavior
  • deterministic hard-deny checks and Bash AST analysis
  • classifier routing for write and edit
  • symlink-aware safety-control checks
  • token-budgeted transcript selection
  • staged classifier tool-call parsing and cache behavior
  • hook-level allow and block behavior

Publishing

When a maintainer publishes a GitHub Release, GitHub Actions publishes the package to npm. The required release tag format is v<version>. The <version> value must be the same as the version in package.json. For example, version 1.0.0 requires tag v1.0.0.

The workflow uses npm Trusted Publishing, so it does not need an npm token secret. Configure this package on npm with this repository and workflow file (.github/workflows/publish.yml). The workflow builds the package, runs npm run check, and publishes with npm provenance.

Release tag must point at the version bump

The publish workflow checks the commit that the release tag identifies. It compares the version in package.json with the tag name.

The tag must identify a commit that contains the new version.

  1. Commit the version change with chore: release X.Y.Z.
  2. Push main.
  3. Create the GitHub release from that commit.

If the tag identifies an older version, the Check release tag step fails. It reports Release tag (vX.Y.Z) does not match package.json version (x.y.z).

CAUTION: Do not move a correct release tag. Moving the tag changes a published reference.

  1. If the tag identifies the wrong commit, force-move it to the version-change commit.
  2. Force-push the corrected tag.
  3. Run gh workflow run publish.yml --ref vX.Y.Z.

When GitHub creates the tag, the release event occurs. A rerun of a failed release workflow uses the original reference. It does not use the moved tag.

Author

Carlo Zottmann, [email protected]

版本与发布记录

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

版本发布日期距今
1.17.0latest2026/09/221 个月前
1.16.02026/09/082 个月前
1.15.02026/08/282 个月前
1.14.02026/08/272 个月前
1.13.02026/08/262 个月前
1.12.02026/08/242 个月前

关于 @czottmann/pi-automode 的常见问题

@czottmann/pi-automode 是什么?

Claude Code-style auto mode guardrail for pi.

如何安装 @czottmann/pi-automode?

在项目目录运行 npm install @czottmann/pi-automode,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typebox(*)、@earendil-works/pi-ai(*)、@earendil-works/pi-tui(*)、@earendil-works/pi-coding-agent(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@czottmann/pi-automode 支持 TypeScript 吗?

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

@czottmann/pi-automode 支持 ESM 还是 CommonJS?

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

@czottmann/pi-automode 可以商用吗?

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

@czottmann/pi-automode 的下载量有多少?

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

@czottmann/pi-automode 还在维护吗?

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