Fetch command output the server left out, for the open row and Copy output

This commit is contained in:
Callum Alpass committed 2026-11-02 23:19:54 +11:00
1 parent 81a1ee942c
commit 3ef67c5b50
5 files changed
+103 -8

No files matched your search

+7
View File
@@ -4,6 +4,7 @@ import {
type OrchestrationGetFullThreadDiffInput, type OrchestrationGetFullThreadDiffInput,
type ReviewDiffFileContentsInput, type ReviewDiffFileContentsInput,
type OrchestrationV2Checkpoint, type OrchestrationV2Checkpoint,
type OrchestrationV2TurnItem,
type TurnItemId, type TurnItemId,
MessageId, MessageId,
ORCHESTRATION_PROTOCOL_HEADER, ORCHESTRATION_PROTOCOL_HEADER,
@@ -364,6 +365,12 @@ export class T3Session {
return Effect.runPromise(this.requireConnection().rpc[ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff](input)); return Effect.runPromise(this.requireConnection().rpc[ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff](input));
} }
/** One turn item in full: the server leaves long command output out of the thread (`outputOmitted`). */
async turnItem(threadId: ThreadId, itemId: TurnItemId): Promise<OrchestrationV2TurnItem | null> {
const result = await Effect.runPromise(this.requireConnection().rpc[ORCHESTRATION_V2_WS_METHODS.getTurnItem]({ threadId, itemId }));
return result.item ?? null;
}
diffFileContents(input: ReviewDiffFileContentsInput) { diffFileContents(input: ReviewDiffFileContentsInput) {
return Effect.runPromise(this.requireConnection().rpc[WS_METHODS.reviewGetDiffFileContents](input)); return Effect.runPromise(this.requireConnection().rpc[WS_METHODS.reviewGetDiffFileContents](input));
} }
+10 -2
View File
@@ -2,7 +2,7 @@ import type { KeyEvent, MouseEvent, ScrollBoxRenderable, Selection, TextareaRend
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react"; import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
import { resolveComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch"; import { resolveComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch";
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences"; import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
import type { OrchestrationV2ThreadShell, ProviderApprovalDecision, ThreadId } from "@t3tools/contracts"; import type { OrchestrationV2ThreadShell, ProviderApprovalDecision, ThreadId, TurnItemId } from "@t3tools/contracts";
import { homedir } from "node:os"; import { homedir } from "node:os";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -925,13 +925,21 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
copyText(renderer, text); copyText(renderer, text);
say(`Copied ${label}`); say(`Copied ${label}`);
}; };
/** Long output stays on the server until it's asked for. */
const copyOmittedOutput = (source: { readonly threadId: ThreadId; readonly itemId: TurnItemId }) => () => {
say("Fetching the output…");
session.turnItem(source.threadId, source.itemId).then(
(item) => (item?.type === "command_execution" && item.output ? copy("the output", item.output) : say("The command left no output.")),
(error) => say(`Could not fetch the output: ${error instanceof Error ? error.message : String(error)}`, true),
);
};
/** The right-click menu on a message or command, as a picker like the thread menu. */ /** The right-click menu on a message or command, as a picker like the thread menu. */
const openConversationMenu = (target: ConversationTarget) => { const openConversationMenu = (target: ConversationTarget) => {
const items: PickerItem[] = const items: PickerItem[] =
target.kind === "command" target.kind === "command"
? [ ? [
{ id: "copy-command", title: "Copy command", run: () => copy("the command", target.command) }, { id: "copy-command", title: "Copy command", run: () => copy("the command", target.command) },
...(target.output ? [{ id: "copy-output", title: "Copy output", run: () => copy("the output", target.output) }] : []), ...(target.output ? [{ id: "copy-output", title: "Copy output", run: () => copy("the output", target.output) }] : target.omitted && target.source ? [{ id: "copy-output", title: "Copy output", run: copyOmittedOutput(target.source) }] : []),
] ]
: [ : [
{ id: "copy-message", title: "Copy message", run: () => copy("the message", target.text) }, { id: "copy-message", title: "Copy message", run: () => copy("the message", target.text) },
+31 -5
View File
@@ -1,8 +1,8 @@
import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core"; import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core";
import type { ProviderApprovalDecision, ThreadId } from "@t3tools/contracts"; import type { ProviderApprovalDecision, ThreadId, TurnItemId } from "@t3tools/contracts";
import { formatWorkingDurationLabel } from "@t3tools/client-runtime/state/models"; import { formatWorkingDurationLabel } from "@t3tools/client-runtime/state/models";
import { liveThoughtLine, workEntryDisplayIndicatesToolFailure, type ToolGroupSummaryKind } from "@t3tools/client-runtime/work-log/presentation"; import { liveThoughtLine, workEntryDisplayIndicatesToolFailure, type ToolGroupSummaryKind } from "@t3tools/client-runtime/work-log/presentation";
import { memo, useState, type RefObject } from "react"; import { memo, useEffect, useState, type RefObject } from "react";
import { findTextSegments } from "../model/search.ts"; import { findTextSegments } from "../model/search.ts";
import { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch"; import { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts"; import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts";
@@ -19,7 +19,8 @@ import { colors, getMarkdownStyle, toneColor } from "./theme.ts";
/** What a right-click in the conversation was on. */ /** What a right-click in the conversation was on. */
export type ConversationTarget = export type ConversationTarget =
| { readonly kind: "message"; readonly messageId: string; readonly role: "user" | "assistant" | "system"; readonly text: string } | { readonly kind: "message"; readonly messageId: string; readonly role: "user" | "assistant" | "system"; readonly text: string }
| { readonly kind: "command"; readonly command: string; readonly output: string }; /** `omitted`: the server left the output out of the thread; `source` is where to fetch it. */
| { readonly kind: "command"; readonly command: string; readonly output: string; readonly omitted: boolean; readonly source: { readonly threadId: ThreadId; readonly itemId: TurnItemId } | null };
export interface ConversationMouse { export interface ConversationMouse {
readonly respond: (decision: ProviderApprovalDecision) => void; readonly respond: (decision: ProviderApprovalDecision) => void;
@@ -229,6 +230,28 @@ function UserMessage({ text, messageId, selected, onSelect, onMenu }: { readonly
); );
} }
/** Output the server left out of the thread, fetched when its row opens. */
function OmittedOutput({ session, source }: { readonly session: T3Session; readonly source: { readonly threadId: ThreadId; readonly itemId: TurnItemId } | null }) {
const [state, setState] = useState<{ readonly text: string } | { readonly error: string } | null>(null);
const threadId = source?.threadId;
const itemId = source?.itemId;
useEffect(() => {
if (!threadId || !itemId) return;
let cancelled = false;
session.turnItem(threadId, itemId).then(
(item) => !cancelled && setState({ text: item?.type === "command_execution" ? (item.output ?? "") : "" }),
(error) => !cancelled && setState({ error: error instanceof Error ? error.message : String(error) }),
);
return () => {
cancelled = true;
};
}, [session, threadId, itemId]);
if (!source) return <text fg={colors.faint}>The output wasn't sent with the thread.</text>;
if (!state) return <text fg={colors.faint}>Loading output…</text>;
if ("error" in state) return <text fg={colors.bad}>{`Could not load the output: ${state.error}`}</text>;
return <text fg={colors.muted}>{state.text || "No output."}</text>;
}
function WorkEntry({ entry, expanded: groupExpanded, label, onOpenThread, onMenu, session, streamCommandOutput, scrollRef }: { readonly entry: WorkLogEntry; readonly expanded: boolean; readonly label: string; readonly onOpenThread: (threadId: ThreadId) => void; readonly onMenu: (target: ConversationTarget) => void; readonly session: T3Session; readonly streamCommandOutput: boolean; readonly scrollRef: RefObject<ScrollBoxRenderable | null> }) { function WorkEntry({ entry, expanded: groupExpanded, label, onOpenThread, onMenu, session, streamCommandOutput, scrollRef }: { readonly entry: WorkLogEntry; readonly expanded: boolean; readonly label: string; readonly onOpenThread: (threadId: ThreadId) => void; readonly onMenu: (target: ConversationTarget) => void; readonly session: T3Session; readonly streamCommandOutput: boolean; readonly scrollRef: RefObject<ScrollBoxRenderable | null> }) {
const [open, setExpanded] = useState<boolean | null>(null); const [open, setExpanded] = useState<boolean | null>(null);
const [hover, hoverProps] = useHover(); const [hover, hoverProps] = useHover();
@@ -241,9 +264,12 @@ function WorkEntry({ entry, expanded: groupExpanded, label, onOpenThread, onMenu
const tone = failed || entry.tone === "error" ? colors.bad : child ? colors.accent : entry.tone === "thinking" ? colors.faint : colors.muted; const tone = failed || entry.tone === "error" ? colors.bad : child ? colors.accent : entry.tone === "thinking" ? colors.faint : colors.muted;
const clickable = Boolean(command || child); const clickable = Boolean(command || child);
const text = <text fg={clickable && hover ? colors.text : tone} selectable={!clickable}>{`${failed ? "✕" : glyphFor(entry)} ${firstLine(label)}${child ? " ↗" : ""}`}</text>; const text = <text fg={clickable && hover ? colors.text : tone} selectable={!clickable}>{`${failed ? "✕" : glyphFor(entry)} ${firstLine(label)}${child ? " ↗" : ""}`}</text>;
const source = projected ? { threadId: projected.sourceThreadId, itemId: projected.sourceItemId } : null;
const streaming = expanded && streamCommandOutput && source !== null;
if (command) return <box flexDirection="column"> if (command) return <box flexDirection="column">
<box flexDirection="row" {...hoverProps} onMouseDown={(event: MouseEvent) => (isRightClick(event) ? onMenu({ kind: "command", command: command.input, output: command.output ?? "" }) : isLeftClick(event) ? setExpanded(!expanded) : undefined)}><text fg={colors.faint} selectable={false}>{expanded ? "⌄ " : "› "}</text>{text}</box> <box flexDirection="row" {...hoverProps} onMouseDown={(event: MouseEvent) => (isRightClick(event) ? onMenu({ kind: "command", command: command.input, output: command.output ?? "", omitted: command.outputOmitted === true, source }) : isLeftClick(event) ? setExpanded(!expanded) : undefined)}><text fg={colors.faint} selectable={false}>{expanded ? "⌄ " : "› "}</text>{text}</box>
{expanded && streamCommandOutput && projected ? <CommandOutput session={session} threadId={projected.sourceThreadId} itemId={projected.sourceItemId} scrollRef={scrollRef} /> {streaming ? <CommandOutput session={session} threadId={source.threadId} itemId={source.itemId} scrollRef={scrollRef} />
: expanded && command.outputOmitted ? <OmittedOutput session={session} source={source} />
: expanded ? <text fg={colors.muted}>{command.output || "No output."}</text> : null} : expanded ? <text fg={colors.muted}>{command.output || "No output."}</text> : null}
</box>; </box>;
return child ? <box {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && onOpenThread(child)}>{text}</box> : text; return child ? <box {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && onOpenThread(child)}>{text}</box> : text;
+25 -1
View File
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, test } from "bun:test"; import { afterEach, describe, expect, test } from "bun:test";
import { withApproval, withQuestion } from "./fixtures.ts"; import { omittedCommand, withApproval, withOmittedOutput, withQuestion } from "./fixtures.ts";
import { loadLayout } from "../../src/layout.ts"; import { loadLayout } from "../../src/layout.ts";
import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx"; import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx";
@@ -243,6 +243,30 @@ describe("connection", () => {
}); });
}); });
describe("command output", () => {
const session = () => fakeSession({ projection: withOmittedOutput(), results: { turnItem: { ...omittedCommand, outputOmitted: false, output: "12 pass\n0 fail" } } });
test("output the server left out loads when the command opens", async () => {
const app = await open({ session: session() });
const row = app.find("bun test");
await app.click(row.x, row.y);
await app.settle(50);
expect(app.calls("turnItem").map((call) => call.args)).toEqual([[omittedCommand.threadId, omittedCommand.id]]);
expect(app.frame()).toContain("12 pass");
});
test("Copy output fetches it first", async () => {
const app = await open({ session: session() });
const row = app.find("bun test");
await app.click(row.x, row.y, 2);
await app.type("copy output");
await app.press("return");
await app.settle(50);
expect(app.calls("turnItem")).toHaveLength(1);
expect(app.hints()).toBe("Copied the output");
});
});
describe("mouse", () => { describe("mouse", () => {
test("the header button opens the palette", async () => { test("the header button opens the palette", async () => {
const app = await open(); const app = await open();
+30
View File
@@ -31,3 +31,33 @@ export function withQuestion(): OrchestrationV2ThreadProjection {
], ],
} as unknown as OrchestrationV2ThreadProjection; } as unknown as OrchestrationV2ThreadProjection;
} }
/** A finished command whose long output the server left out of the thread. */
export const omittedCommand = {
id: "item-cmd",
threadId: v2Projection.thread.id,
runId: null,
nodeId: null,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: 0,
status: "completed",
title: null,
startedAt: at,
completedAt: at,
updatedAt: at,
type: "command_execution",
input: "bun test",
outputOmitted: true,
exitCode: 0,
} as const;
export function withOmittedOutput(): OrchestrationV2ThreadProjection {
return {
...v2Projection,
turnItems: [omittedCommand],
visibleTurnItems: [{ position: 0, visibility: "local", sourceThreadId: omittedCommand.threadId, sourceItemId: omittedCommand.id, item: omittedCommand }],
} as unknown as OrchestrationV2ThreadProjection;
}