diff --git a/scripts/work/cli.mjs b/scripts/work/cli.mjs index 62e26ab..cd3ff66 100644 --- a/scripts/work/cli.mjs +++ b/scripts/work/cli.mjs @@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url"; import { buildState } from "./state-builder.mjs"; import { runCli as runPrdShip } from "./prd-ship.mjs"; import { runCli as runDecompose } from "./decompose.mjs"; +import { runCli as runDispatch } from "./dispatch.mjs"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const REPO_ROOT = path.resolve(__dirname, "..", ".."); @@ -138,8 +139,8 @@ else if (cmd === "next") printNext(); else if (cmd === "ready") printReady(); else if (cmd === "blocked") printBlocked(); else if (cmd === "dispatch") { - // Re-dispatch to the dispatch script so it can handle its own --execute flag - import("./dispatch.mjs").catch((e) => { + // dispatch.mjs handles its own --execute flag + runDispatch(process.argv.slice(3)).catch((e) => { console.error(e); process.exit(1); }); diff --git a/scripts/work/dispatch.mjs b/scripts/work/dispatch.mjs index 99da3c7..0c07889 100644 --- a/scripts/work/dispatch.mjs +++ b/scripts/work/dispatch.mjs @@ -295,15 +295,22 @@ async function executeDispatch() { console.log("(Automatic state mutation by the orchestrator is v2.)"); } -// Only run the CLI when this module is invoked directly. Without this guard, -// importing any export (e.g. `resolveClaudeAuth` from sibling work scripts) -// triggers the CLI as a side effect. -const invokedDirectly = import.meta.url === `file://${process.argv[1]}`; -if (invokedDirectly) { - const args = process.argv.slice(2); +/** + * Explicit CLI entry. Exported so cli.mjs can dispatch into this module + * without relying on a top-level side effect (which would also fire when + * sibling work scripts import `resolveClaudeAuth`, etc.). + */ +export async function runCli(args) { if (args.includes("--execute")) { - executeDispatch(); + await executeDispatch(); } else { printPlan(); } } + +// When invoked directly (`node scripts/work/dispatch.mjs ...`), run the CLI. +// When imported by cli.mjs or any sibling, do nothing — the caller decides. +const invokedDirectly = import.meta.url === `file://${process.argv[1]}`; +if (invokedDirectly) { + runCli(process.argv.slice(2)); +}