@ngockhoale/ukit 3.5.11 → 3.5.14
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/CHANGELOG.md +62 -0
- package/manifests/documentation.yaml +11 -0
- package/manifests/platform.full.yaml +39 -2
- package/package.json +1 -1
- package/scripts/audit/field-replay.mjs +194 -0
- package/scripts/audit/field-telemetry.mjs +341 -0
- package/scripts/release/candidate-state.mjs +4 -1
- package/template_project/.claude/agents/code-reviewer.md +1 -0
- package/template_project/.claude/agents/feature-implementer.md +1 -0
- package/template_project/.claude/hooks/completion-gate.sh +3 -3
- package/template_project/.claude/hooks/context-hardcap-gate.sh +40 -230
- package/template_project/.claude/hooks/context-window-guard.sh +1 -1
- package/template_project/.claude/hooks/sensitive-data-guard.mjs +297 -13
- package/template_project/.claude/settings.json +2 -2
- package/template_project/.claude/skills/code-review/SKILL.md +14 -0
- package/template_project/.claude/skills/testing-quality/SKILL.md +31 -1
- package/template_project/.claude/skills/testing-quality/memory-safe-tests.md +133 -0
- package/template_project/.claude/ukit/index/post-edit-verify.mjs +3 -7
- package/template_project/.claude/ukit/index/pre-edit-backup.mjs +1 -0
- package/template_project/.claude/ukit/index/test-batches-adapters.mjs +261 -0
- package/template_project/.claude/ukit/index/test-batches.mjs +829 -0
- package/template_project/.claude/ukit/runtime/compact-threshold.mjs +3 -3
- package/template_project/.claude/ukit/runtime/execution-ledger.mjs +92 -3
- package/template_project/.claude/ukit/runtime/output-compression.mjs +28 -1
- package/template_project/.claude/ukit/runtime/safe-patch-core.mjs +22 -0
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +40 -4
- package/template_project/.omp/agents/code-reviewer.md +1 -0
- package/template_project/.omp/agents/feature-implementer.md +1 -0
- package/template_project/.omp/config.yml +1 -1
- package/template_project/AGENTS.md +1 -1
- package/template_project/CLAUDE.md +1 -1
- package/template_project/docs/AI_HANDOFF/RULES.md +1 -1
- package/template_project/docs/memory/testing.md +10 -0
- package/template_project/instructions/core.md +1 -1
- package/template_project/ukit/storage/config.json +3 -3
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* field-telemetry.mjs — T0 of docs/plans/2026-11-20-field-telemetry-fix-program.md
|
|
4
|
+
*
|
|
5
|
+
* Offline measurement of UKit hook behaviour in Claude Code transcripts
|
|
6
|
+
* (~/.claude/projects/<project>/**.jsonl). Streams every file line by line.
|
|
7
|
+
*
|
|
8
|
+
* Collected (shapes verified against Claude Code 2.1.x transcripts):
|
|
9
|
+
* - attachment.type "hook_blocking_error" → attachment.blockingError.blockingError
|
|
10
|
+
* - attachment.type "hook_system_message" → attachment.content
|
|
11
|
+
* - top-level / attachment `systemMessage` strings (older shapes)
|
|
12
|
+
* - tool_result with permissionDecision.source === "hook" (PreToolUse denial;
|
|
13
|
+
* its " - <label>" lines are the block labels)
|
|
14
|
+
* - system/stop_hook_summary → hookInfos[].durationMs + hookErrors[]
|
|
15
|
+
* - attachment.type "hook_success" durationMs → per-hookName latency
|
|
16
|
+
* The Bash command preceding a PreToolUse block is resolved via toolUseID →
|
|
17
|
+
* the assistant tool_use block with the same id.
|
|
18
|
+
*
|
|
19
|
+
* Usage: node scripts/audit/field-telemetry.mjs [--projects-dir DIR]
|
|
20
|
+
* [--match SUBSTR]... [--since YYYY-MM-DD] [--json]
|
|
21
|
+
*/
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import fsp from 'node:fs/promises';
|
|
24
|
+
import os from 'node:os';
|
|
25
|
+
import path from 'node:path';
|
|
26
|
+
import readline from 'node:readline';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
|
|
29
|
+
// --- normalization / redaction ----------------------------------------------
|
|
30
|
+
const UUID_RE = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
|
|
31
|
+
const TOOLU_RE = /\btoolu_[A-Za-z0-9]+\b/g;
|
|
32
|
+
const HEX_RE = /\b(?=[0-9a-f]*[0-9])(?=[0-9a-f]*[a-f])[0-9a-f]{7,}\b/gi;
|
|
33
|
+
const PATH_RE = /(?<![\w.-])(?:~|\$[A-Z_]+|\.{1,2})?(?:\/[^\s"'`:,;()<>\]\[{}]+)+\/?|\b[\w.-]+(?:\/[\w.-]+){2,}\b|\b[\w.-]+(?:\/[\w.-]+)*\/[\w-]+\.[A-Za-z]\w{0,5}\b/g;
|
|
34
|
+
// ^ relative paths need >=2 slashes or a file extension, so "dotenv/secret" stays readable.
|
|
35
|
+
const NUM_RE = /\b\d+(?:\.\d+)?(?:ms|s|m|h|d|%|x|MB|KB|GB)?\b/g;
|
|
36
|
+
|
|
37
|
+
export function normalizeMessage(text, max = 140) {
|
|
38
|
+
let s = String(text ?? '');
|
|
39
|
+
s = s.replace(/<\/?system-reminder>/g, ' ');
|
|
40
|
+
s = s.replace(UUID_RE, '#').replace(TOOLU_RE, '#');
|
|
41
|
+
s = s.replace(PATH_RE, '<p>');
|
|
42
|
+
s = s.replace(HEX_RE, '#');
|
|
43
|
+
s = s.replace(NUM_RE, 'N');
|
|
44
|
+
s = s.replace(/\s+/g, ' ').trim();
|
|
45
|
+
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Masks values that look like credentials before anything is printed.
|
|
49
|
+
export function redact(text) {
|
|
50
|
+
return String(text ?? '')
|
|
51
|
+
.replace(
|
|
52
|
+
/\b([A-Za-z_][A-Za-z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|PWD|CREDENTIAL|AUTH)[A-Za-z0-9_]*)\s*([=:])\s*("[^"]*"|'[^']*'|[^\s;&|]+)/gi,
|
|
53
|
+
'$1$2<redacted>',
|
|
54
|
+
)
|
|
55
|
+
// vendor-formatted keys
|
|
56
|
+
.replace(/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, '<redacted-key>')
|
|
57
|
+
.replace(/\b(?:gh[pousr]_[A-Za-z0-9]{10,}|github_pat_[A-Za-z0-9_]{10,}|glpat-[A-Za-z0-9_-]{10,}|xox[abposr]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{12,}|AIza[0-9A-Za-z_-]{20,})/g, '<redacted-key>')
|
|
58
|
+
.replace(/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, '<redacted-jwt>')
|
|
59
|
+
.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{8,}/g, '$1 <redacted>')
|
|
60
|
+
.replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(-----END [A-Z ]*PRIVATE KEY-----|$)/g, '<private-key>')
|
|
61
|
+
// high-entropy standalone tokens (not path segments)
|
|
62
|
+
.replace(/(?<![\w/.-])(?=[A-Za-z0-9_\-+]*[0-9])(?=[A-Za-z0-9_\-+]*[A-Z])(?=[A-Za-z0-9_\-+]*[a-z])[A-Za-z0-9_\-+]{32,}={0,2}(?![\w/])/g, '<redacted>');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function truncate(text, max) {
|
|
66
|
+
const s = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
67
|
+
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// --- transcript parsing --------------------------------------------------------
|
|
71
|
+
const INTERESTING = ['hook_', 'stop_hook_summary', 'systemMessage', '"tool_use"', 'permissionDecision'];
|
|
72
|
+
|
|
73
|
+
function isoDay(ts) {
|
|
74
|
+
return typeof ts === 'string' && ts.length >= 10 ? ts.slice(0, 10) : 'unknown';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toolResultText(content) {
|
|
78
|
+
if (typeof content === 'string') return content;
|
|
79
|
+
if (Array.isArray(content)) return content.map((c) => (c && typeof c.text === 'string' ? c.text : '')).join('\n');
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parse one transcript's lines into events. `state.commands` maps tool_use id
|
|
85
|
+
* → Bash command (shared across files so subagent transcripts resolve too).
|
|
86
|
+
* Returns { events, stopDurations, hookLatency } appended into `acc`.
|
|
87
|
+
*/
|
|
88
|
+
export function parseTranscriptLine(line, acc, { since } = {}) {
|
|
89
|
+
if (!INTERESTING.some((k) => line.includes(k))) return;
|
|
90
|
+
let o;
|
|
91
|
+
try {
|
|
92
|
+
o = JSON.parse(line);
|
|
93
|
+
} catch {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!o || typeof o !== 'object') return;
|
|
97
|
+
const ts = o.timestamp;
|
|
98
|
+
if (since && typeof ts === 'string' && ts.slice(0, 10) < since) {
|
|
99
|
+
// still learn tool_use ids so later blocks can resolve their command
|
|
100
|
+
if (o.type !== 'assistant') return;
|
|
101
|
+
}
|
|
102
|
+
const day = isoDay(ts);
|
|
103
|
+
const inWindow = !since || day === 'unknown' || day >= since;
|
|
104
|
+
|
|
105
|
+
// assistant tool_use → remember Bash commands by id
|
|
106
|
+
if (o.type === 'assistant' && Array.isArray(o.message?.content)) {
|
|
107
|
+
for (const c of o.message.content) {
|
|
108
|
+
if (c && c.type === 'tool_use' && c.name === 'Bash' && c.input && typeof c.input.command === 'string') {
|
|
109
|
+
acc.commands.set(c.id, c.input.command);
|
|
110
|
+
acc.lastBash = c.input.command;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (!inWindow) return;
|
|
116
|
+
|
|
117
|
+
const push = (kind, hookEvent, hookName, text, toolUseID) => {
|
|
118
|
+
if (!text || !String(text).trim()) return;
|
|
119
|
+
acc.events.push({
|
|
120
|
+
kind,
|
|
121
|
+
hookEvent: hookEvent || 'unknown',
|
|
122
|
+
hookName: hookName || '',
|
|
123
|
+
day,
|
|
124
|
+
cls: normalizeMessage(text),
|
|
125
|
+
toolUseID: toolUseID || null,
|
|
126
|
+
command: toolUseID && acc.commands.has(toolUseID) ? acc.commands.get(toolUseID) : null,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const a = o.attachment;
|
|
131
|
+
if (a && typeof a === 'object') {
|
|
132
|
+
if (a.type === 'hook_blocking_error') {
|
|
133
|
+
const be = a.blockingError;
|
|
134
|
+
const text = typeof be === 'string' ? be : be && be.blockingError;
|
|
135
|
+
push('hook_blocking_error', a.hookEvent, a.hookName, text, a.toolUseID);
|
|
136
|
+
} else if (a.type === 'hook_system_message') {
|
|
137
|
+
push('hook_system_message', a.hookEvent, a.hookName, a.content, a.toolUseID);
|
|
138
|
+
} else if (a.type === 'hook_success' && Number.isFinite(a.durationMs)) {
|
|
139
|
+
const key = a.hookName || a.hookEvent || 'unknown';
|
|
140
|
+
(acc.hookLatency[key] ||= []).push(a.durationMs);
|
|
141
|
+
}
|
|
142
|
+
if (typeof a.systemMessage === 'string') push('systemMessage', a.hookEvent, a.hookName, a.systemMessage, a.toolUseID);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (typeof o.systemMessage === 'string') push('systemMessage', o.hookEvent, '', o.systemMessage, o.toolUseID);
|
|
147
|
+
|
|
148
|
+
if (o.type === 'system' && o.subtype === 'stop_hook_summary') {
|
|
149
|
+
const infos = Array.isArray(o.hookInfos) ? o.hookInfos : [];
|
|
150
|
+
let total = 0;
|
|
151
|
+
let seen = false;
|
|
152
|
+
for (const h of infos) {
|
|
153
|
+
if (h && Number.isFinite(h.durationMs)) {
|
|
154
|
+
total += h.durationMs;
|
|
155
|
+
seen = true;
|
|
156
|
+
acc.stopHookDurations.push(h.durationMs);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (seen) acc.stopDurations.push(total);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// PreToolUse denial surfaced as an is_error tool_result
|
|
164
|
+
if (o.type === 'user' && o.permissionDecision && o.permissionDecision.source === 'hook') {
|
|
165
|
+
const tr = Array.isArray(o.message?.content) ? o.message.content.find((c) => c && c.type === 'tool_result') : null;
|
|
166
|
+
if (!tr) return;
|
|
167
|
+
const text = toolResultText(tr.content);
|
|
168
|
+
const labels = text.split('\n').filter((l) => l.startsWith(' - ')).map((l) => l.slice(4));
|
|
169
|
+
const reason = o.permissionDecision.reasonCode || 'hook';
|
|
170
|
+
const event = /PreToolUse/.test(reason) ? 'PreToolUse' : reason.replace(/^hook:\s*/, '');
|
|
171
|
+
const headline = (text.split(']: ')[1] || text).split('\n')[0];
|
|
172
|
+
for (const label of labels.length ? labels : [headline]) {
|
|
173
|
+
push('tool_denial', event, '', label, tr.tool_use_id);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function newAccumulator() {
|
|
179
|
+
return { events: [], commands: new Map(), lastBash: null, stopDurations: [], stopHookDurations: [], hookLatency: {} };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function parseTranscriptFile(file, acc, opts) {
|
|
183
|
+
const rl = readline.createInterface({ input: fs.createReadStream(file, { encoding: 'utf8' }), crlfDelay: Infinity });
|
|
184
|
+
for await (const line of rl) parseTranscriptLine(line, acc, opts);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// --- aggregation ---------------------------------------------------------------
|
|
188
|
+
export function percentile(values, p) {
|
|
189
|
+
if (!values.length) return null;
|
|
190
|
+
const sorted = [...values].sort((x, y) => x - y);
|
|
191
|
+
const idx = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1));
|
|
192
|
+
return sorted[idx];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const stats = (v) => ({ n: v.length, p50: percentile(v, 50), p95: percentile(v, 95), max: v.length ? Math.max(...v) : null });
|
|
196
|
+
|
|
197
|
+
export function aggregate(acc, { top = 15, cmdTop = 20 } = {}) {
|
|
198
|
+
const byKey = new Map();
|
|
199
|
+
for (const e of acc.events) {
|
|
200
|
+
const key = `${e.hookEvent} | ${e.kind} | ${e.cls}`;
|
|
201
|
+
let r = byKey.get(key);
|
|
202
|
+
if (!r) {
|
|
203
|
+
r = { key, hookEvent: e.hookEvent, kind: e.kind, cls: e.cls, count: 0, days: {}, commands: new Map() };
|
|
204
|
+
byKey.set(key, r);
|
|
205
|
+
}
|
|
206
|
+
r.count += 1;
|
|
207
|
+
r.days[e.day] = (r.days[e.day] || 0) + 1;
|
|
208
|
+
if (e.hookEvent === 'PreToolUse' && e.command) {
|
|
209
|
+
const c = truncate(redact(e.command), 160);
|
|
210
|
+
r.commands.set(c, (r.commands.get(c) || 0) + 1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const classes = [...byKey.values()].sort((x, y) => y.count - x.count || x.key.localeCompare(y.key));
|
|
214
|
+
const latency = Object.fromEntries(
|
|
215
|
+
Object.entries(acc.hookLatency)
|
|
216
|
+
.map(([k, v]) => [k, stats(v)])
|
|
217
|
+
.sort((x, y) => (y[1].p95 ?? 0) - (x[1].p95 ?? 0)),
|
|
218
|
+
);
|
|
219
|
+
return {
|
|
220
|
+
totalEvents: acc.events.length,
|
|
221
|
+
classes: classes.map((r, i) => ({
|
|
222
|
+
hookEvent: r.hookEvent,
|
|
223
|
+
kind: r.kind,
|
|
224
|
+
cls: r.cls,
|
|
225
|
+
count: r.count,
|
|
226
|
+
perDay: i < top ? Object.fromEntries(Object.entries(r.days).sort()) : undefined,
|
|
227
|
+
commands:
|
|
228
|
+
r.hookEvent === 'PreToolUse'
|
|
229
|
+
? [...r.commands.entries()].sort((x, y) => y[1] - x[1]).slice(0, cmdTop).map(([command, count]) => ({ command, count }))
|
|
230
|
+
: undefined,
|
|
231
|
+
})),
|
|
232
|
+
stop: { perStop: stats(acc.stopDurations), perHook: stats(acc.stopHookDurations) },
|
|
233
|
+
hookLatency: latency,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// --- file discovery ---------------------------------------------------------------
|
|
238
|
+
export function parseArgs(argv) {
|
|
239
|
+
const opts = { projectsDir: path.join(os.homedir(), '.claude', 'projects'), match: [], since: null, json: false, limit: 20000, hook: 'sensitive', mode: 'inproc' };
|
|
240
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
241
|
+
const a = argv[i];
|
|
242
|
+
const next = () => argv[++i];
|
|
243
|
+
if (a === '--projects-dir') opts.projectsDir = next();
|
|
244
|
+
else if (a === '--match') opts.match.push(next());
|
|
245
|
+
else if (a === '--since') opts.since = next();
|
|
246
|
+
else if (a === '--json') opts.json = true;
|
|
247
|
+
else if (a === '--limit') opts.limit = Number.parseInt(next(), 10) || opts.limit;
|
|
248
|
+
else if (a === '--hook') opts.hook = next();
|
|
249
|
+
else if (a === '--mode') opts.mode = next();
|
|
250
|
+
else if (a === '--help' || a === '-h') opts.help = true;
|
|
251
|
+
}
|
|
252
|
+
if (!opts.match.length) opts.match = ['KHOA-EXTENAL'];
|
|
253
|
+
if (opts.since && !/^\d{4}-\d{2}-\d{2}$/.test(opts.since)) throw new Error(`--since must be YYYY-MM-DD, got ${opts.since}`);
|
|
254
|
+
return opts;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export async function listTranscripts({ projectsDir, match, since }) {
|
|
258
|
+
const sinceMs = since ? Date.parse(`${since}T00:00:00Z`) : 0;
|
|
259
|
+
const out = [];
|
|
260
|
+
const walk = async (dir) => {
|
|
261
|
+
let entries;
|
|
262
|
+
try {
|
|
263
|
+
entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
264
|
+
} catch {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
for (const ent of entries) {
|
|
268
|
+
const p = path.join(dir, ent.name);
|
|
269
|
+
if (ent.isDirectory()) await walk(p);
|
|
270
|
+
else if (ent.isFile() && ent.name.endsWith('.jsonl')) {
|
|
271
|
+
if (sinceMs) {
|
|
272
|
+
try {
|
|
273
|
+
if ((await fsp.stat(p)).mtimeMs < sinceMs) continue; // nothing appended after `since`
|
|
274
|
+
} catch {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
out.push(p);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const top = await fsp.readdir(projectsDir, { withFileTypes: true });
|
|
283
|
+
for (const ent of top) {
|
|
284
|
+
if (ent.isDirectory() && match.some((m) => ent.name.includes(m))) await walk(path.join(projectsDir, ent.name));
|
|
285
|
+
}
|
|
286
|
+
// Older first so tool_use ids are learned before later blocks reference them.
|
|
287
|
+
return out.sort();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// --- report ---------------------------------------------------------------------------
|
|
291
|
+
function renderText(rep, meta) {
|
|
292
|
+
const L = [];
|
|
293
|
+
L.push(`field-telemetry: ${meta.files} transcript(s), since ${meta.since || 'all'}, ${rep.totalEvents} hook message(s), ${meta.ms} ms`);
|
|
294
|
+
L.push('', '## Top classes (hookEvent | kind | class)');
|
|
295
|
+
rep.classes.slice(0, 30).forEach((c, i) => L.push(`${String(i + 1).padStart(2)}. ${String(c.count).padStart(5)} ${c.hookEvent} | ${c.kind} | ${c.cls}`));
|
|
296
|
+
L.push('', '## Per-day counts (top 15)');
|
|
297
|
+
rep.classes.slice(0, 15).forEach((c, i) => L.push(`${String(i + 1).padStart(2)}. ${Object.entries(c.perDay || {}).map(([d, n]) => `${d.slice(5)}:${n}`).join(' ')}`));
|
|
298
|
+
L.push('', '## Bash command before each PreToolUse block (top 20 per class)');
|
|
299
|
+
for (const c of rep.classes.filter((x) => x.commands && x.commands.length)) {
|
|
300
|
+
L.push(`- [${c.count}] ${c.cls}`);
|
|
301
|
+
for (const cmd of c.commands) L.push(` ${String(cmd.count).padStart(3)}x ${cmd.command}`);
|
|
302
|
+
}
|
|
303
|
+
const f = (s) => `n=${s.n} p50=${s.p50 ?? '-'}ms p95=${s.p95 ?? '-'}ms max=${s.max ?? '-'}ms`;
|
|
304
|
+
L.push('', '## Stop hook duration', `per Stop (sum of hooks): ${f(rep.stop.perStop)}`, `per hook command: ${f(rep.stop.perHook)}`);
|
|
305
|
+
L.push('', '## Hook latency (hook_success durationMs, top 15 by p95)');
|
|
306
|
+
Object.entries(rep.hookLatency).slice(0, 15).forEach(([k, s]) => L.push(` ${k.padEnd(34)} ${f(s)}`));
|
|
307
|
+
return L.join('\n');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
311
|
+
const opts = parseArgs(argv);
|
|
312
|
+
if (opts.help) {
|
|
313
|
+
process.stdout.write('Usage: field-telemetry.mjs [--projects-dir DIR] [--match SUBSTR]... [--since YYYY-MM-DD] [--json]\n');
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
const t0 = Date.now();
|
|
317
|
+
const files = await listTranscripts(opts);
|
|
318
|
+
const acc = newAccumulator();
|
|
319
|
+
for (const f of files) await parseTranscriptFile(f, acc, { since: opts.since });
|
|
320
|
+
const rep = aggregate(acc);
|
|
321
|
+
const meta = { files: files.length, since: opts.since, ms: Date.now() - t0 };
|
|
322
|
+
process.stdout.write(opts.json ? `${JSON.stringify({ meta, ...rep }, null, 2)}\n` : `${renderText(rep, meta)}\n`);
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const isDirect = (() => {
|
|
327
|
+
try {
|
|
328
|
+
return process.argv[1] && fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
|
|
329
|
+
} catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
})();
|
|
333
|
+
if (isDirect) {
|
|
334
|
+
main().then(
|
|
335
|
+
(code) => process.exit(code),
|
|
336
|
+
(err) => {
|
|
337
|
+
process.stderr.write(`field-telemetry: ${err && err.message ? err.message : err}\n`);
|
|
338
|
+
process.exit(1);
|
|
339
|
+
},
|
|
340
|
+
);
|
|
341
|
+
}
|
|
@@ -8,9 +8,12 @@ import path from 'node:path';
|
|
|
8
8
|
const mutable = /^(?:\.ukit\/storage\/|\.claude\/ukit\/runtime\/\.ukit\/storage\/|\.cache\/|node_modules\/)/;
|
|
9
9
|
|
|
10
10
|
export function candidateFingerprint(root) {
|
|
11
|
+
// `git ls-files --others` lists an untracked nested repository (a running test's temp project
|
|
12
|
+
// with its own `.git`) as one `dir/` entry. It is not a candidate input; it is dropped before
|
|
13
|
+
// hashing, so its appearing/vanishing mid-run neither crashes nor drifts the fingerprint.
|
|
11
14
|
const files = execFileSync('git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'], {
|
|
12
15
|
cwd: root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024, timeout: 30_000,
|
|
13
|
-
}).split('\0').filter((file) => file && !mutable.test(file));
|
|
16
|
+
}).split('\0').filter((file) => file && !file.endsWith('/') && !mutable.test(file));
|
|
14
17
|
const hash = createHash('sha256');
|
|
15
18
|
for (const file of [...new Set(files)].sort()) {
|
|
16
19
|
hash.update(JSON.stringify(file));
|
|
@@ -67,6 +67,7 @@ If any input is missing, return `CHANGES-REQUESTED` with reason "incomplete hand
|
|
|
67
67
|
4. **Safety / security / data loss** — Destructive actions, auth/permission, path handling, unsafe shell/DB/file ops.
|
|
68
68
|
5. **Performance / scale** — Accidental N+1, repeated I/O, large scans inside hot paths.
|
|
69
69
|
6. **Maintainability** — Duplicated logic, dead branches, misleading naming, drift between docs/tests/source.
|
|
70
|
+
6a. **Test hygiene (test diffs)** — Follow `.claude/skills/code-review/SKILL.md` § Test Diffs: app/server/client/DB fixtures without teardown, real-data reachability, per-test app registries, oversized new test files (count parametrize expansion), and tests skipped to save time/RAM. Run `node .claude/ukit/index/test-batches.mjs audit --changed`; an enforced ERROR on a new test file is `CHANGES-REQUESTED` unless the project records an exception.
|
|
70
71
|
7. **Solution fit** — For each added block, ask with evidence and cite the construct + why (never the prose length):
|
|
71
72
|
- Does new code duplicate an existing helper with the same semantics? A same-semantics duplicate is `CHANGES-REQUESTED` — reuse the existing helper.
|
|
72
73
|
- Would the standard library or a native platform API satisfy every stated requirement? If yes, the custom implementation is avoidable.
|
|
@@ -43,6 +43,7 @@ and even then, report it, don't ask about it.
|
|
|
43
43
|
### 2. Plan Approach (< 1 minute)
|
|
44
44
|
|
|
45
45
|
- List files to create/modify (max diff).
|
|
46
|
+
- **Tests you add:** plan the layout first (feature, category, expected case count incl. parametrize, target files, fixture teardown) and follow `.claude/skills/testing-quality/SKILL.md` § Writing Memory-Safe Tests — small focused files, every app/client/DB fixture torn down, test paths isolated before app import. Full-suite verification uses `node .claude/ukit/index/test-batches.mjs run`.
|
|
46
47
|
- **Handoff mode only:** if no Test Plan exists in the task file and task is not `trivial`, write one inline before implementing (happy + ≥2 edge cases of different kinds; regression test if fixing a bug). In daily mode, skip this step.
|
|
47
48
|
- **Choose the smallest solution that fully meets the stated requirements and project conventions.** When more than one option qualifies, prefer, in order: (1) reuse an existing codebase helper with the same semantics; (2) standard library, native platform API, or an already-installed dependency; (3) custom code or a new dependency (last resort). Never drop validation, security, accessibility, error handling, compatibility, or required tests to reduce code. A bugfix fixes the root cause and the affected callers. If the small option is insufficient, build the full option — never ship a weaker version and ask. No speculative abstraction for imagined needs.
|
|
48
49
|
|
|
@@ -86,10 +86,10 @@ fi
|
|
|
86
86
|
__ukit_coord_out="$(mktemp "${TMPDIR:-/tmp}/ukit-coord-out.XXXXXX")"
|
|
87
87
|
__ukit_coord_err="$(mktemp "${TMPDIR:-/tmp}/ukit-coord-err.XXXXXX" 2>/dev/null)" || __ukit_coord_err=/dev/null
|
|
88
88
|
__ukit_coord_t0=$SECONDS
|
|
89
|
-
printf '%s' "$INPUT" | UKIT_HARNESS="${UKIT_HARNESS:-claude-code}" UKIT_HOOK_DEADLINE_MS="${UKIT_HOOK_DEADLINE_MS:-
|
|
89
|
+
printf '%s' "$INPUT" | UKIT_HARNESS="${UKIT_HARNESS:-claude-code}" UKIT_HOOK_DEADLINE_MS="${UKIT_HOOK_DEADLINE_MS:-10000}" node "$SCRIPT" --evaluate-stop > "$__ukit_coord_out" 2>"$__ukit_coord_err" &
|
|
90
90
|
__ukit_coord_pid=$!
|
|
91
|
-
__ukit_coord_ms="${UKIT_HOOK_DEADLINE_MS:-
|
|
92
|
-
case "$__ukit_coord_ms" in ''|*[!0-9]*) __ukit_coord_ms=
|
|
91
|
+
__ukit_coord_ms="${UKIT_HOOK_DEADLINE_MS:-10000}"
|
|
92
|
+
case "$__ukit_coord_ms" in ''|*[!0-9]*) __ukit_coord_ms=10000 ;; esac
|
|
93
93
|
__ukit_coord_ms=$((__ukit_coord_ms + 1500))
|
|
94
94
|
printf -v __ukit_coord_s '%d.%03d' $((__ukit_coord_ms / 1000)) $((__ukit_coord_ms % 1000))
|
|
95
95
|
( sleep "$__ukit_coord_s" 2>/dev/null; kill -9 "$__ukit_coord_pid" 2>/dev/null ) <&- >/dev/null 2>&1 &
|