@volter/twin-standard 1.0.148 → 1.0.150

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 (103) hide show
  1. package/README.md +12 -3
  2. package/client-sdks/bun.lock +0 -32
  3. package/client-sdks/package.json +0 -2
  4. package/dist/client-sdks/bun.lock +0 -32
  5. package/dist/client-sdks/package.json +0 -2
  6. package/dist/src/assessment.d.ts +6 -4
  7. package/dist/src/assessment.js +2 -1
  8. package/dist/src/cli.js +21 -6
  9. package/dist/src/clients/harness.d.ts +3 -1
  10. package/dist/src/clients/harness.js +4 -2
  11. package/dist/src/clients/jira.d.ts +2 -0
  12. package/dist/src/clients/jira.js +71 -0
  13. package/dist/src/clients/polar.d.ts +2 -0
  14. package/dist/src/clients/polar.js +73 -0
  15. package/dist/src/clients/resend.js +38 -0
  16. package/dist/src/clients/run.js +1 -1
  17. package/dist/src/clients/sentry.js +1 -26
  18. package/dist/src/clients/smtp.d.ts +2 -0
  19. package/dist/src/clients/smtp.js +54 -0
  20. package/dist/src/clients/stripe.js +1 -1
  21. package/dist/src/clients/volteridentity.js +4 -3
  22. package/dist/src/clients/x.d.ts +2 -0
  23. package/dist/src/clients/x.js +64 -0
  24. package/dist/src/conformance.d.ts +4 -3
  25. package/dist/src/conformance.js +293 -8
  26. package/dist/src/consumer.js +5 -1
  27. package/dist/src/create-pack.d.ts +5 -0
  28. package/dist/src/create-pack.js +38 -4
  29. package/dist/src/derive.js +21 -13
  30. package/dist/src/gate.d.ts +1 -0
  31. package/dist/src/gate.js +47 -4
  32. package/dist/src/grade.d.ts +1 -0
  33. package/dist/src/grade.js +1 -1
  34. package/dist/src/pack-facts.d.ts +9 -1
  35. package/dist/src/pack-facts.js +11 -2
  36. package/dist/src/pack-files.js +2 -1
  37. package/dist/src/protocol-3.js +40 -6
  38. package/dist/src/spec-ir-client.js +3 -2
  39. package/dist/src/spec-ir-commands.d.ts +73 -0
  40. package/dist/src/spec-ir-commands.js +63 -0
  41. package/dist/src/spec-ir.d.ts +2 -0
  42. package/dist/src/spec-ir.js +43 -0
  43. package/dist/src/tools/judge-brief.d.ts +1 -0
  44. package/dist/src/tools/judge-brief.js +67 -0
  45. package/dist/src/tools/life-coverage-walk.d.ts +2 -0
  46. package/dist/src/tools/life-coverage-walk.js +220 -0
  47. package/dist/src/tools/life-coverage.d.ts +2 -0
  48. package/dist/src/tools/life-coverage.js +271 -0
  49. package/dist/src/tools/packs-root.d.ts +9 -0
  50. package/dist/src/tools/packs-root.js +17 -0
  51. package/dist/src/tools/run-tool.d.ts +1 -0
  52. package/dist/src/tools/run-tool.js +18 -0
  53. package/dist/src/tools/score-pack.d.ts +2 -0
  54. package/dist/src/tools/score-pack.js +264 -0
  55. package/dist/src/tools/vendor-examples.d.ts +2 -0
  56. package/dist/src/tools/vendor-examples.js +1493 -0
  57. package/dist/src/types.d.ts +2 -0
  58. package/dist/src/verdict.js +1 -1
  59. package/dist/src/walk/behavior-journey.d.ts +6 -0
  60. package/dist/src/walk/behavior-journey.js +108 -8
  61. package/dist/src/walk/journey-kit.d.ts +23 -1
  62. package/dist/src/walk/journey-kit.js +7 -2
  63. package/dist/src/walk/rendered-scalar.d.ts +3 -0
  64. package/dist/src/walk/rendered-scalar.js +23 -0
  65. package/dist/src/walk/sse-example.js +45 -0
  66. package/package.json +2 -2
  67. package/src/assessment.ts +2 -1
  68. package/src/cli.ts +15 -2
  69. package/src/clients/harness.ts +4 -2
  70. package/src/clients/jira.ts +73 -0
  71. package/src/clients/polar.ts +73 -0
  72. package/src/clients/resend.ts +32 -0
  73. package/src/clients/run.ts +2 -2
  74. package/src/clients/sentry.ts +1 -25
  75. package/src/clients/smtp.ts +49 -0
  76. package/src/clients/stripe.ts +1 -1
  77. package/src/clients/volteridentity.ts +4 -3
  78. package/src/clients/x.ts +66 -0
  79. package/src/conformance.ts +226 -10
  80. package/src/consumer.ts +5 -1
  81. package/src/create-pack.ts +35 -5
  82. package/src/derive.ts +21 -14
  83. package/src/gate.ts +40 -6
  84. package/src/grade.ts +2 -2
  85. package/src/pack-facts.ts +10 -3
  86. package/src/pack-files.ts +2 -1
  87. package/src/protocol-3.ts +32 -6
  88. package/src/spec-ir-client.ts +3 -2
  89. package/src/spec-ir-commands.ts +81 -0
  90. package/src/spec-ir.ts +31 -0
  91. package/src/tools/judge-brief.ts +63 -0
  92. package/src/tools/life-coverage-walk.ts +173 -0
  93. package/src/tools/life-coverage.ts +237 -0
  94. package/src/tools/packs-root.ts +21 -0
  95. package/src/tools/run-tool.ts +10 -0
  96. package/src/tools/score-pack.ts +244 -0
  97. package/src/tools/vendor-examples.ts +1250 -0
  98. package/src/types.ts +2 -0
  99. package/src/verdict.ts +1 -1
  100. package/src/walk/behavior-journey.ts +65 -4
  101. package/src/walk/journey-kit.ts +21 -3
  102. package/src/walk/rendered-scalar.ts +17 -0
  103. package/src/walk/sse-example.ts +37 -0
@@ -0,0 +1,244 @@
1
+ #!/usr/bin/env bun
2
+ // score-pack — a Protocol 3 pack's report (docs/contributing/architecture.md, "Protocol 3", Scoring). One customer
3
+ // life per pack is walked through the pack's own fetch on the in-memory World, and the report says:
4
+ // - the life: whether a judge's plausible verdict names its current content (a verdict its author wrote is not one);
5
+ // - correctness: every check on every step (status, expectations, captures, SHAPE, the beats) and the life
6
+ // answering byte for byte the same on a second fresh World;
7
+ // - coverage: the hand-written code the life and the vendor's published examples run and the declared state logic
8
+ // they reach (life-coverage.ts), with what they never reach;
9
+ // - the vendor's published examples: replayed and judged (vendor-examples.ts);
10
+ // - breadth: the spec's operations (a line protocol's commands) by what serves them (a handler, the generated
11
+ // core, a legacy fallback, nothing).
12
+ // This is source-journey evidence, not installed readiness or pack completion. pack-done owns completion and consumes
13
+ // this report alongside the exact artifact's installed customer assessment in the one final run.
14
+ //
15
+ // Usage: twin-standard walk <vendor> [--write] [--report <path>] (from the pack repository's root; twin-world's
16
+ // bun scripts/score-pack.ts <vendor> runs the same)
17
+ // --write keeps journeys/score.json and journeys/coverage.json; --report writes the report and what it lacks for done
18
+ // to <path> as JSON and changes nothing in the checkout
19
+
20
+ import { parseExactJson } from '@volter/world-core/exact-json';
21
+ import { notIndependent } from '../verdict.ts';
22
+ import { spawnSync } from 'node:child_process';
23
+ import { existsSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
24
+ import { createRequire } from 'node:module';
25
+ import { tmpdir } from 'node:os';
26
+ import { dirname, join, sep } from 'node:path';
27
+ import { inMemoryWorld, walk, withPinnedWorldDraws, type Failure, usePacks } from '../walk/behavior-journey.ts';
28
+ import { expandFills, waitMs, type Journey } from '../walk/journey-kit.ts';
29
+ import { vendorFetch, vendorStream } from '../walk/vendor-fetch.ts';
30
+ import { existenceProbe } from '../walk/journey-kit.ts';
31
+ import { kernelCheckout, packsRoot, toolPath } from './packs-root.ts';
32
+ const PACKS = packsRoot();
33
+ usePacks(PACKS);
34
+
35
+ const vendor = process.argv[2];
36
+ if (!vendor || vendor.startsWith('-')) { console.error('usage: twin-standard walk <vendor> [--write] [--report <path>] (from the pack repository\'s root)'); process.exit(1); }
37
+ // The surface measured: the kernel the pack repository resolves, named in the report. twin-world's own scripts require
38
+ // it to be their checkout's (linked in development, decision 0029): a pack repository whose node_modules resolves
39
+ // @volter/* into another checkout scores the pack against someone else's kernel, no measurement of this one.
40
+ const kernel = ((): string => {
41
+ try { return realpathSync(join(PACKS, 'node_modules', '@volter', 'world-core')); } catch { /* resolved through a parent's node_modules */ }
42
+ try {
43
+ let at = dirname(realpathSync(createRequire(join(PACKS, 'package.json')).resolve('@volter/world-core')));
44
+ while (!existsSync(join(at, 'package.json')) && dirname(at) !== at) at = dirname(at);
45
+ return at;
46
+ } catch { return '(unresolved)'; }
47
+ })();
48
+ const checkout = kernelCheckout();
49
+ if (checkout && !kernel.startsWith(realpathSync(checkout) + sep)) { // the platform's separator: '/' never prefixes a Windows path
50
+ console.error(`score-pack: @volter/world-core resolves to ${kernel}, outside this checkout (${realpathSync(checkout)}); link the pack repository's node_modules/@volter/* to this checkout's packages before scoring`);
51
+ process.exit(2);
52
+ }
53
+ const PKG = join(PACKS, vendor);
54
+ const lifePath = join(PKG, 'journeys', 'customer-life.json');
55
+ if (!existsSync(lifePath)) { console.error(`${vendor}: no journeys/customer-life.json`); process.exit(1); }
56
+
57
+ // ── the life and its verdict ─────────────────────────────────────────────────────────────────
58
+ const text = readFileSync(lifePath, 'utf8');
59
+ // its fills written out once, so the steps the walk hands back are the life's own (a sitting is found by position)
60
+ const life = expandFills(parseExactJson(text) as Journey);
61
+ const verdictPath = join(PKG, 'journeys', 'customer-life.verdict.json');
62
+ const verdict = existsSync(verdictPath) ? (parseExactJson(readFileSync(verdictPath, 'utf8')) as { sha256?: string; plausible?: boolean; judge?: { session?: string; name?: string; agent?: string }; authors?: string[] } ) : undefined;
63
+ // A verdict is a judge's in another session: one its author wrote (marked self-judged) rules nothing, however it reads.
64
+ // The dispatcher stamps the judge’s author name (`judge.agent`) and every author of the life
65
+ // (`authors`) consistently when it commits the verdict; a verdict without them,
66
+ // or whose judge is among the authors, is not independent.
67
+ // one judging per pack: the verdict stands, and the life's changes since (its rulings applied, a review's fixes, steps for
68
+ // coverage) keep it (architecture, "Writing a life", Judge)
69
+ const dependent = verdict ? notIndependent(verdict, life.author) : undefined;
70
+ const judged = life.steps.length === 0 || !verdict ? 'unjudged' : dependent ? dependent : verdict.plausible ? 'plausible' : 'rejected';
71
+
72
+ // ── correctness ──────────────────────────────────────────────────────────────────────────────
73
+ const world = inMemoryWorld(`score-${vendor}`);
74
+ const failures: Failure[] = [];
75
+ await walk(life, world.root(), failures, { beats: true });
76
+ const answers = async (): Promise<string[]> => {
77
+ const seen: string[] = [];
78
+ // the World's own draws (its seed, its keys) are the same in both: two Worlds differ only by what is beyond them (R9)
79
+ await withPinnedWorldDraws(() => walk(life, world.root(), [], { beats: false, hooks: { after: (step, p, a) => seen.push(`${(step as { name?: string }).name ?? ''}\u0000${p} ${a.status} ${JSON.stringify(a.body)}`) } }));
80
+ return seen;
81
+ };
82
+ const [first, second] = [await answers(), await answers()];
83
+
84
+ // ── what a judge rejects on sight ────────────────────────────────────────────────────────────
85
+ // The patterns independent judges rejected every self-judged life for (the Journeys section): a failing repeat of a
86
+ // request that succeeded earlier in the same sitting, three or more refusals in a row, and a resource written A → B → A
87
+ // or made and removed in one sitting. A sitting is the steps between two `wait` steps. These are flags for the author
88
+ // and the judge, not failed checks: the judge rules, and a flag the story gives a shown cause may stand.
89
+ type Flag = { step: string; pattern: 'REPEAT' | 'RUN' | 'TOGGLE' | 'TIME' | 'CRED'; detail: string };
90
+ const flags: Flag[] = [];
91
+ // CRED: a life where steps act with different credentials carries no life-wide default one; a default leaks one actor's
92
+ // credential into every step that forgot its own (a judge found octocat's token on a server's call).
93
+ {
94
+ const auth = (h?: Record<string, string>) => Object.entries(h ?? {}).find(([k]) => k.toLowerCase() === 'authorization')?.[1];
95
+ const own = new Set(life.steps.flatMap((st) => { const a = auth((st as { headers?: Record<string, string> }).headers); return a ? [a] : []; }));
96
+ const fallback = auth((life as { headers?: Record<string, string> }).headers);
97
+ if (fallback && own.size > 0) {
98
+ const leaning = life.steps.filter((st) => 'method' in st && !auth((st as { headers?: Record<string, string> }).headers));
99
+ if (leaning.length) flags.push({ step: (leaning[0] as { name: string }).name, pattern: 'CRED', detail: `${leaning.length} steps act with the life-wide default credential in a life of ${own.size + 1} credentials; give each its actor's own` });
100
+ }
101
+ }
102
+ {
103
+ const walked: Array<{ index: number; name: string; key: string; path: string; method: string; body: string; refused: boolean; status: number }> = [];
104
+ const refusedAnswer = (a: { status: number; body: unknown }): boolean => {
105
+ const b = a.body as Record<string, unknown> | null;
106
+ return a.status >= 400 || (!!b && typeof b === 'object' && (b.ok === false || (Array.isArray(b.errors) && b.errors.length > 0 && b.data === undefined) || typeof b.error === 'string'));
107
+ };
108
+ // CRED too: a credential a person was shown once (a key on a dashboard, a token in a mail) is read off what showed it
109
+ // (a capture), never typed in: a literal equal to what an earlier answer showed means the life knows how the twin mints it
110
+ const shown = new Set<string>();
111
+ let literalFlags = 0;
112
+ await walk(life, inMemoryWorld(`flags-${vendor}`).root(), [], { beats: false, hooks: { after: (step, path, answer) => {
113
+ const s = step as { name: string; connection?: string; resp?: unknown; method?: string; git?: string; on?: string; send?: unknown; body?: unknown; ref?: string; delete?: boolean; headers?: Record<string, string>; socket?: string; open?: string; close?: boolean; mysql?: string; values?: unknown; link?: string; signIn?: { user: string } };
114
+ for (const [k, v] of Object.entries(s.headers ?? {})) {
115
+ if (!/^(authorization|x-api-key|api-key|cookie)$/i.test(k) || v.includes('{')) continue;
116
+ const secret = v.replace(/^(bearer|token|basic)\s+/i, '').replace(/^[a-z_]+=/i, '');
117
+ if (secret.length >= 16 && shown.has(secret) && literalFlags++ < 3) flags.push({ step: s.name, pattern: 'CRED', detail: `sends as a literal the credential an earlier answer showed (${secret.slice(0, 12)}…): capture it where it was shown` });
118
+ }
119
+ const text = typeof answer.body === 'string' ? answer.body : JSON.stringify(answer.body ?? '');
120
+ // a token ends before trailing punctuation (a key closing a sentence); a JWT's inner dots stay
121
+ for (const t of text.match(/[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*/g) ?? []) if (t.length >= 16) shown.add(t);
122
+ const method = s.method ?? (s.mysql !== undefined || s.signIn ? `MySQL ${s.link ?? 'mysql'}` : s.connection ? `RESP ${s.connection}` : s.socket ? `socket ${s.open ? 'open' : s.close ? 'close' : 'send'}` : s.git ? `git ${s.git}${s.delete ? ' delete' : ''}` : `line ${s.on}`);
123
+ const body = JSON.stringify(s.mysql !== undefined || s.signIn ? { mysql: s.mysql ?? null, values: s.values ?? null, signIn: s.signIn?.user ?? null } : s.resp ?? s.body ?? s.send ?? (s.ref ? { ref: s.ref } : null));
124
+ // an operation named in a header (AWS's X-Amz-Target) is part of what the request is; who sends it is not
125
+ const named = Object.entries(s.headers ?? {}).filter(([k]) => !/^(authorization|stripe-account|x-slack-|cookie)/i.test(k)).sort().map(([k, v]) => `${k}=${v}`).join('&');
126
+ // and so is the region an AWS request is signed for (its credential scope), which says where it goes
127
+ const region = /Credential=[^/]+\/\d{8}\/([a-z0-9-]+)\//.exec((s.headers ?? {}).authorization ?? (life.headers ?? {}).authorization ?? '')?.[1];
128
+ const where = named || region ? `${path} [${[named, region ? `region=${region}` : ''].filter(Boolean).join('&')}]` : path;
129
+ walked.push({ index: life.steps.indexOf(step as never), name: s.name, key: `${method} ${where} ${body}`, path: where, method, body, refused: s.socket ? (answer.status !== 101 && answer.status !== 1000) : refusedAnswer(answer), status: answer.status });
130
+ } } });
131
+ const sitting = (i: number): number => life.steps.slice(0, i).filter((x) => 'wait' in x).length;
132
+ // a client asking whether something exists before it makes it is not a refusal (existenceProbe, journey-kit)
133
+ const probe = (n: number): boolean => existenceProbe(walked.map((w) => ({ ...w, sitting: sitting(w.index) })), n);
134
+ let run: typeof walked = [];
135
+ const endRun = () => { if (run.length >= 3) flags.push({ step: run[0]!.name, pattern: 'RUN', detail: `${run.length} refusals in a row, from "${run[0]!.name.slice(0, 50)}" to "${run.at(-1)!.name.slice(0, 50)}"` }); run = []; };
136
+ walked.forEach((w, n) => {
137
+ if (w.refused && !probe(n)) run.push(w); else if (!w.refused) endRun();
138
+ const earlier = walked.slice(0, n).filter((e) => sitting(e.index) === sitting(w.index));
139
+ if (w.refused && earlier.some((e) => !e.refused && e.key === w.key)) flags.push({ step: w.name, pattern: 'REPEAT', detail: `repeats a request that succeeded earlier in the sitting (${w.method} ${w.path.slice(0, 60)})` });
140
+ if (!w.refused && /^(POST|PUT|PATCH)$/.test(w.method)) {
141
+ const writes = earlier.filter((e) => !e.refused && e.method === w.method && e.path === w.path);
142
+ if (writes.length >= 2 && writes.at(-2)!.body === w.body && writes.at(-1)!.body !== w.body) flags.push({ step: w.name, pattern: 'TOGGLE', detail: `writes ${w.path.slice(0, 60)} back to what it was two writes before, in one sitting` });
143
+ }
144
+ if (!w.refused && w.method === 'DELETE' && earlier.some((e) => !e.refused && (e.method === 'PUT' || e.method === 'POST') && e.path === w.path)) flags.push({ step: w.name, pattern: 'TOGGLE', detail: `removes ${w.path.slice(0, 60)}, made earlier in the same sitting` });
145
+ });
146
+ endRun();
147
+ // a time of day a step names that its hour on the World clock contradicts (the clock starts at startsAt or the default and
148
+ // moves only by `wait` steps; a wait's name tells what happens once it has passed)
149
+ const hours: Array<[RegExp, number, number]> = [[/\bmorning\b/i, 5, 12], [/\blunch\b/i, 11, 15], [/\bafternoon\b/i, 12, 18], [/\bevening\b/i, 17, 23]];
150
+ const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
151
+ const MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
152
+ const DATED = /\b(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),? (\d{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December)(?:,? (\d{4}))?/g;
153
+ let clock = Date.parse(life.startsAt ?? '2026-01-01T00:00:00Z');
154
+ for (const step of life.steps) {
155
+ if ('wait' in step) clock += waitMs(step.wait);
156
+ const hour = new Date(clock).getUTCHours();
157
+ for (const [word, from, to] of hours) {
158
+ if (word.test(step.name) && (hour < from || hour >= to)) flags.push({ step: step.name, pattern: 'TIME', detail: `says ${word.source.replace(/\\b/g, '')} at ${String(hour).padStart(2, '0')}:00 on the World clock` });
159
+ }
160
+ // a weekday named with its date is a fact of the calendar, and a wait's name says the date the clock reaches
161
+ for (const m of step.name.matchAll(DATED)) {
162
+ const [, weekday, day, month, year] = m;
163
+ const at = new Date(Date.UTC(year ? Number(year) : new Date(clock).getUTCFullYear(), MONTHS.indexOf(month!.toLowerCase()), Number(day)));
164
+ if (WEEKDAYS[at.getUTCDay()] !== weekday!.toLowerCase()) flags.push({ step: step.name, pattern: 'TIME', detail: `says ${weekday} ${day} ${month}, which is a ${WEEKDAYS[at.getUTCDay()]}` });
165
+ else if ('wait' in step && at.toISOString().slice(0, 10) !== new Date(clock).toISOString().slice(0, 10)) flags.push({ step: step.name, pattern: 'TIME', detail: `its wait reaches ${new Date(clock).toISOString().slice(0, 10)}, not ${weekday} ${day} ${month}` });
166
+ }
167
+ }
168
+ }
169
+ const differs = first.findIndex((line, i) => line !== second[i]);
170
+ if (differs >= 0 || first.length !== second.length) failures.push({ step: '(whole life)', beat: 'REPLAYABLE', detail: `a second fresh World answered differently at "${(first[differs] ?? second[differs] ?? first.at(-1) ?? '').split('\u0000')[0]}" (the ${differs + 1}th answered step; waits are not counted)` });
171
+
172
+ // ── breadth ──────────────────────────────────────────────────────────────────────────────────
173
+ const factory = await vendorFetch(PACKS, vendor);
174
+ const fetch = factory?.(world.root()) as ((r: Request) => Promise<Response>) & { owners?: () => Record<string, string> } | undefined;
175
+ // a line protocol's commands are served on its stream
176
+ const stream = (await vendorStream(PACKS, vendor))?.(world.root()) as { owners?: () => Record<string, string> } | undefined;
177
+ const owners = fetch?.owners?.() ?? stream?.owners?.() ?? {};
178
+ world.restore();
179
+ const breadth: Record<string, number> = {};
180
+ for (const o of Object.values(owners)) breadth[o] = (breadth[o] ?? 0) + 1;
181
+ const operations = Object.keys(owners).length;
182
+
183
+ // ── coverage ─────────────────────────────────────────────────────────────────────────────────
184
+ // the measurement is kept (journeys/coverage.json) only with --write; a plain run leaves the checkout as it found it
185
+ const keep = process.argv.includes('--write');
186
+ const coveragePath = keep ? join(PKG, 'journeys', 'coverage.json') : join(mkdtempSync(join(tmpdir(), 'score-coverage-')), 'coverage.json');
187
+ // each tool in a process of its own, run from the pack repository, naming it as this one does
188
+ const tool = (name: string, args: string[]) => spawnSync(process.execPath, [toolPath('run-tool'), PACKS, checkout ?? '', toolPath(name), ...args], { cwd: PACKS, stdio: ['ignore', 'pipe', 'pipe'] });
189
+ const measured = tool('life-coverage', [vendor, ...(keep ? ['--write'] : ['--out', coveragePath])]);
190
+ // a measurement that failed reports so, never the last one it kept
191
+ const coverage = measured.status === 0 && existsSync(coveragePath) ? (parseExactJson(readFileSync(coveragePath, 'utf8')) as { missing: number; code: { lines: number; run: number; recorded: number; missing: number }; state: { declared: number; reached: number; recorded: number; missing: string[]; undeclared: string[] } }) : undefined;
192
+
193
+ // ── the vendor's published examples (vendor-examples.ts) ────────────────────────────────────────
194
+ const replay = tool('vendor-examples', [vendor]);
195
+ const replayOut = String(replay.stdout).trim().split('\n');
196
+ const replayLine = replayOut.at(-1) ?? '';
197
+ // replayed and judged are two lacks: the replay is the twin's, the verdict a judge's (pack-done's (d) and (f))
198
+ const examples = {
199
+ done: replay.status === 0,
200
+ replayed: replayOut.some((l) => l.trim() === 'replayed: yes'),
201
+ verdict: replayOut.find((l) => l.trim().startsWith('verdict: '))?.trim().slice('verdict: '.length) ?? 'not measured',
202
+ failures: replayOut.filter((line) => /^\s*(?:FAIL|GAP)\s/.test(line)).map((line) => line.trim()),
203
+ line: replayLine.replace(/^\S+\s+/, ''),
204
+ };
205
+
206
+ const pct = (hit: number, found: number): string => (found ? `${((hit / found) * 100).toFixed(1)}%` : 'n/a');
207
+ const score = {
208
+ scope: 'source-customer-life-and-published-examples',
209
+ vendor,
210
+ life: { steps: life.steps.length, verdict: judged, judge: verdict?.judge?.agent ?? verdict?.judge?.name ?? null, authors: verdict?.authors ?? [] },
211
+ failures: failures.map((f) => ({ step: f.step, beat: f.beat, detail: f.detail })),
212
+ flags,
213
+ coverage: coverage ?? null,
214
+ examples,
215
+ breadth: { operations, ...breadth },
216
+ };
217
+ console.log(` measured through: ${kernel}`);
218
+ console.log(`${vendor}: life of ${life.steps.length} steps, ${judged}; ${failures.length} checks failing`);
219
+ if (!coverage) console.log(` coverage: NOT MEASURED — life-coverage failed: ${String(measured.stderr).trim().split('\n').slice(-3).join(' ')}`);
220
+ if (coverage) console.log(` coverage: ${coverage.missing === 0 ? 'meets the standard' : `${coverage.missing} missing`} — hand-written lines ${pct(coverage.code.run, coverage.code.lines)} run, ${coverage.code.recorded} recorded unreachable, ${coverage.code.missing} missing; state logic ${coverage.state.reached}/${coverage.state.declared} reached, ${coverage.state.recorded} recorded, ${coverage.state.missing.length} missing, ${coverage.state.undeclared.length} undeclared moves`);
221
+ console.log(` ${examples.line || 'examples: not measured'}`);
222
+ console.log(` breadth: ${operations} spec operations — ${Object.entries(breadth).map(([k, n]) => `${n} ${k}`).join(', ')}`);
223
+ for (const f of failures.slice(0, 20)) console.log(` FAIL ${f.beat} ${f.step.slice(0, 60)}: ${f.detail.slice(0, 140)}`);
224
+ console.log(` judge flags: ${flags.length ? `${flags.length} (${(['REPEAT', 'RUN', 'TOGGLE', 'TIME', 'CRED'] as const).map((p) => `${flags.filter((f) => f.pattern === p).length} ${p}`).join(', ')}) — what judges reject on sight; resolve each or give it a cause the story shows` : 'none'}`);
225
+ for (const f of flags.slice(0, 30)) console.log(` FLAG ${f.pattern} ${f.step.slice(0, 60)}: ${f.detail}`);
226
+ // Source requirements used by pack-done's report step; keep the field name for existing report consumers.
227
+ const missingForDone = [
228
+ judged !== 'plausible' ? `a plausible verdict from another session (now: ${judged})` : '',
229
+ failures.length ? `${failures.length} checks failing` : '',
230
+ flags.length ? `${flags.length} judge flags` : '',
231
+ !coverage ? 'coverage not measured' : coverage.missing ? `${coverage.missing} coverage items missing` : '',
232
+ breadth.legacy ? `${breadth.legacy} operations on a legacy fallback` : '',
233
+ examples.replayed ? '' : "the vendor's published examples not all replayed",
234
+ examples.verdict === 'plausible' ? '' : `a plausible verdict on the vendor's published examples (now: ${examples.verdict})`,
235
+ ].filter(Boolean);
236
+ console.log(` source journey: ${missingForDone.length ? `incomplete — ${missingForDone.join('; ')}` : 'meets the source requirements'}`);
237
+ console.log(' pack completion: not assessed — pack-done consumes the exact installed assessment in the final run');
238
+ const reportAt = process.argv.indexOf('--report');
239
+ if (reportAt >= 0 && process.argv[reportAt + 1]) {
240
+ writeFileSync(process.argv[reportAt + 1]!, `${JSON.stringify({ ...score, missingForDone }, null, 2)}\n`);
241
+ }
242
+ if (process.argv.includes('--write')) {
243
+ writeFileSync(join(PKG, 'journeys', 'score.json'), `${JSON.stringify(score, null, 2)}\n`);
244
+ }