Skip to content

Commit f999dc1

Browse files
fix(web): preserve single tildes in sent user messages (pingdotgg#35859)
1 parent d20d535 commit f999dc1

5 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,25 @@ describe("MessagesTimeline messages", () => {
861861
expect((globalThis as { __t3Xss?: number }).__t3Xss).toBeUndefined();
862862
});
863863

864+
it("keeps single tildes in user paths literal without changing double tildes or assistant text", async () => {
865+
const source =
866+
"Install the skill as ~/folder-a/skills/x, then follow the guide (~/folder-a/guide.md).";
867+
await using screen = await renderTimeline([
868+
message(source),
869+
message("Drop ~~the old plan~~", {}, "message-2"),
870+
message(source, { role: "assistant" }, "assistant-1"),
871+
]);
872+
const [user, doubleTilde, assistant] = screen.container.querySelectorAll<HTMLElement>(
873+
"[data-timeline-row-kind=message]",
874+
);
875+
expect(user?.textContent).toContain(source);
876+
expect(user?.querySelector("del")).toBeNull();
877+
expect(doubleTilde?.querySelector("del")?.textContent).toBe("the old plan");
878+
expect(assistant?.querySelector("del")?.textContent).toBe(
879+
"/folder-a/skills/x, then follow the guide (",
880+
);
881+
});
882+
864883
it("renders sanitized raw HTML in assistant messages", async () => {
865884
await using screen = await renderTimeline([
866885
message(

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { InlineAudioPreview } from "../files/InlineAudioPreview";
22
import { filePreviewKind } from "@t3tools/shared/filePreview";
3-
import { remarkEnableOrderedListNumbers } from "@t3tools/shared/markdownPipeline";
3+
import {
4+
CHAT_USER_MARKDOWN_REMARK_PLUGINS,
5+
remarkEnableOrderedListNumbers,
6+
} from "@t3tools/shared/markdownPipeline";
47
import { findRevealRef } from "./markdownFindContext";
58
import {
69
type EnvironmentId,
@@ -1200,7 +1203,10 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
12001203
);
12011204
});
12021205

1203-
const USER_MESSAGE_REMARK_PLUGINS = [remarkEnableOrderedListNumbers];
1206+
const USER_MESSAGE_REMARK_PLUGINS = [
1207+
...CHAT_USER_MARKDOWN_REMARK_PLUGINS,
1208+
remarkEnableOrderedListNumbers,
1209+
];
12041210

12051211
const UserMessageBody = memo(function UserMessageBody(props: {
12061212
text: string;

‎packages/shared/src/markdownPipeline.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ export const CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS: PluggableList = [
274274
remarkNormalizeLinksAndTagInlineCode,
275275
];
276276

277+
// Users type paths like ~/a and (~/b, which GFM's single-tilde strikethrough hides as <del>.
278+
// Appended after the base list, this reconfigures its remark-gfm entry; ~~double~~ still strikes.
279+
export const CHAT_USER_MARKDOWN_REMARK_PLUGINS: PluggableList = [
280+
[remarkGfm, { singleTilde: false }],
281+
];
282+
277283
// Start tags an HTML parser closes an open `<p>` for.
278284
const CLOSES_PARAGRAPH = new Set(
279285
"address article aside blockquote center details dialog dir div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr li listing main menu nav ol p plaintext pre search section summary table ul xmp dd dt".split(

‎packages/shared/src/threadFindText.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ it("excludes review attachments rendered as context chips", () => {
2121
]);
2222
});
2323

24+
it("indexes single tildes in user paths as typed", () => {
25+
const text = "Install as ~/a/x, then read (~/a/guide.md).";
26+
expect(searchableMessageSegments({ role: "user", text, streaming: false })?.join("")).toBe(text);
27+
expect(
28+
searchableMessageSegments({ role: "user", text: "Drop ~~old~~", streaming: false })?.join(""),
29+
).toBe("Drop old");
30+
});
31+
2432
it("excludes structured context chips without joining text across them", () => {
2533
expect(
2634
searchableMessageSegments({

‎packages/shared/src/threadFindText.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
CHAT_MARKDOWN_REHYPE_PLUGINS,
3838
CHAT_MARKDOWN_REMARK_PLUGINS,
3939
CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS,
40+
CHAT_USER_MARKDOWN_REMARK_PLUGINS,
4041
} from "./markdownPipeline.ts";
4142

4243
// Inline wrappers (including Shiki token spans) must not split a search phrase.
@@ -94,6 +95,7 @@ const insightBreaksProcessor = assistantTextProcessor(true, true);
9495
const userProcessor = unified()
9596
.use(remarkParse)
9697
.use(CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS)
98+
.use(CHAT_USER_MARKDOWN_REMARK_PLUGINS)
9799
.use(remarkRehype, { allowDangerousHtml: true });
98100

99101
interface TextTree {

0 commit comments

Comments
 (0)