From 8e049569f72cdb0a5ebf4dc9a6f545125f110309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:32:58 -0400 Subject: [PATCH 1/8] feat(mobile): cite selected assistant text from the selection menu Selecting text in an assistant reply now offers Cite next to Copy, like web. Cite asks for an optional comment, then inserts the same citation link web uses into the composer, where it shows as a quote chip. Co-Authored-By: Claude Opus 5.5 --- .../assets/context-chip-icons/quote.png | Bin 0 -> 1259 bytes .../scripts/sync-context-chip-icons.mjs | 1 + .../src/features/threads/ThreadFeed.tsx | 20 ++++++ .../src/features/threads/citeAssistantText.ts | 63 ++++++++++++++++++ .../src/lib/composerChipPresentation.ts | 1 + apps/mobile/src/lib/composerContext.test.ts | 27 ++++++++ apps/mobile/src/lib/composerContext.ts | 16 ++++- .../src/lib/contextChipIcons.generated.ts | 1 + .../src/native/EnrichedMarkdownText.tsx | 15 ++++- .../native/SelectableMarkdownText.types.ts | 2 + .../src/native/T3ComposerEditor.ios.tsx | 8 ++- .../src/native/T3ComposerEditor.native.tsx | 8 ++- 12 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 apps/mobile/assets/context-chip-icons/quote.png create mode 100644 apps/mobile/src/features/threads/citeAssistantText.ts diff --git a/apps/mobile/assets/context-chip-icons/quote.png b/apps/mobile/assets/context-chip-icons/quote.png new file mode 100644 index 0000000000000000000000000000000000000000..0e180813c3ca5ca427266288b0410ac621dcebf6 GIT binary patch literal 1259 zcmVJNRCt{2n_GxhRTRgMO;(yC6h5RRQkY^-7J@#A7X-sH%F9SZ z^bq(EOk?z58CjA~f<~DpK`KF$I0}wXdBvh0te}fZPrVe8QGuDIc^T&?3%8f%TkGu0 zIY)!`ALeCPd;Qm5XYIAu+IxRRk&%&+k>Lk$H?Ra)2lROUx`8!72hd)DvmIFEbae;t zifvuMU8$Tc0PX~~0R5!l4`3lFou zf)!lRGr=%sx*|K%kR6}Et3|@Ps_TDyf+05;lUf+D{s$%SYKe4fjDj9TK~Jn9PM3y7 zikuWYElA|7WDyyMS-004QtQ=Qw-U;*TVrFhB5nrdmD1V zP~fC-Ao_4jB-G)6c6Xy=;cwtG;64ea+_nJ5BLt)=sV%9rI6#|byf)En0$0i z4j2cV3E(^d%x~HOZNTn8C+xKjFJm0w80uCqy8x^^mjR<%of%9oa&j~|zry~1a>U{qNU?Ol%A$VDl9cegV zW)T747U1iMBq&ANK)e;hsU^RMfE6Vb;uK}v3`2J8Kw0B@eX9HN+T;amjIr9=gk?U? z766mvS{y&Vm78E?{7Z`LX?X%wS-pCldYvJ_H_@!;hMH=LGa2 zhg{QB?I$r2FTS5~iE)#w#XH^W?jc13aLw2g!0U37 void) | undefined; @@ -1149,6 +1153,15 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: { linkCustomization: (href) => withChipIcon(props.linkHandlers.linkCustomization?.(href), threadIcons.get(href)), }; + const { environmentId, citeThreadId: threadId, citeMessageId: messageId } = props; + const onCite = useMemo( + () => + threadId && messageId + ? (selection: { readonly text: string; readonly start: number }) => + citeAssistantText({ environmentId, threadId, messageId }, selection) + : undefined, + [environmentId, threadId, messageId], + ); return ( ); }); @@ -1172,6 +1186,9 @@ function AssistantMarkdownBlocks(props: { readonly renderImage: MarkdownImageRenderer; readonly skills?: ReadonlyArray | undefined; readonly models: ReturnType; + readonly onCite: + | ((selection: { readonly text: string; readonly start: number }) => void) + | undefined; }) { const blocks = useMemo( () => @@ -1215,6 +1232,7 @@ function AssistantMarkdownBlocks(props: { textStyle={props.markdownStyles.nativeTextStyle} {...props.linkHandlers} renderImage={props.renderImage} + onCite={props.onCite} /> ); }); @@ -2236,6 +2254,8 @@ function renderFeedEntry( ASSISTANT_CITATION_MAX_TEXT_LENGTH) { + Dialog.alert("Selection is too long to cite", "Select a shorter passage and try again."); + return; + } + const draftKey = scopedThreadKey(source.environmentId, source.threadId); + const insertion = captureComposerDraftInsertion(draftKey); + const start = Math.max(0, selection.start); + // Native offsets are per rendered block, not per message, and carry no surrounding context; + // web resolves the quote by its text when the offsets do not line up. + const citation = { + version: 1 as const, + ...source, + text, + start, + end: start + text.replace(/\s+/g, " ").length, + prefix: "", + suffix: "", + }; + Dialog.prompt({ + title: "Cite", + message: "Add a comment about this quote (optional).", + placeholder: "Comment", + initialValue: "", + confirmText: "Cite", + onConfirm: (comment) => { + const before = insertion.text.slice(0, insertion.start); + const lead = before.length > 0 && !/\s$/.test(before) ? " " : ""; + insertComposerDraftText( + draftKey, + `${lead}${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `, + insertion, + ); + }, + }); +} diff --git a/apps/mobile/src/lib/composerChipPresentation.ts b/apps/mobile/src/lib/composerChipPresentation.ts index 067e3aea2ecf7..7efc99fc04bce 100644 --- a/apps/mobile/src/lib/composerChipPresentation.ts +++ b/apps/mobile/src/lib/composerChipPresentation.ts @@ -39,6 +39,7 @@ const CONTEXT_CHIP_PRESENTATIONS = { icon: "git-pull-request-arrow", }, skill: { accent: "#b261be", icon: "skill" }, + citation: { icon: "quote" }, thread: { accent: "#009c96", icon: "messages-square", diff --git a/apps/mobile/src/lib/composerContext.test.ts b/apps/mobile/src/lib/composerContext.test.ts index 2e1ee64831d08..7a2c1c6ca91af 100644 --- a/apps/mobile/src/lib/composerContext.test.ts +++ b/apps/mobile/src/lib/composerContext.test.ts @@ -1,8 +1,12 @@ import { ComposerContextId, + EnvironmentId, + MessageId, + ThreadId, type OrchestrationMessageContext, type ServerProviderSkill, } from "@t3tools/contracts"; +import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations"; import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens"; import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, @@ -156,6 +160,29 @@ describe("mobile composer context", () => { expect(restore("deleted")?.records ?? []).toEqual([]); expect(createComposerContextHistory()(source)?.records).toEqual([]); }); + it("chips a cited assistant quote as one token, hiding mentions inside its link", () => { + const quote = serializeAssistantCitation({ + version: 1, + environmentId: EnvironmentId.make("env"), + threadId: ThreadId.make("thread"), + messageId: MessageId.make("message"), + text: "Run $deploy with model:codex/gpt-6.1 ", + start: 0, + end: 37, + prefix: "", + suffix: "", + comment: "Why this one?", + }); + const text = `See ${quote} please`; + expect( + composerContextEditorTokens( + text, + collectComposerInlineTokens(text), + new Set(["deploy"]), + collectComposerModelTokens(text, new Set(["model:codex/gpt-6.1"])), + ).map((token) => [token.type, token.value, token.start, token.end]), + ).toEqual([["citation", "Why this one?", 4, 4 + quote.length]]); + }); it("chips a model reference only once it is complete and names a known model", () => { const known = new Set(["model:codex/gpt-6.1"]); const modelTokens = (text: string) => diff --git a/apps/mobile/src/lib/composerContext.ts b/apps/mobile/src/lib/composerContext.ts index 53494209362af..30c37ab74ba87 100644 --- a/apps/mobile/src/lib/composerContext.ts +++ b/apps/mobile/src/lib/composerContext.ts @@ -4,6 +4,10 @@ import { } from "@t3tools/client-runtime/composer-model-mentions"; import { isProviderSkillUserInvocable } from "@t3tools/client-runtime/providerSkills"; import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; +import { + assistantCitationLabel, + collectAssistantCitations, +} from "@t3tools/shared/assistantCitations"; import { filePreviewKind } from "@t3tools/shared/filePreview"; import { videoMimeType } from "@t3tools/shared/video"; import { @@ -194,13 +198,14 @@ export function composerContextEditorTokens( modelTokens: ReadonlyArray = [], ) { const references = collectComposerContextReferences(text); + const citations = collectAssistantCitations(text); const inlineTokens = tokens.filter( (token) => // `$HOME` and other `$name` text that is not one of the provider's skills stays prose. (token.type !== "skill" || knownSkills.has(token.value)) && - !references.some((ref) => token.start < ref.end && token.end > ref.start), + ![...references, ...citations].some((ref) => token.start < ref.end && token.end > ref.start), ); - const taken = [...inlineTokens, ...references, ...composerMathRanges(text)]; + const taken = [...inlineTokens, ...references, ...citations, ...composerMathRanges(text)]; const models = modelTokens.filter( (mention) => !taken.some((range) => mention.start < range.end && mention.end > range.start), ); @@ -216,6 +221,13 @@ export function composerContextEditorTokens( value: mention.model, ...mention, })), + ...citations.map(({ citation, source, start, end }) => ({ + type: "citation" as const, + value: assistantCitationLabel(citation), + source, + start, + end, + })), ].sort((a, b) => a.start - b.start); } diff --git a/apps/mobile/src/lib/contextChipIcons.generated.ts b/apps/mobile/src/lib/contextChipIcons.generated.ts index 170fe0c776fc1..683e65adf1538 100644 --- a/apps/mobile/src/lib/contextChipIcons.generated.ts +++ b/apps/mobile/src/lib/contextChipIcons.generated.ts @@ -12,6 +12,7 @@ export const CONTEXT_CHIP_ICON_SOURCES = { "message-circle": require("../../assets/context-chip-icons/message-circle.png"), "messages-square": require("../../assets/context-chip-icons/messages-square.png"), "mouse-pointer-click": require("../../assets/context-chip-icons/mouse-pointer-click.png"), + quote: require("../../assets/context-chip-icons/quote.png"), server: require("../../assets/context-chip-icons/server.png"), skill: require("../../assets/context-chip-icons/skill.png"), terminal: require("../../assets/context-chip-icons/terminal.png"), diff --git a/apps/mobile/src/native/EnrichedMarkdownText.tsx b/apps/mobile/src/native/EnrichedMarkdownText.tsx index 86bf8021bdd0f..25622e701c251 100644 --- a/apps/mobile/src/native/EnrichedMarkdownText.tsx +++ b/apps/mobile/src/native/EnrichedMarkdownText.tsx @@ -218,7 +218,19 @@ function codeBlockElement( } export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { - const { renderImage, resolveImageSource, fileEmbedLabel } = props; + const { renderImage, resolveImageSource, fileEmbedLabel, onCite } = props; + const citeMenuItems = useMemo( + () => + onCite && [ + { + text: "Cite", + icon: "quote.bubble", + onPress: ({ text, selection }: { text: string; selection: { start: number } }) => + onCite({ text, start: selection.start }), + }, + ], + [onCite], + ); const { themeAppearance, mathRenderingEnabled } = useAppearancePreferences(); const { markdown, fileHrefs } = useMemo(() => { if (!fileEmbedLabel) { @@ -439,6 +451,7 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { onLinkLongPress={onLinkLongPress} linkContextMenuItems={linkContextMenuItems} linkPillContent={linkPillContent} + contextMenuItems={citeMenuItems} /> ); diff --git a/apps/mobile/src/native/SelectableMarkdownText.types.ts b/apps/mobile/src/native/SelectableMarkdownText.types.ts index 63f8429c386fd..1295be40df6fa 100644 --- a/apps/mobile/src/native/SelectableMarkdownText.types.ts +++ b/apps/mobile/src/native/SelectableMarkdownText.types.ts @@ -94,6 +94,8 @@ export interface SelectableMarkdownTextProps { readonly checked: boolean; readonly text: string; }) => void; + /** Adds Cite to the text selection menu. `start` is an offset into this block's rendered text. */ + readonly onCite?: (selection: { readonly text: string; readonly start: number }) => void; readonly marginTop?: number; readonly marginBottom?: number; readonly writingDirection?: "ltr" | "rtl"; diff --git a/apps/mobile/src/native/T3ComposerEditor.ios.tsx b/apps/mobile/src/native/T3ComposerEditor.ios.tsx index 437bcda4d012d..3c563958f9f91 100644 --- a/apps/mobile/src/native/T3ComposerEditor.ios.tsx +++ b/apps/mobile/src/native/T3ComposerEditor.ios.tsx @@ -214,9 +214,11 @@ export function ComposerEditor({ ? (skillLabels.get(token.value) ?? token.value) : model ? model.label - : token.type === "context" - ? `${token.label}${props.context?.records.some((record) => record.contextId === token.contextId) ? "" : " · unavailable"}` - : basename(token.value), + : token.type === "citation" + ? token.value + : token.type === "context" + ? `${token.label}${props.context?.records.some((record) => record.contextId === token.contextId) ? "" : " · unavailable"}` + : basename(token.value), detail: token.type === "context" ? composerChipSizeSuffix(record) : "", iconUri: model ? modelChipIconUri(model) : contextChipIconUri(icon), tintsIcon: model ? modelChipIcon(model).tintsIcon : icon.kind === "chip", diff --git a/apps/mobile/src/native/T3ComposerEditor.native.tsx b/apps/mobile/src/native/T3ComposerEditor.native.tsx index 5aabd8e0d6071..4ecf0cbd6225e 100644 --- a/apps/mobile/src/native/T3ComposerEditor.native.tsx +++ b/apps/mobile/src/native/T3ComposerEditor.native.tsx @@ -215,9 +215,11 @@ export function ComposerEditor({ ? (skillLabels.get(token.value) ?? token.value) : model ? model.label - : token.type === "context" - ? `${token.label}${props.context?.records.some((record) => record.contextId === token.contextId) ? "" : " · unavailable"}` - : basename(token.value), + : token.type === "citation" + ? token.value + : token.type === "context" + ? `${token.label}${props.context?.records.some((record) => record.contextId === token.contextId) ? "" : " · unavailable"}` + : basename(token.value), detail: token.type === "context" ? composerChipSizeSuffix(record) : "", iconUri: model ? modelChipIconUri(model) : contextChipIconUri(icon), tintsIcon: model ? modelChipIcon(model).tintsIcon : icon.kind === "chip", From 2ed96e79b70ca1b7f98c8a8394af0a5d7e8c6e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:41:52 -0400 Subject: [PATCH 2/8] fix(mobile): reject Cite comments over the citation length limit Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/threads/citeAssistantText.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/mobile/src/features/threads/citeAssistantText.ts b/apps/mobile/src/features/threads/citeAssistantText.ts index 602a099bb9cb9..cca0020b958f5 100644 --- a/apps/mobile/src/features/threads/citeAssistantText.ts +++ b/apps/mobile/src/features/threads/citeAssistantText.ts @@ -1,4 +1,5 @@ import { + ASSISTANT_CITATION_MAX_COMMENT_LENGTH, ASSISTANT_CITATION_MAX_TEXT_LENGTH, type EnvironmentId, type MessageId, @@ -51,6 +52,10 @@ export function citeAssistantText( initialValue: "", confirmText: "Cite", onConfirm: (comment) => { + if (comment.trim().length > ASSISTANT_CITATION_MAX_COMMENT_LENGTH) { + Dialog.alert("Comment is too long", "Shorten the comment and cite again."); + return; + } const before = insertion.text.slice(0, insertion.start); const lead = before.length > 0 && !/\s$/.test(before) ? " " : ""; insertComposerDraftText( From e00f28dad99a4bdb078d776e31d9b9fcc7b3f834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 15:58:10 -0400 Subject: [PATCH 3/8] fix(mobile): Cite targets the open draft and keeps an oversized comment Co-Authored-By: Claude Opus 5.5 --- .../src/features/threads/citeAssistantText.ts | 51 +++++++++++-------- .../src/state/use-thread-composer-state.ts | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/apps/mobile/src/features/threads/citeAssistantText.ts b/apps/mobile/src/features/threads/citeAssistantText.ts index cca0020b958f5..f1cbaea8c27c1 100644 --- a/apps/mobile/src/features/threads/citeAssistantText.ts +++ b/apps/mobile/src/features/threads/citeAssistantText.ts @@ -11,11 +11,11 @@ import { } from "@t3tools/shared/assistantCitations"; import * as Dialog from "../../components/ui/Dialog"; -import { scopedThreadKey } from "../../lib/scopedEntities"; import { captureComposerDraftInsertion, insertComposerDraftText, } from "../../state/use-composer-drafts"; +import { activeComposerDraftKey } from "../../state/use-thread-composer-state"; export function citeAssistantText( source: { @@ -31,7 +31,10 @@ export function citeAssistantText( Dialog.alert("Selection is too long to cite", "Select a shorter passage and try again."); return; } - const draftKey = scopedThreadKey(source.environmentId, source.threadId); + const draftKey = activeComposerDraftKey({ + environmentId: source.environmentId, + id: source.threadId, + }); const insertion = captureComposerDraftInsertion(draftKey); const start = Math.max(0, selection.start); // Native offsets are per rendered block, not per message, and carry no surrounding context; @@ -45,24 +48,28 @@ export function citeAssistantText( prefix: "", suffix: "", }; - Dialog.prompt({ - title: "Cite", - message: "Add a comment about this quote (optional).", - placeholder: "Comment", - initialValue: "", - confirmText: "Cite", - onConfirm: (comment) => { - if (comment.trim().length > ASSISTANT_CITATION_MAX_COMMENT_LENGTH) { - Dialog.alert("Comment is too long", "Shorten the comment and cite again."); - return; - } - const before = insertion.text.slice(0, insertion.start); - const lead = before.length > 0 && !/\s$/.test(before) ? " " : ""; - insertComposerDraftText( - draftKey, - `${lead}${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `, - insertion, - ); - }, - }); + const askForComment = (initialValue: string) => + Dialog.prompt({ + title: "Cite", + message: "Add a comment about this quote (optional).", + placeholder: "Comment", + initialValue, + confirmText: "Cite", + onConfirm: (comment) => { + if (comment.trim().length > ASSISTANT_CITATION_MAX_COMMENT_LENGTH) { + Dialog.alert("Comment is too long", "Shorten the comment and try again.", [ + { text: "OK", onPress: () => askForComment(comment) }, + ]); + return; + } + const before = insertion.text.slice(0, insertion.start); + const lead = before.length > 0 && !/\s$/.test(before) ? " " : ""; + insertComposerDraftText( + draftKey, + `${lead}${serializeAssistantCitation(withAssistantCitationComment(citation, comment))} `, + insertion, + ); + }, + }); + askForComment(""); } diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 702aa53f90f0f..237b0ec5fc3e3 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -153,7 +153,7 @@ export function appendReviewCommentToDraft(input: { } /** Resolve per call so callbacks created before editing still target the current draft. */ -function activeComposerDraftKey(thread: { +export function activeComposerDraftKey(thread: { readonly environmentId: EnvironmentId; readonly id: ThreadId; }): string { From ead4962d447a10b822136cf77182c006d5120bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:05:57 -0400 Subject: [PATCH 4/8] fix(mobile): offer Cite only on assistant messages, as web does Co-Authored-By: Claude Fable 5.2 --- apps/mobile/src/features/threads/ThreadFeed.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx index 0d8b31f938c8f..48bb68c857262 100644 --- a/apps/mobile/src/features/threads/ThreadFeed.tsx +++ b/apps/mobile/src/features/threads/ThreadFeed.tsx @@ -2254,8 +2254,8 @@ function renderFeedEntry( Date: Wed, 11 Nov 2026 16:19:57 -0400 Subject: [PATCH 5/8] fix(mobile): keep Cite's draft lookup off the composer state module Importing use-thread-composer-state from the thread feed pulled native modules into filePreview.test.ts, which renders ThreadFeed. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/threads/citeAssistantText.ts | 11 ++++++----- apps/mobile/src/state/use-thread-composer-state.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/features/threads/citeAssistantText.ts b/apps/mobile/src/features/threads/citeAssistantText.ts index f1cbaea8c27c1..af82e4b0a0aa0 100644 --- a/apps/mobile/src/features/threads/citeAssistantText.ts +++ b/apps/mobile/src/features/threads/citeAssistantText.ts @@ -11,11 +11,12 @@ import { } from "@t3tools/shared/assistantCitations"; import * as Dialog from "../../components/ui/Dialog"; +import { scopedThreadKey } from "../../lib/scopedEntities"; import { captureComposerDraftInsertion, insertComposerDraftText, } from "../../state/use-composer-drafts"; -import { activeComposerDraftKey } from "../../state/use-thread-composer-state"; +import { getQueuedRunEdit, queuedEditDraftKey } from "../../state/queued-run-edit"; export function citeAssistantText( source: { @@ -31,10 +32,10 @@ export function citeAssistantText( Dialog.alert("Selection is too long to cite", "Select a shorter passage and try again."); return; } - const draftKey = activeComposerDraftKey({ - environmentId: source.environmentId, - id: source.threadId, - }); + // Same draft the composer shows: a queued message's edit draft while one is open. + const threadKey = scopedThreadKey(source.environmentId, source.threadId); + const edit = getQueuedRunEdit(threadKey); + const draftKey = edit === null ? threadKey : queuedEditDraftKey(threadKey, edit.runId); const insertion = captureComposerDraftInsertion(draftKey); const start = Math.max(0, selection.start); // Native offsets are per rendered block, not per message, and carry no surrounding context; diff --git a/apps/mobile/src/state/use-thread-composer-state.ts b/apps/mobile/src/state/use-thread-composer-state.ts index 237b0ec5fc3e3..702aa53f90f0f 100644 --- a/apps/mobile/src/state/use-thread-composer-state.ts +++ b/apps/mobile/src/state/use-thread-composer-state.ts @@ -153,7 +153,7 @@ export function appendReviewCommentToDraft(input: { } /** Resolve per call so callbacks created before editing still target the current draft. */ -export function activeComposerDraftKey(thread: { +function activeComposerDraftKey(thread: { readonly environmentId: EnvironmentId; readonly id: ThreadId; }): string { From 0a3f63959fbe37bba58f15eef46312c0dae53027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:30:21 -0400 Subject: [PATCH 6/8] fix(mobile): resolve Cite's target draft when the comment is confirmed Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/threads/citeAssistantText.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/mobile/src/features/threads/citeAssistantText.ts b/apps/mobile/src/features/threads/citeAssistantText.ts index af82e4b0a0aa0..418e6cc101ed4 100644 --- a/apps/mobile/src/features/threads/citeAssistantText.ts +++ b/apps/mobile/src/features/threads/citeAssistantText.ts @@ -32,11 +32,6 @@ export function citeAssistantText( Dialog.alert("Selection is too long to cite", "Select a shorter passage and try again."); return; } - // Same draft the composer shows: a queued message's edit draft while one is open. - const threadKey = scopedThreadKey(source.environmentId, source.threadId); - const edit = getQueuedRunEdit(threadKey); - const draftKey = edit === null ? threadKey : queuedEditDraftKey(threadKey, edit.runId); - const insertion = captureComposerDraftInsertion(draftKey); const start = Math.max(0, selection.start); // Native offsets are per rendered block, not per message, and carry no surrounding context; // web resolves the quote by its text when the offsets do not line up. @@ -63,6 +58,11 @@ export function citeAssistantText( ]); return; } + // Resolved on confirm: a queued edit can end while the prompt is open. + const threadKey = scopedThreadKey(source.environmentId, source.threadId); + const edit = getQueuedRunEdit(threadKey); + const draftKey = edit === null ? threadKey : queuedEditDraftKey(threadKey, edit.runId); + const insertion = captureComposerDraftInsertion(draftKey); const before = insertion.text.slice(0, insertion.start); const lead = before.length > 0 && !/\s$/.test(before) ? " " : ""; insertComposerDraftText( From 102c8baf12c7668bd4b3e00b58f98d065a82a56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:34:16 -0400 Subject: [PATCH 7/8] test(mobile): Cite lands in the thread draft when a queued edit ends mid-prompt Co-Authored-By: Claude Opus 5.5 --- .../threads/citeAssistantText.test.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 apps/mobile/src/features/threads/citeAssistantText.test.ts diff --git a/apps/mobile/src/features/threads/citeAssistantText.test.ts b/apps/mobile/src/features/threads/citeAssistantText.test.ts new file mode 100644 index 0000000000000..d6f286c0f2d3c --- /dev/null +++ b/apps/mobile/src/features/threads/citeAssistantText.test.ts @@ -0,0 +1,62 @@ +import { EnvironmentId, MessageId, RunId, ThreadId } from "@t3tools/contracts"; +import { collectAssistantCitations } from "@t3tools/shared/assistantCitations"; +import { Atom } from "effect/reactivity"; +import { describe, expect, it, vi } from "vite-plus/test"; + +import type { TextInputDialogRequest } from "../../components/ui/Dialog"; +import { appAtomRegistry } from "../../state/atom-registry"; +import { beginQueuedRunEdit, queuedEditDraftKey } from "../../state/queued-run-edit"; +import { getComposerDraftSnapshot } from "../../state/use-composer-drafts"; +import { citeAssistantText } from "./citeAssistantText"; + +const prompts: TextInputDialogRequest[] = []; +vi.mock("../../components/ui/Dialog", () => ({ + alert: vi.fn(), + prompt: (request: TextInputDialogRequest) => prompts.push(request), +})); + +vi.mock("expo-file-system", () => ({ + Directory: class { + create() {} + }, + File: class { + exists = false; + create() {} + write() {} + moveSync() {} + }, + Paths: { document: { uri: "file:///documents" } }, +})); + +describe("citeAssistantText", () => { + it("cites into the thread draft when the queued edit ends while the prompt is open", () => { + prompts.length = 0; + const environmentId = EnvironmentId.make("env-cite"); + const threadId = ThreadId.make("thread-cite"); + const threadKey = `${environmentId}:${threadId}`; + const runId = RunId.make("run-cite"); + const runs = Atom.make | null>([ + { id: runId, status: "queued" }, + ]); + beginQueuedRunEdit( + threadKey, + { runId, messageId: MessageId.make("queued"), originalText: "", existingAttachments: [] }, + runs, + ); + + citeAssistantText( + { environmentId, threadId, messageId: MessageId.make("reply") }, + { text: "complete", start: 0 }, + ); + appAtomRegistry.set(runs, [{ id: runId, status: "running" }]); + prompts[0]!.onConfirm("Why?"); + + expect(getComposerDraftSnapshot(queuedEditDraftKey(threadKey, runId)).text).toBe(""); + expect( + collectAssistantCitations(getComposerDraftSnapshot(threadKey).text).map(({ citation }) => [ + citation.text, + citation.comment, + ]), + ).toEqual([["complete", "Why?"]]); + }); +}); From 06c112c2edb95b3aaffcc49cd8013d1b3f02f531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20M=C3=A9ndez?= <103284630+Jose-Manuel18@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:46:47 -0400 Subject: [PATCH 8/8] chore: retrigger CI Co-Authored-By: Claude Opus 5.5