local-codebase-indexer 0.9.0__tar.gz → 0.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/AGENTS.md +9 -2
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/CHANGELOG.md +13 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/CONTRIBUTING.md +1 -1
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/PKG-INFO +29 -2
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/README.md +28 -1
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/README.zh-CN.md +27 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/README.zh-TW.md +27 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/README.md +16 -0
- local_codebase_indexer-0.9.1/benchmarks/compare_tools.py +296 -0
- local_codebase_indexer-0.9.1/benchmarks/navigation_task.json +11 -0
- local_codebase_indexer-0.9.1/benchmarks/tool-comparison-queries.jsonl +96 -0
- local_codebase_indexer-0.9.1/benchmarks/tool-comparison.json +148 -0
- local_codebase_indexer-0.9.1/docs/comparison-evidence.json +54 -0
- local_codebase_indexer-0.9.1/docs/tool-comparison.md +108 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/__init__.py +1 -1
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/csdata.py +43 -7
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/dataflow.py +4 -3
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/db.py +1 -1
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/sqlaccess.py +123 -24
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/vbdata.py +44 -6
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/PKG-INFO +29 -2
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/SOURCES.txt +9 -1
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/server.json +2 -2
- local_codebase_indexer-0.9.1/tests/test_provenance_boundaries.py +220 -0
- local_codebase_indexer-0.9.1/tests/test_tool_comparison.py +69 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/.claude-plugin/marketplace.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/CLAUDE.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/LICENSE +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/MANIFEST.in +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/TODO.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/assets/demo-output.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/assets/demo-preview.png +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/assets/demo-report.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/assets/demo.gif +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/baseline.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Auth/LoginService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Controllers/LotController.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Controllers/ScrapController.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Data/MesDbContext.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Legacy/frmChangeLine.frm +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Models/DrillBreakEvent.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Models/Lot.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Models/ScrapRecord.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Printing/LabelPrinter.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Repositories/LotRepository.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Repositories/ScrapRepository.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Services/IScrapService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Services/InspectionService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Services/LotService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Services/ScrapService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Sql/MES_Lot.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Sql/usp_Inspection_Report.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Sql/usp_Lot_UpdateStatus.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Sql/usp_Scrap_Insert.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Utils/DateRangeHelper.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Utils/PartNumberDecoder.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Web/scrapForm.ts +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/Web.config +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/corpus/tools/export_report.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/queries_project.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/queries_stdlib.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/queries_synthetic.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/benchmarks/run_benchmark.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/bin/indexer +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/case-study.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/discovery.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/launch/community.en.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/launch/community.zh-TW.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/launch/directory-entry.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/reference.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/reference.zh-CN.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/reference.zh-TW.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/docs/sql-legacy-support.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/index.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/llms.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/__main__.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/callgraph.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/cli.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/context.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/core.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/cscalls.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Controllers/OrdersController.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Data/OrderRepository.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Models/Order.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/README.md +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Services/IOrderService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Services/OrderService.cs +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Sql/Sales_OrderHeader.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Sql/usp_ApproveOrder.sql +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/demo_project/Views/Orders/Details.cshtml +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/embedder.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/evaluation.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/impact.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/langparse.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/locking.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/mcp_server.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/pagination.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/query.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/query_common.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/relations.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/rendering.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/scanner.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/synonyms.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer/textdecode.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/dependency_links.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/entry_points.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/requires.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/local_codebase_indexer.egg-info/top_level.txt +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/plugins/local-codebase-indexer/.claude-plugin/plugin.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/plugins/local-codebase-indexer/.mcp.json +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/pyproject.toml +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/scripts/release_assets.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/scripts/render_demo.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/setup.cfg +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_dataaccess.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_demo.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_evaluation.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_indexer.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_navigation_stability.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_onnx_plumbing.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_release_assets.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_reliability.py +0 -0
- {local_codebase_indexer-0.9.0 → local_codebase_indexer-0.9.1}/tests/test_sql_regressions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Instructions for AI coding assistants
|
|
2
2
|
|
|
3
|
-
This repository is **local-codebase-indexer**: a local code index (SQLite, no cloud) that you can use as an MCP server or CLI to find code, callers, and SQL table/stored-procedure access with
|
|
3
|
+
This repository is **local-codebase-indexer**: a local code index (SQLite, no cloud) that you can use as an MCP server or CLI to find code, callers, and SQL table/stored-procedure access with source locations, confidence labels, and bounded context.
|
|
4
4
|
|
|
5
5
|
## Install (pick one)
|
|
6
6
|
|
|
@@ -80,10 +80,17 @@ Run `local-codebase-indexer demo` without a database or model. It uses a tempora
|
|
|
80
80
|
|
|
81
81
|
## SQL and legacy-source correctness (0.9.0)
|
|
82
82
|
|
|
83
|
-
- Run `python -m ruff check local_codebase_indexer scripts`, `python -m mypy`, and the full pytest suite before publishing. CI covers Linux and Windows on Python 3.10, 3.12, and 3.13.
|
|
83
|
+
- Run `python -m ruff check local_codebase_indexer scripts benchmarks/compare_tools.py`, `python -m mypy`, and the full pytest suite before publishing. CI covers Linux and Windows on Python 3.10, 3.12, and 3.13.
|
|
84
84
|
- Dependency declarations live in `pyproject.toml`; `requirements.txt` was removed to avoid drift.
|
|
85
85
|
- Source decoding and context extraction handle BOM-tagged UTF-16/UTF-32. True binary files are excluded consistently by scanning and status.
|
|
86
86
|
- `data-access` has additive `schema_changes` entries (`access=schema`) for table/index DDL. They are not row writers. File-level SQL changes appear in impact with before/current/after labels and source evidence.
|
|
87
87
|
- VB6 `.frm`/`.bas`/`.cls` SQL strings get procedure owners. Complete SQL at known ADO/DAO receivers may be confirmed; unknown receivers or incomplete concatenation remain probable/uncertain. No VB6 call graph or runtime execution proof is implied.
|
|
88
88
|
- Explicit negations in `.ai_context/ignore` can include default source directories such as `!bin/` and `!bin/**`, overriding `.gitignore`. Include excluded parents first. `.git`, `.svn`, `.hg`, and `.ai_context` remain excluded.
|
|
89
89
|
- Keep `query.py` as the facade/search implementation; navigation, source context, and rendering live in `relations.py`, `context.py`, and `rendering.py`. Legacy public imports from `query` remain supported.
|
|
90
|
+
|
|
91
|
+
## SQL provenance and tool comparison (0.9.1)
|
|
92
|
+
|
|
93
|
+
- SQL statement/batch boundaries and lexical bindings must not manufacture confirmed access from unrelated literals or shadowed parameters. Keep regression coverage in `tests/test_provenance_boundaries.py`.
|
|
94
|
+
- SQL object definitions come only from SQL sources; application symbol navigation still includes Python/JS functions.
|
|
95
|
+
- Index format 10 invalidates older parsed edges and rebuilds them on the first update. Keep package and Registry versions synchronized when preparing a release.
|
|
96
|
+
- Tool comparisons live in `docs/tool-comparison.md`; keep language READMEs in sync, cite upstream capabilities, and distinguish a literal-search baseline from a full Claude workflow. Do not claim measured speed/token/accuracy superiority without a corresponding experiment.
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.9.1
|
|
6
|
+
|
|
7
|
+
- Bound dynamic `sp_executesql` analysis to its SQL argument and statement; preserve uncertainty for quoted procedure names and exclude unrelated literals/column names.
|
|
8
|
+
- Scope CTE exclusions to one consuming statement/batch, including omitted semicolons and UNION/INSERT SELECT and stop UPDATE/DELETE alias lookup at the next command, including commands without semicolons.
|
|
9
|
+
- Preserve comma sources following JOIN predicates that use qualified `go` columns; recognize GO only as a batch separator line.
|
|
10
|
+
- Restrict SQL object definitions/suggestions to SQL source files so application functions do not become tables/procedures or redirect SQL search routing.
|
|
11
|
+
- Respect C#/VB6 parameter and local shadowing, invalidate overwritten SQL, and avoid interpreting query parameters as SQL. Preserve earlier valid execution evidence and known ADO declarations.
|
|
12
|
+
- Add English/Traditional Chinese/Simplified Chinese tool comparisons with documented trade-offs, pinned upstream sources, and a reproducible literal-search/relation-report example.
|
|
13
|
+
- Quantify those comparisons with a reproducible ripgrep + BM25 baseline, unchanged retrieval questions, raw per-query records, file-level recall/MRR, exact character denominators, and CLI evidence coverage/latency. Show stdlib losses and tiny-file output overhead alongside MES gains in all three READMEs. Add benchmark protocol regression tests and a CI artifact smoke run.
|
|
14
|
+
- Index format 10 rebuilds stale parsing results on the first update. Package and Registry versions remain unchanged until a release is prepared.
|
|
15
|
+
|
|
3
16
|
## 0.9.0
|
|
4
17
|
|
|
5
18
|
- Fix a first-run Windows lock-file initialization race found by concurrent-process CI; serialize index ignore-file creation.
|
|
@@ -8,7 +8,7 @@ Use Python 3.10+ in a virtual environment:
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
python -m pip install -e ".[dev,onnx]" onnx build twine
|
|
11
|
-
python -m ruff check local_codebase_indexer scripts
|
|
11
|
+
python -m ruff check local_codebase_indexer scripts benchmarks/compare_tools.py
|
|
12
12
|
python -m mypy
|
|
13
13
|
python -m pytest -q
|
|
14
14
|
python -m build
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: local-codebase-indexer
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: Trace SQL Server tables to C# callers and Razor pages locally. MCP server and CLI for code search and change impact.
|
|
5
5
|
Author: sfy257000
|
|
6
6
|
License-Expression: MIT
|
|
@@ -44,7 +44,7 @@ Dynamic: license-file
|
|
|
44
44
|
|
|
45
45
|
# Local Codebase Indexer
|
|
46
46
|
|
|
47
|
-
**English** | [繁體中文](
|
|
47
|
+
**English** | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)
|
|
48
48
|
|
|
49
49
|
**Which C# code and pages reach this SQL Server table?**
|
|
50
50
|
|
|
@@ -54,6 +54,33 @@ Trace tables and stored procedures to repositories, controller actions, and Razo
|
|
|
54
54
|
|
|
55
55
|
[Case study and raw results](https://github.com/sfy257000/local-codebase-indexer/blob/main/docs/case-study.md) · [CLI reference](https://github.com/sfy257000/local-codebase-indexer/blob/main/docs/reference.md) · [PyPI](https://pypi.org/project/local-codebase-indexer/) · [MIT license](https://github.com/sfy257000/local-codebase-indexer/blob/main/LICENSE)
|
|
56
56
|
|
|
57
|
+
## How it compares with Claude's Grep and similar tools
|
|
58
|
+
|
|
59
|
+
**Measured on our MES fixtures: +9.5–10.7 percentage points in relevant-file recall versus `rg + BM25`.** For the bundled SQL → C# → page investigation, the relation report covers **5/5 required evidence files**, versus **3/5** from one literal table-name search (**+40 points**).
|
|
60
|
+
|
|
61
|
+
| Fixed retrieval suite | `rg + BM25` file Recall@5 | This project | Difference |
|
|
62
|
+
|---|---:|---:|---:|
|
|
63
|
+
| MES-style synthetic: 42 questions, 24 files | 81.0% | **91.7%** | **+10.7 pp** |
|
|
64
|
+
| Same 42 questions with distractors: 109 files | 81.0% | **90.5%** | **+9.5 pp** |
|
|
65
|
+
| Python stdlib: 12 questions, 85 real source files | **100.0%** | 79.2% | −20.8 pp |
|
|
66
|
+
|
|
67
|
+
Recall means the fraction of known relevant files retrieved, averaged over questions. The baseline runs real ripgrep with generic query-term splitting and BM25 ranking; it is not Claude's agent. This project uses default hashing and 5 result chunks; the baseline returns 5 files. Both are scored at file level. These are 54 unique, project-authored questions (96 executions including the repeated noisy suite), not a general accuracy guarantee.
|
|
68
|
+
|
|
69
|
+
**Less source to read:** on the noisy MES and stdlib suites, rendered search results contain **94.9% / 96.9% fewer characters** than reading the same selected files in full. Tiny synthetic files instead produce **2.3% more** characters. This measures output size against whole-file reading, not savings against Grep snippets or Claude tokens.
|
|
70
|
+
|
|
71
|
+
**Cost of the richer report:** the demo CLI takes **244.5 ms** warm versus **8.3 ms** for one literal `rg` call (three-run medians; first indexer call **266.1 ms** including indexing). It adds controller/page evidence, not a speed win. The controller path is `probable`, not runtime proof. No end-to-end Claude, Serena, or Claude Context measurement was made. [Protocol and reproduction](docs/tool-comparison.md) · [machine/environment and summary](benchmarks/tool-comparison.json) · [all 96 query records](benchmarks/tool-comparison-queries.jsonl).
|
|
72
|
+
|
|
73
|
+
**The extra value is an indexed SQL → C# → page relation report.** For supported patterns, one `data-access` query returns direct/procedure-mediated access, controller actions, page links, and confidence labels. Claude can also follow these links through multiple Grep searches and file reads; this tool packages that investigation into a repeatable CLI/MCP result.
|
|
74
|
+
|
|
75
|
+
| Tool / workflow | Strong fit | Trade-off and where this project helps |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| Claude + Grep / ripgrep | Exact identifiers, strings, and regex; no index setup | Keep it for direct text checks. This project's SQL/call/page relations go beyond the literal table-name matches. |
|
|
78
|
+
| [Serena](https://github.com/oraios/serena) with LSP / JetBrains | Backend-driven symbols, references, and editing/refactoring | Prefer compiler/IDE semantics for accurate renames and overloads. This project provides a focused SQL maintenance report without a language-server backend. |
|
|
79
|
+
| [Claude Context](https://github.com/zilliztech/claude-context) | Natural-language hybrid BM25 + dense-vector retrieval | Its documented setup uses an embedding provider and Milvus/Zilliz configuration; local providers are supported. This project's default needs no embedding API or vector server, but identifier-oriented hashing can miss paraphrases. |
|
|
80
|
+
| Local Codebase Indexer | SQL Server table/procedure → C# accessors → actions/pages; schema and Git impact | Approximate static analysis with visible confidence; no Roslyn overload resolution or semantic rename. |
|
|
81
|
+
|
|
82
|
+
The controller and Razor page in the demo contain no literal table name; the relation report reaches them through the stored procedure and C# calls. All **4 built-in relationship checks pass**. See [source evidence and upstream feature references](docs/tool-comparison.md).
|
|
83
|
+
|
|
57
84
|
## Try it in three steps
|
|
58
85
|
|
|
59
86
|
Python **3.10+**. Run these in a virtual environment; no SQL Server, .NET runtime, model download, or API key is needed for the demo.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Local Codebase Indexer
|
|
2
2
|
|
|
3
|
-
**English** | [繁體中文](
|
|
3
|
+
**English** | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)
|
|
4
4
|
|
|
5
5
|
**Which C# code and pages reach this SQL Server table?**
|
|
6
6
|
|
|
@@ -10,6 +10,33 @@ Trace tables and stored procedures to repositories, controller actions, and Razo
|
|
|
10
10
|
|
|
11
11
|
[Case study and raw results](https://github.com/sfy257000/local-codebase-indexer/blob/main/docs/case-study.md) · [CLI reference](https://github.com/sfy257000/local-codebase-indexer/blob/main/docs/reference.md) · [PyPI](https://pypi.org/project/local-codebase-indexer/) · [MIT license](https://github.com/sfy257000/local-codebase-indexer/blob/main/LICENSE)
|
|
12
12
|
|
|
13
|
+
## How it compares with Claude's Grep and similar tools
|
|
14
|
+
|
|
15
|
+
**Measured on our MES fixtures: +9.5–10.7 percentage points in relevant-file recall versus `rg + BM25`.** For the bundled SQL → C# → page investigation, the relation report covers **5/5 required evidence files**, versus **3/5** from one literal table-name search (**+40 points**).
|
|
16
|
+
|
|
17
|
+
| Fixed retrieval suite | `rg + BM25` file Recall@5 | This project | Difference |
|
|
18
|
+
|---|---:|---:|---:|
|
|
19
|
+
| MES-style synthetic: 42 questions, 24 files | 81.0% | **91.7%** | **+10.7 pp** |
|
|
20
|
+
| Same 42 questions with distractors: 109 files | 81.0% | **90.5%** | **+9.5 pp** |
|
|
21
|
+
| Python stdlib: 12 questions, 85 real source files | **100.0%** | 79.2% | −20.8 pp |
|
|
22
|
+
|
|
23
|
+
Recall means the fraction of known relevant files retrieved, averaged over questions. The baseline runs real ripgrep with generic query-term splitting and BM25 ranking; it is not Claude's agent. This project uses default hashing and 5 result chunks; the baseline returns 5 files. Both are scored at file level. These are 54 unique, project-authored questions (96 executions including the repeated noisy suite), not a general accuracy guarantee.
|
|
24
|
+
|
|
25
|
+
**Less source to read:** on the noisy MES and stdlib suites, rendered search results contain **94.9% / 96.9% fewer characters** than reading the same selected files in full. Tiny synthetic files instead produce **2.3% more** characters. This measures output size against whole-file reading, not savings against Grep snippets or Claude tokens.
|
|
26
|
+
|
|
27
|
+
**Cost of the richer report:** the demo CLI takes **244.5 ms** warm versus **8.3 ms** for one literal `rg` call (three-run medians; first indexer call **266.1 ms** including indexing). It adds controller/page evidence, not a speed win. The controller path is `probable`, not runtime proof. No end-to-end Claude, Serena, or Claude Context measurement was made. [Protocol and reproduction](docs/tool-comparison.md) · [machine/environment and summary](benchmarks/tool-comparison.json) · [all 96 query records](benchmarks/tool-comparison-queries.jsonl).
|
|
28
|
+
|
|
29
|
+
**The extra value is an indexed SQL → C# → page relation report.** For supported patterns, one `data-access` query returns direct/procedure-mediated access, controller actions, page links, and confidence labels. Claude can also follow these links through multiple Grep searches and file reads; this tool packages that investigation into a repeatable CLI/MCP result.
|
|
30
|
+
|
|
31
|
+
| Tool / workflow | Strong fit | Trade-off and where this project helps |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| Claude + Grep / ripgrep | Exact identifiers, strings, and regex; no index setup | Keep it for direct text checks. This project's SQL/call/page relations go beyond the literal table-name matches. |
|
|
34
|
+
| [Serena](https://github.com/oraios/serena) with LSP / JetBrains | Backend-driven symbols, references, and editing/refactoring | Prefer compiler/IDE semantics for accurate renames and overloads. This project provides a focused SQL maintenance report without a language-server backend. |
|
|
35
|
+
| [Claude Context](https://github.com/zilliztech/claude-context) | Natural-language hybrid BM25 + dense-vector retrieval | Its documented setup uses an embedding provider and Milvus/Zilliz configuration; local providers are supported. This project's default needs no embedding API or vector server, but identifier-oriented hashing can miss paraphrases. |
|
|
36
|
+
| Local Codebase Indexer | SQL Server table/procedure → C# accessors → actions/pages; schema and Git impact | Approximate static analysis with visible confidence; no Roslyn overload resolution or semantic rename. |
|
|
37
|
+
|
|
38
|
+
The controller and Razor page in the demo contain no literal table name; the relation report reaches them through the stored procedure and C# calls. All **4 built-in relationship checks pass**. See [source evidence and upstream feature references](docs/tool-comparison.md).
|
|
39
|
+
|
|
13
40
|
## Try it in three steps
|
|
14
41
|
|
|
15
42
|
Python **3.10+**. Run these in a virtual environment; no SQL Server, .NET runtime, model download, or API key is needed for the demo.
|
|
@@ -10,6 +10,33 @@
|
|
|
10
10
|
|
|
11
11
|
[可复现案例及完整输出](docs/case-study.md) · [进阶手册](docs/reference.zh-CN.md) · [PyPI](https://pypi.org/project/local-codebase-indexer/) · [MIT 许可](LICENSE)
|
|
12
12
|
|
|
13
|
+
## 与 Claude 的 Grep 及类似工具比较
|
|
14
|
+
|
|
15
|
+
**在本项目的 MES 测试集,相关文件召回率比 `rg + BM25` 高 9.5~10.7 个百分点。** 内置 SQL → C# → 页面调查场景中,关系报告覆盖 **5/5 个必要证据文件**,单次表名字面搜索为 **3/5**,覆盖率 **60% → 100%(+40 个百分点)**。
|
|
16
|
+
|
|
17
|
+
| 固定搜索测试集 | `rg + BM25` 文件 Recall@5 | 本项目 | 差异 |
|
|
18
|
+
|---|---:|---:|---:|
|
|
19
|
+
| MES 风格合成数据:42 题、24 个文件 | 81.0% | **91.7%** | **+10.7 个百分点** |
|
|
20
|
+
| 相同 42 题加入干扰来源:109 个文件 | 81.0% | **90.5%** | **+9.5 个百分点** |
|
|
21
|
+
| Python 标准库:12 题、85 个真实源代码文件 | **100.0%** | 79.2% | −20.8 个百分点 |
|
|
22
|
+
|
|
23
|
+
召回率是每题找回的已知相关文件比例,再取平均。基准实际运行 ripgrep,以通用查询拆词及 BM25 排序,并非 Claude agent。本项目使用默认 hashing、取 5 个结果块;基准取 5 个文件,双方都按文件评分。共 54 个由本项目编写的不同题目(含重跑干扰集共 96 次),不代表通用准确率保证。
|
|
24
|
+
|
|
25
|
+
**减少需要阅读的源代码:** 在含干扰的 MES 与标准库测试集,搜索结果文本比“完整读取同一批选中文件”少 **94.9%/96.9% 字符**;极小的合成文件反而多 **2.3%**。这是相对于整文件读取的输出大小,并非相对 Grep 片段或 Claude token 的节省量。
|
|
26
|
+
|
|
27
|
+
**较完整报告的成本:** demo CLI 暖查询 **244.5 ms**,单次字面 `rg` 为 **8.3 ms**(各测量 3 次取中位数;本项目首次查询含建索引为 **266.1 ms**)。提升在于多追到 Controller/页面;速度较慢。Controller 路径标为 `probable`,不代表运行时证明。尚未测量完整 Claude、Serena 或 Claude Context 流程。[方法与重跑命令](docs/tool-comparison.md) · [机器环境与汇总数据](benchmarks/tool-comparison.json) · [全部 96 条逐题记录](benchmarks/tool-comparison-queries.jsonl)。
|
|
28
|
+
|
|
29
|
+
**这个项目多提供的是 SQL → C# → 页面的索引关系报告。** 在支持的代码模式中,一次 `data-access` 查询就能列出直接/通过存储过程的访问、Controller Action、页面与置信度标签。Claude 也能通过多轮 Grep 和读文件追踪关系;该工具将这段调查整理成可重复执行的 CLI/MCP 结果。
|
|
30
|
+
|
|
31
|
+
| 工具/流程 | 适合用途 | 取舍与本项目的用途 |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| Claude+Grep/ripgrep | 精确标识符、字符串和正则表达式,无需建立索引 | 直接核对文本仍优先使用。该项目另提供字面表名以外的 SQL/调用/页面关系。 |
|
|
34
|
+
| [Serena](https://github.com/oraios/serena)+LSP/JetBrains | 后端提供的符号、引用和编辑/重构 | 精确 rename、重载解析优先使用编译器/IDE 语义。本项目聚焦 SQL 维护报告,无需配置语言服务器。 |
|
|
35
|
+
| [Claude Context](https://github.com/zilliztech/claude-context) | 自然语言的 BM25+dense vector 混合搜索 | 官方配置包含 embedding provider 和 Milvus/Zilliz,也支持本地 provider。本项目默认无需 embedding API 或向量服务器,但 hashing 仍可能遗漏自然语言改写。 |
|
|
36
|
+
| Local Codebase Indexer | SQL Server 表/存储过程 → C# 访问者 → Action/页面,以及 schema、Git impact | 带有置信度标签的近似静态分析,没有 Roslyn 重载解析或语义 rename。 |
|
|
37
|
+
|
|
38
|
+
示例的 Controller 和 Razor 页面不含该表名字符串;关系报告通过存储过程和 C# 调用追踪到它们,**4 项内置关系检查通过**。[源代码证据与上游功能资料](docs/tool-comparison.md)。
|
|
39
|
+
|
|
13
40
|
## 三步开始
|
|
14
41
|
|
|
15
42
|
需要 **Python 3.10+**,建议在虚拟环境执行。内置 demo 不需要 SQL Server、.NET 运行环境、模型下载或 API key。
|
|
@@ -10,6 +10,33 @@
|
|
|
10
10
|
|
|
11
11
|
[可重現案例與完整輸出](docs/case-study.md) · [進階手冊](docs/reference.zh-TW.md) · [PyPI](https://pypi.org/project/local-codebase-indexer/) · [MIT 授權](LICENSE)
|
|
12
12
|
|
|
13
|
+
## 與 Claude 的 Grep 及類似工具比較
|
|
14
|
+
|
|
15
|
+
**在本專案的 MES 測試集,相關檔案召回率比 `rg + BM25` 高 9.5~10.7 個百分點。** 內建 SQL → C# → 頁面調查情境中,關係報告涵蓋 **5/5 個必要證據檔案**,單次表名字面搜尋為 **3/5**,涵蓋率 **60% → 100%(+40 個百分點)**。
|
|
16
|
+
|
|
17
|
+
| 固定搜尋測試集 | `rg + BM25` 檔案 Recall@5 | 本專案 | 差異 |
|
|
18
|
+
|---|---:|---:|---:|
|
|
19
|
+
| MES 風格合成資料:42 題、24 個檔案 | 81.0% | **91.7%** | **+10.7 個百分點** |
|
|
20
|
+
| 相同 42 題加入干擾來源:109 個檔案 | 81.0% | **90.5%** | **+9.5 個百分點** |
|
|
21
|
+
| Python 標準函式庫:12 題、85 個真實原始碼檔案 | **100.0%** | 79.2% | −20.8 個百分點 |
|
|
22
|
+
|
|
23
|
+
召回率是每題找回的已知相關檔案比例,再取平均。基準實際執行 ripgrep,以通用查詢拆詞及 BM25 排序,並非 Claude agent。本專案使用預設 hashing、取 5 個結果區塊;基準取 5 個檔案,雙方都以檔案計分。共 54 個由本專案編寫的不同題目(含重跑干擾集共 96 次),不代表通用準確率保證。
|
|
24
|
+
|
|
25
|
+
**減少需要閱讀的原始碼:** 在含干擾的 MES 與標準函式庫測試集,搜尋結果文字比「完整讀取同一批選中檔案」少 **94.9%/96.9% 字元**;極小的合成檔案反而多 **2.3%**。這是相對於整檔讀取的輸出大小,並非相對 Grep 摘錄或 Claude token 的節省量。
|
|
26
|
+
|
|
27
|
+
**較完整報告的成本:** demo CLI 暖查詢 **244.5 ms**,單次字面 `rg` 為 **8.3 ms**(各量測 3 次取中位數;本專案首次查詢含建索引為 **266.1 ms**)。提升在於多追到 Controller/頁面;速度較慢。Controller 路徑標為 `probable`,不代表執行期證明。尚未量測完整 Claude、Serena 或 Claude Context 流程。[方法與重跑命令](docs/tool-comparison.md) · [機器環境與彙總數據](benchmarks/tool-comparison.json) · [全部 96 筆逐題紀錄](benchmarks/tool-comparison-queries.jsonl)。
|
|
28
|
+
|
|
29
|
+
**這個專案多提供的是 SQL → C# → 頁面的索引關係報告。** 在支援的程式模式中,一次 `data-access` 查詢就能列出直接/透過預存程序的存取、Controller Action、頁面與信心標籤。Claude 也能透過多輪 Grep 與讀檔追出關係;此工具把這段調查整理成可重複執行的 CLI/MCP 結果。
|
|
30
|
+
|
|
31
|
+
| 工具/流程 | 適合用途 | 取捨與本專案的用途 |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| Claude+Grep/ripgrep | 精確識別字、字串與正規表示式,不需建索引 | 直接核對文字仍優先使用。此專案另提供字面資料表名稱以外的 SQL/呼叫/頁面關係。 |
|
|
34
|
+
| [Serena](https://github.com/oraios/serena)+LSP/JetBrains | 後端提供的符號、引用與編輯/重構 | 精確 rename、多載解析優先使用編譯器/IDE 語意。本專案聚焦 SQL 維護報告,不需設定語言伺服器。 |
|
|
35
|
+
| [Claude Context](https://github.com/zilliztech/claude-context) | 自然語言的 BM25+dense vector 混合搜尋 | 官方設定含 embedding provider 與 Milvus/Zilliz,也支援本機 provider。本專案預設不需 embedding API 或向量伺服器,但 hashing 仍可能漏掉自然語言改寫。 |
|
|
36
|
+
| Local Codebase Indexer | SQL Server 表/預存程序 → C# 存取者 → Action/頁面,以及 schema、Git impact | 帶有信心標籤的近似靜態分析,沒有 Roslyn 多載解析或語意 rename。 |
|
|
37
|
+
|
|
38
|
+
範例的 Controller 與 Razor 頁面沒有該表名字串;關係報告透過預存程序與 C# 呼叫追到它們,**4 項內建關係檢查通過**。[原始碼證據與上游功能資料](docs/tool-comparison.md)。
|
|
39
|
+
|
|
13
40
|
## 三步開始
|
|
14
41
|
|
|
15
42
|
需要 **Python 3.10+**,建議在虛擬環境執行。內建 demo 不需要 SQL Server、.NET 執行環境、模型下載或 API key。
|
|
@@ -33,3 +33,19 @@ Expected answers are `file` plus an optional `symbol` suffix. A result is releva
|
|
|
33
33
|
## History
|
|
34
34
|
|
|
35
35
|
- Chinese queries in the noisy corpus: Recall@5 0.50 -> 1.00 after Chinese runs were indexed as character bigrams (SQLite FTS5 keeps a whole run of Chinese characters as one token).
|
|
36
|
+
|
|
37
|
+
## Reproducible comparison with ripgrep + BM25
|
|
38
|
+
|
|
39
|
+
The optional `compare_tools.py` runner uses the same frozen questions/corpora and an actual ripgrep candidate search with generic tokenization and BM25 ranking. Install `rg` separately; it is not a product dependency.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python -m pip install -e ".[dev]"
|
|
43
|
+
python benchmarks/compare_tools.py --repeats 3 --navigation \
|
|
44
|
+
--save /tmp/tool-comparison.json --details /tmp/tool-comparison-queries.jsonl
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Use output paths suitable for your OS. Add `--suite synthetic` for a smaller run. The full run executes 42 synthetic + the same 42 noisy + 12 stdlib questions (54 unique, 96 executions). One warm-up and three measured repetitions per method are the default. `--navigation` also runs a five-evidence-file task through the real CLI, with fresh-index and warm timings. CI runs the synthetic/navigation subset and uploads raw outputs as an artifact.
|
|
48
|
+
|
|
49
|
+
Unlike the existing symbol-aware benchmark, this comparison scores **file-level** Recall@5 and MRR@5 for both methods, ignoring gold symbol suffixes. The indexer retains its default 5 chunks; the baseline returns 5 files. Output reductions use **exact Unicode characters** against whole reads of the **same indexer-selected files**, not model tokens or Grep output. In-process indexer timings and subprocess baseline timings have different boundaries; only the separate navigation task measures both CLI processes. This is not a Claude agent, Serena, or Claude Context head-to-head test.
|
|
50
|
+
|
|
51
|
+
[Recorded summary](tool-comparison.json) · [96 per-query records](tool-comparison-queries.jsonl) · [complete protocol, results, losses, and limitations](../docs/tool-comparison.md). The sample shows +10.7 / +9.5 percentage points of file recall on MES fixtures, and −20.8 points on stdlib. Corpus/source/dataset hashes and runtime versions are recorded. Keep gold answers fixed when comparing changes; do not rerun only until a favorable timing appears.
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Matched file-retrieval comparison against ripgrep + BM25, not a Claude agent test.
|
|
3
|
+
|
|
4
|
+
Queries/gold come unchanged from the existing suites. Both methods get the same
|
|
5
|
+
files/query; relevance is scored at file level for both (symbol suffixes ignored).
|
|
6
|
+
The wrapper gives rg a deterministic ranking it does not natively provide.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import math
|
|
14
|
+
import os
|
|
15
|
+
import platform
|
|
16
|
+
import re
|
|
17
|
+
import shutil
|
|
18
|
+
import sqlite3
|
|
19
|
+
import statistics
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
import tempfile
|
|
23
|
+
import time
|
|
24
|
+
from collections import Counter
|
|
25
|
+
from datetime import datetime, timezone
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
HERE = Path(__file__).resolve().parent
|
|
29
|
+
sys.path.insert(0, str(HERE.parent))
|
|
30
|
+
sys.path.insert(0, str(HERE))
|
|
31
|
+
|
|
32
|
+
from run_benchmark import prepare_corpus # noqa: E402
|
|
33
|
+
|
|
34
|
+
from local_codebase_indexer import __version__ # noqa: E402
|
|
35
|
+
from local_codebase_indexer import db as dbmod # noqa: E402
|
|
36
|
+
from local_codebase_indexer.demo import _copy_sample # noqa: E402
|
|
37
|
+
from local_codebase_indexer.embedder import HashingEmbedder # noqa: E402
|
|
38
|
+
from local_codebase_indexer.query import CodebaseTools, render_search # noqa: E402
|
|
39
|
+
from local_codebase_indexer.textdecode import decode_bytes # noqa: E402
|
|
40
|
+
|
|
41
|
+
# Generic query stop words, not domain synonyms or terms learned from gold.
|
|
42
|
+
STOP = set('a an the of to in is are for and or where do we how what which that this with on it be does can find show me by at as from into i my our there when who so up'.split())
|
|
43
|
+
WORDS = re.compile(r'[A-Z]+(?=[A-Z][a-z]|[0-9]|$)|[A-Z]?[a-z]+|[0-9]+')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def lexemes(text: str) -> list[str]:
|
|
47
|
+
result = []
|
|
48
|
+
for word in re.findall(r'[A-Za-z_][A-Za-z0-9_]*|[\u4e00-\u9fff]+|\d+', text):
|
|
49
|
+
if re.fullmatch(r'[\u4e00-\u9fff]+', word):
|
|
50
|
+
candidates = [word[i:i + 2] for i in range(len(word) - 1)] or [word]
|
|
51
|
+
else:
|
|
52
|
+
candidates = [word.lower(), *[part.lower() for piece in word.split('_') for part in WORDS.findall(piece)]]
|
|
53
|
+
# Deduplicate within one identifier occurrence, not across the document.
|
|
54
|
+
result.extend(candidate for candidate in dict.fromkeys(candidates) if len(candidate) > 1 and candidate not in STOP)
|
|
55
|
+
return result
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def terms(text: str) -> list[str]:
|
|
59
|
+
return list(dict.fromkeys(lexemes(text)))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def file_scores(paths: list[str], gold: set[str], k: int = 5) -> dict:
|
|
63
|
+
if not gold:
|
|
64
|
+
raise ValueError('Gold files must not be empty')
|
|
65
|
+
ranked = list(dict.fromkeys(paths))[:k]
|
|
66
|
+
found = gold.intersection(ranked)
|
|
67
|
+
first = next((i for i, path in enumerate(ranked, 1) if path in gold), None)
|
|
68
|
+
return {'recall5': len(found) / len(gold), 'rr5': 1 / first if first else 0.0,
|
|
69
|
+
'found_files': sorted(found), 'top_files': ranked}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def reduction_percent(actual: int, reference: int) -> float | None:
|
|
73
|
+
return 100 * (1 - actual / reference) if reference else None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class RipgrepBM25:
|
|
77
|
+
"""Actual rg candidate files + BM25 (k1=1.2, b=.75); no gold-aware rewriting."""
|
|
78
|
+
def __init__(self, root: Path, files: dict[str, str], executable: str):
|
|
79
|
+
self.root, self.files, self.executable = root, files, executable
|
|
80
|
+
self.counts = {path: Counter(lexemes(text)) for path, text in files.items()}
|
|
81
|
+
self.lengths = {path: sum(counter.values()) for path, counter in self.counts.items()}
|
|
82
|
+
self.frequency = Counter(word for counter in self.counts.values() for word in counter)
|
|
83
|
+
self.mean_length = statistics.mean(self.lengths.values()) or 1
|
|
84
|
+
|
|
85
|
+
def search(self, query: str) -> list[str]:
|
|
86
|
+
words = terms(query)
|
|
87
|
+
if not words:
|
|
88
|
+
return []
|
|
89
|
+
pattern = '|'.join(re.escape(word) for word in sorted(words, key=lambda word: (-len(word), word)))
|
|
90
|
+
command = [self.executable, '--no-config', '--files-with-matches', '--text', '--ignore-case', '-e', pattern,
|
|
91
|
+
'--', *sorted(self.files)]
|
|
92
|
+
proc = subprocess.run(command, cwd=self.root, capture_output=True, text=True, encoding='utf-8', timeout=60)
|
|
93
|
+
if proc.returncode not in (0, 1):
|
|
94
|
+
raise RuntimeError('ripgrep failed: ' + proc.stderr)
|
|
95
|
+
scores = {}
|
|
96
|
+
for line in proc.stdout.splitlines():
|
|
97
|
+
path = line.replace('\\', '/')
|
|
98
|
+
score = 0.0
|
|
99
|
+
norm = 1.2 * (1 - 0.75 + 0.75 * self.lengths[path] / self.mean_length)
|
|
100
|
+
for word in words:
|
|
101
|
+
count = self.counts[path][word]
|
|
102
|
+
if count:
|
|
103
|
+
idf = math.log(1 + (len(self.files) - self.frequency[word] + 0.5) / (self.frequency[word] + 0.5))
|
|
104
|
+
score += idf * count * 2.2 / (count + norm)
|
|
105
|
+
if score:
|
|
106
|
+
scores[path] = score
|
|
107
|
+
return sorted(scores, key=lambda path: (-scores[path], path))[:5]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _mean(rows: list[dict], method: str, key: str) -> float:
|
|
111
|
+
return statistics.mean(row[method][key] for row in rows)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def summarize(rows: list[dict]) -> dict:
|
|
115
|
+
result = {}
|
|
116
|
+
for method in ('rg_bm25', 'indexer'):
|
|
117
|
+
result[method] = {'file_recall5': _mean(rows, method, 'recall5'),
|
|
118
|
+
'file_mrr5': _mean(rows, method, 'rr5'),
|
|
119
|
+
'median_query_ms': statistics.median(value for row in rows for value in row[method]['query_ms'])}
|
|
120
|
+
result['recall_gain_pp'] = 100 * (result['indexer']['file_recall5'] - result['rg_bm25']['file_recall5'])
|
|
121
|
+
snippets = sum(row['indexer']['output_chars'] for row in rows)
|
|
122
|
+
whole = sum(row['indexer']['same_files_full_read_chars'] for row in rows)
|
|
123
|
+
result['context'] = {'returned_chars': snippets, 'same_files_full_read_chars': whole,
|
|
124
|
+
'reduction_pct': reduction_percent(snippets, whole)}
|
|
125
|
+
return result
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def compare_suite(name: str, repeats: int, workdir: str, rg: str) -> tuple[dict, list[dict]]:
|
|
129
|
+
query_file = HERE / ('queries_stdlib.json' if name == 'stdlib' else 'queries_synthetic.json')
|
|
130
|
+
dataset = json.loads(query_file.read_text(encoding='utf-8'))
|
|
131
|
+
root = Path(prepare_corpus(dataset, name, name == 'synthetic-noisy', workdir))
|
|
132
|
+
shutil.rmtree(root / '.ai_context', ignore_errors=True)
|
|
133
|
+
tools = CodebaseTools(str(root), auto_refresh=False, embedder=HashingEmbedder())
|
|
134
|
+
try:
|
|
135
|
+
start = time.perf_counter()
|
|
136
|
+
stats = tools.refresh()
|
|
137
|
+
index_ms = (time.perf_counter() - start) * 1000
|
|
138
|
+
if stats.failed:
|
|
139
|
+
raise RuntimeError('Indexing failed: ' + '; '.join(stats.warnings))
|
|
140
|
+
files = {row[0]: decode_bytes((root / row[0]).read_bytes()) for row in tools.conn.execute('SELECT file_path FROM files')}
|
|
141
|
+
corpus_hash = hashlib.sha256()
|
|
142
|
+
for path in sorted(files):
|
|
143
|
+
corpus_hash.update(path.encode('utf-8') + b'\0' + files[path].encode('utf-8') + b'\0')
|
|
144
|
+
start = time.perf_counter()
|
|
145
|
+
baseline = RipgrepBM25(root, files, rg)
|
|
146
|
+
baseline_setup_ms = (time.perf_counter() - start) * 1000
|
|
147
|
+
rows = []
|
|
148
|
+
for number, item in enumerate(dataset['queries'], 1):
|
|
149
|
+
query = item['query']
|
|
150
|
+
gold = {answer['file'] for answer in item['relevant']}
|
|
151
|
+
if not gold <= files.keys():
|
|
152
|
+
raise ValueError('Gold files missing from shared corpus')
|
|
153
|
+
# Warm both methods; alternate measured order to reduce cache/order bias.
|
|
154
|
+
baseline.search(query)
|
|
155
|
+
tools.semantic_search(query, limit=5)
|
|
156
|
+
rg_times, indexer_times = [], []
|
|
157
|
+
ranked = []
|
|
158
|
+
response = {}
|
|
159
|
+
for trial in range(repeats):
|
|
160
|
+
for method in (('rg', 'indexer') if trial % 2 == 0 else ('indexer', 'rg')):
|
|
161
|
+
start = time.perf_counter()
|
|
162
|
+
if method == 'rg':
|
|
163
|
+
ranked = baseline.search(query)
|
|
164
|
+
rg_times.append(round((time.perf_counter() - start) * 1000, 3))
|
|
165
|
+
else:
|
|
166
|
+
response = tools.semantic_search(query, limit=5)
|
|
167
|
+
indexer_times.append(round((time.perf_counter() - start) * 1000, 3))
|
|
168
|
+
selected = [hit['file_path'] for hit in response['results']]
|
|
169
|
+
rg_score = file_scores(ranked, gold)
|
|
170
|
+
indexer_score = file_scores(selected, gold)
|
|
171
|
+
# Context comparison holds the selected files fixed. This reference
|
|
172
|
+
# is whole-file reading, not rg's tiny filename output or rg -C.
|
|
173
|
+
whole_chars = sum(len(path) + 1 + len(files[path]) + 1 for path in set(selected))
|
|
174
|
+
rows.append({'suite': name, 'query_number': number, 'category': item['category'],
|
|
175
|
+
'query': query, 'gold_files': sorted(gold), 'keyword_terms': terms(query),
|
|
176
|
+
'rg_bm25': {**rg_score, 'query_ms': rg_times},
|
|
177
|
+
'indexer': {**indexer_score, 'query_ms': indexer_times,
|
|
178
|
+
'output_chars': len(render_search(response)), 'same_files_full_read_chars': whole_chars}})
|
|
179
|
+
return {'queries': len(rows), 'files': len(files), 'chunks': stats.chunks,
|
|
180
|
+
'dataset_sha256': hashlib.sha256(query_file.read_bytes()).hexdigest(),
|
|
181
|
+
'corpus_sha256': corpus_hash.hexdigest(), 'initial_index_ms': index_ms,
|
|
182
|
+
'rg_bm25_setup_ms': baseline_setup_ms, **summarize(rows)}, rows
|
|
183
|
+
finally:
|
|
184
|
+
tools.indexer.close()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def evidence_files(response: dict) -> list[str]:
|
|
189
|
+
paths = set()
|
|
190
|
+
for section in ('definitions', 'readers', 'writers', 'executed_by', 'mapped_by', 'schema_changes',
|
|
191
|
+
'possible', 'programs', 'no_known_caller'):
|
|
192
|
+
for entry in response.get(section, []):
|
|
193
|
+
if entry.get('file_path'):
|
|
194
|
+
paths.add(entry['file_path'])
|
|
195
|
+
paths.update(entry.get('pages', []))
|
|
196
|
+
return sorted(paths)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def compare_navigation(workdir: str, repeats: int, rg: str) -> dict:
|
|
200
|
+
task_file = HERE / 'navigation_task.json'
|
|
201
|
+
task = json.loads(task_file.read_text(encoding='utf-8'))
|
|
202
|
+
root = Path(workdir) / 'navigation'
|
|
203
|
+
_copy_sample(root)
|
|
204
|
+
gold = set(task['required_files'])
|
|
205
|
+
command = [rg, '--no-config', '-l', '-i', '-w', '-F', '-e', task['target'],
|
|
206
|
+
'-g', '*.cs', '-g', '*.sql', '-g', '*.cshtml', '--', str(root)]
|
|
207
|
+
rg_times = []
|
|
208
|
+
rg_paths = []
|
|
209
|
+
for trial in range(repeats + 1):
|
|
210
|
+
start = time.perf_counter()
|
|
211
|
+
proc = subprocess.run(command, capture_output=True, text=True, encoding='utf-8', timeout=60)
|
|
212
|
+
if proc.returncode not in (0, 1):
|
|
213
|
+
raise RuntimeError(proc.stderr)
|
|
214
|
+
if trial:
|
|
215
|
+
rg_times.append(round((time.perf_counter() - start) * 1000, 3))
|
|
216
|
+
rg_paths = sorted(Path(line).relative_to(root).as_posix() for line in proc.stdout.splitlines())
|
|
217
|
+
command = [sys.executable, '-m', 'local_codebase_indexer', '--root', str(root),
|
|
218
|
+
'data-access', task['target'], '--json']
|
|
219
|
+
cli_times = []
|
|
220
|
+
child_env = dict(os.environ)
|
|
221
|
+
child_env.pop('INDEXER_ONNX_MODEL', None) # Fix the measured embedder even with ambient optional settings.
|
|
222
|
+
response = {}
|
|
223
|
+
for trial in range(repeats + 1):
|
|
224
|
+
start = time.perf_counter()
|
|
225
|
+
proc = subprocess.run(command, cwd=HERE.parent, env=child_env, capture_output=True, text=True, encoding='utf-8', timeout=60, check=True)
|
|
226
|
+
elapsed = round((time.perf_counter() - start) * 1000, 3)
|
|
227
|
+
if trial:
|
|
228
|
+
cli_times.append(elapsed)
|
|
229
|
+
else:
|
|
230
|
+
initial_cli_ms = elapsed
|
|
231
|
+
response = json.loads(proc.stdout)
|
|
232
|
+
paths = evidence_files(response)
|
|
233
|
+
rg_coverage = len(gold.intersection(rg_paths)) / len(gold)
|
|
234
|
+
indexer_coverage = len(gold.intersection(paths)) / len(gold)
|
|
235
|
+
return {'sample_kind': 'bundled synthetic fixture; five required evidence files',
|
|
236
|
+
'task_sha256': hashlib.sha256(task_file.read_bytes()).hexdigest(),
|
|
237
|
+
'target': task['target'], 'required_files': sorted(gold),
|
|
238
|
+
'literal_rg': {'files': rg_paths, 'coverage': rg_coverage, 'cli_ms': rg_times},
|
|
239
|
+
'indexer': {'files': paths, 'coverage': indexer_coverage, 'initial_cli_ms': initial_cli_ms,
|
|
240
|
+
'warm_cli_ms': cli_times, 'program_confidence': [p['confidence'] for p in response['programs']]},
|
|
241
|
+
'coverage_gain_pp': 100 * (indexer_coverage - rg_coverage),
|
|
242
|
+
'limitation': 'One table-name grep call, not a multi-step agent or expert-grep workflow; five task-specific required files, not all potentially relevant source.'}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main() -> int:
|
|
246
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
247
|
+
parser.add_argument('--suite', choices=['synthetic', 'synthetic-noisy', 'stdlib', 'all'], default='all')
|
|
248
|
+
parser.add_argument('--repeats', type=int, default=3)
|
|
249
|
+
parser.add_argument('--navigation', action='store_true', help='also measure the source-evidence task and actual CLI latency')
|
|
250
|
+
parser.add_argument('--save', type=Path, required=True)
|
|
251
|
+
parser.add_argument('--details', type=Path, required=True)
|
|
252
|
+
args = parser.parse_args()
|
|
253
|
+
if args.repeats < 1:
|
|
254
|
+
parser.error('--repeats must be positive')
|
|
255
|
+
if args.save.resolve() == args.details.resolve():
|
|
256
|
+
parser.error('--save and --details must be different files')
|
|
257
|
+
rg = shutil.which('rg')
|
|
258
|
+
if not rg:
|
|
259
|
+
parser.error('Install ripgrep (rg) to run this optional comparison')
|
|
260
|
+
source_hash = hashlib.sha256()
|
|
261
|
+
for path in sorted((HERE.parent / 'local_codebase_indexer').glob('*.py')):
|
|
262
|
+
source_hash.update(path.name.encode() + b'\0' + path.read_bytes())
|
|
263
|
+
report = {'schema_version': 1, 'indexer_version': __version__, 'index_format': dbmod.INDEX_VERSION, 'indexer_source_sha256': source_hash.hexdigest(),
|
|
264
|
+
'sqlite_version': sqlite3.sqlite_version, 'recorded_at_utc': datetime.now(timezone.utc).isoformat(), 'python': platform.python_version(), 'platform': platform.platform(),
|
|
265
|
+
'rg_version': subprocess.check_output([rg, '--version'], text=True).splitlines()[0],
|
|
266
|
+
'repeats': args.repeats, 'indexer': 'HashingEmbedder; default 5 chunks; frozen corpus; warm process',
|
|
267
|
+
'baseline': 'rg case-insensitive OR candidates + BM25 token counts (k1=1.2, b=0.75); top 5 files',
|
|
268
|
+
'units': {'quality': 'macro file Recall@5 and file MRR@5; symbols ignored for both methods',
|
|
269
|
+
'latency': 'warm indexer method excludes transport/startup; baseline includes rg subprocess + ranking',
|
|
270
|
+
'context': 'exact Unicode character counts vs full reads of the same indexer-selected files; not model tokens'},
|
|
271
|
+
'limitations': ['Not Claude, Serena, or Claude Context end-to-end runs.',
|
|
272
|
+
'Synthetic queries/corpus/domain synonyms were authored by this project; absolute quality is optimistic.',
|
|
273
|
+
'Noisy suite repeats the same 42 questions; stdlib is real Python source with 12 authored questions.',
|
|
274
|
+
'Timings depend on the machine and are not comparable to CLI/model/agent latency.'],
|
|
275
|
+
'suites': {}}
|
|
276
|
+
details = []
|
|
277
|
+
with tempfile.TemporaryDirectory(prefix='indexer-tool-comparison-') as workdir:
|
|
278
|
+
for name in ['synthetic', 'synthetic-noisy', 'stdlib']:
|
|
279
|
+
if args.suite not in (name, 'all'):
|
|
280
|
+
continue
|
|
281
|
+
summary, rows = compare_suite(name, args.repeats, workdir, rg)
|
|
282
|
+
report['suites'][name] = summary
|
|
283
|
+
details.extend(rows)
|
|
284
|
+
print(name, json.dumps(summary, ensure_ascii=False))
|
|
285
|
+
if args.navigation:
|
|
286
|
+
report['navigation'] = compare_navigation(workdir, args.repeats, rg)
|
|
287
|
+
print('navigation', json.dumps(report['navigation'], ensure_ascii=False))
|
|
288
|
+
args.save.parent.mkdir(parents=True, exist_ok=True)
|
|
289
|
+
args.details.parent.mkdir(parents=True, exist_ok=True)
|
|
290
|
+
args.save.write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
291
|
+
args.details.write_text(''.join(json.dumps(row, ensure_ascii=False) + '\n' for row in details), encoding='utf-8')
|
|
292
|
+
return 0
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if __name__ == '__main__':
|
|
296
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Author-curated synthetic task: return source evidence for the table definition, SQL writer, C# writer, controller entry point, and Razor page. Intermediate service files are not required answers for this particular report task.",
|
|
3
|
+
"target": "Sales_OrderHeader",
|
|
4
|
+
"required_files": [
|
|
5
|
+
"Sql/Sales_OrderHeader.sql",
|
|
6
|
+
"Sql/usp_ApproveOrder.sql",
|
|
7
|
+
"Data/OrderRepository.cs",
|
|
8
|
+
"Controllers/OrdersController.cs",
|
|
9
|
+
"Views/Orders/Details.cshtml"
|
|
10
|
+
]
|
|
11
|
+
}
|