From 706d8fa9afc23d36a888a36f168496ff3aa3068a Mon Sep 17 00:00:00 2001 From: kangju2000 Date: Sat, 2 Aug 2025 15:53:32 +0900 Subject: [PATCH 1/2] feat: add cancel command to terminate active intents --- src/core/commands/cancel.ts | 32 ++++++++++++++++++++++++++++++++ src/core/commands/index.ts | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/core/commands/cancel.ts 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 df9131f..7227b41 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 "./list"; export * from "./start"; From d784a677cfe0055be3ec35e4fbbece9a0cabefc0 Mon Sep 17 00:00:00 2001 From: kangju2000 Date: Sat, 2 Aug 2025 15:53:39 +0900 Subject: [PATCH 2/2] feat: add CLI command to cancel active intent --- src/cli.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index 7dd4d0d..8c658d3 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); + } + }); + async function main() { try { await program.parseAsync(process.argv);