diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index 205097182914f..cf5854697675f 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -4,7 +4,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell import * as ThreadUndo from "@t3tools/client-runtime/state/thread-undo"; import { showThreadUndoNotice } from "./thread-undo-notice"; import { canSnooze } from "@t3tools/client-runtime/state/thread-settled"; -import { AuthOrchestrationOperateScope } from "@t3tools/contracts"; +import { AuthOrchestrationOperateScope, isStandingThreadRoot } from "@t3tools/contracts"; import * as Cause from "effect/Cause"; import * as Haptics from "expo-haptics"; import { msg } from "gt-react-native"; @@ -705,7 +705,8 @@ export function useThreadListActions(): { ? "pinned" : "active"; if (section === "settled") { - if (!environmentConfigLoaded(thread.environmentId)) return false; + if (!environmentConfigLoaded(thread.environmentId) || isStandingThreadRoot(thread)) + return false; appAtomRegistry.set(threadDropBusyAtom, true); const settled = await settleThread(thread); appAtomRegistry.set(threadDropBusyAtom, false); diff --git a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx index 0a91eb1be2247..258657898b502 100644 --- a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx +++ b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx @@ -3,6 +3,7 @@ import { SheetHeader } from "../../components/ui/SheetHeader"; import { appAtomRegistry } from "../../state/atom-registry"; import { useAtomValue } from "@effect/atom-react"; import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; +import { isStandingThreadRoot } from "@t3tools/contracts"; import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; import { sortInboxThreadsByReturn } from "@t3tools/client-runtime/state/thread-inbox"; import { msg, T, useGT, useMessages } from "gt-react-native"; @@ -324,7 +325,11 @@ function ThreadArrangementSheet(props: { onClose: () => void }) { !target.thread || contentY < target.offset + target.height / 2 ? "before" : "after", }; if (target.section === "settled") { - if (current.sourceSection !== "settled" && configs.has(current.thread.environmentId)) + if ( + current.sourceSection !== "settled" && + configs.has(current.thread.environmentId) && + !isStandingThreadRoot(current.thread) + ) destination = { section: "settled", targetId: null, placement: "before" }; } else if (latest.current.planners[target.section](keyOf(current.thread), candidate) !== null) destination = candidate; @@ -461,7 +466,9 @@ function ThreadArrangementSheet(props: { onClose: () => void }) { const label = threadDragAction(item.section, section, m); if (!label) return []; if (section === "settled") - return configLoaded ? [{ name: section, label }] : []; + return configLoaded && !isStandingThreadRoot(thread) + ? [{ name: section, label }] + : []; if ( ((section === "pinned" || thread.pinnedAt != null) && !configLoaded) || (section === "active" && item.section === "settled" && !configLoaded) || diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.test.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.test.tsx new file mode 100644 index 0000000000000..fb4a82fc433da --- /dev/null +++ b/apps/mobile/src/features/threads/thread-list-v2-items.test.tsx @@ -0,0 +1,155 @@ +import type { MenuAction } from "@react-native-menu/menu"; +import { act, type ReactNode } from "react"; +import { createRoot } from "react-dom/client"; +import { expect, it, vi } from "vite-plus/test"; +import { ThreadId } from "@t3tools/contracts"; +import { makeThreadShellFixture } from "../../test-fixtures"; + +const { Slot, nothing, command, harness } = vi.hoisted(() => ({ + Slot: ({ children }: { children?: ReactNode }) => children, + nothing: () => null, + command: vi.fn(), + harness: { actions: [] as MenuAction[], swipeEnabled: undefined as boolean | undefined }, +})); +vi.mock("react-native", () => ({ + Platform: { OS: "ios" }, + View: Slot, + Text: Slot, + Pressable: Slot, + useWindowDimensions: () => ({ width: 400, fontScale: 1 }), +})); +vi.mock("@effect/atom-react", () => ({ useAtomValue: () => false })); +vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({ navigate: command }) })); +vi.mock("../../components/ui/Dialog", () => ({})); +vi.mock("../../components/ui/RowPressable", () => ({ RowPressable: Slot })); +vi.mock("./CustomSnoozeSheet", () => ({ CustomSnoozeSheet: nothing })); +vi.mock("../../state/atom-registry", () => ({ appAtomRegistry: {} })); +vi.mock("../../state/thread-order", () => ({ threadArrangementOpenAtom: {} })); +vi.mock("../../state/threads", () => ({ threadEnvironment: { pendingSyncAtom: nothing } })); +vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => command })); +vi.mock("./use-visible-second-clock", () => ({ useVisibleSecondClock: () => 0 })); +vi.mock("../../components/ui/AppSymbol", () => ({ SymbolView: nothing })); +vi.mock("../../components/ui/AppText", () => ({ AppText: Slot })); +vi.mock("../../components/EnvironmentMachineSymbol", () => ({ EnvironmentMachineSymbol: nothing })); +vi.mock("../../components/ProjectFavicon", () => ({ ProjectFavicon: nothing })); +vi.mock("../../components/ProviderIcon", () => ({ + ProviderIcon: nothing, + ProviderInstanceIcon: nothing, + providerInstanceNameLabel: nothing, +})); +vi.mock("../../lib/clock", () => ({ useNowAfter: () => Date.UTC(2026, 10, 30) })); +vi.mock("../../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: command })); +vi.mock("../../lib/copyThreadReference", () => ({ copyThreadReference: command })); +vi.mock("../../lib/useUniwindTheme", () => ({ useUniwindTheme: () => ({}) })); +vi.mock("../../state/session", () => ({ + useEnvironmentScope: () => true, + useEnvironmentScopeDenied: () => false, +})); +vi.mock("../../state/pending-new-tasks-model", () => ({ + pendingDraftBranchNeedsRefs: nothing, + resolvePendingDraftBranch: nothing, +})); +vi.mock("../../state/queries", () => ({ useBranches: nothing })); +vi.mock("./use-new-task-project-defaults", () => ({ useNewTaskProjectDefaults: nothing })); +vi.mock("../../state/thread-pr-presentation", () => ({ resolveThreadPrBadgeAction: nothing })); +vi.mock("../../state/use-thread-pr", () => ({ useThreadPr: nothing })); +vi.mock("../home/swipe-row-activation", () => ({ useSwipeRowDormant: () => false })); +vi.mock("./turnThreadIntoProject", () => ({ + canTurnThreadIntoProject: () => false, + turnThreadIntoProject: command, +})); +vi.mock("../home/threadArchive", () => ({ threadCanArchive: () => true })); +vi.mock("./useCanShareWithGuest", () => ({ useCanShareWithGuest: () => false })); +vi.mock("./queued-message-icon", () => ({ QueuedMessageIcon: nothing })); +vi.mock("./thread-search-match", () => ({ ThreadSearchMatchExcerpt: nothing })); +vi.mock("../settings/appearance/useScaledTextRole", () => ({ + useScaledTextRole: () => ({ fontSize: 16, lineHeight: 20 }), +})); +vi.mock("../pull-requests/pullRequestGlyphs", () => ({ PullRequestGlyph: nothing })); +vi.mock("../pull-requests/pullRequestStatus", () => ({ pullRequestStatus: nothing })); +vi.mock("../../components/ui/Menu", () => ({ + Menu: ({ actions, children }: { actions: MenuAction[]; children: ReactNode }) => { + harness.actions = actions; + return children; + }, +})); +vi.mock("../home/thread-swipe-actions", () => ({ + ThreadSwipeable: ({ + enabled, + children, + }: { + enabled?: boolean; + children: (close: () => void) => ReactNode; + }) => { + harness.swipeEnabled = enabled !== false; + return children(command); + }, +})); + +import { ThreadListV2Row } from "./thread-list-v2-items"; + +it("keeps standing-root rename, pin and snooze menus while disabling only the settle swipe", async () => { + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); + const thread = makeThreadShellFixture({ + standing: { name: "Role", avatarId: "bolt", accent: "sky" }, + }); + const root = createRoot(document.createElement("div")); + const props = { + variant: "card", + wokeAt: null, + timeLabel: "", + snoozePresetMinute: "2026-11-30T00:00:00.000Z", + project: null, + providers: undefined, + providerInstance: null, + environmentLabel: null, + onSelectThread: command, + onOpenThreadPullRequests: command, + onDeleteThread: command, + onNewThreadOnBranch: command, + onRenameThread: command, + onRegenerateThreadTitle: command, + onSettleThread: async () => true, + onSnoozeThread: command, + onUnsnoozeThread: command, + onUnsettleThread: command, + onArchiveThread: command, + onPinThread: command, + onUnpinThread: command, + onSetThreadAutoSettle: command, + settlementSupported: true, + snoozeSupported: true, + snoozePresets: undefined, + pinningSupported: true, + autoSettleOptOutSupported: false, + titleRegenerationSupported: false, + onSwipeableWillOpen: command, + onSwipeableClose: command, + } as const; + const leafActions = (actions: readonly MenuAction[]): MenuAction[] => + actions.flatMap((action) => + action.subactions ? [action, ...leafActions(action.subactions)] : [action], + ); + try { + await act(() => root.render()); + const actions = leafActions(harness.actions); + expect(actions.map((action) => action.id)).toEqual( + expect.arrayContaining(["rename", "pin", "snooze"]), + ); + expect(actions.find((action) => action.id === "settle")?.attributes?.disabled).toBe(true); + expect(harness.swipeEnabled).toBe(false); + + const child = { + ...thread, + lineage: { ...thread.lineage, parentThreadId: ThreadId.make("parent") }, + }; + await act(() => root.render()); + expect( + leafActions(harness.actions).find((action) => action.id === "settle")?.attributes?.disabled, + ).toBe(false); + expect(harness.swipeEnabled).toBe(true); + } finally { + act(() => root.unmount()); + vi.unstubAllGlobals(); + } +}); diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx index d2893a9fd785a..7d23734526517 100644 --- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx +++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx @@ -28,6 +28,7 @@ import { } from "@t3tools/client-runtime/state/models"; import { AuthOrchestrationOperateScope, + isStandingThreadRoot, type EnvironmentId, type EnvironmentMachineKind, } from "@t3tools/contracts"; @@ -943,6 +944,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { !useEnvironmentScopeDenied(thread.environmentId, AuthOrchestrationOperateScope) && !canOperateThread; const canShareWithGuest = useCanShareWithGuest(thread.environmentId); + const isStandingRoot = isStandingThreadRoot(thread); const navigation = useNavigation(); const handleRegenerateTitle = useCallback( () => onRegenerateThreadTitle(thread), @@ -1181,7 +1183,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { nested, direct: [ ...direct, - localized(CARD_MENU_ACTIONS[0]!), + { + ...localized(CARD_MENU_ACTIONS[0]!), + attributes: { disabled: isStandingRoot }, + }, ...(swipeActions.secondary === "snooze" ? [ { @@ -1208,6 +1213,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { autoSettleMenuItems, canShareWithGuest, canUnsettle, + isStandingRoot, pinMenuItems, props.settlementSupported, reorderMenuItems, @@ -1371,8 +1377,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { : null, [gt, handleMenuAction, snoozePresetActions, swipeActions.secondary, thread.title], ); - const canSwipe = + const canUseRowActions = canOperateThread || (triageOnly && TRIAGE_MENU_ACTION_IDS.has(swipeActions.primary)); + const canSwipe = canUseRowActions && !(swipeActions.primary === "settle" && isStandingRoot); const swipeAccessibilityHint = !canSwipe ? gt("Opens the thread") : secondaryAction === null @@ -1771,7 +1778,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { ); - if (!canSwipe) + if (!canUseRowActions) return {rowContent(() => {})}; return ( @@ -1780,6 +1787,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { setCustomSnoozeOpen(false)} onSnooze={handleSnooze} /> )} }).pipe(Effect.provide(layerTest)), ); +it.effect.each(["thread.settle", "thread.auto-settle"] as const)( + "%s refuses a standing root without events, allows its persona child and permits retirement", + (type) => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const projections = yield* ProjectionStore.ProjectionStoreV2; + const events = yield* EventSink.EventSinkV2; + const threadId = ThreadId.make("thread:standing-root"); + yield* orchestrator.dispatch({ + type: "thread.create", + commandId: CommandId.make("standing-root:create"), + threadId, + projectId: ProjectId.make("project:standing-settle"), + title: "Role thread", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + createdBy: "user", + creationSource: "web", + }); + yield* orchestrator.dispatch({ + type: "thread.standing.set", + commandId: CommandId.make("standing-root:persona"), + threadId, + standing: { name: "Role", avatarId: "bolt", accent: "sky" }, + }); + const before = yield* projections.getThread(threadId); + const beforeSequence = yield* orchestrator.getThreadEventSequence(threadId); + const commandId = CommandId.make("standing-root:settle"); + const refused = yield* orchestrator + .dispatch({ type, commandId, threadId, snapshotAt: before.updatedAt }) + .pipe(Effect.flip); + assert.equal(refused._tag, "OrchestratorDispatchError"); + assert.include( + "cause" in refused ? String(refused.cause) : "", + "Clear its standing persona before settling", + ); + assert.deepEqual(yield* projections.getThread(threadId), before); + assert.equal(yield* orchestrator.getThreadEventSequence(threadId), beforeSequence); + assert.deepEqual(yield* events.readByCommandId({ commandId }).pipe(Stream.runCollect), []); + + const childId = ThreadId.make("thread:standing-child"); + yield* projections.apply({ + id: EventId.make("standing-child:create"), + type: "thread.created", + threadId: childId, + occurredAt: before.updatedAt, + payload: { + ...before, + id: childId, + lineage: { + parentThreadId: threadId, + rootThreadId: threadId, + relationshipToParent: "fork", + }, + }, + }); + yield* orchestrator.dispatch({ + type, + commandId: CommandId.make("standing-child:settle"), + threadId: childId, + snapshotAt: before.updatedAt, + }); + const child = yield* projections.getThread(childId); + assert.deepEqual(child.standing, before.standing); + assert.equal(child.settledOverride, "settled"); + + yield* orchestrator.dispatch({ + type: "thread.standing.set", + commandId: CommandId.make("standing-root:retire"), + threadId, + standing: null, + }); + const retired = yield* projections.getThread(threadId); + yield* orchestrator.dispatch({ + type, + commandId: CommandId.make("standing-root:settle-retired"), + threadId, + snapshotAt: retired.updatedAt, + }); + const settled = yield* projections.getThread(threadId); + assert.equal(settled.settledOverride, "settled"); + assert.isNull(settled.deletedAt); + }).pipe(Effect.provide(layerTest)), +); + it.effect("explicit settle clears snooze atomically and stays idempotent after re-snoozing", () => Effect.gen(function* () { const orchestrator = yield* Orchestrator.OrchestratorV2; diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index a2b36016d4467..aa2babc0b6341 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -9,6 +9,7 @@ import type { } from "@t3tools/contracts"; import { inboxAfterStandingSet, + isStandingThreadRoot, makeThreadInbox, nextFounderSeenMessage, nextFounderVisits, @@ -5613,6 +5614,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio } } if (command.type === "thread.settle") { + if (isStandingThreadRoot(thread)) { + return yield* new OrchestratorDispatchError({ + commandId: command.commandId, + commandType: command.type, + cause: + "Standing role threads cannot be settled. Clear its standing persona before settling.", + }); + } const projection = yield* loadProjectionForCommand( command, ["runs", "runtimeRequests", "providerThreads", "turnItems"], diff --git a/apps/server/src/orchestration-v2/ThreadManagementService.ts b/apps/server/src/orchestration-v2/ThreadManagementService.ts index 7a94212828310..2365a74894ff3 100644 --- a/apps/server/src/orchestration-v2/ThreadManagementService.ts +++ b/apps/server/src/orchestration-v2/ThreadManagementService.ts @@ -1,5 +1,9 @@ import * as SecureRandom from "effect/crypto/SecureRandom"; -import { BACKGROUND_WAIT_STALE_MINUTES, ThreadRedirectError } from "@t3tools/contracts"; +import { + BACKGROUND_WAIT_STALE_MINUTES, + isStandingThreadRoot, + ThreadRedirectError, +} from "@t3tools/contracts"; import { staleTimeoutMs } from "./waitStaleness.ts"; import type { OrchestrationV2SearchThreadInput, @@ -1561,7 +1565,7 @@ const make = Effect.gen(function* () { "orchestrationV2.threadManagement.settleThread", )(function* (input) { const shell = input.byOwnAgent ? yield* orchestrator.getThreadShell(input.threadId) : null; - if (shell != null && shell.activeRunId !== null) { + if (shell != null && shell.activeRunId !== null && !isStandingThreadRoot(shell)) { yield* settleAfterRun({ projectId: shell.projectId, threadId: shell.id, diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts index ce0a605ccc513..8535745aeed3f 100644 --- a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts @@ -336,6 +336,16 @@ describe("settlesFinishedAgentWork", () => { }), ), ).toBe(false); + const child = finished("completed", { + standing: { name: "Ops", role: null, avatarId: "bolt", accent: "sky" }, + lineage: { + parentThreadId: ThreadId.make("role-root"), + rootThreadId: ThreadId.make("role-root"), + relationshipToParent: "subagent", + }, + }); + expect(ThreadSettlementService.settlesFinishedAgentWork(child)).toBe(true); + expect(ThreadSettlementService.isAutoSettlementCandidate(child, NOW_MS)).toBe(true); expect(ThreadSettlementService.settlesFinishedAgentWork(shell({ status: "completed" }))).toBe( false, ); diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.ts index 517233420c259..d86583515ddad 100644 --- a/apps/server/src/orchestration-v2/ThreadSettlementService.ts +++ b/apps/server/src/orchestration-v2/ThreadSettlementService.ts @@ -9,6 +9,7 @@ import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests"; import { CommandId, isDelegatedAppThread, + isStandingThreadRoot, isOrchestrationV2WorkActive, type ThreadId, type OrchestrationV2DomainEvent, @@ -191,10 +192,10 @@ function agentBackgroundWorkPending( export function settlesFinishedAgentWork( thread: Pick< ProjectionStore.ProjectionSettlementCandidate, - "inbox" | "status" | "pendingBackgroundTasks" | "standing" + "inbox" | "status" | "pendingBackgroundTasks" | "standing" | "lineage" >, ): boolean { - if (thread.standing != null || thread.inbox?.audience !== "agent-only") return false; + if (isStandingThreadRoot(thread) || thread.inbox?.audience !== "agent-only") return false; // An unattributed conversation uses Agents for routing without becoming autonomous work. if (thread.inbox.origin === null) return false; if (!FINISHED_AGENT_RUN_STATUSES.has(thread.status)) return false; @@ -213,8 +214,7 @@ export function isAutoSettlementCandidate( return false; } if (thread.inbox?.audience === "agent-only" && thread.status === "failed") return false; - // A standing bot is a long-lived lane, never finished work. - if (thread.standing != null) return false; + if (isStandingThreadRoot(thread)) return false; if (thread.pendingRuntimeRequest !== null) return false; // A guest is waiting on the owner; settling would hide the Request. if ((thread.pendingGuestMessageCount ?? 0) > 0) return false; diff --git a/apps/web/src/components/Sidebar.bulk-settle.test.ts b/apps/web/src/components/Sidebar.bulk-settle.test.ts new file mode 100644 index 0000000000000..7def60a92ae93 --- /dev/null +++ b/apps/web/src/components/Sidebar.bulk-settle.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vite-plus/test"; +import { ThreadId } from "@t3tools/contracts"; +import { makeThreadFixture } from "../test-fixtures"; +import { selectSidebarSettleTargets } from "./Sidebar.logic"; + +const role = makeThreadFixture({ standing: { name: "Role", avatarId: "bolt", accent: "sky" } }); +const child = makeThreadFixture({ + id: ThreadId.make("child"), + standing: role.standing, + lineage: { ...role.lineage, parentThreadId: role.id }, +}); +const regular = makeThreadFixture({ id: ThreadId.make("regular") }); +const settled = makeThreadFixture({ id: ThreadId.make("settled"), settledOverride: "settled" }); + +describe("standing roots in sidebar bulk settlement", () => { + it("has no settle targets for a root-only selection, disabling bulk Settle", () => { + expect(selectSidebarSettleTargets([role])).toEqual([]); + }); + it("only dispatches eligible children and ordinary threads from a mixed selection", () => { + expect(selectSidebarSettleTargets([role, child, regular, settled])).toEqual([child, regular]); + expect(selectSidebarSettleTargets([{ ...regular, standing: role.standing }])).toEqual([]); + }); +}); diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 865fe67f76562..9f7e68821e56b 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -20,6 +20,7 @@ import { import { foldSearchQuery, rankSearchItems, scoreThreadSearch } from "@t3tools/shared/paletteSearch"; import { scheduledTaskThreadMode, + isStandingThreadRoot, SYS_DAEMON_STANDING_ROLE, type ContextMenuItem, type EnvironmentId, @@ -58,6 +59,14 @@ import { shortcutModifierStore } from "../shortcutModifierState"; import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore"; import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore"; +export function selectSidebarSettleTargets< + T extends Pick, +>(threads: readonly T[]): T[] { + return threads.filter( + (thread) => thread.settledOverride !== "settled" && !isStandingThreadRoot(thread), + ); +} + export function shouldNavigateAfterThreadPark(input: { readonly threadKey: string; readonly currentThreadKey: string | null; diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 4d339c9407ebe..301c01602d23f 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -22,6 +22,7 @@ import { m } from "../i18n/messages"; import { attachSidebarTree } from "../lib/sidebarTree"; import { effectiveInboxFilter, + isStandingThreadRoot, isHiddenFromFounder, staysActiveWhileWorking, type EnvironmentId, @@ -215,6 +216,7 @@ import { } from "./threadActionMenu.logic"; import { applySidebarThreadDrop, + selectSidebarSettleTargets, filterSidebarV2VisibleThreads, freshSessionThreadKeys, groupSidebarThreadsByProject, @@ -1889,10 +1891,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- registers this sidebar's settle handler in the module-level settleAndAdvance registry useEffect(() => registerSettleAndAdvance(attemptSettle), [attemptSettle]); const settleThreads = (threadKeys: readonly string[]) => { - const coSettlingKeys = new Set(threadKeys); - for (const threadKey of threadKeys) { + const settleable = threadKeys.flatMap((threadKey) => { const thread = threadByKeyRef.current.get(threadKey); - if (!thread || thread.settledOverride === "settled") continue; + if (!thread || thread.settledOverride === "settled" || isStandingThreadRoot(thread)) { + return []; + } + return [{ threadKey, thread }]; + }); + const coSettlingKeys = new Set(settleable.map((entry) => entry.threadKey)); + for (const { thread } of settleable) { attemptSettle(scopeThreadRef(thread.environmentId, thread.id), { coSettlingKeys }); } }; @@ -2057,7 +2064,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve return ( thread !== undefined && sectionByThreadKeyRef.current.get(key) === originSection && - serverConfigs.has(thread.environmentId) + serverConfigs.has(thread.environmentId) && + (action !== "settle" || !isStandingThreadRoot(thread)) ); }; let targetKey: string | null = null; @@ -2314,7 +2322,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve activeSection: draggedFromSection, activePinned: source.pinnedAt != null, activeSettled: source.settledOverride === "settled", - supportsSettlement: serverConfigs.has(source.environmentId), + supportsSettlement: + serverConfigs.has(source.environmentId) && !isStandingThreadRoot(source), target, pinnedOrder: pinnedKeys, pinnedKeysById, @@ -2348,7 +2357,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve activeSection, activePinned: activeThread.pinnedAt != null, activeSettled: activeThread.settledOverride === "settled", - supportsSettlement: serverConfigs.has(activeThread.environmentId), + supportsSettlement: + serverConfigs.has(activeThread.environmentId) && !isStandingThreadRoot(activeThread), target, pinnedOrder: pinnedKeys, pinnedKeysById, @@ -2552,9 +2562,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const thread = threadByKeyRef.current.get(threadKey); return thread ? [thread] : []; }); - const settlingThreads = selectedThreads.filter( - (thread) => thread.settledOverride !== "settled", - ); + const settlingThreads = selectSidebarSettleTargets(selectedThreads); const canSnoozeSelection = selectedThreads.every( (thread) => serverConfigs.has(thread.environmentId) && @@ -2650,7 +2658,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const current = threadByKeyRef.current.get( scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)), ); - return current && current.settledOverride !== "settled" ? [current] : []; + return current ? selectSidebarSettleTargets([current]) : []; }) : selectedThreads; if (clicked.value === "settle" && actionTargets.length === 0) return; @@ -2908,6 +2916,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve AuthOrchestrationOperateScope, ), canTriage: threadTriagePermitted(threadRef.environmentId), + canSettle: !isStandingThreadRoot(thread), branch: thread.branch ?? null, // An archived project is not a filter choice. projectFilter: diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index 4cf925732481b..45b19d9896261 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -31,6 +31,7 @@ import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environ import { toServerClock } from "@t3tools/client-runtime/clock"; import { AuthOrchestrationOperateScope, + isStandingThreadRoot, type ContextMenuSource, type EnvironmentId, type EnvironmentMachineKind, @@ -1562,6 +1563,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP type="button" aria-label={gt("Settle thread")} onClick={handleSettleClick} + disabled={isStandingThreadRoot(thread)} onPointerDown={handleActionPointerDown} className={cn( "pointer-events-none absolute inset-y-0 right-0 -mr-2 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-2 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 group-any-hover/sidebar-row:pointer-events-auto group-any-hover/sidebar-row:opacity-100", @@ -1772,6 +1774,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP type="button" aria-label={gt("Settle thread")} onClick={handleSettleClick} + disabled={isStandingThreadRoot(thread)} onPointerDown={handleActionPointerDown} className="-mr-1 inline-flex cursor-pointer items-center gap-1 rounded-md bg-transparent px-1.5 text-xs text-muted-foreground hover:text-foreground" /> diff --git a/apps/web/src/components/threadActionMenu.logic.test.ts b/apps/web/src/components/threadActionMenu.logic.test.ts index 11674cdfad875..59cf9a88dc5ad 100644 --- a/apps/web/src/components/threadActionMenu.logic.test.ts +++ b/apps/web/src/components/threadActionMenu.logic.test.ts @@ -31,6 +31,17 @@ const baseState: ThreadActionMenuState = { }; describe("buildThreadActionMenuItems", () => { + it("disables settling when the thread is a standing root while keeping un-settle available", () => { + const items = buildThreadActionMenuItems({ ...baseState, canSettle: false }); + expect(items.find((item) => item.id === "settle")?.disabled).toBe(true); + const settled = buildThreadActionMenuItems({ + ...baseState, + canSettle: false, + isSettled: true, + }); + expect(settled.find((item) => item.id === "unsettle")?.disabled).not.toBe(true); + }); + it.each([false, true])( "disables both lifecycle directions without permission (reversed: %s)", (reversed) => { diff --git a/apps/web/src/components/threadActionMenu.logic.ts b/apps/web/src/components/threadActionMenu.logic.ts index 3dabb0c4fbe66..a74c5d577bfc5 100644 --- a/apps/web/src/components/threadActionMenu.logic.ts +++ b/apps/web/src/components/threadActionMenu.logic.ts @@ -106,6 +106,7 @@ export interface ThreadActionMenuState { readonly canOperate: boolean; /** Settle, snooze and their undo stay available until the host denies the operate scope. */ readonly canTriage?: boolean; + readonly canSettle?: boolean; readonly canFind?: boolean; /** False where no inline title editor is rendered, such as sidebar search results. */ readonly canRename?: boolean; @@ -240,7 +241,12 @@ export function buildThreadActionMenuItems( label: resolve(msg("Un-settle thread")), icon: "circle-check", } - : { id: "settle" as const, label: resolve(msg("Settle thread")), icon: "circle-check" }, + : { + id: "settle" as const, + label: resolve(msg("Settle thread")), + icon: "circle-check", + disabled: state.canSettle === false, + }, ] : []), ...(state.supports.snooze diff --git a/apps/web/src/hooks/useThreadActionMenu.ts b/apps/web/src/hooks/useThreadActionMenu.ts index 9b9afad3a49b3..acc485adbd06d 100644 --- a/apps/web/src/hooks/useThreadActionMenu.ts +++ b/apps/web/src/hooks/useThreadActionMenu.ts @@ -11,6 +11,7 @@ import { import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; import { AuthOrchestrationOperateScope, + isStandingThreadRoot, type ScopedThreadRef, type ThreadId, type ContextMenuSource, @@ -140,6 +141,7 @@ export function useThreadActionMenu(input: { const items = buildThreadActionMenuItems({ canOperate: readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope), canTriage: threadTriagePermitted(threadRef.environmentId), + canSettle: !isStandingThreadRoot(thread), canFind: onFind !== undefined, canRename: onStartRename !== undefined, branch: thread.branch ?? null, diff --git a/docs/FEATURES.md b/docs/FEATURES.md index e9733813cde42..78bba54aa0279 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -6,7 +6,7 @@ Each entry is a user-facing feature: how a user reaches it, how an agent drives Last sweep: 903b140c21 on 2026-11-27, target: local build. Projects: desktop (1440×900) and phone (390×844), each in light and dark. -**63 verified, 0 broken, 8 unverified** of 71 features. +**63 verified, 0 broken, 9 unverified** of 72 features. ## Sidebar @@ -50,6 +50,14 @@ Last sweep: 903b140c21 on 2026-11-27, target: local build. Projects: desktop (14 - **Code:** `apps/web/src/components/sidebar/`, `apps/web/src/components/Sidebar.tsx` - **Status:** verified: 903b140c21 2026-11-27 +### sidebar.thread-settlement — Settle threads from the sidebar + +- **Path:** Right-click a thread row or a selection of threads to open the Settle action. +- **Drive:** 1. open the context menu on a standing bot root and check that Settle thread is disabled 2. select the root together with a child fork listed in the sidebar and choose Settle 3. check that the child moves to Settled and the standing root stays available +- **Success:** Individual and bulk actions keep standing bot roots available. Child threads can still settle. +- **Code:** `apps/web/src/components/Sidebar.tsx`, `apps/web/src/components/Sidebar.logic.ts`, `apps/web/src/components/sidebar/SidebarThreadRow.tsx` +- **Status:** unverified: The click QA fixture has no standing root or inherited-persona child. Sidebar regression tests cover bulk eligibility. + ### sidebar.footer-links — Footer links - **Path:** Sidebar footer → Settings, Pull requests, Issues, Usage. diff --git a/packages/contracts/src/threadStanding.ts b/packages/contracts/src/threadStanding.ts index 0da430f97fdf1..a80f2ec7bd4c7 100644 --- a/packages/contracts/src/threadStanding.ts +++ b/packages/contracts/src/threadStanding.ts @@ -76,6 +76,13 @@ export const StoredThreadStanding = Schema.NullOr( ).pipe(Schema.catchDecoding(() => Effect.succeedSome(null))); export type StoredThreadStanding = typeof StoredThreadStanding.Type; +export function isStandingThreadRoot(thread: { + readonly standing?: unknown; + readonly lineage: { readonly parentThreadId: string | null }; +}): boolean { + return thread.standing != null && thread.lineage.parentThreadId === null; +} + export function resolveThreadStandingAvatarId(avatarId: string): ThreadStandingAvatarId { return (THREAD_STANDING_AVATAR_IDS as readonly string[]).includes(avatarId) ? (avatarId as ThreadStandingAvatarId) diff --git a/qa/features.ts b/qa/features.ts index c50bdc690d4b0..4caf6d867ac38 100644 --- a/qa/features.ts +++ b/qa/features.ts @@ -98,6 +98,22 @@ export const FEATURES: ReadonlyArray = [ "The menu lists thread actions; pinning adds the Pinned section and unpinning removes it.", code: [`${C}sidebar/`, `${C}Sidebar.tsx`], }), + f({ + id: "sidebar.thread-settlement", + area: "Sidebar", + title: "Settle threads from the sidebar", + path: "Right-click a thread row or a selection of threads to open the Settle action.", + drive: [ + "open the context menu on a standing bot root and check that Settle thread is disabled", + "select the root together with a child fork listed in the sidebar and choose Settle", + "check that the child moves to Settled and the standing root stays available", + ], + success: + "Individual and bulk actions keep standing bot roots available. Child threads can still settle.", + code: [`${C}Sidebar.tsx`, `${C}Sidebar.logic.ts`, `${C}sidebar/SidebarThreadRow.tsx`], + unverified: + "The click QA fixture has no standing root or inherited-persona child. Sidebar regression tests cover bulk eligibility.", + }), f({ id: "sidebar.footer-links", area: "Sidebar",