/** * 工具注册中间件 — 封装安全的工具注册边界。 * * 职责边界: * - 负责:合同查找、动态 category/side_effects 计算、合同验证、 * 声明式门禁链调用、handler 执行与响应装饰 * - 不负责:授权决策(在 middleware/authorization.ts)、 * 工作区/denied_paths(在 middleware/workspace_check.ts)、 * 具体工具业务逻辑(在各 sf_* 工具模块中) * * 被谁调用:各 sf_* 工具模块通过 createToolRegistrar 注册工具 * 调用谁:middleware/authorization、 * middleware/workspace_check、middleware_gates、gate_engine、lazy_loaders * * 数据流:MCP 请求 → 合同查找 → 授权 → 状态/工作区预检 → * 声明式门禁链 → 合同验证 → handler 执行 → 响应装饰 → MCP 响应 * 持久化:读写 .soloforge/ 目录、项目知识文件 */ import type { z } from "zod"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import type { ProjectConfig } from "../../types/index.js"; import type { KnowledgeIndexManager } from "../../context/index.js"; import type { TaskContextManager } from "../../core/task_context.js"; import type { IOController } from "../../shared/io_controller.js"; import { type SideEffect } from "../../gate/index.js"; import type { ToolRequestArgs } from "./types.js"; export type { ToolRequestArgs } from "./types.js"; /** MCP 工具 handler 返回类型 — 由中间件动态检查结构 */ type ToolHandlerResult = unknown; export interface ToolRegistrationContext { server: McpServer; config: ProjectConfig; knowledgeIndex: KnowledgeIndexManager; taskContext: TaskContextManager; ioController: IOController; projectPath: string; /** 注册时自动收集的工具名列表,供契约预检使用 */ registeredToolNames: string[]; } export interface ToolRegistrar { registerSafeTool: (name: string, desc: string, schema: Record, handler: (args: ToolRequestArgs) => Promise) => void; loadRelevantAnchors: (query: { module?: string; file_paths?: string[]; }) => Promise | undefined>; } /** 根据声明式自动化层级得到本次 action 的真实副作用;L0 必须保持纯读。 */ export declare function effectiveSideEffectsForAction(toolName: string, args: ToolRequestArgs, contract: { side_effects: SideEffect[]; action_side_effects?: Record; }): SideEffect[]; export declare function createToolRegistrar(ctx: ToolRegistrationContext): ToolRegistrar;