Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions apps/web/src/lib/composerContextRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
MessageId,
OrchestrationMessageContext,
ThreadId,
TurnItemId,
type PreviewAnnotationPayload,
} from "@t3tools/contracts";
import * as Schema from "effect/Schema";
Expand All @@ -24,6 +25,7 @@ import {
previewAnnotationFromRecord,
pullRequestContextKindLabel,
resolveUserMessageContext,
responseContextRecord,
reviewCommentContextLabel,
selectedMessageContextFragment,
reviewCommentContextRecord,
Expand Down Expand Up @@ -227,6 +229,26 @@ describe("composerContextRecords", () => {
expect(record.label).toBe(`${"a".repeat(46)}…`);
});

it("shortens a long reply label without splitting an emoji", () => {
const text = `${"a".repeat(63)}😀 trailing`;
const record = responseContextRecord({
citation: {
version: 1,
environmentId: EnvironmentId.make("environment-1"),
threadId: ThreadId.make("thread-1"),
messageId: MessageId.make("message-1"),
text,
start: 0,
end: text.length,
prefix: "",
suffix: "",
},
itemId: TurnItemId.make("item-1"),
subagents: [],
});
expect(record.label).toBe("a".repeat(63));
});

it("restores multiple edits on one target without parsing display strings", () => {
const styleChanges = [
...annotation.styleChanges,
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/lib/composerContextRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
import type { ReviewCommentContext } from "~/reviewCommentContext";

const PREVIEW_LABEL_MAX_CHARS = 48;
const RESPONSE_LABEL_MAX_CHARS = 64;

// Truncate selections to wire bounds before persistence to avoid send-time encoding failures.
const TRUNCATION_MARKER = "\n… truncated …";
Expand Down Expand Up @@ -178,6 +179,13 @@ export function responseContextReference(record: ResponseContextRecord): Compose
return { kind: "response", contextId: record.contextId, label: record.label };
}

function responseContextLabel(text: string): string {
const last = text.charCodeAt(RESPONSE_LABEL_MAX_CHARS - 1);
const end =
last >= 0xd800 && last <= 0xdbff ? RESPONSE_LABEL_MAX_CHARS - 1 : RESPONSE_LABEL_MAX_CHARS;
return sanitizeComposerContextLabel(text.slice(0, end), "response");
}

/** One record per response, so replying to it again reuses the same reference. */
export function responseContextRecord(
input: Pick<ResponseContextRecord, "citation" | "itemId"> & {
Expand All @@ -192,7 +200,7 @@ export function responseContextRecord(
version: 1,
kind: "response",
contextId: toKindScopedComposerContextId("response", input.citation.messageId),
label: sanitizeComposerContextLabel(input.citation.text.slice(0, 64), "response"),
label: responseContextLabel(input.citation.text),
citation: input.citation,
itemId: input.itemId,
...(input.subagents.length > 0
Expand Down
Loading