@hasna/terminal 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +29 -12
- package/package.json +1 -1
- package/src/ai.ts +50 -36
- package/src/cli.tsx +29 -12
- package/src/context-hints.ts +89 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-store.ts +65 -0
- package/src/providers/index.ts +4 -4
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Test suite for rtk-rewrite.sh
|
|
3
|
+
# Feeds mock JSON through the hook and verifies the rewritten commands.
|
|
4
|
+
#
|
|
5
|
+
# Usage: bash ~/.claude/hooks/test-rtk-rewrite.sh
|
|
6
|
+
|
|
7
|
+
HOOK="${HOOK:-$HOME/.claude/hooks/rtk-rewrite.sh}"
|
|
8
|
+
PASS=0
|
|
9
|
+
FAIL=0
|
|
10
|
+
TOTAL=0
|
|
11
|
+
|
|
12
|
+
# Colors
|
|
13
|
+
GREEN='\033[32m'
|
|
14
|
+
RED='\033[31m'
|
|
15
|
+
DIM='\033[2m'
|
|
16
|
+
RESET='\033[0m'
|
|
17
|
+
|
|
18
|
+
test_rewrite() {
|
|
19
|
+
local description="$1"
|
|
20
|
+
local input_cmd="$2"
|
|
21
|
+
local expected_cmd="$3" # empty string = expect no rewrite
|
|
22
|
+
TOTAL=$((TOTAL + 1))
|
|
23
|
+
|
|
24
|
+
local input_json
|
|
25
|
+
input_json=$(jq -n --arg cmd "$input_cmd" '{"tool_name":"Bash","tool_input":{"command":$cmd}}')
|
|
26
|
+
local output
|
|
27
|
+
output=$(echo "$input_json" | bash "$HOOK" 2>/dev/null) || true
|
|
28
|
+
|
|
29
|
+
if [ -z "$expected_cmd" ]; then
|
|
30
|
+
# Expect no rewrite (hook exits 0 with no output)
|
|
31
|
+
if [ -z "$output" ]; then
|
|
32
|
+
printf " ${GREEN}PASS${RESET} %s ${DIM}→ (no rewrite)${RESET}\n" "$description"
|
|
33
|
+
PASS=$((PASS + 1))
|
|
34
|
+
else
|
|
35
|
+
local actual
|
|
36
|
+
actual=$(echo "$output" | jq -r '.hookSpecificOutput.updatedInput.command // empty')
|
|
37
|
+
printf " ${RED}FAIL${RESET} %s\n" "$description"
|
|
38
|
+
printf " expected: (no rewrite)\n"
|
|
39
|
+
printf " actual: %s\n" "$actual"
|
|
40
|
+
FAIL=$((FAIL + 1))
|
|
41
|
+
fi
|
|
42
|
+
else
|
|
43
|
+
local actual
|
|
44
|
+
actual=$(echo "$output" | jq -r '.hookSpecificOutput.updatedInput.command // empty' 2>/dev/null)
|
|
45
|
+
if [ "$actual" = "$expected_cmd" ]; then
|
|
46
|
+
printf " ${GREEN}PASS${RESET} %s ${DIM}→ %s${RESET}\n" "$description" "$actual"
|
|
47
|
+
PASS=$((PASS + 1))
|
|
48
|
+
else
|
|
49
|
+
printf " ${RED}FAIL${RESET} %s\n" "$description"
|
|
50
|
+
printf " expected: %s\n" "$expected_cmd"
|
|
51
|
+
printf " actual: %s\n" "$actual"
|
|
52
|
+
FAIL=$((FAIL + 1))
|
|
53
|
+
fi
|
|
54
|
+
fi
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
echo "============================================"
|
|
58
|
+
echo " RTK Rewrite Hook Test Suite"
|
|
59
|
+
echo "============================================"
|
|
60
|
+
echo ""
|
|
61
|
+
|
|
62
|
+
# ---- SECTION 1: Existing patterns (regression tests) ----
|
|
63
|
+
echo "--- Existing patterns (regression) ---"
|
|
64
|
+
test_rewrite "git status" \
|
|
65
|
+
"git status" \
|
|
66
|
+
"rtk git status"
|
|
67
|
+
|
|
68
|
+
test_rewrite "git log --oneline -10" \
|
|
69
|
+
"git log --oneline -10" \
|
|
70
|
+
"rtk git log --oneline -10"
|
|
71
|
+
|
|
72
|
+
test_rewrite "git diff HEAD" \
|
|
73
|
+
"git diff HEAD" \
|
|
74
|
+
"rtk git diff HEAD"
|
|
75
|
+
|
|
76
|
+
test_rewrite "git show abc123" \
|
|
77
|
+
"git show abc123" \
|
|
78
|
+
"rtk git show abc123"
|
|
79
|
+
|
|
80
|
+
test_rewrite "git add ." \
|
|
81
|
+
"git add ." \
|
|
82
|
+
"rtk git add ."
|
|
83
|
+
|
|
84
|
+
test_rewrite "gh pr list" \
|
|
85
|
+
"gh pr list" \
|
|
86
|
+
"rtk gh pr list"
|
|
87
|
+
|
|
88
|
+
test_rewrite "npx playwright test" \
|
|
89
|
+
"npx playwright test" \
|
|
90
|
+
"rtk playwright test"
|
|
91
|
+
|
|
92
|
+
test_rewrite "ls -la" \
|
|
93
|
+
"ls -la" \
|
|
94
|
+
"rtk ls -la"
|
|
95
|
+
|
|
96
|
+
test_rewrite "curl -s https://example.com" \
|
|
97
|
+
"curl -s https://example.com" \
|
|
98
|
+
"rtk curl -s https://example.com"
|
|
99
|
+
|
|
100
|
+
test_rewrite "cat package.json" \
|
|
101
|
+
"cat package.json" \
|
|
102
|
+
"rtk read package.json"
|
|
103
|
+
|
|
104
|
+
test_rewrite "grep -rn pattern src/" \
|
|
105
|
+
"grep -rn pattern src/" \
|
|
106
|
+
"rtk grep -rn pattern src/"
|
|
107
|
+
|
|
108
|
+
test_rewrite "rg pattern src/" \
|
|
109
|
+
"rg pattern src/" \
|
|
110
|
+
"rtk grep pattern src/"
|
|
111
|
+
|
|
112
|
+
test_rewrite "cargo test" \
|
|
113
|
+
"cargo test" \
|
|
114
|
+
"rtk cargo test"
|
|
115
|
+
|
|
116
|
+
test_rewrite "npx prisma migrate" \
|
|
117
|
+
"npx prisma migrate" \
|
|
118
|
+
"rtk prisma migrate"
|
|
119
|
+
|
|
120
|
+
echo ""
|
|
121
|
+
|
|
122
|
+
# ---- SECTION 2: Env var prefix handling (THE BIG FIX) ----
|
|
123
|
+
echo "--- Env var prefix handling (new) ---"
|
|
124
|
+
test_rewrite "env + playwright" \
|
|
125
|
+
"TEST_SESSION_ID=2 npx playwright test --config=foo" \
|
|
126
|
+
"TEST_SESSION_ID=2 rtk playwright test --config=foo"
|
|
127
|
+
|
|
128
|
+
test_rewrite "env + git status" \
|
|
129
|
+
"GIT_PAGER=cat git status" \
|
|
130
|
+
"GIT_PAGER=cat rtk git status"
|
|
131
|
+
|
|
132
|
+
test_rewrite "env + git log" \
|
|
133
|
+
"GIT_PAGER=cat git log --oneline -10" \
|
|
134
|
+
"GIT_PAGER=cat rtk git log --oneline -10"
|
|
135
|
+
|
|
136
|
+
test_rewrite "multi env + vitest" \
|
|
137
|
+
"NODE_ENV=test CI=1 npx vitest run" \
|
|
138
|
+
"NODE_ENV=test CI=1 rtk vitest run"
|
|
139
|
+
|
|
140
|
+
test_rewrite "env + ls" \
|
|
141
|
+
"LANG=C ls -la" \
|
|
142
|
+
"LANG=C rtk ls -la"
|
|
143
|
+
|
|
144
|
+
test_rewrite "env + npm run" \
|
|
145
|
+
"NODE_ENV=test npm run test:e2e" \
|
|
146
|
+
"NODE_ENV=test rtk npm test:e2e"
|
|
147
|
+
|
|
148
|
+
test_rewrite "env + docker compose (unsupported subcommand, NOT rewritten)" \
|
|
149
|
+
"COMPOSE_PROJECT_NAME=test docker compose up -d" \
|
|
150
|
+
""
|
|
151
|
+
|
|
152
|
+
test_rewrite "env + docker compose logs (supported, rewritten)" \
|
|
153
|
+
"COMPOSE_PROJECT_NAME=test docker compose logs web" \
|
|
154
|
+
"COMPOSE_PROJECT_NAME=test rtk docker compose logs web"
|
|
155
|
+
|
|
156
|
+
echo ""
|
|
157
|
+
|
|
158
|
+
# ---- SECTION 3: New patterns ----
|
|
159
|
+
echo "--- New patterns ---"
|
|
160
|
+
test_rewrite "npm run test:e2e" \
|
|
161
|
+
"npm run test:e2e" \
|
|
162
|
+
"rtk npm test:e2e"
|
|
163
|
+
|
|
164
|
+
test_rewrite "npm run build" \
|
|
165
|
+
"npm run build" \
|
|
166
|
+
"rtk npm build"
|
|
167
|
+
|
|
168
|
+
test_rewrite "npm test" \
|
|
169
|
+
"npm test" \
|
|
170
|
+
"rtk npm test"
|
|
171
|
+
|
|
172
|
+
test_rewrite "vue-tsc -b" \
|
|
173
|
+
"vue-tsc -b" \
|
|
174
|
+
"rtk tsc -b"
|
|
175
|
+
|
|
176
|
+
test_rewrite "npx vue-tsc --noEmit" \
|
|
177
|
+
"npx vue-tsc --noEmit" \
|
|
178
|
+
"rtk tsc --noEmit"
|
|
179
|
+
|
|
180
|
+
test_rewrite "docker compose up -d (NOT rewritten — unsupported by rtk)" \
|
|
181
|
+
"docker compose up -d" \
|
|
182
|
+
""
|
|
183
|
+
|
|
184
|
+
test_rewrite "docker compose logs postgrest" \
|
|
185
|
+
"docker compose logs postgrest" \
|
|
186
|
+
"rtk docker compose logs postgrest"
|
|
187
|
+
|
|
188
|
+
test_rewrite "docker compose ps" \
|
|
189
|
+
"docker compose ps" \
|
|
190
|
+
"rtk docker compose ps"
|
|
191
|
+
|
|
192
|
+
test_rewrite "docker compose build" \
|
|
193
|
+
"docker compose build" \
|
|
194
|
+
"rtk docker compose build"
|
|
195
|
+
|
|
196
|
+
test_rewrite "docker compose down (NOT rewritten — unsupported by rtk)" \
|
|
197
|
+
"docker compose down" \
|
|
198
|
+
""
|
|
199
|
+
|
|
200
|
+
test_rewrite "docker compose -f file.yml up (NOT rewritten — flag before subcommand)" \
|
|
201
|
+
"docker compose -f docker-compose.preview.yml --project-name myapp up -d --build" \
|
|
202
|
+
""
|
|
203
|
+
|
|
204
|
+
test_rewrite "docker run --rm postgres" \
|
|
205
|
+
"docker run --rm postgres" \
|
|
206
|
+
"rtk docker run --rm postgres"
|
|
207
|
+
|
|
208
|
+
test_rewrite "docker exec -it db psql" \
|
|
209
|
+
"docker exec -it db psql" \
|
|
210
|
+
"rtk docker exec -it db psql"
|
|
211
|
+
|
|
212
|
+
test_rewrite "find (NOT rewritten — different arg format)" \
|
|
213
|
+
"find . -name '*.ts'" \
|
|
214
|
+
""
|
|
215
|
+
|
|
216
|
+
test_rewrite "tree (NOT rewritten — different arg format)" \
|
|
217
|
+
"tree src/" \
|
|
218
|
+
""
|
|
219
|
+
|
|
220
|
+
test_rewrite "wget (NOT rewritten — different arg format)" \
|
|
221
|
+
"wget https://example.com/file" \
|
|
222
|
+
""
|
|
223
|
+
|
|
224
|
+
test_rewrite "gh api repos/owner/repo" \
|
|
225
|
+
"gh api repos/owner/repo" \
|
|
226
|
+
"rtk gh api repos/owner/repo"
|
|
227
|
+
|
|
228
|
+
test_rewrite "gh release list" \
|
|
229
|
+
"gh release list" \
|
|
230
|
+
"rtk gh release list"
|
|
231
|
+
|
|
232
|
+
test_rewrite "kubectl describe pod foo" \
|
|
233
|
+
"kubectl describe pod foo" \
|
|
234
|
+
"rtk kubectl describe pod foo"
|
|
235
|
+
|
|
236
|
+
test_rewrite "kubectl apply -f deploy.yaml" \
|
|
237
|
+
"kubectl apply -f deploy.yaml" \
|
|
238
|
+
"rtk kubectl apply -f deploy.yaml"
|
|
239
|
+
|
|
240
|
+
echo ""
|
|
241
|
+
|
|
242
|
+
# ---- SECTION 3b: RTK_DISABLED and redirect fixes (#345, #346) ----
|
|
243
|
+
echo "--- RTK_DISABLED (#345) ---"
|
|
244
|
+
test_rewrite "RTK_DISABLED=1 git status (no rewrite)" \
|
|
245
|
+
"RTK_DISABLED=1 git status" \
|
|
246
|
+
""
|
|
247
|
+
|
|
248
|
+
test_rewrite "RTK_DISABLED=1 cargo test (no rewrite)" \
|
|
249
|
+
"RTK_DISABLED=1 cargo test" \
|
|
250
|
+
""
|
|
251
|
+
|
|
252
|
+
test_rewrite "FOO=1 RTK_DISABLED=1 git status (no rewrite)" \
|
|
253
|
+
"FOO=1 RTK_DISABLED=1 git status" \
|
|
254
|
+
""
|
|
255
|
+
|
|
256
|
+
echo ""
|
|
257
|
+
echo "--- Redirect operators (#346) ---"
|
|
258
|
+
test_rewrite "cargo test 2>&1 | head" \
|
|
259
|
+
"cargo test 2>&1 | head" \
|
|
260
|
+
"rtk cargo test 2>&1 | head"
|
|
261
|
+
|
|
262
|
+
test_rewrite "cargo test 2>&1" \
|
|
263
|
+
"cargo test 2>&1" \
|
|
264
|
+
"rtk cargo test 2>&1"
|
|
265
|
+
|
|
266
|
+
test_rewrite "cargo test &>/dev/null" \
|
|
267
|
+
"cargo test &>/dev/null" \
|
|
268
|
+
"rtk cargo test &>/dev/null"
|
|
269
|
+
|
|
270
|
+
# Note: the bash hook rewrites only the first command segment (sed-based);
|
|
271
|
+
# full compound rewriting (both sides of &) is handled by `rtk rewrite` (Rust).
|
|
272
|
+
# The critical behavior tested here: `&` after `cargo test` is NOT mistaken for
|
|
273
|
+
# a redirect — the hook still rewrites cargo test, no crash.
|
|
274
|
+
test_rewrite "cargo test & git status (bash hook rewrites first segment only)" \
|
|
275
|
+
"cargo test & git status" \
|
|
276
|
+
"rtk cargo test & git status"
|
|
277
|
+
|
|
278
|
+
echo ""
|
|
279
|
+
|
|
280
|
+
# ---- SECTION 4: Vitest edge case (fixed double "run" bug) ----
|
|
281
|
+
echo "--- Vitest run dedup ---"
|
|
282
|
+
test_rewrite "vitest (no args)" \
|
|
283
|
+
"vitest" \
|
|
284
|
+
"rtk vitest run"
|
|
285
|
+
|
|
286
|
+
test_rewrite "vitest run (no double run)" \
|
|
287
|
+
"vitest run" \
|
|
288
|
+
"rtk vitest run"
|
|
289
|
+
|
|
290
|
+
test_rewrite "vitest run --reporter" \
|
|
291
|
+
"vitest run --reporter=verbose" \
|
|
292
|
+
"rtk vitest run --reporter=verbose"
|
|
293
|
+
|
|
294
|
+
test_rewrite "npx vitest run" \
|
|
295
|
+
"npx vitest run" \
|
|
296
|
+
"rtk vitest run"
|
|
297
|
+
|
|
298
|
+
test_rewrite "pnpm vitest run --coverage" \
|
|
299
|
+
"pnpm vitest run --coverage" \
|
|
300
|
+
"rtk vitest run --coverage"
|
|
301
|
+
|
|
302
|
+
echo ""
|
|
303
|
+
|
|
304
|
+
# ---- SECTION 5: Should NOT rewrite ----
|
|
305
|
+
echo "--- Should NOT rewrite ---"
|
|
306
|
+
test_rewrite "already rtk" \
|
|
307
|
+
"rtk git status" \
|
|
308
|
+
""
|
|
309
|
+
|
|
310
|
+
test_rewrite "heredoc" \
|
|
311
|
+
"cat <<'EOF'
|
|
312
|
+
hello
|
|
313
|
+
EOF" \
|
|
314
|
+
""
|
|
315
|
+
|
|
316
|
+
test_rewrite "echo (no pattern)" \
|
|
317
|
+
"echo hello world" \
|
|
318
|
+
""
|
|
319
|
+
|
|
320
|
+
test_rewrite "cd (no pattern)" \
|
|
321
|
+
"cd /tmp" \
|
|
322
|
+
""
|
|
323
|
+
|
|
324
|
+
test_rewrite "mkdir (no pattern)" \
|
|
325
|
+
"mkdir -p foo/bar" \
|
|
326
|
+
""
|
|
327
|
+
|
|
328
|
+
test_rewrite "python3 (no pattern)" \
|
|
329
|
+
"python3 script.py" \
|
|
330
|
+
""
|
|
331
|
+
|
|
332
|
+
test_rewrite "node (no pattern)" \
|
|
333
|
+
"node -e 'console.log(1)'" \
|
|
334
|
+
""
|
|
335
|
+
|
|
336
|
+
echo ""
|
|
337
|
+
|
|
338
|
+
# ---- SECTION 6: Audit logging ----
|
|
339
|
+
echo "--- Audit logging (RTK_HOOK_AUDIT=1) ---"
|
|
340
|
+
|
|
341
|
+
AUDIT_TMPDIR=$(mktemp -d)
|
|
342
|
+
trap "rm -rf $AUDIT_TMPDIR" EXIT
|
|
343
|
+
|
|
344
|
+
test_audit_log() {
|
|
345
|
+
local description="$1"
|
|
346
|
+
local input_cmd="$2"
|
|
347
|
+
local expected_action="$3"
|
|
348
|
+
TOTAL=$((TOTAL + 1))
|
|
349
|
+
|
|
350
|
+
# Clean log
|
|
351
|
+
rm -f "$AUDIT_TMPDIR/hook-audit.log"
|
|
352
|
+
|
|
353
|
+
local input_json
|
|
354
|
+
input_json=$(jq -n --arg cmd "$input_cmd" '{"tool_name":"Bash","tool_input":{"command":$cmd}}')
|
|
355
|
+
echo "$input_json" | RTK_HOOK_AUDIT=1 RTK_AUDIT_DIR="$AUDIT_TMPDIR" bash "$HOOK" 2>/dev/null || true
|
|
356
|
+
|
|
357
|
+
if [ ! -f "$AUDIT_TMPDIR/hook-audit.log" ]; then
|
|
358
|
+
printf " ${RED}FAIL${RESET} %s (no log file created)\n" "$description"
|
|
359
|
+
FAIL=$((FAIL + 1))
|
|
360
|
+
return
|
|
361
|
+
fi
|
|
362
|
+
|
|
363
|
+
local log_line
|
|
364
|
+
log_line=$(head -1 "$AUDIT_TMPDIR/hook-audit.log")
|
|
365
|
+
local actual_action
|
|
366
|
+
actual_action=$(echo "$log_line" | cut -d'|' -f2 | tr -d ' ')
|
|
367
|
+
|
|
368
|
+
if [ "$actual_action" = "$expected_action" ]; then
|
|
369
|
+
printf " ${GREEN}PASS${RESET} %s ${DIM}→ %s${RESET}\n" "$description" "$actual_action"
|
|
370
|
+
PASS=$((PASS + 1))
|
|
371
|
+
else
|
|
372
|
+
printf " ${RED}FAIL${RESET} %s\n" "$description"
|
|
373
|
+
printf " expected action: %s\n" "$expected_action"
|
|
374
|
+
printf " actual action: %s\n" "$actual_action"
|
|
375
|
+
printf " log line: %s\n" "$log_line"
|
|
376
|
+
FAIL=$((FAIL + 1))
|
|
377
|
+
fi
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
test_audit_log "audit: rewrite git status" \
|
|
381
|
+
"git status" \
|
|
382
|
+
"rewrite"
|
|
383
|
+
|
|
384
|
+
test_audit_log "audit: skip already_rtk" \
|
|
385
|
+
"rtk git status" \
|
|
386
|
+
"skip:already_rtk"
|
|
387
|
+
|
|
388
|
+
test_audit_log "audit: skip heredoc" \
|
|
389
|
+
"cat <<'EOF'
|
|
390
|
+
hello
|
|
391
|
+
EOF" \
|
|
392
|
+
"skip:heredoc"
|
|
393
|
+
|
|
394
|
+
test_audit_log "audit: skip no_match" \
|
|
395
|
+
"echo hello world" \
|
|
396
|
+
"skip:no_match"
|
|
397
|
+
|
|
398
|
+
test_audit_log "audit: rewrite cargo test" \
|
|
399
|
+
"cargo test" \
|
|
400
|
+
"rewrite"
|
|
401
|
+
|
|
402
|
+
# Test log format (4 pipe-separated fields)
|
|
403
|
+
rm -f "$AUDIT_TMPDIR/hook-audit.log"
|
|
404
|
+
input_json=$(jq -n --arg cmd "git status" '{"tool_name":"Bash","tool_input":{"command":$cmd}}')
|
|
405
|
+
echo "$input_json" | RTK_HOOK_AUDIT=1 RTK_AUDIT_DIR="$AUDIT_TMPDIR" bash "$HOOK" 2>/dev/null || true
|
|
406
|
+
TOTAL=$((TOTAL + 1))
|
|
407
|
+
log_line=$(cat "$AUDIT_TMPDIR/hook-audit.log" 2>/dev/null || echo "")
|
|
408
|
+
field_count=$(echo "$log_line" | awk -F' \\| ' '{print NF}')
|
|
409
|
+
if [ "$field_count" = "4" ]; then
|
|
410
|
+
printf " ${GREEN}PASS${RESET} audit: log format has 4 fields ${DIM}→ %s${RESET}\n" "$log_line"
|
|
411
|
+
PASS=$((PASS + 1))
|
|
412
|
+
else
|
|
413
|
+
printf " ${RED}FAIL${RESET} audit: log format (expected 4 fields, got %s)\n" "$field_count"
|
|
414
|
+
printf " log line: %s\n" "$log_line"
|
|
415
|
+
FAIL=$((FAIL + 1))
|
|
416
|
+
fi
|
|
417
|
+
|
|
418
|
+
# Test no log when RTK_HOOK_AUDIT is unset
|
|
419
|
+
rm -f "$AUDIT_TMPDIR/hook-audit.log"
|
|
420
|
+
input_json=$(jq -n --arg cmd "git status" '{"tool_name":"Bash","tool_input":{"command":$cmd}}')
|
|
421
|
+
echo "$input_json" | RTK_AUDIT_DIR="$AUDIT_TMPDIR" bash "$HOOK" 2>/dev/null || true
|
|
422
|
+
TOTAL=$((TOTAL + 1))
|
|
423
|
+
if [ ! -f "$AUDIT_TMPDIR/hook-audit.log" ]; then
|
|
424
|
+
printf " ${GREEN}PASS${RESET} audit: no log when RTK_HOOK_AUDIT unset\n"
|
|
425
|
+
PASS=$((PASS + 1))
|
|
426
|
+
else
|
|
427
|
+
printf " ${RED}FAIL${RESET} audit: log created when RTK_HOOK_AUDIT unset\n"
|
|
428
|
+
FAIL=$((FAIL + 1))
|
|
429
|
+
fi
|
|
430
|
+
|
|
431
|
+
echo ""
|
|
432
|
+
|
|
433
|
+
# ---- SUMMARY ----
|
|
434
|
+
echo "============================================"
|
|
435
|
+
if [ $FAIL -eq 0 ]; then
|
|
436
|
+
printf " ${GREEN}ALL $TOTAL TESTS PASSED${RESET}\n"
|
|
437
|
+
else
|
|
438
|
+
printf " ${RED}$FAIL FAILED${RESET} / $TOTAL total ($PASS passed)\n"
|
|
439
|
+
fi
|
|
440
|
+
echo "============================================"
|
|
441
|
+
|
|
442
|
+
exit $FAIL
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# rtk installer - https://github.com/rtk-ai/rtk
|
|
3
|
+
# Usage: curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
REPO="rtk-ai/rtk"
|
|
8
|
+
BINARY_NAME="rtk"
|
|
9
|
+
INSTALL_DIR="${RTK_INSTALL_DIR:-$HOME/.local/bin}"
|
|
10
|
+
|
|
11
|
+
# Colors
|
|
12
|
+
RED='\033[0;31m'
|
|
13
|
+
GREEN='\033[0;32m'
|
|
14
|
+
YELLOW='\033[1;33m'
|
|
15
|
+
NC='\033[0m' # No Color
|
|
16
|
+
|
|
17
|
+
info() {
|
|
18
|
+
printf "${GREEN}[INFO]${NC} %s\n" "$1"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
warn() {
|
|
22
|
+
printf "${YELLOW}[WARN]${NC} %s\n" "$1"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
error() {
|
|
26
|
+
printf "${RED}[ERROR]${NC} %s\n" "$1"
|
|
27
|
+
exit 1
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Detect OS
|
|
31
|
+
detect_os() {
|
|
32
|
+
case "$(uname -s)" in
|
|
33
|
+
Linux*) OS="linux";;
|
|
34
|
+
Darwin*) OS="darwin";;
|
|
35
|
+
*) error "Unsupported operating system: $(uname -s)";;
|
|
36
|
+
esac
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Detect architecture
|
|
40
|
+
detect_arch() {
|
|
41
|
+
case "$(uname -m)" in
|
|
42
|
+
x86_64|amd64) ARCH="x86_64";;
|
|
43
|
+
arm64|aarch64) ARCH="aarch64";;
|
|
44
|
+
*) error "Unsupported architecture: $(uname -m)";;
|
|
45
|
+
esac
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Get latest release version
|
|
49
|
+
get_latest_version() {
|
|
50
|
+
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
|
|
51
|
+
if [ -z "$VERSION" ]; then
|
|
52
|
+
error "Failed to get latest version"
|
|
53
|
+
fi
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Build target triple
|
|
57
|
+
get_target() {
|
|
58
|
+
case "$OS" in
|
|
59
|
+
linux)
|
|
60
|
+
case "$ARCH" in
|
|
61
|
+
x86_64) TARGET="x86_64-unknown-linux-musl";;
|
|
62
|
+
aarch64) TARGET="aarch64-unknown-linux-gnu";;
|
|
63
|
+
esac
|
|
64
|
+
;;
|
|
65
|
+
darwin)
|
|
66
|
+
TARGET="${ARCH}-apple-darwin"
|
|
67
|
+
;;
|
|
68
|
+
esac
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Download and install
|
|
72
|
+
install() {
|
|
73
|
+
info "Detected: $OS $ARCH"
|
|
74
|
+
info "Target: $TARGET"
|
|
75
|
+
info "Version: $VERSION"
|
|
76
|
+
|
|
77
|
+
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}-${TARGET}.tar.gz"
|
|
78
|
+
TEMP_DIR=$(mktemp -d)
|
|
79
|
+
ARCHIVE="${TEMP_DIR}/${BINARY_NAME}.tar.gz"
|
|
80
|
+
|
|
81
|
+
info "Downloading from: $DOWNLOAD_URL"
|
|
82
|
+
if ! curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE"; then
|
|
83
|
+
error "Failed to download binary"
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
info "Extracting..."
|
|
87
|
+
tar -xzf "$ARCHIVE" -C "$TEMP_DIR"
|
|
88
|
+
|
|
89
|
+
mkdir -p "$INSTALL_DIR"
|
|
90
|
+
mv "${TEMP_DIR}/${BINARY_NAME}" "${INSTALL_DIR}/"
|
|
91
|
+
|
|
92
|
+
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
|
|
93
|
+
|
|
94
|
+
# Cleanup
|
|
95
|
+
rm -rf "$TEMP_DIR"
|
|
96
|
+
|
|
97
|
+
info "Successfully installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Verify installation
|
|
101
|
+
verify() {
|
|
102
|
+
if command -v "$BINARY_NAME" >/dev/null 2>&1; then
|
|
103
|
+
info "Verification: $($BINARY_NAME --version)"
|
|
104
|
+
else
|
|
105
|
+
warn "Binary installed but not in PATH. Add to your shell profile:"
|
|
106
|
+
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
|
|
107
|
+
fi
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main() {
|
|
111
|
+
info "Installing $BINARY_NAME..."
|
|
112
|
+
|
|
113
|
+
detect_os
|
|
114
|
+
detect_arch
|
|
115
|
+
get_target
|
|
116
|
+
get_latest_version
|
|
117
|
+
install
|
|
118
|
+
verify
|
|
119
|
+
|
|
120
|
+
echo ""
|
|
121
|
+
info "Installation complete! Run '$BINARY_NAME --help' to get started."
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main
|