Skip to content

Commit c6ff57d

Browse files
authored
Merge branch 'main' into fix/cypher-nonnumeric-limit-silently-dropped
2 parents 3d9a6cf + ffb5ebe commit c6ff57d

77 files changed

Lines changed: 4174 additions & 553 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/_test.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,14 @@ jobs:
311311
steps:
312312
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
313313

314+
# Pinned: the unversioned `llvm` formula tracks Homebrew stable, so the
315+
# leg's compiler changed under us when stable moved 22 -> 23 (a new
316+
# -Wunused-but-set-global under -Werror broke the build on whichever
317+
# runner drew the 23 bottle, and passed on the ones that drew 22). A
318+
# test verdict must be a function of the code, not of the image snapshot;
319+
# moving to a newer major is a deliberate one-line bump here.
314320
- name: Install LSan-capable toolchain
315-
run: brew install llvm ccache
321+
run: brew install llvm@22 ccache
316322

317323
- name: Compiler cache (content-verified, restore)
318324
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
@@ -327,7 +333,7 @@ jobs:
327333
env:
328334
ASAN_OPTIONS: "detect_leaks=1:halt_on_error=1"
329335
run: |
330-
LLVM_PREFIX="$(brew --prefix llvm)"
336+
LLVM_PREFIX="$(brew --prefix llvm@22)"
331337
scripts/test.sh CC="$LLVM_PREFIX/bin/clang" CXX="$LLVM_PREFIX/bin/clang++"
332338
333339
- name: Compiler cache (save)

‎README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,13 @@ Commit a single compressed file to your repo and your teammates skip the reindex
250250
- **Best** (`zstd -9` + index strip + `VACUUM INTO`) — written on explicit `index_repository`
251251
- **Fast** (`zstd -3`) — written by the watcher for low-latency incremental updates
252252
- **Bootstrap**: when no local DB exists but the artifact is present, `index_repository` imports the artifact first, then runs incremental indexing — avoiding the full reindex cost
253-
- **No merge pain**: a `.gitattributes` line with `merge=ours` is auto-created on first export, so concurrent edits don't produce conflicts on the binary artifact
253+
- **No merge pain**: a `.codebase-memory/.gitattributes` line with `merge=ours` is auto-created on first export, so concurrent edits don't produce conflicts on the binary artifact
254+
- **Commit it deliberately**: the artifact is rewritten on every index, including the watcher's Fast tier, and git stores each rewrite as a full new blob. Committing every refresh is what turns a 20 MB file into gigabytes of history — one team reached ~6 GB across ~350 commits of this single path. Pick a cadence (a release, a milestone, a nightly job) rather than committing every save.
255+
- **Git LFS, if it must move on every commit**: track it from the **repo-root** `.gitattributes` and leave the auto-created `.codebase-memory/.gitattributes` in place — the nearer file goes on supplying `merge=ours`, and only `filter` comes from the root:
256+
```gitattributes
257+
.codebase-memory/graph.db.zst filter=lfs diff=lfs merge=lfs -text
258+
```
259+
Track only the `.zst`; `artifact.json` is small and carries the schema version. The attribute applies to future commits only, so a repo that already has the blobs in history needs `git-filter-repo` to rewrite them first. Two costs to weigh before adopting it: GitHub meters LFS storage and bandwidth, and its objects cannot be pruned without contacting support; and every teammate needs `git lfs install` — without it their checkout leaves a pointer file where the artifact should be, the integrity-checked import refuses it, and they fall back to a full reindex.
254260
- **Optional**: never committed unless you want it. Add `.codebase-memory/` to `.gitignore` if you prefer everyone to reindex from scratch.
255261

256262
The result is similar in spirit to graphify's `graphify-out/` directory, but as a single compressed file with explicit two-tier export, integrity-checked import, and zero merge friction.

‎graph-ui/src/App.test.tsx‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* @vitest-environment jsdom */
2+
import "@testing-library/jest-dom/vitest";
3+
import { cleanup, render, screen, waitFor } from "@testing-library/react";
4+
import { afterEach, describe, expect, it, vi } from "vitest";
5+
import { App } from "./App";
6+
import { messages } from "./lib/i18n";
7+
8+
vi.mock("./components/GraphTab", () => ({ GraphTab: () => null }));
9+
vi.mock("./components/StatsTab", () => ({ StatsTab: () => null }));
10+
vi.mock("./components/ControlTab", () => ({ ControlTab: () => null }));
11+
vi.mock("./lib/i18n", async (importOriginal) => {
12+
const actual = await importOriginal<typeof import("./lib/i18n")>();
13+
return { ...actual, useUiMessages: () => messages.en };
14+
});
15+
16+
describe("App", () => {
17+
afterEach(() => {
18+
cleanup();
19+
vi.unstubAllGlobals();
20+
window.history.replaceState(null, "", "/");
21+
});
22+
23+
it("shows the serving binary version", async () => {
24+
vi.stubGlobal("fetch", vi.fn(async () =>
25+
new Response(JSON.stringify({ lang: "en", version: "0.10.8" }), {
26+
status: 200,
27+
headers: { "Content-Type": "application/json" },
28+
}),
29+
));
30+
31+
render(<App />);
32+
33+
expect(await screen.findByText("v0.10.8")).toBeVisible();
34+
});
35+
36+
it("hides the version when the config has no string version", async () => {
37+
const fetchMock = vi.fn(async () =>
38+
new Response(JSON.stringify({ lang: "en", version: 108 }), { status: 200 }),
39+
);
40+
vi.stubGlobal("fetch", fetchMock);
41+
42+
render(<App />);
43+
44+
await waitFor(() => expect(fetchMock).toHaveBeenCalledWith("/api/ui-config"));
45+
expect(screen.queryByTitle("Server version")).not.toBeInTheDocument();
46+
});
47+
48+
it("hides the version when the config request fails", async () => {
49+
const fetchMock = vi.fn(async () => {
50+
throw new Error("offline");
51+
});
52+
vi.stubGlobal("fetch", fetchMock);
53+
54+
render(<App />);
55+
56+
await waitFor(() => expect(fetchMock).toHaveBeenCalledWith("/api/ui-config"));
57+
expect(screen.queryByTitle("Server version")).not.toBeInTheDocument();
58+
});
59+
});

‎graph-ui/src/App.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,24 @@ function routeUrl(tab: TabId, project: string | null): string {
3333
export function App() {
3434
const t = useUiMessages();
3535
const [route, setRoute] = useState<RouteState>(readRoute);
36+
const [version, setVersion] = useState<string | null>(null);
3637
const { tab: activeTab, project: selectedProject } = route;
3738

39+
useEffect(() => {
40+
let cancelled = false;
41+
void fetch("/api/ui-config")
42+
.then((response) => (response.ok ? response.json() : null))
43+
.then((config) => {
44+
if (!cancelled && typeof config?.version === "string" && config.version) {
45+
setVersion(config.version);
46+
}
47+
})
48+
.catch(() => {});
49+
return () => {
50+
cancelled = true;
51+
};
52+
}, []);
53+
3854
/* Normalize the URL on first load so it always carries the current route. */
3955
useEffect(() => {
4056
const initial = readRoute();
@@ -73,6 +89,14 @@ export function App() {
7389
<span className="text-[13px] font-semibold text-foreground/90 tracking-tight">
7490
Codebase Memory
7591
</span>
92+
{version && (
93+
<span
94+
className="translate-y-px text-[10px] font-mono text-foreground/30"
95+
title="Server version"
96+
>
97+
{version.startsWith("v") ? version : `v${version}`}
98+
</span>
99+
)}
76100
</div>
77101

78102
{/* Tabs inline in header */}

‎internal/cbm/cbm.c‎

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* Full declaration set for the same CBMArena, and it must precede cbm.h:
2+
* internal/cbm/arena.h declares a subset and the two share the CBM_ARENA_H
3+
* guard, so whichever is included first is the one this file sees. */
4+
#include "foundation/arena.h" // cbm_arena_init_sized
15
#include "cbm.h"
26
#include "arena.h" // CBMArena, cbm_arena_init/alloc/strdup/destroy
37
#include "helpers.h"
@@ -817,9 +821,13 @@ static void cbm_error_regions_push(cbm_error_regions_t *acc, TSNode n) {
817821
* untouched.
818822
*
819823
* #1746: the Dockerfile grammar places that zero-width missing newline before
820-
* trailing horizontal whitespace rather than at raw EOF. Preserve the broad
821-
* exact-EOF rule above; only extend it past spaces/tabs when the missing token
822-
* is specifically a newline. */
824+
* trailing whitespace rather than at raw EOF. Preserve the broad exact-EOF
825+
* rule above; only extend it past blanks when the missing token is specifically
826+
* a newline. */
827+
static bool cbm_is_blank_not_newline(char c) {
828+
return c == ' ' || c == '\t' || c == '\v' || c == '\f' || c == '\r';
829+
}
830+
823831
static bool cbm_is_eof_terminator_miss(TSNode n, const char *source, int source_len) {
824832
if (!ts_node_is_missing(n) || source_len < 0) {
825833
return false;
@@ -836,7 +844,7 @@ static bool cbm_is_eof_terminator_miss(TSNode n, const char *source, int source_
836844
return false;
837845
}
838846
for (uint32_t i = end; i < (uint32_t)source_len; i++) {
839-
if (source[i] != ' ' && source[i] != '\t') {
847+
if (!cbm_is_blank_not_newline(source[i])) {
840848
return false;
841849
}
842850
}
@@ -1186,11 +1194,27 @@ CBMFileResult *cbm_extract_file(const char *source, int source_len, CBMLanguage
11861194
return r;
11871195
}
11881196

1189-
CBMFileResult *cbm_extract_file_ex(const char *source, int source_len, CBMLanguage language,
1190-
const char *project, const char *rel_path,
1191-
int64_t timeout_micros, const char **extra_defines,
1192-
const char **include_paths, const CBMMacroTable *macro_table,
1193-
const CBMReturnTypeTable *return_type_table) {
1197+
/* Initial block for the per-file traversal scratch arena, chosen by measuring
1198+
* arena_grow on a 14k-file TypeScript tree: it fires on one file in 12,000 at
1199+
* both this size and at 1 MB, and on most files at 256 KB, where the two
1200+
* channel walks alone are exactly 262144 bytes. 512 KB therefore buys the same
1201+
* growth behaviour as 1 MB for half the resident block per worker. It is also
1202+
* exactly MI_LARGE_MAX_OBJ_SIZE in the vendored mimalloc
1203+
* (vendored/mimalloc/include/mimalloc/types.h:426, MI_LARGE_PAGE_SIZE/8 with
1204+
* MI_ENABLE_LARGE_PAGES defaulting to 1 at :115 and not overridden here), so
1205+
* the block is still bin-allocated from a large page. Growth is not free at
1206+
* this size for the same reason: arena_grow doubles to 1 MiB, which is above
1207+
* that bound and so a singleton OS allocation. One file in twelve thousand
1208+
* pays it, which is why the cost is accepted. */
1209+
enum { CBM_EXTRACT_SCRATCH_BLOCK = CBM_SZ_512 * CBM_SZ_1K };
1210+
1211+
static CBMFileResult *extract_file_ex_body(const char *source, int source_len, CBMLanguage language,
1212+
const char *project, const char *rel_path,
1213+
int64_t timeout_micros, const char **extra_defines,
1214+
const char **include_paths,
1215+
const CBMMacroTable *macro_table,
1216+
const CBMReturnTypeTable *return_type_table,
1217+
CBMArena *scratch) {
11941218
// Allocate result on heap (arena inside for all string data)
11951219
enum { SINGLE = 1 };
11961220
CBMFileResult *result = (CBMFileResult *)calloc(SINGLE, sizeof(CBMFileResult));
@@ -1301,6 +1325,7 @@ CBMFileResult *cbm_extract_file_ex(const char *source, int source_len, CBMLangua
13011325
// Build extraction context
13021326
CBMExtractCtx ctx = {
13031327
.arena = a,
1328+
.scratch = scratch,
13041329
.result = result,
13051330
.source = source,
13061331
.source_len = source_len,
@@ -1429,6 +1454,7 @@ CBMFileResult *cbm_extract_file_ex(const char *source, int source_len, CBMLangua
14291454
// Build context for expanded source — extract only calls via unified extractor
14301455
CBMExtractCtx pp_ctx = {
14311456
.arena = a,
1457+
.scratch = scratch,
14321458
.result = result,
14331459
.source = expanded,
14341460
.source_len = expanded_len,
@@ -1665,6 +1691,26 @@ CBMFileResult *cbm_extract_file_ex(const char *source, int source_len, CBMLangua
16651691
return result;
16661692
}
16671693

1694+
/* Public entry. Owns the traversal scratch arena for the whole of one file's
1695+
* extraction: created here, handed to the body as ctx->scratch, destroyed on
1696+
* the way out. The body has seven early returns, so bracketing it in a wrapper
1697+
* is what keeps that to one create and one destroy. If the arena cannot be
1698+
* created, the body is handed NULL and the traversal stacks fall back to the
1699+
* result arena, which is what shipped before #1997. */
1700+
CBMFileResult *cbm_extract_file_ex(const char *source, int source_len, CBMLanguage language,
1701+
const char *project, const char *rel_path,
1702+
int64_t timeout_micros, const char **extra_defines,
1703+
const char **include_paths, const CBMMacroTable *macro_table,
1704+
const CBMReturnTypeTable *return_type_table) {
1705+
CBMArena scratch;
1706+
cbm_arena_init_sized(&scratch, CBM_EXTRACT_SCRATCH_BLOCK);
1707+
CBMFileResult *result = extract_file_ex_body(
1708+
source, source_len, language, project, rel_path, timeout_micros, extra_defines,
1709+
include_paths, macro_table, return_type_table, scratch.nblocks > 0 ? &scratch : NULL);
1710+
cbm_arena_destroy(&scratch);
1711+
return result;
1712+
}
1713+
16681714
void cbm_free_result(CBMFileResult *result) {
16691715
if (!result) {
16701716
return;

‎internal/cbm/cbm.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ typedef struct {
269269
// pass_lsp_cross.c. Default false.
270270
bool requires_lsp_resolution; // synthetic semantic candidate (for example an implicit
271271
// C++ operator). Never fall back to textual resolution.
272+
bool callee_is_locally_bound; // bare call foo() whose callee identifier is bound as a
273+
// parameter of an enclosing function, so it cannot be the
274+
// module-level foo. Python only today. Read by the
275+
// weak-local-binding guard. Default false.
272276
} CBMCall;
273277

274278
typedef struct {
@@ -292,6 +296,10 @@ typedef struct {
292296
uint32_t site_start_byte; // exact reference-token span; end > start when present
293297
uint32_t site_end_byte; // exclusive byte offset in the source file
294298
CBMSourceOrigin source_origin; // raw source or C-family preprocessed buffer
299+
bool is_member_access; // token is the member half of a selector/attribute
300+
// (Go x.f — field_identifier). The extractor strips
301+
// the receiver, so this is the only surviving record
302+
// of selector shape (#1962). Default false.
295303
} CBMUsage;
296304

297305
typedef struct {
@@ -303,6 +311,9 @@ typedef struct {
303311
const char *var_name; // variable name
304312
const char *enclosing_func_qn; // QN of enclosing function
305313
bool is_write; // true = write, false = read
314+
bool is_member_access; // var_name is the field half of a selector/member LHS
315+
// (`t.err = x` → "err"); the receiver is stripped here,
316+
// so this is the only record of selector shape (#1962)
306317
} CBMReadWrite;
307318

308319
typedef struct {
@@ -582,6 +593,13 @@ typedef struct {
582593

583594
typedef struct {
584595
CBMArena *arena;
596+
/* Scratch for AST traversal, owned by the cbm_extract_file_ex call that
597+
* built this context and destroyed when it returns. Nothing a
598+
* CBMFileResult points at may be allocated here: `arena` is the result's
599+
* own, and it outlives extraction by the whole pipeline (#1997). NULL in a
600+
* context built without one, in which case the stacks fall back to
601+
* `arena`. */
602+
CBMArena *scratch;
585603
CBMFileResult *result;
586604
const char *source;
587605
int source_len;

0 commit comments

Comments
 (0)