fix(todo-continuation-enforcer): skip continuation for compaction-only message history
This commit is contained in:
@@ -144,8 +144,11 @@ export async function handleSessionIdle(args: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let resolvedInfo: ResolvedMessageInfo | undefined
|
let resolvedInfo: ResolvedMessageInfo | undefined
|
||||||
|
let encounteredCompaction = false
|
||||||
try {
|
try {
|
||||||
resolvedInfo = await resolveLatestMessageInfo(ctx, sessionID)
|
const messageInfoResult = await resolveLatestMessageInfo(ctx, sessionID)
|
||||||
|
resolvedInfo = messageInfoResult.resolvedInfo
|
||||||
|
encounteredCompaction = messageInfoResult.encounteredCompaction
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`[${HOOK_NAME}] Failed to fetch messages for agent check`, { sessionID, error: String(error) })
|
log(`[${HOOK_NAME}] Failed to fetch messages for agent check`, { sessionID, error: String(error) })
|
||||||
}
|
}
|
||||||
@@ -164,7 +167,7 @@ export async function handleSessionIdle(args: {
|
|||||||
log(`[${HOOK_NAME}] Skipped: agent in skipAgents list`, { sessionID, agent: resolvedAgentName })
|
log(`[${HOOK_NAME}] Skipped: agent in skipAgents list`, { sessionID, agent: resolvedAgentName })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (compactionGuardActive && !resolvedInfo?.agent) {
|
if ((compactionGuardActive || encounteredCompaction) && !resolvedInfo?.agent) {
|
||||||
log(`[${HOOK_NAME}] Skipped: compaction occurred but no agent info resolved`, { sessionID })
|
log(`[${HOOK_NAME}] Skipped: compaction occurred but no agent info resolved`, { sessionID })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,30 +2,35 @@ import type { PluginInput } from "@opencode-ai/plugin"
|
|||||||
|
|
||||||
import { normalizeSDKResponse } from "../../shared"
|
import { normalizeSDKResponse } from "../../shared"
|
||||||
|
|
||||||
import type { MessageInfo, ResolvedMessageInfo } from "./types"
|
import type { MessageInfo, ResolveLatestMessageInfoResult } from "./types"
|
||||||
|
|
||||||
export async function resolveLatestMessageInfo(
|
export async function resolveLatestMessageInfo(
|
||||||
ctx: PluginInput,
|
ctx: PluginInput,
|
||||||
sessionID: string
|
sessionID: string
|
||||||
): Promise<ResolvedMessageInfo | undefined> {
|
): Promise<ResolveLatestMessageInfoResult> {
|
||||||
const messagesResp = await ctx.client.session.messages({
|
const messagesResp = await ctx.client.session.messages({
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
})
|
})
|
||||||
const messages = normalizeSDKResponse(messagesResp, [] as Array<{ info?: MessageInfo }>)
|
const messages = normalizeSDKResponse(messagesResp, [] as Array<{ info?: MessageInfo }>)
|
||||||
|
let encounteredCompaction = false
|
||||||
|
|
||||||
for (let i = messages.length - 1; i >= 0; i--) {
|
for (let i = messages.length - 1; i >= 0; i--) {
|
||||||
const info = messages[i].info
|
const info = messages[i].info
|
||||||
if (info?.agent === "compaction") {
|
if (info?.agent === "compaction") {
|
||||||
|
encounteredCompaction = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (info?.agent || info?.model || (info?.modelID && info?.providerID)) {
|
if (info?.agent || info?.model || (info?.modelID && info?.providerID)) {
|
||||||
return {
|
return {
|
||||||
agent: info.agent,
|
resolvedInfo: {
|
||||||
model: info.model ?? (info.providerID && info.modelID ? { providerID: info.providerID, modelID: info.modelID } : undefined),
|
agent: info.agent,
|
||||||
tools: info.tools,
|
model: info.model ?? (info.providerID && info.modelID ? { providerID: info.providerID, modelID: info.modelID } : undefined),
|
||||||
|
tools: info.tools,
|
||||||
|
},
|
||||||
|
encounteredCompaction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined
|
return { resolvedInfo: undefined, encounteredCompaction }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,3 +54,8 @@ export interface ResolvedMessageInfo {
|
|||||||
model?: { providerID: string; modelID: string }
|
model?: { providerID: string; modelID: string }
|
||||||
tools?: Record<string, ToolPermission>
|
tools?: Record<string, ToolPermission>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ResolveLatestMessageInfoResult {
|
||||||
|
resolvedInfo?: ResolvedMessageInfo
|
||||||
|
encounteredCompaction: boolean
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user