@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.
- package/CHANGELOG.md +8 -92
- 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/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,508 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import YAML from "yaml";
|
|
5
|
-
|
|
6
|
-
import { artifactPath, toPosix } from "./common.mjs";
|
|
7
|
-
import { pathExists } from "../fs-helpers.mjs";
|
|
8
|
-
|
|
9
|
-
export const AUDIT_SWEEP_PROJECT_CONFIG_REF = ".nimi/config/audit-sweep.yaml";
|
|
10
|
-
export const APP_SLICE_ADMISSION_REF = ".nimi/spec/platform/kernel/tables/app-slice-admissions.yaml";
|
|
11
|
-
const AUDIT_EVIDENCE_ROOT_TABLE_BASENAME = "audit-evidence-roots.yaml";
|
|
12
|
-
const DELEGATED_PROJECTION_ADMISSION_BASENAME = "delegated-projection-admissions.yaml";
|
|
13
|
-
const PACKAGE_AUTHORITY_ADMISSION_BASENAME = "package-authority-admissions.yaml";
|
|
14
|
-
|
|
15
|
-
export function refInsideRoot(fileRef, rootRef) {
|
|
16
|
-
const normalizedRoot = rootRef.replace(/\\/g, "/").replace(/\/$/, "");
|
|
17
|
-
return fileRef === normalizedRoot || fileRef.startsWith(`${normalizedRoot}/`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function safeProjectRef(value) {
|
|
21
|
-
return typeof value === "string"
|
|
22
|
-
&& value.trim().length > 0
|
|
23
|
-
&& !path.isAbsolute(value)
|
|
24
|
-
&& !value.split("/").includes("..");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function normalizeProjectRef(value) {
|
|
28
|
-
const normalized = String(value ?? "").trim().replace(/\\/g, "/");
|
|
29
|
-
if (/^[a-z][a-z0-9+.-]*:\/\/$/iu.test(normalized)) {
|
|
30
|
-
return normalized;
|
|
31
|
-
}
|
|
32
|
-
return normalized.replace(/\/$/, "");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function activePosture(row) {
|
|
36
|
-
return String(row?.status ?? row?.admission_posture ?? "").trim();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function safeProjectionSourceRef(value) {
|
|
40
|
-
const normalized = normalizeProjectRef(value);
|
|
41
|
-
return normalized.startsWith("parent://")
|
|
42
|
-
|| normalized.startsWith("package://")
|
|
43
|
-
|| safeProjectRef(normalized);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function safeRelativePath(value) {
|
|
47
|
-
const normalized = normalizeProjectRef(value);
|
|
48
|
-
return normalized.length > 0
|
|
49
|
-
&& !path.isAbsolute(normalized)
|
|
50
|
-
&& !normalized.split("/").includes("..");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function loadAuditSweepProjectConfig(projectRoot) {
|
|
54
|
-
const configPath = artifactPath(projectRoot, AUDIT_SWEEP_PROJECT_CONFIG_REF);
|
|
55
|
-
const info = await pathExists(configPath);
|
|
56
|
-
if (!info?.isFile()) {
|
|
57
|
-
return { ok: true, found: false, excludePatterns: [], ignorePatterns: [], ignoreOwnerDomains: [], ignoreReason: null };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let parsed;
|
|
61
|
-
try {
|
|
62
|
-
parsed = YAML.parse(await readFile(configPath, "utf8"));
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return {
|
|
65
|
-
ok: false,
|
|
66
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} must contain valid YAML (${error.message}).\n`,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const rawExcludePatterns = parsed?.audit_sweep?.exclude_patterns ?? parsed?.exclude_patterns ?? [];
|
|
71
|
-
const rawIgnorePatterns = parsed?.audit_sweep?.ignore_patterns ?? parsed?.ignore_patterns ?? [];
|
|
72
|
-
const rawIgnoreOwnerDomains = parsed?.audit_sweep?.ignore_owner_domains ?? parsed?.ignore_owner_domains ?? [];
|
|
73
|
-
const rawIgnoreReason = parsed?.audit_sweep?.ignore_reason ?? parsed?.ignore_reason ?? null;
|
|
74
|
-
if (!Array.isArray(rawExcludePatterns)) {
|
|
75
|
-
return {
|
|
76
|
-
ok: false,
|
|
77
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} exclude_patterns must be an array.\n`,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (!Array.isArray(rawIgnorePatterns)) {
|
|
81
|
-
return {
|
|
82
|
-
ok: false,
|
|
83
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} ignore_patterns must be an array.\n`,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (!Array.isArray(rawIgnoreOwnerDomains)) {
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} ignore_owner_domains must be an array.\n`,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (rawIgnoreReason !== null && (typeof rawIgnoreReason !== "string" || rawIgnoreReason.trim().length === 0)) {
|
|
93
|
-
return {
|
|
94
|
-
ok: false,
|
|
95
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} ignore_reason must be a non-empty string when present.\n`,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const excludePatterns = [];
|
|
100
|
-
for (const pattern of rawExcludePatterns) {
|
|
101
|
-
if (typeof pattern !== "string" || pattern.trim().length === 0) {
|
|
102
|
-
return {
|
|
103
|
-
ok: false,
|
|
104
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} exclude_patterns entries must be non-empty strings.\n`,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
excludePatterns.push(pattern.trim());
|
|
108
|
-
}
|
|
109
|
-
const ignorePatterns = [];
|
|
110
|
-
for (const pattern of rawIgnorePatterns) {
|
|
111
|
-
if (typeof pattern !== "string" || pattern.trim().length === 0) {
|
|
112
|
-
return {
|
|
113
|
-
ok: false,
|
|
114
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} ignore_patterns entries must be non-empty strings.\n`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
ignorePatterns.push(pattern.trim());
|
|
118
|
-
}
|
|
119
|
-
const ignoreOwnerDomains = [];
|
|
120
|
-
for (const ownerDomain of rawIgnoreOwnerDomains) {
|
|
121
|
-
if (typeof ownerDomain !== "string" || ownerDomain.trim().length === 0) {
|
|
122
|
-
return {
|
|
123
|
-
ok: false,
|
|
124
|
-
error: `nimicoding sweep audit refused: ${AUDIT_SWEEP_PROJECT_CONFIG_REF} ignore_owner_domains entries must be non-empty strings.\n`,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
ignoreOwnerDomains.push(ownerDomain.trim());
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
ok: true,
|
|
132
|
-
found: true,
|
|
133
|
-
excludePatterns,
|
|
134
|
-
ignorePatterns,
|
|
135
|
-
ignoreOwnerDomains,
|
|
136
|
-
ignoreReason: rawIgnoreReason?.trim() ?? null,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export async function loadAppSliceAdmissions(projectRoot) {
|
|
141
|
-
const configPath = artifactPath(projectRoot, APP_SLICE_ADMISSION_REF);
|
|
142
|
-
const info = await pathExists(configPath);
|
|
143
|
-
if (!info?.isFile()) {
|
|
144
|
-
return { ok: true, found: false, admissions: [] };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let parsed;
|
|
148
|
-
try {
|
|
149
|
-
parsed = YAML.parse(await readFile(configPath, "utf8"));
|
|
150
|
-
} catch (error) {
|
|
151
|
-
return {
|
|
152
|
-
ok: false,
|
|
153
|
-
error: `nimicoding sweep audit refused: ${APP_SLICE_ADMISSION_REF} must contain valid YAML (${error.message}).\n`,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const rows = Array.isArray(parsed?.admissions) ? parsed.admissions : null;
|
|
158
|
-
if (!rows) {
|
|
159
|
-
return {
|
|
160
|
-
ok: false,
|
|
161
|
-
error: `nimicoding sweep audit refused: ${APP_SLICE_ADMISSION_REF} must declare admissions as an array.\n`,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const admissions = [];
|
|
166
|
-
const seenAppIds = new Set();
|
|
167
|
-
for (const row of rows) {
|
|
168
|
-
const appId = String(row?.app_id ?? "").trim();
|
|
169
|
-
const status = String(row?.status ?? "").trim();
|
|
170
|
-
const ownerDomain = String(row?.owner_domain ?? "").trim();
|
|
171
|
-
const authorityRoot = String(row?.authority_root ?? "").trim().replace(/\\/g, "/").replace(/\/$/, "");
|
|
172
|
-
const evidenceRoots = Array.isArray(row?.evidence_roots)
|
|
173
|
-
? row.evidence_roots.map((entry) => String(entry ?? "").trim().replace(/\\/g, "/").replace(/\/$/, "")).filter(Boolean)
|
|
174
|
-
: null;
|
|
175
|
-
if (!appId || seenAppIds.has(appId)) {
|
|
176
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${APP_SLICE_ADMISSION_REF} has missing or duplicate app_id.\n` };
|
|
177
|
-
}
|
|
178
|
-
seenAppIds.add(appId);
|
|
179
|
-
if (appId === "avatar") {
|
|
180
|
-
return { ok: false, error: `nimicoding sweep audit refused: avatar is promoted to .nimi/spec/avatar and must not be admitted through ${APP_SLICE_ADMISSION_REF}.\n` };
|
|
181
|
-
}
|
|
182
|
-
if (status !== "active") {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (!ownerDomain || !safeProjectRef(authorityRoot) || !authorityRoot.startsWith(`apps/${appId}/spec`)) {
|
|
186
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${APP_SLICE_ADMISSION_REF} ${appId} has invalid owner_domain or authority_root.\n` };
|
|
187
|
-
}
|
|
188
|
-
if (!evidenceRoots || evidenceRoots.length === 0 || !evidenceRoots.every((rootRef) => safeProjectRef(rootRef) && refInsideRoot(rootRef, `apps/${appId}`))) {
|
|
189
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${APP_SLICE_ADMISSION_REF} ${appId} has invalid evidence_roots.\n` };
|
|
190
|
-
}
|
|
191
|
-
admissions.push({
|
|
192
|
-
app_id: appId,
|
|
193
|
-
owner_domain: ownerDomain,
|
|
194
|
-
status,
|
|
195
|
-
authority_root: authorityRoot,
|
|
196
|
-
evidence_roots: evidenceRoots,
|
|
197
|
-
admission_ref: `${APP_SLICE_ADMISSION_REF}#${appId}`,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return { ok: true, found: true, admissions };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async function listSpecTableRefs(projectRoot, basename, listGitFiles, listFallbackFiles) {
|
|
205
|
-
const specRootInfo = await pathExists(artifactPath(projectRoot, ".nimi/spec"));
|
|
206
|
-
if (!specRootInfo?.isDirectory()) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
const gitSpecFiles = await listGitFiles(projectRoot, ".nimi/spec");
|
|
210
|
-
const specFiles = gitSpecFiles.length > 0
|
|
211
|
-
? gitSpecFiles
|
|
212
|
-
: await listFallbackFiles(projectRoot, ".nimi/spec", []);
|
|
213
|
-
return specFiles
|
|
214
|
-
.map((entry) => toPosix(entry))
|
|
215
|
-
.filter((entry) => entry.endsWith(`/kernel/tables/${basename}`))
|
|
216
|
-
.sort();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export async function loadAuditEvidenceRootAdmissions(projectRoot, listGitFiles, listFallbackFiles) {
|
|
220
|
-
const tableRefs = await listSpecTableRefs(projectRoot, AUDIT_EVIDENCE_ROOT_TABLE_BASENAME, listGitFiles, listFallbackFiles);
|
|
221
|
-
if (!tableRefs) {
|
|
222
|
-
return { ok: true, tableRefs: [], admissions: [] };
|
|
223
|
-
}
|
|
224
|
-
const admissions = [];
|
|
225
|
-
|
|
226
|
-
for (const tableRef of tableRefs) {
|
|
227
|
-
let parsed;
|
|
228
|
-
try {
|
|
229
|
-
parsed = YAML.parse(await readFile(artifactPath(projectRoot, tableRef), "utf8"));
|
|
230
|
-
} catch (error) {
|
|
231
|
-
return {
|
|
232
|
-
ok: false,
|
|
233
|
-
error: `nimicoding sweep audit refused: ${tableRef} must contain valid YAML (${error.message}).\n`,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
const rows = Array.isArray(parsed?.roots) ? parsed.roots : null;
|
|
237
|
-
if (!rows) {
|
|
238
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} must declare roots as an array.\n` };
|
|
239
|
-
}
|
|
240
|
-
for (const row of rows) {
|
|
241
|
-
const id = String(row?.id ?? "").trim();
|
|
242
|
-
const ownerDomain = String(row?.owner_domain ?? "").trim();
|
|
243
|
-
const authorityRefs = Array.isArray(row?.authority_refs)
|
|
244
|
-
? row.authority_refs.map((entry) => String(entry ?? "").trim().replace(/\\/g, "/")).filter(Boolean)
|
|
245
|
-
: null;
|
|
246
|
-
const evidenceRoots = Array.isArray(row?.evidence_roots)
|
|
247
|
-
? row.evidence_roots.map((entry) => String(entry ?? "").trim().replace(/\\/g, "/").replace(/\/$/, "")).filter(Boolean)
|
|
248
|
-
: null;
|
|
249
|
-
if (!id || !ownerDomain || !authorityRefs?.length || !evidenceRoots?.length) {
|
|
250
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} root rows require id, owner_domain, authority_refs, and evidence_roots.\n` };
|
|
251
|
-
}
|
|
252
|
-
if (!authorityRefs.every((ref) => safeProjectRef(ref) && ref.startsWith(".nimi/spec/"))) {
|
|
253
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} authority_refs must stay under .nimi/spec.\n` };
|
|
254
|
-
}
|
|
255
|
-
if (!evidenceRoots.every((ref) => safeProjectRef(ref) && !ref.startsWith(".nimi/spec/"))) {
|
|
256
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} evidence_roots must be project evidence roots outside .nimi/spec.\n` };
|
|
257
|
-
}
|
|
258
|
-
admissions.push({
|
|
259
|
-
id,
|
|
260
|
-
owner_domain: ownerDomain,
|
|
261
|
-
authority_refs: authorityRefs,
|
|
262
|
-
evidence_roots: evidenceRoots,
|
|
263
|
-
admission_ref: `${tableRef}#${id}`,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return { ok: true, tableRefs, admissions };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export async function loadDelegatedProjectionAdmissions(projectRoot, listGitFiles, listFallbackFiles) {
|
|
272
|
-
const tableRefs = await listSpecTableRefs(projectRoot, DELEGATED_PROJECTION_ADMISSION_BASENAME, listGitFiles, listFallbackFiles);
|
|
273
|
-
if (!tableRefs) {
|
|
274
|
-
return { ok: true, tableRefs: [], admissions: [] };
|
|
275
|
-
}
|
|
276
|
-
const admissions = [];
|
|
277
|
-
const seenIds = new Set();
|
|
278
|
-
|
|
279
|
-
for (const tableRef of tableRefs) {
|
|
280
|
-
let parsed;
|
|
281
|
-
try {
|
|
282
|
-
parsed = YAML.parse(await readFile(artifactPath(projectRoot, tableRef), "utf8"));
|
|
283
|
-
} catch (error) {
|
|
284
|
-
return {
|
|
285
|
-
ok: false,
|
|
286
|
-
error: `nimicoding sweep audit refused: ${tableRef} must contain valid YAML (${error.message}).\n`,
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
const rows = Array.isArray(parsed?.admissions) ? parsed.admissions : null;
|
|
290
|
-
if (!rows) {
|
|
291
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} must declare admissions as an array.\n` };
|
|
292
|
-
}
|
|
293
|
-
for (const row of rows) {
|
|
294
|
-
const id = String(row?.id ?? "").trim();
|
|
295
|
-
const posture = activePosture(row);
|
|
296
|
-
const ownerDomain = String(row?.owner_domain ?? "").trim();
|
|
297
|
-
const authorityRoot = normalizeProjectRef(row?.authority_root);
|
|
298
|
-
const sourceAuthorityRoot = normalizeProjectRef(row?.source_authority_root);
|
|
299
|
-
const localProjectionEvidenceRoots = Array.isArray(row?.local_projection_evidence_roots)
|
|
300
|
-
? row.local_projection_evidence_roots.map(normalizeProjectRef).filter(Boolean)
|
|
301
|
-
: null;
|
|
302
|
-
const delegatedEvidenceRoots = Array.isArray(row?.delegated_evidence_roots)
|
|
303
|
-
? row.delegated_evidence_roots.map(normalizeProjectRef).filter(Boolean)
|
|
304
|
-
: null;
|
|
305
|
-
const delegatedDeclaredEvidencePrefixes = Array.isArray(row?.delegated_declared_evidence_prefixes)
|
|
306
|
-
? row.delegated_declared_evidence_prefixes.map(normalizeProjectRef).filter(Boolean)
|
|
307
|
-
: [];
|
|
308
|
-
const hostOwnedRelativePaths = Array.isArray(row?.host_owned_relative_paths)
|
|
309
|
-
? row.host_owned_relative_paths.map(normalizeProjectRef).filter(Boolean)
|
|
310
|
-
: [];
|
|
311
|
-
const requiredVerificationCommands = Array.isArray(row?.required_verification_commands)
|
|
312
|
-
? row.required_verification_commands.map((entry) => String(entry ?? "").trim()).filter(Boolean)
|
|
313
|
-
: [];
|
|
314
|
-
const admissionKey = `${tableRef}#${id}`;
|
|
315
|
-
if (!id || seenIds.has(admissionKey)) {
|
|
316
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} has missing or duplicate delegated projection id.\n` };
|
|
317
|
-
}
|
|
318
|
-
seenIds.add(admissionKey);
|
|
319
|
-
if (posture !== "active") {
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
if (!ownerDomain || !safeProjectRef(authorityRoot) || !authorityRoot.startsWith(".nimi/spec/")) {
|
|
323
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid owner_domain or authority_root.\n` };
|
|
324
|
-
}
|
|
325
|
-
if (!safeProjectionSourceRef(sourceAuthorityRoot)) {
|
|
326
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid source_authority_root.\n` };
|
|
327
|
-
}
|
|
328
|
-
if (!localProjectionEvidenceRoots?.length || !localProjectionEvidenceRoots.every((rootRef) => safeProjectRef(rootRef) && !rootRef.startsWith(".nimi/spec/"))) {
|
|
329
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid local_projection_evidence_roots.\n` };
|
|
330
|
-
}
|
|
331
|
-
if (!delegatedEvidenceRoots?.length || !delegatedEvidenceRoots.every(safeProjectionSourceRef)) {
|
|
332
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid delegated_evidence_roots.\n` };
|
|
333
|
-
}
|
|
334
|
-
if (delegatedDeclaredEvidencePrefixes.length === 0 || !delegatedDeclaredEvidencePrefixes.every(safeRelativePath)) {
|
|
335
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} must declare delegated_declared_evidence_prefixes.\n` };
|
|
336
|
-
}
|
|
337
|
-
if (!hostOwnedRelativePaths.every(safeRelativePath)) {
|
|
338
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid host_owned_relative_paths.\n` };
|
|
339
|
-
}
|
|
340
|
-
if (!requiredVerificationCommands.every((command) => command.length > 0)) {
|
|
341
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid required_verification_commands.\n` };
|
|
342
|
-
}
|
|
343
|
-
admissions.push({
|
|
344
|
-
id,
|
|
345
|
-
owner_domain: ownerDomain,
|
|
346
|
-
status: posture,
|
|
347
|
-
authority_root: authorityRoot,
|
|
348
|
-
source_authority_root: sourceAuthorityRoot,
|
|
349
|
-
local_projection_evidence_roots: localProjectionEvidenceRoots,
|
|
350
|
-
delegated_evidence_roots: delegatedEvidenceRoots,
|
|
351
|
-
delegated_declared_evidence_prefixes: delegatedDeclaredEvidencePrefixes,
|
|
352
|
-
host_owned_relative_paths: hostOwnedRelativePaths,
|
|
353
|
-
required_verification_commands: requiredVerificationCommands,
|
|
354
|
-
admission_ref: admissionKey,
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return { ok: true, tableRefs, admissions };
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
export async function loadPackageAuthorityAdmissions(projectRoot, listGitFiles, listFallbackFiles) {
|
|
363
|
-
const tableRefs = await listSpecTableRefs(projectRoot, PACKAGE_AUTHORITY_ADMISSION_BASENAME, listGitFiles, listFallbackFiles);
|
|
364
|
-
if (!tableRefs) {
|
|
365
|
-
return { ok: true, tableRefs: [], admissions: [] };
|
|
366
|
-
}
|
|
367
|
-
const admissions = [];
|
|
368
|
-
const seenIds = new Set();
|
|
369
|
-
|
|
370
|
-
for (const tableRef of tableRefs) {
|
|
371
|
-
let parsed;
|
|
372
|
-
try {
|
|
373
|
-
parsed = YAML.parse(await readFile(artifactPath(projectRoot, tableRef), "utf8"));
|
|
374
|
-
} catch (error) {
|
|
375
|
-
return {
|
|
376
|
-
ok: false,
|
|
377
|
-
error: `nimicoding sweep audit refused: ${tableRef} must contain valid YAML (${error.message}).\n`,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
const rows = Array.isArray(parsed?.admissions) ? parsed.admissions : null;
|
|
381
|
-
if (!rows) {
|
|
382
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} must declare admissions as an array.\n` };
|
|
383
|
-
}
|
|
384
|
-
for (const row of rows) {
|
|
385
|
-
const id = String(row?.id ?? "").trim();
|
|
386
|
-
const status = String(row?.status ?? "").trim();
|
|
387
|
-
const ownerDomain = String(row?.owner_domain ?? "").trim();
|
|
388
|
-
const authorityRoot = String(row?.authority_root ?? "").trim().replace(/\\/g, "/").replace(/\/$/, "");
|
|
389
|
-
const evidenceRoots = Array.isArray(row?.evidence_roots)
|
|
390
|
-
? row.evidence_roots.map((entry) => String(entry ?? "").trim().replace(/\\/g, "/").replace(/\/$/, "")).filter(Boolean)
|
|
391
|
-
: null;
|
|
392
|
-
const hostAuthorityProjectionRefs = Array.isArray(row?.projection_boundary?.host_authority_projection_refs)
|
|
393
|
-
? row.projection_boundary.host_authority_projection_refs.map((entry) => ({
|
|
394
|
-
host_ref: String(entry?.host_ref ?? "").trim().replace(/\\/g, "/"),
|
|
395
|
-
package_ref: String(entry?.package_ref ?? "").trim().replace(/\\/g, "/"),
|
|
396
|
-
})).filter((entry) => entry.host_ref || entry.package_ref)
|
|
397
|
-
: [];
|
|
398
|
-
const admissionKey = `${tableRef}#${id}`;
|
|
399
|
-
if (!id || seenIds.has(admissionKey)) {
|
|
400
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} has missing or duplicate package authority id.\n` };
|
|
401
|
-
}
|
|
402
|
-
seenIds.add(admissionKey);
|
|
403
|
-
if (status !== "active") {
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
if (!ownerDomain || !safeProjectRef(authorityRoot) || authorityRoot.startsWith(".nimi/spec/") || !authorityRoot.endsWith("/spec")) {
|
|
407
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid owner_domain or authority_root.\n` };
|
|
408
|
-
}
|
|
409
|
-
if (!evidenceRoots || evidenceRoots.length === 0 || !evidenceRoots.every((rootRef) => safeProjectRef(rootRef) && !rootRef.startsWith(".nimi/spec/") && refInsideRoot(authorityRoot, rootRef))) {
|
|
410
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} has invalid evidence_roots.\n` };
|
|
411
|
-
}
|
|
412
|
-
const seenProjectionHostRefs = new Set();
|
|
413
|
-
for (const projection of hostAuthorityProjectionRefs) {
|
|
414
|
-
const hostProjectionAllowed = projection.host_ref.startsWith(".nimi/config/")
|
|
415
|
-
|| projection.host_ref.startsWith(".nimi/contracts/")
|
|
416
|
-
|| projection.host_ref.startsWith(".nimi/methodology/")
|
|
417
|
-
|| projection.host_ref.startsWith(".nimi/spec/");
|
|
418
|
-
if (!safeProjectRef(projection.host_ref) || !hostProjectionAllowed) {
|
|
419
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} host_authority_projection_refs host_ref must stay under .nimi config/contracts/methodology/spec projections.\n` };
|
|
420
|
-
}
|
|
421
|
-
const packageRoot = authorityRoot.replace(/\/spec$/, "");
|
|
422
|
-
const packageProjectionAllowed = projection.package_ref.startsWith(`${packageRoot}/config/`)
|
|
423
|
-
|| projection.package_ref.startsWith(`${packageRoot}/contracts/`)
|
|
424
|
-
|| projection.package_ref.startsWith(`${packageRoot}/methodology/`)
|
|
425
|
-
|| projection.package_ref.startsWith(`${packageRoot}/spec/`);
|
|
426
|
-
if (!safeProjectRef(projection.package_ref) || !packageProjectionAllowed) {
|
|
427
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} host_authority_projection_refs package_ref must stay under admitted package authority roots.\n` };
|
|
428
|
-
}
|
|
429
|
-
if (seenProjectionHostRefs.has(projection.host_ref)) {
|
|
430
|
-
return { ok: false, error: `nimicoding sweep audit refused: ${tableRef} ${id} host_authority_projection_refs contains duplicate host_ref.\n` };
|
|
431
|
-
}
|
|
432
|
-
seenProjectionHostRefs.add(projection.host_ref);
|
|
433
|
-
}
|
|
434
|
-
admissions.push({
|
|
435
|
-
id,
|
|
436
|
-
owner_domain: ownerDomain,
|
|
437
|
-
status,
|
|
438
|
-
authority_root: authorityRoot,
|
|
439
|
-
evidence_roots: evidenceRoots,
|
|
440
|
-
host_authority_projection_refs: hostAuthorityProjectionRefs,
|
|
441
|
-
admission_ref: admissionKey,
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return { ok: true, tableRefs, admissions };
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function appSliceAdmissionForFile(fileRef, appSliceAdmissions = []) {
|
|
450
|
-
return appSliceAdmissions.find((admission) => refInsideRoot(fileRef, admission.authority_root)) ?? null;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function packageAuthorityAdmissionForFile(fileRef, packageAuthorityAdmissions = []) {
|
|
454
|
-
return packageAuthorityAdmissions.find((admission) => refInsideRoot(fileRef, admission.authority_root)) ?? null;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
export function specSurfaceForFile(fileRef, appSliceAdmissions = [], packageAuthorityAdmissions = []) {
|
|
458
|
-
const packageAdmission = packageAuthorityAdmissionForFile(fileRef, packageAuthorityAdmissions);
|
|
459
|
-
if (packageAdmission) {
|
|
460
|
-
const relative = fileRef.slice(packageAdmission.authority_root.length + 1);
|
|
461
|
-
const parts = relative.split("/");
|
|
462
|
-
if (parts[0] === "_meta") {
|
|
463
|
-
return { ownerDomain: packageAdmission.owner_domain, surface: "package-meta", packageAdmission };
|
|
464
|
-
}
|
|
465
|
-
if (parts[0] === "kernel" && parts[1] === "tables") {
|
|
466
|
-
return { ownerDomain: packageAdmission.owner_domain, surface: "package-kernel-tables", packageAdmission };
|
|
467
|
-
}
|
|
468
|
-
if (parts[0] === "kernel") {
|
|
469
|
-
return { ownerDomain: packageAdmission.owner_domain, surface: "package-kernel-contracts", packageAdmission };
|
|
470
|
-
}
|
|
471
|
-
return { ownerDomain: packageAdmission.owner_domain, surface: "package-root", packageAdmission };
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
const appAdmission = appSliceAdmissionForFile(fileRef, appSliceAdmissions);
|
|
475
|
-
if (appAdmission) {
|
|
476
|
-
const relative = fileRef.slice(appAdmission.authority_root.length + 1);
|
|
477
|
-
const parts = relative.split("/");
|
|
478
|
-
if (parts[0] === "kernel" && parts[1] === "tables") {
|
|
479
|
-
return { ownerDomain: appAdmission.owner_domain, surface: "app-kernel-tables", appAdmission };
|
|
480
|
-
}
|
|
481
|
-
if (parts[0] === "kernel") {
|
|
482
|
-
return { ownerDomain: appAdmission.owner_domain, surface: "app-kernel-contracts", appAdmission };
|
|
483
|
-
}
|
|
484
|
-
return { ownerDomain: appAdmission.owner_domain, surface: "app-domain-guides", appAdmission };
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
const withoutRoot = fileRef.startsWith(".nimi/spec/")
|
|
488
|
-
? fileRef.slice(".nimi/spec/".length)
|
|
489
|
-
: fileRef;
|
|
490
|
-
const parts = withoutRoot.split("/");
|
|
491
|
-
if (parts[0] === "_meta") {
|
|
492
|
-
return { ownerDomain: "spec-meta", surface: path.posix.basename(fileRef, path.posix.extname(fileRef)) };
|
|
493
|
-
}
|
|
494
|
-
if (parts.length === 1) {
|
|
495
|
-
return { ownerDomain: "spec-root", surface: path.posix.basename(fileRef, path.posix.extname(fileRef)) };
|
|
496
|
-
}
|
|
497
|
-
const domain = parts[0];
|
|
498
|
-
if (parts[1] === "kernel" && parts[2] === "tables") {
|
|
499
|
-
return { ownerDomain: domain, surface: "kernel-tables" };
|
|
500
|
-
}
|
|
501
|
-
if (parts[1] === "kernel" && parts[2] === "generated") {
|
|
502
|
-
return { ownerDomain: domain, surface: "kernel-generated" };
|
|
503
|
-
}
|
|
504
|
-
if (parts[1] === "kernel") {
|
|
505
|
-
return { ownerDomain: domain, surface: "kernel-contracts" };
|
|
506
|
-
}
|
|
507
|
-
return { ownerDomain: domain, surface: "domain-guides" };
|
|
508
|
-
}
|