instar 1.3.889 → 1.3.891

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 (126) hide show
  1. package/dashboard/glance.js +1 -0
  2. package/dashboard/index.html +93 -0
  3. package/dist/commands/server.d.ts.map +1 -1
  4. package/dist/commands/server.js +99 -1
  5. package/dist/commands/server.js.map +1 -1
  6. package/dist/config/ConfigDefaults.d.ts.map +1 -1
  7. package/dist/config/ConfigDefaults.js +14 -0
  8. package/dist/config/ConfigDefaults.js.map +1 -1
  9. package/dist/core/BackupManager.d.ts.map +1 -1
  10. package/dist/core/BackupManager.js +22 -15
  11. package/dist/core/BackupManager.js.map +1 -1
  12. package/dist/core/InitiativeTracker.d.ts +7 -0
  13. package/dist/core/InitiativeTracker.d.ts.map +1 -1
  14. package/dist/core/InitiativeTracker.js +17 -0
  15. package/dist/core/InitiativeTracker.js.map +1 -1
  16. package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
  17. package/dist/core/PostUpdateMigrator.js +8 -0
  18. package/dist/core/PostUpdateMigrator.js.map +1 -1
  19. package/dist/core/WriteDomainRegistry.d.ts.map +1 -1
  20. package/dist/core/WriteDomainRegistry.js +12 -0
  21. package/dist/core/WriteDomainRegistry.js.map +1 -1
  22. package/dist/core/canonicalPipelineRegistry.d.ts +73 -0
  23. package/dist/core/canonicalPipelineRegistry.d.ts.map +1 -0
  24. package/dist/core/canonicalPipelineRegistry.js +56 -0
  25. package/dist/core/canonicalPipelineRegistry.js.map +1 -0
  26. package/dist/core/canonicalPipelineRuntimeEvidence.d.ts +13 -0
  27. package/dist/core/canonicalPipelineRuntimeEvidence.d.ts.map +1 -0
  28. package/dist/core/canonicalPipelineRuntimeEvidence.js +15 -0
  29. package/dist/core/canonicalPipelineRuntimeEvidence.js.map +1 -0
  30. package/dist/core/componentCategories.d.ts.map +1 -1
  31. package/dist/core/componentCategories.js +1 -0
  32. package/dist/core/componentCategories.js.map +1 -1
  33. package/dist/core/devGatedFeatures.d.ts.map +1 -1
  34. package/dist/core/devGatedFeatures.js +24 -0
  35. package/dist/core/devGatedFeatures.js.map +1 -1
  36. package/dist/core/types.d.ts +24 -1
  37. package/dist/core/types.d.ts.map +1 -1
  38. package/dist/core/types.js.map +1 -1
  39. package/dist/core/version-skew.d.ts +1 -1
  40. package/dist/core/version-skew.d.ts.map +1 -1
  41. package/dist/data/llmBenchCoverage.d.ts.map +1 -1
  42. package/dist/data/llmBenchCoverage.js +6 -0
  43. package/dist/data/llmBenchCoverage.js.map +1 -1
  44. package/dist/data/provenanceCoverage.d.ts +2 -0
  45. package/dist/data/provenanceCoverage.d.ts.map +1 -1
  46. package/dist/data/provenanceCoverage.js +10 -0
  47. package/dist/data/provenanceCoverage.js.map +1 -1
  48. package/dist/feedback-factory/drain/FeedbackConsumerPromotionStore.d.ts +18 -0
  49. package/dist/feedback-factory/drain/FeedbackConsumerPromotionStore.d.ts.map +1 -0
  50. package/dist/feedback-factory/drain/FeedbackConsumerPromotionStore.js +51 -0
  51. package/dist/feedback-factory/drain/FeedbackConsumerPromotionStore.js.map +1 -0
  52. package/dist/feedback-factory/drain/FeedbackDrainBackupCadence.d.ts +20 -0
  53. package/dist/feedback-factory/drain/FeedbackDrainBackupCadence.d.ts.map +1 -0
  54. package/dist/feedback-factory/drain/FeedbackDrainBackupCadence.js +28 -0
  55. package/dist/feedback-factory/drain/FeedbackDrainBackupCadence.js.map +1 -0
  56. package/dist/feedback-factory/drain/FeedbackDrainPosture.d.ts +14 -0
  57. package/dist/feedback-factory/drain/FeedbackDrainPosture.d.ts.map +1 -0
  58. package/dist/feedback-factory/drain/FeedbackDrainPosture.js +15 -0
  59. package/dist/feedback-factory/drain/FeedbackDrainPosture.js.map +1 -0
  60. package/dist/feedback-factory/drain/FeedbackDrainService.d.ts +121 -0
  61. package/dist/feedback-factory/drain/FeedbackDrainService.d.ts.map +1 -0
  62. package/dist/feedback-factory/drain/FeedbackDrainService.js +370 -0
  63. package/dist/feedback-factory/drain/FeedbackDrainService.js.map +1 -0
  64. package/dist/feedback-factory/drain/FeedbackDrainStore.d.ts +369 -0
  65. package/dist/feedback-factory/drain/FeedbackDrainStore.d.ts.map +1 -0
  66. package/dist/feedback-factory/drain/FeedbackDrainStore.js +1125 -0
  67. package/dist/feedback-factory/drain/FeedbackDrainStore.js.map +1 -0
  68. package/dist/feedback-factory/drain/FeedbackDrainTickProxy.d.ts +67 -0
  69. package/dist/feedback-factory/drain/FeedbackDrainTickProxy.d.ts.map +1 -0
  70. package/dist/feedback-factory/drain/FeedbackDrainTickProxy.js +151 -0
  71. package/dist/feedback-factory/drain/FeedbackDrainTickProxy.js.map +1 -0
  72. package/dist/feedback-factory/drain/FeedbackFactoryGeneratedDefaults.d.ts +32 -0
  73. package/dist/feedback-factory/drain/FeedbackFactoryGeneratedDefaults.d.ts.map +1 -0
  74. package/dist/feedback-factory/drain/FeedbackFactoryGeneratedDefaults.js +47 -0
  75. package/dist/feedback-factory/drain/FeedbackFactoryGeneratedDefaults.js.map +1 -0
  76. package/dist/feedback-factory/drain/FeedbackInitiativeConsumer.d.ts +33 -0
  77. package/dist/feedback-factory/drain/FeedbackInitiativeConsumer.d.ts.map +1 -0
  78. package/dist/feedback-factory/drain/FeedbackInitiativeConsumer.js +71 -0
  79. package/dist/feedback-factory/drain/FeedbackInitiativeConsumer.js.map +1 -0
  80. package/dist/feedback-factory/drain/FeedbackReadinessArbiter.d.ts +36 -0
  81. package/dist/feedback-factory/drain/FeedbackReadinessArbiter.d.ts.map +1 -0
  82. package/dist/feedback-factory/drain/FeedbackReadinessArbiter.js +153 -0
  83. package/dist/feedback-factory/drain/FeedbackReadinessArbiter.js.map +1 -0
  84. package/dist/feedback-factory/drain/index.d.ts +2 -0
  85. package/dist/feedback-factory/drain/index.d.ts.map +1 -0
  86. package/dist/feedback-factory/drain/index.js +2 -0
  87. package/dist/feedback-factory/drain/index.js.map +1 -0
  88. package/dist/feedback-factory/processing/FeedbackProcessingService.d.ts +14 -0
  89. package/dist/feedback-factory/processing/FeedbackProcessingService.d.ts.map +1 -1
  90. package/dist/feedback-factory/processing/FeedbackProcessingService.js +25 -4
  91. package/dist/feedback-factory/processing/FeedbackProcessingService.js.map +1 -1
  92. package/dist/feedback-factory/store/FeedbackSourceGenerations.d.ts +39 -0
  93. package/dist/feedback-factory/store/FeedbackSourceGenerations.d.ts.map +1 -0
  94. package/dist/feedback-factory/store/FeedbackSourceGenerations.js +288 -0
  95. package/dist/feedback-factory/store/FeedbackSourceGenerations.js.map +1 -0
  96. package/dist/feedback-factory/store/JsonlFeedbackStore.d.ts +26 -6
  97. package/dist/feedback-factory/store/JsonlFeedbackStore.d.ts.map +1 -1
  98. package/dist/feedback-factory/store/JsonlFeedbackStore.js +139 -25
  99. package/dist/feedback-factory/store/JsonlFeedbackStore.js.map +1 -1
  100. package/dist/monitoring/AutonomousThroughputFloor.d.ts +118 -0
  101. package/dist/monitoring/AutonomousThroughputFloor.d.ts.map +1 -0
  102. package/dist/monitoring/AutonomousThroughputFloor.js +147 -0
  103. package/dist/monitoring/AutonomousThroughputFloor.js.map +1 -0
  104. package/dist/scaffold/templates.d.ts.map +1 -1
  105. package/dist/scaffold/templates.js +4 -0
  106. package/dist/scaffold/templates.js.map +1 -1
  107. package/dist/server/AgentServer.d.ts +4 -0
  108. package/dist/server/AgentServer.d.ts.map +1 -1
  109. package/dist/server/AgentServer.js +193 -1
  110. package/dist/server/AgentServer.js.map +1 -1
  111. package/dist/server/routes.d.ts +33 -0
  112. package/dist/server/routes.d.ts.map +1 -1
  113. package/dist/server/routes.js +288 -0
  114. package/dist/server/routes.js.map +1 -1
  115. package/package.json +5 -2
  116. package/scripts/lint-canonical-pipeline-completeness.mjs +265 -0
  117. package/src/data/builtin-manifest.json +65 -65
  118. package/src/data/llmBenchCoverage.ts +6 -0
  119. package/src/data/provenanceCoverage.ts +12 -0
  120. package/src/data/state-coherence-registry.json +18 -0
  121. package/src/scaffold/templates/jobs/instar/feedback-factory-process.md +13 -12
  122. package/src/scaffold/templates.ts +4 -0
  123. package/upgrades/1.3.890.md +19 -0
  124. package/upgrades/1.3.891.md +30 -0
  125. package/upgrades/side-effects/autonomous-throughput-floor.md +36 -0
  126. package/upgrades/side-effects/feedback-factory-operating-drain.md +110 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "1.3.889",
3
+ "version": "1.3.891",
4
4
  "description": "Coherence infrastructure for self-evolving AI agents — on the Claude Code or Codex subscription you already have.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,10 @@
28
28
  "test:contract": "node scripts/run-contract-tests.js",
29
29
  "test:contract:raw": "vitest run --config vitest.contract.config.ts",
30
30
  "test:all": "vitest run && vitest run --config vitest.integration.config.ts && vitest run --config vitest.e2e.config.ts",
31
- "lint": "tsc --noEmit && node scripts/lint-no-direct-destructive.js && node scripts/lint-no-direct-llm-http.js && node scripts/lint-no-direct-url-log.js && node scripts/lint-no-unfunneled-topic-creation.js && node scripts/lint-no-unfunneled-headless-launch.js && node scripts/lint-no-unbounded-llm-spawn.js && node scripts/lint-no-unregistered-self-action.js && node scripts/lint-no-unfunneled-credential-write.js && node scripts/lint-state-registry.js && node scripts/lint-store-retention-declared.js && node scripts/lint-no-wholefile-sync-read.js && node scripts/lint-cas-emit-placement.js && node scripts/lint-journal-actuation-ban.js && node scripts/lint-no-blocking-process-scans.js && node scripts/lint-sync-subprocess-chokepoint.js && node scripts/lint-dev-agent-dark-gate.js && node scripts/lint-guard-manifest.js && node scripts/lint-llm-attribution.js && node scripts/lint-no-mainthread-cartographer-walk.js && node scripts/lint-scrape-fixture-realness.js && node scripts/check-codex-rule1-drift.js && node scripts/lint-routing-registry-freshness.js && node scripts/lint-no-opus-claude-cli-gating.js && node scripts/lint-model-registry-freshness.mjs && node scripts/lint-no-unreachable-messaging-gate.js && node scripts/lint-nature-chains.mjs && node scripts/lint-emit-without-admit.js && node scripts/lint-migration-consumer-completeness.js && node scripts/lint-expected-capacity-degradations.js",
31
+ "lint": "tsc --noEmit && node scripts/lint-no-direct-destructive.js && node scripts/lint-no-direct-llm-http.js && node scripts/lint-no-direct-url-log.js && node scripts/lint-no-unfunneled-topic-creation.js && node scripts/lint-no-unfunneled-headless-launch.js && node scripts/lint-no-unbounded-llm-spawn.js && node scripts/lint-no-unregistered-self-action.js && node scripts/lint-no-unfunneled-credential-write.js && node scripts/lint-state-registry.js && node scripts/lint-store-retention-declared.js && node scripts/lint-no-wholefile-sync-read.js && node scripts/lint-cas-emit-placement.js && node scripts/lint-journal-actuation-ban.js && node scripts/lint-no-blocking-process-scans.js && node scripts/lint-sync-subprocess-chokepoint.js && node scripts/lint-dev-agent-dark-gate.js && node scripts/lint-guard-manifest.js && node scripts/lint-llm-attribution.js && node scripts/lint-no-mainthread-cartographer-walk.js && node scripts/lint-scrape-fixture-realness.js && node scripts/check-codex-rule1-drift.js && node scripts/lint-routing-registry-freshness.js && node scripts/lint-no-opus-claude-cli-gating.js && node scripts/lint-model-registry-freshness.mjs && node scripts/lint-no-unreachable-messaging-gate.js && node scripts/lint-nature-chains.mjs && node scripts/lint-emit-without-admit.js && node scripts/lint-migration-consumer-completeness.js && node scripts/lint-canonical-pipeline-completeness.mjs && node scripts/lint-expected-capacity-degradations.js",
32
+ "lint:canonical-pipeline-completeness": "node scripts/lint-canonical-pipeline-completeness.mjs",
33
+ "test:canonical-pipeline-runtime": "vitest run --config vitest.e2e.config.ts tests/e2e/feedback-factory-drain-lifecycle.test.ts && vitest run tests/unit/canonical-pipeline-completeness-lint.test.ts tests/unit/canonical-pipeline-runtime-evidence.test.ts",
34
+ "test:feedback-drain-performance": "vitest run tests/integration/feedback-drain-performance.test.ts",
32
35
  "lint:routing-registry": "node scripts/lint-routing-registry-freshness.js",
33
36
  "lint:no-opus-claude-cli-gating": "node scripts/lint-no-opus-claude-cli-gating.js",
34
37
  "lint:nature-chains": "node scripts/lint-nature-chains.mjs",
@@ -0,0 +1,265 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Structural coverage guard for Canonical Pipeline Operational Completeness.
4
+ *
5
+ * This lint proves declaration coverage and citation integrity only. Runtime
6
+ * liveness, effective idempotency, cadence, and semantic completeness belong to
7
+ * the collected smoke/E2E contracts and review authority.
8
+ */
9
+
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ import ts from 'typescript';
14
+
15
+ const SCRIPT_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
16
+ const MANIFEST_PATH = 'docs/canonical-pipelines.json';
17
+ const REGISTRY_PATH = 'src/core/canonicalPipelineRegistry.ts';
18
+ const ID_RE = /^[a-z0-9][a-z0-9-]*$/;
19
+
20
+ /** @typedef {{rule:string,message:string,path?:string,id?:string}} Finding */
21
+
22
+ /** @param {unknown} value */
23
+ const nonEmpty = (value) => typeof value === 'string' && value.trim().length > 0;
24
+
25
+ /** @param {string} citation */
26
+ export function splitCitation(citation) {
27
+ if (!nonEmpty(citation)) return null;
28
+ const separator = citation.lastIndexOf('#');
29
+ if (separator <= 0 || separator === citation.length - 1) return null;
30
+ return { path: citation.slice(0, separator), symbol: citation.slice(separator + 1) };
31
+ }
32
+
33
+ /** @param {unknown} manifest @returns {Finding[]} */
34
+ export function validateCanonicalPipelineManifest(manifest) {
35
+ /** @type {Finding[]} */
36
+ const findings = [];
37
+ if (!manifest || typeof manifest !== 'object') {
38
+ return [{ rule: 'CPC0-manifest-shape', message: 'manifest must be an object' }];
39
+ }
40
+ const candidate = /** @type {Record<string, unknown>} */ (manifest);
41
+ if (candidate.schemaVersion !== 1) {
42
+ findings.push({ rule: 'CPC0-manifest-shape', message: 'schemaVersion must equal 1' });
43
+ }
44
+ if (!Array.isArray(candidate.pipelines) || candidate.pipelines.length === 0) {
45
+ findings.push({ rule: 'CPC0-manifest-shape', message: 'pipelines must be a non-empty array' });
46
+ return findings;
47
+ }
48
+ const ids = new Set();
49
+ for (const raw of candidate.pipelines) {
50
+ const pipeline = /** @type {Record<string, any>} */ (raw);
51
+ if (!ID_RE.test(pipeline?.id ?? '') || ids.has(pipeline.id)) {
52
+ findings.push({ rule: 'CPC0-pipeline-id', id: pipeline?.id, message: 'pipeline id must be unique kebab-case' });
53
+ continue;
54
+ }
55
+ ids.add(pipeline.id);
56
+ if (!nonEmpty(pipeline.owner)) {
57
+ findings.push({ rule: 'CPC1-owner-required', id: pipeline.id, message: `${pipeline.id} must declare an owner` });
58
+ }
59
+ if (!Array.isArray(pipeline.stages) || pipeline.stages.length < 2) {
60
+ findings.push({ rule: 'CPC2-stages-required', id: pipeline.id, message: `${pipeline.id} must declare at least two ordered stages` });
61
+ continue;
62
+ }
63
+ const stageIds = pipeline.stages.map((stage) => stage?.id);
64
+ if (stageIds.some((id) => !ID_RE.test(id ?? '')) || new Set(stageIds).size !== stageIds.length) {
65
+ findings.push({ rule: 'CPC2-stage-id', id: pipeline.id, message: `${pipeline.id} stage ids must be unique kebab-case` });
66
+ }
67
+ for (const stage of pipeline.stages) {
68
+ for (const field of ['metadataCitation', 'implementationCitation']) {
69
+ if (!splitCitation(stage?.[field])) {
70
+ findings.push({ rule: 'CPC3-stage-citation', id: pipeline.id, message: `${pipeline.id}.${stage?.id ?? '(stage)'}.${field} must be path#symbol` });
71
+ }
72
+ }
73
+ }
74
+ if (!Array.isArray(pipeline.ingress?.surfaceIds) || pipeline.ingress.surfaceIds.length === 0 || !splitCitation(pipeline.ingress?.wiringCitation)) {
75
+ findings.push({ rule: 'CPC4-ingress-required', id: pipeline.id, message: `${pipeline.id} must declare ingress surface ids and wiring citation` });
76
+ }
77
+ const expectedEdges = stageIds.slice(0, -1).map((from, index) => `${from}\0${stageIds[index + 1]}`);
78
+ const transitions = Array.isArray(pipeline.transitions) ? pipeline.transitions : [];
79
+ const actualEdges = transitions.map((edge) => `${edge?.from}\0${edge?.to}`);
80
+ if (transitions.length !== expectedEdges.length || expectedEdges.some((edge) => !actualEdges.includes(edge))) {
81
+ findings.push({ rule: 'CPC5-transition-coverage', id: pipeline.id, message: `${pipeline.id} must declare every adjacent stage transition exactly once` });
82
+ }
83
+ for (const transition of transitions) {
84
+ if (!splitCitation(transition?.implementationCitation) || !nonEmpty(transition?.persistentState) || !nonEmpty(transition?.idempotencyKey)) {
85
+ findings.push({ rule: 'CPC5-transition-contract', id: pipeline.id, message: `${pipeline.id} transition ${transition?.from ?? '?'} -> ${transition?.to ?? '?'} needs implementation, persistent state, and idempotency key` });
86
+ }
87
+ }
88
+ const terminal = pipeline.terminalHandoff;
89
+ if (terminal?.stage !== stageIds.at(-1) || !nonEmpty(terminal?.consumer) || !splitCitation(terminal?.consumerCitation)) {
90
+ findings.push({ rule: 'CPC6-terminal-consumer', id: pipeline.id, message: `${pipeline.id} must name a cited consumer at its final stage` });
91
+ }
92
+ if (!splitCitation(pipeline.cadence?.triggerCitation)) {
93
+ findings.push({ rule: 'CPC7-cadence-citation', id: pipeline.id, message: `${pipeline.id} must cite an operated cadence/trigger` });
94
+ }
95
+ if (!splitCitation(pipeline.metrics?.readinessCitation)) {
96
+ findings.push({ rule: 'CPC8-metrics-citation', id: pipeline.id, message: `${pipeline.id} must cite metrics/readiness` });
97
+ }
98
+ const smoke = pipeline.runtimeSmoke;
99
+ if (!nonEmpty(smoke?.test) || !nonEmpty(smoke?.command) || smoke?.productionConsumerAdapter !== true || smoke?.authoritativeReadBack !== true) {
100
+ findings.push({ rule: 'CPC9-runtime-contract', id: pipeline.id, message: `${pipeline.id} must declare a production-adapter authoritative-read-back runtime smoke/E2E` });
101
+ }
102
+ if (!nonEmpty(pipeline.rollout?.posture) || !nonEmpty(pipeline.rollout?.rollbackSwitch)) {
103
+ findings.push({ rule: 'CPC10-rollout-contract', id: pipeline.id, message: `${pipeline.id} must declare rollout posture and rollback switch` });
104
+ }
105
+ }
106
+ return findings;
107
+ }
108
+
109
+ /**
110
+ * Read the closed TypeScript intake registry without executing repository code.
111
+ * @param {string} filePath
112
+ */
113
+ export function parseIntakeRegistry(filePath) {
114
+ const text = fs.readFileSync(filePath, 'utf8');
115
+ const source = ts.createSourceFile(filePath, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
116
+ /** @type {Record<string, string>[]} */
117
+ const declarations = [];
118
+ const literal = (node) => ts.isStringLiteral(node) ? node.text : undefined;
119
+ const visit = (node) => {
120
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === 'CANONICAL_INTAKE_SURFACES') {
121
+ let initializer = node.initializer;
122
+ while (initializer && (ts.isAsExpression(initializer) || ts.isSatisfiesExpression(initializer))) initializer = initializer.expression;
123
+ if (!initializer || !ts.isArrayLiteralExpression(initializer)) return;
124
+ for (const element of initializer.elements) {
125
+ if (!ts.isObjectLiteralExpression(element)) continue;
126
+ const record = {};
127
+ for (const property of element.properties) {
128
+ if (!ts.isPropertyAssignment(property)) continue;
129
+ const key = ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : undefined;
130
+ const value = literal(property.initializer);
131
+ if (key && value !== undefined) record[key] = value;
132
+ }
133
+ declarations.push(record);
134
+ }
135
+ }
136
+ ts.forEachChild(node, visit);
137
+ };
138
+ visit(source);
139
+ return declarations;
140
+ }
141
+
142
+ /**
143
+ * @param {{root:string, manifest:any, intakeDeclarations:Record<string,string>[], readText?:(path:string)=>string|undefined, pathExists?:(path:string)=>boolean}} input
144
+ * @returns {Finding[]}
145
+ */
146
+ export function auditCanonicalPipelineCompleteness(input) {
147
+ const findings = [...validateCanonicalPipelineManifest(input.manifest)];
148
+ if (findings.some((finding) => finding.rule === 'CPC0-manifest-shape')) return findings;
149
+ const pipelines = new Map((input.manifest.pipelines ?? []).map((pipeline) => [pipeline.id, pipeline]));
150
+ const declarations = new Map();
151
+ const readText = input.readText ?? ((relativePath) => {
152
+ try { return fs.readFileSync(path.join(input.root, relativePath), 'utf8'); } catch { return undefined; }
153
+ });
154
+ const pathExists = input.pathExists ?? ((relativePath) => fs.existsSync(path.join(input.root, relativePath)));
155
+
156
+ for (const surface of input.intakeDeclarations) {
157
+ if (!nonEmpty(surface.id) || declarations.has(surface.id)) {
158
+ findings.push({ rule: 'CPC11-intake-id', id: surface.id, message: 'intake surface id must be non-empty and unique' });
159
+ continue;
160
+ }
161
+ declarations.set(surface.id, surface);
162
+ const canonical = nonEmpty(surface.canonicalPipelineId);
163
+ const excluded = nonEmpty(surface.nonCanonicalReason);
164
+ if (canonical === excluded) {
165
+ findings.push({ rule: 'CPC12-intake-classification', id: surface.id, message: `${surface.id} must declare exactly one canonicalPipelineId or nonCanonicalReason` });
166
+ }
167
+ if (canonical && !pipelines.has(surface.canonicalPipelineId)) {
168
+ findings.push({ rule: 'CPC12-unknown-pipeline', id: surface.id, message: `${surface.id} names unregistered pipeline ${surface.canonicalPipelineId}` });
169
+ }
170
+ if (excluded && (!nonEmpty(surface.owner) || surface.nonCanonicalReason.length < 12 || !/^\d{4}-\d{2}-\d{2}$/.test(surface.expiresAt ?? ''))) {
171
+ findings.push({ rule: 'CPC13-exclusion-contract', id: surface.id, message: `${surface.id} exclusion needs owner, substantive reason, and YYYY-MM-DD expiry` });
172
+ }
173
+ const source = readText(surface.sourcePath);
174
+ if (!source) {
175
+ findings.push({ rule: 'CPC14-intake-source-missing', id: surface.id, path: surface.sourcePath, message: `${surface.id} source path is missing` });
176
+ } else {
177
+ const needle = surface.kind === 'route' ? surface.route : surface.jobSlug;
178
+ if (!nonEmpty(needle) || !source.includes(needle)) {
179
+ findings.push({ rule: 'CPC14-intake-wiring-missing', id: surface.id, path: surface.sourcePath, message: `${surface.id} declared route/job is absent from its source` });
180
+ }
181
+ }
182
+ }
183
+
184
+ const citations = [];
185
+ for (const pipeline of input.manifest.pipelines ?? []) {
186
+ for (const surfaceId of pipeline.ingress?.surfaceIds ?? []) {
187
+ const surface = declarations.get(surfaceId);
188
+ if (!surface || surface.canonicalPipelineId !== pipeline.id) {
189
+ findings.push({ rule: 'CPC15-ingress-registry-link', id: pipeline.id, message: `${pipeline.id} ingress ${surfaceId} is missing or classified elsewhere` });
190
+ }
191
+ }
192
+ for (const stage of pipeline.stages ?? []) {
193
+ citations.push(stage.metadataCitation, stage.implementationCitation);
194
+ const metadata = splitCitation(stage.metadataCitation);
195
+ const source = metadata ? readText(metadata.path) : undefined;
196
+ if (metadata && source) {
197
+ const symbolOffset = source.indexOf(metadata.symbol);
198
+ const declaration = symbolOffset >= 0 ? source.slice(symbolOffset, symbolOffset + 700) : '';
199
+ const pipelinePattern = new RegExp(`canonicalPipelineId\\s*:\\s*['\"]${pipeline.id}['\"]`);
200
+ const stagePattern = new RegExp(`stage\\s*:\\s*['\"]${stage.id}['\"]`);
201
+ if (!pipelinePattern.test(declaration) || !stagePattern.test(declaration)) {
202
+ findings.push({
203
+ rule: 'CPC3-stage-metadata-mismatch', id: pipeline.id, path: metadata.path,
204
+ message: `${stage.metadataCitation} must declare canonicalPipelineId ${pipeline.id} and stage ${stage.id}`,
205
+ });
206
+ }
207
+ }
208
+ }
209
+ for (const edge of pipeline.transitions ?? []) citations.push(edge.implementationCitation);
210
+ citations.push(pipeline.ingress?.wiringCitation, pipeline.terminalHandoff?.consumerCitation, pipeline.cadence?.triggerCitation, pipeline.metrics?.readinessCitation);
211
+
212
+ const testPath = pipeline.runtimeSmoke?.test;
213
+ if (nonEmpty(testPath) && !pathExists(testPath)) {
214
+ findings.push({ rule: 'CPC16-runtime-test-missing', id: pipeline.id, path: testPath, message: `${pipeline.id} runtime smoke/E2E path is missing` });
215
+ }
216
+ const packageText = readText('package.json');
217
+ let packageJson;
218
+ try { packageJson = packageText ? JSON.parse(packageText) : null; } catch { packageJson = null; }
219
+ const command = pipeline.runtimeSmoke?.command;
220
+ const script = packageJson?.scripts?.[command];
221
+ if (!nonEmpty(command) || !nonEmpty(script) || !script.includes(testPath)) {
222
+ findings.push({ rule: 'CPC17-runtime-test-uncollected', id: pipeline.id, path: testPath, message: `${pipeline.id} runtime test must be collected by package script ${command ?? '(missing)'}` });
223
+ }
224
+ }
225
+
226
+ for (const rawCitation of citations) {
227
+ const citation = splitCitation(rawCitation);
228
+ if (!citation) continue;
229
+ const source = readText(citation.path);
230
+ if (!source) {
231
+ findings.push({ rule: 'CPC18-citation-path-missing', path: citation.path, message: `citation path is missing: ${rawCitation}` });
232
+ } else if (!source.includes(citation.symbol)) {
233
+ findings.push({ rule: 'CPC18-citation-symbol-missing', path: citation.path, message: `citation symbol/token is missing: ${rawCitation}` });
234
+ }
235
+ }
236
+ return findings;
237
+ }
238
+
239
+ function main() {
240
+ const args = process.argv.slice(2);
241
+ const rootIndex = args.indexOf('--root');
242
+ const root = rootIndex >= 0 && args[rootIndex + 1] ? path.resolve(args[rootIndex + 1]) : SCRIPT_ROOT;
243
+ let manifest;
244
+ try { manifest = JSON.parse(fs.readFileSync(path.join(root, MANIFEST_PATH), 'utf8')); }
245
+ catch (error) {
246
+ console.error(`CPC0-manifest-missing-or-invalid: ${error instanceof Error ? error.message : String(error)}`);
247
+ process.exit(1);
248
+ }
249
+ let intakeDeclarations;
250
+ try { intakeDeclarations = parseIntakeRegistry(path.join(root, REGISTRY_PATH)); }
251
+ catch (error) {
252
+ console.error(`CPC0-intake-registry-invalid: ${error instanceof Error ? error.message : String(error)}`);
253
+ process.exit(1);
254
+ }
255
+ const findings = auditCanonicalPipelineCompleteness({ root, manifest, intakeDeclarations });
256
+ if (findings.length === 0) {
257
+ console.log('lint-canonical-pipeline-completeness: clean (structural coverage evidence only)');
258
+ return;
259
+ }
260
+ console.error(`lint-canonical-pipeline-completeness: ${findings.length} finding(s)`);
261
+ for (const finding of findings) console.error(` ${finding.rule}${finding.path ? ` ${finding.path}` : ''}: ${finding.message}`);
262
+ process.exit(1);
263
+ }
264
+
265
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();