feat(composer): fold large pastes into text attachments (#11442)

This commit is contained in:
Chris Deeming authored and GitHub committed 2026-09-12 17:28:28 -07:00
1 parent 36caf200c2
commit 68c2277f50
77 files changed
+3278 -465

No files matched your search

@@ -582,6 +582,22 @@ describe("upgradeLegacyContextMessage", () => {
]);
});
it("keeps adjacent trailing reviews in place, including their original spacing", () => {
const upgraded = upgradeLegacyContextMessage(`Compare ${review} ${review}`);
expect(upgraded.text).toBe(
"Compare [f.ts line](t3-context://v1/review-comment/legacy_review-comment_1) [f.ts line](t3-context://v1/review-comment/legacy_review-comment_2)",
);
});
it("keeps a trailing review beside a terminal chip whose payload follows it", () => {
const upgraded = upgradeLegacyContextMessage(
`@build:7 ${review}\n\n<terminal_context>\n- Build line 7:\n output\n</terminal_context>`,
);
expect(upgraded.text).toBe(
"[Build line 7](t3-context://v1/terminal/legacy_terminal_1) [f.ts line](t3-context://v1/review-comment/legacy_review-comment_1)",
);
});
it("handles the combined legacy send order: terminal, element, preview, review", () => {
const text = [
"See ",
+13 -6
View File
@@ -339,15 +339,22 @@ export function upgradeLegacyContextMessage(text: string): UpgradedLegacyContext
// Blocks were appended in send order (terminal, element, preview, review), so they peel
// off the end in reverse. Each peel exposes the next block as trailing.
// Only reviews that trailed the original text were appended by the old send path; a
// review that sat before other blocks keeps its place.
// Peel reviews only when they hide another trailing context block. A review at the end
// of ordinary prose can still be inline; keep its original spacing and line breaks.
const trailingReviewTokens: number[] = [];
const tokens = trailingReviewTokenPattern.exec(rest);
if (tokens && tokens[0].length > 0) {
trailingReviewTokens.push(
...Array.from(tokens[0].matchAll(reviewTokenPattern), (m) => Number(m[1])),
);
rest = rest.slice(0, tokens.index).replace(/\n+$/, "");
const preceding = rest.slice(0, tokens.index);
if (
TRAILING_PREVIEW.test(preceding) ||
TRAILING_ELEMENT.test(preceding) ||
TRAILING_TERMINAL.test(preceding)
) {
trailingReviewTokens.push(
...Array.from(tokens[0].matchAll(reviewTokenPattern), (m) => Number(m[1])),
);
rest = preceding;
}
}
for (;;) {
const preview = stripTrailing(rest, TRAILING_PREVIEW);
@@ -99,6 +99,31 @@ describe("serializeLegacyContextMessage", () => {
});
});
it.each([" ", "\n", "\n\n"])(
"preserves the separator between a skill and a trailing PR through an older server: %j",
(separator) => {
const pullRequest = {
...review,
label: "#11440",
sectionId: "pull-request:11440",
sectionTitle: "Pull request",
filePath: "PR #11440",
rangeLabel: "summary",
text: "Audit Mobile Photo Import",
diff: "",
};
const text = `$pr-audit${separator}${formatComposerContextReference(pullRequest)}`;
const upgraded = upgradeLegacyContextMessage(
serializeLegacyContextMessage({ text, records: [pullRequest] }),
);
expect(upgraded.records).toHaveLength(1);
expect(upgraded.text).toBe(
`$pr-audit${separator}${formatComposerContextReference(upgraded.records[0]!)}`,
);
},
);
it("retains picked-element details for preview annotations sent through an older server", () => {
const text = `Update ${formatComposerContextReference(annotation)}`;
const upgraded = upgradeLegacyContextMessage(