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 22, 04:30 UTC
refactor: Effect code reads env through HostProcess.Environment (#31218)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 4, 2026 at 19:31 UTC
e313a122452835da330feef41d0b74a4d2eddbeb
41 files changed
+404
-449
apps/desktop/src/app/DesktopApp.ts
+9
-2
@@ -1,4 +1,5 @@
1
import * as Cause from "effect/Cause";
2
+import * as Config from "effect/Config";
3
import * as Duration from "effect/Duration";
4
import * as Effect from "effect/Effect";
5
import * as Option from "effect/Option";
@@ -42,6 +43,11 @@ const DEFAULT_DESKTOP_BACKEND_PORT = 3773;
43
const MAX_TCP_PORT = 65_535;
44
const DESKTOP_BACKEND_PORT_PROBE_HOSTS = ["127.0.0.1", "0.0.0.0", "::"] as const;
45
46
+const LinuxDesktopSessionConfig = Config.all({
47
+ current: Config.String("XDG_CURRENT_DESKTOP").pipe(Config.option),
48
+ session: Config.String("XDG_SESSION_DESKTOP").pipe(Config.option),
49
+});
50
+
51
const makeDesktopRunId = SecureRandom.SecureRandom.pipe(
52
Effect.flatMap((random) => random.uuidV4()),
53
Effect.map((value) => value.replaceAll("-", "").slice(0, 12)),
@@ -307,12 +313,13 @@ const startup = Effect.gen(function* () {
313
yield* desktopSettings.load;
314
315
if (linuxElectronOptions !== null) {
316
+ const xdgDesktop = yield* LinuxDesktopSessionConfig;
317
yield* logStartupInfo("linux password store configured", {
318
passwordStore: hasCommandLinePasswordStore
319
? "command-line"
320
: (linuxElectronOptions.passwordStore ?? "electron-default"),
314
- xdgCurrentDesktop: process.env.XDG_CURRENT_DESKTOP ?? null,
315
- xdgSessionDesktop: process.env.XDG_SESSION_DESKTOP ?? null,
321
+ xdgCurrentDesktop: Option.getOrNull(xdgDesktop.current),
322
+ xdgSessionDesktop: Option.getOrNull(xdgDesktop.session),
323
});
324
}
325
apps/desktop/src/app/DesktopCliCommand.test.ts
+18
-18
@@ -1,5 +1,5 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
-import { afterEach, beforeEach, expect, it } from "@effect/vitest";
2
+import { expect, it } from "@effect/vitest";
3
import * as HostProcess from "@t3tools/shared/HostProcess";
4
import * as Effect from "effect/Effect";
5
import * as FileSystem from "effect/FileSystem";
@@ -29,7 +29,13 @@ const environmentFor = (
29
} as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
30
31
const commandIn = (
32
- input: { home: string; baseDir?: string; platform?: NodeJS.Platform; isPackaged?: boolean },
32
+ input: {
33
+ home: string;
34
+ baseDir?: string;
35
+ platform?: NodeJS.Platform;
36
+ isPackaged?: boolean;
37
+ env?: NodeJS.ProcessEnv;
38
+ },
39
spawner?: ChildProcessSpawner.ChildProcessSpawner["Service"],
40
) =>
41
Effect.gen(function* () {
@@ -42,6 +48,7 @@ const commandIn = (
48
DesktopEnvironment.DesktopEnvironment,
49
environmentFor(path, { ...input, baseDir }),
50
),
51
+ Effect.provideService(HostProcess.Environment, input.env ?? { PATH: "" }),
52
);
53
return yield* spawner
54
? make.pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner))
@@ -84,14 +91,6 @@ const fakePowerShell = (initial: string) => {
91
return { registry, spawner };
92
};
93
87
-const machinePath = process.env.PATH;
88
-beforeEach(() => {
89
- process.env.PATH = "";
90
-});
91
-afterEach(() => {
92
- process.env.PATH = machinePath;
93
-});
94
-
94
it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
95
it.effect("links the launcher onto PATH and removes only that link", () =>
96
Effect.gen(function* () {
@@ -124,7 +123,8 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
123
const fs = yield* FileSystem.FileSystem;
124
const path = yield* Path.Path;
125
const home = yield* fs.makeTempDirectoryScoped();
127
- const command = yield* commandIn({ home });
126
+ const env: NodeJS.ProcessEnv = { PATH: "" };
127
+ const command = yield* commandIn({ home, env });
128
const theirs = path.join(home, ".local", "bin", "t3");
129
yield* fs.makeDirectory(path.dirname(theirs), { recursive: true });
130
yield* fs.writeFileString(theirs, "npm's t3\n");
@@ -139,7 +139,7 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
139
140
const launcher = path.join(home, ".t3", "bin", "t3");
141
yield* fs.writeFileString(launcher, "npm's t3\n");
142
- process.env.PATH = path.dirname(launcher);
142
+ env.PATH = path.dirname(launcher);
143
expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher });
144
expect((yield* Effect.flip(command.install)).message).toContain("Could not set up");
145
yield* command.uninstall;
@@ -173,9 +173,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
173
const shadow = path.join(home, "shadow");
174
yield* fs.makeDirectory(shadow);
175
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
176
- process.env.PATH = [shadow, path.join(home, ".local", "bin")].join(":");
176
+ const env = { PATH: [shadow, path.join(home, ".local", "bin")].join(":") };
177
178
- const command = yield* commandIn({ home });
178
+ const command = yield* commandIn({ home, env });
179
const theirs = path.join(shadow, "t3");
180
expect((yield* command.state).shadowedBy).toBe(theirs);
181
const error = yield* Effect.flip(command.install);
@@ -209,9 +209,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
209
yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601);
210
yield* fs.makeDirectory(shadow);
211
yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 });
212
- process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":");
212
+ const env = { PATH: [folder, plain, shadow, path.join(home, ".local", "bin")].join(":") };
213
214
- const command = yield* commandIn({ home });
214
+ const command = yield* commandIn({ home, env });
215
expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3"));
216
217
const error = yield* Effect.flip(command.install);
@@ -231,9 +231,9 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
231
const path = yield* Path.Path;
232
const home = yield* fs.makeTempDirectoryScoped();
233
const launcher = path.join(home, ".t3", "bin", "t3");
234
- process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":");
234
+ const env = { PATH: [path.dirname(launcher), path.join(home, ".local", "bin")].join(":") };
235
236
- const command = yield* commandIn({ home });
236
+ const command = yield* commandIn({ home, env });
237
const installed = yield* command.install;
238
239
expect(yield* fs.exists(launcher)).toBe(true);
apps/desktop/src/app/DesktopCliCommand.ts
+9
-6
@@ -2,6 +2,7 @@
2
import * as NodeFSP from "node:fs/promises";
3
4
import type { DesktopCliCommandState } from "@t3tools/contracts";
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
import * as Context from "effect/Context";
7
import * as Effect from "effect/Effect";
8
import * as FileSystem from "effect/FileSystem";
@@ -61,11 +62,13 @@ export class DesktopCliCommand extends Context.Service<
62
}
63
>()("@t3tools/desktop/app/DesktopCliCommand") {}
64
64
-/** @public */
65
export const make = Effect.gen(function* () {
66
const environment = yield* DesktopEnvironment.DesktopEnvironment;
67
const fs = yield* FileSystem.FileSystem;
68
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
69
+ // Read the live env: shell discovery patches PATH after startup, and Windows variable
70
+ // names are case-insensitive only on process.env, not on Config's copy of it.
71
+ const env = yield* HostProcess.Environment;
72
const path = environment.path;
73
const windows = environment.platform === "win32";
74
const launcher = DesktopCliShim.launcherPath(environment);
@@ -105,15 +108,15 @@ export const make = Effect.gen(function* () {
108
Effect.orElseSucceed(() => false),
109
);
110
108
- const powershell = (env: Record<string, string>) =>
111
+ const powershell = (overrides: Record<string, string>) =>
112
Effect.scoped(
113
Effect.gen(function* () {
111
- const root = process.env.SystemRoot ?? process.env.WINDIR;
114
+ const root = env.SystemRoot ?? env.WINDIR;
115
const handle = yield* spawner.spawn(
116
ChildProcess.make(
117
root ? `${root}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe` : "powershell.exe",
118
["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", WINDOWS_USER_PATH_SCRIPT],
116
- { stdin: "ignore", stderr: "ignore", env, extendEnv: true },
119
+ { stdin: "ignore", stderr: "ignore", env: overrides, extendEnv: true },
120
),
121
);
122
const [stdout, exitCode] = yield* Effect.all(
@@ -144,7 +147,7 @@ export const make = Effect.gen(function* () {
147
);
148
149
const firstOnPath = Effect.gen(function* () {
147
- for (const directory of pathEntries(process.env.PATH, ":")) {
150
+ for (const directory of pathEntries(env.PATH, ":")) {
151
const candidate = path.join(directory, "t3");
152
if (yield* isExecutableFile(candidate)) return Option.some(candidate);
153
}
@@ -239,7 +242,7 @@ export const make = Effect.gen(function* () {
242
`Another t3 at ${shadowedBy.value} runs first in a new terminal. Remove it, or run the launcher directly at ${launcher}.`,
243
);
244
}
242
- const onPath = pathEntries(process.env.PATH, ":");
245
+ const onPath = pathEntries(env.PATH, ":");
246
const candidates = unixCandidates(environment.homeDirectory, environment.platform);
247
for (const directory of [
248
...candidates.filter((candidate) => onPath.includes(candidate)),
apps/desktop/src/app/DesktopConfig.ts
+1
-1
@@ -8,7 +8,7 @@ const trimNonEmptyOption = (value: string): Option.Option<string> => {
8
return trimmed.length > 0 ? Option.some(trimmed) : Option.none();
9
};
10
11
-const trimmedString = (name: string) =>
11
+export const trimmedString = (name: string) =>
12
Config.String(name).pipe(Config.option, Config.map(Option.flatMap(trimNonEmptyOption)));
13
14
const optionalBoolean = (name: string) =>
apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+14
-5
@@ -57,6 +57,7 @@ vi.mock("node:child_process", () => ({
57
execFileSync: execFileSyncMock,
58
}));
59
60
+import * as DesktopConfig from "./DesktopConfig.ts";
61
import * as DesktopPreReadyPlatform from "./DesktopPreReadyPlatform.ts";
62
63
describe("DesktopPreReadyPlatform", () => {
@@ -124,8 +125,6 @@ describe("DesktopPreReadyPlatform", () => {
125
{ previousEntry: 'Exec="/Applications/deleted-previous.AppImage" %U', label: "stale" },
126
])("prepares a $label Linux desktop entry before startup yields", ({ previousEntry }) => {
127
vi.stubEnv("VITE_DEV_SERVER_URL", "");
127
- vi.stubEnv("XDG_DATA_HOME", "/xdg");
128
- vi.stubEnv("APPIMAGE", "/Applications/current.AppImage");
128
getSwitchValueMock.mockReturnValue("");
129
let desktopName = "t3code.desktop";
130
let desktopEntry = previousEntry;
@@ -150,6 +149,12 @@ describe("DesktopPreReadyPlatform", () => {
149
yield* Layer.build(
150
DesktopPreReadyPlatform.layer.pipe(
151
Layer.provide(Layer.succeed(HostProcess.Platform, "linux")),
152
+ Layer.provide(
153
+ DesktopConfig.layerTest({
154
+ XDG_DATA_HOME: "/xdg",
155
+ APPIMAGE: "/Applications/current.AppImage",
156
+ }),
157
+ ),
158
),
159
);
160
const identity = yield* Effect.promise(() => portalIdentity);
@@ -168,9 +173,6 @@ describe("DesktopPreReadyPlatform", () => {
173
174
it.effect("points the early portal entry at a configured distribution launcher", () => {
175
vi.stubEnv("VITE_DEV_SERVER_URL", "");
171
- vi.stubEnv("XDG_DATA_HOME", "/xdg");
172
- vi.stubEnv("APPIMAGE", "/Applications/current.AppImage");
173
- vi.stubEnv("T3CODE_DESKTOP_LAUNCHER_PATH", " /opt/T3 Code/t3code ");
176
getSwitchValueMock.mockReturnValue("");
177
178
return Effect.scoped(
@@ -178,6 +180,13 @@ describe("DesktopPreReadyPlatform", () => {
180
yield* Layer.build(
181
DesktopPreReadyPlatform.layer.pipe(
182
Layer.provide(Layer.succeed(HostProcess.Platform, "linux")),
183
+ Layer.provide(
184
+ DesktopConfig.layerTest({
185
+ XDG_DATA_HOME: "/xdg",
186
+ APPIMAGE: "/Applications/current.AppImage",
187
+ T3CODE_DESKTOP_LAUNCHER_PATH: " /opt/T3 Code/t3code ",
188
+ }),
189
+ ),
190
),
191
);
192
const entry = writeFileSyncMock.mock.calls.find(
apps/desktop/src/app/DesktopPreReadyPlatform.ts
+18
-4
@@ -2,14 +2,17 @@
2
import * as NodeChildProcess from "node:child_process";
3
import * as NodeFS from "node:fs";
4
import * as NodePath from "node:path";
5
+import * as Config from "effect/Config";
6
import * as Context from "effect/Context";
7
import * as Effect from "effect/Effect";
8
import * as Layer from "effect/Layer";
9
+import * as Option from "effect/Option";
10
11
import * as Electron from "electron";
12
import * as HostProcess from "@t3tools/shared/HostProcess";
13
14
import * as DesktopEarlyElectronStartup from "./DesktopEarlyElectronStartup.ts";
15
+import { trimmedString } from "./DesktopConfig.ts";
16
import { resolveDesktopAppBranding } from "./DesktopEnvironment.ts";
17
import { renderUrlHandlerDesktopEntry } from "./DesktopLinuxUrlHandler.ts";
18
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
@@ -49,10 +52,17 @@ export class DesktopPreReadyElectronOptions extends Context.Service<
52
}
53
>()("@t3tools/desktop/app/DesktopPreReadyPlatform/DesktopPreReadyElectronOptions") {}
54
55
+const LinuxDesktopEntryConfig = Config.all({
56
+ xdgDataHome: trimmedString("XDG_DATA_HOME"),
57
+ launcherPath: trimmedString("T3CODE_DESKTOP_LAUNCHER_PATH"),
58
+ appImagePath: trimmedString("APPIMAGE"),
59
+});
60
+
61
/** @public */
62
export const make = Effect.gen(function* () {
63
const platform = yield* HostProcess.Platform;
64
const homeDirectory = yield* HostProcess.HomeDirectory;
65
+ const linuxDesktopEntryConfig = yield* LinuxDesktopEntryConfig;
66
return yield* Effect.sync((): DesktopPreReadyElectronOptions["Service"] => {
67
const linuxPasswordStoreCommandLine =
68
platform === "linux"
@@ -77,8 +87,9 @@ export const make = Effect.gen(function* () {
87
// have removed the executable referenced by the previous launch's entry.
88
try {
89
const applicationsDir = NodePath.posix.join(
80
- process.env.XDG_DATA_HOME?.trim() ||
90
+ Option.getOrElse(linuxDesktopEntryConfig.xdgDataHome, () =>
91
NodePath.posix.join(homeDirectory, ".local", "share"),
92
+ ),
93
"applications",
94
);
95
NodeFS.mkdirSync(applicationsDir, { recursive: true });
@@ -110,9 +121,12 @@ export const make = Effect.gen(function* () {
121
appVersion: Electron.app.getVersion(),
122
}).displayName,
123
execTarget:
113
- process.env.T3CODE_DESKTOP_LAUNCHER_PATH?.trim() ||
114
- process.env.APPIMAGE?.trim() ||
115
- process.execPath,
124
+ Option.getOrUndefined(
125
+ Option.orElse(
126
+ linuxDesktopEntryConfig.launcherPath,
127
+ () => linuxDesktopEntryConfig.appImagePath,
128
+ ),
129
+ ) ?? process.execPath,
130
scheme: ElectronProtocol.getDesktopScheme(linux.isDevelopment),
131
...(iconPath === undefined ? {} : { iconPath }),
132
}),
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+71
-104
@@ -2,6 +2,7 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
import { assert, describe, it } from "@effect/vitest";
4
import { currentDesktopBootstrapToken } from "@t3tools/shared/desktopBootstrapToken";
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
import * as Clock from "effect/Clock";
7
import * as Effect from "effect/Effect";
8
import * as FileSystem from "effect/FileSystem";
@@ -93,14 +94,6 @@ function layerEnvironment(
94
);
95
}
96
96
-const restoreEnv = (name: string, value: string | undefined) => {
97
- if (value === undefined) {
98
- delete process.env[name];
99
- } else {
100
- process.env[name] = value;
101
- }
102
-};
103
-
97
const withHarness = <A, E, R>(
98
effect: Effect.Effect<
99
A,
@@ -692,49 +685,38 @@ describe("DesktopBackendConfiguration", () => {
685
prefix: "t3-desktop-backend-config-test-",
686
});
687
695
- const previousWslEnv = process.env.WSLENV;
696
- const previousDisabled = process.env.OTEL_SDK_DISABLED;
697
- const previousTelemetry = process.env.T3CODE_TELEMETRY_ENABLED;
698
- const previousResourceAttributes = process.env.OTEL_RESOURCE_ATTRIBUTES;
699
- try {
700
- delete process.env.WSLENV;
701
- process.env.OTEL_SDK_DISABLED = "true";
702
- process.env.T3CODE_TELEMETRY_ENABLED = "false";
703
- process.env.OTEL_RESOURCE_ATTRIBUTES = "deployment.environment.name=staging";
704
-
705
- yield* Effect.gen(function* () {
706
- const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
707
- const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
708
-
709
- assert.equal(config.env.OTEL_SDK_DISABLED, "true");
710
- assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
711
- assert.equal(config.env.T3CODE_TELEMETRY_ENABLED, "false");
712
- assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
713
- assert.equal(config.env.OTEL_RESOURCE_ATTRIBUTES, "deployment.environment.name=staging");
714
- assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_RESOURCE_ATTRIBUTES");
715
- }).pipe(
716
- Effect.provide(
717
- layerBackendConfiguration().pipe(
718
- Layer.provideMerge(layerServerExposure),
719
- Layer.provideMerge(DesktopAppSettings.layerTest()),
720
- Layer.provideMerge(DesktopWslServerTree.layerTest()),
721
- Layer.provideMerge(
722
- DesktopWslEnvironment.layerTest({
723
- isAvailable: true,
724
- windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"),
725
- getDistroIp: () => Option.some("172.27.0.99"),
726
- }),
727
- ),
728
- Layer.provideMerge(layerEnvironment(baseDir, { platform: "win32" })),
688
+ yield* Effect.gen(function* () {
689
+ const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
690
+ const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
691
+
692
+ assert.equal(config.env.OTEL_SDK_DISABLED, "true");
693
+ assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
694
+ assert.equal(config.env.T3CODE_TELEMETRY_ENABLED, "false");
695
+ assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
696
+ assert.equal(config.env.OTEL_RESOURCE_ATTRIBUTES, "deployment.environment.name=staging");
697
+ assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_RESOURCE_ATTRIBUTES");
698
+ }).pipe(
699
+ Effect.provide(
700
+ layerBackendConfiguration().pipe(
701
+ Layer.provideMerge(layerServerExposure),
702
+ Layer.provideMerge(DesktopAppSettings.layerTest()),
703
+ Layer.provideMerge(DesktopWslServerTree.layerTest()),
704
+ Layer.provideMerge(
705
+ DesktopWslEnvironment.layerTest({
706
+ isAvailable: true,
707
+ windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"),
708
+ getDistroIp: () => Option.some("172.27.0.99"),
709
+ }),
710
),
711
+ Layer.provideMerge(layerEnvironment(baseDir, { platform: "win32" })),
712
),
731
- );
732
- } finally {
733
- restoreEnv("WSLENV", previousWslEnv);
734
- restoreEnv("OTEL_SDK_DISABLED", previousDisabled);
735
- restoreEnv("T3CODE_TELEMETRY_ENABLED", previousTelemetry);
736
- restoreEnv("OTEL_RESOURCE_ATTRIBUTES", previousResourceAttributes);
737
- }
713
+ ),
714
+ Effect.provideService(HostProcess.Environment, {
715
+ OTEL_SDK_DISABLED: "true",
716
+ T3CODE_TELEMETRY_ENABLED: "false",
717
+ OTEL_RESOURCE_ATTRIBUTES: "deployment.environment.name=staging",
718
+ }),
719
+ );
720
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
721
);
722
@@ -745,63 +727,48 @@ describe("DesktopBackendConfiguration", () => {
727
prefix: "t3-desktop-backend-config-test-",
728
});
729
748
- const previousWslEnv = process.env.WSLENV;
749
- const previousOpenAiKey = process.env.OPENAI_API_KEY;
750
- const previousAnthropicKey = process.env.ANTHROPIC_API_KEY;
751
- const previousOtlpHeaders = process.env.T3CODE_OTLP_HEADERS;
752
- const previousOtlpProtocol = process.env.T3CODE_OTLP_PROTOCOL;
753
- const ambientOtel = Object.entries(process.env).filter(([name]) => name.startsWith("OTEL_"));
754
- try {
755
- for (const [name] of ambientOtel) delete process.env[name];
756
- process.env.WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u";
757
- process.env.OPENAI_API_KEY = "openai-key";
758
- process.env.ANTHROPIC_API_KEY = "anthropic-key";
759
- process.env.T3CODE_OTLP_HEADERS = 'authorization="Bearer%20my-token"';
760
- process.env.T3CODE_OTLP_PROTOCOL = "http/protobuf";
761
-
762
- yield* Effect.gen(function* () {
763
- const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
764
- const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
765
-
766
- assert.equal(config.executablePath, "wsl.exe");
767
- assert.equal(config.bootstrap.port, 5050);
768
- assert.equal(config.bootstrap.host, "0.0.0.0");
769
- assert.equal(config.bootstrap.tailscaleServeEnabled, false);
770
- assert.notProperty(config.bootstrap, "desktopTelemetryFd");
771
- assert.notProperty(config.bootstrap, "resourceMonitorPath");
772
- assert.equal(config.httpBaseUrl.href, "http://172.27.0.99:5050/");
773
- assert.equal(config.env.OPENAI_API_KEY, "openai-key");
774
- assert.equal(config.env.ANTHROPIC_API_KEY, "anthropic-key");
775
- assert.equal(config.env.T3CODE_OTLP_PROTOCOL, "http/protobuf");
776
- assert.equal(
777
- config.env.WSLENV,
778
- "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY:T3CODE_OTLP_HEADERS:T3CODE_OTLP_PROTOCOL",
779
- );
780
- }).pipe(
781
- Effect.provide(
782
- layerBackendConfiguration().pipe(
783
- Layer.provideMerge(layerServerExposure),
784
- Layer.provideMerge(DesktopAppSettings.layerTest()),
785
- Layer.provideMerge(DesktopWslServerTree.layerTest()),
786
- Layer.provideMerge(
787
- DesktopWslEnvironment.layerTest({
788
- isAvailable: true,
789
- windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"),
790
- getDistroIp: () => Option.some("172.27.0.99"),
791
- }),
792
- ),
793
- Layer.provideMerge(layerEnvironment(baseDir, { platform: "win32" })),
730
+ yield* Effect.gen(function* () {
731
+ const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
732
+ const config = yield* configuration.resolveWsl({ port: 5050, distro: null });
733
+
734
+ assert.equal(config.executablePath, "wsl.exe");
735
+ assert.equal(config.bootstrap.port, 5050);
736
+ assert.equal(config.bootstrap.host, "0.0.0.0");
737
+ assert.equal(config.bootstrap.tailscaleServeEnabled, false);
738
+ assert.notProperty(config.bootstrap, "desktopTelemetryFd");
739
+ assert.notProperty(config.bootstrap, "resourceMonitorPath");
740
+ assert.equal(config.httpBaseUrl.href, "http://172.27.0.99:5050/");
741
+ assert.equal(config.env.OPENAI_API_KEY, "openai-key");
742
+ assert.equal(config.env.ANTHROPIC_API_KEY, "anthropic-key");
743
+ assert.equal(config.env.T3CODE_OTLP_PROTOCOL, "http/protobuf");
744
+ assert.equal(
745
+ config.env.WSLENV,
746
+ "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u:ANTHROPIC_API_KEY:T3CODE_OTLP_HEADERS:T3CODE_OTLP_PROTOCOL",
747
+ );
748
+ }).pipe(
749
+ Effect.provide(
750
+ layerBackendConfiguration().pipe(
751
+ Layer.provideMerge(layerServerExposure),
752
+ Layer.provideMerge(DesktopAppSettings.layerTest()),
753
+ Layer.provideMerge(DesktopWslServerTree.layerTest()),
754
+ Layer.provideMerge(
755
+ DesktopWslEnvironment.layerTest({
756
+ isAvailable: true,
757
+ windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"),
758
+ getDistroIp: () => Option.some("172.27.0.99"),
759
+ }),
760
),
761
+ Layer.provideMerge(layerEnvironment(baseDir, { platform: "win32" })),
762
),
796
- );
797
- } finally {
798
- restoreEnv("WSLENV", previousWslEnv);
799
- restoreEnv("OPENAI_API_KEY", previousOpenAiKey);
800
- restoreEnv("ANTHROPIC_API_KEY", previousAnthropicKey);
801
- restoreEnv("T3CODE_OTLP_HEADERS", previousOtlpHeaders);
802
- restoreEnv("T3CODE_OTLP_PROTOCOL", previousOtlpProtocol);
803
- for (const [name, value] of ambientOtel) restoreEnv(name, value);
804
- }
763
+ ),
764
+ Effect.provideService(HostProcess.Environment, {
765
+ WSLENV: "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u",
766
+ OPENAI_API_KEY: "openai-key",
767
+ ANTHROPIC_API_KEY: "anthropic-key",
768
+ T3CODE_OTLP_HEADERS: 'authorization="Bearer%20my-token"',
769
+ T3CODE_OTLP_PROTOCOL: "http/protobuf",
770
+ }),
771
+ );
772
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
773
);
774
apps/desktop/src/backend/DesktopBackendConfiguration.ts
+5
-3
@@ -2,6 +2,7 @@ import * as NodeOS from "node:os";
2
3
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
4
import { currentDesktopBootstrapToken } from "@t3tools/shared/desktopBootstrapToken";
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
import * as Clock from "effect/Clock";
7
import * as Context from "effect/Context";
8
import * as SecureRandom from "effect/crypto/SecureRandom";
@@ -562,6 +563,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
563
const environment = yield* DesktopEnvironment.DesktopEnvironment;
564
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
565
const fileSystem = yield* FileSystem.FileSystem;
566
+ const env = yield* HostProcess.Environment;
567
568
// wslhost loopback forwarding is unreliable on some Windows hosts; advertise the WSL IP instead.
569
const wslBindHost = "0.0.0.0";
@@ -633,7 +635,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
635
const forwardedEnv: Record<string, string> = {};
636
const forwardedEnvNames: string[] = [];
637
for (const name of WSL_FORWARDED_ENV_NAMES) {
636
- const value = process.env[name];
638
+ const value = env[name];
639
if (value !== undefined && value.length > 0) {
640
forwardedEnv[name] = value;
641
forwardedEnvNames.push(name);
@@ -641,7 +643,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
643
}
644
645
const parentEnvWithoutT3Home: Record<string, string | undefined> = {};
644
- for (const [key, value] of Object.entries(process.env)) {
646
+ for (const [key, value] of Object.entries(env)) {
647
if (key === "T3CODE_HOME") continue;
648
parentEnvWithoutT3Home[key] = value;
649
}
@@ -658,7 +660,7 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl
660
...forwardedEnv,
661
...(wslEnv !== undefined ? { WSLENV: wslEnv } : {}),
662
},
661
- // env already excludes T3CODE_HOME; merging process.env would restore it.
663
+ // env already excludes T3CODE_HOME; merging the host env would restore it.
664
extendEnv: false,
665
bootstrap,
666
bootstrapDelivery: "stdin" as const,
apps/desktop/src/snapShot/DesktopSnapShot.ts
+4
-1
@@ -768,6 +768,8 @@ export const make = Effect.gen(function* () {
768
const captureDirectory = path.join(environment.stateDir, "snap-shots");
769
const linuxAppId = environment.linuxDesktopEntryName.replace(/\.desktop$/, "");
770
const home = yield* HostProcess.HomeDirectory;
771
+ // Shell discovery can replace XDG_CURRENT_DESKTOP after startup, so read the live env per state.
772
+ const hostEnv = yield* HostProcess.Environment;
773
let shortcutVerified = false;
774
const gnomeSetupPaths = {
775
bundle: environment.isPackaged
@@ -1621,7 +1623,8 @@ export const make = Effect.gen(function* () {
1623
Effect.gen(function* () {
1624
const linuxDesktop =
1625
state.mode === "portal"
1624
- ? process.env.XDG_CURRENT_DESKTOP?.toLowerCase()
1626
+ ? (hostEnv.XDG_CURRENT_DESKTOP ?? "")
1627
+ .toLowerCase()
1628
.split(":")
1629
.find(
1630
(name) =>
apps/desktop/src/wsl/DesktopWslEnvironment.ts
+3
-1
@@ -9,6 +9,7 @@ import * as Schema from "effect/Schema";
9
import * as Stream from "effect/Stream";
10
import { ChildProcess, ChildProcessSpawner } from "effect/process";
11
12
+import * as HostProcess from "@t3tools/shared/HostProcess";
13
import { buildRemoteNodeEnvScript } from "@t3tools/ssh/tunnel";
14
import { satisfiesSemverRange } from "@t3tools/shared/semver";
15
@@ -1141,7 +1142,8 @@ export const layer = Layer.effect(
1142
const environment = yield* DesktopEnvironment.DesktopEnvironment;
1143
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1144
const fileSystem = yield* FileSystem.FileSystem;
1144
- const windir = process.env.WINDIR ?? "C:\\Windows";
1145
+ // Not Config: Windows variable names are case-insensitive only on the live process.env.
1146
+ const windir = (yield* HostProcess.Environment).WINDIR ?? "C:\\Windows";
1147
1148
const provideSpawner = <A, E>(
1149
effect: Effect.Effect<A, E, ChildProcessSpawner.ChildProcessSpawner>,
apps/server/integration/transferBudgetV2.integration.test.ts
+7
-2
@@ -27,6 +27,7 @@ import {
27
type OrchestrationV2ShellStreamItem,
28
} from "@t3tools/contracts";
29
import * as Context from "effect/Context";
30
+import * as Config from "effect/Config";
31
import * as Effect from "effect/Effect";
32
import * as FileSystem from "effect/FileSystem";
33
import * as Layer from "effect/Layer";
@@ -453,9 +454,13 @@ it.live("reports V2 thread HTTP and WebSocket transfer budgets", () =>
454
}
455
const fs = yield* FileSystem.FileSystem;
456
const report = formatTransferBudgetReport(runs);
457
+ const outputPaths = yield* Config.all({
458
+ report: Config.String("T3CODE_TRANSFER_BUDGET_REPORT_PATH").pipe(Config.withDefault("")),
459
+ result: Config.String("T3CODE_TRANSFER_BUDGET_RESULT_PATH").pipe(Config.withDefault("")),
460
+ });
461
for (const [path, contents] of [
457
- [process.env.T3CODE_TRANSFER_BUDGET_REPORT_PATH, report],
458
- [process.env.T3CODE_TRANSFER_BUDGET_RESULT_PATH, formatTransferBudgetResult(runs)],
462
+ [outputPaths.report, report],
463
+ [outputPaths.result, formatTransferBudgetResult(runs)],
464
])
465
if (path && contents) yield* fs.writeFileString(path, contents);
466
yield* Effect.log(report);
apps/server/scripts/acp-mock-agent.ts
+5
-3
@@ -43,6 +43,9 @@ const omitInitializeModelState = process.env.T3_ACP_OMIT_INITIALIZE_MODEL_STATE
43
const completeFirstPromptOnCancel = process.env.T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL === "1";
44
const floodStderr = process.env.T3_ACP_FLOOD_STDERR === "1";
45
const hangPromptForever = process.env.T3_ACP_HANG_PROMPT_FOREVER === "1";
46
+const agentVersion = process.env.T3_ACP_AGENT_VERSION ?? "0.0.0";
47
+const geminiApiKey = process.env.GEMINI_API_KEY;
48
+const idleError = process.env.T3_ACP_IDLE_ERROR;
49
const emitTrackedToolCallKindThenHang = process.env.T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG;
50
const clientFsProbePath = process.env.T3_ACP_CLIENT_FS_PROBE_PATH;
51
const clientFsProbeLogPath = process.env.T3_ACP_CLIENT_FS_PROBE_LOG_PATH;
@@ -512,7 +515,7 @@ const program = Effect.gen(function* () {
515
parameterizedModelPicker = request.capabilities?._meta?.parameterizedModelPicker === true;
516
return {
517
protocolVersion: 2,
515
- info: { name: "t3-acp-mock-agent", version: process.env.T3_ACP_AGENT_VERSION ?? "0.0.0" },
518
+ info: { name: "t3-acp-mock-agent", version: agentVersion },
519
...(omitInitializeModelState ? {} : { _meta: { modelState: modelState() } }),
520
capabilities: {
521
session: {
@@ -550,7 +553,7 @@ const program = Effect.gen(function* () {
553
if (antigravityProfile) {
554
if (
555
request.methodId !== "oauth-personal" &&
553
- !(request.methodId === "gemini-api-key" && process.env.GEMINI_API_KEY)
556
+ !(request.methodId === "gemini-api-key" && geminiApiKey)
557
) {
558
return yield* AcpError.AcpRequestError.invalidParams(
559
`Mock Antigravity rejected auth method ${request.methodId}.`,
@@ -811,7 +814,6 @@ const program = Effect.gen(function* () {
814
const requestedSessionId = String(request.sessionId ?? sessionId);
815
beginAcpMockPrompt(cancelledSessions, requestedSessionId);
816
promptCount += 1;
814
- const idleError = process.env.T3_ACP_IDLE_ERROR;
817
if (idleError === "grok-background" && promptCount === 1) {
818
// The structured completion lands before the prompt settles, so it is buffered.
819
const taskId = "call-idle-error-background";
apps/server/scripts/record-codex-app-server-replay-fixture.ts
+16
-2
@@ -13,6 +13,8 @@ import * as FileSystem from "effect/FileSystem";
13
import * as Layer from "effect/Layer";
14
import * as Path from "effect/Path";
15
import * as PlatformError from "effect/PlatformError";
16
+import * as Config from "effect/Config";
17
+import * as Option from "effect/Option";
18
import * as Effect from "effect/Effect";
19
import { ChildProcess, ChildProcessSpawner } from "effect/process";
20
@@ -1486,12 +1488,24 @@ const runScenario = Effect.fn("record-codex-app-server-replay-fixture.runScenari
1488
yield* recorder.flush();
1489
});
1490
1491
+const RecorderEnv = Config.all({
1492
+ T3_CODEX_REPLAY_OUT_DIR: Config.String("T3_CODEX_REPLAY_OUT_DIR").pipe(
1493
+ Config.option,
1494
+ Config.map(Option.getOrUndefined),
1495
+ ),
1496
+ T3_CODEX_REPLAY_OUT: Config.String("T3_CODEX_REPLAY_OUT").pipe(
1497
+ Config.option,
1498
+ Config.map(Option.getOrUndefined),
1499
+ ),
1500
+});
1501
+
1502
const program = Effect.gen(function* () {
1503
+ const recorderEnv = yield* RecorderEnv;
1504
const path = yield* Path.Path;
1505
const requestedScenarios = parseScenarios();
1506
const allScenarios = scenarios();
1493
- const outDir = readArgValue("--out-dir") ?? process.env.T3_CODEX_REPLAY_OUT_DIR;
1494
- const singleOutPath = readArgValue("--out") ?? process.env.T3_CODEX_REPLAY_OUT;
1507
+ const outDir = readArgValue("--out-dir") ?? recorderEnv.T3_CODEX_REPLAY_OUT_DIR;
1508
+ const singleOutPath = readArgValue("--out") ?? recorderEnv.T3_CODEX_REPLAY_OUT;
1509
const selected = allScenarios.filter((scenario) => requestedScenarios.includes(scenario.name));
1510
1511
if (selected.length === 0) {
apps/server/scripts/record-fx-acp-replay-fixture.ts
+20
-6
@@ -13,6 +13,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
13
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
14
import * as Clock from "effect/Clock";
15
import * as Console from "effect/Console";
16
+import * as Config from "effect/Config";
17
+import * as Option from "effect/Option";
18
import * as Effect from "effect/Effect";
19
import * as FileSystem from "effect/FileSystem";
20
import * as Layer from "effect/Layer";
@@ -322,7 +324,19 @@ function normalizeEntries(input: {
324
325
const DEFAULT_FX_SETTINGS = Schema.decodeSync(FxSettings)({});
326
327
+const RecorderEnv = Config.all({
328
+ T3_FX_BIN: Config.String("T3_FX_BIN").pipe(Config.option, Config.map(Option.getOrUndefined)),
329
+ HOME: Config.String("HOME").pipe(Config.option, Config.map(Option.getOrUndefined)),
330
+ USER: Config.String("USER").pipe(Config.option, Config.map(Option.getOrUndefined)),
331
+ AI_GATEWAY_API_KEY: Config.String("AI_GATEWAY_API_KEY").pipe(
332
+ Config.option,
333
+ Config.map(Option.getOrUndefined),
334
+ ),
335
+ TMPDIR: Config.String("TMPDIR").pipe(Config.option, Config.map(Option.getOrUndefined)),
336
+});
337
+
338
const recordScenario = Effect.fn("recordFxScenario")(function* (fixtureName: string) {
339
+ const recorderEnv = yield* RecorderEnv;
340
const fixture = ORCHESTRATOR_REPLAY_FIXTURES.find((candidate) => candidate.name === fixtureName);
341
const variant = fixture?.providers.find((provider) => provider.driver === FX_DRIVER_KIND);
342
if (fixture === undefined || variant === undefined) {
@@ -359,7 +373,7 @@ const recordScenario = Effect.fn("recordFxScenario")(function* (fixtureName: str
373
};
374
375
const tee = makeWireTee();
362
- const settings = { ...DEFAULT_FX_SETTINGS, binaryPath: process.env.T3_FX_BIN ?? "fx" };
376
+ const settings = { ...DEFAULT_FX_SETTINGS, binaryPath: recorderEnv.T3_FX_BIN ?? "fx" };
377
const layerRegistry = ProviderAdapterRegistry.layerFromAdaptersEffect(
378
Effect.gen(function* () {
379
const environment = yield* HostProcess.Environment;
@@ -455,7 +469,7 @@ const recordScenario = Effect.fn("recordFxScenario")(function* (fixtureName: str
469
isRecord(initialize.frame.result.agentInfo)
470
? initialize.frame.result.agentInfo
471
: {};
458
- const home = process.env.HOME ?? "";
472
+ const home = recorderEnv.HOME ?? "";
473
const transcript = {
474
provider: FX_DRIVER_KIND,
475
protocol: ACP_PROTOCOL,
@@ -473,11 +487,11 @@ const recordScenario = Effect.fn("recordFxScenario")(function* (fixtureName: str
487
entries,
488
workspace: realWorkspace,
489
home,
476
- user: process.env.USER ?? "",
490
+ user: recorderEnv.USER ?? "",
491
skillNames: yield* readUserSkillNames(home),
478
- ...(process.env.AI_GATEWAY_API_KEY === undefined
492
+ ...(recorderEnv.AI_GATEWAY_API_KEY === undefined
493
? {}
480
- : { gatewayApiKey: process.env.AI_GATEWAY_API_KEY }),
494
+ : { gatewayApiKey: recorderEnv.AI_GATEWAY_API_KEY }),
495
runtimeInstructions: buildRuntimeInstructions({
496
harness: "fx",
497
model: variant.modelSelection.model,
@@ -494,7 +508,7 @@ const recordScenario = Effect.fn("recordFxScenario")(function* (fixtureName: str
508
);
509
if (liveFailure._tag === "Some") {
510
const dumpPath = path.join(
497
- process.env.TMPDIR ?? "/tmp",
511
+ recorderEnv.TMPDIR ?? "/tmp",
512
`fx-replay-${fixtureName}-failed.json`,
513
);
514
yield* fs.writeFileString(dumpPath, encodeJson(transcript));
apps/server/scripts/record-grok-acp-replay-fixture.ts
+12
-3
@@ -6,6 +6,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
6
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
7
import * as Clock from "effect/Clock";
8
import * as Console from "effect/Console";
9
+import * as Config from "effect/Config";
10
+import * as Option from "effect/Option";
11
import * as Effect from "effect/Effect";
12
import * as FileSystem from "effect/FileSystem";
13
import * as Layer from "effect/Layer";
@@ -370,7 +372,14 @@ function normalizeEntries(input: {
372
373
const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
374
375
+const RecorderEnv = Config.all({
376
+ T3_GROK_BIN: Config.String("T3_GROK_BIN").pipe(Config.option, Config.map(Option.getOrUndefined)),
377
+ HOME: Config.String("HOME").pipe(Config.option, Config.map(Option.getOrUndefined)),
378
+ USER: Config.String("USER").pipe(Config.option, Config.map(Option.getOrUndefined)),
379
+});
380
+
381
const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: string) {
382
+ const recorderEnv = yield* RecorderEnv;
383
const fixture = ORCHESTRATOR_REPLAY_FIXTURES.find((candidate) => candidate.name === fixtureName);
384
const variant = fixture?.providers.find((provider) => provider.driver === GROK_PROVIDER);
385
if (fixture === undefined || variant === undefined) {
@@ -404,7 +413,7 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s
413
};
414
415
const tee = makeWireTee();
407
- const settings = { ...DEFAULT_GROK_SETTINGS, binaryPath: process.env.T3_GROK_BIN ?? "grok" };
416
+ const settings = { ...DEFAULT_GROK_SETTINGS, binaryPath: recorderEnv.T3_GROK_BIN ?? "grok" };
417
const layerRegistry = ProviderAdapterRegistry.layerFromAdaptersEffect(
418
Effect.gen(function* () {
419
const environment = yield* HostProcess.Environment;
@@ -522,8 +531,8 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s
531
...normalizeEntries({
532
entries,
533
workspace: realWorkspace,
525
- home: process.env.HOME ?? "",
526
- user: process.env.USER ?? "",
534
+ home: recorderEnv.HOME ?? "",
535
+ user: recorderEnv.USER ?? "",
536
runtimeInstructions: buildRuntimeInstructions({
537
harness: "Grok",
538
model: variant.modelSelection.model,
apps/server/scripts/record-kiro-acp-replay-fixture.ts
+15
-3
@@ -12,6 +12,8 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
12
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
13
import * as Clock from "effect/Clock";
14
import * as Console from "effect/Console";
15
+import * as Config from "effect/Config";
16
+import * as Option from "effect/Option";
17
import * as Effect from "effect/Effect";
18
import * as FileSystem from "effect/FileSystem";
19
import * as Layer from "effect/Layer";
@@ -407,7 +409,17 @@ const KIRO_RECORDING_SETTINGS = Schema.decodeSync(KiroSettings)({
409
binaryPath: process.env.T3_KIRO_BIN ?? "kiro-cli",
410
});
411
412
+const RecorderEnv = Config.all({
413
+ T3_KIRO_VERSION: Config.String("T3_KIRO_VERSION").pipe(
414
+ Config.option,
415
+ Config.map(Option.getOrUndefined),
416
+ ),
417
+ HOME: Config.String("HOME").pipe(Config.option, Config.map(Option.getOrUndefined)),
418
+ USER: Config.String("USER").pipe(Config.option, Config.map(Option.getOrUndefined)),
419
+});
420
+
421
const recordScenario = Effect.fn("recordKiroScenario")(function* (fixtureName: string) {
422
+ const recorderEnv = yield* RecorderEnv;
423
const fixture = ORCHESTRATOR_REPLAY_FIXTURES.find((candidate) => candidate.name === fixtureName);
424
const variant = fixture?.providers.find((provider) => provider.driver === KIRO_PROVIDER);
425
if (fixture === undefined || variant === undefined) {
@@ -544,7 +556,7 @@ const recordScenario = Effect.fn("recordKiroScenario")(function* (fixtureName: s
556
scenario: fixtureName,
557
metadata: {
558
generatedBy: "live-kiro-recorder",
547
- kiroVersion: process.env.T3_KIRO_VERSION ?? "unknown",
559
+ kiroVersion: recorderEnv.T3_KIRO_VERSION ?? "unknown",
560
normalization:
561
"Session ids are fixed sess_ UUIDs and other UUIDs (message and request ids) are numbered in first-seen order, the workspace is <workspace>, HOME is /home/kiro-replay and the recording user is kiro-replay. T3-owned prompt text, MCP servers and initialize params other than clientCapabilities and _meta are <any>. Kiro's log directory, user-scoped commands and agents, and the _kiro/* broadcasts T3 ignores (governance, steering documents, powers, tools, hooks, MCP status, session roster, memory sync) are removed. Timestamps are kept as recorded.",
562
droppedFrames,
@@ -553,8 +565,8 @@ const recordScenario = Effect.fn("recordKiroScenario")(function* (fixtureName: s
565
...normalizeEntries({
566
entries,
567
workspace: realWorkspace,
556
- home: process.env.HOME ?? "",
557
- user: process.env.USER ?? "",
568
+ home: recorderEnv.HOME ?? "",
569
+ user: recorderEnv.USER ?? "",
570
runtimeInstructions: buildRuntimeInstructions({
571
harness: "Kiro",
572
model: variant.modelSelection.model,
apps/server/src/cli/app.test.ts
+12
-9
@@ -41,6 +41,16 @@ const liveProcess = Effect.acquireRelease(
41
42
const encodeRuntimeState = Schema.encodeEffect(Schema.fromJsonString(PersistedServerRuntimeState));
43
44
+// Node reads this variable itself, so the test must set the real process environment.
45
+const setProcessEnv = (name: string, value: string) => {
46
+ const previous = process.env[name];
47
+ process.env[name] = value;
48
+ return () => {
49
+ if (previous === undefined) delete process.env[name];
50
+ else process.env[name] = previous;
51
+ };
52
+};
53
+
54
const runCli = (args: ReadonlyArray<string>, env: Record<string, string> = {}) =>
55
Command.runWith(makeCli(), { version: "0.0.0" })(args).pipe(
56
Effect.provide(
@@ -229,16 +239,9 @@ describe("t3 app", () => {
239
"t3-app-unsafe-",
240
(root) =>
241
Effect.gen(function* () {
232
- const previousTmpdir = process.env.TMPDIR;
242
yield* Effect.acquireRelease(
234
- Effect.sync(() => {
235
- process.env.TMPDIR = root;
236
- }),
237
- () =>
238
- Effect.sync(() => {
239
- if (previousTmpdir === undefined) delete process.env.TMPDIR;
240
- else process.env.TMPDIR = previousTmpdir;
241
- }),
243
+ Effect.sync(() => setProcessEnv("TMPDIR", root)),
244
+ (restore) => Effect.sync(restore),
245
);
246
const baseDir = NodePath.join(root, ".t3");
247
const userId = yield* HostProcess.UserId;
apps/server/src/cli/uninstall.test.ts
+5
-1
@@ -1,5 +1,6 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
import { assert, it } from "@effect/vitest";
3
+import * as Config from "effect/Config";
4
import * as Effect from "effect/Effect";
5
import * as FileSystem from "effect/FileSystem";
6
import * as Path from "effect/Path";
@@ -47,7 +48,10 @@ it.live.runIf(HostProcess.Platform.defaultValue() === "win32")(
48
yield* fs.makeDirectory(path.join(runtimeDir, "versions", "1.0.0"), { recursive: true });
49
yield* fs.writeFileString(path.join(runtimeDir, "versions", "1.0.0", "t3.exe"), "");
50
50
- const child = spawnWindowsRemoval(process.env.ComSpec ?? "cmd.exe", runtimeDir);
51
+ const child = spawnWindowsRemoval(
52
+ yield* Config.String("ComSpec").pipe(Config.withDefault("cmd.exe")),
53
+ runtimeDir,
54
+ );
55
yield* Effect.callback<void, Error>((resume) => {
56
child.once("error", (error) => resume(Effect.fail(error)));
57
child.once("exit", (code) =>
apps/server/src/cloud/ManagedEndpointRuntime.test.ts
+20
-18
@@ -1,6 +1,8 @@
1
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
import { describe, expect, it } from "@effect/vitest";
4
+import * as HostProcess from "@t3tools/shared/HostProcess";
5
+import * as ConfigProvider from "effect/ConfigProvider";
6
import * as Context from "effect/Context";
7
import * as Deferred from "effect/Deferred";
8
import * as Duration from "effect/Duration";
@@ -80,6 +82,7 @@ const buildCloudManagedEndpointRuntime = (
82
relayClientLayer = layerRelayClientAvailable,
83
httpClient = unusedHttpClient,
84
secretStoreLayer = emptySecretStoreLayer,
85
+ env: Record<string, string> = {},
86
) =>
87
Effect.gen(function* () {
88
const context = yield* Layer.build(
@@ -90,7 +93,10 @@ const buildCloudManagedEndpointRuntime = (
93
return yield* Effect.service(ManagedEndpointRuntime.CloudManagedEndpointRuntime).pipe(
94
Effect.provide(context),
95
);
93
- });
96
+ }).pipe(
97
+ Effect.provideService(HostProcess.Environment, env),
98
+ Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))),
99
+ );
100
101
function makeHandle(input: {
102
readonly pid: number;
@@ -345,19 +351,6 @@ describe("CloudManagedEndpointRuntime", () => {
351
isRunning?: Effect.Effect<boolean>;
352
} = {},
353
) {
348
- yield* Effect.acquireRelease(
349
- Effect.sync(() => {
350
- const previous = process.env.TUNNEL_TRANSPORT_PROTOCOL;
351
- if (options.transport === undefined) delete process.env.TUNNEL_TRANSPORT_PROTOCOL;
352
- else process.env.TUNNEL_TRANSPORT_PROTOCOL = options.transport;
353
- return previous;
354
- }),
355
- (previous) =>
356
- Effect.sync(() => {
357
- if (previous === undefined) delete process.env.TUNNEL_TRANSPORT_PROTOCOL;
358
- else process.env.TUNNEL_TRANSPORT_PROTOCOL = previous;
359
- }),
360
- );
354
const spawned: Array<ChildProcess.StandardCommand> = [];
355
const killed: Array<number> = [];
356
const outputs: Array<Queue.Queue<Uint8Array>> = [];
@@ -410,7 +403,9 @@ describe("CloudManagedEndpointRuntime", () => {
403
index,
404
lines + "2026-10-16T20:30:00Z INF Registered tunnel connection connIndex=0\n",
405
).pipe(Effect.andThen(Stream.runHead(runtime.tunnelConnected)));
413
- return { spawner, spawned, killed, exits, started, emit, observe };
406
+ const env: Record<string, string> =
407
+ options.transport === undefined ? {} : { TUNNEL_TRANSPORT_PROTOCOL: options.transport };
408
+ return { spawner, env, spawned, killed, exits, started, emit, observe };
409
});
410
411
it.effect("restarts only the inspected connector and supervises its replacement", () =>
@@ -438,7 +433,13 @@ describe("CloudManagedEndpointRuntime", () => {
433
it.effect("preserves an explicit transport choice despite repeated QUIC stalls", () =>
434
Effect.gen(function* () {
435
const fixture = yield* makeTransportSpawner({ transport: "quic" });
441
- const runtime = yield* buildCloudManagedEndpointRuntime(fixture.spawner);
436
+ const runtime = yield* buildCloudManagedEndpointRuntime(
437
+ fixture.spawner,
438
+ layerRelayClientAvailable,
439
+ unusedHttpClient,
440
+ emptySecretStoreLayer,
441
+ fixture.env,
442
+ );
443
yield* runtime.applyConfig(tunnelConfig);
444
yield* fixture.observe(runtime, 0, quicDialWarning.repeat(30));
445
yield* fixture.observe(runtime, 0, quicDatagramWarning.repeat(30));
@@ -464,12 +465,13 @@ describe("CloudManagedEndpointRuntime", () => {
465
context.pipe(Context.get(ServerSecretStore.ServerSecretStore)),
466
);
467
const fixture = yield* makeTransportSpawner();
467
- const start = (spawner = fixture.spawner) =>
468
+ const start = (spawner = fixture.spawner, env = fixture.env) =>
469
buildCloudManagedEndpointRuntime(
470
spawner,
471
layerRelayClientAvailable,
472
unusedHttpClient,
473
secretStoreLayer,
474
+ env,
475
);
476
yield* Effect.gen(function* () {
477
const runtime = yield* start();
@@ -486,7 +488,7 @@ describe("CloudManagedEndpointRuntime", () => {
488
for (const transport of [undefined, "quic", "http2", "auto", undefined]) {
489
yield* Effect.gen(function* () {
490
const next = yield* makeTransportSpawner(transport ? { transport } : {});
489
- const restarted = yield* start(next.spawner);
491
+ const restarted = yield* start(next.spawner, next.env);
492
yield* restarted.applyConfig(tunnelConfig);
493
if (transport === undefined) {
494
expect(next.spawned[0]!.args.slice(-3)).toEqual(["--protocol", "http2", "run"]);
apps/server/src/cloud/ManagedEndpointRuntime.ts
+7
-2
@@ -1,7 +1,9 @@
1
import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay";
2
import { RotatingFileSink } from "@t3tools/shared/logging";
3
+import * as HostProcess from "@t3tools/shared/HostProcess";
4
import * as RelayClient from "@t3tools/shared/relayClient";
5
import * as Clock from "effect/Clock";
6
+import * as Config from "effect/Config";
7
import * as Context from "effect/Context";
8
import * as Deferred from "effect/Deferred";
9
import * as Duration from "effect/Duration";
@@ -225,7 +227,10 @@ export const make = Effect.gen(function* () {
227
const retryLoopRunningRef = yield* Ref.make(false);
228
const notReadyChecksBeforeRestartRef = yield* Ref.make(CONNECTOR_NOT_READY_CHECKS_BEFORE_RESTART);
229
// An explicit cloudflared transport in the environment is the user's choice.
228
- const transportChosenByUser = process.env.TUNNEL_TRANSPORT_PROTOCOL !== undefined;
230
+ const env = yield* HostProcess.Environment;
231
+ const transportChosenByUser = Option.isSome(
232
+ yield* Config.String("TUNNEL_TRANSPORT_PROTOCOL").pipe(Config.option),
233
+ );
234
const previousFallback = transportChosenByUser
235
? Option.none()
236
: yield* secrets.get(HTTP2_FALLBACK_STATE).pipe(
@@ -730,7 +735,7 @@ export const make = Effect.gen(function* () {
735
{
736
detached: false,
737
env: {
733
- ...process.env,
738
+ ...env,
739
TUNNEL_TOKEN: config.connectorToken,
740
},
741
shell: false,
apps/server/src/device/AgentDeviceTarget.test.ts
+2
-1
@@ -77,10 +77,11 @@ exec '${process.execPath.replaceAll("'", "'\"'\"'")}' "$@"
77
"a!b!c",
78
"",
79
];
80
+ const hostPath = (yield* HostProcess.Environment).PATH ?? "";
81
yield* Effect.promise(() =>
82
expect(
83
exec(path.join(shim, "agent-device"), args, {
83
- env: { PATH: process.env.PATH ?? "", HOME: temp },
84
+ env: { PATH: hostPath, HOME: temp },
85
}),
86
).rejects.toMatchObject({ code: 23, stdout: `${JSON.stringify(args)}\n`, stderr: "" }),
87
);
apps/server/src/git/GitManager.ts
+6
-1
@@ -1,6 +1,7 @@
1
import * as Arr from "effect/Array";
2
import * as Cache from "effect/Cache";
3
import * as Clock from "effect/Clock";
4
+import * as Config from "effect/Config";
5
import * as Context from "effect/Context";
6
import * as SecureRandom from "effect/crypto/SecureRandom";
7
import * as ByteSize from "effect/ByteSize";
@@ -1098,7 +1099,11 @@ export const make = Effect.gen(function* () {
1099
),
1100
),
1101
);
1101
- const tempDir = process.env.TMPDIR ?? process.env.TEMP ?? process.env.TMP ?? "/tmp";
1102
+ const tempDir = yield* Config.String("TMPDIR").pipe(
1103
+ Config.orElse(() => Config.String("TEMP")),
1104
+ Config.orElse(() => Config.String("TMP")),
1105
+ Config.withDefault("/tmp"),
1106
+ );
1107
const canonicalizeExistingPath = (value: string) =>
1108
fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => value));
1109
const normalizeStatusCacheKey = canonicalizeExistingPath;
apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts
+2
-2
@@ -84,7 +84,7 @@ it.effect("forks a session stored under the instance's own CLAUDE_CONFIG_DIR", (
84
prefix: "t3-claude-fork-config-",
85
});
86
const projectDir = yield* writeClaudeSession(configDir);
87
- const hostConfigDir = process.env.CLAUDE_CONFIG_DIR;
87
+ const hostConfigDir = (yield* HostProcess.Environment).CLAUDE_CONFIG_DIR;
88
const inProcessFork = vi.spyOn(ClaudeSdk, "forkSession");
89
yield* Effect.addFinalizer(() => Effect.sync(() => inProcessFork.mockRestore()));
90
@@ -110,7 +110,7 @@ it.effect("forks a session stored under the instance's own CLAUDE_CONFIG_DIR", (
110
?.match(/"uuid"\s*:\s*"([^"]+)"/)?.[1];
111
assert.isString(inheritedHead);
112
assert.equal(forked.headMessageId, inheritedHead);
113
- assert.equal(process.env.CLAUDE_CONFIG_DIR, hostConfigDir);
113
+ assert.equal((yield* HostProcess.Environment).CLAUDE_CONFIG_DIR, hostConfigDir);
114
assert.equal(inProcessFork.mock.calls.length, 0);
115
}).pipe(Effect.provide(forkRunnerLayer)),
116
).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
apps/server/src/project/ManagedProjectFolders.test.ts
+14
-20
@@ -2,6 +2,7 @@ import { assert, it } from "@effect/vitest";
2
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3
import * as NodeServices from "@effect/platform-node/NodeServices";
4
import { CommandId, ProjectId, ThreadId, VcsProcessSpawnError } from "@t3tools/contracts";
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
import * as Deferred from "effect/Deferred";
7
import * as Effect from "effect/Effect";
8
import * as Fiber from "effect/Fiber";
@@ -306,25 +307,15 @@ const withGitEnv = <A, E, R>(
307
Effect.gen(function* () {
308
const fileSystem = yield* FileSystem.FileSystem;
309
const emptyConfig = yield* fileSystem.makeTempFileScoped({ prefix: "t3-gitconfig-" });
309
- return yield* Effect.acquireUseRelease(
310
- Effect.sync(() => {
311
- const saved = GIT_IDENTITY_KEYS.map((key) => [key, process.env[key]] as const);
312
- for (const key of GIT_IDENTITY_KEYS) delete process.env[key];
313
- Object.assign(process.env, {
314
- GIT_CONFIG_GLOBAL: emptyConfig,
315
- GIT_CONFIG_NOSYSTEM: "1",
316
- ...env,
317
- });
318
- return saved;
310
+ const hostEnv: NodeJS.ProcessEnv = { ...(yield* HostProcess.Environment) };
311
+ for (const key of GIT_IDENTITY_KEYS) delete hostEnv[key];
312
+ return yield* effect.pipe(
313
+ Effect.provideService(HostProcess.Environment, {
314
+ ...hostEnv,
315
+ GIT_CONFIG_GLOBAL: emptyConfig,
316
+ GIT_CONFIG_NOSYSTEM: "1",
317
+ ...env,
318
}),
320
- () => effect,
321
- (saved) =>
322
- Effect.sync(() => {
323
- for (const [key, value] of saved) {
324
- if (value === undefined) delete process.env[key];
325
- else process.env[key] = value;
326
- }
327
- }),
319
);
320
});
321
@@ -354,7 +345,7 @@ it.effect("starts a named project as a committed repository, and suffixes a take
345
yield* fileSystem.writeFileString(attributes, "* text=auto eol=crlf\n");
346
yield* git(baseDir, ["config", "--file", crlfConfig, "core.safecrlf", "true"]);
347
yield* git(baseDir, ["config", "--file", crlfConfig, "core.attributesFile", attributes]);
357
- process.env.GIT_CONFIG_GLOBAL = crlfConfig;
348
+ (yield* HostProcess.Environment).GIT_CONFIG_GLOBAL = crlfConfig;
349
350
const first = yield* folders.createNamedProject({ name: "Pinball Stats" });
351
const second = yield* folders.createNamedProject({ name: "pinball stats" });
@@ -427,7 +418,10 @@ it.effect("keeps a named project and reports why when Git cannot commit", () =>
418
path.join(baseDir, "no-identity.gitconfig"),
419
"[user]\n\tuseConfigOnly = true\n",
420
);
430
- process.env.GIT_CONFIG_GLOBAL = path.join(baseDir, "no-identity.gitconfig");
421
+ (yield* HostProcess.Environment).GIT_CONFIG_GLOBAL = path.join(
422
+ baseDir,
423
+ "no-identity.gitconfig",
424
+ );
425
426
const result = yield* folders.createNamedProject({ name: "No Identity" });
427
apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts
+2
-1
@@ -4,6 +4,7 @@ import { ClaudeSettings, type ServerProvider } from "@t3tools/contracts";
4
import { vi } from "vite-plus/test";
5
import * as ClaudeSdk from "@anthropic-ai/claude-agent-sdk";
6
import { assert, it } from "@effect/vitest";
7
+import * as HostProcess from "@t3tools/shared/HostProcess";
8
import * as Effect from "effect/Effect";
9
import * as FileSystem from "effect/FileSystem";
10
import * as Schema from "effect/Schema";
@@ -76,7 +77,7 @@ it.effect("keeps the probe subprocess alive while gateway model discovery can fi
77
);
78
const capabilities = yield* probeClaudeCapabilities(
79
yield* decodeClaudeSettings({ binaryPath: "claude" }),
79
- { PATH: process.env.PATH, CLAUDE_CONFIG_DIR: configDir },
80
+ { PATH: (yield* HostProcess.Environment).PATH, CLAUDE_CONFIG_DIR: configDir },
81
);
82
assert.deepEqual(
83
capabilities.models?.map((model) => model.value),
apps/server/src/provider/CodexManagedRuntime.test.ts
+3
-2
@@ -95,6 +95,7 @@ it.live.each(
95
email: null,
96
});
97
yield* store.set(new TextEncoder().encode(json));
98
+ const hostEnv = yield* HostProcess.Environment;
99
const ambient = {
100
CODEX_HOME: "/user/.codex",
101
ACCESS_TOKEN: "ambient-bearer",
@@ -102,8 +103,8 @@ it.live.each(
103
OPENAI_API_KEY: "dummy-global-key",
104
OPENAI_BASE_URL: "https://user-proxy.test",
105
T3CODE_CODEX_LAUNCH_ARGS: "--config model_provider=global-proxy",
105
- PATH: process.env.PATH,
106
- SystemRoot: process.env.SystemRoot,
106
+ PATH: hostEnv.PATH,
107
+ SystemRoot: hostEnv.SystemRoot,
108
};
109
const runtime = yield* makeCodexManagedRuntime({
110
instanceId,
apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
+12
-10
@@ -34,6 +34,16 @@ const mockRuntimeOptions = {
34
authMethodId: "test",
35
} satisfies AcpSessionRuntime.AcpSessionRuntimeOptions;
36
37
+// The spawner extends the real process environment, so the test must set it there.
38
+const setProcessEnv = (name: string, value: string) => {
39
+ const previous = process.env[name];
40
+ process.env[name] = value;
41
+ return () => {
42
+ if (previous === undefined) delete process.env[name];
43
+ else process.env[name] = previous;
44
+ };
45
+};
46
+
47
describe("AcpSessionRuntime", () => {
48
it.effect.each(["session/new", "session/resume"] as const)(
49
"buffers root metadata while %s startup is still pending",
@@ -422,16 +432,8 @@ describe("AcpSessionRuntime", () => {
432
it.effect("does not restore ambient variables to a sanitized child environment", () =>
433
Effect.gen(function* () {
434
yield* Effect.acquireRelease(
425
- Effect.sync(() => {
426
- const previous = process.env.T3_ACP_RUNTIME_AMBIENT;
427
- process.env.T3_ACP_RUNTIME_AMBIENT = "sentinel";
428
- return previous;
429
- }),
430
- (previous) =>
431
- Effect.sync(() => {
432
- if (previous === undefined) delete process.env.T3_ACP_RUNTIME_AMBIENT;
433
- else process.env.T3_ACP_RUNTIME_AMBIENT = previous;
434
- }),
435
+ Effect.sync(() => setProcessEnv("T3_ACP_RUNTIME_AMBIENT", "sentinel")),
436
+ (restore) => Effect.sync(restore),
437
);
438
const runtime = yield* AcpSessionRuntime.make({
439
...mockRuntimeOptions,
apps/server/src/serviceLauncher.test.ts
+2
-1
@@ -6,6 +6,7 @@ import * as NodeFS from "node:fs";
6
import * as NodeServices from "@effect/platform-node/NodeServices";
7
import { assert, it } from "@effect/vitest";
8
import { SERVER_EXIT_CODE_STATE_DIR_OWNED } from "@t3tools/contracts";
9
+import * as HostProcess from "@t3tools/shared/HostProcess";
10
import * as Effect from "effect/Effect";
11
import * as FileSystem from "effect/FileSystem";
12
import * as Path from "effect/Path";
@@ -379,7 +380,7 @@ if (context.update?.status === "pending") {
380
{ token: "initial", update: "pending" },
381
{ token: "initial", update: "rolled-back" },
382
]);
382
- assert.equal(process.env.T3CODE_TEST_SERVICE_TOKEN, "inherited");
383
+ assert.equal((yield* HostProcess.Environment).T3CODE_TEST_SERVICE_TOKEN, "inherited");
384
assert.equal(yield* fs.readFileString(envPath), "T3CODE_TEST_SERVICE_TOKEN=changed\n");
385
}),
386
);
apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
+24
-126
@@ -75,136 +75,34 @@ function withFakeClaudeEnv<A, E, R>(
75
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-claude-text-" });
76
const binDir = yield* makeFakeClaudeBinary(tempDir, input.lifecyclePort);
77
const pathDelimiter = (yield* HostProcess.isWindows) ? ";" : ":";
78
- const previousPath = process.env.PATH;
79
- const previousRejectsNoSessionPersistence =
80
- process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
81
- const previousOutput = process.env.T3_FAKE_CLAUDE_OUTPUT;
82
- const previousExitCode = process.env.T3_FAKE_CLAUDE_EXIT_CODE;
83
- const previousStderr = process.env.T3_FAKE_CLAUDE_STDERR;
84
- const previousArgsMustContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN;
85
- const previousArgsMustNotContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN;
86
- const previousStdinMustContain = process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN;
87
- const previousConfigDirMustBe = process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE;
88
- const previousCwdMustNotBe = process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE;
89
-
90
- yield* Effect.acquireRelease(
91
- Effect.sync(() => {
92
- process.env.PATH = `${binDir}${pathDelimiter}${previousPath ?? ""}`;
93
- process.env.T3_FAKE_CLAUDE_OUTPUT = input.output;
94
-
95
- if (input.rejectsNoSessionPersistence) {
96
- process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE = "1";
97
- } else {
98
- delete process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
99
- }
100
-
101
- if (input.exitCode !== undefined) {
102
- process.env.T3_FAKE_CLAUDE_EXIT_CODE = String(input.exitCode);
103
- } else {
104
- delete process.env.T3_FAKE_CLAUDE_EXIT_CODE;
105
- }
106
-
107
- if (input.stderr !== undefined) {
108
- process.env.T3_FAKE_CLAUDE_STDERR = input.stderr;
109
- } else {
110
- delete process.env.T3_FAKE_CLAUDE_STDERR;
111
- }
112
-
113
- if (input.argsMustContain !== undefined) {
114
- process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN = input.argsMustContain;
115
- } else {
116
- delete process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN;
117
- }
118
-
119
- if (input.argsMustNotContain !== undefined) {
120
- process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN = input.argsMustNotContain;
121
- } else {
122
- delete process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN;
123
- }
124
-
125
- if (input.stdinMustContain !== undefined) {
126
- process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN = input.stdinMustContain;
127
- } else {
128
- delete process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN;
129
- }
130
-
131
- if (input.cwdMustNotBe !== undefined) {
132
- process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE = input.cwdMustNotBe;
133
- } else {
134
- delete process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE;
135
- }
136
-
137
- if (input.configDirMustBe !== undefined) {
138
- process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE = input.configDirMustBe;
139
- } else {
140
- delete process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE;
141
- }
142
- }),
143
- () =>
144
- Effect.sync(() => {
145
- process.env.PATH = previousPath;
146
-
147
- if (previousRejectsNoSessionPersistence === undefined) {
148
- delete process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
149
- } else {
150
- process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE =
151
- previousRejectsNoSessionPersistence;
152
- }
153
-
154
- if (previousOutput === undefined) {
155
- delete process.env.T3_FAKE_CLAUDE_OUTPUT;
156
- } else {
157
- process.env.T3_FAKE_CLAUDE_OUTPUT = previousOutput;
158
- }
159
-
160
- if (previousExitCode === undefined) {
161
- delete process.env.T3_FAKE_CLAUDE_EXIT_CODE;
162
- } else {
163
- process.env.T3_FAKE_CLAUDE_EXIT_CODE = previousExitCode;
164
- }
165
-
166
- if (previousStderr === undefined) {
167
- delete process.env.T3_FAKE_CLAUDE_STDERR;
168
- } else {
169
- process.env.T3_FAKE_CLAUDE_STDERR = previousStderr;
170
- }
171
-
172
- if (previousArgsMustContain === undefined) {
173
- delete process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN;
174
- } else {
175
- process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN = previousArgsMustContain;
176
- }
177
-
178
- if (previousArgsMustNotContain === undefined) {
179
- delete process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN;
180
- } else {
181
- process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN = previousArgsMustNotContain;
182
- }
183
-
184
- if (previousStdinMustContain === undefined) {
185
- delete process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN;
186
- } else {
187
- process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN = previousStdinMustContain;
188
- }
189
-
190
- if (previousCwdMustNotBe === undefined) {
191
- delete process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE;
192
- } else {
193
- process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE = previousCwdMustNotBe;
194
- }
195
-
196
- if (previousConfigDirMustBe === undefined) {
197
- delete process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE;
198
- } else {
199
- process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE = previousConfigDirMustBe;
200
- }
201
- }),
202
- );
78
+ const hostEnv = yield* HostProcess.Environment;
79
+ const fakeClaudeEnv: Record<string, string | undefined> = {
80
+ T3_FAKE_CLAUDE_OUTPUT: input.output,
81
+ T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE: input.rejectsNoSessionPersistence
82
+ ? "1"
83
+ : undefined,
84
+ T3_FAKE_CLAUDE_EXIT_CODE: input.exitCode === undefined ? undefined : String(input.exitCode),
85
+ T3_FAKE_CLAUDE_STDERR: input.stderr,
86
+ T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN: input.argsMustContain,
87
+ T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN: input.argsMustNotContain,
88
+ T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN: input.stdinMustContain,
89
+ T3_FAKE_CLAUDE_CWD_MUST_NOT_BE: input.cwdMustNotBe,
90
+ T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE: input.configDirMustBe,
91
+ };
92
+ const environment: NodeJS.ProcessEnv = {
93
+ ...Object.fromEntries(
94
+ Object.entries(hostEnv).filter(([name]) => !name.startsWith("T3_FAKE_CLAUDE_")),
95
+ ),
96
+ ...Object.fromEntries(
97
+ Object.entries(fakeClaudeEnv).filter(([, value]) => value !== undefined),
98
+ ),
99
+ PATH: `${binDir}${pathDelimiter}${hostEnv.PATH ?? ""}`,
100
+ };
101
102
const config = decodeClaudeSettings(input.claudeConfig ?? {});
103
const textGeneration = yield* makeClaudeTextGeneration(
104
config,
207
- undefined,
105
+ environment,
106
Effect.succeed(SYNTHETIC_CLAUDE_MODEL_CATALOG),
107
);
108
return yield* effectFn(textGeneration);
apps/server/src/vcs/GitVcsDriver.test.ts
+4
-11
@@ -277,18 +277,11 @@ it.effect("checkpoint recovery discovers nested HEAD independently of inherited
277
const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);
278
yield* git(["init", "empty"]);
279
const originalIndex = yield* fs.readFile(path.join(cwd, ".git", "index"));
280
- yield* Effect.acquireUseRelease(
281
- Effect.sync(() => {
282
- const previous = process.env.GIT_DIR;
283
- process.env.GIT_DIR = path.join(cwd, ".git");
284
- return previous;
280
+ yield* driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }).pipe(
281
+ Effect.provideService(HostProcess.Environment, {
282
+ ...(yield* HostProcess.Environment),
283
+ GIT_DIR: path.join(cwd, ".git"),
284
}),
286
- () => driver.checkpoints.captureCheckpoint({ cwd, checkpointRef }),
287
- (previous) =>
288
- Effect.sync(() => {
289
- if (previous === undefined) delete process.env.GIT_DIR;
290
- else process.env.GIT_DIR = previous;
291
- }),
285
);
286
assert.strictEqual((yield* git(["show", `${checkpointRef}:file.txt`])).stdout, "unstaged\n");
287
assert.strictEqual((yield* git(["ls-tree", "-r", checkpointRef, "--", "empty"])).stdout, "");
apps/server/src/vcs/GitVcsDriver.ts
+3
-2
@@ -913,8 +913,9 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
913
const { gitCommonDir, indexPath, headExists } = yield* resolveCaptureRepository(input.cwd);
914
const indexId = yield* random.uuidV4();
915
const tempIndexPath = path.join(gitCommonDir, `t3-checkpoint-index-${indexId}`);
916
+ const hostEnv = yield* HostProcess.Environment;
917
const commitEnv: NodeJS.ProcessEnv = {
917
- ...process.env,
918
+ ...hostEnv,
919
GIT_INDEX_FILE: tempIndexPath,
920
GIT_AUTHOR_NAME: "T3 Code",
921
GIT_AUTHOR_EMAIL: "t3code@users.noreply.github.com",
@@ -1207,7 +1208,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
1208
);
1209
if (candidates.length > CHECKPOINT_RECOVERY_MAX_CANDIDATES) return yield* error;
1210
const nestedRepoEnv: NodeJS.ProcessEnv = {
1210
- ...process.env,
1211
+ ...hostEnv,
1212
GIT_DIR: undefined,
1213
GIT_WORK_TREE: undefined,
1214
GIT_COMMON_DIR: undefined,
apps/server/src/vcs/GitVcsDriverCore.test.ts
+21
-58
@@ -266,6 +266,14 @@ const git = (
266
return result.stdout.trim();
267
});
268
269
+// Git blocks file submodule transports (CVE-2022-39253) despite repo config; local fixtures need env permission.
270
+const withGitFileProtocol = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
271
+ Effect.flatMap(HostProcess.Environment, (env) =>
272
+ effect.pipe(
273
+ Effect.provideService(HostProcess.Environment, { ...env, GIT_ALLOW_PROTOCOL: "file" }),
274
+ ),
275
+ );
276
+
277
const initRepoWithCommit = (
278
cwd: string,
279
): Effect.Effect<
@@ -4040,30 +4048,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4048
const sshWrapperPath = yield* pathService.fromFileUrl(
4049
new URL("./testing/GitVcsDriverCore.fixture.sh", import.meta.url),
4050
);
4043
- const envKeys = [
4044
- "GCM_INTERACTIVE",
4045
- "GIT_ASKPASS",
4046
- "GIT_SSH",
4047
- "GIT_TERMINAL_PROMPT",
4048
- "SSH_ASKPASS",
4049
- "SSH_ASKPASS_REQUIRE",
4050
- "T3_TEST_SSH_ASKPASS_LOG",
4051
- ] as const;
4052
- const previousEnv = new Map(envKeys.map((key) => [key, process.env[key]]));
4051
4052
yield* git(cwd, ["remote", "add", "origin", "ssh://example.invalid/repo.git"]);
4053
yield* git(cwd, ["update-ref", `refs/remotes/origin/${initialBranch}`, "HEAD"]);
4054
yield* git(cwd, ["branch", "--set-upstream-to", `origin/${initialBranch}`]);
4055
4056
yield* Effect.gen(function* () {
4059
- process.env.GIT_SSH = sshWrapperPath;
4060
- process.env.GCM_INTERACTIVE = "always";
4061
- process.env.GIT_ASKPASS = "git-askpass";
4062
- process.env.GIT_TERMINAL_PROMPT = "1";
4063
- process.env.SSH_ASKPASS = "ssh-askpass";
4064
- process.env.SSH_ASKPASS_REQUIRE = "force";
4065
- process.env.T3_TEST_SSH_ASKPASS_LOG = sshLogPath;
4066
-
4057
yield* (yield* GitVcsDriver.GitVcsDriver).statusDetails(cwd);
4058
4059
assert.deepEqual((yield* fileSystem.readFileString(sshLogPath)).trim().split(/\r?\n/), [
@@ -4074,18 +4064,16 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4064
"SSH_ASKPASS_REQUIRE=never",
4065
]);
4066
}).pipe(
4077
- Effect.ensuring(
4078
- Effect.sync(() => {
4079
- for (const key of envKeys) {
4080
- const previous = previousEnv.get(key);
4081
- if (previous === undefined) {
4082
- delete process.env[key];
4083
- } else {
4084
- process.env[key] = previous;
4085
- }
4086
- }
4087
- }),
4088
- ),
4067
+ Effect.provideService(HostProcess.Environment, {
4068
+ ...(yield* HostProcess.Environment),
4069
+ GIT_SSH: sshWrapperPath,
4070
+ GCM_INTERACTIVE: "always",
4071
+ GIT_ASKPASS: "git-askpass",
4072
+ GIT_TERMINAL_PROMPT: "1",
4073
+ SSH_ASKPASS: "ssh-askpass",
4074
+ SSH_ASKPASS_REQUIRE: "force",
4075
+ T3_TEST_SSH_ASKPASS_LOG: sshLogPath,
4076
+ }),
4077
);
4078
}),
4079
);
@@ -4488,7 +4476,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4476
const fs = yield* FileSystem.FileSystem;
4477
const path = yield* Path.Path;
4478
const driver = yield* GitVcsDriver.GitVcsDriver;
4491
- const serverLocale = process.env.LC_ALL ?? "unset";
4479
+ const serverLocale = (yield* HostProcess.Environment).LC_ALL ?? "unset";
4480
const seenLocale = path.join(yield* makeTmpDir("git-hook-locale-"), "lc-all");
4481
yield* writeTextFile(
4482
cwd,
@@ -4767,19 +4755,6 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4755
const fileSystem = yield* FileSystem.FileSystem;
4756
const pathService = yield* Path.Path;
4757
4770
- // Git blocks file submodule transports (CVE-2022-39253) despite repo config; local fixtures need env permission.
4771
- const previousAllowedProtocol = process.env.GIT_ALLOW_PROTOCOL;
4772
- process.env.GIT_ALLOW_PROTOCOL = "file";
4773
- yield* Effect.addFinalizer(() =>
4774
- Effect.sync(() => {
4775
- if (previousAllowedProtocol === undefined) {
4776
- delete process.env.GIT_ALLOW_PROTOCOL;
4777
- } else {
4778
- process.env.GIT_ALLOW_PROTOCOL = previousAllowedProtocol;
4779
- }
4780
- }),
4781
- );
4782
-
4758
const submoduleRepo = yield* makeTmpDir("git-submodule-");
4759
yield* initRepoWithCommit(submoduleRepo);
4760
yield* writeTextFile(submoduleRepo, ".gitattributes", "* text eol=lf\n");
@@ -4865,7 +4840,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4840
"",
4841
);
4842
if (progress) assert.isNotEmpty(yield* Ref.get(lines));
4868
- }),
4843
+ }).pipe(withGitFileProtocol),
4844
);
4845
4846
it.effect("still creates the worktree when submodule checkout fails", () =>
@@ -4994,18 +4969,6 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4969
const fileSystem = yield* FileSystem.FileSystem;
4970
const pathService = yield* Path.Path;
4971
4997
- const previousAllowedProtocol = process.env.GIT_ALLOW_PROTOCOL;
4998
- process.env.GIT_ALLOW_PROTOCOL = "file";
4999
- yield* Effect.addFinalizer(() =>
5000
- Effect.sync(() => {
5001
- if (previousAllowedProtocol === undefined) {
5002
- delete process.env.GIT_ALLOW_PROTOCOL;
5003
- } else {
5004
- process.env.GIT_ALLOW_PROTOCOL = previousAllowedProtocol;
5005
- }
5006
- }),
5007
- );
5008
-
4972
const nestedRepo = yield* makeTmpDir("git-nested-");
4973
yield* initRepoWithCommit(nestedRepo);
4974
yield* writeTextFile(nestedRepo, "NESTED.md", "# nested\n");
@@ -5076,7 +5039,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
5039
inner: false,
5040
nested: false,
5041
});
5079
- }),
5042
+ }).pipe(withGitFileProtocol),
5043
);
5044
5045
it.effect("still creates the worktree when the base-ref config stays locked", () =>
apps/server/src/vcs/GitVcsDriverCore.ts
+1
-1
@@ -977,7 +977,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
977
),
978
);
979
const baseEnv = {
980
- ...process.env,
980
+ ...(yield* HostProcess.Environment),
981
// Concurrent status polls must not take index.lock to save refreshed indexes.
982
GIT_OPTIONAL_LOCKS: "0",
983
...input.env,
evals/mcp-tool-use/run.ts
+2
-1
@@ -22,6 +22,7 @@ import {
22
} from "@t3tools/contracts";
23
import * as Cause from "effect/Cause";
24
import * as Context from "effect/Context";
25
+import * as Config from "effect/Config";
26
import * as Effect from "effect/Effect";
27
import * as FileSystem from "effect/FileSystem";
28
import * as Layer from "effect/Layer";
@@ -2403,7 +2404,7 @@ const main = Effect.gen(function* () {
2404
}
2405
return;
2406
}
2406
- const apiKey = process.env.ANTHROPIC_API_KEY ?? "";
2407
+ const apiKey = yield* Config.String("ANTHROPIC_API_KEY").pipe(Config.withDefault(""));
2408
const out = flags.out;
2409
if ((!apiKey && !codex) || out === undefined) {
2410
const message =
packages/effect-acp/test/fixtures/acp-mock-peer.ts
+4
-2
@@ -23,6 +23,8 @@ const sessionId = "mock-session-1";
23
const v2Management = process.env.ACP_MOCK_V2_MANAGEMENT === "1";
24
const unknownVariants = process.env.ACP_MOCK_UNKNOWN_VARIANTS === "1";
25
const mcpOverAcp = process.env.ACP_MOCK_MCP_OVER_ACP === "1";
26
+const v2Diff = process.env.ACP_MOCK_V2_DIFF === "1";
27
+const badTypedRequest = process.env.ACP_MOCK_BAD_TYPED_REQUEST === "1";
28
29
const program = Effect.gen(function* () {
30
const agent = yield* AcpAgent.AcpAgent;
@@ -178,7 +180,7 @@ const program = Effect.gen(function* () {
180
},
181
});
182
181
- if (process.env.ACP_MOCK_V2_DIFF === "1") {
183
+ if (v2Diff) {
184
yield* agent.client.sessionUpdate({
185
sessionId,
186
update: {
@@ -211,7 +213,7 @@ const program = Effect.gen(function* () {
213
});
214
215
yield* agent.client.extRequest("x/typed_request", {
214
- message: process.env.ACP_MOCK_BAD_TYPED_REQUEST === "1" ? 123 : "hello from typed request",
216
+ message: badTypedRequest ? 123 : "hello from typed request",
217
});
218
219
yield* agent.client.extNotification("x/typed_notification", {
packages/effect-codex-app-server/scripts/generate.ts
+4
-3
@@ -203,12 +203,13 @@ const ensureGeneratedDir = Effect.fn("ensureGeneratedDir")(function* () {
203
yield* fs.makeDirectory(generatedDir, { recursive: true });
204
});
205
206
+const githubToken = process.env.GITHUB_TOKEN;
207
+
208
const fetchText = Effect.fn("fetchText")(function* (url: string) {
207
- const token = process.env.GITHUB_TOKEN;
209
return yield* HttpClientRequest.get(url).pipe(
210
HttpClientRequest.setHeader("user-agent", USER_AGENT),
210
- token && url.startsWith("https://api.github.com/")
211
- ? HttpClientRequest.bearerToken(token)
211
+ githubToken && url.startsWith("https://api.github.com/")
212
+ ? HttpClientRequest.bearerToken(githubToken)
213
: (request) => request,
214
HttpClient.execute,
215
Effect.flatMap(HttpClientResponse.filterStatusOk),
packages/effect-codex-app-server/test/examples/codex-app-server-probe.ts
+3
-1
@@ -7,10 +7,12 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
7
8
import * as CodexClient from "../../src/client.ts";
9
10
+const codexBin = process.env.CODEX_BIN ?? "codex";
11
+
12
const program = Effect.gen(function* () {
13
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
14
const handle = yield* spawner.spawn(
13
- ChildProcess.make(process.env.CODEX_BIN ?? "codex", ["app-server"], {
15
+ ChildProcess.make(codexBin, ["app-server"], {
16
cwd: process.cwd(),
17
shell: false,
18
}),
packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts
+8
-4
@@ -91,10 +91,12 @@ const makeFakeNpmToolchain = Effect.fn("AcpRegistrySupport.test.makeFakeNpmToolc
91
npmPath,
92
);
93
yield* fileSystem.chmod(npmPath, 0o755);
94
+ // The fake toolchain runs on the real host, not the simulated provider environment.
95
+ const hostEnv = HostProcess.Environment.defaultValue();
96
return {
97
environment: {
96
- ...process.env,
97
- PATH: `${toolchainBin}:${process.env.PATH ?? ""}`,
98
+ ...hostEnv,
99
+ PATH: `${toolchainBin}:${hostEnv.PATH ?? ""}`,
100
FAKE_NPM_LOG: logPath,
101
FAKE_NPM_PREFIX: path.join(rootDirectory, "external-npm-global"),
102
FAKE_NPM_MANIFEST: encodeUnknownJson({
@@ -127,10 +129,12 @@ const makeFakeUvToolchain = Effect.fn("AcpRegistrySupport.test.makeFakeUvToolcha
129
uvPath,
130
);
131
yield* fileSystem.chmod(uvPath, 0o755);
132
+ // The fake toolchain runs on the real host, not the simulated provider environment.
133
+ const hostEnv = HostProcess.Environment.defaultValue();
134
return {
135
environment: {
132
- ...process.env,
133
- PATH: `${toolchainBin}:${process.env.PATH ?? ""}`,
136
+ ...hostEnv,
137
+ PATH: `${toolchainBin}:${hostEnv.PATH ?? ""}`,
138
FAKE_UV_LOG: logPath,
139
FAKE_UV_BIN: path.join(rootDirectory, "external-uv-bin"),
140
FAKE_UV_EXECUTABLE: executablePath,
packages/source-control-forgejo/src/server/ForgejoCli.ts
+11
-4
@@ -1,6 +1,8 @@
1
+import * as Config from "effect/Config";
2
import * as Context from "effect/Context";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
5
+import * as Option from "effect/Option";
6
import * as Schema from "effect/Schema";
7
import * as Result from "effect/Result";
8
import * as Clock from "effect/Clock";
@@ -209,7 +211,14 @@ export function matchForgejoLogin(
211
: undefined;
212
}
213
214
+const ForgejoKeysConfig = Config.all({
215
+ dataHome: Config.String("XDG_DATA_HOME").pipe(Config.option),
216
+ appData: Config.String("APPDATA").pipe(Config.option),
217
+});
218
+
219
export const make = Effect.gen(function* () {
220
+ // Optional strings cannot fail to decode.
221
+ const { dataHome, appData } = yield* Effect.suspend(() => ForgejoKeysConfig).pipe(Effect.orDie);
222
const { process } = yield* SourceControlHost.SourceControlHost;
223
const fileSystem = yield* FileSystem.FileSystem;
224
const httpClient = yield* HttpClient.HttpClient;
@@ -249,10 +258,8 @@ export const make = Effect.gen(function* () {
258
for (const path of forgejoKeysPaths({
259
platform: yield* HostProcess.Platform,
260
home: yield* HostProcess.HomeDirectory,
252
- ...(globalThis.process.env.XDG_DATA_HOME
253
- ? { dataHome: globalThis.process.env.XDG_DATA_HOME }
254
- : {}),
255
- ...(globalThis.process.env.APPDATA ? { appData: globalThis.process.env.APPDATA } : {}),
261
+ ...(Option.isSome(dataHome) ? { dataHome: dataHome.value } : {}),
262
+ ...(Option.isSome(appData) ? { appData: appData.value } : {}),
263
})) {
264
const exists = yield* fileSystem.exists(path).pipe(
265
Effect.mapError(
scripts/build-npm-launcher.test.ts
+4
-4
@@ -68,7 +68,7 @@ exit 7
68
yield* fs.chmod(path.join(root, "release", stem, "t3"), 0o755);
69
const tar = yield* run("tar", ["-czf", archiveName, stem], {
70
cwd: path.join(root, "release"),
71
- env: { PATH: process.env.PATH },
71
+ env: { PATH: (yield* HostProcess.Environment).PATH },
72
});
73
assert.equal(tar.exitCode, 0, tar.stderr);
74
const archive = yield* fs.readFile(path.join(root, "release", archiveName));
@@ -131,7 +131,7 @@ it.layer(NodeServices.layer)("build-npm-launcher", (it) => {
131
yield* fs.makeDirectory(installed);
132
const unpack = yield* run("tar", ["-xzf", output.tarball, "-C", installed], {
133
cwd: root,
134
- env: { PATH: process.env.PATH },
134
+ env: { PATH: (yield* HostProcess.Environment).PATH },
135
});
136
assert.equal(unpack.exitCode, 0, unpack.stderr);
137
const packageDir = path.join(installed, "package");
@@ -139,7 +139,7 @@ it.layer(NodeServices.layer)("build-npm-launcher", (it) => {
139
const release = yield* serveFakeRelease(root);
140
const home = path.join(root, "home");
141
const env = {
142
- PATH: process.env.PATH,
142
+ PATH: (yield* HostProcess.Environment).PATH,
143
T3CODE_HOME: home,
144
T3CODE_TEST_CALLS: path.join(root, "calls"),
145
T3CODE_RELEASE_BASE_URL: release.baseUrl,
@@ -374,7 +374,7 @@ syncBuiltinESMExports();
374
`,
375
);
376
const env = {
377
- PATH: process.env.PATH,
377
+ PATH: (yield* HostProcess.Environment).PATH,
378
T3CODE_HOME: home,
379
T3CODE_RELEASE_BASE_URL: release.baseUrl,
380
T3CODE_TEST_READY: path.join(root, "probe-ready"),
tsconfig.effect.json
+1
@@ -96,6 +96,7 @@
96
"timeoutCatchTagToTimeoutOrElse": "error",
97
"unnecessaryPipe": "error",
98
"unnecessaryTypeofType": "error",
99
+ "processEnvInEffect": "error",
100
"schemaNumber": "off"
101
},
102
"overrides": [