@solidactions/cli 3.20.1 → 3.22.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.
Files changed (53) hide show
  1. package/README.md +12 -6
  2. package/dist/command-manifest.json +18 -7
  3. package/dist/commands/connection-list.js +2 -2
  4. package/dist/commands/crew-env-delete.js +2 -2
  5. package/dist/commands/crew-env-list.js +2 -2
  6. package/dist/commands/crew-env-push.js +5 -2
  7. package/dist/commands/crew-env-set.js +2 -2
  8. package/dist/commands/database-push.js +1 -1
  9. package/dist/commands/deploy.js +41 -12
  10. package/dist/commands/dev.js +4 -4
  11. package/dist/commands/doc-pull.js +531 -73
  12. package/dist/commands/doc-push.js +291 -28
  13. package/dist/commands/doc-upload.js +5 -2
  14. package/dist/commands/env-delete.js +12 -5
  15. package/dist/commands/env-list.js +19 -14
  16. package/dist/commands/env-map.js +7 -5
  17. package/dist/commands/env-pull.js +5 -6
  18. package/dist/commands/env-push.js +10 -6
  19. package/dist/commands/env-reset.js +12 -8
  20. package/dist/commands/env-set.js +15 -11
  21. package/dist/commands/init.js +4 -1
  22. package/dist/commands/login.js +15 -18
  23. package/dist/commands/oauth-action-list.js +2 -2
  24. package/dist/commands/oauth-action-platforms.js +2 -2
  25. package/dist/commands/oauth-action-search.js +2 -2
  26. package/dist/commands/oauth-action-view.js +2 -2
  27. package/dist/commands/project-create.js +1 -1
  28. package/dist/commands/project-list.js +2 -2
  29. package/dist/commands/project-logs.js +7 -3
  30. package/dist/commands/project-view.js +26 -9
  31. package/dist/commands/pull.js +4 -2
  32. package/dist/commands/run-list.js +27 -22
  33. package/dist/commands/run-start.js +22 -18
  34. package/dist/commands/run-view.js +10 -22
  35. package/dist/commands/schedule-delete.js +5 -10
  36. package/dist/commands/schedule-list.js +5 -10
  37. package/dist/commands/schedule-set.js +39 -44
  38. package/dist/commands/schedule-state.js +12 -16
  39. package/dist/commands/state.js +3 -3
  40. package/dist/commands/webhook-list.js +12 -4
  41. package/dist/commands/webhook-secret.js +12 -4
  42. package/dist/commands/workflow-view.js +3 -3
  43. package/dist/commands/workspaces.js +58 -3
  44. package/dist/index.js +13 -7
  45. package/dist/utils/api.js +69 -4
  46. package/dist/utils/config.js +96 -3
  47. package/dist/utils/crew.js +6 -1
  48. package/dist/utils/mcp.js +7 -3
  49. package/dist/utils/project-ref.js +91 -0
  50. package/dist/utils/run-status.js +61 -0
  51. package/dist/utils/secure-write.js +40 -5
  52. package/dist/utils/workspace-lookup.js +30 -3
  53. package/package.json +2 -2
@@ -11,7 +11,8 @@ const config_1 = require("../utils/config");
11
11
  const config_write_target_1 = require("../utils/config-write-target");
12
12
  const workspace_lookup_1 = require("../utils/workspace-lookup");
13
13
  async function workspacesList() {
14
- const config = (0, api_1.requireConfig)();
14
+ const resolved = (0, api_1.requireResolvedConfig)();
15
+ const config = resolved.config;
15
16
  // Grouping keys are tenant ids (app#1214), so the org header and the
16
17
  // same-name disambiguation both come from per-row tenant data, never
17
18
  // from the key.
@@ -20,12 +21,21 @@ async function workspacesList() {
20
21
  ({ workspaces } = await (0, workspace_lookup_1.fetchWorkspaces)(config));
21
22
  }
22
23
  catch (error) {
23
- console.error(chalk_1.default.red('Failed to list workspaces:'), error.response?.data?.message || error.message);
24
+ if (error.response?.status === 401) {
25
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
26
+ }
27
+ else if (error.response) {
28
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
29
+ }
30
+ else {
31
+ console.error(chalk_1.default.red('Connection failed:'), error.message);
32
+ }
24
33
  process.exit(1);
25
34
  }
26
35
  console.log(chalk_1.default.blue(`\nYour workspaces:\n`));
27
36
  if (workspaces.length === 0) {
28
37
  console.log(chalk_1.default.yellow('No workspaces found.'));
38
+ warnDanglingPin(config.workspace, config.workspaceId, resolved.sources.workspaceId, true);
29
39
  return;
30
40
  }
31
41
  for (const group of (0, workspace_lookup_1.groupWorkspacesByOrg)(workspaces)) {
@@ -39,7 +49,48 @@ async function workspacesList() {
39
49
  console.log(chalk_1.default.gray(` ID: ${ws.id}`));
40
50
  }
41
51
  }
52
+ // cli#113: a pin the list doesn't contain gets no "← current" — say so instead of looking normal.
53
+ if (config.workspaceId && !workspaces.some((ws) => ws.id === config.workspaceId)) {
54
+ warnDanglingPin(config.workspace, config.workspaceId, resolved.sources.workspaceId, false);
55
+ }
56
+ console.log('');
57
+ }
58
+ /**
59
+ * Warn about a pinned workspace the server's list does not contain (cli#113).
60
+ * Runs against an empty list too: losing access to every workspace is exactly
61
+ * the lost-access case, so the pin is evaluated rather than skipped. With
62
+ * nothing listed there is nothing to pick from, so the remedy says how to
63
+ * clear or change the pin instead of pointing at the list.
64
+ */
65
+ function warnDanglingPin(workspace, workspaceId, workspaceIdSource, emptyList) {
66
+ if (!workspaceId)
67
+ return;
68
+ const label = workspace ? `${workspace} (${workspaceId})` : workspaceId;
69
+ const from = workspaceIdSource === 'env'
70
+ ? '$SOLIDACTIONS_WORKSPACE_ID'
71
+ : workspaceIdSource === 'cli'
72
+ ? 'the -w/--workspace-override flag'
73
+ : workspaceIdSource;
42
74
  console.log('');
75
+ console.log(chalk_1.default.yellow(`warn: the active workspace ${label} (from ${from}) is not in this list — it may belong to another host, or you may no longer have access.`));
76
+ if (workspaceIdSource === 'env') {
77
+ // `workspace set` refuses while $SOLIDACTIONS_WORKSPACE_ID is set, list or no list.
78
+ console.log(chalk_1.default.yellow(`Unset $SOLIDACTIONS_WORKSPACE_ID, then select a workspace with \`solidactions workspace set <slug>\`${emptyList ? ' once `workspace list` shows one' : ''}.`));
79
+ }
80
+ else if (emptyList) {
81
+ // `workspace set` resolves an accessible workspace first, so it cannot
82
+ // clear or change a pin when the list is empty: name the action that
83
+ // applies to where this pin came from instead.
84
+ if (workspaceIdSource === 'cli') {
85
+ console.log(chalk_1.default.yellow('Re-run without -w/--workspace-override, then select a workspace with `solidactions workspace set <slug>` once `workspace list` shows one.'));
86
+ }
87
+ else {
88
+ console.log(chalk_1.default.yellow(`Remove the workspace pin (workspaceId and related keys) from ${from}, then select a workspace with \`solidactions workspace set <slug>\` once \`workspace list\` shows one.`));
89
+ }
90
+ }
91
+ else {
92
+ console.log(chalk_1.default.yellow('Pick one from the list with `solidactions workspace set <slug> --local` (or --global).'));
93
+ }
43
94
  }
44
95
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
45
96
  function looksLikeUuid(input) {
@@ -71,6 +122,10 @@ async function workspaceSet(input, options = {}) {
71
122
  if (target === 'local') {
72
123
  await (0, config_write_target_1.ensureGitignoreCovers)(process.cwd(), !!options.gitignore);
73
124
  }
74
- console.log(chalk_1.default.green(`Workspace set to: ${(0, workspace_lookup_1.formatWorkspaceWithOrg)(workspace)} (${workspace.id})`));
125
+ // Lead with org AND slug: "Main" can be three different workspaces (cli#112).
126
+ const label = workspace.slug
127
+ ? `${(0, workspace_lookup_1.formatWorkspaceWithOrg)(workspace)}, slug ${workspace.slug}`
128
+ : (0, workspace_lookup_1.formatWorkspaceWithOrg)(workspace);
129
+ console.log(chalk_1.default.green(`Workspace set to: ${label} (${workspace.id})`));
75
130
  console.log(chalk_1.default.gray(`Saved to ${targetPath}`));
76
131
  }
package/dist/index.js CHANGED
@@ -104,12 +104,14 @@ const pkg = require('../package.json');
104
104
  exports.program = new commander_1.Command();
105
105
  if (process.env.SOLIDACTIONS_DEBUG === '1') {
106
106
  // eslint-disable-next-line @typescript-eslint/no-var-requires
107
- const { resolveConfig } = require('./utils/config');
107
+ const { resolveConfig, credentialConflictMessage } = require('./utils/config');
108
108
  const resolved = resolveConfig();
109
109
  if (resolved) {
110
110
  const fmt = (src) => {
111
111
  if (src === 'env')
112
112
  return '(from $SOLIDACTIONS_* env var)';
113
+ if (src === 'default')
114
+ return '(default)';
113
115
  if (src === null)
114
116
  return '(unset)';
115
117
  return `(from ${src})`;
@@ -119,6 +121,9 @@ if (process.env.SOLIDACTIONS_DEBUG === '1') {
119
121
  process.stderr.write(` apiKey: <redacted> ${fmt(resolved.sources.apiKey)}\n`);
120
122
  process.stderr.write(` workspaceId: ${resolved.config.workspaceId ?? ''} ${fmt(resolved.sources.workspaceId)}\n`);
121
123
  process.stderr.write(` activePath: ${resolved.activePath}\n`);
124
+ if (resolved.credentialConflict) {
125
+ process.stderr.write(` credentials: REFUSED — ${credentialConflictMessage(resolved.credentialConflict).split('\n')[0]}\n`);
126
+ }
122
127
  }
123
128
  else {
124
129
  process.stderr.write('[SOLIDACTIONS_DEBUG] no config resolvable\n');
@@ -1045,16 +1050,17 @@ role
1045
1050
  const doc = exports.program.command('doc').description('Manage docs in SA-Docs');
1046
1051
  doc
1047
1052
  .command('push')
1048
- .description('Recursively upload a local markdown tree into SA-Docs')
1049
- .argument('<dir>', 'Path to the directory containing markdown files')
1050
- .option('--on-conflict <mode>', 'Conflict resolution: skip|overwrite|rename (default: skip)', 'skip')
1051
- .option('--type <slug>', 'Doc-type slug to apply to all uploaded docs')
1053
+ .description('Upload docs from local files into SA-Docs: .md as markdown, .html as a visual doc, .canvas.json / .canvas as a canvas')
1054
+ .argument('<path>', 'A directory of .md / .html / .canvas.json / .canvas files (walked recursively), or one such file')
1055
+ .option('--on-conflict <mode>', 'Conflict resolution: skip|overwrite|rename (default: skip)')
1056
+ .option('--type <slug>', 'Doc-type slug to apply to all uploaded docs (.html and canvas files keep visual / canvas)')
1052
1057
  .option('--folder <base>', 'Nest the whole upload under this base folder path in SA-Docs')
1058
+ .option('--replace <doc-id>', 'Replace the body of an existing doc (numeric id) with a single file of the same kind')
1053
1059
  .option('--dry-run', 'Preview what would be created without writing')
1054
1060
  .option('--force', 'Overwrite tracked docs (from a prior doc pull) without a base-revision drift guard')
1055
1061
  .option('--json', 'Output result as JSON')
1056
- .action(async (dir, options) => {
1057
- await (0, doc_push_1.docPush)(dir, { onConflict: options.onConflict, type: options.type, folder: options.folder, dryRun: options.dryRun, force: options.force, json: options.json });
1062
+ .action(async (target, options) => {
1063
+ await (0, doc_push_1.docPush)(target, { onConflict: options.onConflict, type: options.type, folder: options.folder, replace: options.replace, dryRun: options.dryRun, force: options.force, json: options.json });
1058
1064
  });
1059
1065
  doc
1060
1066
  .command('pull')
package/dist/utils/api.js CHANGED
@@ -15,17 +15,22 @@ exports.describeProjectEnvironments = describeProjectEnvironments;
15
15
  exports.formatValidationError = formatValidationError;
16
16
  exports.requireResolvedConfig = requireResolvedConfig;
17
17
  exports.requireConfig = requireConfig;
18
+ exports.displayHost = displayHost;
18
19
  exports.authFailureMessage = authFailureMessage;
20
+ exports.formatApiFailure = formatApiFailure;
21
+ exports.authFailedLine = authFailedLine;
19
22
  exports.ensureWorkspaceSelected = ensureWorkspaceSelected;
20
23
  exports.buildWorkspaceConfirmPrompt = buildWorkspaceConfirmPrompt;
21
24
  exports.applyWorkspaceGuard = applyWorkspaceGuard;
22
25
  exports.requireConfigWithWorkspace = requireConfigWithWorkspace;
23
26
  const axios_1 = __importDefault(require("axios"));
24
27
  const chalk_1 = __importDefault(require("chalk"));
28
+ const path_1 = __importDefault(require("path"));
25
29
  const prompts_1 = __importDefault(require("prompts"));
26
30
  const config_1 = require("./config");
27
31
  const workspace_lookup_1 = require("./workspace-lookup");
28
32
  const mutating_commands_1 = require("./mutating-commands");
33
+ const project_ref_1 = require("./project-ref");
29
34
  const workspace_guard_1 = require("./workspace-guard");
30
35
  // Backend (solidactions-app PR #128) returns: "Project '<slug>' not found in your active workspace '<workspace-slug>'."
31
36
  // We require the literal single-quotes around the slug so plausible future error messages
@@ -202,7 +207,13 @@ async function lookupProjectFamilyEnvironments(config, projectName) {
202
207
  try {
203
208
  const res = await axios_1.default.get(`${config.host}/api/v1/projects`, { headers: getApiHeaders(config) });
204
209
  const rows = res.data?.data ?? res.data ?? [];
205
- const hit = rows.find((p) => p.name === projectName || p.slug === projectName);
210
+ // The same rungs `run list` retries with (cli#161): an ambiguous
211
+ // case-insensitive match yields no hint rather than a guess.
212
+ const match = (0, project_ref_1.matchProjectRungs)(rows, projectName);
213
+ if (match.ambiguous.length > 0) {
214
+ return null;
215
+ }
216
+ const hit = match.project;
206
217
  const environments = hit?.environments;
207
218
  if (!environments?.length) {
208
219
  return null;
@@ -276,6 +287,10 @@ function formatValidationError(data) {
276
287
  */
277
288
  function requireResolvedConfig() {
278
289
  const resolved = (0, config_1.resolveConfig)();
290
+ if (resolved?.credentialConflict) {
291
+ console.error(chalk_1.default.red((0, config_1.credentialConflictMessage)(resolved.credentialConflict)));
292
+ process.exit(1);
293
+ }
279
294
  if (!resolved || !resolved.config.apiKey) {
280
295
  console.error(chalk_1.default.red('Not initialized. Run `solidactions login --global` first.'));
281
296
  process.exit(1);
@@ -285,6 +300,26 @@ function requireResolvedConfig() {
285
300
  function requireConfig() {
286
301
  return requireResolvedConfig().config;
287
302
  }
303
+ /**
304
+ * Host as shown in user-facing output: a URL with any userinfo stripped
305
+ * (credentials must never reach the terminal), otherwise shown as
306
+ * configured. Shared by every authentication-failure message (cli#156).
307
+ */
308
+ function displayHost(host) {
309
+ let shown = host;
310
+ try {
311
+ const url = new URL(host);
312
+ if (url.username || url.password) {
313
+ url.username = '';
314
+ url.password = '';
315
+ shown = url.toString().replace(/\/$/, '');
316
+ }
317
+ }
318
+ catch {
319
+ // Not a URL: show it as configured.
320
+ }
321
+ return shown;
322
+ }
288
323
  /**
289
324
  * Contextual 401 message — names the host being called and where the (now
290
325
  * apparently invalid/expired) API key came from, instead of a bare
@@ -292,7 +327,24 @@ function requireConfig() {
292
327
  */
293
328
  function authFailureMessage(config, sources) {
294
329
  const keySource = sources?.apiKey ?? 'config';
295
- return `Authentication failed against ${config.host} (key from ${keySource}). Run \`solidactions login --global\` to re-configure.`;
330
+ return `Authentication failed against ${displayHost(config.host)} (key from ${keySource}). Run \`solidactions login --global\` to re-configure.`;
331
+ }
332
+ /**
333
+ * One line for a failed API response: the server's `message` when it sent one, else the
334
+ * status alone. Never the raw body — a debug-mode server returns the whole stack trace
335
+ * there (cli#114), and a proxy may return an HTML page.
336
+ */
337
+ function formatApiFailure(status, data) {
338
+ const message = data && typeof data === 'object' && !Array.isArray(data)
339
+ ? data.message
340
+ : undefined;
341
+ return typeof message === 'string' && message.trim() !== ''
342
+ ? `Failed: ${status} ${message.trim()}`
343
+ : `Failed: ${status}`;
344
+ }
345
+ /** The one-line 401 every command prints: names the host that refused the key (cli#156), never its userinfo. */
346
+ function authFailedLine(host) {
347
+ return `Authentication failed against ${displayHost(host)}. Run "solidactions login --global" to re-configure.`;
296
348
  }
297
349
  async function ensureWorkspaceSelected(config, dependencies = {}) {
298
350
  if (config.workspaceId) {
@@ -302,6 +354,7 @@ async function ensureWorkspaceSelected(config, dependencies = {}) {
302
354
  const resolved = (0, config_1.resolveConfig)();
303
355
  const workspaceSource = resolved?.sources.workspaceId ?? null;
304
356
  let workspaces;
357
+ let responseScope = null;
305
358
  try {
306
359
  const response = await axios_1.default.get(`${config.host}/api/v1/workspaces`, {
307
360
  headers: {
@@ -331,6 +384,7 @@ async function ensureWorkspaceSelected(config, dependencies = {}) {
331
384
  if (scope) {
332
385
  config.scopeMode = scope.mode;
333
386
  config.scopedWorkspaceIds = scope.workspace_ids;
387
+ responseScope = scope;
334
388
  }
335
389
  }
336
390
  catch (error) {
@@ -371,8 +425,18 @@ async function ensureWorkspaceSelected(config, dependencies = {}) {
371
425
  config.workspaceId = selected.id;
372
426
  config.workspaceOrg = selected.org_name;
373
427
  if (workspaceSource !== 'env') {
428
+ // Persist ONLY the pin. Writing the merged config here copied host/apiKey (from env or
429
+ // the global file) into whichever file was active — a credential crossing layers (cli#124).
374
430
  const targetPath = resolved?.activePath ?? (0, config_1.getGlobalConfigPath)();
375
- (0, config_1.writeConfigFile)(targetPath, config);
431
+ (0, config_1.writeWorkspaceToFile)(targetPath, config.workspace, config.workspaceId, config.workspaceOrg);
432
+ // Correction (cli#124): the token's scope describes the API key, so it belongs in
433
+ // the file that holds that key — and only there. Never into a local pin file whose
434
+ // key lives in another file, and never for an env key.
435
+ const keySource = resolved?.sources.apiKey;
436
+ if (responseScope && keySource !== 'env' && keySource != null && path_1.default.resolve(keySource) === path_1.default.resolve(targetPath)) {
437
+ const existing = (0, config_1.readConfigFile)(targetPath) ?? {};
438
+ (0, config_1.writeConfigFile)(targetPath, { ...existing, scopeMode: responseScope.mode, scopedWorkspaceIds: responseScope.workspace_ids });
439
+ }
376
440
  }
377
441
  return config;
378
442
  }
@@ -484,7 +548,8 @@ async function applyWorkspaceGuard(config, sources, options, io = {}) {
484
548
  }
485
549
  }
486
550
  if (options.mutating && config.workspaceId) {
487
- announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)}`));
551
+ // Name the host too (cli#124): the same workspace name on two hosts confirms nothing.
552
+ announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)} on ${config.host}`));
488
553
  }
489
554
  // state.json means "the workspace you last WROTE to" — that is precisely what the write
490
555
  // confirmation above compares against. A read must never consume the change that gates a
@@ -3,6 +3,9 @@ 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.DEFAULT_HOST = void 0;
7
+ exports.normalizeHost = normalizeHost;
8
+ exports.credentialConflictMessage = credentialConflictMessage;
6
9
  exports.setCliWorkspaceOverride = setCliWorkspaceOverride;
7
10
  exports.getGlobalConfigPath = getGlobalConfigPath;
8
11
  exports.getLocalConfigPath = getLocalConfigPath;
@@ -17,6 +20,42 @@ exports.resolveConfig = resolveConfig;
17
20
  const fs_1 = __importDefault(require("fs"));
18
21
  const os_1 = __importDefault(require("os"));
19
22
  const path_1 = __importDefault(require("path"));
23
+ /** The host an env key goes to when no layer names one (PM ruling 10); the same default `login` uses. */
24
+ exports.DEFAULT_HOST = 'https://app.solidactions.com';
25
+ /** Hosts compare equal ignoring surrounding space, trailing slashes and case. */
26
+ function normalizeHost(host) {
27
+ return host.trim().replace(/\/+$/, '').toLowerCase();
28
+ }
29
+ function describeSource(source, envVar) {
30
+ return source === 'env' ? `$${envVar}` : String(source);
31
+ }
32
+ /** The refusal shown when a key would be sent to a host it was not configured with. Never includes the key. */
33
+ function credentialConflictMessage(conflict) {
34
+ if (conflict.keySource === 'env') {
35
+ // An env key with no SOLIDACTIONS_HOST may only go to the global config's host or the
36
+ // default host — never to a host a folder's config names (PM rulings 1 and 10).
37
+ const globalNote = conflict.otherHost !== undefined
38
+ ? ` (the global config names ${conflict.otherHost})`
39
+ : '';
40
+ return [
41
+ `Refusing to send the API key from $SOLIDACTIONS_API_KEY to ${conflict.host} (host from ${describeSource(conflict.hostSource, 'SOLIDACTIONS_HOST')}): without SOLIDACTIONS_HOST, a key from the environment only goes to the host in the global config or the default host ${exports.DEFAULT_HOST}${globalNote}.`,
42
+ 'Fix: set SOLIDACTIONS_HOST to the host that key belongs to.',
43
+ ].join('\n');
44
+ }
45
+ const hostFrom = describeSource(conflict.hostSource, 'SOLIDACTIONS_HOST');
46
+ const keyFrom = describeSource(conflict.keySource, 'SOLIDACTIONS_API_KEY');
47
+ const keyHome = conflict.keyHost ?? 'no host (that config sets none)';
48
+ const fixes = conflict.hostSource === 'env'
49
+ ? ['unset SOLIDACTIONS_HOST', 'or set SOLIDACTIONS_API_KEY to a key for that host as well']
50
+ : [`run \`solidactions login --local --host ${conflict.host}\` in this folder to store a key for ${conflict.host}`, `or remove "host" from ${hostFrom}`];
51
+ if (conflict.keyHost === undefined) {
52
+ fixes.push(`or add "host" to ${keyFrom}`);
53
+ }
54
+ return [
55
+ `Refusing to send the API key from ${keyFrom} to ${conflict.host} (host from ${hostFrom}): that key is configured for ${keyHome}.`,
56
+ `Fix: ${fixes.join(', ')}.`,
57
+ ].join('\n');
58
+ }
20
59
  const LOCAL_DIR_NAME = '.solidactions';
21
60
  const LOCAL_FILE_NAME = 'config.json';
22
61
  let cliWorkspaceOverride = undefined;
@@ -133,6 +172,13 @@ function readEnvOverrides() {
133
172
  * layer that defines it: env > local > global. Returns null only when no source
134
173
  * contributes a host or apiKey (i.e. nothing usable).
135
174
  *
175
+ * Credential-pair rule (cli#124): host and apiKey travel together. A host set in a
176
+ * layer ABOVE the layer that supplied the key must equal the key's own host, or the
177
+ * merge reports a `credentialConflict` and withholds the key (`apiKey: ''`) — a key
178
+ * is only ever sent to the host configured with it. An env key without
179
+ * SOLIDACTIONS_HOST may go only to the global config's host, or to DEFAULT_HOST when
180
+ * no file names a host; it never goes to a folder config's host.
181
+ *
136
182
  * Invariant the caller must uphold: if `local` is non-null, `localPath` must
137
183
  * also be non-null. (`local` is the parsed contents of a file at `localPath`;
138
184
  * the path is required for source attribution.) `global` may be null even when
@@ -177,10 +223,55 @@ function mergeConfigs(env, local, localPath, global, globalPath) {
177
223
  if (!host.value && !apiKey.value) {
178
224
  return null;
179
225
  }
226
+ // cli#124: host and apiKey are picked per field above, so a host set in a HIGHER layer
227
+ // than the key's layer would carry that key to a host it was never configured for.
228
+ // The key may only travel with the host of its own layer, or of a layer below it.
229
+ const layers = [{ cfg: env, source: 'env' }];
230
+ if (local)
231
+ layers.push({ cfg: local, source: localPath });
232
+ if (global)
233
+ layers.push({ cfg: global, source: globalPath });
234
+ const keyIndex = layers.findIndex((l) => l.cfg.apiKey !== undefined);
235
+ const hostIndex = layers.findIndex((l) => l.cfg.host !== undefined);
236
+ let credentialConflict;
237
+ if (keyIndex !== -1 && hostIndex !== -1 && hostIndex < keyIndex) {
238
+ const keyHost = layers.slice(keyIndex).find((l) => l.cfg.host !== undefined)?.cfg.host;
239
+ const resolvedHost = layers[hostIndex].cfg.host;
240
+ if (keyHost === undefined || normalizeHost(keyHost) !== normalizeHost(resolvedHost)) {
241
+ credentialConflict = {
242
+ host: resolvedHost,
243
+ hostSource: layers[hostIndex].source,
244
+ keyHost,
245
+ keySource: layers[keyIndex].source,
246
+ };
247
+ }
248
+ }
249
+ // PM rulings 1 and 10 (build card task-buildclitrust-bc78): a key from env with no
250
+ // SOLIDACTIONS_HOST has no host of its own, so the check above never fires for it. It may
251
+ // go only to the GLOBAL config's host or the default host — never to a host a folder's
252
+ // config names (a cloned repo's .solidactions/config.json must not receive an exported
253
+ // key), unless that host is the same as the global one.
254
+ let defaultHost = false;
255
+ if (keyIndex === 0 && env.host === undefined) {
256
+ const localHost = local?.host;
257
+ const globalHost = global?.host;
258
+ if (localHost !== undefined && (globalHost === undefined || normalizeHost(localHost) !== normalizeHost(globalHost))) {
259
+ credentialConflict = {
260
+ host: localHost,
261
+ hostSource: localPath,
262
+ keyHost: undefined,
263
+ keySource: 'env',
264
+ ...(globalHost !== undefined ? { otherHost: globalHost, otherHostSource: globalPath } : {}),
265
+ };
266
+ }
267
+ else if (localHost === undefined && globalHost === undefined) {
268
+ defaultHost = true;
269
+ }
270
+ }
180
271
  return {
181
272
  config: {
182
- host: (host.value ?? ''),
183
- apiKey: (apiKey.value ?? ''),
273
+ host: (defaultHost ? exports.DEFAULT_HOST : host.value ?? ''),
274
+ apiKey: (credentialConflict ? '' : apiKey.value ?? ''),
184
275
  workspace: workspace.value,
185
276
  workspaceId: workspaceId.value,
186
277
  workspaceOrg: workspaceId.org,
@@ -188,11 +279,12 @@ function mergeConfigs(env, local, localPath, global, globalPath) {
188
279
  scopedWorkspaceIds: scopedWorkspaceIds.value,
189
280
  },
190
281
  sources: {
191
- host: host.source,
282
+ host: defaultHost ? 'default' : host.source,
192
283
  apiKey: apiKey.source,
193
284
  workspace: workspace.source,
194
285
  workspaceId: workspaceId.source,
195
286
  },
287
+ ...(credentialConflict ? { credentialConflict } : {}),
196
288
  };
197
289
  }
198
290
  /**
@@ -223,5 +315,6 @@ function resolveConfig(cwd = process.cwd()) {
223
315
  config: merged.config,
224
316
  sources: merged.sources,
225
317
  activePath: localPath ?? globalPath,
318
+ credentialConflict: merged.credentialConflict,
226
319
  };
227
320
  }
@@ -58,7 +58,12 @@ async function resolveCrewId(config, input) {
58
58
  crews = await fetchCrews(config);
59
59
  }
60
60
  catch (error) {
61
- console.error(chalk_1.default.red('Failed to list crews:'), error.response?.data?.message || error.message);
61
+ if (error.response?.status === 401) {
62
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
63
+ }
64
+ else {
65
+ console.error(chalk_1.default.red('Failed to list crews:'), error.response?.data?.message || error.message);
66
+ }
62
67
  process.exit(1);
63
68
  }
64
69
  const result = matchCrewByName(input, crews);
package/dist/utils/mcp.js CHANGED
@@ -206,20 +206,24 @@ const CREWS_ROUTES = {
206
206
  sandbox_exec: { tool: 'crews_sandbox', action: 'role_exec', rename: { environment: 'role_exec_environment' } },
207
207
  },
208
208
  };
209
+ /** Own-property lookup: a route table must never resolve an inherited Object.prototype member (cli#155). */
210
+ function ownValue(table, key) {
211
+ return table !== undefined && Object.hasOwn(table, key) ? table[key] : undefined;
212
+ }
209
213
  /**
210
214
  * Map a CLI-level crews call (group + action) to the public MCP tool, action and
211
215
  * param names of the current catalog. Throws for an action the CLI has no route for.
212
216
  */
213
217
  function resolveCrewsCall(group, args) {
214
218
  const action = String(args.action ?? '');
215
- const route = CREWS_ROUTES[group][action];
219
+ const route = ownValue(CREWS_ROUTES[group], action);
216
220
  if (!route)
217
221
  throw new Error(`unsupported crews action: ${group}.${action}`);
218
222
  const out = {};
219
223
  for (const [k, v] of Object.entries(args)) {
220
224
  if (v === undefined)
221
225
  continue;
222
- out[route.rename?.[k] ?? k] = v;
226
+ out[ownValue(route.rename, k) ?? k] = v;
223
227
  }
224
228
  if (route.action)
225
229
  out.action = route.action;
@@ -256,7 +260,7 @@ const DOCS_ROUTES = {
256
260
  */
257
261
  function resolveDocsCall(args) {
258
262
  const action = String(args.action ?? '');
259
- const tool = DOCS_ROUTES[action];
263
+ const tool = ownValue(DOCS_ROUTES, action);
260
264
  if (!tool)
261
265
  throw new Error(`unsupported docs action: ${action}`);
262
266
  const out = {};
@@ -0,0 +1,91 @@
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.getProjectBySlugOrCanonical = getProjectBySlugOrCanonical;
7
+ exports.projectSlugCandidates = projectSlugCandidates;
8
+ exports.resolveProjectSlug = resolveProjectSlug;
9
+ exports.matchProjectRungs = matchProjectRungs;
10
+ const axios_1 = __importDefault(require("axios"));
11
+ const api_1 = require("./api");
12
+ const slug_1 = require("./slug");
13
+ /**
14
+ * GET a project by the name as typed, then — on a 404 only — by its canonical slug when
15
+ * that differs (cli#102). The server stores `Issue970-QX` as `issue970-qx`; without the
16
+ * retry a redeploy 404s, tries to create, and collides with the slug that already exists.
17
+ * The typed spelling goes first so a legacy slug the slugifier would rewrite still resolves.
18
+ */
19
+ async function getProjectBySlugOrCanonical(config, typed, canonical) {
20
+ try {
21
+ return await axios_1.default.get(`${config.host}/api/v1/projects/${typed}`, { headers: (0, api_1.getApiHeaders)(config) });
22
+ }
23
+ catch (error) {
24
+ if (error.response?.status !== 404 || canonical === '' || canonical === typed) {
25
+ throw error;
26
+ }
27
+ return axios_1.default.get(`${config.host}/api/v1/projects/${canonical}`, { headers: (0, api_1.getApiHeaders)(config) });
28
+ }
29
+ }
30
+ /** The slug a command used before cli#161, then the canonical slug — no duplicates, no empty canonical. */
31
+ function projectSlugCandidates(typed, environment) {
32
+ const today = environment === undefined || environment === 'production' ? typed : `${typed}-${environment}`;
33
+ const out = [today];
34
+ if ((0, slug_1.slugifyName)(typed) !== '') {
35
+ const canonical = (0, slug_1.buildProjectSlug)(typed, environment ?? 'production');
36
+ if (!out.includes(canonical))
37
+ out.push(canonical);
38
+ }
39
+ return out;
40
+ }
41
+ /**
42
+ * Resolve a user-typed project to the slug the server stores (cli#161): try each candidate, move on only
43
+ * on a 404, and return the server's slug. Any other error propagates to the command's own handling. When
44
+ * every candidate 404s, return the first so the command's existing not-found message runs unchanged.
45
+ */
46
+ async function resolveProjectSlug(config, typed, environment) {
47
+ const candidates = projectSlugCandidates(typed, environment);
48
+ for (const candidate of candidates) {
49
+ try {
50
+ // Unencoded, as the commands put the slug into their own URLs (PM ruling 6).
51
+ const response = await axios_1.default.get(`${config.host}/api/v1/projects/${candidate}`, { headers: (0, api_1.getApiHeaders)(config) });
52
+ return (typeof response.data?.slug === 'string' && response.data.slug) || candidate;
53
+ }
54
+ catch (error) {
55
+ // PM ruling 3: a token may be allowed the command's own route but not the project read —
56
+ // a 403 here is not a failure; let the command's own request decide.
57
+ if (error.response?.status === 403)
58
+ return candidates[0];
59
+ if (error.response?.status !== 404)
60
+ throw error;
61
+ }
62
+ }
63
+ return candidates[0];
64
+ }
65
+ /**
66
+ * Match a typed project against `GET /api/v1/projects` rows in rungs, stopping
67
+ * at the first rung with a hit: exact name, exact slug, canonical slug, then a
68
+ * case-insensitive name (PM ruling 4: more than one hit there is ambiguous).
69
+ * Shared by `run list`'s retry and `lookupProjectFamilyEnvironments`.
70
+ */
71
+ function matchProjectRungs(projects, typed) {
72
+ if (!Array.isArray(projects))
73
+ return { project: null, ambiguous: [] };
74
+ const byName = projects.find((p) => p?.name === typed);
75
+ if (byName)
76
+ return { project: byName, ambiguous: [] };
77
+ const bySlug = projects.find((p) => p?.slug === typed);
78
+ if (bySlug)
79
+ return { project: bySlug, ambiguous: [] };
80
+ const canonical = (0, slug_1.slugifyName)(typed);
81
+ if (canonical !== '') {
82
+ const byCanonical = projects.find((p) => p?.slug === canonical);
83
+ if (byCanonical)
84
+ return { project: byCanonical, ambiguous: [] };
85
+ }
86
+ const lowered = typed.toLowerCase();
87
+ const ci = projects.filter((p) => typeof p?.name === 'string' && p.name.toLowerCase() === lowered);
88
+ if (ci.length > 1)
89
+ return { project: null, ambiguous: ci };
90
+ return { project: ci[0] ?? null, ambiguous: [] };
91
+ }
@@ -0,0 +1,61 @@
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.TERMINAL_RUN_STATUSES = void 0;
7
+ exports.getStatusColor = getStatusColor;
8
+ exports.formatRunStatusLabel = formatRunStatusLabel;
9
+ exports.describeAdmissionDenied = describeAdmissionDenied;
10
+ exports.describeTerminalRun = describeTerminalRun;
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ /** solidactions-app RunTrigger::TERMINAL_STATUSES — a run in one of these never changes again. */
13
+ exports.TERMINAL_RUN_STATUSES = ['completed', 'failed', 'cancelled', 'dispatch_failed', 'skipped_no_credit'];
14
+ function getStatusColor(status) {
15
+ switch (status?.toLowerCase()) {
16
+ case 'completed':
17
+ case 'success':
18
+ return chalk_1.default.green;
19
+ case 'running':
20
+ return chalk_1.default.blue;
21
+ case 'pending':
22
+ case 'queued':
23
+ case 'admission_pending':
24
+ return chalk_1.default.yellow;
25
+ case 'failed':
26
+ case 'error':
27
+ case 'dispatch_failed':
28
+ case 'skipped_no_credit':
29
+ return chalk_1.default.red;
30
+ case 'cancelled':
31
+ default:
32
+ return chalk_1.default.gray;
33
+ }
34
+ }
35
+ /** Status text for humans; `admission_pending` alone says nothing to a user (cli#99). */
36
+ function formatRunStatusLabel(status) {
37
+ return status === 'admission_pending' ? 'admission_pending (waiting for a free run slot)' : status;
38
+ }
39
+ /** Why a run never started, from the run payload's `admission_denied_reason`; null when there is none. */
40
+ function describeAdmissionDenied(reason) {
41
+ if (typeof reason !== 'string' || reason === '')
42
+ return null;
43
+ if (reason === 'ttl_expired') {
44
+ return 'Run never started: it waited for a free run slot longer than its time limit (admission_denied_reason: ttl_expired).';
45
+ }
46
+ return `Run never started (admission_denied_reason: ${reason}).`;
47
+ }
48
+ /** The outcome `run start --wait` reports for a terminal run, or null while the run can still change. */
49
+ function describeTerminalRun(run) {
50
+ const status = typeof run.status === 'string' ? run.status : '';
51
+ if (!exports.TERMINAL_RUN_STATUSES.includes(status))
52
+ return null;
53
+ if (status === 'completed')
54
+ return { exitCode: 0, message: 'Workflow completed successfully!' };
55
+ if (status === 'cancelled')
56
+ return { exitCode: 1, message: 'Workflow was cancelled.' };
57
+ if (status === 'failed') {
58
+ return { exitCode: 1, message: describeAdmissionDenied(run.admission_denied_reason) ?? 'Workflow failed!' };
59
+ }
60
+ return { exitCode: 1, message: `Workflow did not run (status: ${status}).` };
61
+ }