import { Command } from 'commander'; import chalk from 'chalk'; import { findNodeByPrefix } from '../../core/store'; import { getConnections } from '../../core/graph'; import { NodeKind } from '../../types'; export const childrenCommand = new Command('children') .argument('', 'Parent node ID (or prefix)') .option('--kind ', 'Filter children by kind') .option('--format ', 'Output format: text or json', 'text') .description('List child nodes (outgoing "contains" edges)') .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); let children = conns.outgoing.filter(c => c.type === 'contains'); if (opts.kind) { children = children.filter(c => c.node.kind === opts.kind); } if (opts.format === 'json') { console.log(JSON.stringify(children.map(c => ({ id: c.node.id, kind: c.node.kind, title: c.node.title, status: c.node.status, })), null, 2)); return; } if (children.length === 0) { console.log(chalk.dim('No children.')); return; } console.log(chalk.bold(`Children of [${node.kind}] ${node.title}:`)); for (const c of children) { console.log(` ${c.node.id.slice(0, 8)} [${c.node.kind}] ${c.node.title}`); } });