GeezerVison is showing github.com — fix(web): keep timeline approvals answerable · pingdotgg/t3code@330d3e8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,7 @@ import { useStableCallback } from "../hooks/useStableCallback"; | 38 | 38 | import { useProjectScriptEditing } from "./chat/useProjectScriptEditing"; | 39 | 39 | import { RightPanelSurfaceContent } from "./chat/RightPanelSurfaceContent"; | 40 | 40 | import { usePendingThreadRequests } from "./chat/usePendingThreadRequests"; | | 41 | +import { useComposerTypingGuard } from "./chat/useComposerTypingGuard"; | 41 | 42 | import { isScratchProject } from "@t3tools/client-runtime/state/projects"; | 42 | 43 | import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests"; | 43 | 44 | import { | @@ -210,6 +211,7 @@ import { | 210 | 211 | } from "../sidebarPendingFileDropStore"; | 211 | 212 | import { | 212 | 213 | composerDraftHasUserContent, | | 214 | + composerTargetKey, | 213 | 215 | type ComposerFileAttachment, | 214 | 216 | type ComposerImageAttachment, | 215 | 217 | type DraftThreadEnvMode, | @@ -1312,6 +1314,10 @@ export default function ChatView(props: ChatViewProps) { | 1312 | 1314 | composerRef, | 1313 | 1315 | setThreadError, | 1314 | 1316 | }); | | 1317 | + const typingGuard = useComposerTypingGuard(composerTargetKey(composerDraftTarget), [ | | 1318 | + ...pendingApprovals.map((request) => request.requestId), | | 1319 | + ...pendingUserInputs.map((request) => request.requestId), | | 1320 | + ]); | 1315 | 1321 | const activeProposedPlan = (() => { | 1316 | 1322 | if (!latestRunSettled) { | 1317 | 1323 | return null; | @@ -3272,6 +3278,7 @@ export default function ChatView(props: ChatViewProps) { | 3272 | 3278 | <div className="relative flex min-h-0 flex-1 flex-col bg-background"> | 3273 | 3279 | <ThreadTimeline | 3274 | 3280 | pendingApprovals={pendingApprovals} | | 3281 | + heldApprovalRequestIds={typingGuard.heldRequestIds} | 3275 | 3282 | respondingRequestIds={respondingRequestIds} | 3276 | 3283 | onRespondToApproval={onRespondToApprovalStable} | 3277 | 3284 | canOperateThread={canOperateThread} | @@ -3524,6 +3531,7 @@ export default function ChatView(props: ChatViewProps) { | 3524 | 3531 | environmentUnavailable={activeEnvironmentUnavailableState} | 3525 | 3532 | activePendingApproval={activePendingApproval} | 3526 | 3533 | pendingApprovals={pendingApprovals} | | 3534 | + typingGuard={typingGuard} | 3527 | 3535 | pendingUserInputs={pendingUserInputs} | 3528 | 3536 | activePendingProgress={activePendingProgress} | 3529 | 3537 | activePendingResolvedAnswers={activePendingResolvedAnswers} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ChatComposer.tsx +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { useComposerTypingGuard } from "./useComposerTypingGuard"; | | 1 | +import type { useComposerTypingGuard } from "./useComposerTypingGuard"; | 2 | 2 | import { insertAttachmentReferencesForDraft } from "./composerAttachmentReferences"; | 3 | 3 | import { DESKTOP_PASTE_AS_TEXT_EVENT } from "../../lib/desktopPasteAsText"; | 4 | 4 | import { runtimeModeConfig, runtimeModeOptions as runtimeModes } from "./runtimeModeConfig"; | @@ -401,6 +401,7 @@ export interface ChatComposerProps { | 401 | 401 |
| 402 | 402 | activePendingApproval: PendingApproval | null; | 403 | 403 | pendingApprovals: PendingApproval[]; | | 404 | + typingGuard: ReturnType<typeof useComposerTypingGuard>; | 404 | 405 | pendingUserInputs: PendingUserInput[]; | 405 | 406 | activePendingProgress: { | 406 | 407 | questionIndex: number; | @@ -549,6 +550,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 549 | 550 | environmentUnavailable, | 550 | 551 | activePendingApproval: incomingPendingApproval, | 551 | 552 | pendingApprovals, | | 553 | + typingGuard, | 552 | 554 | pendingUserInputs: incomingPendingUserInputs, | 553 | 555 | activePendingProgress: incomingPendingProgress, | 554 | 556 | activePendingResolvedAnswers, | @@ -627,10 +629,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) | 627 | 629 | onFocus: onTypingGuardFocus, | 628 | 630 | onBlur: onTypingGuardBlur, | 629 | 631 | onSend: onTypingGuardSend, | 630 | | - } = useComposerTypingGuard(composerDraftTargetKey, [ | 631 | | - ...pendingApprovals.map((request) => request.requestId), | 632 | | - ...incomingPendingUserInputs.map((request) => request.requestId), | 633 | | - ]); | | 632 | + } = typingGuard; | 634 | 633 | const activePendingApproval = | 635 | 634 | incomingPendingApproval && !heldRequestIds.has(incomingPendingApproval.requestId) | 636 | 635 | ? incomingPendingApproval | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +78-33Lines changed: 78 additions & 33 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1036,42 +1036,39 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se | 1036 | 1036 | responseCapability: "live", | 1037 | 1037 | }, | 1038 | 1038 | ]; | 1039 | | - const entries = deriveTimelineEntriesFromVisibleTurnItems({ | 1040 | | - visibleTurnItems: [ | 1041 | | - source, | 1042 | | - ...approvals.map((approval, index) => ({ | 1043 | | - ...source, | 1044 | | - position: source.position + index + 1, | 1045 | | - sourceItemId: TurnItemId.make(`approval-${index}`), | 1046 | | - item: { | 1047 | | - ...sourceItem, | 1048 | | - id: TurnItemId.make(`approval-${index}`), | 1049 | | - type: "approval_request" as const, | 1050 | | - status: "waiting" as const, | 1051 | | - requestId: approval.requestId, | 1052 | | - requestKind: approval.requestKind, | 1053 | | - prompt: approval.detail, | 1054 | | - }, | 1055 | | - })), | 1056 | | - ], | 1057 | | - optimisticMessages: [], | 1058 | | - }); | | 1039 | + const entries = (completed = false) => | | 1040 | + deriveTimelineEntriesFromVisibleTurnItems({ | | 1041 | + visibleTurnItems: [ | | 1042 | + { ...source, item: { ...sourceItem, status: completed ? "completed" : sourceItem.status } }, | | 1043 | + ...approvals.map((approval, index) => ({ | | 1044 | + ...source, | | 1045 | + position: source.position + index + 1, | | 1046 | + sourceItemId: TurnItemId.make(`approval-${index}`), | | 1047 | + item: { | | 1048 | + ...sourceItem, | | 1049 | + id: TurnItemId.make(`approval-${index}`), | | 1050 | + type: "approval_request" as const, | | 1051 | + status: completed ? ("completed" as const) : ("waiting" as const), | | 1052 | + requestId: approval.requestId, | | 1053 | + requestKind: approval.requestKind, | | 1054 | + prompt: approval.detail, | | 1055 | + }, | | 1056 | + })), | | 1057 | + ], | | 1058 | + optimisticMessages: [], | | 1059 | + }); | 1059 | 1060 | const props = baseProps(); | 1060 | 1061 | const onRespondToApproval = vi.fn(async () => {}); | 1061 | | - const ui = ( | 1062 | | - pendingApprovals = approvals, | 1063 | | - canOperateThread = true, | 1064 | | - respondingRequestIds: RuntimeRequestId[] = [], | 1065 | | - ) => ( | | 1062 | + const ui = (overrides: Partial<TimelineProps> = {}) => ( | 1066 | 1063 | <MessagesTimeline | 1067 | 1064 | {...props} | 1068 | | - timelineEntries={entries} | 1069 | | - pendingApprovals={pendingApprovals} | 1070 | | - respondingRequestIds={respondingRequestIds} | 1071 | | - canOperateThread={canOperateThread} | | 1065 | + timelineEntries={entries()} | | 1066 | + pendingApprovals={approvals} | | 1067 | + canOperateThread | 1072 | 1068 | onRespondToApproval={onRespondToApproval} | 1073 | 1069 | isWorking | 1074 | 1070 | runningRunId={fixture.runId} | | 1071 | + {...overrides} | 1075 | 1072 | /> | 1076 | 1073 | ); | 1077 | 1074 | await using screen = await renderElement(ui()); | @@ -1081,6 +1078,12 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se | 1081 | 1078 | .toBeVisible(); | 1082 | 1079 | await expect.element(screen.getByText(approvals[0]!.detail!, { exact: true })).toBeVisible(); | 1083 | 1080 | await expect.element(screen.getByText("Needs permission to run the command")).toBeVisible(); | | 1081 | + expect( | | 1082 | + getComputedStyle(screen.getByLabelText("Command", { exact: true }).element()).userSelect, | | 1083 | + ).toBe("text"); | | 1084 | + expect( | | 1085 | + getComputedStyle(screen.getByText("Needs permission to run the command").element()).userSelect, | | 1086 | + ).toBe("text"); | 1084 | 1087 | await expect.element(screen.getByText("Safari", { exact: true })).toBeVisible(); | 1085 | 1088 | await click(screen.button("Why am I being asked this?")); | 1086 | 1089 | await expect.element(page.getByText(/an ask rule in the agent's own settings/)).toBeVisible(); | @@ -1097,24 +1100,66 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se | 1097 | 1100 | expect(onRespondToApproval).toHaveBeenLastCalledWith(commandRequest, "decline"); | 1098 | 1101 | await click(screen.button("Allow once")); | 1099 | 1102 | expect(onRespondToApproval).toHaveBeenLastCalledWith(appRequest, "accept"); | 1100 | | - await screen.rerender(ui(approvals, false)); | | 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 | + 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 | + 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 })); | 1101 | 1135 | await expect.element(screen.getByRole("button", { name: "Approve", exact: true })).toBeDisabled(); | 1102 | 1136 | expect( | 1103 | 1137 | screen.buttons("More approval options").every((button) => button.hasAttribute("disabled")), | 1104 | 1138 | ).toBe(true); | 1105 | | - await screen.rerender(ui(approvals, true, [commandRequest])); | | 1139 | + await screen.rerender(ui({ respondingRequestIds: [commandRequest] })); | 1106 | 1140 | await expect.element(screen.getByRole("button", { name: "Approve", exact: true })).toBeDisabled(); | 1107 | 1141 | await expect | 1108 | 1142 | .element(screen.getByRole("button", { name: "Allow once", exact: true })) | 1109 | 1143 | .toBeEnabled(); | 1110 | | - await screen.rerender(ui([{ ...approvals[0]!, responseCapability: "not_resumable" }])); | | 1144 | + await screen.rerender( | | 1145 | + ui({ pendingApprovals: [{ ...approvals[0]!, responseCapability: "not_resumable" }] }), | | 1146 | + ); | 1111 | 1147 | await expect | 1112 | 1148 | .element(screen.getByText("Provider process is gone. Interrupt or restart the run to respond.")) | 1113 | 1149 | .toBeVisible(); | 1114 | 1150 | expect(screen.buttons("Approve")).toHaveLength(0); | 1115 | | - await screen.rerender(ui([])); | | 1151 | + await screen.rerender( | | 1152 | + ui({ pendingApprovals: [], timelineEntries: entries(true), isWorking: false }), | | 1153 | + ); | 1116 | 1154 | await expect | 1117 | 1155 | .element(screen.getByRole("group", { name: "Command approval" })) | 1118 | 1156 | .not.toBeInTheDocument(); | 1119 | 1157 | expect(screen.text()).not.toContain("Waiting for approval"); | | 1158 | + await screen.getByRole("button", { expanded: false }).click(); | | 1159 | + await expect | | 1160 | + .element(screen.getByRole("button", { name: approvals[0]!.detail!, exact: true })) | | 1161 | + .toBeVisible(); | | 1162 | + await expect | | 1163 | + .element(screen.getByRole("button", { name: "Open the current tab", exact: true })) | | 1164 | + .toBeVisible(); | 1120 | 1165 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MessagesTimeline.tsx +43-10Lines changed: 43 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { ThreadFindTimelineContext } from "./ThreadFindProvider"; | 3 | 3 | import { MarkdownFindContext } from "./markdownFindContext"; | 4 | 4 | import { useChatCanvas } from "./ChatCanvasContext"; | 5 | 5 | import { WorkLogBlock } from "./WorkLog"; | | 6 | +import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow"; | 6 | 7 | import type { WorktreeSetupSnapshot } from "@t3tools/contracts"; | 7 | 8 | import { deriveTimelineMinimapItems } from "./timelineMinimapItems"; | 8 | 9 | import { | @@ -201,6 +202,7 @@ export interface MessagesTimelineHistoryControls { | 201 | 202 |
| 202 | 203 | interface MessagesTimelineProps { | 203 | 204 | pendingApprovals?: ReadonlyArray<PendingApproval>; | | 205 | + heldApprovalRequestIds?: ReadonlySet<string> | undefined; | 204 | 206 | respondingRequestIds?: TimelineRowSharedState["respondingRequestIds"]; | 205 | 207 | canOperateThread?: boolean; | 206 | 208 | onRespondToApproval?: TimelineRowSharedState["onRespondToApproval"]; | @@ -317,6 +319,7 @@ export function MessagesTimeline(props: MessagesTimelineProps) { | 317 | 319 |
| 318 | 320 | const ConversationTimeline = memo(function ConversationTimeline({ | 319 | 321 | pendingApprovals = EMPTY_PENDING_APPROVALS, | | 322 | + heldApprovalRequestIds, | 320 | 323 | respondingRequestIds = EMPTY_RESPONDING_REQUEST_IDS, | 321 | 324 | canOperateThread = false, | 322 | 325 | onRespondToApproval, | @@ -669,7 +672,9 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 669 | 672 | : paintedExpandedAttemptIds; | 670 | 673 |
| 671 | 674 | const pendingApprovalsByRequestId = new Map( | 672 | | - pendingApprovals.map((approval) => [approval.requestId, approval]), | | 675 | + pendingApprovals | | 676 | + .filter((approval) => !heldApprovalRequestIds?.has(approval.requestId)) | | 677 | + .map((approval) => [approval.requestId, approval]), | 673 | 678 | ); | 674 | 679 | const pendingApprovalRequestIds = new Set(pendingApprovalsByRequestId.keys()); | 675 | 680 | const rawRows = useIncrementalTimelineRows(`${listIdentityKey}\0${workspaceRoot ?? ""}`, { | @@ -690,6 +695,17 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 690 | 695 | worktreeSetup, | 691 | 696 | }); | 692 | 697 | const rows = useStableRows(rawRows, listIdentityKey); | | 698 | + const unmatchedPendingApprovals = new Map(pendingApprovalsByRequestId); | | 699 | + if (unmatchedPendingApprovals.size > 0) { | | 700 | + for (const row of rows) { | | 701 | + const entries = | | 702 | + row.kind === "work" ? row.groupedEntries : row.kind === "work-live" ? [row.entry] : []; | | 703 | + for (const entry of entries) { | | 704 | + const item = entry.projectedItem?.item; | | 705 | + if (item?.type === "approval_request") unmatchedPendingApprovals.delete(item.requestId); | | 706 | + } | | 707 | + } | | 708 | + } | 693 | 709 | // Run status/timestamps change per stream event; keep them out of shared row context. | 694 | 710 | const runs = useStableHandoffRuns(runsProp); | 695 | 711 | const minimapItems = deriveTimelineMinimapItems(rows); | @@ -702,6 +718,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 702 | 718 | restoringThreadPosition && restoreRowIndex >= 0 ? { indices: [restoreRowIndex] } : undefined; | 703 | 719 | const showsEmptyState = | 704 | 720 | rows.length === 0 && | | 721 | + unmatchedPendingApprovals.size === 0 && | 705 | 722 | !isWorking && | 706 | 723 | parentThreadLink === null && | 707 | 724 | historyControls === undefined && | @@ -743,6 +760,7 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 743 | 760 | listRef, | 744 | 761 | rememberedPosition, | 745 | 762 | restoreReady, | | 763 | + viewportRef, | 746 | 764 | ]); | 747 | 765 |
| 748 | 766 | const [timelineViewportElement, setTimelineViewportElement] = useState<HTMLDivElement | null>( | @@ -828,15 +846,6 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 828 | 846 | size: true, | 829 | 847 | shouldRestorePosition: shouldRestoreVisibleContentPosition, | 830 | 848 | }; | 831 | | - const timelineListFooter = ( | 832 | | - <TimelineListFooter | 833 | | - composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment} | 834 | | - onGrow={onFooterGrow} | 835 | | - > | 836 | | - {footer} | 837 | | - </TimelineListFooter> | 838 | | - ); | 839 | | - | 840 | 849 | const measureContentOverflow = () => | 841 | 850 | timelineContentOverflowsViewport(listRef.current?.getState?.(), { | 842 | 851 | composerInset: contentInsetEndAdjustment, | @@ -1259,6 +1268,30 @@ const ConversationTimeline = memo(function ConversationTimeline({ | 1259 | 1268 | </TimelineRowCtx> | 1260 | 1269 | ); | 1261 | 1270 | const listExtraData = { identity: listIdentityKey, rowCount: rows.length, sharedState }; | | 1271 | + const timelineListFooter = ( | | 1272 | + <TimelineListFooter | | 1273 | + composerInset={anchoredEndSpace ? 0 : contentInsetEndAdjustment} | | 1274 | + onGrow={onFooterGrow} | | 1275 | + > | | 1276 | + {footer} | | 1277 | + {unmatchedPendingApprovals.size > 0 ? ( | | 1278 | + <TimelineRowCtx value={sharedState}> | | 1279 | + <div className="messages-timeline-row-frame"> | | 1280 | + <div | | 1281 | + className="@container/chat-lane chat-content-lane overflow-x-clip" | | 1282 | + data-timeline-root="true" | | 1283 | + > | | 1284 | + <WorkLogBlock> | | 1285 | + {[...unmatchedPendingApprovals.values()].map((approval) => ( | | 1286 | + <TimelinePendingApprovalRow key={approval.requestId} approval={approval} /> | | 1287 | + ))} | | 1288 | + </WorkLogBlock> | | 1289 | + </div> | | 1290 | + </div> | | 1291 | + </TimelineRowCtx> | | 1292 | + ) : null} | | 1293 | + </TimelineListFooter> | | 1294 | + ); | 1262 | 1295 |
| 1263 | 1296 | const forwardMinimapWheel = (event: WheelEvent) => { | 1264 | 1297 | const scrollNode = listRef.current?.getScrollableNode(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelinePendingApprovalRow.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -56,7 +56,7 @@ export const TimelinePendingApprovalRow = memo(function TimelinePendingApprovalR | 56 | 56 | label={ | 57 | 57 | <code | 58 | 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 wrap-anywhere [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70" | | 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 | 60 | data-approval-detail="complete" | 61 | 61 | tabIndex={0} | 62 | 62 | > | @@ -69,7 +69,7 @@ export const TimelinePendingApprovalRow = memo(function TimelinePendingApprovalR | 69 | 69 | <span className="text-muted-foreground wrap-anywhere">{approval.appName}</span> | 70 | 70 | ) : null} | 71 | 71 | {approval.reason ? ( | 72 | | - <span className="text-muted-foreground wrap-anywhere">{approval.reason}</span> | | 72 | + <span className="text-muted-foreground select-text wrap-anywhere">{approval.reason}</span> | 73 | 73 | ) : null} | 74 | 74 | <div className="flex flex-wrap items-center gap-x-2 gap-y-1"> | 75 | 75 | {canRespond ? ( | |
|