Skip to content

feat(hooks): integrate rtk upstream as external CLI for token reduction#2

Merged
DarkCodePE merged 3 commits into
mainfrom
feat/rtk-external-cli-260511-gpoapa
May 13, 2026
Merged

feat(hooks): integrate rtk upstream as external CLI for token reduction#2
DarkCodePE merged 3 commits into
mainfrom
feat/rtk-external-cli-260511-gpoapa

Conversation

@DarkCodePE
Copy link
Copy Markdown
Owner

Closes #1

Summary

Wires the upstream rtk binary (github.com/rtk-ai/rtk, v0.34.3) into RuFlo via a PreToolUse hook for 60-90% token reduction on Bash tool outputs. RTK is treated as an optional external CLI dependency (install via brew or cargo install --git), invoked from the hook verbatim, never absorbed into this repo.

PRD

Authoritative spec lives in docs/plans/260511-gpoapa-rtk-external-cli-integration.md.

Architectural decision

ADR-032 — Status: Proposed. Clarifies that ADR-027's "absorb-not-install" policy applies to Claude Code plugins, while RTK (a standalone CLI binary) follows the inverse "install-not-absorb" pattern, same as git, jq, or ripgrep.

Negative reference

9router/open-sse/rtk/ reimplemented rtk in JavaScript inside a MITM proxy (~1000 LOC owned, no upstream tests, marketing-grade "20-40%" claim with no benchmark). We invoke the upstream binary instead.

Test plan

  • AC 1: hook rewrites Bash(git diff) to Bash(rtk git diff) when rtk >= 0.23.0 is installed
  • AC 2: hook exits 0 silently when rtk is absent (bash .claude/hooks/rtk-rewrite.sh < /dev/null → no error)
  • AC 3: hook emits "too old" warning when wrong rtk is installed (verified live during integration with name-collision case)
  • AC 4: CLAUDE.md § RTK lists three valid install commands + explicit warning against cargo install rtk
  • AC 5: ADR-032 documents alternatives, relation to ADR-027, and verification command
  • AC 6: rtk gain reports 60-90% compression after two real Claude Code sessions (deferred to post-merge)
  • AC 7: ruflo-rtk-integration.drawio shows the hook + external-deps architecture

Files changed

  • .claude/hooks/rtk-rewrite.sh (new, verbatim from upstream)
  • .claude/settings.json (PreToolUse Bash matcher: rtk hook added next to existing pre-bash)
  • CLAUDE.md (RTK Token Reduction section + install warning)
  • docs/adr/ADR-032-rtk-external-cli-dependency.md (new)
  • docs/diagrams/9router-vs-ruflo-token-reduction.drawio (new, comparative)
  • docs/diagrams/ruflo-rtk-integration.drawio (new, final integration)
  • docs/plans/260511-gpoapa-rtk-external-cli-integration.md (new, PRD)

Process note

This PR closes a workflow audit gap: the /grill-me step happened conversationally and /to-prd ran retroactively after the swarm dispatch. The PRD's Further Notes section documents the miss so it does not recur.

🤖 Generated with claude-flow

Orlando Kuan and others added 3 commits May 11, 2026 12:57
Add PreToolUse hook delegating eligible Bash commands to the upstream
rtk binary (rtk-ai/rtk, v0.34.3) for 60-90% token reduction. RTK is
treated as an optional external dependency (install via brew or
cargo --git), invoked verbatim from the hook, never absorbed into the
codebase. Hook degrades silently when rtk is missing.

Documented:
- ADR-032: install-not-absorb policy for standalone CLI tools,
  contrasted with ADR-027's absorb-not-install for Claude Code plugins
- CLAUDE.md: install instructions with explicit warning against
  cargo install rtk (crate-name collision on crates.io with an
  unrelated Lua toolkit)
- docs/diagrams: comparative architecture (9Router proxy MITM vs
  RuFlo in-process hook) plus the final RuFlo+RTK integration diagram
- docs/plans/260511-gpoapa: retrospective PRD documenting the change

Negative reference: 9router/open-sse/rtk/ reimplemented rtk in JS
inside a MITM proxy (~1000 LOC owned, no upstream tests, degraded
20-40% claim). RuFlo invokes the upstream binary instead.

Refs: 260511-gpoapa
Co-Authored-By: claude-flow <ruv@ruv.net>
The RTK PreToolUse hook was originally added to .claude/hooks/ only,
which is the local repo mirror — not the canonical source-of-truth.
Per the repo pattern (scripts/init-arquetipo.sh:208, tests/*.sh, and
scripts/gen-reference.sh:80), docs/arquetipo/deliverables/hooks/hooks/
is the canonical location that ships in the npm package and is copied
to user projects on init.

Changes:
- Add canonical rtk-rewrite.sh under deliverables/hooks/hooks/ (identical
  to the .claude/hooks/ mirror that was added in the previous commit).
- Register the rtk hook in the deliverable settings.json under
  PreToolUse matcher Bash, alongside validate-bash.py and the existing
  pre-command hook. Bump _meta.hooks_count from 15 to 16.
- Add a check_mirror_sync function to tests/hooks-syntax-suite.sh that
  diffs .claude/hooks/<file> vs deliverables/hooks/hooks/<file> for an
  allow-list of tracked files (starting with rtk-rewrite.sh). Fails the
  suite if they drift. Legacy drift on other files is not yet in scope;
  the list will be extended as those are reconciled separately.

Test suite: PASS=29 FAIL=0 (was 28, +1 mirror check).

Refs: 260511-gpoapa, PR #2, ADR-032
Co-Authored-By: claude-flow <ruv@ruv.net>
Documentation and version bump for the alpha.12 release. Code changes
landed in the previous two commits of PR #2 (260511-gpoapa).

- README.md: new "RTK Token Reduction (optional)" section with the
  three valid install commands, the name-collision warning, and a
  pointer to ADR-032. Features table updated (24 -> 25 hooks; added
  RTK row).
- package.json: 1.0.0-alpha.11 -> 1.0.0-alpha.12. publishConfig and
  files arrays unchanged; rtk-rewrite.sh ships inside the existing
  docs/arquetipo/deliverables/** glob.
- RELEASE-NOTES.md: rewritten for alpha.12. Highlights focus on the
  RTK integration, ADR-032, the anti-drift test, the diagrams, and
  the workflow audit (process miss + retroactive PRD). Migration path
  is purely additive (no breaking changes from alpha.11).

The release.yml workflow fires on push of tag v1.0.0-alpha.12. This
commit does not create or push that tag - tag creation is deferred
until PR #2 is merged to main.

Refs: 260511-gpoapa, PR #2, ADR-032
Co-Authored-By: claude-flow <ruv@ruv.net>
@DarkCodePE DarkCodePE merged commit 87b0521 into main May 13, 2026
2 of 3 checks passed
@DarkCodePE DarkCodePE deleted the feat/rtk-external-cli-260511-gpoapa branch May 13, 2026 16:17
DarkCodePE pushed a commit that referenced this pull request May 14, 2026
Wave C C3 of ADR-036. Hookifies the §9 File rule doctrine: post-edit hook
conditionally invokes smell-scanner which detects canonical smells (bare
catch, TODO without link, function >30 LoC, cyclomatic >10) on the diff
and auto-files issues with dedupe via AgentDB pattern-store cache.

9 AC across 7 slices. Default-off via SMELL_SCAN_ENABLE=1 (ADR-035 pattern).
Supersedes the original Brecha #2 collateral-issuer.mjs proposal.

Refs #11 #12 #13 #14 #15 #16 #17.

Co-Authored-By: claude-flow <ruv@ruv.net>
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.

Implements 260511-gpoapa — RTK external CLI for token reduction

1 participant