Skip to content

Commit bba5bac

Browse files
authored
feat: add cancel command to CLI (#44)
* feat: add cancel command to terminate active intents * feat: add CLI command to cancel active intent
1 parent 30f509d commit bba5bac

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎src/cli.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ program
4242
}
4343
});
4444

45+
program
46+
.command("cancel")
47+
.description("Cancel the active intent")
48+
.action(async () => {
49+
try {
50+
const projectId = await ensureProject();
51+
const branchId = await ensureBranch(projectId);
52+
53+
const intent = await commands.cancel({ branchId });
54+
console.log(`Cancelled intent #${intent.id}: ${intent.message}`);
55+
} catch (error) {
56+
console.error("Failed to cancel intent:", getErrorMessage(error));
57+
process.exit(1);
58+
}
59+
});
60+
4561
program
4662
.command("finish")
4763
.description("Finish the current active intent")

‎src/core/commands/cancel.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { eq } from "drizzle-orm";
2+
import { db } from "../db";
3+
import { type Intent, intents } from "../db/schema";
4+
import { findActiveIntent } from "./findActiveIntent";
5+
6+
export async function cancel({
7+
branchId,
8+
}: {
9+
branchId: string;
10+
}): Promise<Intent> {
11+
try {
12+
const activeIntent = await findActiveIntent({ branchId });
13+
14+
if (!activeIntent) {
15+
throw new Error("No active intent found for this branch");
16+
}
17+
18+
return db
19+
.update(intents)
20+
.set({
21+
status: "cancelled",
22+
})
23+
.where(eq(intents.id, activeIntent.id))
24+
.returning()
25+
.get();
26+
} catch (error) {
27+
console.error("Failed to cancel intent: ", error);
28+
throw new Error(
29+
`Failed to cancel intent: ${error instanceof Error ? error.message : "Unknown error"}`,
30+
);
31+
}
32+
}

‎src/core/commands/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./cancel";
12
export * from "./findActiveIntent";
23
export * from "./finish";
34
export * from "./list";

0 commit comments

Comments
 (0)