@nimiplatform/nimi-coding 0.2.8 → 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 (205) hide show
  1. package/CHANGELOG.md +8 -92
  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/help.mjs +28 -145
  9. package/cli/index.mjs +5 -33
  10. package/cli/lib/blueprint-audit.mjs +5 -12
  11. package/cli/lib/bootstrap.mjs +0 -9
  12. package/cli/lib/contracts.mjs +0 -163
  13. package/cli/lib/doctor.mjs +155 -10
  14. package/cli/lib/entrypoints.mjs +63 -167
  15. package/cli/lib/internal/contracts-loaders.mjs +0 -85
  16. package/cli/lib/internal/contracts-parse.mjs +84 -520
  17. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +13 -8
  18. package/cli/lib/internal/surface-taxonomy-validators.mjs +316 -66
  19. package/cli/lib/internal/validators-shared.mjs +0 -16
  20. package/cli/lib/internal/validators-spec-helpers.mjs +7 -140
  21. package/cli/lib/internal/validators-spec.mjs +103 -342
  22. package/cli/lib/shared.mjs +1 -42
  23. package/cli/lib/validators.mjs +0 -48
  24. package/cli/seeds/seed-policy.yaml +0 -3
  25. package/config/bootstrap.yaml +4 -4
  26. package/config/spec-generation-inputs.yaml +6 -12
  27. package/contracts/domain-admission.schema.yaml +3 -3
  28. package/contracts/migration-inventory.schema.yaml +12 -75
  29. package/contracts/negative-fixtures.yaml +19 -99
  30. package/contracts/placement-contract.schema.yaml +49 -78
  31. package/contracts/projection-edge.schema.yaml +37 -121
  32. package/contracts/shared-enums.yaml +4 -8
  33. package/contracts/spec-generation-inputs.schema.yaml +15 -112
  34. package/contracts/spec-layout.schema.yaml +32 -0
  35. package/contracts/surface-taxonomy.schema.yaml +43 -94
  36. package/contracts/table-family.schema.yaml +1 -1
  37. package/contracts/tracked-output-admission.schema.yaml +13 -66
  38. package/methodology/core.yaml +33 -25
  39. package/methodology/four-closure-policy.yaml +18 -26
  40. package/methodology/role-separation-policy.yaml +21 -27
  41. package/methodology/spec-reconstruction.yaml +17 -34
  42. package/package.json +2 -4
  43. package/spec/_meta/spec-tree-model.yaml +5 -101
  44. package/spec/product-scope.yaml +25 -57
  45. package/adapters/README.md +0 -25
  46. package/adapters/claude/README.md +0 -89
  47. package/adapters/claude/profile.yaml +0 -70
  48. package/adapters/codex/README.md +0 -53
  49. package/adapters/codex/profile.yaml +0 -78
  50. package/adapters/oh-my-codex/README.md +0 -184
  51. package/adapters/oh-my-codex/profile.yaml +0 -46
  52. package/cli/commands/admit-high-risk-decision.mjs +0 -108
  53. package/cli/commands/audit-sweep.mjs +0 -364
  54. package/cli/commands/closeout.mjs +0 -186
  55. package/cli/commands/decide-high-risk-execution.mjs +0 -124
  56. package/cli/commands/handoff.mjs +0 -123
  57. package/cli/commands/ingest-high-risk-execution.mjs +0 -95
  58. package/cli/commands/review-high-risk-execution.mjs +0 -95
  59. package/cli/commands/sweep-design.mjs +0 -295
  60. package/cli/commands/sweep.mjs +0 -22
  61. package/cli/commands/topic-formatters.mjs +0 -382
  62. package/cli/commands/topic-goal.mjs +0 -33
  63. package/cli/commands/topic-options-shared.mjs +0 -27
  64. package/cli/commands/topic-options-workflow.mjs +0 -767
  65. package/cli/commands/topic-options.mjs +0 -626
  66. package/cli/commands/topic-runner.mjs +0 -169
  67. package/cli/commands/topic.mjs +0 -795
  68. package/cli/commands/validate-acceptance.mjs +0 -5
  69. package/cli/commands/validate-execution-packet.mjs +0 -5
  70. package/cli/commands/validate-orchestration-state.mjs +0 -5
  71. package/cli/commands/validate-prompt.mjs +0 -5
  72. package/cli/commands/validate-worker-output.mjs +0 -5
  73. package/cli/lib/adapter-profiles.mjs +0 -403
  74. package/cli/lib/audit-execution.mjs +0 -52
  75. package/cli/lib/audit-sweep-runtime/admissions.mjs +0 -508
  76. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +0 -356
  77. package/cli/lib/audit-sweep-runtime/chunks.mjs +0 -697
  78. package/cli/lib/audit-sweep-runtime/claude-auditor.mjs +0 -658
  79. package/cli/lib/audit-sweep-runtime/closeout.mjs +0 -144
  80. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +0 -654
  81. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +0 -527
  82. package/cli/lib/audit-sweep-runtime/common.mjs +0 -341
  83. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +0 -172
  84. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +0 -155
  85. package/cli/lib/audit-sweep-runtime/format.mjs +0 -57
  86. package/cli/lib/audit-sweep-runtime/ingest.mjs +0 -486
  87. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +0 -425
  88. package/cli/lib/audit-sweep-runtime/inventory.mjs +0 -798
  89. package/cli/lib/audit-sweep-runtime/ledger.mjs +0 -315
  90. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +0 -101
  91. package/cli/lib/audit-sweep-runtime/remediation.mjs +0 -349
  92. package/cli/lib/audit-sweep-runtime/rerun.mjs +0 -129
  93. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +0 -300
  94. package/cli/lib/audit-sweep-runtime/status.mjs +0 -62
  95. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +0 -215
  96. package/cli/lib/audit-sweep-runtime/validators.mjs +0 -797
  97. package/cli/lib/audit-sweep.mjs +0 -19
  98. package/cli/lib/authority-convergence.mjs +0 -720
  99. package/cli/lib/closeout.mjs +0 -732
  100. package/cli/lib/codex-sdk-runner.mjs +0 -76
  101. package/cli/lib/external-execution.mjs +0 -101
  102. package/cli/lib/handoff.mjs +0 -812
  103. package/cli/lib/high-risk-admission.mjs +0 -512
  104. package/cli/lib/high-risk-decision.mjs +0 -353
  105. package/cli/lib/high-risk-ingest.mjs +0 -321
  106. package/cli/lib/high-risk-review.mjs +0 -267
  107. package/cli/lib/internal/contracts-parse-high-risk.mjs +0 -131
  108. package/cli/lib/internal/contracts-validators.mjs +0 -399
  109. package/cli/lib/internal/doctor-bootstrap-surface.mjs +0 -406
  110. package/cli/lib/internal/doctor-delegated-surface.mjs +0 -256
  111. package/cli/lib/internal/doctor-finalize.mjs +0 -383
  112. package/cli/lib/internal/doctor-format.mjs +0 -286
  113. package/cli/lib/internal/doctor-inspectors.mjs +0 -327
  114. package/cli/lib/internal/doctor-state.mjs +0 -205
  115. package/cli/lib/internal/validators-artifacts.mjs +0 -515
  116. package/cli/lib/sweep-design-runtime/common.mjs +0 -246
  117. package/cli/lib/sweep-design-runtime/engine.mjs +0 -733
  118. package/cli/lib/sweep-design-runtime/fix-topic.mjs +0 -414
  119. package/cli/lib/sweep-design-runtime/lifecycle.mjs +0 -54
  120. package/cli/lib/sweep-design-runtime/results.mjs +0 -324
  121. package/cli/lib/sweep-design.mjs +0 -8
  122. package/cli/lib/topic-artifacts.mjs +0 -186
  123. package/cli/lib/topic-authority-coverage.mjs +0 -73
  124. package/cli/lib/topic-closeout.mjs +0 -560
  125. package/cli/lib/topic-common.mjs +0 -404
  126. package/cli/lib/topic-decisions.mjs +0 -332
  127. package/cli/lib/topic-draft-packets.mjs +0 -167
  128. package/cli/lib/topic-execution.mjs +0 -533
  129. package/cli/lib/topic-goal.mjs +0 -440
  130. package/cli/lib/topic-ledger.mjs +0 -281
  131. package/cli/lib/topic-lifecycle-artifacts.mjs +0 -173
  132. package/cli/lib/topic-root-validation.mjs +0 -288
  133. package/cli/lib/topic-runner-commands.mjs +0 -174
  134. package/cli/lib/topic-runner-deferral.mjs +0 -532
  135. package/cli/lib/topic-runner-stale-gates.mjs +0 -114
  136. package/cli/lib/topic-runner-validation.mjs +0 -138
  137. package/cli/lib/topic-runner.mjs +0 -727
  138. package/cli/lib/topic-scaffold.mjs +0 -252
  139. package/cli/lib/topic-waves.mjs +0 -403
  140. package/cli/lib/topic.mjs +0 -81
  141. package/config/audit-execution-artifacts.yaml +0 -20
  142. package/config/external-execution-artifacts.yaml +0 -16
  143. package/config/host-adapter.yaml +0 -30
  144. package/config/host-profile.yaml +0 -29
  145. package/config/installer-evidence.yaml +0 -31
  146. package/config/skill-installer.yaml +0 -23
  147. package/config/skill-manifest.yaml +0 -48
  148. package/config/skills.yaml +0 -30
  149. package/contracts/acceptance.schema.yaml +0 -16
  150. package/contracts/admission-checklist.schema.yaml +0 -15
  151. package/contracts/audit-chunk.schema.yaml +0 -123
  152. package/contracts/audit-closeout.schema.yaml +0 -51
  153. package/contracts/audit-finding.schema.yaml +0 -61
  154. package/contracts/audit-ledger.schema.yaml +0 -138
  155. package/contracts/audit-plan.schema.yaml +0 -138
  156. package/contracts/audit-remediation-map.schema.yaml +0 -52
  157. package/contracts/audit-rerun.schema.yaml +0 -31
  158. package/contracts/audit-sweep-result.yaml +0 -53
  159. package/contracts/authority-convergence-audit.schema.yaml +0 -19
  160. package/contracts/closeout.schema.yaml +0 -25
  161. package/contracts/decision-review.schema.yaml +0 -16
  162. package/contracts/doc-spec-audit-result.yaml +0 -19
  163. package/contracts/execution-packet.schema.yaml +0 -49
  164. package/contracts/external-host-compatibility.yaml +0 -22
  165. package/contracts/forbidden-shortcuts.catalog.yaml +0 -23
  166. package/contracts/high-risk-admission.schema.yaml +0 -23
  167. package/contracts/high-risk-execution-result.yaml +0 -20
  168. package/contracts/orchestration-state.schema.yaml +0 -41
  169. package/contracts/overflow-continuation.schema.yaml +0 -12
  170. package/contracts/packet.schema.yaml +0 -30
  171. package/contracts/pending-note.schema.yaml +0 -17
  172. package/contracts/prompt.schema.yaml +0 -12
  173. package/contracts/remediation.schema.yaml +0 -16
  174. package/contracts/result.schema.yaml +0 -24
  175. package/contracts/spec-reconstruction-result.yaml +0 -41
  176. package/contracts/sweep-design-result.yaml +0 -349
  177. package/contracts/topic-goal.schema.yaml +0 -87
  178. package/contracts/topic-run-ledger.schema.yaml +0 -72
  179. package/contracts/topic-step-decision.schema.yaml +0 -45
  180. package/contracts/topic.schema.yaml +0 -65
  181. package/contracts/true-close.schema.yaml +0 -15
  182. package/contracts/wave.schema.yaml +0 -29
  183. package/contracts/worker-output.schema.yaml +0 -15
  184. package/contracts/workflow-consumer.schema.yaml +0 -110
  185. package/methodology/audit-sweep-p0p1-recall.yaml +0 -45
  186. package/methodology/authority-convergence-policy.yaml +0 -42
  187. package/methodology/overflow-continuation-policy.yaml +0 -14
  188. package/methodology/skill-exchange-projection.yaml +0 -114
  189. package/methodology/skill-handoff.yaml +0 -34
  190. package/methodology/skill-installer-result.yaml +0 -27
  191. package/methodology/skill-installer-summary-projection.yaml +0 -181
  192. package/methodology/skill-runtime.yaml +0 -23
  193. package/methodology/spec-target-truth-profile.yaml +0 -46
  194. package/methodology/topic-lifecycle-report.yaml +0 -144
  195. package/methodology/topic-lifecycle.yaml +0 -37
  196. package/methodology/topic-naming-ontology.yaml +0 -21
  197. package/methodology/topic-ontology.yaml +0 -38
  198. package/methodology/topic-validation-policy.yaml +0 -9
  199. package/methodology/wave-dag-policy.yaml +0 -14
  200. package/spec/_meta/command-gating-matrix.yaml +0 -143
  201. package/spec/_meta/generate-drift-migration-checklist.yaml +0 -137
  202. package/spec/_meta/governance-routing-cutover-checklist.yaml +0 -35
  203. package/spec/_meta/phase2-impacted-surface-matrix.yaml +0 -44
  204. package/spec/_meta/spec-authority-cutover-readiness.yaml +0 -102
  205. package/spec/bootstrap-state.yaml +0 -99
@@ -1,324 +0,0 @@
1
- import path from "node:path";
2
-
3
- import {
4
- assertDesignArtifact,
5
- FINAL_OUTCOME_STATES,
6
- inputError,
7
- loadYamlRef,
8
- nowIso,
9
- requireRunId,
10
- safeDesignId,
11
- TRANSIENT_STATES,
12
- writeYamlRef,
13
- } from "./common.mjs";
14
- import {
15
- decisionQueueRef,
16
- finalOutcomeState,
17
- finalStateReportRef,
18
- isLlmAuditorResult,
19
- isSyntheticAuditorResult,
20
- ledgerRef,
21
- loadInventory,
22
- loadOrCreateLedger,
23
- normalizeRevisionEntry,
24
- packetRef,
25
- resultRef,
26
- stopClassForResult,
27
- updateLedgerHashes,
28
- validateAuditorResult,
29
- validateLedger,
30
- validateOutcome,
31
- validatePacket,
32
- validateWave,
33
- wavePlanRef,
34
- } from "./engine.mjs";
35
-
36
- export async function runResultIngest(projectRoot, options) {
37
- const run = requireRunId(options);
38
- if (!run.ok) return run;
39
- if (!options.from) return inputError("nimicoding sweep design refused: result-ingest requires --from.\n");
40
- const result = await loadYamlRef(projectRoot, options.from) ?? await import("node:fs/promises").then(async ({ readFile }) => {
41
- const YAML = await import("yaml");
42
- return YAML.parse(await readFile(path.resolve(projectRoot, options.from), "utf8"));
43
- }).catch(() => null);
44
- const errors = validateAuditorResult(result);
45
- if (errors.length > 0) return inputError(`nimicoding sweep design refused: ${errors.join("; ")}.\n`);
46
- if (isSyntheticAuditorResult(result) && options.allowSyntheticTrial !== true) {
47
- return inputError("nimicoding sweep design refused: synthetic_trial results require --allow-synthetic-trial and do not satisfy true LLM closeout.\n");
48
- }
49
- if (!safeDesignId(result.packet_id)) return inputError("nimicoding sweep design refused: result packet_id must be a stable id.\n");
50
- if (!safeDesignId(result.result_id)) return inputError("nimicoding sweep design refused: result_id must be a stable id.\n");
51
- if (result.run_id !== run.runId) return inputError("nimicoding sweep design refused: result run_id does not match --run-id.\n");
52
- const packet = await assertDesignArtifact(projectRoot, packetRef(run.runId, result.packet_id), "sweep-design-design-auditor-packet", "design auditor packet");
53
- if (!packet.ok) return packet;
54
- if (result.packet_ref !== packet.ref) return inputError("nimicoding sweep design refused: result packet_ref does not match canonical packet artifact.\n");
55
- const packetErrors = validatePacket(packet.value);
56
- if (packetErrors.length > 0) return inputError(`nimicoding sweep design refused: ${packetErrors.join("; ")}.\n`);
57
- const timestamp = options.verifiedAt ?? nowIso();
58
- const ledger = await loadOrCreateLedger(projectRoot, run.runId, timestamp);
59
- if (!ledger.ok) return ledger;
60
- const previousSnapshotHash = ledger.value.ledger_snapshot_hash;
61
- const normalizedRevisionEntries = [];
62
- const revisionErrors = [];
63
- const context = {
64
- ledger: ledger.value,
65
- normalized: normalizedRevisionEntries,
66
- errors: revisionErrors,
67
- resultId: result.result_id,
68
- resultArtifactRef: resultRef(run.runId, result.result_id),
69
- timestamp,
70
- auditorProvenance: {
71
- auditor: result.auditor,
72
- auditor_family: result.auditor_family,
73
- auditor_mode: result.auditor_mode,
74
- auditor_result_origin: result.auditor_result_origin,
75
- session_ref: result.session_ref,
76
- transcript_ref: result.transcript_ref,
77
- llm_session_ref: result.llm_session_ref ?? null,
78
- llm_transcript_ref: result.llm_transcript_ref ?? null,
79
- llm_prompt_ref: result.llm_prompt_ref ?? null,
80
- packet_ref: result.packet_ref,
81
- result_ref: resultRef(run.runId, result.result_id),
82
- },
83
- };
84
- for (const entry of result.revision_entries) {
85
- normalizedRevisionEntries.push(normalizeRevisionEntry(entry, context));
86
- }
87
- if (revisionErrors.length > 0) return inputError(`nimicoding sweep design refused: ${revisionErrors.join("; ")}.\n`);
88
- const outcomeErrors = [];
89
- for (const outcome of result.finding_outcomes) {
90
- validateOutcome(outcome, { errors: outcomeErrors });
91
- }
92
- const includedFindingIds = new Set(packet.value.included_finding_ids);
93
- const outcomeFindingIds = result.finding_outcomes.map((outcome) => outcome.finding_id);
94
- const uniqueOutcomeFindingIds = new Set(outcomeFindingIds);
95
- if (uniqueOutcomeFindingIds.size !== outcomeFindingIds.length) {
96
- outcomeErrors.push("finding_outcomes[] contains duplicate finding_id entries");
97
- }
98
- const missingOutcomeIds = packet.value.included_finding_ids.filter((findingId) => !uniqueOutcomeFindingIds.has(findingId));
99
- if (missingOutcomeIds.length > 0) {
100
- outcomeErrors.push(`design auditor result is missing final outcomes for included findings: ${missingOutcomeIds.join(", ")}`);
101
- }
102
- const outOfPacketOutcomeIds = outcomeFindingIds.filter((findingId) => !includedFindingIds.has(findingId));
103
- if (outOfPacketOutcomeIds.length > 0) {
104
- outcomeErrors.push(`design auditor result includes outcomes outside the packet: ${[...new Set(outOfPacketOutcomeIds)].join(", ")}`);
105
- }
106
- const normalizedRevisionRefs = new Set(normalizedRevisionEntries.map((entry) => `${ledger.ref}#${entry.revision_entry_id}`));
107
- for (const outcome of result.finding_outcomes) {
108
- for (const ref of outcome.revision_ledger_entry_refs ?? []) {
109
- if (!normalizedRevisionRefs.has(ref)) {
110
- outcomeErrors.push(`finding_outcomes[] revision_ledger_entry_refs must reference revision entries from this ingest: ${ref}`);
111
- }
112
- }
113
- }
114
- if (outcomeErrors.length > 0) return inputError(`nimicoding sweep design refused: ${outcomeErrors.join("; ")}.\n`);
115
- const storedResult = {
116
- ...result,
117
- closeout_eligible: isLlmAuditorResult(result),
118
- ingested_at: timestamp,
119
- normalized_revision_entry_refs: normalizedRevisionEntries.map((entry) => `${ledger.ref}#${entry.revision_entry_id}`),
120
- };
121
- const storedResultRef = await writeYamlRef(projectRoot, resultRef(run.runId, result.result_id), storedResult);
122
- ledger.value.entries.push(...normalizedRevisionEntries);
123
- updateLedgerHashes(ledger.value, previousSnapshotHash, timestamp);
124
- await writeYamlRef(projectRoot, ledger.ref, ledger.value);
125
- const decisionItems = result.finding_outcomes
126
- .filter((outcome) => finalOutcomeState(outcome) === "needs_user_decision")
127
- .map((outcome) => ({
128
- decision_queue_item_ref: outcome.decision_queue_item_ref,
129
- finding_id: outcome.finding_id,
130
- decision_packet_ref: outcome.decision_packet_ref,
131
- recommended_decision: outcome.recommended_decision,
132
- queue_status: outcome.queue_status,
133
- blocked_downstream_wave_refs: outcome.blocked_downstream_wave_refs,
134
- }));
135
- if (decisionItems.length > 0 || result.human_decision_requests.length > 0) {
136
- await writeYamlRef(projectRoot, decisionQueueRef(run.runId), {
137
- version: 2,
138
- kind: "sweep-design-decision-queue",
139
- run_id: run.runId,
140
- source_design_auditor_result_ref: storedResultRef,
141
- queue_policy: "focused_mode_stops_immediately_all_mode_batches_until_audit_complete",
142
- original_findings_mutation_policy: "read_only_never_update_from_sweep_design",
143
- pending_decision_count: decisionItems.length + result.human_decision_requests.length,
144
- items: decisionItems,
145
- human_decision_requests: result.human_decision_requests,
146
- created_at: timestamp,
147
- });
148
- }
149
- const stopClass = stopClassForResult(result);
150
- const mode = options.mode ?? result.auditor_mode;
151
- const focusedStop = mode === "focused" && stopClass;
152
- return {
153
- ok: true,
154
- exitCode: focusedStop ? 2 : 0,
155
- runId: run.runId,
156
- resultRef: storedResultRef,
157
- ledgerRef: ledger.ref,
158
- revisionEntryCount: normalizedRevisionEntries.length,
159
- findingOutcomeCount: result.finding_outcomes.length,
160
- closeoutEligible: isLlmAuditorResult(result),
161
- stopped: Boolean(focusedStop),
162
- stopClass: focusedStop ? stopClass : null,
163
- stopReason: focusedStop ? "focused_mode_requires_manager_or_human_resolution" : null,
164
- };
165
- }
166
-
167
- export async function runLedgerValidate(projectRoot, options) {
168
- const run = requireRunId(options);
169
- if (!run.ok) return run;
170
- const ledger = await assertDesignArtifact(projectRoot, ledgerRef(run.runId), "sweep-design-revision-ledger", "revision ledger");
171
- if (!ledger.ok) return ledger;
172
- const errors = validateLedger(ledger.value);
173
- if (errors.length > 0) return inputError(`nimicoding sweep design refused: ${errors.join("; ")}.\n`);
174
- return {
175
- ok: true,
176
- exitCode: 0,
177
- runId: run.runId,
178
- ledgerRef: ledger.ref,
179
- revisionEntryCount: ledger.value.entries.length,
180
- ledgerSnapshotHash: ledger.value.ledger_snapshot_hash,
181
- };
182
- }
183
-
184
- export async function runFinalize(projectRoot, options) {
185
- const run = requireRunId(options);
186
- if (!run.ok) return run;
187
- const inventory = await loadInventory(projectRoot, run.runId);
188
- if (!inventory.ok) return inventory;
189
- const ledger = await assertDesignArtifact(projectRoot, ledgerRef(run.runId), "sweep-design-revision-ledger", "revision ledger");
190
- if (!ledger.ok) return ledger;
191
- const ledgerErrors = validateLedger(ledger.value);
192
- if (ledgerErrors.length > 0) return inputError(`nimicoding sweep design refused: ${ledgerErrors.join("; ")}.\n`);
193
- const outcomes = new Map();
194
- const resultRefs = new Set();
195
- const nonLlmResultRefs = [];
196
- for (const entry of ledger.value.entries) {
197
- for (const ref of entry.replacement_artifact_refs ?? []) {
198
- if (ref.includes("/design-auditor-results/")) resultRefs.add(ref);
199
- }
200
- }
201
- for (const ref of resultRefs) {
202
- const result = await loadYamlRef(projectRoot, ref);
203
- if (result?.kind !== "sweep-design-design-auditor-result") continue;
204
- if (!isLlmAuditorResult(result)) nonLlmResultRefs.push(ref);
205
- for (const outcome of result.finding_outcomes ?? []) {
206
- outcomes.set(outcome.finding_id, { ...outcome, source_result_ref: ref });
207
- }
208
- }
209
- const findings = inventory.value.findings.map((finding) => {
210
- const outcome = outcomes.get(finding.finding_id);
211
- if (!outcome) {
212
- return {
213
- finding_id: finding.finding_id,
214
- state: "raw",
215
- final_outcome: false,
216
- transient: true,
217
- reason: "missing_design_auditor_final_outcome",
218
- };
219
- }
220
- const state = finalOutcomeState(outcome);
221
- return {
222
- finding_id: finding.finding_id,
223
- state,
224
- final_outcome: FINAL_OUTCOME_STATES.has(state),
225
- transient: TRANSIENT_STATES.has(state),
226
- source_result_ref: outcome.source_result_ref,
227
- design_auditor_packet_ref: outcome.design_auditor_packet_ref,
228
- revision_ledger_entry_refs: outcome.revision_ledger_entry_refs,
229
- };
230
- });
231
- const transient = findings.filter((finding) => finding.transient || !finding.final_outcome);
232
- const finalOutcomeComplete = transient.length === 0;
233
- const llmCloseoutEligible = nonLlmResultRefs.length === 0;
234
- const complete = finalOutcomeComplete && (llmCloseoutEligible || options.allowSyntheticCloseout === true);
235
- const artifact = {
236
- version: 2,
237
- kind: "sweep-design-final-state-report",
238
- run_id: run.runId,
239
- source_inventory_ref: inventory.ref,
240
- source_revision_ledger_ref: ledger.ref,
241
- final_state_policy: "every_finding_must_have_final_sweep_design_outcome_with_llm_packet_result_ledger_provenance",
242
- source_findings_mutation_policy: "read_only_never_update_from_sweep_design",
243
- complete,
244
- final_outcome_complete: finalOutcomeComplete,
245
- llm_closeout_eligible: llmCloseoutEligible,
246
- non_llm_result_refs: nonLlmResultRefs,
247
- total_finding_count: findings.length,
248
- final_finding_count: findings.length - transient.length,
249
- transient_finding_count: transient.length,
250
- final_outcome_states: [...FINAL_OUTCOME_STATES].sort(),
251
- transient_states: [...TRANSIENT_STATES].sort(),
252
- blocking_findings: transient.map((finding) => ({
253
- finding_id: finding.finding_id,
254
- state: finding.state,
255
- reason: finding.reason ?? "transient_or_missing_final_outcome",
256
- })),
257
- findings,
258
- created_at: options.verifiedAt ?? nowIso(),
259
- };
260
- const ref = await writeYamlRef(projectRoot, finalStateReportRef(run.runId), artifact);
261
- return {
262
- ok: true,
263
- exitCode: complete ? 0 : 2,
264
- runId: run.runId,
265
- finalStateReportRef: ref,
266
- finalComplete: complete,
267
- finalOutcomeComplete,
268
- llmCloseoutEligible,
269
- nonLlmResultCount: nonLlmResultRefs.length,
270
- totalFindingCount: artifact.total_finding_count,
271
- finalFindingCount: artifact.final_finding_count,
272
- transientFindingCount: artifact.transient_finding_count,
273
- stopped: !complete,
274
- stopClass: complete ? null : finalOutcomeComplete ? "non_llm_result_provenance" : "incomplete_final_state",
275
- stopReason: complete ? null : finalOutcomeComplete ? "synthetic_or_non_llm_results_do_not_satisfy_true_llm_closeout" : "missing_or_transient_final_outcomes_remaining",
276
- };
277
- }
278
-
279
- export async function runWavePlan(projectRoot, options) {
280
- const run = requireRunId(options);
281
- if (!run.ok) return run;
282
- if (!options.topicId) return inputError("nimicoding sweep design refused: --topic-id is required.\n");
283
- const ledger = await assertDesignArtifact(projectRoot, ledgerRef(run.runId), "sweep-design-revision-ledger", "revision ledger");
284
- if (!ledger.ok) return ledger;
285
- const ledgerErrors = validateLedger(ledger.value);
286
- if (ledgerErrors.length > 0) return inputError(`nimicoding sweep design refused: ${ledgerErrors.join("; ")}.\n`);
287
- const waves = [];
288
- const errors = [];
289
- const resultRefs = new Set();
290
- for (const entry of ledger.value.entries) {
291
- for (const ref of entry.replacement_artifact_refs ?? []) {
292
- if (ref.includes("/design-auditor-results/")) resultRefs.add(ref);
293
- }
294
- }
295
- for (const ref of resultRefs) {
296
- const result = await loadYamlRef(projectRoot, ref);
297
- if (result?.kind !== "sweep-design-design-auditor-result") continue;
298
- if (!isLlmAuditorResult(result) && options.allowSyntheticTrial !== true) {
299
- errors.push(`wave-plan result ${ref} is not closeout-eligible LLM provenance; pass --allow-synthetic-trial only for load tests`);
300
- continue;
301
- }
302
- for (const wave of result.wave_changes ?? []) {
303
- if (wave.state === "ready_for_implementation" || wave.ready_for_implementation_wave === true) {
304
- validateWave(wave, errors);
305
- waves.push({ ...wave, source_design_auditor_result_ref: ref });
306
- }
307
- }
308
- }
309
- if (errors.length > 0) return inputError(`nimicoding sweep design refused: ${errors.join("; ")}.\n`);
310
- const artifact = {
311
- version: 2,
312
- kind: "sweep-design-wave-plan",
313
- run_id: run.runId,
314
- topic_id: options.topicId,
315
- source_revision_ledger_ref: ledger.ref,
316
- mutates_topic_state: false,
317
- worker_dispatch_allowed: false,
318
- wave_count: waves.length,
319
- waves,
320
- created_at: options.verifiedAt ?? nowIso(),
321
- };
322
- const ref = await writeYamlRef(projectRoot, wavePlanRef(run.runId), artifact);
323
- return { ok: true, exitCode: 0, runId: run.runId, wavePlanRef: ref, waveCount: waves.length };
324
- }
@@ -1,8 +0,0 @@
1
- export {
2
- runAuditorPrompt,
3
- runIntake,
4
- runPacketBuild,
5
- runPacketBuildBatch,
6
- } from "./sweep-design-runtime/engine.mjs";
7
- export { runFixTopic } from "./sweep-design-runtime/fix-topic.mjs";
8
- export { runFinalize, runLedgerValidate, runResultIngest, runWavePlan } from "./sweep-design-runtime/results.mjs";
@@ -1,186 +0,0 @@
1
- import { readdir, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import YAML from "yaml";
4
-
5
- import { readTextIfFile } from "./fs-helpers.mjs";
6
- import { packetAuthorityCoverage, packetAuthorityCoverageError } from "./topic-authority-coverage.mjs";
7
- import { isRecognizedLifecycleArtifactName } from "./topic-lifecycle-artifacts.mjs";
8
- import { parseYamlText } from "./yaml-helpers.mjs";
9
- import { loadTopicRuntimeAuthority, toPortableRelativePath } from "./topic-common.mjs";
10
- import { getTopicWaves, loadTopicReport, topicHasEnrichedShape } from "./topic-scaffold.mjs";
11
-
12
- export function readFrontmatterObject(text) {
13
- const parsed = parsePacketDraft(text);
14
- return parsed && typeof parsed == "object" ? parsed : null;
15
- }
16
- export function parsePacketDraft(text) {
17
- if (!text) return null;
18
- if (
19
- text.startsWith(`---
20
- `)
21
- ) {
22
- const closing = text.indexOf(
23
- `
24
- ---
25
- `,
26
- 4,
27
- );
28
- if (closing !== -1) {
29
- const frontmatter = text.slice(4, closing);
30
- return parseYamlText(frontmatter);
31
- }
32
- }
33
- return parseYamlText(text);
34
- }
35
- export function packetFilenameFromId(packetId) {
36
- return `packet-${packetId}.md`;
37
- }
38
- export function resultFilename(waveId, slug, resultKind) {
39
- return `result-${waveId}-${resultKind}.md`;
40
- }
41
- export function decisionReviewFilename(slug) {
42
- return `decision-review-${slug}.md`;
43
- }
44
- export function remediationFilename(waveId, kind, reason) {
45
- return `packet-${waveId}-remediation-${kind}-${reason}.md`;
46
- }
47
- export function overflowContinuationFilename(waveId, continuationPacketId) {
48
- return `overflow-continuation-${waveId}-${continuationPacketId}.md`;
49
- }
50
- export function waveCloseoutFilename(waveId) {
51
- return `closeout-${waveId}.md`;
52
- }
53
- export function topicCloseoutFilename() {
54
- return "closeout-topic.md";
55
- }
56
- export function topicTrueCloseAuditFilename() {
57
- return "topic-true-close-audit.md";
58
- }
59
- export function topicTrueCloseJudgementFilename() {
60
- return "result-topic-true-close-audit.md";
61
- }
62
- export function topicTrueCloseRecordFilename() {
63
- return "result-topic-true-close.md";
64
- }
65
- export function pendingNoteFilename() {
66
- return "pending-note.md";
67
- }
68
- export function pendingNoteMarkdown(note) {
69
- return `---
70
- ${YAML.stringify(note).trimEnd()}
71
- ---
72
-
73
- # Pending Note
74
-
75
- Recorded by \`nimicoding topic hold\`.
76
- `;
77
- }
78
- export function packetMarkdown(packet) {
79
- return `---
80
- ${YAML.stringify(packet).trimEnd()}
81
- ---
82
-
83
- # Packet ${packet.packet_id}
84
-
85
- Frozen by \`nimicoding topic packet freeze\`.
86
- `;
87
- }
88
- export async function freezePacketForTopic(projectRoot, input, draftPath) {
89
- const loaded = await loadTopicReport(projectRoot, input);
90
- if (!loaded.ok) return loaded;
91
- const authority = await loadTopicRuntimeAuthority(projectRoot);
92
- if (!topicHasEnrichedShape(loaded.topic, authority))
93
- return { ok: false, error: "Packet freeze requires an enriched topic root." };
94
- const draftText = await readTextIfFile(path.resolve(projectRoot, draftPath));
95
- if (draftText === null) return { ok: false, error: `Draft packet not found: ${draftPath}` };
96
- const packet = parsePacketDraft(draftText);
97
- if (!packet || typeof packet != "object")
98
- return { ok: false, error: `Draft packet is not valid YAML/frontmatter: ${draftPath}` };
99
- const missingFields = authority.packetRequiredFields.filter((field) => {
100
- const value = packet[field];
101
- return value == null || value === "" || (Array.isArray(value) && value.length === 0);
102
- });
103
- if (missingFields.length > 0)
104
- return {
105
- ok: false,
106
- error: `Draft packet is missing required fields: ${missingFields.join(", ")}`,
107
- };
108
- if (packet.topic_id !== loaded.topicId)
109
- return {
110
- ok: false,
111
- error: `Draft packet topic_id does not match topic (${packet.topic_id} vs ${loaded.topicId})`,
112
- };
113
- if (!getTopicWaves(loaded.topic).find((entry) => entry.wave_id === packet.wave_id))
114
- return {
115
- ok: false,
116
- error: `Draft packet wave_id does not resolve inside the topic: ${packet.wave_id}`,
117
- };
118
- const wave = getTopicWaves(loaded.topic).find((entry) => entry.wave_id === packet.wave_id);
119
- const coverage = packetAuthorityCoverage(packet, wave);
120
- if (!coverage.ok)
121
- return {
122
- ok: false,
123
- error: packetAuthorityCoverageError(coverage),
124
- missingAuthorityOwnerRefs: coverage.missingAuthorityOwnerRefs,
125
- missingCanonicalSeamRefs: coverage.missingCanonicalSeamRefs,
126
- };
127
- if (!authority.packetFreezeAllowedStatuses.includes(packet.status))
128
- return { ok: false, error: `Draft packet status is not freezeable: ${packet.status}` };
129
- const packetFileName = packetFilenameFromId(packet.packet_id);
130
- if (!isRecognizedLifecycleArtifactName(packetFileName))
131
- return {
132
- ok: false,
133
- error: `Draft packet packet_id would create an ambiguous lifecycle artifact name: ${packetFileName}. Use a wave-prefixed packet id such as ${packet.wave_id}-${packet.packet_id}.`,
134
- };
135
- packet.status = "candidate";
136
- const packetPath = path.join(loaded.topicDir, packetFileName);
137
- return (
138
- await writeFile(packetPath, packetMarkdown(packet), "utf8"),
139
- {
140
- ok: true,
141
- topicId: loaded.topicId,
142
- topicRef: toPortableRelativePath(path.relative(projectRoot, loaded.topicDir)),
143
- packetId: packet.packet_id,
144
- packetRef: toPortableRelativePath(path.relative(projectRoot, packetPath)),
145
- waveId: packet.wave_id,
146
- status: packet.status,
147
- }
148
- );
149
- }
150
- export async function loadTopicPacket(projectRoot, input, packetId) {
151
- const loaded = await loadTopicReport(projectRoot, input);
152
- if (!loaded.ok) return loaded;
153
- const packetPath = path.join(loaded.topicDir, packetFilenameFromId(packetId)),
154
- packetText = await readTextIfFile(packetPath);
155
- if (packetText === null) return { ok: false, error: `Packet not found: ${packetId}` };
156
- const packet = parsePacketDraft(packetText);
157
- return !packet || typeof packet != "object"
158
- ? { ok: false, error: `Packet is not valid YAML/frontmatter: ${packetId}` }
159
- : { ok: true, ...loaded, packetPath, packet };
160
- }
161
- export async function listWavePackets(topicDir, waveId) {
162
- const entries = await readdir(topicDir, { withFileTypes: true }),
163
- packets = [];
164
- for (const entry of entries) {
165
- if (!entry.isFile() || !entry.name.startsWith("packet-") || !entry.name.endsWith(".md"))
166
- continue;
167
- const packetPath = path.join(topicDir, entry.name),
168
- packetText = await readTextIfFile(packetPath),
169
- packet = readFrontmatterObject(packetText ?? "");
170
- packet?.wave_id === waveId && packets.push({ packet, packetPath, packetRefName: entry.name });
171
- }
172
- return packets.sort((left, right) => left.packetRefName.localeCompare(right.packetRefName));
173
- }
174
- export async function listWaveResults(topicDir, waveId) {
175
- const entries = await readdir(topicDir, { withFileTypes: true }),
176
- results = [];
177
- for (const entry of entries) {
178
- if (!entry.isFile() || !entry.name.startsWith("result-") || !entry.name.endsWith(".md"))
179
- continue;
180
- const resultPath = path.join(topicDir, entry.name),
181
- resultText = await readTextIfFile(resultPath),
182
- result = readFrontmatterObject(resultText ?? "");
183
- result?.wave_id === waveId && results.push({ result, resultPath, resultRefName: entry.name });
184
- }
185
- return results.sort((left, right) => left.resultRefName.localeCompare(right.resultRefName));
186
- }
@@ -1,73 +0,0 @@
1
- function stringArray(value) {
2
- if (typeof value === "string" && value.trim()) return [value.trim()];
3
- if (!Array.isArray(value)) return [];
4
- return value
5
- .filter((entry) => typeof entry === "string")
6
- .map((entry) => entry.trim())
7
- .filter(Boolean);
8
- }
9
-
10
- function isAuthorityRef(value) {
11
- const ref = String(value ?? "").trim();
12
- if (!ref) return false;
13
- return (
14
- ref.startsWith(".nimi/spec/")
15
- || ref.startsWith("apps/") && ref.includes("/spec/")
16
- || ref.startsWith("package://@nimiplatform/nimi-coding/spec/")
17
- || ref.startsWith("package://@nimiplatform/nimi-coding/contracts/")
18
- || ref.startsWith("package://@nimiplatform/nimi-coding/methodology/")
19
- || ref.startsWith("package://@nimiplatform/nimi-coding/config/")
20
- );
21
- }
22
-
23
- function unique(values) {
24
- return [...new Set(values.filter(Boolean))];
25
- }
26
-
27
- export function sourceSweepDesignAuthorityRefs(source) {
28
- if (!source || typeof source !== "object") return [];
29
- return unique([
30
- ...stringArray(source.authority_owner),
31
- ...stringArray(source.authority_refs),
32
- ...stringArray(source.authority_refs_considered),
33
- ...stringArray(source.merged_root_cause_keys).filter(isAuthorityRef),
34
- ]);
35
- }
36
-
37
- export function sweepDesignWaveAuthorityRefs(wave) {
38
- if (!wave || typeof wave !== "object") return [];
39
- return sourceSweepDesignAuthorityRefs(wave);
40
- }
41
-
42
- export function packetAuthorityCoverage(packet, wave) {
43
- const required = sourceSweepDesignAuthorityRefs(wave?.source_sweep_design);
44
- if (required.length === 0) {
45
- return {
46
- ok: true,
47
- requiredAuthorityRefs: [],
48
- missingAuthorityOwnerRefs: [],
49
- missingCanonicalSeamRefs: [],
50
- };
51
- }
52
- const owners = new Set(stringArray(packet?.authority_owner));
53
- const seams = new Set(stringArray(packet?.canonical_seams));
54
- const missingAuthorityOwnerRefs = required.filter((ref) => !owners.has(ref));
55
- const missingCanonicalSeamRefs = required.filter((ref) => !seams.has(ref));
56
- return {
57
- ok: missingAuthorityOwnerRefs.length === 0 && missingCanonicalSeamRefs.length === 0,
58
- requiredAuthorityRefs: required,
59
- missingAuthorityOwnerRefs,
60
- missingCanonicalSeamRefs,
61
- };
62
- }
63
-
64
- export function packetAuthorityCoverageError(coverage) {
65
- const parts = [];
66
- if (coverage.missingAuthorityOwnerRefs?.length) {
67
- parts.push(`authority_owner missing ${coverage.missingAuthorityOwnerRefs.join(", ")}`);
68
- }
69
- if (coverage.missingCanonicalSeamRefs?.length) {
70
- parts.push(`canonical_seams missing ${coverage.missingCanonicalSeamRefs.join(", ")}`);
71
- }
72
- return `Draft packet authority coverage is incomplete: ${parts.join("; ")}`;
73
- }