Skip to content

Commit 9372d19

Browse files
committed
Merge feat/doc-links-core (with main) into feat/doc-links-documents
Resolves the definition walks next to each other: main's decl_namespace (DeusData#2120) and this branch's extra_props are both compacted and both counted in the result census. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2 parents 190ac6b + 8207f8a commit 9372d19

22 files changed

Lines changed: 968 additions & 22 deletions

‎.github/workflows/pr.yml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ jobs:
6565
steps:
6666
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6767
with:
68-
# The PR merge commit and its base parent: the change to select for.
69-
fetch-depth: 2
68+
# Full history: the engine certifies the history it diffs and refuses
69+
# a shallow clone, so a depth-2 checkout always answered `all`.
70+
fetch-depth: 0
7071
persist-credentials: false
7172
- name: Build this checkout's engine
7273
run: |
@@ -281,8 +282,11 @@ jobs:
281282
steps:
282283
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
283284
with:
284-
# The PR merge commit and its base parent: the diff to predict for.
285-
fetch-depth: 2
285+
# Full history: the engine (test-impact select) certifies the history
286+
# it diffs and refuses a shallow clone ("Graft or shallow state
287+
# prevents history certification"), which made every shadow answer
288+
# run_all (GIT_UNAVAILABLE). About 400 MiB, this job only.
289+
fetch-depth: 0
286290
persist-credentials: false
287291
- name: Fetch the latest released binary
288292
id: release

‎.github/workflows/test-impact-artifact.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ jobs:
3838
steps:
3939
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4040
with:
41-
fetch-depth: 2
41+
# Full history: `test-impact select/publish` certify the history they
42+
# read and refuse a shallow clone.
43+
fetch-depth: 0
4244
persist-credentials: false
4345

4446
- name: Install build deps and LLVM 21 (coverage toolchain)

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ codebase-memory-mcp config set auto_index true
151151

152152
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`.
153153

154+
The watcher follows MCP sessions: it watches the project each open MCP session is rooted in (the client's working directory) and stops when the last session for that project closes. A repository indexed with `cli index_repository`, or indexed from a session rooted somewhere else, is not watched — re-run `index_repository` after changing it. `index_status` reports this in its `watch` object: `watched`, and either the poll cadence and last scan time or the `reason` it is not watched.
155+
154156
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.
155157

156158
To turn the watcher off entirely, set `config set watcher_enabled false` (default `true`): the background poll thread never starts and no project is registered, while `auto_index` and manual `index_repository` keep working. Unlike `auto_watch` — which is consulted per session — `watcher_enabled` is read once when the background daemon starts, so run `codebase-memory-mcp daemon stop` after changing it; reconnecting your MCP client alone will not restart the daemon. See [docs/CONFIGURATION.md](docs/CONFIGURATION.md#2-cli-managed-runtime-settings).
@@ -246,7 +248,7 @@ The install script placed beside the binary is **reported, not deleted** — uni
246248

247249
### Distribution & operation
248250
- **Native runtime set, zero infrastructure services**: SQLite-backed, persists to `~/.cache/codebase-memory-mcp/`
249-
- **Auto-sync**: Background watcher detects file changes and re-indexes automatically
251+
- **Auto-sync**: Background watcher detects file changes in the project an MCP session is working in and re-indexes it automatically (other indexed repos: re-run `index_repository`)
250252
- **Route nodes**: REST endpoints are first-class graph entities
251253
- **CLI mode**: `codebase-memory-mcp cli search_graph '{"project": "my-project", "name_pattern": ".*Handler.*"}'`
252254
- **Available on**: npm, PyPI, Homebrew, Scoop, Winget, Chocolatey, AUR, `go install`
@@ -681,7 +683,7 @@ JSON arguments can also be piped on stdin, for tools that take arguments. A tool
681683

682684
| Tool | Description |
683685
|------|-------------|
684-
| `index_repository` | Index a repository into the graph. Auto-sync keeps it fresh after that. Waits for the whole index by default; pass `async: true` to start it in the daemon and return at once, then poll with `status: true` (see below). |
686+
| `index_repository` | Index a repository into the graph. Auto-sync keeps it fresh only while it is the project of an open MCP session; repos indexed from the CLI or from another project's session need a re-run (`index_status` shows `watch`). Waits for the whole index by default; pass `async: true` to start it in the daemon and return at once, then poll with `status: true` (see below). |
685687
| `list_projects` | List all indexed projects with node/edge counts. |
686688
| `delete_project` | Remove a project and all its graph data. |
687689
| `index_status` | Check indexing status of a project. |

‎docs/CONFIGURATION.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ Current keys:
8888
| `auto_index` | `false` | Automatically index new projects when an MCP session starts. |
8989
| `auto_index_limit` | `50000` | Maximum file count allowed for automatic indexing of a new project. |
9090
| `auto_watch` | `true` | Register the session's project with the background git watcher on connect. Set `false` to keep a session from registering its project (the watcher still runs for other projects). |
91-
| `watcher_enabled` | `true` | Master switch for the background watcher subsystem. Set `false` to stop the watcher from starting at all — no poll thread and no project registration. Reindex manually with `index_repository` when disabled. |
91+
| `watcher_enabled` | `true` | Master switch for the background watcher subsystem. Set `false` to stop the watcher from starting at all — no poll thread and no project registration. Reindex manually with `index_repository` when disabled. Only an open MCP session's own project is ever watched; `index_status` reports the current state in its `watch` object. |
9292
| `watch_non_git` | `false` | Also poll project roots that are **not git repositories**. By default the watcher only follows git projects, so a project indexed from a plain directory is never refreshed after its first index — reindex it manually with `index_repository`. Set `true` to poll such roots on the same adaptive cadence with a file-tree scan: the indexer's own discovery walk (same skip lists, `.gitignore` and `.cbmignore` rules) hashed over each file's path, size and mtime. Any change reindexes once; paths the indexer skips (including cbm's own `.codebase-memory/` output) never trigger. The first poll after the daemon starts reindexes each such project once, since nothing records which tree state the index holds. The scan walks the whole tree every poll, so it costs more than git polling on very large trees. Read once when the daemon starts, like `watcher_enabled`. |
9393
| `index_max_files` | `off` | Optional maximum number of accepted source files in one discovery run. |
9494
| `index_max_source_mb` | `off` | Optional maximum accepted source size in MiB in one discovery run. |
9595

96+
For a watched project, `index_status` names the polling method in `watch.strategy`:
97+
`git` (HEAD and dirty-state polling), `tree` (a non-git root polled by the
98+
`watch_non_git` file-tree scan), `none` (a non-git root that is registered but never
99+
polled, the default for a plain directory) or `pending` (registered; the first poll
100+
has not run yet).
101+
96102
> **`watcher_enabled` vs `auto_watch`.** `watcher_enabled` controls whether the
97103
> watcher *subsystem* starts at all (the background poll thread). `auto_watch` is
98104
> narrower: it only controls whether a connecting session registers *its own*

‎docs/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ <h3>Infrastructure-as-code indexing</h3>
728728
</div>
729729
<div class="feature">
730730
<h3>Auto-sync</h3>
731-
<p>A background watcher detects changes and re-indexes incrementally. No manual reindex after editing files.</p>
731+
<p>A background watcher detects changes in the project your MCP session is working in and re-indexes it incrementally. No manual reindex after editing files there.</p>
732732
</div>
733733
<div class="feature">
734734
<h3>Team-shared graph artifact</h3>

‎internal/cbm/cbm.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ typedef struct {
285285
* qualified_name (base QN = the first qn_sig_off bytes); 0 = no suffix.
286286
* Always 0 until a language enables its callable_identity mode. */
287287
uint32_t qn_sig_off;
288+
/* C# only: declared namespace of a TOP-LEVEL type (NULL for nested types,
289+
* the global namespace and every other language). Per type, because the
290+
* file-level namespace_name records only a file's first namespace. */
291+
const char *decl_namespace;
288292
CBMTestDefinitionRole test_role; /* NONE preserves legacy helper/test-file semantics */
289293
/* Configured raw definitions only; zero for all legacy rows. Exact spans
290294
* are bound to the owning result's source identity before cross-file use. */

‎internal/cbm/extract_defs.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7156,6 +7156,58 @@ static void extract_py_field_types(CBMExtractCtx *ctx, TSNode class_node, const
71567156
}
71577157
}
71587158

7159+
/* Name of a C# namespace declaration node (block or file-scoped), or NULL. */
7160+
static const char *cs_namespace_decl_name(CBMArena *a, TSNode ns, const char *source) {
7161+
TSNode nm = ts_node_child_by_field_name(ns, TS_FIELD("name"));
7162+
if (ts_node_is_null(nm)) {
7163+
return NULL;
7164+
}
7165+
const char *text = cbm_node_text(a, nm, source);
7166+
return text && text[0] ? text : NULL;
7167+
}
7168+
7169+
/* Declared namespace of a C# type declaration: every enclosing namespace
7170+
* block (outer to inner) under an optional file-scoped namespace, which the
7171+
* grammar may attach either as an ancestor or as a preceding sibling of the
7172+
* compilation unit's members. NULL = global namespace. The file-level
7173+
* namespace_name keeps only the FIRST namespace of a file, which mislabels
7174+
* every type of a multi-namespace file (#2120). */
7175+
static const char *cs_type_decl_namespace(CBMArena *a, TSNode node, const char *source) {
7176+
const char *acc = NULL;
7177+
bool file_scoped = false;
7178+
TSNode top = node;
7179+
for (TSNode cur = ts_node_parent(node); !ts_node_is_null(cur); cur = ts_node_parent(cur)) {
7180+
const char *k = ts_node_type(cur);
7181+
bool is_file_scoped = strcmp(k, "file_scoped_namespace_declaration") == 0;
7182+
if (is_file_scoped || strcmp(k, "namespace_declaration") == 0) {
7183+
const char *name = cs_namespace_decl_name(a, cur, source);
7184+
if (name) {
7185+
acc = acc ? cbm_arena_sprintf(a, "%s.%s", name, acc) : name;
7186+
}
7187+
file_scoped = file_scoped || is_file_scoped;
7188+
}
7189+
top = cur;
7190+
}
7191+
if (file_scoped) {
7192+
return acc;
7193+
}
7194+
uint32_t start = ts_node_start_byte(node);
7195+
uint32_t n = ts_node_named_child_count(top);
7196+
for (uint32_t i = 0; i < n; i++) {
7197+
TSNode c = ts_node_named_child(top, i);
7198+
if (ts_node_start_byte(c) >= start) {
7199+
break;
7200+
}
7201+
if (strcmp(ts_node_type(c), "file_scoped_namespace_declaration") == 0) {
7202+
const char *name = cs_namespace_decl_name(a, c, source);
7203+
if (name) {
7204+
return acc ? cbm_arena_sprintf(a, "%s.%s", name, acc) : name;
7205+
}
7206+
}
7207+
}
7208+
return acc;
7209+
}
7210+
71597211
static void extract_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) {
71607212
CBMArena *a = ctx->arena;
71617213
const char *kind = ts_node_type(node);
@@ -7556,6 +7608,9 @@ static void emit_class_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *s
75567608
def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET;
75577609
def.lines = (int)(def.end_line - def.start_line + TS_LINE_OFFSET);
75587610
def.is_exported = cbm_is_exported(name, ctx->language);
7611+
if (ctx->language == CBM_LANG_CSHARP && !ctx->enclosing_class_qn) {
7612+
def.decl_namespace = cs_type_decl_namespace(a, node, ctx->source);
7613+
}
75597614
def.base_classes = extract_base_classes(a, node, ctx->source, ctx->language);
75607615
def.decorators = extract_decorators(a, node, ctx->source, ctx->language, spec);
75617616
def.docstring = extract_docstring(ctx, node, name);

0 commit comments

Comments
 (0)