stopbar 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/SECURITY.md +139 -0
- package/bin/stopbar.mjs +6 -0
- package/claude-hooks.example.json +27 -0
- package/dist/adapters/antigravity.js +45 -0
- package/dist/adapters/claude.js +19 -0
- package/dist/adapters/codex.js +48 -0
- package/dist/adapters/cursor.js +63 -0
- package/dist/adapters/gemini.js +47 -0
- package/dist/adapters/index.js +45 -0
- package/dist/adapters/types.js +103 -0
- package/dist/attest.js +97 -0
- package/dist/build-info.json +6 -0
- package/dist/classify.js +212 -0
- package/dist/cli.js +88 -0
- package/dist/commands.js +146 -0
- package/dist/config.js +96 -0
- package/dist/doctor.js +185 -0
- package/dist/engine.js +51 -0
- package/dist/githook.js +17 -0
- package/dist/glob.js +68 -0
- package/dist/hook.js +236 -0
- package/dist/integrations.js +141 -0
- package/dist/kernel.gen.js +63 -0
- package/dist/kernel.js +162 -0
- package/dist/pkg.js +13 -0
- package/dist/probe/index.js +119 -0
- package/dist/probe/wrapper.js +311 -0
- package/dist/repo.js +177 -0
- package/dist/run.js +28 -0
- package/dist/store.js +144 -0
- package/dist/verify.js +154 -0
- package/package.json +58 -4
- package/src/kernel.ts +161 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
- Adapters for Cursor, Codex CLI, Gemini CLI and Antigravity CLI next to Claude Code. One internal event, one kernel;
|
|
6
|
+
each adapter renders the decision in the client's own protocol.
|
|
7
|
+
- `stopbar hook --adapter auto|claude|cursor|codex|gemini|antigravity`. `auto` (the default) detects the client from
|
|
8
|
+
the payload; v1.0 Claude Code settings keep working; an unknown or damaged payload fails closed.
|
|
9
|
+
- `stopbar init --hooks` takes `claude` (`local`), `claude-project` (`project`), `cursor`, `codex`, `gemini`,
|
|
10
|
+
`antigravity` (`agy`) and `git`, comma separated, and merges into existing config files.
|
|
11
|
+
- Git fallback: `stopbar git-hook pre-commit|pre-push`, installed by `init --hooks git` (an existing user hook is kept
|
|
12
|
+
unless `--force-hooks`), and `stopbar run build|test` to record gate runs for tools without hooks.
|
|
13
|
+
- Self-protection also covers `.cursor/hooks.json`, `.codex/hooks.json`, `.codex/config.toml`, `.gemini/*settings*.json`,
|
|
14
|
+
`.gemini/**/hooks.json` and `.agents/hooks.json`.
|
|
15
|
+
- `stopbar doctor` checks the hooks of every client it finds and the git hooks.
|
|
16
|
+
- `stopbar status`, `status --json` and `stopbar attest` say why the secret gate is on (pattern, file or token, tool,
|
|
17
|
+
revision); `events.jsonl` records the pattern and the token of every secret read, never the content.
|
|
18
|
+
- No secret false alarm on code: a bare token that matches only an extension pattern (`*.key`, `*.pem`) counts only if
|
|
19
|
+
the file exists (`claim.key` in inline code is not a read; `cat server.key` and `cat certs/server.key` are).
|
|
20
|
+
- `safeTools` in `config.json` (default `["mcp__ccd_turn__*"]`): local tools that are not treated as outbound.
|
|
21
|
+
- Antigravity CLI tool names from a live session (`write_file`, `sed_file`, `call_mcp_tool`, `list_dir`, ...).
|
|
22
|
+
- A gate command whose post event carries no exit status (Codex CLI) is recorded neither as a pass nor as a failure,
|
|
23
|
+
and the agent is told to use `stopbar run build|test`; blocked commits name `stopbar run` as the other way.
|
|
24
|
+
- Package metadata: repository, homepage and bugs links.
|
|
25
|
+
|
|
26
|
+
## 1.0.0 (2026-11-26)
|
|
27
|
+
|
|
28
|
+
First public release.
|
|
29
|
+
|
|
30
|
+
- Four pillars in one CLI:
|
|
31
|
+
- PROVE: `stopbar prove` (alias `verify`) runs the inductive proof of the kernel and refutes 10 mutants with
|
|
32
|
+
concrete counterexample runs. `npm run verify:lean` checks the Lean export with `lake build` in a pinned
|
|
33
|
+
Lean 4.34.0 container without network.
|
|
34
|
+
- PROBE: `stopbar probe --target wrapper` runs stateful sequences of hook events, human commands and damaged files on
|
|
35
|
+
real git repositories and compares every step with the proven kernel.
|
|
36
|
+
- GATE: `init`, `hook`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor`.
|
|
37
|
+
- ATTEST: `stopbar attest --format json|md` gives a deterministic attestation of the session with the sha256 of the
|
|
38
|
+
event log.
|
|
39
|
+
- The hooks run a step function generated from the proven kernel with gdp-wired `compileJs`; they never load the prover.
|
|
40
|
+
- Self-protection: no edits of `.git/**`, `.claude/*settings*.json` or the Stopbar code; the runtime is pinned in
|
|
41
|
+
`.git/stopbar/runtime`.
|
|
42
|
+
- The quoted heredoc commit `git commit -m "$(cat <<'EOF' ... EOF)"` is allowed; every other command substitution and
|
|
43
|
+
chain in a commit is blocked.
|
|
44
|
+
- Fail closed on a damaged `config.json` or `state.json`. A torn last line of `events.jsonl` never swallows the next
|
|
45
|
+
entry.
|
|
46
|
+
- Path patterns for tests, test config and secrets in `config.json`; profiles `default`, `ts`, `python`, `strict`.
|
|
47
|
+
- Hook latency: no git process in `PreToolUse`, one in `PostToolUse`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paweł Olszewski <kontakt@polszewski.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,209 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Stopbar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stopbar is a formally proven execution gate for AI coding agents. It runs as the hooks of Claude Code, Cursor, Codex
|
|
4
|
+
CLI, Gemini CLI and Antigravity CLI, and as git hooks for any other tool. It stops an agent from:
|
|
5
|
+
|
|
6
|
+
- committing without a passing build and a passing **full** test suite at the current revision of the working tree;
|
|
7
|
+
- weakening existing tests or test configuration without a human approval;
|
|
8
|
+
- running risky or outbound commands after it read a secret, unless a human allows one call;
|
|
9
|
+
- looping on failing builds or tests, or going past a budget of tool calls;
|
|
10
|
+
- switching itself off by editing the agent's hook configuration, git hooks or its own state.
|
|
11
|
+
|
|
12
|
+
The decisions come from one rule, `src/kernel.ts`. gdp-wired 0.60.0 proves its laws by induction, and 10 mutants of
|
|
13
|
+
the rule each fall with a counterexample. Every client goes through the same rule: an adapter translates the client's
|
|
14
|
+
hook payload into one internal event and renders the decision in the client's own output format. See
|
|
15
|
+
[SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and what needs an OS sandbox.
|
|
16
|
+
|
|
17
|
+
## Supported agents
|
|
18
|
+
|
|
19
|
+
| Agent | Config written by `init --hooks` | Events | Block protocol | Status |
|
|
20
|
+
|---|---|---|---|---|
|
|
21
|
+
| Claude Code | `claude`: `.claude/settings.local.json` (`claude-project`: `.claude/settings.json`) | PreToolUse, PostToolUse, PostToolUseFailure, Stop | exit 2, reason on stderr | live-verified (Claude Code 2.1.326) |
|
|
22
|
+
| Cursor | `cursor`: `.cursor/hooks.json` (`failClosed: true`) | preToolUse, postToolUse, postToolUseFailure, stop (also beforeShellExecution, beforeMCPExecution, beforeReadFile, afterFileEdit, afterShellExecution) | exit 2 and `{"permission": "deny"}`; stop: `followup_message` | spec-tested (Cursor hooks reference) |
|
|
23
|
+
| Codex CLI | `codex`: `.codex/hooks.json` | PreToolUse, PostToolUse, Stop | `hookSpecificOutput.permissionDecision: "deny"`; stop: `decision: "block"` | live-verified (Codex CLI 0.172.0): denied commit and config write, tree changes, Stop. Run the gates as `npx stopbar run build` / `npx stopbar run test`, because Codex reports no exit status to hooks. Codex loads project hooks only in a trusted folder |
|
|
24
|
+
| Gemini CLI | `gemini`: `.gemini/settings.json` | BeforeTool, AfterTool, AfterAgent | exit 2, reason on stderr; AfterAgent: `decision: "block"` | spec-tested (Gemini CLI hooks reference) |
|
|
25
|
+
| Antigravity CLI | `antigravity` (alias `agy`): `.agents/hooks.json` | PreToolUse, PostToolUse, Stop | `{"decision": "deny"}`; stop: `decision: "continue"` | live-verified (Antigravity CLI 1.5.18): denied early commit and config write, build and full tests recorded, honest commit allowed, Stop |
|
|
26
|
+
| Any tool, via git | `git`: `.git/hooks/pre-commit`, `.git/hooks/pre-push` | commit, push | exit 1 aborts git | tested with real git (E2E) |
|
|
27
|
+
|
|
28
|
+
`live-verified` means a live agent session passed through the hooks; `spec-tested` means the adapter follows the
|
|
29
|
+
client's published hook schema and the E2E suite runs it with payloads in that schema. Combine targets in one call:
|
|
30
|
+
`--hooks claude,cursor,codex,gemini,antigravity,git`.
|
|
31
|
+
|
|
32
|
+
`stopbar hook --adapter auto` (the default) detects the client from the payload, so the v1.0 Claude Code settings keep
|
|
33
|
+
working. An unknown or damaged payload fails closed (exit 2). The configs written by `init` pass `--adapter` explicitly.
|
|
34
|
+
|
|
35
|
+
**Git fallback.** For a tool without hooks, run the gates through Stopbar so their real exit status counts:
|
|
36
|
+
`npx stopbar run build` and `npx stopbar run test`. The git hooks then allow a commit only after both passed at the
|
|
37
|
+
current tree, block it after an unapproved test change, and block a push after a secret read without approval.
|
|
38
|
+
|
|
39
|
+
## Four pillars
|
|
40
|
+
|
|
41
|
+
| Pillar | Command | What it gives you |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| PROVE | `stopbar prove`, `npm run verify:lean` | The inductive proof of the kernel, 10 mutants that must fall with a counterexample, and (release gate) `lake build` of the Lean export in a pinned Lean 4.34.0 container without network. |
|
|
44
|
+
| PROBE | `stopbar probe` | Stateful probing: at least 200 random multi-step sequences of hook events, human commands and damaged files on real git repositories, compared step by step with the proven kernel. v1.0 has one target, `wrapper` (Stopbar itself). |
|
|
45
|
+
| GATE | `stopbar init`, `hook`, `git-hook`, `run`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The agent hooks, the git fallback and the human commands. |
|
|
46
|
+
| ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions and the sha256 of the event log. |
|
|
47
|
+
|
|
48
|
+
## Set up in 3 steps
|
|
49
|
+
|
|
50
|
+
Requirements: Node.js 22.18 or later, git, a git repository.
|
|
51
|
+
|
|
52
|
+
1. **Install** Stopbar in the repository (or globally):
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
npm install --save-dev stopbar
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2. **Initialise** with your exact build and full-test commands, and write the hooks of your agents:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npx stopbar init --build "npm run build" --test "npm test" --hooks claude,cursor,git
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Profiles for the path patterns: `--profile default|ts|python|strict`. `init` copies the runtime to
|
|
65
|
+
`.git/stopbar/runtime/` and points every hook to it. Existing settings and hooks in those files stay; earlier
|
|
66
|
+
Stopbar entries are replaced. `init` does not overwrite a git hook it did not write, unless you pass
|
|
67
|
+
`--force-hooks` (the old hook is kept as `<name>.stopbar-backup`). Without `--hooks`, it prints the Claude Code JSON
|
|
68
|
+
to paste. A template is in [claude-hooks.example.json](claude-hooks.example.json).
|
|
69
|
+
|
|
70
|
+
3. **Check** the setup, then restart the agent in the repository:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
npx stopbar doctor
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`doctor` checks Node, git, the kernel link, `config.json`, `state.json`, the event log and the hooks of every client
|
|
77
|
+
it finds, and makes a dry run of the real hook pipeline on a scratch repository.
|
|
78
|
+
|
|
79
|
+
The agent must run the gate commands exactly as configured and alone, for example `npm test` and not
|
|
80
|
+
`npm test | tail`. Commits must be one command. The quoted heredoc form that agents use is allowed:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
git commit -m "$(cat <<'EOF'
|
|
84
|
+
Fix the parser
|
|
85
|
+
|
|
86
|
+
Reviewed-by: Jane Doe <jane@example.invalid>
|
|
87
|
+
EOF
|
|
88
|
+
)"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Commands
|
|
92
|
+
|
|
93
|
+
| Command | Who | What it does |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--max-retries 3] [--cap 500] [--cost 1] [--hooks <targets>] [--no-pin] [--force] [--force-hooks]` | human | Writes `config.json` and a fresh state, pins the runtime, writes or prints the hooks. Targets: `claude` (`local`), `claude-project` (`project`), `cursor`, `codex`, `gemini`, `antigravity` (`agy`), `git`, comma separated. |
|
|
96
|
+
| `stopbar hook [--adapter auto\|claude\|cursor\|codex\|gemini\|antigravity]` | agent | The hook. JSON on stdin; the decision in the client's format (see Supported agents). |
|
|
97
|
+
| `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
|
|
98
|
+
| `stopbar run build\|test` | human, agent, CI | Runs the configured gate command and records its real exit status. |
|
|
99
|
+
| `stopbar status [--json]` | human | Revision, gates, taint, budget, why a commit is blocked, and which file or token turned the secret gate on. |
|
|
100
|
+
| `stopbar approve-tests [--rev N]` | human | You reviewed the changed tests or test config up to revision N (default: the current one). |
|
|
101
|
+
| `stopbar approve-shell` | human | Allows **one** risky or outbound call after a secret read. |
|
|
102
|
+
| `stopbar resume --extra N` | human | Lifts a halt (retry limit or budget) and adds N to the budget. |
|
|
103
|
+
| `stopbar reset` | human | Fresh kernel state. Config and event log stay. Also repairs a damaged `state.json`. |
|
|
104
|
+
| `stopbar doctor [--json]` | human | Environment, config, state, hooks and a dry run. Exit 1 on a problem. |
|
|
105
|
+
| `stopbar prove [--out f.json] [--lean f.lean]` | human, CI | PROVE: the inductive proof of the kernel and the 10 mutants. Exit 0 only if everything holds. `verify` is an alias. |
|
|
106
|
+
| `stopbar probe [--target wrapper] [--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir]` | human, CI | PROBE: stateful probing against the proven kernel. A failure is shrunk to a minimal JSON reproduction. Needs the full package (gdp-wired). |
|
|
107
|
+
| `stopbar attest [--format json\|md]` | human, CI | ATTEST: the session attestation. The same state and log give the same output. Exit 1 if the state and the log disagree, exit 2 if a file is damaged. |
|
|
108
|
+
|
|
109
|
+
All commands take `--repo <dir>`. The agent cannot run the human commands: the hooks block them.
|
|
110
|
+
|
|
111
|
+
State, configuration and the event log are in `<repo>/.git/stopbar/`: `config.json`, `state.json`, `events.jsonl`, the
|
|
112
|
+
private snapshot index and the pinned runtime. They are outside the working tree, so they never change the tree hash.
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
`config.json` keeps the gate commands, the limits and three lists of glob patterns:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"version": 1, "profile": "default",
|
|
121
|
+
"buildCmd": "npm run build", "fullTestCmd": "npm test",
|
|
122
|
+
"maxRetries": 3, "cap": 500, "costPerCall": 1,
|
|
123
|
+
"paths": {
|
|
124
|
+
"tests": ["**/tests/**", "**/*.test.*", "**/test_*.py"],
|
|
125
|
+
"testConfig": ["package.json", "pyproject.toml", ".github/workflows/**"],
|
|
126
|
+
"secrets": [".env*", "*.pem", "**/secrets/**"]
|
|
127
|
+
},
|
|
128
|
+
"safeTools": ["mcp__ccd_turn__*"]
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A pattern without `/` matches the file name anywhere. `**` is a whole path segment. Matching ignores case. Change a
|
|
133
|
+
profile by editing the lists: no code change is necessary.
|
|
134
|
+
|
|
135
|
+
- **Secrets in shell commands.** A token in a command counts as a secret read when it matches a secret pattern. For an
|
|
136
|
+
extension-only pattern such as `*.key` or `*.pem`, a bare token (`claim.key`, `self.pem`) counts only when that file
|
|
137
|
+
exists, because it is usually a field access in code; a token with a path separator (`certs/server.key`) and every
|
|
138
|
+
other pattern (`.env*`, `id_rsa*`) count always. `stopbar status` says why the secret gate is on, for example
|
|
139
|
+
`secret read yes (matched *.key (server.key) in Bash at rev 3)`; `events.jsonl` keeps the pattern and the token,
|
|
140
|
+
never the file content.
|
|
141
|
+
- **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default is
|
|
142
|
+
`["mcp__ccd_turn__*"]`, the task-list and turn-summary tools of Claude Desktop. It only exempts tools from the
|
|
143
|
+
outbound gate (WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before, and a halted
|
|
144
|
+
session still blocks every tool. A damaged or empty `config.json` or `state.json` blocks every
|
|
145
|
+
tool call (exit 2) with a message that says how to repair it.
|
|
146
|
+
|
|
147
|
+
## Local use
|
|
148
|
+
|
|
149
|
+
- `npm run build` builds `dist/` from `src/` with Node's own type stripping and generates `dist/kernel.gen.js` from
|
|
150
|
+
the kernel with gdp-wired's `compileJs`. There is no TypeScript compiler and no bundler.
|
|
151
|
+
- `npm test` runs the unit tests, the E2E suite (real git repositories, a separate hook process for each call) and the
|
|
152
|
+
stateful fuzzer (200 random sequences of 20–30 steps, compared with the proven kernel). It takes about 3 minutes.
|
|
153
|
+
In Claude Code, give the Bash tool enough time, for example `"env": {"BASH_DEFAULT_TIMEOUT_MS": "600000"}` in the
|
|
154
|
+
settings.
|
|
155
|
+
- `npm run prove` builds and runs `stopbar prove` (about 3 minutes). `npm run verify` is the same.
|
|
156
|
+
- `npm run verify:lean` exports the Lean project (`leanProject()` of gdp-wired) and runs `lake build` in the
|
|
157
|
+
container from `docker/lean.Dockerfile` with `--network none`. It is the release gate for changes of `src/kernel.ts`,
|
|
158
|
+
not part of `npm test`. Build the image once (this needs the network):
|
|
159
|
+
`docker build -f docker/lean.Dockerfile -t stopbar-lean:4.34.0 docker`.
|
|
160
|
+
- `npm run bench` measures the hook latency.
|
|
161
|
+
- `npm run test:e2e` or `npm run test:fuzz` runs only the E2E suite or only the stateful prober.
|
|
162
|
+
|
|
163
|
+
## Use in CI
|
|
164
|
+
|
|
165
|
+
Prove the kernel and run the tests on every change of Stopbar itself:
|
|
166
|
+
|
|
167
|
+
```yaml
|
|
168
|
+
- run: npm ci
|
|
169
|
+
- run: npm test
|
|
170
|
+
- run: npx stopbar prove --out stopbar-prove.json
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
For headless agent runs in CI, initialise Stopbar in the job and keep the evidence:
|
|
174
|
+
|
|
175
|
+
```yaml
|
|
176
|
+
- run: npx stopbar init --build "npm run build" --test "npm test" --hooks project
|
|
177
|
+
- run: claude -p "<task>" --setting-sources project,local --max-turns 20
|
|
178
|
+
- run: npx stopbar status --json > stopbar-status.json
|
|
179
|
+
- run: npx stopbar attest --format md > stopbar-attest.md
|
|
180
|
+
- run: cp .git/stopbar/events.jsonl stopbar-events.jsonl
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`stopbar attest` tells whether a commit is allowed at the end and lists every human action. Its sha256 of
|
|
184
|
+
`events.jsonl` ties the report to the log, which has one line for each kernel step and each block, with the reason.
|
|
185
|
+
|
|
186
|
+
## Hook latency
|
|
187
|
+
|
|
188
|
+
Each hook is a separate Node process. The hooks never load the prover. `PreToolUse` makes no git call. `PostToolUse` and
|
|
189
|
+
a commit check make one: `git add -A` on a private index, which the hook then reads itself. `Stop` makes two. On
|
|
190
|
+
Windows 11 with a 330-file repository, in one run with 1.0.0 as the baseline: 1.1.0 p50 94 ms and p95 234 ms over all
|
|
191
|
+
hook processes, including Cursor and Antigravity payloads; 1.0.0 p95 247 ms. The adapter layer adds no measurable
|
|
192
|
+
latency. An earlier prototype that loaded the prover in every hook measured p50 981 ms and p95 1613 ms.
|
|
193
|
+
`npm run bench` repeats the measurement (`--baseline <cli>` compares with another build).
|
|
194
|
+
|
|
195
|
+
## Tested platforms
|
|
196
|
+
|
|
197
|
+
| Platform | Node | git | Unit | E2E | `stopbar probe` | `stopbar prove` | `stopbar doctor` |
|
|
198
|
+
|---|---|---|---|---|---|---|---|
|
|
199
|
+
| Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 28/28 | 237/237 | 201/201 sequences | proven, 10/10 mutants | OK |
|
|
200
|
+
| Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 28/28 | 237/237 | 201/201 sequences | proven, 10/10 mutants | OK |
|
|
201
|
+
|
|
202
|
+
The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
|
|
203
|
+
git commits and pushes. The probe runs the same 200 seeds plus 1 regression on both platforms, with the same 5007 steps
|
|
204
|
+
and 7085 hook calls. `stopbar doctor` passes on a fresh repository with all six `--hooks` targets.
|
|
205
|
+
`npm run verify:lean` passes in the Lean 4.34.0 container: `lake build` exit 0, 0 errors, 0 `sorry`.
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT. Stopbar depends on [gdp-wired](https://github.com/monotykamary/gdp-wired) (MIT), pinned to 0.60.0.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Security model
|
|
2
|
+
|
|
3
|
+
Stopbar is a set of Claude Code hooks with a formally proven decision kernel. This file says what is proven, what the
|
|
4
|
+
wrapper enforces, and what Stopbar cannot give you without an operating-system sandbox. Read the last part before you
|
|
5
|
+
rely on Stopbar against a hostile agent.
|
|
6
|
+
|
|
7
|
+
## 1. What is proven
|
|
8
|
+
|
|
9
|
+
The decision rule is `src/kernel.ts`, written in the gdp-wired 0.60.0 DSL. `stopbar prove` runs an inductive proof of
|
|
10
|
+
all laws together with the lemmas I1–I5. The proof result is `proven: true, checked: true`: gdp-wired's proof kernel
|
|
11
|
+
checked the certificate. The laws hold for every sequence of requests, every budget and every retry limit:
|
|
12
|
+
|
|
13
|
+
| Law | Statement |
|
|
14
|
+
|---|---|
|
|
15
|
+
| L1 | A commit executes only after a passing build and a passing full test suite since the last tree change. |
|
|
16
|
+
| L2.1 | A commit executes only when every suspicious test or test-config edit is covered by a human approval of that revision or a later one. |
|
|
17
|
+
| L2.2 | Taint survives every action except a human test approval. A passing test run does not clear it. |
|
|
18
|
+
| L3.1 | "A secret was read" never resets. |
|
|
19
|
+
| L3.2 | A risky or outbound shell call after a secret read pauses, unless a one-time human approval is held. |
|
|
20
|
+
| L3.3 | The risky call that the approval allows uses it up. |
|
|
21
|
+
| L4.1 | In the halted state only RESUME unblocks. There is no ALLOW, no BLOCK and no commit. |
|
|
22
|
+
| L4.2 | Reaching the budget cap halts the session at once. |
|
|
23
|
+
| L4.3a, L4.3b | `maxRetries` failed test runs without a full pass, or `maxRetries` failed builds, halt the session. |
|
|
24
|
+
| L4.4 | In the halted state no action except RESUME changes the key state fields. |
|
|
25
|
+
|
|
26
|
+
Ten mutants of the rule (M1a–M7) each break one requirement. For each of them the prover must fail, and a concrete
|
|
27
|
+
counterexample run must break a law on the mutant and break no law on the original (gdp-wired `replayRefutation`).
|
|
28
|
+
This shows that the laws are not vacuous.
|
|
29
|
+
|
|
30
|
+
How the proof reaches the hooks: the build runs gdp-wired's `compileJs` on the proven machine and writes
|
|
31
|
+
`dist/kernel.gen.js`. The hooks run only that file and never load the prover. `stopbar prove`, `stopbar doctor` and the
|
|
32
|
+
test suite regenerate it and compare it byte for byte, check the sha256 of `src/kernel.ts`, and replay thousands of
|
|
33
|
+
random steps against gdp-wired's interpreter. This link is a check, not a proof: you trust gdp-wired's code generator.
|
|
34
|
+
|
|
35
|
+
The Lean gate (`npm run verify:lean`) exports the full Lean project with gdp-wired's `leanProject()` and runs
|
|
36
|
+
`lake build` with Lean 4.34.0 in a container without network (`docker/lean.Dockerfile`). It passes only with exit 0,
|
|
37
|
+
0 errors and 0 `sorry`. It is a release gate for changes of `src/kernel.ts`, not part of `npm test`. It writes the result and the sha256 of the
|
|
38
|
+
checked `.lean` file to `results/lean/lean-verify.json`.
|
|
39
|
+
|
|
40
|
+
## 2. What the wrapper enforces (tested, not proven)
|
|
41
|
+
|
|
42
|
+
The wrapper turns tool calls into kernel requests. These rules are plain code. The E2E suite, the unit tests and the
|
|
43
|
+
stateful prober (`stopbar probe`, real git repositories, compared with gdp-wired's interpreter) test them.
|
|
44
|
+
There is no proof for them.
|
|
45
|
+
|
|
46
|
+
- **Gates by exact command.** Only the exact configured `buildCmd` and `fullTestCmd`, alone, count as gate runs. With
|
|
47
|
+
`;`, `&&`, `||`, `|`, a redirection or `$(...)`, the command is blocked before it runs, because operators hide its exit
|
|
48
|
+
status. Other test runners count as partial runs: they can fail a session, but they never pass the gate.
|
|
49
|
+
- **Results from the event type.** Claude Code sends `PostToolUseFailure` for a failed command and `PostToolUse`
|
|
50
|
+
without an exit code for a successful one. A user interrupt (`is_interrupt`) does not count as a failure.
|
|
51
|
+
- **Tree changes from content.** A private git index in `.git/stopbar/` gives a content snapshot after every edit and
|
|
52
|
+
every shell call: edits, deletions and new files that are not ignored. A change to a test file that exists in HEAD,
|
|
53
|
+
or to any test-config file, is suspicious. The path patterns are in `config.json`.
|
|
54
|
+
- **Commits.** `git commit` and `git push` must be one command without operators, also with git global options before
|
|
55
|
+
the subcommand. The one allowed form of command substitution is the quoted heredoc that Claude Code writes:
|
|
56
|
+
`git commit ... -m "$(cat <<'EOF'` … `EOF` `)"`. The delimiter is in single quotes, so bash expands nothing in the
|
|
57
|
+
message. Nothing else may be in the command. Unquoted `<<EOF`, any other `$(...)`, backticks and chains are blocked.
|
|
58
|
+
- **Self-protection, before the kernel, also when halted.** Edit and Write may not touch any `.git/` directory (Stopbar
|
|
59
|
+
state, git hooks, `.git/config`), the hook configuration of a supported agent (`.claude/*settings*.json`,
|
|
60
|
+
`.cursor/hooks.json`, `.codex/hooks.json`, `.codex/config.toml`, `.gemini/*settings*.json`, `.gemini/**/hooks.json`,
|
|
61
|
+
`.agents/hooks.json`, at project and user level), or the Stopbar code that runs the hooks. A shell command may not
|
|
62
|
+
name a `.git`, `.claude`, `.cursor`, `.codex`, `.gemini` or `.agents` directory, write git config (`git config`
|
|
63
|
+
without `--get` or `--list`), name the Stopbar code, use a `STOPBAR_*` variable, or run a human command
|
|
64
|
+
(`approve-tests`, `approve-shell`, `stopbar init/resume/reset`).
|
|
65
|
+
- **One kernel for every agent.** An adapter per client (Claude Code, Cursor, Codex CLI, Gemini CLI, Antigravity CLI)
|
|
66
|
+
translates the hook payload into one internal event and the decision into the client's output protocol. The
|
|
67
|
+
adapters are wrapper code: the E2E suite runs each with payloads in the client's published schema.
|
|
68
|
+
- **Pinned runtime.** `stopbar init` copies the runtime to `.git/stopbar/runtime/` and points the hooks there. An agent
|
|
69
|
+
that edits or rebuilds a Stopbar checkout cannot change the code that judges it.
|
|
70
|
+
- **Fail closed.** Bad hook input, a missing or damaged `config.json` or `state.json`, a busy lock, or any internal
|
|
71
|
+
error gives exit 2 with a fix on stderr. Every tool call is then blocked until a human repairs the state.
|
|
72
|
+
- **Event log.** `events.jsonl` gets one JSON line per kernel step. If a crash left the last line torn, the next entry
|
|
73
|
+
starts on a new line, so it is never glued to the fragment.
|
|
74
|
+
|
|
75
|
+
## 3. What Stopbar does not give you without an OS sandbox
|
|
76
|
+
|
|
77
|
+
An agent with a shell runs with your user's rights. The hooks see the text of a command, not what it does. Under these
|
|
78
|
+
conditions Stopbar is a strong guard against shortcuts and mistakes. It is **not** a security boundary against an agent
|
|
79
|
+
that tries to defeat it:
|
|
80
|
+
|
|
81
|
+
1. **Indirect execution.** A script written to a normal file and then run (`node x.js`, `bash x.sh`) can do anything:
|
|
82
|
+
delete `.git/stopbar`, edit `.claude/settings.local.json`, run `stopbar approve-tests`. The text checks do not see
|
|
83
|
+
inside the script. Obfuscation (`c=cu; ${c}rl`), aliases and shell functions also pass the text checks.
|
|
84
|
+
2. **Gate commands run arbitrary code.** `buildCmd` and `fullTestCmd` run the repository's code. A new test file is
|
|
85
|
+
trusted. It can read secrets, use the network or weaken other checks at run time.
|
|
86
|
+
3. **Secrets by file name only.** Secrets in environment variables, in files with ordinary names, or found with Grep in
|
|
87
|
+
ordinary files are not seen. The exfiltration gate works on command text only. In a shell command, a bare token
|
|
88
|
+
that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
|
|
89
|
+
`claim.key` is not a file); a command that names a `.key` file which does not exist yet is therefore not a read.
|
|
90
|
+
Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools) are not treated as
|
|
91
|
+
outbound; a human who adds a glob there vouches that those tools send nothing out.
|
|
92
|
+
4. **Weak new tests.** A new test file is not suspicious. A mock of the system under test or an empty assertion in a
|
|
93
|
+
new file passes. Hard-coded answers in production code are an ordinary code edit.
|
|
94
|
+
5. **Ignored files.** Files ignored by `.gitignore` are invisible to the snapshot (for example patches in
|
|
95
|
+
`node_modules`). A change to `.gitignore` itself is suspicious.
|
|
96
|
+
6. **Other commit paths.** Git aliases, `git commit-tree`, `gh pr create` and similar are not detected. The Stop hook
|
|
97
|
+
catches uncommitted work only.
|
|
98
|
+
7. **Concurrency and humans.** A change made between two hook calls (a background job, a human edit) is counted as the
|
|
99
|
+
agent's change at the next hook. With parallel tool calls a change can be attributed to the wrong call.
|
|
100
|
+
8. **Agent configuration.** Settings outside the repository (user settings, managed settings, `--settings`,
|
|
101
|
+
`disableAllHooks`) can remove the hooks. The hooks cover what Claude Code sends to them.
|
|
102
|
+
9. **Human approvals.** `approve-tests` and `approve-shell` are only as good as the human review behind them.
|
|
103
|
+
10. **Client-specific limits of the adapters.**
|
|
104
|
+
- Cursor: a hook exit other than 0 and 2 is fail-open unless the entry sets `failClosed: true`; `init --hooks
|
|
105
|
+
cursor` sets it. `afterShellExecution` carries no exit code, so a gate command seen only there never passes; the
|
|
106
|
+
config written by `init` uses `preToolUse` and `postToolUse`.
|
|
107
|
+
- Codex CLI: there is no failure event, and the tool result of a shell call is the plain output without the exit
|
|
108
|
+
status (seen live in 0.172.0). A gate command seen there is recorded neither as a pass nor as a failure; the agent
|
|
109
|
+
is told to run `stopbar run build|test`, which runs the command and records its real exit status. Codex loads
|
|
110
|
+
`.codex/` (config and hooks) only in a trusted project and asks the user to review and trust project hooks; until
|
|
111
|
+
then they do not run (a live run in an untrusted folder loaded none).
|
|
112
|
+
- Gemini CLI: an exit other than 0 and 2 is only a warning, and invalid JSON output counts as "allow". Stopbar exits
|
|
113
|
+
2 for every block and internal error, but a crash before Stopbar's own handler (for example a missing Node.js)
|
|
114
|
+
fails open. Gemini CLI warns when a project hook changes and treats it as untrusted.
|
|
115
|
+
- Antigravity CLI: hooks of a workspace load only after the folder is trusted. A message after a tool call
|
|
116
|
+
(PostToolUse) cannot reach the agent; it sees the reason at its next blocked call. An allowed call returns an
|
|
117
|
+
empty answer, so Antigravity's own permission rules still apply on top of Stopbar (checked live).
|
|
118
|
+
- Git fallback: git hooks see only commits and pushes, not reads or shell commands, so the secret gate needs an agent
|
|
119
|
+
hook to record the read. `git commit --no-verify` and `git push --no-verify` skip git hooks.
|
|
120
|
+
|
|
121
|
+
For a hostile-agent threat model, run the agent in a container or VM: no network by default, the repository mounted
|
|
122
|
+
read-write, `.git/stopbar` and `.claude` mounted read-only or owned by another user, and the human commands run outside
|
|
123
|
+
the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the boundary.
|
|
124
|
+
|
|
125
|
+
## Known limits of 1.1.0
|
|
126
|
+
|
|
127
|
+
- Lean: the check needs Docker and a one-time image build with network access. The base image is pinned by digest and
|
|
128
|
+
the Lean archive by sha256, both recorded at the first build (trust on first use). The Lean export is not
|
|
129
|
+
deterministic: each export is a different proof tree, and the gate checks the one it exports.
|
|
130
|
+
- Platforms: the unit tests, E2E, `stopbar probe` and `stopbar prove` pass on Windows 11 with Git for Windows and on
|
|
131
|
+
Linux (Debian 13, Node 24, git 2.47). A live Claude Code session ran on Windows. macOS is not tested.
|
|
132
|
+
- Adapters: Cursor, Codex CLI, Gemini CLI and Antigravity CLI are spec-tested (see the README table); a client can
|
|
133
|
+
change its hook schema in a later version.
|
|
134
|
+
- Hook latency: Windows starts a process in 50–70 ms, so a hook with one git process takes about 120–200 ms in all.
|
|
135
|
+
|
|
136
|
+
## Reporting a vulnerability
|
|
137
|
+
|
|
138
|
+
Send a private report to the maintainers before you publish it. Include the Stopbar version, `stopbar doctor --json`
|
|
139
|
+
and `stopbar attest` output and a minimal reproduction (the probe's JSON format in `tests/regressions/` is welcome).
|
package/bin/stopbar.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Entry point. Loads only the compiled dist/ (no TypeScript, no prover in hooks).
|
|
3
|
+
import('../dist/cli.js').catch((e) => {
|
|
4
|
+
process.stderr.write(`STOPBAR FAIL-CLOSED: cannot load dist/cli.js (${e && e.message}). Run: npm run build\n`)
|
|
5
|
+
process.exitCode = 2
|
|
6
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "*",
|
|
6
|
+
"hooks": [{"type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.git/stopbar/runtime/bin/stopbar.mjs\" hook", "timeout": 30}]
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"PostToolUse": [
|
|
10
|
+
{
|
|
11
|
+
"matcher": "Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell",
|
|
12
|
+
"hooks": [{"type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.git/stopbar/runtime/bin/stopbar.mjs\" hook", "timeout": 60}]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"PostToolUseFailure": [
|
|
16
|
+
{
|
|
17
|
+
"matcher": "Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell",
|
|
18
|
+
"hooks": [{"type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.git/stopbar/runtime/bin/stopbar.mjs\" hook", "timeout": 60}]
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"Stop": [
|
|
22
|
+
{
|
|
23
|
+
"hooks": [{"type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.git/stopbar/runtime/bin/stopbar.mjs\" hook", "timeout": 30}]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Built from src/adapters/antigravity.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// Antigravity CLI (agy; hooks.json in the customization root, e.g. <workspace>/.agents/hooks.json). camelCase payloads:
|
|
3
|
+
// hookEventName, toolCall {id, name, args}, cwd, workspacePaths; PostToolUse carries `error` when the tool failed;
|
|
4
|
+
// Stop carries continuationActive. Output is JSON on stdout: PreToolUse {"decision": "deny", "reason"}; Stop
|
|
5
|
+
// {"decision": "continue", "reason"} keeps the agent working. Tool names are the lower-cased step types.
|
|
6
|
+
import { byName, commandText, edit, json, make, outbound, pathsOf, read, shell, } from './types.js'
|
|
7
|
+
|
|
8
|
+
// names seen in a live Antigravity CLI 1.5.18 session (write_file with Path) plus the step types of its hooks spec
|
|
9
|
+
const EDIT = new Set(['write_file', 'write_to_file', 'replace_file_content', 'multi_replace_file_content', 'sed_file', 'notebook_edit', 'code_action',
|
|
10
|
+
'file_change', 'propose_code', 'write_blob', 'edit_notebook', 'delete_directory', 'move'])
|
|
11
|
+
const READ = new Set(['view_file', 'view_file_outline', 'view_code_item', 'view_content_chunk', 'read_notebook', 'list_directory', 'list_dir', 'find', 'find_by_name', 'code_search', 'read_resource'])
|
|
12
|
+
const OUT = new Set(['read_url_content', 'search_web', 'open_browser_url', 'read_browser_page', 'execute_browser_javascript', 'click_browser_pixel', 'mcp_tool', 'call_mcp_tool'])
|
|
13
|
+
|
|
14
|
+
function tool(name , args ) {
|
|
15
|
+
if (name === 'run_command' || name === 'shell_exec' || name === 'send_command_input' || name === 'notebook_execution') return shell(commandText(args.CommandLine ?? args.Command ?? args.command ?? args.Input ?? ''))
|
|
16
|
+
if (EDIT.has(name)) return edit(pathsOf(args))
|
|
17
|
+
if (READ.has(name)) return read(pathsOf(args))
|
|
18
|
+
if (name === 'grep_search') return {tool_name: 'Grep', tool_input: {pattern: args.Query ?? args.query, path: args.SearchPath ?? args.SearchDirectory}}
|
|
19
|
+
if (OUT.has(name) || name.startsWith('browser_') || name.startsWith('capture_browser_')) return outbound(name === 'mcp_tool' || name === 'call_mcp_tool' ? `mcp__${args.ServerName ?? args.serverName ?? 'server'}__${args.ToolName ?? args.toolName ?? 'tool'}` : name)
|
|
20
|
+
return byName(name, args, args.CommandLine)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const antigravity = {
|
|
24
|
+
name: 'antigravity',
|
|
25
|
+
detect: (i) => typeof i.hookEventName === 'string' || (typeof i.toolCall === 'object' && i.toolCall !== null) || typeof i.conversationId === 'string',
|
|
26
|
+
normalize(i) {
|
|
27
|
+
const ev = String(i.hookEventName ?? '')
|
|
28
|
+
const cwd = typeof i.cwd === 'string' && i.cwd ? i.cwd : Array.isArray(i.workspacePaths) ? i.workspacePaths[0] : undefined
|
|
29
|
+
const call = (i.toolCall ?? {})
|
|
30
|
+
const args = (call.args && typeof call.args === 'object' ? call.args : {})
|
|
31
|
+
if (ev === 'PreToolUse') return {kind: 'pre-tool', event: make('antigravity', i, ev, {hook_event_name: 'PreToolUse', cwd, ...tool(String(call.name ?? ''), args)}, {tool: call.name})}
|
|
32
|
+
if (ev === 'PostToolUse') {
|
|
33
|
+
const failed = typeof i.error === 'string' ? i.error.length > 0 : !!i.error
|
|
34
|
+
return {kind: failed ? 'post-tool-failure' : 'post-tool', event: make('antigravity', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd,
|
|
35
|
+
...tool(String(call.name ?? ''), args), tool_response: failed ? {error: i.error} : {}}, {tool: call.name})}
|
|
36
|
+
}
|
|
37
|
+
if (ev === 'Stop') return {kind: 'stop', event: make('antigravity', i, ev, {hook_event_name: 'Stop', cwd, stop_hook_active: i.continuationActive === true})}
|
|
38
|
+
return {kind: 'other', event: null}
|
|
39
|
+
},
|
|
40
|
+
render(kind, out) {
|
|
41
|
+
if (kind === 'pre-tool') return out.code === 0 ? {code: 0} : {code: 0, stdout: json({decision: 'deny', reason: out.msg ?? 'blocked by stopbar'}) + '\n', stderr: (out.msg ?? '') + '\n'}
|
|
42
|
+
if (kind === 'stop') return out.code !== 0 && out.msg ? {code: 0, stdout: json({decision: 'continue', reason: out.msg}) + '\n'} : {code: 0, stdout: '{}\n'}
|
|
43
|
+
return {code: 0, stdout: '{}\n'}
|
|
44
|
+
},
|
|
45
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Built from src/adapters/claude.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// Claude Code: the payload already is the internal event (v1.0 behaviour, unchanged).
|
|
3
|
+
// Output: exit 0 allows, exit 2 blocks; the reason goes to stderr (stdout for exit 0 messages).
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const KIND = {PreToolUse: 'pre-tool', PostToolUse: 'post-tool', PostToolUseFailure: 'post-tool-failure', Stop: 'stop'}
|
|
7
|
+
|
|
8
|
+
export const claude = {
|
|
9
|
+
name: 'claude',
|
|
10
|
+
detect: (i) => typeof i.hook_event_name === 'string',
|
|
11
|
+
normalize(i) {
|
|
12
|
+
const kind = KIND[i.hook_event_name] ?? 'other'
|
|
13
|
+
return {kind, event: kind === 'other' ? null : (i )}
|
|
14
|
+
},
|
|
15
|
+
render(_kind, out) {
|
|
16
|
+
if (!out.msg) return {code: out.code}
|
|
17
|
+
return out.code === 0 ? {code: 0, stdout: out.msg + '\n'} : {code: out.code, stderr: out.msg + '\n'}
|
|
18
|
+
},
|
|
19
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Built from src/adapters/codex.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// Codex CLI (hooks.json, Claude Code compatible events). Schemas from the CLI's own command-hook JSON schemas
|
|
3
|
+
// (pre-tool-use / post-tool-use / stop .command.input and .command.output): every input carries turn_id and model.
|
|
4
|
+
// There is no failure event: PostToolUse also follows a failed command, so a gate passes only with an exit code 0
|
|
5
|
+
// found in tool_response. Output: JSON on stdout with exit 0 (permissionDecision deny / decision block).
|
|
6
|
+
import { byName, commandText, edit, exitCodeIn, json, make, patchPaths, shell, } from './types.js'
|
|
7
|
+
|
|
8
|
+
const SHELL = new Set(['Bash', 'shell', 'exec_command', 'local_shell', 'unified_exec', 'shell_command', 'container.exec'])
|
|
9
|
+
|
|
10
|
+
function tool(name , ti ) {
|
|
11
|
+
if (SHELL.has(name)) return shell(commandText(ti.command ?? ti.cmd ?? ti.argv))
|
|
12
|
+
if (name === 'apply_patch') return edit(patchPaths(ti.input ?? ti.patch ?? ti.command))
|
|
13
|
+
if (name.startsWith('mcp__')) return {tool_name: name, tool_input: ti}
|
|
14
|
+
if (['Edit', 'Write', 'MultiEdit', 'Read', 'Grep', 'Glob', 'WebFetch', 'WebSearch'].includes(name)) return {tool_name: name, tool_input: ti}
|
|
15
|
+
return byName(name, ti, ti.command)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const codex = {
|
|
19
|
+
name: 'codex',
|
|
20
|
+
detect: (i) => typeof i.hook_event_name === 'string' && typeof i.turn_id === 'string',
|
|
21
|
+
normalize(i) {
|
|
22
|
+
const ev = i.hook_event_name, ti = (i.tool_input && typeof i.tool_input === 'object' ? i.tool_input : {})
|
|
23
|
+
if (ev === 'PreToolUse') {
|
|
24
|
+
const t = tool(String(i.tool_name ?? ''), ti)
|
|
25
|
+
return {kind: 'pre-tool', event: make('codex', i, ev, {hook_event_name: 'PreToolUse', cwd: i.cwd, ...t}, {tool: i.tool_name})}
|
|
26
|
+
}
|
|
27
|
+
if (ev === 'PostToolUse') {
|
|
28
|
+
const t = tool(String(i.tool_name ?? ''), ti)
|
|
29
|
+
const code = exitCodeIn(i.tool_response)
|
|
30
|
+
const failed = code !== undefined && code !== 0
|
|
31
|
+
return {kind: failed ? 'post-tool-failure' : 'post-tool',
|
|
32
|
+
event: make('codex', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd: i.cwd, ...t,
|
|
33
|
+
tool_response: code === undefined ? i.tool_response : {exitCode: code}}, {requireExitCode: true, tool: i.tool_name})}
|
|
34
|
+
}
|
|
35
|
+
if (ev === 'Stop') return {kind: 'stop', event: make('codex', i, ev, {hook_event_name: 'Stop', cwd: i.cwd, stop_hook_active: i.stop_hook_active === true})}
|
|
36
|
+
return {kind: 'other', event: null}
|
|
37
|
+
},
|
|
38
|
+
render(kind , out) {
|
|
39
|
+
if (kind === 'pre-tool') {
|
|
40
|
+
if (out.code === 0) return {code: 0}
|
|
41
|
+
return {code: 0, stdout: json({hookSpecificOutput: {hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: out.msg ?? 'blocked by stopbar'}}) + '\n', stderr: (out.msg ?? '') + '\n'}
|
|
42
|
+
}
|
|
43
|
+
if (kind === 'post-tool' || kind === 'post-tool-failure' || kind === 'stop') {
|
|
44
|
+
return out.msg && out.code !== 0 ? {code: 0, stdout: json({decision: 'block', reason: out.msg}) + '\n'} : {code: 0}
|
|
45
|
+
}
|
|
46
|
+
return {code: 0}
|
|
47
|
+
},
|
|
48
|
+
}
|