Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a63bf965f8 | ||
|
|
c7f2ce72a6 | ||
|
|
f713405400 | ||
|
|
63ecfa9b64 |
No files matched your search
@@ -20,7 +20,7 @@ function activity(payload: Record<string, unknown>): OrchestrationThreadActivity
|
||||
* If slimming ever moves to an allowlist over the whole payload, these
|
||||
* assertions are the tripwire.
|
||||
*/
|
||||
describe("projectActivityPayload agent-field survival", () => {
|
||||
describe("projectActivityPayload", () => {
|
||||
it("preserves tool attribution (agentId/parentToolUseId) through data slimming", () => {
|
||||
const projected = projectActivityPayload(
|
||||
activity({
|
||||
@@ -97,6 +97,45 @@ describe("projectActivityPayload agent-field survival", () => {
|
||||
expect(JSON.stringify(acp.payload).length).toBeLessThan(500);
|
||||
});
|
||||
|
||||
it("normalizes Claude and OpenCode command inputs before slimming provider data", () => {
|
||||
const claude = projectActivityPayload(
|
||||
activity({
|
||||
itemType: "command_execution",
|
||||
toolCallId: "claude-call-1",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
result: { content: "x".repeat(5_000) },
|
||||
},
|
||||
}),
|
||||
);
|
||||
const openCode = projectActivityPayload(
|
||||
activity({
|
||||
itemType: "command_execution",
|
||||
toolCallId: "opencode-call-1",
|
||||
data: {
|
||||
tool: "bash",
|
||||
state: {
|
||||
status: "running",
|
||||
input: { command: "vp lint" },
|
||||
output: "x".repeat(5_000),
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(claude.payload).toMatchObject({
|
||||
toolCallId: "claude-call-1",
|
||||
data: { command: "vp test run" },
|
||||
});
|
||||
expect(openCode.payload).toMatchObject({
|
||||
toolCallId: "opencode-call-1",
|
||||
data: { command: "vp lint" },
|
||||
});
|
||||
expect(JSON.stringify(claude.payload).length).toBeLessThan(200);
|
||||
expect(JSON.stringify(openCode.payload).length).toBeLessThan(200);
|
||||
});
|
||||
|
||||
it("slims Codex-shaped mcp_tool_call items to rendered fields plus a result summary", () => {
|
||||
const projected = projectActivityPayload(
|
||||
activity({
|
||||
|
||||
@@ -125,6 +125,24 @@ function projectCommandData(data: Record<string, unknown>): Record<string, unkno
|
||||
return Object.keys(projectedItem).length > 0 ? projectedItem : undefined;
|
||||
}
|
||||
|
||||
function projectCommandValue(data: Record<string, unknown>): unknown {
|
||||
if (data.command !== undefined) {
|
||||
return data.command;
|
||||
}
|
||||
|
||||
const input = asRecord(data.input);
|
||||
if (input?.command !== undefined) {
|
||||
return input.command;
|
||||
}
|
||||
|
||||
const stateInput = asRecord(asRecord(data.state)?.input);
|
||||
if (stateInput?.command !== undefined) {
|
||||
return stateInput.command;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function summarizeToolTextOutput(value: string): string | null {
|
||||
const lines: string[] = [];
|
||||
for (const rawLine of value.split(/\r?\n/u)) {
|
||||
@@ -339,8 +357,9 @@ export function projectActivityPayload(
|
||||
if (item) {
|
||||
projectedData.item = item;
|
||||
}
|
||||
if ("command" in data) {
|
||||
projectedData.command = data.command;
|
||||
const command = projectCommandValue(data);
|
||||
if (command !== undefined) {
|
||||
projectedData.command = command;
|
||||
}
|
||||
|
||||
const changedFiles: string[] = [];
|
||||
@@ -420,10 +439,10 @@ function dropStaleContextWindowActivities(
|
||||
/**
|
||||
* Identity both clients use to fold a tool lifecycle row into the call it
|
||||
* belongs to (`deriveToolLifecycleCollapseKey` in web's `session-logic` and
|
||||
* mobile's `threadActivity`): an explicit `data.toolCallId` when the adapter
|
||||
* emits one, otherwise the itemType/title/detail triple. Returns null for rows
|
||||
* with no identity at all — those never collapse on the client either, so they
|
||||
* must not be dropped here.
|
||||
* mobile's `threadActivity`): the runtime item id ingestion stamps as
|
||||
* `toolCallId`, a legacy `data.toolCallId`, or the itemType/title/detail triple.
|
||||
* Returns null for rows with no identity at all — those never collapse on the
|
||||
* client either, so they must not be dropped here.
|
||||
*/
|
||||
function toolLifecycleIdentity(activity: OrchestrationThreadActivity): string | null {
|
||||
const payload = asRecord(activity.payload);
|
||||
@@ -431,7 +450,8 @@ function toolLifecycleIdentity(activity: OrchestrationThreadActivity): string |
|
||||
return null;
|
||||
}
|
||||
|
||||
const toolCallId = asTrimmedString(asRecord(payload.data)?.toolCallId);
|
||||
const toolCallId =
|
||||
asTrimmedString(payload.toolCallId) ?? asTrimmedString(asRecord(payload.data)?.toolCallId);
|
||||
if (toolCallId) {
|
||||
return `id:${toolCallId}`;
|
||||
}
|
||||
|
||||
@@ -2815,11 +2815,16 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
createdAt: now,
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-9"),
|
||||
itemId: asItemId("tool-call-9"),
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
status: "in_progress",
|
||||
title: "Read file",
|
||||
detail: "/tmp/file.ts",
|
||||
status: "inProgress",
|
||||
title: "Command run",
|
||||
detail: "Bash: vp test run",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2834,11 +2839,20 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
);
|
||||
|
||||
expect(thread.session?.status).toBe("ready");
|
||||
expect(
|
||||
thread.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "tool.started",
|
||||
),
|
||||
).toBe(true);
|
||||
const activity = thread.activities.find(
|
||||
(entry: ProviderRuntimeTestActivity) => entry.kind === "tool.started",
|
||||
);
|
||||
const payload = activity?.payload as Record<string, unknown> | undefined;
|
||||
expect(payload).toMatchObject({
|
||||
itemType: "command_execution",
|
||||
toolCallId: "tool-call-9",
|
||||
status: "inProgress",
|
||||
detail: "Bash: vp test run",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("consumes P1 runtime events into thread metadata, diff checkpoints, and activities", async () => {
|
||||
@@ -2956,6 +2970,8 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
expect(toolUpdate?.kind).toBe("tool.updated");
|
||||
expect(toolUpdatePayload?.itemType).toBe("command_execution");
|
||||
expect(toolUpdatePayload?.status).toBe("in_progress");
|
||||
expect(toolUpdatePayload?.toolCallId).toBe("item-p1-tool");
|
||||
expect(toolUpdatePayload?.data).toMatchObject({ toolCallId: "item-p1-tool" });
|
||||
|
||||
const warning = thread.activities.find(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-runtime-warning",
|
||||
|
||||
@@ -211,6 +211,17 @@ function truncateDetail(value: string, limit = 180): string {
|
||||
return value.length > limit ? `${value.slice(0, limit - 3)}...` : value;
|
||||
}
|
||||
|
||||
function withToolCallId(data: unknown, toolCallId: string | undefined): unknown {
|
||||
if (toolCallId === undefined) return data;
|
||||
if (data !== null && typeof data === "object" && !Array.isArray(data)) {
|
||||
return { toolCallId, ...data };
|
||||
}
|
||||
return {
|
||||
toolCallId,
|
||||
...(data !== undefined ? { value: data } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeProposedPlanMarkdown(planMarkdown: string | undefined): string | undefined {
|
||||
const trimmed = planMarkdown?.trim();
|
||||
if (!trimmed) {
|
||||
@@ -787,6 +798,7 @@ export function runtimeEventToActivities(
|
||||
if (!isToolLifecycleItemType(event.payload.itemType)) {
|
||||
return [];
|
||||
}
|
||||
const data = withToolCallId(event.payload.data, event.itemId);
|
||||
// A streaming update's `data` carries the full tool output accumulated
|
||||
// so far (adapters merge state forward), and a new activity is emitted
|
||||
// per chunk, so persisting `data` verbatim writes O(N²) bytes per tool
|
||||
@@ -803,9 +815,10 @@ export function runtimeEventToActivities(
|
||||
summary: event.payload.title ?? "Tool updated",
|
||||
payload: {
|
||||
itemType: event.payload.itemType,
|
||||
...(event.itemId !== undefined ? { toolCallId: event.itemId } : {}),
|
||||
...(event.payload.status ? { status: event.payload.status } : {}),
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
...(event.payload.data !== undefined ? { data: event.payload.data } : {}),
|
||||
...(data !== undefined ? { data } : {}),
|
||||
...(event.payload.agentId ? { agentId: event.payload.agentId } : {}),
|
||||
...(event.payload.parentToolUseId
|
||||
? { parentToolUseId: event.payload.parentToolUseId }
|
||||
@@ -821,6 +834,7 @@ export function runtimeEventToActivities(
|
||||
if (!isToolLifecycleItemType(event.payload.itemType)) {
|
||||
return [];
|
||||
}
|
||||
const data = withToolCallId(event.payload.data, event.itemId);
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -830,8 +844,10 @@ export function runtimeEventToActivities(
|
||||
summary: event.payload.title ?? "Tool",
|
||||
payload: {
|
||||
itemType: event.payload.itemType,
|
||||
...(event.itemId !== undefined ? { toolCallId: event.itemId } : {}),
|
||||
...(event.payload.status ? { status: event.payload.status } : {}),
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
...(event.payload.data !== undefined ? { data: event.payload.data } : {}),
|
||||
...(data !== undefined ? { data } : {}),
|
||||
...(event.payload.agentId ? { agentId: event.payload.agentId } : {}),
|
||||
...(event.payload.parentToolUseId
|
||||
? { parentToolUseId: event.payload.parentToolUseId }
|
||||
@@ -847,6 +863,7 @@ export function runtimeEventToActivities(
|
||||
if (!isToolLifecycleItemType(event.payload.itemType)) {
|
||||
return [];
|
||||
}
|
||||
const data = withToolCallId(event.payload.data, event.itemId);
|
||||
return [
|
||||
{
|
||||
id: event.eventId,
|
||||
@@ -856,7 +873,10 @@ export function runtimeEventToActivities(
|
||||
summary: `${event.payload.title ?? "Tool"} started`,
|
||||
payload: {
|
||||
itemType: event.payload.itemType,
|
||||
...(event.itemId !== undefined ? { toolCallId: event.itemId } : {}),
|
||||
...(event.payload.status ? { status: event.payload.status } : {}),
|
||||
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
|
||||
...(data !== undefined ? { data } : {}),
|
||||
...(event.payload.agentId ? { agentId: event.payload.agentId } : {}),
|
||||
...(event.payload.parentToolUseId
|
||||
? { parentToolUseId: event.payload.parentToolUseId }
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
isBranchMismatchDismissedForSession,
|
||||
reconcileMountedTerminalThreadIds,
|
||||
reconcileRetainedMountedThreadIds,
|
||||
resolveComposerOwnsTopAttachment,
|
||||
resolveThreadMetadataUpdateForNextTurn,
|
||||
resolveSendEnvMode,
|
||||
scheduleEnvironmentReconnectWarning,
|
||||
@@ -39,6 +40,41 @@ const projectId = ProjectId.make("project-1");
|
||||
const threadId = ThreadId.make("thread-1");
|
||||
const now = "2026-03-29T00:00:00.000Z";
|
||||
|
||||
describe("composer top attachment ownership", () => {
|
||||
it("only detaches a ready plan when its drawer is visible", () => {
|
||||
const readyPlan = {
|
||||
hasPendingApproval: false,
|
||||
pendingUserInputCount: 0,
|
||||
showPlanFollowUpPrompt: true,
|
||||
hasActiveProposedPlan: true,
|
||||
};
|
||||
|
||||
expect(resolveComposerOwnsTopAttachment({ ...readyPlan, topDrawerVisible: false })).toBe(false);
|
||||
expect(resolveComposerOwnsTopAttachment({ ...readyPlan, topDrawerVisible: true })).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps blocking interactions attached to their drawer", () => {
|
||||
expect(
|
||||
resolveComposerOwnsTopAttachment({
|
||||
hasPendingApproval: true,
|
||||
pendingUserInputCount: 0,
|
||||
showPlanFollowUpPrompt: false,
|
||||
hasActiveProposedPlan: false,
|
||||
topDrawerVisible: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
resolveComposerOwnsTopAttachment({
|
||||
hasPendingApproval: false,
|
||||
pendingUserInputCount: 1,
|
||||
showPlanFollowUpPrompt: false,
|
||||
hasActiveProposedPlan: false,
|
||||
topDrawerVisible: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("environment reconnect warning grace", () => {
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
|
||||
@@ -29,6 +29,20 @@ export const ENVIRONMENT_RECONNECT_WARNING_GRACE_MS = 2_000;
|
||||
|
||||
export const LastInvokedScriptByProjectSchema = Schema.Record(ProjectId, Schema.String);
|
||||
|
||||
export function resolveComposerOwnsTopAttachment(input: {
|
||||
hasPendingApproval: boolean;
|
||||
pendingUserInputCount: number;
|
||||
showPlanFollowUpPrompt: boolean;
|
||||
hasActiveProposedPlan: boolean;
|
||||
topDrawerVisible: boolean;
|
||||
}): boolean {
|
||||
return (
|
||||
input.hasPendingApproval ||
|
||||
input.pendingUserInputCount > 0 ||
|
||||
(input.showPlanFollowUpPrompt && input.hasActiveProposedPlan && input.topDrawerVisible)
|
||||
);
|
||||
}
|
||||
|
||||
export function scheduleEnvironmentReconnectWarning(showWarning: () => void): () => void {
|
||||
const timeoutId = globalThis.setTimeout(showWarning, ENVIRONMENT_RECONNECT_WARNING_GRACE_MS);
|
||||
return () => globalThis.clearTimeout(timeoutId);
|
||||
|
||||
@@ -221,7 +221,11 @@ import {
|
||||
import { appendPreviewAnnotationPrompt } from "../lib/previewAnnotation";
|
||||
import { appendReviewCommentsToPrompt, type ReviewCommentContext } from "../reviewCommentContext";
|
||||
import { environmentCatalog } from "../connection/catalog";
|
||||
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
|
||||
import {
|
||||
selectThreadTerminalCustomLabels,
|
||||
selectThreadTerminalUiState,
|
||||
useTerminalUiStateStore,
|
||||
} from "../terminalUiStateStore";
|
||||
import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/terminalSessions";
|
||||
import { projectEnvironment } from "../state/projects";
|
||||
import { useEnvironmentQuery } from "../state/query";
|
||||
@@ -315,6 +319,7 @@ import {
|
||||
deriveLockedProvider,
|
||||
readFileAsDataUrl,
|
||||
reconcileMountedTerminalThreadIds,
|
||||
resolveComposerOwnsTopAttachment,
|
||||
resolveThreadMetadataUpdateForNextTurn,
|
||||
resolveSendEnvMode,
|
||||
revokeBlobPreviewUrl,
|
||||
@@ -658,6 +663,7 @@ interface PersistentThreadTerminalDrawerProps {
|
||||
newShortcutLabel: string | undefined;
|
||||
closeShortcutLabel: string | undefined;
|
||||
keybindings: ResolvedKeybindingsConfig;
|
||||
onHide: () => void;
|
||||
onAddTerminalContext: (selection: TerminalContextSelection) => void;
|
||||
}
|
||||
|
||||
@@ -672,6 +678,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
|
||||
newShortcutLabel,
|
||||
closeShortcutLabel,
|
||||
keybindings,
|
||||
onHide,
|
||||
onAddTerminalContext,
|
||||
}: PersistentThreadTerminalDrawerProps) {
|
||||
const openTerminal = useAtomCommand(terminalEnvironment.open, "terminal open");
|
||||
@@ -995,6 +1002,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
|
||||
onSplitTerminal={splitTerminal}
|
||||
onSplitTerminalVertical={splitTerminalVertical}
|
||||
onNewTerminal={createNewTerminal}
|
||||
onHide={onHide}
|
||||
splitShortcutLabel={visible ? splitShortcutLabel : undefined}
|
||||
splitVerticalShortcutLabel={visible ? splitVerticalShortcutLabel : undefined}
|
||||
newShortcutLabel={visible ? newShortcutLabel : undefined}
|
||||
@@ -1557,6 +1565,16 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
const canCheckoutPullRequestIntoThread = isLocalDraftThread;
|
||||
const activeThreadId = activeThread?.id ?? null;
|
||||
const activeThreadEnvironmentId = activeThread?.environmentId ?? null;
|
||||
const activeThreadRef = useMemo(
|
||||
() =>
|
||||
activeThreadEnvironmentId && activeThreadId
|
||||
? scopeThreadRef(activeThreadEnvironmentId, activeThreadId)
|
||||
: null,
|
||||
[activeThreadEnvironmentId, activeThreadId],
|
||||
);
|
||||
const activeTerminalCustomLabels = useTerminalUiStateStore((state) =>
|
||||
selectThreadTerminalCustomLabels(state.terminalCustomLabelsByThreadKey, activeThreadRef),
|
||||
);
|
||||
const runningTerminalIds = useThreadRunningTerminalIds({
|
||||
environmentId: activeThread?.environmentId ?? null,
|
||||
threadId: activeThreadId,
|
||||
@@ -1586,18 +1604,15 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
for (const session of activeThreadKnownSessions) {
|
||||
labels.set(
|
||||
session.target.terminalId,
|
||||
resolveTerminalSessionLabel(session.target.terminalId, session.state.summary),
|
||||
activeTerminalCustomLabels[session.target.terminalId] ??
|
||||
resolveTerminalSessionLabel(session.target.terminalId, session.state.summary),
|
||||
);
|
||||
}
|
||||
for (const [terminalId, label] of Object.entries(activeTerminalCustomLabels)) {
|
||||
if (!labels.has(terminalId)) labels.set(terminalId, label);
|
||||
}
|
||||
return labels;
|
||||
}, [activeThreadKnownSessions]);
|
||||
const activeThreadRef = useMemo(
|
||||
() =>
|
||||
activeThreadEnvironmentId && activeThreadId
|
||||
? scopeThreadRef(activeThreadEnvironmentId, activeThreadId)
|
||||
: null,
|
||||
[activeThreadEnvironmentId, activeThreadId],
|
||||
);
|
||||
}, [activeTerminalCustomLabels, activeThreadKnownSessions]);
|
||||
const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null;
|
||||
const changeRequestSnapshotByKey = useAtomValue(threadChangeRequestSnapshotsAtom);
|
||||
const [timelineAnchor, setTimelineAnchor] = useState<{
|
||||
@@ -2304,6 +2319,16 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
latestTurnSettled &&
|
||||
hasActionableProposedPlan(activeProposedPlan);
|
||||
const activePendingApproval = pendingApprovals[0] ?? null;
|
||||
const [composerTopDrawerVisible, setComposerTopDrawerVisible] = useState(false);
|
||||
const composerOwnsTopAttachment = resolveComposerOwnsTopAttachment({
|
||||
hasPendingApproval: activePendingApproval !== null,
|
||||
pendingUserInputCount: pendingUserInputs.length,
|
||||
showPlanFollowUpPrompt,
|
||||
hasActiveProposedPlan: activeProposedPlan !== null,
|
||||
topDrawerVisible: composerTopDrawerVisible,
|
||||
});
|
||||
const composerBannerAttached =
|
||||
(!threadSyncPhase || activeEnvironmentUnavailable) && !composerOwnsTopAttachment;
|
||||
const {
|
||||
beginLocalDispatch,
|
||||
resetLocalDispatch,
|
||||
@@ -2826,6 +2851,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
},
|
||||
[activeThreadRef, storeSetTerminalOpen],
|
||||
);
|
||||
const hideTerminal = useCallback(() => setTerminalOpen(false), [setTerminalOpen]);
|
||||
const toggleTerminalVisibility = useCallback(() => {
|
||||
if (!activeThreadRef) return;
|
||||
const nextOpen = !terminalUiState.terminalOpen;
|
||||
@@ -4442,19 +4468,20 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
),
|
||||
title: working
|
||||
? liveCount > 0
|
||||
? `${liveCount} ${liveCount === 1 ? "agent" : "agents"} working in the background`
|
||||
: "Background work running"
|
||||
: "Monitoring in the background",
|
||||
? `${liveCount} ${liveCount === 1 ? "agent" : "agents"} working`
|
||||
: "Background work"
|
||||
: "Monitoring",
|
||||
actions: (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
size="micro"
|
||||
variant="ghost-muted"
|
||||
disabled={isStoppingBackgroundWork}
|
||||
onClick={() => void handleStopBackgroundWork()}
|
||||
>
|
||||
{isStoppingBackgroundWork ? "Stopping..." : "Stop"}
|
||||
</Button>
|
||||
),
|
||||
className: "px-3 pt-1.5 text-xs",
|
||||
};
|
||||
}, [
|
||||
activeBackgroundLiveness,
|
||||
@@ -6383,13 +6410,24 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
activeProjectTitle={activeProject?.title ?? null}
|
||||
/>
|
||||
</div>
|
||||
<ComposerBannerStack className="relative z-0" items={composerBannerItems} />
|
||||
<ComposerBannerStack
|
||||
attached={composerBannerAttached}
|
||||
className="relative z-0"
|
||||
items={composerBannerItems}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<ComposerBannerStack className="relative z-0" items={composerBannerItems} />
|
||||
<ComposerBannerStack
|
||||
attached={composerBannerAttached}
|
||||
className="relative z-0"
|
||||
items={composerBannerItems}
|
||||
/>
|
||||
)}
|
||||
{threadSyncPhase && !activeEnvironmentUnavailable ? (
|
||||
<ThreadSyncStatusPill phase={threadSyncPhase} />
|
||||
<ThreadSyncStatusPill
|
||||
attached={!composerOwnsTopAttachment}
|
||||
phase={threadSyncPhase}
|
||||
/>
|
||||
) : null}
|
||||
<div
|
||||
className="relative"
|
||||
@@ -6479,6 +6517,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
scheduleComposerFocus={scheduleComposerFocus}
|
||||
setThreadError={setThreadError}
|
||||
onExpandImage={onExpandTimelineImage}
|
||||
onTopDrawerVisibilityChange={setComposerTopDrawerVisible}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -6604,6 +6643,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
newShortcutLabel={newTerminalShortcutLabel ?? undefined}
|
||||
closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}
|
||||
keybindings={keybindings}
|
||||
onHide={hideTerminal}
|
||||
onAddTerminalContext={addTerminalContextToDraft}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -4,10 +4,19 @@ import {
|
||||
resolveTerminalSelectionActionPosition,
|
||||
shouldHandleTerminalExit,
|
||||
shouldHandleTerminalSelectionMouseUp,
|
||||
shouldShowTerminalSidebar,
|
||||
terminalSelectionActionDelayForClickCount,
|
||||
terminalSelectionLineRange,
|
||||
} from "./ThreadTerminalDrawer";
|
||||
|
||||
describe("shouldShowTerminalSidebar", () => {
|
||||
it("shows the sidebar only when there is more than one terminal", () => {
|
||||
expect(shouldShowTerminalSidebar(0)).toBe(false);
|
||||
expect(shouldShowTerminalSidebar(1)).toBe(false);
|
||||
expect(shouldShowTerminalSidebar(2)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveTerminalSelectionActionPosition", () => {
|
||||
it("prefers the selection rect over the last pointer position", () => {
|
||||
expect(
|
||||
|
||||
@@ -5,11 +5,11 @@ import {
|
||||
} from "@t3tools/client-runtime/state/runtime";
|
||||
import { type TerminalSessionState } from "@t3tools/client-runtime/state/terminal";
|
||||
import {
|
||||
PanelBottomCloseIcon,
|
||||
Plus,
|
||||
SquareSplitHorizontal,
|
||||
SquareSplitVertical,
|
||||
TerminalSquare,
|
||||
Trash2,
|
||||
XIcon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
@@ -21,8 +21,8 @@ import {
|
||||
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
|
||||
import * as Schema from "effect/Schema";
|
||||
import {
|
||||
type PointerEvent as ReactPointerEvent,
|
||||
type ReactNode,
|
||||
type PointerEvent as ReactPointerEvent,
|
||||
type SetStateAction,
|
||||
useCallback,
|
||||
useEffect,
|
||||
@@ -31,9 +31,9 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import { readTextFromClipboard, writeTextToClipboard } from "~/hooks/useCopyToClipboard";
|
||||
import { useResizableWidth } from "~/hooks/useResizableWidth";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { type TerminalContextSelection } from "~/lib/terminalContext";
|
||||
import {
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
isTerminalSplitShortcut,
|
||||
isTerminalSplitVerticalShortcut,
|
||||
isTerminalToggleShortcut,
|
||||
shortcutLabelForCommand,
|
||||
terminalDeleteShortcutData,
|
||||
terminalNavigationShortcutData,
|
||||
} from "../keybindings";
|
||||
@@ -61,6 +62,7 @@ import {
|
||||
import { readLocalApi } from "~/localApi";
|
||||
import { useClientSettings } from "../hooks/useSettings";
|
||||
import { useLocalStorage } from "../hooks/useLocalStorage";
|
||||
import { selectThreadTerminalCustomLabels, useTerminalUiStateStore } from "../terminalUiStateStore";
|
||||
import { useAttachedTerminalSession } from "../state/terminalSessions";
|
||||
import { serverEnvironment } from "../state/server";
|
||||
import { previewEnvironment } from "../state/preview";
|
||||
@@ -73,10 +75,48 @@ import {
|
||||
resolveTerminalFontSizePreference,
|
||||
TYPOGRAPHY_ADVANCED_STORAGE_KEY,
|
||||
} from "../appearanceFonts";
|
||||
import { RightPanelResizeHandle } from "./preview/RightPanelResizeHandle";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
|
||||
const MIN_DRAWER_HEIGHT = 180;
|
||||
const MAX_DRAWER_HEIGHT_RATIO = 0.75;
|
||||
const MULTI_CLICK_SELECTION_ACTION_DELAY_MS = 260;
|
||||
const TERMINAL_SIDEBAR_DEFAULT_WIDTH = 144;
|
||||
const TERMINAL_SIDEBAR_MIN_WIDTH = 144;
|
||||
const TERMINAL_SIDEBAR_MAX_WIDTH = 320;
|
||||
const TERMINAL_SIDEBAR_WIDTH_STORAGE_KEY = "t3code:terminal-sidebar-width";
|
||||
|
||||
function TerminalToolbarAction({
|
||||
label,
|
||||
disabled = false,
|
||||
onClick,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
onClick: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
size="icon-micro"
|
||||
variant="ghost"
|
||||
aria-label={label}
|
||||
aria-disabled={disabled || undefined}
|
||||
className={cn(disabled && "cursor-not-allowed opacity-64")}
|
||||
onClick={onClick}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="bottom">{label}</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function maxDrawerHeight(): number {
|
||||
if (typeof window === "undefined") return DEFAULT_THREAD_TERMINAL_HEIGHT;
|
||||
@@ -245,6 +285,10 @@ export function shouldHandleTerminalSelectionMouseUp(
|
||||
return selectionGestureActive && button === 0;
|
||||
}
|
||||
|
||||
export function shouldShowTerminalSidebar(terminalCount: number): boolean {
|
||||
return terminalCount > 1;
|
||||
}
|
||||
|
||||
export function terminalSelectionLineRange(position: {
|
||||
start: { y: number };
|
||||
end: { y: number };
|
||||
@@ -999,6 +1043,7 @@ interface ThreadTerminalDrawerProps {
|
||||
onSplitTerminal: () => void;
|
||||
onSplitTerminalVertical: () => void;
|
||||
onNewTerminal: () => void;
|
||||
onHide?: () => void;
|
||||
splitShortcutLabel?: string | undefined;
|
||||
splitVerticalShortcutLabel?: string | undefined;
|
||||
newShortcutLabel?: string | undefined;
|
||||
@@ -1014,35 +1059,6 @@ interface ThreadTerminalDrawerProps {
|
||||
terminalLaunchLocationsById?: ReadonlyMap<string, TerminalLaunchLocation>;
|
||||
}
|
||||
|
||||
interface TerminalActionButtonProps {
|
||||
label: string;
|
||||
className: string;
|
||||
onClick: () => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
function TerminalActionButton({ label, className, onClick, children }: TerminalActionButtonProps) {
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
render={<button type="button" className={className} onClick={onClick} aria-label={label} />}
|
||||
>
|
||||
{children}
|
||||
</PopoverTrigger>
|
||||
<PopoverPopup
|
||||
tooltipStyle
|
||||
side="bottom"
|
||||
sideOffset={6}
|
||||
align="center"
|
||||
className="pointer-events-none select-none"
|
||||
>
|
||||
{label}
|
||||
</PopoverPopup>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ThreadTerminalDrawer({
|
||||
mode = "drawer",
|
||||
threadRef,
|
||||
@@ -1060,6 +1076,7 @@ export default function ThreadTerminalDrawer({
|
||||
onSplitTerminal,
|
||||
onSplitTerminalVertical,
|
||||
onNewTerminal,
|
||||
onHide,
|
||||
splitShortcutLabel,
|
||||
splitVerticalShortcutLabel,
|
||||
newShortcutLabel,
|
||||
@@ -1073,6 +1090,21 @@ export default function ThreadTerminalDrawer({
|
||||
terminalLaunchLocationsById,
|
||||
}: ThreadTerminalDrawerProps) {
|
||||
const isPanel = mode === "panel";
|
||||
const { width: terminalSidebarWidth, handlers: terminalSidebarResizeHandlers } =
|
||||
useResizableWidth({
|
||||
storageKey: TERMINAL_SIDEBAR_WIDTH_STORAGE_KEY,
|
||||
defaultWidth: TERMINAL_SIDEBAR_DEFAULT_WIDTH,
|
||||
minWidth: TERMINAL_SIDEBAR_MIN_WIDTH,
|
||||
maxWidth: TERMINAL_SIDEBAR_MAX_WIDTH,
|
||||
edge: "left",
|
||||
});
|
||||
const terminalCustomLabels = useTerminalUiStateStore((state) =>
|
||||
selectThreadTerminalCustomLabels(state.terminalCustomLabelsByThreadKey, threadRef),
|
||||
);
|
||||
const setTerminalCustomLabel = useTerminalUiStateStore((state) => state.setTerminalCustomLabel);
|
||||
const [renamingTerminalId, setRenamingTerminalId] = useState<string | null>(null);
|
||||
const [terminalRenameDraft, setTerminalRenameDraft] = useState("");
|
||||
const cancelTerminalRenameRef = useRef(false);
|
||||
const [advancedTypography] = useLocalStorage(
|
||||
TYPOGRAPHY_ADVANCED_STORAGE_KEY,
|
||||
false,
|
||||
@@ -1221,19 +1253,28 @@ export default function ThreadTerminalDrawer({
|
||||
(normalizedTerminalIds.length > 0 ? [resolvedActiveTerminalId] : []);
|
||||
const splitDirection =
|
||||
resolvedTerminalGroups[resolvedActiveGroupIndex]?.splitDirection ?? "horizontal";
|
||||
const hasTerminalSidebar = normalizedTerminalIds.length > 1;
|
||||
const hasTerminalSidebar = shouldShowTerminalSidebar(normalizedTerminalIds.length);
|
||||
const isSplitView = visibleTerminalIds.length > 1;
|
||||
const showGroupHeaders =
|
||||
resolvedTerminalGroups.length > 1 ||
|
||||
resolvedTerminalGroups.some((terminalGroup) => terminalGroup.terminalIds.length > 1);
|
||||
const hasReachedSplitLimit = visibleTerminalIds.length >= MAX_TERMINALS_PER_GROUP;
|
||||
const terminalLabelById = useMemo(() => {
|
||||
const automaticTerminalLabelById = useMemo(() => {
|
||||
const next = new Map<string, string>();
|
||||
for (const terminalId of normalizedTerminalIds) {
|
||||
next.set(terminalId, terminalLabelsById?.get(terminalId) ?? getTerminalLabel(terminalId));
|
||||
}
|
||||
return next;
|
||||
}, [normalizedTerminalIds, terminalLabelsById]);
|
||||
const terminalLabelById = useMemo(() => {
|
||||
const next = new Map<string, string>();
|
||||
for (const terminalId of normalizedTerminalIds) {
|
||||
next.set(
|
||||
terminalId,
|
||||
terminalCustomLabels[terminalId]?.trim() ||
|
||||
automaticTerminalLabelById.get(terminalId) ||
|
||||
getTerminalLabel(terminalId),
|
||||
);
|
||||
}
|
||||
return next;
|
||||
}, [automaticTerminalLabelById, normalizedTerminalIds, terminalCustomLabels]);
|
||||
const resolveTerminalLaunchLocation = useCallback(
|
||||
(terminalId: string): TerminalLaunchLocation => {
|
||||
return (
|
||||
@@ -1246,6 +1287,9 @@ export default function ThreadTerminalDrawer({
|
||||
},
|
||||
[cwd, runtimeEnv, terminalLaunchLocationsById, worktreePath],
|
||||
);
|
||||
const newTerminalActionLabel = newShortcutLabel
|
||||
? `New Terminal (${newShortcutLabel})`
|
||||
: "New Terminal";
|
||||
const splitTerminalActionLabel = hasReachedSplitLimit
|
||||
? `Split Terminal Horizontally (max ${MAX_TERMINALS_PER_GROUP} per group)`
|
||||
: splitShortcutLabel
|
||||
@@ -1256,12 +1300,13 @@ export default function ThreadTerminalDrawer({
|
||||
: splitVerticalShortcutLabel
|
||||
? `Split Terminal Vertically (${splitVerticalShortcutLabel})`
|
||||
: "Split Terminal Vertically";
|
||||
const newTerminalActionLabel = newShortcutLabel
|
||||
? `New Terminal (${newShortcutLabel})`
|
||||
: "New Terminal";
|
||||
const closeTerminalActionLabel = closeShortcutLabel
|
||||
? `Close Terminal (${closeShortcutLabel})`
|
||||
: "Close Terminal";
|
||||
const terminalToggleShortcutLabel = shortcutLabelForCommand(keybindings, "terminal.toggle");
|
||||
const hideTerminalActionLabel = terminalToggleShortcutLabel
|
||||
? `Toggle terminal drawer (${terminalToggleShortcutLabel})`
|
||||
: "Toggle terminal drawer";
|
||||
const onSplitTerminalAction = useCallback(() => {
|
||||
if (hasReachedSplitLimit) return;
|
||||
onSplitTerminal();
|
||||
@@ -1270,9 +1315,53 @@ export default function ThreadTerminalDrawer({
|
||||
if (hasReachedSplitLimit) return;
|
||||
onSplitTerminalVertical();
|
||||
}, [hasReachedSplitLimit, onSplitTerminalVertical]);
|
||||
const onNewTerminalAction = useCallback(() => {
|
||||
onNewTerminal();
|
||||
}, [onNewTerminal]);
|
||||
const startTerminalRename = useCallback(
|
||||
(terminalId: string) => {
|
||||
cancelTerminalRenameRef.current = false;
|
||||
setRenamingTerminalId(terminalId);
|
||||
setTerminalRenameDraft(
|
||||
terminalCustomLabels[terminalId] ?? terminalLabelById.get(terminalId) ?? "",
|
||||
);
|
||||
},
|
||||
[terminalCustomLabels, terminalLabelById],
|
||||
);
|
||||
const finishTerminalRename = useCallback(() => {
|
||||
if (!renamingTerminalId) return;
|
||||
const nextLabel = terminalRenameDraft.trim();
|
||||
const automaticLabel = automaticTerminalLabelById.get(renamingTerminalId) ?? "";
|
||||
setTerminalCustomLabel(
|
||||
threadRef,
|
||||
renamingTerminalId,
|
||||
nextLabel.length === 0 || nextLabel === automaticLabel ? null : nextLabel,
|
||||
);
|
||||
setRenamingTerminalId(null);
|
||||
}, [
|
||||
automaticTerminalLabelById,
|
||||
renamingTerminalId,
|
||||
setTerminalCustomLabel,
|
||||
terminalRenameDraft,
|
||||
threadRef,
|
||||
]);
|
||||
const cancelTerminalRename = useCallback(() => {
|
||||
cancelTerminalRenameRef.current = true;
|
||||
setRenamingTerminalId(null);
|
||||
}, []);
|
||||
const closeTerminalSafely = useCallback(
|
||||
(terminalId: string) => {
|
||||
if (renamingTerminalId === terminalId) {
|
||||
cancelTerminalRenameRef.current = true;
|
||||
setRenamingTerminalId(null);
|
||||
}
|
||||
onCloseTerminal(terminalId);
|
||||
},
|
||||
[onCloseTerminal, renamingTerminalId],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
cancelTerminalRenameRef.current = false;
|
||||
setRenamingTerminalId(null);
|
||||
setTerminalRenameDraft("");
|
||||
}, [threadRef.environmentId, threadRef.threadId]);
|
||||
|
||||
useEffect(() => {
|
||||
onHeightChangeRef.current = onHeightChange;
|
||||
@@ -1397,7 +1486,7 @@ export default function ThreadTerminalDrawer({
|
||||
) : null}
|
||||
<div className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-4 py-6 text-center text-sm text-muted-foreground">
|
||||
<p>No terminal sessions for this thread yet.</p>
|
||||
<Button size="xs" variant="outline" onClick={onNewTerminalAction}>
|
||||
<Button size="xs" variant="outline" onClick={onNewTerminal}>
|
||||
{newTerminalActionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -1406,7 +1495,41 @@ export default function ThreadTerminalDrawer({
|
||||
}
|
||||
|
||||
const activeTerminalLaunchLocation = resolveTerminalLaunchLocation(resolvedActiveTerminalId);
|
||||
|
||||
const compactTerminalToolbar = (
|
||||
<>
|
||||
<TerminalToolbarAction
|
||||
label={splitTerminalActionLabel}
|
||||
disabled={hasReachedSplitLimit}
|
||||
onClick={onSplitTerminalAction}
|
||||
>
|
||||
<SquareSplitHorizontal className="size-3.5" />
|
||||
</TerminalToolbarAction>
|
||||
<TerminalToolbarAction
|
||||
label={splitTerminalVerticalActionLabel}
|
||||
disabled={hasReachedSplitLimit}
|
||||
onClick={onSplitTerminalVerticalAction}
|
||||
>
|
||||
<SquareSplitVertical className="size-3.5" />
|
||||
</TerminalToolbarAction>
|
||||
<TerminalToolbarAction label={newTerminalActionLabel} onClick={onNewTerminal}>
|
||||
<Plus className="size-3.5" />
|
||||
</TerminalToolbarAction>
|
||||
<TerminalToolbarAction
|
||||
label={closeTerminalActionLabel}
|
||||
onClick={() => closeTerminalSafely(resolvedActiveTerminalId)}
|
||||
>
|
||||
<XIcon className="size-3.5" />
|
||||
</TerminalToolbarAction>
|
||||
{!isPanel && onHide ? (
|
||||
<>
|
||||
<span aria-hidden className="mx-0.5 h-4 w-px bg-border/70" />
|
||||
<TerminalToolbarAction label={hideTerminalActionLabel} onClick={onHide}>
|
||||
<PanelBottomCloseIcon className="size-3.5" />
|
||||
</TerminalToolbarAction>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<aside
|
||||
data-terminal-owner={isPanel ? "right-panel" : "drawer"}
|
||||
@@ -1426,277 +1549,239 @@ export default function ThreadTerminalDrawer({
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{!hasTerminalSidebar && (
|
||||
<div className="pointer-events-none absolute right-2 top-2 z-20">
|
||||
<div className="pointer-events-auto inline-flex items-center overflow-hidden rounded-md border border-border/80 bg-background shadow-xs">
|
||||
<TerminalActionButton
|
||||
className={`p-1 text-foreground/90 transition-colors ${
|
||||
hasReachedSplitLimit
|
||||
? "cursor-not-allowed opacity-45 hover:bg-transparent"
|
||||
: "hover:bg-accent"
|
||||
}`}
|
||||
onClick={onSplitTerminalAction}
|
||||
label={splitTerminalActionLabel}
|
||||
>
|
||||
<SquareSplitHorizontal className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<div className="h-4 w-px bg-border/80" />
|
||||
<TerminalActionButton
|
||||
className={`p-1 text-foreground/90 transition-colors ${
|
||||
hasReachedSplitLimit
|
||||
? "cursor-not-allowed opacity-45 hover:bg-transparent"
|
||||
: "hover:bg-accent"
|
||||
}`}
|
||||
onClick={onSplitTerminalVerticalAction}
|
||||
label={splitTerminalVerticalActionLabel}
|
||||
>
|
||||
<SquareSplitVertical className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<div className="h-4 w-px bg-border/80" />
|
||||
<TerminalActionButton
|
||||
className="p-1 text-foreground/90 transition-colors hover:bg-accent"
|
||||
onClick={onNewTerminalAction}
|
||||
label={newTerminalActionLabel}
|
||||
>
|
||||
<Plus className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<div className="h-4 w-px bg-border/80" />
|
||||
<TerminalActionButton
|
||||
className="p-1 text-foreground/90 transition-colors hover:bg-accent"
|
||||
onClick={() => onCloseTerminal(resolvedActiveTerminalId)}
|
||||
label={closeTerminalActionLabel}
|
||||
>
|
||||
<Trash2 className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
{!hasTerminalSidebar ? (
|
||||
<div className="pointer-events-none absolute top-2 right-2 z-20">
|
||||
<div className="pointer-events-auto flex h-8 items-center rounded-lg border border-border/70 bg-background p-0.5 shadow-xs">
|
||||
{compactTerminalToolbar}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : null}
|
||||
|
||||
<div className="min-h-0 w-full flex-1">
|
||||
<div className={`flex h-full min-h-0 ${hasTerminalSidebar ? "gap-1.5" : ""}`}>
|
||||
<div className="min-w-0 flex-1">
|
||||
{isSplitView ? (
|
||||
<div
|
||||
className="grid h-full w-full min-w-0 gap-0 overflow-hidden"
|
||||
style={
|
||||
splitDirection === "vertical"
|
||||
? {
|
||||
gridTemplateRows: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
|
||||
}
|
||||
: {
|
||||
gridTemplateColumns: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
|
||||
}
|
||||
}
|
||||
>
|
||||
{visibleTerminalIds.map((terminalId) => {
|
||||
const terminalLaunchLocation = resolveTerminalLaunchLocation(terminalId);
|
||||
return (
|
||||
<div
|
||||
key={terminalId}
|
||||
className={`min-h-0 min-w-0 ${
|
||||
splitDirection === "vertical"
|
||||
? "border-t first:border-t-0"
|
||||
: "border-l first:border-l-0"
|
||||
} ${
|
||||
terminalId === resolvedActiveTerminalId
|
||||
? "border-border"
|
||||
: "border-border/70"
|
||||
}`}
|
||||
onMouseDown={() => {
|
||||
if (terminalId !== resolvedActiveTerminalId) {
|
||||
onActiveTerminalChange(terminalId);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
advancedTypography={advancedTypography}
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={terminalId}
|
||||
terminalLabel={terminalLabelById.get(terminalId) ?? "Terminal"}
|
||||
cwd={terminalLaunchLocation.cwd}
|
||||
{...(terminalLaunchLocation.worktreePath !== undefined
|
||||
? { worktreePath: terminalLaunchLocation.worktreePath }
|
||||
: {})}
|
||||
{...(terminalLaunchLocation.runtimeEnv
|
||||
? { runtimeEnv: terminalLaunchLocation.runtimeEnv }
|
||||
: {})}
|
||||
onSessionExited={() => onCloseTerminal(terminalId)}
|
||||
onAddTerminalContext={onAddTerminalContext}
|
||||
focusRequestId={focusRequestId}
|
||||
autoFocus={terminalId === resolvedActiveTerminalId}
|
||||
resizeEpoch={resizeEpoch}
|
||||
drawerHeight={drawerHeight}
|
||||
keybindings={keybindings}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex min-h-0 w-full flex-1">
|
||||
<div className="min-w-0 flex-1">
|
||||
{isSplitView ? (
|
||||
<div
|
||||
className="grid h-full w-full min-w-0 gap-0 overflow-hidden"
|
||||
style={
|
||||
splitDirection === "vertical"
|
||||
? {
|
||||
gridTemplateRows: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
|
||||
}
|
||||
: {
|
||||
gridTemplateColumns: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
|
||||
}
|
||||
}
|
||||
>
|
||||
{visibleTerminalIds.map((terminalId) => {
|
||||
const terminalLaunchLocation = resolveTerminalLaunchLocation(terminalId);
|
||||
const isActive = terminalId === resolvedActiveTerminalId;
|
||||
return (
|
||||
<div
|
||||
key={terminalId}
|
||||
className={cn(
|
||||
"min-h-0 min-w-0",
|
||||
splitDirection === "vertical"
|
||||
? "border-t first:border-t-0"
|
||||
: "border-l first:border-l-0",
|
||||
isActive ? "border-border" : "border-border/70",
|
||||
)}
|
||||
onMouseDown={() => {
|
||||
if (!isActive) onActiveTerminalChange(terminalId);
|
||||
}}
|
||||
>
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
advancedTypography={advancedTypography}
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={terminalId}
|
||||
terminalLabel={terminalLabelById.get(terminalId) ?? "Terminal"}
|
||||
cwd={terminalLaunchLocation.cwd}
|
||||
{...(terminalLaunchLocation.worktreePath !== undefined
|
||||
? { worktreePath: terminalLaunchLocation.worktreePath }
|
||||
: {})}
|
||||
{...(terminalLaunchLocation.runtimeEnv
|
||||
? { runtimeEnv: terminalLaunchLocation.runtimeEnv }
|
||||
: {})}
|
||||
onSessionExited={() => closeTerminalSafely(terminalId)}
|
||||
onAddTerminalContext={onAddTerminalContext}
|
||||
focusRequestId={focusRequestId}
|
||||
autoFocus={isActive}
|
||||
resizeEpoch={resizeEpoch}
|
||||
drawerHeight={drawerHeight}
|
||||
keybindings={keybindings}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
advancedTypography={advancedTypography}
|
||||
key={resolvedActiveTerminalId}
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={resolvedActiveTerminalId}
|
||||
terminalLabel={terminalLabelById.get(resolvedActiveTerminalId) ?? "Terminal"}
|
||||
cwd={activeTerminalLaunchLocation.cwd}
|
||||
{...(activeTerminalLaunchLocation.worktreePath !== undefined
|
||||
? { worktreePath: activeTerminalLaunchLocation.worktreePath }
|
||||
: {})}
|
||||
{...(activeTerminalLaunchLocation.runtimeEnv
|
||||
? { runtimeEnv: activeTerminalLaunchLocation.runtimeEnv }
|
||||
: {})}
|
||||
onSessionExited={() => onCloseTerminal(resolvedActiveTerminalId)}
|
||||
onAddTerminalContext={onAddTerminalContext}
|
||||
focusRequestId={focusRequestId}
|
||||
autoFocus
|
||||
resizeEpoch={resizeEpoch}
|
||||
drawerHeight={drawerHeight}
|
||||
keybindings={keybindings}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasTerminalSidebar && (
|
||||
<aside className="flex w-36 min-w-36 flex-col border border-border/70 bg-muted/10">
|
||||
<div className="flex h-[22px] items-stretch justify-end border-b border-border/70">
|
||||
<div className="inline-flex h-full items-stretch">
|
||||
<TerminalActionButton
|
||||
className={`inline-flex h-full items-center px-1 text-foreground/90 transition-colors ${
|
||||
hasReachedSplitLimit
|
||||
? "cursor-not-allowed opacity-45 hover:bg-transparent"
|
||||
: "hover:bg-accent/70"
|
||||
}`}
|
||||
onClick={onSplitTerminalAction}
|
||||
label={splitTerminalActionLabel}
|
||||
>
|
||||
<SquareSplitHorizontal className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<TerminalActionButton
|
||||
className={`inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors ${
|
||||
hasReachedSplitLimit
|
||||
? "cursor-not-allowed opacity-45 hover:bg-transparent"
|
||||
: "hover:bg-accent/70"
|
||||
}`}
|
||||
onClick={onSplitTerminalVerticalAction}
|
||||
label={splitTerminalVerticalActionLabel}
|
||||
>
|
||||
<SquareSplitVertical className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<TerminalActionButton
|
||||
className="inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors hover:bg-accent/70"
|
||||
onClick={onNewTerminalAction}
|
||||
label={newTerminalActionLabel}
|
||||
>
|
||||
<Plus className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
<TerminalActionButton
|
||||
className="inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors hover:bg-accent/70"
|
||||
onClick={() => onCloseTerminal(resolvedActiveTerminalId)}
|
||||
label={closeTerminalActionLabel}
|
||||
>
|
||||
<Trash2 className="size-3.25" />
|
||||
</TerminalActionButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-1 py-1">
|
||||
{resolvedTerminalGroups.map((terminalGroup, groupIndex) => {
|
||||
const isGroupActive =
|
||||
terminalGroup.terminalIds.includes(resolvedActiveTerminalId);
|
||||
const groupActiveTerminalId = isGroupActive
|
||||
? resolvedActiveTerminalId
|
||||
: (terminalGroup.terminalIds[0] ?? resolvedActiveTerminalId);
|
||||
|
||||
return (
|
||||
<div key={terminalGroup.id} className="pb-0.5">
|
||||
{showGroupHeaders && (
|
||||
<button
|
||||
type="button"
|
||||
className={`flex w-full items-center rounded px-1 py-0.5 text-[10px] uppercase tracking-[0.08em] ${
|
||||
isGroupActive
|
||||
? "bg-accent/70 text-foreground"
|
||||
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => onActiveTerminalChange(groupActiveTerminalId)}
|
||||
>
|
||||
Group {groupIndex + 1}
|
||||
</button>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={showGroupHeaders ? "ml-1 border-l border-border/60 pl-1.5" : ""}
|
||||
>
|
||||
{terminalGroup.terminalIds.map((terminalId) => {
|
||||
const isActive = terminalId === resolvedActiveTerminalId;
|
||||
const closeTerminalLabel = `Close ${
|
||||
terminalLabelById.get(terminalId) ?? "terminal"
|
||||
}${isActive && closeShortcutLabel ? ` (${closeShortcutLabel})` : ""}`;
|
||||
return (
|
||||
<div
|
||||
key={terminalId}
|
||||
className={`group flex items-center gap-1 rounded px-1 py-0.5 text-[11px] ${
|
||||
isActive
|
||||
? "bg-accent text-foreground"
|
||||
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
{showGroupHeaders && (
|
||||
<span className="text-[10px] text-muted-foreground/80">└</span>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-w-0 flex-1 items-center gap-1 text-left"
|
||||
onClick={() => onActiveTerminalChange(terminalId)}
|
||||
>
|
||||
<TerminalSquare className="size-3 shrink-0" />
|
||||
<span className="truncate">
|
||||
{terminalLabelById.get(terminalId) ?? "Terminal"}
|
||||
</span>
|
||||
</button>
|
||||
{normalizedTerminalIds.length > 1 && (
|
||||
<Popover>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex size-3.5 items-center justify-center rounded text-xs font-medium leading-none text-muted-foreground opacity-0 transition hover:bg-accent hover:text-foreground group-hover:opacity-100"
|
||||
onClick={() => onCloseTerminal(terminalId)}
|
||||
aria-label={closeTerminalLabel}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<XIcon className="size-2.5" />
|
||||
</PopoverTrigger>
|
||||
<PopoverPopup
|
||||
tooltipStyle
|
||||
side="bottom"
|
||||
sideOffset={6}
|
||||
align="center"
|
||||
className="pointer-events-none select-none"
|
||||
>
|
||||
{closeTerminalLabel}
|
||||
</PopoverPopup>
|
||||
</Popover>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
advancedTypography={advancedTypography}
|
||||
key={resolvedActiveTerminalId}
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={resolvedActiveTerminalId}
|
||||
terminalLabel={terminalLabelById.get(resolvedActiveTerminalId) ?? "Terminal"}
|
||||
cwd={activeTerminalLaunchLocation.cwd}
|
||||
{...(activeTerminalLaunchLocation.worktreePath !== undefined
|
||||
? { worktreePath: activeTerminalLaunchLocation.worktreePath }
|
||||
: {})}
|
||||
{...(activeTerminalLaunchLocation.runtimeEnv
|
||||
? { runtimeEnv: activeTerminalLaunchLocation.runtimeEnv }
|
||||
: {})}
|
||||
onSessionExited={() => closeTerminalSafely(resolvedActiveTerminalId)}
|
||||
onAddTerminalContext={onAddTerminalContext}
|
||||
focusRequestId={focusRequestId}
|
||||
autoFocus
|
||||
resizeEpoch={resizeEpoch}
|
||||
drawerHeight={drawerHeight}
|
||||
keybindings={keybindings}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<aside
|
||||
className={cn(
|
||||
"relative flex shrink-0 flex-col border-l border-border/70 bg-muted/10",
|
||||
!hasTerminalSidebar && "hidden",
|
||||
)}
|
||||
style={{ width: `${terminalSidebarWidth}px` }}
|
||||
>
|
||||
<RightPanelResizeHandle handlers={terminalSidebarResizeHandlers} />
|
||||
<div className="flex h-9 shrink-0 items-center justify-center border-b border-border/70 px-2">
|
||||
{hasTerminalSidebar ? compactTerminalToolbar : null}
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto p-1">
|
||||
{resolvedTerminalGroups.map((terminalGroup, groupIndex) => {
|
||||
const isSplitGroup = terminalGroup.terminalIds.length > 1;
|
||||
const splitVertically = terminalGroup.splitDirection === "vertical";
|
||||
const SplitIcon = splitVertically ? SquareSplitVertical : SquareSplitHorizontal;
|
||||
return (
|
||||
<div
|
||||
key={terminalGroup.id}
|
||||
className={cn(
|
||||
groupIndex > 0 && "mt-1",
|
||||
isSplitGroup && "rounded-lg border border-border/80 bg-muted/20 p-1",
|
||||
)}
|
||||
>
|
||||
{isSplitGroup ? (
|
||||
<div className="flex h-5 items-center gap-1 px-1 text-[10px] font-medium text-muted-foreground">
|
||||
<SplitIcon className="size-3" />
|
||||
<span>{splitVertically ? "Split down" : "Split right"}</span>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={cn(isSplitGroup && "space-y-0.5")}>
|
||||
{terminalGroup.terminalIds.map((terminalId) => {
|
||||
const isActive = terminalId === resolvedActiveTerminalId;
|
||||
const automaticLabel =
|
||||
automaticTerminalLabelById.get(terminalId) ?? "Terminal";
|
||||
const customLabel = terminalCustomLabels[terminalId]?.trim() ?? "";
|
||||
const displayLabel = terminalLabelById.get(terminalId) ?? automaticLabel;
|
||||
const isRenaming = renamingTerminalId === terminalId;
|
||||
const terminalTabTooltipLabel = `${displayLabel}${customLabel && customLabel !== automaticLabel ? ` · ${automaticLabel}` : ""} — ${resolveTerminalLaunchLocation(terminalId).cwd} · F2 to rename`;
|
||||
return (
|
||||
<div
|
||||
key={terminalId}
|
||||
className={cn(
|
||||
"group/tab flex h-6 items-center gap-0.5 rounded-md pr-2 text-xs",
|
||||
isSplitGroup ? "pl-0.5" : "pl-1.5",
|
||||
isActive
|
||||
? "bg-accent text-foreground"
|
||||
: "text-muted-foreground hover:bg-accent/50 hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="group/close relative flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm hover:bg-muted"
|
||||
aria-label={`Close ${displayLabel}`}
|
||||
onClick={() => closeTerminalSafely(terminalId)}
|
||||
>
|
||||
<TerminalSquare className="size-3 shrink-0 group-hover/tab:hidden group-focus-visible/close:hidden pointer-coarse:hidden" />
|
||||
<XIcon className="hidden size-3 group-hover/tab:block group-focus-visible/close:block pointer-coarse:block" />
|
||||
</button>
|
||||
{isRenaming ? (
|
||||
<input
|
||||
autoFocus
|
||||
value={terminalRenameDraft}
|
||||
aria-label="Rename terminal"
|
||||
className="h-6 min-w-0 flex-1 rounded border border-input bg-background px-1.5 text-xs text-foreground outline-none focus:ring-2 focus:ring-ring"
|
||||
onFocus={(event) => event.currentTarget.select()}
|
||||
onChange={(event) =>
|
||||
setTerminalRenameDraft(event.currentTarget.value)
|
||||
}
|
||||
onBlur={() => {
|
||||
if (cancelTerminalRenameRef.current) {
|
||||
cancelTerminalRenameRef.current = false;
|
||||
return;
|
||||
}
|
||||
finishTerminalRename();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.stopPropagation();
|
||||
if (event.nativeEvent.isComposing) return;
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
finishTerminalRename();
|
||||
} else if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
cancelTerminalRename();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-w-0 flex-1 cursor-pointer items-center text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
aria-keyshortcuts="F2"
|
||||
onClick={() => onActiveTerminalChange(terminalId)}
|
||||
onContextMenu={(event) => {
|
||||
event.preventDefault();
|
||||
onActiveTerminalChange(terminalId);
|
||||
startTerminalRename(terminalId);
|
||||
}}
|
||||
onDoubleClick={(event) => {
|
||||
event.preventDefault();
|
||||
onActiveTerminalChange(terminalId);
|
||||
startTerminalRename(terminalId);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "F2") return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
startTerminalRename(terminalId);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{displayLabel}
|
||||
{customLabel && customLabel !== automaticLabel ? (
|
||||
<span className="font-normal text-muted-foreground/80">
|
||||
{` · ${automaticLabel}`}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="left">{terminalTabTooltipLabel}</TooltipPopup>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
|
||||
@@ -23,14 +23,10 @@ describe("ChangedFilesCard", () => {
|
||||
expect(markup).toContain('data-changed-files-state="expanded"');
|
||||
expect(markup).toContain('aria-expanded="true"');
|
||||
expect(markup).toContain("whitespace-nowrap");
|
||||
expect(markup).toContain('class="group flex min-w-0 flex-1 items-center rounded-xl');
|
||||
expect(markup).not.toMatch(/class="group flex min-w-0 flex-1 items-center[^"]*overflow-hidden/);
|
||||
expect(markup).toContain('class="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden"');
|
||||
expect(markup).toContain('class="flex min-w-0 items-center gap-1.5 rounded-md px-1 py-1');
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1 whitespace-nowrap');
|
||||
expect(markup).toContain('class="ml-1 hidden min-w-0 flex-1 truncate');
|
||||
expect(markup).toContain("@[24rem]/changed-files:inline");
|
||||
expect(markup).not.toContain("sm:inline");
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1.5 pr-1"');
|
||||
expect(markup).toContain('class="hidden @[24rem]/changed-files:inline">Open diff</span>');
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1.5"');
|
||||
expect(markup).toContain("!size-[22px]");
|
||||
expect(markup).toContain("size-3");
|
||||
expect(markup).toContain('aria-label="Collapse all folders"');
|
||||
@@ -38,9 +34,11 @@ describe("ChangedFilesCard", () => {
|
||||
expect(markup).toContain('role="group" aria-label="2 additions, 1 deletions"');
|
||||
expect(markup).toContain("1 changed file");
|
||||
expect(markup).not.toContain("1 changed files");
|
||||
expect(markup).not.toContain("Hide files");
|
||||
expect(markup).not.toContain("ml-auto");
|
||||
});
|
||||
|
||||
it("renders a scope and representative-file preview for a large latest change", () => {
|
||||
it("renders a clean representative-file preview for a large latest change", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ChangedFilesCard
|
||||
turnId={TurnId.make("turn-1")}
|
||||
@@ -67,14 +65,16 @@ describe("ChangedFilesCard", () => {
|
||||
|
||||
expect(markup).toContain('data-changed-files-state="preview"');
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
expect(markup).toContain("apps");
|
||||
expect(markup).toContain("2 files");
|
||||
expect(markup).toContain("packages");
|
||||
expect(markup).toContain("root");
|
||||
expect(markup).toContain("apps/web/src/");
|
||||
expect(markup).toContain("packages/shared/src/");
|
||||
expect(markup).toContain("App.tsx");
|
||||
expect(markup).toContain("git.ts");
|
||||
expect(markup).toContain("README.md");
|
||||
expect(markup).toContain("Show all 4 files");
|
||||
expect(markup).not.toContain("basis-0");
|
||||
expect(markup).not.toContain("+1 more");
|
||||
expect(markup).not.toContain("Show files");
|
||||
expect(markup).toContain('aria-label="120 additions, 20 deletions"');
|
||||
expect(markup).toContain("focus-visible:ring-inset");
|
||||
expect(markup).not.toContain("App.test.tsx");
|
||||
});
|
||||
|
||||
|
||||
@@ -19,11 +19,7 @@ import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel";
|
||||
import { PierreEntryIcon } from "./PierreEntryIcon";
|
||||
import { Button } from "../ui/button";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
changedFileName,
|
||||
selectChangedFilePreview,
|
||||
summarizeChangedFileScopes,
|
||||
} from "./changedFilesPresentation";
|
||||
import { changedFileName, selectChangedFilePreview } from "./changedFilesPresentation";
|
||||
|
||||
const EMPTY_DIRECTORY_OVERRIDES: Record<string, boolean> = {};
|
||||
|
||||
@@ -50,13 +46,12 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
onOpenTurnDiff,
|
||||
} = props;
|
||||
const summaryStat = useMemo(() => summarizeTurnDiffStats(files), [files]);
|
||||
const scopeSummary = useMemo(() => summarizeChangedFileScopes(files), [files]);
|
||||
const previewFiles = useMemo(() => selectChangedFilePreview(files), [files]);
|
||||
const compactPreviewVisible = showCompactPreview && !expanded;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="@container/changed-files mt-4 rounded-2xl border border-border/70 bg-secondary p-2 dark:border-transparent dark:bg-input/32"
|
||||
className="@container/changed-files mt-4 rounded-xl border border-border/70 bg-secondary p-1.5 dark:border-transparent dark:bg-input/32"
|
||||
data-changed-files-state={
|
||||
expanded ? "expanded" : compactPreviewVisible ? "preview" : "collapsed"
|
||||
}
|
||||
@@ -64,7 +59,7 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
<div
|
||||
data-changed-files-header=""
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-2 rounded-xl",
|
||||
"flex items-center justify-between gap-2 rounded-lg px-1",
|
||||
expanded &&
|
||||
"sticky top-2 z-10 mb-2 bg-secondary dark:bg-[color-mix(in_srgb,var(--foreground)_2.5%,var(--background))]",
|
||||
)}
|
||||
@@ -73,36 +68,31 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
data-scroll-anchor-ignore
|
||||
className="group flex min-w-0 flex-1 items-center rounded-xl px-2 py-1.5 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
className="flex min-w-0 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(!expanded)}
|
||||
>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
<span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
className="text-xs leading-4"
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="ml-1 hidden min-w-0 flex-1 truncate text-[11px] text-muted-foreground group-hover:text-foreground/80 @[24rem]/changed-files:inline">
|
||||
{expanded ? "Hide files" : "Show files"}
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
<span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
className="text-xs leading-4"
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
<div className="flex shrink-0 items-center gap-1.5 pr-1">
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
{expanded ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
@@ -160,43 +150,35 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
onOpenTurnDiff={onOpenTurnDiff}
|
||||
/>
|
||||
) : compactPreviewVisible ? (
|
||||
<div className="px-2 pb-1.5 pt-1">
|
||||
<p className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground">
|
||||
{scopeSummary.map((scope, index) => (
|
||||
<span key={scope.label} className="inline-flex items-center gap-1">
|
||||
{index > 0 ? <span aria-hidden="true">·</span> : null}
|
||||
<span className="font-mono text-foreground/75">{scope.label}</span>
|
||||
<span>
|
||||
{scope.fileCount} file{scope.fileCount === 1 ? "" : "s"}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-1.5">
|
||||
<div className="px-1.5 pb-1 pt-0.5">
|
||||
<div className="flex min-w-0 items-center gap-x-3 overflow-hidden">
|
||||
{previewFiles.map((file) => (
|
||||
<button
|
||||
key={file.path}
|
||||
type="button"
|
||||
title={file.path}
|
||||
className="inline-flex max-w-48 items-center gap-1 rounded-md border border-border/70 bg-background/45 px-1.5 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
className="group flex min-h-6 min-w-0 max-w-72 shrink items-center gap-1.5 rounded-md px-1 text-left transition-colors hover:bg-accent/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
||||
onClick={() => onOpenTurnDiff(turnId, file.path)}
|
||||
>
|
||||
<PierreEntryIcon
|
||||
pathValue={file.path}
|
||||
kind="file"
|
||||
theme={resolvedTheme}
|
||||
className="size-3 shrink-0 text-muted-foreground/70"
|
||||
className="size-3.5 shrink-0 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate">{changedFileName(file.path)}</span>
|
||||
<span className="min-w-0 truncate font-mono text-xs text-foreground/75 group-hover:text-foreground">
|
||||
{changedFileName(file.path)}
|
||||
</span>
|
||||
{hasNonZeroStat(file) ? (
|
||||
<DiffStatLabel
|
||||
additions={file.additions}
|
||||
deletions={file.deletions}
|
||||
layout="inline"
|
||||
className="shrink-0 text-[10px]"
|
||||
/>
|
||||
) : null}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(true)}
|
||||
>
|
||||
Show all {files.length} files
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -272,11 +254,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
) : (
|
||||
<FolderClosedIcon className="size-3.5 shrink-0 text-muted-foreground/75" />
|
||||
)}
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
|
||||
<span className="min-w-0 truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
|
||||
{node.name}
|
||||
</span>
|
||||
{hasNonZeroStat(node.stat) && (
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<span className="ml-1 shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
)}
|
||||
@@ -307,11 +289,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
theme={resolvedTheme}
|
||||
className="size-3.5 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90">
|
||||
<span className="min-w-0 truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90">
|
||||
{node.name}
|
||||
</span>
|
||||
{node.stat && (
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<span className="ml-1 shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -49,12 +49,24 @@ describe("ComposerBannerStack", () => {
|
||||
const markup = renderToStaticMarkup(<ComposerBannerStack items={[banner("front")]} />);
|
||||
|
||||
expect(markup).not.toContain("data-composer-banner-stack-expanded-items");
|
||||
expect(markup).toContain("alert-glass");
|
||||
expect(markup).toContain("chat-composer-drawer-surface");
|
||||
expect(markup).toContain("chat-composer-drawer-attached");
|
||||
expect(markup).toContain('data-composer-banner-drawer="true"');
|
||||
expect(markup).toContain('data-variant="warning"');
|
||||
expect(markup).toContain("transform:none");
|
||||
expect(markup).not.toContain("will-change:transform");
|
||||
});
|
||||
|
||||
it("renders a detached banner when another composer status sits below it", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerBannerStack attached={false} items={[banner("front")]} />,
|
||||
);
|
||||
|
||||
expect(markup).toContain("alert-glass");
|
||||
expect(markup).not.toContain("chat-composer-drawer-slot");
|
||||
expect(markup).not.toContain("chat-composer-drawer-attached");
|
||||
});
|
||||
|
||||
it("applies item-specific surface and action layout classes", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerBannerStack
|
||||
|
||||
@@ -50,11 +50,16 @@ export interface ComposerBannerStackItem {
|
||||
}
|
||||
|
||||
interface ComposerBannerStackProps {
|
||||
readonly attached?: boolean;
|
||||
readonly className?: string;
|
||||
readonly items: ReadonlyArray<ComposerBannerStackItem>;
|
||||
}
|
||||
|
||||
export function ComposerBannerStack({ className, items }: ComposerBannerStackProps) {
|
||||
export function ComposerBannerStack({
|
||||
attached = true,
|
||||
className,
|
||||
items,
|
||||
}: ComposerBannerStackProps) {
|
||||
const [requestedExitingItemId, setExitingItemId] = useState<string | null>(null);
|
||||
const dismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const exitingItemId =
|
||||
@@ -98,7 +103,14 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn("group/banner-stack mx-auto mb-2 max-w-3xl", className)}>
|
||||
<div
|
||||
className={cn(
|
||||
"group/banner-stack max-w-[calc(48rem-2.75rem)]",
|
||||
attached ? "chat-composer-drawer-slot" : "mx-auto mb-2 w-[calc(100%-2.75rem)]",
|
||||
className,
|
||||
)}
|
||||
data-composer-banner-drawer="true"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex flex-col-reverse",
|
||||
@@ -108,7 +120,7 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
{showCollapsedStackCap && firstStackedItem ? (
|
||||
<div
|
||||
className={cn(
|
||||
"pointer-events-none absolute inset-x-0 -top-3 z-0 mx-auto h-3 rounded-t-[22px]",
|
||||
"pointer-events-none absolute inset-x-0 -top-3 z-0 mx-auto h-3 rounded-t-2xl",
|
||||
"border border-b-0 bg-background/96 shadow-[0_6px_18px_rgba(0,0,0,0.06)]",
|
||||
stackCapBorderClass[firstStackedItem.variant],
|
||||
"transition-opacity duration-150 ease-out",
|
||||
@@ -130,6 +142,7 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
>
|
||||
<ComposerBannerStackAlert
|
||||
item={frontItem}
|
||||
attached={attached}
|
||||
exiting={exitingItemId === frontItem.id}
|
||||
onDismissRequest={() => requestDismiss(frontItem)}
|
||||
/>
|
||||
@@ -162,6 +175,7 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
>
|
||||
<ComposerBannerStackAlert
|
||||
item={item}
|
||||
attached={false}
|
||||
exiting={exitingItemId === item.id}
|
||||
onDismissRequest={() => requestDismiss(item)}
|
||||
/>
|
||||
@@ -178,10 +192,12 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
||||
|
||||
function ComposerBannerStackAlert({
|
||||
item,
|
||||
attached,
|
||||
exiting,
|
||||
onDismissRequest,
|
||||
}: {
|
||||
readonly item: ComposerBannerStackItem;
|
||||
readonly attached: boolean;
|
||||
readonly exiting: boolean;
|
||||
readonly onDismissRequest: () => void;
|
||||
}) {
|
||||
@@ -190,7 +206,12 @@ function ComposerBannerStackAlert({
|
||||
return (
|
||||
<Alert
|
||||
variant={item.variant}
|
||||
className={cn("alert-glass rounded-[22px]", item.className)}
|
||||
className={cn(
|
||||
attached
|
||||
? "chat-composer-drawer-surface chat-composer-drawer-attached px-3 pt-2 pb-[calc(var(--chat-composer-attachment-overlap)_+_0.375rem)]"
|
||||
: "alert-glass rounded-[22px]",
|
||||
item.className,
|
||||
)}
|
||||
data-variant={item.variant}
|
||||
>
|
||||
{item.icon}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { ComposerCommandMenu } from "./ComposerCommandMenu";
|
||||
|
||||
describe("ComposerCommandMenu", () => {
|
||||
it("renders slash-command results as an attached composer drawer", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerCommandMenu
|
||||
items={[]}
|
||||
resolvedTheme="dark"
|
||||
isLoading={false}
|
||||
triggerKind="slash-command"
|
||||
activeItemId={null}
|
||||
onHighlightedItemChange={() => {}}
|
||||
onSelect={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-composer-command-drawer="true"');
|
||||
expect(markup).toContain("chat-composer-drawer-surface");
|
||||
expect(markup).toContain("chat-composer-drawer-attached");
|
||||
expect(markup).not.toContain("dropdown-glass");
|
||||
});
|
||||
|
||||
it("renders commands without a category heading or invented icons", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerCommandMenu
|
||||
items={[
|
||||
{
|
||||
id: "slash:model",
|
||||
type: "slash-command",
|
||||
command: "model",
|
||||
label: "/model",
|
||||
description: "Switch response model for this thread",
|
||||
},
|
||||
]}
|
||||
resolvedTheme="dark"
|
||||
isLoading={false}
|
||||
triggerKind="slash-command"
|
||||
activeItemId="slash:model"
|
||||
onHighlightedItemChange={() => {}}
|
||||
onSelect={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("/model");
|
||||
expect(markup).toContain("Switch response model for this thread");
|
||||
expect(markup).not.toContain("Built-in");
|
||||
expect(markup).not.toContain("<svg");
|
||||
expect(markup).toContain("font-sans text-xs font-medium");
|
||||
expect(markup).not.toContain("font-mono");
|
||||
expect(markup).toContain("text-right");
|
||||
});
|
||||
});
|
||||
@@ -4,20 +4,12 @@ import {
|
||||
type ServerProviderSkill,
|
||||
type ServerProviderSlashCommand,
|
||||
} from "@t3tools/contracts";
|
||||
import { BotIcon } from "lucide-react";
|
||||
import { memo, useLayoutEffect, useMemo, useRef } from "react";
|
||||
import { memo, useLayoutEffect, useRef } from "react";
|
||||
|
||||
import { type ComposerSlashCommand, type ComposerTriggerKind } from "../../composer-logic";
|
||||
import { formatProviderSkillInstallSource } from "~/providerSkillPresentation";
|
||||
import { cn } from "~/lib/utils";
|
||||
import {
|
||||
Command,
|
||||
CommandGroup,
|
||||
CommandGroupLabel,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
CommandSeparator,
|
||||
} from "../ui/command";
|
||||
import { Command, CommandGroup, CommandItem, CommandList } from "../ui/command";
|
||||
import { PierreEntryIcon } from "./PierreEntryIcon";
|
||||
|
||||
export type ComposerCommandItem =
|
||||
@@ -53,73 +45,17 @@ export type ComposerCommandItem =
|
||||
description: string;
|
||||
};
|
||||
|
||||
type ComposerCommandGroup = {
|
||||
id: string;
|
||||
label: string | null;
|
||||
items: ComposerCommandItem[];
|
||||
};
|
||||
|
||||
function SkillGlyph(props: { className?: string }) {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.85"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
className={props.className}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" />
|
||||
<path d="m3.3 7 8.7 5 8.7-5" />
|
||||
<path d="M12 22V12" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
function groupCommandItems(
|
||||
items: ComposerCommandItem[],
|
||||
triggerKind: ComposerTriggerKind | null,
|
||||
groupSlashCommandSections: boolean,
|
||||
): ComposerCommandGroup[] {
|
||||
if (triggerKind === "skill") {
|
||||
return items.length > 0 ? [{ id: "skills", label: "Skills", items }] : [];
|
||||
}
|
||||
if (triggerKind !== "slash-command" || !groupSlashCommandSections) {
|
||||
return [{ id: "default", label: null, items }];
|
||||
}
|
||||
|
||||
const builtInItems = items.filter((item) => item.type === "slash-command");
|
||||
const providerItems = items.filter((item) => item.type === "provider-slash-command");
|
||||
|
||||
const groups: ComposerCommandGroup[] = [];
|
||||
if (builtInItems.length > 0) {
|
||||
groups.push({ id: "built-in", label: "Built-in", items: builtInItems });
|
||||
}
|
||||
if (providerItems.length > 0) {
|
||||
groups.push({ id: "provider", label: "Provider", items: providerItems });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
items: ComposerCommandItem[];
|
||||
resolvedTheme: "light" | "dark";
|
||||
isLoading: boolean;
|
||||
triggerKind: ComposerTriggerKind | null;
|
||||
groupSlashCommandSections?: boolean;
|
||||
emptyStateText?: string;
|
||||
activeItemId: string | null;
|
||||
onHighlightedItemChange: (itemId: string | null) => void;
|
||||
onSelect: (item: ComposerCommandItem) => void;
|
||||
}) {
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
const groups = useMemo(
|
||||
() =>
|
||||
groupCommandItems(props.items, props.triggerKind, props.groupSlashCommandSections ?? true),
|
||||
[props.groupSlashCommandSections, props.items, props.triggerKind],
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!props.activeItemId || !listRef.current) return;
|
||||
@@ -141,57 +77,38 @@ export const ComposerCommandMenu = memo(function ComposerCommandMenu(props: {
|
||||
>
|
||||
<div
|
||||
ref={listRef}
|
||||
className="dropdown-glass relative w-full overflow-hidden rounded-[20px] shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] **:data-[slot=scroll-area-scrollbar]:data-[orientation=vertical]:my-4 dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]"
|
||||
className="chat-composer-drawer-surface chat-composer-drawer-attached relative w-full overflow-hidden **:data-[slot=scroll-area-scrollbar]:data-[orientation=vertical]:my-4"
|
||||
data-composer-command-drawer="true"
|
||||
>
|
||||
{props.items.length > 0 ? (
|
||||
<CommandList className="max-h-72 not-empty:py-3">
|
||||
{groups.map((group, groupIndex) => (
|
||||
<div key={group.id}>
|
||||
{groupIndex > 0 ? <CommandSeparator className="my-0.5" /> : null}
|
||||
<CommandGroup>
|
||||
{group.label ? (
|
||||
<CommandGroupLabel className="px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-secondary-label">
|
||||
{group.label}
|
||||
</CommandGroupLabel>
|
||||
) : null}
|
||||
{group.items.map((item) => (
|
||||
<ComposerCommandMenuItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
isActive={props.activeItemId === item.id}
|
||||
onHighlight={props.onHighlightedItemChange}
|
||||
onSelect={props.onSelect}
|
||||
/>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</div>
|
||||
))}
|
||||
<CommandList className="max-h-72 scroll-pb-6">
|
||||
<CommandGroup>
|
||||
{props.items.map((item) => (
|
||||
<ComposerCommandMenuItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
isActive={props.activeItemId === item.id}
|
||||
onHighlight={props.onHighlightedItemChange}
|
||||
onSelect={props.onSelect}
|
||||
/>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
) : (
|
||||
<div className="px-5 py-3.5">
|
||||
{props.triggerKind === "skill" ? (
|
||||
<CommandGroup>
|
||||
<CommandGroupLabel className="px-0 pt-0 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-secondary-label">
|
||||
Skills
|
||||
</CommandGroupLabel>
|
||||
<p className="text-secondary-label text-xs">
|
||||
{props.isLoading
|
||||
? "Searching workspace skills..."
|
||||
: (props.emptyStateText ??
|
||||
"No skills found. Try / to browse provider commands.")}
|
||||
</p>
|
||||
</CommandGroup>
|
||||
) : (
|
||||
<p className="text-secondary-label text-xs">
|
||||
{props.isLoading
|
||||
? "Searching workspace files..."
|
||||
: (props.emptyStateText ??
|
||||
(props.triggerKind === "path"
|
||||
<div className="px-5 pt-3.5 pb-7">
|
||||
<p className="text-secondary-label text-xs">
|
||||
{props.isLoading
|
||||
? props.triggerKind === "skill"
|
||||
? "Searching workspace skills..."
|
||||
: "Searching workspace files..."
|
||||
: (props.emptyStateText ??
|
||||
(props.triggerKind === "skill"
|
||||
? "No skills found. Try / to browse provider commands."
|
||||
: props.triggerKind === "path"
|
||||
? "No matching files or folders."
|
||||
: "No matching command."))}
|
||||
</p>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -214,7 +131,7 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
value={props.item.id}
|
||||
data-composer-item-id={props.item.id}
|
||||
className={cn(
|
||||
"cursor-pointer select-none gap-2 hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
|
||||
"cursor-pointer select-none gap-3 rounded-lg px-3 py-2! hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
|
||||
props.isActive && "bg-accent! text-accent-foreground!",
|
||||
)}
|
||||
onMouseMove={() => {
|
||||
@@ -234,22 +151,9 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
|
||||
theme={props.resolvedTheme}
|
||||
/>
|
||||
) : null}
|
||||
{props.item.type === "slash-command" ? (
|
||||
<BotIcon className="size-4 shrink-0 text-icon-muted" />
|
||||
) : null}
|
||||
{props.item.type === "provider-slash-command" ? (
|
||||
<span className="inline-flex size-4 shrink-0 items-center justify-center text-icon-muted">
|
||||
<SkillGlyph className="size-3.5" />
|
||||
</span>
|
||||
) : null}
|
||||
{props.item.type === "skill" ? (
|
||||
<span className="inline-flex size-4 shrink-0 items-center justify-center text-icon-muted">
|
||||
<SkillGlyph className="size-3.5" />
|
||||
</span>
|
||||
) : null}
|
||||
<span className="flex min-w-0 flex-1 items-center gap-2">
|
||||
<span className="shrink-0">{props.item.label}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-label text-xs">
|
||||
<span className="flex min-w-0 flex-1 items-baseline gap-3">
|
||||
<span className="shrink-0 font-sans text-xs font-medium">{props.item.label}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-right text-secondary-label text-xs">
|
||||
{props.item.description}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApprovalRequestId } from "@t3tools/contracts";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions";
|
||||
|
||||
describe("ComposerPendingApprovalActions", () => {
|
||||
it("states that the persistent approval lasts for this session", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerPendingApprovalActions
|
||||
requestId={ApprovalRequestId.make("approval-1")}
|
||||
isResponding={false}
|
||||
onRespondToApproval={async () => undefined}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain(">Cancel<");
|
||||
expect(markup).toContain("Always allow this session");
|
||||
expect(markup).not.toContain(">Always allow<");
|
||||
expect(markup).toContain("h-5");
|
||||
expect(markup).toContain("sm:text-[11px]");
|
||||
expect(markup).not.toContain("sm:h-6");
|
||||
});
|
||||
});
|
||||
@@ -19,36 +19,40 @@ export const ComposerPendingApprovalActions = memo(function ComposerPendingAppro
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
size="micro"
|
||||
variant="ghost-muted"
|
||||
className="font-normal"
|
||||
disabled={isResponding}
|
||||
onClick={() => void onRespondToApproval(requestId, "cancel")}
|
||||
>
|
||||
Cancel turn
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive-outline"
|
||||
size="micro"
|
||||
variant="ghost-muted"
|
||||
className="font-normal text-destructive-foreground [:hover,[data-pressed]]:text-destructive-foreground"
|
||||
disabled={isResponding}
|
||||
onClick={() => void onRespondToApproval(requestId, "decline")}
|
||||
>
|
||||
Decline
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
size="micro"
|
||||
variant="ghost-muted"
|
||||
className="font-normal"
|
||||
disabled={isResponding}
|
||||
onClick={() => void onRespondToApproval(requestId, "acceptForSession")}
|
||||
>
|
||||
Always allow this session
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
size="micro"
|
||||
variant="ghost-muted"
|
||||
className="font-normal text-foreground"
|
||||
disabled={isResponding}
|
||||
onClick={() => void onRespondToApproval(requestId, "accept")}
|
||||
>
|
||||
Approve once
|
||||
Approve
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
|
||||
|
||||
describe("ComposerPendingApprovalPanel", () => {
|
||||
it("renders complete multiline command details without hover or truncation", () => {
|
||||
it("keeps the complete command readable in the compact row", () => {
|
||||
const detail = `bun run release -- ${"x".repeat(500)}\nsecond line`;
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerPendingApprovalPanel
|
||||
@@ -22,10 +22,12 @@ describe("ComposerPendingApprovalPanel", () => {
|
||||
expect(markup).toContain('data-approval-detail="complete"');
|
||||
expect(markup).toContain('aria-label="Command"');
|
||||
expect(markup).toContain(detail);
|
||||
expect(markup).toContain("max-h-20");
|
||||
expect(markup).toContain("overflow-auto");
|
||||
expect(markup).toContain("whitespace-pre");
|
||||
expect(markup).not.toContain("truncate");
|
||||
expect(markup).not.toContain("line-clamp");
|
||||
expect(markup).toContain("min-w-0");
|
||||
expect(markup).toContain("max-w-full");
|
||||
expect(markup).toContain("[overflow-wrap:anywhere]");
|
||||
expect(markup).not.toContain("Command approval requested");
|
||||
});
|
||||
});
|
||||
@@ -1,22 +1,25 @@
|
||||
import { memo } from "react";
|
||||
import { type PendingApproval } from "../../session-logic";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
interface ComposerPendingApprovalPanelProps {
|
||||
approval: PendingApproval;
|
||||
pendingCount: number;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprovalPanel({
|
||||
approval,
|
||||
pendingCount,
|
||||
className,
|
||||
}: ComposerPendingApprovalPanelProps) {
|
||||
const approvalSummary =
|
||||
const fallbackLabel =
|
||||
approval.requestKind === "command"
|
||||
? "Command approval requested"
|
||||
? "Command approval"
|
||||
: approval.requestKind === "file-read"
|
||||
? "File-read approval requested"
|
||||
: "File-change approval requested";
|
||||
const detailLabel =
|
||||
? "File read approval"
|
||||
: "File change approval";
|
||||
const detailAriaLabel =
|
||||
approval.requestKind === "command"
|
||||
? "Command"
|
||||
: approval.requestKind === "file-read"
|
||||
@@ -24,25 +27,18 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
|
||||
: "File change";
|
||||
|
||||
return (
|
||||
<div className="min-w-0 px-4 py-3.5 sm:px-5 sm:py-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="uppercase text-sm tracking-[0.2em]">PENDING APPROVAL</span>
|
||||
<span className="text-sm font-medium">{approvalSummary}</span>
|
||||
{pendingCount > 1 ? (
|
||||
<span className="text-xs text-muted-foreground">1/{pendingCount}</span>
|
||||
) : null}
|
||||
</div>
|
||||
{approval.detail ? (
|
||||
<div className="mt-3 min-w-0 max-w-full rounded-lg border border-border/65 bg-background/70 p-3">
|
||||
<p className="text-xs font-medium text-muted-foreground">{detailLabel}</p>
|
||||
<pre
|
||||
aria-label={detailLabel}
|
||||
className="mt-2 min-w-0 max-w-full max-h-40 overflow-auto whitespace-pre-wrap [overflow-wrap:anywhere] font-mono text-xs leading-relaxed text-foreground"
|
||||
data-approval-detail="complete"
|
||||
>
|
||||
{approval.detail}
|
||||
</pre>
|
||||
</div>
|
||||
<div className={cn("flex min-w-0 flex-1 items-center gap-2", className)}>
|
||||
<code
|
||||
aria-label={detailAriaLabel}
|
||||
className="block max-h-20 min-w-0 flex-1 overflow-auto whitespace-pre font-mono text-[11px] text-foreground/85"
|
||||
data-approval-detail="complete"
|
||||
>
|
||||
{approval.detail ?? fallbackLabel}
|
||||
</code>
|
||||
{pendingCount > 1 ? (
|
||||
<span className="shrink-0 text-[10px] font-medium text-muted-foreground tabular-nums">
|
||||
1/{pendingCount}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ApprovalRequestId } from "@t3tools/contracts";
|
||||
import type { ReactNode } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
@@ -22,7 +23,7 @@ const prompt: PendingUserInput = {
|
||||
],
|
||||
};
|
||||
|
||||
function renderPanel() {
|
||||
function renderPanel(trailing?: ReactNode) {
|
||||
return renderToStaticMarkup(
|
||||
<ComposerPendingUserInputPanel
|
||||
pendingUserInputs={[prompt]}
|
||||
@@ -31,6 +32,7 @@ function renderPanel() {
|
||||
questionIndex={0}
|
||||
onToggleOption={() => {}}
|
||||
onAdvance={() => {}}
|
||||
trailing={trailing}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
@@ -58,4 +60,11 @@ describe("ComposerPendingUserInputPanel", () => {
|
||||
expect(markup).toContain("Incremental");
|
||||
expect(markup).toContain("Big bang");
|
||||
});
|
||||
|
||||
it("keeps a separate trailing action beside the disclosure control", () => {
|
||||
const markup = renderPanel(<button data-stash-action="true">Stash</button>);
|
||||
|
||||
expect(markup).toContain('data-stash-action="true"');
|
||||
expect(markup).toMatch(/<\/button><button data-stash-action="true">/);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type ApprovalRequestId } from "@t3tools/contracts";
|
||||
import { memo, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { memo, useCallback, useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { type PendingUserInput } from "../../session-logic";
|
||||
import {
|
||||
derivePendingUserInputProgress,
|
||||
@@ -14,6 +14,7 @@ interface PendingUserInputPanelProps {
|
||||
respondingRequestIds: ApprovalRequestId[];
|
||||
answers: Record<string, PendingUserInputDraftAnswer>;
|
||||
questionIndex: number;
|
||||
trailing?: ReactNode;
|
||||
onToggleOption: (questionId: string, optionLabel: string) => void;
|
||||
onAdvance: () => void;
|
||||
}
|
||||
@@ -23,6 +24,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
|
||||
respondingRequestIds,
|
||||
answers,
|
||||
questionIndex,
|
||||
trailing,
|
||||
onToggleOption,
|
||||
onAdvance,
|
||||
}: PendingUserInputPanelProps) {
|
||||
@@ -37,6 +39,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
|
||||
isResponding={respondingRequestIds.includes(activePrompt.requestId)}
|
||||
answers={answers}
|
||||
questionIndex={questionIndex}
|
||||
trailing={trailing}
|
||||
onToggleOption={onToggleOption}
|
||||
onAdvance={onAdvance}
|
||||
/>
|
||||
@@ -48,6 +51,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
isResponding,
|
||||
answers,
|
||||
questionIndex,
|
||||
trailing,
|
||||
onToggleOption,
|
||||
onAdvance,
|
||||
}: {
|
||||
@@ -55,6 +59,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
isResponding: boolean;
|
||||
answers: Record<string, PendingUserInputDraftAnswer>;
|
||||
questionIndex: number;
|
||||
trailing?: ReactNode;
|
||||
onToggleOption: (questionId: string, optionLabel: string) => void;
|
||||
onAdvance: () => void;
|
||||
}) {
|
||||
@@ -167,7 +172,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
|
||||
return (
|
||||
<Collapsible
|
||||
className="py-3"
|
||||
className="py-2"
|
||||
open={!isCollapsed}
|
||||
onOpenChange={(open) => {
|
||||
setCollapsedQuestionId(open ? null : activeQuestion.id);
|
||||
@@ -179,19 +184,19 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
header label and the chevron still line up with the left and right
|
||||
edges of the question text below. The negative block margin keeps the
|
||||
taller hit area from pushing the panel down. */}
|
||||
<div className="px-1.5 sm:px-2.5">
|
||||
<div className="flex items-center gap-1 px-1 sm:px-2">
|
||||
<CollapsibleTrigger
|
||||
title={
|
||||
isCollapsed ? "Show the question and its options" : "Hide the question and its options"
|
||||
}
|
||||
data-pending-user-input-toggle={isCollapsed ? "collapsed" : "expanded"}
|
||||
className="group -my-1 flex w-full items-center gap-3 rounded-md px-2.5 py-1.5 text-left outline-none transition-colors duration-150 hover:bg-muted/40 focus-visible:ring-1 focus-visible:ring-primary/25"
|
||||
className="group -my-1 flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-left outline-none transition-colors duration-150 hover:bg-muted/35 focus-visible:ring-1 focus-visible:ring-primary/25"
|
||||
>
|
||||
<span className="text-secondary-label text-[11px] font-semibold tracking-widest uppercase group-hover:text-foreground">
|
||||
<span className="text-xs font-medium text-muted-foreground group-hover:text-foreground/85">
|
||||
{activeQuestion.header}
|
||||
</span>
|
||||
{prompt.questions.length > 1 ? (
|
||||
<span className="flex h-5 items-center rounded-md bg-muted/60 px-1.5 text-secondary-label text-[10px] font-medium tabular-nums">
|
||||
<span className="text-[10px] font-medium text-muted-foreground tabular-nums">
|
||||
{questionIndex + 1}/{prompt.questions.length}
|
||||
</span>
|
||||
) : null}
|
||||
@@ -213,17 +218,18 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
)}
|
||||
/>
|
||||
</CollapsibleTrigger>
|
||||
{trailing}
|
||||
</div>
|
||||
{/* The panel carries the horizontal padding itself: it clips its content
|
||||
while the height animates, so the option buttons have to sit inside
|
||||
that padding or their focus rings get shaved off at the edges. */}
|
||||
<CollapsiblePanel className="px-4 sm:px-5">
|
||||
<CollapsiblePanel className="px-3 sm:px-4">
|
||||
<div className="pt-2 pb-0.5">
|
||||
<p className="text-sm text-foreground/90">{activeQuestion.question}</p>
|
||||
<p className="text-sm text-foreground/85">{activeQuestion.question}</p>
|
||||
{activeQuestion.multiSelect ? (
|
||||
<p className="mt-1 text-secondary-label text-xs">Select one or more options.</p>
|
||||
) : null}
|
||||
<div className="mt-3 space-y-1.5">
|
||||
<div className="mt-2 space-y-0.5">
|
||||
{activeQuestion.options.map((option, index) => {
|
||||
const isOptimisticallySelected =
|
||||
optimisticSingleSelect?.questionId === activeQuestion.id &&
|
||||
@@ -233,10 +239,10 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
(!customAnswerActive && progress.selectedOptionLabels.includes(option.label));
|
||||
const shortcutKey = index < 9 ? index + 1 : null;
|
||||
const className = cn(
|
||||
"group flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left outline-none transition-all duration-150 focus-visible:border-primary/40 focus-visible:ring-1 focus-visible:ring-primary/25",
|
||||
"group flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-primary/25",
|
||||
isSelected
|
||||
? "border-primary/30 bg-primary/8 text-foreground"
|
||||
: "border-transparent bg-muted/22 text-foreground/85 hover:border-border/45 hover:bg-muted/34",
|
||||
? "bg-muted/55 text-foreground"
|
||||
: "bg-transparent text-foreground/85 hover:bg-muted/30",
|
||||
isResponding && "opacity-50 cursor-not-allowed",
|
||||
!isResponding && "cursor-pointer",
|
||||
);
|
||||
@@ -245,7 +251,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
<div className="min-w-0 flex-1 flex flex-col gap-0.5">
|
||||
<span className="text-sm font-medium">{option.label}</span>
|
||||
{option.description && option.description !== option.label ? (
|
||||
<span className="text-secondary-label text-xs">{option.description}</span>
|
||||
<span className="text-secondary-label text-[11px]">{option.description}</span>
|
||||
) : null}
|
||||
</div>
|
||||
{isSelected ? (
|
||||
@@ -253,8 +259,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
|
||||
) : shortcutKey !== null ? (
|
||||
<kbd
|
||||
className={cn(
|
||||
"flex size-5 shrink-0 items-center justify-center rounded border border-border/50 text-[11px] font-medium tabular-nums transition-colors duration-150",
|
||||
"bg-background/35 text-secondary-label group-hover:border-border/70 group-hover:text-foreground",
|
||||
"flex size-5 shrink-0 items-center justify-center text-[10px] font-medium text-muted-foreground tabular-nums",
|
||||
)}
|
||||
>
|
||||
{shortcutKey}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
import { memo } from "react";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { memo, type ReactNode } from "react";
|
||||
|
||||
export const ComposerPlanFollowUpBanner = memo(function ComposerPlanFollowUpBanner({
|
||||
planTitle,
|
||||
trailing,
|
||||
}: {
|
||||
planTitle: string | null;
|
||||
trailing?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="px-4 py-3.5 sm:px-5 sm:py-4">
|
||||
<div className="px-3 py-2 sm:px-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge
|
||||
variant="info"
|
||||
size="sm"
|
||||
className="rounded-md px-1.5 py-0 font-semibold tracking-wide uppercase"
|
||||
>
|
||||
Plan Ready
|
||||
</Badge>
|
||||
<span className="text-sm font-medium text-foreground/90">Plan ready</span>
|
||||
{planTitle ? (
|
||||
<span className="min-w-0 flex-1 truncate text-sm font-medium">{planTitle}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-xs text-foreground/85">{planTitle}</span>
|
||||
) : null}
|
||||
{trailing}
|
||||
</div>
|
||||
{/* <div className="mt-2 text-xs text-muted-foreground">
|
||||
Review the plan
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { ComposerStashBadge } from "./ComposerStashBadge";
|
||||
|
||||
describe("ComposerStashBadge", () => {
|
||||
it("renders as an attached composer tab instead of a floating pill", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerStashBadge
|
||||
count={3}
|
||||
menuOpen={false}
|
||||
pulseKey={0}
|
||||
pulsing={false}
|
||||
onToggleMenu={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("chat-composer-stash-tab");
|
||||
expect(markup).toContain("rounded-t-xl");
|
||||
expect(markup).toContain("border-b-0");
|
||||
expect(markup).toContain("items-center");
|
||||
expect(markup).not.toContain("items-start");
|
||||
expect(markup).not.toContain("rounded-full");
|
||||
expect(markup).not.toContain("opacity-70");
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
});
|
||||
|
||||
it("reports when the stash drawer is open", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerStashBadge
|
||||
count={3}
|
||||
menuOpen
|
||||
pulseKey={0}
|
||||
pulsing={false}
|
||||
onToggleMenu={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('aria-expanded="true"');
|
||||
});
|
||||
|
||||
it("can sit inside the plan drawer without using the overlapping tab", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerStashBadge
|
||||
embedded
|
||||
count={3}
|
||||
menuOpen={false}
|
||||
pulseKey={0}
|
||||
pulsing={false}
|
||||
onToggleMenu={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("h-6");
|
||||
expect(markup).not.toContain("chat-composer-stash-tab");
|
||||
expect(markup).not.toContain("absolute");
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { memo } from "react";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
/**
|
||||
* Bookmark pill perched on the composer's top-right shoulder. Shows the
|
||||
* Bookmark tab tucked behind the composer's top-right shoulder. Shows the
|
||||
* stash count and doubles as the click target for opening the stash menu.
|
||||
*
|
||||
* On save the badge gives one quiet acknowledgement: it lifts to full
|
||||
@@ -12,10 +12,11 @@ import { cn } from "~/lib/utils";
|
||||
* the count so the transition replays without a continuous animation.
|
||||
*/
|
||||
export const ComposerStashBadge = memo(function ComposerStashBadge(props: {
|
||||
embedded?: boolean;
|
||||
count: number;
|
||||
menuOpen: boolean;
|
||||
pulseKey: number;
|
||||
pulsing: boolean;
|
||||
menuOpen: boolean;
|
||||
onToggleMenu: () => void;
|
||||
}) {
|
||||
if (props.count === 0) return null;
|
||||
@@ -27,11 +28,14 @@ export const ComposerStashBadge = memo(function ComposerStashBadge(props: {
|
||||
aria-label={`Stashed prompts: ${props.count}. Open stash.`}
|
||||
aria-expanded={props.menuOpen}
|
||||
className={cn(
|
||||
"absolute -top-3 right-4 z-10 inline-flex cursor-pointer items-center gap-1.5 rounded-full border bg-popover px-2.5 py-0.5 text-xs shadow-sm",
|
||||
"transition-[color,border-color,opacity] duration-200",
|
||||
props.menuOpen || props.pulsing
|
||||
? "border-border text-foreground opacity-100"
|
||||
: "border-border/70 text-muted-foreground opacity-70 hover:opacity-100 hover:text-foreground",
|
||||
"inline-flex cursor-pointer items-center gap-1.5 border leading-none",
|
||||
props.embedded
|
||||
? "ms-auto h-6 shrink-0 rounded-md border-border/70 px-2 text-[11px]"
|
||||
: "chat-composer-stash-tab absolute -top-7 right-4 z-0 h-8 rounded-t-xl border-b-0 px-3 pb-1 text-xs",
|
||||
"transition-[color,border-color] duration-200",
|
||||
props.pulsing
|
||||
? "border-border text-foreground"
|
||||
: "border-border/70 text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
onPointerDown={(event) => {
|
||||
// Keep composer focus so Escape/typing flows stay intact.
|
||||
@@ -39,15 +43,15 @@ export const ComposerStashBadge = memo(function ComposerStashBadge(props: {
|
||||
}}
|
||||
onClick={props.onToggleMenu}
|
||||
>
|
||||
<BookmarkIcon className="size-3" aria-hidden="true" />
|
||||
<BookmarkIcon className="size-3 shrink-0" aria-hidden="true" />
|
||||
Stash
|
||||
<span
|
||||
key={props.pulseKey}
|
||||
className={cn(
|
||||
"rounded-full px-1.5 text-[10px] font-medium tabular-nums",
|
||||
"text-[10px] font-medium leading-none tabular-nums",
|
||||
props.pulsing
|
||||
? "animate-[prompt-stash-count-enter_180ms_ease-out_both] bg-primary text-primary-foreground motion-reduce:animate-none"
|
||||
: "bg-muted text-muted-foreground",
|
||||
? "animate-[prompt-stash-count-enter_180ms_ease-out_both] text-primary motion-reduce:animate-none"
|
||||
: "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{props.count}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { ComposerStashMenu } from "./ComposerStashMenu";
|
||||
|
||||
describe("ComposerStashMenu", () => {
|
||||
it("renders saved prompts as an attached composer drawer", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerStashMenu
|
||||
entries={[]}
|
||||
onRestore={() => {}}
|
||||
onDelete={() => {}}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-composer-stash-drawer="true"');
|
||||
expect(markup).toContain("chat-composer-drawer-surface");
|
||||
expect(markup).toContain("chat-composer-drawer-attached");
|
||||
expect(markup).not.toContain("dropdown-glass");
|
||||
expect(markup).not.toContain("Stashed prompts");
|
||||
});
|
||||
|
||||
it("shows saved image thumbnails and incomplete image states", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ComposerStashMenu
|
||||
entries={[
|
||||
{
|
||||
id: "with-images",
|
||||
createdAt: new Date(0).toISOString(),
|
||||
prompt: "Compare these screenshots",
|
||||
attachments: [
|
||||
{
|
||||
id: "image-one",
|
||||
name: "before.png",
|
||||
mimeType: "image/png",
|
||||
sizeBytes: 128,
|
||||
dataUrl: "data:image/png;base64,AA==",
|
||||
},
|
||||
],
|
||||
droppedImageNames: ["after.png"],
|
||||
unreadableImageNames: [],
|
||||
pendingImageCount: 0,
|
||||
},
|
||||
{
|
||||
id: "saving-images",
|
||||
createdAt: new Date(0).toISOString(),
|
||||
prompt: "Save this image",
|
||||
attachments: [],
|
||||
droppedImageNames: [],
|
||||
unreadableImageNames: [],
|
||||
pendingImageCount: 1,
|
||||
},
|
||||
]}
|
||||
onRestore={() => {}}
|
||||
onDelete={() => {}}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('src="data:image/png;base64,AA=="');
|
||||
expect(markup).toContain("1 image dropped");
|
||||
expect(markup).toContain("saving 1 image");
|
||||
expect(markup).toContain("absolute top-1/2 right-2");
|
||||
expect(markup).toContain("pointer-events-none");
|
||||
expect(markup).toContain("max-sm:pointer-events-auto");
|
||||
expect(markup).toContain("max-sm:static");
|
||||
expect(markup).toContain("max-sm:opacity-100");
|
||||
expect(markup).toContain("bg-popover!");
|
||||
expect(markup).toContain("[--control-icon-color:var(--foreground)]");
|
||||
expect(markup).toContain("size-3.5 stroke-2");
|
||||
expect(markup).not.toContain("bg-background/90");
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { BookmarkIcon, XIcon } from "lucide-react";
|
||||
import { XIcon } from "lucide-react";
|
||||
import { memo, useEffect, useState } from "react";
|
||||
|
||||
import { formatRelativeTimeLabel } from "../../timestampFormat";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { type PromptStashEntry } from "../../promptStashStore";
|
||||
import { Command, CommandGroup, CommandGroupLabel, CommandItem, CommandList } from "../ui/command";
|
||||
import { Command, CommandGroup, CommandItem, CommandList } from "../ui/command";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
const SNIPPET_MAX_CHARS = 90;
|
||||
@@ -91,15 +91,14 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
|
||||
|
||||
return (
|
||||
<Command autoHighlight={false} mode="none">
|
||||
<div className="dropdown-glass relative w-full overflow-hidden rounded-[20px] shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]">
|
||||
<CommandList className="max-h-72">
|
||||
<div
|
||||
className="chat-composer-drawer-surface chat-composer-drawer-attached relative w-full overflow-hidden"
|
||||
data-composer-stash-drawer="true"
|
||||
>
|
||||
<CommandList className="max-h-72 scroll-pb-6">
|
||||
<CommandGroup>
|
||||
<CommandGroupLabel className="flex items-center gap-1.5 px-3 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-secondary-label">
|
||||
<BookmarkIcon className="size-3" aria-hidden="true" />
|
||||
Stashed prompts
|
||||
</CommandGroupLabel>
|
||||
{entries.length === 0 ? (
|
||||
<p className="px-3 pb-3 pt-1 text-secondary-label text-xs">
|
||||
<p className="px-3 py-1.5 text-secondary-label text-xs">
|
||||
Nothing stashed yet. Press ⌘S with a prompt in the composer to stash it.
|
||||
</p>
|
||||
) : (
|
||||
@@ -108,7 +107,7 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
|
||||
key={entry.id}
|
||||
value={entry.id}
|
||||
className={cn(
|
||||
"group/stash cursor-pointer select-none gap-2 hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
|
||||
"group/stash relative cursor-pointer select-none gap-3 rounded-lg px-3 py-1.5! hover:bg-transparent hover:text-inherit data-highlighted:bg-transparent data-highlighted:text-inherit",
|
||||
highlightedId === entry.id && "bg-accent! text-accent-foreground!",
|
||||
)}
|
||||
onMouseMove={() => {
|
||||
@@ -121,22 +120,7 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
|
||||
onRestore(entry);
|
||||
}}
|
||||
>
|
||||
{entry.attachments.length > 0 ? (
|
||||
<span className="flex shrink-0 items-center -space-x-1.5">
|
||||
{entry.attachments.slice(0, 3).map((attachment) => (
|
||||
<img
|
||||
key={attachment.id}
|
||||
src={attachment.dataUrl}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
className="size-5 rounded border border-border/70 object-cover"
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
) : (
|
||||
<BookmarkIcon className="size-4 shrink-0 text-icon-muted" />
|
||||
)}
|
||||
<span className="min-w-0 flex-1 truncate text-sm">
|
||||
<span className="min-w-0 flex-1 truncate text-xs">
|
||||
{stashEntrySnippet(entry)}
|
||||
</span>
|
||||
{entry.pendingImageCount ? (
|
||||
@@ -150,20 +134,33 @@ export const ComposerStashMenu = memo(function ComposerStashMenu(props: {
|
||||
{missingImageCount(entry) === 1 ? "" : "s"} dropped
|
||||
</span>
|
||||
) : null}
|
||||
<span className="shrink-0 text-secondary-label text-xs">
|
||||
{entry.attachments.length > 0 ? (
|
||||
<span className="flex shrink-0 items-center -space-x-1.5">
|
||||
{entry.attachments.slice(0, 3).map((attachment) => (
|
||||
<img
|
||||
key={attachment.id}
|
||||
src={attachment.dataUrl}
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
className="size-5 rounded border border-border/70 object-cover"
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="shrink-0 text-secondary-label text-xs max-sm:hidden">
|
||||
{formatRelativeTimeLabel(entry.createdAt)}
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="shrink-0 opacity-0 transition-opacity group-hover/stash:opacity-100"
|
||||
className="pointer-events-none absolute top-1/2 right-2 z-10 -translate-y-1/2 [--control-icon-color:var(--foreground)] bg-popover! opacity-0 shadow-none! transition-opacity max-sm:pointer-events-auto max-sm:static max-sm:translate-y-0 max-sm:opacity-100 hover:bg-popover! group-hover/stash:pointer-events-auto group-hover/stash:opacity-100 group-focus-within/stash:pointer-events-auto group-focus-within/stash:opacity-100 focus-visible:pointer-events-auto focus-visible:bg-popover! focus-visible:opacity-100"
|
||||
aria-label="Delete stashed prompt"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onDelete(entry);
|
||||
}}
|
||||
>
|
||||
<XIcon />
|
||||
<XIcon className="size-3.5 stroke-2" />
|
||||
</Button>
|
||||
</CommandItem>
|
||||
))
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
deriveMessagesTimelineRows,
|
||||
normalizeCompactToolLabel,
|
||||
resolveAssistantMessageCopyState,
|
||||
summarizeToolGroup,
|
||||
shouldPreserveAssistantLineBreaks,
|
||||
} from "./MessagesTimeline.logic";
|
||||
|
||||
@@ -218,6 +219,50 @@ describe("normalizeCompactToolLabel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeToolGroup", () => {
|
||||
it("distinguishes local grep from web search", () => {
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "grep",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "grep",
|
||||
toolTitle: "grep",
|
||||
tone: "tool",
|
||||
itemType: "web_search",
|
||||
},
|
||||
]),
|
||||
).toBe("Searched code 1 time");
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "web-search",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "Web search",
|
||||
toolTitle: "Web search",
|
||||
tone: "tool",
|
||||
itemType: "web_search",
|
||||
},
|
||||
]),
|
||||
).toBe("Searched the web 1 time");
|
||||
});
|
||||
|
||||
it("recognizes provider-neutral read tool calls", () => {
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "read-file",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "Read File",
|
||||
toolTitle: "Read File",
|
||||
tone: "tool",
|
||||
itemType: "dynamic_tool_call",
|
||||
},
|
||||
]),
|
||||
).toBe("Read 1 file");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAssistantMessageCopyState", () => {
|
||||
it("returns enabled copy state for completed assistant messages", () => {
|
||||
expect(
|
||||
@@ -545,7 +590,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
"user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-thought-entry",
|
||||
"work-entry-1",
|
||||
"work-toggle:work-entry-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
expect(
|
||||
@@ -650,6 +695,99 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(foldRow?.label).toBe("Worked for 12s");
|
||||
});
|
||||
|
||||
it("keeps a collapsed superseded turn fold by the response and expands it downward", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "initial-user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
message: {
|
||||
id: "initial-user" as never,
|
||||
role: "user",
|
||||
text: "Start the work",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
updatedAt: "2026-01-01T00:00:00Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "superseded-work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:10Z",
|
||||
entry: {
|
||||
id: "superseded-work",
|
||||
createdAt: "2026-01-01T00:00:10Z",
|
||||
turnId: "turn-1" as never,
|
||||
label: "Ran command",
|
||||
tone: "tool",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "steer-user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:12Z",
|
||||
message: {
|
||||
id: "steer-user" as never,
|
||||
role: "user",
|
||||
text: "Change the approach",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:12Z",
|
||||
updatedAt: "2026-01-01T00:00:12Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-final-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:20Z",
|
||||
message: {
|
||||
id: "assistant-final" as never,
|
||||
role: "assistant",
|
||||
text: "Implemented locally, uncommitted.",
|
||||
turnId: "turn-2" as never,
|
||||
createdAt: "2026-01-01T00:00:20Z",
|
||||
updatedAt: "2026-01-01T00:00:21Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
] satisfies Parameters<typeof deriveMessagesTimelineRows>[0]["timelineEntries"];
|
||||
const input = {
|
||||
timelineEntries,
|
||||
latestTurn: {
|
||||
turnId: "turn-2" as never,
|
||||
state: "completed" as const,
|
||||
startedAt: "2026-01-01T00:00:12Z",
|
||||
completedAt: "2026-01-01T00:00:21Z",
|
||||
},
|
||||
isWorking: false,
|
||||
activeTurnStartedAt: null,
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
};
|
||||
const rows = deriveMessagesTimelineRows(input);
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"initial-user-entry",
|
||||
"steer-user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
|
||||
const expandedRows = deriveMessagesTimelineRows({
|
||||
...input,
|
||||
expandedTurnIds: new Set(["turn-1" as never]),
|
||||
});
|
||||
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"initial-user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"work-toggle:superseded-work-entry",
|
||||
"steer-user-entry",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses latest-turn timings and the stopped label for an interrupted latest turn", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -756,6 +894,72 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(finalRow?.kind === "message" && finalRow.showAssistantMeta).toBe(true);
|
||||
});
|
||||
|
||||
it("places an unkeyed active plan below the working header", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
message: {
|
||||
id: "user" as never,
|
||||
role: "user",
|
||||
text: "Make a plan",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
updatedAt: "2026-01-01T00:00:00Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "plan-entry",
|
||||
kind: "proposed-plan",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
proposedPlan: {
|
||||
id: "plan" as never,
|
||||
turnId: null,
|
||||
planMarkdown: "# Plan",
|
||||
implementedAt: null,
|
||||
implementationThreadId: null,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
updatedAt: "2026-01-01T00:00:01Z",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
message: {
|
||||
id: "assistant" as never,
|
||||
role: "assistant",
|
||||
text: "Planning now.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
updatedAt: "2026-01-01T00:00:02Z",
|
||||
streaming: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"user-entry",
|
||||
"working-indicator-row",
|
||||
"plan-entry",
|
||||
"assistant-entry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not fold the active in-progress turn", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -783,6 +987,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
turnId: "turn-1" as never,
|
||||
label: "Ran command",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -800,12 +1005,299 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
|
||||
expect(rows.some((row) => row.kind === "turn-fold")).toBe(false);
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"assistant-thought-entry",
|
||||
"work-entry-1",
|
||||
"working-indicator-row",
|
||||
"assistant-thought-entry",
|
||||
"work-live:work-entry-1",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps the current tool batch expandable while live entries append", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "work-entry-1",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-1",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-1",
|
||||
label: "Read file",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "work-entry-2",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
entry: {
|
||||
id: "work-2",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-2",
|
||||
label: "Run command",
|
||||
command: "vp test run",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
];
|
||||
const baseInput = {
|
||||
timelineEntries,
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running" as const,
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
};
|
||||
|
||||
const collapsedRows = deriveMessagesTimelineRows(baseInput);
|
||||
const expandedRows = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
expandedWorkGroupIds: new Set(["work-group:tool:call-1"]),
|
||||
});
|
||||
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
]);
|
||||
expect(collapsedRows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
groupId: "work-group:tool:call-1",
|
||||
expanded: false,
|
||||
groupedEntries: [{ id: "work-1" }, { id: "work-2" }],
|
||||
});
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
]);
|
||||
expect(expandedRows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
groupId: "work-group:tool:call-1",
|
||||
expanded: true,
|
||||
});
|
||||
|
||||
const appendedRows = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
timelineEntries: [
|
||||
...timelineEntries,
|
||||
{
|
||||
id: "work-entry-3",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
entry: {
|
||||
id: "work-3",
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-3",
|
||||
label: "Changed file",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
expandedWorkGroupIds: new Set(["work-group:tool:call-1"]),
|
||||
});
|
||||
|
||||
expect(appendedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
"work-3",
|
||||
]);
|
||||
|
||||
const rowsWithLaterPlan = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
timelineEntries: [
|
||||
...timelineEntries,
|
||||
{
|
||||
id: "plan:thread-1:turn:turn-1",
|
||||
kind: "proposed-plan" as const,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
proposedPlan: {
|
||||
id: "plan:thread-1:turn:turn-1",
|
||||
turnId: "turn-1" as never,
|
||||
planMarkdown: "# Next steps",
|
||||
implementedAt: null,
|
||||
implementationThreadId: null,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
updatedAt: "2026-01-01T00:00:03Z",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(rowsWithLaterPlan.some((row) => row.kind === "work-live")).toBe(false);
|
||||
expect(rowsWithLaterPlan.some((row) => row.kind === "proposed-plan")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps a running call visible when a parallel call completes", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-running-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-running",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-running",
|
||||
label: "Search files",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "work-completed-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
entry: {
|
||||
id: "work-completed",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-completed",
|
||||
label: "Read file",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "completed" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
entry: { id: "work-running", toolLifecycleStatus: "inProgress" },
|
||||
groupedEntries: [{ id: "work-running" }, { id: "work-completed" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a completed trailing call to history while the turn keeps thinking", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-completed-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-completed",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-completed",
|
||||
label: "Ran tests",
|
||||
command: "vp test run",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "completed" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.some((row) => row.kind === "work-live")).toBe(false);
|
||||
expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: true });
|
||||
expect(rows.some((row) => row.kind === "work-toggle")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps thinking visible after an informational work entry", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "context-compacted-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "context-compacted",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
label: "Context compacted",
|
||||
tone: "info" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: true });
|
||||
});
|
||||
|
||||
it("keeps the current tool batch live before an empty assistant placeholder", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-1",
|
||||
label: "Run command",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-placeholder-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
message: {
|
||||
id: "assistant-placeholder" as never,
|
||||
role: "assistant",
|
||||
text: " ",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
updatedAt: "2026-01-01T00:00:02Z",
|
||||
streaming: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.id)).toContain("work-live:tool:call-1");
|
||||
});
|
||||
|
||||
it("does not fold the session's running turn when latestTurn regresses", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -864,7 +1356,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.turnId)).toEqual([
|
||||
"turn-1",
|
||||
]);
|
||||
expect(rows.map((row) => row.id)).toContain("running-work-entry");
|
||||
expect(rows.map((row) => row.id)).toContain("work-live:running-work-entry");
|
||||
});
|
||||
|
||||
it("only shows assistant metadata on the terminal assistant message", () => {
|
||||
@@ -1006,18 +1498,18 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expandedWorkGroupIds: new Set(["work-group:work-entry-1"]),
|
||||
});
|
||||
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual(["work-3", "work-toggle:work-entry-1"]);
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual(["work-toggle:work-entry-1"]);
|
||||
expect(collapsedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
groupId: "work-group:work-entry-1",
|
||||
hiddenCount: 2,
|
||||
hiddenCount: 3,
|
||||
expanded: false,
|
||||
onlyToolEntries: true,
|
||||
});
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"work-toggle:work-entry-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
"work-3",
|
||||
"work-toggle:work-entry-1",
|
||||
]);
|
||||
expect(expandedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
expanded: true,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as Equal from "effect/Equal";
|
||||
import {
|
||||
formatDuration,
|
||||
workEntryIndicatesToolFailure,
|
||||
workEntryIndicatesToolNeutralStatus,
|
||||
workLogEntryIsToolLike,
|
||||
type TimelineEntry,
|
||||
@@ -170,6 +171,17 @@ export type MessagesTimelineRow =
|
||||
id: string;
|
||||
createdAt: string;
|
||||
groupedEntries: WorkLogEntry[];
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
isLastExpandedToolGroupEntry: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "work-live";
|
||||
id: string;
|
||||
createdAt: string;
|
||||
entry: WorkLogEntry;
|
||||
groupedEntries: WorkLogEntry[];
|
||||
groupId: string;
|
||||
expanded: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "work-toggle";
|
||||
@@ -179,6 +191,9 @@ export type MessagesTimelineRow =
|
||||
hiddenCount: number;
|
||||
expanded: boolean;
|
||||
onlyToolEntries: boolean;
|
||||
summary: string | null;
|
||||
summaryKind: ToolGroupAction | "mixed" | null;
|
||||
hasFailure: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "turn-fold";
|
||||
@@ -212,7 +227,12 @@ export type MessagesTimelineRow =
|
||||
createdAt: string;
|
||||
turnPlan: TurnPlanEntry;
|
||||
}
|
||||
| { kind: "working"; id: string; createdAt: string | null };
|
||||
| {
|
||||
kind: "working";
|
||||
id: string;
|
||||
createdAt: string | null;
|
||||
showThinking: boolean;
|
||||
};
|
||||
|
||||
export interface StableMessagesTimelineRowsState {
|
||||
byId: Map<string, MessagesTimelineRow>;
|
||||
@@ -242,6 +262,106 @@ export function normalizeCompactToolLabel(value: string): string {
|
||||
return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
|
||||
}
|
||||
|
||||
type ToolGroupAction = "read" | "edit" | "command" | "code-search" | "search" | "other";
|
||||
|
||||
export function workLogEntryIsLocalCodeSearch(entry: WorkLogEntry): boolean {
|
||||
return (
|
||||
entry.itemType === "web_search" &&
|
||||
/\bgrep\b/i.test(normalizeCompactToolLabel(entry.toolTitle ?? entry.label))
|
||||
);
|
||||
}
|
||||
|
||||
function toolGroupAction(entry: WorkLogEntry): ToolGroupAction {
|
||||
if (
|
||||
entry.requestKind === "file-read" ||
|
||||
entry.itemType === "image_view" ||
|
||||
(entry.itemType === "dynamic_tool_call" && entry.toolTitle === "Read File")
|
||||
) {
|
||||
return "read";
|
||||
}
|
||||
if (
|
||||
entry.requestKind === "file-change" ||
|
||||
entry.itemType === "file_change" ||
|
||||
(entry.changedFiles?.length ?? 0) > 0
|
||||
) {
|
||||
return "edit";
|
||||
}
|
||||
if (entry.requestKind === "command" || entry.itemType === "command_execution" || entry.command) {
|
||||
return "command";
|
||||
}
|
||||
if (workLogEntryIsLocalCodeSearch(entry)) return "code-search";
|
||||
if (entry.itemType === "web_search") return "search";
|
||||
return "other";
|
||||
}
|
||||
|
||||
function toolGroupActionCount(
|
||||
action: ToolGroupAction,
|
||||
entries: ReadonlyArray<WorkLogEntry>,
|
||||
): number {
|
||||
if (action !== "edit") return entries.length;
|
||||
|
||||
const changedFiles = new Set<string>();
|
||||
let editsWithoutFileDetails = 0;
|
||||
for (const entry of entries) {
|
||||
if (!entry.changedFiles || entry.changedFiles.length === 0) {
|
||||
editsWithoutFileDetails += 1;
|
||||
continue;
|
||||
}
|
||||
for (const file of entry.changedFiles) changedFiles.add(file);
|
||||
}
|
||||
return changedFiles.size + editsWithoutFileDetails;
|
||||
}
|
||||
|
||||
function toolGroupActionLabel(action: ToolGroupAction, count: number): string {
|
||||
switch (action) {
|
||||
case "read":
|
||||
return `Read ${count} ${count === 1 ? "file" : "files"}`;
|
||||
case "edit":
|
||||
return `Changed ${count} ${count === 1 ? "file" : "files"}`;
|
||||
case "command":
|
||||
return `Ran ${count} ${count === 1 ? "command" : "commands"}`;
|
||||
case "search":
|
||||
return `Searched the web ${count} ${count === 1 ? "time" : "times"}`;
|
||||
case "code-search":
|
||||
return `Searched code ${count} ${count === 1 ? "time" : "times"}`;
|
||||
case "other":
|
||||
return `Used ${count} ${count === 1 ? "tool" : "tools"}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** Immediate, provider-neutral fallback while generated tool summaries are disabled or unavailable. */
|
||||
export function summarizeToolGroup(entries: ReadonlyArray<WorkLogEntry>): string {
|
||||
const groupedEntries = new Map<ToolGroupAction, WorkLogEntry[]>();
|
||||
for (const entry of entries) {
|
||||
const action = toolGroupAction(entry);
|
||||
const group = groupedEntries.get(action);
|
||||
if (group) group.push(entry);
|
||||
else groupedEntries.set(action, [entry]);
|
||||
}
|
||||
const labels = [...groupedEntries].map(([action, actionEntries]) =>
|
||||
toolGroupActionLabel(action, toolGroupActionCount(action, actionEntries)),
|
||||
);
|
||||
const sentenceLabels = labels.map((label, index) =>
|
||||
index === 0 ? label : label.charAt(0).toLowerCase() + label.slice(1),
|
||||
);
|
||||
if (sentenceLabels.length < 2) return sentenceLabels[0] ?? "";
|
||||
if (sentenceLabels.length === 2) return sentenceLabels.join(" and ");
|
||||
return `${sentenceLabels.slice(0, -1).join(", ")}, and ${sentenceLabels.at(-1)}`;
|
||||
}
|
||||
|
||||
function toolGroupSummaryKind(entries: ReadonlyArray<WorkLogEntry>): ToolGroupAction | "mixed" {
|
||||
const actions = new Set(entries.map(toolGroupAction));
|
||||
return actions.size === 1 ? actions.values().next().value! : "mixed";
|
||||
}
|
||||
|
||||
function workGroupIdentity(timelineEntryId: string, entry: WorkLogEntry): string {
|
||||
return entry.toolCallId ? `tool:${entry.toolCallId}` : timelineEntryId;
|
||||
}
|
||||
|
||||
function workGroupId(timelineEntryId: string, entry: WorkLogEntry): string {
|
||||
return `work-group:${workGroupIdentity(timelineEntryId, entry)}`;
|
||||
}
|
||||
|
||||
export function resolveAssistantMessageCopyState({
|
||||
text,
|
||||
showCopyButton,
|
||||
@@ -314,17 +434,36 @@ function deriveUnsettledTurnId(
|
||||
return isSettled ? null : latestTurn.turnId;
|
||||
}
|
||||
|
||||
function lastUserMessageIndex(timelineEntries: ReadonlyArray<TimelineEntry>): number {
|
||||
return timelineEntries.findLastIndex(
|
||||
(entry) => entry.kind === "message" && entry.message.role === "user",
|
||||
);
|
||||
}
|
||||
|
||||
function timelineEntryTurnId(entry: TimelineEntry): TurnId | null {
|
||||
if (entry.kind === "message") {
|
||||
return entry.message.role === "assistant" ? (entry.message.turnId ?? null) : null;
|
||||
}
|
||||
if (entry.kind === "turn-plan") {
|
||||
return entry.turnPlan.turnId;
|
||||
}
|
||||
return entry.kind === "work" ? (entry.entry.turnId ?? null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settled turns fold their commentary and tool activity behind a
|
||||
* "Worked for ..." row anchored at the turn's first foldable entry; the
|
||||
* terminal assistant message stays visible below the fold.
|
||||
* "Worked for ..." row. While collapsed, the row stays immediately before the
|
||||
* next terminal assistant response so a steer cannot strand it above the
|
||||
* visible response. While expanded, it moves before the first hidden entry so
|
||||
* the revealed activity follows the disclosure in chronological order.
|
||||
*/
|
||||
function deriveTurnFolds(input: {
|
||||
timelineEntries: ReadonlyArray<TimelineEntry>;
|
||||
terminalAssistantMessageIds: ReadonlySet<string>;
|
||||
latestTurn: TimelineLatestTurn | null;
|
||||
unsettledTurnId: TurnId | null;
|
||||
}): ReadonlyMap<string, TurnFold> {
|
||||
expandedTurnIds: ReadonlySet<TurnId> | undefined;
|
||||
}): ReadonlyMap<string, ReadonlyArray<TurnFold>> {
|
||||
interface TurnGroup {
|
||||
entries: Array<TimelineEntry>;
|
||||
terminalEntry: Extract<TimelineEntry, { kind: "message" }> | null;
|
||||
@@ -379,7 +518,7 @@ function deriveTurnFolds(input: {
|
||||
}
|
||||
}
|
||||
|
||||
const foldsByAnchorEntryId = new Map<string, TurnFold>();
|
||||
const foldsByAnchorEntryId = new Map<string, TurnFold[]>();
|
||||
for (const [turnId, group] of groupsByTurnId) {
|
||||
if (turnId === input.unsettledTurnId) {
|
||||
continue;
|
||||
@@ -405,8 +544,31 @@ function deriveTurnFolds(input: {
|
||||
}
|
||||
|
||||
const firstEntry = group.entries[0];
|
||||
const firstHiddenEntry = group.entries.find((entry) => hiddenEntryIds.has(entry.id));
|
||||
const lastEntry = group.entries.at(-1);
|
||||
if (!firstEntry || !lastEntry) {
|
||||
if (!firstEntry || !firstHiddenEntry || !lastEntry) {
|
||||
continue;
|
||||
}
|
||||
const lastHiddenEntryIndex = input.timelineEntries.findLastIndex((entry) =>
|
||||
hiddenEntryIds.has(entry.id),
|
||||
);
|
||||
if (lastHiddenEntryIndex < 0) {
|
||||
continue;
|
||||
}
|
||||
const nextTerminalAssistantEntry = input.timelineEntries
|
||||
.slice(lastHiddenEntryIndex + 1)
|
||||
.find(
|
||||
(entry) =>
|
||||
entry.kind === "message" &&
|
||||
entry.message.role === "assistant" &&
|
||||
input.terminalAssistantMessageIds.has(entry.message.id),
|
||||
);
|
||||
const collapsedAnchorEntry =
|
||||
nextTerminalAssistantEntry ?? input.timelineEntries[lastHiddenEntryIndex];
|
||||
const anchorEntry = input.expandedTurnIds?.has(turnId)
|
||||
? firstHiddenEntry
|
||||
: collapsedAnchorEntry;
|
||||
if (!anchorEntry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -435,13 +597,16 @@ function deriveTurnFolds(input: {
|
||||
? `Worked for ${duration}`
|
||||
: "Worked";
|
||||
|
||||
foldsByAnchorEntryId.set(firstEntry.id, {
|
||||
const fold = {
|
||||
turnId,
|
||||
anchorEntryId: firstEntry.id,
|
||||
createdAt: firstEntry.createdAt,
|
||||
anchorEntryId: anchorEntry.id,
|
||||
createdAt: anchorEntry.createdAt,
|
||||
hiddenEntryIds,
|
||||
label,
|
||||
});
|
||||
};
|
||||
const anchoredFolds = foldsByAnchorEntryId.get(anchorEntry.id);
|
||||
if (anchoredFolds) anchoredFolds.push(fold);
|
||||
else foldsByAnchorEntryId.set(anchorEntry.id, [fold]);
|
||||
}
|
||||
return foldsByAnchorEntryId;
|
||||
}
|
||||
@@ -471,38 +636,206 @@ export function deriveMessagesTimelineRows(input: {
|
||||
terminalAssistantMessageIds,
|
||||
latestTurn: input.latestTurn ?? null,
|
||||
unsettledTurnId,
|
||||
expandedTurnIds: input.expandedTurnIds,
|
||||
});
|
||||
const collapsedEntryIds = new Set<string>();
|
||||
for (const fold of foldsByAnchorEntryId.values()) {
|
||||
if (!input.expandedTurnIds?.has(fold.turnId)) {
|
||||
for (const entryId of fold.hiddenEntryIds) {
|
||||
collapsedEntryIds.add(entryId);
|
||||
for (const folds of foldsByAnchorEntryId.values()) {
|
||||
for (const fold of folds) {
|
||||
if (!input.expandedTurnIds?.has(fold.turnId)) {
|
||||
for (const entryId of fold.hiddenEntryIds) {
|
||||
collapsedEntryIds.add(entryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let activeTurnHeaderIndex = input.timelineEntries.length;
|
||||
if (input.isWorking) {
|
||||
const latestUserMessageIndex = lastUserMessageIndex(input.timelineEntries);
|
||||
const firstOwnedAfterUser =
|
||||
unsettledTurnId === null
|
||||
? -1
|
||||
: input.timelineEntries.findIndex(
|
||||
(entry, index) =>
|
||||
index > latestUserMessageIndex &&
|
||||
(entry.kind === "proposed-plan" ||
|
||||
entry.kind === "turn-plan" ||
|
||||
timelineEntryTurnId(entry) === unsettledTurnId),
|
||||
);
|
||||
activeTurnHeaderIndex =
|
||||
firstOwnedAfterUser >= 0 ? firstOwnedAfterUser : latestUserMessageIndex + 1;
|
||||
}
|
||||
const entryBelongsToActiveTurn = (entry: TimelineEntry, index: number) =>
|
||||
input.isWorking &&
|
||||
index >= activeTurnHeaderIndex &&
|
||||
(unsettledTurnId === null || timelineEntryTurnId(entry) === unsettledTurnId);
|
||||
const isVisibleActiveToolEntry = (entry: WorkLogEntry) =>
|
||||
workLogEntryIsToolLike(entry) &&
|
||||
(entry.toolLifecycleStatus === "inProgress" || !workEntryIndicatesToolNeutralStatus(entry));
|
||||
const workEntryCouldBeInProgress = (entry: WorkLogEntry) =>
|
||||
entry.toolLifecycleStatus === undefined || entry.toolLifecycleStatus === "inProgress";
|
||||
const activeEntries = input.isWorking
|
||||
? input.timelineEntries.filter((entry, index) => entryBelongsToActiveTurn(entry, index))
|
||||
: [];
|
||||
const activeTurnHasVisibleContent =
|
||||
activeEntries.some((entry) => {
|
||||
if (entry.kind === "message") {
|
||||
return entry.message.role === "assistant" && (entry.message.text?.trim().length ?? 0) > 0;
|
||||
}
|
||||
if (entry.kind === "work") {
|
||||
return (
|
||||
entry.entry.agentSpawn === undefined &&
|
||||
workLogEntryIsToolLike(entry.entry) &&
|
||||
workEntryCouldBeInProgress(entry.entry)
|
||||
);
|
||||
}
|
||||
if (entry.kind === "turn-plan") return true;
|
||||
return false;
|
||||
}) ||
|
||||
input.timelineEntries
|
||||
.slice(activeTurnHeaderIndex)
|
||||
.some((entry) => entry.kind === "proposed-plan" || entry.kind === "turn-plan");
|
||||
|
||||
const activeWorkEntryIds = new Set<string>();
|
||||
const activeWorkRowsByAnchorId = new Map<
|
||||
string,
|
||||
Extract<MessagesTimelineRow, { kind: "work-live" }>
|
||||
>();
|
||||
const hasLaterTurnContent = Array.from({ length: input.timelineEntries.length + 1 }, () => false);
|
||||
for (let index = input.timelineEntries.length - 1; index >= 0; index -= 1) {
|
||||
const entry = input.timelineEntries[index];
|
||||
if (!entry) continue;
|
||||
const isVisibleTurnContent =
|
||||
(entry.kind === "message" && entry.message.role === "user") ||
|
||||
entry.kind === "proposed-plan" ||
|
||||
(entryBelongsToActiveTurn(entry, index) &&
|
||||
((entry.kind === "message" &&
|
||||
entry.message.role === "assistant" &&
|
||||
(entry.message.text?.trim().length ?? 0) > 0) ||
|
||||
entry.kind === "turn-plan" ||
|
||||
(entry.kind === "work" &&
|
||||
entry.entry.agentSpawn === undefined &&
|
||||
isVisibleActiveToolEntry(entry.entry))));
|
||||
hasLaterTurnContent[index] = isVisibleTurnContent || hasLaterTurnContent[index + 1] === true;
|
||||
}
|
||||
|
||||
for (let index = 0; index < input.timelineEntries.length; index += 1) {
|
||||
const entry = input.timelineEntries[index];
|
||||
if (
|
||||
!entry ||
|
||||
entry.kind !== "work" ||
|
||||
entry.entry.agentSpawn !== undefined ||
|
||||
!entryBelongsToActiveTurn(entry, index)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (!isVisibleActiveToolEntry(entry.entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const anchorEntry = entry;
|
||||
let latestToolEntry = entry;
|
||||
const batchEntryIds = [entry.id];
|
||||
const visibleBatchEntries = [entry.entry];
|
||||
let cursor = index + 1;
|
||||
while (cursor < input.timelineEntries.length) {
|
||||
const nextEntry = input.timelineEntries[cursor];
|
||||
if (
|
||||
!nextEntry ||
|
||||
nextEntry.kind !== "work" ||
|
||||
nextEntry.entry.agentSpawn !== undefined ||
|
||||
!entryBelongsToActiveTurn(nextEntry, cursor)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
batchEntryIds.push(nextEntry.id);
|
||||
if (isVisibleActiveToolEntry(nextEntry.entry)) {
|
||||
if (
|
||||
nextEntry.entry.toolLifecycleStatus === "inProgress" ||
|
||||
latestToolEntry.entry.toolLifecycleStatus !== "inProgress"
|
||||
) {
|
||||
latestToolEntry = nextEntry;
|
||||
}
|
||||
visibleBatchEntries.push(nextEntry.entry);
|
||||
}
|
||||
cursor += 1;
|
||||
}
|
||||
|
||||
// Once newer commentary, a plan, or another tool batch exists, this batch
|
||||
// is history. Let the regular work-group path turn it into an expandable
|
||||
// summary so none of its calls disappear behind the live one-line view.
|
||||
if (
|
||||
hasLaterTurnContent[cursor] !== true &&
|
||||
visibleBatchEntries.some(workEntryCouldBeInProgress)
|
||||
) {
|
||||
for (const entryId of batchEntryIds) activeWorkEntryIds.add(entryId);
|
||||
const groupId = workGroupId(anchorEntry.id, anchorEntry.entry);
|
||||
activeWorkRowsByAnchorId.set(anchorEntry.id, {
|
||||
kind: "work-live",
|
||||
id: `work-live:${workGroupIdentity(anchorEntry.id, anchorEntry.entry)}`,
|
||||
createdAt: anchorEntry.createdAt,
|
||||
entry: latestToolEntry.entry,
|
||||
groupedEntries: visibleBatchEntries,
|
||||
groupId,
|
||||
expanded: input.expandedWorkGroupIds?.has(groupId) ?? false,
|
||||
});
|
||||
}
|
||||
index = cursor - 1;
|
||||
}
|
||||
|
||||
for (let index = 0; index < input.timelineEntries.length; index += 1) {
|
||||
const timelineEntry = input.timelineEntries[index];
|
||||
if (!timelineEntry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const turnFold = foldsByAnchorEntryId.get(timelineEntry.id);
|
||||
if (turnFold) {
|
||||
if (input.isWorking && index === activeTurnHeaderIndex) {
|
||||
nextRows.push({
|
||||
kind: "turn-fold",
|
||||
id: `turn-fold:${turnFold.turnId}`,
|
||||
createdAt: turnFold.createdAt,
|
||||
turnId: turnFold.turnId,
|
||||
label: turnFold.label,
|
||||
expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
|
||||
kind: "working",
|
||||
id: "working-indicator-row",
|
||||
createdAt: input.activeTurnStartedAt,
|
||||
showThinking: !activeTurnHasVisibleContent,
|
||||
});
|
||||
}
|
||||
|
||||
const anchoredTurnFolds = foldsByAnchorEntryId.get(timelineEntry.id);
|
||||
if (anchoredTurnFolds) {
|
||||
for (const turnFold of anchoredTurnFolds) {
|
||||
nextRows.push({
|
||||
kind: "turn-fold",
|
||||
id: `turn-fold:${turnFold.turnId}`,
|
||||
createdAt: turnFold.createdAt,
|
||||
turnId: turnFold.turnId,
|
||||
label: turnFold.label,
|
||||
expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (collapsedEntryIds.has(timelineEntry.id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (activeWorkEntryIds.has(timelineEntry.id)) {
|
||||
const activeWorkRow = activeWorkRowsByAnchorId.get(timelineEntry.id);
|
||||
if (activeWorkRow) {
|
||||
nextRows.push(activeWorkRow);
|
||||
if (activeWorkRow.expanded) {
|
||||
for (const [entryIndex, workEntry] of activeWorkRow.groupedEntries.entries()) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: true,
|
||||
isLastExpandedToolGroupEntry: entryIndex === activeWorkRow.groupedEntries.length - 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timelineEntry.kind === "work") {
|
||||
const groupedEntries = [timelineEntry.entry];
|
||||
let cursor = index + 1;
|
||||
@@ -511,6 +844,7 @@ export function deriveMessagesTimelineRows(input: {
|
||||
if (
|
||||
!nextEntry ||
|
||||
nextEntry.kind !== "work" ||
|
||||
activeWorkEntryIds.has(nextEntry.id) ||
|
||||
collapsedEntryIds.has(nextEntry.id) ||
|
||||
foldsByAnchorEntryId.has(nextEntry.id)
|
||||
) {
|
||||
@@ -523,15 +857,48 @@ export function deriveMessagesTimelineRows(input: {
|
||||
(entry) => !workEntryIndicatesToolNeutralStatus(entry),
|
||||
);
|
||||
if (visibleGroupedEntries.length > 0) {
|
||||
if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
|
||||
const onlyToolEntries = visibleGroupedEntries.every(
|
||||
(entry) => workLogEntryIsToolLike(entry) && entry.agentSpawn === undefined,
|
||||
);
|
||||
if (onlyToolEntries) {
|
||||
const groupId = workGroupId(timelineEntry.id, timelineEntry.entry);
|
||||
const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
|
||||
const summaryKind = toolGroupSummaryKind(visibleGroupedEntries);
|
||||
nextRows.push({
|
||||
kind: "work-toggle",
|
||||
id: `work-toggle:${timelineEntry.id}`,
|
||||
createdAt: timelineEntry.createdAt,
|
||||
groupId,
|
||||
hiddenCount: visibleGroupedEntries.length,
|
||||
expanded,
|
||||
onlyToolEntries: true,
|
||||
summary: summarizeToolGroup(visibleGroupedEntries),
|
||||
summaryKind,
|
||||
hasFailure: visibleGroupedEntries.some((entry) => workEntryIndicatesToolFailure(entry)),
|
||||
});
|
||||
if (expanded) {
|
||||
for (const [entryIndex, workEntry] of visibleGroupedEntries.entries()) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: true,
|
||||
isLastExpandedToolGroupEntry: entryIndex === visibleGroupedEntries.length - 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: timelineEntry.id,
|
||||
createdAt: timelineEntry.createdAt,
|
||||
groupedEntries: visibleGroupedEntries,
|
||||
isExpandedToolGroupEntry: false,
|
||||
isLastExpandedToolGroupEntry: false,
|
||||
});
|
||||
} else {
|
||||
const groupId = `work-group:${timelineEntry.id}`;
|
||||
const groupId = workGroupId(timelineEntry.id, timelineEntry.entry);
|
||||
const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
|
||||
// Agent-spawn CTA rows are always visible: a running fleet must
|
||||
// never hide behind a "+N tool calls" toggle. Selection is by
|
||||
@@ -555,6 +922,8 @@ export function deriveMessagesTimelineRows(input: {
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: false,
|
||||
isLastExpandedToolGroupEntry: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -566,8 +935,11 @@ export function deriveMessagesTimelineRows(input: {
|
||||
groupId,
|
||||
hiddenCount: hiddenEntries.length,
|
||||
expanded,
|
||||
onlyToolEntries: visibleGroupedEntries.every((entry) =>
|
||||
workLogEntryIsToolLike(entry),
|
||||
onlyToolEntries,
|
||||
summary: null,
|
||||
summaryKind: null,
|
||||
hasFailure: visibleGroupedEntries.some((entry) =>
|
||||
workEntryIndicatesToolFailure(entry),
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -633,11 +1005,12 @@ export function deriveMessagesTimelineRows(input: {
|
||||
});
|
||||
}
|
||||
|
||||
if (input.isWorking) {
|
||||
if (input.isWorking && activeTurnHeaderIndex === input.timelineEntries.length) {
|
||||
nextRows.push({
|
||||
kind: "working",
|
||||
id: "working-indicator-row",
|
||||
createdAt: input.activeTurnStartedAt,
|
||||
showThinking: !activeTurnHasVisibleContent,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -670,7 +1043,9 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
|
||||
switch (a.kind) {
|
||||
case "working":
|
||||
return a.createdAt === (b as typeof a).createdAt;
|
||||
return (
|
||||
a.createdAt === (b as typeof a).createdAt && a.showThinking === (b as typeof a).showThinking
|
||||
);
|
||||
|
||||
case "turn-fold": {
|
||||
const bf = b as typeof a;
|
||||
@@ -687,8 +1062,25 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan;
|
||||
}
|
||||
|
||||
case "work":
|
||||
return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
|
||||
case "work": {
|
||||
const bw = b as typeof a;
|
||||
return (
|
||||
a.isExpandedToolGroupEntry === bw.isExpandedToolGroupEntry &&
|
||||
a.isLastExpandedToolGroupEntry === bw.isLastExpandedToolGroupEntry &&
|
||||
Equal.equals(a.groupedEntries, bw.groupedEntries)
|
||||
);
|
||||
}
|
||||
|
||||
case "work-live": {
|
||||
const bw = b as typeof a;
|
||||
return (
|
||||
a.createdAt === bw.createdAt &&
|
||||
a.groupId === bw.groupId &&
|
||||
a.expanded === bw.expanded &&
|
||||
Equal.equals(a.entry, bw.entry) &&
|
||||
Equal.equals(a.groupedEntries, bw.groupedEntries)
|
||||
);
|
||||
}
|
||||
|
||||
case "work-toggle": {
|
||||
const bw = b as typeof a;
|
||||
@@ -697,7 +1089,10 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
a.groupId === bw.groupId &&
|
||||
a.hiddenCount === bw.hiddenCount &&
|
||||
a.expanded === bw.expanded &&
|
||||
a.onlyToolEntries === bw.onlyToolEntries
|
||||
a.onlyToolEntries === bw.onlyToolEntries &&
|
||||
a.summary === bw.summary &&
|
||||
a.summaryKind === bw.summaryKind &&
|
||||
a.hasFailure === bw.hasFailure
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,6 +238,47 @@ function buildAssistantTimelineEntry(text: string) {
|
||||
}
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
it("sizes the subagent card from its own container", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "agent-spawn-entry",
|
||||
kind: "work",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
entry: {
|
||||
id: "agent-spawn",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
label: "Spawned agent",
|
||||
tone: "info",
|
||||
agentSpawn: { workflowId: null, agentTaskIds: ["agent-1"] },
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("@container/agent-group");
|
||||
expect(markup).toContain("@[24rem]/agent-group:inline");
|
||||
expect(markup).toContain("@[32rem]/agent-group:flex");
|
||||
expect(markup).toContain("sr-only @[32rem]/agent-group:hidden");
|
||||
});
|
||||
|
||||
it("keeps the active plan step in the live thinking row", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
isWorking
|
||||
workingStepLabel="Write focused tests"
|
||||
timelineEntries={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("Thinking · Write focused tests");
|
||||
expect(markup).toContain('aria-hidden="true" class="size-6 shrink-0"');
|
||||
});
|
||||
|
||||
it("sizes expanded tool details with the configured code font size", () => {
|
||||
expect(toolCallExpandedBodyClassName).toContain("var(--font-size-code");
|
||||
expect(toolCallExpandedBodyClassName).not.toContain("text-[11px]");
|
||||
@@ -706,7 +747,50 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("Work Log");
|
||||
});
|
||||
|
||||
it("formats changed file paths from the workspace root", () => {
|
||||
it("makes the whole live tool row expandable without adding a chevron", () => {
|
||||
const turnId = TurnId.make("turn-live-tools");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
isWorking
|
||||
activeTurnInProgress
|
||||
activeTurnStartedAt="2026-03-17T19:12:28.000Z"
|
||||
latestTurn={{
|
||||
turnId,
|
||||
state: "running",
|
||||
startedAt: "2026-03-17T19:12:28.000Z",
|
||||
completedAt: null,
|
||||
}}
|
||||
runningTurnId={turnId}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "entry-live-tool",
|
||||
kind: "work",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
entry: {
|
||||
id: "work-live-tool",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
turnId,
|
||||
toolCallId: "call-live-tool",
|
||||
label: "Running tests",
|
||||
command: 'FOO="hello world" /usr/bin/env -C /tmp /usr/bin/sudo -iu postgres psql',
|
||||
tone: "tool",
|
||||
toolLifecycleStatus: "inProgress",
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).not.toContain('aria-label="Expand current tool calls"');
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
expect(markup).toContain("Running psql");
|
||||
expect(markup).not.toContain("lucide-chevron-right");
|
||||
expect(markup).not.toContain("lucide-chevron-down");
|
||||
expect(markup).not.toContain("hover:bg-accent/20");
|
||||
});
|
||||
|
||||
it("summarizes completed changed-file activity", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
@@ -728,7 +812,7 @@ describe("MessagesTimeline", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
|
||||
expect(markup).toContain("Changed 1 file");
|
||||
expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
|
||||
});
|
||||
|
||||
@@ -832,6 +916,8 @@ describe("MessagesTimeline", () => {
|
||||
);
|
||||
|
||||
expect(markup).toContain("lucide-x");
|
||||
expect(markup).toContain('aria-label="Used 1 tool, tool call failed"');
|
||||
expect(markup).toContain('role="img"');
|
||||
expect(markup).toContain('aria-label="Tool call failed"');
|
||||
});
|
||||
});
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
deriveTimelineEntries,
|
||||
workEntryIndicatesToolFailure,
|
||||
workEntryIndicatesToolNeutralStatus,
|
||||
workEntryIndicatesToolSuccess,
|
||||
workLogEntryIsToolLike,
|
||||
} from "../../session-logic";
|
||||
import { type TurnDiffSummary } from "../../types";
|
||||
@@ -57,7 +56,7 @@ import {
|
||||
MessageCircleIcon,
|
||||
MousePointerClickIcon,
|
||||
PaintbrushIcon,
|
||||
MinusIcon,
|
||||
SearchIcon,
|
||||
SquarePenIcon,
|
||||
TerminalIcon,
|
||||
Undo2Icon,
|
||||
@@ -84,6 +83,7 @@ import {
|
||||
resolveTimelineMinimapInteractiveWidth,
|
||||
resolveTimelineMinimapTopPercent,
|
||||
shouldPreserveAssistantLineBreaks,
|
||||
workLogEntryIsLocalCodeSearch,
|
||||
type StableMessagesTimelineRowsState,
|
||||
type MessagesTimelineRow,
|
||||
TIMELINE_MINIMAP_MIN_ITEMS,
|
||||
@@ -921,17 +921,34 @@ type TimelineWorkEntry = Extract<MessagesTimelineRow, { kind: "work" }>["grouped
|
||||
type TimelineRow = MessagesTimelineRow;
|
||||
|
||||
const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: TimelineRow }) {
|
||||
const isExpandedToolGroupEntry = row.kind === "work" && row.isExpandedToolGroupEntry;
|
||||
const isLastExpandedToolGroupEntry = row.kind === "work" && row.isLastExpandedToolGroupEntry;
|
||||
const isExpandedToolGroupHeader =
|
||||
(row.kind === "work-toggle" && row.onlyToolEntries && row.expanded) ||
|
||||
(row.kind === "work-live" && row.expanded);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
// Commentary (non-terminal assistant) rows carry no metadata row, so
|
||||
// they sit closer to the work that follows them.
|
||||
(row.kind === "message" && row.message.role === "assistant" && !row.showAssistantMeta) ||
|
||||
row.kind === "work" ||
|
||||
row.kind === "work-toggle" ||
|
||||
row.kind === "turn-plan"
|
||||
? "pb-2"
|
||||
: "pb-4",
|
||||
isExpandedToolGroupEntry
|
||||
? isLastExpandedToolGroupEntry
|
||||
? "pb-1"
|
||||
: "pb-0"
|
||||
: isExpandedToolGroupHeader
|
||||
? "pb-0"
|
||||
: row.kind === "turn-fold"
|
||||
? "pb-1.5"
|
||||
: (row.kind === "message" &&
|
||||
row.message.role === "assistant" &&
|
||||
!row.showAssistantMeta) ||
|
||||
row.kind === "work" ||
|
||||
row.kind === "work-live" ||
|
||||
row.kind === "work-toggle" ||
|
||||
row.kind === "turn-plan"
|
||||
? "pb-2"
|
||||
: "pb-4",
|
||||
row.kind === "message" && row.message.role === "assistant" ? "group/assistant" : null,
|
||||
)}
|
||||
data-timeline-row-id={row.id}
|
||||
@@ -939,7 +956,13 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
|
||||
data-message-id={row.kind === "message" ? row.message.id : undefined}
|
||||
data-message-role={row.kind === "message" ? row.message.role : undefined}
|
||||
>
|
||||
{row.kind === "work" ? <WorkGroupSection groupedEntries={row.groupedEntries} /> : null}
|
||||
{row.kind === "work" ? (
|
||||
<WorkGroupSection
|
||||
groupedEntries={row.groupedEntries}
|
||||
isExpandedToolGroupEntry={row.isExpandedToolGroupEntry}
|
||||
/>
|
||||
) : null}
|
||||
{row.kind === "work-live" ? <LiveWorkEntryTimelineRow row={row} /> : null}
|
||||
{row.kind === "work-toggle" ? <WorkGroupToggleTimelineRow row={row} /> : null}
|
||||
{row.kind === "turn-fold" ? <TurnFoldTimelineRow row={row} /> : null}
|
||||
{row.kind === "message" && row.message.role === "user" ? <UserTimelineRow row={row} /> : null}
|
||||
@@ -1093,7 +1116,7 @@ function TurnFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "turn-
|
||||
aria-expanded={row.expanded}
|
||||
data-scroll-anchor-ignore
|
||||
onClick={() => ctx.onToggleTurnFold(row.turnId)}
|
||||
className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-xs text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-sm leading-relaxed text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
>
|
||||
<span>{row.label}</span>
|
||||
<Icon className="size-3.5" />
|
||||
@@ -1280,16 +1303,10 @@ const TurnPlanTimelineRow = memo(function TurnPlanTimelineRow({
|
||||
});
|
||||
|
||||
function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
|
||||
const { workingStepLabel } = use(TimelineRowActivityCtx);
|
||||
return (
|
||||
<div className="py-0.5 pl-1.5">
|
||||
<div className="flex min-w-0 items-center gap-2 pt-1 text-secondary-label text-[11px] tabular-nums">
|
||||
<span className="inline-flex items-center gap-[3px]">
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse" />
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:200ms]" />
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:400ms]" />
|
||||
</span>
|
||||
<span className="shrink-0">
|
||||
<div>
|
||||
<div className="border-b border-border/60 pb-2 pt-1">
|
||||
<div className="px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
|
||||
{row.createdAt ? (
|
||||
<>
|
||||
Working for <WorkingTimer createdAt={row.createdAt} />
|
||||
@@ -1297,11 +1314,13 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
|
||||
) : (
|
||||
"Working..."
|
||||
)}
|
||||
</span>
|
||||
{workingStepLabel ? (
|
||||
<span className="min-w-0 truncate text-muted-foreground/55">· {workingStepLabel}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{row.showThinking ? (
|
||||
<div className="mt-2">
|
||||
<ThinkingActivityRow />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1342,13 +1361,20 @@ function WorkingTimer({ createdAt }: { createdAt: string }) {
|
||||
/** Renders one or more already-derived work log rows. Overflow expansion is modeled as LegendList data. */
|
||||
const WorkGroupSection = memo(function WorkGroupSection({
|
||||
groupedEntries,
|
||||
isExpandedToolGroupEntry,
|
||||
}: {
|
||||
groupedEntries: Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"];
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workspaceRoot } = use(TimelineRowCtx);
|
||||
const nonEmptyEntries = useMemo(
|
||||
() => groupedEntries.filter((entry) => !workEntryIndicatesToolNeutralStatus(entry)),
|
||||
[groupedEntries],
|
||||
() =>
|
||||
groupedEntries.filter(
|
||||
(entry) =>
|
||||
(isExpandedToolGroupEntry && entry.toolLifecycleStatus === "inProgress") ||
|
||||
!workEntryIndicatesToolNeutralStatus(entry),
|
||||
),
|
||||
[groupedEntries, isExpandedToolGroupEntry],
|
||||
);
|
||||
const onlyToolEntries = nonEmptyEntries.every((entry) => workLogEntryIsToolLike(entry));
|
||||
const groupLabel = onlyToolEntries
|
||||
@@ -1360,7 +1386,10 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
if (nonEmptyEntries.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="-mx-1 space-y-0.5 px-1 py-0.5" aria-label={groupLabel}>
|
||||
<section
|
||||
className={cn("-mx-1 px-1", isExpandedToolGroupEntry ? "py-0" : "space-y-0.5 py-0.5")}
|
||||
aria-label={groupLabel}
|
||||
>
|
||||
{!onlyToolEntries && (
|
||||
<p className="px-0.5 pb-0.5 font-medium text-secondary-label text-[11px]">{groupLabel}</p>
|
||||
)}
|
||||
@@ -1370,6 +1399,7 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
key={workEntry.id}
|
||||
workEntry={workEntry}
|
||||
workspaceRoot={workspaceRoot}
|
||||
isExpandedToolGroupEntry={isExpandedToolGroupEntry}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -1377,12 +1407,140 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
);
|
||||
});
|
||||
|
||||
function LiveActivityRow({ label, iconName }: { label: string; iconName?: WorkEntryIconName }) {
|
||||
return (
|
||||
<div className="relative min-h-6 w-fit max-w-full min-w-0 overflow-hidden rounded-md text-sm leading-relaxed">
|
||||
<LiveActivityContent label={label} iconName={iconName} />
|
||||
<div
|
||||
aria-hidden
|
||||
className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
|
||||
>
|
||||
<div className="live-activity-focus-counter">
|
||||
<div className="live-activity-focus-aligned">
|
||||
<LiveActivityContent label={label} iconName={iconName} highlighted />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ThinkingActivityRow() {
|
||||
const { workingStepLabel } = use(TimelineRowActivityCtx);
|
||||
return (
|
||||
<LiveActivityRow label={workingStepLabel ? `Thinking · ${workingStepLabel}` : "Thinking"} />
|
||||
);
|
||||
}
|
||||
|
||||
function LiveActivityContent({
|
||||
label,
|
||||
iconName,
|
||||
highlighted = false,
|
||||
}: {
|
||||
label: string;
|
||||
iconName: WorkEntryIconName | undefined;
|
||||
highlighted?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex min-h-6 min-w-0 items-center gap-1.5 px-1 py-0.5",
|
||||
highlighted ? "text-foreground" : "text-secondary-label",
|
||||
)}
|
||||
>
|
||||
{iconName ? (
|
||||
<span
|
||||
className={cn(
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
highlighted ? "text-foreground" : "text-icon-muted",
|
||||
)}
|
||||
>
|
||||
<WorkEntryIconSvg name={iconName} className="block size-4 shrink-0 stroke-[1.8]" />
|
||||
</span>
|
||||
) : (
|
||||
<span aria-hidden className="size-6 shrink-0" />
|
||||
)}
|
||||
<span className="min-w-0 flex-1 truncate">{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "work-live" }> }) {
|
||||
const ctx = use(TimelineRowCtx);
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<LiveActivityRow
|
||||
label={liveWorkEntryLabel(row.entry, ctx.workspaceRoot)}
|
||||
iconName={workEntryIconName(row.entry)}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function toolGroupSummaryIconName(
|
||||
kind: Extract<TimelineRow, { kind: "work-toggle" }>["summaryKind"],
|
||||
): WorkEntryIconName {
|
||||
switch (kind) {
|
||||
case "read":
|
||||
return "eye";
|
||||
case "edit":
|
||||
return "square-pen";
|
||||
case "command":
|
||||
return "terminal";
|
||||
case "search":
|
||||
return "globe";
|
||||
case "code-search":
|
||||
return "search";
|
||||
case "other":
|
||||
return "wrench";
|
||||
case "mixed":
|
||||
case null:
|
||||
return "hammer";
|
||||
}
|
||||
}
|
||||
|
||||
function WorkGroupToggleTimelineRow({
|
||||
row,
|
||||
}: {
|
||||
row: Extract<TimelineRow, { kind: "work-toggle" }>;
|
||||
}) {
|
||||
const ctx = use(TimelineRowCtx);
|
||||
if (row.onlyToolEntries && row.summary) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="group/tool-group flex min-h-6 w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-sm leading-relaxed transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-label={row.hasFailure ? `${row.summary}, tool call failed` : undefined}
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
row.hasFailure ? "text-destructive" : "text-icon-muted",
|
||||
)}
|
||||
role={row.hasFailure ? "img" : undefined}
|
||||
aria-label={row.hasFailure ? "Tool call failed" : undefined}
|
||||
>
|
||||
{row.hasFailure ? (
|
||||
<XIcon className="size-4 shrink-0 stroke-[1.8]" aria-hidden />
|
||||
) : (
|
||||
<WorkEntryIconSvg
|
||||
name={toolGroupSummaryIconName(row.summaryKind)}
|
||||
className="size-4 shrink-0 stroke-[1.8] opacity-70"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-label">{row.summary}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
const labelNoun = row.onlyToolEntries
|
||||
? row.hiddenCount === 1
|
||||
? "tool call"
|
||||
@@ -1394,14 +1552,14 @@ function WorkGroupToggleTimelineRow({
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-[12px] leading-5 transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
className="flex min-h-6 w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-sm leading-relaxed transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<span className="flex size-5 shrink-0 items-center justify-center text-icon-muted">
|
||||
<span className="flex size-6 shrink-0 items-center justify-center text-icon-muted">
|
||||
<ChevronDownIcon
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 opacity-70 transition-transform duration-200",
|
||||
"size-4 shrink-0 opacity-70 transition-transform duration-200",
|
||||
row.expanded && "rotate-180",
|
||||
)}
|
||||
/>
|
||||
@@ -1947,6 +2105,7 @@ type WorkEntryIconName =
|
||||
| "globe"
|
||||
| "hammer"
|
||||
| "message-circle"
|
||||
| "search"
|
||||
| "square-pen"
|
||||
| "terminal"
|
||||
| "wrench"
|
||||
@@ -1969,6 +2128,8 @@ function WorkEntryIconSvg({ name, className }: { name: WorkEntryIconName; classN
|
||||
return <HammerIcon className={className} aria-hidden />;
|
||||
case "message-circle":
|
||||
return <MessageCircleIcon className={className} aria-hidden />;
|
||||
case "search":
|
||||
return <SearchIcon className={className} aria-hidden />;
|
||||
case "square-pen":
|
||||
return <SquarePenIcon className={className} aria-hidden />;
|
||||
case "terminal":
|
||||
@@ -2025,32 +2186,159 @@ function workEntryPreview(
|
||||
: `${displayPath} +${workEntry.changedFiles!.length - 1} more`;
|
||||
}
|
||||
|
||||
function workEntryRawCommand(
|
||||
workEntry: Pick<TimelineWorkEntry, "command" | "rawCommand">,
|
||||
): string | null {
|
||||
const rawCommand = workEntry.rawCommand?.trim();
|
||||
if (!rawCommand || !workEntry.command) {
|
||||
return null;
|
||||
type CommandWrapper = "env" | "sudo";
|
||||
|
||||
const COMMAND_WRAPPER_OPTIONS_WITH_VALUE: Record<CommandWrapper, ReadonlySet<string>> = {
|
||||
env: new Set(["-C", "--chdir", "-S", "--split-string", "-u", "--unset"]),
|
||||
sudo: new Set(["-C", "--close-from", "-D", "--chdir", "-g", "--group", "-u", "--user"]),
|
||||
};
|
||||
|
||||
const COMMAND_WRAPPER_FLAGS: Record<CommandWrapper, ReadonlySet<string>> = {
|
||||
env: new Set(["-0", "--null", "-i", "--ignore-environment", "--debug"]),
|
||||
sudo: new Set(["-A", "--askpass", "-b", "--background", "-E", "-H", "-i", "-n", "-S"]),
|
||||
};
|
||||
|
||||
function tokenizeShellCommand(command: string): string[] | null {
|
||||
const tokens: string[] = [];
|
||||
let current = "";
|
||||
let quote: '"' | "'" | null = null;
|
||||
let escaping = false;
|
||||
let tokenStarted = false;
|
||||
|
||||
for (const character of command.trim()) {
|
||||
if (escaping) {
|
||||
current += character;
|
||||
escaping = false;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (character === "\\" && quote !== "'") {
|
||||
escaping = true;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (quote !== null) {
|
||||
if (character === quote) {
|
||||
quote = null;
|
||||
} else {
|
||||
current += character;
|
||||
}
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (character === '"' || character === "'") {
|
||||
quote = character;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (/\s/u.test(character)) {
|
||||
if (tokenStarted) {
|
||||
tokens.push(current);
|
||||
current = "";
|
||||
tokenStarted = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
current += character;
|
||||
tokenStarted = true;
|
||||
}
|
||||
return rawCommand === workEntry.command.trim() ? null : rawCommand;
|
||||
|
||||
if (quote !== null || escaping) return null;
|
||||
if (tokenStarted) tokens.push(current);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function commandProgramName(command: string): string | null {
|
||||
const tokens = tokenizeShellCommand(command);
|
||||
if (tokens === null) return null;
|
||||
let index = 0;
|
||||
let wrapper: CommandWrapper | null = null;
|
||||
|
||||
while (index < tokens.length) {
|
||||
const token = tokens[index];
|
||||
if (!token) return null;
|
||||
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(token)) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
const tokenProgram = token.split(/[\\/]/).at(-1);
|
||||
if (tokenProgram === "env" || tokenProgram === "sudo") {
|
||||
wrapper = tokenProgram;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (wrapper !== null && token === "--") {
|
||||
wrapper = null;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (wrapper !== null && token.startsWith("-")) {
|
||||
if (COMMAND_WRAPPER_OPTIONS_WITH_VALUE[wrapper].has(token)) {
|
||||
if (tokens[index + 1] === undefined) return null;
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
if (COMMAND_WRAPPER_FLAGS[wrapper].has(token) || /^--[^=]+=/.test(token)) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (/^-[A-Za-z].+/.test(token) && !token.startsWith("--")) {
|
||||
let consumesNextToken = false;
|
||||
for (const [optionIndex, option] of token.slice(1).split("").entries()) {
|
||||
const shortOption = `-${option}`;
|
||||
if (COMMAND_WRAPPER_OPTIONS_WITH_VALUE[wrapper].has(shortOption)) {
|
||||
consumesNextToken = optionIndex === token.length - 2;
|
||||
break;
|
||||
}
|
||||
if (!COMMAND_WRAPPER_FLAGS[wrapper].has(shortOption)) return null;
|
||||
}
|
||||
if (consumesNextToken && tokens[index + 1] === undefined) return null;
|
||||
index += consumesNextToken ? 2 : 1;
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return token.split(/[\\/]/).at(-1) || null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function liveWorkEntryLabel(
|
||||
workEntry: TimelineWorkEntry,
|
||||
workspaceRoot: string | undefined,
|
||||
): string {
|
||||
const command = workEntry.command?.trim();
|
||||
if (command) {
|
||||
const program = commandProgramName(command);
|
||||
const verb =
|
||||
workEntry.toolLifecycleStatus === "completed"
|
||||
? "Ran"
|
||||
: workEntry.toolLifecycleStatus === "failed"
|
||||
? "Failed"
|
||||
: "Running";
|
||||
if (program) return `${verb} ${program}`;
|
||||
return `${verb} command`;
|
||||
}
|
||||
|
||||
return workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
}
|
||||
|
||||
function buildToolCallExpandedBody(
|
||||
workEntry: TimelineWorkEntry,
|
||||
workspaceRoot: string | undefined,
|
||||
): string | null {
|
||||
const command = workEntry.rawCommand?.trim() || workEntry.command?.trim();
|
||||
const blocks: string[] = [];
|
||||
if (command) {
|
||||
blocks.push(command);
|
||||
}
|
||||
if (workEntry.itemType === "mcp_tool_call" && workEntry.toolData !== undefined) {
|
||||
blocks.push(`MCP call\n${JSON.stringify(workEntry.toolData, null, 2)}`);
|
||||
}
|
||||
const raw = workEntryRawCommand(workEntry);
|
||||
if (raw?.trim()) {
|
||||
blocks.push(raw.trim());
|
||||
} else if (workEntry.command?.trim()) {
|
||||
blocks.push(workEntry.command.trim());
|
||||
}
|
||||
if (workEntry.detail?.trim()) {
|
||||
blocks.push(workEntry.detail.trim());
|
||||
const detail = workEntry.detail?.trim();
|
||||
if (detail && detail !== command) {
|
||||
blocks.push(detail);
|
||||
}
|
||||
const changedFiles = workEntry.changedFiles ?? [];
|
||||
if (changedFiles.length > 0) {
|
||||
@@ -2083,6 +2371,7 @@ function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
|
||||
if (workEntry.itemType === "file_change" || (workEntry.changedFiles?.length ?? 0) > 0) {
|
||||
return "square-pen";
|
||||
}
|
||||
if (workLogEntryIsLocalCodeSearch(workEntry)) return "search";
|
||||
if (workEntry.itemType === "web_search") return "globe";
|
||||
if (workEntry.itemType === "image_view") return "eye";
|
||||
|
||||
@@ -2189,71 +2478,94 @@ const AgentSpawnCtaRow = memo(function AgentSpawnCtaRow(props: { workEntry: Time
|
||||
: "working"
|
||||
: failed > 0
|
||||
? `${failed} failed`
|
||||
: "✓ completed";
|
||||
: "Completed";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenAgents}
|
||||
className="-mx-1 flex w-full items-center gap-2 rounded-md border border-border/60 bg-card/50 px-2.5 py-1.5 text-left text-[13px] transition hover:bg-accent/50"
|
||||
>
|
||||
<span aria-hidden className={cn("size-1.5 shrink-0 rounded-full", dotClass)} />
|
||||
<WorkEntryIconSvg name="bot" className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="min-w-0 truncate">
|
||||
<span className="font-medium">{lead}</span>
|
||||
{workflowName ? <span className="text-muted-foreground"> · {workflowName}</span> : null}
|
||||
</span>
|
||||
<span className="ml-auto flex shrink-0 items-center gap-2 font-mono text-[.7rem] text-muted-foreground">
|
||||
<span>{status}</span>
|
||||
{totalTokens > 0 ? (
|
||||
<span className="tabular-nums">Σ {formatSubagentTokenCount(totalTokens)}</span>
|
||||
) : null}
|
||||
<span className="text-info-foreground">{live ? "Open Agents ▸" : "View ▸"}</span>
|
||||
</span>
|
||||
</button>
|
||||
<div className="@container/agent-group -mx-1 rounded-xl border border-border/70 bg-secondary p-1.5 dark:border-transparent dark:bg-input/32">
|
||||
<div className="flex items-center justify-between gap-2 px-1">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5 px-1 py-1 text-left text-xs leading-4">
|
||||
<span className="sr-only @[32rem]/agent-group:hidden">{status}</span>
|
||||
<span aria-hidden className={cn("size-1.5 shrink-0 rounded-full", dotClass)} />
|
||||
<WorkEntryIconSvg name="bot" className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="min-w-0 truncate font-medium text-foreground">{lead}</span>
|
||||
{workflowName ? (
|
||||
<span className="hidden min-w-0 truncate text-[11px] text-muted-foreground @[40rem]/agent-group:inline">
|
||||
{workflowName}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="ml-auto hidden shrink-0 items-center gap-2 text-[11px] text-muted-foreground @[32rem]/agent-group:flex">
|
||||
<span>{status}</span>
|
||||
{totalTokens > 0 ? (
|
||||
<span className="font-mono tabular-nums">
|
||||
Σ {formatSubagentTokenCount(totalTokens)}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</div>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
aria-label={live ? "Open agents" : "View agents"}
|
||||
onClick={onOpenAgents}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<EyeIcon className="size-3" />
|
||||
<span className="hidden @[24rem]/agent-group:inline">
|
||||
{live ? "Open agents" : "View agents"}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{live ? "Open agents" : "View agents"}</TooltipPopup>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: {
|
||||
workEntry: TimelineWorkEntry;
|
||||
workspaceRoot: string | undefined;
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workEntry, workspaceRoot } = props;
|
||||
const { workEntry, workspaceRoot, isExpandedToolGroupEntry } = props;
|
||||
// Before any hooks: spawn CTA rows render their own component.
|
||||
if (workEntry.agentSpawn) {
|
||||
return <AgentSpawnCtaRow workEntry={workEntry} />;
|
||||
}
|
||||
return <PlainWorkEntryRow workEntry={workEntry} workspaceRoot={workspaceRoot} />;
|
||||
return (
|
||||
<PlainWorkEntryRow
|
||||
workEntry={workEntry}
|
||||
workspaceRoot={workspaceRoot}
|
||||
isExpandedToolGroupEntry={isExpandedToolGroupEntry}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
workEntry: TimelineWorkEntry;
|
||||
workspaceRoot: string | undefined;
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workEntry, workspaceRoot } = props;
|
||||
const activity = use(TimelineRowActivityCtx);
|
||||
const { workEntry, workspaceRoot, isExpandedToolGroupEntry } = props;
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const iconConfig = workToneIcon(workEntry.tone);
|
||||
const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning";
|
||||
const entryIconName = showWarningIndicator ? "x" : workEntryIconName(workEntry);
|
||||
const heading = toolWorkEntryHeading(workEntry);
|
||||
const rawPreview = workEntryPreview(workEntry, workspaceRoot);
|
||||
const preview =
|
||||
rawPreview &&
|
||||
normalizeCompactToolLabel(rawPreview).toLowerCase() ===
|
||||
normalizeCompactToolLabel(heading).toLowerCase()
|
||||
? null
|
||||
: rawPreview;
|
||||
const displayText = preview ? `${heading} - ${preview}` : heading;
|
||||
const showFailedIndicator = workEntryIndicatesToolFailure(workEntry);
|
||||
const entryIconName =
|
||||
showWarningIndicator || showFailedIndicator ? "x" : workEntryIconName(workEntry);
|
||||
const displayText = workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
const expandedBody = buildToolCallExpandedBody(workEntry, workspaceRoot);
|
||||
const canExpand = expandedBody !== null;
|
||||
const showFailedIndicator = workEntryIndicatesToolFailure(workEntry);
|
||||
const showDestructiveRowStyle =
|
||||
showFailedIndicator &&
|
||||
(workEntry.sourceActivityKind === "runtime.error" || !workLogEntryIsToolLike(workEntry));
|
||||
const iconWrapperClass = cn(
|
||||
"flex size-5 shrink-0 items-center justify-center",
|
||||
showWarningIndicator
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
showWarningIndicator || showFailedIndicator
|
||||
? "text-destructive"
|
||||
: showDestructiveRowStyle
|
||||
? "text-destructive"
|
||||
@@ -2265,17 +2577,19 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
? "font-medium text-warning"
|
||||
: showDestructiveRowStyle
|
||||
? "font-medium text-destructive"
|
||||
: "font-medium text-foreground";
|
||||
const turnSettled = !activity.activeTurnInProgress;
|
||||
const showNeutralIndicator = !turnSettled && workEntryIndicatesToolNeutralStatus(workEntry);
|
||||
const showSuccessIndicator =
|
||||
workEntryIndicatesToolSuccess(workEntry) ||
|
||||
(turnSettled && workEntryIndicatesToolNeutralStatus(workEntry));
|
||||
: workLogEntryIsToolLike(workEntry)
|
||||
? "text-secondary-label"
|
||||
: "text-foreground/80";
|
||||
const showEntryIcon = !isExpandedToolGroupEntry || showWarningIndicator || showFailedIndicator;
|
||||
const accessibleDisplayText = showFailedIndicator
|
||||
? `${displayText}, tool call failed`
|
||||
: displayText;
|
||||
const rowToggleProps = canExpand
|
||||
? {
|
||||
role: "button" as const,
|
||||
tabIndex: 0 as const,
|
||||
"aria-label": displayText,
|
||||
"aria-label": accessibleDisplayText,
|
||||
"aria-expanded": expanded,
|
||||
onClick: () => setExpanded((v) => !v),
|
||||
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
@@ -2289,90 +2603,41 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col rounded-md px-0.5 py-0.5 transition-colors",
|
||||
"flex flex-col rounded-md px-0.5 transition-colors",
|
||||
isExpandedToolGroupEntry ? "py-0" : "py-0.5",
|
||||
canExpand &&
|
||||
"cursor-pointer hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
|
||||
)}
|
||||
{...rowToggleProps}
|
||||
>
|
||||
<div className="flex select-none items-center gap-1.5 transition-[opacity,translate] duration-200">
|
||||
<span className={iconWrapperClass}>
|
||||
<span
|
||||
className={cn(iconWrapperClass, !showEntryIcon && "invisible")}
|
||||
role={showFailedIndicator ? "img" : undefined}
|
||||
aria-label={showFailedIndicator ? "Tool call failed" : undefined}
|
||||
aria-hidden={!showEntryIcon}
|
||||
>
|
||||
<WorkEntryIconSvg
|
||||
name={entryIconName}
|
||||
className="block size-3.5 shrink-0 stroke-[1.8] opacity-80"
|
||||
className="block size-4 shrink-0 stroke-[1.8] opacity-70"
|
||||
/>
|
||||
</span>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<div className="min-w-0 flex-1 overflow-hidden">
|
||||
<p className="flex min-w-0 w-full items-baseline gap-1.5 text-[12px] leading-5">
|
||||
<span className={cn("min-w-0 shrink truncate", headingClass)}>{heading}</span>
|
||||
{preview && (
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-label">{preview}</span>
|
||||
<p
|
||||
className={cn(
|
||||
"flex min-w-0 w-full items-baseline gap-1.5 leading-relaxed",
|
||||
isExpandedToolGroupEntry ? "text-[12px] leading-5" : "text-sm",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-px text-icon-muted">
|
||||
<span
|
||||
className="flex size-4 shrink-0 items-center justify-center"
|
||||
aria-hidden={!canExpand}
|
||||
>
|
||||
{canExpand ? (
|
||||
<ChevronDownIcon
|
||||
className={cn(
|
||||
"size-3 shrink-0 opacity-70 transition-transform duration-200",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="flex size-4 shrink-0 items-center justify-center">
|
||||
{showFailedIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
className="flex size-4 items-center justify-center"
|
||||
aria-label="Tool call failed"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<XIcon className="block size-3 shrink-0 text-destructive" aria-hidden />
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Failed</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : showSuccessIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="flex size-4 items-center justify-center" />}
|
||||
>
|
||||
<span className="inline-flex size-4 items-center justify-center">
|
||||
<CheckIcon
|
||||
className="block size-3 shrink-0 stroke-current"
|
||||
stroke="currentColor"
|
||||
aria-hidden
|
||||
/>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Completed</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : showNeutralIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="flex size-4 items-center justify-center" />}
|
||||
>
|
||||
<MinusIcon className="block size-3 shrink-0 opacity-70" aria-hidden />
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Empty</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</span>
|
||||
<span className={cn("min-w-0 flex-1 truncate", headingClass)}>{displayText}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{expanded && canExpand && expandedBody ? (
|
||||
<div
|
||||
className="mt-1 ms-7 cursor-default border-s border-border/45 ps-3 pt-0.5"
|
||||
className="mt-1 ms-[1.875rem] cursor-default pt-0.5"
|
||||
onClick={stopRowToggle}
|
||||
onPointerDown={stopRowToggle}
|
||||
>
|
||||
|
||||
@@ -11,7 +11,20 @@ describe("ThreadSyncStatusPill", () => {
|
||||
const markup = renderToStaticMarkup(<ThreadSyncStatusPill phase={phase} />);
|
||||
|
||||
expect(markup).toContain('role="status"');
|
||||
expect(markup).toContain('data-thread-sync-drawer="true"');
|
||||
expect(markup).toContain("chat-composer-drawer-surface");
|
||||
expect(markup).toContain("chat-composer-drawer-attached");
|
||||
expect(markup).toContain("chat-composer-drawer-slot");
|
||||
expect(markup).toContain(label);
|
||||
expect(markup).not.toContain("animate-");
|
||||
});
|
||||
|
||||
it("renders as a detached status when the composer owns the attachment seam", () => {
|
||||
const markup = renderToStaticMarkup(<ThreadSyncStatusPill attached={false} phase="syncing" />);
|
||||
|
||||
expect(markup).toContain("alert-glass");
|
||||
expect(markup).toContain("mb-2");
|
||||
expect(markup).not.toContain("chat-composer-drawer-attached");
|
||||
expect(markup).not.toContain("chat-composer-drawer-slot");
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,27 @@
|
||||
import { LoaderCircleIcon } from "lucide-react";
|
||||
|
||||
import { threadSyncLabel, type ThreadSyncPhase } from "../../threadSync";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
export function ThreadSyncStatusPill({ phase }: { readonly phase: ThreadSyncPhase }) {
|
||||
export function ThreadSyncStatusPill({
|
||||
attached = true,
|
||||
phase,
|
||||
}: {
|
||||
readonly attached?: boolean;
|
||||
readonly phase: ThreadSyncPhase;
|
||||
}) {
|
||||
const label = threadSyncLabel(phase);
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-label={label}
|
||||
className="pointer-events-none mx-auto mb-2 flex w-fit max-w-full items-center gap-2 rounded-full border border-border/60 bg-card/95 px-3 py-1.5 text-foreground text-xs font-medium shadow-sm"
|
||||
className={cn(
|
||||
"pointer-events-none flex max-w-[calc(48rem-2.75rem)] items-center gap-2 px-3 text-foreground text-xs font-medium",
|
||||
attached
|
||||
? "chat-composer-drawer-surface chat-composer-drawer-attached chat-composer-drawer-slot pt-2"
|
||||
: "alert-glass mx-auto mb-2 w-[calc(100%-2.75rem)] rounded-[22px] py-2",
|
||||
)}
|
||||
data-thread-sync-drawer="true"
|
||||
role="status"
|
||||
>
|
||||
<LoaderCircleIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
changedFileName,
|
||||
selectChangedFilePreview,
|
||||
shouldAutoExpandChangedFiles,
|
||||
summarizeChangedFileScopes,
|
||||
} from "./changedFilesPresentation";
|
||||
|
||||
describe("changed-files presentation", () => {
|
||||
@@ -35,22 +34,6 @@ describe("changed-files presentation", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("summarizes the most prominent top-level scopes", () => {
|
||||
const files = [
|
||||
{ path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "README.md", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "apps/server/src/index.ts", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "packages/shared/src/git.ts", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "apps\\mobile\\App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
];
|
||||
|
||||
expect(summarizeChangedFileScopes(files)).toEqual([
|
||||
{ label: "apps", fileCount: 3 },
|
||||
{ label: "root", fileCount: 1 },
|
||||
{ label: "packages", fileCount: 1 },
|
||||
]);
|
||||
});
|
||||
|
||||
it("previews files across different scopes before filling from one scope", () => {
|
||||
const files = [
|
||||
{ path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
|
||||
@@ -4,12 +4,6 @@ import { summarizeTurnDiffStats } from "../../lib/turnDiffTree";
|
||||
export const CHANGED_FILES_AUTO_EXPAND_FILE_LIMIT = 5;
|
||||
export const CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT = 200;
|
||||
export const CHANGED_FILES_PREVIEW_FILE_LIMIT = 3;
|
||||
export const CHANGED_FILES_PREVIEW_SCOPE_LIMIT = 4;
|
||||
|
||||
export interface ChangedFilesScopeSummary {
|
||||
readonly label: string;
|
||||
readonly fileCount: number;
|
||||
}
|
||||
|
||||
function pathSegments(pathValue: string): string[] {
|
||||
return pathValue
|
||||
@@ -38,35 +32,6 @@ export function shouldAutoExpandChangedFiles(
|
||||
return stat.additions + stat.deletions <= CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT;
|
||||
}
|
||||
|
||||
export function summarizeChangedFileScopes(
|
||||
files: ReadonlyArray<TurnDiffFileChange>,
|
||||
limit = CHANGED_FILES_PREVIEW_SCOPE_LIMIT,
|
||||
): ChangedFilesScopeSummary[] {
|
||||
const scopes = new Map<string, { fileCount: number; firstIndex: number }>();
|
||||
files.forEach((file, index) => {
|
||||
const label = changedFileScope(file.path);
|
||||
const current = scopes.get(label);
|
||||
scopes.set(label, {
|
||||
fileCount: (current?.fileCount ?? 0) + 1,
|
||||
firstIndex: current?.firstIndex ?? index,
|
||||
});
|
||||
});
|
||||
|
||||
return Array.from(scopes, ([label, scope]) => ({
|
||||
label,
|
||||
fileCount: scope.fileCount,
|
||||
firstIndex: scope.firstIndex,
|
||||
}))
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
right.fileCount - left.fileCount ||
|
||||
left.firstIndex - right.firstIndex ||
|
||||
left.label.localeCompare(right.label),
|
||||
)
|
||||
.slice(0, limit)
|
||||
.map(({ label, fileCount }) => ({ label, fileCount }));
|
||||
}
|
||||
|
||||
export function selectChangedFilePreview(
|
||||
files: ReadonlyArray<TurnDiffFileChange>,
|
||||
limit = CHANGED_FILES_PREVIEW_FILE_LIMIT,
|
||||
|
||||
@@ -30,7 +30,7 @@ const buttonVariants = cva(
|
||||
"size-7 sm:size-6 not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-4 sm:not-in-data-[slot=input-group]:[&_svg:not([class*='size-'])]:size-3.5",
|
||||
lg: "h-10 px-[calc(--spacing(3.5)-1px)] sm:h-9",
|
||||
micro:
|
||||
"h-5 gap-1 rounded-sm px-[calc(--spacing(1.5)-1px)] text-xs before:rounded-[calc(var(--radius-sm)-1px)] [&_svg:not([class*='size-'])]:size-3",
|
||||
"h-5 gap-1 rounded-sm px-[calc(--spacing(1.5)-1px)] text-[11px] before:rounded-[calc(var(--radius-sm)-1px)] sm:text-[11px] [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:h-7",
|
||||
xl: "h-11 px-[calc(--spacing(4)-1px)] text-lg sm:h-10 sm:text-base [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-4.5",
|
||||
xs: "h-7 gap-1 px-[calc(--spacing(2)-1px)] text-sm sm:h-6 sm:text-xs [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import { type PointerEvent as ReactPointerEvent, useCallback, useRef, useState } from "react";
|
||||
|
||||
import { getLocalStorageItem, setLocalStorageItem } from "./useLocalStorage";
|
||||
import { useLocalStorage } from "./useLocalStorage";
|
||||
|
||||
const WidthSchema = Schema.Finite;
|
||||
|
||||
@@ -28,12 +28,10 @@ export interface ResizableWidthHandlers {
|
||||
|
||||
/**
|
||||
* Width state for a side-anchored panel resized via a drag handle on the
|
||||
* specified edge. Width is read from localStorage on mount and persisted on
|
||||
* drag-end (not on every rAF tick — would otherwise be ~60 writes/sec).
|
||||
* specified edge. Mounted consumers sharing a storage key stay synchronized.
|
||||
*
|
||||
* The hook updates an internal `width` state during drag (so the panel
|
||||
* follows the cursor live) and only commits to localStorage when the user
|
||||
* lifts the pointer.
|
||||
* The hook keeps drag width local so the panel follows the cursor without
|
||||
* writing at rAF frequency, then commits once when the pointer lifts.
|
||||
*/
|
||||
export function useResizableWidth(options: UseResizableWidthOptions): {
|
||||
readonly width: number;
|
||||
@@ -49,19 +47,9 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
|
||||
[defaultWidth, maxWidth, minWidth],
|
||||
);
|
||||
|
||||
// No cross-tab subscription: panel width is per-window state.
|
||||
const [width, setWidth] = useState<number>(() => {
|
||||
if (typeof window === "undefined") return defaultWidth;
|
||||
try {
|
||||
const stored = getLocalStorageItem(storageKey, WidthSchema);
|
||||
return clamp(stored ?? defaultWidth);
|
||||
} catch (error) {
|
||||
console.error("Could not read persisted panel width.", error);
|
||||
return defaultWidth;
|
||||
}
|
||||
});
|
||||
|
||||
const clampedWidth = clamp(width);
|
||||
const [storedWidth, setStoredWidth] = useLocalStorage(storageKey, defaultWidth, WidthSchema);
|
||||
const [dragWidth, setDragWidth] = useState<number | null>(null);
|
||||
const clampedWidth = clamp(dragWidth ?? storedWidth);
|
||||
|
||||
const dragStateRef = useRef<{
|
||||
pointerId: number;
|
||||
@@ -127,7 +115,7 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
|
||||
const active = dragStateRef.current;
|
||||
if (!active) return;
|
||||
active.rafId = null;
|
||||
setWidth(active.pending);
|
||||
setDragWidth(active.pending);
|
||||
});
|
||||
},
|
||||
[clamp, edge],
|
||||
@@ -139,24 +127,19 @@ export function useResizableWidth(options: UseResizableWidthOptions): {
|
||||
if (!state || state.pointerId !== event.pointerId) return;
|
||||
const finalWidth = clamp(state.pending);
|
||||
releasePointer(event.pointerId);
|
||||
// Commit once at drag-end to avoid 60Hz localStorage writes.
|
||||
try {
|
||||
setLocalStorageItem(storageKey, finalWidth, WidthSchema);
|
||||
} catch (error) {
|
||||
console.error("Could not persist panel width.", error);
|
||||
}
|
||||
setWidth(finalWidth);
|
||||
setStoredWidth(finalWidth);
|
||||
setDragWidth(null);
|
||||
},
|
||||
[clamp, releasePointer, storageKey],
|
||||
[clamp, releasePointer, setStoredWidth],
|
||||
);
|
||||
|
||||
const onPointerCancel = useCallback(
|
||||
(event: ReactPointerEvent<HTMLElement>) => {
|
||||
const state = dragStateRef.current;
|
||||
if (!state || state.pointerId !== event.pointerId) return;
|
||||
// Don't persist a cancelled drag; revert to the start width.
|
||||
// Don't persist a cancelled drag; use the latest shared stored width.
|
||||
releasePointer(event.pointerId);
|
||||
setWidth(state.startWidth);
|
||||
setDragWidth(null);
|
||||
},
|
||||
[releasePointer],
|
||||
);
|
||||
|
||||
+311
-2
@@ -431,6 +431,80 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes live-activity-focus {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes live-activity-focus-counter {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus {
|
||||
--live-activity-focus-width: 4.5rem;
|
||||
|
||||
right: auto;
|
||||
left: calc(-1 * var(--live-activity-focus-width));
|
||||
width: calc(100% + var(--live-activity-focus-width) + var(--live-activity-focus-width));
|
||||
-webkit-mask-image: linear-gradient(
|
||||
to right,
|
||||
transparent 0,
|
||||
rgb(0 0 0 / 12%) 0.675rem,
|
||||
rgb(0 0 0 / 55%) 1.575rem,
|
||||
black 2.25rem,
|
||||
rgb(0 0 0 / 55%) 2.925rem,
|
||||
rgb(0 0 0 / 12%) 3.825rem,
|
||||
transparent var(--live-activity-focus-width),
|
||||
transparent 100%
|
||||
);
|
||||
-webkit-mask-repeat: no-repeat;
|
||||
mask-image: linear-gradient(
|
||||
to right,
|
||||
transparent 0,
|
||||
rgb(0 0 0 / 12%) 0.675rem,
|
||||
rgb(0 0 0 / 55%) 1.575rem,
|
||||
black 2.25rem,
|
||||
rgb(0 0 0 / 55%) 2.925rem,
|
||||
rgb(0 0 0 / 12%) 3.825rem,
|
||||
transparent var(--live-activity-focus-width),
|
||||
transparent 100%
|
||||
);
|
||||
mask-repeat: no-repeat;
|
||||
animation: live-activity-focus 2.2s steps(24) infinite;
|
||||
will-change: transform;
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
animation: none;
|
||||
opacity: 0;
|
||||
will-change: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus-counter {
|
||||
width: 100%;
|
||||
animation: live-activity-focus-counter 2.2s steps(24) infinite;
|
||||
will-change: transform;
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
animation: none;
|
||||
will-change: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus-aligned {
|
||||
width: calc(100% - var(--live-activity-focus-width) - var(--live-activity-focus-width));
|
||||
margin-left: var(--live-activity-focus-width);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
/* Keep the original T3 Code artwork palettes as the defaults. Built-in
|
||||
@@ -680,7 +754,144 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.chat-composer-stash-tab {
|
||||
border-color: var(
|
||||
--chat-composer-outline,
|
||||
color-mix(in srgb, var(--foreground) 8%, transparent)
|
||||
);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--chat-composer-glass-surface, var(--card)) var(--glass-opacity),
|
||||
transparent
|
||||
);
|
||||
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
box-shadow: 0 -8px 24px -18px rgb(0 0 0 / 45%);
|
||||
|
||||
@variant dark {
|
||||
box-shadow: 0 -10px 28px -18px rgb(0 0 0 / 80%);
|
||||
}
|
||||
|
||||
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
|
||||
background: var(--chat-composer-glass-surface, var(--card));
|
||||
}
|
||||
}
|
||||
|
||||
/* Mirror the run-context strip above the composer. These surfaces deliberately
|
||||
own no card fill or border themselves: a masked pseudo-element draws the
|
||||
same inset glass, 16px outer corners, quiet outline, and open attachment
|
||||
seam as the strip below. */
|
||||
.chat-composer-drawer-surface,
|
||||
.chat-composer-top-drawer {
|
||||
--chat-composer-attachment-overlap: calc(1rem + 1px);
|
||||
--chat-composer-attached-surface: var(--chat-composer-glass-surface, var(--card));
|
||||
--chat-composer-attached-outline: var(
|
||||
--chat-composer-outline,
|
||||
color-mix(in srgb, var(--foreground) 8%, transparent)
|
||||
);
|
||||
--chat-composer-attached-tint: transparent;
|
||||
position: relative;
|
||||
isolation: isolate;
|
||||
border: 0 !important;
|
||||
background: transparent !important;
|
||||
box-shadow: none;
|
||||
|
||||
@variant dark {
|
||||
--chat-composer-attached-surface: var(
|
||||
--chat-composer-glass-surface,
|
||||
color-mix(in srgb, var(--background) 96%, var(--color-white))
|
||||
);
|
||||
--chat-composer-attached-outline: var(
|
||||
--chat-composer-outline,
|
||||
color-mix(in srgb, var(--color-white) 5%, transparent)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
.chat-composer-drawer-attached,
|
||||
.chat-composer-top-drawer {
|
||||
padding-bottom: var(--chat-composer-attachment-overlap);
|
||||
}
|
||||
|
||||
.chat-composer-drawer-slot,
|
||||
.chat-composer-top-drawer {
|
||||
--chat-composer-attachment-overlap: calc(1rem + 1px);
|
||||
width: calc(100% - 2.75rem);
|
||||
margin-inline: auto;
|
||||
margin-bottom: calc(-1 * var(--chat-composer-attachment-overlap));
|
||||
}
|
||||
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer)::before {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
inset: 0;
|
||||
border: 1px solid var(--chat-composer-attached-outline);
|
||||
border-radius: 16px 16px 0 0;
|
||||
background:
|
||||
linear-gradient(var(--chat-composer-attached-tint), var(--chat-composer-attached-tint)),
|
||||
color-mix(in srgb, var(--chat-composer-attached-surface) var(--glass-opacity), transparent);
|
||||
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
-webkit-mask-image: linear-gradient(
|
||||
to top,
|
||||
transparent 0 var(--chat-composer-attachment-overlap),
|
||||
black var(--chat-composer-attachment-overlap)
|
||||
);
|
||||
mask-image: linear-gradient(
|
||||
to top,
|
||||
transparent 0 var(--chat-composer-attachment-overlap),
|
||||
black var(--chat-composer-attachment-overlap)
|
||||
);
|
||||
box-shadow: 0 12px 28px -18px rgb(0 0 0 / 40%);
|
||||
content: "";
|
||||
|
||||
@variant dark {
|
||||
background:
|
||||
linear-gradient(var(--chat-composer-attached-tint), var(--chat-composer-attached-tint)),
|
||||
linear-gradient(
|
||||
to top,
|
||||
transparent 0 var(--chat-composer-attachment-overlap),
|
||||
rgb(0 0 0 / 18%) var(--chat-composer-attachment-overlap),
|
||||
transparent calc(var(--chat-composer-attachment-overlap) + 10px)
|
||||
),
|
||||
color-mix(in srgb, var(--chat-composer-attached-surface) var(--glass-opacity), transparent);
|
||||
box-shadow: 0 14px 32px -18px rgb(0 0 0 / 75%);
|
||||
}
|
||||
|
||||
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
|
||||
background:
|
||||
linear-gradient(var(--chat-composer-attached-tint), var(--chat-composer-attached-tint)),
|
||||
var(--chat-composer-attached-surface);
|
||||
}
|
||||
}
|
||||
|
||||
.chat-composer-top-drawer {
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer)[data-variant="error"] {
|
||||
--chat-composer-attached-outline: color-mix(in srgb, var(--error) 32%, transparent);
|
||||
--chat-composer-attached-tint: color-mix(in srgb, var(--error) 8%, transparent);
|
||||
}
|
||||
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer)[data-variant="info"] {
|
||||
--chat-composer-attached-outline: color-mix(in srgb, var(--info) 32%, transparent);
|
||||
--chat-composer-attached-tint: color-mix(in srgb, var(--info) 4%, transparent);
|
||||
}
|
||||
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer)[data-variant="success"] {
|
||||
--chat-composer-attached-outline: color-mix(in srgb, var(--success) 32%, transparent);
|
||||
--chat-composer-attached-tint: color-mix(in srgb, var(--success) 4%, transparent);
|
||||
}
|
||||
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer)[data-variant="warning"] {
|
||||
--chat-composer-attached-outline: color-mix(in srgb, var(--warning) 28%, transparent);
|
||||
--chat-composer-attached-tint: color-mix(in srgb, var(--warning) 8%, transparent);
|
||||
}
|
||||
|
||||
.chat-composer-glass-shell {
|
||||
--chat-composer-attachment-overlap: calc(1rem + 1px);
|
||||
--chat-composer-glass-surface: var(--card);
|
||||
--chat-composer-outline: rgb(0 0 0 / 8%);
|
||||
|
||||
@@ -775,7 +986,63 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
content: "";
|
||||
}
|
||||
|
||||
.chat-composer-glass-shell-with-context .chat-composer-glass-host::after {
|
||||
/* A top attachment cannot share the shell's single clipped backdrop: it
|
||||
needs the composer surface and outline to paint in front of its overlap.
|
||||
Split the glass into exact surfaces while a drawer or tab is present; the
|
||||
default composer keeps the cheaper continuous layer. */
|
||||
.chat-composer-glass-shell:has(:is(.chat-composer-top-drawer, .chat-composer-stash-tab))::before,
|
||||
.chat-composer-glass-host:has(:is(.chat-composer-top-drawer, .chat-composer-stash-tab))::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chat-composer-glass-host:has(:is(.chat-composer-top-drawer, .chat-composer-stash-tab)) {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.chat-composer-glass-host:has(:is(.chat-composer-top-drawer, .chat-composer-stash-tab))
|
||||
[data-chat-composer-main-surface="true"] {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--chat-composer-glass-surface) var(--glass-opacity),
|
||||
transparent
|
||||
);
|
||||
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
box-shadow: 0 12px 28px -18px rgb(0 0 0 / 40%);
|
||||
|
||||
&::after {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
z-index: 20;
|
||||
inset: 0;
|
||||
border: 1px solid var(--chat-composer-outline);
|
||||
border-radius: inherit;
|
||||
content: "";
|
||||
}
|
||||
|
||||
@variant dark {
|
||||
box-shadow: none;
|
||||
|
||||
&::after {
|
||||
box-shadow: inset 0 1px var(--chat-composer-highlight);
|
||||
}
|
||||
}
|
||||
|
||||
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
|
||||
background: var(--chat-composer-glass-surface);
|
||||
}
|
||||
}
|
||||
|
||||
.chat-composer-glass-host:has(.chat-composer-top-drawer)
|
||||
[data-chat-composer-mobile-collapsed="true"] {
|
||||
min-height: var(--chat-composer-attachment-overlap);
|
||||
}
|
||||
|
||||
.chat-composer-glass-shell-with-context .chat-composer-glass-host::after,
|
||||
.chat-composer-glass-shell-with-context:has(
|
||||
:is(.chat-composer-top-drawer, .chat-composer-stash-tab)
|
||||
)
|
||||
[data-chat-composer-main-surface="true"]::after {
|
||||
/* Keep the attachment seam open; the strip continues the outer outline below. */
|
||||
clip-path: polygon(
|
||||
0 0,
|
||||
@@ -822,6 +1089,29 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
content: "";
|
||||
}
|
||||
|
||||
.chat-composer-glass-shell:has(:is(.chat-composer-top-drawer, .chat-composer-stash-tab))
|
||||
.chat-composer-context-strip::before {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--chat-composer-glass-surface) var(--glass-opacity),
|
||||
transparent
|
||||
);
|
||||
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
|
||||
@variant dark {
|
||||
background:
|
||||
linear-gradient(
|
||||
to bottom,
|
||||
transparent 0 1rem,
|
||||
rgb(0 0 0 / 18%) 1rem,
|
||||
transparent calc(1rem + 10px)
|
||||
),
|
||||
linear-gradient(rgb(255 255 255 / 2%), rgb(255 255 255 / 2%)),
|
||||
color-mix(in srgb, var(--chat-composer-glass-surface) var(--glass-opacity), transparent);
|
||||
}
|
||||
}
|
||||
|
||||
@supports not (clip-path: shape(from 0 0, line to 1px 1px)) {
|
||||
.chat-composer-glass-shell-with-context::before {
|
||||
inset-block-end: var(--chat-composer-context-extension);
|
||||
@@ -1255,6 +1545,26 @@ html[data-theme-id] .chat-composer-glass-shell {
|
||||
}
|
||||
}
|
||||
|
||||
html[data-theme-id] :is(.chat-composer-drawer-surface, .chat-composer-top-drawer) {
|
||||
--chat-composer-attached-surface: var(--app-theme-surface-raised);
|
||||
}
|
||||
|
||||
html[data-theme-id]
|
||||
:is(.chat-composer-drawer-surface, .chat-composer-top-drawer):is(
|
||||
:not([data-variant]),
|
||||
[data-variant="default"]
|
||||
) {
|
||||
--chat-composer-attached-outline: var(--app-theme-toolbar-border);
|
||||
|
||||
@variant dark {
|
||||
--chat-composer-attached-outline: color-mix(
|
||||
in srgb,
|
||||
var(--app-theme-input) 30%,
|
||||
var(--background)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
html[data-theme-id="t3-chat"] .chat-composer-glass-shell {
|
||||
/* T3 Chat's visible composer edge is a dark plum, not the stock translucent
|
||||
white outline. Its highlight is derived from --chat-input-gradient. */
|
||||
@@ -1934,7 +2244,6 @@ code {
|
||||
#ff6b6b 100%
|
||||
);
|
||||
position: relative;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.ultrathink-frame::before {
|
||||
|
||||
@@ -722,24 +722,214 @@ describe("workEntryIndicatesToolFailure", () => {
|
||||
});
|
||||
|
||||
describe("deriveWorkLogEntries", () => {
|
||||
it("omits tool started entries and keeps completed entries", () => {
|
||||
it("shows a command from its start event while it is still running", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "tool-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Tool call complete",
|
||||
kind: "tool.completed",
|
||||
}),
|
||||
makeActivity({
|
||||
id: "tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Tool call",
|
||||
summary: "Command run started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "inProgress",
|
||||
title: "Command run",
|
||||
detail: "Bash: vp test run",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const [entry] = deriveWorkLogEntries(activities);
|
||||
expect(entry).toMatchObject({
|
||||
id: "tool-start",
|
||||
command: "vp test run",
|
||||
toolCallId: "call-1",
|
||||
toolLifecycleStatus: "inProgress",
|
||||
sourceActivityKind: "tool.started",
|
||||
});
|
||||
});
|
||||
|
||||
it("retains the start command when the matching completion omits it", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Command run started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "inProgress",
|
||||
title: "Command run",
|
||||
data: { input: { command: "vp test run" } },
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "other-tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.500Z",
|
||||
summary: "Other command started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-2",
|
||||
status: "inProgress",
|
||||
title: "Other command",
|
||||
data: { input: { command: "vp lint" } },
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "tool-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Command run",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "completed",
|
||||
title: "Command run",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "other-tool-complete",
|
||||
createdAt: "2026-02-23T00:00:04.000Z",
|
||||
summary: "Other command",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-2",
|
||||
status: "completed",
|
||||
title: "Other command",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const entries = deriveWorkLogEntries(activities);
|
||||
expect(entries.map((entry) => entry.id)).toEqual(["tool-complete"]);
|
||||
expect(entries).toHaveLength(2);
|
||||
expect(entries[0]).toMatchObject({
|
||||
id: "tool-complete",
|
||||
command: "vp test run",
|
||||
toolCallId: "call-1",
|
||||
toolLifecycleStatus: "completed",
|
||||
sourceActivityKind: "tool.completed",
|
||||
});
|
||||
expect(entries[1]).toMatchObject({
|
||||
id: "other-tool-complete",
|
||||
command: "vp lint",
|
||||
toolCallId: "call-2",
|
||||
toolLifecycleStatus: "completed",
|
||||
sourceActivityKind: "tool.completed",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not merge non-adjacent tool starts without stable call ids", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "unkeyed-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
makeActivity({
|
||||
id: "keyed-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Command started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-between",
|
||||
title: "Command",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "unkeyed-start-2",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"unkeyed-start-1",
|
||||
"keyed-start",
|
||||
"unkeyed-start-2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not merge adjacent tool starts without stable call ids", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "unkeyed-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
makeActivity({
|
||||
id: "unkeyed-start-2",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"unkeyed-start-1",
|
||||
"unkeyed-start-2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not assign an unkeyed completion to an adjacent concurrent start", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "search-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
toolCallId: "search-call-1",
|
||||
title: "Search",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "search-start-2",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
toolCallId: "search-call-2",
|
||||
title: "Search",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "legacy-search-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Search",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
title: "Search",
|
||||
status: "completed",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"search-start-1",
|
||||
"search-start-2",
|
||||
"legacy-search-complete",
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits task.started but shows task.progress and task.completed", () => {
|
||||
@@ -1239,6 +1429,7 @@ describe("deriveWorkLogEntries", () => {
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0]).toMatchObject({
|
||||
id: "grep-complete",
|
||||
toolCallId: "tool-grep-1",
|
||||
toolTitle: "grep",
|
||||
detail: "19 files",
|
||||
itemType: "web_search",
|
||||
|
||||
@@ -65,6 +65,8 @@ export interface WorkLogEntry {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
turnId?: TurnId | null;
|
||||
/** Stable provider identity across in-progress and completed lifecycle updates. */
|
||||
toolCallId?: string;
|
||||
label: string;
|
||||
detail?: string;
|
||||
command?: string;
|
||||
@@ -748,7 +750,6 @@ export function deriveWorkLogEntries(
|
||||
const ordered = [...activities].toSorted(compareActivitiesByOrder);
|
||||
const entries: DerivedWorkLogEntry[] = [];
|
||||
for (const activity of ordered) {
|
||||
if (activity.kind === "tool.started") continue;
|
||||
// Agent task.started rows are CTA seeds: they carry the true spawn turn,
|
||||
// which is the batch key (completions of background subagents arrive
|
||||
// under later synthetic turns and must not start new batches). They
|
||||
@@ -757,8 +758,13 @@ export function deriveWorkLogEntries(
|
||||
if (activity.kind === "task.updated") continue;
|
||||
if (activity.kind === "tool.progress") continue;
|
||||
if (activity.kind === "context-window.updated") continue;
|
||||
// Plan updates have a dedicated task row. Keeping the raw activity here
|
||||
// duplicates it as a legacy "Work Log / Plan updated" row when history
|
||||
// is expanded.
|
||||
if (activity.kind === "turn.plan.updated") continue;
|
||||
if (activity.summary === "Checkpoint captured") continue;
|
||||
if (isPlanBoundaryToolActivity(activity)) continue;
|
||||
if (isCodexTerminalInteractionActivity(activity)) continue;
|
||||
if (isAgentInternalActivity(activity)) continue;
|
||||
entries.push(toDerivedWorkLogEntry(activity));
|
||||
}
|
||||
@@ -769,7 +775,11 @@ export function deriveWorkLogEntries(
|
||||
}
|
||||
|
||||
function isPlanBoundaryToolActivity(activity: OrchestrationThreadActivity): boolean {
|
||||
if (activity.kind !== "tool.updated" && activity.kind !== "tool.completed") {
|
||||
if (
|
||||
activity.kind !== "tool.started" &&
|
||||
activity.kind !== "tool.updated" &&
|
||||
activity.kind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -780,6 +790,28 @@ function isPlanBoundaryToolActivity(activity: OrchestrationThreadActivity): bool
|
||||
return typeof payload?.detail === "string" && payload.detail.startsWith("ExitPlanMode:");
|
||||
}
|
||||
|
||||
/**
|
||||
* Codex terminal interactions report bytes written to an already-running PTY.
|
||||
* Some thread histories contain them as generic tool.updated rows, so filter
|
||||
* their exact wire shape from the presentation model. This repairs existing
|
||||
* history without deleting or rewriting persisted activities.
|
||||
*/
|
||||
function isCodexTerminalInteractionActivity(activity: OrchestrationThreadActivity): boolean {
|
||||
if (activity.kind !== "tool.updated") {
|
||||
return false;
|
||||
}
|
||||
const payload = asRecord(activity.payload);
|
||||
const data = asRecord(payload?.data);
|
||||
return (
|
||||
payload?.itemType === "command_execution" &&
|
||||
typeof data?.itemId === "string" &&
|
||||
typeof data.processId === "string" &&
|
||||
typeof data.stdin === "string" &&
|
||||
typeof data.threadId === "string" &&
|
||||
typeof data.turnId === "string"
|
||||
);
|
||||
}
|
||||
|
||||
function extractWorkLogToolLifecycleStatus(
|
||||
payload: Record<string, unknown> | null,
|
||||
): WorkLogToolLifecycleStatus | undefined {
|
||||
@@ -878,6 +910,9 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
|
||||
entry.toolCallId = toolCallId;
|
||||
}
|
||||
let toolLifecycleStatus = extractWorkLogToolLifecycleStatus(payload);
|
||||
if (!toolLifecycleStatus && activity.kind === "tool.started") {
|
||||
toolLifecycleStatus = "inProgress";
|
||||
}
|
||||
if (!toolLifecycleStatus && activity.kind === "tool.completed") {
|
||||
toolLifecycleStatus = "completed";
|
||||
}
|
||||
@@ -933,6 +968,17 @@ function agentSpawnGroupKey(entry: DerivedWorkLogEntry): string {
|
||||
return entry.turnId ? `direct:${entry.turnId}` : `direct:task:${taskId}`;
|
||||
}
|
||||
|
||||
function toolLifecycleCollapseMapKey(entry: DerivedWorkLogEntry): string | undefined {
|
||||
if (
|
||||
entry.activityKind !== "tool.started" &&
|
||||
entry.activityKind !== "tool.updated" &&
|
||||
entry.activityKind !== "tool.completed"
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return entry.toolCallId ? `tool:${entry.toolCallId}` : undefined;
|
||||
}
|
||||
|
||||
function collapseDerivedWorkLogEntries(
|
||||
entries: ReadonlyArray<DerivedWorkLogEntry>,
|
||||
): DerivedWorkLogEntry[] {
|
||||
@@ -949,6 +995,7 @@ function collapseDerivedWorkLogEntries(
|
||||
// own turn splintered one batch into a stream of "Kicked off N subagents"
|
||||
// rows (live-test finding, thread 7ac7ef05).
|
||||
const groupKeyByTaskId = new Map<string, string>();
|
||||
const toolLifecycleRowIndex = new Map<string, number>();
|
||||
for (const entry of entries) {
|
||||
const isTaskRow =
|
||||
entry.taskId !== undefined &&
|
||||
@@ -993,12 +1040,40 @@ function collapseDerivedWorkLogEntries(
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const lifecycleKey = toolLifecycleCollapseMapKey(entry);
|
||||
if (lifecycleKey !== undefined) {
|
||||
const matchingLifecycleIndex = toolLifecycleRowIndex.get(lifecycleKey);
|
||||
if (matchingLifecycleIndex !== undefined) {
|
||||
const matchingEntry = collapsed[matchingLifecycleIndex];
|
||||
if (matchingEntry && shouldCollapseToolLifecycleEntries(matchingEntry, entry)) {
|
||||
toolLifecycleRowIndex.delete(lifecycleKey);
|
||||
const merged = mergeDerivedWorkLogEntries(matchingEntry, entry);
|
||||
collapsed[matchingLifecycleIndex] = merged;
|
||||
if (merged.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(lifecycleKey, matchingLifecycleIndex);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
toolLifecycleRowIndex.delete(lifecycleKey);
|
||||
}
|
||||
}
|
||||
const previous = collapsed.at(-1);
|
||||
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
|
||||
collapsed[collapsed.length - 1] = mergeDerivedWorkLogEntries(previous, entry);
|
||||
const previousIndex = collapsed.length - 1;
|
||||
const previousKey = toolLifecycleCollapseMapKey(previous);
|
||||
if (previousKey !== undefined) toolLifecycleRowIndex.delete(previousKey);
|
||||
const merged = mergeDerivedWorkLogEntries(previous, entry);
|
||||
collapsed[previousIndex] = merged;
|
||||
const mergedKey = toolLifecycleCollapseMapKey(merged);
|
||||
if (mergedKey !== undefined && merged.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(mergedKey, previousIndex);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
collapsed.push(entry);
|
||||
if (lifecycleKey !== undefined && entry.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(lifecycleKey, collapsed.length - 1);
|
||||
}
|
||||
}
|
||||
return collapsed;
|
||||
}
|
||||
@@ -1007,19 +1082,31 @@ function shouldCollapseToolLifecycleEntries(
|
||||
previous: DerivedWorkLogEntry,
|
||||
next: DerivedWorkLogEntry,
|
||||
): boolean {
|
||||
if (previous.activityKind !== "tool.updated" && previous.activityKind !== "tool.completed") {
|
||||
if (
|
||||
previous.activityKind !== "tool.started" &&
|
||||
previous.activityKind !== "tool.updated" &&
|
||||
previous.activityKind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (next.activityKind !== "tool.updated" && next.activityKind !== "tool.completed") {
|
||||
if (
|
||||
next.activityKind !== "tool.started" &&
|
||||
next.activityKind !== "tool.updated" &&
|
||||
next.activityKind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (previous.activityKind === "tool.completed") {
|
||||
return false;
|
||||
}
|
||||
if (next.activityKind === "tool.started") {
|
||||
return false;
|
||||
}
|
||||
if (previous.collapseKey !== undefined && previous.collapseKey === next.collapseKey) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
previous.activityKind !== "tool.started" &&
|
||||
previous.toolCallId !== undefined &&
|
||||
next.toolCallId === undefined &&
|
||||
previous.itemType === next.itemType &&
|
||||
@@ -1080,7 +1167,11 @@ function deriveToolLifecycleCollapseKey(entry: DerivedWorkLogEntry): string | un
|
||||
) {
|
||||
return `task${entry.taskId}`;
|
||||
}
|
||||
if (entry.activityKind !== "tool.updated" && entry.activityKind !== "tool.completed") {
|
||||
if (
|
||||
entry.activityKind !== "tool.started" &&
|
||||
entry.activityKind !== "tool.updated" &&
|
||||
entry.activityKind !== "tool.completed"
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
if (entry.toolCallId) {
|
||||
@@ -1283,6 +1374,8 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const itemInput = asRecord(item?.input);
|
||||
const dataInput = asRecord(data?.input);
|
||||
const stateInput = asRecord(asRecord(data?.state)?.input);
|
||||
const itemType = asTrimmedString(payload?.itemType);
|
||||
const detail = asTrimmedString(payload?.detail);
|
||||
const candidates: unknown[] = [
|
||||
@@ -1290,6 +1383,8 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
itemInput?.command,
|
||||
itemResult?.command,
|
||||
data?.command,
|
||||
dataInput?.command,
|
||||
stateInput?.command,
|
||||
itemType === "command_execution" && detail ? stripTrailingExitCode(detail).output : null,
|
||||
];
|
||||
|
||||
@@ -1316,7 +1411,7 @@ function extractToolTitle(payload: Record<string, unknown> | null): string | nul
|
||||
|
||||
function extractToolCallId(payload: Record<string, unknown> | null): string | null {
|
||||
const data = asRecord(payload?.data);
|
||||
return asTrimmedString(data?.toolCallId);
|
||||
return asTrimmedString(payload?.toolCallId) ?? asTrimmedString(data?.toolCallId);
|
||||
}
|
||||
|
||||
function normalizeInlinePreview(value: string): string {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
migratePersistedTerminalUiStateStoreState,
|
||||
selectThreadTerminalCustomLabels,
|
||||
selectThreadTerminalUiState,
|
||||
useTerminalUiStateStore,
|
||||
} from "./terminalUiStateStore";
|
||||
@@ -18,6 +19,7 @@ describe("terminalUiStateStore actions", () => {
|
||||
useTerminalUiStateStore.persist.clearStorage();
|
||||
useTerminalUiStateStore.setState({
|
||||
terminalUiStateByThreadKey: {},
|
||||
terminalCustomLabelsByThreadKey: {},
|
||||
suppressedTerminalIdsByThreadKey: {},
|
||||
});
|
||||
});
|
||||
@@ -212,9 +214,53 @@ describe("terminalUiStateStore actions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes persisted terminal labels", () => {
|
||||
const migrated = migratePersistedTerminalUiStateStoreState(
|
||||
{
|
||||
terminalCustomLabelsByThreadKey: {
|
||||
[scopedThreadKey(THREAD_REF)]: {
|
||||
" term-1 ": " API server ",
|
||||
empty: " ",
|
||||
invalid: 42,
|
||||
},
|
||||
"legacy-thread-id": { "term-2": "Ignored" },
|
||||
},
|
||||
},
|
||||
4,
|
||||
);
|
||||
|
||||
expect(migrated).toEqual({
|
||||
terminalUiStateByThreadKey: {},
|
||||
terminalCustomLabelsByThreadKey: {
|
||||
[scopedThreadKey(THREAD_REF)]: { "term-1": "API server" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("sets and clears a terminal label", () => {
|
||||
const store = useTerminalUiStateStore.getState();
|
||||
store.setTerminalCustomLabel(THREAD_REF, "term-1", " API server ");
|
||||
|
||||
expect(
|
||||
selectThreadTerminalCustomLabels(
|
||||
useTerminalUiStateStore.getState().terminalCustomLabelsByThreadKey,
|
||||
THREAD_REF,
|
||||
),
|
||||
).toEqual({ "term-1": "API server" });
|
||||
|
||||
store.setTerminalCustomLabel(THREAD_REF, "term-1", null);
|
||||
expect(
|
||||
selectThreadTerminalCustomLabels(
|
||||
useTerminalUiStateStore.getState().terminalCustomLabelsByThreadKey,
|
||||
THREAD_REF,
|
||||
),
|
||||
).toEqual({});
|
||||
});
|
||||
|
||||
it("resets to default and clears persisted entry when closing the last terminal", () => {
|
||||
const store = useTerminalUiStateStore.getState();
|
||||
store.newTerminal(THREAD_REF, "terminal-only");
|
||||
store.setTerminalCustomLabel(THREAD_REF, "terminal-only", "Build");
|
||||
store.closeTerminal(THREAD_REF, "terminal-only");
|
||||
|
||||
expect(
|
||||
@@ -226,6 +272,12 @@ describe("terminalUiStateStore actions", () => {
|
||||
THREAD_REF,
|
||||
).terminalIds,
|
||||
).toEqual([]);
|
||||
expect(
|
||||
selectThreadTerminalCustomLabels(
|
||||
useTerminalUiStateStore.getState().terminalCustomLabelsByThreadKey,
|
||||
THREAD_REF,
|
||||
),
|
||||
).toEqual({});
|
||||
});
|
||||
|
||||
it("keeps a valid active terminal after closing an active split terminal", () => {
|
||||
@@ -248,6 +300,8 @@ describe("terminalUiStateStore actions", () => {
|
||||
it("reconciles terminal ids from an external ordered list", () => {
|
||||
const store = useTerminalUiStateStore.getState();
|
||||
store.setTerminalOpen(THREAD_REF, true);
|
||||
store.setTerminalCustomLabel(THREAD_REF, "term-a", "API server");
|
||||
store.setTerminalCustomLabel(THREAD_REF, "stale-term", "Old task");
|
||||
store.reconcileTerminalIds(THREAD_REF, ["term-a", "term-b"]);
|
||||
|
||||
const terminalUiState = selectThreadTerminalUiState(
|
||||
@@ -260,6 +314,11 @@ describe("terminalUiStateStore actions", () => {
|
||||
{ id: "group-term-a", terminalIds: ["term-a"] },
|
||||
{ id: "group-term-b", terminalIds: ["term-b"] },
|
||||
]);
|
||||
expect(
|
||||
useTerminalUiStateStore.getState().terminalCustomLabelsByThreadKey[
|
||||
scopedThreadKey(THREAD_REF)
|
||||
],
|
||||
).toEqual({ "term-a": "API server" });
|
||||
});
|
||||
|
||||
it("does not import a closed panel terminal from stale metadata", () => {
|
||||
|
||||
@@ -32,8 +32,11 @@ const TERMINAL_UI_STATE_STORAGE_KEY = "t3code:terminal-state:v1";
|
||||
interface PersistedTerminalUiStateStoreState {
|
||||
terminalUiStateByThreadKey?: Record<string, ThreadTerminalUiState>;
|
||||
terminalStateByThreadKey?: Record<string, ThreadTerminalUiState>;
|
||||
terminalCustomLabelsByThreadKey?: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
const EMPTY_TERMINAL_CUSTOM_LABELS: Readonly<Record<string, string>> = Object.freeze({});
|
||||
|
||||
export function migratePersistedTerminalUiStateStoreState(
|
||||
persistedState: unknown,
|
||||
_version: number,
|
||||
@@ -50,8 +53,32 @@ export function migratePersistedTerminalUiStateStoreState(
|
||||
parseScopedThreadKey(threadKey),
|
||||
),
|
||||
);
|
||||
const terminalCustomLabelsByThreadKey = Object.fromEntries(
|
||||
Object.entries(candidate.terminalCustomLabelsByThreadKey ?? {}).flatMap(
|
||||
([threadKey, labels]) => {
|
||||
if (!parseScopedThreadKey(threadKey) || !labels || typeof labels !== "object") return [];
|
||||
const normalizedLabels = Object.fromEntries(
|
||||
Object.entries(labels).flatMap(([terminalId, label]) => {
|
||||
const normalizedTerminalId = terminalId.trim();
|
||||
const normalizedLabel = typeof label === "string" ? label.trim().slice(0, 80) : "";
|
||||
return normalizedTerminalId && normalizedLabel
|
||||
? [[normalizedTerminalId, normalizedLabel] as const]
|
||||
: [];
|
||||
}),
|
||||
);
|
||||
return Object.keys(normalizedLabels).length > 0
|
||||
? [[threadKey, normalizedLabels] as const]
|
||||
: [];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return { terminalUiStateByThreadKey };
|
||||
return {
|
||||
terminalUiStateByThreadKey,
|
||||
...(Object.keys(terminalCustomLabelsByThreadKey).length > 0
|
||||
? { terminalCustomLabelsByThreadKey }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
function createTerminalUiStateStorage() {
|
||||
@@ -489,6 +516,18 @@ export function selectThreadTerminalUiState(
|
||||
);
|
||||
}
|
||||
|
||||
export function selectThreadTerminalCustomLabels(
|
||||
terminalCustomLabelsByThreadKey: Record<string, Record<string, string>>,
|
||||
threadRef: ScopedThreadRef | null | undefined,
|
||||
): Readonly<Record<string, string>> {
|
||||
if (!threadRef || threadRef.threadId.length === 0) {
|
||||
return EMPTY_TERMINAL_CUSTOM_LABELS;
|
||||
}
|
||||
return (
|
||||
terminalCustomLabelsByThreadKey[terminalThreadKey(threadRef)] ?? EMPTY_TERMINAL_CUSTOM_LABELS
|
||||
);
|
||||
}
|
||||
|
||||
function updateTerminalUiStateByThreadKey(
|
||||
terminalUiStateByThreadKey: Record<string, ThreadTerminalUiState>,
|
||||
threadRef: ScopedThreadRef,
|
||||
@@ -562,6 +601,7 @@ function removeRecordEntry<T>(record: Record<string, T>, key: string): Record<st
|
||||
|
||||
interface TerminalUiStateStoreState {
|
||||
terminalUiStateByThreadKey: Record<string, ThreadTerminalUiState>;
|
||||
terminalCustomLabelsByThreadKey: Record<string, Record<string, string>>;
|
||||
/** Closed ids hidden from stale server metadata until that id is explicitly opened again. */
|
||||
suppressedTerminalIdsByThreadKey: Record<string, string[]>;
|
||||
setTerminalOpen: (threadRef: ScopedThreadRef, open: boolean) => void;
|
||||
@@ -575,6 +615,11 @@ interface TerminalUiStateStoreState {
|
||||
options?: { open?: boolean; active?: boolean },
|
||||
) => void;
|
||||
setActiveTerminal: (threadRef: ScopedThreadRef, terminalId: string) => void;
|
||||
setTerminalCustomLabel: (
|
||||
threadRef: ScopedThreadRef,
|
||||
terminalId: string,
|
||||
label: string | null,
|
||||
) => void;
|
||||
closeTerminal: (threadRef: ScopedThreadRef, terminalId: string) => void;
|
||||
reconcileTerminalIds: (threadRef: ScopedThreadRef, nextIds: string[]) => void;
|
||||
clearTerminalUiState: (threadRef: ScopedThreadRef) => void;
|
||||
@@ -591,7 +636,12 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
state: ThreadTerminalUiState,
|
||||
suppressedTerminalIds: readonly string[],
|
||||
) => ThreadTerminalUiState,
|
||||
suppression?: { terminalId: string; suppressed: boolean },
|
||||
suppression?: {
|
||||
terminalId: string;
|
||||
suppressed: boolean;
|
||||
clearCustomLabel?: boolean;
|
||||
},
|
||||
pruneCustomLabels = false,
|
||||
) => {
|
||||
set((state) => {
|
||||
const threadKey = terminalThreadKey(threadRef);
|
||||
@@ -609,21 +659,57 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
suppression.suppressed,
|
||||
)
|
||||
: state.suppressedTerminalIdsByThreadKey;
|
||||
const terminalIdToClear = suppression?.clearCustomLabel
|
||||
? suppression.terminalId.trim()
|
||||
: "";
|
||||
const currentLabels = state.terminalCustomLabelsByThreadKey[threadKey] ?? {};
|
||||
let nextTerminalCustomLabelsByThreadKey =
|
||||
terminalIdToClear.length > 0 && currentLabels[terminalIdToClear] !== undefined
|
||||
? Object.keys(currentLabels).length === 1
|
||||
? removeRecordEntry(state.terminalCustomLabelsByThreadKey, threadKey)
|
||||
: {
|
||||
...state.terminalCustomLabelsByThreadKey,
|
||||
[threadKey]: removeRecordEntry(currentLabels, terminalIdToClear),
|
||||
}
|
||||
: state.terminalCustomLabelsByThreadKey;
|
||||
if (pruneCustomLabels) {
|
||||
const survivingIds = new Set(
|
||||
selectThreadTerminalUiState(nextTerminalUiStateByThreadKey, threadRef).terminalIds,
|
||||
);
|
||||
const labelsForThread = nextTerminalCustomLabelsByThreadKey[threadKey] ?? {};
|
||||
const survivingLabels = Object.fromEntries(
|
||||
Object.entries(labelsForThread).filter(([terminalId]) =>
|
||||
survivingIds.has(terminalId),
|
||||
),
|
||||
);
|
||||
if (Object.keys(survivingLabels).length !== Object.keys(labelsForThread).length) {
|
||||
nextTerminalCustomLabelsByThreadKey =
|
||||
Object.keys(survivingLabels).length > 0
|
||||
? {
|
||||
...nextTerminalCustomLabelsByThreadKey,
|
||||
[threadKey]: survivingLabels,
|
||||
}
|
||||
: removeRecordEntry(nextTerminalCustomLabelsByThreadKey, threadKey);
|
||||
}
|
||||
}
|
||||
if (
|
||||
nextTerminalUiStateByThreadKey === state.terminalUiStateByThreadKey &&
|
||||
nextSuppressedTerminalIdsByThreadKey === state.suppressedTerminalIdsByThreadKey
|
||||
nextSuppressedTerminalIdsByThreadKey === state.suppressedTerminalIdsByThreadKey &&
|
||||
nextTerminalCustomLabelsByThreadKey === state.terminalCustomLabelsByThreadKey
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
terminalUiStateByThreadKey: nextTerminalUiStateByThreadKey,
|
||||
suppressedTerminalIdsByThreadKey: nextSuppressedTerminalIdsByThreadKey,
|
||||
terminalCustomLabelsByThreadKey: nextTerminalCustomLabelsByThreadKey,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
terminalUiStateByThreadKey: {},
|
||||
terminalCustomLabelsByThreadKey: {},
|
||||
suppressedTerminalIdsByThreadKey: {},
|
||||
setTerminalOpen: (threadRef, open) => {
|
||||
const terminalState = selectThreadTerminalUiState(
|
||||
@@ -682,22 +768,56 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
),
|
||||
setActiveTerminal: (threadRef, terminalId) =>
|
||||
updateTerminal(threadRef, (state) => setThreadActiveTerminal(state, terminalId)),
|
||||
setTerminalCustomLabel: (threadRef, terminalId, label) =>
|
||||
set((state) => {
|
||||
const normalizedTerminalId = terminalId.trim();
|
||||
if (normalizedTerminalId.length === 0) return state;
|
||||
const threadKey = terminalThreadKey(threadRef);
|
||||
const currentLabels = state.terminalCustomLabelsByThreadKey[threadKey] ?? {};
|
||||
const normalizedLabel = label?.trim().slice(0, 80) ?? "";
|
||||
if (normalizedLabel.length > 0) {
|
||||
if (currentLabels[normalizedTerminalId] === normalizedLabel) return state;
|
||||
return {
|
||||
terminalCustomLabelsByThreadKey: {
|
||||
...state.terminalCustomLabelsByThreadKey,
|
||||
[threadKey]: { ...currentLabels, [normalizedTerminalId]: normalizedLabel },
|
||||
},
|
||||
};
|
||||
}
|
||||
if (currentLabels[normalizedTerminalId] === undefined) return state;
|
||||
const { [normalizedTerminalId]: _removed, ...remainingLabels } = currentLabels;
|
||||
return {
|
||||
terminalCustomLabelsByThreadKey:
|
||||
Object.keys(remainingLabels).length > 0
|
||||
? {
|
||||
...state.terminalCustomLabelsByThreadKey,
|
||||
[threadKey]: remainingLabels,
|
||||
}
|
||||
: removeRecordEntry(state.terminalCustomLabelsByThreadKey, threadKey),
|
||||
};
|
||||
}),
|
||||
closeTerminal: (threadRef, terminalId) =>
|
||||
updateTerminal(threadRef, (state) => closeThreadTerminal(state, terminalId), {
|
||||
terminalId,
|
||||
suppressed: true,
|
||||
clearCustomLabel: true,
|
||||
}),
|
||||
reconcileTerminalIds: (threadRef, nextIds) =>
|
||||
updateTerminal(threadRef, (state, suppressedTerminalIds) => {
|
||||
if (suppressedTerminalIds.length === 0) {
|
||||
return reconcileThreadTerminalSessionIds(state, nextIds);
|
||||
}
|
||||
const suppressedIds = new Set(suppressedTerminalIds);
|
||||
return reconcileThreadTerminalSessionIds(
|
||||
state,
|
||||
nextIds.filter((terminalId) => !suppressedIds.has(terminalId)),
|
||||
);
|
||||
}),
|
||||
updateTerminal(
|
||||
threadRef,
|
||||
(state, suppressedTerminalIds) => {
|
||||
if (suppressedTerminalIds.length === 0) {
|
||||
return reconcileThreadTerminalSessionIds(state, nextIds);
|
||||
}
|
||||
const suppressedIds = new Set(suppressedTerminalIds);
|
||||
return reconcileThreadTerminalSessionIds(
|
||||
state,
|
||||
nextIds.filter((terminalId) => !suppressedIds.has(terminalId)),
|
||||
);
|
||||
},
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
clearTerminalUiState: (threadRef) =>
|
||||
set((state) => {
|
||||
const threadKey = terminalThreadKey(threadRef);
|
||||
@@ -708,14 +828,20 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
);
|
||||
const hadSuppressedTerminalIds =
|
||||
state.suppressedTerminalIdsByThreadKey[threadKey] !== undefined;
|
||||
const hadCustomLabels = state.terminalCustomLabelsByThreadKey[threadKey] !== undefined;
|
||||
if (
|
||||
nextTerminalUiStateByThreadKey === state.terminalUiStateByThreadKey &&
|
||||
!hadSuppressedTerminalIds
|
||||
!hadSuppressedTerminalIds &&
|
||||
!hadCustomLabels
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
terminalUiStateByThreadKey: nextTerminalUiStateByThreadKey,
|
||||
terminalCustomLabelsByThreadKey: removeRecordEntry(
|
||||
state.terminalCustomLabelsByThreadKey,
|
||||
threadKey,
|
||||
),
|
||||
suppressedTerminalIdsByThreadKey: removeRecordEntry(
|
||||
state.suppressedTerminalIdsByThreadKey,
|
||||
threadKey,
|
||||
@@ -728,7 +854,8 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
const hadTerminalUiState = state.terminalUiStateByThreadKey[threadKey] !== undefined;
|
||||
const hadSuppressedTerminalIds =
|
||||
state.suppressedTerminalIdsByThreadKey[threadKey] !== undefined;
|
||||
if (!hadTerminalUiState && !hadSuppressedTerminalIds) {
|
||||
const hadCustomLabels = state.terminalCustomLabelsByThreadKey[threadKey] !== undefined;
|
||||
if (!hadTerminalUiState && !hadSuppressedTerminalIds && !hadCustomLabels) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
@@ -736,6 +863,10 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
state.terminalUiStateByThreadKey,
|
||||
threadKey,
|
||||
),
|
||||
terminalCustomLabelsByThreadKey: removeRecordEntry(
|
||||
state.terminalCustomLabelsByThreadKey,
|
||||
threadKey,
|
||||
),
|
||||
suppressedTerminalIdsByThreadKey: removeRecordEntry(
|
||||
state.suppressedTerminalIdsByThreadKey,
|
||||
threadKey,
|
||||
@@ -747,6 +878,7 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
const orphanedIds = new Set(
|
||||
[
|
||||
...Object.keys(state.terminalUiStateByThreadKey),
|
||||
...Object.keys(state.terminalCustomLabelsByThreadKey),
|
||||
...Object.keys(state.suppressedTerminalIdsByThreadKey),
|
||||
].filter((key) => !activeThreadKeys.has(key)),
|
||||
);
|
||||
@@ -757,12 +889,17 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
const nextSuppressedTerminalIdsByThreadKey = {
|
||||
...state.suppressedTerminalIdsByThreadKey,
|
||||
};
|
||||
const nextTerminalCustomLabelsByThreadKey = {
|
||||
...state.terminalCustomLabelsByThreadKey,
|
||||
};
|
||||
for (const id of orphanedIds) {
|
||||
delete nextTerminalUiStateByThreadKey[id];
|
||||
delete nextTerminalCustomLabelsByThreadKey[id];
|
||||
delete nextSuppressedTerminalIdsByThreadKey[id];
|
||||
}
|
||||
return {
|
||||
terminalUiStateByThreadKey: nextTerminalUiStateByThreadKey,
|
||||
terminalCustomLabelsByThreadKey: nextTerminalCustomLabelsByThreadKey,
|
||||
suppressedTerminalIdsByThreadKey: nextSuppressedTerminalIdsByThreadKey,
|
||||
};
|
||||
}),
|
||||
@@ -770,11 +907,12 @@ export const useTerminalUiStateStore = create<TerminalUiStateStoreState>()(
|
||||
},
|
||||
{
|
||||
name: TERMINAL_UI_STATE_STORAGE_KEY,
|
||||
version: 4,
|
||||
version: 5,
|
||||
storage: createJSONStorage(createTerminalUiStateStorage),
|
||||
migrate: migratePersistedTerminalUiStateStoreState,
|
||||
partialize: (state) => ({
|
||||
terminalUiStateByThreadKey: state.terminalUiStateByThreadKey,
|
||||
terminalCustomLabelsByThreadKey: state.terminalCustomLabelsByThreadKey,
|
||||
}),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user