@nimiplatform/nimi-coding 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/adapters/README.md +25 -0
- package/adapters/claude/README.md +89 -0
- package/adapters/claude/profile.yaml +70 -0
- package/adapters/codex/README.md +53 -0
- package/adapters/codex/profile.yaml +78 -0
- package/adapters/oh-my-codex/README.md +185 -0
- package/adapters/oh-my-codex/profile.yaml +46 -0
- package/bin/nimicoding.mjs +6 -0
- package/cli/commands/admit-high-risk-decision.mjs +108 -0
- package/cli/commands/audit-sweep.mjs +341 -0
- package/cli/commands/blueprint-audit.mjs +91 -0
- package/cli/commands/clear.mjs +168 -0
- package/cli/commands/closeout.mjs +183 -0
- package/cli/commands/decide-high-risk-execution.mjs +124 -0
- package/cli/commands/doctor.mjs +53 -0
- package/cli/commands/generate-spec-derived-docs.mjs +131 -0
- package/cli/commands/handoff.mjs +123 -0
- package/cli/commands/ingest-high-risk-execution.mjs +95 -0
- package/cli/commands/review-high-risk-execution.mjs +95 -0
- package/cli/commands/start.mjs +717 -0
- package/cli/commands/topic-formatters.mjs +382 -0
- package/cli/commands/topic-goal.mjs +33 -0
- package/cli/commands/topic-options-shared.mjs +27 -0
- package/cli/commands/topic-options-workflow.mjs +767 -0
- package/cli/commands/topic-options.mjs +626 -0
- package/cli/commands/topic-runner.mjs +169 -0
- package/cli/commands/topic.mjs +795 -0
- package/cli/commands/validate-acceptance.mjs +5 -0
- package/cli/commands/validate-ai-governance.mjs +214 -0
- package/cli/commands/validate-execution-packet.mjs +5 -0
- package/cli/commands/validate-orchestration-state.mjs +5 -0
- package/cli/commands/validate-prompt.mjs +5 -0
- package/cli/commands/validate-spec-audit.mjs +27 -0
- package/cli/commands/validate-spec-governance.mjs +124 -0
- package/cli/commands/validate-spec-tree.mjs +27 -0
- package/cli/commands/validate-worker-output.mjs +5 -0
- package/cli/constants.mjs +489 -0
- package/cli/help.mjs +134 -0
- package/cli/index.mjs +103 -0
- package/cli/lib/adapter-profiles.mjs +403 -0
- package/cli/lib/audit-execution.mjs +52 -0
- package/cli/lib/audit-sweep-runtime/admissions.mjs +381 -0
- package/cli/lib/audit-sweep-runtime/audit-validity.mjs +333 -0
- package/cli/lib/audit-sweep-runtime/chunks.mjs +697 -0
- package/cli/lib/audit-sweep-runtime/closeout.mjs +144 -0
- package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +639 -0
- package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +515 -0
- package/cli/lib/audit-sweep-runtime/common.mjs +329 -0
- package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +172 -0
- package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +152 -0
- package/cli/lib/audit-sweep-runtime/format.mjs +57 -0
- package/cli/lib/audit-sweep-runtime/ingest.mjs +486 -0
- package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +198 -0
- package/cli/lib/audit-sweep-runtime/inventory.mjs +728 -0
- package/cli/lib/audit-sweep-runtime/ledger.mjs +315 -0
- package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +101 -0
- package/cli/lib/audit-sweep-runtime/remediation.mjs +349 -0
- package/cli/lib/audit-sweep-runtime/rerun.mjs +129 -0
- package/cli/lib/audit-sweep-runtime/risk-budget.mjs +300 -0
- package/cli/lib/audit-sweep-runtime/status.mjs +62 -0
- package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +215 -0
- package/cli/lib/audit-sweep-runtime/validators.mjs +758 -0
- package/cli/lib/audit-sweep.mjs +18 -0
- package/cli/lib/authority-convergence.mjs +309 -0
- package/cli/lib/blueprint-audit.mjs +370 -0
- package/cli/lib/bootstrap.mjs +228 -0
- package/cli/lib/closeout.mjs +623 -0
- package/cli/lib/codex-sdk-runner.mjs +76 -0
- package/cli/lib/contracts.mjs +180 -0
- package/cli/lib/doctor.mjs +18 -0
- package/cli/lib/entrypoints.mjs +274 -0
- package/cli/lib/external-execution.mjs +101 -0
- package/cli/lib/fs-helpers.mjs +33 -0
- package/cli/lib/handoff.mjs +785 -0
- package/cli/lib/high-risk-admission.mjs +442 -0
- package/cli/lib/high-risk-decision.mjs +324 -0
- package/cli/lib/high-risk-ingest.mjs +317 -0
- package/cli/lib/high-risk-review.mjs +263 -0
- package/cli/lib/internal/contracts-loaders.mjs +132 -0
- package/cli/lib/internal/contracts-parse-high-risk.mjs +131 -0
- package/cli/lib/internal/contracts-parse.mjs +457 -0
- package/cli/lib/internal/contracts-validators.mjs +398 -0
- package/cli/lib/internal/doctor-bootstrap-surface.mjs +359 -0
- package/cli/lib/internal/doctor-delegated-surface.mjs +256 -0
- package/cli/lib/internal/doctor-finalize.mjs +385 -0
- package/cli/lib/internal/doctor-format.mjs +286 -0
- package/cli/lib/internal/doctor-inspectors.mjs +294 -0
- package/cli/lib/internal/doctor-state.mjs +205 -0
- package/cli/lib/internal/governance/ai/ai-context-budget-core.mjs +315 -0
- package/cli/lib/internal/governance/ai/ai-structure-budget-core.mjs +358 -0
- package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +155 -0
- package/cli/lib/internal/governance/ai/check-high-risk-doc-metadata-core.mjs +173 -0
- package/cli/lib/internal/governance/config.mjs +150 -0
- package/cli/lib/internal/governance/runner.mjs +35 -0
- package/cli/lib/internal/governance/shared/read-yaml-with-fragments.mjs +49 -0
- package/cli/lib/internal/validators-artifacts.mjs +515 -0
- package/cli/lib/internal/validators-shared.mjs +28 -0
- package/cli/lib/internal/validators-spec-helpers.mjs +186 -0
- package/cli/lib/internal/validators-spec.mjs +410 -0
- package/cli/lib/shared.mjs +83 -0
- package/cli/lib/topic-draft-packets.mjs +48 -0
- package/cli/lib/topic-goal.mjs +361 -0
- package/cli/lib/topic-runner.mjs +772 -0
- package/cli/lib/topic.mjs +93 -0
- package/cli/lib/ui.mjs +178 -0
- package/cli/lib/validators.mjs +78 -0
- package/cli/lib/value-helpers.mjs +24 -0
- package/cli/lib/yaml-helpers.mjs +133 -0
- package/cli/nimicoding.mjs +1 -0
- package/cli/seeds/bootstrap.mjs +47 -0
- package/config/audit-execution-artifacts.yaml +20 -0
- package/config/bootstrap.yaml +6 -0
- package/config/external-execution-artifacts.yaml +16 -0
- package/config/host-adapter.yaml +30 -0
- package/config/host-profile.yaml +29 -0
- package/config/installer-evidence.yaml +31 -0
- package/config/skill-installer.yaml +23 -0
- package/config/skill-manifest.yaml +46 -0
- package/config/skills.yaml +30 -0
- package/config/spec-generation-inputs.yaml +25 -0
- package/contracts/acceptance.schema.yaml +16 -0
- package/contracts/admission-checklist.schema.yaml +15 -0
- package/contracts/audit-chunk.schema.yaml +110 -0
- package/contracts/audit-closeout.schema.yaml +51 -0
- package/contracts/audit-finding.schema.yaml +61 -0
- package/contracts/audit-ledger.schema.yaml +138 -0
- package/contracts/audit-plan.schema.yaml +123 -0
- package/contracts/audit-remediation-map.schema.yaml +51 -0
- package/contracts/audit-rerun.schema.yaml +31 -0
- package/contracts/audit-sweep-result.yaml +49 -0
- package/contracts/authority-convergence-audit.schema.yaml +19 -0
- package/contracts/closeout.schema.yaml +25 -0
- package/contracts/decision-review.schema.yaml +16 -0
- package/contracts/doc-spec-audit-result.yaml +19 -0
- package/contracts/execution-packet.schema.yaml +49 -0
- package/contracts/external-host-compatibility.yaml +22 -0
- package/contracts/forbidden-shortcuts.catalog.yaml +23 -0
- package/contracts/high-risk-admission.schema.yaml +23 -0
- package/contracts/high-risk-execution-result.yaml +20 -0
- package/contracts/orchestration-state.schema.yaml +41 -0
- package/contracts/overflow-continuation.schema.yaml +12 -0
- package/contracts/packet.schema.yaml +30 -0
- package/contracts/pending-note.schema.yaml +17 -0
- package/contracts/prompt.schema.yaml +12 -0
- package/contracts/remediation.schema.yaml +16 -0
- package/contracts/result.schema.yaml +24 -0
- package/contracts/spec-generation-audit.schema.yaml +31 -0
- package/contracts/spec-generation-inputs.schema.yaml +39 -0
- package/contracts/spec-reconstruction-result.yaml +37 -0
- package/contracts/topic-goal.schema.yaml +78 -0
- package/contracts/topic-run-ledger.schema.yaml +72 -0
- package/contracts/topic-step-decision.schema.yaml +45 -0
- package/contracts/topic.schema.yaml +65 -0
- package/contracts/true-close.schema.yaml +15 -0
- package/contracts/wave.schema.yaml +29 -0
- package/contracts/worker-output.schema.yaml +15 -0
- package/methodology/audit-sweep-p0p1-recall.yaml +45 -0
- package/methodology/authority-convergence-policy.yaml +42 -0
- package/methodology/core.yaml +25 -0
- package/methodology/four-closure-policy.yaml +28 -0
- package/methodology/overflow-continuation-policy.yaml +14 -0
- package/methodology/role-separation-policy.yaml +28 -0
- package/methodology/skill-exchange-projection.yaml +114 -0
- package/methodology/skill-handoff.yaml +34 -0
- package/methodology/skill-installer-result.yaml +27 -0
- package/methodology/skill-installer-summary-projection.yaml +181 -0
- package/methodology/skill-runtime.yaml +23 -0
- package/methodology/spec-reconstruction.yaml +63 -0
- package/methodology/spec-target-truth-profile.yaml +53 -0
- package/methodology/topic-lifecycle-report.yaml +144 -0
- package/methodology/topic-lifecycle.yaml +37 -0
- package/methodology/topic-naming-ontology.yaml +21 -0
- package/methodology/topic-ontology.yaml +38 -0
- package/methodology/topic-validation-policy.yaml +9 -0
- package/methodology/wave-dag-policy.yaml +14 -0
- package/package.json +50 -0
- package/spec/_meta/command-gating-matrix.yaml +110 -0
- package/spec/_meta/generate-drift-migration-checklist.yaml +155 -0
- package/spec/_meta/governance-routing-cutover-checklist.yaml +35 -0
- package/spec/_meta/phase2-impacted-surface-matrix.yaml +44 -0
- package/spec/_meta/spec-authority-cutover-readiness.yaml +104 -0
- package/spec/_meta/spec-tree-model.yaml +72 -0
- package/spec/bootstrap-state.yaml +99 -0
- package/spec/product-scope.yaml +56 -0
|
@@ -0,0 +1,324 @@
|
|
|
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 extractAcceptanceDisposition(text) {
|
|
154
|
+
const match = text.match(/Disposition:\s*(\w+)/i);
|
|
155
|
+
return match ? match[1].toLowerCase() : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function evaluateDecisionReadiness(doctorResult, acceptanceReport) {
|
|
159
|
+
if (!doctorResult.ok || !doctorResult.handoffReadiness.ok) {
|
|
160
|
+
return {
|
|
161
|
+
ok: false,
|
|
162
|
+
reason: "Bootstrap or handoff validation is failing; repair doctor errors before recording a manager decision",
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (doctorResult.lifecycleState?.treeState !== "canonical_tree_ready" || doctorResult.canonicalTree?.requiredFilesValid !== true) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
reason: "High-risk decision projection requires canonical_tree_ready with declared canonical files present",
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!acceptanceReport.ok) {
|
|
174
|
+
return {
|
|
175
|
+
ok: false,
|
|
176
|
+
reason: "Acceptance artifact failed mechanical validation",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
ok: true,
|
|
182
|
+
reason: "Manager-owned local decision record is ready",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function buildHighRiskDecisionPayload(projectRoot, options) {
|
|
187
|
+
const imported = await loadImportedReviewPayload(projectRoot, options.fromPath);
|
|
188
|
+
if (!imported.ok) {
|
|
189
|
+
return {
|
|
190
|
+
ok: false,
|
|
191
|
+
exitCode: 2,
|
|
192
|
+
inputError: true,
|
|
193
|
+
error: imported.error,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const inputValidation = validateImportedReviewPayload(imported.payload);
|
|
198
|
+
if (!inputValidation.ok) {
|
|
199
|
+
return {
|
|
200
|
+
ok: false,
|
|
201
|
+
exitCode: 2,
|
|
202
|
+
inputError: true,
|
|
203
|
+
error: `${localize(
|
|
204
|
+
`nimicoding decide-high-risk-execution refused: ${inputValidation.reason}.`,
|
|
205
|
+
`nimicoding decide-high-risk-execution 已拒绝:${translateDecisionReason(inputValidation.reason)}。`,
|
|
206
|
+
)}\n`,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!isIsoUtcTimestamp(options.verifiedAt)) {
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
exitCode: 2,
|
|
214
|
+
inputError: true,
|
|
215
|
+
error: `${localize(
|
|
216
|
+
"nimicoding decide-high-risk-execution refused: --verified-at must be an ISO-8601 UTC timestamp.",
|
|
217
|
+
"nimicoding decide-high-risk-execution 已拒绝:`--verified-at` 必须是 ISO-8601 UTC 时间戳。",
|
|
218
|
+
)}\n`,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const acceptanceRef = path.resolve(projectRoot, options.acceptancePath);
|
|
223
|
+
const acceptanceText = await readTextIfFile(acceptanceRef);
|
|
224
|
+
if (acceptanceText === null) {
|
|
225
|
+
return {
|
|
226
|
+
ok: false,
|
|
227
|
+
exitCode: 2,
|
|
228
|
+
inputError: true,
|
|
229
|
+
error: `${localize(
|
|
230
|
+
`nimicoding decide-high-risk-execution refused: cannot read acceptance artifact at ${acceptanceRef}.`,
|
|
231
|
+
`nimicoding decide-high-risk-execution 已拒绝:无法读取 ${acceptanceRef} 处的 acceptance 产物。`,
|
|
232
|
+
)}\n`,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const acceptanceReport = await validateAcceptance(acceptanceRef);
|
|
237
|
+
const disposition = extractAcceptanceDisposition(acceptanceText);
|
|
238
|
+
if (!disposition) {
|
|
239
|
+
return {
|
|
240
|
+
ok: false,
|
|
241
|
+
exitCode: 2,
|
|
242
|
+
inputError: true,
|
|
243
|
+
error: `${localize(
|
|
244
|
+
"nimicoding decide-high-risk-execution refused: acceptance artifact must declare a Disposition line.",
|
|
245
|
+
"nimicoding decide-high-risk-execution 已拒绝:acceptance 产物必须声明一行 `Disposition`。",
|
|
246
|
+
)}\n`,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const doctorResult = await inspectDoctorState(projectRoot);
|
|
251
|
+
const readiness = evaluateDecisionReadiness(doctorResult, acceptanceReport);
|
|
252
|
+
const artifactPath = path.join(
|
|
253
|
+
projectRoot,
|
|
254
|
+
".nimi",
|
|
255
|
+
"local",
|
|
256
|
+
"handoff-results",
|
|
257
|
+
"high_risk_execution.decision.json",
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
contractVersion: HIGH_RISK_DECISION_PAYLOAD_CONTRACT_VERSION,
|
|
262
|
+
ok: readiness.ok,
|
|
263
|
+
exitCode: readiness.ok ? 0 : 1,
|
|
264
|
+
projectRoot,
|
|
265
|
+
sourceReviewRef: imported.path,
|
|
266
|
+
localOnly: true,
|
|
267
|
+
artifactPath,
|
|
268
|
+
skill: {
|
|
269
|
+
id: "high_risk_execution",
|
|
270
|
+
resultContractRef: HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
|
|
271
|
+
},
|
|
272
|
+
verifiedAt: options.verifiedAt,
|
|
273
|
+
managerReviewOwner: imported.payload.managerReviewOwner ?? doctorResult.delegatedContracts.semanticReviewOwner,
|
|
274
|
+
decisionStatus: readiness.ok ? "manager_decision_recorded" : "blocked",
|
|
275
|
+
acceptanceRef,
|
|
276
|
+
acceptanceDisposition: disposition,
|
|
277
|
+
acceptanceValidation: {
|
|
278
|
+
ok: acceptanceReport.ok,
|
|
279
|
+
refusal: acceptanceReport.refusal ?? null,
|
|
280
|
+
errors: acceptanceReport.errors ?? [],
|
|
281
|
+
warnings: acceptanceReport.warnings ?? [],
|
|
282
|
+
},
|
|
283
|
+
reviewStatus: imported.payload.reviewStatus,
|
|
284
|
+
summary: imported.payload.summary,
|
|
285
|
+
attachmentRefs: imported.payload.attachmentRefs,
|
|
286
|
+
readiness,
|
|
287
|
+
doctor: {
|
|
288
|
+
ok: doctorResult.ok,
|
|
289
|
+
handoffReadiness: doctorResult.handoffReadiness,
|
|
290
|
+
delegatedContracts: doctorResult.delegatedContracts,
|
|
291
|
+
},
|
|
292
|
+
nextAction: readiness.ok
|
|
293
|
+
? options.writeLocal
|
|
294
|
+
? `Write the high-risk decision artifact to ${artifactPath}.`
|
|
295
|
+
: "Review the local decision payload or write it locally with `--write-local`."
|
|
296
|
+
: readiness.reason,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function formatHighRiskDecisionPayload(payload) {
|
|
301
|
+
const nextAction = payload.readiness.ok
|
|
302
|
+
? payload.nextAction.startsWith("Write the high-risk decision artifact to ")
|
|
303
|
+
? localize(payload.nextAction, `将 high-risk decision 产物写入 ${payload.artifactPath}。`)
|
|
304
|
+
: localize(
|
|
305
|
+
payload.nextAction,
|
|
306
|
+
`检查本地 decision payload,或使用 ${styleCommand("--write-local")} 将其写入本地。`,
|
|
307
|
+
)
|
|
308
|
+
: translateDecisionReason(payload.nextAction);
|
|
309
|
+
const lines = [
|
|
310
|
+
styleHeading(`nimicoding decide-high-risk-execution: ${payload.projectRoot}`),
|
|
311
|
+
"",
|
|
312
|
+
styleLabel(localize("Decision:", "决策:")),
|
|
313
|
+
` - decision_status: ${payload.decisionStatus}`,
|
|
314
|
+
` - disposition: ${payload.acceptanceDisposition}`,
|
|
315
|
+
` - manager_review_owner: ${payload.managerReviewOwner ?? localize("unknown", "未知")}`,
|
|
316
|
+
` - ready: ${styleStatus(payload.readiness.ok ? "ready" : "needs_attention")}`,
|
|
317
|
+
` - local_only: ${payload.localOnly ? "true" : "false"}`,
|
|
318
|
+
"",
|
|
319
|
+
styleLabel(localize("Next:", "下一步:")),
|
|
320
|
+
` - ${nextAction}`,
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
return `${lines.join("\n")}\n`;
|
|
324
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
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
|
+
if (doctorResult.lifecycleState?.treeState !== "canonical_tree_ready" || doctorResult.canonicalTree?.requiredFilesValid !== true) {
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
reason: "High-risk ingest requires canonical_tree_ready with declared canonical files present",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const mechanicalChecksOk = validations.executionPacket.ok
|
|
160
|
+
&& validations.orchestrationState.ok
|
|
161
|
+
&& validations.prompt.ok
|
|
162
|
+
&& validations.workerOutput.ok
|
|
163
|
+
&& validations.evidence.every((entry) => entry.ok);
|
|
164
|
+
|
|
165
|
+
if (!mechanicalChecksOk) {
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
reason: "One or more external execution candidate artifacts failed mechanical validation",
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
ok: true,
|
|
174
|
+
reason: "External execution candidate artifacts passed bounded ingest validation",
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function buildHighRiskIngestPayload(projectRoot, fromPath, options = {}) {
|
|
179
|
+
const sourceCloseoutRef = path.resolve(projectRoot, fromPath);
|
|
180
|
+
const imported = await loadImportedCloseoutOptions(projectRoot, fromPath);
|
|
181
|
+
if (!imported.ok) {
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
exitCode: 2,
|
|
185
|
+
inputError: true,
|
|
186
|
+
error: imported.error,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const highRiskContract = await loadHighRiskExecutionContract(projectRoot);
|
|
191
|
+
if (!highRiskContract.ok) {
|
|
192
|
+
return {
|
|
193
|
+
ok: false,
|
|
194
|
+
exitCode: 2,
|
|
195
|
+
inputError: true,
|
|
196
|
+
error: `${localize(
|
|
197
|
+
"nimicoding ingest-high-risk-execution refused: high_risk_execution result contract is missing or malformed.",
|
|
198
|
+
"nimicoding ingest-high-risk-execution 已拒绝:high_risk_execution 结果契约缺失或格式错误。",
|
|
199
|
+
)}\n`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const externalExecutionArtifacts = await loadExternalExecutionArtifactsConfig(projectRoot);
|
|
204
|
+
if (!externalExecutionArtifacts.ok) {
|
|
205
|
+
return {
|
|
206
|
+
ok: false,
|
|
207
|
+
exitCode: 2,
|
|
208
|
+
inputError: true,
|
|
209
|
+
error: `${localize(
|
|
210
|
+
"nimicoding ingest-high-risk-execution refused: external execution artifacts config is missing or malformed.",
|
|
211
|
+
"nimicoding ingest-high-risk-execution 已拒绝:external execution artifacts 配置缺失或格式错误。",
|
|
212
|
+
)}\n`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const summaryValidation = validateHighRiskExecutionSummary(
|
|
217
|
+
imported.options.summary,
|
|
218
|
+
highRiskContract,
|
|
219
|
+
imported.options.verifiedAt,
|
|
220
|
+
);
|
|
221
|
+
const rootsValidation = imported.options.summary
|
|
222
|
+
? validateHighRiskExecutionArtifactRefs(imported.options.summary, externalExecutionArtifacts)
|
|
223
|
+
: { ok: true };
|
|
224
|
+
const ingestInputValidation = validateHighRiskIngestInput(
|
|
225
|
+
imported.options,
|
|
226
|
+
summaryValidation,
|
|
227
|
+
rootsValidation,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
if (!ingestInputValidation.ok) {
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
exitCode: 2,
|
|
234
|
+
inputError: true,
|
|
235
|
+
error: `${localize(
|
|
236
|
+
`nimicoding ingest-high-risk-execution refused: ${ingestInputValidation.reason}.`,
|
|
237
|
+
`nimicoding ingest-high-risk-execution 已拒绝:${translateIngestReason(ingestInputValidation.reason)}。`,
|
|
238
|
+
)}\n`,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const validations = await validateReferencedArtifacts(projectRoot, imported.options.summary);
|
|
243
|
+
const doctorResult = await inspectDoctorState(projectRoot);
|
|
244
|
+
const readiness = evaluateHighRiskIngestReadiness(doctorResult, validations);
|
|
245
|
+
const artifactPath = path.join(
|
|
246
|
+
projectRoot,
|
|
247
|
+
".nimi",
|
|
248
|
+
"local",
|
|
249
|
+
"handoff-results",
|
|
250
|
+
"high_risk_execution.ingest.json",
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
contractVersion: HIGH_RISK_INGEST_PAYLOAD_CONTRACT_VERSION,
|
|
255
|
+
ok: readiness.ok,
|
|
256
|
+
exitCode: readiness.ok ? 0 : 1,
|
|
257
|
+
projectRoot,
|
|
258
|
+
sourceCloseoutRef,
|
|
259
|
+
localOnly: true,
|
|
260
|
+
artifactPath,
|
|
261
|
+
skill: {
|
|
262
|
+
id: "high_risk_execution",
|
|
263
|
+
resultContractRef: HIGH_RISK_EXECUTION_RESULT_CONTRACT_REF,
|
|
264
|
+
artifactContractRef: EXTERNAL_EXECUTION_ARTIFACTS_CONFIG_REF,
|
|
265
|
+
},
|
|
266
|
+
outcome: imported.options.outcome,
|
|
267
|
+
verifiedAt: imported.options.verifiedAt,
|
|
268
|
+
summary: imported.options.summary,
|
|
269
|
+
artifactRoots: externalExecutionArtifacts.artifactRoots,
|
|
270
|
+
validations,
|
|
271
|
+
readiness,
|
|
272
|
+
doctor: {
|
|
273
|
+
ok: doctorResult.ok,
|
|
274
|
+
handoffReadiness: doctorResult.handoffReadiness,
|
|
275
|
+
delegatedContracts: doctorResult.delegatedContracts,
|
|
276
|
+
},
|
|
277
|
+
nextAction: readiness.ok
|
|
278
|
+
? options.writeLocal
|
|
279
|
+
? `Write the high-risk ingest artifact to ${artifactPath}.`
|
|
280
|
+
: "Review the ingest payload or write it locally with `--write-local`."
|
|
281
|
+
: readiness.reason,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function formatHighRiskIngestPayload(payload) {
|
|
286
|
+
const nextAction = payload.readiness.ok
|
|
287
|
+
? payload.nextAction.startsWith("Write the high-risk ingest artifact to ")
|
|
288
|
+
? localize(payload.nextAction, `将 high-risk ingest 产物写入 ${payload.artifactPath}。`)
|
|
289
|
+
: localize(
|
|
290
|
+
payload.nextAction,
|
|
291
|
+
`检查 ingest payload,或使用 ${styleCommand("--write-local")} 将其写入本地。`,
|
|
292
|
+
)
|
|
293
|
+
: translateIngestReason(payload.nextAction);
|
|
294
|
+
const lines = [
|
|
295
|
+
styleHeading(`nimicoding ingest-high-risk-execution: ${payload.projectRoot}`),
|
|
296
|
+
"",
|
|
297
|
+
styleLabel(localize("Source:", "来源:")),
|
|
298
|
+
` - closeout_ref: ${payload.sourceCloseoutRef}`,
|
|
299
|
+
` - verified_at: ${payload.verifiedAt}`,
|
|
300
|
+
"",
|
|
301
|
+
styleLabel(localize("Result:", "结果:")),
|
|
302
|
+
` - ready: ${styleStatus(payload.readiness.ok ? "ready" : "needs_attention")}`,
|
|
303
|
+
` - local_only: ${payload.localOnly ? "true" : "false"}`,
|
|
304
|
+
"",
|
|
305
|
+
styleLabel(localize("Mechanical Validation:", "机械校验:")),
|
|
306
|
+
` - execution_packet: ${payload.validations.executionPacket.ok ? "ok" : "invalid"}`,
|
|
307
|
+
` - orchestration_state: ${payload.validations.orchestrationState.ok ? "ok" : "invalid"}`,
|
|
308
|
+
` - prompt: ${payload.validations.prompt.ok ? "ok" : "invalid"}`,
|
|
309
|
+
` - worker_output: ${payload.validations.workerOutput.ok ? "ok" : "invalid"}`,
|
|
310
|
+
` - evidence: ${payload.validations.evidence.every((entry) => entry.ok) ? "ok" : "invalid"}`,
|
|
311
|
+
"",
|
|
312
|
+
styleLabel(localize("Next:", "下一步:")),
|
|
313
|
+
` - ${nextAction}`,
|
|
314
|
+
];
|
|
315
|
+
|
|
316
|
+
return `${lines.join("\n")}\n`;
|
|
317
|
+
}
|