feat(compaction): add delegated agent sessions section with resume directive
Adds §8 to compaction prompt instructing the LLM to preserve spawned agent session IDs and resume them post-compaction instead of starting fresh. Injects actual TaskHistory data when BackgroundManager is available.
This commit is contained in:
@@ -15,6 +15,7 @@ mock.module("../../shared/system-directive", () => ({
|
||||
}))
|
||||
|
||||
import { createCompactionContextInjector } from "./index"
|
||||
import { TaskHistory } from "../../features/background-agent/task-history"
|
||||
|
||||
describe("createCompactionContextInjector", () => {
|
||||
describe("Agent Verification State preservation", () => {
|
||||
@@ -69,4 +70,47 @@ describe("createCompactionContextInjector", () => {
|
||||
expect(prompt).toContain("Do NOT invent")
|
||||
expect(prompt).toContain("Quote constraints verbatim")
|
||||
})
|
||||
|
||||
describe("Delegated Agent Sessions", () => {
|
||||
it("includes delegated sessions section in compaction prompt", async () => {
|
||||
//#given
|
||||
const injector = createCompactionContextInjector()
|
||||
|
||||
//#when
|
||||
const prompt = injector()
|
||||
|
||||
//#then
|
||||
expect(prompt).toContain("Delegated Agent Sessions")
|
||||
expect(prompt).toContain("RESUME, DON'T RESTART")
|
||||
expect(prompt).toContain("session_id")
|
||||
})
|
||||
|
||||
it("injects actual task history when backgroundManager and sessionID provided", async () => {
|
||||
//#given
|
||||
const mockManager = { taskHistory: new TaskHistory() } as any
|
||||
mockManager.taskHistory.record("ses_parent", { id: "t1", sessionID: "ses_child", agent: "explore", description: "Find patterns", status: "completed", category: "quick" })
|
||||
const injector = createCompactionContextInjector(mockManager)
|
||||
|
||||
//#when
|
||||
const prompt = injector("ses_parent")
|
||||
|
||||
//#then
|
||||
expect(prompt).toContain("Active/Recent Delegated Sessions")
|
||||
expect(prompt).toContain("**explore**")
|
||||
expect(prompt).toContain("[quick]")
|
||||
expect(prompt).toContain("`ses_child`")
|
||||
})
|
||||
|
||||
it("does not inject task history section when no entries exist", async () => {
|
||||
//#given
|
||||
const mockManager = { taskHistory: new TaskHistory() } as any
|
||||
const injector = createCompactionContextInjector(mockManager)
|
||||
|
||||
//#when
|
||||
const prompt = injector("ses_empty")
|
||||
|
||||
//#then
|
||||
expect(prompt).not.toContain("Active/Recent Delegated Sessions")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user