Skip to content

fix: expand ~ and resolve relative workspace paths - #24

Merged
Asdivyansh merged 2 commits into
SilosLabs:mainfrom
TheDreamSaver:fix/workspace-path-expansion
Nov 19, 2026
Merged

Asdivyansh merged 2 commits into
SilosLabs:mainfrom
TheDreamSaver:fix/workspace-path-expansion

Conversation

@TheDreamSaver

@TheDreamSaver TheDreamSaver commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #23

Problem

The workspace path went to docker run -v <path>:/workspace exactly as typed:

  • The onboard prompt saved ~/silo-workspace, one of the examples in docs/cli-reference.md, literally, and mkdir created a ./~/silo-workspace directory.
  • start --workspace passed its value through unchanged.

Docker treats a non-absolute -v source as a volume name. A bare ws therefore mounted a named volume instead of the host folder, and ~/… or ./… failed.

Change

  • src/utils/paths.ts:
    • expandHome() expands ~, ~/… and ~\….
    • expandHostPath() also resolves relative paths. It moved here, unchanged in behaviour, from start.ts, where --mount uses it.
    • isVolumeName() applies Docker's local volume-name rule.
  • onboard expands the workspace answer before creating the directory and saving the config.
  • resolveWorkspaceMount() (src/utils/workspace.ts) is the single place that decides the /workspace source:
    • A non-empty --workspace wins. An empty one falls back to the config, instead of resolving to the current directory.
    • ~ is expanded, and the folder must exist, as --mount sources must.
    • Older bare-name configs: if the config holds a bare name like ws and that Docker volume exists, start keeps mounting the volume, warns, and prints how to copy the files to a host folder. With no such volume, it refuses with a clear message rather than guessing a base folder. The same applies to any other relative path in the config.
    • A relative --workspace on the command line resolves against the current directory, as a shell user expects.
  • start uses it before touching any container, so a bad path fails cleanly, and logs (Docker volume) when it mounts one.
  • doctor reports exactly what start would mount. status shows the ~-expanded path.
  • Docs: docs/cli-reference.md describes the workspace mount rules and the --workspace fallback.

Tests

  • tests/utils/paths.test.ts: ~, ~/x, ~\x, a bare name, relative segments, an absolute path, ~other, expandHome, and isVolumeName.
  • tests/utils/workspace.test.ts: every branch of resolveWorkspaceMount, with an injected volume lookup, including the empty --workspace and the existing-volume cases.
  • tests/docker/templates.test.ts: the resolved source lands in --volume <source>:/workspace:rw, for a folder and for a named volume.
  • tests/commands/onboard.test.ts: ~/silo-ws and silo-ws are saved as absolute paths. Both cases fail on main.
  • tests/cli.test.ts, using the fake docker with a new volume inspect case:
    • doctor on a ~/ws config;
    • doctor recognising a bare-name volume;
    • start refusing a bare name with no volume;
    • start refusing a missing folder.

npm run typecheck, npm test (394 passing) and npm run build are green. The branch merges cleanly with #13.

Not verified live: Docker wasn't running on this machine, so the Docker-side behaviour (a named volume for a bare name, an error for ~/…) comes from Docker's documented -v behaviour.

The workspace path reached `docker run -v <path>:/workspace` exactly as
typed. The onboard prompt returns raw text, so `~/silo-workspace` (one of the
examples the CLI reference gives) was saved as-is and mkdir created a literal
"./~/silo-workspace", while a bare name such as `ws` would make Docker mount a
named volume instead of the host folder. `start --workspace` passed its value
through the same way.

--mount sources already went through expandHostPath() in start.ts. Move it
to src/utils/paths.ts and use it for the workspace too:

- onboard expands the answer before creating the directory and saving it.
- start expands --workspace and the configured path, so configs saved
  before this fix work without re-running onboard.
- doctor checks the expanded path, so a "~/…" config isn't reported as a
  missing directory, and its fix hint no longer suggests mkdir -p "~/…"
  (quoted, so a shell creates a literal "~").

Fixes SilosLabs#23
@Asdivyansh

Copy link
Copy Markdown
Member

Thanks, this is great, but there are some minor issues here. I have also added some suggestions that we can implement along.

Two things I'd like addressed before merge:

1. Existing configs with a bare name lose their data
A config saved before this PR with a bare name like ws has been mounting the Docker named volume ws, and that's where the user's files are. With this change, start bind-mounts $CWD/ws instead. That's an empty folder, and which one depends on the directory you run start from, so the workspace looks wiped. Could we detect this case and either keep using the volume with a warning, or tell the user how to migrate? At minimum, warn instead of switching silently.

2. --workspace "" now mounts the current directory
Going from opts.workspace ? … : {} to opts.workspace ?? … means an empty value (e.g. -w "$WS" with WS unset) no longer falls back to the config. resolve("") returns the current directory, so the agent gets read/write access to wherever the user happens to be. Switching back to a truthy check fixes it:

workspacePath: expandHostPath(opts.workspace || config.sandbox.workspacePath),

Smaller things, fine here or in a follow-up:

  • start doesn't check that the workspace exists, though --mount sources do. On Linux, Docker creates a missing folder owned by root, and the container (running as user 1001) can't write to it.
  • expandHostPath only handles ~/. On Windows, ~\ws still becomes a literal ~ folder. Something like /^~[\\/]/ would cover both.
  • silo status still prints the raw config path, so it can disagree with what start mounts.
  • It might be simpler to expand the path once where the config is read (e.g. a zod .transform), instead of in each command. That would also cover status and host mounts saved in the config, which are still passed through unexpanded.
  • There's no test of the -v source that start passes to Docker. The fake-docker setup in cli.test.ts could record the run arguments so we can check them.

Review follow-up for SilosLabs#24.

- Older configs could hold a bare name such as `ws`, which Docker mounted as
  the named volume `ws`. Switching that to `$CWD/ws` would hide the user's
  files. A new resolveWorkspaceMount() keeps mounting the volume when it
  exists, with a warning and steps to move to a host folder, and otherwise
  refuses a relative configured path instead of guessing a base folder.
- An empty --workspace ("-w $WS" with WS unset) falls back to the config
  again, instead of resolving to the current directory.
- start refuses a workspace folder that doesn't exist, as --mount already
  does (on Linux, Docker would create it owned by root).
- expandHome()/expandHostPath() also expand Windows-style "~\".
- doctor reports exactly what start would mount; status shows the ~-expanded
  path.
- Tests: resolveWorkspaceMount unit tests (injected volume lookup), the
  -v source in buildRunFlags, and CLI tests for doctor recognising a volume
  and start refusing a bare name with no volume or a missing folder.
@TheDreamSaver

TheDreamSaver commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the careful review. You're right on both blockers. 2972f64 addresses them, and the PR description is updated to match.

1. Bare-name configs: start no longer switches them to $CWD/ws. A new resolveWorkspaceMount() (src/utils/workspace.ts) decides the /workspace source:

  • Existing volume: if the config holds a bare name and docker volume inspect <name> succeeds, start keeps mounting that volume. It warns that the workspace is a named volume and prints a one-line copy command for moving the files to a host folder.
  • No such volume: it refuses with "the workspace path in your config, "ws", is relative…" and suggests setting an absolute path. Other relative paths in the config get the same treatment, rather than resolving against wherever start happens to run.
  • On the command line: a relative --workspace still resolves against the current directory, since that's what a shell user means. An existing volume named there is honoured too.

2. --workspace "": now flag || configured, as you suggested, with a test that an empty value falls back to the config.

Smaller things:

  • Workspace existence: start now refuses a missing folder ("Workspace folder does not exist… mkdir -p …"), the same way --mount does.
  • Windows: ~\ws is expanded now (/^~[\\/]/).
  • status: shows the ~-expanded path. A relative legacy value is shown as stored, rather than as a guessed folder.
  • Normalising in the config schema: I kept the resolution in one function that start and doctor share, rather than a zod .transform, for three reasons. Telling a legacy volume from a folder needs a Docker call. A relative value has no correct base directory at read time, which is exactly the problem in point 1. And a transform would rewrite the stored value on the next writeConfig. Saved host mounts have the same gap, so I've opened Host mounts saved in the config aren't expanded or checked like --mount #25 for that rather than widen this PR.
  • The -v source: a fake-docker test through docker run isn't practical, because start spawns the real proxy daemon (from dist/) before run, which would leave a daemon bound to a port in CI. Instead:
    • buildRunFlags tests check that the resolved source lands in --volume <source>:/workspace:rw, for both a folder and a named volume;
    • unit tests cover every branch of resolveWorkspaceMount;
    • CLI tests drive the refusals through the real start, which exits before any container or daemon work.

394 tests are passing and CI is green.

@Asdivyansh
Asdivyansh merged commit 64748f1 into SilosLabs:main Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workspace paths with ~ or a relative path aren't expanded before docker run

2 participants