Home · Developers · Guides · Indexing

Workspace

Indexing

Incremental scanner and cache

The novacoder/indexing/ package is the incremental indexing pipeline for Nova Coder. It is consumed by WorkspaceService to build project understanding.

Status: IMPLEMENTED ✅

The indexing pipeline supports:

  • File scanning with hash-based change detection
  • Language detection from file extensions
  • Symbol extraction for Python, JavaScript, and TypeScript
  • Generic symbol extraction via regex for unsupported languages (imports, classes, functions)
  • Tree-sitter extraction (optional), accurate multi-language parsing with incremental re-parsing when the treesitter extra is installed (pip install "novacoder[treesitter]"). SymbolExtractor prefers TreeSitterExtractor per language and falls back to the built-in extractors when a grammar is unavailable or parsing fails.
  • Incremental scanning, only changed and deleted files are reprocessed
  • Symbol index for fast lookup
  • Import extraction for dependency graph building

Package Layout

novacoder/indexing/
├── __init__.py       # Public re-exports
├── languages.py      # LanguageDetector
├── scanner.py        # ProjectScanner, FileEntry
├── symbols.py        # Symbol, SymbolExtractor, SymbolIndex
└── extractors/
    ├── __init__.py   # EXTRACTORS registry
    ├── base.py       # LanguageExtractor ABC
    ├── generic.py
    ├── javascript.py
    ├── python.py
    └── typescript.py

ProjectScanner

ProjectScanner discovers files and returns only changed files on incremental scans.

from novacoder.indexing import ProjectScanner

scanner = ProjectScanner("/path/to/project")
files = scanner.scan()

# Incremental re-scan
changed = scanner.scan(incremental=True)
deleted = scanner.last_deleted

Performance semantics (post-Report 34)

  • Metadata fast-path: scan() stats each file and skips read_bytes + sha256 + symbol extraction when (mtime, size) match the stored entry, in both incremental and non-incremental modes. A no-change rescan of this repo (~1800 indexed files) went from ~15–48s to ~0.5s.
  • Pruned traversal: the scanner walks with os.walk and prunes excluded directories (node_modules, .venv, .git, …) before descending, dependency trees are never entered. Path.rglob used to stat all ~30k excluded files first.
  • Single extraction: _index_file extracts symbols once; consumers reuse entry.symbols (WorkspaceService.scan, _run_scan) instead of re-extracting.
  • entry.content is transient: set only for changed/new files and released by consumers after use. Callers must not assume content persists.
  • Lazy graphs: WorkspaceService marks its four symbol graphs dirty on changes and rebuilds them on first property access, not per scan.
  • Change key caveat: mtime+size is the fast-path key; a same-size same-mtime edit is the accepted edge case (hash check catches mtime-only touches cheaply).

See backups/reports_archive_2026-10-13/ai-chat-performance/34_large_project_performance.md for measurements and scripts/bench_indexing.py for the benchmark harness.

Symbol Extraction

SymbolExtractor dispatches to a language-specific extractor.

from novacoder.indexing import SymbolExtractor, SymbolIndex

result = SymbolExtractor().extract("main.py")
print(result["classes"])
print(result["functions"])
print(result["imports"])

index = SymbolIndex()
index.add(result["symbols"])
print(index.find(kind="class"))

Language Detection

LanguageDetector maps file extensions to language identifiers.

from novacoder.indexing import LanguageDetector

print(LanguageDetector.detect("main.py"))      # python
print(LanguageDetector.detect("app.js"))       # javascript
print(LanguageDetector.detect("app.ts"))       # typescript

Integration with WorkspaceService

WorkspaceService uses ProjectScanner and SymbolExtractor from novacoder/indexing/ to maintain the project index. It publishes WorkspaceScanned, WorkspaceFileChanged, and WorkspaceSymbolsUpdated events.

The FileWatcher debounces filesystem events (default 1s quiet period, one trailing run if changes arrive during a scan) and its polling fallback prunes the scanner's literal exclude dirs. IndexingService.ingest() runs the scan + graph builds in a threadpool and bounds embedding concurrency (asyncio.Semaphore(8)); VectorMemoryStore is capacity-bounded (max_entries=50_000, FIFO) and skips re-embedding identical text.

Development Instructions

Adding a New Language

  1. Edit LanguageDetector.EXTENSIONS in novacoder/indexing/languages.py.
  2. Add a new extractor in novacoder/indexing/extractors/ if needed.
  3. Register the extractor in novacoder/indexing/extractors/__init__.py.

Adding a New Extractor

  1. Create a class extending LanguageExtractor.
  2. Implement extract(path, content) -> dict[str, Any] returning imports, classes, functions, symbols.
  3. Register it in EXTRACTORS under the language identifier.
  4. Add tests in tests/test_indexing.py.

Source: wiki/indexing.md · rendered 2026-11-10