GeezerVison is showing github.com — fix(shared): file mentions of __init__.py keep their name as the labe… · pingdotgg/t3code@1cec104
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadSearch.test.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -860,13 +860,21 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => { | 860 | 860 | const project = ProjectId.make("project:heron"); | 861 | 861 | const labeled = ThreadId.make("thread:heron-label"); | 862 | 862 | const addressOnly = ThreadId.make("thread:heron-address"); | | 863 | + const mention = ThreadId.make("thread:heron-mention"); | 863 | 864 | yield* createProject(project); | 864 | 865 | yield* Effect.forEach( | 865 | 866 | [ | 866 | 867 | thread(labeled, project), | 867 | 868 | message(labeled, "heron-label", "assistant", "See [the heron plan](https://x.dev/a) now"), | 868 | 869 | thread(addressOnly, project), | 869 | 870 | message(addressOnly, "heron-address", "user", "Read [this](https://heron.dev/b)"), | | 871 | + thread(mention, project), | | 872 | + message( | | 873 | + mention, | | 874 | + "heron-mention", | | 875 | + "user", | | 876 | + String.raw`Fix [\_\_init\_\_.py](pkg/__init__.py) and [\_café\_.py](pkg/_caf%C3%A9_.py)`, | | 877 | + ), | 870 | 878 | ], | 871 | 879 | projections.apply, | 872 | 880 | { discard: true }, | @@ -876,6 +884,13 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => { | 876 | 884 | matches.map((match) => [match.threadId, match.snippet]), | 877 | 885 | [[labeled, "See the heron plan now"]], | 878 | 886 | ); | | 887 | + for (const query of ["__init__.py", "_café_.py"]) { | | 888 | + const mentions = yield* search.search({ query }); | | 889 | + assert.deepEqual( | | 890 | + mentions.matches.map((match) => [match.threadId, match.snippet]), | | 891 | + [[mention, "Fix __init__.py and _café_.py"]], | | 892 | + ); | | 893 | + } | 879 | 894 | }), | 880 | 895 | ); | 881 | 896 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/messageSearchIndex.ts +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,13 +48,21 @@ const foldApostrophes = (text: string) => `replace(replace(${text}, '’', '''') | 48 | 48 | const readableText = (row: string) => | 49 | 49 | `COALESCE(${row}.search_text, json_extract(${row}.payload_json, '$.text'))`; | 50 | 50 |
| | 51 | +// A file mention stores `__init__.py` as `[\_\_init\_\_.py](...)`; the index | | 52 | +// holds the label as it reads, so search can find the name as typed. | | 53 | +const LINK_LABEL = /(!?\[)([^\]\n]*)(\]\([^)\s]*\))/g; | | 54 | + | 51 | 55 | /** | 52 | 56 | * What search_text holds for a message: its text as it reads, a quote's | 53 | 57 | * percent-encoded link replaced by its words and comment. NULL when that is | 54 | 58 | * the stored text, so most messages store nothing extra. | 55 | 59 | */ | 56 | 60 | export const readableSearchText = (text: string) => { | 57 | | - const readable = assistantCitationsToPlainText(text); | | 61 | + const readable = assistantCitationsToPlainText(text).replace( | | 62 | + LINK_LABEL, | | 63 | + (_link, open: string, label: string, close: string) => | | 64 | + open + label.replace(/\\([*_])/g, "$1") + close, | | 65 | + ); | 58 | 66 | return readable === text ? null : readable; | 59 | 67 | }; | 60 | 68 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/composerTrigger.test.ts +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import remarkParse from "remark-parse"; | | 2 | +import { unified } from "unified"; | 1 | 3 | import { describe, expect, it } from "vite-plus/test"; | 2 | 4 |
| 3 | 5 | import { | @@ -6,6 +8,21 @@ import { | 6 | 8 | serializeComposerFileLink, | 7 | 9 | } from "./composerTrigger.ts"; | 8 | 10 |
| | 11 | +interface MarkdownNode { | | 12 | + readonly type: string; | | 13 | + readonly value?: string; | | 14 | + readonly children?: ReadonlyArray<MarkdownNode>; | | 15 | +} | | 16 | + | | 17 | +function parsedLinkLabel(markdown: string): string | undefined { | | 18 | + const textOf = (node: MarkdownNode): string => | | 19 | + node.value ?? (node.children ?? []).map(textOf).join(""); | | 20 | + const find = (node: MarkdownNode): MarkdownNode | undefined => | | 21 | + node.type === "link" ? node : node.children?.map(find).find(Boolean); | | 22 | + const link = find(unified().use(remarkParse).parse(markdown) as MarkdownNode); | | 23 | + return link && textOf(link); | | 24 | +} | | 25 | + | 9 | 26 | describe("detectComposerTrigger", () => { | 10 | 27 | it.each([ | 11 | 28 | ["Run /tmp/build.sh", "Run /tmp/build.sh".length], | @@ -91,6 +108,13 @@ describe("serializeComposerFileLink", () => { | 91 | 108 | ); | 92 | 109 | }); | 93 | 110 |
| | 111 | + it.each([ | | 112 | + ["pkg/__init__.py", "__init__.py"], | | 113 | + ["notes/*draft*.md", "*draft*.md"], | | 114 | + ])("renders the mention of %j with its file name as the label", (path, basename) => { | | 115 | + expect(parsedLinkLabel(serializeComposerFileLink(path))).toBe(basename); | | 116 | + }); | | 117 | + | 94 | 118 | it("preserves paths that legitimately start with an at sign", () => { | 95 | 119 | expect(serializeComposerFileLink("@scope/package.json")).toBe( | 96 | 120 | "[package.json](@scope/package.json)", | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/composerTrigger.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,8 +18,10 @@ function composerFileLinkBasename(path: string): string { | 18 | 18 | return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path; | 19 | 19 | } | 20 | 20 |
| | 21 | +// Emphasis markers too: `__init__.py` would otherwise render as bold "init.py", | | 22 | +// which no longer matches the path, so the label shows beside the chip. | 21 | 23 | function escapeMarkdownLinkLabel(label: string): string { | 22 | | - return label.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]"); | | 24 | + return label.replace(/[\\[\]*_]/g, "\\$&"); | 23 | 25 | } | 24 | 26 |
| 25 | 27 | function encodeMarkdownLinkDestination(path: string): string { | |
|