Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en
import { leaveSettingsPage } from "./settings-navigation";
import { workspaceHasColumns } from "../layout/workspace/workspace-selection-store";
import { DEFAULT_SETTINGS_PAGE } from "../layout/workspace/workspace-tab-navigation";
import { readUnloadedThreadCount } from "../../state/olderSettledShelf";
import { readServerOwnedThreadCount, readUnloadedThreadCount } from "../../state/olderSettledShelf";
import { m } from "../../i18n/messages";

export function SettingsProjectOverviewRouteScreen() {
Expand Down Expand Up @@ -253,6 +253,7 @@ function ProjectOverviewContent(props: {
displayName,
threads,
unloadedThreadCount: readUnloadedThreadCount(members, threads),
serverOwnedThreadCount: readServerOwnedThreadCount(members, threads),
},
m,
);
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Dadurch werden {count} gruppierte Projekteinträge entfernt.",
"3e46fbf3eadf0745": "Diese Threads und alle archivierten Threads werden aus T3 Code gelöscht. Anbietersitzungen bleiben erhalten.",
"1a50cbc984f8fe1c": "Alle archivierten Threads werden aus T3 Code gelöscht. Anbietersitzungen bleiben erhalten.",
"361080ce34c8e8ed": "{count, plural, one {{count} von einem Board oder der Engine gestartetes Gespräch wird archiviert, nicht gelöscht.} other {{count} von einem Board oder der Engine gestartete Gespräche werden archiviert, nicht gelöscht.}} Bereits archivierte Board- und Engine-Gespräche bleiben erhalten.",
"4f076ebbf1c8846e": "Dadurch werden nur die Projekteinträge entfernt, nicht die Dateien auf der Festplatte.",
"19b8f3ad79efb9e1": "Andere Einträge in diesem gruppierten Projekt sind nicht betroffen.",
"2207c69b042b2e37": "Diese Aktion kann nicht rückgängig gemacht werden.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "This removes {count} grouped project entries.",
"3e46fbf3eadf0745": "Those threads and any archived threads are deleted from T3 Code. Provider sessions are kept.",
"1a50cbc984f8fe1c": "Any archived threads are deleted from T3 Code. Provider sessions are kept.",
"361080ce34c8e8ed": "{count, plural, one {{count} conversation started by a board or the engine is archived, not deleted.} other {{count} conversations started by a board or the engine are archived, not deleted.}} Board and engine conversations already archived are kept.",
"4f076ebbf1c8846e": "This removes only the project entries, not the files on disk.",
"19b8f3ad79efb9e1": "Other entries in this grouped project are unaffected.",
"2207c69b042b2e37": "This action cannot be undone.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Esto quita {count} entradas de proyecto agrupadas.",
"3e46fbf3eadf0745": "Esos hilos y los hilos archivados se eliminan de T3 Code. Las sesiones del proveedor se conservan.",
"1a50cbc984f8fe1c": "Los hilos archivados se eliminan de T3 Code. Las sesiones del proveedor se conservan.",
"361080ce34c8e8ed": "{count, plural, one {{count} conversación iniciada por un tablero o por el motor se archiva, no se elimina.} other {{count} conversaciones iniciadas por un tablero o por el motor se archivan, no se eliminan.}} Las conversaciones de tableros y del motor ya archivadas se conservan.",
"4f076ebbf1c8846e": "Esto solo quita las entradas del proyecto, no los archivos del disco.",
"19b8f3ad79efb9e1": "Las demás entradas de este proyecto agrupado no se ven afectadas.",
"2207c69b042b2e37": "Esta acción no se puede deshacer.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Cela retire {count} entrées de projet regroupées.",
"3e46fbf3eadf0745": "Ces fils et tous les fils archivés sont supprimés de T3 Code. Les sessions du fournisseur sont conservées.",
"1a50cbc984f8fe1c": "Tous les fils archivés sont supprimés de T3 Code. Les sessions du fournisseur sont conservées.",
"361080ce34c8e8ed": "{count, plural, one {{count} conversation lancée par un tableau ou par le moteur est archivée, pas supprimée.} other {{count} conversations lancées par un tableau ou par le moteur sont archivées, pas supprimées.}} Les conversations de tableaux et du moteur déjà archivées sont conservées.",
"4f076ebbf1c8846e": "Cela retire uniquement les entrées de projet, pas les fichiers sur le disque.",
"19b8f3ad79efb9e1": "Les autres entrées de ce projet regroupé ne sont pas affectées.",
"2207c69b042b2e37": "Cette action est irréversible.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "グループ化された {count} 件のプロジェクトエントリを削除します。",
"3e46fbf3eadf0745": "それらのスレッドとアーカイブ済みのスレッドは T3 Code から削除されます。プロバイダーのセッションは保持されます。",
"1a50cbc984f8fe1c": "アーカイブ済みのスレッドは T3 Code から削除されます。プロバイダーのセッションは保持されます。",
"361080ce34c8e8ed": "{count, plural, other {ボードまたはエンジンが開始した会話 {count} 件はアーカイブされ、削除されません。}}すでにアーカイブ済みのボードおよびエンジンの会話は保持されます。",
"4f076ebbf1c8846e": "削除されるのはプロジェクトのエントリだけで、ディスク上のファイルは削除されません。",
"19b8f3ad79efb9e1": "このグループ化されたプロジェクト内の他のエントリには影響しません。",
"2207c69b042b2e37": "この操作は元に戻せません。",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "그룹화된 프로젝트 항목 {count}개를 제거합니다.",
"3e46fbf3eadf0745": "해당 스레드와 보관된 스레드는 T3 Code에서 삭제됩니다. 제공자 세션은 유지됩니다.",
"1a50cbc984f8fe1c": "보관된 스레드는 T3 Code에서 삭제됩니다. 제공자 세션은 유지됩니다.",
"361080ce34c8e8ed": "{count, plural, other {보드 또는 엔진이 시작한 대화 {count}개는 삭제되지 않고 보관됩니다.}} 이미 보관된 보드 및 엔진 대화는 그대로 유지됩니다.",
"4f076ebbf1c8846e": "디스크의 파일이 아닌 프로젝트 항목만 제거합니다.",
"19b8f3ad79efb9e1": "이 그룹화된 프로젝트의 다른 항목은 영향을 받지 않습니다.",
"2207c69b042b2e37": "이 작업은 되돌릴 수 없습니다.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Isto remove {count} entradas de projeto agrupadas.",
"3e46fbf3eadf0745": "Essas threads e as threads arquivadas são excluídas do T3 Code. As sessões do provedor são mantidas.",
"1a50cbc984f8fe1c": "As threads arquivadas são excluídas do T3 Code. As sessões do provedor são mantidas.",
"361080ce34c8e8ed": "{count, plural, one {{count} conversa iniciada por um quadro ou pelo motor é arquivada, não excluída.} other {{count} conversas iniciadas por um quadro ou pelo motor são arquivadas, não excluídas.}} As conversas de quadros e do motor já arquivadas são mantidas.",
"4f076ebbf1c8846e": "Isto remove apenas as entradas do projeto, não os arquivos no disco.",
"19b8f3ad79efb9e1": "As outras entradas deste projeto agrupado não são afetadas.",
"2207c69b042b2e37": "Esta ação não pode ser desfeita.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Будут удалены сгруппированные записи проекта: {count}.",
"3e46fbf3eadf0745": "Эти треды и все архивные треды будут удалены из T3 Code. Сеансы провайдера сохранятся.",
"1a50cbc984f8fe1c": "Все архивные треды будут удалены из T3 Code. Сеансы провайдера сохранятся.",
"361080ce34c8e8ed": "{count, plural, one {{count} разговор, начатый доской или движком, будет архивирован, а не удалён.} few {{count} разговора, начатых доской или движком, будут архивированы, а не удалены.} many {{count} разговоров, начатых доской или движком, будут архивированы, а не удалены.} other {{count} разговора, начатых доской или движком, будут архивированы, а не удалены.}} Уже архивированные разговоры досок и движка сохранятся.",
"4f076ebbf1c8846e": "Удаляются только записи проекта, а не файлы на диске.",
"19b8f3ad79efb9e1": "Другие записи в этом сгруппированном проекте не затрагиваются.",
"2207c69b042b2e37": "Это действие нельзя отменить.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "Det här tar bort {count} grupperade projektposter.",
"3e46fbf3eadf0745": "De trådarna och eventuella arkiverade trådar tas bort från T3 Code. Leverantörssessioner behålls.",
"1a50cbc984f8fe1c": "Eventuella arkiverade trådar tas bort från T3 Code. Leverantörssessioner behålls.",
"361080ce34c8e8ed": "{count, plural, one {{count} konversation som startats av en tavla eller motorn arkiveras, den tas inte bort.} other {{count} konversationer som startats av en tavla eller motorn arkiveras, de tas inte bort.}} Redan arkiverade konversationer från tavlor och motorn behålls.",
"4f076ebbf1c8846e": "Det här tar bara bort projektposterna, inte filerna på disken.",
"19b8f3ad79efb9e1": "Andra poster i det här grupperade projektet påverkas inte.",
"2207c69b042b2e37": "Den här åtgärden kan inte ångras.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
"bac5ef48aafb20b1": "将移除 {count} 个已分组的项目条目。",
"3e46fbf3eadf0745": "这些会话及所有已归档会话将从 T3 Code 中删除。提供方自身保存的对话记录会保留。",
"1a50cbc984f8fe1c": "所有已归档会话将从 T3 Code 中删除。提供方自身保存的对话记录会保留。",
"361080ce34c8e8ed": "{count, plural, other {由看板或引擎发起的 {count} 个对话将被归档,不会删除。}}已归档的看板和引擎对话会保留。",
"4f076ebbf1c8846e": "仅移除项目条目,磁盘上的文件会保留。",
"19b8f3ad79efb9e1": "此项目组中的其他条目不受影响。",
"2207c69b042b2e37": "此操作无法撤销。",
Expand Down
17 changes: 17 additions & 0 deletions apps/mobile/src/state/olderSettledShelf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useAtomValue } from "@effect/atom-react";
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models";
import { serverOwnedThreadCount } from "@t3tools/client-runtime/state/projects";
import {
isListedSettledThread,
settledShelfFrontier,
Expand Down Expand Up @@ -137,3 +138,19 @@ export function useOlderSettledCount(
);
return project === null ? 0 : (older?.counts.get(project.id) ?? 0);
}

/**
* Threads of these projects that the server started for itself, which the shell counts and does
* not send: see `serverOwnedThreadCount`. A project removal archives them.
*/
export function readServerOwnedThreadCount(
members: ReadonlyArray<{ readonly environmentId: EnvironmentId; readonly id: ProjectId }>,
threads: ReadonlyArray<EnvironmentThreadShell>,
): number {
return serverOwnedThreadCount({
members,
counted: (environmentId) =>
appAtomRegistry.get(threadFamilies.snapshotAtom(environmentId))?.serverOwnedThreads,
threads,
});
}
186 changes: 186 additions & 0 deletions apps/mobile/src/state/use-thread-selection.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import * as NodeModule from "node:module";

import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads";
import {
EnvironmentId,
isListedThreadLineage,
ThreadId,
type OrchestrationV2ThreadProjection,
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import * as Option from "effect/Option";
import { act, useLayoutEffect } from "react";
import { createRoot } from "react-dom/client";
import { expect, it, vi } from "vite-plus/test";

import { extractAgentNotificationDeepLink } from "../features/agent-awareness/notificationPayload";
import { scopedThreadKey } from "../lib/scopedEntities";
import { makeRawThreadShell } from "../test-fixtures";

// The environment is stood in for at the two reads the thread route makes: the shell row and the
// thread's own detail. Mobile has no fake socket to drive a whole screen against.
const harness = vi.hoisted(() => ({
route: { key: "thread", name: "Thread", params: {} as object },
shell: null as unknown,
detail: null as unknown,
detailReads: [] as Array<readonly [string | null, string | null]>,
}));

vi.mock("@react-navigation/native", () => ({ useRoute: () => harness.route }));
vi.mock("./entities", () => ({
useQuietThreadShell: () => harness.shell,
useProject: () => null,
}));
vi.mock("./threads", () => ({
useEnvironmentThread: (environmentId: string | null, threadId: string | null) => {
harness.detailReads.push([environmentId, threadId]);
return environmentId === null ? EMPTY_ENVIRONMENT_THREAD_STATE : harness.detail;
},
}));
vi.mock("./use-thread-outbox", () => ({ useThreadOutboxMessages: () => ({}) }));
vi.mock("./use-remote-environment-registry", () => ({
useRemoteEnvironmentRuntime: () => null,
useSavedRemoteConnection: () => null,
}));

import { useThreadSelection } from "./use-thread-selection";

const requireNavigation = NodeModule.createRequire(
NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
);
const { getStateFromPath } = requireNavigation("@react-navigation/core") as {
getStateFromPath: typeof import("@react-navigation/native").getStateFromPath;
};

const environmentId = EnvironmentId.make("environment-1");
const threadId = ThreadId.make("board-task-thread");
const boardTask = makeRawThreadShell({
id: threadId,
title: "Task 7",
lineage: {
rootThreadId: threadId,
parentThreadId: null,
relationshipToParent: null,
engineIntake: "board-task:board-1:task-7",
},
});

function detailOf(archivedAt: DateTime.Utc | null): OrchestrationV2ThreadProjection {
return {
thread: {
id: boardTask.id,
projectId: boardTask.projectId,
title: boardTask.title,
providerInstanceId: boardTask.providerInstanceId,
modelSelection: boardTask.modelSelection,
runtimeMode: boardTask.runtimeMode,
interactionMode: boardTask.interactionMode,
branch: boardTask.branch,
worktreePath: boardTask.worktreePath,
activeProviderThreadId: boardTask.activeProviderThreadId,
lineage: boardTask.lineage,
forkedFrom: boardTask.forkedFrom,
createdBy: boardTask.createdBy,
creationSource: boardTask.creationSource,
createdAt: boardTask.createdAt,
updatedAt: boardTask.updatedAt,
archivedAt,
settledOverride: null,
settledAt: null,
lastVisitedAt: null,
deletedAt: null,
},
runs: [],
attempts: [],
nodes: [],
subagents: [],
providerSessions: [],
providerThreads: [],
providerTurns: [],
runtimeRequests: [],
messages: [],
plans: [],
turnItems: [],
checkpointScopes: [],
checkpoints: [],
contextHandoffs: [],
contextTransfers: [],
visibleTurnItems: [],
updatedAt: boardTask.updatedAt,
};
}

/** The Thread route's params for a link, read with the path `Stack.tsx` gives that route. */
function threadRouteParams(link: string) {
const state = getStateFromPath(link, {
screens: { Thread: { path: "threads/:environmentId?/:threadId?" } },
});
const route = state?.routes.at(-1);
if (route?.name !== "Thread") throw new Error(`${link} did not open the thread route`);
return route.params ?? {};
}

function select() {
let selection: ReturnType<typeof useThreadSelection> | null = null;
function Probe() {
const current = useThreadSelection();
useLayoutEffect(() => {
selection = current;
});
return null;
}
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
const root = createRoot(document.createElement("div"));
try {
act(() => root.render(<Probe />));
return (selection as ReturnType<typeof useThreadSelection> | null)!;
} finally {
act(() => root.unmount());
}
}

const archivedAt = DateTime.makeUnsafe("2026-11-20T00:00:00.000Z");
const live = { ...EMPTY_ENVIRONMENT_THREAD_STATE, status: "live" as const };

it.each([
{ shell: "left its row out", row: null, detail: detailOf(null), archived: false },
{ shell: "has archived it", row: null, detail: detailOf(archivedAt), archived: true },
{ shell: "got its row as a delta", row: boardTask, detail: null, archived: false },
])("opens a board task's thread from a link by id when the shell $shell", (c) => {
// The link a notification or another app hands over, as the app itself writes it.
const link = extractAgentNotificationDeepLink({
notification: { request: { content: { data: { environmentId, threadId } } } },
});
expect(link).toBe("/threads/environment-1/board-task-thread");
harness.route = { key: "thread", name: "Thread", params: threadRouteParams(link!) };
harness.shell = c.row === null ? null : { ...c.row, environmentId };
harness.detail = c.detail === null ? live : { ...live, data: Option.some(c.detail) };
harness.detailReads = [];

const { selectedThread } = select();

// The route screen shows the thread when the selection is the thread the route names.
expect(selectedThread).not.toBeNull();
expect(scopedThreadKey(selectedThread!.environmentId, selectedThread!.id)).toBe(
scopedThreadKey(environmentId, threadId),
);
expect(selectedThread!.title).toBe("Task 7");
// It is still a thread no list shows: the lists filter on this lineage.
expect(isListedThreadLineage(selectedThread!.lineage)).toBe(false);
expect(selectedThread!.archivedAt !== null).toBe(c.archived);
// Without a row the thread's own detail is what opens it; with one the detail is not read here.
expect(harness.detailReads.at(-1)).toEqual(
c.row === null ? [environmentId, threadId] : [null, null],
);
});

it("has no thread to show when neither the shell nor the thread's detail knows the id", () => {
harness.route = {
key: "thread",
name: "Thread",
params: threadRouteParams("/threads/environment-1/gone"),
};
harness.shell = null;
harness.detail = { ...EMPTY_ENVIRONMENT_THREAD_STATE, status: "deleted" as const };
expect(select().selectedThread).toBeNull();
});
1 change: 1 addition & 0 deletions apps/mobile/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const reactTests = [
"src/native/useRetryingImageSource.test.tsx",
"src/state/queries.debounce.test.tsx",
"src/state/use-selected-thread-git-state.test.tsx",
"src/state/use-thread-selection.test.tsx",
"src/features/terminal/useTerminalExitNavigation.test.tsx",
"src/features/threads/use-thread-list-now.test.tsx",
"src/features/threads/use-composer-command-menu.select.test.tsx",
Expand Down
Loading
Loading