@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
@@ -1,18 +1,79 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const vitest_1 = require("vitest");
13
- const safety_1 = require("./safety");
14
3
  const common_1 = require("@lightdash-tools/common");
15
4
  const commander_1 = require("commander");
5
+ const vitest_1 = require("vitest");
6
+ const safety_1 = require("./safety");
7
+ const UUID_ALLOWED = '11111111-1111-1111-1111-111111111111';
8
+ const UUID_FORBIDDEN = '22222222-2222-2222-2222-222222222222';
9
+ /** Builds a root + subcommand hierarchy like the real CLI program. */
10
+ function buildCommandHierarchy() {
11
+ const root = new commander_1.Command('lightdash-ai');
12
+ root
13
+ .option('--safety-mode <mode>', 'Safety mode')
14
+ .option('--projects <uuids>', 'Allowed project UUIDs')
15
+ .option('--dry-run', 'Simulate mutating operations');
16
+ const child = new commander_1.Command('charts');
17
+ root.addCommand(child);
18
+ return { root, child };
19
+ }
20
+ (0, vitest_1.describe)('getSafetyMode', () => {
21
+ (0, vitest_1.afterEach)(() => {
22
+ delete process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
23
+ });
24
+ (0, vitest_1.it)('reads safety mode from cmd option via optsWithGlobals', () => {
25
+ const { child } = buildCommandHierarchy();
26
+ child.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
27
+ (0, vitest_1.expect)((0, safety_1.getSafetyMode)(child)).toBe(common_1.SafetyMode.WRITE_DESTRUCTIVE);
28
+ });
29
+ });
30
+ (0, vitest_1.describe)('isDryRun', () => {
31
+ (0, vitest_1.beforeEach)(() => {
32
+ delete process.env.LIGHTDASH_TOOLS_DRY_RUN;
33
+ });
34
+ (0, vitest_1.afterEach)(() => {
35
+ delete process.env.LIGHTDASH_TOOLS_DRY_RUN;
36
+ });
37
+ (0, vitest_1.it)('reads dry-run from root --dry-run flag', () => {
38
+ const { root, child } = buildCommandHierarchy();
39
+ root.setOptionValueWithSource('dryRun', true, 'cli');
40
+ (0, vitest_1.expect)((0, safety_1.isDryRun)(child)).toBe(true);
41
+ });
42
+ });
43
+ (0, vitest_1.describe)('getAllowedProjects', () => {
44
+ (0, vitest_1.it)('reads comma-separated projects from root --projects flag', () => {
45
+ const { root, child } = buildCommandHierarchy();
46
+ root.setOptionValueWithSource('projects', `${UUID_ALLOWED}, ${UUID_FORBIDDEN}`, 'cli');
47
+ (0, vitest_1.expect)((0, safety_1.getAllowedProjects)(child)).toEqual([UUID_ALLOWED, UUID_FORBIDDEN]);
48
+ });
49
+ });
50
+ (0, vitest_1.describe)('assertAllowedProject', () => {
51
+ const consoleErrorSpy = vitest_1.vi.spyOn(console, 'error').mockImplementation(() => { });
52
+ const processExitSpy = vitest_1.vi.spyOn(process, 'exit').mockImplementation(() => {
53
+ throw new Error('exit');
54
+ });
55
+ (0, vitest_1.afterEach)(() => {
56
+ vitest_1.vi.clearAllMocks();
57
+ });
58
+ (0, vitest_1.it)('allows project when no allowlist is configured', () => {
59
+ const { child } = buildCommandHierarchy();
60
+ (0, vitest_1.expect)(() => (0, safety_1.assertAllowedProject)(child, UUID_FORBIDDEN)).not.toThrow();
61
+ (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
62
+ });
63
+ (0, vitest_1.it)('allows project when it is in the allowlist', () => {
64
+ const { root, child } = buildCommandHierarchy();
65
+ root.setOptionValueWithSource('projects', UUID_ALLOWED, 'cli');
66
+ (0, vitest_1.expect)(() => (0, safety_1.assertAllowedProject)(child, UUID_ALLOWED)).not.toThrow();
67
+ (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
68
+ });
69
+ (0, vitest_1.it)('blocks project parsed from bundle when not in allowlist', () => {
70
+ const { root, child } = buildCommandHierarchy();
71
+ root.setOptionValueWithSource('projects', UUID_ALLOWED, 'cli');
72
+ (0, vitest_1.expect)(() => (0, safety_1.assertAllowedProject)(child, UUID_FORBIDDEN)).toThrow('exit');
73
+ (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('not in the list of allowed projects'));
74
+ (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
75
+ });
76
+ });
16
77
  (0, vitest_1.describe)('CLI wrapAction', () => {
17
78
  const mockAction = vitest_1.vi.fn().mockResolvedValue(undefined);
18
79
  const consoleErrorSpy = vitest_1.vi.spyOn(console, 'error').mockImplementation(() => { });
@@ -27,69 +88,110 @@ const commander_1 = require("commander");
27
88
  (0, vitest_1.afterEach)(() => {
28
89
  delete process.env.LIGHTDASH_TOOLS_DRY_RUN;
29
90
  });
30
- (0, vitest_1.it)('should allow read-only action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
91
+ (0, vitest_1.it)('should allow read-only action in read-only mode', async () => {
31
92
  const cmd = new commander_1.Command();
32
93
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
33
94
  const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
34
- yield wrapped.call(cmd, 'arg1');
95
+ await wrapped.call(cmd, 'arg1');
35
96
  (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
36
97
  (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
37
- }));
38
- (0, vitest_1.it)('should block destructive action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
98
+ });
99
+ (0, vitest_1.it)('should block destructive action in read-only mode', async () => {
39
100
  const cmd = new commander_1.Command();
40
101
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
41
102
  const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
42
- yield (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('exit');
103
+ await (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('exit');
43
104
  (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
44
105
  (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('disabled in read-only mode'));
45
106
  (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
46
- }));
47
- (0, vitest_1.it)('should allow destructive action in write-destructive mode', () => __awaiter(void 0, void 0, void 0, function* () {
107
+ });
108
+ (0, vitest_1.it)('should allow destructive action in write-destructive mode', async () => {
48
109
  const cmd = new commander_1.Command();
49
110
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
50
111
  const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
51
- yield wrapped.call(cmd, 'arg1');
112
+ await wrapped.call(cmd, 'arg1');
52
113
  (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
53
114
  (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
54
- }));
55
- (0, vitest_1.it)('should reject invalid projectUuid in options before calling handler', () => __awaiter(void 0, void 0, void 0, function* () {
115
+ });
116
+ (0, vitest_1.it)('should reject invalid projectUuid in options before calling handler', async () => {
56
117
  const cmd = new commander_1.Command();
57
118
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
58
119
  const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
59
- yield (0, vitest_1.expect)(wrapped.call(cmd, 'arg1', { projectUuid: 'uuid?fields=name' })).rejects.toThrow('exit');
120
+ await (0, vitest_1.expect)(wrapped.call(cmd, 'arg1', { projectUuid: 'uuid?fields=name' })).rejects.toThrow('exit');
60
121
  (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
61
122
  (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('Invalid resource ID'));
62
123
  (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
63
- }));
64
- (0, vitest_1.it)('should allow free-form query strings in positionals', () => __awaiter(void 0, void 0, void 0, function* () {
124
+ });
125
+ (0, vitest_1.it)('should allow free-form query strings in positionals', async () => {
65
126
  const cmd = new commander_1.Command();
66
127
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
67
128
  const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
68
- yield wrapped.call(cmd, 'what?');
129
+ await wrapped.call(cmd, 'what?');
69
130
  (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('what?');
70
131
  (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
71
132
  mockAction.mockClear();
72
- yield wrapped.call(cmd, 'growth%');
133
+ await wrapped.call(cmd, 'growth%');
73
134
  (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('growth%');
74
135
  (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
75
- }));
76
- (0, vitest_1.it)('should simulate write command when LIGHTDASH_TOOLS_DRY_RUN=1', () => __awaiter(void 0, void 0, void 0, function* () {
136
+ });
137
+ (0, vitest_1.it)('should simulate write command when LIGHTDASH_TOOLS_DRY_RUN=1', async () => {
77
138
  process.env.LIGHTDASH_TOOLS_DRY_RUN = '1';
78
139
  const cmd = new commander_1.Command();
79
140
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_IDEMPOTENT, 'cli');
80
141
  const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, mockAction);
81
- yield wrapped.call(cmd, 'project-uuid-123');
142
+ await wrapped.call(cmd, 'project-uuid-123');
82
143
  (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
83
144
  (0, vitest_1.expect)(consoleLogSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('[DRY-RUN] Would execute'));
84
145
  (0, vitest_1.expect)(consoleLogSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('No changes were made'));
85
- }));
86
- (0, vitest_1.it)('should execute read command even when LIGHTDASH_TOOLS_DRY_RUN=1', () => __awaiter(void 0, void 0, void 0, function* () {
146
+ });
147
+ (0, vitest_1.it)('should execute read command even when LIGHTDASH_TOOLS_DRY_RUN=1', async () => {
87
148
  process.env.LIGHTDASH_TOOLS_DRY_RUN = '1';
88
149
  const cmd = new commander_1.Command();
89
150
  cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
90
151
  const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
91
- yield wrapped.call(cmd, 'arg1');
152
+ await wrapped.call(cmd, 'arg1');
92
153
  (0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
93
154
  (0, vitest_1.expect)(consoleLogSpy).not.toHaveBeenCalledWith(vitest_1.expect.stringContaining('[DRY-RUN]'));
94
- }));
155
+ });
156
+ (0, vitest_1.it)('should simulate write command when root --dry-run flag is set', async () => {
157
+ const { root, child } = buildCommandHierarchy();
158
+ child.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_IDEMPOTENT, 'cli');
159
+ root.setOptionValueWithSource('dryRun', true, 'cli');
160
+ const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, mockAction);
161
+ await wrapped.call(child, UUID_ALLOWED);
162
+ (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
163
+ (0, vitest_1.expect)(consoleLogSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('[DRY-RUN] Would execute'));
164
+ });
165
+ (0, vitest_1.it)('should block when project is not in root --projects list', async () => {
166
+ const { root, child } = buildCommandHierarchy();
167
+ child.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
168
+ root.setOptionValueWithSource('projects', UUID_ALLOWED, 'cli');
169
+ const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, mockAction);
170
+ await (0, vitest_1.expect)(wrapped.call(child, UUID_FORBIDDEN)).rejects.toThrow('exit');
171
+ (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
172
+ (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('not in the list of allowed projects'));
173
+ (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
174
+ });
175
+ (0, vitest_1.it)('should enforce allowlist from command opts when project is only in --project', async () => {
176
+ const { root, child } = buildCommandHierarchy();
177
+ child
178
+ .option('--project <uuid>', 'Project UUID')
179
+ .setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
180
+ root.setOptionValueWithSource('projects', UUID_ALLOWED, 'cli');
181
+ child.setOptionValueWithSource('project', UUID_FORBIDDEN, 'cli');
182
+ const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, mockAction);
183
+ await (0, vitest_1.expect)(wrapped.call(child)).rejects.toThrow('exit');
184
+ (0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
185
+ (0, vitest_1.expect)(consoleErrorSpy).toHaveBeenCalledWith(vitest_1.expect.stringContaining('not in the list of allowed projects'));
186
+ (0, vitest_1.expect)(processExitSpy).toHaveBeenCalledWith(1);
187
+ });
188
+ (0, vitest_1.it)('should re-throw when the action throws', async () => {
189
+ const failingAction = vitest_1.vi.fn().mockRejectedValue(new Error('action failed'));
190
+ const cmd = new commander_1.Command();
191
+ cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
192
+ const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, failingAction);
193
+ await (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('action failed');
194
+ (0, vitest_1.expect)(failingAction).toHaveBeenCalledWith('arg1');
195
+ (0, vitest_1.expect)(processExitSpy).not.toHaveBeenCalled();
196
+ });
95
197
  });
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.6.0",
3
+ "version": "0.8.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": "^14.0.3",
15
- "@lightdash-tools/common": "0.6.0",
16
- "@lightdash-tools/client": "0.6.0"
19
+ "commander": "^15.0.0",
20
+ "yaml": "^2.9.0",
21
+ "@lightdash-tools/client": "0.8.0",
22
+ "@lightdash-tools/common": "0.8.0"
17
23
  },
18
24
  "devDependencies": {
19
- "@types/node": "^25.3.4"
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
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Re-exports shared bundle state fetch from the client package.
3
+ */
4
+
5
+ export { fetchBundleCurrentState } from '@lightdash-tools/client';