Skip to content

fix(agent-config): make the install gate block in OpenCode 2.x, Cline, Gemini CLI and Antigravity - #1140

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

sandstream merged 7 commits into
mainfrom
fix/agent-gate-wiring-a

Conversation

@sandstream

@sandstream sandstream commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What was broken

kit wires kit gate-bash into each agent's pre-tool hook. In four agents the gate did not block, and nothing said so.

Agent What was broken Source evidence
OpenCode 2.x kit wrote a V1 plugin (tool.execute.before, no default export). OpenCode 2.x loads only export default { id, setup } or { id, effect }, so the gate never loaded. sst/opencode 697db192 (v2.4.1): packages/core/src/plugin/module.ts:81-93; services/site/src/docs/content/build/plugins/migrate-v1.mdx:10-12
Cline The shell tool is now run_commands with commands (a list; JSON text in the VS Code payload). kit read preToolUse.parameters.command, found nothing and allowed the call. cline/cline cbc7d141: sdk/packages/core/src/extensions/tools/schemas.ts:133-176; apps/vscode/src/sdk/hooks-adapter.ts:28-38,168-174; sdk/packages/core/src/hooks/hook-file-hooks.ts:845-867
Gemini CLI When a hook prints JSON, the JSON decides and the exit code is ignored. Exit 2 with empty output does not block. Project hooks do not run in an untrusted folder. google-gemini/gemini-cli 60f8082b: packages/core/src/hooks/hookRunner.ts:451-489,537-560; packages/core/src/hooks/hookRegistry.ts:171-186
Antigravity hooks.json is keyed by hook name at the top level. kit wrote {"hooks": {...}}. The exit-code meaning is not documented. https://antigravity.google/docs/hooks.md (fetched 2026-11-26; the product is closed source)

What changed

  • OpenCode. No single file loads in every release:

    • 1.0 to 1.3 call every export as a function (packages/opencode/src/plugin/index.ts:41-44 at v1.0.0, :86-92 at v1.2.0, :119-124 at v1.3.0).
    • 1.4 and later read default.server (readV1Plugin, shared.ts:272-303 at v1.4.0 and v1.19.6).
    • 2.x refuses a default export that is not an object (effect 4.1.0 SchemaAST.ts:3144).

    kit reads the installed version and writes the form that version loads: function exports for 1.0 to 1.3, and export default { id, setup, server } for 1.4 and later, 2.x included. When kit cannot read the version, a new install gets the 1.4+ form with a notice. A 1.x plugin that kit wrote earlier is kept, also with a notice.

  • Cline. kit gate-bash reads commands from tool_call.input or from the JSON text in parameters. It still reads the old command and cmd fields. It gates every command. A run_commands call whose commands kit cannot read is blocked. The block is still {cancel:true}, which is Cline's only block signal for file hooks, and it stops the whole Cline run.

  • Gemini CLI. The hook runs with --format gemini. On a deny it writes {"decision":"deny"} to stdout, writes the reason to stderr, and exits 2. kit agent-config now says that the folder must be trusted with /permissions trust.

  • Antigravity. kit writes a kit-install-gate entry with enabled: true. It moves its gate out of the old hooks entry and keeps every user hook there. kit refuses to overwrite a hooks.json it cannot parse. On a deny the gate writes the stdout decision and also exits 2.

  • Code layout. The Gemini, OpenCode, Cline and Antigravity installers moved to src/agent-gate-contracts.ts, beside fix(agent-config): make the install gate run, and fail closed, in Codex, Amazon Q, Kiro, Cursor, Droid and Aider #1136's src/agent-gate-installers.ts. The hook-payload extraction moved to src/install-gate-payload.ts. Gemini and Antigravity treat an entry as kit's only on an exact isKitGateCommand match (--format gemini is now one of the forms), so a look-alike is left alone. The Gemini trust step and the OpenCode version notes use the next steps that kit agent-config prints.

  • kit pull. It now names .amazonq/cli-agents/ files. The installer-file test found the gap once it read every installer module.

Security hardening (from review)

  1. Cline {command, args} entries. Cline runs these without a shell. kit now quotes each argv word in POSIX single quotes before the gate parses the line, so an argument with spaces, quotes, ; or && stays one word. When args are not a list of strings, or a word holds a NUL byte, kit blocks the call.
  2. Cline command lists. kit also gates the list as one newline-joined script, so a cd or an export in one command applies to the next one.
  3. OpenCode version check.
    • kit never runs an opencode from the project. It looks only in absolute PATH directories outside the project root.
    • It reads the version from the npm package.json that the binary belongs to.
    • On Windows it runs nothing.
    • On macOS and Linux it runs the absolute binary only when no package.json is found. It runs it without a shell, from the home directory.

What the tests prove

src/agent-gate-contracts.test.ts, src/install-gate-payload.test.ts and the changed src/agent-config.test.ts do the following:

  • Each test installs the gate with kit's installer, then runs what was installed with the agent's payload from the cited source: the Cline hook file, the Gemini and Antigravity hook lines (through /bin/sh), and the OpenCode plugin module.
  • Each test reads the result the way the agent's code does.
  • The registry is unreachable on purpose. npm i some-untriaged-pkg is blocked and ls is allowed, with no network call.

The tests also cover these cases:

  • Cline: an argument that hides an install (sh -c '<install>') is blocked. An argument that only looks like one (echo '; npm i …') is allowed. Unreadable args are blocked. A cd sub then npm install list is blocked as a script, and each command alone is allowed.
  • OpenCode: the 2.x setup hook, the 1.4+ server hook and the 1.0 to 1.3 function exports all block. A 1.x plugin is kept when the version is unknown. A planted opencode in the project is never run.
  • Antigravity: the old file is migrated and user hooks are kept.

Before the fix, 16 of the 17 first-round tests failed on the old code.

Not verified

  • No test runs a real agent. The payload shapes and reading rules come from the agents' source (Antigravity from its docs only).
  • Cline on Windows runs only PreToolUse.ps1 (apps/vscode/src/core/hooks/hook-factory.ts:988). kit does not write that file, so the Cline gate does not run on Windows.
  • Antigravity's exit-code behaviour is not documented. kit sends both a stdout decision and exit 2.
  • On OpenCode 2.x, the --version output and the npm package name are not confirmed. kit accepts any package.json whose name contains opencode.
  • No CI job runs macOS. The hook-line tests that use /bin/sh skip on Windows, and the CLI-level tests run there.

🤖 Generated with Claude Code

sandstream and others added 4 commits November 27, 2026 13:52
… Gemini and Antigravity

- OpenCode: one plugin file for 2.x (setup) and 1.4+ (server); V1-only form did not load in 2.x.
- Cline: read run_commands' commands list (also JSON text); gate every command; unreadable list blocks.
- Gemini: --format gemini prints a JSON deny decision; agent-config says the folder must be trusted.
- Antigravity: top-level named hook entry, stdout decision plus exit 2; user hooks kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 4ca51367da39b1d76c12283c6937505b81d437e5
…nt installers

- Cline {command, args} entries: each argv word is POSIX single-quoted before the gate parses
  the line, so an argument with spaces, quotes, `;` or `&&` stays one word. Args that are not a
  list of strings, or hold a NUL byte, make the call unreadable, and it is blocked.
- Cline run_commands: the list is also gated as one newline-joined script, so a `cd` or an
  `export` in one command is seen by the next.
- OpenCode: no single plugin file loads in 1.0-1.3 (every export is called as a function) and in
  2.x (the default export must be an object). kit reads `opencode --version`: 1.0-1.3 get the
  function-only plugin, 1.4+ and 2.x the default-object plugin. With no version, kit keeps a
  1.x plugin it wrote before and says so.
- Gemini, OpenCode, Cline and Antigravity installers move to src/agent-gate-installers.ts and
  the hook command line to src/kit-invocation.ts; agent-config.ts re-exports them.
- Tests are table-driven: one fixture table per agent.

Test-Growth: four agents' hook contracts (Cline, Gemini CLI, Antigravity, OpenCode 1.x/1.4+/2.x) each need an end-to-end run of the installed hook with the agent's real payload, plus the three security cases; the fixtures are already one table per agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 7ac9db0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: f313e77
…nary

`opencode --version` ran whatever `opencode` resolved to, with the project as cwd; on Windows
with a shell, cmd.exe looks in the current directory first, so a committed opencode.cmd would
run during `kit agent-config`. kit now looks only in absolute PATH directories outside the
project, reads the version from the npm package.json the binary belongs to, and runs nothing on
Windows. On macOS and Linux, when there is no package.json, it runs that absolute binary without
a shell from the home directory. A planted `opencode` in the project must not run (test).

A default export that is a function with id/setup/server attached is not a fallback: OpenCode
2.x refuses a default export that is not an object (effect 4.1.0 SchemaAST.ts:3144).

Also splits installInstallGateOpenCode and cmdGateBash below the complexity limit.

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

Comment thread src/agent-gate-installers.ts Fixed

@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 6e9d38459eef: not approved.

  • checks did not pass: CodeQL, Security gate, Stage 2 — SAST, build-and-test, linux shard 3/4, windows shard 3/4, windows-native
  • touches protected paths (permissions), which the owner approves: src/agent-config.ts, src/commands/gate.ts, src/install-gate-payload.test.ts, src/install-gate-payload.ts, src/install-gate.ts, src/opencode-gate.ts
  • 1725 changed lines, over the 1500-line limit for a gate-only approval

sandstream and others added 3 commits November 27, 2026 14:38
- pull-agent-files.test.ts read gate files from agent-config.ts only; the moved installers live
  in agent-gate-installers.ts, so it reads both.
- gate.ts: a top-level type import instead of an inline import() type, which Semgrep could not
  parse.
- The Cline hook shim is written through a temporary file and a rename, not in place after an
  existence check (CodeQL js/file-system-race).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 36e15c0
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
…eir own modules

The Gemini CLI, OpenCode, Cline and Antigravity installers move from agent-gate-installers.ts to
src/agent-gate-contracts.ts (tested by agent-gate-contracts.test.ts), and the hook-payload command
extraction from install-gate.ts to install-gate-payload.ts (re-exported), so neither file grows
past main's size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kit-Hook-Tree: 931f4bd
@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 25d9d66447f4: not approved.

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

@sandstream
sandstream merged commit fabc83f into main Nov 27, 2026
34 checks passed
@sandstream
sandstream deleted the fix/agent-gate-wiring-a branch November 27, 2026 14:29
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.

2 participants