@nimiplatform/nimi-coding 0.2.7 → 0.3.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 (207) hide show
  1. package/CHANGELOG.md +8 -80
  2. package/CONTRIBUTING.md +5 -34
  3. package/README.md +47 -350
  4. package/README.zh-CN.md +33 -287
  5. package/cli/commands/start.mjs +48 -688
  6. package/cli/commands/validate-spec-audit.mjs +1 -5
  7. package/cli/constants.mjs +9 -417
  8. package/cli/dev/run-cli-smoke.mjs +24 -0
  9. package/cli/dev/run-suite.mjs +17 -0
  10. package/cli/help.mjs +28 -145
  11. package/cli/index.mjs +5 -33
  12. package/cli/lib/blueprint-audit.mjs +5 -12
  13. package/cli/lib/bootstrap.mjs +0 -9
  14. package/cli/lib/contracts.mjs +0 -163
  15. package/cli/lib/doctor.mjs +155 -10
  16. package/cli/lib/entrypoints.mjs +63 -167
  17. package/cli/lib/internal/contracts-loaders.mjs +0 -85
  18. package/cli/lib/internal/contracts-parse.mjs +84 -520
  19. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +13 -8
  20. package/cli/lib/internal/surface-taxonomy-validators.mjs +316 -66
  21. package/cli/lib/internal/validators-shared.mjs +0 -16
  22. package/cli/lib/internal/validators-spec-helpers.mjs +7 -140
  23. package/cli/lib/internal/validators-spec.mjs +103 -342
  24. package/cli/lib/shared.mjs +1 -42
  25. package/cli/lib/validators.mjs +0 -48
  26. package/cli/seeds/seed-policy.yaml +0 -3
  27. package/config/bootstrap.yaml +4 -4
  28. package/config/spec-generation-inputs.yaml +6 -12
  29. package/contracts/domain-admission.schema.yaml +3 -3
  30. package/contracts/migration-inventory.schema.yaml +12 -75
  31. package/contracts/negative-fixtures.yaml +19 -99
  32. package/contracts/placement-contract.schema.yaml +49 -78
  33. package/contracts/projection-edge.schema.yaml +37 -121
  34. package/contracts/shared-enums.yaml +4 -8
  35. package/contracts/spec-generation-inputs.schema.yaml +15 -112
  36. package/contracts/spec-layout.schema.yaml +32 -0
  37. package/contracts/surface-taxonomy.schema.yaml +43 -94
  38. package/contracts/table-family.schema.yaml +1 -1
  39. package/contracts/tracked-output-admission.schema.yaml +13 -66
  40. package/methodology/core.yaml +33 -25
  41. package/methodology/four-closure-policy.yaml +18 -26
  42. package/methodology/role-separation-policy.yaml +21 -27
  43. package/methodology/spec-reconstruction.yaml +17 -34
  44. package/package.json +4 -6
  45. package/spec/_meta/spec-tree-model.yaml +5 -101
  46. package/spec/product-scope.yaml +25 -57
  47. package/adapters/README.md +0 -25
  48. package/adapters/claude/README.md +0 -89
  49. package/adapters/claude/profile.yaml +0 -70
  50. package/adapters/codex/README.md +0 -53
  51. package/adapters/codex/profile.yaml +0 -78
  52. package/adapters/oh-my-codex/README.md +0 -184
  53. package/adapters/oh-my-codex/profile.yaml +0 -46
  54. package/cli/commands/admit-high-risk-decision.mjs +0 -108
  55. package/cli/commands/audit-sweep.mjs +0 -364
  56. package/cli/commands/closeout.mjs +0 -186
  57. package/cli/commands/decide-high-risk-execution.mjs +0 -124
  58. package/cli/commands/handoff.mjs +0 -123
  59. package/cli/commands/ingest-high-risk-execution.mjs +0 -95
  60. package/cli/commands/review-high-risk-execution.mjs +0 -95
  61. package/cli/commands/sweep-design.mjs +0 -295
  62. package/cli/commands/sweep.mjs +0 -22
  63. package/cli/commands/topic-formatters.mjs +0 -382
  64. package/cli/commands/topic-goal.mjs +0 -33
  65. package/cli/commands/topic-options-shared.mjs +0 -27
  66. package/cli/commands/topic-options-workflow.mjs +0 -767
  67. package/cli/commands/topic-options.mjs +0 -626
  68. package/cli/commands/topic-runner.mjs +0 -169
  69. package/cli/commands/topic.mjs +0 -795
  70. package/cli/commands/validate-acceptance.mjs +0 -5
  71. package/cli/commands/validate-execution-packet.mjs +0 -5
  72. package/cli/commands/validate-orchestration-state.mjs +0 -5
  73. package/cli/commands/validate-prompt.mjs +0 -5
  74. package/cli/commands/validate-worker-output.mjs +0 -5
  75. package/cli/lib/adapter-profiles.mjs +0 -403
  76. package/cli/lib/audit-execution.mjs +0 -52
  77. package/cli/lib/audit-sweep-runtime/admissions.mjs +0 -508
  78. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +0 -356
  79. package/cli/lib/audit-sweep-runtime/chunks.mjs +0 -697
  80. package/cli/lib/audit-sweep-runtime/claude-auditor.mjs +0 -647
  81. package/cli/lib/audit-sweep-runtime/closeout.mjs +0 -144
  82. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +0 -654
  83. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +0 -516
  84. package/cli/lib/audit-sweep-runtime/common.mjs +0 -341
  85. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +0 -172
  86. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +0 -155
  87. package/cli/lib/audit-sweep-runtime/format.mjs +0 -57
  88. package/cli/lib/audit-sweep-runtime/ingest.mjs +0 -486
  89. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +0 -425
  90. package/cli/lib/audit-sweep-runtime/inventory.mjs +0 -798
  91. package/cli/lib/audit-sweep-runtime/ledger.mjs +0 -315
  92. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +0 -101
  93. package/cli/lib/audit-sweep-runtime/remediation.mjs +0 -349
  94. package/cli/lib/audit-sweep-runtime/rerun.mjs +0 -129
  95. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +0 -300
  96. package/cli/lib/audit-sweep-runtime/status.mjs +0 -62
  97. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +0 -215
  98. package/cli/lib/audit-sweep-runtime/validators.mjs +0 -797
  99. package/cli/lib/audit-sweep.mjs +0 -19
  100. package/cli/lib/authority-convergence.mjs +0 -704
  101. package/cli/lib/closeout.mjs +0 -732
  102. package/cli/lib/codex-sdk-runner.mjs +0 -76
  103. package/cli/lib/external-execution.mjs +0 -101
  104. package/cli/lib/handoff.mjs +0 -812
  105. package/cli/lib/high-risk-admission.mjs +0 -512
  106. package/cli/lib/high-risk-decision.mjs +0 -353
  107. package/cli/lib/high-risk-ingest.mjs +0 -321
  108. package/cli/lib/high-risk-review.mjs +0 -267
  109. package/cli/lib/internal/contracts-parse-high-risk.mjs +0 -131
  110. package/cli/lib/internal/contracts-validators.mjs +0 -399
  111. package/cli/lib/internal/doctor-bootstrap-surface.mjs +0 -406
  112. package/cli/lib/internal/doctor-delegated-surface.mjs +0 -256
  113. package/cli/lib/internal/doctor-finalize.mjs +0 -383
  114. package/cli/lib/internal/doctor-format.mjs +0 -286
  115. package/cli/lib/internal/doctor-inspectors.mjs +0 -327
  116. package/cli/lib/internal/doctor-state.mjs +0 -205
  117. package/cli/lib/internal/validators-artifacts.mjs +0 -515
  118. package/cli/lib/sweep-design-runtime/common.mjs +0 -246
  119. package/cli/lib/sweep-design-runtime/engine.mjs +0 -733
  120. package/cli/lib/sweep-design-runtime/fix-topic.mjs +0 -414
  121. package/cli/lib/sweep-design-runtime/lifecycle.mjs +0 -54
  122. package/cli/lib/sweep-design-runtime/results.mjs +0 -324
  123. package/cli/lib/sweep-design.mjs +0 -8
  124. package/cli/lib/topic-artifacts.mjs +0 -186
  125. package/cli/lib/topic-authority-coverage.mjs +0 -73
  126. package/cli/lib/topic-closeout.mjs +0 -560
  127. package/cli/lib/topic-common.mjs +0 -404
  128. package/cli/lib/topic-decisions.mjs +0 -332
  129. package/cli/lib/topic-draft-packets.mjs +0 -167
  130. package/cli/lib/topic-execution.mjs +0 -515
  131. package/cli/lib/topic-goal.mjs +0 -440
  132. package/cli/lib/topic-ledger.mjs +0 -281
  133. package/cli/lib/topic-lifecycle-artifacts.mjs +0 -173
  134. package/cli/lib/topic-root-validation.mjs +0 -288
  135. package/cli/lib/topic-runner-commands.mjs +0 -174
  136. package/cli/lib/topic-runner-deferral.mjs +0 -532
  137. package/cli/lib/topic-runner-stale-gates.mjs +0 -114
  138. package/cli/lib/topic-runner-validation.mjs +0 -138
  139. package/cli/lib/topic-runner.mjs +0 -727
  140. package/cli/lib/topic-scaffold.mjs +0 -252
  141. package/cli/lib/topic-waves.mjs +0 -403
  142. package/cli/lib/topic.mjs +0 -81
  143. package/config/audit-execution-artifacts.yaml +0 -20
  144. package/config/external-execution-artifacts.yaml +0 -16
  145. package/config/host-adapter.yaml +0 -30
  146. package/config/host-profile.yaml +0 -29
  147. package/config/installer-evidence.yaml +0 -31
  148. package/config/skill-installer.yaml +0 -23
  149. package/config/skill-manifest.yaml +0 -48
  150. package/config/skills.yaml +0 -30
  151. package/contracts/acceptance.schema.yaml +0 -16
  152. package/contracts/admission-checklist.schema.yaml +0 -15
  153. package/contracts/audit-chunk.schema.yaml +0 -123
  154. package/contracts/audit-closeout.schema.yaml +0 -51
  155. package/contracts/audit-finding.schema.yaml +0 -61
  156. package/contracts/audit-ledger.schema.yaml +0 -138
  157. package/contracts/audit-plan.schema.yaml +0 -138
  158. package/contracts/audit-remediation-map.schema.yaml +0 -52
  159. package/contracts/audit-rerun.schema.yaml +0 -31
  160. package/contracts/audit-sweep-result.yaml +0 -53
  161. package/contracts/authority-convergence-audit.schema.yaml +0 -19
  162. package/contracts/closeout.schema.yaml +0 -25
  163. package/contracts/decision-review.schema.yaml +0 -16
  164. package/contracts/doc-spec-audit-result.yaml +0 -19
  165. package/contracts/execution-packet.schema.yaml +0 -49
  166. package/contracts/external-host-compatibility.yaml +0 -22
  167. package/contracts/forbidden-shortcuts.catalog.yaml +0 -23
  168. package/contracts/high-risk-admission.schema.yaml +0 -23
  169. package/contracts/high-risk-execution-result.yaml +0 -20
  170. package/contracts/orchestration-state.schema.yaml +0 -41
  171. package/contracts/overflow-continuation.schema.yaml +0 -12
  172. package/contracts/packet.schema.yaml +0 -30
  173. package/contracts/pending-note.schema.yaml +0 -17
  174. package/contracts/prompt.schema.yaml +0 -12
  175. package/contracts/remediation.schema.yaml +0 -16
  176. package/contracts/result.schema.yaml +0 -24
  177. package/contracts/spec-reconstruction-result.yaml +0 -41
  178. package/contracts/sweep-design-result.yaml +0 -349
  179. package/contracts/topic-goal.schema.yaml +0 -87
  180. package/contracts/topic-run-ledger.schema.yaml +0 -72
  181. package/contracts/topic-step-decision.schema.yaml +0 -45
  182. package/contracts/topic.schema.yaml +0 -65
  183. package/contracts/true-close.schema.yaml +0 -15
  184. package/contracts/wave.schema.yaml +0 -29
  185. package/contracts/worker-output.schema.yaml +0 -15
  186. package/contracts/workflow-consumer.schema.yaml +0 -110
  187. package/methodology/audit-sweep-p0p1-recall.yaml +0 -45
  188. package/methodology/authority-convergence-policy.yaml +0 -42
  189. package/methodology/overflow-continuation-policy.yaml +0 -14
  190. package/methodology/skill-exchange-projection.yaml +0 -114
  191. package/methodology/skill-handoff.yaml +0 -34
  192. package/methodology/skill-installer-result.yaml +0 -27
  193. package/methodology/skill-installer-summary-projection.yaml +0 -181
  194. package/methodology/skill-runtime.yaml +0 -23
  195. package/methodology/spec-target-truth-profile.yaml +0 -46
  196. package/methodology/topic-lifecycle-report.yaml +0 -144
  197. package/methodology/topic-lifecycle.yaml +0 -37
  198. package/methodology/topic-naming-ontology.yaml +0 -21
  199. package/methodology/topic-ontology.yaml +0 -38
  200. package/methodology/topic-validation-policy.yaml +0 -9
  201. package/methodology/wave-dag-policy.yaml +0 -14
  202. package/spec/_meta/command-gating-matrix.yaml +0 -143
  203. package/spec/_meta/generate-drift-migration-checklist.yaml +0 -137
  204. package/spec/_meta/governance-routing-cutover-checklist.yaml +0 -35
  205. package/spec/_meta/phase2-impacted-surface-matrix.yaml +0 -44
  206. package/spec/_meta/spec-authority-cutover-readiness.yaml +0 -102
  207. package/spec/bootstrap-state.yaml +0 -99
@@ -1,205 +0,0 @@
1
- import {
2
- SPEC_GENERATION_AUDIT_REF,
3
- STANDALONE_COMPLETION_STATUS,
4
- } from "../../constants.mjs";
5
-
6
- export function buildCheck(id, ok, detail, severity = ok ? "ok" : "error") {
7
- return { id, ok, detail, severity };
8
- }
9
-
10
- export function emptyDelegatedContracts() {
11
- return {
12
- runtimeOwner: null,
13
- executionMode: null,
14
- installerMode: null,
15
- selfHostedRuntime: false,
16
- triggerMode: null,
17
- expectedSkillIds: [],
18
- selectedAdapterId: null,
19
- admittedAdapterIds: [],
20
- adapterHandoffMode: null,
21
- semanticReviewOwner: null,
22
- };
23
- }
24
-
25
- export function emptyHandoffReadiness() {
26
- return {
27
- ok: false,
28
- requiredContextOrder: [],
29
- missingContextEntries: [],
30
- missingPaths: [],
31
- };
32
- }
33
-
34
- export function emptyAdapterProfiles() {
35
- return {
36
- admitted: [],
37
- invalid: [],
38
- selected: null,
39
- };
40
- }
41
-
42
- export function emptyAuditArtifact() {
43
- return {
44
- present: false,
45
- ok: true,
46
- artifactPath: ".nimi/local/handoff-results/doc_spec_audit.json",
47
- outcome: null,
48
- summaryStatus: null,
49
- verifiedAt: null,
50
- reason: "No local doc_spec_audit closeout artifact detected",
51
- };
52
- }
53
-
54
- export function emptySpecGenerationAudit() {
55
- return {
56
- present: false,
57
- ok: false,
58
- auditPath: SPEC_GENERATION_AUDIT_REF,
59
- validator: "validate-spec-audit",
60
- summary: null,
61
- reason: "No spec generation audit detected yet; it will be required before completed reconstruction closeout",
62
- };
63
- }
64
-
65
- export function emptyCompletionPosture() {
66
- return {
67
- completionProfile: null,
68
- completionStatus: STANDALONE_COMPLETION_STATUS.INCOMPLETE,
69
- completedSurfaces: [],
70
- deferredExecutionSurfaces: [],
71
- promotedParityGapSummary: [],
72
- };
73
- }
74
-
75
- export function emptyCanonicalTree() {
76
- return {
77
- profile: null,
78
- canonicalRoot: null,
79
- requiredFiles: [],
80
- present: [],
81
- missing: [],
82
- invalid: [],
83
- requiredFilesValid: false,
84
- ready: false,
85
- };
86
- }
87
-
88
- export function emptyLifecycleState() {
89
- return {
90
- mode: null,
91
- treeState: null,
92
- authorityMode: null,
93
- blueprintMode: null,
94
- reconstructionRequired: false,
95
- readyForAiReconstruction: false,
96
- cutoverReadiness: {},
97
- activeAuthorityRoot: null,
98
- };
99
- }
100
-
101
- export function emptyCommandGating() {
102
- return {
103
- ok: false,
104
- entries: [],
105
- };
106
- }
107
-
108
- export function emptyBlueprintReference() {
109
- return {
110
- present: false,
111
- ok: true,
112
- mode: null,
113
- root: null,
114
- canonicalTargetRoot: null,
115
- equivalenceContractRef: null,
116
- };
117
- }
118
-
119
- export function emptySpecGenerationInputs() {
120
- return {
121
- ok: false,
122
- mode: null,
123
- canonicalTargetRoot: null,
124
- codeRoots: [],
125
- docsRoots: [],
126
- structureRoots: [],
127
- humanNotePaths: [],
128
- benchmarkBlueprintRoot: null,
129
- benchmarkMode: null,
130
- acceptanceMode: null,
131
- generationOrder: [],
132
- inferenceRules: [],
133
- };
134
- }
135
-
136
- export function emptyBenchmarkAuditReadiness() {
137
- return {
138
- available: false,
139
- ready: false,
140
- benchmarkRoot: null,
141
- acceptanceMode: null,
142
- reason: "No benchmark blueprint is declared for this project.",
143
- };
144
- }
145
-
146
- export function emptyExecutionContracts() {
147
- return {
148
- total: 0,
149
- valid: 0,
150
- invalid: [],
151
- contracts: [],
152
- };
153
- }
154
-
155
- export function emptyHostCompatibility() {
156
- return {
157
- contractRef: "unknown",
158
- supportedHostPosture: [],
159
- supportedHostExamples: [],
160
- requiredBehavior: [],
161
- forbiddenBehavior: [],
162
- genericExternalHostCompatible: false,
163
- namedOverlaySupport: {
164
- mode: "generic_only",
165
- admittedOverlayIds: [],
166
- selectedOverlayId: null,
167
- selectedOverlayProfileRef: null,
168
- selectedOverlayHostClass: null,
169
- },
170
- futureOnlyHostSurfaces: [],
171
- nativeReviewSurfaces: [],
172
- };
173
- }
174
-
175
- export function createDoctorMissingRootResult(projectRoot, detail, nextStep) {
176
- return {
177
- projectRoot,
178
- ok: false,
179
- bootstrapPresent: false,
180
- reconstructionRequired: false,
181
- runtimeInstalled: false,
182
- bootstrapContract: {
183
- status: "missing",
184
- id: null,
185
- version: null,
186
- },
187
- lifecycleState: emptyLifecycleState(),
188
- specTreeModel: null,
189
- specGenerationInputs: emptySpecGenerationInputs(),
190
- canonicalTree: emptyCanonicalTree(),
191
- specGenerationAudit: emptySpecGenerationAudit(),
192
- commandGating: emptyCommandGating(),
193
- blueprintReference: emptyBlueprintReference(),
194
- benchmarkAuditReadiness: emptyBenchmarkAuditReadiness(),
195
- delegatedContracts: emptyDelegatedContracts(),
196
- adapterProfiles: emptyAdapterProfiles(),
197
- hostCompatibility: emptyHostCompatibility(),
198
- ...emptyCompletionPosture(),
199
- handoffReadiness: emptyHandoffReadiness(),
200
- checks: [buildCheck("nimi_root", false, detail)],
201
- auditArtifact: emptyAuditArtifact(),
202
- executionContracts: emptyExecutionContracts(),
203
- nextSteps: [nextStep],
204
- };
205
- }
@@ -1,515 +0,0 @@
1
- import path from "node:path";
2
-
3
- import {
4
- ACCEPTANCE_SCHEMA_REF,
5
- EXECUTION_PACKET_SCHEMA_REF,
6
- HIGH_RISK_SCHEMA_SPECS,
7
- ORCHESTRATION_STATE_SCHEMA_REF,
8
- PROMPT_SCHEMA_REF,
9
- WORKER_OUTPUT_SCHEMA_REF,
10
- } from "../../constants.mjs";
11
- import { readTextIfFile } from "../fs-helpers.mjs";
12
- import { isPlainObject } from "../value-helpers.mjs";
13
- import { parseYamlText } from "../yaml-helpers.mjs";
14
- import {
15
- makeValidatorRefusal,
16
- VALIDATOR_NATIVE_REFUSAL_CODES,
17
- } from "./validators-shared.mjs";
18
-
19
- function listMarkdownHeadings(text) {
20
- return Array.from(text.matchAll(/^#{1,6}\s+(.+?)\s*$/gm)).map((match) => match[1]);
21
- }
22
-
23
- function missingHeadings(headings, requiredBlocks) {
24
- const present = new Set(headings);
25
- return requiredBlocks.filter((block) => !present.has(block));
26
- }
27
-
28
- function indexOfHeading(headings, heading) {
29
- return headings.findIndex((entry) => entry === heading);
30
- }
31
-
32
- function extractSectionBody(text, heading) {
33
- const lines = text.split("\n");
34
- const headingLine = `## ${heading}`;
35
- const startIndex = lines.findIndex((line) => line.trim() === headingLine);
36
-
37
- if (startIndex === -1) {
38
- return null;
39
- }
40
-
41
- const bodyLines = [];
42
- for (let index = startIndex + 1; index < lines.length; index += 1) {
43
- if (lines[index].startsWith("## ")) {
44
- break;
45
- }
46
- bodyLines.push(lines[index]);
47
- }
48
-
49
- return bodyLines.join("\n").trim();
50
- }
51
-
52
- function buildMissingFileReport(filePath, code, label) {
53
- return {
54
- ok: false,
55
- errors: [`missing file: ${filePath}`],
56
- warnings: [],
57
- refusal: makeValidatorRefusal(code, `${label} artifact is missing`),
58
- };
59
- }
60
-
61
- async function loadYamlArtifact(filePath, missingCode, invalidCode, label) {
62
- const text = await readTextIfFile(filePath);
63
- if (text === null) {
64
- return buildMissingFileReport(filePath, missingCode, label);
65
- }
66
-
67
- const doc = parseYamlText(text);
68
- if (!isPlainObject(doc)) {
69
- return {
70
- ok: false,
71
- errors: [`invalid YAML document: ${filePath}`],
72
- warnings: [],
73
- refusal: makeValidatorRefusal(invalidCode, `${label} artifact is not valid YAML`),
74
- };
75
- }
76
-
77
- return { ok: true, doc, text };
78
- }
79
-
80
- function ensureStringOrNull(value) {
81
- return value === null || value === "" || typeof value === "string";
82
- }
83
-
84
- function validateExecutionPacketDoc(doc, filePath) {
85
- const errors = [];
86
- const warnings = [];
87
- const spec = HIGH_RISK_SCHEMA_SPECS[EXECUTION_PACKET_SCHEMA_REF];
88
-
89
- for (const field of spec.listFields.required) {
90
- if (!(field in doc)) {
91
- errors.push(`missing execution packet field: ${field}`);
92
- }
93
- }
94
-
95
- if (doc.status && !spec.listFields.status_enum.includes(String(doc.status))) {
96
- errors.push(`invalid execution packet status: ${doc.status}`);
97
- }
98
-
99
- if (!Array.isArray(doc.phases) || doc.phases.length === 0) {
100
- errors.push("execution packet phases must be a non-empty array");
101
- } else {
102
- const phaseIds = new Set();
103
-
104
- for (const phase of doc.phases) {
105
- if (!isPlainObject(phase)) {
106
- errors.push("execution packet phases entries must be mappings");
107
- continue;
108
- }
109
-
110
- for (const field of spec.listFields.phase_required) {
111
- if (!(field in phase)) {
112
- errors.push(`execution packet phase missing field: ${field}`);
113
- }
114
- }
115
-
116
- const phaseId = String(phase.phase_id ?? "");
117
- if (!phaseId) {
118
- errors.push("execution packet phase_id must be a non-empty string");
119
- } else if (phaseIds.has(phaseId)) {
120
- errors.push(`duplicate execution packet phase_id: ${phaseId}`);
121
- } else {
122
- phaseIds.add(phaseId);
123
- }
124
-
125
- for (const key of [
126
- "authority_refs",
127
- "write_scope",
128
- "read_scope",
129
- "required_checks",
130
- "completion_criteria",
131
- "escalation_conditions",
132
- ]) {
133
- if (!Array.isArray(phase[key]) || phase[key].length === 0) {
134
- errors.push(`execution packet phase ${phaseId || "<unknown>"}: ${key} must be a non-empty array`);
135
- }
136
- }
137
-
138
- if (
139
- phase.stop_on_failure
140
- && !spec.listFields.phase_stop_on_failure_enum.includes(String(phase.stop_on_failure))
141
- ) {
142
- errors.push(`execution packet phase ${phaseId || "<unknown>"}: invalid stop_on_failure ${phase.stop_on_failure}`);
143
- }
144
-
145
- if (!(phase.next_on_success === null || phase.next_on_success === "" || typeof phase.next_on_success === "string")) {
146
- errors.push(`execution packet phase ${phaseId || "<unknown>"}: next_on_success must be a string or null`);
147
- }
148
- }
149
-
150
- if (doc.entry_phase_id && !phaseIds.has(String(doc.entry_phase_id))) {
151
- errors.push(`execution packet entry_phase_id does not exist in phases: ${doc.entry_phase_id}`);
152
- }
153
-
154
- for (const phase of doc.phases) {
155
- if (typeof phase?.next_on_success === "string" && phase.next_on_success !== "" && !phaseIds.has(phase.next_on_success)) {
156
- errors.push(`execution packet phase ${phase.phase_id || "<unknown>"}: next_on_success target does not exist: ${phase.next_on_success}`);
157
- }
158
- }
159
- }
160
-
161
- if (!isPlainObject(doc.escalation_policy)) {
162
- errors.push("execution packet escalation_policy must be a mapping");
163
- } else {
164
- for (const key of spec.listFields.escalation_policy_required) {
165
- if (!Array.isArray(doc.escalation_policy[key])) {
166
- errors.push(`execution packet escalation_policy missing array: ${key}`);
167
- }
168
- }
169
- }
170
-
171
- if (!isPlainObject(doc.notification_settings)) {
172
- errors.push("execution packet notification_settings must be a mapping");
173
- } else {
174
- for (const key of spec.listFields.notification_settings_required) {
175
- if (typeof doc.notification_settings[key] !== "boolean") {
176
- errors.push(`execution packet notification_settings.${key} must be boolean`);
177
- }
178
- }
179
- }
180
-
181
- if (!isPlainObject(doc.resume_policy)) {
182
- errors.push("execution packet resume_policy must be a mapping");
183
- } else {
184
- for (const key of spec.listFields.resume_policy_required) {
185
- if (!Array.isArray(doc.resume_policy[key])) {
186
- errors.push(`execution packet resume_policy missing array: ${key}`);
187
- }
188
- }
189
- }
190
-
191
- return {
192
- ok: errors.length === 0,
193
- errors,
194
- warnings,
195
- refusal: errors.length === 0
196
- ? null
197
- : makeValidatorRefusal(
198
- VALIDATOR_NATIVE_REFUSAL_CODES.EXECUTION_PACKET_INVALID,
199
- `execution-packet artifact is invalid: ${path.basename(filePath)}`,
200
- ),
201
- };
202
- }
203
-
204
- function validateOrchestrationStateDoc(doc, filePath) {
205
- const errors = [];
206
- const warnings = [];
207
- const spec = HIGH_RISK_SCHEMA_SPECS[ORCHESTRATION_STATE_SCHEMA_REF];
208
-
209
- for (const field of spec.listFields.required) {
210
- if (!(field in doc)) {
211
- errors.push(`missing orchestration state field: ${field}`);
212
- }
213
- }
214
-
215
- if (doc.run_status && !spec.listFields.run_status_enum.includes(String(doc.run_status))) {
216
- errors.push(`invalid orchestration state run_status: ${doc.run_status}`);
217
- }
218
-
219
- if (Object.prototype.hasOwnProperty.call(doc, "resume_token")) {
220
- errors.push("orchestration state must not contain resume_token");
221
- }
222
-
223
- for (const key of ["current_phase_id", "last_completed_phase_id", "awaiting_human_action", "pause_reason"]) {
224
- if (key in doc && !ensureStringOrNull(doc[key])) {
225
- errors.push(`orchestration state ${key} must be a string or null`);
226
- }
227
- }
228
-
229
- if (doc.run_status === "running" && !(typeof doc.current_phase_id === "string" && doc.current_phase_id.length > 0)) {
230
- errors.push("running orchestration state requires current_phase_id");
231
- }
232
-
233
- if (doc.run_status === "paused") {
234
- if (!(typeof doc.current_phase_id === "string" && doc.current_phase_id.length > 0)) {
235
- errors.push("paused orchestration state requires current_phase_id");
236
- }
237
- if (!(typeof doc.pause_reason === "string" && doc.pause_reason.length > 0)) {
238
- errors.push("paused orchestration state requires pause_reason");
239
- }
240
- if (!(typeof doc.awaiting_human_action === "string" && doc.awaiting_human_action.length > 0)) {
241
- errors.push("paused orchestration state requires awaiting_human_action");
242
- }
243
- }
244
-
245
- if (doc.run_status === "failed" && !(typeof doc.awaiting_human_action === "string" && doc.awaiting_human_action.length > 0)) {
246
- errors.push("failed orchestration state requires awaiting_human_action");
247
- }
248
-
249
- if (doc.run_status === "completed") {
250
- if (!(typeof doc.last_completed_phase_id === "string" && doc.last_completed_phase_id.length > 0)) {
251
- errors.push("completed orchestration state requires last_completed_phase_id");
252
- }
253
- if (!(doc.current_phase_id === null || doc.current_phase_id === "")) {
254
- errors.push("completed orchestration state must not carry current_phase_id");
255
- }
256
- if (!(doc.awaiting_human_action === null || doc.awaiting_human_action === "")) {
257
- errors.push("completed orchestration state must not carry awaiting_human_action");
258
- }
259
- if (!(doc.pause_reason === undefined || doc.pause_reason === null || doc.pause_reason === "")) {
260
- errors.push("completed orchestration state must not carry pause_reason");
261
- }
262
- }
263
-
264
- if ("notification_refs" in doc && doc.notification_refs !== null) {
265
- if (!Array.isArray(doc.notification_refs)) {
266
- errors.push("orchestration state notification_refs must be an array when present");
267
- } else {
268
- for (const row of doc.notification_refs) {
269
- if (!isPlainObject(row)) {
270
- errors.push("orchestration state notification_refs entries must be mappings");
271
- continue;
272
- }
273
- for (const key of spec.listFields.notification_ref_required) {
274
- if (typeof row[key] !== "string" || row[key].length === 0) {
275
- errors.push(`orchestration state notification_refs entry missing string field: ${key}`);
276
- }
277
- }
278
- }
279
- }
280
- }
281
-
282
- return {
283
- ok: errors.length === 0,
284
- errors,
285
- warnings,
286
- refusal: errors.length === 0
287
- ? null
288
- : makeValidatorRefusal(
289
- VALIDATOR_NATIVE_REFUSAL_CODES.ORCHESTRATION_STATE_INVALID,
290
- `orchestration-state artifact is invalid: ${path.basename(filePath)}`,
291
- ),
292
- };
293
- }
294
-
295
- function readRunnerSignal(text) {
296
- const sectionBody = extractSectionBody(text, "Runner Signal");
297
- if (!sectionBody) {
298
- return {
299
- ok: false,
300
- errors: ["missing worker-output block: Runner Signal"],
301
- warnings: [],
302
- refusal: makeValidatorRefusal(
303
- VALIDATOR_NATIVE_REFUSAL_CODES.RUNNER_SIGNAL_MISSING,
304
- "worker-output artifact is missing the required Runner Signal block",
305
- ),
306
- signal: null,
307
- };
308
- }
309
-
310
- const blockMatch = sectionBody.match(/```ya?ml\s+([\s\S]*?)```/i);
311
- if (!blockMatch) {
312
- return {
313
- ok: false,
314
- errors: ["runner signal must contain a fenced yaml block"],
315
- warnings: [],
316
- refusal: makeValidatorRefusal(
317
- VALIDATOR_NATIVE_REFUSAL_CODES.RUNNER_SIGNAL_INVALID,
318
- "worker-output runner signal is missing a fenced yaml block",
319
- ),
320
- signal: null,
321
- };
322
- }
323
-
324
- const parsed = parseYamlText(blockMatch[1]);
325
- if (!isPlainObject(parsed)) {
326
- return {
327
- ok: false,
328
- errors: ["runner signal fenced yaml block must decode to a mapping"],
329
- warnings: [],
330
- refusal: makeValidatorRefusal(
331
- VALIDATOR_NATIVE_REFUSAL_CODES.RUNNER_SIGNAL_INVALID,
332
- "worker-output runner signal is not valid yaml mapping data",
333
- ),
334
- signal: null,
335
- };
336
- }
337
-
338
- return {
339
- ok: true,
340
- errors: [],
341
- warnings: [],
342
- refusal: null,
343
- signal: parsed,
344
- };
345
- }
346
-
347
- function validatePromptText(text, filePath) {
348
- const errors = [];
349
- const warnings = [];
350
- const headings = listMarkdownHeadings(text);
351
- const missingBlocks = missingHeadings(
352
- headings,
353
- HIGH_RISK_SCHEMA_SPECS[PROMPT_SCHEMA_REF].listFields.required_blocks,
354
- );
355
-
356
- for (const block of missingBlocks) {
357
- errors.push(`missing prompt block: ${block}`);
358
- }
359
-
360
- return {
361
- ok: errors.length === 0,
362
- errors,
363
- warnings,
364
- refusal: errors.length === 0
365
- ? null
366
- : makeValidatorRefusal(
367
- VALIDATOR_NATIVE_REFUSAL_CODES.PROMPT_INVALID,
368
- `prompt artifact is invalid: ${path.basename(filePath)}`,
369
- ),
370
- };
371
- }
372
-
373
- function validateWorkerOutputText(text, filePath) {
374
- const errors = [];
375
- const warnings = [];
376
- const headings = listMarkdownHeadings(text);
377
- const missingBlocks = missingHeadings(
378
- headings,
379
- HIGH_RISK_SCHEMA_SPECS[WORKER_OUTPUT_SCHEMA_REF].listFields.required_blocks,
380
- );
381
-
382
- for (const block of missingBlocks) {
383
- errors.push(`missing worker-output block: ${block}`);
384
- }
385
-
386
- const signalReport = readRunnerSignal(text);
387
- errors.push(...signalReport.errors);
388
- warnings.push(...signalReport.warnings);
389
-
390
- const refusal = signalReport.refusal
391
- || (errors.length > 0
392
- ? makeValidatorRefusal(
393
- VALIDATOR_NATIVE_REFUSAL_CODES.WORKER_OUTPUT_INVALID,
394
- `worker-output artifact is invalid: ${path.basename(filePath)}`,
395
- )
396
- : null);
397
-
398
- return {
399
- ok: errors.length === 0,
400
- errors,
401
- warnings,
402
- refusal,
403
- signal: signalReport.signal,
404
- };
405
- }
406
-
407
- function validateAcceptanceText(text, filePath) {
408
- const errors = [];
409
- const warnings = [];
410
- const headings = listMarkdownHeadings(text);
411
- const spec = HIGH_RISK_SCHEMA_SPECS[ACCEPTANCE_SCHEMA_REF];
412
- const missingBlocks = missingHeadings(headings, spec.listFields.required_blocks);
413
-
414
- for (const block of missingBlocks) {
415
- errors.push(`missing acceptance block: ${block}`);
416
- }
417
-
418
- const requiredOrder = ["Findings", "Current Phase Disposition", "Next Step or Reopen Condition"];
419
- let previousIndex = -1;
420
- for (const block of requiredOrder) {
421
- const currentIndex = indexOfHeading(headings, block);
422
- if (currentIndex !== -1 && currentIndex < previousIndex) {
423
- errors.push("acceptance required blocks are out of order");
424
- break;
425
- }
426
- previousIndex = currentIndex === -1 ? previousIndex : currentIndex;
427
- }
428
-
429
- const dispositionSection = extractSectionBody(text, "Current Phase Disposition");
430
- if (dispositionSection) {
431
- const dispositionMatch = dispositionSection.match(/disposition:\s*(\w+)/i);
432
- if (dispositionMatch) {
433
- const disposition = dispositionMatch[1].toLowerCase();
434
- if (!spec.listFields.disposition_enum.includes(disposition)) {
435
- errors.push(`invalid acceptance disposition: ${disposition}`);
436
- }
437
- } else {
438
- warnings.push("acceptance missing explicit `Disposition:` line in Current Phase Disposition block");
439
- }
440
- }
441
-
442
- return {
443
- ok: errors.length === 0,
444
- errors,
445
- warnings,
446
- refusal: errors.length === 0
447
- ? null
448
- : makeValidatorRefusal(
449
- VALIDATOR_NATIVE_REFUSAL_CODES.ACCEPTANCE_INVALID,
450
- `acceptance artifact is invalid: ${path.basename(filePath)}`,
451
- ),
452
- };
453
- }
454
-
455
- export async function validateExecutionPacket(filePath) {
456
- const loaded = await loadYamlArtifact(
457
- filePath,
458
- VALIDATOR_NATIVE_REFUSAL_CODES.EXECUTION_PACKET_MISSING,
459
- VALIDATOR_NATIVE_REFUSAL_CODES.EXECUTION_PACKET_INVALID,
460
- "execution-packet",
461
- );
462
- if (!loaded.ok) {
463
- return loaded;
464
- }
465
- return validateExecutionPacketDoc(loaded.doc, filePath);
466
- }
467
-
468
- export async function validateOrchestrationState(filePath) {
469
- const loaded = await loadYamlArtifact(
470
- filePath,
471
- VALIDATOR_NATIVE_REFUSAL_CODES.ORCHESTRATION_STATE_MISSING,
472
- VALIDATOR_NATIVE_REFUSAL_CODES.ORCHESTRATION_STATE_INVALID,
473
- "orchestration-state",
474
- );
475
- if (!loaded.ok) {
476
- return loaded;
477
- }
478
- return validateOrchestrationStateDoc(loaded.doc, filePath);
479
- }
480
-
481
- export async function validatePrompt(filePath) {
482
- const text = await readTextIfFile(filePath);
483
- if (text === null) {
484
- return buildMissingFileReport(
485
- filePath,
486
- VALIDATOR_NATIVE_REFUSAL_CODES.PROMPT_MISSING,
487
- "prompt",
488
- );
489
- }
490
- return validatePromptText(text, filePath);
491
- }
492
-
493
- export async function validateWorkerOutput(filePath) {
494
- const text = await readTextIfFile(filePath);
495
- if (text === null) {
496
- return buildMissingFileReport(
497
- filePath,
498
- VALIDATOR_NATIVE_REFUSAL_CODES.WORKER_OUTPUT_MISSING,
499
- "worker-output",
500
- );
501
- }
502
- return validateWorkerOutputText(text, filePath);
503
- }
504
-
505
- export async function validateAcceptance(filePath) {
506
- const text = await readTextIfFile(filePath);
507
- if (text === null) {
508
- return buildMissingFileReport(
509
- filePath,
510
- VALIDATOR_NATIVE_REFUSAL_CODES.ACCEPTANCE_MISSING,
511
- "acceptance",
512
- );
513
- }
514
- return validateAcceptanceText(text, filePath);
515
- }