Skip to content

v0.11.0 — Intelligent Rules (Tier 2) #445

Closed

Description

@ajianaz

Design: v0.11.0 — Intelligent Rules (Tier 2)

Goal

Add index-powered deterministic rules to cora review — rules that require symbol graph intelligence, impossible with regex alone.

Features

1. Unused Import Detection via Index (P0)

Problem: Regex can't determine if an imported symbol is actually used in the file. Tree-sitter extracts import edges, but nothing checks if the imported symbol appears as a usage in the same file.

Approach:

For each changed file:
  1. Query edges table: IMPORTS edges where source_file = changed_file
  2. For each imported symbol:
     a. Query: does this symbol appear as a callee/usage in the file?
     b. If NO usages found → unused import finding

SQL queries needed:

-- Find all imports for a file
SELECT source, target, line FROM edges
WHERE file = ?1 AND kind = 'IMPORTS' AND project_id = ?2

-- Check if imported symbol is used in file (via call_graph or edges)
SELECT 1 FROM call_graph cg
WHERE cg.caller_file = ?1 AND cg.callee LIKE ?2 AND cg.project_id = ?3
LIMIT 1

Implementation:

  • New function: graph::find_unused_imports(conn, file, project_id)
  • New scanner: src/engine/unused_import_scanner.rs (follows secrets_scanner pattern)
  • Wire into review.rs alongside secrets/security scans
  • Finding severity: Minor (unused import, not a bug)

Scope: Works when index is available. Graceful skip when no index.

Languages: Initially Rust, TypeScript, Go, Python (where imports are well-extracted).
Others can be added incrementally.

2. Dead Code Flag in Review (P0)

Problem: cora dead-code exists as standalone command, but review doesn't flag dead code in changed files.

Approach:

For each changed file:
  1. Extract defined symbols (functions, methods, structs)
  2. For each defined symbol: find_callers(symbol)
  3. If 0 callers AND not a test AND not entry point → dead code finding

Implementation:

  • New function: graph::find_dead_code_in_file(conn, file, project_id)
  • New scanner: src/engine/dead_code_scanner.rs
  • Wire into review.rs as deterministic rule
  • Finding severity: Info (dead code is informational, not a bug)

Exclusions:

  • Entry points: main(), #[entry_point], exported functions
  • Test functions (naming: test_*, *_test, *_spec)
  • Public trait implementations (could be used externally)
  • Symbols with < 3 lines body (trivially small)

3. Breaking Change Detection (P1)

Problem: When a review removes or renames a public symbol, downstream callers break silently.

Approach:

For each removed/modified symbol in diff:
  1. If symbol was public (exported, pub fn, export default)
  2. find_callers(symbol) → any callers exist?
  3. If yes → breaking change finding
     "Removing `foo` breaks 3 callers: bar (src/baz.rs:10), qux (src/quux.rs:25)"

Implementation:

  • New scanner: src/engine/breaking_change_scanner.rs
  • Parse diff for removed lines containing public symbol definitions
  • Cross-reference with index callers
  • Finding severity: Major (breaking change)

Challenges:

  • Detecting "public" varies by language (pub fn, export, pub struct, etc.)
  • Renames are harder to detect (need to compare old vs new symbol names)
  • Initial scope: Rust only (clear pub keyword), expand later

4. HTTP Route Detection (P1)

Problem: HTTP route handlers are not tracked as symbols. Can't trace "which route calls this function?"

New EdgeKind variant:

pub enum EdgeKind {
    Calls, Imports, Implements, Inherits, ChildOf,
    Route,  // NEW: HTTP route → handler function
}

Per-framework patterns:

Framework Pattern Example
Axum #[get("/path")] #[get("/users")]
Actix #[get("/path")] #[get("/users")]
Rocket #[get("/path")] #[get("/users")]
Go net/http http.HandleFunc("/path", handler) mux.HandleFunc("/", handler)
Express/Fastify app.get("/path", handler) app.get("/users", listUsers)
SvelteKit +page.server.ts Exported actions/load

Implementation:

  • New extraction logic in ast.rs per language
  • New Route edge in edges table
  • cora query "GET /users -> *" traces route to handler

Architecture

cora review (with index available)
│
├─ Parse diff → diff_chunks
│
├─ Extract symbols → outbound / inbound
│
├─ Context Chain Builder (existing)
│
├─ Brain Enrichment (Tier 1, existing)
│
├─ 🆕 Deterministic Index Rules (Tier 2)
│   ├─ unused_import_scanner → unused import findings
│   ├─ dead_code_scanner → dead code in changed files
│   ├─ breaking_change_scanner → breaking API changes
│   └─ (future) route coverage scanner
│
├─ Deterministic rules (existing — regex-based)
│
└─ LLM review prompt
    ├─ system prompt + diff
    ├─ brain context (Tier 1)
    ├─ 🆕 index rule findings (Tier 2) — injected as context
    ├─ context chain text
    └─ language-specific context

Files to Change

File Change Est. LOC
src/index/graph.rs Add find_unused_imports(), find_dead_code_in_file() +80
src/engine/unused_import_scanner.rs NEW — unused import detection +60
src/engine/dead_code_scanner.rs NEW — dead code in review +50
src/engine/breaking_change_scanner.rs NEW — breaking change detection +70
src/engine/review.rs Wire new scanners into review pipeline +30
src/index/ast.rs Add EdgeKind::Route, route extraction per language +100
Cargo.toml Bump version to 0.11.0 +1
CHANGELOG.md v0.11.0 changelog +40

Total estimated: ~430 LOC new code

Backward Compatibility

Scenario Behavior
No index Identical to v0.10.0 — regex rules only, no index rules
Index exists 🆕 Index-powered rules fire alongside regex rules
CI (no persistent index) cora index && cora review --ci enables index rules

Testing Plan

  1. Unit test: find_unused_imports() — mock DB with known import edges
  2. Unit test: find_dead_code_in_file() — mock DB with known call graph
  3. Unit test: breaking_change_scanner — diff with removed public symbol
  4. Integration test: cora index && cora review on cora-code itself
  5. Pre-commit hook test: verify hook runs index + review with new rules
  6. Regression: review without index — identical output to v0.10.0

Non-Goals (v0.12.0+)

Activity

  1. added
    enhancement
    scope:cli
    scope:code-intel
    on Aug 1, 2026
  2. added a commit that references this issue on Aug 1, 2026
    3f88689
  3. added a commit that references this issue on Aug 1, 2026
    899ac6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementscope:cliscope:code-intel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions