Skip to content

Commit 1a610ee

Browse files
committed
fix(composer): preserve mention handling after main merge
1 parent 655b71c commit 1a610ee

6 files changed

Lines changed: 64 additions & 16 deletions

File tree

‎apps/server/src/mention/MentionIndex.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ it.effect("loadScope retains a newer published scope over a concurrent stale dis
128128
const store = KeyValueStore.makeStringOnly({
129129
get: (key) =>
130130
Effect.gen(function* () {
131+
const valueAtReadStart = disk.get(key);
131132
if (gateScopeReads && key === `scope:${scopeKey}`) {
132133
yield* Deferred.succeed(readStarted, undefined);
133134
yield* Deferred.await(allowRead);
134135
}
135-
return disk.get(key);
136+
return valueAtReadStart;
136137
}),
137138
set: (key, value) =>
138139
Effect.sync(() => {

‎apps/web/src/components/chat/CollapsedComposerPromptPreview.tsx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
55
import { fileBasename } from "@t3tools/shared/path";
66
import {
77
CircleDashedIcon,
8+
CircleDotIcon,
9+
LinkIcon,
10+
PaintbrushIcon,
811
ImageIcon,
912
MessageCircleIcon,
1013
MessagesSquareIcon,
@@ -25,6 +28,7 @@ import { ContextChip, ContextChipLabel } from "../ContextChip";
2528
import { ContextChipShell } from "../contextChipParts";
2629
import { PierreEntryIcon } from "./PierreEntryIcon";
2730
import { SkillChipIcon } from "./SkillInlineText";
31+
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
2832

2933
type Theme = "light" | "dark";
3034

@@ -40,6 +44,10 @@ const CONTEXT_REFERENCE_ICONS: Record<
4044
"review-comment": () => <MessageCircleIcon />,
4145
thread: () => <MessagesSquareIcon />,
4246
environment: () => <MonitorIcon />,
47+
"pull-request": () => <PullRequestGlyph.pullRequest />,
48+
jira: () => <LinkIcon />,
49+
figma: () => <PaintbrushIcon />,
50+
issue: () => <CircleDotIcon />,
4351
};
4452

4553
// Mirrors the editor's chip: only a draft record of the same kind resolves a reference.
@@ -97,7 +105,11 @@ export function CollapsedComposerPromptPreview(props: {
97105
return entry ? (
98106
<ContextChipShell
99107
key={key}
100-
kind={entry.kind}
108+
kind={
109+
entry.kind === "jira" || entry.kind === "figma" || entry.kind === "issue"
110+
? "file"
111+
: entry.kind
112+
}
101113
icon={CONTEXT_REFERENCE_ICONS[entry.kind](segment.label, props.theme)}
102114
label={segment.label}
103115
/>

‎apps/web/src/components/chat/useComposerContextImport.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ export function useComposerContextImport(input: {
312312
// re-minted under a fresh id so both survive the paste.
313313
const record = asKnownContextRecord(candidate);
314314
if (!record) continue;
315+
if (
316+
questionAttachmentTarget !== null &&
317+
(record.kind === "pull-request" ||
318+
record.kind === "jira" ||
319+
record.kind === "figma" ||
320+
record.kind === "issue")
321+
)
322+
continue;
315323
// A reminted annotation needs its screenshot under the new annotation id.
316324
const existing = dependentAttachmentLocalIds.has(record.contextId)
317325
? undefined

‎apps/web/src/components/composerInlineTokenPaste.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ describe("importPastedComposerText", () => {
5656
);
5757
expect(text).toBe(pasted);
5858
expect(imported.map((fragment) => fragment.records)).toEqual([[record]]);
59+
const rejected = importPastedComposerText(
60+
clipboard({
61+
"text/plain": pasted,
62+
[COMPOSER_CONTEXT_CLIPBOARD_MIME]: encodeComposerContextFragment({
63+
version: 1,
64+
source: { environmentId: thread.environmentId },
65+
records: [record],
66+
})!,
67+
}),
68+
() => new Map(),
69+
{ rewriteExternalLinks: true },
70+
);
71+
expect(rejected).toBe(record.url);
5972
});
6073
it("pastes a copied thread link back as the chip it was copied from", () => {
6174
const target = threadChipCopyTarget(thread, "Fix the login flow");

‎apps/web/src/components/composerInlineTokenPaste.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export function importPastedComposerText(
9898
const fragment = importContextFragment ? readPastedComposerContext(clipboardData, options) : null;
9999
const rewrittenIds =
100100
fragment && fragment.records.length > 0 ? importContextFragment!(fragment) : null;
101-
if (!rewrittenIds || rewrittenIds.size === 0) return pastedText;
101+
if (!fragment) return pastedText;
102102
const nextId = (contextId: string) => {
103-
const id = rewrittenIds.get(contextId);
103+
const id = rewrittenIds?.get(contextId);
104104
return id ? ComposerContextId.make(id) : undefined;
105105
};
106106
const text = replaceComposerContextReferences(pastedText, (occurrence) => {
@@ -111,7 +111,19 @@ export function importPastedComposerText(
111111
contextId,
112112
kind: occurrence.kind === "element" ? "preview-annotation" : occurrence.kind,
113113
})
114-
: occurrence.source;
114+
: (() => {
115+
const record = fragment.records.find(
116+
(record) => record.contextId === occurrence.contextId,
117+
);
118+
return record &&
119+
"url" in record &&
120+
(record.kind === "pull-request" ||
121+
record.kind === "jira" ||
122+
record.kind === "figma" ||
123+
record.kind === "issue")
124+
? record.url
125+
: occurrence.source;
126+
})();
115127
});
116128
// A thread the import refused, on a machine this agent cannot read, stays the link it was.
117129
const withThreads = threadLinkContextReferences(

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -568,17 +568,19 @@ export function projectComposerContextForProvider(input: {
568568
if (occurrence.url !== undefined) return recordsByUrl.get(occurrence.url.trim());
569569
return undefined;
570570
};
571-
const body = expandAssistantCitationsForProvider(replaceComposerContextReferences(input.text, (occurrence) => {
572-
const record = lookupRecord(occurrence);
573-
// Draft already stores a real URL, or the record can supply one — keep/re-emit the link.
574-
if (occurrence.url !== undefined) return occurrence.source;
575-
return formatComposerContextProviderMarker(
576-
record?.kind ?? occurrence.kind,
577-
occurrence.label,
578-
occurrence.contextId,
579-
record,
580-
);
581-
}));
571+
const body = expandAssistantCitationsForProvider(
572+
replaceComposerContextReferences(input.text, (occurrence) => {
573+
const record = lookupRecord(occurrence);
574+
// Draft already stores a real URL, or the record can supply one — keep/re-emit the link.
575+
if (occurrence.url !== undefined) return occurrence.source;
576+
return formatComposerContextProviderMarker(
577+
record?.kind ?? occurrence.kind,
578+
occurrence.label,
579+
occurrence.contextId,
580+
record,
581+
);
582+
}),
583+
);
582584
const seen = new Set<ComposerContextId>();
583585
const entries: string[] = [];
584586
for (const occurrence of occurrences) {

0 commit comments

Comments
 (0)