mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-24 09:05:50 +00:00
refactor: 拆分 3 个过大 ACP 文件为模块化子文件(每个 <500 行)
通过 4 阶段 workflow(分析 → 计划 → 重构 → 验证)将 3 个超大的 ACP 源文件拆分为 28 个模块化子文件,每个均严格小于 500 行,且完整保留 所有公共 API(barrel 模式重导出)。 变更概要: - packages/acp-link/src/server.ts: 1800 → 20 行(barrel),新增 11 个子模块 (server/types、payload-decode、permission-mode、runtime-state、dispatch、 handlers-agent、handlers-session、acp-client、client-send、start-server、 testing-internals) - src/services/acp/agent.ts: 1297 → 33 行(barrel),新增 9 个子模块 (agent/AcpAgent、sessionTypes、permissionMode、configOptions、promptQueue、 internalAccessors、createSessionMethod、sessionLifecycle、promptFlow) - src/services/acp/bridge.ts: 1516 → 29 行(barrel),新增 8 个子模块 (bridge/types、paths、contentBlocks、toolInfo、toolResults、modelUsage、 notifications、forwarding) 验证: - bun run precheck 全通过(typecheck + lint + 5851 tests) - ACP service tests: 176 pass / 0 fail - ACP link tests: 47 pass / 0 fail - 所有外部消费者(entry.ts、permissions.ts、__tests__/)的 import 路径不变 - 测试文件零修改 迁移计划详见 docs/acp-refactor-plan.md。 Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
65
packages/acp-link/src/server/testing-internals.ts
Normal file
65
packages/acp-link/src/server/testing-internals.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { ChildProcess } from 'node:child_process'
|
||||
import * as acp from '@agentclientprotocol/sdk'
|
||||
import type { WSContext } from 'hono/ws'
|
||||
import type { JsonRpc2ClientMessage } from '../ws-message.js'
|
||||
import { dispatchClientMessage, dispatchJsonRpcMessage } from './dispatch.js'
|
||||
import { clients, setDefaultPermissionMode } from './runtime-state.js'
|
||||
import { createClientState, type ProxyMessage } from './types.js'
|
||||
|
||||
export function assertTestingInternalsEnabled(): void {
|
||||
if (process.env.ACP_LINK_TEST_INTERNALS === '1') {
|
||||
return
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'acp-link test internals are disabled outside test execution.',
|
||||
)
|
||||
}
|
||||
|
||||
export const __testing = {
|
||||
dispatchClientMessage(ws: WSContext, data: unknown): Promise<void> {
|
||||
assertTestingInternalsEnabled()
|
||||
return dispatchClientMessage(ws, data as ProxyMessage)
|
||||
},
|
||||
dispatchJsonRpcMessage(ws: WSContext, data: unknown): Promise<void> {
|
||||
assertTestingInternalsEnabled()
|
||||
return dispatchJsonRpcMessage(ws, data as JsonRpc2ClientMessage)
|
||||
},
|
||||
registerClient(
|
||||
ws: WSContext,
|
||||
state: {
|
||||
connection?: unknown
|
||||
process?: ChildProcess | null
|
||||
sessionId?: string | null
|
||||
clientInfo?: { name: string; version: string }
|
||||
clientCapabilities?: Record<string, unknown>
|
||||
jsonRpc?: boolean
|
||||
},
|
||||
): () => void {
|
||||
assertTestingInternalsEnabled()
|
||||
const full = createClientState()
|
||||
full.process = state.process ?? null
|
||||
full.connection = (state.connection ??
|
||||
null) as acp.ClientSideConnection | null
|
||||
full.sessionId = state.sessionId ?? null
|
||||
if (state.clientInfo) full.clientInfo = state.clientInfo
|
||||
if (state.clientCapabilities)
|
||||
full.clientCapabilities = state.clientCapabilities
|
||||
if (typeof state.jsonRpc === 'boolean') full.jsonRpc = state.jsonRpc
|
||||
clients.set(ws, full)
|
||||
return () => {
|
||||
clients.delete(ws)
|
||||
}
|
||||
},
|
||||
getClientSessionId(ws: WSContext): string | null | undefined {
|
||||
assertTestingInternalsEnabled()
|
||||
return clients.get(ws)?.sessionId
|
||||
},
|
||||
setDefaultPermissionMode(mode: string | undefined): () => void {
|
||||
assertTestingInternalsEnabled()
|
||||
const previous = setDefaultPermissionMode(mode)
|
||||
return () => {
|
||||
setDefaultPermissionMode(previous)
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user