Split HookContext and HookCommandContext to prevent deadlocks
HookContext (all events): - isIdle() - read-only state check - hasQueuedMessages() - read-only state check - abort() - fire-and-forget, does not wait HookCommandContext (slash commands only): - waitForIdle() - waits for agent to finish - newSession(options?) - create new session - branch(entryId) - branch from entry - navigateTree(targetId, options?) - navigate session tree Session control methods moved from HookAPI (pi.*) to HookCommandContext (ctx.*) because they can deadlock when called from event handlers that run inside the agent loop (tool_call, tool_result, context events).
This commit is contained in:
@@ -80,9 +80,6 @@ describe.skipIf(!API_KEY)("Compaction hooks", () => {
|
||||
commands: new Map(),
|
||||
setSendMessageHandler: () => {},
|
||||
setAppendEntryHandler: () => {},
|
||||
setNewSessionHandler: () => {},
|
||||
setBranchHandler: () => {},
|
||||
setNavigateTreeHandler: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -269,9 +266,6 @@ describe.skipIf(!API_KEY)("Compaction hooks", () => {
|
||||
commands: new Map(),
|
||||
setSendMessageHandler: () => {},
|
||||
setAppendEntryHandler: () => {},
|
||||
setNewSessionHandler: () => {},
|
||||
setBranchHandler: () => {},
|
||||
setNavigateTreeHandler: () => {},
|
||||
};
|
||||
|
||||
createSession([throwingHook]);
|
||||
@@ -319,9 +313,6 @@ describe.skipIf(!API_KEY)("Compaction hooks", () => {
|
||||
commands: new Map(),
|
||||
setSendMessageHandler: () => {},
|
||||
setAppendEntryHandler: () => {},
|
||||
setNewSessionHandler: () => {},
|
||||
setBranchHandler: () => {},
|
||||
setNavigateTreeHandler: () => {},
|
||||
};
|
||||
|
||||
const hook2: LoadedHook = {
|
||||
@@ -351,9 +342,6 @@ describe.skipIf(!API_KEY)("Compaction hooks", () => {
|
||||
commands: new Map(),
|
||||
setSendMessageHandler: () => {},
|
||||
setAppendEntryHandler: () => {},
|
||||
setNewSessionHandler: () => {},
|
||||
setBranchHandler: () => {},
|
||||
setNavigateTreeHandler: () => {},
|
||||
};
|
||||
|
||||
createSession([hook1, hook2]);
|
||||
|
||||
Reference in New Issue
Block a user