Skip to content

Commit e0f3e51

Browse files
committed
chore(usage): merge main and preserve workspace credit identity
2 parents 92a3f2b + 57b3780 commit e0f3e51

111 files changed

Lines changed: 3844 additions & 682 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.macroscope/check-run-agents/effect-service-conventions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Effect Service Conventions
3-
model: gpt-6-1-sol
4-
reasoning: max
3+
model: gpt-6-sol
4+
effort: max
55
input: incremental
66
tools:
77
- browse_code

‎.macroscope/check-run-agents/ui-consistency.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: UI Consistency
3-
model: gpt-6-1-sol
4-
reasoning: max
3+
model: gpt-6-sol
4+
effort: max
55
input: incremental
66
tools:
77
- browse_code

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Install the latest version of the desktop app from [GitHub Releases](https://git
4848
winget install T3Tools.T3Code
4949
```
5050

51+
#### Windows (`scoop`)
52+
53+
```bash
54+
scoop install extras/t3code
55+
```
56+
5157
#### macOS (Homebrew)
5258

5359
```bash

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,21 @@ describe("DesktopBackendConfiguration", () => {
325325
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
326326
);
327327

328+
it.effect("only the local primary bootstrap claims the prepared shell environment", () =>
329+
withHarness(
330+
Effect.gen(function* () {
331+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
332+
333+
const primary = yield* configuration.resolvePrimary;
334+
const wsl = yield* configuration.resolveWsl({ port: 5000, distro: null });
335+
336+
assert.equal(primary.bootstrap.shellEnvironmentPrepared, true);
337+
// A WSL server runs on its own Linux user environment and must hydrate it.
338+
assert.isUndefined(wsl.bootstrap.shellEnvironmentPrepared);
339+
}),
340+
),
341+
);
342+
328343
it.effect("resolveWsl reuses the primary's bootstrap token", () =>
329344
withHarness(
330345
Effect.gen(function* () {

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
567567
host: backendExposure.bindHost,
568568
desktopBootstrapToken: input.bootstrapToken,
569569
desktopBootstrapSecret: input.bootstrapSecret,
570+
// DesktopApp installs the shell environment into process.env before any
571+
// backend starts, and this child extends it (extendEnv below). WSL gets
572+
// a different environment, so its bootstrap never sets this.
573+
shellEnvironmentPrepared: true,
570574
tailscaleServeEnabled: backendExposure.tailscaleServeEnabled,
571575
tailscaleServePort: backendExposure.tailscaleServePort,
572576
desktopTelemetryFd: 4,

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import * as Sink from "effect/Sink";
99
import * as Stream from "effect/Stream";
1010
import * as ChildProcess from "effect/process/ChildProcess";
1111
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
12+
import * as NodeOS from "node:os";
13+
import { vi } from "vite-plus/test";
1214

1315
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
1416
import * as DesktopShellEnvironment from "./DesktopShellEnvironment.ts";
1517

18+
vi.mock("node:os", { spy: true });
19+
1620
const textEncoder = new TextEncoder();
1721

1822
const isDesktopShellEnvironmentCommandError = Schema.is(
@@ -29,14 +33,14 @@ function envOutput(values: Readonly<Record<string, string>>): string {
2933
.join("\n");
3034
}
3135

32-
function makeProcess(output: string): ChildProcessSpawner.ChildProcessHandle {
36+
function makeProcess(output: string, exitCode = 0): ChildProcessSpawner.ChildProcessHandle {
3337
const stdout = output.length === 0 ? Stream.empty : Stream.make(textEncoder.encode(output));
3438
return ChildProcessSpawner.makeHandle({
3539
pid: ChildProcessSpawner.ProcessId(123),
3640
stdout,
3741
stderr: Stream.empty,
3842
all: stdout,
39-
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
43+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCode)),
4044
isRunning: Effect.succeed(false),
4145
kill: () => Effect.void,
4246
stdin: Sink.drain,
@@ -67,7 +71,10 @@ function withProcessEnv<A, E, R>(
6771
function runShellEnvironment(input: {
6872
readonly env: NodeJS.ProcessEnv;
6973
readonly platform: NodeJS.Platform;
70-
readonly handler: (command: ChildProcess.Command) => string;
74+
readonly userShell?: string;
75+
readonly handler: (
76+
command: ChildProcess.Command,
77+
) => string | { output: string; exitCode: number };
7178
readonly failure?: PlatformError.PlatformError;
7279
}) {
7380
const layerEnvironment = Layer.succeed(
@@ -78,11 +85,15 @@ function runShellEnvironment(input: {
7885
);
7986
const layerSpawner = Layer.succeed(
8087
ChildProcessSpawner.ChildProcessSpawner,
81-
ChildProcessSpawner.make((command) =>
82-
input.failure === undefined
83-
? Effect.succeed(makeProcess(input.handler(command)))
84-
: Effect.fail(input.failure),
85-
),
88+
ChildProcessSpawner.make((command) => {
89+
if (input.failure !== undefined) return Effect.fail(input.failure);
90+
const result = input.handler(command);
91+
return Effect.succeed(
92+
typeof result === "string"
93+
? makeProcess(result)
94+
: makeProcess(result.output, result.exitCode),
95+
);
96+
}),
8697
);
8798

8899
const program = Effect.gen(function* () {
@@ -96,10 +107,88 @@ function runShellEnvironment(input: {
96107
),
97108
);
98109

99-
return withProcessEnv(input.env, program);
110+
return Effect.acquireUseRelease(
111+
Effect.sync(() =>
112+
vi.spyOn(NodeOS, "userInfo").mockReturnValue({
113+
...NodeOS.userInfo(),
114+
shell: input.userShell ?? null,
115+
}),
116+
),
117+
() => withProcessEnv(input.env, program),
118+
(spy) => Effect.sync(() => spy.mockRestore()),
119+
);
100120
}
101121

102122
describe("DesktopShellEnvironment", () => {
123+
it.effect("rejects PATH output from a failed shell and tries the next candidate", () =>
124+
Effect.gen(function* () {
125+
const env: NodeJS.ProcessEnv = { SHELL: "/bin/failing", PATH: "/usr/bin" };
126+
const commands: string[] = [];
127+
128+
yield* runShellEnvironment({
129+
env,
130+
platform: "linux",
131+
userShell: "/usr/local/bin/fish",
132+
handler: (command) => {
133+
if (command._tag !== "StandardCommand") return "";
134+
commands.push(command.command);
135+
return command.command === "/bin/failing"
136+
? { output: envOutput({ PATH: "/failed/bin" }), exitCode: 7 }
137+
: envOutput({ PATH: "/home/test/.local/bin:/usr/bin" });
138+
},
139+
}).pipe(Effect.provide(Logger.layer([])));
140+
141+
assert.deepEqual(commands, ["/bin/failing", "/usr/local/bin/fish"]);
142+
assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
143+
}),
144+
);
145+
146+
it.effect.each(["darwin", "linux"] as const)(
147+
"uses the account shell when SHELL is missing on %s",
148+
(platform) =>
149+
Effect.gen(function* () {
150+
const env: NodeJS.ProcessEnv = { PATH: "/usr/bin" };
151+
const commands: string[] = [];
152+
153+
yield* runShellEnvironment({
154+
env,
155+
platform,
156+
userShell: "/usr/local/bin/fish",
157+
handler: (command) => {
158+
if (command._tag !== "StandardCommand") return "";
159+
commands.push(command.command);
160+
return envOutput({ PATH: "/home/test/.local/bin:/usr/bin" });
161+
},
162+
});
163+
164+
assert.deepEqual(commands, ["/usr/local/bin/fish"]);
165+
assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
166+
}),
167+
);
168+
169+
it.effect("tries the account shell before the platform fallback when SHELL has no PATH", () =>
170+
Effect.gen(function* () {
171+
const env: NodeJS.ProcessEnv = { SHELL: "/bin/missing", PATH: "/usr/bin" };
172+
const commands: string[] = [];
173+
174+
yield* runShellEnvironment({
175+
env,
176+
platform: "linux",
177+
userShell: "/usr/local/bin/fish",
178+
handler: (command) => {
179+
if (command._tag !== "StandardCommand") return "";
180+
commands.push(command.command);
181+
return command.command === "/usr/local/bin/fish"
182+
? envOutput({ PATH: "/home/test/.local/bin:/usr/bin" })
183+
: "";
184+
},
185+
});
186+
187+
assert.deepEqual(commands, ["/bin/missing", "/usr/local/bin/fish"]);
188+
assert.equal(env.PATH, "/home/test/.local/bin:/usr/bin");
189+
}),
190+
);
191+
103192
it.effect("hydrates PATH and missing SSH_AUTH_SOCK from the login shell on macOS", () =>
104193
Effect.gen(function* () {
105194
const env: NodeJS.ProcessEnv = {

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { listLoginShellCandidates } from "@t3tools/shared/shell";
12
import * as Context from "effect/Context";
23
import * as Duration from "effect/Duration";
34
import * as Effect from "effect/Effect";
45
import * as FileSystem from "effect/FileSystem";
56
import * as Layer from "effect/Layer";
67
import * as Option from "effect/Option";
78
import * as Schema from "effect/Schema";
9+
import * as Stream from "effect/Stream";
810
import * as ChildProcess from "effect/process/ChildProcess";
911
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1012

@@ -15,7 +17,6 @@ type EnvironmentPatch = Record<string, string>;
1517
interface ShellEnvironmentConfig {
1618
readonly env: NodeJS.ProcessEnv;
1719
readonly platform: NodeJS.Platform;
18-
readonly userShell: Option.Option<string>;
1920
}
2021

2122
interface WindowsProbeOptions {
@@ -157,25 +158,6 @@ const mergePaths = (
157158
return entries.length > 0 ? Option.some(entries.join(delimiter)) : Option.none();
158159
};
159160

160-
const listLoginShellCandidates = (config: ShellEnvironmentConfig): ReadonlyArray<string> => {
161-
const fallback =
162-
config.platform === "darwin" ? "/bin/zsh" : config.platform === "linux" ? "/bin/bash" : "";
163-
const seen = new Set<string>();
164-
const candidates: string[] = [];
165-
166-
for (const candidate of [
167-
trimNonEmpty(config.env.SHELL),
168-
config.userShell,
169-
trimNonEmpty(fallback),
170-
]) {
171-
if (Option.isNone(candidate) || seen.has(candidate.value)) continue;
172-
seen.add(candidate.value);
173-
candidates.push(candidate.value);
174-
}
175-
176-
return candidates;
177-
};
178-
179161
const knownWindowsCliDirs = (env: NodeJS.ProcessEnv): ReadonlyArray<string> => [
180162
...trimNonEmpty(env.APPDATA).pipe(
181163
Option.match({
@@ -267,33 +249,49 @@ const runCommandOutput = Effect.fn("desktop.shellEnvironment.runCommandOutput")(
267249
readonly shell?: boolean;
268250
}): Effect.fn.Return<string, never, ChildProcessSpawner.ChildProcessSpawner> {
269251
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
270-
const output = yield* spawner
271-
.string(
272-
ChildProcess.make(input.command, input.args, {
273-
shell: input.shell ?? false,
274-
stdin: "ignore",
275-
stdout: "pipe",
276-
stderr: "pipe",
277-
killSignal: "SIGTERM",
278-
forceKillAfter: PROCESS_TERMINATE_GRACE,
279-
}),
280-
)
281-
.pipe(
282-
Effect.mapError(
283-
(cause) =>
284-
new DesktopShellEnvironmentCommandError({
285-
probe: input.probe,
286-
executable: executableName(input.command),
287-
argumentCount: input.args.length,
288-
cause,
289-
}),
290-
),
291-
Effect.catchTags({
292-
DesktopShellEnvironmentCommandError: (error) =>
293-
logShellEnvironmentCommandError(error).pipe(Effect.as("")),
294-
}),
295-
Effect.timeoutOption(input.timeout),
296-
);
252+
const output = yield* Effect.scoped(
253+
Effect.gen(function* () {
254+
const child = yield* spawner.spawn(
255+
ChildProcess.make(input.command, input.args, {
256+
shell: input.shell ?? false,
257+
stdin: "ignore",
258+
stdout: "pipe",
259+
stderr: "pipe",
260+
killSignal: "SIGTERM",
261+
forceKillAfter: PROCESS_TERMINATE_GRACE,
262+
}),
263+
);
264+
return yield* Effect.all([Stream.mkString(Stream.decodeText(child.stdout)), child.exitCode], {
265+
concurrency: 2,
266+
});
267+
}),
268+
).pipe(
269+
Effect.mapError(
270+
(cause) =>
271+
new DesktopShellEnvironmentCommandError({
272+
probe: input.probe,
273+
executable: executableName(input.command),
274+
argumentCount: input.args.length,
275+
cause,
276+
}),
277+
),
278+
Effect.filterOrFail(
279+
([, exitCode]) => exitCode === 0,
280+
([, exitCode]) =>
281+
new DesktopShellEnvironmentCommandError({
282+
probe: input.probe,
283+
executable: executableName(input.command),
284+
argumentCount: input.args.length,
285+
cause: { exitCode },
286+
}),
287+
),
288+
Effect.map(([stdout]) => stdout),
289+
Effect.catchTags({
290+
DesktopShellEnvironmentCommandError: (error) =>
291+
logShellEnvironmentCommandError(error).pipe(Effect.as("")),
292+
}),
293+
Effect.timeoutOption(input.timeout),
294+
);
297295
if (Option.isSome(output)) {
298296
return output.value;
299297
}
@@ -406,7 +404,7 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
406404
const fileSystem = yield* FileSystem.FileSystem;
407405
const shellEnvironment: EnvironmentPatch = {};
408406

409-
for (const shell of listLoginShellCandidates(config)) {
407+
for (const shell of listLoginShellCandidates(config.platform, config.env.SHELL)) {
410408
Object.assign(
411409
shellEnvironment,
412410
yield* readLoginShellEnvironment(shell, LOGIN_SHELL_ENV_NAMES),
@@ -521,7 +519,6 @@ export const make = Effect.gen(function* () {
521519
installShellEnvironment({
522520
env: process.env,
523521
platform: environment.platform,
524-
userShell: Option.none(),
525522
}).pipe(
526523
Effect.provideService(FileSystem.FileSystem, fileSystem),
527524
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),

0 commit comments

Comments
 (0)