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:
46
src/cli/commands/show.ts
Normal file
46
src/cli/commands/show.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Command } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { findNodeByPrefix } from '../../core/store';
|
||||
import { getConnections } from '../../core/graph';
|
||||
|
||||
export const showCommand = new Command('show')
|
||||
.argument('<id>', 'Node ID (or prefix)')
|
||||
.option('--format <fmt>', 'Output format: text or json', 'text')
|
||||
.description('Show a node and its connections')
|
||||
.action(async (idRaw: string, opts) => {
|
||||
const node = findNodeByPrefix(idRaw);
|
||||
if (!node) {
|
||||
console.error(chalk.red(`Node not found: ${idRaw}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const conns = getConnections(node.id);
|
||||
|
||||
if (opts.format === 'json') {
|
||||
console.log(JSON.stringify({ ...node, embedding: undefined, connections: conns }, null, 2));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(chalk.bold.cyan(`[${node.kind}] ${node.title}`));
|
||||
console.log(`ID: ${node.id}`);
|
||||
if (node.status) console.log(`Status: ${node.status}`);
|
||||
if (node.tags.length) console.log(`Tags: ${node.tags.join(', ')}`);
|
||||
console.log(`Created: ${new Date(node.createdAt).toLocaleString()}`);
|
||||
console.log(`Updated: ${new Date(node.updatedAt).toLocaleString()}`);
|
||||
if (node.isStale) console.log(chalk.red('STALE'));
|
||||
if (node.content) console.log(`\n${node.content}`);
|
||||
|
||||
if (conns.outgoing.length) {
|
||||
console.log(chalk.bold('\nOutgoing:'));
|
||||
for (const c of conns.outgoing) {
|
||||
console.log(` ${chalk.dim(`-[${c.type}]->`)} [${c.node.kind}] ${c.node.title} (${c.node.id.slice(0, 8)})`);
|
||||
}
|
||||
}
|
||||
|
||||
if (conns.incoming.length) {
|
||||
console.log(chalk.bold('\nIncoming:'));
|
||||
for (const c of conns.incoming) {
|
||||
console.log(` [${c.node.kind}] ${c.node.title} (${c.node.id.slice(0, 8)}) ${chalk.dim(`-[${c.type}]->`)} this`);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user