Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
4b5e961
test(web): reproduce #29925 unbacked pasted context references
juliusmarminge Nov 3, 2026
334a40b
fix(web): pasted context links without a record paste as plain text
juliusmarminge Nov 3, 2026
70c4e8a
fix(web): pasted threads from unlinked machines keep their chip
juliusmarminge Nov 3, 2026
e2bca44
fix(web): pasted threads from unlinked machines attach their transcript
juliusmarminge Nov 3, 2026
a7ef64c
fix(web): transcript import failure toast no longer says dropped
juliusmarminge Nov 3, 2026
38a48ea
fix(web): restored thread transcripts land in the restored draft; pas…
juliusmarminge Nov 3, 2026
809724e
fix(web): backticks in a pasted reference's label no longer read as c…
juliusmarminge Nov 3, 2026
ef88e90
fix(web): pasted duplicates keep their chip when the draft holds them…
juliusmarminge Nov 3, 2026
cb72b6c
Merge remote-tracking branch 'origin/main' into fix/issue-29925
juliusmarminge Nov 10, 2026
94d52af
fix(web): pasted threads from machines this client is not connected t…
juliusmarminge Nov 10, 2026
7ce31b6
fix(web): pasted threads the agent cannot read keep a link to their m…
juliusmarminge Nov 10, 2026
cda4957
Merge remote-tracking branch 'origin/main' into fix/issue-29925
juliusmarminge Nov 17, 2026
00fd41b
test(web): fold pasted-reference cases into one table
juliusmarminge Nov 17, 2026
f8f3e26
fix(web): CR-only pastes keep their thread records
juliusmarminge Nov 17, 2026
e430470
fix(mobile): pasted threads from unlinked machines stay links
juliusmarminge Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions apps/mobile/src/components/ComposerEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,13 @@ export function ComposerEditor({
const warnings: string[] = [];
if (result.failures.length > 0)
warnings.push(
"Some attachments could not be copied. Reconnect to the source environment and copy them again.",
"Some attachments could not be copied. Reconnect to the source environment and copy them again. Those references are marked unavailable.",
);
if (result.skippedThreads.length > 0)
warnings.push(
`${result.skippedThreads.map((title) => `"${title}"`).join(", ")} ${result.skippedThreads.length === 1 ? "is" : "are"} on another machine.`,
);
if (warnings.length > 0)
Dialog.alert(
"Some context is unavailable",
[...warnings, "Those references are marked unavailable."].join("\n\n"),
`${result.skippedThreads.map((title) => `"${title}"`).join(", ")} ${result.skippedThreads.length === 1 ? "is" : "are"} on another machine, so the agent gets a link instead.`,
);
if (warnings.length > 0) Dialog.alert("Some context is unavailable", warnings.join("\n\n"));
});
operation.finish();
setComposerContextImporting(draftKey, false);
Expand Down
19 changes: 8 additions & 11 deletions apps/mobile/src/lib/composerContextClipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ThreadId,
} from "@t3tools/contracts";
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
import { formatHostedThreadLink } from "@t3tools/shared/threadLinks";
import {
collectComposerContextReferences,
formatComposerContextReference,
Expand Down Expand Up @@ -245,21 +246,20 @@ describe("mobile context clipboard imports", () => {
]);
expect(result!.failures).toEqual([]);
expect(result!.skippedThreads).toEqual([foreignThread.title]);
// The foreign thread stays a link to its machine, not a reference with no record behind it.
expect(result!.text).toContain(formatHostedThreadLink(foreignThread, foreignThread.label));
const references = collectComposerContextReferences(result!.text);
expect(references.map((reference) => reference.label)).toEqual(
mixedRecords.map((record) => record.label),
);
expect(result!.context.records.map((record) => record.contextId)).toEqual(
references.slice(1).map((reference) => reference.contextId),
references.map((reference) => reference.contextId),
);
expect(references.map((reference) => reference.label)).toEqual(
mixedRecords.slice(1).map((record) => record.label),
);
expect(
references.every(
(reference) => !mixedRecords.some((record) => record.contextId === reference.contextId),
),
).toBe(true);
expect(
result!.context.records.some((record) => record.contextId === references[0]!.contextId),
).toBe(false);
expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);

const restoreHistory = createComposerContextHistory();
Expand Down Expand Up @@ -301,17 +301,14 @@ describe("mobile context clipboard imports", () => {
expect(result!.failures).toEqual([image.name]);
expect(result!.skippedThreads).toEqual([foreignThread.title]);
const references = collectComposerContextReferences(result!.text);
expect(references.map((reference) => reference.label)).toEqual(
mixedRecords.map((record) => record.label),
);
expect(
references
.filter(
(reference) =>
!result!.context.records.some((record) => record.contextId === reference.contextId),
)
.map((reference) => reference.label),
).toEqual([foreignThread.label, image.label]);
).toEqual([image.label]);
expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
});

Expand Down
13 changes: 10 additions & 3 deletions apps/mobile/src/lib/composerContextClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
encodeComposerContextFragment,
} from "@t3tools/shared/composerContextClipboard";
import {
replaceComposerContextReferences,
threadContextsOutsideEnvironment,
threadLinkContextReferences,
} from "@t3tools/shared/composerContextReferences";
import { formatHostedThreadLink } from "@t3tools/shared/threadLinks";
import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
import * as Option from "effect/Option";
Expand Down Expand Up @@ -116,8 +118,13 @@ export async function importComposerContextClipboard(
environmentId: destinationEnvironmentId,
linkedEnvironments,
});
const skippedIds = new Set(skippedThreads.map((record) => record.contextId));
const retained = imported.context.records.filter((record) => !skippedIds.has(record.contextId));
const skippedById = new Map(skippedThreads.map((record) => [record.contextId, record]));
// The agent cannot read these threads, so each stays a link that opens it on its machine.
const text = replaceComposerContextReferences(imported.text, (reference) => {
const thread = skippedById.get(reference.contextId);
return thread ? formatHostedThreadLink(thread, reference.label) : reference.source;
});
const retained = imported.context.records.filter((record) => !skippedById.has(record.contextId));
if (existingContextCount + retained.length > COMPOSER_CONTEXT_MAX_RECORDS)
throw new Error("Remove some context items from the draft before pasting more.");
const attachments: DraftComposerAttachment[] = [];
Expand All @@ -144,7 +151,7 @@ export async function importComposerContextClipboard(
// The last copy can be cancelled after its own check; a cancelled import must not return files nobody will release.
checkAborted(signal);
return {
text: imported.text,
text,
context: { version: 1 as const, records },
attachments,
failures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { ComposerFileAttachment } from "../composerDraftStore";
import { formatInlineContextReference } from "../lib/composerContextReferences";
import { fileContextReference } from "../lib/composerContextRecords";
import {
heldContextIds,
reconcileAttachmentContextReferences,
type RetainedContextPayloads,
useRetainedContextPayloads,
} from "./chat/composerContextUndo";
import { importPastedComposerText } from "./composerInlineTokenPaste";

import {
ComposerContextId,
Expand Down Expand Up @@ -64,15 +66,15 @@ function Composer({
skills,
onChange,
onCommandKeyDown = () => false,
importContextFragment,
importPastedText,
literalText = false,
}: {
value: string;
richTextEnabled: boolean;
skills: ReadonlyArray<ServerProviderSkill>;
onChange?: ComposerPromptEditorProps["onChange"] | undefined;
onCommandKeyDown?: ComposerPromptEditorProps["onCommandKeyDown"] | undefined;
importContextFragment?: ComposerPromptEditorProps["importContextFragment"];
importPastedText?: ComposerPromptEditorProps["importPastedText"];
literalText?: boolean;
}) {
const [prompt, setPrompt] = useState({ value, cursor: value.length });
Expand All @@ -92,7 +94,7 @@ function Composer({
}}
onPaste={() => {}}
onCommandKeyDown={onCommandKeyDown}
importContextFragment={importContextFragment}
importPastedText={importPastedText}
literalText={literalText}
/>
);
Expand Down Expand Up @@ -514,14 +516,16 @@ it.each([
mimeType: "image/png",
sizeBytes: 3,
} satisfies ComposerContextRecord;
const importContextFragment = vi.fn(() => new Map([[record.contextId, record.contextId]]));
const importPastedText = vi.fn((clipboardData: DataTransfer) =>
clipboardData.getData("text/plain"),
);
await using screen = await render(
<Composer
value=""
richTextEnabled
skills={[]}
literalText={literalText}
importContextFragment={importContextFragment}
importPastedText={importPastedText}
/>,
);
const editor = editorIn(screen.container);
Expand All @@ -543,7 +547,7 @@ it.each([
new ClipboardEvent("paste", { clipboardData, cancelable: true }),
);
});
expect(importContextFragment).toHaveBeenCalledTimes(imports);
expect(importPastedText).toHaveBeenCalledTimes(imports);
},
);

Expand Down Expand Up @@ -907,17 +911,24 @@ describe("composer context undo lifetime", () => {
current = draft;
retained = payloads;
});
const contextRecords = new Map(
draft.files.map((entry) => [
fileContextReference(entry).contextId,
{ kind: "file" as const, record: entry },
]),
);
const editorProps = {
draftKey: targetKey,
editorRef,
value: draft.value,
cursor: 0,
contextRecords: new Map(
draft.files.map((entry) => [
fileContextReference(entry).contextId,
{ kind: "file" as const, record: entry },
]),
),
contextRecords,
importPastedText: (clipboardData) =>
importPastedComposerText(
clipboardData,
() => new Map(),
heldContextIds(contextRecords, new Set(), payloads),
),
skills: [],
disabled: false,
placeholder: "",
Expand Down Expand Up @@ -990,6 +1001,22 @@ describe("composer context undo lifetime", () => {
expect(retained.files.size).toBe(0);
});

// A plain-text paste carries no record, so the cut chip used to come back as its label.
it("restores a cut chip and its file bytes when its text is pasted back as plain text", async () => {
await using composer = await mountComposer();
await composer.deleteDraft();
expect(composer.draft()).toEqual({ value: "", files: [] });
await act(async () => {
const clipboardData = new DataTransfer();
clipboardData.setData("text/plain", composer.initialValue);
composer
.editor()
.view.dom.dispatchEvent(new ClipboardEvent("paste", { clipboardData, cancelable: true }));
});
expect(composer.draft().value.trimEnd()).toBe(composer.initialValue);
expect(composer.draft().files[0]?.file).toBe(file.file);
});

it.each(["", "Draft B"])(
"releases deleted payloads and prevents undo into the previous draft when switching to %j",
async (destinationValue) => {
Expand Down
28 changes: 8 additions & 20 deletions apps/web/src/components/ComposerPromptEditorTiptap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import {
} from "@tiptap/pm/state";
import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view";
import type { NodeType, ResolvedPos } from "@tiptap/pm/model";
import type {
AssistantCitation,
ComposerContextClipboardFragment,
ServerProviderSkill,
} from "@t3tools/contracts";
import type { AssistantCitation, ServerProviderSkill } from "@t3tools/contracts";
import {
serializeAssistantCitation,
withAssistantCitationComment,
Expand Down Expand Up @@ -139,11 +135,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
import { ComposerCodeBlockNodeView } from "./chat/ComposerCodeBlockNodeView";
import { resolveAssistantCitationCommentDismissal } from "./chat/assistantCitationCommentDismissal";
import { composerCodeBlockHighlight } from "./composerCodeBlockHighlight";
import {
importPastedComposerText,
readPastedComposerContext,
readPastedPlainText,
} from "./composerInlineTokenPaste";
import { readPastedComposerContext, readPastedPlainText } from "./composerInlineTokenPaste";
import { didComposerSelectionChangeVisibly } from "./composerSelection";
import {
captureComposerAttachmentInsertion,
Expand Down Expand Up @@ -177,9 +169,8 @@ export interface ComposerPromptEditorProps {
buildContextClipboardFragment?:
| ((contextIds: ReadonlyArray<string>) => string | null)
| undefined;
importContextFragment?:
| ((fragment: ComposerContextClipboardFragment) => ReadonlyMap<string, string>)
| undefined;
/** Imports a paste's context records and returns its text with references rewritten. */
importPastedText?: ((clipboardData: DataTransfer) => string) | undefined;
skills: ReadonlyArray<ServerProviderSkill>;
disabled: boolean;
placeholder: string;
Expand Down Expand Up @@ -945,7 +936,7 @@ function ComposerPromptEditorTiptapInner(
literalText = false,
contextRecords,
buildContextClipboardFragment,
importContextFragment,
importPastedText,
skills,
disabled,
placeholder,
Expand Down Expand Up @@ -987,7 +978,7 @@ function ComposerPromptEditorTiptapInner(
onVisibleSelectionChange,
onCommandKeyDown,
isPathQueryActive,
importContextFragment,
importPastedText,
}));

const { environmentId } = use(ComposerContextActionsContext);
Expand Down Expand Up @@ -1445,11 +1436,8 @@ function ComposerPromptEditorTiptapInner(
);
return true;
}
const importFragment = readCallbacks().importContextFragment;
let text =
!literalText && importFragment
? importPastedComposerText(clipboardData, importFragment)
: pastedText;
const importText = readCallbacks().importPastedText;
let text = !literalText && importText ? importText(clipboardData) : pastedText;
const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`);
const isChip = (token: (typeof tokens)[number] | undefined) =>
token?.type === "mention" ||
Expand Down
Loading
Loading