Skip to content

Commit bdf204b

Browse files
committed
Merge origin/main into fix/elixir-extraction-defects
Signed-off-by: Martin Vogel <[email protected]>
2 parents f925afa + 47474b6 commit bdf204b

43 files changed

Lines changed: 1895 additions & 154 deletions

Some content is hidden

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

‎.claude-plugin/marketplace.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "codebase-memory",
3+
"description": "The codebase-memory-mcp code knowledge graph server, as a Claude Code plugin.",
4+
"owner": {
5+
"name": "DeusData",
6+
"url": "https://github.com/DeusData"
7+
},
8+
"plugins": [
9+
{
10+
"name": "codebase-memory",
11+
"source": "./plugin",
12+
"description": "Codebase knowledge graph for AI agents: sub-ms queries, 99% fewer tokens."
13+
}
14+
]
15+
}

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Thumbs.db
3333

3434
# MCP config (user-local, generated by install command)
3535
.mcp.json
36+
# ...except the Claude Code plugin's server definition, which is published
37+
!plugin/.mcp.json
3638

3739
# MCP Registry auth tokens
3840
.mcpregistry_*

‎README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,30 @@ Working in a clone? Use `.` in place of the flake URL, e.g. `nix run .#codebase-
578578
You: "Install this MCP server: https://github.com/DeusData/codebase-memory-mcp"
579579
```
580580

581+
### Install via Claude Code plugin
582+
583+
This repository is also a Claude Code plugin marketplace, so you can find and
584+
add the server from inside Claude Code:
585+
586+
```bash
587+
claude plugin marketplace add DeusData/codebase-memory-mcp
588+
claude plugin install codebase-memory@codebase-memory
589+
```
590+
591+
The plugin registers the MCP server only. It starts the server with
592+
`npx -y codebase-memory-mcp@<version>`, pinned to the current release; the first
593+
start downloads that release's binary through the npm package, which verifies
594+
it against the release checksums. The skill, the three graph agents and the
595+
context hooks are not part of the plugin: they come from
596+
`codebase-memory-mcp install`.
597+
598+
Use one or the other. `install` registers the same server for Claude Code, so
599+
with both you run it twice, under two tool namespaces
600+
(`mcp__codebase-memory-mcp__*` and
601+
`mcp__plugin_codebase-memory_codebase-memory-mcp__*`). Choose `install` for the
602+
full Claude Code setup; choose the plugin to add just the server without
603+
running an installer.
604+
581605
### Build from Source
582606

583607
<details>

‎docs/CONFIGURATION.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ root because they are too broad or too sensitive to index as a unit:
245245
- a credential directory at any depth — `.ssh`, `.aws`, `.gnupg`, `.kube`,
246246
`.docker`, `.netrc`, `.git-credentials`, `.password-store`, macOS `Keychains`.
247247

248+
A single top-level directory can still be indexed as one root on purpose, for
249+
example a container or build machine that keeps its project in `/work`, `/app` or
250+
`/src`, by approving that exact path in a terminal:
251+
`codebase-memory-mcp allow-root --approve-broad /work`. The approval is recorded
252+
like any other allowed root, listed as `(approved broad)` by `allow-root --list`,
253+
and covers no other top-level directory; as with any recorded root, indexing is
254+
then confined to the recorded roots. Filesystem, drive and share roots cannot be
255+
approved.
256+
248257
Two limits are worth stating plainly. This constrains *scope*, not
249258
*sensitivity*: inside a root that is allowed, every file the process can read may
250259
be indexed and later returned. And the credential list is a denylist, so it

‎internal/cbm/cbm.h‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ typedef struct {
298298
* are bound to the owning result's source identity before cross-file use. */
299299
uint32_t test_name_start_byte, test_name_end_byte;
300300
uint32_t test_body_start_byte, test_body_end_byte;
301-
/* Documents only: facts a document definition adds to its node's
302-
* properties, as a NULL-terminated key, value, key, value, ... list (an
303-
* ADR's id, status, date, deciders, title). Keys are fixed literals; the
301+
/* Facts a definition adds to its node's properties, as a NULL-terminated
302+
* key, value, key, value, ... list: a document's (an ADR's id, status,
303+
* date, deciders, title), or CBM_PROP_GENERATED on a member the compiler
304+
* writes and the source never spells. Keys are fixed literals; the
304305
* values are escaped where the properties are written. Tail field:
305306
* zero-init stays valid. */
306307
const char **extra_props;
@@ -321,6 +322,13 @@ typedef struct {
321322
const char *alias_target;
322323
} CBMDefinition;
323324

325+
/* extra_props key of a generated member, one the compiler writes and the
326+
* source never spells: a Java record's implicit accessor carries
327+
* `generated: record`. The node keeps the property, and the pipeline registers
328+
* such a definition by qualified name only, so no short-name guess can land on
329+
* it (pipeline.h cbm_def_props_generated). */
330+
#define CBM_PROP_GENERATED "generated"
331+
324332
/* Argument captured from a call expression */
325333
typedef struct {
326334
const char *expr; // raw expression text ("payload.info", "MY_URL", "'hello'")

‎internal/cbm/extract_defs.c‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ static void extract_class_fields(CBMExtractCtx *ctx, TSNode class_node, const ch
230230
const CBMLangSpec *spec);
231231
static TSNode find_class_body(TSNode class_node, CBMLanguage lang);
232232
static void extract_enum_members(CBMExtractCtx *ctx, TSNode node, const char *class_qn);
233+
static void extract_record_accessors(CBMExtractCtx *ctx, TSNode node, const char *class_qn);
233234
static void extract_elixir_call(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec);
234235

235236
// --- Helpers ---
@@ -8317,6 +8318,10 @@ static void emit_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *s
83178318
extract_enum_members(ctx, node, class_qn);
83188319
}
83198320

8321+
if (ctx->language == CBM_LANG_JAVA && strcmp(kind, "record_declaration") == 0) {
8322+
extract_record_accessors(ctx, node, class_qn);
8323+
}
8324+
83208325
// Extract methods inside the class
83218326
int methods_from = ctx->result->defs.count;
83228327
extract_class_methods(ctx, node, class_qn, spec);
@@ -9782,6 +9787,121 @@ static void extract_enum_members(CBMExtractCtx *ctx, TSNode node, const char *cl
97829787
}
97839788
}
97849789

9790+
/* Whether the record body declares this accessor itself (JLS §8.10.3 lets a
9791+
* record override any of them), so the implicit one is not emitted twice. */
9792+
static bool record_declares_accessor(CBMExtractCtx *ctx, TSNode node, const char *comp_name) {
9793+
TSNode body = find_class_body(node, ctx->language);
9794+
if (ts_node_is_null(body)) {
9795+
return false;
9796+
}
9797+
uint32_t mc = ts_node_named_child_count(body);
9798+
for (uint32_t mi = 0; mi < mc; mi++) {
9799+
TSNode member = ts_node_named_child(body, mi);
9800+
if (strcmp(ts_node_type(member), "method_declaration") != 0) {
9801+
continue;
9802+
}
9803+
TSNode mname = ts_node_child_by_field_name(member, TS_FIELD("name"));
9804+
if (ts_node_is_null(mname)) {
9805+
continue;
9806+
}
9807+
char *name = cbm_node_text(ctx->arena, mname, ctx->source);
9808+
if (!name || strcmp(name, comp_name) != 0) {
9809+
continue;
9810+
}
9811+
/* Same name, no parameters — that is the accessor. */
9812+
TSNode params = ts_node_child_by_field_name(member, TS_FIELD("parameters"));
9813+
if (ts_node_is_null(params)) {
9814+
return true;
9815+
}
9816+
/* Comments are named extras, not parameters. */
9817+
bool has_parameters = false;
9818+
uint32_t pc = ts_node_named_child_count(params);
9819+
for (uint32_t pi = 0; pi < pc; pi++) {
9820+
if (!ts_node_is_extra(ts_node_named_child(params, pi))) {
9821+
has_parameters = true;
9822+
break;
9823+
}
9824+
}
9825+
if (!has_parameters) {
9826+
return true;
9827+
}
9828+
}
9829+
return false;
9830+
}
9831+
9832+
/* Java records: the compiler writes one accessor per component, so `p.x()`
9833+
* calls a method that appears nowhere in the source. Without a definition for
9834+
* it the call has nothing to resolve to and falls through to the project-wide
9835+
* name registry, which binds it to the first `x` in the tree — typically an
9836+
* unrelated class's private field. Emitting the accessors makes the record's
9837+
* own API visible, exactly as the language defines it (JLS §8.10.3). */
9838+
static void extract_record_accessors(CBMExtractCtx *ctx, TSNode node, const char *class_qn) {
9839+
CBMArena *a = ctx->arena;
9840+
TSNode params = ts_node_child_by_field_name(node, TS_FIELD("parameters"));
9841+
if (ts_node_is_null(params)) {
9842+
return;
9843+
}
9844+
uint32_t pc = ts_node_named_child_count(params);
9845+
for (uint32_t pi = 0; pi < pc; pi++) {
9846+
TSNode comp = ts_node_named_child(params, pi);
9847+
bool spread = strcmp(ts_node_type(comp), "spread_parameter") == 0;
9848+
if (!spread && strcmp(ts_node_type(comp), "formal_parameter") != 0) {
9849+
continue;
9850+
}
9851+
TSNode cname = ts_node_child_by_field_name(comp, TS_FIELD("name"));
9852+
TSNode ctype = ts_node_child_by_field_name(comp, TS_FIELD("type"));
9853+
if (spread) {
9854+
/* Java varargs have an unnamed type child and a nested declarator. */
9855+
TSNode decl = cbm_find_child_by_kind(comp, "variable_declarator");
9856+
if (ts_node_is_null(decl)) {
9857+
continue;
9858+
}
9859+
cname = ts_node_child_by_field_name(decl, TS_FIELD("name"));
9860+
uint32_t nc = ts_node_named_child_count(comp);
9861+
for (uint32_t ci = 0; ci < nc; ci++) {
9862+
TSNode child = ts_node_named_child(comp, ci);
9863+
if (!ts_node_is_extra(child) && strcmp(ts_node_type(child), "modifiers") != 0) {
9864+
ctype = child;
9865+
break;
9866+
}
9867+
}
9868+
}
9869+
if (ts_node_is_null(cname)) {
9870+
continue;
9871+
}
9872+
char *comp_name = cbm_node_text(a, cname, ctx->source);
9873+
if (!comp_name || !comp_name[0] || record_declares_accessor(ctx, node, comp_name)) {
9874+
continue;
9875+
}
9876+
CBMDefinition adef;
9877+
memset(&adef, 0, sizeof(adef));
9878+
adef.name = comp_name;
9879+
adef.qualified_name = cbm_arena_sprintf(a, "%s.%s", class_qn, comp_name);
9880+
adef.label = "Method";
9881+
adef.file_path = ctx->rel_path;
9882+
adef.start_line = ts_node_start_point(comp).row + TS_LINE_OFFSET;
9883+
adef.end_line = ts_node_end_point(comp).row + TS_LINE_OFFSET;
9884+
adef.lines = 1;
9885+
adef.parent_class = class_qn;
9886+
adef.is_exported = true;
9887+
if (!ts_node_is_null(ctype)) {
9888+
const char *type = cbm_node_text(a, ctype, ctx->source);
9889+
adef.return_type = spread && type ? cbm_arena_sprintf(a, "%s[]", type) : type;
9890+
}
9891+
/* The compiler writes this member and the source never spells it: its
9892+
* node says so, and the pipeline registers it by qualified name only,
9893+
* so no short-name guess can land on it. */
9894+
const char **kv = (const char **)cbm_arena_alloc(a, CBM_SZ_3 * sizeof(char *));
9895+
if (kv) {
9896+
kv[0] = CBM_PROP_GENERATED;
9897+
kv[SKIP_ONE] = "record";
9898+
kv[PAIR_LEN] = NULL;
9899+
}
9900+
adef.extra_props = kv;
9901+
cbm_defs_push(&ctx->result->defs, a, adef);
9902+
}
9903+
}
9904+
97859905
/* Resolve the identifier node from a destructure pattern child.
97869906
* pair_pattern → value field; shorthand/identifier → itself; others → first named child. */
97879907
static TSNode destructure_ident(TSNode pat_child) {

‎internal/cbm/lsp/py_lsp.c‎

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,10 +6179,36 @@ static void py_split_field_defs(CBMArena *arena, const char *field_defs, const c
61796179
*types_out = types;
61806180
}
61816181

6182+
/* Qualified names of reg->types[0..noted), for a caller that registers into a
6183+
* registry it does not finalize until the end (cbm_py_build_cross_registry):
6184+
* that registry's own lookup scans every type. qns == NULL probes the
6185+
* registry instead. */
6186+
typedef struct {
6187+
CBMHashTable *qns;
6188+
int noted;
6189+
} PyKnownTypes;
6190+
6191+
/* Note the types added since the last call. Run after every add_type, so an
6192+
* add that failed silently cannot desync set and registry. If the set cannot
6193+
* grow it is dropped and probes fall back to the registry. */
6194+
static void py_note_known_types(PyKnownTypes *known, const CBMTypeRegistry *reg) {
6195+
for (; known && known->qns && known->noted < reg->type_count; known->noted++) {
6196+
const char *qn = reg->types[known->noted].qualified_name;
6197+
if (!qn || cbm_ht_has(known->qns, qn))
6198+
continue;
6199+
cbm_ht_set(known->qns, qn, (void *)(uintptr_t)(known->noted + 1));
6200+
if (!cbm_ht_has(known->qns, qn)) {
6201+
cbm_ht_free(known->qns);
6202+
known->qns = NULL;
6203+
}
6204+
}
6205+
}
6206+
61826207
/* Build a registry from CBMLSPDef[] supplied by the caller — covers both
6183-
* the source file's own defs and cross-file referenced defs. */
6208+
* the source file's own defs and cross-file referenced defs. known is NULL
6209+
* except for the shared Tier-2 build. */
61846210
static bool py_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRegistry *reg,
6185-
CBMLSPDef *defs, int def_count) {
6211+
CBMLSPDef *defs, int def_count, PyKnownTypes *known) {
61866212
/* Pass 1: types only — the method pass probes the registry per Method def
61876213
* (receiver auto-registration), which is a LINEAR scan pre-finalize:
61886214
* O(methods x types) per file (same quadratic as php_register_lsp_defs;
@@ -6206,6 +6232,7 @@ static bool py_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRe
62066232
}
62076233
py_split_field_defs(arena, d->field_defs, &rt.field_names, &rt.field_types);
62086234
cbm_registry_add_type(reg, rt);
6235+
py_note_known_types(known, reg);
62096236
}
62106237
}
62116238
/* idx_arena == NULL skips the mid-build finalize: the tier-2 builder
@@ -6259,13 +6286,17 @@ static bool py_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRe
62596286

62606287
if (strcmp(d->label, "Method") == 0 && d->receiver_type && d->receiver_type[0]) {
62616288
rf.receiver_type = d->receiver_type; /* borrowed */
6262-
if (!cbm_registry_lookup_type(reg, rf.receiver_type)) {
6289+
bool recv_known = known && known->qns
6290+
? cbm_ht_has(known->qns, rf.receiver_type)
6291+
: cbm_registry_lookup_type(reg, rf.receiver_type) != NULL;
6292+
if (!recv_known) {
62636293
CBMRegisteredType auto_t;
62646294
memset(&auto_t, 0, sizeof(auto_t));
62656295
auto_t.qualified_name = rf.receiver_type;
62666296
const char *dot = strrchr(d->receiver_type, '.');
62676297
auto_t.short_name = dot ? dot + 1 : rf.receiver_type; /* borrowed substring */
62686298
cbm_registry_add_type(reg, auto_t);
6299+
py_note_known_types(known, reg);
62696300
}
62706301
}
62716302
cbm_registry_add_func(reg, rf);
@@ -6277,7 +6308,7 @@ static bool py_register_lsp_defs(CBMArena *arena, CBMArena *idx_arena, CBMTypeRe
62776308
#ifdef CBM_ENABLE_TEST_SEAMS
62786309
bool cbm_py_lsp_test_register_defs(CBMArena *arena, CBMTypeRegistry *reg, CBMLSPDef *defs,
62796310
int def_count) {
6280-
return py_register_lsp_defs(arena, NULL, reg, defs, def_count);
6311+
return py_register_lsp_defs(arena, NULL, reg, defs, def_count, NULL);
62816312
}
62826313
#endif
62836314

@@ -6774,7 +6805,7 @@ CBMLSPStatus cbm_run_py_lsp_cross_status(CBMArena *arena, const char *source, in
67746805
py_lsp_init_for_stage(&ctx, arena, source, source_len, &reg, module_qn, out, "cross");
67756806
if (ctx.eval_failure)
67766807
goto cross_cleanup;
6777-
if (!py_register_lsp_defs(arena, &idx_arena, &reg, defs, def_count)) {
6808+
if (!py_register_lsp_defs(arena, &idx_arena, &reg, defs, def_count, NULL)) {
67786809
ctx.eval_failure = CBM_LSP_SCOPE_FAILED;
67796810
goto cross_cleanup;
67806811
}
@@ -6813,15 +6844,27 @@ CBMTypeRegistry *cbm_py_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, i
68136844
cbm_registry_init(reg, arena);
68146845
cbm_python_stdlib_register(reg, arena);
68156846

6847+
/* The registry is not finalized until the end, so probing it for each
6848+
* Method's receiver scanned every type: O(methods x types), single-threaded
6849+
* (~54 s of lsp_cross_prepare on a large Python tree). Probe a set of
6850+
* the registered type QNs instead; registration order is unchanged. Sized
6851+
* for the stdlib seed, not def_count (the mixed all-language count). NULL
6852+
* on allocation failure: the registry probe runs as before. */
6853+
PyKnownTypes known = {cbm_ht_create((uint32_t)reg->type_count), 0};
6854+
py_note_known_types(&known, reg);
6855+
68166856
/* Filter to Python defs only — defs[] is mixed-language all_defs. */
68176857
for (int i = 0; i < def_count; i++) {
68186858
CBMLSPDef *d = &defs[i];
68196859
if (d->lang != CBM_LANG_PYTHON)
68206860
continue;
68216861
/* Reuse the existing register fn on a single-def slice (n=1 inline). */
6822-
if (!py_register_lsp_defs(arena, NULL, reg, d, 1))
6862+
if (!py_register_lsp_defs(arena, NULL, reg, d, 1, &known)) {
6863+
cbm_ht_free(known.qns);
68236864
return NULL; /* caller owns the shared arena and other registries */
6865+
}
68246866
}
6867+
cbm_ht_free(known.qns);
68256868

68266869
py_mark_ambiguous_callable_bindings(reg, arena);
68276870
cbm_registry_build_type_qn_order(reg, arena);

‎plugin/.claude-plugin/plugin.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "codebase-memory",
3+
"version": "0.12.1",
4+
"description": "Codebase knowledge graph for AI agents: sub-ms queries, 99% fewer tokens.",
5+
"author": {
6+
"name": "DeusData",
7+
"url": "https://github.com/DeusData"
8+
}
9+
}

‎plugin/.mcp.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"mcpServers": {
3+
"codebase-memory-mcp": {
4+
"type": "stdio",
5+
"command": "npx",
6+
"args": ["-y", "[email protected]"]
7+
}
8+
}
9+
}

‎src/cli/cli.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "daemon/runtime.h"
2121
#include "daemon/version_cohort.h"
2222
#include "foundation/compat.h"
23+
#include "foundation/compat_fs.h"
2324
#include "foundation/platform.h"
2425
#include "foundation/constants.h"
2526
#include "foundation/json_writer.h"
@@ -2718,12 +2719,8 @@ int cbm_remove_zed_mcp_owned(const char *binary_path, const char *config_path) {
27182719
/* ── Agent detection ──────────────────────────────────────────── */
27192720

27202721
static bool dir_exists(const char *path) {
2721-
struct stat st;
2722-
#ifndef _WIN32
2723-
return lstat(path, &st) == 0 && S_ISDIR(st.st_mode);
2724-
#else
2725-
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
2726-
#endif
2722+
cbm_path_info_t info = {0};
2723+
return cbm_path_info_utf8(path, &info) == CBM_PATH_INFO_OK && info.is_directory;
27272724
}
27282725

27292726
/* Resolve the Claude Code config dir.

0 commit comments

Comments
 (0)