diff --git a/src/hooks/start-work/index.test.ts b/src/hooks/start-work/index.test.ts index 64f09e15..43908877 100644 --- a/src/hooks/start-work/index.test.ts +++ b/src/hooks/start-work/index.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, test, beforeEach, afterEach } from "bun:test" +import { describe, expect, test, beforeEach, afterEach, spyOn } from "bun:test" import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs" import { join } from "node:path" import { tmpdir, homedir } from "node:os" @@ -8,6 +8,7 @@ import { clearBoulderState, } from "../../features/boulder-state" import type { BoulderState } from "../../features/boulder-state" +import * as sessionState from "../../features/claude-code-session-state" describe("start-work hook", () => { const TEST_DIR = join(tmpdir(), "start-work-test-" + Date.now()) @@ -380,4 +381,26 @@ feature-implementation expect(output.parts[0].text).toContain("Auto-Selected Plan") }) }) + + describe("session agent management", () => { + test("should clear session agent when start-work command is triggered", async () => { + // #given - spy on clearSessionAgent + const clearSpy = spyOn(sessionState, "clearSessionAgent") + + const hook = createStartWorkHook(createMockPluginInput()) + const output = { + parts: [{ type: "text", text: "Start Sisyphus work session" }], + } + + // #when - start-work command is processed + await hook["chat.message"]( + { sessionID: "ses-prometheus-to-sisyphus" }, + output + ) + + // #then - clearSessionAgent should be called with the sessionID + expect(clearSpy).toHaveBeenCalledWith("ses-prometheus-to-sisyphus") + clearSpy.mockRestore() + }) + }) }) diff --git a/src/hooks/start-work/index.ts b/src/hooks/start-work/index.ts index 0ba3768c..9bd217d1 100644 --- a/src/hooks/start-work/index.ts +++ b/src/hooks/start-work/index.ts @@ -10,6 +10,7 @@ import { clearBoulderState, } from "../../features/boulder-state" import { log } from "../../shared/logger" +import { clearSessionAgent } from "../../features/claude-code-session-state" export const HOOK_NAME = "start-work" @@ -70,6 +71,9 @@ export function createStartWorkHook(ctx: PluginInput) { sessionID: input.sessionID, }) + // Clear previous session agent (e.g., Prometheus) to allow mode transition + clearSessionAgent(input.sessionID) + const existingState = readBoulderState(ctx.directory) const sessionId = input.sessionID const timestamp = new Date().toISOString()