fix(hooks): settle idle prompt continuations
This commit is contained in:
@@ -11,6 +11,7 @@ import { getLastAgentFromSession } from "./session-last-agent"
|
||||
import { isSessionInBoulderLineage } from "./boulder-session-lineage"
|
||||
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
||||
import { log } from "../../shared/logger"
|
||||
import { settleAfterSessionIdle } from "../shared/session-idle-settle"
|
||||
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
||||
import { HOOK_NAME } from "./hook-name"
|
||||
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
||||
@@ -302,6 +303,8 @@ export async function handleAtlasSessionIdle(input: {
|
||||
return
|
||||
}
|
||||
|
||||
await settleAfterSessionIdle(options?.idleSettleMs)
|
||||
|
||||
await injectContinuation({
|
||||
ctx,
|
||||
sessionID,
|
||||
|
||||
@@ -68,6 +68,7 @@ describe("atlas hook", () => {
|
||||
): ReturnType<typeof createAtlasHook> {
|
||||
const resolvedOptions: AtlasHookOptions = {
|
||||
directory: TEST_DIR,
|
||||
idleSettleMs: 0,
|
||||
isCallerOrchestrator: async (sessionID) => callerAgentBySession.get(sessionID ?? "") === "atlas",
|
||||
...options,
|
||||
}
|
||||
@@ -1346,6 +1347,40 @@ session_id: ses_untrusted_999
|
||||
expect(callArgs.body.parts[0].text).toContain("2 remaining")
|
||||
})
|
||||
|
||||
test("should settle idle before injecting boulder continuation", async () => {
|
||||
// given
|
||||
const planPath = join(TEST_DIR, "test-plan.md")
|
||||
writeFileSync(planPath, "# Plan\n- [ ] Task 1\n- [x] Task 2")
|
||||
|
||||
const state: BoulderState = {
|
||||
active_plan: planPath,
|
||||
started_at: "2026-01-02T10:00:00Z",
|
||||
session_ids: [MAIN_SESSION_ID],
|
||||
plan_name: "test-plan",
|
||||
}
|
||||
writeBoulderState(TEST_DIR, state)
|
||||
|
||||
const mockInput = createMockPluginInput()
|
||||
const hook = createTestAtlasHook(mockInput, { idleSettleMs: 50 })
|
||||
|
||||
// when
|
||||
const startedAt = Date.now()
|
||||
const eventPromise = hook.handler({
|
||||
event: {
|
||||
type: "session.idle",
|
||||
properties: { sessionID: MAIN_SESSION_ID },
|
||||
},
|
||||
})
|
||||
await Promise.resolve()
|
||||
|
||||
// then
|
||||
expect(mockInput._promptMock).not.toHaveBeenCalled()
|
||||
|
||||
await eventPromise
|
||||
expect(Date.now() - startedAt).toBeGreaterThanOrEqual(45)
|
||||
expect(mockInput._promptMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test("should not inject when no boulder state exists", async () => {
|
||||
// given - no boulder state
|
||||
const mockInput = createMockPluginInput()
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface AtlasHookOptions {
|
||||
isContinuationStopped?: (sessionID: string) => boolean
|
||||
isCallerOrchestrator?: (sessionID: string | undefined) => Promise<boolean>
|
||||
agentOverrides?: AgentOverrides
|
||||
idleSettleMs?: number
|
||||
/** Enable auto-commit after each atomic task completion (default: true) */
|
||||
autoCommit?: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user