Skip to content

feat(cockpit): PostToolUse tool-mirror hook — zero-token live worker activity (3c spike, closes #71) - #75

Merged
robercano-ghbot merged 1 commit into
mainfrom
feat/issue-71-tool-mirror
Jul 7, 2026
Merged

feat(cockpit): PostToolUse tool-mirror hook — zero-token live worker activity (3c spike, closes #71)#75
robercano-ghbot merged 1 commit into
mainfrom
feat/issue-71-tool-mirror

Conversation

@robercano-ghbot

Copy link
Copy Markdown
Collaborator

Summary

Spike (Cockpit 3c, part 3 of 3 — design in #68, unblocked by #70) adding a harness-side PostToolUse tool-mirror hook that records worker Bash/Edit/Write tool calls to .claude/state/worker-tools.jsonl at zero agent tokens. Ships disabled by default — enabling is a one-line wiring change pending the go/no-go decision below.

Closes #71.

What's here

  • .claude/scripts/log-worker-tool.sh — PostToolUse hook. Mirrors only Bash/Edit/Write into JSONL {ts, tool, summary(one-line), path} (path = cwd for Bash → worktree-path attribution; file_path for Edit/Write). JSON built via node (safe escaping, single-line collapse, 200-char Bash cap). Strict no-op on any failure (always exit 0). Rotation capped to ${WORKER_TOOLS_MAX_LINES:-2000} via atomic temp+rename, mirroring log-event.sh. CLAUDE_WORKER_TOOLS_FILE override for tests. Not wired into .claude/settings.json — a commented, copy-paste wiring snippet lives in the script header.
  • .claude/scripts/log-worker-tool.test.sh — 17 checks (discovered by the test gate): per-tool capture, non-target drop, empty/malformed stdin no-op, multi-line collapse, JSON escaping, rotation cap, unwritable-dir exit-0.

Gates (self-adapter .claude/self/gates.json)

build / lint / test — all pass (test includes checks.sh + smoke-fanout.sh).

Review

Consensus (all) met: correctness (opus) APPROVE, tests (sonnet) APPROVE. Non-blocking nits noted for follow-up: Edit/Write summary field not asserted (trivial derivative of well-tested path); no explicit 200-char truncation test.

Go/no-go evaluation

  • Signal vs noise: synthetic 15-event implementer burst → 8 records mirrored (2 Edit, 1 Write, 5 Bash), 7 Read/Grep/Glob dropped (~53% of raw calls become records; every record actionable). No noise source found.
  • Log growth: ~105 bytes/record (844 bytes for the 8-record burst). At the 2000-line cap, steady-state ceiling ≈ 300–500 KB. Growth bounded regardless of session length.
  • Zero worker interference: exit-0-always confirmed under injected failures — empty/truncated stdin, unwritable dir, node absent from PATH — no error output, no corruption (0-byte file worst case).
  • 0 agent tokens: structural — hook runs in the Claude Code PostToolUse mechanism, outside the agent sandbox/context (per the repo's verified 2026-07-07 note that Pre/PostToolUse hooks run outside the sandbox). The agent never sees the hook's stdin/stdout.
  • Recommendation: GO, staying disabled by default until a short live trial confirms cwd/path from real PostToolUse payloads resolve to the worktree paths cockpit expects (this spike exercised synthetic hook-event JSON only). Cockpit read/attribution path deferred to the go decision, per plan.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SxWgee2T3w45nnPw5yZ4iu

…fault)

Adds log-worker-tool.sh, a harness-side PostToolUse hook that mirrors
Bash/Edit/Write tool calls into .claude/state/worker-tools.jsonl (0
agent tokens — runs outside the sandbox, off stdin). Mirrors
log-event.sh's node-based JSON building, resolve-roots.sh sourcing,
CLAUDE_*_FILE override, and atomic rotation exactly. Strict no-op on
any failure (malformed stdin, missing node, unwritable dir): always
exits 0.

Not wired into .claude/settings.json's PostToolUse array — spike
discipline per issue #71. The script's header comment carries a
copy-paste-ready enable snippet.

Adds log-worker-tool.test.sh (17 checks) covering per-tool mirroring,
non-target-tool/malformed-input no-ops, multi-line command collapsing,
JSON escaping, and rotation; picked up automatically by
.claude/self/checks.sh's *.test.sh glob.

Refs #71

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SxWgee2T3w45nnPw5yZ4iu
@robercano-ghbot
robercano-ghbot merged commit 5fae96f into main Jul 7, 2026
9 checks passed
@robercano-ghbot
robercano-ghbot deleted the feat/issue-71-tool-mirror branch July 7, 2026 19:02
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.

Cockpit 3c (spike): PostToolUse tool-mirror — zero-token live worker activity

2 participants