From 75925d5433ababa8a48567cfa3fcbe095e1cca71 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Fri, 16 Jan 2026 11:30:54 +0900 Subject: [PATCH] fix: clear session agent on /start-work to allow mode transition from Prometheus When transitioning from Prometheus (Planner) to Sisyphus via /start-work, the session agent was not being cleared. This caused prometheus-md-only hook to continue injecting READ-ONLY constraints into sisyphus_task calls. - Add clearSessionAgent() call when start-work command is detected - Add TDD test verifying clearSessionAgent is called with sessionID --- src/hooks/start-work/index.test.ts | 25 ++++++++++++++++++++++++- src/hooks/start-work/index.ts | 4 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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()