diff --git a/src/cli.ts b/src/cli.ts index 9c5a582..154f678 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -42,6 +42,22 @@ program } }); +program + .command("cancel") + .description("Cancel the active intent") + .action(async () => { + try { + const projectId = await ensureProject(); + const branchId = await ensureBranch(projectId); + + const intent = await commands.cancel({ branchId }); + console.log(`Cancelled intent #${intent.id}: ${intent.message}`); + } catch (error) { + console.error("Failed to cancel intent:", getErrorMessage(error)); + process.exit(1); + } + }); + program .command("finish") .description("Finish the current active intent") diff --git a/src/core/commands/cancel.ts b/src/core/commands/cancel.ts new file mode 100644 index 0000000..1337fed --- /dev/null +++ b/src/core/commands/cancel.ts @@ -0,0 +1,32 @@ +import { eq } from "drizzle-orm"; +import { db } from "../db"; +import { type Intent, intents } from "../db/schema"; +import { findActiveIntent } from "./findActiveIntent"; + +export async function cancel({ + branchId, +}: { + branchId: string; +}): Promise { + try { + const activeIntent = await findActiveIntent({ branchId }); + + if (!activeIntent) { + throw new Error("No active intent found for this branch"); + } + + return db + .update(intents) + .set({ + status: "cancelled", + }) + .where(eq(intents.id, activeIntent.id)) + .returning() + .get(); + } catch (error) { + console.error("Failed to cancel intent: ", error); + throw new Error( + `Failed to cancel intent: ${error instanceof Error ? error.message : "Unknown error"}`, + ); + } +} diff --git a/src/core/commands/index.ts b/src/core/commands/index.ts index 3e15f2b..b658a10 100644 --- a/src/core/commands/index.ts +++ b/src/core/commands/index.ts @@ -1,3 +1,4 @@ +export * from "./cancel"; export * from "./findActiveIntent"; export * from "./finish"; export * from "./list";