@solidactions/cli 3.13.0 → 3.15.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 +70 -2
- package/dist/command-manifest.json +3 -3
- package/dist/commands/deploy.js +52 -2
- package/dist/commands/login.js +111 -48
- 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 +11 -2
- package/dist/utils/api.js +180 -12
- package/dist/utils/config.js +14 -6
- package/dist/utils/mutating-commands.js +215 -0
- package/dist/utils/source-provenance.js +13 -0
- package/dist/utils/workspace-guard.js +115 -0
- package/dist/utils/workspace-lookup.js +137 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,6 +95,7 @@ const workflow_view_1 = require("./commands/workflow-view");
|
|
|
95
95
|
const database_1 = require("./commands/database");
|
|
96
96
|
const database_push_1 = require("./commands/database-push");
|
|
97
97
|
const config_1 = require("./utils/config");
|
|
98
|
+
const mutating_commands_1 = require("./utils/mutating-commands");
|
|
98
99
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
99
100
|
const pkg = require('../package.json');
|
|
100
101
|
exports.program = new commander_1.Command();
|
|
@@ -130,8 +131,16 @@ exports.program
|
|
|
130
131
|
// a parent option of the same name, so `login --workspace <x>` was being
|
|
131
132
|
// swallowed by this global flag instead of reaching login()'s own option.
|
|
132
133
|
// The short form `-w` is unaffected and remains the primary way to use this.
|
|
133
|
-
exports.program.option('-w, --workspace-override <id-or-slug-or-name>', 'Override active workspace for this command (short form: -w)');
|
|
134
|
+
exports.program.option('-w, --workspace-override <id-or-slug-or-name>', 'Override active workspace for this command (short form: -w; also skips the CWD-inference prompt)');
|
|
134
135
|
exports.program.hook('preAction', (thisCommand, actionCommand) => {
|
|
136
|
+
// Record the full commander path (e.g. ['project', 'deploy']) unconditionally —
|
|
137
|
+
// it feeds the workspace guard in requireConfigWithWorkspace() and must never be
|
|
138
|
+
// skipped by an early return below (e.g. the `workspace set` -w warning).
|
|
139
|
+
const commandPath = [];
|
|
140
|
+
for (let cmd = actionCommand; cmd && cmd !== exports.program; cmd = cmd.parent) {
|
|
141
|
+
commandPath.unshift(cmd.name());
|
|
142
|
+
}
|
|
143
|
+
(0, mutating_commands_1.setActiveCommandPath)(commandPath, actionCommand.opts());
|
|
135
144
|
const opts = thisCommand.opts();
|
|
136
145
|
const wsOverride = opts.workspaceOverride;
|
|
137
146
|
if (wsOverride) {
|
|
@@ -485,7 +494,7 @@ runCmd
|
|
|
485
494
|
runCmd
|
|
486
495
|
.command('view')
|
|
487
496
|
.description('View details, timeline, steps, or logs for a workflow run')
|
|
488
|
-
.argument('<run-id>', 'Run ID')
|
|
497
|
+
.argument('<run-id>', 'Run ID (numeric id or run UUID)')
|
|
489
498
|
.option('--timeline', 'Show only timeline data')
|
|
490
499
|
.option('--steps', 'Show only step data')
|
|
491
500
|
.option('--logs', 'Show raw logs')
|
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,155 @@ 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 === 'warn-no-baseline') {
|
|
455
|
+
// Fresh install / fresh CI container: no state.json exists yet, so there is nothing
|
|
456
|
+
// to compare against. This warns once, on write #1, and deliberately does NOT confirm
|
|
457
|
+
// or refuse — ADR 0002 rejected "always confirm CWD-inferred writes", and refusing here
|
|
458
|
+
// would break every fresh CI runner that infers its workspace from CWD (app#1481).
|
|
459
|
+
const inferredFrom = sources.workspaceId;
|
|
460
|
+
warn(chalk_1.default.yellow('warn:') + ` about to write to ${describeWorkspace(config, sources)} `
|
|
461
|
+
+ `— inferred from ${inferredFrom}; no previously recorded workspace to compare against. `
|
|
462
|
+
+ `Pin it with -w ${config.workspaceId}.`);
|
|
463
|
+
}
|
|
464
|
+
if (action === 'confirm') {
|
|
465
|
+
// Consent to a workspace is exactly two things: stating it explicitly (-w /
|
|
466
|
+
// SOLIDACTIONS_WORKSPACE_ID, both of which make this branch unreachable), or
|
|
467
|
+
// answering the interactive prompt below. A command's OWN --yes is never
|
|
468
|
+
// workspace consent — it acknowledges that command's own destructive act
|
|
469
|
+
// (`database push` requires -y, `database pull --yes` means "overwrite the local
|
|
470
|
+
// file"), and conflating the two made the confirmation structurally unreachable
|
|
471
|
+
// on the highest-blast-radius command in the CLI (#1437).
|
|
472
|
+
if (!isTty()) {
|
|
473
|
+
warn(`re-run with -w ${config.workspaceId} to confirm the target workspace`);
|
|
474
|
+
throw new WorkspaceGuardAbort(1, 'workspace guard: refused (non-interactive)');
|
|
475
|
+
}
|
|
476
|
+
const confirmFn = io.confirm ?? (async (message) => {
|
|
477
|
+
const response = await (0, prompts_1.default)(buildWorkspaceConfirmPrompt(message));
|
|
478
|
+
return !!response.confirm;
|
|
479
|
+
});
|
|
480
|
+
const proceed = await confirmFn(`This command WRITES to ${describeWorkspace(config, sources)}. Proceed?`);
|
|
481
|
+
if (!proceed) {
|
|
482
|
+
announce(chalk_1.default.gray('Cancelled.'));
|
|
483
|
+
throw new WorkspaceGuardAbort(0, 'workspace guard: user declined');
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (options.mutating && config.workspaceId) {
|
|
487
|
+
announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)}`));
|
|
488
|
+
}
|
|
489
|
+
// state.json means "the workspace you last WROTE to" — that is precisely what the write
|
|
490
|
+
// confirmation above compares against. A read must never consume the change that gates a
|
|
491
|
+
// write, so only a mutating command records here; reads stay purely advisory.
|
|
492
|
+
if (options.mutating && config.workspaceId) {
|
|
493
|
+
(0, workspace_guard_1.writeLastUsedWorkspace)({ workspaceId: config.workspaceId, label: config.workspace, at: now().toISOString() }, io.homeDir);
|
|
494
|
+
}
|
|
495
|
+
return config;
|
|
496
|
+
}
|
|
343
497
|
async function requireConfigWithWorkspace() {
|
|
344
498
|
const resolved = requireResolvedConfig();
|
|
345
499
|
let config = resolved.config;
|
|
500
|
+
const explicitOverride = resolved.sources.workspace === 'cli';
|
|
346
501
|
// -w override path: source label 'cli' on the workspace field means
|
|
347
502
|
// setCliWorkspaceOverride was called. workspaceId was cleared by resolveConfig
|
|
348
503
|
// because we don't yet know if the input was a slug or UUID. Resolve now.
|
|
349
|
-
if (
|
|
504
|
+
if (explicitOverride && !config.workspaceId) {
|
|
350
505
|
const ws = await (0, workspace_lookup_1.resolveWorkspaceInput)(config, config.workspace);
|
|
351
|
-
config = { ...config, workspace: ws.slug ?? ws.name, workspaceId: ws.id };
|
|
352
|
-
|
|
506
|
+
config = { ...config, workspace: ws.slug ?? ws.name, workspaceId: ws.id, workspaceOrg: ws.org_name };
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
config = await ensureWorkspaceSelected(config);
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
return await applyWorkspaceGuard(config, resolved.sources, {
|
|
513
|
+
mutating: (0, mutating_commands_1.activeCommandIsMutating)(),
|
|
514
|
+
explicitOverride,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
if (error instanceof WorkspaceGuardAbort) {
|
|
519
|
+
process.exit(error.exitCode);
|
|
520
|
+
}
|
|
521
|
+
throw error;
|
|
353
522
|
}
|
|
354
|
-
return ensureWorkspaceSelected(config);
|
|
355
523
|
}
|
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,215 @@
|
|
|
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, by default — it does not see
|
|
20
|
+
* flags. Over-inclusion is the intended bias for anything not explicitly
|
|
21
|
+
* refined below: the workspace-mismatch guard this file feeds only prompts
|
|
22
|
+
* when the resolved workspace ALSO changed and was CWD-inferred, so
|
|
23
|
+
* classifying a mostly-read command as MUTATING costs at most one extra
|
|
24
|
+
* confirmation, whereas the reverse can silently write to the wrong
|
|
25
|
+
* workspace.
|
|
26
|
+
*
|
|
27
|
+
* FLAG_SENSITIVE_COMMANDS below is a narrow, deliberate refinement layer on
|
|
28
|
+
* top of that path-only answer: a handful of leaves genuinely change from
|
|
29
|
+
* read to write depending on a flag (e.g. `database pull --writable`, which
|
|
30
|
+
* opens a live write REPL instead of just writing a local file). Those
|
|
31
|
+
* leaves stay listed in MUTATING_COMMANDS — the conservative, path-only
|
|
32
|
+
* fail-safe — and isMutatingCommand() only consults the flag predicate when
|
|
33
|
+
* it is given actual options to check; called with no options, or for a
|
|
34
|
+
* path that has no entry in the table, it falls straight through to the
|
|
35
|
+
* path-only answer above.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.FLAG_SENSITIVE_COMMANDS = exports.READONLY_COMMANDS = exports.MUTATING_COMMANDS = void 0;
|
|
39
|
+
exports.isMutatingCommand = isMutatingCommand;
|
|
40
|
+
exports.setActiveCommandPath = setActiveCommandPath;
|
|
41
|
+
exports.getActiveCommandPath = getActiveCommandPath;
|
|
42
|
+
exports.getActiveCommandOptions = getActiveCommandOptions;
|
|
43
|
+
exports.activeCommandIsMutating = activeCommandIsMutating;
|
|
44
|
+
/** Space-joined command paths that mutate SERVER state, e.g. 'project deploy'. */
|
|
45
|
+
exports.MUTATING_COMMANDS = new Set([
|
|
46
|
+
'database create',
|
|
47
|
+
'database delete',
|
|
48
|
+
'database undelete',
|
|
49
|
+
'database exec',
|
|
50
|
+
'database import',
|
|
51
|
+
'database push',
|
|
52
|
+
// Plain `database pull` is read-only (GET, writes a local file only —
|
|
53
|
+
// same family as project/env/doc/skill pull). But `--writable`
|
|
54
|
+
// (databaseWritablePullWithConfig, src/commands/database.ts:1320) mints
|
|
55
|
+
// a WRITE-mode credential and opens a live interactive SQL REPL that
|
|
56
|
+
// executes real statements (client.execute/executeMultiple, ~lines
|
|
57
|
+
// 1540-1560) against the server-backed replica. This is the path-only
|
|
58
|
+
// fail-safe answer (kept for callers that don't pass options, and for
|
|
59
|
+
// completeness/disjointness); FLAG_SENSITIVE_COMMANDS below refines it
|
|
60
|
+
// to the exact `--writable` boundary when options are available.
|
|
61
|
+
'database pull',
|
|
62
|
+
'project create',
|
|
63
|
+
'project deploy',
|
|
64
|
+
'project enable',
|
|
65
|
+
'project disable',
|
|
66
|
+
'workflow enable',
|
|
67
|
+
'workflow disable',
|
|
68
|
+
'run start',
|
|
69
|
+
'env set',
|
|
70
|
+
'env delete',
|
|
71
|
+
'env reset',
|
|
72
|
+
'env map',
|
|
73
|
+
'env push',
|
|
74
|
+
'crew env set',
|
|
75
|
+
'crew env map-database',
|
|
76
|
+
'crew env delete',
|
|
77
|
+
'crew env push',
|
|
78
|
+
'schedule set',
|
|
79
|
+
'schedule enable',
|
|
80
|
+
'schedule disable',
|
|
81
|
+
'schedule reset',
|
|
82
|
+
'schedule delete',
|
|
83
|
+
'skill push',
|
|
84
|
+
'skill publish',
|
|
85
|
+
'skill delete',
|
|
86
|
+
// --target sandbox executes the stored skill via the crews MCP
|
|
87
|
+
// 'sandbox_exec' action, which runs real code with side effects on the
|
|
88
|
+
// server-managed sandbox — the same class of action as `run start`.
|
|
89
|
+
'skill exec',
|
|
90
|
+
'role push',
|
|
91
|
+
'doc push',
|
|
92
|
+
'doc upload',
|
|
93
|
+
]);
|
|
94
|
+
/** Space-joined command paths that do not mutate server state. */
|
|
95
|
+
exports.READONLY_COMMANDS = new Set([
|
|
96
|
+
'login',
|
|
97
|
+
'init',
|
|
98
|
+
'logout',
|
|
99
|
+
'whoami',
|
|
100
|
+
// Runs locally; does not touch server state for any workspace.
|
|
101
|
+
'dev',
|
|
102
|
+
'database list',
|
|
103
|
+
'database schema',
|
|
104
|
+
'database query',
|
|
105
|
+
// Downloads a dump and writes it to a local file only, like the `pull`
|
|
106
|
+
// family below — the data-plane request happens to be a POST, but no
|
|
107
|
+
// server state changes.
|
|
108
|
+
'database dump',
|
|
109
|
+
'project view',
|
|
110
|
+
'project pull',
|
|
111
|
+
'project logs',
|
|
112
|
+
'project list',
|
|
113
|
+
'workflow view',
|
|
114
|
+
'run list',
|
|
115
|
+
'run view',
|
|
116
|
+
'env list',
|
|
117
|
+
'env pull',
|
|
118
|
+
'crew env list',
|
|
119
|
+
'schedule list',
|
|
120
|
+
'webhook list',
|
|
121
|
+
'webhook secret',
|
|
122
|
+
'workspace list',
|
|
123
|
+
// Never reaches the guard at all: `workspace set` resolves through
|
|
124
|
+
// requireConfig()/requireResolvedConfig(), not requireConfigWithWorkspace(), so
|
|
125
|
+
// applyWorkspaceGuard never runs for it. Listed anyway to keep the classification
|
|
126
|
+
// complete — it writes local config, never server state.
|
|
127
|
+
'workspace set',
|
|
128
|
+
'oauth-action search',
|
|
129
|
+
'oauth-action list',
|
|
130
|
+
'oauth-action view',
|
|
131
|
+
'oauth-action platforms',
|
|
132
|
+
'connection list',
|
|
133
|
+
'ai init',
|
|
134
|
+
'ai examples',
|
|
135
|
+
'skill pull',
|
|
136
|
+
'skill list',
|
|
137
|
+
'skill view',
|
|
138
|
+
// Fetches crew variables (read) and runs the working copy locally, like
|
|
139
|
+
// `dev` — never writes server state.
|
|
140
|
+
'skill dev',
|
|
141
|
+
// Hidden deprecated alias of `skill dev` (same skillDev() function, removed
|
|
142
|
+
// in v2.0.0) — omitted from this list originally; without it the fail-safe
|
|
143
|
+
// default classified it MUTATING, which broke the alias's identical-output
|
|
144
|
+
// contract by making it print the mutating-command workspace banner (#1437).
|
|
145
|
+
'skill run',
|
|
146
|
+
'doc pull',
|
|
147
|
+
]);
|
|
148
|
+
/**
|
|
149
|
+
* Command paths whose read/write nature depends on a flag rather than being
|
|
150
|
+
* fixed by path alone. Each predicate takes the leaf command's own parsed
|
|
151
|
+
* options and returns true when that flag combination makes the command a
|
|
152
|
+
* SERVER WRITE. This table is a deliberate hole in the path-only fail-safe
|
|
153
|
+
* above — keep it tiny, and keep the corresponding leaf in MUTATING_COMMANDS
|
|
154
|
+
* so any caller that can't supply options still gets the conservative
|
|
155
|
+
* answer.
|
|
156
|
+
*/
|
|
157
|
+
exports.FLAG_SENSITIVE_COMMANDS = new Map([
|
|
158
|
+
['database pull', (options) => options.writable === true],
|
|
159
|
+
]);
|
|
160
|
+
/**
|
|
161
|
+
* True when the given commander path is a server-mutating command.
|
|
162
|
+
*
|
|
163
|
+
* When `options` is supplied and the path has an entry in
|
|
164
|
+
* FLAG_SENSITIVE_COMMANDS, that entry's predicate decides the answer
|
|
165
|
+
* exactly — this is the only way a `database pull` without `--writable` is
|
|
166
|
+
* classified as read-only. Without options (the caller didn't observe any
|
|
167
|
+
* flags, or the path isn't flag-sensitive), classification falls through to
|
|
168
|
+
* the path-only tables: a path not present in either MUTATING_COMMANDS or
|
|
169
|
+
* READONLY_COMMANDS returns true (fail safe) — an unclassified command is
|
|
170
|
+
* treated as a write, so a newly-added command can never silently skip the
|
|
171
|
+
* workspace-mismatch guard, and an unobserved-flags lookup never guesses
|
|
172
|
+
* read from absence.
|
|
173
|
+
*/
|
|
174
|
+
function isMutatingCommand(path, options) {
|
|
175
|
+
const key = path.join(' ');
|
|
176
|
+
if (options !== undefined) {
|
|
177
|
+
const predicate = exports.FLAG_SENSITIVE_COMMANDS.get(key);
|
|
178
|
+
if (predicate) {
|
|
179
|
+
return predicate(options);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (exports.MUTATING_COMMANDS.has(key)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (exports.READONLY_COMMANDS.has(key)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
let activeCommandPath = undefined;
|
|
191
|
+
let activeCommandOptions = undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Set the command path (and its own parsed options) from the commander
|
|
194
|
+
* `preAction` hook. Module-level state — set once at CLI startup before the
|
|
195
|
+
* command runs. Pass `undefined` for both to clear (used in tests).
|
|
196
|
+
*/
|
|
197
|
+
function setActiveCommandPath(path, options) {
|
|
198
|
+
activeCommandPath = path;
|
|
199
|
+
activeCommandOptions = path === undefined ? undefined : options;
|
|
200
|
+
}
|
|
201
|
+
/** The path recorded by setActiveCommandPath, or undefined. */
|
|
202
|
+
function getActiveCommandPath() {
|
|
203
|
+
return activeCommandPath;
|
|
204
|
+
}
|
|
205
|
+
/** The options recorded by setActiveCommandPath, or undefined. */
|
|
206
|
+
function getActiveCommandOptions() {
|
|
207
|
+
return activeCommandOptions;
|
|
208
|
+
}
|
|
209
|
+
/** True when the recorded active command is mutating. False when nothing was recorded. */
|
|
210
|
+
function activeCommandIsMutating() {
|
|
211
|
+
if (activeCommandPath === undefined) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return isMutatingCommand(activeCommandPath, activeCommandOptions);
|
|
215
|
+
}
|
|
@@ -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)
|