mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-21 15:55:50 +00:00
通过 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>
75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import type {
|
|
SessionModeState,
|
|
SessionModelState,
|
|
SessionConfigOption,
|
|
} from '@agentclientprotocol/sdk'
|
|
|
|
export function buildConfigOptions(
|
|
modes: SessionModeState,
|
|
models: SessionModelState,
|
|
): SessionConfigOption[] {
|
|
return [
|
|
{
|
|
id: 'mode',
|
|
name: 'Mode',
|
|
description: 'Session permission mode',
|
|
category: 'mode',
|
|
type: 'select' as const,
|
|
currentValue: modes.currentModeId,
|
|
options: modes.availableModes.map(
|
|
(m: SessionModeState['availableModes'][number]) => ({
|
|
value: m.id,
|
|
name: m.name,
|
|
description: m.description,
|
|
}),
|
|
),
|
|
},
|
|
{
|
|
id: 'model',
|
|
name: 'Model',
|
|
description: 'AI model to use',
|
|
category: 'model',
|
|
type: 'select' as const,
|
|
currentValue: models.currentModelId,
|
|
options: models.availableModels.map(
|
|
(m: SessionModelState['availableModels'][number]) => ({
|
|
value: m.modelId,
|
|
name: m.name,
|
|
description: m.description ?? undefined,
|
|
}),
|
|
),
|
|
},
|
|
] as SessionConfigOption[]
|
|
}
|
|
|
|
/**
|
|
* Flatten a SessionConfigOption's `options` (which may be flat
|
|
* SessionConfigSelectOption entries or grouped SessionConfigSelectGroup
|
|
* entries) into a list of valid value strings. Used to validate that a
|
|
* setSessionConfigOption value is one of the listed options.
|
|
*/
|
|
export function flattenConfigOptionValues(options: unknown): string[] {
|
|
const values: string[] = []
|
|
if (!Array.isArray(options)) return values
|
|
for (const opt of options) {
|
|
if (typeof opt !== 'object' || opt === null) continue
|
|
const maybeGroup = opt as { group?: unknown; options?: unknown[] }
|
|
if (Array.isArray(maybeGroup.options)) {
|
|
// SessionConfigSelectGroup — recurse into its options
|
|
for (const inner of maybeGroup.options) {
|
|
if (
|
|
inner &&
|
|
typeof inner === 'object' &&
|
|
typeof (inner as { value?: unknown }).value === 'string'
|
|
) {
|
|
values.push((inner as { value: string }).value)
|
|
}
|
|
}
|
|
} else if (typeof (opt as { value?: unknown }).value === 'string') {
|
|
// SessionConfigSelectOption
|
|
values.push((opt as { value: string }).value)
|
|
}
|
|
}
|
|
return values
|
|
}
|