Preserve agent context in preemptive compaction's continue message

When sending the 'Continue' message after compaction, now includes the
original agent parameter from the stored message. Previously, the Continue
message was sent without the agent parameter, causing OpenCode to use the
default 'build' agent instead of preserving the original agent context
(e.g., Sisyphus).

Implementation:
- Get messageDir using getMessageDir(sessionID)
- Retrieve storedMessage using findNearestMessageWithFields
- Pass agent: storedMessage?.agent to promptAsync body

🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-23 15:17:51 +09:00
parent 56deaa3a3e
commit 83c1b8d5a4

View File

@@ -184,9 +184,15 @@ export function createPreemptiveCompactionHook(
setTimeout(async () => { setTimeout(async () => {
try { try {
const messageDir = getMessageDir(sessionID)
const storedMessage = messageDir ? findNearestMessageWithFields(messageDir) : null
await ctx.client.session.promptAsync({ await ctx.client.session.promptAsync({
path: { id: sessionID }, path: { id: sessionID },
body: { parts: [{ type: "text", text: "Continue" }] }, body: {
agent: storedMessage?.agent,
parts: [{ type: "text", text: "Continue" }],
},
query: { directory: ctx.directory }, query: { directory: ctx.directory },
}) })
} catch {} } catch {}