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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/mobile/src/features/home/useThreadListActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) ||
Expand Down
155 changes: 155 additions & 0 deletions apps/mobile/src/features/threads/thread-list-v2-items.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<ThreadListV2Row {...props} thread={thread} />));
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(<ThreadListV2Row {...props} thread={child} />));
expect(
leafActions(harness.actions).find((action) => action.id === "settle")?.attributes?.disabled,
).toBe(false);
expect(harness.swipeEnabled).toBe(true);
} finally {
act(() => root.unmount());
vi.unstubAllGlobals();
}
});
14 changes: 11 additions & 3 deletions apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "@t3tools/client-runtime/state/models";
import {
AuthOrchestrationOperateScope,
isStandingThreadRoot,
type EnvironmentId,
type EnvironmentMachineKind,
} from "@t3tools/contracts";
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"
? [
{
Expand All @@ -1208,6 +1213,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
autoSettleMenuItems,
canShareWithGuest,
canUnsettle,
isStandingRoot,
pinMenuItems,
props.settlementSupported,
reorderMenuItems,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1771,7 +1778,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
</RowPressable>
);

if (!canSwipe)
if (!canUseRowActions)
return <View style={rowAppearance.swipeContainerStyle}>{rowContent(() => {})}</View>;

return (
Expand All @@ -1780,6 +1787,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
<CustomSnoozeSheet onClose={() => setCustomSnoozeOpen(false)} onSnooze={handleSnooze} />
)}
<ThreadSwipeable
enabled={canSwipe}
dormant={dormant}
threadKey={`${thread.environmentId}:${thread.id}`}
backgroundColor={rowAppearance.swipeBackgroundColor}
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
import "vite-plus/test/config";

const reactTests = [
"src/features/threads/thread-list-v2-items.test.tsx",
"src/features/browser/LocalPreviewRouteScreen.test.tsx",
"src/features/threads/LinkedThreadSheet.test.tsx",
"src/features/workflows/WorkflowStepCard.test.tsx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,94 @@ it.effect("replays a thread.create receipt without changing the thread", () =>
}).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;
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from "@t3tools/contracts";
import {
inboxAfterStandingSet,
isStandingThreadRoot,
makeThreadInbox,
nextFounderSeenMessage,
nextFounderVisits,
Expand Down Expand Up @@ -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"],
Expand Down
Loading
Loading