@solidactions/cli 3.21.0 → 3.23.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 +7 -3
  2. package/dist/command-manifest.json +1 -1
  3. package/dist/commands/connection-list.js +1 -1
  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-map-database.js +4 -1
  7. package/dist/commands/crew-env-push.js +5 -2
  8. package/dist/commands/crew-env-set.js +2 -2
  9. package/dist/commands/database-push.js +2 -1
  10. package/dist/commands/deploy.js +44 -28
  11. package/dist/commands/device-login.js +3 -2
  12. package/dist/commands/doc-pull.js +628 -90
  13. package/dist/commands/doc-push.js +54 -3
  14. package/dist/commands/doc-upload.js +5 -2
  15. package/dist/commands/env-delete.js +12 -5
  16. package/dist/commands/env-list.js +12 -7
  17. package/dist/commands/env-map.js +7 -5
  18. package/dist/commands/env-pull.js +5 -6
  19. package/dist/commands/env-push.js +10 -6
  20. package/dist/commands/env-reset.js +12 -8
  21. package/dist/commands/env-set.js +15 -11
  22. package/dist/commands/login.js +84 -20
  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 +24 -3
  33. package/dist/commands/run-start.js +12 -9
  34. package/dist/commands/run-view.js +2 -2
  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/skill-exec.js +4 -1
  40. package/dist/commands/skill-run.js +4 -1
  41. package/dist/commands/state.js +3 -3
  42. package/dist/commands/webhook-list.js +12 -4
  43. package/dist/commands/webhook-secret.js +12 -4
  44. package/dist/commands/workflow-view.js +20 -4
  45. package/dist/commands/workspaces.js +53 -2
  46. package/dist/index.js +2 -1
  47. package/dist/utils/api.js +18 -4
  48. package/dist/utils/config.js +5 -4
  49. package/dist/utils/crew.js +6 -1
  50. package/dist/utils/host-display.js +47 -0
  51. package/dist/utils/project-ref.js +91 -0
  52. package/dist/utils/workspace-lookup.js +11 -1
  53. package/package.json +2 -2
@@ -208,7 +208,10 @@ async function execOnHost(name, commandParts, options, environment, config) {
208
208
  skippedSecrets = response.data?.skipped_secrets ?? [];
209
209
  }
210
210
  catch (e) {
211
- process.stderr.write(chalk_1.default.red(`error: failed to resolve crew variables: ${e?.response?.data?.message ?? e.message}\n`));
211
+ const message = e?.response?.status === 401
212
+ ? (0, api_1.authFailedLine)(config.host)
213
+ : `error: failed to resolve crew variables: ${e?.response?.data?.message ?? e.message}`;
214
+ process.stderr.write(chalk_1.default.red(`${message}\n`));
212
215
  process.exit(1);
213
216
  }
214
217
  }
@@ -166,7 +166,10 @@ async function skillRunWithConfig(dir, commandParts, options, config) {
166
166
  skippedSecrets = response.data?.skipped_secrets ?? [];
167
167
  }
168
168
  catch (e) {
169
- process.stderr.write(chalk_1.default.red(`error: failed to resolve crew variables: ${e?.response?.data?.message ?? e.message}\n`));
169
+ const message = e?.response?.status === 401
170
+ ? (0, api_1.authFailedLine)(config.host)
171
+ : `error: failed to resolve crew variables: ${e?.response?.data?.message ?? e.message}`;
172
+ process.stderr.write(chalk_1.default.red(`${message}\n`));
170
173
  process.exit(1);
171
174
  }
172
175
  }
@@ -73,12 +73,12 @@ function printInverseCommand(target, environment, enabled) {
73
73
  : `solidactions project ${verb} ${target.project} --env ${environment}`;
74
74
  console.log(chalk_1.default.gray(`Undo: ${command}`));
75
75
  }
76
- function errorMessage(error, target) {
76
+ function errorMessage(error, target, host) {
77
77
  if (!error.response) {
78
78
  return `Connection failed: ${error.message}`;
79
79
  }
80
80
  if (error.response.status === 401) {
81
- return 'Authentication failed. Run "solidactions login --global" to re-configure.';
81
+ return (0, api_1.authFailedLine)(host);
82
82
  }
83
83
  if (error.response.status === 422) {
84
84
  return (0, api_1.formatValidationError)(error.response.data);
@@ -117,7 +117,7 @@ async function setStateWithConfig(target, enabled, options, config) {
117
117
  printInverseCommand(target, environment, enabled);
118
118
  }
119
119
  catch (error) {
120
- console.error(chalk_1.default.red(errorMessage(error, target)));
120
+ console.error(chalk_1.default.red(errorMessage(error, target, config.host)));
121
121
  process.exit(1);
122
122
  }
123
123
  }
@@ -7,6 +7,7 @@ exports.webhookList = webhookList;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const api_1 = require("../utils/api");
10
+ const project_ref_1 = require("../utils/project-ref");
10
11
  const webhook_formatters_1 = require("../utils/webhook-formatters");
11
12
  async function webhookList(projectName, options = {}) {
12
13
  const format = options.format ?? 'table';
@@ -16,11 +17,11 @@ async function webhookList(projectName, options = {}) {
16
17
  }
17
18
  const config = await (0, api_1.requireConfigWithWorkspace)();
18
19
  const environment = options.env || 'dev';
19
- const projectSlug = environment === 'production' ? projectName : `${projectName}-${environment}`;
20
20
  if (format === 'table') {
21
21
  console.log(chalk_1.default.blue(`Webhooks for project "${projectName}"${environment !== 'production' ? ` (${environment})` : ''}:`));
22
22
  }
23
23
  try {
24
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
24
25
  const params = {};
25
26
  if (options.showSecrets) {
26
27
  params.show_secrets = 'true';
@@ -50,13 +51,20 @@ async function webhookList(projectName, options = {}) {
50
51
  catch (error) {
51
52
  if (error.response) {
52
53
  if (error.response.status === 401) {
53
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
54
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
54
55
  }
55
56
  else if (error.response.status === 404) {
56
- console.error(chalk_1.default.red(`Project "${projectName}" not found.`));
57
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
58
+ const envs = family?.environments ?? [];
59
+ if (envs.length > 0 && !envs.includes(environment)) {
60
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}). Pass -e <env> to target a different environment.`));
61
+ }
62
+ else {
63
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
64
+ }
57
65
  }
58
66
  else {
59
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
67
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
60
68
  }
61
69
  }
62
70
  else {
@@ -8,6 +8,7 @@ exports.webhookSecret = webhookSecret;
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
10
  const api_1 = require("../utils/api");
11
+ const project_ref_1 = require("../utils/project-ref");
11
12
  function formatSecretOutput(rows, workflowFilter) {
12
13
  if (workflowFilter) {
13
14
  const match = rows.find((r) => r.workflow_name === workflowFilter);
@@ -29,11 +30,11 @@ async function webhookSecret(projectName, options = {}) {
29
30
  }
30
31
  const config = await (0, api_1.requireConfigWithWorkspace)();
31
32
  const environment = options.env || 'dev';
32
- const projectSlug = environment === 'production' ? projectName : `${projectName}-${environment}`;
33
33
  if (format === 'text') {
34
34
  process.stderr.write(chalk_1.default.dim(`(environment: ${environment} — pass -e <env> to change)\n`));
35
35
  }
36
36
  try {
37
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
37
38
  const response = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/webhooks`, {
38
39
  headers: (0, api_1.getApiHeaders)(config),
39
40
  params: { show_secrets: 'true' },
@@ -57,13 +58,20 @@ async function webhookSecret(projectName, options = {}) {
57
58
  catch (error) {
58
59
  if (error.response) {
59
60
  if (error.response.status === 401) {
60
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
61
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
61
62
  }
62
63
  else if (error.response.status === 404) {
63
- console.error(chalk_1.default.red(`Project "${projectName}" not found.`));
64
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
65
+ const envs = family?.environments ?? [];
66
+ if (envs.length > 0 && !envs.includes(environment)) {
67
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}). Pass -e <env> to target a different environment.`));
68
+ }
69
+ else {
70
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
71
+ }
64
72
  }
65
73
  else {
66
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
74
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
67
75
  }
68
76
  }
69
77
  else {
@@ -57,13 +57,13 @@ function printAmbiguity(error) {
57
57
  }
58
58
  console.error('Re-run with an exact slug.');
59
59
  }
60
- function printWorkflowViewError(error) {
60
+ async function printWorkflowViewError(error, config, project, environment) {
61
61
  if (!error.response) {
62
62
  console.error(chalk_1.default.red('Connection failed:'), display(error.message, 'Unknown network error.', 500));
63
63
  return;
64
64
  }
65
65
  if (error.response.status === 401) {
66
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
66
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
67
67
  return;
68
68
  }
69
69
  // The GET workflow endpoint uses the v1 {code, message} convention;
@@ -74,6 +74,21 @@ function printWorkflowViewError(error) {
74
74
  printAmbiguity(error);
75
75
  return;
76
76
  }
77
+ if (error.response.status === 404) {
78
+ // The workflow route cannot say which environment is missing, so ask
79
+ // the family lookup; any failure falls through to the server message.
80
+ try {
81
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, project);
82
+ const environments = family?.environments ?? [];
83
+ if (environments.length > 0 && !environments.includes(environment)) {
84
+ console.error(chalk_1.default.red(`Project "${display(project)}" has no ${display(environment)} environment (exists in: ${environments.map((e) => display(e)).join(', ')}). Pass -e <env> to target a different environment.`));
85
+ return;
86
+ }
87
+ }
88
+ catch {
89
+ // fall through to the server's message
90
+ }
91
+ }
77
92
  const fallback = error.response.status === 404
78
93
  ? 'Project or workflow not found.'
79
94
  : `Failed to view workflow: ${error.response.status}`;
@@ -81,8 +96,9 @@ function printWorkflowViewError(error) {
81
96
  }
82
97
  async function workflowViewWithConfig(project, workflow, options, config) {
83
98
  let projectSlug;
99
+ let environment;
84
100
  try {
85
- const environment = (0, state_1.resolveStateEnvironment)(options.env);
101
+ environment = (0, state_1.resolveStateEnvironment)(options.env);
86
102
  projectSlug = (0, state_1.projectSlugForState)(project, environment);
87
103
  }
88
104
  catch (error) {
@@ -102,7 +118,7 @@ async function workflowViewWithConfig(project, workflow, options, config) {
102
118
  }
103
119
  }
104
120
  catch (error) {
105
- printWorkflowViewError(error);
121
+ await printWorkflowViewError(error, config, project, environment);
106
122
  process.exit(1);
107
123
  }
108
124
  }
@@ -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) {
package/dist/index.js CHANGED
@@ -97,6 +97,7 @@ const database_1 = require("./commands/database");
97
97
  const database_push_1 = require("./commands/database-push");
98
98
  const database_export_1 = require("./commands/database-export");
99
99
  const config_1 = require("./utils/config");
100
+ const host_display_1 = require("./utils/host-display");
100
101
  const mutating_commands_1 = require("./utils/mutating-commands");
101
102
  const agent_freshness_1 = require("./utils/agent-freshness");
102
103
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -117,7 +118,7 @@ if (process.env.SOLIDACTIONS_DEBUG === '1') {
117
118
  return `(from ${src})`;
118
119
  };
119
120
  process.stderr.write('[SOLIDACTIONS_DEBUG] resolved configuration:\n');
120
- process.stderr.write(` host: ${resolved.config.host} ${fmt(resolved.sources.host)}\n`);
121
+ process.stderr.write(` host: ${(0, host_display_1.displayHost)(resolved.config.host)} ${fmt(resolved.sources.host)}\n`);
121
122
  process.stderr.write(` apiKey: <redacted> ${fmt(resolved.sources.apiKey)}\n`);
122
123
  process.stderr.write(` workspaceId: ${resolved.config.workspaceId ?? ''} ${fmt(resolved.sources.workspaceId)}\n`);
123
124
  process.stderr.write(` activePath: ${resolved.activePath}\n`);
package/dist/utils/api.js CHANGED
@@ -3,7 +3,7 @@ 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.WorkspaceGuardAbort = exports.SANDBOX_EGRESS_MESSAGE = void 0;
6
+ exports.WorkspaceGuardAbort = exports.SANDBOX_EGRESS_MESSAGE = exports.displayHost = void 0;
7
7
  exports.augmentSandboxEgressMessage = augmentSandboxEgressMessage;
8
8
  exports.augmentNotFoundMessage = augmentNotFoundMessage;
9
9
  exports.augmentWorkspaceForbiddenMessage = augmentWorkspaceForbiddenMessage;
@@ -17,6 +17,7 @@ exports.requireResolvedConfig = requireResolvedConfig;
17
17
  exports.requireConfig = requireConfig;
18
18
  exports.authFailureMessage = authFailureMessage;
19
19
  exports.formatApiFailure = formatApiFailure;
20
+ exports.authFailedLine = authFailedLine;
20
21
  exports.ensureWorkspaceSelected = ensureWorkspaceSelected;
21
22
  exports.buildWorkspaceConfirmPrompt = buildWorkspaceConfirmPrompt;
22
23
  exports.applyWorkspaceGuard = applyWorkspaceGuard;
@@ -27,7 +28,10 @@ const path_1 = __importDefault(require("path"));
27
28
  const prompts_1 = __importDefault(require("prompts"));
28
29
  const config_1 = require("./config");
29
30
  const workspace_lookup_1 = require("./workspace-lookup");
31
+ const host_display_1 = require("./host-display");
32
+ Object.defineProperty(exports, "displayHost", { enumerable: true, get: function () { return host_display_1.displayHost; } });
30
33
  const mutating_commands_1 = require("./mutating-commands");
34
+ const project_ref_1 = require("./project-ref");
31
35
  const workspace_guard_1 = require("./workspace-guard");
32
36
  // Backend (solidactions-app PR #128) returns: "Project '<slug>' not found in your active workspace '<workspace-slug>'."
33
37
  // We require the literal single-quotes around the slug so plausible future error messages
@@ -204,7 +208,13 @@ async function lookupProjectFamilyEnvironments(config, projectName) {
204
208
  try {
205
209
  const res = await axios_1.default.get(`${config.host}/api/v1/projects`, { headers: getApiHeaders(config) });
206
210
  const rows = res.data?.data ?? res.data ?? [];
207
- const hit = rows.find((p) => p.name === projectName || p.slug === projectName);
211
+ // The same rungs `run list` retries with (cli#161): an ambiguous
212
+ // case-insensitive match yields no hint rather than a guess.
213
+ const match = (0, project_ref_1.matchProjectRungs)(rows, projectName);
214
+ if (match.ambiguous.length > 0) {
215
+ return null;
216
+ }
217
+ const hit = match.project;
208
218
  const environments = hit?.environments;
209
219
  if (!environments?.length) {
210
220
  return null;
@@ -298,7 +308,7 @@ function requireConfig() {
298
308
  */
299
309
  function authFailureMessage(config, sources) {
300
310
  const keySource = sources?.apiKey ?? 'config';
301
- return `Authentication failed against ${config.host} (key from ${keySource}). Run \`solidactions login --global\` to re-configure.`;
311
+ return `Authentication failed against ${(0, host_display_1.displayHost)(config.host)} (key from ${keySource}). Run \`solidactions login --global\` to re-configure.`;
302
312
  }
303
313
  /**
304
314
  * One line for a failed API response: the server's `message` when it sent one, else the
@@ -313,6 +323,10 @@ function formatApiFailure(status, data) {
313
323
  ? `Failed: ${status} ${message.trim()}`
314
324
  : `Failed: ${status}`;
315
325
  }
326
+ /** The one-line 401 every command prints: names the host that refused the key (cli#156), never its userinfo. */
327
+ function authFailedLine(host) {
328
+ return `Authentication failed against ${(0, host_display_1.displayHost)(host)}. Run "solidactions login --global" to re-configure.`;
329
+ }
316
330
  async function ensureWorkspaceSelected(config, dependencies = {}) {
317
331
  if (config.workspaceId) {
318
332
  return config;
@@ -516,7 +530,7 @@ async function applyWorkspaceGuard(config, sources, options, io = {}) {
516
530
  }
517
531
  if (options.mutating && config.workspaceId) {
518
532
  // Name the host too (cli#124): the same workspace name on two hosts confirms nothing.
519
- announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)} on ${config.host}`));
533
+ announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)} on ${(0, host_display_1.displayHost)(config.host)}`));
520
534
  }
521
535
  // state.json means "the workspace you last WROTE to" — that is precisely what the write
522
536
  // confirmation above compares against. A read must never consume the change that gates a
@@ -20,6 +20,7 @@ exports.resolveConfig = resolveConfig;
20
20
  const fs_1 = __importDefault(require("fs"));
21
21
  const os_1 = __importDefault(require("os"));
22
22
  const path_1 = __importDefault(require("path"));
23
+ const host_display_1 = require("./host-display");
23
24
  /** The host an env key goes to when no layer names one (PM ruling 10); the same default `login` uses. */
24
25
  exports.DEFAULT_HOST = 'https://app.solidactions.com';
25
26
  /** Hosts compare equal ignoring surrounding space, trailing slashes and case. */
@@ -35,10 +36,10 @@ function credentialConflictMessage(conflict) {
35
36
  // An env key with no SOLIDACTIONS_HOST may only go to the global config's host or the
36
37
  // default host — never to a host a folder's config names (PM rulings 1 and 10).
37
38
  const globalNote = conflict.otherHost !== undefined
38
- ? ` (the global config names ${conflict.otherHost})`
39
+ ? ` (the global config names ${(0, host_display_1.displayHost)(conflict.otherHost)})`
39
40
  : '';
40
41
  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
+ `Refusing to send the API key from $SOLIDACTIONS_API_KEY to ${(0, host_display_1.displayHost)(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
43
  'Fix: set SOLIDACTIONS_HOST to the host that key belongs to.',
43
44
  ].join('\n');
44
45
  }
@@ -47,12 +48,12 @@ function credentialConflictMessage(conflict) {
47
48
  const keyHome = conflict.keyHost ?? 'no host (that config sets none)';
48
49
  const fixes = conflict.hostSource === 'env'
49
50
  ? ['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
+ : [`run \`solidactions login --local --host ${(0, host_display_1.displayHost)(conflict.host)}\` in this folder to store a key for ${(0, host_display_1.displayHost)(conflict.host)}`, `or remove "host" from ${hostFrom}`];
51
52
  if (conflict.keyHost === undefined) {
52
53
  fixes.push(`or add "host" to ${keyFrom}`);
53
54
  }
54
55
  return [
55
- `Refusing to send the API key from ${keyFrom} to ${conflict.host} (host from ${hostFrom}): that key is configured for ${keyHome}.`,
56
+ `Refusing to send the API key from ${keyFrom} to ${(0, host_display_1.displayHost)(conflict.host)} (host from ${hostFrom}): that key is configured for ${(0, host_display_1.displayHost)(keyHome)}.`,
56
57
  `Fix: ${fixes.join(', ')}.`,
57
58
  ].join('\n');
58
59
  }
@@ -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);
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayHost = displayHost;
4
+ /**
5
+ * Host as shown in user-facing output: a URL with any userinfo stripped
6
+ * (credentials must never reach the terminal), otherwise shown as
7
+ * configured. Every printed host goes through this (cli#156, cli#163);
8
+ * tests/host-display-guard.test.ts fails on a raw host in a printed template.
9
+ */
10
+ function displayHost(host) {
11
+ let shown = host;
12
+ try {
13
+ const url = new URL(host);
14
+ if (url.host === '') {
15
+ // Parses as an opaque `scheme:rest` (`u:secret@host`): no authority to trust.
16
+ shown = stripUnparsedUserinfo(host);
17
+ }
18
+ else if (url.username || url.password) {
19
+ url.username = '';
20
+ url.password = '';
21
+ shown = url.toString().replace(/\/$/, '');
22
+ }
23
+ }
24
+ catch {
25
+ shown = stripUnparsedUserinfo(host);
26
+ }
27
+ return shown;
28
+ }
29
+ const INVALID_HOST_PLACEHOLDER = '<invalid host>';
30
+ /**
31
+ * Fallback for a value `new URL` rejects (`http://u:secret@localhost:bad-port`),
32
+ * which must not keep its userinfo (cli#163): cut the authority at its LAST `@`
33
+ * (an `@` inside a password cannot leak), and if an `@` is still left after
34
+ * that, or nothing is, show a placeholder rather than guess. A value without
35
+ * `@` is shown as configured.
36
+ */
37
+ function stripUnparsedUserinfo(host) {
38
+ if (!host.includes('@')) {
39
+ return host;
40
+ }
41
+ const [, scheme = '', authority = '', rest = ''] = host.match(/^([a-z][a-z0-9+.-]*:\/\/)?([^/?#]*)(.*)$/is) ?? [];
42
+ const afterUserinfo = authority.slice(authority.lastIndexOf('@') + 1);
43
+ if (afterUserinfo === '' || rest.includes('@')) {
44
+ return INVALID_HOST_PLACEHOLDER;
45
+ }
46
+ return scheme + afterUserinfo + rest;
47
+ }
@@ -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
+ }
@@ -14,6 +14,7 @@ exports.resolveWorkspaceInput = resolveWorkspaceInput;
14
14
  const axios_1 = __importDefault(require("axios"));
15
15
  const chalk_1 = __importDefault(require("chalk"));
16
16
  const readline_1 = __importDefault(require("readline"));
17
+ const api_1 = require("./api");
17
18
  /**
18
19
  * Workspaces whose slug or name contains the input (or is contained in it), case-insensitively —
19
20
  * offered after a miss, never selected (cli#112). Reverse containment only counts for
@@ -302,7 +303,16 @@ async function resolveWorkspaceInput(config, input) {
302
303
  ({ workspaces, scope } = await fetchWorkspaces(config));
303
304
  }
304
305
  catch (error) {
305
- console.error(chalk_1.default.red('Failed to list workspaces:'), error.response?.data?.message || error.message);
306
+ const status = error.response?.status;
307
+ if (status === 401) {
308
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
309
+ }
310
+ else if (status) {
311
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(status, error.response.data)));
312
+ }
313
+ else {
314
+ console.error(chalk_1.default.red(`Connection failed: ${error.message}`));
315
+ }
306
316
  process.exit(1);
307
317
  }
308
318
  const result = classifyWorkspaceInput(input, workspaces);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidactions/cli",
3
- "version": "3.21.0",
3
+ "version": "3.23.0",
4
4
  "description": "SolidActions CLI - Deploy and manage workflow automation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -62,6 +62,6 @@
62
62
  "@types/prompts": "^2.4.9",
63
63
  "@types/tar": "^6.1.13",
64
64
  "typescript": "^5.0.0",
65
- "vitest": "^4.1.5"
65
+ "vitest": "^4.1.11"
66
66
  }
67
67
  }