refactor(core,daemon): extract StartSignal as independent Role parameter #102
Reference in New Issue
Block a user
Delete Branch "refactor/100-extract-start-signal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Extract StartSignal as a separate first parameter for Role and Moderator functions, instead of embedding it in messages[0].
Why
Roles had to cast
messages[0].metato access thread config (maxRounds, etc.) — no type safety. This refactor gives roles typedStartSignalaccess and separates config from conversation history, like LLM system prompt vs chat messages.Changes
Role<Meta>takes(start: StartSignal, messages: WorkflowMessage[]); messages no longer contains start frameModeratorContext<M>discriminated union (kind: start | step) replaces rawStartSignal | RoleSignalunionModeratorContextinitThreadMessages/executeRole/runThreadTests
All 151 daemon tests + full monorepo check/build pass.
Ref
Fixes #100
✅ LGTM — Approved
干净利落的类型安全重构。
Highlights
Role<Meta>签名改为(start, messages)— 消除了messages[0].meta as StartSignal['meta']的 type assertion,角色函数拿到的就是类型正确的 StartSignalModeratorContext<M>判别联合 —kind: 'start' | 'step'比原来的StartSignal | RoleSignal<M>联合更清晰,moderator 实现不需要自己判断信号类型isStartMeta类型守卫 — 替代了 rawascast,防御性更好ThreadMessagesState— start 和 role messages 分离,数据流一目了然细节确认
startSignalFromWorkflowMessage对非 START 消息有合理 fallback ✓没有问题,直接合。
Reviewed by 小墨 🖊️