@swarmdo/cli 1.50.0 → 1.58.1
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/README.md +6 -3
- package/dist/src/agent-bridge/bridge.d.ts +104 -0
- package/dist/src/agent-bridge/bridge.d.ts.map +1 -0
- package/dist/src/agent-bridge/bridge.js +133 -0
- package/dist/src/agent-bridge/bridge.js.map +1 -0
- package/dist/src/command-usage/usage.d.ts +74 -0
- package/dist/src/command-usage/usage.d.ts.map +1 -0
- package/dist/src/command-usage/usage.js +161 -0
- package/dist/src/command-usage/usage.js.map +1 -0
- package/dist/src/commands/agent.d.ts.map +1 -1
- package/dist/src/commands/agent.js +133 -1
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/commands.d.ts +19 -0
- package/dist/src/commands/commands.d.ts.map +1 -0
- package/dist/src/commands/commands.js +107 -0
- package/dist/src/commands/commands.js.map +1 -0
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +11 -3
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/standup.d.ts +18 -0
- package/dist/src/commands/standup.d.ts.map +1 -0
- package/dist/src/commands/standup.js +116 -0
- package/dist/src/commands/standup.js.map +1 -0
- package/dist/src/commands/swarm.d.ts.map +1 -1
- package/dist/src/commands/swarm.js +29 -0
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/usage.d.ts.map +1 -1
- package/dist/src/commands/usage.js +57 -1
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/comms/store.d.ts +11 -1
- package/dist/src/comms/store.d.ts.map +1 -1
- package/dist/src/comms/store.js +16 -2
- package/dist/src/comms/store.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts.map +1 -1
- package/dist/src/init/helpers-generator.js +41 -1
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/statusline-generator.d.ts.map +1 -1
- package/dist/src/init/statusline-generator.js +9 -2
- package/dist/src/init/statusline-generator.js.map +1 -1
- package/dist/src/integrations/integrations.d.ts.map +1 -1
- package/dist/src/integrations/integrations.js +19 -8
- package/dist/src/integrations/integrations.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +166 -0
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/comms-tools.js +4 -4
- package/dist/src/mcp-tools/comms-tools.js.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.d.ts +33 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +73 -38
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/standup/standup.d.ts +83 -0
- package/dist/src/standup/standup.d.ts.map +1 -0
- package/dist/src/standup/standup.js +157 -0
- package/dist/src/standup/standup.js.map +1 -0
- package/dist/src/usage/transcript-friction.d.ts +77 -0
- package/dist/src/usage/transcript-friction.d.ts.map +1 -0
- package/dist/src/usage/transcript-friction.js +151 -0
- package/dist/src/usage/transcript-friction.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* standup.ts — "what did I do?" recall from git history, weekend-aware.
|
|
3
|
+
*
|
|
4
|
+
* Ports the signature behavior of git-standup: list the commits since your last
|
|
5
|
+
* WORKING day, so on Monday you reach back to Friday (not merely yesterday).
|
|
6
|
+
* Power users juggling many repos + AI-agent sessions use it to re-orient at the
|
|
7
|
+
* start of a session and to answer the standup question in one command.
|
|
8
|
+
*
|
|
9
|
+
* Pure + deterministic: the grouping core takes the raw `git log --numstat`
|
|
10
|
+
* dump (control-char delimited, subject included) and a reference Date, and
|
|
11
|
+
* folds it into per-day buckets. No LLM, no network — the git subprocess lives
|
|
12
|
+
* in ../commands/standup.ts, so this module is fully fixture-testable.
|
|
13
|
+
* `resolveRenamePath` is reused from hotspots so renamed files fold correctly.
|
|
14
|
+
*
|
|
15
|
+
* Expected log format (control-char delimited):
|
|
16
|
+
* <SOH>%H<US>%aN<US>%aI<US>%s ← one header line per commit (subject last)
|
|
17
|
+
* <added>\t<deleted>\t<path> ← one numstat line per file ('-' = binary)
|
|
18
|
+
*/
|
|
19
|
+
export interface StandupCommit {
|
|
20
|
+
hash: string;
|
|
21
|
+
author: string;
|
|
22
|
+
/** epoch milliseconds, parsed from the ISO author date */
|
|
23
|
+
date: number;
|
|
24
|
+
subject: string;
|
|
25
|
+
/** insertions summed across the commit's files (binary counts as 0) */
|
|
26
|
+
added: number;
|
|
27
|
+
/** deletions summed across the commit's files */
|
|
28
|
+
deleted: number;
|
|
29
|
+
/** count of files touched by the commit */
|
|
30
|
+
files: number;
|
|
31
|
+
}
|
|
32
|
+
export interface DayBucket {
|
|
33
|
+
/** local calendar day, `YYYY-MM-DD` */
|
|
34
|
+
day: string;
|
|
35
|
+
/** commits on this day, newest first */
|
|
36
|
+
commits: StandupCommit[];
|
|
37
|
+
/** day totals */
|
|
38
|
+
added: number;
|
|
39
|
+
deleted: number;
|
|
40
|
+
files: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How many days back to the last WORKING day (Mon–Fri), given a day-of-week
|
|
44
|
+
* (0=Sun..6=Sat). Weekend-aware, matching git-standup's signature behavior:
|
|
45
|
+
* Monday (1) → 3 (reach back to Friday)
|
|
46
|
+
* Sunday (0) → 2 (reach back to Friday)
|
|
47
|
+
* any other → 1 (yesterday)
|
|
48
|
+
* Pure integer core — no Date, no timezone. Out-of-range inputs are normalized
|
|
49
|
+
* into 0..6 so callers can pass raw arithmetic safely.
|
|
50
|
+
*/
|
|
51
|
+
export declare function daysToLastWorkingDay(dayOfWeek: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* The default weekend-aware window for a reference date. Reads the LOCAL
|
|
54
|
+
* day-of-week — a user's "last working day" is local to them. Pure w.r.t. the
|
|
55
|
+
* injected Date.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sinceLastWorkingDay(refDate: Date): {
|
|
58
|
+
sinceDays: number;
|
|
59
|
+
};
|
|
60
|
+
/** Parse the control-char-delimited standup log dump into commits. Pure. */
|
|
61
|
+
export declare function parseStandupLog(raw: string): StandupCommit[];
|
|
62
|
+
/**
|
|
63
|
+
* Local `YYYY-MM-DD` for an epoch-ms instant. Uses LOCAL calendar components so
|
|
64
|
+
* the day matches the user's wall clock; round-trips with local-constructed
|
|
65
|
+
* dates regardless of the runner timezone. Pure.
|
|
66
|
+
*/
|
|
67
|
+
export declare function dayKey(ms: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* Fold commits into per-day buckets — newest day first, and newest commit first
|
|
70
|
+
* within a day. Day boundaries are LOCAL. Pure (Array.sort is stable, so
|
|
71
|
+
* same-timestamp commits keep git-log order).
|
|
72
|
+
*/
|
|
73
|
+
export declare function groupByDay(commits: StandupCommit[]): DayBucket[];
|
|
74
|
+
/** Weekday name for a `YYYY-MM-DD` day key (local). '' if unparseable. Pure. */
|
|
75
|
+
export declare function weekdayOf(day: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Human-readable standup: a heading per day (weekday + date + counts) followed
|
|
78
|
+
* by each commit's abbreviated hash and subject, then a totals footer. Pure.
|
|
79
|
+
*/
|
|
80
|
+
export declare function formatStandup(buckets: DayBucket[], opts?: {
|
|
81
|
+
abbrev?: number;
|
|
82
|
+
}): string;
|
|
83
|
+
//# sourceMappingURL=standup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standup.d.ts","sourceRoot":"","sources":["../../../src/standup/standup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAOH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK9D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAExE;AAED,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAmC5D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAMzC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,CAkBhE;AAID,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAkB1F"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* standup.ts — "what did I do?" recall from git history, weekend-aware.
|
|
3
|
+
*
|
|
4
|
+
* Ports the signature behavior of git-standup: list the commits since your last
|
|
5
|
+
* WORKING day, so on Monday you reach back to Friday (not merely yesterday).
|
|
6
|
+
* Power users juggling many repos + AI-agent sessions use it to re-orient at the
|
|
7
|
+
* start of a session and to answer the standup question in one command.
|
|
8
|
+
*
|
|
9
|
+
* Pure + deterministic: the grouping core takes the raw `git log --numstat`
|
|
10
|
+
* dump (control-char delimited, subject included) and a reference Date, and
|
|
11
|
+
* folds it into per-day buckets. No LLM, no network — the git subprocess lives
|
|
12
|
+
* in ../commands/standup.ts, so this module is fully fixture-testable.
|
|
13
|
+
* `resolveRenamePath` is reused from hotspots so renamed files fold correctly.
|
|
14
|
+
*
|
|
15
|
+
* Expected log format (control-char delimited):
|
|
16
|
+
* <SOH>%H<US>%aN<US>%aI<US>%s ← one header line per commit (subject last)
|
|
17
|
+
* <added>\t<deleted>\t<path> ← one numstat line per file ('-' = binary)
|
|
18
|
+
*/
|
|
19
|
+
import { resolveRenamePath } from '../hotspots/hotspots.js';
|
|
20
|
+
const SOH = '\x01'; // start-of-commit marker (git --format=format:%x01...)
|
|
21
|
+
const US = '\x1f'; // field separator (%x1f)
|
|
22
|
+
/**
|
|
23
|
+
* How many days back to the last WORKING day (Mon–Fri), given a day-of-week
|
|
24
|
+
* (0=Sun..6=Sat). Weekend-aware, matching git-standup's signature behavior:
|
|
25
|
+
* Monday (1) → 3 (reach back to Friday)
|
|
26
|
+
* Sunday (0) → 2 (reach back to Friday)
|
|
27
|
+
* any other → 1 (yesterday)
|
|
28
|
+
* Pure integer core — no Date, no timezone. Out-of-range inputs are normalized
|
|
29
|
+
* into 0..6 so callers can pass raw arithmetic safely.
|
|
30
|
+
*/
|
|
31
|
+
export function daysToLastWorkingDay(dayOfWeek) {
|
|
32
|
+
const d = ((Math.trunc(dayOfWeek) % 7) + 7) % 7;
|
|
33
|
+
if (d === 1)
|
|
34
|
+
return 3; // Monday → Friday
|
|
35
|
+
if (d === 0)
|
|
36
|
+
return 2; // Sunday → Friday
|
|
37
|
+
return 1; // yesterday
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The default weekend-aware window for a reference date. Reads the LOCAL
|
|
41
|
+
* day-of-week — a user's "last working day" is local to them. Pure w.r.t. the
|
|
42
|
+
* injected Date.
|
|
43
|
+
*/
|
|
44
|
+
export function sinceLastWorkingDay(refDate) {
|
|
45
|
+
return { sinceDays: daysToLastWorkingDay(refDate.getDay()) };
|
|
46
|
+
}
|
|
47
|
+
/** Parse the control-char-delimited standup log dump into commits. Pure. */
|
|
48
|
+
export function parseStandupLog(raw) {
|
|
49
|
+
const commits = [];
|
|
50
|
+
let cur = null;
|
|
51
|
+
for (const line of raw.split('\n')) {
|
|
52
|
+
if (line === '')
|
|
53
|
+
continue;
|
|
54
|
+
if (line.startsWith(SOH)) {
|
|
55
|
+
const parts = line.slice(1).split(US);
|
|
56
|
+
const t = Date.parse(parts[2] ?? '');
|
|
57
|
+
cur = {
|
|
58
|
+
hash: parts[0] ?? '',
|
|
59
|
+
author: parts[1] ?? '',
|
|
60
|
+
date: Number.isNaN(t) ? 0 : t,
|
|
61
|
+
// subject is the last field; rejoin defensively in case it ever held a US.
|
|
62
|
+
subject: parts.slice(3).join(US),
|
|
63
|
+
added: 0,
|
|
64
|
+
deleted: 0,
|
|
65
|
+
files: 0,
|
|
66
|
+
};
|
|
67
|
+
commits.push(cur);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!cur)
|
|
71
|
+
continue;
|
|
72
|
+
// numstat: added<TAB>deleted<TAB>path ('-' means binary → count as 0)
|
|
73
|
+
const tab1 = line.indexOf('\t');
|
|
74
|
+
const tab2 = line.indexOf('\t', tab1 + 1);
|
|
75
|
+
if (tab1 < 0 || tab2 < 0)
|
|
76
|
+
continue;
|
|
77
|
+
const a = line.slice(0, tab1);
|
|
78
|
+
const d = line.slice(tab1 + 1, tab2);
|
|
79
|
+
const path = resolveRenamePath(line.slice(tab2 + 1));
|
|
80
|
+
if (!path)
|
|
81
|
+
continue;
|
|
82
|
+
cur.added += a === '-' ? 0 : parseInt(a, 10) || 0;
|
|
83
|
+
cur.deleted += d === '-' ? 0 : parseInt(d, 10) || 0;
|
|
84
|
+
cur.files += 1;
|
|
85
|
+
}
|
|
86
|
+
return commits;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Local `YYYY-MM-DD` for an epoch-ms instant. Uses LOCAL calendar components so
|
|
90
|
+
* the day matches the user's wall clock; round-trips with local-constructed
|
|
91
|
+
* dates regardless of the runner timezone. Pure.
|
|
92
|
+
*/
|
|
93
|
+
export function dayKey(ms) {
|
|
94
|
+
const d = new Date(ms);
|
|
95
|
+
const y = d.getFullYear();
|
|
96
|
+
const m = String(d.getMonth() + 1).padStart(2, '0');
|
|
97
|
+
const day = String(d.getDate()).padStart(2, '0');
|
|
98
|
+
return `${y}-${m}-${day}`;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Fold commits into per-day buckets — newest day first, and newest commit first
|
|
102
|
+
* within a day. Day boundaries are LOCAL. Pure (Array.sort is stable, so
|
|
103
|
+
* same-timestamp commits keep git-log order).
|
|
104
|
+
*/
|
|
105
|
+
export function groupByDay(commits) {
|
|
106
|
+
const map = new Map();
|
|
107
|
+
for (const c of commits) {
|
|
108
|
+
const key = dayKey(c.date);
|
|
109
|
+
let b = map.get(key);
|
|
110
|
+
if (!b) {
|
|
111
|
+
b = { day: key, commits: [], added: 0, deleted: 0, files: 0 };
|
|
112
|
+
map.set(key, b);
|
|
113
|
+
}
|
|
114
|
+
b.commits.push(c);
|
|
115
|
+
b.added += c.added;
|
|
116
|
+
b.deleted += c.deleted;
|
|
117
|
+
b.files += c.files;
|
|
118
|
+
}
|
|
119
|
+
const buckets = [...map.values()];
|
|
120
|
+
for (const b of buckets)
|
|
121
|
+
b.commits.sort((x, y) => y.date - x.date); // newest first
|
|
122
|
+
buckets.sort((x, y) => (x.day < y.day ? 1 : x.day > y.day ? -1 : 0)); // newest day first
|
|
123
|
+
return buckets;
|
|
124
|
+
}
|
|
125
|
+
const WEEKDAY = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
126
|
+
/** Weekday name for a `YYYY-MM-DD` day key (local). '' if unparseable. Pure. */
|
|
127
|
+
export function weekdayOf(day) {
|
|
128
|
+
const [y, m, d] = day.split('-').map(Number);
|
|
129
|
+
if (!y || !m || !d)
|
|
130
|
+
return '';
|
|
131
|
+
return WEEKDAY[new Date(y, m - 1, d).getDay()] ?? '';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Human-readable standup: a heading per day (weekday + date + counts) followed
|
|
135
|
+
* by each commit's abbreviated hash and subject, then a totals footer. Pure.
|
|
136
|
+
*/
|
|
137
|
+
export function formatStandup(buckets, opts = {}) {
|
|
138
|
+
if (buckets.length === 0)
|
|
139
|
+
return 'no commits in the window — nothing to report';
|
|
140
|
+
const abbrev = opts.abbrev ?? 9;
|
|
141
|
+
const totalCommits = buckets.reduce((n, b) => n + b.commits.length, 0);
|
|
142
|
+
const lines = [];
|
|
143
|
+
for (const b of buckets) {
|
|
144
|
+
const wd = weekdayOf(b.day);
|
|
145
|
+
const plural = b.commits.length === 1 ? '' : 's';
|
|
146
|
+
lines.push(`${wd ? wd + ', ' : ''}${b.day} — ${b.commits.length} commit${plural}, +${b.added}/-${b.deleted}`);
|
|
147
|
+
for (const c of b.commits) {
|
|
148
|
+
lines.push(` ${c.hash.slice(0, abbrev)} ${c.subject}`);
|
|
149
|
+
}
|
|
150
|
+
lines.push('');
|
|
151
|
+
}
|
|
152
|
+
const dp = buckets.length === 1 ? '' : 's';
|
|
153
|
+
const cp = totalCommits === 1 ? '' : 's';
|
|
154
|
+
lines.push(`${totalCommits} commit${cp} across ${buckets.length} day${dp}`);
|
|
155
|
+
return lines.join('\n');
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=standup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standup.js","sourceRoot":"","sources":["../../../src/standup/standup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAA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O,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3C,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IACzC,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY,UAAU,EAAE,WAAW,OAAO,CAAC,MAAM,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transcript-friction.ts — interruption + error-category analytics over the same
|
|
3
|
+
* Claude Code transcripts the `usage` command already reads. `usage errors`
|
|
4
|
+
* answers "which tools fail"; this answers "where does Claude waste my turns" —
|
|
5
|
+
* how often you interrupt it (ESC mid-turn), which tool was running when you did,
|
|
6
|
+
* and what KIND of errors dominate (NotFound/Permission/Timeout/Network/Syntax).
|
|
7
|
+
* The interruption axis + human-meaningful error categories are the sniffly
|
|
8
|
+
* (chiphuyen, 1.2k★) headline signals `usage errors` left on the table (#102).
|
|
9
|
+
*
|
|
10
|
+
* The fold is pure and unit-tested; only collectFriction touches the filesystem.
|
|
11
|
+
* Reuses blockText / ParsedLine (transcript-errors) + the transcript plumbing.
|
|
12
|
+
*/
|
|
13
|
+
import { type ParsedLine } from './transcript-errors.js';
|
|
14
|
+
export type ErrorCategory = 'NotFound' | 'Permission' | 'Timeout' | 'Network' | 'Syntax' | 'Other';
|
|
15
|
+
export declare const ERROR_CATEGORIES: ErrorCategory[];
|
|
16
|
+
export interface ToolInterruptions {
|
|
17
|
+
/** tool name that was running when interrupted, or '(idle)' when none was */
|
|
18
|
+
tool: string;
|
|
19
|
+
interruptions: number;
|
|
20
|
+
}
|
|
21
|
+
export interface CategoryShare {
|
|
22
|
+
category: ErrorCategory;
|
|
23
|
+
count: number;
|
|
24
|
+
/** count / totalErrors, 0..1 (0 when no errors) */
|
|
25
|
+
share: number;
|
|
26
|
+
}
|
|
27
|
+
export interface FrictionReport {
|
|
28
|
+
interruptions: number;
|
|
29
|
+
assistantTurns: number;
|
|
30
|
+
/** interruptions / assistantTurns, 0 when no turns (never divides by zero) */
|
|
31
|
+
interruptionRate: number;
|
|
32
|
+
byTool: ToolInterruptions[];
|
|
33
|
+
categories: CategoryShare[];
|
|
34
|
+
totalErrors: number;
|
|
35
|
+
filesScanned: number;
|
|
36
|
+
}
|
|
37
|
+
/** Bucket used when an interruption happened outside any running tool. */
|
|
38
|
+
export declare const IDLE_CONTEXT = "(idle)";
|
|
39
|
+
/**
|
|
40
|
+
* Does a user-role text block read as an ESC interruption sentinel? Matches the
|
|
41
|
+
* whole family at the START of the text (real transcripts show "[Request
|
|
42
|
+
* interrupted by user]", "… for tool use]", "…]", and bare "Request
|
|
43
|
+
* interrupted") — anchored so an incidental mid-sentence mention doesn't count.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isInterruptionText(text: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Map a tool-error message to a human-meaningful category. Order matters:
|
|
48
|
+
* specific buckets come before the broad Syntax catch so e.g. "no such file"
|
|
49
|
+
* lands in NotFound, not Syntax. Everything unmatched is Other. Pure.
|
|
50
|
+
*/
|
|
51
|
+
export declare function classifyError(raw: string): ErrorCategory;
|
|
52
|
+
export interface FrictionAccum {
|
|
53
|
+
interruptions: number;
|
|
54
|
+
assistantTurns: number;
|
|
55
|
+
byTool: Map<string, number>;
|
|
56
|
+
categories: Map<ErrorCategory, number>;
|
|
57
|
+
totalErrors: number;
|
|
58
|
+
/** open tool_use id → name; cleared on its result, or on an interruption */
|
|
59
|
+
openTools: Map<string, string>;
|
|
60
|
+
/** most recent tool_use name (open or already-resolved); reset per turn on an
|
|
61
|
+
* interruption. Used to attribute a "…for tool use]" sentinel even after the
|
|
62
|
+
* interrupted tool's (often synthetic) result already landed. */
|
|
63
|
+
lastToolName: string | null;
|
|
64
|
+
}
|
|
65
|
+
export declare function newFrictionAccum(): FrictionAccum;
|
|
66
|
+
/** Fold one parsed transcript line into the accumulator. Pure (no fs). */
|
|
67
|
+
export declare function foldFriction(acc: FrictionAccum, line: ParsedLine): void;
|
|
68
|
+
export declare function finalizeFriction(acc: FrictionAccum, filesScanned: number): FrictionReport;
|
|
69
|
+
export interface CollectFrictionOptions {
|
|
70
|
+
dirs?: string[];
|
|
71
|
+
since?: string;
|
|
72
|
+
until?: string;
|
|
73
|
+
}
|
|
74
|
+
/** Walk transcripts and produce the friction report. Malformed lines and
|
|
75
|
+
* unreadable files are skipped, never fatal (same discipline as collectUsage). */
|
|
76
|
+
export declare function collectFriction(opts?: CollectFrictionOptions): FrictionReport;
|
|
77
|
+
//# sourceMappingURL=transcript-friction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-friction.d.ts","sourceRoot":"","sources":["../../../src/usage/transcript-friction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AACnG,eAAO,MAAM,gBAAgB,EAAE,aAAa,EAAwE,CAAC;AAErH,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,gBAAgB,EAAE,MAAM,CAAC;IACzB,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|
2
|
+
* transcript-friction.ts — interruption + error-category analytics over the same
|
|
3
|
+
* Claude Code transcripts the `usage` command already reads. `usage errors`
|
|
4
|
+
* answers "which tools fail"; this answers "where does Claude waste my turns" —
|
|
5
|
+
* how often you interrupt it (ESC mid-turn), which tool was running when you did,
|
|
6
|
+
* and what KIND of errors dominate (NotFound/Permission/Timeout/Network/Syntax).
|
|
7
|
+
* The interruption axis + human-meaningful error categories are the sniffly
|
|
8
|
+
* (chiphuyen, 1.2k★) headline signals `usage errors` left on the table (#102).
|
|
9
|
+
*
|
|
10
|
+
* The fold is pure and unit-tested; only collectFriction touches the filesystem.
|
|
11
|
+
* Reuses blockText / ParsedLine (transcript-errors) + the transcript plumbing.
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import { defaultClaudeProjectDirs, findTranscriptFiles, normalizeDateBound } from './transcript-usage.js';
|
|
15
|
+
import { blockText } from './transcript-errors.js';
|
|
16
|
+
export const ERROR_CATEGORIES = ['NotFound', 'Permission', 'Timeout', 'Network', 'Syntax', 'Other'];
|
|
17
|
+
/** Bucket used when an interruption happened outside any running tool. */
|
|
18
|
+
export const IDLE_CONTEXT = '(idle)';
|
|
19
|
+
/**
|
|
20
|
+
* Does a user-role text block read as an ESC interruption sentinel? Matches the
|
|
21
|
+
* whole family at the START of the text (real transcripts show "[Request
|
|
22
|
+
* interrupted by user]", "… for tool use]", "…]", and bare "Request
|
|
23
|
+
* interrupted") — anchored so an incidental mid-sentence mention doesn't count.
|
|
24
|
+
*/
|
|
25
|
+
export function isInterruptionText(text) {
|
|
26
|
+
return /^\s*\[?\s*request interrupted/i.test(text);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Map a tool-error message to a human-meaningful category. Order matters:
|
|
30
|
+
* specific buckets come before the broad Syntax catch so e.g. "no such file"
|
|
31
|
+
* lands in NotFound, not Syntax. Everything unmatched is Other. Pure.
|
|
32
|
+
*/
|
|
33
|
+
export function classifyError(raw) {
|
|
34
|
+
const s = raw.toLowerCase();
|
|
35
|
+
if (/\bnot found\b|no such file|enoent|does not exist|cannot find|doesn'?t exist|\b404\b/.test(s))
|
|
36
|
+
return 'NotFound';
|
|
37
|
+
if (/permission denied|\beacces\b|\beperm\b|not permitted|unauthori[sz]ed|forbidden|\b403\b/.test(s))
|
|
38
|
+
return 'Permission';
|
|
39
|
+
if (/timed ?out|\betimedout\b|timeout|deadline exceeded/.test(s))
|
|
40
|
+
return 'Timeout';
|
|
41
|
+
if (/econnrefused|econnreset|enotfound|network|socket hang|getaddrinfo|fetch failed|\bdns\b/.test(s))
|
|
42
|
+
return 'Network';
|
|
43
|
+
if (/syntax|parse error|unexpected token|invalid |compil|typeerror|referenceerror|cannot read propert/.test(s))
|
|
44
|
+
return 'Syntax';
|
|
45
|
+
return 'Other';
|
|
46
|
+
}
|
|
47
|
+
export function newFrictionAccum() {
|
|
48
|
+
return { interruptions: 0, assistantTurns: 0, byTool: new Map(), categories: new Map(), totalErrors: 0, openTools: new Map(), lastToolName: null };
|
|
49
|
+
}
|
|
50
|
+
/** Fold one parsed transcript line into the accumulator. Pure (no fs). */
|
|
51
|
+
export function foldFriction(acc, line) {
|
|
52
|
+
const role = line.message?.role;
|
|
53
|
+
if (role === 'assistant')
|
|
54
|
+
acc.assistantTurns++;
|
|
55
|
+
const content = line.message?.content;
|
|
56
|
+
if (!Array.isArray(content))
|
|
57
|
+
return;
|
|
58
|
+
for (const b of content) {
|
|
59
|
+
if (!b || typeof b !== 'object')
|
|
60
|
+
continue;
|
|
61
|
+
if (b.type === 'tool_use' && b.id && b.name) {
|
|
62
|
+
acc.openTools.set(b.id, b.name);
|
|
63
|
+
acc.lastToolName = b.name;
|
|
64
|
+
}
|
|
65
|
+
else if (b.type === 'tool_result') {
|
|
66
|
+
if (b.tool_use_id)
|
|
67
|
+
acc.openTools.delete(b.tool_use_id);
|
|
68
|
+
if (b.is_error) {
|
|
69
|
+
acc.totalErrors++;
|
|
70
|
+
const cat = classifyError(blockText(b.content));
|
|
71
|
+
acc.categories.set(cat, (acc.categories.get(cat) ?? 0) + 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (b.type === 'text' && role === 'user' && typeof b.text === 'string' && isInterruptionText(b.text)) {
|
|
75
|
+
acc.interruptions++;
|
|
76
|
+
// Attribute to: a still-open tool (interrupted mid-execution) → else, when
|
|
77
|
+
// the sentinel says "for tool use", the last tool used even if its
|
|
78
|
+
// (synthetic) result already landed → else idle.
|
|
79
|
+
const open = [...acc.openTools.values()];
|
|
80
|
+
const tool = open.length > 0
|
|
81
|
+
? open[open.length - 1]
|
|
82
|
+
: /for tool use/i.test(b.text) && acc.lastToolName
|
|
83
|
+
? acc.lastToolName
|
|
84
|
+
: IDLE_CONTEXT;
|
|
85
|
+
acc.byTool.set(tool, (acc.byTool.get(tool) ?? 0) + 1);
|
|
86
|
+
acc.openTools.clear(); // an interrupt ends the pending turn
|
|
87
|
+
acc.lastToolName = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function finalizeFriction(acc, filesScanned) {
|
|
92
|
+
const byTool = [...acc.byTool.entries()]
|
|
93
|
+
.map(([tool, interruptions]) => ({ tool, interruptions }))
|
|
94
|
+
.sort((a, b) => b.interruptions - a.interruptions || a.tool.localeCompare(b.tool));
|
|
95
|
+
const categories = [...acc.categories.entries()]
|
|
96
|
+
.map(([category, count]) => ({ category, count, share: acc.totalErrors > 0 ? count / acc.totalErrors : 0 }))
|
|
97
|
+
.sort((a, b) => b.count - a.count || a.category.localeCompare(b.category));
|
|
98
|
+
return {
|
|
99
|
+
interruptions: acc.interruptions,
|
|
100
|
+
assistantTurns: acc.assistantTurns,
|
|
101
|
+
interruptionRate: acc.assistantTurns > 0 ? acc.interruptions / acc.assistantTurns : 0,
|
|
102
|
+
byTool,
|
|
103
|
+
categories,
|
|
104
|
+
totalErrors: acc.totalErrors,
|
|
105
|
+
filesScanned,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Walk transcripts and produce the friction report. Malformed lines and
|
|
109
|
+
* unreadable files are skipped, never fatal (same discipline as collectUsage). */
|
|
110
|
+
export function collectFriction(opts = {}) {
|
|
111
|
+
const dirs = opts.dirs && opts.dirs.length > 0 ? opts.dirs : defaultClaudeProjectDirs();
|
|
112
|
+
const since = normalizeDateBound(opts.since);
|
|
113
|
+
const until = normalizeDateBound(opts.until);
|
|
114
|
+
const acc = newFrictionAccum();
|
|
115
|
+
let filesScanned = 0;
|
|
116
|
+
for (const dir of dirs) {
|
|
117
|
+
for (const { file } of findTranscriptFiles(dir)) {
|
|
118
|
+
filesScanned++;
|
|
119
|
+
let content;
|
|
120
|
+
try {
|
|
121
|
+
content = fs.readFileSync(file, 'utf8');
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
for (const raw of content.split('\n')) {
|
|
127
|
+
if (!raw.trim())
|
|
128
|
+
continue;
|
|
129
|
+
let line;
|
|
130
|
+
try {
|
|
131
|
+
line = JSON.parse(raw);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (since || until) {
|
|
137
|
+
const day = line.timestamp ? line.timestamp.slice(0, 10) : '';
|
|
138
|
+
if (day) {
|
|
139
|
+
if (since && day < since)
|
|
140
|
+
continue;
|
|
141
|
+
if (until && day > until)
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
foldFriction(acc, line);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return finalizeFriction(acc, filesScanned);
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=transcript-friction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-friction.js","sourceRoot":"","sources":["../../../src/usage/transcript-friction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAA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