fix(keyword-detector): use session state for agent-specific ultrawork templates

Bug: When switching from Prometheus to Sisyphus, the Prometheus ultrawork
template was still injected because:
1. setSessionAgent() only sets on first call, ignoring subsequent updates
2. keyword-detector relied solely on input.agent which could be stale

Fix:
- Use updateSessionAgent() instead of setSessionAgent() in index.ts
- keyword-detector now uses getSessionAgent() as primary source, fallback to input.agent
- Added tests for agent switch scenario
This commit is contained in:
justsisyphus
2026-01-16 19:06:00 +09:00
parent 7cd59e9c0a
commit 5ee8996a39
3 changed files with 201 additions and 5 deletions
+3 -2
View File
@@ -2,7 +2,7 @@ import type { PluginInput } from "@opencode-ai/plugin"
import { detectKeywordsWithType, extractPromptText, removeCodeBlocks } from "./detector"
import { log } from "../../shared"
import { isSystemDirective } from "../../shared/system-directive"
import { getMainSessionID } from "../../features/claude-code-session-state"
import { getMainSessionID, getSessionAgent } from "../../features/claude-code-session-state"
import type { ContextCollector } from "../../features/context-injector"
export * from "./detector"
@@ -30,7 +30,8 @@ export function createKeywordDetectorHook(ctx: PluginInput, collector?: ContextC
return
}
let detectedKeywords = detectKeywordsWithType(removeCodeBlocks(promptText), input.agent)
const currentAgent = getSessionAgent(input.sessionID) ?? input.agent
let detectedKeywords = detectKeywordsWithType(removeCodeBlocks(promptText), currentAgent)
if (detectedKeywords.length === 0) {
return