@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.
- package/CHANGELOG.md +10 -90
- package/CONTRIBUTING.md +5 -34
- package/README.md +47 -350
- package/README.zh-CN.md +33 -287
- package/cli/commands/start.mjs +48 -688
- package/cli/commands/validate-spec-audit.mjs +1 -5
- package/cli/commands/validate-spec-governance.mjs +20 -0
- package/cli/constants.mjs +9 -417
- package/cli/help.mjs +28 -145
- package/cli/index.mjs +5 -33
- package/cli/lib/blueprint-audit.mjs +5 -12
- package/cli/lib/bootstrap.mjs +0 -9
- package/cli/lib/contracts.mjs +0 -163
- package/cli/lib/doctor.mjs +155 -10
- package/cli/lib/entrypoints.mjs +63 -167
- package/cli/lib/internal/contracts-loaders.mjs +0 -85
- package/cli/lib/internal/contracts-parse.mjs +84 -520
- package/cli/lib/internal/governance/ai/check-agents-freshness.mjs +13 -8
- package/cli/lib/internal/surface-taxonomy-validators.mjs +316 -66
- package/cli/lib/internal/validators-shared.mjs +0 -16
- package/cli/lib/internal/validators-spec-helpers.mjs +7 -140
- package/cli/lib/internal/validators-spec.mjs +103 -342
- package/cli/lib/shared.mjs +1 -42
- package/cli/lib/validators.mjs +0 -48
- package/cli/seeds/seed-policy.yaml +0 -3
- package/config/bootstrap.yaml +4 -4
- package/config/spec-generation-inputs.yaml +6 -12
- package/contracts/domain-admission.schema.yaml +3 -3
- package/contracts/migration-inventory.schema.yaml +12 -75
- package/contracts/negative-fixtures.yaml +19 -99
- package/contracts/placement-contract.schema.yaml +49 -78
- package/contracts/projection-edge.schema.yaml +37 -121
- package/contracts/shared-enums.yaml +4 -8
- package/contracts/spec-generation-inputs.schema.yaml +15 -112
- package/contracts/spec-layout.schema.yaml +32 -0
- package/contracts/surface-taxonomy.schema.yaml +43 -94
- package/contracts/table-family.schema.yaml +1 -1
- package/contracts/tracked-output-admission.schema.yaml +13 -66
- package/methodology/core.yaml +33 -25
- package/methodology/four-closure-policy.yaml +18 -26
- package/methodology/role-separation-policy.yaml +21 -27
- package/methodology/spec-reconstruction.yaml +17 -34
- package/package.json +2 -4
- package/spec/_meta/spec-tree-model.yaml +5 -101
- package/spec/product-scope.yaml +25 -57
- package/adapters/README.md +0 -25
- package/adapters/claude/README.md +0 -89
- package/adapters/claude/profile.yaml +0 -70
- package/adapters/codex/README.md +0 -53
- package/adapters/codex/profile.yaml +0 -78
- package/adapters/oh-my-codex/README.md +0 -184
- package/adapters/oh-my-codex/profile.yaml +0 -46
- package/cli/commands/admit-high-risk-decision.mjs +0 -108
- package/cli/commands/audit-sweep.mjs +0 -364
- package/cli/commands/closeout.mjs +0 -186
- package/cli/commands/decide-high-risk-execution.mjs +0 -124
- package/cli/commands/handoff.mjs +0 -123
- package/cli/commands/ingest-high-risk-execution.mjs +0 -95
- package/cli/commands/review-high-risk-execution.mjs +0 -95
- package/cli/commands/sweep-design.mjs +0 -295
- package/cli/commands/sweep.mjs +0 -22
- package/cli/commands/topic-formatters.mjs +0 -382
- package/cli/commands/topic-goal.mjs +0 -33
- package/cli/commands/topic-options-shared.mjs +0 -27
- package/cli/commands/topic-options-workflow.mjs +0 -767
- package/cli/commands/topic-options.mjs +0 -626
- package/cli/commands/topic-runner.mjs +0 -169
- package/cli/commands/topic.mjs +0 -795
- package/cli/commands/validate-acceptance.mjs +0 -5
- package/cli/commands/validate-execution-packet.mjs +0 -5
- package/cli/commands/validate-orchestration-state.mjs +0 -5
- package/cli/commands/validate-prompt.mjs +0 -5
- package/cli/commands/validate-worker-output.mjs +0 -5
- package/cli/lib/adapter-profiles.mjs +0 -403
- package/cli/lib/audit-execution.mjs +0 -52
- package/cli/lib/audit-sweep-runtime/admissions.mjs +0 -508
- package/cli/lib/audit-sweep-runtime/audit-validity.mjs +0 -356
- package/cli/lib/audit-sweep-runtime/chunks.mjs +0 -697
- package/cli/lib/audit-sweep-runtime/claude-auditor.mjs +0 -658
- package/cli/lib/audit-sweep-runtime/closeout.mjs +0 -144
- package/cli/lib/audit-sweep-runtime/codex-auditor-evidence.mjs +0 -654
- package/cli/lib/audit-sweep-runtime/codex-auditor.mjs +0 -527
- package/cli/lib/audit-sweep-runtime/common.mjs +0 -341
- package/cli/lib/audit-sweep-runtime/coverage-quality.mjs +0 -172
- package/cli/lib/audit-sweep-runtime/evidence-assignment.mjs +0 -155
- package/cli/lib/audit-sweep-runtime/format.mjs +0 -57
- package/cli/lib/audit-sweep-runtime/ingest.mjs +0 -486
- package/cli/lib/audit-sweep-runtime/inventory-spec-chunks.mjs +0 -425
- package/cli/lib/audit-sweep-runtime/inventory.mjs +0 -798
- package/cli/lib/audit-sweep-runtime/ledger.mjs +0 -315
- package/cli/lib/audit-sweep-runtime/p0p1-profile.mjs +0 -101
- package/cli/lib/audit-sweep-runtime/remediation.mjs +0 -349
- package/cli/lib/audit-sweep-runtime/rerun.mjs +0 -129
- package/cli/lib/audit-sweep-runtime/risk-budget.mjs +0 -300
- package/cli/lib/audit-sweep-runtime/status.mjs +0 -62
- package/cli/lib/audit-sweep-runtime/validators-ledger.mjs +0 -215
- package/cli/lib/audit-sweep-runtime/validators.mjs +0 -797
- package/cli/lib/audit-sweep.mjs +0 -19
- package/cli/lib/authority-convergence.mjs +0 -720
- package/cli/lib/closeout.mjs +0 -732
- package/cli/lib/codex-sdk-runner.mjs +0 -76
- package/cli/lib/external-execution.mjs +0 -101
- package/cli/lib/handoff.mjs +0 -812
- package/cli/lib/high-risk-admission.mjs +0 -512
- package/cli/lib/high-risk-decision.mjs +0 -353
- package/cli/lib/high-risk-ingest.mjs +0 -321
- package/cli/lib/high-risk-review.mjs +0 -267
- package/cli/lib/internal/contracts-parse-high-risk.mjs +0 -131
- package/cli/lib/internal/contracts-validators.mjs +0 -399
- package/cli/lib/internal/doctor-bootstrap-surface.mjs +0 -406
- package/cli/lib/internal/doctor-delegated-surface.mjs +0 -256
- package/cli/lib/internal/doctor-finalize.mjs +0 -383
- package/cli/lib/internal/doctor-format.mjs +0 -286
- package/cli/lib/internal/doctor-inspectors.mjs +0 -327
- package/cli/lib/internal/doctor-state.mjs +0 -205
- package/cli/lib/internal/validators-artifacts.mjs +0 -515
- package/cli/lib/sweep-design-runtime/common.mjs +0 -246
- package/cli/lib/sweep-design-runtime/engine.mjs +0 -733
- package/cli/lib/sweep-design-runtime/fix-topic.mjs +0 -414
- package/cli/lib/sweep-design-runtime/lifecycle.mjs +0 -54
- package/cli/lib/sweep-design-runtime/results.mjs +0 -324
- package/cli/lib/sweep-design.mjs +0 -8
- package/cli/lib/topic-artifacts.mjs +0 -186
- package/cli/lib/topic-authority-coverage.mjs +0 -73
- package/cli/lib/topic-closeout.mjs +0 -560
- package/cli/lib/topic-common.mjs +0 -404
- package/cli/lib/topic-decisions.mjs +0 -332
- package/cli/lib/topic-draft-packets.mjs +0 -167
- package/cli/lib/topic-execution.mjs +0 -533
- package/cli/lib/topic-goal.mjs +0 -440
- package/cli/lib/topic-ledger.mjs +0 -281
- package/cli/lib/topic-lifecycle-artifacts.mjs +0 -173
- package/cli/lib/topic-root-validation.mjs +0 -288
- package/cli/lib/topic-runner-commands.mjs +0 -174
- package/cli/lib/topic-runner-deferral.mjs +0 -532
- package/cli/lib/topic-runner-stale-gates.mjs +0 -114
- package/cli/lib/topic-runner-validation.mjs +0 -138
- package/cli/lib/topic-runner.mjs +0 -727
- package/cli/lib/topic-scaffold.mjs +0 -252
- package/cli/lib/topic-waves.mjs +0 -403
- package/cli/lib/topic.mjs +0 -81
- package/config/audit-execution-artifacts.yaml +0 -20
- package/config/external-execution-artifacts.yaml +0 -16
- package/config/host-adapter.yaml +0 -30
- package/config/host-profile.yaml +0 -29
- package/config/installer-evidence.yaml +0 -31
- package/config/skill-installer.yaml +0 -23
- package/config/skill-manifest.yaml +0 -48
- package/config/skills.yaml +0 -30
- package/contracts/acceptance.schema.yaml +0 -16
- package/contracts/admission-checklist.schema.yaml +0 -15
- package/contracts/audit-chunk.schema.yaml +0 -123
- package/contracts/audit-closeout.schema.yaml +0 -51
- package/contracts/audit-finding.schema.yaml +0 -61
- package/contracts/audit-ledger.schema.yaml +0 -138
- package/contracts/audit-plan.schema.yaml +0 -138
- package/contracts/audit-remediation-map.schema.yaml +0 -52
- package/contracts/audit-rerun.schema.yaml +0 -31
- package/contracts/audit-sweep-result.yaml +0 -53
- package/contracts/authority-convergence-audit.schema.yaml +0 -19
- package/contracts/closeout.schema.yaml +0 -25
- package/contracts/decision-review.schema.yaml +0 -16
- package/contracts/doc-spec-audit-result.yaml +0 -19
- package/contracts/execution-packet.schema.yaml +0 -49
- package/contracts/external-host-compatibility.yaml +0 -22
- package/contracts/forbidden-shortcuts.catalog.yaml +0 -23
- package/contracts/high-risk-admission.schema.yaml +0 -23
- package/contracts/high-risk-execution-result.yaml +0 -20
- package/contracts/orchestration-state.schema.yaml +0 -41
- package/contracts/overflow-continuation.schema.yaml +0 -12
- package/contracts/packet.schema.yaml +0 -30
- package/contracts/pending-note.schema.yaml +0 -17
- package/contracts/prompt.schema.yaml +0 -12
- package/contracts/remediation.schema.yaml +0 -16
- package/contracts/result.schema.yaml +0 -24
- package/contracts/spec-reconstruction-result.yaml +0 -41
- package/contracts/sweep-design-result.yaml +0 -349
- package/contracts/topic-goal.schema.yaml +0 -87
- package/contracts/topic-run-ledger.schema.yaml +0 -72
- package/contracts/topic-step-decision.schema.yaml +0 -45
- package/contracts/topic.schema.yaml +0 -65
- package/contracts/true-close.schema.yaml +0 -15
- package/contracts/wave.schema.yaml +0 -29
- package/contracts/worker-output.schema.yaml +0 -15
- package/contracts/workflow-consumer.schema.yaml +0 -110
- package/methodology/audit-sweep-p0p1-recall.yaml +0 -45
- package/methodology/authority-convergence-policy.yaml +0 -42
- package/methodology/overflow-continuation-policy.yaml +0 -14
- package/methodology/skill-exchange-projection.yaml +0 -114
- package/methodology/skill-handoff.yaml +0 -34
- package/methodology/skill-installer-result.yaml +0 -27
- package/methodology/skill-installer-summary-projection.yaml +0 -181
- package/methodology/skill-runtime.yaml +0 -23
- package/methodology/spec-target-truth-profile.yaml +0 -46
- package/methodology/topic-lifecycle-report.yaml +0 -144
- package/methodology/topic-lifecycle.yaml +0 -37
- package/methodology/topic-naming-ontology.yaml +0 -21
- package/methodology/topic-ontology.yaml +0 -38
- package/methodology/topic-validation-policy.yaml +0 -9
- package/methodology/wave-dag-policy.yaml +0 -14
- package/spec/_meta/command-gating-matrix.yaml +0 -143
- package/spec/_meta/generate-drift-migration-checklist.yaml +0 -137
- package/spec/_meta/governance-routing-cutover-checklist.yaml +0 -35
- package/spec/_meta/phase2-impacted-surface-matrix.yaml +0 -44
- package/spec/_meta/spec-authority-cutover-readiness.yaml +0 -102
- package/spec/bootstrap-state.yaml +0 -99
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import { specSurfaceForFile } from "./admissions.mjs";
|
|
4
|
-
|
|
5
|
-
function evidenceRootsForSpecOwner(ownerDomain, targetRootRef) {
|
|
6
|
-
if (targetRootRef !== ".") {
|
|
7
|
-
return [targetRootRef];
|
|
8
|
-
}
|
|
9
|
-
const owner = String(ownerDomain ?? "").trim().replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
10
|
-
if (!owner || owner === "spec-meta" || owner === "spec-root") {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
if (owner === "project") {
|
|
14
|
-
return ["src", "lib", "packages", "apps", "tools", "services"];
|
|
15
|
-
}
|
|
16
|
-
return [
|
|
17
|
-
owner,
|
|
18
|
-
`nimi-${owner}`,
|
|
19
|
-
`src/${owner}`,
|
|
20
|
-
`lib/${owner}`,
|
|
21
|
-
`packages/${owner}`,
|
|
22
|
-
`packages/nimi-${owner}`,
|
|
23
|
-
`apps/${owner}`,
|
|
24
|
-
`tools/${owner}`,
|
|
25
|
-
`services/${owner}`,
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const DECLARED_EVIDENCE_REF_PATTERN = /(?:^|[\s"'`([{:;,])((?:\.\/)?(?:[A-Za-z0-9_.@+-]+\/)+[A-Za-z0-9_@+.-]+\.(?:cjs|css|go|js|jsx|json|md|mjs|prisma|proto|py|rs|ts|tsx|yaml|yml))(?:[#:)\\\],;."'`]|\s|$)/gu;
|
|
30
|
-
|
|
31
|
-
function looksLikeSpecAuthorityRelativeRef(normalized) {
|
|
32
|
-
const extension = path.posix.extname(normalized);
|
|
33
|
-
if (![".md", ".yaml", ".yml"].includes(extension)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const parts = normalized.split("/");
|
|
37
|
-
const firstSegment = parts[0];
|
|
38
|
-
if (["tables", "generated", "kernel"].includes(firstSegment)) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
if (parts[1] === "kernel") {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
const specDomainLike = /^(backend|dashboard|realm|runtime|v[0-9]+|vision|workers)$/u.test(firstSegment);
|
|
45
|
-
return specDomainLike && parts.length <= 2;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function normalizeDeclaredEvidenceRef(value) {
|
|
49
|
-
const raw = String(value ?? "")
|
|
50
|
-
.trim()
|
|
51
|
-
.replace(/\\/g, "/")
|
|
52
|
-
.replace(/[),.;:]+$/u, "");
|
|
53
|
-
if (!raw || raw.startsWith("../") || raw.includes("/../") || raw.startsWith("http:") || raw.startsWith("https:")) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
if (raw.startsWith("@") || raw.startsWith("./")) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
const normalized = raw.replace(/^\.\//, "");
|
|
60
|
-
if (!normalized || normalized.startsWith("../") || normalized.includes("/../") || normalized.startsWith("http:") || normalized.startsWith("https:")) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
if (!normalized.includes("/")) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
const firstSegment = normalized.split("/")[0];
|
|
67
|
-
if (looksLikeSpecAuthorityRelativeRef(normalized)) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
if (
|
|
71
|
-
normalized.startsWith(".nimi/spec/")
|
|
72
|
-
|| normalized.startsWith(".nimi/contracts/")
|
|
73
|
-
|| normalized.startsWith(".nimi/methodology/")
|
|
74
|
-
|| normalized.startsWith(".nimi/local/")
|
|
75
|
-
|| normalized.startsWith(".agents/")
|
|
76
|
-
|| normalized.startsWith(".claude/")
|
|
77
|
-
|| normalized.startsWith(".openclaw/")
|
|
78
|
-
|| normalized.includes("/.nimi/spec/")
|
|
79
|
-
|| normalized.includes("/.nimi/contracts/")
|
|
80
|
-
|| normalized.includes("/.nimi/methodology/")
|
|
81
|
-
) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
const basename = path.posix.basename(normalized).toLowerCase();
|
|
85
|
-
if (basename === "agents.md" || basename === "readme.md") {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return normalized;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function candidateEvidenceRefsForDeclaredRef(declaredRef, evidenceRoots) {
|
|
92
|
-
const normalized = String(declaredRef ?? "").replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
|
|
93
|
-
if (!normalized) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
const candidates = [normalized];
|
|
97
|
-
for (const rootRef of evidenceRoots ?? []) {
|
|
98
|
-
const root = String(rootRef ?? "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
99
|
-
if (!root || root === "." || root.startsWith(".nimi/spec") || path.posix.extname(root)) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (normalized === root || normalized.startsWith(`${root}/`)) {
|
|
103
|
-
candidates.push(normalized);
|
|
104
|
-
} else {
|
|
105
|
-
candidates.push(`${root}/${normalized}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return [...new Set(candidates)].sort();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function normalizedRef(value) {
|
|
112
|
-
return String(value ?? "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function refInsideRoot(fileRef, rootRef) {
|
|
116
|
-
const root = normalizedRef(rootRef);
|
|
117
|
-
return Boolean(root) && (fileRef === root || fileRef.startsWith(`${root}/`));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function delegatedProjectionAdmissionForFile(fileRef, admissions = []) {
|
|
121
|
-
return admissions.find((admission) => {
|
|
122
|
-
if (!refInsideRoot(fileRef, admission.authority_root)) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const relative = fileRef === admission.authority_root
|
|
126
|
-
? ""
|
|
127
|
-
: fileRef.slice(admission.authority_root.length + 1);
|
|
128
|
-
return !(admission.host_owned_relative_paths ?? []).some((hostOwnedPath) => (
|
|
129
|
-
relative === hostOwnedPath || relative.startsWith(`${hostOwnedPath}/`)
|
|
130
|
-
));
|
|
131
|
-
}) ?? null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function declaredRefDelegated(ref, prefixes = []) {
|
|
135
|
-
const normalized = normalizedRef(ref);
|
|
136
|
-
return prefixes.some((prefix) => {
|
|
137
|
-
const normalizedPrefix = normalizedRef(prefix);
|
|
138
|
-
return normalizedPrefix && (normalized === normalizedPrefix || normalized.startsWith(`${normalizedPrefix}/`));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function extractDeclaredEvidenceRefs(text) {
|
|
143
|
-
const refs = [];
|
|
144
|
-
for (const match of String(text ?? "").matchAll(DECLARED_EVIDENCE_REF_PATTERN)) {
|
|
145
|
-
const normalized = normalizeDeclaredEvidenceRef(match[1]);
|
|
146
|
-
if (normalized) {
|
|
147
|
-
refs.push(normalized);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return [...new Set(refs)].sort();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function slugPart(value) {
|
|
154
|
-
return String(value)
|
|
155
|
-
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
156
|
-
.replace(/^-+|-+$/g, "")
|
|
157
|
-
.toLowerCase() || "spec";
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function extractModuleMapRefs(markdownText) {
|
|
161
|
-
const lines = String(markdownText ?? "").split(/\r?\n/);
|
|
162
|
-
const refs = [];
|
|
163
|
-
let inModuleMap = false;
|
|
164
|
-
for (const line of lines) {
|
|
165
|
-
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
|
|
166
|
-
if (heading) {
|
|
167
|
-
const headingText = heading[2].trim().toLowerCase();
|
|
168
|
-
if (headingText === "module map") {
|
|
169
|
-
inModuleMap = true;
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
if (inModuleMap && heading[1].length <= 2) {
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (!inModuleMap) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
const match = /^\s*[-*]\s+`([^`]+)`/.exec(line);
|
|
180
|
-
if (match) {
|
|
181
|
-
refs.push(match[1].trim());
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return [...new Set(refs)].sort();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function buildDelegatedProjectionChunk({
|
|
188
|
-
admission,
|
|
189
|
-
entries,
|
|
190
|
-
chunkIndex,
|
|
191
|
-
criteria,
|
|
192
|
-
authorityTextByRef,
|
|
193
|
-
}) {
|
|
194
|
-
const authorityRefs = entries.map((entry) => entry.file_ref).sort();
|
|
195
|
-
const authorityText = authorityRefs
|
|
196
|
-
.map((authorityRef) => authorityTextByRef?.get(authorityRef) ?? "")
|
|
197
|
-
.join("\n");
|
|
198
|
-
const declaredEvidenceRefs = extractDeclaredEvidenceRefs(authorityText);
|
|
199
|
-
const delegatedDeclaredEvidenceRefs = declaredEvidenceRefs
|
|
200
|
-
.filter((ref) => declaredRefDelegated(ref, admission.delegated_declared_evidence_prefixes))
|
|
201
|
-
.sort();
|
|
202
|
-
const localDeclaredEvidenceRefs = declaredEvidenceRefs
|
|
203
|
-
.filter((ref) => !declaredRefDelegated(ref, admission.delegated_declared_evidence_prefixes))
|
|
204
|
-
.sort();
|
|
205
|
-
const evidenceRoots = [...new Set(admission.local_projection_evidence_roots ?? [])].sort();
|
|
206
|
-
const declaredEvidenceTargets = localDeclaredEvidenceRefs
|
|
207
|
-
.map((evidenceRef) => ({
|
|
208
|
-
source_path: evidenceRef,
|
|
209
|
-
candidates: candidateEvidenceRefsForDeclaredRef(evidenceRef, evidenceRoots),
|
|
210
|
-
}))
|
|
211
|
-
.filter((target) => target.candidates.length > 0);
|
|
212
|
-
return {
|
|
213
|
-
chunk_id: [
|
|
214
|
-
`chunk-${String(chunkIndex).padStart(3, "0")}`,
|
|
215
|
-
slugPart(admission.owner_domain),
|
|
216
|
-
"delegated-projection",
|
|
217
|
-
slugPart(admission.id),
|
|
218
|
-
].join("-"),
|
|
219
|
-
state: "planned",
|
|
220
|
-
owner_domain: admission.owner_domain,
|
|
221
|
-
planning_basis: "spec_authority",
|
|
222
|
-
spec_surface: "delegated-projection",
|
|
223
|
-
criteria,
|
|
224
|
-
files: authorityRefs,
|
|
225
|
-
authority_refs: authorityRefs,
|
|
226
|
-
authority_kind: "delegated_projection",
|
|
227
|
-
delegated_projection_id: admission.id,
|
|
228
|
-
admission_ref: admission.admission_ref,
|
|
229
|
-
authority_root: admission.authority_root,
|
|
230
|
-
source_authority_root: admission.source_authority_root,
|
|
231
|
-
admitted_evidence_roots: evidenceRoots,
|
|
232
|
-
delegated_evidence_roots: admission.delegated_evidence_roots,
|
|
233
|
-
delegated_declared_evidence_prefixes: admission.delegated_declared_evidence_prefixes,
|
|
234
|
-
...(delegatedDeclaredEvidenceRefs.length > 0 ? {
|
|
235
|
-
delegated_declared_evidence_refs: delegatedDeclaredEvidenceRefs,
|
|
236
|
-
declared_evidence_delegation: {
|
|
237
|
-
status: "delegated_to_source_authority",
|
|
238
|
-
delegated_ref_count: delegatedDeclaredEvidenceRefs.length,
|
|
239
|
-
source_authority_root: admission.source_authority_root,
|
|
240
|
-
delegated_evidence_roots: admission.delegated_evidence_roots,
|
|
241
|
-
},
|
|
242
|
-
} : {}),
|
|
243
|
-
...(admission.required_verification_commands?.length > 0 ? {
|
|
244
|
-
required_verification_commands: admission.required_verification_commands,
|
|
245
|
-
} : {}),
|
|
246
|
-
...(declaredEvidenceTargets.length > 0 ? {
|
|
247
|
-
declared_evidence_targets: declaredEvidenceTargets,
|
|
248
|
-
} : {}),
|
|
249
|
-
evidence_roots: evidenceRoots,
|
|
250
|
-
file_count: authorityRefs.length,
|
|
251
|
-
finding_count: 0,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function candidateEvidenceRefsForModuleMapPath(modulePath, evidenceRoots) {
|
|
256
|
-
const normalized = String(modulePath ?? "").replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
|
|
257
|
-
if (!normalized || normalized.startsWith("http:") || normalized.startsWith("https:")) {
|
|
258
|
-
return [];
|
|
259
|
-
}
|
|
260
|
-
const firstSegment = normalized.split("/")[0];
|
|
261
|
-
const genericDirectRoots = new Set([".github", ".nimi", "apps", "config", "lib", "packages", "scripts", "services", "src", "tools"]);
|
|
262
|
-
const directRoot = genericDirectRoots.has(firstSegment)
|
|
263
|
-
|| (evidenceRoots ?? []).some((rootRef) => {
|
|
264
|
-
const root = String(rootRef ?? "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
265
|
-
return root !== "." && (normalized === root || normalized.startsWith(`${root}/`));
|
|
266
|
-
});
|
|
267
|
-
const candidates = [];
|
|
268
|
-
if (directRoot) {
|
|
269
|
-
candidates.push(normalized);
|
|
270
|
-
}
|
|
271
|
-
for (const rootRef of evidenceRoots ?? []) {
|
|
272
|
-
const root = String(rootRef ?? "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
273
|
-
if (!root || root.startsWith(".nimi/spec")) {
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
candidates.push(`${root}/${normalized}`);
|
|
277
|
-
if (root.startsWith("apps/")) {
|
|
278
|
-
candidates.push(`${root}/src/${normalized}`);
|
|
279
|
-
candidates.push(`${root}/src/shell/renderer/${normalized}`);
|
|
280
|
-
candidates.push(`${root}/src-tauri/src/${normalized}`);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return [...new Set(candidates)].sort();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export function buildSpecChunks(includedInventory, options) {
|
|
287
|
-
const sortedEntries = [...includedInventory].sort((left, right) => left.file_ref.localeCompare(right.file_ref));
|
|
288
|
-
const includedRefs = new Set(sortedEntries.map((entry) => entry.file_ref));
|
|
289
|
-
const delegatedEntriesByAdmissionRef = new Map();
|
|
290
|
-
for (const entry of sortedEntries) {
|
|
291
|
-
const admission = delegatedProjectionAdmissionForFile(entry.file_ref, options.delegatedProjectionAdmissions);
|
|
292
|
-
if (!admission) {
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
const entries = delegatedEntriesByAdmissionRef.get(admission.admission_ref) ?? [];
|
|
296
|
-
entries.push(entry);
|
|
297
|
-
delegatedEntriesByAdmissionRef.set(admission.admission_ref, entries);
|
|
298
|
-
}
|
|
299
|
-
const hostProjectionByHostRef = new Map();
|
|
300
|
-
const hostProjectionsByPackageRef = new Map();
|
|
301
|
-
for (const admission of options.packageAuthorityAdmissions ?? []) {
|
|
302
|
-
for (const projection of admission.host_authority_projection_refs ?? []) {
|
|
303
|
-
if (!includedRefs.has(projection.package_ref)) {
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
const enrichedProjection = {
|
|
307
|
-
host_ref: projection.host_ref,
|
|
308
|
-
package_ref: projection.package_ref,
|
|
309
|
-
package_authority_id: admission.id,
|
|
310
|
-
admission_ref: admission.admission_ref,
|
|
311
|
-
};
|
|
312
|
-
hostProjectionByHostRef.set(projection.host_ref, enrichedProjection);
|
|
313
|
-
const projections = hostProjectionsByPackageRef.get(projection.package_ref) ?? [];
|
|
314
|
-
projections.push(enrichedProjection);
|
|
315
|
-
hostProjectionsByPackageRef.set(projection.package_ref, projections);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
let chunkIndex = 0;
|
|
319
|
-
const chunks = [];
|
|
320
|
-
const emittedDelegatedAdmissions = new Set();
|
|
321
|
-
for (const entry of sortedEntries) {
|
|
322
|
-
const delegatedAdmission = delegatedProjectionAdmissionForFile(entry.file_ref, options.delegatedProjectionAdmissions);
|
|
323
|
-
if (delegatedAdmission) {
|
|
324
|
-
if (emittedDelegatedAdmissions.has(delegatedAdmission.admission_ref)) {
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
emittedDelegatedAdmissions.add(delegatedAdmission.admission_ref);
|
|
328
|
-
chunkIndex += 1;
|
|
329
|
-
chunks.push(buildDelegatedProjectionChunk({
|
|
330
|
-
admission: delegatedAdmission,
|
|
331
|
-
entries: delegatedEntriesByAdmissionRef.get(delegatedAdmission.admission_ref) ?? [entry],
|
|
332
|
-
chunkIndex,
|
|
333
|
-
criteria: options.criteria,
|
|
334
|
-
authorityTextByRef: options.authorityTextByRef,
|
|
335
|
-
}));
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (hostProjectionByHostRef.has(entry.file_ref)) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
const surface = specSurfaceForFile(entry.file_ref, options.appSliceAdmissions, options.packageAuthorityAdmissions);
|
|
342
|
-
const appAdmission = surface.appAdmission;
|
|
343
|
-
const packageAdmission = surface.packageAdmission;
|
|
344
|
-
const hostAuthorityProjectionRefs = (hostProjectionsByPackageRef.get(entry.file_ref) ?? [])
|
|
345
|
-
.sort((left, right) => left.host_ref.localeCompare(right.host_ref));
|
|
346
|
-
const authorityRefs = [
|
|
347
|
-
entry.file_ref,
|
|
348
|
-
...hostAuthorityProjectionRefs.map((projection) => projection.host_ref),
|
|
349
|
-
];
|
|
350
|
-
const rootAdmissions = (options.auditEvidenceRootAdmissions ?? [])
|
|
351
|
-
.filter((admission) => admission.owner_domain === surface.ownerDomain && admission.authority_refs.includes(entry.file_ref));
|
|
352
|
-
const admittedEvidenceRoots = rootAdmissions.flatMap((admission) => admission.evidence_roots);
|
|
353
|
-
const authorityText = authorityRefs
|
|
354
|
-
.map((authorityRef) => options.authorityTextByRef?.get(authorityRef) ?? "")
|
|
355
|
-
.join("\n");
|
|
356
|
-
const declaredEvidenceRefs = packageAdmission || appAdmission
|
|
357
|
-
? []
|
|
358
|
-
: extractDeclaredEvidenceRefs(authorityText);
|
|
359
|
-
const evidenceRoots = packageAdmission
|
|
360
|
-
? packageAdmission.evidence_roots
|
|
361
|
-
: appAdmission
|
|
362
|
-
? appAdmission.evidence_roots
|
|
363
|
-
: [...new Set([
|
|
364
|
-
...evidenceRootsForSpecOwner(surface.ownerDomain, options.targetRootRef),
|
|
365
|
-
...declaredEvidenceRefs,
|
|
366
|
-
...admittedEvidenceRoots,
|
|
367
|
-
])].sort();
|
|
368
|
-
const moduleMapRefs = surface.surface === "domain-guides" || surface.surface === "app-domain-guides"
|
|
369
|
-
? extractModuleMapRefs(options.authorityTextByRef?.get(entry.file_ref) ?? "")
|
|
370
|
-
: [];
|
|
371
|
-
const declaredEvidenceTargets = [
|
|
372
|
-
...moduleMapRefs.map((moduleRef) => ({
|
|
373
|
-
source_path: moduleRef,
|
|
374
|
-
candidates: candidateEvidenceRefsForModuleMapPath(moduleRef, evidenceRoots),
|
|
375
|
-
})),
|
|
376
|
-
...declaredEvidenceRefs.map((evidenceRef) => ({
|
|
377
|
-
source_path: evidenceRef,
|
|
378
|
-
candidates: candidateEvidenceRefsForDeclaredRef(evidenceRef, evidenceRoots),
|
|
379
|
-
})),
|
|
380
|
-
]
|
|
381
|
-
.filter((target) => target.candidates.length > 0);
|
|
382
|
-
chunkIndex += 1;
|
|
383
|
-
const chunkId = [
|
|
384
|
-
`chunk-${String(chunkIndex).padStart(3, "0")}`,
|
|
385
|
-
slugPart(surface.ownerDomain),
|
|
386
|
-
slugPart(surface.surface),
|
|
387
|
-
slugPart(path.posix.basename(entry.file_ref, path.posix.extname(entry.file_ref))),
|
|
388
|
-
].join("-");
|
|
389
|
-
chunks.push({
|
|
390
|
-
chunk_id: chunkId,
|
|
391
|
-
state: "planned",
|
|
392
|
-
owner_domain: surface.ownerDomain,
|
|
393
|
-
planning_basis: "spec_authority",
|
|
394
|
-
spec_surface: surface.surface,
|
|
395
|
-
criteria: options.criteria,
|
|
396
|
-
files: authorityRefs,
|
|
397
|
-
authority_refs: authorityRefs,
|
|
398
|
-
authority_kind: packageAdmission ? "admitted_package_authority" : (appAdmission ? "admitted_app_slice" : "nimi_spec"),
|
|
399
|
-
...(packageAdmission ? {
|
|
400
|
-
package_authority_id: packageAdmission.id,
|
|
401
|
-
admission_ref: packageAdmission.admission_ref,
|
|
402
|
-
authority_root: packageAdmission.authority_root,
|
|
403
|
-
} : {}),
|
|
404
|
-
...(appAdmission ? {
|
|
405
|
-
app_id: appAdmission.app_id,
|
|
406
|
-
admission_ref: appAdmission.admission_ref,
|
|
407
|
-
authority_root: appAdmission.authority_root,
|
|
408
|
-
} : {}),
|
|
409
|
-
...(rootAdmissions.length > 0 ? {
|
|
410
|
-
evidence_root_admission_refs: rootAdmissions.map((admission) => admission.admission_ref),
|
|
411
|
-
admitted_evidence_roots: admittedEvidenceRoots,
|
|
412
|
-
} : {}),
|
|
413
|
-
...(hostAuthorityProjectionRefs.length > 0 ? {
|
|
414
|
-
host_authority_projection_refs: hostAuthorityProjectionRefs,
|
|
415
|
-
} : {}),
|
|
416
|
-
...(declaredEvidenceTargets.length > 0 ? {
|
|
417
|
-
declared_evidence_targets: declaredEvidenceTargets,
|
|
418
|
-
} : {}),
|
|
419
|
-
evidence_roots: evidenceRoots,
|
|
420
|
-
file_count: authorityRefs.length,
|
|
421
|
-
finding_count: 0,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
return chunks;
|
|
425
|
-
}
|