import type { ReactNode } from "react"; import { MAX_DETAIL_FILES, type ChangedFile, type DetailsAction, type DetailsFold, type LineageLine, type ThreadDetails } from "../model/details.ts"; import { Button, ClickRow } from "./Button.tsx"; import { truncate } from "./text.ts"; import { colors, scrollbarOptions, statusColor } from "./theme.ts"; /** Rows stay readable when the panel takes the conversation's place on a narrow terminal. */ const IN_PLACE_MAX_WIDTH = 64; /** Cells in the context bar. */ const BAR_CELLS = 10; /** * The web's thread details card as a right-hand column, what changes first: run state, * context and limits, the agent's tasks, changes, branch, subagents, servers, background * work, goal, automations, then where and how the thread runs. 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 unfolded: ReadonlySet; readonly onActivate: (id: string) => void; /** Opens a changed file in $EDITOR, from its ▸ Edit. */ readonly onEdit: (path: string) => void; /** Shown when there are no details, which defaults to no thread being selected. */ readonly empty?: string; }) { const { details } = props; const width = props.inPlace ? Math.min(props.width, IN_PLACE_MAX_WIDTH) : props.width; // A column of padding on each side, and one more for the scrollbox's scrollbar. const inner = Math.max(10, width - 3); return ( {!details ? ( {props.empty ?? "No thread selected."} ) : ( )} ); } interface LineProps { readonly selected: string | null; readonly onActivate: (id: string) => void; } function Sections({ details, inner, loading, unfolded, selected, onActivate, onEdit }: { readonly details: ThreadDetails; readonly inner: number; readonly loading: boolean; readonly unfolded: ReadonlySet; readonly onEdit: (path: string) => void } & LineProps) { const { branch, changes, git, tasks } = details; const files = changes?.files ?? []; const line = { selected, onActivate }; const gitActions = git ? ( <> {files.length > 0 || git.quick ? ( {files.length > 0 ? : null} {files.length > 0 && git.quick ? : null} {git.quick ? : null} ) : null} {git.menu.map((item) => )} ) : files.length > 0 ? ( ) : null; const visibleTasks = tasks ? (tasks.window && !unfolded.has("tasks") ? tasks.steps.slice(tasks.window.start, tasks.window.end) : tasks.steps) : []; const finished = details.lineage.filter((entry) => entry.finished); const lineageTitle = details.subagents.total > 0 ? "Subagents" : "Lineage"; return ( {tasks ? (
{`${tasks.done}/${tasks.total}`}}> {visibleTasks.map((step) => ( {`${TASK_GLYPHS[step.status]} `} {truncate(step.text, inner - 2)} ))} {tasks.window ? : null}
) : null} {changes ? (
}> {files.slice(0, MAX_DETAIL_FILES).map((file) => ( {selected === `diff:${file.path}` && !file.path.endsWith("/") ? (
) : loading ? (
Loading…
) : null} {details.vcsNote ? {details.vcsNote} : null} {branch ? ( {branch.pullRequest?.title && branch.pullRequest.title.length <= inner ? {branch.pullRequest.title} : null} {changes ? null : gitActions} ) : null} {details.lineage.length > 0 ? (
0 ? ( {`${details.subagents.total}`} {details.subagents.running > 0 ? {` · ${details.subagents.running} running`} : null} ) : undefined } > {details.lineage.filter((entry) => !entry.finished).map((entry) => )} {finished.length > 0 ? : null} {unfolded.has("subagents") ? finished.map((entry) => ) : null}
) : null} {details.servers.length > 0 ? (
{details.servers.map(({ server, label }) => ( ))}
) : null} {details.background.length > 0 ? (
{details.background.map((task, index) => ( {truncate(`${task.glyph} ${task.text}`, inner)} ))}
) : null} {details.goal ? (
{details.goal.objective} {details.goal.status}
) : null} {details.automations.length > 0 ? (
{details.automations.map((automation) => ( {truncate(automation.task.title, inner - automation.when.length - 1)} {automation.when} ))}
) : null}