Add diffs, git actions, servers, automations and a command palette
- Details rows are actionable: view the working-tree diff (whole or per file), run the web app's git quick action or menu after a confirmation, stop a local server, run or toggle an automation, open lineage threads. - Command palette (ctrl+k or :) searching commands and threads with T3's own scoring. - Subagent work entries link to their child threads; u goes to the parent. - Threads open scrolled to the bottom. - Mouse: thread rows, collapsed sections, details rows, palette, composer. - The / filter opens in the thread list. - Multi-line composer: shift+enter, ctrl+j, or a trailing backslash; it grows to 8 lines. - The credential asks for filesystem:read, source-control:write and terminal:operate, and is reissued when a stored one lacks them.
This commit is contained in:
1 parent
248603d9ae
commit
ed36949fa7
15 files changed
+1235
-192
No files matched your search
+434
-66
@@ -8,29 +8,41 @@ import {
|
||||
togglePendingUserInputOptionSelection,
|
||||
type PendingUserInputDraftAnswer,
|
||||
} from "@t3tools/client-runtime/state/pending-user-input";
|
||||
import type { ProviderApprovalDecision, ThreadId } from "@t3tools/contracts";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { DiscoveredLocalServer, ProviderApprovalDecision, ScheduledTask, ThreadId } from "@t3tools/contracts";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import type { ShellState, T3Session, ThreadState, VcsState } from "../client/session.ts";
|
||||
import { detailsCwd, RUNTIME_MODE_LABELS, threadDetails } from "../model/details.ts";
|
||||
import type { FeedState, ShellState, T3Session, ThreadState, VcsState } from "../client/session.ts";
|
||||
import { detailsActions, detailsCwd, RUNTIME_MODE_LABELS, threadDetails, type DetailsAction, type GitAction } from "../model/details.ts";
|
||||
import { paletteEntries, paletteGroups, type PaletteCommand } from "../model/palette.ts";
|
||||
import { buildTimeline, type Timeline } from "../model/timeline.ts";
|
||||
import { threadRows, type Section } from "../model/threads.ts";
|
||||
import { QuestionPanel } from "./QuestionPanel.tsx";
|
||||
import { ConfirmBar, type Confirmation } from "./ConfirmBar.tsx";
|
||||
import { DetailsPanel } from "./DetailsPanel.tsx";
|
||||
import { DiffView, type DiffState } from "./DiffView.tsx";
|
||||
import { Palette } from "./Palette.tsx";
|
||||
import { QuestionPanel } from "./QuestionPanel.tsx";
|
||||
import { colors } from "./theme.ts";
|
||||
import { ThreadList } from "./ThreadList.tsx";
|
||||
import { ThreadView } from "./ThreadView.tsx";
|
||||
|
||||
/** "input": typing goes to the composer. "nav": single keys move, scroll, approve. */
|
||||
type Mode = "input" | "nav" | "filter";
|
||||
/**
|
||||
* "input": typing goes to the composer. "nav": single keys move, scroll, approve.
|
||||
* "details": j/k move through the details panel. The rest are overlays with their own input.
|
||||
*/
|
||||
type Mode = "input" | "nav" | "filter" | "details" | "palette" | "confirm";
|
||||
|
||||
/** Holding j/k skims past threads; only subscribe to one you stop on. */
|
||||
const SUBSCRIBE_DELAY_MS = 120;
|
||||
/** Opening a thread marks it read once you've stayed this long, as in the web app. */
|
||||
const VISIT_DELAY_MS = 1_500;
|
||||
const MAX_COMPOSER_LINES = 6;
|
||||
const MAX_COMPOSER_LINES = 8;
|
||||
/** Sections folded to a count unless you filter or press z, like the web sidebar's. */
|
||||
const FOLDED_SECTIONS: readonly Section[] = ["snoozed", "settled"];
|
||||
/** The details column opens by itself on terminals at least this wide. */
|
||||
const DETAILS_AUTO_WIDTH = 160;
|
||||
const DETAILS_WIDTH = 38;
|
||||
/** Below this, the details panel takes the conversation's place instead of a column beside it. */
|
||||
const MIN_CONVERSATION_WIDTH = 70;
|
||||
|
||||
const COMPOSER_KEYS = [
|
||||
{ name: "return", action: "submit" },
|
||||
@@ -38,12 +50,6 @@ const COMPOSER_KEYS = [
|
||||
{ name: "j", ctrl: true, action: "newline" },
|
||||
] as const;
|
||||
|
||||
/** The details column opens by itself on terminals at least this wide. */
|
||||
const DETAILS_AUTO_WIDTH = 160;
|
||||
const DETAILS_WIDTH = 36;
|
||||
/** Below this, the details panel takes the conversation's place instead of a column beside it. */
|
||||
const MIN_CONVERSATION_WIDTH = 70;
|
||||
|
||||
interface QuestionDraft {
|
||||
readonly index: number;
|
||||
readonly answers: Record<string, PendingUserInputDraftAnswer>;
|
||||
@@ -51,16 +57,24 @@ interface QuestionDraft {
|
||||
|
||||
export function App(props: { readonly session: T3Session; readonly attachThreadId?: ThreadId }) {
|
||||
const { session, attachThreadId } = props;
|
||||
const attached = attachThreadId !== undefined;
|
||||
const renderer = useRenderer();
|
||||
const { width, height } = useTerminalDimensions();
|
||||
const [shell, setShell] = useState<ShellState>(session.getShell());
|
||||
// Any thread, listed or not: subagents open here too.
|
||||
const [selectedId, setSelectedId] = useState<ThreadId | undefined>(attachThreadId);
|
||||
const [mode, setMode] = useState<Mode>(attachThreadId ? "input" : "nav");
|
||||
const [mode, setMode] = useState<Mode>(attached ? "input" : "nav");
|
||||
const [filter, setFilter] = useState("");
|
||||
const [showFolded, setShowFolded] = useState(false);
|
||||
const [expandAll, setExpandAll] = useState(false);
|
||||
/** null follows the terminal width; d sets it for the rest of the session. */
|
||||
const [detailsPref, setDetailsPref] = useState<boolean | null>(null);
|
||||
const [detailsSelected, setDetailsSelected] = useState<string | null>(null);
|
||||
const [diff, setDiff] = useState<DiffState | null>(null);
|
||||
const [confirmation, setConfirmation] = useState<Confirmation | null>(null);
|
||||
const [confirmMessage, setConfirmMessage] = useState("");
|
||||
const [paletteQuery, setPaletteQuery] = useState("");
|
||||
const [paletteIndex, setPaletteIndex] = useState(0);
|
||||
const [flash, setFlash] = useState<{ text: string; bad?: boolean } | null>(null);
|
||||
const [composerLines, setComposerLines] = useState(1);
|
||||
const [composerEmpty, setComposerEmpty] = useState(true);
|
||||
@@ -69,6 +83,8 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const scrollRef = useRef<ScrollBoxRenderable | null>(null);
|
||||
const composerRef = useRef<TextareaRenderable | null>(null);
|
||||
const drafts = useRef(new Map<string, string>());
|
||||
/** Where mode returns to when an overlay closes. */
|
||||
const returnMode = useRef<Mode>("nav");
|
||||
|
||||
useEffect(() => session.onShell(setShell), [session]);
|
||||
// Drives "Working for 12s" and the sidebar's durations.
|
||||
@@ -85,18 +101,21 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
[allRows, unfold],
|
||||
);
|
||||
// Selection is a thread id, not an index, so the list can reorder underneath it.
|
||||
const selectedIndex = Math.max(0, rows.findIndex((row) => row.thread.id === selectedId));
|
||||
const threadId = attachThreadId ?? rows[selectedIndex]?.thread.id;
|
||||
const threadId = selectedId ?? rows[0]?.thread.id;
|
||||
const selectedIndex = rows.findIndex((row) => row.thread.id === threadId);
|
||||
const threadRow = allRows.find((row) => row.thread.id === threadId);
|
||||
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId);
|
||||
// Pin the initial selection to a thread, or it would follow whatever sorts first.
|
||||
useEffect(() => {
|
||||
if (selectedId === undefined && rows[0]) setSelectedId(rows[0].thread.id);
|
||||
}, [selectedId, rows]);
|
||||
const move = (delta: number) => {
|
||||
const next = rows[Math.min(rows.length - 1, Math.max(0, selectedIndex + delta))];
|
||||
if (next) setSelectedId(next.thread.id);
|
||||
};
|
||||
|
||||
const openThread = useCallback((id: ThreadId) => {
|
||||
setSelectedId(id);
|
||||
setDiff(null);
|
||||
setDetailsSelected(null);
|
||||
setMode((current) => (current === "details" ? "nav" : current));
|
||||
}, []);
|
||||
|
||||
const [watchedId, setWatchedId] = useState(threadId);
|
||||
useEffect(() => {
|
||||
@@ -119,20 +138,6 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
return () => clearTimeout(timer);
|
||||
}, [session, watchedId, unread]);
|
||||
|
||||
const showDetails = detailsPref ?? width >= DETAILS_AUTO_WIDTH;
|
||||
const project = threadShell ? shell.snapshot?.projects.find((candidate) => candidate.id === threadShell.projectId) : undefined;
|
||||
const vcsCwd = threadShell ? detailsCwd(threadShell, project) : null;
|
||||
const [vcs, setVcs] = useState<{ cwd: string; state: VcsState } | null>(null);
|
||||
useEffect(() => {
|
||||
if (!showDetails || !vcsCwd || shell.status.type !== "live") return;
|
||||
return session.watchVcs(vcsCwd, (state) => setVcs({ cwd: vcsCwd, state }));
|
||||
}, [session, showDetails, vcsCwd, shell.status.type]);
|
||||
const vcsState = vcs?.cwd === vcsCwd ? vcs.state : null;
|
||||
const details = useMemo(
|
||||
() => (showDetails && threadShell ? threadDetails(threadShell, project, vcsState, shell.snapshot) : null),
|
||||
[showDetails, threadShell, project, vcsState, shell.snapshot],
|
||||
);
|
||||
|
||||
const previousTimeline = useRef<{ id: string; timeline: Timeline } | null>(null);
|
||||
const timeline = useMemo(() => {
|
||||
if (!thread?.projection || !watchedId) return null;
|
||||
@@ -147,6 +152,70 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const questionDraft = pendingInput ? (questionDrafts.get(pendingInput.requestId) ?? { index: 0, answers: {} }) : undefined;
|
||||
const working = current?.isWorking ?? false;
|
||||
|
||||
// A thread opens at its latest message: once its first snapshot renders, jump to the bottom.
|
||||
const loaded = current !== null;
|
||||
useEffect(() => {
|
||||
if (!loaded) return;
|
||||
const timer = setTimeout(() => scrollRef.current?.scrollTo(scrollRef.current.scrollHeight), 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [loaded, watchedId]);
|
||||
|
||||
const projection = watchedId === threadId ? thread?.projection : null;
|
||||
const appThread = projection?.thread;
|
||||
const title = threadShell?.title ?? appThread?.title ?? "Thread";
|
||||
const parentId = (threadShell?.lineage ?? appThread?.lineage)?.parentThreadId ?? null;
|
||||
const parent = parentId
|
||||
? { threadId: parentId, title: shell.snapshot?.threads.find((other) => other.id === parentId)?.title ?? "Parent thread" }
|
||||
: undefined;
|
||||
|
||||
const move = (delta: number) => {
|
||||
// From a subagent, which isn't listed, j/k carry on from its parent's row.
|
||||
const parentIndex = rows.findIndex((row) => row.thread.id === parentId);
|
||||
const from = selectedIndex >= 0 ? selectedIndex : parentIndex >= 0 ? parentIndex : delta > 0 ? -1 : rows.length;
|
||||
const next = rows[Math.min(rows.length - 1, Math.max(0, from + delta))];
|
||||
if (next) openThread(next.thread.id);
|
||||
};
|
||||
|
||||
// Details: git status for the thread's folder, plus the server-wide servers and automations lists.
|
||||
const showDetails = detailsPref ?? width >= DETAILS_AUTO_WIDTH;
|
||||
const project = threadShell ? shell.snapshot?.projects.find((candidate) => candidate.id === threadShell.projectId) : undefined;
|
||||
const vcsCwd = threadShell ? detailsCwd(threadShell, project) : null;
|
||||
const live = shell.status.type === "live";
|
||||
const [vcs, setVcs] = useState<{ cwd: string; state: VcsState } | null>(null);
|
||||
useEffect(() => {
|
||||
if (!showDetails || !vcsCwd || !live) return;
|
||||
return session.watchVcs(vcsCwd, (state) => setVcs({ cwd: vcsCwd, state }));
|
||||
}, [session, showDetails, vcsCwd, live]);
|
||||
const [servers, setServers] = useState<FeedState<DiscoveredLocalServer> | null>(null);
|
||||
const [automations, setAutomations] = useState<FeedState<ScheduledTask> | null>(null);
|
||||
useEffect(() => {
|
||||
if (!live) return;
|
||||
const stopServers = session.watchServers(setServers);
|
||||
const stopAutomations = session.watchAutomations(setAutomations);
|
||||
return () => {
|
||||
stopServers();
|
||||
stopAutomations();
|
||||
};
|
||||
}, [session, live]);
|
||||
const vcsState = vcs?.cwd === vcsCwd ? vcs.state : null;
|
||||
const details = useMemo(
|
||||
() =>
|
||||
threadShell
|
||||
? threadDetails({
|
||||
thread: threadShell,
|
||||
project,
|
||||
vcs: vcsState,
|
||||
snapshot: shell.snapshot,
|
||||
subagents: projection?.subagents ?? [],
|
||||
servers: servers?.items ?? [],
|
||||
automations: automations?.items ?? [],
|
||||
now,
|
||||
})
|
||||
: null,
|
||||
[threadShell, project, vcsState, shell.snapshot, projection?.subagents, servers, automations, now],
|
||||
);
|
||||
const actions = useMemo(() => (details ? detailsActions(details) : []), [details]);
|
||||
|
||||
const say = (text: string, bad = false) => {
|
||||
setFlash({ text, bad });
|
||||
setTimeout(() => setFlash((value) => (value?.text === text ? null : value)), 4000);
|
||||
@@ -154,7 +223,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
const run = (label: string, action: () => Promise<unknown>) => {
|
||||
action().then(
|
||||
() => say(label),
|
||||
(error) => say(`${label} failed: ${error instanceof Error ? error.message : String(error)}`, true),
|
||||
(error) => say(`${label} failed: ${messageOf(error)}`, true),
|
||||
);
|
||||
};
|
||||
const respond = (decision: ProviderApprovalDecision) => {
|
||||
@@ -162,6 +231,100 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
run(decision === "decline" ? "Declined" : "Approved", () => session.respond(threadId, pendingApproval.requestId, decision));
|
||||
};
|
||||
|
||||
const confirm = (next: Confirmation) => {
|
||||
if (mode !== "confirm" && mode !== "palette") returnMode.current = mode;
|
||||
setConfirmMessage("");
|
||||
setConfirmation(next);
|
||||
setMode("confirm");
|
||||
};
|
||||
const closeOverlay = () => {
|
||||
setConfirmation(null);
|
||||
setMode(returnMode.current);
|
||||
};
|
||||
|
||||
const openDiff = (path: string | null) => {
|
||||
if (!vcsCwd) return;
|
||||
const cwd = vcsCwd;
|
||||
setDiff({ cwd, path, status: "loading" });
|
||||
session.workingTreeDiff(cwd, path ?? undefined).then(
|
||||
(source) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "ready", patch: source?.diff ?? "", truncated: source?.truncated ?? false } : value)),
|
||||
(error) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "error", error: messageOf(error) } : value)),
|
||||
);
|
||||
};
|
||||
|
||||
const runGit = (git: GitAction) => {
|
||||
if (!vcsCwd || !threadShell) return;
|
||||
const cwd = vcsCwd;
|
||||
const branch = details?.branch?.name;
|
||||
const onDefault = vcsState?.local?.isDefaultRef === true;
|
||||
confirm({
|
||||
title: `${git.label}?`,
|
||||
detail: `${branch ? `On ${branch}` : "In"} · ${details?.workspace.path ?? cwd}${onDefault && git.action !== "create_pr" ? " · this is the default branch" : ""}`,
|
||||
...(git.commits ? { message: { placeholder: "Leave blank to have one written for you" } } : {}),
|
||||
confirmLabel: git.label.toLowerCase(),
|
||||
run: (message) => {
|
||||
say(`${git.label}…`);
|
||||
session
|
||||
.runGitAction(
|
||||
{ cwd, action: git.action, threadId: threadShell.id, projectId: threadShell.projectId, ...(git.commits && message.trim() ? { commitMessage: message.trim() } : {}) },
|
||||
(event) => {
|
||||
if (event.kind === "phase_started") setFlash({ text: `${event.label}…` });
|
||||
if (event.kind === "hook_started") setFlash({ text: `Running ${event.hookName} hook…` });
|
||||
},
|
||||
)
|
||||
.then(
|
||||
(result) => say(result.toast.description ? `${result.toast.title}: ${result.toast.description}` : result.toast.title),
|
||||
(error) => say(`${git.label} failed: ${messageOf(error)}`, true),
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const stopServer = (server: DiscoveredLocalServer) =>
|
||||
confirm({
|
||||
title: `Stop ${server.url}?`,
|
||||
...(server.processName ? { detail: `${server.processName}${server.pid ? ` (pid ${server.pid})` : ""}` } : {}),
|
||||
confirmLabel: "stop",
|
||||
run: () => run("Server stopped", () => session.stopServer(server)),
|
||||
});
|
||||
const runAutomation = (task: ScheduledTask) =>
|
||||
confirm({ title: `Run "${task.title}" now?`, detail: firstLine(task.prompt), confirmLabel: "run", run: () => run("Automation started", () => session.runAutomationNow(task.id)) });
|
||||
const toggleAutomation = (task: ScheduledTask) => run(task.enabled ? "Automation turned off" : "Automation turned on", () => session.setAutomationEnabled(task.id, !task.enabled));
|
||||
|
||||
const activate = (action: DetailsAction) => {
|
||||
setDetailsSelected(action.id);
|
||||
switch (action.kind) {
|
||||
case "diff":
|
||||
return openDiff(action.path);
|
||||
case "git":
|
||||
return runGit(action.git);
|
||||
case "thread":
|
||||
return openThread(action.threadId);
|
||||
case "server":
|
||||
return stopServer(action.server);
|
||||
case "automation":
|
||||
return runAutomation(action.task);
|
||||
}
|
||||
};
|
||||
const activateById = (id: string) => {
|
||||
const action = actions.find((candidate) => candidate.id === id);
|
||||
if (!action) return;
|
||||
if (action.kind !== "thread") setMode("details");
|
||||
activate(action);
|
||||
};
|
||||
const moveDetails = (delta: number) => {
|
||||
if (actions.length === 0) return;
|
||||
const index = actions.findIndex((action) => action.id === detailsSelected);
|
||||
const next = actions[index < 0 ? (delta > 0 ? 0 : actions.length - 1) : Math.min(actions.length - 1, Math.max(0, index + delta))];
|
||||
if (next) setDetailsSelected(next.id);
|
||||
};
|
||||
const focusDetails = () => {
|
||||
if (!threadShell) return;
|
||||
if (!showDetails) setDetailsPref(true);
|
||||
if (!actions.some((action) => action.id === detailsSelected)) setDetailsSelected(actions[0]?.id ?? null);
|
||||
setMode("details");
|
||||
};
|
||||
|
||||
const clearComposer = () => {
|
||||
composerRef.current?.setText("");
|
||||
if (threadId) drafts.current.delete(threadId);
|
||||
@@ -200,7 +363,16 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
|
||||
/** Enter in the composer; `alternate` is alt+enter, which flips steer and queue. */
|
||||
const submit = (alternate = false) => {
|
||||
const text = composerRef.current?.plainText.trim() ?? "";
|
||||
const composer = composerRef.current;
|
||||
const raw = composer?.plainText ?? "";
|
||||
// A trailing backslash continues onto a new line, for terminals that can't send shift+enter.
|
||||
if (!alternate && composer && raw.endsWith("\\")) {
|
||||
composer.setText(raw.slice(0, -1));
|
||||
composer.gotoBufferEnd();
|
||||
composer.newLine();
|
||||
return;
|
||||
}
|
||||
const text = raw.trim();
|
||||
if (!threadId) return;
|
||||
if (pendingInput && questionDraft) {
|
||||
const question = pendingInput.questions[questionDraft.index];
|
||||
@@ -222,7 +394,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
|
||||
const loadEarlier = () => {
|
||||
if (!watchedId) return;
|
||||
session.loadEarlier(watchedId).catch((error) => say(`Could not load earlier turns: ${error instanceof Error ? error.message : String(error)}`, true));
|
||||
session.loadEarlier(watchedId).catch((error) => say(`Could not load earlier turns: ${messageOf(error)}`, true));
|
||||
};
|
||||
|
||||
const quit = () => {
|
||||
@@ -234,18 +406,93 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
|
||||
const scrollPage = (direction: 1 | -1) => scrollRef.current?.scrollBy(direction * Math.max(1, height - 10));
|
||||
|
||||
// The command palette: everything the keys do, plus what the details panel offers.
|
||||
const commands: (PaletteCommand & { readonly run: () => void })[] = [];
|
||||
const command = (id: string, label: string, action: () => void, extra: Omit<PaletteCommand, "id" | "title"> = {}) => commands.push({ id, title: label, run: action, ...extra });
|
||||
if (pendingApproval) {
|
||||
command("approve", "Approve request", () => respond("accept"), { shortcut: "y" });
|
||||
command("approve-session", "Always allow this session", () => respond("acceptForSession"), { shortcut: "Y" });
|
||||
command("decline", "Decline request", () => respond("decline"), { shortcut: "n" });
|
||||
}
|
||||
if (threadId && pendingInput?.dismissible) command("dismiss", "Dismiss question", () => run("Dismissed", () => session.dismissQuestion(threadId, pendingInput.requestId)), { shortcut: "x" });
|
||||
if (threadId) command("type", "Write a message", () => setMode("input"), { shortcut: "i", keywords: ["compose", "send", "steer"] });
|
||||
if (threadId && working) command("stop", "Stop thread", () => run("Stop requested", () => session.stopThread(threadId)), { shortcut: "S", keywords: ["interrupt", "cancel"] });
|
||||
if (details?.changes && details.changes.files.length > 0) command("diff", "View uncommitted changes", () => openDiff(null), { keywords: ["diff", "changes"] });
|
||||
for (const action of actions) {
|
||||
if (action.kind === "git") command(action.id, `Git: ${action.git.label}`, () => runGit(action.git), { keywords: ["commit", "push", "pull request", "pr"] });
|
||||
if (action.kind === "server") command(action.id, `Stop server ${action.server.url}`, () => stopServer(action.server), { keywords: ["port", "kill"] });
|
||||
if (action.kind === "automation") {
|
||||
command(action.id, `Run automation: ${action.task.title}`, () => runAutomation(action.task), { keywords: ["scheduled", "task"] });
|
||||
command(`${action.id}:toggle`, `${action.task.enabled ? "Turn off" : "Turn on"} automation: ${action.task.title}`, () => toggleAutomation(action.task), { keywords: ["scheduled", "task", "enable", "disable"] });
|
||||
}
|
||||
}
|
||||
if (parent) command("parent", `Go to parent: ${parent.title}`, () => openThread(parent.threadId), { shortcut: "u" });
|
||||
command("details", showDetails ? "Hide thread details" : "Show thread details", () => setDetailsPref(!showDetails), { shortcut: "d", keywords: ["panel", "info"] });
|
||||
if (threadShell) command("focus-details", "Focus thread details", focusDetails, { shortcut: "l" });
|
||||
command("expand", expandAll ? "Collapse work" : "Expand all work", () => setExpandAll(!expandAll), { shortcut: "e", keywords: ["fold", "tool calls"] });
|
||||
if (thread?.history.hasMore) command("earlier", "Load earlier turns", loadEarlier, { shortcut: "o", keywords: ["history", "older"] });
|
||||
if (!attached) {
|
||||
command("filter", "Filter threads", () => setMode("filter"), { shortcut: "/", keywords: ["search"] });
|
||||
command("settled", showFolded ? "Hide settled threads" : "Show settled threads", () => setShowFolded(!showFolded), { shortcut: "z", keywords: ["snoozed", "archive"] });
|
||||
}
|
||||
command("quit", "Quit tui3", quit, { shortcut: "q", keywords: ["exit"] });
|
||||
|
||||
const commandKey = commands.map((candidate) => `${candidate.id}:${candidate.title}`).join("|");
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- commands are rebuilt each render; commandKey tracks what changed.
|
||||
const groups = useMemo(() => (mode === "palette" ? paletteGroups({ query: paletteQuery, commands, snapshot: shell.snapshot, now }) : []), [mode, paletteQuery, commandKey, shell.snapshot]);
|
||||
const entries = paletteEntries(groups);
|
||||
const openPalette = () => {
|
||||
if (mode !== "palette" && mode !== "confirm") returnMode.current = mode === "filter" ? "nav" : mode;
|
||||
setPaletteQuery("");
|
||||
setPaletteIndex(0);
|
||||
setMode("palette");
|
||||
};
|
||||
const pick = (index: number) => {
|
||||
const entry = entries[index];
|
||||
if (!entry) return;
|
||||
setMode(returnMode.current === "details" ? "nav" : returnMode.current);
|
||||
if (entry.kind === "thread") return openThread(entry.threadId);
|
||||
commands.find((candidate) => candidate.id === entry.command.id)?.run();
|
||||
};
|
||||
|
||||
/** Keys that work in every mode. Returns true when handled. */
|
||||
const globalKey = (key: KeyEvent): boolean => {
|
||||
if (key.ctrl && key.name === "c") return quit(), true;
|
||||
if (key.name === "pagedown" || (key.ctrl && key.name === "d")) return scrollPage(1), true;
|
||||
if (key.name === "pageup" || (key.ctrl && key.name === "u")) return scrollPage(-1), true;
|
||||
if (!attachThreadId && ((key.ctrl && key.name === "n") || (key.meta && key.name === "down"))) return move(1), true;
|
||||
if (!attachThreadId && ((key.ctrl && key.name === "p") || (key.meta && key.name === "up"))) return move(-1), true;
|
||||
if (key.ctrl && key.name === "k") return openPalette(), true;
|
||||
// One-line inputs keep ctrl+u and ctrl+d for editing.
|
||||
const lineInput = mode === "filter" || mode === "palette" || mode === "confirm";
|
||||
if (key.name === "pagedown" || (!lineInput && key.ctrl && key.name === "d")) return scrollPage(1), true;
|
||||
if (key.name === "pageup" || (!lineInput && key.ctrl && key.name === "u")) return scrollPage(-1), true;
|
||||
if (!attached && ((key.ctrl && key.name === "n") || (key.meta && key.name === "down"))) return move(1), true;
|
||||
if (!attached && ((key.ctrl && key.name === "p") || (key.meta && key.name === "up"))) return move(-1), true;
|
||||
if (mode === "input" && key.meta && key.name === "return") return submit(true), true;
|
||||
return false;
|
||||
};
|
||||
|
||||
useKeyboard((key) => {
|
||||
if (mode === "palette") {
|
||||
if (key.ctrl && key.name === "c") return quit();
|
||||
if (key.name === "escape" || (key.ctrl && key.name === "k")) setMode(returnMode.current);
|
||||
else if (key.name === "down" || (key.ctrl && key.name === "n")) setPaletteIndex((index) => Math.min(entries.length - 1, index + 1));
|
||||
else if (key.name === "up" || (key.ctrl && key.name === "p")) setPaletteIndex((index) => Math.max(0, index - 1));
|
||||
else return;
|
||||
return key.preventDefault();
|
||||
}
|
||||
if (mode === "confirm") {
|
||||
if (key.ctrl && key.name === "c") return quit();
|
||||
if (key.name === "escape") {
|
||||
closeOverlay();
|
||||
return key.preventDefault();
|
||||
}
|
||||
// Without a message box, enter confirms here; with one, the box's submit does.
|
||||
if (key.name === "return" && !confirmation?.message) {
|
||||
const pending = confirmation;
|
||||
closeOverlay();
|
||||
pending?.run("");
|
||||
return key.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (globalKey(key)) return key.preventDefault();
|
||||
const digit = /^[1-9]$/.test(key.name) && !key.ctrl && !key.meta ? Number(key.name) - 1 : -1;
|
||||
if (digit >= 0 && pendingInput && (mode === "nav" || (mode === "input" && composerEmpty))) {
|
||||
@@ -260,19 +507,58 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
return;
|
||||
}
|
||||
const scroll = scrollRef.current;
|
||||
if (mode === "details") {
|
||||
switch (key.name) {
|
||||
case "j":
|
||||
case "down":
|
||||
return moveDetails(1);
|
||||
case "k":
|
||||
case "up":
|
||||
return moveDetails(-1);
|
||||
case "return":
|
||||
case "space": {
|
||||
const action = actions.find((candidate) => candidate.id === detailsSelected);
|
||||
if (action) activate(action);
|
||||
return key.preventDefault();
|
||||
}
|
||||
case "t": {
|
||||
const action = actions.find((candidate) => candidate.id === detailsSelected);
|
||||
if (action?.kind === "automation") toggleAutomation(action.task);
|
||||
return;
|
||||
}
|
||||
case "escape":
|
||||
if (diff) return setDiff(null);
|
||||
setDetailsSelected(null);
|
||||
return setMode("nav");
|
||||
case "h":
|
||||
case "left":
|
||||
setDetailsSelected(null);
|
||||
return setMode("nav");
|
||||
}
|
||||
}
|
||||
switch (key.name) {
|
||||
case "q":
|
||||
if (diff) return setDiff(null);
|
||||
return quit();
|
||||
case "escape":
|
||||
if (diff) setDiff(null);
|
||||
return;
|
||||
case "j":
|
||||
case "down":
|
||||
return attachThreadId ? scroll?.scrollBy(1) : move(1);
|
||||
return attached || diff ? scroll?.scrollBy(1) : move(1);
|
||||
case "k":
|
||||
case "up":
|
||||
return attachThreadId ? scroll?.scrollBy(-1) : move(-1);
|
||||
return attached || diff ? scroll?.scrollBy(-1) : move(-1);
|
||||
case "g":
|
||||
return key.shift ? scroll?.scrollTo(scroll.scrollHeight) : scroll?.scrollTo(0);
|
||||
case "d":
|
||||
return setDetailsPref(!showDetails);
|
||||
case "l":
|
||||
case "right":
|
||||
return focusDetails();
|
||||
case "u":
|
||||
if (parent) openThread(parent.threadId);
|
||||
return;
|
||||
case "e":
|
||||
return setExpandAll((value) => !value);
|
||||
case "o":
|
||||
@@ -289,8 +575,11 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
case "s":
|
||||
if (threadId && key.shift) run("Stop requested", () => session.stopThread(threadId));
|
||||
return;
|
||||
case ":":
|
||||
openPalette();
|
||||
return key.preventDefault();
|
||||
case "/":
|
||||
if (!attachThreadId) setMode("filter");
|
||||
if (!attached) setMode("filter");
|
||||
return key.preventDefault();
|
||||
case "i":
|
||||
case "return":
|
||||
@@ -308,7 +597,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
: shell.status.type === "reconnecting"
|
||||
? "reconnecting…"
|
||||
: (shell.serverUrl ?? "");
|
||||
const listWidth = attachThreadId ? 0 : Math.min(46, Math.max(28, Math.floor(width * 0.3)));
|
||||
const listWidth = attached ? 0 : Math.min(46, Math.max(28, Math.floor(width * 0.3)));
|
||||
const detailsColumn = showDetails && width - listWidth - DETAILS_WIDTH >= MIN_CONVERSATION_WIDTH;
|
||||
const detailsInPlace = showDetails && !detailsColumn;
|
||||
const composerHeight = Math.min(MAX_COMPOSER_LINES, composerLines) + 2;
|
||||
@@ -333,6 +622,18 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
.filter(Boolean)
|
||||
.join(" · ")
|
||||
: "";
|
||||
const detailsPanel = (inPlace: boolean) => (
|
||||
<DetailsPanel
|
||||
details={details}
|
||||
// Idle subagents are left out of the shell, which is where details come from.
|
||||
{...(threadId && !threadShell ? { empty: "No details for idle subagent threads. u goes to the parent." } : {})}
|
||||
width={inPlace ? width - listWidth : DETAILS_WIDTH}
|
||||
loading={vcsState?.status !== "live"}
|
||||
inPlace={inPlace}
|
||||
selected={mode === "details" || (mode === "confirm" && returnMode.current === "details") ? detailsSelected : null}
|
||||
onActivate={activateById}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<box flexDirection="column" width={width} height={height} backgroundColor={colors.bg}>
|
||||
@@ -341,20 +642,42 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
<strong>tui3</strong>
|
||||
</text>
|
||||
<text fg={shell.status.type === "live" ? colors.faint : colors.warn}>{` ${status}`}</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>ctrl+k commands</text>
|
||||
</box>
|
||||
<box flexDirection="row" flexGrow={1} flexShrink={1} minHeight={0} overflow="hidden">
|
||||
{attachThreadId ? null : (
|
||||
<ThreadList rows={rows} collapsed={collapsed} selected={selectedIndex} focused={mode === "nav"} width={listWidth} height={height - 2} filter={filter} now={now} />
|
||||
{attached ? null : (
|
||||
<ThreadList
|
||||
rows={rows}
|
||||
collapsed={collapsed}
|
||||
selected={selectedIndex}
|
||||
focused={mode === "nav" || mode === "filter"}
|
||||
width={listWidth}
|
||||
height={height - 2}
|
||||
filter={filter}
|
||||
filtering={mode === "filter"}
|
||||
now={now}
|
||||
onFilter={setFilter}
|
||||
onFilterDone={() => setMode("nav")}
|
||||
onPick={(id) => {
|
||||
openThread(id);
|
||||
setMode("nav");
|
||||
}}
|
||||
onUnfold={() => setShowFolded(true)}
|
||||
/>
|
||||
)}
|
||||
<box flexDirection="column" flexGrow={1} minHeight={0}>
|
||||
{threadId && detailsInPlace ? (
|
||||
{diff ? (
|
||||
<DiffView diff={diff} scrollRef={scrollRef} />
|
||||
) : threadId && detailsInPlace ? (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column">
|
||||
<DetailsPanel details={details} width={width - listWidth} loading={vcsState?.status !== "live"} inPlace />
|
||||
{detailsPanel(true)}
|
||||
</box>
|
||||
) : threadId ? (
|
||||
<ThreadView
|
||||
key={watchedId}
|
||||
project={threadRow?.projectName ?? ""}
|
||||
title={threadShell?.title ?? "Thread"}
|
||||
title={title}
|
||||
detail={threadShell?.branch ?? ""}
|
||||
timeline={current}
|
||||
history={watchedId === threadId ? (thread?.history ?? null) : null}
|
||||
@@ -363,18 +686,27 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
workspaceRoot={threadShell?.worktreePath ?? undefined}
|
||||
now={now}
|
||||
scrollRef={scrollRef}
|
||||
parent={parent}
|
||||
onOpenThread={openThread}
|
||||
/>
|
||||
) : (
|
||||
<box flexGrow={1} paddingLeft={2} paddingTop={1}>
|
||||
<text fg={colors.muted}>{shell.snapshot ? "No thread selected." : "Waiting for threads…"}</text>
|
||||
</box>
|
||||
)}
|
||||
{mode !== "filter" && pendingInput && questionDraft ? <QuestionPanel request={pendingInput} index={questionDraft.index} draft={questionDraft.answers[pendingInput.questions[questionDraft.index]?.id ?? ""]} /> : null}
|
||||
{mode === "filter" ? (
|
||||
<box title=" filter " border borderStyle="rounded" borderColor={colors.borderFocused} height={3} flexShrink={0} marginLeft={1} marginRight={1}>
|
||||
<input focused placeholder="title or project…" value={filter} onInput={(value: string) => setFilter(value)} onSubmit={() => setMode("nav")} />
|
||||
</box>
|
||||
) : threadId ? (
|
||||
{mode !== "confirm" && pendingInput && questionDraft ? <QuestionPanel request={pendingInput} index={questionDraft.index} draft={questionDraft.answers[pendingInput.questions[questionDraft.index]?.id ?? ""]} /> : null}
|
||||
{mode === "confirm" && confirmation ? (
|
||||
<ConfirmBar
|
||||
confirmation={confirmation}
|
||||
message={confirmMessage}
|
||||
onMessage={setConfirmMessage}
|
||||
onSubmit={() => {
|
||||
closeOverlay();
|
||||
confirmation.run(confirmMessage);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{threadId ? (
|
||||
<box
|
||||
border
|
||||
borderStyle="rounded"
|
||||
@@ -385,6 +717,7 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
marginRight={1}
|
||||
paddingLeft={1}
|
||||
paddingRight={1}
|
||||
onMouseDown={() => setMode("input")}
|
||||
>
|
||||
<textarea
|
||||
key={threadId}
|
||||
@@ -394,49 +727,84 @@ export function App(props: { readonly session: T3Session; readonly attachThreadI
|
||||
placeholder={placeholder}
|
||||
placeholderColor={colors.faint}
|
||||
textColor={colors.text}
|
||||
wrapMode="word"
|
||||
keyBindings={[...COMPOSER_KEYS]}
|
||||
onSubmit={() => submit()}
|
||||
onContentChange={() => {
|
||||
const text = composerRef.current?.plainText ?? "";
|
||||
const composer = composerRef.current;
|
||||
const text = composer?.plainText ?? "";
|
||||
if (text) drafts.current.set(threadId, text);
|
||||
else drafts.current.delete(threadId);
|
||||
setComposerLines(Math.max(1, text.split("\n").length));
|
||||
// Wrapped lines count too, so a long paragraph grows the box.
|
||||
// The wrapped count can lag a programmatic newline, so hard lines are a floor.
|
||||
setComposerLines(Math.max(text.split("\n").length, composer?.virtualLineCount ?? 1));
|
||||
setComposerEmpty(text.trim() === "");
|
||||
}}
|
||||
/>
|
||||
</box>
|
||||
) : null}
|
||||
{mode !== "filter" && threadId ? (
|
||||
{threadId ? (
|
||||
<box flexDirection="row" height={1} flexShrink={0} paddingLeft={2} paddingRight={2}>
|
||||
<text fg={colors.faint}>{footer}</text>
|
||||
</box>
|
||||
) : null}
|
||||
</box>
|
||||
{detailsColumn ? <DetailsPanel details={details} width={DETAILS_WIDTH} loading={vcsState?.status !== "live"} /> : null}
|
||||
{detailsColumn ? detailsPanel(false) : null}
|
||||
</box>
|
||||
<box flexDirection="row" paddingLeft={2} height={1} flexShrink={0}>
|
||||
{flash ? (
|
||||
<text fg={flash.bad ? colors.bad : colors.good}>{flash.text}</text>
|
||||
) : (
|
||||
<text fg={colors.faint}>{hints(mode, { approval: Boolean(pendingApproval), question: Boolean(pendingInput), working, attached: Boolean(attachThreadId) })}</text>
|
||||
<text fg={colors.faint}>{hints(mode, { approval: Boolean(pendingApproval), question: Boolean(pendingInput), working, attached, diff: diff !== null, parent: parent !== undefined })}</text>
|
||||
)}
|
||||
</box>
|
||||
{mode === "palette" ? (
|
||||
<Palette
|
||||
query={paletteQuery}
|
||||
groups={groups}
|
||||
selected={Math.min(paletteIndex, Math.max(0, entries.length - 1))}
|
||||
width={width}
|
||||
height={height}
|
||||
onQuery={(value) => {
|
||||
setPaletteQuery(value);
|
||||
setPaletteIndex(0);
|
||||
}}
|
||||
onSubmit={() => pick(Math.min(paletteIndex, entries.length - 1))}
|
||||
onPick={pick}
|
||||
/>
|
||||
) : null}
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
function hints(mode: Mode, state: { readonly approval: boolean; readonly question: boolean; readonly working: boolean; readonly attached: boolean }): string {
|
||||
function hints(
|
||||
mode: Mode,
|
||||
state: { readonly approval: boolean; readonly question: boolean; readonly working: boolean; readonly attached: boolean; readonly diff: boolean; readonly parent: boolean },
|
||||
): string {
|
||||
if (mode === "filter") return "enter done · esc close";
|
||||
if (mode === "palette") return "↑/↓ move · enter run · esc close";
|
||||
if (mode === "confirm") return "enter confirm · esc cancel";
|
||||
if (mode === "details") return "j/k move · enter open · t toggle automation · esc back";
|
||||
if (mode === "input") {
|
||||
const parts = [state.working ? "enter steer · alt+enter queue" : "enter send", "shift+enter newline", "esc navigate"];
|
||||
const parts = [state.working ? "enter steer · alt+enter queue" : "enter send", "shift+enter or \\ newline", "esc navigate"];
|
||||
if (state.question) parts.unshift("1-9 pick");
|
||||
if (state.approval) parts.unshift("approval waiting: esc, then y/n");
|
||||
if (!state.attached) parts.push("ctrl+n/p thread");
|
||||
return parts.join(" · ");
|
||||
}
|
||||
const parts = state.attached ? ["j/k scroll"] : ["j/k threads", "/ filter", "z settled"];
|
||||
parts.push("i type", "e expand", "o earlier", "d details", "S stop", "q quit");
|
||||
if (state.diff) return "j/k scroll · esc close diff · l details";
|
||||
const parts = state.attached ? ["j/k scroll"] : ["j/k threads", "/ filter"];
|
||||
parts.push("i type", "l details", "e expand", "o earlier");
|
||||
if (state.parent) parts.push("u parent");
|
||||
parts.push("ctrl+k commands", "q quit");
|
||||
if (state.question) parts.unshift("1-9 pick · x dismiss");
|
||||
if (state.approval) parts.unshift("y approve · Y always · n decline");
|
||||
return parts.join(" · ");
|
||||
}
|
||||
|
||||
const messageOf = (error: unknown) => (error instanceof Error ? error.message : String(error));
|
||||
|
||||
function firstLine(text: string): string {
|
||||
const line = (text.trim().split("\n")[0] ?? "").replace(/\s+/g, " ");
|
||||
return line.length > 100 ? `${line.slice(0, 99)}…` : line;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { colors } from "./theme.ts";
|
||||
|
||||
/** An action that waits for you to say yes: git actions, stopping a server, running an automation. */
|
||||
export interface Confirmation {
|
||||
readonly title: string;
|
||||
readonly detail?: string;
|
||||
/** Commit actions take an optional message, typed here; blank lets the server write one. */
|
||||
readonly message?: { readonly placeholder: string };
|
||||
readonly confirmLabel: string;
|
||||
readonly run: (message: string) => void;
|
||||
}
|
||||
|
||||
/** Shown above the composer while a confirmation is open. */
|
||||
export function ConfirmBar(props: { readonly confirmation: Confirmation; readonly message: string; readonly onMessage: (value: string) => void; readonly onSubmit: () => void }) {
|
||||
const { confirmation } = props;
|
||||
return (
|
||||
<box border borderStyle="rounded" borderColor={colors.warn} flexDirection="column" flexShrink={0} marginLeft={1} marginRight={1} paddingLeft={1} paddingRight={1}>
|
||||
<text fg={colors.warn}>
|
||||
<strong>{confirmation.title}</strong>
|
||||
</text>
|
||||
{confirmation.detail ? <text fg={colors.muted}>{confirmation.detail}</text> : null}
|
||||
{confirmation.message ? (
|
||||
<box flexDirection="row" height={1}>
|
||||
<text fg={colors.faint}>{"Message: "}</text>
|
||||
<input focused flexGrow={1} placeholder={confirmation.message.placeholder} value={props.message} onInput={props.onMessage} onSubmit={props.onSubmit} />
|
||||
</box>
|
||||
) : null}
|
||||
<text fg={colors.faint}>{`enter ${confirmation.confirmLabel} · esc cancel`}</text>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
+90
-25
@@ -1,29 +1,55 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import type { ThreadDetails } from "../model/details.ts";
|
||||
import { MAX_DETAIL_FILES, type DetailsAction, type ThreadDetails } from "../model/details.ts";
|
||||
import { colors, statusColor } from "./theme.ts";
|
||||
|
||||
/** Files listed under Changes before the rest fold into a count. */
|
||||
const MAX_FILES = 8;
|
||||
/** Rows stay readable when the panel takes the conversation's place on a narrow terminal. */
|
||||
const IN_PLACE_MAX_WIDTH = 64;
|
||||
|
||||
/** The web's thread details card as a right-hand column: workspace, branch and PR, changes, lineage, background work, goal. */
|
||||
export function DetailsPanel(props: { readonly details: ThreadDetails | null; readonly width: number; readonly loading: boolean; readonly inPlace?: boolean }) {
|
||||
/**
|
||||
* The web's thread details card as a right-hand column: workspace, branch and PR, git actions,
|
||||
* changes, lineage, servers, automations, background work, goal. Lines that do something are
|
||||
* selectable with the keyboard and clickable.
|
||||
*/
|
||||
export function DetailsPanel(props: {
|
||||
readonly details: ThreadDetails | null;
|
||||
readonly width: number;
|
||||
readonly loading: boolean;
|
||||
readonly inPlace?: boolean;
|
||||
/** The selected line's action id, while the panel has focus. */
|
||||
readonly selected: string | null;
|
||||
readonly onActivate: (id: string) => void;
|
||||
/** Shown when there are no details, which defaults to no thread being selected. */
|
||||
readonly empty?: string;
|
||||
}) {
|
||||
const { details } = props;
|
||||
// In place of the conversation it sits beside the thread list's border and needs none of its own.
|
||||
const width = props.inPlace ? Math.min(props.width, IN_PLACE_MAX_WIDTH) : props.width;
|
||||
const inner = Math.max(10, width - (props.inPlace ? 3 : 4));
|
||||
return (
|
||||
<box {...(props.inPlace ? {} : { border: ["left"] as const, borderColor: colors.border })} width={width} flexShrink={0} flexDirection="column" paddingLeft={1} paddingRight={1} overflow="hidden">
|
||||
{!details ? <text fg={colors.faint}>No thread selected.</text> : <Sections details={details} inner={inner} loading={props.loading} />}
|
||||
<box
|
||||
{...(props.inPlace ? {} : { border: ["left"] as const, borderColor: props.selected ? colors.borderFocused : colors.border })}
|
||||
width={width}
|
||||
flexShrink={0}
|
||||
flexDirection="column"
|
||||
overflow="hidden"
|
||||
>
|
||||
<scrollbox flexGrow={1} minHeight={0} paddingLeft={1} paddingRight={1}>
|
||||
{!details ? <text fg={colors.faint}>{props.empty ?? "No thread selected."}</text> : <Sections details={details} inner={inner} loading={props.loading} selected={props.selected} onActivate={props.onActivate} />}
|
||||
</scrollbox>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
function Sections({ details, inner, loading }: { readonly details: ThreadDetails; readonly inner: number; readonly loading: boolean }) {
|
||||
const { workspace, branch, changes } = details;
|
||||
interface LineProps {
|
||||
readonly selected: string | null;
|
||||
readonly onActivate: (id: string) => void;
|
||||
}
|
||||
|
||||
function Sections({ details, inner, loading, selected, onActivate }: { readonly details: ThreadDetails; readonly inner: number; readonly loading: boolean } & LineProps) {
|
||||
const { workspace, branch, changes, git } = details;
|
||||
const files = changes?.files ?? [];
|
||||
const line = { selected, onActivate };
|
||||
return (
|
||||
<>
|
||||
<Section title="Workspace" first>
|
||||
@@ -35,7 +61,11 @@ function Sections({ details, inner, loading }: { readonly details: ThreadDetails
|
||||
|
||||
{branch ? (
|
||||
<Section title="Branch">
|
||||
<Line left={truncate(branch.name, inner - (branch.upstream?.length ?? 0) - 1)} right={branch.upstream ?? ""} />
|
||||
<box flexDirection="row">
|
||||
<text fg={colors.text}>{truncate(branch.name, inner - (branch.upstream?.length ?? 0) - 1)}</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>{branch.upstream ?? ""}</text>
|
||||
</box>
|
||||
{branch.pullRequest ? (
|
||||
<>
|
||||
<box flexDirection="row">
|
||||
@@ -47,15 +77,21 @@ function Sections({ details, inner, loading }: { readonly details: ThreadDetails
|
||||
{branch.pullRequest.title ? <text fg={colors.muted}>{truncate(branch.pullRequest.title, inner)}</text> : null}
|
||||
</>
|
||||
) : null}
|
||||
{git?.quick ? <Selectable id={`git:quick:${git.quick.action}`} {...line} color={colors.accent} text={`▸ ${git.quick.label}`} inner={inner} /> : null}
|
||||
{git?.menu.map((item) => <Selectable key={item.action} id={`git:${item.action}`} {...line} color={colors.muted} text={` ${item.label}`} inner={inner} />)}
|
||||
{git && !git.quick && git.hint ? <text fg={colors.faint}>{truncate(git.hint, inner)}</text> : null}
|
||||
</Section>
|
||||
) : null}
|
||||
|
||||
{changes ? (
|
||||
<Section title="Changes" right={<Counts insertions={changes.insertions} deletions={changes.deletions} />}>
|
||||
{files.slice(0, MAX_FILES).map((file) => (
|
||||
<FileLine key={file.path} path={file.path} insertions={file.insertions} deletions={file.deletions} inner={inner} />
|
||||
{files.length > 0 ? <Selectable id="diff:*" {...line} color={colors.accent} text="▸ View diff" inner={inner} /> : null}
|
||||
{files.slice(0, MAX_DETAIL_FILES).map((file) => (
|
||||
<Selectable key={file.path} id={`diff:${file.path}`} {...line} inner={inner}>
|
||||
<FileLine path={file.path} insertions={file.insertions} deletions={file.deletions} inner={inner} />
|
||||
</Selectable>
|
||||
))}
|
||||
{files.length > MAX_FILES ? <text fg={colors.faint}>{`… ${files.length - MAX_FILES} more files`}</text> : null}
|
||||
{files.length > MAX_DETAIL_FILES ? <text fg={colors.faint}>{`… ${files.length - MAX_DETAIL_FILES} more files (in the full diff)`}</text> : null}
|
||||
{files.length === 0 ? <text fg={colors.faint}>Working tree clean</text> : null}
|
||||
{changes.branchTotal ? (
|
||||
<box flexDirection="row">
|
||||
@@ -74,8 +110,37 @@ function Sections({ details, inner, loading }: { readonly details: ThreadDetails
|
||||
|
||||
{details.lineage.length > 0 ? (
|
||||
<Section title="Lineage">
|
||||
{details.lineage.map((entry) => (
|
||||
<text key={entry.text} fg={colors.muted}>{truncate(`${entry.glyph} ${entry.text}`, inner)}</text>
|
||||
{details.lineage.map((entry) =>
|
||||
entry.threadId ? (
|
||||
<Selectable key={entry.threadId} id={`thread:${entry.threadId}`} {...line} color={colors.muted} text={`${entry.glyph} ${entry.text}`} inner={inner} />
|
||||
) : (
|
||||
<text key={entry.text} fg={colors.muted}>{truncate(`${entry.glyph} ${entry.text}`, inner)}</text>
|
||||
),
|
||||
)}
|
||||
</Section>
|
||||
) : null}
|
||||
|
||||
{details.servers.length > 0 ? (
|
||||
<Section title="Servers">
|
||||
{details.servers.map(({ server, label }) => (
|
||||
<Selectable key={server.port} id={`server:${server.port}`} {...line} color={colors.info} text={`● ${label}`} inner={inner} />
|
||||
))}
|
||||
</Section>
|
||||
) : null}
|
||||
|
||||
{details.automations.length > 0 ? (
|
||||
<Section title="Automations">
|
||||
{details.automations.map((automation) => (
|
||||
<Selectable key={automation.task.id} id={`automation:${automation.task.id}`} {...line} inner={inner}>
|
||||
<box flexDirection="column">
|
||||
<text fg={colors.text}>{truncate(automation.task.title, inner)}</text>
|
||||
<box flexDirection="row">
|
||||
<text fg={colors.faint}>{truncate(automation.schedule, inner - automation.status.length - 1)}</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={statusColor[automation.tone]}>{automation.status}</text>
|
||||
</box>
|
||||
</box>
|
||||
</Selectable>
|
||||
))}
|
||||
</Section>
|
||||
) : null}
|
||||
@@ -98,6 +163,16 @@ function Sections({ details, inner, loading }: { readonly details: ThreadDetails
|
||||
);
|
||||
}
|
||||
|
||||
/** A line that does something: highlighted when selected, activated by a click. */
|
||||
function Selectable(props: LineProps & { readonly id: DetailsAction["id"]; readonly inner: number; readonly text?: string; readonly color?: string; readonly children?: ReactNode }) {
|
||||
const active = props.selected === props.id;
|
||||
return (
|
||||
<box backgroundColor={active ? colors.selectedBg : "transparent"} onMouseDown={() => props.onActivate(props.id)}>
|
||||
{props.children ?? <text fg={active ? colors.text : (props.color ?? colors.muted)}>{truncate(props.text ?? "", props.inner)}</text>}
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
function Section(props: { readonly title: string; readonly right?: ReactNode; readonly first?: boolean; readonly children: ReactNode }) {
|
||||
return (
|
||||
<box flexDirection="column" marginTop={props.first ? 0 : 1} flexShrink={0}>
|
||||
@@ -113,16 +188,6 @@ function Section(props: { readonly title: string; readonly right?: ReactNode; re
|
||||
);
|
||||
}
|
||||
|
||||
function Line({ left, right }: { readonly left: string; readonly right: string }) {
|
||||
return (
|
||||
<box flexDirection="row">
|
||||
<text fg={colors.text}>{left}</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>{right}</text>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
function FileLine(props: { readonly path: string; readonly insertions: number; readonly deletions: number; readonly inner: number }) {
|
||||
const counts = countsText(props.insertions, props.deletions);
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { ScrollBoxRenderable } from "@opentui/core";
|
||||
import type { RefObject } from "react";
|
||||
|
||||
import { colors, getMarkdownStyle } from "./theme.ts";
|
||||
|
||||
export interface DiffState {
|
||||
readonly cwd: string;
|
||||
/** null for the whole working tree. */
|
||||
readonly path: string | null;
|
||||
readonly status: "loading" | "ready" | "error";
|
||||
readonly patch?: string;
|
||||
readonly truncated?: boolean;
|
||||
readonly error?: string;
|
||||
}
|
||||
|
||||
/** Uncommitted changes as unified diffs, one block per file, in place of the conversation. */
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly scrollRef: RefObject<ScrollBoxRenderable | null> }) {
|
||||
const { diff } = props;
|
||||
const files = diff.patch ? splitPatch(diff.patch) : [];
|
||||
return (
|
||||
<box flexGrow={1} minHeight={0} flexDirection="column" paddingLeft={1} paddingRight={1}>
|
||||
<box flexDirection="row" flexShrink={0} height={1}>
|
||||
<text fg={colors.muted}>Uncommitted / </text>
|
||||
<text fg={colors.text}>
|
||||
<strong>{diff.path ?? `${files.length} ${files.length === 1 ? "file" : "files"}`}</strong>
|
||||
</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>esc close</text>
|
||||
</box>
|
||||
{diff.status === "loading" ? <text fg={colors.muted}>Loading diff…</text> : null}
|
||||
{diff.status === "error" ? <text fg={colors.bad}>{`Could not load the diff: ${diff.error ?? "unknown error"}`}</text> : null}
|
||||
{diff.status === "ready" && files.length === 0 ? <text fg={colors.muted}>No changes.</text> : null}
|
||||
{diff.truncated ? <text fg={colors.warn}>The diff was too large and is cut short.</text> : null}
|
||||
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
|
||||
{files.map((file) => (
|
||||
<box key={file.path} flexDirection="column" marginTop={1}>
|
||||
{diff.path ? null : <text fg={colors.accent}>{file.path}</text>}
|
||||
<diff
|
||||
diff={file.patch}
|
||||
view="unified"
|
||||
{...(filetypeOf(file.path) ? { filetype: filetypeOf(file.path)! } : {})}
|
||||
syntaxStyle={getMarkdownStyle()}
|
||||
showLineNumbers
|
||||
wrapMode="none"
|
||||
fg={colors.text}
|
||||
addedBg="#1e2a1e"
|
||||
removedBg="#2d1f24"
|
||||
addedContentBg="#1e2a1e"
|
||||
removedContentBg="#2d1f24"
|
||||
addedSignColor={colors.good}
|
||||
removedSignColor={colors.bad}
|
||||
lineNumberFg={colors.faint}
|
||||
/>
|
||||
</box>
|
||||
))}
|
||||
</scrollbox>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
/** Splits a multi-file patch at each `diff --git` header. */
|
||||
export function splitPatch(patch: string): { path: string; patch: string }[] {
|
||||
return patch
|
||||
.split(/^(?=diff --git )/m)
|
||||
.filter((chunk) => chunk.startsWith("diff --git "))
|
||||
.map((chunk) => ({ path: /^diff --git a\/(.+?) b\//.exec(chunk)?.[1] ?? "file", patch: chunk }));
|
||||
}
|
||||
|
||||
const FILETYPES: Record<string, string> = { ts: "typescript", tsx: "tsx", js: "javascript", jsx: "javascript", json: "json", md: "markdown", rs: "rust", py: "python", go: "go", css: "css", html: "html", sh: "bash", yml: "yaml", yaml: "yaml", zig: "zig" };
|
||||
|
||||
function filetypeOf(path: string): string | undefined {
|
||||
return FILETYPES[path.split(".").pop() ?? ""];
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { PaletteEntry, PaletteGroup } from "../model/palette.ts";
|
||||
import { colors } from "./theme.ts";
|
||||
|
||||
/**
|
||||
* The web's command palette (mod+K) as an overlay: a search box over grouped commands and
|
||||
* threads. Arrows or ctrl+n/p move, enter runs, a click runs, esc closes.
|
||||
*/
|
||||
export function Palette(props: {
|
||||
readonly query: string;
|
||||
readonly groups: readonly PaletteGroup[];
|
||||
readonly selected: number;
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly onQuery: (query: string) => void;
|
||||
readonly onSubmit: () => void;
|
||||
readonly onPick: (index: number) => void;
|
||||
}) {
|
||||
const width = Math.min(80, props.width - 4);
|
||||
const listHeight = Math.max(4, Math.min(props.height - 8, 22));
|
||||
// Rows are entries plus a header per group; keep the selection in view.
|
||||
const rows: ({ kind: "header"; label: string } | { kind: "entry"; entry: PaletteEntry; index: number })[] = [];
|
||||
let index = 0;
|
||||
for (const group of props.groups) {
|
||||
rows.push({ kind: "header", label: group.label });
|
||||
for (const entry of group.entries) rows.push({ kind: "entry", entry, index: index++ });
|
||||
}
|
||||
const selectedRow = rows.findIndex((row) => row.kind === "entry" && row.index === props.selected);
|
||||
const start = Math.max(0, Math.min(selectedRow - Math.floor(listHeight / 2), rows.length - listHeight));
|
||||
const inner = width - 4;
|
||||
return (
|
||||
<box position="absolute" top={2} left={Math.floor((props.width - width) / 2)} width={width} zIndex={10} flexDirection="column" border borderStyle="rounded" borderColor={colors.borderFocused} backgroundColor={colors.panel}>
|
||||
<box paddingLeft={1} paddingRight={1} height={1} flexDirection="row">
|
||||
<text fg={colors.accent}>{"› "}</text>
|
||||
<input focused flexGrow={1} placeholder="Search commands and threads (> for commands only)" value={props.query} onInput={props.onQuery} onSubmit={props.onSubmit} backgroundColor={colors.panel} focusedBackgroundColor={colors.panel} />
|
||||
</box>
|
||||
<box border={["top"]} borderColor={colors.border} flexDirection="column" height={listHeight + 1}>
|
||||
{rows.length === 0 ? <text fg={colors.muted} paddingLeft={1}>No matches</text> : null}
|
||||
{rows.slice(start, start + listHeight).map((row) =>
|
||||
row.kind === "header" ? (
|
||||
<text key={`h-${row.label}`} fg={colors.faint} paddingLeft={1}>
|
||||
{row.label}
|
||||
</text>
|
||||
) : (
|
||||
<Row key={entryKey(row.entry)} entry={row.entry} selected={row.index === props.selected} inner={inner} onPick={() => props.onPick(row.index)} />
|
||||
),
|
||||
)}
|
||||
</box>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
function Row(props: { readonly entry: PaletteEntry; readonly selected: boolean; readonly inner: number; readonly onPick: () => void }) {
|
||||
const { entry } = props;
|
||||
const right = entry.kind === "command" ? (entry.command.shortcut ?? "") : entry.project;
|
||||
const title = entry.kind === "command" ? entry.command.title : `${entry.subagent ? "↳ " : ""}${entry.title}`;
|
||||
return (
|
||||
<box flexDirection="row" paddingLeft={1} paddingRight={1} backgroundColor={props.selected ? colors.selectedBg : "transparent"} onMouseDown={props.onPick}>
|
||||
<text fg={props.selected ? colors.text : entry.kind === "command" ? colors.text : colors.muted}>{truncate(title, props.inner - right.length - 2)}</text>
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>{right}</text>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
export function entryKey(entry: PaletteEntry): string {
|
||||
return entry.kind === "command" ? `c:${entry.command.id}` : `t:${entry.threadId}`;
|
||||
}
|
||||
|
||||
function truncate(text: string, width: number): string {
|
||||
const single = text.replace(/\s+/g, " ");
|
||||
return single.length > width ? `${single.slice(0, Math.max(0, width - 1))}…` : single;
|
||||
}
|
||||
+25
-4
@@ -1,4 +1,6 @@
|
||||
import { needsAttention, relativeTime, rowTime, SECTION_LABELS, statusLabel, type Section, type ThreadRow } from "../model/threads.ts";
|
||||
import type { ThreadId } from "@t3tools/contracts";
|
||||
|
||||
import { colors, statusColor } from "./theme.ts";
|
||||
|
||||
/**
|
||||
@@ -15,11 +17,17 @@ export function ThreadList(props: {
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly filter: string;
|
||||
/** The filter box is open and has the keyboard. */
|
||||
readonly filtering: boolean;
|
||||
readonly now: number;
|
||||
readonly onFilter: (value: string) => void;
|
||||
readonly onFilterDone: () => void;
|
||||
readonly onPick: (threadId: ThreadId) => void;
|
||||
readonly onUnfold: () => void;
|
||||
}) {
|
||||
const { rows, selected, focused, width, height, now } = props;
|
||||
// Rows take two lines plus a header per section; keep the selection in view.
|
||||
const visibleCount = Math.max(1, Math.floor((height - 6) / 2));
|
||||
const visibleCount = Math.max(1, Math.floor((height - (props.filtering ? 9 : 6)) / 2));
|
||||
const start = Math.max(0, Math.min(selected - Math.floor(visibleCount / 2), rows.length - visibleCount));
|
||||
const windowRows = rows.slice(start, start + visibleCount);
|
||||
const inner = Math.max(8, width - 3);
|
||||
@@ -42,7 +50,14 @@ export function ThreadList(props: {
|
||||
const recede = !isSelected && (row.status === "working" || row.status === "waiting" || (row.status === "ready" && !row.unread));
|
||||
const title = truncate(row.thread.title || "New thread", inner);
|
||||
lines.push(
|
||||
<box key={row.thread.id} flexDirection="column" paddingLeft={1} paddingRight={1} backgroundColor={isSelected ? (focused ? colors.selectedBg : colors.panel) : "transparent"}>
|
||||
<box
|
||||
key={row.thread.id}
|
||||
flexDirection="column"
|
||||
paddingLeft={1}
|
||||
paddingRight={1}
|
||||
backgroundColor={isSelected ? (focused ? colors.selectedBg : colors.panel) : "transparent"}
|
||||
onMouseDown={() => props.onPick(row.thread.id)}
|
||||
>
|
||||
<box flexDirection="row">
|
||||
<text fg={colors.faint}>{left}</text>
|
||||
<box flexGrow={1} />
|
||||
@@ -55,11 +70,17 @@ export function ThreadList(props: {
|
||||
const collapsed = [...props.collapsed].filter(([, count]) => count > 0);
|
||||
return (
|
||||
<box border={["right"]} borderColor={colors.border} width={width} flexShrink={0} overflow="hidden" flexDirection="column">
|
||||
{props.filter ? <text fg={colors.accent}>{` /${props.filter}`}</text> : null}
|
||||
{props.filtering ? (
|
||||
<box border borderStyle="rounded" borderColor={colors.borderFocused} height={3} flexShrink={0}>
|
||||
<input focused placeholder="Filter threads…" value={props.filter} onInput={props.onFilter} onSubmit={props.onFilterDone} />
|
||||
</box>
|
||||
) : props.filter ? (
|
||||
<text fg={colors.accent}>{` /${props.filter}`}</text>
|
||||
) : null}
|
||||
{rows.length === 0 ? <text fg={colors.muted}>{props.filter ? " no matches" : " no threads"}</text> : lines}
|
||||
<box flexGrow={1} />
|
||||
{collapsed.map(([section, count]) => (
|
||||
<text key={section} fg={colors.faint}>{` › ${SECTION_LABELS[section]} ${count}`}</text>
|
||||
<text key={section} fg={colors.faint} onMouseDown={props.onUnfold}>{` › ${SECTION_LABELS[section]} ${count}`}</text>
|
||||
))}
|
||||
</box>
|
||||
);
|
||||
|
||||
+32
-5
@@ -1,4 +1,5 @@
|
||||
import type { ScrollBoxRenderable } from "@opentui/core";
|
||||
import type { ThreadId } 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, type RefObject } from "react";
|
||||
@@ -20,6 +21,10 @@ export function ThreadView(props: {
|
||||
readonly workspaceRoot: string | undefined;
|
||||
readonly now: number;
|
||||
readonly scrollRef: RefObject<ScrollBoxRenderable | null>;
|
||||
/** For a subagent or fork: the thread it came from, shown as a link in the header. */
|
||||
readonly parent?: { readonly title: string; readonly threadId: ThreadId } | undefined;
|
||||
/** Opens another thread: a subagent from its work row, or the parent from the header. Keep it stable; rows are memoized on it. */
|
||||
readonly onOpenThread: (threadId: ThreadId) => void;
|
||||
}) {
|
||||
const { timeline, history } = props;
|
||||
const pendingIds = new Set<string>(timeline?.pending.approvals.map((approval) => approval.requestId) ?? []);
|
||||
@@ -33,6 +38,11 @@ export function ThreadView(props: {
|
||||
<box flexGrow={1} />
|
||||
<text fg={colors.faint}>{props.detail}</text>
|
||||
</box>
|
||||
{props.parent ? (
|
||||
<box flexShrink={0} height={1} onMouseDown={() => props.onOpenThread(props.parent!.threadId)}>
|
||||
<text fg={colors.accent}>{`↰ ${props.parent.title} (u)`}</text>
|
||||
</box>
|
||||
) : null}
|
||||
{props.error ? <text fg={colors.bad} flexShrink={0}>{props.error}</text> : null}
|
||||
<scrollbox ref={props.scrollRef} flexGrow={1} flexShrink={1} minHeight={0} stickyScroll stickyStart="bottom">
|
||||
{props.loading && !timeline ? <text fg={colors.muted}>Loading…</text> : null}
|
||||
@@ -45,6 +55,7 @@ export function ThreadView(props: {
|
||||
workspaceRoot={props.workspaceRoot}
|
||||
now={row.kind === "working" ? props.now : 0}
|
||||
workStartedAt={timeline.workStartedAt}
|
||||
onOpenThread={props.onOpenThread}
|
||||
/>
|
||||
))}
|
||||
</scrollbox>
|
||||
@@ -78,6 +89,7 @@ const Row = memo(function Row(props: {
|
||||
readonly workspaceRoot: string | undefined;
|
||||
readonly now: number;
|
||||
readonly workStartedAt: string | null;
|
||||
readonly onOpenThread: (threadId: ThreadId) => void;
|
||||
}) {
|
||||
const { row, workspaceRoot } = props;
|
||||
switch (row.kind) {
|
||||
@@ -109,7 +121,7 @@ const Row = memo(function Row(props: {
|
||||
return (
|
||||
<box marginTop={row.continuesWorkLog ? 0 : 1} flexDirection="column">
|
||||
{row.groupedEntries.map((entry) => (
|
||||
<WorkEntry key={entry.id} entry={entry} label={row.displayLabel && row.groupedEntries.length === 1 ? row.displayLabel : workEntryDisplayLabel(entry, workspaceRoot)} />
|
||||
<WorkEntry key={entry.id} entry={entry} label={row.displayLabel && row.groupedEntries.length === 1 ? row.displayLabel : workEntryDisplayLabel(entry, workspaceRoot)} onOpenThread={props.onOpenThread} />
|
||||
))}
|
||||
</box>
|
||||
);
|
||||
@@ -117,7 +129,9 @@ const Row = memo(function Row(props: {
|
||||
return (
|
||||
<box marginTop={1} flexDirection="column">
|
||||
{row.thought?.detail ? <text fg={colors.faint}>{`∴ ${liveThoughtLine(row.thought.detail)}`}</text> : null}
|
||||
<text fg={row.active ? colors.info : colors.muted}>{`${row.active ? "◐" : glyphFor(row.entry)} ${liveWorkEntryLabel(row.entry, workspaceRoot, row.active)}`}</text>
|
||||
<box onMouseDown={() => openChild(row.entry, props.onOpenThread)}>
|
||||
<text fg={row.active ? colors.info : colors.muted}>{`${row.active ? "◐" : glyphFor(row.entry)} ${liveWorkEntryLabel(row.entry, workspaceRoot, row.active)}${childThreadOf(row.entry) ? " ↗" : ""}`}</text>
|
||||
</box>
|
||||
</box>
|
||||
);
|
||||
case "working": {
|
||||
@@ -166,10 +180,23 @@ function UserMessage({ text }: { readonly text: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
function WorkEntry({ entry, label }: { readonly entry: WorkLogEntry; readonly label: string }) {
|
||||
function WorkEntry({ entry, label, onOpenThread }: { readonly entry: WorkLogEntry; readonly label: string; readonly onOpenThread: (threadId: ThreadId) => void }) {
|
||||
const failed = workEntryDisplayIndicatesToolFailure(entry);
|
||||
const tone = failed || entry.tone === "error" ? colors.bad : entry.tone === "thinking" ? colors.faint : colors.muted;
|
||||
return <text fg={tone}>{`${failed ? "✕" : glyphFor(entry)} ${firstLine(label)}`}</text>;
|
||||
const child = childThreadOf(entry);
|
||||
const tone = failed || entry.tone === "error" ? colors.bad : child ? colors.accent : entry.tone === "thinking" ? colors.faint : colors.muted;
|
||||
const text = <text fg={tone}>{`${failed ? "✕" : glyphFor(entry)} ${firstLine(label)}${child ? " ↗" : ""}`}</text>;
|
||||
return child ? <box onMouseDown={() => onOpenThread(child)}>{text}</box> : text;
|
||||
}
|
||||
|
||||
/** The thread a subagent work row ran in, when it has its own. */
|
||||
export function childThreadOf(entry: WorkLogEntry): ThreadId | null {
|
||||
const item = entry.structuredPayload;
|
||||
return item?.type === "subagent" ? (item.childThreadId ?? null) : null;
|
||||
}
|
||||
|
||||
function openChild(entry: WorkLogEntry, onOpenThread: (threadId: ThreadId) => void): void {
|
||||
const child = childThreadOf(entry);
|
||||
if (child) onOpenThread(child);
|
||||
}
|
||||
|
||||
function EventRow({ item, pending }: { readonly item: MessagesTimelineRow extends infer R ? (R extends { kind: "event"; projectedItem: { item: infer I } } ? I : never) : never; readonly pending: boolean }) {
|
||||
|
||||
Reference in new issue
Block a user