/** * ARCHITECTURE BREAK — GateRunner V2 迁移开关 * * 本文件控制从旧版分散式门禁/工具检查系统到统一 GateRunner 控制面的迁移。 * * 迁移策略(双轨并行): * * 迁移期间(KCODE_GATE_RUNNER_V2 != "1"): * - 旧入口(evaluateToolGateway、sourceWriteBlockReason 等)继续作为适配器工作。 * - 新 GateRunner 以影子模式运行:findings 被记录但不阻塞操作。 * - 用途:验证新策略逻辑的正确性,不影响现有工作流。 * * 迁移完成后(KCODE_GATE_RUNNER_V2 = "1"): * - GateRunner 成为门禁决策的唯一权威。 * - 旧规则源被删除或降级为适配器(不再做规则判断)。 * - 所有 tool/write/phase/delegation 入口必须经过 GateRunner。 * * 旧模块迁移状态映射表(MODULE_MIGRATION_MAP): * 记录每个旧模块到新模块的对应关系和迁移状态, * 用于运行时判断是否使用旧模块作为主规则源。 /** 全局开关:设为 "1" 时激活 GateRunner V2 控制面。由环境变量 KCODE_GATE_RUNNER_V2 控制。 */ export const GATE_RUNNER_V2_ENABLED: boolean = process.env.KCODE_GATE_RUNNER_V2 === "1"; /** * 影子模式:V2 未启用时,若 KCODE_GATE_RUNNER_SHADOW=1, * GateRunner 与旧门禁并行运行,记录 findings 但不阻塞操作。 * 用于迁移期间的验证和对比测试。 */ export const GATE_RUNNER_SHADOW_MODE: boolean = !GATE_RUNNER_V2_ENABLED && process.env.KCODE_GATE_RUNNER_SHADOW === "1"; /** * 旧模块迁移状态。 * * 每个条目对应"旧模块废弃表"中的一项: * - "adapter": 旧模块仍存在,但委托给新模块执行。 * - "deprecated": 旧模块标记为废弃,新模块为权威。 * - "rewrite": 旧模块将被完全重写为新模块。 * - "deleted": 旧模块已被移除。 * - "keep-runtime": PI Runtime 接口,不属于 KCode Harness 重构范围。 */ export type MigrationStatus = "adapter" | "deprecated" | "rewrite" | "deleted" | "keep-runtime"; /** 单个模块迁移条目。 */ export interface ModuleMigrationEntry { oldPath: string; newPath: string; status: MigrationStatus; notes: string; } /** * 模块迁移映射表。 * * 记录旧模块路径 → 新模块路径的对应关系和迁移状态。 * 运行时通过 isOldRuleSource() 查询此表,判断旧模块是否仍为主规则源。 */ export const MODULE_MIGRATION_MAP: readonly ModuleMigrationEntry[] = [ { oldPath: "src/harness/gates.ts", newPath: "src/harness/gates/*", status: "rewrite", notes: "Old gate logic migrated to GateRunner + PolicyRegistry. Old functions become adapters.", }, { oldPath: "src/harness/tool-gateway.ts", newPath: "src/harness/tools/tool-pipeline.ts", status: "rewrite", notes: "Tool gateway checks moved to ToolPipeline + GateRunner pre-tool checkpoint.", }, { oldPath: "src/harness/action-policy.ts", newPath: "src/harness/gates/policies/source-write-policy.ts", status: "deprecated", notes: "Source write policy extracted to independent policy module.", }, { oldPath: "src/harness/goal-loop.ts", newPath: "src/harness/loop/loop-kernel.ts", status: "rewrite", notes: "Goal loop unified under LoopKernel + VerifyPlan.", }, { oldPath: "src/harness/demand-loop.ts", newPath: "src/harness/loop/loop-kernel.ts", status: "rewrite", notes: "Demand loop unified under LoopKernel.", }, { oldPath: "src/harness/repair.ts", newPath: "src/harness/loop/loop-kernel.ts", status: "rewrite", notes: "Repair loop unified under LoopKernel + StopHook.", }, { oldPath: "src/harness/prompt.ts", newPath: "src/harness/context/prompt-section-registry.ts", status: "rewrite", notes: "Prompt renderer only; rules come from PromptSectionRegistry.", }, { oldPath: "src/harness/prompt-policy.ts", newPath: "src/harness/gates/policy-registry.ts", status: "deprecated", notes: "Policy rules extracted to PolicyRegistry; prompt only renders summaries.", }, { oldPath: "src/harness/evidence.ts", newPath: "src/harness/evidence/evidence-store.ts", status: "deprecated", notes: "Evidence management moved to EvidenceStore with sourceTrust grading.", }, { oldPath: "src/harness/write-transaction.ts", newPath: "src/harness/tools/write-pipeline.ts", status: "rewrite", notes: "Write transactions managed by WritePipeline through pre-write/post-write gates.", }, { oldPath: "extensions/kingdee-tools.ts", newPath: "src/harness/tools/tool-pipeline.ts", status: "adapter", notes: "Tool definitions remain; gate checks delegated to ToolPipeline.", }, { oldPath: "extensions/kingdee-powershell-tool.ts", newPath: "src/harness/tools/tool-pipeline.ts", status: "adapter", notes: "PowerShell wrapper passes through ToolPipeline + PowerShellMutationPolicy.", }, { oldPath: "extensions/kingdee-subagents.ts", newPath: "src/harness/loop/delegation-plan.ts", status: "adapter", notes: "Subagent spawn delegates to DelegationPlan + pre/post-delegation gates.", }, ] as const; /** * 判断指定路径的旧模块是否应作为主规则源。 * * V2 启用后,旧模块永远不再是主规则源(返回 false)。 * V2 未启用时,检查 MODULE_MIGRATION_MAP 中是否存在未删除的条目。 */ export function isOldRuleSource(path: string): boolean { // V2 启用 = GateRunner 是唯一权威,旧模块全部降级 if (GATE_RUNNER_V2_ENABLED) return false; return MODULE_MIGRATION_MAP.some( (entry) => entry.oldPath === path && entry.status !== "deleted" ); }