@nimiplatform/nimi-coding 0.3.1 → 0.4.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 +23 -0
- package/CONTRIBUTING.md +3 -3
- package/README.md +285 -41
- package/README.zh-CN.md +294 -31
- package/bin/nimicoding.mjs +1 -1
- package/cli/commands/authority.mjs +849 -0
- package/cli/commands/clear.mjs +27 -7
- package/cli/commands/doctor.mjs +10 -1
- package/cli/commands/start.mjs +23 -27
- package/cli/commands/sync.mjs +21 -101
- package/cli/constants.mjs +7 -31
- package/cli/dev/check-authority-surface.mjs +173 -0
- package/cli/dev/check-product-conformance.mjs +917 -0
- package/cli/help.mjs +10 -17
- package/cli/index.mjs +6 -47
- package/cli/lib/authority/anchors.mjs +491 -0
- package/cli/lib/authority/audit.mjs +490 -0
- package/cli/lib/authority/closed-sets.mjs +646 -0
- package/cli/lib/authority/compile.mjs +110 -0
- package/cli/lib/authority/consumers.mjs +470 -0
- package/cli/lib/authority/diagnostics.mjs +87 -0
- package/cli/lib/authority/diff.mjs +287 -0
- package/cli/lib/authority/discover.mjs +447 -0
- package/cli/lib/authority/evidence-snapshot.mjs +1 -0
- package/cli/lib/authority/evidence.mjs +1432 -0
- package/cli/lib/authority/format.mjs +197 -0
- package/cli/lib/authority/git-snapshot.mjs +1065 -0
- package/cli/lib/authority/graph.mjs +351 -0
- package/cli/lib/authority/impact.mjs +252 -0
- package/cli/lib/authority/lexicon.mjs +55 -0
- package/cli/lib/authority/query.mjs +162 -0
- package/cli/lib/authority/repository-corpus.mjs +37 -0
- package/cli/lib/authority/repository-inventory.mjs +34 -0
- package/cli/lib/authority/review.mjs +222 -0
- package/cli/lib/authority/sarif.mjs +181 -0
- package/cli/lib/authority/scope-bindings.mjs +225 -0
- package/cli/lib/authority/source-map.mjs +105 -0
- package/cli/lib/authority/source-markdown.mjs +167 -0
- package/cli/lib/authority/source-yaml.mjs +312 -0
- package/cli/lib/authority/surface.mjs +79 -0
- package/cli/lib/authority/terms.mjs +421 -0
- package/cli/lib/authority/tracked-text.mjs +70 -0
- package/cli/lib/authority/validate.mjs +308 -0
- package/cli/lib/bootstrap.mjs +55 -71
- package/cli/lib/doctor.mjs +40 -123
- package/cli/lib/entrypoints.mjs +103 -105
- package/cli/lib/fs-helpers.mjs +139 -15
- package/cli/lib/internal/governance/config.mjs +0 -36
- package/cli/lib/shared.mjs +8 -21
- package/cli/lib/sync.mjs +81 -92
- package/cli/lib/value-helpers.mjs +0 -26
- package/cli/lib/yaml-helpers.mjs +1 -124
- package/cli/seeds/bootstrap.mjs +31 -87
- package/cli/seeds/seed-policy.yaml +9 -63
- package/contracts/authority-evidence-bindings.schema.yaml +53 -0
- package/contracts/authority-evidence-probe-results.schema.yaml +38 -0
- package/contracts/authority-impact-dispositions.schema.yaml +13 -0
- package/contracts/authority-scope-bindings.schema.yaml +15 -0
- package/contracts/authority-source.schema.yaml +64 -0
- package/contracts/authority-verifier-bindings.schema.yaml +20 -0
- package/methodology/authority-authoring.yaml +144 -0
- package/methodology/core.yaml +31 -26
- package/package.json +10 -6
- package/spec/authority-anchors.yaml +99 -0
- package/spec/authority-audit.yaml +85 -0
- package/spec/authority-authoring.yaml +150 -0
- package/spec/authority-closed-sets.yaml +65 -0
- package/spec/authority-consumers.yaml +70 -0
- package/spec/authority-context.yaml +50 -0
- package/spec/authority-discovery.yaml +119 -0
- package/spec/authority-evidence.yaml +200 -0
- package/spec/authority-graph.yaml +59 -0
- package/spec/authority-impact.yaml +84 -0
- package/spec/authority-review.yaml +89 -0
- package/spec/authority-terms.yaml +59 -0
- package/spec/product-scope.yaml +36 -23
- package/cli/commands/blueprint-audit.mjs +0 -91
- package/cli/commands/classify-spec-tree.mjs +0 -5
- package/cli/commands/generate-spec-derived-docs.mjs +0 -151
- package/cli/commands/generate-spec-migration-plan.mjs +0 -30
- package/cli/commands/surface-validator-command.mjs +0 -49
- package/cli/commands/validate-domain-admission.mjs +0 -5
- package/cli/commands/validate-guidance-bodies.mjs +0 -5
- package/cli/commands/validate-placement.mjs +0 -5
- package/cli/commands/validate-projection-edges.mjs +0 -5
- package/cli/commands/validate-spec-audit.mjs +0 -27
- package/cli/commands/validate-spec-governance.mjs +0 -144
- package/cli/commands/validate-spec-tree.mjs +0 -27
- package/cli/commands/validate-table-family.mjs +0 -5
- package/cli/commands/validate-tracked-output-admission.mjs +0 -5
- package/cli/lib/blueprint-audit.mjs +0 -363
- package/cli/lib/contracts.mjs +0 -21
- package/cli/lib/internal/contracts-loaders.mjs +0 -47
- package/cli/lib/internal/contracts-parse.mjs +0 -192
- package/cli/lib/internal/governance/runner.mjs +0 -35
- package/cli/lib/internal/surface-taxonomy-validators.mjs +0 -1147
- package/cli/lib/internal/validators-shared.mjs +0 -12
- package/cli/lib/internal/validators-spec-helpers.mjs +0 -52
- package/cli/lib/internal/validators-spec.mjs +0 -380
- package/cli/lib/validators.mjs +0 -30
- package/config/bootstrap.yaml +0 -6
- package/config/spec-generation-inputs.yaml +0 -41
- package/contracts/domain-admission.schema.yaml +0 -56
- package/contracts/migration-inventory.schema.yaml +0 -15
- package/contracts/negative-fixtures.yaml +0 -26
- package/contracts/placement-contract.schema.yaml +0 -127
- package/contracts/projection-edge.schema.yaml +0 -46
- package/contracts/shared-enums.yaml +0 -63
- package/contracts/spec-generation-audit.schema.yaml +0 -46
- package/contracts/spec-generation-inputs.schema.yaml +0 -43
- package/contracts/spec-layout.schema.yaml +0 -32
- package/contracts/surface-taxonomy.schema.yaml +0 -139
- package/contracts/table-family.schema.yaml +0 -133
- package/contracts/tracked-output-admission.schema.yaml +0 -17
- package/methodology/four-closure-policy.yaml +0 -20
- package/methodology/role-separation-policy.yaml +0 -22
- package/methodology/spec-reconstruction.yaml +0 -69
- package/spec/_meta/spec-tree-model.yaml +0 -44
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
import { localize } from "../lib/ui.mjs";
|
|
6
|
-
import { loadGovernanceConfig, requireProfile } from "../lib/internal/governance/config.mjs";
|
|
7
|
-
import { runCommand } from "../lib/internal/governance/runner.mjs";
|
|
8
|
-
import { parseSpecGenerationInputsConfig } from "../lib/internal/contracts-parse.mjs";
|
|
9
|
-
|
|
10
|
-
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
11
|
-
|
|
12
|
-
function parseOptions(args) {
|
|
13
|
-
const options = {
|
|
14
|
-
profile: null,
|
|
15
|
-
scope: "all",
|
|
16
|
-
check: false,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
20
|
-
const arg = args[index];
|
|
21
|
-
|
|
22
|
-
if (arg === "--profile") {
|
|
23
|
-
const value = args[index + 1];
|
|
24
|
-
if (!value || value.startsWith("--")) {
|
|
25
|
-
return { ok: false, error: "nimicoding generate-spec-derived-docs refused: --profile requires a value.\n" };
|
|
26
|
-
}
|
|
27
|
-
options.profile = value;
|
|
28
|
-
index += 1;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (arg === "--scope") {
|
|
33
|
-
const value = args[index + 1];
|
|
34
|
-
if (!value || value.startsWith("--")) {
|
|
35
|
-
return { ok: false, error: "nimicoding generate-spec-derived-docs refused: --scope requires a value.\n" };
|
|
36
|
-
}
|
|
37
|
-
options.scope = value;
|
|
38
|
-
index += 1;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (arg === "--check") {
|
|
43
|
-
options.check = true;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
ok: false,
|
|
49
|
-
error: `nimicoding generate-spec-derived-docs refused: unknown option ${arg}.\n`,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return { ok: true, options };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function resolveScopes(scope, governanceConfig) {
|
|
57
|
-
const configuredScopes = Object.keys(governanceConfig.specGovernance.generateCommands || {});
|
|
58
|
-
if (scope === "all") {
|
|
59
|
-
return {
|
|
60
|
-
ok: true,
|
|
61
|
-
scopes: configuredScopes,
|
|
62
|
-
error: null,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (!configuredScopes.includes(scope)) {
|
|
66
|
-
return {
|
|
67
|
-
ok: false,
|
|
68
|
-
scopes: [],
|
|
69
|
-
error: `nimicoding generate-spec-derived-docs refused: unsupported --scope value ${scope}.\n`,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
ok: true,
|
|
74
|
-
scopes: [scope],
|
|
75
|
-
error: null,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function runGenerateSpecDerivedDocs(args) {
|
|
80
|
-
const parsed = parseOptions(args);
|
|
81
|
-
if (!parsed.ok) {
|
|
82
|
-
process.stderr.write(localize(parsed.error, parsed.error));
|
|
83
|
-
return 2;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const governance = await loadGovernanceConfig(process.cwd());
|
|
87
|
-
if (!governance.ok) {
|
|
88
|
-
process.stderr.write(localize(
|
|
89
|
-
`nimicoding generate-spec-derived-docs refused: ${governance.reason} at ${governance.path}.\n`,
|
|
90
|
-
`nimicoding generate-spec-derived-docs 已拒绝:${governance.path} 的治理配置不可用。\n`,
|
|
91
|
-
));
|
|
92
|
-
return 2;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const profileCheck = requireProfile(governance.config, parsed.options.profile);
|
|
96
|
-
if (!profileCheck.ok) {
|
|
97
|
-
process.stderr.write(localize(
|
|
98
|
-
`nimicoding generate-spec-derived-docs refused: ${profileCheck.error}.\n`,
|
|
99
|
-
`nimicoding generate-spec-derived-docs 已拒绝:${profileCheck.error}。\n`,
|
|
100
|
-
));
|
|
101
|
-
return 2;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const scopeResolution = resolveScopes(parsed.options.scope, governance.config);
|
|
105
|
-
if (!scopeResolution.ok) {
|
|
106
|
-
process.stderr.write(localize(scopeResolution.error, scopeResolution.error));
|
|
107
|
-
return 2;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const packageInputsText = await readFile(
|
|
111
|
-
path.join(PACKAGE_ROOT, "config", "spec-generation-inputs.yaml"),
|
|
112
|
-
"utf8",
|
|
113
|
-
);
|
|
114
|
-
const packageInputs = parseSpecGenerationInputsConfig(packageInputsText);
|
|
115
|
-
if (!packageInputs.ok || !packageInputs.generationOrder.includes("validate_placement")) {
|
|
116
|
-
process.stderr.write(localize(
|
|
117
|
-
"nimicoding generate-spec-derived-docs refused: package spec generation inputs must be class-filtered and include placement validation.\n",
|
|
118
|
-
"nimicoding generate-spec-derived-docs 已拒绝:package spec generation inputs 必须按 surface class 过滤并包含 placement validation。\n",
|
|
119
|
-
));
|
|
120
|
-
return 2;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let failed = false;
|
|
124
|
-
for (const scope of scopeResolution.scopes) {
|
|
125
|
-
const commands = governance.config.specGovernance.generateCommands[scope] || [];
|
|
126
|
-
if (commands.length === 0) {
|
|
127
|
-
process.stderr.write(localize(
|
|
128
|
-
`nimicoding generate-spec-derived-docs refused: scope ${scope} is not configured in .nimi/config/governance.yaml.\n`,
|
|
129
|
-
`nimicoding generate-spec-derived-docs 已拒绝:.nimi/config/governance.yaml 未配置 ${scope}。\n`,
|
|
130
|
-
));
|
|
131
|
-
return 2;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
for (const command of commands) {
|
|
135
|
-
const commandToRun = parsed.options.check ? `${command} --check` : command;
|
|
136
|
-
const result = runCommand(commandToRun, { cwd: process.cwd() });
|
|
137
|
-
if (result.stdout) process.stdout.write(result.stdout);
|
|
138
|
-
if (result.stderr) process.stderr.write(result.stderr);
|
|
139
|
-
if (!result.ok) {
|
|
140
|
-
failed = true;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (failed) {
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return failed ? 1 : 0;
|
|
151
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateSpecMigrationPlan,
|
|
3
|
-
parseSurfaceValidatorOptions,
|
|
4
|
-
writeMigrationPlanIfRequested,
|
|
5
|
-
} from "../lib/internal/surface-taxonomy-validators.mjs";
|
|
6
|
-
import { localize } from "../lib/ui.mjs";
|
|
7
|
-
|
|
8
|
-
export async function runGenerateSpecMigrationPlan(args) {
|
|
9
|
-
const parsed = parseSurfaceValidatorOptions(args);
|
|
10
|
-
if (!parsed.ok) {
|
|
11
|
-
process.stderr.write(localize(
|
|
12
|
-
`nimicoding generate-spec-migration-plan refused: ${parsed.error}\n`,
|
|
13
|
-
`nimicoding generate-spec-migration-plan 已拒绝:${parsed.error}\n`,
|
|
14
|
-
));
|
|
15
|
-
return 2;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const report = await generateSpecMigrationPlan(process.cwd(), parsed.options);
|
|
20
|
-
await writeMigrationPlanIfRequested(report, parsed.options.emit, process.cwd());
|
|
21
|
-
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
22
|
-
return report.ok ? 0 : 1;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
process.stderr.write(localize(
|
|
25
|
-
`nimicoding generate-spec-migration-plan refused: ${error.message}\n`,
|
|
26
|
-
`nimicoding generate-spec-migration-plan 已拒绝:${error.message}\n`,
|
|
27
|
-
));
|
|
28
|
-
return 2;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
classifySpecSurface,
|
|
3
|
-
parseSurfaceValidatorOptions,
|
|
4
|
-
validateDomainAdmission,
|
|
5
|
-
validateGuidanceBodies,
|
|
6
|
-
validatePlacement,
|
|
7
|
-
validateProjectionEdges,
|
|
8
|
-
validateTableFamily,
|
|
9
|
-
validateTrackedOutputAdmission,
|
|
10
|
-
writeInventoryIfRequested,
|
|
11
|
-
} from "../lib/internal/surface-taxonomy-validators.mjs";
|
|
12
|
-
import { localize } from "../lib/ui.mjs";
|
|
13
|
-
|
|
14
|
-
const VALIDATORS = {
|
|
15
|
-
"classify-spec-tree": classifySpecSurface,
|
|
16
|
-
"validate-placement": validatePlacement,
|
|
17
|
-
"validate-table-family": validateTableFamily,
|
|
18
|
-
"validate-projection-edges": validateProjectionEdges,
|
|
19
|
-
"validate-guidance-bodies": validateGuidanceBodies,
|
|
20
|
-
"validate-domain-admission": validateDomainAdmission,
|
|
21
|
-
"validate-tracked-output-admission": validateTrackedOutputAdmission,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export async function runSurfaceValidatorCommand(args, validatorName) {
|
|
25
|
-
const parsed = parseSurfaceValidatorOptions(args);
|
|
26
|
-
if (!parsed.ok) {
|
|
27
|
-
process.stderr.write(localize(
|
|
28
|
-
`nimicoding ${validatorName} refused: ${parsed.error}\n`,
|
|
29
|
-
`nimicoding ${validatorName} 已拒绝:${parsed.error}\n`,
|
|
30
|
-
));
|
|
31
|
-
return 2;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const validator = VALIDATORS[validatorName];
|
|
35
|
-
if (!validator) {
|
|
36
|
-
process.stderr.write(localize(
|
|
37
|
-
`nimicoding ${validatorName} refused: unknown surface validator.\n`,
|
|
38
|
-
`nimicoding ${validatorName} 已拒绝:未知 surface validator。\n`,
|
|
39
|
-
));
|
|
40
|
-
return 2;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const report = await validator(process.cwd(), parsed.options);
|
|
44
|
-
if (validatorName === "classify-spec-tree") {
|
|
45
|
-
await writeInventoryIfRequested(report, parsed.options.emit, process.cwd());
|
|
46
|
-
}
|
|
47
|
-
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
48
|
-
return report.ok ? 0 : 1;
|
|
49
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import { validateSpecAudit, buildValidatorCliReport } from "../lib/validators.mjs";
|
|
4
|
-
import { localize } from "../lib/ui.mjs";
|
|
5
|
-
|
|
6
|
-
export async function runValidateSpecAudit(args) {
|
|
7
|
-
const normalized = args[0] === "--" ? args.slice(1) : args;
|
|
8
|
-
let targetPath = ".nimi/local/state/spec-generation/spec-generation-audit.yaml";
|
|
9
|
-
|
|
10
|
-
if (normalized.length > 1) {
|
|
11
|
-
process.stderr.write(localize(
|
|
12
|
-
"nimicoding validate-spec-audit refused: expected zero or one path argument.\n",
|
|
13
|
-
"nimicoding validate-spec-audit 已拒绝:期望零个或一个路径参数。\n",
|
|
14
|
-
));
|
|
15
|
-
return 2;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (normalized.length === 1) {
|
|
19
|
-
targetPath = normalized[0];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const absolutePath = path.resolve(process.cwd(), targetPath);
|
|
23
|
-
const report = await validateSpecAudit(absolutePath, { projectRoot: process.cwd() });
|
|
24
|
-
const cliReport = buildValidatorCliReport("validate-spec-audit", absolutePath, report);
|
|
25
|
-
process.stdout.write(`${JSON.stringify(cliReport, null, 2)}\n`);
|
|
26
|
-
return report.ok ? 0 : 1;
|
|
27
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import { localize } from "../lib/ui.mjs";
|
|
4
|
-
import { buildValidatorCliReport, validateSpecTree } from "../lib/validators.mjs";
|
|
5
|
-
import { loadGovernanceConfig, requireProfile } from "../lib/internal/governance/config.mjs";
|
|
6
|
-
import { runCommand } from "../lib/internal/governance/runner.mjs";
|
|
7
|
-
|
|
8
|
-
function parseOptions(args) {
|
|
9
|
-
const options = {
|
|
10
|
-
profile: null,
|
|
11
|
-
scope: "all",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
15
|
-
const arg = args[index];
|
|
16
|
-
|
|
17
|
-
if (arg === "--profile") {
|
|
18
|
-
const value = args[index + 1];
|
|
19
|
-
if (!value || value.startsWith("--")) {
|
|
20
|
-
return { ok: false, error: "nimicoding validate-spec-governance refused: --profile requires a value.\n" };
|
|
21
|
-
}
|
|
22
|
-
options.profile = value;
|
|
23
|
-
index += 1;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (arg === "--scope") {
|
|
28
|
-
const value = args[index + 1];
|
|
29
|
-
if (!value || value.startsWith("--")) {
|
|
30
|
-
return { ok: false, error: "nimicoding validate-spec-governance refused: --scope requires a value.\n" };
|
|
31
|
-
}
|
|
32
|
-
options.scope = value;
|
|
33
|
-
index += 1;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
ok: false,
|
|
39
|
-
error: `nimicoding validate-spec-governance refused: unknown option ${arg}.\n`,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return { ok: true, options };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function resolveScopes(scope, governanceConfig) {
|
|
47
|
-
const configuredScopes = Object.keys(governanceConfig.specGovernance.validateCommands || {});
|
|
48
|
-
if (scope === "all") {
|
|
49
|
-
return {
|
|
50
|
-
ok: true,
|
|
51
|
-
scopes: configuredScopes,
|
|
52
|
-
error: null,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (!configuredScopes.includes(scope)) {
|
|
56
|
-
return {
|
|
57
|
-
ok: false,
|
|
58
|
-
scopes: [],
|
|
59
|
-
error: `nimicoding validate-spec-governance refused: unsupported --scope value ${scope}.\n`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
ok: true,
|
|
64
|
-
scopes: [scope],
|
|
65
|
-
error: null,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function runValidateSpecGovernance(args) {
|
|
70
|
-
const parsed = parseOptions(args);
|
|
71
|
-
if (!parsed.ok) {
|
|
72
|
-
process.stderr.write(localize(parsed.error, parsed.error));
|
|
73
|
-
return 2;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const governance = await loadGovernanceConfig(process.cwd());
|
|
77
|
-
if (!governance.ok) {
|
|
78
|
-
process.stderr.write(localize(
|
|
79
|
-
`nimicoding validate-spec-governance refused: ${governance.reason} at ${governance.path}.\n`,
|
|
80
|
-
`nimicoding validate-spec-governance 已拒绝:${governance.path} 的治理配置不可用。\n`,
|
|
81
|
-
));
|
|
82
|
-
return 2;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const profileCheck = requireProfile(governance.config, parsed.options.profile);
|
|
86
|
-
if (!profileCheck.ok) {
|
|
87
|
-
process.stderr.write(localize(
|
|
88
|
-
`nimicoding validate-spec-governance refused: ${profileCheck.error}.\n`,
|
|
89
|
-
`nimicoding validate-spec-governance 已拒绝:${profileCheck.error}。\n`,
|
|
90
|
-
));
|
|
91
|
-
return 2;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const scopeResolution = resolveScopes(parsed.options.scope, governance.config);
|
|
95
|
-
if (!scopeResolution.ok) {
|
|
96
|
-
process.stderr.write(localize(scopeResolution.error, scopeResolution.error));
|
|
97
|
-
return 2;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (parsed.options.scope === "all") {
|
|
101
|
-
if (governance.config.specGovernance.canonicalRoot !== ".nimi/spec") {
|
|
102
|
-
process.stderr.write(localize(
|
|
103
|
-
"nimicoding validate-spec-governance refused: spec_governance.canonical_root must be .nimi/spec.\n",
|
|
104
|
-
"nimicoding validate-spec-governance 已拒绝:spec_governance.canonical_root 必须为 .nimi/spec。\n",
|
|
105
|
-
));
|
|
106
|
-
return 2;
|
|
107
|
-
}
|
|
108
|
-
const canonicalRoot = path.resolve(process.cwd(), ".nimi/spec");
|
|
109
|
-
const treeReport = await validateSpecTree(canonicalRoot, { projectRoot: process.cwd() });
|
|
110
|
-
if (!treeReport.ok) {
|
|
111
|
-
const cliReport = buildValidatorCliReport("validate-spec-tree", canonicalRoot, treeReport);
|
|
112
|
-
process.stdout.write(`${JSON.stringify(cliReport, null, 2)}\n`);
|
|
113
|
-
return 1;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let failed = false;
|
|
118
|
-
for (const scope of scopeResolution.scopes) {
|
|
119
|
-
const commands = governance.config.specGovernance.validateCommands[scope] || [];
|
|
120
|
-
if (commands.length === 0) {
|
|
121
|
-
process.stderr.write(localize(
|
|
122
|
-
`nimicoding validate-spec-governance refused: scope ${scope} is not configured in .nimi/config/governance.yaml.\n`,
|
|
123
|
-
`nimicoding validate-spec-governance 已拒绝:.nimi/config/governance.yaml 未配置 ${scope}。\n`,
|
|
124
|
-
));
|
|
125
|
-
return 2;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
for (const command of commands) {
|
|
129
|
-
const result = runCommand(command, { cwd: process.cwd() });
|
|
130
|
-
if (result.stdout) process.stdout.write(result.stdout);
|
|
131
|
-
if (result.stderr) process.stderr.write(result.stderr);
|
|
132
|
-
if (!result.ok) {
|
|
133
|
-
failed = true;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (failed) {
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return failed ? 1 : 0;
|
|
144
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import { buildValidatorCliReport, validateSpecTree } from "../lib/validators.mjs";
|
|
4
|
-
import { localize } from "../lib/ui.mjs";
|
|
5
|
-
|
|
6
|
-
export async function runValidateSpecTree(args) {
|
|
7
|
-
const normalized = args[0] === "--" ? args.slice(1) : args;
|
|
8
|
-
let targetRoot = ".nimi/spec";
|
|
9
|
-
|
|
10
|
-
if (normalized.length > 1) {
|
|
11
|
-
process.stderr.write(localize(
|
|
12
|
-
"nimicoding validate-spec-tree refused: expected zero or one path argument.\n",
|
|
13
|
-
"nimicoding validate-spec-tree 已拒绝:期望零个或一个路径参数。\n",
|
|
14
|
-
));
|
|
15
|
-
return 2;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (normalized.length === 1) {
|
|
19
|
-
targetRoot = normalized[0];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const absoluteRoot = path.resolve(process.cwd(), targetRoot);
|
|
23
|
-
const report = await validateSpecTree(absoluteRoot, { projectRoot: process.cwd() });
|
|
24
|
-
const cliReport = buildValidatorCliReport("validate-spec-tree", absoluteRoot, report);
|
|
25
|
-
process.stdout.write(`${JSON.stringify(cliReport, null, 2)}\n`);
|
|
26
|
-
return report.ok ? 0 : 1;
|
|
27
|
-
}
|