import { readRawConfig } from "../utils/config"; import { addWatchChannel, removeWatchChannel, enableWatchChannel, disableWatchChannel } from "../mcp/tools"; import { fail, ICON_PASS, ICON_FAIL } from "../utils/cli"; const HELP = `Usage: nia watch Commands: list List watch channels (default) add [behavior] Add a watch channel. If [behavior] is omitted, loads watches//behavior.md at runtime. If [behavior] is a single word, it names a different file to load. Otherwise it is treated as inline prose. remove Remove a watch channel enable Enable a watch channel disable Disable a watch channel`; export function watchCommand(): void { const sub = process.argv[3]; if (sub === "--help" || sub === "-h" || sub === "help") { console.log(HELP); return; } switch (sub) { case "list": case undefined: { const raw = readRawConfig(); const channels = (raw.channels || {}) as Record; const slack = (channels.slack || {}) as Record; const watch = (slack.watch || {}) as Record; const entries = Object.entries(watch); if (entries.length === 0) { console.log("No watch channels configured."); break; } for (const [key, val] of entries) { const cfg = val as Record; const enabled = cfg.enabled !== false; const icon = enabled ? ICON_PASS : ICON_FAIL; const rawBehavior = typeof cfg.behavior === "string" ? cfg.behavior : ""; const behavior = rawBehavior ? rawBehavior.slice(0, 80).replace(/\n/g, " ") : "(default — loads from file)"; console.log(` ${icon} ${key} ${behavior}${rawBehavior.length > 80 ? "..." : ""}`); } break; } case "add": { const name = process.argv[4]; const behavior = process.argv.slice(5).join(" ") || undefined; if (!name) { fail("Usage: nia watch add [behavior]"); } console.log(addWatchChannel(name, behavior)); break; } case "remove": { const name = process.argv[4]; if (!name) fail("Usage: nia watch remove "); console.log(removeWatchChannel(name)); break; } case "enable": { const name = process.argv[4]; if (!name) fail("Usage: nia watch enable "); console.log(enableWatchChannel(name)); break; } case "disable": { const name = process.argv[4]; if (!name) fail("Usage: nia watch disable "); console.log(disableWatchChannel(name)); break; } default: console.error(`Unknown subcommand: ${sub}`); console.log(HELP); process.exit(1); } }