codingest 0.1.4__tar.gz → 0.1.5__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.
Files changed (86) hide show
  1. {codingest-0.1.4 → codingest-0.1.5}/Cargo.lock +10 -10
  2. codingest-0.1.5/Cargo.toml +42 -0
  3. {codingest-0.1.4 → codingest-0.1.5}/PKG-INFO +12 -5
  4. {codingest-0.1.4 → codingest-0.1.5}/README.md +10 -3
  5. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/Cargo.toml +1 -1
  6. codingest-0.1.5/crates/codingest/src/bin/codingest_stats.rs +464 -0
  7. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/call_edges.rs +390 -17
  8. codingest-0.1.5/crates/codingest/src/builder/js_workspace.rs +595 -0
  9. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/load/edge_frames.rs +24 -0
  10. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/load.rs +37 -5
  11. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/mod.rs +40 -12
  12. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/other_edges.rs +406 -5
  13. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/semantic_edges.rs +7 -0
  14. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/agc.rs +12 -2
  15. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/registry.rs +15 -0
  16. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/typescript.rs +161 -10
  17. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/tests/goldens/README.md +9 -0
  18. codingest-0.1.5/crates/codingest/tests/goldens/dup_minified_assets.sha256 +1 -0
  19. codingest-0.1.5/crates/codingest/tests/goldens/py_basic.sha256 +1 -0
  20. codingest-0.1.5/crates/codingest/tests/goldens/py_inheritance.sha256 +1 -0
  21. codingest-0.1.5/crates/codingest/tests/goldens/rust_xfile.sha256 +1 -0
  22. codingest-0.1.5/crates/codingest/tests/goldens/ts_callback.sha256 +1 -0
  23. codingest-0.1.5/crates/codingest/tests/goldens/ts_monorepo.sha256 +1 -0
  24. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/tests/parity.rs +98 -0
  25. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/Cargo.toml +1 -1
  26. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/src/code_tree_cli.rs +7 -3
  27. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/src/lib.rs +20 -0
  28. codingest-0.1.5/crates/codingest-cli/src/main.rs +10 -0
  29. codingest-0.1.5/crates/codingest-cli/src/query.rs +644 -0
  30. codingest-0.1.5/crates/codingest-cli/tests/exit_codes.rs +209 -0
  31. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-mcp/Cargo.toml +1 -1
  32. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-py/Cargo.toml +3 -3
  33. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-py/src/lib.rs +1 -1
  34. {codingest-0.1.4 → codingest-0.1.5}/pyproject.toml +2 -2
  35. codingest-0.1.4/Cargo.toml +0 -40
  36. codingest-0.1.4/crates/codingest/src/bin/codingest_stats.rs +0 -150
  37. codingest-0.1.4/crates/codingest/tests/goldens/dup_minified_assets.sha256 +0 -1
  38. codingest-0.1.4/crates/codingest/tests/goldens/py_basic.sha256 +0 -1
  39. codingest-0.1.4/crates/codingest/tests/goldens/py_inheritance.sha256 +0 -1
  40. codingest-0.1.4/crates/codingest/tests/goldens/rust_xfile.sha256 +0 -1
  41. codingest-0.1.4/crates/codingest/tests/goldens/ts_callback.sha256 +0 -1
  42. codingest-0.1.4/crates/codingest-cli/src/main.rs +0 -5
  43. {codingest-0.1.4 → codingest-0.1.5}/LICENSE +0 -0
  44. {codingest-0.1.4 → codingest-0.1.5}/codingest/__init__.py +0 -0
  45. {codingest-0.1.4 → codingest-0.1.5}/codingest/__init__.pyi +0 -0
  46. {codingest-0.1.4 → codingest-0.1.5}/codingest/cli.py +0 -0
  47. {codingest-0.1.4 → codingest-0.1.5}/codingest/mcp_server.py +0 -0
  48. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/bin/codingest_bench.rs +0 -0
  49. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/load/entity_frames.rs +0 -0
  50. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/routes/django.rs +0 -0
  51. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/routes/fastapi.rs +0 -0
  52. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/routes/flask.rs +0 -0
  53. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/routes/mod.rs +0 -0
  54. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/builder/type_edges.rs +0 -0
  55. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/cross_lang.rs +0 -0
  56. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/docs/mod.rs +0 -0
  57. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/docs/rst.rs +0 -0
  58. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/lib.rs +0 -0
  59. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/manifest/mod.rs +0 -0
  60. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/models.rs +0 -0
  61. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/cpp.rs +0 -0
  62. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/csharp.rs +0 -0
  63. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/css.rs +0 -0
  64. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/dart.rs +0 -0
  65. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/go.rs +0 -0
  66. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/html.rs +0 -0
  67. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/java.rs +0 -0
  68. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/mod.rs +0 -0
  69. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/php.rs +0 -0
  70. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/python.rs +0 -0
  71. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/rust_lang.rs +0 -0
  72. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/shared.rs +0 -0
  73. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/parsers/swift.rs +0 -0
  74. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/repo.rs +0 -0
  75. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/src/rev.rs +0 -0
  76. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/tests/agc_apollo.rs +0 -0
  77. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/tests/goldens/agc_basic.sha256 +0 -0
  78. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest/tests/goldens/cross_ts_py.sha256 +0 -0
  79. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/skills/codingest-code-review/SKILL.md +0 -0
  80. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/skills/codingest-code-review/references/mcp-upgrade.md +0 -0
  81. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/skills/codingest-code-review/references/public-repositories.md +0 -0
  82. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/skills/codingest-code-review/references/queries.md +0 -0
  83. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/src/skill.rs +0 -0
  84. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-cli/src/skill_assets.rs +0 -0
  85. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-mcp/src/lib.rs +0 -0
  86. {codingest-0.1.4 → codingest-0.1.5}/crates/codingest-mcp/src/main.rs +0 -0
@@ -313,7 +313,7 @@ dependencies = [
313
313
 
314
314
  [[package]]
315
315
  name = "codingest"
316
- version = "0.1.4"
316
+ version = "0.1.5"
317
317
  dependencies = [
318
318
  "aho-corasick",
319
319
  "base64",
@@ -345,7 +345,7 @@ dependencies = [
345
345
 
346
346
  [[package]]
347
347
  name = "codingest-cli"
348
- version = "0.1.4"
348
+ version = "0.1.5"
349
349
  dependencies = [
350
350
  "anyhow",
351
351
  "clap",
@@ -357,7 +357,7 @@ dependencies = [
357
357
 
358
358
  [[package]]
359
359
  name = "codingest-mcp"
360
- version = "0.1.4"
360
+ version = "0.1.5"
361
361
  dependencies = [
362
362
  "anyhow",
363
363
  "codingest",
@@ -366,7 +366,7 @@ dependencies = [
366
366
 
367
367
  [[package]]
368
368
  name = "codingest-py"
369
- version = "0.1.4"
369
+ version = "0.1.5"
370
370
  dependencies = [
371
371
  "codingest",
372
372
  "codingest-cli",
@@ -1393,9 +1393,9 @@ dependencies = [
1393
1393
 
1394
1394
  [[package]]
1395
1395
  name = "kglite"
1396
- version = "0.15.3"
1396
+ version = "0.15.5"
1397
1397
  source = "registry+https://github.com/rust-lang/crates.io-index"
1398
- checksum = "4ec07586e3dac4fa5dd1e216ac057f41ffe056f95eefc8ddd866f09fd7e48394"
1398
+ checksum = "4664fc457e5dd762f5775977f06eb5377634556fffae45e4a86e2eb1e1eb0bfb"
1399
1399
  dependencies = [
1400
1400
  "bzip2",
1401
1401
  "chrono",
@@ -1428,9 +1428,9 @@ dependencies = [
1428
1428
 
1429
1429
  [[package]]
1430
1430
  name = "kglite-mcp-server"
1431
- version = "0.15.3"
1431
+ version = "0.15.5"
1432
1432
  source = "registry+https://github.com/rust-lang/crates.io-index"
1433
- checksum = "f9dae485f96add5453ef56518cd14e57c3f20727c8ab151500cc6f1afb70deef"
1433
+ checksum = "e5e5d2207a45eb77c90e60a772bc8cc60ceac3d7c6f3ad2b948e8079355e1df4"
1434
1434
  dependencies = [
1435
1435
  "anyhow",
1436
1436
  "bytes",
@@ -1532,9 +1532,9 @@ dependencies = [
1532
1532
 
1533
1533
  [[package]]
1534
1534
  name = "mcp-methods"
1535
- version = "0.4.2"
1535
+ version = "0.4.3"
1536
1536
  source = "registry+https://github.com/rust-lang/crates.io-index"
1537
- checksum = "04c1063113c3a885d5967e45da2ea1cbb235938a9ba02333f15e81149b451b23"
1537
+ checksum = "caa2079c12e642cd4b9a20543c85305eb5ffee04b1d565feab47b084db167a99"
1538
1538
  dependencies = [
1539
1539
  "anyhow",
1540
1540
  "clap",
@@ -0,0 +1,42 @@
1
+ [workspace]
2
+ members = ["crates/codingest", "crates/codingest-cli", "crates/codingest-mcp", "crates/codingest-py"]
3
+ resolver = "2"
4
+
5
+ [workspace.package]
6
+ version = "0.1.5"
7
+ edition = "2021"
8
+ rust-version = "1.88"
9
+ license = "MIT"
10
+ repository = "https://github.com/kkollsga/codingest"
11
+
12
+ [workspace.dependencies]
13
+ base64 = "0.22"
14
+ sha2 = "0.11"
15
+ # kglite engine + MCP server — imported as crates.io libraries. The 0.15.5
16
+ # floor adds the two workspace controls codingest asked upstream for:
17
+ # `workspace.sandbox_root`, a real containment boundary that confines
18
+ # `set_root_dir` to a subtree instead of trusting the caller's path, and
19
+ # `workspace.adopt_client_roots`. Both land on top of the generic
20
+ # workspace-graph hooks, tri-state `durable` levels, typed
21
+ # constraint/conflict exceptions carrying a stable `.code`, and the
22
+ # deterministic Postcard persistence stack inherited from 0.14.5/0.15.0-0.15.3.
23
+ # 0.15.4 is deliberately skipped: it was WAL/durability and mapped-graph work
24
+ # we consume none of — codingest uses no `durable=` level, no `MappedGraph`,
25
+ # and no disk storage. Neither patch changes `kglite::api`, graph output,
26
+ # property encoding, or `.kgl` serialization.
27
+ # Keep both libraries aligned so the graph and server share one engine release.
28
+ kglite = { version = "0.15.5", default-features = false }
29
+ kglite-mcp-server = { version = "0.15.5", default-features = false }
30
+
31
+ # Mirror KGLite's release codegen so the standalone builder has
32
+ # performance parity with the in-tree component (see KGLite
33
+ # workspace Cargo.toml).
34
+ [profile.release]
35
+ lto = "thin"
36
+ codegen-units = 1
37
+ strip = "symbols"
38
+
39
+ [profile.profiling]
40
+ inherits = "release"
41
+ debug = "line-tables-only"
42
+ strip = "none"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codingest
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Programming Language :: Python :: 3
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.14
12
12
  Classifier: Programming Language :: Rust
13
13
  Classifier: Topic :: Software Development
14
14
  Classifier: Topic :: Software Development :: Libraries
15
- Requires-Dist: kglite>=0.15.3,<0.16
15
+ Requires-Dist: kglite>=0.15.5,<0.16
16
16
  License-File: LICENSE
17
17
  Summary: Build fast, queryable code graphs for AI agents, MCP code review, and local or GitHub repository analysis.
18
18
  Keywords: ai-agents,mcp,code-review,knowledge-graph,code-analysis,github,tree-sitter,cypher
@@ -136,9 +136,16 @@ The bundled terminal command offers the same workflow:
136
136
  ```bash
137
137
  codingest build /path/to/repo
138
138
  codingest status --output /path/to/repo/.kglite/code-review.kgl
139
+ codingest query -g /path/to/repo/.kglite/code-review.kgl \
140
+ "MATCH (f:Function)-[:CALLS]->(g:Function) RETURN f.name, g.name LIMIT 20"
139
141
  kglite describe /path/to/repo/.kglite/code-review.kgl --connections
140
142
  ```
141
143
 
144
+ `codingest query` prints unbounded TSV to stdout (use `--format csv|json`, or
145
+ Cypher `LIMIT` to bound rows), warns on stderr when the graph has gone stale,
146
+ and with `--require-fresh` refuses a stale graph with exit code 3 — see
147
+ [docs/cli.md](docs/cli.md).
148
+
142
149
  ## Analyse an open-source repository
143
150
 
144
151
  ```python
@@ -180,7 +187,7 @@ codingest skill install # code-review Agent Skill
180
187
  ```
181
188
 
182
189
  The wheel bundles every grammar plus the `codingest` and `codingest-mcp`
183
- commands. KGLite ≥0.15.3 is installed automatically as the query/storage
190
+ commands. KGLite ≥0.15.5 is installed automatically as the query/storage
184
191
  engine; its MCP server and the transitive `mcp-methods` framework power the
185
192
  builder-aware Codingest server. Nothing else needs to be installed.
186
193
 
@@ -193,7 +200,7 @@ Python prerequisites.
193
200
  ```toml
194
201
  [dependencies]
195
202
  codingest = "0.1"
196
- kglite = "0.15.3"
203
+ kglite = "0.15.5"
197
204
  ```
198
205
 
199
206
  ```rust
@@ -265,7 +272,7 @@ diagnostic.
265
272
  ## Dependency policy
266
273
 
267
274
  `kglite` and `kglite-mcp-server` use matching crates.io requirements with a
268
- 0.15.3 minimum and a shared lockfile. This keeps the builder, persistence
275
+ 0.15.5 minimum and a shared lockfile. This keeps the builder, persistence
269
276
  handoff, and embedded MCP server on one compatible engine patch line.
270
277
 
271
278
  ## Parity with the (now-removed) in-tree component
@@ -109,9 +109,16 @@ The bundled terminal command offers the same workflow:
109
109
  ```bash
110
110
  codingest build /path/to/repo
111
111
  codingest status --output /path/to/repo/.kglite/code-review.kgl
112
+ codingest query -g /path/to/repo/.kglite/code-review.kgl \
113
+ "MATCH (f:Function)-[:CALLS]->(g:Function) RETURN f.name, g.name LIMIT 20"
112
114
  kglite describe /path/to/repo/.kglite/code-review.kgl --connections
113
115
  ```
114
116
 
117
+ `codingest query` prints unbounded TSV to stdout (use `--format csv|json`, or
118
+ Cypher `LIMIT` to bound rows), warns on stderr when the graph has gone stale,
119
+ and with `--require-fresh` refuses a stale graph with exit code 3 — see
120
+ [docs/cli.md](docs/cli.md).
121
+
115
122
  ## Analyse an open-source repository
116
123
 
117
124
  ```python
@@ -153,7 +160,7 @@ codingest skill install # code-review Agent Skill
153
160
  ```
154
161
 
155
162
  The wheel bundles every grammar plus the `codingest` and `codingest-mcp`
156
- commands. KGLite ≥0.15.3 is installed automatically as the query/storage
163
+ commands. KGLite ≥0.15.5 is installed automatically as the query/storage
157
164
  engine; its MCP server and the transitive `mcp-methods` framework power the
158
165
  builder-aware Codingest server. Nothing else needs to be installed.
159
166
 
@@ -166,7 +173,7 @@ Python prerequisites.
166
173
  ```toml
167
174
  [dependencies]
168
175
  codingest = "0.1"
169
- kglite = "0.15.3"
176
+ kglite = "0.15.5"
170
177
  ```
171
178
 
172
179
  ```rust
@@ -238,7 +245,7 @@ diagnostic.
238
245
  ## Dependency policy
239
246
 
240
247
  `kglite` and `kglite-mcp-server` use matching crates.io requirements with a
241
- 0.15.3 minimum and a shared lockfile. This keeps the builder, persistence
248
+ 0.15.5 minimum and a shared lockfile. This keeps the builder, persistence
242
249
  handoff, and embedded MCP server on one compatible engine patch line.
243
250
 
244
251
  ## Parity with the (now-removed) in-tree component
@@ -10,7 +10,7 @@ keywords = ["knowledge-graph", "code-analysis", "tree-sitter", "cypher", "kglite
10
10
  categories = ["development-tools", "parser-implementations"]
11
11
 
12
12
  # Requires the kglite 0.15 engine API (`kglite::api::code_entities`); the
13
- # workspace pins the current 0.15 patch floor (0.15.3).
13
+ # workspace pins the current 0.15 patch floor (0.15.5).
14
14
 
15
15
  [lib]
16
16
  name = "codingest"
@@ -0,0 +1,464 @@
1
+ //! code_tree accuracy harness — the measurement substrate for the
2
+ //! re-resolution phases.
3
+ //!
4
+ //! Builds the code graph for a repo and reports, as a single JSON object:
5
+ //! build wall-time, node/edge counts, and the CALLS-resolution breakdown
6
+ //! (`total_calls` → `excluded_noise` / `no_candidate` / `ambiguous_dropped`
7
+ //! / `resolved_call_sites`, plus the de-duplicated `resolved_edges`).
8
+ //!
9
+ //! The headline metric is `resolution_rate` = `resolved_call_sites` /
10
+ //! (`total_calls` - `excluded_noise`): of every call site that wasn't stdlib
11
+ //! noise, the fraction we pinned to at least one in-project symbol. Track it
12
+ //! across phases; re-resolution should push it up without moving build-time
13
+ //! on the default path.
14
+ //!
15
+ //! Usage:
16
+ //! cargo run -p codingest --bin codingest_stats --release -- <path>
17
+ //! cargo run -p codingest --bin codingest_stats --release -- <path> --include-tests
18
+ //! cargo run -p codingest --bin codingest_stats --release -- <path> --function-metrics
19
+ //! cargo run -p codingest --bin codingest_stats --release -- <path> --edge-breakdown
20
+ //! cargo run -p codingest --bin codingest_stats --release -- <path> --dump-calls a,b,c
21
+ //!
22
+ //! `--edge-breakdown` appends a per-connection-type edge histogram to the JSON
23
+ //! object, with `IMPORTS` split by endpoint node type (`IMPORTS(File->File)`
24
+ //! vs `IMPORTS(File->Module)`) — the two are the same connection type but
25
+ //! answer different questions, and the File→File half is the dependency
26
+ //! conduit. `--dump-calls` emits the raw CALLS edges whose callee short-name
27
+ //! is in the supplied list, which is the substrate for labeling call-resolution
28
+ //! precision by hand. Both are read-only reporting over the built graph.
29
+
30
+ use kglite::api::GraphRead;
31
+ use kglite::api::{session, DirGraph, Value};
32
+ use serde::Serialize;
33
+ use std::collections::{BTreeMap, BTreeSet, HashMap};
34
+ use std::path::Path;
35
+ use std::time::Instant;
36
+
37
+ #[derive(Serialize)]
38
+ struct FunctionMetric {
39
+ path: String,
40
+ qualified_name: String,
41
+ start_line: i64,
42
+ end_line: i64,
43
+ branch_count: i64,
44
+ max_nesting: i64,
45
+ is_test: bool,
46
+ }
47
+
48
+ fn string_value(value: &Value) -> String {
49
+ match value {
50
+ Value::String(value) => value.clone(),
51
+ Value::Null => String::new(),
52
+ other => panic!("expected string metric, got {other:?}"),
53
+ }
54
+ }
55
+
56
+ fn int_value(value: &Value) -> i64 {
57
+ match value {
58
+ Value::Int64(value) => *value,
59
+ Value::UniqueId(value) => i64::from(*value),
60
+ Value::Null => 0,
61
+ other => panic!("expected integer metric, got {other:?}"),
62
+ }
63
+ }
64
+
65
+ fn bool_value(value: &Value) -> bool {
66
+ match value {
67
+ Value::Boolean(value) => *value,
68
+ Value::Null => false,
69
+ other => panic!("expected boolean metric, got {other:?}"),
70
+ }
71
+ }
72
+
73
+ fn function_metrics(graph: &kglite::api::DirGraph) -> Vec<FunctionMetric> {
74
+ let params = HashMap::new();
75
+ let options = session::ExecuteOptions::eager(&params);
76
+ let query = "MATCH (f:Function) RETURN f.file_path, f.qualified_name, \
77
+ f.line_number, f.end_line, f.branch_count, f.max_nesting, f.is_test";
78
+ let outcome = session::execute_read(graph, query, &options).expect("query function metrics");
79
+ let mut metrics: Vec<_> = outcome
80
+ .result
81
+ .rows
82
+ .iter()
83
+ .map(|row| FunctionMetric {
84
+ path: string_value(&row[0]),
85
+ qualified_name: string_value(&row[1]),
86
+ start_line: int_value(&row[2]),
87
+ end_line: int_value(&row[3]),
88
+ branch_count: int_value(&row[4]),
89
+ max_nesting: int_value(&row[5]),
90
+ is_test: bool_value(&row[6]),
91
+ })
92
+ .collect();
93
+ metrics.sort_by(|a, b| {
94
+ (&a.path, &a.qualified_name, a.start_line).cmp(&(&b.path, &b.qualified_name, b.start_line))
95
+ });
96
+ metrics
97
+ }
98
+
99
+ // ── edge breakdown ───────────────────────────────────────────────────────
100
+
101
+ /// Histogram key for one edge. `IMPORTS` is the only connection type this
102
+ /// build emits between two *different* endpoint shapes (File→File and
103
+ /// File→Module), so it is the only one split; every other type collapses to
104
+ /// its bare connection name.
105
+ fn edge_breakdown_key(conn: &str, source_type: &str, target_type: &str) -> String {
106
+ if conn == "IMPORTS" {
107
+ format!("IMPORTS({source_type}->{target_type})")
108
+ } else {
109
+ conn.to_string()
110
+ }
111
+ }
112
+
113
+ /// connection type (IMPORTS split by endpoint) → edge count. Sums to
114
+ /// `graph.edge_count()` by construction: every edge contributes exactly one key.
115
+ fn edge_breakdown(graph: &DirGraph) -> BTreeMap<String, usize> {
116
+ let mut out: BTreeMap<String, usize> = BTreeMap::new();
117
+ for e in graph.graph.edge_indices() {
118
+ let Some(edge) = graph.graph.edge_weight(e) else {
119
+ continue;
120
+ };
121
+ let Some((s, t)) = graph.graph.edge_endpoints(e) else {
122
+ continue;
123
+ };
124
+ let (Some(sn), Some(tn)) = (graph.graph.node_weight(s), graph.graph.node_weight(t)) else {
125
+ continue;
126
+ };
127
+ let key = edge_breakdown_key(
128
+ edge.connection_type_str(&graph.interner),
129
+ sn.node_type_str(&graph.interner),
130
+ tn.node_type_str(&graph.interner),
131
+ );
132
+ *out.entry(key).or_insert(0) += 1;
133
+ }
134
+ out
135
+ }
136
+
137
+ // ── CALLS dump (the labeling substrate) ──────────────────────────────────
138
+
139
+ /// Terminal segment of a `::` / `.` / `/`-separated qualified name — the bare
140
+ /// symbol a `--dump-calls` name list is matched against. Mirrors
141
+ /// `call_edges::short_type_name`'s rule (rightmost separator of any flavour
142
+ /// wins) so the dump selects exactly the names the resolver keyed on.
143
+ fn short_name(qname: &str) -> &str {
144
+ let mut cut = 0usize;
145
+ for sep in ["::", ".", "/"] {
146
+ if let Some(i) = qname.rfind(sep) {
147
+ let after = i + sep.len();
148
+ if after > cut {
149
+ cut = after;
150
+ }
151
+ }
152
+ }
153
+ &qname[cut..]
154
+ }
155
+
156
+ /// A node id as its bare string. `NodeData::id()` hands back a `Value`, whose
157
+ /// `Display` quotes strings (`"pkg.app.run"`), so the raw `to_string()` cannot
158
+ /// be short-name-split or compared against a qualified name.
159
+ fn id_string(id: std::borrow::Cow<'_, Value>) -> String {
160
+ match id.as_ref() {
161
+ Value::String(s) => s.clone(),
162
+ other => other.to_string(),
163
+ }
164
+ }
165
+
166
+ /// A string-valued property of a node/edge, or `""` when absent.
167
+ fn str_prop(props: &HashMap<String, Value>, key: &str) -> String {
168
+ match props.get(key) {
169
+ Some(Value::String(v)) => v.clone(),
170
+ _ => String::new(),
171
+ }
172
+ }
173
+
174
+ /// One CALLS edge, with both endpoints' files. The files are what makes the
175
+ /// dump self-sufficient as a labeling substrate: deciding whether an edge is a
176
+ /// true call means reading the caller's source at the recorded lines, and
177
+ /// whether the caller imports the callee's file is the structural signal
178
+ /// Phase 5's gate keys on.
179
+ #[derive(Serialize, PartialEq, Eq, Debug)]
180
+ struct CallRow {
181
+ caller: String,
182
+ callee: String,
183
+ caller_file: String,
184
+ callee_file: String,
185
+ call_lines: String,
186
+ /// Resolution metadata, empty/absent on edges that predate it or that the
187
+ /// semantic pass produced. Carried here so the labeled truth set can be
188
+ /// re-scored against a candidate suppression policy without rebuilding.
189
+ resolution: String,
190
+ candidates: i64,
191
+ import_backed: bool,
192
+ }
193
+
194
+ /// Every CALLS edge whose callee short-name is in `names`, sorted by
195
+ /// (callee, caller) so two runs — and two builds — produce identical output.
196
+ fn dump_calls(graph: &DirGraph, names: &BTreeSet<String>) -> Vec<CallRow> {
197
+ let mut rows: Vec<CallRow> = Vec::new();
198
+ for e in graph.graph.edge_indices() {
199
+ let Some(edge) = graph.graph.edge_weight(e) else {
200
+ continue;
201
+ };
202
+ if edge.connection_type_str(&graph.interner) != "CALLS" {
203
+ continue;
204
+ }
205
+ let Some((s, t)) = graph.graph.edge_endpoints(e) else {
206
+ continue;
207
+ };
208
+ let (Some(sn), Some(tn)) = (graph.graph.node_weight(s), graph.graph.node_weight(t)) else {
209
+ continue;
210
+ };
211
+ let callee = id_string(tn.id());
212
+ if !names.contains(short_name(&callee)) {
213
+ continue;
214
+ }
215
+ let props = edge.properties_cloned(&graph.interner);
216
+ rows.push(CallRow {
217
+ caller: id_string(sn.id()),
218
+ callee,
219
+ caller_file: str_prop(&sn.properties_cloned(&graph.interner), "file_path"),
220
+ callee_file: str_prop(&tn.properties_cloned(&graph.interner), "file_path"),
221
+ call_lines: str_prop(&props, "call_lines"),
222
+ resolution: str_prop(&props, "resolution"),
223
+ candidates: match props.get("candidates") {
224
+ Some(Value::Int64(v)) => *v,
225
+ _ => 0,
226
+ },
227
+ import_backed: matches!(props.get("import_backed"), Some(Value::Boolean(true))),
228
+ });
229
+ }
230
+ rows.sort_by(|a, b| (&a.callee, &a.caller).cmp(&(&b.callee, &b.caller)));
231
+ rows
232
+ }
233
+
234
+ fn main() {
235
+ let mut args = std::env::args().skip(1);
236
+ let path = match args.next() {
237
+ Some(p) => p,
238
+ None => {
239
+ eprintln!(
240
+ "usage: codingest_stats <path> [--include-tests] [--function-metrics] \
241
+ [--edge-breakdown] [--dump-calls name1,name2,...]"
242
+ );
243
+ std::process::exit(2);
244
+ }
245
+ };
246
+ let options: Vec<_> = args.collect();
247
+ let include_tests = options.iter().any(|a| a == "--include-tests");
248
+ let emit_function_metrics = options.iter().any(|a| a == "--function-metrics");
249
+ let emit_edge_breakdown = options.iter().any(|a| a == "--edge-breakdown");
250
+ let dump_call_names: Option<BTreeSet<String>> = options
251
+ .iter()
252
+ .position(|a| a == "--dump-calls")
253
+ .map(|i| match options.get(i + 1) {
254
+ Some(list) => list
255
+ .split(',')
256
+ .map(str::trim)
257
+ .filter(|s| !s.is_empty())
258
+ .map(str::to_string)
259
+ .collect(),
260
+ None => {
261
+ eprintln!("--dump-calls requires a comma-separated name list");
262
+ std::process::exit(2);
263
+ }
264
+ });
265
+
266
+ let t = Instant::now();
267
+ let (graph, stats) = match codingest::builder::run_with_options_stats(
268
+ Path::new(&path),
269
+ false,
270
+ include_tests,
271
+ None,
272
+ None,
273
+ false,
274
+ ) {
275
+ Ok(pair) => pair,
276
+ Err(e) => {
277
+ eprintln!("build failed: {e}");
278
+ std::process::exit(1);
279
+ }
280
+ };
281
+ let build_secs = t.elapsed().as_secs_f64();
282
+
283
+ if emit_function_metrics {
284
+ println!(
285
+ "{}",
286
+ serde_json::to_string_pretty(&function_metrics(&graph)).unwrap()
287
+ );
288
+ return;
289
+ }
290
+
291
+ if let Some(names) = &dump_call_names {
292
+ println!(
293
+ "{}",
294
+ serde_json::to_string_pretty(&dump_calls(&graph, names)).unwrap()
295
+ );
296
+ return;
297
+ }
298
+
299
+ let denom = stats.total_calls.saturating_sub(stats.excluded_noise);
300
+ let resolution_rate = if denom > 0 {
301
+ stats.resolved_call_sites as f64 / denom as f64
302
+ } else {
303
+ 0.0
304
+ };
305
+
306
+ let mut out = serde_json::json!({
307
+ "path": path,
308
+ "include_tests": include_tests,
309
+ "build_secs": (build_secs * 1000.0).round() / 1000.0,
310
+ "nodes": graph.graph.node_count(),
311
+ "edges": graph.graph.edge_count(),
312
+ "total_calls": stats.total_calls,
313
+ "excluded_noise": stats.excluded_noise,
314
+ "no_candidate": stats.no_candidate,
315
+ "ambiguous_dropped": stats.ambiguous_dropped,
316
+ "resolved_call_sites": stats.resolved_call_sites,
317
+ "resolved_via_inheritance": stats.resolved_via_inheritance,
318
+ "resolved_edges": stats.resolved_edges,
319
+ "resolution_rate": (resolution_rate * 10000.0).round() / 10000.0,
320
+ });
321
+ if emit_edge_breakdown {
322
+ out["edge_breakdown"] = serde_json::to_value(edge_breakdown(&graph)).unwrap();
323
+ }
324
+ println!("{}", serde_json::to_string_pretty(&out).unwrap());
325
+ }
326
+
327
+ #[cfg(test)]
328
+ mod tests {
329
+ use super::*;
330
+ use std::path::PathBuf;
331
+
332
+ fn corpus(name: &str) -> PathBuf {
333
+ Path::new(env!("CARGO_MANIFEST_DIR"))
334
+ .join("..")
335
+ .join("..")
336
+ .join("tests")
337
+ .join("corpus")
338
+ .join(name)
339
+ }
340
+
341
+ fn build(name: &str) -> std::sync::Arc<DirGraph> {
342
+ codingest::builder::run_with_options(&corpus(name), false, true, None, None, true)
343
+ .expect("corpus build")
344
+ }
345
+
346
+ #[test]
347
+ fn short_name_takes_the_rightmost_separator_of_any_flavour() {
348
+ assert_eq!(short_name("pkg.util.helper"), "helper");
349
+ assert_eq!(short_name("crate::graph::cypher::run"), "run");
350
+ assert_eq!(short_name("packages/opencode/src/mcp/fetch"), "fetch");
351
+ assert_eq!(short_name("bare"), "bare");
352
+ // Mixed separators: the rightmost one wins regardless of flavour.
353
+ assert_eq!(short_name("web/api.ts::Client.send"), "send");
354
+ }
355
+
356
+ #[test]
357
+ fn edge_breakdown_splits_imports_and_accounts_for_every_edge() {
358
+ // `agc_basic` is the ONLY committed corpus that currently produces
359
+ // IMPORTS edges at all — the very blind spot this plan's `ts_monorepo`
360
+ // corpus is added to close. Its single `# INCLUDE` resolves to one
361
+ // File→Module and one File→File edge.
362
+ let graph = build("agc_basic");
363
+ let breakdown = edge_breakdown(&graph);
364
+
365
+ // Every edge lands in exactly one bucket.
366
+ assert_eq!(
367
+ breakdown.values().sum::<usize>(),
368
+ graph.graph.edge_count(),
369
+ "breakdown must account for every edge: {breakdown:?}"
370
+ );
371
+
372
+ // Pinned exactly — an instrument that mislabels a connection type or
373
+ // collapses the IMPORTS split would still sum correctly, so the sum
374
+ // alone is not a gate.
375
+ assert_eq!(
376
+ breakdown.get("IMPORTS(File->Module)").copied(),
377
+ Some(1),
378
+ "expected exactly one File→Module IMPORTS edge: {breakdown:?}"
379
+ );
380
+ assert_eq!(
381
+ breakdown.get("IMPORTS(File->File)").copied(),
382
+ Some(1),
383
+ "expected exactly one File→File IMPORTS edge: {breakdown:?}"
384
+ );
385
+ assert!(
386
+ !breakdown.contains_key("IMPORTS"),
387
+ "IMPORTS must always be split by endpoint, never reported bare: {breakdown:?}"
388
+ );
389
+ // Representative unsplit types, to catch a key derivation that mangles
390
+ // every connection name rather than just IMPORTS.
391
+ assert_eq!(breakdown.get("CALLS").copied(), Some(4));
392
+ assert_eq!(breakdown.get("DEFINES").copied(), Some(21));
393
+ }
394
+
395
+ #[test]
396
+ fn dump_calls_selects_by_callee_short_name_and_sorts() {
397
+ let graph = build("py_basic");
398
+
399
+ // `py_basic.pkg.app.run` calls `helper` on line 5 of pkg/app.py.
400
+ let rows = dump_calls(&graph, &BTreeSet::from(["helper".to_string()]));
401
+ assert_eq!(
402
+ rows,
403
+ vec![CallRow {
404
+ caller: "py_basic.pkg.app.run".into(),
405
+ callee: "py_basic.pkg.util.helper".into(),
406
+ caller_file: "pkg/app.py".into(),
407
+ callee_file: "pkg/util.py".into(),
408
+ call_lines: "5".into(),
409
+ resolution: "unique_name".into(),
410
+ candidates: 1,
411
+ // No IMPORTS edge exists between these two files — Python
412
+ // absolute imports do not resolve (filed separately), which is
413
+ // exactly why this property must be read, not assumed.
414
+ import_backed: false,
415
+ }],
416
+ "expected the single helper CALLS edge"
417
+ );
418
+
419
+ // A name nobody calls selects nothing (the filter is real, not a
420
+ // pass-through) — `other` IS defined in the corpus but never called.
421
+ assert!(dump_calls(&graph, &BTreeSet::from(["other".to_string()])).is_empty());
422
+ assert!(dump_calls(&graph, &BTreeSet::new()).is_empty());
423
+
424
+ // Sorted by (callee, caller) — proven on the corpus with the most
425
+ // CALLS edges, which is also the one with several distinct callees.
426
+ let graph = build("agc_basic");
427
+ let all: BTreeSet<String> = graph
428
+ .graph
429
+ .edge_indices()
430
+ .filter_map(|e| {
431
+ let edge = graph.graph.edge_weight(e)?;
432
+ if edge.connection_type_str(&graph.interner) != "CALLS" {
433
+ return None;
434
+ }
435
+ let (_, t) = graph.graph.edge_endpoints(e)?;
436
+ Some(short_name(&id_string(graph.graph.node_weight(t)?.id())).to_string())
437
+ })
438
+ .collect();
439
+ assert!(all.len() > 1, "need several distinct callees to prove sort");
440
+ let rows = dump_calls(&graph, &all);
441
+ assert_eq!(rows.len(), 4, "every CALLS edge must be selected");
442
+ let keys: Vec<(String, String)> = rows
443
+ .iter()
444
+ .map(|r| (r.callee.clone(), r.caller.clone()))
445
+ .collect();
446
+ let mut sorted = keys.clone();
447
+ sorted.sort();
448
+ assert_eq!(keys, sorted, "dump must be (callee, caller)-sorted");
449
+ for row in &rows {
450
+ assert!(
451
+ all.contains(short_name(&row.callee)),
452
+ "row {row:?} escaped the name filter"
453
+ );
454
+ assert!(
455
+ !row.call_lines.is_empty(),
456
+ "row {row:?} lost its call_lines property"
457
+ );
458
+ assert!(
459
+ row.caller_file.ends_with(".agc") && row.callee_file.ends_with(".agc"),
460
+ "row {row:?} lost an endpoint file_path"
461
+ );
462
+ }
463
+ }
464
+ }