@lightdash-tools/cli 0.5.0 → 0.7.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/README.md +6 -2
- package/dist/commands/agentops/apply.d.ts +5 -0
- package/dist/commands/agentops/apply.js +53 -0
- package/dist/commands/agentops/bundle-schema.d.ts +5 -0
- package/dist/commands/agentops/bundle-schema.js +16 -0
- package/dist/commands/agentops/drift.d.ts +5 -0
- package/dist/commands/agentops/drift.js +46 -0
- package/dist/commands/agentops/evaluate-gate.d.ts +5 -0
- package/dist/commands/agentops/evaluate-gate.js +89 -0
- package/dist/commands/agentops/gate-schema.d.ts +5 -0
- package/dist/commands/agentops/gate-schema.js +16 -0
- package/dist/commands/agentops/plan.d.ts +5 -0
- package/dist/commands/agentops/plan.js +42 -0
- package/dist/commands/agentops/state.d.ts +4 -0
- package/dist/commands/agentops/state.js +8 -0
- package/dist/commands/agentops.d.ts +8 -0
- package/dist/commands/agentops.js +26 -0
- package/dist/commands/agentops.test.d.ts +1 -0
- package/dist/commands/agentops.test.js +400 -0
- package/dist/commands/agents-crud.d.ts +8 -0
- package/dist/commands/agents-crud.js +144 -0
- package/dist/commands/agents-discovery.d.ts +8 -0
- package/dist/commands/agents-discovery.js +139 -0
- package/dist/commands/agents-discovery.test.d.ts +1 -0
- package/dist/commands/agents-discovery.test.js +13 -0
- package/dist/commands/agents-evals.d.ts +8 -0
- package/dist/commands/agents-evals.js +246 -0
- package/dist/commands/agents-threads.d.ts +8 -0
- package/dist/commands/agents-threads.js +83 -0
- package/dist/commands/agents.js +8 -360
- package/dist/commands/ai-agents.js +52 -70
- package/dist/commands/charts.js +35 -46
- package/dist/commands/content.js +3 -12
- package/dist/commands/dashboards.js +3 -12
- package/dist/commands/explores.js +12 -21
- package/dist/commands/groups.js +44 -63
- package/dist/commands/metrics.js +6 -15
- package/dist/commands/organization-roles.js +28 -39
- package/dist/commands/organization.js +3 -12
- package/dist/commands/project-access.js +9 -18
- package/dist/commands/project-role-assignments.js +15 -24
- package/dist/commands/projects.js +33 -26
- package/dist/commands/query.js +30 -41
- package/dist/commands/schedulers.js +6 -15
- package/dist/commands/schema.js +33 -10
- package/dist/commands/schema.test.js +58 -1
- package/dist/commands/space-access.js +12 -21
- package/dist/commands/spaces.js +6 -15
- package/dist/commands/tags.js +6 -15
- package/dist/commands/users.js +23 -41
- package/dist/index.js +18 -16
- package/dist/index.test.js +9 -9
- package/dist/utils/cli-params.d.ts +4 -0
- package/dist/utils/cli-params.js +15 -0
- package/dist/utils/cli-params.test.d.ts +1 -0
- package/dist/utils/cli-params.test.js +12 -0
- package/dist/utils/file-input.d.ts +30 -0
- package/dist/utils/file-input.js +77 -0
- package/dist/utils/file-input.test.d.ts +1 -0
- package/dist/utils/file-input.test.js +68 -0
- package/dist/utils/safety.d.ts +5 -0
- package/dist/utils/safety.js +97 -109
- package/dist/utils/safety.test.js +135 -33
- package/package.json +14 -5
- package/src/commands/agentops/apply.ts +77 -0
- package/src/commands/agentops/bundle-schema.ts +20 -0
- package/src/commands/agentops/drift.ts +63 -0
- package/src/commands/agentops/evaluate-gate.ts +128 -0
- package/src/commands/agentops/gate-schema.ts +20 -0
- package/src/commands/agentops/plan.ts +55 -0
- package/src/commands/agentops/state.ts +5 -0
- package/src/commands/agentops.test.ts +454 -0
- package/src/commands/agentops.ts +28 -0
- package/src/commands/agents-crud.ts +193 -0
- package/src/commands/agents-discovery.test.ts +16 -0
- package/src/commands/agents-discovery.ts +180 -0
- package/src/commands/agents-evals.ts +353 -0
- package/src/commands/agents-threads.ts +116 -0
- package/src/commands/agents.ts +9 -493
- package/src/commands/ai-agents.ts +37 -28
- package/src/commands/charts.ts +6 -3
- package/src/commands/content.ts +3 -1
- package/src/commands/dashboards.ts +3 -1
- package/src/commands/explores.ts +3 -1
- package/src/commands/groups.ts +33 -33
- package/src/commands/metrics.ts +3 -1
- package/src/commands/organization-roles.ts +3 -1
- package/src/commands/organization.ts +3 -1
- package/src/commands/project-access.ts +3 -1
- package/src/commands/project-role-assignments.ts +3 -1
- package/src/commands/projects.ts +44 -18
- package/src/commands/query.ts +4 -1
- package/src/commands/schedulers.ts +3 -1
- package/src/commands/schema.test.ts +72 -1
- package/src/commands/schema.ts +60 -14
- package/src/commands/space-access.ts +3 -1
- package/src/commands/spaces.ts +3 -1
- package/src/commands/tags.ts +3 -1
- package/src/commands/users.ts +29 -25
- package/src/index.test.ts +10 -9
- package/src/index.ts +19 -16
- package/src/utils/cli-params.test.ts +13 -0
- package/src/utils/cli-params.ts +12 -0
- package/src/utils/client.test.ts +1 -0
- package/src/utils/file-input.test.ts +91 -0
- package/src/utils/file-input.ts +83 -0
- package/src/utils/safety.test.ts +158 -2
- package/src/utils/safety.ts +27 -20
- package/tsconfig.json +2 -1
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "CLI for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/yu-iskw/lightdash-tools.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
6
11
|
"license": "Apache-2.0",
|
|
7
12
|
"author": "",
|
|
8
13
|
"main": "dist/index.js",
|
|
@@ -11,12 +16,16 @@
|
|
|
11
16
|
"lightdash-tools": "./dist/index.js"
|
|
12
17
|
},
|
|
13
18
|
"dependencies": {
|
|
14
|
-
"commander": "^
|
|
15
|
-
"
|
|
16
|
-
"@lightdash-tools/
|
|
19
|
+
"commander": "^15.0.0",
|
|
20
|
+
"yaml": "^2.9.0",
|
|
21
|
+
"@lightdash-tools/client": "0.7.0",
|
|
22
|
+
"@lightdash-tools/common": "0.7.0"
|
|
17
23
|
},
|
|
18
24
|
"devDependencies": {
|
|
19
|
-
"@types/node": "^25.3
|
|
25
|
+
"@types/node": "^25.9.3"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
20
29
|
},
|
|
21
30
|
"scripts": {
|
|
22
31
|
"build": "tsc"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops apply — apply bundle diff to Lightdash.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { applyBundleDiff } from '@lightdash-tools/client';
|
|
6
|
+
import {
|
|
7
|
+
WRITE_DESTRUCTIVE,
|
|
8
|
+
WRITE_NONDESTRUCTIVE,
|
|
9
|
+
computeBundleDiff,
|
|
10
|
+
isAllowed,
|
|
11
|
+
parseLightdashAiAgentBundle,
|
|
12
|
+
} from '@lightdash-tools/common';
|
|
13
|
+
|
|
14
|
+
import { getClient } from '../../utils/client';
|
|
15
|
+
import { readExplicitFileOrStdin } from '../../utils/file-input';
|
|
16
|
+
import { assertAllowedProject, getSafetyMode, wrapAction } from '../../utils/safety';
|
|
17
|
+
|
|
18
|
+
import { fetchBundleCurrentState } from './state';
|
|
19
|
+
|
|
20
|
+
import type { Command } from 'commander';
|
|
21
|
+
|
|
22
|
+
export function registerAgentopsApplyCommand(agentopsCmd: Command): void {
|
|
23
|
+
agentopsCmd
|
|
24
|
+
.command('apply')
|
|
25
|
+
.description('Apply an agent bundle to Lightdash')
|
|
26
|
+
.option('--file <path>', 'Path to bundle YAML file')
|
|
27
|
+
.option('--stdin', 'Read bundle YAML from stdin')
|
|
28
|
+
.action(
|
|
29
|
+
wrapAction(WRITE_NONDESTRUCTIVE, async function (this: Command) {
|
|
30
|
+
const options = this.opts() as { file?: string; stdin?: boolean };
|
|
31
|
+
try {
|
|
32
|
+
const content = await readExplicitFileOrStdin({
|
|
33
|
+
file: options.file,
|
|
34
|
+
stdin: options.stdin,
|
|
35
|
+
});
|
|
36
|
+
const bundle = parseLightdashAiAgentBundle(content);
|
|
37
|
+
assertAllowedProject(this, bundle.spec.projectUuid);
|
|
38
|
+
const client = getClient();
|
|
39
|
+
const current = await fetchBundleCurrentState(client, bundle);
|
|
40
|
+
const diff = computeBundleDiff(bundle, current);
|
|
41
|
+
|
|
42
|
+
if (diff.summary.deletes > 0 && !isAllowed(getSafetyMode(this), WRITE_DESTRUCTIVE)) {
|
|
43
|
+
console.error(
|
|
44
|
+
'Error: bundle requires destructive operations (deletes). Use --safety-mode write-destructive.',
|
|
45
|
+
);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const result = await applyBundleDiff(client, bundle, diff.changes);
|
|
50
|
+
console.log(
|
|
51
|
+
JSON.stringify(
|
|
52
|
+
{
|
|
53
|
+
bundleName: bundle.metadata.name,
|
|
54
|
+
projectUuid: bundle.spec.projectUuid,
|
|
55
|
+
summary: diff.summary,
|
|
56
|
+
applied: result.applied,
|
|
57
|
+
skipped: result.skipped,
|
|
58
|
+
failed: result.failed,
|
|
59
|
+
},
|
|
60
|
+
null,
|
|
61
|
+
2,
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (result.failed.length > 0) {
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(
|
|
70
|
+
'Error applying bundle:',
|
|
71
|
+
error instanceof Error ? error.message : String(error),
|
|
72
|
+
);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops bundle-schema — emit JSON Schema for LightdashAiAgentBundle.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { READ_ONLY_DEFAULT, getLightdashAiAgentBundleJsonSchema } from '@lightdash-tools/common';
|
|
6
|
+
|
|
7
|
+
import { wrapAction } from '../../utils/safety';
|
|
8
|
+
|
|
9
|
+
import type { Command } from 'commander';
|
|
10
|
+
|
|
11
|
+
export function registerAgentopsBundleSchemaCommand(agentopsCmd: Command): void {
|
|
12
|
+
agentopsCmd
|
|
13
|
+
.command('bundle-schema')
|
|
14
|
+
.description('Print JSON Schema for LightdashAiAgentBundle documents')
|
|
15
|
+
.action(
|
|
16
|
+
wrapAction(READ_ONLY_DEFAULT, () => {
|
|
17
|
+
console.log(JSON.stringify(getLightdashAiAgentBundleJsonSchema(), null, 2));
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops drift — detect configuration drift vs desired bundle state.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
READ_ONLY_DEFAULT,
|
|
7
|
+
detectBundleDrift,
|
|
8
|
+
parseLightdashAiAgentBundle,
|
|
9
|
+
} from '@lightdash-tools/common';
|
|
10
|
+
|
|
11
|
+
import { getClient } from '../../utils/client';
|
|
12
|
+
import { readExplicitFileOrStdin } from '../../utils/file-input';
|
|
13
|
+
import { assertAllowedProject, wrapAction } from '../../utils/safety';
|
|
14
|
+
|
|
15
|
+
import { fetchBundleCurrentState } from './state';
|
|
16
|
+
|
|
17
|
+
import type { Command } from 'commander';
|
|
18
|
+
|
|
19
|
+
export function registerAgentopsDriftCommand(agentopsCmd: Command): void {
|
|
20
|
+
agentopsCmd
|
|
21
|
+
.command('drift')
|
|
22
|
+
.description('Detect drift between bundle desired state and Lightdash')
|
|
23
|
+
.option('--file <path>', 'Path to bundle YAML file')
|
|
24
|
+
.option('--stdin', 'Read bundle YAML from stdin')
|
|
25
|
+
.action(
|
|
26
|
+
wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
|
|
27
|
+
const options = this.opts() as { file?: string; stdin?: boolean };
|
|
28
|
+
try {
|
|
29
|
+
const content = await readExplicitFileOrStdin({
|
|
30
|
+
file: options.file,
|
|
31
|
+
stdin: options.stdin,
|
|
32
|
+
});
|
|
33
|
+
const bundle = parseLightdashAiAgentBundle(content);
|
|
34
|
+
assertAllowedProject(this, bundle.spec.projectUuid);
|
|
35
|
+
const client = getClient();
|
|
36
|
+
const current = await fetchBundleCurrentState(client, bundle);
|
|
37
|
+
const { hasDrift, diff } = detectBundleDrift(bundle, current);
|
|
38
|
+
console.log(
|
|
39
|
+
JSON.stringify(
|
|
40
|
+
{
|
|
41
|
+
bundleName: bundle.metadata.name,
|
|
42
|
+
projectUuid: bundle.spec.projectUuid,
|
|
43
|
+
hasDrift,
|
|
44
|
+
summary: diff.summary,
|
|
45
|
+
changes: diff.changes.filter((c) => c.operation !== 'noop'),
|
|
46
|
+
},
|
|
47
|
+
null,
|
|
48
|
+
2,
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
if (hasDrift) {
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(
|
|
56
|
+
'Error detecting drift:',
|
|
57
|
+
error instanceof Error ? error.message : String(error),
|
|
58
|
+
);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops evaluate-gate — evaluate an evaluation gate policy against a run.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { resolveEvaluationRun } from '@lightdash-tools/client';
|
|
6
|
+
import {
|
|
7
|
+
GateExitCode,
|
|
8
|
+
WRITE_OPEN_WORLD,
|
|
9
|
+
evaluateGatePolicy,
|
|
10
|
+
formatGateJUnit,
|
|
11
|
+
formatGateMarkdown,
|
|
12
|
+
formatGateTimeoutJUnit,
|
|
13
|
+
formatGateTimeoutMarkdown,
|
|
14
|
+
parseLightdashAiEvaluationGate,
|
|
15
|
+
} from '@lightdash-tools/common';
|
|
16
|
+
|
|
17
|
+
import { getClient } from '../../utils/client';
|
|
18
|
+
import { readExplicitFileOrStdin } from '../../utils/file-input';
|
|
19
|
+
import { assertAllowedProject, wrapAction } from '../../utils/safety';
|
|
20
|
+
|
|
21
|
+
import type { Command } from 'commander';
|
|
22
|
+
|
|
23
|
+
function parsePositiveSeconds(value: string, flag: string): number {
|
|
24
|
+
const parsed = Number.parseInt(value, 10);
|
|
25
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
26
|
+
throw new Error(`${flag} must be a positive integer`);
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function registerAgentopsEvaluateGateCommand(agentopsCmd: Command): void {
|
|
32
|
+
agentopsCmd
|
|
33
|
+
.command('evaluate-gate')
|
|
34
|
+
.description('Evaluate an evaluation gate policy against a run')
|
|
35
|
+
.option('--file <path>', 'Path to gate YAML file')
|
|
36
|
+
.option('--stdin', 'Read gate YAML from stdin')
|
|
37
|
+
.option('--wait', 'Wait for the evaluation run to complete', false)
|
|
38
|
+
.option(
|
|
39
|
+
'--timeout <seconds>',
|
|
40
|
+
'Wait timeout in seconds',
|
|
41
|
+
(v: string) => parsePositiveSeconds(v, '--timeout'),
|
|
42
|
+
600,
|
|
43
|
+
)
|
|
44
|
+
.option(
|
|
45
|
+
'--poll-interval <seconds>',
|
|
46
|
+
'Poll interval in seconds',
|
|
47
|
+
(v: string) => parsePositiveSeconds(v, '--poll-interval'),
|
|
48
|
+
10,
|
|
49
|
+
)
|
|
50
|
+
.option('--output <format>', 'Output format: json, junit, markdown', 'json')
|
|
51
|
+
.action(
|
|
52
|
+
wrapAction(WRITE_OPEN_WORLD, async function (this: Command) {
|
|
53
|
+
const options = this.opts() as {
|
|
54
|
+
file?: string;
|
|
55
|
+
stdin?: boolean;
|
|
56
|
+
wait?: boolean;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
pollInterval?: number;
|
|
59
|
+
output?: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const output = options.output ?? 'json';
|
|
63
|
+
if (!['json', 'junit', 'markdown'].includes(output)) {
|
|
64
|
+
console.error(`Error: unsupported --output '${output}'. Use json, junit, or markdown.`);
|
|
65
|
+
process.exit(GateExitCode.INVALID);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const content = await readExplicitFileOrStdin({
|
|
70
|
+
file: options.file,
|
|
71
|
+
stdin: options.stdin,
|
|
72
|
+
});
|
|
73
|
+
const gate = parseLightdashAiEvaluationGate(content);
|
|
74
|
+
assertAllowedProject(this, gate.spec.projectUuid);
|
|
75
|
+
const timeoutSeconds = options.timeout ?? 600;
|
|
76
|
+
const pollIntervalSeconds = options.pollInterval ?? 10;
|
|
77
|
+
const client = getClient();
|
|
78
|
+
const { run, timedOut } = await resolveEvaluationRun(client, gate, {
|
|
79
|
+
wait: options.wait === true,
|
|
80
|
+
timeoutMs: timeoutSeconds * 1000,
|
|
81
|
+
pollIntervalMs: pollIntervalSeconds * 1000,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (timedOut) {
|
|
85
|
+
const payload = {
|
|
86
|
+
gateName: gate.metadata.name,
|
|
87
|
+
exitCode: GateExitCode.TIMEOUT,
|
|
88
|
+
passed: false,
|
|
89
|
+
reasons: ['Timed out waiting for evaluation run to complete'],
|
|
90
|
+
run,
|
|
91
|
+
};
|
|
92
|
+
if (output === 'json') console.log(JSON.stringify(payload, null, 2));
|
|
93
|
+
else if (output === 'markdown') {
|
|
94
|
+
console.log(formatGateTimeoutMarkdown(gate));
|
|
95
|
+
} else {
|
|
96
|
+
console.log(formatGateTimeoutJUnit(gate));
|
|
97
|
+
}
|
|
98
|
+
process.exit(GateExitCode.TIMEOUT);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const evaluation = evaluateGatePolicy(gate.spec.policy, run);
|
|
102
|
+
|
|
103
|
+
const payload = {
|
|
104
|
+
gateName: gate.metadata.name,
|
|
105
|
+
projectUuid: gate.spec.projectUuid,
|
|
106
|
+
agentUuid: gate.spec.agentUuid,
|
|
107
|
+
evaluationUuid: gate.spec.evaluationUuid,
|
|
108
|
+
runUuid: run.runUuid,
|
|
109
|
+
...evaluation,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (output === 'json') {
|
|
113
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
114
|
+
} else if (output === 'junit') {
|
|
115
|
+
console.log(formatGateJUnit(gate, evaluation));
|
|
116
|
+
} else {
|
|
117
|
+
console.log(formatGateMarkdown(gate, evaluation));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
process.exit(evaluation.exitCode);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
console.error('Error evaluating gate:', message);
|
|
124
|
+
process.exit(GateExitCode.ERROR);
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops gate-schema — emit JSON Schema for LightdashAiEvaluationGate.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { READ_ONLY_DEFAULT, getLightdashAiEvaluationGateJsonSchema } from '@lightdash-tools/common';
|
|
6
|
+
|
|
7
|
+
import { wrapAction } from '../../utils/safety';
|
|
8
|
+
|
|
9
|
+
import type { Command } from 'commander';
|
|
10
|
+
|
|
11
|
+
export function registerAgentopsGateSchemaCommand(agentopsCmd: Command): void {
|
|
12
|
+
agentopsCmd
|
|
13
|
+
.command('gate-schema')
|
|
14
|
+
.description('Print JSON Schema for LightdashAiEvaluationGate documents')
|
|
15
|
+
.action(
|
|
16
|
+
wrapAction(READ_ONLY_DEFAULT, () => {
|
|
17
|
+
console.log(JSON.stringify(getLightdashAiEvaluationGateJsonSchema(), null, 2));
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentops plan — validate bundle, fetch current state, compute diff (read-only).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
READ_ONLY_DEFAULT,
|
|
7
|
+
computeBundleDiff,
|
|
8
|
+
parseLightdashAiAgentBundle,
|
|
9
|
+
} from '@lightdash-tools/common';
|
|
10
|
+
|
|
11
|
+
import { getClient } from '../../utils/client';
|
|
12
|
+
import { readExplicitFileOrStdin } from '../../utils/file-input';
|
|
13
|
+
import { assertAllowedProject, wrapAction } from '../../utils/safety';
|
|
14
|
+
|
|
15
|
+
import { fetchBundleCurrentState } from './state';
|
|
16
|
+
|
|
17
|
+
import type { Command } from 'commander';
|
|
18
|
+
|
|
19
|
+
export function registerAgentopsPlanCommand(agentopsCmd: Command): void {
|
|
20
|
+
agentopsCmd
|
|
21
|
+
.command('plan')
|
|
22
|
+
.description('Validate an agent bundle and show the planned diff (read-only)')
|
|
23
|
+
.option('--file <path>', 'Path to bundle YAML file')
|
|
24
|
+
.option('--stdin', 'Read bundle YAML from stdin')
|
|
25
|
+
.option('--output <format>', 'Output format: json', 'json')
|
|
26
|
+
.action(
|
|
27
|
+
wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
|
|
28
|
+
const options = this.opts() as { file?: string; stdin?: boolean; output?: string };
|
|
29
|
+
if (options.output !== 'json') {
|
|
30
|
+
console.error(
|
|
31
|
+
`Error: unsupported --output '${options.output}'. Only 'json' is supported.`,
|
|
32
|
+
);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const content = await readExplicitFileOrStdin({
|
|
37
|
+
file: options.file,
|
|
38
|
+
stdin: options.stdin,
|
|
39
|
+
});
|
|
40
|
+
const bundle = parseLightdashAiAgentBundle(content);
|
|
41
|
+
assertAllowedProject(this, bundle.spec.projectUuid);
|
|
42
|
+
const client = getClient();
|
|
43
|
+
const current = await fetchBundleCurrentState(client, bundle);
|
|
44
|
+
const diff = computeBundleDiff(bundle, current);
|
|
45
|
+
console.log(JSON.stringify(diff, null, 2));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(
|
|
48
|
+
'Error planning bundle:',
|
|
49
|
+
error instanceof Error ? error.message : String(error),
|
|
50
|
+
);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
}
|