aiinfra-tools 0.3.0 → 0.5.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 (65) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +43 -0
  3. package/bin/aiinfra.mjs +12 -0
  4. package/fleetops/deploy/grafana-dashboard.json +71 -0
  5. package/fleetops/deploy/shadow-live/README.md +8 -0
  6. package/fleetops/deploy/shadow-live/kit.yaml +2 -0
  7. package/fleetops/deploy/shadow-live/run.sh +6 -1
  8. package/fleetops/docs/SHADOW.md +25 -2
  9. package/fleetops/package.json +1 -1
  10. package/fleetops/src/api.mjs +8 -0
  11. package/fleetops/src/ingest.mjs +9 -2
  12. package/fleetops/src/schema.mjs +3 -0
  13. package/fleetops/src/serving.mjs +11 -1
  14. package/fleetops/src/shadow-quality.mjs +107 -0
  15. package/fleetops/src/shadow.mjs +12 -6
  16. package/fleetops/tools/cmd/help.mjs +4 -1
  17. package/fleetops/tools/cmd/shadow.mjs +14 -2
  18. package/fleetscope/build.mjs +4 -0
  19. package/fleetscope/dist/index.html +809 -4
  20. package/fleetscope/package.json +1 -1
  21. package/fleetscope/src/engine.js +19 -2
  22. package/fleetscope/src/index.src.html +23 -1
  23. package/gpu-health/package.json +1 -1
  24. package/gpu-ledger/package.json +1 -1
  25. package/harness-ledger/README.md +48 -0
  26. package/harness-ledger/integrations/README.md +11 -0
  27. package/harness-ledger/integrations/claude-code/aiinfra-hook.mjs +113 -0
  28. package/harness-ledger/integrations/claude-code/aiinfra-statusline.mjs +35 -0
  29. package/harness-ledger/integrations/litellm/aiinfra_prefix_lint.py +247 -0
  30. package/harness-ledger/package.json +1 -1
  31. package/harness-ledger/src/advise.mjs +410 -0
  32. package/harness-ledger/src/assess.mjs +66 -0
  33. package/harness-ledger/src/doctor.mjs +202 -0
  34. package/harness-ledger/src/engine-metrics.mjs +35 -0
  35. package/harness-ledger/src/importers.mjs +14 -3
  36. package/harness-ledger/src/lint.mjs +115 -0
  37. package/harness-ledger/src/mooncake.mjs +83 -0
  38. package/harness-ledger/src/profile.mjs +164 -0
  39. package/harness-ledger/src/record.mjs +2 -2
  40. package/harness-ledger/src/suggest.mjs +177 -0
  41. package/harness-ledger/src/trajectory.mjs +81 -0
  42. package/harness-ledger/src/workload-demo.mjs +100 -0
  43. package/harness-ledger/tools/harness-ledger.mjs +224 -5
  44. package/hybrid-tracing/package.json +1 -1
  45. package/inference-sizer/build.mjs +1 -0
  46. package/inference-sizer/dist/index.html +192 -17
  47. package/inference-sizer/docs/CATALOG.md +71 -0
  48. package/inference-sizer/docs/METHOD.md +1 -1
  49. package/inference-sizer/package.json +1 -1
  50. package/inference-sizer/src/accelerators.js +23 -1
  51. package/inference-sizer/src/catalog.js +49 -3
  52. package/inference-sizer/src/index.src.html +7 -0
  53. package/inference-sizer/src/model.js +29 -9
  54. package/inference-sizer/src/suggest.js +70 -0
  55. package/inference-sizer/src/ui.js +14 -4
  56. package/inference-sizer/tools/validate-agentx.mjs +8 -2
  57. package/inference-sizer/tools/validate-inferencex.mjs +1 -1
  58. package/mcp/README.md +3 -0
  59. package/mcp/server.mjs +22 -0
  60. package/package.json +3 -1
  61. package/schemas/README.md +3 -0
  62. package/schemas/commands.mjs +7 -0
  63. package/schemas/harness-ledger.advise.schema.json +1102 -0
  64. package/schemas/harness-ledger.assess.schema.json +2823 -0
  65. package/schemas/harness-ledger.suggest.schema.json +326 -0
@@ -0,0 +1,107 @@
1
+ // The quality gate: replay real evaluation tasks on the baseline and the candidate endpoint and block the change when
2
+ // the candidate solves fewer of them. Latency checks say whether a change is faster; this says whether it still does
3
+ // the work (a quantized model, a capped tool output, a compacted context or a new model can all change answers).
4
+ //
5
+ // Tasks, one JSON object per line:
6
+ // { "id": "t1", "prompt": "…" | "messages": [ … ], "check": { "type": "contains", "value": "Paris" }, "maxTokens": 256 }
7
+ // Checks (on the answer text):
8
+ // contains / not-contains a substring (case-insensitive unless "case": true)
9
+ // regex a regular expression ("flags" optional)
10
+ // exact the whole answer, trimmed
11
+ // number the last number in the answer within "tol" (absolute, default 0) of "value"
12
+ // json the answer (or its first {…} block) parses as JSON; with "value", every key in value matches
13
+ // Both arms answer every task at temperature 0. The comparison is paired: each task is solved by both, neither, or one
14
+ // of the two, and only the tasks where they disagree carry information. The verdict is a non-inferiority test on the
15
+ // difference in success rate: the candidate passes when the lower 95% bound of (candidate − baseline) is above
16
+ // −maxDrop. Nothing is sent without --live; only task ids, pass/fail and counts are kept (no prompts or answers).
17
+ export const DEFAULTS = { maxDrop: 0.02, minTasks: 20, maxTokens: 512, concurrency: 8, timeoutS: 300 };
18
+
19
+ export function loadTasks(text) {
20
+ const tasks = [];
21
+ String(text).split(/\r?\n/).forEach((l, i) => {
22
+ const s = l.trim(); if (!s || s.startsWith('#')) return;
23
+ let t; try { t = JSON.parse(s); } catch { throw new Error(`tasks line ${i + 1}: not JSON`); }
24
+ if (!t.prompt && !Array.isArray(t.messages)) throw new Error(`tasks line ${i + 1}: needs "prompt" or "messages"`);
25
+ if (!t.check || !CHECKS[t.check.type]) throw new Error(`tasks line ${i + 1}: "check.type" one of ${Object.keys(CHECKS).join(', ')}`);
26
+ tasks.push({ id: String(t.id ?? `task-${i + 1}`), prompt: t.prompt, messages: t.messages, check: t.check, maxTokens: t.maxTokens });
27
+ });
28
+ const ids = new Set(); for (const t of tasks) { if (ids.has(t.id)) throw new Error(`tasks: duplicate id ${t.id}`); ids.add(t.id); }
29
+ return tasks;
30
+ }
31
+
32
+ const lastNumber = s => { const m = String(s).replace(/,(?=\d{3}\b)/g, '').match(/-?\d+(?:\.\d+)?(?:e[-+]?\d+)?/gi); return m ? Number(m[m.length - 1]) : null; };
33
+ const jsonOf = s => { try { return JSON.parse(s); } catch { const m = String(s).match(/\{[\s\S]*\}/); if (!m) return undefined; try { return JSON.parse(m[0]); } catch { return undefined; } } };
34
+ const subset = (want, got) => (want && typeof want === 'object' ? got != null && typeof got === 'object' && Object.keys(want).every(k => subset(want[k], got[k])) : want === got);
35
+ export const CHECKS = {
36
+ contains: (a, c) => (c.case ? a.includes(String(c.value)) : a.toLowerCase().includes(String(c.value).toLowerCase())),
37
+ 'not-contains': (a, c) => !CHECKS.contains(a, c),
38
+ regex: (a, c) => new RegExp(c.value, c.flags || '').test(a),
39
+ exact: (a, c) => a.trim() === String(c.value).trim(),
40
+ number: (a, c) => { const x = lastNumber(a); return x != null && Math.abs(x - Number(c.value)) <= Number(c.tol || 0); },
41
+ json: (a, c) => { const j = jsonOf(a); return j !== undefined && (c.value === undefined || subset(c.value, j)); },
42
+ };
43
+ export const check = (answer, chk) => CHECKS[chk.type](String(answer ?? ''), chk);
44
+
45
+ // one answer from an OpenAI-compatible endpoint (vLLM, SGLang, a gateway): chat completions, or plain completions
46
+ export async function ask(arm, task, { model, maxTokens = DEFAULTS.maxTokens, completions = false, fetchImpl = fetch, timeoutS = DEFAULTS.timeoutS } = {}) {
47
+ const headers = { 'content-type': 'application/json' }; if (arm.apiKey) headers.authorization = `Bearer ${arm.apiKey}`;
48
+ const base = { model: arm.model || model, max_tokens: task.maxTokens || maxTokens, temperature: 0, seed: 0 };
49
+ const prompt = task.prompt ?? task.messages.map(m => `${m.role}: ${typeof m.content === 'string' ? m.content : JSON.stringify(m.content)}`).join('\n');
50
+ const body = completions ? { ...base, prompt } : { ...base, messages: task.messages || [{ role: 'user', content: task.prompt }] };
51
+ const ac = new AbortController(), timer = setTimeout(() => ac.abort(), timeoutS * 1000);
52
+ try {
53
+ const res = await fetchImpl(arm.url.replace(/\/$/, '') + (completions ? '/v1/completions' : '/v1/chat/completions'), { method: 'POST', headers, body: JSON.stringify(body), signal: ac.signal });
54
+ if (!res.ok) return { error: `HTTP ${res.status}` };
55
+ const j = await res.json(), c = j.choices && j.choices[0];
56
+ return { text: c ? (completions ? c.text : c.message && c.message.content) ?? '' : '' };
57
+ } catch (e) { return { error: e.name === 'AbortError' ? 'timeout' : e.message }; } finally { clearTimeout(timer); }
58
+ }
59
+
60
+ // paired success rates. results: [{ id, baseline: bool, candidate: bool }]. The interval on the difference uses the
61
+ // discordant counts (lost: baseline solved it and the candidate didn't; gained: the reverse), with half a count added
62
+ // to each so that a run with no disagreements still has a width.
63
+ export function pairedQuality(results, { maxDrop = DEFAULTS.maxDrop, minTasks = DEFAULTS.minTasks } = {}) {
64
+ const n = results.length, bp = results.filter(r => r.baseline).length, cp = results.filter(r => r.candidate).length;
65
+ const lost = results.filter(r => r.baseline && !r.candidate).length, gained = results.filter(r => !r.baseline && r.candidate).length;
66
+ const diff = n ? (cp - bp) / n : 0;
67
+ const b = lost + 0.5, c = gained + 0.5, m = n + 1, d = (c - b) / m, se = Math.sqrt(Math.max(0, b + c - (c - b) ** 2 / m)) / m;
68
+ const lo = d - 1.96 * se, hi = d + 1.96 * se;
69
+ let verdict, why, more = 0;
70
+ if (n < minTasks) { verdict = 'inconclusive'; why = `${n} tasks: at least ${minTasks} are needed to judge`; more = minTasks - n; }
71
+ else if (lo > 0) { verdict = 'better'; why = `the candidate solves more tasks (+${(100 * diff).toFixed(1)} points)`; }
72
+ else if (lo >= -maxDrop) { verdict = 'same'; why = `no drop past ${(100 * maxDrop).toFixed(1)} points (95% bound ${(100 * lo).toFixed(1)})`; }
73
+ else if (hi < -maxDrop || (hi < 0 && diff <= -maxDrop)) { verdict = 'worse'; why = `the candidate solves fewer tasks (${(100 * diff).toFixed(1)} points; ${lost} lost, ${gained} gained)`; }
74
+ else {
75
+ verdict = 'inconclusive'; why = `the drop could be up to ${(100 * -lo).toFixed(1)} points: more tasks needed`;
76
+ const margin = Math.max(0.002, d + maxDrop); more = Math.max(1, Math.ceil(n * ((1.96 * se) / margin) ** 2 - n));
77
+ }
78
+ return { n, baseline: { passed: bp, rate: n ? bp / n : 0 }, candidate: { passed: cp, rate: n ? cp / n : 0 }, lost, gained, diff, lo, hi, maxDrop, verdict, why, more };
79
+ }
80
+
81
+ async function pool(items, k, f) { const out = new Array(items.length); let i = 0; await Promise.all(Array.from({ length: Math.min(k, items.length) }, async () => { while (i < items.length) { const j = i++; out[j] = await f(items[j], j); } })); return out; }
82
+
83
+ export async function runQuality(tasks, arms, { live = false, model, maxTokens, completions = false, concurrency = DEFAULTS.concurrency, maxDrop = DEFAULTS.maxDrop, minTasks = DEFAULTS.minTasks, fetchImpl = fetch, timeoutS } = {}) {
84
+ if (arms.length !== 2) throw new Error('two endpoints: baseline and candidate');
85
+ if (!live) return { dryRun: true, tasks: tasks.length, arms: arms.map(a => a.name), note: `${tasks.length} tasks × 2 endpoints at temperature 0 (${completions ? '/v1/completions' : '/v1/chat/completions'})` };
86
+ const [A, B] = arms;
87
+ const rows = await pool(tasks, concurrency, async t => {
88
+ const [a, b] = await Promise.all([ask(A, t, { model, maxTokens, completions, fetchImpl, timeoutS }), ask(B, t, { model, maxTokens, completions, fetchImpl, timeoutS })]);
89
+ return { id: t.id, baseline: !a.error && check(a.text, t.check), candidate: !b.error && check(b.text, t.check), errors: [a.error && 'baseline', b.error && 'candidate'].filter(Boolean) };
90
+ });
91
+ const q = pairedQuality(rows, { maxDrop, minTasks });
92
+ const errs = k => rows.filter(r => r.errors.includes(k)).length;
93
+ q.baseline.errors = errs('baseline'); q.candidate.errors = errs('candidate');
94
+ return Object.assign({ kind: 'fleetops.shadow-quality', dryRun: false, t: Math.floor(Date.now() / 1000) }, q, {
95
+ changed: rows.filter(r => r.baseline !== r.candidate).map(r => ({ id: r.id, baseline: r.baseline, candidate: r.candidate })) });
96
+ }
97
+
98
+ export function qualityText(q) {
99
+ if (q.dryRun) return `dry run: ${q.note}. Add --live to send them.`;
100
+ const L = [`quality: ${q.verdict.toUpperCase()}: ${q.why}`,
101
+ ` ${q.n} tasks; baseline solved ${q.baseline.passed} (${(100 * q.baseline.rate).toFixed(1)}%), candidate ${q.candidate.passed} (${(100 * q.candidate.rate).toFixed(1)}%)`,
102
+ ` difference ${(100 * q.diff).toFixed(1)} points (95% CI ${(100 * q.lo).toFixed(1)} to ${(100 * q.hi).toFixed(1)}); ${q.lost} lost, ${q.gained} gained; gate: no drop past ${(100 * q.maxDrop).toFixed(1)} points`];
103
+ if (q.baseline.errors || q.candidate.errors) L.push(` endpoint errors (counted as failures): baseline ${q.baseline.errors}, candidate ${q.candidate.errors}`);
104
+ if (q.verdict === 'inconclusive' && q.more) L.push(` about ${q.more} more tasks would settle it`);
105
+ if (q.changed && q.changed.length) L.push(` tasks that changed: ${q.changed.slice(0, 12).map(x => `${x.id} ${x.baseline ? 'lost' : 'gained'}`).join(', ')}${q.changed.length > 12 ? ` and ${q.changed.length - 12} more` : ''}`);
106
+ return L.join('\n');
107
+ }
@@ -133,9 +133,12 @@ export function compare(base0, cand0, opt = {}) {
133
133
  for (const [k, p] of Object.entries(opt.predicted)) { const m = metrics[k]; const meas = m ? (m.effect ?? null) : null; if (meas == null || !Number.isFinite(p)) continue; rows.push({ metric: k, predicted: p, measured: meas, off: (1 + meas) / (1 + p) - 1 }); }
134
134
  prediction = { rows, holds: rows.every(r => Math.abs(r.off) <= G.prediction) };
135
135
  }
136
- const d = decide(metrics, answers, prediction);
137
- // answers, prediction and infra appear only when given: absent rather than null, so their shape is part of the --json contract
138
- return Object.assign({ decision: d.decision, why: d.why, paired, requests: { baseline: base.length, candidate: cand.length }, metrics, gates: G }, answers ? { answers } : {}, prediction ? { prediction } : {}, opt.infra ? { infra: opt.infra } : {});
136
+ const quality = opt.quality && !opt.quality.dryRun ? opt.quality : null;
137
+ const d = decide(metrics, answers, prediction, { quality });
138
+ // answers, prediction, quality and infra appear only when given: absent rather than null, so their shape is part of the --json contract
139
+ return Object.assign({ decision: d.decision, why: d.why, paired, requests: { baseline: base.length, candidate: cand.length }, metrics, gates: G }, answers ? { answers } : {}, prediction ? { prediction } : {},
140
+ quality ? { quality: { n: quality.n, baseline: quality.baseline, candidate: quality.candidate, lost: quality.lost, gained: quality.gained, diff: quality.diff, lo: quality.lo, hi: quality.hi, maxDrop: quality.maxDrop, verdict: quality.verdict, why: quality.why } } : {},
141
+ opt.infra ? { infra: opt.infra } : {});
139
142
  }
140
143
 
141
144
  // errors: a difference in rate past the gate, by a one-sided two-proportion test. eb, ec: { n, k } (requests, errors)
@@ -145,15 +148,18 @@ export function errorTest(eb, ec, gate = GATES.errorRate) {
145
148
  }
146
149
 
147
150
  // promote / roll back / extend the test, from the metric verdicts (and answers and the prediction when there are any)
148
- export function decide(metrics, answers = null, prediction = null, { unit = 'requests per arm' } = {}) {
151
+ // quality: a quality-gate result (shadow-quality.mjs): fewer tasks solved rolls back, an unsettled result extends the test
152
+ export function decide(metrics, answers = null, prediction = null, { unit = 'requests per arm', quality = null } = {}) {
149
153
  const vs = Object.entries(metrics).filter(([, m]) => m && m.verdict);
150
154
  const worse = vs.filter(([, m]) => m.verdict === 'worse').map(([k]) => k), open = vs.filter(([, m]) => m.verdict === 'inconclusive').map(([k]) => k);
151
155
  let decision, why;
152
- if (answers && answers.verdict === 'different') { decision = 'roll back'; why = `answers differ (${(100 * answers.matchRate).toFixed(1)}% identical under greedy decoding)`; }
156
+ if (quality && quality.verdict === 'worse') { decision = 'roll back'; why = `quality: ${quality.why}`; }
157
+ else if (answers && answers.verdict === 'different') { decision = 'roll back'; why = `answers differ (${(100 * answers.matchRate).toFixed(1)}% identical under greedy decoding)`; }
153
158
  else if (worse.length) { decision = 'roll back'; why = `worse on ${worse.join(', ')}`; }
154
159
  else if (open.length) { decision = 'extend the test'; why = `not settled on ${open.join(', ')}: about ${Math.max(...open.map(k => metrics[k].more || 0))} more ${unit}`; }
155
160
  else if (['ttft', 'tpot', 'e2e'].every(k => !metrics[k] || metrics[k].verdict === 'no data')) { decision = 'extend the test'; why = 'no latency data to judge yet'; }
156
- else { decision = 'promote'; why = `no metric worse${vs.some(([, m]) => m.verdict === 'better') ? `; better on ${vs.filter(([, m]) => m.verdict === 'better').map(([k]) => k).join(', ')}` : ''}`; }
161
+ else if (quality && quality.verdict === 'inconclusive') { decision = 'extend the test'; why = `quality not settled: ${quality.why}`; }
162
+ else { decision = 'promote'; why = `no metric worse${vs.some(([, m]) => m.verdict === 'better') ? `; better on ${vs.filter(([, m]) => m.verdict === 'better').map(([k]) => k).join(', ')}` : ''}${quality ? `; quality ${quality.verdict} on ${quality.n} tasks` : ''}`; }
157
163
  if (prediction && !prediction.holds) why += '; the prediction was off: recalibrate the sizer for this change';
158
164
  return { decision, why };
159
165
  }
@@ -170,8 +170,11 @@ Shadow upgrades (an infra change measured against the baseline at matched load b
170
170
  the same requests to both endpoints at the same moments (dry run unless --live); results go to the store
171
171
  fleetops shadow answers --baseline URL --candidate URL [--prompts FILE] [--model M] [--live] --out answers.json
172
172
  greedy decoding on both: identical tokens, first divergence, log-probability drift
173
+ fleetops shadow quality --tasks tasks.jsonl --baseline URL --candidate URL [--model M] [--max-drop 2] [--min-tasks 20]
174
+ [--completions] [--concurrency 8] [--live] [--out quality.json]
175
+ real tasks with pass checks on both: success rates paired by task; blocks a drop past --max-drop points
173
176
  fleetops shadow compare --results FILE | --baseline SEL --candidate SEL [--from T --to T]
174
- [--plan plan.json] [--answers answers.json] [--baseline-gpus N --baseline-rate R --candidate-gpus N --candidate-rate R]
177
+ [--plan plan.json] [--answers answers.json] [--quality quality.json] [--baseline-gpus N --baseline-rate R --candidate-gpus N --candidate-rate R]
175
178
  [--baseline-nodes RE --candidate-nodes RE] [--gates gates.json] matched-load verdict: promote, roll back, extend
176
179
  with --plan: a prediction off by more than 15% refits the candidate's sizer efficiencies into
177
180
  <store>/calibration/sizer.json (--calibration F; --no-recalibrate to skip), which plan, inference-sizer --calibration
@@ -7,6 +7,7 @@ import * as Replay from '../../src/shadow-replay.mjs';
7
7
  import * as SProm from '../../src/shadow-prom.mjs';
8
8
  import * as Gate from '../../src/shadow-gate.mjs';
9
9
  import * as Canary from '../../src/shadow-canary.mjs';
10
+ import * as Quality from '../../src/shadow-quality.mjs';
10
11
  import { J, OUT, say, read, time, fmt, pctS } from './common.mjs';
11
12
 
12
13
  // ---------- shadow upgrades ----------
@@ -24,6 +25,7 @@ export function shadowText(r) {
24
25
  if (r.metrics.tokPerGpuS) L.push(` tok/s per GPU ${r.metrics.tokPerGpuS.baseline.toFixed(0)} → ${r.metrics.tokPerGpuS.candidate.toFixed(0)} (${pctS(r.metrics.tokPerGpuS.effect)}; ${r.metrics.tokPerGpuS.note})`);
25
26
  if (r.metrics.costPerMTok) L.push(` $ per M output tokens ${r.metrics.costPerMTok.baseline.toFixed(2)} → ${r.metrics.costPerMTok.candidate.toFixed(2)} (${pctS(r.metrics.costPerMTok.effect)}) ${r.metrics.costPerMTok.verdict}`);
26
27
  if (r.answers) L.push(` answers ${r.answers.identical}/${r.answers.prompts} identical under greedy decoding; log-prob drift ${r.answers.meanAbsLogprobDiff != null ? r.answers.meanAbsLogprobDiff.toFixed(3) : '–'} ${r.answers.verdict}`);
28
+ if (r.quality) L.push(` quality ${r.quality.candidate.passed}/${r.quality.n} tasks vs ${r.quality.baseline.passed}/${r.quality.n} (${pctS(r.quality.diff).replace('%', ' pts')}; ${r.quality.lost} lost, ${r.quality.gained} gained)`.padEnd(52) + ` ${r.quality.verdict}`);
27
29
  if (r.prediction) L.push('', ` prediction ${r.prediction.holds ? 'holds' : 'is off: recalibrate'}: ` + r.prediction.rows.map(x => `${x.metric} predicted ${pctS(x.predicted)}, measured ${pctS(x.measured)}`).join('; '));
28
30
  if (r.infra) L.push('', ' infra: ' + Object.entries(r.infra).map(([k, v]) => v.effect != null ? `${k} ${pctS(v.effect)}` : `${k} ${v.baseline} → ${v.candidate}`).join(', '));
29
31
  return L.join('\n');
@@ -95,13 +97,23 @@ export async function shadowCmd(store, cmd, rest, o) {
95
97
  if (J) { OUT.answers = res; return; }
96
98
  return say(res.dryRun ? `dry run: ${res.note}. Add --live to send them.` : `${res.identical}/${res.prompts} identical; first divergence at token ${res.meanFirstDivergence ?? '–'} on average; log-prob drift ${res.meanAbsLogprobDiff != null ? res.meanAbsLogprobDiff.toFixed(4) : '–'}${opt('out') ? ` → ${opt('out')}` : ''}`);
97
99
  }
100
+ if (cmd === 'quality') {
101
+ if (!opt('tasks') || !opt('baseline') || !opt('candidate')) throw new Error('--tasks FILE.jsonl --baseline URL --candidate URL [--max-drop 2] [--live]');
102
+ const tasks = Quality.loadTasks(read(opt('tasks')));
103
+ const maxDrop = num('max-drop') != null ? num('max-drop') / 100 : Quality.DEFAULTS.maxDrop;
104
+ const res = await Quality.runQuality(tasks, [arm('baseline', opt('baseline')), arm('candidate', opt('candidate'))], { live: !!o.live, model: opt('model'), maxTokens: num('max-tokens'), completions: !!o.completions,
105
+ concurrency: num('concurrency') || Quality.DEFAULTS.concurrency, maxDrop, minTasks: num('min-tasks') ?? Quality.DEFAULTS.minTasks });
106
+ if (!res.dryRun) { const f = opt('out') || path.join(dir, 'quality.json'); fs.writeFileSync(f, JSON.stringify(res, null, 1) + '\n'); res.file = f; }
107
+ if (J) { OUT.quality = res; return; }
108
+ return say(Quality.qualityText(res) + (res.file ? `\nwrote ${res.file}; fleetops shadow compare … --quality ${res.file}` : ''));
109
+ }
98
110
  if (cmd === 'compare') {
99
111
  let base, cand;
100
112
  if (opt('results')) { const rs = readJsonl(opt('results')); base = rs.filter(r => r.variant === 'baseline'); cand = rs.filter(r => r.variant === 'candidate'); }
101
113
  else { if (!opt('baseline') || !opt('candidate')) throw new Error('--results FILE, or --baseline SEL --candidate SEL'); base = requests(opt('baseline')); cand = requests(opt('candidate')); }
102
114
  if (!base.length || !cand.length) throw new Error(`no requests: ${base.length} baseline, ${cand.length} candidate`);
103
115
  const plan = json('plan'), re = k => (opt(k) ? new RegExp(opt(k)) : null);
104
- const r = Shadow.compare(base, cand, { gates: json('gates'), predicted: plan && plan.predicted, answers: json('answers'),
116
+ const r = Shadow.compare(base, cand, { gates: json('gates'), predicted: plan && plan.predicted, answers: json('answers'), quality: json('quality'),
105
117
  baseline: { gpus: num('baseline-gpus'), rate: num('baseline-rate') }, candidate: { gpus: num('candidate-gpus'), rate: num('candidate-rate') },
106
118
  infra: opt('baseline-nodes') ? Shadow.infraSignals(store, { baselineNodes: re('baseline-nodes'), candidateNodes: re('candidate-nodes'), from, to }) : null });
107
119
  fs.appendFileSync(path.join(dir, 'verdicts.jsonl'), JSON.stringify({ t: Math.floor(Date.now() / 1000), baseline: opt('baseline') || opt('results'), candidate: opt('candidate') || opt('results'), decision: r.decision, why: r.why, metrics: r.metrics, ...(r.prediction ? { prediction: r.prediction } : {}) }) + '\n');
@@ -200,5 +212,5 @@ export async function shadowCmd(store, cmd, rest, o) {
200
212
  }
201
213
  throw new Error('fleetops shadow canary start | advance | approve | status');
202
214
  }
203
- throw new Error('fleetops shadow demo | plan | replay | answers | compare | baseline save|list | watch | prom | serve | canary');
215
+ throw new Error('fleetops shadow demo | plan | replay | answers | quality | compare | baseline save|list | watch | prom | serve | canary');
204
216
  }
@@ -10,6 +10,10 @@ const read = p => readFileSync(join(here, p), 'utf8');
10
10
  const page = read('src/index.src.html');
11
11
  const inlined = {
12
12
  '/*ACCELERATORS*/': readFileSync(join(here, '../inference-sizer/src/accelerators.js'), 'utf8'),
13
+ // the sizer's catalog and model: FleetScope's model list comes from the catalog, its KV per token from the model
14
+ '/*SIZERCATALOG*/': readFileSync(join(here, '../inference-sizer/src/catalog.js'), 'utf8'),
15
+ '/*SIZERMODEL*/': readFileSync(join(here, '../inference-sizer/src/model.js'), 'utf8'),
16
+ '/*SIZERSUGGEST*/': readFileSync(join(here, '../inference-sizer/src/suggest.js'), 'utf8'),
13
17
  '/*ENGINE*/': read('src/engine.js'),
14
18
  '/*TEMPLATES*/': read('src/templates.js'),
15
19
  '/*INGEST*/': read('src/ingest.js'),