GeezerVison is showing github.com — fix(mobile): don't send or paste attached threads a machine can't rea… · NikitaMGrimm/t3code@21517ed
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ComposerEditor.tsx +16-3Lines changed: 16 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,6 +101,7 @@ export function ComposerEditor({ | 101 | 101 | retained.attachments.length, | 102 | 102 | controller.signal, | 103 | 103 | retained.context?.records.length ?? 0, | | 104 | + environmentId, | 104 | 105 | ); | 105 | 106 | if (!result) { | 106 | 107 | insertComposerDraftText(draftKey, clipboard.text, insertion); | @@ -113,10 +114,22 @@ export function ComposerEditor({ | 113 | 114 | ); | 114 | 115 | return; | 115 | 116 | } | 116 | | - if (result.failures.length > 0) | | 117 | + const warnings = [ | | 118 | + ...(result.failures.length > 0 | | 119 | + ? [ | | 120 | + "Some attachments could not be copied. Reconnect to the source environment and copy them again.", | | 121 | + ] | | 122 | + : []), | | 123 | + ...(result.skippedThreads.length > 0 | | 124 | + ? [ | | 125 | + `${result.skippedThreads.map((title) => `"${title}"`).join(", ")} ${result.skippedThreads.length === 1 ? "is" : "are"} on another machine.`, | | 126 | + ] | | 127 | + : []), | | 128 | + ]; | | 129 | + if (warnings.length > 0) | 117 | 130 | Alert.alert( | 118 | | - "Some attachments could not be copied", | 119 | | - "Reconnect to the source environment and copy them again. References without their files are marked unavailable.", | | 131 | + "Some context is unavailable", | | 132 | + [...warnings, "Those references are marked unavailable."].join("\n\n"), | 120 | 133 | ); | 121 | 134 | } catch (error) { | 122 | 135 | if (!controller.signal.aborted) | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/NewTaskDraftScreen.tsx +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,6 +67,7 @@ import { ProviderIcon } from "../../components/ProviderIcon"; | 67 | 67 | import { SymbolView } from "../../components/AppSymbol"; | 68 | 68 | import { AppText as Text } from "../../components/AppText"; | 69 | 69 | import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits"; | | 70 | +import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences"; | 70 | 71 | import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer"; | 71 | 72 | import { ComposerCommandPopover } from "./ComposerCommandPopover"; | 72 | 73 | import { useComposerCommandMenu } from "./use-composer-command-menu"; | @@ -1313,6 +1314,22 @@ export function NewTaskDraftScreen(props: { | 1313 | 1314 | Alert.alert("Too much context", contextBlockReason); | 1314 | 1315 | return; | 1315 | 1316 | } | | 1317 | + const strandedThread = threadContextsOutsideEnvironment({ | | 1318 | + text: draft.text, | | 1319 | + records: draft.context?.records ?? [], | | 1320 | + environmentId: selectedProject.environmentId, | | 1321 | + })[0]; | | 1322 | + if (strandedThread) { | | 1323 | + const owner = | | 1324 | + flow.environments.find( | | 1325 | + (environment) => environment.environmentId === strandedThread.environmentId, | | 1326 | + )?.environmentLabel ?? "its machine"; | | 1327 | + Alert.alert( | | 1328 | + "Attached thread unavailable", | | 1329 | + `"${strandedThread.title}" is on another machine. Switch back to ${owner} or remove it from the draft.`, | | 1330 | + ); | | 1331 | + return; | | 1332 | + } | 1316 | 1333 |
| 1317 | 1334 | const editingPendingTask = flow.editingPendingTask; | 1318 | 1335 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/new-task-flow-provider.tsx +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,7 @@ import { | 24 | 24 | ThreadId, | 25 | 25 | } from "@t3tools/contracts"; | 26 | 26 | import { sanitizeNewRefName } from "@t3tools/shared/git"; | | 27 | +import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences"; | 27 | 28 | import { resolveNewThreadEnvMode, resolveProjectSettings } from "@t3tools/shared/projectSettings"; | 28 | 29 | import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile"; | 29 | 30 | import * as Arr from "effect/Array"; | @@ -1131,6 +1132,16 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) { | 1131 | 1132 | if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) { | 1132 | 1133 | return null; | 1133 | 1134 | } | | 1135 | + // A thread attached on another machine is unreadable here; the submit path explains why. | | 1136 | + if ( | | 1137 | + threadContextsOutsideEnvironment({ | | 1138 | + text: draft.text, | | 1139 | + records: draft.context?.records ?? [], | | 1140 | + environmentId: selectedProject.environmentId, | | 1141 | + }).length > 0 | | 1142 | + ) { | | 1143 | + return null; | | 1144 | + } | 1134 | 1145 | // A saved choice from before the project went no-project must not | 1135 | 1146 | // survive: those threads always run locally in their own folder. | 1136 | 1147 | const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContextClipboard.test.ts +55-1Lines changed: 55 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 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"; | 3 | 8 | import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard"; | 4 | 9 |
| 5 | 10 | const mocks = vi.hoisted(() => ({ | @@ -142,6 +147,55 @@ describe("mobile context clipboard imports", () => { | 142 | 147 | expect(mocks.download).not.toHaveBeenCalled(); | 143 | 148 | }); | 144 | 149 |
| | 150 | + const thread = (id: string, environmentId: string) => ({ | | 151 | + version: 1 as const, | | 152 | + kind: "thread" as const, | | 153 | + contextId: ComposerContextId.make(id), | | 154 | + label: id, | | 155 | + environmentId: EnvironmentId.make(environmentId), | | 156 | + threadId: ThreadId.make(id), | | 157 | + title: id, | | 158 | + }); | | 159 | + | | 160 | + it("drops threads owned by another machine than the destination", async () => { | | 161 | + const result = await importComposerContextClipboard( | | 162 | + { | | 163 | + text: "[local](t3-context://v1/thread/local) [foreign](t3-context://v1/thread/foreign)", | | 164 | + fragment: encodeComposerContextFragment({ | | 165 | + version: 1, | | 166 | + source: { environmentId: EnvironmentId.make("source") }, | | 167 | + records: [thread("local", "destination"), thread("foreign", "source")], | | 168 | + })!, | | 169 | + html: "", | | 170 | + }, | | 171 | + 0, | | 172 | + new AbortController().signal, | | 173 | + // Only one slot is free: the dropped thread must not count against it. | | 174 | + COMPOSER_CONTEXT_MAX_RECORDS - 1, | | 175 | + EnvironmentId.make("destination"), | | 176 | + ); | | 177 | + expect(result?.context.records.map((record) => record.label)).toEqual(["local"]); | | 178 | + expect(result?.skippedThreads).toEqual(["foreign"]); | | 179 | + }); | | 180 | + | | 181 | + it("keeps threads when the destination machine is unknown", async () => { | | 182 | + const result = await importComposerContextClipboard( | | 183 | + { | | 184 | + text: "[foreign](t3-context://v1/thread/foreign)", | | 185 | + fragment: encodeComposerContextFragment({ | | 186 | + version: 1, | | 187 | + source: { environmentId: EnvironmentId.make("source") }, | | 188 | + records: [thread("foreign", "source")], | | 189 | + })!, | | 190 | + html: "", | | 191 | + }, | | 192 | + 0, | | 193 | + new AbortController().signal, | | 194 | + ); | | 195 | + expect(result?.context.records.map((record) => record.label)).toEqual(["foreign"]); | | 196 | + expect(result?.skippedThreads).toEqual([]); | | 197 | + }); | | 198 | + | 145 | 199 | it("refuses an overflowing context paste before copying files", async () => { | 146 | 200 | await expect( | 147 | 201 | importComposerContextClipboard(clipboard, 0, new AbortController().signal, 200), | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContextClipboard.ts +18-2Lines changed: 18 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -66,14 +66,29 @@ export async function importComposerContextClipboard( | 66 | 66 | existingCount: number, | 67 | 67 | signal: AbortSignal, | 68 | 68 | existingContextCount = 0, | | 69 | + destinationEnvironmentId?: EnvironmentId, | 69 | 70 | ) { | 70 | 71 | const fragment = | 71 | 72 | decodeComposerContextFragment(input.fragment) ?? decodeComposerContextClipboardHtml(input.html); | 72 | 73 | if (!fragment) return null; | 73 | 74 | const selected = referencedComposerContext(input.text, { version: 1, records: fragment.records }); | 74 | | - if (existingContextCount + (selected?.records.length ?? 0) > COMPOSER_CONTEXT_MAX_RECORDS) | | 75 | + // The agent can only read threads on its own server; a pasted foreign one is dropped and its | | 76 | + // reference stays visibly unavailable, like an attachment that failed to copy. | | 77 | + const skippedThreads: string[] = []; | | 78 | + const retained = (selected?.records ?? []).filter((record) => { | | 79 | + if ( | | 80 | + record.kind !== "thread" || | | 81 | + !("threadId" in record) || | | 82 | + destinationEnvironmentId === undefined || | | 83 | + record.environmentId === destinationEnvironmentId | | 84 | + ) | | 85 | + return true; | | 86 | + skippedThreads.push(record.title); | | 87 | + return false; | | 88 | + }); | | 89 | + if (existingContextCount + retained.length > COMPOSER_CONTEXT_MAX_RECORDS) | 75 | 90 | throw new Error("Remove some context items from the draft before pasting more."); | 76 | | - const imported = reidentifyComposerContext(input.text, selected?.records ?? [], uuidv4); | | 91 | + const imported = reidentifyComposerContext(input.text, retained, uuidv4); | 77 | 92 | const attachments: DraftComposerAttachment[] = []; | 78 | 93 | const records: ComposerContextRecord[] = []; | 79 | 94 | const failures: string[] = []; | @@ -100,6 +115,7 @@ export async function importComposerContextClipboard( | 100 | 115 | context: { version: 1 as const, records }, | 101 | 116 | attachments, | 102 | 117 | failures, | | 118 | + skippedThreads, | 103 | 119 | }; | 104 | 120 | } catch (error) { | 105 | 121 | await Promise.all( | |
|