This repository is @czottmann/pi-automode, a Pi extension package that implements Claude Code-style auto mode guardrails. The extension intercepts Pi agent tool calls before execution and blocks actions through permission rules, deterministic hard-deny checks, protected-path handling, and an LLM classifier.
This is not a sandbox. Do not describe it as one.
extensions/auto-mode.ts— main extension implementation and exported testable helpers.tests/auto-mode.test.ts— Node test suite for config merging, permission matching, hard-deny checks, classifier parsing, and hook behavior.examples/automode.local.json— example user/project-local configuration.README.md— user-facing documentation and install/config reference.package.json— npm package metadata, Pi manifest, scripts, peer/dev dependencies.
Track issues in GitHub. Use the gh CLI for issue operations.
GitHub Issues has no Draft state. Create captured tickets as open issues and state that they are Drafts in the description.
Use bug for defects, enhancement for behavior changes, and documentation for documentation-only work.
Run these before handing off code changes:
npm run check
npm testFor package/release-sensitive changes, also run:
npm pack --dry-runnpm run build is currently an alias for TypeScript no-emit checking.
- TypeScript is strict, ESM, NodeNext (
tsconfig.json). - Keep code simple and explicit. Avoid abstractions unless multiple call sites justify them.
- Prefer exported pure helpers for logic that needs tests.
- Keep deterministic hard-deny logic independent from classifier behavior where possible.
- Fail closed for safety decisions: missing classifier, invalid classifier output, or hook errors should block rather than allow risky actions.
- Preserve Pi tool names in lowercase in docs and config examples:
bash(...),write(...),edit(...),read(...),find(...),ls(...). - Do not add runtime dependencies unless necessary. Pi core imports belong in
peerDependencieswith"*"; development versions belong indevDependencies.
Use red/green TDD for behavior changes: first add or update a test that demonstrates the missing behavior, then implement the smallest passing change.
When changing guardrail behavior, add or update tests in tests/auto-mode.test.ts for:
- config precedence and diagnostics;
- permission pattern parsing/matching;
- deterministic hard-deny checks;
- protected-path behavior, including symlinks or cross-project paths when relevant;
- classifier decision parsing and fail-closed behavior;
tool_callhook ordering: permissions first, deterministic hard-deny second, read-only bypass, classifier last.
Bug fixes to blocking/allowing behavior need tests that prove the observed behavior is fixed.
This project is itself a safety-control extension. Treat these areas as high risk:
- hard-deny rules and deterministic checks;
- config-source precedence, especially shared project
.pi/automode.jsonnot weakeningautoMode; - classifier prompt semantics;
- protected-path matching;
- shell parsing and command classification;
- permission deny/ask handling.
Do not weaken safety behavior, broaden allow rules, or bypass classifier checks without explicit user direction and tests. Changes to docs must not imply guarantees the extension does not provide.
Before editing Pi extension APIs, command/UI behavior, tool hooks, package metadata, or package install behavior, consult the installed Pi docs:
docs/extensions.mddocs/packages.md- relevant files under
examples/extensions/
Key Pi API constraints used by this project:
tool_callcan block by returning{ block: true, reason }.event.inputis mutable, but this extension should generally classify the requested action rather than mutate it.- Use
ctx.hasUI/ctx.modebefore UI-only behavior. - Use
ctx.signalfor nested model calls or async work during active turns. pi.appendEntry()persists extension state outside LLM context; restore fromctx.sessionManageronsession_start.
- Keep
README.mduser-facing and concrete. - Keep security wording precise: this extension reduces unsafe autonomous tool use; it is not an OS-level security boundary.
- When adding config examples, include
$defaultsunless the example is intentionally demonstrating replacement behavior. - Keep command lists and examples in sync with
extensions/auto-mode.ts.
- Check
git status --shortbefore committing or making broad edits. - Do not overwrite unrelated user changes.
- Do not edit
.envfiles or local Pi auto-mode config unless explicitly asked. - Commit only when explicitly asked.