feat: builtin agent session resume via deterministic message reconstruction (#426)

- StepRecord adds edgePrompt field (backward compat: defaults to "")
- StepNode CAS schema includes edgePrompt
- writeStepNode persists ctx.edgePrompt
- buildHistory exposes edgePrompt in StepContext
- buildBuiltinMessages reconstructs multi-turn moderator↔agent conversation:
  system = role prompt + output format (stable prefix)
  per prior visit: user (edgePrompt + inter-step summary) + assistant (output)
  current: user (edgePrompt + recent summary)
- Zero extra persistence — pure function of CAS chain
- Stable prefix for LLM prompt cache hits
- 10 builtin tests pass, all other package tests pass
This commit is contained in:
2026-05-23 17:34:49 +08:00
parent 9f95956e19
commit 080792a6c0
12 changed files with 305 additions and 52 deletions
@@ -41,7 +41,15 @@ describe("buildClaudeCodePrompt", () => {
test("includes previous steps as history summary", () => {
const ctx = makeCtx({
steps: [{ role: "planner", output: '{"plan":"do X"}', agent: "hermes" }],
steps: [
{
role: "planner",
output: '{"plan":"do X"}',
agent: "hermes",
detail: "detail-1",
edgePrompt: "Create a plan.",
},
],
});
const result = buildClaudeCodePrompt(ctx);
expect(result).toContain("## Previous Steps");