@solidactions/cli 3.12.0 → 3.14.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 +58 -2
- package/dist/command-manifest.json +3 -3
- package/dist/commands/deploy.js +52 -2
- package/dist/commands/login.js +105 -37
- package/dist/commands/project-list.js +5 -2
- package/dist/commands/project-view.js +35 -4
- package/dist/commands/run-list.js +3 -15
- package/dist/commands/run-view.js +10 -6
- package/dist/commands/workspaces.js +1 -1
- package/dist/index.js +17 -3
- package/dist/utils/api.js +170 -12
- package/dist/utils/config.js +14 -6
- package/dist/utils/mutating-commands.js +176 -0
- package/dist/utils/source-provenance.js +13 -0
- package/dist/utils/workspace-guard.js +110 -0
- package/dist/utils/workspace-lookup.js +137 -25
- package/package.json +1 -1
package/dist/utils/api.js
CHANGED
|
@@ -3,23 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SANDBOX_EGRESS_MESSAGE = void 0;
|
|
6
|
+
exports.WorkspaceGuardAbort = exports.SANDBOX_EGRESS_MESSAGE = void 0;
|
|
7
7
|
exports.augmentSandboxEgressMessage = augmentSandboxEgressMessage;
|
|
8
8
|
exports.augmentNotFoundMessage = augmentNotFoundMessage;
|
|
9
9
|
exports.augmentWorkspaceForbiddenMessage = augmentWorkspaceForbiddenMessage;
|
|
10
10
|
exports.augmentTokenMissingAbilityMessage = augmentTokenMissingAbilityMessage;
|
|
11
11
|
exports.getApiHeaders = getApiHeaders;
|
|
12
|
+
exports.lookupProjectFamilyEnvironments = lookupProjectFamilyEnvironments;
|
|
13
|
+
exports.listProjectEnvironments = listProjectEnvironments;
|
|
12
14
|
exports.describeProjectEnvironments = describeProjectEnvironments;
|
|
13
15
|
exports.formatValidationError = formatValidationError;
|
|
14
16
|
exports.requireResolvedConfig = requireResolvedConfig;
|
|
15
17
|
exports.requireConfig = requireConfig;
|
|
16
18
|
exports.authFailureMessage = authFailureMessage;
|
|
17
19
|
exports.ensureWorkspaceSelected = ensureWorkspaceSelected;
|
|
20
|
+
exports.buildWorkspaceConfirmPrompt = buildWorkspaceConfirmPrompt;
|
|
21
|
+
exports.applyWorkspaceGuard = applyWorkspaceGuard;
|
|
18
22
|
exports.requireConfigWithWorkspace = requireConfigWithWorkspace;
|
|
19
23
|
const axios_1 = __importDefault(require("axios"));
|
|
20
24
|
const chalk_1 = __importDefault(require("chalk"));
|
|
25
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
21
26
|
const config_1 = require("./config");
|
|
22
27
|
const workspace_lookup_1 = require("./workspace-lookup");
|
|
28
|
+
const mutating_commands_1 = require("./mutating-commands");
|
|
29
|
+
const workspace_guard_1 = require("./workspace-guard");
|
|
23
30
|
// Backend (solidactions-app PR #128) returns: "Project '<slug>' not found in your active workspace '<workspace-slug>'."
|
|
24
31
|
// We require the literal single-quotes around the slug so plausible future error messages
|
|
25
32
|
// like "Project files not found ..." don't false-match.
|
|
@@ -186,22 +193,48 @@ function getApiHeaders(config, contentType) {
|
|
|
186
193
|
return headers;
|
|
187
194
|
}
|
|
188
195
|
/**
|
|
189
|
-
* Best-effort lookup of the environments a project family actually has
|
|
190
|
-
*
|
|
191
|
-
* any failure — callers should treat that as "no extra detail
|
|
196
|
+
* Best-effort lookup of the environments a project family actually has, with
|
|
197
|
+
* the real slug the server uses for each, for a friendlier 404 message.
|
|
198
|
+
* Returns null on any failure — callers should treat that as "no extra detail
|
|
199
|
+
* available."
|
|
192
200
|
*/
|
|
193
|
-
async function
|
|
201
|
+
async function lookupProjectFamilyEnvironments(config, projectName) {
|
|
194
202
|
try {
|
|
195
203
|
const res = await axios_1.default.get(`${config.host}/api/v1/projects`, { headers: getApiHeaders(config) });
|
|
196
204
|
const rows = res.data?.data ?? res.data ?? [];
|
|
197
205
|
const hit = rows.find((p) => p.name === projectName || p.slug === projectName);
|
|
198
|
-
const
|
|
199
|
-
|
|
206
|
+
const environments = hit?.environments;
|
|
207
|
+
if (!environments?.length) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const slugs = {};
|
|
211
|
+
for (const detail of hit?.environment_details ?? []) {
|
|
212
|
+
if (typeof detail?.environment === 'string' && typeof detail?.slug === 'string') {
|
|
213
|
+
slugs[detail.environment] = detail.slug;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { environments, slugs };
|
|
200
217
|
}
|
|
201
218
|
catch {
|
|
202
219
|
return null;
|
|
203
220
|
}
|
|
204
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Best-effort lookup of the environments a project family actually has
|
|
224
|
+
* (e.g. ["production", "dev"]), for a friendlier 404 message. Returns null
|
|
225
|
+
* on any failure — callers should treat that as "no extra detail available."
|
|
226
|
+
*/
|
|
227
|
+
async function listProjectEnvironments(config, projectName) {
|
|
228
|
+
return (await lookupProjectFamilyEnvironments(config, projectName))?.environments ?? null;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Same lookup as `listProjectEnvironments`, joined for display (e.g.
|
|
232
|
+
* "production, dev"). Returns null on any failure.
|
|
233
|
+
*/
|
|
234
|
+
async function describeProjectEnvironments(config, projectName) {
|
|
235
|
+
const envs = await listProjectEnvironments(config, projectName);
|
|
236
|
+
return envs ? envs.join(', ') : null;
|
|
237
|
+
}
|
|
205
238
|
/**
|
|
206
239
|
* Render a Laravel-style 422 validation error body as plain readable text —
|
|
207
240
|
* never a raw JSON dump. Prefers `data.errors` (flattened, one message per
|
|
@@ -316,7 +349,9 @@ async function ensureWorkspaceSelected(config, dependencies = {}) {
|
|
|
316
349
|
let selected;
|
|
317
350
|
if (workspaces.length === 1) {
|
|
318
351
|
selected = workspaces[0];
|
|
319
|
-
|
|
352
|
+
// Status text, not a command's own output — stdout is reserved for machine-parseable
|
|
353
|
+
// output (e.g. `--json`), same reasoning as the workspace banner above.
|
|
354
|
+
console.error(chalk_1.default.gray(`Auto-selected workspace: ${(0, workspace_lookup_1.formatWorkspaceWithOrg)(selected)}`));
|
|
320
355
|
}
|
|
321
356
|
else {
|
|
322
357
|
if (!process.stdin.isTTY) {
|
|
@@ -334,22 +369,145 @@ async function ensureWorkspaceSelected(config, dependencies = {}) {
|
|
|
334
369
|
}
|
|
335
370
|
config.workspace = selected.slug ?? selected.name;
|
|
336
371
|
config.workspaceId = selected.id;
|
|
372
|
+
config.workspaceOrg = selected.org_name;
|
|
337
373
|
if (workspaceSource !== 'env') {
|
|
338
374
|
const targetPath = resolved?.activePath ?? (0, config_1.getGlobalConfigPath)();
|
|
339
375
|
(0, config_1.writeConfigFile)(targetPath, config);
|
|
340
376
|
}
|
|
341
377
|
return config;
|
|
342
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Thrown by applyWorkspaceGuard when a CWD-inferred write is refused (non-TTY, no --yes)
|
|
381
|
+
* or declined (user answered no to the confirm prompt). Kept as a typed error rather than
|
|
382
|
+
* calling process.exit directly so the guard's decision logic stays unit-testable; the thin
|
|
383
|
+
* wrapper below (requireConfigWithWorkspace) is the only place that converts it into an exit.
|
|
384
|
+
*/
|
|
385
|
+
class WorkspaceGuardAbort extends Error {
|
|
386
|
+
exitCode;
|
|
387
|
+
constructor(exitCode, message) {
|
|
388
|
+
super(message);
|
|
389
|
+
this.exitCode = exitCode;
|
|
390
|
+
this.name = 'WorkspaceGuardAbort';
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
exports.WorkspaceGuardAbort = WorkspaceGuardAbort;
|
|
394
|
+
/**
|
|
395
|
+
* Renders the resolved workspace for humans: `<name> — organization <org> (<id>)`.
|
|
396
|
+
*
|
|
397
|
+
* `workspace` (the display name/slug) and `workspaceId` are INDEPENDENT config layers.
|
|
398
|
+
* Setting only SOLIDACTIONS_WORKSPACE_ID resolves the id from the environment while the
|
|
399
|
+
* name is left behind by a config file that describes a DIFFERENT workspace — pairing them
|
|
400
|
+
* would print a confident lie about where a write is going. When the name did not come from
|
|
401
|
+
* the same layer as the id, show the id alone (#1437).
|
|
402
|
+
*/
|
|
403
|
+
function describeWorkspace(config, sources) {
|
|
404
|
+
const id = config.workspaceId ?? '';
|
|
405
|
+
// A name that is merely ABSENT cannot mislead — only one carried over from another layer can.
|
|
406
|
+
if (config.workspace && sources.workspace !== sources.workspaceId) {
|
|
407
|
+
return id || 'workspace';
|
|
408
|
+
}
|
|
409
|
+
const name = config.workspace ?? (id || 'workspace');
|
|
410
|
+
return `${(0, workspace_lookup_1.formatWorkspaceWithOrg)({ id, name, org_name: config.workspaceOrg })} (${id})`;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* The `prompts` question for the workspace-write confirmation. stdout is reserved for a
|
|
414
|
+
* command's own machine-parseable output (see the `announce` comment in applyWorkspaceGuard
|
|
415
|
+
* below), so this prompt must render to stderr — `prompts` defaults to stdout unless told
|
|
416
|
+
* otherwise, which would corrupt a captured `--json` stream while stdin is still a TTY (#1437).
|
|
417
|
+
*/
|
|
418
|
+
function buildWorkspaceConfirmPrompt(message) {
|
|
419
|
+
return { type: 'confirm', name: 'confirm', message, initial: false, stdout: process.stderr };
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Applies the CWD-inference guard to an already-resolved config, then records it as last-used.
|
|
423
|
+
* Returns the config, or throws WorkspaceGuardAbort when the user declines / cannot be asked
|
|
424
|
+
* (the caller is responsible for turning that into process.exit).
|
|
425
|
+
*/
|
|
426
|
+
async function applyWorkspaceGuard(config, sources, options, io = {}) {
|
|
427
|
+
const isTty = io.isTty ?? (() => !!process.stdin.isTTY);
|
|
428
|
+
const warn = io.warn ?? ((message) => { process.stderr.write(`${message}\n`); });
|
|
429
|
+
// stdout is reserved for a command's own machine-parseable output (e.g. `database
|
|
430
|
+
// create --json`) — the banner and the decline message are human-facing status, so
|
|
431
|
+
// they default to stderr, same as warn.
|
|
432
|
+
const announce = io.announce ?? ((message) => { process.stderr.write(`${message}\n`); });
|
|
433
|
+
const now = io.now ?? (() => new Date());
|
|
434
|
+
const cwdInferred = (0, workspace_guard_1.isCwdInferredWorkspace)(sources, (0, config_1.getGlobalConfigPath)());
|
|
435
|
+
if (options.explicitOverride && cwdInferred) {
|
|
436
|
+
// Invariant: -w always sets sources.workspaceId = 'cli', which isCwdInferredWorkspace
|
|
437
|
+
// already treats as not-inferred. If this fires, resolution wiring is broken.
|
|
438
|
+
throw new Error('workspace guard: explicitOverride but isCwdInferredWorkspace returned true');
|
|
439
|
+
}
|
|
440
|
+
const lastUsed = (0, workspace_guard_1.readLastUsedWorkspace)(io.homeDir);
|
|
441
|
+
const action = (0, workspace_guard_1.decideWorkspaceGuard)({
|
|
442
|
+
resolvedWorkspaceId: config.workspaceId,
|
|
443
|
+
lastUsedWorkspaceId: lastUsed?.workspaceId,
|
|
444
|
+
cwdInferred,
|
|
445
|
+
mutating: options.mutating,
|
|
446
|
+
});
|
|
447
|
+
if (action === 'warn' || action === 'confirm') {
|
|
448
|
+
const inferredFrom = sources.workspaceId;
|
|
449
|
+
const lastLabel = lastUsed?.label ?? lastUsed?.workspaceId ?? 'unknown';
|
|
450
|
+
warn(chalk_1.default.yellow('warn:') + ` workspace changed to ${describeWorkspace(config, sources)} `
|
|
451
|
+
+ `— inferred from ${inferredFrom}; last used was ${lastLabel}. `
|
|
452
|
+
+ `Pin it with -w ${config.workspaceId}.`);
|
|
453
|
+
}
|
|
454
|
+
if (action === 'confirm') {
|
|
455
|
+
// Consent to a workspace is exactly two things: stating it explicitly (-w /
|
|
456
|
+
// SOLIDACTIONS_WORKSPACE_ID, both of which make this branch unreachable), or
|
|
457
|
+
// answering the interactive prompt below. A command's OWN --yes is never
|
|
458
|
+
// workspace consent — it acknowledges that command's own destructive act
|
|
459
|
+
// (`database push` requires -y, `database pull --yes` means "overwrite the local
|
|
460
|
+
// file"), and conflating the two made the confirmation structurally unreachable
|
|
461
|
+
// on the highest-blast-radius command in the CLI (#1437).
|
|
462
|
+
if (!isTty()) {
|
|
463
|
+
warn(`re-run with -w ${config.workspaceId} to confirm the target workspace`);
|
|
464
|
+
throw new WorkspaceGuardAbort(1, 'workspace guard: refused (non-interactive)');
|
|
465
|
+
}
|
|
466
|
+
const confirmFn = io.confirm ?? (async (message) => {
|
|
467
|
+
const response = await (0, prompts_1.default)(buildWorkspaceConfirmPrompt(message));
|
|
468
|
+
return !!response.confirm;
|
|
469
|
+
});
|
|
470
|
+
const proceed = await confirmFn(`This command WRITES to ${describeWorkspace(config, sources)}. Proceed?`);
|
|
471
|
+
if (!proceed) {
|
|
472
|
+
announce(chalk_1.default.gray('Cancelled.'));
|
|
473
|
+
throw new WorkspaceGuardAbort(0, 'workspace guard: user declined');
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (options.mutating && config.workspaceId) {
|
|
477
|
+
announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)}`));
|
|
478
|
+
}
|
|
479
|
+
// state.json means "the workspace you last WROTE to" — that is precisely what the write
|
|
480
|
+
// confirmation above compares against. A read must never consume the change that gates a
|
|
481
|
+
// write, so only a mutating command records here; reads stay purely advisory.
|
|
482
|
+
if (options.mutating && config.workspaceId) {
|
|
483
|
+
(0, workspace_guard_1.writeLastUsedWorkspace)({ workspaceId: config.workspaceId, label: config.workspace, at: now().toISOString() }, io.homeDir);
|
|
484
|
+
}
|
|
485
|
+
return config;
|
|
486
|
+
}
|
|
343
487
|
async function requireConfigWithWorkspace() {
|
|
344
488
|
const resolved = requireResolvedConfig();
|
|
345
489
|
let config = resolved.config;
|
|
490
|
+
const explicitOverride = resolved.sources.workspace === 'cli';
|
|
346
491
|
// -w override path: source label 'cli' on the workspace field means
|
|
347
492
|
// setCliWorkspaceOverride was called. workspaceId was cleared by resolveConfig
|
|
348
493
|
// because we don't yet know if the input was a slug or UUID. Resolve now.
|
|
349
|
-
if (
|
|
494
|
+
if (explicitOverride && !config.workspaceId) {
|
|
350
495
|
const ws = await (0, workspace_lookup_1.resolveWorkspaceInput)(config, config.workspace);
|
|
351
|
-
config = { ...config, workspace: ws.slug ?? ws.name, workspaceId: ws.id };
|
|
352
|
-
|
|
496
|
+
config = { ...config, workspace: ws.slug ?? ws.name, workspaceId: ws.id, workspaceOrg: ws.org_name };
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
config = await ensureWorkspaceSelected(config);
|
|
500
|
+
}
|
|
501
|
+
try {
|
|
502
|
+
return await applyWorkspaceGuard(config, resolved.sources, {
|
|
503
|
+
mutating: (0, mutating_commands_1.activeCommandIsMutating)(),
|
|
504
|
+
explicitOverride,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
if (error instanceof WorkspaceGuardAbort) {
|
|
509
|
+
process.exit(error.exitCode);
|
|
510
|
+
}
|
|
511
|
+
throw error;
|
|
353
512
|
}
|
|
354
|
-
return ensureWorkspaceSelected(config);
|
|
355
513
|
}
|
package/dist/utils/config.js
CHANGED
|
@@ -107,9 +107,9 @@ function writeConfigFile(filePath, config) {
|
|
|
107
107
|
* any existing keys (preserves host/apiKey if already present). Re-uses
|
|
108
108
|
* writeConfigFile's atomic-write + 0o600 mode contract.
|
|
109
109
|
*/
|
|
110
|
-
function writeWorkspaceToFile(filePath, workspace, workspaceId) {
|
|
110
|
+
function writeWorkspaceToFile(filePath, workspace, workspaceId, org) {
|
|
111
111
|
const existing = readConfigFile(filePath) ?? {};
|
|
112
|
-
writeConfigFile(filePath, { ...existing, workspace, workspaceId });
|
|
112
|
+
writeConfigFile(filePath, { ...existing, workspace, workspaceId, workspaceOrg: org });
|
|
113
113
|
}
|
|
114
114
|
function removeConfigFile(filePath) {
|
|
115
115
|
if (!fs_1.default.existsSync(filePath)) {
|
|
@@ -157,14 +157,17 @@ function mergeConfigs(env, local, localPath, global, globalPath) {
|
|
|
157
157
|
// Pure workspace-pin local files (no host/apiKey of their own) keep
|
|
158
158
|
// inheriting global credentials and so may still inherit the workspace.
|
|
159
159
|
const localDefinesCreds = !!(local && (local.host !== undefined || local.apiKey !== undefined));
|
|
160
|
+
// org must travel with the SAME layer that supplied workspaceId — never picked
|
|
161
|
+
// independently — so a local file pinning workspace A never inherits the global
|
|
162
|
+
// file's org name for a workspace it didn't name (the confusion #1194 fixed).
|
|
160
163
|
const pickWorkspaceField = (key) => {
|
|
161
164
|
if (env[key] !== undefined)
|
|
162
|
-
return { value: env[key], source: 'env' };
|
|
165
|
+
return { value: env[key], source: 'env', org: undefined };
|
|
163
166
|
if (local && local[key] !== undefined)
|
|
164
|
-
return { value: local[key], source: localPath };
|
|
167
|
+
return { value: local[key], source: localPath, org: local.workspaceOrg };
|
|
165
168
|
if (!localDefinesCreds && global && global[key] !== undefined)
|
|
166
|
-
return { value: global[key], source: globalPath };
|
|
167
|
-
return { value: undefined, source: null };
|
|
169
|
+
return { value: global[key], source: globalPath, org: global.workspaceOrg };
|
|
170
|
+
return { value: undefined, source: null, org: undefined };
|
|
168
171
|
};
|
|
169
172
|
const workspace = pickWorkspaceField('workspace');
|
|
170
173
|
const workspaceId = pickWorkspaceField('workspaceId');
|
|
@@ -180,6 +183,7 @@ function mergeConfigs(env, local, localPath, global, globalPath) {
|
|
|
180
183
|
apiKey: (apiKey.value ?? ''),
|
|
181
184
|
workspace: workspace.value,
|
|
182
185
|
workspaceId: workspaceId.value,
|
|
186
|
+
workspaceOrg: workspaceId.org,
|
|
183
187
|
scopeMode: scopeMode.value,
|
|
184
188
|
scopedWorkspaceIds: scopedWorkspaceIds.value,
|
|
185
189
|
},
|
|
@@ -208,6 +212,10 @@ function resolveConfig(cwd = process.cwd()) {
|
|
|
208
212
|
if (cliWorkspaceOverride !== undefined) {
|
|
209
213
|
merged.config.workspace = cliWorkspaceOverride;
|
|
210
214
|
merged.config.workspaceId = undefined;
|
|
215
|
+
// Org is unknown until resolveWorkspaceInput() re-resolves it for the override
|
|
216
|
+
// (requireConfigWithWorkspace's -w branch sets it there) — a stale file-layer
|
|
217
|
+
// org must not linger and get attributed to whatever workspace -w turns out to be.
|
|
218
|
+
merged.config.workspaceOrg = undefined;
|
|
211
219
|
merged.sources.workspace = 'cli';
|
|
212
220
|
merged.sources.workspaceId = 'cli';
|
|
213
221
|
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Read-vs-write classification for every leaf CLI command.
|
|
4
|
+
*
|
|
5
|
+
* Used to decide whether an implicitly-resolved workspace (inferred from
|
|
6
|
+
* CWD) needs a confirmation prompt before a command runs: reads are safe to
|
|
7
|
+
* run against the wrong workspace, writes are not.
|
|
8
|
+
*
|
|
9
|
+
* Classified by reading each command's implementation under src/commands/
|
|
10
|
+
* and checking which HTTP verb it sends. Most commands call axios directly
|
|
11
|
+
* (GET = read, POST/PUT/PATCH/DELETE = write). The MCP-backed commands
|
|
12
|
+
* (crews/roles tools: skill push/publish/pull/list/view/delete, role push;
|
|
13
|
+
* docs_vault tool: doc push/pull) are transported as a single JSON-RPC
|
|
14
|
+
* `tools/call` POST regardless of semantics (see `postMcpTool` in
|
|
15
|
+
* src/utils/mcp.ts) — for those, the classification follows the MCP tool's
|
|
16
|
+
* `action` argument instead of the outer HTTP verb ('list'/'read' = read,
|
|
17
|
+
* 'create'/'edit'/'delete'/'take_snapshot'/'sandbox_exec' = write).
|
|
18
|
+
*
|
|
19
|
+
* Classification is per command PATH only — it does not see flags. A
|
|
20
|
+
* command that can write under some flag combination but not others (e.g.
|
|
21
|
+
* `database pull --writable`) must still be classified MUTATING wholesale;
|
|
22
|
+
* there is no flag-aware variant of this lookup. Over-inclusion is the
|
|
23
|
+
* intended bias: the workspace-mismatch guard this file feeds only prompts
|
|
24
|
+
* when the resolved workspace ALSO changed and was CWD-inferred, so
|
|
25
|
+
* classifying a mostly-read command as MUTATING costs at most one extra
|
|
26
|
+
* confirmation, whereas the reverse can silently write to the wrong
|
|
27
|
+
* workspace.
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.READONLY_COMMANDS = exports.MUTATING_COMMANDS = void 0;
|
|
31
|
+
exports.isMutatingCommand = isMutatingCommand;
|
|
32
|
+
exports.setActiveCommandPath = setActiveCommandPath;
|
|
33
|
+
exports.getActiveCommandPath = getActiveCommandPath;
|
|
34
|
+
exports.activeCommandIsMutating = activeCommandIsMutating;
|
|
35
|
+
/** Space-joined command paths that mutate SERVER state, e.g. 'project deploy'. */
|
|
36
|
+
exports.MUTATING_COMMANDS = new Set([
|
|
37
|
+
'database create',
|
|
38
|
+
'database delete',
|
|
39
|
+
'database undelete',
|
|
40
|
+
'database exec',
|
|
41
|
+
'database import',
|
|
42
|
+
'database push',
|
|
43
|
+
// Plain `database pull` is read-only (GET, writes a local file only —
|
|
44
|
+
// same family as project/env/doc/skill pull). But `--writable`
|
|
45
|
+
// (databaseWritablePullWithConfig, src/commands/database.ts:1320) mints
|
|
46
|
+
// a WRITE-mode credential and opens a live interactive SQL REPL that
|
|
47
|
+
// executes real statements (client.execute/executeMultiple, ~lines
|
|
48
|
+
// 1540-1560) against the server-backed replica. Classification can't see
|
|
49
|
+
// flags, so the whole leaf must be MUTATING to keep the workspace guard
|
|
50
|
+
// from silently letting --writable writes through against the wrong
|
|
51
|
+
// CWD-inferred workspace.
|
|
52
|
+
'database pull',
|
|
53
|
+
'project create',
|
|
54
|
+
'project deploy',
|
|
55
|
+
'project enable',
|
|
56
|
+
'project disable',
|
|
57
|
+
'workflow enable',
|
|
58
|
+
'workflow disable',
|
|
59
|
+
'run start',
|
|
60
|
+
'env set',
|
|
61
|
+
'env delete',
|
|
62
|
+
'env reset',
|
|
63
|
+
'env map',
|
|
64
|
+
'env push',
|
|
65
|
+
'crew env set',
|
|
66
|
+
'crew env map-database',
|
|
67
|
+
'crew env delete',
|
|
68
|
+
'crew env push',
|
|
69
|
+
'schedule set',
|
|
70
|
+
'schedule enable',
|
|
71
|
+
'schedule disable',
|
|
72
|
+
'schedule reset',
|
|
73
|
+
'schedule delete',
|
|
74
|
+
'skill push',
|
|
75
|
+
'skill publish',
|
|
76
|
+
'skill delete',
|
|
77
|
+
// --target sandbox executes the stored skill via the crews MCP
|
|
78
|
+
// 'sandbox_exec' action, which runs real code with side effects on the
|
|
79
|
+
// server-managed sandbox — the same class of action as `run start`.
|
|
80
|
+
'skill exec',
|
|
81
|
+
'role push',
|
|
82
|
+
'doc push',
|
|
83
|
+
'doc upload',
|
|
84
|
+
]);
|
|
85
|
+
/** Space-joined command paths that do not mutate server state. */
|
|
86
|
+
exports.READONLY_COMMANDS = new Set([
|
|
87
|
+
'login',
|
|
88
|
+
'init',
|
|
89
|
+
'logout',
|
|
90
|
+
'whoami',
|
|
91
|
+
// Runs locally; does not touch server state for any workspace.
|
|
92
|
+
'dev',
|
|
93
|
+
'database list',
|
|
94
|
+
'database schema',
|
|
95
|
+
'database query',
|
|
96
|
+
// Downloads a dump and writes it to a local file only, like the `pull`
|
|
97
|
+
// family below — the data-plane request happens to be a POST, but no
|
|
98
|
+
// server state changes.
|
|
99
|
+
'database dump',
|
|
100
|
+
'project view',
|
|
101
|
+
'project pull',
|
|
102
|
+
'project logs',
|
|
103
|
+
'project list',
|
|
104
|
+
'workflow view',
|
|
105
|
+
'run list',
|
|
106
|
+
'run view',
|
|
107
|
+
'env list',
|
|
108
|
+
'env pull',
|
|
109
|
+
'crew env list',
|
|
110
|
+
'schedule list',
|
|
111
|
+
'webhook list',
|
|
112
|
+
'webhook secret',
|
|
113
|
+
'workspace list',
|
|
114
|
+
// Never reaches the guard at all: `workspace set` resolves through
|
|
115
|
+
// requireConfig()/requireResolvedConfig(), not requireConfigWithWorkspace(), so
|
|
116
|
+
// applyWorkspaceGuard never runs for it. Listed anyway to keep the classification
|
|
117
|
+
// complete — it writes local config, never server state.
|
|
118
|
+
'workspace set',
|
|
119
|
+
'oauth-action search',
|
|
120
|
+
'oauth-action list',
|
|
121
|
+
'oauth-action view',
|
|
122
|
+
'oauth-action platforms',
|
|
123
|
+
'connection list',
|
|
124
|
+
'ai init',
|
|
125
|
+
'ai examples',
|
|
126
|
+
'skill pull',
|
|
127
|
+
'skill list',
|
|
128
|
+
'skill view',
|
|
129
|
+
// Fetches crew variables (read) and runs the working copy locally, like
|
|
130
|
+
// `dev` — never writes server state.
|
|
131
|
+
'skill dev',
|
|
132
|
+
// Hidden deprecated alias of `skill dev` (same skillDev() function, removed
|
|
133
|
+
// in v2.0.0) — omitted from this list originally; without it the fail-safe
|
|
134
|
+
// default classified it MUTATING, which broke the alias's identical-output
|
|
135
|
+
// contract by making it print the mutating-command workspace banner (#1437).
|
|
136
|
+
'skill run',
|
|
137
|
+
'doc pull',
|
|
138
|
+
]);
|
|
139
|
+
/**
|
|
140
|
+
* True when the given commander path is a server-mutating command.
|
|
141
|
+
*
|
|
142
|
+
* A path not present in either MUTATING_COMMANDS or READONLY_COMMANDS
|
|
143
|
+
* returns true (fail safe): an unclassified command is treated as a write,
|
|
144
|
+
* so a newly-added command can never silently skip the workspace-mismatch
|
|
145
|
+
* guard.
|
|
146
|
+
*/
|
|
147
|
+
function isMutatingCommand(path) {
|
|
148
|
+
const key = path.join(' ');
|
|
149
|
+
if (exports.MUTATING_COMMANDS.has(key)) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (exports.READONLY_COMMANDS.has(key)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
let activeCommandPath = undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Set the command path from the commander `preAction` hook.
|
|
160
|
+
* Module-level state — set once at CLI startup before the command runs.
|
|
161
|
+
* Pass `undefined` to clear (used in tests).
|
|
162
|
+
*/
|
|
163
|
+
function setActiveCommandPath(path) {
|
|
164
|
+
activeCommandPath = path;
|
|
165
|
+
}
|
|
166
|
+
/** The path recorded by setActiveCommandPath, or undefined. */
|
|
167
|
+
function getActiveCommandPath() {
|
|
168
|
+
return activeCommandPath;
|
|
169
|
+
}
|
|
170
|
+
/** True when the recorded active command is mutating. False when nothing was recorded. */
|
|
171
|
+
function activeCommandIsMutating() {
|
|
172
|
+
if (activeCommandPath === undefined) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return isMutatingCommand(activeCommandPath);
|
|
176
|
+
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.sanitizeDisplayText = sanitizeDisplayText;
|
|
7
7
|
exports.formatRevisionSummary = formatRevisionSummary;
|
|
8
8
|
exports.revisionSha = revisionSha;
|
|
9
|
+
exports.formatRevisionCell = formatRevisionCell;
|
|
9
10
|
exports.formatDetailedRevision = formatDetailedRevision;
|
|
10
11
|
exports.sanitizeRemoteUrl = sanitizeRemoteUrl;
|
|
11
12
|
exports.collectSourceMetadata = collectSourceMetadata;
|
|
@@ -55,6 +56,18 @@ function revisionSha(revision) {
|
|
|
55
56
|
return sanitizeDisplayText(revision.short_sha, 16)
|
|
56
57
|
?? sanitizeDisplayText(revision.commit_sha, 64);
|
|
57
58
|
}
|
|
59
|
+
function formatRevisionCell(revision) {
|
|
60
|
+
const sha = revisionSha(revision);
|
|
61
|
+
if (!sha)
|
|
62
|
+
return '-';
|
|
63
|
+
const dirty = revision?.dirty === true ? '*' : revision?.dirty === false ? '' : '?';
|
|
64
|
+
const behind = typeof revision?.commits_behind === 'number'
|
|
65
|
+
&& Number.isSafeInteger(revision.commits_behind)
|
|
66
|
+
&& revision.commits_behind > 0
|
|
67
|
+
? ` ↓${revision.commits_behind}`
|
|
68
|
+
: '';
|
|
69
|
+
return (0, table_1.sanitizeCell)(`${sha}${dirty}${behind}`);
|
|
70
|
+
}
|
|
58
71
|
function formatDetailedRevision(revision) {
|
|
59
72
|
const sha = revisionSha(revision);
|
|
60
73
|
if (!sha)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isCwdInferredWorkspace = isCwdInferredWorkspace;
|
|
7
|
+
exports.getStateFilePath = getStateFilePath;
|
|
8
|
+
exports.readLastUsedWorkspace = readLastUsedWorkspace;
|
|
9
|
+
exports.writeLastUsedWorkspace = writeLastUsedWorkspace;
|
|
10
|
+
exports.decideWorkspaceGuard = decideWorkspaceGuard;
|
|
11
|
+
// src/utils/workspace-guard.ts
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const os_1 = __importDefault(require("os"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const STATE_DIR_NAME = '.solidactions';
|
|
16
|
+
const STATE_FILE_NAME = 'state.json';
|
|
17
|
+
/**
|
|
18
|
+
* True when the resolved workspaceId came from a project-local .solidactions/config.json
|
|
19
|
+
* discovered by walking up from the CWD — i.e. it was INFERRED from where the user happens
|
|
20
|
+
* to be standing, not stated explicitly.
|
|
21
|
+
*
|
|
22
|
+
* `sources.workspaceId` is one of:
|
|
23
|
+
* - 'cli' — the -w/--workspace-override flag -> not inferred
|
|
24
|
+
* - 'env' — SOLIDACTIONS_WORKSPACE_ID -> not inferred
|
|
25
|
+
* - the global config path -> not inferred (deliberately pinned via `workspace set`)
|
|
26
|
+
* - any OTHER filesystem path -> a project-local config found by the upward walk -> INFERRED
|
|
27
|
+
* - null -> nothing resolved -> not inferred
|
|
28
|
+
*/
|
|
29
|
+
function isCwdInferredWorkspace(sources, globalConfigPath) {
|
|
30
|
+
const source = sources.workspaceId;
|
|
31
|
+
if (source === null || source === 'cli' || source === 'env') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return path_1.default.resolve(source) !== path_1.default.resolve(globalConfigPath);
|
|
35
|
+
}
|
|
36
|
+
/** Path to the state file, given a home dir. */
|
|
37
|
+
function getStateFilePath(homeDir = os_1.default.homedir()) {
|
|
38
|
+
return path_1.default.join(homeDir, STATE_DIR_NAME, STATE_FILE_NAME);
|
|
39
|
+
}
|
|
40
|
+
/** Read the recorded last-written-to workspace. Returns null when absent, unreadable, or malformed. */
|
|
41
|
+
function readLastUsedWorkspace(homeDir = os_1.default.homedir()) {
|
|
42
|
+
const filePath = getStateFilePath(homeDir);
|
|
43
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const raw = JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
|
|
48
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (typeof raw.workspaceId !== 'string') {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return raw;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Record the workspace a command just wrote to. Callers must only invoke this for mutating
|
|
62
|
+
* commands — a read must never consume the change that gates a write confirmation. Never
|
|
63
|
+
* throws — a failure to persist must not break a command.
|
|
64
|
+
*
|
|
65
|
+
* Atomic write mirroring writeConfigFile in src/utils/config.ts: write to `<path>.tmp`, then
|
|
66
|
+
* fs.renameSync into place; create the parent dir with mode 0o700 if missing. Unlike config.json,
|
|
67
|
+
* this file holds no secret (just a workspace UUID and a cosmetic label), so it is written with
|
|
68
|
+
* the default file mode rather than 0o600.
|
|
69
|
+
*/
|
|
70
|
+
function writeLastUsedWorkspace(entry, homeDir = os_1.default.homedir()) {
|
|
71
|
+
try {
|
|
72
|
+
const filePath = getStateFilePath(homeDir);
|
|
73
|
+
const dir = path_1.default.dirname(filePath);
|
|
74
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
75
|
+
fs_1.default.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
76
|
+
}
|
|
77
|
+
const tmp = `${filePath}.tmp`;
|
|
78
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(entry, null, 2));
|
|
79
|
+
fs_1.default.renameSync(tmp, filePath);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Advisory state only — never let a persistence failure break a command.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Decision table:
|
|
87
|
+
* | condition | result |
|
|
88
|
+
* |----------------------------------------------------------------|-----------|
|
|
89
|
+
* | resolvedWorkspaceId falsy | 'none' |
|
|
90
|
+
* | cwdInferred is false | 'none' |
|
|
91
|
+
* | lastUsedWorkspaceId falsy (first run, do not nag) | 'none' |
|
|
92
|
+
* | resolved === lastUsed | 'none' |
|
|
93
|
+
* | resolved !== lastUsed, mutating false | 'warn' |
|
|
94
|
+
* | resolved !== lastUsed, mutating true | 'confirm' |
|
|
95
|
+
*/
|
|
96
|
+
function decideWorkspaceGuard(input) {
|
|
97
|
+
if (!input.resolvedWorkspaceId) {
|
|
98
|
+
return 'none';
|
|
99
|
+
}
|
|
100
|
+
if (!input.cwdInferred) {
|
|
101
|
+
return 'none';
|
|
102
|
+
}
|
|
103
|
+
if (!input.lastUsedWorkspaceId) {
|
|
104
|
+
return 'none';
|
|
105
|
+
}
|
|
106
|
+
if (input.resolvedWorkspaceId === input.lastUsedWorkspaceId) {
|
|
107
|
+
return 'none';
|
|
108
|
+
}
|
|
109
|
+
return input.mutating ? 'confirm' : 'warn';
|
|
110
|
+
}
|