UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

140 lines (139 loc) 4.54 kB
/** * orchestrator.js — 内部 Agent AI-First Bootstrap 管线 * * ⚠️ 本文件是「内部 Agent」专用 — 由 bootstrap.js Phase 5 调用。 * 外部 Agent (Cursor/Copilot) 不经过此管线,它们自行分析代码。 * * 核心架构: PipelineStrategy 驱动 (Analyze → QualityGate → Produce → RejectionGate) * * 1. Analyze 阶段: 自由探索代码 (AST 工具 + 文件搜索) * 2. QualityGate: 质量门控 (insightGateEvaluator) * 3. Produce 阶段: 格式化输出 (submit_knowledge) * 4. TierScheduler 分层并行执行 * * @module pipeline/orchestrator */ import type { DimensionDef } from '#types/project-snapshot.js'; import type { PipelineFillView } from '#types/snapshot-views.js'; import { clearCheckpoints } from './checkpoint.js'; /** Singleton properties accessed by orchestrator */ interface OrchestratorSingletons { aiProvider?: { name?: string; model?: string; supportsEmbedding?: () => boolean; [key: string]: unknown; } | null; _embedProvider?: { embed?: (text: string) => Promise<number[]>; [key: string]: unknown; } | null; _fileCache?: BootstrapFileEntry[] | null; _projectRoot?: string; _config?: Record<string, unknown>; _lang?: string | null; [key: string]: unknown; } /** Services orchestrator accesses via container.get() */ interface OrchestratorServiceKeys { agentFactory: AgentFactoryLike; bootstrapTaskManager: TaskManagerLike; database: any; } /** Extended DI container shape for orchestrator */ interface OrchestratorContainer { get<K extends keyof OrchestratorServiceKeys>(name: K): OrchestratorServiceKeys[K]; get(name: string): any; singletons: OrchestratorSingletons; buildProjectGraph?(projectRoot: string, options?: Record<string, unknown>): Promise<ProjectGraphLike | null>; [key: string]: unknown; } /** ProjectGraph minimal shape */ interface ProjectGraphLike { getOverview(): { totalClasses: number; totalProtocols: number; [key: string]: unknown; }; [key: string]: unknown; } /** Bootstrap file entry */ interface BootstrapFileEntry { name: string; path: string; relativePath: string; content: string; targetName?: string; } /** Task manager minimal shape */ interface TaskManagerLike { isSessionValid(sessionId: string): boolean; getSessionAbortSignal?(): AbortSignal | null; emitProgress?(event: string, data: Record<string, unknown>): void; [key: string]: unknown; } /** Agent factory minimal shape */ interface AgentFactoryLike { createRuntime(preset: string, overrides?: Record<string, unknown>): AgentRuntimeLike; createContextWindow(opts?: { isSystem?: boolean; }): unknown; [key: string]: unknown; } /** Agent runtime minimal shape */ interface AgentRuntimeLike { execute(message: unknown, opts?: Record<string, unknown>): Promise<AgentResultLike>; setFileCache(files: unknown[] | null): void; aiProvider: { name?: string; model?: string; [key: string]: unknown; }; [key: string]: unknown; } /** Agent execution result */ interface AgentResultLike { reply?: string; toolCalls?: ToolCallRecord[]; tokenUsage?: { input: number; output: number; }; phases?: Record<string, { reply?: string; artifact?: Record<string, any>; [key: string]: any; }>; degraded?: boolean; [key: string]: unknown; } /** Tool call record from runtime */ interface ToolCallRecord { tool?: string; name?: string; args?: Record<string, unknown>; params?: Record<string, unknown>; result?: unknown; [key: string]: unknown; } /** * fillDimensionsV3 — v3.0 AI-First 维度填充管线 * * @param view PipelineFillView — 从 handler 传入的类型化视图 * @param dimensions 当前运行的维度列表(rescan 可能是 gap 子集) */ export declare function fillDimensionsV3(view: PipelineFillView, dimensions: DimensionDef[]): Promise<void>; /** * 清除增量 Bootstrap 快照 — 供 bootstrapKnowledge 在手动冷启动时调用 * @param ctx { container, logger } */ declare function clearSnapshotsImpl(projectRoot: string, ctx: { container: OrchestratorContainer; logger: { info(...args: unknown[]): void; warn(...args: unknown[]): void; }; }): Promise<void>; export { clearCheckpoints }; export { clearSnapshotsImpl as clearSnapshots }; export default fillDimensionsV3;