Code Indexer
The Code Indexer scans project files and extracts structural knowledge — functions, classes, imports, and exports — into the Cortex knowledge graph as RDF triples. This gives agents an understanding of the codebase structure.
Supported languages
| Language | Extensions | Extracted patterns |
|---|---|---|
| TypeScript | .ts, .tsx | functions, classes, interfaces, imports, exports |
| JavaScript | .js, .jsx, .mjs | functions, classes, imports, exports |
| Python | .py | functions, classes, imports |
| Rust | .rs | functions, structs, impls, use statements |
| Go | .go | functions, structs, interfaces, imports |
The code indexer uses regex-based extraction, not AST parsing — it's fast but may miss complex patterns like deeply nested or dynamically generated definitions.
Incremental indexing
The indexer tracks file hashes to avoid re-indexing unchanged files:
- On each run, it computes a hash of every matching file
- Files with unchanged hashes are skipped
- Changed files have their old triples deleted and new triples created
- Deleted files have their triples removed
This makes re-indexing fast even on large codebases.
Triple patterns
The indexer generates triples following these patterns:
file:src/auth.ts → defines:function → "validateToken"
file:src/auth.ts → defines:class → "AuthService"
file:src/auth.ts → imports → "jsonwebtoken"
file:src/auth.ts → exports → "AuthService"
file:src/auth.ts → defines:interface → "AuthConfig"
These triples can be queried via mayros kg explore "file:src/auth.ts" or through the knowledge graph tools.
CLI
bash# Trigger a manual re-index mayros kg code --reindex # Show triple counts by type mayros kg stats
Configuration
json5{ codeIndexer: { enabled: true, // Enable/disable indexing include: ["src/**/*"], // Glob patterns to include exclude: [ // Glob patterns to exclude "node_modules/**", "dist/**", "*.test.*", ], languages: ["typescript", "javascript", "python", "rust", "go"], }, }
Related
- Knowledge Graph — overview of the knowledge system
- Project Memory — conventions and findings
- kg CLI — command reference