Skip to content

Commit de5ee51

Browse files
Merge main into fix/issue-25000
2 parents 8cfa0bb + e2d3ded commit de5ee51

40 files changed

Lines changed: 769 additions & 218 deletions

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ We are (mostly) not accepting contributions yet. Small fixes may be considered.
9494

9595
Full docs live in [docs/](./docs). There's no docs site yet.
9696

97+
- [FAQ](./docs/user/faq.md)
9798
- [Install and first run](./docs/user/install.md)
9899
- [Permission modes](./docs/user/permission-modes.md)
99100
- [Keyboard shortcuts](./docs/user/keybindings.md)

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type { ComposerTextPaste } from "../../native/T3ComposerEditor.types";
2626
import { type EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2727
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2828
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
29+
import { queuedRunEditBlockedReason } from "@t3tools/client-runtime/queued-run-edit";
2930
import {
3031
childThreadInputsTitle,
3132
type CodexFeedbackSubmission,
@@ -777,6 +778,9 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
777778
const activeUserInputRequestId = props.activePendingUserInput?.requestId ?? null;
778779
const composerSlotHidden =
779780
activeUserInputRequestId !== null || props.creationState?.kind === "failed";
781+
const pendingMessageEditBlocked =
782+
queuedRunEditBlockedReason({ openQuestionCount: activeUserInputRequestId === null ? 0 : 1 }) !==
783+
null;
780784
const [usageLimitsPanel, setUsageLimitsPanel] = useState<{
781785
readonly key: string;
782786
readonly threadKey: string;
@@ -1167,6 +1171,7 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
11671171
};
11681172

11691173
const handleEditPendingMessage = async (message: QueuedThreadMessage) => {
1174+
if (pendingMessageEditBlocked) return;
11701175
const scope = threadScope.current.signal;
11711176
const edited = await settlePromise(() => editPendingThreadMessage(message));
11721177
if (AsyncResult.isFailure(edited)) {
@@ -1296,7 +1301,9 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
12961301
dispatchingMessageId={props.dispatchingMessageId}
12971302
// A native subagent has no composer to edit a pending message in;
12981303
// Cancel on the edit banner would discard it.
1299-
onEditPendingMessage={isProviderSubagent ? null : handleEditPendingMessage}
1304+
onEditPendingMessage={
1305+
isProviderSubagent || pendingMessageEditBlocked ? null : handleEditPendingMessage
1306+
}
13001307
contentPresentation={props.contentPresentation}
13011308
agentLabel={agentLabel}
13021309
threadTitle={props.selectedThread.title}

‎apps/mobile/src/features/threads/ThreadQueueControl.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { type StaticScreenProps, useNavigation } from "@react-navigation/native";
22
import { useAtomValue } from "@effect/atom-react";
3-
import { makeQueuedRunsAtom } from "@t3tools/client-runtime/queued-run-edit";
3+
import {
4+
makeQueuedRunsAtom,
5+
queuedRunEditBlockedReason,
6+
} from "@t3tools/client-runtime/queued-run-edit";
47
import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
58
import { Atom } from "effect/reactivity";
69
import { Image } from "expo-image";
@@ -75,6 +78,10 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
7578
const workflow = useThreadQueueWorkflow(target);
7679
const threadKey = scopedThreadKey(target.environmentId, target.threadId);
7780
const editing = useQueuedRunEdit(threadKey);
81+
const pendingRequests = useAtomValue(environmentThreadDetails.pendingRequestsAtom(target));
82+
const editBlockedReason = queuedRunEditBlockedReason({
83+
openQuestionCount: pendingRequests?.userInputs.length ?? 0,
84+
});
7885
const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message");
7986
const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
8087
const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message");
@@ -127,6 +134,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
127134
return;
128135
}
129136
if (action === "edit") {
137+
if (editBlockedReason !== null) return;
130138
const entry = queuedRuns[index]!;
131139
void Haptics.selectionAsync();
132140
beginQueuedRunEdit(
@@ -212,6 +220,9 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
212220
/>
213221
</View>
214222
) : null}
223+
{editBlockedReason !== null && queuedRuns.length > 0 ? (
224+
<Text className="py-3 text-sm text-foreground-muted">{editBlockedReason}</Text>
225+
) : null}
215226
{queuedRuns.length === 0 ? (
216227
<Text className="pt-6 text-center text-sm text-foreground-muted">
217228
No messages waiting in this queue.
@@ -231,6 +242,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
231242
canPromoteToSteer: workflow?.canPromoteToSteer ?? false,
232243
canSendNow: workflow?.canSendNow ?? false,
233244
canReorder: workflow?.canReorder ?? false,
245+
editBlocked: editBlockedReason !== null,
234246
index,
235247
isEditing: editing?.runId === run.id,
236248
isGuestMessage: context?.guest !== undefined,
@@ -372,7 +384,7 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
372384
accessibilityHint={
373385
controls.canEdit
374386
? "Opens this message in the composer for editing"
375-
: undefined
387+
: (editBlockedReason ?? undefined)
376388
}
377389
disabled={!controls.canEdit}
378390
onPress={() => void act(run.id, "edit")}

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { buildProjectThreadStartTurnInput } from "../../lib/projectThreadStartTu
55
import { useWorktreeSetup } from "./use-worktree-setup";
66
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
77
import { AppBar } from "../../components/ui/AppBar";
8-
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
8+
import {
9+
StackActions,
10+
useNavigation,
11+
useRoute,
12+
type StaticScreenProps,
13+
} from "@react-navigation/native";
914
import { useEffect, useEffectEvent, useRef, useState, type ReactNode } from "react";
1015
import * as Option from "effect/Option";
1116
import {
@@ -74,6 +79,9 @@ import { useThreadComposerState } from "../../state/use-thread-composer-state";
7479
import { resolveMergeBackTargetThreadId } from "@t3tools/client-runtime/state/thread-relationships";
7580
import { resolveLatestMergeBackRun } from "@t3tools/client-runtime/state/thread-workflows";
7681
import { threadEnvironment, useThreadFamily } from "../../state/threads";
82+
import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads";
83+
import { useProjects } from "../../state/entities";
84+
import { newTaskDestination } from "./new-task-project-selection";
7785
import { projectThreadContentPresentation } from "./threadContentPresentation";
7886
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
7987
import {
@@ -191,6 +199,27 @@ function ThreadUnavailableScreen(props: {
191199
);
192200
}
193201

202+
/** A thread that can't load opens a new task in its environment instead of a dead end. */
203+
function UnavailableThreadDraftRedirect(props: { readonly environmentId: EnvironmentId }) {
204+
const navigation = useNavigation();
205+
const projects = useProjects();
206+
const { layout } = useAdaptiveWorkspaceLayout();
207+
const openDraft = useEffectEvent(() => {
208+
const project = projects.find((candidate) => candidate.environmentId === props.environmentId);
209+
navigation.dispatch(
210+
StackActions.replace(
211+
"Thread",
212+
newTaskDestination(layout.usesSplitView, projects, project, uuidv4()),
213+
),
214+
);
215+
});
216+
// oxlint-disable-next-line t3code/react-effect-budget -- replaces this route in the navigator
217+
useEffect(() => {
218+
openDraft();
219+
}, []);
220+
return <OpeningThreadLoadingScreen />;
221+
}
222+
194223
export function ThreadRouteScreen(props: ThreadRouteScreenProps) {
195224
return (
196225
<ThreadScreenHost>
@@ -225,6 +254,7 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
225254
const routeEnvironmentShellState = useEnvironmentShellReadiness(environmentId);
226255
const { onReconnectEnvironment } = useRemoteConnections();
227256
const navigation = useNavigation();
257+
const routeName = useRoute().name;
228258
const routeConnectionState =
229259
routeEnvironmentRuntime?.connectionState ?? (environmentId ? "available" : connectionState);
230260
const routeThreadKey =
@@ -261,6 +291,10 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
261291

262292
const stillHydrating = threadRouteIsHydrating({
263293
isLoadingConnections: !connectionsReady,
294+
environmentRegistered: routeEnvironmentRuntime !== null,
295+
localCacheRead:
296+
routeEnvironmentShellState.cacheRead &&
297+
selectedThreadDetailState !== EMPTY_ENVIRONMENT_THREAD_STATE,
264298
connectionState: routeConnectionState,
265299
shellStatus: routeEnvironmentShellState.status,
266300
shellHasError: routeEnvironmentShellState.hasError,
@@ -272,6 +306,10 @@ function LiveThreadRouteController(props: ThreadRouteScreenProps) {
272306
return withInspectorHeader(<OpeningThreadLoadingScreen />);
273307
}
274308

309+
if (routeName === "Thread" && !props.inspectorPresentation) {
310+
return <UnavailableThreadDraftRedirect environmentId={environmentId} />;
311+
}
312+
275313
return withInspectorHeader(
276314
<ThreadUnavailableScreen
277315
actionLabel={

‎apps/mobile/src/features/threads/thread-route-hydration.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { threadRouteIsHydrating } from "./thread-route-hydration";
44

55
const settled = {
66
isLoadingConnections: false,
7+
environmentRegistered: true,
8+
localCacheRead: true,
79
connectionState: "connected" as const,
810
shellStatus: "live" as const,
911
shellHasError: false,
@@ -19,6 +21,21 @@ describe("threadRouteIsHydrating", () => {
1921
expect(threadRouteIsHydrating({ ...settled, detailStatus: "empty" })).toBe(true);
2022
});
2123

24+
it("waits for the local cache before trusting an offline connection", () => {
25+
const offline = {
26+
...settled,
27+
connectionState: "offline" as const,
28+
detailStatus: "empty" as const,
29+
};
30+
expect(threadRouteIsHydrating({ ...offline, localCacheRead: false })).toBe(true);
31+
expect(threadRouteIsHydrating(offline)).toBe(false);
32+
expect(threadRouteIsHydrating({ ...offline, connectionState: "reconnecting" })).toBe(false);
33+
expect(threadRouteIsHydrating({ ...offline, connectionState: "connecting" })).toBe(true);
34+
expect(
35+
threadRouteIsHydrating({ ...offline, localCacheRead: false, environmentRegistered: false }),
36+
).toBe(false);
37+
});
38+
2239
it("stops waiting once an empty detail has an actionable outcome", () => {
2340
expect(
2441
threadRouteIsHydrating({

‎apps/mobile/src/features/threads/thread-route-hydration.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/thre
44

55
export function threadRouteIsHydrating(input: {
66
readonly isLoadingConnections: boolean;
7+
readonly environmentRegistered: boolean;
8+
readonly localCacheRead: boolean;
79
readonly connectionState: EnvironmentConnectionPhase;
810
readonly shellStatus: EnvironmentShellStatus;
911
readonly shellHasError: boolean;
@@ -16,16 +18,23 @@ export function threadRouteIsHydrating(input: {
1618
if (input.isLoadingConnections) {
1719
return true;
1820
}
21+
if (!input.environmentRegistered) {
22+
return false;
23+
}
24+
if (!input.localCacheRead) {
25+
return true;
26+
}
27+
// Only a first attempt is worth waiting out; a reconnecting environment has already failed.
1928
if (
2029
input.connectionState === "available" ||
2130
input.connectionState === "offline" ||
31+
input.connectionState === "reconnecting" ||
2232
input.connectionState === "error"
2333
) {
2434
return false;
2535
}
2636
return (
2737
input.connectionState === "connecting" ||
28-
input.connectionState === "reconnecting" ||
2938
input.shellStatus === "synchronizing" ||
3039
(input.connectionState === "connected" && input.shellStatus === "empty") ||
3140
input.detailStatus === "synchronizing" ||

‎apps/mobile/src/features/threads/threadQueueControlPresentation.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export function resolveThreadQueueRowControls(input: {
1919
readonly canPromoteToSteer: boolean;
2020
readonly canSendNow: boolean;
2121
readonly canReorder: boolean;
22+
/** Something else holds the composer, such as an open question. */
23+
readonly editBlocked?: boolean;
2224
readonly index: number;
2325
readonly isEditing?: boolean;
2426
/** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */
@@ -33,7 +35,8 @@ export function resolveThreadQueueRowControls(input: {
3335
canDismiss: !input.busy,
3436
// Re-opening the row already in the composer would reload it and throw
3537
// away whatever has been typed since.
36-
canEdit: mutationEnabled && !isEditing && input.isGuestMessage !== true,
38+
canEdit:
39+
mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true,
3740
canMoveDown: mutationEnabled && input.canReorder && input.index < input.queuedCount - 1,
3841
canMoveUp: mutationEnabled && input.canReorder && input.index > 0,
3942
canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing,

‎apps/mobile/src/features/workspace/workspace-selection-store.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { workspaceRoutesOf } from "../layout/workspace-overlay-routes";
1919
import type { WorkspaceSelections } from "../../persistence/mobile-preferences";
2020
import { appAtomRegistry } from "../../state/atom-registry";
2121
import { environmentPresentations } from "../../state/presentation";
22-
import { environmentThreadShells, threadEnvironment } from "../../state/threads";
22+
import {
23+
environmentThreadShells,
24+
startOpeningEnvironmentThread,
25+
threadEnvironment,
26+
} from "../../state/threads";
2327
import {
2428
rememberedSettingsPage,
2529
workspaceSelectionsIn,
@@ -137,11 +141,17 @@ export function settingsLinkPage() {
137141
*/
138142
export async function launchWorkspaceURL(): Promise<string | null> {
139143
if (!REMEMBERS) return null;
140-
await Promise.all([
141-
hydrateWorkspaceSelections(),
142-
firstNativeLayoutMetrics(NATIVE_METRICS_TIMEOUT_MS),
143-
]);
144+
const metrics = firstNativeLayoutMetrics(NATIVE_METRICS_TIMEOUT_MS);
145+
await hydrateWorkspaceSelections();
144146
const thread = selections.threads;
147+
// Read the chat's cached copy while the layout metrics are still on their way.
148+
if (thread) {
149+
startOpeningEnvironmentThread(
150+
thread.environmentId as EnvironmentId,
151+
thread.threadId as ThreadId,
152+
);
153+
}
154+
await metrics;
145155
if (!thread || !workspaceHasColumns() || !workspaceSelectionCheck.thread(thread)) return null;
146156
return Linking.createURL(
147157
`threads/${encodeURIComponent(thread.environmentId)}/${encodeURIComponent(thread.threadId)}`,

‎apps/mobile/src/state/shell.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const EMPTY_ENVIRONMENT_SHELL_STATE_ATOM = Atom.make<EnvironmentShellState>(EMPT
2626

2727
const shellStatus = (state: EnvironmentShellState) => state.status;
2828
const shellHasError = (state: EnvironmentShellState) => Option.isSome(state.error);
29+
// The empty placeholder stands until the environment has read its cached shell.
30+
const shellCacheRead = (state: EnvironmentShellState) => state !== EMPTY_SHELL_STATE;
2931

3032
export function useEnvironmentShellReadiness(environmentId: EnvironmentId | null) {
3133
const atom =
@@ -35,5 +37,6 @@ export function useEnvironmentShellReadiness(environmentId: EnvironmentId | null
3537
return {
3638
status: useAtomValue(atom, shellStatus),
3739
hasError: useAtomValue(atom, shellHasError),
40+
cacheRead: useAtomValue(atom, shellCacheRead),
3841
};
3942
}

‎apps/server/src/provider/ClaudeModelCatalog.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,21 @@ function tryResolveClaudeModelCatalog(
5959
};
6060
}
6161

62-
const BUNDLED_CLAUDE_PROVIDER_CATALOG =
63-
resolveProviderCatalog(BUNDLED_MODEL_MANIFEST, CLAUDE) ?? undefined;
64-
62+
/** Resolve the fallback on each read so its new-model badges can expire. */
6563
export function resolveClaudeModelCatalog(
6664
catalog: ModelCatalog.ProviderCatalog | undefined,
6765
): ClaudeModelCatalog {
6866
return (
6967
tryResolveClaudeModelCatalog(catalog) ??
70-
tryResolveClaudeModelCatalog(BUNDLED_CLAUDE_PROVIDER_CATALOG) ?? {
68+
tryResolveClaudeModelCatalog(
69+
resolveProviderCatalog(BUNDLED_MODEL_MANIFEST, CLAUDE) ?? undefined,
70+
) ?? {
7171
models: [],
7272
}
7373
);
7474
}
7575

76-
export const BUNDLED_CLAUDE_MODEL_CATALOG = resolveClaudeModelCatalog(
77-
BUNDLED_CLAUDE_PROVIDER_CATALOG,
78-
);
76+
export const BUNDLED_CLAUDE_MODEL_CATALOG = resolveClaudeModelCatalog(undefined);
7977

8078
export function scopeClaudeModelCatalog(
8179
catalog: ClaudeModelCatalog,

0 commit comments

Comments
 (0)