Skip to content

Commit 4fff22f

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/845-supervisor-host-gate
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com> # Conflicts: # tests/test_mcp.c
2 parents fbd7287 + 54efcef commit 4fff22f

35 files changed

Lines changed: 2437 additions & 98 deletions

‎Makefile.cbm‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ TEST_REPRO_SRCS = \
462462
tests/repro/repro_new_cypher_limit_zero.c \
463463
tests/repro/repro_issue363.c \
464464
tests/repro/repro_issue581.c \
465+
tests/repro/repro_issue787.c \
465466
tests/repro/repro_invariant_calls.c \
466467
tests/repro/repro_invariant_graph.c \
467468
tests/repro/repro_invariant_breadth.c \
@@ -482,6 +483,7 @@ TEST_REPRO_SRCS = \
482483
tests/repro/repro_lsp_c_cpp.c \
483484
tests/repro/repro_lsp_go_py.c \
484485
tests/repro/repro_lsp_ts.c \
486+
tests/repro/repro_ts_inherited_method.c \
485487
tests/repro/repro_lsp_java_cs.c \
486488
tests/repro/repro_lsp_kt_php_rust.c
487489

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ codebase-memory-mcp config set auto_index true
122122

123123
When enabled, new projects are indexed automatically on first connection. Previously-indexed projects are registered with the background watcher for ongoing git-based change detection. Configurable file limit: `config set auto_index_limit 50000`.
124124

125+
Watcher registration is controlled separately by `auto_watch` (default `true`). Set `config set auto_watch false` to keep a session from registering its project with the background watcher — useful when working across many projects and you want each session contained to explicit indexing.
126+
125127
### Keeping Up to Date
126128

127129
```bash
@@ -466,6 +468,7 @@ See [docs/cbmignore.md](docs/cbmignore.md) for the full `.cbmignore` how-to: syn
466468
codebase-memory-mcp config list # show all settings
467469
codebase-memory-mcp config set auto_index true # auto-index on session start
468470
codebase-memory-mcp config set auto_index_limit 50000 # max files for auto-index
471+
codebase-memory-mcp config set auto_watch false # don't register background git watcher (default: true)
469472
codebase-memory-mcp config reset auto_index # reset to default
470473
```
471474

‎graph-ui/src/components/StatsTab.test.tsx‎

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @vitest-environment jsdom */
22
import "@testing-library/jest-dom/vitest";
3-
import { fireEvent, render, screen, waitFor, act } from "@testing-library/react";
3+
import { cleanup, fireEvent, render, screen, waitFor, act } from "@testing-library/react";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import { StatsTab, IndexProgress } from "./StatsTab";
66
import { messages } from "../lib/i18n";
@@ -43,6 +43,7 @@ function mockProjectsFetch(extra?: (url: string, init?: RequestInit) => Response
4343

4444
describe("StatsTab index modal", () => {
4545
afterEach(() => {
46+
cleanup();
4647
vi.unstubAllGlobals();
4748
});
4849

@@ -65,7 +66,7 @@ describe("StatsTab index modal", () => {
6566
fireEvent.change(await screen.findByLabelText("Repository path"), {
6667
target: { value: "D:\\work\\信租风控通后端" },
6768
});
68-
fireEvent.change(screen.getByLabelText("Project name"), {
69+
fireEvent.change(screen.getByLabelText("Project ID (optional — permanent, cannot be renamed)"), {
6970
target: { value: "信租风控通后端" },
7071
});
7172
fireEvent.click(screen.getByRole("button", { name: "Index This Folder" }));
@@ -93,6 +94,119 @@ describe("StatsTab index modal", () => {
9394
expect(screen.getByRole("button", { name: "Index beta" })).toBeInTheDocument();
9495
expect(screen.getByRole("button", { name: "Browse D:/" })).toBeInTheDocument();
9596
});
97+
98+
it("navigates Windows breadcrumb segments to real drive paths", async () => {
99+
const fetchMock = mockProjectsFetch((url) => {
100+
if (url.startsWith("/api/browse")) {
101+
return new Response(JSON.stringify({
102+
path: "C:/Users/rap",
103+
parent: "C:/Users",
104+
dirs: ["Documents", "Downloads"],
105+
roots: ["C:/", "D:/"],
106+
}), { status: 200, headers: { "Content-Type": "application/json" } });
107+
}
108+
return undefined;
109+
});
110+
111+
render(<StatsTab onSelectProject={() => {}} />);
112+
fireEvent.click(await screen.findByRole("button", { name: "Index your first repository" }));
113+
114+
/* No bogus unified "/" root crumb on a Windows drive path. */
115+
await screen.findByRole("button", { name: "C:" });
116+
expect(screen.queryByRole("button", { name: "/" })).not.toBeInTheDocument();
117+
118+
/* Clicking the drive crumb browses to "C:/", not "/C:". */
119+
fireEvent.click(screen.getByRole("button", { name: "C:" }));
120+
await waitFor(() => {
121+
expect(fetchMock).toHaveBeenCalledWith("/api/browse?path=C%3A%2F");
122+
});
123+
124+
/* Clicking a nested crumb browses to "C:/Users", not "/C:/Users". */
125+
fireEvent.click(screen.getByRole("button", { name: "Users" }));
126+
await waitFor(() => {
127+
expect(fetchMock).toHaveBeenCalledWith("/api/browse?path=C%3A%2FUsers");
128+
});
129+
});
130+
131+
it("refreshes the folder list when a drive is typed into the path field", async () => {
132+
mockProjectsFetch((url) => {
133+
if (url.startsWith("/api/browse")) {
134+
const m = /[?&]path=([^&]*)/.exec(url);
135+
const path = m ? decodeURIComponent(m[1]) : "C:/Users/rap";
136+
const onD = path.replace(/\\/g, "/").toUpperCase().startsWith("D:");
137+
return new Response(JSON.stringify({
138+
path,
139+
parent: "C:/",
140+
dirs: onD ? ["projects", "games"] : ["Documents", "Downloads"],
141+
roots: ["C:/", "D:/"],
142+
}), { status: 200, headers: { "Content-Type": "application/json" } });
143+
}
144+
return undefined;
145+
});
146+
147+
render(<StatsTab onSelectProject={() => {}} />);
148+
fireEvent.click(await screen.findByRole("button", { name: "Index your first repository" }));
149+
150+
/* Initial C: listing is shown. */
151+
expect(await screen.findByText("Documents")).toBeInTheDocument();
152+
153+
/* Typing a different drive refreshes the listing to that drive (debounced). */
154+
fireEvent.change(await screen.findByLabelText("Repository path"), {
155+
target: { value: "D:/" },
156+
});
157+
158+
expect(await screen.findByText("projects")).toBeInTheDocument();
159+
expect(screen.queryByText("Documents")).not.toBeInTheDocument();
160+
});
161+
162+
it("replaces the meaningless '/' root with the drive on Windows", async () => {
163+
const fetchMock = mockProjectsFetch((url) => {
164+
if (url.startsWith("/api/browse")) {
165+
const m = /[?&]path=([^&]*)/.exec(url);
166+
const path = m ? decodeURIComponent(m[1]) : "C:/Users/rap";
167+
return new Response(JSON.stringify({
168+
path,
169+
parent: "C:/",
170+
dirs: ["Documents"],
171+
roots: ["/"], // older backend: no drive enumeration
172+
}), { status: 200, headers: { "Content-Type": "application/json" } });
173+
}
174+
return undefined;
175+
});
176+
177+
render(<StatsTab onSelectProject={() => {}} />);
178+
fireEvent.click(await screen.findByRole("button", { name: "Index your first repository" }));
179+
180+
/* The bogus "/" quick-jump is gone; the current drive root is offered. */
181+
expect(await screen.findByRole("button", { name: "Browse C:/" })).toBeInTheDocument();
182+
expect(screen.queryByRole("button", { name: "Browse /" })).not.toBeInTheDocument();
183+
184+
/* Clicking it browses to the drive root, not "/". */
185+
fireEvent.click(screen.getByRole("button", { name: "Browse C:/" }));
186+
await waitFor(() => {
187+
expect(fetchMock).toHaveBeenCalledWith("/api/browse?path=C%3A%2F");
188+
});
189+
});
190+
191+
it("does not auto-refresh on POSIX when a path is typed", async () => {
192+
const fetchMock = mockProjectsFetch(); // browse returns POSIX path "/home/dev"
193+
194+
render(<StatsTab onSelectProject={() => {}} />);
195+
fireEvent.click(await screen.findByRole("button", { name: "Index your first repository" }));
196+
await screen.findByText("alpha"); // initial POSIX listing
197+
198+
const browseCalls = () =>
199+
fetchMock.mock.calls.filter((c) => String(c[0]).startsWith("/api/browse")).length;
200+
const before = browseCalls();
201+
202+
fireEvent.change(screen.getByLabelText("Repository path"), {
203+
target: { value: "/usr/local" },
204+
});
205+
206+
/* Wait past the debounce window; a POSIX path must NOT trigger a re-browse. */
207+
await new Promise((r) => setTimeout(r, 400));
208+
expect(browseCalls()).toBe(before);
209+
});
96210
});
97211

98212
describe("IndexProgress", () => {

‎graph-ui/src/components/StatsTab.tsx‎

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,47 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
179179
const [submitting, setSubmitting] = useState(false);
180180
const [error, setError] = useState<string | null>(null);
181181
const filterRef = useRef<HTMLInputElement>(null);
182+
/* Path whose listing is currently shown. Lets the typed-path effect skip a
183+
* redundant re-fetch after browse() sets currentPath itself. */
184+
const lastBrowsedRef = useRef<string>("");
182185

183-
const browse = useCallback(async (path?: string) => {
184-
setLoading(true);
186+
const browse = useCallback(async (path?: string, opts?: { silent?: boolean }) => {
187+
const silent = opts?.silent ?? false;
188+
if (!silent) setLoading(true);
185189
setError(null);
186190
try {
187191
const q = path ? `?path=${encodeURIComponent(path)}` : "";
188192
const res = await fetch(`/api/browse${q}`);
189193
const data = await res.json();
190194
if (data.error) throw new Error(data.error);
195+
lastBrowsedRef.current = data.path ?? "";
191196
setCurrentPath(data.path ?? "");
192197
setDirs((data.dirs ?? []).sort());
193198
setRoots(data.roots ?? ["/"]);
194199
setParentPath(data.parent ?? "/");
195-
} catch (e) { setError(e instanceof Error ? e.message : "Browse failed"); }
196-
finally { setLoading(false); }
200+
} catch (e) {
201+
/* Silent (typed-path) refreshes keep the last good listing instead of
202+
* flashing an error while the user is still typing a path. */
203+
if (!silent) setError(e instanceof Error ? e.message : "Browse failed");
204+
}
205+
finally { if (!silent) setLoading(false); }
197206
}, []);
198207

199208
useEffect(() => { browse(); }, [browse]);
200209
useEffect(() => { filterRef.current?.focus(); }, []);
201210

211+
/* Windows only: when the user types a drive path into the Repository path
212+
* field, refresh the folder listing to match (debounced). On Windows, typing
213+
* is the way to switch drives, and without this the breadcrumb and path box
214+
* updated but the directory list stayed stale (e.g. typing "D:/" still showed
215+
* the previous drive's folders). POSIX navigation is left unchanged. */
216+
useEffect(() => {
217+
if (!currentPath || currentPath === lastBrowsedRef.current) return;
218+
if (!/^[A-Za-z]:/.test(currentPath.replace(/\\/g, "/"))) return;
219+
const id = setTimeout(() => { void browse(currentPath, { silent: true }); }, 350);
220+
return () => clearTimeout(id);
221+
}, [currentPath, browse]);
222+
202223
const filteredDirs = useMemo(() => {
203224
const q = filter.trim().toLowerCase();
204225
if (!q) return dirs;
@@ -239,6 +260,30 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
239260
/* Breadcrumb segments */
240261
const displayPath = currentPath.replace(/\\/g, "/");
241262
const segments = displayPath.split("/").filter(Boolean);
263+
/* A Windows drive path ("C:/Users/rap") has no unified "/" root — its first
264+
* segment is the drive letter. Build crumb targets accordingly so clicking a
265+
* segment navigates to a real directory instead of a bogus "/C:/..." path
266+
* that the backend rejects as "not a directory". */
267+
const isWinPath = /^[A-Za-z]:$/.test(segments[0] ?? "");
268+
const crumbPath = (i: number): string => {
269+
const parts = segments.slice(0, i + 1);
270+
if (isWinPath) return parts.length === 1 ? `${parts[0]}/` : parts.join("/");
271+
return "/" + parts.join("/");
272+
};
273+
274+
/* Root/drive quick-jump buttons. On Windows the POSIX "/" root is meaningless
275+
* — browsing it returns an empty listing — so drop it and offer drive roots
276+
* instead. An older backend may not enumerate drives, so always include the
277+
* current drive; other drives stay reachable by typing a path. */
278+
const displayRoots = (() => {
279+
if (!isWinPath) return roots;
280+
const drives = Array.from(new Set(
281+
roots.filter((r) => /^[A-Za-z]:[\\/]?$/.test(r)).map((r) => `${r[0].toUpperCase()}:/`),
282+
));
283+
const curRoot = `${displayPath[0].toUpperCase()}:/`;
284+
if (!drives.includes(curRoot)) drives.unshift(curRoot);
285+
return drives;
286+
})();
242287

243288
return (
244289
<div className="fixed inset-0 z-50 flex items-center justify-center" onClick={onClose}>
@@ -257,6 +302,7 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
257302
aria-label={t.index.repositoryPath}
258303
value={currentPath}
259304
onChange={(e) => setCurrentPath(e.target.value)}
305+
onKeyDown={(e) => { if (e.key === "Enter" && /^[A-Za-z]:/.test(currentPath.replace(/\\/g, "/"))) { e.preventDefault(); void browse(currentPath); } }}
260306
className="w-full bg-white/[0.04] border border-white/[0.06] rounded-lg px-3 py-2 text-[12px] text-foreground font-mono outline-none focus:border-primary/40"
261307
/>
262308
</label>
@@ -269,6 +315,7 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
269315
onChange={(e) => setProjectName(e.target.value)}
270316
className="w-full bg-white/[0.04] border border-white/[0.06] rounded-lg px-3 py-2 text-[12px] text-foreground outline-none focus:border-primary/40 placeholder:text-foreground/20"
271317
/>
318+
<span className="block text-[10px] text-foreground/25 mt-1">{t.index.projectNameHelp}</span>
272319
</label>
273320
</div>
274321

@@ -282,7 +329,7 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
282329
className="flex-1 bg-white/[0.04] border border-white/[0.06] rounded-lg px-3 py-2 text-[12px] text-foreground outline-none focus:border-primary/40 placeholder:text-foreground/20"
283330
/>
284331
<div className="flex items-center gap-1">
285-
{roots.map((root) => (
332+
{displayRoots.map((root) => (
286333
<button
287334
key={root}
288335
aria-label={t.index.browseRoot(root)}
@@ -297,12 +344,14 @@ function CreateIndexModal({ onClose, onCreated }: { onClose: () => void; onCreat
297344

298345
{/* Breadcrumb */}
299346
<div className="px-5 py-2 border-y border-border/20 flex items-center gap-0.5 overflow-x-auto text-[11px] shrink-0">
300-
<button onClick={() => browse("/")} className="text-primary/60 hover:text-primary shrink-0 transition-colors">/</button>
347+
{!isWinPath && (
348+
<button onClick={() => browse("/")} className="text-primary/60 hover:text-primary shrink-0 transition-colors">/</button>
349+
)}
301350
{segments.map((seg, i) => (
302351
<span key={i} className="flex items-center gap-0.5 shrink-0">
303-
<span className="text-foreground/15">/</span>
352+
{(i > 0 || !isWinPath) && <span className="text-foreground/15">/</span>}
304353
<button
305-
onClick={() => browse("/" + segments.slice(0, i + 1).join("/"))}
354+
onClick={() => browse(crumbPath(i))}
306355
className={`transition-colors ${i === segments.length - 1 ? "text-foreground/70 font-medium" : "text-primary/50 hover:text-primary"}`}
307356
>
308357
{seg}

‎graph-ui/src/lib/i18n.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ export const messages = {
4545
selectRepositoryFolder: "Select Repository Folder",
4646
instructions: "Navigate to the project root and click \"Index This Folder\".",
4747
repositoryPath: "Repository path",
48-
projectName: "Project name",
49-
projectNamePlaceholder: "Optional display name",
48+
projectName: "Project ID (optional — permanent, cannot be renamed)",
49+
projectNamePlaceholder: "Derived from folder name if blank",
50+
projectNameHelp: "Becomes the database name and query prefix. Leave blank to derive it from the path.",
5051
filterFolders: "Filter folders",
5152
noSubdirectories: "No subdirectories",
5253
indexThisFolder: "Index This Folder",
@@ -116,8 +117,9 @@ export const messages = {
116117
selectRepositoryFolder: "选择仓库目录",
117118
instructions: "导航到项目根目录,然后点击“索引此目录”。",
118119
repositoryPath: "仓库路径",
119-
projectName: "项目名称",
120-
projectNamePlaceholder: "可选显示名称",
120+
projectName: "项目 ID(可选,永久且不可重命名)",
121+
projectNamePlaceholder: "留空则从路径派生",
122+
projectNameHelp: "将作为数据库名称与查询前缀;留空则从路径派生。",
121123
filterFolders: "筛选目录",
122124
noSubdirectories: "没有子目录",
123125
indexThisFolder: "索引此目录",

‎internal/cbm/cbm.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ typedef struct {
236236
int loop_depth; // enclosing loop nesting at the call site
237237
int branch_depth; // enclosing branch nesting at the call site
238238
int start_line; // 1-based source line of the call (for def range-match)
239-
bool is_method; // Perl-only: arrow/method call ($obj->m). Default false.
239+
bool is_method; // method/member call with a non-self receiver. Perl:
240+
// arrow/method call ($obj->m). TS/JS/TSX: member call
241+
// x.foo() whose receiver is not this/super. Default false.
240242
} CBMCall;
241243

242244
typedef struct {

‎internal/cbm/extract_calls.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,29 @@ void handle_calls(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec, Walk
18921892
strcmp(ts_node_type(node), "method_call_expression") == 0) {
18931893
call.is_method = true;
18941894
}
1895+
// TS/JS/TSX receiver-aware guard (#592/#606 direction; same intent
1896+
// as the Perl flag above). Flag a member call x.foo() whose receiver
1897+
// is NOT `this`/`super`. When the TS-LSP cannot resolve the receiver
1898+
// type, the call-resolution pass suppresses weak short-name matches
1899+
// for these (so `re.test()` cannot fabricate an edge to a project
1900+
// `test`). this/super receivers stay unflagged — their target is the
1901+
// enclosing class, where a namespace-proximity weak match is usually
1902+
// right. Bare calls (helper()) and new_expression have no member
1903+
// receiver, so they keep is_method=false (struct is zero-init).
1904+
if ((ctx->language == CBM_LANG_JAVASCRIPT || ctx->language == CBM_LANG_TYPESCRIPT ||
1905+
ctx->language == CBM_LANG_TSX) &&
1906+
strcmp(ts_node_type(node), "call_expression") == 0) {
1907+
TSNode fn = ts_node_child_by_field_name(node, TS_FIELD("function"));
1908+
if (!ts_node_is_null(fn) && strcmp(ts_node_type(fn), "member_expression") == 0) {
1909+
TSNode obj = ts_node_child_by_field_name(fn, TS_FIELD("object"));
1910+
if (!ts_node_is_null(obj)) {
1911+
const char *ok = ts_node_type(obj);
1912+
if (strcmp(ok, "this") != 0 && strcmp(ok, "super") != 0) {
1913+
call.is_method = true;
1914+
}
1915+
}
1916+
}
1917+
}
18951918

18961919
TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
18971920
if (!ts_node_is_null(args)) {

‎src/cli/cli.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,8 @@ int cbm_cmd_config(int argc, char **argv) {
28222822
"Enable auto-indexing on MCP session start");
28232823
printf(" %-25s default=%-10s %s\n", CBM_CONFIG_AUTO_INDEX_LIMIT, "50000",
28242824
"Max files for auto-indexing new projects");
2825+
printf(" %-25s default=%-10s %s\n", CBM_CONFIG_AUTO_WATCH, "true",
2826+
"Register background git watcher on session connect");
28252827
printf(" %-25s default=%-10s %s\n", CBM_CONFIG_UI_LANG, "auto",
28262828
"Pin graph UI language: en, zh, or auto");
28272829
return 0;
@@ -2849,6 +2851,8 @@ int cbm_cmd_config(int argc, char **argv) {
28492851
cbm_config_get(cfg, CBM_CONFIG_AUTO_INDEX, "false"));
28502852
printf(" %-25s = %-10s\n", CBM_CONFIG_AUTO_INDEX_LIMIT,
28512853
cbm_config_get(cfg, CBM_CONFIG_AUTO_INDEX_LIMIT, "50000"));
2854+
printf(" %-25s = %-10s\n", CBM_CONFIG_AUTO_WATCH,
2855+
cbm_config_get(cfg, CBM_CONFIG_AUTO_WATCH, "true"));
28522856
printf(" %-25s = %-10s\n", CBM_CONFIG_UI_LANG,
28532857
cbm_config_get(cfg, CBM_CONFIG_UI_LANG, "auto"));
28542858
} else if (strcmp(argv[0], "get") == 0) {

0 commit comments

Comments
 (0)