Address PR #3960 review findings and CI failures
CI: add settledOverride/settledAt + new client settings to desktop and mobile test fixtures and the mobile threadDetailToShell mapping. Review fixes (cursor bugbot + macroscope): - failed status now requires session.status === "error" instead of any lingering lastError on a stopped/ready session - effectiveSettled: pending approvals or user input always win — blocked work can never collapse into the settled tail, even manually settled - decider unsettle-on-activity guards check settledOverride === "settled" so activity no longer erases a user's explicit keep-active override - repeat thread.settle re-emits with updatedAt = original settledAt, so double-settles no longer bump recency ordering - sidebarAutoSettleAfterDays bounded 1..90 in schema and patch - approval wait sort/label use shell.updatedAt (bumped by the approval activity in the projection pipeline) instead of latestUserMessageAt / turn start, with the approximation documented - v2 rows: Enter/Space keyboard activation; double-click inline rename ported from v1 plus a context-menu Rename entry - new-thread picker: cross-project creation no longer inherits the active thread's branch/worktree; preselection consults the active draft via resolveThreadActionProjectRef; stale project scope resets to All - settle worktree prompt: vcs status checked before offering (and again at click time) — dirty or ahead worktrees are never offered Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
e17a333d3f
commit
069f271b1c
21 files changed
+386
-68
No files matched your search
@@ -20,6 +20,7 @@ const clientSettings: ClientSettings = {
|
||||
diffIgnoreWhitespace: true,
|
||||
favorites: [],
|
||||
providerModelPreferences: {},
|
||||
sidebarAutoSettleAfterDays: 3,
|
||||
sidebarProjectGroupingMode: "repository_path",
|
||||
sidebarProjectGroupingOverrides: {
|
||||
"environment-1:/tmp/project-a": "separate",
|
||||
@@ -27,6 +28,7 @@ const clientSettings: ClientSettings = {
|
||||
sidebarProjectSortOrder: "manual",
|
||||
sidebarThreadSortOrder: "created_at",
|
||||
sidebarThreadPreviewCount: 6,
|
||||
sidebarV2Enabled: false,
|
||||
timestampFormat: "24-hour",
|
||||
wordWrap: true,
|
||||
};
|
||||
|
||||
@@ -41,6 +41,8 @@ function makeThread(
|
||||
hasPendingUserInput: false,
|
||||
hasActionableProposedPlan: false,
|
||||
...input,
|
||||
settledOverride: input.settledOverride ?? null,
|
||||
settledAt: input.settledAt ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ function makeThread(id: string, projectId: ProjectId): EnvironmentThreadShell {
|
||||
createdAt: "2026-06-01T00:00:00.000Z",
|
||||
updatedAt: "2026-06-01T00:00:00.000Z",
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
session: null,
|
||||
latestUserMessageAt: null,
|
||||
hasPendingApprovals: false,
|
||||
|
||||
@@ -41,6 +41,8 @@ function makeThread(
|
||||
hasPendingUserInput: false,
|
||||
hasActionableProposedPlan: false,
|
||||
...input,
|
||||
settledOverride: input.settledOverride ?? null,
|
||||
settledAt: input.settledAt ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ function makeThread(
|
||||
hasPendingUserInput: false,
|
||||
hasActionableProposedPlan: false,
|
||||
...input,
|
||||
settledOverride: input.settledOverride ?? null,
|
||||
settledAt: input.settledAt ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ function makeThread(
|
||||
checkpoints: [],
|
||||
session: null,
|
||||
...input,
|
||||
settledOverride: input.settledOverride ?? null,
|
||||
settledAt: input.settledAt ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ function threadDetailToShell(
|
||||
createdAt: thread.createdAt,
|
||||
updatedAt: thread.updatedAt,
|
||||
archivedAt: thread.archivedAt,
|
||||
settledOverride: thread.settledOverride,
|
||||
settledAt: thread.settledAt,
|
||||
session: thread.session,
|
||||
latestUserMessageAt: latestUserMessageAt(thread),
|
||||
hasPendingApprovals: false,
|
||||
|
||||
@@ -98,6 +98,7 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => {
|
||||
expect(reEmitEvents[0]?.type).toBe("thread.settled");
|
||||
if (reEmitEvents[0]?.type === "thread.settled") {
|
||||
expect(reEmitEvents[0].payload.settledAt).toBe(SETTLED_AT);
|
||||
expect(reEmitEvents[0].payload.updatedAt).toBe(SETTLED_AT);
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -199,10 +200,55 @@ it.layer(NodeServices.layer)("settled thread decider", (it) => {
|
||||
readModel: makeReadModel("active"),
|
||||
});
|
||||
const sessionEvents = Array.isArray(sessionResult) ? sessionResult : [sessionResult];
|
||||
expect(sessionEvents.map((event) => event.type)).toEqual([
|
||||
"thread.unsettled",
|
||||
"thread.session-set",
|
||||
expect(sessionEvents.map((event) => event.type)).toEqual(["thread.session-set"]);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves an explicit active override during activity", () =>
|
||||
Effect.gen(function* () {
|
||||
const turnResult = yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.make("cmd-active-turn-start"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
message: {
|
||||
messageId: MessageId.make("message-active"),
|
||||
role: "user",
|
||||
text: "Continue",
|
||||
attachments: [],
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
createdAt: NOW,
|
||||
},
|
||||
readModel: makeReadModel("active"),
|
||||
});
|
||||
const turnEvents = Array.isArray(turnResult) ? turnResult : [turnResult];
|
||||
expect(turnEvents.map((event) => event.type)).toEqual([
|
||||
"thread.message-sent",
|
||||
"thread.turn-start-requested",
|
||||
]);
|
||||
|
||||
const activityResult = yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "thread.activity.append",
|
||||
commandId: CommandId.make("cmd-active-approval"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
activity: {
|
||||
id: EventId.make("activity-active"),
|
||||
tone: "approval",
|
||||
kind: "approval.requested",
|
||||
summary: "Command approval requested",
|
||||
payload: null,
|
||||
turnId: null,
|
||||
createdAt: NOW,
|
||||
},
|
||||
createdAt: NOW,
|
||||
},
|
||||
readModel: makeReadModel("active"),
|
||||
});
|
||||
const activityEvents = Array.isArray(activityResult) ? activityResult : [activityResult];
|
||||
expect(activityEvents.map((event) => event.type)).toEqual(["thread.activity-appended"]);
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
settledAt,
|
||||
updatedAt: occurredAt,
|
||||
updatedAt: settledAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -519,7 +519,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
createdAt: command.createdAt,
|
||||
},
|
||||
};
|
||||
if (targetThread.settledOverride === null) {
|
||||
if (targetThread.settledOverride !== "settled") {
|
||||
return [userMessageEvent, turnStartRequestedEvent];
|
||||
}
|
||||
const unsettledEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||
@@ -681,7 +681,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
// must not fight a user's explicit settle.
|
||||
const isSessionActivity =
|
||||
command.session.status === "starting" || command.session.status === "running";
|
||||
if (thread.settledOverride === null || !isSessionActivity) {
|
||||
if (thread.settledOverride !== "settled" || !isSessionActivity) {
|
||||
return sessionSetEvent;
|
||||
}
|
||||
const unsettledEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||
@@ -857,7 +857,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
const wakesSettledThread =
|
||||
command.activity.kind === "approval.requested" ||
|
||||
command.activity.kind === "user-input.requested";
|
||||
if (thread.settledOverride === null || !wakesSettledThread) {
|
||||
if (thread.settledOverride !== "settled" || !wakesSettledThread) {
|
||||
return activityAppendedEvent;
|
||||
}
|
||||
const unsettledEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||
|
||||
@@ -592,17 +592,23 @@ describe("resolveSidebarV2Status", () => {
|
||||
).toBe("working");
|
||||
});
|
||||
|
||||
it("reports failed only for stopped sessions with an error", () => {
|
||||
it("reports failed only while the session status is error", () => {
|
||||
expect(
|
||||
resolveSidebarV2Status({
|
||||
hasPendingApprovals: false,
|
||||
session: { ...session, status: "stopped" as const, lastError: "boom" },
|
||||
session: { ...session, status: "error" as const, lastError: "boom" },
|
||||
}),
|
||||
).toBe("failed");
|
||||
expect(
|
||||
resolveSidebarV2Status({
|
||||
hasPendingApprovals: false,
|
||||
session: { ...session, status: "stopped" as const },
|
||||
session: { ...session, status: "stopped" as const, lastError: "persisted" },
|
||||
}),
|
||||
).toBe("ready");
|
||||
expect(
|
||||
resolveSidebarV2Status({
|
||||
hasPendingApprovals: false,
|
||||
session: { ...session, status: "ready" as const, lastError: "persisted" },
|
||||
}),
|
||||
).toBe("ready");
|
||||
});
|
||||
@@ -617,12 +623,13 @@ describe("sortThreadsForSidebarV2", () => {
|
||||
id: string;
|
||||
hasPendingApprovals?: boolean;
|
||||
latestUserMessageAt: string;
|
||||
updatedAt?: string;
|
||||
}) => ({
|
||||
id: input.id,
|
||||
hasPendingApprovals: input.hasPendingApprovals ?? false,
|
||||
session: null,
|
||||
createdAt: "2026-03-09T10:00:00.000Z",
|
||||
updatedAt: input.latestUserMessageAt,
|
||||
updatedAt: input.updatedAt ?? input.latestUserMessageAt,
|
||||
latestUserMessageAt: input.latestUserMessageAt,
|
||||
});
|
||||
|
||||
@@ -632,12 +639,14 @@ describe("sortThreadsForSidebarV2", () => {
|
||||
sortable({
|
||||
id: "approval-new",
|
||||
hasPendingApprovals: true,
|
||||
latestUserMessageAt: "2026-03-09T11:00:00.000Z",
|
||||
latestUserMessageAt: "2026-03-09T08:00:00.000Z",
|
||||
updatedAt: "2026-03-09T11:00:00.000Z",
|
||||
}),
|
||||
sortable({
|
||||
id: "approval-old",
|
||||
hasPendingApprovals: true,
|
||||
latestUserMessageAt: "2026-03-09T09:00:00.000Z",
|
||||
latestUserMessageAt: "2026-03-09T11:30:00.000Z",
|
||||
updatedAt: "2026-03-09T09:00:00.000Z",
|
||||
}),
|
||||
sortable({ id: "stale", latestUserMessageAt: "2026-03-09T08:00:00.000Z" }),
|
||||
]);
|
||||
|
||||
@@ -373,7 +373,7 @@ export function resolveSidebarV2Status(thread: SidebarV2StatusInput): SidebarV2S
|
||||
if (thread.session?.status === "running" || thread.session?.status === "starting") {
|
||||
return "working";
|
||||
}
|
||||
if (thread.session != null && thread.session.lastError !== null) {
|
||||
if (thread.session?.status === "error") {
|
||||
return "failed";
|
||||
}
|
||||
return "ready";
|
||||
@@ -390,13 +390,16 @@ export function sortThreadsForSidebarV2<
|
||||
if (leftApproval !== rightApproval) {
|
||||
return leftApproval ? -1 : 1;
|
||||
}
|
||||
// Approval activities update the shell's updatedAt in the projection
|
||||
// pipeline, making it the best available request-time proxy. Oldest waits
|
||||
// pin first. (The shell does not expose the approval request timestamp.)
|
||||
if (leftApproval && rightApproval) {
|
||||
return (
|
||||
Date.parse(left.updatedAt) - Date.parse(right.updatedAt) || left.id.localeCompare(right.id)
|
||||
);
|
||||
}
|
||||
const byRecency =
|
||||
getThreadSortTimestamp(right, "updated_at") - getThreadSortTimestamp(left, "updated_at");
|
||||
// Approval wait time is "how long you've been the bottleneck", which is
|
||||
// oldest-activity-first — the inverse of recency.
|
||||
if (leftApproval && rightApproval) {
|
||||
return -byRecency || left.id.localeCompare(right.id);
|
||||
}
|
||||
return byRecency || left.id.localeCompare(right.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type KeyboardEvent as ReactKeyboardEvent,
|
||||
type MouseEvent as ReactMouseEvent,
|
||||
} from "react";
|
||||
import { useParams, useRouter } from "@tanstack/react-router";
|
||||
@@ -47,6 +48,7 @@ import { useOpenAddProjectCommandPalette } from "../commandPaletteContext";
|
||||
import { onOpenNewThreadPicker } from "../newThreadPickerBus";
|
||||
import { Dialog, DialogHeader, DialogPopup, DialogTitle } from "./ui/dialog";
|
||||
import {
|
||||
resolveThreadActionProjectRef,
|
||||
startNewThreadFromContext,
|
||||
startNewThreadInProjectFromContext,
|
||||
} from "../lib/chatThreadActions";
|
||||
@@ -55,7 +57,9 @@ import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments"
|
||||
import { useProjects, useThreadShells } from "../state/entities";
|
||||
import { primaryServerKeybindingsAtom } from "../state/server";
|
||||
import { vcsEnvironment } from "../state/vcs";
|
||||
import { threadEnvironment } from "../state/threads";
|
||||
import { useEnvironmentQuery } from "../state/query";
|
||||
import { useAtomCommand } from "../state/use-atom-command";
|
||||
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
|
||||
import { formatElapsedDurationLabel, formatRelativeTimeLabel } from "../timestampFormat";
|
||||
import type { SidebarThreadSummary } from "../types";
|
||||
@@ -128,8 +132,10 @@ function threadTimeLabel(thread: SidebarThreadSummary, status: SidebarV2Status):
|
||||
return formatElapsedDurationLabel(thread.latestTurn.startedAt);
|
||||
}
|
||||
if (status === "approval") {
|
||||
const waitingSince = thread.latestTurn?.startedAt ?? thread.updatedAt;
|
||||
return `waiting ${formatElapsedDurationLabel(waitingSince)}`;
|
||||
// Approval activities bump shell.updatedAt in the projection pipeline.
|
||||
// The shell has no dedicated request timestamp, so this is the closest
|
||||
// accurate wait-start signal shared by the label and approval ordering.
|
||||
return `waiting ${formatElapsedDurationLabel(thread.updatedAt)}`;
|
||||
}
|
||||
const timestamp = thread.latestUserMessageAt ?? thread.updatedAt;
|
||||
return formatRelativeTimeLabel(timestamp);
|
||||
@@ -152,17 +158,31 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
projectCwd: string | null;
|
||||
providerEntryByInstanceId: ReadonlyMap<string, ProviderInstanceEntry>;
|
||||
onThreadClick: (event: ReactMouseEvent, threadRef: ScopedThreadRef) => void;
|
||||
onThreadActivate: (threadRef: ScopedThreadRef) => void;
|
||||
onStartRename: (threadRef: ScopedThreadRef, title: string) => void;
|
||||
onRenameTitleChange: (title: string) => void;
|
||||
onCommitRename: (threadRef: ScopedThreadRef, title: string, originalTitle: string) => void;
|
||||
onCancelRename: () => void;
|
||||
isRenaming: boolean;
|
||||
renamingTitle: string;
|
||||
onContextMenu: (threadRef: ScopedThreadRef, position: { x: number; y: number }) => void;
|
||||
onSettle: (threadRef: ScopedThreadRef) => void;
|
||||
onUnsettle: (threadRef: ScopedThreadRef) => void;
|
||||
onChangeRequestState: (threadKey: string, state: "open" | "closed" | "merged" | null) => void;
|
||||
}) {
|
||||
const {
|
||||
isRenaming,
|
||||
onChangeRequestState,
|
||||
onCancelRename,
|
||||
onCommitRename,
|
||||
onContextMenu,
|
||||
onRenameTitleChange,
|
||||
onSettle,
|
||||
onStartRename,
|
||||
onThreadActivate,
|
||||
onThreadClick,
|
||||
onUnsettle,
|
||||
renamingTitle,
|
||||
thread,
|
||||
variant,
|
||||
variantAction,
|
||||
@@ -221,6 +241,50 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
},
|
||||
[onContextMenu, threadRef],
|
||||
);
|
||||
const handleKeyDown = useCallback(
|
||||
(event: ReactKeyboardEvent) => {
|
||||
if (event.target !== event.currentTarget) return;
|
||||
if (event.key !== "Enter" && event.key !== " ") return;
|
||||
event.preventDefault();
|
||||
onThreadActivate(threadRef);
|
||||
},
|
||||
[onThreadActivate, threadRef],
|
||||
);
|
||||
const handleDoubleClick = useCallback(
|
||||
(event: ReactMouseEvent) => {
|
||||
if (isRenaming || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
||||
return;
|
||||
}
|
||||
if ((event.target as HTMLElement).closest("button, a, input")) return;
|
||||
event.preventDefault();
|
||||
onStartRename(threadRef, thread.title);
|
||||
},
|
||||
[isRenaming, onStartRename, thread.title, threadRef],
|
||||
);
|
||||
const renameCommittedRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (isRenaming) renameCommittedRef.current = false;
|
||||
}, [isRenaming]);
|
||||
const handleRenameKeyDown = useCallback(
|
||||
(event: ReactKeyboardEvent<HTMLInputElement>) => {
|
||||
event.stopPropagation();
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
renameCommittedRef.current = true;
|
||||
onCommitRename(threadRef, renamingTitle, thread.title);
|
||||
} else if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
renameCommittedRef.current = true;
|
||||
onCancelRename();
|
||||
}
|
||||
},
|
||||
[onCancelRename, onCommitRename, renamingTitle, thread.title, threadRef],
|
||||
);
|
||||
const handleRenameBlur = useCallback(() => {
|
||||
if (!renameCommittedRef.current) {
|
||||
onCommitRename(threadRef, renamingTitle, thread.title);
|
||||
}
|
||||
}, [onCommitRename, renamingTitle, thread.title, threadRef]);
|
||||
const handleSettleClick = useCallback(
|
||||
(event: ReactMouseEvent) => {
|
||||
event.preventDefault();
|
||||
@@ -261,6 +325,36 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
/>
|
||||
);
|
||||
|
||||
const title = isRenaming ? (
|
||||
<input
|
||||
autoFocus
|
||||
value={renamingTitle}
|
||||
aria-label="Thread title"
|
||||
onChange={(event) => onRenameTitleChange(event.target.value)}
|
||||
onFocus={(event) => event.currentTarget.select()}
|
||||
onKeyDown={handleRenameKeyDown}
|
||||
onBlur={handleRenameBlur}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onDoubleClick={(event) => event.stopPropagation()}
|
||||
className="min-w-0 flex-1 rounded border border-border bg-background px-1 text-[13px] text-foreground outline-none focus:border-ring"
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate text-[13px]",
|
||||
variant === "card"
|
||||
? isUnread
|
||||
? "font-semibold text-foreground"
|
||||
: "font-medium text-foreground/85"
|
||||
: isUnread
|
||||
? "font-medium text-foreground"
|
||||
: "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{thread.title}
|
||||
</span>
|
||||
);
|
||||
|
||||
const prBadge =
|
||||
prStatus && pr ? (
|
||||
<button
|
||||
@@ -288,17 +382,12 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
data-testid="sidebar-v2-row-slim"
|
||||
className={cn(rowClassName, "flex h-[34px] items-center gap-2.5 rounded-lg px-2.5")}
|
||||
onClick={handleClick}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
onKeyDown={handleKeyDown}
|
||||
onContextMenu={handleContextMenu}
|
||||
>
|
||||
{favicon}
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate text-[13px]",
|
||||
isUnread ? "font-medium text-foreground" : "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{thread.title}
|
||||
</span>
|
||||
{title}
|
||||
{prBadge}
|
||||
<span className="relative flex h-6 w-14 shrink-0 items-center justify-end">
|
||||
<span className="text-[11px] tabular-nums text-muted-foreground/40 transition-opacity group-hover/v2-row:opacity-0">
|
||||
@@ -357,6 +446,8 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
: "hover:bg-accent/50 dark:hover:bg-accent/30",
|
||||
)}
|
||||
onClick={handleClick}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
onKeyDown={handleKeyDown}
|
||||
onContextMenu={handleContextMenu}
|
||||
>
|
||||
<div className="flex items-center gap-2.5">
|
||||
@@ -365,14 +456,7 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
|
||||
) : (
|
||||
favicon
|
||||
)}
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate text-[13px]",
|
||||
isUnread ? "font-semibold text-foreground" : "font-medium text-foreground/85",
|
||||
)}
|
||||
>
|
||||
{thread.title}
|
||||
</span>
|
||||
{title}
|
||||
{diff ? (
|
||||
<span className="shrink-0 font-mono text-[11px]">
|
||||
<span className="text-emerald-600 dark:text-emerald-400">+{diff.insertions}</span>{" "}
|
||||
@@ -475,6 +559,9 @@ export default function SidebarV2() {
|
||||
const autoSettleAfterDays = useClientSettings((s) => s.sidebarAutoSettleAfterDays);
|
||||
const confirmThreadDelete = useClientSettings((s) => s.confirmThreadDelete);
|
||||
const { settleThread, unsettleThread, archiveThread, deleteThread } = useThreadActions();
|
||||
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const newThreadContext = useHandleNewThread();
|
||||
const openAddProjectCommandPalette = useOpenAddProjectCommandPalette();
|
||||
const { environments } = useEnvironments();
|
||||
@@ -563,6 +650,14 @@ export default function SidebarV2() {
|
||||
) ?? null),
|
||||
[projectScopeKey, projects],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (
|
||||
projectScopeKey !== null &&
|
||||
!projects.some((project) => `${project.environmentId}:${project.id}` === projectScopeKey)
|
||||
) {
|
||||
setProjectScopeKey(null);
|
||||
}
|
||||
}, [projectScopeKey, projects]);
|
||||
|
||||
const { activeThreads, settledThreads } = useMemo(() => {
|
||||
const now = `${nowMinute}:00.000Z`;
|
||||
@@ -667,6 +762,42 @@ export default function SidebarV2() {
|
||||
[clearSelection, isMobile, router, setOpenMobile, setSelectionAnchor],
|
||||
);
|
||||
|
||||
const [renamingThreadKey, setRenamingThreadKey] = useState<string | null>(null);
|
||||
const [renamingTitle, setRenamingTitle] = useState("");
|
||||
const startThreadRename = useCallback((threadRef: ScopedThreadRef, title: string) => {
|
||||
setRenamingThreadKey(scopedThreadKey(threadRef));
|
||||
setRenamingTitle(title);
|
||||
}, []);
|
||||
const cancelThreadRename = useCallback(() => setRenamingThreadKey(null), []);
|
||||
const commitThreadRename = useCallback(
|
||||
(threadRef: ScopedThreadRef, title: string, originalTitle: string) => {
|
||||
void (async () => {
|
||||
const trimmed = title.trim();
|
||||
setRenamingThreadKey(null);
|
||||
if (trimmed.length === 0) {
|
||||
toastManager.add({ type: "warning", title: "Thread title cannot be empty" });
|
||||
return;
|
||||
}
|
||||
if (trimmed === originalTitle) return;
|
||||
const result = await updateThreadMetadata({
|
||||
environmentId: threadRef.environmentId,
|
||||
input: { threadId: threadRef.threadId, title: trimmed },
|
||||
});
|
||||
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
|
||||
const error = squashAtomCommandFailure(result);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to rename thread",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
}),
|
||||
);
|
||||
}
|
||||
})();
|
||||
},
|
||||
[updateThreadMetadata],
|
||||
);
|
||||
|
||||
const handleThreadClick = useCallback(
|
||||
(event: ReactMouseEvent, threadRef: ScopedThreadRef) => {
|
||||
const isMac = isMacPlatform(navigator.platform);
|
||||
@@ -830,6 +961,7 @@ export default function SidebarV2() {
|
||||
isSettled
|
||||
? { id: "unsettle", label: "Un-settle thread" }
|
||||
: { id: "settle", label: "Settle thread" },
|
||||
{ id: "rename", label: "Rename thread" },
|
||||
{ id: "mark-unread", label: "Mark unread" },
|
||||
{ id: "archive", label: "Archive" },
|
||||
{ id: "delete", label: "Delete", destructive: true, icon: "trash" },
|
||||
@@ -845,6 +977,9 @@ export default function SidebarV2() {
|
||||
case "unsettle":
|
||||
attemptUnsettle(threadRef);
|
||||
return;
|
||||
case "rename":
|
||||
startThreadRename(threadRef, thread.title);
|
||||
return;
|
||||
case "mark-unread":
|
||||
markThreadUnread(threadKey, thread.latestTurn?.completedAt);
|
||||
return;
|
||||
@@ -900,6 +1035,7 @@ export default function SidebarV2() {
|
||||
deleteThread,
|
||||
handleMultiSelectContextMenu,
|
||||
markThreadUnread,
|
||||
startThreadRename,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1016,15 +1152,15 @@ export default function SidebarV2() {
|
||||
},
|
||||
[isMobile, newThreadContext, projects, setOpenMobile],
|
||||
);
|
||||
const activeProjectRef = (() => {
|
||||
const activeThread = routeThreadKey ? threadByKey.get(routeThreadKey) : null;
|
||||
return activeThread
|
||||
? scopeProjectRef(activeThread.environmentId, activeThread.projectId)
|
||||
: null;
|
||||
})();
|
||||
const contextualProjectRef = resolveThreadActionProjectRef({
|
||||
activeDraftThread: newThreadContext.activeDraftThread,
|
||||
activeThread: newThreadContext.activeThread ?? undefined,
|
||||
defaultProjectRef: newThreadContext.defaultProjectRef,
|
||||
handleNewThread: newThreadContext.handleNewThread,
|
||||
});
|
||||
const newThreadTargetRef = scopedProject
|
||||
? scopeProjectRef(scopedProject.environmentId, scopedProject.id)
|
||||
: (activeProjectRef ?? newThreadContext.defaultProjectRef);
|
||||
: contextualProjectRef;
|
||||
const newThreadTargetProject = newThreadTargetRef
|
||||
? (projects.find(
|
||||
(project) =>
|
||||
@@ -1192,6 +1328,13 @@ export default function SidebarV2() {
|
||||
}
|
||||
providerEntryByInstanceId={providerEntryByInstanceId}
|
||||
onThreadClick={handleThreadClick}
|
||||
onThreadActivate={navigateToThread}
|
||||
onStartRename={startThreadRename}
|
||||
onRenameTitleChange={setRenamingTitle}
|
||||
onCommitRename={commitThreadRename}
|
||||
onCancelRename={cancelThreadRename}
|
||||
isRenaming={renamingThreadKey === threadKey}
|
||||
renamingTitle={renamingThreadKey === threadKey ? renamingTitle : ""}
|
||||
onContextMenu={handleThreadContextMenu}
|
||||
onSettle={attemptSettle}
|
||||
onUnsettle={attemptUnsettle}
|
||||
|
||||
@@ -22,7 +22,11 @@ import { readLocalApi } from "../localApi";
|
||||
import { readEnvironmentThreadRefs, readProject, readThreadShell } from "../state/entities";
|
||||
import { useTerminalUiStateStore } from "../terminalUiStateStore";
|
||||
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
|
||||
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
|
||||
import {
|
||||
canOfferWorktreeRemoval,
|
||||
formatWorktreePathForDisplay,
|
||||
getOrphanedWorktreePathForThread,
|
||||
} from "../worktreeCleanup";
|
||||
import { stackedThreadToast, toastManager } from "../components/ui/toast";
|
||||
import { useClientSettings } from "./useSettings";
|
||||
import { useAtomCommand } from "../state/use-atom-command";
|
||||
@@ -381,6 +385,14 @@ export function useThreadActions() {
|
||||
if (orphanedWorktreePath === null || threadProject === null) {
|
||||
return settleResult;
|
||||
}
|
||||
const statusResult = await refreshVcsStatus({
|
||||
environmentId: threadRef.environmentId,
|
||||
input: { cwd: orphanedWorktreePath },
|
||||
});
|
||||
// If status cannot be verified, keep the worktree and skip the prompt.
|
||||
if (statusResult._tag === "Failure" || !canOfferWorktreeRemoval(statusResult.value)) {
|
||||
return settleResult;
|
||||
}
|
||||
const displayWorktreePath = formatWorktreePathForDisplay(orphanedWorktreePath);
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
@@ -415,9 +427,26 @@ export function useThreadActions() {
|
||||
);
|
||||
return;
|
||||
}
|
||||
// force stays false: git refuses to remove a worktree with
|
||||
// uncommitted changes, which is the backstop for work created
|
||||
// after the settle. Branch commits survive worktree removal.
|
||||
const currentStatusResult = await refreshVcsStatus({
|
||||
environmentId: threadRef.environmentId,
|
||||
input: { cwd: orphanedWorktreePath },
|
||||
});
|
||||
if (
|
||||
currentStatusResult._tag === "Failure" ||
|
||||
!canOfferWorktreeRemoval(currentStatusResult.value)
|
||||
) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "warning",
|
||||
title: "Worktree kept",
|
||||
description:
|
||||
"This worktree has uncommitted or unpushed changes, or its status could not be verified.",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
// force stays false as an additional guard against changes
|
||||
// created between the status check and the removal request.
|
||||
const removeResult = await removeWorktree({
|
||||
environmentId: threadRef.environmentId,
|
||||
input: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
resolveNewDraftStartFromOrigin,
|
||||
startNewLocalThreadFromContext,
|
||||
startNewThreadFromContext,
|
||||
startNewThreadInProjectFromContext,
|
||||
type ChatThreadActionContext,
|
||||
} from "./chatThreadActions";
|
||||
|
||||
@@ -117,6 +118,26 @@ describe("chatThreadActions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not carry branch or worktree context into a different project", async () => {
|
||||
const handleNewThread = vi.fn<ChatThreadActionContext["handleNewThread"]>(async () => {});
|
||||
const targetProjectRef = scopeProjectRef(ENVIRONMENT_ID, FALLBACK_PROJECT_ID);
|
||||
|
||||
await startNewThreadInProjectFromContext(
|
||||
createContext({
|
||||
activeThread: {
|
||||
environmentId: ENVIRONMENT_ID,
|
||||
projectId: PROJECT_ID,
|
||||
branch: "feature/refactor",
|
||||
worktreePath: "/tmp/worktree",
|
||||
},
|
||||
handleNewThread,
|
||||
}),
|
||||
targetProjectRef,
|
||||
);
|
||||
|
||||
expect(handleNewThread).toHaveBeenCalledWith(targetProjectRef);
|
||||
});
|
||||
|
||||
it("delegates the target environment defaults to the new-thread handler", async () => {
|
||||
const handleNewThread = vi.fn<ChatThreadActionContext["handleNewThread"]>(async () => {});
|
||||
|
||||
|
||||
@@ -75,6 +75,14 @@ export async function startNewThreadInProjectFromContext(
|
||||
context: ChatThreadActionContext,
|
||||
projectRef: ScopedProjectRef,
|
||||
): Promise<void> {
|
||||
const contextualProjectRef = resolveThreadActionProjectRef(context);
|
||||
const matchesContext =
|
||||
contextualProjectRef?.environmentId === projectRef.environmentId &&
|
||||
contextualProjectRef.projectId === projectRef.projectId;
|
||||
if (!matchesContext) {
|
||||
await context.handleNewThread(projectRef);
|
||||
return;
|
||||
}
|
||||
await context.handleNewThread(projectRef, buildContextualThreadOptions(context));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@ import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { DEFAULT_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, type Thread } from "./types";
|
||||
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "./worktreeCleanup";
|
||||
import {
|
||||
canOfferWorktreeRemoval,
|
||||
formatWorktreePathForDisplay,
|
||||
getOrphanedWorktreePathForThread,
|
||||
} from "./worktreeCleanup";
|
||||
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
|
||||
@@ -110,3 +114,11 @@ describe("formatWorktreePathForDisplay", () => {
|
||||
expect(result).toBe("my-worktree");
|
||||
});
|
||||
});
|
||||
|
||||
describe("canOfferWorktreeRemoval", () => {
|
||||
it("requires a clean worktree with no unpushed commits", () => {
|
||||
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: false, aheadCount: 0 })).toBe(true);
|
||||
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: true, aheadCount: 0 })).toBe(false);
|
||||
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: false, aheadCount: 1 })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { VcsStatusResult } from "@t3tools/contracts";
|
||||
import type { ThreadShell } from "./types";
|
||||
|
||||
function normalizeWorktreePath(path: string | null): string | null {
|
||||
@@ -43,3 +44,9 @@ export function formatWorktreePathForDisplay(worktreePath: string): string {
|
||||
const lastPart = parts[parts.length - 1]?.trim() ?? "";
|
||||
return lastPart.length > 0 ? lastPart : trimmed;
|
||||
}
|
||||
|
||||
export function canOfferWorktreeRemoval(
|
||||
status: Pick<VcsStatusResult, "hasWorkingTreeChanges" | "aheadCount">,
|
||||
): boolean {
|
||||
return !status.hasWorkingTreeChanges && status.aheadCount === 0;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ function makeShell(input: {
|
||||
readonly settledOverride: OrchestrationThreadShell["settledOverride"];
|
||||
readonly activityAt: string | null;
|
||||
readonly sessionStatus?: "starting" | "running";
|
||||
readonly pending?: "approval" | "user-input";
|
||||
}): OrchestrationThreadShell {
|
||||
const threadId = ThreadId.make("thread-1");
|
||||
return {
|
||||
@@ -61,8 +62,8 @@ function makeShell(input: {
|
||||
updatedAt: NOW,
|
||||
},
|
||||
latestUserMessageAt: null,
|
||||
hasPendingApprovals: false,
|
||||
hasPendingUserInput: false,
|
||||
hasPendingApprovals: input.pending === "approval",
|
||||
hasPendingUserInput: input.pending === "user-input",
|
||||
hasActionableProposedPlan: false,
|
||||
};
|
||||
}
|
||||
@@ -97,32 +98,38 @@ describe("effectiveSettled", () => {
|
||||
["no-activity", null],
|
||||
] as const;
|
||||
const runningCases = [false, true] as const;
|
||||
const pendingCases = [undefined, "approval", "user-input"] as const;
|
||||
const truthTable = overrides.flatMap((settledOverride) =>
|
||||
changeRequestStates.flatMap((changeRequestState) =>
|
||||
inactivityCases.flatMap(([inactivity, activityAt]) =>
|
||||
runningCases.map((running) => ({
|
||||
settledOverride,
|
||||
changeRequestState,
|
||||
inactivity,
|
||||
activityAt,
|
||||
running,
|
||||
expected:
|
||||
settledOverride === "settled" ||
|
||||
(settledOverride === null &&
|
||||
!running &&
|
||||
(changeRequestState === "merged" || inactivity === "stale")),
|
||||
})),
|
||||
runningCases.flatMap((running) =>
|
||||
pendingCases.map((pending) => ({
|
||||
settledOverride,
|
||||
changeRequestState,
|
||||
inactivity,
|
||||
activityAt,
|
||||
running,
|
||||
pending,
|
||||
expected:
|
||||
pending === undefined &&
|
||||
(settledOverride === "settled" ||
|
||||
(settledOverride === null &&
|
||||
!running &&
|
||||
(changeRequestState === "merged" || inactivity === "stale"))),
|
||||
})),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
it.each(truthTable)(
|
||||
"override=$settledOverride pr=$changeRequestState inactivity=$inactivity running=$running",
|
||||
({ settledOverride, changeRequestState, activityAt, running, expected }) => {
|
||||
"override=$settledOverride pr=$changeRequestState inactivity=$inactivity running=$running pending=$pending",
|
||||
({ settledOverride, changeRequestState, activityAt, running, pending, expected }) => {
|
||||
const shell = makeShell({
|
||||
settledOverride,
|
||||
activityAt,
|
||||
...(running ? { sessionStatus: "running" as const } : {}),
|
||||
...(pending === undefined ? {} : { pending }),
|
||||
});
|
||||
const changeRequestOptions =
|
||||
changeRequestState === undefined
|
||||
|
||||
@@ -34,6 +34,8 @@ export function effectiveSettled(
|
||||
readonly changeRequestState?: ChangeRequestStateLike | null;
|
||||
},
|
||||
): boolean {
|
||||
// Blocked work must remain visible even when a user explicitly settled it.
|
||||
if (shell.hasPendingApprovals || shell.hasPendingUserInput) return false;
|
||||
if (shell.settledOverride === "settled") return true;
|
||||
if (shell.settledOverride === "active") return false;
|
||||
if (shell.session?.status === "starting" || shell.session?.status === "running") return false;
|
||||
|
||||
@@ -4,12 +4,14 @@ import * as Schema from "effect/Schema";
|
||||
import { ProviderInstanceId } from "./providerInstance.ts";
|
||||
import {
|
||||
ClientSettingsSchema,
|
||||
ClientSettingsPatch,
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
ServerSettings,
|
||||
ServerSettingsPatch,
|
||||
} from "./settings.ts";
|
||||
|
||||
const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
|
||||
const decodeClientSettingsPatch = Schema.decodeUnknownSync(ClientSettingsPatch);
|
||||
const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
|
||||
const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
|
||||
const encodeServerSettings = Schema.encodeSync(ServerSettings);
|
||||
@@ -43,6 +45,11 @@ describe("ClientSettings sidebar v2", () => {
|
||||
decodeClientSettings({ sidebarAutoSettleAfterDays: null }).sidebarAutoSettleAfterDays,
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it.each([-1, 0, 91])("rejects an auto-settle threshold outside 1..90: %s", (value) => {
|
||||
expect(() => decodeClientSettings({ sidebarAutoSettleAfterDays: value })).toThrow();
|
||||
expect(() => decodeClientSettingsPatch({ sidebarAutoSettleAfterDays: value })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
|
||||
|
||||
@@ -38,6 +38,16 @@ export const SidebarThreadPreviewCount = Schema.Int.check(
|
||||
);
|
||||
export type SidebarThreadPreviewCount = typeof SidebarThreadPreviewCount.Type;
|
||||
export const DEFAULT_SIDEBAR_THREAD_PREVIEW_COUNT: SidebarThreadPreviewCount = 6;
|
||||
export const MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 1;
|
||||
export const MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS = 90;
|
||||
export const SidebarAutoSettleAfterDays = Schema.Number.check(
|
||||
Schema.isBetween({
|
||||
minimum: MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
|
||||
maximum: MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
|
||||
}),
|
||||
);
|
||||
export type SidebarAutoSettleAfterDays = typeof SidebarAutoSettleAfterDays.Type;
|
||||
export const DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS: SidebarAutoSettleAfterDays = 3;
|
||||
|
||||
export const ClientSettingsSchema = Schema.Struct({
|
||||
autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
|
||||
@@ -72,8 +82,8 @@ export const ClientSettingsSchema = Schema.Struct({
|
||||
modelOrder: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
|
||||
}),
|
||||
).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
|
||||
sidebarAutoSettleAfterDays: Schema.NullOr(Schema.Number).pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(3)),
|
||||
sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
|
||||
),
|
||||
sidebarProjectGroupingMode: SidebarProjectGroupingMode.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE)),
|
||||
@@ -563,7 +573,7 @@ export const ClientSettingsPatch = Schema.Struct({
|
||||
}),
|
||||
),
|
||||
),
|
||||
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(Schema.Number)),
|
||||
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
|
||||
sidebarProjectGroupingMode: Schema.optionalKey(SidebarProjectGroupingMode),
|
||||
sidebarProjectGroupingOverrides: Schema.optionalKey(
|
||||
Schema.Record(TrimmedNonEmptyString, SidebarProjectGroupingMode),
|
||||
|
||||
Reference in new issue
Block a user