Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 13 additions & 32 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Usage:
# make -f Makefile.cbm test # Build + run all tests (ASan + UBSan)
# make -f Makefile.cbm test-foundation # Foundation tests only (fast)
# make -f Makefile.cbm test-tsan # Thread sanitizer build
# make -f Makefile.cbm cbm # Production binary
# make -f Makefile.cbm clean-c # Remove build artifacts
Expand Down Expand Up @@ -93,29 +92,11 @@ LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz -fsanitize=thread $(WIN32_LIBS)

# ── Source files ─────────────────────────────────────────────────

# The rest of src/foundation is Zig (CBM_ZIG_SRCS). hash_table.c wraps the
# vendored Verstable macro template; c_shim.c holds the variadic functions.
FOUNDATION_SRCS = \
src/foundation/arena.c \
src/foundation/hash_table.c \
src/foundation/str_intern.c \
src/foundation/log.c \
src/foundation/str_util.c \
src/foundation/platform.c \
src/foundation/system_info.c \
src/foundation/slab_alloc.c \
src/foundation/yaml.c \
src/foundation/compat.c \
src/foundation/compat_thread.c \
src/foundation/compat_fs.c \
src/foundation/file_lock.c \
src/foundation/compat_regex.c \
src/foundation/mem.c \
src/foundation/diagnostics.c \
src/foundation/profile.c \
src/foundation/dump_verify.c \
src/foundation/limits.c \
src/foundation/subprocess.c \
src/foundation/git_env.c \
src/foundation/sha256.c
src/foundation/c_shim.c

# Existing extraction C code (compiled from current location)
EXTRACTION_SRCS = \
Expand Down Expand Up @@ -492,12 +473,20 @@ CBM_ZIG_SRCS = $(CBM_ZIG_SRC) src/cbm_zig_c.h src/cli_zig/cbm_cli_zig.zig src/cl
src/cli/archive.zig src/cli/cli.zig src/cli/commands.zig src/cli/store.zig \
src/cli/tool_args.zig \
src/cli/hook_augment.zig src/cli/progress_sink.zig src/cli/progress_sink.h \
src/foundation/sha256.h \
src/cli/cli.h src/mcp/mcp.h src/pipeline/pipeline.h \
src/mcp/mcp.zig src/mcp/server.zig src/mcp/code_tools.zig \
src/mcp/graph_tools.zig src/mcp/index_tools.zig src/mcp/project_tools.zig \
src/mcp/search_tools.zig src/mcp/index_supervisor.zig src/mcp/index_supervisor.h \
src/foundation/interop.zig \
src/foundation/arena.zig src/foundation/compat.zig src/foundation/compat_fs.zig \
src/foundation/compat_regex.zig src/foundation/compat_thread.zig \
src/foundation/diagnostics.zig src/foundation/dump_verify.zig \
src/foundation/file_lock.zig src/foundation/git_env.zig src/foundation/limits.zig \
src/foundation/log.zig src/foundation/mem.zig src/foundation/platform.zig \
src/foundation/profile.zig src/foundation/sha256.zig src/foundation/slab_alloc.zig \
src/foundation/str_intern.zig src/foundation/str_util.zig \
src/foundation/subprocess.zig src/foundation/system_info.zig src/foundation/yaml.zig \
$(wildcard src/foundation/*.h) \
src/cypher/parser.zig src/cypher/cypher.zig src/cypher/cypher.h \
src/discover/discover.zig src/discover/gitignore.zig src/discover/language.zig \
src/discover/userconfig.zig \
Expand Down Expand Up @@ -539,7 +528,7 @@ PP_OBJ_TEST = $(BUILD_DIR)/preprocessor.o

# ── Targets ──────────────────────────────────────────────────────

.PHONY: test test-cli test-mcp test-repro test-foundation test-tsan cbm check-zova test-zova test-zova-c-sql-functions test-zova-bridge zova-test-runner clean-c print-build-sources lint lint-tidy lint-cppcheck lint-format security
.PHONY: test test-cli test-mcp test-repro test-tsan cbm check-zova test-zova test-zova-c-sql-functions test-zova-bridge zova-test-runner clean-c print-build-sources lint lint-tidy lint-cppcheck lint-format security

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
Expand Down Expand Up @@ -625,14 +614,6 @@ $(BUILD_DIR)/cbm_zova_bridge.o: $(CBM_ZOVA_BRIDGE_ZIG_SRC) src/zova/cbm_zova_bri
-Mzova_build_options=$(BUILD_DIR)/zova_build_options.zig
endif

# ── Foundation-only test (fast, no extraction) ───────────────────

$(BUILD_DIR)/test-foundation: $(TEST_FOUNDATION_SRCS) $(FOUNDATION_SRCS) | $(BUILD_DIR)
$(CC) $(CFLAGS_TEST) -o $@ $(TEST_FOUNDATION_SRCS) $(FOUNDATION_SRCS) $(LDFLAGS_TEST)

test-foundation: $(BUILD_DIR)/test-foundation
cd $(CURDIR) && $(BUILD_DIR)/test-foundation

# ── Grammar/TS/LSP object files (compiled with relaxed warnings) ─

$(BUILD_DIR)/%.o: $(CBM_DIR)/%.c | $(BUILD_DIR)
Expand Down
22 changes: 1 addition & 21 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -530,28 +530,8 @@ fn grammarSources(b: *std.Build) []const []const u8 {
}

const native_sources = [_][]const u8{
"src/foundation/arena.c",
"src/foundation/hash_table.c",
"src/foundation/str_intern.c",
"src/foundation/log.c",
"src/foundation/str_util.c",
"src/foundation/platform.c",
"src/foundation/system_info.c",
"src/foundation/slab_alloc.c",
"src/foundation/yaml.c",
"src/foundation/compat.c",
"src/foundation/compat_thread.c",
"src/foundation/compat_fs.c",
"src/foundation/file_lock.c",
"src/foundation/compat_regex.c",
"src/foundation/mem.c",
"src/foundation/diagnostics.c",
"src/foundation/profile.c",
"src/foundation/dump_verify.c",
"src/foundation/limits.c",
"src/foundation/subprocess.c",
"src/foundation/git_env.c",
"src/foundation/sha256.c",
"src/foundation/c_shim.c",
"src/store/store.c",
"src/zova/cbm_zova.c",
"src/zova/cbm_zova_publish_model.c",
Expand Down
12 changes: 6 additions & 6 deletions scripts/security-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# list causes the security audit (scripts/security-audit.sh) to fail.

# ── Foundation: platform abstraction (defines cbm_popen wrapper + shell-free exec) ──
src/foundation/compat_fs.c:popen:cbm_popen wrapper definition (POSIX)
src/foundation/compat_fs.c:cbm_popen:cbm_popen function definition
src/foundation/compat_fs.c:cbm_popen_git:cbm_popen_git function definition (git children with the repository-local git environment removed)
src/foundation/compat_fs.c:fork:cbm_exec_no_shell — fork+execvp for shell-free subprocess execution
src/foundation/subprocess.c:fork:cbm_run_posix — fork+execv for the crash/hang-isolating index worker (supervisor primitive; child execs immediately, no code runs in the forked image)
src/foundation/compat_fs.c:execvp:cbm_exec_no_shell — direct exec without shell interpretation
src/foundation/compat_fs.zig:popen:cbm_popen wrapper definition (POSIX)
src/foundation/compat_fs.zig:cbm_popen:cbm_popen function definition
src/foundation/compat_fs.zig:cbm_popen_git:cbm_popen_git function definition (git children with the repository-local git environment removed)
src/foundation/compat_fs.zig:fork:cbm_exec_no_shell — fork+execvp for shell-free subprocess execution
src/foundation/subprocess.zig:fork:runPosix — fork+execv for the crash/hang-isolating index worker (supervisor primitive; child execs immediately, no code runs in the forked image)
src/foundation/compat_fs.zig:execvp:cbm_exec_no_shell — direct exec without shell interpretation

# ── CLI: update command (user-initiated, interactive) ──────────────────────
src/cli/commands.zig:cbm_popen:latest-release lookup via curl redirect header (hardcoded URL)
Expand Down
4 changes: 2 additions & 2 deletions scripts/security-audit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ while IFS= read -r match; do
file=$(echo "$match" | cut -d: -f1)
relfile="${file#"$ROOT/"}"
case "$relfile" in
src/cli/cli.zig|src/store/store.c|src/pipeline/*.c|src/foundation/log.c|src/foundation/diagnostics.c|src/mcp/search_tools.zig|src/mcp/index_tools.zig)
;; # Known safe (diagnostics.c: atomic .tmp+rename metrics dump to configured path;
src/cli/cli.zig|src/store/store.c|src/pipeline/*.c|src/foundation/diagnostics.zig|src/mcp/search_tools.zig|src/mcp/index_tools.zig)
;; # Known safe (diagnostics.zig: atomic .tmp+rename metrics dump to configured path;
# search_tools.zig: search pattern/file-list temp files; index_tools.zig:
# index supervisor response/quarantine files)
*)
Expand Down
26 changes: 26 additions & 0 deletions src/cbm_zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ comptime {
checkExports(@import("discover/gitignore.zig"));
checkExports(@import("discover/language.zig"));
checkExports(@import("discover/userconfig.zig"));
checkExports(@import("foundation/arena.zig"));
checkExports(@import("foundation/compat.zig"));
checkExports(@import("foundation/compat.zig").windows);
checkExports(@import("foundation/compat_fs.zig"));
checkExports(@import("foundation/compat_fs.zig").impl);
checkExports(@import("foundation/compat_regex.zig"));
checkExports(@import("foundation/compat_thread.zig"));
checkExports(@import("foundation/diagnostics.zig"));
checkExports(@import("foundation/dump_verify.zig"));
checkExports(@import("foundation/file_lock.zig"));
checkExports(@import("foundation/git_env.zig"));
checkExports(@import("foundation/git_env.zig").windows);
checkExports(@import("foundation/git_env.zig").posix);
checkExports(@import("foundation/limits.zig"));
checkExports(@import("foundation/log.zig"));
checkExports(@import("foundation/mem.zig"));
checkExports(@import("foundation/platform.zig"));
checkExports(@import("foundation/profile.zig"));
checkExports(@import("foundation/sha256.zig"));
checkExports(@import("foundation/slab_alloc.zig"));
checkExports(@import("foundation/str_intern.zig"));
checkExports(@import("foundation/str_util.zig"));
checkExports(@import("foundation/subprocess.zig"));
checkExports(@import("foundation/system_info.zig"));
checkExports(@import("foundation/system_info.zig").linux);
checkExports(@import("foundation/yaml.zig"));
checkExports(@import("git/git_context.zig"));
checkExports(@import("mcp/code_tools.zig"));
checkExports(@import("mcp/graph_tools.zig"));
Expand Down
44 changes: 44 additions & 0 deletions src/cbm_zig_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,43 @@
#include <poll.h>
#endif
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>

/* Platform headers used by the Zig foundation modules. */
#ifdef _WIN32
#include <windows.h>
#include <direct.h>
#include <io.h>
#include <process.h>
#include <psapi.h>
#include "foundation/win_utf8.h"
#include <tre/regex.h>
#else
#include <dirent.h>
#include <pthread.h>
#include <regex.h>
#include <sched.h>
#include <spawn.h>
#include <strings.h>
#include <sys/mman.h>
#include <sys/wait.h>
#endif
#ifdef __APPLE__
#include <CommonCrypto/CommonDigest.h>
#include <crt_externs.h>
#include <mach-o/dyld.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <sys/sysctl.h>
#endif
#ifdef __linux__
#include <sys/sysinfo.h>
#endif
#include <mimalloc.h>

#include "foundation/arena.h"
#include "foundation/compat.h"
#include "foundation/compat_fs.h"
#include "foundation/compat_regex.h"
Expand All @@ -37,14 +72,23 @@
#include "foundation/hash_table.h"
#include "foundation/limits.h"
#include "foundation/log.h"
#include "foundation/log_internal.h"
#include "foundation/mem.h"
#include "foundation/diagnostics.h"
#include "foundation/dump_verify.h"
#include "foundation/file_lock.h"
#include "foundation/git_env.h"
#include "foundation/profile.h"
#include "foundation/subprocess.h"
#include "foundation/platform.h"
#include "foundation/sha256.h"
#include "foundation/sha256_backend.h"
#include "foundation/slab_alloc.h"
#include "foundation/str_intern.h"
#include "foundation/str_util.h"
#include "foundation/system_info_internal.h"
#include "foundation/compat_fs_internal.h"
#include "foundation/yaml.h"
#include "mcp/mcp.h"
#include "pipeline/pipeline.h"
#include "store/store.h"
Expand Down
Loading
Loading