/** * ============================================================ * src/plugin-sdk.ts —— 插件作者的稳定 import 门面 * ------------------------------------------------------------ * Drop-in 插件契约的"窄门":插件根目录下的 plugin.ts 只允许从 * '../../src/plugin-sdk.js' 取运行时(NodeNext 标准,Bun 自动回退到 .ts * 源文件,Node 跑 install 后编译产物),不直接访问 src/ 内部路径。 * * 好处: * - 框架内部重构(loop.ts / llm/client.ts / tools/* 移动)不破坏插件 * - 插件作者只需记一个 import 源 * - 暴露面收口(这里没的 API 不开放给插件) * * 零运行时开销:纯 re-export,TS 编译后等价于直接 import。 * ============================================================ */ // --- 运行时入口 --- export { runQuery } from './loop.js'; export type { RunQueryOptions } from './loop.js'; export { killTree } from './tools/shared/killTree.js'; export { isReadOnlyShellCommand } from './tools/bash/semantics.js'; export { runBoundedProcess } from './runtime/boundedProcess.js'; export { resolveScriptRuntime } from './runtime/scriptRuntime.js'; export type { ToolGate, ToolGateRequest, ToolGateDecision } from './toolGate.js'; export { runAgentTurn } from './session/runAgentTurn.js'; export type { RunAgentTurnOptions, RunAgentTurnResult } from './session/runAgentTurn.js'; export { chat } from './llm/client.js'; export { derivePromptCacheContext, } from './llm/promptCache.js'; export { ALL_TOOLS, executeCatalogTool, executeTool, getToolByName, getToolGateDetails } from './tools/index.js'; export { shutdownAllLsp } from './tools/lsp/service.js'; // --- Computer Use --- // // 桌面操作的**知识与命令面**住在 `plugins/computer_use/`,可信执行层住在内核 // (`src/tools/computeruse/`)。这里**只**开放只读诊断门面: // // ⚠️ 曾经这里导出的是完整的 `computerUseService`,而那个对象的 `request()` // 能派发 click / type / file_drop —— 一个「只做诊断与知识管理」的插件不该 // 拿得到操作鼠标键盘的能力。注释当时宣称「只开放这几件事」,代码没做到。 // 别再把 service 加回来。 export { computerUseDiagnostics } from './tools/computeruse/diagnostics.js'; export { describeCapabilities } from './tools/computeruse/capabilityLabels.js'; export type { CapabilityLabel, CapabilityState } from './tools/computeruse/capabilityLabels.js'; export type { ManualDraft, ManualSource, } from './tools/computeruse/diagnostics.js'; export { readRecentComputerUseAudit } from './cli/computerUse.js'; export { readComputerUseTelemetryReport } from './tools/computeruse/telemetryLog.js'; export { matchGuide, describeMatch, loadAllAppManuals, } from './tools/computeruse/vision/appGuide.js'; export type { LoadedManuals, } from './tools/computeruse/vision/appGuide.js'; export { EMPTY_MANUAL, validateManual, } from './tools/computeruse/manualSchema.js'; export type { ManualFlow, } from './tools/computeruse/manualSchema.js'; export type { ComputerUseResponse, } from './tools/computeruse/protocol.js'; // pre-read 守卫状态登记:tool 步覆盖「声明产物」时用来解除内核「先读后写 / 截断禁写」 // 守卫(确定性步的 args 写死、模型没机会先 Read)。详见 stepExecutors/tool.ts。 export { recordRead } from './tools/shared/fileState.js'; export { getWorkingDir } from './bootstrap/workingDir.js'; export { agentStateDir } from './context/agentHome.js'; export { dlog } from './utils/debugLog.js'; // 思维链剥离:内核与 workflow-runner 共享(原住 agentCommon.ts, // Agent 子任务工具也需要 → 上移内核,插件经此 re-export)。 export { stripThinkBlocks } from './utils/stripThink.js'; // 长驻宿主保持 buildBaseSystemPrompt 稳定,每回合单独传 transient bundle。 // (`buildTransientContext` 曾也在这里 re-export,唯一消费者是已删除的 yaml 引擎; // 门面每多一个导出就多一条不能自由重构的边,没消费者就先不导出。) export { buildTransientPromptBundle } from './prompts/system.js'; export { refreshStableSystemPrompt } from './prompts/stableSystemPrompt.js'; /** @deprecated Prefer runAgentTurn or refreshStableSystemPrompt for runtime-aware prompts. */ export { buildBaseSystemPrompt } from './prompts/system.js'; /** @deprecated Prefer refreshStableSystemPrompt, which also refreshes tool guidance. */ export { upsertStableSystemMessage } from './prompts/stableSystemPrompt.js'; export type { PromptEnvelope, PromptSurface } from './prompts/promptAssembly.js'; export type { ContextBundle } from './context/contextBundle.js'; export { createAgentRuntimeContext, filterToolsForRuntime, } from './runtime/agentRuntimeContext.js'; export type { AgentRuntimeContext, } from './runtime/agentRuntimeContext.js'; export { getResourceSearchPaths } from './utils/resourcePaths.js'; export type { ResourceName } from './utils/resourcePaths.js'; // 「这个路径在不在那个目录里」的唯一实现——已经被手写错过好几次(含 // workflow-runner 自己的两份,Windows 跨盘符时会误判成"在目录内")。插件凡是要 // 做路径包含判定,一律经这里,不要再手写一遍。 export { pathContains } from './utils/pathContains.js'; // 确定性检查设施:verify 步(shell/file_exists/file_contains/test_count)经此跑校验。 export { parseCheckString, runVerification } from './infra/verification.js'; export type { Check } from './infra/verification.js'; export { triggerHook } from './plugins/hookEngine.js'; export type { HookEventName, HookDecision } from './plugins/hookEngine.js'; export { createSessionState, disposeDetachedSessionState } from './session/sessionState.js'; export type { SessionState } from './session/sessionState.js'; // 会话文件是否真实存在(含 default session 的 legacy 路径回退): // cron-runner 等需要在发起回合前判断"绑定的 session 是否还在"时用它, // 不要绕过 legacy 回退逻辑自己拼路径。 export { resolveSessionFile } from './context/sessionPath.js'; /** * 按模型 id 解析出一个 Provider(工作流的 `agent(..., { model })` 用)。 * * ⚠️ 门面只暴露这一个**语义明确的解析函数**,不暴露整个 ConfigService —— * 后者带着读写配置、草稿、顾问设置一大堆能力,插件不该拿到,而门面每多一个 * 导出就多一条不能自由重构的边(`test/pluginSdkSurface.test.ts` 守这条)。 * * 解析不到(id 不存在 / 该条目没填 apiKey)返回 null —— 调用方**必须**回落到 * 基座 provider 并如实告警,不能静默换模型。 */ export async function resolveProviderForModel( modelId: string, ): Promise { const { configService } = await import('./config/configService.js'); return configService.providerForModel(modelId); } /** Resolve a portable workflow capability role through this machine's config. */ export async function resolveProviderForWorkflowRole( role: string, ): Promise { const { configService } = await import('./config/configService.js'); return configService.providerForWorkflowRole(role); } // --- 类型 --- export type { ImageInputSpec, InvocationResource, Message, Provider, LoopEvent, LlmStreamEvent, PromptCacheContext, Tool, ToolResult, // 插件需要它来组装 executeTool 的第四参(宿主授权上下文按需切片转发)。 // 不导出的话插件只能绕过门面直接 import 内核,那正是门面要避免的。 ToolCallContext, // 工作流引擎要把每次 agent()/llm() 的用量记进账本,`budget()` 才有刻度。 TurnResourceUsage, } from './types.js'; export type { PluginApi, PluginContext, PluginRuntimeContext, } from './plugins/pluginApi.js';