GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): don't send or paste attached threads a machine can't rea… · NikitaMGrimm/t3code@21517ed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src
    • components
      • ComposerEditor.tsx
    • features/threads
      • NewTaskDraftScreen.tsx
      • new-task-flow-provider.tsx
    • lib
      • composerContextClipboard.test.ts
      • composerContextClipboard.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/components/ComposerEditor.tsx
+16-3Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function ComposerEditor({
101101
retained.attachments.length,
102102
controller.signal,
103103
retained.context?.records.length ?? 0,
104+
environmentId,
104105
);
105106
if (!result) {
106107
insertComposerDraftText(draftKey, clipboard.text, insertion);
@@ -113,10 +114,22 @@ export function ComposerEditor({
113114
);
114115
return;
115116
}
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)
117130
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"),
120133
);
121134
} catch (error) {
122135
if (!controller.signal.aborted)
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
6767
import { SymbolView } from "../../components/AppSymbol";
6868
import { AppText as Text } from "../../components/AppText";
6969
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
70+
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
7071
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
7172
import { ComposerCommandPopover } from "./ComposerCommandPopover";
7273
import { useComposerCommandMenu } from "./use-composer-command-menu";
@@ -1313,6 +1314,22 @@ export function NewTaskDraftScreen(props: {
13131314
Alert.alert("Too much context", contextBlockReason);
13141315
return;
13151316
}
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+
}
13161333

13171334
const editingPendingTask = flow.editingPendingTask;
13181335

Collapse file

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

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 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";
@@ -1131,6 +1132,16 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
11311132
if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) {
11321133
return null;
11331134
}
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+
}
11341145
// A saved choice from before the project went no-project must not
11351146
// survive: those threads always run locally in their own folder.
11361147
const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined;
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContextClipboard.test.ts
+55-1Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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";
49

510
const mocks = vi.hoisted(() => ({
@@ -142,6 +147,55 @@ describe("mobile context clipboard imports", () => {
142147
expect(mocks.download).not.toHaveBeenCalled();
143148
});
144149

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+
145199
it("refuses an overflowing context paste before copying files", async () => {
146200
await expect(
147201
importComposerContextClipboard(clipboard, 0, new AbortController().signal, 200),
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContextClipboard.ts
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,29 @@ export async function importComposerContextClipboard(
6666
existingCount: number,
6767
signal: AbortSignal,
6868
existingContextCount = 0,
69+
destinationEnvironmentId?: EnvironmentId,
6970
) {
7071
const fragment =
7172
decodeComposerContextFragment(input.fragment) ?? decodeComposerContextClipboardHtml(input.html);
7273
if (!fragment) return null;
7374
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)
7590
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);
7792
const attachments: DraftComposerAttachment[] = [];
7893
const records: ComposerContextRecord[] = [];
7994
const failures: string[] = [];
@@ -100,6 +115,7 @@ export async function importComposerContextClipboard(
100115
context: { version: 1 as const, records },
101116
attachments,
102117
failures,
118+
skippedThreads,
103119
};
104120
} catch (error) {
105121
await Promise.all(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.