mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 19:05:11 +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
|
|
@ -186,9 +186,11 @@ export class RpcClient {
|
|||
|
||||
/**
|
||||
* Reset session (clear all messages).
|
||||
* @returns Object with `cancelled: true` if a hook cancelled the reset
|
||||
*/
|
||||
async reset(): Promise<void> {
|
||||
await this.send({ type: "reset" });
|
||||
async reset(): Promise<{ cancelled: boolean }> {
|
||||
const response = await this.send({ type: "reset" });
|
||||
return this.getData(response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -311,15 +313,18 @@ export class RpcClient {
|
|||
|
||||
/**
|
||||
* Switch to a different session file.
|
||||
* @returns Object with `cancelled: true` if a hook cancelled the switch
|
||||
*/
|
||||
async switchSession(sessionPath: string): Promise<void> {
|
||||
await this.send({ type: "switch_session", sessionPath });
|
||||
async switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {
|
||||
const response = await this.send({ type: "switch_session", sessionPath });
|
||||
return this.getData(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Branch from a specific message.
|
||||
* @returns Object with `text` (the message text) and `cancelled` (if hook cancelled)
|
||||
*/
|
||||
async branch(entryIndex: number): Promise<{ text: string }> {
|
||||
async branch(entryIndex: number): Promise<{ text: string; cancelled: boolean }> {
|
||||
const response = await this.send({ type: "branch", entryIndex });
|
||||
return this.getData(response);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue