refactor(cli): reduce cognitive complexity in thread.ts #452
Reference in New Issue
Block a user
Delete Branch "fix/446-reduce-thread-complexity"
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
Refactor
packages/cli-workflow/src/commands/thread.tsto reduce cognitive complexity by extracting helper functions.Why
The
cmdThreadfunction had high cognitive complexity due to deeply nested conditionals and inline logic for multiple sub-commands. This made the code hard to read and maintain.Changes
resolveThreadId— resolves thread ID from arg or active threadgetThreadHead— fetches and validates thread head CAS nodelistThreadSteps— renders the steps list sub-commanddisplayStepDetails— renders step-details sub-commanddisplayThreadRead— renders thread read sub-commandthread.test.tsworkflow-agent-claude-code/src/claude-code.ts(literal key style)Ref
Fixes #446
LGTM ✅ 提取的函数命名清晰,行为基本保持一致。测试新增覆盖不错。
⚠️ Minor
expandArrayField丢了schema.type === "array"检查 — 原来是三重判断type === "array" && schema.items && Array.isArray(value),重构后只检查后两个。边界情况下可能行为变更。claude-code.tsCLAUDE_MODEL 功能 — 这是 feature 不是 refactor,理想情况应拆分到单独 PR。都不阻塞合入。