fix(plugin): reject '/' as workspace, fall back to $HOME#62
Open
yannicklescure wants to merge 1 commit intoNomadcxx:mainfrom
Open
fix(plugin): reject '/' as workspace, fall back to $HOME#62yannicklescure wants to merge 1 commit intoNomadcxx:mainfrom
yannicklescure wants to merge 1 commit intoNomadcxx:mainfrom
Conversation
resolveWorkspaceDirectory previously accepted any path the daemon received, including a bare filesystem root. When opencode is launched without a sensible cwd (common for systemd units or shells started at '/'), worktree/directory/cwd can all resolve to '/', which made every tool operate against the whole machine and silently bypassed workspace scoping. Now every candidate — env vars, worktree, directory, cwd — is rejected if it resolves to '/' (or a bare Windows drive root). When no usable workspace is found we fall back to the current user's home directory before the config prefix, so tools always land in a writable, user-scoped location. Also export resolveWorkspaceDirectory / isRootPath so the behaviour can be unit-tested, and add tests/unit/plugin-workspace-resolution.test.ts covering each rejection and fallback path. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveWorkspaceDirectorypreviously accepted any path it was handed, including a bare filesystem root (/). When opencode is launched without a real cwd (systemd unit, login shell at/, daemon spawned by root),worktree,directory, andprocess.cwd()can all resolve to/, which silently makes every tool operate against the whole machine and bypasses workspace scoping.CURSOR_ACP_WORKSPACE,OPENCODE_CURSOR_PROJECT_DIR),worktree,directory, andcwd— is now rejected if it resolves to/(or a bare Windows drive root likeC:\)./.resolveWorkspaceDirectoryand a newisRootPathhelper are exported so the behaviour is unit-testable.Why
The bundled
~/.config/opencode/plugin/cursor-acp.jswas hot-patched in the field to work around this. This PR lands the same fix in the TypeScript source (src/plugin.ts) so a freshbun run buildproduces a plugin that is safe by default.Changes
src/plugin.tsisRootPath(pathValue)— detects/and bare Windows drive roots.isAcceptableWorkspace(path, configPrefix)— rejects empty, root, and config-prefix paths in one place.resolveWorkspaceDirectoryso theconfigPrefixis computed once, each candidate goes throughisAcceptableWorkspace, and a$HOMEfallback is consulted before the config prefix.resolveWorkspaceDirectoryandisRootPath.tests/unit/plugin-workspace-resolution.test.ts(new)isRootPathcovers POSIX root, Windows drive roots (skipped off-Windows), and ordinary paths.resolveWorkspaceDirectorycovers: worktree preferred, directory fallback,/rejected from worktree/directory (falls back to cwd),/everywhere (falls back to\$HOME), env-var/rejection for both env vars, honoring a real env workspace, and skipping paths inside the config prefix.Test plan
bun test tests/unit/plugin-workspace-resolution.test.ts— 10 pass, 1 skipped (Windows-only case).bun test tests/unit/plugin.test.ts tests/unit/plugin-config.test.ts— no regressions.bun run build— bundles cleanly./as the workspace.Note:
tests/unit/plugin-tools-hook.test.ts > treats config path aliases (symlink/case variants) as config and falls back to workspacefails onmainas well (unrelated symlink/tmp handling); not addressed here.Made with Cursor