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 { ContextCollector } from "./collector"
|
||||||
import type { Message, Part } from "@opencode-ai/sdk"
|
import type { Message, Part } from "@opencode-ai/sdk"
|
||||||
import { log } from "../../shared"
|
import { log } from "../../shared"
|
||||||
|
import { getMainSessionID } from "../claude-code-session-state"
|
||||||
|
|
||||||
interface OutputPart {
|
interface OutputPart {
|
||||||
type: string
|
type: string
|
||||||
@ -105,14 +106,17 @@ export function createContextInjectorMessagesTransformHook(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lastUserMessage = messages[lastUserMessageIndex]
|
const lastUserMessage = messages[lastUserMessageIndex]
|
||||||
const sessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
// Try message.info.sessionID first, fallback to mainSessionID
|
||||||
log("[DEBUG] Extracted sessionID from lastUserMessage.info", {
|
const messageSessionID = (lastUserMessage.info as unknown as { sessionID?: string }).sessionID
|
||||||
|
const sessionID = messageSessionID ?? getMainSessionID()
|
||||||
|
log("[DEBUG] Extracted sessionID", {
|
||||||
|
messageSessionID,
|
||||||
|
mainSessionID: getMainSessionID(),
|
||||||
sessionID,
|
sessionID,
|
||||||
infoKeys: Object.keys(lastUserMessage.info),
|
infoKeys: Object.keys(lastUserMessage.info),
|
||||||
lastUserMessageInfo: JSON.stringify(lastUserMessage.info).slice(0, 200),
|
|
||||||
})
|
})
|
||||||
if (!sessionID) {
|
if (!sessionID) {
|
||||||
log("[DEBUG] sessionID is undefined or empty")
|
log("[DEBUG] sessionID is undefined (both message.info and mainSessionID are empty)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user