@nimiplatform/nimi-coding 0.2.8 → 0.3.1

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 (206) hide show
  1. package/CHANGELOG.md +10 -90
  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/commands/validate-spec-governance.mjs +20 -0
  8. package/cli/constants.mjs +9 -417
  9. package/cli/help.mjs +28 -145
  10. package/cli/index.mjs +5 -33
  11. package/cli/lib/blueprint-audit.mjs +5 -12
  12. package/cli/lib/bootstrap.mjs +0 -9
  13. package/cli/lib/contracts.mjs +0 -163
  14. package/cli/lib/doctor.mjs +155 -10
  15. package/cli/lib/entrypoints.mjs +63 -167
  16. package/cli/lib/internal/contracts-loaders.mjs +0 -85
  17. package/cli/lib/internal/contracts-parse.mjs +84 -520
  18. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +13 -8
  19. package/cli/lib/internal/surface-taxonomy-validators.mjs +316 -66
  20. package/cli/lib/internal/validators-shared.mjs +0 -16
  21. package/cli/lib/internal/validators-spec-helpers.mjs +7 -140
  22. package/cli/lib/internal/validators-spec.mjs +103 -342
  23. package/cli/lib/shared.mjs +1 -42
  24. package/cli/lib/validators.mjs +0 -48
  25. package/cli/seeds/seed-policy.yaml +0 -3
  26. package/config/bootstrap.yaml +4 -4
  27. package/config/spec-generation-inputs.yaml +6 -12
  28. package/contracts/domain-admission.schema.yaml +3 -3
  29. package/contracts/migration-inventory.schema.yaml +12 -75
  30. package/contracts/negative-fixtures.yaml +19 -99
  31. package/contracts/placement-contract.schema.yaml +49 -78
  32. package/contracts/projection-edge.schema.yaml +37 -121
  33. package/contracts/shared-enums.yaml +4 -8
  34. package/contracts/spec-generation-inputs.schema.yaml +15 -112
  35. package/contracts/spec-layout.schema.yaml +32 -0
  36. package/contracts/surface-taxonomy.schema.yaml +43 -94
  37. package/contracts/table-family.schema.yaml +1 -1
  38. package/contracts/tracked-output-admission.schema.yaml +13 -66
  39. package/methodology/core.yaml +33 -25
  40. package/methodology/four-closure-policy.yaml +18 -26
  41. package/methodology/role-separation-policy.yaml +21 -27
  42. package/methodology/spec-reconstruction.yaml +17 -34
  43. package/package.json +2 -4
  44. package/spec/_meta/spec-tree-model.yaml +5 -101
  45. package/spec/product-scope.yaml +25 -57
  46. package/adapters/README.md +0 -25
  47. package/adapters/claude/README.md +0 -89
  48. package/adapters/claude/profile.yaml +0 -70
  49. package/adapters/codex/README.md +0 -53
  50. package/adapters/codex/profile.yaml +0 -78
  51. package/adapters/oh-my-codex/README.md +0 -184
  52. package/adapters/oh-my-codex/profile.yaml +0 -46
  53. package/cli/commands/admit-high-risk-decision.mjs +0 -108
  54. package/cli/commands/audit-sweep.mjs +0 -364
  55. package/cli/commands/closeout.mjs +0 -186
  56. package/cli/commands/decide-high-risk-execution.mjs +0 -124
  57. package/cli/commands/handoff.mjs +0 -123
  58. package/cli/commands/ingest-high-risk-execution.mjs +0 -95
  59. package/cli/commands/review-high-risk-execution.mjs +0 -95
  60. package/cli/commands/sweep-design.mjs +0 -295
  61. package/cli/commands/sweep.mjs +0 -22
  62. package/cli/commands/topic-formatters.mjs +0 -382
  63. package/cli/commands/topic-goal.mjs +0 -33
  64. package/cli/commands/topic-options-shared.mjs +0 -27
  65. package/cli/commands/topic-options-workflow.mjs +0 -767
  66. package/cli/commands/topic-options.mjs +0 -626
  67. package/cli/commands/topic-runner.mjs +0 -169
  68. package/cli/commands/topic.mjs +0 -795
  69. package/cli/commands/validate-acceptance.mjs +0 -5
  70. package/cli/commands/validate-execution-packet.mjs +0 -5
  71. package/cli/commands/validate-orchestration-state.mjs +0 -5
  72. package/cli/commands/validate-prompt.mjs +0 -5
  73. package/cli/commands/validate-worker-output.mjs +0 -5
  74. package/cli/lib/adapter-profiles.mjs +0 -403
  75. package/cli/lib/audit-execution.mjs +0 -52
  76. package/cli/lib/audit-sweep-runtime/admissions.mjs +0 -508
  77. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +0 -356
  78. package/cli/lib/audit-sweep-runtime/chunks.mjs +0 -697
  79. package/cli/lib/audit-sweep-runtime/claude-auditor.mjs +0 -658
  80. package/cli/lib/audit-sweep-runtime/closeout.mjs +0 -144
  81. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +0 -654
  82. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +0 -527
  83. package/cli/lib/audit-sweep-runtime/common.mjs +0 -341
  84. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +0 -172
  85. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +0 -155
  86. package/cli/lib/audit-sweep-runtime/format.mjs +0 -57
  87. package/cli/lib/audit-sweep-runtime/ingest.mjs +0 -486
  88. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +0 -425
  89. package/cli/lib/audit-sweep-runtime/inventory.mjs +0 -798
  90. package/cli/lib/audit-sweep-runtime/ledger.mjs +0 -315
  91. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +0 -101
  92. package/cli/lib/audit-sweep-runtime/remediation.mjs +0 -349
  93. package/cli/lib/audit-sweep-runtime/rerun.mjs +0 -129
  94. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +0 -300
  95. package/cli/lib/audit-sweep-runtime/status.mjs +0 -62
  96. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +0 -215
  97. package/cli/lib/audit-sweep-runtime/validators.mjs +0 -797
  98. package/cli/lib/audit-sweep.mjs +0 -19
  99. package/cli/lib/authority-convergence.mjs +0 -720
  100. package/cli/lib/closeout.mjs +0 -732
  101. package/cli/lib/codex-sdk-runner.mjs +0 -76
  102. package/cli/lib/external-execution.mjs +0 -101
  103. package/cli/lib/handoff.mjs +0 -812
  104. package/cli/lib/high-risk-admission.mjs +0 -512
  105. package/cli/lib/high-risk-decision.mjs +0 -353
  106. package/cli/lib/high-risk-ingest.mjs +0 -321
  107. package/cli/lib/high-risk-review.mjs +0 -267
  108. package/cli/lib/internal/contracts-parse-high-risk.mjs +0 -131
  109. package/cli/lib/internal/contracts-validators.mjs +0 -399
  110. package/cli/lib/internal/doctor-bootstrap-surface.mjs +0 -406
  111. package/cli/lib/internal/doctor-delegated-surface.mjs +0 -256
  112. package/cli/lib/internal/doctor-finalize.mjs +0 -383
  113. package/cli/lib/internal/doctor-format.mjs +0 -286
  114. package/cli/lib/internal/doctor-inspectors.mjs +0 -327
  115. package/cli/lib/internal/doctor-state.mjs +0 -205
  116. package/cli/lib/internal/validators-artifacts.mjs +0 -515
  117. package/cli/lib/sweep-design-runtime/common.mjs +0 -246
  118. package/cli/lib/sweep-design-runtime/engine.mjs +0 -733
  119. package/cli/lib/sweep-design-runtime/fix-topic.mjs +0 -414
  120. package/cli/lib/sweep-design-runtime/lifecycle.mjs +0 -54
  121. package/cli/lib/sweep-design-runtime/results.mjs +0 -324
  122. package/cli/lib/sweep-design.mjs +0 -8
  123. package/cli/lib/topic-artifacts.mjs +0 -186
  124. package/cli/lib/topic-authority-coverage.mjs +0 -73
  125. package/cli/lib/topic-closeout.mjs +0 -560
  126. package/cli/lib/topic-common.mjs +0 -404
  127. package/cli/lib/topic-decisions.mjs +0 -332
  128. package/cli/lib/topic-draft-packets.mjs +0 -167
  129. package/cli/lib/topic-execution.mjs +0 -533
  130. package/cli/lib/topic-goal.mjs +0 -440
  131. package/cli/lib/topic-ledger.mjs +0 -281
  132. package/cli/lib/topic-lifecycle-artifacts.mjs +0 -173
  133. package/cli/lib/topic-root-validation.mjs +0 -288
  134. package/cli/lib/topic-runner-commands.mjs +0 -174
  135. package/cli/lib/topic-runner-deferral.mjs +0 -532
  136. package/cli/lib/topic-runner-stale-gates.mjs +0 -114
  137. package/cli/lib/topic-runner-validation.mjs +0 -138
  138. package/cli/lib/topic-runner.mjs +0 -727
  139. package/cli/lib/topic-scaffold.mjs +0 -252
  140. package/cli/lib/topic-waves.mjs +0 -403
  141. package/cli/lib/topic.mjs +0 -81
  142. package/config/audit-execution-artifacts.yaml +0 -20
  143. package/config/external-execution-artifacts.yaml +0 -16
  144. package/config/host-adapter.yaml +0 -30
  145. package/config/host-profile.yaml +0 -29
  146. package/config/installer-evidence.yaml +0 -31
  147. package/config/skill-installer.yaml +0 -23
  148. package/config/skill-manifest.yaml +0 -48
  149. package/config/skills.yaml +0 -30
  150. package/contracts/acceptance.schema.yaml +0 -16
  151. package/contracts/admission-checklist.schema.yaml +0 -15
  152. package/contracts/audit-chunk.schema.yaml +0 -123
  153. package/contracts/audit-closeout.schema.yaml +0 -51
  154. package/contracts/audit-finding.schema.yaml +0 -61
  155. package/contracts/audit-ledger.schema.yaml +0 -138
  156. package/contracts/audit-plan.schema.yaml +0 -138
  157. package/contracts/audit-remediation-map.schema.yaml +0 -52
  158. package/contracts/audit-rerun.schema.yaml +0 -31
  159. package/contracts/audit-sweep-result.yaml +0 -53
  160. package/contracts/authority-convergence-audit.schema.yaml +0 -19
  161. package/contracts/closeout.schema.yaml +0 -25
  162. package/contracts/decision-review.schema.yaml +0 -16
  163. package/contracts/doc-spec-audit-result.yaml +0 -19
  164. package/contracts/execution-packet.schema.yaml +0 -49
  165. package/contracts/external-host-compatibility.yaml +0 -22
  166. package/contracts/forbidden-shortcuts.catalog.yaml +0 -23
  167. package/contracts/high-risk-admission.schema.yaml +0 -23
  168. package/contracts/high-risk-execution-result.yaml +0 -20
  169. package/contracts/orchestration-state.schema.yaml +0 -41
  170. package/contracts/overflow-continuation.schema.yaml +0 -12
  171. package/contracts/packet.schema.yaml +0 -30
  172. package/contracts/pending-note.schema.yaml +0 -17
  173. package/contracts/prompt.schema.yaml +0 -12
  174. package/contracts/remediation.schema.yaml +0 -16
  175. package/contracts/result.schema.yaml +0 -24
  176. package/contracts/spec-reconstruction-result.yaml +0 -41
  177. package/contracts/sweep-design-result.yaml +0 -349
  178. package/contracts/topic-goal.schema.yaml +0 -87
  179. package/contracts/topic-run-ledger.schema.yaml +0 -72
  180. package/contracts/topic-step-decision.schema.yaml +0 -45
  181. package/contracts/topic.schema.yaml +0 -65
  182. package/contracts/true-close.schema.yaml +0 -15
  183. package/contracts/wave.schema.yaml +0 -29
  184. package/contracts/worker-output.schema.yaml +0 -15
  185. package/contracts/workflow-consumer.schema.yaml +0 -110
  186. package/methodology/audit-sweep-p0p1-recall.yaml +0 -45
  187. package/methodology/authority-convergence-policy.yaml +0 -42
  188. package/methodology/overflow-continuation-policy.yaml +0 -14
  189. package/methodology/skill-exchange-projection.yaml +0 -114
  190. package/methodology/skill-handoff.yaml +0 -34
  191. package/methodology/skill-installer-result.yaml +0 -27
  192. package/methodology/skill-installer-summary-projection.yaml +0 -181
  193. package/methodology/skill-runtime.yaml +0 -23
  194. package/methodology/spec-target-truth-profile.yaml +0 -46
  195. package/methodology/topic-lifecycle-report.yaml +0 -144
  196. package/methodology/topic-lifecycle.yaml +0 -37
  197. package/methodology/topic-naming-ontology.yaml +0 -21
  198. package/methodology/topic-ontology.yaml +0 -38
  199. package/methodology/topic-validation-policy.yaml +0 -9
  200. package/methodology/wave-dag-policy.yaml +0 -14
  201. package/spec/_meta/command-gating-matrix.yaml +0 -143
  202. package/spec/_meta/generate-drift-migration-checklist.yaml +0 -137
  203. package/spec/_meta/governance-routing-cutover-checklist.yaml +0 -35
  204. package/spec/_meta/phase2-impacted-surface-matrix.yaml +0 -44
  205. package/spec/_meta/spec-authority-cutover-readiness.yaml +0 -102
  206. package/spec/bootstrap-state.yaml +0 -99
@@ -1,399 +0,0 @@
1
- import {
2
- HIGH_RISK_ADMISSION_CONTRACT_REF,
3
- SPEC_GENERATION_AUDIT_REF,
4
- } from "../../constants.mjs";
5
- import {
6
- arraysEqual,
7
- isIsoUtcTimestamp,
8
- isPlainObject,
9
- } from "../value-helpers.mjs";
10
-
11
- const SPEC_RECONSTRUCTION_COVERAGE_SUMMARY_REQUIRED_FIELDS = [
12
- "complete_files",
13
- "partial_files",
14
- "placeholder_files",
15
- ];
16
-
17
- function validateRequiredFields(subject, requiredFields, label) {
18
- const missingFields = requiredFields.filter((field) => !(field in subject));
19
- if (missingFields.length > 0) {
20
- return {
21
- ok: false,
22
- reason: `${label} is missing required fields: ${missingFields.join(", ")}`,
23
- };
24
- }
25
-
26
- return null;
27
- }
28
-
29
- function validateSummaryEnvelope(summary, contract, verifiedAt, label) {
30
- if (!isPlainObject(summary)) {
31
- return {
32
- ok: false,
33
- reason: `${label} must be an object`,
34
- };
35
- }
36
-
37
- const missingFields = validateRequiredFields(summary, contract.summaryRequiredFields, label);
38
- if (missingFields) {
39
- return missingFields;
40
- }
41
-
42
- if (typeof summary.summary !== "string" || summary.summary.trim().length === 0) {
43
- return {
44
- ok: false,
45
- reason: `${label}.summary must be a non-empty string`,
46
- };
47
- }
48
-
49
- if (!contract.summaryStatusEnum.includes(summary.status)) {
50
- return {
51
- ok: false,
52
- reason: `${label}.status must be one of: ${contract.summaryStatusEnum.join(", ")}`,
53
- };
54
- }
55
-
56
- if (!isIsoUtcTimestamp(summary.verified_at)) {
57
- return {
58
- ok: false,
59
- reason: `${label}.verified_at must be an ISO-8601 UTC timestamp`,
60
- };
61
- }
62
-
63
- if (verifiedAt && summary.verified_at !== verifiedAt) {
64
- return {
65
- ok: false,
66
- reason: `${label}.verified_at must match the top-level verifiedAt`,
67
- };
68
- }
69
-
70
- return null;
71
- }
72
-
73
- export function validateSpecReconstructionSummary(summary, contract, verifiedAt) {
74
- const envelopeError = validateSummaryEnvelope(
75
- summary,
76
- contract,
77
- verifiedAt,
78
- "spec_reconstruction summary",
79
- );
80
- if (envelopeError) {
81
- return envelopeError;
82
- }
83
-
84
- if (
85
- !Array.isArray(summary.generated_paths)
86
- || summary.generated_paths.some((entry) => typeof entry !== "string")
87
- ) {
88
- return {
89
- ok: false,
90
- reason: "spec_reconstruction summary.generated_paths must be an array of strings",
91
- };
92
- }
93
-
94
- const expectedAuditRef = contract.canonicalTreeCompletion?.auditRef ?? SPEC_GENERATION_AUDIT_REF;
95
- if (typeof summary.audit_ref !== "string" || summary.audit_ref !== expectedAuditRef) {
96
- return {
97
- ok: false,
98
- reason: `spec_reconstruction summary.audit_ref must be \`${expectedAuditRef}\``,
99
- };
100
- }
101
-
102
- if (!isPlainObject(summary.coverage_summary)) {
103
- return {
104
- ok: false,
105
- reason: "spec_reconstruction summary.coverage_summary must be an object",
106
- };
107
- }
108
-
109
- const missingCoverageFields = validateRequiredFields(
110
- summary.coverage_summary,
111
- SPEC_RECONSTRUCTION_COVERAGE_SUMMARY_REQUIRED_FIELDS,
112
- "spec_reconstruction summary.coverage_summary",
113
- );
114
- if (missingCoverageFields) {
115
- return missingCoverageFields;
116
- }
117
-
118
- for (const field of SPEC_RECONSTRUCTION_COVERAGE_SUMMARY_REQUIRED_FIELDS) {
119
- if (!Number.isInteger(summary.coverage_summary[field]) || summary.coverage_summary[field] < 0) {
120
- return {
121
- ok: false,
122
- reason: `spec_reconstruction summary.coverage_summary.${field} must be a non-negative integer`,
123
- };
124
- }
125
- }
126
-
127
- if (!Number.isInteger(summary.unresolved_file_count) || summary.unresolved_file_count < 0) {
128
- return {
129
- ok: false,
130
- reason: "spec_reconstruction summary.unresolved_file_count must be a non-negative integer",
131
- };
132
- }
133
-
134
- if (!Number.isInteger(summary.inferred_file_count) || summary.inferred_file_count < 0) {
135
- return {
136
- ok: false,
137
- reason: "spec_reconstruction summary.inferred_file_count must be a non-negative integer",
138
- };
139
- }
140
-
141
- return { ok: true };
142
- }
143
-
144
- export function validateDocSpecAuditSummary(summary, contract, verifiedAt) {
145
- const envelopeError = validateSummaryEnvelope(summary, contract, verifiedAt, "doc_spec_audit summary");
146
- if (envelopeError) {
147
- return envelopeError;
148
- }
149
-
150
- if (
151
- !Array.isArray(summary.compared_paths)
152
- || summary.compared_paths.length === 0
153
- || summary.compared_paths.some((entry) => typeof entry !== "string")
154
- ) {
155
- return {
156
- ok: false,
157
- reason: "doc_spec_audit summary.compared_paths must be a non-empty array of strings",
158
- };
159
- }
160
-
161
- if (!Number.isInteger(summary.finding_count) || summary.finding_count < 0) {
162
- return {
163
- ok: false,
164
- reason: "doc_spec_audit summary.finding_count must be a non-negative integer",
165
- };
166
- }
167
-
168
- return { ok: true };
169
- }
170
-
171
- export function validateAuditSweepSummary(summary, contract, verifiedAt) {
172
- const envelopeError = validateSummaryEnvelope(summary, contract, verifiedAt, "audit_sweep summary");
173
- if (envelopeError) {
174
- return envelopeError;
175
- }
176
-
177
- const unexpectedFields = Object.keys(summary).filter(
178
- (field) => !contract.summaryRequiredFields.includes(field),
179
- );
180
- if (unexpectedFields.length > 0) {
181
- return {
182
- ok: false,
183
- reason: `audit_sweep summary contains unexpected fields: ${unexpectedFields.join(", ")}`,
184
- };
185
- }
186
-
187
- for (const field of [
188
- "plan_ref",
189
- "ledger_ref",
190
- "report_ref",
191
- "remediation_map_ref",
192
- "audit_closeout_ref",
193
- ]) {
194
- if (typeof summary[field] !== "string" || summary[field].trim().length === 0) {
195
- return {
196
- ok: false,
197
- reason: `audit_sweep summary.${field} must be a non-empty string`,
198
- };
199
- }
200
- }
201
-
202
- for (const field of ["chunk_refs", "evidence_refs"]) {
203
- if (
204
- !Array.isArray(summary[field])
205
- || summary[field].length === 0
206
- || summary[field].some((entry) => typeof entry !== "string" || entry.trim().length === 0)
207
- ) {
208
- return {
209
- ok: false,
210
- reason: `audit_sweep summary.${field} must be a non-empty array of non-empty strings`,
211
- };
212
- }
213
- }
214
-
215
- for (const field of ["finding_count", "unresolved_finding_count"]) {
216
- if (!Number.isInteger(summary[field]) || summary[field] < 0) {
217
- return {
218
- ok: false,
219
- reason: `audit_sweep summary.${field} must be a non-negative integer`,
220
- };
221
- }
222
- }
223
-
224
- if (typeof summary.coverage_scope !== "string" || summary.coverage_scope.trim().length === 0) {
225
- return {
226
- ok: false,
227
- reason: "audit_sweep summary.coverage_scope must be a non-empty string",
228
- };
229
- }
230
-
231
- for (const field of ["coverage_quality", "audit_validity"]) {
232
- if (!isPlainObject(summary[field])) {
233
- return {
234
- ok: false,
235
- reason: `audit_sweep summary.${field} must be an object`,
236
- };
237
- }
238
- }
239
-
240
- return { ok: true };
241
- }
242
-
243
- export function validateHighRiskExecutionSummary(summary, contract, verifiedAt) {
244
- const envelopeError = validateSummaryEnvelope(
245
- summary,
246
- contract,
247
- verifiedAt,
248
- "high_risk_execution summary",
249
- );
250
- if (envelopeError) {
251
- return envelopeError;
252
- }
253
-
254
- const unexpectedFields = Object.keys(summary).filter(
255
- (field) => !contract.summaryRequiredFields.includes(field),
256
- );
257
- if (unexpectedFields.length > 0) {
258
- return {
259
- ok: false,
260
- reason: `high_risk_execution summary contains unexpected fields: ${unexpectedFields.join(", ")}`,
261
- };
262
- }
263
-
264
- for (const field of [
265
- "packet_ref",
266
- "orchestration_state_ref",
267
- "prompt_ref",
268
- "worker_output_ref",
269
- ]) {
270
- if (typeof summary[field] !== "string" || summary[field].trim().length === 0) {
271
- return {
272
- ok: false,
273
- reason: `high_risk_execution summary.${field} must be a non-empty string`,
274
- };
275
- }
276
- }
277
-
278
- if (
279
- !Array.isArray(summary.evidence_refs)
280
- || summary.evidence_refs.length === 0
281
- || summary.evidence_refs.some((entry) => typeof entry !== "string" || entry.trim().length === 0)
282
- ) {
283
- return {
284
- ok: false,
285
- reason: "high_risk_execution summary.evidence_refs must be a non-empty array of non-empty strings",
286
- };
287
- }
288
-
289
- return { ok: true };
290
- }
291
-
292
- export function validateHighRiskAdmissionRecord(record, contract) {
293
- if (!isPlainObject(record)) {
294
- return {
295
- ok: false,
296
- reason: "high-risk admission record must be an object",
297
- };
298
- }
299
-
300
- const keys = Object.keys(record).sort();
301
- const expectedKeys = contract.admissionRequiredFields.slice().sort();
302
- if (!arraysEqual(keys, expectedKeys)) {
303
- return {
304
- ok: false,
305
- reason: `high-risk admission record must contain exactly these fields: ${contract.admissionRequiredFields.join(", ")}`,
306
- };
307
- }
308
-
309
- for (const field of [
310
- "topic_id",
311
- "packet_id",
312
- "manager_review_owner",
313
- "summary",
314
- "source_decision_contract",
315
- ]) {
316
- if (typeof record[field] !== "string" || record[field].trim().length === 0) {
317
- return {
318
- ok: false,
319
- reason: `high-risk admission record ${field} must be a non-empty string`,
320
- };
321
- }
322
- }
323
-
324
- if (!contract.dispositionEnum.includes(record.disposition)) {
325
- return {
326
- ok: false,
327
- reason: `high-risk admission record disposition must be one of: ${contract.dispositionEnum.join(", ")}`,
328
- };
329
- }
330
-
331
- if (!isIsoUtcTimestamp(record.admitted_at)) {
332
- return {
333
- ok: false,
334
- reason: "high-risk admission record admitted_at must be an ISO-8601 UTC timestamp",
335
- };
336
- }
337
-
338
- return { ok: true };
339
- }
340
-
341
- export function validateHighRiskAdmissionsSpec(spec, contract) {
342
- if (!isPlainObject(spec)) {
343
- return {
344
- ok: false,
345
- reason: "high-risk admissions spec must be an object",
346
- };
347
- }
348
-
349
- const missingKeys = contract.topLevelRequiredKeys.filter((key) => !(key in spec));
350
- if (missingKeys.length > 0) {
351
- return {
352
- ok: false,
353
- reason: `high-risk admissions spec is missing top-level keys: ${missingKeys.join(", ")}`,
354
- };
355
- }
356
-
357
- if (
358
- !Array.isArray(spec.admissions)
359
- || !Array.isArray(spec.admission_rules)
360
- || !Array.isArray(spec.semantic_constraints)
361
- ) {
362
- return {
363
- ok: false,
364
- reason: "high-risk admissions spec top-level sections must be arrays",
365
- };
366
- }
367
-
368
- if (
369
- spec.admission_rules.some((entry) => typeof entry !== "string")
370
- || spec.semantic_constraints.some((entry) => typeof entry !== "string")
371
- ) {
372
- return {
373
- ok: false,
374
- reason: "high-risk admissions spec rules and semantic constraints must be string arrays",
375
- };
376
- }
377
-
378
- const seenTopicIds = new Set();
379
- for (const record of spec.admissions) {
380
- const validation = validateHighRiskAdmissionRecord(record, contract);
381
- if (!validation.ok) {
382
- return validation;
383
- }
384
-
385
- if (seenTopicIds.has(record.topic_id)) {
386
- return {
387
- ok: false,
388
- reason: `high-risk admissions spec contains duplicate topic_id ${record.topic_id}`,
389
- };
390
- }
391
- seenTopicIds.add(record.topic_id);
392
- }
393
-
394
- return { ok: true };
395
- }
396
-
397
- export function makeInvalidHighRiskAdmissionContractReason() {
398
- return `${HIGH_RISK_ADMISSION_CONTRACT_REF} is missing or malformed`;
399
- }