@tangle-network/agent-eval 0.120.0 → 0.120.2

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 (171) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/dist/analyst/index.d.ts +0 -3111
  4. package/dist/analyst/index.js +0 -403
  5. package/dist/analyst/index.js.map +0 -1
  6. package/dist/authenticity/index.d.ts +0 -161
  7. package/dist/authenticity/index.js +0 -215
  8. package/dist/authenticity/index.js.map +0 -1
  9. package/dist/belief-state/index.d.ts +0 -1301
  10. package/dist/belief-state/index.js +0 -2152
  11. package/dist/belief-state/index.js.map +0 -1
  12. package/dist/benchmarks/index.d.ts +0 -974
  13. package/dist/benchmarks/index.js +0 -60
  14. package/dist/benchmarks/index.js.map +0 -1
  15. package/dist/builder-eval/index.d.ts +0 -695
  16. package/dist/builder-eval/index.js +0 -366
  17. package/dist/builder-eval/index.js.map +0 -1
  18. package/dist/campaign/index.d.ts +0 -7454
  19. package/dist/campaign/index.js +0 -272
  20. package/dist/campaign/index.js.map +0 -1
  21. package/dist/chunk-32BZXMSO.js +0 -3878
  22. package/dist/chunk-32BZXMSO.js.map +0 -1
  23. package/dist/chunk-3A246TSA.js +0 -998
  24. package/dist/chunk-3A246TSA.js.map +0 -1
  25. package/dist/chunk-3RF76KTD.js +0 -84
  26. package/dist/chunk-3RF76KTD.js.map +0 -1
  27. package/dist/chunk-3YYRZDON.js +0 -45
  28. package/dist/chunk-3YYRZDON.js.map +0 -1
  29. package/dist/chunk-4I2E3LLO.js +0 -1030
  30. package/dist/chunk-4I2E3LLO.js.map +0 -1
  31. package/dist/chunk-ARU2PZFM.js +0 -312
  32. package/dist/chunk-ARU2PZFM.js.map +0 -1
  33. package/dist/chunk-BOD4O7OF.js +0 -40
  34. package/dist/chunk-BOD4O7OF.js.map +0 -1
  35. package/dist/chunk-DPZAEKA6.js +0 -880
  36. package/dist/chunk-DPZAEKA6.js.map +0 -1
  37. package/dist/chunk-DTJ6QUQB.js +0 -131
  38. package/dist/chunk-DTJ6QUQB.js.map +0 -1
  39. package/dist/chunk-GGE4NNQT.js +0 -65
  40. package/dist/chunk-GGE4NNQT.js.map +0 -1
  41. package/dist/chunk-H5UD2323.js +0 -286
  42. package/dist/chunk-H5UD2323.js.map +0 -1
  43. package/dist/chunk-HHWE3POT.js +0 -94
  44. package/dist/chunk-HHWE3POT.js.map +0 -1
  45. package/dist/chunk-HKUCJ437.js +0 -787
  46. package/dist/chunk-HKUCJ437.js.map +0 -1
  47. package/dist/chunk-JHCHEVET.js +0 -274
  48. package/dist/chunk-JHCHEVET.js.map +0 -1
  49. package/dist/chunk-JHOJHHU7.js +0 -867
  50. package/dist/chunk-JHOJHHU7.js.map +0 -1
  51. package/dist/chunk-JM2SKQMS.js +0 -750
  52. package/dist/chunk-JM2SKQMS.js.map +0 -1
  53. package/dist/chunk-JN2FCO5W.js +0 -7958
  54. package/dist/chunk-JN2FCO5W.js.map +0 -1
  55. package/dist/chunk-K4DBDHLK.js +0 -158
  56. package/dist/chunk-K4DBDHLK.js.map +0 -1
  57. package/dist/chunk-K6N6XJJX.js +0 -306
  58. package/dist/chunk-K6N6XJJX.js.map +0 -1
  59. package/dist/chunk-MA6HLL3S.js +0 -65
  60. package/dist/chunk-MA6HLL3S.js.map +0 -1
  61. package/dist/chunk-MAZ26DC7.js +0 -99
  62. package/dist/chunk-MAZ26DC7.js.map +0 -1
  63. package/dist/chunk-MOXWMGPC.js +0 -577
  64. package/dist/chunk-MOXWMGPC.js.map +0 -1
  65. package/dist/chunk-NJC7U437.js +0 -626
  66. package/dist/chunk-NJC7U437.js.map +0 -1
  67. package/dist/chunk-NPCTHQIO.js +0 -91
  68. package/dist/chunk-NPCTHQIO.js.map +0 -1
  69. package/dist/chunk-ONWEPEDO.js +0 -57
  70. package/dist/chunk-ONWEPEDO.js.map +0 -1
  71. package/dist/chunk-OYZAPX5G.js +0 -1526
  72. package/dist/chunk-OYZAPX5G.js.map +0 -1
  73. package/dist/chunk-PC4UYEBM.js +0 -166
  74. package/dist/chunk-PC4UYEBM.js.map +0 -1
  75. package/dist/chunk-PICTDURQ.js +0 -766
  76. package/dist/chunk-PICTDURQ.js.map +0 -1
  77. package/dist/chunk-PJQFMIOX.js +0 -1182
  78. package/dist/chunk-PJQFMIOX.js.map +0 -1
  79. package/dist/chunk-PXD6ZFNY.js +0 -1107
  80. package/dist/chunk-PXD6ZFNY.js.map +0 -1
  81. package/dist/chunk-PXE2VKMX.js +0 -140
  82. package/dist/chunk-PXE2VKMX.js.map +0 -1
  83. package/dist/chunk-PZ5AY32C.js +0 -10
  84. package/dist/chunk-PZ5AY32C.js.map +0 -1
  85. package/dist/chunk-QBRSJK47.js +0 -622
  86. package/dist/chunk-QBRSJK47.js.map +0 -1
  87. package/dist/chunk-QWMPPZ3X.js +0 -550
  88. package/dist/chunk-QWMPPZ3X.js.map +0 -1
  89. package/dist/chunk-S3UZOQ5Y.js +0 -328
  90. package/dist/chunk-S3UZOQ5Y.js.map +0 -1
  91. package/dist/chunk-S5TT5R3L.js +0 -2668
  92. package/dist/chunk-S5TT5R3L.js.map +0 -1
  93. package/dist/chunk-T4SQEITX.js +0 -95
  94. package/dist/chunk-T4SQEITX.js.map +0 -1
  95. package/dist/chunk-TT4KNT67.js +0 -124
  96. package/dist/chunk-TT4KNT67.js.map +0 -1
  97. package/dist/chunk-U5CHZ5M3.js +0 -357
  98. package/dist/chunk-U5CHZ5M3.js.map +0 -1
  99. package/dist/chunk-ULOKLHIQ.js +0 -1937
  100. package/dist/chunk-ULOKLHIQ.js.map +0 -1
  101. package/dist/chunk-VI2UW6B6.js +0 -162
  102. package/dist/chunk-VI2UW6B6.js.map +0 -1
  103. package/dist/chunk-VQMK5FMP.js +0 -247
  104. package/dist/chunk-VQMK5FMP.js.map +0 -1
  105. package/dist/chunk-VSMTAMNK.js +0 -53
  106. package/dist/chunk-VSMTAMNK.js.map +0 -1
  107. package/dist/chunk-VZSRQ272.js +0 -149
  108. package/dist/chunk-VZSRQ272.js.map +0 -1
  109. package/dist/chunk-WW2A73HW.js +0 -159
  110. package/dist/chunk-WW2A73HW.js.map +0 -1
  111. package/dist/chunk-X4UCIOTZ.js +0 -136
  112. package/dist/chunk-X4UCIOTZ.js.map +0 -1
  113. package/dist/chunk-XDIRG3TO.js +0 -1266
  114. package/dist/chunk-XDIRG3TO.js.map +0 -1
  115. package/dist/chunk-XJYR7XFV.js +0 -317
  116. package/dist/chunk-XJYR7XFV.js.map +0 -1
  117. package/dist/chunk-ZET2UAYW.js +0 -89
  118. package/dist/chunk-ZET2UAYW.js.map +0 -1
  119. package/dist/chunk-ZZUXHH3R.js +0 -99
  120. package/dist/chunk-ZZUXHH3R.js.map +0 -1
  121. package/dist/cli.d.ts +0 -1
  122. package/dist/cli.js +0 -112
  123. package/dist/cli.js.map +0 -1
  124. package/dist/contract/index.d.ts +0 -4969
  125. package/dist/contract/index.js +0 -1653
  126. package/dist/contract/index.js.map +0 -1
  127. package/dist/control.d.ts +0 -1013
  128. package/dist/control.js +0 -34
  129. package/dist/control.js.map +0 -1
  130. package/dist/fuzz.d.ts +0 -759
  131. package/dist/fuzz.js +0 -714
  132. package/dist/fuzz.js.map +0 -1
  133. package/dist/hosted/index.d.ts +0 -730
  134. package/dist/hosted/index.js +0 -14
  135. package/dist/hosted/index.js.map +0 -1
  136. package/dist/index.d.ts +0 -16780
  137. package/dist/index.js +0 -12168
  138. package/dist/index.js.map +0 -1
  139. package/dist/matrix/index.d.ts +0 -155
  140. package/dist/matrix/index.js +0 -8
  141. package/dist/matrix/index.js.map +0 -1
  142. package/dist/meta-eval/index.d.ts +0 -1030
  143. package/dist/meta-eval/index.js +0 -417
  144. package/dist/meta-eval/index.js.map +0 -1
  145. package/dist/multishot/index.d.ts +0 -579
  146. package/dist/multishot/index.js +0 -589
  147. package/dist/multishot/index.js.map +0 -1
  148. package/dist/openapi.json +0 -992
  149. package/dist/pipelines/index.d.ts +0 -567
  150. package/dist/pipelines/index.js +0 -515
  151. package/dist/pipelines/index.js.map +0 -1
  152. package/dist/reporting.d.ts +0 -1277
  153. package/dist/reporting.js +0 -48
  154. package/dist/reporting.js.map +0 -1
  155. package/dist/rl.d.ts +0 -4092
  156. package/dist/rl.js +0 -1724
  157. package/dist/rl.js.map +0 -1
  158. package/dist/run-campaign-HNFPJET4.js +0 -14
  159. package/dist/run-campaign-HNFPJET4.js.map +0 -1
  160. package/dist/storyboard/index.d.ts +0 -279
  161. package/dist/storyboard/index.js +0 -767
  162. package/dist/storyboard/index.js.map +0 -1
  163. package/dist/trace-attributes.d.ts +0 -52
  164. package/dist/trace-attributes.js +0 -62
  165. package/dist/trace-attributes.js.map +0 -1
  166. package/dist/traces.d.ts +0 -2343
  167. package/dist/traces.js +0 -249
  168. package/dist/traces.js.map +0 -1
  169. package/dist/wire/index.d.ts +0 -1252
  170. package/dist/wire/index.js +0 -81
  171. package/dist/wire/index.js.map +0 -1
@@ -1,750 +0,0 @@
1
- import {
2
- Mutex
3
- } from "./chunk-3YYRZDON.js";
4
- import {
5
- aggregateRunScore,
6
- clamp01,
7
- computeFindingId
8
- } from "./chunk-S5TT5R3L.js";
9
- import {
10
- callLlmJson,
11
- costReceiptFromLlm,
12
- costReceiptFromLlmError,
13
- maximumChargeForLlmRequest
14
- } from "./chunk-NJC7U437.js";
15
- import {
16
- CostLedger
17
- } from "./chunk-JHOJHHU7.js";
18
- import {
19
- NotFoundError
20
- } from "./chunk-ONWEPEDO.js";
21
-
22
- // src/locked-jsonl-appender.ts
23
- import { appendFileSync, existsSync, mkdirSync } from "fs";
24
- import { dirname } from "path";
25
- var mutexes = /* @__PURE__ */ new Map();
26
- function getMutex(path) {
27
- let m = mutexes.get(path);
28
- if (!m) {
29
- m = new Mutex();
30
- mutexes.set(path, m);
31
- }
32
- return m;
33
- }
34
- var LockedJsonlAppender = class {
35
- constructor(path) {
36
- this.path = path;
37
- this.mutex = getMutex(path);
38
- if (!existsSync(dirname(path))) {
39
- mkdirSync(dirname(path), { recursive: true });
40
- }
41
- }
42
- path;
43
- mutex;
44
- async append(entry) {
45
- const line = `${JSON.stringify(entry)}
46
- `;
47
- await this.mutex.runExclusive(() => {
48
- appendFileSync(this.path, line);
49
- });
50
- }
51
- };
52
-
53
- // src/analyst/findings-store.ts
54
- import { existsSync as existsSync2, readFileSync } from "fs";
55
- var FindingsStore = class {
56
- constructor(path) {
57
- this.path = path;
58
- this.appender = new LockedJsonlAppender(path);
59
- }
60
- path;
61
- appender;
62
- async append(runId, findings) {
63
- for (const f of findings) {
64
- const row = { ...f, run_id: runId };
65
- await this.appender.append(row);
66
- }
67
- }
68
- /** Load every persisted finding. Discards malformed trailing lines silently. */
69
- loadAll() {
70
- if (!existsSync2(this.path)) return [];
71
- const raw = readFileSync(this.path, "utf8");
72
- if (!raw) return [];
73
- const out = [];
74
- for (const line of raw.split("\n")) {
75
- if (!line) continue;
76
- try {
77
- out.push(JSON.parse(line));
78
- } catch {
79
- }
80
- }
81
- return out;
82
- }
83
- /** Filter to a single run. */
84
- loadRun(runId) {
85
- return this.loadAll().filter((r) => r.run_id === runId);
86
- }
87
- };
88
- function defaultIsMaterial(a, b) {
89
- if (a.severity !== b.severity) return true;
90
- if (Math.abs((a.confidence ?? 0) - (b.confidence ?? 0)) > 0.05) return true;
91
- if (a.evidence_refs.length !== b.evidence_refs.length) return true;
92
- return false;
93
- }
94
- function diffFindings(previous, current, policy = {}) {
95
- const isMaterial = policy.isMaterial ?? defaultIsMaterial;
96
- const prevById = new Map(previous.map((f) => [f.finding_id, f]));
97
- const curById = new Map(current.map((f) => [f.finding_id, f]));
98
- const appeared = [];
99
- const disappeared = [];
100
- const persisted = [];
101
- const changed = [];
102
- for (const [id, cur] of curById) {
103
- const prev = prevById.get(id);
104
- if (!prev) {
105
- appeared.push(cur);
106
- continue;
107
- }
108
- if (isMaterial(prev, cur)) {
109
- changed.push({ previous: prev, current: cur });
110
- } else {
111
- persisted.push(cur);
112
- }
113
- }
114
- for (const [id, prev] of prevById) {
115
- if (!curById.has(id)) disappeared.push(prev);
116
- }
117
- return { appeared, disappeared, persisted, changed };
118
- }
119
-
120
- // src/analyst/kinds/skill-usage.ts
121
- import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
122
- import { join } from "path";
123
- var BLOAT_LINE_THRESHOLD = 300;
124
- var TANGLE_PRIVATE_RE = /\b(cli-bridge|tangletools|ops-board|drew-gtr-pro|@tangle-network\/|~\/company|tangle\.tools|gtm-agent)\b|\bkimi\b|\btcloud\b/gi;
125
- var TRIGGER_RE = /triggers?\s*[:-]/i;
126
- function listSkillDirs(root) {
127
- if (!existsSync3(root)) return [];
128
- const out = [];
129
- for (const entry of readdirSync(root, { withFileTypes: true })) {
130
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
131
- const skillMd = join(root, entry.name, "SKILL.md");
132
- if (existsSync3(skillMd)) out.push({ name: entry.name, path: skillMd });
133
- }
134
- return out;
135
- }
136
- function walkJsonl(dir, cap) {
137
- if (!existsSync3(dir)) return [];
138
- const files = [];
139
- const stack = [dir];
140
- while (stack.length) {
141
- const cur = stack.pop();
142
- let entries;
143
- try {
144
- entries = readdirSync(cur, { withFileTypes: true });
145
- } catch {
146
- continue;
147
- }
148
- for (const e of entries) {
149
- const full = join(cur, e.name);
150
- if (e.isDirectory()) stack.push(full);
151
- else if (e.name.endsWith(".jsonl")) {
152
- files.push(full);
153
- if (cap > 0 && files.length >= cap) return files;
154
- }
155
- }
156
- }
157
- return files;
158
- }
159
- function frontmatterDescription(body) {
160
- const fm = /^---\n([\s\S]*?)\n---/.exec(body);
161
- const block = fm?.[1] ?? "";
162
- const m = /description:\s*(.+)/i.exec(block);
163
- return m?.[1] ?? "";
164
- }
165
- function countArtifacts(roots, name, aliases) {
166
- let n = 0;
167
- for (const root of roots) {
168
- const candidates = [join(root, ".evolve", name), ...aliases.map((a) => join(root, a))];
169
- for (const dir of candidates) {
170
- if (!existsSync3(dir)) continue;
171
- try {
172
- if (statSync(dir).isDirectory()) n += readdirSync(dir).length;
173
- else n += 1;
174
- } catch {
175
- }
176
- }
177
- }
178
- return n;
179
- }
180
- function buildSkillUsageReport(config) {
181
- const skills = config.skillRoots.flatMap(
182
- ({ root, kind }) => listSkillDirs(root).map((s) => ({ ...s, kind }))
183
- );
184
- const names = skills.map((s) => s.name);
185
- const direct = new Map(names.map((n) => [n, 0]));
186
- const slash = new Map(names.map((n) => [n, 0]));
187
- const skillRe = /"skill"\s*:\s*"([a-z0-9_:-]+)"/g;
188
- const cmdRe = /<command-name>\/?([a-z0-9_:-]+)<\/command-name>/g;
189
- let transcripts = 0;
190
- for (const dir of config.transcriptDirs) {
191
- for (const file of walkJsonl(dir, config.maxTranscriptsPerDir ?? 0)) {
192
- transcripts += 1;
193
- let data;
194
- try {
195
- data = readFileSync2(file, "utf8");
196
- } catch {
197
- continue;
198
- }
199
- for (const m of data.matchAll(skillRe)) {
200
- const g = m[1];
201
- if (!g) continue;
202
- const n = g.split(":").pop() ?? g;
203
- const prev = direct.get(n);
204
- if (prev !== void 0) direct.set(n, prev + 1);
205
- }
206
- for (const m of data.matchAll(cmdRe)) {
207
- const g = m[1];
208
- if (g === void 0) continue;
209
- const prev = slash.get(g);
210
- if (prev !== void 0) slash.set(g, prev + 1);
211
- }
212
- }
213
- }
214
- const bodies = /* @__PURE__ */ new Map();
215
- for (const s of skills) {
216
- try {
217
- bodies.set(s.name, readFileSync2(s.path, "utf8"));
218
- } catch {
219
- bodies.set(s.name, "");
220
- }
221
- }
222
- const inbound = new Map(names.map((n) => [n, 0]));
223
- for (const target of names) {
224
- const ref = new RegExp(`/${target}\\b|\\[\\[${target}\\]\\]`);
225
- for (const s of skills) {
226
- if (s.name === target) continue;
227
- if (ref.test(bodies.get(s.name) ?? "")) inbound.set(target, inbound.get(target) + 1);
228
- }
229
- }
230
- const records = skills.map((s) => {
231
- const body = bodies.get(s.name) ?? "";
232
- const dir = s.path.replace(/\/SKILL\.md$/, "");
233
- return {
234
- name: s.name,
235
- kind: s.kind,
236
- path: s.path,
237
- lines: body ? body.split("\n").length : 0,
238
- directInvocations: direct.get(s.name) ?? 0,
239
- slashInvocations: slash.get(s.name) ?? 0,
240
- inboundRefs: inbound.get(s.name) ?? 0,
241
- artifactCount: countArtifacts(
242
- config.artifactRoots ?? [],
243
- s.name,
244
- config.artifactAliases?.[s.name] ?? []
245
- ),
246
- tanglePrivateRefs: (body.match(TANGLE_PRIVATE_RE) ?? []).length,
247
- hasReferencesDir: existsSync3(join(dir, "references")),
248
- hasEvalsDir: existsSync3(join(dir, "evals")),
249
- logsRuns: body.includes("skill-runs.jsonl"),
250
- hasTriggerPhrases: TRIGGER_RE.test(frontmatterDescription(body) || body.slice(0, 600))
251
- };
252
- });
253
- return { generatedFromTraces: transcripts, records };
254
- }
255
- var ANALYST_ID = "skill-usage";
256
- function finding(area, subject, claim, severity, confidence, producedAt, recommended, evidenceUri, rationale) {
257
- return {
258
- schema_version: "1.0.0",
259
- finding_id: computeFindingId({ analyst_id: ANALYST_ID, area, subject, claim }),
260
- analyst_id: ANALYST_ID,
261
- produced_at: producedAt,
262
- severity,
263
- area,
264
- claim,
265
- rationale,
266
- evidence_refs: [{ kind: "artifact", uri: evidenceUri }],
267
- recommended_action: recommended,
268
- confidence,
269
- subject
270
- };
271
- }
272
- function emitSkillUsageFindings(report, producedAt) {
273
- const out = [];
274
- for (const r of report.records) {
275
- const directTotal = r.directInvocations + r.slashInvocations;
276
- const trueUsage = directTotal + r.inboundRefs + r.artifactCount;
277
- if (trueUsage === 0) {
278
- out.push(
279
- finding(
280
- "skill-usage",
281
- r.name,
282
- `Skill '${r.name}' has zero usage across all signals (direct, slash, inbound-refs, artifacts)`,
283
- "high",
284
- 0.6,
285
- producedAt,
286
- "Confirm the skill covers a real recurring job; if not, deprecate. Zero true usage is the only deterministic deprecation candidate.",
287
- r.path,
288
- "No Skill-tool call, no slash invocation, no sibling dispatches to it, and no on-disk artifacts."
289
- )
290
- );
291
- } else if (directTotal === 0 && r.inboundRefs + r.artifactCount > 0) {
292
- out.push(
293
- finding(
294
- "skill-usage",
295
- r.name,
296
- `Skill '${r.name}' shows 0 direct invocations but is used via orchestration/artifacts (inbound=${r.inboundRefs}, artifacts=${r.artifactCount})`,
297
- "info",
298
- 0.8,
299
- producedAt,
300
- "Do NOT treat as unused \u2014 usage is real but logged under parent skills or on disk. Strengthen direct-invocation discovery only if direct use is desired.",
301
- r.path,
302
- "The Skill-tool counter undercounts orchestrated/chained leaf skills."
303
- )
304
- );
305
- }
306
- if (directTotal <= 2 && !r.hasTriggerPhrases) {
307
- out.push(
308
- finding(
309
- "discoverability",
310
- r.name,
311
- `Skill '${r.name}' is rarely invoked directly and its description has no explicit trigger phrases`,
312
- "medium",
313
- 0.7,
314
- producedAt,
315
- "Add a `Triggers:` clause with verbatim user phrases to the frontmatter description so the model auto-invokes it.",
316
- r.path
317
- )
318
- );
319
- }
320
- if (r.kind === "public" && r.tanglePrivateRefs > 0) {
321
- out.push(
322
- finding(
323
- "safety",
324
- r.name,
325
- `Public skill '${r.name}' carries ${r.tanglePrivateRefs} Tangle-private reference(s)`,
326
- "high",
327
- 0.75,
328
- producedAt,
329
- "Sanitize incidental internal refs (cli-bridge/kimi/tcloud/~company/private repos) or relocate to a private repo. Verify @tangle-network/* refs are to PUBLISHED packages before treating as a leak.",
330
- r.path
331
- )
332
- );
333
- }
334
- if (r.lines > BLOAT_LINE_THRESHOLD && !r.hasReferencesDir) {
335
- out.push(
336
- finding(
337
- "maintainability",
338
- r.name,
339
- `Skill '${r.name}' is ${r.lines} lines with no references/ split (progressive disclosure)`,
340
- "medium",
341
- 0.8,
342
- producedAt,
343
- `Split detail into references/ loaded on demand; keep SKILL.md a short overview. ${r.lines} lines load into every session's context budget.`,
344
- r.path
345
- )
346
- );
347
- }
348
- if (!r.hasEvalsDir) {
349
- out.push(
350
- finding(
351
- "data-quality",
352
- r.name,
353
- `Skill '${r.name}' ships no evals/`,
354
- "low",
355
- 0.6,
356
- producedAt,
357
- "Add evals/evals.json with >=3 scenarios proving the skill beats baseline; gives regression coverage.",
358
- r.path
359
- )
360
- );
361
- }
362
- if (!r.logsRuns) {
363
- out.push(
364
- finding(
365
- "observability",
366
- r.name,
367
- `Skill '${r.name}' never appends to .evolve/skill-runs.jsonl`,
368
- "low",
369
- 0.55,
370
- producedAt,
371
- "Append one run line to .evolve/skill-runs.jsonl on completion, or declare it a non-logging leaf, so the self-improvement loop can see it ran.",
372
- r.path
373
- )
374
- );
375
- }
376
- }
377
- return out;
378
- }
379
- var SkillUsageAnalyst = class {
380
- id = ANALYST_ID;
381
- description = "Deterministic multi-signal skill-usage analysis: flags dead skills, measurement-invisible (orchestrated) usage, discovery gaps, public-repo leaks, bloat, missing evals, and missing run-logging.";
382
- inputKind = "custom";
383
- cost = { kind: "deterministic", est_usd_per_run: 0 };
384
- version = "1.0.0";
385
- async analyze(input, ctx) {
386
- const producedAt = ctx.tags?.producedAt ?? (/* @__PURE__ */ new Date()).toISOString();
387
- ctx.log?.(
388
- `skill-usage: ${input.records.length} skills over ${input.generatedFromTraces} transcripts`
389
- );
390
- return emitSkillUsageFindings(input, producedAt);
391
- }
392
- };
393
- var SKILL_USAGE_ANALYST = new SkillUsageAnalyst();
394
-
395
- // src/run-critic.ts
396
- var DEFAULT_DRIFT_PATTERNS = [
397
- /https?:\/\//i,
398
- /\btitle:\s/i,
399
- /\bsummary:\s/i,
400
- /\burl:\s/i,
401
- /\bnpm package usage\b/i,
402
- /\bnews\b/i
403
- ];
404
- var RunCritic = class {
405
- weights;
406
- driftPatterns;
407
- constructor(options = {}) {
408
- this.weights = options.weights;
409
- this.driftPatterns = options.driftPatterns ?? DEFAULT_DRIFT_PATTERNS;
410
- }
411
- async score(store, runId) {
412
- const run = await store.getRun(runId);
413
- if (!run) throw new NotFoundError(`run ${runId} not found`);
414
- const [spans, events, artifacts, budget] = await Promise.all([
415
- store.spans({ runId }),
416
- store.events({ runId }),
417
- store.artifacts(runId),
418
- store.budget(runId)
419
- ]);
420
- return this.scoreTrace({ run, spans, events, artifacts, budget });
421
- }
422
- scoreTrace(trace) {
423
- const notes = [];
424
- const llmSpans = trace.spans.filter(
425
- (s) => s.kind === "llm"
426
- );
427
- const toolSpans = trace.spans.filter(
428
- (s) => s.kind === "tool"
429
- );
430
- const judgeSpans = trace.spans.filter(
431
- (s) => s.kind === "judge"
432
- );
433
- const sandboxSpans = trace.spans.filter(
434
- (s) => s.kind === "sandbox"
435
- );
436
- const finalGateSpans = judgeSpans.filter(
437
- (span) => span.dimension === "final_gate" || span.attributes?.finalGate === true
438
- );
439
- const success = trace.run.outcome?.pass === true ? 1 : trace.run.status === "completed" ? 0.5 : 0;
440
- if (!success) notes.push("run did not complete with pass=true");
441
- const judgeAverage = judgeSpans.length ? judgeSpans.reduce((sum, span) => sum + normalizeJudgeScore(span.score), 0) / judgeSpans.length : void 0;
442
- const outcomeScore = typeof trace.run.outcome?.score === "number" ? clamp01(
443
- trace.run.outcome.score > 1 ? trace.run.outcome.score / 100 : trace.run.outcome.score
444
- ) : void 0;
445
- const goalProgress = outcomeScore ?? judgeAverage ?? success;
446
- const successfulTools = toolSpans.filter((span) => span.status !== "error").length;
447
- const toolUseQuality = toolSpans.length === 0 ? 0 : successfulTools / toolSpans.length;
448
- if (toolSpans.length === 0) notes.push("no tool spans recorded");
449
- const patchEvidence = trace.artifacts.length + toolSpans.filter((span) => /write|edit|patch|apply/i.test(span.toolName)).length;
450
- const patchQuality = patchEvidence > 0 ? clamp01(patchEvidence / 4) : 0;
451
- if (!patchQuality) notes.push("no artifact or edit evidence recorded");
452
- const sandboxTests = sandboxSpans.filter(
453
- (span) => typeof span.testsTotal === "number" && span.testsTotal > 0
454
- );
455
- const testReality = sandboxTests.length ? sandboxTests.reduce(
456
- (sum, span) => sum + (span.testsPassed ?? 0) / Math.max(1, span.testsTotal ?? 1),
457
- 0
458
- ) / sandboxTests.length : toolSpans.some(
459
- (span) => /\btest|vitest|pytest|jest|build|tsc\b/i.test(JSON.stringify(span.args))
460
- ) ? 0.4 : 0;
461
- if (!testReality) notes.push("no real test/build evidence recorded");
462
- const blockerSpans = judgeSpans.filter((span) => isBlockingJudge(span));
463
- const finalGateBlockers = finalGateSpans.filter((span) => isBlockingJudge(span));
464
- const finalGate = finalGateSpans.length ? finalGateBlockers.length ? 0 : 1 : success;
465
- if (finalGateBlockers.length)
466
- notes.push(`final gate blocked by ${finalGateBlockers.length} reviewer(s)`);
467
- else if (!finalGateSpans.length) notes.push("no final gate judgment recorded");
468
- const reviewerBlockers = judgeSpans.length ? blockerSpans.length / judgeSpans.length : 0;
469
- if (reviewerBlockers) notes.push(`detected ${blockerSpans.length} blocking reviewer signal(s)`);
470
- const positiveGroundingSignals = patchEvidence + sandboxSpans.length + llmSpans.filter((span) => looksRepoGrounded(span.output ?? "")).length;
471
- const driftSignals = llmSpans.filter((span) => this.isDrift(span.output ?? "")).length + trace.events.filter((event) => this.isDrift(JSON.stringify(event.payload))).length;
472
- const repoGroundedness = positiveGroundingSignals + driftSignals === 0 ? 0 : positiveGroundingSignals / (positiveGroundingSignals + driftSignals);
473
- const driftPenalty = positiveGroundingSignals + driftSignals === 0 ? 0 : driftSignals / (positiveGroundingSignals + driftSignals);
474
- if (driftSignals > 0) notes.push(`detected ${driftSignals} drift signal(s)`);
475
- const costUsd = trace.budget.length ? Math.max(
476
- ...trace.budget.filter((entry) => entry.dimension === "usd").map((entry) => entry.consumed),
477
- 0
478
- ) : llmSpans.reduce((sum, span) => sum + (span.costUsd ?? 0), 0);
479
- const wallSeconds = trace.run.endedAt && trace.run.startedAt ? Math.max(0, (trace.run.endedAt - trace.run.startedAt) / 1e3) : 0;
480
- return {
481
- success,
482
- goalProgress,
483
- repoGroundedness,
484
- driftPenalty,
485
- toolUseQuality,
486
- patchQuality,
487
- testReality,
488
- finalGate,
489
- reviewerBlockers,
490
- costUsd,
491
- wallSeconds,
492
- notes
493
- };
494
- }
495
- rank(score) {
496
- return aggregateRunScore(score, this.weights);
497
- }
498
- isDrift(text) {
499
- return this.driftPatterns.some((pattern) => pattern.test(text));
500
- }
501
- };
502
- function normalizeJudgeScore(score) {
503
- return score > 1 ? clamp01(score / 10) : clamp01(score);
504
- }
505
- function looksRepoGrounded(text) {
506
- return /(?:src\/|tests?\/|package\.json|tsconfig|\.ts\b|\.tsx\b|git status|pnpm |npm |vitest|pytest|jest)/i.test(
507
- text
508
- );
509
- }
510
- function isBlockingJudge(span) {
511
- return span.attributes?.blocking === true || span.attributes?.verdict === "BLOCKING" || positiveNumber(span.attributes?.blockingFindings) || positiveNumber(span.attributes?.highFindings) || span.score <= 2;
512
- }
513
- function positiveNumber(value) {
514
- return typeof value === "number" && value > 0;
515
- }
516
-
517
- // src/semantic-concept-judge.ts
518
- var DEFAULT_COMPLEXITY_WEIGHTS = {
519
- render: 1,
520
- integrate: 2,
521
- compute: 2.5
522
- };
523
- var SEMANTIC_CONCEPT_JUDGE_VERSION = "semantic-concept-judge-v1-2026-04-24";
524
- var DEFAULT_MAX_SOURCE = 45e3;
525
- var DEFAULT_MAX_HTML = 3e4;
526
- var DEFAULT_MAX_PER_FILE = 2e4;
527
- var DEFAULT_TIMEOUT = 3e5;
528
- var DEFAULT_MAX_TOKENS = 16e3;
529
- var DEFAULT_MODEL = "claude-sonnet-4-6";
530
- var SEMANTIC_SCHEMA = {
531
- type: "object",
532
- additionalProperties: false,
533
- required: ["summary", "concepts"],
534
- properties: {
535
- summary: { type: "string", minLength: 20, maxLength: 600 },
536
- concepts: {
537
- type: "array",
538
- minItems: 1,
539
- items: {
540
- type: "object",
541
- additionalProperties: false,
542
- required: ["concept", "present", "score", "evidence", "severity"],
543
- properties: {
544
- concept: { type: "string", minLength: 1, maxLength: 120 },
545
- present: { type: "boolean" },
546
- score: { type: "number", minimum: 0, maximum: 10 },
547
- evidence: { type: "string", minLength: 5, maxLength: 400 },
548
- severity: { type: "string", enum: ["critical", "major", "minor", "info"] }
549
- }
550
- }
551
- }
552
- }
553
- };
554
- function truncate(body, cap, label) {
555
- if (body.length <= cap) return body;
556
- return `${body.slice(0, cap)}
557
- \u2026 [truncated ${body.length - cap} chars of ${label}]`;
558
- }
559
- function buildPrompt(input, opts) {
560
- const sourceBlob = input.sourceFiles.filter((f) => f.content.length <= opts.maxPerFileChars).map((f) => `--- FILE: ${f.path} ---
561
- ${f.content}`).join("\n\n");
562
- const html = input.servedHtml ?? "";
563
- return `You are a strict code-review judge evaluating whether an agent's 0-to-1 build actually implements the features the user asked for.
564
-
565
- You MUST distinguish:
566
- (a) WORKING code that implements the concept (rendered UI, wired handler, real API call),
567
- (b) KEYWORD-PRESENT stub (comments mentioning the concept, variable names, TODOs),
568
- (c) ABSENT (concept nowhere).
569
-
570
- A comment like "// TODO: add mint button" is NOT present \u2014 score 2-3. Only count a concept as present if there is real functional code: a rendered component, a call handler wired to state or a network call, a computed value actually used.
571
-
572
- USER REQUEST (what the agent was asked to build):
573
- ${input.userRequest}
574
-
575
- ${input.artifactLabel ? `ARTIFACT METADATA:
576
- name: ${input.artifactLabel}
577
- description: ${input.artifactDescription ?? ""}
578
-
579
- ` : ""}EXPECTED CONCEPTS (each must be graded independently):
580
- ${input.expectedConcepts.map(
581
- (c, i) => ` ${i + 1}. "${c.name}"${c.keywords?.length ? ` \u2014 hints: [${c.keywords.slice(0, 6).join(" | ")}]` : ""}`
582
- ).join("\n")}
583
-
584
- ${html ? `SERVED HTML (what the preview returns when hit):
585
- ${truncate(html, opts.maxHtmlChars, "HTML")}
586
-
587
- ` : ""}SOURCE FILES (the agent's workdir):
588
- ${truncate(sourceBlob, opts.maxSourceChars, "source")}
589
-
590
- For EACH concept, return:
591
- - concept: the concept name as given (match exactly)
592
- - present: boolean \u2014 does a working implementation exist?
593
- - score: 0-10 \u2014 10 = production-ready; 7 = functional but thin; 4 = partial/stubbed; 2 = keyword-only comment; 0 = absent
594
- - evidence: cite "<file>:<line>" or "served-html:<selector>" pointing at the strongest supporting code. If the concept is absent or stubbed, explain what's missing.
595
- - severity:
596
- "info" when present: true AND score >= 7
597
- "minor" when present: true AND 4 <= score < 7
598
- "major" when present: false OR score < 4
599
- "critical" when the concept is not only absent but a core user flow depends on it
600
-
601
- Also produce a "summary" (one sentence, 20-600 chars): overall verdict on whether this is a shippable implementation of the user request vs a keyword-dense placeholder.
602
-
603
- BE SKEPTICAL. Keyword matching already passed \u2014 your job is to catch what keyword matching misses. If the agent shipped a working build, say so. If it shipped a stub, say so. Don't grade on effort.
604
-
605
- Return STRICT JSON. No prose outside the JSON.`;
606
- }
607
- async function runSemanticConceptJudge(input, options = {}) {
608
- const start = Date.now();
609
- const totalCount = input.expectedConcepts.length;
610
- if (totalCount === 0) {
611
- return {
612
- kind: "semantic-concept",
613
- version: SEMANTIC_CONCEPT_JUDGE_VERSION,
614
- score: 0,
615
- presentCount: 0,
616
- totalCount: 0,
617
- findings: [],
618
- summary: "no expected concepts declared",
619
- durationMs: 0,
620
- costUsd: null,
621
- available: false,
622
- error: "no expected concepts declared"
623
- };
624
- }
625
- const opts = {
626
- model: options.model ?? DEFAULT_MODEL,
627
- timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT,
628
- maxTokens: options.maxTokens ?? DEFAULT_MAX_TOKENS,
629
- maxSourceChars: options.maxSourceChars ?? DEFAULT_MAX_SOURCE,
630
- maxPerFileChars: options.maxPerFileChars ?? DEFAULT_MAX_PER_FILE,
631
- maxHtmlChars: options.maxHtmlChars ?? DEFAULT_MAX_HTML,
632
- llm: options.llm ?? {},
633
- costLedger: options.costLedger ?? new CostLedger(),
634
- costPhase: options.costPhase ?? "judge.semantic-concept",
635
- signal: options.signal ?? new AbortController().signal,
636
- weightConcepts: options.weightConcepts ?? "mean",
637
- complexityWeights: { ...DEFAULT_COMPLEXITY_WEIGHTS, ...options.complexityWeights ?? {} }
638
- };
639
- const weightForConcept = (spec) => {
640
- if (opts.weightConcepts === "mean") return 1;
641
- if (spec.weight != null) return spec.weight;
642
- if (opts.weightConcepts === "complexity") {
643
- return opts.complexityWeights[spec.complexity ?? "render"] ?? 1;
644
- }
645
- return 1;
646
- };
647
- const weightByName = new Map(
648
- input.expectedConcepts.map((c) => [c.name, weightForConcept(c)])
649
- );
650
- let receipt;
651
- try {
652
- const request = {
653
- model: opts.model,
654
- messages: [
655
- {
656
- role: "system",
657
- content: "You are a strict code-review judge. Return strict JSON only. No prose outside the JSON. A keyword in a comment is NOT a working implementation."
658
- },
659
- { role: "user", content: buildPrompt(input, opts) }
660
- ],
661
- jsonSchema: { name: "semantic_concept_judge", schema: SEMANTIC_SCHEMA },
662
- temperature: 0,
663
- maxTokens: opts.maxTokens,
664
- timeoutMs: opts.timeoutMs
665
- };
666
- const paid = await opts.costLedger.runPaidCall({
667
- channel: "judge",
668
- phase: opts.costPhase,
669
- actor: "semantic-concept",
670
- model: opts.model,
671
- maximumCharge: maximumChargeForLlmRequest(request, opts.llm),
672
- signal: opts.signal,
673
- execute: (signal, callId) => callLlmJson(request, {
674
- ...opts.llm,
675
- signal,
676
- idempotencyKey: callId
677
- }),
678
- receipt: ({ result }) => costReceiptFromLlm(result),
679
- receiptFromError: costReceiptFromLlmError
680
- });
681
- receipt = paid.receipt;
682
- if (!paid.succeeded) throw paid.error;
683
- const { value } = paid.value;
684
- if (!value?.concepts || !Array.isArray(value.concepts)) {
685
- throw new Error('judge returned malformed response \u2014 expected array under "concepts"');
686
- }
687
- const findings = value.concepts.map((c) => ({
688
- concept: String(c.concept),
689
- present: Boolean(c.present),
690
- score: Math.max(0, Math.min(10, Number(c.score ?? 0))),
691
- evidence: String(c.evidence ?? ""),
692
- severity: ["critical", "major", "minor", "info"].includes(c.severity) ? c.severity : "info"
693
- }));
694
- const presentCount = findings.filter((f) => f.present && f.score >= 7).length;
695
- let weightSum = 0;
696
- let weightedScoreSum = 0;
697
- for (const f of findings) {
698
- const w = weightByName.get(f.concept) ?? 1;
699
- weightSum += w;
700
- weightedScoreSum += w * f.score;
701
- }
702
- const scoreAvg = weightSum > 0 ? weightedScoreSum / weightSum : findings.reduce((a, f) => a + f.score, 0) / Math.max(1, findings.length);
703
- return {
704
- kind: "semantic-concept",
705
- version: SEMANTIC_CONCEPT_JUDGE_VERSION,
706
- score: Number((scoreAvg / 10).toFixed(3)),
707
- presentCount,
708
- totalCount,
709
- findings,
710
- summary: String(value.summary ?? ""),
711
- durationMs: Date.now() - start,
712
- costUsd: paid.receipt.costUnknown ? null : paid.receipt.costUsd,
713
- available: true
714
- };
715
- } catch (err) {
716
- return {
717
- kind: "semantic-concept",
718
- version: SEMANTIC_CONCEPT_JUDGE_VERSION,
719
- score: 0,
720
- presentCount: 0,
721
- totalCount,
722
- findings: [],
723
- summary: "",
724
- durationMs: Date.now() - start,
725
- costUsd: receipt && !receipt.costUnknown ? receipt.costUsd : null,
726
- available: false,
727
- error: err instanceof Error ? err.message : String(err)
728
- };
729
- }
730
- }
731
- function createSemanticConceptJudge(options = {}) {
732
- return (input) => runSemanticConceptJudge(input, options);
733
- }
734
-
735
- export {
736
- LockedJsonlAppender,
737
- FindingsStore,
738
- defaultIsMaterial,
739
- diffFindings,
740
- buildSkillUsageReport,
741
- emitSkillUsageFindings,
742
- SkillUsageAnalyst,
743
- SKILL_USAGE_ANALYST,
744
- RunCritic,
745
- DEFAULT_COMPLEXITY_WEIGHTS,
746
- SEMANTIC_CONCEPT_JUDGE_VERSION,
747
- runSemanticConceptJudge,
748
- createSemanticConceptJudge
749
- };
750
- //# sourceMappingURL=chunk-JM2SKQMS.js.map