Phase 4 Testing: Engine 迁移到 json-cas #299

Closed
opened 2026-05-18 02:27:47 +00:00 by xiaoju · 0 comments
Owner

验证目标

将 engine 从 workflow-cas 切换到 json-cas,thread 执行使用新 schema。

前置

工作内容

1. Engine 核心替换

修改 workflow-execute/src/engine/engine.ts:

  • 启动时:从 CAS 加载 workflow 定义(loadWorkflow),不再从 bundle import
  • Moderator 使用 evaluateModerator(rules, context) 替代 tableToModerator
  • 每个 step 写入 thread-step 节点(json-cas format)
  • 启动时写入 thread-start 节点(含 workflow hash + agents binding)
  • 结束时写入 thread-end 节点

2. Store 替换

  • CasStore 类型从 @uncaged/workflow-cas 改为 @uncaged/json-casStore
  • createCasStore(dir) 改为 createFsStore(dir) (from @uncaged/json-cas-fs)
  • 所有 put 操作使用 store.put(typeHash, payload) 替代旧的 putStartNode/putStateNode/putContentNodeWithRefs

3. Context 构建

修改 workflow-runtime/src/build-context.ts:

  • 从 json-cas 节点构建 ThreadContext
  • 遍历 thread-step 链(via previous cas_ref)重建 steps 数组
  • 从 content 节点读取 agent 输出文本

4. Worker 适配

修改 workflow-execute/src/engine/worker.ts:

  • 初始化时 bootstrap json-cas store + 注册 workflow schemas
  • 传递 type hash map 给 engine

5. 删除旧依赖

  • 从 workflow-execute、workflow-runtime 的 package.json 移除 @uncaged/workflow-cas
  • 删除所有对旧 CAS 函数的 import

测试步骤

  • Step 1: 端到端 solve-issue
    用 memory store 注册 solve-issue workflow → 创建 thread → 跑完整流程 → thread-end 存在

  • Step 2: thread-start 结构正确
    thread-start 节点包含 workflow cas_ref 和 agents binding(role → agent hash)

  • Step 3: thread-step 链完整
    每个 step 有 content ref、start ref、previous ref(链表结构)

  • Step 4: thread-end 记录正确
    returnCode + summary + start ref + lastStep ref

  • Step 5: walk 遍历完整
    walk(threadStartHash) 遍历 thread-start → 所有 steps → 所有 content 节点

  • Step 6: content 读取正确
    从 step 的 content ref 读取 agent 输出文本,内容正确

  • Step 7: fs store 持久化
    用 fs store 跑一次,重新打开 store 后 thread 数据完整可读

验证完成标准

所有 checkbox 打勾
bun test 全过(至少 engine 相关测试)
workflow-execute 和 workflow-runtime 不再 import @uncaged/workflow-cas

Ref: #294

## 验证目标 将 engine 从 workflow-cas 切换到 json-cas,thread 执行使用新 schema。 ## 前置 - Phase 3 完成(#297, PR #298) - 需要先合并 PR #298 ## 工作内容 ### 1. Engine 核心替换 修改 `workflow-execute/src/engine/engine.ts`: - 启动时:从 CAS 加载 workflow 定义(`loadWorkflow`),不再从 bundle import - Moderator 使用 `evaluateModerator(rules, context)` 替代 `tableToModerator` - 每个 step 写入 `thread-step` 节点(json-cas format) - 启动时写入 `thread-start` 节点(含 workflow hash + agents binding) - 结束时写入 `thread-end` 节点 ### 2. Store 替换 - `CasStore` 类型从 `@uncaged/workflow-cas` 改为 `@uncaged/json-cas` 的 `Store` - `createCasStore(dir)` 改为 `createFsStore(dir)` (from `@uncaged/json-cas-fs`) - 所有 put 操作使用 `store.put(typeHash, payload)` 替代旧的 `putStartNode/putStateNode/putContentNodeWithRefs` ### 3. Context 构建 修改 `workflow-runtime/src/build-context.ts`: - 从 json-cas 节点构建 ThreadContext - 遍历 thread-step 链(via `previous` cas_ref)重建 steps 数组 - 从 content 节点读取 agent 输出文本 ### 4. Worker 适配 修改 `workflow-execute/src/engine/worker.ts`: - 初始化时 bootstrap json-cas store + 注册 workflow schemas - 传递 type hash map 给 engine ### 5. 删除旧依赖 - 从 workflow-execute、workflow-runtime 的 package.json 移除 `@uncaged/workflow-cas` - 删除所有对旧 CAS 函数的 import ## 测试步骤 - [ ] **Step 1: 端到端 solve-issue** 用 memory store 注册 solve-issue workflow → 创建 thread → 跑完整流程 → thread-end 存在 - [ ] **Step 2: thread-start 结构正确** thread-start 节点包含 workflow cas_ref 和 agents binding(role → agent hash) - [ ] **Step 3: thread-step 链完整** 每个 step 有 content ref、start ref、previous ref(链表结构) - [ ] **Step 4: thread-end 记录正确** returnCode + summary + start ref + lastStep ref - [ ] **Step 5: walk 遍历完整** `walk(threadStartHash)` 遍历 thread-start → 所有 steps → 所有 content 节点 - [ ] **Step 6: content 读取正确** 从 step 的 content ref 读取 agent 输出文本,内容正确 - [ ] **Step 7: fs store 持久化** 用 fs store 跑一次,重新打开 store 后 thread 数据完整可读 ## 验证完成标准 ✅ 所有 checkbox 打勾 ✅ `bun test` 全过(至少 engine 相关测试) ✅ workflow-execute 和 workflow-runtime 不再 import @uncaged/workflow-cas Ref: #294
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#299