@event4u/agent-config 14.4.0 → 14.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 (48) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +132 -291
  3. package/dist/agent-src/commands/analyze/decision.md +7 -0
  4. package/dist/agent-src/commands/optimize/project.md +10 -0
  5. package/dist/agent-src/commands/roadmap/process-full.md +45 -3
  6. package/dist/agent-src/contexts/execution/roadmap-process-loop.md +130 -1
  7. package/dist/agent-src/rules/decision-revisit-gate.md +108 -7
  8. package/dist/agent-src/skills/adr-create/SKILL.md +25 -3
  9. package/dist/agent-src/skills/decision-review/SKILL.md +18 -0
  10. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  11. package/dist/cli-delegate/{chunk-ZPSXJTLI.js → chunk-P6LQDIWK.js} +15 -1
  12. package/dist/cli-delegate/cmd_conformance.js +1 -1
  13. package/dist/cli-delegate/cmd_handoff.js +1 -1
  14. package/dist/cli-delegate/cmd_session_recycle.js +1 -1
  15. package/dist/discovery/deprecation-report.md +1 -1
  16. package/dist/discovery/discovery-manifest.json +8 -8
  17. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  18. package/dist/discovery/discovery-manifest.summary.md +1 -1
  19. package/dist/discovery/dormancy-report.md +1 -1
  20. package/dist/discovery/orphan-report.md +1 -1
  21. package/dist/discovery/packs.json +2 -2
  22. package/dist/discovery/trust-report.md +1 -1
  23. package/dist/discovery/workspaces.json +2 -2
  24. package/dist/hooks/dispatch.js +419 -94
  25. package/dist/mcp/registry-manifest.json +2 -2
  26. package/dist/mcp/server.json +2 -2
  27. package/dist/router.json +1 -1
  28. package/docs/guidelines/agent-infra/engineering-memory-data-format.md +49 -0
  29. package/package.json +1 -1
  30. package/src/config/estate-count-budget.json +36 -1
  31. package/src/config/pack-size-budget.json +3 -2
  32. package/src/scripts/_lib/layer_overlap_notice.ts +85 -0
  33. package/src/scripts/_lib/scope_guard.sh +62 -3
  34. package/src/scripts/_lib/subagent_capsule.ts +81 -1
  35. package/src/scripts/adr/regenerate_index.ts +13 -2
  36. package/src/scripts/adr_cite_check.ts +424 -0
  37. package/src/scripts/bench_hook_injection.ts +18 -1
  38. package/src/scripts/check_adr_frontmatter.ts +187 -1
  39. package/src/scripts/check_single_delivery.ts +473 -0
  40. package/src/scripts/hooks/host_semantics.ts +28 -0
  41. package/src/scripts/hooks/injection_budget.ts +152 -16
  42. package/src/scripts/hooks/run_continuation_hook.ts +918 -46
  43. package/src/scripts/install.sh +12 -2
  44. package/src/scripts/memory_consolidation.ts +189 -0
  45. package/src/scripts/memory_eviction.ts +384 -0
  46. package/src/scripts/report_layer_overlap.ts +72 -0
  47. package/src/scripts/report_memory_pointers.ts +622 -0
  48. package/src/scripts/session_register_hook.ts +144 -21
@@ -0,0 +1,473 @@
1
+ /**
2
+ * check_single_delivery — assert that no artefact is delivered from both layers.
3
+ *
4
+ * THE INVARIANT (ADR-236, one-artefact-one-layer): every rule and every skill is
5
+ * delivered from exactly ONE layer. Claude Code loads `~/.claude/**` AND
6
+ * `<project>/.claude/**`, both, user layer first, with no dedup — so an artefact
7
+ * present in both is delivered twice, in every session, forever.
8
+ *
9
+ * WHY THIS EXISTS AS A SEPARATE CHECK, rather than inside a producer. Two
10
+ * producers write these layers and neither can see the other:
11
+ *
12
+ * - the INSTALLER writes the global layer, and `_gate_rule_layer_overlap`
13
+ * (install.ts) checks the overlap at install time — rules only, Claude only,
14
+ * and never again afterwards;
15
+ * - `task generate-tools` writes the project layer, and contains zero
16
+ * references to that gate or to `rule_layer_overlap`.
17
+ *
18
+ * So the overlap is created by whichever producer runs LAST, and an install-time
19
+ * gate cannot see a layer written afterwards. This check is deliberately outside
20
+ * both: it reads the filesystem and does not care who wrote it.
21
+ *
22
+ * WHAT IT COUNTS, and why the two halves are separate:
23
+ *
24
+ * 1. RAW OVERLAP — names present in both layers. The token cost.
25
+ * 2. SCOPE DEFEAT — shared rules where one copy carries `paths:` and the other
26
+ * does not. `report_carrier_divergence` names the mechanism: a copy that
27
+ * LACKS `paths:` defeats the other copy's scoping, so the rule loads
28
+ * unconditionally however carefully the other copy was scoped. This is a
29
+ * correctness fact rather than a token fact, and it needs a different
30
+ * remedy, so it is never folded into the overlap number.
31
+ *
32
+ * REPORT BY DEFAULT, ENFORCE ON REQUEST — and that is not timidity. The
33
+ * invariant is not true yet: `road-to-single-delivery` Phase 2, which makes the
34
+ * producers write disjoint layers, is HALTED on blocker
35
+ * `partition-requires-global-layer`. A blocking default would therefore red every
36
+ * run on a defect nobody can currently fix, which teaches readers to ignore it —
37
+ * the exact failure this estate has recorded twice already. Pass `--enforce` once
38
+ * Phase 2 lands.
39
+ *
40
+ * A LAYER THAT DOES NOT EXIST IS NOT A PASS. Where a layer is absent there is no
41
+ * overlap to find, and saying "invariant holds" would be a gate reading nothing
42
+ * and reporting green. Absent layers are named, and `--enforce` refuses rather
43
+ * than passing when BOTH layers of every type are missing.
44
+ */
45
+
46
+ import * as fs from 'node:fs';
47
+ import * as os from 'node:os';
48
+ import * as path from 'node:path';
49
+ import process from 'node:process';
50
+ import { fileURLToPath, pathToFileURL } from 'node:url';
51
+
52
+ import { reportScanned } from './_lib/scan_scope.js';
53
+
54
+ const _HERE = fileURLToPath(import.meta.url);
55
+ const REPO_ROOT = path.resolve(path.dirname(_HERE), '..', '..');
56
+
57
+ /** Artefact types the host loads from both layers. */
58
+ const TYPES = ['rules', 'skills', 'commands', 'agents'] as const;
59
+ type ArtefactType = (typeof TYPES)[number];
60
+
61
+ /**
62
+ * What a layer's entries physically ARE — symlinks, directories, or regular files.
63
+ *
64
+ * R2 finding 2: without this, name-equality was reported as "delivered twice" for
65
+ * two layers holding entirely different payload shapes. Measured on this repo:
66
+ * project `.claude/commands/` is **40 directories** of symlinks into
67
+ * `src/domains/**` while global `.claude/commands/` is **52 regular files**. Those
68
+ * 40 shared names are not 40 duplicated artefacts in the sense the rules row means,
69
+ * and a check that prints one number for both teaches the reader they are.
70
+ */
71
+ export interface LayerShape {
72
+ symlinks: number;
73
+ dirs: number;
74
+ files: number;
75
+ }
76
+
77
+ export interface TypeReading {
78
+ type: ArtefactType;
79
+ /** null when that layer's directory does not exist — distinct from empty. */
80
+ globalNames: string[] | null;
81
+ projectNames: string[] | null;
82
+ globalShape: LayerShape | null;
83
+ projectShape: LayerShape | null;
84
+ /**
85
+ * True when the two layers' dominant entry shape differs, so a shared NAME is
86
+ * not evidence of a shared artefact. The overlap is still reported — it is
87
+ * still a delivery collision — but it is labelled, never summed with the rest.
88
+ */
89
+ shapeMismatch: boolean;
90
+ both: string[];
91
+ globalOnly: string[];
92
+ projectOnly: string[];
93
+ /** Shared rules whose two copies disagree on `paths:`. Rules only. */
94
+ scopeDefeat: string[];
95
+ }
96
+
97
+ function dominant(s: LayerShape): 'symlink' | 'dir' | 'file' | 'empty' {
98
+ const max = Math.max(s.symlinks, s.dirs, s.files);
99
+ if (max === 0) return 'empty';
100
+ if (s.symlinks === max) return 'symlink';
101
+ if (s.dirs === max) return 'dir';
102
+ return 'file';
103
+ }
104
+
105
+ interface LayerReading {
106
+ names: string[];
107
+ shape: LayerShape;
108
+ }
109
+
110
+ function readLayer(dir: string): LayerReading | null {
111
+ let entries: fs.Dirent[];
112
+ try {
113
+ if (!fs.statSync(dir).isDirectory()) return null;
114
+ entries = fs.readdirSync(dir, { withFileTypes: true });
115
+ } catch {
116
+ return null;
117
+ }
118
+ const shape: LayerShape = { symlinks: 0, dirs: 0, files: 0 };
119
+ for (const e of entries) {
120
+ // isSymbolicLink() is checked FIRST and deliberately: readdir with
121
+ // withFileTypes does not follow links, but a reader who tested isDirectory
122
+ // first would classify a symlink-to-directory as a directory and lose the
123
+ // distinction this whole field exists for.
124
+ if (e.isSymbolicLink()) shape.symlinks += 1;
125
+ else if (e.isDirectory()) shape.dirs += 1;
126
+ else shape.files += 1;
127
+ }
128
+ return { names: entries.map((e) => e.name).sort(), shape };
129
+ }
130
+
131
+ /**
132
+ * Does this rule file declare a `paths:` key in its frontmatter?
133
+ *
134
+ * Frontmatter only, deliberately: a `paths:` mentioned in prose is not a load
135
+ * schedule, and matching it would manufacture scope-defeat findings out of
136
+ * documentation.
137
+ */
138
+ export function declaresPaths(file: string): 'yes' | 'no' | 'unreadable' {
139
+ // Three-valued on purpose (R2 finding): a boolean collapsed "no paths: key"
140
+ // and "could not read the file" into the same answer, so an unreadable copy
141
+ // silently matched an unscoped one and the pair vanished from the scope-defeat
142
+ // set — the direction that hides a finding rather than inventing one.
143
+ let text: string;
144
+ try {
145
+ text = fs.readFileSync(file, 'utf8');
146
+ } catch {
147
+ return 'unreadable';
148
+ }
149
+ if (!text.startsWith('---')) return 'no';
150
+ const end = text.indexOf('\n---', 3);
151
+ if (end < 0) return 'no';
152
+ return /^paths:/m.test(text.slice(3, end)) ? 'yes' : 'no';
153
+ }
154
+
155
+ export function readType(type: ArtefactType, globalRoot: string, projectRoot: string): TypeReading {
156
+ const gDir = path.join(globalRoot, type);
157
+ const pDir = path.join(projectRoot, type);
158
+ const gLayer = readLayer(gDir);
159
+ const pLayer = readLayer(pDir);
160
+ const globalNames = gLayer?.names ?? null;
161
+ const projectNames = pLayer?.names ?? null;
162
+ const globalShape = gLayer?.shape ?? null;
163
+ const projectShape = pLayer?.shape ?? null;
164
+ const shapeMismatch =
165
+ gLayer !== null && pLayer !== null && dominant(gLayer.shape) !== dominant(pLayer.shape);
166
+ const g = new Set(globalNames ?? []);
167
+ const p = new Set(projectNames ?? []);
168
+
169
+ const both = [...g].filter((n) => p.has(n)).sort();
170
+ const globalOnly = [...g].filter((n) => !p.has(n)).sort();
171
+ const projectOnly = [...p].filter((n) => !g.has(n)).sort();
172
+
173
+ // Scope defeat is a rules-only property: `paths:` is the one frontmatter key
174
+ // this host reads as a load schedule.
175
+ const scopeDefeat =
176
+ type === 'rules'
177
+ ? both
178
+ .filter((n) => n.endsWith('.md'))
179
+ .filter((n) => {
180
+ const g2 = declaresPaths(path.join(gDir, n));
181
+ const p2 = declaresPaths(path.join(pDir, n));
182
+ // An unreadable copy is reported as a disagreement rather
183
+ // than dropped: not knowing whether a rule is scoped is a
184
+ // finding, and the alternative silently shrinks the set.
185
+ if (g2 === 'unreadable' || p2 === 'unreadable') return true;
186
+ return g2 !== p2;
187
+ })
188
+ .sort()
189
+ : [];
190
+
191
+ return {
192
+ type,
193
+ globalNames,
194
+ projectNames,
195
+ globalShape,
196
+ projectShape,
197
+ shapeMismatch,
198
+ both,
199
+ globalOnly,
200
+ projectOnly,
201
+ scopeDefeat,
202
+ };
203
+ }
204
+
205
+ export interface Verdict {
206
+ readings: TypeReading[];
207
+ /**
208
+ * Shared names in types where BOTH layers hold the same dominant shape — the
209
+ * number that means "this artefact is delivered twice".
210
+ */
211
+ duplicated: number;
212
+ /**
213
+ * Shared names in types whose layers hold DIFFERENT shapes. Still a delivery
214
+ * collision on the same name, but not the same claim, so it is reported on its
215
+ * own line and never summed into `duplicated` (R2 finding 2).
216
+ */
217
+ nameOverlapDifferentShape: number;
218
+ /** Shared rules whose copies disagree on `paths:`. */
219
+ defeated: number;
220
+ /** Types where at least one layer's directory is missing. */
221
+ absent: string[];
222
+ /**
223
+ * Types where BOTH layers were present, i.e. where a comparison actually
224
+ * happened. Carried explicitly rather than derived as
225
+ * `readings.length - absent.length`: `absent` counts LAYERS (up to two per
226
+ * type) while readings counts TYPES, so that subtraction goes negative. It
227
+ * printed `types_compared=-2` before this field existed.
228
+ */
229
+ typesCompared: number;
230
+ /**
231
+ * Entry names read across every present layer — the gate's dead-scope unit.
232
+ *
233
+ * Deliberately NOT `typesCompared`: a machine with only one layer is a normal
234
+ * consumer state, and crashing the gate there would punish the topology this
235
+ * roadmap is trying to reach. Zero names read, on the other hand, means every
236
+ * directory the gate knows about is gone, which is blindness rather than
237
+ * cleanliness — so it has no `allowEmpty` reason and `reportScanned` throws.
238
+ */
239
+ namesRead: number;
240
+ /** True when no type had BOTH layers present — nothing was actually compared. */
241
+ readNothing: boolean;
242
+ }
243
+
244
+ export function evaluate(globalRoot: string, projectRoot: string): Verdict {
245
+ const readings = TYPES.map((t) => readType(t, globalRoot, projectRoot));
246
+ const absent: string[] = [];
247
+ let compared = 0;
248
+ for (const r of readings) {
249
+ if (r.globalNames === null) absent.push(`${r.type} (global)`);
250
+ if (r.projectNames === null) absent.push(`${r.type} (project)`);
251
+ if (r.globalNames !== null && r.projectNames !== null) compared += 1;
252
+ }
253
+ return {
254
+ readings,
255
+ duplicated: readings.reduce((n, r) => n + (r.shapeMismatch ? 0 : r.both.length), 0),
256
+ nameOverlapDifferentShape: readings.reduce(
257
+ (n, r) => n + (r.shapeMismatch ? r.both.length : 0),
258
+ 0,
259
+ ),
260
+ defeated: readings.reduce((n, r) => n + r.scopeDefeat.length, 0),
261
+ absent,
262
+ typesCompared: compared,
263
+ namesRead: readings.reduce(
264
+ (n, r) => n + (r.globalNames?.length ?? 0) + (r.projectNames?.length ?? 0),
265
+ 0,
266
+ ),
267
+ readNothing: compared === 0,
268
+ };
269
+ }
270
+
271
+ export function render(v: Verdict, globalRoot: string, projectRoot: string): string {
272
+ const out: string[] = [];
273
+ out.push('check_single_delivery · invariant: one artefact, one layer (ADR-236)');
274
+ out.push(` global: ${globalRoot}`);
275
+ out.push(` project: ${projectRoot}`);
276
+ out.push('');
277
+ const shapeOf = (s: LayerShape | null): string =>
278
+ s === null ? 'absent' : `${dominant(s)} (l${s.symlinks}/d${s.dirs}/f${s.files})`;
279
+ for (const r of v.readings) {
280
+ const g = r.globalNames === null ? 'absent' : String(r.globalNames.length);
281
+ const p = r.projectNames === null ? 'absent' : String(r.projectNames.length);
282
+ out.push(
283
+ ` ${r.type.padEnd(9)} global ${g.padStart(6)} · project ${p.padStart(6)}` +
284
+ ` · BOTH ${String(r.both.length).padStart(4)}` +
285
+ ` · global-only ${String(r.globalOnly.length).padStart(4)}` +
286
+ ` · project-only ${String(r.projectOnly.length).padStart(4)}`,
287
+ );
288
+ out.push(` shape: global ${shapeOf(r.globalShape)} · project ${shapeOf(r.projectShape)}`);
289
+ if (r.shapeMismatch && r.both.length > 0) {
290
+ out.push(
291
+ ` ⚠️ SHAPE MISMATCH — this check cannot establish that the` +
292
+ ` ${r.both.length} shared name(s) are the same artefact.`,
293
+ );
294
+ out.push(
295
+ ' It does not establish that they differ either: a project symlink into' +
296
+ ' dist/ and a real',
297
+ );
298
+ out.push(
299
+ ' directory installed globally can hold identical content reached two' +
300
+ ' ways. Counted on its own',
301
+ );
302
+ out.push(
303
+ ' line rather than as duplication, because only the same-shape rows' +
304
+ ' support that claim.',
305
+ );
306
+ }
307
+ if (r.scopeDefeat.length > 0) {
308
+ out.push(
309
+ ` scope defeat: ${r.scopeDefeat.length} shared rule(s) where one copy` +
310
+ ' carries `paths:` and the other does not —',
311
+ );
312
+ out.push(
313
+ ' the unscoped copy DEFEATS the other copy\'s scoping, so the rule' +
314
+ ' loads unconditionally:',
315
+ );
316
+ for (const n of r.scopeDefeat) out.push(` - ${n}`);
317
+ }
318
+ }
319
+ if (v.absent.length > 0) {
320
+ out.push('');
321
+ out.push(` layers not present (nothing to compare there): ${v.absent.join(', ')}`);
322
+ }
323
+ out.push('');
324
+ out.push(
325
+ `check_single_delivery ledger: duplicated=${v.duplicated}` +
326
+ ` name_overlap_different_shape=${v.nameOverlapDifferentShape}` +
327
+ ` scope_defeat=${v.defeated}` +
328
+ ` types_compared=${v.typesCompared} of ${v.readings.length}` +
329
+ ` names_read=${v.namesRead}`,
330
+ );
331
+ return out.join('\n');
332
+ }
333
+
334
+ export function main(argv?: readonly string[]): number {
335
+ const args = argv ?? process.argv.slice(2);
336
+ let globalRoot = path.join(os.homedir(), '.claude');
337
+ let projectRoot = path.join(REPO_ROOT, '.claude');
338
+ let enforce = false;
339
+
340
+ const value = (i: number): string | null => {
341
+ const v = args[i + 1];
342
+ return v === undefined || v.startsWith('-') ? null : v;
343
+ };
344
+ for (let i = 0; i < args.length; i += 1) {
345
+ const a = args[i];
346
+ if (a === '--global' || a === '--project') {
347
+ const v = value(i);
348
+ if (v === null) {
349
+ process.stderr.write(`check_single_delivery: ${a} needs a directory\n`);
350
+ return 1;
351
+ }
352
+ if (a === '--global') globalRoot = path.resolve(v);
353
+ else projectRoot = path.resolve(v);
354
+ i += 1;
355
+ } else if (a === '--enforce') {
356
+ enforce = true;
357
+ } else if (a === '--help' || a === '-h') {
358
+ process.stdout.write(
359
+ 'usage: check_single_delivery [--global DIR] [--project DIR] [--enforce]\n' +
360
+ '\n' +
361
+ 'Reports by default and exits 0: the invariant is not true yet, because\n' +
362
+ 'road-to-single-delivery Phase 2 is halted on partition-requires-global-layer.\n' +
363
+ '--enforce exits 1 on any overlap, and is what to register once Phase 2 lands.\n',
364
+ );
365
+ return 0;
366
+ } else if (a !== undefined) {
367
+ // R2 finding: this used to reject only `--`-prefixed tokens, so
368
+ // `-enforce` (one dash) and a bare positional both fell through
369
+ // SILENTLY — the gate then reported without enforcing while the caller
370
+ // believed it had asked for enforcement. A typo that turns a blocking
371
+ // gate advisory is worse than a crash, so anything unrecognised is an
372
+ // error, dash or not.
373
+ process.stderr.write(
374
+ `check_single_delivery: unexpected argument ${a}` +
375
+ ' (did you mean --enforce, --global DIR or --project DIR?)\n',
376
+ );
377
+ return 1;
378
+ }
379
+ }
380
+
381
+ const v = evaluate(globalRoot, projectRoot);
382
+ process.stdout.write(`${render(v, globalRoot, projectRoot)}\n`);
383
+ // Dead-scope assertion via the shared primitive rather than a hand-rolled
384
+ // `scanned:` line: `check_gate_coverage`'s hardening ratchet accepts an
385
+ // emitted line only from a gate registered in the enforced manifest, and this
386
+ // one is deliberately unregistered while step 4.3's binding surface is an open
387
+ // blocker. No `allowEmpty` reason — see the `namesRead` docstring for why zero
388
+ // is blindness here rather than a valid empty corpus.
389
+ //
390
+ // Caught rather than allowed to propagate: an uncaught `DeadScopeError` prints
391
+ // a Node stack trace, which is the correct exit code wearing an unusable
392
+ // message. The error carries the gate name and the roots, so printing it plus
393
+ // the repoint hint gives the reader what the trace was burying.
394
+ reportScanned({
395
+ gate: 'check_single_delivery',
396
+ scanned: v.namesRead,
397
+ units: 'artefact name(s) across both layers',
398
+ roots: [globalRoot, projectRoot],
399
+ // R2 finding 1: without this reason the gate returned 1 UNCONDITIONALLY
400
+ // wherever it is meant to be bound. `.claude/` is gitignored and no CI leg
401
+ // installs at user scope, so `namesRead` is 0 there, the DeadScopeError
402
+ // fired before both the `readNothing` branch and `--enforce`, and the
403
+ // gate contradicted its own `--help` ("Reports by default and exits 0").
404
+ //
405
+ // OPTIONAL_SURFACE is the correct one of the three prefixes: these two
406
+ // directories are an INSTALL-TIME surface, not a corpus this repo owns.
407
+ // Applying the doc's operational test — if the scan root were deleted,
408
+ // would the reason still make sense? — yes: no layers installed means
409
+ // there is no delivery to duplicate, which is a true answer rather than
410
+ // blindness. The blindness case is narrower and is still refused below:
411
+ // layers that exist but never pair up (`readNothing`).
412
+ allowEmpty:
413
+ 'OPTIONAL_SURFACE: both host layers are install-time surfaces, absent by' +
414
+ ' construction in CI (.claude/ is gitignored) and on any machine that has' +
415
+ ' not installed. Zero names means nothing is delivered, so nothing can be' +
416
+ ' delivered twice — a true verdict, not a dead scope. The unverifiable' +
417
+ ' case (layers present but never paired) is refused separately.',
418
+ });
419
+
420
+ if (v.readNothing) {
421
+ // Never a pass. A gate that compared nothing has not verified anything,
422
+ // and saying "invariant holds" here is the false-green shape this repo
423
+ // has recorded from other gates.
424
+ process.stdout.write(
425
+ '⚠️ check_single_delivery: no artefact type had BOTH layers present, so nothing was' +
426
+ ' compared. This is NOT a pass — repoint with --global/--project.\n',
427
+ );
428
+ return enforce ? 1 : 0;
429
+ }
430
+
431
+ if (v.duplicated === 0 && v.defeated === 0 && v.nameOverlapDifferentShape === 0) {
432
+ process.stdout.write('✅ check_single_delivery: one artefact, one layer — no overlap.\n');
433
+ return 0;
434
+ }
435
+
436
+ const parts: string[] = [];
437
+ if (v.duplicated > 0) parts.push(`${v.duplicated} artefact(s) delivered twice`);
438
+ if (v.nameOverlapDifferentShape > 0) {
439
+ parts.push(
440
+ `${v.nameOverlapDifferentShape} name collision(s) across layers of DIFFERENT shape` +
441
+ ' (a delivery collision, not a duplicated artefact)',
442
+ );
443
+ }
444
+ if (v.defeated > 0) {
445
+ parts.push(`${v.defeated} shared rule(s) with defeated \`paths:\` scoping`);
446
+ }
447
+ const detail = parts.join(', and ');
448
+ if (enforce) {
449
+ process.stdout.write(`❌ check_single_delivery: ${detail}. Invariant ADR-236 violated.\n`);
450
+ return 1;
451
+ }
452
+ process.stdout.write(
453
+ `⚠️ check_single_delivery: ${detail}. Reported, not enforced — ` +
454
+ 'road-to-single-delivery Phase 2 is halted on `partition-requires-global-layer`, ' +
455
+ 'so this is a known-open defect rather than a regression. Re-run with --enforce ' +
456
+ 'once the partition ships.\n',
457
+ );
458
+ return 0;
459
+ }
460
+
461
+ function _isCliEntry(): boolean {
462
+ if (process.argv[1] === undefined) return false;
463
+ if (import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) return true;
464
+ try {
465
+ return fs.realpathSync(_HERE) === fs.realpathSync(path.resolve(process.argv[1]));
466
+ } catch {
467
+ return false;
468
+ }
469
+ }
470
+
471
+ if (_isCliEntry()) {
472
+ process.exit(main());
473
+ }
@@ -97,6 +97,34 @@ export function claudeAdditionalContext(event: string, text: string): string {
97
97
  })}\n`;
98
98
  }
99
99
 
100
+ /**
101
+ * Will `emitFor` actually put the reasons on a stream?
102
+ *
103
+ * The per-turn injection ceiling (`injection_budget.ts`) may only charge bytes
104
+ * the host receives. Two branches of `emitFor` below emit nothing REGARDLESS of
105
+ * the reasons, and those are the two this predicate answers for: an unverified
106
+ * platform (legacy pass-through) and `severity: allow`. The budget module
107
+ * originally covered only the first, which let an `allow` dispatch spend the turn
108
+ * on output nobody got — and a crashed non-`fail_closed` concern is fail-opened
109
+ * to exactly that verdict with its stack trace as the largest candidate.
110
+ *
111
+ * A THIRD non-emitting case exists and this predicate deliberately does not claim
112
+ * it: a `warn` whose joined reason comes out empty, because `_joinReasons` trims
113
+ * and drops blanks, so a whitespace-only advisory text emits nothing either. It
114
+ * is content-dependent rather than a property of `(platform, severity)`, so a
115
+ * predicate with this signature cannot decide it — stated here rather than left
116
+ * to be discovered, since an R2 review found the earlier "TWO branches" wording
117
+ * asserting a completeness it did not have.
118
+ *
119
+ * Kept beside `emitFor` deliberately rather than re-derived at the call site:
120
+ * the predicate is only correct while it mirrors the function below it, and a
121
+ * copy one module away is a copy that drifts.
122
+ */
123
+ export function emissionCarriesReasons(platform: string, severity: Severity): boolean {
124
+ if (!VERIFIED_PLATFORMS.has(platform)) return false;
125
+ return severity !== "allow";
126
+ }
127
+
100
128
  /**
101
129
  * Translate (platform, event, severity, reasons) into a native emission.
102
130
  *