@nexusclawhq/cli 0.3.80 → 0.3.81
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 +6 -0
- package/dist/build-info.json +4 -4
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.d.ts +99 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.js +3 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.js.map +1 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/en-US.d.ts +32 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/en-US.js +32 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/en-US.js.map +1 -1
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/index.d.ts +64 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/zh-CN.d.ts +32 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/zh-CN.js +32 -0
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/locales/zh-CN.js.map +1 -1
- package/dist/nexus-cli/src/cli.js +0 -0
- package/dist/nexus-cli/src/commands/metadata/diff.d.ts +2 -0
- package/dist/nexus-cli/src/commands/metadata/diff.js +5 -1
- package/dist/nexus-cli/src/commands/metadata/diff.js.map +1 -1
- package/dist/nexus-cli/src/commands/metadata/diff.test.d.ts +1 -0
- package/dist/nexus-cli/src/commands/metadata/diff.test.js +66 -0
- package/dist/nexus-cli/src/commands/metadata/diff.test.js.map +1 -0
- package/dist/nexus-cli/src/contracts/command-routing.d.ts +25 -0
- package/dist/nexus-cli/src/contracts/command-routing.js +488 -0
- package/dist/nexus-cli/src/contracts/command-routing.js.map +1 -0
- package/dist/nexus-cli/src/contracts/command-routing.test.d.ts +1 -0
- package/dist/nexus-cli/src/contracts/command-routing.test.js +73 -0
- package/dist/nexus-cli/src/contracts/command-routing.test.js.map +1 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.d.ts +40 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.js +234 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.js.map +1 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.test.d.ts +1 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.test.js +65 -0
- package/dist/nexus-cli/src/contracts/task-route.registry.test.js.map +1 -0
- package/dist/nexus-cli/src/services/api-client.d.ts +1 -0
- package/dist/nexus-cli/src/services/api-client.js +15 -1
- package/dist/nexus-cli/src/services/api-client.js.map +1 -1
- package/dist/nexus-cli/src/services/api-client.test.js +20 -0
- package/dist/nexus-cli/src/services/api-client.test.js.map +1 -1
- package/dist/nexus-cli/src/services/workforce-bundle-archive.d.ts +1 -1
- package/dist/nexus-cli/src/services/workforce-bundle-remote.d.ts +1 -1
- package/dist/nexus-cli/src/services/workforce-test-remote.d.ts +1 -1
- package/dist/nexus-cli/src/services/workforce-test-remote.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
File without changes
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.diffCommand = void 0;
|
|
7
|
+
exports.readMetadataDiffSourceFiles = readMetadataDiffSourceFiles;
|
|
7
8
|
const commander_1 = require("commander");
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
10
|
const api_client_1 = require("../../services/api-client");
|
|
@@ -24,7 +25,7 @@ exports.diffCommand = new commander_1.Command('diff')
|
|
|
24
25
|
const json = (0, command_options_1.isJsonOutputRequested)(options, command);
|
|
25
26
|
const spinner = json ? null : (0, spinner_1.createSpinner)('正在生成 metadata diff...').start();
|
|
26
27
|
try {
|
|
27
|
-
const files = (
|
|
28
|
+
const files = readMetadataDiffSourceFiles(options.source);
|
|
28
29
|
const environmentName = (0, command_options_1.resolveEnvironmentOption)(options);
|
|
29
30
|
const targetOrg = environmentName
|
|
30
31
|
? (0, target_context_1.resolveTargetContext)({
|
|
@@ -68,4 +69,7 @@ exports.diffCommand = new commander_1.Command('diff')
|
|
|
68
69
|
throw error;
|
|
69
70
|
}
|
|
70
71
|
});
|
|
72
|
+
function readMetadataDiffSourceFiles(source) {
|
|
73
|
+
return source === '.' ? (0, source_tracker_1.readSourceFiles)(source) : (0, source_tracker_1.readSelectedSourceDirectory)(source);
|
|
74
|
+
}
|
|
71
75
|
//# sourceMappingURL=diff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../../../src/commands/metadata/diff.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../../../../src/commands/metadata/diff.ts"],"names":[],"mappings":";;;;;;AAmEA,kEAEC;AArED,yCAAoC;AACpC,kDAA0B;AAC1B,0DAA4D;AAC5D,kEAA6F;AAC7F,iDAAoD;AACpD,+CAA4C;AAC5C,kEAAqE;AACrE,iEAA8F;AAC9F,mEAA+E;AAElE,QAAA,WAAW,GAAG,IAAI,mBAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,uCAAuC,CAAC;KACpD,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,GAAG,CAAC;KACrD,MAAM,CAAC,0BAA0B,EAAE,kBAAkB,CAAC;KACtD,MAAM,CAAC,cAAc,EAAE,6BAA6B,CAAC;KACrD,MAAM,CAAC,sBAAsB,EAAE,6BAA6B,CAAC;KAC7D,MAAM,CAAC,QAAQ,EAAE,2CAA2C,EAAE,KAAK,CAAC;KACpE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAgB,EAAE,EAAE;IAC1C,MAAM,IAAI,GAAG,IAAA,uCAAqB,EAAC,OAAO,EAAE,OAAO,CA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|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_test_1 = __importDefault(require("node:test"));
|
|
11
|
+
const diff_1 = require("./diff");
|
|
12
|
+
(0, node_test_1.default)('metadata diff reads only an explicitly selected directory inside a workspace', () => {
|
|
13
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'nexus-metadata-diff-'));
|
|
14
|
+
try {
|
|
15
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, 'nexus-project.yaml'), [
|
|
16
|
+
'schemaVersion: nexus-project/v2',
|
|
17
|
+
'projectName: scoped-diff',
|
|
18
|
+
'compatibleCoreVersion: 0.3.x',
|
|
19
|
+
'sourceRoots:',
|
|
20
|
+
' - path: nexus-app/main/default',
|
|
21
|
+
' kind: metadata-runtime',
|
|
22
|
+
'localPackages: []',
|
|
23
|
+
'environments: []',
|
|
24
|
+
].join('\n'));
|
|
25
|
+
const selected = node_path_1.default.join(root, 'handoff', 'bundle');
|
|
26
|
+
const unrelated = node_path_1.default.join(root, 'nexus-app', 'main', 'default', 'objects', 'account');
|
|
27
|
+
node_fs_1.default.mkdirSync(node_path_1.default.join(selected, 'views'), { recursive: true });
|
|
28
|
+
node_fs_1.default.mkdirSync(unrelated, { recursive: true });
|
|
29
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(selected, 'views', 'selected.view.json'), '{"selected":true}');
|
|
30
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(unrelated, 'object.json'), '{"nameSingular":"account"}');
|
|
31
|
+
strict_1.default.deepEqual((0, diff_1.readMetadataDiffSourceFiles)(selected), [
|
|
32
|
+
{ path: 'views/selected.view.json', content: '{"selected":true}' },
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
node_fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
(0, node_test_1.default)('metadata diff retains workspace source roots for the default source', () => {
|
|
40
|
+
const root = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'nexus-metadata-diff-default-'));
|
|
41
|
+
const previous = process.cwd();
|
|
42
|
+
try {
|
|
43
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(root, 'nexus-project.yaml'), [
|
|
44
|
+
'schemaVersion: nexus-project/v2',
|
|
45
|
+
'projectName: default-diff',
|
|
46
|
+
'compatibleCoreVersion: 0.3.x',
|
|
47
|
+
'sourceRoots:',
|
|
48
|
+
' - path: nexus-app/main/default',
|
|
49
|
+
' kind: metadata-runtime',
|
|
50
|
+
'localPackages: []',
|
|
51
|
+
'environments: []',
|
|
52
|
+
].join('\n'));
|
|
53
|
+
const objects = node_path_1.default.join(root, 'nexus-app', 'main', 'default', 'objects', 'account');
|
|
54
|
+
node_fs_1.default.mkdirSync(objects, { recursive: true });
|
|
55
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(objects, 'object.json'), '{"nameSingular":"account"}');
|
|
56
|
+
process.chdir(root);
|
|
57
|
+
strict_1.default.deepEqual((0, diff_1.readMetadataDiffSourceFiles)('.'), [
|
|
58
|
+
{ path: 'objects/account/object.json', content: '{"nameSingular":"account"}' },
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
process.chdir(previous);
|
|
63
|
+
node_fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=diff.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.test.js","sourceRoot":"","sources":["../../../../../src/commands/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C,SAAS,CAAC,IAAA,kCAA2B,EAAC,GAAG,CAAC,EAAE;YACjD,EAAE,IAAI,EAAE,6BAA6B,EAAE,OAAO,EAAE,4BAA4B,EAAE;SAC/E,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxB,iBAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CliAgentCommandRoutingGraphV1, type CliAgentCommandRoutingFactsV1, type CliAgentCommandRoutingPlanV1, type CliAgentCommandRoutingFailureCode } from '@nexusclaw/shared';
|
|
2
|
+
import type { CliCommandInventoryV1 } from './command-inventory';
|
|
3
|
+
import { type CliRegisteredCommandPolicyV2 } from './command-policy.registry';
|
|
4
|
+
export interface CommandRoutingBuildContext {
|
|
5
|
+
readonly mode?: 'offline' | 'online';
|
|
6
|
+
readonly workspaceId?: string | null;
|
|
7
|
+
readonly principalScopeDigest?: `sha256:${string}` | null;
|
|
8
|
+
readonly expiresAt?: string | null;
|
|
9
|
+
readonly generatedAt?: string;
|
|
10
|
+
readonly cliVersion?: string;
|
|
11
|
+
readonly coreCommitSha?: string | null;
|
|
12
|
+
readonly inventory?: CliCommandInventoryV1;
|
|
13
|
+
readonly policies?: ReadonlyArray<CliRegisteredCommandPolicyV2>;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildCommandRoutingGraph(input?: CommandRoutingBuildContext): CliAgentCommandRoutingGraphV1;
|
|
16
|
+
export declare function resolveCommandRoutingPlan(graph: CliAgentCommandRoutingGraphV1, routeId: string, facts?: CliAgentCommandRoutingFactsV1): import('@nexusclaw/shared').CliAgentCommandRoutingResolutionV1;
|
|
17
|
+
export type CommandRoutingDispatchValidation = {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly graphDigest: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly ok: false;
|
|
22
|
+
readonly code: CliAgentCommandRoutingFailureCode;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function validateCommandRoutingPlanForDispatch(plan: CliAgentCommandRoutingPlanV1, argv: ReadonlyArray<string>, graph: CliAgentCommandRoutingGraphV1, explicitUserAuthority?: boolean): CommandRoutingDispatchValidation;
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCommandRoutingGraph = buildCommandRoutingGraph;
|
|
4
|
+
exports.resolveCommandRoutingPlan = resolveCommandRoutingPlan;
|
|
5
|
+
exports.validateCommandRoutingPlanForDispatch = validateCommandRoutingPlanForDispatch;
|
|
6
|
+
const shared_1 = require("@nexusclaw/shared");
|
|
7
|
+
const build_info_1 = require("../services/build-info");
|
|
8
|
+
const command_inventory_1 = require("./command-inventory");
|
|
9
|
+
const command_contract_registry_1 = require("./command-contract.registry");
|
|
10
|
+
const command_contract_1 = require("./command-contract");
|
|
11
|
+
const command_order_1 = require("./command-order");
|
|
12
|
+
const command_contract_exporter_1 = require("./command-contract.exporter");
|
|
13
|
+
const command_policy_registry_1 = require("./command-policy.registry");
|
|
14
|
+
const command_policy_validator_1 = require("./command-policy.validator");
|
|
15
|
+
const command_policy_exporter_1 = require("./command-policy.exporter");
|
|
16
|
+
const SURFACES = [
|
|
17
|
+
'code', 'flow', 'metadata', 'source', 'workforce', 'observe', 'release',
|
|
18
|
+
];
|
|
19
|
+
const ROUTING_CONTROL_OPTIONS = new Set(['--route-plan', '--route-authorized']);
|
|
20
|
+
function loadProgramInventory() {
|
|
21
|
+
const { buildCliProgram } = require('../cli');
|
|
22
|
+
return (0, command_inventory_1.buildCommandInventory)(buildCliProgram());
|
|
23
|
+
}
|
|
24
|
+
function allContracts() {
|
|
25
|
+
return command_contract_registry_1.commandContractRegistry.all().map((entry) => entry.contract);
|
|
26
|
+
}
|
|
27
|
+
function surfaceFor(path, commandId) {
|
|
28
|
+
const value = `${path} ${commandId}`.toLocaleLowerCase('en-US');
|
|
29
|
+
if (value.startsWith('employee code') || value.includes('code-action'))
|
|
30
|
+
return 'code';
|
|
31
|
+
if (value.startsWith('employee flow') || value.includes('flow'))
|
|
32
|
+
return 'flow';
|
|
33
|
+
if (value.startsWith('workforce')) {
|
|
34
|
+
return /release|publish|rollback|stage-activation|promote|revoke/u.test(value)
|
|
35
|
+
? 'release'
|
|
36
|
+
: 'workforce';
|
|
37
|
+
}
|
|
38
|
+
if (/^source\b|\bsource\b|pull|push/u.test(value))
|
|
39
|
+
return 'source';
|
|
40
|
+
if (/^metadata\b|^package\b|^workspace\b|^project\b|^org\b|^user\b|^install\b|^generate\b/u.test(value))
|
|
41
|
+
return 'metadata';
|
|
42
|
+
if (/deployment|revision|release|promote|rollback|publish|candidate/u.test(value))
|
|
43
|
+
return 'release';
|
|
44
|
+
if (/log|doctor|test|preflight|diff|report|history|status|health|display|list|query/u.test(value))
|
|
45
|
+
return 'observe';
|
|
46
|
+
return 'metadata';
|
|
47
|
+
}
|
|
48
|
+
function optionName(value) {
|
|
49
|
+
return value.replace(/^--/, '').replace(/[^A-Za-z0-9_]+/g, '_');
|
|
50
|
+
}
|
|
51
|
+
function schemaOptionName(value) {
|
|
52
|
+
const name = optionName(value);
|
|
53
|
+
return /(?:token|password|secret|private[_-]?key|access[_-]?token|refresh[_-]?token)/iu.test(name)
|
|
54
|
+
? `input_${name}`
|
|
55
|
+
: name;
|
|
56
|
+
}
|
|
57
|
+
function collectPredicateOptions(expression, output = new Set()) {
|
|
58
|
+
switch (expression.kind) {
|
|
59
|
+
case 'option_present':
|
|
60
|
+
case 'option_equals':
|
|
61
|
+
case 'option_matches_schema':
|
|
62
|
+
output.add(expression.option);
|
|
63
|
+
return output;
|
|
64
|
+
case 'option_absent':
|
|
65
|
+
return output;
|
|
66
|
+
case 'exactly_one':
|
|
67
|
+
case 'none_of':
|
|
68
|
+
expression.options.forEach((option) => output.add(option));
|
|
69
|
+
return output;
|
|
70
|
+
case 'all_of':
|
|
71
|
+
case 'any_of':
|
|
72
|
+
expression.expressions.forEach((child) => collectPredicateOptions(child, output));
|
|
73
|
+
return output;
|
|
74
|
+
case 'not':
|
|
75
|
+
return collectPredicateOptions(expression.expression, output);
|
|
76
|
+
default:
|
|
77
|
+
return output;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function inputSchema(source) {
|
|
81
|
+
const properties = {};
|
|
82
|
+
const required = [];
|
|
83
|
+
for (const argument of source.leaf.arguments) {
|
|
84
|
+
properties[argument.name] = {
|
|
85
|
+
type: argument.variadic ? 'array' : 'string',
|
|
86
|
+
description: argument.description,
|
|
87
|
+
};
|
|
88
|
+
if (argument.required)
|
|
89
|
+
required.push(argument.name);
|
|
90
|
+
}
|
|
91
|
+
for (const option of source.leaf.options) {
|
|
92
|
+
if (!option.long)
|
|
93
|
+
continue;
|
|
94
|
+
if (ROUTING_CONTROL_OPTIONS.has(option.long))
|
|
95
|
+
continue;
|
|
96
|
+
const name = schemaOptionName(option.long);
|
|
97
|
+
properties[name] = {
|
|
98
|
+
type: option.negated || option.defaultValue === false ? 'boolean' : 'string',
|
|
99
|
+
description: option.description,
|
|
100
|
+
};
|
|
101
|
+
if (option.mandatory)
|
|
102
|
+
required.push(name);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
106
|
+
type: 'object',
|
|
107
|
+
additionalProperties: false,
|
|
108
|
+
properties,
|
|
109
|
+
...(required.length > 0 ? { required: [...new Set(required)].sort() } : {}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function invocationTemplate(source) {
|
|
113
|
+
const tokens = [`nexus ${source.leaf.path}`];
|
|
114
|
+
for (const argument of source.leaf.arguments) {
|
|
115
|
+
if (argument.required)
|
|
116
|
+
tokens.push(`<${argument.name}>`);
|
|
117
|
+
}
|
|
118
|
+
const selected = new Set([
|
|
119
|
+
...source.leaf.options.filter((option) => option.mandatory && option.long && !ROUTING_CONTROL_OPTIONS.has(option.long)).map((option) => option.long),
|
|
120
|
+
...collectPredicateOptions(source.contractMode?.when ?? { kind: 'all_of', expressions: [] }),
|
|
121
|
+
]);
|
|
122
|
+
selected.add('--json');
|
|
123
|
+
for (const option of [...selected].sort()) {
|
|
124
|
+
const record = source.leaf.options.find((candidate) => candidate.long === option);
|
|
125
|
+
if (option === '--json' || record?.defaultValue === false || record?.negated
|
|
126
|
+
|| (record && !record.required && !record.optional)) {
|
|
127
|
+
tokens.push(option);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
tokens.push(`${option} <${optionName(option)}>`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return tokens.join(' ');
|
|
134
|
+
}
|
|
135
|
+
function effectFor(source) {
|
|
136
|
+
const contractEffect = source.contractMode?.effects[0];
|
|
137
|
+
if (contractEffect)
|
|
138
|
+
return contractEffect;
|
|
139
|
+
switch (source.mode.invocationPolicy.mutability) {
|
|
140
|
+
case 'remote-write': return 'remote_write';
|
|
141
|
+
case 'local-write': return 'local_write';
|
|
142
|
+
case 'read-only':
|
|
143
|
+
return source.leaf.options.some((option) => option.long === '--target-org' || option.long === '--workspace-id')
|
|
144
|
+
? 'remote_read'
|
|
145
|
+
: 'none';
|
|
146
|
+
default: return 'none';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function authFor(source) {
|
|
150
|
+
if (source.contractMode?.auth)
|
|
151
|
+
return source.contractMode.auth;
|
|
152
|
+
return source.leaf.options.some((option) => option.long === '--target-org' || option.long === '--workspace-id')
|
|
153
|
+
? 'org'
|
|
154
|
+
: 'none';
|
|
155
|
+
}
|
|
156
|
+
function requiredFacts(source) {
|
|
157
|
+
const facts = source.leaf.arguments.filter((argument) => argument.required).map((argument) => `argument:${argument.name}`);
|
|
158
|
+
facts.push(...source.leaf.options.filter((option) => option.mandatory && option.long && !ROUTING_CONTROL_OPTIONS.has(option.long)).map((option) => `option:${option.long}`));
|
|
159
|
+
if (authFor(source) === 'org')
|
|
160
|
+
facts.push('target-org');
|
|
161
|
+
if (source.mode.invocationPolicy.mutability !== 'read-only')
|
|
162
|
+
facts.push('explicit-user-authority');
|
|
163
|
+
return [...new Set(facts)].sort();
|
|
164
|
+
}
|
|
165
|
+
function preconditions(source) {
|
|
166
|
+
const conditions = requiredFacts(source).map((fact) => `Provide ${fact}.`);
|
|
167
|
+
if (source.contractMode?.requiresStepUp)
|
|
168
|
+
conditions.push('A valid step-up authorization is available.');
|
|
169
|
+
if (source.contractMode?.requiresIdempotencyKey)
|
|
170
|
+
conditions.push('A stable idempotency key is available.');
|
|
171
|
+
for (const rule of source.contractMode?.permissionRules ?? []) {
|
|
172
|
+
for (const requirement of rule.require) {
|
|
173
|
+
conditions.push(`Permission ${requirement.capability}:${requirement.action} is satisfied when ${rule.when}.`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return [...new Set(conditions)].sort();
|
|
177
|
+
}
|
|
178
|
+
function nodeId(commandId, modeId) {
|
|
179
|
+
return `${commandId}#${modeId}`;
|
|
180
|
+
}
|
|
181
|
+
function buildNode(source, nextNodeIds, forbiddenAlternatives) {
|
|
182
|
+
const schema = inputSchema(source);
|
|
183
|
+
const template = invocationTemplate(source);
|
|
184
|
+
const contractExamples = source.contract?.examples
|
|
185
|
+
.filter((example) => example.modeId === source.mode.modeId)
|
|
186
|
+
.map((example) => example.argv);
|
|
187
|
+
const examples = contractExamples && contractExamples.length > 0
|
|
188
|
+
? contractExamples
|
|
189
|
+
: [[template]];
|
|
190
|
+
return {
|
|
191
|
+
nodeId: nodeId(source.policy.commandId, source.mode.modeId),
|
|
192
|
+
commandId: source.policy.commandId,
|
|
193
|
+
modeId: source.mode.modeId,
|
|
194
|
+
surface: surfaceFor(source.leaf.path, source.policy.commandId),
|
|
195
|
+
commandPath: source.leaf.path,
|
|
196
|
+
argvTemplate: template,
|
|
197
|
+
inputSchema: schema,
|
|
198
|
+
inputSchemaDigest: (0, shared_1.canonicalJsonDigest)(schema),
|
|
199
|
+
inputSchemaRefs: source.contract?.inputSchemaRefs ?? [],
|
|
200
|
+
requiredFacts: requiredFacts(source),
|
|
201
|
+
examples,
|
|
202
|
+
preconditions: preconditions(source),
|
|
203
|
+
evidenceSources: ['nexusclaw.cli-result/v1', `${source.policy.commandId}#${source.mode.modeId}`],
|
|
204
|
+
effect: effectFor(source),
|
|
205
|
+
auth: authFor(source),
|
|
206
|
+
permissionProfileId: source.contractMode?.permissionProfileId ?? 'LOCAL',
|
|
207
|
+
requiresStepUp: source.contractMode?.requiresStepUp ?? false,
|
|
208
|
+
requiresIdempotencyKey: source.contractMode?.requiresIdempotencyKey ?? false,
|
|
209
|
+
supportsDryRun: source.mode.invocationPolicy.supportsDryRun,
|
|
210
|
+
forbiddenAlternatives: [...forbiddenAlternatives].sort(),
|
|
211
|
+
documentationRef: `cli-command:${source.policy.commandId}`,
|
|
212
|
+
recoveryHints: [
|
|
213
|
+
`nexus ai help --command ${source.policy.commandId} --json`,
|
|
214
|
+
'nexus ai help --routes --json',
|
|
215
|
+
],
|
|
216
|
+
nextNodeIds,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function resolveBuildSources(input) {
|
|
220
|
+
const contracts = allContracts();
|
|
221
|
+
const inventory = input.inventory ?? loadProgramInventory();
|
|
222
|
+
const policies = input.policies ?? (0, command_policy_registry_1.buildCommandPolicyRegistry)(inventory, contracts);
|
|
223
|
+
if (policies.length !== inventory.leaves.length) {
|
|
224
|
+
throw new Error(`CLI_COMMAND_ROUTING_REGISTRY_DRIFT: inventory=${inventory.leaves.length} policies=${policies.length}`);
|
|
225
|
+
}
|
|
226
|
+
const report = (0, command_policy_validator_1.validateCommandPolicyRegistry)(inventory, policies);
|
|
227
|
+
if (!report.ok) {
|
|
228
|
+
throw new Error(`CLI_COMMAND_ROUTING_REGISTRY_DRIFT: ${report.diagnostics.map((diagnostic) => diagnostic.ruleId).join(',')}`);
|
|
229
|
+
}
|
|
230
|
+
return { inventory, policies, contracts };
|
|
231
|
+
}
|
|
232
|
+
function buildCommandRoutingGraph(input = {}) {
|
|
233
|
+
const { inventory, policies, contracts } = resolveBuildSources(input);
|
|
234
|
+
const contractById = new Map(contracts.map((contract) => [contract.commandId, contract]));
|
|
235
|
+
const policyById = new Map(policies.map((policy) => [policy.commandId, policy]));
|
|
236
|
+
const modeByNode = new Map();
|
|
237
|
+
for (const leaf of inventory.leaves) {
|
|
238
|
+
const policy = policyById.get(leaf.commandId);
|
|
239
|
+
if (!policy)
|
|
240
|
+
throw new Error(`CLI_COMMAND_ROUTING_POLICY_MISSING: ${leaf.commandId}`);
|
|
241
|
+
const contract = contractById.get(leaf.commandId);
|
|
242
|
+
const contractModes = contract ? (0, command_contract_1.implementedModesOf)(contract) : [];
|
|
243
|
+
for (const mode of policy.modes) {
|
|
244
|
+
const source = {
|
|
245
|
+
leaf,
|
|
246
|
+
policy,
|
|
247
|
+
mode,
|
|
248
|
+
contract,
|
|
249
|
+
contractMode: contractModes.find((candidate) => candidate.modeId === mode.modeId),
|
|
250
|
+
};
|
|
251
|
+
if (contract && !source.contractMode && policy.source === 'v1-contract') {
|
|
252
|
+
throw new Error(`CLI_COMMAND_ROUTING_MODE_DRIFT: ${leaf.commandId}#${mode.modeId}`);
|
|
253
|
+
}
|
|
254
|
+
modeByNode.set(nodeId(leaf.commandId, mode.modeId), source);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const order = (0, command_order_1.buildImplementedCommandOrder)(contracts);
|
|
258
|
+
const edges = order.edges
|
|
259
|
+
.map((edge) => ({
|
|
260
|
+
edgeId: `${edge.from}->${edge.to}`,
|
|
261
|
+
fromNodeId: edge.from,
|
|
262
|
+
toNodeId: edge.to,
|
|
263
|
+
predicates: edge.when.allOf.map((predicate) => predicate.kind).sort(),
|
|
264
|
+
authorization: edge.authorization,
|
|
265
|
+
}))
|
|
266
|
+
.filter((edge) => modeByNode.has(edge.fromNodeId) && modeByNode.has(edge.toNodeId))
|
|
267
|
+
.sort((left, right) => left.edgeId.localeCompare(right.edgeId));
|
|
268
|
+
const nextByNode = new Map();
|
|
269
|
+
for (const edge of edges) {
|
|
270
|
+
const current = nextByNode.get(edge.fromNodeId) ?? [];
|
|
271
|
+
current.push(edge.toNodeId);
|
|
272
|
+
nextByNode.set(edge.fromNodeId, current);
|
|
273
|
+
}
|
|
274
|
+
const allSources = [...modeByNode.values()];
|
|
275
|
+
const lastPath = (path) => path.split(/\s+/u).at(-1) ?? path;
|
|
276
|
+
const nodes = allSources
|
|
277
|
+
.map((source) => {
|
|
278
|
+
const sameLeaf = allSources
|
|
279
|
+
.filter((candidate) => candidate.policy.commandId !== source.policy.commandId && lastPath(candidate.leaf.path) === lastPath(source.leaf.path))
|
|
280
|
+
.map((candidate) => nodeId(candidate.policy.commandId, candidate.mode.modeId));
|
|
281
|
+
return buildNode(source, nextByNode.get(nodeId(source.policy.commandId, source.mode.modeId)) ?? [], sameLeaf);
|
|
282
|
+
})
|
|
283
|
+
.sort((left, right) => left.nodeId.localeCompare(right.nodeId));
|
|
284
|
+
const routes = nodes.map((node) => ({
|
|
285
|
+
routeId: node.nodeId,
|
|
286
|
+
surface: node.surface,
|
|
287
|
+
intentLabels: [node.commandId, node.commandPath],
|
|
288
|
+
requiredFacts: node.requiredFacts,
|
|
289
|
+
startNodeIds: [node.nodeId],
|
|
290
|
+
nodeIds: [node.nodeId],
|
|
291
|
+
terminalAuthorization: node.effect === 'remote_write' || node.effect === 'promote'
|
|
292
|
+
? 'explicit_user'
|
|
293
|
+
: 'none',
|
|
294
|
+
}));
|
|
295
|
+
const v1Registry = (0, command_contract_exporter_1.exportCommandContracts)(contracts);
|
|
296
|
+
const policyExport = (0, command_policy_exporter_1.exportCommandPolicyRegistryV2)(inventory, policies, (0, command_policy_validator_1.validateCommandPolicyRegistry)(inventory, policies));
|
|
297
|
+
const registryDigest = (0, shared_1.canonicalJsonDigest)({
|
|
298
|
+
v1: v1Registry.registryDigest,
|
|
299
|
+
v2: policyExport.registryDigest,
|
|
300
|
+
});
|
|
301
|
+
const buildInfo = (0, build_info_1.loadBuildInfo)();
|
|
302
|
+
const base = {
|
|
303
|
+
schemaVersion: shared_1.CLI_COMMAND_ROUTING_SCHEMA_VERSION,
|
|
304
|
+
cliVersion: input.cliVersion ?? buildInfo.version,
|
|
305
|
+
coreCommitSha: input.coreCommitSha ?? (buildInfo.gitSha === 'unknown' ? null : buildInfo.gitSha),
|
|
306
|
+
generatedAt: input.generatedAt ?? new Date().toISOString(),
|
|
307
|
+
registryDigest,
|
|
308
|
+
context: {
|
|
309
|
+
mode: input.mode ?? 'offline',
|
|
310
|
+
workspaceId: input.workspaceId ?? null,
|
|
311
|
+
principalScopeDigest: input.principalScopeDigest ?? null,
|
|
312
|
+
expiresAt: input.expiresAt ?? null,
|
|
313
|
+
},
|
|
314
|
+
surfaces: SURFACES,
|
|
315
|
+
routes,
|
|
316
|
+
nodes,
|
|
317
|
+
edges,
|
|
318
|
+
};
|
|
319
|
+
const { generatedAt: _generatedAt, ...graphIdentity } = base;
|
|
320
|
+
return {
|
|
321
|
+
...base,
|
|
322
|
+
graphDigest: (0, shared_1.canonicalJsonDigest)(graphIdentity),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function resolveCommandRoutingPlan(graph, routeId, facts) {
|
|
326
|
+
const { graphDigest, generatedAt: _generatedAt, ...unsignedGraph } = graph;
|
|
327
|
+
if ((0, shared_1.canonicalJsonDigest)(unsignedGraph) !== graphDigest) {
|
|
328
|
+
return {
|
|
329
|
+
ok: false,
|
|
330
|
+
code: 'CLI_ROUTE_STALE',
|
|
331
|
+
message: 'The routing graph digest does not match its contents.',
|
|
332
|
+
candidates: [],
|
|
333
|
+
missingFacts: [],
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
if (graph.context.expiresAt) {
|
|
337
|
+
const expiry = Date.parse(graph.context.expiresAt);
|
|
338
|
+
if (!Number.isFinite(expiry) || expiry <= Date.now()) {
|
|
339
|
+
return {
|
|
340
|
+
ok: false,
|
|
341
|
+
code: 'CLI_ROUTE_STALE',
|
|
342
|
+
message: 'The routing graph context has expired.',
|
|
343
|
+
candidates: [],
|
|
344
|
+
missingFacts: [],
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const normalized = routeId.trim();
|
|
349
|
+
if (!normalized) {
|
|
350
|
+
return {
|
|
351
|
+
ok: false,
|
|
352
|
+
code: 'CLI_ROUTE_UNSUPPORTED',
|
|
353
|
+
message: 'A route id is required.',
|
|
354
|
+
candidates: [],
|
|
355
|
+
missingFacts: [],
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const route = graph.routes.filter((candidate) => candidate.routeId === normalized);
|
|
359
|
+
if (route.length === 0) {
|
|
360
|
+
return {
|
|
361
|
+
ok: false,
|
|
362
|
+
code: 'CLI_ROUTE_UNSUPPORTED',
|
|
363
|
+
message: `No route is registered for ${routeId}.`,
|
|
364
|
+
candidates: [],
|
|
365
|
+
missingFacts: [],
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (route.length > 1) {
|
|
369
|
+
return {
|
|
370
|
+
ok: false,
|
|
371
|
+
code: 'CLI_ROUTE_AMBIGUOUS',
|
|
372
|
+
message: `Multiple routes are registered for ${routeId}.`,
|
|
373
|
+
candidates: route.map((candidate) => candidate.routeId),
|
|
374
|
+
missingFacts: [],
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (facts) {
|
|
378
|
+
const selected = route[0];
|
|
379
|
+
const missingFacts = selected.requiredFacts.filter((fact) => {
|
|
380
|
+
if (fact === 'target-org')
|
|
381
|
+
return !facts.targetOrg;
|
|
382
|
+
if (fact === 'explicit-user-authority')
|
|
383
|
+
return facts.explicitUserAuthority !== true;
|
|
384
|
+
if (fact === 'workspace')
|
|
385
|
+
return !facts.workspaceId;
|
|
386
|
+
if (fact === 'surface')
|
|
387
|
+
return !facts.surface;
|
|
388
|
+
if (fact.startsWith('option:--')) {
|
|
389
|
+
const key = fact.slice('option:--'.length).replace(/-([a-z])/gu, (_, letter) => letter.toUpperCase());
|
|
390
|
+
return facts.values?.[key] === undefined && facts.values?.[`input_${key}`] === undefined;
|
|
391
|
+
}
|
|
392
|
+
if (fact.startsWith('argument:'))
|
|
393
|
+
return facts.values?.[fact.slice('argument:'.length)] === undefined;
|
|
394
|
+
return false;
|
|
395
|
+
});
|
|
396
|
+
if (missingFacts.length > 0) {
|
|
397
|
+
return {
|
|
398
|
+
ok: false,
|
|
399
|
+
code: 'CLI_ROUTE_MISSING_FACTS',
|
|
400
|
+
message: `Route ${normalized} is missing required facts: ${missingFacts.join(', ')}.`,
|
|
401
|
+
candidates: [normalized],
|
|
402
|
+
missingFacts,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const node = graph.nodes.find((candidate) => candidate.nodeId === route[0].startNodeIds[0]);
|
|
407
|
+
if (!node) {
|
|
408
|
+
return {
|
|
409
|
+
ok: false,
|
|
410
|
+
code: 'CLI_ROUTE_STALE',
|
|
411
|
+
message: `Route ${routeId} references a missing command node.`,
|
|
412
|
+
candidates: [routeId],
|
|
413
|
+
missingFacts: [],
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (graph.context.mode === 'offline' && (node.auth === 'org' || node.effect === 'remote_read' || node.effect === 'remote_write' || node.effect === 'promote')) {
|
|
417
|
+
return {
|
|
418
|
+
ok: false,
|
|
419
|
+
code: 'CLI_ROUTE_UNSUPPORTED',
|
|
420
|
+
message: `Route ${normalized} requires an online authenticated context.`,
|
|
421
|
+
candidates: [],
|
|
422
|
+
missingFacts: ['online-context'],
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const unsigned = {
|
|
426
|
+
schemaVersion: shared_1.CLI_COMMAND_ROUTING_SCHEMA_VERSION,
|
|
427
|
+
routeId: normalized,
|
|
428
|
+
node,
|
|
429
|
+
context: graph.context,
|
|
430
|
+
graphDigest: graph.graphDigest,
|
|
431
|
+
};
|
|
432
|
+
return {
|
|
433
|
+
ok: true,
|
|
434
|
+
plan: {
|
|
435
|
+
...unsigned,
|
|
436
|
+
planDigest: (0, shared_1.canonicalJsonDigest)(unsigned),
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function argvHasFlag(argv, flag) {
|
|
441
|
+
return argv.some((token) => token === flag || token.startsWith(`${flag}=`));
|
|
442
|
+
}
|
|
443
|
+
function validateCommandRoutingPlanForDispatch(plan, argv, graph, explicitUserAuthority = false) {
|
|
444
|
+
const { planDigest, ...unsignedPlan } = plan;
|
|
445
|
+
if ((0, shared_1.canonicalJsonDigest)(unsignedPlan) !== planDigest) {
|
|
446
|
+
return { ok: false, code: 'CLI_ROUTE_STALE', message: 'Route plan digest does not match its contents.' };
|
|
447
|
+
}
|
|
448
|
+
const { graphDigest, generatedAt: _generatedAt, ...unsignedGraph } = graph;
|
|
449
|
+
if ((0, shared_1.canonicalJsonDigest)(unsignedGraph) !== graphDigest || plan.graphDigest !== graphDigest) {
|
|
450
|
+
return { ok: false, code: 'CLI_ROUTE_STALE', message: 'Route plan graph digest is stale.' };
|
|
451
|
+
}
|
|
452
|
+
if (plan.context.mode !== graph.context.mode
|
|
453
|
+
|| plan.context.workspaceId !== graph.context.workspaceId
|
|
454
|
+
|| plan.context.principalScopeDigest !== graph.context.principalScopeDigest
|
|
455
|
+
|| plan.context.expiresAt !== graph.context.expiresAt) {
|
|
456
|
+
return { ok: false, code: 'CLI_ROUTE_STALE', message: 'Route plan context does not match the current CLI context.' };
|
|
457
|
+
}
|
|
458
|
+
const node = graph.nodes.find((candidate) => candidate.nodeId === `${plan.node.commandId}#${plan.node.modeId}`);
|
|
459
|
+
if (!node || (0, shared_1.canonicalJsonDigest)(node) !== (0, shared_1.canonicalJsonDigest)(plan.node)) {
|
|
460
|
+
return { ok: false, code: 'CLI_ROUTE_STALE', message: 'Route plan node does not match the current command registry.' };
|
|
461
|
+
}
|
|
462
|
+
const pathTokens = node.commandPath.split(/\s+/u);
|
|
463
|
+
const argvTokens = argv.slice(2).filter((token, index, all) => {
|
|
464
|
+
if (token === '--json')
|
|
465
|
+
return false;
|
|
466
|
+
if (token === '--route-plan')
|
|
467
|
+
return false;
|
|
468
|
+
if (index > 0 && all[index - 1] === '--route-plan')
|
|
469
|
+
return false;
|
|
470
|
+
return true;
|
|
471
|
+
});
|
|
472
|
+
const pathStart = argvTokens.findIndex((token) => token === pathTokens[0]);
|
|
473
|
+
if (pathStart < 0 || pathTokens.some((token, index) => argvTokens[pathStart + index] !== token)) {
|
|
474
|
+
return { ok: false, code: 'CLI_ROUTE_STALE', message: 'Route plan command path does not match argv.' };
|
|
475
|
+
}
|
|
476
|
+
for (const token of node.argvTemplate.split(/\s+/u)) {
|
|
477
|
+
if (!token.startsWith('--') || token === '--json' || token === '--dry-run')
|
|
478
|
+
continue;
|
|
479
|
+
if (!argvHasFlag(argv, token)) {
|
|
480
|
+
return { ok: false, code: 'CLI_ROUTE_MISSING_FACTS', message: `Route plan requires argv option ${token}.` };
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if ((node.effect === 'remote_write' || node.effect === 'promote') && !explicitUserAuthority) {
|
|
484
|
+
return { ok: false, code: 'CLI_ROUTE_MISSING_FACTS', message: 'Remote route execution requires explicit user authority.' };
|
|
485
|
+
}
|
|
486
|
+
return { ok: true, graphDigest };
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=command-routing.js.map
|