Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ rtk gain --history | grep proxy

| Module | Purpose | Token Strategy |
|--------|---------|----------------|
| bazel_cmd.rs | Bazel commands | Strip stderr noise, group targets by package (85% reduction) |
| git.rs | Git operations | Stat summaries + compact diffs |
| grep_cmd.rs | Code search | Group by file, truncate lines |
| ls.rs | Directory listing | Tree format, aggregate counts |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ The hook is included in this repository at `.claude/hooks/rtk-rewrite.sh`. To us
| `git status/diff/log/add/commit/push/pull/branch/fetch/stash` | `rtk git ...` |
| `gh pr/issue/run` | `rtk gh ...` |
| `cargo test/build/clippy` | `rtk cargo ...` |
| `bazel build/test/run/query` | `rtk bazel ...` |
| `cat <file>` | `rtk read <file>` |
| `rg/grep <pattern>` | `rtk grep <pattern>` |
| `ls` | `rtk ls` |
Expand Down
4 changes: 4 additions & 0 deletions hooks/rtk-rewrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ elif echo "$MATCH_CMD" | grep -qE '^cargo[[:space:]]'; then
;;
esac

# --- Bazel ---
elif echo "$MATCH_CMD" | grep -qE '^bazel[[:space:]]+(build|test|run|query|aquery|cquery)([[:space:]]|$)'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^bazel /rtk bazel /')"

# --- File operations ---
elif echo "$MATCH_CMD" | grep -qE '^cat[[:space:]]+'; then
REWRITTEN="${ENV_PREFIX}$(echo "$CMD_BODY" | sed 's/^cat /rtk read /')"
Expand Down
16 changes: 16 additions & 0 deletions hooks/test-rtk-rewrite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ test_rewrite "cargo test" \
"cargo test" \
"rtk cargo test"

test_rewrite "bazel query //src/..." \
"bazel query //src/..." \
"rtk bazel query //src/..."

test_rewrite "bazel build //src:bazel-dev" \
"bazel build //src:bazel-dev" \
"rtk bazel build //src:bazel-dev"

test_rewrite "npx prisma migrate" \
"npx prisma migrate" \
"rtk prisma migrate"
Expand Down Expand Up @@ -145,6 +153,10 @@ test_rewrite "env + npm run" \
"NODE_ENV=test npm run test:e2e" \
"NODE_ENV=test rtk npm test:e2e"

test_rewrite "env + bazel query" \
"USE_BAZEL_VERSION=8.2.0 bazel query //src/..." \
"USE_BAZEL_VERSION=8.2.0 rtk bazel query //src/..."

test_rewrite "env + docker compose (unsupported subcommand, NOT rewritten)" \
"COMPOSE_PROJECT_NAME=test docker compose up -d" \
""
Expand Down Expand Up @@ -295,6 +307,10 @@ test_rewrite "node (no pattern)" \
"node -e 'console.log(1)'" \
""

test_rewrite "bazel startup flags before subcommand (NOT rewritten)" \
"bazel --output_base=/tmp/bazel query //src/..." \
""

echo ""

# ---- SECTION 6: Audit logging ----
Expand Down
Loading