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 24, 14:00 UTC
fix(server): keep provider CLIs available in the macOS service (#8173)
Theo Browne committed
Aug 25, 2026 at 00:35 UTC
1baf99195a552572e24f907cd7f72ce01c6c81c8
2 files changed
+146
-30
apps/server/src/cloud/bootService.test.ts
+96
-24
@@ -56,17 +56,26 @@ const macPlan = {
56
logPath: "/Users/theo/.t3/userdata/logs/boot-service.log",
57
unitPath: "/Users/theo/Library/LaunchAgents/com.t3tools.t3code.service.plist",
58
};
59
+const macInstallerPath =
60
+ "/opt/homebrew/bin:/Users/theo/.npm-global/bin:/Users/theo/.nvm/versions/node/v22.16.0/bin:/usr/bin:/bin";
61
+const macRenderOptions = { homeDir: "/Users/theo", environmentPath: macInstallerPath };
62
63
it("keeps launchd pinned to the stable launcher rather than a versioned server", () => {
61
- const plist = BootService.renderBootServicePlist(macPlan, { homeDir: "/Users/theo" });
64
+ const plist = BootService.renderBootServicePlist(macPlan, macRenderOptions);
65
66
expect(plist).toContain("<string>/opt/homebrew/bin/node</string>");
67
expect(plist).toContain("<string>/Users/theo/.t3/runtime/service-launcher.mjs</string>");
68
expect(plist).not.toContain("versions/1.2.3");
69
});
70
71
+it("preserves the installer's provider search path in the launch agent", () => {
72
+ const plist = BootService.renderBootServicePlist(macPlan, macRenderOptions);
73
+
74
+ expect(plist).toContain(` <key>PATH</key>\n <string>${macInstallerPath}</string>`);
75
+});
76
+
77
it("restarts the launch agent on the systemd cadence", () => {
69
- const plist = BootService.renderBootServicePlist(macPlan, { homeDir: "/Users/theo" });
78
+ const plist = BootService.renderBootServicePlist(macPlan, macRenderOptions);
79
80
expect(plist).toContain("<key>RunAtLoad</key>\n <true/>");
81
expect(plist).toContain("<key>KeepAlive</key>\n <true/>");
@@ -75,7 +84,7 @@ it("restarts the launch agent on the systemd cadence", () => {
84
});
85
86
it("appends both stdio streams to the boot service log", () => {
78
- const plist = BootService.renderBootServicePlist(macPlan, { homeDir: "/Users/theo" });
87
+ const plist = BootService.renderBootServicePlist(macPlan, macRenderOptions);
88
89
expect(plist).toContain(
90
"<key>StandardOutPath</key>\n <string>/Users/theo/.t3/userdata/logs/boot-service.log</string>",
@@ -88,15 +97,17 @@ it("appends both stdio streams to the boot service log", () => {
97
it("escapes XML in host paths", () => {
98
const plist = BootService.renderBootServicePlist(
99
{ ...macPlan, baseDir: "/Users/theo/T3 & <Co>" },
91
- { homeDir: "/Users/theo" },
100
+ { homeDir: "/Users/theo", environmentPath: "/Users/theo/Tools & <Scripts>:/usr/bin" },
101
);
102
103
expect(plist).toContain("<string>/Users/theo/T3 & <Co></string>");
104
+ expect(plist).toContain("<string>/Users/theo/Tools & <Scripts>:/usr/bin</string>");
105
});
106
107
const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
108
platform: NodeJS.Platform = "linux",
109
usePinnedLauncher = false,
110
+ installerPath = macInstallerPath,
111
) {
112
const fs = yield* FileSystem.FileSystem;
113
const path = yield* Path.Path;
@@ -135,27 +146,33 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
146
};
147
}),
148
});
138
- const service = yield* BootService.make({
139
- baseDir,
140
- logsDir: path.join(baseDir, "userdata", "logs"),
141
- cliVersion: "1.2.3",
142
- host: {
143
- execPath: "/usr/bin/node",
144
- ...(usePinnedLauncher ? {} : { launcherSourcePath: sourceLauncher }),
145
- },
146
- }).pipe(
147
- Effect.provideService(ProcessRunner.ProcessRunner, runner),
148
- Effect.provide(
149
- Layer.mergeAll(
150
- Layer.succeed(HostProcessPlatform, platform),
151
- Layer.succeed(HostProcessUserId, 501),
152
- Layer.succeed(HostProcessExecutablePath, "/usr/bin/node"),
153
- Layer.succeed(HostProcessArguments, ["/usr/bin/node", path.join(home, "bin.mjs")]),
154
- ConfigProvider.layer(ConfigProvider.fromEnv({ env: { HOME: home } })),
149
+ const makeService = (environmentPath = installerPath) =>
150
+ BootService.make({
151
+ baseDir,
152
+ logsDir: path.join(baseDir, "userdata", "logs"),
153
+ cliVersion: "1.2.3",
154
+ host: {
155
+ execPath: "/usr/bin/node",
156
+ ...(usePinnedLauncher ? {} : { launcherSourcePath: sourceLauncher }),
157
+ },
158
+ }).pipe(
159
+ Effect.provideService(ProcessRunner.ProcessRunner, runner),
160
+ Effect.provide(
161
+ Layer.mergeAll(
162
+ Layer.succeed(HostProcessPlatform, platform),
163
+ Layer.succeed(HostProcessUserId, 501),
164
+ Layer.succeed(HostProcessExecutablePath, "/usr/bin/node"),
165
+ Layer.succeed(HostProcessArguments, ["/usr/bin/node", path.join(home, "bin.mjs")]),
166
+ ConfigProvider.layer(
167
+ ConfigProvider.fromEnv({
168
+ env: { HOME: home, ...(environmentPath === "" ? {} : { PATH: environmentPath }) },
169
+ }),
170
+ ),
171
+ ),
172
),
156
- ),
157
- );
158
- return { service, fs, statePath, commands, timeouts, control };
173
+ );
174
+ const service = yield* makeService();
175
+ return { service, makeService, fs, statePath, commands, timeouts, control };
176
});
177
178
it.layer(NodeServices.layer)("boot service install", (it) => {
@@ -266,6 +283,9 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
283
expect(plan.unitPath.endsWith("Library/LaunchAgents/com.t3tools.t3code.service.plist")).toBe(
284
true,
285
);
286
+ expect(yield* fs.readFileString(plan.unitPath)).toContain(
287
+ ` <key>PATH</key>\n <string>${macInstallerPath}:/usr/local/bin:/usr/sbin:/sbin</string>`,
288
+ );
289
expect(parseServiceState(yield* fs.readFileString(statePath))).toEqual({
290
protocol: SERVICE_LAUNCHER_PROTOCOL,
291
activeVersion: "1.2.3",
@@ -303,6 +323,58 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
323
}),
324
);
325
326
+ it.effect("reconstructs a launch agent search path when the installer has no PATH", () =>
327
+ Effect.gen(function* () {
328
+ const { service, fs } = yield* makeHarness("darwin", false, "");
329
+ const plan = yield* service.install;
330
+
331
+ expect(yield* fs.readFileString(plan.unitPath)).toContain(
332
+ " <key>PATH</key>\n <string>/usr/bin:/opt/homebrew/bin:/usr/local/bin:/bin:/usr/sbin:/sbin</string>",
333
+ );
334
+ expect((yield* service.status).current).toBe(true);
335
+ }),
336
+ );
337
+
338
+ it.effect("adds missing provider directories to a minimal installer PATH", () =>
339
+ Effect.gen(function* () {
340
+ const { service, fs } = yield* makeHarness("darwin", false, "/usr/bin:/bin");
341
+ const plan = yield* service.install;
342
+
343
+ expect(yield* fs.readFileString(plan.unitPath)).toContain(
344
+ " <key>PATH</key>\n <string>/usr/bin:/bin:/opt/homebrew/bin:/usr/local/bin:/usr/sbin:/sbin</string>",
345
+ );
346
+ expect((yield* service.status).current).toBe(true);
347
+ }),
348
+ );
349
+
350
+ it.effect("keeps an installed launch agent current when the process PATH changes", () =>
351
+ Effect.gen(function* () {
352
+ const { service, makeService } = yield* makeHarness("darwin");
353
+ yield* service.install;
354
+
355
+ const restartedService = yield* makeService("/usr/local/bin:/usr/bin:/bin");
356
+ expect((yield* restartedService.status).current).toBe(true);
357
+ }),
358
+ );
359
+
360
+ it.effect("drops PATH directories that cannot be represented in a launch agent plist", () =>
361
+ Effect.gen(function* () {
362
+ const { service, fs } = yield* makeHarness(
363
+ "darwin",
364
+ false,
365
+ "/opt/homebrew/bin:/Users/theo/\u0001invalid:/usr/bin",
366
+ );
367
+ const plan = yield* service.install;
368
+ const plist = yield* fs.readFileString(plan.unitPath);
369
+
370
+ expect(plist).toContain(
371
+ " <key>PATH</key>\n <string>/opt/homebrew/bin:/usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin</string>",
372
+ );
373
+ expect(plist).not.toContain("\u0001");
374
+ expect((yield* service.status).current).toBe(true);
375
+ }),
376
+ );
377
+
378
it.effect("ignores a bootout for an agent that is not loaded", () =>
379
Effect.gen(function* () {
380
const { service, control } = yield* makeHarness("darwin");
apps/server/src/cloud/bootService.ts
+50
-6
@@ -99,7 +99,7 @@ export function escapeXmlText(value: string): string {
99
/** Pure renderer: launch agents cannot rely on the user's shell or PATH. */
100
export function renderBootServicePlist(
101
plan: BootServicePlan,
102
- options: { readonly homeDir: string },
102
+ options: { readonly homeDir: string; readonly environmentPath: string },
103
): string {
104
// KeepAlive + ThrottleInterval mirror Restart=always + RestartSec=5. launchd
105
// has no StartLimitBurst analog; a hard crash loop respawns every 5s forever.
@@ -127,6 +127,8 @@ export function renderBootServicePlist(
127
` </array>`,
128
` <key>EnvironmentVariables</key>`,
129
` <dict>`,
130
+ ` <key>PATH</key>`,
131
+ ` <string>${escapeXmlText(options.environmentPath)}</string>`,
132
` <key>T3CODE_HOME</key>`,
133
` <string>${escapeXmlText(plan.baseDir)}</string>`,
134
` <key>${BOOT_SERVICE_UNIT_ENV}</key>`,
@@ -268,6 +270,7 @@ export function launchdManager(input: {
270
readonly path: Path.Path;
271
readonly homeDir: string;
272
readonly uid: number;
273
+ readonly environmentPath: string;
274
}): BootServiceManager {
275
const unitPath = input.path.join(
276
input.homeDir,
@@ -287,7 +290,11 @@ export function launchdManager(input: {
290
return {
291
kind: "launchd",
292
unitPath,
290
- render: (plan) => renderBootServicePlist(plan, { homeDir: input.homeDir }),
293
+ render: (plan) =>
294
+ renderBootServicePlist(plan, {
295
+ homeDir: input.homeDir,
296
+ environmentPath: input.environmentPath,
297
+ }),
298
// Without --wait, bootout returns in milliseconds while the job drains
299
// for up to ExitTimeOut, and a bootstrap during the drain fails EIO.
300
// --wait (present on modern macOS, absent from the man page) blocks until
@@ -346,6 +353,7 @@ export function selectBootServiceManager(input: {
353
readonly homeDir: string;
354
readonly uid: number | undefined;
355
readonly path: Path.Path;
356
+ readonly environmentPath: string;
357
}): BootServiceManager | undefined {
358
if (input.homeDir === "") {
359
return undefined;
@@ -354,7 +362,12 @@ export function selectBootServiceManager(input: {
362
return systemdManager({ path: input.path, homeDir: input.homeDir });
363
}
364
if (input.platform === "darwin" && input.uid !== undefined) {
357
- return launchdManager({ path: input.path, homeDir: input.homeDir, uid: input.uid });
365
+ return launchdManager({
366
+ path: input.path,
367
+ homeDir: input.homeDir,
368
+ uid: input.uid,
369
+ environmentPath: input.environmentPath,
370
+ });
371
}
372
return undefined;
373
}
@@ -441,12 +454,39 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
454
const platform = yield* HostProcessPlatform;
455
const uid = yield* HostProcessUserId;
456
const homeDir = yield* Config.string("HOME").pipe(Config.withDefault(""));
457
+ const installerPath = yield* Config.string("PATH").pipe(Config.withDefault(""));
458
const fs = yield* FileSystem.FileSystem;
459
const path = yield* Path.Path;
460
const runner = yield* ProcessRunner.ProcessRunner;
461
const host = input.host ?? { execPath: hostExecPath };
448
-
449
- const detectedManager = selectBootServiceManager({ platform, homeDir, uid, path });
462
+ const xmlSafeInstallerDirectories = installerPath.split(":").filter(
463
+ (directory) =>
464
+ directory.length > 0 &&
465
+ Array.from(directory).every((character) => {
466
+ const code = character.charCodeAt(0);
467
+ return code >= 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
468
+ }),
469
+ );
470
+ const environmentPath = Array.from(
471
+ new Set([
472
+ ...xmlSafeInstallerDirectories,
473
+ path.dirname(host.execPath),
474
+ "/opt/homebrew/bin",
475
+ "/usr/local/bin",
476
+ "/usr/bin",
477
+ "/bin",
478
+ "/usr/sbin",
479
+ "/sbin",
480
+ ]),
481
+ ).join(":");
482
+
483
+ const detectedManager = selectBootServiceManager({
484
+ platform,
485
+ homeDir,
486
+ uid,
487
+ path,
488
+ environmentPath,
489
+ });
490
const unitPath = detectedManager?.unitPath ?? "";
491
const logPath = path.join(input.logsDir, "boot-service.log");
492
const launcherPath = path.join(input.baseDir, "runtime", SERVICE_LAUNCHER_FILE);
@@ -664,11 +704,15 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
704
fs.readFileString(statePath).pipe(Effect.option),
705
]);
706
const state = Option.isSome(stateText) ? parseServiceState(stateText.value) : undefined;
707
+ const normalizeUnit = (contents: string) =>
708
+ detectedManager.kind === "launchd"
709
+ ? contents.replace(/(<key>PATH<\/key>\n\s*<string>)[^<]*(<\/string>)/, "$1$2")
710
+ : contents;
711
return {
712
supported: true,
713
installed: true,
714
current:
671
- unit === detectedManager.render(plan) &&
715
+ normalizeUnit(unit) === normalizeUnit(detectedManager.render(plan)) &&
716
launcherExists &&
717
runtimeEntryExists &&
718
Option.isSome(runtimeSentinel) &&