@solidactions/cli 3.14.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 +12 -0
- package/dist/command-manifest.json +1 -1
- package/dist/commands/login.js +6 -11
- package/dist/index.js +1 -1
- package/dist/utils/api.js +10 -0
- package/dist/utils/mutating-commands.js +59 -20
- package/dist/utils/workspace-guard.js +14 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -169,6 +169,18 @@ CWD-inferred workspace differs from that last-written-to one, the CLI warns:
|
|
|
169
169
|
warn: workspace changed to <name> — organization <org> (<workspaceId>) — inferred from <path>; last used was <last-used-name-or-id>. Pin it with -w <workspaceId>.
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
+
On a fresh install (or a fresh CI container) there's no `state.json` yet, so a CWD-inferred
|
|
173
|
+
write has nothing to compare against. A **write** in that case still warns — once, on that
|
|
174
|
+
first write — even though nothing has "changed":
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
warn: about to write to <name> — organization <org> (<workspaceId>) — inferred from <path>; no previously recorded workspace to compare against. Pin it with -w <workspaceId>.
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This warns and proceeds; it never confirms or refuses. That first write records `state.json`,
|
|
181
|
+
so this line cannot fire again — from then on there is a baseline, and a later CWD-inferred
|
|
182
|
+
write against a *different* workspace gets the `workspace changed to …` treatment above.
|
|
183
|
+
|
|
172
184
|
For commands that **write** to the server, it also asks for confirmation before proceeding:
|
|
173
185
|
|
|
174
186
|
```
|
package/dist/commands/login.js
CHANGED
|
@@ -307,17 +307,12 @@ async function completeLogin(config, workspaces, options, scope = null, prefligh
|
|
|
307
307
|
config.workspace = match.slug ?? match.name;
|
|
308
308
|
config.workspaceId = match.id;
|
|
309
309
|
}
|
|
310
|
-
else if (workspaces.length
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
else if (workspaces.length === 0) {
|
|
317
|
-
console.log(chalk_1.default.yellow('No workspaces found. Create one at your SolidActions dashboard, then '
|
|
318
|
-
+ 'run `solidactions workspace set <name>`.'));
|
|
319
|
-
}
|
|
320
|
-
else if (process.stdin.isTTY) {
|
|
310
|
+
else if (workspaces.length <= 1 || process.stdin.isTTY) {
|
|
311
|
+
// 0 and 1 workspace need no interactive prompt, but their status copy
|
|
312
|
+
// ("No workspaces found."/"Auto-selected workspace:") already lives in
|
|
313
|
+
// selectWorkspaceInteractively (cli#137, on stderr) — route them
|
|
314
|
+
// through it too so those strings have exactly one call site instead
|
|
315
|
+
// of a stdout duplicate here (app#1482).
|
|
321
316
|
const selectWorkspace = dependencies.selectWorkspace ?? workspace_lookup_1.selectWorkspaceInteractively;
|
|
322
317
|
const selected = await selectWorkspace(workspaces);
|
|
323
318
|
if (selected) {
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ exports.program.hook('preAction', (thisCommand, actionCommand) => {
|
|
|
140
140
|
for (let cmd = actionCommand; cmd && cmd !== exports.program; cmd = cmd.parent) {
|
|
141
141
|
commandPath.unshift(cmd.name());
|
|
142
142
|
}
|
|
143
|
-
(0, mutating_commands_1.setActiveCommandPath)(commandPath);
|
|
143
|
+
(0, mutating_commands_1.setActiveCommandPath)(commandPath, actionCommand.opts());
|
|
144
144
|
const opts = thisCommand.opts();
|
|
145
145
|
const wsOverride = opts.workspaceOverride;
|
|
146
146
|
if (wsOverride) {
|
package/dist/utils/api.js
CHANGED
|
@@ -451,6 +451,16 @@ async function applyWorkspaceGuard(config, sources, options, io = {}) {
|
|
|
451
451
|
+ `— inferred from ${inferredFrom}; last used was ${lastLabel}. `
|
|
452
452
|
+ `Pin it with -w ${config.workspaceId}.`);
|
|
453
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
|
+
}
|
|
454
464
|
if (action === 'confirm') {
|
|
455
465
|
// Consent to a workspace is exactly two things: stating it explicitly (-w /
|
|
456
466
|
// SOLIDACTIONS_WORKSPACE_ID, both of which make this branch unreachable), or
|
|
@@ -16,21 +16,30 @@
|
|
|
16
16
|
* `action` argument instead of the outer HTTP verb ('list'/'read' = read,
|
|
17
17
|
* 'create'/'edit'/'delete'/'take_snapshot'/'sandbox_exec' = write).
|
|
18
18
|
*
|
|
19
|
-
* Classification is per command PATH only — it does not see
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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
|
|
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
|
|
24
22
|
* when the resolved workspace ALSO changed and was CWD-inferred, so
|
|
25
23
|
* classifying a mostly-read command as MUTATING costs at most one extra
|
|
26
24
|
* confirmation, whereas the reverse can silently write to the wrong
|
|
27
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.
|
|
28
36
|
*/
|
|
29
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.READONLY_COMMANDS = exports.MUTATING_COMMANDS = void 0;
|
|
38
|
+
exports.FLAG_SENSITIVE_COMMANDS = exports.READONLY_COMMANDS = exports.MUTATING_COMMANDS = void 0;
|
|
31
39
|
exports.isMutatingCommand = isMutatingCommand;
|
|
32
40
|
exports.setActiveCommandPath = setActiveCommandPath;
|
|
33
41
|
exports.getActiveCommandPath = getActiveCommandPath;
|
|
42
|
+
exports.getActiveCommandOptions = getActiveCommandOptions;
|
|
34
43
|
exports.activeCommandIsMutating = activeCommandIsMutating;
|
|
35
44
|
/** Space-joined command paths that mutate SERVER state, e.g. 'project deploy'. */
|
|
36
45
|
exports.MUTATING_COMMANDS = new Set([
|
|
@@ -45,10 +54,10 @@ exports.MUTATING_COMMANDS = new Set([
|
|
|
45
54
|
// (databaseWritablePullWithConfig, src/commands/database.ts:1320) mints
|
|
46
55
|
// a WRITE-mode credential and opens a live interactive SQL REPL that
|
|
47
56
|
// executes real statements (client.execute/executeMultiple, ~lines
|
|
48
|
-
// 1540-1560) against the server-backed replica.
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
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.
|
|
52
61
|
'database pull',
|
|
53
62
|
'project create',
|
|
54
63
|
'project deploy',
|
|
@@ -136,16 +145,40 @@ exports.READONLY_COMMANDS = new Set([
|
|
|
136
145
|
'skill run',
|
|
137
146
|
'doc pull',
|
|
138
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
|
+
]);
|
|
139
160
|
/**
|
|
140
161
|
* True when the given commander path is a server-mutating command.
|
|
141
162
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
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.
|
|
146
173
|
*/
|
|
147
|
-
function isMutatingCommand(path) {
|
|
174
|
+
function isMutatingCommand(path, options) {
|
|
148
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
|
+
}
|
|
149
182
|
if (exports.MUTATING_COMMANDS.has(key)) {
|
|
150
183
|
return true;
|
|
151
184
|
}
|
|
@@ -155,22 +188,28 @@ function isMutatingCommand(path) {
|
|
|
155
188
|
return true;
|
|
156
189
|
}
|
|
157
190
|
let activeCommandPath = undefined;
|
|
191
|
+
let activeCommandOptions = undefined;
|
|
158
192
|
/**
|
|
159
|
-
* Set the command path from the commander
|
|
160
|
-
* Module-level state — set once at CLI startup before the
|
|
161
|
-
* Pass `undefined` to clear (used in tests).
|
|
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).
|
|
162
196
|
*/
|
|
163
|
-
function setActiveCommandPath(path) {
|
|
197
|
+
function setActiveCommandPath(path, options) {
|
|
164
198
|
activeCommandPath = path;
|
|
199
|
+
activeCommandOptions = path === undefined ? undefined : options;
|
|
165
200
|
}
|
|
166
201
|
/** The path recorded by setActiveCommandPath, or undefined. */
|
|
167
202
|
function getActiveCommandPath() {
|
|
168
203
|
return activeCommandPath;
|
|
169
204
|
}
|
|
205
|
+
/** The options recorded by setActiveCommandPath, or undefined. */
|
|
206
|
+
function getActiveCommandOptions() {
|
|
207
|
+
return activeCommandOptions;
|
|
208
|
+
}
|
|
170
209
|
/** True when the recorded active command is mutating. False when nothing was recorded. */
|
|
171
210
|
function activeCommandIsMutating() {
|
|
172
211
|
if (activeCommandPath === undefined) {
|
|
173
212
|
return false;
|
|
174
213
|
}
|
|
175
|
-
return isMutatingCommand(activeCommandPath);
|
|
214
|
+
return isMutatingCommand(activeCommandPath, activeCommandOptions);
|
|
176
215
|
}
|
|
@@ -84,14 +84,15 @@ function writeLastUsedWorkspace(entry, homeDir = os_1.default.homedir()) {
|
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Decision table:
|
|
87
|
-
* | condition | result
|
|
88
|
-
*
|
|
89
|
-
* | resolvedWorkspaceId falsy | 'none'
|
|
90
|
-
* | cwdInferred is false | 'none'
|
|
91
|
-
* | lastUsedWorkspaceId falsy (
|
|
92
|
-
* |
|
|
93
|
-
* | resolved
|
|
94
|
-
* | resolved !== lastUsed, mutating
|
|
87
|
+
* | condition | result |
|
|
88
|
+
* |------------------------------------------------------------------|--------------------|
|
|
89
|
+
* | resolvedWorkspaceId falsy | 'none' |
|
|
90
|
+
* | cwdInferred is false | 'none' |
|
|
91
|
+
* | lastUsedWorkspaceId falsy, mutating true (fresh install, first write) | 'warn-no-baseline' |
|
|
92
|
+
* | lastUsedWorkspaceId falsy, mutating false (reads stay frictionless) | 'none' |
|
|
93
|
+
* | resolved === lastUsed | 'none' |
|
|
94
|
+
* | resolved !== lastUsed, mutating false | 'warn' |
|
|
95
|
+
* | resolved !== lastUsed, mutating true | 'confirm' |
|
|
95
96
|
*/
|
|
96
97
|
function decideWorkspaceGuard(input) {
|
|
97
98
|
if (!input.resolvedWorkspaceId) {
|
|
@@ -101,7 +102,11 @@ function decideWorkspaceGuard(input) {
|
|
|
101
102
|
return 'none';
|
|
102
103
|
}
|
|
103
104
|
if (!input.lastUsedWorkspaceId) {
|
|
104
|
-
|
|
105
|
+
// Deliberate: readLastUsedWorkspace() returns null for an absent state.json AND for
|
|
106
|
+
// an unreadable/malformed one. Both mean "no baseline to compare against" — an
|
|
107
|
+
// unreadable baseline is an unknown baseline, not a known-safe one — so both take
|
|
108
|
+
// the same conservative branch: warn on a write rather than silently confirming.
|
|
109
|
+
return input.mutating ? 'warn-no-baseline' : 'none';
|
|
105
110
|
}
|
|
106
111
|
if (input.resolvedWorkspaceId === input.lastUsedWorkspaceId) {
|
|
107
112
|
return 'none';
|