@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,6 +11,7 @@ const axios_1 = __importDefault(require("axios"));
11
11
  const chalk_1 = __importDefault(require("chalk"));
12
12
  const readline_1 = __importDefault(require("readline"));
13
13
  const api_1 = require("../utils/api");
14
+ const project_ref_1 = require("../utils/project-ref");
14
15
  const secure_write_1 = require("../utils/secure-write");
15
16
  /**
16
17
  * Prompt the user for confirmation (unless --yes flag is set).
@@ -75,15 +76,13 @@ function databaseDisplayName(variable) {
75
76
  async function envPull(projectName, options = {}) {
76
77
  const config = await (0, api_1.requireConfigWithWorkspace)();
77
78
  const environment = options.env || 'dev';
78
- // Build the project slug for lookup
79
- const projectSlug = environment === 'production'
80
- ? projectName
81
- : `${projectName}-${environment}`;
82
79
  // Determine output file
83
80
  const outputFile = options.output || (environment === 'production' ? '.env' : `.env.${environment}`);
84
81
  const outputPath = path_1.default.resolve(outputFile);
85
82
  console.log(chalk_1.default.blue(`Pulling variables from "${projectName}" (${environment})...`));
83
+ let projectSlug = '';
86
84
  try {
85
+ projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
87
86
  // First, check if there are any secrets
88
87
  const checkResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings?resolve_oauth=true`, {
89
88
  headers: (0, api_1.getApiHeaders)(config),
@@ -299,7 +298,7 @@ async function envPull(projectName, options = {}) {
299
298
  catch (error) {
300
299
  if (error.response) {
301
300
  if (error.response.status === 401) {
302
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
301
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
303
302
  }
304
303
  else if (error.response.status === 404) {
305
304
  console.error(chalk_1.default.red(`Project "${projectSlug}" not found.`));
@@ -319,7 +318,7 @@ async function envPull(projectName, options = {}) {
319
318
  console.error(chalk_1.default.red(detail ? `${lead}\n\n${detail}` : lead));
320
319
  }
321
320
  else {
322
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
321
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
323
322
  }
324
323
  }
325
324
  else if (!axios_1.default.isAxiosError(error) && error.code) {
@@ -10,6 +10,7 @@ const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const prompts_1 = __importDefault(require("prompts"));
12
12
  const api_1 = require("../utils/api");
13
+ const project_ref_1 = require("../utils/project-ref");
13
14
  const env_1 = require("../utils/env");
14
15
  async function envPush(projectName, sourcePath, options = {}) {
15
16
  const config = await (0, api_1.requireConfigWithWorkspace)();
@@ -81,14 +82,12 @@ async function envPush(projectName, sourcePath, options = {}) {
81
82
  `Rename them (e.g. "${reservedKeys[0].replace(/^SOLIDACTIONS_/, 'MY_')}") and retry. Nothing was pushed.`));
82
83
  process.exit(1);
83
84
  }
84
- // Build project slug
85
- const projectSlug = environment === 'production'
86
- ? projectName
87
- : `${projectName}-${environment}`;
88
85
  console.log(chalk_1.default.blue(`Pushing variables to "${projectName}" (${environment})...`));
89
86
  // Fetch current server state
90
87
  let serverMappings = [];
88
+ let projectSlug = '';
91
89
  try {
90
+ projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
92
91
  const response = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
93
92
  headers: (0, api_1.getApiHeaders)(config),
94
93
  });
@@ -96,7 +95,7 @@ async function envPush(projectName, sourcePath, options = {}) {
96
95
  }
97
96
  catch (error) {
98
97
  if (error.response?.status === 401) {
99
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
98
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
100
99
  process.exit(1);
101
100
  }
102
101
  else if (error.response?.status === 404) {
@@ -200,7 +199,12 @@ async function envPush(projectName, sourcePath, options = {}) {
200
199
  console.log(chalk_1.default.gray(` ${created} created, ${updated} updated` + (toSkip.length > 0 ? `, ${toSkip.length} skipped` : '')));
201
200
  }
202
201
  catch (error) {
203
- console.error(chalk_1.default.red('Failed to push variables:'), error.response?.data?.message || error.message);
202
+ if (error.response?.status === 401) {
203
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
204
+ }
205
+ else {
206
+ console.error(chalk_1.default.red('Failed to push variables:'), error.response?.data?.message || error.message);
207
+ }
204
208
  process.exit(1);
205
209
  }
206
210
  }
@@ -7,6 +7,7 @@ exports.envReset = envReset;
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
  function describeRestoredSource(mapping) {
11
12
  const sourceType = mapping.source_type || mapping.source || 'unknown';
12
13
  if (sourceType === 'oauth_connection') {
@@ -22,10 +23,8 @@ function describeRestoredSource(mapping) {
22
23
  async function envReset(projectName, key, options = {}) {
23
24
  const config = await (0, api_1.requireConfigWithWorkspace)();
24
25
  const environment = options.env || 'dev';
25
- const projectSlug = environment === 'production'
26
- ? projectName
27
- : `${projectName}-${environment}`;
28
26
  try {
27
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
29
28
  const listResponse = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, { headers: (0, api_1.getApiHeaders)(config) });
30
29
  const mappings = listResponse.data || [];
31
30
  const mapping = mappings.find((candidate) => candidate.env_name === key);
@@ -41,15 +40,20 @@ async function envReset(projectName, key, options = {}) {
41
40
  catch (error) {
42
41
  if (error.response) {
43
42
  if (error.response.status === 401) {
44
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
43
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
45
44
  }
46
45
  else if (error.response.status === 404) {
47
- const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
48
- console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment` +
49
- `${envsList ? ` (exists in: ${envsList})` : ''}.`));
46
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
47
+ const envs = family?.environments ?? [];
48
+ if (envs.length > 0 && !envs.includes(environment)) {
49
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}).`));
50
+ }
51
+ else {
52
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
53
+ }
50
54
  }
51
55
  else {
52
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
56
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
53
57
  }
54
58
  }
55
59
  else {
@@ -10,6 +10,7 @@ const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const prompts_1 = __importDefault(require("prompts"));
12
12
  const api_1 = require("../utils/api");
13
+ const project_ref_1 = require("../utils/project-ref");
13
14
  const env_1 = require("../utils/env");
14
15
  /** Returns true when stdin is not an interactive terminal (CI, pipes, scripts). */
15
16
  function isNonTty() {
@@ -63,13 +64,10 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
63
64
  process.exit(1);
64
65
  }
65
66
  const environment = options.env || 'dev';
66
- // Build project slug
67
- const projectSlug = environment === 'production'
68
- ? projectName
69
- : `${projectName}-${environment}`;
70
67
  // Auto-detect secrets
71
68
  const isSecret = options.secret || /secret|key|token|password|credential/i.test(key);
72
69
  try {
70
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName, environment);
73
71
  if (isOauthConnectionMode) {
74
72
  await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings`, {
75
73
  project_key: key,
@@ -126,18 +124,24 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
126
124
  catch (error) {
127
125
  if (error.response) {
128
126
  if (error.response.status === 401) {
129
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
127
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
130
128
  }
131
129
  else if (error.response.status === 404) {
132
- const envsList = await (0, api_1.describeProjectEnvironments)(config, projectName);
133
- console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment${envsList ? ` (exists in: ${envsList})` : ''}.`
134
- + `\nRun 'solidactions project deploy ${projectName} -e ${environment} --create' first.`));
130
+ const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, projectName);
131
+ const envs = family?.environments ?? [];
132
+ if (envs.length > 0 && !envs.includes(environment)) {
133
+ console.error(chalk_1.default.red(`Project "${projectName}" has no ${environment} environment (exists in: ${envs.join(', ')}).`
134
+ + `\nRun 'solidactions project deploy ${projectName} -e ${environment} --create' first.`));
135
+ }
136
+ else {
137
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(404, error.response.data)));
138
+ }
135
139
  }
136
140
  else if (error.response.status === 422) {
137
141
  console.error(chalk_1.default.red((0, api_1.formatValidationError)(error.response.data)));
138
142
  }
139
143
  else {
140
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
144
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
141
145
  }
142
146
  }
143
147
  else {
@@ -249,13 +253,13 @@ async function envSet(keyOrProject, valueOrKey, valueIfProject, options = {}) {
249
253
  catch (error) {
250
254
  if (error.response) {
251
255
  if (error.response.status === 401) {
252
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
256
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
253
257
  }
254
258
  else if (error.response.status === 422) {
255
259
  console.error(chalk_1.default.red((0, api_1.formatValidationError)(error.response.data)));
256
260
  }
257
261
  else {
258
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
262
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
259
263
  }
260
264
  }
261
265
  else {
@@ -11,6 +11,7 @@ const chalk_1 = __importDefault(require("chalk"));
11
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
12
12
  const github_1 = require("../utils/github");
13
13
  const examples_ref_1 = require("../utils/examples-ref");
14
+ const slug_1 = require("../utils/slug");
14
15
  const ai_init_1 = require("./ai-init");
15
16
  const EXAMPLES_OWNER = 'SolidActions';
16
17
  const EXAMPLES_REPO = 'solidactions-examples';
@@ -40,7 +41,9 @@ async function init(directory, options = {}) {
40
41
  const cwd = process.cwd();
41
42
  const installSkills = options.skills !== false; // default true
42
43
  const targetDir = directory ? path_1.default.resolve(cwd, directory) : cwd;
43
- const projectName = path_1.default.basename(targetDir);
44
+ // The canonical slug, not the folder's spelling: a mixed-case name is an invalid npm
45
+ // package name and redeploys under a different slug than the server stores (cli#102).
46
+ const projectName = (0, slug_1.slugifyName)(path_1.default.basename(targetDir)) || 'solidactions-project';
44
47
  if (directory) {
45
48
  fs_extra_1.default.ensureDirSync(targetDir);
46
49
  }
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DEVICE_LOGIN_REFUSAL_MESSAGE = exports.API_KEY_PROMPT = exports.selectWorkspaceInteractively = void 0;
7
7
  exports.resolveLoginApiKey = resolveLoginApiKey;
8
- exports.getConfig = getConfig;
9
- exports.saveConfig = saveConfig;
10
8
  exports.clearConfig = clearConfig;
11
9
  exports.resolveLoginHost = resolveLoginHost;
12
10
  exports.backupPathFor = backupPathFor;
@@ -72,15 +70,6 @@ async function resolveLoginApiKey(apiKey, options = {}, dependencies = {}) {
72
70
  }
73
71
  return trimmed;
74
72
  }
75
- function getConfig() {
76
- const resolved = (0, config_1.resolveConfig)();
77
- return resolved ? resolved.config : null;
78
- }
79
- function saveConfig(config) {
80
- const resolved = (0, config_1.resolveConfig)();
81
- const targetPath = resolved ? resolved.activePath : (0, config_1.getGlobalConfigPath)();
82
- (0, config_1.writeConfigFile)(targetPath, config);
83
- }
84
73
  function clearConfig() {
85
74
  (0, config_1.removeConfigFile)((0, config_1.getGlobalConfigPath)());
86
75
  }
@@ -437,6 +426,11 @@ function logout(options = {}) {
437
426
  }
438
427
  function whoami() {
439
428
  const resolved = (0, config_1.resolveConfig)();
429
+ if (resolved?.credentialConflict) {
430
+ // stderr, like requireResolvedConfig (PM ruling 7).
431
+ console.error(chalk_1.default.red((0, config_1.credentialConflictMessage)(resolved.credentialConflict)));
432
+ process.exit(1);
433
+ }
440
434
  if (!resolved || !resolved.config.apiKey) {
441
435
  console.log(chalk_1.default.yellow('Not initialized.'));
442
436
  console.log(chalk_1.default.gray('Run "solidactions login --global" to configure.'));
@@ -451,19 +445,22 @@ function whoami() {
451
445
  return chalk_1.default.gray('(from $SOLIDACTIONS_* env var)');
452
446
  if (src === 'cli')
453
447
  return chalk_1.default.gray('(from -w flag)');
448
+ if (src === 'default')
449
+ return chalk_1.default.gray('(default)');
454
450
  if (src === null)
455
451
  return chalk_1.default.gray('(unset)');
456
452
  return chalk_1.default.gray(`(from ${src})`);
457
453
  };
458
- const workspaceLabel = config.workspace
459
- ? `${config.workspace}${config.workspaceId ? ` (${config.workspaceId})` : ''}`
460
- : config.workspaceId
454
+ const workspaceName = config.workspace ?? config.workspaceId;
455
+ const workspaceLabel = !config.workspaceId && !config.workspace
456
+ ? ''
457
+ : !config.workspace
461
458
  ? `${config.workspaceId} (slug unknown — run 'workspace set <slug>' to populate)`
462
- : '';
463
- const isFileSource = (src) => src !== null && src !== 'env' && src !== 'cli';
464
- const workspaceInheritedFromOtherFile = isFileSource(sources.workspaceId) && sources.workspaceId !== sources.apiKey;
459
+ : config.workspaceOrg
460
+ ? `${workspaceName} — organization ${config.workspaceOrg}${config.workspaceId ? ` (${config.workspaceId})` : ''}`
461
+ : `${workspaceName}${config.workspaceId ? ` (${config.workspaceId})` : ''}`;
465
462
  console.log(chalk_1.default.blue('Current configuration:'));
466
463
  console.log(` Host: ${config.host.padEnd(50)} ${fmt(sources.host)}`);
467
464
  console.log(` API Key: ${maskedKey.padEnd(50)} ${fmt(sources.apiKey)}`);
468
- console.log(` Workspace: ${workspaceLabel.padEnd(50)} ${fmt(sources.workspaceId)}${workspaceInheritedFromOtherFile ? chalk_1.default.yellow(' (inherited from a different config file)') : ''}`);
465
+ console.log(` Workspace: ${workspaceLabel.padEnd(50)} ${fmt(sources.workspaceId)}`);
469
466
  }
@@ -38,10 +38,10 @@ async function oauthActionList(platform, options) {
38
38
  console.error(chalk_1.default.red(`Unknown platform "${platform}". Run \`solidactions oauth-action platforms\` to see available platforms.`));
39
39
  }
40
40
  else if (error.response?.status === 401) {
41
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global".'));
41
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
42
42
  }
43
43
  else if (error.response) {
44
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
44
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
45
45
  }
46
46
  else {
47
47
  console.error(chalk_1.default.red('Connection failed:'), error.message);
@@ -28,10 +28,10 @@ async function oauthActionPlatforms(options) {
28
28
  }
29
29
  catch (error) {
30
30
  if (error.response?.status === 401) {
31
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global".'));
31
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
32
32
  }
33
33
  else if (error.response) {
34
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
34
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
35
35
  }
36
36
  else {
37
37
  console.error(chalk_1.default.red('Connection failed:'), error.message);
@@ -49,10 +49,10 @@ async function oauthActionSearch(platform, query, options) {
49
49
  console.error(chalk_1.default.red(`Unknown platform "${platform}". Run \`solidactions oauth-action platforms\` to see available platforms.`));
50
50
  }
51
51
  else if (error.response?.status === 401) {
52
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
52
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
53
53
  }
54
54
  else if (error.response) {
55
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
55
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
56
56
  }
57
57
  else {
58
58
  console.error(chalk_1.default.red('Connection failed:'), error.message);
@@ -26,10 +26,10 @@ async function oauthActionView(platform, actionId, options) {
26
26
  console.error(chalk_1.default.red(`Action not found: ${platform}/${actionId}`));
27
27
  }
28
28
  else if (error.response?.status === 401) {
29
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global".'));
29
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
30
30
  }
31
31
  else if (error.response) {
32
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
32
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
33
33
  }
34
34
  else {
35
35
  console.error(chalk_1.default.red('Connection failed:'), error.message);
@@ -45,7 +45,7 @@ async function projectCreateWithConfig(name, options, config) {
45
45
  catch (error) {
46
46
  if (error.response) {
47
47
  if (error.response.status === 401) {
48
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
48
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
49
49
  }
50
50
  else {
51
51
  console.error(chalk_1.default.red('Failed to create project:'), error.response.data?.message || error.message);
@@ -68,10 +68,10 @@ async function projectList(options = {}) {
68
68
  catch (error) {
69
69
  if (error.response) {
70
70
  if (error.response.status === 401) {
71
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
71
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
72
72
  }
73
73
  else {
74
- 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)));
75
75
  }
76
76
  }
77
77
  else {
@@ -9,6 +9,7 @@ exports.logsBuild = logsBuild;
9
9
  const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  const api_1 = require("../utils/api");
12
+ const project_ref_1 = require("../utils/project-ref");
12
13
  function buildBuildLogUrl(host, projectName, environment) {
13
14
  if (environment) {
14
15
  return `${host}/api/v1/projects/resolve/build-log`;
@@ -27,8 +28,11 @@ function buildBuildLogRequest(host, projectName, environment) {
27
28
  async function logsBuild(projectName, environment) {
28
29
  const config = await (0, api_1.requireConfigWithWorkspace)();
29
30
  console.log(chalk_1.default.blue(`Fetching build logs for project "${projectName}"...`));
30
- const { url, params } = buildBuildLogRequest(config.host, projectName, environment);
31
31
  try {
32
+ // Only the path without -e resolves here; the -e path already asks
33
+ // the server to resolve the name.
34
+ const name = environment === undefined ? await (0, project_ref_1.resolveProjectSlug)(config, projectName) : projectName;
35
+ const { url, params } = buildBuildLogRequest(config.host, name, environment);
32
36
  const response = await axios_1.default.get(url, {
33
37
  headers: (0, api_1.getApiHeaders)(config),
34
38
  params,
@@ -45,7 +49,7 @@ async function logsBuild(projectName, environment) {
45
49
  catch (error) {
46
50
  if (error.response) {
47
51
  if (error.response.status === 401) {
48
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
52
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
49
53
  }
50
54
  else if (error.response.status === 404) {
51
55
  console.error(chalk_1.default.red(error.response.data?.message ?? `Project "${projectName}" not found.`));
@@ -55,7 +59,7 @@ async function logsBuild(projectName, environment) {
55
59
  }
56
60
  }
57
61
  else {
58
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
62
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
59
63
  }
60
64
  }
61
65
  else {
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.projectViewJsonProjection = projectViewJsonProjection;
7
7
  exports.quoteCommandArg = quoteCommandArg;
8
+ exports.isUsableProjectRef = isUsableProjectRef;
8
9
  exports.projectSlugForView = projectSlugForView;
9
10
  exports.formatDeploymentRevision = formatDeploymentRevision;
10
11
  exports.formatProjectView = formatProjectView;
@@ -13,6 +14,7 @@ exports.projectView = projectView;
13
14
  const axios_1 = __importDefault(require("axios"));
14
15
  const chalk_1 = __importDefault(require("chalk"));
15
16
  const api_1 = require("../utils/api");
17
+ const project_ref_1 = require("../utils/project-ref");
16
18
  const slug_1 = require("../utils/slug");
17
19
  const source_provenance_1 = require("../utils/source-provenance");
18
20
  /**
@@ -64,6 +66,24 @@ function projectViewJsonProjection(project) {
64
66
  function quoteCommandArg(arg) {
65
67
  return /^[A-Za-z0-9._/-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, "'\\''")}'`;
66
68
  }
69
+ /**
70
+ * Fail fast on a bad project reference before any HTTP (cli#161 kept
71
+ * resolution; validation still refuses locally). Returns true when the
72
+ * reference is usable. On a bad reference prints the long-standing message
73
+ * to stderr and exits 1; the false return only matters when process.exit is
74
+ * a test double, so the caller still stops.
75
+ */
76
+ function isUsableProjectRef(project, environment) {
77
+ try {
78
+ projectSlugForView(project, environment);
79
+ return true;
80
+ }
81
+ catch (error) {
82
+ console.error(chalk_1.default.red(error.message));
83
+ process.exit(1);
84
+ return false;
85
+ }
86
+ }
67
87
  function projectSlugForView(project, environment) {
68
88
  if (environment === undefined) {
69
89
  return project;
@@ -151,16 +171,13 @@ function formatProjectView(project) {
151
171
  }
152
172
  async function projectViewWithConfig(project, options, config, writeLine = console.log) {
153
173
  const environment = options.env ?? 'dev';
154
- let slug;
155
- try {
156
- slug = projectSlugForView(project, environment);
157
- }
158
- catch (error) {
159
- console.error(chalk_1.default.red(error.message));
160
- process.exit(1);
174
+ let slug = '';
175
+ // Local input validation first (cli#161 kept resolution; validation
176
+ // still fails fast before any HTTP).
177
+ if (!isUsableProjectRef(project, environment))
161
178
  return;
162
- }
163
179
  try {
180
+ slug = await (0, project_ref_1.resolveProjectSlug)(config, project, environment);
164
181
  const response = await axios_1.default.get(`${config.host}/api/v1/projects/${encodeURIComponent(slug)}?include=deployment`, { headers: (0, api_1.getApiHeaders)(config) });
165
182
  if (options.json) {
166
183
  writeLine(JSON.stringify(projectViewJsonProjection(response.data), null, 2));
@@ -173,7 +190,7 @@ async function projectViewWithConfig(project, options, config, writeLine = conso
173
190
  }
174
191
  catch (error) {
175
192
  if (error.response?.status === 401) {
176
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
193
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
177
194
  }
178
195
  else if (error.response?.status === 404) {
179
196
  const family = await (0, api_1.lookupProjectFamilyEnvironments)(config, project);
@@ -14,6 +14,7 @@ const axios_1 = __importDefault(require("axios"));
14
14
  const chalk_1 = __importDefault(require("chalk"));
15
15
  const prompts_1 = __importDefault(require("prompts"));
16
16
  const api_1 = require("../utils/api");
17
+ const project_ref_1 = require("../utils/project-ref");
17
18
  async function pull(projectName, destPath, options = {}) {
18
19
  const config = await (0, api_1.requireConfigWithWorkspace)();
19
20
  const destination = destPath ? path_1.default.resolve(destPath) : process.cwd();
@@ -37,7 +38,8 @@ async function pull(projectName, destPath, options = {}) {
37
38
  }
38
39
  console.log(chalk_1.default.blue(`Pulling project "${projectName}"...`));
39
40
  try {
40
- const response = await axios_1.default.get(`${config.host}/api/v1/projects/${projectName}/source`, {
41
+ const projectSlug = await (0, project_ref_1.resolveProjectSlug)(config, projectName);
42
+ const response = await axios_1.default.get(`${config.host}/api/v1/projects/${projectSlug}/source`, {
41
43
  headers: { ...(0, api_1.getApiHeaders)(config), 'Accept': 'application/octet-stream' },
42
44
  responseType: 'arraybuffer',
43
45
  });
@@ -70,7 +72,7 @@ async function pull(projectName, destPath, options = {}) {
70
72
  console.error(chalk_1.default.red(`Project "${projectName}" not found.`));
71
73
  }
72
74
  else if (error.response.status === 401) {
73
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
75
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
74
76
  }
75
77
  else {
76
78
  console.error(chalk_1.default.red(`Failed: ${error.response.status}`));
@@ -13,6 +13,8 @@ exports.displayDetailedList = displayDetailedList;
13
13
  const axios_1 = __importDefault(require("axios"));
14
14
  const chalk_1 = __importDefault(require("chalk"));
15
15
  const api_1 = require("../utils/api");
16
+ const project_ref_1 = require("../utils/project-ref");
17
+ const run_status_1 = require("../utils/run-status");
16
18
  const table_1 = require("../utils/table");
17
19
  const source_provenance_1 = require("../utils/source-provenance");
18
20
  var source_provenance_2 = require("../utils/source-provenance");
@@ -48,10 +50,30 @@ async function runs(projectName, options = {}) {
48
50
  const config = await (0, api_1.requireConfigWithWorkspace)();
49
51
  try {
50
52
  const params = buildRunListParams(projectName, options);
51
- const response = await axios_1.default.get(`${config.host}/api/v1/runs`, {
53
+ let response = await axios_1.default.get(`${config.host}/api/v1/runs`, {
52
54
  headers: (0, api_1.getApiHeaders)(config),
53
55
  params,
54
56
  });
57
+ // cli#161: the filter text may be a name whose slug differs (or the
58
+ // other way round) — look the project up once and retry with its
59
+ // exact name (PM ruling 4: an ambiguous match refuses instead).
60
+ if (response.data?.error === 'project_not_found' && projectName) {
61
+ const listResponse = await axios_1.default.get(`${config.host}/api/v1/projects`, { headers: (0, api_1.getApiHeaders)(config) });
62
+ const rows = listResponse.data?.data ?? listResponse.data ?? [];
63
+ const match = (0, project_ref_1.matchProjectRungs)(rows, projectName);
64
+ if (match.ambiguous.length > 0) {
65
+ const names = match.ambiguous.map((p) => `${p.name} (${p.slug})`).join(', ');
66
+ console.error(chalk_1.default.red(`"${projectName}" matches more than one project: ${names} — re-run with the exact name or slug.`));
67
+ process.exit(1);
68
+ }
69
+ const hit = match.project;
70
+ if (hit && typeof hit.name === 'string' && hit.name !== projectName) {
71
+ response = await axios_1.default.get(`${config.host}/api/v1/runs`, {
72
+ headers: (0, api_1.getApiHeaders)(config),
73
+ params: { ...params, project: hit.name },
74
+ });
75
+ }
76
+ }
55
77
  const runsList = response.data.data || response.data;
56
78
  // Check server-side error fields FIRST (project_not_found comes back as 200 with data:[])
57
79
  const serverError = response.data.error;
@@ -89,10 +111,10 @@ async function runs(projectName, options = {}) {
89
111
  console.error(chalk_1.default.yellow(`Pass -e <env> to disambiguate, e.g.: solidactions run list ${projectName} -e dev`));
90
112
  }
91
113
  else if (error.response.status === 401) {
92
- console.error(chalk_1.default.red('Authentication failed. Run "solidactions login --global" to re-configure.'));
114
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
93
115
  }
94
116
  else {
95
- console.error(chalk_1.default.red(`Failed: ${error.response.status}`), error.response.data);
117
+ console.error(chalk_1.default.red((0, api_1.formatApiFailure)(error.response.status, error.response.data)));
96
118
  }
97
119
  }
98
120
  else {
@@ -152,7 +174,7 @@ function displaySummaryTable(runsList, projectName) {
152
174
  const run = runsList[i];
153
175
  const [id, workflow, status, revision, triggeredAt, triggeredBy] = rows[i];
154
176
  const { attention } = summaryStatusLabel(run);
155
- const statusColor = attention ? chalk_1.default.yellow : getStatusColor(status);
177
+ const statusColor = attention ? chalk_1.default.yellow : (0, run_status_1.getStatusColor)(status);
156
178
  console.log(chalk_1.default.gray(id.padEnd(widths[0])) +
157
179
  workflow.padEnd(widths[1]) +
158
180
  statusColor(status.padEnd(widths[2])) +
@@ -169,7 +191,7 @@ function displayDetailedList(runsList, projectName) {
169
191
  console.log(chalk_1.default.blue(header));
170
192
  for (const run of runsList) {
171
193
  const status = run.execution_status || run.status || '?';
172
- const statusColor = getStatusColor(status);
194
+ const statusColor = (0, run_status_1.getStatusColor)(status);
173
195
  const exitStr = run.exit_code !== null && run.exit_code !== undefined ? ` (exit ${run.exit_code})` : '';
174
196
  console.log('');
175
197
  const outcomeTag = detailedOutcomeTag(run);
@@ -350,20 +372,3 @@ function truncate(str, max) {
350
372
  return str;
351
373
  return str.substring(0, max - 3) + '...';
352
374
  }
353
- function getStatusColor(status) {
354
- switch (status?.toLowerCase()) {
355
- case 'completed':
356
- case 'success':
357
- return chalk_1.default.green;
358
- case 'running':
359
- return chalk_1.default.blue;
360
- case 'pending':
361
- case 'queued':
362
- return chalk_1.default.yellow;
363
- case 'failed':
364
- case 'error':
365
- return chalk_1.default.red;
366
- default:
367
- return chalk_1.default.gray;
368
- }
369
- }