fix(todo-continuation): preserve model when injecting continuation prompt
This commit is contained in:
parent
1dd369fda5
commit
4c22d6de76
@ -807,4 +807,26 @@ describe("todo-continuation-enforcer", () => {
|
|||||||
// #then - no continuation (API fallback detected the abort)
|
// #then - no continuation (API fallback detected the abort)
|
||||||
expect(promptCalls).toHaveLength(0)
|
expect(promptCalls).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should pass model property in prompt call (undefined when no message context)", async () => {
|
||||||
|
// #given - session with incomplete todos, no prior message context available
|
||||||
|
const sessionID = "main-model-preserve"
|
||||||
|
setMainSession(sessionID)
|
||||||
|
|
||||||
|
const hook = createTodoContinuationEnforcer(createMockPluginInput(), {
|
||||||
|
backgroundManager: createMockBackgroundManager(false),
|
||||||
|
})
|
||||||
|
|
||||||
|
// #when - session goes idle and continuation is injected
|
||||||
|
await hook.handler({
|
||||||
|
event: { type: "session.idle", properties: { sessionID } },
|
||||||
|
})
|
||||||
|
|
||||||
|
await new Promise(r => setTimeout(r, 2500))
|
||||||
|
|
||||||
|
// #then - prompt call made, model is undefined when no context (expected behavior)
|
||||||
|
expect(promptCalls.length).toBe(1)
|
||||||
|
expect(promptCalls[0].text).toContain("TODO CONTINUATION")
|
||||||
|
expect("model" in promptCalls[0]).toBe(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -206,14 +206,18 @@ export function createTodoContinuationEnforcer(
|
|||||||
|
|
||||||
const prompt = `${CONTINUATION_PROMPT}\n\n[Status: ${todos.length - freshIncompleteCount}/${todos.length} completed, ${freshIncompleteCount} remaining]`
|
const prompt = `${CONTINUATION_PROMPT}\n\n[Status: ${todos.length - freshIncompleteCount}/${todos.length} completed, ${freshIncompleteCount} remaining]`
|
||||||
|
|
||||||
try {
|
const model = prevMessage?.model?.providerID && prevMessage?.model?.modelID
|
||||||
log(`[${HOOK_NAME}] Injecting continuation`, { sessionID, agent: prevMessage?.agent, incompleteCount: freshIncompleteCount })
|
? { providerID: prevMessage.model.providerID, modelID: prevMessage.model.modelID }
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
try {
|
||||||
|
log(`[${HOOK_NAME}] Injecting continuation`, { sessionID, agent: prevMessage?.agent, model, incompleteCount: freshIncompleteCount })
|
||||||
|
|
||||||
// Don't pass model - let OpenCode use session's existing lastModel
|
|
||||||
await ctx.client.session.prompt({
|
await ctx.client.session.prompt({
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
body: {
|
body: {
|
||||||
agent: prevMessage?.agent,
|
agent: prevMessage?.agent,
|
||||||
|
...(model !== undefined ? { model } : {}),
|
||||||
parts: [{ type: "text", text: prompt }],
|
parts: [{ type: "text", text: prompt }],
|
||||||
},
|
},
|
||||||
query: { directory: ctx.directory },
|
query: { directory: ctx.directory },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user