/** * `verb` — run one `conductor_*` verb as the orchestrator, from the CLI: through the daemon's own checks and ledger rows. * * Moved out of cli.ts's switch by the per-verb module split (#462); * only the case wrapper, the injected `ctx` lookups and the imports * changed from the original bodies. */ import type { CommandContext } from "./context.ts"; import { findProject, loadConfig } from "../config.ts"; import { isPaused, pausedAt } from "../daemon.ts"; import { probeRunLane, readBaseChain } from "../gitops.ts"; import { dbPath, openStore } from "../store.ts"; import { makeTracker } from "../tracker/github.ts"; import { VERB_NAMES } from "../types.ts"; import { githubVerbActions } from "../verbs/actions.ts"; import { handleVerbCall, type VerbChannel } from "../verbs/server.ts"; export async function verbCommand(ctx: CommandContext): Promise { const name = ctx.argv[1]; if (name === undefined || !VERB_NAMES.some((n) => n === name)) { process.stderr.write( `omp-conductor: unknown verb "${name ?? ""}". Known verbs: ${VERB_NAMES.join(", ")}\n`, ); process.exit(2); } const cfg = loadConfig(); const project = findProject(cfg, ctx.projectFlag); const args: Record = {}; for (let i = 2; i < ctx.argv.length; i++) { const token = ctx.argv[i]; if (token === "--arg") { const pair = ctx.argv[i + 1]; if (pair === undefined || !pair.includes("=")) { process.stderr.write(`omp-conductor: verb --arg needs k=v, got "${pair ?? ""}"\n`); process.exit(2); } const eq = pair.indexOf("="); args[pair.slice(0, eq)] = pair.slice(eq + 1); i++; } else if (token === "--project" || token?.startsWith("--project=") === true) { // Consumed by `ctx.projectFlag` above; both spellings skip here. if (token === "--project") i++; } else { process.stderr.write( `omp-conductor: verb: unexpected argument "${token ?? ""}" (pass verb arguments as --arg k=v)\n`, ); process.exit(2); } } const store = openStore(dbPath()); try { const channel: VerbChannel = { kind: "orchestrator", path: "cli", project: project.name, role: "orchestrator", }; const reply = await handleVerbCall( { project: () => findProject(loadConfig(), project.name), projects: () => loadConfig().projects, store, tracker: makeTracker(project), actions: githubVerbActions(project), fleetStop: () => isPaused(project.name) ? "claiming is paused for this fleet (omp-conductor hold or stop)" : undefined, pausedAt: () => pausedAt(project.name), log: (m) => process.stderr.write(`${m}\n`), now: () => Date.now(), chain: { readBaseChain }, lane: { probeRunLane }, }, channel, { verb: name, args }, ); process.stdout.write(`${reply.text}\n`); // A refusal must not read as success to a script calling this. if (!reply.ok) process.exitCode = 3; } finally { store.close(); } }