Repository navigation
fs/gateway: resolve relative paths to the workspace, not the launch CWD - #408
Conversation
The fs tools resolved a relative path arg (write_file "index.html") with ExpandFileName -- i.e. against the process's current directory. On a gateway / serve run that's wherever the service was launched, so files landed somewhere the web UI Files tab never shows, and the system prompt advertised a *third* location (the .pasclaw home dir) as "your workspace". The operator had to hand-steer every write with an absolute path. - New Sandbox.ResolveWorkspacePath: relative paths resolve against CurrentWorkspace (the configured workspace, or the launch dir when unset); absolute paths pass through. All fs tools -- read/write/append/ edit (string + hashline) / list / grep / apply_patch -- call it before the CanRead/CanWritePath gate. - gateway + serve now default the working directory to $PASCLAW_HOME/workspace (the dir the Files tab browses) when sandbox.workspace is unset, instead of the launch CWD. An explicit sandbox.workspace still wins. CLI agent/tui/build are unchanged (they keep resolving relative paths against the project CWD). - The system prompt's Workspace section now advertises the actual working directory and states that relative paths resolve there, so the model writes to the right place without being told. Test: workspace_paths_tests -- ResolveWorkspacePath (relative->workspace, absolute->itself) and write/read/append relative paths land in the configured workspace, not the launch CWD. Verified end-to-end through the relay: a default gateway launched from an unrelated dir lands a relative write in $PASCLAW_HOME/workspace. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f110f4755e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Result := | ||
| '## Workspace' + sLineBreak + | ||
| 'Your workspace is at: ' + Home + sLineBreak + | ||
| 'Your working directory is: ' + WorkDir + sLineBreak + |
There was a problem hiding this comment.
Avoid labeling the FS workspace as the process cwd
In default gateway/serve local-backend runs with sandbox.restrict_to_workspace=false, the new startup path sets CurrentWorkspace to $PASCLAW_HOME/workspace, and the FS tools now resolve write_file("x") there, but shell_exec still leaves WorkDir empty when restriction is inactive (checked src/pkg/tools/PasClaw.Tools.Shell.pas:104-107), so shell commands inherit the launch cwd. This prompt line tells the model that CurrentWorkspace is its working directory, which makes common flows like write_file("x") followed by shell_exec("cat x") look in two different directories.
Useful? React with 👍 / 👎.
…eview fix)
shell_exec pinned its cwd to the workspace only when
restrict_to_workspace was on; with restriction off (the default) it
inherited the process launch cwd. After the FS tools began resolving
relative paths against CurrentWorkspace, that split the two: on a default
gateway/serve run write_file("x") wrote into $PASCLAW_HOME/workspace
while shell_exec("cat x") looked in the launch dir -- and the prompt
claimed a single working directory.
Start the shell in CurrentWorkspace unconditionally so write_file("x")
and shell_exec("cat x") agree. CurrentWorkspace defaults to the launch
dir when no workspace is configured, so CLI agent/tui are byte-identical;
the gateway/serve default ($PASCLAW_HOME/workspace) now governs the shell
too -- i.e. the web UI uses /workspace for everything, the CLI uses its
launch dir. When restriction is on this cwd still pins the boundary. Falls
back to inheriting the parent cwd if the workspace dir does not exist.
gateway + serve ForceDirectories the default workspace at startup so the
shell has a directory to start in on a fresh install.
Verified end-to-end through the relay: on a default gateway launched from
an unrelated dir, shell_exec `pwd` reports $PASCLAW_HOME/workspace and
`cat` reads back the file a prior relative write_file created.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
The problem
On a
pasclaw gateway/serverun (the web UI path), a relativewrite_file("index.html")landed in the process's launch directory — wherever the service happened to be started — not the workspace the web UI Files tab shows. Meanwhile the system prompt advertised a third location (~/.pasclaw, the config dir) as "your workspace". So an un-steered write vanished somewhere the UI never displays, and the operator had to hand-supply an absolute path (or tell the model "use the workspace") on every build.Root cause: the fs tools resolved a relative
patharg withExpandFileName— i.e. against the process CWD — and ignored the configured workspace entirely.The fix
Sandbox.ResolveWorkspacePath— relative paths resolve againstCurrentWorkspace(the configuredsandbox.workspace, or the launch dir when unset); absolute paths pass through canonicalised. All fs tools call it before theCanRead/CanWritePathgate:read_file/write_file/append_file/edit_file(string and hashline patch) /list_dir/grep_files/apply_patch.$PASCLAW_HOME/workspace(the dir the Files tab browses) whensandbox.workspaceis unset, instead of the launch CWD. An explicitsandbox.workspacestill wins. CLIagent/tui/buildare unchanged — they keep resolving relative paths against the project CWD, which is what a user in their repo expects.Tests
workspace_paths_tests—ResolveWorkspacePath(relative → workspace, absolute → itself) and write/read/append relative paths land in the configured workspace, not the launch CWD.Verified end-to-end through the relay with a default gateway (no
sandbox.workspace) launched from an unrelated directory: a relativewrite_file("probe.html")with no workspace instruction landed in$PASCLAW_HOME/workspace, and the model's system prompt showed the correct working directory.🤖 Generated with Claude Code
https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Generated by Claude Code