@lightdash-tools/cli 0.6.0 → 0.8.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.
Files changed (110) hide show
  1. package/README.md +8 -4
  2. package/dist/commands/agentops/apply.d.ts +5 -0
  3. package/dist/commands/agentops/apply.js +53 -0
  4. package/dist/commands/agentops/bundle-schema.d.ts +5 -0
  5. package/dist/commands/agentops/bundle-schema.js +16 -0
  6. package/dist/commands/agentops/drift.d.ts +5 -0
  7. package/dist/commands/agentops/drift.js +46 -0
  8. package/dist/commands/agentops/evaluate-gate.d.ts +5 -0
  9. package/dist/commands/agentops/evaluate-gate.js +89 -0
  10. package/dist/commands/agentops/gate-schema.d.ts +5 -0
  11. package/dist/commands/agentops/gate-schema.js +16 -0
  12. package/dist/commands/agentops/plan.d.ts +5 -0
  13. package/dist/commands/agentops/plan.js +42 -0
  14. package/dist/commands/agentops/state.d.ts +4 -0
  15. package/dist/commands/agentops/state.js +8 -0
  16. package/dist/commands/agentops.d.ts +8 -0
  17. package/dist/commands/agentops.js +26 -0
  18. package/dist/commands/agentops.test.d.ts +1 -0
  19. package/dist/commands/agentops.test.js +400 -0
  20. package/dist/commands/agents-crud.d.ts +8 -0
  21. package/dist/commands/agents-crud.js +144 -0
  22. package/dist/commands/agents-discovery.d.ts +8 -0
  23. package/dist/commands/agents-discovery.js +139 -0
  24. package/dist/commands/agents-discovery.test.d.ts +1 -0
  25. package/dist/commands/agents-discovery.test.js +13 -0
  26. package/dist/commands/agents-evals.d.ts +8 -0
  27. package/dist/commands/agents-evals.js +246 -0
  28. package/dist/commands/agents-threads.d.ts +8 -0
  29. package/dist/commands/agents-threads.js +83 -0
  30. package/dist/commands/agents.js +8 -360
  31. package/dist/commands/ai-agents.js +52 -70
  32. package/dist/commands/charts.js +35 -46
  33. package/dist/commands/content.js +3 -12
  34. package/dist/commands/dashboards.js +3 -12
  35. package/dist/commands/explores.js +12 -21
  36. package/dist/commands/groups.js +44 -63
  37. package/dist/commands/metrics.js +6 -15
  38. package/dist/commands/organization-roles.js +28 -39
  39. package/dist/commands/organization.js +3 -12
  40. package/dist/commands/project-access.js +9 -18
  41. package/dist/commands/project-role-assignments.js +15 -24
  42. package/dist/commands/projects.js +33 -26
  43. package/dist/commands/query.js +30 -41
  44. package/dist/commands/schedulers.js +6 -15
  45. package/dist/commands/schema.d.ts +1 -2
  46. package/dist/commands/schema.js +24 -97
  47. package/dist/commands/schema.test.js +80 -15
  48. package/dist/commands/space-access.js +12 -21
  49. package/dist/commands/spaces.js +6 -15
  50. package/dist/commands/tags.js +6 -15
  51. package/dist/commands/users.js +23 -41
  52. package/dist/index.js +18 -16
  53. package/dist/index.test.js +9 -9
  54. package/dist/utils/cli-params.d.ts +4 -0
  55. package/dist/utils/cli-params.js +15 -0
  56. package/dist/utils/cli-params.test.d.ts +1 -0
  57. package/dist/utils/cli-params.test.js +12 -0
  58. package/dist/utils/file-input.d.ts +30 -0
  59. package/dist/utils/file-input.js +77 -0
  60. package/dist/utils/file-input.test.d.ts +1 -0
  61. package/dist/utils/file-input.test.js +68 -0
  62. package/dist/utils/safety.d.ts +5 -0
  63. package/dist/utils/safety.js +97 -109
  64. package/dist/utils/safety.test.js +135 -33
  65. package/package.json +14 -5
  66. package/src/commands/agentops/apply.ts +77 -0
  67. package/src/commands/agentops/bundle-schema.ts +20 -0
  68. package/src/commands/agentops/drift.ts +63 -0
  69. package/src/commands/agentops/evaluate-gate.ts +128 -0
  70. package/src/commands/agentops/gate-schema.ts +20 -0
  71. package/src/commands/agentops/plan.ts +55 -0
  72. package/src/commands/agentops/state.ts +5 -0
  73. package/src/commands/agentops.test.ts +454 -0
  74. package/src/commands/agentops.ts +28 -0
  75. package/src/commands/agents-crud.ts +193 -0
  76. package/src/commands/agents-discovery.test.ts +16 -0
  77. package/src/commands/agents-discovery.ts +180 -0
  78. package/src/commands/agents-evals.ts +353 -0
  79. package/src/commands/agents-threads.ts +116 -0
  80. package/src/commands/agents.ts +9 -493
  81. package/src/commands/ai-agents.ts +37 -28
  82. package/src/commands/charts.ts +6 -3
  83. package/src/commands/content.ts +3 -1
  84. package/src/commands/dashboards.ts +3 -1
  85. package/src/commands/explores.ts +3 -1
  86. package/src/commands/groups.ts +33 -33
  87. package/src/commands/metrics.ts +3 -1
  88. package/src/commands/organization-roles.ts +3 -1
  89. package/src/commands/organization.ts +3 -1
  90. package/src/commands/project-access.ts +3 -1
  91. package/src/commands/project-role-assignments.ts +3 -1
  92. package/src/commands/projects.ts +44 -18
  93. package/src/commands/query.ts +4 -1
  94. package/src/commands/schedulers.ts +3 -1
  95. package/src/commands/schema.test.ts +95 -16
  96. package/src/commands/schema.ts +42 -99
  97. package/src/commands/space-access.ts +3 -1
  98. package/src/commands/spaces.ts +3 -1
  99. package/src/commands/tags.ts +3 -1
  100. package/src/commands/users.ts +29 -25
  101. package/src/index.test.ts +10 -9
  102. package/src/index.ts +19 -16
  103. package/src/utils/cli-params.test.ts +13 -0
  104. package/src/utils/cli-params.ts +12 -0
  105. package/src/utils/client.test.ts +1 -0
  106. package/src/utils/file-input.test.ts +91 -0
  107. package/src/utils/file-input.ts +83 -0
  108. package/src/utils/safety.test.ts +158 -2
  109. package/src/utils/safety.ts +27 -20
  110. package/tsconfig.json +2 -1
@@ -0,0 +1,454 @@
1
+ import {
2
+ GateExitCode,
3
+ computeBundleDiff,
4
+ evaluateGatePolicy,
5
+ parseLightdashAiAgentBundle,
6
+ parseLightdashAiEvaluationGate,
7
+ } from '@lightdash-tools/common';
8
+ import { describe, expect, it } from 'vitest';
9
+
10
+ const PROJECT_UUID = '00000000-0000-4000-8000-000000000001';
11
+ const AGENT_UUID = '00000000-0000-4000-8000-000000000010';
12
+ const EVAL_UUID = '00000000-0000-4000-8000-000000000020';
13
+
14
+ const validBundleYaml = `
15
+ apiVersion: lightdash.ai/v1alpha1
16
+ kind: LightdashAiAgentBundle
17
+ metadata:
18
+ name: sales-bundle
19
+ spec:
20
+ projectUuid: ${PROJECT_UUID}
21
+ agents:
22
+ - key: sales
23
+ uuid: ${AGENT_UUID}
24
+ name: Sales Agent
25
+ instruction: Help with sales
26
+ evaluations:
27
+ - key: smoke
28
+ uuid: ${EVAL_UUID}
29
+ title: Smoke Tests
30
+ prompts:
31
+ - prompt: What are total sales?
32
+ expectedResponse: null
33
+ `;
34
+
35
+ const validGateYaml = `
36
+ apiVersion: lightdash.ai/v1alpha1
37
+ kind: LightdashAiEvaluationGate
38
+ metadata:
39
+ name: release-gate
40
+ spec:
41
+ projectUuid: ${PROJECT_UUID}
42
+ agentUuid: ${AGENT_UUID}
43
+ evaluationUuid: ${EVAL_UUID}
44
+ policy:
45
+ minPassRate: 0.9
46
+ maxFailedAssessments: 0
47
+ triggerRun: true
48
+ `;
49
+
50
+ describe('AgentOps schema validation', () => {
51
+ it('parses a valid LightdashAiAgentBundle', () => {
52
+ const bundle = parseLightdashAiAgentBundle(validBundleYaml);
53
+ expect(bundle.kind).toBe('LightdashAiAgentBundle');
54
+ expect(bundle.metadata.name).toBe('sales-bundle');
55
+ expect(bundle.spec.agents).toHaveLength(1);
56
+ expect(bundle.spec.agents[0]?.key).toBe('sales');
57
+ });
58
+
59
+ it('rejects bundle with wrong apiVersion', () => {
60
+ const yaml = validBundleYaml.replace('lightdash.ai/v1alpha1', 'v1');
61
+ expect(() => parseLightdashAiAgentBundle(yaml)).toThrow(/Invalid LightdashAiAgentBundle/);
62
+ });
63
+
64
+ it('rejects bundle without agents', () => {
65
+ const yaml = validBundleYaml.replace(/agents:[\s\S]*/, 'agents: []\n');
66
+ expect(() => parseLightdashAiAgentBundle(yaml)).toThrow(/Invalid LightdashAiAgentBundle/);
67
+ });
68
+
69
+ it('parses a valid LightdashAiEvaluationGate', () => {
70
+ const gate = parseLightdashAiEvaluationGate(validGateYaml);
71
+ expect(gate.kind).toBe('LightdashAiEvaluationGate');
72
+ expect(gate.spec.policy.minPassRate).toBe(0.9);
73
+ expect(gate.spec.triggerRun).toBe(true);
74
+ });
75
+
76
+ it('rejects gate with invalid project UUID', () => {
77
+ const yaml = validGateYaml.replace(PROJECT_UUID, 'not-a-uuid');
78
+ expect(() => parseLightdashAiEvaluationGate(yaml)).toThrow(/Invalid LightdashAiEvaluationGate/);
79
+ });
80
+ });
81
+
82
+ describe('AgentOps bundle diff', () => {
83
+ const bundle = parseLightdashAiAgentBundle(validBundleYaml);
84
+
85
+ it('reports noop when current state matches desired state', () => {
86
+ const current = {
87
+ projectUuid: PROJECT_UUID,
88
+ agents: [
89
+ {
90
+ agent: {
91
+ uuid: AGENT_UUID,
92
+ name: 'Sales Agent',
93
+ description: null,
94
+ instruction: 'Help with sales',
95
+ tags: null,
96
+ },
97
+ evaluations: [
98
+ {
99
+ evalUuid: EVAL_UUID,
100
+ title: 'Smoke Tests',
101
+ description: null,
102
+ prompts: [
103
+ {
104
+ type: 'string' as const,
105
+ prompt: 'What are total sales?',
106
+ expectedResponse: null,
107
+ },
108
+ ],
109
+ },
110
+ ],
111
+ },
112
+ ],
113
+ };
114
+
115
+ const diff = computeBundleDiff(bundle, current);
116
+ expect(diff.hasDrift).toBe(false);
117
+ expect(diff.summary.creates).toBe(0);
118
+ expect(diff.summary.updates).toBe(0);
119
+ expect(diff.summary.deletes).toBe(0);
120
+ expect(diff.summary.noops).toBe(2);
121
+ });
122
+
123
+ it('reports create when agent is missing', () => {
124
+ const diff = computeBundleDiff(bundle, { projectUuid: PROJECT_UUID, agents: [] });
125
+ expect(diff.hasDrift).toBe(true);
126
+ expect(diff.summary.creates).toBe(2);
127
+ expect(diff.changes.some((c) => c.resourceType === 'agent' && c.operation === 'create')).toBe(
128
+ true,
129
+ );
130
+ });
131
+
132
+ it('reports update when agent instruction drifts', () => {
133
+ const current = {
134
+ projectUuid: PROJECT_UUID,
135
+ agents: [
136
+ {
137
+ agent: {
138
+ uuid: AGENT_UUID,
139
+ name: 'Sales Agent',
140
+ description: null,
141
+ instruction: 'Old instruction',
142
+ tags: null,
143
+ },
144
+ evaluations: [
145
+ {
146
+ evalUuid: EVAL_UUID,
147
+ title: 'Smoke Tests',
148
+ description: null,
149
+ prompts: [
150
+ {
151
+ type: 'string' as const,
152
+ prompt: 'What are total sales?',
153
+ expectedResponse: null,
154
+ },
155
+ ],
156
+ },
157
+ ],
158
+ },
159
+ ],
160
+ };
161
+
162
+ const diff = computeBundleDiff(bundle, current);
163
+ expect(diff.summary.updates).toBe(1);
164
+ expect(diff.changes.find((c) => c.resourceType === 'agent')?.fields?.instruction).toEqual({
165
+ from: 'Old instruction',
166
+ to: 'Help with sales',
167
+ });
168
+ });
169
+
170
+ it('reports noop when bundle omits enableReasoning and API agent has undefined', () => {
171
+ const bundleWithoutReasoning = parseLightdashAiAgentBundle(`
172
+ apiVersion: lightdash.ai/v1alpha1
173
+ kind: LightdashAiAgentBundle
174
+ metadata:
175
+ name: sales-bundle
176
+ spec:
177
+ projectUuid: ${PROJECT_UUID}
178
+ agents:
179
+ - key: sales
180
+ uuid: ${AGENT_UUID}
181
+ name: Sales Agent
182
+ instruction: Help with sales
183
+ evaluations: []
184
+ `);
185
+
186
+ const current = {
187
+ projectUuid: PROJECT_UUID,
188
+ agents: [
189
+ {
190
+ agent: {
191
+ uuid: AGENT_UUID,
192
+ name: 'Sales Agent',
193
+ description: null,
194
+ instruction: 'Help with sales',
195
+ tags: null,
196
+ enableDataAccess: false,
197
+ enableSelfImprovement: false,
198
+ },
199
+ evaluations: [],
200
+ },
201
+ ],
202
+ };
203
+
204
+ const diff = computeBundleDiff(bundleWithoutReasoning, current);
205
+ expect(diff.hasDrift).toBe(false);
206
+ expect(diff.summary.updates).toBe(0);
207
+ expect(diff.summary.noops).toBe(1);
208
+ });
209
+
210
+ it('reports noop when bundle tags are empty array and API has null tags', () => {
211
+ const bundleWithEmptyTags = parseLightdashAiAgentBundle(`
212
+ apiVersion: lightdash.ai/v1alpha1
213
+ kind: LightdashAiAgentBundle
214
+ metadata:
215
+ name: sales-bundle
216
+ spec:
217
+ projectUuid: ${PROJECT_UUID}
218
+ agents:
219
+ - key: sales
220
+ uuid: ${AGENT_UUID}
221
+ name: Sales Agent
222
+ instruction: Help with sales
223
+ tags: []
224
+ evaluations: []
225
+ `);
226
+
227
+ const current = {
228
+ projectUuid: PROJECT_UUID,
229
+ agents: [
230
+ {
231
+ agent: {
232
+ uuid: AGENT_UUID,
233
+ name: 'Sales Agent',
234
+ description: null,
235
+ instruction: 'Help with sales',
236
+ tags: null,
237
+ },
238
+ evaluations: [],
239
+ },
240
+ ],
241
+ };
242
+
243
+ const diff = computeBundleDiff(bundleWithEmptyTags, current);
244
+ expect(diff.hasDrift).toBe(false);
245
+ expect(diff.summary.updates).toBe(0);
246
+ expect(diff.summary.noops).toBe(1);
247
+ });
248
+
249
+ it('reports noop when API has false booleans and bundle omits them', () => {
250
+ const bundleWithoutBooleans = parseLightdashAiAgentBundle(`
251
+ apiVersion: lightdash.ai/v1alpha1
252
+ kind: LightdashAiAgentBundle
253
+ metadata:
254
+ name: sales-bundle
255
+ spec:
256
+ projectUuid: ${PROJECT_UUID}
257
+ agents:
258
+ - key: sales
259
+ uuid: ${AGENT_UUID}
260
+ name: Sales Agent
261
+ instruction: Help with sales
262
+ evaluations: []
263
+ `);
264
+
265
+ const current = {
266
+ projectUuid: PROJECT_UUID,
267
+ agents: [
268
+ {
269
+ agent: {
270
+ uuid: AGENT_UUID,
271
+ name: 'Sales Agent',
272
+ description: null,
273
+ instruction: 'Help with sales',
274
+ tags: null,
275
+ enableDataAccess: false,
276
+ enableSelfImprovement: false,
277
+ },
278
+ evaluations: [],
279
+ },
280
+ ],
281
+ };
282
+
283
+ const diff = computeBundleDiff(bundleWithoutBooleans, current);
284
+ expect(diff.hasDrift).toBe(false);
285
+ expect(diff.summary.updates).toBe(0);
286
+ expect(diff.summary.noops).toBe(1);
287
+ });
288
+
289
+ it('includes agentUuid on name-matched agent update changes', () => {
290
+ const nameMatchedBundle = parseLightdashAiAgentBundle(`
291
+ apiVersion: lightdash.ai/v1alpha1
292
+ kind: LightdashAiAgentBundle
293
+ metadata:
294
+ name: sales-bundle
295
+ spec:
296
+ projectUuid: ${PROJECT_UUID}
297
+ agents:
298
+ - key: sales
299
+ name: Sales Agent
300
+ instruction: Updated instruction
301
+ evaluations: []
302
+ `);
303
+
304
+ const current = {
305
+ projectUuid: PROJECT_UUID,
306
+ agents: [
307
+ {
308
+ agent: {
309
+ uuid: AGENT_UUID,
310
+ name: 'Sales Agent',
311
+ description: null,
312
+ instruction: 'Help with sales',
313
+ tags: null,
314
+ },
315
+ evaluations: [],
316
+ },
317
+ ],
318
+ };
319
+
320
+ const diff = computeBundleDiff(nameMatchedBundle, current);
321
+ const agentUpdate = diff.changes.find(
322
+ (c) => c.resourceType === 'agent' && c.operation === 'update',
323
+ );
324
+ expect(agentUpdate?.agentUuid).toBe(AGENT_UUID);
325
+ });
326
+
327
+ it('reports delete for agents not in bundle', () => {
328
+ const orphanUuid = '00000000-0000-4000-8000-000000000099';
329
+ const current = {
330
+ projectUuid: PROJECT_UUID,
331
+ agents: [
332
+ {
333
+ agent: {
334
+ uuid: AGENT_UUID,
335
+ name: 'Sales Agent',
336
+ description: null,
337
+ instruction: 'Help with sales',
338
+ tags: null,
339
+ },
340
+ evaluations: [
341
+ {
342
+ evalUuid: EVAL_UUID,
343
+ title: 'Smoke Tests',
344
+ description: null,
345
+ prompts: [
346
+ {
347
+ type: 'string' as const,
348
+ prompt: 'What are total sales?',
349
+ expectedResponse: null,
350
+ },
351
+ ],
352
+ },
353
+ ],
354
+ },
355
+ {
356
+ agent: {
357
+ uuid: orphanUuid,
358
+ name: 'Orphan Agent',
359
+ description: null,
360
+ instruction: null,
361
+ tags: null,
362
+ },
363
+ evaluations: [],
364
+ },
365
+ ],
366
+ };
367
+
368
+ const diff = computeBundleDiff(bundle, current);
369
+ expect(diff.changes.some((c) => c.operation === 'delete' && c.key === orphanUuid)).toBe(true);
370
+ });
371
+ });
372
+
373
+ describe('AgentOps evaluate-gate CLI options', () => {
374
+ it('rejects non-numeric timeout values', () => {
375
+ const parse = (value: string) => {
376
+ const parsed = Number.parseInt(value, 10);
377
+ if (!Number.isFinite(parsed) || parsed <= 0) {
378
+ throw new Error('--timeout must be a positive integer');
379
+ }
380
+ return parsed;
381
+ };
382
+
383
+ expect(() => parse('abc')).toThrow('--timeout must be a positive integer');
384
+ expect(() => parse('0')).toThrow('--timeout must be a positive integer');
385
+ expect(parse('30')).toBe(30);
386
+ });
387
+ });
388
+
389
+ describe('AgentOps gate policy evaluation', () => {
390
+ const baseRun = {
391
+ runUuid: '00000000-0000-4000-8000-000000000030',
392
+ status: 'completed' as const,
393
+ passedAssessments: 9,
394
+ failedAssessments: 1,
395
+ completedAt: '2026-01-01T00:00:00.000Z',
396
+ };
397
+
398
+ it('passes when policy thresholds are met', () => {
399
+ const result = evaluateGatePolicy({ minPassRate: 0.8, maxFailedAssessments: 2 }, baseRun);
400
+ expect(result.passed).toBe(true);
401
+ expect(result.exitCode).toBe(GateExitCode.PASSED);
402
+ expect(result.metrics.passRate).toBe(0.9);
403
+ });
404
+
405
+ it('fails with POLICY_FAILED when minPassRate is not met', () => {
406
+ const result = evaluateGatePolicy({ minPassRate: 0.95 }, baseRun);
407
+ expect(result.passed).toBe(false);
408
+ expect(result.exitCode).toBe(GateExitCode.POLICY_FAILED);
409
+ expect(result.reasons[0]).toMatch(/minPassRate/);
410
+ });
411
+
412
+ it('returns RUN_FAILED for failed runs', () => {
413
+ const result = evaluateGatePolicy(
414
+ { minPassRate: 0.5 },
415
+ { ...baseRun, status: 'failed', passedAssessments: 0, failedAssessments: 0 },
416
+ );
417
+ expect(result.exitCode).toBe(GateExitCode.RUN_FAILED);
418
+ });
419
+
420
+ it('returns RUN_IN_PROGRESS for pending runs', () => {
421
+ const result = evaluateGatePolicy(
422
+ { minPassRate: 0.5 },
423
+ { ...baseRun, status: 'running', completedAt: null },
424
+ );
425
+ expect(result.exitCode).toBe(GateExitCode.RUN_IN_PROGRESS);
426
+ });
427
+
428
+ it('enforces requireAllPassed', () => {
429
+ const result = evaluateGatePolicy({ requireAllPassed: true }, baseRun);
430
+ expect(result.passed).toBe(false);
431
+ expect(result.exitCode).toBe(GateExitCode.POLICY_FAILED);
432
+ });
433
+
434
+ it('fails when maxFailedAssessments exceeded', () => {
435
+ const result = evaluateGatePolicy({ maxFailedAssessments: 0 }, baseRun);
436
+ expect(result.passed).toBe(false);
437
+ expect(result.reasons[0]).toMatch(/maxFailedAssessments/);
438
+ });
439
+
440
+ it('fails when minPassedAssessments not met', () => {
441
+ const result = evaluateGatePolicy({ minPassedAssessments: 10 }, baseRun);
442
+ expect(result.passed).toBe(false);
443
+ expect(result.reasons[0]).toMatch(/minPassedAssessments/);
444
+ });
445
+
446
+ it('fails minPassRate when no assessments exist', () => {
447
+ const result = evaluateGatePolicy(
448
+ { minPassRate: 0.5 },
449
+ { ...baseRun, passedAssessments: 0, failedAssessments: 0 },
450
+ );
451
+ expect(result.passed).toBe(false);
452
+ expect(result.reasons[0]).toMatch(/at least one assessment/);
453
+ });
454
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * AgentOps CLI command group (RFC Phase 2).
3
+ */
4
+
5
+ import { type Command } from 'commander';
6
+
7
+ import { registerAgentopsApplyCommand } from './agentops/apply';
8
+ import { registerAgentopsBundleSchemaCommand } from './agentops/bundle-schema';
9
+ import { registerAgentopsDriftCommand } from './agentops/drift';
10
+ import { registerAgentopsEvaluateGateCommand } from './agentops/evaluate-gate';
11
+ import { registerAgentopsGateSchemaCommand } from './agentops/gate-schema';
12
+ import { registerAgentopsPlanCommand } from './agentops/plan';
13
+
14
+ /**
15
+ * Registers the top-level agentops command and subcommands.
16
+ */
17
+ export function registerAgentopsCommand(program: Command): void {
18
+ const agentopsCmd = program
19
+ .command('agentops')
20
+ .description('AgentOps workflows — bundle plan/apply/drift and evaluation gates');
21
+
22
+ registerAgentopsPlanCommand(agentopsCmd);
23
+ registerAgentopsApplyCommand(agentopsCmd);
24
+ registerAgentopsDriftCommand(agentopsCmd);
25
+ registerAgentopsEvaluateGateCommand(agentopsCmd);
26
+ registerAgentopsBundleSchemaCommand(agentopsCmd);
27
+ registerAgentopsGateSchemaCommand(agentopsCmd);
28
+ }
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Agent CRUD commands (list, get, create, update, delete).
3
+ */
4
+
5
+ import { READ_ONLY_DEFAULT, WRITE_DESTRUCTIVE, WRITE_IDEMPOTENT } from '@lightdash-tools/common';
6
+
7
+ import { getClient } from '../utils/client';
8
+ import { hasExplicitFileInput, readParsedInput } from '../utils/file-input';
9
+ import { wrapAction } from '../utils/safety';
10
+
11
+ import type { Command } from 'commander';
12
+
13
+ /**
14
+ * Registers agent CRUD subcommands on the `agents` command group.
15
+ */
16
+ export function registerAgentsCrudCommands(agentsCmd: Command): void {
17
+ agentsCmd
18
+ .command('list')
19
+ .description('List all agents in a project')
20
+ .requiredOption('--project <uuid>', 'Project UUID')
21
+ .action(
22
+ wrapAction(READ_ONLY_DEFAULT, async function (this: Command) {
23
+ const { project } = this.opts() as { project: string };
24
+ try {
25
+ const client = getClient();
26
+ const result = await client.v1.aiAgents.listAgents(project);
27
+ console.log(JSON.stringify(result, null, 2));
28
+ } catch (error) {
29
+ console.error(
30
+ 'Error listing agents:',
31
+ error instanceof Error ? error.message : String(error),
32
+ );
33
+ process.exit(1);
34
+ }
35
+ }),
36
+ );
37
+
38
+ agentsCmd
39
+ .command('get <agentUuid>')
40
+ .description('Get a single agent by UUID')
41
+ .requiredOption('--project <uuid>', 'Project UUID')
42
+ .action(
43
+ wrapAction(READ_ONLY_DEFAULT, async (agentUuid: string, cmd: Command) => {
44
+ const { project } = cmd.opts() as { project: string };
45
+ try {
46
+ const client = getClient();
47
+ const result = await client.v1.aiAgents.getAgent(project, agentUuid);
48
+ console.log(JSON.stringify(result, null, 2));
49
+ } catch (error) {
50
+ console.error(
51
+ 'Error fetching agent:',
52
+ error instanceof Error ? error.message : String(error),
53
+ );
54
+ process.exit(1);
55
+ }
56
+ }),
57
+ );
58
+
59
+ agentsCmd
60
+ .command('create')
61
+ .description('Create a new agent in a project')
62
+ .requiredOption('--project <uuid>', 'Project UUID')
63
+ .option('--name <name>', 'Agent name')
64
+ .option('--description <text>', 'Agent description')
65
+ .option('--instruction <text>', 'System instruction for the agent')
66
+ .option('--file <path>', 'Read agent JSON/YAML from file')
67
+ .option('--stdin', 'Read agent JSON/YAML from stdin')
68
+ .action(
69
+ wrapAction(WRITE_IDEMPOTENT, async function (this: Command) {
70
+ const options = this.opts() as {
71
+ project: string;
72
+ name?: string;
73
+ description?: string;
74
+ instruction?: string;
75
+ file?: string;
76
+ stdin?: boolean;
77
+ };
78
+ try {
79
+ const client = getClient();
80
+ let body: Parameters<typeof client.v1.aiAgents.createAgent>[1];
81
+
82
+ if (hasExplicitFileInput(options)) {
83
+ const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
84
+ if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
85
+ console.error('Error: agent input must be a JSON/YAML object');
86
+ process.exit(1);
87
+ }
88
+ body = {
89
+ ...(parsed as Record<string, unknown>),
90
+ projectUuid: options.project,
91
+ } as Parameters<typeof client.v1.aiAgents.createAgent>[1];
92
+ } else {
93
+ if (options.name == null) {
94
+ console.error('Error: --name is required unless using --file or --stdin');
95
+ process.exit(1);
96
+ }
97
+ body = {
98
+ name: options.name,
99
+ projectUuid: options.project,
100
+ ...(options.description != null ? { description: options.description } : {}),
101
+ ...(options.instruction != null ? { instruction: options.instruction } : {}),
102
+ } as Parameters<typeof client.v1.aiAgents.createAgent>[1];
103
+ }
104
+
105
+ const result = await client.v1.aiAgents.createAgent(options.project, body);
106
+ console.log(JSON.stringify(result, null, 2));
107
+ } catch (error) {
108
+ console.error(
109
+ 'Error creating agent:',
110
+ error instanceof Error ? error.message : String(error),
111
+ );
112
+ process.exit(1);
113
+ }
114
+ }),
115
+ );
116
+
117
+ agentsCmd
118
+ .command('update <agentUuid>')
119
+ .description('Update an existing agent')
120
+ .requiredOption('--project <uuid>', 'Project UUID')
121
+ .option('--name <name>', 'New agent name')
122
+ .option('--description <text>', 'New agent description')
123
+ .option('--instruction <text>', 'New system instruction')
124
+ .option('--file <path>', 'Read agent patch JSON/YAML from file')
125
+ .option('--stdin', 'Read agent patch JSON/YAML from stdin')
126
+ .action(
127
+ wrapAction(WRITE_IDEMPOTENT, async (agentUuid: string, cmd: Command) => {
128
+ const options = cmd.opts() as {
129
+ project: string;
130
+ name?: string;
131
+ description?: string;
132
+ instruction?: string;
133
+ file?: string;
134
+ stdin?: boolean;
135
+ };
136
+ try {
137
+ const client = getClient();
138
+ let body: Parameters<typeof client.v1.aiAgents.updateAgent>[2];
139
+
140
+ if (hasExplicitFileInput(options)) {
141
+ const parsed = await readParsedInput({ file: options.file, stdin: options.stdin });
142
+ if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed)) {
143
+ console.error('Error: agent patch input must be a JSON/YAML object');
144
+ process.exit(1);
145
+ }
146
+ body = parsed as Parameters<typeof client.v1.aiAgents.updateAgent>[2];
147
+ } else {
148
+ const patch: Record<string, unknown> = {};
149
+ if (options.name != null) patch['name'] = options.name;
150
+ if (options.description != null) patch['description'] = options.description;
151
+ if (options.instruction != null) patch['instruction'] = options.instruction;
152
+ if (Object.keys(patch).length === 0) {
153
+ console.error(
154
+ 'Error: at least one of --name, --description, --instruction, --file, --stdin is required',
155
+ );
156
+ process.exit(1);
157
+ }
158
+ body = patch as Parameters<typeof client.v1.aiAgents.updateAgent>[2];
159
+ }
160
+
161
+ const result = await client.v1.aiAgents.updateAgent(options.project, agentUuid, body);
162
+ console.log(JSON.stringify(result, null, 2));
163
+ } catch (error) {
164
+ console.error(
165
+ 'Error updating agent:',
166
+ error instanceof Error ? error.message : String(error),
167
+ );
168
+ process.exit(1);
169
+ }
170
+ }),
171
+ );
172
+
173
+ agentsCmd
174
+ .command('delete <agentUuid>')
175
+ .description('Delete an agent')
176
+ .requiredOption('--project <uuid>', 'Project UUID')
177
+ .action(
178
+ wrapAction(WRITE_DESTRUCTIVE, async (agentUuid: string, cmd: Command) => {
179
+ const { project } = cmd.opts() as { project: string };
180
+ try {
181
+ const client = getClient();
182
+ await client.v1.aiAgents.deleteAgent(project, agentUuid);
183
+ console.error(`Agent ${agentUuid} deleted successfully`);
184
+ } catch (error) {
185
+ console.error(
186
+ 'Error deleting agent:',
187
+ error instanceof Error ? error.message : String(error),
188
+ );
189
+ process.exit(1);
190
+ }
191
+ }),
192
+ );
193
+ }
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { hasExplicitFileInput } from '../utils/file-input';
4
+
5
+ describe('agents preferences set input selection', () => {
6
+ it('prefers --default-agent when file/stdin were not explicitly requested', () => {
7
+ const fileOptions = {};
8
+ const defaultAgent = '22222222-2222-2222-2222-222222222222';
9
+
10
+ expect(hasExplicitFileInput(fileOptions)).toBe(false);
11
+
12
+ const body = defaultAgent != null ? { defaultAgentUuid: defaultAgent } : undefined;
13
+
14
+ expect(body).toEqual({ defaultAgentUuid: defaultAgent });
15
+ });
16
+ });