The best way to control Claude Code, Codex and more from any computer or phone
feat(web): pending approvals show on their timeline row (#26255)
maria committed
Oct 28, 2026 at 06:03 UTC
1f8530ec3c4676b11badd9d67884ca0d3e85a7f1
14 files changed
+546
-185
apps/web/src/components/ChatView.tsx
+13
-1
@@ -115,6 +115,7 @@ import { useLocation, useNavigate } from "@tanstack/react-router";
115
import { assistantCitationFromLocation } from "../lib/assistantCitationNavigation";
116
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
117
import { useStore } from "zustand";
118
+import { shallow } from "zustand/vanilla/shallow";
119
import { useShallow } from "zustand/react/shallow";
120
import {
121
isAtomCommandInterrupted,
@@ -1314,6 +1315,12 @@ export default function ChatView(props: ChatViewProps) {
1315
composerRef,
1316
setThreadError,
1317
});
1318
+ const [heldApprovalRequestIds, setHeldApprovalRequestIds] = useState<ReadonlySet<string>>(
1319
+ () => new Set(),
1320
+ );
1321
+ const onHeldRequestIdsChange = useStableCallback((requestIds: ReadonlySet<string>) => {
1322
+ setHeldApprovalRequestIds((current) => (shallow(current, requestIds) ? current : requestIds));
1323
+ });
1324
const activeProposedPlan = (() => {
1325
if (!latestRunSettled) {
1326
return null;
@@ -3245,6 +3252,11 @@ export default function ChatView(props: ChatViewProps) {
3252
className="relative flex min-h-0 flex-1 flex-col bg-background"
3253
>
3254
<ThreadTimeline
3255
+ pendingApprovals={pendingApprovals}
3256
+ heldApprovalRequestIds={heldApprovalRequestIds}
3257
+ respondingRequestIds={respondingRequestIds}
3258
+ onRespondToApproval={onRespondToApprovalStable}
3259
+ canOperateThread={canOperateThread}
3260
threadDetailRef={routeThreadDetailRef}
3261
entriesInput={timelineEntriesInput}
3262
draftEntries={isServerThread ? null : draftTimelineEntries}
@@ -3489,6 +3501,7 @@ export default function ChatView(props: ChatViewProps) {
3501
environmentUnavailable={activeEnvironmentUnavailableState}
3502
activePendingApproval={activePendingApproval}
3503
pendingApprovals={pendingApprovals}
3504
+ onHeldRequestIdsChange={onHeldRequestIdsChange}
3505
pendingUserInputs={pendingUserInputs}
3506
activePendingProgress={activePendingProgress}
3507
activePendingResolvedAnswers={activePendingResolvedAnswers}
@@ -3550,7 +3563,6 @@ export default function ChatView(props: ChatViewProps) {
3563
onResume={onComposerResumeStable}
3564
onInterrupt={onInterruptStable}
3565
onImplementPlanInNewThread={onImplementPlanInNewThreadStable}
3553
- onRespondToApproval={onRespondToApprovalStable}
3566
onSelectActivePendingUserInputOption={
3567
onSelectActivePendingUserInputOptionStable
3568
}
apps/web/src/components/chat/ChatComposer.tsx
+12
-46
@@ -20,7 +20,6 @@ import type {
20
ModelSelection,
21
ProjectId,
22
PreviewAnnotationPayload,
23
- ProviderApprovalDecision,
23
ThreadContextRecord,
24
EnvironmentContextRecord,
25
ProviderInteractionMode,
@@ -187,7 +186,6 @@ import {
186
ComposerCommandMenu,
187
composerSuggestionOptionId,
188
} from "./ComposerCommandMenu";
190
-import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
189
import {
190
ComposerAttachButton,
191
ComposerAttachmentFileList,
@@ -198,7 +196,6 @@ import {
196
} from "./ComposerAttachmentStrip";
197
import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
198
import { ComposerFooterPrimaryActions } from "./ComposerFooterControls";
201
-import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
199
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
200
import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner";
201
import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight";
@@ -239,7 +236,7 @@ const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidErro
236
const COMPOSER_SCROLL_COLLAPSE_THRESHOLD_PX = 24;
237
const COMPOSER_SCROLL_GESTURE_RESET_MS = 120;
238
import { toastManager } from "../ui/toast";
242
-import { PlayIcon, ShieldIcon } from "lucide-react";
239
+import { PlayIcon } from "lucide-react";
240
import { proposedPlanTitle } from "@t3tools/shared/proposedPlanText";
241
import { hasProviderSetup } from "./ProviderStatusBanner";
242
import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelSelection";
@@ -402,6 +399,7 @@ export interface ChatComposerProps {
399
400
activePendingApproval: PendingApproval | null;
401
pendingApprovals: PendingApproval[];
402
+ onHeldRequestIdsChange: (requestIds: ReadonlySet<string>) => void;
403
pendingUserInputs: PendingUserInput[];
404
activePendingProgress: {
405
questionIndex: number;
@@ -482,10 +480,6 @@ export interface ChatComposerProps {
480
onResume: () => void;
481
onInterrupt: () => void;
482
onImplementPlanInNewThread: () => void;
485
- onRespondToApproval: (
486
- requestId: RuntimeRequestId,
487
- decision: ProviderApprovalDecision,
488
- ) => Promise<unknown>;
483
onSelectActivePendingUserInputOption: (questionId: string, optionValue: string) => void;
484
onAdvanceActivePendingUserInput: () => void;
485
onDismissActivePendingUserInput: (requestId: RuntimeRequestId) => void;
@@ -550,6 +544,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
544
environmentUnavailable,
545
activePendingApproval: incomingPendingApproval,
546
pendingApprovals,
547
+ onHeldRequestIdsChange,
548
pendingUserInputs: incomingPendingUserInputs,
549
activePendingProgress: incomingPendingProgress,
550
activePendingResolvedAnswers,
@@ -601,7 +596,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
596
onResume,
597
onInterrupt,
598
onImplementPlanInNewThread,
604
- onRespondToApproval,
599
onSelectActivePendingUserInputOption,
600
onAdvanceActivePendingUserInput,
601
onDismissActivePendingUserInput,
@@ -633,6 +627,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
627
...pendingApprovals.map((request) => request.requestId),
628
...incomingPendingUserInputs.map((request) => request.requestId),
629
]);
630
+ // A layout effect so the timeline never paints a held approval as answerable.
631
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- publishes held requests to the timeline without lifting per-keystroke typing state
632
+ useLayoutEffect(() => {
633
+ onHeldRequestIdsChange(heldRequestIds);
634
+ }, [heldRequestIds, onHeldRequestIdsChange]);
635
const activePendingApproval =
636
incomingPendingApproval && !heldRequestIds.has(incomingPendingApproval.requestId)
637
? incomingPendingApproval
@@ -1200,7 +1199,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
1199
const isChoiceOnlyPendingQuestion =
1200
activePendingProgress?.activeQuestion?.allowCustomAnswer === false;
1201
const showComposerTopDrawer =
1203
- isComposerApprovalState ||
1202
pendingUserInputs.length > 0 ||
1203
(!isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan !== null);
1204
const showCollapsedMobilePromptRow = isComposerCollapsedMobile;
@@ -2320,8 +2318,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2318
importContextRecords,
2319
expandMobileComposer: expandMobileComposerStable,
2320
});
2323
- const hasBlockingComposerTopDrawer =
2324
- activePendingApproval !== null || pendingUserInputs.length > 0;
2321
+ const hasBlockingComposerTopDrawer = pendingUserInputs.length > 0;
2322
const hasImageAttachmentAttention = standaloneComposerImages.some((image) => {
2323
const upload = uploadsByImageId[image.id];
2324
const failedInCurrentEnvironment =
@@ -2580,7 +2577,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2577
getModelDisabledReason={getModelDisabledReason}
2578
/>
2579
);
2583
- // An open approval or question owns the space above the composer. Only a machine problem,
2580
+ // An open question owns the space above the composer. Only a machine problem,
2581
// which is why an answer could not go through, stays beside it.
2582
const shelfItems = hasBlockingComposerTopDrawer
2583
? props.bannerItems.filter(
@@ -3444,39 +3441,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3441
<ComposerBannerStack items={shelfItems} />
3442
{showComposerTopDrawer ? (
3443
<ComposerBanner.Attachment>
3447
- <ComposerBanner.Root
3448
- data-chat-composer-top-drawer="true"
3449
- variant={activePendingApproval ? "warning" : "info"}
3450
- density={activePendingApproval ? "spacious" : "default"}
3451
- >
3452
- {activePendingApproval ? (
3453
- <ComposerBanner.Row
3454
- layout="approval"
3455
- data-chat-composer-collapsed-controls="true"
3456
- >
3457
- <ComposerBanner.Icon>
3458
- <ShieldIcon />
3459
- </ComposerBanner.Icon>
3460
- <ComposerBanner.Content>
3461
- <ComposerPendingApprovalPanel
3462
- approval={activePendingApproval}
3463
- pendingCount={pendingApprovals.length}
3464
- />
3465
- </ComposerBanner.Content>
3466
- <ComposerBanner.Actions>
3467
- <ComposerPendingApprovalActions
3468
- requestId={activePendingApproval.requestId}
3469
- disabled={!canOperateThread}
3470
- isResponding={respondingRequestIds.includes(
3471
- activePendingApproval.requestId,
3472
- )}
3473
- options={activePendingApproval.options}
3474
- canRespond={activePendingApproval.responseCapability === "live"}
3475
- onRespondToApproval={onRespondToApproval}
3476
- />
3477
- </ComposerBanner.Actions>
3478
- </ComposerBanner.Row>
3479
- ) : pendingUserInputs.length > 0 ? (
3444
+ <ComposerBanner.Root data-chat-composer-top-drawer="true" variant="info">
3445
+ {pendingUserInputs.length > 0 ? (
3446
<ComposerPendingUserInputPanel
3447
pendingUserInputs={pendingUserInputs}
3448
cwd={gitCwd ?? undefined}
apps/web/src/components/chat/ComposerPendingApprovalActions.tsx
+48
-21
@@ -5,12 +5,13 @@ import {
5
} from "@t3tools/contracts";
6
import { memo } from "react";
7
import { EllipsisIcon, TriangleAlertIcon } from "lucide-react";
8
-import { Button } from "../ui/button";
8
+import { Button, InlineButton } from "../ui/button";
9
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
10
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
11
import { composerFloatingLayerProps } from "./composerEventScope";
12
13
interface ComposerPendingApprovalActionsProps {
14
+ presentation?: "composer" | "inline";
15
requestId: RuntimeRequestId;
16
isResponding: boolean;
17
canRespond: boolean;
@@ -30,6 +31,7 @@ const DEFAULT_APPROVAL_OPTIONS = [
31
] satisfies ReadonlyArray<ProviderApprovalOption>;
32
33
export const ComposerPendingApprovalActions = memo(function ComposerPendingApprovalActions({
34
+ presentation = "composer",
35
requestId,
36
isResponding,
37
canRespond,
@@ -47,23 +49,42 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
49
return (
50
<>
51
{primaryOptions.map((option) => {
50
- const button = (
51
- <Button
52
- key={option.decision}
53
- size="xs"
54
- variant={option.decision === "accept" ? "default" : "outline"}
55
- disabled={disabled || isResponding || !canRespond}
56
- aria-description={option.warning}
57
- onClick={() => {
58
- if (!disabled && !isResponding) {
59
- void onRespondToApproval(requestId, option.decision);
60
- }
61
- }}
62
- >
52
+ const buttonProps = {
53
+ disabled: disabled || isResponding || !canRespond,
54
+ "aria-description": option.warning,
55
+ onClick: () => {
56
+ if (!disabled && !isResponding && canRespond) {
57
+ void onRespondToApproval(requestId, option.decision);
58
+ }
59
+ },
60
+ };
61
+ const content = (
62
+ <>
63
{option.warning ? <TriangleAlertIcon className="size-3 shrink-0" /> : null}
64
- <span className="max-w-40 truncate">{option.label}</span>
65
- </Button>
64
+ <span className={presentation === "inline" ? "whitespace-normal" : "max-w-40 truncate"}>
65
+ {option.label}
66
+ </span>
67
+ </>
68
);
69
+ const button =
70
+ presentation === "inline" ? (
71
+ <InlineButton
72
+ key={option.decision}
73
+ {...buttonProps}
74
+ tone={option.decision === "accept" ? "default" : "muted"}
75
+ >
76
+ {content}
77
+ </InlineButton>
78
+ ) : (
79
+ <Button
80
+ key={option.decision}
81
+ {...buttonProps}
82
+ size="xs"
83
+ variant={option.decision === "accept" ? "default" : "outline"}
84
+ >
85
+ {content}
86
+ </Button>
87
+ );
88
return option.warning ? (
89
<Tooltip key={option.decision}>
90
<TooltipTrigger render={button} />
@@ -76,20 +97,26 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
97
{moreOptions.length > 0 ? (
98
<Menu>
99
<MenuTrigger
79
- disabled={disabled || isResponding}
80
- render={<Button size="icon-xs" variant="outline" aria-label="More approval options" />}
100
+ disabled={disabled || isResponding || !canRespond}
101
+ render={
102
+ presentation === "inline" ? (
103
+ <InlineButton tone="muted" aria-label="More approval options" />
104
+ ) : (
105
+ <Button size="icon-xs" variant="outline" aria-label="More approval options" />
106
+ )
107
+ }
108
>
82
- <EllipsisIcon />
109
+ {presentation === "inline" ? "More" : <EllipsisIcon />}
110
</MenuTrigger>
111
<MenuPopup {...composerFloatingLayerProps} side="top" align="end" width="content">
112
{moreOptions.map((option) => {
113
const item = (
114
<MenuItem
115
key={option.decision}
89
- disabled={disabled || isResponding}
116
+ disabled={disabled || isResponding || !canRespond}
117
aria-description={option.warning}
118
onClick={() => {
92
- if (!disabled && !isResponding)
119
+ if (!disabled && !isResponding && canRespond)
120
void onRespondToApproval(requestId, option.decision);
121
}}
122
>
apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx
deleted
-96
@@ -1,96 +0,0 @@
1
-import {
2
- FULL_ACCESS_OVERRIDE_QUESTION,
3
- fullAccessOverrideExplanation,
4
-} from "@t3tools/client-runtime/state/thread-requests";
5
-import { memo } from "react";
6
-import { type PendingApproval } from "../../session-logic";
7
-import { InlineButton } from "../ui/button";
8
-import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
9
-import { composerFloatingLayerProps } from "./composerEventScope";
10
-import { cn } from "~/lib/utils";
11
-
12
-interface ComposerPendingApprovalPanelProps {
13
- approval: PendingApproval;
14
- pendingCount: number;
15
- className?: string;
16
-}
17
-
18
-export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprovalPanel({
19
- approval,
20
- pendingCount,
21
- className,
22
-}: ComposerPendingApprovalPanelProps) {
23
- const Detail = approval.requestKind === "mcp-elicitation" ? "span" : "code";
24
- const fallbackLabel =
25
- approval.requestKind === "mcp-elicitation"
26
- ? "App access approval"
27
- : approval.requestKind === "command"
28
- ? "Command approval"
29
- : approval.requestKind === "file-read"
30
- ? "File read approval"
31
- : approval.requestKind === "permission"
32
- ? "App permission approval"
33
- : "File change approval";
34
- const detailAriaLabel =
35
- approval.requestKind === "mcp-elicitation"
36
- ? "App access request"
37
- : approval.requestKind === "command"
38
- ? "Command"
39
- : approval.requestKind === "file-read"
40
- ? "File to read"
41
- : approval.requestKind === "permission"
42
- ? "Permission request"
43
- : "File change";
44
-
45
- return (
46
- <span
47
- aria-label={fallbackLabel}
48
- className={cn("flex min-w-0 flex-1 flex-col items-start gap-1", className)}
49
- role="group"
50
- >
51
- <span className="flex w-full min-w-0 items-center gap-2 text-2xs text-muted-foreground">
52
- <span className="shrink-0 font-medium text-warning">{fallbackLabel}</span>
53
- {approval.appName ? <span className="min-w-0 truncate">{approval.appName}</span> : null}
54
- {approval.fullAccessOverride ? (
55
- <Popover>
56
- <PopoverTrigger openOnHover render={<InlineButton tone="muted" />}>
57
- {FULL_ACCESS_OVERRIDE_QUESTION}
58
- </PopoverTrigger>
59
- <PopoverPopup
60
- {...composerFloatingLayerProps}
61
- aria-label={FULL_ACCESS_OVERRIDE_QUESTION}
62
- tooltipStyle
63
- side="top"
64
- className="max-w-[min(22rem,calc(100vw-2rem))] whitespace-normal"
65
- >
66
- {fullAccessOverrideExplanation(approval.fullAccessOverride)}
67
- </PopoverPopup>
68
- </Popover>
69
- ) : null}
70
- {pendingCount > 1 ? (
71
- <span className="ml-auto shrink-0 tabular-nums">1/{pendingCount}</span>
72
- ) : null}
73
- </span>
74
- <Detail
75
- aria-label={detailAriaLabel}
76
- className={cn(
77
- "block w-full min-w-0 overflow-auto text-xs text-foreground [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70 [&::-webkit-scrollbar]:h-1.5",
78
- approval.requestKind === "mcp-elicitation"
79
- ? "max-h-20 whitespace-pre-wrap font-sans wrap-break-word"
80
- : "max-h-40 whitespace-pre-wrap font-mono wrap-anywhere",
81
- )}
82
- data-approval-detail="complete"
83
- tabIndex={0}
84
- >
85
- {approval.responseCapability === "not_resumable"
86
- ? "Provider process is gone. Interrupt or restart the run to respond."
87
- : approval.detail || fallbackLabel}
88
- </Detail>
89
- {approval.reason ? (
90
- <span className="w-full min-w-0 text-2xs text-muted-foreground wrap-break-word">
91
- {approval.reason}
92
- </span>
93
- ) : null}
94
- </span>
95
- );
96
-});
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+176
-1
@@ -1,11 +1,14 @@
1
import { AudioPreview } from "../files/AudioPreview";
2
import { onTestFinished } from "vite-plus/test";
3
+import { page } from "vite-plus/test/browser";
4
import { stubGlobal } from "../../../test/render";
5
import {
6
EnvironmentId,
7
MessageId,
8
RunAttemptId,
9
RunId,
10
+ RuntimeRequestId,
11
+ TurnItemId,
12
ScheduledTaskId,
13
ThreadId,
14
} from "@t3tools/contracts";
@@ -18,7 +21,10 @@ import "~/index.css";
21
import { act, fakeTimers, render } from "../../../test/render";
22
import { MessagesTimeline } from "./MessagesTimeline";
23
import { makeStreamingTimelineFixture } from "../../test-fixtures";
21
-import { deriveTimelineEntriesFromVisibleTurnItems } from "../../session-logic";
24
+import {
25
+ type PendingApproval,
26
+ deriveTimelineEntriesFromVisibleTurnItems,
27
+} from "../../session-logic";
28
import { remarkThoughtPreview } from "./TimelineWorkEntryRow.logic";
29
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
30
import { collectThreadFindRanges } from "./threadFindHighlights";
@@ -990,3 +996,172 @@ it("renders automatic compaction as one live divider that finishes with its reas
996
expect(container.querySelectorAll('[role="separator"]')).toHaveLength(1);
997
expect(container.textContent).not.toContain("Compacting before");
998
});
999
+
1000
+it("keeps concurrent approvals actionable outside collapsed work and restores settled rows", async () => {
1001
+ setup();
1002
+ const fixture = makeStreamingTimelineFixture();
1003
+ const source = fixture.visibleTurnItems[4]!;
1004
+ if (source.item.type !== "dynamic_tool") throw new Error("Expected fixture tool");
1005
+ const sourceItem = source.item;
1006
+ const commandRequest = RuntimeRequestId.make("command-approval");
1007
+ const appRequest = RuntimeRequestId.make("app-approval");
1008
+ const approvals: PendingApproval[] = [
1009
+ {
1010
+ requestId: commandRequest,
1011
+ requestKind: "command",
1012
+ createdAt: fixture.time(6),
1013
+ detail: "printf '" + "long-command ".repeat(80) + "'",
1014
+ reason: "Needs permission to run the command",
1015
+ fullAccessOverride: "ask_rule",
1016
+ responseCapability: "live",
1017
+ },
1018
+ {
1019
+ requestId: appRequest,
1020
+ requestKind: "permission",
1021
+ createdAt: fixture.time(6),
1022
+ detail: "Open the current tab",
1023
+ appName: "Safari",
1024
+ options: [
1025
+ { decision: "decline", label: "Deny" },
1026
+ { decision: "accept", label: "Allow once" },
1027
+ {
1028
+ decision: "acceptAlways",
1029
+ label: "Always allow Safari",
1030
+ warning: "Applies to future requests",
1031
+ },
1032
+ ],
1033
+ responseCapability: "live",
1034
+ },
1035
+ ];
1036
+ const entries = (completed = false) =>
1037
+ deriveTimelineEntriesFromVisibleTurnItems({
1038
+ visibleTurnItems: [
1039
+ { ...source, item: { ...sourceItem, status: completed ? "completed" : sourceItem.status } },
1040
+ ...approvals.map((approval, index) => ({
1041
+ ...source,
1042
+ position: source.position + index + 1,
1043
+ sourceItemId: TurnItemId.make(`approval-${index}`),
1044
+ item: {
1045
+ ...sourceItem,
1046
+ id: TurnItemId.make(`approval-${index}`),
1047
+ type: "approval_request" as const,
1048
+ status: completed ? ("completed" as const) : ("waiting" as const),
1049
+ requestId: approval.requestId,
1050
+ requestKind: approval.requestKind,
1051
+ prompt: approval.detail,
1052
+ },
1053
+ })),
1054
+ ],
1055
+ optimisticMessages: [],
1056
+ });
1057
+ const props = baseProps();
1058
+ const onRespondToApproval = vi.fn(async () => {});
1059
+ const ui = (overrides: Partial<TimelineProps> = {}) => (
1060
+ <MessagesTimeline
1061
+ {...props}
1062
+ timelineEntries={entries()}
1063
+ pendingApprovals={approvals}
1064
+ canOperateThread
1065
+ onRespondToApproval={onRespondToApproval}
1066
+ isWorking
1067
+ runningRunId={fixture.runId}
1068
+ {...overrides}
1069
+ />
1070
+ );
1071
+ await using screen = await renderElement(ui());
1072
+ await expect.element(screen.getByRole("group", { name: "Command approval" })).toBeVisible();
1073
+ await expect
1074
+ .element(screen.getByRole("group", { name: "App permission approval" }))
1075
+ .toBeVisible();
1076
+ await expect.element(screen.getByText(approvals[0]!.detail!, { exact: true })).toBeVisible();
1077
+ await expect.element(screen.getByText("Needs permission to run the command")).toBeVisible();
1078
+ await vi.waitFor(() => {
1079
+ expect(
1080
+ getComputedStyle(screen.getByLabelText("Command", { exact: true }).element()).userSelect,
1081
+ ).toBe("text");
1082
+ expect(
1083
+ getComputedStyle(screen.getByText("Needs permission to run the command").element())
1084
+ .userSelect,
1085
+ ).toBe("text");
1086
+ });
1087
+ await expect.element(screen.getByText("Safari", { exact: true })).toBeVisible();
1088
+ await click(screen.button("Why am I being asked this?"));
1089
+ await expect.element(page.getByText(/an ask rule in the agent's own settings/)).toBeVisible();
1090
+ await click(screen.button("Why am I being asked this?"));
1091
+ await click(screen.buttons("More approval options")[1]!);
1092
+ await expect.element(page.getByRole("menuitem", { name: "Always allow Safari" })).toBeVisible();
1093
+ await page.getByRole("menuitem", { name: "Always allow Safari" }).click();
1094
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(appRequest, "acceptAlways");
1095
+ await click(screen.buttons("More approval options")[0]!);
1096
+ await expect.element(page.getByRole("menuitem", { name: "Cancel", exact: true })).toBeVisible();
1097
+ await page.getByRole("menuitem", { name: "Always allow this session" }).click();
1098
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(commandRequest, "acceptForSession");
1099
+ await click(screen.button("Decline"));
1100
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(commandRequest, "decline");
1101
+ await click(screen.button("Allow once"));
1102
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(appRequest, "accept");
1103
+ for (const timelineEntries of [entries(), []]) {
1104
+ await screen.rerender(
1105
+ ui({ timelineEntries, heldApprovalRequestIds: new Set([commandRequest]) }),
1106
+ );
1107
+ await expect
1108
+ .element(screen.getByRole("group", { name: "Command approval" }))
1109
+ .not.toBeInTheDocument();
1110
+ await vi.waitFor(() => expect(screen.buttons("Approve")).toHaveLength(0));
1111
+ await expect
1112
+ .element(screen.getByRole("button", { name: "Allow once", exact: true }))
1113
+ .toBeVisible();
1114
+ await screen.rerender(ui({ timelineEntries }));
1115
+ await expect.element(screen.getByRole("group", { name: "Command approval" })).toBeVisible();
1116
+ await vi.waitFor(() => expect(screen.buttons("Approve")).toHaveLength(1));
1117
+ }
1118
+ await screen.rerender(ui({ timelineEntries: [], isWorking: false }));
1119
+ await expect.element(screen.getByRole("group", { name: "Command approval" })).toBeVisible();
1120
+ await click(screen.button("Approve"));
1121
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(commandRequest, "accept");
1122
+ await click(screen.button("Deny"));
1123
+ expect(onRespondToApproval).toHaveBeenLastCalledWith(appRequest, "decline");
1124
+ await screen.rerender(
1125
+ ui({
1126
+ timelineEntries: [],
1127
+ isWorking: false,
1128
+ pendingApprovals: [{ ...approvals[0]!, detail: "" }],
1129
+ }),
1130
+ );
1131
+ await expect
1132
+ .element(screen.getByLabelText("Command", { exact: true }))
1133
+ .toHaveTextContent("Command approval");
1134
+ await screen.rerender(ui({ canOperateThread: false }));
1135
+ await expect.element(screen.getByRole("button", { name: "Approve", exact: true })).toBeDisabled();
1136
+ await vi.waitFor(() =>
1137
+ expect(
1138
+ screen.buttons("More approval options").every((button) => button.hasAttribute("disabled")),
1139
+ ).toBe(true),
1140
+ );
1141
+ await screen.rerender(ui({ respondingRequestIds: [commandRequest] }));
1142
+ await expect.element(screen.getByRole("button", { name: "Approve", exact: true })).toBeDisabled();
1143
+ await expect
1144
+ .element(screen.getByRole("button", { name: "Allow once", exact: true }))
1145
+ .toBeEnabled();
1146
+ await screen.rerender(
1147
+ ui({ pendingApprovals: [{ ...approvals[0]!, responseCapability: "not_resumable" }] }),
1148
+ );
1149
+ await expect
1150
+ .element(screen.getByText("Provider process is gone. Interrupt or restart the run to respond."))
1151
+ .toBeVisible();
1152
+ await vi.waitFor(() => expect(screen.buttons("Approve")).toHaveLength(0));
1153
+ await screen.rerender(
1154
+ ui({ pendingApprovals: [], timelineEntries: entries(true), isWorking: false }),
1155
+ );
1156
+ await expect
1157
+ .element(screen.getByRole("group", { name: "Command approval" }))
1158
+ .not.toBeInTheDocument();
1159
+ await vi.waitFor(() => expect(screen.text()).not.toContain("Waiting for approval"));
1160
+ await screen.getByRole("button", { expanded: false }).click();
1161
+ await expect
1162
+ .element(screen.getByRole("button", { name: approvals[0]!.detail!, exact: true }))
1163
+ .toBeVisible();
1164
+ await expect
1165
+ .element(screen.getByRole("button", { name: "Open the current tab", exact: true }))
1166
+ .toBeVisible();
1167
+});
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+33
@@ -241,6 +241,37 @@ describe("deriveMessagesTimelineRows", () => {
241
expect(rows.some((row) => row.kind === "event")).toBe(false);
242
expect(workRows[0]).not.toMatchObject({ expanded: true });
243
expect(workRows[0]).not.toMatchObject({ isExpandedToolGroup: true });
244
+ const pendingRows = deriveMessagesTimelineRows({
245
+ timelineEntries: entries,
246
+ pendingApprovalRequestIds: new Set([RuntimeRequestId.make("approval-request")]),
247
+ isWorking: status === "waiting",
248
+ runningRunId: fixture.runId,
249
+ activeTurnStartedAt: fixture.time(0),
250
+ turnDiffSummaries: [],
251
+ supportsConversationRollback: false,
252
+ });
253
+ expect(pendingRows.filter((row) => row.kind === "work")).toContainEqual(
254
+ expect.objectContaining({
255
+ groupedEntries: [expect.objectContaining({ itemType: "approval_request" })],
256
+ isExpandedToolGroup: false,
257
+ }),
258
+ );
259
+ expect(
260
+ pendingRows
261
+ .filter((row) => row.kind === "work-live")
262
+ .flatMap((row) => row.groupedEntries)
263
+ .some((entry) => entry.itemType === "approval_request"),
264
+ ).toBe(false);
265
+ const approvalOnlyRows = deriveMessagesTimelineRows({
266
+ timelineEntries: entries.slice(1, 2),
267
+ pendingApprovalRequestIds: new Set([RuntimeRequestId.make("approval-request")]),
268
+ isWorking: status === "waiting",
269
+ runningRunId: fixture.runId,
270
+ activeTurnStartedAt: fixture.time(0),
271
+ turnDiffSummaries: [],
272
+ supportsConversationRollback: false,
273
+ });
274
+ expect(approvalOnlyRows.some((row) => row.kind === "thinking")).toBe(false);
275
},
276
);
277
@@ -3027,6 +3058,7 @@ describe("streaming v2 row projection", () => {
3058
const previous = deriveMessagesTimelineRowsWithState({
3059
...initial.input,
3060
availableRevertTurnCounts: new Set([0]),
3061
+ pendingApprovalRequestIds: new Set<RuntimeRequestId>(),
3062
});
3063
Object.freeze(previous.rows);
3064
for (const row of previous.rows) Object.freeze(row);
@@ -3044,6 +3076,7 @@ describe("streaming v2 row projection", () => {
3076
latestRun: { ...initial.input.latestRun },
3077
turnDiffSummaries: initial.input.turnDiffSummaries.map((summary) => ({ ...summary })),
3078
availableRevertTurnCounts: new Set([0]),
3079
+ pendingApprovalRequestIds: new Set<RuntimeRequestId>(),
3080
};
3081
const next = deriveMessagesTimelineRowsWithState(input, previous);
3082
expect(next.rows).toEqual(
apps/web/src/components/chat/MessagesTimeline.logic.ts
+26
-2
@@ -55,6 +55,7 @@ import {
55
type WorktreeSetupSnapshot,
56
type OrchestrationV2ProjectedTurnItem,
57
type RunAttemptId,
58
+ type RuntimeRequestId,
59
RunId,
60
type ThreadId,
61
type TurnItemId,
@@ -1345,6 +1346,7 @@ function deriveTimelineTurnFolds(
1346
1347
export function deriveMessagesTimelineRows(input: {
1348
timelineEntries: ReadonlyArray<TimelineEntry>;
1349
+ pendingApprovalRequestIds?: ReadonlySet<RuntimeRequestId>;
1350
latestRun?: TimelineLatestRun | null;
1351
runningRunId?: RunId | null;
1352
expandedRunIds?: ReadonlySet<RunId>;
@@ -1361,6 +1363,13 @@ export function deriveMessagesTimelineRows(input: {
1363
worktreeSetup?: WorktreeSetupSnapshot | null;
1364
}): MessagesTimelineRow[] {
1365
const timelineEntries = timelineRowEntries(input.timelineEntries);
1366
+ const isPendingApproval = (entry: WorkLogEntry) => {
1367
+ const item = entry.projectedItem?.item;
1368
+ return (
1369
+ item?.type === "approval_request" &&
1370
+ input.pendingApprovalRequestIds?.has(item.requestId) === true
1371
+ );
1372
+ };
1373
const turnDiffSummaryByAssistantMessageId = new Map<MessageId, TurnDiffSummary>();
1374
for (const summary of input.turnDiffSummaries) {
1375
if (summary.assistantMessageId) {
@@ -1423,6 +1432,14 @@ export function deriveMessagesTimelineRows(input: {
1432
}
1433
}
1434
}
1435
+ if (input.pendingApprovalRequestIds?.size) {
1436
+ for (const entry of timelineEntries) {
1437
+ if (entry.kind === "work" && isPendingApproval(entry.entry)) {
1438
+ collapsedEntryIds.delete(entry.id);
1439
+ collapsedSupersededEntryIds.delete(entry.id);
1440
+ }
1441
+ }
1442
+ }
1443
const runIdIsActiveResponse = (runId: RunId | null | undefined) =>
1444
runId == null ? runlessWorkActive : activeVisualResponseRunIds.has(runId);
1445
const workEntryIsInActiveRun = (entry: WorkLogEntry) =>
@@ -1446,6 +1463,7 @@ export function deriveMessagesTimelineRows(input: {
1463
entry.entry.itemType === "system_notice" ||
1464
entry.entry.itemType === "notification" ||
1465
entry.entry.questionAnswer !== undefined ||
1466
+ isPendingApproval(entry.entry) ||
1467
!runIdIsActiveResponse(entry.entry.runId) ||
1468
entry.entry.sourceActivityKind === "context-compaction" ||
1469
collapsedEntryIds.has(entry.id) ||
@@ -1475,7 +1493,8 @@ export function deriveMessagesTimelineRows(input: {
1493
const latestToolKeepsActivityLive =
1494
latestRunningToolEntry !== undefined ||
1495
(latestVisibleToolEntry !== undefined &&
1478
- workEntryIndicatesToolSuccess(latestVisibleToolEntry.entry));
1496
+ workEntryIndicatesToolSuccess(latestVisibleToolEntry.entry) &&
1497
+ !input.pendingApprovalRequestIds?.size);
1498
const latestToolFailed =
1499
latestRunningToolEntry === undefined &&
1500
latestVisibleToolEntry !== undefined &&
@@ -1717,6 +1736,7 @@ export function deriveMessagesTimelineRows(input: {
1736
1737
if (timelineEntry.kind === "work") {
1738
if (
1739
+ isPendingApproval(timelineEntry.entry) ||
1740
(timelineEntry.entry.runId != null && failedRunIds.has(timelineEntry.entry.runId)) ||
1741
(timelineEntry.entry.itemType === "error" &&
1742
timelineEntry.entry.toolLifecycleStatus === "failed") ||
@@ -1748,6 +1768,7 @@ export function deriveMessagesTimelineRows(input: {
1768
nextEntry.entry.itemType === "system_notice" ||
1769
nextEntry.entry.itemType === "notification" ||
1770
nextEntry.entry.questionAnswer !== undefined ||
1771
+ isPendingApproval(nextEntry.entry) ||
1772
activeWorkEntryIds.has(nextEntry.id) ||
1773
collapsedEntryIds.has(nextEntry.id) ||
1774
collapsedSupersededEntryIds.has(nextEntry.id) ||
@@ -2023,7 +2044,7 @@ export function deriveMessagesTimelineRows(input: {
2044
!setupOwnsWorkingSlot &&
2045
!hasActiveCompaction &&
2046
!compactionOnlyRunFinished &&
2026
- (!hasActivityRow || latestToolFailed)
2047
+ (latestToolFailed || (!hasActivityRow && !input.pendingApprovalRequestIds?.size))
2048
) {
2049
const failedGroupAnchor = latestToolFailed ? activeWorkAnchor : undefined;
2050
if (failedGroupAnchor) {
@@ -2173,6 +2194,7 @@ function replaceStreamingMessageRows(
2194
expandedRunIds: previousExpandedRuns,
2195
expandedAttemptIds: previousExpandedAttempts,
2196
expandedWorkGroupIds: previousExpandedGroups,
2197
+ pendingApprovalRequestIds: previousPendingApprovalRequestIds,
2198
availableRevertTurnCounts: previousAvailableRevertTurnCounts,
2199
...previousContext
2200
} = previous.input;
@@ -2183,6 +2205,7 @@ function replaceStreamingMessageRows(
2205
expandedRunIds,
2206
expandedAttemptIds,
2207
expandedWorkGroupIds,
2208
+ pendingApprovalRequestIds,
2209
availableRevertTurnCounts,
2210
...context
2211
} = input;
@@ -2194,6 +2217,7 @@ function replaceStreamingMessageRows(
2217
!shallow(previousExpandedRuns, expandedRunIds) ||
2218
!shallow(previousExpandedAttempts, expandedAttemptIds) ||
2219
!shallow(previousExpandedGroups, expandedWorkGroupIds) ||
2220
+ !shallow(previousPendingApprovalRequestIds, pendingApprovalRequestIds) ||
2221
!shallow(previousAvailableRevertTurnCounts, availableRevertTurnCounts) ||
2222
!sameCheckpointSummaries(previousCheckpoints, turnDiffSummaries)
2223
) {
apps/web/src/components/chat/MessagesTimeline.tsx
+63
-10
@@ -3,6 +3,7 @@ import { ThreadFindTimelineContext } from "./ThreadFindProvider";
3
import { MarkdownFindContext } from "./markdownFindContext";
4
import { useChatCanvas } from "./ChatCanvasContext";
5
import { WorkLogBlock } from "./WorkLog";
6
+import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
7
import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
8
import { deriveTimelineMinimapItems } from "./timelineMinimapItems";
9
import {
@@ -22,6 +23,9 @@ import { observeResize } from "~/lib/observeResize";
23
import { useStableCallback } from "~/hooks/useStableCallback";
24
25
const NOOP_USE_ARTIFACT_TEMPLATE = () => {};
26
+const EMPTY_PENDING_APPROVALS: ReadonlyArray<PendingApproval> = [];
27
+const EMPTY_RESPONDING_REQUEST_IDS: TimelineRowSharedState["respondingRequestIds"] = [];
28
+
29
const NOOP_OPEN_ATTACHMENT = (_attachment: ChatFileAttachment) => {};
30
31
import { resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
@@ -41,7 +45,7 @@ import {
45
type LegendListRef,
46
type MaintainScrollAtEndOptions,
47
} from "@legendapp/list/react";
44
-import { type TimelineEntry } from "../../session-logic";
48
+import { type PendingApproval, type TimelineEntry } from "../../session-logic";
49
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
50
import { type ChatFileAttachment, type TurnDiffSummary } from "../../types";
51
import { ArrowRightIcon, BotIcon, CircleAlertIcon, Minimize2Icon } from "lucide-react";
@@ -197,6 +201,11 @@ export interface MessagesTimelineHistoryControls {
201
}
202
203
interface MessagesTimelineProps {
204
+ pendingApprovals?: ReadonlyArray<PendingApproval>;
205
+ heldApprovalRequestIds?: ReadonlySet<string> | undefined;
206
+ respondingRequestIds?: TimelineRowSharedState["respondingRequestIds"];
207
+ canOperateThread?: boolean;
208
+ onRespondToApproval?: TimelineRowSharedState["onRespondToApproval"];
209
citationRequest?: AssistantCitationRequest | null;
210
citationHistory?: CitedHistory;
211
onCiteAssistantText?: (
@@ -304,6 +313,11 @@ export function MessagesTimeline(props: MessagesTimelineProps) {
313
}
314
315
const ConversationTimeline = memo(function ConversationTimeline({
316
+ pendingApprovals = EMPTY_PENDING_APPROVALS,
317
+ heldApprovalRequestIds,
318
+ respondingRequestIds = EMPTY_RESPONDING_REQUEST_IDS,
319
+ canOperateThread = false,
320
+ onRespondToApproval,
321
citationRequest = null,
322
citationHistory = CITED_HISTORY_LOADING,
323
onCiteAssistantText,
@@ -650,8 +664,15 @@ const ConversationTimeline = memo(function ConversationTimeline({
664
? new Set(paintedExpandedAttemptIds).add(activeFindAttemptId)
665
: paintedExpandedAttemptIds;
666
667
+ const pendingApprovalsByRequestId = new Map(
668
+ pendingApprovals
669
+ .filter((approval) => !heldApprovalRequestIds?.has(approval.requestId))
670
+ .map((approval) => [approval.requestId, approval]),
671
+ );
672
+ const pendingApprovalRequestIds = new Set(pendingApprovalsByRequestId.keys());
673
const rawRows = useIncrementalTimelineRows(`${listIdentityKey}\0${workspaceRoot ?? ""}`, {
674
timelineEntries,
675
+ pendingApprovalRequestIds,
676
latestRun,
677
runningRunId,
678
expandedRunIds: visibleExpandedRunIds,
@@ -667,6 +688,17 @@ const ConversationTimeline = memo(function ConversationTimeline({
688
worktreeSetup,
689
});
690
const rows = useStableRows(rawRows, listIdentityKey);
691
+ const unmatchedPendingApprovals = new Map(pendingApprovalsByRequestId);
692
+ if (unmatchedPendingApprovals.size > 0) {
693
+ for (const row of rows) {
694
+ const entries =
695
+ row.kind === "work" ? row.groupedEntries : row.kind === "work-live" ? [row.entry] : [];
696
+ for (const entry of entries) {
697
+ const item = entry.projectedItem?.item;
698
+ if (item?.type === "approval_request") unmatchedPendingApprovals.delete(item.requestId);
699
+ }
700
+ }
701
+ }
702
// Run status/timestamps change per stream event; keep them out of shared row context.
703
const runs = useStableHandoffRuns(runsProp);
704
const minimapItems = deriveTimelineMinimapItems(rows);
@@ -679,6 +711,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
711
restoringThreadPosition && restoreRowIndex >= 0 ? { indices: [restoreRowIndex] } : undefined;
712
const showsEmptyState =
713
rows.length === 0 &&
714
+ unmatchedPendingApprovals.size === 0 &&
715
!isWorking &&
716
parentThreadLink === null &&
717
historyControls === undefined &&
@@ -720,6 +753,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
753
listRef,
754
rememberedPosition,
755
restoreReady,
756
+ viewportRef,
757
]);
758
759
const [timelineViewportElement, setTimelineViewportElement] = useState<HTMLDivElement | null>(
@@ -805,15 +839,6 @@ const ConversationTimeline = memo(function ConversationTimeline({
839
size: true,
840
shouldRestorePosition: shouldRestoreVisibleContentPosition,
841
};
808
- const timelineListFooter = (
809
- <TimelineListFooter
810
- composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment}
811
- onGrow={onFooterGrow}
812
- >
813
- {footer}
814
- </TimelineListFooter>
815
- );
816
-
842
const measureContentOverflow = () =>
843
timelineContentOverflowsViewport(listRef.current?.getState?.(), {
844
composerInset: contentInsetEndAdjustment,
@@ -1003,6 +1028,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
1028
};
1029
1030
const sharedState: TimelineRowSharedState = {
1031
+ pendingApprovals: pendingApprovalsByRequestId,
1032
+ respondingRequestIds,
1033
+ canOperateThread,
1034
+ onRespondToApproval,
1035
citationRequest: readyCitationRequest,
1036
listRef,
1037
timestampFormat,
@@ -1230,6 +1259,30 @@ const ConversationTimeline = memo(function ConversationTimeline({
1259
</TimelineRowCtx>
1260
);
1261
const listExtraData = { identity: listIdentityKey, rowCount: rows.length, sharedState };
1262
+ const timelineListFooter = (
1263
+ <TimelineListFooter
1264
+ composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment}
1265
+ onGrow={onFooterGrow}
1266
+ >
1267
+ {footer}
1268
+ {unmatchedPendingApprovals.size > 0 ? (
1269
+ <TimelineRowCtx value={sharedState}>
1270
+ <div className="messages-timeline-row-frame">
1271
+ <div
1272
+ className="@container/chat-lane chat-content-lane overflow-x-clip"
1273
+ data-timeline-root="true"
1274
+ >
1275
+ <WorkLogBlock>
1276
+ {[...unmatchedPendingApprovals.values()].map((approval) => (
1277
+ <TimelinePendingApprovalRow key={approval.requestId} approval={approval} />
1278
+ ))}
1279
+ </WorkLogBlock>
1280
+ </div>
1281
+ </div>
1282
+ </TimelineRowCtx>
1283
+ ) : null}
1284
+ </TimelineListFooter>
1285
+ );
1286
1287
const forwardMinimapWheel = (event: WheelEvent) => {
1288
const scrollNode = listRef.current?.getScrollableNode();
apps/web/src/components/chat/TimelinePendingApprovalRow.tsx
new
+122
@@ -0,0 +1,122 @@
1
+import {
2
+ FULL_ACCESS_OVERRIDE_QUESTION,
3
+ fullAccessOverrideExplanation,
4
+} from "@t3tools/client-runtime/state/thread-requests";
5
+import { ShieldIcon } from "lucide-react";
6
+import { memo, use } from "react";
7
+import { type PendingApproval } from "../../session-logic";
8
+import { InlineButton } from "../ui/button";
9
+import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
10
+import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
11
+import { ToolActivityIconView, type WorkEntryIconName } from "./TimelineToolActivityIcon";
12
+import { TimelineRowCtx } from "./timelineRowContext";
13
+import { WorkLogRow } from "./WorkLog";
14
+
15
+const APPROVAL_PRESENTATION = {
16
+ command: { icon: "terminal", label: "Command approval", detailLabel: "Command" },
17
+ "file-change": { icon: "square-pen", label: "File change approval", detailLabel: "File change" },
18
+ "file-read": { icon: "eye", label: "File read approval", detailLabel: "File to read" },
19
+ permission: {
20
+ icon: "wrench",
21
+ label: "App permission approval",
22
+ detailLabel: "Permission request",
23
+ },
24
+ "mcp-elicitation": {
25
+ icon: "hammer",
26
+ label: "App access approval",
27
+ detailLabel: "App access request",
28
+ },
29
+} satisfies Record<
30
+ PendingApproval["requestKind"],
31
+ { icon: WorkEntryIconName; label: string; detailLabel: string }
32
+>;
33
+
34
+export const TimelinePendingApprovalRow = memo(function TimelinePendingApprovalRow({
35
+ approval,
36
+}: {
37
+ approval: PendingApproval;
38
+}) {
39
+ const { respondingRequestIds, canOperateThread, onRespondToApproval } = use(TimelineRowCtx);
40
+ const presentation = APPROVAL_PRESENTATION[approval.requestKind];
41
+ const canRespond = approval.responseCapability === "live";
42
+ return (
43
+ <WorkLogRow
44
+ role="group"
45
+ aria-label={presentation.label}
46
+ data-v2-item-type="approval_request"
47
+ wrapLabel
48
+ icon={
49
+ <ToolActivityIconView
50
+ icon={undefined}
51
+ fallbackName={presentation.icon}
52
+ className="block size-4 shrink-0 stroke-2 text-icon-muted"
53
+ muted
54
+ />
55
+ }
56
+ label={
57
+ <code
58
+ aria-label={presentation.detailLabel}
59
+ className="block max-h-40 min-w-0 overflow-auto whitespace-pre-wrap font-mono text-xs leading-5 text-foreground select-text! wrap-anywhere [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
60
+ data-approval-detail="complete"
61
+ tabIndex={0}
62
+ >
63
+ {approval.detail || presentation.label}
64
+ </code>
65
+ }
66
+ >
67
+ <div className="ms-7.5 flex min-w-0 flex-col gap-1 pb-1 text-xs">
68
+ {approval.appName ? (
69
+ <span className="text-muted-foreground wrap-anywhere">{approval.appName}</span>
70
+ ) : null}
71
+ {approval.reason ? (
72
+ <span className="text-muted-foreground select-text wrap-anywhere">{approval.reason}</span>
73
+ ) : null}
74
+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
75
+ {canRespond ? (
76
+ <>
77
+ <span className="inline-flex items-center gap-1 text-warning">
78
+ <ShieldIcon aria-hidden className="size-3 shrink-0" />
79
+ Waiting for approval
80
+ </span>
81
+ {onRespondToApproval ? (
82
+ <>
83
+ <span aria-hidden className="text-muted-foreground">
84
+ ·
85
+ </span>
86
+ <ComposerPendingApprovalActions
87
+ presentation="inline"
88
+ requestId={approval.requestId}
89
+ disabled={!canOperateThread}
90
+ isResponding={respondingRequestIds.includes(approval.requestId)}
91
+ canRespond={canRespond}
92
+ options={approval.options}
93
+ onRespondToApproval={onRespondToApproval}
94
+ />
95
+ </>
96
+ ) : null}
97
+ </>
98
+ ) : (
99
+ <span className="text-warning">
100
+ Provider process is gone. Interrupt or restart the run to respond.
101
+ </span>
102
+ )}
103
+ {approval.fullAccessOverride ? (
104
+ <Popover>
105
+ <PopoverTrigger openOnHover render={<InlineButton tone="muted" />}>
106
+ {FULL_ACCESS_OVERRIDE_QUESTION}
107
+ </PopoverTrigger>
108
+ <PopoverPopup
109
+ aria-label={FULL_ACCESS_OVERRIDE_QUESTION}
110
+ tooltipStyle
111
+ side="top"
112
+ className="max-w-[min(22rem,calc(100vw-2rem))] whitespace-normal"
113
+ >
114
+ {fullAccessOverrideExplanation(approval.fullAccessOverride)}
115
+ </PopoverPopup>
116
+ </Popover>
117
+ ) : null}
118
+ </div>
119
+ </div>
120
+ </WorkLogRow>
121
+ );
122
+});
apps/web/src/components/chat/TimelineWorkEntryRow.tsx
+6
@@ -1,3 +1,4 @@
1
+import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
2
import { WorkLogDetails, WorkLogRow } from "./WorkLog";
3
import {
4
getQuestionAnswerPreview,
@@ -198,6 +199,11 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
199
setExpanded(next);
200
};
201
const failureItem = workEntry.projectedItem?.item;
202
+ const pendingApproval =
203
+ failureItem?.type === "approval_request"
204
+ ? ctx.pendingApprovals.get(failureItem.requestId)
205
+ : undefined;
206
+ if (pendingApproval) return <TimelinePendingApprovalRow approval={pendingApproval} />;
207
if (failureItem?.type === "error" && failureItem.status === "failed") {
208
const warning = failureItem.failure.class === "usage_limit";
209
const resetAt = failureItem.failure.resetAt;
apps/web/src/components/chat/TimelineWorkGroupRows.tsx
+20
-5
@@ -1,3 +1,4 @@
1
+import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
2
import { WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
3
import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
4
import { type ToolActivityIcon } from "@t3tools/contracts";
@@ -66,12 +67,17 @@ export const WorkGroupSection = memo(function WorkGroupSection({
67
isExpandedToolGroup: boolean;
68
displayLabel?: string | undefined;
69
}) {
69
- const { workspaceRoot, routeThreadKey, onToggleWorkEntry } = use(TimelineRowCtx);
70
+ const { workspaceRoot, routeThreadKey, onToggleWorkEntry, pendingApprovals } =
71
+ use(TimelineRowCtx);
72
const onToggleStandaloneEntry = (collapsed: boolean) =>
73
onToggleWorkEntry(disclosureAnchorKey, collapsed);
72
- const nonEmptyEntries = groupedEntries.filter((entry) =>
73
- workEntryIsVisibleInGroup(entry, isExpandedToolGroup),
74
- );
74
+ const nonEmptyEntries = groupedEntries.filter((entry) => {
75
+ const item = entry.projectedItem?.item;
76
+ return (
77
+ (item?.type === "approval_request" && pendingApprovals.has(item.requestId)) ||
78
+ workEntryIsVisibleInGroup(entry, isExpandedToolGroup)
79
+ );
80
+ });
81
82
if (nonEmptyEntries.length === 0) return null;
83
if (isExpandedToolGroup && nonEmptyEntries.every((entry) => entry.itemType === "reasoning")) {
@@ -355,7 +361,11 @@ export function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind:
361
const ctx = use(TimelineRowCtx);
362
const { isCompacting, isPreparingWorktree } = use(TimelineRowActivityCtx);
363
if (isPreparingWorktree || isCompacting) return <WorkLogRow label="" />;
358
- const activity = <LiveActivityRow label="Thinking" iconName="brain" active shimmer />;
364
+ // A failed group keeps this disclosure while an approval waits, but nothing is thinking then.
365
+ const live = ctx.pendingApprovals.size === 0;
366
+ const activity = (
367
+ <LiveActivityRow label="Thinking" iconName="brain" active={live} shimmer={live} />
368
+ );
369
const { groupId } = row;
370
if (groupId === undefined) return activity;
371
return (
@@ -484,6 +494,11 @@ export function LiveWorkEntryTimelineRow({
494
const label = liveWorkEntryLabel(row.entry, ctx.workspaceRoot, row.active);
495
const threadLabel = threadReadLabel(label, threadTarget);
496
497
+ const item = row.entry.projectedItem?.item;
498
+ const pendingApproval =
499
+ item?.type === "approval_request" ? ctx.pendingApprovals.get(item.requestId) : undefined;
500
+ if (pendingApproval) return <TimelinePendingApprovalRow approval={pendingApproval} />;
501
+
502
const failed = workEntryDisplayIndicatesToolFailure(row.entry);
503
const thoughtLine = row.thought && !row.expanded ? liveThoughtLine(row.thought.detail ?? "") : "";
504
const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought;
apps/web/src/components/chat/composerTypingGuard.test.ts
+6
@@ -19,6 +19,9 @@ describe("composer typing guard", () => {
19
});
20
state = updateComposerTypingGuard(state, { type });
21
expect([...state.held]).toEqual([]);
22
+ const released = state.held;
23
+ state = updateComposerTypingGuard(state, { type });
24
+ expect(state.held).toBe(released);
25
state = updateComposerTypingGuard(state, { type: "focus" });
26
state = updateComposerTypingGuard(state, { type: "type", now: 2000 });
27
state = updateComposerTypingGuard(state, { type: "requests", requestIds: [], now: 2100 });
@@ -37,13 +40,16 @@ describe("composer typing guard", () => {
40
requestIds: ["question"],
41
now: 0,
42
});
43
+ const held = state.held;
44
state = updateComposerTypingGuard(state, { type: "focus" });
45
state = updateComposerTypingGuard(state, { type: "type", now: 1000 });
46
+ expect(state.held).toBe(held);
47
state = updateComposerTypingGuard(state, {
48
type: "requests",
49
requestIds: ["question"],
50
now: 1100,
51
});
52
expect([...state.held]).toEqual([]);
53
+ expect(state.held).toBe(held);
54
});
55
});
apps/web/src/components/chat/composerTypingGuard.ts
+9
-2
@@ -32,7 +32,14 @@ export function updateComposerTypingGuard(
32
}
33
seen.add(id);
34
}
35
- return { ...state, seen, held };
35
+ return {
36
+ ...state,
37
+ seen,
38
+ held:
39
+ held.size === state.held.size && [...held].every((id) => state.held.has(id))
40
+ ? state.held
41
+ : held,
42
+ };
43
}
44
case "type":
45
return { ...state, lastTypedAt: event.now };
@@ -43,7 +50,7 @@ export function updateComposerTypingGuard(
50
case "idle":
51
return {
52
...state,
46
- held: new Set<string>(),
53
+ held: state.held.size === 0 ? state.held : new Set<string>(),
54
lastTypedAt: -Infinity,
55
focused: event.type === "blur" ? false : state.focused,
56
};
apps/web/src/components/chat/timelineRowContext.ts
+12
-1
@@ -1,4 +1,8 @@
1
-import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
1
+import type {
2
+ ProviderApprovalDecision,
3
+ RuntimeRequestId,
4
+ WorktreeSetupSnapshot,
5
+} from "@t3tools/contracts";
6
import {
7
type EnvironmentId,
8
type MessageId,
@@ -16,6 +20,7 @@ import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRunt
20
import { createContext, type MouseEvent, type ReactNode } from "react";
21
import { type LegendListRef } from "@legendapp/list/react";
22
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
23
+import type { PendingApproval } from "../../session-logic";
24
import { type ChatFileAttachment } from "../../types";
25
import { ExpandedImagePreview } from "./ExpandedImagePreview";
26
import { type AssistantCitationTarget } from "./AssistantCitationSource";
@@ -37,6 +42,12 @@ export interface TurnItemSource {
42
}
43
44
export interface TimelineRowSharedState {
45
+ pendingApprovals: ReadonlyMap<RuntimeRequestId, PendingApproval>;
46
+ respondingRequestIds: ReadonlyArray<RuntimeRequestId>;
47
+ canOperateThread: boolean;
48
+ onRespondToApproval:
49
+ | ((requestId: RuntimeRequestId, decision: ProviderApprovalDecision) => Promise<unknown>)
50
+ | undefined;
51
citationRequest: AssistantCitationTarget | null;
52
listRef: React.RefObject<LegendListRef | null>;
53
timestampFormat: TimestampFormat;