GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): file mentions of __init__.py keep their name as the labe… · pingdotgg/t3code@1cec104

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • ThreadSearch.test.ts
    • messageSearchIndex.ts
  • packages/shared/src
    • composerTrigger.test.ts
    • composerTrigger.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/ThreadSearch.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ThreadSearch.test.ts
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,21 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
860860
const project = ProjectId.make("project:heron");
861861
const labeled = ThreadId.make("thread:heron-label");
862862
const addressOnly = ThreadId.make("thread:heron-address");
863+
const mention = ThreadId.make("thread:heron-mention");
863864
yield* createProject(project);
864865
yield* Effect.forEach(
865866
[
866867
thread(labeled, project),
867868
message(labeled, "heron-label", "assistant", "See [the heron plan](https://x.dev/a) now"),
868869
thread(addressOnly, project),
869870
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+
),
870878
],
871879
projections.apply,
872880
{ discard: true },
@@ -876,6 +884,13 @@ it.layer(layerTest)("ThreadSearch filters before it ranks", (it) => {
876884
matches.map((match) => [match.threadId, match.snippet]),
877885
[[labeled, "See the heron plan now"]],
878886
);
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+
}
879894
}),
880895
);
881896

Collapse file

‎apps/server/src/orchestration-v2/messageSearchIndex.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/messageSearchIndex.ts
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,21 @@ const foldApostrophes = (text: string) => `replace(replace(${text}, '’', '''')
4848
const readableText = (row: string) =>
4949
`COALESCE(${row}.search_text, json_extract(${row}.payload_json, '$.text'))`;
5050

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+
5155
/**
5256
* What search_text holds for a message: its text as it reads, a quote's
5357
* percent-encoded link replaced by its words and comment. NULL when that is
5458
* the stored text, so most messages store nothing extra.
5559
*/
5660
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+
);
5866
return readable === text ? null : readable;
5967
};
6068

Collapse file

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

Copy file name to clipboardExpand all lines: packages/shared/src/composerTrigger.test.ts
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import remarkParse from "remark-parse";
2+
import { unified } from "unified";
13
import { describe, expect, it } from "vite-plus/test";
24

35
import {
@@ -6,6 +8,21 @@ import {
68
serializeComposerFileLink,
79
} from "./composerTrigger.ts";
810

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+
926
describe("detectComposerTrigger", () => {
1027
it.each([
1128
["Run /tmp/build.sh", "Run /tmp/build.sh".length],
@@ -91,6 +108,13 @@ describe("serializeComposerFileLink", () => {
91108
);
92109
});
93110

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+
94118
it("preserves paths that legitimately start with an at sign", () => {
95119
expect(serializeComposerFileLink("@scope/package.json")).toBe(
96120
"[package.json](@scope/package.json)",
Collapse file

‎packages/shared/src/composerTrigger.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/composerTrigger.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ function composerFileLinkBasename(path: string): string {
1818
return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path;
1919
}
2020

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.
2123
function escapeMarkdownLinkLabel(label: string): string {
22-
return label.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]");
24+
return label.replace(/[\\[\]*_]/g, "\\$&");
2325
}
2426

2527
function encodeMarkdownLinkDestination(path: string): string {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.