Skip to content

Commit 8e5a7c2

Browse files
refactor: generalize remote URI handling and remove CLAUDE.md
- Remove WSL-specific check in favor of generic URI handling - Support all vscode-remote:// URI schemes (WSL, SSH, dev-container) - Prefer file:// URIs when available, fall back to remote URIs - Add tests for various remote URI formats - Remove CLAUDE.md per reviewer feedback (use AGENTS.md convention) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 6b30a88 commit 8e5a7c2

File tree

3 files changed

+65
-65
lines changed

3 files changed

+65
-65
lines changed

CLAUDE.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

core/tools/implementations/runTerminalCommand.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ import { getBooleanArg, getStringArg } from "../parseArgs";
4848
* Falls back to home directory or temp directory if no workspace is available.
4949
*/
5050
function resolveWorkingDirectory(workspaceDirs: string[]): string {
51-
// Handle vscode-remote://wsl+distro/path URIs (WSL2 remote workspaces)
52-
const wslWorkspaceDir = workspaceDirs.find((dir) =>
53-
dir.startsWith("vscode-remote://wsl"),
54-
);
55-
if (wslWorkspaceDir) {
56-
try {
57-
const url = new URL(wslWorkspaceDir);
58-
return decodeURIComponent(url.pathname); // e.g., "/home/user/project"
59-
} catch {
60-
// Fall through to other handlers
61-
}
62-
}
63-
6451
// Handle file:// URIs (local workspaces)
6552
const fileWorkspaceDir = workspaceDirs.find((dir) =>
6653
dir.startsWith("file:/"),
@@ -74,6 +61,19 @@ function resolveWorkingDirectory(workspaceDirs: string[]): string {
7461
}
7562
}
7663

64+
// Handle other URI schemes (vscode-remote://wsl, vscode-remote://ssh-remote, etc.)
65+
const remoteWorkspaceDir = workspaceDirs.find(
66+
(dir) => dir.includes("://") && !dir.startsWith("file:/"),
67+
);
68+
if (remoteWorkspaceDir) {
69+
try {
70+
const url = new URL(remoteWorkspaceDir);
71+
return decodeURIComponent(url.pathname);
72+
} catch {
73+
// Fall through to other handlers
74+
}
75+
}
76+
7777
// Default to user's home directory with fallbacks
7878
try {
7979
return process.env.HOME || process.env.USERPROFILE || process.cwd();

core/tools/implementations/runTerminalCommand.vitest.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,58 @@ describe("runTerminalCommandImpl", () => {
553553
// This demonstrates why the fix is needed - fileURLToPath throws on non-file URIs
554554
expect(() => fileURLToPath(nonFileUri)).toThrow();
555555
});
556+
557+
it("should handle vscode-remote URIs by extracting pathname", async () => {
558+
// Various remote URI formats that VS Code uses
559+
const remoteUris = [
560+
"vscode-remote://wsl+Ubuntu/home/user/project",
561+
"vscode-remote://ssh-remote+myserver/home/user/project",
562+
"vscode-remote://dev-container+abc123/workspace",
563+
];
564+
565+
for (const uri of remoteUris) {
566+
mockGetWorkspaceDirs.mockResolvedValue([uri]);
567+
568+
// Should not throw - the generic URI handler extracts the pathname
569+
await expect(
570+
runTerminalCommandImpl(
571+
{ command: "echo test", waitForCompletion: false },
572+
createMockExtras(),
573+
),
574+
).resolves.toBeDefined();
575+
}
576+
});
577+
578+
it("should decode URI-encoded characters in remote workspace paths", async () => {
579+
// Path with spaces and special characters
580+
const encodedUri =
581+
"vscode-remote://wsl+Ubuntu/home/user/my%20project%20%28test%29";
582+
mockGetWorkspaceDirs.mockResolvedValue([encodedUri]);
583+
584+
// Should handle without throwing - decodeURIComponent is applied
585+
await expect(
586+
runTerminalCommandImpl(
587+
{ command: "echo test", waitForCompletion: false },
588+
createMockExtras(),
589+
),
590+
).resolves.toBeDefined();
591+
});
592+
593+
it("should prefer file:// URIs over remote URIs when both present", async () => {
594+
const workspaceDirs = [
595+
"vscode-remote://wsl+Ubuntu/home/user/remote-project",
596+
"file:///home/user/local-project",
597+
];
598+
mockGetWorkspaceDirs.mockResolvedValue(workspaceDirs);
599+
600+
// Should succeed, preferring the file:// URI
601+
await expect(
602+
runTerminalCommandImpl(
603+
{ command: "echo test", waitForCompletion: false },
604+
createMockExtras(),
605+
),
606+
).resolves.toBeDefined();
607+
});
556608
});
557609

558610
describe("remote environment handling", () => {

0 commit comments

Comments
 (0)