mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 10:02:23 +00:00
Add skipConversationRestore for before_branch hooks (#286)
This commit is contained in:
parent
4492a3f304
commit
2953a9d8d4
3 changed files with 14 additions and 2 deletions
|
|
@ -154,7 +154,12 @@ pi.on("session", async (event, ctx) => {
|
||||||
if (event.reason === "before_clear") {
|
if (event.reason === "before_clear") {
|
||||||
return { cancel: true };
|
return { cancel: true };
|
||||||
}
|
}
|
||||||
// No return needed if not cancelling
|
|
||||||
|
// For before_branch only: create branch but skip conversation restore
|
||||||
|
// (useful for checkpoint hooks that restore files separately)
|
||||||
|
if (event.reason === "before_branch") {
|
||||||
|
return { skipConversationRestore: true };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1249,6 +1249,8 @@ export class AgentSession {
|
||||||
|
|
||||||
const selectedText = this._extractUserMessageText(selectedEntry.message.content);
|
const selectedText = this._extractUserMessageText(selectedEntry.message.content);
|
||||||
|
|
||||||
|
let skipConversationRestore = false;
|
||||||
|
|
||||||
// Emit before_branch event (can be cancelled)
|
// Emit before_branch event (can be cancelled)
|
||||||
if (this._hookRunner?.hasHandlers("session")) {
|
if (this._hookRunner?.hasHandlers("session")) {
|
||||||
const result = (await this._hookRunner.emit({
|
const result = (await this._hookRunner.emit({
|
||||||
|
|
@ -1263,6 +1265,7 @@ export class AgentSession {
|
||||||
if (result?.cancel) {
|
if (result?.cancel) {
|
||||||
return { selectedText, cancelled: true };
|
return { selectedText, cancelled: true };
|
||||||
}
|
}
|
||||||
|
skipConversationRestore = result?.skipConversationRestore ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create branched session (returns null in --no-session mode)
|
// Create branched session (returns null in --no-session mode)
|
||||||
|
|
@ -1293,7 +1296,9 @@ export class AgentSession {
|
||||||
// Emit session event to custom tools (with reason "branch")
|
// Emit session event to custom tools (with reason "branch")
|
||||||
await this._emitToolSessionEvent("branch", previousSessionFile);
|
await this._emitToolSessionEvent("branch", previousSessionFile);
|
||||||
|
|
||||||
this.agent.replaceMessages(loaded.messages);
|
if (!skipConversationRestore) {
|
||||||
|
this.agent.replaceMessages(loaded.messages);
|
||||||
|
}
|
||||||
|
|
||||||
return { selectedText, cancelled: false };
|
return { selectedText, cancelled: false };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,8 @@ export interface ToolResultEventResult {
|
||||||
export interface SessionEventResult {
|
export interface SessionEventResult {
|
||||||
/** If true, cancel the pending action (switch, clear, or branch) */
|
/** If true, cancel the pending action (switch, clear, or branch) */
|
||||||
cancel?: boolean;
|
cancel?: boolean;
|
||||||
|
/** If true (for before_branch only), skip restoring conversation to branch point while still creating the branched session file */
|
||||||
|
skipConversationRestore?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue