@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,315 +0,0 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
-
4
- import YAML from "yaml";
5
-
6
- import {
7
- ACTIVE_CHUNK_STATES,
8
- appendRunEvent,
9
- artifactPath,
10
- artifactRef,
11
- chunkRef,
12
- ensureIsoTimestamp,
13
- findingsRef,
14
- inputError,
15
- loadJsonFile,
16
- ledgerRef,
17
- loadChunk,
18
- loadFindings,
19
- loadPlan,
20
- remediationMapRef,
21
- reportRef,
22
- runLedgerRef,
23
- safeSweepId,
24
- writeYamlRef,
25
- } from "./common.mjs";
26
- import { buildAuditValidityForEvidence, combineAuditValidity } from "./audit-validity.mjs";
27
- import { buildCoverageQuality } from "./coverage-quality.mjs";
28
- import { deriveLedgerSnapshotId } from "./validators.mjs";
29
- import { ensureClusterStore } from "./risk-budget.mjs";
30
-
31
- function countBy(values, keyFn) {
32
- const counts = {};
33
- for (const value of values) {
34
- const key = keyFn(value);
35
- counts[key] = (counts[key] ?? 0) + 1;
36
- }
37
- return counts;
38
- }
39
-
40
- async function loadChunks(projectRoot, sweepId, plan) {
41
- const chunks = [];
42
- for (const chunk of plan.chunks) {
43
- const loaded = await loadChunk(projectRoot, sweepId, chunk.chunk_id);
44
- if (!loaded.ok) {
45
- return loaded;
46
- }
47
- chunks.push(loaded.chunk);
48
- }
49
- return { ok: true, chunks };
50
- }
51
-
52
- function buildFindingPosture(findings) {
53
- return {
54
- open: findings.filter((finding) => finding.disposition === "open").length,
55
- remediated: findings.filter((finding) => finding.disposition === "remediated").length,
56
- accepted_risk: findings.filter((finding) => finding.disposition === "accepted-risk").length,
57
- false_positive: findings.filter((finding) => finding.disposition === "false-positive").length,
58
- deferred_backlog: findings.filter((finding) => finding.disposition === "deferred-backlog").length,
59
- };
60
- }
61
-
62
- function buildLedgerCoverage(plan, chunks) {
63
- const frozenChunks = chunks.filter((chunk) => chunk.state === "frozen");
64
- const base = {
65
- frozen_chunks: frozenChunks.length,
66
- failed_chunks: chunks.filter((chunk) => chunk.state === "failed").length,
67
- skipped_chunks: chunks.filter((chunk) => chunk.state === "skipped").length,
68
- active_chunks: chunks.filter((chunk) => ACTIVE_CHUNK_STATES.has(chunk.state)).length,
69
- };
70
- if (plan.planning_basis?.mode !== "spec_authority") {
71
- const auditedFiles = new Set(frozenChunks.flatMap((chunk) => chunk.files));
72
- return {
73
- total_files: plan.coverage.total_files,
74
- included_files: plan.coverage.included_files,
75
- audited_files: auditedFiles.size,
76
- ...base,
77
- };
78
- }
79
-
80
- const auditedAuthorityFiles = new Set(frozenChunks.flatMap((chunk) => chunk.files));
81
- const auditedEvidenceFiles = new Set(frozenChunks.flatMap((chunk) => chunk.evidence_inventory ?? []));
82
- const authorityTotal = plan.coverage?.authority_files ?? plan.coverage?.included_files ?? 0;
83
- const evidenceTotal = plan.coverage?.evidence_files ?? plan.evidence_inventory?.length ?? 0;
84
- const unmappedEvidenceFiles = plan.coverage?.unmapped_evidence_files ?? plan.unmapped_evidence_files?.length ?? 0;
85
- const emptyEvidenceChunks = plan.coverage?.authority_chunks_without_evidence_inventory
86
- ?? chunks.filter((chunk) => (chunk.evidence_inventory ?? []).length === 0).length;
87
- return {
88
- total_files: authorityTotal + evidenceTotal,
89
- included_files: authorityTotal + evidenceTotal,
90
- audited_files: auditedAuthorityFiles.size + auditedEvidenceFiles.size,
91
- authority_coverage: {
92
- total_files: authorityTotal,
93
- audited_files: auditedAuthorityFiles.size,
94
- chunks_without_evidence_inventory: emptyEvidenceChunks,
95
- },
96
- evidence_coverage: {
97
- total_files: evidenceTotal,
98
- audited_files: auditedEvidenceFiles.size,
99
- unmapped_files: unmappedEvidenceFiles,
100
- },
101
- ...base,
102
- };
103
- }
104
-
105
- async function buildLedgerAuditValidity(projectRoot, chunks) {
106
- const entries = [];
107
- for (const chunk of chunks) {
108
- if (!chunk.evidence_ref) {
109
- continue;
110
- }
111
- const evidence = await loadJsonFile(artifactPath(projectRoot, chunk.evidence_ref));
112
- if (evidence.ok) {
113
- entries.push(buildAuditValidityForEvidence(chunk, evidence.value));
114
- }
115
- }
116
- return combineAuditValidity(entries);
117
- }
118
-
119
- function deriveLedgerStatus(plan, coverage, chunks) {
120
- const includedFiles = coverage.included_files ?? 0;
121
- const frozenChunks = chunks.filter((chunk) => chunk.state === "frozen").length;
122
-
123
- if (includedFiles === 0) {
124
- return "blocked";
125
- }
126
- if (coverage.active_chunks > 0) {
127
- return "partial";
128
- }
129
- if (coverage.failed_chunks > 0 || coverage.skipped_chunks > 0) {
130
- return "partial";
131
- }
132
- if (plan.planning_basis?.mode === "spec_authority") {
133
- const authorityFull = coverage.authority_coverage?.total_files > 0
134
- && coverage.authority_coverage.audited_files === coverage.authority_coverage.total_files;
135
- const evidenceFull = coverage.evidence_coverage?.audited_files === coverage.evidence_coverage?.total_files
136
- && coverage.evidence_coverage?.unmapped_files === 0;
137
- if (frozenChunks === chunks.length && authorityFull && evidenceFull) {
138
- return "candidate_ready";
139
- }
140
- if (authorityFull && !evidenceFull) {
141
- return "blocked_evidence_incomplete";
142
- }
143
- return "partial_authority_only";
144
- }
145
- return frozenChunks === chunks.length ? "candidate_ready" : "partial";
146
- }
147
-
148
- function formatReport({ sweepId, ledger, findings }) {
149
- const lines = [
150
- `# Audit Sweep ${sweepId}`,
151
- "",
152
- `- Snapshot: ${ledger.snapshot_id}`,
153
- `- Status: ${ledger.status}`,
154
- `- Included files: ${ledger.coverage.included_files}`,
155
- `- Audited files: ${ledger.coverage.audited_files}`,
156
- ...(ledger.coverage_quality ? [
157
- `- Coverage quality: ${ledger.coverage_quality.posture}`,
158
- `- Coverage quality warnings: ${ledger.coverage_quality.warnings.length}`,
159
- `- Coverage quality blockers: ${ledger.coverage_quality.blockers.length}`,
160
- ] : []),
161
- ...(ledger.audit_validity ? [
162
- `- Audit validity: ${ledger.audit_validity.posture}`,
163
- `- Audit validity warnings: ${ledger.audit_validity.warnings.length}`,
164
- `- Audit validity blockers: ${ledger.audit_validity.blockers.length}`,
165
- `- No-finding posture: ${ledger.audit_validity.no_finding_posture}`,
166
- ] : []),
167
- ...(ledger.coverage.authority_coverage ? [
168
- `- Authority coverage: ${ledger.coverage.authority_coverage.audited_files}/${ledger.coverage.authority_coverage.total_files}`,
169
- `- Evidence coverage: ${ledger.coverage.evidence_coverage.audited_files}/${ledger.coverage.evidence_coverage.total_files}`,
170
- `- Unmapped evidence files: ${ledger.coverage.evidence_coverage.unmapped_files}`,
171
- ] : []),
172
- `- Frozen chunks: ${ledger.coverage.frozen_chunks}`,
173
- `- Findings: ${ledger.finding_count}`,
174
- `- Finding clusters: ${ledger.finding_cluster_count ?? 0}`,
175
- `- Clustered duplicate symptoms: ${ledger.clustered_symptom_count ?? 0}`,
176
- `- Open findings: ${ledger.finding_posture.open}`,
177
- "",
178
- "## Severity Counts",
179
- "",
180
- ...Object.entries(ledger.severity_counts).map(([severity, count]) => `- ${severity}: ${count}`),
181
- "",
182
- "## Findings",
183
- "",
184
- ];
185
-
186
- if (findings.length === 0) {
187
- lines.push("No findings recorded.");
188
- } else {
189
- for (const finding of findings) {
190
- lines.push(`### ${finding.id}: ${finding.title}`);
191
- lines.push("");
192
- lines.push(`- Severity: ${finding.severity}`);
193
- lines.push(`- Disposition: ${finding.disposition}`);
194
- lines.push(`- Actionability: ${finding.actionability}`);
195
- lines.push(`- Location: ${finding.location.file}${finding.location.line ? `:${finding.location.line}` : ""}`);
196
- lines.push(`- Fingerprint: ${finding.fingerprint}`);
197
- lines.push("");
198
- lines.push(finding.description);
199
- lines.push("");
200
- }
201
- }
202
-
203
- return `${lines.join("\n")}\n`;
204
- }
205
-
206
- export async function buildAuditSweepLedger(projectRoot, options) {
207
- const sweepId = safeSweepId(options.sweepId);
208
- if (!sweepId) {
209
- return inputError("nimicoding sweep audit refused: --sweep-id is required.\n");
210
- }
211
-
212
- const timestampError = options.verifiedAt ? ensureIsoTimestamp(options.verifiedAt) : null;
213
- if (timestampError) {
214
- return timestampError;
215
- }
216
- const verifiedAt = options.verifiedAt ?? new Date().toISOString();
217
-
218
- const planResult = await loadPlan(projectRoot, sweepId);
219
- if (!planResult.ok) {
220
- return inputError(planResult.error);
221
- }
222
- const chunksResult = await loadChunks(projectRoot, sweepId, planResult.plan);
223
- if (!chunksResult.ok) {
224
- return inputError(chunksResult.error);
225
- }
226
- const { findingsRef: aggregateFindingsRef, store } = await loadFindings(projectRoot, sweepId);
227
- ensureClusterStore(store);
228
- await writeYamlRef(projectRoot, aggregateFindingsRef, store);
229
- const chunks = chunksResult.chunks;
230
- const coverage = buildLedgerCoverage(planResult.plan, chunks);
231
- const status = deriveLedgerStatus(planResult.plan, coverage, chunks);
232
- const coverageQuality = buildCoverageQuality(planResult.plan, chunks, coverage);
233
- const auditValidity = await buildLedgerAuditValidity(projectRoot, chunks);
234
- const evidenceRefs = [
235
- aggregateFindingsRef,
236
- ...chunks.map((chunk) => chunk.evidence_ref).filter(Boolean),
237
- ...store.findings.map((finding) => finding.resolution?.evidence_ref).filter(Boolean),
238
- ];
239
- const findingPosture = buildFindingPosture(store.findings);
240
- const snapshotId = deriveLedgerSnapshotId(sweepId, planResult.plan, chunks, store.findings, store.clusters);
241
- const currentLedgerRef = ledgerRef(sweepId, snapshotId);
242
- const currentReportRef = reportRef(sweepId, snapshotId);
243
- const latestPointerRef = artifactRef("ledger_ref", sweepId, "latest.yaml");
244
- const ledger = {
245
- version: 1,
246
- kind: "audit-ledger",
247
- sweep_id: sweepId,
248
- snapshot_id: snapshotId,
249
- immutable: true,
250
- plan_ref: planResult.planRef,
251
- chunk_refs: chunks.map((chunk) => chunkRef(sweepId, chunk.chunk_id)),
252
- findings_ref: aggregateFindingsRef,
253
- evidence_refs: evidenceRefs,
254
- run_ledger_ref: runLedgerRef(sweepId),
255
- report_ref: currentReportRef,
256
- remediation_map_ref: remediationMapRef(sweepId, snapshotId),
257
- status,
258
- coverage,
259
- ...(coverageQuality ? { coverage_quality: coverageQuality } : {}),
260
- audit_validity: auditValidity,
261
- finding_count: store.findings.length,
262
- finding_cluster_count: store.clusters.length,
263
- clustered_symptom_count: store.clustered_symptom_count ?? 0,
264
- remediation_obligation_count: store.remediation_obligation_count ?? store.findings.length,
265
- unresolved_finding_count: findingPosture.open,
266
- finding_posture: findingPosture,
267
- severity_counts: countBy(store.findings, (finding) => finding.severity),
268
- actionability_counts: countBy(store.findings, (finding) => finding.actionability),
269
- created_at: verifiedAt,
270
- };
271
-
272
- await writeYamlRef(projectRoot, currentLedgerRef, ledger);
273
- await writeYamlRef(projectRoot, latestPointerRef, {
274
- version: 1,
275
- kind: "audit-ledger-pointer",
276
- sweep_id: sweepId,
277
- ledger_ref: currentLedgerRef,
278
- snapshot_id: snapshotId,
279
- updated_at: verifiedAt,
280
- });
281
- await mkdir(path.dirname(artifactPath(projectRoot, currentReportRef)), { recursive: true });
282
- await writeFile(artifactPath(projectRoot, currentReportRef), formatReport({ sweepId, ledger, findings: store.findings }), "utf8");
283
- const runRef = await appendRunEvent(projectRoot, sweepId, {
284
- event_type: "ledger_snapshot_created",
285
- ledger_ref: currentLedgerRef,
286
- snapshot_id: snapshotId,
287
- status,
288
- });
289
-
290
- return {
291
- ok: true,
292
- exitCode: 0,
293
- sweepId,
294
- status,
295
- snapshotId,
296
- planRef: planResult.planRef,
297
- chunkRefs: ledger.chunk_refs,
298
- ledgerRef: currentLedgerRef,
299
- latestLedgerRef: latestPointerRef,
300
- reportRef: currentReportRef,
301
- remediationMapRef: ledger.remediation_map_ref,
302
- runLedgerRef: runRef,
303
- evidenceRefs,
304
- findingCount: store.findings.length,
305
- findingClusterCount: store.clusters.length,
306
- clusteredSymptomCount: store.clustered_symptom_count ?? 0,
307
- remediationObligationCount: store.remediation_obligation_count ?? store.findings.length,
308
- unresolvedFindingCount: findingPosture.open,
309
- coverage: ledger.coverage,
310
- coverageQuality: ledger.coverage_quality ?? null,
311
- auditValidity: ledger.audit_validity,
312
- };
313
- }
314
-
315
- export { formatReport as formatAuditSweepReport };
@@ -1,101 +0,0 @@
1
- const P0P1_CRITERIA = new Set([
2
- "p0p1",
3
- "p0-p1",
4
- "p0",
5
- "p1",
6
- "critical-high",
7
- "critical_high",
8
- ]);
9
-
10
- const HIGH_RISK_OWNER_DOMAINS = new Set([
11
- "runtime",
12
- "sdk",
13
- "platform",
14
- "security",
15
- "provider",
16
- "desktop",
17
- "web",
18
- "nimicoding",
19
- "nimicoding/audit-sweep",
20
- ]);
21
-
22
- export function criteriaEnableP0P1Recall(criteria) {
23
- return Array.isArray(criteria)
24
- && criteria.some((entry) => P0P1_CRITERIA.has(String(entry).trim().toLowerCase()));
25
- }
26
-
27
- export function buildP0P1RecallProfile({ chunk, plan }) {
28
- const ownerDomain = chunk.owner_domain ?? "unknown";
29
- const highRiskOwnerDomain = HIGH_RISK_OWNER_DOMAINS.has(ownerDomain);
30
- const calibrationExpectedDefects = Array.isArray(chunk.calibration_expected_defects)
31
- ? chunk.calibration_expected_defects.length
32
- : 0;
33
-
34
- return {
35
- profile_id: "p0_p1_recall",
36
- objective: "Prioritize critical/high recall. Missing a P0/P1 issue is worse than a low-confidence false positive.",
37
- severity_mapping: {
38
- p0: "critical",
39
- p1: "high",
40
- },
41
- priority_defect_classes: [
42
- {
43
- id: "fail_open_or_pseudo_success",
44
- question: "Can an error, missing dependency, skipped work, or invalid evidence still produce a success posture?",
45
- },
46
- {
47
- id: "authority_boundary_or_private_import_bypass",
48
- question: "Can runtime/sdk/app/spec boundaries be bypassed or treated as advisory?",
49
- },
50
- {
51
- id: "app_local_shadow_truth",
52
- question: "Can an unadmitted file, host-local artifact, or generated projection become semantic truth?",
53
- },
54
- {
55
- id: "partial_coverage_misrepresented_as_complete",
56
- question: "Can partial, skipped, sampled, or authority-only coverage be reported as complete?",
57
- },
58
- {
59
- id: "permission_or_capability_bypass",
60
- question: "Can user, provider, filesystem, network, or app permissions be bypassed?",
61
- },
62
- {
63
- id: "ungated_destructive_action",
64
- question: "Can destructive mutation, deletion, overwrite, or publication happen without the required gate?",
65
- },
66
- {
67
- id: "provider_or_model_hardcoding",
68
- question: "Can provider or model selection be hardcoded instead of flowing through admitted authority and configuration?",
69
- },
70
- ],
71
- triage_flow: [
72
- "classify whether the chunk contains P0/P1-relevant authority or implementation evidence",
73
- "scan authority_refs and evidence_inventory for every priority_defect_class",
74
- "record candidate P0/P1 signals before spending time on low-severity cleanup",
75
- "deep-audit only the files and flows tied to a candidate P0/P1 signal or trigger",
76
- "cluster duplicate symptoms under one canonical root-cause finding",
77
- ],
78
- deep_audit_triggers: [
79
- "p0_p1_signal_found_in_triage",
80
- highRiskOwnerDomain ? "high_risk_owner_domain" : null,
81
- calibrationExpectedDefects > 0 ? "calibration_expected_defects_present" : null,
82
- ].filter(Boolean),
83
- token_budget_policy: {
84
- triage_first: true,
85
- deep_audit_only_on_trigger: true,
86
- cluster_duplicate_symptoms: true,
87
- prefer_canonical_root_cause_findings: true,
88
- pause_when_risk_budget_blocks_more_discovery: true,
89
- max_sweep_high_risk_findings_before_pause: plan.risk_budget_policy?.max_sweep_high_risk_findings ?? null,
90
- max_domain_high_risk_findings_before_pause: plan.risk_budget_policy?.max_domain_high_risk_findings ?? null,
91
- },
92
- no_p0p1_finding_requirement: {
93
- required: true,
94
- reasoning_field: "coverage.p0p1_negative_reasoning",
95
- evidence_refs_field: "coverage.p0p1_evidence_refs",
96
- implementation_not_applicable_reason_field: "coverage.p0p1_implementation_not_applicable_reason",
97
- summary: "If no critical/high finding is emitted, explain why each applicable priority defect class did not produce a P0/P1 issue and cite implementation evidence; for empty implementation inventory, explicitly justify why implementation evidence is not applicable.",
98
- evidence_refs_must_include_implementation: true,
99
- },
100
- };
101
- }