hyntx 4.0.0 → 4.1.0

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);
@@ -3837,19 +4044,6 @@ var OLLAMA_BUDGET = {
3837
4044
  textChars: 140
3838
4045
  };
3839
4046
  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
4047
  var FACT_KEYS = [
3854
4048
  "previousTurnInterrupted",
3855
4049
  "errorClass",
@@ -3929,6 +4123,7 @@ var SYSTEM_PROMPT = `You are a careful analyst of a developer's Claude Code usag
3929
4123
  Rules:
3930
4124
  - Use only the evidence you are given. Never invent episodes, numbers, projects or quotes.
3931
4125
  - 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.
4126
+ - 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
4127
  - 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
4128
  - 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
4129
  - Reply with the requested JSON object only. Write in English.`;
@@ -3946,7 +4141,8 @@ var RESPONSE_SCHEMA = {
3946
4141
  type: "string",
3947
4142
  enum: ["confirmed", "rejected", "unclear"]
3948
4143
  },
3949
- reason: { type: "string" }
4144
+ reason: { type: "string" },
4145
+ cause: { type: "string", enum: Object.values(CorrectionCause) }
3950
4146
  },
3951
4147
  required: ["id", "verdict", "reason"]
3952
4148
  }
@@ -4029,6 +4225,14 @@ var VERDICTS = /* @__PURE__ */ new Set([
4029
4225
  "rejected",
4030
4226
  "unclear"
4031
4227
  ]);
4228
+ var CAUSES = new Set(Object.values(CorrectionCause));
4229
+ function asCause(value, verdict, episodeType) {
4230
+ if (typeof value !== "string" || verdict !== "confirmed" || episodeType !== EpisodeType.CORRECTION) {
4231
+ return null;
4232
+ }
4233
+ const normalized = value.trim().toLowerCase();
4234
+ return CAUSES.has(normalized) ? normalized : CorrectionCause.OTHER;
4235
+ }
4032
4236
  function validateAnswer(raw, evidence) {
4033
4237
  if (!isRecord2(raw)) {
4034
4238
  throw new EngineOutputError("the model did not return a JSON object");
@@ -4039,7 +4243,8 @@ function validateAnswer(raw, evidence) {
4039
4243
  "the model returned no usable summary (empty or placeholder text)"
4040
4244
  );
4041
4245
  }
4042
- const episodeIds = new Set(evidence.episodes.map((e) => e.id));
4246
+ const episodeTypes = new Map(evidence.episodes.map((e) => [e.id, e.type]));
4247
+ const episodeIds = new Set(episodeTypes.keys());
4043
4248
  const knownIds = /* @__PURE__ */ new Set([
4044
4249
  ...episodeIds,
4045
4250
  ...evidence.insights.map((i) => i.id)
@@ -4057,7 +4262,15 @@ function validateAnswer(raw, evidence) {
4057
4262
  return [];
4058
4263
  }
4059
4264
  seen.add(id);
4060
- return [{ episodeId: id, verdict, note }];
4265
+ const cause = asCause(item["cause"], verdict, episodeTypes.get(id));
4266
+ return [
4267
+ {
4268
+ episodeId: id,
4269
+ verdict,
4270
+ note,
4271
+ ...cause ? { cause } : {}
4272
+ }
4273
+ ];
4061
4274
  });
4062
4275
  const recommendations = (Array.isArray(raw["recommendations"]) ? raw["recommendations"] : []).flatMap((item) => {
4063
4276
  if (!isRecord2(item)) {
@@ -4353,7 +4566,8 @@ async function interpretReport(report, options) {
4353
4566
  ...sanitized,
4354
4567
  insightReviews: reviewInsights(
4355
4568
  sanitized.insights,
4356
- sanitized.interpretation
4569
+ sanitized.interpretation,
4570
+ sanitized.episodes
4357
4571
  )
4358
4572
  };
4359
4573
  } catch (error) {
@@ -4417,9 +4631,14 @@ pre{margin:.35rem 0 0;padding:10px 12px;background:var(--code-bg);border:1px sol
4417
4631
  .ba{display:grid;grid-template-columns:1fr;gap:6px}
4418
4632
  @media (min-width:640px){.ba{grid-template-columns:1fr 1fr}}
4419
4633
  .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)}
4634
+ 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}
4635
+ .js button.copy,.js button.copyall{display:inline-block}
4636
+ button.copy:hover,button.copyall:hover:not(:disabled){border-color:var(--accent)}
4637
+ button.copyall:disabled{opacity:.55;cursor:default}
4638
+ .acts{display:inline-flex;align-items:center;gap:10px}
4639
+ .pick{display:none;align-items:center;gap:5px;font-weight:400;font-size:.8rem;color:var(--muted);cursor:pointer}
4640
+ .js .pick{display:inline-flex}
4641
+ .copyall{margin:0 0 .75rem}
4423
4642
  details{margin:.6rem 0 0}
4424
4643
  summary{cursor:pointer;color:var(--muted);font-size:.875rem}
4425
4644
  summary:hover{color:var(--text)}
@@ -4456,7 +4675,7 @@ footer{margin-top:3rem;padding-top:1rem;border-top:1px solid var(--border);color
4456
4675
  .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
4457
4676
  @media print{
4458
4677
  body{font-size:11pt}
4459
- button.copy,.js button.copy{display:none}
4678
+ button.copy,.js button.copy,button.copyall,.js button.copyall,.pick,.js .pick{display:none}
4460
4679
  .card,figure.chart{break-inside:avoid}
4461
4680
  h2{break-after:avoid}
4462
4681
  }
@@ -4482,20 +4701,44 @@ var JS = `
4482
4701
  }
4483
4702
  return Promise.resolve(fallbackCopy(text));
4484
4703
  }
4704
+ function flash(button,ok,restore){
4705
+ var original=button.getAttribute('data-label')||button.textContent;
4706
+ button.setAttribute('data-label',original);
4707
+ button.textContent=ok?'Copied':'Copy failed';
4708
+ if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
4709
+ setTimeout(function(){button.textContent=original;button.removeAttribute('data-label');if(restore)restore();if(live)live.textContent='';},1800);
4710
+ }
4711
+ var all=document.getElementById('copy-checked');
4712
+ function picked(){
4713
+ return Array.prototype.filter.call(document.querySelectorAll('input[data-pick]'),function(input){return input.checked;});
4714
+ }
4715
+ function syncAll(){
4716
+ if(!all)return;
4717
+ var n=picked().length;
4718
+ all.disabled=n===0;
4719
+ all.textContent='Copy checked ('+n+')';
4720
+ }
4721
+ document.addEventListener('change',function(event){
4722
+ var target=event.target;
4723
+ if(target&&target.matches&&target.matches('input[data-pick]'))syncAll();
4724
+ });
4485
4725
  document.addEventListener('click',function(event){
4486
4726
  var target=event.target;
4487
4727
  if(!(target instanceof Element))return;
4728
+ if(all&&target.closest('#copy-checked')){
4729
+ var texts=picked().map(function(input){
4730
+ var source=document.getElementById(input.getAttribute('data-pick')||'');
4731
+ return source?(source.textContent||''):'';
4732
+ }).filter(function(text){return text!=='';});
4733
+ if(texts.length===0)return;
4734
+ copyText(texts.join('\\n\\n')).then(function(ok){flash(all,ok,syncAll);});
4735
+ return;
4736
+ }
4488
4737
  var button=target.closest('button.copy');
4489
4738
  if(!button)return;
4490
4739
  var source=document.getElementById(button.getAttribute('data-copy-target')||'');
4491
4740
  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
- });
4741
+ copyText(source.textContent||'').then(function(ok){flash(button,ok,null);});
4499
4742
  });
4500
4743
  window.addEventListener('beforeprint',function(){
4501
4744
  document.querySelectorAll('details').forEach(function(d){d.setAttribute('data-was-open',d.open?'1':'0');d.open=true;});
@@ -4686,12 +4929,16 @@ var ORDER = {
4686
4929
  rejected: 1,
4687
4930
  unclear: 2
4688
4931
  };
4689
- function judgeInsight(insight, interpretation) {
4932
+ function judgeInsight(insight, interpretation, episodes = []) {
4690
4933
  const ids = new Set(insight.episodeIds);
4691
4934
  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);
4935
+ const review = reviewInsight(insight, interpretation, episodes);
4693
4936
  return { insight, state: review.state, review, notes };
4694
4937
  }
4938
+ function describeCauses(review) {
4939
+ const parts = Object.entries(review.causes ?? {}).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([cause, n]) => `${String(n)} ${cause.replace(/-/g, " ")}`);
4940
+ return parts.length > 0 ? parts.join(", ") : null;
4941
+ }
4695
4942
  function describeCoverage(review) {
4696
4943
  if (review.reviewed === 0) {
4697
4944
  return null;
@@ -4702,11 +4949,12 @@ function describeCoverage(review) {
4702
4949
  review.unclear > 0 ? `${String(review.unclear)} unclear` : null
4703
4950
  ].filter((part) => part !== null);
4704
4951
  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` : "");
4952
+ const causes = describeCauses(review);
4953
+ 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
4954
  }
4707
4955
  function judgeInsights(report) {
4708
4956
  const judged = report.insights.map(
4709
- (insight) => judgeInsight(insight, report.interpretation)
4957
+ (insight) => judgeInsight(insight, report.interpretation, report.episodes)
4710
4958
  );
4711
4959
  return {
4712
4960
  kept: judged.filter((j) => j.state !== "dismissed"),
@@ -4748,7 +4996,7 @@ function describeAction(action) {
4748
4996
  switch (action.kind) {
4749
4997
  case "claude-md-rule":
4750
4998
  return {
4751
- label: action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`,
4999
+ label: `${action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`}${action.section ? ` under "${action.section}"` : ""}`,
4752
5000
  lines: [],
4753
5001
  verbatim: action.text.split("\n")
4754
5002
  };
@@ -4816,10 +5064,13 @@ function section(id, heading, body) {
4816
5064
  ${body}
4817
5065
  </section>`;
4818
5066
  }
5067
+ function pick(id, copyLabel) {
5068
+ return `<label class="pick"><input type="checkbox" data-pick="${id}" aria-label="${esc(`Include in copy checked: ${copyLabel}`)}"><span>Select</span></label>`;
5069
+ }
4819
5070
  function copyBlock(ids, label, text, copyLabel) {
4820
5071
  const id = ids();
4821
5072
  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>
5073
+ <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
5074
  <pre id="${id}">${esc(text)}</pre>
4824
5075
  </div>`;
4825
5076
  }
@@ -4828,7 +5079,7 @@ function renderAction(action, ids) {
4828
5079
  case "claude-md-rule":
4829
5080
  return copyBlock(
4830
5081
  ids,
4831
- action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`,
5082
+ `${action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`}${action.section ? ` under "${action.section}"` : ""}`,
4832
5083
  action.text,
4833
5084
  "CLAUDE.md rule"
4834
5085
  );
@@ -4851,7 +5102,7 @@ function renderAction(action, ids) {
4851
5102
  const afterId = ids();
4852
5103
  const pair = action.before !== null || action.after !== null ? `<div class="ba">
4853
5104
  ${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>` : ""}
5105
+ ${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
5106
  </div>` : "";
4856
5107
  return `<div class="action"><div class="label"><span>Prompt habit: ${esc(action.habit)}</span></div>${pair}</div>`;
4857
5108
  }
@@ -4862,7 +5113,7 @@ ${action.after !== null ? `<div><div class="tag">After <button type="button" cla
4862
5113
  ...action.steps.map((step, i) => `${String(i + 1)}. ${step}`)
4863
5114
  ].join("\n");
4864
5115
  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>
5116
+ <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
5117
  ${action.steps.length > 0 ? `<ol class="steps">${action.steps.map((step) => `<li>${esc(step)}</li>`).join("")}</ol>` : ""}
4867
5118
  <pre id="${id}" class="sr-only">${esc(text)}</pre>
4868
5119
  </div>`;
@@ -4947,10 +5198,11 @@ function renderInsights(report, ids) {
4947
5198
  const dismissedHtml = dismissed.length > 0 ? `<details><summary>Dismissed by the interpretation (${esc(dismissed.length)})</summary><ul>${dismissed.map(
4948
5199
  ({ insight, notes }) => `<li>${esc(insight.title)}${notes[0] ? ` <span class="muted small">- ${esc(notes[0].note)}</span>` : ""}</li>`
4949
5200
  ).join("")}</ul></details>` : "";
5201
+ const copyAll = body.includes("data-pick=") ? '<div class="copyall"><button type="button" id="copy-checked" class="copyall" disabled>Copy checked (0)</button></div>' : "";
4950
5202
  return section(
4951
5203
  "insights",
4952
5204
  `What to change${kept.length > 0 ? ` (${String(kept.length)})` : ""}`,
4953
- `${renderInterpretationSummary(report)}${body}${dismissedHtml}`
5205
+ `${renderInterpretationSummary(report)}${copyAll}${body}${dismissedHtml}`
4954
5206
  );
4955
5207
  }
4956
5208
  var count = (value) => formatNumber(value);
@@ -5098,8 +5350,12 @@ function renderModels(report) {
5098
5350
  (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
5351
  ).join("")}</tbody></table></div>`;
5100
5352
  }
5353
+ function formatSeconds(seconds) {
5354
+ return seconds < 90 ? `${String(Math.round(seconds))} s` : formatMinutes(seconds / 60);
5355
+ }
5101
5356
  function renderHabits(report) {
5102
5357
  const { overall, activity } = report.metrics;
5358
+ const { parallelSessions, responseTime } = activity;
5103
5359
  if (overall.typedPrompts < MIN_PROMPTS_FOR_HABIT_CHARTS) {
5104
5360
  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
5361
  }
@@ -5140,9 +5396,25 @@ function renderHabits(report) {
5140
5396
  ),
5141
5397
  labels: overall.sessionMinutes.buckets.map((b) => b.label),
5142
5398
  values: overall.sessionMinutes.buckets.map((b) => b.count)
5143
- })
5399
+ }),
5400
+ ...responseTime.samples > 0 ? [
5401
+ renderCategoryChart({
5402
+ chart: describeChart(
5403
+ responseTime.buckets.map((b) => b.label),
5404
+ "response-time",
5405
+ "Time before your next prompt",
5406
+ "prompts",
5407
+ responseTime.buckets.map((b) => b.count),
5408
+ count
5409
+ ),
5410
+ labels: responseTime.buckets.map((b) => b.label),
5411
+ values: responseTime.buckets.map((b) => b.count)
5412
+ })
5413
+ ] : []
5144
5414
  ];
5145
- return `<div class="charts">${charts.join("")}</div>`;
5415
+ 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>` : "";
5416
+ 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>` : "";
5417
+ return `<div class="charts">${charts.join("")}</div>${parallelNote}${responseNote}`;
5146
5418
  }
5147
5419
  function renderMetrics(report) {
5148
5420
  const { overall, byProject } = report.metrics;
@@ -5172,7 +5444,7 @@ function renderEpisode(report, episode) {
5172
5444
  const verdict = report.interpretation?.episodeVerdicts.find(
5173
5445
  (v) => v.episodeId === episode.id
5174
5446
  );
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>`;
5447
+ 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
5448
  }
5177
5449
  function renderEpisodes(report) {
5178
5450
  if (report.episodes.length === 0) {
@@ -5288,7 +5560,7 @@ function renderInterpretation(report) {
5288
5560
  "### Episode verdicts",
5289
5561
  "",
5290
5562
  ...interpretation.episodeVerdicts.map(
5291
- (v) => `- \`${v.episodeId}\`: **${v.verdict}** - ${v.note}`
5563
+ (v) => `- \`${v.episodeId}\`: **${v.verdict}**${v.cause ? ` (${v.cause})` : ""} - ${v.note}`
5292
5564
  ),
5293
5565
  ""
5294
5566
  ] : []
@@ -5678,11 +5950,13 @@ async function run(argv) {
5678
5950
  }
5679
5951
  spinner.text = "Analyzing...";
5680
5952
  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
- )
5953
+ const projectDirs = Object.fromEntries(
5954
+ sessions.flatMap((s) => s.cwd ? [[s.project, s.cwd]] : [])
5685
5955
  );
5956
+ const [allowedRules, claudeMdHeadings] = await Promise.all([
5957
+ loadAllowedRules(projectDirs),
5958
+ loadClaudeMdHeadings(projectDirs)
5959
+ ]);
5686
5960
  let report = buildReport({
5687
5961
  sessions,
5688
5962
  stats,
@@ -5692,6 +5966,7 @@ async function run(argv) {
5692
5966
  history: history.days,
5693
5967
  historyUnreadable: history.unreadable,
5694
5968
  allowedRules,
5969
+ claudeMdHeadings,
5695
5970
  version
5696
5971
  });
5697
5972
  if (!values["no-llm"]) {