feat(context): purify leading SYSTEM, route context layers as USER turns (#290)

Move intent, repo map, docs catalog, decision journal and relevant-files
context entries to EntryRole.USER so they no longer fold into the single
leading SYSTEM block — that block stays pure policy/schema. Omit L3 repo-map
retrieval on repair retries (the transcript already carries the evidence).
Add "initialIntent" to REQUIRED_SOURCE_TYPES.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 18:35:29 +04:00
parent bc050f8e8a
commit 3bf4dd7379
7 changed files with 57 additions and 13 deletions
@@ -123,6 +123,29 @@ class PromptRendererOrderingTest {
)
}
@Test
fun `USER-role context entries render as separate turns and never fold into system`() {
// #290: intent, repo map, docs catalog and decision journal carry EntryRole.USER so the
// leading system block stays pure policy/schema. They must appear as user turns, not merge in.
val pack = ContextPack(
id = ContextPackId("p"),
sessionId = sessionId,
stageId = stageId,
layers = mapOf(
ContextLayer.L0 to listOf(entry("policy", ContextLayer.L0, EntryRole.SYSTEM, "systemPrompt")),
ContextLayer.L1 to listOf(entry("intent", ContextLayer.L1, EntryRole.USER, "initialIntent")),
ContextLayer.L3 to listOf(entry("journal", ContextLayer.L3, EntryRole.USER, "decisionJournal")),
),
budgetUsed = 30,
budgetLimit = 4000,
)
val messages = PromptRenderer.render(pack)
assertEquals("policy", messages.first().content, "leading system must be policy only")
org.junit.jupiter.api.Assertions.assertEquals(1, messages.count { it.role == "system" })
org.junit.jupiter.api.Assertions.assertTrue(messages.any { it.role == "user" && it.content == "intent" })
org.junit.jupiter.api.Assertions.assertTrue(messages.any { it.role == "user" && it.content == "journal" })
}
@Test
fun `non-L0 SYSTEM entries fold into the single leading system message`() {
// Strict chat templates (Qwen) 400 on any system message after index 0. Recalled L3