fix(compaction): skip autocontinue for compaction agent
This commit is contained in:
@@ -160,6 +160,25 @@ describe("experimental.session.compacting handler", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("experimental.compaction.autocontinue handler", () => {
|
describe("experimental.compaction.autocontinue handler", () => {
|
||||||
|
it("disables OpenCode autocontinue when the compaction agent would continue itself", async () => {
|
||||||
|
//#given
|
||||||
|
const restoreContextMock = mock(async () => true)
|
||||||
|
const restoreTodosMock = mock(async () => {})
|
||||||
|
const handler = createCompactionAutocontinueHandler({
|
||||||
|
compactionContextInjector: { restore: restoreContextMock },
|
||||||
|
compactionTodoPreserver: { restore: restoreTodosMock },
|
||||||
|
})
|
||||||
|
const output = { enabled: true }
|
||||||
|
|
||||||
|
//#when
|
||||||
|
await handler({ sessionID: "ses_compaction_loop", agent: "compaction" }, output)
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(output.enabled).toBe(false)
|
||||||
|
expect(restoreContextMock).not.toHaveBeenCalled()
|
||||||
|
expect(restoreTodosMock).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
it("restores checkpointed context and todos before OpenCode adds the synthetic continue turn", async () => {
|
it("restores checkpointed context and todos before OpenCode adds the synthetic continue turn", async () => {
|
||||||
//#given
|
//#given
|
||||||
const callOrder: string[] = []
|
const callOrder: string[] = []
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Hooks } from "@opencode-ai/plugin"
|
import type { Hooks } from "@opencode-ai/plugin"
|
||||||
|
|
||||||
|
import { isCompactionAgent } from "../shared/compaction-marker"
|
||||||
import { log } from "../shared/logger"
|
import { log } from "../shared/logger"
|
||||||
|
|
||||||
type SessionCompactingHook = NonNullable<Hooks["experimental.session.compacting"]>
|
type SessionCompactingHook = NonNullable<Hooks["experimental.session.compacting"]>
|
||||||
@@ -92,8 +93,13 @@ export function createCompactionAutocontinueHandler(
|
|||||||
): CompactionAutocontinueHook {
|
): CompactionAutocontinueHook {
|
||||||
return async (
|
return async (
|
||||||
input: CompactionAutocontinueInput,
|
input: CompactionAutocontinueInput,
|
||||||
_output: CompactionAutocontinueOutput,
|
output: CompactionAutocontinueOutput,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
|
if (isCompactionAgent(input.agent)) {
|
||||||
|
output.enabled = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await runCompactionStep("compactionContextInjector.restore", input.sessionID, async () => {
|
await runCompactionStep("compactionContextInjector.restore", input.sessionID, async () => {
|
||||||
const restore = hooks.compactionContextInjector?.restore
|
const restore = hooks.compactionContextInjector?.restore
|
||||||
if (restore) {
|
if (restore) {
|
||||||
|
|||||||
Reference in New Issue
Block a user