Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ nexus chat resume 5f2a # 지난 대화 이어
- `chat answer` 는 터미널에서 도는 Claude Code 의 요청에도 답합니다(앱의 요청 카드와 같음). `--stop` 은 거절하면서 턴도 멈춥니다.
- `chat interrupt` 는 탭의 멈춤 버튼과 같습니다. 대기열의 메시지는 그대로 남습니다.
- `chat panel` 은 탭 옆 패널의 내용입니다: 목표, 할 일, 작업(백그라운드 실행, `chat stop-task` 가 받는 id), 서브에이전트, 바뀐 파일, 컨텍스트 · 비용 · 플랜 사용량, MCP 서버, 원격 제어, 보류 메시지. 로그인한 계정은 보이지 않습니다.
- 작업 패널의 백그라운드 명령은 현재 실행에서 수집하며, 앱을 재시작하면 대화 기록에서 복원되지 않습니다.
- `chat unsend <탭> <id|번호>` 는 보류 메시지를 id 로 회수하고 그 내용을 출력합니다. 번호를 주면 턴 중에 보내 아직 읽지 않은 메시지(`chat read` 에 `(unread)` 로 표시)를 회수합니다(Claude 탭만). 이미 읽었으면 종료 코드 1 입니다.
- `chat rewind <탭> <번호>` 는 되감기 버튼과 같습니다. 그 메시지 전으로 대화를, `--files` 면 그 뒤 Claude 가 바꾼 파일도 되돌립니다. `--preview` 는 되돌릴 파일만 보여줍니다. 턴 중에는 안 되고, 사용자에게 매번 묻습니다(Claude 탭만).
- `chat fork <탭> [번호]` 는 대화를 새 탭(뒤쪽)으로 복사합니다. 번호가 없으면 전부, 답변 번호면 그 답변까지, 메시지 번호면 그 메시지 전까지입니다. 메시지에서 갈라내면 그 메시지는 보내지 않고 출력합니다(Claude 탭만).
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/components/chat/claude-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
} from "../../services/chat/print-runs";
import { withRelayed } from "../../services/chat/relayed";
import { revertChangedFile } from "../../services/chat/revert-file";
import { jobToolStatuses } from "../../services/chat/running";
import {
type ChatTabState,
type ComposerDraft,
Expand Down Expand Up @@ -397,10 +398,14 @@ export function ClaudeTabView({ workspaceId, tabId, props, isVisible }: ClaudeTa
}, [isVisible]);
// The previews may read what the tab links outside the workspace, while it is open.
const [looked, setLooked] = useState<readonly string[]>([]);
// Taken from the parts it reads, so a line that changes none of them (a
// usage report, a turn's end) does not walk the whole session again.
const history = state.history;
const { items: liveItems, tools: liveTools, tasks } = state.model;
const toolStatuses = useMemo(
() => jobToolStatuses({ tasks, tools: liveTools, running }),
[tasks, liveTools, running],
);
// Taken from the parts it reads, so a line that changes none of them (a
// usage report, a turn's end) does not walk the whole session again.
const outside = useMemo(() => {
const items = history ? [...history.items, ...liveItems] : liveItems;
const tools = history ? { ...history.tools, ...liveTools } : liveTools;
Expand Down Expand Up @@ -681,6 +686,7 @@ export function ClaudeTabView({ workspaceId, tabId, props, isVisible }: ClaudeTa
rootPath={rootPath}
history={pastModel}
model={state.model}
toolStatuses={toolStatuses}
actions={shown ? undefined : actions}
items={shownTranscript}
reveal={shown ? null : callAsk}
Expand Down
61 changes: 47 additions & 14 deletions src/renderer/components/chat/message-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
} from "../../services/chat/panel";
import { followsMessage } from "../../services/chat/profile-moves";
import { RELAY_KINDS, withRelayed } from "../../services/chat/relayed";
import type { ToolRowStatuses } from "../../services/chat/running";
import { isOwnScroll, nearBottom, scrolledDown } from "../../services/chat/stick-to-bottom";
import { foldToolRuns, tallyRun } from "../../services/chat/tool-runs";
import { showPeerSession } from "../../services/remote/show-peer";
Expand All @@ -98,6 +99,8 @@ import { AnsweredQuestions, PlanOutcome, showsAsPrompt } from "./prompt-rows";
import { SentFiles } from "./sent-files";
import { ToolRow } from "./tool-row";

const NO_TOOL_STATUSES: ToolRowStatuses = {};

interface MessageListProps {
workspaceId: string;
/** The tab the conversation is, if it is one. */
Expand All @@ -106,6 +109,7 @@ interface MessageListProps {
rootPath: string;
history: ChatModel | null;
model: ChatModel;
toolStatuses?: ToolRowStatuses;
/** Shown when there is no message yet. */
empty?: React.ReactNode;
actions?: MessageActions;
Expand Down Expand Up @@ -219,6 +223,7 @@ export function MessageList({
rootPath,
history,
model,
toolStatuses = NO_TOOL_STATUSES,
empty,
actions,
items,
Expand Down Expand Up @@ -495,14 +500,22 @@ export function MessageList({
);
const under = useMemo(() => callsUnder(tools), [tools]);
const views = useMemo(() => {
const sources = { tools, callsUnder: under, shown, extras, earlier, asked: shownCall };
const sources = {
tools,
toolStatuses,
callsUnder: under,
shown,
extras,
earlier,
asked: shownCall,
};
const out = new Map<ChatItem, ItemView>();
for (const item of windowItems) {
const view = itemView(item, sources);
if (view) out.set(item, view);
}
return out;
}, [windowItems, tools, under, shown, extras, earlier, shownCall]);
}, [windowItems, tools, toolStatuses, under, shown, extras, earlier, shownCall]);

const list = (
<div className="relative min-h-0 flex-1">
Expand Down Expand Up @@ -558,6 +571,7 @@ export function MessageList({
streaming={streaming}
ctx={ctx}
tools={tools}
toolStatuses={toolStatuses}
shownEarlier={earlier.inLastTurn}
/>
)}
Expand Down Expand Up @@ -614,7 +628,14 @@ const Item = memo(function Item({ item, ctx, view }: ItemProps) {
<AssistantMessage
item={item}
ctx={ctx}
view={view ?? { blocks: item.blocks, tools: {}, earlier: new Map() }}
view={
view ?? {
blocks: item.blocks,
tools: {},
toolStatuses: NO_TOOL_STATUSES,
earlier: new Map(),
}
}
/>
);
case "notice":
Expand Down Expand Up @@ -1064,6 +1085,7 @@ function AssistantMessage({
toolUseId={block.toolUseId}
ctx={ctx}
tools={view.tools}
toolStatuses={view.toolStatuses}
shownEarlier={view.earlier.get(block.toolUseId)}
/>
),
Expand Down Expand Up @@ -1100,10 +1122,6 @@ function runKey(blocks: AssistantBlock[]): string {
return first?.type === "tool" ? first.toolUseId : "";
}

function isLive(tool: ToolCall | undefined): boolean {
return !tool || tool.status === "running" || tool.status === "streaming";
}

/** The kinds of call a run's line counts, in its order. */
const RUN_KINDS = ["commands", "reads", "edits", "searches", "others"] as const;

Expand All @@ -1123,7 +1141,7 @@ function ToolRun({
}) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const { tools } = view;
const { tools, toolStatuses } = view;
// Opens when the side panel asks to see a call of the run's.
const asked = view.asked;
// biome-ignore lint/correctness/useExhaustiveDependencies: each ask once; a call joining the run later does not open it again
Expand All @@ -1133,14 +1151,17 @@ function ToolRun({
}
}, [asked]);
const calls = blocks.flatMap((block) => (block.type === "tool" ? [tools[block.toolUseId]] : []));
const running = calls.some(isLive);
const tally = tallyRun(calls);
const live = blocks.filter((block) => {
if (block.type !== "tool") return false;
const status = toolStatuses[block.toolUseId] ?? tools[block.toolUseId]?.status;
return !status || status === "running" || status === "streaming" || status === "background";
});
const running = live.length > 0;
const tally = tallyRun(calls, toolStatuses);
const label = RUN_KINDS.filter((kind) => tally[kind] > 0)
.map((kind) => t(`chat.tool.run.${kind}`, { count: tally[kind] }))
.join(" · ");
const rows = open
? blocks
: blocks.filter((block) => block.type === "tool" && isLive(tools[block.toolUseId]));
const rows = open ? blocks : live;
return (
<div className="my-1 text-app-ui-sm" data-testid="chat-tool-run">
<div className="flex min-w-0 items-center gap-1">
Expand Down Expand Up @@ -1191,6 +1212,7 @@ function ToolRun({
toolUseId={block.toolUseId}
tool={tools[block.toolUseId]}
tools={tools}
toolStatuses={toolStatuses}
cwd={ctx.cwd}
onBackground={backgroundOf(ctx.actions, block.toolUseId)}
/>
Expand All @@ -1210,12 +1232,14 @@ function CallRow({
toolUseId,
ctx,
tools,
toolStatuses,
shownEarlier,
}: {
toolUseId: string;
ctx: ItemContext;
/** Its call and the calls it runs, by id; more is fine. */
tools: Readonly<Record<string, ToolCall>>;
toolStatuses: ToolRowStatuses;
/** The image files it sends that its turn showed before. */
shownEarlier?: ReadonlySet<string>;
}) {
Expand Down Expand Up @@ -1254,6 +1278,7 @@ function CallRow({
toolUseId={toolUseId}
tool={tool}
tools={tools}
toolStatuses={toolStatuses}
cwd={ctx.cwd}
onBackground={backgroundOf(ctx.actions, toolUseId)}
/>
Expand Down Expand Up @@ -1302,11 +1327,13 @@ function Streaming({
streaming,
ctx,
tools,
toolStatuses,
shownEarlier,
}: {
streaming: StreamingMessage;
ctx: ItemContext;
tools: Record<string, ToolCall>;
toolStatuses: ToolRowStatuses;
/** What the last turn shows in full so far, which it shows as chips. */
shownEarlier: ReadonlySet<string>;
}) {
Expand All @@ -1329,7 +1356,13 @@ function Streaming({
) : block.type === "thinking" ? (
<Thinking key={index} text={block.text} live />
) : block.toolUseId ? (
<CallRow key={block.toolUseId} toolUseId={block.toolUseId} ctx={ctx} tools={tools} />
<CallRow
key={block.toolUseId}
toolUseId={block.toolUseId}
ctx={ctx}
tools={tools}
toolStatuses={toolStatuses}
/>
) : null,
)}
</div>
Expand Down
11 changes: 2 additions & 9 deletions src/renderer/components/chat/running-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { IconButton } from "../ui/icon-button";
import { SearchInput } from "../ui/search-input";
import { relativeTime } from "./message-list";
import { FirstFew, Row, Section, useFold, useRevealedRow } from "./panel-section";
import { BackgroundIcon } from "./tool-row";
import { BackgroundBadge, BackgroundIcon } from "./tool-row";

/** How many ended rows show before the rest is asked for. */
export const ENDED_FIRST = 5;
Expand Down Expand Up @@ -405,14 +405,7 @@ const RunningRow = memo(function RunningRow({
<ActivityGlyph status={row.status} />
<span className="min-w-0 flex-1 truncate">{row.description}</span>
</button>
{row.background && (
<span
className="shrink-0 rounded-full border border-border px-1.5 text-app-micro leading-4 text-muted-foreground"
data-testid="running-background"
>
{t("chat.panel.running.background")}
</span>
)}
{row.background && <BackgroundBadge testId="running-background" />}
<RunningFor from={row.startedAt} />
{foreground && onBackground && (
<IconButton
Expand Down
40 changes: 34 additions & 6 deletions src/renderer/components/chat/tool-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { useTranslation } from "react-i18next";
import { imageFileOf } from "../../services/chat/image-look";
import { slashWindowsPath } from "../../services/chat/links";
import type { ToolCall } from "../../services/chat/model";
import { canBackground } from "../../services/chat/running";
import {
canBackground,
type ToolRowStatus,
type ToolRowStatuses,
} from "../../services/chat/running";
import { cn } from "../../utils/cn";
import { ChatImage, ToolThumbs } from "./chat-image";
import { Highlighted, highlightCode, languageOf } from "./code-highlight";
Expand All @@ -26,6 +30,7 @@ interface ToolRowProps {
toolUseId: string;
/** Every tool call the tab knows, for an Agent call's own calls. */
tools: Record<string, ToolCall>;
toolStatuses: ToolRowStatuses;
cwd: string;
/** Sends a running command or subagent to the background, as Ctrl+B does in the terminal. */
onBackground?: (toolUseId: string) => void;
Expand All @@ -51,21 +56,35 @@ export function toolTint(name: string): string {
*/
export const BackgroundIcon = Layers2;

/** The label for a job running beside the turn, in the conversation and the panel. */
export function BackgroundBadge({ testId }: { testId?: string }) {
const { t } = useTranslation();
return (
<span
className="shrink-0 rounded-full border border-border px-1.5 text-app-micro leading-4 text-muted-foreground"
data-testid={testId}
>
{t("chat.panel.running.background")}
</span>
);
}

/** Longest output an open row shows; the rest is cut. */
const MAX_OUTPUT_CHARS = 20_000;

export function ToolRow({ tool, toolUseId, tools, cwd, onBackground }: ToolRowProps) {
export function ToolRow({ tool, toolUseId, tools, toolStatuses, cwd, onBackground }: ToolRowProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const name = tool?.displayName || tool?.name || "tool";
const summary = tool ? toolSummary(tool, cwd) : "";
const status = tool?.status ?? "running";
const jobStatus = toolStatuses[toolUseId];
const status = jobStatus ?? tool?.status ?? "running";
const unsandboxed = tool ? isUnsandboxed(tool.input) : false;
const children =
tool && AGENT_TOOLS.has(tool.name)
? Object.values(tools).filter((t) => t.parentToolUseId === toolUseId)
: [];
const backgroundable = onBackground && tool && canBackground(tool);
const backgroundable = onBackground && tool && jobStatus === undefined && canBackground(tool);
return (
<div className="my-1 text-app-ui-sm" data-tool-use-id={toolUseId}>
<div className="flex min-w-0 items-center gap-1">
Expand All @@ -88,6 +107,7 @@ export function ToolRow({ tool, toolUseId, tools, cwd, onBackground }: ToolRowPr
{t("chat.tool.unsandboxed")}
</span>
)}
{status === "background" && <BackgroundBadge />}
{status === "denied" && (
<span className="shrink-0 text-muted-foreground">{t("chat.tool.denied")}</span>
)}
Expand Down Expand Up @@ -122,7 +142,14 @@ export function ToolRow({ tool, toolUseId, tools, cwd, onBackground }: ToolRowPr
{open && children.length > 0 && (
<div className="ml-4 border-l border-border pl-2">
{children.map((child) => (
<ToolRow key={child.id} toolUseId={child.id} tool={child} tools={tools} cwd={cwd} />
<ToolRow
key={child.id}
toolUseId={child.id}
tool={child}
tools={tools}
toolStatuses={toolStatuses}
cwd={cwd}
/>
))}
</div>
)}
Expand All @@ -143,11 +170,12 @@ export function isUnsandboxed(input: unknown): boolean {
);
}

function StatusIcon({ status }: { status: ToolCall["status"] }) {
function StatusIcon({ status }: { status: ToolRowStatus }) {
const cls = "size-3.5 shrink-0";
switch (status) {
case "streaming":
case "running":
case "background":
return (
<LoaderCircle className={cn(cls, "animate-spin text-[var(--state-loading-indicator)]")} />
);
Expand Down
Loading