@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,697 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
appendRunEvent,
|
|
7
|
+
chunkRef,
|
|
8
|
+
ensureIsoTimestamp,
|
|
9
|
+
inputError,
|
|
10
|
+
loadChunk,
|
|
11
|
+
loadPlan,
|
|
12
|
+
packetRef,
|
|
13
|
+
safeSweepId,
|
|
14
|
+
withAuditSweepMutationLock,
|
|
15
|
+
writeYamlRef,
|
|
16
|
+
} from "./common.mjs";
|
|
17
|
+
import { buildP0P1RecallProfile, criteriaEnableP0P1Recall } from "./p0p1-profile.mjs";
|
|
18
|
+
import { budgetBlockForChunk } from "./risk-budget.mjs";
|
|
19
|
+
|
|
20
|
+
const HIGH_RISK_TERMS = new Set([
|
|
21
|
+
"auth",
|
|
22
|
+
"authn",
|
|
23
|
+
"authz",
|
|
24
|
+
"jwt",
|
|
25
|
+
"token",
|
|
26
|
+
"session",
|
|
27
|
+
"security",
|
|
28
|
+
"permission",
|
|
29
|
+
"capability",
|
|
30
|
+
"delegation",
|
|
31
|
+
"approval",
|
|
32
|
+
"boundary",
|
|
33
|
+
"bridge",
|
|
34
|
+
"ipc",
|
|
35
|
+
"runtime",
|
|
36
|
+
"sdk",
|
|
37
|
+
"hook",
|
|
38
|
+
"destructive",
|
|
39
|
+
"provider",
|
|
40
|
+
"model",
|
|
41
|
+
"secret",
|
|
42
|
+
"revocation",
|
|
43
|
+
"firewall",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
const GENERATED_TERMS = new Set([
|
|
47
|
+
"generated",
|
|
48
|
+
"codegen",
|
|
49
|
+
"table",
|
|
50
|
+
"tables",
|
|
51
|
+
"index",
|
|
52
|
+
"registry",
|
|
53
|
+
"manifest",
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const STOP_WORDS = new Set([
|
|
57
|
+
"the",
|
|
58
|
+
"and",
|
|
59
|
+
"for",
|
|
60
|
+
"with",
|
|
61
|
+
"from",
|
|
62
|
+
"into",
|
|
63
|
+
"contract",
|
|
64
|
+
"kernel",
|
|
65
|
+
"spec",
|
|
66
|
+
"nimi",
|
|
67
|
+
"desktop",
|
|
68
|
+
"runtime",
|
|
69
|
+
"source",
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
export function updatePlanChunk(plan, chunkId, patch) {
|
|
73
|
+
return {
|
|
74
|
+
...plan,
|
|
75
|
+
chunks: plan.chunks.map((chunk) => chunk.chunk_id === chunkId ? { ...chunk, ...patch } : chunk),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function uniqueSorted(values) {
|
|
80
|
+
return [...new Set((values ?? []).filter((value) => typeof value === "string" && value.trim()).map((value) => value.replace(/\\/g, "/")))].sort();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function sha256Json(value) {
|
|
84
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function tokenize(value) {
|
|
88
|
+
return String(value ?? "")
|
|
89
|
+
.toLowerCase()
|
|
90
|
+
.split(/[^a-z0-9]+/u)
|
|
91
|
+
.filter((token) => token.length >= 3 && !STOP_WORDS.has(token));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function readProjectFileText(projectRoot, fileRef, byteLimit = 65536) {
|
|
95
|
+
if (!projectRoot || typeof fileRef !== "string") {
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
const absolutePath = path.resolve(projectRoot, fileRef);
|
|
99
|
+
if (!absolutePath.startsWith(path.resolve(projectRoot) + path.sep) && absolutePath !== path.resolve(projectRoot)) {
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
if (!existsSync(absolutePath)) {
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return readFileSync(absolutePath, "utf8").slice(0, byteLimit);
|
|
107
|
+
} catch {
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function adaptiveDepthForChunk(chunk) {
|
|
113
|
+
const surface = [
|
|
114
|
+
chunk.chunk_id,
|
|
115
|
+
chunk.owner_domain,
|
|
116
|
+
chunk.spec_surface,
|
|
117
|
+
...(chunk.files ?? []),
|
|
118
|
+
...(chunk.authority_refs ?? []),
|
|
119
|
+
].join(" ").toLowerCase();
|
|
120
|
+
const tokens = new Set(tokenize(surface));
|
|
121
|
+
const generated = [...GENERATED_TERMS].some((term) => tokens.has(term) || surface.includes(`/${term}`) || surface.includes(`-${term}`));
|
|
122
|
+
if (generated) {
|
|
123
|
+
return {
|
|
124
|
+
level: "shallow",
|
|
125
|
+
selected_limit: 16,
|
|
126
|
+
reason: "generated_table_index_or_registry_surface",
|
|
127
|
+
codex_posture: "audit authority invariants against a compact representative implementation slice; do not expand to the full generated inventory unless a P0/P1 signal requires it",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const highRisk = [...HIGH_RISK_TERMS].some((term) => tokens.has(term))
|
|
131
|
+
|| ["runtime", "sdk", "security", "boundary"].includes(chunk.owner_domain);
|
|
132
|
+
if (highRisk) {
|
|
133
|
+
return {
|
|
134
|
+
level: "deep",
|
|
135
|
+
selected_limit: 96,
|
|
136
|
+
reason: "high_risk_runtime_sdk_security_boundary_or_capability_surface",
|
|
137
|
+
codex_posture: "inspect the selected implementation slice deeply for P0/P1 recall before deciding no-finding",
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
level: "normal",
|
|
142
|
+
selected_limit: 48,
|
|
143
|
+
reason: "ordinary_spec_authority_surface",
|
|
144
|
+
codex_posture: "inspect the selected implementation slice semantically with normal depth",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function relativeImportTargets(sourceRef, sourceText, inventorySet) {
|
|
149
|
+
const targets = [];
|
|
150
|
+
const imports = [
|
|
151
|
+
...sourceText.matchAll(/\b(?:import|export)\s+(?:[^'"`]*?\s+from\s+)?["'`]([^"'`]+)["'`]/gu),
|
|
152
|
+
...sourceText.matchAll(/\brequire\(["'`]([^"'`]+)["'`]\)/gu),
|
|
153
|
+
].map((match) => match[1]);
|
|
154
|
+
const sourceDir = path.posix.dirname(sourceRef);
|
|
155
|
+
const extensions = ["", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".go", ".rs", ".json", ".yaml", ".yml"];
|
|
156
|
+
for (const specifier of imports) {
|
|
157
|
+
if (typeof specifier !== "string" || !specifier.startsWith(".")) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const base = path.posix.normalize(path.posix.join(sourceDir, specifier));
|
|
161
|
+
const candidates = [
|
|
162
|
+
...extensions.map((extension) => `${base}${extension}`),
|
|
163
|
+
...extensions.filter(Boolean).map((extension) => `${base}/index${extension}`),
|
|
164
|
+
];
|
|
165
|
+
const target = candidates.find((candidate) => inventorySet.has(candidate));
|
|
166
|
+
if (target) {
|
|
167
|
+
targets.push(target);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return uniqueSorted(targets);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function buildRetrievalPrepass({ projectRoot, chunk, depth }) {
|
|
174
|
+
const evidenceInventory = uniqueSorted(chunk.evidence_inventory ?? []);
|
|
175
|
+
const authorityRefs = uniqueSorted(chunk.authority_refs ?? chunk.files ?? []);
|
|
176
|
+
if (evidenceInventory.length === 0) {
|
|
177
|
+
return {
|
|
178
|
+
mode: "compact_selected_slice",
|
|
179
|
+
selected_implementation_refs: [],
|
|
180
|
+
selected_count: 0,
|
|
181
|
+
full_inventory_count: 0,
|
|
182
|
+
omitted_inventory_count: 0,
|
|
183
|
+
omitted_inventory_sha256: sha256Json([]),
|
|
184
|
+
omitted_inventory_canonicalization: "sorted_json_array_of_project_relative_refs",
|
|
185
|
+
selection_signals: ["empty_evidence_inventory"],
|
|
186
|
+
import_graph_edges: [],
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const authorityText = [
|
|
191
|
+
chunk.chunk_id,
|
|
192
|
+
chunk.owner_domain,
|
|
193
|
+
chunk.spec_surface,
|
|
194
|
+
...authorityRefs,
|
|
195
|
+
...authorityRefs.map((ref) => readProjectFileText(projectRoot, ref)),
|
|
196
|
+
].join("\n");
|
|
197
|
+
const authorityTokens = new Set(tokenize(authorityText));
|
|
198
|
+
const ownerTokens = new Set(tokenize([chunk.owner_domain, chunk.spec_surface, chunk.chunk_id].join(" ")));
|
|
199
|
+
const inventorySet = new Set(evidenceInventory);
|
|
200
|
+
const scores = new Map(evidenceInventory.map((ref) => [ref, {
|
|
201
|
+
ref,
|
|
202
|
+
score: 0,
|
|
203
|
+
signals: [],
|
|
204
|
+
}]));
|
|
205
|
+
|
|
206
|
+
for (const ref of evidenceInventory) {
|
|
207
|
+
const entry = scores.get(ref);
|
|
208
|
+
const refText = ref.toLowerCase();
|
|
209
|
+
const refTokens = new Set(tokenize(ref));
|
|
210
|
+
const tokenHits = [...authorityTokens].filter((token) => refTokens.has(token) || refText.includes(token));
|
|
211
|
+
if (tokenHits.length > 0) {
|
|
212
|
+
entry.score += Math.min(24, tokenHits.length * 4);
|
|
213
|
+
entry.signals.push(`authority_keywords:${tokenHits.slice(0, 8).join(",")}`);
|
|
214
|
+
}
|
|
215
|
+
const ownerHits = [...ownerTokens].filter((token) => refTokens.has(token) || refText.includes(token));
|
|
216
|
+
if (ownerHits.length > 0) {
|
|
217
|
+
entry.score += Math.min(9, ownerHits.length * 3);
|
|
218
|
+
entry.signals.push(`owner_domain:${ownerHits.slice(0, 4).join(",")}`);
|
|
219
|
+
}
|
|
220
|
+
if (/(^|[/_.-])(test|tests|spec|e2e)([/_.-]|$)/u.test(refText) || /(_test|\.test|\.spec)\.[a-z0-9]+$/u.test(refText)) {
|
|
221
|
+
entry.score += 3;
|
|
222
|
+
entry.signals.push("test_or_spec_file");
|
|
223
|
+
}
|
|
224
|
+
if (/(^|[/_.-])(index|registry|table|tables|generated|codegen)([/_.-]|$)/u.test(refText)) {
|
|
225
|
+
entry.score += depth.level === "shallow" ? 2 : -2;
|
|
226
|
+
entry.signals.push("generated_table_index_surface");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const importGraphEdges = [];
|
|
231
|
+
const scanLimit = Math.min(evidenceInventory.length, depth.level === "deep" ? 240 : depth.level === "normal" ? 120 : 60);
|
|
232
|
+
for (const ref of evidenceInventory.slice(0, scanLimit)) {
|
|
233
|
+
const text = readProjectFileText(projectRoot, ref, 32768);
|
|
234
|
+
if (!text) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const targets = relativeImportTargets(ref, text, inventorySet);
|
|
238
|
+
for (const target of targets) {
|
|
239
|
+
importGraphEdges.push({ from: ref, to: target });
|
|
240
|
+
scores.get(ref).score += 2;
|
|
241
|
+
scores.get(ref).signals.push("import_graph_source");
|
|
242
|
+
scores.get(target).score += 3;
|
|
243
|
+
scores.get(target).signals.push("import_graph_target");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const ranked = [...scores.values()].sort((left, right) => {
|
|
248
|
+
if (right.score !== left.score) {
|
|
249
|
+
return right.score - left.score;
|
|
250
|
+
}
|
|
251
|
+
return left.ref.localeCompare(right.ref);
|
|
252
|
+
});
|
|
253
|
+
const initialSelected = ranked.slice(0, Math.min(depth.selected_limit, ranked.length)).map((entry) => entry.ref);
|
|
254
|
+
const selectedSet = new Set(initialSelected);
|
|
255
|
+
for (const selected of initialSelected) {
|
|
256
|
+
const selectedDir = path.posix.dirname(selected);
|
|
257
|
+
const selectedStem = path.posix.basename(selected).replace(/(\.test|\.spec|_test)?\.[^.]+$/u, "");
|
|
258
|
+
for (const ref of evidenceInventory) {
|
|
259
|
+
if (selectedSet.size >= depth.selected_limit) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (selectedSet.has(ref)) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const sameDir = path.posix.dirname(ref) === selectedDir;
|
|
266
|
+
const sameStem = path.posix.basename(ref).includes(selectedStem);
|
|
267
|
+
const isNearbyTest = sameDir && (sameStem || /(\.test|\.spec|_test)\./u.test(ref));
|
|
268
|
+
if (isNearbyTest) {
|
|
269
|
+
selectedSet.add(ref);
|
|
270
|
+
scores.get(ref).signals.push("nearby_file_or_test");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const selected = uniqueSorted([...selectedSet]);
|
|
275
|
+
const selectedSignals = selected.map((ref) => ({
|
|
276
|
+
ref,
|
|
277
|
+
score: scores.get(ref)?.score ?? 0,
|
|
278
|
+
signals: uniqueSorted(scores.get(ref)?.signals ?? []).slice(0, 8),
|
|
279
|
+
}));
|
|
280
|
+
return {
|
|
281
|
+
mode: "compact_selected_slice",
|
|
282
|
+
selected_implementation_refs: selected,
|
|
283
|
+
selected_count: selected.length,
|
|
284
|
+
full_inventory_count: evidenceInventory.length,
|
|
285
|
+
omitted_inventory_count: Math.max(0, evidenceInventory.length - selected.length),
|
|
286
|
+
omitted_inventory_sha256: sha256Json(evidenceInventory),
|
|
287
|
+
omitted_inventory_canonicalization: "sorted_json_array_of_project_relative_refs",
|
|
288
|
+
selection_signals: [
|
|
289
|
+
"authority_keywords",
|
|
290
|
+
"owner_domain",
|
|
291
|
+
"import_graph",
|
|
292
|
+
"tests",
|
|
293
|
+
"nearby_files",
|
|
294
|
+
],
|
|
295
|
+
selected_ref_signals: selectedSignals,
|
|
296
|
+
import_graph_edges: importGraphEdges.slice(0, 200),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function buildAuditorPacket(sweepId, chunk, auditor, dispatchedAt, plan, options = {}) {
|
|
301
|
+
const specAuthority = chunk.planning_basis === "spec_authority";
|
|
302
|
+
const p0p1RecallProfile = criteriaEnableP0P1Recall(chunk.criteria)
|
|
303
|
+
? buildP0P1RecallProfile({ chunk, plan })
|
|
304
|
+
: null;
|
|
305
|
+
const p0p1RuleCheckRequiredIds = [
|
|
306
|
+
"fail_open_or_pseudo_success",
|
|
307
|
+
"partial_coverage_misrepresented_as_complete",
|
|
308
|
+
"authority_boundary_or_private_import_bypass",
|
|
309
|
+
"permission_or_capability_bypass",
|
|
310
|
+
"ungated_destructive_action",
|
|
311
|
+
"provider_or_model_hardcoding",
|
|
312
|
+
"app_local_shadow_truth",
|
|
313
|
+
];
|
|
314
|
+
const auditDepth = adaptiveDepthForChunk(chunk);
|
|
315
|
+
const retrievalPrepass = buildRetrievalPrepass({ projectRoot: options.projectRoot, chunk, depth: auditDepth });
|
|
316
|
+
const selectedImplementationRefs = retrievalPrepass.selected_implementation_refs;
|
|
317
|
+
return {
|
|
318
|
+
version: 1,
|
|
319
|
+
kind: "audit-auditor-packet",
|
|
320
|
+
sweep_id: sweepId,
|
|
321
|
+
chunk_id: chunk.chunk_id,
|
|
322
|
+
auditor,
|
|
323
|
+
planning_basis: chunk.planning_basis ?? "file_inventory",
|
|
324
|
+
spec_surface: chunk.spec_surface ?? null,
|
|
325
|
+
criteria: chunk.criteria,
|
|
326
|
+
owner_domain: chunk.owner_domain,
|
|
327
|
+
audit_depth: auditDepth,
|
|
328
|
+
files: chunk.files,
|
|
329
|
+
authority_refs: chunk.authority_refs ?? chunk.files,
|
|
330
|
+
host_authority_projection_refs: chunk.host_authority_projection_refs ?? [],
|
|
331
|
+
evidence_roots: chunk.evidence_roots ?? [],
|
|
332
|
+
admitted_evidence_roots: chunk.admitted_evidence_roots ?? [],
|
|
333
|
+
evidence_inventory: selectedImplementationRefs,
|
|
334
|
+
selected_implementation_refs: selectedImplementationRefs,
|
|
335
|
+
retrieval_prepass: retrievalPrepass,
|
|
336
|
+
omitted_evidence_inventory: {
|
|
337
|
+
manager_owned: true,
|
|
338
|
+
full_inventory_count: retrievalPrepass.full_inventory_count,
|
|
339
|
+
selected_count: retrievalPrepass.selected_count,
|
|
340
|
+
omitted_count: retrievalPrepass.omitted_inventory_count,
|
|
341
|
+
sha256: retrievalPrepass.omitted_inventory_sha256,
|
|
342
|
+
canonicalization: retrievalPrepass.omitted_inventory_canonicalization,
|
|
343
|
+
source: "chunk.evidence_inventory",
|
|
344
|
+
},
|
|
345
|
+
evidence_inventory_status: chunk.evidence_inventory_status ?? null,
|
|
346
|
+
evidence_inventory_empty_reason: chunk.evidence_inventory_empty_reason ?? null,
|
|
347
|
+
coverage_contract: chunk.coverage_contract ?? null,
|
|
348
|
+
risk_budget_policy: plan.risk_budget_policy ?? null,
|
|
349
|
+
risk_budget_status: plan.risk_budget_status ?? null,
|
|
350
|
+
audit_strategy: p0p1RecallProfile ? {
|
|
351
|
+
mode: "p0_p1_triage_then_deep",
|
|
352
|
+
profile: p0p1RecallProfile,
|
|
353
|
+
} : {
|
|
354
|
+
mode: specAuthority ? "spec_first_full_audit" : "file_inventory_audit",
|
|
355
|
+
},
|
|
356
|
+
audit_instructions: specAuthority ? {
|
|
357
|
+
posture: "spec_first_full_audit",
|
|
358
|
+
authority_source: ".nimi/spec/**",
|
|
359
|
+
auditor_goal: "Find all material issues. Missing an issue is worse than a false positive.",
|
|
360
|
+
required_categories: [
|
|
361
|
+
"security",
|
|
362
|
+
"logic-error",
|
|
363
|
+
"error-handling",
|
|
364
|
+
"code-quality",
|
|
365
|
+
"performance",
|
|
366
|
+
"consistency",
|
|
367
|
+
"type-safety",
|
|
368
|
+
"resource-leak",
|
|
369
|
+
"race-condition",
|
|
370
|
+
"spec-drift",
|
|
371
|
+
"boundary",
|
|
372
|
+
"contract",
|
|
373
|
+
"architecture",
|
|
374
|
+
],
|
|
375
|
+
required_flow: [
|
|
376
|
+
"read every authority_ref first",
|
|
377
|
+
"use selected_implementation_refs/evidence_inventory as the compact implementation slice selected by the manager retrieval prepass",
|
|
378
|
+
"do not ask for or reconstruct the omitted full evidence_inventory; audit-codex validates cited refs against the manager-owned full chunk inventory",
|
|
379
|
+
"inspect and cite the implementation refs needed for semantic authority and P0/P1 reasoning",
|
|
380
|
+
`use audit_depth=${auditDepth.level}: ${auditDepth.codex_posture}`,
|
|
381
|
+
"evaluate inspected implementation evidence against the authority_refs",
|
|
382
|
+
"if evidence_inventory is empty, treat evidence_inventory_empty_reason as an auditable planning assertion rather than proof of correctness",
|
|
383
|
+
"emit auditor.id, auditor.mode, auditor.methodology_ref, and auditor.provenance with kind=semantic_audit, packet_ref, and session_ref or transcript_ref or review_ref",
|
|
384
|
+
"do not author coverage.files, coverage.authority_refs, or coverage.evidence_files; audit-codex mechanically populates them from the packet before ingest",
|
|
385
|
+
"emit one authority_outcome per authority_ref",
|
|
386
|
+
`emit coverage.p0p1_rule_checks with exactly these ids and no aliases: ${p0p1RuleCheckRequiredIds.join(", ")}`,
|
|
387
|
+
"each P0/P1 rule check must include id, status, implementation_refs, and chunk-specific negative_reasoning",
|
|
388
|
+
"use status=checked with at least one in-scope implementation_ref when implementation evidence was inspected",
|
|
389
|
+
"use status=not_applicable only when there is no implementation surface and explain why in negative_reasoning",
|
|
390
|
+
"emit coverage.p0p1_evidence_refs for implementation refs actually inspected",
|
|
391
|
+
"emit every finding that satisfies the audit-finding contract",
|
|
392
|
+
],
|
|
393
|
+
p0p1_recall: p0p1RecallProfile,
|
|
394
|
+
} : null,
|
|
395
|
+
output_contract: {
|
|
396
|
+
format: "json",
|
|
397
|
+
required_top_level_fields: ["chunk_id", "auditor", "coverage", "findings"],
|
|
398
|
+
auditor_required_shape: {
|
|
399
|
+
required_fields: ["id", "mode", "methodology_ref", "provenance"],
|
|
400
|
+
provenance_required: {
|
|
401
|
+
kind: "semantic_audit",
|
|
402
|
+
packet_ref: packetRef(sweepId, chunk.chunk_id),
|
|
403
|
+
one_of: ["session_ref", "transcript_ref", "review_ref"],
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
raw_coverage_required_fields: [
|
|
407
|
+
"authority_outcomes",
|
|
408
|
+
"p0p1_evidence_refs",
|
|
409
|
+
"p0p1_rule_checks",
|
|
410
|
+
],
|
|
411
|
+
manager_owned_coverage_fields: [
|
|
412
|
+
"files",
|
|
413
|
+
"authority_refs",
|
|
414
|
+
"evidence_files",
|
|
415
|
+
],
|
|
416
|
+
manager_owned_coverage_population: {
|
|
417
|
+
coverage_files_from_chunk_files: chunk.files,
|
|
418
|
+
coverage_authority_refs_from_chunk_authority_refs: chunk.authority_refs ?? chunk.files,
|
|
419
|
+
coverage_evidence_files_from_chunk_evidence_inventory: specAuthority ? "manager_owned_chunk.evidence_inventory" : null,
|
|
420
|
+
codex_cited_implementation_refs_must_belong_to_evidence_inventory: true,
|
|
421
|
+
},
|
|
422
|
+
spec_authority_coverage_requires_authority_outcomes: specAuthority,
|
|
423
|
+
authority_outcome_required_fields: [
|
|
424
|
+
"authority_ref",
|
|
425
|
+
"status",
|
|
426
|
+
"inspected_implementation_refs_or_implementation_evidence_refs_or_implementation_not_applicable_reason",
|
|
427
|
+
"negative_reasoning",
|
|
428
|
+
],
|
|
429
|
+
authority_outcome_manager_owned_fields: [
|
|
430
|
+
"evidence_refs",
|
|
431
|
+
],
|
|
432
|
+
authority_outcome_status_semantics: {
|
|
433
|
+
audited: "The authority ref and available implementation evidence were inspected. Use this even when findings were discovered.",
|
|
434
|
+
blocked: "The auditor could not inspect required evidence and must explain the blocker in reason.",
|
|
435
|
+
not_applicable: "No implementation surface applies and the auditor must explain why in reason.",
|
|
436
|
+
},
|
|
437
|
+
spec_authority_normalized_evidence_requires_evidence_files: specAuthority,
|
|
438
|
+
p0p1_negative_reasoning_required_when_no_critical_or_high_findings: Boolean(p0p1RecallProfile),
|
|
439
|
+
p0p1_negative_reasoning_field: p0p1RecallProfile ? "coverage.p0p1_negative_reasoning" : null,
|
|
440
|
+
p0p1_evidence_refs_field: p0p1RecallProfile ? "coverage.p0p1_evidence_refs" : null,
|
|
441
|
+
p0p1_rule_checks_field: p0p1RecallProfile ? "coverage.p0p1_rule_checks" : null,
|
|
442
|
+
p0p1_rule_check_required_ids: p0p1RecallProfile ? p0p1RuleCheckRequiredIds : [],
|
|
443
|
+
p0p1_rule_check_id_policy: {
|
|
444
|
+
exact_ids_required: true,
|
|
445
|
+
aliases_rejected_fail_closed: true,
|
|
446
|
+
required_ids_source: "output_contract.p0p1_rule_check_required_ids",
|
|
447
|
+
},
|
|
448
|
+
p0p1_rule_check_required_fields: ["id", "status", "implementation_refs", "negative_reasoning"],
|
|
449
|
+
p0p1_rule_check_status_enum: ["checked", "not_applicable"],
|
|
450
|
+
p0p1_rule_check_semantics: {
|
|
451
|
+
checked_requires_in_scope_implementation_refs: true,
|
|
452
|
+
checked_refs_should_come_from_selected_implementation_refs: true,
|
|
453
|
+
not_applicable_requires_negative_reasoning: true,
|
|
454
|
+
missing_status_or_negative_reasoning_rejected_before_ingest: true,
|
|
455
|
+
},
|
|
456
|
+
finding_locations_must_belong_to_chunk_files_or_evidence_inventory: true,
|
|
457
|
+
authority_only_finding_location_policy: "when no implementation surface exists, findings[].location.file must be the in-scope authority_ref that contains the defect",
|
|
458
|
+
finding_contract_ref: ".nimi/contracts/audit-finding.schema.yaml",
|
|
459
|
+
ingest_command: `nimicoding audit-sweep chunk ingest --sweep-id ${sweepId} --chunk-id ${chunk.chunk_id} --from <audit-output.json> --verified-at <ISO-8601-UTC>`,
|
|
460
|
+
},
|
|
461
|
+
hard_constraints: [
|
|
462
|
+
"do_not_sample_out_files_from_this_chunk",
|
|
463
|
+
"for_spec_authority_chunks_audit_the_authority_refs_first_and_use_evidence_roots_for_implementation_evidence",
|
|
464
|
+
"for_spec_authority_chunks_emit_one_authority_outcome_per_authority_ref",
|
|
465
|
+
"for_spec_authority_chunks_cite_only_inspected_implementation_refs_from_selected_implementation_refs",
|
|
466
|
+
"audit_codex_populates_full_coverage_evidence_files_from_manager_owned_chunk_inventory",
|
|
467
|
+
"full_evidence_inventory_is_manager_owned_and_not_exposed_to_codex",
|
|
468
|
+
"if_no_implementation_surface_exists_mark_the_authority_outcome_not_applicable_with_reason",
|
|
469
|
+
"do_not_return_pseudo_success",
|
|
470
|
+
"do_not_emit_findings_outside_chunk_files_or_declared_evidence_inventory",
|
|
471
|
+
"fail_closed_if_a_file_cannot_be_audited",
|
|
472
|
+
],
|
|
473
|
+
created_at: dispatchedAt,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export async function dispatchAuditSweepChunk(projectRoot, options) {
|
|
478
|
+
const sweepId = safeSweepId(options.sweepId);
|
|
479
|
+
if (!sweepId || typeof options.chunkId !== "string") {
|
|
480
|
+
return inputError("nimicoding audit-sweep refused: --sweep-id and --chunk-id are required.\n");
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const timestampError = ensureIsoTimestamp(options.dispatchedAt, "--dispatched-at");
|
|
484
|
+
if (timestampError) {
|
|
485
|
+
return timestampError;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return withAuditSweepMutationLock(projectRoot, sweepId, "chunk dispatch", async () => {
|
|
489
|
+
const planResult = await loadPlan(projectRoot, sweepId);
|
|
490
|
+
if (!planResult.ok) {
|
|
491
|
+
return inputError(planResult.error);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const chunkResult = await loadChunk(projectRoot, sweepId, options.chunkId);
|
|
495
|
+
if (!chunkResult.ok) {
|
|
496
|
+
return inputError(chunkResult.error);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (chunkResult.chunk.state !== "planned") {
|
|
500
|
+
return inputError("nimicoding audit-sweep refused: chunk dispatch requires planned state.\n");
|
|
501
|
+
}
|
|
502
|
+
const budgetBlock = budgetBlockForChunk(planResult.plan, chunkResult.chunk);
|
|
503
|
+
if (budgetBlock) {
|
|
504
|
+
return inputError(`nimicoding audit-sweep refused: ${budgetBlock}; build or admit remediation bundles before continuing discovery.\n`);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const updatedChunk = {
|
|
508
|
+
...chunkResult.chunk,
|
|
509
|
+
state: "dispatched",
|
|
510
|
+
lifecycle: {
|
|
511
|
+
...chunkResult.chunk.lifecycle,
|
|
512
|
+
dispatched_at: options.dispatchedAt,
|
|
513
|
+
},
|
|
514
|
+
dispatch: {
|
|
515
|
+
auditor: options.auditor ?? "external_auditor",
|
|
516
|
+
criteria: chunkResult.chunk.criteria,
|
|
517
|
+
files: chunkResult.chunk.files,
|
|
518
|
+
authority_refs: chunkResult.chunk.authority_refs ?? chunkResult.chunk.files,
|
|
519
|
+
host_authority_projection_refs: chunkResult.chunk.host_authority_projection_refs ?? [],
|
|
520
|
+
evidence_roots: chunkResult.chunk.evidence_roots ?? [],
|
|
521
|
+
admitted_evidence_roots: chunkResult.chunk.admitted_evidence_roots ?? [],
|
|
522
|
+
evidence_inventory: chunkResult.chunk.evidence_inventory ?? [],
|
|
523
|
+
evidence_inventory_status: chunkResult.chunk.evidence_inventory_status ?? null,
|
|
524
|
+
evidence_inventory_empty_reason: chunkResult.chunk.evidence_inventory_empty_reason ?? null,
|
|
525
|
+
},
|
|
526
|
+
updated_at: options.dispatchedAt,
|
|
527
|
+
};
|
|
528
|
+
const packet = buildAuditorPacket(sweepId, chunkResult.chunk, updatedChunk.dispatch.auditor, options.dispatchedAt, planResult.plan, { projectRoot });
|
|
529
|
+
const auditorPacketRef = packetRef(sweepId, options.chunkId);
|
|
530
|
+
await writeYamlRef(projectRoot, auditorPacketRef, packet);
|
|
531
|
+
await writeYamlRef(projectRoot, chunkResult.chunkRef, updatedChunk);
|
|
532
|
+
await writeYamlRef(projectRoot, planResult.planRef, {
|
|
533
|
+
...updatePlanChunk(planResult.plan, options.chunkId, { state: "dispatched" }),
|
|
534
|
+
updated_at: options.dispatchedAt,
|
|
535
|
+
});
|
|
536
|
+
const runRef = await appendRunEvent(projectRoot, sweepId, {
|
|
537
|
+
event_type: "chunk_dispatched",
|
|
538
|
+
chunk_id: options.chunkId,
|
|
539
|
+
chunk_ref: chunkRef(sweepId, options.chunkId),
|
|
540
|
+
packet_ref: auditorPacketRef,
|
|
541
|
+
auditor: updatedChunk.dispatch.auditor,
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
return {
|
|
545
|
+
ok: true,
|
|
546
|
+
exitCode: 0,
|
|
547
|
+
sweepId,
|
|
548
|
+
chunkId: options.chunkId,
|
|
549
|
+
state: "dispatched",
|
|
550
|
+
chunkRef: chunkResult.chunkRef,
|
|
551
|
+
packetRef: auditorPacketRef,
|
|
552
|
+
runLedgerRef: runRef,
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export async function reviewAuditSweepChunk(projectRoot, options) {
|
|
558
|
+
const sweepId = safeSweepId(options.sweepId);
|
|
559
|
+
if (!sweepId || typeof options.chunkId !== "string") {
|
|
560
|
+
return inputError("nimicoding audit-sweep refused: --sweep-id and --chunk-id are required.\n");
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const timestampError = ensureIsoTimestamp(options.reviewedAt, "--reviewed-at");
|
|
564
|
+
if (timestampError) {
|
|
565
|
+
return timestampError;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (!["pass", "fail"].includes(options.verdict)) {
|
|
569
|
+
return inputError("nimicoding audit-sweep refused: --verdict must be pass or fail.\n");
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return withAuditSweepMutationLock(projectRoot, sweepId, "chunk review", async () => {
|
|
573
|
+
const planResult = await loadPlan(projectRoot, sweepId);
|
|
574
|
+
if (!planResult.ok) {
|
|
575
|
+
return inputError(planResult.error);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
const chunkResult = await loadChunk(projectRoot, sweepId, options.chunkId);
|
|
579
|
+
if (!chunkResult.ok) {
|
|
580
|
+
return inputError(chunkResult.error);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (chunkResult.chunk.state !== "ingested") {
|
|
584
|
+
return inputError("nimicoding audit-sweep refused: chunk review requires ingested state.\n");
|
|
585
|
+
}
|
|
586
|
+
if (options.verdict === "pass" && chunkResult.chunk.audit_validity?.posture === "invalid") {
|
|
587
|
+
return inputError("nimicoding audit-sweep refused: manager review cannot freeze invalid no-finding evidence as pass.\n");
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const nextState = options.verdict === "pass" ? "frozen" : "failed";
|
|
591
|
+
const updatedChunk = {
|
|
592
|
+
...chunkResult.chunk,
|
|
593
|
+
state: nextState,
|
|
594
|
+
lifecycle: {
|
|
595
|
+
...chunkResult.chunk.lifecycle,
|
|
596
|
+
reviewed_at: options.reviewedAt,
|
|
597
|
+
frozen_at: options.verdict === "pass" ? options.reviewedAt : chunkResult.chunk.lifecycle.frozen_at,
|
|
598
|
+
failed_at: options.verdict === "fail" ? options.reviewedAt : chunkResult.chunk.lifecycle.failed_at,
|
|
599
|
+
},
|
|
600
|
+
review: {
|
|
601
|
+
verdict: options.verdict,
|
|
602
|
+
reviewer: options.reviewer ?? "nimicoding_manager",
|
|
603
|
+
summary: options.summary ?? null,
|
|
604
|
+
reviewed_at: options.reviewedAt,
|
|
605
|
+
},
|
|
606
|
+
failure: options.verdict === "fail"
|
|
607
|
+
? { reason: options.summary ?? "manager_review_failed", failed_at: options.reviewedAt }
|
|
608
|
+
: chunkResult.chunk.failure,
|
|
609
|
+
updated_at: options.reviewedAt,
|
|
610
|
+
};
|
|
611
|
+
await writeYamlRef(projectRoot, chunkResult.chunkRef, updatedChunk);
|
|
612
|
+
await writeYamlRef(projectRoot, planResult.planRef, {
|
|
613
|
+
...updatePlanChunk(planResult.plan, options.chunkId, { state: nextState }),
|
|
614
|
+
updated_at: options.reviewedAt,
|
|
615
|
+
});
|
|
616
|
+
const runRef = await appendRunEvent(projectRoot, sweepId, {
|
|
617
|
+
event_type: options.verdict === "pass" ? "chunk_frozen" : "chunk_failed",
|
|
618
|
+
chunk_id: options.chunkId,
|
|
619
|
+
chunk_ref: chunkResult.chunkRef,
|
|
620
|
+
reviewer: updatedChunk.review.reviewer,
|
|
621
|
+
summary: updatedChunk.review.summary,
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
return {
|
|
625
|
+
ok: true,
|
|
626
|
+
exitCode: 0,
|
|
627
|
+
sweepId,
|
|
628
|
+
chunkId: options.chunkId,
|
|
629
|
+
state: nextState,
|
|
630
|
+
chunkRef: chunkResult.chunkRef,
|
|
631
|
+
runLedgerRef: runRef,
|
|
632
|
+
};
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export async function skipAuditSweepChunk(projectRoot, options) {
|
|
637
|
+
const sweepId = safeSweepId(options.sweepId);
|
|
638
|
+
if (!sweepId || typeof options.chunkId !== "string") {
|
|
639
|
+
return inputError("nimicoding audit-sweep refused: --sweep-id and --chunk-id are required.\n");
|
|
640
|
+
}
|
|
641
|
+
const timestampError = ensureIsoTimestamp(options.skippedAt, "--skipped-at");
|
|
642
|
+
if (timestampError) {
|
|
643
|
+
return timestampError;
|
|
644
|
+
}
|
|
645
|
+
if (typeof options.reason !== "string" || !options.reason.trim()) {
|
|
646
|
+
return inputError("nimicoding audit-sweep refused: --reason is required when skipping a chunk.\n");
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return withAuditSweepMutationLock(projectRoot, sweepId, "chunk skip", async () => {
|
|
650
|
+
const planResult = await loadPlan(projectRoot, sweepId);
|
|
651
|
+
if (!planResult.ok) {
|
|
652
|
+
return inputError(planResult.error);
|
|
653
|
+
}
|
|
654
|
+
const chunkResult = await loadChunk(projectRoot, sweepId, options.chunkId);
|
|
655
|
+
if (!chunkResult.ok) {
|
|
656
|
+
return inputError(chunkResult.error);
|
|
657
|
+
}
|
|
658
|
+
if (chunkResult.chunk.state === "frozen") {
|
|
659
|
+
return inputError("nimicoding audit-sweep refused: frozen chunks cannot be skipped.\n");
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const updatedChunk = {
|
|
663
|
+
...chunkResult.chunk,
|
|
664
|
+
state: "skipped",
|
|
665
|
+
lifecycle: {
|
|
666
|
+
...chunkResult.chunk.lifecycle,
|
|
667
|
+
skipped_at: options.skippedAt,
|
|
668
|
+
},
|
|
669
|
+
skip: {
|
|
670
|
+
reason: options.reason,
|
|
671
|
+
skipped_at: options.skippedAt,
|
|
672
|
+
},
|
|
673
|
+
updated_at: options.skippedAt,
|
|
674
|
+
};
|
|
675
|
+
await writeYamlRef(projectRoot, chunkResult.chunkRef, updatedChunk);
|
|
676
|
+
await writeYamlRef(projectRoot, planResult.planRef, {
|
|
677
|
+
...updatePlanChunk(planResult.plan, options.chunkId, { state: "skipped" }),
|
|
678
|
+
updated_at: options.skippedAt,
|
|
679
|
+
});
|
|
680
|
+
const runRef = await appendRunEvent(projectRoot, sweepId, {
|
|
681
|
+
event_type: "chunk_skipped",
|
|
682
|
+
chunk_id: options.chunkId,
|
|
683
|
+
chunk_ref: chunkResult.chunkRef,
|
|
684
|
+
reason: options.reason,
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
return {
|
|
688
|
+
ok: true,
|
|
689
|
+
exitCode: 0,
|
|
690
|
+
sweepId,
|
|
691
|
+
chunkId: options.chunkId,
|
|
692
|
+
state: "skipped",
|
|
693
|
+
chunkRef: chunkResult.chunkRef,
|
|
694
|
+
runLedgerRef: runRef,
|
|
695
|
+
};
|
|
696
|
+
});
|
|
697
|
+
}
|