@lightdash-tools/cli 0.7.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 +3 -3
- package/dist/commands/schema.d.ts +1 -2
- package/dist/commands/schema.js +9 -105
- package/dist/commands/schema.test.js +36 -27
- package/dist/index.js +1 -1
- package/dist/utils/safety.d.ts +1 -1
- package/dist/utils/safety.js +18 -50
- package/package.json +3 -3
- package/src/commands/schema.test.ts +38 -29
- package/src/commands/schema.ts +13 -116
- package/src/index.ts +1 -1
- package/src/utils/safety.ts +25 -52
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
|
-
- `
|
|
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).
|
|
@@ -168,8 +168,8 @@ lightdash-ai ai-agents threads --page 1 --page-size 10
|
|
|
168
168
|
lightdash-ai schema list
|
|
169
169
|
|
|
170
170
|
# Get schema for a resource (path, method, params)
|
|
171
|
-
lightdash-ai schema get charts.list
|
|
172
|
-
lightdash-ai schema get ai-agents.settings.update
|
|
171
|
+
lightdash-ai schema get cli.charts.list
|
|
172
|
+
lightdash-ai schema get ai-agents.admin.settings.update
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
### Global Options
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Outputs machine-readable JSON describing API paths, methods, and parameters.
|
|
2
|
+
* Shared CLI schema command — catalog-only introspection (ADR-0013).
|
|
4
3
|
*/
|
|
5
4
|
import type { Command } from 'commander';
|
|
6
5
|
export declare function getSchema(resource: string): Record<string, unknown> | null;
|
package/dist/commands/schema.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Outputs machine-readable JSON describing API paths, methods, and parameters.
|
|
3
|
+
* Shared CLI schema command — catalog-only introspection (ADR-0013).
|
|
5
4
|
*/
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
exports.getSchema = getSchema;
|
|
@@ -9,87 +8,6 @@ exports.listResources = listResources;
|
|
|
9
8
|
exports.registerSchemaCommand = registerSchemaCommand;
|
|
10
9
|
const common_1 = require("@lightdash-tools/common");
|
|
11
10
|
const safety_1 = require("../utils/safety");
|
|
12
|
-
/** Maps legacy resource identifiers to API path + method + description. */
|
|
13
|
-
const LEGACY_SCHEMA_REGISTRY = {
|
|
14
|
-
'organization.get': {
|
|
15
|
-
path: '/api/v1/org',
|
|
16
|
-
method: 'GET',
|
|
17
|
-
description: 'Get current organization details',
|
|
18
|
-
},
|
|
19
|
-
'projects.list': {
|
|
20
|
-
path: '/api/v1/org/projects',
|
|
21
|
-
method: 'GET',
|
|
22
|
-
description: 'List all projects in the organization',
|
|
23
|
-
},
|
|
24
|
-
'projects.get': {
|
|
25
|
-
path: '/api/v1/projects/{projectUuid}',
|
|
26
|
-
method: 'GET',
|
|
27
|
-
description: 'Get project by UUID',
|
|
28
|
-
params: ['projectUuid'],
|
|
29
|
-
},
|
|
30
|
-
'charts.list': {
|
|
31
|
-
path: '/api/v1/projects/{projectUuid}/charts',
|
|
32
|
-
method: 'GET',
|
|
33
|
-
description: 'List charts in a project',
|
|
34
|
-
params: ['projectUuid'],
|
|
35
|
-
},
|
|
36
|
-
'charts.code.list': {
|
|
37
|
-
path: '/api/v1/projects/{projectUuid}/code/charts',
|
|
38
|
-
method: 'GET',
|
|
39
|
-
description: 'Get charts in code representation',
|
|
40
|
-
params: ['projectUuid'],
|
|
41
|
-
},
|
|
42
|
-
'charts.code.upsert': {
|
|
43
|
-
path: '/api/v1/projects/{projectUuid}/code/charts/{slug}',
|
|
44
|
-
method: 'POST',
|
|
45
|
-
description: 'Create or update chart by slug',
|
|
46
|
-
params: ['projectUuid', 'slug'],
|
|
47
|
-
},
|
|
48
|
-
'dashboards.list': {
|
|
49
|
-
path: '/api/v1/projects/{projectUuid}/dashboards',
|
|
50
|
-
method: 'GET',
|
|
51
|
-
description: 'List dashboards in a project',
|
|
52
|
-
params: ['projectUuid'],
|
|
53
|
-
},
|
|
54
|
-
'spaces.list': {
|
|
55
|
-
path: '/api/v1/projects/{projectUuid}/spaces',
|
|
56
|
-
method: 'GET',
|
|
57
|
-
description: 'List spaces in a project',
|
|
58
|
-
params: ['projectUuid'],
|
|
59
|
-
},
|
|
60
|
-
'ai-agents.list': {
|
|
61
|
-
path: '/api/v1/aiAgents/admin/agents',
|
|
62
|
-
method: 'GET',
|
|
63
|
-
description: 'List AI agents (admin)',
|
|
64
|
-
},
|
|
65
|
-
'ai-agents.threads': {
|
|
66
|
-
path: '/api/v1/aiAgents/admin/threads',
|
|
67
|
-
method: 'GET',
|
|
68
|
-
description: 'List AI agent threads (admin)',
|
|
69
|
-
},
|
|
70
|
-
'ai-agents.settings.get': {
|
|
71
|
-
path: '/api/v1/aiAgents/admin/settings',
|
|
72
|
-
method: 'GET',
|
|
73
|
-
description: 'Get AI organization settings',
|
|
74
|
-
},
|
|
75
|
-
'ai-agents.settings.update': {
|
|
76
|
-
path: '/api/v1/aiAgents/admin/settings',
|
|
77
|
-
method: 'PATCH',
|
|
78
|
-
description: 'Update AI organization settings',
|
|
79
|
-
},
|
|
80
|
-
'projects.validate.run': {
|
|
81
|
-
path: '/api/v1/projects/{projectUuid}/validate',
|
|
82
|
-
method: 'POST',
|
|
83
|
-
description: 'Start project validation job',
|
|
84
|
-
params: ['projectUuid'],
|
|
85
|
-
},
|
|
86
|
-
'projects.validate.results': {
|
|
87
|
-
path: '/api/v1/projects/{projectUuid}/validate',
|
|
88
|
-
method: 'GET',
|
|
89
|
-
description: 'Get latest validation results',
|
|
90
|
-
params: ['projectUuid'],
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
11
|
function extractPathParams(path) {
|
|
94
12
|
const params = [];
|
|
95
13
|
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
@@ -99,23 +17,11 @@ function extractPathParams(path) {
|
|
|
99
17
|
}
|
|
100
18
|
function operationToSchema(operation) {
|
|
101
19
|
var _a;
|
|
102
|
-
return Object.assign({ resource: operation.id, path: operation.http.path, method: operation.http.method, description: operation.summary, params: extractPathParams(operation.http.path), cliCommand: operation.cli.commandPath
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
var _a;
|
|
106
|
-
return {
|
|
107
|
-
resource,
|
|
108
|
-
path: entry.path,
|
|
109
|
-
method: entry.method,
|
|
110
|
-
description: entry.description,
|
|
111
|
-
params: (_a = entry.params) !== null && _a !== void 0 ? _a : [],
|
|
112
|
-
};
|
|
20
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ resource: operation.id, path: operation.http.path, method: operation.http.method, description: operation.summary, params: extractPathParams(operation.http.path) }, (operation.cli != null ? { cliCommand: operation.cli.commandPath } : {})), (((_a = operation.mcp) === null || _a === void 0 ? void 0 : _a.taskSupport.exposed) === true ? { mcpToolName: operation.mcp.toolName } : {})), (operation.bannedMcpToolName != null
|
|
21
|
+
? { bannedMcpToolName: operation.bannedMcpToolName }
|
|
22
|
+
: {})), { agentExposure: operation.agentExposure, sensitivity: operation.sensitivity, profiles: [...operation.profiles], safetyImpact: operation.authorization.safetyImpact }), (operation.workflow != null ? { workflow: [...operation.workflow] } : {}));
|
|
113
23
|
}
|
|
114
24
|
function getSchema(resource) {
|
|
115
|
-
const legacy = LEGACY_SCHEMA_REGISTRY[resource];
|
|
116
|
-
if (legacy) {
|
|
117
|
-
return legacyToSchema(resource, legacy);
|
|
118
|
-
}
|
|
119
25
|
const operation = (0, common_1.getOperation)(resource);
|
|
120
26
|
if (operation) {
|
|
121
27
|
return operationToSchema(operation);
|
|
@@ -123,11 +29,9 @@ function getSchema(resource) {
|
|
|
123
29
|
return null;
|
|
124
30
|
}
|
|
125
31
|
function listResources() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
]);
|
|
130
|
-
return [...resources].sort();
|
|
32
|
+
return (0, common_1.listOperations)()
|
|
33
|
+
.map((operation) => operation.id)
|
|
34
|
+
.sort();
|
|
131
35
|
}
|
|
132
36
|
/**
|
|
133
37
|
* Registers the schema introspection command.
|
|
@@ -138,14 +42,14 @@ function registerSchemaCommand(program) {
|
|
|
138
42
|
.description('Introspect API schema for agent discoverability');
|
|
139
43
|
schemaCmd
|
|
140
44
|
.command('list')
|
|
141
|
-
.description('List all introspectable resources')
|
|
45
|
+
.description('List all introspectable resources from the operation catalog')
|
|
142
46
|
.action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, () => {
|
|
143
47
|
const resources = listResources();
|
|
144
48
|
console.log(JSON.stringify({ resources }, null, 2));
|
|
145
49
|
}));
|
|
146
50
|
schemaCmd
|
|
147
51
|
.command('get <resource>')
|
|
148
|
-
.description('Get schema for a
|
|
52
|
+
.description('Get schema for a catalog operation id (e.g. ai-agents.project.agents.list)')
|
|
149
53
|
.action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (resource) => {
|
|
150
54
|
const schema = getSchema(resource);
|
|
151
55
|
if (!schema) {
|
|
@@ -4,39 +4,48 @@ const vitest_1 = require("vitest");
|
|
|
4
4
|
const schema_1 = require("./schema");
|
|
5
5
|
(0, vitest_1.describe)('schema command', () => {
|
|
6
6
|
(0, vitest_1.describe)('getSchema', () => {
|
|
7
|
-
(0, vitest_1.it)('returns
|
|
8
|
-
const schema = (0, schema_1.getSchema)('
|
|
7
|
+
(0, vitest_1.it)('returns schema for ai-agents.project.agents.list from the operation catalog', () => {
|
|
8
|
+
const schema = (0, schema_1.getSchema)('ai-agents.project.agents.list');
|
|
9
9
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
10
|
-
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/
|
|
10
|
+
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/aiAgents');
|
|
11
11
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'GET');
|
|
12
|
-
(0, vitest_1.expect)(schema).toHaveProperty('
|
|
13
|
-
(0, vitest_1.expect)(schema
|
|
14
|
-
(0, vitest_1.expect)(schema).toHaveProperty('
|
|
15
|
-
(0, vitest_1.expect)(schema).
|
|
12
|
+
(0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'agents list');
|
|
13
|
+
(0, vitest_1.expect)(schema).toHaveProperty('mcpToolName', 'list_project_agents');
|
|
14
|
+
(0, vitest_1.expect)(schema).toHaveProperty('profiles');
|
|
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');
|
|
17
|
+
(0, vitest_1.expect)(schema).toHaveProperty('sensitivity', 'none');
|
|
16
18
|
});
|
|
17
|
-
(0, vitest_1.it)('returns schema for ai-agents.settings.update
|
|
18
|
-
const schema = (0, schema_1.getSchema)('ai-agents.settings.update');
|
|
19
|
+
(0, vitest_1.it)('returns schema for ai-agents.admin.settings.update from the operation catalog', () => {
|
|
20
|
+
const schema = (0, schema_1.getSchema)('ai-agents.admin.settings.update');
|
|
19
21
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
20
22
|
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/aiAgents/admin/settings');
|
|
21
23
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'PATCH');
|
|
24
|
+
(0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'ai-agents settings update');
|
|
25
|
+
(0, vitest_1.expect)(schema).not.toHaveProperty('mcpToolName');
|
|
22
26
|
});
|
|
23
|
-
(0, vitest_1.it)('returns schema for
|
|
24
|
-
const schema = (0, schema_1.getSchema)('
|
|
27
|
+
(0, vitest_1.it)('returns schema for cli.charts.list from the operation catalog', () => {
|
|
28
|
+
const schema = (0, schema_1.getSchema)('cli.charts.list');
|
|
25
29
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
26
|
-
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/
|
|
30
|
+
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/code/charts');
|
|
27
31
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'GET');
|
|
28
|
-
(0, vitest_1.expect)(schema).
|
|
29
|
-
(0, vitest_1.expect)(schema).toHaveProperty('
|
|
30
|
-
|
|
32
|
+
(0, vitest_1.expect)(schema === null || schema === void 0 ? void 0 : schema.params).toEqual(['projectUuid']);
|
|
33
|
+
(0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'projects charts list');
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)('returns schema for semantic.projects.list with exposed MCP tool name', () => {
|
|
36
|
+
const schema = (0, schema_1.getSchema)('semantic.projects.list');
|
|
37
|
+
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
38
|
+
(0, vitest_1.expect)(schema).toHaveProperty('mcpToolName', 'list_projects');
|
|
39
|
+
(0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'projects list');
|
|
31
40
|
});
|
|
32
|
-
(0, vitest_1.it)('returns schema for ai-agents.project.evaluations.create from operation
|
|
41
|
+
(0, vitest_1.it)('returns schema for ai-agents.project.evaluations.create from the operation catalog', () => {
|
|
33
42
|
const schema = (0, schema_1.getSchema)('ai-agents.project.evaluations.create');
|
|
34
43
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
35
44
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'POST');
|
|
36
45
|
(0, vitest_1.expect)(schema).toHaveProperty('cliCommand', 'agents evals create');
|
|
37
46
|
(0, vitest_1.expect)(schema === null || schema === void 0 ? void 0 : schema.params).toEqual(vitest_1.expect.arrayContaining(['projectUuid', 'agentUuid']));
|
|
38
47
|
});
|
|
39
|
-
(0, vitest_1.it)('returns schema for ai-agents.project.threads.start from operation
|
|
48
|
+
(0, vitest_1.it)('returns schema for ai-agents.project.threads.start from the operation catalog', () => {
|
|
40
49
|
const schema = (0, schema_1.getSchema)('ai-agents.project.threads.start');
|
|
41
50
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
42
51
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'POST');
|
|
@@ -50,7 +59,7 @@ const schema_1 = require("./schema");
|
|
|
50
59
|
}),
|
|
51
60
|
]));
|
|
52
61
|
});
|
|
53
|
-
(0, vitest_1.it)('returns workflow for ai-agents.project.threads.continue from operation
|
|
62
|
+
(0, vitest_1.it)('returns workflow for ai-agents.project.threads.continue from the operation catalog', () => {
|
|
54
63
|
const schema = (0, schema_1.getSchema)('ai-agents.project.threads.continue');
|
|
55
64
|
(0, vitest_1.expect)(schema).not.toBeNull();
|
|
56
65
|
(0, vitest_1.expect)(schema === null || schema === void 0 ? void 0 : schema.workflow).toEqual(vitest_1.expect.arrayContaining([
|
|
@@ -70,27 +79,27 @@ const schema_1 = require("./schema");
|
|
|
70
79
|
(0, vitest_1.expect)(schema).toHaveProperty('method', 'DELETE');
|
|
71
80
|
(0, vitest_1.expect)(schema).toHaveProperty('path', '/api/v1/org/user/{userUuid}');
|
|
72
81
|
(0, vitest_1.expect)(schema).toHaveProperty('agentExposure', 'client-only');
|
|
82
|
+
(0, vitest_1.expect)(schema).toHaveProperty('bannedMcpToolName', 'delete_member');
|
|
73
83
|
});
|
|
74
84
|
(0, vitest_1.it)('returns null for unknown resource', () => {
|
|
75
85
|
const schema = (0, schema_1.getSchema)('unknown.resource');
|
|
76
86
|
(0, vitest_1.expect)(schema).toBeNull();
|
|
77
87
|
});
|
|
88
|
+
(0, vitest_1.it)('does not resolve retired legacy schema keys', () => {
|
|
89
|
+
(0, vitest_1.expect)((0, schema_1.getSchema)('charts.list')).toBeNull();
|
|
90
|
+
(0, vitest_1.expect)((0, schema_1.getSchema)('ai-agents.settings.update')).toBeNull();
|
|
91
|
+
});
|
|
78
92
|
});
|
|
79
93
|
(0, vitest_1.describe)('listResources', () => {
|
|
80
|
-
(0, vitest_1.it)('returns sorted
|
|
94
|
+
(0, vitest_1.it)('returns sorted catalog operation ids only', () => {
|
|
81
95
|
const resources = (0, schema_1.listResources)();
|
|
82
|
-
(0, vitest_1.expect)(resources).toContain('charts.list');
|
|
83
|
-
(0, vitest_1.expect)(resources).toContain('ai-agents.settings.get');
|
|
84
96
|
(0, vitest_1.expect)(resources).toEqual([...resources].sort());
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(0, vitest_1.expect)((0, schema_1.listResources)()).toContain('charts.list');
|
|
88
|
-
});
|
|
89
|
-
(0, vitest_1.it)('includes project-scoped registry operation ids', () => {
|
|
90
|
-
const resources = (0, schema_1.listResources)();
|
|
97
|
+
(0, vitest_1.expect)(resources).not.toContain('charts.list');
|
|
98
|
+
(0, vitest_1.expect)(resources).toContain('cli.charts.list');
|
|
91
99
|
(0, vitest_1.expect)(resources).toContain('ai-agents.project.agents.list');
|
|
92
100
|
(0, vitest_1.expect)(resources).toContain('ai-agents.project.evaluations.run');
|
|
93
101
|
(0, vitest_1.expect)(resources).toContain('ai-agents.project.threads.continue');
|
|
102
|
+
(0, vitest_1.expect)(resources).toContain('semantic.projects.list');
|
|
94
103
|
});
|
|
95
104
|
});
|
|
96
105
|
});
|
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.
|
|
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)');
|
package/dist/utils/safety.d.ts
CHANGED
|
@@ -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
|
|
16
|
+
* CLI --projects takes priority over LIGHTDASH_TOOLS_ALLOWED_PROJECT_UUIDS.
|
|
17
17
|
*/
|
|
18
18
|
export declare function getAllowedProjects(cmd: Command): string[];
|
|
19
19
|
/**
|
package/dist/utils/safety.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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
|
-
(
|
|
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.
|
|
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.
|
|
22
|
-
"@lightdash-tools/common": "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"
|
|
@@ -4,35 +4,45 @@ import { getSchema, listResources } from './schema';
|
|
|
4
4
|
|
|
5
5
|
describe('schema command', () => {
|
|
6
6
|
describe('getSchema', () => {
|
|
7
|
-
it('returns
|
|
8
|
-
const schema = getSchema('
|
|
7
|
+
it('returns schema for ai-agents.project.agents.list from the operation catalog', () => {
|
|
8
|
+
const schema = getSchema('ai-agents.project.agents.list');
|
|
9
9
|
expect(schema).not.toBeNull();
|
|
10
|
-
expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/
|
|
10
|
+
expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/aiAgents');
|
|
11
11
|
expect(schema).toHaveProperty('method', 'GET');
|
|
12
|
-
expect(schema).toHaveProperty('
|
|
13
|
-
expect(schema
|
|
14
|
-
expect(schema).toHaveProperty('
|
|
15
|
-
expect(schema).
|
|
12
|
+
expect(schema).toHaveProperty('cliCommand', 'agents list');
|
|
13
|
+
expect(schema).toHaveProperty('mcpToolName', 'list_project_agents');
|
|
14
|
+
expect(schema).toHaveProperty('profiles');
|
|
15
|
+
expect(schema?.profiles).toContain('core-lifecycle');
|
|
16
|
+
expect(schema?.profiles).toContain('ai-agent-ops');
|
|
17
|
+
expect(schema).toHaveProperty('sensitivity', 'none');
|
|
16
18
|
});
|
|
17
19
|
|
|
18
|
-
it('returns schema for ai-agents.settings.update
|
|
19
|
-
const schema = getSchema('ai-agents.settings.update');
|
|
20
|
+
it('returns schema for ai-agents.admin.settings.update from the operation catalog', () => {
|
|
21
|
+
const schema = getSchema('ai-agents.admin.settings.update');
|
|
20
22
|
expect(schema).not.toBeNull();
|
|
21
23
|
expect(schema).toHaveProperty('path', '/api/v1/aiAgents/admin/settings');
|
|
22
24
|
expect(schema).toHaveProperty('method', 'PATCH');
|
|
25
|
+
expect(schema).toHaveProperty('cliCommand', 'ai-agents settings update');
|
|
26
|
+
expect(schema).not.toHaveProperty('mcpToolName');
|
|
23
27
|
});
|
|
24
28
|
|
|
25
|
-
it('returns schema for
|
|
26
|
-
const schema = getSchema('
|
|
29
|
+
it('returns schema for cli.charts.list from the operation catalog', () => {
|
|
30
|
+
const schema = getSchema('cli.charts.list');
|
|
27
31
|
expect(schema).not.toBeNull();
|
|
28
|
-
expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/
|
|
32
|
+
expect(schema).toHaveProperty('path', '/api/v1/projects/{projectUuid}/code/charts');
|
|
29
33
|
expect(schema).toHaveProperty('method', 'GET');
|
|
30
|
-
expect(schema).
|
|
31
|
-
expect(schema).toHaveProperty('
|
|
32
|
-
|
|
34
|
+
expect(schema?.params).toEqual(['projectUuid']);
|
|
35
|
+
expect(schema).toHaveProperty('cliCommand', 'projects charts list');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns schema for semantic.projects.list with exposed MCP tool name', () => {
|
|
39
|
+
const schema = getSchema('semantic.projects.list');
|
|
40
|
+
expect(schema).not.toBeNull();
|
|
41
|
+
expect(schema).toHaveProperty('mcpToolName', 'list_projects');
|
|
42
|
+
expect(schema).toHaveProperty('cliCommand', 'projects list');
|
|
33
43
|
});
|
|
34
44
|
|
|
35
|
-
it('returns schema for ai-agents.project.evaluations.create from operation
|
|
45
|
+
it('returns schema for ai-agents.project.evaluations.create from the operation catalog', () => {
|
|
36
46
|
const schema = getSchema('ai-agents.project.evaluations.create');
|
|
37
47
|
expect(schema).not.toBeNull();
|
|
38
48
|
expect(schema).toHaveProperty('method', 'POST');
|
|
@@ -40,7 +50,7 @@ describe('schema command', () => {
|
|
|
40
50
|
expect(schema?.params).toEqual(expect.arrayContaining(['projectUuid', 'agentUuid']));
|
|
41
51
|
});
|
|
42
52
|
|
|
43
|
-
it('returns schema for ai-agents.project.threads.start from operation
|
|
53
|
+
it('returns schema for ai-agents.project.threads.start from the operation catalog', () => {
|
|
44
54
|
const schema = getSchema('ai-agents.project.threads.start');
|
|
45
55
|
expect(schema).not.toBeNull();
|
|
46
56
|
expect(schema).toHaveProperty('method', 'POST');
|
|
@@ -60,7 +70,7 @@ describe('schema command', () => {
|
|
|
60
70
|
);
|
|
61
71
|
});
|
|
62
72
|
|
|
63
|
-
it('returns workflow for ai-agents.project.threads.continue from operation
|
|
73
|
+
it('returns workflow for ai-agents.project.threads.continue from the operation catalog', () => {
|
|
64
74
|
const schema = getSchema('ai-agents.project.threads.continue');
|
|
65
75
|
expect(schema).not.toBeNull();
|
|
66
76
|
expect(schema?.workflow).toEqual(
|
|
@@ -83,31 +93,30 @@ describe('schema command', () => {
|
|
|
83
93
|
expect(schema).toHaveProperty('method', 'DELETE');
|
|
84
94
|
expect(schema).toHaveProperty('path', '/api/v1/org/user/{userUuid}');
|
|
85
95
|
expect(schema).toHaveProperty('agentExposure', 'client-only');
|
|
96
|
+
expect(schema).toHaveProperty('bannedMcpToolName', 'delete_member');
|
|
86
97
|
});
|
|
87
98
|
|
|
88
99
|
it('returns null for unknown resource', () => {
|
|
89
100
|
const schema = getSchema('unknown.resource');
|
|
90
101
|
expect(schema).toBeNull();
|
|
91
102
|
});
|
|
103
|
+
|
|
104
|
+
it('does not resolve retired legacy schema keys', () => {
|
|
105
|
+
expect(getSchema('charts.list')).toBeNull();
|
|
106
|
+
expect(getSchema('ai-agents.settings.update')).toBeNull();
|
|
107
|
+
});
|
|
92
108
|
});
|
|
93
109
|
|
|
94
110
|
describe('listResources', () => {
|
|
95
|
-
it('returns sorted
|
|
111
|
+
it('returns sorted catalog operation ids only', () => {
|
|
96
112
|
const resources = listResources();
|
|
97
|
-
expect(resources).toContain('charts.list');
|
|
98
|
-
expect(resources).toContain('ai-agents.settings.get');
|
|
99
113
|
expect(resources).toEqual([...resources].sort());
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
it('includes charts.list', () => {
|
|
103
|
-
expect(listResources()).toContain('charts.list');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('includes project-scoped registry operation ids', () => {
|
|
107
|
-
const resources = listResources();
|
|
114
|
+
expect(resources).not.toContain('charts.list');
|
|
115
|
+
expect(resources).toContain('cli.charts.list');
|
|
108
116
|
expect(resources).toContain('ai-agents.project.agents.list');
|
|
109
117
|
expect(resources).toContain('ai-agents.project.evaluations.run');
|
|
110
118
|
expect(resources).toContain('ai-agents.project.threads.continue');
|
|
119
|
+
expect(resources).toContain('semantic.projects.list');
|
|
111
120
|
});
|
|
112
121
|
});
|
|
113
122
|
});
|
package/src/commands/schema.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Outputs machine-readable JSON describing API paths, methods, and parameters.
|
|
2
|
+
* Shared CLI schema command — catalog-only introspection (ADR-0013).
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
import { getOperation, listOperations, READ_ONLY_DEFAULT } from '@lightdash-tools/common';
|
|
@@ -10,95 +9,6 @@ import { wrapAction } from '../utils/safety';
|
|
|
10
9
|
import type { OperationDescriptor } from '@lightdash-tools/common';
|
|
11
10
|
import type { Command } from 'commander';
|
|
12
11
|
|
|
13
|
-
type SchemaEntry = {
|
|
14
|
-
path: string;
|
|
15
|
-
method: string;
|
|
16
|
-
description: string;
|
|
17
|
-
params?: string[];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/** Maps legacy resource identifiers to API path + method + description. */
|
|
21
|
-
const LEGACY_SCHEMA_REGISTRY: Record<string, SchemaEntry> = {
|
|
22
|
-
'organization.get': {
|
|
23
|
-
path: '/api/v1/org',
|
|
24
|
-
method: 'GET',
|
|
25
|
-
description: 'Get current organization details',
|
|
26
|
-
},
|
|
27
|
-
'projects.list': {
|
|
28
|
-
path: '/api/v1/org/projects',
|
|
29
|
-
method: 'GET',
|
|
30
|
-
description: 'List all projects in the organization',
|
|
31
|
-
},
|
|
32
|
-
'projects.get': {
|
|
33
|
-
path: '/api/v1/projects/{projectUuid}',
|
|
34
|
-
method: 'GET',
|
|
35
|
-
description: 'Get project by UUID',
|
|
36
|
-
params: ['projectUuid'],
|
|
37
|
-
},
|
|
38
|
-
'charts.list': {
|
|
39
|
-
path: '/api/v1/projects/{projectUuid}/charts',
|
|
40
|
-
method: 'GET',
|
|
41
|
-
description: 'List charts in a project',
|
|
42
|
-
params: ['projectUuid'],
|
|
43
|
-
},
|
|
44
|
-
'charts.code.list': {
|
|
45
|
-
path: '/api/v1/projects/{projectUuid}/code/charts',
|
|
46
|
-
method: 'GET',
|
|
47
|
-
description: 'Get charts in code representation',
|
|
48
|
-
params: ['projectUuid'],
|
|
49
|
-
},
|
|
50
|
-
'charts.code.upsert': {
|
|
51
|
-
path: '/api/v1/projects/{projectUuid}/code/charts/{slug}',
|
|
52
|
-
method: 'POST',
|
|
53
|
-
description: 'Create or update chart by slug',
|
|
54
|
-
params: ['projectUuid', 'slug'],
|
|
55
|
-
},
|
|
56
|
-
'dashboards.list': {
|
|
57
|
-
path: '/api/v1/projects/{projectUuid}/dashboards',
|
|
58
|
-
method: 'GET',
|
|
59
|
-
description: 'List dashboards in a project',
|
|
60
|
-
params: ['projectUuid'],
|
|
61
|
-
},
|
|
62
|
-
'spaces.list': {
|
|
63
|
-
path: '/api/v1/projects/{projectUuid}/spaces',
|
|
64
|
-
method: 'GET',
|
|
65
|
-
description: 'List spaces in a project',
|
|
66
|
-
params: ['projectUuid'],
|
|
67
|
-
},
|
|
68
|
-
'ai-agents.list': {
|
|
69
|
-
path: '/api/v1/aiAgents/admin/agents',
|
|
70
|
-
method: 'GET',
|
|
71
|
-
description: 'List AI agents (admin)',
|
|
72
|
-
},
|
|
73
|
-
'ai-agents.threads': {
|
|
74
|
-
path: '/api/v1/aiAgents/admin/threads',
|
|
75
|
-
method: 'GET',
|
|
76
|
-
description: 'List AI agent threads (admin)',
|
|
77
|
-
},
|
|
78
|
-
'ai-agents.settings.get': {
|
|
79
|
-
path: '/api/v1/aiAgents/admin/settings',
|
|
80
|
-
method: 'GET',
|
|
81
|
-
description: 'Get AI organization settings',
|
|
82
|
-
},
|
|
83
|
-
'ai-agents.settings.update': {
|
|
84
|
-
path: '/api/v1/aiAgents/admin/settings',
|
|
85
|
-
method: 'PATCH',
|
|
86
|
-
description: 'Update AI organization settings',
|
|
87
|
-
},
|
|
88
|
-
'projects.validate.run': {
|
|
89
|
-
path: '/api/v1/projects/{projectUuid}/validate',
|
|
90
|
-
method: 'POST',
|
|
91
|
-
description: 'Start project validation job',
|
|
92
|
-
params: ['projectUuid'],
|
|
93
|
-
},
|
|
94
|
-
'projects.validate.results': {
|
|
95
|
-
path: '/api/v1/projects/{projectUuid}/validate',
|
|
96
|
-
method: 'GET',
|
|
97
|
-
description: 'Get latest validation results',
|
|
98
|
-
params: ['projectUuid'],
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
12
|
function extractPathParams(path: string): string[] {
|
|
103
13
|
const params: string[] = [];
|
|
104
14
|
for (const match of path.matchAll(/\{([^}]+)\}/g)) {
|
|
@@ -114,44 +24,31 @@ function operationToSchema(operation: OperationDescriptor): Record<string, unkno
|
|
|
114
24
|
method: operation.http.method,
|
|
115
25
|
description: operation.summary,
|
|
116
26
|
params: extractPathParams(operation.http.path),
|
|
117
|
-
cliCommand: operation.cli.commandPath,
|
|
118
|
-
|
|
27
|
+
...(operation.cli != null ? { cliCommand: operation.cli.commandPath } : {}),
|
|
28
|
+
...(operation.mcp?.taskSupport.exposed === true ? { mcpToolName: operation.mcp.toolName } : {}),
|
|
29
|
+
...(operation.bannedMcpToolName != null
|
|
30
|
+
? { bannedMcpToolName: operation.bannedMcpToolName }
|
|
31
|
+
: {}),
|
|
32
|
+
agentExposure: operation.agentExposure,
|
|
33
|
+
sensitivity: operation.sensitivity,
|
|
119
34
|
profiles: [...operation.profiles],
|
|
120
35
|
safetyImpact: operation.authorization.safetyImpact,
|
|
121
36
|
...(operation.workflow != null ? { workflow: [...operation.workflow] } : {}),
|
|
122
37
|
};
|
|
123
38
|
}
|
|
124
39
|
|
|
125
|
-
function legacyToSchema(resource: string, entry: SchemaEntry): Record<string, unknown> {
|
|
126
|
-
return {
|
|
127
|
-
resource,
|
|
128
|
-
path: entry.path,
|
|
129
|
-
method: entry.method,
|
|
130
|
-
description: entry.description,
|
|
131
|
-
params: entry.params ?? [],
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
40
|
export function getSchema(resource: string): Record<string, unknown> | null {
|
|
136
|
-
const legacy = LEGACY_SCHEMA_REGISTRY[resource];
|
|
137
|
-
if (legacy) {
|
|
138
|
-
return legacyToSchema(resource, legacy);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
41
|
const operation = getOperation(resource);
|
|
142
42
|
if (operation) {
|
|
143
43
|
return operationToSchema(operation);
|
|
144
44
|
}
|
|
145
|
-
|
|
146
45
|
return null;
|
|
147
46
|
}
|
|
148
47
|
|
|
149
48
|
export function listResources(): string[] {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
]);
|
|
154
|
-
return [...resources].sort();
|
|
49
|
+
return listOperations()
|
|
50
|
+
.map((operation) => operation.id)
|
|
51
|
+
.sort();
|
|
155
52
|
}
|
|
156
53
|
|
|
157
54
|
/**
|
|
@@ -164,7 +61,7 @@ export function registerSchemaCommand(program: Command): void {
|
|
|
164
61
|
|
|
165
62
|
schemaCmd
|
|
166
63
|
.command('list')
|
|
167
|
-
.description('List all introspectable resources')
|
|
64
|
+
.description('List all introspectable resources from the operation catalog')
|
|
168
65
|
.action(
|
|
169
66
|
wrapAction(READ_ONLY_DEFAULT, () => {
|
|
170
67
|
const resources = listResources();
|
|
@@ -174,7 +71,7 @@ export function registerSchemaCommand(program: Command): void {
|
|
|
174
71
|
|
|
175
72
|
schemaCmd
|
|
176
73
|
.command('get <resource>')
|
|
177
|
-
.description('Get schema for a
|
|
74
|
+
.description('Get schema for a catalog operation id (e.g. ai-agents.project.agents.list)')
|
|
178
75
|
.action(
|
|
179
76
|
wrapAction(READ_ONLY_DEFAULT, (resource: string) => {
|
|
180
77
|
const schema = getSchema(resource);
|
package/src/index.ts
CHANGED
package/src/utils/safety.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|