local-codebase-indexer 0.4.0__tar.gz → 0.5.0__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.4.0 → local_codebase_indexer-0.5.0}/AGENTS.md +3 -2
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/CLAUDE.md +3 -2
- {local_codebase_indexer-0.4.0/local_codebase_indexer.egg-info → local_codebase_indexer-0.5.0}/PKG-INFO +10 -5
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/README.md +9 -4
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/README.zh-CN.md +9 -4
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/README.zh-TW.md +9 -4
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/TODO.md +3 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/__init__.py +1 -1
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/cli.py +14 -3
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/core.py +148 -12
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/csdata.py +3 -1
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/dataflow.py +24 -14
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/db.py +10 -2
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/mcp_server.py +19 -3
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/query.py +155 -16
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0/local_codebase_indexer.egg-info}/PKG-INFO +10 -5
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/server.json +2 -2
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/tests/test_dataaccess.py +74 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/tests/test_indexer.py +56 -2
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/MANIFEST.in +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/README.md +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/baseline.json +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Auth/LoginService.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Controllers/LotController.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Controllers/ScrapController.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Data/MesDbContext.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Legacy/frmChangeLine.frm +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Models/DrillBreakEvent.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Models/Lot.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Models/ScrapRecord.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Printing/LabelPrinter.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Repositories/LotRepository.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Repositories/ScrapRepository.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Services/IScrapService.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Services/InspectionService.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Services/LotService.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Services/ScrapService.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Sql/MES_Lot.sql +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Sql/usp_Inspection_Report.sql +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Sql/usp_Lot_UpdateStatus.sql +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Sql/usp_Scrap_Insert.sql +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Utils/DateRangeHelper.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Utils/PartNumberDecoder.cs +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Web/scrapForm.ts +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/Web.config +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/corpus/tools/export_report.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/queries_stdlib.json +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/queries_synthetic.json +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/benchmarks/run_benchmark.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/index.md +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/llms.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/__main__.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/callgraph.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/cscalls.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/embedder.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/langparse.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/scanner.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/sqlaccess.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/synonyms.py +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer.egg-info/SOURCES.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer.egg-info/dependency_links.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer.egg-info/entry_points.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer.egg-info/requires.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer.egg-info/top_level.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/pyproject.toml +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/requirements.txt +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/setup.cfg +0 -0
- {local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/tests/test_onnx_plumbing.py +0 -0
|
@@ -18,7 +18,8 @@ Check: `local-codebase-indexer --help`. No API keys or network access are needed
|
|
|
18
18
|
local-codebase-indexer --root <project> index # build / refresh the index
|
|
19
19
|
local-codebase-indexer --root <project> search "natural language or identifier" --limit 5
|
|
20
20
|
local-codebase-indexer --root <project> relations <SymbolName> --direction both
|
|
21
|
-
local-codebase-indexer --root <project> data-access <TableOrProcedure> # who reads / writes / executes it
|
|
21
|
+
local-codebase-indexer --root <project> data-access <TableOrProcedure> # who reads / writes / executes it, which programs and pages reach it
|
|
22
|
+
local-codebase-indexer --root <project> impact [base] # what a diff touches: symbols, tables, programs, pages
|
|
22
23
|
local-codebase-indexer --root <project> context <file> --lines 120 --padding 15
|
|
23
24
|
local-codebase-indexer --root <project> status # is the index fresh?
|
|
24
25
|
```
|
|
@@ -31,7 +32,7 @@ Put `--json` before the subcommand for JSON output. The index lives in `<project
|
|
|
31
32
|
claude mcp add local-indexer -- local-codebase-indexer --root <project> serve
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
Tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_index_status`.
|
|
35
|
+
Tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_impact_analysis`, `codebase_index_status`.
|
|
35
36
|
|
|
36
37
|
## Reading the results
|
|
37
38
|
|
|
@@ -18,7 +18,8 @@ Check: `local-codebase-indexer --help`. No API keys or network access are needed
|
|
|
18
18
|
local-codebase-indexer --root <project> index # build / refresh the index
|
|
19
19
|
local-codebase-indexer --root <project> search "natural language or identifier" --limit 5
|
|
20
20
|
local-codebase-indexer --root <project> relations <SymbolName> --direction both
|
|
21
|
-
local-codebase-indexer --root <project> data-access <TableOrProcedure> # who reads / writes / executes it
|
|
21
|
+
local-codebase-indexer --root <project> data-access <TableOrProcedure> # who reads / writes / executes it, which programs and pages reach it
|
|
22
|
+
local-codebase-indexer --root <project> impact [base] # what a diff touches: symbols, tables, programs, pages
|
|
22
23
|
local-codebase-indexer --root <project> context <file> --lines 120 --padding 15
|
|
23
24
|
local-codebase-indexer --root <project> status # is the index fresh?
|
|
24
25
|
```
|
|
@@ -31,7 +32,7 @@ Put `--json` before the subcommand for JSON output. The index lives in `<project
|
|
|
31
32
|
claude mcp add local-indexer -- local-codebase-indexer --root <project> serve
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
Tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_index_status`.
|
|
35
|
+
Tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_impact_analysis`, `codebase_index_status`.
|
|
35
36
|
|
|
36
37
|
## Reading the results
|
|
37
38
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: local-codebase-indexer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Local codebase indexer and context provider for AI coding assistants: MCP server and CLI with SQL data-access and C# call relations. No cloud, no server.
|
|
5
5
|
Author: sfy257000
|
|
6
6
|
Project-URL: Homepage, https://github.com/sfy257000/local-codebase-indexer
|
|
@@ -61,7 +61,8 @@ local-codebase-indexer --root <project> index # build / in
|
|
|
61
61
|
local-codebase-indexer search "database mapping for LotNo" --limit 5
|
|
62
62
|
local-codebase-indexer relations IExistOpenHandleService --direction both # upstream | downstream | both
|
|
63
63
|
local-codebase-indexer context Services/LotService.cs --lines 120 --padding 15 # alias: slice
|
|
64
|
-
local-codebase-indexer data-access MES_Lot # who reads / writes / executes a table or procedure; what a procedure touches
|
|
64
|
+
local-codebase-indexer data-access MES_Lot # who reads / writes / executes a table or procedure; what a procedure touches (--full: every entry)
|
|
65
|
+
local-codebase-indexer impact main...HEAD # symbols, tables, programs and pages a change touches (no argument: uncommitted work)
|
|
65
66
|
local-codebase-indexer stats
|
|
66
67
|
local-codebase-indexer status # is the index fresh? failed files, git commit, consistency checks
|
|
67
68
|
```
|
|
@@ -78,7 +79,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
78
79
|
# without installing: claude mcp add local-indexer -- uvx local-codebase-indexer --root /path/to/project serve
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
`serve` speaks JSON-RPC (MCP) over stdio and exposes
|
|
82
|
+
`serve` speaks JSON-RPC (MCP) over stdio and exposes six tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_impact_analysis`, `codebase_index_status`. A long-lived server re-checks the index before a query when the last check is older than 15 s (a no-op check takes about a second on a few thousand files). `codebase_get_data_access` returns a summary (5 entries per section, every program) unless `detail` is set; `codebase_semantic_search` lists dependency-graph neighbours only with `related`.
|
|
82
83
|
|
|
83
84
|
## Three-layer index
|
|
84
85
|
|
|
@@ -99,7 +100,7 @@ Encodings: UTF-8 first, then Big5, then cp1252. Files over 5MB are skipped. Root
|
|
|
99
100
|
|
|
100
101
|
## Data access (SQL)
|
|
101
102
|
|
|
102
|
-
`data-access <table-or-procedure>` answers "what writes / reads / executes X". It is built from T-SQL (INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC, with alias resolution; CTEs, temp tables and system objects excluded), from C# SQL strings (literals, `+`, interpolation, `string.Format`, consts, locals, `StringBuilder.Append` / `AppendLine` / `AppendFormat`) passed to Dapper, `SqlCommand` or EF `FromSql`, from stored-procedure names used with `CommandType.StoredProcedure`, from EF LINQ on `DbSet<T>` members (`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`, `from o in ctx.Orders`; `probable`, since only the member name is matched) and from EF `ToTable` / `[Table]` mappings. A procedure's callers are indirect writers of the tables it writes (followed up to 4 hops). `programs` (USED BY PROGRAMS) follows confirmed / probable C# calls upward from those accessors to `*Controller` methods (up to 8 hops) (including from an implementation to the callers of the interface method it implements, for `foreach (var step in steps) step.Run()` pipelines) and groups them per controller file, with the Razor pages (`.cshtml`) whose `Url.Action("Action"[, "Controller"])` or AngularJS `ControllerPath + 'Action'` (controller from `$scope.Controller = 'X'`) targets those actions, so a table maps to the screens that touch it. A method that reads a DbSet and calls `SaveChanges` without an explicit `Add` / `Remove` may update tracked entities; it is listed as a possible (`uncertain`) writer. Each entry has a confidence; **dynamic SQL (`EXEC(@sql)`, `sp_executesql`, SQL built from unknown values) cannot be resolved and is listed separately as `uncertain`**, never mixed into the confirmed lists. Known gaps: `FROM a JOIN b ON ..., c` loses `c`, and a stored-procedure name passed to a non-database method is not seen.
|
|
103
|
+
`data-access <table-or-procedure>` answers "what writes / reads / executes X". It is built from T-SQL (INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC, with alias resolution; CTEs, temp tables and system objects excluded), from C# SQL strings (literals, `+`, interpolation, `string.Format`, consts, locals, `StringBuilder.Append` / `AppendLine` / `AppendFormat`) passed to Dapper, `SqlCommand` or EF `FromSql`, from stored-procedure names used with `CommandType.StoredProcedure`, from EF LINQ on `DbSet<T>` members (`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`, `from o in ctx.Orders`; `probable`, since only the member name is matched) and from EF `ToTable` / `[Table]` mappings. A procedure's callers are indirect writers of the tables it writes (followed up to 4 hops). `programs` (USED BY PROGRAMS) follows confirmed / probable C# calls upward from those accessors to `*Controller` methods (up to 8 hops) (including from an implementation to the callers of the interface method it implements, for `foreach (var step in steps) step.Run()` pipelines) and groups them per controller file, with the Razor pages (`.cshtml`) whose `Url.Action("Action"[, "Controller"])` or AngularJS `ControllerPath + 'Action'` (controller from `$scope.Controller = 'X'`) targets those actions, so a table maps to the screens that touch it. A method that reads a DbSet and calls `SaveChanges` without an explicit `Add` / `Remove` may update tracked entities; it is listed as a possible (`uncertain`) writer. Each entry has a confidence; **dynamic SQL (`EXEC(@sql)`, `sp_executesql`, SQL built from unknown values) cannot be resolved and is listed separately as `uncertain`**, never mixed into the confirmed lists. EF accesses are `confirmed` when the context variable (`using (var db = new X())`, a field or property, or `this`) is typed as a class that declares or inherits the DbSet, `probable` otherwise. Methods on the way up that have no confirmed / probable caller at all are listed under NO KNOWN CALLER: entry points such as API endpoints, jobs or `Main`, or calls the graph could not resolve. Known gaps: `FROM a JOIN b ON ..., c` loses `c`, and a stored-procedure name passed to a non-database method is not seen.
|
|
103
104
|
|
|
104
105
|
Stored procedures that live only in the database can be exported to a folder outside the repo and listed in `.ai_context/extra_roots` (one folder per line, absolute or relative to the root); their files are indexed under their absolute paths.
|
|
105
106
|
|
|
@@ -109,9 +110,13 @@ Natural-language search routes questions such as "who modifies MES_ScrapRecord"
|
|
|
109
110
|
|
|
110
111
|
Queries are expanded with a small synonym dictionary (`SP` / `預存程序` / `stored procedure` / `usp`, table, lot, scrap, ...; `local_codebase_indexer/synonyms.py`). Add or disable groups per project in `.ai_context/synonyms.json`: `{"groups": [["wpnlot", "在製批"]], "disable": ["sp"]}`. This helps abbreviations and Chinese/English terms, not free paraphrase.
|
|
111
112
|
|
|
113
|
+
The index also mines its own dictionary: Chinese bigrams in the comments right above a symbol are paired with the sub-words of its name (`/// 收帳` above `ReceiveLotAsync` gives 收帳 = receive). A pair is kept when at least 5 symbols support it, it covers at least 15% of the symbols commented with the bigram (smoothed) and the word is at least 15x likelier there than overall. On a 30k-chunk C# codebase this yields about 350 pairs (收帳 -> receive, 拆批 -> divide, 油墨 -> ink, 底片 -> film) and raised MRR on paraphrased queries from 0.57 to 0.64.
|
|
114
|
+
|
|
112
115
|
## Index health
|
|
113
116
|
|
|
114
|
-
`status` (also the MCP tool `codebase_index_status`) reports whether the index can be trusted without refreshing it: `fresh`, `stale` (files changed or git HEAD moved since the last update), `degraded` (failed files or an inconsistent database) or `not_indexed`. A file that fails to parse is removed from the index, listed with its error, and retried on every update, so search never returns stale lines for it. `index --force` rebuilds everything.
|
|
117
|
+
`status` (also the MCP tool `codebase_index_status`) reports whether the index can be trusted without refreshing it: `fresh`, `stale` (files changed or git HEAD moved since the last update), `degraded` (failed files or an inconsistent database) or `not_indexed`. A file that fails to parse is removed from the index, listed with its error, and retried on every update, so search never returns stale lines for it. `index --force` rebuilds everything. Status also shows the running version and warns when the package's code changed on disk after the process started (restart the MCP server, i.e. open a new Claude Code session, to run it).
|
|
118
|
+
|
|
119
|
+
Speed (2.3k files, 30k chunks, hashing embedder): full build about 36 s into an empty database, a branch switch that rewrites 400 files about 10 s, a no-op check about 1 s. Each file is written inside a savepoint (atomic), and commits are batched every 500 files.
|
|
115
120
|
|
|
116
121
|
## Benchmark
|
|
117
122
|
|
|
@@ -26,7 +26,8 @@ local-codebase-indexer --root <project> index # build / in
|
|
|
26
26
|
local-codebase-indexer search "database mapping for LotNo" --limit 5
|
|
27
27
|
local-codebase-indexer relations IExistOpenHandleService --direction both # upstream | downstream | both
|
|
28
28
|
local-codebase-indexer context Services/LotService.cs --lines 120 --padding 15 # alias: slice
|
|
29
|
-
local-codebase-indexer data-access MES_Lot # who reads / writes / executes a table or procedure; what a procedure touches
|
|
29
|
+
local-codebase-indexer data-access MES_Lot # who reads / writes / executes a table or procedure; what a procedure touches (--full: every entry)
|
|
30
|
+
local-codebase-indexer impact main...HEAD # symbols, tables, programs and pages a change touches (no argument: uncommitted work)
|
|
30
31
|
local-codebase-indexer stats
|
|
31
32
|
local-codebase-indexer status # is the index fresh? failed files, git commit, consistency checks
|
|
32
33
|
```
|
|
@@ -43,7 +44,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
43
44
|
# without installing: claude mcp add local-indexer -- uvx local-codebase-indexer --root /path/to/project serve
|
|
44
45
|
```
|
|
45
46
|
|
|
46
|
-
`serve` speaks JSON-RPC (MCP) over stdio and exposes
|
|
47
|
+
`serve` speaks JSON-RPC (MCP) over stdio and exposes six tools: `codebase_semantic_search`, `codebase_get_symbol_relations`, `codebase_get_optimized_context`, `codebase_get_data_access`, `codebase_impact_analysis`, `codebase_index_status`. A long-lived server re-checks the index before a query when the last check is older than 15 s (a no-op check takes about a second on a few thousand files). `codebase_get_data_access` returns a summary (5 entries per section, every program) unless `detail` is set; `codebase_semantic_search` lists dependency-graph neighbours only with `related`.
|
|
47
48
|
|
|
48
49
|
## Three-layer index
|
|
49
50
|
|
|
@@ -64,7 +65,7 @@ Encodings: UTF-8 first, then Big5, then cp1252. Files over 5MB are skipped. Root
|
|
|
64
65
|
|
|
65
66
|
## Data access (SQL)
|
|
66
67
|
|
|
67
|
-
`data-access <table-or-procedure>` answers "what writes / reads / executes X". It is built from T-SQL (INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC, with alias resolution; CTEs, temp tables and system objects excluded), from C# SQL strings (literals, `+`, interpolation, `string.Format`, consts, locals, `StringBuilder.Append` / `AppendLine` / `AppendFormat`) passed to Dapper, `SqlCommand` or EF `FromSql`, from stored-procedure names used with `CommandType.StoredProcedure`, from EF LINQ on `DbSet<T>` members (`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`, `from o in ctx.Orders`; `probable`, since only the member name is matched) and from EF `ToTable` / `[Table]` mappings. A procedure's callers are indirect writers of the tables it writes (followed up to 4 hops). `programs` (USED BY PROGRAMS) follows confirmed / probable C# calls upward from those accessors to `*Controller` methods (up to 8 hops) (including from an implementation to the callers of the interface method it implements, for `foreach (var step in steps) step.Run()` pipelines) and groups them per controller file, with the Razor pages (`.cshtml`) whose `Url.Action("Action"[, "Controller"])` or AngularJS `ControllerPath + 'Action'` (controller from `$scope.Controller = 'X'`) targets those actions, so a table maps to the screens that touch it. A method that reads a DbSet and calls `SaveChanges` without an explicit `Add` / `Remove` may update tracked entities; it is listed as a possible (`uncertain`) writer. Each entry has a confidence; **dynamic SQL (`EXEC(@sql)`, `sp_executesql`, SQL built from unknown values) cannot be resolved and is listed separately as `uncertain`**, never mixed into the confirmed lists. Known gaps: `FROM a JOIN b ON ..., c` loses `c`, and a stored-procedure name passed to a non-database method is not seen.
|
|
68
|
+
`data-access <table-or-procedure>` answers "what writes / reads / executes X". It is built from T-SQL (INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC, with alias resolution; CTEs, temp tables and system objects excluded), from C# SQL strings (literals, `+`, interpolation, `string.Format`, consts, locals, `StringBuilder.Append` / `AppendLine` / `AppendFormat`) passed to Dapper, `SqlCommand` or EF `FromSql`, from stored-procedure names used with `CommandType.StoredProcedure`, from EF LINQ on `DbSet<T>` members (`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`, `from o in ctx.Orders`; `probable`, since only the member name is matched) and from EF `ToTable` / `[Table]` mappings. A procedure's callers are indirect writers of the tables it writes (followed up to 4 hops). `programs` (USED BY PROGRAMS) follows confirmed / probable C# calls upward from those accessors to `*Controller` methods (up to 8 hops) (including from an implementation to the callers of the interface method it implements, for `foreach (var step in steps) step.Run()` pipelines) and groups them per controller file, with the Razor pages (`.cshtml`) whose `Url.Action("Action"[, "Controller"])` or AngularJS `ControllerPath + 'Action'` (controller from `$scope.Controller = 'X'`) targets those actions, so a table maps to the screens that touch it. A method that reads a DbSet and calls `SaveChanges` without an explicit `Add` / `Remove` may update tracked entities; it is listed as a possible (`uncertain`) writer. Each entry has a confidence; **dynamic SQL (`EXEC(@sql)`, `sp_executesql`, SQL built from unknown values) cannot be resolved and is listed separately as `uncertain`**, never mixed into the confirmed lists. EF accesses are `confirmed` when the context variable (`using (var db = new X())`, a field or property, or `this`) is typed as a class that declares or inherits the DbSet, `probable` otherwise. Methods on the way up that have no confirmed / probable caller at all are listed under NO KNOWN CALLER: entry points such as API endpoints, jobs or `Main`, or calls the graph could not resolve. Known gaps: `FROM a JOIN b ON ..., c` loses `c`, and a stored-procedure name passed to a non-database method is not seen.
|
|
68
69
|
|
|
69
70
|
Stored procedures that live only in the database can be exported to a folder outside the repo and listed in `.ai_context/extra_roots` (one folder per line, absolute or relative to the root); their files are indexed under their absolute paths.
|
|
70
71
|
|
|
@@ -74,9 +75,13 @@ Natural-language search routes questions such as "who modifies MES_ScrapRecord"
|
|
|
74
75
|
|
|
75
76
|
Queries are expanded with a small synonym dictionary (`SP` / `預存程序` / `stored procedure` / `usp`, table, lot, scrap, ...; `local_codebase_indexer/synonyms.py`). Add or disable groups per project in `.ai_context/synonyms.json`: `{"groups": [["wpnlot", "在製批"]], "disable": ["sp"]}`. This helps abbreviations and Chinese/English terms, not free paraphrase.
|
|
76
77
|
|
|
78
|
+
The index also mines its own dictionary: Chinese bigrams in the comments right above a symbol are paired with the sub-words of its name (`/// 收帳` above `ReceiveLotAsync` gives 收帳 = receive). A pair is kept when at least 5 symbols support it, it covers at least 15% of the symbols commented with the bigram (smoothed) and the word is at least 15x likelier there than overall. On a 30k-chunk C# codebase this yields about 350 pairs (收帳 -> receive, 拆批 -> divide, 油墨 -> ink, 底片 -> film) and raised MRR on paraphrased queries from 0.57 to 0.64.
|
|
79
|
+
|
|
77
80
|
## Index health
|
|
78
81
|
|
|
79
|
-
`status` (also the MCP tool `codebase_index_status`) reports whether the index can be trusted without refreshing it: `fresh`, `stale` (files changed or git HEAD moved since the last update), `degraded` (failed files or an inconsistent database) or `not_indexed`. A file that fails to parse is removed from the index, listed with its error, and retried on every update, so search never returns stale lines for it. `index --force` rebuilds everything.
|
|
82
|
+
`status` (also the MCP tool `codebase_index_status`) reports whether the index can be trusted without refreshing it: `fresh`, `stale` (files changed or git HEAD moved since the last update), `degraded` (failed files or an inconsistent database) or `not_indexed`. A file that fails to parse is removed from the index, listed with its error, and retried on every update, so search never returns stale lines for it. `index --force` rebuilds everything. Status also shows the running version and warns when the package's code changed on disk after the process started (restart the MCP server, i.e. open a new Claude Code session, to run it).
|
|
83
|
+
|
|
84
|
+
Speed (2.3k files, 30k chunks, hashing embedder): full build about 36 s into an empty database, a branch switch that rewrites 400 files about 10 s, a no-op check about 1 s. Each file is written inside a savepoint (atomic), and commits are batched every 500 files.
|
|
80
85
|
|
|
81
86
|
## Benchmark
|
|
82
87
|
|
|
@@ -22,7 +22,8 @@ local-codebase-indexer --root <项目路径> index # 建立
|
|
|
22
22
|
local-codebase-indexer search "database mapping for LotNo" --limit 5
|
|
23
23
|
local-codebase-indexer relations IExistOpenHandleService --direction both # upstream | downstream | both
|
|
24
24
|
local-codebase-indexer context Services/LotService.cs --lines 120 --padding 15 # 别名:slice
|
|
25
|
-
local-codebase-indexer data-access MES_Lot # 谁读 / 写 /
|
|
25
|
+
local-codebase-indexer data-access MES_Lot # 谁读 / 写 / 执行某数据表或存储过程;存储过程碰了哪些数据(--full 列出全部)
|
|
26
|
+
local-codebase-indexer impact main...HEAD # 一次变更动到的符号、数据表、程序与页面(不给参数=未提交的变更)
|
|
26
27
|
local-codebase-indexer stats
|
|
27
28
|
local-codebase-indexer status # 索引是否新鲜、失败文件、git commit、一致性检查
|
|
28
29
|
```
|
|
@@ -39,7 +40,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
39
40
|
# 不安装直接运行:claude mcp add local-indexer -- uvx local-codebase-indexer --root /path/to/project serve
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
`serve` 通过 stdio 提供 JSON-RPC(MCP
|
|
43
|
+
`serve` 通过 stdio 提供 JSON-RPC(MCP),暴露六个工具:`codebase_semantic_search`、`codebase_get_symbol_relations`、`codebase_get_optimized_context`、`codebase_get_data_access`、`codebase_impact_analysis`、`codebase_index_status`。常驻的 server 在距离上次检查超过 15 秒时,查询前会重新检查索引(几千个文件无变动约 1 秒)。`codebase_get_data_access` 默认返回摘要(每区 5 条、程序全列),加 `detail` 才列全部;`codebase_semantic_search` 加 `related` 才附依赖文件。
|
|
43
44
|
|
|
44
45
|
## 三层索引
|
|
45
46
|
|
|
@@ -60,7 +61,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
60
61
|
|
|
61
62
|
## 数据访问(SQL)
|
|
62
63
|
|
|
63
|
-
`data-access <数据表或存储过程>` 回答“谁写入 / 读取 / 执行 X”。数据来源:T-SQL(INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC,含别名解析,排除 CTE、临时表、系统对象)、C# 的 SQL 字符串(字面值、`+`、字符串插值、`string.Format`、常量、局部变量、`StringBuilder.Append` / `AppendLine` / `AppendFormat`)经 Dapper、`SqlCommand` 或 EF `FromSql` 发出、配合 `CommandType.StoredProcedure` 的存储过程名称、对 `DbSet<T>` 成员的 EF LINQ(`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`、`from o in ctx.Orders`;只比对成员名称,所以是 `probable`),以及 EF 的 `ToTable` / `[Table]` 映射。调用某存储过程的代码视为该过程所写数据表的间接写入者(最多追 4 层)。`programs`(USED BY PROGRAMS)沿 confirmed / probable 的 C# 调用往上追到 `*Controller` 方法(最多 8 层),(实现方法也会接到它所实现接口方法的调用者,涵盖 `foreach (var step in steps) step.Run()` 这种管线),按 controller 文件分组,并列出 `Url.Action("Action"[, "Controller"])` 或 AngularJS `ControllerPath + 'Action'`(controller 取自 `$scope.Controller = 'X'`)指向这些 action 的 Razor 页面(`.cshtml`),查一张表就知道哪些画面会动到它。方法读了某 DbSet 又调用 `SaveChanges`、但没有明确 `Add` / `Remove` 时,可能是在更新跟踪中的实体,列为可能(`uncertain`)写入者。每条都有置信等级;**动态 SQL(`EXEC(@sql)`、`sp_executesql`、由未知值组成的 SQL)无法解析,会单独列为 `uncertain
|
|
64
|
+
`data-access <数据表或存储过程>` 回答“谁写入 / 读取 / 执行 X”。数据来源:T-SQL(INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC,含别名解析,排除 CTE、临时表、系统对象)、C# 的 SQL 字符串(字面值、`+`、字符串插值、`string.Format`、常量、局部变量、`StringBuilder.Append` / `AppendLine` / `AppendFormat`)经 Dapper、`SqlCommand` 或 EF `FromSql` 发出、配合 `CommandType.StoredProcedure` 的存储过程名称、对 `DbSet<T>` 成员的 EF LINQ(`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`、`from o in ctx.Orders`;只比对成员名称,所以是 `probable`),以及 EF 的 `ToTable` / `[Table]` 映射。调用某存储过程的代码视为该过程所写数据表的间接写入者(最多追 4 层)。`programs`(USED BY PROGRAMS)沿 confirmed / probable 的 C# 调用往上追到 `*Controller` 方法(最多 8 层),(实现方法也会接到它所实现接口方法的调用者,涵盖 `foreach (var step in steps) step.Run()` 这种管线),按 controller 文件分组,并列出 `Url.Action("Action"[, "Controller"])` 或 AngularJS `ControllerPath + 'Action'`(controller 取自 `$scope.Controller = 'X'`)指向这些 action 的 Razor 页面(`.cshtml`),查一张表就知道哪些画面会动到它。方法读了某 DbSet 又调用 `SaveChanges`、但没有明确 `Add` / `Remove` 时,可能是在更新跟踪中的实体,列为可能(`uncertain`)写入者。每条都有置信等级;**动态 SQL(`EXEC(@sql)`、`sp_executesql`、由未知值组成的 SQL)无法解析,会单独列为 `uncertain`**,不会混进确定的清单。EF 访问在 context 变量(`using (var db = new X())`、字段或属性、`this`)的类型是声明或继承该 DbSet 的类时为 `confirmed`,否则 `probable`。往上追时没有任何 confirmed / probable 调用者的方法列在 NO KNOWN CALLER:可能是 API、计划任务、`Main` 等入口,或是调用图解不出的调用。已知缺口:`FROM a JOIN b ON ..., c` 会漏掉 `c`;把存储过程名称传给非数据库方法时看不到。
|
|
64
65
|
|
|
65
66
|
只存在数据库里的存储过程,可导出到仓库外的文件夹,再写进 `.ai_context/extra_roots`(一行一个文件夹,绝对路径或相对于项目根目录);这些文件以绝对路径索引。
|
|
66
67
|
|
|
@@ -70,9 +71,13 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
70
71
|
|
|
71
72
|
查询会用小型同义词字典扩展(`SP` / `预存程序` / `stored procedure` / `usp`、数据表、批号、报废等;见 `local_codebase_indexer/synonyms.py`)。可在 `.ai_context/synonyms.json` 为项目新增或停用分组:`{"groups": [["wpnlot", "在制批"]], "disable": ["sp"]}`。这对缩写与中英对照有帮助,对自由改写的同义说法没用。
|
|
72
73
|
|
|
74
|
+
索引也会自动挖项目自己的词典:符号正上方注释里的中文双字词,配对符号名称的英文子词(`ReceiveLotAsync` 上面写 `/// 收帳` → 收帳 = receive)。至少 5 个符号支持、在带有该词注释的符号中占 15% 以上(有平滑)、且该英文词在那里出现的概率是整体的 15 倍以上才保留。在 3 万 chunk 的 C# 项目上约得到 350 组(收帳→receive、拆批→divide、油墨→ink、底片→film),换个说法的查询 MRR 由 0.57 提升到 0.64。
|
|
75
|
+
|
|
73
76
|
## 索引健康状态
|
|
74
77
|
|
|
75
|
-
`status`(也是 MCP 工具 `codebase_index_status`)不更新索引,只报告索引是否可信:`fresh`(新鲜)、`stale`(文件有变更或 git HEAD 已移动)、`degraded`(有解析失败的文件或数据库不一致)、`not_indexed`(尚未建立)。解析失败的文件会从索引移除、连同错误原因列出,并在每次更新时重试,所以搜索不会返回它的过期内容。`index --force` 可全部重建。
|
|
78
|
+
`status`(也是 MCP 工具 `codebase_index_status`)不更新索引,只报告索引是否可信:`fresh`(新鲜)、`stale`(文件有变更或 git HEAD 已移动)、`degraded`(有解析失败的文件或数据库不一致)、`not_indexed`(尚未建立)。解析失败的文件会从索引移除、连同错误原因列出,并在每次更新时重试,所以搜索不会返回它的过期内容。`index --force` 可全部重建。status 也会显示运行中的版本;包的代码在进程启动后有改动时会提示重启 MCP server(也就是开新的 Claude Code session)。
|
|
79
|
+
|
|
80
|
+
速度(2.3k 文件、3 万 chunk、hashing 嵌入):空数据库全量约 36 秒,切分支改写 400 个文件约 10 秒,无变动检查约 1 秒。每个文件在 savepoint 内写入(不可分割),每 500 个文件 commit 一次。
|
|
76
81
|
|
|
77
82
|
## 基准测试
|
|
78
83
|
|
|
@@ -22,7 +22,8 @@ local-codebase-indexer --root <專案路徑> index # 建立
|
|
|
22
22
|
local-codebase-indexer search "database mapping for LotNo" --limit 5
|
|
23
23
|
local-codebase-indexer relations IExistOpenHandleService --direction both # upstream | downstream | both
|
|
24
24
|
local-codebase-indexer context Services/LotService.cs --lines 120 --padding 15 # 別名:slice
|
|
25
|
-
local-codebase-indexer data-access MES_Lot # 誰讀 / 寫 /
|
|
25
|
+
local-codebase-indexer data-access MES_Lot # 誰讀 / 寫 / 執行某資料表或預存程序;預存程序碰了哪些資料(--full 列出全部)
|
|
26
|
+
local-codebase-indexer impact main...HEAD # 一次變更動到的符號、資料表、程式與頁面(不給參數=未提交的變更)
|
|
26
27
|
local-codebase-indexer stats
|
|
27
28
|
local-codebase-indexer status # 索引是否新鮮、失敗檔案、git commit、一致性檢查
|
|
28
29
|
```
|
|
@@ -39,7 +40,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
39
40
|
# 不安裝直接跑:claude mcp add local-indexer -- uvx local-codebase-indexer --root /path/to/project serve
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
`serve` 以 stdio 提供 JSON-RPC(MCP
|
|
43
|
+
`serve` 以 stdio 提供 JSON-RPC(MCP),暴露六個工具:`codebase_semantic_search`、`codebase_get_symbol_relations`、`codebase_get_optimized_context`、`codebase_get_data_access`、`codebase_impact_analysis`、`codebase_index_status`。長駐的 server 在距離上次檢查超過 15 秒時,查詢前會重新檢查索引(幾千個檔案無變動約 1 秒)。`codebase_get_data_access` 預設回摘要(每區 5 筆、程式全列),加 `detail` 才列全部;`codebase_semantic_search` 加 `related` 才附相依檔案。
|
|
43
44
|
|
|
44
45
|
## 三層索引
|
|
45
46
|
|
|
@@ -60,7 +61,7 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
60
61
|
|
|
61
62
|
## 資料存取(SQL)
|
|
62
63
|
|
|
63
|
-
`data-access <資料表或預存程序>` 回答「誰寫入 / 讀取 / 執行 X」。資料來源:T-SQL(INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC,含別名解析,排除 CTE、暫存表、系統物件)、C# 的 SQL 字串(字面值、`+`、字串內插、`string.Format`、常數、區域變數、`StringBuilder.Append` / `AppendLine` / `AppendFormat`)經 Dapper、`SqlCommand` 或 EF `FromSql` 送出、搭配 `CommandType.StoredProcedure` 的 SP 名稱、對 `DbSet<T>` 成員的 EF LINQ(`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`、`from o in ctx.Orders`;只比對成員名稱,所以是 `probable`),以及 EF 的 `ToTable` / `[Table]` 對應。呼叫某 SP 的程式視為該 SP 所寫資料表的間接寫入者(最多追 4 層)。`programs`(USED BY PROGRAMS)沿 confirmed / probable 的 C# 呼叫往上追到 `*Controller` 方法(最多 8 層),(實作方法也會接到它所實作介面方法的呼叫者,涵蓋 `foreach (var step in steps) step.Run()` 這種管線),依 controller 檔案分組,並列出 `Url.Action("Action"[, "Controller"])` 或 AngularJS `ControllerPath + 'Action'`(controller 取自 `$scope.Controller = 'X'`)指向這些 action 的 Razor 頁面(`.cshtml`),查一張表就知道哪些畫面會動到它。方法讀了某 DbSet 又呼叫 `SaveChanges`、但沒有明確 `Add` / `Remove` 時,可能是在更新追蹤中的實體,列為可能(`uncertain`)寫入者。每筆都有信心等級;**動態 SQL(`EXEC(@sql)`、`sp_executesql`、由未知值組成的 SQL)無法解析,會獨立列為 `uncertain
|
|
64
|
+
`data-access <資料表或預存程序>` 回答「誰寫入 / 讀取 / 執行 X」。資料來源:T-SQL(INSERT / UPDATE / DELETE / MERGE / TRUNCATE / SELECT INTO / FROM / JOIN / EXEC,含別名解析,排除 CTE、暫存表、系統物件)、C# 的 SQL 字串(字面值、`+`、字串內插、`string.Format`、常數、區域變數、`StringBuilder.Append` / `AppendLine` / `AppendFormat`)經 Dapper、`SqlCommand` 或 EF `FromSql` 送出、搭配 `CommandType.StoredProcedure` 的 SP 名稱、對 `DbSet<T>` 成員的 EF LINQ(`ctx.Orders.Where(..)` / `.Add(..)` / `.Remove(..)`、`from o in ctx.Orders`;只比對成員名稱,所以是 `probable`),以及 EF 的 `ToTable` / `[Table]` 對應。呼叫某 SP 的程式視為該 SP 所寫資料表的間接寫入者(最多追 4 層)。`programs`(USED BY PROGRAMS)沿 confirmed / probable 的 C# 呼叫往上追到 `*Controller` 方法(最多 8 層),(實作方法也會接到它所實作介面方法的呼叫者,涵蓋 `foreach (var step in steps) step.Run()` 這種管線),依 controller 檔案分組,並列出 `Url.Action("Action"[, "Controller"])` 或 AngularJS `ControllerPath + 'Action'`(controller 取自 `$scope.Controller = 'X'`)指向這些 action 的 Razor 頁面(`.cshtml`),查一張表就知道哪些畫面會動到它。方法讀了某 DbSet 又呼叫 `SaveChanges`、但沒有明確 `Add` / `Remove` 時,可能是在更新追蹤中的實體,列為可能(`uncertain`)寫入者。每筆都有信心等級;**動態 SQL(`EXEC(@sql)`、`sp_executesql`、由未知值組成的 SQL)無法解析,會獨立列為 `uncertain`**,不會混進確定的清單。EF 存取在 context 變數(`using (var db = new X())`、欄位或屬性、`this`)的型別是宣告或繼承該 DbSet 的類別時為 `confirmed`,否則 `probable`。往上追時沒有任何 confirmed / probable 呼叫者的方法列在 NO KNOWN CALLER:可能是 API、排程、`Main` 等入口,或是呼叫圖解不出的呼叫。已知缺口:`FROM a JOIN b ON ..., c` 會漏掉 `c`;把 SP 名稱傳給非資料庫方法時看不到。
|
|
64
65
|
|
|
65
66
|
只存在資料庫裡的預存程序,可匯出到 repo 外的資料夾,再寫進 `.ai_context/extra_roots`(一行一個資料夾,絕對路徑或相對於專案根目錄);這些檔案以絕對路徑索引。
|
|
66
67
|
|
|
@@ -70,9 +71,13 @@ claude mcp add local-indexer -- local-codebase-indexer --root /path/to/project s
|
|
|
70
71
|
|
|
71
72
|
查詢會用小型同義詞字典擴展(`SP` / `預存程序` / `stored procedure` / `usp`、資料表、批號、報廢等;見 `local_codebase_indexer/synonyms.py`)。可在 `.ai_context/synonyms.json` 為專案新增或停用群組:`{"groups": [["wpnlot", "在製批"]], "disable": ["sp"]}`。這對縮寫與中英對照有幫助,對自由改寫的同義說法沒用。
|
|
72
73
|
|
|
74
|
+
索引也會自動挖專案自己的字典:符號正上方註解裡的中文雙字詞,配對符號名稱的英文子詞(`ReceiveLotAsync` 上面寫 `/// 收帳` → 收帳 = receive)。至少 5 個符號支持、在帶有該詞註解的符號中占 15% 以上(有平滑)、且該英文詞在那裡出現的機率是整體的 15 倍以上才保留。在 3 萬 chunk 的 C# 專案上約得到 350 組(收帳→receive、拆批→divide、油墨→ink、底片→film),換句話說的查詢 MRR 由 0.57 提升到 0.64。
|
|
75
|
+
|
|
73
76
|
## 索引健康狀態
|
|
74
77
|
|
|
75
|
-
`status`(也是 MCP 工具 `codebase_index_status`)不更新索引,只回報索引是否可信:`fresh`(新鮮)、`stale`(檔案有變更或 git HEAD 已移動)、`degraded`(有解析失敗的檔案或資料庫不一致)、`not_indexed`(尚未建立)。解析失敗的檔案會從索引移除、連同錯誤原因列出,並在每次更新時重試,所以搜尋不會回傳它的過期內容。`index --force` 可全部重建。
|
|
78
|
+
`status`(也是 MCP 工具 `codebase_index_status`)不更新索引,只回報索引是否可信:`fresh`(新鮮)、`stale`(檔案有變更或 git HEAD 已移動)、`degraded`(有解析失敗的檔案或資料庫不一致)、`not_indexed`(尚未建立)。解析失敗的檔案會從索引移除、連同錯誤原因列出,並在每次更新時重試,所以搜尋不會回傳它的過期內容。`index --force` 可全部重建。status 也會顯示執行中的版本;套件程式碼在程序啟動後有改動時會提示重開 MCP server(也就是開新的 Claude Code session)。
|
|
79
|
+
|
|
80
|
+
速度(2.3k 檔、3 萬 chunk、hashing 嵌入):空資料庫全量約 36 秒,切分支改寫 400 個檔約 10 秒,無變動檢查約 1 秒。每個檔案在 savepoint 內寫入(不可分割),每 500 個檔案 commit 一次。
|
|
76
81
|
|
|
77
82
|
## 基準測試
|
|
78
83
|
|
|
@@ -13,6 +13,7 @@ Priorities come from the benchmark (`benchmarks/run_benchmark.py`, baseline in `
|
|
|
13
13
|
| Item | Why deferred | Revisit when |
|
|
14
14
|
|---|---|---|
|
|
15
15
|
| Real embedding model as default | Measured 0.4.0 on a real 30k-chunk C# codebase with Chinese comments, 12 paraphrased queries (6 zh, 6 en): hashing MRR 0.48 / hit@5 6, `all-MiniLM-L6-v2` 0.29 / 6, `paraphrase-multilingual-MiniLM-L12-v2` (int8) 0.41 / 6; full index 128 s vs 35 / 43 min. Benchmark: MiniLM +0.08-0.13 MRR, multilingual -0.01..+0.03. Domain jargon ("split a lot into two") was missed by all three | A model trained on code + Chinese, or embedding becomes incremental enough that branch switches stay under a minute |
|
|
16
|
+
| Content-hash cache of parse results across branch switches | Measured: a switch that rewrites 400 files re-indexes in about 10 s; parsing is about 40% of that, so a cache would save a few seconds at the cost of a large table | Branch switches routinely rewrite thousands of files |
|
|
16
17
|
| ANN index | Exact search is not the bottleneck. Measured (Python stdlib copies, linear growth): 17k chunks cold CLI search 0.35 s / warm 0.13 s / index 10 s; 52k chunks 0.75 s / 0.36 s / 28 s; 104k chunks 1.09 s / 0.73 s / 54 s, 372 MB RSS, 729 MB database. At 104k chunks the cosine product plus top-k takes about 12 ms; loading the vectors out of SQLite (fetch 0.31 s, join 0.12 s) is about half of a warm query | Exact cosine itself becomes slow, which is far beyond 1M chunks |
|
|
17
18
|
| Vector matrix cache | Cheap and measurable: it removes about half of a warm query at 104k chunks (about 0.8 s -> 0.3 s). Not needed below ~50k chunks | A real project passes ~50k chunks. Keep the matrix in the MCP server process, and/or store it as a memory-mapped `.npy` next to the database so the CLI benefits too (invalidate on any index change) |
|
|
18
19
|
| `codebase_trace_execution` | Needs reliable call / data-flow relations; today's usage edges are name matches | Call graph gaps (item 3) are narrowed; today edges carry a confidence level |
|
|
@@ -22,6 +23,8 @@ Priorities come from the benchmark (`benchmarks/run_benchmark.py`, baseline in `
|
|
|
22
23
|
|
|
23
24
|
## Done
|
|
24
25
|
|
|
26
|
+
- 0.5.0: a long-lived MCP server re-checks the index (was: once per process); full build 155 s -> 36 s on 2.3k files (C# usings no longer scanned as Python modules, per-file savepoints with batched commits); Chinese comment <-> identifier dictionary mined per project (iWAP paraphrase MRR 0.57 -> 0.64); data-access summary by default (`detail` / `--full`), related files only on request; EF confidence from the context variable's type; NO KNOWN CALLER roots; `impact` tool for a git diff; status shows the running version and warns when the code changed after start
|
|
27
|
+
|
|
25
28
|
- Data access: `StringBuilder` SQL, EF LINQ on `DbSet<T>` members (resolved after indexing against declared DbSets), `programs` roll-up from accessors to controller actions; `relations Type.Method`; call graph resolves `Lazy<T>.Value` and `foreach (var x in ...)` element types; programs roll-up walks from an implementation to its interface method's callers and lists Razor pages (`Url.Action`, AngularJS `ControllerPath + 'Action'`); a typed identifier's scope includes files named after it and ranks names matching the rest of the query first ("WD0096 存檔" -> SetRecord); EF `SaveChanges` on tracked entities listed as possible writes; `.ai_context/extra_roots`; `.ai_context/ignore`, minified files skipped; C# namespace imports only link files whose types are used; piped CLI output is UTF-8
|
|
26
29
|
|
|
27
30
|
- SQL / data-access relations: `data_access` table and tool (`data-access` CLI, `codebase_get_data_access` MCP); T-SQL read / write / exec, C# SQL strings and Dapper / SqlCommand / EF sinks, EF table mappings, indirect writers through procedures, dynamic SQL reported as `uncertain`; search routes "who writes / reads / calls X" to it. Benchmark `sql_dataflow` Recall@5 0.72 -> 1.00, new `data_access` queries 0.67 -> 1.00
|
|
@@ -33,6 +33,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
33
33
|
s.add_argument("query", nargs="?")
|
|
34
34
|
s.add_argument("--query", dest="query_opt")
|
|
35
35
|
s.add_argument("--limit", type=int, default=5)
|
|
36
|
+
s.add_argument("--related", action="store_true", help="also list dependency-graph neighbours of the top hits")
|
|
36
37
|
|
|
37
38
|
s = sub.add_parser("relations", aliases=["codebase_get_symbol_relations"], help="symbol dependency graph")
|
|
38
39
|
s.add_argument("symbol", nargs="?")
|
|
@@ -51,6 +52,12 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
51
52
|
help="who reads / writes / executes a table or stored procedure, and what a procedure touches")
|
|
52
53
|
s.add_argument("object", nargs="?")
|
|
53
54
|
s.add_argument("--object_name", dest="object_opt")
|
|
55
|
+
s.add_argument("--full", action="store_true", help="up to 40 entries per section instead of a 5-entry summary")
|
|
56
|
+
|
|
57
|
+
s = sub.add_parser("impact", aliases=["codebase_impact_analysis"],
|
|
58
|
+
help="symbols, tables, programs and pages touched by a git diff")
|
|
59
|
+
s.add_argument("base", nargs="?", help="git revision or range (default: uncommitted work against HEAD)")
|
|
60
|
+
s.add_argument("--full", action="store_true", help="list every changed symbol")
|
|
54
61
|
|
|
55
62
|
sub.add_parser("stats", help="show index statistics")
|
|
56
63
|
sub.add_parser("status", aliases=["codebase_index_status"], help="index health: freshness, failures, consistency")
|
|
@@ -83,7 +90,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
83
90
|
from .mcp_server import serve
|
|
84
91
|
return serve(root)
|
|
85
92
|
|
|
86
|
-
from .query import render_context, render_data_access, render_relations, render_search,
|
|
93
|
+
from .query import (render_context, render_data_access, render_impact, render_relations, render_search,
|
|
94
|
+
render_status)
|
|
87
95
|
|
|
88
96
|
try:
|
|
89
97
|
t = _tools(root)
|
|
@@ -99,7 +107,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
99
107
|
if not q:
|
|
100
108
|
print("error: a query is required", file=sys.stderr)
|
|
101
109
|
return 2
|
|
102
|
-
res = t.semantic_search(q, args.limit)
|
|
110
|
+
res = t.semantic_search(q, args.limit, args.related)
|
|
103
111
|
_emit(res, render_search(res), args.json)
|
|
104
112
|
elif args.cmd in ("relations", "codebase_get_symbol_relations"):
|
|
105
113
|
sym = args.symbol_opt or args.symbol
|
|
@@ -121,7 +129,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
121
129
|
print("error: an object name is required", file=sys.stderr)
|
|
122
130
|
return 2
|
|
123
131
|
res = t.data_access(name)
|
|
124
|
-
_emit(res, render_data_access(res), args.json)
|
|
132
|
+
_emit(res, render_data_access(res, args.full), args.json)
|
|
133
|
+
elif args.cmd in ("impact", "codebase_impact_analysis"):
|
|
134
|
+
res = t.impact(args.base)
|
|
135
|
+
_emit(res, render_impact(res, args.full), args.json)
|
|
125
136
|
elif args.cmd in ("status", "codebase_index_status"):
|
|
126
137
|
res = t.index_status()
|
|
127
138
|
_emit(res, render_status(res), args.json)
|
{local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/core.py
RENAMED
|
@@ -9,6 +9,7 @@ import re
|
|
|
9
9
|
import sqlite3
|
|
10
10
|
import subprocess
|
|
11
11
|
import time
|
|
12
|
+
from contextlib import contextmanager
|
|
12
13
|
from collections import defaultdict
|
|
13
14
|
from dataclasses import dataclass, field
|
|
14
15
|
|
|
@@ -21,6 +22,24 @@ from .scanner import iter_files
|
|
|
21
22
|
_TYPE_KINDS = tuple(CLASS_LIKE)
|
|
22
23
|
|
|
23
24
|
|
|
25
|
+
COMMIT_EVERY = 500 # files per commit; each file is still atomic through a savepoint
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@contextmanager
|
|
29
|
+
def _file_transaction(conn: sqlite3.Connection):
|
|
30
|
+
"""One file's rows go in or out together, inside the batch transaction that ``update`` commits."""
|
|
31
|
+
if not conn.in_transaction:
|
|
32
|
+
conn.execute("BEGIN")
|
|
33
|
+
conn.execute("SAVEPOINT index_file")
|
|
34
|
+
try:
|
|
35
|
+
yield
|
|
36
|
+
except BaseException:
|
|
37
|
+
conn.execute("ROLLBACK TO index_file")
|
|
38
|
+
conn.execute("RELEASE index_file")
|
|
39
|
+
raise
|
|
40
|
+
conn.execute("RELEASE index_file")
|
|
41
|
+
|
|
42
|
+
|
|
24
43
|
def decode_bytes(data: bytes) -> str:
|
|
25
44
|
for enc in ("utf-8-sig", "big5", "cp1252"):
|
|
26
45
|
try:
|
|
@@ -57,14 +76,20 @@ def embedding_text_for(header: str, body: str) -> str:
|
|
|
57
76
|
return (header + "\n" + body)[:2500]
|
|
58
77
|
|
|
59
78
|
|
|
79
|
+
def git(root: str, *args: str, timeout: int = 15) -> str | None:
|
|
80
|
+
"""stdout of a git command run in ``root`` (UTF-8), None when git fails or is missing."""
|
|
81
|
+
try:
|
|
82
|
+
r = subprocess.run(["git", "-C", root, *args], capture_output=True, text=True, encoding="utf-8",
|
|
83
|
+
errors="replace", timeout=timeout)
|
|
84
|
+
except (OSError, subprocess.SubprocessError):
|
|
85
|
+
return None
|
|
86
|
+
return r.stdout if r.returncode == 0 else None
|
|
87
|
+
|
|
88
|
+
|
|
60
89
|
def git_info(root: str) -> dict | None:
|
|
61
90
|
"""HEAD commit, branch and number of uncommitted paths; None outside a git work tree."""
|
|
62
91
|
def run(*args: str) -> str | None:
|
|
63
|
-
|
|
64
|
-
r = subprocess.run(["git", "-C", root, *args], capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=15)
|
|
65
|
-
except (OSError, subprocess.SubprocessError):
|
|
66
|
-
return None
|
|
67
|
-
return r.stdout if r.returncode == 0 else None
|
|
92
|
+
return git(root, *args)
|
|
68
93
|
|
|
69
94
|
head = run("rev-parse", "HEAD")
|
|
70
95
|
if head is None:
|
|
@@ -162,6 +187,8 @@ class Indexer:
|
|
|
162
187
|
stats.updated += 1
|
|
163
188
|
else:
|
|
164
189
|
stats.added += 1
|
|
190
|
+
if (stats.added + stats.updated) % COMMIT_EVERY == 0:
|
|
191
|
+
conn.commit()
|
|
165
192
|
|
|
166
193
|
for gone in set(existing) - seen:
|
|
167
194
|
self._remove_file(gone)
|
|
@@ -177,6 +204,7 @@ class Indexer:
|
|
|
177
204
|
resolve_calls(conn)
|
|
178
205
|
resolve_page_actions(conn)
|
|
179
206
|
resolve_ef_access(conn)
|
|
207
|
+
mine_terms(conn)
|
|
180
208
|
self._record_run_meta()
|
|
181
209
|
conn.commit()
|
|
182
210
|
stats.chunks = conn.execute("SELECT COUNT(*) FROM chunk_metadata").fetchone()[0]
|
|
@@ -224,7 +252,7 @@ class Indexer:
|
|
|
224
252
|
[embedding_text_for(ch.header, ch.text) for ch in parsed.chunks]
|
|
225
253
|
)
|
|
226
254
|
c = self.conn
|
|
227
|
-
with c:
|
|
255
|
+
with _file_transaction(c):
|
|
228
256
|
self._remove_file(rel_path)
|
|
229
257
|
c.execute(
|
|
230
258
|
"INSERT INTO files(file_path, last_modified, md5_hash, language) VALUES(?,?,?,?)",
|
|
@@ -312,9 +340,106 @@ def resolve_page_actions(conn: sqlite3.Connection) -> None:
|
|
|
312
340
|
rows)
|
|
313
341
|
|
|
314
342
|
|
|
343
|
+
# identifier words too generic to stand for a Chinese term
|
|
344
|
+
_MINE_STOP = {
|
|
345
|
+
"get", "set", "async", "by", "to", "of", "and", "or", "list", "data", "info", "model", "the", "is", "in", "on",
|
|
346
|
+
"for", "new", "all", "with", "from", "check", "do", "process", "result", "value", "item", "items", "id", "no",
|
|
347
|
+
"nbr", "dto", "view", "service", "repository", "controller", "query", "condition", "rec", "record", "records",
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def mine_terms(conn: sqlite3.Connection) -> None:
|
|
352
|
+
"""Pair Chinese bigrams of the comments right above a symbol with the sub-words of its name, e.g.
|
|
353
|
+
``/// 收帳`` above ``ReceiveLotAsync`` -> 收帳 = receive. Kept: seen with >= 5 symbols, >= 15% of the
|
|
354
|
+
symbols commented with the bigram carry the word (smoothed by 10, so a handful of comments on one class
|
|
355
|
+
cannot map a generic word like 維護), and the word is >= 15x likelier there than overall."""
|
|
356
|
+
conn.execute("DELETE FROM mined_terms")
|
|
357
|
+
pairs: dict[tuple[str, str], int] = defaultdict(int)
|
|
358
|
+
gram_n: dict[str, int] = defaultdict(int)
|
|
359
|
+
word_n: dict[str, int] = defaultdict(int)
|
|
360
|
+
total = 0
|
|
361
|
+
for name, sym_start, chunk_start, text in conn.execute(
|
|
362
|
+
"SELECT s.symbol_name, s.start_line, c.start_line, c.raw_text FROM chunk_metadata c "
|
|
363
|
+
"JOIN symbols s ON s.id = c.symbol_id WHERE s.symbol_type IN "
|
|
364
|
+
"('method', 'class', 'interface', 'property', 'function', 'constructor')"):
|
|
365
|
+
words = {w for w in split_identifier(name) if len(w) >= 3 and not w.isdigit() and w not in _MINE_STOP}
|
|
366
|
+
total += 1
|
|
367
|
+
for w in words:
|
|
368
|
+
word_n[w] += 1
|
|
369
|
+
head = text.split("\n")[:max(0, sym_start - chunk_start)]
|
|
370
|
+
grams = {run[i:i + 2] for line in head for run in _CJK_RUN.findall(line) for i in range(len(run) - 1)}
|
|
371
|
+
for g in grams:
|
|
372
|
+
gram_n[g] += 1
|
|
373
|
+
for w in words:
|
|
374
|
+
pairs[(g, w)] += 1
|
|
375
|
+
best: dict[str, list[tuple[float, str, int]]] = defaultdict(list)
|
|
376
|
+
for (g, w), n in pairs.items():
|
|
377
|
+
share = n / (gram_n[g] + 10)
|
|
378
|
+
if n >= 5 and share >= 0.15 and share / (word_n[w] / total) >= 15:
|
|
379
|
+
best[g].append((share, w, n))
|
|
380
|
+
conn.executemany("INSERT INTO mined_terms(gram, word, n) VALUES(?,?,?)",
|
|
381
|
+
[(g, w, n) for g, lst in best.items() for _s, w, n in sorted(lst, reverse=True)[:3]])
|
|
382
|
+
|
|
383
|
+
|
|
315
384
|
_DBSET = re.compile(r"\bI?DbSet<\s*([\w.]+)\s*>")
|
|
316
385
|
|
|
317
386
|
|
|
387
|
+
def _subclasses(conn: sqlite3.Connection):
|
|
388
|
+
"""name -> that class and every class deriving from it (by base-list name)."""
|
|
389
|
+
children: dict[str, set[str]] = defaultdict(set)
|
|
390
|
+
for owner, base in conn.execute("SELECT o.symbol_name, r.name FROM raw_refs r JOIN symbols o ON o.id = r.owner "
|
|
391
|
+
"WHERE r.kind = 'base'"):
|
|
392
|
+
children[base.split(".")[-1].split("<")[0]].add(owner)
|
|
393
|
+
cache: dict[str, set[str]] = {}
|
|
394
|
+
|
|
395
|
+
def of(name: str) -> set[str]:
|
|
396
|
+
if name not in cache:
|
|
397
|
+
out, todo = {name}, [name]
|
|
398
|
+
while todo:
|
|
399
|
+
for c in children.get(todo.pop(), ()):
|
|
400
|
+
if c not in out:
|
|
401
|
+
out.add(c)
|
|
402
|
+
todo.append(c)
|
|
403
|
+
cache[name] = out
|
|
404
|
+
return cache[name]
|
|
405
|
+
return of
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class _ContextTypes:
|
|
409
|
+
"""Declared type of the context variable in ``ctx.Set.Where(..)``: ``this`` is the enclosing class, a local is
|
|
410
|
+
read from the method text (``var ctx = new X(..)`` / ``X ctx``), anything else from the class's field or
|
|
411
|
+
property declaration."""
|
|
412
|
+
|
|
413
|
+
def __init__(self, conn: sqlite3.Connection):
|
|
414
|
+
self.conn = conn
|
|
415
|
+
self._sym: dict[str, sqlite3.Row | None] = {}
|
|
416
|
+
self._text: dict[str, str] = {}
|
|
417
|
+
|
|
418
|
+
def __call__(self, source_id: str | None, var: str) -> str:
|
|
419
|
+
if not source_id or not var:
|
|
420
|
+
return ""
|
|
421
|
+
if source_id not in self._sym:
|
|
422
|
+
self._sym[source_id] = self.conn.execute(
|
|
423
|
+
"SELECT qualified_name FROM symbols WHERE id=?", (source_id,)).fetchone()
|
|
424
|
+
sym = self._sym[source_id]
|
|
425
|
+
if sym is None or not sym["qualified_name"] or "." not in sym["qualified_name"]:
|
|
426
|
+
return ""
|
|
427
|
+
cls = sym["qualified_name"].rsplit(".", 1)[0]
|
|
428
|
+
if var == "this":
|
|
429
|
+
return cls.rsplit(".", 1)[-1]
|
|
430
|
+
if source_id not in self._text:
|
|
431
|
+
self._text[source_id] = "\n".join(r[0] for r in self.conn.execute(
|
|
432
|
+
"SELECT raw_text FROM chunk_metadata WHERE symbol_id=? ORDER BY start_line", (source_id,)))
|
|
433
|
+
v = re.escape(var)
|
|
434
|
+
m = (re.search(rf"\b{v}\s*=\s*new\s+([\w.]+)\s*\(", self._text[source_id])
|
|
435
|
+
or re.search(rf"\b(?!var\b)([\w.]+)\s+{v}\s*[=;,)]", self._text[source_id]))
|
|
436
|
+
if m:
|
|
437
|
+
return m.group(1).split(".")[-1]
|
|
438
|
+
row = self.conn.execute("SELECT type_name FROM symbols WHERE qualified_name=? AND symbol_type IN "
|
|
439
|
+
"('field', 'property')", (f"{cls}.{var}",)).fetchone()
|
|
440
|
+
return (row["type_name"] or "") if row else ""
|
|
441
|
+
|
|
442
|
+
|
|
318
443
|
def resolve_ef_access(conn: sqlite3.Connection) -> None:
|
|
319
444
|
"""Turn ``ef_raw`` candidates whose member is a declared ``DbSet<T>`` into ``ef_linq`` table accesses.
|
|
320
445
|
Table = the EF mapping of T (``ToTable`` / ``[Table]``) when there is one, else the DbSet property name.
|
|
@@ -322,22 +447,33 @@ def resolve_ef_access(conn: sqlite3.Connection) -> None:
|
|
|
322
447
|
entities: that becomes an ``uncertain`` write (listed as possible, never as a confirmed writer)."""
|
|
323
448
|
conn.execute("DELETE FROM data_access WHERE via='ef_linq'")
|
|
324
449
|
dbsets: dict[str, str] = {}
|
|
325
|
-
|
|
326
|
-
|
|
450
|
+
contexts: dict[str, set[str]] = defaultdict(set) # DbSet member -> context classes declaring it
|
|
451
|
+
for name, sig, owner in conn.execute(
|
|
452
|
+
"SELECT s.symbol_name, s.signature, p.symbol_name FROM symbols s LEFT JOIN symbols p ON p.id = s.parent_id "
|
|
453
|
+
"WHERE s.symbol_type='property' AND s.signature LIKE '%DbSet<%'"):
|
|
454
|
+
m = _DBSET.search(sig or "")
|
|
327
455
|
if m:
|
|
328
|
-
dbsets[
|
|
456
|
+
dbsets[name.lower()] = m.group(1).split(".")[-1]
|
|
457
|
+
if owner:
|
|
458
|
+
contexts[name.lower()].add(owner)
|
|
329
459
|
if not dbsets:
|
|
330
460
|
return
|
|
461
|
+
subclasses = _subclasses(conn)
|
|
331
462
|
mapped = {r[0].split(".")[-1]: r[1] for r in conn.execute(
|
|
332
463
|
"SELECT detail, target_name FROM data_access WHERE via='ef_mapping' AND detail != ''")}
|
|
464
|
+
ctx_type = _ContextTypes(conn)
|
|
333
465
|
rows = []
|
|
334
466
|
for r in conn.execute("SELECT * FROM data_access WHERE via='ef_raw'").fetchall():
|
|
335
|
-
|
|
467
|
+
member = r["target_key"][3:]
|
|
468
|
+
entity = dbsets.get(member)
|
|
336
469
|
if entity is None:
|
|
337
470
|
continue
|
|
338
471
|
table = mapped.get(entity, r["target_name"])
|
|
472
|
+
owners = {c for o in contexts[member] for c in subclasses(o)}
|
|
473
|
+
# confirmed when the context variable is typed as a class that declares (or inherits) this DbSet
|
|
474
|
+
conf = "confirmed" if ctx_type(r["source_id"], r["qualifier"]) in owners else "probable"
|
|
339
475
|
rows.append((r["file_path"], r["source_id"], r["line"], table.lower(), table, "", "table", r["access"],
|
|
340
|
-
r["op"], "ef_linq",
|
|
476
|
+
r["op"], "ef_linq", conf, r["evidence"], entity))
|
|
341
477
|
savers = {r[0]: (r[1], r[2]) for r in conn.execute(
|
|
342
478
|
"SELECT source_id, line, evidence FROM data_access WHERE via='ef_raw' AND target_key='ef:#savechanges' "
|
|
343
479
|
"AND source_id IS NOT NULL")}
|
|
@@ -389,7 +525,7 @@ def resolve_dependencies(conn: sqlite3.Connection) -> None:
|
|
|
389
525
|
targets.add(t)
|
|
390
526
|
elif name in ns_files:
|
|
391
527
|
targets |= {t for t in ns_files[name] if file_types[t] & used[src]}
|
|
392
|
-
|
|
528
|
+
elif src.endswith(".py"):
|
|
393
529
|
slug = name.replace(".", "/")
|
|
394
530
|
for cand in (slug + ".py", slug + "/__init__.py"):
|
|
395
531
|
targets |= {f for f in files if f == cand or f.endswith("/" + cand)}
|
{local_codebase_indexer-0.4.0 → local_codebase_indexer-0.5.0}/local_codebase_indexer/csdata.py
RENAMED
|
@@ -466,8 +466,10 @@ class _Extractor:
|
|
|
466
466
|
"identifier", "this_expression", "member_access_expression"):
|
|
467
467
|
return
|
|
468
468
|
write = _EF_WRITE.get(method)
|
|
469
|
+
# qualifier = the context variable (IMES in IMES.Lots.Where), "this" inside the context itself
|
|
470
|
+
last = ctx.child_by_field_name("name") if ctx.type == "member_access_expression" else ctx
|
|
469
471
|
self.out.append(Access(
|
|
470
|
-
key="ef:" + self.text(name).lower(), name=self.text(name), qualifier=
|
|
472
|
+
key="ef:" + self.text(name).lower(), name=self.text(name), qualifier=self.text(last), kind="entity_set",
|
|
471
473
|
access="write" if write else "read", op=write or "select", line=self.line(n), via="ef_raw",
|
|
472
474
|
confidence="probable", evidence=self.collapsed(n), detail=method,
|
|
473
475
|
))
|