Fetch command output the server left out, for the open row and Copy output
This commit is contained in:
1 parent
81a1ee942c
commit
3ef67c5b50
5 files changed
+103
-8
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
type OrchestrationGetFullThreadDiffInput,
|
||||
type ReviewDiffFileContentsInput,
|
||||
type OrchestrationV2Checkpoint,
|
||||
type OrchestrationV2TurnItem,
|
||||
type TurnItemId,
|
||||
MessageId,
|
||||
ORCHESTRATION_PROTOCOL_HEADER,
|
||||
@@ -364,6 +365,12 @@ export class T3Session {
|
||||
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) {
|
||||
return Effect.runPromise(this.requireConnection().rpc[WS_METHODS.reviewGetDiffFileContents](input));
|
||||
}
|
||||
|
||||
+10
-2
@@ -2,7 +2,7 @@ import type { KeyEvent, MouseEvent, ScrollBoxRenderable, Selection, TextareaRend
|
||||
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
|
||||
import { resolveComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch";
|
||||
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 { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
@@ -925,13 +925,21 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
||||
copyText(renderer, text);
|
||||
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. */
|
||||
const openConversationMenu = (target: ConversationTarget) => {
|
||||
const items: PickerItem[] =
|
||||
target.kind === "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) },
|
||||
|
||||
+31
-5
@@ -1,8 +1,8 @@
|
||||
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 { 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 { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
|
||||
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. */
|
||||
export type ConversationTarget =
|
||||
| { 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 {
|
||||
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> }) {
|
||||
const [open, setExpanded] = useState<boolean | null>(null);
|
||||
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 clickable = Boolean(command || child);
|
||||
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">
|
||||
<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>
|
||||
{expanded && streamCommandOutput && projected ? <CommandOutput session={session} threadId={projected.sourceThreadId} itemId={projected.sourceItemId} scrollRef={scrollRef} />
|
||||
<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>
|
||||
{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}
|
||||
</box>;
|
||||
return child ? <box {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && onOpenThread(child)}>{text}</box> : text;
|
||||
|
||||
Reference in new issue
Block a user