From 1d3b3f08b8e3eb78d0ef2a75abec231837fc11d0 Mon Sep 17 00:00:00 2001 From: quarnel-dev Date: Mon, 14 Sep 2026 16:48:26 +0300 Subject: [PATCH] feat(cli): wire 'why' command --- src/index.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/index.ts b/src/index.ts index 038f215..5f74187 100644 --- a/src/index.ts +++ b/src/index.ts @@ -136,6 +136,34 @@ program } }); +program + .command("why ") + .description("Print the causal chain for an event") + .option("-d, --depth ", "Max depth of the chain (1-5)", "3") + .option("--data-dir ", "Data directory override") + .option("--json", "Output JSON instead of text") + .action(async (event: string, opts) => { + const { loadConfig } = await import("./config.js"); + const { LocalJsonStore } = await import("./graph/store.js"); + const { handleWhy } = await import("./tools/why.js"); + + const config = loadConfig({ dataDir: opts.dataDir }); + const store = new LocalJsonStore(config.graphFile); + await store.load(); + + const result = await handleWhy(store, { + event, + depth: parseInt(opts.depth, 10), + }); + + if (opts.json) { + console.log(JSON.stringify(result, null, 2)); + } else { + const text = result.content.find((c: { type: string }) => c.type === "text"); + console.log(text?.text ?? "(no causal chain found)"); + } + }); + program .command("parse") .description("Parse text from stdin into graph fragment JSON on stdout")