feat(rtk): add an rtk plugin that routes Bash calls through rtk #284

Merged
Defame1297 merged 8 commits from feat/179-rtk-plugin into main 2026-12-06 15:31:00 +00:00
Owner

Closes #179

Summary

  • New opt-in plugin plugins/rtk v0.1.0 (Claude target only).
  • PreToolUse Bash hook route-through-rtk.sh runs rtk hook claude when rtk is on PATH and is silent otherwise. Any rtk failure exits 0 with no output, so the hook can never block a Bash call (PreToolUse exit 2 blocks, and clap exits 2 on usage errors). The plugin does not run rtk init.
  • plugins/rtk/README.md covers approval, overlap with a global rtk init -g hook, apm's "ambiguous duplicate APM-owned hook entry" error, pre-approval, and notes it was tested with rtk 0.42.4.
  • Root apm.yml dependency, .claude-plugin/marketplace.json entry, and an executables.allow grant.
  • ADR-0032 amended: rtk may return permissionDecision: allow. That is accepted because hooks are guardrails, not the safety boundary, and the git push guard still sees rtk git push.

Gate change

A new hook-shipping plugin could not be pushed: check-executables-allow-sync requires the root dependency, while apm-audit-ci ref-consistency fails until the plugin is on the remote's main (ADR-0019).

  • scripts/apm-audit-ci.sh now waives exactly that root failure for a plugins/<name> that is present locally but absent from local origin/main. It then re-runs the full 15-check root audit in a private scratch copy without that dependency and requires it to pass.
  • ADR-0026 amended; docs/spec/gates.md and LESSONS.md updated.
  • tests/test-apm-audit-ci-waiver.sh (28 cases).

Verification

  • tests/test-rtk-hook.sh: 11/11, including real rtk 0.42.4.
  • tests/run-tests.sh --strict: all suites pass.
  • shellcheck clean.
  • All pre-commit and pre-push hooks pass. apm-audit-ci passes via the waiver; the root re-run reports "All 15 check(s) passed".

Review

  • Plugin: 2 rounds. Round 1 caught the exit-2 blocking bug.
  • Gate waiver: 2 rounds. Round 1 caught skipped root checks and the ADR-0026 contradiction.

Follow-ups / human steps

  1. After merge, open a chore(apm): deploy rtk PR that runs uv run --frozen apm update to record plugins/rtk in apm.lock.yaml. The waiver then stops applying to rtk.
  2. After merge, cut and push release tag rtk-v0.1.0 via scripts/tag-plugin-releases.sh (maintainer approval required).
  3. Non-blocking polish:
    • Add a real-rtk test that an already-prefixed rtk git status passes through.
    • Give a clear error if timeout is missing in tests/test-rtk-hook.sh.
    • README should say apm audit raises the duplicate error.
    • Waiver: copy .git/info/exclude into the scratch repo. The wording in gates.md and the script header claims origin is the only git state apm reads, but deployed-files-present uses git check-ignore.
    • Waiver: exclude ./.claude/worktrees from the scratch copy.
    • Waiver: add a test for the deletions-only / post-reduce guards.
    • Waiver: document that a stale, unfetched origin/main keeps the waiver alive (fails safe).

🤖 Generated with Claude Code

https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi

Closes #179 ## Summary - New opt-in plugin `plugins/rtk` v0.1.0 (Claude target only). - PreToolUse `Bash` hook `route-through-rtk.sh` runs `rtk hook claude` when `rtk` is on `PATH` and is silent otherwise. Any rtk failure exits 0 with no output, so the hook can never block a Bash call (PreToolUse exit 2 blocks, and clap exits 2 on usage errors). The plugin does not run `rtk init`. - `plugins/rtk/README.md` covers approval, overlap with a global `rtk init -g` hook, apm's "ambiguous duplicate APM-owned hook entry" error, pre-approval, and notes it was tested with rtk 0.42.4. - Root `apm.yml` dependency, `.claude-plugin/marketplace.json` entry, and an `executables.allow` grant. - ADR-0032 amended: rtk may return `permissionDecision: allow`. That is accepted because hooks are guardrails, not the safety boundary, and the git push guard still sees `rtk git push`. ## Gate change A new hook-shipping plugin could not be pushed: `check-executables-allow-sync` requires the root dependency, while `apm-audit-ci` ref-consistency fails until the plugin is on the remote's `main` (ADR-0019). - `scripts/apm-audit-ci.sh` now waives exactly that root failure for a `plugins/<name>` that is present locally but absent from local `origin/main`. It then re-runs the full 15-check root audit in a private scratch copy without that dependency and requires it to pass. - ADR-0026 amended; `docs/spec/gates.md` and `LESSONS.md` updated. - `tests/test-apm-audit-ci-waiver.sh` (28 cases). ## Verification - `tests/test-rtk-hook.sh`: 11/11, including real rtk 0.42.4. - `tests/run-tests.sh --strict`: all suites pass. - shellcheck clean. - All pre-commit and pre-push hooks pass. `apm-audit-ci` passes via the waiver; the root re-run reports "All 15 check(s) passed". ## Review - Plugin: 2 rounds. Round 1 caught the exit-2 blocking bug. - Gate waiver: 2 rounds. Round 1 caught skipped root checks and the ADR-0026 contradiction. ## Follow-ups / human steps 1. After merge, open a `chore(apm): deploy rtk` PR that runs `uv run --frozen apm update` to record `plugins/rtk` in `apm.lock.yaml`. The waiver then stops applying to rtk. 2. After merge, cut and push release tag `rtk-v0.1.0` via `scripts/tag-plugin-releases.sh` (maintainer approval required). 3. Non-blocking polish: - Add a real-rtk test that an already-prefixed `rtk git status` passes through. - Give a clear error if `timeout` is missing in `tests/test-rtk-hook.sh`. - README should say `apm audit` raises the duplicate error. - Waiver: copy `.git/info/exclude` into the scratch repo. The wording in `gates.md` and the script header claims origin is the only git state apm reads, but `deployed-files-present` uses `git check-ignore`. - Waiver: exclude `./.claude/worktrees` from the scratch copy. - Waiver: add a test for the deletions-only / post-reduce guards. - Waiver: document that a stale, unfetched `origin/main` keeps the waiver alive (fails safe). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Claude added 8 commits 2026-12-06 10:21:06 +00:00
A Claude Code PreToolUse hook on Bash execs `rtk hook claude` when rtk is on PATH and passes its answer through unchanged; without rtk it exits 0 silently. It acts only from .claude/hooks/, like git's push guard.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Stub rtk, rtk absent, the .claude/hooks/ guard, the real rtk when installed, and the hooks.json wiring.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Adds the git+path dependency, the hooks grant for plugins/rtk#0.1.0 and the marketplace package entry, and regenerates marketplace.json with apm pack.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Records that the hook may return permissionDecision: allow, accepted because hooks are guardrails, and that git's push guard still sees rtk git push.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
The hook ran `exec rtk hook claude`, so rtk's exit code became the hook's.
Claude Code treats a PreToolUse exit 2 as "block this tool call", and rtk
(clap) exits 2 on a usage error, e.g. an older rtk without `hook claude`.
On such a machine every Bash call would have been blocked.

The hook now captures rtk's stdout and always exits 0. On any non-zero rtk
exit it prints nothing, so the call proceeds unchanged. On success it prints
rtk's output only when non-empty, with no stray blank line. stdin still
reaches rtk.

Tests cover a stub rtk exiting 2 with stderr, exiting 1, and exiting 0 with
no output, and note that the real-rtk pass-through case depends on rtk
0.42.4's built-in rules.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
A first-landing hook- or bin-shipping plugin could not be pushed.
check-executables-allow-sync requires its git+path entry in root apm.yml,
but root dependencies resolve from the remote's main (ADR-0019), so the
lock cannot record the plugin until it lands and root `apm audit --ci`
fails ref-consistency with `<identity>/plugins/<name>: not found in
lockfile`. No state of the branch satisfied both gates.

scripts/apm-audit-ci.sh now waives the root audit only when the sole
failure is ref-consistency (`1 of 3 check(s) failed`, as apm 0.39.3
prints it), every detail line is that form for the identity root
apm.yml's own git+path entry yields, plugins/<name>/apm.yml exists in
the working tree, and the plugin is absent from the local origin/main.
No fetch; a missing origin/main or unrecognised output fails closed. The
waiver lapses for a plugin once it is on origin/main, when the follow-up
lock PR must record it.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Why: on apm 0.39.3 a failing ref-consistency stops the root run after
three checks, so while the unlanded-plugin waiver applied, the other twelve
root checks (content-integrity, hook-approval-pins, local-bundle-hooks,
exec-status-current, deployed-files-present, ...) never ran.

Implementation notes: once the waiver's conditions hold, the hook copies
the working tree (minus .git and .venv) into a mktemp dir. There it drops
only the waived plugins' dependencies.apm items, checks the diff is
deletions only, and runs git init with the same origin. It then runs
apm audit --ci in the copy, and passes only on exit 0 with
"All 15 check(s) passed". A copy was chosen over a trap-guarded in-place
swap of apm.yml: it never writes the working tree, so the tree stays
byte-identical even after SIGKILL. The plugin name must now start
alphanumeric and contain no "..".

Impact: tests cover a failing, short, or non-zero re-run; a one-of-three
failure on another row; a duplicated details header; and dotted names.
Each guard was mutation-checked. On this branch the re-run reports all 15
checks passing.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
ADR-0026 said the root manifest is never waived. Since the rtk routing
hook landed it has one narrow waiver: ref-consistency for a plugin not
yet on origin/main. The amendment records the waiver's conditions, the
re-run of the full 15-check root set on a scratch copy with those
plugins' entries removed, and that the waiver lapses once the follow-up
lock PR lands.

Refs: #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Defame1297 merged commit 0b04fa1e66 into main 2026-12-06 15:31:00 +00:00
Defame1297 deleted branch feat/179-rtk-plugin 2026-12-06 15:31:02 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#284