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 +344 -69
- package/dist/index.d.ts +55 -3
- package/dist/index.js +306 -65
- package/package.json +1 -1
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 (/
|
|
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
|
|
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
|
-
|
|
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: {
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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);
|
|
@@ -3714,19 +3890,6 @@ var OLLAMA_BUDGET = {
|
|
|
3714
3890
|
textChars: 140
|
|
3715
3891
|
};
|
|
3716
3892
|
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
3893
|
var FACT_KEYS = [
|
|
3731
3894
|
"previousTurnInterrupted",
|
|
3732
3895
|
"errorClass",
|
|
@@ -3806,6 +3969,7 @@ var SYSTEM_PROMPT = `You are a careful analyst of a developer's Claude Code usag
|
|
|
3806
3969
|
Rules:
|
|
3807
3970
|
- Use only the evidence you are given. Never invent episodes, numbers, projects or quotes.
|
|
3808
3971
|
- 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.
|
|
3972
|
+
- 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
3973
|
- 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
3974
|
- 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
3975
|
- Reply with the requested JSON object only. Write in English.`;
|
|
@@ -3823,7 +3987,8 @@ var RESPONSE_SCHEMA = {
|
|
|
3823
3987
|
type: "string",
|
|
3824
3988
|
enum: ["confirmed", "rejected", "unclear"]
|
|
3825
3989
|
},
|
|
3826
|
-
reason: { type: "string" }
|
|
3990
|
+
reason: { type: "string" },
|
|
3991
|
+
cause: { type: "string", enum: Object.values(CorrectionCause) }
|
|
3827
3992
|
},
|
|
3828
3993
|
required: ["id", "verdict", "reason"]
|
|
3829
3994
|
}
|
|
@@ -3906,6 +4071,14 @@ var VERDICTS = /* @__PURE__ */ new Set([
|
|
|
3906
4071
|
"rejected",
|
|
3907
4072
|
"unclear"
|
|
3908
4073
|
]);
|
|
4074
|
+
var CAUSES = new Set(Object.values(CorrectionCause));
|
|
4075
|
+
function asCause(value, verdict, episodeType) {
|
|
4076
|
+
if (typeof value !== "string" || verdict !== "confirmed" || episodeType !== EpisodeType.CORRECTION) {
|
|
4077
|
+
return null;
|
|
4078
|
+
}
|
|
4079
|
+
const normalized = value.trim().toLowerCase();
|
|
4080
|
+
return CAUSES.has(normalized) ? normalized : CorrectionCause.OTHER;
|
|
4081
|
+
}
|
|
3909
4082
|
function validateAnswer(raw, evidence) {
|
|
3910
4083
|
if (!isRecord2(raw)) {
|
|
3911
4084
|
throw new EngineOutputError("the model did not return a JSON object");
|
|
@@ -3916,7 +4089,8 @@ function validateAnswer(raw, evidence) {
|
|
|
3916
4089
|
"the model returned no usable summary (empty or placeholder text)"
|
|
3917
4090
|
);
|
|
3918
4091
|
}
|
|
3919
|
-
const
|
|
4092
|
+
const episodeTypes = new Map(evidence.episodes.map((e) => [e.id, e.type]));
|
|
4093
|
+
const episodeIds = new Set(episodeTypes.keys());
|
|
3920
4094
|
const knownIds = /* @__PURE__ */ new Set([
|
|
3921
4095
|
...episodeIds,
|
|
3922
4096
|
...evidence.insights.map((i) => i.id)
|
|
@@ -3934,7 +4108,15 @@ function validateAnswer(raw, evidence) {
|
|
|
3934
4108
|
return [];
|
|
3935
4109
|
}
|
|
3936
4110
|
seen.add(id);
|
|
3937
|
-
|
|
4111
|
+
const cause = asCause(item["cause"], verdict, episodeTypes.get(id));
|
|
4112
|
+
return [
|
|
4113
|
+
{
|
|
4114
|
+
episodeId: id,
|
|
4115
|
+
verdict,
|
|
4116
|
+
note,
|
|
4117
|
+
...cause ? { cause } : {}
|
|
4118
|
+
}
|
|
4119
|
+
];
|
|
3938
4120
|
});
|
|
3939
4121
|
const recommendations = (Array.isArray(raw["recommendations"]) ? raw["recommendations"] : []).flatMap((item) => {
|
|
3940
4122
|
if (!isRecord2(item)) {
|
|
@@ -4210,7 +4392,8 @@ async function interpretReport(report, options) {
|
|
|
4210
4392
|
...sanitized,
|
|
4211
4393
|
insightReviews: reviewInsights(
|
|
4212
4394
|
sanitized.insights,
|
|
4213
|
-
sanitized.interpretation
|
|
4395
|
+
sanitized.interpretation,
|
|
4396
|
+
sanitized.episodes
|
|
4214
4397
|
)
|
|
4215
4398
|
};
|
|
4216
4399
|
} catch (error) {
|
|
@@ -4274,9 +4457,14 @@ pre{margin:.35rem 0 0;padding:10px 12px;background:var(--code-bg);border:1px sol
|
|
|
4274
4457
|
.ba{display:grid;grid-template-columns:1fr;gap:6px}
|
|
4275
4458
|
@media (min-width:640px){.ba{grid-template-columns:1fr 1fr}}
|
|
4276
4459
|
.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)}
|
|
4460
|
+
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}
|
|
4461
|
+
.js button.copy,.js button.copyall{display:inline-block}
|
|
4462
|
+
button.copy:hover,button.copyall:hover:not(:disabled){border-color:var(--accent)}
|
|
4463
|
+
button.copyall:disabled{opacity:.55;cursor:default}
|
|
4464
|
+
.acts{display:inline-flex;align-items:center;gap:10px}
|
|
4465
|
+
.pick{display:none;align-items:center;gap:5px;font-weight:400;font-size:.8rem;color:var(--muted);cursor:pointer}
|
|
4466
|
+
.js .pick{display:inline-flex}
|
|
4467
|
+
.copyall{margin:0 0 .75rem}
|
|
4280
4468
|
details{margin:.6rem 0 0}
|
|
4281
4469
|
summary{cursor:pointer;color:var(--muted);font-size:.875rem}
|
|
4282
4470
|
summary:hover{color:var(--text)}
|
|
@@ -4313,7 +4501,7 @@ footer{margin-top:3rem;padding-top:1rem;border-top:1px solid var(--border);color
|
|
|
4313
4501
|
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
4314
4502
|
@media print{
|
|
4315
4503
|
body{font-size:11pt}
|
|
4316
|
-
button.copy,.js button.copy{display:none}
|
|
4504
|
+
button.copy,.js button.copy,button.copyall,.js button.copyall,.pick,.js .pick{display:none}
|
|
4317
4505
|
.card,figure.chart{break-inside:avoid}
|
|
4318
4506
|
h2{break-after:avoid}
|
|
4319
4507
|
}
|
|
@@ -4339,20 +4527,44 @@ var JS = `
|
|
|
4339
4527
|
}
|
|
4340
4528
|
return Promise.resolve(fallbackCopy(text));
|
|
4341
4529
|
}
|
|
4530
|
+
function flash(button,ok,restore){
|
|
4531
|
+
var original=button.getAttribute('data-label')||button.textContent;
|
|
4532
|
+
button.setAttribute('data-label',original);
|
|
4533
|
+
button.textContent=ok?'Copied':'Copy failed';
|
|
4534
|
+
if(live)live.textContent=ok?'Copied to clipboard':'Copy failed';
|
|
4535
|
+
setTimeout(function(){button.textContent=original;button.removeAttribute('data-label');if(restore)restore();if(live)live.textContent='';},1800);
|
|
4536
|
+
}
|
|
4537
|
+
var all=document.getElementById('copy-checked');
|
|
4538
|
+
function picked(){
|
|
4539
|
+
return Array.prototype.filter.call(document.querySelectorAll('input[data-pick]'),function(input){return input.checked;});
|
|
4540
|
+
}
|
|
4541
|
+
function syncAll(){
|
|
4542
|
+
if(!all)return;
|
|
4543
|
+
var n=picked().length;
|
|
4544
|
+
all.disabled=n===0;
|
|
4545
|
+
all.textContent='Copy checked ('+n+')';
|
|
4546
|
+
}
|
|
4547
|
+
document.addEventListener('change',function(event){
|
|
4548
|
+
var target=event.target;
|
|
4549
|
+
if(target&&target.matches&&target.matches('input[data-pick]'))syncAll();
|
|
4550
|
+
});
|
|
4342
4551
|
document.addEventListener('click',function(event){
|
|
4343
4552
|
var target=event.target;
|
|
4344
4553
|
if(!(target instanceof Element))return;
|
|
4554
|
+
if(all&&target.closest('#copy-checked')){
|
|
4555
|
+
var texts=picked().map(function(input){
|
|
4556
|
+
var source=document.getElementById(input.getAttribute('data-pick')||'');
|
|
4557
|
+
return source?(source.textContent||''):'';
|
|
4558
|
+
}).filter(function(text){return text!=='';});
|
|
4559
|
+
if(texts.length===0)return;
|
|
4560
|
+
copyText(texts.join('\\n\\n')).then(function(ok){flash(all,ok,syncAll);});
|
|
4561
|
+
return;
|
|
4562
|
+
}
|
|
4345
4563
|
var button=target.closest('button.copy');
|
|
4346
4564
|
if(!button)return;
|
|
4347
4565
|
var source=document.getElementById(button.getAttribute('data-copy-target')||'');
|
|
4348
4566
|
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
|
-
});
|
|
4567
|
+
copyText(source.textContent||'').then(function(ok){flash(button,ok,null);});
|
|
4356
4568
|
});
|
|
4357
4569
|
window.addEventListener('beforeprint',function(){
|
|
4358
4570
|
document.querySelectorAll('details').forEach(function(d){d.setAttribute('data-was-open',d.open?'1':'0');d.open=true;});
|
|
@@ -4543,12 +4755,16 @@ var ORDER = {
|
|
|
4543
4755
|
rejected: 1,
|
|
4544
4756
|
unclear: 2
|
|
4545
4757
|
};
|
|
4546
|
-
function judgeInsight(insight, interpretation) {
|
|
4758
|
+
function judgeInsight(insight, interpretation, episodes = []) {
|
|
4547
4759
|
const ids = new Set(insight.episodeIds);
|
|
4548
4760
|
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);
|
|
4761
|
+
const review = reviewInsight(insight, interpretation, episodes);
|
|
4550
4762
|
return { insight, state: review.state, review, notes };
|
|
4551
4763
|
}
|
|
4764
|
+
function describeCauses(review) {
|
|
4765
|
+
const parts = Object.entries(review.causes ?? {}).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([cause, n]) => `${String(n)} ${cause.replace(/-/g, " ")}`);
|
|
4766
|
+
return parts.length > 0 ? parts.join(", ") : null;
|
|
4767
|
+
}
|
|
4552
4768
|
function describeCoverage(review) {
|
|
4553
4769
|
if (review.reviewed === 0) {
|
|
4554
4770
|
return null;
|
|
@@ -4559,11 +4775,12 @@ function describeCoverage(review) {
|
|
|
4559
4775
|
review.unclear > 0 ? `${String(review.unclear)} unclear` : null
|
|
4560
4776
|
].filter((part) => part !== null);
|
|
4561
4777
|
const unreviewed = review.episodes - review.reviewed;
|
|
4562
|
-
|
|
4778
|
+
const causes = describeCauses(review);
|
|
4779
|
+
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
4780
|
}
|
|
4564
4781
|
function judgeInsights(report) {
|
|
4565
4782
|
const judged = report.insights.map(
|
|
4566
|
-
(insight) => judgeInsight(insight, report.interpretation)
|
|
4783
|
+
(insight) => judgeInsight(insight, report.interpretation, report.episodes)
|
|
4567
4784
|
);
|
|
4568
4785
|
return {
|
|
4569
4786
|
kept: judged.filter((j) => j.state !== "dismissed"),
|
|
@@ -4605,7 +4822,7 @@ function describeAction(action) {
|
|
|
4605
4822
|
switch (action.kind) {
|
|
4606
4823
|
case "claude-md-rule":
|
|
4607
4824
|
return {
|
|
4608
|
-
label: action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`,
|
|
4825
|
+
label: `${action.scope === "project" ? `Add to CLAUDE.md in project "${action.project ?? "?"}"` : `Add to ${action.file}`}${action.section ? ` under "${action.section}"` : ""}`,
|
|
4609
4826
|
lines: [],
|
|
4610
4827
|
verbatim: action.text.split("\n")
|
|
4611
4828
|
};
|
|
@@ -4673,10 +4890,13 @@ function section(id, heading, body) {
|
|
|
4673
4890
|
${body}
|
|
4674
4891
|
</section>`;
|
|
4675
4892
|
}
|
|
4893
|
+
function pick(id, copyLabel) {
|
|
4894
|
+
return `<label class="pick"><input type="checkbox" data-pick="${id}" aria-label="${esc(`Include in copy checked: ${copyLabel}`)}"><span>Select</span></label>`;
|
|
4895
|
+
}
|
|
4676
4896
|
function copyBlock(ids, label, text, copyLabel) {
|
|
4677
4897
|
const id = ids();
|
|
4678
4898
|
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>
|
|
4899
|
+
<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
4900
|
<pre id="${id}">${esc(text)}</pre>
|
|
4681
4901
|
</div>`;
|
|
4682
4902
|
}
|
|
@@ -4685,7 +4905,7 @@ function renderAction(action, ids) {
|
|
|
4685
4905
|
case "claude-md-rule":
|
|
4686
4906
|
return copyBlock(
|
|
4687
4907
|
ids,
|
|
4688
|
-
action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`,
|
|
4908
|
+
`${action.scope === "project" ? `Add to ${action.file} in project "${action.project ?? "?"}"` : `Add to ${action.file} (all projects)`}${action.section ? ` under "${action.section}"` : ""}`,
|
|
4689
4909
|
action.text,
|
|
4690
4910
|
"CLAUDE.md rule"
|
|
4691
4911
|
);
|
|
@@ -4708,7 +4928,7 @@ function renderAction(action, ids) {
|
|
|
4708
4928
|
const afterId = ids();
|
|
4709
4929
|
const pair = action.before !== null || action.after !== null ? `<div class="ba">
|
|
4710
4930
|
${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>` : ""}
|
|
4931
|
+
${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
4932
|
</div>` : "";
|
|
4713
4933
|
return `<div class="action"><div class="label"><span>Prompt habit: ${esc(action.habit)}</span></div>${pair}</div>`;
|
|
4714
4934
|
}
|
|
@@ -4719,7 +4939,7 @@ ${action.after !== null ? `<div><div class="tag">After <button type="button" cla
|
|
|
4719
4939
|
...action.steps.map((step, i) => `${String(i + 1)}. ${step}`)
|
|
4720
4940
|
].join("\n");
|
|
4721
4941
|
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>
|
|
4942
|
+
<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
4943
|
${action.steps.length > 0 ? `<ol class="steps">${action.steps.map((step) => `<li>${esc(step)}</li>`).join("")}</ol>` : ""}
|
|
4724
4944
|
<pre id="${id}" class="sr-only">${esc(text)}</pre>
|
|
4725
4945
|
</div>`;
|
|
@@ -4804,10 +5024,11 @@ function renderInsights(report, ids) {
|
|
|
4804
5024
|
const dismissedHtml = dismissed.length > 0 ? `<details><summary>Dismissed by the interpretation (${esc(dismissed.length)})</summary><ul>${dismissed.map(
|
|
4805
5025
|
({ insight, notes }) => `<li>${esc(insight.title)}${notes[0] ? ` <span class="muted small">- ${esc(notes[0].note)}</span>` : ""}</li>`
|
|
4806
5026
|
).join("")}</ul></details>` : "";
|
|
5027
|
+
const copyAll = body.includes("data-pick=") ? '<div class="copyall"><button type="button" id="copy-checked" class="copyall" disabled>Copy checked (0)</button></div>' : "";
|
|
4807
5028
|
return section(
|
|
4808
5029
|
"insights",
|
|
4809
5030
|
`What to change${kept.length > 0 ? ` (${String(kept.length)})` : ""}`,
|
|
4810
|
-
`${renderInterpretationSummary(report)}${body}${dismissedHtml}`
|
|
5031
|
+
`${renderInterpretationSummary(report)}${copyAll}${body}${dismissedHtml}`
|
|
4811
5032
|
);
|
|
4812
5033
|
}
|
|
4813
5034
|
var count = (value) => formatNumber(value);
|
|
@@ -4955,8 +5176,12 @@ function renderModels(report) {
|
|
|
4955
5176
|
(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
5177
|
).join("")}</tbody></table></div>`;
|
|
4957
5178
|
}
|
|
5179
|
+
function formatSeconds(seconds) {
|
|
5180
|
+
return seconds < 90 ? `${String(Math.round(seconds))} s` : formatMinutes(seconds / 60);
|
|
5181
|
+
}
|
|
4958
5182
|
function renderHabits(report) {
|
|
4959
5183
|
const { overall, activity } = report.metrics;
|
|
5184
|
+
const { parallelSessions, responseTime } = activity;
|
|
4960
5185
|
if (overall.typedPrompts < MIN_PROMPTS_FOR_HABIT_CHARTS) {
|
|
4961
5186
|
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
5187
|
}
|
|
@@ -4997,9 +5222,25 @@ function renderHabits(report) {
|
|
|
4997
5222
|
),
|
|
4998
5223
|
labels: overall.sessionMinutes.buckets.map((b) => b.label),
|
|
4999
5224
|
values: overall.sessionMinutes.buckets.map((b) => b.count)
|
|
5000
|
-
})
|
|
5225
|
+
}),
|
|
5226
|
+
...responseTime.samples > 0 ? [
|
|
5227
|
+
renderCategoryChart({
|
|
5228
|
+
chart: describeChart(
|
|
5229
|
+
responseTime.buckets.map((b) => b.label),
|
|
5230
|
+
"response-time",
|
|
5231
|
+
"Time before your next prompt",
|
|
5232
|
+
"prompts",
|
|
5233
|
+
responseTime.buckets.map((b) => b.count),
|
|
5234
|
+
count
|
|
5235
|
+
),
|
|
5236
|
+
labels: responseTime.buckets.map((b) => b.label),
|
|
5237
|
+
values: responseTime.buckets.map((b) => b.count)
|
|
5238
|
+
})
|
|
5239
|
+
] : []
|
|
5001
5240
|
];
|
|
5002
|
-
|
|
5241
|
+
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>` : "";
|
|
5242
|
+
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>` : "";
|
|
5243
|
+
return `<div class="charts">${charts.join("")}</div>${parallelNote}${responseNote}`;
|
|
5003
5244
|
}
|
|
5004
5245
|
function renderMetrics(report) {
|
|
5005
5246
|
const { overall, byProject } = report.metrics;
|
|
@@ -5029,7 +5270,7 @@ function renderEpisode(report, episode) {
|
|
|
5029
5270
|
const verdict = report.interpretation?.episodeVerdicts.find(
|
|
5030
5271
|
(v) => v.episodeId === episode.id
|
|
5031
5272
|
);
|
|
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 ? ` - “${esc(episode.prompt)}”` : ""}${verdict?.note ? ` - ${esc(verdict.note)}` : ""}</div></div>`;
|
|
5273
|
+
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 ? ` - “${esc(episode.prompt)}”` : ""}${verdict?.note ? ` - ${esc(verdict.note)}` : ""}</div></div>`;
|
|
5033
5274
|
}
|
|
5034
5275
|
function renderEpisodes(report) {
|
|
5035
5276
|
if (report.episodes.length === 0) {
|
|
@@ -5145,7 +5386,7 @@ function renderInterpretation(report) {
|
|
|
5145
5386
|
"### Episode verdicts",
|
|
5146
5387
|
"",
|
|
5147
5388
|
...interpretation.episodeVerdicts.map(
|
|
5148
|
-
(v) => `- \`${v.episodeId}\`: **${v.verdict}
|
|
5389
|
+
(v) => `- \`${v.episodeId}\`: **${v.verdict}**${v.cause ? ` (${v.cause})` : ""} - ${v.note}`
|
|
5149
5390
|
),
|
|
5150
5391
|
""
|
|
5151
5392
|
] : []
|
|
@@ -5389,4 +5630,4 @@ function renderInsight2(judged, position, c, severityColor) {
|
|
|
5389
5630
|
return out;
|
|
5390
5631
|
}
|
|
5391
5632
|
|
|
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 };
|
|
5633
|
+
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 };
|