mayros code-index

Scan the codebase structure and store it as RDF triples in the Cortex knowledge graph. Supports incremental updates via content hashing so only changed files are re-indexed.

Subcommands

code-index run

Run a full or incremental code index. Scans TypeScript/JS files using regex-based parsing, detects functions, classes, imports, and file entities, and writes them as triples to Cortex.

Options:

FlagDescription
--path <dir>Override the project root directory (default: current working directory)

Output includes:

  • Total files scanned
  • New, changed, unchanged, and removed file counts
  • Entity and triple counts
  • Duration in milliseconds

code-index status

Show the current code index statistics from Cortex:

  • Files — number of indexed files
  • Functions — number of indexed functions
  • Classes — number of indexed classes
  • Imports — number of indexed imports
  • Last indexed — timestamp of the last index run

code-index query <term>

Search code entities in the knowledge graph by name or file path.

ArgumentDescription
<term>Search term (symbol name, file path, or module)

Options:

FlagDescription
--type <type>Filter by entity type: function, class, import, file
--limit <n>Maximum results to return (default: 10)

Results show the entity type, name, file path, and line number.

How it works

  1. The scanner walks configured paths and file extensions
  2. Each file is hashed (SHA-256) for incremental change detection
  3. Regex patterns extract functions, classes, imports, and file metadata
  4. Entities are mapped to RDF triples using namespace-prefixed predicates
  5. Triples are stored in Cortex with code:type, code:name, code:path, and code:line predicates

Examples

bash
mayros code-index run
mayros code-index run --path /path/to/project
mayros code-index status
mayros code-index query "CortexClient"
mayros code-index query "index.ts" --type file
mayros code-index query "createTriple" --type function --limit 5