Skip to content

feat(cli): add stats command for indexed codebase - #53

Merged
lexasub merged 1 commit into
mainfrom
feat/stats-command
Aug 1, 2026
Merged

feat(cli): add stats command for indexed codebase#53
lexasub merged 1 commit into
mainfrom
feat/stats-command

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #13

Adds ast-rag stats, reporting the four things the issue asks for — node counts by kind, edge counts by type, language distribution, file count — plus --json for scripting.

$ ast-rag stats
─────────────────── AST-RAG Index Statistics ───────────────────
  Files indexed: 103

Nodes (921 total)
  Field                     414
  Method                    368
  Class                     100
  Constructor                27
  Interface                   9
  Enum                        3

Edges (951 total)
  CONTAINS_FIELD            409
  CONTAINS_METHOD           392
  CALLS                     150

Languages
  java                      921  (100%)

That output is from a real 103-file Spring Boot codebase, not a fixture.

Two details worth flagging

Edges are grouped by the kind property, not by relationship type. batch_upsert_edges writes every edge as a generic :EDGE and carries the semantic type as a property, so type(r) would collapse everything into a single EDGE bucket and the command would look broken. The query uses coalesce(r.kind, type(r)) so it still degrades sensibly if typed relationships are ever introduced. There's a test pinning this specifically, so it can't quietly regress.

CurrentVersion is excluded from node counts. It's the graph's bookkeeping pointer rather than a code node — including it made the total read 922 for a codebase with 921 nodes.

Tests

5 new tests in tests/test_stats_command.py, all against a mock driver so they need no live Neo4j: totals and shaping, the two query-shape guards above, the empty-index hint, and --json emitting parseable JSON.

Verification

ruff check ast_rag/ tests/     All checks passed!
ruff format --check            76 files already formatted
pytest tests/                  3 failed, 179 passed, 2 xfailed

Baseline on main is 3 failed, 174 passed — same three pre-existing failures (fixed separately in #51), plus the 5 new tests.

Independent of #50, #51 and #52; branches from main.

Reports the four things the issue asks for -- node counts by kind, edge counts
by type, language distribution and file count -- plus --json for scripting.

Edges are grouped by the `kind` property rather than by relationship type,
because batch_upsert_edges writes everything as a generic :EDGE and carries the
semantic type as a property. Grouping by type(r) would report a single 'EDGE'
bucket. A test pins that so the query can't regress to type(r).

The CurrentVersion bookkeeping node is excluded from node counts; it is the
graph's version pointer, not code.

Verified against a 103-file Spring Boot index:

  Files indexed: 103
  Nodes (921 total): Field 414, Method 368, Class 100, Constructor 27, ...
  Edges (951 total): CONTAINS_FIELD 409, CONTAINS_METHOD 392, CALLS 150
  Languages: java 921 (100%)

Suite: 3 failed, 179 passed (baseline on main: 3 failed, 174 passed) -- same
three pre-existing failures, fixed separately in #51.
@r0h1tb

r0h1tb commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI on this PR is red at the Lint with ruff step, which is pre-existing and unrelated to these changes — main fails identically.

Ruff is unpinned and [tool.ruff] never set select, so a newer ruff widened its default rule set and the tree went from clean to 496 findings with no code change. Running today's ruff against 16ae8bd — the last commit whose CI run was green — also reports 496.

Because lint runs before pytest, the Run tests step is skipped, so CI hasn't actually executed the suite since 2026-07-27.

#51 fixes that and is passing. Once it lands, this PR should go green on a re-run; I've verified all three CI steps locally in the meantime.

@lexasub

lexasub commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Good pr

@lexasub
lexasub merged commit 0d939fd into main Aug 1, 2026
1 check failed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in raged kanban Aug 1, 2026
@lexasub
lexasub deleted the feat/stats-command branch August 1, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add Statistics Command

2 participants