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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This is a personal fork of [pingdotgg/t3code](https://github.com/pingdotgg/t3cod

- **Open threads from links.** The desktop app opens `t3code://app/<environmentId>/<threadId>` links (`t3code-dev://` for Dev builds) from other apps and from pages in the built-in browser, whether it is already running or starts from the link. Use `primary` as the environment ID for the desktop's own environment. When tag hiding is off, archived threads open too, with an archived notice and an Unarchive button above the composer. A link to an unknown environment or thread shows a short error instead. Upstream's prompt links (`t3code://new`, `t3code://threads/…`) follow the same rules: each build answers only its own scheme, and a thread link opens in the active split pane.

- **Archive when done.** Archiving a working thread, from its menu, the command palette, the archive shortcut, mobile, or the `/t3-archive` composer command, waits until the turn, its checkpoint, any subagents, and any commands or monitors the agent waits on finish. Automatic follow-ups such as subagent results don't cancel it; a new message does. A pending archive shows an archive icon on the thread's row, and the same actions cancel it. Archiving an idle thread that has queued messages, including messages held by Stop, always asks first and names the count, even with archive confirmation off; confirming archives it now and discards them. Agents can archive their own thread, or pass `threadId` to archive another one they have read and no longer need, with `archive_thread` (inspected or cancelled with `archive_thread_status` and `cancel_thread_archive`), optionally removing its clean worktree while keeping the branch (never an SP Labs lab). Requests survive restarts. Like a manual archive, it also archives the thread's side chats, and sending a message to an archived thread unarchives it and those side chats first. Agents can use `archive_thread` with `includeDescendants: true` to archive finished child and subagent threads in the same call; active descendants are skipped and reported. Shared-worktree refusals report the blocker count and up to ten thread ids, titles, and states.
- **Archive when done.** Archiving a working thread, from its menu, the command palette, the archive shortcut, or mobile, waits until the turn, its checkpoint, any subagents, and any commands or monitors the agent waits on finish. Automatic follow-ups such as subagent results don't cancel it; a new message does. A pending archive shows an archive icon on the thread's row, and the same actions cancel it. Archiving discards queued messages, including messages held by Stop: the thread's own when it archives now, and those of the side chats it takes either way. It always asks first and names the count, even with archive confirmation off. Agents can archive their own thread, or pass `threadId` to archive another one they have read and no longer need, with `archive_thread` (inspected or cancelled with `archive_thread_status` and `cancel_thread_archive`), optionally removing its clean worktree while keeping the branch (never an SP Labs lab). Requests survive restarts. Like a manual archive, it also archives the thread's side chats, and sending a message to an archived thread unarchives it and those side chats first. Agents can use `archive_thread` with `includeDescendants: true` to archive finished child and subagent threads in the same call; active descendants are skipped and reported. Shared-worktree refusals report the blocker count and up to ten thread ids, titles, and states.

- **Thread tools for agents.** Agents can list custom thread groups with their thread counts, create a group, and move a thread into a group or back to Active with `t3_thread_groups`, and can start new threads directly in a group by passing `groupId` to `t3_thread_launch` or `create_threads`; renaming, deleting, and reordering groups stay with you. `t3_thread_drain_status` tells an agent whether a thread is fully quiet (no active or queued run, no subagents, monitors, or background commands left), for example before handing its session to another machine. `t3_thread_list` can list every project at once and find the threads bound to a worktree path. When a thread an agent started with `t3_thread_launch` fails workspace preparation on the same machine (a branch already in use, a reserved lab), that agent gets a message with the error so it can launch again.

Expand Down
24 changes: 18 additions & 6 deletions apps/mobile/src/features/home/threadArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@ import {
type ThreadRuntimeSummary,
} from "@t3tools/client-runtime/state/models";

import type { ArchiveQueuedMessageDiscard } from "@t3tools/client-runtime/state/thread-settled";

import * as Dialog from "../../components/ui/Dialog";

export function threadCanArchive(runtime: ThreadRuntimeSummary | null | undefined): boolean {
return threadRuntimeCanArchive(runtime);
}

/** Fork: asks before archiving now discards a thread's queued messages. */
/** Fork: asks before an archive discards queued messages of a thread or its side chats. */
export function confirmQueuedMessageDiscard(input: {
readonly title: string;
readonly count: number;
readonly discarded: ArchiveQueuedMessageDiscard;
readonly whenDone: boolean;
readonly onConfirm: () => void;
readonly onCancel?: () => void;
}): void {
const { total, inSideChats } = input.discarded;
const waiting =
inSideChats === 0
? `“${input.title}” has`
: inSideChats === total
? `Side chats of “${input.title}” have`
: `“${input.title}” and its side chats have`;
Dialog.confirm({
title: `Archive and discard ${input.count} queued ${input.count === 1 ? "message" : "messages"}?`,
message: `“${input.title}” has messages waiting to run. Archiving discards them.`,
title: `Archive${input.whenDone ? " when done" : ""} and discard ${total} queued ${total === 1 ? "message" : "messages"}?`,
message: `${waiting} messages waiting to run. Archiving discards them.${
inSideChats === 0
? ""
: " A side chat still running a delegated task stays open and keeps its messages."
}`,
confirmText: "Archive",
destructive: true,
onConfirm: input.onConfirm,
...(input.onCancel === undefined ? {} : { onCancel: input.onCancel }),
});
}
24 changes: 24 additions & 0 deletions apps/mobile/src/features/home/useThreadListActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,30 @@ describe("thread archive guard", () => {
]);
});

it("re-reads side chat queues after the discard confirmation", async () => {
const sideChat = (queuedMessageCount: number) =>
makeThread({
id: ThreadId.make("side"),
lineage: {
parentThreadId: ThreadId.make("thread"),
relationshipToParent: "fork",
rootThreadId: ThreadId.make("thread"),
sideChat: true,
},
queuedMessageCount,
});
state.shells = [makeThread(), sideChat(1)];
expect(await useThreadListActions().archiveThread(makeThread())).toBe(false);
// A queue that grew while the dialog was open asks again instead of archiving.
state.shells = [makeThread(), sideChat(2)];
state.dialogs[0]?.onConfirm();
expect(state.dialogs).toHaveLength(2);
state.dialogs[1]?.onConfirm();
await vi.waitFor(() =>
expect(state.requests).toEqual([expect.objectContaining({ action: "archive" })]),
);
});

it("archives when done from a row held from before the run started", async () => {
state.shells = [
makeThread({
Expand Down
41 changes: 30 additions & 11 deletions apps/mobile/src/features/home/useThreadListActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ 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 {
archiveDiscardedQueuedMessageCount,
type ArchiveQueuedMessageDiscard,
type ArchiveToggleAction,
archiveDiscardedQueuedMessages,
discardExceedsConfirmed,
canSnooze,
resolveArchiveToggleAction,
} from "@t3tools/client-runtime/state/thread-settled";
Expand Down Expand Up @@ -454,21 +457,36 @@ export function useThreadListActions(
const titleRegenerationInFlightThreadKeys = useRef(new Set<string>());

/**
* The archive toggle: archives, archives when done, or cancels a pending archive. Archiving
* now discards queued messages, so that always confirms first, offline from the cached shell.
* The archive toggle: archives, archives when done, or cancels a pending archive. Discarding
* queued messages, the thread's or its side chats', always confirms first, offline from cache.
*/
const archiveThread = (thread: EnvironmentThreadShell, discardConfirmed = false) => {
const discardedCount = archiveDiscardedQueuedMessageCount(thread);
if (discardedCount > 0 && !discardConfirmed) {
const archiveThread = (
thread: EnvironmentThreadShell,
confirmed?: {
readonly toggle: ArchiveToggleAction;
readonly discarded: ArchiveQueuedMessageDiscard;
},
): Promise<boolean> => {
const toggle = resolveArchiveToggleAction(thread);
// The thread can change while the dialog is open: a changed action does nothing.
if (confirmed !== undefined && confirmed.toggle !== toggle) return Promise.resolve(false);
const discarded = archiveDiscardedQueuedMessages(
thread,
appAtomRegistry.get(environmentThreadShells.threadShellsAtom),
);
if (
confirmed === undefined
? discarded.total > 0
: discardExceedsConfirmed(discarded, confirmed.discarded)
) {
confirmQueuedMessageDiscard({
title: thread.title,
count: discardedCount,
// The thread can change while the dialog is open (a resumed turn must not be archived).
onConfirm: () => void archiveThread(liveThread(thread), true),
discarded,
whenDone: toggle === "schedule",
onConfirm: () => void archiveThread(liveThread(thread), { toggle, discarded }),
});
return Promise.resolve(false);
}
const toggle = resolveArchiveToggleAction(thread);
return executeAction(
toggle === "cancel"
? "cancel-archive"
Expand All @@ -478,7 +496,8 @@ export function useThreadListActions(
thread,
undefined,
undefined,
discardConfirmed && discardedCount > 0,
// Replay may archive now only over the thread's own confirmed queue.
confirmed !== undefined && discarded.total > discarded.inSideChats,
);
};
const offerUndo = (
Expand Down
54 changes: 1 addition & 53 deletions apps/mobile/src/features/settings/lib/extras-settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
import {
MAX_ACCENT_TINT_INTENSITY_PERCENT,
MAX_STEER_GRACE_WINDOW_MS,
MIN_ACCENT_TINT_INTENSITY_PERCENT,
MIN_STEER_GRACE_WINDOW_MS,
} from "@t3tools/contracts/settings";
import { describe, expect, it } from "vite-plus/test";

import {
formatAccentTintIntensityPercent,
formatSteerGraceWindowSeconds,
toStoredAccentTintIntensityPercent,
toStoredArchivedSectionVisibleCount,
toStoredSteerGraceWindowMs,
} from "./extras-settings";

describe("formatSteerGraceWindowSeconds", () => {
it("reads the stored milliseconds as seconds with one decimal", () => {
expect(formatSteerGraceWindowSeconds(5_000)).toBe("5.0s");
expect(formatSteerGraceWindowSeconds(2_500)).toBe("2.5s");
expect(formatSteerGraceWindowSeconds(MIN_STEER_GRACE_WINDOW_MS)).toBe("0.0s");
expect(formatSteerGraceWindowSeconds(MAX_STEER_GRACE_WINDOW_MS)).toBe("15.0s");
});
});

describe("toStoredArchivedSectionVisibleCount", () => {
it("rounds and clamps the archived count", () => {
expect(toStoredArchivedSectionVisibleCount(10.4)).toBe(10);
expect(toStoredArchivedSectionVisibleCount(-5)).toBe(1);
expect(toStoredArchivedSectionVisibleCount(100)).toBe(50);
});
});

describe("formatAccentTintIntensityPercent", () => {
it("reads the stored intensity as a percentage", () => {
expect(formatAccentTintIntensityPercent(12)).toBe("12%");
});
});
import { toStoredSteerGraceWindowMs } from "./extras-settings";

describe("toStoredSteerGraceWindowMs", () => {
it("snaps to the half-second step the slider moves in", () => {
expect(toStoredSteerGraceWindowMs(2_499)).toBe(2_500);
expect(toStoredSteerGraceWindowMs(2_749)).toBe(2_500);
expect(toStoredSteerGraceWindowMs(2_751)).toBe(3_000);
});

it("clamps to the contract bounds rather than storing an out-of-range window", () => {
expect(toStoredSteerGraceWindowMs(-1_000)).toBe(MIN_STEER_GRACE_WINDOW_MS);
expect(toStoredSteerGraceWindowMs(60_000)).toBe(MAX_STEER_GRACE_WINDOW_MS);
});
});

describe("toStoredAccentTintIntensityPercent", () => {
it("stores whole percentages", () => {
expect(toStoredAccentTintIntensityPercent(12.4)).toBe(12);
expect(toStoredAccentTintIntensityPercent(12.6)).toBe(13);
});

it("clamps to the contract bounds", () => {
expect(toStoredAccentTintIntensityPercent(0)).toBe(MIN_ACCENT_TINT_INTENSITY_PERCENT);
expect(toStoredAccentTintIntensityPercent(99)).toBe(MAX_ACCENT_TINT_INTENSITY_PERCENT);
});
});
16 changes: 0 additions & 16 deletions apps/mobile/src/features/threads/use-composer-command-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ describe("resolveComposerMenuSelection", () => {
});

describe("mobile slash commands", () => {
it("offers archive only for an existing thread and inserts it for submission", () => {
const input = { query: "t3-arch", atMessageStart: true, selectedProviderStatus: null };
expect(buildComposerSlashCommandItems({ ...input, hasThread: false })).toEqual([]);
const items = buildComposerSlashCommandItems({ ...input, hasThread: true });
expect(items).toHaveLength(1);
const item = items[0];
if (!item) throw new Error("Expected archive command");
expect(
resolveComposerCommandSelection({
draftMessage: "/t3-arch",
trigger: { rangeStart: 0, rangeEnd: 8 },
item,
}),
).toEqual({ text: "/t3-archive ", cursor: 12 });
});

it("keeps a provider's native /plan", () => {
const items = buildComposerSlashCommandItems({
query: "pl",
Expand Down
32 changes: 11 additions & 21 deletions apps/mobile/src/features/threads/use-composer-command-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,17 @@ export function buildComposerSlashCommandItems(
resolve: MessageResolver = m,
): ComposerCommandItem[] {
const query = input.query.toLowerCase();
const builtIn = [
{
id: "cmd:model",
type: "slash-command",
command: "model",
label: "/model",
description: resolve(msg("Switch model")),
},
...(input.hasThread
? [
{
id: "cmd:t3-archive",
type: "slash-command" as const,
command: "t3-archive",
label: "/t3-archive",
description: "Archive now or when done; send again to cancel",
},
]
: []),
] satisfies ComposerCommandItem[];
const items: ComposerCommandItem[] = builtIn.filter((item) => item.command.includes(query));
const items: ComposerCommandItem[] = "model".includes(query)
? [
{
id: "cmd:model",
type: "slash-command",
command: "model",
label: "/model",
description: resolve(msg("Switch model")),
},
]
: [];

// Providers expand commands only at the start of a message. T3 commands
// change local state and do not have this restriction, except `/clear`.
Expand Down
29 changes: 12 additions & 17 deletions apps/mobile/src/persistence/mobile-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ export interface Preferences {
readonly sidebarSnoozedShelfExpanded?: boolean;
readonly sidebarSettledShelfExpanded?: boolean;
readonly sidebarArchivedShelfExpanded?: boolean;
/**
* Upstream's shelf keys. The fork's `sidebar*ShelfExpanded` keys above own
* settled/snoozed fold state; these stay decoded for upstream compatibility.
* Only the Working shelf reads its own key.
*/
readonly threadListSettledShelfExpanded?: boolean;
readonly threadListSnoozedShelfExpanded?: boolean;
readonly threadListWorkingShelfExpanded?: boolean;
readonly toolCallVisibility?: ToolCallVisibility;
readonly workingShelfEnabled?: boolean;
readonly useLastProjectForNewThreads?: boolean;
Expand All @@ -197,6 +189,9 @@ export interface Preferences {
readonly provider: ProviderInstanceId;
readonly model: string;
}>;
readonly threadListSettledShelfExpanded?: boolean;
readonly threadListSnoozedShelfExpanded?: boolean;
readonly threadListWorkingShelfExpanded?: boolean;
/**
* Device-local mirror of the web fork's Extras settings. Numbers are stored
* raw and clamped on read (see `state/use-mobile-preferences`), because the
Expand Down Expand Up @@ -291,19 +286,19 @@ export function sanitizePreferences(parsed: Preferences): Preferences {
microphones?: ReadonlyArray<MicrophoneEntry>;
projectGroupingEnabled?: boolean;
projectGroupingMode?: SidebarProjectGroupingMode;
toolCallVisibility?: ToolCallVisibility;
workingShelfEnabled?: boolean;
sidebarPinnedShelfExpanded?: boolean;
sidebarActiveShelfExpanded?: boolean;
sidebarSnoozedShelfExpanded?: boolean;
sidebarSettledShelfExpanded?: boolean;
sidebarArchivedShelfExpanded?: boolean;
useLastProjectForNewThreads?: boolean;
lastThreadProject?: typeof ThreadProject.Type;
modelFavorites?: Preferences["modelFavorites"];
threadListSettledShelfExpanded?: boolean;
threadListSnoozedShelfExpanded?: boolean;
threadListWorkingShelfExpanded?: boolean;
toolCallVisibility?: ToolCallVisibility;
workingShelfEnabled?: boolean;
modelFavorites?: Preferences["modelFavorites"];
steerGraceWindowMs?: number;
accentTintsEnabled?: boolean;
accentTintIntensityPercent?: number;
Expand Down Expand Up @@ -455,12 +450,6 @@ export function sanitizePreferences(parsed: Preferences): Preferences {
if (typeof parsed.sidebarArchivedShelfExpanded === "boolean") {
preferences.sidebarArchivedShelfExpanded = parsed.sidebarArchivedShelfExpanded;
}
if (typeof parsed.threadListSettledShelfExpanded === "boolean") {
preferences.threadListSettledShelfExpanded = parsed.threadListSettledShelfExpanded;
}
if (typeof parsed.threadListSnoozedShelfExpanded === "boolean") {
preferences.threadListSnoozedShelfExpanded = parsed.threadListSnoozedShelfExpanded;
}
if (isToolCallVisibility(parsed.toolCallVisibility)) {
preferences.toolCallVisibility = parsed.toolCallVisibility;
}
Expand All @@ -484,6 +473,12 @@ export function sanitizePreferences(parsed: Preferences): Preferences {
favorite.model.trim().length > 0,
);
}
if (typeof parsed.threadListSettledShelfExpanded === "boolean") {
preferences.threadListSettledShelfExpanded = parsed.threadListSettledShelfExpanded;
}
if (typeof parsed.threadListSnoozedShelfExpanded === "boolean") {
preferences.threadListSnoozedShelfExpanded = parsed.threadListSnoozedShelfExpanded;
}
if (typeof parsed.steerGraceWindowMs === "number") {
preferences.steerGraceWindowMs = parsed.steerGraceWindowMs;
}
Expand Down
7 changes: 5 additions & 2 deletions apps/mobile/src/state/thread-lifecycle-outbox-model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { archiveDiscardedQueuedMessageCount } from "@t3tools/client-runtime/state/thread-settled";
import { archiveDiscardedQueuedMessages } from "@t3tools/client-runtime/state/thread-settled";
import {
scopeThreadShell,
type EnvironmentShellStatus,
Expand Down Expand Up @@ -195,6 +195,8 @@ export function resolveThreadLifecycleOutboxAction(input: {
readonly thread:
| Pick<
EnvironmentThreadShell,
| "environmentId"
| "id"
| "archivedAt"
| "archiveRequest"
| "runtime"
Expand Down Expand Up @@ -226,7 +228,8 @@ export function resolveThreadLifecycleOutboxAction(input: {
const archivePending = !archived && thread.archiveRequest?.status === "pending";
if (input.desiredArchived) {
if ((archived || archivePending) && !input.requiresDispatch) return "remove";
return input.discardQueuedMessages && archiveDiscardedQueuedMessageCount(thread) > 0
// Only the thread's own queue refuses archive-when-done; side chat queues never do.
return input.discardQueuedMessages && archiveDiscardedQueuedMessages(thread).total > 0
? "archive-now"
: "archive";
}
Expand Down
11 changes: 10 additions & 1 deletion apps/mobile/src/state/thread-lifecycle-outbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ const live = {
requiresDispatch: false,
discardQueuedMessages: false,
} as const;
const idle = { archivedAt: null, archiveRequest: null, runtime: null, pendingBackgroundTasks: [] };
const idle = {
environmentId,
id: threadId,
archivedAt: null,
archiveRequest: null,
runtime: null,
pendingBackgroundTasks: [],
};
const pendingArchive = {
environmentId,
id: threadId,
runtime: null,
pendingBackgroundTasks: [],
archivedAt: null,
Expand Down
Loading
Loading