Initial commit: Cortex — AI project memory & knowledge graph
SQLite-backed knowledge graph with CLI interface. Supports nodes (memory, component, task, decision) connected by typed edges, with hybrid search (BM25 + Ollama embeddings).
This commit is contained in:
27
src/cli/commands/graph.ts
Normal file
27
src/cli/commands/graph.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Command } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { findNodeByPrefix } from '../../core/store';
|
||||
import { buildTree, renderTree } from '../../core/graph';
|
||||
|
||||
export const graphCommand = new Command('graph')
|
||||
.argument('[id]', 'Root node ID (or prefix). Omit for full graph.')
|
||||
.description('Visualize the knowledge graph as a tree')
|
||||
.action(async (idRaw?: string) => {
|
||||
let rootId: string | undefined;
|
||||
if (idRaw) {
|
||||
const node = findNodeByPrefix(idRaw);
|
||||
if (!node) {
|
||||
console.error(chalk.red(`Node not found: ${idRaw}`));
|
||||
process.exit(1);
|
||||
}
|
||||
rootId = node.id;
|
||||
}
|
||||
|
||||
const trees = buildTree(rootId);
|
||||
if (trees.length === 0) {
|
||||
console.log(chalk.yellow('Graph is empty.'));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(renderTree(trees));
|
||||
});
|
||||
Reference in New Issue
Block a user