@nimiplatform/nimi-coding 0.1.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 (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +348 -0
  3. package/adapters/README.md +25 -0
  4. package/adapters/claude/README.md +89 -0
  5. package/adapters/claude/profile.yaml +70 -0
  6. package/adapters/codex/README.md +53 -0
  7. package/adapters/codex/profile.yaml +78 -0
  8. package/adapters/oh-my-codex/README.md +185 -0
  9. package/adapters/oh-my-codex/profile.yaml +46 -0
  10. package/bin/nimicoding.mjs +6 -0
  11. package/cli/commands/admit-high-risk-decision.mjs +108 -0
  12. package/cli/commands/audit-sweep.mjs +341 -0
  13. package/cli/commands/blueprint-audit.mjs +91 -0
  14. package/cli/commands/clear.mjs +168 -0
  15. package/cli/commands/closeout.mjs +183 -0
  16. package/cli/commands/decide-high-risk-execution.mjs +124 -0
  17. package/cli/commands/doctor.mjs +53 -0
  18. package/cli/commands/generate-spec-derived-docs.mjs +131 -0
  19. package/cli/commands/handoff.mjs +123 -0
  20. package/cli/commands/ingest-high-risk-execution.mjs +95 -0
  21. package/cli/commands/review-high-risk-execution.mjs +95 -0
  22. package/cli/commands/start.mjs +717 -0
  23. package/cli/commands/topic-formatters.mjs +382 -0
  24. package/cli/commands/topic-goal.mjs +33 -0
  25. package/cli/commands/topic-options-shared.mjs +27 -0
  26. package/cli/commands/topic-options-workflow.mjs +767 -0
  27. package/cli/commands/topic-options.mjs +626 -0
  28. package/cli/commands/topic-runner.mjs +169 -0
  29. package/cli/commands/topic.mjs +795 -0
  30. package/cli/commands/validate-acceptance.mjs +5 -0
  31. package/cli/commands/validate-ai-governance.mjs +214 -0
  32. package/cli/commands/validate-execution-packet.mjs +5 -0
  33. package/cli/commands/validate-orchestration-state.mjs +5 -0
  34. package/cli/commands/validate-prompt.mjs +5 -0
  35. package/cli/commands/validate-spec-audit.mjs +27 -0
  36. package/cli/commands/validate-spec-governance.mjs +124 -0
  37. package/cli/commands/validate-spec-tree.mjs +27 -0
  38. package/cli/commands/validate-worker-output.mjs +5 -0
  39. package/cli/constants.mjs +489 -0
  40. package/cli/help.mjs +134 -0
  41. package/cli/index.mjs +103 -0
  42. package/cli/lib/adapter-profiles.mjs +403 -0
  43. package/cli/lib/audit-execution.mjs +52 -0
  44. package/cli/lib/audit-sweep-runtime/admissions.mjs +381 -0
  45. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +333 -0
  46. package/cli/lib/audit-sweep-runtime/chunks.mjs +697 -0
  47. package/cli/lib/audit-sweep-runtime/closeout.mjs +144 -0
  48. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +639 -0
  49. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +515 -0
  50. package/cli/lib/audit-sweep-runtime/common.mjs +329 -0
  51. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +172 -0
  52. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +152 -0
  53. package/cli/lib/audit-sweep-runtime/format.mjs +57 -0
  54. package/cli/lib/audit-sweep-runtime/ingest.mjs +486 -0
  55. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +198 -0
  56. package/cli/lib/audit-sweep-runtime/inventory.mjs +728 -0
  57. package/cli/lib/audit-sweep-runtime/ledger.mjs +315 -0
  58. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +101 -0
  59. package/cli/lib/audit-sweep-runtime/remediation.mjs +349 -0
  60. package/cli/lib/audit-sweep-runtime/rerun.mjs +129 -0
  61. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +300 -0
  62. package/cli/lib/audit-sweep-runtime/status.mjs +62 -0
  63. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +215 -0
  64. package/cli/lib/audit-sweep-runtime/validators.mjs +758 -0
  65. package/cli/lib/audit-sweep.mjs +18 -0
  66. package/cli/lib/authority-convergence.mjs +309 -0
  67. package/cli/lib/blueprint-audit.mjs +370 -0
  68. package/cli/lib/bootstrap.mjs +228 -0
  69. package/cli/lib/closeout.mjs +623 -0
  70. package/cli/lib/codex-sdk-runner.mjs +76 -0
  71. package/cli/lib/contracts.mjs +180 -0
  72. package/cli/lib/doctor.mjs +18 -0
  73. package/cli/lib/entrypoints.mjs +274 -0
  74. package/cli/lib/external-execution.mjs +101 -0
  75. package/cli/lib/fs-helpers.mjs +33 -0
  76. package/cli/lib/handoff.mjs +785 -0
  77. package/cli/lib/high-risk-admission.mjs +442 -0
  78. package/cli/lib/high-risk-decision.mjs +324 -0
  79. package/cli/lib/high-risk-ingest.mjs +317 -0
  80. package/cli/lib/high-risk-review.mjs +263 -0
  81. package/cli/lib/internal/contracts-loaders.mjs +132 -0
  82. package/cli/lib/internal/contracts-parse-high-risk.mjs +131 -0
  83. package/cli/lib/internal/contracts-parse.mjs +457 -0
  84. package/cli/lib/internal/contracts-validators.mjs +398 -0
  85. package/cli/lib/internal/doctor-bootstrap-surface.mjs +359 -0
  86. package/cli/lib/internal/doctor-delegated-surface.mjs +256 -0
  87. package/cli/lib/internal/doctor-finalize.mjs +385 -0
  88. package/cli/lib/internal/doctor-format.mjs +286 -0
  89. package/cli/lib/internal/doctor-inspectors.mjs +294 -0
  90. package/cli/lib/internal/doctor-state.mjs +205 -0
  91. package/cli/lib/internal/governance/ai/ai-context-budget-core.mjs +315 -0
  92. package/cli/lib/internal/governance/ai/ai-structure-budget-core.mjs +358 -0
  93. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +155 -0
  94. package/cli/lib/internal/governance/ai/check-high-risk-doc-metadata-core.mjs +173 -0
  95. package/cli/lib/internal/governance/config.mjs +150 -0
  96. package/cli/lib/internal/governance/runner.mjs +35 -0
  97. package/cli/lib/internal/governance/shared/read-yaml-with-fragments.mjs +49 -0
  98. package/cli/lib/internal/validators-artifacts.mjs +515 -0
  99. package/cli/lib/internal/validators-shared.mjs +28 -0
  100. package/cli/lib/internal/validators-spec-helpers.mjs +186 -0
  101. package/cli/lib/internal/validators-spec.mjs +410 -0
  102. package/cli/lib/shared.mjs +83 -0
  103. package/cli/lib/topic-draft-packets.mjs +48 -0
  104. package/cli/lib/topic-goal.mjs +361 -0
  105. package/cli/lib/topic-runner.mjs +772 -0
  106. package/cli/lib/topic.mjs +93 -0
  107. package/cli/lib/ui.mjs +178 -0
  108. package/cli/lib/validators.mjs +78 -0
  109. package/cli/lib/value-helpers.mjs +24 -0
  110. package/cli/lib/yaml-helpers.mjs +133 -0
  111. package/cli/nimicoding.mjs +1 -0
  112. package/cli/seeds/bootstrap.mjs +47 -0
  113. package/config/audit-execution-artifacts.yaml +20 -0
  114. package/config/bootstrap.yaml +6 -0
  115. package/config/external-execution-artifacts.yaml +16 -0
  116. package/config/host-adapter.yaml +30 -0
  117. package/config/host-profile.yaml +29 -0
  118. package/config/installer-evidence.yaml +31 -0
  119. package/config/skill-installer.yaml +23 -0
  120. package/config/skill-manifest.yaml +46 -0
  121. package/config/skills.yaml +30 -0
  122. package/config/spec-generation-inputs.yaml +25 -0
  123. package/contracts/acceptance.schema.yaml +16 -0
  124. package/contracts/admission-checklist.schema.yaml +15 -0
  125. package/contracts/audit-chunk.schema.yaml +110 -0
  126. package/contracts/audit-closeout.schema.yaml +51 -0
  127. package/contracts/audit-finding.schema.yaml +61 -0
  128. package/contracts/audit-ledger.schema.yaml +138 -0
  129. package/contracts/audit-plan.schema.yaml +123 -0
  130. package/contracts/audit-remediation-map.schema.yaml +51 -0
  131. package/contracts/audit-rerun.schema.yaml +31 -0
  132. package/contracts/audit-sweep-result.yaml +49 -0
  133. package/contracts/authority-convergence-audit.schema.yaml +19 -0
  134. package/contracts/closeout.schema.yaml +25 -0
  135. package/contracts/decision-review.schema.yaml +16 -0
  136. package/contracts/doc-spec-audit-result.yaml +19 -0
  137. package/contracts/execution-packet.schema.yaml +49 -0
  138. package/contracts/external-host-compatibility.yaml +22 -0
  139. package/contracts/forbidden-shortcuts.catalog.yaml +23 -0
  140. package/contracts/high-risk-admission.schema.yaml +23 -0
  141. package/contracts/high-risk-execution-result.yaml +20 -0
  142. package/contracts/orchestration-state.schema.yaml +41 -0
  143. package/contracts/overflow-continuation.schema.yaml +12 -0
  144. package/contracts/packet.schema.yaml +30 -0
  145. package/contracts/pending-note.schema.yaml +17 -0
  146. package/contracts/prompt.schema.yaml +12 -0
  147. package/contracts/remediation.schema.yaml +16 -0
  148. package/contracts/result.schema.yaml +24 -0
  149. package/contracts/spec-generation-audit.schema.yaml +31 -0
  150. package/contracts/spec-generation-inputs.schema.yaml +39 -0
  151. package/contracts/spec-reconstruction-result.yaml +37 -0
  152. package/contracts/topic-goal.schema.yaml +78 -0
  153. package/contracts/topic-run-ledger.schema.yaml +72 -0
  154. package/contracts/topic-step-decision.schema.yaml +45 -0
  155. package/contracts/topic.schema.yaml +65 -0
  156. package/contracts/true-close.schema.yaml +15 -0
  157. package/contracts/wave.schema.yaml +29 -0
  158. package/contracts/worker-output.schema.yaml +15 -0
  159. package/methodology/audit-sweep-p0p1-recall.yaml +45 -0
  160. package/methodology/authority-convergence-policy.yaml +42 -0
  161. package/methodology/core.yaml +25 -0
  162. package/methodology/four-closure-policy.yaml +28 -0
  163. package/methodology/overflow-continuation-policy.yaml +14 -0
  164. package/methodology/role-separation-policy.yaml +28 -0
  165. package/methodology/skill-exchange-projection.yaml +114 -0
  166. package/methodology/skill-handoff.yaml +34 -0
  167. package/methodology/skill-installer-result.yaml +27 -0
  168. package/methodology/skill-installer-summary-projection.yaml +181 -0
  169. package/methodology/skill-runtime.yaml +23 -0
  170. package/methodology/spec-reconstruction.yaml +63 -0
  171. package/methodology/spec-target-truth-profile.yaml +53 -0
  172. package/methodology/topic-lifecycle-report.yaml +144 -0
  173. package/methodology/topic-lifecycle.yaml +37 -0
  174. package/methodology/topic-naming-ontology.yaml +21 -0
  175. package/methodology/topic-ontology.yaml +38 -0
  176. package/methodology/topic-validation-policy.yaml +9 -0
  177. package/methodology/wave-dag-policy.yaml +14 -0
  178. package/package.json +50 -0
  179. package/spec/_meta/command-gating-matrix.yaml +110 -0
  180. package/spec/_meta/generate-drift-migration-checklist.yaml +155 -0
  181. package/spec/_meta/governance-routing-cutover-checklist.yaml +35 -0
  182. package/spec/_meta/phase2-impacted-surface-matrix.yaml +44 -0
  183. package/spec/_meta/spec-authority-cutover-readiness.yaml +104 -0
  184. package/spec/_meta/spec-tree-model.yaml +72 -0
  185. package/spec/bootstrap-state.yaml +99 -0
  186. package/spec/product-scope.yaml +56 -0
@@ -0,0 +1,515 @@
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
+ }
@@ -0,0 +1,28 @@
1
+ export const VALIDATOR_CLI_RESULT_CONTRACT = "validator-cli-result.v1";
2
+
3
+ export const VALIDATOR_NATIVE_REFUSAL_CODES = {
4
+ EXECUTION_PACKET_MISSING: "EXECUTION_PACKET_MISSING",
5
+ EXECUTION_PACKET_INVALID: "EXECUTION_PACKET_INVALID",
6
+ ORCHESTRATION_STATE_MISSING: "ORCHESTRATION_STATE_MISSING",
7
+ ORCHESTRATION_STATE_INVALID: "ORCHESTRATION_STATE_INVALID",
8
+ PROMPT_MISSING: "PROMPT_MISSING",
9
+ PROMPT_INVALID: "PROMPT_INVALID",
10
+ WORKER_OUTPUT_MISSING: "WORKER_OUTPUT_MISSING",
11
+ WORKER_OUTPUT_INVALID: "WORKER_OUTPUT_INVALID",
12
+ RUNNER_SIGNAL_MISSING: "RUNNER_SIGNAL_MISSING",
13
+ RUNNER_SIGNAL_INVALID: "RUNNER_SIGNAL_INVALID",
14
+ ACCEPTANCE_MISSING: "ACCEPTANCE_MISSING",
15
+ ACCEPTANCE_INVALID: "ACCEPTANCE_INVALID",
16
+ SPEC_TREE_MISSING: "SPEC_TREE_MISSING",
17
+ SPEC_TREE_INVALID: "SPEC_TREE_INVALID",
18
+ SPEC_AUDIT_MISSING: "SPEC_AUDIT_MISSING",
19
+ SPEC_AUDIT_INVALID: "SPEC_AUDIT_INVALID",
20
+ };
21
+
22
+ export function makeValidatorRefusal(code, message) {
23
+ return { code, message };
24
+ }
25
+
26
+ export function normalizeArgv(args) {
27
+ return args[0] === "--" ? args.slice(1) : args;
28
+ }