Skip to content

Commit 70dd3c5

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/remove-image-preview-tooltip
2 parents 72d0b20 + 47f2c8d commit 70dd3c5

11 files changed

Lines changed: 198 additions & 229 deletions

‎apps/server/src/provider/Drivers/ClaudeHome.test.ts‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,44 @@ it.layer(NodeServices.layer)("ClaudeHome", (it) => {
5959
);
6060
});
6161

62-
it.effect("labels Claude processes t3-code unless instance env or Claude settings set one", () =>
63-
Effect.gen(function* () {
64-
const fileSystem = yield* FileSystem.FileSystem;
65-
const path = yield* Path.Path;
66-
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
67-
const host = { CLAUDE_CODE_ENTRYPOINT: "claude-desktop", KEEP: "1" };
68-
const instance = [{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false }];
62+
it.effect(
63+
"drops the launching Claude session and labels processes t3-code unless overridden",
64+
() =>
65+
Effect.gen(function* () {
66+
const fileSystem = yield* FileSystem.FileSystem;
67+
const path = yield* Path.Path;
68+
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
69+
const host = {
70+
CLAUDE_CODE_ENTRYPOINT: "claude-desktop",
71+
CLAUDECODE: "1",
72+
CLAUDE_CODE_SESSION_ID: "host-session",
73+
CLAUDE_CODE_MESSAGING_SOCKET: "/tmp/host-claude.sock",
74+
CLAUDE_EFFORT: "high",
75+
KEEP: "1",
76+
};
77+
const instance = [
78+
{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false },
79+
{ name: "CLAUDE_EFFORT", value: "low", sensitive: false },
80+
];
6981

70-
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toMatchObject({
71-
CLAUDE_CODE_ENTRYPOINT: "t3-code",
72-
KEEP: "1",
73-
});
74-
expect(
75-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
76-
).toBe("instance");
82+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toEqual({
83+
CLAUDE_CODE_ENTRYPOINT: "t3-code",
84+
KEEP: "1",
85+
});
86+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).toEqual({
87+
CLAUDE_CODE_ENTRYPOINT: "instance",
88+
CLAUDE_EFFORT: "low",
89+
KEEP: "1",
90+
});
7791

78-
yield* fileSystem.writeFileString(
79-
path.join(homePath, "settings.json"),
80-
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
81-
);
82-
expect(
83-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
84-
).toBe("custom");
85-
}),
92+
yield* fileSystem.writeFileString(
93+
path.join(homePath, "settings.json"),
94+
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
95+
);
96+
expect(
97+
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host))
98+
.CLAUDE_CODE_ENTRYPOINT,
99+
).toBe("custom");
100+
}),
86101
);
87102
});

‎apps/server/src/provider/Drivers/ClaudeHome.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function
4545
};
4646
});
4747

48+
// A Claude Code session that launched T3 exports these. A claude spawned with them acts as part of
49+
// that session: its session id, messaging socket and token, and effort.
50+
const CLAUDE_HOST_SESSION_VARIABLES = [
51+
"CLAUDECODE",
52+
"CLAUDE_CODE_SESSION_ID",
53+
"CLAUDE_CODE_HOST_SESSION_ID",
54+
"CLAUDE_CODE_CHILD_SESSION",
55+
"CLAUDE_CODE_SESSION_ATTENDED",
56+
"CLAUDE_CODE_MESSAGING_SOCKET",
57+
"CLAUDE_CODE_MESSAGING_TOKEN",
58+
"CLAUDE_CODE_EXECPATH",
59+
"CLAUDE_CODE_DESKTOP_APP_VERSION",
60+
"CLAUDE_EFFORT",
61+
"CLAUDE_PID",
62+
"CLAUDE_AGENT_SDK_VERSION",
63+
];
64+
4865
/**
4966
* Base env for the Claude processes T3 Code runs, before `makeClaudeEnvironment`.
5067
* Claude Code reads its entrypoint from the process env, not its settings `env`, so T3 Code applies that override itself.
@@ -54,10 +71,12 @@ export const mergeClaudeProcessEnvironment = Effect.fn("mergeClaudeProcessEnviro
5471
instanceEnvironment: ProviderInstanceEnvironment | undefined,
5572
hostEnvironment: NodeJS.ProcessEnv,
5673
) {
57-
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, {
74+
const baseEnvironment: NodeJS.ProcessEnv = {
5875
...hostEnvironment,
5976
CLAUDE_CODE_ENTRYPOINT: "t3-code",
60-
});
77+
};
78+
for (const name of CLAUDE_HOST_SESSION_VARIABLES) delete baseEnvironment[name];
79+
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, baseEnvironment);
6180
const settingsEntrypoint = (yield* readClaudeSettingsEnv(config, undefined, environment))
6281
.CLAUDE_CODE_ENTRYPOINT;
6382
return settingsEntrypoint

‎apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { WORKING_EXIT_GRACE_MS } from "@t3tools/client-runtime/state/thread-inbox";
21
import type { AnyRouter } from "@tanstack/react-router";
32
import { EnvironmentId } from "@t3tools/contracts";
43
import * as DateTime from "effect/DateTime";
54
import * as Option from "effect/Option";
65
import { Atom, AtomRegistry } from "effect/reactivity";
76
import { expect, it, vi } from "vite-plus/test";
87

9-
import { fakeTimers, stubGlobal } from "../../test/render";
8+
import { stubGlobal } from "../../test/render";
109

1110
const state = vi.hoisted(() => ({
1211
mode: "notifications",
@@ -241,24 +240,18 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
241240
},
242241
);
243242

244-
it("holds a completion through a continuation gap and notifies once it settles", async () => {
243+
it("presents completion notifications and sound as soon as the shell completes", async () => {
245244
await using app = setup();
245+
state.mode = "notifications-and-sound";
246246
app.start();
247-
using _timers = fakeTimers();
248-
const finished = (turnId: string, completedAt: string) => ({
249-
latestTurn: { turnId, state: "completed", completedAt },
250-
});
251-
state.shells.set("one", shell(finished("turn-1", "2026-09-13T07:00:01.000Z")));
252247
state.shells.set(
253248
"one",
254-
shell({ latestTurn: { turnId: "turn-2", state: "running", completedAt: null } }),
249+
shell({
250+
latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:00:01.000Z" },
251+
}),
255252
);
256-
state.shells.set("one", shell(finished("turn-2", "2026-09-13T07:00:02.000Z")));
257-
expect(TestNotification.sent).toEqual([]);
258-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS - 1);
259-
expect(TestNotification.sent).toEqual([]);
260-
await vi.advanceTimersByTimeAsync(1);
261253
expect(TestNotification.sent.map((sent) => sent.title)).toEqual(["Thread completed"]);
254+
expect(state.sound).toHaveBeenCalledWith("completion", expect.any(Function));
262255
});
263256

264257
it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
@@ -277,7 +270,6 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
277270
};
278271
state.shells.set("one", shell({ id: "working" }, { id: "asking" }, { id: "offline" }, done));
279272
app.start();
280-
using _timers = fakeTimers();
281273
state.shells.set("one", shell({ id: "working" }, asking, { id: "offline" }, done));
282274
state.shells.set("one", {
283275
...shell({ id: "working" }, asking, { id: "offline" }, done),
@@ -296,37 +288,31 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
296288

297289
expect(TestNotification.sent.map(({ title }) => title)).toEqual([
298290
"Approval needed",
291+
"Thread completed",
299292
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
300293
]);
301-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
302294
state.shells.set("one", { ...shell(completed, asking, offline, done), status: "cached" });
303295
state.shells.set("one", shell(completed, asking, offline, done));
304-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
305296
expect(TestNotification.sent.map(({ title }) => title)).toEqual([
306297
"Approval needed",
307-
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
308298
"Thread completed",
299+
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
309300
]);
310301
},
311302
);
312303

313304
it.each([false, true])(
314-
"rechecks a pending completion after reconnect (continued: %s)",
305+
"does not replay a notified completion after reconnect (continued: %s)",
315306
async (continued) => {
316307
await using app = setup();
317308
app.start();
318-
using _timers = fakeTimers();
319309
const completed = shell({
320310
latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:05:00.000Z" },
321311
});
322312
state.shells.set("one", completed);
323313
state.shells.set("one", { ...completed, status: "cached" });
324-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
325-
expect(TestNotification.sent).toEqual([]);
314+
expect(TestNotification.sent.map(({ title }) => title)).toEqual(["Thread completed"]);
326315
state.shells.set("one", continued ? shell() : completed);
327-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
328-
expect(TestNotification.sent.map(({ title }) => title)).toEqual(
329-
continued ? [] : ["Thread completed"],
330-
);
316+
expect(TestNotification.sent.map(({ title }) => title)).toEqual(["Thread completed"]);
331317
},
332318
);

0 commit comments

Comments
 (0)