Skip to content

Commit d8d01fb

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-29175
2 parents d53e9f2 + 47f2c8d commit d8d01fb

4 files changed

Lines changed: 98 additions & 38 deletions

File tree

‎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/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,45 @@ const TASK_ID = ScheduledTaskId.make("task-1");
217217
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
218218

219219
describe("MessagesTimeline work rows", () => {
220+
it("keeps the worked-for heading in place when expanded at the bottom", async () => {
221+
const props = baseProps();
222+
const runId = RunId.make("completed-run");
223+
const container = document.createElement("div");
224+
container.style.cssText = "height: 600px; width: 900px; display: flex; flex-direction: column;";
225+
await using screen = await render(
226+
<MessagesTimeline
227+
{...props}
228+
timelineEntries={[
229+
...Array.from({ length: 12 }, (_, index) =>
230+
message(`Earlier context ${index}`, {}, `context-${index}`),
231+
),
232+
message("Progress details\n\n".repeat(50), { role: "assistant", runId }, "progress"),
233+
message("Done", { role: "assistant", runId }, "final"),
234+
]}
235+
/>,
236+
{ container },
237+
);
238+
const heading = screen.getByRole("button", { name: /^Worked for/ });
239+
await expect.element(heading).toBeVisible();
240+
const viewport = props.listRef.current!.getScrollableNode()!;
241+
await vi.waitFor(() =>
242+
expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeLessThan(2),
243+
);
244+
expect(viewport.scrollTop).toBeGreaterThan(0);
245+
const top = heading.element().getBoundingClientRect().top;
246+
const height = viewport.scrollHeight;
247+
using _timers = fakeTimers();
248+
await heading.click();
249+
await act(() => vi.advanceTimersByTime(1000));
250+
await vi.waitFor(() => {
251+
expect(viewport.scrollHeight).toBeGreaterThan(height + 500);
252+
expect(heading.element().getBoundingClientRect().top).toBeCloseTo(top, 0);
253+
expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeGreaterThan(
254+
500,
255+
);
256+
});
257+
});
258+
220259
it.each(["delegated", "legacy", "missing"] as const)(
221260
"uses the reported task for %s completion notifications",
222261
async (source) => {

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,6 @@ const ConversationTimeline = memo(function ConversationTimeline({
470470
const normalizedFindQuery = findQuery.trim();
471471
const findActive = findExpanded;
472472

473-
const disclosurePinsEndRef = useRef(false);
474-
const pinDisclosureToEnd = () => {
475-
if (!disclosurePinsEndRef.current) return;
476-
const element = listRef.current?.getScrollableNode();
477-
if (element) element.scrollTop = element.scrollHeight;
478-
};
479-
480473
const scheduleDisclosureSettle = () => {
481474
if (disclosureSettleFrameRef.current !== null) {
482475
cancelAnimationFrame(disclosureSettleFrameRef.current);
@@ -485,10 +478,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
485478
cancelAnimationFrame(disclosureSettleSecondFrameRef.current);
486479
}
487480
disclosureSettleFrameRef.current = requestAnimationFrame(() => {
488-
pinDisclosureToEnd();
489481
disclosureSettleSecondFrameRef.current = requestAnimationFrame(() => {
490-
pinDisclosureToEnd();
491-
disclosurePinsEndRef.current = false;
492482
disclosureAnchorKeyRef.current = null;
493483
setDisclosureToggleSettling(false);
494484
disclosureSettleFrameRef.current = null;
@@ -499,13 +489,11 @@ const ConversationTimeline = memo(function ConversationTimeline({
499489

500490
const suspendEndScrollMaintenanceForDisclosure = (anchorKey: string) => {
501491
disclosureAnchorKeyRef.current = anchorKey;
502-
disclosurePinsEndRef.current = resolveTimelineIsAtEnd(listRef.current?.getState()) === true;
503492
setDisclosureToggleSettling(true);
504493
scheduleDisclosureSettle();
505494
};
506495

507496
const shouldRestoreVisibleContentPosition = (row: MessagesTimelineRow) => {
508-
if (disclosurePinsEndRef.current) return false;
509497
const disclosureAnchorKey = disclosureAnchorKeyRef.current;
510498
return disclosureAnchorKey === null || row.id === disclosureAnchorKey;
511499
};
@@ -955,8 +943,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
955943
};
956944

957945
const handleItemSizeChanged = () => {
958-
if (disclosurePinsEndRef.current) {
959-
queueMicrotask(pinDisclosureToEnd);
946+
if (disclosureAnchorKeyRef.current !== null) {
960947
scheduleDisclosureSettle();
961948
}
962949
scheduleMinimapRefresh();

0 commit comments

Comments
 (0)