Skip to content

feat(git): review gate before git commit (cora agent-as-reviewer, on by default when attached) #534

Closed

Description

@ajianaz

What problem does this solve?

tole attaches the cora mcp surface automatically when cora is on PATH, and the system prompt of run / chat / tui tells the model how to review a diff (mcp_cora_cora_review_prepare, judge it itself, then mcp_cora_cora_review_finalize). But nothing makes the agent do it:

  • The prompt text only says how ("To review a change: ..."); it is not an obligation.
  • --on-turnend stop gates are off by default, and mission --verify is empty by default.
  • The git tool's commit op (Write) has no review precondition.

AGENTS.md makes cora review --staged mandatory before every commit for humans and agents alike, yet an agent session can commit without ever reviewing. There is no pre-commit hook by default either.

Proposed solution

A host-level precondition on the git tool's commit op (in tole-cli, not tole-core, which stays platform-agnostic):

  • A commit is refused unless the session holds a recorded review_finalize verdict with should_block == false for the current staged diff.
  • Binding: tole computes the hash of git diff --cached itself and compares it with the diff the model passed to review_finalize (tole sees the call). The model cannot claim a verdict for a different diff, and any later change to the index invalidates it.
  • The refusal message tells the model exactly what to do: get git diff --cached, call review_prepare, judge, call review_finalize with the same diff, then retry the commit.
  • Verdicts are recorded as a session register (append-only JSONL stays untouched; a verdict is a new register write) and cached per diff hash, so recommitting the same index does not pay again.
  • Policy: --review-gate off|warn|block, config key review_gate. Default block when both review tools are attached, off otherwise. When cora is missing or older than 0.19, skip with one startup warning (probe-first, never a phantom gate), consistent with the "cora error is non-blocking" rule in AGENTS.md.
  • Headless missions use the same policy; a should_block == true verdict ends in a refused commit, not a hung turn.
  • Small diffs: open question whether docs-only or tiny diffs need the gate.

Honest limits

This is a review by the same model that wrote the change: the gate guarantees the process ran on this exact diff, not that the judgement is good. It adds token cost per commit. It does not replace the independent CI Cora Review job.

Open questions

  • Default block vs warn for the first release.
  • Threshold for skipping trivial diffs (docs-only, N lines).
  • Should the gate also cover gh write ops once they exist?
  • What if review_finalize returns findings but should_block == false: surface them in the commit result so they are not lost?

Alternatives considered

  • Rely on cora hook install (a git pre-commit hook): works for human commits but uses the BYOK review, not agent-as-reviewer, and does not exist in agent sandboxes.
  • A generic --on-turnend gate: fires at the end of the turn, after the commit already happened.

Acceptance criteria

  • With the review tools attached, a git commit without a verdict for the staged diff is refused with an actionable message (test with a fake review server).
  • A verdict for diff A does not unlock a commit of diff B; changing the index after finalize invalidates it (tests).
  • should_block == true refuses the commit and shows the findings.
  • off and missing/old cora behave as specified; one startup warning, no phantom tool.
  • The gate cannot be bypassed by a different tool path to git commit (run_command already refuses git-shaped escapes; verify and test).
  • Docs: README, docs/threat-model.md, tole doctor reports the gate state.

Related: #531 (run_command ergonomics) for the bypass check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions