Commit Graph
7 Commits
Author SHA1 Message Date
Andrew Hundt 0d19cd3a79 refactor(platform): centralize env flag parsing
Add cbm_env_flag_enabled() beside cbm_safe_getenv() so debug/probe feature flags share one parser for unset, empty, 0, false, off, and no.

Remove the LSP-only env wrapper and route LSP debug/probe checks directly through the foundation helper. Reuse the same helper for CBM_PROFILE and CBM_SEMANTIC_ENABLED, and use cbm_safe_getenv() for CBM_SEMANTIC_THRESHOLD.

This keeps debug/profile nonempty opt-in compatibility while making explicit false values disable them. It also lets semantic enabled flags use the same true-style config convention rather than only literal 1.

Validation logs: /private/tmp/cbm-p26-env-flag-source-safety.log; /private/tmp/cbm-p26-env-flag-source-safety-selftest.log; /private/tmp/cbm-p26-env-flag-test-runner-build.log; /private/tmp/cbm-p26-env-flag-platform.log; /private/tmp/cbm-p26-env-flag-ts-lsp.log; /private/tmp/cbm-p26-env-flag-all-lsp.log; /private/tmp/cbm-p26-env-flag-pipeline.log; /private/tmp/cbm-p26-env-flag-product-build.log.

Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
2026-07-02 04:07:36 -04:00
Andrew Hundt ab4e9148b9 fix(fs): reject truncated directory entries
Return only exactly represented directory names from cbm_readdir so callers never stat, open, list, or delete a fabricated prefix path. This centralizes the Windows UTF-8 expansion edge case in compat_fs instead of duplicating checks at each caller.

Also make MCP bad-project available_projects hints append only complete escaped JSON strings and expose available_projects_truncated when the compact hint omits entries.

Validation: make -f Makefile.cbm build/c/test-runner; CBM_ONLY_SUITE=platform ./build/c/test-runner; CBM_ONLY_SUITE=mcp ./build/c/test-runner; bash scripts/check-source-safety.sh; git diff --check.
Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
2026-06-30 18:02:44 -04:00
Andrew Hundt 3261ce9383 fix(cli): harden install path formatting
Add cbm_getenv_fits so path-like environment values can fail closed when set but too long, instead of being silently truncated by bounded copies or falling back to HOME.

Use checked formatting for Claude hook command/script paths, install/uninstall Claude config paths, install/update binary targets, and PATH directory writes. Overlong paths now return or report an error before mutating a truncated location.

Add focused CLI regressions for overlong hook homes and CLAUDE_CONFIG_DIR, plus platform coverage for the new environment helper.

Validation: make -f Makefile.cbm cbm; make -f Makefile.cbm build/c/test-runner; CBM_ONLY_SUITE=cli ./build/c/test-runner; CBM_ONLY_SUITE=platform ./build/c/test-runner; bash scripts/check-source-safety.sh; git diff --check.
Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
2026-06-30 17:49:19 -04:00
Martin Vogel 34864c8c7e test(platform): use cbm_setenv/cbm_unsetenv for Windows portability
The CBM_WORKERS env tests called bare setenv/unsetenv, which are
POSIX-only and undeclared on the MSYS2 Windows test build. Switch to the
cbm_setenv/cbm_unsetenv compat wrappers (a no-op #define to setenv on
POSIX) and include foundation/compat.h. Fixes the test-windows build.
2026-05-30 20:15:30 +02:00
Sam Li a5a3d1d60a feat(platform): cgroup-aware CPU/memory detection in detect_system_linux
Inside a container, sysconf(_SC_NPROCESSORS_ONLN) and sysinfo() report
the host's CPU count and RAM, not the cgroup's effective quota — so
cbm_default_worker_count over-provisions workers and the mmap budget can
exceed the cgroup memory cap, driving OOMKills (#363).

detect_system_linux now reads the cgroup limits:
- cbm_detect_cgroup_cpus: cgroup v2 cpu.max, then v1 cpu.cfs_quota_us /
  cpu.cfs_period_us → ceil(quota/period); -1 when unlimited.
- cbm_detect_cgroup_mem: cgroup v2 memory.max, then v1
  memory.limit_in_bytes; 0 when unlimited or the v1 near-ULLONG_MAX
  sentinel.
- Effective value is min(cgroup, host), guarding against mis-mounted
  cgroups that report more than the host.

Helpers read via a bounded read_small_file (fopen "re", capped fread)
and are exposed through system_info_internal.h for unit tests that drive
them against a fake cgroup tree. The test teardown uses opendir/unlink/
rmdir (no shell spawn).

Distilled from #365 onto current main (unioned the test additions with
the CBM_WORKERS tests from #364, and replaced the test-cleanup
system("rm -rf") with a shell-free recursive remove). Closes #363
together with #364.
2026-05-30 17:47:18 +02:00
yangsec888 d95223817e feat(platform): CBM_WORKERS env override for cbm_default_worker_count
Adds a CBM_WORKERS env knob (clamped to [1, 256], invalid values warned
and ignored) that explicitly sets the parallel-indexing worker count.
In containers, sysconf(_SC_NPROCESSORS_ONLN) reports host CPUs rather
than the cgroup's effective quota, so a 1-vCPU pod on a 16-core node
otherwise spawns ~16 workers — the dominant OOMKill driver. When unset,
behaviour is unchanged.

From #364.
2026-05-30 17:32:47 +02:00
Martin Vogel 94a9a92f83 Add C-native pipeline with blocking clang-tidy, cppcheck, clang-format linting
Complete C implementation of the indexing pipeline (src/), parallel worker
pool, graph buffer with merge support, SQLite writer, and 1893-test suite.

Linter setup: zero warnings from clang-tidy (all checks enabled, no NOLINT
suppressions), cppcheck, and clang-format. All issues fixed at source —
proper headers for external linkage, GROW_ARRAY macro restructured to
eliminate type parameter, null-deref paths guarded, named intermediates
for suspicious-argument checks.
2026-03-15 19:26:12 +01:00