Repository navigation
chore(agents): run the push check in Pi - #136
Merged
Merged
Conversation
doistbot
reviewed
Nov 27, 2026
doistbot
left a comment
Member
There was a problem hiding this comment.
Clean port of the push check to Pi: the extension reuses .agents/scripts/guard.ts with the same payload and fail-open behaviour as the Claude Code and Codex hooks, catches its own errors so Pi can't turn one into a block, and is consistently wired into the tooling tsconfig, tests, and docs.
Few things worth tightening:
- Guard startup failures are silently allowed: if
guard.tsexits unsuccessfully (e.g. a syntax error), the handler converts the empty stdout to{}and discards stderr, so the push goes through without the promised note. Report the failed exit/signal as a diagnostic while keeping successful-but-empty output silent, and add a test that corruptsguard.tsitself. - The tests can't distinguish "skipped" from "started and failed": deleting the
existsSync(GUARD)check or thetoolName/MIGHT_PUSHearly returns still passes, since every failure path resolves to the sameundefined-with-no-notes shape. Pin the skip cases with a sentinel (e.g. a log file that must never be created), mirroring whathook-wiring.test.tsdoes with stubgit/nodescripts. - Minor test cleanup: the new test hand-rolls file creation that
TempRepo.writealready covers.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (4)
docs/agents.md:68: The per-agent enumeration drops Cursor: "Claude Code and Codex from their hook configs, Pi from a small extension". Cursor is still wired (it runs the Claude Code hooks, as the table two paragraphs down says), so the rewritten sentence reads as if only three agents are covered. Add Cursor to the list, e.g. "Claude Code and Codex from their hook configs, Cursor through the Claude Code hooks, Pi from a small extension".
.agents/scripts/pi-extension.test.ts:54:
mkdirSync+writeFileSynchere re-implementTempRepo.write, which already creates parent folders and is used a few lines up insetUp. Taking the targetTempRepoindriveinstead ofroot(defaulting to the module-levelrepo) would let this betarget.write('.tmp/event.json', JSON.stringify(event)), and drops the twonode:fsimports..agents/scripts/pi-extension.test.ts:156: The test suite covers every other fail-open branch of runGuard — failed to run, printed no JSON, exited before reading stdin — but not the timeout. The timeout is now the extension's own responsibility (Claude Code and Codex get their 30s timeout from their hook configs, e.g.
.claude/settings.json'stimeout: 30; Pi has no such setting), and docs/agents.md and the PR description both list "times out" as designed behavior. If the timer'sfinishcall regressed, the handler would await forever and hang every push-like tool call in Pi, and no existing test would notice. Since 30s can't be waited out, consider letting the test set a short timeout — e.g. have runGuard read an override likeAGENT_GUARD_TIMEOUT_MSfrom the environment (the isolated test env already manages agent-guard env vars) — and add one test asserting a hung guard produces the "timed out, so it allowed the action" note and lets the call through..pi/extensions/agent-guard.ts:71: The timeout note drops the guard's stderr, which the handler has been collecting the whole time. The no-JSON path at line 83 includes
stderr.trim()in its note so a broken guard explains itself, but a guard that hangs produces only "timed out, so it allowed the action" — the least actionable of the failure modes. Include the collected stderr in the timeout message the same way, so a hung guard (e.g. waiting on git) says what it printed before stalling.
scottlovegrove
force-pushed
the
scottl/agent-guard-pi
branch
from
November 27, 2026 14:04
911bc25 to
9575728
Compare
Runs the push check in Pi as well, ported from todoist/todoist-cli#673. Pi has no hook files, so .pi/extensions/agent-guard.ts listens to Pi's tool_call event: before a bash call that could push, it runs the same .agents/scripts/guard.ts the Claude Code and Codex hooks call, with the same JSON, and blocks the call with the guard's reason when it says no. It behaves like the other agents' hooks: DISABLE_AGENT_GUARD=1 turns it off, a checkout without the guard is skipped without starting anything, and a guard that fails, times out or prints something odd allows the call with a note. Pi blocks a tool call whose handler throws, so the handler catches its own errors and allows the call too. The extension is type-checked with the rest of the agent tooling (the tooling tsconfig now includes .pi), and oxlint and oxfmt already cover .pi, since both run over the whole repository. Its tests are in .agents/scripts/pi-extension.test.ts, since Pi would load a test file in .pi/extensions/ as another extension.
When guard.ts itself failed to load, such as with a syntax error, node exited with nothing on stdout and the extension read that as "nothing to say", so the push went through without the note the other agents show. A guard that exits unsuccessfully now gives a note with its exit code or signal and what it printed on stderr, and a timeout note carries the stderr too. The tests for the calls the extension skips (other tools, commands that can't push, DISABLE_AGENT_GUARD=1, a checkout without the guard) now put a `node` on PATH that records each start, so they fail if the extension starts the guard at all, rather than passing on a guard that ran and said nothing. The test driver writes its event file with TempRepo.write.
The overview listed Claude Code, Codex and Pi; Cursor runs the Claude Code hooks, as the table below it says.
scottlovegrove
force-pushed
the
scottl/agent-guard-pi
branch
from
November 27, 2026 14:30
05e852e to
2db9cfd
Compare
2 tasks done
scottlovegrove
added a commit
to todoist/todoist-mcp
that referenced
this pull request
Nov 27, 2026
# Pull Request ## Short description Part 2 of 3, on top of #784. Runs the push check in Pi, ported from todoist/todoist-cli#673. Pi has no hook files, so `.pi/extensions/agent-guard.ts` listens to Pi's `tool_call` event: before a `bash` call that could push, it runs the same `.agents/scripts/guard.ts` with the same JSON, and blocks the call with the guard's reason when it says no. Pi only loads project extensions once the project is trusted (`pi --approve`, or the prompt on first run), and only from the folder it starts in, so AGENTS.md and docs/agents.md say to start Pi at the repository root. `.pi` is now in the lint paths (`format:check`, `format:fix`, `check` and verify's lint step) and in the tooling tsconfig as `../../.pi/**/*` (a bare `../../.pi` includes nothing; a test asks tsc what it reads). `.pi/` is in the package-contents test's dev-only list and the instructions test's rooted paths. The tests live in `.agents/scripts/pi-extension.test.ts`, since Pi would load a test file in `.pi/extensions/` as another extension. Fixes from the other ports, each with a test that fails without it: - A guard that crashes or can't start (a syntax error makes Node exit non-zero with only stderr) used to resolve to `{}` and allow the push without a word. It now allows it with a note carrying the exit code or signal and stderr (all three ports; the wording follows comms-cli, which also puts stderr in the timeout note). - A `ui.notify` that throws could turn a denial into an allow, since the handler's catch allows. The block is worked out first and a failed note falls back to stderr (outline-cli, todoist/outline-cli#194). - The skip tests put a `node` on `PATH` that records each start, so they tell "skipped" from "started and failed" (comms-cli, todoist/comms-cli#136). Tried with Pi 0.85.1 (`pi -p --approve --mode json`) in a throwaway clone pushing to a local bare repository: the JSON event stream shows the unverified push blocked with the guard's reason, `npm run verify` passing, and the same push then going through; the bare repo has the branch. ## PR Checklist - [x] Added tests for bugs / new features - [x] Updated docs (README, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Runs the push check from #135 in Pi as well, ported from todoist/todoist-cli#673. Pi has no hook files, so
.pi/extensions/agent-guard.tslistens to Pi'stool_callevent: before abashcall that could push, it runs the same.agents/scripts/guard.tsthe Claude Code and Codex hooks call, with the same JSON, and blocks the call with the guard's reason when it says no.It behaves like the other agents' hooks:
DISABLE_AGENT_GUARD=1turns it off, a checkout without the guard is skipped without starting anything, and a guard that fails, times out or prints something odd allows the call with a note. Pi blocks a tool call whose handler throws, so the handler catches its own errors and allows the call too. Doistbot's review here found that a guard that can't load at all, such as one with a syntax error, was read as having nothing to say, so no note appeared; todoist-cli's extension does the same. It now gives a note with the exit code and the guard's stderr, and the tests for the calls it skips check that it never starts the guard. Pi only loads project extensions once the project is trusted, and only from the folder it starts in, so docs/agents.md says to start Pi at the repository root.One difference from todoist-cli: there,
.pihad to be added to the lint paths ofnpm run checkand verify's lint step. Herenpm run lint:checkand verify already runoxlint .andoxfmtover the whole repository, and both catch problems in.pi(I checked with an unused variable and a badly formatted line in the extension), sopackage.jsonand the verify steps are unchanged. The tooling tsconfig now includes.pi/**/*so the extension is type-checked, and.pi/joins the dev-only paths the package-contents test keeps out of the npm package. The tests are in.agents/scripts/pi-extension.test.ts, since Pi would load a test file in.pi/extensions/as another extension.Tried with Pi 0.85.1 (
pi -p --approve) at the top of this stack, in a throwaway clone pushing to a local bare repository: the unverified push was blocked with the guard's reason, and afternpm run verifythe same push went through. The JSON event stream showed the blocked call, and the bare repository's ref matched the pushed commit.