@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,414 +0,0 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import YAML from "yaml";
5
-
6
- import { addWaveToTopic, admitWaveInTopic, createTopic, selectWaveInTopic } from "../topic.mjs";
7
- import { sweepDesignWaveAuthorityRefs } from "../topic-authority-coverage.mjs";
8
- import { assertDesignArtifact, designRef, inputError, nowIso, requireRunId } from "./common.mjs";
9
-
10
- function inventoryRef(runId) {
11
- return designRef(runId, "inventory.yaml");
12
- }
13
-
14
- function ledgerRef(runId) {
15
- return designRef(runId, "revision-ledger.yaml");
16
- }
17
-
18
- function finalStateReportRef(runId) {
19
- return designRef(runId, "final-state-report.yaml");
20
- }
21
-
22
- function wavePlanRef(runId) {
23
- return designRef(runId, "wave-plan.yaml");
24
- }
25
-
26
- function toPortableRelativePath(filePath) {
27
- return filePath.split(path.sep).join("/");
28
- }
29
-
30
- function stableSlug(value, fallback = "sweep-fix") {
31
- const slug = String(value ?? "")
32
- .toLowerCase()
33
- .replace(/[^a-z0-9]+/g, "-")
34
- .replace(/^-+|-+$/g, "")
35
- .replace(/-{2,}/g, "-");
36
- return slug || fallback;
37
- }
38
-
39
- function titleFromSlug(value) {
40
- return stableSlug(value)
41
- .split("-")
42
- .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
43
- .join(" ");
44
- }
45
-
46
- function topicWaveFromSweepDesignWave(wave, context) {
47
- const authorityRefs = sweepDesignWaveAuthorityRefs(wave);
48
- return {
49
- wave_id: wave.wave_id,
50
- slug: stableSlug(wave.wave_id.replace(/^wave-/, ""), wave.wave_id),
51
- state: "candidate",
52
- primary_closure_goal: wave.scope,
53
- deps: Array.isArray(wave.dependencies) ? wave.dependencies : [],
54
- owner_domain: wave.owner_domain,
55
- parallelizable_after: [],
56
- selected: false,
57
- source_sweep_design: {
58
- run_id: context.runId,
59
- wave_plan_ref: context.wavePlanRef,
60
- final_state_report_ref: context.finalStateReportRef,
61
- source_revision_ledger_ref: context.sourceRevisionLedgerRef,
62
- source_inventory_ref: context.sourceInventoryRef,
63
- source_design_packet_refs: wave.source_design_packet_refs ?? [],
64
- design_auditor_result_refs: wave.design_auditor_result_refs ?? [],
65
- revision_ledger_entry_refs: wave.revision_ledger_entry_refs ?? [],
66
- finding_ids: wave.finding_ids ?? [],
67
- merged_cluster_ids: wave.merged_cluster_ids ?? [],
68
- merged_root_cause_keys: wave.merged_root_cause_keys ?? [],
69
- authority_owner: authorityRefs.length > 0 ? authorityRefs : wave.authority_owner,
70
- source_authority_refs: authorityRefs,
71
- source_authority_coverage_policy: "authority_owner_and_canonical_seams_must_cover_union_of_source_sweep_design_authority_refs",
72
- preflight_ref: wave.preflight_ref,
73
- validation_commands: wave.validation_commands ?? [],
74
- negative_checks: wave.negative_checks ?? [],
75
- drift_resistance_checks: wave.drift_resistance_checks ?? [],
76
- closeout_criteria: wave.closeout_criteria ?? [],
77
- blocked_gate_refs: wave.blocked_gate_refs ?? [],
78
- non_goals: wave.non_goals ?? [],
79
- consolidation_rationale: wave.consolidation_rationale ?? null,
80
- isolation_justification: wave.isolation_justification ?? null,
81
- source_design_auditor_result_ref: wave.source_design_auditor_result_ref ?? null,
82
- },
83
- };
84
- }
85
-
86
- function buildSweepFixReadme(topicId, title, context) {
87
- return `# ${title}
88
-
89
- State: generated sweep-fix topic
90
-
91
- This topic was materialized from a completed sweep design run. It is the implementation carrier for the deterministic waves produced by the LLM sweep-design process.
92
-
93
- ## Source
94
-
95
- - Topic id: ${topicId}
96
- - Sweep design run: ${context.runId}
97
- - Final state report: ${context.finalStateReportRef}
98
- - Wave plan: ${context.wavePlanRef}
99
- - Wave count: ${context.waveCount}
100
- - Source findings mutation: forbidden
101
-
102
- ## Contract
103
-
104
- The source audit findings remain immutable evidence. This topic owns implementation planning and execution state only. Each wave in topic.yaml carries a source_sweep_design block, and sweep-fix-wave-catalog.yaml preserves the full wave-plan payload for review, packet creation, validation, and closeout.
105
- `;
106
- }
107
-
108
- function buildSweepFixDesign(topicId, context) {
109
- return `# Sweep Fix Design
110
-
111
- Topic: ${topicId}
112
-
113
- ## Product Shape
114
-
115
- This topic is generated from sweep design, not hand-authored from a prose summary. The source run has already produced final finding outcomes and deterministic implementation waves.
116
-
117
- ## Authority Boundary
118
-
119
- - Source findings are read-only input evidence.
120
- - Implementation state belongs to this topic.
121
- - Wave execution must use the wave's source_sweep_design provenance, validation commands, negative checks, and closeout criteria.
122
- - No compatibility or legacy migration surface is implied by this generated topic.
123
-
124
- ## Source Artifacts
125
-
126
- - Inventory: ${context.sourceInventoryRef}
127
- - Final state report: ${context.finalStateReportRef}
128
- - Revision ledger: ${context.sourceRevisionLedgerRef}
129
- - Wave plan: ${context.wavePlanRef}
130
- `;
131
- }
132
-
133
- function buildSweepFixPreflight(topicId, context) {
134
- return `# Preflight
135
-
136
- Topic: ${topicId}
137
-
138
- ## Spec Status
139
-
140
- - preflight-required
141
-
142
- ## Authority Owner
143
-
144
- - Selected-wave authority owner is read from topic.yaml waves[].source_sweep_design.authority_owner.
145
- - Topic-wide authority input is .nimi/spec/** plus each generated wave's source_sweep_design block.
146
-
147
- ## Work Type
148
-
149
- - redesign
150
-
151
- ## Status
152
-
153
- This topic contains ${context.waveCount} generated sweep-fix waves from sweep design run ${context.runId}.
154
-
155
- ## Admission Rule
156
-
157
- Wave admission is handled by nimicoding topic. A generated wave may move from candidate to preflight_admitted only when its dependencies are closed and its packet/preflight evidence has been frozen from source_sweep_design.
158
-
159
- ## Stop Line
160
-
161
- - Do not mutate source audit findings.
162
- - Do not dispatch implementation from the sweep design run directory.
163
- - Do not treat sweep-fix-wave-catalog.yaml as a parallel topic state; topic.yaml is the lifecycle registry.
164
- - Do not drop validation commands, negative checks, drift checks, or closeout criteria when freezing packets.
165
-
166
- ## Human Gates
167
-
168
- - Product, authority, semantic, or evidence forks must stop for human decision before the affected wave can close.
169
- - All-mode execution may queue independent gates, but gated waves remain pending or blocked until the decision is recorded.
170
-
171
- ## Validation Commands
172
-
173
- - pnpm exec nimicoding topic validate ${topicId} --json
174
- - pnpm exec nimicoding topic validate graph ${topicId} --json
175
- - pnpm exec nimicoding topic goal ${topicId} --json is expected to emit a goal once a selected wave reaches preflight_admitted or a later execution-stage state.
176
- `;
177
- }
178
-
179
- function buildSweepFixWaves(topicId, waves) {
180
- const rows = waves
181
- .map((wave) => {
182
- const deps = Array.isArray(wave.dependencies) && wave.dependencies.length > 0 ? wave.dependencies.join(", ") : "none";
183
- const findings = Array.isArray(wave.finding_ids) ? wave.finding_ids.length : 0;
184
- return `| ${wave.wave_id} | ${wave.owner_domain} | ${findings} | ${deps} |`;
185
- })
186
- .join("\n");
187
- return `# Waves
188
-
189
- Topic: ${topicId}
190
-
191
- The machine lifecycle registry lives in topic.yaml. Full source design context lives in sweep-fix-wave-catalog.yaml.
192
-
193
- | Wave | Owner | Findings | Dependencies |
194
- |---|---|---:|---|
195
- ${rows}
196
- `;
197
- }
198
-
199
- function buildSweepFixCandidateWavePlan(topicId, context) {
200
- return `# Candidate Wave Plan
201
-
202
- Topic: ${topicId}
203
-
204
- The candidate wave set is generated from ${context.wavePlanRef}. There are ${context.waveCount} candidate implementation waves. The first executable wave should be selected by nimicoding topic after dependency checks and packet freeze, not by editing the source sweep-design artifacts.
205
- `;
206
- }
207
-
208
- function buildSweepFixCloseout(topicId) {
209
- return `# Closeout
210
-
211
- Topic: ${topicId}
212
-
213
- ## Wave-1 Closeout Requirements
214
-
215
- - complete: selected wave has implementation result lineage, validation evidence, negative-check evidence, drift-resistance evidence, and source_sweep_design provenance.
216
- - partial: selected wave has bounded residual work recorded with explicit downstream wave refs.
217
- - blocked: selected wave has unresolved product, authority, semantic, or evidence gates.
218
- - pending: selected wave is waiting on external evidence or human decision.
219
-
220
- ## Wave Closeout
221
-
222
- Each wave must close with packet lineage, implementation result lineage, validation command evidence, negative check evidence, drift resistance evidence, and source_sweep_design provenance retained.
223
-
224
- ## Topic Closeout
225
-
226
- The topic may close only after all generated waves are closed, retired by explicit supersession, or blocked with a recorded human decision.
227
- `;
228
- }
229
-
230
- function buildSweepFixImplementationDoctrine(topicId) {
231
- return `# Implementation Doctrine
232
-
233
- Topic: ${topicId}
234
-
235
- Implementation must be hard-cut, complete, and authority-aligned. No pseudo-success, compatibility shim, legacy alias, app-local shadow truth, or partial closure is acceptable. Runtime/SDK/Desktop/Web boundaries remain governed by repository authority and by each wave's validation and closeout criteria.
236
- `;
237
- }
238
-
239
- function buildSweepFixAdmissionChecklists(topicId) {
240
- return `# Admission Checklists
241
-
242
- Topic: ${topicId}
243
-
244
- ## Before Admitting A Wave
245
-
246
- - The wave exists in topic.yaml.
247
- - All dependencies are closed.
248
- - source_sweep_design includes design packet refs, auditor result refs, revision ledger refs, validation commands, negative checks, drift checks, and closeout criteria.
249
- - Any blocked gate refs have recorded human decisions.
250
- - A packet/preflight artifact has been frozen for this wave.
251
- `;
252
- }
253
-
254
- function buildSweepFixManagerSessionProtocol(topicId) {
255
- return `# Manager Session Protocol
256
-
257
- Topic: ${topicId}
258
-
259
- 1. Use nimicoding topic to select, admit, run, and close waves.
260
- 2. Read sweep-fix-wave-catalog.yaml and the selected wave's source_sweep_design before freezing a packet.
261
- 3. Stop for human confirmation only on product, authority, semantic, or evidence forks.
262
- 4. In all-mode execution, queue human decisions and continue independent waves; resolve queued decisions before closing affected waves.
263
- `;
264
- }
265
-
266
- function buildSweepFixManagerPrompts(topicId) {
267
- return `# Manager Prompts
268
-
269
- Topic: ${topicId}
270
-
271
- ## Packet Freeze Prompt
272
-
273
- Use the selected topic wave and its source_sweep_design block to produce an implementation packet. Preserve the source design packet refs, auditor result refs, revision ledger refs, validation commands, negative checks, drift checks, closeout criteria, non-goals, and blocked gates. Do not mutate source findings.
274
- `;
275
- }
276
-
277
- async function writeSweepFixTopicArtifacts(topicDir, topicId, title, context, waves) {
278
- await mkdir(path.join(topicDir, "sweep-fix"), { recursive: true });
279
- const catalog = {
280
- version: 1,
281
- kind: "sweep-fix-wave-catalog",
282
- topic_id: topicId,
283
- source_sweep_design_run_id: context.runId,
284
- source_inventory_ref: context.sourceInventoryRef,
285
- source_final_state_report_ref: context.finalStateReportRef,
286
- source_revision_ledger_ref: context.sourceRevisionLedgerRef,
287
- source_wave_plan_ref: context.wavePlanRef,
288
- source_findings_mutation_policy: "read_only_never_update_from_sweep_fix_topic",
289
- wave_count: waves.length,
290
- waves,
291
- created_at: context.createdAt,
292
- };
293
- const source = {
294
- version: 1,
295
- kind: "sweep-fix-topic-source",
296
- topic_id: topicId,
297
- source_sweep_design_run_id: context.runId,
298
- source_inventory_ref: context.sourceInventoryRef,
299
- source_final_state_report_ref: context.finalStateReportRef,
300
- source_revision_ledger_ref: context.sourceRevisionLedgerRef,
301
- source_wave_plan_ref: context.wavePlanRef,
302
- source_findings_mutation_policy: "read_only_never_update_from_sweep_fix_topic",
303
- final_state_complete: true,
304
- wave_count: waves.length,
305
- created_at: context.createdAt,
306
- };
307
- const files = new Map([
308
- ["README.md", buildSweepFixReadme(topicId, title, context)],
309
- ["design.md", buildSweepFixDesign(topicId, context)],
310
- ["preflight.md", buildSweepFixPreflight(topicId, context)],
311
- ["waves.md", buildSweepFixWaves(topicId, waves)],
312
- ["candidate-wave-plan.md", buildSweepFixCandidateWavePlan(topicId, context)],
313
- ["closeout.md", buildSweepFixCloseout(topicId)],
314
- ["implementation-doctrine.md", buildSweepFixImplementationDoctrine(topicId)],
315
- ["admission-checklists.md", buildSweepFixAdmissionChecklists(topicId)],
316
- ["manager-session-protocol.md", buildSweepFixManagerSessionProtocol(topicId)],
317
- ["manager-prompts.md", buildSweepFixManagerPrompts(topicId)],
318
- ["sweep-fix/source.yaml", YAML.stringify(source)],
319
- ["sweep-fix/wave-catalog.yaml", YAML.stringify(catalog)],
320
- ]);
321
- for (const [fileName, contents] of files.entries()) {
322
- await writeFile(path.join(topicDir, fileName), contents.endsWith("\n") ? contents : `${contents}\n`, "utf8");
323
- }
324
- }
325
-
326
- async function loadInventory(projectRoot, runId) {
327
- return assertDesignArtifact(projectRoot, inventoryRef(runId), "sweep-design-inventory", "inventory");
328
- }
329
-
330
- export async function runFixTopic(projectRoot, options) {
331
- const run = requireRunId(options);
332
- if (!run.ok) return run;
333
- const inventory = await loadInventory(projectRoot, run.runId);
334
- if (!inventory.ok) return inventory;
335
- const finalReport = await assertDesignArtifact(projectRoot, finalStateReportRef(run.runId), "sweep-design-final-state-report", "final state report");
336
- if (!finalReport.ok) return finalReport;
337
- if (finalReport.value.complete !== true) {
338
- return inputError("nimicoding sweep design fix-topic refused: final-state-report is not complete.\n");
339
- }
340
- const wavePlan = await assertDesignArtifact(projectRoot, wavePlanRef(run.runId), "sweep-design-wave-plan", "wave plan");
341
- if (!wavePlan.ok) return wavePlan;
342
- const waves = Array.isArray(wavePlan.value.waves) ? wavePlan.value.waves : [];
343
- if (waves.length === 0) return inputError("nimicoding sweep design fix-topic refused: wave-plan contains no implementation waves.\n");
344
- if (wavePlan.value.wave_count !== waves.length) {
345
- return inputError("nimicoding sweep design fix-topic refused: wave-plan wave_count does not match waves[].\n");
346
- }
347
- const waveIds = new Set();
348
- for (const wave of waves) {
349
- if (waveIds.has(wave.wave_id)) return inputError(`nimicoding sweep design fix-topic refused: duplicate wave id ${wave.wave_id}.\n`);
350
- waveIds.add(wave.wave_id);
351
- }
352
- const slug = stableSlug(options.slug ?? `sweep-fix-${run.runId}`, `sweep-fix-${run.runId}`);
353
- const title = options.title ?? titleFromSlug(slug);
354
- const now = options.verifiedAt ? new Date(options.verifiedAt) : new Date();
355
- if (Number.isNaN(now.getTime())) return inputError("nimicoding sweep design fix-topic refused: --verified-at must be an ISO timestamp.\n");
356
- const created = await createTopic(projectRoot, {
357
- slug,
358
- title,
359
- now,
360
- mode: "landed",
361
- posture: "no_legacy_hard_cut",
362
- designPolicy: "complete_contract_first",
363
- parallelTruth: "forbidden",
364
- layering: "ontology",
365
- risk: "high",
366
- applicability: "complex_remediation",
367
- justification: `sweep design run ${run.runId} produced a complete final-state report and ${waves.length} deterministic implementation waves`,
368
- executionMode: "manager_worker_auditor",
369
- });
370
- if (!created.ok) return created;
371
- const context = {
372
- runId: run.runId,
373
- sourceInventoryRef: inventory.ref,
374
- finalStateReportRef: finalReport.ref,
375
- sourceRevisionLedgerRef: wavePlan.value.source_revision_ledger_ref ?? finalReport.value.source_revision_ledger_ref ?? ledgerRef(run.runId),
376
- wavePlanRef: wavePlan.ref,
377
- waveCount: waves.length,
378
- createdAt: options.verifiedAt ?? nowIso(),
379
- };
380
- const topicWaves = waves.map((wave) => topicWaveFromSweepDesignWave(wave, context));
381
- for (const topicWave of topicWaves) {
382
- const added = await addWaveToTopic(projectRoot, created.topicId, topicWave);
383
- if (!added.ok) return added;
384
- }
385
- await writeSweepFixTopicArtifacts(created.topicDir, created.topicId, title, context, waves);
386
- let admittedWaveId = null;
387
- let finalTopicRef = created.topicRef;
388
- let finalTopicState = created.state;
389
- const admitWaveId = options.admitWaveId ?? (options.admitFirstWave ? topicWaves.find((wave) => wave.deps.length === 0)?.wave_id : null);
390
- if (admitWaveId) {
391
- if (!waveIds.has(admitWaveId)) return inputError(`nimicoding sweep design fix-topic refused: --admit-wave-id does not exist in the generated wave plan: ${admitWaveId}.\n`);
392
- const selected = await selectWaveInTopic(projectRoot, created.topicId, admitWaveId);
393
- if (!selected.ok) return selected;
394
- const admitted = await admitWaveInTopic(projectRoot, created.topicId, admitWaveId);
395
- if (!admitted.ok) return admitted;
396
- admittedWaveId = admitted.waveId;
397
- finalTopicRef = admitted.topicRef;
398
- finalTopicState = admitted.state;
399
- }
400
- return {
401
- ok: true,
402
- exitCode: 0,
403
- runId: run.runId,
404
- topicId: created.topicId,
405
- topicRef: finalTopicRef,
406
- state: finalTopicState,
407
- sourceRef: toPortableRelativePath(path.join(finalTopicRef, "sweep-fix", "source.yaml")),
408
- waveCatalogRef: toPortableRelativePath(path.join(finalTopicRef, "sweep-fix", "wave-catalog.yaml")),
409
- wavePlanRef: wavePlan.ref,
410
- waveCount: waves.length,
411
- materializedWaveIds: topicWaves.map((wave) => wave.wave_id),
412
- admittedWaveId,
413
- };
414
- }
@@ -1,54 +0,0 @@
1
- import { DESIGN_STATES, TERMINAL_STATES } from "./common.mjs";
2
-
3
- const TRANSITIONS = new Map([
4
- ["raw", new Set(["confirmed", "duplicate", "superseded", "false_positive", "needs_more_audit"])],
5
- ["confirmed", new Set([
6
- "needs_user_decision",
7
- "needs_authority_alignment",
8
- "needs_design",
9
- "ready_for_implementation_wave",
10
- "blocked",
11
- ])],
12
- ["needs_more_audit", new Set(["confirmed", "false_positive", "superseded", "blocked"])],
13
- ["needs_user_decision", new Set(["confirmed", "ready_for_implementation_wave", "blocked"])],
14
- ["needs_authority_alignment", new Set(["confirmed", "ready_for_implementation_wave", "blocked"])],
15
- ["needs_design", new Set(["confirmed", "ready_for_implementation_wave", "blocked"])],
16
- ["ready_for_implementation_wave", new Set(["blocked"])],
17
- ]);
18
-
19
- function needsUserGate(toState) {
20
- return toState === "false_positive";
21
- }
22
-
23
- function needsNextArtifact(fromState, toState) {
24
- return fromState.startsWith("needs_") || [
25
- "needs_more_audit",
26
- "needs_user_decision",
27
- "needs_authority_alignment",
28
- "needs_design",
29
- "ready_for_implementation_wave",
30
- ].includes(toState);
31
- }
32
-
33
- export function validateLifecycleTransition({ fromState, toState, userGateRef, nextArtifactRef }) {
34
- if (!DESIGN_STATES.has(fromState) || !DESIGN_STATES.has(toState)) {
35
- return `unsupported lifecycle transition ${fromState} -> ${toState}`;
36
- }
37
- if (TERMINAL_STATES.has(fromState)) {
38
- return `terminal finding state cannot transition: ${fromState}`;
39
- }
40
- if (!TRANSITIONS.get(fromState)?.has(toState)) {
41
- return `illegal lifecycle transition ${fromState} -> ${toState}`;
42
- }
43
- if (needsUserGate(toState) && !userGateRef) {
44
- return `${toState} requires --user-gate-ref`;
45
- }
46
- if (needsNextArtifact(fromState, toState) && !nextArtifactRef) {
47
- return `${fromState} -> ${toState} requires --next-artifact-ref`;
48
- }
49
- return null;
50
- }
51
-
52
- export function terminalStates() {
53
- return [...TERMINAL_STATES].sort();
54
- }