Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge PR #87: feat(k8s) — Kubernetes and Kustomize indexing (66 languages)

Martin Vogelfad0ff7f9004
diff --cc CONTRIBUTING.md
index 1cb9d57dd,3f73f59cf..ac0981b3f
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@@ -84,25 -85,27 +85,42 @@@ Language support is split between two l
4. Add a test case in `tests/test_pipeline.c` for integration-level fixes
5. Verify with a real open-source repo
+### Infrastructure Languages (Infra-Pass Pattern)
+
+Languages like **Dockerfile**, **docker-compose**, **Kubernetes manifests**, and **Kustomize** do not require a new tree-sitter grammar. Instead they follow an *infra-pass* pattern, reusing the existing tree-sitter YAML grammar where applicable:
+
+1. **Detection helpers** in `src/pipeline/pass_infrascan.c` — functions like `cbm_is_dockerfile()`, `cbm_is_k8s_manifest()`, `cbm_is_kustomize_file()` identify files by name and/or content heuristics (e.g., presence of `apiVersion:`).
+2. **Custom extractors** in `internal/cbm/extract_k8s.c` — tree-sitter-based parsers that walk the YAML AST (using the tree-sitter YAML grammar) and populate `CBMFileResult` with imports and definitions.
+3. **Pipeline pass** (`pass_k8s.c`, `pass_infrascan.c`) — calls the extractor and emits graph nodes/edges. K8s manifests emit `Resource` nodes; Kustomize files emit `Module` nodes with `IMPORTS` edges to referenced resource files.
+
+**When adding a new infrastructure language:**
+- Add a detection helper (`cbm_is_<lang>_file()`) in `pass_infrascan.c` or a new `pass_<lang>.c`.
+- Add the `CBM_LANG_<LANG>` enum value in `internal/cbm/cbm.h` and a row in the language table in `lang_specs.c`.
+- Write a custom extractor that returns `CBMFileResult*` — do not add a tree-sitter grammar.
+- Register the pass in `pipeline.c`.
+- Add tests in `tests/test_pipeline.c` following the `TEST(infra_is_dockerfile)` and `TEST(k8s_extract_manifest)` patterns.
+
+ ## Commit Format
+
+ Use conventional commits: `type(scope): description`
+
+ | Type | When to use |
+ |------|-------------|
+ | `feat` | New feature or capability |
+ | `fix` | Bug fix |
+ | `test` | Adding or updating tests |
+ | `refactor` | Code change that neither fixes a bug nor adds a feature |
+ | `perf` | Performance improvement |
+ | `docs` | Documentation only |
+ | `chore` | Build scripts, CI, dependency updates |
+
+ Examples: `fix(store): set busy_timeout before WAL`, `feat(cli): add --progress flag`
+
## Pull Request Guidelines
+ - **One issue per PR.** Each PR must address exactly one bug, one feature, or one refactor. Do not bundle multiple fixes or feature additions into a single PR. If your change touches multiple areas, split it into separate PRs.
+ - **Open an issue first.** Every PR should reference a tracking issue (`Fixes #N` or `Closes #N`). This ensures the change is discussed before code is written.
- **C code only** — this project was rewritten from Go to pure C in v0.5.0. Go PRs will be acknowledged and potentially ported, but cannot be merged directly.
- - One logical change per PR — don't bundle unrelated features
- Include tests for new functionality
- Run `scripts/test.sh` and `scripts/lint.sh` before submitting
- Keep PRs focused — avoid unrelated reformatting or refactoring
diff --cc README.md
index 2aff6faef,c9e18baa6..4c3c566f3
--- a/README.md
+++ b/README.md
@@@ -1,8 -1,18 +1,18 @@@
# codebase-memory-mcp
+ [![GitHub Release](https://img.shields.io/github/v/release/DeusData/codebase-memory-mcp?style=flat&color=blue)](https://github.com/DeusData/codebase-memory-mcp/releases/latest)
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
+ [![CI](https://img.shields.io/github/actions/workflow/status/DeusData/codebase-memory-mcp/dry-run.yml?label=CI)](https://github.com/DeusData/codebase-memory-mcp/actions/workflows/dry-run.yml)
+ [![Tests](https://img.shields.io/badge/tests-2042_passing-brightgreen)](https://github.com/DeusData/codebase-memory-mcp)
-[![Languages](https://img.shields.io/badge/languages-64-orange)](https://github.com/DeusData/codebase-memory-mcp)
++[![Languages](https://img.shields.io/badge/languages-66-orange)](https://github.com/DeusData/codebase-memory-mcp)
+ [![Agents](https://img.shields.io/badge/agents-10-purple)](https://github.com/DeusData/codebase-memory-mcp)
+ [![Pure C](https://img.shields.io/badge/pure_C-zero_dependencies-blue)](https://github.com/DeusData/codebase-memory-mcp)
+ [![Platform](https://img.shields.io/badge/macOS_%7C_Linux_%7C_Windows-supported-lightgrey)](https://github.com/DeusData/codebase-memory-mcp/releases/latest)
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/DeusData/codebase-memory-mcp/badge)](https://scorecard.dev/viewer/?uri=github.com/DeusData/codebase-memory-mcp)
+
**The fastest and most efficient code intelligence engine for AI coding agents.** Full-indexes an average repository in milliseconds, the Linux kernel (28M LOC, 75K files) in 3 minutes. Answers structural queries in under 1ms. Ships as a single static binary for macOS, Linux, and Windows — download, run `install`, done.
--High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-sitter/) AST analysis across all 64 languages, enhanced with LSP-style hybrid type resolution for Go, C, and C++ (more languages coming soon) — producing a persistent knowledge graph of functions, classes, call chains, HTTP routes, and cross-service links. 14 MCP tools. Zero dependencies. Plug and play across 10 coding agents.
++High-quality parsing through [tree-sitter](https://tree-sitter.github.io/tree-sitter/) AST analysis across all 66 languages, enhanced with LSP-style hybrid type resolution for Go, C, and C++ (more languages coming soon) — producing a persistent knowledge graph of functions, classes, call chains, HTTP routes, and cross-service links. 14 MCP tools. Zero dependencies. Plug and play across 10 coding agents.
<p align="center">
<img src="docs/graph-ui-screenshot.png" alt="Graph visualization UI showing the codebase-memory-mcp knowledge graph" width="800">
@@@ -14,10 -24,10 +24,11 @@@
- **Extreme indexing speed** — Linux kernel (28M LOC, 75K files) in 3 minutes. RAM-first pipeline: LZ4 compression, in-memory SQLite, fused Aho-Corasick pattern matching. Memory released after indexing.
- **Plug and play** — single static binary for macOS (arm64/amd64), Linux (arm64/amd64), and Windows (amd64). No Docker, no runtime dependencies, no API keys. Download → `install` → restart agent → done.
--- **64 languages** — vendored tree-sitter grammars compiled into the binary. Nothing to install, nothing that breaks.
++- **66 languages** — vendored tree-sitter grammars compiled into the binary. Nothing to install, nothing that breaks.
- **120x fewer tokens** — 5 structural queries: ~3,400 tokens vs ~412,000 via file-by-file search. One graph query replaces dozens of grep/read cycles.
- **10 agents, one command** — `install` auto-detects Claude Code, Codex CLI, Gemini CLI, Zed, OpenCode, Antigravity, Aider, KiloCode, VS Code, and OpenClaw — configures MCP entries, instruction files, and pre-tool hooks for each.
- **Built-in graph visualization** — 3D interactive UI at `localhost:9749` (optional UI binary variant).
++- **Infrastructure-as-code indexing** — Dockerfiles, Kubernetes manifests, and Kustomize overlays indexed as graph nodes with cross-references. `Resource` nodes for K8s kinds, `Module` nodes for Kustomize overlays with `IMPORTS` edges to referenced resources.
- **14 MCP tools** — search, trace, architecture, impact analysis, Cypher queries, dead code detection, cross-service HTTP linking, ADR management, and more.
## Quick Start
@@@ -313,7 -341,7 +342,7 @@@ SQLite databases stored at `~/.cache/co
## Language Support
--64 languages. Benchmarked against 64 real open-source repositories (78 to 49K nodes):
++66 languages. Benchmarked against 64 real open-source repositories (78 to 49K nodes):
| Tier | Score | Languages |
|------|-------|-----------|
@@@ -338,7 -366,7 +367,7 @@@ src
traces/ Runtime trace ingestion
ui/ Embedded HTTP server + 3D graph visualization
foundation/ Platform abstractions (threads, filesystem, logging, memory)
--internal/cbm/ Vendored tree-sitter grammars (64 languages) + AST extraction engine
++internal/cbm/ Vendored tree-sitter grammars (66 languages) + AST extraction engine
```
## License
diff --cc server.json
index a208b52a8,2b6e81083..e85fc90e1
--- a/server.json
+++ b/server.json
@@@ -2,7 -2,7 +2,7 @@@
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.DeusData/codebase-memory-mcp",
"title": "Codebase Memory",
- "description": "Persistent codebase knowledge graph — 35 languages, sub-ms queries, 99% fewer tokens than grep. Survives session restarts and context compaction.",
- "description": "Persistent codebase knowledge graph — 64 languages, sub-ms queries, 99% fewer tokens than grep. Survives session restarts and context compaction.",
++ "description": "Persistent codebase knowledge graph — 66 languages, sub-ms queries, 99% fewer tokens than grep. Survives session restarts and context compaction.",
"repository": {
"url": "https://github.com/DeusData/codebase-memory-mcp",
"source": "github"
diff --cc src/pipeline/pass_infrascan.c
index 1e30b71f7,30c47d95e..d19439e9e
--- a/src/pipeline/pass_infrascan.c
+++ b/src/pipeline/pass_infrascan.c
@@@ -192,27 -192,6 +192,31 @@@ bool cbm_is_env_file(const char *name)
return false;
}
+bool cbm_is_kustomize_file(const char *name) {
+ if (!name) {
+ return false;
+ }
+ char lower[256];
+ to_lower(name, lower, sizeof(lower));
- return (strcmp(lower, "kustomization.yaml") == 0 || strcmp(lower, "kustomization.yml") == 0);
++ if (strcmp(lower, "kustomization.yaml") == 0) {
++ return true;
++ }
++ return strcmp(lower, "kustomization.yml") == 0;
+}
+
+// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
+bool cbm_is_k8s_manifest(const char *name, const char *content) {
+ if (!name || !content || cbm_is_kustomize_file(name)) {
+ return false;
+ }
- char buf[4097];
++ enum { K8S_PEEK_SZ = 4097 };
++ char buf[K8S_PEEK_SZ];
+ size_t n = strnlen(content, 4096);
+ memcpy(buf, content, n);
+ buf[n] = '\0';
+ return ci_strstr(buf, "apiVersion:") != NULL;
+}
+
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
bool cbm_is_shell_script(const char *name, const char *ext) {
(void)name;
diff --cc src/pipeline/pass_k8s.c
index 03cc8254b,000000000..b0a6aa5c3
mode 100644,000000..100644
--- a/src/pipeline/pass_k8s.c
+++ b/src/pipeline/pass_k8s.c
@@@ -1,239 -1,0 +1,240 @@@
+/*
+ * pass_k8s.c — Pipeline pass for Kubernetes manifest and Kustomize overlay processing.
+ *
+ * For each discovered YAML file:
+ * 1. Check if it is a kustomize overlay (kustomization.yaml / kustomization.yml)
+ * → emit a Module node and IMPORTS edges for each resources/bases/patches entry
+ * 2. Else if it is a generic k8s manifest (apiVersion: detected)
- * → emit one Resource node per file (first document only — multi-document YAML is not yet supported)
++ * → emit one Resource node per file (first document only — multi-document YAML is not yet
++ * supported)
+ *
+ * Depends on: pass_infrascan.c (cbm_is_kustomize_file, cbm_is_k8s_manifest, cbm_infra_qn),
+ * extraction layer (cbm.h), graph_buffer, pipeline internals.
+ */
+#include "pipeline/pipeline.h"
+#include "pipeline/pipeline_internal.h"
+#include "graph_buffer/graph_buffer.h"
+#include "discover/discover.h"
+#include "foundation/log.h"
+#include "foundation/compat.h"
+#include "cbm.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+/* ── Internal helpers ────────────────────────────────────────────── */
+
+/* Read entire file into heap-allocated buffer. Returns NULL on error.
+ * Caller must free(). Sets *out_len to byte count. */
+static char *k8s_read_file(const char *path, int *out_len) {
+ FILE *f = fopen(path, "rb");
+ if (!f) {
+ return NULL;
+ }
+
+ (void)fseek(f, 0, SEEK_END);
+ long size = ftell(f);
+ (void)fseek(f, 0, SEEK_SET);
+
+ if (size <= 0 || size > (long)100 * 1024 * 1024) {
+ (void)fclose(f);
+ return NULL;
+ }
+
+ char *buf = malloc(size + 1);
+ if (!buf) {
+ (void)fclose(f);
+ return NULL;
+ }
+
+ size_t nread = fread(buf, 1, size, f);
+ (void)fclose(f);
+ // NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
+ buf[nread] = '\0';
+ *out_len = (int)nread;
+ return buf;
+}
+
+/* Format int to string for logging. Thread-safe via TLS. */
+static const char *itoa_k8s(int val) {
+ static CBM_TLS char bufs[4][32];
+ static CBM_TLS int idx = 0;
+ int i = idx;
+ idx = (idx + 1) & 3;
+ snprintf(bufs[i], sizeof(bufs[i]), "%d", val);
+ return bufs[i];
+}
+
+/* Extract the basename of a path (pointer into the string; no allocation). */
+static const char *k8s_basename(const char *path) {
+ const char *p = strrchr(path, '/');
+ return p ? p + 1 : path;
+}
+
+/* ── Kustomize handler ───────────────────────────────────────────── */
+
+static void handle_kustomize(cbm_pipeline_ctx_t *ctx, const char *path, const char *rel_path,
+ CBMFileResult *result) {
+ /* Emit Module node for this kustomize overlay file */
+ char *mod_qn = cbm_infra_qn(ctx->project_name, rel_path, "kustomize", NULL);
+ if (!mod_qn) {
+ return;
+ }
+
+ // NOLINTNEXTLINE(misc-include-cleaner)
+ int64_t mod_id = cbm_gbuf_upsert_node(ctx->gbuf, "Module", k8s_basename(rel_path), mod_qn,
+ rel_path, 1, 0, "{\"source\":\"kustomize\"}");
+ free(mod_qn);
+
+ if (mod_id <= 0) {
+ return;
+ }
+
+ /* If we have a cached extraction result, emit IMPORTS edges for
+ * resources/bases/patches/components entries */
+ int import_count = 0;
+ CBMFileResult *res = result;
+ bool allocated = false;
+
+ if (!res) {
+ /* Fall back to re-extraction */
+ int src_len = 0;
+ char *source = k8s_read_file(path, &src_len);
+ if (source) {
+ res = cbm_extract_file(source, src_len, CBM_LANG_KUSTOMIZE, ctx->project_name, rel_path,
+ CBM_EXTRACT_BUDGET, NULL, NULL);
+ free(source);
+ allocated = true;
+ }
+ }
+
+ if (res) {
+ for (int j = 0; j < res->imports.count; j++) {
+ CBMImport *imp = &res->imports.items[j];
+ if (!imp->module_path) {
+ continue;
+ }
+
+ /* Compute target file QN */
+ char *target_qn =
+ cbm_pipeline_fqn_compute(ctx->project_name, imp->module_path, "__file__");
+ if (!target_qn) {
+ continue;
+ }
+
+ const cbm_gbuf_node_t *target = cbm_gbuf_find_by_qn(ctx->gbuf, target_qn);
+ free(target_qn);
+
+ if (target) {
+ cbm_gbuf_insert_edge(ctx->gbuf, mod_id, target->id, "IMPORTS",
+ "{\"via\":\"kustomize\"}");
+ import_count++;
+ }
+ }
+
+ if (allocated) {
+ cbm_free_result(res);
+ }
+ }
+
+ cbm_log_info("pass.k8s.kustomize", "file", rel_path, "imports", itoa_k8s(import_count));
+}
+
+/* ── K8s manifest handler ────────────────────────────────────────── */
+
+/* source/src_len are the already-read file bytes (caller retains ownership and
+ * must free after this call returns). */
+static void handle_k8s_manifest(cbm_pipeline_ctx_t *ctx, const char *path, const char *rel_path,
+ const char *source, int src_len) {
+ (void)path; /* retained for symmetry; source is always provided now */
+ int resource_count = 0;
+
+ CBMFileResult *res = cbm_extract_file(source, src_len, CBM_LANG_K8S, ctx->project_name,
+ rel_path, CBM_EXTRACT_BUDGET, NULL, NULL);
+ if (!res) {
+ return;
+ }
+
+ /* Compute file node QN for DEFINES edges */
+ char *file_qn = cbm_pipeline_fqn_compute(ctx->project_name, rel_path, "__file__");
+ const cbm_gbuf_node_t *file_node = file_qn ? cbm_gbuf_find_by_qn(ctx->gbuf, file_qn) : NULL;
+ free(file_qn);
+
+ for (int d = 0; d < res->defs.count; d++) {
+ CBMDefinition *def = &res->defs.items[d];
+ if (!def->label || strcmp(def->label, "Resource") != 0) {
+ continue;
+ }
+ if (!def->name || !def->qualified_name) {
+ continue;
+ }
+
+ // NOLINTNEXTLINE(misc-include-cleaner)
+ int64_t node_id =
+ cbm_gbuf_upsert_node(ctx->gbuf, "Resource", def->name, def->qualified_name, rel_path,
+ (int)def->start_line, (int)def->end_line, "{\"source\":\"k8s\"}");
+
+ /* DEFINES edge: File → Resource */
+ if (file_node && node_id > 0) {
+ cbm_gbuf_insert_edge(ctx->gbuf, file_node->id, node_id, "DEFINES", "{}");
+ }
+
+ resource_count++;
+ }
+
+ cbm_free_result(res);
+
+ cbm_log_info("pass.k8s.manifest", "file", rel_path, "resources", itoa_k8s(resource_count));
+}
+
+/* ── Pass entry point ────────────────────────────────────────────── */
+
+// NOLINTNEXTLINE(misc-include-cleaner) — cbm_file_info_t provided by standard header
+int cbm_pipeline_pass_k8s(cbm_pipeline_ctx_t *ctx, const cbm_file_info_t *files, int file_count) {
+ cbm_log_info("pass.start", "pass", "k8s", "files", itoa_k8s(file_count));
+
+ cbm_init();
+
+ int kustomize_count = 0;
+ int manifest_count = 0;
+
+ for (int i = 0; i < file_count; i++) {
+ if (cbm_pipeline_check_cancel(ctx)) {
+ return -1;
+ }
+
+ const char *path = files[i].path;
+ const char *rel = files[i].rel_path;
+ CBMLanguage lang = files[i].language;
+ const char *base = k8s_basename(rel);
+
+ CBMFileResult *cached =
+ (ctx->result_cache && ctx->result_cache[i]) ? ctx->result_cache[i] : NULL;
+
+ if (cbm_is_kustomize_file(base)) {
+ handle_kustomize(ctx, path, rel, cached);
+ kustomize_count++;
+ } else if (lang == CBM_LANG_YAML || lang == CBM_LANG_K8S) {
+ /* Read source once to classify (and reuse for uncached extraction). */
+ int src_len = 0;
+ char *source = k8s_read_file(path, &src_len);
+ if (source) {
+ if (cbm_is_k8s_manifest(base, source)) {
+ /* Always re-extract with CBM_LANG_K8S regardless of any cached
+ * result: cached results were produced during the parallel YAML
+ * pass and contain no "Resource" definitions. Pass the already-
+ * read source buffer so handle_k8s_manifest does not re-read. */
+ (void)cached; /* cached YAML result intentionally discarded */
+ handle_k8s_manifest(ctx, path, rel, source, src_len);
+ manifest_count++;
+ }
+ free(source);
+ }
+ }
+ }
+
+ cbm_log_info("pass.done", "pass", "k8s", "kustomize", itoa_k8s(kustomize_count), "manifests",
+ itoa_k8s(manifest_count));
+ return 0;
+}