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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Add build scripts, fix GCC warnings, unify CI workflows
Martin Vogelfd1640ec2982
diff --git a/.github/workflows/dry-run.yml b/.github/workflows/dry-run.ymlindex 17b8a4de7..4491a0250 100644--- a/.github/workflows/dry-run.yml+++ b/.github/workflows/dry-run.yml@@ -7,7 +7,7 @@ permissions:contents: readjobs:- # ── Step 1: Lint ──────────────────────────────────────────────+ # ── Step 1: Lint (clang-format + cppcheck) ───────────────────lint:runs-on: ubuntu-lateststeps:@@ -16,7 +16,6 @@ jobs:- name: Install build depsrun: sudo apt-get update && sudo apt-get install -y libsqlite3-dev zlib1g-dev cmake- # LLVM 20 (clang-format + clang-tidy) from apt.llvm.org- name: Install LLVM 20run: |wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc@@ -24,7 +23,6 @@ jobs:sudo apt-get updatesudo apt-get install -y clang-format-20- # cppcheck 2.20.0 from source (cached)- uses: actions/cache@v4id: cppcheck-cachewith:@@ -42,18 +40,10 @@ jobs:- name: Add cppcheck to PATHrun: echo "/opt/cppcheck/bin" >> "$GITHUB_PATH"- - name: Verify versions- run: |- echo "clang-format: $(clang-format-20 --version)"- echo "cppcheck: $(cppcheck --version)"-- - name: clang-format- run: make -f Makefile.cbm lint-format CLANG_FORMAT=clang-format-20-- - name: cppcheck- run: make -f Makefile.cbm lint-cppcheck+ - name: Lint+ run: scripts/lint.sh CLANG_FORMAT=clang-format-20- # ── Step 2: Unit tests (ASan + UBSan) ────────────────────────+ # ── Step 2: Unit tests (ASan + UBSan) ───────────────────────test:needs: [lint]strategy:@@ -84,10 +74,10 @@ jobs:if: startsWith(matrix.os, 'ubuntu')run: sudo apt-get update && sudo apt-get install -y libsqlite3-dev zlib1g-dev- - name: Run C tests (ASan + UBSan)- run: make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm test CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}+ - name: Test+ run: scripts/test.sh CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- # ── Step 3: Build binaries (standard + UI, all OS) ───────────+ # ── Step 3: Build binaries (standard + UI, all OS) ──────────build-unix:needs: [test]strategy:@@ -126,7 +116,7 @@ jobs:node-version: "22"- name: Build standard binary- run: make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm cbm CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}+ run: scripts/build.sh CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- name: Archive standard binaryrun: |@@ -134,7 +124,7 @@ jobs:-C build/c codebase-memory-mcp- name: Build UI binary- run: make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm cbm-with-ui CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}+ run: scripts/build.sh --with-ui CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- name: Archive UI binaryrun: |@@ -168,7 +158,7 @@ jobs:- name: Build standard binaryshell: msys2 {0}- run: make -j$(nproc) -f Makefile.cbm cbm+ run: scripts/build.sh- name: Archive standard binaryshell: pwsh@@ -178,7 +168,7 @@ jobs:- name: Build UI binaryshell: msys2 {0}- run: make -j$(nproc) -f Makefile.cbm cbm-with-ui+ run: scripts/build.sh --with-ui- name: Archive UI binaryshell: pwsh@@ -191,7 +181,7 @@ jobs:name: binaries-windows-amd64path: "*.zip"- # ── Step 4: Smoke test every binary ──────────────────────────+ # ── Step 4: Smoke test every binary ─────────────────────────smoke-unix:needs: [build-unix]strategy:diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex e8023fac0..6e49d2c8b 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -21,7 +21,7 @@ permissions:contents: writejobs:- # ── Step 1: Lint (clang-format + cppcheck, no clang-tidy) ────+ # ── Step 1: Lint (clang-format + cppcheck) ───────────────────lint:runs-on: ubuntu-lateststeps:@@ -54,18 +54,10 @@ jobs:- name: Add cppcheck to PATHrun: echo "/opt/cppcheck/bin" >> "$GITHUB_PATH"- - name: Verify versions- run: |- echo "clang-format: $(clang-format-20 --version)"- echo "cppcheck: $(cppcheck --version)"-- - name: clang-format- run: make -f Makefile.cbm lint-format CLANG_FORMAT=clang-format-20+ - name: Lint+ run: scripts/lint.sh CLANG_FORMAT=clang-format-20- - name: cppcheck- run: make -f Makefile.cbm lint-cppcheck-- # ── Step 2: Unit tests (ASan + UBSan) ────────────────────────+ # ── Step 2: Unit tests (ASan + UBSan) ───────────────────────test:needs: [lint]strategy:@@ -96,10 +88,10 @@ jobs:if: startsWith(matrix.os, 'ubuntu')run: sudo apt-get update && sudo apt-get install -y libsqlite3-dev zlib1g-dev- - name: Run C tests (ASan + UBSan)- run: make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm test CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}+ - name: Test+ run: scripts/test.sh CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- # ── Step 3: Build binaries (standard + UI, all OS) ───────────+ # ── Step 3: Build binaries (standard + UI, all OS) ──────────build-unix:needs: [test]strategy:@@ -138,13 +130,7 @@ jobs:node-version: "22"- name: Build standard binary- env:- VERSION: ${{ inputs.version }}- run: |- CLEAN_VERSION="${VERSION#v}"- make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm cbm \- CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} \- CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""+ run: scripts/build.sh --version ${{ inputs.version }} CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- name: Archive standard binaryrun: |@@ -152,13 +138,7 @@ jobs:-C build/c codebase-memory-mcp- name: Build UI binary- env:- VERSION: ${{ inputs.version }}- run: |- CLEAN_VERSION="${VERSION#v}"- make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) -f Makefile.cbm cbm-with-ui \- CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} \- CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""+ run: scripts/build.sh --with-ui --version ${{ inputs.version }} CC=${{ matrix.cc }} CXX=${{ matrix.cxx }}- name: Archive UI binaryrun: |@@ -192,12 +172,7 @@ jobs:- name: Build standard binaryshell: msys2 {0}- env:- VERSION: ${{ inputs.version }}- run: |- CLEAN_VERSION="${VERSION#v}"- make -j$(nproc) -f Makefile.cbm cbm \- CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""+ run: scripts/build.sh --version ${{ inputs.version }}- name: Archive standard binaryshell: pwsh@@ -207,12 +182,7 @@ jobs:- name: Build UI binaryshell: msys2 {0}- env:- VERSION: ${{ inputs.version }}- run: |- CLEAN_VERSION="${VERSION#v}"- make -j$(nproc) -f Makefile.cbm cbm-with-ui \- CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""+ run: scripts/build.sh --with-ui --version ${{ inputs.version }}- name: Archive UI binaryshell: pwsh@@ -225,7 +195,7 @@ jobs:name: binaries-windows-amd64path: "*.zip"- # ── Step 4: Smoke test every binary ──────────────────────────+ # ── Step 4: Smoke test every binary ─────────────────────────smoke-unix:needs: [build-unix]strategy:@@ -291,7 +261,7 @@ jobs:shell: msys2 {0}run: scripts/smoke-test.sh ./codebase-memory-mcp.exe- # ── Step 5: Create GitHub release ────────────────────────────+ # ── Step 5: Create GitHub release ───────────────────────────release:needs: [smoke-unix, smoke-windows]runs-on: ubuntu-latestdiff --git a/scripts/build.sh b/scripts/build.shnew file mode 100755index 000000000..e949eec47--- /dev/null+++ b/scripts/build.sh@@ -0,0 +1,68 @@+#!/bin/bash+# build.sh — Clean build of production binary (standard or with UI).+#+# Usage:+# scripts/build.sh # Standard binary+# scripts/build.sh --with-ui # Binary with embedded UI+# scripts/build.sh --version v0.8.0 # With version stamp+#+# This script is the SINGLE source of truth for building release binaries.+# Used identically in local development and CI workflows.++set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"+cd "$ROOT"++# Detect parallelism+NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)++# Parse arguments+WITH_UI=false+VERSION=""+EXTRA_MAKE_ARGS=()++while [[ $# -gt 0 ]]; do+ case "$1" in+ --with-ui)+ WITH_UI=true+ shift+ ;;+ --version)+ VERSION="$2"+ shift 2+ ;;+ CC=*|CXX=*)+ export "${1?}"+ EXTRA_MAKE_ARGS+=("$1")+ shift+ ;;+ *)+ EXTRA_MAKE_ARGS+=("$1")+ shift+ ;;+ esac+done++# Version flag+CFLAGS_EXTRA=""+if [[ -n "$VERSION" ]]; then+ CLEAN_VERSION="${VERSION#v}"+ CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""+fi++echo "=== build.sh: compiler=${CC:-default} ui=$WITH_UI version=${VERSION:-dev} cores=$NPROC ==="++# Step 1: Clean C build artifacts only (not node_modules — npm ci handles that)+rm -rf "$ROOT/build/c"++# Step 2: Build+if $WITH_UI; then+ make -j"$NPROC" -f Makefile.cbm cbm-with-ui \+ CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"+else+ make -j"$NPROC" -f Makefile.cbm cbm \+ CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"+fi++echo "=== Build complete: build/c/codebase-memory-mcp ==="diff --git a/scripts/clean.sh b/scripts/clean.shnew file mode 100755index 000000000..dc8bd22ea--- /dev/null+++ b/scripts/clean.sh@@ -0,0 +1,29 @@+#!/bin/bash+# clean.sh — Remove ALL build artifacts, caches, and generated files.+#+# Usage: scripts/clean.sh+#+# Ensures every subsequent build starts from scratch — no cached .o files,+# no stale node_modules, no leftover dist folders. This is the first step+# in both scripts/test.sh and scripts/build.sh.++set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"++echo "=== Cleaning build artifacts ==="++# C build artifacts+rm -rf "$ROOT/build/c"++# Frontend build artifacts+rm -rf "$ROOT/graph-ui/dist"+rm -rf "$ROOT/graph-ui/node_modules"++# Root-level node artifacts (if any)+rm -rf "$ROOT/node_modules"++# Generated embedded assets (regenerated by embed-frontend.sh)+rm -f "$ROOT/src/ui/embedded_assets.c"++echo "=== Clean complete ==="diff --git a/scripts/lint.sh b/scripts/lint.shnew file mode 100755index 000000000..4a123d29f--- /dev/null+++ b/scripts/lint.sh@@ -0,0 +1,27 @@+#!/bin/bash+# lint.sh — Run all CI linters (clang-format + cppcheck).+#+# Usage:+# scripts/lint.sh # Default tools+# scripts/lint.sh CLANG_FORMAT=clang-format-20 # Override formatter+#+# This script is the SINGLE source of truth for CI linting.+# clang-tidy is intentionally excluded (platform-dependent, pre-commit only).++set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"+cd "$ROOT"++# Forward overrides from args (e.g. CLANG_FORMAT=clang-format-20)+MAKE_ARGS=()+for arg in "$@"; do+ MAKE_ARGS+=("$arg")+done++echo "=== lint.sh: running clang-format + cppcheck ==="++# Run format and cppcheck in parallel+make -j2 -f Makefile.cbm lint-ci "${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"}"++echo "=== All linters passed ==="diff --git a/scripts/test.sh b/scripts/test.shnew file mode 100755index 000000000..c5e9ecb9b--- /dev/null+++ b/scripts/test.sh@@ -0,0 +1,35 @@+#!/bin/bash+# test.sh — Clean build + run all C tests with ASan + UBSan.+#+# Usage: scripts/test.sh [CC=gcc-14] [CXX=g++-14]+#+# This script is the SINGLE source of truth for running tests.+# Used identically in local development and CI workflows.+#+# Steps:+# 1. Clean all build artifacts (forced fresh compile)+# 2. Build test-runner with sanitizers+# 3. Run all test suites++set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"+cd "$ROOT"++# Detect parallelism+NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)++# Forward CC/CXX from env or args (e.g. scripts/test.sh CC=gcc-14)+for arg in "$@"; do+ export "${arg?}"+done++echo "=== test.sh: compiler=${CC:-default} cores=$NPROC ==="++# Step 1: Clean+scripts/clean.sh++# Step 2 + 3: Build and run tests+make -j"$NPROC" -f Makefile.cbm test++echo "=== All tests passed ==="diff --git a/src/pipeline/pass_httplinks.c b/src/pipeline/pass_httplinks.cindex 1fcabe5d7..ff367326f 100644--- a/src/pipeline/pass_httplinks.c+++ b/src/pipeline/pass_httplinks.c@@ -365,7 +365,8 @@ static void resolve_fastapi_prefixes(cbm_pipeline_ctx_t *ctx, cbm_route_handler_char var[128];char module[256];} import_entry_t;- import_entry_t imports[64] = {{0}};+ import_entry_t imports[64];+ memset(imports, 0, sizeof(imports));int import_count = 0;const char *p = source;@@ -506,7 +507,8 @@ static void resolve_express_prefixes(cbm_pipeline_ctx_t *ctx, cbm_route_handler_char var[128];char module[256];} import_entry_t;- import_entry_t imports[64] = {{0}};+ import_entry_t imports[64];+ memset(imports, 0, sizeof(imports));int import_count = 0;const char *p = source;@@ -622,7 +624,8 @@ static void resolve_cross_file_group_prefixes(cbm_pipeline_ctx_t *ctx, cbm_routeint start;int count;} func_routes_t;- func_routes_t func_map[1024] = {{0}};+ func_routes_t func_map[1024];+ memset(func_map, 0, sizeof(func_map));int func_map_count = 0;for (int i = 0; i < route_count && func_map_count < 1024; i++) {@@ -739,7 +742,8 @@ static void resolve_cross_file_group_prefixes(cbm_pipeline_ctx_t *ctx, cbm_routechar var[128];char prefix[256];} var_prefix_t;- var_prefix_t var_pfx[16] = {{0}};+ var_prefix_t var_pfx[16];+ memset(var_pfx, 0, sizeof(var_pfx));int var_count = 0;p = caller_source;diff --git a/src/pipeline/pass_infrascan.c b/src/pipeline/pass_infrascan.cindex 1fe6c3be2..30c47d95e 100644--- a/src/pipeline/pass_infrascan.c+++ b/src/pipeline/pass_infrascan.c@@ -539,9 +539,12 @@ int cbm_parse_dockerfile_source(const char *source, cbm_dockerfile_result_t *outreturn -1;}- /* base_image = last stage's image */- snprintf(out->base_image, sizeof(out->base_image), "%s",- out->stage_images[out->stage_count - 1]);+ /* base_image = last stage's image (use intermediate copy to avoid restrict overlap) */+ {+ char tmp[sizeof(out->base_image)];+ snprintf(tmp, sizeof(tmp), "%s", out->stage_images[out->stage_count - 1]);+ memcpy(out->base_image, tmp, sizeof(out->base_image));+ }return 0;}