Skip to content

Commit e11f923

Browse files
committed
fix(web): show details for background commands
- Preserve command and source item details for Claude background tasks - Show full commands and captured output in the background work dialog
1 parent ee59ab2 commit e11f923

7 files changed

Lines changed: 266 additions & 5 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10049,6 +10049,32 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1004910049
attachments: [],
1005010050
}),
1005110051
);
10052+
yield* Queue.offer(
10053+
harness.sdkMessages,
10054+
claudeSdkFrame({
10055+
type: "assistant",
10056+
message: {
10057+
model: "claude-sonnet-4-6",
10058+
id: "msg_background_command",
10059+
type: "message",
10060+
role: "assistant",
10061+
content: [
10062+
{
10063+
type: "tool_use",
10064+
id: WAKE_TOOL_USE_ID,
10065+
name: "Bash",
10066+
input: {
10067+
command: "python3 audit.py > audit.log 2>&1",
10068+
run_in_background: true,
10069+
},
10070+
},
10071+
],
10072+
},
10073+
parent_tool_use_id: null,
10074+
uuid: "background-command-launch",
10075+
session_id: WAKE_NATIVE_SESSION,
10076+
}),
10077+
);
1005210078
yield* Queue.offer(harness.sdkMessages, wakeTaskStarted);
1005310079
yield* Queue.offer(harness.sdkMessages, turnOneResult);
1005410080
yield* harness.awaitTerminal(1);
@@ -10062,6 +10088,37 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1006210088
WAKE_TASK_ID,
1006310089
);
1006410090

10091+
const command = harness.events.find(
10092+
(event) =>
10093+
event.type === "turn_item.updated" &&
10094+
event.turnItem.type === "command_execution" &&
10095+
event.turnItem.nativeItemRef?.nativeId === WAKE_TOOL_USE_ID,
10096+
);
10097+
assert.equal(command?.type, "turn_item.updated");
10098+
if (command?.type !== "turn_item.updated") return;
10099+
const details = {
10100+
command: "python3 audit.py > audit.log 2>&1",
10101+
itemId: command.turnItem.id,
10102+
};
10103+
assert.deepInclude(
10104+
afterStart.at(-1)?.providerThread.pendingBackgroundTasks?.[0],
10105+
details,
10106+
);
10107+
yield* harness.offerAndWait(
10108+
claudeSdkFrame({
10109+
type: "system",
10110+
subtype: "background_tasks_changed",
10111+
tasks: [{ task_id: WAKE_TASK_ID, task_type: "local_bash", description: "Audit" }],
10112+
uuid: "background-command-snapshot",
10113+
session_id: WAKE_NATIVE_SESSION,
10114+
}),
10115+
);
10116+
assert.deepInclude(
10117+
providerThreadRosterEvents(harness.events).at(-1)?.providerThread
10118+
.pendingBackgroundTasks?.[0],
10119+
details,
10120+
);
10121+
1006510122
yield* Queue.offer(
1006610123
harness.sdkMessages,
1006710124
claudeSdkFrame({

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,7 +5777,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
57775777
} else {
57785778
updated.set(
57795779
nativeThreadId,
5780-
new Map(tasks.map((task) => [task.taskId, task] as const)),
5780+
new Map(
5781+
tasks.map((task) => {
5782+
const previous = current.get(nativeThreadId)?.get(task.taskId);
5783+
return [task.taskId, { ...previous, ...task }] as const;
5784+
}),
5785+
),
57815786
);
57825787
}
57835788
return updated;
@@ -8719,9 +8724,26 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
87198724
if (!isClaudeNonSubagentTask(message) || message.is_backgrounded === false) {
87208725
return false;
87218726
}
8722-
yield* upsertPendingBackgroundTask(
8723-
input.nativeThreadId,
8724-
claudePendingBackgroundTask({
8727+
const launch =
8728+
message.tool_use_id === undefined || input.activeContext === null
8729+
? undefined
8730+
: findToolCall(input.activeContext, message.tool_use_id);
8731+
const command =
8732+
launch?.classification.itemType === "command_execution"
8733+
? firstStringInputField(launch.input, ["command"])
8734+
: undefined;
8735+
yield* upsertPendingBackgroundTask(input.nativeThreadId, {
8736+
...(launch === undefined || command === undefined
8737+
? {}
8738+
: {
8739+
itemId: idAllocator.derive.turnItemFromProviderItem({
8740+
driver: CLAUDE_PROVIDER,
8741+
nativeItemId: launch.nativeItemId,
8742+
}),
8743+
sourceThreadId: launch.threadId,
8744+
}),
8745+
...(command === undefined ? {} : { command }),
8746+
...claudePendingBackgroundTask({
87258747
taskId: message.task_id,
87268748
taskType: claudeTaskTypeFromSdkMessage(message),
87278749
startedByMonitor: yield* isClaudeMonitorTask({
@@ -8733,7 +8755,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
87338755
typeof message.description === "string" ? message.description : undefined,
87348756
parentTaskId: Reflect.get(message, "parent_task_id"),
87358757
}),
8736-
);
8758+
});
87378759
rosterChanged = true;
87388760
} else if (message.type === "system" && message.subtype === "task_notification") {
87398761
yield* endClaudeMonitorTasks((taskId) => taskId === message.task_id);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import "~/index.css";
2+
import { EnvironmentId, ThreadId, TurnItemId } from "@t3tools/contracts";
3+
import * as DateTime from "effect/DateTime";
4+
import { expect, it, vi } from "vite-plus/test";
5+
import { page } from "vite-plus/test/browser";
6+
vi.mock(import("./CommandOutputPanel"), () => ({
7+
useCommandOutputStreaming: () => true,
8+
CommandOutputPanel: () => <div>Command output stream</div>,
9+
}));
10+
11+
import { render } from "../../../test/render";
12+
import { backgroundWorkNowItem } from "./ThreadActivityBanners";
13+
import { ThreadNow } from "./ThreadNow";
14+
15+
it("opens full command details for short labels and keeps pending tasks current", async () => {
16+
const command = "python3 audit.py -j 6\n> scratch/audit.log 2>&1";
17+
const view = (description?: string, status: "running" | "completed" = "completed") => (
18+
<ThreadNow
19+
attention={null}
20+
syncPhase={null}
21+
goal={null}
22+
work={backgroundWorkNowItem({
23+
environmentId: EnvironmentId.make("test"),
24+
threadId: ThreadId.make("thread"),
25+
tasks: [{ taskId: "bash-1", kind: "command", description, command, awaited: true }],
26+
turnItems: [
27+
{
28+
id: TurnItemId.make("bash-1"),
29+
threadId: ThreadId.make("thread"),
30+
runId: null,
31+
nodeId: null,
32+
providerThreadId: null,
33+
providerTurnId: null,
34+
nativeItemRef: null,
35+
parentItemId: null,
36+
ordinal: 1,
37+
status,
38+
title: null,
39+
startedAt: null,
40+
completedAt: null,
41+
updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
42+
type: "command_execution",
43+
input: command,
44+
output: "Command running in background with ID: bash-1",
45+
},
46+
],
47+
stopDisabled: false,
48+
stopping: false,
49+
onStop: async () => undefined,
50+
onOpenThread: () => undefined,
51+
})}
52+
/>
53+
);
54+
await using screen = await render(view("Audit"));
55+
await screen.getByRole("button", { name: "Details", exact: true }).click();
56+
await vi.waitFor(() => expect(page.getByRole("dialog").element().textContent).toContain(command));
57+
await expect.element(page.getByText("Command output stream")).not.toBeInTheDocument();
58+
59+
await screen.rerender(view(command));
60+
await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
61+
await screen.rerender(view());
62+
await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
63+
64+
await screen.rerender(view("Check remaining modules", "running"));
65+
await expect
66+
.element(page.getByRole("heading", { name: "Check remaining modules" }))
67+
.toBeVisible();
68+
await expect.element(page.getByText("Command output stream")).toBeVisible();
69+
await page.getByRole("button", { name: "Close", exact: true }).click();
70+
await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
71+
});
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import type {
2+
EnvironmentId,
3+
OrchestrationV2PendingBackgroundTask,
4+
ThreadId,
5+
} from "@t3tools/contracts";
6+
import type { ThreadStructure } from "@t3tools/client-runtime/state/shell";
7+
import { useState } from "react";
8+
9+
import { InlineButton } from "../ui/button";
10+
import {
11+
Dialog,
12+
DialogHeader,
13+
DialogPanel,
14+
DialogPopup,
15+
DialogTitle,
16+
DialogTrigger,
17+
} from "../ui/dialog";
18+
import { CommandOutputPanel, useCommandOutputStreaming } from "./CommandOutputPanel";
19+
import { ShellCommandBlock } from "./ShellCommandBlock";
20+
21+
export function BackgroundWorkDetails(props: {
22+
readonly environmentId: EnvironmentId;
23+
readonly threadId: ThreadId;
24+
readonly tasks: ReadonlyArray<OrchestrationV2PendingBackgroundTask>;
25+
readonly turnItems: ThreadStructure["turnItems"];
26+
readonly onOpenThread: (threadId: ThreadId) => void;
27+
}) {
28+
const [open, setOpen] = useState(false);
29+
const streamsOutput = useCommandOutputStreaming(props.environmentId);
30+
return (
31+
<Dialog open={open} onOpenChange={setOpen}>
32+
<DialogTrigger render={<InlineButton />}>Details</DialogTrigger>
33+
<DialogPopup>
34+
<DialogHeader>
35+
<DialogTitle>Background work</DialogTitle>
36+
</DialogHeader>
37+
<DialogPanel>
38+
<div className="space-y-5">
39+
{props.tasks.map((task) => {
40+
const item = props.turnItems.findLast(
41+
(candidate) =>
42+
candidate.id === task.itemId ||
43+
(candidate.nativeItemRef?.nativeId || candidate.id) === task.taskId,
44+
);
45+
const command =
46+
task.command ?? (item?.type === "command_execution" ? item.input : undefined);
47+
const description = task.description?.trim();
48+
const title =
49+
description && description !== command?.trim()
50+
? description
51+
: command
52+
? "Command"
53+
: task.kind.replaceAll("_", " ");
54+
const itemId =
55+
task.itemId ?? (item?.type === "command_execution" ? item.id : undefined);
56+
const childThreadId = task.kind === "subagent" ? task.childThreadId : undefined;
57+
return (
58+
<section key={task.taskId} className="space-y-2 text-sm">
59+
<div className="flex items-baseline justify-between gap-3">
60+
<h3 className="font-medium">{title}</h3>
61+
<span className="shrink-0 text-xs text-muted-foreground">
62+
{task.awaited ? "Waiting" : "Running"}
63+
</span>
64+
</div>
65+
{command ? (
66+
<div className="rounded-md border border-border bg-muted/20 p-3 font-mono text-xs whitespace-pre-wrap break-words">
67+
<ShellCommandBlock command={command} />
68+
</div>
69+
) : null}
70+
{itemId && streamsOutput && item?.status === "running" ? (
71+
<div className="space-y-1 font-mono text-xs whitespace-pre-wrap break-words">
72+
<p className="font-sans text-muted-foreground">Captured output</p>
73+
<CommandOutputPanel
74+
environmentId={props.environmentId}
75+
threadId={task.sourceThreadId ?? item?.threadId ?? props.threadId}
76+
itemId={itemId}
77+
/>
78+
</div>
79+
) : null}
80+
{childThreadId ? (
81+
<InlineButton
82+
onClick={() => {
83+
setOpen(false);
84+
props.onOpenThread(childThreadId);
85+
}}
86+
>
87+
Open thread
88+
</InlineButton>
89+
) : null}
90+
</section>
91+
);
92+
})}
93+
</div>
94+
</DialogPanel>
95+
</DialogPopup>
96+
</Dialog>
97+
);
98+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from "lucide-react";
2828
import { Fragment } from "react";
2929
import { tickTextContent } from "~/lib/tickTextContent";
30+
import { BackgroundWorkDetails } from "./BackgroundWorkDetails";
3031
import { Button, InlineButton } from "../ui/button";
3132
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
3233
import type { ComposerBannerStackItem } from "./ComposerBannerStack";
@@ -168,6 +169,7 @@ export function runStopNowItem(input: {
168169

169170
/** Background commands and subagents, for the end of the timeline. */
170171
export function backgroundWorkNowItem(input: {
172+
readonly environmentId: EnvironmentId;
171173
readonly threadId: ThreadId;
172174
readonly tasks: ReadonlyArray<OrchestrationV2PendingBackgroundTask>;
173175
readonly turnItems: ThreadStructure["turnItems"];
@@ -246,6 +248,13 @@ export function backgroundWorkNowItem(input: {
246248
className="tabular-nums"
247249
/>
248250
)}
251+
<BackgroundWorkDetails
252+
environmentId={input.environmentId}
253+
threadId={input.threadId}
254+
tasks={input.tasks}
255+
turnItems={input.turnItems}
256+
onOpenThread={onOpenThread}
257+
/>
249258
{onlyThreadId === undefined ? null : (
250259
<InlineButton tone="muted" onClick={() => onOpenThread(onlyThreadId)}>
251260
Open

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
596596
: null;
597597
const backgroundWorkNow = activeThread
598598
? backgroundWorkNowItem({
599+
environmentId,
599600
threadId: activeThread.id,
600601
tasks: activeBackgroundTasks,
601602
turnItems,

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,9 @@ function kindUnionWithFallback<
10231023
}
10241024

10251025
const PendingBackgroundTaskFields = {
1026+
command: Schema.optional(Schema.String),
1027+
itemId: Schema.optional(TurnItemId),
1028+
sourceThreadId: Schema.optional(ThreadId),
10261029
taskId: TrimmedNonEmptyString,
10271030
description: Schema.optional(TrimmedNonEmptyString),
10281031
/** The subagent task that started this work and waits on it. */

0 commit comments

Comments
 (0)