- lib/stats/event-emit.mjs: STATS_FILENAME -> trekexecute-stats.jsonl + comment - hooks/scripts/post-bash-stats.mjs: stats target + comment -> trekexecute-stats.jsonl - lib/stats/cache-analyzer.mjs: help-text + comment -> trekexecute-stats.jsonl - tests/lib/stats-event-emit.test.mjs (lines 104, 117): fixture assertions - settings.json: ultraplan/ultraresearch -> trekplan/trekresearch keys + statsFile values - tests/lib/doc-consistency.test.mjs: allowlist (line 83) + accessor cfg.ultraplan?.* -> cfg.trekplan?.* (lines 91, 93) — atomic-pair, prevents vacuous undefined assertions - scripts/q3-cache-prefix-experiment.mjs: STATS_JSONL hardcoded path -> voyage data dir + trekexecute filename - hooks/scripts/pre-bash-executor.mjs (2 lines), pre-compact-flush.mjs (2 lines), pre-write-executor.mjs (1 line): [ultraplan]/[ultraplan-local] stderr prefix -> [voyage] - commands + agents/review-orchestrator.md + CLAUDE.md: prose stats filename literals -> trek* equivalents Atomic per session-spec: settings.json scope keys + doc-consistency.test.mjs allowlist + property accessors committed together to prevent silent vacuous undefined-equals-undefined assertions. Part of voyage-rebrand session 2 (W3.7 / Step 9). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
58 lines
1.8 KiB
JavaScript
Executable file
58 lines
1.8 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
// post-bash-stats.mjs — PostToolUse hook (CC v2.1.97+)
|
|
//
|
|
// Captures duration_ms from PostToolUse payload for Bash tool calls and
|
|
// appends a structured stats line to ${CLAUDE_PLUGIN_DATA}/trekexecute-stats.jsonl
|
|
// when the running session is an ultraexecute session.
|
|
//
|
|
// Detection: only fires when the tool input matches the verify/checkpoint
|
|
// pattern of an ultraexecute step (i.e., the command was issued from inside
|
|
// /ultraexecute-local). We err on the side of "log everything in plugin
|
|
// scope" — duration data is cheap and the alternative is missing real
|
|
// per-step timings.
|
|
//
|
|
// Fail-open invariant: any error → exit 0, no output, no log line.
|
|
|
|
import { stdin } from 'node:process';
|
|
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
async function readStdin() {
|
|
let data = '';
|
|
for await (const chunk of stdin) data += chunk;
|
|
return data;
|
|
}
|
|
|
|
(async () => {
|
|
try {
|
|
const raw = await readStdin();
|
|
if (!raw.trim()) return;
|
|
const payload = JSON.parse(raw);
|
|
|
|
if (payload.tool_name !== 'Bash') return;
|
|
const duration = payload.duration_ms;
|
|
if (typeof duration !== 'number') return;
|
|
|
|
const dataDir = process.env.CLAUDE_PLUGIN_DATA;
|
|
if (!dataDir) return;
|
|
|
|
const cmd = payload.tool_input?.command || '';
|
|
if (!cmd) return;
|
|
|
|
const line = JSON.stringify({
|
|
ts: new Date().toISOString(),
|
|
session_id: payload.session_id || null,
|
|
command_excerpt: cmd.slice(0, 120),
|
|
duration_ms: duration,
|
|
success: payload.tool_response?.success !== false,
|
|
});
|
|
|
|
const target = join(dataDir, 'trekexecute-stats.jsonl');
|
|
try {
|
|
mkdirSync(dirname(target), { recursive: true });
|
|
} catch {}
|
|
appendFileSync(target, line + '\n');
|
|
} catch {
|
|
// fail open
|
|
}
|
|
})();
|