Skip to content

Commit 9ef95eb

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-24882
2 parents 8e83c58 + 4cb29a5 commit 9ef95eb

93 files changed

Lines changed: 3091 additions & 1043 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.coderabbit.config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ export default defineConfig((ctx) => ({
2626
path: "apps/web/src/**/*.{tsx,css}",
2727
instructions: "Hold changed code to the rules in docs/internals/web-ui.md.",
2828
},
29+
{
30+
path: "**/*.test.{ts,tsx}",
31+
instructions:
32+
"Hold changed tests to the rules in docs/internals/testing.md. Request tests only as those rules allow.",
33+
},
2934
],
3035
},
3136
knowledge_base: {
3237
code_guidelines: {
3338
filePatterns: [
3439
{ files: "docs/internals/effect-services.md", applyTo: "{apps,packages,infra}/**/*.ts" },
3540
{ files: "docs/internals/web-ui.md", applyTo: "apps/web/src/**/*.{tsx,css}" },
41+
{ files: "docs/internals/testing.md", applyTo: "{apps,packages,infra}/**/*.{ts,tsx}" },
3642
],
3743
},
3844
},

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
103103
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105105
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
106+
- [Testing](docs/internals/testing.md) carries these same test rules, plus review guidance, for review bots. Change both together.
106107
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
107108
- Backend behavior changes ship with focused tests for that behavior.
108109
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in the module's existing test file), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.

‎apps/mobile/package.json‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@
7373
"@t3tools/mobile-review-diff-native": "file:./modules/t3-review-diff",
7474
"@t3tools/mobile-source-text": "file:./modules/t3-source-text",
7575
"@t3tools/mobile-terminal-native": "file:./modules/t3-terminal",
76-
"@t3tools/provider-acp-registry": "workspace:*",
77-
"@t3tools/provider-core": "workspace:*",
78-
"@t3tools/provider-cursor": "workspace:*",
79-
"@t3tools/provider-fx": "workspace:*",
80-
"@t3tools/provider-grok": "workspace:*",
81-
"@t3tools/provider-muse": "workspace:*",
82-
"@t3tools/provider-opencode": "workspace:*",
83-
"@t3tools/provider-pi": "workspace:*",
8476
"@t3tools/shared": "workspace:*",
8577
"@tabler/icons-react-native": "^3.44.0",
8678
"clsx": "^2.1.1",

‎apps/mobile/src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
2626
import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
2727
import {
2828
presentPendingIncomingShare,
29+
pruneIncomingShareImports,
2930
startIncomingShareInbox,
3031
} from "./features/sharing/IncomingShareProvider";
3132
import {
@@ -133,6 +134,7 @@ function handleNavigationStateChange(state: NavigationState | undefined): void {
133134
setAgentNotificationPathname(workspaceLocationFromState(state).pathname);
134135
recordAppShortcutNavigationState(state);
135136
pruneNewTaskBranchCheckouts(state);
137+
pruneIncomingShareImports(state);
136138
}
137139

138140
function handleNavigationReady(): void {

‎apps/mobile/src/components/ComposerModelControl.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function ComposerModelControl(props: {
7070
/>
7171
)
7272
}
73-
label={label}
73+
label={props.modelOption?.shortName ?? label}
7474
iconOnly={props.iconOnly}
7575
suffix={
7676
summary ? (

‎apps/mobile/src/components/ProviderIcon.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useId, useState } from "react";
1010
import { resolveOfficialAcpRegistryIconUrl } from "@t3tools/contracts";
1111
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
1212
import { AppText as Text } from "./ui/AppText";
13-
import { getProviderClient } from "../lib/providerClients";
13+
import { getProviderClient } from "@t3tools/client-runtime/provider-clients";
1414

1515
type ProviderIconProps = {
1616
readonly provider: string | null | undefined;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import type { Wakeups } from "@t3tools/client-runtime/connection";
22

3-
export const MOBILE_BACKGROUND_RECONNECT_AFTER_MS = 10_000;
3+
export const MOBILE_LONG_BACKGROUND_AFTER_MS = 10_000;
44

55
export type MobileApplicationActiveWakeup = Extract<
66
Wakeups.ConnectionWakeup,
7-
"application-active-probe" | "application-active-reconnect"
7+
"application-active-probe" | "application-active-long"
88
>;
99

1010
export function mobileApplicationActiveWakeup(
1111
backgroundedAtMs: number | null,
1212
activeAtMs: number,
1313
): MobileApplicationActiveWakeup {
1414
return backgroundedAtMs !== null &&
15-
activeAtMs - backgroundedAtMs >= MOBILE_BACKGROUND_RECONNECT_AFTER_MS
16-
? "application-active-reconnect"
15+
activeAtMs - backgroundedAtMs >= MOBILE_LONG_BACKGROUND_AFTER_MS
16+
? "application-active-long"
1717
: "application-active-probe";
1818
}

‎apps/mobile/src/connection/platform.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const networkPathChanges = Stream.callback<"network-changed">((queue) =>
118118
const layerWakeups = Wakeups.layer({
119119
changes: Stream.mergeAll(
120120
[
121-
Stream.callback<"application-active-probe" | "application-active-reconnect">((queue) =>
121+
Stream.callback<"application-active-probe" | "application-active-long">((queue) =>
122122
Effect.acquireRelease(
123123
Effect.sync(() => {
124124
let backgroundedAtMs = AppState.currentState === "background" ? Date.now() : null;

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
1313
import { type EnvironmentId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
1414
import { useAtomValue } from "@effect/atom-react";
15-
import { useFocusEffect } from "@react-navigation/native";
1615
import { use, useEffect, useRef, useState, type ComponentProps } from "react";
1716
import {
1817
Platform,
@@ -51,6 +50,7 @@ import { useThreadSearch } from "../../state/queries";
5150
import { requestThreadMessageJump } from "../threads/threadMessageJump";
5251
import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches";
5352
import { useThreadListV2 } from "../threads/useThreadListV2";
53+
import { useThreadListNow } from "../threads/use-thread-list-now";
5454
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
5555
import { usePendingThreadOrder } from "../../state/thread-order";
5656
import { threadListEnvironmentsAtom } from "../../state/server";
@@ -423,15 +423,7 @@ export function HomeScreen(props: HomeScreenProps) {
423423
toggleSnoozedShelf,
424424
toggleWorkingShelf,
425425
} = useThreadListV2ShelfPreferences();
426-
// Keep time in state; the compiler would cache a render-time new Date().
427-
const [now, setNow] = useState(() => new Date().toISOString());
428-
const nowMinute = now.slice(0, 16);
429-
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
430-
useFocusEffect(() => {
431-
setNow(new Date().toISOString());
432-
const id = setInterval(() => setNow(new Date().toISOString()), 60_000);
433-
return () => clearInterval(id);
434-
});
426+
const now = useThreadListNow(props.threads);
435427
const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
436428
const {
437429
providersByEnvironmentId,
@@ -445,7 +437,7 @@ export function HomeScreen(props: HomeScreenProps) {
445437
titleRegenerationEnvironmentIds,
446438
} = listEnvironments;
447439
const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
448-
const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
440+
const pendingOrder = usePendingThreadOrder();
449441
const {
450442
layout: threadListV2Layout,
451443
items: threadListV2Items,
@@ -473,19 +465,6 @@ export function HomeScreen(props: HomeScreenProps) {
473465
settledShelfExpanded,
474466
selectedThreadKey,
475467
});
476-
const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
477-
useEffect(() => {
478-
if (nextSnoozeWakeAt === null) return;
479-
const wakeAtMs = Date.parse(nextSnoozeWakeAt);
480-
if (Number.isNaN(wakeAtMs)) return;
481-
const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
482-
const id = setTimeout(() => {
483-
setNow(new Date().toISOString());
484-
bumpSnoozeWakeTick((tick) => tick + 1);
485-
}, delayMs);
486-
return () => clearTimeout(id);
487-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- snoozeWakeTick re-arms clamped timers even when the wake date exceeds 32-bit setTimeout and stays unchanged.
488-
}, [nextSnoozeWakeAt, snoozeWakeTick]);
489468
// Called as `props.onSelectThread(...)`, the compiler would cache this handler on the whole
490469
// props object, which is new on every render of Home's parent.
491470
const { onSelectThread } = props;

‎apps/mobile/src/features/sharing/IncomingShareProvider.tsx‎

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Dialog from "../../components/ui/Dialog";
22
import Constants from "expo-constants";
33
import * as Crypto from "expo-crypto";
4-
import { PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
4+
import { EnvironmentId, PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
55
import {
66
clearSharedPayloads,
77
getResolvedSharedPayloadsAsync,
@@ -11,10 +11,12 @@ import {
1111
} from "expo-sharing";
1212
import { useSyncExternalStore } from "react";
1313
import { Platform } from "react-native";
14+
import { CommonActions } from "@react-navigation/native";
1415

1516
import {
1617
buildIncomingShareDraft,
1718
isShareFileUriUnderOwnedRoots,
19+
selectIncomingShareAttachmentsForServer,
1820
type IncomingShareDestination,
1921
type IncomingShareDraft,
2022
} from "./incoming-share-model";
@@ -26,6 +28,16 @@ import { coalescedRun } from "../../lib/coalescedRun";
2628
import { rootNavigationRef } from "../../lib/rootNavigation";
2729
import { selectWorkspaceDetail } from "../workspace/workspace-detail-selection";
2830
import { isDraftThreadRoute } from "../threads/thread-route-state";
31+
import { makeIncomingShareImports } from "../threads/incomingShareImport";
32+
import { liveNewTaskFlowKeys } from "../threads/new-task-flow-state";
33+
import { appAtomRegistry } from "../../state/atom-registry";
34+
import { serverEnvironment } from "../../state/server";
35+
import {
36+
getComposerDraftSnapshot,
37+
mergeComposerDraftContent,
38+
scheduleUnusedComposerAttachmentCleanup,
39+
undoComposerDraftMerge,
40+
} from "../../state/use-composer-drafts";
2941
import {
3042
EMPTY_INCOMING_SHARE_PRESENTATION_STATE,
3143
transitionIncomingSharePresentation,
@@ -282,6 +294,67 @@ async function releaseShareReservation(
282294
publish(await incomingShareInbox.releaseReservation(shareId, expectedDestination));
283295
}
284296

297+
/** Moves shares into new-task drafts; see makeIncomingShareImports. */
298+
export const incomingShareImports = makeIncomingShareImports({
299+
registry: appAtomRegistry,
300+
getShare: (shareId) => snapshot.drafts.find((draft) => draft.id === shareId) ?? null,
301+
reserve: reserveShare,
302+
release: releaseShareReservation,
303+
consume: consumeShare,
304+
readDraft: getComposerDraftSnapshot,
305+
undoMerge: undoComposerDraftMerge,
306+
mergeIntoDraft: mergeComposerDraftContent,
307+
selectAttachments: (share, environmentId) =>
308+
selectIncomingShareAttachmentsForServer({
309+
attachments: share.attachments,
310+
serverConfig: appAtomRegistry.get(
311+
serverEnvironment.configValueAtom(EnvironmentId.make(environmentId)),
312+
),
313+
}),
314+
releaseUnusedAttachments: scheduleUnusedComposerAttachmentCleanup,
315+
onWarnings: (warnings) => {
316+
Dialog.alert("Some shared content was skipped", warnings.join("\n"));
317+
},
318+
onImportFailure: (target, error) => {
319+
Dialog.alert(
320+
"Could not import shared content",
321+
error instanceof Error ? error.message : "The shared content could not be saved.",
322+
[
323+
{
324+
text: "Cancel import",
325+
style: "cancel",
326+
onPress: () => void incomingShareImports.cancel(target),
327+
},
328+
{ text: "Retry", onPress: () => incomingShareImports.retry(target) },
329+
],
330+
{ cancelable: false },
331+
);
332+
},
333+
onCancelFailure: (target, error) => {
334+
Dialog.alert(
335+
"Could not cancel import",
336+
error instanceof Error ? error.message : "The shared content could not be restored safely.",
337+
[
338+
{ text: "Retry import", onPress: () => incomingShareImports.retry(target) },
339+
{ text: "Retry cancel", onPress: () => void incomingShareImports.cancel(target) },
340+
],
341+
{ cancelable: false },
342+
);
343+
},
344+
leave: (target) => {
345+
rootNavigationRef.dispatch({
346+
...CommonActions.goBack(),
347+
source: target.routeKey,
348+
target: rootNavigationRef.getRootState()?.key,
349+
});
350+
},
351+
});
352+
353+
/** Abandons the share imports of draft routes that left the stack. */
354+
export function pruneIncomingShareImports(state: Parameters<typeof liveNewTaskFlowKeys>[0]) {
355+
void incomingShareImports.prune(liveNewTaskFlowKeys(state));
356+
}
357+
285358
export function useIncomingShare() {
286359
const { drafts, isLoading } = useSyncExternalStore(
287360
subscribeIncomingShares,
@@ -291,8 +364,6 @@ export function useIncomingShare() {
291364
pendingShare: drafts[0] ?? null,
292365
isLoading,
293366
getShare: (shareId: string) => drafts.find((draft) => draft.id === shareId) ?? null,
294-
reserveShare,
295367
releaseShareReservation,
296-
consumeShare,
297368
};
298369
}

0 commit comments

Comments
 (0)