feat: Phase 3 — agent observability for Merkle call stack

- StartStep gains parentState: string | null (from StartNodePayload)
- buildAgentPrompt injects Parent Context section when parentState is set
- CLI thread show outputs parentState (top-level) and childThread (per step)
- 2 new prompt tests + thread show assertion updates

Refs #197, #194

小橘 🍊(NEKO Team)
This commit is contained in:
2026-05-12 02:23:15 +00:00
parent 4a31cf9d63
commit 98122b446d
11 changed files with 88 additions and 3 deletions
@@ -3,12 +3,13 @@ import { type AgentContext, START } from "@uncaged/workflow-runtime";
import { buildAgentPrompt } from "../src/index.js";
function startTask(content: string): AgentContext["start"] {
function startTask(content: string, parentState: string | null = null): AgentContext["start"] {
return {
role: START,
content,
meta: {},
timestamp: 1,
parentState,
};
}
@@ -95,6 +96,35 @@ describe("buildAgentPrompt", () => {
expect(text).toContain("uncaged-workflow thread 01TEST000000000000000000TR");
});
test("parentState null omits Parent Context section", async () => {
const ctx: AgentContext = {
start: startTask("top-level task"),
depth: 0,
bundleHash: "TESTHASH00001",
steps: [],
threadId: "01TEST000000000000000000TR",
currentRole: { name: START, systemPrompt: "You are an agent." },
};
const text = await buildAgentPrompt(ctx);
expect(text).not.toContain("## Parent Context");
});
test("parentState non-null includes Parent Context section with hash", async () => {
const parentHash = "01PARENTSTATE0000000000001";
const ctx: AgentContext = {
start: startTask("child task", parentHash),
depth: 1,
bundleHash: "TESTHASH00001",
steps: [],
threadId: "01TEST000000000000000000TR",
currentRole: { name: START, systemPrompt: "You are an agent." },
};
const text = await buildAgentPrompt(ctx);
expect(text).toContain("## Parent Context");
expect(text).toContain(parentHash);
expect(text).toContain(`uncaged-workflow cas get ${parentHash}`);
});
test("middle steps show meta summary only and latest shows hash", async () => {
const ha = "01HASHA00000000000000000001";
const hb = "01HASHB00000000000000000001";