@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,353 +0,0 @@
1
- import { realpath } from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import {
5
- HIGH_RISK_DECISION_PAYLOAD_CONTRACT_VERSION,
6
- HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
7
- } from "../constants.mjs";
8
- import { inspectDoctorState } from "./doctor.mjs";
9
- import { readTextIfFile } from "./fs-helpers.mjs";
10
- import {
11
- localize,
12
- styleCommand,
13
- styleHeading,
14
- styleLabel,
15
- styleStatus,
16
- } from "./ui.mjs";
17
- import { validateAcceptance } from "./validators.mjs";
18
- import { isIsoUtcTimestamp, isPlainObject } from "./value-helpers.mjs";
19
-
20
- function translateDecisionReason(reason) {
21
- const translations = new Map([
22
- ["imported review payload must declare contractVersion nimicoding.high-risk-review.v1", "导入的 review payload 必须声明 contractVersion nimicoding.high-risk-review.v1"],
23
- ["imported review payload must declare skill.id high_risk_execution", "导入的 review payload 必须声明 skill.id 为 high_risk_execution"],
24
- ["imported review payload must remain localOnly true", "导入的 review payload 必须保持 localOnly 为 true"],
25
- ["decide-high-risk-execution requires a review payload with ok true", "decide-high-risk-execution 需要一个 ok 为 true 的 review payload"],
26
- ["decide-high-risk-execution requires reviewStatus ready_for_manager_review", "decide-high-risk-execution 需要 reviewStatus 为 ready_for_manager_review"],
27
- ["imported review payload must include attachmentRefs", "导入的 review payload 必须包含 attachmentRefs"],
28
- ["Bootstrap or handoff validation is failing; repair doctor errors before recording a manager decision", "bootstrap 或 handoff 校验失败;请先修复 doctor 报错,再记录 manager decision"],
29
- ["High-risk decision projection requires the canonical tree under `.nimi/spec`", "high-risk decision 投影需要 `.nimi/spec` 下的 canonical tree"],
30
- ["Acceptance artifact failed mechanical validation", "acceptance 产物未通过机械校验"],
31
- ["Manager-owned local decision record is ready", "manager 拥有的本地 decision 记录已准备就绪"],
32
- ]);
33
- return translations.get(reason) ?? reason;
34
- }
35
-
36
- async function loadImportedReviewPayload(projectRoot, fromPath) {
37
- const absolutePath = path.resolve(projectRoot, fromPath);
38
- const rawText = await readTextIfFile(absolutePath);
39
-
40
- if (rawText === null) {
41
- return {
42
- ok: false,
43
- error: `${localize(
44
- `nimicoding decide-high-risk-execution refused: cannot read imported review JSON at ${absolutePath}.`,
45
- `nimicoding decide-high-risk-execution 已拒绝:无法读取 ${absolutePath} 处的导入 review JSON。`,
46
- )}\n`,
47
- };
48
- }
49
-
50
- let parsed;
51
- try {
52
- parsed = JSON.parse(rawText);
53
- } catch {
54
- return {
55
- ok: false,
56
- error: `${localize(
57
- `nimicoding decide-high-risk-execution refused: imported review JSON at ${absolutePath} is invalid JSON.`,
58
- `nimicoding decide-high-risk-execution 已拒绝:${absolutePath} 处的导入 review JSON 不是合法 JSON。`,
59
- )}\n`,
60
- };
61
- }
62
-
63
- if (!isPlainObject(parsed)) {
64
- return {
65
- ok: false,
66
- error: `${localize(
67
- "nimicoding decide-high-risk-execution refused: imported review JSON must be an object.",
68
- "nimicoding decide-high-risk-execution 已拒绝:导入的 review JSON 必须是对象。",
69
- )}\n`,
70
- };
71
- }
72
-
73
- if (parsed.projectRoot) {
74
- let importedProjectRoot;
75
- let currentProjectRoot;
76
- try {
77
- importedProjectRoot = await realpath(parsed.projectRoot);
78
- currentProjectRoot = await realpath(projectRoot);
79
- } catch {
80
- return {
81
- ok: false,
82
- error: `${localize(
83
- "nimicoding decide-high-risk-execution refused: imported review projectRoot could not be resolved.",
84
- "nimicoding decide-high-risk-execution 已拒绝:无法解析导入 review 的 projectRoot。",
85
- )}\n`,
86
- };
87
- }
88
-
89
- if (importedProjectRoot !== currentProjectRoot) {
90
- return {
91
- ok: false,
92
- error: `${localize(
93
- "nimicoding decide-high-risk-execution refused: imported review projectRoot does not match the current project.",
94
- "nimicoding decide-high-risk-execution 已拒绝:导入 review 的 projectRoot 与当前项目不匹配。",
95
- )}\n`,
96
- };
97
- }
98
- }
99
-
100
- return {
101
- ok: true,
102
- path: absolutePath,
103
- payload: parsed,
104
- };
105
- }
106
-
107
- function validateImportedReviewPayload(payload) {
108
- if (payload.contractVersion !== "nimicoding.high-risk-review.v1") {
109
- return {
110
- ok: false,
111
- reason: "imported review payload must declare contractVersion nimicoding.high-risk-review.v1",
112
- };
113
- }
114
-
115
- if (payload.skill?.id !== "high_risk_execution") {
116
- return {
117
- ok: false,
118
- reason: "imported review payload must declare skill.id high_risk_execution",
119
- };
120
- }
121
-
122
- if (payload.localOnly !== true) {
123
- return {
124
- ok: false,
125
- reason: "imported review payload must remain localOnly true",
126
- };
127
- }
128
-
129
- if (payload.ok !== true) {
130
- return {
131
- ok: false,
132
- reason: "decide-high-risk-execution requires a review payload with ok true",
133
- };
134
- }
135
-
136
- if (payload.reviewStatus !== "ready_for_manager_review") {
137
- return {
138
- ok: false,
139
- reason: "decide-high-risk-execution requires reviewStatus ready_for_manager_review",
140
- };
141
- }
142
-
143
- if (!isPlainObject(payload.attachmentRefs)) {
144
- return {
145
- ok: false,
146
- reason: "imported review payload must include attachmentRefs",
147
- };
148
- }
149
-
150
- return { ok: true };
151
- }
152
-
153
- function extractMarkdownSectionBody(text, heading) {
154
- const lines = text.split(/\r?\n/);
155
- let sectionLevel = null;
156
- const body = [];
157
- for (const line of lines) {
158
- const headingMatch = line.match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);
159
- if (headingMatch) {
160
- const level = headingMatch[1].length;
161
- const title = headingMatch[2].trim();
162
- if (sectionLevel !== null && level <= sectionLevel) {
163
- break;
164
- }
165
- if (title === heading) {
166
- sectionLevel = level;
167
- continue;
168
- }
169
- }
170
- if (sectionLevel !== null) {
171
- body.push(line);
172
- }
173
- }
174
- return sectionLevel === null ? "" : body.join("\n");
175
- }
176
-
177
- function extractAcceptanceDisposition(text) {
178
- const dispositionSection = extractMarkdownSectionBody(text, "Current Phase Disposition");
179
- const match = dispositionSection.match(/Disposition:\s*(\w+)/i);
180
- return match ? match[1].toLowerCase() : null;
181
- }
182
-
183
- function evaluateDecisionReadiness(doctorResult, acceptanceReport) {
184
- if (!doctorResult.ok || !doctorResult.handoffReadiness.ok) {
185
- return {
186
- ok: false,
187
- reason: "Bootstrap or handoff validation is failing; repair doctor errors before recording a manager decision",
188
- };
189
- }
190
-
191
- const v2Ready = doctorResult.specGenerationInputs?.mode === "class_filtered"
192
- && doctorResult.canonicalTree?.requiredFilesValid === true;
193
- const legacyReady = doctorResult.lifecycleState?.treeState === "canonical_tree_ready"
194
- && doctorResult.canonicalTree?.requiredFilesValid === true;
195
- if (!v2Ready && !legacyReady) {
196
- return {
197
- ok: false,
198
- reason: "High-risk decision projection requires canonical_tree_ready with declared canonical files present",
199
- };
200
- }
201
-
202
- if (!acceptanceReport.ok) {
203
- return {
204
- ok: false,
205
- reason: "Acceptance artifact failed mechanical validation",
206
- };
207
- }
208
-
209
- return {
210
- ok: true,
211
- reason: "Manager-owned local decision record is ready",
212
- };
213
- }
214
-
215
- export async function buildHighRiskDecisionPayload(projectRoot, options) {
216
- const imported = await loadImportedReviewPayload(projectRoot, options.fromPath);
217
- if (!imported.ok) {
218
- return {
219
- ok: false,
220
- exitCode: 2,
221
- inputError: true,
222
- error: imported.error,
223
- };
224
- }
225
-
226
- const inputValidation = validateImportedReviewPayload(imported.payload);
227
- if (!inputValidation.ok) {
228
- return {
229
- ok: false,
230
- exitCode: 2,
231
- inputError: true,
232
- error: `${localize(
233
- `nimicoding decide-high-risk-execution refused: ${inputValidation.reason}.`,
234
- `nimicoding decide-high-risk-execution 已拒绝:${translateDecisionReason(inputValidation.reason)}。`,
235
- )}\n`,
236
- };
237
- }
238
-
239
- if (!isIsoUtcTimestamp(options.verifiedAt)) {
240
- return {
241
- ok: false,
242
- exitCode: 2,
243
- inputError: true,
244
- error: `${localize(
245
- "nimicoding decide-high-risk-execution refused: --verified-at must be an ISO-8601 UTC timestamp.",
246
- "nimicoding decide-high-risk-execution 已拒绝:`--verified-at` 必须是 ISO-8601 UTC 时间戳。",
247
- )}\n`,
248
- };
249
- }
250
-
251
- const acceptanceRef = path.resolve(projectRoot, options.acceptancePath);
252
- const acceptanceText = await readTextIfFile(acceptanceRef);
253
- if (acceptanceText === null) {
254
- return {
255
- ok: false,
256
- exitCode: 2,
257
- inputError: true,
258
- error: `${localize(
259
- `nimicoding decide-high-risk-execution refused: cannot read acceptance artifact at ${acceptanceRef}.`,
260
- `nimicoding decide-high-risk-execution 已拒绝:无法读取 ${acceptanceRef} 处的 acceptance 产物。`,
261
- )}\n`,
262
- };
263
- }
264
-
265
- const acceptanceReport = await validateAcceptance(acceptanceRef);
266
- const disposition = extractAcceptanceDisposition(acceptanceText);
267
- if (!disposition) {
268
- return {
269
- ok: false,
270
- exitCode: 2,
271
- inputError: true,
272
- error: `${localize(
273
- "nimicoding decide-high-risk-execution refused: acceptance artifact must declare a Disposition line.",
274
- "nimicoding decide-high-risk-execution 已拒绝:acceptance 产物必须声明一行 `Disposition`。",
275
- )}\n`,
276
- };
277
- }
278
-
279
- const doctorResult = await inspectDoctorState(projectRoot);
280
- const readiness = evaluateDecisionReadiness(doctorResult, acceptanceReport);
281
- const artifactPath = path.join(
282
- projectRoot,
283
- ".nimi",
284
- "local",
285
- "handoff-results",
286
- "high_risk_execution.decision.json",
287
- );
288
-
289
- return {
290
- contractVersion: HIGH_RISK_DECISION_PAYLOAD_CONTRACT_VERSION,
291
- ok: readiness.ok,
292
- exitCode: readiness.ok ? 0 : 1,
293
- projectRoot,
294
- sourceReviewRef: imported.path,
295
- localOnly: true,
296
- artifactPath,
297
- skill: {
298
- id: "high_risk_execution",
299
- resultContractRef: HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
300
- },
301
- verifiedAt: options.verifiedAt,
302
- managerReviewOwner: imported.payload.managerReviewOwner ?? doctorResult.delegatedContracts.semanticReviewOwner,
303
- decisionStatus: readiness.ok ? "manager_decision_recorded" : "blocked",
304
- acceptanceRef,
305
- acceptanceDisposition: disposition,
306
- acceptanceValidation: {
307
- ok: acceptanceReport.ok,
308
- refusal: acceptanceReport.refusal ?? null,
309
- errors: acceptanceReport.errors ?? [],
310
- warnings: acceptanceReport.warnings ?? [],
311
- },
312
- reviewStatus: imported.payload.reviewStatus,
313
- summary: imported.payload.summary,
314
- attachmentRefs: imported.payload.attachmentRefs,
315
- readiness,
316
- doctor: {
317
- ok: doctorResult.ok,
318
- handoffReadiness: doctorResult.handoffReadiness,
319
- delegatedContracts: doctorResult.delegatedContracts,
320
- },
321
- nextAction: readiness.ok
322
- ? options.writeLocal
323
- ? `Write the high-risk decision artifact to ${artifactPath}.`
324
- : "Review the local decision payload or write it locally with `--write-local`."
325
- : readiness.reason,
326
- };
327
- }
328
-
329
- export function formatHighRiskDecisionPayload(payload) {
330
- const nextAction = payload.readiness.ok
331
- ? payload.nextAction.startsWith("Write the high-risk decision artifact to ")
332
- ? localize(payload.nextAction, `将 high-risk decision 产物写入 ${payload.artifactPath}。`)
333
- : localize(
334
- payload.nextAction,
335
- `检查本地 decision payload,或使用 ${styleCommand("--write-local")} 将其写入本地。`,
336
- )
337
- : translateDecisionReason(payload.nextAction);
338
- const lines = [
339
- styleHeading(`nimicoding decide-high-risk-execution: ${payload.projectRoot}`),
340
- "",
341
- styleLabel(localize("Decision:", "决策:")),
342
- ` - decision_status: ${payload.decisionStatus}`,
343
- ` - disposition: ${payload.acceptanceDisposition}`,
344
- ` - manager_review_owner: ${payload.managerReviewOwner ?? localize("unknown", "未知")}`,
345
- ` - ready: ${styleStatus(payload.readiness.ok ? "ready" : "needs_attention")}`,
346
- ` - local_only: ${payload.localOnly ? "true" : "false"}`,
347
- "",
348
- styleLabel(localize("Next:", "下一步:")),
349
- ` - ${nextAction}`,
350
- ];
351
-
352
- return `${lines.join("\n")}\n`;
353
- }
@@ -1,321 +0,0 @@
1
- import path from "node:path";
2
-
3
- import {
4
- EXTERNAL_EXECUTION_ARTIFACTS_CONFIG_REF,
5
- HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
6
- HIGH_RISK_INGEST_PAYLOAD_CONTRACT_VERSION,
7
- } from "../constants.mjs";
8
- import {
9
- loadHighRiskExecutionContract,
10
- validateHighRiskExecutionSummary,
11
- } from "./contracts.mjs";
12
- import {
13
- loadExternalExecutionArtifactsConfig,
14
- validateHighRiskExecutionArtifactRefs,
15
- } from "./external-execution.mjs";
16
- import { pathExists } from "./fs-helpers.mjs";
17
- import { inspectDoctorState } from "./doctor.mjs";
18
- import { loadImportedCloseoutOptions } from "./closeout.mjs";
19
- import {
20
- localize,
21
- styleCommand,
22
- styleHeading,
23
- styleLabel,
24
- styleStatus,
25
- } from "./ui.mjs";
26
- import {
27
- validateExecutionPacket,
28
- validateOrchestrationState,
29
- validatePrompt,
30
- validateWorkerOutput,
31
- } from "./validators.mjs";
32
-
33
- function translateIngestReason(reason) {
34
- const translations = new Map([
35
- ["imported closeout must declare skill high_risk_execution", "导入的 closeout 必须声明 skill 为 high_risk_execution"],
36
- ["high-risk ingest requires a completed high_risk_execution closeout artifact", "high-risk ingest 需要一个 completed 的 high_risk_execution closeout 产物"],
37
- ["high-risk ingest requires an imported summary", "high-risk ingest 需要导入的 summary"],
38
- ["high-risk ingest requires summary.status candidate_ready", "high-risk ingest 需要 summary.status 为 candidate_ready"],
39
- ["Bootstrap or handoff validation is failing; repair doctor errors before ingesting external execution artifacts", "bootstrap 或 handoff 校验失败;请先修复 doctor 报错,再导入外部执行产物"],
40
- ["High-risk ingest requires the canonical tree under `.nimi/spec`", "high-risk ingest 需要 `.nimi/spec` 下的 canonical tree"],
41
- ["One or more external execution candidate artifacts failed mechanical validation", "一个或多个外部执行候选产物未通过机械校验"],
42
- ["External execution candidate artifacts passed bounded ingest validation", "外部执行候选产物已通过受边界约束的导入校验"],
43
- ]);
44
- return translations.get(reason) ?? reason;
45
- }
46
-
47
- function projectValidation(ref, report) {
48
- return {
49
- ref,
50
- ok: Boolean(report.ok),
51
- refusal: report.refusal ?? null,
52
- errors: report.errors ?? [],
53
- warnings: report.warnings ?? [],
54
- ...(report.signal ? { signal: report.signal } : {}),
55
- };
56
- }
57
-
58
- async function validateEvidenceRefs(projectRoot, refs) {
59
- const results = [];
60
-
61
- for (const ref of refs) {
62
- const absolutePath = path.resolve(projectRoot, ref);
63
- const info = await pathExists(absolutePath);
64
- results.push({
65
- ref,
66
- ok: Boolean(info?.isFile()),
67
- errors: info?.isFile() ? [] : [`missing evidence artifact: ${ref}`],
68
- warnings: [],
69
- });
70
- }
71
-
72
- return results;
73
- }
74
-
75
- async function validateReferencedArtifacts(projectRoot, summary) {
76
- const packetRef = path.resolve(projectRoot, summary.packet_ref);
77
- const orchestrationStateRef = path.resolve(projectRoot, summary.orchestration_state_ref);
78
- const promptRef = path.resolve(projectRoot, summary.prompt_ref);
79
- const workerOutputRef = path.resolve(projectRoot, summary.worker_output_ref);
80
-
81
- const [
82
- executionPacket,
83
- orchestrationState,
84
- prompt,
85
- workerOutput,
86
- evidence,
87
- ] = await Promise.all([
88
- validateExecutionPacket(packetRef),
89
- validateOrchestrationState(orchestrationStateRef),
90
- validatePrompt(promptRef),
91
- validateWorkerOutput(workerOutputRef),
92
- validateEvidenceRefs(projectRoot, summary.evidence_refs),
93
- ]);
94
-
95
- return {
96
- executionPacket: projectValidation(summary.packet_ref, executionPacket),
97
- orchestrationState: projectValidation(summary.orchestration_state_ref, orchestrationState),
98
- prompt: projectValidation(summary.prompt_ref, prompt),
99
- workerOutput: projectValidation(summary.worker_output_ref, workerOutput),
100
- evidence,
101
- };
102
- }
103
-
104
- function validateHighRiskIngestInput(importedOptions, summaryValidation, rootsValidation) {
105
- if (importedOptions.skill !== "high_risk_execution") {
106
- return {
107
- ok: false,
108
- reason: "imported closeout must declare skill high_risk_execution",
109
- };
110
- }
111
-
112
- if (importedOptions.outcome !== "completed") {
113
- return {
114
- ok: false,
115
- reason: "high-risk ingest requires a completed high_risk_execution closeout artifact",
116
- };
117
- }
118
-
119
- if (!importedOptions.summary) {
120
- return {
121
- ok: false,
122
- reason: "high-risk ingest requires an imported summary",
123
- };
124
- }
125
-
126
- if (!summaryValidation.ok) {
127
- return summaryValidation;
128
- }
129
-
130
- if (importedOptions.summary.status !== "candidate_ready") {
131
- return {
132
- ok: false,
133
- reason: "high-risk ingest requires summary.status candidate_ready",
134
- };
135
- }
136
-
137
- if (!rootsValidation.ok) {
138
- return rootsValidation;
139
- }
140
-
141
- return { ok: true };
142
- }
143
-
144
- function evaluateHighRiskIngestReadiness(doctorResult, validations) {
145
- if (!doctorResult.ok || !doctorResult.handoffReadiness.ok) {
146
- return {
147
- ok: false,
148
- reason: "Bootstrap or handoff validation is failing; repair doctor errors before ingesting external execution artifacts",
149
- };
150
- }
151
-
152
- const v2Ready = doctorResult.specGenerationInputs?.mode === "class_filtered"
153
- && doctorResult.canonicalTree?.requiredFilesValid === true;
154
- const legacyReady = doctorResult.lifecycleState?.treeState === "canonical_tree_ready"
155
- && doctorResult.canonicalTree?.requiredFilesValid === true;
156
- if (!v2Ready && !legacyReady) {
157
- return {
158
- ok: false,
159
- reason: "High-risk ingest requires canonical_tree_ready with declared canonical files present",
160
- };
161
- }
162
-
163
- const mechanicalChecksOk = validations.executionPacket.ok
164
- && validations.orchestrationState.ok
165
- && validations.prompt.ok
166
- && validations.workerOutput.ok
167
- && validations.evidence.every((entry) => entry.ok);
168
-
169
- if (!mechanicalChecksOk) {
170
- return {
171
- ok: false,
172
- reason: "One or more external execution candidate artifacts failed mechanical validation",
173
- };
174
- }
175
-
176
- return {
177
- ok: true,
178
- reason: "External execution candidate artifacts passed bounded ingest validation",
179
- };
180
- }
181
-
182
- export async function buildHighRiskIngestPayload(projectRoot, fromPath, options = {}) {
183
- const sourceCloseoutRef = path.resolve(projectRoot, fromPath);
184
- const imported = await loadImportedCloseoutOptions(projectRoot, fromPath);
185
- if (!imported.ok) {
186
- return {
187
- ok: false,
188
- exitCode: 2,
189
- inputError: true,
190
- error: imported.error,
191
- };
192
- }
193
-
194
- const highRiskContract = await loadHighRiskExecutionContract(projectRoot);
195
- if (!highRiskContract.ok) {
196
- return {
197
- ok: false,
198
- exitCode: 2,
199
- inputError: true,
200
- error: `${localize(
201
- "nimicoding ingest-high-risk-execution refused: high_risk_execution result contract is missing or malformed.",
202
- "nimicoding ingest-high-risk-execution 已拒绝:high_risk_execution 结果契约缺失或格式错误。",
203
- )}\n`,
204
- };
205
- }
206
-
207
- const externalExecutionArtifacts = await loadExternalExecutionArtifactsConfig(projectRoot);
208
- if (!externalExecutionArtifacts.ok) {
209
- return {
210
- ok: false,
211
- exitCode: 2,
212
- inputError: true,
213
- error: `${localize(
214
- "nimicoding ingest-high-risk-execution refused: external execution artifacts config is missing or malformed.",
215
- "nimicoding ingest-high-risk-execution 已拒绝:external execution artifacts 配置缺失或格式错误。",
216
- )}\n`,
217
- };
218
- }
219
-
220
- const summaryValidation = validateHighRiskExecutionSummary(
221
- imported.options.summary,
222
- highRiskContract,
223
- imported.options.verifiedAt,
224
- );
225
- const rootsValidation = imported.options.summary
226
- ? validateHighRiskExecutionArtifactRefs(imported.options.summary, externalExecutionArtifacts)
227
- : { ok: true };
228
- const ingestInputValidation = validateHighRiskIngestInput(
229
- imported.options,
230
- summaryValidation,
231
- rootsValidation,
232
- );
233
-
234
- if (!ingestInputValidation.ok) {
235
- return {
236
- ok: false,
237
- exitCode: 2,
238
- inputError: true,
239
- error: `${localize(
240
- `nimicoding ingest-high-risk-execution refused: ${ingestInputValidation.reason}.`,
241
- `nimicoding ingest-high-risk-execution 已拒绝:${translateIngestReason(ingestInputValidation.reason)}。`,
242
- )}\n`,
243
- };
244
- }
245
-
246
- const validations = await validateReferencedArtifacts(projectRoot, imported.options.summary);
247
- const doctorResult = await inspectDoctorState(projectRoot);
248
- const readiness = evaluateHighRiskIngestReadiness(doctorResult, validations);
249
- const artifactPath = path.join(
250
- projectRoot,
251
- ".nimi",
252
- "local",
253
- "handoff-results",
254
- "high_risk_execution.ingest.json",
255
- );
256
-
257
- return {
258
- contractVersion: HIGH_RISK_INGEST_PAYLOAD_CONTRACT_VERSION,
259
- ok: readiness.ok,
260
- exitCode: readiness.ok ? 0 : 1,
261
- projectRoot,
262
- sourceCloseoutRef,
263
- localOnly: true,
264
- artifactPath,
265
- skill: {
266
- id: "high_risk_execution",
267
- resultContractRef: HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
268
- artifactContractRef: EXTERNAL_EXECUTION_ARTIFACTS_CONFIG_REF,
269
- },
270
- outcome: imported.options.outcome,
271
- verifiedAt: imported.options.verifiedAt,
272
- summary: imported.options.summary,
273
- artifactRoots: externalExecutionArtifacts.artifactRoots,
274
- validations,
275
- readiness,
276
- doctor: {
277
- ok: doctorResult.ok,
278
- handoffReadiness: doctorResult.handoffReadiness,
279
- delegatedContracts: doctorResult.delegatedContracts,
280
- },
281
- nextAction: readiness.ok
282
- ? options.writeLocal
283
- ? `Write the high-risk ingest artifact to ${artifactPath}.`
284
- : "Review the ingest payload or write it locally with `--write-local`."
285
- : readiness.reason,
286
- };
287
- }
288
-
289
- export function formatHighRiskIngestPayload(payload) {
290
- const nextAction = payload.readiness.ok
291
- ? payload.nextAction.startsWith("Write the high-risk ingest artifact to ")
292
- ? localize(payload.nextAction, `将 high-risk ingest 产物写入 ${payload.artifactPath}。`)
293
- : localize(
294
- payload.nextAction,
295
- `检查 ingest payload,或使用 ${styleCommand("--write-local")} 将其写入本地。`,
296
- )
297
- : translateIngestReason(payload.nextAction);
298
- const lines = [
299
- styleHeading(`nimicoding ingest-high-risk-execution: ${payload.projectRoot}`),
300
- "",
301
- styleLabel(localize("Source:", "来源:")),
302
- ` - closeout_ref: ${payload.sourceCloseoutRef}`,
303
- ` - verified_at: ${payload.verifiedAt}`,
304
- "",
305
- styleLabel(localize("Result:", "结果:")),
306
- ` - ready: ${styleStatus(payload.readiness.ok ? "ready" : "needs_attention")}`,
307
- ` - local_only: ${payload.localOnly ? "true" : "false"}`,
308
- "",
309
- styleLabel(localize("Mechanical Validation:", "机械校验:")),
310
- ` - execution_packet: ${payload.validations.executionPacket.ok ? "ok" : "invalid"}`,
311
- ` - orchestration_state: ${payload.validations.orchestrationState.ok ? "ok" : "invalid"}`,
312
- ` - prompt: ${payload.validations.prompt.ok ? "ok" : "invalid"}`,
313
- ` - worker_output: ${payload.validations.workerOutput.ok ? "ok" : "invalid"}`,
314
- ` - evidence: ${payload.validations.evidence.every((entry) => entry.ok) ? "ok" : "invalid"}`,
315
- "",
316
- styleLabel(localize("Next:", "下一步:")),
317
- ` - ${nextAction}`,
318
- ];
319
-
320
- return `${lines.join("\n")}\n`;
321
- }