@nexusclawhq/cli 0.3.84 → 0.3.86
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 +15 -0
- package/README.md +13 -0
- package/dist/build-info.json +4 -4
- package/dist/nexus-cli/src/cli-runner.test.js +15 -0
- package/dist/nexus-cli/src/cli-runner.test.js.map +1 -1
- package/dist/nexus-cli/src/cli.js +1 -1
- package/dist/nexus-cli/src/cli.js.map +1 -1
- package/dist/nexus-cli/src/commands/ai/help.test.js +5 -4
- package/dist/nexus-cli/src/commands/ai/help.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.js +2 -2
- package/dist/nexus-cli/src/commands/doctor/doctor.js.map +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.test.js +1 -1
- package/dist/nexus-cli/src/commands/doctor/doctor.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/employee/candidate.test.js +14 -22
- package/dist/nexus-cli/src/commands/employee/candidate.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/display.js +5 -1
- package/dist/nexus-cli/src/commands/org/display.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/display.test.js +63 -0
- package/dist/nexus-cli/src/commands/org/display.test.js.map +1 -0
- package/dist/nexus-cli/src/commands/org/list.js +4 -0
- package/dist/nexus-cli/src/commands/org/list.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/login-web.js +25 -12
- package/dist/nexus-cli/src/commands/org/login-web.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/open.js +8 -1
- package/dist/nexus-cli/src/commands/org/open.js.map +1 -1
- package/dist/nexus-cli/src/commands/org/open.test.js +38 -0
- package/dist/nexus-cli/src/commands/org/open.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/p1-operations.test.js +29 -11
- package/dist/nexus-cli/src/commands/p1-operations.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/revision/revision.e2e.test.js +22 -1
- package/dist/nexus-cli/src/commands/revision/revision.e2e.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/pull.js +31 -10
- package/dist/nexus-cli/src/commands/source/pull.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/push.js +56 -3
- package/dist/nexus-cli/src/commands/source/push.js.map +1 -1
- package/dist/nexus-cli/src/commands/source/source-sync.e2e.test.js +290 -3
- package/dist/nexus-cli/src/commands/source/source-sync.e2e.test.js.map +1 -1
- package/dist/nexus-cli/src/commands/workspace/billing-download.test.js +125 -0
- package/dist/nexus-cli/src/commands/workspace/billing-download.test.js.map +1 -0
- package/dist/nexus-cli/src/commands/workspace/billing.d.ts +2 -0
- package/dist/nexus-cli/src/commands/workspace/billing.js +84 -10
- package/dist/nexus-cli/src/commands/workspace/billing.js.map +1 -1
- package/dist/nexus-cli/src/contracts/command-contract-coverage-baseline.json +4 -4
- package/dist/nexus-cli/src/contracts/command-contract-matrix.generated.test.js +83 -36
- package/dist/nexus-cli/src/contracts/command-contract-matrix.generated.test.js.map +1 -1
- package/dist/nexus-cli/src/contracts/command-contract-matrix.scenarios.js +3 -0
- package/dist/nexus-cli/src/contracts/command-contract-matrix.scenarios.js.map +1 -1
- package/dist/nexus-cli/src/runtime/output-coordinator.d.ts +1 -0
- package/dist/nexus-cli/src/runtime/output-coordinator.js +5 -0
- package/dist/nexus-cli/src/runtime/output-coordinator.js.map +1 -1
- package/dist/nexus-cli/src/services/api-client.d.ts +8 -2
- package/dist/nexus-cli/src/services/api-client.js +257 -154
- package/dist/nexus-cli/src/services/api-client.js.map +1 -1
- package/dist/nexus-cli/src/services/api-client.test.js +631 -3
- package/dist/nexus-cli/src/services/api-client.test.js.map +1 -1
- package/dist/nexus-cli/src/services/auth-store.d.ts +1 -0
- package/dist/nexus-cli/src/services/auth-store.js +45 -1
- package/dist/nexus-cli/src/services/auth-store.js.map +1 -1
- package/dist/nexus-cli/src/services/auth-store.test.js +41 -0
- package/dist/nexus-cli/src/services/auth-store.test.js.map +1 -1
- package/dist/nexus-cli/src/services/config.d.ts +0 -1
- package/dist/nexus-cli/src/services/config.js +4 -3
- package/dist/nexus-cli/src/services/config.js.map +1 -1
- package/dist/nexus-cli/src/services/config.test.js +1 -1
- package/dist/nexus-cli/src/services/config.test.js.map +1 -1
- package/dist/nexus-cli/src/services/doctor.d.ts +2 -1
- package/dist/nexus-cli/src/services/doctor.js +35 -20
- package/dist/nexus-cli/src/services/doctor.js.map +1 -1
- package/dist/nexus-cli/src/services/doctor.test.js +14 -6
- package/dist/nexus-cli/src/services/doctor.test.js.map +1 -1
- package/dist/nexus-cli/src/services/external-object-sort.d.ts +25 -0
- package/dist/nexus-cli/src/services/external-object-sort.js +249 -0
- package/dist/nexus-cli/src/services/external-object-sort.js.map +1 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.js +78 -0
- package/dist/nexus-cli/src/services/external-object-sort.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-agent.d.ts +12 -0
- package/dist/nexus-cli/src/services/http-agent.js +88 -0
- package/dist/nexus-cli/src/services/http-agent.js.map +1 -0
- package/dist/nexus-cli/src/services/http-agent.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-agent.test.js +129 -0
- package/dist/nexus-cli/src/services/http-agent.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.js +62 -0
- package/dist/nexus-cli/src/services/http-pool-cli.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.d.ts +14 -0
- package/dist/nexus-cli/src/services/http-pool-client.js +95 -0
- package/dist/nexus-cli/src/services/http-pool-client.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.js +63 -0
- package/dist/nexus-cli/src/services/http-pool-client.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.d.ts +15 -0
- package/dist/nexus-cli/src/services/http-pool-identity.js +115 -0
- package/dist/nexus-cli/src/services/http-pool-identity.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.js +41 -0
- package/dist/nexus-cli/src/services/http-pool-identity.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.d.ts +3 -0
- package/dist/nexus-cli/src/services/http-pool-server.js +143 -0
- package/dist/nexus-cli/src/services/http-pool-server.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.js +170 -0
- package/dist/nexus-cli/src/services/http-pool-server.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.d.ts +6 -0
- package/dist/nexus-cli/src/services/http-pool-start.js +155 -0
- package/dist/nexus-cli/src/services/http-pool-start.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.js +175 -0
- package/dist/nexus-cli/src/services/http-pool-start.test.js.map +1 -0
- package/dist/nexus-cli/src/services/http-pool-worker.d.ts +2 -0
- package/dist/nexus-cli/src/services/http-pool-worker.js +89 -0
- package/dist/nexus-cli/src/services/http-pool-worker.js.map +1 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.js +175 -0
- package/dist/nexus-cli/src/services/http-proxy-https.test.js.map +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.d.ts +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.js +499 -0
- package/dist/nexus-cli/src/services/large-json-hash.js.map +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.js +329 -0
- package/dist/nexus-cli/src/services/large-json-hash.test.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/initialize.js +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/initialize.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.d.ts +3 -1
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.js +142 -4
- package/dist/nexus-cli/src/services/revision-ledger/ledger-storage.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.js +61 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger-memory.test.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger.test.js +113 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-ledger.test.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.d.ts +8 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.js +29 -0
- package/dist/nexus-cli/src/services/revision-ledger/revision-service.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/rollback-service.js +3 -1
- package/dist/nexus-cli/src/services/revision-ledger/rollback-service.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.d.ts +2 -0
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.js +29 -0
- package/dist/nexus-cli/src/services/revision-ledger/source-tracking-bridge.js.map +1 -1
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.d.ts +2 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.js +131 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.js.map +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.js +30 -0
- package/dist/nexus-cli/src/services/revision-ledger/streamed-ledger.test.js.map +1 -0
- package/dist/nexus-cli/src/services/safe-json-stream.d.ts +2 -0
- package/dist/nexus-cli/src/services/safe-json-stream.js +20 -0
- package/dist/nexus-cli/src/services/safe-json-stream.js.map +1 -0
- package/dist/nexus-cli/src/services/source-command-governance.test.js +7 -0
- package/dist/nexus-cli/src/services/source-command-governance.test.js.map +1 -1
- package/dist/nexus-cli/src/services/source-pull-plan.d.ts +1 -0
- package/dist/nexus-cli/src/services/source-pull-plan.js +5 -1
- package/dist/nexus-cli/src/services/source-pull-plan.js.map +1 -1
- package/dist/nexus-cli/src/services/source-response-stream.d.ts +12 -0
- package/dist/nexus-cli/src/services/source-response-stream.js +236 -0
- package/dist/nexus-cli/src/services/source-response-stream.js.map +1 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.js +110 -0
- package/dist/nexus-cli/src/services/source-response-stream.test.js.map +1 -0
- package/dist/nexus-cli/src/services/source-taxonomy.js +2 -0
- package/dist/nexus-cli/src/services/source-taxonomy.js.map +1 -1
- package/dist/nexus-cli/src/services/source-tracker.d.ts +9 -2
- package/dist/nexus-cli/src/services/source-tracker.js +34 -5
- package/dist/nexus-cli/src/services/source-tracker.js.map +1 -1
- package/dist/nexus-cli/src/services/source-tracker.test.js +101 -0
- package/dist/nexus-cli/src/services/source-tracker.test.js.map +1 -1
- package/dist/nexus-cli/src/services/sse-client.d.ts +4 -0
- package/dist/nexus-cli/src/services/sse-client.js +108 -71
- package/dist/nexus-cli/src/services/sse-client.js.map +1 -1
- package/dist/nexus-cli/src/services/sse-client.test.d.ts +1 -0
- package/dist/nexus-cli/src/services/sse-client.test.js +216 -0
- package/dist/nexus-cli/src/services/sse-client.test.js.map +1 -0
- package/dist/nexus-cli/src/services/update-check.js +37 -30
- package/dist/nexus-cli/src/services/update-check.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 +4 -1
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.d.ts +0 -99
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.js +0 -3
- package/dist/nexus-cli/node_modules/@nexusclaw/shared/dist/agent-executable-assets/command-routing.types.js.map +0 -1
- package/dist/nexus-cli/src/contracts/command-routing.d.ts +0 -25
- package/dist/nexus-cli/src/contracts/command-routing.js +0 -488
- package/dist/nexus-cli/src/contracts/command-routing.js.map +0 -1
- package/dist/nexus-cli/src/contracts/command-routing.test.js +0 -73
- package/dist/nexus-cli/src/contracts/command-routing.test.js.map +0 -1
- package/dist/nexus-cli/src/contracts/task-route.registry.d.ts +0 -40
- package/dist/nexus-cli/src/contracts/task-route.registry.js +0 -234
- package/dist/nexus-cli/src/contracts/task-route.registry.js.map +0 -1
- package/dist/nexus-cli/src/contracts/task-route.registry.test.js +0 -65
- package/dist/nexus-cli/src/contracts/task-route.registry.test.js.map +0 -1
- /package/dist/nexus-cli/src/{contracts/command-routing.test.d.ts → commands/org/display.test.d.ts} +0 -0
- /package/dist/nexus-cli/src/{contracts/task-route.registry.test.d.ts → commands/workspace/billing-download.test.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexusclawhq/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.86",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"README.md",
|
|
@@ -32,7 +32,10 @@
|
|
|
32
32
|
"libphonenumber-js": "1.13.10",
|
|
33
33
|
"open": "^10.1.0",
|
|
34
34
|
"ora": "^5.4.1",
|
|
35
|
+
"proper-lockfile": "4.1.2",
|
|
36
|
+
"proxy-agent": "6.5.0",
|
|
35
37
|
"semver": "7.8.5",
|
|
38
|
+
"stream-json": "1.9.1",
|
|
36
39
|
"typescript": "5.9.3"
|
|
37
40
|
},
|
|
38
41
|
"engines": {
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { CliArgvPredicateExprV1, CliEffectKind } from './cli-contract.types';
|
|
2
|
-
import type { AiContextSha256 } from './ai-authoring-context.types';
|
|
3
|
-
import type { JsonObject } from './json-value';
|
|
4
|
-
import { CLI_COMMAND_ROUTING_SCHEMA_VERSION } from './contract-versions';
|
|
5
|
-
export type CliRoutingSurfaceV1 = 'code' | 'flow' | 'metadata' | 'source' | 'workforce' | 'observe' | 'release';
|
|
6
|
-
export type CliRoutingAuthorizationV1 = 'none' | 'explicit_user';
|
|
7
|
-
export interface CliAgentCommandNodeV1 {
|
|
8
|
-
readonly nodeId: string;
|
|
9
|
-
readonly commandId: string;
|
|
10
|
-
readonly modeId: string;
|
|
11
|
-
readonly surface: CliRoutingSurfaceV1;
|
|
12
|
-
readonly commandPath: string;
|
|
13
|
-
readonly argvTemplate: string;
|
|
14
|
-
readonly inputSchema: JsonObject;
|
|
15
|
-
readonly inputSchemaDigest: AiContextSha256;
|
|
16
|
-
readonly inputSchemaRefs: ReadonlyArray<string>;
|
|
17
|
-
readonly requiredFacts: ReadonlyArray<string>;
|
|
18
|
-
readonly examples: ReadonlyArray<ReadonlyArray<string>>;
|
|
19
|
-
readonly preconditions: ReadonlyArray<string>;
|
|
20
|
-
readonly evidenceSources: ReadonlyArray<string>;
|
|
21
|
-
readonly effect: CliEffectKind;
|
|
22
|
-
readonly auth: 'none' | 'org';
|
|
23
|
-
readonly permissionProfileId: string;
|
|
24
|
-
readonly requiresStepUp: boolean;
|
|
25
|
-
readonly requiresIdempotencyKey: boolean;
|
|
26
|
-
readonly supportsDryRun: boolean;
|
|
27
|
-
readonly forbiddenAlternatives: ReadonlyArray<string>;
|
|
28
|
-
readonly documentationRef: string;
|
|
29
|
-
readonly recoveryHints: ReadonlyArray<string>;
|
|
30
|
-
readonly nextNodeIds: ReadonlyArray<string>;
|
|
31
|
-
}
|
|
32
|
-
export interface CliAgentRouteV1 {
|
|
33
|
-
readonly routeId: string;
|
|
34
|
-
readonly surface: CliRoutingSurfaceV1;
|
|
35
|
-
readonly intentLabels: ReadonlyArray<string>;
|
|
36
|
-
readonly requiredFacts: ReadonlyArray<string>;
|
|
37
|
-
readonly startNodeIds: ReadonlyArray<string>;
|
|
38
|
-
readonly nodeIds: ReadonlyArray<string>;
|
|
39
|
-
readonly terminalAuthorization: CliRoutingAuthorizationV1;
|
|
40
|
-
}
|
|
41
|
-
export interface CliAgentCommandEdgeV1 {
|
|
42
|
-
readonly edgeId: string;
|
|
43
|
-
readonly fromNodeId: string;
|
|
44
|
-
readonly toNodeId: string;
|
|
45
|
-
readonly predicates: ReadonlyArray<string>;
|
|
46
|
-
readonly authorization: CliRoutingAuthorizationV1;
|
|
47
|
-
}
|
|
48
|
-
export interface CliAgentCommandRoutingContextV1 {
|
|
49
|
-
readonly mode: 'offline' | 'online';
|
|
50
|
-
readonly workspaceId: string | null;
|
|
51
|
-
readonly principalScopeDigest: AiContextSha256 | null;
|
|
52
|
-
readonly expiresAt: string | null;
|
|
53
|
-
}
|
|
54
|
-
export interface CliAgentCommandRoutingFactsV1 {
|
|
55
|
-
readonly surface?: CliRoutingSurfaceV1;
|
|
56
|
-
readonly assetKind?: string;
|
|
57
|
-
readonly localMode?: 'local' | 'remote';
|
|
58
|
-
readonly targetOrg?: string;
|
|
59
|
-
readonly candidateId?: string;
|
|
60
|
-
readonly workspaceId?: string;
|
|
61
|
-
readonly evidenceDigests?: ReadonlyArray<AiContextSha256>;
|
|
62
|
-
readonly explicitUserAuthority?: boolean;
|
|
63
|
-
/** Normalized argument/option values supplied for route validation. */
|
|
64
|
-
readonly values?: JsonObject;
|
|
65
|
-
}
|
|
66
|
-
export interface CliAgentCommandRoutingGraphV1 {
|
|
67
|
-
readonly schemaVersion: typeof CLI_COMMAND_ROUTING_SCHEMA_VERSION;
|
|
68
|
-
readonly cliVersion: string;
|
|
69
|
-
readonly coreCommitSha: string | null;
|
|
70
|
-
readonly generatedAt: string;
|
|
71
|
-
readonly registryDigest: AiContextSha256;
|
|
72
|
-
readonly graphDigest: AiContextSha256;
|
|
73
|
-
readonly context: CliAgentCommandRoutingContextV1;
|
|
74
|
-
readonly surfaces: ReadonlyArray<CliRoutingSurfaceV1>;
|
|
75
|
-
readonly routes: ReadonlyArray<CliAgentRouteV1>;
|
|
76
|
-
readonly nodes: ReadonlyArray<CliAgentCommandNodeV1>;
|
|
77
|
-
readonly edges: ReadonlyArray<CliAgentCommandEdgeV1>;
|
|
78
|
-
}
|
|
79
|
-
export type CliAgentCommandRoutingFailureCode = 'CLI_ROUTE_UNSUPPORTED' | 'CLI_ROUTE_AMBIGUOUS' | 'CLI_ROUTE_MISSING_FACTS' | 'CLI_ROUTE_STALE';
|
|
80
|
-
export interface CliAgentCommandRoutingPlanV1 {
|
|
81
|
-
readonly schemaVersion: typeof CLI_COMMAND_ROUTING_SCHEMA_VERSION;
|
|
82
|
-
readonly routeId: string;
|
|
83
|
-
readonly node: CliAgentCommandNodeV1;
|
|
84
|
-
readonly context: CliAgentCommandRoutingContextV1;
|
|
85
|
-
readonly graphDigest: AiContextSha256;
|
|
86
|
-
readonly planDigest: AiContextSha256;
|
|
87
|
-
}
|
|
88
|
-
export type CliAgentCommandRoutingResolutionV1 = {
|
|
89
|
-
readonly ok: true;
|
|
90
|
-
readonly plan: CliAgentCommandRoutingPlanV1;
|
|
91
|
-
} | {
|
|
92
|
-
readonly ok: false;
|
|
93
|
-
readonly code: CliAgentCommandRoutingFailureCode;
|
|
94
|
-
readonly message: string;
|
|
95
|
-
readonly candidates: ReadonlyArray<string>;
|
|
96
|
-
readonly missingFacts: ReadonlyArray<string>;
|
|
97
|
-
};
|
|
98
|
-
/** Keep the predicate type reachable from the public routing module barrel. */
|
|
99
|
-
export type CliRoutingPredicateV1 = CliArgvPredicateExprV1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-routing.types.js","sourceRoot":"","sources":["../../src/agent-executable-assets/command-routing.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
|
@@ -1,488 +0,0 @@
|
|
|
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
|