@devries-cameron20 / t3code-1 / commits / d15909af15
Fork 0

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

Use Effect child process for editor launches (#2659)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

cursor[bot] committed May 12, 2026 at 20:15 UTC d15909af15602622c6bd1d10aa2e3e165117a1c8
11 files changed +614 -342
apps/server/package.json
+1 -2
@@ -31,8 +31,7 @@
31 "@opencode-ai/sdk": "^1.3.15",
32 "@pierre/diffs": "catalog:",
33 "effect": "catalog:",
34 - "node-pty": "^1.1.0",
35 - "open": "^10.1.0"
34 + "node-pty": "^1.1.0"
35 },
36 "devDependencies": {
37 "@effect/language-service": "catalog:",
apps/server/src/open.ts deleted
-241
@@ -1,241 +0,0 @@
1 -// @effect-diagnostics nodeBuiltinImport:off
2 -/**
3 - * Open - Browser/editor launch service interface.
4 - *
5 - * Owns process launch helpers for opening URLs in a browser and workspace
6 - * paths in a configured editor.
7 - *
8 - * @module Open
9 - */
10 -import { spawn } from "node:child_process";
11 -
12 -import { EDITORS, OpenError, type EditorId } from "@t3tools/contracts";
13 -import { isCommandAvailable, type CommandAvailabilityOptions } from "@t3tools/shared/shell";
14 -import * as Context from "effect/Context";
15 -import * as Effect from "effect/Effect";
16 -import * as Layer from "effect/Layer";
17 -
18 -// ==============================
19 -// Definitions
20 -// ==============================
21 -
22 -export { OpenError };
23 -export { isCommandAvailable } from "@t3tools/shared/shell";
24 -
25 -export interface OpenInEditorInput {
26 - readonly cwd: string;
27 - readonly editor: EditorId;
28 -}
29 -
30 -interface EditorLaunch {
31 - readonly command: string;
32 - readonly args: ReadonlyArray<string>;
33 -}
34 -
35 -const TARGET_WITH_POSITION_PATTERN = /^(.*?):(\d+)(?::(\d+))?$/;
36 -
37 -function parseTargetPathAndPosition(target: string): {
38 - path: string;
39 - line: string | undefined;
40 - column: string | undefined;
41 -} | null {
42 - const match = TARGET_WITH_POSITION_PATTERN.exec(target);
43 - if (!match?.[1] || !match[2]) {
44 - return null;
45 - }
46 -
47 - return {
48 - path: match[1],
49 - line: match[2],
50 - column: match[3],
51 - };
52 -}
53 -
54 -function resolveCommandEditorArgs(
55 - editor: (typeof EDITORS)[number],
56 - target: string,
57 -): ReadonlyArray<string> {
58 - const parsedTarget = parseTargetPathAndPosition(target);
59 -
60 - switch (editor.launchStyle) {
61 - case "direct-path":
62 - return [target];
63 - case "goto":
64 - return parsedTarget ? ["--goto", target] : [target];
65 - case "line-column": {
66 - if (!parsedTarget) {
67 - return [target];
68 - }
69 -
70 - const { path, line, column } = parsedTarget;
71 - return [...(line ? ["--line", line] : []), ...(column ? ["--column", column] : []), path];
72 - }
73 - }
74 -}
75 -
76 -function resolveEditorArgs(
77 - editor: (typeof EDITORS)[number],
78 - target: string,
79 -): ReadonlyArray<string> {
80 - const baseArgs = "baseArgs" in editor ? editor.baseArgs : [];
81 - return [...baseArgs, ...resolveCommandEditorArgs(editor, target)];
82 -}
83 -
84 -function resolveAvailableCommand(
85 - commands: ReadonlyArray<string>,
86 - options: CommandAvailabilityOptions = {},
87 -): string | null {
88 - for (const command of commands) {
89 - if (isCommandAvailable(command, options)) {
90 - return command;
91 - }
92 - }
93 - return null;
94 -}
95 -
96 -function fileManagerCommandForPlatform(platform: NodeJS.Platform): string {
97 - switch (platform) {
98 - case "darwin":
99 - return "open";
100 - case "win32":
101 - return "explorer";
102 - default:
103 - return "xdg-open";
104 - }
105 -}
106 -
107 -export function resolveAvailableEditors(
108 - platform: NodeJS.Platform = process.platform,
109 - env: NodeJS.ProcessEnv = process.env,
110 -): ReadonlyArray<EditorId> {
111 - const available: EditorId[] = [];
112 -
113 - for (const editor of EDITORS) {
114 - if (editor.commands === null) {
115 - const command = fileManagerCommandForPlatform(platform);
116 - if (isCommandAvailable(command, { platform, env })) {
117 - available.push(editor.id);
118 - }
119 - continue;
120 - }
121 -
122 - const command = resolveAvailableCommand(editor.commands, { platform, env });
123 - if (command !== null) {
124 - available.push(editor.id);
125 - }
126 - }
127 -
128 - return available;
129 -}
130 -
131 -/**
132 - * OpenShape - Service API for browser and editor launch actions.
133 - */
134 -export interface OpenShape {
135 - /**
136 - * Open a URL target in the default browser.
137 - */
138 - readonly openBrowser: (target: string) => Effect.Effect<void, OpenError>;
139 -
140 - /**
141 - * Open a workspace path in a selected editor integration.
142 - *
143 - * Launches the editor as a detached process so server startup is not blocked.
144 - */
145 - readonly openInEditor: (input: OpenInEditorInput) => Effect.Effect<void, OpenError>;
146 -}
147 -
148 -/**
149 - * Open - Service tag for browser/editor launch operations.
150 - */
151 -export class Open extends Context.Service<Open, OpenShape>()("t3/open") {}
152 -
153 -// ==============================
154 -// Implementations
155 -// ==============================
156 -
157 -export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
158 - input: OpenInEditorInput,
159 - platform: NodeJS.Platform = process.platform,
160 - env: NodeJS.ProcessEnv = process.env,
161 -): Effect.fn.Return<EditorLaunch, OpenError> {
162 - yield* Effect.annotateCurrentSpan({
163 - "open.editor": input.editor,
164 - "open.cwd": input.cwd,
165 - "open.platform": platform,
166 - });
167 - const editorDef = EDITORS.find((editor) => editor.id === input.editor);
168 - if (!editorDef) {
169 - return yield* new OpenError({ message: `Unknown editor: ${input.editor}` });
170 - }
171 -
172 - if (editorDef.commands) {
173 - const command =
174 - resolveAvailableCommand(editorDef.commands, { platform, env }) ?? editorDef.commands[0];
175 - return {
176 - command,
177 - args: resolveEditorArgs(editorDef, input.cwd),
178 - };
179 - }
180 -
181 - if (editorDef.id !== "file-manager") {
182 - return yield* new OpenError({ message: `Unsupported editor: ${input.editor}` });
183 - }
184 -
185 - return { command: fileManagerCommandForPlatform(platform), args: [input.cwd] };
186 -});
187 -
188 -export const launchDetached = (launch: EditorLaunch) =>
189 - Effect.gen(function* () {
190 - if (!isCommandAvailable(launch.command)) {
191 - return yield* new OpenError({ message: `Editor command not found: ${launch.command}` });
192 - }
193 -
194 - yield* Effect.callback<void, OpenError>((resume) => {
195 - let child;
196 - try {
197 - const isWin32 = process.platform === "win32";
198 - child = spawn(
199 - launch.command,
200 - isWin32 ? launch.args.map((a) => `"${a}"`) : [...launch.args],
201 - {
202 - detached: true,
203 - stdio: "ignore",
204 - shell: isWin32,
205 - },
206 - );
207 - } catch (error) {
208 - return resume(
209 - Effect.fail(new OpenError({ message: "failed to spawn detached process", cause: error })),
210 - );
211 - }
212 -
213 - const handleSpawn = () => {
214 - child.unref();
215 - resume(Effect.void);
216 - };
217 -
218 - child.once("spawn", handleSpawn);
219 - child.once("error", (cause) =>
220 - resume(Effect.fail(new OpenError({ message: "failed to spawn detached process", cause }))),
221 - );
222 - });
223 - });
224 -
225 -const make = Effect.gen(function* () {
226 - const open = yield* Effect.tryPromise({
227 - try: () => import("open"),
228 - catch: (cause) => new OpenError({ message: "failed to load browser opener", cause }),
229 - });
230 -
231 - return {
232 - openBrowser: (target) =>
233 - Effect.tryPromise({
234 - try: () => open.default(target),
235 - catch: (cause) => new OpenError({ message: "Browser auto-open failed", cause }),
236 - }),
237 - openInEditor: (input) => Effect.flatMap(resolveEditorLaunch(input), launchDetached),
238 - } satisfies OpenShape;
239 -});
240 -
241 -export const OpenLive = Layer.effect(Open, make);
apps/server/src/process/externalLauncher.test.ts renamed
+211 -51
@@ -2,16 +2,52 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, it } from "@effect/vitest";
3 import { assertSuccess } from "@effect/vitest/utils";
4 import * as Effect from "effect/Effect";
5 +import * as Encoding from "effect/Encoding";
6 import * as FileSystem from "effect/FileSystem";
7 +import * as Layer from "effect/Layer";
8 import * as Path from "effect/Path";
9 import * as Random from "effect/Random";
10 +import * as Sink from "effect/Sink";
11 +import * as Stream from "effect/Stream";
12 +import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
13
14 import {
15 isCommandAvailable,
11 - launchDetached,
16 + launchBrowser,
17 + launchEditorProcess,
18 resolveAvailableEditors,
19 + resolveBrowserLaunch,
20 resolveEditorLaunch,
14 -} from "./open.ts";
21 +} from "./externalLauncher.ts";
22 +
23 +function encodeUtf16LeBase64(input: string): string {
24 + const bytes = new Uint8Array(input.length * 2);
25 + for (let index = 0; index < input.length; index += 1) {
26 + const code = input.charCodeAt(index);
27 + bytes[index * 2] = code & 0xff;
28 + bytes[index * 2 + 1] = code >>> 8;
29 + }
30 + return Encoding.encodeBase64(bytes);
31 +}
32 +
33 +function makeMockDetachedHandle(onUnref: () => void = () => undefined) {
34 + return ChildProcessSpawner.makeHandle({
35 + pid: ChildProcessSpawner.ProcessId(1),
36 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
37 + isRunning: Effect.succeed(true),
38 + kill: () => Effect.void,
39 + unref: Effect.sync(() => {
40 + onUnref();
41 + return Effect.void;
42 + }),
43 + stdin: Sink.drain,
44 + stdout: Stream.empty,
45 + stderr: Stream.empty,
46 + all: Stream.empty,
47 + getInputFd: () => Sink.drain,
48 + getOutputFd: () => Stream.empty,
49 + });
50 +}
51
52 it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
53 it.effect("returns commands for command-based editors", () =>
@@ -216,70 +252,70 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
252 });
253
254 const lineAndColumn = yield* resolveEditorLaunch(
219 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "cursor" },
255 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "cursor" },
256 "darwin",
257 { PATH: "" },
258 );
259 assert.deepEqual(lineAndColumn, {
260 command: "cursor",
225 - args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
261 + args: ["--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
262 });
263
264 const traeLineAndColumn = yield* resolveEditorLaunch(
229 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "trae" },
265 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "trae" },
266 "darwin",
267 );
268 assert.deepEqual(traeLineAndColumn, {
269 command: "trae",
234 - args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
270 + args: ["--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
271 });
272
273 const kiroLineAndColumn = yield* resolveEditorLaunch(
238 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "kiro" },
274 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "kiro" },
275 "darwin",
276 { PATH: "" },
277 );
278 assert.deepEqual(kiroLineAndColumn, {
279 command: "kiro",
244 - args: ["ide", "--goto", "/tmp/workspace/src/open.ts:71:5"],
280 + args: ["ide", "--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
281 });
282
283 const vscodeLineAndColumn = yield* resolveEditorLaunch(
248 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscode" },
284 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "vscode" },
285 "darwin",
286 { PATH: "" },
287 );
288 assert.deepEqual(vscodeLineAndColumn, {
289 command: "code",
254 - args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
290 + args: ["--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
291 });
292
293 const vscodeInsidersLineAndColumn = yield* resolveEditorLaunch(
258 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscode-insiders" },
294 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "vscode-insiders" },
295 "darwin",
296 );
297 assert.deepEqual(vscodeInsidersLineAndColumn, {
298 command: "code-insiders",
263 - args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
299 + args: ["--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
300 });
301
302 const vscodiumLineAndColumn = yield* resolveEditorLaunch(
267 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscodium" },
303 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "vscodium" },
304 "darwin",
305 );
306 assert.deepEqual(vscodiumLineAndColumn, {
307 command: "codium",
272 - args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
308 + args: ["--goto", "/tmp/workspace/src/process/externalLauncher.ts:71:5"],
309 });
310
311 const zedLineAndColumn = yield* resolveEditorLaunch(
276 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "zed" },
312 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "zed" },
313 "darwin",
314 { PATH: "" },
315 );
316 assert.deepEqual(zedLineAndColumn, {
317 command: "zed",
282 - args: ["/tmp/workspace/src/open.ts:71:5"],
318 + args: ["/tmp/workspace/src/process/externalLauncher.ts:71:5"],
319 });
320
321 const zedLineOnly = yield* resolveEditorLaunch(
@@ -302,102 +338,102 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
338 });
339
340 const ideaLineAndColumn = yield* resolveEditorLaunch(
305 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "idea" },
341 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "idea" },
342 "darwin",
343 );
344 assert.deepEqual(ideaLineAndColumn, {
345 command: "idea",
310 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
346 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
347 });
348
349 const aquaLineAndColumn = yield* resolveEditorLaunch(
314 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "aqua" },
350 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "aqua" },
351 "darwin",
352 );
353 assert.deepEqual(aquaLineAndColumn, {
354 command: "aqua",
319 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
355 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
356 });
357
358 const clionLineAndColumn = yield* resolveEditorLaunch(
323 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "clion" },
359 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "clion" },
360 "darwin",
361 );
362 assert.deepEqual(clionLineAndColumn, {
363 command: "clion",
328 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
364 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
365 });
366
367 const datagripLineAndColumn = yield* resolveEditorLaunch(
332 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "datagrip" },
368 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "datagrip" },
369 "darwin",
370 );
371 assert.deepEqual(datagripLineAndColumn, {
372 command: "datagrip",
337 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
373 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
374 });
375
376 const dataspellLineAndColumn = yield* resolveEditorLaunch(
341 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "dataspell" },
377 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "dataspell" },
378 "darwin",
379 );
380 assert.deepEqual(dataspellLineAndColumn, {
381 command: "dataspell",
346 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
382 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
383 });
384
385 const golandLineAndColumn = yield* resolveEditorLaunch(
350 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "goland" },
386 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "goland" },
387 "darwin",
388 );
389 assert.deepEqual(golandLineAndColumn, {
390 command: "goland",
355 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
391 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
392 });
393
394 const phpstormLineAndColumn = yield* resolveEditorLaunch(
359 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "phpstorm" },
395 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "phpstorm" },
396 "darwin",
397 );
398 assert.deepEqual(phpstormLineAndColumn, {
399 command: "phpstorm",
364 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
400 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
401 });
402
403 const pycharmLineAndColumn = yield* resolveEditorLaunch(
368 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "pycharm" },
404 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "pycharm" },
405 "darwin",
406 );
407 assert.deepEqual(pycharmLineAndColumn, {
408 command: "pycharm",
373 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
409 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
410 });
411
412 const riderLineAndColumn = yield* resolveEditorLaunch(
377 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "rider" },
413 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "rider" },
414 "darwin",
415 );
416 assert.deepEqual(riderLineAndColumn, {
417 command: "rider",
382 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
418 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
419 });
420
421 const rubymineLineAndColumn = yield* resolveEditorLaunch(
386 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "rubymine" },
422 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "rubymine" },
423 "darwin",
424 );
425 assert.deepEqual(rubymineLineAndColumn, {
426 command: "rubymine",
391 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
427 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
428 });
429
430 const rustroverLineAndColumn = yield* resolveEditorLaunch(
395 - { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "rustrover" },
431 + { cwd: "/tmp/workspace/src/process/externalLauncher.ts:71:5", editor: "rustrover" },
432 "darwin",
433 );
434 assert.deepEqual(rustroverLineAndColumn, {
435 command: "rustrover",
400 - args: ["--line", "71", "--column", "5", "/tmp/workspace/src/open.ts"],
436 + args: ["--line", "71", "--column", "5", "/tmp/workspace/src/process/externalLauncher.ts"],
437 });
438
439 const webstormLineOnly = yield* resolveEditorLaunch(
@@ -415,7 +451,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
451 Effect.gen(function* () {
452 const fs = yield* FileSystem.FileSystem;
453 const path = yield* Path.Path;
418 - const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
454 + const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
455 yield* fs.writeFileString(path.join(dir, "zeditor"), "#!/bin/sh\nexit 0\n");
456 yield* fs.chmod(path.join(dir, "zeditor"), 0o755);
457
@@ -477,23 +513,147 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
513 );
514 });
515
480 -it.layer(NodeServices.layer)("launchDetached", (it) => {
481 - it.effect("resolves when command can be spawned", () =>
516 +it("resolveBrowserLaunch maps default browser launchers by platform", () => {
517 + const target = "https://example.com/some path?name=o'hara";
518 +
519 + assert.deepEqual(resolveBrowserLaunch(target, "darwin").command, "open");
520 + assert.deepEqual(resolveBrowserLaunch(target, "darwin").args, [target]);
521 + assert.deepEqual(resolveBrowserLaunch(target, "darwin").options, {
522 + detached: true,
523 + stdin: "ignore",
524 + stdout: "ignore",
525 + stderr: "ignore",
526 + });
527 +
528 + assert.deepEqual(resolveBrowserLaunch(target, "linux", {}).command, "xdg-open");
529 + assert.deepEqual(resolveBrowserLaunch(target, "linux", {}).args, [target]);
530 +
531 + const windows = resolveBrowserLaunch(target, "win32", {
532 + SYSTEMROOT: "C:\\Windows",
533 + });
534 + assert.equal(windows.command, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");
535 + assert.deepEqual(windows.args, [
536 + "-NoProfile",
537 + "-NonInteractive",
538 + "-ExecutionPolicy",
539 + "Bypass",
540 + "-EncodedCommand",
541 + encodeUtf16LeBase64(
542 + "$ProgressPreference = 'SilentlyContinue'; Start 'https://example.com/some path?name=o''hara'",
543 + ),
544 + ]);
545 + assert.deepEqual(windows.options, {
546 + detached: true,
547 + shell: false,
548 + stdin: "ignore",
549 + stdout: "ignore",
550 + stderr: "ignore",
551 + });
552 +});
553 +
554 +it("resolveBrowserLaunch opens through Windows from WSL when not remote", () => {
555 + const launch = resolveBrowserLaunch("https://example.com", "linux", {
556 + WSL_DISTRO_NAME: "Ubuntu",
557 + });
558 + assert.equal(launch.command, "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe");
559 + assert.equal(launch.options.detached, true);
560 +});
561 +
562 +it("resolveBrowserLaunch keeps xdg-open for WSL over SSH", () => {
563 + const launch = resolveBrowserLaunch("https://example.com", "linux", {
564 + WSL_DISTRO_NAME: "Ubuntu",
565 + SSH_CONNECTION: "client server",
566 + });
567 + assert.equal(launch.command, "xdg-open");
568 +});
569 +
570 +it.layer(NodeServices.layer)("launchBrowser", (it) => {
571 + it.effect("spawns through the ChildProcessSpawner service and unrefs the handle", () =>
572 + Effect.gen(function* () {
573 + let spawnedCommand: ChildProcess.StandardCommand | undefined;
574 + let didUnref = false;
575 +
576 + const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
577 + spawn: (command) =>
578 + Effect.sync(() => {
579 + assert.equal(ChildProcess.isStandardCommand(command), true);
580 + if (!ChildProcess.isStandardCommand(command)) {
581 + throw new Error("Expected a standard command");
582 + }
583 + spawnedCommand = command;
584 + return makeMockDetachedHandle(() => {
585 + didUnref = true;
586 + });
587 + }),
588 + });
589 +
590 + const result = yield* launchBrowser("https://example.com").pipe(
591 + Effect.provide(spawnerLayer),
592 + Effect.result,
593 + );
594 +
595 + assertSuccess(result, undefined);
596 + assert.ok(spawnedCommand);
597 + const expectedLaunch = resolveBrowserLaunch("https://example.com");
598 + assert.equal(spawnedCommand.command, expectedLaunch.command);
599 + assert.deepEqual(spawnedCommand.args, expectedLaunch.args);
600 + assert.deepEqual(spawnedCommand.options, expectedLaunch.options);
601 + assert.equal(didUnref, true);
602 + }),
603 + );
604 +});
605 +
606 +it.layer(NodeServices.layer)("launchEditorProcess", (it) => {
607 + it.effect("spawns through the ChildProcessSpawner service and unrefs the handle", () =>
608 Effect.gen(function* () {
483 - const result = yield* launchDetached({
609 + let spawnedCommand: ChildProcess.StandardCommand | undefined;
610 + let didUnref = false;
611 + const expectedArgs = ["-e", "process.exit(0)"];
612 +
613 + const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {
614 + spawn: (command) =>
615 + Effect.sync(() => {
616 + assert.equal(ChildProcess.isStandardCommand(command), true);
617 + if (!ChildProcess.isStandardCommand(command)) {
618 + throw new Error("Expected a standard command");
619 + }
620 + spawnedCommand = command;
621 + return makeMockDetachedHandle(() => {
622 + didUnref = true;
623 + });
624 + }),
625 + });
626 +
627 + const result = yield* launchEditorProcess({
628 command: process.execPath,
485 - args: ["-e", "process.exit(0)"],
486 - }).pipe(Effect.result);
629 + args: expectedArgs,
630 + }).pipe(Effect.provide(spawnerLayer), Effect.result);
631 +
632 assertSuccess(result, undefined);
633 + assert.ok(spawnedCommand);
634 + assert.equal(spawnedCommand.command, process.execPath);
635 + assert.deepEqual(
636 + spawnedCommand.args,
637 + process.platform === "win32" ? expectedArgs.map((arg) => `"${arg}"`) : expectedArgs,
638 + );
639 + assert.deepEqual(spawnedCommand.options, {
640 + detached: true,
641 + shell: process.platform === "win32",
642 + stdin: "ignore",
643 + stdout: "ignore",
644 + stderr: "ignore",
645 + });
646 + assert.equal(didUnref, true);
647 }),
648 );
649
650 it.effect("rejects when command does not exist", () =>
651 Effect.gen(function* () {
493 - const result = yield* launchDetached({
652 + const spawnerLayer = Layer.mock(ChildProcessSpawner.ChildProcessSpawner, {});
653 + const result = yield* launchEditorProcess({
654 command: `t3code-no-such-command-${yield* Random.nextUUIDv4}`,
655 args: [],
496 - }).pipe(Effect.result);
656 + }).pipe(Effect.provide(spawnerLayer), Effect.result);
657 assert.equal(result._tag, "Failure");
658 }),
659 );
@@ -504,7 +664,7 @@ it.layer(NodeServices.layer)("isCommandAvailable", (it) => {
664 Effect.gen(function* () {
665 const fs = yield* FileSystem.FileSystem;
666 const path = yield* Path.Path;
507 - const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
667 + const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
668 yield* fs.writeFileString(path.join(dir, "code.CMD"), "@echo off\r\n");
669 const env = {
670 PATH: dir,
@@ -526,7 +686,7 @@ it.layer(NodeServices.layer)("isCommandAvailable", (it) => {
686 Effect.gen(function* () {
687 const fs = yield* FileSystem.FileSystem;
688 const path = yield* Path.Path;
529 - const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
689 + const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
690 yield* fs.writeFileString(path.join(dir, "npm"), "echo nope\r\n");
691 const env = {
692 PATH: dir,
@@ -540,7 +700,7 @@ it.layer(NodeServices.layer)("isCommandAvailable", (it) => {
700 Effect.gen(function* () {
701 const fs = yield* FileSystem.FileSystem;
702 const path = yield* Path.Path;
543 - const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
703 + const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
704 yield* fs.writeFileString(path.join(dir, "my.tool.CMD"), "@echo off\r\n");
705 const env = {
706 PATH: dir,
@@ -554,8 +714,8 @@ it.layer(NodeServices.layer)("isCommandAvailable", (it) => {
714 Effect.gen(function* () {
715 const fs = yield* FileSystem.FileSystem;
716 const path = yield* Path.Path;
557 - const firstDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
558 - const secondDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
717 + const firstDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
718 + const secondDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-external-launcher-test-" });
719 yield* fs.writeFileString(path.join(firstDir, "code.CMD"), "@echo off\r\n");
720 yield* fs.writeFileString(path.join(secondDir, "code.CMD"), "MZ");
721 const env = {
apps/server/src/process/externalLauncher.ts new
+364
@@ -0,0 +1,364 @@
1 +/**
2 + * ExternalLauncher - external application launch service interface.
3 + *
4 + * Owns process launch helpers for browser URLs and workspace paths
5 + * in configured editor integrations.
6 + *
7 + * @module ExternalLauncher
8 + */
9 +import {
10 + EDITORS,
11 + ExternalLauncherError,
12 + type EditorId,
13 + type LaunchEditorInput,
14 +} from "@t3tools/contracts";
15 +import { isCommandAvailable, type CommandAvailabilityOptions } from "@t3tools/shared/shell";
16 +import * as Context from "effect/Context";
17 +import * as Effect from "effect/Effect";
18 +import * as Encoding from "effect/Encoding";
19 +import * as Layer from "effect/Layer";
20 +import * as Option from "effect/Option";
21 +import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
22 +
23 +// ==============================
24 +// Definitions
25 +// ==============================
26 +
27 +export { ExternalLauncherError };
28 +export type { LaunchEditorInput };
29 +export { isCommandAvailable } from "@t3tools/shared/shell";
30 +
31 +interface EditorLaunch {
32 + readonly command: string;
33 + readonly args: ReadonlyArray<string>;
34 +}
35 +
36 +interface ProcessLaunch {
37 + readonly command: string;
38 + readonly args: ReadonlyArray<string>;
39 + readonly options: ChildProcess.CommandOptions;
40 +}
41 +
42 +interface TargetPathAndPosition {
43 + readonly path: string;
44 + readonly line: string;
45 + readonly column: Option.Option<string>;
46 +}
47 +
48 +const TARGET_WITH_POSITION_PATTERN = /^(.*?):(\d+)(?::(\d+))?$/;
49 +const POWERSHELL_ARGUMENTS_PREFIX = [
50 + "-NoProfile",
51 + "-NonInteractive",
52 + "-ExecutionPolicy",
53 + "Bypass",
54 + "-EncodedCommand",
55 +] as const;
56 +
57 +const DETACHED_IGNORE_STDIO_OPTIONS = {
58 + detached: true,
59 + stdin: "ignore",
60 + stdout: "ignore",
61 + stderr: "ignore",
62 +} as const satisfies ChildProcess.CommandOptions;
63 +
64 +function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAndPosition> {
65 + const match = TARGET_WITH_POSITION_PATTERN.exec(target);
66 + if (!match?.[1] || !match[2]) {
67 + return Option.none();
68 + }
69 +
70 + return Option.some({
71 + path: match[1],
72 + line: match[2],
73 + column: Option.fromUndefinedOr(match[3]),
74 + });
75 +}
76 +
77 +function resolveCommandEditorArgs(
78 + editor: (typeof EDITORS)[number],
79 + target: string,
80 +): ReadonlyArray<string> {
81 + const parsedTarget = parseTargetPathAndPosition(target);
82 +
83 + switch (editor.launchStyle) {
84 + case "direct-path":
85 + return [target];
86 + case "goto":
87 + return Option.isSome(parsedTarget) ? ["--goto", target] : [target];
88 + case "line-column":
89 + return Option.match(parsedTarget, {
90 + onNone: () => [target],
91 + onSome: ({ path, line, column }) => [
92 + "--line",
93 + line,
94 + ...Option.match(column, {
95 + onNone: () => [],
96 + onSome: (value) => ["--column", value],
97 + }),
98 + path,
99 + ],
100 + });
101 + }
102 +}
103 +
104 +function resolveEditorArgs(
105 + editor: (typeof EDITORS)[number],
106 + target: string,
107 +): ReadonlyArray<string> {
108 + const baseArgs = "baseArgs" in editor ? editor.baseArgs : [];
109 + return [...baseArgs, ...resolveCommandEditorArgs(editor, target)];
110 +}
111 +
112 +function resolveAvailableCommand(
113 + commands: ReadonlyArray<string>,
114 + options: CommandAvailabilityOptions = {},
115 +): Option.Option<string> {
116 + for (const command of commands) {
117 + if (isCommandAvailable(command, options)) {
118 + return Option.some(command);
119 + }
120 + }
121 + return Option.none();
122 +}
123 +
124 +function encodeUtf16LeBase64(input: string): string {
125 + const bytes = new Uint8Array(input.length * 2);
126 + for (let index = 0; index < input.length; index += 1) {
127 + const code = input.charCodeAt(index);
128 + bytes[index * 2] = code & 0xff;
129 + bytes[index * 2 + 1] = code >>> 8;
130 + }
131 + return Encoding.encodeBase64(bytes);
132 +}
133 +
134 +function escapePowerShellStringLiteral(input: string): string {
135 + return `'${input.replaceAll("'", "''")}'`;
136 +}
137 +
138 +function resolvePowerShellPath(env: NodeJS.ProcessEnv = process.env): string {
139 + return `${env.SYSTEMROOT || env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
140 +}
141 +
142 +function resolveWslPowerShellPath(): string {
143 + return "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe";
144 +}
145 +
146 +function shouldUseWindowsBrowserFromWsl(
147 + platform: NodeJS.Platform,
148 + env: NodeJS.ProcessEnv = process.env,
149 +): boolean {
150 + return (
151 + platform === "linux" &&
152 + (env.WSL_DISTRO_NAME !== undefined || env.WSL_INTEROP !== undefined) &&
153 + env.SSH_CONNECTION === undefined &&
154 + env.SSH_TTY === undefined &&
155 + env.container === undefined
156 + );
157 +}
158 +
159 +function resolveWindowsBrowserLaunch(target: string, command: string): ProcessLaunch {
160 + const encodedCommand = encodeUtf16LeBase64(
161 + `$ProgressPreference = 'SilentlyContinue'; Start ${escapePowerShellStringLiteral(target)}`,
162 + );
163 + return {
164 + command,
165 + args: [...POWERSHELL_ARGUMENTS_PREFIX, encodedCommand],
166 + options: {
167 + detached: true,
168 + shell: false,
169 + stdin: "ignore",
170 + stdout: "ignore",
171 + stderr: "ignore",
172 + },
173 + };
174 +}
175 +
176 +function fileManagerCommandForPlatform(platform: NodeJS.Platform): string {
177 + switch (platform) {
178 + case "darwin":
179 + return "open";
180 + case "win32":
181 + return "explorer";
182 + default:
183 + return "xdg-open";
184 + }
185 +}
186 +
187 +export function resolveBrowserLaunch(
188 + target: string,
189 + platform: NodeJS.Platform = process.platform,
190 + env: NodeJS.ProcessEnv = process.env,
191 +): ProcessLaunch {
192 + if (platform === "darwin") {
193 + return {
194 + command: "open",
195 + args: [target],
196 + options: DETACHED_IGNORE_STDIO_OPTIONS,
197 + };
198 + }
199 +
200 + if (platform === "win32") {
201 + return resolveWindowsBrowserLaunch(target, resolvePowerShellPath(env));
202 + }
203 +
204 + if (shouldUseWindowsBrowserFromWsl(platform, env)) {
205 + return resolveWindowsBrowserLaunch(target, resolveWslPowerShellPath());
206 + }
207 +
208 + return {
209 + command: "xdg-open",
210 + args: [target],
211 + options: DETACHED_IGNORE_STDIO_OPTIONS,
212 + };
213 +}
214 +
215 +export function resolveAvailableEditors(
216 + platform: NodeJS.Platform = process.platform,
217 + env: NodeJS.ProcessEnv = process.env,
218 +): ReadonlyArray<EditorId> {
219 + const available: EditorId[] = [];
220 +
221 + for (const editor of EDITORS) {
222 + if (editor.commands === null) {
223 + const command = fileManagerCommandForPlatform(platform);
224 + if (isCommandAvailable(command, { platform, env })) {
225 + available.push(editor.id);
226 + }
227 + continue;
228 + }
229 +
230 + const command = resolveAvailableCommand(editor.commands, { platform, env });
231 + if (Option.isSome(command)) {
232 + available.push(editor.id);
233 + }
234 + }
235 +
236 + return available;
237 +}
238 +
239 +/**
240 + * ExternalLauncherShape - Service API for browser and editor launch actions.
241 + */
242 +export interface ExternalLauncherShape {
243 + /**
244 + * Launch a URL target in the default browser.
245 + */
246 + readonly launchBrowser: (target: string) => Effect.Effect<void, ExternalLauncherError>;
247 +
248 + /**
249 + * Launch a workspace path in a selected editor integration.
250 + *
251 + * Launches the editor as a detached process so server startup is not blocked.
252 + */
253 + readonly launchEditor: (input: LaunchEditorInput) => Effect.Effect<void, ExternalLauncherError>;
254 +}
255 +
256 +/**
257 + * ExternalLauncher - Service tag for browser/editor launch operations.
258 + */
259 +export class ExternalLauncher extends Context.Service<ExternalLauncher, ExternalLauncherShape>()(
260 + "t3/process/ExternalLauncher",
261 +) {}
262 +
263 +// ==============================
264 +// Implementations
265 +// ==============================
266 +
267 +export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
268 + input: LaunchEditorInput,
269 + platform: NodeJS.Platform = process.platform,
270 + env: NodeJS.ProcessEnv = process.env,
271 +): Effect.fn.Return<EditorLaunch, ExternalLauncherError> {
272 + yield* Effect.annotateCurrentSpan({
273 + "externalLauncher.editor": input.editor,
274 + "externalLauncher.cwd": input.cwd,
275 + "externalLauncher.platform": platform,
276 + });
277 + const editorDef = EDITORS.find((editor) => editor.id === input.editor);
278 + if (!editorDef) {
279 + return yield* new ExternalLauncherError({ message: `Unknown editor: ${input.editor}` });
280 + }
281 +
282 + if (editorDef.commands) {
283 + const command = Option.getOrElse(
284 + resolveAvailableCommand(editorDef.commands, { platform, env }),
285 + () => editorDef.commands[0],
286 + );
287 + return {
288 + command,
289 + args: resolveEditorArgs(editorDef, input.cwd),
290 + };
291 + }
292 +
293 + if (editorDef.id !== "file-manager") {
294 + return yield* new ExternalLauncherError({ message: `Unsupported editor: ${input.editor}` });
295 + }
296 +
297 + return { command: fileManagerCommandForPlatform(platform), args: [input.cwd] };
298 +});
299 +
300 +const launchAndUnref = Effect.fn("externalLauncher.launchAndUnref")(function* (
301 + launch: ProcessLaunch,
302 + errorMessage: string,
303 +): Effect.fn.Return<void, ExternalLauncherError, ChildProcessSpawner.ChildProcessSpawner> {
304 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
305 + const command = ChildProcess.make(launch.command, launch.args, launch.options);
306 +
307 + yield* spawner.spawn(command).pipe(
308 + Effect.flatMap((handle) => handle.unref),
309 + Effect.asVoid,
310 + Effect.scoped,
311 + Effect.mapError((cause) => new ExternalLauncherError({ message: errorMessage, cause })),
312 + );
313 +});
314 +
315 +export const launchBrowser = Effect.fn("externalLauncher.launchBrowser")(function* (
316 + target: string,
317 +): Effect.fn.Return<void, ExternalLauncherError, ChildProcessSpawner.ChildProcessSpawner> {
318 + return yield* launchAndUnref(resolveBrowserLaunch(target), "Browser auto-open failed");
319 +});
320 +
321 +export const launchEditorProcess = Effect.fn("externalLauncher.launchEditorProcess")(function* (
322 + launch: EditorLaunch,
323 +): Effect.fn.Return<void, ExternalLauncherError, ChildProcessSpawner.ChildProcessSpawner> {
324 + if (!isCommandAvailable(launch.command)) {
325 + return yield* new ExternalLauncherError({
326 + message: `Editor command not found: ${launch.command}`,
327 + });
328 + }
329 +
330 + const isWin32 = process.platform === "win32";
331 + yield* launchAndUnref(
332 + {
333 + command: launch.command,
334 + args: isWin32 ? launch.args.map((arg) => `"${arg}"`) : [...launch.args],
335 + options: {
336 + detached: true,
337 + shell: isWin32,
338 + stdin: "ignore",
339 + stdout: "ignore",
340 + stderr: "ignore",
341 + },
342 + },
343 + "failed to spawn detached process",
344 + );
345 +});
346 +
347 +const make = Effect.gen(function* () {
348 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
349 +
350 + return {
351 + launchBrowser: (target) =>
352 + launchBrowser(target).pipe(
353 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
354 + ),
355 + launchEditor: (input) =>
356 + Effect.flatMap(resolveEditorLaunch(input), (launch) =>
357 + launchEditorProcess(launch).pipe(
358 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
359 + ),
360 + ),
361 + } satisfies ExternalLauncherShape;
362 +});
363 +
364 +export const layer = Layer.effect(ExternalLauncher, make);
apps/server/src/server.test.ts
+13 -11
@@ -10,7 +10,7 @@ import {
10 GitCommandError,
11 KeybindingRule,
12 MessageId,
13 - OpenError,
13 + ExternalLauncherError,
14 type OrchestrationThreadShell,
15 TerminalNotRunningError,
16 type OrchestrationCommand,
@@ -63,7 +63,7 @@ import {
63 } from "./checkpointing/Services/CheckpointDiffQuery.ts";
64 import { GitManager, type GitManagerShape } from "./git/GitManager.ts";
65 import { Keybindings, type KeybindingsShape } from "./keybindings.ts";
66 -import { Open, type OpenShape } from "./open.ts";
66 +import * as ExternalLauncher from "./process/externalLauncher.ts";
67 import {
68 OrchestrationEngineService,
69 type OrchestrationEngineShape,
@@ -319,7 +319,7 @@ const buildAppUnderTest = (options?: {
319 keybindings?: Partial<KeybindingsShape>;
320 providerRegistry?: Partial<ProviderRegistryShape>;
321 serverSettings?: Partial<ServerSettingsShape>;
322 - open?: Partial<OpenShape>;
322 + externalLauncher?: Partial<ExternalLauncher.ExternalLauncherShape>;
323 vcsDriver?: Partial<VcsDriver.VcsDriverShape>;
324 vcsDriverRegistry?: Partial<VcsDriverRegistry.VcsDriverRegistryShape>;
325 gitVcsDriver?: Partial<GitVcsDriver.GitVcsDriverShape>;
@@ -540,8 +540,8 @@ const buildAppUnderTest = (options?: {
540 }),
541 ),
542 Layer.provide(
543 - Layer.mock(Open)({
544 - ...options?.layers?.open,
543 + Layer.mock(ExternalLauncher.ExternalLauncher)({
544 + ...options?.layers?.externalLauncher,
545 }),
546 ),
547 Layer.provide(
@@ -2517,8 +2517,8 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
2517 let openedInput: { cwd: string; editor: EditorId } | null = null;
2518 yield* buildAppUnderTest({
2519 layers: {
2520 - open: {
2521 - openInEditor: (input) =>
2520 + externalLauncher: {
2521 + launchEditor: (input) =>
2522 Effect.sync(() => {
2523 openedInput = input;
2524 }),
@@ -2542,11 +2542,13 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
2542
2543 it.effect("routes websocket rpc shell.openInEditor errors", () =>
2544 Effect.gen(function* () {
2545 - const openError = new OpenError({ message: "Editor command not found: cursor" });
2545 + const externalLauncherError = new ExternalLauncherError({
2546 + message: "Editor command not found: cursor",
2547 + });
2548 yield* buildAppUnderTest({
2549 layers: {
2548 - open: {
2549 - openInEditor: () => Effect.fail(openError),
2550 + externalLauncher: {
2551 + launchEditor: () => Effect.fail(externalLauncherError),
2552 },
2553 },
2554 });
@@ -2561,7 +2563,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
2563 ).pipe(Effect.result),
2564 );
2565
2564 - assertFailure(result, openError);
2566 + assertFailure(result, externalLauncherError);
2567 }).pipe(Effect.provide(NodeHttpServer.layerTest)),
2568 );
2569
apps/server/src/server.ts
+2 -2
@@ -13,7 +13,7 @@ import {
13 } from "./http.ts";
14 import { fixPath } from "./os-jank.ts";
15 import { websocketRpcRouteLayer } from "./ws.ts";
16 -import { OpenLive } from "./open.ts";
16 +import * as ExternalLauncher from "./process/externalLauncher.ts";
17 import { layerConfig as SqlitePersistenceLayerLive } from "./persistence/Layers/Sqlite.ts";
18 import { ServerLifecycleEventsLive } from "./serverLifecycleEvents.ts";
19 import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService.ts";
@@ -282,7 +282,7 @@ const RuntimeDependenciesLive = RuntimeCoreDependenciesLive.pipe(
282 Layer.provideMerge(ProcessDiagnostics.layer),
283 Layer.provideMerge(TraceDiagnostics.layer),
284 Layer.provideMerge(AnalyticsServiceLayerLive),
285 - Layer.provideMerge(OpenLive),
285 + Layer.provideMerge(ExternalLauncher.layer),
286 Layer.provideMerge(ServerLifecycleEventsLive),
287 Layer.provide(NetService.layer),
288 );
apps/server/src/serverRuntimeStartup.ts
+3 -3
@@ -23,7 +23,7 @@ import * as DateTime from "effect/DateTime";
23
24 import { ServerConfig } from "./config.ts";
25 import { Keybindings } from "./keybindings.ts";
26 -import { Open } from "./open.ts";
26 +import * as ExternalLauncher from "./process/externalLauncher.ts";
27 import { OrchestrationEngineService } from "./orchestration/Services/OrchestrationEngine.ts";
28 import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
29 import { OrchestrationReactor } from "./orchestration/Services/OrchestrationReactor.ts";
@@ -261,9 +261,9 @@ const maybeOpenBrowser = (target: string) =>
261 if (serverConfig.noBrowser) {
262 return;
263 }
264 - const { openBrowser } = yield* Open;
264 + const externalLauncher = yield* ExternalLauncher.ExternalLauncher;
265
266 - yield* openBrowser(target).pipe(
266 + yield* externalLauncher.launchBrowser(target).pipe(
267 Effect.catch(() =>
268 Effect.logInfo("browser auto-open unavailable", {
269 hint: `Open ${target} in your browser.`,
apps/server/src/ws.ts
+4 -4
@@ -40,7 +40,7 @@ import { RpcSerialization, RpcServer } from "effect/unstable/rpc";
40 import { CheckpointDiffQuery } from "./checkpointing/Services/CheckpointDiffQuery.ts";
41 import { ServerConfig } from "./config.ts";
42 import { Keybindings } from "./keybindings.ts";
43 -import { Open, resolveAvailableEditors } from "./open.ts";
43 +import * as ExternalLauncher from "./process/externalLauncher.ts";
44 import { normalizeDispatchCommand } from "./orchestration/Normalizer.ts";
45 import { OrchestrationEngineService } from "./orchestration/Services/OrchestrationEngine.ts";
46 import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
@@ -163,7 +163,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
163 const orchestrationEngine = yield* OrchestrationEngineService;
164 const checkpointDiffQuery = yield* CheckpointDiffQuery;
165 const keybindings = yield* Keybindings;
166 - const open = yield* Open;
166 + const externalLauncher = yield* ExternalLauncher.ExternalLauncher;
167 const gitWorkflow = yield* GitWorkflowService;
168 const vcsProvisioning = yield* VcsProvisioningService;
169 const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;
@@ -583,7 +583,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
583 keybindings: keybindingsConfig.keybindings,
584 issues: keybindingsConfig.issues,
585 providers,
586 - availableEditors: resolveAvailableEditors(),
586 + availableEditors: ExternalLauncher.resolveAvailableEditors(),
587 observability: {
588 logsDirectoryPath: config.logsDir,
589 localTracingEnabled: true,
@@ -970,7 +970,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
970 { "rpc.aggregate": "workspace" },
971 ),
972 [WS_METHODS.shellOpenInEditor]: (input) =>
973 - observeRpcEffect(WS_METHODS.shellOpenInEditor, open.openInEditor(input), {
973 + observeRpcEffect(WS_METHODS.shellOpenInEditor, externalLauncher.launchEditor(input), {
974 "rpc.aggregate": "workspace",
975 }),
976 [WS_METHODS.filesystemBrowse]: (input) =>
bun.lock
+4 -19
@@ -17,7 +17,7 @@
17 },
18 "apps/desktop": {
19 "name": "@t3tools/desktop",
20 - "version": "0.0.22",
20 + "version": "0.0.23",
21 "dependencies": {
22 "@effect/platform-node": "catalog:",
23 "effect": "catalog:",
@@ -52,7 +52,7 @@
52 },
53 "apps/server": {
54 "name": "t3",
55 - "version": "0.0.22",
55 + "version": "0.0.23",
56 "bin": {
57 "t3": "./dist/bin.mjs",
58 },
@@ -65,7 +65,6 @@
65 "@pierre/diffs": "catalog:",
66 "effect": "catalog:",
67 "node-pty": "^1.1.0",
68 - "open": "^10.1.0",
68 },
69 "devDependencies": {
70 "@effect/language-service": "catalog:",
@@ -85,7 +84,7 @@
84 },
85 "apps/web": {
86 "name": "@t3tools/web",
88 - "version": "0.0.22",
87 + "version": "0.0.23",
88 "dependencies": {
89 "@base-ui/react": "^1.4.1",
90 "@dnd-kit/core": "^6.3.1",
@@ -167,7 +166,7 @@
166 },
167 "packages/contracts": {
168 "name": "@t3tools/contracts",
170 - "version": "0.0.22",
169 + "version": "0.0.23",
170 "dependencies": {
171 "effect": "catalog:",
172 },
@@ -1038,8 +1037,6 @@
1037
1038 "bun-types": ["bun-types@1.3.11", "", { "dependencies": { "@types/node": "*" } }, "sha512-1KGPpoxQWl9f6wcZh57LvrPIInQMn2TQ7jsgxqpRzg+l0QPOFvJVH7HmvHo/AiPgwXy+/Thf6Ov3EdVn1vOabg=="],
1039
1041 - "bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="],
1042 -
1040 "bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="],
1041
1042 "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="],
@@ -1126,16 +1123,10 @@
1123
1124 "decompress-response": ["decompress-response@6.0.0", "", { "dependencies": { "mimic-response": "^3.1.0" } }, "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ=="],
1125
1129 - "default-browser": ["default-browser@5.5.0", "", { "dependencies": { "bundle-name": "^4.1.0", "default-browser-id": "^5.0.0" } }, "sha512-H9LMLr5zwIbSxrmvikGuI/5KGhZ8E2zH3stkMgM5LpOWDutGM2JZaj460Udnf1a+946zc7YBgrqEWwbk7zHvGw=="],
1130 -
1131 - "default-browser-id": ["default-browser-id@5.0.1", "", {}, "sha512-x1VCxdX4t+8wVfd1so/9w+vQ4vx7lKd2Qp5tDRutErwmR85OgmfX7RlLRMWafRMY7hbEiXIbudNrjOAPa/hL8Q=="],
1132 -
1126 "defer-to-connect": ["defer-to-connect@2.0.1", "", {}, "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg=="],
1127
1128 "define-data-property": ["define-data-property@1.1.4", "", { "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", "gopd": "^1.0.1" } }, "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A=="],
1129
1137 - "define-lazy-prop": ["define-lazy-prop@3.0.0", "", {}, "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg=="],
1138 -
1130 "define-properties": ["define-properties@1.2.1", "", { "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", "object-keys": "^1.1.1" } }, "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg=="],
1131
1132 "defu": ["defu@6.1.4", "", {}, "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg=="],
@@ -1664,8 +1655,6 @@
1655
1656 "oniguruma-to-es": ["oniguruma-to-es@4.3.5", "", { "dependencies": { "oniguruma-parser": "^0.12.1", "regex": "^6.1.0", "regex-recursion": "^6.0.2" } }, "sha512-Zjygswjpsewa0NLTsiizVuMQZbp0MDyM6lIt66OxsF21npUDlzpHi1Mgb/qhQdkb+dWFTzJmFbEWdvZgRho8eQ=="],
1657
1667 - "open": ["open@10.2.0", "", { "dependencies": { "default-browser": "^5.2.1", "define-lazy-prop": "^3.0.0", "is-inside-container": "^1.0.0", "wsl-utils": "^0.1.0" } }, "sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA=="],
1668 -
1658 "outvariant": ["outvariant@1.4.3", "", {}, "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA=="],
1659
1660 "oxfmt": ["oxfmt@0.40.0", "", { "dependencies": { "tinypool": "2.1.0" }, "optionalDependencies": { "@oxfmt/binding-android-arm-eabi": "0.40.0", "@oxfmt/binding-android-arm64": "0.40.0", "@oxfmt/binding-darwin-arm64": "0.40.0", "@oxfmt/binding-darwin-x64": "0.40.0", "@oxfmt/binding-freebsd-x64": "0.40.0", "@oxfmt/binding-linux-arm-gnueabihf": "0.40.0", "@oxfmt/binding-linux-arm-musleabihf": "0.40.0", "@oxfmt/binding-linux-arm64-gnu": "0.40.0", "@oxfmt/binding-linux-arm64-musl": "0.40.0", "@oxfmt/binding-linux-ppc64-gnu": "0.40.0", "@oxfmt/binding-linux-riscv64-gnu": "0.40.0", "@oxfmt/binding-linux-riscv64-musl": "0.40.0", "@oxfmt/binding-linux-s390x-gnu": "0.40.0", "@oxfmt/binding-linux-x64-gnu": "0.40.0", "@oxfmt/binding-linux-x64-musl": "0.40.0", "@oxfmt/binding-openharmony-arm64": "0.40.0", "@oxfmt/binding-win32-arm64-msvc": "0.40.0", "@oxfmt/binding-win32-ia32-msvc": "0.40.0", "@oxfmt/binding-win32-x64-msvc": "0.40.0" }, "bin": { "oxfmt": "bin/oxfmt" } }, "sha512-g0C3I7xUj4b4DcagevM9kgH6+pUHytikxUcn3/VUkvzTNaaXBeyZqb7IBsHwojeXm4mTBEC/aBjBTMVUkZwWUQ=="],
@@ -1820,8 +1809,6 @@
1809
1810 "router": ["router@2.2.0", "", { "dependencies": { "debug": "^4.4.0", "depd": "^2.0.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" } }, "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ=="],
1811
1823 - "run-applescript": ["run-applescript@7.1.0", "", {}, "sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q=="],
1824 -
1812 "safer-buffer": ["safer-buffer@2.1.2", "", {}, "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="],
1813
1814 "sax": ["sax@1.5.0", "", {}, "sha512-21IYA3Q5cQf089Z6tgaUTr7lDAyzoTPx5HRtbhsME8Udispad8dC/+sziTNugOEx54ilvatQ9YCzl4KQLPcRHA=="],
@@ -2110,8 +2097,6 @@
2097
2098 "ws": ["ws@8.20.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA=="],
2099
2113 - "wsl-utils": ["wsl-utils@0.1.0", "", { "dependencies": { "is-wsl": "^3.1.0" } }, "sha512-h3Fbisa2nKGPxCpm89Hk33lBLsnaGBvctQopaBSOW/uIs6FTe1ATyAnKFJrzVs9vpGdsTe73WF3V4lIsk4Gacw=="],
2114 -
2100 "xxhash-wasm": ["xxhash-wasm@1.1.0", "", {}, "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA=="],
2101
2102 "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="],
packages/contracts/src/editor.ts
+9 -6
@@ -44,13 +44,16 @@ export const EDITORS = [
44 export const EditorId = Schema.Literals(EDITORS.map((e) => e.id));
45 export type EditorId = typeof EditorId.Type;
46
47 -export const OpenInEditorInput = Schema.Struct({
47 +export const LaunchEditorInput = Schema.Struct({
48 cwd: TrimmedNonEmptyString,
49 editor: EditorId,
50 });
51 -export type OpenInEditorInput = typeof OpenInEditorInput.Type;
51 +export type LaunchEditorInput = typeof LaunchEditorInput.Type;
52
53 -export class OpenError extends Schema.TaggedErrorClass<OpenError>()("OpenError", {
54 - message: Schema.String,
55 - cause: Schema.optional(Schema.Defect),
56 -}) {}
53 +export class ExternalLauncherError extends Schema.TaggedErrorClass<ExternalLauncherError>()(
54 + "ExternalLauncherError",
55 + {
56 + message: Schema.String,
57 + cause: Schema.optional(Schema.Defect),
58 + },
59 +) {}
packages/contracts/src/rpc.ts
+3 -3
@@ -2,7 +2,7 @@ import * as Schema from "effect/Schema";
2 import * as Rpc from "effect/unstable/rpc/Rpc";
3 import * as RpcGroup from "effect/unstable/rpc/RpcGroup";
4
5 -import { OpenError, OpenInEditorInput } from "./editor.ts";
5 +import { ExternalLauncherError, LaunchEditorInput } from "./editor.ts";
6 import { AuthAccessStreamEvent } from "./auth.ts";
7 import {
8 FilesystemBrowseInput,
@@ -266,8 +266,8 @@ export const WsProjectsWriteFileRpc = Rpc.make(WS_METHODS.projectsWriteFile, {
266 });
267
268 export const WsShellOpenInEditorRpc = Rpc.make(WS_METHODS.shellOpenInEditor, {
269 - payload: OpenInEditorInput,
270 - error: OpenError,
269 + payload: LaunchEditorInput,
270 + error: ExternalLauncherError,
271 });
272
273 export const WsFilesystemBrowseRpc = Rpc.make(WS_METHODS.filesystemBrowse, {