@devries-cameron20 / t3code Mirror · read-only / commits / 580b526758
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 16:00 UTC

fix(server): respect the default Windows file manager (#28205)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

prov3ntus committed Nov 14, 2026 at 04:36 UTC 580b526758c59e92e4688c82b4cc95ebbaa10a42
2 files changed +134 -12
apps/server/src/process/externalLauncher.test.ts
+113 -3
@@ -339,6 +339,111 @@ it.effect("launches an installed editor with platform-safe arguments", () =>
339 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
340 );
341
342 +it.live.skipIf(!windowsHost)("opens Windows folders through the default shell handler", () =>
343 + Effect.gen(function* () {
344 + let spawned: ChildProcess.StandardCommand | undefined;
345 + yield* Effect.gen(function* () {
346 + const launcher = yield* ExternalLauncher.ExternalLauncher;
347 + yield* launcher.launchEditor({
348 + editor: "file-manager",
349 + cwd: "C:/workspace [draft]/author's ‘left’ ‚low‛ $media/’; Write-Output injected; #",
350 + });
351 + }).pipe(
352 + Effect.provide(
353 + layerTest({
354 + platform: "win32",
355 + env: { PATH: "C:\\Windows", PATHEXT: ".EXE" },
356 + onSpawn: (command) => {
357 + spawned = command;
358 + },
359 + }),
360 + ),
361 + );
362 + assert.ok(spawned);
363 + assert.equal(spawned.options.detached, false);
364 + const source = Buffer.from(String(spawned.args.at(-1) ?? ""), "base64").toString("utf16le");
365 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
366 + const output = yield* spawner.string(
367 + ChildProcess.make(spawned.command, [
368 + ...spawned.args.slice(0, -1),
369 + Buffer.from(
370 + `[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false); function Invoke-Item { param($LiteralPath) Write-Output $LiteralPath }; ${source}`,
371 + "utf16le",
372 + ).toString("base64"),
373 + ]),
374 + );
375 + assert.equal(
376 + output.trim(),
377 + "C:\\workspace [draft]\\author's ‘left’ ‚low‛ $media\\’; Write-Output injected; #",
378 + );
379 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
380 +);
381 +
382 +for (const [replacement, verb, handler, target, expected] of [
383 + ["none", "none", "", "C:/repo/file.txt", 'explorer.exe /select,"C:\\repo\\file.txt"'],
384 + ["Directory", "openindopus", "dopusrt.exe", "C:/repo/file.txt", "shell:C:\\repo"],
385 + ["Folder", "openindopus", "dopusrt.exe", "C:/repo/file.txt", "shell:C:\\repo"],
386 + [
387 + "Folder",
388 + "open",
389 + '"C:\\Windows\\explorer.exe"',
390 + "C:/repo/file.txt",
391 + 'explorer.exe /select,"C:\\repo\\file.txt"',
392 + ],
393 + [
394 + "Folder",
395 + "open",
396 + "ExplorerDelegate",
397 + "C:/repo/file.txt",
398 + 'explorer.exe /select,"C:\\repo\\file.txt"',
399 + ],
400 + [
401 + "Drive",
402 + "openindopus",
403 + "dopusrt.exe",
404 + "C:/repo/file.txt",
405 + 'explorer.exe /select,"C:\\repo\\file.txt"',
406 + ],
407 + ["Drive", "openindopus", "dopusrt.exe", "C:/file.txt", "shell:C:\\"],
408 +] as const) {
409 + it.live.skipIf(!windowsHost)(
410 + `reveals ${target} with ${replacement}/${verb} handled by ${handler}`,
411 + () =>
412 + Effect.gen(function* () {
413 + let spawned: ChildProcess.StandardCommand | undefined;
414 + yield* Effect.gen(function* () {
415 + const launcher = yield* ExternalLauncher.ExternalLauncher;
416 + yield* launcher.launchEditor({
417 + editor: "file-manager",
418 + cwd: target,
419 + reveal: true,
420 + });
421 + }).pipe(
422 + Effect.provide(
423 + layerTest({
424 + platform: "win32",
425 + env: { PATH: "C:\\Windows", PATHEXT: ".EXE" },
426 + onSpawn: (command) => {
427 + spawned = command;
428 + },
429 + }),
430 + ),
431 + );
432 + assert.ok(spawned);
433 + const source = Buffer.from(String(spawned.args.at(-1) ?? ""), "base64").toString("utf16le");
434 + const stubs = `function Get-ItemProperty { param($LiteralPath, $ErrorAction) @{ '(default)' = if ($LiteralPath -eq 'Registry::HKEY_CLASSES_ROOT\\${replacement}\\shell') { '${verb}' } elseif ($LiteralPath -eq 'Registry::HKEY_CLASSES_ROOT\\${replacement}\\shell\\${verb}\\command') { '${handler}' } else { 'none' }; DelegateExecute = if ('${handler}' -eq 'ExplorerDelegate') { '{11dbb47c-a525-400b-9e80-a54615a090c0}' } else { '' } } }; function Invoke-Item { param($LiteralPath) Write-Output "shell:$LiteralPath" }; function Start-Process { param($FilePath, $ArgumentList) Write-Output "$FilePath $ArgumentList" }; `;
435 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
436 + const output = yield* spawner.string(
437 + ChildProcess.make(spawned.command, [
438 + ...spawned.args.slice(0, -1),
439 + Buffer.from(stubs + source, "utf16le").toString("base64"),
440 + ]),
441 + );
442 + assert.equal(output.trim(), expected);
443 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
444 + );
445 +}
446 +
447 it.effect.skipIf(windowsHost)(
448 "reveals a WSL file in Windows File Explorer through its UNC path",
449 () =>
@@ -359,7 +464,7 @@ it.effect.skipIf(windowsHost)(
464 const editors = yield* launcher.resolveAvailableEditors();
465 yield* launcher.launchEditor({
466 editor: "file-manager",
362 - cwd: "/home/t3/workspace [draft]/author's $media/clip|draft.mp4",
467 + cwd: "/home/t3/workspace [draft]/author's ‘$media/clip|draft.mp4",
468 reveal: true,
469 });
470 return { kind, editors };
@@ -386,9 +491,14 @@ it.effect.skipIf(windowsHost)(
491 assert.equal(spawned.options.detached, true);
492 const encodedCommand = String(spawned.args[spawned.args.length - 1] ?? "");
493 const decodedCommand = Buffer.from(encodedCommand, "base64").toString("utf16le");
389 - assert.equal(
494 + assert.include(decodedCommand, "'Directory', 'Folder'");
495 + assert.include(
496 + decodedCommand,
497 + "Invoke-Item -LiteralPath '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s ‘‘$media'",
498 + );
499 + assert.include(
500 decodedCommand,
391 - "$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s $media' } else { Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s $media\\clip|draft.mp4' + '\"') }",
501 + "'\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace [draft]\\author''s ‘‘$media\\clip|draft.mp4'",
502 );
503 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
504 );
apps/server/src/process/externalLauncher.ts
+21 -9
@@ -182,7 +182,8 @@ function encodeUtf16LeBase64(input: string): string {
182 }
183
184 function escapePowerShellStringLiteral(input: string): string {
185 - return `'${input.replaceAll("'", "''")}'`;
185 + // PowerShell also recognises typographic apostrophes as single-quote delimiters.
186 + return `'${input.replace(/['\u2018-\u201b]/g, "$&$&")}'`;
187 }
188
189 function resolveWindowsRoot(env: NodeJS.ProcessEnv): string {
@@ -527,6 +528,18 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
528 return yield* resolveFileManagerRevealLaunch(target, platform, env, command);
529 }
530
531 + if (platform === "win32") {
532 + // ShellExecute honours replacement folder handlers that explorer.exe bypasses.
533 + return {
534 + ...powerShellFileManagerLaunch(
535 + target,
536 + `Invoke-Item -LiteralPath ${escapePowerShellStringLiteral(normalizeWindowsFileManagerPath(target))}`,
537 + resolvePowerShellPath(env),
538 + ),
539 + detached: WINDOWS_POWERSHELL_DETACHED,
540 + };
541 + }
542 +
543 return {
544 editor: editorDef.id,
545 target,
@@ -534,19 +547,18 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
547 args:
548 command === "explorer.exe" && env.WSL_DISTRO_NAME !== undefined
549 ? [resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME)]
537 - : platform === "win32"
538 - ? // Explorer interprets / as a switch and silently opens a fallback folder.
539 - [normalizeWindowsFileManagerPath(target)]
540 - : [target],
550 + : [target],
551 };
552 });
553
544 -// A replacement manager registers a default Directory shell verb; stock Windows
545 -// uses "none". Explorer needs its /select argument passed verbatim through
546 -// PowerShell because Node's argument quoting changes how Explorer parses it.
554 +// Replacement managers can register under Directory, Drive, or Folder. Explorer
555 +// needs its /select argument passed verbatim through PowerShell because Node's
556 +// argument quoting changes how Explorer parses it.
557 function buildFileManagerRevealPowerShellSource(target: string, parent: string): string {
558 const literal = escapePowerShellStringLiteral(target);
549 - return `$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath ${escapePowerShellStringLiteral(parent)} } else { Start-Process 'explorer.exe' -ArgumentList ('/select,"' + ${literal} + '"') }`;
559 + const folderClass = /^[a-z]:\\$/i.test(parent) ? "Drive" : "Directory";
560 + // Explorer's ordinary open/explore handlers may also be explicit defaults.
561 + return String.raw`$ProgressPreference = 'SilentlyContinue'; $folderVerb = '${folderClass}', 'Folder' | ForEach-Object { $key = "Registry::HKEY_CLASSES_ROOT\$_\shell"; $verb = (Get-ItemProperty -LiteralPath $key -ErrorAction SilentlyContinue).'(default)'; if ($verb -and $verb -ne 'none') { $handler = Get-ItemProperty -LiteralPath "$key\$verb\command" -ErrorAction SilentlyContinue; if ($handler.DelegateExecute -ne '{11dbb47c-a525-400b-9e80-a54615a090c0}' -and $handler.'(default)' -notmatch '^\s*"?(?:[^"]*[\\/])?explorer\.exe(?:["\s]|$)') { $verb } } }; if ($folderVerb) { Invoke-Item -LiteralPath ${escapePowerShellStringLiteral(parent)} } else { Start-Process 'explorer.exe' -ArgumentList ('/select,"' + ${literal} + '"') }`;
562 }
563
564 function powerShellFileManagerLaunch(