chore: 仓库瘦身 + runtime.ts 解耦#2
Merged
Merged
Conversation
将 SwarmChatApp 中对 evals/local-evals.ts (16.9k 行) 的静态 import 改为 /evals 命令处理块内的动态 import,默认 TUI 启动不再拉入该模块。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
.brainstorming/ 与 .workflow/ 下的 .csv-wave、scratch 为流程草稿, 非产品代码。git rm --cached 取消跟踪 (本地保留),并将 .brainstorming/ 加入 .gitignore。已确认无源码/测试从磁盘读取这些路径。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
agent-actor-runtime 的 AgentActorRuntime 类、deterministicActorRunner、 执行循环以及 mailbox-delivery-pump 在产品代码中构造后从不被调用 (.agentActorRuntime/.mailboxDeliveryPump/.pumpActor 均无产品调用点)。 - 将仍在用的 emitLegacyDirectInvokeAdapterTelemetry (runtime.ts:2833) 抽到独立模块 legacy-direct-invoke-telemetry.ts - 删除 agent-actor-runtime.ts、mailbox-delivery-pump.ts 及其测试 - work-session-lifecycle.test.ts 改为直接用 agentActorStore 播种 actor 记录 - runtime.ts 移除两处构造与属性声明 净删约 640 行实现 + 约 600 行测试,tsc 与受影响测试全绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
runLocalEvals 内 769 条 checkFile/checkContains/checkNotContains 结构断言 (把'某源码文件必须含某字符串'钉死) 是大文件无法拆分的根因。 - 新增 src/evals/structure-contract.ts: 声明式 STRUCTURE_CONTRACT 表 (sf/sc/snc),所有 file<->substring 耦合集中一处 - runLocalEvals 改为 ...runStructureContract(root) 展开 - 实参字面量逐字保留,golden 输出 954 项逐条比对完全一致,行为零变化 效果: 重命名/拆分源文件时只需改一处表项,而非散落数百调用点。 release:gate 与 local-evals.test.ts 均通过。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
resolveGatewayUrl(x9)/gatewayErrorMessage(x7)/recordValue(x7)/ stringValue(x7)/delay(x4) 在 approvals/handoffs/runs/sessions/workers/ watch 各文件中逐字重复。已验证各副本字节级一致后抽到 src/server/gateway-client-utils.ts 共享。 truncateText(2 个变体)与 normalizeLimit(report 格式化局部)保持不变。 净减约 183 行,tsc 与受影响测试全绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
commit af84ff0 把 .workflow/ 整体 gitignore 时丢失了 work-kernel-docs-coverage-matrix.md,导致 docs-contract.test.ts 长期 ENOENT 失败(README/PRD/WORK_KERNEL 都指向该不存在文件)。 - docs-contract.test.ts 移除依赖该矩阵的断言(3 个),保留与矩阵无关的 文档边界/诚实性断言(checkpoint 边界、claim 边界、Swarm v2 证据声明、 TUI spec、RFC 边界) - README/PRD/WORK_KERNEL 将'权威源'从丢失的矩阵文件改指向实际的离线 release gate (npm run release:gate) - sessions/report.test.ts 中作为示例 fixture 的路径字符串保持不变 全量 npm test 现在全绿(此前唯一红的文件)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
把 8 个纯叶子 helper(sanitizeKey/delay/isRecord/uniqueStrings/ formatWorkspaceChangeForFreshness/parseJsonObject/firstLine/positiveLimit) 从 runtime.ts 抽到 common-utilities.ts。这些是多个待抽模块的共享依赖, 先落地可避免后续模块产生循环引用。 tsc 绿 + golden eval 954 项完全一致 + runtime 测试通过。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
12 个 RunOptions/执行状态纯校验函数移入 run-options.ts; structure-contract 中 hasRunSandboxPolicy 条目同步改指向新文件。 tsc 绿 + golden 954 项一致 + runtime 测试通过。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
createLocalPolicy / riskClassForActionName / mcpMaterialPolicy 移入 policy-configuration.ts。tsc 绿 + golden 952 项稳定检查完全一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
10 个 agent-task/prompt 构造纯函数移入 agent-task-construction.ts。 structure-contract 中 renderActivatedSkillsForPrompt 改指向新文件; 行为检查 checkAgentContinuationFreshnessBehavior 同步读取新文件 (其断言的 needle 随函数迁移)。 修复 mover 脚本以正确处理对象字面量返回类型函数。 tsc 绿 + golden 952 项稳定检查完全一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7 个 agent spawn 决策/worker 身份规范化纯函数移入 worker-identity.ts (isAgentInvocationMode 从 run-options 导入,makeWorkerIdentity 从 worker-state-store 导入)。structure-contract 中 stripEphemeralAgentPersona 改指向新文件。 注: eval 套件中 42 个 'CLI ' 子进程检查被确认为 flaky(spawnSync, 非确定性),已从 golden 对比中排除;纯函数迁移不影响其行为。 tsc 绿 + golden 910 项确定性检查完全一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
10 个 tool 输出报告/摘要纯函数移入 tool-result-report.ts (isRecord 从 common-utilities 导入)。tsc 绿 + golden 910 项一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- worker-display.ts: compactWorkerRecord/renderWorkerList/renderWorkerDetailForTool - blackboard-live-control.ts: blackboardEntryMatches/filterBlackboardSearch/ normalizeLiveControlRequestId/isLiveControlDirectiveEntry/formatLiveControlDirective 共享叶子(isRecord/firstLine)统一从 common-utilities 导入。 tsc 绿 + golden 910 项一致。runtime.ts 降至 4954 行。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
首个类方法组抽取(workflow 评分 82/100,唯一零阻塞组):5 个 blackboard envelope/store 私有方法(writeBlackboardEvidence + write/read/ search/list ViaEnvelope)移入 blackboard-envelope-operator.ts,以 BlackboardOperatorDeps 结构化 deps 句柄(SwarmRuntime 的 4 个公开 readonly 字段天然满足)接收 this。 类保留同名私有 delegation shim,公开/私有方法签名零变化,无可见性放宽。 tsc 绿 + golden 910 项一致 + 行为零变化(纯委托,deterministic envelope)。 其余 5 个方法组经分析阻塞成本高,建议 region 组织而非抽取。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
handleRuntimeChildTransportMessage/isChildRuntimeEnvelope/
isChildProviderUsageMessage 移入 child-transport.ts(类型 RuntimeChild
TransportMessageInput/Result 仍在 runtime.ts,type-only 回引避免运行时循环)。
runtime.ts re-export handleRuntimeChildTransportMessage 供测试沿用。
local-evals 中 3 个 envelope.type needle 改读 child-transport.ts。
修复 mover 处理 TS 类型谓词 (value is {...}) 返回类型。
tsc 绿 + golden 910 项一致 + distributed-transport 测试通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ation 7 个 review 裁决/verification 规范化函数移入 review-verification.ts (isRecord 从 common-utilities,tool 报告 helper 从 tool-result-report 导入)。 postChangeExecutionStatus 经 runtime.ts re-export 保持外部消费者(evals + work-session-lifecycle.test.ts)沿用。 mover 改用黑名单法定位函数体起始,正确处理字符串字面量联合返回类型。 tsc 绿 + golden 910 项一致。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
对 Swarm 仓库做的一轮分级瘦身 + 解耦。证据驱动(多 agent 诊断 + 对抗式验证),每一步以
tsc/ golden eval 比对 / 完整npm test/release:gate把关。净效果约 −4,200 行真实代码(另移出约 3,900 行 scratch 产物),并把runtime.ts这个 5,708 行的 god-file 拆到 4,622 行。改动分层
Tier 1 — 干净切除
evals/local-evals.ts(16.9k 行),默认启动不再拉入。AgentActorRuntime/MailboxDeliveryPump(构造后从不调用),抽出仍在用的 telemetry。.brainstorming/.workflowscratch 产物(51 文件)并补 gitignore。Tier 0 — eval 解冻(关键解锁)
runLocalEvals内 769 条checkFile/checkContains/checkNotContains结构断言抽进声明式structure-contract.ts数据表。此前这些断言把源码文件布局钉死,是大文件无法拆分的根因;解冻后重命名/拆分源文件只需改一处表项。argument 字面量逐字保留,golden 输出 954 项逐条一致。Tier 2 — 重复整合
resolveGatewayUrl×9 等)合并到server/gateway-client-utils.ts,净减约 183 行。诚实性修复
docs-contract.test.ts长期 ENOENT 失败:根因是 commitaf84ff0把.workflow/整体 gitignore 时丢失了被 README/PRD/WORK_KERNEL 引用的覆盖率矩阵文件。按「移除矩阵依赖」处理——清理失效断言、把文档「权威源」改指向真实的npm run release:gate,完整测试套件转绿。Tier 3 — 拆分
runtime.ts(god-file)blackboard-envelope-operator,collaborator 模式,零可见性放宽)。runtime.ts5708 → 4622 行(−19%),新增 11 个内聚兄弟模块。SwarmRuntime~4,500 行)经耦合分析确认是合理的不可再分边界:其余 5 个方法组每个都需放宽 1–3 个私有成员(= API 倒退),不做。验证
tsc -p tsconfig.json --noEmit:绿npm test:绿npm run release:gate:pass已知(非本 PR 引入)
/evals套件有 16 个既有结构断言失败(断言代码里不存在的字符串),gate 因只跑子集未拦截——代码与断言漂移,可后续清理。CLI子进程检查 + router lease 过期测试在并行负载下 flaky(隔离/重跑确认非回归)。🤖 Generated with Claude Code