@lightdash-tools/cli 0.8.0 → 0.9.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 CHANGED
@@ -26,7 +26,7 @@ The CLI requires the following environment variables (consistent with `@lightdas
26
26
  - `LIGHTDASH_API_KEY` - Personal access token (PAT)
27
27
  - `LIGHTDASH_PROXY_AUTHORIZATION` - Optional proxy authorization header
28
28
  - `LIGHTDASH_TOOLS_SAFETY_MODE` - Optional safety mode (`read-only`, `write-idempotent`, `write-destructive`)
29
- - `LIGHTDASH_TOOLS_ALLOWED_PROJECTS` - Optional comma-separated project UUIDs (restrict operations to these projects; empty = all allowed)
29
+ - `LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS` - Optional comma-separated project UUIDs (restrict operations to these projects; empty = all allowed)
30
30
  - `LIGHTDASH_TOOLS_DRY_RUN` - Set to `1`, `true`, or `yes` to simulate mutating operations without executing
31
31
 
32
32
  Prefer env vars from the parent process. Avoid plaintext `.env` when AI agents have file access. If using `.env`, use [dotenvx](https://dotenvx.com/) for encrypted secrets. See [docs/secrets-and-credentials.md](../../docs/secrets-and-credentials.md).
@@ -10,9 +10,10 @@ const schema_1 = require("./schema");
10
10
  (0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/aiAgents');
11
11
  (0, vitest_1.expect)(schema).toHaveProperty('method', 'GET');
12
12
  (0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'agents list');
13
- (0, vitest_1.expect)(schema).not.toHaveProperty('mcpToolName');
13
+ (0, vitest_1.expect)(schema).toHaveProperty('mcpToolName', 'list_project_agents');
14
14
  (0, vitest_1.expect)(schema).toHaveProperty('profiles');
15
15
  (0, vitest_1.expect)(schema === null || schema === void 0 ? void 0 : schema.profiles).toContain('core-lifecycle');
16
+ (0, vitest_1.expect)(schema === null || schema === void 0 ? void 0 : schema.profiles).toContain('ai-agent-ops');
16
17
  (0, vitest_1.expect)(schema).toHaveProperty('sensitivity', 'none');
17
18
  });
18
19
  (0, vitest_1.it)('returns schema for ai-agents.admin.settings.update from the operation catalog', () => {
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ const program = new commander_1.Command();
33
33
  program
34
34
  .name('lightdash-ai')
35
35
  .description('CLI for Lightdash AI')
36
- .version('0.8.0')
36
+ .version('0.9.0')
37
37
  .option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only')
38
38
  .option('--projects <uuids>', 'Comma-separated list of allowed project UUIDs (security guardrail)')
39
39
  .option('--dry-run', 'Simulate mutating operations without executing (env: LIGHTDASH_TOOLS_DRY_RUN=1)');
@@ -13,7 +13,7 @@ export declare function isDryRun(cmd: Command): boolean;
13
13
  /**
14
14
  * Resolves the allowed project UUIDs from the command line options or environment variables.
15
15
  * We specifically want the root --projects flag as the security guardrail.
16
- * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECTS.
16
+ * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS.
17
17
  */
18
18
  export declare function getAllowedProjects(cmd: Command): string[];
19
19
  /**
@@ -34,7 +34,7 @@ function isDryRun(cmd) {
34
34
  /**
35
35
  * Resolves the allowed project UUIDs from the command line options or environment variables.
36
36
  * We specifically want the root --projects flag as the security guardrail.
37
- * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECTS.
37
+ * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS.
38
38
  */
39
39
  function getAllowedProjects(cmd) {
40
40
  let root = cmd;
@@ -49,7 +49,13 @@ function getAllowedProjects(cmd) {
49
49
  .map((s) => s.trim())
50
50
  .filter(Boolean);
51
51
  }
52
- return (0, common_1.getAllowedProjectUuidsFromEnv)();
52
+ try {
53
+ return (0, common_1.getAllowedProjectUuidsFromEnv)();
54
+ }
55
+ catch (err) {
56
+ console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
57
+ process.exit(1);
58
+ }
53
59
  }
54
60
  /**
55
61
  * Enforces project allowlist for project UUIDs parsed from bundle/gate YAML.
@@ -75,6 +81,9 @@ function getCommandPath(cmd) {
75
81
  }
76
82
  return parts.join(' ');
77
83
  }
84
+ function recordCliAudit(tool, status, startMs, projectUuids) {
85
+ (0, common_1.logAuditEntry)((0, common_1.buildAuditLogEntry)({ tool, status, startMs, projectUuids }));
86
+ }
78
87
  /**
79
88
  * Wraps a CLI action with safety-mode enforcement and audit logging.
80
89
  */
@@ -87,6 +96,7 @@ function wrapAction(annotations, action) {
87
96
  const targetProjects = [
88
97
  ...new Set([...(0, common_1.extractProjectUuids)(args), ...(0, common_1.extractProjectUuids)(this.opts())]),
89
98
  ];
99
+ const projectUuids = targetProjects.length > 0 ? targetProjects : undefined;
90
100
  // ── Input Validation ─────────────────────────────────────────────────────
91
101
  // Validate only known identifier fields (RESOURCE_ID_KEYS) in objects.
92
102
  // Do NOT validate bare positional strings—they may be free-form (query, name, etc.).
@@ -97,41 +107,20 @@ function wrapAction(annotations, action) {
97
107
  (0, common_1.validateResourceIdsInObject)(this.opts());
98
108
  }
99
109
  catch (err) {
100
- (0, common_1.logAuditEntry)({
101
- timestamp: new Date().toISOString(),
102
- sessionId: (0, common_1.getSessionId)(),
103
- tool: commandPath,
104
- projectUuids: targetProjects,
105
- status: 'blocked',
106
- durationMs: Date.now() - start,
107
- });
110
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
108
111
  console.error(`Error: Invalid resource ID: ${err instanceof Error ? err.message : String(err)}`);
109
112
  process.exit(1);
110
113
  }
111
114
  // ── Safety Mode Enforcement ──────────────────────────────────────────────
112
115
  if (!(0, common_1.isAllowed)(mode, annotations)) {
113
- (0, common_1.logAuditEntry)({
114
- timestamp: new Date().toISOString(),
115
- sessionId: (0, common_1.getSessionId)(),
116
- tool: commandPath,
117
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
118
- status: 'blocked',
119
- durationMs: Date.now() - start,
120
- });
116
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
121
117
  console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOLS_SAFETY_MODE.`);
122
118
  process.exit(1);
123
119
  }
124
120
  // ── Dry-Run (Write Commands Only) ────────────────────────────────────────
125
121
  const isReadOnly = !!annotations.readOnlyHint;
126
122
  if (!isReadOnly && isDryRun(this)) {
127
- (0, common_1.logAuditEntry)({
128
- timestamp: new Date().toISOString(),
129
- sessionId: (0, common_1.getSessionId)(),
130
- tool: commandPath,
131
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
132
- status: 'blocked',
133
- durationMs: Date.now() - start,
134
- });
123
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
135
124
  console.log(`[DRY-RUN] Would execute: ${commandPath} with args: ${JSON.stringify(args)}. No changes were made.`);
136
125
  return;
137
126
  }
@@ -139,39 +128,18 @@ function wrapAction(annotations, action) {
139
128
  if (allowedProjects.length > 0) {
140
129
  const deniedProjects = targetProjects.filter((p) => !(0, common_1.areAllProjectsAllowed)(allowedProjects, [p]));
141
130
  if (deniedProjects.length > 0) {
142
- (0, common_1.logAuditEntry)({
143
- timestamp: new Date().toISOString(),
144
- sessionId: (0, common_1.getSessionId)(),
145
- tool: commandPath,
146
- projectUuids: targetProjects,
147
- status: 'blocked',
148
- durationMs: Date.now() - start,
149
- });
131
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
150
132
  console.error(`Error: Project(s) [${deniedProjects.join(', ')}] are not in the list of allowed projects. Allowed: [${allowedProjects.join(', ')}].`);
151
133
  process.exit(1);
152
134
  }
153
135
  }
154
136
  try {
155
137
  const result = await action.apply(this, args);
156
- (0, common_1.logAuditEntry)({
157
- timestamp: new Date().toISOString(),
158
- sessionId: (0, common_1.getSessionId)(),
159
- tool: commandPath,
160
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
161
- status: 'success',
162
- durationMs: Date.now() - start,
163
- });
138
+ recordCliAudit(commandPath, 'success', start, projectUuids);
164
139
  return result;
165
140
  }
166
141
  catch (err) {
167
- (0, common_1.logAuditEntry)({
168
- timestamp: new Date().toISOString(),
169
- sessionId: (0, common_1.getSessionId)(),
170
- tool: commandPath,
171
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
172
- status: 'error',
173
- durationMs: Date.now() - start,
174
- });
142
+ recordCliAudit(commandPath, 'error', start, projectUuids);
175
143
  throw err;
176
144
  }
177
145
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "CLI for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -18,8 +18,8 @@
18
18
  "dependencies": {
19
19
  "commander": "^15.0.0",
20
20
  "yaml": "^2.9.0",
21
- "@lightdash-tools/client": "0.8.0",
22
- "@lightdash-tools/common": "0.8.0"
21
+ "@lightdash-tools/client": "0.9.0",
22
+ "@lightdash-tools/common": "0.9.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^25.9.3"
@@ -10,9 +10,10 @@ describe('schema command', () => {
10
10
  expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/aiAgents');
11
11
  expect(schema).toHaveProperty('method', 'GET');
12
12
  expect(schema).toHaveProperty('cliCommand', 'agents list');
13
- expect(schema).not.toHaveProperty('mcpToolName');
13
+ expect(schema).toHaveProperty('mcpToolName', 'list_project_agents');
14
14
  expect(schema).toHaveProperty('profiles');
15
15
  expect(schema?.profiles).toContain('core-lifecycle');
16
+ expect(schema?.profiles).toContain('ai-agent-ops');
16
17
  expect(schema).toHaveProperty('sensitivity', 'none');
17
18
  });
18
19
 
package/src/index.ts CHANGED
@@ -36,7 +36,7 @@ const program = new Command();
36
36
  program
37
37
  .name('lightdash-ai')
38
38
  .description('CLI for Lightdash AI')
39
- .version('0.8.0')
39
+ .version('0.9.0')
40
40
  .option(
41
41
  '--safety-mode <mode>',
42
42
  'Safety mode (read-only, write-idempotent, write-destructive)',
@@ -2,8 +2,8 @@ import {
2
2
  isAllowed,
3
3
  getSafetyModeFromEnv,
4
4
  SafetyMode,
5
+ buildAuditLogEntry,
5
6
  logAuditEntry,
6
- getSessionId,
7
7
  areAllProjectsAllowed,
8
8
  getAllowedProjectUuidsFromEnv,
9
9
  extractProjectUuids,
@@ -11,7 +11,7 @@ import {
11
11
  validateResourceIdsInObject,
12
12
  } from '@lightdash-tools/common';
13
13
 
14
- import type { ToolAnnotations } from '@lightdash-tools/common';
14
+ import type { AuditStatus, ToolAnnotations } from '@lightdash-tools/common';
15
15
  import type { Command } from 'commander';
16
16
 
17
17
  /**
@@ -43,7 +43,7 @@ export function isDryRun(cmd: Command): boolean {
43
43
  /**
44
44
  * Resolves the allowed project UUIDs from the command line options or environment variables.
45
45
  * We specifically want the root --projects flag as the security guardrail.
46
- * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECTS.
46
+ * CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS.
47
47
  */
48
48
  export function getAllowedProjects(cmd: Command): string[] {
49
49
  let root = cmd;
@@ -58,7 +58,12 @@ export function getAllowedProjects(cmd: Command): string[] {
58
58
  .map((s) => s.trim())
59
59
  .filter(Boolean);
60
60
  }
61
- return getAllowedProjectUuidsFromEnv();
61
+ try {
62
+ return getAllowedProjectUuidsFromEnv();
63
+ } catch (err) {
64
+ console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
65
+ process.exit(1);
66
+ }
62
67
  }
63
68
 
64
69
  /**
@@ -88,6 +93,15 @@ function getCommandPath(cmd: Command): string {
88
93
  return parts.join(' ');
89
94
  }
90
95
 
96
+ function recordCliAudit(
97
+ tool: string,
98
+ status: AuditStatus,
99
+ startMs: number,
100
+ projectUuids: string[] | undefined,
101
+ ): void {
102
+ logAuditEntry(buildAuditLogEntry({ tool, status, startMs, projectUuids }));
103
+ }
104
+
91
105
  /**
92
106
  * Wraps a CLI action with safety-mode enforcement and audit logging.
93
107
  */
@@ -103,6 +117,7 @@ export function wrapAction<T extends unknown[]>(
103
117
  const targetProjects = [
104
118
  ...new Set([...extractProjectUuids(args), ...extractProjectUuids(this.opts())]),
105
119
  ];
120
+ const projectUuids = targetProjects.length > 0 ? targetProjects : undefined;
106
121
 
107
122
  // ── Input Validation ─────────────────────────────────────────────────────
108
123
  // Validate only known identifier fields (RESOURCE_ID_KEYS) in objects.
@@ -113,14 +128,7 @@ export function wrapAction<T extends unknown[]>(
113
128
  }
114
129
  validateResourceIdsInObject(this.opts());
115
130
  } catch (err) {
116
- logAuditEntry({
117
- timestamp: new Date().toISOString(),
118
- sessionId: getSessionId(),
119
- tool: commandPath,
120
- projectUuids: targetProjects,
121
- status: 'blocked',
122
- durationMs: Date.now() - start,
123
- });
131
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
124
132
  console.error(
125
133
  `Error: Invalid resource ID: ${err instanceof Error ? err.message : String(err)}`,
126
134
  );
@@ -129,14 +137,7 @@ export function wrapAction<T extends unknown[]>(
129
137
 
130
138
  // ── Safety Mode Enforcement ──────────────────────────────────────────────
131
139
  if (!isAllowed(mode, annotations)) {
132
- logAuditEntry({
133
- timestamp: new Date().toISOString(),
134
- sessionId: getSessionId(),
135
- tool: commandPath,
136
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
137
- status: 'blocked',
138
- durationMs: Date.now() - start,
139
- });
140
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
140
141
  console.error(
141
142
  `Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOLS_SAFETY_MODE.`,
142
143
  );
@@ -146,14 +147,7 @@ export function wrapAction<T extends unknown[]>(
146
147
  // ── Dry-Run (Write Commands Only) ────────────────────────────────────────
147
148
  const isReadOnly = !!annotations.readOnlyHint;
148
149
  if (!isReadOnly && isDryRun(this)) {
149
- logAuditEntry({
150
- timestamp: new Date().toISOString(),
151
- sessionId: getSessionId(),
152
- tool: commandPath,
153
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
154
- status: 'blocked',
155
- durationMs: Date.now() - start,
156
- });
150
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
157
151
  console.log(
158
152
  `[DRY-RUN] Would execute: ${commandPath} with args: ${JSON.stringify(args)}. No changes were made.`,
159
153
  );
@@ -166,14 +160,7 @@ export function wrapAction<T extends unknown[]>(
166
160
  (p) => !areAllProjectsAllowed(allowedProjects, [p]),
167
161
  );
168
162
  if (deniedProjects.length > 0) {
169
- logAuditEntry({
170
- timestamp: new Date().toISOString(),
171
- sessionId: getSessionId(),
172
- tool: commandPath,
173
- projectUuids: targetProjects,
174
- status: 'blocked',
175
- durationMs: Date.now() - start,
176
- });
163
+ recordCliAudit(commandPath, 'blocked', start, projectUuids);
177
164
  console.error(
178
165
  `Error: Project(s) [${deniedProjects.join(', ')}] are not in the list of allowed projects. Allowed: [${allowedProjects.join(', ')}].`,
179
166
  );
@@ -183,24 +170,10 @@ export function wrapAction<T extends unknown[]>(
183
170
 
184
171
  try {
185
172
  const result = await action.apply(this, args);
186
- logAuditEntry({
187
- timestamp: new Date().toISOString(),
188
- sessionId: getSessionId(),
189
- tool: commandPath,
190
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
191
- status: 'success',
192
- durationMs: Date.now() - start,
193
- });
173
+ recordCliAudit(commandPath, 'success', start, projectUuids);
194
174
  return result;
195
175
  } catch (err) {
196
- logAuditEntry({
197
- timestamp: new Date().toISOString(),
198
- sessionId: getSessionId(),
199
- tool: commandPath,
200
- projectUuids: targetProjects.length > 0 ? targetProjects : undefined,
201
- status: 'error',
202
- durationMs: Date.now() - start,
203
- });
176
+ recordCliAudit(commandPath, 'error', start, projectUuids);
204
177
  throw err;
205
178
  }
206
179
  };