/** * AgentAdapter — 子 Agent 统一适配层 * * v8.3.160+: 实现子 Agent 隔离,解决上下文漂移问题。 * v8.3.169+: 真正集成 Qoder Agent SDK,支持多工具动态适配: * - Qoder: 通过 @qoder-ai/qoder-agent-sdk 直接调度子 Agent * - Cursor/Windsurf/Claude/CodeBuddy/Trae: Headless 模式(文本标记) * - 所有工具默认兜底 Headless * * 每个 Pipeline 步骤可以指定 subagent,由适配层负责: * 1. 准备该 subagent 所需的紧凑上下文 * 2. 控制上下文大小(Token 预算) * 3. 输出子 Agent 激活标记和指令(Headless) * 4. 或直接通过 SDK 调度子 Agent 执行(Qoder SDK) */ import { ContextSnapshot } from './pipeline-engine'; import { type HostAiTool } from './ask-host-ai'; export interface AgentContext { /** 子 Agent 名称 */ subagent: string; /** 迭代名 */ iteration: string; /** 任务 ID */ task?: string; /** 端名 */ platform?: string; /** 上下文快照 */ contextSnapshot?: ContextSnapshot; /** 上下文预算(tokens) */ contextBudget: number; /** 上下文加载类型 */ contextType: 'full' | 'incremental' | 'platform-only' | 'contract-only'; /** 工作区根目录 */ cwd: string; } export interface SubagentConfig { /** 子 Agent 标识名 */ name: string; /** 职责描述 */ description: string; /** 系统级 Prompt(角色定义) */ systemPrompt: string; /** 默认上下文类型 */ defaultContextType: 'full' | 'incremental' | 'platform-only' | 'contract-only'; /** 默认 Token 预算 */ defaultContextBudget: number; /** 关联技能文件路径 */ skills: string[]; } export type AgentAdapterMode = 'headless' | 'qoder-sdk' | 'cursor-sdk' | 'windsurf-sdk' | 'claude-sdk' | 'codebuddy-sdk'; export interface SubagentDispatchResult { /** 是否成功执行 */ success: boolean; /** Agent 的文本回复 */ content?: string; /** 被修改/创建的文件路径列表 */ filesChanged?: string[]; /** 错误信息 */ error?: string; } export interface AgentAdapter { /** 注册子 Agent 配置 */ registerSubagent(name: string, config: SubagentConfig): void; /** 根据 subagent 名获取配置 */ getSubagentConfig(name: string): SubagentConfig | undefined; /** 准备子 Agent 的紧凑上下文文本 */ prepareContext(ctx: AgentContext): Promise; /** 构建子 Agent 激活标记和指令 */ buildActivationPrompt(ctx: AgentContext, nextPrompt: string): string; /** 获取支持的适配模式 */ getMode(): AgentAdapterMode; /** v8.3.169+: 直接调度子 Agent 执行任务(SDK 模式) * 返回 null 表示当前适配器不支持直接调度,需由外层 AI 接管 */ dispatchSubagent?(ctx: AgentContext, taskPrompt: string): Promise; } export declare class HeadlessAdapter implements AgentAdapter { private registry; private registryLoaded; constructor(); /** v8.3.183+: 懒加载从 frontmatter 元数据构建 registry(替代硬编码 DEFAULT_SUBAGENTS) */ private ensureRegistryLoaded; getMode(): AgentAdapterMode; /** v8.3.169+: Headless 模式不支持直接调度,返回 null 由外层 AI 接管 */ dispatchSubagent(_ctx: AgentContext, _taskPrompt: string): Promise; registerSubagent(name: string, config: SubagentConfig): void; getSubagentConfig(name: string): SubagentConfig | undefined; /** 准备子 Agent 的紧凑上下文 */ prepareContext(ctx: AgentContext): Promise; /** 构建子 Agent 激活标记 */ buildActivationPrompt(ctx: AgentContext, nextPrompt: string): string; } export declare class QoderSdkAdapter implements AgentAdapter { private registry; private sdkModule; private registryLoaded; constructor(); /** v8.3.183+: 懒加载从 frontmatter 元数据构建 registry */ private ensureRegistryLoaded; getMode(): AgentAdapterMode; registerSubagent(name: string, config: SubagentConfig): void; getSubagentConfig(name: string): SubagentConfig | undefined; /** 上下文准备:回退到 Headless(Prompt 构建阶段统一使用) */ prepareContext(ctx: AgentContext): Promise; /** 激活标记:回退到 Headless(SDK 模式下也输出标记作为备用) */ buildActivationPrompt(ctx: AgentContext, nextPrompt: string): string; /** * v8.3.266: 三级鉴权降级—— * 1. 国际版 PAT 环境变量(SDK 原生识别名 QODER_PERSONAL_ACCESS_TOKEN) * 2. Qoder CN 的 PAT 环境变量(docs.qoder.cn 官方文档用 QODERCN_PERSONAL_ACCESS_TOKEN, * SDK 不识别此名——此前按 CN 文档设置的用户会白设并报「未设置 QODER_PERSONAL_ACCESS_TOKEN」) * 3. Qoder CLI 登录态(qodercliAuth,零配置路径) */ /** v8.3.301+: 鉴权探测缓存——auto 预检与正式调度复用同一次探测结果,避免重复唤起 CLI 登录态 */ private authProbe; private resolveSdkAuth; /** * v8.3.301+: 预检鉴权可用性(settings.agent_dispatch.mode=auto 用)—— * 先确保 SDK 模块已加载(CLI 登录态探测依赖 qodercliAuth),再做三级鉴权探测 */ probeSdkAuth(): Promise; /** * v8.3.301+: 动态加载 SDK 模块(optional dependency),返回是否加载成功。 * 从 dispatchSubagent 拆出,供 probeSdkAuth 预检复用(CLI 登录态探测依赖 qodercliAuth)。 */ private ensureSdkLoaded; /** v8.3.169+: 通过 Qoder Agent SDK 直接调度子 Agent */ dispatchSubagent(ctx: AgentContext, taskPrompt: string): Promise; } /** 判断当前工具是否支持 SDK 级子 Agent 调度 */ export declare function isSdkDispatchSupported(tool?: HostAiTool): boolean; export type SdkDispatchMode = 'auto' | 'on' | 'off'; /** * v8.3.301+: 读取 SDK 派单开关(settings.agent_dispatch.mode) * - auto(默认): Qoder 宿主 + token 可用(PAT 环境变量或 CLI 登录态)时才走 SDK * - on: 强制尝试 SDK(token 不可用也尝试,失败回退标记模式) * - off: 禁用 SDK 派单,永远标记模式 * 配置缺失/读取失败/非法值均按 auto 兜底(保持 v8.3.300 前默认行为) */ export declare function getSdkDispatchMode(): Promise; /** 判断当前环境是否支持直接子 Agent 调度(SDK 或 Headless) */ export declare function isSubagentDispatchSupported(): boolean; /** v8.3.301+: 导出单例获取器(dispatchSubagent 开关拦截逻辑的测试接缝) */ export declare function getQoderSdkAdapter(): QoderSdkAdapter; /** * 调度子 Agent 执行任务 * * - Qoder 环境:通过 @qoder-ai/qoder-agent-sdk 直接调用 * - 其他环境:返回 null(由外层 AI 通过 [SPECCORE_SESSION_AGENT] 标记接管) */ export declare function dispatchSubagent(ctx: AgentContext, taskPrompt: string): Promise; /** * 创建适配器 * v8.3.169+: 根据检测到的宿主工具自动选择适配器 */ export declare function createAgentAdapter(mode?: AgentAdapterMode): AgentAdapter; export declare const defaultAdapter: HeadlessAdapter; //# sourceMappingURL=agent-adapter.d.ts.map