@llm4ts/flow 2.4.2 → 2.6.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.
Files changed (82) hide show
  1. package/dist/Classified.d.ts +2 -0
  2. package/dist/Classified.d.ts.map +1 -1
  3. package/dist/Classified.js +4 -0
  4. package/dist/Classified.js.map +1 -1
  5. package/dist/CostReport.d.ts +110 -0
  6. package/dist/CostReport.d.ts.map +1 -0
  7. package/dist/CostReport.js +313 -0
  8. package/dist/CostReport.js.map +1 -0
  9. package/dist/EstimatedUsage.d.ts.map +1 -1
  10. package/dist/EstimatedUsage.js +4 -0
  11. package/dist/EstimatedUsage.js.map +1 -1
  12. package/dist/Flow.d.ts +14 -0
  13. package/dist/Flow.d.ts.map +1 -1
  14. package/dist/Flow.js +45 -2
  15. package/dist/Flow.js.map +1 -1
  16. package/dist/FlowContext.d.ts +7 -0
  17. package/dist/FlowContext.d.ts.map +1 -1
  18. package/dist/FlowContext.js.map +1 -1
  19. package/dist/FlowEvents.d.ts +44 -1
  20. package/dist/FlowEvents.d.ts.map +1 -1
  21. package/dist/FlowEvents.js +35 -0
  22. package/dist/FlowEvents.js.map +1 -1
  23. package/dist/GitTool.d.ts +7 -0
  24. package/dist/GitTool.d.ts.map +1 -1
  25. package/dist/GitTool.js +15 -1
  26. package/dist/GitTool.js.map +1 -1
  27. package/dist/Judgment.d.ts +88 -0
  28. package/dist/Judgment.d.ts.map +1 -0
  29. package/dist/Judgment.js +281 -0
  30. package/dist/Judgment.js.map +1 -0
  31. package/dist/JudgmentDataset.d.ts +79 -0
  32. package/dist/JudgmentDataset.d.ts.map +1 -0
  33. package/dist/JudgmentDataset.js +164 -0
  34. package/dist/JudgmentDataset.js.map +1 -0
  35. package/dist/JudgmentEval.d.ts +143 -0
  36. package/dist/JudgmentEval.d.ts.map +1 -0
  37. package/dist/JudgmentEval.js +242 -0
  38. package/dist/JudgmentEval.js.map +1 -0
  39. package/dist/JudgmentLog.d.ts +46 -0
  40. package/dist/JudgmentLog.d.ts.map +1 -0
  41. package/dist/JudgmentLog.js +62 -0
  42. package/dist/JudgmentLog.js.map +1 -0
  43. package/dist/JudgmentTypes.d.ts +13 -0
  44. package/dist/JudgmentTypes.d.ts.map +1 -0
  45. package/dist/JudgmentTypes.js +11 -0
  46. package/dist/JudgmentTypes.js.map +1 -0
  47. package/dist/ProgramJudge.d.ts +15 -2
  48. package/dist/ProgramJudge.d.ts.map +1 -1
  49. package/dist/ProgramJudge.js +58 -3
  50. package/dist/ProgramJudge.js.map +1 -1
  51. package/dist/Replay.d.ts.map +1 -1
  52. package/dist/Replay.js +9 -4
  53. package/dist/Replay.js.map +1 -1
  54. package/dist/Review.d.ts +35 -0
  55. package/dist/Review.d.ts.map +1 -1
  56. package/dist/Review.js +92 -13
  57. package/dist/Review.js.map +1 -1
  58. package/dist/Reviewer.d.ts +8 -0
  59. package/dist/Reviewer.d.ts.map +1 -1
  60. package/dist/Reviewer.js +12 -1
  61. package/dist/Reviewer.js.map +1 -1
  62. package/dist/TransientRetry.d.ts.map +1 -1
  63. package/dist/TransientRetry.js +1 -0
  64. package/dist/TransientRetry.js.map +1 -1
  65. package/package.json +8 -3
  66. package/src/Classified.ts +5 -0
  67. package/src/CostReport.ts +402 -0
  68. package/src/EstimatedUsage.ts +15 -0
  69. package/src/Flow.ts +77 -2
  70. package/src/FlowContext.ts +7 -0
  71. package/src/FlowEvents.ts +42 -0
  72. package/src/GitTool.ts +19 -1
  73. package/src/Judgment.ts +418 -0
  74. package/src/JudgmentDataset.ts +254 -0
  75. package/src/JudgmentEval.ts +306 -0
  76. package/src/JudgmentLog.ts +96 -0
  77. package/src/JudgmentTypes.ts +15 -0
  78. package/src/ProgramJudge.ts +89 -4
  79. package/src/Replay.ts +23 -17
  80. package/src/Review.ts +163 -13
  81. package/src/Reviewer.ts +15 -1
  82. package/src/TransientRetry.ts +1 -0
@@ -0,0 +1,143 @@
1
+ import * as Schema from "effect/Schema";
2
+ import { type Answer } from "@llm4ts/core/judgment/Schemas";
3
+ import { type Decision } from "./Judgment.ts";
4
+ import { LabelledItem } from "./JudgmentDataset.ts";
5
+ import type { ReviewPrescreenResult, ReviewResult, Severity } from "./Review.ts";
6
+ import type { Reviewer } from "./Reviewer.ts";
7
+ export interface EvalItem {
8
+ readonly item: LabelledItem;
9
+ readonly answer: Answer | undefined;
10
+ readonly latencyMs: number;
11
+ readonly failure?: string;
12
+ readonly decision?: Decision;
13
+ readonly severities?: ReadonlyArray<Severity>;
14
+ }
15
+ /** One completed full-path result per lens; missing screens remain failed eval items. */
16
+ export declare const replayEvalItems: (commit: {
17
+ readonly sha: string;
18
+ readonly diff: string;
19
+ }, runs: ReadonlyArray<{
20
+ readonly lens: Reviewer;
21
+ readonly result: ReviewResult;
22
+ }>, observations: ReviewPrescreenResult["observations"], screeningMs: number, labelledAt: string) => ReadonlyArray<EvalItem>;
23
+ declare const SeverityCounts: Schema.Struct<{
24
+ readonly Critical: Schema.Int;
25
+ readonly Warning: Schema.Int;
26
+ readonly Info: Schema.Int;
27
+ }>;
28
+ /** Lost issues and missed positive lenses have different units; verify both independently. */
29
+ export declare const replayMissesAgree: (report: EvalReport, lost: typeof SeverityCounts.Type, missedPositiveLenses: number) => boolean;
30
+ export declare const EvalMemory: Schema.Struct<{
31
+ readonly restMb: Schema.Number;
32
+ readonly peakMb: Schema.Number;
33
+ }>;
34
+ export declare const CalibrationBin: Schema.Struct<{
35
+ readonly lower: Schema.Number;
36
+ readonly upper: Schema.Number;
37
+ readonly count: Schema.Int;
38
+ readonly meanLabelProbability: Schema.NullOr<Schema.Number>;
39
+ }>;
40
+ export declare const EvalMeasures: Schema.Struct<{
41
+ readonly items: Schema.Int;
42
+ readonly answered: Schema.Int;
43
+ readonly failed: Schema.Int;
44
+ readonly accuracy: Schema.NullOr<Schema.Number>;
45
+ readonly ece: Schema.NullOr<Schema.Number>;
46
+ readonly brier: Schema.NullOr<Schema.Number>;
47
+ readonly bins: Schema.$Array<Schema.Struct<{
48
+ readonly lower: Schema.Number;
49
+ readonly upper: Schema.Number;
50
+ readonly count: Schema.Int;
51
+ readonly meanLabelProbability: Schema.NullOr<Schema.Number>;
52
+ }>>;
53
+ readonly decisions: Schema.Struct<{
54
+ readonly act: Schema.Int;
55
+ readonly caution: Schema.Int;
56
+ readonly hold: Schema.Int;
57
+ }>;
58
+ readonly latencyMs: Schema.Struct<{
59
+ readonly p50: Schema.NullOr<Schema.Number>;
60
+ readonly p95: Schema.NullOr<Schema.Number>;
61
+ }>;
62
+ }>;
63
+ declare const EvalReport_base: Schema.Class<EvalReport, Schema.Struct<{
64
+ readonly overall: Schema.Struct<{
65
+ readonly items: Schema.Int;
66
+ readonly answered: Schema.Int;
67
+ readonly failed: Schema.Int;
68
+ readonly accuracy: Schema.NullOr<Schema.Number>;
69
+ readonly ece: Schema.NullOr<Schema.Number>;
70
+ readonly brier: Schema.NullOr<Schema.Number>;
71
+ readonly bins: Schema.$Array<Schema.Struct<{
72
+ readonly lower: Schema.Number;
73
+ readonly upper: Schema.Number;
74
+ readonly count: Schema.Int;
75
+ readonly meanLabelProbability: Schema.NullOr<Schema.Number>;
76
+ }>>;
77
+ readonly decisions: Schema.Struct<{
78
+ readonly act: Schema.Int;
79
+ readonly caution: Schema.Int;
80
+ readonly hold: Schema.Int;
81
+ }>;
82
+ readonly latencyMs: Schema.Struct<{
83
+ readonly p50: Schema.NullOr<Schema.Number>;
84
+ readonly p95: Schema.NullOr<Schema.Number>;
85
+ }>;
86
+ }>;
87
+ readonly decisions: Schema.$Array<Schema.Struct<{
88
+ readonly decision: Schema.Literals<readonly ["review-prescreen", "satisfied-probe", "program-judge"]>;
89
+ readonly measures: Schema.Struct<{
90
+ readonly items: Schema.Int;
91
+ readonly answered: Schema.Int;
92
+ readonly failed: Schema.Int;
93
+ readonly accuracy: Schema.NullOr<Schema.Number>;
94
+ readonly ece: Schema.NullOr<Schema.Number>;
95
+ readonly brier: Schema.NullOr<Schema.Number>;
96
+ readonly bins: Schema.$Array<Schema.Struct<{
97
+ readonly lower: Schema.Number;
98
+ readonly upper: Schema.Number;
99
+ readonly count: Schema.Int;
100
+ readonly meanLabelProbability: Schema.NullOr<Schema.Number>;
101
+ }>>;
102
+ readonly decisions: Schema.Struct<{
103
+ readonly act: Schema.Int;
104
+ readonly caution: Schema.Int;
105
+ readonly hold: Schema.Int;
106
+ }>;
107
+ readonly latencyMs: Schema.Struct<{
108
+ readonly p50: Schema.NullOr<Schema.Number>;
109
+ readonly p95: Schema.NullOr<Schema.Number>;
110
+ }>;
111
+ }>;
112
+ }>>;
113
+ readonly missedIssues: Schema.optionalKey<Schema.Struct<{
114
+ readonly count: Schema.Int;
115
+ readonly positiveAnswered: Schema.Int;
116
+ readonly rate: Schema.NullOr<Schema.Number>;
117
+ readonly severities: Schema.optionalKey<Schema.Struct<{
118
+ readonly Critical: Schema.Int;
119
+ readonly Warning: Schema.Int;
120
+ readonly Info: Schema.Int;
121
+ }>>;
122
+ }>>;
123
+ readonly memory: Schema.optionalKey<Schema.Struct<{
124
+ readonly restMb: Schema.Number;
125
+ readonly peakMb: Schema.Number;
126
+ }>>;
127
+ }>, {}>;
128
+ export declare class EvalReport extends EvalReport_base {
129
+ }
130
+ /** Failures and mismatched answer kinds count as failed and are excluded from all metrics. */
131
+ export declare const evaluateJudgments: (items: ReadonlyArray<EvalItem>, memory?: typeof EvalMemory.Type) => EvalReport;
132
+ export interface EvalReportMeta {
133
+ readonly date: string;
134
+ readonly decision: string;
135
+ readonly backend: string;
136
+ readonly model: string;
137
+ readonly memoryNote?: string;
138
+ readonly title?: string;
139
+ readonly latencyNote?: string;
140
+ }
141
+ export declare const renderEvalReport: (report: EvalReport, meta: EvalReportMeta) => string;
142
+ export {};
143
+ //# sourceMappingURL=JudgmentEval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentEval.d.ts","sourceRoot":"","sources":["../src/JudgmentEval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM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H,eAAO,MAAM,UAAU;;;EAAkE,CAAA;AACzF,eAAO,MAAM,cAAc;;;;;EAKzB,CAAA;AACF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;EAUvB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,qBAAa,UAAW,SAAQ,eAY9B;CAAG;AA4EL,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,GAC5B,OAAO,aAAa,CAAC,QAAQ,CAAC,EAC9B,SAAS,OAAO,UAAU,CAAC,IAAI,KAC9B,UAsCF,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAKD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,UAAU,EAAE,MAAM,cAAc,KAAG,MA2E3E,CAAA"}
@@ -0,0 +1,242 @@
1
+ import * as Schema from "effect/Schema";
2
+ import { expectedScore, truth } from "@llm4ts/core/judgment/Schemas";
3
+ import { decide } from "./Judgment.js";
4
+ import { candidateId, DatasetDecision, LabelledItem } from "./JudgmentDataset.js";
5
+ /** One completed full-path result per lens; missing screens remain failed eval items. */
6
+ export const replayEvalItems = (commit, runs, observations, screeningMs, labelledAt) => runs.map(({ lens, result }) => {
7
+ const observation = observations.find(({ key }) => key === lens.name);
8
+ const source = `commit:${commit.sha}:${lens.name}`;
9
+ return {
10
+ item: LabelledItem.make({
11
+ id: candidateId("review-prescreen", source),
12
+ decision: "review-prescreen",
13
+ source,
14
+ state: observation?.state ?? { diff: commit.diff },
15
+ question: observation?.question ?? truth(lens.screeningStatement),
16
+ label: result.issues.length > 0,
17
+ labelledBy: "outcome",
18
+ labelledAt
19
+ }),
20
+ answer: observation?.answer,
21
+ ...(observation === undefined
22
+ ? { failure: "Pre-screen returned no matching answer." }
23
+ : { decision: observation.decision }),
24
+ severities: result.issues.map(({ severity }) => severity),
25
+ latencyMs: screeningMs / runs.length
26
+ };
27
+ });
28
+ const SeverityCounts = Schema.Struct({
29
+ Critical: Schema.Int,
30
+ Warning: Schema.Int,
31
+ Info: Schema.Int
32
+ });
33
+ /** Lost issues and missed positive lenses have different units; verify both independently. */
34
+ export const replayMissesAgree = (report, lost, missedPositiveLenses) => report.missedIssues?.count === missedPositiveLenses &&
35
+ report.missedIssues.severities !== undefined &&
36
+ ["Critical", "Warning", "Info"].every((severity) => report.missedIssues?.severities?.[severity] === lost[severity]);
37
+ const Metric = Schema.NullOr(Schema.Number);
38
+ export const EvalMemory = Schema.Struct({ restMb: Schema.Number, peakMb: Schema.Number });
39
+ export const CalibrationBin = Schema.Struct({
40
+ lower: Schema.Number,
41
+ upper: Schema.Number,
42
+ count: Schema.Int,
43
+ meanLabelProbability: Metric
44
+ });
45
+ export const EvalMeasures = Schema.Struct({
46
+ items: Schema.Int,
47
+ answered: Schema.Int,
48
+ failed: Schema.Int,
49
+ accuracy: Metric,
50
+ ece: Metric,
51
+ brier: Metric,
52
+ bins: Schema.Array(CalibrationBin),
53
+ decisions: Schema.Struct({ act: Schema.Int, caution: Schema.Int, hold: Schema.Int }),
54
+ latencyMs: Schema.Struct({ p50: Metric, p95: Metric })
55
+ });
56
+ export class EvalReport extends Schema.Class("EvalReport")({
57
+ overall: EvalMeasures,
58
+ decisions: Schema.Array(Schema.Struct({ decision: DatasetDecision, measures: EvalMeasures })),
59
+ missedIssues: Schema.optionalKey(Schema.Struct({
60
+ count: Schema.Int,
61
+ positiveAnswered: Schema.Int,
62
+ rate: Metric,
63
+ severities: Schema.optionalKey(SeverityCounts)
64
+ })),
65
+ memory: Schema.optionalKey(EvalMemory)
66
+ }) {
67
+ }
68
+ const measured = ({ item, answer, failure, latencyMs, decision }) => {
69
+ if (failure !== undefined || answer === undefined)
70
+ return undefined;
71
+ if (item.question.type === "truth" &&
72
+ answer.type === "truth" &&
73
+ typeof item.label === "boolean") {
74
+ return {
75
+ answer,
76
+ decision: decision ?? decide(answer),
77
+ latencyMs,
78
+ correct: answer.truth >= 0.5 === item.label,
79
+ probability: item.label ? answer.truth : 1 - answer.truth
80
+ };
81
+ }
82
+ if (item.question.type === "score" && answer.type === "score" && typeof item.label === "number") {
83
+ return {
84
+ answer,
85
+ decision: decision ?? decide(answer),
86
+ latencyMs,
87
+ correct: Math.round(expectedScore(answer.probabilities)) === item.label,
88
+ probability: answer.probabilities[String(item.label)] ?? 0
89
+ };
90
+ }
91
+ return undefined;
92
+ };
93
+ /** Nearest rank, with no interpolation; no observations means no metric. */
94
+ const percentile = (sorted, fraction) => sorted[Math.ceil(sorted.length * fraction) - 1] ?? null;
95
+ const measures = (items) => {
96
+ const answered = items.flatMap((item) => {
97
+ const value = measured(item);
98
+ return value === undefined ? [] : [value];
99
+ });
100
+ const count = answered.length;
101
+ const average = (sum) => (count === 0 ? null : sum / count);
102
+ const bins = Array.from({ length: 10 }, (_, index) => {
103
+ const members = answered.filter(({ probability }) => Math.min(9, Math.floor(probability * 10)) === index);
104
+ return {
105
+ lower: index / 10,
106
+ upper: (index + 1) / 10,
107
+ count: members.length,
108
+ meanLabelProbability: members.length === 0
109
+ ? null
110
+ : members.reduce((sum, member) => sum + member.probability, 0) / members.length
111
+ };
112
+ });
113
+ const decisions = answered.map(({ decision }) => decision);
114
+ const latencies = answered.map(({ latencyMs }) => latencyMs).sort((a, b) => a - b);
115
+ return {
116
+ items: items.length,
117
+ answered: count,
118
+ failed: items.length - count,
119
+ accuracy: average(answered.filter(({ correct }) => correct).length),
120
+ // The labelled outcome occurred (target 1), regardless of the predicted class.
121
+ ece: average(bins.reduce((sum, bin) => sum + bin.count * Math.abs(1 - (bin.meanLabelProbability ?? 1)), 0)),
122
+ brier: average(answered.reduce((sum, value) => sum + (1 - value.probability) ** 2, 0)),
123
+ bins,
124
+ decisions: {
125
+ act: decisions.filter((decision) => decision === "act").length,
126
+ caution: decisions.filter((decision) => decision === "caution").length,
127
+ hold: decisions.filter((decision) => decision === "hold").length
128
+ },
129
+ latencyMs: { p50: percentile(latencies, 0.5), p95: percentile(latencies, 0.95) }
130
+ };
131
+ };
132
+ /** Failures and mismatched answer kinds count as failed and are excluded from all metrics. */
133
+ export const evaluateJudgments = (items, memory) => {
134
+ const decisions = [...new Set(items.map(({ item }) => item.decision))].sort();
135
+ const positives = items
136
+ .filter(({ item }) => item.decision === "review-prescreen" && item.label === true)
137
+ .flatMap((item) => {
138
+ const value = measured(item);
139
+ return value === undefined ? [] : [{ ...value, severities: item.severities }];
140
+ });
141
+ const missed = positives.filter(({ answer, decision }) => answer.type === "truth" && answer.truth < 0.5 && decision === "act");
142
+ const severities = missed.flatMap((item) => item.severities ?? []);
143
+ return EvalReport.make({
144
+ overall: measures(items),
145
+ decisions: decisions.map((decision) => ({
146
+ decision,
147
+ measures: measures(items.filter(({ item }) => item.decision === decision))
148
+ })),
149
+ ...(decisions.includes("review-prescreen")
150
+ ? {
151
+ missedIssues: {
152
+ count: missed.length,
153
+ positiveAnswered: positives.length,
154
+ rate: positives.length === 0 ? null : missed.length / positives.length,
155
+ ...(items.every((item) => item.severities !== undefined)
156
+ ? {
157
+ severities: {
158
+ Critical: severities.filter((severity) => severity === "Critical").length,
159
+ Warning: severities.filter((severity) => severity === "Warning").length,
160
+ Info: severities.filter((severity) => severity === "Info").length
161
+ }
162
+ }
163
+ : {})
164
+ }
165
+ }
166
+ : {}),
167
+ ...(memory === undefined ? {} : { memory })
168
+ });
169
+ };
170
+ const cell = (value) => value.replace(/\|/g, "&#124;").replace(/[\r\n]/g, " ");
171
+ const number = (value) => (value === null ? "n/a" : value.toFixed(4));
172
+ export const renderEvalReport = (report, meta) => {
173
+ const rows = [
174
+ ...report.decisions.map(({ decision, measures }) => ({ name: decision, measures })),
175
+ { name: "Overall", measures: report.overall }
176
+ ];
177
+ return [
178
+ `# ${cell(meta.title ?? "Judgment evaluation")}`,
179
+ "",
180
+ `- Date: ${cell(meta.date)}`,
181
+ `- Decision: ${cell(meta.decision)}`,
182
+ `- Backend identity: ${cell(meta.backend)}`,
183
+ `- Model: ${cell(meta.model)}`,
184
+ "",
185
+ "## Measures",
186
+ "",
187
+ "| Decision | Items | Answered | Failed | Accuracy | ECE (10 bins) | Brier | p50 ms | p95 ms |",
188
+ "| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |",
189
+ ...rows.map(({ name, measures: m }) => `| ${name} | ${m.items} | ${m.answered} | ${m.failed} | ${number(m.accuracy)} | ${number(m.ece)} | ${number(m.brier)} | ${number(m.latencyMs.p50)} | ${number(m.latencyMs.p95)} |`),
190
+ "",
191
+ "Metrics use answered items only; n/a means no observations. Overall is item-weighted.",
192
+ "Accuracy: Truth >= 0.5; Score rounds the expected level index.",
193
+ "ECE bins the labelled-outcome probability p into [0, 0.1), ..., [0.9, 1]; target = 1.",
194
+ "ECE = sum(bin count / answered * |1 - mean p|); Brier = mean((1 - p)^2).",
195
+ "These are labelled-outcome metrics, not predicted-confidence ECE or multiclass Brier.",
196
+ meta.latencyNote ??
197
+ "Latency uses nearest-rank percentiles per independent question, excluding failures.",
198
+ "",
199
+ "## Default policy decisions",
200
+ "",
201
+ "| Decision | Act | Caution | Hold |",
202
+ "| --- | ---: | ---: | ---: |",
203
+ ...rows.map(({ name, measures: m }) => `| ${name} | ${m.decisions.act} | ${m.decisions.caution} | ${m.decisions.hold} |`),
204
+ ...(report.missedIssues === undefined
205
+ ? []
206
+ : [
207
+ "",
208
+ "## Pre-screen missed issues",
209
+ "",
210
+ "| Missed positive items | Answered positive items | Missed rate |",
211
+ "| ---: | ---: | ---: |",
212
+ `| ${report.missedIssues.count} | ${report.missedIssues.positiveAnswered} | ${number(report.missedIssues.rate)} |`,
213
+ "",
214
+ "A miss requires label=true, truth<0.5 and decide=act (the lens would be skipped).",
215
+ ...(report.missedIssues.severities === undefined
216
+ ? [
217
+ "Severity breakdown unavailable: LabelledItem records presence, not issue counts or severity."
218
+ ]
219
+ : [
220
+ "",
221
+ "| Lost Critical issues | Lost Warning issues | Lost Info issues |",
222
+ "| ---: | ---: | ---: |",
223
+ `| ${report.missedIssues.severities.Critical} | ${report.missedIssues.severities.Warning} | ${report.missedIssues.severities.Info} |`,
224
+ "",
225
+ "Severity counts are issues on missed positive lenses; one lens can report multiple issues."
226
+ ])
227
+ ]),
228
+ "",
229
+ "## Judgment seat resident memory",
230
+ "",
231
+ "| Rest MiB | Sampled peak MiB |",
232
+ "| ---: | ---: |",
233
+ `| ${number(report.memory?.restMb ?? null)} | ${number(report.memory?.peakMb ?? null)} |`,
234
+ "",
235
+ meta.memoryNote ??
236
+ (report.memory === undefined
237
+ ? "Memory not supplied."
238
+ : "Memory supplied by the caller; peak is the maximum sampled RSS."),
239
+ ""
240
+ ].join("\n");
241
+ };
242
+ //# sourceMappingURL=JudgmentEval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentEval.js","sourceRoot":"","sources":["../src/JudgmentEval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAe,MAAM,+BAA+B,CAAA;AACjF,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAajF,yFAAyF;AACzF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,MAAuD,EACvD,IAA+E,EAC/E,YAAmD,EACnD,WAAmB,EACnB,UAAkB,EACO,EAAE,CAC3B,IAAI,CAAC,GAAG,CAAC,CAAC,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;aACP,CAAC;QACN,EAAE;QACF,kCAAkC;QAClC,EAAE;QACF,iCAAiC;QACjC,iBAAiB;QACjB,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,IAAI,CAAC,IAAI;QACzF,EAAE;QACF,IAAI,CAAC,UAAU;YACb,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS;gBAC1B,CAAC,CAAC,sBAAsB;gBACxB,CAAC,CAAC,iEAAiE,CAAC;QACxE,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC,CAAA"}
@@ -0,0 +1,46 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
+ import type * as Scope from "effect/Scope";
4
+ import { type FlowEvent, type FlowEventHub } from "./FlowEvents.ts";
5
+ import type { PlainFileStoreShape } from "./Persistence.ts";
6
+ declare const JudgmentObservation_base: Schema.Class<JudgmentObservation, Schema.Struct<{
7
+ readonly runId: Schema.String;
8
+ /** Epoch milliseconds, matching FlowRecorder's timestamp. */
9
+ readonly at: Schema.Number;
10
+ readonly consumer: Schema.Literals<readonly ["review-prescreen", "satisfied-probe", "program-judge"]>;
11
+ readonly key: Schema.String;
12
+ readonly state: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>, Schema.$Array<Schema.String>]>;
13
+ readonly question: Schema.Union<readonly [typeof import("@llm4ts/core/judgment/Schemas.ts").ChoiceQuestion, typeof import("@llm4ts/core/judgment/Schemas.ts").ScoreQuestion, typeof import("@llm4ts/core/judgment/Schemas.ts").TruthQuestion]>;
14
+ readonly answer: Schema.Union<readonly [typeof import("@llm4ts/core/judgment/Schemas.ts").ChoiceAnswer, typeof import("@llm4ts/core/judgment/Schemas.ts").ScoreAnswer, typeof import("@llm4ts/core/judgment/Schemas.ts").TruthAnswer]>;
15
+ readonly outcome: Schema.Union<readonly [Schema.TaggedStruct<"ReviewPrescreen", {
16
+ readonly lens: Schema.String;
17
+ readonly issues: Schema.Struct<{
18
+ readonly Critical: Schema.Int;
19
+ readonly Warning: Schema.Int;
20
+ readonly Info: Schema.Int;
21
+ }>;
22
+ }>, Schema.TaggedStruct<"SatisfiedProbe", {
23
+ readonly literalMatch: Schema.Boolean;
24
+ }>, Schema.TaggedStruct<"ProgramJudge", {
25
+ readonly score: Schema.Number;
26
+ }>]>;
27
+ readonly decision: Schema.Literals<readonly ["act", "caution", "hold"]>;
28
+ readonly mode: Schema.Literals<readonly ["observe", "advise", "act"]>;
29
+ readonly judgmentIdentity: Schema.String;
30
+ }>, {}>;
31
+ export declare class JudgmentObservation extends JudgmentObservation_base {
32
+ }
33
+ export declare const judgmentLogPath: (root: string, consumer: JudgmentObservation["consumer"]) => string;
34
+ export interface JudgmentLogShape {
35
+ readonly record: (event: FlowEvent) => Effect.Effect<void>;
36
+ readonly consume: (hub: FlowEventHub) => Effect.Effect<void, never, Scope.Scope>;
37
+ readonly awaitDrained: (hub: FlowEventHub) => Effect.Effect<void>;
38
+ }
39
+ /** A best-effort subscriber, with the same permanent degradation policy as FlowRecorder. */
40
+ export declare const makeJudgmentLog: (options: {
41
+ readonly files: PlainFileStoreShape;
42
+ readonly root: string;
43
+ readonly runId: string;
44
+ }) => Effect.Effect<JudgmentLogShape, never, never>;
45
+ export {};
46
+ //# sourceMappingURL=JudgmentLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentLog.d.ts","sourceRoot":"","sources":["../src/JudgmentLog.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACrF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;;;IAIzD,6DAA6D;;;;;;;;;;;;;;;;;;;;;;;AAF/D,qBAAa,mBAAoB,SAAQ,wBAavC;CAAG;AAEL,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,UAAU,mBAAmB,CAAC,UAAU,CAAC,KAAG,MACpB,CAAA;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1D,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;IAChF,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAClE;AAID,4FAA4F;AAC5F,eAAO,MAAM,eAAe;oBACV,mBAAmB;mBACpB,MAAM;oBACL,MAAM;mDAuDtB,CAAA"}
@@ -0,0 +1,62 @@
1
+ import * as Clock from "effect/Clock";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Ref from "effect/Ref";
4
+ import * as Schema from "effect/Schema";
5
+ import * as Semaphore from "effect/Semaphore";
6
+ import * as Stream from "effect/Stream";
7
+ import { JudgmentObserved } from "./FlowEvents.js";
8
+ export class JudgmentObservation extends Schema.Class("JudgmentObservation")({
9
+ runId: Schema.String,
10
+ /** Epoch milliseconds, matching FlowRecorder's timestamp. */
11
+ at: Schema.Number,
12
+ consumer: JudgmentObserved.fields.consumer,
13
+ key: JudgmentObserved.fields.key,
14
+ state: JudgmentObserved.fields.state,
15
+ question: JudgmentObserved.fields.question,
16
+ answer: JudgmentObserved.fields.answer,
17
+ outcome: JudgmentObserved.fields.outcome,
18
+ decision: JudgmentObserved.fields.decision,
19
+ mode: JudgmentObserved.fields.mode,
20
+ judgmentIdentity: JudgmentObserved.fields.judgmentIdentity
21
+ }) {
22
+ }
23
+ export const judgmentLogPath = (root, consumer) => `${root.replace(/[\\/]+$/, "")}/.llm4ts/judgments/${consumer}.jsonl`;
24
+ const codec = Schema.fromJsonString(JudgmentObservation);
25
+ /** A best-effort subscriber, with the same permanent degradation policy as FlowRecorder. */
26
+ export const makeJudgmentLog = Effect.fn("@llm4ts/flow/JudgmentLog.make")(function* (options) {
27
+ const consumed = yield* Ref.make(0);
28
+ const degraded = yield* Ref.make(false);
29
+ const lock = yield* Semaphore.make(1);
30
+ const record = (event) => event._tag !== "JudgmentObserved"
31
+ ? Effect.void
32
+ : lock.withPermit(Effect.gen(function* () {
33
+ if (yield* Ref.get(degraded))
34
+ return;
35
+ const at = yield* Clock.currentTimeMillis;
36
+ // Classified remains sealed until an explicit, audited declassify.
37
+ // Text uses its toString; JSON uses its toJSON. Serialize before
38
+ // schema traversal so even nested sealed values use that redaction,
39
+ // never their private payload. Already declassified plain text has
40
+ // no taint metadata; callers must retain the wrapper for secrets.
41
+ const observation = yield* Schema.decodeUnknownEffect(codec)(JSON.stringify({ ...event, runId: options.runId, at }));
42
+ const line = yield* Schema.encodeEffect(codec)(observation);
43
+ yield* options.files.append(judgmentLogPath(options.root, event.consumer), `${line}\n`);
44
+ }).pipe(Effect.catch(() => Ref.set(degraded, true))));
45
+ const awaitDrained = (hub) => Effect.gen(function* () {
46
+ const target = yield* hub.publishedCount;
47
+ const drain = Effect.suspend(() => Ref.get(consumed).pipe(Effect.flatMap((count) => count >= target ? Effect.void : Effect.yieldNow.pipe(Effect.andThen(drain)))));
48
+ yield* drain;
49
+ });
50
+ return {
51
+ record,
52
+ awaitDrained,
53
+ consume: (hub) => Effect.gen(function* () {
54
+ yield* Ref.set(consumed, yield* hub.publishedCount);
55
+ const subscription = yield* hub.subscribe;
56
+ yield* Stream.fromSubscription(subscription).pipe(Stream.runForEach((event) => record(event).pipe(Effect.andThen(Ref.update(consumed, (count) => count + 1)))), Effect.forkScoped);
57
+ // Registered after the consumer fiber: drain before scope interrupts it.
58
+ yield* Effect.addFinalizer(() => awaitDrained(hub));
59
+ })
60
+ };
61
+ });
62
+ //# sourceMappingURL=JudgmentLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentLog.js","sourceRoot":"","sources":["../src/JudgmentLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAE7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAqC,MAAM,iBAAiB,CAAA;AAGrF,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,KAAK,CAAsB,qBAAqB,CAAC,CAAC;IAChG,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;IAC1C,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG;IAChC,KAAK,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK;IACpC,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;IAC1C,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM;IACtC,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO;IACxC,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;IAC1C,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI;IAClC,gBAAgB,EAAE,gBAAgB,CAAC,MAAM,CAAC,gBAAgB;CAC3D,CAAC;CAAG;AAEL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,KAAK,CAAC,CAAC,GAAG,CAAC,SAAS,CAAA;YACzC,KAAK,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,IAAI,CAC/C,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAC1B,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAC/E,EACD,MAAM,CAAC,UAAU,CAClB,CAAA;YACD,yEAAyE;YACzE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;QACrD,CAAC,CAAC;KACL,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * The two literals shared by the judgment policy and the flow events. They
4
+ * live apart from `Judgment.ts` so `FlowEvents.ts` can import them without
5
+ * a module cycle (the policy module publishes events).
6
+ */
7
+ /** Consumers observe by default; automation requires an explicit act mode. */
8
+ export declare const JudgmentMode: Schema.Literals<readonly ["observe", "advise", "act"]>;
9
+ export type JudgmentMode = typeof JudgmentMode.Type;
10
+ /** The three bands Jev documents: act, proceed with caution, or hold. */
11
+ export declare const Decision: Schema.Literals<readonly ["act", "caution", "hold"]>;
12
+ export type Decision = typeof Decision.Type;
13
+ //# sourceMappingURL=JudgmentTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentTypes.d.ts","sourceRoot":"","sources":["../src/JudgmentTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,YAAY,wDAAgD,CAAA;AACzE,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,yEAAyE;AACzE,eAAO,MAAM,QAAQ,sDAA8C,CAAA;AACnE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA"}
@@ -0,0 +1,11 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * The two literals shared by the judgment policy and the flow events. They
4
+ * live apart from `Judgment.ts` so `FlowEvents.ts` can import them without
5
+ * a module cycle (the policy module publishes events).
6
+ */
7
+ /** Consumers observe by default; automation requires an explicit act mode. */
8
+ export const JudgmentMode = Schema.Literals(["observe", "advise", "act"]);
9
+ /** The three bands Jev documents: act, proceed with caution, or hold. */
10
+ export const Decision = Schema.Literals(["act", "caution", "hold"]);
11
+ //# sourceMappingURL=JudgmentTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JudgmentTypes.js","sourceRoot":"","sources":["../src/JudgmentTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;AAGzE,yEAAyE;AACzE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA"}
@@ -1,8 +1,10 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import { Sample, type Dimension } from "@llm4ts/core/eval/Eval";
3
- import type { Evaluator } from "@llm4ts/core/eval/Evaluator";
3
+ import { type Evaluator } from "@llm4ts/core/eval/Evaluator";
4
+ import type { JudgmentShape } from "@llm4ts/core/judgment/Judgment";
4
5
  import { FlowLlmError, type FlowError } from "./FlowError.ts";
5
- import { FlowEvents } from "./FlowEvents.ts";
6
+ import { FlowEvents, type FlowEventsShape } from "./FlowEvents.ts";
7
+ import { type JudgmentMode } from "./Judgment.ts";
6
8
  import type { GitToolShape } from "./GitTool.ts";
7
9
  import type { Pack } from "./Pack.ts";
8
10
  import type { PlainFileStoreShape } from "./Persistence.ts";
@@ -21,6 +23,11 @@ export declare const groupFiles: (pack: Pack, programs: ReadonlyArray<string>, c
21
23
  export interface ProgramJudgeOptions {
22
24
  readonly pack: Pack;
23
25
  readonly judge: Evaluator<Sample>;
26
+ /** Observe alongside the generative judge by default; only act replaces its scores. */
27
+ readonly judgment?: {
28
+ readonly judgment: JudgmentShape;
29
+ readonly mode?: JudgmentMode;
30
+ };
24
31
  readonly dimensions: ReadonlyArray<Dimension>;
25
32
  readonly git: GitToolShape;
26
33
  readonly files: PlainFileStoreShape;
@@ -34,6 +41,12 @@ export interface ProgramJudgeOptions {
34
41
  /** Content fingerprint for the verdict cache (hashing lives outside flow). */
35
42
  readonly fingerprint: (...parts: ReadonlyArray<string>) => string;
36
43
  }
44
+ /**
45
+ * Compare typed answers with generative scores without changing the result in
46
+ * observe/advise. Failed questions have no answer to observe; backend failure
47
+ * keeps the generative result. Act uses core's judgment evaluator unchanged.
48
+ */
49
+ export declare const withJudgment: (generative: Evaluator<Sample>, dimensions: ReadonlyArray<Dimension>, options: NonNullable<ProgramJudgeOptions["judgment"]>, events: FlowEventsShape) => Evaluator<Sample>;
37
50
  /**
38
51
  * A spec'd program with NO matching changed file is a deterministic gate
39
52
  * failure, not a silent pass. Skipping it would let the branch clear a bar the
@@ -1 +1 @@
1
- {"version":3,"file":"ProgramJudge.d.ts","sourceRoot":"","sources":["../src/ProgramJudge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAmB,MAAM,wBAAwB,CAAA;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAE5D,OAAO,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,MAA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