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
51 changes: 44 additions & 7 deletions .github/workflows/_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
artifact: codescope-aarch64-linux
- os: macos-15
artifact: codescope-aarch64-macos
- os: windows-2022
artifact: codescope-x86_64-windows
runs-on: ${{ matrix.os }}
timeout-minutes: 45
# ccache accelerates C/C++ compiles. On a dep-version cache miss
Expand Down Expand Up @@ -73,6 +75,18 @@ jobs:
# LadybugDB shared library is vendored under engine/third_party/ladybug/lib/macos/
# (committed to git, including the liblbug.dylib dev symlink).

- name: Install deps (Windows)
if: matrix.os == 'windows-2022'
run: |
# Install MinGW-w64 toolchain (version pinned to match local dev: GCC 16.1.0)
choco install mingw --version=14.0.0 -y --no-progress
echo "C:\tools\mingw64\bin" >> $GITHUB_PATH
# Add Rust Windows GNU target (Rust version pinned to 1.95.0 by dtolnay/rust-toolchain@1.95.0)
rustup target add x86_64-pc-windows-gnu
echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
echo "CXX=x86_64-w64-mingw32-g++" >> $GITHUB_ENV
# CMake 4.4.0 and Ninja 1.13.2 are pre-installed on GitHub Actions Windows runners

- name: Cache Cargo registry
uses: actions/cache@v6 # v4.2.3
with:
Expand Down Expand Up @@ -124,17 +138,27 @@ jobs:
env:
CBM_SKIP_PERF: ${{ inputs.skip_perf && '1' || '' }}
run: |
cargo build --release --bin codescope
cargo nextest run --release --no-tests=pass
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cargo build --release --target x86_64-pc-windows-gnu --bin codescope
else
cargo build --release --bin codescope
cargo nextest run --release --no-tests=pass
fi

- name: Smoke test
shell: bash
run: |
./target/release/codescope --help || true
# Verify binary is not corrupted (prints Mach-O / ELF metadata).
file target/release/codescope
if [ "${{ matrix.os }}" = "windows-2022" ]; then
./target/x86_64-pc-windows-gnu/release/codescope.exe --help || true
file target/x86_64-pc-windows-gnu/release/codescope.exe
else
./target/release/codescope --help || true
# Verify binary is not corrupted (prints Mach-O / ELF metadata).
file target/release/codescope
fi

- name: Build + test C++ engine
if: matrix.os != 'windows-2022' # C++ engine is built by build.rs on Windows
shell: bash
run: |
# Configure with tests enabled. Dependencies are vendored under
Expand Down Expand Up @@ -214,7 +238,11 @@ jobs:
if: inputs.skip_package != true
shell: bash
run: |
strip target/release/codescope 2>/dev/null || true
if [ "${{ matrix.os }}" = "windows-2022" ]; then
strip target/x86_64-pc-windows-gnu/release/codescope.exe 2>/dev/null || true
else
strip target/release/codescope 2>/dev/null || true
fi

- name: Ad-hoc sign macOS binary
if: ${{ matrix.os == 'macos-15' && inputs.skip_package != true }}
Expand All @@ -225,7 +253,11 @@ jobs:
shell: bash
run: |
mkdir -p package
cp target/release/codescope package/
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cp target/x86_64-pc-windows-gnu/release/codescope.exe package/
else
cp target/release/codescope package/
fi
cp LICENSE package/
[ -f install.sh ] && cp install.sh package/

Expand All @@ -246,6 +278,11 @@ jobs:
LBUG_LIB="engine/third_party/ladybug/lib/macos/liblbug.0.dylib"
LBUG_FILE="liblbug.0.dylib"
;;
*-windows)
# Windows: bundle lbug_shared.dll next to the .exe
LBUG_LIB="engine/third_party/ladybug/lib/windows/lbug_shared.dll"
LBUG_FILE="lbug_shared.dll"
;;
esac
cp -L "$LBUG_LIB" "package/$LBUG_FILE"
# Set rpath to $ORIGIN (Linux) / @executable_path (macOS) so the
Expand Down
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@

## Unreleased

## v0.2.3 (2026-07-21)

Windows beta support — cross-compilation from macOS to `x86_64-pc-windows-gnu` (MinGW), vendored LadybugDB Windows DLL, and CI pipeline. Plus critical bug fixes for the v0.2.2 LadybugDB migration that broke all query tools.

### 🚀 New Features

- **Windows Beta Support**: Cross-compilation from macOS to Windows x86-64 via MinGW (`x86_64-w64-mingw32-gcc`). `codescope.exe` produced as a 16MB PE32+ executable. Vendored `lbug_shared.dll` bundled with the binary. CI pipeline added (`windows-2022` runner, `choco install mingw`, `--target x86_64-pc-windows-gnu`).
- **LadybugDB Search** (`search`): Now queries LadybugDB directly via `MATCH (n) WHERE n.name CONTAINS 'query'` — no longer depends on async FTS build. Returns results synchronously in ~1ms.
- **`isGraphReady()` cross-process probe**: `isGraphReady()` now probes LadybugDB directly via `MATCH (n) RETURN count(*)` when the in-memory flag is not set, handling cross-process scenarios where the flag was set in a worker subprocess but the current process is fresh.

### 🐛 Bug Fixes

- **`findSymbolJson` prepare failed**: SQL query referenced `graph_nodes` table (now empty). Fixed to query `entity` table instead. (`store_project.cpp`)
- **`find_callers`/`find_callees`/`find_references`/`find_definition` all "graph not ready"**: `isGraphReady()` used a process-in-memory flag `lbug_populated_` that was set in the worker subprocess but not visible in the CLI process. Added `probeGraphReady()` that runs `MATCH (n) RETURN count(*)` on LadybugDB directly. (`store.h`, `store_ladybug_core.cpp`)
- **`project_overview` shows `total_symbols:0`**: SQL query counted `graph_nodes` (empty). Fixed to count `entity` rows. (`engine_queries.cpp`)
- **`search` returns empty results**: FTS was built on `graph_nodes` (empty) and there was no LadybugDB fallback. Added `searchLadybugJson()` — Cypher `CONTAINS` search via LadybugDB. (`store_ladybug_core.cpp`, `engine_queries.cpp`)
- **`searchGraphFallback`/`searchUnifiedJson` trigram query empty**: Both referenced `graph_nodes`/`graph_edges` tables. Fixed to use `entity`/`relation`. (`store_search.cpp`, `store_query.cpp`)
- **`buildFTSFromGraph` empty**: FTS tables (`code_fts`, `name_trgm`) were built from `graph_nodes` (empty). Fixed to build from `entity`. (`store_search.cpp`)
- **`test_trigram_search` assertion failure**: Test `insertGraphNode` helper inserted into `graph_nodes` only, but `buildFTSFromGraph` now reads from `entity`. Added dual-write to `entity` in the test helper. (`test_trigram_search.cpp`)
- **`engine_get_project_node_count` returns 0**: Queried `graph_nodes` (empty). Fixed to query `entity`. (`store_core.cpp`)
- **`getLatestProjectId` returns wrong project**: Queried `graph_nodes` for node count. Fixed to query `entity`. (`store_core.cpp`)
- **`engine_index_project` returns `total_nodes:0`**: Queried `graph_nodes` for the count. Fixed to query `entity`. (`engine_index_project.cpp`, `engine_index_post_parse.cpp`)
- **`verify_integrity` hangs indefinitely**: No query timeout guard. Added `QueryDeadlineGuard` with 10s timeout. (`engine_verify_ffi.cpp`)
- **`buildCSR` reverse query fails**: `ORDER BY target_node_id` column doesn't exist in `relation` table. Fixed to `ORDER BY target_id`. (`store_graph.cpp`)
- **`buildCSR` reads from `graph_edges`**: Fixed to read from `relation` table. (`store_graph.cpp`)
- **`locateNode`/`locateByName` query empty**: Referenced `graph_nodes`. Fixed to query `entity`. (`query_engine.cpp`)
- **Version string still shows 0.2.1**: Hardcoded in `engine_ffi.cpp`. Updated to `"0.2.2"` (now `"0.2.3"`). (`engine_ffi.cpp`)

### 🔧 Improvements

- **`make fmt` now runs full lint check**: Changed `make fmt` to run `lint-cpp-full` (all files) instead of `lint-cpp` (recent files only), preventing CI from catching formatting issues that local `make fmt` missed. (`Makefile`)
- **`QueryDeadlineGuard` added to `engine_verify_integrity`**: 10s timeout prevents infinite hangs. (`engine_verify_ffi.cpp`)
- **`graph_nodes`/`graph_edges` fully removed from query path**: All SQL queries that referenced these tables have been migrated to `entity`/`relation`. `graph_nodes`/`graph_edges` tables still exist in the schema but are no longer written or queried.

### 🔒 Cross-Platform Fixes

- **Windows cross-compilation**: Fixed `mkstemps` → `mkstemp` (not available on MinGW), `filesystem::path::native()` → `string()` (returns `wstring` on MinGW), `FilterPolicy::STRICT`/`FAST` macro conflicts with Windows headers (`#undef`), `libc::MAP_FAILED` not available on Windows (`#[cfg(windows)]` fallback), scheduler module conditional on `#[cfg(not(windows))]` (uses Unix `mmap`), `index-parallel` command gated on non-Windows.
- **`build.rs` cross-compile detection**: `-DCMAKE_SYSTEM_NAME=Windows` only set when cross-compiling from macOS/Linux, not on native Windows. (`build.rs`)
- **LadybugDB Windows DLL vendored**: `lbug_shared.dll` + `lbug_shared.lib` downloaded to `engine/third_party/ladybug/lib/windows/`. CMake and `build.rs` updated to detect Windows library.

### 🧹 Chores

- **Version bump**: 0.2.2 → 0.2.3
- **`engine/third_party/ladybug/lib/windows/`**: Added vendored Windows LadybugDB binary (lbug_shared.dll + lbug_shared.lib).
- **CI added `windows-2022` runner**: MinGW-w64 14.0.0, Rust `x86_64-pc-windows-gnu` target, C++ engine tests skipped (built by `build.rs`), `codescope.exe` + `lbug_shared.dll` packaged.

---

## v0.2.2 (2026-07-21)

LadybugDB graph engine migration — all graph queries now go through LadybugDB Cypher, with `entity`/`relation` as the canonical source tables. `graph_nodes`/`graph_edges` are deprecated. Plus `enhance_project` now populates the full model layer even on already-finalized projects.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = 4

[[package]]
name = "codescope"
version = "0.2.2"
version = "0.2.3"
dependencies = [
"libc",
"once_cell",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

It transforms source code into verifiable facts, understandable models, and inspectable evidence — enabling AI to validate claims against reality instead of hallucinating.

**Version**: v0.3 | **License**: Apache 2.0
**Version**: v0.2.3 | **License**: Apache 2.0

---

Expand Down Expand Up @@ -556,4 +556,4 @@ Each script calls `codescope cli <tool_name> '<json_args>'` internally. See `ski

Apache 2.0 — see [LICENSE](LICENSE).

**CodeScope v0.3** — Built with Rust 2024 + C++23 + tree-sitter + SQLite.
**CodeScope v0.2.3** — Built with Rust 2024 + C++23 + tree-sitter + SQLite.
4 changes: 2 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

它将源代码转化为可验证的事实、可理解的模型和可检查的证据 — 让 AI 能够根据现实验证断言,而非凭空编造。

**版本**: v0.2.1 | **许可证**: Apache 2.0
**版本**: v0.2.3 | **许可证**: Apache 2.0

---

Expand Down Expand Up @@ -539,4 +539,4 @@ cd CodeScope

Apache 2.0 — 详见 [LICENSE](LICENSE)。

**CodeScope v0.2.1** — 使用 Rust 2024 + C++23 + tree-sitter + SQLite 构建。
**CodeScope v0.2.3** — 使用 Rust 2024 + C++23 + tree-sitter + SQLite 构建。
50 changes: 34 additions & 16 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
## v0.2.2 (2026-07-21)
## v0.2.3 (2026-07-21)

LadybugDB graph engine migration — all graph queries now go through LadybugDB Cypher, with `entity`/`relation` as the canonical source tables. `graph_nodes`/`graph_edges` are deprecated. Plus `enhance_project` now populates the full model layer even on already-finalized projects.
Windows beta support — cross-compilation from macOS to `x86_64-pc-windows-gnu` (MinGW), vendored LadybugDB Windows DLL, and CI pipeline. Plus critical bug fixes for the v0.2.2 LadybugDB migration that broke all query tools.

### What changed

| Area | Before | After |
|------|--------|-------|
| **Graph queries** | SQLite `graph_nodes`/`graph_edges` with LadybugDB as optional fallback | LadybugDB Cypher only; SQLite fallback removed |
| **LadybugDB build** | `compileGraphToLadybugDB` reads from `graph_nodes`/`graph_edges` | `buildLadybugFromEntityRelation` reads from `entity`/`relation` (canonical source) |
| **`enhance_project`** | Returns `already_finalized` without populating model tables | Runs `runModelIndexSync` + `buildKnowledgeGraphSync` unconditionally |
| **Filtering** | Undocumented | 8-layer smart filtering documented in README with real-world impact data |
| **Storage** | SQLite only | LadybugDB 3.4MB (4.4% of SQLite 77MB) for CodeScope self-index |
| **Windows support** | Not supported | Beta: cross-compiled `codescope.exe` (16MB PE32+), `lbug_shared.dll` bundled, CI `windows-2022` |
| **`search` tool** | Async FTS on `graph_nodes` (empty), returned no results | Synchronous `MATCH (n) WHERE n.name CONTAINS 'query'` via LadybugDB, ~1ms |
| **`isGraphReady()`** | Process-in-memory flag only (broken across worker/CLI processes) | Probes LadybugDB directly via `MATCH (n) RETURN count(*)` |
| **All query tools** | `findSymbolJson` prepare failed, `find_callers`/`find_callees` etc. "graph not ready" | All queries go through `entity`/`relation` tables or LadybugDB |
| **`graph_nodes`/`graph_edges`** | Still referenced by >20 SQL queries (returning empty) | Fully removed from all query paths. Tables still exist but unused |
| **`verify_integrity`** | Hangs indefinitely (no timeout) | 10s `QueryDeadlineGuard` |
| **`make fmt`** | Only checked recently modified files | Full project lint check (`lint-cpp-full`) |
| **Cross-compilation** | N/A | `build.rs` detects cross-compile vs native Windows, sets `CMAKE_SYSTEM_NAME` only when needed |

### Upgrade notes

- No breaking API changes. All MCP tools maintain the same JSON response schema.
- `enhance_project` now runs model building even on finalized projects — expect ~2s additional time on first call after upgrade.
- LadybugDB is now required (was optional). Install via `brew install ladybugdb` (macOS) or `curl -fsSL https://install.ladybugdb.com | sh` (Linux).
- `graph_nodes`/`graph_edges` tables are still written but no longer queried. Will be removed in v0.3.
- **Windows**: Use `--target x86_64-pc-windows-gnu` for Rust builds. Requires MinGW-w64 14.0.0+. `lbug_shared.dll` must be in the same directory as `codescope.exe` (bundled in the package).
- **No breaking API changes**: All MCP tools maintain the same JSON response schema.
- **`graph_nodes`/`graph_edges` tables are no longer written**: If you have custom scripts that query these tables, migrate to `entity`/`relation`.
- **LadybugDB is now required for graph queries**: Without LadybugDB, all query tools return "graph not ready" or "LadybugDB not compiled".

### Bug fixes (v0.2.2 migration fallout)

| # | Bug | Root cause | Fix |
|---|-----|------------|-----|
| 1 | `findSymbolJson` prepare failed | SQL query referenced `graph_nodes` (empty) | Query `entity` instead |
| 2 | All tools "graph not ready" | `isGraphReady()` in-memory flag not shared across processes | `probeGraphReady()` queries LadybugDB directly |
| 3 | `project_overview` total_symbols:0 | Counted `graph_nodes` rows | Count `entity` rows |
| 4 | `search` returns empty | FTS built on `graph_nodes` (empty), no fallback | `searchLadybugJson()` via LadybugDB Cypher |
| 5 | `buildFTSFromGraph` empty | FTS tables built from `graph_nodes` | Build from `entity` |
| 6 | `engine_get_project_node_count` returns 0 | Queried `graph_nodes` | Query `entity` |
| 7 | `getLatestProjectId` wrong project | Queried `graph_nodes` for node count | Query `entity` |
| 8 | `verify_integrity` hangs | No query timeout | 10s `QueryDeadlineGuard` |
| 9 | `buildCSR` reverse query fails | `ORDER BY target_node_id` (wrong column name) | `ORDER BY target_id` |
| 10 | Version string still 0.2.1 | Hardcoded in `engine_ffi.cpp` | Updated to 0.2.3 |

### Performance

| Metric | Value |
|--------|-------|
| LadybugDB build (CodeScope, 1,387 nodes) | 579ms |
| LadybugDB file size | 3.4MB (4.4% of SQLite) |
| CodeScope self-index (212 files) | 899ms |
| Windows binary size | 16MB (PE32+ executable) |
| LadybugDB search latency | ~1ms (Cypher CONTAINS) |
| Query latency (all graph tools) | ~1ms |
| `enhance_project` total | 2,655ms |
| `make check` | 85 Rust tests + 17 C++ LadybugDB tests — all pass |
| `make check` | 85 Rust tests + all C++ tests pass |

### Full changelog

See [CHANGELOG.md](./CHANGELOG.md) for the complete list of changes, bug fixes, and code review findings.
See [CHANGELOG.md](./CHANGELOG.md) for the complete list of changes, bug fixes, and cross-platform fixes.
30 changes: 16 additions & 14 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,22 @@ target_link_libraries(astgraph_engine PUBLIC
# is not found (useful for production builds that require Cypher).
option(LADYBUG_REQUIRED "Fail build if LadybugDB is not found" OFF)
set(LADYBUG_VENDOR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/ladybug")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/macos")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Select the architecture-matched vendored library directory:
# lib/linux → x86-64
# lib/linux-aarch64 → aarch64
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/linux-aarch64")
else()
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/linux")
endif()
else()
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/macos")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Select the architecture-matched vendored library directory:
# lib/linux → x86-64
# lib/linux-aarch64 → aarch64
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/linux-aarch64")
else()
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/linux")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib/windows")
else()
set(LADYBUG_VENDOR_LIB_DIR "${LADYBUG_VENDOR_DIR}/lib")
endif()
# Force re-detection: clear stale cache entries from previous runs
unset(LADYBUG_LIBRARY CACHE)
unset(LADYBUG_INCLUDE_DIR CACHE)
Expand Down
2 changes: 1 addition & 1 deletion engine/src/engine_ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,6 @@ const char *engine_version(void)
// No try/catch required — only a static string literal is returned,
// so no exceptions are possible.
// Keep in sync with RELEASE.md and Cargo.toml version.
static const char kVersion[] = "0.2.1";
static const char kVersion[] = "0.2.3";
return kVersion;
}
8 changes: 8 additions & 0 deletions engine/src/engine_index_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
#include "filter_policy.h"
#include "platform_win.h"

// Undefine Windows macros that conflict with enum values
#ifdef STRICT
#undef STRICT
#endif
#ifdef FAST
#undef FAST
#endif

#include <algorithm>
#include <chrono>
#include <condition_variable>
Expand Down
Loading
Loading