Skip to content

fix(agent-config): make the install gate run, and fail closed, in Codex, Amazon Q, Kiro, Cursor, Droid and Aider - #1136

Merged
sandstream merged 6 commits into
mainfrom
fix/agent-gate-wiring-b
Nov 27, 2026
Merged

sandstream merged 6 commits into
mainfrom
fix/agent-gate-wiring-b

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Phase 0.5 of the agent-parity work: kit's install gate (kit gate-bash) was wired into several agents in a way that did not block, or did not block reliably. Each fix below is based on the agent's own source or docs (references in the changelog fragment and in the fixture comments).

What was broken, per agent

Agent Problem Fix
Codex A project hook runs only in a trusted project and after the user trusts the hook (trusted_hash, openai/codex hooks/src/engine/discovery.rs:953-960). kit said nothing, so the gate looked wired while it did not run. kit agent-config prints the steps with the exact command to trust. kit check warns (codex install-gate trust) until both hold. kit computes the hash as Codex does (checked against Codex's test fixtures) and never writes the trust itself.
Amazon Q (Windows) The shell tool is execute_cmd; the execute_bash matcher never fired. Adds an execute_cmd entry. A test proves fs_write (whose input also has a command field) can never reach gate-bash.
Cursor Allowed the call when the hook crashed or timed out. failClosed: true, plus --format cursor so the gate always prints an explicit verdict.
Factory Droid kit wrote a hooks wrapper that Droid's hooks.json does not use, so the gate never loaded. Also failed open. Event-keyed file, onFailure: "block", existing entries migrated.
Kiro IDE 1.0 / CLI V3 read standalone .kiro/hooks/*.json; .md agents were skipped. Writes .kiro/hooks/kit-install-gate.json; legacy wiring kept for CLI 2.x.
Aider Commits with --no-verify unless git-commit-verify: true, so kit's git hooks never run. kit check row aider git hooks, and the CONVENTIONS.md block says it.

Security hardening (from automated review during this work)

  • kit treats an existing hook entry as its own only when the command is exactly a string kit writes on this machine. Path shape proves nothing (/tmp/kit gate-bash, ./node_modules/x/cli.js gate-bash, a UNC path). A look-alike is left in place and named in the output, never copied to a new matcher, migrated, or offered for trust.
  • When lifting kit's Droid handler out of the old wrapper, only kit's handler moves; foreign handlers in the same group stay put.
  • kit's Droid gate counts as wired only under the Execute matcher. A kit line planted under another matcher (which never fires on shell calls) no longer makes kit report the gate as wired.
  • Look-alikes glued to a shell operator (kit gate-bash; id) are reported too.

The Cursor, Amazon Q, Kiro and Droid installers moved to src/agent-gate-installers.ts (agent-config.ts was over the size limit).

Tests

Fixture tests per agent contract, each with the source file it is based on. Every look-alike and matcher test failed on the code before the fix. Local gate: node scripts/prepush.mjs green (tests of changed files, kit review --enforce, self-audit, coverage gate). Test growth is over the 400-line cap; the reason is in the commit trailer.

Not verified

  • No test runs a real agent. The fixtures prove the payload and config shapes from each agent's source and docs, not that the agent calls the hook.
  • Semgrep did not run locally (wrong version installed); CI runs it.
  • apply_patch in Codex is deliberately not added to the gate-bash matcher: Codex sends the raw patch in tool_input.command, which gate-bash would misread. It belongs to the write-gate phase.
  • No CI job runs macOS.

🤖 Generated with Claude Code

sandstream and others added 6 commits November 27, 2026 13:37
…ex, Amazon Q, Kiro, Cursor, Droid and Aider

- Codex: kit agent-config prints the trust steps; kit check warns (codex
  install-gate trust) until the project and the hook are trusted. The hash
  is Codex's own, checked against Codex's test fixtures. kit never writes
  trusted_hash. apply_patch stays out of the matcher.
- Amazon Q: add execute_cmd (Windows shell tool), also for Kiro legacy
  agents; a test proves fs_write never reaches gate-bash.
- Cursor: failClosed: true plus gate-bash --format cursor (explicit allow
  verdict). Droid: onFailure: "block", and hooks.json keyed by event name
  as Droid documents. Existing kit entries are migrated in place.
- Kiro: standalone .kiro/hooks/kit-install-gate.json for IDE 1.0 / CLI V3,
  covering .md agents; array-form agents are no longer falsely "wired".
- Aider: kit check warns when git-commit-verify is off; CONVENTIONS.md
  block says so.
- agent-audit reads Droid's event-keyed hooks.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 65926aeda99f3411d78a8504b6fb7b55bea0fef1
…ommand

A look-alike command ending in gate-bash was treated as kit's entry and copied
to new matchers. Installers now match only the exact lines kit writes, leave a
look-alike untouched and name it, and always write kitGateInvocation().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 8bb7fa8158e4a4d30a539282f7271b3e782c5de6
…handlers, split installers

- kit-gate-command: own-entry test compares against the exact strings kit writes
  on this machine; path shape proves nothing. Look-alikes glued to a shell
  operator (`kit gate-bash; id`) are reported too.
- Droid legacy wrapper: only kit's handlers move; foreign handlers stay put.
- Installers for Amazon Q, Kiro, Cursor and Droid move to agent-gate-installers.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 0a1d75526384fcdbe99803b11fe8b4c63e3285bf
…ecute matcher

A kit line under a non-shell matcher never fires on a shell call, so a repo
could plant one and make kit report the gate as wired. Lifted handlers now
always land under Execute. Also: split the Droid installer, rename the
installer tests after their module, unexport KIRO_HOOK_FILE.

Test-Growth: one fixture test per agent contract (Codex trust hash, Amazon Q Windows matcher, Kiro hook file, Cursor and Droid fail-closed, Aider commit-verify) plus look-alike tests for each installer; each covers a gate that silently did not block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: a302a759897adb41d76813ec608d35d06dfd4ef1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 7c1cdc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 2027b50
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kit review gate at e33c360fe5d7: not approved.

  • touches protected paths (permissions), which the owner approves: src/agent-config.ts, src/commands/gate.ts
  • 2074 changed lines, over the 1500-line limit for a gate-only approval

@sandstream
sandstream merged commit 8726c2a into main Nov 27, 2026
33 checks passed
@sandstream
sandstream deleted the fix/agent-gate-wiring-b branch November 27, 2026 13:33
sandstream added a commit that referenced this pull request Nov 27, 2026
Resolves the conflict with #1136, which moved the Amazon Q, Kiro, Cursor and Droid installers
into src/agent-gate-installers.ts and added src/kit-gate-command.ts:
- the Gemini, OpenCode, Cline and Antigravity installers join them in agent-gate-installers.ts;
  src/kit-invocation.ts is dropped for kit-gate-command.ts.
- Gemini and Antigravity treat an entry as kit's only on an exact isKitGateCommand match, so a
  look-alike is left alone; `--format gemini` is one of the forms kit writes.
- the Gemini trust step and the OpenCode version notes use #1136's `next` steps, which
  `kit agent-config` prints.
- this branch's tests move to src/agent-gate-contracts.test.ts.
- pull-agent-files.test.ts now reads both installer files, which showed that `kit pull` did not
  name `.amazonq/cli-agents/` files; it does now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 20cae07
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