mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 14:03:49 +00:00
Add before/after session events with cancellation support
- Merge branch event into session with before_branch/branch reasons
- Add before_switch, before_clear, shutdown reasons
- before_* events can be cancelled with { cancel: true }
- Update RPC commands to return cancelled status
- Add shutdown event on process exit
- New example hooks: confirm-destructive, dirty-repo-guard, auto-commit-on-exit
fixes #278
This commit is contained in:
parent
99081fce30
commit
42d7d9d9b6
20 changed files with 426 additions and 124 deletions
|
|
@ -19,13 +19,16 @@ export default function (pi: HookAPI) {
|
|||
}
|
||||
});
|
||||
|
||||
pi.on("branch", async (event, ctx) => {
|
||||
pi.on("session", async (event, ctx) => {
|
||||
// Only handle before_branch events
|
||||
if (event.reason !== "before_branch") return;
|
||||
|
||||
const ref = checkpoints.get(event.targetTurnIndex);
|
||||
if (!ref) return undefined;
|
||||
if (!ref) return;
|
||||
|
||||
if (!ctx.hasUI) {
|
||||
// In non-interactive mode, don't restore automatically
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const choice = await ctx.ui.select("Restore code state?", [
|
||||
|
|
@ -37,8 +40,6 @@ export default function (pi: HookAPI) {
|
|||
await ctx.exec("git", ["stash", "apply", ref]);
|
||||
ctx.ui.notify("Code restored to checkpoint", "info");
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
|
||||
pi.on("agent_end", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue