Modules
Classes
Codemap
Handle for SQL queries and index runs after createCodemap.
Each query opens the database for that call; index manages its own open/close lifecycle.
Constructors
Constructor
new Codemap(): Codemap;
Returns
Accessors
root
Get Signature
get root(): string;
Absolute project root (from resolved config).
Returns
string
databasePath
Get Signature
get databasePath(): string;
Absolute path to the SQLite index file (e.g. .codemap/index.db).
Returns
string
Methods
query()
query(sql): unknown[];
Run a read-only SQL statement against the index (same semantics as the CLI query subcommand).
Parameters
| Parameter | Type | Description |
|---|---|---|
sql |
string |
Valid SQLite for the Codemap schema. |
Returns
unknown[]
Result rows from better-sqlite3-style .all().
Throws
On invalid SQL or database errors (same as better-sqlite3).
index()
index(options?): Promise<IndexResult>;
Refresh the index: incremental (git-based), full, or targeted file list.
Parameters
| Parameter | Type | Description |
|---|---|---|
options |
IndexOptions |
See RunIndexOptions. |
Returns
Promise<IndexResult>
Interfaces
ParseContext
Input for a LanguageAdapter. Paths are absolute / project-relative as noted.
Properties
| Property | Type | Description |
|---|---|---|
absPath |
string |
Absolute path on disk (for parsers that need a real filename). |
relPath |
string |
Path relative to project root (stored in DB rows). |
source |
string |
- |
LanguageAdapter
Pluggable extractor for a set of file extensions.
Remarks
Built-ins: BUILTIN_ADAPTERS. Future optional packages can register additional adapters (or replace built-ins) once a public registration API exists.
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
id |
readonly |
string |
- |
extensions |
readonly |
readonly string[] |
Extensions with leading dot, e.g. .ts, .tsx. |
Methods
parse()
parse(ctx): ParsedFilePayload;
Parameters
| Parameter | Type |
|---|---|
ctx |
ParseContext |
Returns
CodemapInitOptions
Options for createCodemap.
Properties
IndexOptions
Properties
IndexTableStats
Row counts per table after an index run (mirrors CLI summary output). Keys
use the SQLite table names (snake_case: type_members, css_vars,
css_classes, css_keyframes) so the same identifiers work directly in
SELECT … FROM <key> queries.
Extends
Record<string,number>
Indexable
[key: string]: number
Properties
IndexRunStats
Per-run counters; see IndexResult for the public shape returned from indexing APIs.
Properties
| Property | Type | Description |
|---|---|---|
indexed |
number |
Number of files written or re-indexed in this run. |
skipped |
number |
Files whose content_hash matched the index (no work done). |
elapsedMs |
number |
Wall-clock time for the indexing pipeline, in milliseconds. |
fullRebuild |
boolean |
true if this run dropped and rebuilt all tables; false for incremental / targeted. |
stats |
IndexTableStats |
Row counts per table after the run completed. |
performance? |
IndexPerformanceReport |
Set only when --performance (or RunIndexOptions.performance) is on. |
IndexResult
Outcome of Codemap#index or runCodemapIndex (CLI and programmatic index runs).
Properties
| Property | Type | Description |
|---|---|---|
mode |
"files" | "full" | "incremental" |
How the index was updated. |
indexed |
number |
Files written or re-indexed in this run. |
skipped |
number |
Files skipped (unchanged hash). |
elapsedMs |
number |
Wall-clock time for the indexing pipeline, in milliseconds. |
stats |
IndexTableStats |
Row counts per table after the run completed. |
idle? |
boolean |
Set when no file bodies were indexed (already fresh, empty files list, or deletions-only pass). |
ResolvedCodemapConfig
Fully resolved config (defaults filled, paths absolute) — stored in the process-global runtime after init and read for indexing / query / serve.
Properties
ParsedFile
One indexed file’s extracted data; workers return arrays of these and
LanguageAdapters populate a ParsedFilePayload subset.
Properties
CodemapDatabase
Minimal SQLite surface used by Codemap — implemented for bun:sqlite and
better-sqlite3 (sync APIs, transactions, PRAGMAs).
Methods
run()
run(sql, params?): void;
Parameters
| Parameter | Type |
|---|---|
sql |
string |
params? |
BindValues |
Returns
void
query()
query<T>(sql): object;
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
sql |
string |
Returns
object
| Name | Type |
|---|---|
get() |
(…params) => T | undefined |
all() |
(…params) => T[] |
transaction()
transaction<T>(fn): () => T;
Returns a function that runs the transaction when invoked (Bun / better-sqlite3 semantics).
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn |
() => T |
Returns
() => T
close()
close(): void;
Returns
void
Type Aliases
ParsedFilePayload
type ParsedFilePayload = Pick<ParsedFile,
| "category"
| "symbols"
| "imports"
| "exports"
| "components"
| "markers"
| "suppressions"
| "typeMembers"
| "typeHeritage"
| "calls"
| "importSpecifiers"
| "scopes"
| "references"
| "fileMetrics"
| "functionParams"
| "runtimeMarkers"
| "testSuites"
| "dynamicImports"
| "hasSideEffects"
| "jsxElements"
| "jsxAttributes"
| "asyncCalls"
| "tryCatchRows"
| "decorators"
| "jsdocTags"
| "cssVariables"
| "cssClasses"
| "cssKeyframes"
| "cssImportSources"
| "parseError">;
Partial parse result merged into ParsedFile after fileRow is built.
Set parseError when extraction fails but the file should still be indexed.
CodemapUserConfig
type CodemapUserConfig = z.infer<typeof codemapUserConfigSchema>;
Inferred from codemapUserConfigSchema.
Variables
BUILTIN_ADAPTERS
const BUILTIN_ADAPTERS: readonly LanguageAdapter[];
Built-in adapters (oxc TS/JS, Lightning CSS, text/markers). Order matters for the first match.
codemapUserConfigSchema
const codemapUserConfigSchema: ZodObject<{
root: ZodOptional<ZodString>;
databasePath: ZodOptional<ZodString>;
include: ZodOptional<ZodArray<ZodString>>;
excludeDirNames: ZodOptional<ZodArray<ZodString>>;
tsconfigPath: ZodOptional<ZodUnion<readonly [ZodString, ZodNull]>>;
fts5: ZodOptional<ZodBoolean>;
recipeRecency: ZodOptional<ZodBoolean>;
churn: ZodOptional<ZodObject<{
halfLifeDays: ZodOptional<ZodNumber>;
since: ZodOptional<ZodString>;
file: ZodOptional<ZodString>;
}, $strict>>;
synthesis: ZodOptional<ZodObject<{
heuristicCalls: ZodOptional<ZodBoolean>;
}, $strict>>;
apply: ZodOptional<ZodObject<{
autoApplyRecipes: ZodOptional<ZodArray<ZodString>>;
}, $strict>>;
boundaries: ZodOptional<ZodArray<ZodObject<{
name: ZodString;
from_glob: ZodString;
to_glob: ZodString;
action: ZodOptional<ZodEnum<{
allow: "allow";
deny: "deny";
}>>;
}, $strict>>>;
}, $strict>;
Zod schema for user config (<state-dir>/config.{ts,js,json}, defineConfig, API).
Unknown keys are rejected (.strict()).
CODEMAP_VERSION
const CODEMAP_VERSION: string = packageJson.version;
Package version from package.json (inlined at build time).
Functions
getAdapterForExtension()
function getAdapterForExtension(ext, adapters?):
| LanguageAdapter
| undefined;
First-match adapter lookup by file extension. ext must include the
leading dot (.tsx); returns undefined when nothing matches (the
indexer then falls back to markers-only text).
Parameters
| Parameter | Type | Default value |
|---|---|---|
ext |
string |
undefined |
adapters |
readonly LanguageAdapter[] |
BUILTIN_ADAPTERS |
Returns
| LanguageAdapter
| undefined
createCodemap()
function createCodemap(options?): Promise<Codemap>;
Programmatic entry point: loads config, initializes the process runtime, configures the import resolver, and returns a Codemap handle.
Parameters
| Parameter | Type |
|---|---|
options |
CodemapInitOptions |
Returns
Promise<Codemap>
Remarks
One project root per process: a second createCodemap() with a different root throws.
Re-initializing the same root is allowed. Audit --base worktree reindex is the only
production path that may temporarily switch roots.
Invalid project config (unknown keys, wrong types) throws at load time via the same schema as parseCodemapUserConfig.
runCodemapIndex()
function runCodemapIndex(db, options?): Promise<IndexResult>;
Parameters
| Parameter | Type |
|---|---|
db |
CodemapDatabase |
options |
IndexOptions |
Returns
Promise<IndexResult>
parseCodemapUserConfig()
function parseCodemapUserConfig(config): object;
Runtime validation for CodemapUserConfig (from JSON, defineConfig, or API).
Parameters
| Parameter | Type |
|---|---|
config |
unknown |
Returns
object
| Name | Type |
|---|---|
root? |
string |
databasePath? |
string |
include? |
string[] |
excludeDirNames? |
string[] |
tsconfigPath? |
string | null |
fts5? |
boolean |
recipeRecency? |
boolean |
churn? |
object |
churn.halfLifeDays? |
number |
churn.since? |
string |
churn.file? |
string |
synthesis? |
object |
synthesis.heuristicCalls? |
boolean |
apply? |
object |
apply.autoApplyRecipes? |
string[] |
boundaries? |
object[] |
Throws
TypeError when the shape is invalid or unknown keys are present.
defineConfig()
function defineConfig(config): object;
Helper for export default defineConfig({ ... }) in .codemap/config.ts.
Parameters
| Parameter | Type |
|---|---|
config |
{ root?: string; databasePath?: string; include?: string[]; excludeDirNames?: string[]; tsconfigPath?: string | null; fts5?: boolean; recipeRecency?: boolean; churn?: { halfLifeDays?: number; since?: string; file?: string; }; synthesis?: { heuristicCalls?: boolean; }; apply?: { autoApplyRecipes?: string[]; }; boundaries?: object[]; } |
config.root? |
string |
config.databasePath? |
string |
config.include? |
string[] |
config.excludeDirNames? |
string[] |
config.tsconfigPath? |
string | null |
config.fts5? |
boolean |
config.recipeRecency? |
boolean |
config.churn? |
{ halfLifeDays?: number; since?: string; file?: string; } |
config.churn.halfLifeDays? |
number |
config.churn.since? |
string |
config.churn.file? |
string |
config.synthesis? |
{ heuristicCalls?: boolean; } |
config.synthesis.heuristicCalls? |
boolean |
config.apply? |
{ autoApplyRecipes?: string[]; } |
config.apply.autoApplyRecipes? |
string[] |
config.boundaries? |
object[] |
Returns
object
| Name | Type |
|---|---|
root? |
string |
databasePath? |
string |
include? |
string[] |
excludeDirNames? |
string[] |
tsconfigPath? |
string | null |
fts5? |
boolean |
recipeRecency? |
boolean |
churn? |
object |
churn.halfLifeDays? |
number |
churn.since? |
string |
churn.file? |
string |
synthesis? |
object |
synthesis.heuristicCalls? |
boolean |
apply? |
object |
apply.autoApplyRecipes? |
string[] |
boundaries? |
object[] |