@nimiplatform/nimi-coding 0.2.8 → 0.3.1

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 (206) hide show
  1. package/CHANGELOG.md +10 -90
  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/commands/validate-spec-governance.mjs +20 -0
  8. package/cli/constants.mjs +9 -417
  9. package/cli/help.mjs +28 -145
  10. package/cli/index.mjs +5 -33
  11. package/cli/lib/blueprint-audit.mjs +5 -12
  12. package/cli/lib/bootstrap.mjs +0 -9
  13. package/cli/lib/contracts.mjs +0 -163
  14. package/cli/lib/doctor.mjs +155 -10
  15. package/cli/lib/entrypoints.mjs +63 -167
  16. package/cli/lib/internal/contracts-loaders.mjs +0 -85
  17. package/cli/lib/internal/contracts-parse.mjs +84 -520
  18. package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +13 -8
  19. package/cli/lib/internal/surface-taxonomy-validators.mjs +316 -66
  20. package/cli/lib/internal/validators-shared.mjs +0 -16
  21. package/cli/lib/internal/validators-spec-helpers.mjs +7 -140
  22. package/cli/lib/internal/validators-spec.mjs +103 -342
  23. package/cli/lib/shared.mjs +1 -42
  24. package/cli/lib/validators.mjs +0 -48
  25. package/cli/seeds/seed-policy.yaml +0 -3
  26. package/config/bootstrap.yaml +4 -4
  27. package/config/spec-generation-inputs.yaml +6 -12
  28. package/contracts/domain-admission.schema.yaml +3 -3
  29. package/contracts/migration-inventory.schema.yaml +12 -75
  30. package/contracts/negative-fixtures.yaml +19 -99
  31. package/contracts/placement-contract.schema.yaml +49 -78
  32. package/contracts/projection-edge.schema.yaml +37 -121
  33. package/contracts/shared-enums.yaml +4 -8
  34. package/contracts/spec-generation-inputs.schema.yaml +15 -112
  35. package/contracts/spec-layout.schema.yaml +32 -0
  36. package/contracts/surface-taxonomy.schema.yaml +43 -94
  37. package/contracts/table-family.schema.yaml +1 -1
  38. package/contracts/tracked-output-admission.schema.yaml +13 -66
  39. package/methodology/core.yaml +33 -25
  40. package/methodology/four-closure-policy.yaml +18 -26
  41. package/methodology/role-separation-policy.yaml +21 -27
  42. package/methodology/spec-reconstruction.yaml +17 -34
  43. package/package.json +2 -4
  44. package/spec/_meta/spec-tree-model.yaml +5 -101
  45. package/spec/product-scope.yaml +25 -57
  46. package/adapters/README.md +0 -25
  47. package/adapters/claude/README.md +0 -89
  48. package/adapters/claude/profile.yaml +0 -70
  49. package/adapters/codex/README.md +0 -53
  50. package/adapters/codex/profile.yaml +0 -78
  51. package/adapters/oh-my-codex/README.md +0 -184
  52. package/adapters/oh-my-codex/profile.yaml +0 -46
  53. package/cli/commands/admit-high-risk-decision.mjs +0 -108
  54. package/cli/commands/audit-sweep.mjs +0 -364
  55. package/cli/commands/closeout.mjs +0 -186
  56. package/cli/commands/decide-high-risk-execution.mjs +0 -124
  57. package/cli/commands/handoff.mjs +0 -123
  58. package/cli/commands/ingest-high-risk-execution.mjs +0 -95
  59. package/cli/commands/review-high-risk-execution.mjs +0 -95
  60. package/cli/commands/sweep-design.mjs +0 -295
  61. package/cli/commands/sweep.mjs +0 -22
  62. package/cli/commands/topic-formatters.mjs +0 -382
  63. package/cli/commands/topic-goal.mjs +0 -33
  64. package/cli/commands/topic-options-shared.mjs +0 -27
  65. package/cli/commands/topic-options-workflow.mjs +0 -767
  66. package/cli/commands/topic-options.mjs +0 -626
  67. package/cli/commands/topic-runner.mjs +0 -169
  68. package/cli/commands/topic.mjs +0 -795
  69. package/cli/commands/validate-acceptance.mjs +0 -5
  70. package/cli/commands/validate-execution-packet.mjs +0 -5
  71. package/cli/commands/validate-orchestration-state.mjs +0 -5
  72. package/cli/commands/validate-prompt.mjs +0 -5
  73. package/cli/commands/validate-worker-output.mjs +0 -5
  74. package/cli/lib/adapter-profiles.mjs +0 -403
  75. package/cli/lib/audit-execution.mjs +0 -52
  76. package/cli/lib/audit-sweep-runtime/admissions.mjs +0 -508
  77. package/cli/lib/audit-sweep-runtime/audit-validity.mjs +0 -356
  78. package/cli/lib/audit-sweep-runtime/chunks.mjs +0 -697
  79. package/cli/lib/audit-sweep-runtime/claude-auditor.mjs +0 -658
  80. package/cli/lib/audit-sweep-runtime/closeout.mjs +0 -144
  81. package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +0 -654
  82. package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +0 -527
  83. package/cli/lib/audit-sweep-runtime/common.mjs +0 -341
  84. package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +0 -172
  85. package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +0 -155
  86. package/cli/lib/audit-sweep-runtime/format.mjs +0 -57
  87. package/cli/lib/audit-sweep-runtime/ingest.mjs +0 -486
  88. package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +0 -425
  89. package/cli/lib/audit-sweep-runtime/inventory.mjs +0 -798
  90. package/cli/lib/audit-sweep-runtime/ledger.mjs +0 -315
  91. package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +0 -101
  92. package/cli/lib/audit-sweep-runtime/remediation.mjs +0 -349
  93. package/cli/lib/audit-sweep-runtime/rerun.mjs +0 -129
  94. package/cli/lib/audit-sweep-runtime/risk-budget.mjs +0 -300
  95. package/cli/lib/audit-sweep-runtime/status.mjs +0 -62
  96. package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +0 -215
  97. package/cli/lib/audit-sweep-runtime/validators.mjs +0 -797
  98. package/cli/lib/audit-sweep.mjs +0 -19
  99. package/cli/lib/authority-convergence.mjs +0 -720
  100. package/cli/lib/closeout.mjs +0 -732
  101. package/cli/lib/codex-sdk-runner.mjs +0 -76
  102. package/cli/lib/external-execution.mjs +0 -101
  103. package/cli/lib/handoff.mjs +0 -812
  104. package/cli/lib/high-risk-admission.mjs +0 -512
  105. package/cli/lib/high-risk-decision.mjs +0 -353
  106. package/cli/lib/high-risk-ingest.mjs +0 -321
  107. package/cli/lib/high-risk-review.mjs +0 -267
  108. package/cli/lib/internal/contracts-parse-high-risk.mjs +0 -131
  109. package/cli/lib/internal/contracts-validators.mjs +0 -399
  110. package/cli/lib/internal/doctor-bootstrap-surface.mjs +0 -406
  111. package/cli/lib/internal/doctor-delegated-surface.mjs +0 -256
  112. package/cli/lib/internal/doctor-finalize.mjs +0 -383
  113. package/cli/lib/internal/doctor-format.mjs +0 -286
  114. package/cli/lib/internal/doctor-inspectors.mjs +0 -327
  115. package/cli/lib/internal/doctor-state.mjs +0 -205
  116. package/cli/lib/internal/validators-artifacts.mjs +0 -515
  117. package/cli/lib/sweep-design-runtime/common.mjs +0 -246
  118. package/cli/lib/sweep-design-runtime/engine.mjs +0 -733
  119. package/cli/lib/sweep-design-runtime/fix-topic.mjs +0 -414
  120. package/cli/lib/sweep-design-runtime/lifecycle.mjs +0 -54
  121. package/cli/lib/sweep-design-runtime/results.mjs +0 -324
  122. package/cli/lib/sweep-design.mjs +0 -8
  123. package/cli/lib/topic-artifacts.mjs +0 -186
  124. package/cli/lib/topic-authority-coverage.mjs +0 -73
  125. package/cli/lib/topic-closeout.mjs +0 -560
  126. package/cli/lib/topic-common.mjs +0 -404
  127. package/cli/lib/topic-decisions.mjs +0 -332
  128. package/cli/lib/topic-draft-packets.mjs +0 -167
  129. package/cli/lib/topic-execution.mjs +0 -533
  130. package/cli/lib/topic-goal.mjs +0 -440
  131. package/cli/lib/topic-ledger.mjs +0 -281
  132. package/cli/lib/topic-lifecycle-artifacts.mjs +0 -173
  133. package/cli/lib/topic-root-validation.mjs +0 -288
  134. package/cli/lib/topic-runner-commands.mjs +0 -174
  135. package/cli/lib/topic-runner-deferral.mjs +0 -532
  136. package/cli/lib/topic-runner-stale-gates.mjs +0 -114
  137. package/cli/lib/topic-runner-validation.mjs +0 -138
  138. package/cli/lib/topic-runner.mjs +0 -727
  139. package/cli/lib/topic-scaffold.mjs +0 -252
  140. package/cli/lib/topic-waves.mjs +0 -403
  141. package/cli/lib/topic.mjs +0 -81
  142. package/config/audit-execution-artifacts.yaml +0 -20
  143. package/config/external-execution-artifacts.yaml +0 -16
  144. package/config/host-adapter.yaml +0 -30
  145. package/config/host-profile.yaml +0 -29
  146. package/config/installer-evidence.yaml +0 -31
  147. package/config/skill-installer.yaml +0 -23
  148. package/config/skill-manifest.yaml +0 -48
  149. package/config/skills.yaml +0 -30
  150. package/contracts/acceptance.schema.yaml +0 -16
  151. package/contracts/admission-checklist.schema.yaml +0 -15
  152. package/contracts/audit-chunk.schema.yaml +0 -123
  153. package/contracts/audit-closeout.schema.yaml +0 -51
  154. package/contracts/audit-finding.schema.yaml +0 -61
  155. package/contracts/audit-ledger.schema.yaml +0 -138
  156. package/contracts/audit-plan.schema.yaml +0 -138
  157. package/contracts/audit-remediation-map.schema.yaml +0 -52
  158. package/contracts/audit-rerun.schema.yaml +0 -31
  159. package/contracts/audit-sweep-result.yaml +0 -53
  160. package/contracts/authority-convergence-audit.schema.yaml +0 -19
  161. package/contracts/closeout.schema.yaml +0 -25
  162. package/contracts/decision-review.schema.yaml +0 -16
  163. package/contracts/doc-spec-audit-result.yaml +0 -19
  164. package/contracts/execution-packet.schema.yaml +0 -49
  165. package/contracts/external-host-compatibility.yaml +0 -22
  166. package/contracts/forbidden-shortcuts.catalog.yaml +0 -23
  167. package/contracts/high-risk-admission.schema.yaml +0 -23
  168. package/contracts/high-risk-execution-result.yaml +0 -20
  169. package/contracts/orchestration-state.schema.yaml +0 -41
  170. package/contracts/overflow-continuation.schema.yaml +0 -12
  171. package/contracts/packet.schema.yaml +0 -30
  172. package/contracts/pending-note.schema.yaml +0 -17
  173. package/contracts/prompt.schema.yaml +0 -12
  174. package/contracts/remediation.schema.yaml +0 -16
  175. package/contracts/result.schema.yaml +0 -24
  176. package/contracts/spec-reconstruction-result.yaml +0 -41
  177. package/contracts/sweep-design-result.yaml +0 -349
  178. package/contracts/topic-goal.schema.yaml +0 -87
  179. package/contracts/topic-run-ledger.schema.yaml +0 -72
  180. package/contracts/topic-step-decision.schema.yaml +0 -45
  181. package/contracts/topic.schema.yaml +0 -65
  182. package/contracts/true-close.schema.yaml +0 -15
  183. package/contracts/wave.schema.yaml +0 -29
  184. package/contracts/worker-output.schema.yaml +0 -15
  185. package/contracts/workflow-consumer.schema.yaml +0 -110
  186. package/methodology/audit-sweep-p0p1-recall.yaml +0 -45
  187. package/methodology/authority-convergence-policy.yaml +0 -42
  188. package/methodology/overflow-continuation-policy.yaml +0 -14
  189. package/methodology/skill-exchange-projection.yaml +0 -114
  190. package/methodology/skill-handoff.yaml +0 -34
  191. package/methodology/skill-installer-result.yaml +0 -27
  192. package/methodology/skill-installer-summary-projection.yaml +0 -181
  193. package/methodology/skill-runtime.yaml +0 -23
  194. package/methodology/spec-target-truth-profile.yaml +0 -46
  195. package/methodology/topic-lifecycle-report.yaml +0 -144
  196. package/methodology/topic-lifecycle.yaml +0 -37
  197. package/methodology/topic-naming-ontology.yaml +0 -21
  198. package/methodology/topic-ontology.yaml +0 -38
  199. package/methodology/topic-validation-policy.yaml +0 -9
  200. package/methodology/wave-dag-policy.yaml +0 -14
  201. package/spec/_meta/command-gating-matrix.yaml +0 -143
  202. package/spec/_meta/generate-drift-migration-checklist.yaml +0 -137
  203. package/spec/_meta/governance-routing-cutover-checklist.yaml +0 -35
  204. package/spec/_meta/phase2-impacted-surface-matrix.yaml +0 -44
  205. package/spec/_meta/spec-authority-cutover-readiness.yaml +0 -102
  206. package/spec/bootstrap-state.yaml +0 -99
@@ -1,356 +0,0 @@
1
- import { criteriaEnableP0P1Recall } from "./p0p1-profile.mjs";
2
-
3
- function diagnostic(id, message, details = {}) {
4
- return { id, message, ...details };
5
- }
6
-
7
- function normalizeRefs(refs) {
8
- return Array.isArray(refs) ? refs.map((ref) => typeof ref === "string" ? ref.replace(/\\/g, "/") : ref) : [];
9
- }
10
-
11
- function normalizeFileRef(value) {
12
- return typeof value === "string" ? value.replace(/\\/g, "/") : null;
13
- }
14
-
15
- function isNonImplementationContextRef(ref) {
16
- if (typeof ref !== "string") {
17
- return false;
18
- }
19
- const normalized = ref.replace(/\\/g, "/");
20
- return /(^|\/)AGENTS\.md$/u.test(normalized)
21
- || /(^|\/)README\.md$/u.test(normalized)
22
- || normalized.startsWith(".nimi/spec/")
23
- || normalized.startsWith(".nimi/contracts/")
24
- || normalized.startsWith(".nimi/methodology/")
25
- || normalized.startsWith("package://@nimiplatform/nimi-coding/methodology/")
26
- || normalized.startsWith("package://@nimiplatform/nimi-coding/spec/");
27
- }
28
-
29
- const REQUIRED_P0P1_RULE_CHECK_IDS = [
30
- "fail_open_or_pseudo_success",
31
- "partial_coverage_misrepresented_as_complete",
32
- "authority_boundary_or_private_import_bypass",
33
- "permission_or_capability_bypass",
34
- "ungated_destructive_action",
35
- "provider_or_model_hardcoding",
36
- "app_local_shadow_truth",
37
- ];
38
- const REQUIRED_P0P1_RULE_CHECK_ID_SET = new Set(REQUIRED_P0P1_RULE_CHECK_IDS);
39
-
40
- function validateP0P1RuleChecks(evidence, implementationRefSet) {
41
- const ruleChecks = evidence?.coverage?.p0p1_rule_checks;
42
- if (!Array.isArray(ruleChecks) || ruleChecks.length === 0) {
43
- return {
44
- ok: false,
45
- missing: REQUIRED_P0P1_RULE_CHECK_IDS,
46
- invalid: [],
47
- checkedIds: [],
48
- };
49
- }
50
-
51
- const checkedIds = [];
52
- const invalid = [];
53
- const seenIds = new Set();
54
- for (const [index, check] of ruleChecks.entries()) {
55
- const id = typeof check?.id === "string" ? check.id : "";
56
- if (id) {
57
- checkedIds.push(id);
58
- if (!REQUIRED_P0P1_RULE_CHECK_ID_SET.has(id)) {
59
- invalid.push({ index, id, reason: "id must exactly match an admitted P0/P1 rule check id" });
60
- } else if (seenIds.has(id)) {
61
- invalid.push({ index, id, reason: "duplicate P0/P1 rule check id" });
62
- }
63
- seenIds.add(id);
64
- }
65
- const status = check?.status;
66
- if (!["checked", "not_applicable"].includes(status)) {
67
- invalid.push({ index, id, reason: "status must be checked or not_applicable" });
68
- continue;
69
- }
70
- const reasoning = typeof check?.negative_reasoning === "string" && check.negative_reasoning.trim().length > 0;
71
- if (!reasoning) {
72
- invalid.push({ index, id, reason: "negative_reasoning is required" });
73
- }
74
- const refs = normalizeRefs(check?.implementation_refs);
75
- if (status === "checked" && refs.length === 0) {
76
- invalid.push({ index, id, reason: "checked rule must cite implementation_refs" });
77
- }
78
- const outOfScopeRefs = refs.filter((ref) => !implementationRefSet.has(ref));
79
- if (outOfScopeRefs.length > 0) {
80
- invalid.push({ index, id, reason: "implementation_refs must belong to chunk implementation surface", invalid_refs: outOfScopeRefs });
81
- }
82
- }
83
-
84
- const checkedIdSet = new Set(checkedIds);
85
- const missing = REQUIRED_P0P1_RULE_CHECK_IDS.filter((id) => !checkedIdSet.has(id));
86
- return {
87
- ok: missing.length === 0 && invalid.length === 0,
88
- missing,
89
- invalid,
90
- checkedIds,
91
- };
92
- }
93
-
94
- function hasSemanticAuditorProvenance(evidence) {
95
- const provenance = evidence?.auditor?.provenance;
96
- if (!provenance || typeof provenance !== "object") {
97
- return false;
98
- }
99
- const kind = typeof provenance.kind === "string" ? provenance.kind : "";
100
- const packetRef = typeof provenance.packet_ref === "string" && provenance.packet_ref.trim().length > 0;
101
- const semanticTrace = [
102
- provenance.session_ref,
103
- provenance.transcript_ref,
104
- provenance.review_ref,
105
- ].some((ref) => typeof ref === "string" && ref.trim().length > 0);
106
- return kind === "semantic_audit" && packetRef && semanticTrace;
107
- }
108
-
109
- function looksSyntheticNoFindingEvidence(evidence) {
110
- const auditorMode = typeof evidence?.auditor?.mode === "string" ? evidence.auditor.mode : "";
111
- const generatedByScript = evidence?.auditor?.generated_by_script === true;
112
- const negativeReasoning = typeof evidence?.coverage?.p0p1_negative_reasoning === "string"
113
- ? evidence.coverage.p0p1_negative_reasoning
114
- : "";
115
- const templatedFragments = [
116
- "reading the complete chunk corpus through the local audit cache",
117
- "Lower-severity cleanup was intentionally summarized so the sweep preserved P0/P1 recall focus",
118
- "No critical/high fail-open, authority-boundary bypass, unadmitted truth promotion, partial coverage success",
119
- ];
120
- return generatedByScript
121
- || auditorMode.includes("script")
122
- || auditorMode.includes("local_full_sweep")
123
- || templatedFragments.some((fragment) => negativeReasoning.includes(fragment));
124
- }
125
-
126
- export function p0p1ImplementationRefsForChunk(chunk) {
127
- if (chunk?.planning_basis === "spec_authority") {
128
- return normalizeRefs(chunk?.evidence_inventory).filter((ref) => !isNonImplementationContextRef(ref));
129
- }
130
- return normalizeRefs(chunk?.files);
131
- }
132
-
133
- function expectedDefectMatchesFinding(expected, finding) {
134
- if (typeof expected?.root_cause_key === "string") {
135
- const findingRootCauseKey = finding?.root_cause?.key ?? finding?.root_cause_key ?? null;
136
- if (findingRootCauseKey !== expected.root_cause_key) {
137
- return false;
138
- }
139
- }
140
- if (typeof expected?.location_file === "string") {
141
- if (normalizeFileRef(finding?.location?.file) !== normalizeFileRef(expected.location_file)) {
142
- return false;
143
- }
144
- }
145
- if (typeof expected?.severity === "string" && finding?.severity !== expected.severity) {
146
- return false;
147
- }
148
- if (typeof expected?.category === "string" && finding?.category !== expected.category) {
149
- return false;
150
- }
151
- return true;
152
- }
153
-
154
- function findMissedCalibrationDefects(chunk, findings) {
155
- const expectedDefects = Array.isArray(chunk?.calibration_expected_defects)
156
- ? chunk.calibration_expected_defects.filter((entry) => typeof entry?.id === "string" && entry.id.trim().length > 0)
157
- : [];
158
- const missed = expectedDefects.filter((expected) => !findings.some((finding) => expectedDefectMatchesFinding(expected, finding)));
159
- return { expectedDefects, missed };
160
- }
161
-
162
- export function buildAuditValidityForEvidence(chunk, evidence) {
163
- const warnings = [];
164
- const blockers = [];
165
- const outcomes = Array.isArray(evidence?.coverage?.authority_outcomes) ? evidence.coverage.authority_outcomes : [];
166
- const findings = Array.isArray(evidence?.findings) ? evidence.findings : [];
167
- const evidenceInventory = Array.isArray(chunk?.evidence_inventory) ? chunk.evidence_inventory : [];
168
- const p0p1ImplementationRefs = p0p1ImplementationRefsForChunk(chunk);
169
- const evidenceInventorySet = new Set(evidenceInventory);
170
- const p0p1ImplementationRefSet = new Set(p0p1ImplementationRefs);
171
- const hasImplementationInventory = evidenceInventory.length > 0;
172
- const hasP0P1ImplementationInventory = p0p1ImplementationRefs.length > 0;
173
- const findingsEmpty = findings.length === 0;
174
- const p0p1RecallRequired = criteriaEnableP0P1Recall(chunk?.criteria);
175
- const hasP0P1Finding = findings.some((finding) => ["critical", "high"].includes(finding?.severity));
176
- let auditedWithImplementationEvidenceRefs = 0;
177
- let auditedWithoutImplementationEvidenceRefs = 0;
178
- let missingNegativeReasoning = 0;
179
- let authorityOnlyAuditedOutcomes = 0;
180
-
181
- for (const outcome of outcomes.filter((entry) => entry?.status === "audited")) {
182
- const explicitImplementationRefs = normalizeRefs(outcome.implementation_evidence_refs);
183
- const implementationRefs = explicitImplementationRefs.filter((ref) => evidenceInventorySet.has(ref));
184
- const notApplicableReason = typeof outcome.implementation_not_applicable_reason === "string"
185
- && outcome.implementation_not_applicable_reason.trim().length > 0;
186
- const evidenceRefs = normalizeRefs(outcome.evidence_refs);
187
- const evidenceRefsIncludeImplementation = evidenceRefs.some((ref) => evidenceInventorySet.has(ref));
188
- const negativeReasoning = typeof outcome.negative_reasoning === "string"
189
- && outcome.negative_reasoning.trim().length > 0;
190
-
191
- if (implementationRefs.length > 0) {
192
- auditedWithImplementationEvidenceRefs += 1;
193
- } else {
194
- auditedWithoutImplementationEvidenceRefs += 1;
195
- }
196
-
197
- if (hasImplementationInventory && !evidenceRefsIncludeImplementation && implementationRefs.length === 0 && !notApplicableReason) {
198
- authorityOnlyAuditedOutcomes += 1;
199
- }
200
- if (findingsEmpty && !negativeReasoning) {
201
- missingNegativeReasoning += 1;
202
- }
203
- }
204
-
205
- if (findingsEmpty && hasImplementationInventory && authorityOnlyAuditedOutcomes > 0) {
206
- blockers.push(diagnostic(
207
- "audited_outcome_authority_only_evidence_refs",
208
- "Audited no-finding outcomes cite only authority refs while implementation evidence inventory exists.",
209
- { outcome_count: authorityOnlyAuditedOutcomes },
210
- ));
211
- blockers.push(diagnostic(
212
- "no_finding_evidence_invalid",
213
- "No-finding evidence cannot prove that declared implementation evidence was reviewed.",
214
- ));
215
- }
216
-
217
- if (findingsEmpty && hasImplementationInventory && missingNegativeReasoning > 0) {
218
- blockers.push(diagnostic(
219
- "no_finding_negative_reasoning_missing",
220
- "No-finding evidence lacks per-outcome negative implementation reasoning.",
221
- { outcome_count: missingNegativeReasoning },
222
- ));
223
- }
224
-
225
- if (findingsEmpty && !hasImplementationInventory) {
226
- warnings.push(diagnostic(
227
- "empty_inventory_no_finding_weak",
228
- "Empty-inventory no-finding evidence is weak unless the empty-evidence reason and negative reasoning support it.",
229
- ));
230
- }
231
-
232
- if (p0p1RecallRequired && !hasP0P1Finding) {
233
- const p0p1NegativeReasoning = typeof evidence?.coverage?.p0p1_negative_reasoning === "string"
234
- && evidence.coverage.p0p1_negative_reasoning.trim().length > 0;
235
- const p0p1EvidenceRefs = normalizeRefs(evidence?.coverage?.p0p1_evidence_refs);
236
- const p0p1ImplementationNotApplicable = !hasP0P1ImplementationInventory
237
- && typeof evidence?.coverage?.p0p1_implementation_not_applicable_reason === "string"
238
- && evidence.coverage.p0p1_implementation_not_applicable_reason.trim().length > 0;
239
- const invalidP0P1EvidenceRefs = p0p1EvidenceRefs.filter((ref) => !p0p1ImplementationRefSet.has(ref));
240
- const hasP0P1ImplementationRef = p0p1EvidenceRefs.length > 0 && invalidP0P1EvidenceRefs.length === 0;
241
- const syntheticNoFindingEvidence = looksSyntheticNoFindingEvidence(evidence);
242
- if (invalidP0P1EvidenceRefs.length > 0) {
243
- blockers.push(diagnostic(
244
- "p0p1_evidence_refs_out_of_scope",
245
- "P0/P1 evidence refs must all belong to the chunk implementation surface.",
246
- { invalid_refs: invalidP0P1EvidenceRefs },
247
- ));
248
- }
249
- if (!p0p1NegativeReasoning || (!hasP0P1ImplementationRef && !p0p1ImplementationNotApplicable)) {
250
- blockers.push(diagnostic(
251
- "p0p1_negative_reasoning_missing",
252
- "P0/P1 recall evidence without critical/high findings must include P0/P1 negative reasoning and implementation evidence refs, or an explicit not-applicable reason when no implementation inventory exists.",
253
- {
254
- p0p1_negative_reasoning_present: p0p1NegativeReasoning,
255
- p0p1_implementation_evidence_refs_present: hasP0P1ImplementationRef,
256
- p0p1_implementation_not_applicable_reason_present: p0p1ImplementationNotApplicable,
257
- },
258
- ));
259
- }
260
- if (syntheticNoFindingEvidence) {
261
- blockers.push(diagnostic(
262
- "synthetic_no_finding_evidence",
263
- "P0/P1 no-finding evidence appears to be generated by a script or bulk template rather than a semantic audit.",
264
- ));
265
- }
266
- if (hasP0P1ImplementationInventory) {
267
- if (!hasSemanticAuditorProvenance(evidence)) {
268
- blockers.push(diagnostic(
269
- "auditor_provenance_missing",
270
- "P0/P1 no-finding evidence with implementation inventory must cite semantic auditor provenance.",
271
- {
272
- required_kind: "semantic_audit",
273
- required_fields: ["auditor.provenance.packet_ref", "auditor.provenance.session_ref|transcript_ref|review_ref"],
274
- },
275
- ));
276
- }
277
- const ruleCheckValidity = validateP0P1RuleChecks(evidence, p0p1ImplementationRefSet);
278
- if (!ruleCheckValidity.ok) {
279
- blockers.push(diagnostic(
280
- "p0p1_rule_checks_missing_or_invalid",
281
- "P0/P1 no-finding evidence with implementation inventory must record rule-specific checks over the chunk implementation surface.",
282
- {
283
- missing_rule_check_ids: ruleCheckValidity.missing,
284
- invalid_rule_checks: ruleCheckValidity.invalid,
285
- present_rule_check_ids: ruleCheckValidity.checkedIds,
286
- },
287
- ));
288
- }
289
- }
290
- }
291
-
292
- const calibration = findMissedCalibrationDefects(chunk, findings);
293
- if (calibration.missed.length > 0) {
294
- blockers.push(diagnostic(
295
- "calibration_known_defect_missed",
296
- "Calibration evidence missed one or more expected known defects.",
297
- {
298
- expected_defect_count: calibration.expectedDefects.length,
299
- missed_defect_ids: calibration.missed.map((defect) => defect.id),
300
- },
301
- ));
302
- }
303
-
304
- return {
305
- posture: blockers.length > 0 ? "invalid" : warnings.length > 0 ? "warning" : "trusted",
306
- no_finding_posture: findings.length > 0 ? "not_applicable" : blockers.length > 0 ? "invalid" : warnings.length > 0 ? "weak" : "explained",
307
- audited_outcomes_with_implementation_evidence_refs: auditedWithImplementationEvidenceRefs,
308
- audited_outcomes_without_implementation_evidence_refs: auditedWithoutImplementationEvidenceRefs,
309
- zero_finding_chunk_count: findingsEmpty ? 1 : 0,
310
- large_zero_finding_chunk_count: findingsEmpty && evidenceInventory.length >= 10 ? 1 : 0,
311
- negative_reasoning_present: !findingsEmpty || (outcomes.length > 0 && missingNegativeReasoning === 0),
312
- p0p1_recall_required: p0p1RecallRequired,
313
- p0p1_recall_posture: !p0p1RecallRequired ? "not_applicable" : hasP0P1Finding ? "p0p1_finding_present" : blockers.length > 0 ? "invalid" : "explained",
314
- p0p1_rule_check_count: Array.isArray(evidence?.coverage?.p0p1_rule_checks) ? evidence.coverage.p0p1_rule_checks.length : 0,
315
- auditor_provenance_present: !findingsEmpty || hasSemanticAuditorProvenance(evidence),
316
- calibration_expected_defect_count: calibration.expectedDefects.length,
317
- calibration_missed_defect_count: calibration.missed.length,
318
- warnings,
319
- blockers,
320
- };
321
- }
322
-
323
- export function combineAuditValidity(entries) {
324
- const validEntries = entries.filter(Boolean);
325
- const warnings = validEntries.flatMap((entry) => entry.warnings ?? []);
326
- const blockers = validEntries.flatMap((entry) => entry.blockers ?? []);
327
- const zeroFindingChunkCount = validEntries.reduce((total, entry) => total + (entry.zero_finding_chunk_count ?? 0), 0);
328
- const largeZeroFindingChunkCount = validEntries.reduce((total, entry) => total + (entry.large_zero_finding_chunk_count ?? 0), 0);
329
- const withImplementation = validEntries.reduce((total, entry) => total + (entry.audited_outcomes_with_implementation_evidence_refs ?? 0), 0);
330
- const withoutImplementation = validEntries.reduce((total, entry) => total + (entry.audited_outcomes_without_implementation_evidence_refs ?? 0), 0);
331
- const calibrationExpectedDefectCount = validEntries.reduce((total, entry) => total + (entry.calibration_expected_defect_count ?? 0), 0);
332
- const calibrationMissedDefectCount = validEntries.reduce((total, entry) => total + (entry.calibration_missed_defect_count ?? 0), 0);
333
- const p0p1RecallRequiredCount = validEntries.reduce((total, entry) => total + (entry.p0p1_recall_required ? 1 : 0), 0);
334
- const p0p1InvalidCount = validEntries.reduce((total, entry) => total + (entry.p0p1_recall_posture === "invalid" ? 1 : 0), 0);
335
- const p0p1RuleCheckCount = validEntries.reduce((total, entry) => total + (entry.p0p1_rule_check_count ?? 0), 0);
336
- const anyInvalid = validEntries.some((entry) => entry.posture === "invalid");
337
- const anyWarning = validEntries.some((entry) => entry.posture === "warning");
338
-
339
- return {
340
- posture: anyInvalid ? "invalid" : anyWarning ? "warning" : "trusted",
341
- no_finding_posture: anyInvalid ? "invalid" : anyWarning ? "weak" : zeroFindingChunkCount > 0 ? "explained" : "not_applicable",
342
- audited_outcomes_with_implementation_evidence_refs: withImplementation,
343
- audited_outcomes_without_implementation_evidence_refs: withoutImplementation,
344
- zero_finding_chunk_count: zeroFindingChunkCount,
345
- large_zero_finding_chunk_count: largeZeroFindingChunkCount,
346
- negative_reasoning_present: validEntries.every((entry) => entry.negative_reasoning_present !== false),
347
- p0p1_recall_required_count: p0p1RecallRequiredCount,
348
- p0p1_recall_invalid_count: p0p1InvalidCount,
349
- p0p1_rule_check_count: p0p1RuleCheckCount,
350
- auditor_provenance_present: validEntries.every((entry) => entry.auditor_provenance_present !== false),
351
- calibration_expected_defect_count: calibrationExpectedDefectCount,
352
- calibration_missed_defect_count: calibrationMissedDefectCount,
353
- warnings,
354
- blockers,
355
- };
356
- }