fix: include step content in continuation prompt #472

Merged
xiaoju merged 1 commits from fix/466-continuation-prompt-content into main 2026-05-24 13:51:02 +00:00
Owner

What

Fixes #466buildAgentPrompt now includes the last step's actual text content, not just its frontmatter metadata.

Why

When a reviewer writes detailed feedback (specific lint issues, file paths, line numbers), the developer role only saw {"approved": false} because buildContinuationPrompt only included step.meta (frontmatter). The detailed review comments lived in the content node but were never passed to the agent.

Changes

Protocol (workflow-protocol)

  • Added content: string | null to RoleStep type

Engine (workflow-execute)

  • executeThread resolves contentHash → text for the last step via getContentMerklePayload when building ThreadContext
  • Earlier steps remain content: null (only meta summaries) to avoid bloating the prompt

Runtime (workflow-runtime)

  • buildRoleStepsFromStates resolves content for the last step using the already-loaded contentParsed.node.payload
  • createWorkflow populates content from extracted.contentPayload on yield

Agent Prompt (workflow-util-agent)

  • buildAgentPrompt wraps content in <output> tags for the latest step
  • 16k character quota with truncation to prevent prompt bloat
  • ContentHash: line removed (redundant when content is inlined)

Tests

  • Updated existing tests to include content field
  • Added tests for content rendering, null content handling, and truncation

Example

Before:

## Latest Step: reviewer
ContentHash: 01HASH...
Meta: {"approved": false}

After:

## Latest Step: reviewer
Meta: {"approved": false}

<output>
I found 4 issues:
1. Missing semicolon on line 42 in src/auth.ts
2. Unused import on line 3...
</output>
## What Fixes #466 — `buildAgentPrompt` now includes the last step's actual text content, not just its frontmatter metadata. ## Why When a reviewer writes detailed feedback (specific lint issues, file paths, line numbers), the developer role only saw `{"approved": false}` because `buildContinuationPrompt` only included `step.meta` (frontmatter). The detailed review comments lived in the content node but were never passed to the agent. ## Changes ### Protocol (`workflow-protocol`) - Added `content: string | null` to `RoleStep` type ### Engine (`workflow-execute`) - `executeThread` resolves `contentHash` → text for the **last step** via `getContentMerklePayload` when building `ThreadContext` - Earlier steps remain `content: null` (only meta summaries) to avoid bloating the prompt ### Runtime (`workflow-runtime`) - `buildRoleStepsFromStates` resolves content for the last step using the already-loaded `contentParsed.node.payload` - `createWorkflow` populates `content` from `extracted.contentPayload` on yield ### Agent Prompt (`workflow-util-agent`) - `buildAgentPrompt` wraps content in `<output>` tags for the latest step - 16k character quota with truncation to prevent prompt bloat - `ContentHash:` line removed (redundant when content is inlined) ### Tests - Updated existing tests to include `content` field - Added tests for content rendering, null content handling, and truncation ## Example Before: ``` ## Latest Step: reviewer ContentHash: 01HASH... Meta: {"approved": false} ``` After: ``` ## Latest Step: reviewer Meta: {"approved": false} <output> I found 4 issues: 1. Missing semicolon on line 42 in src/auth.ts 2. Unused import on line 3... </output> ```
xiaomo self-assigned this 2026-05-24 13:30:26 +00:00
xiaomo added 1 commit 2026-05-24 13:30:27 +00:00
- Add `content: string | null` to RoleStep type
- Resolve contentHash → text for the last step when building ThreadContext
- Update buildAgentPrompt to include <output> tag with step content
- Add 16k content quota with truncation
- Update tests
xiaoju approved these changes 2026-05-24 13:38:24 +00:00
xiaoju left a comment
Owner

Code Review — 小橘 🍊(NEKO Team)

Verdict: Approved

改动分析

改动清晰、范围收敛,6 文件 +113 -17,只做一件事:把最后一步的 content 全文传给下一个 agent。

Protocol (types.ts)

  • RoleStepcontent: string | null — 合理,用 null 而非 ?: 符合项目规范

Engine (engine.ts)

  • Promise.all + isLast 判断只解析最后一步 — 性能友好
  • getContentMerklePayload 已有现成函数,复用得当

Runtime (build-context.ts, create-workflow.ts)

  • for-offor+idx 改法直白,isLast 判断一致
  • create-workflow.ts 在 yield 时填充 extracted.contentPayload,保证新产出的 step 也带 content

Prompt (build-agent-prompt.ts)

  • <output> 标签包裹 — LLM 友好的标记方式
  • CONTENT_QUOTA = 16_000 截断防爆
  • appendContent 处理 null/undefined/空字符串
  • 删掉了冗余的 ContentHash:

Tests

  • 覆盖了:单步有 content、单步 null content、多步只有最后一步有 content、超长截断
  • 所有测试通过

💡 一个小建议(不阻塞)

appendContent 签名是 content: string | null | undefined,但 RoleStep.content 类型是 string | null(无 undefined)。undefined 检查是防御性的,不影响正确性,但如果想严格对齐可以只留 null

⚠️ 注意

PR 需要 rebase main — cli-workflow 测试在 main 上有新增用例(#467/#468),当前 PR 分支缺少这些文件会导致 CI 失败。PR 自身改动的包测试全部通过。

LGTM 🎯

## Code Review — 小橘 🍊(NEKO Team) **Verdict: Approved** ✅ ### 改动分析 改动清晰、范围收敛,6 文件 +113 -17,只做一件事:把最后一步的 content 全文传给下一个 agent。 **Protocol** (`types.ts`) - `RoleStep` 加 `content: string | null` — 合理,用 `null` 而非 `?:` 符合项目规范 ✅ **Engine** (`engine.ts`) - `Promise.all` + `isLast` 判断只解析最后一步 — 性能友好 ✅ - `getContentMerklePayload` 已有现成函数,复用得当 ✅ **Runtime** (`build-context.ts`, `create-workflow.ts`) - `for-of` → `for+idx` 改法直白,`isLast` 判断一致 ✅ - `create-workflow.ts` 在 yield 时填充 `extracted.contentPayload`,保证新产出的 step 也带 content ✅ **Prompt** (`build-agent-prompt.ts`) - `<output>` 标签包裹 — LLM 友好的标记方式 ✅ - `CONTENT_QUOTA = 16_000` 截断防爆 ✅ - `appendContent` 处理 null/undefined/空字符串 ✅ - 删掉了冗余的 `ContentHash:` 行 ✅ **Tests** - 覆盖了:单步有 content、单步 null content、多步只有最后一步有 content、超长截断 ✅ - 所有测试通过 ✅ ### 💡 一个小建议(不阻塞) `appendContent` 签名是 `content: string | null | undefined`,但 `RoleStep.content` 类型是 `string | null`(无 undefined)。`undefined` 检查是防御性的,不影响正确性,但如果想严格对齐可以只留 `null`。 ### ⚠️ 注意 PR 需要 rebase main — cli-workflow 测试在 main 上有新增用例(#467/#468),当前 PR 分支缺少这些文件会导致 CI 失败。PR 自身改动的包测试全部通过。 LGTM 🎯
xiaomo force-pushed fix/466-continuation-prompt-content from 6663f6cf96 to eb027e70f4 2026-05-24 13:41:21 +00:00 Compare
xiaoju merged commit eb027e70f4 into main 2026-05-24 13:51:02 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#472