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/index.js CHANGED
@@ -59,6 +59,14 @@ var InsightKind = {
59
59
  MODEL_SWITCHES: "model-switches"
60
60
  };
61
61
  var REPORT_SCHEMA_VERSION = 1;
62
+ var CorrectionCause = {
63
+ MISUNDERSTOOD_REQUEST: "misunderstood-request",
64
+ WRONG_APPROACH: "wrong-approach",
65
+ BUGGY_CODE: "buggy-code",
66
+ EXCESSIVE_CHANGES: "excessive-changes",
67
+ WRONG_LOCATION: "wrong-location",
68
+ OTHER: "other"
69
+ };
62
70
  var InterpretationEngine = {
63
71
  CLAUDE: "claude",
64
72
  OLLAMA: "ollama"
@@ -547,6 +555,8 @@ var ErrorClass = {
547
555
  DAEMON_DOWN: "daemon-down",
548
556
  AUTH_FAILED: "auth-failed",
549
557
  EDIT_MISMATCH: "edit-mismatch",
558
+ FILE_CHANGED: "file-changed",
559
+ FILE_TOO_LARGE: "file-too-large",
550
560
  FILE_MISSING: "file-missing",
551
561
  TIMEOUT: "timeout",
552
562
  UNCLASSIFIED: "unclassified"
@@ -570,7 +580,15 @@ function classifyToolError(call) {
570
580
  )) {
571
581
  return { id: ErrorClass.AUTH_FAILED, param: null };
572
582
  }
573
- if (/string to replace not found|found \d+ matches|file has been modified|has not been read yet/i.test(
583
+ if (/file has been modified since read/i.test(text)) {
584
+ return { id: ErrorClass.FILE_CHANGED, param: null };
585
+ }
586
+ if (/exceeds maximum allowed tokens|file is too large to read|file too large/i.test(
587
+ text
588
+ )) {
589
+ return { id: ErrorClass.FILE_TOO_LARGE, param: null };
590
+ }
591
+ if (/string to replace not found|found \d+ matches|has not been read yet/i.test(
574
592
  text
575
593
  ) || ["Edit", "MultiEdit"].includes(call.name) && /not found|unique/i.test(text)) {
576
594
  return { id: ErrorClass.EDIT_MISMATCH, param: null };
@@ -606,6 +624,11 @@ function summarizeToolErrors(calls) {
606
624
 
607
625
  // src/core/metrics.ts
608
626
  var IDLE_GAP_MINUTES = 10;
627
+ var TRIVIAL_SESSION_MAX_TYPED_PROMPTS = 1;
628
+ var TRIVIAL_SESSION_MIN_ACTIVE_MINUTES = 1;
629
+ var PARALLEL_WINDOW_MINUTES = 30;
630
+ var RESPONSE_TIME_MIN_SECONDS = 2;
631
+ var RESPONSE_TIME_MAX_SECONDS = 3600;
609
632
  var ZERO_TOKENS = {
610
633
  input: 0,
611
634
  output: 0,
@@ -674,6 +697,13 @@ var TURN_EDGES = [
674
697
  { label: "16-40", upTo: 40 },
675
698
  { label: ">40", upTo: Number.POSITIVE_INFINITY }
676
699
  ];
700
+ var RESPONSE_EDGES = [
701
+ { label: "<=10s", upTo: 10 },
702
+ { label: "10-30s", upTo: 30 },
703
+ { label: "30s-2m", upTo: 120 },
704
+ { label: "2-10m", upTo: 600 },
705
+ { label: "10m-1h", upTo: Number.POSITIVE_INFINITY }
706
+ ];
677
707
  function round(value, digits = 1) {
678
708
  const factor = 10 ** digits;
679
709
  return Math.round(value * factor) / factor;
@@ -738,6 +768,13 @@ function countBy(values) {
738
768
  {}
739
769
  );
740
770
  }
771
+ var AUTOMATED_ENTRYPOINT_PREFIX = "sdk-";
772
+ function isAutomatedSession(session) {
773
+ return session.entrypoint?.startsWith(AUTOMATED_ENTRYPOINT_PREFIX) === true;
774
+ }
775
+ function isTrivialSession(session) {
776
+ return session.turns.filter(isTypedTurn).length <= TRIVIAL_SESSION_MAX_TYPED_PROMPTS || computeActiveMinutes(session) < TRIVIAL_SESSION_MIN_ACTIVE_MINUTES;
777
+ }
741
778
  function computeAggregate(sessions) {
742
779
  const tools = toolStats(sessions);
743
780
  const toolCalls = tools.reduce((n, t) => n + t.calls, 0);
@@ -754,7 +791,8 @@ function computeAggregate(sessions) {
754
791
  ),
755
792
  {}
756
793
  );
757
- const durations = sessions.map(computeActiveMinutes);
794
+ const substantial = sessions.filter((s) => !isTrivialSession(s));
795
+ const durations = substantial.map(computeActiveMinutes);
758
796
  return {
759
797
  sessions: sessions.length,
760
798
  turns: turns.length,
@@ -795,7 +833,7 @@ function computeAggregate(sessions) {
795
833
  MINUTE_EDGES
796
834
  ),
797
835
  sessionTurns: distribution(
798
- sessions.map((s) => s.turns.length),
836
+ substantial.map((s) => s.turns.length),
799
837
  TURN_EDGES
800
838
  )
801
839
  };
@@ -836,6 +874,49 @@ function groupBy(items, keyOf) {
836
874
  }
837
875
  return groups;
838
876
  }
877
+ function gapsToPreviousOtherSession(sorted) {
878
+ let latest = null;
879
+ let latestOther = null;
880
+ return sorted.map((stamp) => {
881
+ const other = latest?.sessionId === stamp.sessionId ? latestOther : latest;
882
+ if (latest && latest.sessionId !== stamp.sessionId) {
883
+ latestOther = latest;
884
+ }
885
+ latest = stamp;
886
+ return other ? stamp.ms - other.ms : Number.POSITIVE_INFINITY;
887
+ });
888
+ }
889
+ function computeParallelSessions(sessions) {
890
+ const stamps = sessions.flatMap(
891
+ (s) => s.turns.filter(isTypedTurn).map((t) => ({ sessionId: s.id, ms: Date.parse(t.prompt.timestamp) }))
892
+ ).filter((stamp) => !Number.isNaN(stamp.ms)).sort((a, b) => a.ms - b.ms);
893
+ const windowMs = PARALLEL_WINDOW_MINUTES * 6e4;
894
+ const before = gapsToPreviousOtherSession(stamps);
895
+ const after = [
896
+ ...gapsToPreviousOtherSession(
897
+ stamps.map((s) => ({ ...s, ms: -s.ms })).reverse()
898
+ )
899
+ ].reverse();
900
+ const overlapping = stamps.filter(
901
+ (_, i) => (before[i] ?? Number.POSITIVE_INFINITY) <= windowMs || (after[i] ?? Number.POSITIVE_INFINITY) <= windowMs
902
+ );
903
+ return {
904
+ overlappingPrompts: overlapping.length,
905
+ sessionsInvolved: new Set(overlapping.map((s) => s.sessionId)).size,
906
+ share: stamps.length > 0 ? round(overlapping.length / stamps.length, 3) : 0
907
+ };
908
+ }
909
+ function computeResponseTime(sessions) {
910
+ const gaps = sessions.flatMap(
911
+ (s) => s.turns.slice(1).map((turn, i) => {
912
+ const previous = s.turns[i];
913
+ return previous && isTypedTurn(turn) ? (Date.parse(turn.prompt.timestamp) - Date.parse(previous.endedAt)) / 1e3 : Number.NaN;
914
+ })
915
+ ).filter(
916
+ (gap) => gap >= RESPONSE_TIME_MIN_SECONDS && gap <= RESPONSE_TIME_MAX_SECONDS
917
+ ).map((gap) => round(gap));
918
+ return { ...distribution(gaps, RESPONSE_EDGES), samples: gaps.length };
919
+ }
839
920
  function computeMetrics(sessions) {
840
921
  const typedTimes = sessions.flatMap((s) => s.turns.filter(isTypedTurn)).map((t) => new Date(t.prompt.timestamp));
841
922
  const byHour = Array.from(
@@ -853,7 +934,12 @@ function computeMetrics(sessions) {
853
934
  ),
854
935
  byDay: [...groupBy(sessions, (s) => isoToDateKey(s.startedAt)).entries()].map(([date, group]) => ({ date, ...computeAggregate(group) })).sort((a, b) => a.date.localeCompare(b.date)),
855
936
  sessions: sessions.map(computeSessionMetrics),
856
- activity: { byHour, byWeekday }
937
+ activity: {
938
+ byHour,
939
+ byWeekday,
940
+ parallelSessions: computeParallelSessions(sessions),
941
+ responseTime: computeResponseTime(sessions)
942
+ }
857
943
  };
858
944
  }
859
945
  function computeDailyPoints(sessions, episodes) {
@@ -1824,7 +1910,7 @@ async function writeFileAtomic(filePath, content) {
1824
1910
  await mkdir(dirname(filePath), { recursive: true });
1825
1911
  const tmpFile = `${filePath}.${String(process.pid)}.${randomUUID()}.tmp`;
1826
1912
  try {
1827
- await writeFile(tmpFile, content, "utf-8");
1913
+ await writeFile(tmpFile, content, { encoding: "utf-8", mode: 384 });
1828
1914
  await rename(tmpFile, filePath);
1829
1915
  } catch (error) {
1830
1916
  await unlink(tmpFile).catch(() => void 0);
@@ -1890,6 +1976,21 @@ async function saveDailyHistory(days, filePath = DAILY_HISTORY_FILE) {
1890
1976
  await writeFileAtomic(filePath, `${JSON.stringify(content)}
1891
1977
  `);
1892
1978
  }
1979
+ var NO_CLAUDE_MD_HEADINGS = {
1980
+ user: [],
1981
+ byProject: {}
1982
+ };
1983
+ var TOPIC_BY_KIND = {
1984
+ [InsightKind.TOOL_ERROR_LOOPS]: /\b(tools?|commands?|shell|bash|environment|setup|troubleshooting|workflow)\b/i,
1985
+ [InsightKind.TOOL_DENIALS]: /\b(permissions?|safety|security|hooks?|git|commands?|workflow)\b/i,
1986
+ [InsightKind.CORRECTIONS]: /\b(conventions?|style|preferences?|guidelines?|rules|workflow|instructions|behaviou?r)\b/i,
1987
+ [InsightKind.REPEATED_INSTRUCTION]: /\b(conventions?|style|preferences?|guidelines?|rules|workflow|instructions|behaviou?r)\b/i,
1988
+ [InsightKind.REWORK]: /\b(conventions?|style|guidelines?|rules|workflow|testing|code)\b/i
1989
+ };
1990
+ function pickSection(headings, kind) {
1991
+ const topic = TOPIC_BY_KIND[kind];
1992
+ return (topic && headings.find((heading) => topic.test(heading))) ?? null;
1993
+ }
1893
1994
  var NO_ALLOWED_RULES = { user: [], byProject: {} };
1894
1995
  function escapeRegExp(text) {
1895
1996
  return text.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
@@ -2121,6 +2222,23 @@ var ERROR_ADVICE = {
2121
2222
  title: "Edits fail to find their target text",
2122
2223
  rule: () => "- Re-read the file right before editing it, and give `old_string` enough surrounding context to be unique."
2123
2224
  },
2225
+ "file-changed": {
2226
+ title: "Files change between Claude reading and editing them",
2227
+ rule: null,
2228
+ workflow: {
2229
+ kind: "workflow",
2230
+ suggestion: "Find what rewrites files while Claude works: a formatter or linter hook, or a second session on the same project.",
2231
+ steps: [
2232
+ "Check hooks in `.claude/settings.json` and `~/.claude/settings.json` for formatters that run after Edit or Write.",
2233
+ "Run the formatter on save outside Claude, or make the hook run only at the end of a turn.",
2234
+ "Avoid two sessions editing the same project at once; use a git worktree for the second one."
2235
+ ]
2236
+ }
2237
+ },
2238
+ "file-too-large": {
2239
+ title: "Whole-file reads of files that are too large",
2240
+ rule: () => "- For large files, search with Grep first or read with `offset` and `limit` instead of reading the whole file."
2241
+ },
2124
2242
  "file-missing": {
2125
2243
  title: "Calls on files or paths that do not exist",
2126
2244
  rule: () => "- Confirm a path exists (`ls` or Glob) before reading, running or editing it instead of guessing names."
@@ -2152,7 +2270,8 @@ function toolErrorInsights({ episodes }) {
2152
2270
  const tools = distinct(
2153
2271
  group.flatMap((e) => Object.keys(e.context.tools))
2154
2272
  ).slice(0, 3);
2155
- const action = advice.rule ? {
2273
+ const known = advice.rule !== null || advice.workflow !== void 0;
2274
+ const action = advice.workflow ?? (advice.rule ? {
2156
2275
  kind: "claude-md-rule",
2157
2276
  scope: "project",
2158
2277
  project,
@@ -2166,13 +2285,13 @@ function toolErrorInsights({ episodes }) {
2166
2285
  'Ask: "What is the root cause of this error? Show the evidence before changing anything."',
2167
2286
  "If the cause is environmental (service down, missing tool), fix that first, then resume."
2168
2287
  ]
2169
- };
2288
+ });
2170
2289
  return buildInsight({
2171
2290
  id: `tool-errors:${project}:${classId}:${param}`.replace(/\s+/g, "_"),
2172
2291
  kind: InsightKind.TOOL_ERROR_LOOPS,
2173
2292
  title: `${advice.title} (${project})`,
2174
2293
  // Without a known cause the claim is weak, so it never ranks high.
2175
- severity: advice.rule ? severityByCount(errors, 8, 5) : Severity.LOW,
2294
+ severity: known ? severityByCount(errors, 8, 5) : Severity.LOW,
2176
2295
  finding: `${plural(errors, "failed tool call")} in ${plural(group.length, "streak")} across ${plural(sessions, "session")}${tools.length > 0 ? ` (${tools.join(", ")})` : ""}${firstError ? `; typical error: "${firstError}"` : ""}.`,
2177
2296
  evidence: evidenceOf(
2178
2297
  group,
@@ -2187,7 +2306,7 @@ function toolErrorInsights({ episodes }) {
2187
2306
  null
2188
2307
  ),
2189
2308
  action,
2190
- confidence: advice.rule ? averageConfidence(group) : Math.min(0.5, averageConfidence(group)),
2309
+ confidence: known ? averageConfidence(group) : Math.min(0.5, averageConfidence(group)),
2191
2310
  episodes: group
2192
2311
  });
2193
2312
  });
@@ -2320,6 +2439,14 @@ function denialInsights({ episodes }) {
2320
2439
  return [];
2321
2440
  });
2322
2441
  }
2442
+ function reworkSeverity(edits, turns, interleavedFailures) {
2443
+ const returned = turns >= 3;
2444
+ const broke = interleavedFailures >= 1;
2445
+ if (edits >= 10 && returned && broke) {
2446
+ return Severity.HIGH;
2447
+ }
2448
+ return edits >= 7 && (returned || broke) ? Severity.MEDIUM : Severity.LOW;
2449
+ }
2323
2450
  function reworkInsights({ episodes }) {
2324
2451
  return episodes.filter((e) => e.type === EpisodeType.REWORK).sort((a, b) => b.count - a.count).slice(0, 3).map((episode) => {
2325
2452
  const file = detailString(episode, "file") ?? "a file";
@@ -2335,7 +2462,7 @@ function reworkInsights({ episodes }) {
2335
2462
  ),
2336
2463
  kind: InsightKind.REWORK,
2337
2464
  title: `\`${file}\` was reworked repeatedly`,
2338
- severity: severityByCount(episode.count, 10, 7),
2465
+ severity: reworkSeverity(episode.count, turns, interleaved),
2339
2466
  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)"}.`,
2340
2467
  evidence: evidenceOf(
2341
2468
  [episode],
@@ -2644,7 +2771,17 @@ function modelSwitchInsight({ episodes }) {
2644
2771
  episodes: list
2645
2772
  });
2646
2773
  }
2774
+ function withSectionHint(insight, headings) {
2775
+ const { action } = insight;
2776
+ if (action.kind !== "claude-md-rule") {
2777
+ return insight;
2778
+ }
2779
+ const known = action.scope === "user" ? headings.user : headings.byProject[action.project ?? ""] ?? [];
2780
+ const section2 = pickSection(known, insight.kind);
2781
+ return section2 ? { ...insight, action: { ...action, section: section2 } } : insight;
2782
+ }
2647
2783
  function generateInsights(input) {
2784
+ const headings = input.claudeMdHeadings ?? NO_CLAUDE_MD_HEADINGS;
2648
2785
  return [
2649
2786
  interruptionInsight(input),
2650
2787
  correctionInsight(input),
@@ -2655,11 +2792,24 @@ function generateInsights(input) {
2655
2792
  ...repeatedInstructionInsights(input),
2656
2793
  readonlyCommandInsight(input),
2657
2794
  modelSwitchInsight(input)
2658
- ].filter((insight) => insight !== null).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
2795
+ ].filter((insight) => insight !== null).map((insight) => withSectionHint(insight, headings)).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
2659
2796
  }
2660
2797
 
2661
2798
  // src/core/insight-review.ts
2662
- function reviewInsight(insight, interpretation) {
2799
+ function needsVerdict(episode) {
2800
+ switch (episode.type) {
2801
+ case EpisodeType.CORRECTION:
2802
+ case EpisodeType.REPEATED_INSTRUCTION:
2803
+ case EpisodeType.REWORK:
2804
+ case EpisodeType.TOOL_ERROR_LOOP:
2805
+ return true;
2806
+ case EpisodeType.CONTEXT_PRESSURE:
2807
+ return episode.confidence < 0.8;
2808
+ default:
2809
+ return false;
2810
+ }
2811
+ }
2812
+ function reviewInsight(insight, interpretation, episodeList = []) {
2663
2813
  const ids = new Set(insight.episodeIds);
2664
2814
  const verdicts = (interpretation?.episodeVerdicts ?? []).filter(
2665
2815
  (v) => ids.has(v.episodeId)
@@ -2669,7 +2819,16 @@ function reviewInsight(insight, interpretation) {
2669
2819
  const rejected = count2("rejected");
2670
2820
  const unclear = count2("unclear");
2671
2821
  const episodes = ids.size;
2672
- const state = confirmed > 0 ? "confirmed" : episodes > 0 && rejected === episodes ? "dismissed" : "unverified";
2822
+ const byId = new Map(episodeList.map((e) => [e.id, e]));
2823
+ const isCountedFact = episodes > 0 && insight.episodeIds.every((id) => {
2824
+ const episode = byId.get(id);
2825
+ return episode !== void 0 && !needsVerdict(episode);
2826
+ });
2827
+ const state = confirmed > 0 ? "confirmed" : episodes > 0 && rejected === episodes ? "dismissed" : isCountedFact ? "not-needed" : "unverified";
2828
+ const causes = verdicts.reduce(
2829
+ (acc, v) => v.cause === void 0 ? acc : { ...acc, [v.cause]: (acc[v.cause] ?? 0) + 1 },
2830
+ {}
2831
+ );
2673
2832
  return {
2674
2833
  insightId: insight.id,
2675
2834
  state,
@@ -2677,11 +2836,14 @@ function reviewInsight(insight, interpretation) {
2677
2836
  reviewed: verdicts.length,
2678
2837
  confirmed,
2679
2838
  rejected,
2680
- unclear
2839
+ unclear,
2840
+ ...Object.keys(causes).length > 0 ? { causes } : {}
2681
2841
  };
2682
2842
  }
2683
- function reviewInsights(insights, interpretation) {
2684
- return insights.map((insight) => reviewInsight(insight, interpretation));
2843
+ function reviewInsights(insights, interpretation, episodes = []) {
2844
+ return insights.map(
2845
+ (insight) => reviewInsight(insight, interpretation, episodes)
2846
+ );
2685
2847
  }
2686
2848
 
2687
2849
  // src/core/report.ts
@@ -2721,15 +2883,18 @@ function sanitizeValue(value, key) {
2721
2883
  function sanitizeReport(report) {
2722
2884
  return sanitizeValue(report, null);
2723
2885
  }
2724
- function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, extraNotes) {
2725
- const enoughData = sessions.length >= MIN_SESSIONS_FOR_FINDINGS && typedPrompts >= MIN_PROMPTS_FOR_FINDINGS;
2886
+ function buildDataQuality(stats, sessions, interactive, typedPrompts, periodDays, episodes, extraNotes) {
2887
+ const interactivePrompts = interactive.flatMap((s) => s.turns).filter(isTypedTurn).length;
2888
+ const enoughData = interactive.length >= MIN_SESSIONS_FOR_FINDINGS && interactivePrompts >= MIN_PROMPTS_FOR_FINDINGS;
2889
+ const automatedSessions = sessions.length - interactive.length;
2726
2890
  const unknownCount = Object.values(stats.unknownRecordTypes).reduce(
2727
2891
  (a, b) => a + b,
2728
2892
  0
2729
2893
  );
2894
+ const trivialSessions = sessions.filter(isTrivialSession).length;
2730
2895
  const notes = [
2731
2896
  ...enoughData ? [] : [
2732
- `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.`
2897
+ `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.`
2733
2898
  ],
2734
2899
  ...unknownCount > 0 ? [
2735
2900
  `${plural(unknownCount, "record")} of unknown type ${unknownCount === 1 ? "was" : "were"} skipped (${Object.keys(stats.unknownRecordTypes).join(", ")}); the log format may have changed.`
@@ -2743,6 +2908,12 @@ function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, e
2743
2908
  ...stats.emptySessions > 0 ? [
2744
2909
  `${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.`
2745
2910
  ] : [],
2911
+ ...automatedSessions > 0 ? [
2912
+ `${plural(automatedSessions, "headless session")} (started by scripts or other tools) ${automatedSessions === 1 ? "is" : "are"} in the totals but left out of the friction findings.`
2913
+ ] : [],
2914
+ ...trivialSessions > 0 ? [
2915
+ `${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.`
2916
+ ] : [],
2746
2917
  ...extraNotes,
2747
2918
  ...episodes.some((e) => e.type === EpisodeType.CORRECTION) ? [
2748
2919
  "Corrections are detected heuristically from phrasing and are not confirmed without an interpretation step."
@@ -2762,17 +2933,21 @@ function buildDataQuality(stats, sessions, typedPrompts, periodDays, episodes, e
2762
2933
  enoughData,
2763
2934
  filesFailed: stats.filesFailed,
2764
2935
  emptySessionsSkipped: stats.emptySessions,
2936
+ trivialSessions,
2937
+ automatedSessions,
2765
2938
  notes
2766
2939
  };
2767
2940
  }
2768
2941
  function buildReport(options) {
2769
2942
  const { sessions, stats, from, to, project } = options;
2770
2943
  const metrics = computeMetrics(sessions);
2771
- const { episodes, promptTraits, notes } = detectFriction(sessions);
2944
+ const interactive = sessions.filter((s) => !isAutomatedSession(s));
2945
+ const { episodes, promptTraits, notes } = detectFriction(interactive);
2772
2946
  const insights = generateInsights({
2773
2947
  metrics,
2774
2948
  episodes,
2775
- ...options.allowedRules ? { allowedRules: options.allowedRules } : {}
2949
+ ...options.allowedRules ? { allowedRules: options.allowedRules } : {},
2950
+ ...options.claudeMdHeadings ? { claudeMdHeadings: options.claudeMdHeadings } : {}
2776
2951
  });
2777
2952
  const currentDaily = computeDailyPoints(sessions, episodes);
2778
2953
  const daily = project === null ? mergeDaily(options.history ?? [], currentDaily) : currentDaily;
@@ -2786,6 +2961,7 @@ function buildReport(options) {
2786
2961
  dataQuality: buildDataQuality(
2787
2962
  stats,
2788
2963
  sessions,
2964
+ interactive,
2789
2965
  metrics.overall.typedPrompts,
2790
2966
  periodDays,
2791
2967
  episodes,
@@ -2801,7 +2977,7 @@ function buildReport(options) {
2801
2977
  episodes,
2802
2978
  promptTraits,
2803
2979
  insights,
2804
- insightReviews: reviewInsights(insights, null),
2980
+ insightReviews: reviewInsights(insights, null, episodes),
2805
2981
  interpretation: null
2806
2982
  };
2807
2983
  return sanitizeReport(report);
@@ -3501,17 +3677,15 @@ function foldSession(acc) {
3501
3677
  messages: (previousModel?.messages ?? 0) + 1,
3502
3678
  tokens: addTokens(previousModel?.tokens ?? EMPTY_TOKENS, event.usage)
3503
3679
  });
3504
- const calls = event.toolUses.filter((use) => !seenCallIds.has(use.id)).map(
3505
- (use) => ({
3506
- id: use.id,
3507
- name: use.name,
3508
- timestamp: event.ts,
3509
- sidechain: event.sidechain,
3510
- target: use.target,
3511
- command: use.command,
3512
- result: resultsById.get(use.id) ?? null
3513
- })
3514
- );
3680
+ const calls = event.toolUses.filter((use) => !seenCallIds.has(use.id)).map((use) => ({
3681
+ id: use.id,
3682
+ name: use.name,
3683
+ timestamp: event.ts,
3684
+ sidechain: event.sidechain,
3685
+ target: use.target,
3686
+ command: use.command,
3687
+ result: resultsById.get(use.id) ?? null
3688
+ }));
3515
3689
  for (const call of calls) {
3516
3690
  seenCallIds.add(call.id);
3517
3691
  allCalls.push(call);
@@ -3714,19 +3888,6 @@ var OLLAMA_BUDGET = {
3714
3888
  textChars: 140
3715
3889
  };
3716
3890
  var MAX_RECOMMENDATIONS = 4;
3717
- function needsVerdict(episode) {
3718
- switch (episode.type) {
3719
- case EpisodeType.CORRECTION:
3720
- case EpisodeType.REPEATED_INSTRUCTION:
3721
- case EpisodeType.REWORK:
3722
- case EpisodeType.TOOL_ERROR_LOOP:
3723
- return true;
3724
- case EpisodeType.CONTEXT_PRESSURE:
3725
- return episode.confidence < 0.8;
3726
- default:
3727
- return false;
3728
- }
3729
- }
3730
3891
  var FACT_KEYS = [
3731
3892
  "previousTurnInterrupted",
3732
3893
  "errorClass",
@@ -3806,6 +3967,7 @@ var SYSTEM_PROMPT = `You are a careful analyst of a developer's Claude Code usag
3806
3967
  Rules:
3807
3968
  - Use only the evidence you are given. Never invent episodes, numbers, projects or quotes.
3808
3969
  - 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.
3970
+ - 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.
3809
3971
  - 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.
3810
3972
  - 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.
3811
3973
  - Reply with the requested JSON object only. Write in English.`;
@@ -3823,7 +3985,8 @@ var RESPONSE_SCHEMA = {
3823
3985
  type: "string",
3824
3986
  enum: ["confirmed", "rejected", "unclear"]
3825
3987
  },
3826
- reason: { type: "string" }
3988
+ reason: { type: "string" },
3989
+ cause: { type: "string", enum: Object.values(CorrectionCause) }
3827
3990
  },
3828
3991
  required: ["id", "verdict", "reason"]
3829
3992
  }
@@ -3906,6 +4069,14 @@ var VERDICTS = /* @__PURE__ */ new Set([
3906
4069
  "rejected",
3907
4070
  "unclear"
3908
4071
  ]);
4072
+ var CAUSES = new Set(Object.values(CorrectionCause));
4073
+ function asCause(value, verdict, episodeType) {
4074
+ if (typeof value !== "string" || verdict !== "confirmed" || episodeType !== EpisodeType.CORRECTION) {
4075
+ return null;
4076
+ }
4077
+ const normalized = value.trim().toLowerCase();
4078
+ return CAUSES.has(normalized) ? normalized : CorrectionCause.OTHER;
4079
+ }
3909
4080
  function validateAnswer(raw, evidence) {
3910
4081
  if (!isRecord2(raw)) {
3911
4082
  throw new EngineOutputError("the model did not return a JSON object");
@@ -3916,7 +4087,8 @@ function validateAnswer(raw, evidence) {
3916
4087
  "the model returned no usable summary (empty or placeholder text)"
3917
4088
  );
3918
4089
  }
3919
- const episodeIds = new Set(evidence.episodes.map((e) => e.id));
4090
+ const episodeTypes = new Map(evidence.episodes.map((e) => [e.id, e.type]));
4091
+ const episodeIds = new Set(episodeTypes.keys());
3920
4092
  const knownIds = /* @__PURE__ */ new Set([
3921
4093
  ...episodeIds,
3922
4094
  ...evidence.insights.map((i) => i.id)
@@ -3934,7 +4106,15 @@ function validateAnswer(raw, evidence) {
3934
4106
  return [];
3935
4107
  }
3936
4108
  seen.add(id);
3937
- return [{ episodeId: id, verdict, note }];
4109
+ const cause = asCause(item["cause"], verdict, episodeTypes.get(id));
4110
+ return [
4111
+ {
4112
+ episodeId: id,
4113
+ verdict,
4114
+ note,
4115
+ ...cause ? { cause } : {}
4116
+ }
4117
+ ];
3938
4118
  });
3939
4119
  const recommendations = (Array.isArray(raw["recommendations"]) ? raw["recommendations"] : []).flatMap((item) => {
3940
4120
  if (!isRecord2(item)) {
@@ -4210,7 +4390,8 @@ async function interpretReport(report, options) {
4210
4390
  ...sanitized,
4211
4391
  insightReviews: reviewInsights(
4212
4392
  sanitized.insights,
4213
- sanitized.interpretation
4393
+ sanitized.interpretation,
4394
+ sanitized.episodes
4214
4395
  )
4215
4396
  };
4216
4397
  } catch (error) {
@@ -4274,9 +4455,14 @@ pre{margin:.35rem 0 0;padding:10px 12px;background:var(--code-bg);border:1px sol
4274
4455
  .ba{display:grid;grid-template-columns:1fr;gap:6px}
4275
4456
  @media (min-width:640px){.ba{grid-template-columns:1fr 1fr}}
4276
4457
  .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)}
4277
- 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}
4278
- .js button.copy{display:inline-block}
4279
- button.copy:hover{border-color:var(--accent)}
4458
+ 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}
4459
+ .js button.copy,.js button.copyall{display:inline-block}
4460
+ button.copy:hover,button.copyall:hover:not(:disabled){border-color:var(--accent)}
4461
+ button.copyall:disabled{opacity:.55;cursor:default}
4462
+ .acts{display:inline-flex;align-items:center;gap:10px}
4463
+ .pick{display:none;align-items:center;gap:5px;font-weight:400;font-size:.8rem;color:var(--muted);cursor:pointer}
4464
+ .js .pick{display:inline-flex}
4465
+ .copyall{margin:0 0 .75rem}
4280
4466
  details{margin:.6rem 0 0}
4281
4467
  summary{cursor:pointer;color:var(--muted);font-size:.875rem}
4282
4468
  summary:hover{color:var(--text)}
@@ -4313,7 +4499,7 @@ footer{margin-top:3rem;padding-top:1rem;border-top:1px solid var(--border);color
4313
4499
  .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
4314
4500
  @media print{
4315
4501
  body{font-size:11pt}
4316
- button.copy,.js button.copy{display:none}
4502
+ button.copy,.js button.copy,button.copyall,.js button.copyall,.pick,.js .pick{display:none}
4317
4503
  .card,figure.chart{break-inside:avoid}
4318
4504
  h2{break-after:avoid}
4319
4505
  }
@@ -4339,20 +4525,44 @@ var JS = `
4339
4525
  }
4340
4526
  return Promise.resolve(fallbackCopy(text));
4341
4527
  }
4528
+ function flash(button,ok,restore){
4529
+ var original=button.getAttribute('data-label')||button.textContent;
4530
+ button.setAttribute('data-label',original);
4531
+ button.textContent=ok?'Copied':'Copy failed';
4532
+ if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
4533
+ setTimeout(function(){button.textContent=original;button.removeAttribute('data-label');if(restore)restore();if(live)live.textContent='';},1800);
4534
+ }
4535
+ var all=document.getElementById('copy-checked');
4536
+ function picked(){
4537
+ return Array.prototype.filter.call(document.querySelectorAll('input[data-pick]'),function(input){return input.checked;});
4538
+ }
4539
+ function syncAll(){
4540
+ if(!all)return;
4541
+ var n=picked().length;
4542
+ all.disabled=n===0;
4543
+ all.textContent='Copy checked ('+n+')';
4544
+ }
4545
+ document.addEventListener('change',function(event){
4546
+ var target=event.target;
4547
+ if(target&&target.matches&&target.matches('input[data-pick]'))syncAll();
4548
+ });
4342
4549
  document.addEventListener('click',function(event){
4343
4550
  var target=event.target;
4344
4551
  if(!(target instanceof Element))return;
4552
+ if(all&&target.closest('#copy-checked')){
4553
+ var texts=picked().map(function(input){
4554
+ var source=document.getElementById(input.getAttribute('data-pick')||'');
4555
+ return source?(source.textContent||''):'';
4556
+ }).filter(function(text){return text!=='';});
4557
+ if(texts.length===0)return;
4558
+ copyText(texts.join('\\n\\n')).then(function(ok){flash(all,ok,syncAll);});
4559
+ return;
4560
+ }
4345
4561
  var button=target.closest('button.copy');
4346
4562
  if(!button)return;
4347
4563
  var source=document.getElementById(button.getAttribute('data-copy-target')||'');
4348
4564
  if(!source)return;
4349
- copyText(source.textContent||'').then(function(ok){
4350
- var original=button.getAttribute('data-label')||button.textContent;
4351
- button.setAttribute('data-label',original);
4352
- button.textContent=ok?'Copied':'Copy failed';
4353
- if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
4354
- setTimeout(function(){button.textContent=original;if(live)live.textContent='';},1800);
4355
- });
4565
+ copyText(source.textContent||'').then(function(ok){flash(button,ok,null);});
4356
4566
  });
4357
4567
  window.addEventListener('beforeprint',function(){
4358
4568
  document.querySelectorAll('details').forEach(function(d){d.setAttribute('data-was-open',d.open?'1':'0');d.open=true;});
@@ -4543,12 +4753,16 @@ var ORDER = {
4543
4753
  rejected: 1,
4544
4754
  unclear: 2
4545
4755
  };
4546
- function judgeInsight(insight, interpretation) {
4756
+ function judgeInsight(insight, interpretation, episodes = []) {
4547
4757
  const ids = new Set(insight.episodeIds);
4548
4758
  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]);
4549
- const review = reviewInsight(insight, interpretation);
4759
+ const review = reviewInsight(insight, interpretation, episodes);
4550
4760
  return { insight, state: review.state, review, notes };
4551
4761
  }
4762
+ function describeCauses(review) {
4763
+ const parts = Object.entries(review.causes ?? {}).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([cause, n]) => `${String(n)} ${cause.replace(/-/g, " ")}`);
4764
+ return parts.length > 0 ? parts.join(", ") : null;
4765
+ }
4552
4766
  function describeCoverage(review) {
4553
4767
  if (review.reviewed === 0) {
4554
4768
  return null;
@@ -4559,11 +4773,12 @@ function describeCoverage(review) {
4559
4773
  review.unclear > 0 ? `${String(review.unclear)} unclear` : null
4560
4774
  ].filter((part) => part !== null);
4561
4775
  const unreviewed = review.episodes - review.reviewed;
4562
- return `LLM reviewed ${String(review.reviewed)} of ${String(review.episodes)} ${review.episodes === 1 ? "episode" : "episodes"}: ${parts.join(", ")}` + (unreviewed > 0 ? `; ${String(unreviewed)} not reviewed` : "");
4776
+ const causes = describeCauses(review);
4777
+ 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}` : "");
4563
4778
  }
4564
4779
  function judgeInsights(report) {
4565
4780
  const judged = report.insights.map(
4566
- (insight) => judgeInsight(insight, report.interpretation)
4781
+ (insight) => judgeInsight(insight, report.interpretation, report.episodes)
4567
4782
  );
4568
4783
  return {
4569
4784
  kept: judged.filter((j) => j.state !== "dismissed"),
@@ -4605,7 +4820,7 @@ function describeAction(action) {
4605
4820
  switch (action.kind) {
4606
4821
  case "claude-md-rule":
4607
4822
  return {
4608
- label: action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`,
4823
+ label: `${action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`}${action.section ? ` under "${action.section}"` : ""}`,
4609
4824
  lines: [],
4610
4825
  verbatim: action.text.split("\n")
4611
4826
  };
@@ -4673,10 +4888,13 @@ function section(id, heading, body) {
4673
4888
  ${body}
4674
4889
  </section>`;
4675
4890
  }
4891
+ function pick(id, copyLabel) {
4892
+ return `<label class="pick"><input type="checkbox" data-pick="${id}" aria-label="${esc(`Include in copy checked: ${copyLabel}`)}"><span>Select</span></label>`;
4893
+ }
4676
4894
  function copyBlock(ids, label, text, copyLabel) {
4677
4895
  const id = ids();
4678
4896
  return `<div class="action">
4679
- <div class="label"><span>${esc(label)}</span><button type="button" class="copy" data-copy-target="${id}" aria-label="${esc(`Copy: ${copyLabel}`)}">Copy</button></div>
4897
+ <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>
4680
4898
  <pre id="${id}">${esc(text)}</pre>
4681
4899
  </div>`;
4682
4900
  }
@@ -4685,7 +4903,7 @@ function renderAction(action, ids) {
4685
4903
  case "claude-md-rule":
4686
4904
  return copyBlock(
4687
4905
  ids,
4688
- action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`,
4906
+ `${action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`}${action.section ? ` under "${action.section}"` : ""}`,
4689
4907
  action.text,
4690
4908
  "CLAUDE.md rule"
4691
4909
  );
@@ -4708,7 +4926,7 @@ function renderAction(action, ids) {
4708
4926
  const afterId = ids();
4709
4927
  const pair = action.before !== null || action.after !== null ? `<div class="ba">
4710
4928
  ${action.before !== null ? `<div><div class="tag">Before</div><pre id="${beforeId}">${esc(action.before)}</pre></div>` : ""}
4711
- ${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>` : ""}
4929
+ ${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>` : ""}
4712
4930
  </div>` : "";
4713
4931
  return `<div class="action"><div class="label"><span>Prompt habit: ${esc(action.habit)}</span></div>${pair}</div>`;
4714
4932
  }
@@ -4719,7 +4937,7 @@ ${action.after !== null ? `<div><div class="tag">After <button type="button" cla
4719
4937
  ...action.steps.map((step, i) => `${String(i + 1)}. ${step}`)
4720
4938
  ].join("\n");
4721
4939
  return `<div class="action">
4722
- <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>
4940
+ <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>
4723
4941
  ${action.steps.length > 0 ? `<ol class="steps">${action.steps.map((step) => `<li>${esc(step)}</li>`).join("")}</ol>` : ""}
4724
4942
  <pre id="${id}" class="sr-only">${esc(text)}</pre>
4725
4943
  </div>`;
@@ -4804,10 +5022,11 @@ function renderInsights(report, ids) {
4804
5022
  const dismissedHtml = dismissed.length > 0 ? `<details><summary>Dismissed by the interpretation (${esc(dismissed.length)})</summary><ul>${dismissed.map(
4805
5023
  ({ insight, notes }) => `<li>${esc(insight.title)}${notes[0] ? ` <span class="muted small">- ${esc(notes[0].note)}</span>` : ""}</li>`
4806
5024
  ).join("")}</ul></details>` : "";
5025
+ const copyAll = body.includes("data-pick=") ? '<div class="copyall"><button type="button" id="copy-checked" class="copyall" disabled>Copy checked (0)</button></div>' : "";
4807
5026
  return section(
4808
5027
  "insights",
4809
5028
  `What to change${kept.length > 0 ? ` (${String(kept.length)})` : ""}`,
4810
- `${renderInterpretationSummary(report)}${body}${dismissedHtml}`
5029
+ `${renderInterpretationSummary(report)}${copyAll}${body}${dismissedHtml}`
4811
5030
  );
4812
5031
  }
4813
5032
  var count = (value) => formatNumber(value);
@@ -4955,8 +5174,12 @@ function renderModels(report) {
4955
5174
  (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>`
4956
5175
  ).join("")}</tbody></table></div>`;
4957
5176
  }
5177
+ function formatSeconds(seconds) {
5178
+ return seconds < 90 ? `${String(Math.round(seconds))} s` : formatMinutes(seconds / 60);
5179
+ }
4958
5180
  function renderHabits(report) {
4959
5181
  const { overall, activity } = report.metrics;
5182
+ const { parallelSessions, responseTime } = activity;
4960
5183
  if (overall.typedPrompts < MIN_PROMPTS_FOR_HABIT_CHARTS) {
4961
5184
  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>`;
4962
5185
  }
@@ -4997,9 +5220,25 @@ function renderHabits(report) {
4997
5220
  ),
4998
5221
  labels: overall.sessionMinutes.buckets.map((b) => b.label),
4999
5222
  values: overall.sessionMinutes.buckets.map((b) => b.count)
5000
- })
5223
+ }),
5224
+ ...responseTime.samples > 0 ? [
5225
+ renderCategoryChart({
5226
+ chart: describeChart(
5227
+ responseTime.buckets.map((b) => b.label),
5228
+ "response-time",
5229
+ "Time before your next prompt",
5230
+ "prompts",
5231
+ responseTime.buckets.map((b) => b.count),
5232
+ count
5233
+ ),
5234
+ labels: responseTime.buckets.map((b) => b.label),
5235
+ values: responseTime.buckets.map((b) => b.count)
5236
+ })
5237
+ ] : []
5001
5238
  ];
5002
- return `<div class="charts">${charts.join("")}</div>`;
5239
+ 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>` : "";
5240
+ 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>` : "";
5241
+ return `<div class="charts">${charts.join("")}</div>${parallelNote}${responseNote}`;
5003
5242
  }
5004
5243
  function renderMetrics(report) {
5005
5244
  const { overall, byProject } = report.metrics;
@@ -5029,7 +5268,7 @@ function renderEpisode(report, episode) {
5029
5268
  const verdict = report.interpretation?.episodeVerdicts.find(
5030
5269
  (v) => v.episodeId === episode.id
5031
5270
  );
5032
- 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>`;
5271
+ 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>`;
5033
5272
  }
5034
5273
  function renderEpisodes(report) {
5035
5274
  if (report.episodes.length === 0) {
@@ -5145,7 +5384,7 @@ function renderInterpretation(report) {
5145
5384
  "### Episode verdicts",
5146
5385
  "",
5147
5386
  ...interpretation.episodeVerdicts.map(
5148
- (v) => `- \`${v.episodeId}\`: **${v.verdict}** - ${v.note}`
5387
+ (v) => `- \`${v.episodeId}\`: **${v.verdict}**${v.cause ? ` (${v.cause})` : ""} - ${v.note}`
5149
5388
  ),
5150
5389
  ""
5151
5390
  ] : []
@@ -5389,4 +5628,4 @@ function renderInsight2(judged, position, c, severityColor) {
5389
5628
  return out;
5390
5629
  }
5391
5630
 
5392
- export { DenialKind, EpisodeType, InsightKind, InterpretationEngine, OutputFormat, PromptSource, REPORT_SCHEMA_VERSION, Severity, TurnKind, buildReport, computeMetrics, detectFriction, generateInsights, interpretReport, loadDailyHistory, mergeDaily, readSessions, renderHtml, renderMarkdown, renderTerminal, sanitize, sanitizeReport, saveDailyHistory };
5631
+ export { CorrectionCause, DenialKind, EpisodeType, InsightKind, InterpretationEngine, OutputFormat, PromptSource, REPORT_SCHEMA_VERSION, Severity, TurnKind, buildReport, computeMetrics, detectFriction, generateInsights, interpretReport, loadDailyHistory, mergeDaily, readSessions, renderHtml, renderMarkdown, renderTerminal, sanitize, sanitizeReport, saveDailyHistory };