fix(context-injector): add mainSessionID fallback for synthetic part injection
The transform hook was failing to inject synthetic parts because message.info.sessionID is not always available in the OpenCode SDK. Fix: Use getMainSessionID() as fallback when message.info.sessionID is undefined. This ensures keyword-detector and claude-code-hooks content (like ulw/ultrawork) is properly injected even when the SDK doesn't provide sessionID in message.info.
This commit is contained in:
parent
e22960d862
commit
fd6a33b88f
@ -1,6 +1,7 @@
|
||||
import type { ContextCollector } from "./collector"
|
||||
import type { Message, Part } from "@opencode-ai/sdk"
|
||||
import { log } from "../../shared"
|
||||
import { getMainSessionID } from "../claude-code-session-state"
|
||||
|
||||
interface OutputPart {
|
||||
type: string
|
||||
@ -105,14 +106,17 @@ export function createContextInjectorMessagesTransformHook(
|
||||
}
|
||||
|
||||
const lastUserMessage = messages[lastUserMessageIndex]
|
||||
const sessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
||||
log("[DEBUG] Extracted sessionID from lastUserMessage.info", {
|
||||
// Try message.info.sessionID first, fallback to mainSessionID
|
||||
const messageSessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
||||
const sessionID = messageSessionID ?? getMainSessionID()
|
||||
log("[DEBUG] Extracted sessionID", {
|
||||
messageSessionID,
|
||||
mainSessionID: getMainSessionID(),
|
||||
sessionID,
|
||||
infoKeys: Object.keys(lastUserMessage.info),
|
||||
lastUserMessageInfo: JSON.stringify(lastUserMessage.info).slice(0, 200),
|
||||
})
|
||||
if (!sessionID) {
|
||||
log("[DEBUG] sessionID is undefined or empty")
|
||||
log("[DEBUG] sessionID is undefined (both message.info and mainSessionID are empty)")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user