hyntx 4.0.0 → 4.1.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/dist/cli.js CHANGED
@@ -5,8 +5,8 @@ import { parseArgs } from 'util';
5
5
  import chalk2, { Chalk } from 'chalk';
6
6
  import ora from 'ora';
7
7
  import { stat, readdir, readFile, rename, mkdir, writeFile, unlink } from 'fs/promises';
8
- import { randomUUID } from 'crypto';
9
8
  import { homedir, tmpdir } from 'os';
9
+ import { randomUUID } from 'crypto';
10
10
  import { createInterface } from 'readline';
11
11
  import { spawn } from 'child_process';
12
12
 
@@ -165,6 +165,14 @@ var InsightKind = {
165
165
  MODEL_SWITCHES: "model-switches"
166
166
  };
167
167
  var REPORT_SCHEMA_VERSION = 1;
168
+ var CorrectionCause = {
169
+ MISUNDERSTOOD_REQUEST: "misunderstood-request",
170
+ WRONG_APPROACH: "wrong-approach",
171
+ BUGGY_CODE: "buggy-code",
172
+ EXCESSIVE_CHANGES: "excessive-changes",
173
+ WRONG_LOCATION: "wrong-location",
174
+ OTHER: "other"
175
+ };
168
176
  var InterpretationEngine = {
169
177
  CLAUDE: "claude",
170
178
  OLLAMA: "ollama"
@@ -174,11 +182,57 @@ var OutputFormat = {
174
182
  JSON: "json",
175
183
  MARKDOWN: "markdown"
176
184
  };
185
+
186
+ // src/core/claude-md.ts
187
+ var NO_CLAUDE_MD_HEADINGS = {
188
+ user: [],
189
+ byProject: {}
190
+ };
191
+ function parseHeadings(markdown) {
192
+ let inFence = false;
193
+ return markdown.split("\n").flatMap((line) => {
194
+ if (/^\s*(```|~~~)/.test(line)) {
195
+ inFence = !inFence;
196
+ return [];
197
+ }
198
+ const title = inFence ? void 0 : /^#{2,4}\s+(.+?)\s*#*\s*$/.exec(line)?.[1];
199
+ return title ? [title] : [];
200
+ });
201
+ }
202
+ async function readHeadings(path) {
203
+ try {
204
+ return parseHeadings(await readFile(path, "utf-8"));
205
+ } catch {
206
+ return [];
207
+ }
208
+ }
209
+ async function loadClaudeMdHeadings(projects, home = homedir()) {
210
+ const [user, entries] = await Promise.all([
211
+ readHeadings(join(home, ".claude", "CLAUDE.md")),
212
+ Promise.all(
213
+ Object.entries(projects).map(
214
+ async ([name, cwd]) => [name, await readHeadings(join(cwd, "CLAUDE.md"))]
215
+ )
216
+ )
217
+ ]);
218
+ return { user, byProject: Object.fromEntries(entries) };
219
+ }
220
+ var TOPIC_BY_KIND = {
221
+ [InsightKind.TOOL_ERROR_LOOPS]: /\b(tools?|commands?|shell|bash|environment|setup|troubleshooting|workflow)\b/i,
222
+ [InsightKind.TOOL_DENIALS]: /\b(permissions?|safety|security|hooks?|git|commands?|workflow)\b/i,
223
+ [InsightKind.CORRECTIONS]: /\b(conventions?|style|preferences?|guidelines?|rules|workflow|instructions|behaviou?r)\b/i,
224
+ [InsightKind.REPEATED_INSTRUCTION]: /\b(conventions?|style|preferences?|guidelines?|rules|workflow|instructions|behaviou?r)\b/i,
225
+ [InsightKind.REWORK]: /\b(conventions?|style|guidelines?|rules|workflow|testing|code)\b/i
226
+ };
227
+ function pickSection(headings, kind) {
228
+ const topic = TOPIC_BY_KIND[kind];
229
+ return (topic && headings.find((heading) => topic.test(heading))) ?? null;
230
+ }
177
231
  async function writeFileAtomic(filePath, content) {
178
232
  await mkdir(dirname(filePath), { recursive: true });
179
233
  const tmpFile = `${filePath}.${String(process.pid)}.${randomUUID()}.tmp`;
180
234
  try {
181
- await writeFile(tmpFile, content, "utf-8");
235
+ await writeFile(tmpFile, content, { encoding: "utf-8", mode: 384 });
182
236
  await rename(tmpFile, filePath);
183
237
  } catch (error) {
184
238
  await unlink(tmpFile).catch(() => void 0);
@@ -791,6 +845,8 @@ var ErrorClass = {
791
845
  DAEMON_DOWN: "daemon-down",
792
846
  AUTH_FAILED: "auth-failed",
793
847
  EDIT_MISMATCH: "edit-mismatch",
848
+ FILE_CHANGED: "file-changed",
849
+ FILE_TOO_LARGE: "file-too-large",
794
850
  FILE_MISSING: "file-missing",
795
851
  TIMEOUT: "timeout",
796
852
  UNCLASSIFIED: "unclassified"
@@ -814,7 +870,15 @@ function classifyToolError(call) {
814
870
  )) {
815
871
  return { id: ErrorClass.AUTH_FAILED, param: null };
816
872
  }
817
- if (/string to replace not found|found \d+ matches|file has been modified|has not been read yet/i.test(
873
+ if (/file has been modified since read/i.test(text)) {
874
+ return { id: ErrorClass.FILE_CHANGED, param: null };
875
+ }
876
+ if (/exceeds maximum allowed tokens|file is too large to read|file too large/i.test(
877
+ text
878
+ )) {
879
+ return { id: ErrorClass.FILE_TOO_LARGE, param: null };
880
+ }
881
+ if (/string to replace not found|found \d+ matches|has not been read yet/i.test(
818
882
  text
819
883
  ) || ["Edit", "MultiEdit"].includes(call.name) && /not found|unique/i.test(text)) {
820
884
  return { id: ErrorClass.EDIT_MISMATCH, param: null };
@@ -850,6 +914,11 @@ function summarizeToolErrors(calls) {
850
914
 
851
915
  // src/core/metrics.ts
852
916
  var IDLE_GAP_MINUTES = 10;
917
+ var TRIVIAL_SESSION_MAX_TYPED_PROMPTS = 1;
918
+ var TRIVIAL_SESSION_MIN_ACTIVE_MINUTES = 1;
919
+ var PARALLEL_WINDOW_MINUTES = 30;
920
+ var RESPONSE_TIME_MIN_SECONDS = 2;
921
+ var RESPONSE_TIME_MAX_SECONDS = 3600;
853
922
  var ZERO_TOKENS = {
854
923
  input: 0,
855
924
  output: 0,
@@ -918,6 +987,13 @@ var TURN_EDGES = [
918
987
  { label: "16-40", upTo: 40 },
919
988
  { label: ">40", upTo: Number.POSITIVE_INFINITY }
920
989
  ];
990
+ var RESPONSE_EDGES = [
991
+ { label: "<=10s", upTo: 10 },
992
+ { label: "10-30s", upTo: 30 },
993
+ { label: "30s-2m", upTo: 120 },
994
+ { label: "2-10m", upTo: 600 },
995
+ { label: "10m-1h", upTo: Number.POSITIVE_INFINITY }
996
+ ];
921
997
  function round(value, digits = 1) {
922
998
  const factor = 10 ** digits;
923
999
  return Math.round(value * factor) / factor;
@@ -982,6 +1058,13 @@ function countBy(values) {
982
1058
  {}
983
1059
  );
984
1060
  }
1061
+ var AUTOMATED_ENTRYPOINT_PREFIX = "sdk-";
1062
+ function isAutomatedSession(session) {
1063
+ return session.entrypoint?.startsWith(AUTOMATED_ENTRYPOINT_PREFIX) === true;
1064
+ }
1065
+ function isTrivialSession(session) {
1066
+ return session.turns.filter(isTypedTurn).length <= TRIVIAL_SESSION_MAX_TYPED_PROMPTS || computeActiveMinutes(session) < TRIVIAL_SESSION_MIN_ACTIVE_MINUTES;
1067
+ }
985
1068
  function computeAggregate(sessions) {
986
1069
  const tools = toolStats(sessions);
987
1070
  const toolCalls = tools.reduce((n, t) => n + t.calls, 0);
@@ -998,7 +1081,8 @@ function computeAggregate(sessions) {
998
1081
  ),
999
1082
  {}
1000
1083
  );
1001
- const durations = sessions.map(computeActiveMinutes);
1084
+ const substantial = sessions.filter((s) => !isTrivialSession(s));
1085
+ const durations = substantial.map(computeActiveMinutes);
1002
1086
  return {
1003
1087
  sessions: sessions.length,
1004
1088
  turns: turns.length,
@@ -1039,7 +1123,7 @@ function computeAggregate(sessions) {
1039
1123
  MINUTE_EDGES
1040
1124
  ),
1041
1125
  sessionTurns: distribution(
1042
- sessions.map((s) => s.turns.length),
1126
+ substantial.map((s) => s.turns.length),
1043
1127
  TURN_EDGES
1044
1128
  )
1045
1129
  };
@@ -1080,6 +1164,49 @@ function groupBy(items, keyOf) {
1080
1164
  }
1081
1165
  return groups;
1082
1166
  }
1167
+ function gapsToPreviousOtherSession(sorted) {
1168
+ let latest = null;
1169
+ let latestOther = null;
1170
+ return sorted.map((stamp) => {
1171
+ const other = latest?.sessionId === stamp.sessionId ? latestOther : latest;
1172
+ if (latest && latest.sessionId !== stamp.sessionId) {
1173
+ latestOther = latest;
1174
+ }
1175
+ latest = stamp;
1176
+ return other ? stamp.ms - other.ms : Number.POSITIVE_INFINITY;
1177
+ });
1178
+ }
1179
+ function computeParallelSessions(sessions) {
1180
+ const stamps = sessions.flatMap(
1181
+ (s) => s.turns.filter(isTypedTurn).map((t) => ({ sessionId: s.id, ms: Date.parse(t.prompt.timestamp) }))
1182
+ ).filter((stamp) => !Number.isNaN(stamp.ms)).sort((a, b) => a.ms - b.ms);
1183
+ const windowMs = PARALLEL_WINDOW_MINUTES * 6e4;
1184
+ const before = gapsToPreviousOtherSession(stamps);
1185
+ const after = [
1186
+ ...gapsToPreviousOtherSession(
1187
+ stamps.map((s) => ({ ...s, ms: -s.ms })).reverse()
1188
+ )
1189
+ ].reverse();
1190
+ const overlapping = stamps.filter(
1191
+ (_, i) => (before[i] ?? Number.POSITIVE_INFINITY) <= windowMs || (after[i] ?? Number.POSITIVE_INFINITY) <= windowMs
1192
+ );
1193
+ return {
1194
+ overlappingPrompts: overlapping.length,
1195
+ sessionsInvolved: new Set(overlapping.map((s) => s.sessionId)).size,
1196
+ share: stamps.length > 0 ? round(overlapping.length / stamps.length, 3) : 0
1197
+ };
1198
+ }
1199
+ function computeResponseTime(sessions) {
1200
+ const gaps = sessions.flatMap(
1201
+ (s) => s.turns.slice(1).map((turn, i) => {
1202
+ const previous = s.turns[i];
1203
+ return previous && isTypedTurn(turn) ? (Date.parse(turn.prompt.timestamp) - Date.parse(previous.endedAt)) / 1e3 : Number.NaN;
1204
+ })
1205
+ ).filter(
1206
+ (gap) => gap >= RESPONSE_TIME_MIN_SECONDS && gap <= RESPONSE_TIME_MAX_SECONDS
1207
+ ).map((gap) => round(gap));
1208
+ return { ...distribution(gaps, RESPONSE_EDGES), samples: gaps.length };
1209
+ }
1083
1210
  function computeMetrics(sessions) {
1084
1211
  const typedTimes = sessions.flatMap((s) => s.turns.filter(isTypedTurn)).map((t) => new Date(t.prompt.timestamp));
1085
1212
  const byHour = Array.from(
@@ -1097,7 +1224,12 @@ function computeMetrics(sessions) {
1097
1224
  ),
1098
1225
  byDay: [...groupBy(sessions, (s) => isoToDateKey(s.startedAt)).entries()].map(([date, group]) => ({ date, ...computeAggregate(group) })).sort((a, b) => a.date.localeCompare(b.date)),
1099
1226
  sessions: sessions.map(computeSessionMetrics),
1100
- activity: { byHour, byWeekday }
1227
+ activity: {
1228
+ byHour,
1229
+ byWeekday,
1230
+ parallelSessions: computeParallelSessions(sessions),
1231
+ responseTime: computeResponseTime(sessions)
1232
+ }
1101
1233
  };
1102
1234
  }
1103
1235
  function computeDailyPoints(sessions, episodes) {
@@ -2066,7 +2198,20 @@ function detectFriction(sessions) {
2066
2198
  }
2067
2199
 
2068
2200
  // src/core/insight-review.ts
2069
- function reviewInsight(insight, interpretation) {
2201
+ function needsVerdict(episode) {
2202
+ switch (episode.type) {
2203
+ case EpisodeType.CORRECTION:
2204
+ case EpisodeType.REPEATED_INSTRUCTION:
2205
+ case EpisodeType.REWORK:
2206
+ case EpisodeType.TOOL_ERROR_LOOP:
2207
+ return true;
2208
+ case EpisodeType.CONTEXT_PRESSURE:
2209
+ return episode.confidence < 0.8;
2210
+ default:
2211
+ return false;
2212
+ }
2213
+ }
2214
+ function reviewInsight(insight, interpretation, episodeList = []) {
2070
2215
  const ids = new Set(insight.episodeIds);
2071
2216
  const verdicts = (interpretation?.episodeVerdicts ?? []).filter(
2072
2217
  (v) => ids.has(v.episodeId)
@@ -2076,7 +2221,16 @@ function reviewInsight(insight, interpretation) {
2076
2221
  const rejected = count2("rejected");
2077
2222
  const unclear = count2("unclear");
2078
2223
  const episodes = ids.size;
2079
- const state = confirmed > 0 ? "confirmed" : episodes > 0 && rejected === episodes ? "dismissed" : "unverified";
2224
+ const byId = new Map(episodeList.map((e) => [e.id, e]));
2225
+ const isCountedFact = episodes > 0 && insight.episodeIds.every((id) => {
2226
+ const episode = byId.get(id);
2227
+ return episode !== void 0 && !needsVerdict(episode);
2228
+ });
2229
+ const state = confirmed > 0 ? "confirmed" : episodes > 0 && rejected === episodes ? "dismissed" : isCountedFact ? "not-needed" : "unverified";
2230
+ const causes = verdicts.reduce(
2231
+ (acc, v) => v.cause === void 0 ? acc : { ...acc, [v.cause]: (acc[v.cause] ?? 0) + 1 },
2232
+ {}
2233
+ );
2080
2234
  return {
2081
2235
  insightId: insight.id,
2082
2236
  state,
@@ -2084,11 +2238,14 @@ function reviewInsight(insight, interpretation) {
2084
2238
  reviewed: verdicts.length,
2085
2239
  confirmed,
2086
2240
  rejected,
2087
- unclear
2241
+ unclear,
2242
+ ...Object.keys(causes).length > 0 ? { causes } : {}
2088
2243
  };
2089
2244
  }
2090
- function reviewInsights(insights, interpretation) {
2091
- return insights.map((insight) => reviewInsight(insight, interpretation));
2245
+ function reviewInsights(insights, interpretation, episodes = []) {
2246
+ return insights.map(
2247
+ (insight) => reviewInsight(insight, interpretation, episodes)
2248
+ );
2092
2249
  }
2093
2250
 
2094
2251
  // src/core/insights.ts
@@ -2266,6 +2423,23 @@ var ERROR_ADVICE = {
2266
2423
  title: "Edits fail to find their target text",
2267
2424
  rule: () => "- Re-read the file right before editing it, and give `old_string` enough surrounding context to be unique."
2268
2425
  },
2426
+ "file-changed": {
2427
+ title: "Files change between Claude reading and editing them",
2428
+ rule: null,
2429
+ workflow: {
2430
+ kind: "workflow",
2431
+ suggestion: "Find what rewrites files while Claude works: a formatter or linter hook, or a second session on the same project.",
2432
+ steps: [
2433
+ "Check hooks in `.claude/settings.json` and `~/.claude/settings.json` for formatters that run after Edit or Write.",
2434
+ "Run the formatter on save outside Claude, or make the hook run only at the end of a turn.",
2435
+ "Avoid two sessions editing the same project at once; use a git worktree for the second one."
2436
+ ]
2437
+ }
2438
+ },
2439
+ "file-too-large": {
2440
+ title: "Whole-file reads of files that are too large",
2441
+ rule: () => "- For large files, search with Grep first or read with `offset` and `limit` instead of reading the whole file."
2442
+ },
2269
2443
  "file-missing": {
2270
2444
  title: "Calls on files or paths that do not exist",
2271
2445
  rule: () => "- Confirm a path exists (`ls` or Glob) before reading, running or editing it instead of guessing names."
@@ -2297,7 +2471,8 @@ function toolErrorInsights({ episodes }) {
2297
2471
  const tools = distinct(
2298
2472
  group.flatMap((e) => Object.keys(e.context.tools))
2299
2473
  ).slice(0, 3);
2300
- const action = advice.rule ? {
2474
+ const known = advice.rule !== null || advice.workflow !== void 0;
2475
+ const action = advice.workflow ?? (advice.rule ? {
2301
2476
  kind: "claude-md-rule",
2302
2477
  scope: "project",
2303
2478
  project,
@@ -2311,13 +2486,13 @@ function toolErrorInsights({ episodes }) {
2311
2486
  'Ask: "What is the root cause of this error? Show the evidence before changing anything."',
2312
2487
  "If the cause is environmental (service down, missing tool), fix that first, then resume."
2313
2488
  ]
2314
- };
2489
+ });
2315
2490
  return buildInsight({
2316
2491
  id: `tool-errors:${project}:${classId}:${param}`.replace(/\s+/g, "_"),
2317
2492
  kind: InsightKind.TOOL_ERROR_LOOPS,
2318
2493
  title: `${advice.title} (${project})`,
2319
2494
  // Without a known cause the claim is weak, so it never ranks high.
2320
- severity: advice.rule ? severityByCount(errors, 8, 5) : Severity.LOW,
2495
+ severity: known ? severityByCount(errors, 8, 5) : Severity.LOW,
2321
2496
  finding: `${plural(errors, "failed tool call")} in ${plural(group.length, "streak")} across ${plural(sessions, "session")}${tools.length > 0 ? ` (${tools.join(", ")})` : ""}${firstError ? `; typical error: "${firstError}"` : ""}.`,
2322
2497
  evidence: evidenceOf(
2323
2498
  group,
@@ -2332,7 +2507,7 @@ function toolErrorInsights({ episodes }) {
2332
2507
  null
2333
2508
  ),
2334
2509
  action,
2335
- confidence: advice.rule ? averageConfidence(group) : Math.min(0.5, averageConfidence(group)),
2510
+ confidence: known ? averageConfidence(group) : Math.min(0.5, averageConfidence(group)),
2336
2511
  episodes: group
2337
2512
  });
2338
2513
  });
@@ -2465,6 +2640,14 @@ function denialInsights({ episodes }) {
2465
2640
  return [];
2466
2641
  });
2467
2642
  }
2643
+ function reworkSeverity(edits, turns, interleavedFailures) {
2644
+ const returned = turns >= 3;
2645
+ const broke = interleavedFailures >= 1;
2646
+ if (edits >= 10 && returned && broke) {
2647
+ return Severity.HIGH;
2648
+ }
2649
+ return edits >= 7 && (returned || broke) ? Severity.MEDIUM : Severity.LOW;
2650
+ }
2468
2651
  function reworkInsights({ episodes }) {
2469
2652
  return episodes.filter((e) => e.type === EpisodeType.REWORK).sort((a, b) => b.count - a.count).slice(0, 3).map((episode) => {
2470
2653
  const file = detailString(episode, "file") ?? "a file";
@@ -2480,7 +2663,7 @@ function reworkInsights({ episodes }) {
2480
2663
  ),
2481
2664
  kind: InsightKind.REWORK,
2482
2665
  title: `\`${file}\` was reworked repeatedly`,
2483
- severity: severityByCount(episode.count, 10, 7),
2666
+ severity: reworkSeverity(episode.count, turns, interleaved),
2484
2667
  finding: `\`${file}\` was edited ${String(episode.count)} times across ${plural(turns, "of your prompts", "of your prompts")}${interleaved > 0 ? `, with ${plural(interleaved, "tool failure")} in between` : ""}${planUsed ? " (plan mode was used)" : " (plan mode was not used)"}.`,
2485
2668
  evidence: evidenceOf(
2486
2669
  [episode],
@@ -2789,7 +2972,17 @@ function modelSwitchInsight({ episodes }) {
2789
2972
  episodes: list
2790
2973
  });
2791
2974
  }
2975
+ function withSectionHint(insight, headings) {
2976
+ const { action } = insight;
2977
+ if (action.kind !== "claude-md-rule") {
2978
+ return insight;
2979
+ }
2980
+ const known = action.scope === "user" ? headings.user : headings.byProject[action.project ?? ""] ?? [];
2981
+ const section2 = pickSection(known, insight.kind);
2982
+ return section2 ? { ...insight, action: { ...action, section: section2 } } : insight;
2983
+ }
2792
2984
  function generateInsights(input) {
2985
+ const headings = input.claudeMdHeadings ?? NO_CLAUDE_MD_HEADINGS;
2793
2986
  return [
2794
2987
  interruptionInsight(input),
2795
2988
  correctionInsight(input),
@@ -2800,7 +2993,7 @@ function generateInsights(input) {
2800
2993
  ...repeatedInstructionInsights(input),
2801
2994
  readonlyCommandInsight(input),
2802
2995
  modelSwitchInsight(input)
2803
- ].filter((insight) => insight !== null).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
2996
+ ].filter((insight) => insight !== null).map((insight) => withSectionHint(insight, headings)).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
2804
2997
  }
2805
2998
 
2806
2999
  // src/core/report.ts
@@ -2840,15 +3033,18 @@ function sanitizeValue(value, key) {
2840
3033
  function sanitizeReport(report) {
2841
3034
  return sanitizeValue(report, null);
2842
3035
  }
2843
- function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, extraNotes) {
2844
- const enoughData = sessions.length >= MIN_SESSIONS_FOR_FINDINGS && typedPrompts >= MIN_PROMPTS_FOR_FINDINGS;
3036
+ function buildDataQuality(stats, sessions, interactive, typedPrompts, periodDays, episodes, extraNotes) {
3037
+ const interactivePrompts = interactive.flatMap((s) => s.turns).filter(isTypedTurn).length;
3038
+ const enoughData = interactive.length >= MIN_SESSIONS_FOR_FINDINGS && interactivePrompts >= MIN_PROMPTS_FOR_FINDINGS;
3039
+ const automatedSessions = sessions.length - interactive.length;
2845
3040
  const unknownCount = Object.values(stats.unknownRecordTypes).reduce(
2846
3041
  (a, b) => a + b,
2847
3042
  0
2848
3043
  );
3044
+ const trivialSessions = sessions.filter(isTrivialSession).length;
2849
3045
  const notes = [
2850
3046
  ...enoughData ? [] : [
2851
- `Only ${plural(sessions.length, "session")} and ${plural(typedPrompts, "typed prompt")} in the last ${plural(periodDays, "day")}; findings need at least ${String(MIN_SESSIONS_FOR_FINDINGS)} sessions and ${String(MIN_PROMPTS_FOR_FINDINGS)} prompts to be reliable.`
3047
+ `Only ${plural(interactive.length, "interactive session")} and ${plural(interactivePrompts, "typed prompt")} in the last ${plural(periodDays, "day")}; findings need at least ${String(MIN_SESSIONS_FOR_FINDINGS)} sessions and ${String(MIN_PROMPTS_FOR_FINDINGS)} prompts to be reliable.`
2852
3048
  ],
2853
3049
  ...unknownCount > 0 ? [
2854
3050
  `${plural(unknownCount, "record")} of unknown type ${unknownCount === 1 ? "was" : "were"} skipped (${Object.keys(stats.unknownRecordTypes).join(", ")}); the log format may have changed.`
@@ -2862,6 +3058,12 @@ function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, e
2862
3058
  ...stats.emptySessions > 0 ? [
2863
3059
  `${plural(stats.emptySessions, "session")} with no typed prompt, tool call or reply (for example only /clear or /model) ${stats.emptySessions === 1 ? "was" : "were"} left out of the counts.`
2864
3060
  ] : [],
3061
+ ...automatedSessions > 0 ? [
3062
+ `${plural(automatedSessions, "headless session")} (started by scripts or other tools) ${automatedSessions === 1 ? "is" : "are"} in the totals but left out of the friction findings.`
3063
+ ] : [],
3064
+ ...trivialSessions > 0 ? [
3065
+ `${plural(trivialSessions, "session")} had one typed prompt or under a minute of activity; ${trivialSessions === 1 ? "it is" : "they are"} in the totals but left out of the session length distributions.`
3066
+ ] : [],
2865
3067
  ...extraNotes,
2866
3068
  ...episodes.some((e) => e.type === EpisodeType.CORRECTION) ? [
2867
3069
  "Corrections are detected heuristically from phrasing and are not confirmed without an interpretation step."
@@ -2881,17 +3083,21 @@ function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, e
2881
3083
  enoughData,
2882
3084
  filesFailed: stats.filesFailed,
2883
3085
  emptySessionsSkipped: stats.emptySessions,
3086
+ trivialSessions,
3087
+ automatedSessions,
2884
3088
  notes
2885
3089
  };
2886
3090
  }
2887
3091
  function buildReport(options) {
2888
3092
  const { sessions, stats, from, to, project } = options;
2889
3093
  const metrics = computeMetrics(sessions);
2890
- const { episodes, promptTraits, notes } = detectFriction(sessions);
3094
+ const interactive = sessions.filter((s) => !isAutomatedSession(s));
3095
+ const { episodes, promptTraits, notes } = detectFriction(interactive);
2891
3096
  const insights = generateInsights({
2892
3097
  metrics,
2893
3098
  episodes,
2894
- ...options.allowedRules ? { allowedRules: options.allowedRules } : {}
3099
+ ...options.allowedRules ? { allowedRules: options.allowedRules } : {},
3100
+ ...options.claudeMdHeadings ? { claudeMdHeadings: options.claudeMdHeadings } : {}
2895
3101
  });
2896
3102
  const currentDaily = computeDailyPoints(sessions, episodes);
2897
3103
  const daily = project === null ? mergeDaily(options.history ?? [], currentDaily) : currentDaily;
@@ -2905,6 +3111,7 @@ function buildReport(options) {
2905
3111
  dataQuality: buildDataQuality(
2906
3112
  stats,
2907
3113
  sessions,
3114
+ interactive,
2908
3115
  metrics.overall.typedPrompts,
2909
3116
  periodDays,
2910
3117
  episodes,
@@ -2920,7 +3127,7 @@ function buildReport(options) {
2920
3127
  episodes,
2921
3128
  promptTraits,
2922
3129
  insights,
2923
- insightReviews: reviewInsights(insights, null),
3130
+ insightReviews: reviewInsights(insights, null, episodes),
2924
3131
  interpretation: null
2925
3132
  };
2926
3133
  return sanitizeReport(report);
@@ -3620,17 +3827,15 @@ function foldSession(acc) {
3620
3827
  messages: (previousModel?.messages ?? 0) + 1,
3621
3828
  tokens: addTokens(previousModel?.tokens ?? EMPTY_TOKENS, event.usage)
3622
3829
  });
3623
- const calls = event.toolUses.filter((use) => !seenCallIds.has(use.id)).map(
3624
- (use) => ({
3625
- id: use.id,
3626
- name: use.name,
3627
- timestamp: event.ts,
3628
- sidechain: event.sidechain,
3629
- target: use.target,
3630
- command: use.command,
3631
- result: resultsById.get(use.id) ?? null
3632
- })
3633
- );
3830
+ const calls = event.toolUses.filter((use) => !seenCallIds.has(use.id)).map((use) => ({
3831
+ id: use.id,
3832
+ name: use.name,
3833
+ timestamp: event.ts,
3834
+ sidechain: event.sidechain,
3835
+ target: use.target,
3836
+ command: use.command,
3837
+ result: resultsById.get(use.id) ?? null
3838
+ }));
3634
3839
  for (const call of calls) {
3635
3840
  seenCallIds.add(call.id);
3636
3841
  allCalls.push(call);
@@ -3837,19 +4042,6 @@ var OLLAMA_BUDGET = {
3837
4042
  textChars: 140
3838
4043
  };
3839
4044
  var MAX_RECOMMENDATIONS = 4;
3840
- function needsVerdict(episode) {
3841
- switch (episode.type) {
3842
- case EpisodeType.CORRECTION:
3843
- case EpisodeType.REPEATED_INSTRUCTION:
3844
- case EpisodeType.REWORK:
3845
- case EpisodeType.TOOL_ERROR_LOOP:
3846
- return true;
3847
- case EpisodeType.CONTEXT_PRESSURE:
3848
- return episode.confidence < 0.8;
3849
- default:
3850
- return false;
3851
- }
3852
- }
3853
4045
  var FACT_KEYS = [
3854
4046
  "previousTurnInterrupted",
3855
4047
  "errorClass",
@@ -3929,6 +4121,7 @@ var SYSTEM_PROMPT = `You are a careful analyst of a developer's Claude Code usag
3929
4121
  Rules:
3930
4122
  - Use only the evidence you are given. Never invent episodes, numbers, projects or quotes.
3931
4123
  - Judge every episode in "episodes". The type and summary of an episode are only a regex guess by the tool, so they are not evidence. Decide from the actual words in "prompt", "previousPrompt" and "assistantSaid" and from "facts". "confirmed": those words show real friction (for a correction, the user rejects or redoes what the assistant just did; for rework, the same file is being fixed again because earlier edits were wrong). "rejected": they show something else (a follow-up, a new request, a routine step). "unclear": the words are not enough; choose this when unsure. The reason is one short sentence that quotes or paraphrases specific words from that episode, never the episode type or the tool's summary.
4124
+ - For a "confirmed" episode of type "correction", also set "cause" to the closest of: misunderstood-request (Claude did not grasp what was asked), wrong-approach (right goal, wrong method), buggy-code (the change was faulty), excessive-changes (more changed than asked), wrong-location (the wrong file or place), other. Leave "cause" out for any other episode or verdict.
3932
4125
  - The summary is 2 to 4 plain sentences about how the period went, with numbers taken from "stats". Say honestly if there is little to report or if things went well.
3933
4126
  - Recommendations are 0 to ${String(MAX_RECOMMENDATIONS)} concrete actions the developer can take: a line for CLAUDE.md, a settings change, or a prompting habit. Never suggest loosening safety rules, hooks or auto-mode protections. Each one lists in basedOn the ids of the episodes or insights that justify it, copied exactly from the input. Prefer fewer, better recommendations. An empty list is correct when the evidence does not support one.
3934
4127
  - Reply with the requested JSON object only. Write in English.`;
@@ -3946,7 +4139,8 @@ var RESPONSE_SCHEMA = {
3946
4139
  type: "string",
3947
4140
  enum: ["confirmed", "rejected", "unclear"]
3948
4141
  },
3949
- reason: { type: "string" }
4142
+ reason: { type: "string" },
4143
+ cause: { type: "string", enum: Object.values(CorrectionCause) }
3950
4144
  },
3951
4145
  required: ["id", "verdict", "reason"]
3952
4146
  }
@@ -4029,6 +4223,14 @@ var VERDICTS = /* @__PURE__ */ new Set([
4029
4223
  "rejected",
4030
4224
  "unclear"
4031
4225
  ]);
4226
+ var CAUSES = new Set(Object.values(CorrectionCause));
4227
+ function asCause(value, verdict, episodeType) {
4228
+ if (typeof value !== "string" || verdict !== "confirmed" || episodeType !== EpisodeType.CORRECTION) {
4229
+ return null;
4230
+ }
4231
+ const normalized = value.trim().toLowerCase();
4232
+ return CAUSES.has(normalized) ? normalized : CorrectionCause.OTHER;
4233
+ }
4032
4234
  function validateAnswer(raw, evidence) {
4033
4235
  if (!isRecord2(raw)) {
4034
4236
  throw new EngineOutputError("the model did not return a JSON object");
@@ -4039,7 +4241,8 @@ function validateAnswer(raw, evidence) {
4039
4241
  "the model returned no usable summary (empty or placeholder text)"
4040
4242
  );
4041
4243
  }
4042
- const episodeIds = new Set(evidence.episodes.map((e) => e.id));
4244
+ const episodeTypes = new Map(evidence.episodes.map((e) => [e.id, e.type]));
4245
+ const episodeIds = new Set(episodeTypes.keys());
4043
4246
  const knownIds = /* @__PURE__ */ new Set([
4044
4247
  ...episodeIds,
4045
4248
  ...evidence.insights.map((i) => i.id)
@@ -4057,7 +4260,15 @@ function validateAnswer(raw, evidence) {
4057
4260
  return [];
4058
4261
  }
4059
4262
  seen.add(id);
4060
- return [{ episodeId: id, verdict, note }];
4263
+ const cause = asCause(item["cause"], verdict, episodeTypes.get(id));
4264
+ return [
4265
+ {
4266
+ episodeId: id,
4267
+ verdict,
4268
+ note,
4269
+ ...cause ? { cause } : {}
4270
+ }
4271
+ ];
4061
4272
  });
4062
4273
  const recommendations = (Array.isArray(raw["recommendations"]) ? raw["recommendations"] : []).flatMap((item) => {
4063
4274
  if (!isRecord2(item)) {
@@ -4353,7 +4564,8 @@ async function interpretReport(report, options) {
4353
4564
  ...sanitized,
4354
4565
  insightReviews: reviewInsights(
4355
4566
  sanitized.insights,
4356
- sanitized.interpretation
4567
+ sanitized.interpretation,
4568
+ sanitized.episodes
4357
4569
  )
4358
4570
  };
4359
4571
  } catch (error) {
@@ -4417,9 +4629,14 @@ pre{margin:.35rem 0 0;padding:10px 12px;background:var(--code-bg);border:1px sol
4417
4629
  .ba{display:grid;grid-template-columns:1fr;gap:6px}
4418
4630
  @media (min-width:640px){.ba{grid-template-columns:1fr 1fr}}
4419
4631
  .ba .tag{display:flex;justify-content:space-between;align-items:center;min-height:26px;font-size:.75rem;text-transform:uppercase;letter-spacing:.04em;color:var(--muted)}
4420
- button.copy{display:none;font:inherit;font-size:.8rem;padding:2px 10px;border-radius:5px;border:1px solid var(--border);background:var(--bg);color:var(--text);cursor:pointer}
4421
- .js button.copy{display:inline-block}
4422
- button.copy:hover{border-color:var(--accent)}
4632
+ button.copy,button.copyall{display:none;font:inherit;font-size:.8rem;padding:2px 10px;border-radius:5px;border:1px solid var(--border);background:var(--bg);color:var(--text);cursor:pointer}
4633
+ .js button.copy,.js button.copyall{display:inline-block}
4634
+ button.copy:hover,button.copyall:hover:not(:disabled){border-color:var(--accent)}
4635
+ button.copyall:disabled{opacity:.55;cursor:default}
4636
+ .acts{display:inline-flex;align-items:center;gap:10px}
4637
+ .pick{display:none;align-items:center;gap:5px;font-weight:400;font-size:.8rem;color:var(--muted);cursor:pointer}
4638
+ .js .pick{display:inline-flex}
4639
+ .copyall{margin:0 0 .75rem}
4423
4640
  details{margin:.6rem 0 0}
4424
4641
  summary{cursor:pointer;color:var(--muted);font-size:.875rem}
4425
4642
  summary:hover{color:var(--text)}
@@ -4456,7 +4673,7 @@ footer{margin-top:3rem;padding-top:1rem;border-top:1px solid var(--border);color
4456
4673
  .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
4457
4674
  @media print{
4458
4675
  body{font-size:11pt}
4459
- button.copy,.js button.copy{display:none}
4676
+ button.copy,.js button.copy,button.copyall,.js button.copyall,.pick,.js .pick{display:none}
4460
4677
  .card,figure.chart{break-inside:avoid}
4461
4678
  h2{break-after:avoid}
4462
4679
  }
@@ -4482,20 +4699,44 @@ var JS = `
4482
4699
  }
4483
4700
  return Promise.resolve(fallbackCopy(text));
4484
4701
  }
4702
+ function flash(button,ok,restore){
4703
+ var original=button.getAttribute('data-label')||button.textContent;
4704
+ button.setAttribute('data-label',original);
4705
+ button.textContent=ok?'Copied':'Copy failed';
4706
+ if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
4707
+ setTimeout(function(){button.textContent=original;button.removeAttribute('data-label');if(restore)restore();if(live)live.textContent='';},1800);
4708
+ }
4709
+ var all=document.getElementById('copy-checked');
4710
+ function picked(){
4711
+ return Array.prototype.filter.call(document.querySelectorAll('input[data-pick]'),function(input){return input.checked;});
4712
+ }
4713
+ function syncAll(){
4714
+ if(!all)return;
4715
+ var n=picked().length;
4716
+ all.disabled=n===0;
4717
+ all.textContent='Copy checked ('+n+')';
4718
+ }
4719
+ document.addEventListener('change',function(event){
4720
+ var target=event.target;
4721
+ if(target&&target.matches&&target.matches('input[data-pick]'))syncAll();
4722
+ });
4485
4723
  document.addEventListener('click',function(event){
4486
4724
  var target=event.target;
4487
4725
  if(!(target instanceof Element))return;
4726
+ if(all&&target.closest('#copy-checked')){
4727
+ var texts=picked().map(function(input){
4728
+ var source=document.getElementById(input.getAttribute('data-pick')||'');
4729
+ return source?(source.textContent||''):'';
4730
+ }).filter(function(text){return text!=='';});
4731
+ if(texts.length===0)return;
4732
+ copyText(texts.join('\\n\\n')).then(function(ok){flash(all,ok,syncAll);});
4733
+ return;
4734
+ }
4488
4735
  var button=target.closest('button.copy');
4489
4736
  if(!button)return;
4490
4737
  var source=document.getElementById(button.getAttribute('data-copy-target')||'');
4491
4738
  if(!source)return;
4492
- copyText(source.textContent||'').then(function(ok){
4493
- var original=button.getAttribute('data-label')||button.textContent;
4494
- button.setAttribute('data-label',original);
4495
- button.textContent=ok?'Copied':'Copy failed';
4496
- if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
4497
- setTimeout(function(){button.textContent=original;if(live)live.textContent='';},1800);
4498
- });
4739
+ copyText(source.textContent||'').then(function(ok){flash(button,ok,null);});
4499
4740
  });
4500
4741
  window.addEventListener('beforeprint',function(){
4501
4742
  document.querySelectorAll('details').forEach(function(d){d.setAttribute('data-was-open',d.open?'1':'0');d.open=true;});
@@ -4686,12 +4927,16 @@ var ORDER = {
4686
4927
  rejected: 1,
4687
4928
  unclear: 2
4688
4929
  };
4689
- function judgeInsight(insight, interpretation) {
4930
+ function judgeInsight(insight, interpretation, episodes = []) {
4690
4931
  const ids = new Set(insight.episodeIds);
4691
4932
  const notes = (interpretation?.episodeVerdicts ?? []).filter((v) => ids.has(v.episodeId)).map((v) => ({ verdict: v.verdict, note: v.note })).sort((a, b) => ORDER[a.verdict] - ORDER[b.verdict]);
4692
- const review = reviewInsight(insight, interpretation);
4933
+ const review = reviewInsight(insight, interpretation, episodes);
4693
4934
  return { insight, state: review.state, review, notes };
4694
4935
  }
4936
+ function describeCauses(review) {
4937
+ const parts = Object.entries(review.causes ?? {}).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([cause, n]) => `${String(n)} ${cause.replace(/-/g, " ")}`);
4938
+ return parts.length > 0 ? parts.join(", ") : null;
4939
+ }
4695
4940
  function describeCoverage(review) {
4696
4941
  if (review.reviewed === 0) {
4697
4942
  return null;
@@ -4702,11 +4947,12 @@ function describeCoverage(review) {
4702
4947
  review.unclear > 0 ? `${String(review.unclear)} unclear` : null
4703
4948
  ].filter((part) => part !== null);
4704
4949
  const unreviewed = review.episodes - review.reviewed;
4705
- return `LLM reviewed ${String(review.reviewed)} of ${String(review.episodes)} ${review.episodes === 1 ? "episode" : "episodes"}: ${parts.join(", ")}` + (unreviewed > 0 ? `; ${String(unreviewed)} not reviewed` : "");
4950
+ const causes = describeCauses(review);
4951
+ return `LLM reviewed ${String(review.reviewed)} of ${String(review.episodes)} ${review.episodes === 1 ? "episode" : "episodes"}: ${parts.join(", ")}` + (unreviewed > 0 ? `; ${String(unreviewed)} not reviewed` : "") + (causes ? `; causes: ${causes}` : "");
4706
4952
  }
4707
4953
  function judgeInsights(report) {
4708
4954
  const judged = report.insights.map(
4709
- (insight) => judgeInsight(insight, report.interpretation)
4955
+ (insight) => judgeInsight(insight, report.interpretation, report.episodes)
4710
4956
  );
4711
4957
  return {
4712
4958
  kept: judged.filter((j) => j.state !== "dismissed"),
@@ -4748,7 +4994,7 @@ function describeAction(action) {
4748
4994
  switch (action.kind) {
4749
4995
  case "claude-md-rule":
4750
4996
  return {
4751
- label: action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`,
4997
+ label: `${action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`}${action.section ? ` under "${action.section}"` : ""}`,
4752
4998
  lines: [],
4753
4999
  verbatim: action.text.split("\n")
4754
5000
  };
@@ -4816,10 +5062,13 @@ function section(id, heading, body) {
4816
5062
  ${body}
4817
5063
  </section>`;
4818
5064
  }
5065
+ function pick(id, copyLabel) {
5066
+ return `<label class="pick"><input type="checkbox" data-pick="${id}" aria-label="${esc(`Include in copy checked: ${copyLabel}`)}"><span>Select</span></label>`;
5067
+ }
4819
5068
  function copyBlock(ids, label, text, copyLabel) {
4820
5069
  const id = ids();
4821
5070
  return `<div class="action">
4822
- <div class="label"><span>${esc(label)}</span><button type="button" class="copy" data-copy-target="${id}" aria-label="${esc(`Copy: ${copyLabel}`)}">Copy</button></div>
5071
+ <div class="label"><span>${esc(label)}</span><span class="acts">${pick(id, copyLabel)}<button type="button" class="copy" data-copy-target="${id}" aria-label="${esc(`Copy: ${copyLabel}`)}">Copy</button></span></div>
4823
5072
  <pre id="${id}">${esc(text)}</pre>
4824
5073
  </div>`;
4825
5074
  }
@@ -4828,7 +5077,7 @@ function renderAction(action, ids) {
4828
5077
  case "claude-md-rule":
4829
5078
  return copyBlock(
4830
5079
  ids,
4831
- action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`,
5080
+ `${action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`}${action.section ? ` under "${action.section}"` : ""}`,
4832
5081
  action.text,
4833
5082
  "CLAUDE.md rule"
4834
5083
  );
@@ -4851,7 +5100,7 @@ function renderAction(action, ids) {
4851
5100
  const afterId = ids();
4852
5101
  const pair = action.before !== null || action.after !== null ? `<div class="ba">
4853
5102
  ${action.before !== null ? `<div><div class="tag">Before</div><pre id="${beforeId}">${esc(action.before)}</pre></div>` : ""}
4854
- ${action.after !== null ? `<div><div class="tag">After <button type="button" class="copy" data-copy-target="${afterId}" aria-label="Copy: improved prompt">Copy</button></div><pre id="${afterId}">${esc(action.after)}</pre></div>` : ""}
5103
+ ${action.after !== null ? `<div><div class="tag">After <span class="acts">${pick(afterId, "improved prompt")}<button type="button" class="copy" data-copy-target="${afterId}" aria-label="Copy: improved prompt">Copy</button></span></div><pre id="${afterId}">${esc(action.after)}</pre></div>` : ""}
4855
5104
  </div>` : "";
4856
5105
  return `<div class="action"><div class="label"><span>Prompt habit: ${esc(action.habit)}</span></div>${pair}</div>`;
4857
5106
  }
@@ -4862,7 +5111,7 @@ ${action.after !== null ? `<div><div class="tag">After <button type="button" cla
4862
5111
  ...action.steps.map((step, i) => `${String(i + 1)}. ${step}`)
4863
5112
  ].join("\n");
4864
5113
  return `<div class="action">
4865
- <div class="label"><span>Workflow: ${esc(action.suggestion)}</span><button type="button" class="copy" data-copy-target="${id}" aria-label="Copy: workflow steps">Copy</button></div>
5114
+ <div class="label"><span>Workflow: ${esc(action.suggestion)}</span><span class="acts">${pick(id, "workflow steps")}<button type="button" class="copy" data-copy-target="${id}" aria-label="Copy: workflow steps">Copy</button></span></div>
4866
5115
  ${action.steps.length > 0 ? `<ol class="steps">${action.steps.map((step) => `<li>${esc(step)}</li>`).join("")}</ol>` : ""}
4867
5116
  <pre id="${id}" class="sr-only">${esc(text)}</pre>
4868
5117
  </div>`;
@@ -4947,10 +5196,11 @@ function renderInsights(report, ids) {
4947
5196
  const dismissedHtml = dismissed.length > 0 ? `<details><summary>Dismissed by the interpretation (${esc(dismissed.length)})</summary><ul>${dismissed.map(
4948
5197
  ({ insight, notes }) => `<li>${esc(insight.title)}${notes[0] ? ` <span class="muted small">- ${esc(notes[0].note)}</span>` : ""}</li>`
4949
5198
  ).join("")}</ul></details>` : "";
5199
+ const copyAll = body.includes("data-pick=") ? '<div class="copyall"><button type="button" id="copy-checked" class="copyall" disabled>Copy checked (0)</button></div>' : "";
4950
5200
  return section(
4951
5201
  "insights",
4952
5202
  `What to change${kept.length > 0 ? ` (${String(kept.length)})` : ""}`,
4953
- `${renderInterpretationSummary(report)}${body}${dismissedHtml}`
5203
+ `${renderInterpretationSummary(report)}${copyAll}${body}${dismissedHtml}`
4954
5204
  );
4955
5205
  }
4956
5206
  var count = (value) => formatNumber(value);
@@ -5098,8 +5348,12 @@ function renderModels(report) {
5098
5348
  (m) => `<tr><th scope="row" class="name">${esc(m.model)}<span class="bar" aria-hidden="true" style="width:${String(round3(safeNumber(m.share) * 100, 1))}%"></span></th><td class="num">${esc(count(m.messages))}</td><td class="num">${esc(formatTokens(m.tokens))}</td><td class="num">${esc(formatPercent(m.share))}</td></tr>`
5099
5349
  ).join("")}</tbody></table></div>`;
5100
5350
  }
5351
+ function formatSeconds(seconds) {
5352
+ return seconds < 90 ? `${String(Math.round(seconds))} s` : formatMinutes(seconds / 60);
5353
+ }
5101
5354
  function renderHabits(report) {
5102
5355
  const { overall, activity } = report.metrics;
5356
+ const { parallelSessions, responseTime } = activity;
5103
5357
  if (overall.typedPrompts < MIN_PROMPTS_FOR_HABIT_CHARTS) {
5104
5358
  return `<p class="empty">${esc(plural2(overall.typedPrompts, "typed prompt"))} so far: too few to chart when you work. Charts appear from ${String(MIN_PROMPTS_FOR_HABIT_CHARTS)} prompts.</p>`;
5105
5359
  }
@@ -5140,9 +5394,25 @@ function renderHabits(report) {
5140
5394
  ),
5141
5395
  labels: overall.sessionMinutes.buckets.map((b) => b.label),
5142
5396
  values: overall.sessionMinutes.buckets.map((b) => b.count)
5143
- })
5397
+ }),
5398
+ ...responseTime.samples > 0 ? [
5399
+ renderCategoryChart({
5400
+ chart: describeChart(
5401
+ responseTime.buckets.map((b) => b.label),
5402
+ "response-time",
5403
+ "Time before your next prompt",
5404
+ "prompts",
5405
+ responseTime.buckets.map((b) => b.count),
5406
+ count
5407
+ ),
5408
+ labels: responseTime.buckets.map((b) => b.label),
5409
+ values: responseTime.buckets.map((b) => b.count)
5410
+ })
5411
+ ] : []
5144
5412
  ];
5145
- return `<div class="charts">${charts.join("")}</div>`;
5413
+ const parallelNote = parallelSessions.overlappingPrompts > 0 ? `<p class="muted small">Parallel sessions: ${esc(formatPercent(parallelSessions.share))} of typed prompts (${esc(count(parallelSessions.overlappingPrompts))}) came within 30 minutes of a prompt in another session, across ${esc(plural2(parallelSessions.sessionsInvolved, "session"))}.</p>` : "";
5414
+ const responseNote = responseTime.samples > 0 ? `<p class="muted small">Response time: median ${esc(formatSeconds(responseTime.median))}, p90 ${esc(formatSeconds(responseTime.p90))} over ${esc(plural2(responseTime.samples, "gap"))} between 2 seconds and 1 hour.</p>` : "";
5415
+ return `<div class="charts">${charts.join("")}</div>${parallelNote}${responseNote}`;
5146
5416
  }
5147
5417
  function renderMetrics(report) {
5148
5418
  const { overall, byProject } = report.metrics;
@@ -5172,7 +5442,7 @@ function renderEpisode(report, episode) {
5172
5442
  const verdict = report.interpretation?.episodeVerdicts.find(
5173
5443
  (v) => v.episodeId === episode.id
5174
5444
  );
5175
- return `<div class="ep"><span class="type">${esc(EPISODE_LABELS[episode.type])}</span>${verdict ? `<span class="badge ${esc(verdict.verdict)}">${esc(verdict.verdict)}</span> ` : ""}${esc(episode.summary)}${episode.count > 1 ? ` (x${esc(episode.count)})` : ""}<div class="muted small">${esc(episode.project)} - ${esc(episode.timestamp.slice(0, 10))}${episode.prompt ? ` - &ldquo;${esc(episode.prompt)}&rdquo;` : ""}${verdict?.note ? ` - ${esc(verdict.note)}` : ""}</div></div>`;
5445
+ return `<div class="ep"><span class="type">${esc(EPISODE_LABELS[episode.type])}</span>${verdict ? `<span class="badge ${esc(verdict.verdict)}">${esc(verdict.verdict)}</span> ${verdict.cause ? `<span class="muted small">${esc(verdict.cause.replace(/-/g, " "))}</span> ` : ""}` : ""}${esc(episode.summary)}${episode.count > 1 ? ` (x${esc(episode.count)})` : ""}<div class="muted small">${esc(episode.project)} - ${esc(episode.timestamp.slice(0, 10))}${episode.prompt ? ` - &ldquo;${esc(episode.prompt)}&rdquo;` : ""}${verdict?.note ? ` - ${esc(verdict.note)}` : ""}</div></div>`;
5176
5446
  }
5177
5447
  function renderEpisodes(report) {
5178
5448
  if (report.episodes.length === 0) {
@@ -5288,7 +5558,7 @@ function renderInterpretation(report) {
5288
5558
  "### Episode verdicts",
5289
5559
  "",
5290
5560
  ...interpretation.episodeVerdicts.map(
5291
- (v) => `- \`${v.episodeId}\`: **${v.verdict}** - ${v.note}`
5561
+ (v) => `- \`${v.episodeId}\`: **${v.verdict}**${v.cause ? ` (${v.cause})` : ""} - ${v.note}`
5292
5562
  ),
5293
5563
  ""
5294
5564
  ] : []
@@ -5678,11 +5948,13 @@ async function run(argv) {
5678
5948
  }
5679
5949
  spinner.text = "Analyzing...";
5680
5950
  const history = project ? { days: [], unreadable: false } : await loadDailyHistory();
5681
- const allowedRules = await loadAllowedRules(
5682
- Object.fromEntries(
5683
- sessions.flatMap((s) => s.cwd ? [[s.project, s.cwd]] : [])
5684
- )
5951
+ const projectDirs = Object.fromEntries(
5952
+ sessions.flatMap((s) => s.cwd ? [[s.project, s.cwd]] : [])
5685
5953
  );
5954
+ const [allowedRules, claudeMdHeadings] = await Promise.all([
5955
+ loadAllowedRules(projectDirs),
5956
+ loadClaudeMdHeadings(projectDirs)
5957
+ ]);
5686
5958
  let report = buildReport({
5687
5959
  sessions,
5688
5960
  stats,
@@ -5692,6 +5964,7 @@ async function run(argv) {
5692
5964
  history: history.days,
5693
5965
  historyUnreadable: history.unreadable,
5694
5966
  allowedRules,
5967
+ claudeMdHeadings,
5695
5968
  version
5696
5969
  });
5697
5970
  if (!values["no-llm"]) {