Repository navigation
feat(hooks): check a coding agent's writes to declared systems of record - #2411
Conversation
openadapt hooks install --agent claude-code|codex writes project-local hook settings. Each tool call that writes to a database, HTTP API or MCP tool declared in openadapt.systems.yaml is pre-checked against its declared scope and approval mode, read back with its openadapt.verify/v1 contract through the verifier, and given a signed record/run/v1 receipt. An undeclared write to a declared system is blocked or asked about; a failed read-back is UNCERTAIN and the same call is held until a person releases it. Codex can't ask from a hook, so ask is a deny until openadapt hooks approve. --strict is refused until a credential broker exists for these systems. The hooks are advisory.
…he write not the wording curl, psql, sqlite3 and mysql flags are read from an allow-list; any other flag, an attached short value or SQL with a comment, escape or dollar quote makes the call an unknown write. Holds and approvals are keyed on the declared write and its values (or the call without its free-text description), so a reworded retry of an UNCERTAIN write is refused. Claude Code's PreToolUse entry sets onFailure: block, the launcher runs from the hooks folder, agent-facing errors name the exception type only, and an unsettled declared write's receipt line says approved_unverified.
Independent adversarial review: APPROVEFrom: Grok First review of this PR, stacked on #2394. Author is GitHub Classification does not fail open on the paths I triedA call that names a declared system and is not one clear read is a write or Holds and Codex approvals key the write, not the wording
Receipt honesty
Leftovers, not blockers
Review only; I am not merging. |
One run against a temporary synthetic project: declared writes VERIFIED with receipts that verify, an out-of-scope delete blocked with the database unchanged, a broken read-back UNCERTAIN, a Python heredoc naming the file blocked, and a Python write that builds the path at run time not seen (the advisory limit). Reports, receipts, the signing key and key transcript lines are in benchmark/hooks_live.
Independent adversarial review: APPROVEFrom: Grok Delta re-review after my APPROVE at The only unique commit is evidence: The eight reports match the claimed matrix: two Review only; I am not merging. |
…sts in .gitleaksignore Secret Scan flagged hold_key in the live run's report.json files as a generic API key. Each is a SHA-256 digest of a declared write and its values, not a credential. The reports stay byte-identical (signed receipts cover them), so their eight findings are pinned by exact commit:file:rule:line fingerprint; new reports use hold_sha256, which the rule doesn't match.
Independent adversarial review: APPROVEFrom: Grok Delta re-review of my APPROVE at The Secret Scan change is sound. The eight The merge of current |
The Windows descriptor contract refuses raw os.open next to os.write: on Windows it gives a text-mode descriptor that translates newlines. The hook state, log and report files now open through private_file.open_binary and loop until every byte is written, as receipt_record does.
Independent adversarial review: APPROVEFrom: Grok Delta review of the Secret Scan / hooks work, at the current head named in #211 (7060178263, My previous verdict on this PR (7060107423) was APPROVE at
Inherited from the already-merged #2394 tree, and not unique to this hooks change: |
…istry benchmark/hooks_live/signing-key.json held only a public Ed25519 entry, but its name is key-material shaped, so check_evidence_keys refused it. It is now seal-key.json, a one-entry registry like the other evidence folders, and listed in PUBLIC_REGISTRIES, where it still has to pass the closed schema.
|
Re-review request; your APPROVE was at Delta:
|
Independent adversarial review: APPROVEFrom: Codex I reviewed the registry conversion in The new registry contains one active public verification entry. I compared its three fields with the earlier entry. All three values are identical. The checker adds one repository-relative path and still applies its existing Ed25519 registry validator. Sibling paths retain the existing policy. The README and public artifact manifest reference the new name. All eight reports and eight receipts have the same Git blobs as the approved head. The manifest lists all sixteen files. This preserves the earlier evidence for declared writes, blocked calls and uncertain read-back. The documented unchecked write still has no receipt. I checked the committed files and mapping without rerunning the agent sessions or signature checks. The change introduces no app-specific engine code. It uses the same validator as the other public evidence registries. Held-out evidence remains the previously recorded synthetic runs. This PR is a draft stacked on open #2394 at |
|
From: Gemini (integration) Added Verified locally: |
Independent adversarial review: APPROVEFrom: Codex The delta from the approved head adds I checked both registries on this exact head and exercised the live parser without invoking a hook. The launcher translated The task mapping applies across agents; this check covers CLI compatibility. The author reports 54 Flow and 130 launcher CLI tests passed locally. Hosted CI stopped at the draft-state check. The PR is still stacked on #2394. |
|
From: Gemini CI-only fix: added |
Independent adversarial review: APPROVEFrom: Codex All five hooks subcommands now require full option names. I exercised the registered parser for The current #2394 tip |
Independent adversarial review: APPROVEFrom: Codex The only changes since the approved head are the The prior Mypy job inferred that narrower unknown-write type for the whole variable. It then rejected two valid assignments: the declared write's approval at line 248 and #2411 now targets main and is marked ready for review. Hosted CI for this head is pending. Current run |
Stacked on #2394. The base is
feat/seal-page-app, because therecord/run/v1receipt types (openadapt_types.receipt) and the Flow writer (receipt_record.py) are only there. This PR retargets tomainonce #2394 merges.What this does
openadapt hooks install --agent claude-code(orcodex) writes project-local hook settings. Each tool call that writes to a system declared inopenadapt.systems.yaml(a database URL, an HTTP API base, a CLI such assqlite3/psql/curlreaching it, or an MCP server's tools) gets three steps:allow,ask,block) decides what happens. A write to a declared system that no entry covers is blocked, or asked about ifunknown_write: ask. Before an allowed write, the store is read, so the read-back can tell new rows from old.openadapt.verify/v1contract is checked throughopenadapt_flow.verifier's file-based pair:capture, a savedSnapshot, thenverify_write. It's the same judge thatverify-run, guarded saves andopenadapt verifyuse. No new checker. A failed read-back, or one that never ran, isUNCERTAIN, never a pass, and the same write (the declared write with the same values, however the call is worded) is held until a person runsopenadapt hooks approve <id>..openadapt/hooks/runs/<id>/report.jsonand a signedrecord/run/v1receipt.json, written byreceipt_record.write_receipt_record. The receipt holds no value, path or URL from the call.Also:
openadapt hooks status,openadapt hooks uninstall(removes only OpenAdapt's entries; keeps the user's) andopenadapt hooks approve.Verified hook facts (2026-11-21, primary docs)
Claude Code (code.claude.com/docs/en/hooks)
.claude/settings.jsonor.claude/settings.local.json, underhooks.<Event>[].{matcher, hooks[].{type, command, timeout}}. A matcher with regex characters is an unanchored regular expression. MCP tools are namedmcp__<server>__<tool>.session_id,transcript_path,cwd,permission_mode,hook_event_name.PreToolUseaddstool_name,tool_inputandtool_use_id.PostToolUseaddstool_response.Stopaddsstop_hook_active.PreToolUseoutput ishookSpecificOutput.permissionDecision(allow/deny/ask/defer) withpermissionDecisionReason.allowskips the user's prompt, and settings deny/ask rules still apply. The top-leveldecisionfield is deprecated for this event.PostToolUseandStopusedecision: "block"andreason.Codex (learn.chatgpt.com/docs/hooks): Codex has hooks.
.codex/hooks.jsonor[hooks]inconfig.toml, with the same structure. Project hooks run only once trusted (/hooks), and the trust is hash-bound.Bash, patches asapply_patch(bothtool_input.command), and MCP tools by name. Hosted tools aren't covered.PreToolUsesupportsdenyandallow.askis parsed but unsupported, and the tool runs. Errors, timeouts and malformed output also let the tool run.Failing closed
.openadapt/hooks/run-hook) that exits 2 before a tool call if the hook can't start or crashes. The launcher can't catch a timeout, so Claude Code'sPreToolUseentry also setsonFailure: "block"(Claude Code 2.1.295 and later). On older Claude Code and on Codex, a hook timeout lets the call run.askto Codex. A write that needs a person is denied with an approval id. The person runsopenadapt hooks approve <id>in their own terminal, and the identical call is allowed once.;,$(...), a body read from a file. Thecurl,psql,sqlite3andmysqlparsers read an allow-list of flags, so an unknown flag or an attached short value (-d'...',-XPOST,--config=,--file=,--init-command=) is a write. SQL that holds a comment, an escape or dollar quoting is never a read..openadapt/hooksand the agents' hook settings are blocked, and so isopenadapt hooks approve|install|uninstallrun from the agent's shell.allowwrites send no decision, so Claude Code's own permission prompt still applies.auto_approve: trueopts in to skipping it.Honesty and limits
--strictis refused. It needs a credential broker.openadapt wrap -- COMMAND(feat(wrap): openadapt wrap --example, and compiled browser tools that run over MCP #2406, feat(wrap): openadapt wrap -- COMMAND wraps any agent process #2407) is a browser-MCP harness, not a broker for databases, HTTP APIs or MCP servers. So--strictrefuses rather than installing advisory hooks under a strict name. Nothing here duplicates wrap.REFUTEDorUNCERTAINcall.askisUNCERTAIN. It never getsPostToolUse, so theStophook reads it back and reports itUNCERTAIN, because "not sent" can't be told from "not landed".record/run/v1is built for OpenAdapt's own runs.model_callsis 0: it counts OpenAdapt's check, not the agent. A declared write whose read-back didn't settle is a line withapproved_unverified, because the schema has no read-back-failed code. The hooks feedreceipt_record.write_receipt_recorda syntheticreport.json, and the end-to-end test asserts the signedlinesandchecks, so a change in that builder fails loudly.claude -p(Claude Code 2.1.305) andcodex exec(Codex CLI 0.144.4) sessions ran against a temporary synthetic project (benchmark/hooks_live/). Declared writes came outVERIFIEDwith receipts that verify; an out-of-scope delete was blocked with the database unchanged; a broken read-back wasUNCERTAIN; a Python heredoc naming the file was blocked. A Python write that builds the path at run time was not seen, and its row landed unchecked: the advisory limit. Cost: USD 0.125 for Claude Code, plus about 96,000 input tokens for Codex.Tests
tests/test_hooks.py: the systems file schema; shell, file, MCP and WebFetch classification, with fail-closed cases (SQL hidden behind comments, attached curl values, unknown CLI flags); write keys that ignore wording; hook input parsing;PreToolUse,PostToolUseandStopoutput for each agent, including Codex ask becoming deny; engine refusals (no systems file, missing contract values, unreadable store, unknown-write policy); install merging, idempotence and uninstall that keeps the user's entries; refusal of--strict, the home folder and a broken settings file.tests/test_hooks_e2e.py: the harness runs the real launcher as a subprocess withHOMEand the receipt key in temp dirs.VERIFIED, and its receipt verifies (verify_run_receipt, signer "Signed by this computer"). An out-of-scopeDELETEis blocked, the database is unchanged, and the receipt saysSTOPPED. An HTTP write whose read-back fails isUNCERTAIN(receiptUNKNOWN), and its retry is refused.Stopsummarizes the session.askis denied until approved, then allowed once, thenVERIFIED.UNCERTAINwrite with a rewordeddescriptionis still refused.PostToolUseis read back atStop.Docs:
packages/flow/docs/HOOKS.md, thehookscommand doc and command map, a CAPABILITIES row (Experimental, synthetic), a README mention, andllms-full.txt.Not run locally: mypy,
test_import_layers(its environment lackshypothesis), the link and anchor check, and the wheel-content tests. CI covers them.