Skip to content

Commit bee683c

Browse files
Merge remote-tracking branch 'origin/main' into pr-19581
2 parents a4d9c95 + b874ff6 commit bee683c

120 files changed

Lines changed: 6597 additions & 1267 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/mobile/src/App.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import {
2020
} from "./features/settings/appearance/AppearancePreferencesProvider";
2121
import { RootStack } from "./Stack";
2222
import { appAtomRegistry } from "./state/atom-registry";
23+
import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts";
24+
import { environmentThreadShells } from "./state/threads";
25+
import { environmentShell } from "./state/shell";
2326
import { OverlayPortalHost } from "./components/ui/OverlayPortal";
2427
import { shouldHandleAppLink } from "./lib/appLinking";
2528
import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
@@ -57,6 +60,16 @@ function SplashScreenCoordinator() {
5760

5861
export default function App() {
5962
useUiRuntimeMemoryWarningGc();
63+
useEffect(
64+
() =>
65+
subscribeComposerDraftModelReconciliation({
66+
registry: appAtomRegistry,
67+
threadShellAtom: environmentThreadShells.threadShellAtom,
68+
threadRefsAtom: environmentThreadShells.threadRefsAtom,
69+
shellStateAtom: environmentShell.stateAtom,
70+
}),
71+
[],
72+
);
6073

6174
return (
6275
<RegistryContext.Provider value={appAtomRegistry}>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export function ComposerEditor({
9797
retained.attachments.length,
9898
controller.signal,
9999
retained.context?.records.length ?? 0,
100+
environmentId,
100101
);
101102
if (!result) {
102103
insertComposerDraftText(draftKey, clipboard.text, insertion);
@@ -109,10 +110,19 @@ export function ComposerEditor({
109110
);
110111
return;
111112
}
113+
const warnings: string[] = [];
112114
if (result.failures.length > 0)
115+
warnings.push(
116+
"Some attachments could not be copied. Reconnect to the source environment and copy them again.",
117+
);
118+
if (result.skippedThreads.length > 0)
119+
warnings.push(
120+
`${result.skippedThreads.map((title) => `"${title}"`).join(", ")} ${result.skippedThreads.length === 1 ? "is" : "are"} on another machine.`,
121+
);
122+
if (warnings.length > 0)
113123
Dialog.alert(
114-
"Some attachments could not be copied",
115-
"Reconnect to the source environment and copy them again. References without their files are marked unavailable.",
124+
"Some context is unavailable",
125+
[...warnings, "Those references are marked unavailable."].join("\n\n"),
116126
);
117127
});
118128
setComposerContextImporting(draftKey, false);

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2+
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
13
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
24
import { environmentSession } from "../../state/session";
35
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -783,7 +785,13 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
783785
title: "Copy path",
784786
icon: "doc.on.doc",
785787
inline: false,
786-
onPress: () => copyTextWithHaptic(relativePath),
788+
onPress: () =>
789+
copyTextWithHaptic(
790+
formatFilePathForClipboard(
791+
relativePath,
792+
resolvePathLinkTarget(relativePath, cwd ?? ""),
793+
),
794+
),
787795
} as const,
788796
]),
789797
fileData?.contents != null

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
7171
import { SymbolView } from "../../components/ui/AppSymbol";
7272
import { AppText as Text } from "../../components/ui/AppText";
7373
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
74+
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
7475
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
7576
import { ComposerCommandPopover } from "./ComposerCommandPopover";
7677
import { useComposerCommandMenu } from "./use-composer-command-menu";
@@ -1248,6 +1249,22 @@ export function NewTaskDraftScreen(props: {
12481249
Dialog.alert("Too much context", contextBlockReason);
12491250
return;
12501251
}
1252+
const strandedThread = threadContextsOutsideEnvironment({
1253+
text: draft.text,
1254+
records: draft.context?.records ?? [],
1255+
environmentId: selectedProject.environmentId,
1256+
})[0];
1257+
if (strandedThread) {
1258+
const owner =
1259+
flow.environments.find(
1260+
(environment) => environment.environmentId === strandedThread.environmentId,
1261+
)?.environmentLabel ?? "its machine";
1262+
Dialog.alert(
1263+
"Attached thread unavailable",
1264+
`"${strandedThread.title}" is on another machine. Switch back to ${owner} or remove it from the draft.`,
1265+
);
1266+
return;
1267+
}
12511268

12521269
const editingPendingTask = flow.editingPendingTask;
12531270

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ import {
230230
} from "../files/filePath";
231231
import { waitForThreadShellReady } from "./threadForkNavigation";
232232
import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge";
233-
import { fileChipMenu, resolveFileChipTarget, type FileChipAction } from "./fileChipMenu";
233+
import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
234234
import { useFileChipShare } from "./useFileChipShare";
235235
import {
236236
MarkdownImageAvailableWidthContext,
@@ -1869,13 +1869,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18691869
onFileContextMenuAction: (href, actionId) => {
18701870
const target = resolveFileChipTarget(href, props.workspaceRoot);
18711871
if (!target) return;
1872-
switch (actionId as FileChipAction) {
1872+
switch (actionId) {
18731873
case "copy-full-path":
1874-
if (target.fullPath) copyTextWithHaptic(target.fullPath);
1875-
return;
1876-
case "copy-relative-path":
1877-
if (target.relativePath) copyTextWithHaptic(target.relativePath);
1874+
case "copy-relative-path": {
1875+
const clipboardPath = fileChipClipboardPath(target, actionId);
1876+
if (clipboardPath !== undefined) copyTextWithHaptic(clipboardPath);
18781877
return;
1878+
}
18791879
case "open-file":
18801880
onMarkdownLinkPress(href);
18811881
return;

‎apps/mobile/src/features/threads/fileChipMenu.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { fileChipMenu, fileChipShareSource, resolveFileChipTarget } from "./fileChipMenu";
4+
import {
5+
fileChipClipboardPath,
6+
fileChipMenu,
7+
fileChipShareSource,
8+
resolveFileChipTarget,
9+
} from "./fileChipMenu";
10+
11+
it("copies native paths from a relative file chip in a Windows workspace", () => {
12+
const target = resolveFileChipTarget("reports/Device Users.csv", "C:/repo");
13+
if (!target) throw new Error("File-chip target unavailable");
14+
expect(fileChipClipboardPath(target, "copy-full-path")).toBe(
15+
String.raw`C:\repo\reports\Device Users.csv`,
16+
);
17+
expect(fileChipClipboardPath(target, "copy-relative-path")).toBe(
18+
String.raw`reports\Device Users.csv`,
19+
);
20+
});
521

622
describe("resolveFileChipTarget", () => {
723
it("resolves a workspace-relative link to both paths", () => {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
12
import { fileBasename } from "@t3tools/shared/path";
23
import type { ThreadId } from "@t3tools/contracts";
34
import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks";
@@ -10,13 +11,19 @@ import {
1011
resolveWorkspaceRelativeFilePath,
1112
} from "../files/filePath";
1213

13-
export type FileChipAction = "copy-full-path" | "copy-relative-path" | "open-file" | "save";
14-
1514
export interface FileChipTarget {
1615
readonly fullPath?: string;
1716
readonly relativePath?: string;
1817
}
1918

19+
export function fileChipClipboardPath(
20+
target: FileChipTarget,
21+
action: "copy-full-path" | "copy-relative-path",
22+
): string | undefined {
23+
const path = action === "copy-full-path" ? target.fullPath : target.relativePath;
24+
return path === undefined ? undefined : formatFilePathForClipboard(path, target.fullPath);
25+
}
26+
2027
export function resolveFileChipTarget(
2128
href: string,
2229
workspaceRoot: string | null | undefined,

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ThreadId,
2525
} from "@t3tools/contracts";
2626
import { sanitizeNewRefName } from "@t3tools/shared/git";
27+
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
2728
import { resolveNewThreadEnvMode, resolveProjectSettings } from "@t3tools/shared/projectSettings";
2829
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
2930
import * as Arr from "effect/Array";
@@ -961,6 +962,15 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
961962
if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) {
962963
return null;
963964
}
965+
if (
966+
threadContextsOutsideEnvironment({
967+
text: draft.text,
968+
records: draft.context?.records ?? [],
969+
environmentId: selectedProject.environmentId,
970+
}).length > 0
971+
) {
972+
return null;
973+
}
964974
const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined;
965975
const mode = workspaceSelection?.mode ?? workspaceMode;
966976
// When the selection is the stand-in built from the queued snapshot,

‎apps/mobile/src/lib/composerContextClipboard.test.ts‎

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2-
import { ComposerContextId, EnvironmentId } from "@t3tools/contracts";
2+
import {
3+
COMPOSER_CONTEXT_MAX_RECORDS,
4+
ComposerContextId,
5+
EnvironmentId,
6+
ThreadId,
7+
} from "@t3tools/contracts";
38
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
9+
import {
10+
collectComposerContextReferences,
11+
formatComposerContextReference,
12+
} from "@t3tools/shared/composerContextReferences";
413

514
const mocks = vi.hoisted(() => ({
615
execute: vi.fn(),
@@ -44,6 +53,7 @@ vi.mock("./composerImages", () => ({
4453
vi.mock("./uuid", () => ({ uuidv4: () => `import-${++mocks.sequence}` }));
4554

4655
import { importComposerContextClipboard } from "./composerContextClipboard";
56+
import { createComposerContextHistory } from "./composerContext";
4757

4858
const image = {
4959
version: 1 as const,
@@ -76,6 +86,42 @@ const clipboard = {
7686
html: "",
7787
};
7888

89+
const localThread = {
90+
version: 1 as const,
91+
kind: "thread" as const,
92+
contextId: ComposerContextId.make("thread_local-thread"),
93+
label: "Local discussion",
94+
environmentId: EnvironmentId.make("destination"),
95+
threadId: ThreadId.make("local-thread"),
96+
title: "Local discussion",
97+
};
98+
const foreignThread = {
99+
...localThread,
100+
contextId: ComposerContextId.make("thread_foreign-thread"),
101+
label: "Remote discussion",
102+
environmentId: EnvironmentId.make("source"),
103+
threadId: ThreadId.make("foreign-thread"),
104+
title: "Remote discussion",
105+
};
106+
const mixedRecords = [foreignThread, localThread, terminal, image];
107+
const mixedClipboard = {
108+
text: `Compare these findings: ${mixedRecords.map(formatComposerContextReference).join(" ")} before changing anything.`,
109+
fragment: encodeComposerContextFragment({
110+
version: 1,
111+
source: { environmentId: EnvironmentId.make("source") },
112+
records: [
113+
...mixedRecords,
114+
{
115+
...foreignThread,
116+
contextId: ComposerContextId.make("thread_uncopied-thread"),
117+
threadId: ThreadId.make("uncopied-thread"),
118+
title: "Not in the copied selection",
119+
},
120+
],
121+
})!,
122+
html: "",
123+
};
124+
79125
beforeEach(() => {
80126
vi.clearAllMocks();
81127
mocks.sequence = 0;
@@ -142,6 +188,114 @@ describe("mobile context clipboard imports", () => {
142188
expect(mocks.download).not.toHaveBeenCalled();
143189
});
144190

191+
it("pastes local threads, text context and files at the cap after excluding foreign threads", async () => {
192+
const result = await importComposerContextClipboard(
193+
mixedClipboard,
194+
0,
195+
new AbortController().signal,
196+
COMPOSER_CONTEXT_MAX_RECORDS - 3,
197+
EnvironmentId.make("destination"),
198+
);
199+
expect(result).not.toBeNull();
200+
expect(result!.context.records).toEqual([
201+
{ ...localThread, contextId: expect.any(String) },
202+
{ ...terminal, contextId: expect.any(String) },
203+
{ ...image, contextId: expect.any(String), attachmentId: result!.attachments[0]!.id },
204+
]);
205+
expect(result!.attachments).toEqual([
206+
expect.objectContaining({ name: image.name, fileUri: "file:///owned.png" }),
207+
]);
208+
expect(result!.failures).toEqual([]);
209+
expect(result!.skippedThreads).toEqual([foreignThread.title]);
210+
const references = collectComposerContextReferences(result!.text);
211+
expect(references.map((reference) => reference.label)).toEqual(
212+
mixedRecords.map((record) => record.label),
213+
);
214+
expect(result!.context.records.map((record) => record.contextId)).toEqual(
215+
references.slice(1).map((reference) => reference.contextId),
216+
);
217+
expect(
218+
references.every(
219+
(reference) => !mixedRecords.some((record) => record.contextId === reference.contextId),
220+
),
221+
).toBe(true);
222+
expect(
223+
result!.context.records.some((record) => record.contextId === references[0]!.contextId),
224+
).toBe(false);
225+
expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
226+
227+
const restoreHistory = createComposerContextHistory();
228+
restoreHistory(formatComposerContextReference(foreignThread), {
229+
version: 1,
230+
records: [foreignThread],
231+
});
232+
expect(restoreHistory(`${result!.text} Next step`, result!.context)).toEqual(result!.context);
233+
234+
mocks.download.mockClear();
235+
await expect(
236+
importComposerContextClipboard(
237+
mixedClipboard,
238+
0,
239+
new AbortController().signal,
240+
COMPOSER_CONTEXT_MAX_RECORDS - 2,
241+
EnvironmentId.make("destination"),
242+
),
243+
).rejects.toThrow("Remove some context");
244+
expect(mocks.download).not.toHaveBeenCalled();
245+
});
246+
247+
it("reports foreign threads and failed files together while keeping the rest of a paste", async () => {
248+
mocks.download.mockRejectedValueOnce(new Error("source disconnected"));
249+
const result = await importComposerContextClipboard(
250+
mixedClipboard,
251+
0,
252+
new AbortController().signal,
253+
0,
254+
EnvironmentId.make("destination"),
255+
);
256+
expect(result).not.toBeNull();
257+
expect(result!.context.records).toEqual([
258+
{ ...localThread, contextId: expect.any(String) },
259+
{ ...terminal, contextId: expect.any(String) },
260+
]);
261+
expect(result!.attachments).toEqual([]);
262+
expect(result!.failures).toEqual([image.name]);
263+
expect(result!.skippedThreads).toEqual([foreignThread.title]);
264+
const references = collectComposerContextReferences(result!.text);
265+
expect(references.map((reference) => reference.label)).toEqual(
266+
mixedRecords.map((record) => record.label),
267+
);
268+
expect(
269+
references
270+
.filter(
271+
(reference) =>
272+
!result!.context.records.some((record) => record.contextId === reference.contextId),
273+
)
274+
.map((reference) => reference.label),
275+
).toEqual([foreignThread.label, image.label]);
276+
expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
277+
});
278+
279+
it("preserves both machines' thread references when pasting without a destination", async () => {
280+
const result = await importComposerContextClipboard(
281+
mixedClipboard,
282+
0,
283+
new AbortController().signal,
284+
);
285+
expect(result).not.toBeNull();
286+
expect(result!.context.records).toEqual([
287+
{ ...foreignThread, contextId: expect.any(String) },
288+
{ ...localThread, contextId: expect.any(String) },
289+
{ ...terminal, contextId: expect.any(String) },
290+
{ ...image, contextId: expect.any(String), attachmentId: result!.attachments[0]!.id },
291+
]);
292+
expect(result!.attachments).toHaveLength(1);
293+
expect(result!.failures).toEqual([]);
294+
expect(
295+
collectComposerContextReferences(result!.text).map((reference) => reference.contextId),
296+
).toEqual(result!.context.records.map((record) => record.contextId));
297+
});
298+
145299
it("refuses an overflowing context paste before copying files", async () => {
146300
await expect(
147301
importComposerContextClipboard(clipboard, 0, new AbortController().signal, 200),

0 commit comments

Comments
 (0)