Commit Graph
270 Commits
Author SHA1 Message Date
Martin Vogel 2cd0956560 Break-glass merge PR #2597 2026-10-12 20:15:14 +02:00
Martin Vogel d3b8d258be feat(index): doc_candidates setting and index_repository parameter
The doc<->code candidate scoring (#2574, doc_section_worker in
semantic_edges) scores every documentation section against the functions
that share a key term with it, key terms being those held by at most
funcs/20 functions. Its cost therefore grows with sections x functions.
Measured on 11 corpora (10-09 main vs 4d9592b5, semantic_edges): under a
second up to ~100k functions, +12.6 s on java (325k), +14.6 s on csharp
(451k), +174 s on the Linux kernel (784k functions, 28k sections), almost
all of the kernel's regression against v0.11.0.

A new boolean setting, doc_candidates (default true), and an optional
index_repository argument of the same name switch the scoring off: no
candidate rows are stored and nodes and edges are unchanged. The argument
wins over the setting. The index handler resolves the value once and
passes it to a daemon job or supervised worker as an argument, the same way
as the resource policy, so every route sees one decision; the session
auto-index reads the setting. With the switch off, a delta-route reindex
replaces the candidate rows it would otherwise keep, so turning it off
leaves no stale candidates. The default output is unchanged.

Tests (each fails on its assertion when the switch has no effect):
- pipeline_doc_candidates_off_stores_none_and_keeps_graph: no rows, same
  node and edge counts as the default run, which has rows;
- pipeline_doc_candidates_off_clears_rows_on_delta: a closure-repair
  reindex with the switch off removes the earlier rows;
- tool_index_repository_doc_candidates_switch: argument false -> none;
  setting default -> rows; setting false -> none; argument true over
  setting false -> rows.

Proof, release-built binaries on macOS arm64 (M5 Pro 18c/48 GB):
- django, main 4d9592b5 vs this change with defaults: nodes (63,441),
  edges (307,584) and doc_link_candidates rows (11,304) hash-identical;
- django with doc_candidates false: nodes and edges hash-identical, no
  candidate rows;
- Linux kernel with doc_candidates false: semantic_edges 17.9 s (191.9 s on
  main, 17.6 s before #2574), whole index 210.9 s (v0.11.0: ~234 s), no
  candidate rows.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-12 19:45:10 +02:00
Martin Vogel 8a7cbab13b Merge origin/main into feat/infra-graph
Brings in #2596 (MSan: hidden uninitialized reads) and #2068 (CodeAtlas
web).

README: main's CBM Atlas line and this branch's infrastructure-as-code
line are both kept.

tools/list metadata: main and this branch each stayed under the 20 KiB
discovery budget, but together they reached 20,809 bytes. The branch's
wording is shorter now (search_graph kind/namespace, one hint per trace
mode: 136 bytes less), and the reviewed budget is 21 KiB so the
topology/deploy/run modes keep their usage hints.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-12 19:07:18 +02:00
Martin Vogel 08e0474a36 Harden CBM Lens integration against current main
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-11 17:35:04 +02:00
Martin Vogel 0392068d49 Merge main into CBM Lens Beta
Reconcile the complete Atlas and Lens stream with current main while retaining both histories. Preserve architecture functionality, current process and watcher safeguards, test infrastructure, and dependency security updates. Add coverage for Git-environment isolation combined with child-local overrides.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-11 16:57:48 +02:00
Martin Vogel 75588a2b69 feat(semantic): doc candidates by format and position; whole files and home folders
Doc -> code candidates now carry a p judged for their kind, their document
format and where the document sits.

Format (sample 6, 234 blind-judged candidates): reStructuredText, AsciiDoc and
PDF sections each get their own curve (reST stored from tfidf 0.30, AsciiDoc
from 0.20, PDF not measured and not stored). A candidate that repeats an
exact MENTIONS link of the same section is not stored.

Position (sample 7, 490 blind-judged candidates from four monorepos): every
document gets a home folder -- its folder; a docs folder documents its
parent; a folder without code hands over to the nearest one with code; the
repository root means the whole project. Markdown candidates outside the
document's home were right 6 of 90 and are never stored; inside it they are
stored from tfidf 0.30 (0.33 / 0.53); for documents of the whole project
samples 4 and 7 pooled give 0.22 / 0.51 from 0.30.

New kinds, all in doc_link_candidates (evidence gains "kind" and
"position"; no new edge type, no schema change):
- local: up to two home functions ranked below the top five (0.32);
- file: a whole file, its vector the sum of its functions' terms and its
  definitions' names, config keys included, cut to 64 terms (0.30, from
  tfidf 0.40);
- folder: a README or index document -> its home folder (0.87).

get_code_snippet on a section lists every kind with its label;
get_file_outline shows the sections about the file or a folder holding it
(cbm_store_doc_candidates_for_path).

cbm_sem_p_2dp rounded 0.325 and 0.525 down (their float values sit 1.2e-6
below the half); its epsilon is 1e-4 on the x100 scale.

Replayed on the sample repositories, the build stores exactly the rows the
judged curves select (950 rows, 0 differences).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-09 02:55:31 +02:00
Martin Vogel 842535e7ae feat(semantic): doc section -> code candidates with a judged p
A documentation section that explains a function rarely names it, so
the deterministic doc links cannot connect them. The semantic pass now
ranks, for every Markdown section that can be about code, the functions
whose TF-IDF terms best match the section's heading and body, over the
functions' own corpus (function-pair scores are untouched):

- gate: no candidates for release-number or project-meta headings
  (changelog, licence, contributing, links, contents, install, ...),
  bodies under 20 words, or bodies that are mostly links;
- targets: functions and methods, never tests (by path or name);
- stored: a section's best five with tfidf >= 0.20, each with p, the
  probability that the section is about the function, from 274
  blind-judged candidates in five held-out repositories (three reading
  rounds): 0.36 below 0.30, 0.42 below 0.40, else 0.55. Below 0.20 the
  judged share was 0.06, so nothing is stored there.

These are candidates for an agent to verify, not graph edges: at best
about half are right, far below the bar for a link. They live in a side
table, doc_link_candidates (section and function qualified names, rank,
score, p, evidence), created when a generation is published, so older
indexes read as "no candidates". Full and legacy-partial reindexes
replace a project's rows; the delta route keeps the previous rows (its
proxy buffer has no section text or function tokens to recompute
them), and a row whose node is gone is skipped when read.

get_code_snippet shows them: on a Section, "possibly_about" (its
candidate functions); on a function or method, "possibly_described_in"
(the sections), at most five, highest p then score first, with a
candidates_note saying what they are.

Measured on fastapi (6,144 gated sections): 24,293 rows, identical to
the generator's dump; index time within noise; the database grows by
the table (37 MB there, with a 148-character project prefix on every
qualified name).

Tests: semantic:sem_doc_calibrated_p_bands,
store_arch:doc_candidates_replace_and_get (RED when a replace keeps old
rows), pipeline:pipeline_doc_candidates_published_and_kept_by_delta
(RED with test functions admitted, the heading gate off, the publish
write skipped, or the delta route replacing rows),
mcp:snippet_doc_candidates_both_directions (RED with stale rows shown).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-09 02:55:31 +02:00
Martin Vogel 79b29fc897 Merge pull request #2543 from DeusData/fix/c-typedefs-macros-enumerators
fix(extract): C typedefs become nodes; macros and enumerators get their own QNs
2026-10-09 01:54:47 +02:00
Martin Vogel 92b2dd13d7 Merge pull request #2493 from DeusData/fix/list-projects-empty-sort
fix: avoid null arguments for empty project and edge buffers
2026-10-08 01:48:52 +02:00
Martin Vogel 03193fd22c Merge pull request #2491 from DeusData/fix/search-code-match-root-check
fix(mcp): keep search matches within the resolved project root
2026-10-08 01:43:48 +02:00
Martin Vogel ea2a8f185f Merge main into fix/c-typedefs-macros-enumerators for the release batch
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-08 01:31:33 +02:00
Martin Vogel d050fcae35 Merge main into fix/c-typedefs-macros-enumerators for the release batch
Conflicts: internal/cbm/extract_defs.c includes (union of both sides); src/pipeline/registry.c keeps main's lang-aware index_under_name call, and the fence comment combines both facts (Rust cfg twins are variants of one QN; a C macro's #macro QN never reaches the registry).
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-07 18:28:07 +02:00
Martin Vogel fe63114808 Merge main into fix/search-code-match-root-check for the release batch
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-07 18:23:10 +02:00
Martin Vogel 8517ee5e75 Merge main into fix/list-projects-empty-sort for the release batch
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-07 18:20:26 +02:00
Martin Vogel 515670bff8 Merge main into feat/cross-repo-status for the release batch
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-07 18:19:35 +02:00
Martin Vogel 867e5f883d Merge origin/main into the smart-CI branch
Ten files changed on both sides; every conflict was a union of independent
additions:

- workflows (_lint.yml, _test.yml): keep the branch's lane `if:` and main's
  pinned ubuntu-24.04 runner with its reason.
- internal/cbm/cbm.h: main's callable-identity and module-doc fields plus the
  branch's configured-test fields.
- Makefile.cbm: both new test files; prod_lsp_all.o keeps main's
  .build-config dependency and the branch's coverage flags.
- scripts/test.sh: main's setup-scripts contract becomes Step 0y3, ahead of
  the branch's 0z series and the contracts-only exit.
- src/foundation/subprocess.c: main's cbm_posix_close_fds_from (it closes the
  error descriptor too).
- src/mcp/mcp.c: main's repository default base for detect_changes, with the
  early returns released through the branch's detect_release.
- src/pipeline/lsp_resolve.h, tests/test_main.c: both includes, suites and
  start-up steps (main's git environment reset first).
- scripts/memory-core-baseline.txt: recounted on the merged tree and lowered
  (mcp.c 773, config_toml_edit.c 73).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-05 18:53:37 +02:00
Martin Vogel c5abb64943 feat(test-impact): detect_changes scope:"tests" end to end
One request pins the change (merge base .. HEAD), builds the graph and the
runnable test registry of exactly the HEAD snapshot, seeds the graph from
the change, walks what depends on it and answers which tests to run
(cbm.test_impact). Missing or doubtful evidence never narrows: it becomes a
run-all answer that names why.

Snapshot (classified ledger -> frozen graph -> registry):
- one shared language classifier for discovery and pinned blobs (raw bytes
  on every platform); the classified ledger feeds the frozen build, which
  indexes exactly the listed files and records partial parses as per-file
  PARSE_GAP instead of refusing the graph;
- the pinned tree skips symlinks and submodule links (counted), as
  discovery never indexes them;
- the test model scopes uncertainty to the suites of its file (they run
  whole), reads line splices where they occur, treats a mid-file
  `#ifndef X` + `#define X` as an ordinary condition, and no longer reads a
  plain identifier named like a macro as an invocation. On this repository
  the registry is now narrowable and matches a text census exactly
  (8,365 cases, 141 runner suites).

Seeding and reach (port of the measured replay, rule B):
- hunk -> overlapping definitions, comment-only hunks dropped, pure
  deletions -> enclosing definition, no-definition hunks -> whole file,
  deleted names found by text, header changes propagated through the
  include closure and the headers' macros (pastes included), file-level
  escalation for unclassifiable header lines;
- inbound fixpoint walk over CALLS, ASYNC_CALLS, USAGE, CALL_REFERENCE,
  READS (+ routes); cases, suites and the runner's entry points are sinks;
  a reached runner main runs everything (RUNNER_REACHED);
- a parse gap whose text names a reached definition reaches the
  definition around it (or its file);
- macro-registered tests run their suites whole; cases and suites map to
  graph nodes by their start line.
The line patterns reproduce the reference regexes exactly on 1,383,850
lines of this repository and 37,167,926 kernel lines; on 24 replayed
changes the engine selects at least what the reference selected (13
identical, the rest only conservative supersets on the same graph).

Also:
- configured test declarations that cannot be mapped degrade their file
  (no configured roles, a test_declarations diagnostic) instead of
  aborting the whole index;
- the selector keeps other runners' suites out of the selection, and the
  result codec judges the model by narrowability like the selector;
- a change to .codebase-memory.json runs everything (built-in rule);
- .codebase-memory.json with the c-cbm preset and this repository's rules.

Gate fixes (suites, lint-ci, Windows cross-compile):
- the request runs on its own thread with a default-size stack (daemon
  tool calls run on 256 KiB threads, where the in-process build died);
- a request-supplied config_path is no longer followed by an unlink of an
  uninitialized path buffer;
- the inventory's frame-local reader no longer stays reachable from the
  caller's source after the filter call;
- FILE_ID_INFO needs _WIN32_WINNT >= 0x0602; the pinned-tree header pins
  it before any system header (toolchains defaulting lower failed);
- memory-core ratchet: the win_utf8 converters gain core-backed
  `_in(cls, ...)` forms over one implementation (the legacy names keep
  the C library for unmigrated callers), the Git facts module uses them,
  and the Windows spawn path releases everything through one failure
  exit; pipeline, extraction and config allocations that this work
  touched moved to the core in matched pairs; baselines tightened;
- the branch's C files formatted with the project's clang-format.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-05 02:15:08 +02:00
Martin Vogel 64f5e918bb Merge pull request #2256 from DeusData/distill/1245-int-arg-range
fix(mcp): an integer argument outside int range takes the default
2026-10-04 21:01:13 +02:00
Martin Vogel f7b541ee49 fix(mcp): search_code keeps only matches that resolve inside the root
search_code returns the lines its scan opened. The scoped file list is
built from the index, and an indexed path that now passes through a
directory link still looks like a regular file to lstat, so grep opened
and reported the link's target. Reading a result's source already went
through cbm_path_within_root (attach_result_source); the raw match and
the result row did not.

scan_and_classify_grep_matches now applies the same check to every
file in the scan stream, once per distinct file, and drops the hits of
a file that resolves outside the project root. Dropped hits are not
counted, like a path_filter miss. This covers the scoped and the
recursive scan on both platforms. Links that stay inside the root keep
working as before.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-04 19:09:00 +02:00
Martin Vogel 88380a94b1 Merge branch 'main' into feat/cross-repo-status 2026-10-04 19:02:12 +02:00
Martin Vogel 7bb1de0ed5 Merge pull request #2479 from DeusData/fix/workspace-resolved-home
fix(workspace): compare the home directory in its canonical form
2026-10-04 18:03:21 +02:00
Martin Vogel f40b1a564b Merge pull request #2475 from DeusData/fix/regex-compile-size-budget
fix(regex): size a pattern before compiling and refuse oversized ones
2026-10-04 18:03:16 +02:00
Martin Vogel 5c774862ac Merge pull request #2474 from DeusData/fix/search-arg-bounds
fix(mcp): clamp search_code context on both sides, add sink ceilings
2026-10-04 18:03:10 +02:00
Martin Vogel 1991bf109a Merge remote-tracking branch 'origin/main' into fix/c-typedefs-macros-enumerators
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>

# Conflicts:
#	internal/cbm/cbm.h
#	src/mcp/mcp.c
2026-10-04 17:18:01 +02:00
Martin Vogel b7f67c29a7 Merge pull request #2526 from DeusData/fix/underscore-project-discovery-v2
fix(mcp): discover projects with underscore-prefixed names
2026-10-04 16:24:34 +02:00
Martin Vogel 86f49a0f87 Merge pull request #2524 from DeusData/fix/issue-1366-search-hint-v2
fix(mcp): avoid misleading empty-search filter hints
2026-10-04 16:24:28 +02:00
Martin Vogel 266e2814e3 Merge pull request #2518 from DeusData/fix/search-code-scratch-isolation-v2
test(mcp): isolate search scratch cleanup fixtures
2026-10-04 16:24:15 +02:00
Martin Vogel 3a26acf402 Merge pull request #2496 from DeusData/fix/issue-1357-default-branch-v2
fix(mcp): detect changes from the repository default branch
2026-10-04 16:23:38 +02:00
Martin Vogel 5a9f6e7637 Merge pull request #2494 from DeusData/fix/issue-1300-silent-worker-exit
fix(index): report clean worker exits without a response
2026-10-04 16:23:27 +02:00
Martin Vogel f6fe11dde9 Merge pull request #2446 from DeusData/fix/issue-1690-skill-project-name
fix(mcp): resolve a directory project arg to its owning project (#1690)
2026-10-04 16:21:59 +02:00
Martin Vogel a245618a64 wip(ci): checkpoint hybrid test-impact implementation
Preserve the current selector, frozen-input inventory, result codec,
coverage collection, runner filtering, and isolated Windows venue work.
Component-level regression proofs are recorded in the PR handover.

The live classified provider, public execution integration, artifact
admission, fresh oracle/shadow evidence, and full platform gates remain
incomplete. This checkpoint does not enable or claim verified narrowing.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 23:55:18 +02:00
Martin Vogel a8abd97644 fix(mcp): discover projects with underscore-prefixed names
Use the shared exact-name database predicate for all five MCP cache
scans, including reindex root ownership. Preserve exclusions for the
two internal stores and cover listing, lookup, hints, and root reuse.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 20:49:09 +02:00
Martin Vogel 91117bdf89 fix(mcp): avoid misleading empty-search filter hints
Describe the current filters together when a structural search returns
no results, instead of blaming the label or name pattern.

Refs #1366

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 20:21:24 +02:00
Martin Vogel c38bfff4c2 test(mcp): isolate search scratch cleanup fixtures
Let each test server use a private scratch parent so cleanup checks cannot
count other processes' temporary files. Observe live scratch in the
hook-rejection fixture, preserve deadline assertions, and cover scratch
creation failure with a valid path filter for leak-sanitizer validation.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 19:15:19 +02:00
Martin Vogel fe8dd9df7e fix(mcp): release path filters on search setup errors
Free the compiled path_filter on missing pattern, missing project, unknown
project root, and failed scratch creation. Exercise the three argument and
project validation exits with a valid filter for leak-sanitizer coverage.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 19:05:00 +02:00
Martin Vogel 72f206d18f fix(mcp): resolve repository default for detect_changes
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-03 00:49:21 +02:00
Martin Vogel 25383bc7a4 fix: avoid null arguments in empty sort and edge-copy operations
An empty project cache leaves the list_projects record array unallocated.
Skip qsort when there is at most one record. Workers that emit no deferred
semantic edges likewise have no allocated source buffer; skip their
zero-length memcpy during the merge.

Add an empty-cache response regression covering JSON and tree output.
The Linux sanitizer proof rejects the original qsort call, and the
existing pipeline suite with 64 workers reports the original empty-worker
copy. Both diagnostics disappear with the guards restored.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-02 23:39:20 +02:00
Martin Vogel 44efa6281b fix(extract): C typedefs become nodes; macros and enumerators get their own QNs
In C-family code several different entities competed for one node, and
some had no node at all:

- A typedef name was never a definition: `type_definition` has no `name`
  field, so the class path dropped it. With an anonymous
  `typedef struct/enum {...} X;` the fields and enumerators went with it.
- A function behind an unknown leading macro (`API RetT name(...)`) was
  named after its return type, became a Method `RetT.name`, or was
  dropped, depending on the error-recovery shape.
- Every bodyless `struct X` / `enum X` (a parameter, a field type, a
  forward declaration) minted a Class/Enum node. In one file, or in a
  same-stem .h/.c pair, such a reference displaced the real definition.
- A `#define NAME` shared the QN of the function, type or enumerator
  called NAME, and the later line won: a namespace-rename macro replaced
  the typedef it renames, an `#else` stub macro replaced the function.
- Enumerators were named `<scope>.<Enum>.<CONST>`, although C and
  unscoped C++ enums put them in the enclosing scope.
- A definition repeated in several `#if` branches kept one span; the
  others left no trace.
- Braces split across `#if` branches lost whole functions, and a C
  keyword could surface as a function name (`if`).

Extraction:
- typedef names are definitions: `Type`, or `Class`/`Enum` with members
  for an anonymous `typedef struct/enum {...} X;`; an alias is dropped
  when the same file defines the tag of that name
- macro-prefixed functions get their real name in all three recovery
  shapes, consistently for defs, call scopes, parameters and the C LSP
- a bodyless tag is a reference and creates no node; a definition head
  left as loose ERROR tokens (`struct NAME {`) is recovered
- a C keyword is never a function name
- a first-branch projection (one branch per `#if` group, positions
  unchanged) is parsed when the raw parse lost structure wholesale, and
  only functions missing from the raw result are adopted from it
- macro-wrapped enumerator lists yield one constant per slot

Identity (semantic index version 4; an existing index is rebuilt once):
- a C-preprocessor macro's QN is `<module>.<NAME>#macro` (C, C++, CUDA,
  GLSL, Objective-C, ISPC); name and label are unchanged. Resolvers
  prefer a definition and use the macro only when no definition of that
  name is visible (LSP target lookup, trace_path, get_code_snippet)
- enumerators of C enums and of unscoped C++/Objective-C enums are
  `<enclosing scope>.<CONST>`; `enum class` stays nested; `parent_class`
  names the enum
- a node whose file defines its QN more than once under one label
  carries `variants`, the line spans of all those definitions (`#if`
  twins, per-platform macro redefinitions, C++ overloads)

Full-text search indexes a macro's QN without the fence, so macro rows
score as before.

Measured on redis and curl against the parent commit: nodes 38,625 ->
40,484 and 28,180 -> 29,750; Type nodes 0 -> 573 and 0 -> 193; phantom
Class nodes from references 202 and 821 removed; functions lost to a
same-named macro 45 and 41 restored; curl functions with no node 11 ->
0; nodes of non-C-family files unchanged by QN. Of 174 audited Doxygen
references in xxhash, 174 now reach the right entity (64 before). Index
time is unchanged within noise (+2% pipeline time for 5% more nodes).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-02 06:37:36 +02:00
Martin Vogel 2e6dc0877c fix(workspace): compare the home directory in its canonical form
cbm_workspace_home_dir() returned the raw HOME (or USERPROFILE) string,
while cbm_workspace_classify_root() compares it against a canonical,
link-resolved path. Where the home directory is reached through a link
(/home kept on another volume, a macOS firmlink, a HOME that is itself a
link) the two spellings differ and the home rule never fired, so the home
directory was not classified as the home directory.

The helper now resolves the value through cbm_canonical_path, the same
resolver every caller applies to the path it classifies, and falls back
to the raw value when the directory cannot be resolved. The result lives
in a per-thread buffer recomputed on each call, as cbm_resolve_cache_dir
does, so a changed environment is seen at once. The environment is read
with cbm_safe_getenv so a non-ASCII USERPROFILE arrives as UTF-8.

The ancestor comparison now treats "/" and "\" as the same separator: on
Windows the resolver returns backslashes while some callers normalize to
forward slashes, and both spell one directory.

Two tests cover the helper: one with a plain temp directory (already a
firmlink on macOS), one with a home reached through a symbolic link
(POSIX; creating a link needs a privilege on Windows). The existing
explicit-approval test in the mcp suite now presents its session root in
resolved form, as the daemon does; with the raw spelling it would have
passed as an ordinary root and stopped exercising the approval path.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-02 05:34:41 +02:00
Martin Vogel 9db7de7bae fix(regex): size a pattern before compiling and refuse oversized ones
cbm_regcomp() handed every pattern straight to the platform compiler
(libc regcomp on POSIX, the vendored TRE on Windows). Both expand bounded
repetition at compile time, so the compiled size of a pattern is not
proportional to its length. Measured on macOS libc (TRE-derived) with
REG_EXTENDED|REG_NOSUB, the compiled form costs about 0.6 KB per expanded
atom (1.1 KB with submatch tracking, 1.7 KB with REG_ICASE), a K-way
alternation adds about 70 B x K^2 for its position sets, and an
alternation under an interval pays that for every copy.

The wrapper now sizes a pattern in one linear pass before compiling it:
an atom costs 1, a group costs its content, an interval multiplies the
element it applies to by its upper bound, and a K-way alternation is
charged K^2/8 on top of its branches. Arithmetic saturates and group
nesting is bounded. A pattern longer than 32768 bytes, or whose estimate
exceeds 32768 units, is refused with CBM_REG_ETOOBIG before anything is
allocated. The heaviest accepted compile is a repeated alternation at
about 30 MB with REG_NOSUB (about 90 MB under the ICASE-plus-submatch
flag set no call site uses). Ordinary intervals, the pipeline's fixed
patterns and an alternation of 400 twenty-character identifiers remain
accepted.

The refusal reads as a normal compile error at every call site.
search_code now reports an unusable path_filter as a tool error instead
of silently dropping the filter, search_graph reports a failed row scan
instead of returning an empty result, and query_graph carries the reason
in the result's warning field; all three name it.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-02 01:55:34 +02:00
Martin Vogel 02bc9f2516 fix(mcp): clamp search_code context on both sides, add sink ceilings
The search_code `context` argument had no upper bound while every sibling
sizing argument (result_limit, match_limit, source_max_lines, raw_limit,
directory_limit) is clamped on both sides. A large value made every hit
return its file from the match to the end, and the window arithmetic in
attach_result_source could overflow int. `context` now gets the same
0..200 clamp as source_max_lines (MCP_SEARCH_CONTEXT_MAX_LINES), the
window computation is overflow-safe on its own, and the tool schema states
default, minimum and maximum like its siblings. Values inside the bound
return exactly the lines they did before.

Sink ceilings: cbm_cypher_execute clamps a caller-supplied max_rows to
CYPHER_RESULT_CEILING (nothing above it is ever materialized) and
execute_single checks the binding array it sizes from that value instead
of writing through a failed allocation.

Tests pin the context window and the extreme values (INT_MAX, negative),
the query_graph max_rows ceiling, the search_graph limit ceiling, the
trace cursor token truncated after the leg character, the quote rejection
in file_pattern, and the engine-side max_rows clamp.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-02 01:35:03 +02:00
Martin Vogel fc70534e81 Merge pull request #2425 from DeusData/fix/trace-path-qn-fallback-leak
fix(mcp): free the empty name-lookup result before trace_path's QN fallback
2026-10-02 00:06:01 +02:00
Martin Vogel abf00764a7 fix(mcp): resolve a directory project arg to its owning project (#1690)
An agent in a checkout whose directory name differs from the repository
name (git clone .../repo_name.git some_name) could not find the indexed
project. The installed skill only said "list_projects - check if project
is indexed", so Codex and Copilot guessed the project from the repo name,
got "project not found" and stopped using the graph. Passing the working
directory did not help whenever it was not exactly the indexed root: a
path was only ever turned into the path-DERIVED name, which misses a
checkout indexed under an explicit name (the stored identity, see #1660)
and every directory below an indexed root.

Fix:
- mcp: a path-shaped project keeps the derived name when an index exists
  under it (unchanged fast path); otherwise it resolves to the indexed
  project whose stored root_path owns the directory. The deepest owning
  root wins; two projects owning that root stay unresolved, so the
  not-found error lists every project instead of guessing. Reuses the
  list_projects identity reader and the canonical-path containment helpers.
- mcp: the project-not-found hint says how to pick the project (the name
  whose root_path contains the working directory, or that absolute
  directory; never a repo or folder name), so an agent that guessed can
  recover.
- cli: the SKILL.md every skill client installs (Codex, Copilot and the
  rest), the shared agent instructions and the Aider CLI instructions say
  the same thing.

Proof (dev binary, synthetic HOME; repo_name cloned as some_name and
indexed by path; a second checkout other_dir indexed with name=my-alias):
  before: project=<other_dir>        -> project not found
          project=<some_name>/pkg    -> project not found
  after:  project=<other_dir>        -> my-alias (index_status agrees)
          project=<some_name>/pkg    -> the some_name project
  unchanged: the checkout root path and the explicit name resolve; the
  unindexed sibling some_name_x stays not found; a guessed "repo_name"
  stays not found and now carries the how-to-pick hint.

Tests:
- mcp tool_project_path_resolves_owning_project_issue1690: an explicitly
  named root and its subdirectory resolve; normal naming and similar
  names (some_name2, some_name_x) are not confused; two owners of one
  root are never guessed; a guessed repo name gets the hint. RED 3x
  before, green after, RED again when the production change is reverted
  (the hint check also goes RED on its own revert).
- cli cli_guidance_resolves_project_by_root_path_issue1690: pins the
  instruction in the skill, agent-instructions and Aider variants.

Fixes #1690

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-09-30 23:14:32 +02:00
Martin Vogel e4f9735dea feat(cross-repo): report run status and skipped legacy stores (#2133)
Two follow-ups to the #2133 wildcard fix, both about what cross-repo
intelligence tells the caller.

1. "Never run" vs "ran, no links". An empty CROSS_* set used to mean
   either one, and no output surface could tell them apart. Every run now
   records a marker in the SOURCE store's store_meta
   (key cross_repo_last_run:<project>, same per-project key pattern as
   coverage_shadow_fp:<project>) once the previous CROSS_* generation has
   been cleaned: last_run_at, outcome (complete|cancelled|failed),
   targets, projects_scanned, total_cross_edges, skipped_projects.
   index_status and the UI layout (next to linked_projects) now carry a
   `cross_repo` object: {"status":"never_run"} or {"status":"ran", ...}.
   The marker lives beside the edges it describes, so a reindex that
   rebuilds the store drops both together. No new database files and no
   new freshness key.

   New store API cbm_store_meta_get/put. put seeds a missing store_meta
   through the generation path, because creating the table without
   db_uid/mutation_gen would make cbm_store_generation() report malformed
   metadata.

2. ["*"] skips a pre-#768 store (since #2343) but only logged it. The
   result now names each one, and the MCP response lists them:
   skipped_projects: [{name, reason:"pre_768_schema",
   hint:"reindex this project"}] (only emitted when non-empty). The
   cross_repo.project_unusable log line is unchanged.

cr_project_exists() is split into cr_project_state() (usable / missing /
legacy) so that the enumerator can tell a legacy store apart from a
foreign .db file. New allocations go through mem_core.

Refs #2133
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-09-30 22:40:38 +02:00
Martin Vogel 364dd6a99b test(mcp): compare the #2134 root with forward slashes on Windows
tool_index_repository_reuses_existing_project_for_root_issue2134 counts
how often the canonical repo root occurs in list_projects. On Windows,
cbm_canonical_path returns "C:\Users\...", while the stored root_path is
"C:/Users/...", so the count was 0 and the test failed on the CLANG64
leg (test_mcp.c:8448: owners == 0, expected 1).

Normalize the expected root with cbm_normalize_path_sep, a no-op on
POSIX, before counting.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-09-30 22:26:34 +02:00
Martin Vogel 1f0daaa915 fix(mcp): keep #2134 root-owner reuse out of cross-repo mode; portable test path
Linux, MSan, TSan and diag CI failed in mcp_mutation_guard:
tool_cross_repo_missing_inputs_fail_without_creating_ghost_databases
ASSERT(source_failed). handle_index_repository resolved the root owner
before dispatching cross-repo-intelligence mode. That test registers its
named target with the source's own root, so the unindexed source adopted
existing-cross-target as its project (log: index.root_owner_reused
project=existing-cross-target), and the missing source was no longer
reported. Cross-repo mode reads an existing source index and never writes
one, so the #2134 reuse now runs only on the re-index path, after that
dispatch. macOS CI stayed green because cbm_tmpdir() is /tmp, a symlink
to /private/tmp there, so the canonical repo_path never equalled the
fixture's stored root; with the fixture path canonicalized, the failure
reproduced 3/3 on macOS and passes 3/3 with this change.

The #2134 test itself called realpath() into a 1 KiB buffer. glibc's
FORTIFY check aborts on that ("buffer overflow detected", a SIGABRT of the
mcp suite on the ubuntu 2/3 shards), and MinGW has no realpath at all
(Windows compile error). It now uses cbm_canonical_path with a 4 KiB
buffer, the same canonicalizer production uses.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-09-30 22:26:34 +02:00
Martin Vogel 155d147e78 fix(mcp): reuse the project that owns a root on unnamed re-index (#2134)
index_repository without `name` derived the project key from the path
alone. When the root had first been indexed under an explicit name, a
later unnamed re-index forked a second index (same root_path,
path-derived name) and left the original untouched, so the stale index
kept being served while the call reported success.

Resolve the key from the indexes on disk before any work starts:
- the path-derived project exists -> keep it (unchanged behavior);
- exactly one other project owns the canonical root -> adopt its name
  and update it in place, so existing indexes are never orphaned;
- several projects own the root -> fail loudly, name them and ask for
  `name` instead of guessing or forking again;
- none -> first index under the derived name, as before.

The resolved name is written into the args handed to the daemon job
coordinator and the supervised worker, so the project lease key and the
index actually written stay the same project.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-09-30 22:26:15 +02:00
Martin Vogel 083bc99d80 Merge pull request #2404 from DeusData/fix/issue-2118
fix(mcp): annotate get_file_outline and ingest_traces as read-only (#2118)
2026-09-30 22:21:06 +02:00
Martin Vogel cb251ed472 Merge pull request #2357 from DeusData/fix/issue-2144
feat(mcp): opt-in async index_repository with status polling (#2144)
2026-09-30 22:20:46 +02:00
Martin Vogel e2f9fcc399 Merge pull request #2334 from DeusData/fix/issue-1951
fix(mcp): translate Git-root paths for subdirectory projects in detect_changes (#1951)
2026-09-30 22:19:07 +02:00