@solidactions/cli 3.22.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.
package/README.md CHANGED
@@ -280,6 +280,8 @@ Workspace: <name> — organization <org> (<workspaceId>)
280
280
  - `--local` — write config to `./.solidactions/config.json` in the current folder.
281
281
  - `--global` — write config to `~/.solidactions/config.json` (today's default).
282
282
  - `--gitignore` — with `--local`, auto-add `.solidactions/` to `.gitignore` without prompting.
283
+ - `login` uses `SOLIDACTIONS_HOST` when it is set.
284
+ - An agent that should be credited as itself in SolidActions (for example, docs it pushes are recorded as Agent) logs the CLI in with its own agent token, not a person's key.
283
285
 
284
286
  In interactive shells, `login` without `--local`/`--global` prompts for a location. In non-interactive contexts, one of the flags is required.
285
287
 
@@ -518,6 +520,8 @@ solidactions doc upload logo-v2.png --replace marketing/logo.png
518
520
 
519
521
  **`doc pull --overwrite` is destructive.** If a manifest-tracked file still exists on the server *and* your local copy no longer matches the `body_sha256` recorded at the last pull (i.e. you've edited it and haven't pushed yet), a plain `doc pull` — even with `-y`/`--yes` — refuses with exit 1, naming every modified file, rather than silently discarding your edits. Nothing is written before that refusal. `-y`/`--yes` only bypasses the generic "destination is not empty" prompt; it does not cover locally-modified tracked files. Pass `--overwrite` to discard those local changes and re-pull server content anyway (it also implies `--yes`).
520
522
 
523
+ **`doc pull` never writes through a link or over bytes it does not own.** It refuses before writing anything when a target is a symbolic link, sits under a linked folder inside the destination, or resolves outside it, with or without `--overwrite`. A local file the destination does not track (or tracks without a recorded hash) is replaced only with `--overwrite`; `-y` only answers the confirmation. A file that already holds exactly the server's bytes is simply adopted. A media doc whose download fails is not tracked over a local file.
524
+
521
525
  You do **not** need `--overwrite` to keep an edited file whose doc was deleted on the server — that case is handled by deletion propagation above, on the default path, and the file is kept with a warning.
522
526
 
523
527
  **Getting a doc id.** `doc upload --replace` accepts a docs path (`marketing/hero.png`), so you rarely need an id. If you want one, `doc pull` records it per file in the destination's `.solidactions-docs.json` sidecar, and `import_outputs` returns the ids it created. Note that `--replace` does not update a pulled directory's manifest. If you replace a tracked image out-of-band and leave the local file untouched, the next `doc push` reports it as **unchanged** and does nothing — the content hash matches, so `push` never asks the server. (Edit the local file too, and the drift guard fires as expected.) Re-pull to resync the manifest.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "cli_name": "solidactions",
4
- "cli_version": "3.22.0",
4
+ "cli_version": "3.23.0",
5
5
  "global_options": [
6
6
  {
7
7
  "flags": "-V, --version",
@@ -44,7 +44,10 @@ async function crewEnvMapDatabase(crewArg, key, databaseArg) {
44
44
  console.log(chalk_1.default.yellow(exports.CREW_DATABASE_SCOPE_WARNING));
45
45
  }
46
46
  catch (error) {
47
- if (error.response?.status === 422) {
47
+ if ((error.response?.status ?? error.status) === 401) {
48
+ console.error(chalk_1.default.red((0, api_1.authFailedLine)(config.host)));
49
+ }
50
+ else if (error.response?.status === 422) {
48
51
  console.error(chalk_1.default.red((0, api_1.formatValidationError)(error.response.data)));
49
52
  }
50
53
  else if (typeof error.message === 'string') {
@@ -47,6 +47,7 @@ const os_1 = __importDefault(require("os"));
47
47
  const path_1 = __importDefault(require("path"));
48
48
  const url_1 = require("url");
49
49
  const client_1 = require("@libsql/client");
50
+ const host_display_1 = require("../utils/host-display");
50
51
  const database_data_plane_1 = require("../utils/database-data-plane");
51
52
  const database_1 = require("./database");
52
53
  const MAX_BYTES = 20_000_000_000;
@@ -281,7 +282,7 @@ async function databasePushWithConfig(name, file, options, config, dependencies
281
282
  return value;
282
283
  };
283
284
  const controlRemaining = () => Math.min(database_data_plane_1.DEFAULT_DATABASE_CONTROL_PLANE_TIMEOUT_MS, remaining());
284
- stdout(`WARNING: This destructively replaces database "${name}" in workspace ${config.workspaceId ?? '(none)'} on ${config.host}. Quiesce all writers; old URLs and credentials will become invalid. A private snapshot is normalized to WAL, 4096-byte pages, and auto-vacuum NONE; the source file is unchanged.`);
285
+ stdout(`WARNING: This destructively replaces database "${name}" in workspace ${config.workspaceId ?? '(none)'} on ${(0, host_display_1.displayHost)(config.host)}. Quiesce all writers; old URLs and credentials will become invalid. A private snapshot is normalized to WAL, 4096-byte pages, and auto-vacuum NONE; the source file is unchanged.`);
285
286
  stdout(`Hard deadline: ${Math.ceil(deadlineMs / 60_000)} minutes for ${normalized.inputBytes} bytes. Idempotency key: ${key}`);
286
287
  const prepareBody = {
287
288
  operation: 'bulk_load_prepare', name, bulk_mode: 'replace', input_bytes: normalized.inputBytes,
@@ -27,6 +27,7 @@ const js_yaml_1 = __importDefault(require("js-yaml"));
27
27
  const prompts_1 = __importDefault(require("prompts"));
28
28
  const env_1 = require("../utils/env");
29
29
  const api_1 = require("../utils/api");
30
+ const host_display_1 = require("../utils/host-display");
30
31
  const deploy_ignore_1 = require("../utils/deploy-ignore");
31
32
  const slug_1 = require("../utils/slug");
32
33
  const project_ref_1 = require("../utils/project-ref");
@@ -626,7 +627,7 @@ async function deploy(projectName, sourcePath, options = {}) {
626
627
  }
627
628
  console.log(chalk_1.default.yellow('Uploading...'));
628
629
  if (process.env.SOLIDACTIONS_DEPLOY_DEBUG === '1') {
629
- process.stderr.write(`[deploy-debug] POST ${config.host}/api/v1/projects/${projectSlug}/deploy (workspace=${config.workspaceId ?? '(none)'})\n`);
630
+ process.stderr.write(`[deploy-debug] POST ${(0, host_display_1.displayHost)(config.host)}/api/v1/projects/${projectSlug}/deploy (workspace=${config.workspaceId ?? '(none)'})\n`);
630
631
  }
631
632
  const deployResponse = await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/deploy`, form, {
632
633
  headers: {
@@ -646,7 +647,7 @@ async function deploy(projectName, sourcePath, options = {}) {
646
647
  console.log(chalk_1.default.green('Deployment successfully queued!'));
647
648
  console.log(chalk_1.default.yellow('Waiting for build to complete...\n'));
648
649
  if (process.env.SOLIDACTIONS_DEPLOY_DEBUG === '1') {
649
- process.stderr.write(`[deploy-debug] poll URL = ${config.host}/api/v1/projects/${projectSlug} (workspace=${config.workspaceId ?? '(none)'})\n`);
650
+ process.stderr.write(`[deploy-debug] poll URL = ${(0, host_display_1.displayHost)(config.host)}/api/v1/projects/${projectSlug} (workspace=${config.workspaceId ?? '(none)'})\n`);
650
651
  }
651
652
  // Poll for completion
652
653
  let attempts = 0;
@@ -9,6 +9,7 @@ exports.deviceLogin = deviceLogin;
9
9
  const axios_1 = __importDefault(require("axios"));
10
10
  const chalk_1 = __importDefault(require("chalk"));
11
11
  require("../utils/api");
12
+ const host_display_1 = require("../utils/host-display");
12
13
  const workspace_lookup_1 = require("../utils/workspace-lookup");
13
14
  const login_1 = require("./login");
14
15
  // Public device-flow client id — not a secret; matches the server-seeded
@@ -106,7 +107,7 @@ async function pollForToken(host, clientId, deviceCode, intervalSeconds, expires
106
107
  }
107
108
  }
108
109
  async function deviceLogin(options) {
109
- const resolved = (0, login_1.resolveLoginHost)(options);
110
+ const resolved = (0, login_1.resolveLoginHostOrExit)(options);
110
111
  const host = resolved.host;
111
112
  const preflight = await (0, login_1.preflightDeviceLoginWrite)(options);
112
113
  console.log(chalk_1.default.blue('Requesting device authorization...'));
@@ -138,7 +139,7 @@ async function deviceLogin(options) {
138
139
  }
139
140
  catch (e) {
140
141
  if (e.response?.status === 401) {
141
- console.error(chalk_1.default.red(`Authentication was saved to ${preflight.targetPath}, but the server rejected it during workspace discovery.`));
142
+ console.error(chalk_1.default.red(`Authentication was saved to ${preflight.targetPath}, but ${(0, host_display_1.displayHost)(host)} rejected it during workspace discovery.`));
142
143
  }
143
144
  else {
144
145
  console.error(chalk_1.default.red(`Authentication was saved to ${preflight.targetPath}, but workspace discovery failed: ${e.message}`));
@@ -486,7 +486,7 @@ async function docPullWithConfig(folderPath, dest, options, config) {
486
486
  const entries = fs_1.default.readdirSync(destination);
487
487
  if (entries.length > 0 && !options.yes && !options.overwrite) {
488
488
  console.log(chalk_1.default.yellow(`Destination "${destination}" is not empty (${entries.length} items).`));
489
- console.log(chalk_1.default.yellow('Pulling will overwrite existing files.'));
489
+ console.log(chalk_1.default.yellow("Pulling overwrites tracked files; local files the folder doesn't track are refused unless --overwrite."));
490
490
  const response = await (0, prompts_1.default)({
491
491
  type: 'confirm',
492
492
  name: 'proceed',
@@ -619,6 +619,133 @@ function physicalTargetPath(absPath) {
619
619
  }
620
620
  }
621
621
  }
622
+ /** The first symbolic link on `rel`'s way (inside `destination`, the destination itself excluded), as a relative path; null when there is none. */
623
+ function linkOnTheWay(destination, rel) {
624
+ const parts = rel.split('/');
625
+ for (let i = 1; i <= parts.length; i++) {
626
+ const abs = path_1.default.join(destination, ...parts.slice(0, i));
627
+ try {
628
+ if (fs_1.default.lstatSync(abs).isSymbolicLink())
629
+ return parts.slice(0, i).join('/');
630
+ }
631
+ catch {
632
+ return null; // the rest does not exist yet
633
+ }
634
+ }
635
+ return null;
636
+ }
637
+ function refuseLink(rel, link, doc) {
638
+ const where = link === rel ? '' : ` (or sits under one: ${link})`;
639
+ process.stderr.write(chalk_1.default.red(`error: ${rel} is a symbolic link${where}; this pull would write doc ${doc.id} ("${doc.title}") through it.\n`));
640
+ process.stderr.write(chalk_1.default.red('Replace it with a regular file or folder and pull again.\n'));
641
+ process.exit(1);
642
+ }
643
+ /** One line for a path that cannot be resolved (spec §2.3): the ELOOP wording, or the error code and message. Never returns. */
644
+ function explainUnresolvable(label, error) {
645
+ const code = error.code ?? 'ERROR';
646
+ const reason = code === 'ELOOP' ? 'too many symbolic links (ELOOP). Fix or remove the link and pull again.' : `${code} ${error.message}.`;
647
+ process.stderr.write(chalk_1.default.red(`error: cannot resolve ${label}: ${reason}\n`));
648
+ process.exit(1);
649
+ }
650
+ /** physicalTargetPath, but a resolution error becomes one line (spec §2.3). A planned target with a link on the way gets the symbolic-link refusal. */
651
+ function resolveOrExplain(destination, rel, target) {
652
+ const abs = path_1.default.resolve(destination, ...rel.split('/'));
653
+ try {
654
+ return physicalTargetPath(abs);
655
+ }
656
+ catch (error) {
657
+ if (target) {
658
+ const link = linkOnTheWay(destination, rel);
659
+ if (link !== null)
660
+ refuseLink(rel, link, target);
661
+ }
662
+ explainUnresolvable(rel, error);
663
+ }
664
+ }
665
+ /**
666
+ * Refuse, before any write, a pull that would write a planned doc through a
667
+ * symbolic link or to a place that resolves outside the destination. Covers
668
+ * every planned doc, including a failed media download: commitDocs still
669
+ * creates its directory. Also refuse, unless `--overwrite`, a planned write
670
+ * over a regular file the pull does not own (cli#167): one the previous
671
+ * manifest does not track with a hash and whose bytes differ from the
672
+ * pulled ones. A file already holding the pulled bytes is adopted, and a
673
+ * rename's own source file (a case-only retitle on a case-insensitive
674
+ * filesystem) is never "untracked".
675
+ */
676
+ function checkPlannedWrites(destination, planned, previousManifest, options, renameMoves) {
677
+ // First, so a destination that is itself a looping link gets one line, not a raw ELOOP from the sidecar check below.
678
+ let realDest;
679
+ try {
680
+ realDest = physicalTargetPath(path_1.default.resolve(destination));
681
+ }
682
+ catch (error) {
683
+ explainUnresolvable(destination, error);
684
+ }
685
+ // The manifest sidecar is written at the end of every pull: never through a link.
686
+ try {
687
+ if (fs_1.default.lstatSync(path_1.default.join(destination, docs_manifest_1.DOCS_MANIFEST)).isSymbolicLink()) {
688
+ process.stderr.write(chalk_1.default.red(`error: ${docs_manifest_1.DOCS_MANIFEST} is a symbolic link; this pull would write the docs manifest through it.\n`));
689
+ process.stderr.write(chalk_1.default.red('Replace it with a regular file or folder and pull again.\n'));
690
+ process.exit(1);
691
+ }
692
+ }
693
+ catch (error) {
694
+ if (error.code !== 'ENOENT')
695
+ explainUnresolvable(docs_manifest_1.DOCS_MANIFEST, error);
696
+ }
697
+ for (const p of planned) {
698
+ const link = linkOnTheWay(destination, p.relPath);
699
+ if (link !== null)
700
+ refuseLink(p.relPath, link, p.doc);
701
+ const physical = resolveOrExplain(destination, p.relPath, p.doc);
702
+ // Belt and braces behind linkOnTheWay, which refuses every link first; kept in case the physical path ever diverges without one.
703
+ if (physical !== realDest && !physical.startsWith(realDest + path_1.default.sep)) {
704
+ process.stderr.write(chalk_1.default.red(`error: ${p.relPath} resolves outside the destination (${physical}); this pull would write doc ${p.doc.id} ("${p.doc.title}") there.\n`));
705
+ process.exit(1);
706
+ }
707
+ }
708
+ if (options.overwrite)
709
+ return;
710
+ const untracked = [];
711
+ for (const p of planned) {
712
+ if (p.isMedia && p.mediaBytes === null)
713
+ continue; // a failed download writes nothing
714
+ const tracked = previousManifest?.docs[p.relPath];
715
+ if (tracked !== undefined && tracked.body_sha256 != null)
716
+ continue; // checked as unpushed local changes
717
+ const targetAbs = path_1.default.join(destination, ...p.relPath.split('/'));
718
+ let targetStat;
719
+ let current;
720
+ try {
721
+ targetStat = fs_1.default.statSync(targetAbs);
722
+ if (!targetStat.isFile())
723
+ continue;
724
+ current = fs_1.default.readFileSync(targetAbs);
725
+ }
726
+ catch (error) {
727
+ const code = error.code ?? 'ERROR';
728
+ if (code === 'ENOENT')
729
+ continue; // absent: nothing to overwrite here
730
+ untracked.push(`${p.relPath} (cannot be read: ${code})`); // present but unverifiable: not owned
731
+ continue;
732
+ }
733
+ if ((0, docs_manifest_1.sha256Hex)(current) === p.bodySha256)
734
+ continue;
735
+ const ownSource = renameMoves.find((m) => m.id === p.doc.id)?.sourceIdentity;
736
+ if (ownSource === `${targetStat.dev}:${targetStat.ino}`)
737
+ continue;
738
+ untracked.push(p.relPath);
739
+ }
740
+ if (untracked.length > 0) {
741
+ const one = untracked.length === 1;
742
+ process.stderr.write(chalk_1.default.red(`${untracked.length} ${one ? 'file exists' : 'files exist'} locally but ${one ? 'is' : 'are'} not tracked:\n`));
743
+ for (const rel of untracked)
744
+ process.stderr.write(chalk_1.default.red(` ${rel}\n`));
745
+ process.stderr.write(chalk_1.default.red('Move them aside and pull again, or pass --overwrite to replace them.\n'));
746
+ process.exit(1);
747
+ }
748
+ }
622
749
  /** Write the docs + manifest to disk and print the result (chalk lines or --json). */
623
750
  async function report(destination, folderPath, fetched, options, config, extraWarnings, previousManifest, usedSingleDocFallback) {
624
751
  // Single-doc fallback merging into a manifest that tracks the same folder
@@ -646,6 +773,18 @@ async function report(destination, folderPath, fetched, options, config, extraWa
646
773
  reserved = { usedNames, pathById, titleById };
647
774
  }
648
775
  const { planned, warnings } = await planDocs(fetched, config, reserved, previousManifest);
776
+ // Same doc id under a different path is a rename (PM ruling 2, cli#157):
777
+ // the previous manifest tracks a planned doc under a DIFFERENT path `old`,
778
+ // whatever is on disk at `old` (cli#157 FR4-C1). What is at `old` decides
779
+ // only what happens to `old`; the target checks below apply to every
780
+ // rename. Every rename ends one of three ways:
781
+ // (a) `old` is removed only after its replacement is written (nothing to
782
+ // remove when `old` holds no regular file);
783
+ // (b) `old`'s tracking (and file, if any) is kept, the replacement is
784
+ // not written;
785
+ // (c) the pull refuses here, before any write.
786
+ // Never: bytes lost, an untracked file overwritten without --overwrite,
787
+ // or one doc's tracking attached to another doc's bytes.
649
788
  const renameMoves = [];
650
789
  if (previousManifest) {
651
790
  const pathById = new Map();
@@ -704,7 +843,7 @@ async function report(destination, folderPath, fetched, options, config, extraWa
704
843
  const plannedByIdentity = new Map();
705
844
  const plannedByPhysicalPath = new Map();
706
845
  for (const p of planned) {
707
- const physicalPath = physicalTargetPath(path_1.default.resolve(destination, ...p.relPath.split('/')));
846
+ const physicalPath = resolveOrExplain(destination, p.relPath, p.doc);
708
847
  const physicalTargets = plannedByPhysicalPath.get(physicalPath) ?? [];
709
848
  physicalTargets.push(p);
710
849
  plannedByPhysicalPath.set(physicalPath, physicalTargets);
@@ -726,7 +865,7 @@ async function report(destination, folderPath, fetched, options, config, extraWa
726
865
  // its old tracking). Present sources also need protection from writes
727
866
  // through another name, hard link, symlink or directory component alias.
728
867
  const plannedTargetForSource = (m) => plannedPaths.get(m.oldRel)
729
- ?? plannedByPhysicalPath.get(physicalTargetPath(path_1.default.resolve(destination, ...m.oldRel.split('/'))))?.find((p) => p.doc.id !== m.id)
868
+ ?? plannedByPhysicalPath.get(resolveOrExplain(destination, m.oldRel))?.find((p) => p.doc.id !== m.id)
730
869
  ?? (m.sourceIdentity === null
731
870
  ? undefined
732
871
  : plannedByIdentity.get(m.sourceIdentity)?.find((p) => p.doc.id !== m.id));
@@ -828,18 +967,22 @@ async function report(destination, folderPath, fetched, options, config, extraWa
828
967
  if (targetEntry !== undefined && targetEntry.body_sha256 != null)
829
968
  continue;
830
969
  const absNew = path_1.default.join(destination, ...m.newRel.split('/'));
831
- let existing;
970
+ let existing = null;
971
+ let unreadable = '';
832
972
  try {
833
973
  if (!fs_1.default.statSync(absNew).isFile())
834
974
  continue;
835
975
  existing = fs_1.default.readFileSync(absNew);
836
976
  }
837
- catch {
838
- continue;
977
+ catch (error) {
978
+ const code = error.code ?? 'ERROR';
979
+ if (code === 'ENOENT')
980
+ continue;
981
+ unreadable = ` (cannot be read: ${code})`; // present but unverifiable: not owned
839
982
  }
840
- if ((0, docs_manifest_1.sha256Hex)(existing) === plannedPaths.get(m.newRel)?.bodySha256)
983
+ if (existing !== null && (0, docs_manifest_1.sha256Hex)(existing) === plannedPaths.get(m.newRel)?.bodySha256)
841
984
  continue;
842
- const state = targetEntry === undefined ? 'exists locally but is not tracked' : `holds local bytes with no recorded hash (tracked for doc ${targetEntry.id})`;
985
+ const state = (targetEntry === undefined ? 'exists locally but is not tracked' : `holds local bytes with no recorded hash (tracked for doc ${targetEntry.id})`) + unreadable;
843
986
  process.stderr.write(chalk_1.default.red(`error: ${m.newRel} ${state}; this pull would overwrite it with doc ${m.id} ("${m.title}", renamed from ${m.oldRel}).\n`));
844
987
  process.stderr.write(chalk_1.default.red(`Move ${m.newRel} aside and pull again, or pass --overwrite to replace it.\n`));
845
988
  process.exit(1);
@@ -847,6 +990,9 @@ async function report(destination, folderPath, fetched, options, config, extraWa
847
990
  }
848
991
  }
849
992
  const handledOldPaths = new Set(renameMoves.map((m) => m.oldRel));
993
+ // After the rename block (which keeps its own messages for rename cases) and before anything
994
+ // else that reads or writes the plan: no planned write may go through a link or outside.
995
+ checkPlannedWrites(destination, planned, previousManifest, options, renameMoves);
850
996
  // Unpushed-local-changes protection: now that the server walk is known, refuse only
851
997
  // for a file whose doc still exists remotely — i.e. its relative path is part of this
852
998
  // pull's plan and would be overwritten by commitDocs below. A modified file whose
@@ -882,15 +1028,44 @@ async function report(destination, folderPath, fetched, options, config, extraWa
882
1028
  const destPrefix = path_1.default.resolve(destination) + path_1.default.sep;
883
1029
  const realDest = fs_1.default.realpathSync(destination);
884
1030
  const { manifestDocs, files } = commitDocs(destination, planned);
1031
+ // cli#167: a media doc whose download failed must not be tracked over a
1032
+ // local file the previous manifest does not track, with a hash, for that
1033
+ // same doc: nothing was written, so the manifest would claim bytes the
1034
+ // pull never gave it. A rename keeps its restore-old-entry handling below.
1035
+ const renamedIds = new Set(renameMoves.map((m) => m.id));
1036
+ for (const p of planned) {
1037
+ if (!p.isMedia || p.mediaBytes !== null || renamedIds.has(p.doc.id))
1038
+ continue;
1039
+ const tracked = previousManifest?.docs[p.relPath];
1040
+ if (tracked !== undefined && tracked.id === p.doc.id && tracked.body_sha256 != null)
1041
+ continue;
1042
+ let holdsLocalFile = false;
1043
+ try {
1044
+ holdsLocalFile = fs_1.default.statSync(path_1.default.join(destination, ...p.relPath.split('/'))).isFile();
1045
+ }
1046
+ catch {
1047
+ holdsLocalFile = false;
1048
+ }
1049
+ if (!holdsLocalFile)
1050
+ continue;
1051
+ delete manifestDocs[p.relPath];
1052
+ process.stderr.write(chalk_1.default.yellow(`! doc ${p.doc.id} ("${p.doc.title}") failed to download and ${p.relPath} holds a local file; not tracking it — pull again later\n`));
1053
+ }
885
1054
  // Identity of every file this pull actually wrote, keyed by dev:ino. Used by the
886
1055
  // deletion-propagation loop below to recognize an "orphan" that is really just the
887
1056
  // same file this pull wrote under a different manifest key (e.g. a case-only title
888
1057
  // rename on a case-insensitive filesystem) — that file must never be deleted.
1058
+ // writtenPathByIdentity names the path this pull wrote for each identity, so
1059
+ // rename cleanup can warn instead of silently keeping an old path that
1060
+ // aliases a written file (cli#167 M2).
889
1061
  const writtenIdentities = new Set();
1062
+ const writtenPathByIdentity = new Map();
890
1063
  for (const file of files) {
891
1064
  try {
892
1065
  const stat = fs_1.default.statSync(path_1.default.join(destination, ...file.path.split('/')));
893
- writtenIdentities.add(`${stat.dev}:${stat.ino}`);
1066
+ const identity = `${stat.dev}:${stat.ino}`;
1067
+ writtenIdentities.add(identity);
1068
+ writtenPathByIdentity.set(identity, file.path);
894
1069
  }
895
1070
  catch {
896
1071
  continue;
@@ -924,6 +1099,25 @@ async function report(destination, folderPath, fetched, options, config, extraWa
924
1099
  if (!m.sourcePresent)
925
1100
  continue;
926
1101
  const absOld = path_1.default.resolve(destination, ...m.oldRel.split('/'));
1102
+ // cli#167 M2: the old path is the same file as one this pull just
1103
+ // wrote under another name (a link) — it is kept, loudly, so the
1104
+ // extra name is not mistaken for an orphan. The same-file case
1105
+ // (targetIsSource) stays silent: there is no extra name.
1106
+ if (!m.targetIsSource) {
1107
+ let oldIdentity = null;
1108
+ try {
1109
+ const oldStat = fs_1.default.statSync(absOld);
1110
+ if (oldStat.isFile())
1111
+ oldIdentity = `${oldStat.dev}:${oldStat.ino}`;
1112
+ }
1113
+ catch {
1114
+ oldIdentity = null;
1115
+ }
1116
+ const writtenPath = oldIdentity === null ? undefined : writtenPathByIdentity.get(oldIdentity);
1117
+ if (writtenPath !== undefined) {
1118
+ process.stderr.write(chalk_1.default.yellow(`! kept ${m.oldRel}: it is the same file as ${writtenPath} (a link); the extra name is not tracked — remove it yourself if you don't need it\n`));
1119
+ }
1120
+ }
927
1121
  if (!isSafeToRemoveTrackedFile(absOld, destPrefix, realDest, writtenIdentities))
928
1122
  continue;
929
1123
  try {
@@ -3,10 +3,11 @@ 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.DEVICE_LOGIN_REFUSAL_MESSAGE = exports.API_KEY_PROMPT = exports.selectWorkspaceInteractively = void 0;
6
+ exports.DEVICE_LOGIN_REFUSAL_MESSAGE = exports.LoginHostInvalidError = exports.LoginHostConflictError = exports.API_KEY_PROMPT = exports.selectWorkspaceInteractively = void 0;
7
7
  exports.resolveLoginApiKey = resolveLoginApiKey;
8
8
  exports.clearConfig = clearConfig;
9
9
  exports.resolveLoginHost = resolveLoginHost;
10
+ exports.resolveLoginHostOrExit = resolveLoginHostOrExit;
10
11
  exports.backupPathFor = backupPathFor;
11
12
  exports.preflightDeviceLoginWrite = preflightDeviceLoginWrite;
12
13
  exports.persistPreflightedLoginCredential = persistPreflightedLoginCredential;
@@ -22,6 +23,7 @@ const prompts_1 = __importDefault(require("prompts"));
22
23
  const config_1 = require("../utils/config");
23
24
  const config_write_target_1 = require("../utils/config-write-target");
24
25
  const workspace_lookup_1 = require("../utils/workspace-lookup");
26
+ const host_display_1 = require("../utils/host-display");
25
27
  var workspace_lookup_2 = require("../utils/workspace-lookup");
26
28
  Object.defineProperty(exports, "selectWorkspaceInteractively", { enumerable: true, get: function () { return workspace_lookup_2.selectWorkspaceInteractively; } });
27
29
  exports.API_KEY_PROMPT = {
@@ -73,15 +75,76 @@ async function resolveLoginApiKey(apiKey, options = {}, dependencies = {}) {
73
75
  function clearConfig() {
74
76
  (0, config_1.removeConfigFile)((0, config_1.getGlobalConfigPath)());
75
77
  }
76
- function resolveLoginHost(options) {
77
- if (options.host) {
78
- return { host: options.host, isDefault: false };
78
+ class LoginHostConflictError extends Error {
79
+ flag;
80
+ envHost;
81
+ constructor(flag, envHost) {
82
+ super(`${flag} disagrees with SOLIDACTIONS_HOST=${(0, host_display_1.displayHost)(envHost)}; refusing to send the API key.`);
83
+ this.flag = flag;
84
+ this.envHost = envHost;
79
85
  }
80
- if (options.dev) {
81
- return { host: 'http://localhost:8000', isDefault: false };
86
+ }
87
+ exports.LoginHostConflictError = LoginHostConflictError;
88
+ class LoginHostInvalidError extends Error {
89
+ label;
90
+ raw;
91
+ constructor(label, raw) {
92
+ super(`${label}=${JSON.stringify(raw)} is not a usable host; refusing to send the API key.`);
93
+ this.label = label;
94
+ this.raw = raw;
82
95
  }
96
+ }
97
+ exports.LoginHostInvalidError = LoginHostInvalidError;
98
+ function resolveLoginHost(options, env = process.env) {
99
+ const strip = (h) => h.trim().replace(/\/+$/, '');
100
+ // Ruling 9: a non-empty value that strips to nothing is INVALID, never "absent".
101
+ const usable = (raw, label) => {
102
+ const value = strip(raw);
103
+ if (value === '')
104
+ throw new LoginHostInvalidError(label, raw);
105
+ return value;
106
+ };
107
+ const rawEnv = env.SOLIDACTIONS_HOST;
108
+ const envHost = rawEnv !== undefined && rawEnv.trim() !== '' ? usable(rawEnv, 'SOLIDACTIONS_HOST') : undefined;
109
+ const explicitHostFlag = (raw) => {
110
+ const host = usable(raw, '--host');
111
+ return { host, flag: `--host ${(0, host_display_1.displayHost)(host)}` };
112
+ };
113
+ const explicit = options.host !== undefined
114
+ ? explicitHostFlag(options.host)
115
+ : options.dev
116
+ ? { host: 'http://localhost:8000', flag: '--dev (http://localhost:8000)' }
117
+ : undefined;
118
+ if (explicit && envHost && (0, config_1.normalizeHost)(explicit.host) !== (0, config_1.normalizeHost)(envHost)) {
119
+ throw new LoginHostConflictError(explicit.flag, envHost);
120
+ }
121
+ if (explicit)
122
+ return { host: explicit.host, isDefault: false };
123
+ if (envHost)
124
+ return { host: envHost, isDefault: false };
83
125
  return { host: 'https://app.solidactions.com', isDefault: true };
84
126
  }
127
+ /**
128
+ * `resolveLoginHost` for the login commands: a refused host prints the
129
+ * refusal to stderr and exits 1 before any request or config write.
130
+ */
131
+ function resolveLoginHostOrExit(options) {
132
+ try {
133
+ return resolveLoginHost(options);
134
+ }
135
+ catch (error) {
136
+ if (error instanceof LoginHostConflictError) {
137
+ console.error(chalk_1.default.red(`error: ${error.message}`));
138
+ console.error(chalk_1.default.red('Unset SOLIDACTIONS_HOST or pass the same host to --host.'));
139
+ process.exit(1);
140
+ }
141
+ if (error instanceof LoginHostInvalidError) {
142
+ console.error(chalk_1.default.red(`error: ${error.message}`));
143
+ process.exit(1);
144
+ }
145
+ throw error;
146
+ }
147
+ }
85
148
  /**
86
149
  * Path for a timestamped backup of `targetPath`, e.g.
87
150
  * `config.json.bak-2026-07-05T12-30-00Z`. Pure — takes `now` so tests are
@@ -203,9 +266,9 @@ async function persistPreflightedLoginCredential(config, preflight, options) {
203
266
  }
204
267
  function loginHostLines(resolved) {
205
268
  if (resolved.isDefault) {
206
- return [`Logging into ${resolved.host} (SolidActions Cloud)`];
269
+ return [`Logging into ${(0, host_display_1.displayHost)(resolved.host)} (SolidActions Cloud)`];
207
270
  }
208
- return [`Host: ${resolved.host}`];
271
+ return [`Host: ${(0, host_display_1.displayHost)(resolved.host)}`];
209
272
  }
210
273
  /**
211
274
  * Shared tail of API-key and device login: resolve the workspace against an
@@ -361,11 +424,11 @@ async function completeLogin(config, workspaces, options, scope = null, prefligh
361
424
  }
362
425
  }
363
426
  async function login(apiKey, options) {
364
- const resolved = resolveLoginHost(options);
427
+ const resolved = resolveLoginHostOrExit(options);
365
428
  const host = resolved.host;
366
429
  if (!apiKey || apiKey.trim().length === 0) {
367
430
  console.error(chalk_1.default.red('Error: API key is required.'));
368
- console.log(chalk_1.default.gray('Generate an API key at: ') + chalk_1.default.blue(`${host}/settings/api-keys`));
431
+ console.log(chalk_1.default.gray('Generate an API key at: ') + chalk_1.default.blue(`${(0, host_display_1.displayHost)(host)}/settings/api-keys`));
369
432
  process.exit(1);
370
433
  }
371
434
  console.log(chalk_1.default.blue(`Initializing SolidActions CLI...`));
@@ -384,10 +447,10 @@ async function login(apiKey, options) {
384
447
  }
385
448
  catch (e) {
386
449
  if (e.response?.status === 401) {
387
- console.error(chalk_1.default.red(`Invalid API key for ${host}.`));
450
+ console.error(chalk_1.default.red(`Invalid API key for ${(0, host_display_1.displayHost)(host)}.`));
388
451
  }
389
452
  else {
390
- console.error(chalk_1.default.red(`Could not reach ${host}: ${e.message}`));
453
+ console.error(chalk_1.default.red(`Could not reach ${(0, host_display_1.displayHost)(host)}: ${e.message}`));
391
454
  }
392
455
  process.exit(1);
393
456
  return;
@@ -460,7 +523,7 @@ function whoami() {
460
523
  ? `${workspaceName} — organization ${config.workspaceOrg}${config.workspaceId ? ` (${config.workspaceId})` : ''}`
461
524
  : `${workspaceName}${config.workspaceId ? ` (${config.workspaceId})` : ''}`;
462
525
  console.log(chalk_1.default.blue('Current configuration:'));
463
- console.log(` Host: ${config.host.padEnd(50)} ${fmt(sources.host)}`);
526
+ console.log(` Host: ${(0, host_display_1.displayHost)(config.host).padEnd(50)} ${fmt(sources.host)}`);
464
527
  console.log(` API Key: ${maskedKey.padEnd(50)} ${fmt(sources.apiKey)}`);
465
528
  console.log(` Workspace: ${workspaceLabel.padEnd(50)} ${fmt(sources.workspaceId)}`);
466
529
  }
@@ -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
  }
@@ -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, host) {
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((0, api_1.authFailedLine)(host)));
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, host) {
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, host) {
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, config.host);
121
+ await printWorkflowViewError(error, config, project, environment);
106
122
  process.exit(1);
107
123
  }
108
124
  }
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;
@@ -15,7 +15,6 @@ exports.describeProjectEnvironments = describeProjectEnvironments;
15
15
  exports.formatValidationError = formatValidationError;
16
16
  exports.requireResolvedConfig = requireResolvedConfig;
17
17
  exports.requireConfig = requireConfig;
18
- exports.displayHost = displayHost;
19
18
  exports.authFailureMessage = authFailureMessage;
20
19
  exports.formatApiFailure = formatApiFailure;
21
20
  exports.authFailedLine = authFailedLine;
@@ -29,6 +28,8 @@ const path_1 = __importDefault(require("path"));
29
28
  const prompts_1 = __importDefault(require("prompts"));
30
29
  const config_1 = require("./config");
31
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; } });
32
33
  const mutating_commands_1 = require("./mutating-commands");
33
34
  const project_ref_1 = require("./project-ref");
34
35
  const workspace_guard_1 = require("./workspace-guard");
@@ -300,26 +301,6 @@ function requireResolvedConfig() {
300
301
  function requireConfig() {
301
302
  return requireResolvedConfig().config;
302
303
  }
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
- }
323
304
  /**
324
305
  * Contextual 401 message — names the host being called and where the (now
325
306
  * apparently invalid/expired) API key came from, instead of a bare
@@ -327,7 +308,7 @@ function displayHost(host) {
327
308
  */
328
309
  function authFailureMessage(config, sources) {
329
310
  const keySource = sources?.apiKey ?? 'config';
330
- return `Authentication failed against ${displayHost(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.`;
331
312
  }
332
313
  /**
333
314
  * One line for a failed API response: the server's `message` when it sent one, else the
@@ -344,7 +325,7 @@ function formatApiFailure(status, data) {
344
325
  }
345
326
  /** The one-line 401 every command prints: names the host that refused the key (cli#156), never its userinfo. */
346
327
  function authFailedLine(host) {
347
- return `Authentication failed against ${displayHost(host)}. Run "solidactions login --global" to re-configure.`;
328
+ return `Authentication failed against ${(0, host_display_1.displayHost)(host)}. Run "solidactions login --global" to re-configure.`;
348
329
  }
349
330
  async function ensureWorkspaceSelected(config, dependencies = {}) {
350
331
  if (config.workspaceId) {
@@ -549,7 +530,7 @@ async function applyWorkspaceGuard(config, sources, options, io = {}) {
549
530
  }
550
531
  if (options.mutating && config.workspaceId) {
551
532
  // 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}`));
533
+ announce(chalk_1.default.gray(`Workspace: ${describeWorkspace(config, sources)} on ${(0, host_display_1.displayHost)(config.host)}`));
553
534
  }
554
535
  // state.json means "the workspace you last WROTE to" — that is precisely what the write
555
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
  }
@@ -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
+ }
@@ -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.22.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": {