Skip to content

Commit c29d170

Browse files
committed
docs: align architecture, benchmark, golden-queries with audit fixes
- architecture.md: component detection heuristic (JSX return or hook usage), statement cache on Node, closeDb readonly for query paths, incremental/--files accept previously-indexed custom extensions - benchmark.md: fixture description reflects enriched minimal/ - golden-queries.md: note 13-scenario Tier A coverage across all tables
1 parent f7f0cdd commit c29d170

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

docs/architecture.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ A local SQLite database (`.codemap.db`) indexes the project tree and stores stru
129129

130130
### `--files` (targeted reindex)
131131

132-
When specific file paths are passed via `--files`, the indexer skips git diff, git status, and the full filesystem glob scan. It reads the set of already-indexed paths from the database (for import resolution), then only processes the listed files. Files that no longer exist on disk are automatically removed from the index via `ON DELETE CASCADE`.
132+
When specific file paths are passed via `--files`, the indexer skips git diff, git status, and the full filesystem glob scan. It reads the set of already-indexed paths from the database (for import resolution), then only processes the listed files. Files with non-standard extensions (e.g. custom `include` globs) are accepted and indexed as text; a warning is printed but they are not skipped. Files that no longer exist on disk are automatically removed from the index via `ON DELETE CASCADE`.
133133

134134
## Programmatic usage
135135

@@ -208,7 +208,7 @@ All tables use `STRICT` mode. Tables marked with `WITHOUT ROWID` store data dire
208208
| is_default | INTEGER | 1 if default export |
209209
| re_export_source | TEXT | Source module if re-exported |
210210

211-
### `components` — React components (detected by JSX return + PascalCase) (`STRICT`)
211+
### `components` — React components (detected by PascalCase + JSX return or hook usage) (`STRICT`)
212212

213213
| Column | Type | Description |
214214
| ----------------- | ---------- | ----------------------------- |
@@ -286,7 +286,7 @@ Uses the Rust-based `oxc-parser` via NAPI bindings to parse TypeScript/TSX/JS/JS
286286
- **Symbols**: Functions, arrow functions, classes, interfaces, type aliases, enums — with reconstructed signatures
287287
- **Imports**: All `import` statements with specifiers, source paths, and type-only flags
288288
- **Exports**: Named exports, default exports, re-exports
289-
- **Components**: React components detected via PascalCase name + JSX return. Extracts props type and hooks used
289+
- **Components**: React components detected via PascalCase name + (JSX return **or** hook usage). A PascalCase function in `.tsx`/`.jsx` that neither returns JSX nor calls hooks is indexed only as a symbol, not a component. Extracts props type and hooks used
290290
- **Markers**: `TODO`, `FIXME`, `HACK`, `NOTE` comments with line numbers
291291

292292
### CSS — `css-parser.ts` (`lightningcss`)
@@ -327,9 +327,10 @@ The indexer uses git to detect changes since the last indexed commit:
327327

328328
1. **Stores `last_indexed_commit`** (HEAD SHA) in the `meta` table after each run
329329
2. On next run, computes `git diff --name-only <last_commit>..HEAD` + `git status --porcelain`
330-
3. Only re-indexes changed files (SHA-256 content comparison), using DB-sourced `indexedPaths` for import resolution (skips full `collectFiles()` glob scan)
331-
4. Deleted files are removed via `ON DELETE CASCADE` — deleting from `files` cascades to all related tables
332-
5. Falls back to full rebuild if commit history is incompatible (e.g. force push, branch switch)
330+
3. Filters changed files to those with a known extension **or** already present in the `files` table (so custom-extension files indexed during `--full` are re-indexed on subsequent incremental runs)
331+
4. Only re-indexes changed files (SHA-256 content comparison), using DB-sourced `indexedPaths` for import resolution (skips full `collectFiles()` glob scan)
332+
5. Deleted files are removed via `ON DELETE CASCADE` — deleting from `files` cascades to all related tables
333+
6. Falls back to full rebuild if commit history is incompatible (e.g. force push, branch switch)
333334

334335
## File Artifacts
335336

@@ -436,7 +437,7 @@ Until the first release, Codemap keeps **`SCHEMA_VERSION` at 1**; pull `--full`
436437

437438
### `bun:sqlite` API
438439

439-
All DDL and PRAGMA statements use `Database.run()`. The `sqlite-db.ts` wrapper abstracts both Bun (`bun:sqlite`) and Node (`better-sqlite3`). On Bun, `Database.query()` caches compiled statements; on Node, `better-sqlite3` re-prepares on each call via the wrapper's `run()` method. Read queries use the wrapper's `.query().all()` or `.get()`. Bulk inserts use the generic `batchInsert<T>()` helper with multi-row `INSERT ... VALUES (...),(...),(...)` in batches of 100, pre-computed placeholders, and zero-copy index-bounds iteration.
440+
All DDL and PRAGMA statements use `Database.run()`. The `sqlite-db.ts` wrapper abstracts both Bun (`bun:sqlite`) and Node (`better-sqlite3`). On Bun, `Database.query()` caches compiled statements internally. On Node, the wrapper maintains a `Map<string, Statement>` cache so repeated `run()` and `query()` calls with the same SQL reuse a single prepared statement. Read queries use the wrapper's `.query().all()` or `.get()`. Bulk inserts use the generic `batchInsert<T>()` helper with multi-row `INSERT ... VALUES (...),(...),(...)` in batches of 100, pre-computed placeholders, and zero-copy index-bounds iteration.
440441

441442
### PRAGMAs (set on every `openDb()`)
442443

@@ -457,6 +458,8 @@ All DDL and PRAGMA statements use `Database.run()`. The `sqlite-db.ts` wrapper a
457458
| `analysis_limit` | `400` | Caps rows sampled by `optimize` to keep it fast |
458459
| `optimize` || Gathers query planner statistics (`sqlite_stat1`) for better plans |
459460

461+
Read-only query paths (`printQueryResult`, `queryRows`) call `closeDb` with `{ readonly: true }`, which skips both PRAGMAs to avoid write contention under concurrent `codemap query` processes.
462+
460463
### WITHOUT ROWID tables
461464

462465
Tables with a TEXT PRIMARY KEY and no auto-increment benefit from `WITHOUT ROWID` — the data is stored directly in the primary key B-tree instead of a separate rowid B-tree, eliminating a lookup indirection:

docs/benchmark.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ The benchmark also measures the cost of keeping the index fresh (3 runs each, sa
206206

207207
#### `fixtures/minimal/`
208208

209-
Small **private** package (not published) with intentional:
209+
Small **private** package (not published) with intentional coverage of all indexed tables:
210210

211-
- `usePermissions`, `~/api/client` import, `components/shop/*`, `utils/date`, CSS variables, and a TODO marker.
211+
- **Symbols / imports / dependencies**: `usePermissions`, `~/api/client` path alias, `components/shop/*`, `utils/date`
212+
- **Components**: `ShopButton` (JSX return) + `FormatPrice` (PascalCase non-component — validates detection heuristic)
213+
- **CSS**: variables (`--color-brand`, `--spacing-md`), class selectors (`.container`, `.primary` in a `.module.css`), `@keyframes fadeIn`, `@import` edge
214+
- **Markers**: `TODO` (in `notes.md`) + `FIXME` (in `consumer.ts`)
212215

213216
**Local:**
214217

docs/golden-queries.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ Scenarios live in **`fixtures/golden/scenarios.json`** (Tier A) or optional **`s
6969

7070
## Status
7171

72-
| Area | State |
73-
| ----------------------------- | ----------------------------------------------------------------------- |
74-
| Tier A runner + CI | **`bun run test:golden`** in `check` |
75-
| Tier B external + schema | **`test:golden:external`**, Zod in **`scripts/query-golden/schema.ts`** |
76-
| Subset matchers + budgets | **`match`**, **`budgetMs`**, **`--strict-budget`** |
77-
| Optional CI for public corpus | Deferred — [roadmap § Backlog](./roadmap.md#backlog) |
72+
| Area | State |
73+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
74+
| Tier A runner + CI | **`bun run test:golden`** in `check` |
75+
| Tier A scenario coverage | 13 scenarios across all indexed tables: files, symbols, imports, exports, components, dependencies, markers, CSS vars/classes/keyframes |
76+
| Tier B external + schema | **`test:golden:external`**, Zod in **`scripts/query-golden/schema.ts`** |
77+
| Subset matchers + budgets | **`match`**, **`budgetMs`**, **`--strict-budget`** |
78+
| Optional CI for public corpus | Deferred — [roadmap § Backlog](./roadmap.md#backlog) |
7879

7980
---
8081

0 commit comments

Comments
 (0)