feat(delivery): add the guard hook (ADR-0032 layer 2)

Ship one pre-tool-use hook in the delivery package. It denies the Never
tier on every runtime and asks before Odd jobs on Claude Code and Copilot
CLI (denying them on Codex and unknown runtimes):

- guard.py: stdlib-only Python; tokenises the shell line, unwraps
  bash -c / env / sudo / eval / xargs / find -exec / rtk / uv run and
  friends, checks file-tool paths for secret material, and uses read-verb
  allowlists for kubectl, helm, flux and tofu
- hooks.json: no matcher, onFailure: block, 10s timeout
- tests/test-delivery-guard-hook.sh: 281 cases incl. bypass attempts and
  per-runtime output shape
- root apm.yml: executables.allow delivery#0.1.0
- check-executables-allow-sync now covers every plugin shipping hooks/bin
- ADR-0032 amended: Copilot ask kept as an accepted risk, file tools and
  allowlists recorded

Refs #190

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012CqgnwEGtmfsjcoG9QwByN
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-11-23 08:15:14 +00:00
1 parent 6edd66432c
commit a6ff1c14d4
11 files changed
+2244 -110

No files matched your search

+21 -11
View File
@@ -55,7 +55,7 @@ Nine hooks, grouped below by what they guard rather than by the order `.pre-comm
| Hook | Guards |
|---|---|
| `check-scope-walkup-sync` | `validate.sh`, `validate-provenance.sh`, `new-agent.sh` and `new-skill.sh`'s four independent `$HOME`/`.git`/`apm.yml` walk-up ports still agree behaviorally |
| `check-executables-allow-sync` | root `apm.yml`'s `executables.allow` key names kyberforge's actual version (see [apm gates](#apm-gates)) |
| `check-executables-allow-sync` | root `apm.yml`'s `executables.allow` carries a `<name>#<version>` key naming the actual version of every plugin that ships executables (`.apm/hooks/` or `bin/`) (see [apm gates](#apm-gates)) |
`check-executables-allow-sync` is the odd one in this group: the drift it guards is in a
hand-written key rather than in generated text, and it is a record-keeping gate — the grant itself is
@@ -1249,22 +1249,32 @@ it is never called with a single key: `install/exec_gate.py` builds a candidate
the version-blind name alongside `<package>#<version>`, and `materialize_exec_map` stores every
approved key **under its version-blind name as well**. `_map_grants` matches the same three ways.
**Correction (2026-09-19):** verified against apm 0.28.0, a kyberforge version bump therefore does
**Correction (2026-09-19):** verified against apm 0.28.0, a package version bump therefore does
*not* stop the entry matching — approving `owner/repo#2.0.0` also covers `owner/repo#2.1.0` through
the version-blind alias. The earlier claim here ("no wildcard and no version-less form", so the
entry silently stops matching and the `SessionStart` hook stops deploying) described apm's behaviour
wrongly, and ADR-0019 carries the same correction.
The gate is still required, for a repo-level reason rather than an apm-level one:
`scripts/check-executables-allow-sync.sh` asserts the key matches `plugins/kyberforge/apm.yml`'s
`version:`, so a bump without a key edit fails *this repo's* pre-push, and the key stays an accurate
record of what was approved.
The gate is still required, for a repo-level reason rather than an apm-level one: it asserts each
key matches its plugin's `version:`, so a bump without a key edit fails *this repo's* pre-push, and
every key stays an accurate record of what was approved.
`scripts/check-executables-allow-sync.sh` parses `version:` out of `plugins/kyberforge/apm.yml` and
asserts root `apm.yml` carries the matching `kyberforge#<version>` key. A comment in the
`executables:` block stays as the human-facing pointer; the hook is what actually holds. It parses
with PyYAML where importable and falls back to a two-shape scan otherwise, so a missing pip package
cannot become the thing that blocks every push.
It covers every plugin that ships executables, not one named package. The script scans
`plugins/*/` and treats a plugin as shipping executables when `plugins/<name>/.apm/hooks/` or
`plugins/<name>/bin/` exists — kyberforge ships both, delivery ships a guard hook. For each one it
reads `name:` and `version:` from `plugins/<name>/apm.yml` and asserts root `apm.yml` carries the
`<name>#<version>` key under `executables.allow`. Keys use the package name, so a `name:` that
differs from the directory name fails rather than being guessed at. Every failing package is
reported in one run, each with its own Why/Fix block; a stale `<name>#<other-version>` key is quoted
back as "found instead". It also fails on a shipping plugin with no `apm.yml`, a missing `version:`,
a missing root `apm.yml`, or no `executables.allow` mapping. A repo with no executable-shipping
plugin at all is the one no-op, and a plugin with neither directory needs no key.
A comment in the `executables:` block stays as the human-facing pointer; the hook is what actually
holds. It parses with PyYAML where importable and falls back to a two-shape scan otherwise, so a
missing pip package cannot become the thing that blocks every push. The PyYAML reader refuses an
unquoted two-component version, which YAML reads as a float, instead of comparing a form the reader
invented.
## `.claude/settings.json`