Skip to content

feat: add hook mode — silently execute bash via rtk wrapper - #2

Open
xelr233 wants to merge 12 commits into
sleepinginsummer:mainfrom
xelr233:pr/hook-mode
Open

feat: add hook mode — silently execute bash via rtk wrapper#2
xelr233 wants to merge 12 commits into
sleepinginsummer:mainfrom
xelr233:pr/hook-mode

Conversation

@xelr233

@xelr233 xelr233 commented Aug 15, 2026

Copy link
Copy Markdown

摘要

新增第三种模式 hook:模型调用 bash 时,插件在 tools/pre-executertk hook claude 获取改写命令,在 tools/execute 短路替换执行 /bin/bash -c <rewritten>,让命令真正以 rtk 包装器形式运行——输出经 rtk 过滤、rtk gainTotal commands 计数 +1。默认无感(不附加任何标注),debug=true 时输出排查标注。

本 PR 基于 #1(fix-rtk-probe)之上,链式依赖:先合入 #1

变更

  • rtkHookRewrite():spawn rtk hook claude,stdin 传 PreToolUse JSON,解析 updatedInput.command
  • state.hookPlan / state.hookExecuted(有界 Map,cap 64,防泄漏)
  • tools/execute 短路:返回符合 bash schema 的 {value},跳过 DSH 默认执行;超时返回 timedOut 结果(不重复执行原命令)
  • tools/post-execute:debug 门控的 executed as "..." 标注
  • /rtk set mode hook、help 更新、README 文档 + sandbox/第三方外发安全警告
  • 设计规格与实现计划(docs/superpowers/)

测试

  • node --test test/*.test.js → 41 pass / 0 fail(短路、fallthrough、超时、无感默认、cap、spillPath)
  • E2E 模拟:rtk hook claude/bin/bash -c rtk ls → post-execute 无附注

注意

⚠️ 该模式会把所有 bash 命令静默交给二进制 rtk 执行(可记录本地 history.db),且绕过 DSH sandbox,仅限可信环境。

xelr233 added 12 commits August 15, 2026 23:30
verify/show only read the cached probe state, which stays undefined
until the first bash call, so an installed rtk was always reported as
"not probed yet" (the verify hint even told users to re-run a command
that never probes). Force a fresh probe (cache bypass) in both commands
and report the resolved path or NOT FOUND.

Also fix the npm test script for Node 24 (node --test test/ fails with
MODULE_NOT_FOUND) and add command tests covering verify/show probing.
…EADME, fix mode comment

F1: bound state.hookPlan / state.hookExecuted to HOOK_PLAN_MAX (64) entries,
evicting the oldest beyond the cap, plus defensive hookPlan cleanup in
tools/post-execute so a planned-but-never-executed call leaks nothing.
F2: propagate readStream spillPath into bash stdout/stderr objects.
F3: reconcile README blockquote with the hook-mode exception.
F4: update stale DEFAULT_CONFIG.mode comment to include 'hook'.
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.

1 participant