diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index 8a88cec..5a00609 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -32,6 +32,7 @@ import { useQuestion } from "./useQuestion.ts";
import { useThreadMenu } from "./useThreadMenu.ts";
import { editInEditor } from "./editor.ts";
import { Palette } from "./Palette.tsx";
+import { ApprovalPanel } from "./ApprovalPanel.tsx";
import { QuestionPanel } from "./QuestionPanel.tsx";
import { QueuePanel } from "./QueuePanel.tsx";
import { SecretPanel } from "./SecretPanel.tsx";
@@ -910,7 +911,6 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
// The mouse in the conversation: stable callbacks, since its rows are memoized.
const conversationMouse: ConversationMouse = {
- respond: useEvent((decision: ProviderApprovalDecision) => respond(decision)),
selectTurn: useEvent((messageId: string) => turns.select(messageId)),
toggleFold: useEvent((id: string) =>
setExpandedIds((previous) => {
@@ -1173,6 +1173,10 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
) : null}
{threadId || draft ? (
+ {pendingApproval && !draft ? (
+
+ ) : (
+ <>
+ >
+ )}
) : null}
diff --git a/src/ui/ApprovalPanel.tsx b/src/ui/ApprovalPanel.tsx
new file mode 100644
index 0000000..32fbf02
--- /dev/null
+++ b/src/ui/ApprovalPanel.tsx
@@ -0,0 +1,46 @@
+import type { ThreadPendingApproval } from "@t3tools/client-runtime/state/thread-requests";
+import type { ProviderApprovalDecision } from "@t3tools/contracts";
+
+import { Button, Buttons } from "./Button.tsx";
+import { BAR, NO_BORDER } from "./edges.ts";
+import { colors } from "./theme.ts";
+
+/**
+ * A pending approval in the composer's place, as the web swaps it into the
+ * composer: the composer's own block and bar, the bar turned to the warning
+ * colour, with the same keys the hint bar names.
+ */
+export function ApprovalPanel(props: { readonly approval: ThreadPendingApproval; readonly onRespond: (decision: ProviderApprovalDecision) => void }) {
+ const { approval } = props;
+ return (
+ <>
+
+
+ {approvalTitle(approval.requestKind)}
+
+ {approval.detail ? {approval.detail} : null}
+ {approval.appName ? {approval.appName} : null}
+ {approval.reason ? {approval.reason} : null}
+
+
+
+
+
+
+
+
+ >
+ );
+}
+
+function approvalTitle(kind: string): string {
+ if (kind.includes("command")) return "Command approval";
+ if (kind.includes("read")) return "File read approval";
+ if (kind.includes("file")) return "File change approval";
+ if (kind.includes("elicitation") || kind.includes("access")) return "App access approval";
+ if (kind.includes("permission")) return "App permission approval";
+ return "Approval";
+}
diff --git a/src/ui/ThreadView.tsx b/src/ui/ThreadView.tsx
index a7ada52..77c5f3f 100644
--- a/src/ui/ThreadView.tsx
+++ b/src/ui/ThreadView.tsx
@@ -1,5 +1,5 @@
import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core";
-import type { ProviderApprovalDecision, ThreadId, TurnItemId } from "@t3tools/contracts";
+import type { ThreadId, TurnItemId } from "@t3tools/contracts";
import { formatWorkingDurationLabel } from "@t3tools/client-runtime/state/models";
import { liveThoughtLine, workEntryDisplayIndicatesToolFailure, type ToolGroupSummaryKind } from "@t3tools/client-runtime/work-log/presentation";
import { memo, useEffect, useState, type RefObject } from "react";
@@ -7,7 +7,7 @@ import { findTextSegments } from "../model/search.ts";
import { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts";
import { FindText } from "./FindText.tsx";
-import { Button, Buttons, isLeftClick, isRightClick, useHover } from "./Button.tsx";
+import { isLeftClick, isRightClick, useHover } from "./Button.tsx";
import { checkpointFileTotals, type ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
import type { Tui3Config } from "../config.ts";
@@ -27,7 +27,6 @@ export type ConversationTarget =
| { readonly kind: "command"; readonly command: string; readonly output: string; readonly omitted: boolean; readonly source: { readonly threadId: ThreadId; readonly itemId: TurnItemId } | null };
export interface ConversationMouse {
- readonly respond: (decision: ProviderApprovalDecision) => void;
/** A click on a prompt: the turn cursor, as [ and ] move it. */
readonly selectTurn: (messageId: string) => void;
/** A click on a folded turn or work group: its own expansion, apart from e. */
@@ -73,7 +72,7 @@ export function ThreadView(props: {
{props.loading && !timeline ? Loading… : null}
{history?.hasMore || history?.error ? : null}
- {timeline?.rows.map((row) => (
+ {timeline?.rows.filter((row) => !isPendingApprovalRow(row, pendingIds)).map((row) => (
;
readonly findQuery: string;
readonly activeOccurrence: number | null;
- readonly pending: boolean;
readonly workspaceRoot: string | undefined;
/** The turn footer's text for this row, or "" for none. */
readonly footer: string;
@@ -247,7 +244,7 @@ const Row = memo(function Row(props: {
);
case "event":
- return ;
+ return ;
case "worktree-setup":
return (
@@ -400,23 +397,7 @@ export function childThreadOf(entry: WorkLogEntry): ThreadId | null {
return item?.type === "subagent" ? (item.childThreadId ?? null) : null;
}
-function EventRow({ item, pending, onRespond }: { readonly onRespond: (decision: ProviderApprovalDecision) => void; readonly item: MessagesTimelineRow extends infer R ? (R extends { kind: "event"; projectedItem: { item: infer I } } ? I : never) : never; readonly pending: boolean }) {
- if (item.type === "approval_request" && pending) {
- return (
-
-
- {approvalTitle(item.requestKind)}
-
- {item.prompt ? {item.prompt} : null}
- {item.reason ? {item.reason} : null}
-
- onRespond("accept")} />
- onRespond("acceptForSession")} />
- onRespond("decline")} />
-
-
- );
- }
+function EventRow({ item }: { readonly item: MessagesTimelineRow extends infer R ? (R extends { kind: "event"; projectedItem: { item: infer I } } ? I : never) : never }) {
const block = blockFor(item, new Set());
if (!block) return null;
switch (block.kind) {
@@ -438,20 +419,24 @@ function EventRow({ item, pending, onRespond }: { readonly onRespond: (decision:
}
}
-function approvalTitle(kind: string): string {
- if (kind.includes("command")) return "Command approval";
- if (kind.includes("read")) return "File read approval";
- if (kind.includes("file")) return "File change approval";
- if (kind.includes("access")) return "App access approval";
- if (kind.includes("permission")) return "App permission approval";
- return "Approval";
-}
-
function eventRequestId(row: Extract): string | undefined {
const item = row.projectedItem.item;
return item.type === "approval_request" ? item.requestId : undefined;
}
+function entryRequestId(entry: WorkLogEntry): string | undefined {
+ const item = entry.structuredPayload;
+ return item?.type === "approval_request" ? item.requestId : undefined;
+}
+
+/** A live approval shows in the composer's place, not again as a timeline row. */
+function isPendingApprovalRow(row: MessagesTimelineRow, pendingIds: ReadonlySet): boolean {
+ if (pendingIds.size === 0) return false;
+ if (row.kind === "event") return pendingIds.has(eventRequestId(row) ?? "");
+ if (row.kind === "work-live") return pendingIds.has(entryRequestId(row.entry) ?? "");
+ return row.kind === "work" && row.groupedEntries.length > 0 && row.groupedEntries.every((entry) => pendingIds.has(entryRequestId(entry) ?? ""));
+}
+
/** A folded turn or work group: a click opens or closes just this one. */
function Toggle({ onPress, children }: { readonly onPress: () => void; readonly children: (hover: boolean) => React.ReactNode }) {
const [hover, hoverProps] = useHover();
diff --git a/test/app/app.test.tsx b/test/app/app.test.tsx
index ce99f59..f934a3a 100644
--- a/test/app/app.test.tsx
+++ b/test/app/app.test.tsx
@@ -164,6 +164,19 @@ describe("a finished turn", () => {
});
describe("approvals", () => {
+ test("the request shows in the composer's place, with its buttons, and not in the timeline", async () => {
+ const app = await open({ session: fakeSession({ projection: withApproval() }) });
+ const frame = app.frame();
+ expect(frame).toContain("Command approval");
+ expect(frame).toContain("Deletes dist/ and rebuilds it.");
+ // Only the composer block names the command; its timeline row is hidden.
+ expect(frame.split("rm -rf dist && bun run build")).toHaveLength(2);
+ expect(frame).not.toContain("Press i to type");
+ const approve = app.find("Approve");
+ await app.click(approve.x, approve.y);
+ expect(app.calls("respond").map((call) => call.args[2])).toEqual(["accept"]);
+ });
+
test("y, Y and n answer the request", async () => {
const app = await open({ session: fakeSession({ projection: withApproval() }) });
expect(app.hints()).toStartWith("y approve · Y always · n decline · j/k threads");
diff --git a/test/app/fixtures.ts b/test/app/fixtures.ts
index 8b30ce7..e251b7a 100644
--- a/test/app/fixtures.ts
+++ b/test/app/fixtures.ts
@@ -9,11 +9,34 @@ const after = (seconds: number) => DateTime.makeUnsafe(DateTime.toEpochMillis(at
/** The thread with a command waiting for approval. */
export function withApproval(supportsFeedback = false): OrchestrationV2ThreadProjection {
+ const item = {
+ id: "item-approval",
+ threadId: v2Projection.thread.id,
+ runId: null,
+ nodeId: null,
+ providerThreadId: null,
+ providerTurnId: null,
+ nativeItemRef: null,
+ parentItemId: null,
+ ordinal: 0,
+ status: "waiting",
+ title: null,
+ startedAt: at,
+ completedAt: null,
+ updatedAt: at,
+ type: "approval_request",
+ requestId: "approval-1",
+ requestKind: "command",
+ prompt: "rm -rf dist && bun run build",
+ reason: "Deletes dist/ and rebuilds it.",
+ };
return {
...v2Projection,
runtimeRequests: [
{ id: "approval-1", nodeId: "node-1", providerTurnId: null, nativeRequestRef: null, kind: "command", status: "pending", responseCapability: { type: "live", providerSessionId: "session-1", ...(supportsFeedback ? { supportsFeedback } : {}) }, createdAt: at, resolvedAt: null },
],
+ turnItems: [item],
+ visibleTurnItems: [{ position: 0, visibility: "local", sourceThreadId: v2Projection.thread.id, sourceItemId: item.id, item }],
} as unknown as OrchestrationV2ThreadProjection;
}