Skip to content

Review a coding agent's changes before it ends its turn - #158

Open
Bidthedog wants to merge 9 commits into
prooflinedev:mainfrom
Bidthedog:feature/S001-agent-review-hook
Open

Bidthedog wants to merge 9 commits into
prooflinedev:mainfrom
Bidthedog:feature/S001-agent-review-hook

Conversation

@Bidthedog

Copy link
Copy Markdown

Who this helps

Teams using coding agents (Claude Code, Codex CLI, Gemini CLI, Cursor) in repositories connected to
Proofline. Findings now arrive at commit or PR time, after the agent has finished. This hook
reviews the checkout when the agent tries to stop and hands the serious findings back while it
still has the context to fix them.

proofline agent install <claude-code|codex|gemini|cursor> --review-hook    # preview, confirm, add one hook
proofline agent uninstall <claude-code|codex|gemini|cursor> --review-hook  # remove exactly that entry

How it works

sequenceDiagram
  participant A as Coding agent
  participant H as proofline hook agent-stop
  participant G as Git checkout
  participant P as Proofline API

  A->>H: stop input (working directory, already continuing?)
  H->>G: policy (git config), record (.git/proofline/agent-stop.json)
  H->>G: local changes incl. untracked, fingerprint
  alt no changes, same changes, or repository not connected
    H-->>A: {} (silent)
  else new changes
    H->>H: secret preflight
    H->>P: resolve repository, request patch review
    H->>P: poll the review (up to the timeout)
    alt findings at or above the threshold, block mode, not already continuing
      H-->>A: keep working: findings + review link
      A->>A: fixes or rebuts, tries to stop again
    else otherwise
      H-->>A: a note for the developer
    end
  end
Loading

Decisions

  • No server change. It reuses the local review path: preflight, request_patch_review, repository
    resolution. Policy reuses the Git hooks' proofline.hook.<name>.* keys.
  • Hand back once. A record in the Git directory (a hash, no source) stops the same changes being
    reviewed or handed back twice, and the hook never holds an agent that is already continuing.
  • Silent unless useful. It prints nothing outside connected repositories. Infrastructure
    failures never hold the agent unless onIncomplete=block.
  • Exit 0 with a JSON decision, never 2. Exit 2 means "incomplete review" everywhere else in this
    CLI.
  • Untracked files included. Agents create files.
  • One decision path, one module per agent. hook agent-stop --agent <agent> decides in
    agent-neutral types; agent_stop/{claude,codex,gemini,cursor}.rs only translate input and reply.
    Codex shares Claude Code's contract, Gemini CLI says deny, Cursor sends a followup_message.
  • Each agent's own file and format. Claude Code gets an exec-form entry; Codex, Gemini CLI and
    Cursor take one shell string, so install quotes every part. Timeouts sit above the hook's 1800 s
    cap in each agent's units.

Left out

  • Kiro. Its Agent Stop hook has no documented way for a command to keep the agent working, so
    install refuses it with that reason.
  • Windows for the shell-string agents. Quoting a path in a hook command there is not documented
    for every agent, so install refuses and --print shows the entry to add by hand.
  • Developer notes in Cursor. Cursor shows nothing from a stop hook, so notes there go unseen;
    findings handed to the agent still arrive.

Verification

  • Integration tests drive the built binary against real Git checkouts and a mock API: feedback and
    report modes, the once-only guard, still-running reviews, unknown repositories, missing sign-in,
    preflight refusal, invalid settings, and each agent's input and reply form.
  • Install tests round-trip every agent's settings file, including Gemini's MCP servers and an
    executable path with a space and a quote, which they run through sh as the agent would.
  • cargo test --locked: 208 passed. fmt and clippy clean; dependencies unchanged.
  • Not yet run against a live Proofline organization or live agent sessions.
  • Codex runs a new hook only after you trust it in /hooks; the install message says so.

Questions

  • proofline review skips untracked files unless --include-untracked is passed. Should it include
    them by default, as this hook does?
  • Cursor documents loop_count as counting follow-ups "for this conversation". If it never resets,
    the hook holds a Cursor conversation at most once in total. Is that acceptable?

The Git hooks' policy reader took a Hook value. The agent stop hook needs
the same proofline.hook.<name>.* keys, parsing and errors with its own
defaults, so the reader now takes the name and the defaults. The Git hooks
behave exactly as before.
The agent stop hook sends the report in a JSON reply instead of printing
it, so the report builder returns lines and the Git hooks print them.
The store's symlink, repository, lock and change checks were tied to one
MCP client's file and edit. It now takes the file's path and the edit, so
the Claude Code settings file can be written under the same guarantees.
MCP registration is unchanged.
`proofline hook agent-stop` reads a Claude Code Stop hook's input,
reviews the checkout's local changes, untracked files included, through
the same preflight and patch-review request as the Git hooks, and
answers with one JSON decision: hold the turn and hand the agent the
findings at or above the threshold, or let it end with a note for the
developer.

A record in the Git directory stops the same changes being reviewed or
handed back twice, and the hook never holds an agent that is already
continuing; findings withheld for that reason go back at the next stop
that may hold it. It is silent outside connected repositories, and its
policy uses the Git hooks' `proofline.hook.agent-stop.*` keys with
environment overrides for the wait, the gap and the findings cap.
`agent install claude-code --review-hook` adds one Stop group to
~/.claude/settings.json that runs this executable's `hook agent-stop`,
in exec form so a path with spaces needs no quoting, with a timeout
above the hook's own cap. `--max-findings` lands in its arguments, and
a second review hook with other settings is refused.
`agent uninstall claude-code --review-hook` removes only that exact
entry, drops `Stop` and `hooks` only when it empties them, and leaves
an edited entry in place. Both use the installer's existing preview,
confirmation, lock and repository checks, and a refusal names the
settings file and what is wrong with it.
`hook agent-stop` keeps its decisions in agent_stop.rs and moves
Claude Code's input and reply format to agent_stop/claude.rs, the
checkout's record to agent_stop/record.rs, and the policy to
agent_stop/policy.rs, so another agent needs only a module like
claude.rs. The settings.json edit moves from agent/config.rs to
agent/config/settings.rs, leaving config.rs with the MCP entries.
Code moves only; behaviour is unchanged.
`hook agent-stop --agent codex|gemini|cursor` reads that agent's stop
input and answers in its own form: Codex shares Claude Code's
contract, Gemini CLI keeps the agent working with `decision: "deny"`,
and Cursor with `followup_message`, taking the checkout from
`workspace_roots` and treating `loop_count` above 0 as continuing.
The decisions stay agent-neutral; each agent module only translates.

`agent install|uninstall <agent> --review-hook` writes or removes the
entry in ~/.codex/hooks.json, ~/.gemini/settings.json or
~/.cursor/hooks.json, as one quoted shell command with a timeout above
the hook's cap. Codex's success message names its `/hooks` trust step.
Kiro, whose stop hook cannot continue the agent, is refused, as are
GEMINI_CLI_HOME and, for the shell-string agents, Windows.
- A hook is the review hook only when its command runs the
  `hook agent-stop` words, so an unrelated hook whose command mentions
  agent-stop no longer blocks install.
- The duplicate-hook refusal names the agent to uninstall instead of a
  placeholder, and encoding errors name the agent being edited.
- Uninstall works on Windows for every agent: it only compares JSON,
  so it can remove an entry added by hand from --print.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant