Skip to content

Commit 314bc9c

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3code/codex-citation-handling
# Conflicts: # apps/mobile/src/features/threads/ThreadFeed.tsx # apps/web/src/components/ChatMarkdown.tsx # apps/web/src/components/chat/MessagesTimeline.tsx
2 parents 2039443 + e09b88b commit 314bc9c

73 files changed

Lines changed: 8095 additions & 385 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.

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe("DesktopShellEnvironment", () => {
320320
FNM_DIR: "C:\\Users\\testuser\\AppData\\Roaming\\fnm",
321321
FNM_MULTISHELL_PATH: "C:\\Users\\testuser\\AppData\\Local\\fnm_multishells\\123",
322322
})
323-
: envOutput({ PATH: "C:\\Custom\\Bin;C:\\Windows\\System32" });
323+
: envOutput({ PATH: 'C:\\Custom\\Bin;C:";C:\\Windows\\System32' });
324324
},
325325
});
326326

@@ -337,6 +337,7 @@ describe("DesktopShellEnvironment", () => {
337337
"C:\\Users\\testuser\\.bun\\bin",
338338
"C:\\Users\\testuser\\scoop\\shims",
339339
"C:\\Custom\\Bin",
340+
"C:",
340341
].join(";"),
341342
);
342343
assert.equal(env.FNM_DIR, "C:\\Users\\testuser\\AppData\\Roaming\\fnm");

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ const pathComparisonKey = (entry: string, platform: NodeJS.Platform) => {
151151
return platform === "win32" ? normalized.toLowerCase() : normalized;
152152
};
153153

154+
const sanitizePathEntry = (entry: string, platform: NodeJS.Platform) =>
155+
platform === "win32" ? entry.replaceAll('"', "") : entry;
156+
154157
const mergePaths = (
155158
platform: NodeJS.Platform,
156159
values: ReadonlyArray<Option.Option<string>>,
@@ -163,14 +166,14 @@ const mergePaths = (
163166
if (Option.isNone(value)) continue;
164167

165168
for (const entry of value.value.split(delimiter)) {
166-
const trimmed = entry.trim();
167-
if (trimmed.length === 0) continue;
169+
const sanitized = sanitizePathEntry(entry.trim(), platform);
170+
if (sanitized.length === 0) continue;
168171

169-
const key = pathComparisonKey(trimmed, platform);
172+
const key = pathComparisonKey(sanitized, platform);
170173
if (key.length === 0 || seen.has(key)) continue;
171174

172175
seen.add(key);
173-
entries.push(trimmed);
176+
entries.push(sanitized);
174177
}
175178
}
176179

‎apps/mobile/app.config.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
148148
supportsText: true,
149149
supportsWebUrlWithMaxCount: 1,
150150
supportsImageWithMaxCount: 8,
151+
supportsFileWithMaxCount: 8,
151152
},
152153
},
153154
android: {
154155
enabled: true,
155-
singleShareMimeTypes: ["text/plain", "image/*"],
156-
multipleShareMimeTypes: ["image/*"],
156+
singleShareMimeTypes: ["*/*"],
157+
multipleShareMimeTypes: ["*/*"],
157158
},
158159
},
159160
];

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { SymbolView } from "../components/AppSymbol";
22
import { Image, Pressable, ScrollView, View } from "react-native";
33

4-
import type { DraftComposerImageAttachment } from "../lib/composerImages";
4+
import { AppText as Text } from "./AppText";
5+
import type { DraftComposerAttachment } from "../lib/composerImages";
56

67
export interface ComposerAttachmentStripProps {
7-
/** Attachment images to display. */
8-
readonly attachments: ReadonlyArray<DraftComposerImageAttachment>;
9-
/** Called when the user taps the remove button on an image. */
8+
/** Attachments to display. */
9+
readonly attachments: ReadonlyArray<DraftComposerAttachment>;
10+
/** Called when the user removes an attachment. */
1011
readonly onRemove: (imageId: string) => void;
1112
/** Called when the user taps on an image thumbnail to preview it. */
1213
readonly onPressImage?: (previewUri: string) => void;
@@ -19,8 +20,7 @@ export interface ComposerAttachmentStripProps {
1920
}
2021

2122
/**
22-
* A horizontally-scrollable strip of image attachment thumbnails with remove
23-
* buttons. Used by both the thread composer and the new-task draft screen.
23+
* Attachment thumbnails used by the thread composer and the new-task draft screen.
2424
*/
2525
export function ComposerAttachmentStrip(props: ComposerAttachmentStripProps) {
2626
const size = props.imageSize ?? 72;
@@ -40,37 +40,55 @@ export function ComposerAttachmentStrip(props: ComposerAttachmentStripProps) {
4040
className="grow-0"
4141
>
4242
<View className="flex-row gap-2.5">
43-
{props.attachments.map((image) => (
43+
{props.attachments.map((attachment) => (
4444
<View
45-
key={image.id}
45+
key={attachment.id}
4646
className="relative"
4747
style={{
4848
paddingTop: removeButtonGutter,
4949
paddingRight: removeButtonGutter,
5050
}}
5151
>
52-
<Pressable
53-
onPress={props.onPressImage ? () => props.onPressImage!(image.previewUri) : undefined}
54-
>
55-
<Image
56-
source={{ uri: image.previewUri }}
57-
className="bg-subtle"
52+
{attachment.type === "image" ? (
53+
<Pressable
54+
onPress={
55+
props.onPressImage ? () => props.onPressImage!(attachment.previewUri) : undefined
56+
}
57+
>
58+
<Image
59+
source={{ uri: attachment.previewUri }}
60+
style={{
61+
width: size,
62+
height: size,
63+
borderRadius: radius,
64+
}}
65+
className="bg-subtle"
66+
resizeMode="cover"
67+
/>
68+
</Pressable>
69+
) : (
70+
<View
71+
className="items-center justify-center gap-1 bg-subtle px-2"
5872
style={{
5973
width: size,
6074
height: size,
6175
borderRadius: radius,
6276
}}
63-
resizeMode="cover"
64-
/>
65-
</Pressable>
77+
>
78+
<SymbolView name="doc.text" size={22} tintColor="#a3a3a3" type="monochrome" />
79+
<Text className="w-full text-center text-2xs text-foreground" numberOfLines={1}>
80+
{attachment.name}
81+
</Text>
82+
</View>
83+
)}
6684
<Pressable
6785
className="absolute h-[22px] w-[22px] items-center justify-center rounded-[11px] bg-black/55"
6886
style={{
6987
top: removeButtonPlacement === "gutter" ? 0 : 4,
7088
right: removeButtonPlacement === "gutter" ? 0 : 4,
7189
}}
7290
hitSlop={6}
73-
onPress={() => props.onRemove(image.id)}
91+
onPress={() => props.onRemove(attachment.id)}
7492
>
7593
<SymbolView
7694
name="xmark"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { authClientMetadata } from "../lib/authClientMetadata";
2929
import * as Runtime from "../lib/runtime";
3030
import * as MobileStorage from "../persistence/mobile-storage";
3131
import { appAtomRegistry } from "../state/atom-registry";
32-
import { clearThreadOutboxEnvironment } from "../state/thread-outbox";
32+
import { clearThreadOutboxEnvironment } from "../state/thread-outbox-removal";
3333
import { clearComposerDraftsEnvironment } from "../state/use-composer-drafts";
3434
import { mobileApplicationActiveWakeup } from "./app-state-wakeups";
3535
import { connectionStorageLayer } from "./storage";

‎apps/mobile/src/features/home/usePendingTaskListActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useNavigation } from "@react-navigation/native";
22
import { useCallback } from "react";
33
import { Alert } from "react-native";
44

5-
import { removeThreadOutboxMessage } from "../../state/thread-outbox";
5+
import { removeThreadOutboxMessage } from "../../state/thread-outbox-removal";
66
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
77
import { releaseEditingQueuedMessage } from "../../state/use-thread-outbox";
88

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

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Constants from "expo-constants";
22
import * as Crypto from "expo-crypto";
3+
import { PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
34
import {
45
clearSharedPayloads,
56
getResolvedSharedPayloadsAsync,
@@ -12,11 +13,13 @@ import { Alert, AppState, Platform } from "react-native";
1213

1314
import {
1415
buildIncomingShareDraft,
16+
isShareFileUriUnderOwnedRoots,
1517
type IncomingShareDestination,
1618
type IncomingShareDraft,
1719
} from "./incoming-share-model";
1820
import { createIncomingSharePayloadReader } from "./incoming-share-native";
1921
import { IncomingShareInbox } from "./incoming-share-inbox";
22+
import { persistComposerAttachmentFile } from "../../lib/composerImages";
2023
import {
2124
loadIncomingShareDrafts,
2225
removeIncomingShareDraft,
@@ -54,7 +57,7 @@ const getIncomingSharePayloads = createIncomingSharePayloadReader({
5457
readPayloads: getSharedPayloads,
5558
});
5659

57-
async function resolvedPayloadsForImages(): Promise<ReadonlyArray<ResolvedSharePayload>> {
60+
async function resolvedPayloadsForFiles(): Promise<ReadonlyArray<ResolvedSharePayload>> {
5861
try {
5962
return await getResolvedSharedPayloadsAsync();
6063
} catch (error) {
@@ -84,12 +87,29 @@ async function readBase64(uri: string): Promise<string> {
8487
return new File(uri).base64();
8588
}
8689

90+
async function readFileSize(uri: string): Promise<number | null> {
91+
const { File } = await import("expo-file-system");
92+
return new File(uri).size ?? null;
93+
}
94+
8795
async function removeOwnedFile(uri: string): Promise<void> {
8896
if (!uri.startsWith("file:")) {
8997
return;
9098
}
9199
try {
92-
const { File } = await import("expo-file-system");
100+
const { File, Paths } = await import("expo-file-system");
101+
// Only delete files in directories this app owns: its documents and cache
102+
// sandbox and its share-extension App Group container. An iOS
103+
// open-in-place share points at the sender's own storage; deleting that
104+
// URI would destroy the user's document.
105+
const ownedRootUris = [
106+
Paths.document.uri,
107+
Paths.cache.uri,
108+
...Object.values(Paths.appleSharedContainers ?? {}).map((directory) => directory.uri),
109+
];
110+
if (!isShareFileUriUnderOwnedRoots(uri, ownedRootUris)) {
111+
return;
112+
}
93113
const file = new File(uri);
94114
if (file.exists) {
95115
file.delete();
@@ -99,21 +119,23 @@ async function removeOwnedFile(uri: string): Promise<void> {
99119
}
100120
}
101121

102-
async function removeReplayedImagePayloadFiles(
103-
payloads: ReadonlyArray<SharePayload>,
104-
): Promise<void> {
122+
async function removeReplayedPayloadFiles(payloads: ReadonlyArray<SharePayload>): Promise<void> {
105123
const uris = new Set<string>();
106124
for (const payload of payloads) {
107-
if (payload.shareType === "image") {
125+
if (["image", "file", "audio", "video"].includes(payload.shareType)) {
108126
uris.add(payload.value);
109127
}
110128
}
111129
if (uris.size === 0) {
112130
return;
113131
}
114-
const resolvedPayloads = await resolvedPayloadsForImages();
132+
const resolvedPayloads = payloads.some((payload) =>
133+
["file", "audio", "video"].includes(payload.shareType),
134+
)
135+
? []
136+
: await resolvedPayloadsForFiles();
115137
for (const payload of resolvedPayloads) {
116-
if (payload.shareType === "image" && payload.contentUri) {
138+
if (["image", "file", "audio", "video"].includes(payload.shareType) && payload.contentUri) {
117139
uris.add(payload.contentUri);
118140
}
119141
}
@@ -131,14 +153,29 @@ const incomingShareInbox = new IncomingShareInbox({
131153
clearPayloads: clearSharedPayloads,
132154
buildDraft: async ({ payloads, id, createdAt }) => {
133155
const cleanupUris = new Set<string>();
134-
const resolvedPayloads = payloads.some((payload) => payload.shareType === "image")
135-
? await resolvedPayloadsForImages()
136-
: [];
156+
const persistedUris = new Set<string>();
157+
const hasGenericFilePayload = payloads.some((payload) =>
158+
["file", "audio", "video"].includes(payload.shareType),
159+
);
160+
const resolvedPayloads =
161+
!hasGenericFilePayload && payloads.some((payload) => payload.shareType === "image")
162+
? await resolvedPayloadsForFiles()
163+
: [];
137164
const draft = await buildIncomingShareDraft({
138165
payloads,
139166
resolvedPayloads,
140167
fileReader: {
141168
readBase64,
169+
persistFile: async (uri, name) => {
170+
const persistedUri = await persistComposerAttachmentFile(
171+
uri,
172+
name,
173+
PROVIDER_SEND_TURN_MAX_FILE_BYTES,
174+
);
175+
persistedUris.add(persistedUri);
176+
return persistedUri;
177+
},
178+
readSize: readFileSize,
142179
removeOwnedFile: (uri) => {
143180
cleanupUris.add(uri);
144181
},
@@ -151,9 +188,12 @@ const incomingShareInbox = new IncomingShareInbox({
151188
cleanup: async () => {
152189
await Promise.all([...cleanupUris].map(removeOwnedFile));
153190
},
191+
rollback: async () => {
192+
await Promise.all([...persistedUris].map(removeOwnedFile));
193+
},
154194
};
155195
},
156-
cleanupReplayedPayloads: removeReplayedImagePayloadFiles,
196+
cleanupReplayedPayloads: removeReplayedPayloadFiles,
157197
idForPayloads: incomingShareIdForPayloads,
158198
now: () => new Date().toISOString(),
159199
onClearError: (error) => {

‎apps/mobile/src/features/sharing/incoming-share-inbox.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ describe("IncomingShareInbox", () => {
136136
it("does not acknowledge a supported payload when its durable write fails", async () => {
137137
const clearPayloads = vi.fn();
138138
const cleanup = vi.fn(async () => undefined);
139+
const rollback = vi.fn(async () => undefined);
139140
const { inbox } = createHarness({
140141
clearPayloads,
141142
buildDraft: async ({ id, createdAt }) => ({
142143
draft: draft(id, createdAt),
143144
cleanup,
145+
rollback,
144146
}),
145147
writeDraft: async () => {
146148
throw new Error("disk full");
@@ -150,6 +152,7 @@ describe("IncomingShareInbox", () => {
150152
await expect(inbox.refresh({ ingestNative: true })).rejects.toThrow("disk full");
151153
expect(clearPayloads).not.toHaveBeenCalled();
152154
expect(cleanup).not.toHaveBeenCalled();
155+
expect(rollback).toHaveBeenCalledOnce();
153156
});
154157

155158
it("durably reserves a share for one project before draft import", async () => {

‎apps/mobile/src/features/sharing/incoming-share-inbox.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface IncomingShareInboxDependencies {
2020
}) => Promise<{
2121
readonly draft: IncomingShareDraft;
2222
readonly cleanup: () => Promise<void>;
23+
readonly rollback?: () => Promise<void>;
2324
}>;
2425
readonly cleanupReplayedPayloads?: (payloads: ReadonlyArray<SharePayload>) => Promise<void>;
2526
readonly idForPayloads: (payloads: ReadonlyArray<SharePayload>) => Promise<string>;
@@ -116,7 +117,14 @@ export class IncomingShareInbox {
116117
// The durable inbox write is the transaction boundary. Never clear the
117118
// native handoff first: a process termination must leave one recoverable
118119
// copy on one side of the boundary.
119-
await this.dependencies.writeDraft(draft);
120+
try {
121+
await this.dependencies.writeDraft(draft);
122+
} catch (error) {
123+
if (built.rollback) {
124+
await this.cleanup(built.rollback);
125+
}
126+
throw error;
127+
}
120128
await this.cleanup(built.cleanup);
121129
this.clearNativePayloads();
122130
return sortAndDedupeIncomingShares([draft, ...persisted]);

0 commit comments

Comments
 (0)