@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,263 @@
1
+ import path from "node:path";
2
+
3
+ import {
4
+ HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
5
+ HIGH_RISK_REVIEW_PAYLOAD_CONTRACT_VERSION,
6
+ } from "../constants.mjs";
7
+ import { inspectDoctorState } from "./doctor.mjs";
8
+ import { readTextIfFile } from "./fs-helpers.mjs";
9
+ import {
10
+ localize,
11
+ styleCommand,
12
+ styleHeading,
13
+ styleLabel,
14
+ styleStatus,
15
+ } from "./ui.mjs";
16
+ import { isPlainObject } from "./value-helpers.mjs";
17
+
18
+ function translateReviewReason(reason) {
19
+ const translations = new Map([
20
+ ["imported ingest payload must declare contractVersion nimicoding.high-risk-ingest.v1", "导入的 ingest payload 必须声明 contractVersion nimicoding.high-risk-ingest.v1"],
21
+ ["imported ingest payload must declare skill.id high_risk_execution", "导入的 ingest payload 必须声明 skill.id 为 high_risk_execution"],
22
+ ["imported ingest payload must remain localOnly true", "导入的 ingest payload 必须保持 localOnly 为 true"],
23
+ ["review-high-risk-execution requires an ingest payload with ok true", "review-high-risk-execution 需要一个 ok 为 true 的 ingest payload"],
24
+ ["imported ingest payload must include validations", "导入的 ingest payload 必须包含 validations"],
25
+ ["review-high-risk-execution requires all ingest validations to be mechanically ok", "review-high-risk-execution 需要所有 ingest 校验均机械通过"],
26
+ ["Bootstrap or handoff validation is failing; repair doctor errors before projecting review-ready artifacts", "bootstrap 或 handoff 校验失败;请先修复 doctor 报错,再投影 review-ready 产物"],
27
+ ["High-risk review projection requires the canonical tree under `.nimi/spec`", "high-risk review 投影需要 `.nimi/spec` 下的 canonical tree"],
28
+ ["Candidate artifacts are ready for manager-owned semantic review", "候选产物已准备好供 manager 执行语义审查"],
29
+ ]);
30
+ return translations.get(reason) ?? reason;
31
+ }
32
+
33
+ async function loadImportedIngestPayload(projectRoot, fromPath) {
34
+ const absolutePath = path.resolve(projectRoot, fromPath);
35
+ const rawText = await readTextIfFile(absolutePath);
36
+
37
+ if (rawText === null) {
38
+ return {
39
+ ok: false,
40
+ error: `${localize(
41
+ `nimicoding review-high-risk-execution refused: cannot read imported ingest JSON at ${absolutePath}.`,
42
+ `nimicoding review-high-risk-execution 已拒绝:无法读取 ${absolutePath} 处的导入 ingest JSON。`,
43
+ )}\n`,
44
+ };
45
+ }
46
+
47
+ let parsed;
48
+ try {
49
+ parsed = JSON.parse(rawText);
50
+ } catch {
51
+ return {
52
+ ok: false,
53
+ error: `${localize(
54
+ `nimicoding review-high-risk-execution refused: imported ingest JSON at ${absolutePath} is invalid JSON.`,
55
+ `nimicoding review-high-risk-execution 已拒绝:${absolutePath} 处的导入 ingest JSON 不是合法 JSON。`,
56
+ )}\n`,
57
+ };
58
+ }
59
+
60
+ if (!isPlainObject(parsed)) {
61
+ return {
62
+ ok: false,
63
+ error: `${localize(
64
+ "nimicoding review-high-risk-execution refused: imported ingest JSON must be an object.",
65
+ "nimicoding review-high-risk-execution 已拒绝:导入的 ingest JSON 必须是对象。",
66
+ )}\n`,
67
+ };
68
+ }
69
+
70
+ return {
71
+ ok: true,
72
+ path: absolutePath,
73
+ payload: parsed,
74
+ };
75
+ }
76
+
77
+ function validateImportedIngestPayload(payload) {
78
+ if (payload.contractVersion !== "nimicoding.high-risk-ingest.v1") {
79
+ return {
80
+ ok: false,
81
+ reason: "imported ingest payload must declare contractVersion nimicoding.high-risk-ingest.v1",
82
+ };
83
+ }
84
+
85
+ if (payload.skill?.id !== "high_risk_execution") {
86
+ return {
87
+ ok: false,
88
+ reason: "imported ingest payload must declare skill.id high_risk_execution",
89
+ };
90
+ }
91
+
92
+ if (payload.localOnly !== true) {
93
+ return {
94
+ ok: false,
95
+ reason: "imported ingest payload must remain localOnly true",
96
+ };
97
+ }
98
+
99
+ if (payload.ok !== true) {
100
+ return {
101
+ ok: false,
102
+ reason: "review-high-risk-execution requires an ingest payload with ok true",
103
+ };
104
+ }
105
+
106
+ const validations = payload.validations;
107
+ if (!isPlainObject(validations)) {
108
+ return {
109
+ ok: false,
110
+ reason: "imported ingest payload must include validations",
111
+ };
112
+ }
113
+
114
+ const requiredValidationKeys = [
115
+ "executionPacket",
116
+ "orchestrationState",
117
+ "prompt",
118
+ "workerOutput",
119
+ "evidence",
120
+ ];
121
+ for (const key of requiredValidationKeys) {
122
+ if (!(key in validations)) {
123
+ return {
124
+ ok: false,
125
+ reason: `imported ingest payload validations are missing ${key}`,
126
+ };
127
+ }
128
+ }
129
+
130
+ if (
131
+ validations.executionPacket?.ok !== true
132
+ || validations.orchestrationState?.ok !== true
133
+ || validations.prompt?.ok !== true
134
+ || validations.workerOutput?.ok !== true
135
+ || !Array.isArray(validations.evidence)
136
+ || validations.evidence.some((entry) => !entry || entry.ok !== true)
137
+ ) {
138
+ return {
139
+ ok: false,
140
+ reason: "review-high-risk-execution requires all ingest validations to be mechanically ok",
141
+ };
142
+ }
143
+
144
+ return { ok: true };
145
+ }
146
+
147
+ function evaluateHighRiskReviewReadiness(doctorResult) {
148
+ if (!doctorResult.ok || !doctorResult.handoffReadiness.ok) {
149
+ return {
150
+ ok: false,
151
+ reason: "Bootstrap or handoff validation is failing; repair doctor errors before projecting review-ready artifacts",
152
+ };
153
+ }
154
+
155
+ if (doctorResult.lifecycleState?.treeState !== "canonical_tree_ready" || doctorResult.canonicalTree?.requiredFilesValid !== true) {
156
+ return {
157
+ ok: false,
158
+ reason: "High-risk review projection requires canonical_tree_ready with declared canonical files present",
159
+ };
160
+ }
161
+
162
+ return {
163
+ ok: true,
164
+ reason: "Candidate artifacts are ready for manager-owned semantic review",
165
+ };
166
+ }
167
+
168
+ export async function buildHighRiskReviewPayload(projectRoot, fromPath, options = {}) {
169
+ const imported = await loadImportedIngestPayload(projectRoot, fromPath);
170
+ if (!imported.ok) {
171
+ return {
172
+ ok: false,
173
+ exitCode: 2,
174
+ inputError: true,
175
+ error: imported.error,
176
+ };
177
+ }
178
+
179
+ const inputValidation = validateImportedIngestPayload(imported.payload);
180
+ if (!inputValidation.ok) {
181
+ return {
182
+ ok: false,
183
+ exitCode: 2,
184
+ inputError: true,
185
+ error: `${localize(
186
+ `nimicoding review-high-risk-execution refused: ${inputValidation.reason}.`,
187
+ `nimicoding review-high-risk-execution 已拒绝:${translateReviewReason(inputValidation.reason)}。`,
188
+ )}\n`,
189
+ };
190
+ }
191
+
192
+ const doctorResult = await inspectDoctorState(projectRoot);
193
+ const readiness = evaluateHighRiskReviewReadiness(doctorResult);
194
+ const artifactPath = path.join(
195
+ projectRoot,
196
+ ".nimi",
197
+ "local",
198
+ "handoff-results",
199
+ "high_risk_execution.review.json",
200
+ );
201
+
202
+ return {
203
+ contractVersion: HIGH_RISK_REVIEW_PAYLOAD_CONTRACT_VERSION,
204
+ ok: readiness.ok,
205
+ exitCode: readiness.ok ? 0 : 1,
206
+ projectRoot,
207
+ sourceIngestRef: imported.path,
208
+ localOnly: true,
209
+ artifactPath,
210
+ skill: {
211
+ id: "high_risk_execution",
212
+ resultContractRef: HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
213
+ },
214
+ verifiedAt: imported.payload.verifiedAt,
215
+ reviewStatus: readiness.ok ? "ready_for_manager_review" : "blocked",
216
+ managerReviewOwner: doctorResult.delegatedContracts.semanticReviewOwner,
217
+ summary: imported.payload.summary,
218
+ attachmentRefs: {
219
+ packet_ref: imported.payload.summary.packet_ref,
220
+ orchestration_state_ref: imported.payload.summary.orchestration_state_ref,
221
+ prompt_ref: imported.payload.summary.prompt_ref,
222
+ worker_output_ref: imported.payload.summary.worker_output_ref,
223
+ evidence_refs: imported.payload.summary.evidence_refs,
224
+ },
225
+ ingestValidations: imported.payload.validations,
226
+ readiness,
227
+ doctor: {
228
+ ok: doctorResult.ok,
229
+ handoffReadiness: doctorResult.handoffReadiness,
230
+ delegatedContracts: doctorResult.delegatedContracts,
231
+ },
232
+ nextAction: readiness.ok
233
+ ? options.writeLocal
234
+ ? `Write the high-risk review artifact to ${artifactPath}.`
235
+ : "Review the review-ready payload or write it locally with `--write-local`."
236
+ : readiness.reason,
237
+ };
238
+ }
239
+
240
+ export function formatHighRiskReviewPayload(payload) {
241
+ const nextAction = payload.readiness.ok
242
+ ? payload.nextAction.startsWith("Write the high-risk review artifact to ")
243
+ ? localize(payload.nextAction, `将 high-risk review 产物写入 ${payload.artifactPath}。`)
244
+ : localize(
245
+ payload.nextAction,
246
+ `检查 review-ready payload,或使用 ${styleCommand("--write-local")} 将其写入本地。`,
247
+ )
248
+ : translateReviewReason(payload.nextAction);
249
+ const lines = [
250
+ styleHeading(`nimicoding review-high-risk-execution: ${payload.projectRoot}`),
251
+ "",
252
+ styleLabel(localize("Result:", "结果:")),
253
+ ` - review_status: ${payload.reviewStatus}`,
254
+ ` - manager_review_owner: ${payload.managerReviewOwner ?? localize("unknown", "未知")}`,
255
+ ` - ready: ${styleStatus(payload.readiness.ok ? "ready" : "needs_attention")}`,
256
+ ` - local_only: ${payload.localOnly ? "true" : "false"}`,
257
+ "",
258
+ styleLabel(localize("Next:", "下一步:")),
259
+ ` - ${nextAction}`,
260
+ ];
261
+
262
+ return `${lines.join("\n")}\n`;
263
+ }
@@ -0,0 +1,132 @@
1
+ import path from "node:path";
2
+
3
+ import {
4
+ AUDIT_SWEEP_RESULT_CONTRACT_REF,
5
+ ACCEPTANCE_SCHEMA_REF,
6
+ BLUEPRINT_REFERENCE_REF,
7
+ COMMAND_GATING_MATRIX_REF,
8
+ DOC_SPEC_AUDIT_RESULT_CONTRACT_REF,
9
+ EXTERNAL_HOST_COMPATIBILITY_CONTRACT_REF,
10
+ EXECUTION_PACKET_SCHEMA_REF,
11
+ HIGH_RISK_ADMISSION_CONTRACT_REF,
12
+ HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
13
+ ORCHESTRATION_STATE_SCHEMA_REF,
14
+ PROMPT_SCHEMA_REF,
15
+ SPEC_GENERATION_AUDIT_CONTRACT_REF,
16
+ SPEC_GENERATION_INPUTS_CONTRACT_REF,
17
+ SPEC_GENERATION_INPUTS_REF,
18
+ SPEC_RECONSTRUCTION_RESULT_CONTRACT_REF,
19
+ SPEC_TREE_MODEL_REF,
20
+ WORKER_OUTPUT_SCHEMA_REF,
21
+ } from "../../constants.mjs";
22
+ import { readTextIfFile } from "../fs-helpers.mjs";
23
+ import {
24
+ parseBlueprintReference,
25
+ parseCommandGatingMatrix,
26
+ parseAuditSweepContract,
27
+ parseDocSpecAuditContract,
28
+ parseExternalHostCompatibilityContract,
29
+ parseHighRiskAdmissionContract,
30
+ parseHighRiskExecutionContract,
31
+ parseHighRiskSchemaContract,
32
+ parseSpecGenerationAuditContract,
33
+ parseSpecGenerationInputsConfig,
34
+ parseSpecGenerationInputsContract,
35
+ parseSpecReconstructionContract,
36
+ parseSpecTreeModel,
37
+ } from "./contracts-parse.mjs";
38
+
39
+ async function loadParsedYaml(projectRoot, relativePath, parse) {
40
+ const text = await readTextIfFile(path.join(projectRoot, relativePath));
41
+ return {
42
+ path: relativePath,
43
+ text,
44
+ ...parse(text),
45
+ };
46
+ }
47
+
48
+ export function loadSpecReconstructionContract(projectRoot) {
49
+ return loadParsedYaml(
50
+ projectRoot,
51
+ SPEC_RECONSTRUCTION_RESULT_CONTRACT_REF,
52
+ parseSpecReconstructionContract,
53
+ );
54
+ }
55
+
56
+ export function loadSpecTreeModelContract(projectRoot) {
57
+ return loadParsedYaml(projectRoot, SPEC_TREE_MODEL_REF, parseSpecTreeModel);
58
+ }
59
+
60
+ export function loadSpecGenerationInputsContract(projectRoot) {
61
+ return loadParsedYaml(
62
+ projectRoot,
63
+ SPEC_GENERATION_INPUTS_CONTRACT_REF,
64
+ parseSpecGenerationInputsContract,
65
+ );
66
+ }
67
+
68
+ export function loadSpecGenerationAuditContract(projectRoot) {
69
+ return loadParsedYaml(
70
+ projectRoot,
71
+ SPEC_GENERATION_AUDIT_CONTRACT_REF,
72
+ parseSpecGenerationAuditContract,
73
+ );
74
+ }
75
+
76
+ export function loadSpecGenerationInputsConfig(projectRoot) {
77
+ return loadParsedYaml(projectRoot, SPEC_GENERATION_INPUTS_REF, parseSpecGenerationInputsConfig);
78
+ }
79
+
80
+ export function loadCommandGatingMatrix(projectRoot) {
81
+ return loadParsedYaml(projectRoot, COMMAND_GATING_MATRIX_REF, parseCommandGatingMatrix);
82
+ }
83
+
84
+ export function loadBlueprintReference(projectRoot) {
85
+ return loadParsedYaml(projectRoot, BLUEPRINT_REFERENCE_REF, parseBlueprintReference);
86
+ }
87
+
88
+ export function loadDocSpecAuditContract(projectRoot) {
89
+ return loadParsedYaml(projectRoot, DOC_SPEC_AUDIT_RESULT_CONTRACT_REF, parseDocSpecAuditContract);
90
+ }
91
+
92
+ export function loadAuditSweepContract(projectRoot) {
93
+ return loadParsedYaml(projectRoot, AUDIT_SWEEP_RESULT_CONTRACT_REF, parseAuditSweepContract);
94
+ }
95
+
96
+ export function loadHighRiskExecutionContract(projectRoot) {
97
+ return loadParsedYaml(projectRoot, HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF, parseHighRiskExecutionContract);
98
+ }
99
+
100
+ export function loadHighRiskAdmissionContract(projectRoot) {
101
+ return loadParsedYaml(projectRoot, HIGH_RISK_ADMISSION_CONTRACT_REF, parseHighRiskAdmissionContract);
102
+ }
103
+
104
+ export function loadExternalHostCompatibilityContract(projectRoot) {
105
+ return loadParsedYaml(
106
+ projectRoot,
107
+ EXTERNAL_HOST_COMPATIBILITY_CONTRACT_REF,
108
+ parseExternalHostCompatibilityContract,
109
+ );
110
+ }
111
+
112
+ export async function loadHighRiskSchemaContracts(projectRoot) {
113
+ const contractRefs = [
114
+ EXECUTION_PACKET_SCHEMA_REF,
115
+ ORCHESTRATION_STATE_SCHEMA_REF,
116
+ PROMPT_SCHEMA_REF,
117
+ WORKER_OUTPUT_SCHEMA_REF,
118
+ ACCEPTANCE_SCHEMA_REF,
119
+ ];
120
+
121
+ const results = [];
122
+ for (const schemaRef of contractRefs) {
123
+ const text = await readTextIfFile(path.join(projectRoot, schemaRef));
124
+ results.push({
125
+ path: schemaRef,
126
+ text,
127
+ ...parseHighRiskSchemaContract(text, schemaRef),
128
+ });
129
+ }
130
+
131
+ return results;
132
+ }
@@ -0,0 +1,131 @@
1
+ import {
2
+ AUDIT_SWEEP_SUMMARY_REQUIRED_FIELDS,
3
+ AUDIT_SWEEP_SUMMARY_STATUS,
4
+ DOC_SPEC_AUDIT_DEFAULT_COMPARED_PATHS,
5
+ DOC_SPEC_AUDIT_SUMMARY_REQUIRED_FIELDS,
6
+ DOC_SPEC_AUDIT_SUMMARY_STATUS,
7
+ EXTERNAL_HOST_COMPATIBILITY_FORBIDDEN_BEHAVIOR,
8
+ EXTERNAL_HOST_COMPATIBILITY_REQUIRED_BEHAVIOR,
9
+ EXTERNAL_HOST_COMPATIBILITY_SUPPORTED_HOST_EXAMPLES,
10
+ EXTERNAL_HOST_COMPATIBILITY_SUPPORTED_POSTURE,
11
+ HIGH_RISK_ADMISSION_DISPOSITION_ENUM,
12
+ HIGH_RISK_ADMISSION_RECORD_REQUIRED_FIELDS,
13
+ HIGH_RISK_ADMISSION_REQUIRED_TOP_LEVEL_KEYS,
14
+ HIGH_RISK_EXECUTION_SUMMARY_REQUIRED_FIELDS,
15
+ HIGH_RISK_EXECUTION_SUMMARY_STATUS,
16
+ HIGH_RISK_SCHEMA_SPECS,
17
+ } from "../../constants.mjs";
18
+ import { arraysEqual, toStringArray } from "../value-helpers.mjs";
19
+ import { parseYamlText } from "../yaml-helpers.mjs";
20
+
21
+ export function parseDocSpecAuditContract(text) {
22
+ const parsed = parseYamlText(text);
23
+ const summaryRequiredFields = toStringArray(parsed?.summary_required_fields);
24
+ const summaryStatusEnum = toStringArray(parsed?.summary_status_enum);
25
+ const defaultComparedPaths = toStringArray(parsed?.default_compared_paths);
26
+
27
+ return {
28
+ ok: arraysEqual(summaryRequiredFields, DOC_SPEC_AUDIT_SUMMARY_REQUIRED_FIELDS)
29
+ && arraysEqual(summaryStatusEnum, DOC_SPEC_AUDIT_SUMMARY_STATUS)
30
+ && arraysEqual(defaultComparedPaths, DOC_SPEC_AUDIT_DEFAULT_COMPARED_PATHS),
31
+ summaryRequiredFields,
32
+ summaryStatusEnum,
33
+ defaultComparedPaths,
34
+ };
35
+ }
36
+
37
+ export function parseAuditSweepContract(text) {
38
+ const parsed = parseYamlText(text);
39
+ const summaryRequiredFields = toStringArray(parsed?.summary_required_fields);
40
+ const summaryStatusEnum = toStringArray(parsed?.summary_status_enum);
41
+
42
+ return {
43
+ ok: arraysEqual(summaryRequiredFields, AUDIT_SWEEP_SUMMARY_REQUIRED_FIELDS)
44
+ && arraysEqual(summaryStatusEnum, AUDIT_SWEEP_SUMMARY_STATUS),
45
+ summaryRequiredFields,
46
+ summaryStatusEnum,
47
+ };
48
+ }
49
+
50
+ export function parseHighRiskExecutionContract(text) {
51
+ const parsed = parseYamlText(text);
52
+ const summaryRequiredFields = toStringArray(parsed?.summary_required_fields);
53
+ const summaryStatusEnum = toStringArray(parsed?.summary_status_enum);
54
+
55
+ return {
56
+ ok: arraysEqual(summaryRequiredFields, HIGH_RISK_EXECUTION_SUMMARY_REQUIRED_FIELDS)
57
+ && arraysEqual(summaryStatusEnum, HIGH_RISK_EXECUTION_SUMMARY_STATUS),
58
+ summaryRequiredFields,
59
+ summaryStatusEnum,
60
+ };
61
+ }
62
+
63
+ export function parseHighRiskAdmissionContract(text) {
64
+ const parsed = parseYamlText(text);
65
+ const topLevelRequiredKeys = toStringArray(parsed?.top_level_required_keys);
66
+ const admissionRequiredFields = toStringArray(parsed?.admission_required_fields);
67
+ const dispositionEnum = toStringArray(parsed?.disposition_enum);
68
+
69
+ return {
70
+ ok: String(parsed?.truth_contract?.id ?? "") === "canonical_high_risk_admissions_truth"
71
+ && arraysEqual(topLevelRequiredKeys, HIGH_RISK_ADMISSION_REQUIRED_TOP_LEVEL_KEYS)
72
+ && arraysEqual(admissionRequiredFields, HIGH_RISK_ADMISSION_RECORD_REQUIRED_FIELDS)
73
+ && arraysEqual(dispositionEnum, HIGH_RISK_ADMISSION_DISPOSITION_ENUM),
74
+ topLevelRequiredKeys,
75
+ admissionRequiredFields,
76
+ dispositionEnum,
77
+ };
78
+ }
79
+
80
+ export function parseExternalHostCompatibilityContract(text) {
81
+ const parsed = parseYamlText(text);
82
+ const supportedHostPosture = toStringArray(parsed?.supported_host_posture);
83
+ const supportedHostExamples = toStringArray(parsed?.supported_host_examples);
84
+ const requiredBehavior = toStringArray(parsed?.required_behavior);
85
+ const forbiddenBehavior = toStringArray(parsed?.forbidden_behavior);
86
+
87
+ return {
88
+ ok: String(parsed?.compatibility_contract?.id ?? "") === "external_host_boundary_compatibility"
89
+ && String(parsed?.compatibility_contract?.completion_profile ?? "") === "boundary_complete"
90
+ && arraysEqual(supportedHostPosture, EXTERNAL_HOST_COMPATIBILITY_SUPPORTED_POSTURE)
91
+ && arraysEqual(supportedHostExamples, EXTERNAL_HOST_COMPATIBILITY_SUPPORTED_HOST_EXAMPLES)
92
+ && arraysEqual(requiredBehavior, EXTERNAL_HOST_COMPATIBILITY_REQUIRED_BEHAVIOR)
93
+ && arraysEqual(forbiddenBehavior, EXTERNAL_HOST_COMPATIBILITY_FORBIDDEN_BEHAVIOR),
94
+ supportedHostPosture,
95
+ supportedHostExamples,
96
+ requiredBehavior,
97
+ forbiddenBehavior,
98
+ };
99
+ }
100
+
101
+ export function parseHighRiskSchemaContract(text, schemaRef) {
102
+ const parsed = parseYamlText(text);
103
+ const spec = HIGH_RISK_SCHEMA_SPECS[schemaRef];
104
+
105
+ if (!spec || !parsed) {
106
+ return {
107
+ ok: false,
108
+ id: null,
109
+ kind: null,
110
+ listFieldMatches: [],
111
+ rulesMatch: false,
112
+ };
113
+ }
114
+
115
+ const listFieldMatches = Object.entries(spec.listFields).map(([field, expectedValues]) => ({
116
+ field,
117
+ ok: arraysEqual(toStringArray(parsed[field]), expectedValues),
118
+ }));
119
+ const rulesMatch = arraysEqual(toStringArray(parsed.rules), spec.requiredRules);
120
+
121
+ return {
122
+ ok: String(parsed.id ?? "") === spec.id
123
+ && String(parsed.kind ?? "") === spec.kind
124
+ && listFieldMatches.every((entry) => entry.ok)
125
+ && rulesMatch,
126
+ id: String(parsed.id ?? ""),
127
+ kind: String(parsed.kind ?? ""),
128
+ listFieldMatches,
129
+ rulesMatch,
130
+ };
131
+ }