mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 19:04:37 +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
|
|
@ -1249,6 +1249,8 @@ export class AgentSession {
|
|||
|
||||
const selectedText = this._extractUserMessageText(selectedEntry.message.content);
|
||||
|
||||
let skipConversationRestore = false;
|
||||
|
||||
// Emit before_branch event (can be cancelled)
|
||||
if (this._hookRunner?.hasHandlers("session")) {
|
||||
const result = (await this._hookRunner.emit({
|
||||
|
|
@ -1263,6 +1265,7 @@ export class AgentSession {
|
|||
if (result?.cancel) {
|
||||
return { selectedText, cancelled: true };
|
||||
}
|
||||
skipConversationRestore = result?.skipConversationRestore ?? false;
|
||||
}
|
||||
|
||||
// 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")
|
||||
await this._emitToolSessionEvent("branch", previousSessionFile);
|
||||
|
||||
this.agent.replaceMessages(loaded.messages);
|
||||
if (!skipConversationRestore) {
|
||||
this.agent.replaceMessages(loaded.messages);
|
||||
}
|
||||
|
||||
return { selectedText, cancelled: false };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -323,6 +323,8 @@ export interface ToolResultEventResult {
|
|||
export interface SessionEventResult {
|
||||
/** If true, cancel the pending action (switch, clear, or branch) */
|
||||
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