refactor(edge): adapters SDK 适配器归组子包(#1760 首个增量) - #1770
Conversation
#1760 首个有界增量:把内聚的直连 HTTP SDK 适配器从 internal/adapters 根包(81 个平铺 .go 文件)归组到新子包 internal/adapters/sdk, 根包降至 69 个文件,降低认知负载。 迁移内容(12 个文件 + 延迟基准测试拆分): - anthropic_sdk{,_request,_sse,_types,_e2e_test}.go - openai_sdk{,_request,_sse,_types,_e2e_test}.go - sdk_common{,_test}.go(BuildCommand 哨兵命令助手) - adapter_latency_test.go 的 SDK 基准/测试随迁至 sdk 包; ClassifyComplexity 基准留在根包 - 新增 doc.go / aliases.go(合同类型与 BusEvent* 常量派生自 internal/orchestration,模式对齐既有叶子包 adapters/orchestrator) 为何无环(go list -deps 机器验证): - sdk → adapters 为单向依赖(ResolveModel / CtxRunContext / NewNonRecoverableParseError / SDKAdapterContext 仍留在根包); - 根包不再引用任何 SDK 符号:registry.go 只含字符串适配器 ID "anthropic-sdk"/"openai-sdk",构造函数调用点只在组合根 cmd/agenthub-edge(已改为 import sdk)。 暂不归组:sdk_fixture_mapper*.go 与根包存在双向耦合 (mapper 使用根包 BusEvent* 常量;根包 agentspec_fixture.go 构造 SDKFixture* 类型并调用其它适配器构造函数),强行下沉会形成 import cycle,留待后续增量解耦。 纯重组、无行为变化:go build ./... / go vet ./... / go test ./internal/adapters/... -short 全绿; scripts/verify/verify-orchestrator-deps.py 3/3 通过; cmd/agenthub-edge 与 internal/lifecycle 测试亦通过。 Co-authored-by: Cursor <cursor@vectorcontrol.tech>
|
Warning Review limit reached
Next review available in: 24 minutes Limit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (17)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
#1760 的首个有界增量:把
edge-server/internal/adapters(原 81 个平铺.go文件)中内聚的直连 HTTP SDK 适配器归组到新子包internal/adapters/sdk/,根包降至 69 个文件(-12),降低认知负载。纯重组,无行为变化。迁移了什么(12 个文件 →
adapters/sdk,另拆分 1 个测试文件)anthropic_sdk{,_request,_sse,_types,_e2e_test}.go(5)openai_sdk{,_request,_sse,_types,_e2e_test}.go(5)sdk_common{,_test}.go(BuildCommand 哨兵命令助手,2)adapter_latency_test.go的 SDK 延迟基准/测试随适配器迁入sdk/adapter_latency_test.go;BenchmarkClassifyComplexity(router 相关)留在根包sdk/doc.go、sdk/aliases.go(合同类型与用到的 BusEvent* 常量派生自internal/orchestration,模式对齐既有叶子包adapters/orchestrator)cmd/agenthub-edge/adapter_registry.go改为import .../adapters/sdk(sdk.NewAnthropicSDKAdapter/sdk.NewOpenAISDKAdapter/sdk.AnthropicHTTPTimeout/sdk.OpenAIHTTPTimeout)为什么无环(先分析后动手,
go list -deps机器验证)sdk → adapters(ResolveModel、ResolveReasoningEffort、CtxRunContext、NewNonRecoverableParseError、SDKAdapterContext仍留在根包)+sdk → orchestration(合同 SSOT);go list -deps ./internal/adapters确认根包不含adapters/sdk。registry.go只含字符串适配器 ID("anthropic-sdk"/"openai-sdk"),构造函数调用点只在组合根;原根包内唯一引用 SDK 符号的adapter_latency_test.go(内部测试,使用未导出的buildMessages)已随迁,避免测试图成环。adapters.*引用 SDK 符号。剩余耦合(本增量刻意不碰)
sdk_fixture_mapper*.go(5 个文件)暂不归组:与根包双向耦合——mapper 使用根包BusEvent*常量,而根包生产代码agentspec_fixture.go构造SDKFixture*类型并调用NewClaudeCodeAdapter/NewCodexACPadapter/NewOpenCodeACPAdapter等其他适配器构造函数;整体下沉会形成 import cycle。后续增量可先把 AgentSpec 编译器与 fixture mapper 一起解耦再归组。Verification(全部通过)
go build ./...✅go vet ./...✅go test ./internal/adapters/... -short✅(adapters、adapters/orchestrator、adapters/sdk均 ok)go test ./cmd/... ./internal/lifecycle/... -short✅;scripts/verify/verify-orchestrator-deps.py3/3 PASS(依赖方向门禁不受影响);gofmt -l干净Test plan
go build ./.../go vet ./.../go test ./internal/adapters/... -short全绿go list -deps确认adapters ↛ adapters/sdk(单向无环)