@zqagent/core 0.2.16 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.oss.en.md +15 -2
- package/README.oss.md +18 -2
- package/README.oss.zh-TW.md +13 -2
- package/dist/McpClient-CEQBUPuC.d.cts +145 -0
- package/dist/McpClient-CEQBUPuC.d.ts +145 -0
- package/dist/{ToolRegistry-C3pTFiaJ.d.cts → ToolRegistry-Cy0fQxrb.d.ts} +2 -111
- package/dist/{ToolRegistry-C3pTFiaJ.d.ts → ToolRegistry-DouDvn9E.d.cts} +2 -111
- package/dist/{explore-RtZtb-V6.d.ts → TurnEngine-BPKhWuSI.d.cts} +108 -73
- package/dist/{explore-BgRhj6SP.d.cts → TurnEngine-DtGEuVLT.d.ts} +108 -73
- package/dist/conflictGuard-BBOOIxxK.d.cts +42 -0
- package/dist/conflictGuard-BBOOIxxK.d.ts +42 -0
- package/dist/index.cjs +5477 -1140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +577 -195
- package/dist/index.d.ts +577 -195
- package/dist/index.js +5305 -1002
- package/dist/index.js.map +1 -1
- package/dist/internal/crypto/secrets.cjs +25 -0
- package/dist/internal/crypto/secrets.cjs.map +1 -0
- package/dist/internal/crypto/secrets.d.cts +2 -0
- package/dist/internal/crypto/secrets.d.ts +2 -0
- package/dist/internal/crypto/secrets.js +3 -0
- package/dist/internal/crypto/secrets.js.map +1 -0
- package/dist/internal/engine/FileLogHook.cjs +179 -0
- package/dist/internal/engine/FileLogHook.cjs.map +1 -0
- package/dist/internal/engine/FileLogHook.d.cts +67 -0
- package/dist/internal/engine/FileLogHook.d.ts +67 -0
- package/dist/internal/engine/FileLogHook.js +144 -0
- package/dist/internal/engine/FileLogHook.js.map +1 -0
- package/dist/internal/engine/approvalView.cjs +25 -0
- package/dist/internal/engine/approvalView.cjs.map +1 -0
- package/dist/internal/engine/approvalView.d.cts +1 -0
- package/dist/internal/engine/approvalView.d.ts +1 -0
- package/dist/internal/engine/approvalView.js +3 -0
- package/dist/internal/engine/approvalView.js.map +1 -0
- package/dist/internal/engine/limits.cjs +59 -0
- package/dist/internal/engine/limits.cjs.map +1 -0
- package/dist/internal/engine/limits.d.cts +32 -0
- package/dist/internal/engine/limits.d.ts +32 -0
- package/dist/internal/engine/limits.js +31 -0
- package/dist/internal/engine/limits.js.map +1 -0
- package/dist/internal/engine/sessionNaming.cjs +47 -0
- package/dist/internal/engine/sessionNaming.cjs.map +1 -0
- package/dist/internal/engine/sessionNaming.d.cts +25 -0
- package/dist/internal/engine/sessionNaming.d.ts +25 -0
- package/dist/internal/engine/sessionNaming.js +20 -0
- package/dist/internal/engine/sessionNaming.js.map +1 -0
- package/dist/internal/llmConfig.cjs +561 -0
- package/dist/internal/llmConfig.cjs.map +1 -0
- package/dist/internal/llmConfig.d.cts +75 -0
- package/dist/internal/llmConfig.d.ts +75 -0
- package/dist/internal/llmConfig.js +535 -0
- package/dist/internal/llmConfig.js.map +1 -0
- package/dist/internal/mcp/builtin/index.cjs +685 -0
- package/dist/internal/mcp/builtin/index.cjs.map +1 -0
- package/dist/internal/mcp/builtin/index.d.cts +21 -0
- package/dist/internal/mcp/builtin/index.d.ts +21 -0
- package/dist/internal/mcp/builtin/index.js +652 -0
- package/dist/internal/mcp/builtin/index.js.map +1 -0
- package/dist/internal/mcp/config.cjs +278 -0
- package/dist/internal/mcp/config.cjs.map +1 -0
- package/dist/internal/mcp/config.d.cts +61 -0
- package/dist/internal/mcp/config.d.ts +61 -0
- package/dist/internal/mcp/config.js +235 -0
- package/dist/internal/mcp/config.js.map +1 -0
- package/dist/internal/mcp/presets.cjs +184 -0
- package/dist/internal/mcp/presets.cjs.map +1 -0
- package/dist/internal/mcp/presets.d.cts +39 -0
- package/dist/internal/mcp/presets.d.ts +39 -0
- package/dist/internal/mcp/presets.js +158 -0
- package/dist/internal/mcp/presets.js.map +1 -0
- package/dist/internal/node-name.cjs +45 -0
- package/dist/internal/node-name.cjs.map +1 -0
- package/dist/internal/node-name.d.cts +3 -0
- package/dist/internal/node-name.d.ts +3 -0
- package/dist/internal/node-name.js +10 -0
- package/dist/internal/node-name.js.map +1 -0
- package/dist/internal/paths.cjs +63 -0
- package/dist/internal/paths.cjs.map +1 -0
- package/dist/internal/paths.d.cts +17 -0
- package/dist/internal/paths.d.ts +17 -0
- package/dist/internal/paths.js +25 -0
- package/dist/internal/paths.js.map +1 -0
- package/dist/internal/providers/diagnostics.cjs +288 -0
- package/dist/internal/providers/diagnostics.cjs.map +1 -0
- package/dist/internal/providers/diagnostics.d.cts +103 -0
- package/dist/internal/providers/diagnostics.d.ts +103 -0
- package/dist/internal/providers/diagnostics.js +250 -0
- package/dist/internal/providers/diagnostics.js.map +1 -0
- package/dist/internal/providers/models.cjs +699 -0
- package/dist/internal/providers/models.cjs.map +1 -0
- package/dist/internal/providers/models.d.cts +136 -0
- package/dist/internal/providers/models.d.ts +136 -0
- package/dist/internal/providers/models.js +654 -0
- package/dist/internal/providers/models.js.map +1 -0
- package/dist/internal/terminal.cjs +161 -0
- package/dist/internal/terminal.cjs.map +1 -0
- package/dist/internal/terminal.d.cts +58 -0
- package/dist/internal/terminal.d.ts +58 -0
- package/dist/internal/terminal.js +128 -0
- package/dist/internal/terminal.js.map +1 -0
- package/dist/internal/tools/execAsync.cjs +187 -0
- package/dist/internal/tools/execAsync.cjs.map +1 -0
- package/dist/internal/tools/execAsync.d.cts +30 -0
- package/dist/internal/tools/execAsync.d.ts +30 -0
- package/dist/internal/tools/execAsync.js +162 -0
- package/dist/internal/tools/execAsync.js.map +1 -0
- package/dist/internal/tools/git.cjs +935 -0
- package/dist/internal/tools/git.cjs.map +1 -0
- package/dist/internal/tools/git.d.cts +206 -0
- package/dist/internal/tools/git.d.ts +206 -0
- package/dist/internal/tools/git.js +883 -0
- package/dist/internal/tools/git.js.map +1 -0
- package/dist/internal/tools/pathSafety.cjs +99 -0
- package/dist/internal/tools/pathSafety.cjs.map +1 -0
- package/dist/internal/tools/pathSafety.d.cts +44 -0
- package/dist/internal/tools/pathSafety.d.ts +44 -0
- package/dist/internal/tools/pathSafety.js +61 -0
- package/dist/internal/tools/pathSafety.js.map +1 -0
- package/dist/internal/tools/plan.cjs +146 -0
- package/dist/internal/tools/plan.cjs.map +1 -0
- package/dist/internal/tools/plan.d.cts +48 -0
- package/dist/internal/tools/plan.d.ts +48 -0
- package/dist/internal/tools/plan.js +117 -0
- package/dist/internal/tools/plan.js.map +1 -0
- package/dist/internal/tools/ripgrep.cjs +118 -0
- package/dist/internal/tools/ripgrep.cjs.map +1 -0
- package/dist/internal/tools/ripgrep.d.cts +6 -0
- package/dist/internal/tools/ripgrep.d.ts +6 -0
- package/dist/internal/tools/ripgrep.js +89 -0
- package/dist/internal/tools/ripgrep.js.map +1 -0
- package/dist/internal/tools/sandbox.cjs +253 -0
- package/dist/internal/tools/sandbox.cjs.map +1 -0
- package/dist/internal/tools/sandbox.d.cts +67 -0
- package/dist/internal/tools/sandbox.d.ts +67 -0
- package/dist/internal/tools/sandbox.js +213 -0
- package/dist/internal/tools/sandbox.js.map +1 -0
- package/dist/internal/tools/shell.cjs +771 -0
- package/dist/internal/tools/shell.cjs.map +1 -0
- package/dist/internal/tools/shell.d.cts +47 -0
- package/dist/internal/tools/shell.d.ts +47 -0
- package/dist/internal/tools/shell.js +731 -0
- package/dist/internal/tools/shell.js.map +1 -0
- package/dist/internal/tools/shellRuntime.cjs +220 -0
- package/dist/internal/tools/shellRuntime.cjs.map +1 -0
- package/dist/internal/tools/shellRuntime.d.cts +67 -0
- package/dist/internal/tools/shellRuntime.d.ts +67 -0
- package/dist/internal/tools/shellRuntime.js +181 -0
- package/dist/internal/tools/shellRuntime.js.map +1 -0
- package/dist/internal/update/controller.cjs +1035 -0
- package/dist/internal/update/controller.cjs.map +1 -0
- package/dist/internal/update/controller.d.cts +150 -0
- package/dist/internal/update/controller.d.ts +150 -0
- package/dist/internal/update/controller.js +991 -0
- package/dist/internal/update/controller.js.map +1 -0
- package/dist/internal/update/platform.cjs +234 -0
- package/dist/internal/update/platform.cjs.map +1 -0
- package/dist/internal/update/platform.d.cts +77 -0
- package/dist/internal/update/platform.d.ts +77 -0
- package/dist/internal/update/platform.js +184 -0
- package/dist/internal/update/platform.js.map +1 -0
- package/dist/tools/ask.d.cts +3 -1
- package/dist/tools/ask.d.ts +3 -1
- package/dist/tools/diff.cjs +17 -6
- package/dist/tools/diff.cjs.map +1 -1
- package/dist/tools/diff.d.cts +5 -2
- package/dist/tools/diff.d.ts +5 -2
- package/dist/tools/diff.js +17 -6
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/directories.d.cts +3 -1
- package/dist/tools/directories.d.ts +3 -1
- package/dist/tools/explore.cjs +1778 -204
- package/dist/tools/explore.cjs.map +1 -1
- package/dist/tools/explore.d.cts +82 -2
- package/dist/tools/explore.d.ts +82 -2
- package/dist/tools/explore.js +1780 -204
- package/dist/tools/explore.js.map +1 -1
- package/dist/tools/files.cjs +56 -21
- package/dist/tools/files.cjs.map +1 -1
- package/dist/tools/files.d.cts +6 -3
- package/dist/tools/files.d.ts +6 -3
- package/dist/tools/files.js +56 -21
- package/dist/tools/files.js.map +1 -1
- package/dist/tools/git.cjs +34 -25
- package/dist/tools/git.cjs.map +1 -1
- package/dist/tools/git.d.cts +4 -204
- package/dist/tools/git.d.ts +4 -204
- package/dist/tools/git.js +34 -25
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/media.cjs +280 -3
- package/dist/tools/media.cjs.map +1 -1
- package/dist/tools/media.d.cts +3 -1
- package/dist/tools/media.d.ts +3 -1
- package/dist/tools/media.js +278 -1
- package/dist/tools/media.js.map +1 -1
- package/dist/tools/plan.cjs +62 -0
- package/dist/tools/plan.cjs.map +1 -1
- package/dist/tools/plan.d.cts +4 -17
- package/dist/tools/plan.d.ts +4 -17
- package/dist/tools/plan.js +59 -0
- package/dist/tools/plan.js.map +1 -1
- package/dist/tools/search.cjs +3 -0
- package/dist/tools/search.cjs.map +1 -1
- package/dist/tools/search.d.cts +3 -1
- package/dist/tools/search.d.ts +3 -1
- package/dist/tools/search.js +3 -0
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/shell.cjs +76 -11
- package/dist/tools/shell.cjs.map +1 -1
- package/dist/tools/shell.d.cts +5 -39
- package/dist/tools/shell.d.ts +5 -39
- package/dist/tools/shell.js +75 -11
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/todo.d.cts +3 -1
- package/dist/tools/todo.d.ts +3 -1
- package/dist/tools/web.cjs +279 -5
- package/dist/tools/web.cjs.map +1 -1
- package/dist/tools/web.d.cts +3 -1
- package/dist/tools/web.d.ts +3 -1
- package/dist/tools/web.js +275 -3
- package/dist/tools/web.js.map +1 -1
- package/dist/types-BYyXWWPW.d.cts +237 -0
- package/dist/types-BYyXWWPW.d.ts +237 -0
- package/package.json +26 -37
- package/bin/zqagent +0 -2
- package/dist/cli/index.cjs +0 -24507
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -2
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -24490
- package/dist/cli/index.js.map +0 -1
- package/dist/server/index.cjs +0 -19824
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -2
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.js +0 -19807
- package/dist/server/index.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,20 +1,87 @@
|
|
|
1
|
-
import { E as EngineHook, C as CompactionStartInfo, a as CompactionDoneInfo, b as EventType, c as EngineErrorInfo,
|
|
2
|
-
export { A as ApprovalOutcome, d as Approver, e as CompactionTrigger, D as Decision, O as OpenAIProvider, f as PermissionEngine, g as PermissionRequest, h as
|
|
3
|
-
import {
|
|
4
|
-
export { A as
|
|
1
|
+
import { M as Mode, S as ShellPolicy, E as EngineHook, C as CompactionStartInfo, a as CompactionDoneInfo, b as EventType, c as EngineErrorInfo, P as ProviderClient, T as TurnEngine } from './TurnEngine-BPKhWuSI.cjs';
|
|
2
|
+
export { A as ApprovalOutcome, d as Approver, e as CompactionTrigger, D as Decision, O as OpenAIProvider, f as PermissionEngine, g as PermissionRequest, h as ShellSandboxStatus, i as TurnEngineOpts, W as WsEvent } from './TurnEngine-BPKhWuSI.cjs';
|
|
3
|
+
import { T as TokenUsage, R as ReasoningEffort, M as Message } from './types-BYyXWWPW.cjs';
|
|
4
|
+
export { A as ATTACHMENT_DIR, d as AssistantTurn, e as AttachmentError, f as MAX_ATTACHMENTS, g as MAX_ATTACHMENT_BYTES, b as MessageAttachment, c as StoredAttachment, S as StreamChunk, h as ToolCall, a as ToolSchema, U as UPLOAD_DIR, W as WorkspaceFileRef, i as attachmentBytes, j as buildWorkspaceFileNotice, k as hasNonImageAttachments, n as normalizeAttachments, r as readStoredAttachment, s as saveAttachments, l as saveAttachmentsToWorkspace, m as splitByCapability, o as stripAttachments } from './types-BYyXWWPW.cjs';
|
|
5
|
+
import { T as ToolRegistry } from './ToolRegistry-DouDvn9E.cjs';
|
|
6
|
+
export { R as RiskClass, a as ToolMetadata, b as ToolSpec } from './ToolRegistry-DouDvn9E.cjs';
|
|
7
|
+
import { SandboxMode, SandboxOptions } from './internal/tools/sandbox.cjs';
|
|
8
|
+
export { SandboxBackend, SandboxPlan, buildBwrapArgs, buildMacProfile, describeSandbox, resetSandboxCache, resolveSandbox, wrapWithSandbox } from './internal/tools/sandbox.cjs';
|
|
9
|
+
export { APPROVAL_COLUMNS, APPROVAL_VALUE_MAX, ApprovalField, ApprovalViewInput, approvalFields, approvalInputFromData, approvalToHtmlTable, approvalToMarkdownTable } from '@zqagent/shared/approval-view';
|
|
10
|
+
export { FileLogHook, SavedState } from './internal/engine/FileLogHook.cjs';
|
|
11
|
+
import { a as McpServerConfig, M as McpBuiltinContext } from './McpClient-CEQBUPuC.cjs';
|
|
12
|
+
export { b as McpClient, c as McpClientOptions, d as McpToolInfo, e as McpTransportType, O as OcrLlmConfig, f as OcrRuntimeOverrides, m as mcpToolKey, s as sanitizeToolName } from './McpClient-CEQBUPuC.cjs';
|
|
13
|
+
export { BUILTIN_MCP_CONFIGS, McpConfigNormalizeOptions, McpConfigNormalizeResult, defaultMcpConfigPath, loadMcpConfigFile, normalizeMcpConfig, normalizeMcpConfigs, readMcpConfigFile, saveMcpConfigFile, splitCommandLine, withBuiltinMcpConfigs } from './internal/mcp/config.cjs';
|
|
5
14
|
export { registerFileTools, registerReadOnlyFileTools } from './tools/files.cjs';
|
|
6
|
-
export {
|
|
15
|
+
export { C as ConflictGuard, W as WriteConflict, c as contentDigest } from './conflictGuard-BBOOIxxK.cjs';
|
|
16
|
+
export { getShellCwd, registerShellTool } from './internal/tools/shell.cjs';
|
|
7
17
|
export { registerSearchTool } from './tools/search.cjs';
|
|
8
18
|
export { registerWebTools } from './tools/web.cjs';
|
|
9
|
-
export { registerGitTools } from './tools/git.cjs';
|
|
19
|
+
export { registerGitTools } from './internal/tools/git.cjs';
|
|
10
20
|
export { registerDiffTools } from './tools/diff.cjs';
|
|
11
21
|
export { TodoList, registerTodoTool } from './tools/todo.cjs';
|
|
22
|
+
export { registerExploreTool } from './tools/explore.cjs';
|
|
12
23
|
export { registerMediaTool } from './tools/media.cjs';
|
|
13
24
|
export { QuestionHandler, parsePicks, registerAskTool, setQuestionHandler } from './tools/ask.cjs';
|
|
14
|
-
export { PlanHandler, registerPlanTool, setPlanHandler } from './tools/plan.cjs';
|
|
25
|
+
export { PlanHandler, PlanReply, interpretPlanReply, isAffirmativeText, isRejectionText, registerPlanTool, setPlanHandler } from './internal/tools/plan.cjs';
|
|
15
26
|
export { DirectoryHandler, registerDirectoryTool, setDirectoryHandler } from './tools/directories.cjs';
|
|
16
27
|
import 'openai/resources/chat/completions.js';
|
|
17
28
|
import 'openai/core.mjs';
|
|
29
|
+
import '@zqagent/shared/model-capabilities';
|
|
30
|
+
|
|
31
|
+
interface ConfinementResult {
|
|
32
|
+
/** 命令行里所有路径是否都位于工作区内 */
|
|
33
|
+
confined: boolean;
|
|
34
|
+
/** 判定说明(放行原因 / 触发审批的原因) */
|
|
35
|
+
reason: string;
|
|
36
|
+
}
|
|
37
|
+
interface AssessOptions {
|
|
38
|
+
workspaceRoot: string;
|
|
39
|
+
/** 当前 shell 的 cwd;缺省按工作区根解析相对路径 */
|
|
40
|
+
cwd?: string;
|
|
41
|
+
platform?: NodeJS.Platform;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 判定一条命令是否只在工作区内操作。
|
|
45
|
+
*
|
|
46
|
+
* 阻断条件(任一命中即不自动放行):
|
|
47
|
+
* - 含命令替换 `$(...)` / 反引号;
|
|
48
|
+
* - 解释器内联代码(node -e、python -c、bash -c…);
|
|
49
|
+
* - 间接执行(eval / xargs / source / find -exec);
|
|
50
|
+
* - 系统级命令(sudo、systemctl、reg…);
|
|
51
|
+
* - 任一参数解析到工作区之外。
|
|
52
|
+
*/
|
|
53
|
+
declare function assessCommand(command: string, opts: AssessOptions): ConfinementResult;
|
|
54
|
+
|
|
55
|
+
/** 未配置白名单时的兜底命令前缀(只读类,命中免审) */
|
|
56
|
+
declare const DEFAULT_ALLOWED_COMMANDS: string[];
|
|
57
|
+
/** 项目级权限配置 */
|
|
58
|
+
interface PermissionConfig {
|
|
59
|
+
/** 启动时的运行模式(默认 interactive) */
|
|
60
|
+
mode: Mode;
|
|
61
|
+
/** shell 免审策略(默认 workspace:沙箱生效则免审,否则用工作区路径判定) */
|
|
62
|
+
shellPolicy: ShellPolicy;
|
|
63
|
+
/** 命令白名单(前缀匹配,词边界生效) */
|
|
64
|
+
allowedCommands: string[];
|
|
65
|
+
sandbox: {
|
|
66
|
+
/** auto:探测到就用;off:关闭;required:要求必须可用 */
|
|
67
|
+
mode: SandboxMode;
|
|
68
|
+
/** 额外可写路径(沙箱允许写工作区之外的这些目录) */
|
|
69
|
+
extraWritable: string[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 变更追踪:记录每个会话每轮改了什么,便于事后审计与回滚。
|
|
73
|
+
* auto 时优先用项目已有的 git,否则在 .agent/vcs 建影子仓库。
|
|
74
|
+
*/
|
|
75
|
+
vcs: {
|
|
76
|
+
mode: "auto" | "native" | "shadow" | "off";
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 读取并归一化配置。
|
|
81
|
+
*
|
|
82
|
+
* 所有字段独立回退:某一项非法不影响其余项,便于用户只写关心的部分。
|
|
83
|
+
*/
|
|
84
|
+
declare function loadPermissionConfig(workspace: string, env?: NodeJS.ProcessEnv): PermissionConfig;
|
|
18
85
|
|
|
19
86
|
/**
|
|
20
87
|
* ConsoleHook — 将引擎事件打印到控制台
|
|
@@ -145,7 +212,7 @@ declare class SubagentHook implements EngineHook {
|
|
|
145
212
|
onToolStarted(name: string): void;
|
|
146
213
|
onToolFinished(name: string, status: string, resultPreview: string): void;
|
|
147
214
|
onError(error: string): void;
|
|
148
|
-
onTurnEnd(status: string,
|
|
215
|
+
onTurnEnd(status: string, iterations: number, _producedFiles: string[]): void;
|
|
149
216
|
/**
|
|
150
217
|
* 打印子代理的最终报告。
|
|
151
218
|
*
|
|
@@ -257,122 +324,121 @@ declare class MarkdownRenderer {
|
|
|
257
324
|
}
|
|
258
325
|
|
|
259
326
|
/**
|
|
260
|
-
*
|
|
261
|
-
* 供 CLI、QQ、通用通知、邮件、MQTT、Web 等各端渲染成同一套表格。
|
|
327
|
+
* Agent 提示词的多语言形状。
|
|
262
328
|
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
329
|
+
* 每一组提示词(编程助手 / 通用协作 / 叙述 / 记忆 / 模式上下文 / 子代理 / 环境块 …)
|
|
330
|
+
* 在每种语言里都必须齐备:`Record<PromptLang, PromptSet>` 的约束会让漏翻在
|
|
331
|
+
* typecheck 阶段直接报错,而不是在运行时静默回退成中文。
|
|
332
|
+
*
|
|
333
|
+
* 约定:
|
|
334
|
+
* - 工具名、参数名、命令、路径、环境变量一律保持原样,不翻译。
|
|
335
|
+
* - 带插值的条目用函数表达(`explorerInstructions` / `envBlock`),
|
|
336
|
+
* 避免把 `${maxIterations}` 之类的占位符当普通文本翻译掉。
|
|
265
337
|
*/
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
338
|
+
/** 提示词语言,与界面语言一一对应 */
|
|
339
|
+
type PromptLang = "zh" | "en" | "zh-TW" | "ja" | "ko" | "es";
|
|
340
|
+
/** 全部支持的提示词语言(新增语言时同步 locales/ 与该数组) */
|
|
341
|
+
declare const PROMPT_LANGS: PromptLang[];
|
|
342
|
+
interface PromptSet {
|
|
343
|
+
/** 编程助手(code agent)的系统提示词主体 */
|
|
344
|
+
codeInstructions: string;
|
|
345
|
+
/** 通用协作(cowork agent)的系统提示词主体 */
|
|
346
|
+
coworkInstructions: string;
|
|
347
|
+
/** 每次工具调用前的进度叙述规则 */
|
|
348
|
+
narrationGuidance: string;
|
|
349
|
+
/** 跨会话持久记忆的使用规则 */
|
|
350
|
+
memoryGuidance: string;
|
|
351
|
+
/** 计划模式的上下文说明 */
|
|
352
|
+
planModeContext: string;
|
|
353
|
+
/** 讨论模式的上下文说明 */
|
|
354
|
+
discussModeContext: string;
|
|
355
|
+
/** 会话自动命名的提示词 */
|
|
356
|
+
genSessionNameInstructions: string;
|
|
357
|
+
/** MCP 工具引导 */
|
|
358
|
+
mcpGuidance: string;
|
|
359
|
+
/** OCR 工具引导 */
|
|
360
|
+
ocrGuidance: string;
|
|
361
|
+
/** 输出语言引导(让 agent 用用户所选语言回复) */
|
|
362
|
+
languageGuidance: string;
|
|
363
|
+
/** 只读探索子代理的提示词(含迭代预算插值) */
|
|
364
|
+
explorerInstructions(maxIterations: number): string;
|
|
365
|
+
/** 环境信息块(工作区 / 当前日期) */
|
|
366
|
+
envBlock(workspace: string, today: string): string;
|
|
367
|
+
/** 长对话压缩用的摘要系统提示词 */
|
|
368
|
+
summarySystemPrompt: string;
|
|
369
|
+
/** 压缩后续接的指令(作为最后一条用户消息注入) */
|
|
370
|
+
continuationContract: string;
|
|
371
|
+
/** Git 提交说明生成提示词 */
|
|
372
|
+
genCommitMessageInstructions: string;
|
|
272
373
|
}
|
|
273
|
-
/** 统一审批输入 */
|
|
274
|
-
interface ApprovalViewInput {
|
|
275
|
-
toolName: string;
|
|
276
|
-
reason: string;
|
|
277
|
-
arguments?: Record<string, unknown> | null;
|
|
278
|
-
}
|
|
279
|
-
/** 单个字段值的默认最大长度(超出以 … 截断) */
|
|
280
|
-
declare const APPROVAL_VALUE_MAX = 120;
|
|
281
|
-
/** 表格列标题(各端保持一致) */
|
|
282
|
-
declare const APPROVAL_COLUMNS: readonly ["项目", "详情"];
|
|
283
|
-
/** 从 NotifyEvent.data(审批事件负载)提取统一输入 */
|
|
284
|
-
declare function approvalInputFromData(data: Record<string, unknown>): ApprovalViewInput;
|
|
285
374
|
/**
|
|
286
|
-
*
|
|
375
|
+
* 浏览器/系统语言标签 → 提示词语言。
|
|
376
|
+
*
|
|
377
|
+
* 与 portal(src/lib/i18n.tsx)和官网(.vitepress/config.mts)的判定保持一致:
|
|
378
|
+
* 繁体区与显式 Hant 走繁中,其余中文走简中。
|
|
379
|
+
*/
|
|
380
|
+
declare function matchPromptLang(tag: string | undefined | null): PromptLang | null;
|
|
381
|
+
/** 把任意语言标识规整成受支持的提示词语言(不认识时回退简中) */
|
|
382
|
+
declare function normalizePromptLang(lang: string | undefined | null): PromptLang;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 各语言提示词集合。
|
|
386
|
+
*
|
|
387
|
+
* `Record<PromptLang, PromptSet>` 双重约束:
|
|
388
|
+
* - 少一个语言 → 类型报错
|
|
389
|
+
* - 某个语言缺字段 → 类型报错
|
|
390
|
+
* 因此不存在「漏翻后静默回退中文」的可能。
|
|
287
391
|
*/
|
|
288
|
-
declare function approvalFields(input: ApprovalViewInput, maxLen?: number): ApprovalField[];
|
|
289
|
-
/** 渲染为统一的两列 Markdown 表格 */
|
|
290
|
-
declare function approvalToMarkdownTable(input: ApprovalViewInput, opts?: {
|
|
291
|
-
maxLen?: number;
|
|
292
|
-
title?: string;
|
|
293
|
-
}): string;
|
|
294
|
-
/** 渲染为 HTML 表格(邮件 / Web 端直接展示为真正的表格) */
|
|
295
|
-
declare function approvalToHtmlTable(input: ApprovalViewInput, maxLen?: number): string;
|
|
296
392
|
|
|
297
|
-
|
|
298
|
-
interface SavedState {
|
|
299
|
-
sessionId: string;
|
|
300
|
-
model: string;
|
|
301
|
-
messages: Message[];
|
|
302
|
-
compaction: Record<string, unknown> | null;
|
|
303
|
-
savedAt: string;
|
|
304
|
-
/** 会话名称(AI 自动生成或用户指定) */
|
|
305
|
-
name?: string;
|
|
306
|
-
/** 名称来源:auto=自动生成(可被后续自动生成覆盖);user=用户手动指定(不再自动生成) */
|
|
307
|
-
nameSource?: "auto" | "user";
|
|
308
|
-
/** 已成功完成的任务数(用于第 1/3/5 次自动命名) */
|
|
309
|
-
taskCount?: number;
|
|
310
|
-
}
|
|
311
|
-
/** 会话命名相关的元数据(由 CLI 维护,随 state 快照持久化) */
|
|
312
|
-
interface SessionNameMeta {
|
|
313
|
-
name?: string;
|
|
314
|
-
nameSource?: "auto" | "user";
|
|
315
|
-
taskCount?: number;
|
|
316
|
-
}
|
|
317
|
-
declare class FileLogHook implements EngineHook {
|
|
318
|
-
private sessionId;
|
|
319
|
-
private _logPath;
|
|
320
|
-
private _statePath;
|
|
321
|
-
constructor(sessionId: string, stateDir: string);
|
|
322
|
-
onTurnStart(input: string): void;
|
|
323
|
-
onTurnEnd(status: string, iterations: number, producedFiles: string[]): void;
|
|
324
|
-
onAssistantDelta(_text: string): void;
|
|
325
|
-
onReasoningDelta(_text: string): void;
|
|
326
|
-
onAssistantMessage(text: string | null, toolCalls: string[], usage?: TokenUsage): void;
|
|
327
|
-
onToolProposed(name: string, args: Record<string, unknown>): void;
|
|
328
|
-
onToolStarted(name: string): void;
|
|
329
|
-
onToolFinished(name: string, status: string, resultPreview: string): void;
|
|
330
|
-
onPermissionRequired(name: string, reason: string): void;
|
|
331
|
-
onIterationEnd(iteration: number): void;
|
|
332
|
-
onCompacting(info?: CompactionStartInfo): void;
|
|
333
|
-
onCompacted(text: string, info?: CompactionDoneInfo): void;
|
|
334
|
-
onError(error: string, errorType: string): void;
|
|
335
|
-
onRetry(attempt: number, max: number, reason: string): void;
|
|
336
|
-
onInterrupted(iterations: number): void;
|
|
337
|
-
onPaused(iteration: number, at: string): void;
|
|
338
|
-
onResumed(iteration: number): void;
|
|
339
|
-
onEvent(type: EventType, data: Record<string, unknown>): void;
|
|
340
|
-
/** 保存完整引擎状态快照(检查点) */
|
|
341
|
-
saveState(engine: TurnEngine, meta?: SessionNameMeta): void;
|
|
342
|
-
/** 读取保存的引擎状态 */
|
|
343
|
-
static loadState(sessionId: string, stateDir: string): SavedState | null;
|
|
344
|
-
/** 读取事件日志 */
|
|
345
|
-
static loadEvents(sessionId: string, stateDir: string): Record<string, unknown>[];
|
|
346
|
-
/** 追加一行 JSON 事件 */
|
|
347
|
-
private _append;
|
|
348
|
-
}
|
|
393
|
+
declare const promptSets: Record<PromptLang, PromptSet>;
|
|
349
394
|
|
|
350
395
|
/**
|
|
351
396
|
* Agent 提示词(Prompt 模板)
|
|
352
397
|
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
398
|
+
* 提示词按语言分成多套,放在 ./locales/:简中、英语、繁中(台湾)、日语、韩语、
|
|
399
|
+
* 西班牙语。`Record<PromptLang, PromptSet>` 保证每套都齐全,漏翻在 typecheck
|
|
400
|
+
* 阶段就会报错。
|
|
401
|
+
*
|
|
402
|
+
* 语言的来源:界面语言(用户中心/控制台的语言选择)随会话创建时下发,
|
|
403
|
+
* 也支持 CLI 的 `--lang` 与环境变量;缺省为简体中文,保持既有行为不变。
|
|
404
|
+
*
|
|
405
|
+
* 工具名、参数名、命令、路径、标识符在所有语言里都保持原样——它们要和工具
|
|
406
|
+
* schema 对得上,翻译了模型就绑不到工具。
|
|
357
407
|
*/
|
|
408
|
+
|
|
409
|
+
/** 取指定语言的提示词集合(不认识的语言回退简中) */
|
|
410
|
+
declare function getPrompts(lang?: PromptLang | string | null): PromptSet;
|
|
358
411
|
/** Code Agent — 编程助手 */
|
|
359
|
-
declare const CODE_INSTRUCTIONS
|
|
412
|
+
declare const CODE_INSTRUCTIONS: string;
|
|
360
413
|
/** Cowork Agent — 通用协作助手 */
|
|
361
|
-
declare const COWORK_INSTRUCTIONS
|
|
414
|
+
declare const COWORK_INSTRUCTIONS: string;
|
|
362
415
|
/** Plan 模式上下文:写入和 shell 工具被阻止,只读探索并提交计划 */
|
|
363
|
-
declare const PLAN_MODE_CONTEXT
|
|
416
|
+
declare const PLAN_MODE_CONTEXT: string;
|
|
364
417
|
/** Discuss 模式上下文:写入和 shell 工具被禁用,只做对话式探讨 */
|
|
365
|
-
declare const DISCUSS_MODE_CONTEXT
|
|
366
|
-
/**
|
|
367
|
-
declare const
|
|
418
|
+
declare const DISCUSS_MODE_CONTEXT: string;
|
|
419
|
+
/** MCP 工具引导 */
|
|
420
|
+
declare const MCP_GUIDANCE: string;
|
|
421
|
+
/** OCR 工具引导 */
|
|
422
|
+
declare const OCR_GUIDANCE: string;
|
|
423
|
+
/** 环境信息块:告知模型工作区边界与当前日期(会话启动时快照) */
|
|
424
|
+
declare function buildEnvBlock(workspace: string, today: string, lang?: string | null): string;
|
|
425
|
+
/**
|
|
426
|
+
* 探索者提示词:只读代码探索者,最终消息即报告。
|
|
427
|
+
*
|
|
428
|
+
* 迭代预算必须写进提示词:子代理并不知道自己有轮次上限,缺少这段说明时它
|
|
429
|
+
* 会一路「继续搜下一个关键词」,直到撞上硬上限才被截断——报告往往来不及写。
|
|
430
|
+
*/
|
|
431
|
+
declare function buildExplorerInstructions(maxIterations: number, lang?: string | null): string;
|
|
368
432
|
/**
|
|
369
|
-
*
|
|
433
|
+
* 组装完整的系统提示词
|
|
370
434
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
435
|
+
* @param agentType 代理类型(code=编程助手 / cowork=通用协作)
|
|
436
|
+
* @param workspace 工作区路径(注入到环境信息块中)
|
|
437
|
+
* @param today 当前日期(ISO 格式,注入到环境信息块中)
|
|
438
|
+
* @param lang 界面语言(缺省简中)
|
|
439
|
+
* @returns 拼接后的完整系统提示词(代理提示词 + 叙述规则 + MCP/OCR/语言引导 + 环境信息)
|
|
373
440
|
*/
|
|
374
|
-
declare function
|
|
375
|
-
declare function buildInstructions(agentType: "code" | "cowork", workspace: string, today: string): string;
|
|
441
|
+
declare function buildInstructions(agentType: "code" | "cowork", workspace: string, today: string, lang?: string | null): string;
|
|
376
442
|
|
|
377
443
|
/**
|
|
378
444
|
* Agent 注册表(AgentRegistry)
|
|
@@ -394,7 +460,7 @@ interface AgentDef {
|
|
|
394
460
|
prompt: string;
|
|
395
461
|
/**
|
|
396
462
|
* 可选:切换到此 agent 时同步切换的模型标识
|
|
397
|
-
* (如 "
|
|
463
|
+
* (如 "your-model")。未设置则沿用当前模型。
|
|
398
464
|
*/
|
|
399
465
|
model?: string;
|
|
400
466
|
}
|
|
@@ -446,98 +512,35 @@ declare class AgentRegistry {
|
|
|
446
512
|
switch(name: string): AgentDef | undefined;
|
|
447
513
|
/**
|
|
448
514
|
* 为指定 agent 组装完整系统提示词:
|
|
449
|
-
* agent prompt + 叙述规则 + OCR/语言引导 + 环境信息块。
|
|
515
|
+
* agent prompt + 叙述规则 + MCP/OCR/语言引导 + 环境信息块。
|
|
516
|
+
*
|
|
517
|
+
* 内置角色(code / cowork)的 prompt 按 `lang` 取对应语言那一套;
|
|
518
|
+
* 自定义 agent 的 prompt 原样保留,只有通用规则与环境块跟随语言。
|
|
450
519
|
*
|
|
451
520
|
* @param name agent 名称(不存在时回退到当前 agent)
|
|
452
521
|
* @param workspace 工作区路径(注入环境信息块)
|
|
453
522
|
* @param today 当前日期(ISO 格式,注入环境信息块)
|
|
523
|
+
* @param lang 界面语言(缺省简体中文)
|
|
454
524
|
*/
|
|
455
|
-
buildSystemPrompt(name: string, workspace: string, today: string): string;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* MCP 客户端(McpClient)
|
|
460
|
-
*
|
|
461
|
-
* 基于 @modelcontextprotocol/sdk 封装单个 MCP 服务器的连接与工具调用,
|
|
462
|
-
* 支持两种传输:
|
|
463
|
-
* - stdio:本地子进程(如 `npx -y @some/mcp-server`)
|
|
464
|
-
* - http :远程 streamable HTTP 端点
|
|
465
|
-
*
|
|
466
|
-
* 提供工具列表拉取、工具调用(结果归一化为文本)、连接生命周期管理,
|
|
467
|
-
* 以及 OpenAI 工具名兼容的命名工具(sanitize + 前缀)。
|
|
468
|
-
*/
|
|
469
|
-
/** MCP 服务器配置 */
|
|
470
|
-
interface McpServerConfig {
|
|
471
|
-
/** 服务器名称(唯一标识,也是注册到 ToolRegistry 的工具名前缀) */
|
|
472
|
-
name: string;
|
|
473
|
-
/** 传输类型:stdio=本地子进程 / http=远程端点 */
|
|
474
|
-
type: "stdio" | "http";
|
|
475
|
-
/** stdio 传输:启动命令,如 ["npx","-y","@modelcontextprotocol/server-filesystem","/tmp"] */
|
|
476
|
-
command?: string[];
|
|
477
|
-
/** http 传输:远程端点 URL */
|
|
478
|
-
url?: string;
|
|
479
|
-
/** http 传输:自定义请求头(如 Authorization) */
|
|
480
|
-
headers?: Record<string, string>;
|
|
481
|
-
/** stdio 传输:子进程环境变量 */
|
|
482
|
-
env?: Record<string, string>;
|
|
483
|
-
/** 是否启用(默认 true;禁用时不连接、不注册工具) */
|
|
484
|
-
enabled?: boolean;
|
|
485
|
-
}
|
|
486
|
-
/** 从服务器拉取到的单个工具信息 */
|
|
487
|
-
interface McpToolInfo {
|
|
488
|
-
/** 原始工具名(未加前缀) */
|
|
489
|
-
name: string;
|
|
490
|
-
description?: string;
|
|
491
|
-
/** JSON Schema 参数定义 */
|
|
492
|
-
inputSchema: Record<string, unknown>;
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* 工具名净化:OpenAI 工具名仅允许 [a-zA-Z0-9_-],
|
|
496
|
-
* 其余字符替换为 `_` 并截断到 maxLen。
|
|
497
|
-
* 净化后不含任何字母/数字(纯符号)时回退为 "tool"。
|
|
498
|
-
*/
|
|
499
|
-
declare function sanitizeToolName(name: string, maxLen?: number): string;
|
|
500
|
-
/**
|
|
501
|
-
* 注册到 ToolRegistry 的完整工具键:
|
|
502
|
-
* `mcp__<server>__<tool>`(server 与 tool 均净化,避免冲突与非法字符)
|
|
503
|
-
*/
|
|
504
|
-
declare function mcpToolKey(server: string, tool: string): string;
|
|
505
|
-
declare class McpClient {
|
|
506
|
-
readonly config: McpServerConfig;
|
|
507
|
-
private client;
|
|
508
|
-
private transport;
|
|
509
|
-
private _tools;
|
|
510
|
-
constructor(config: McpServerConfig);
|
|
511
|
-
get name(): string;
|
|
512
|
-
get connected(): boolean;
|
|
513
|
-
/**
|
|
514
|
-
* 建立连接并拉取工具列表。
|
|
515
|
-
* 已连接时幂等(直接返回)。
|
|
516
|
-
*/
|
|
517
|
-
connect(): Promise<void>;
|
|
518
|
-
/** 当前服务器提供的工具列表(副本) */
|
|
519
|
-
listTools(): McpToolInfo[];
|
|
520
|
-
/**
|
|
521
|
-
* 调用工具,把 MCP 结果归一化为文本(或错误对象)。
|
|
522
|
-
*
|
|
523
|
-
* 服务器返回 isError=true 时不抛异常,而是返回
|
|
524
|
-
* `{ error, isError: true }`,让模型看到错误信息继续处理。
|
|
525
|
-
*/
|
|
526
|
-
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
527
|
-
/** 关闭连接,释放子进程/HTTP 会话 */
|
|
528
|
-
close(): Promise<void>;
|
|
525
|
+
buildSystemPrompt(name: string, workspace: string, today: string, lang?: string | null): string;
|
|
529
526
|
}
|
|
530
527
|
|
|
531
528
|
/**
|
|
532
529
|
* MCP 管理器(McpManager)
|
|
533
530
|
*
|
|
534
|
-
* 管理多个 MCP 服务器(stdio / http)的配置与连接生命周期,
|
|
531
|
+
* 管理多个 MCP 服务器(stdio / http / sse / builtin)的配置与连接生命周期,
|
|
535
532
|
* 并负责把各服务器的工具动态注入到 ToolRegistry(带 `mcp__<server>__<tool>`
|
|
536
533
|
* 前缀),支持运行时增删改查与刷新 —— 引擎每次请求都实时拉取
|
|
537
534
|
* registry.schemas(),因此工具的注入/替换/移除对下一次 LLM 调用立即生效。
|
|
538
535
|
*
|
|
536
|
+
* 按需加载(lazy):
|
|
537
|
+
* 当工具总数或 schema 体积超过阈值时,不再全量下发所有 `mcp__*` 工具,
|
|
538
|
+
* 改为下发 `mcp_search_tools`(检索)与 `mcp_call_tool`(调用)两个元工具,
|
|
539
|
+
* 并在检索命中后渐进注册真实工具(下一轮可直接调用)。
|
|
540
|
+
* 小规模场景保持全量注入,行为与旧版一致。
|
|
541
|
+
*
|
|
539
542
|
* 与 AgentRegistry 一致:本类只做内存管理,持久化(如 .agent/mcp.json)
|
|
540
|
-
* 由调用方(CLI)负责。
|
|
543
|
+
* 由调用方(CLI / server)负责。
|
|
541
544
|
*/
|
|
542
545
|
|
|
543
546
|
/** connectAll / refresh 的结果统计 */
|
|
@@ -548,13 +551,44 @@ interface McpConnectResult {
|
|
|
548
551
|
error: string;
|
|
549
552
|
}[];
|
|
550
553
|
}
|
|
554
|
+
/** 按需加载配置 */
|
|
555
|
+
interface McpLazyOptions {
|
|
556
|
+
/** true=强制启用;false=强制关闭;缺省=按阈值自动判断 */
|
|
557
|
+
enabled?: boolean;
|
|
558
|
+
/** 工具数量阈值(默认 16) */
|
|
559
|
+
thresholdTools?: number;
|
|
560
|
+
/** schema 字符数阈值(默认 24000) */
|
|
561
|
+
thresholdChars?: number;
|
|
562
|
+
/** 懒模式下单会话最多自动加载的工具数(默认 40) */
|
|
563
|
+
maxLoaded?: number;
|
|
564
|
+
}
|
|
565
|
+
/** McpManager 构造选项 */
|
|
566
|
+
interface McpManagerOptions {
|
|
567
|
+
/** 内置服务器上下文(workspace / env / LLM 兜底) */
|
|
568
|
+
builtin?: McpBuiltinContext;
|
|
569
|
+
/** 按需加载配置 */
|
|
570
|
+
lazy?: McpLazyOptions;
|
|
571
|
+
}
|
|
572
|
+
/** 懒加载元工具:检索 */
|
|
573
|
+
declare const MCP_SEARCH_TOOL = "mcp_search_tools";
|
|
574
|
+
/** 懒加载元工具:调用 */
|
|
575
|
+
declare const MCP_CALL_TOOL = "mcp_call_tool";
|
|
551
576
|
declare class McpManager {
|
|
552
577
|
private registry;
|
|
553
578
|
private configs;
|
|
554
579
|
private clients;
|
|
555
580
|
/** server → 已注册到 ToolRegistry 的工具 key 列表 */
|
|
556
581
|
private registeredTools;
|
|
557
|
-
|
|
582
|
+
/** server → 该服务器提供的全部工具(连接时拉取) */
|
|
583
|
+
private toolIndex;
|
|
584
|
+
/** 当前实际注册到 registry 的全部 key(含元工具) */
|
|
585
|
+
private injectedKeys;
|
|
586
|
+
/** 懒模式下已加载的真实工具 key */
|
|
587
|
+
private loadedKeys;
|
|
588
|
+
private lazyActive;
|
|
589
|
+
private metaRegistered;
|
|
590
|
+
private options;
|
|
591
|
+
constructor(registry: ToolRegistry, configs?: McpServerConfig[], options?: McpManagerOptions);
|
|
558
592
|
/**
|
|
559
593
|
* 更换关联的 ToolRegistry(如 CLI 清空会话后引擎重建)。
|
|
560
594
|
* 会把已连接服务器的工具从旧 registry 卸载、注册到新 registry,
|
|
@@ -591,18 +625,321 @@ declare class McpManager {
|
|
|
591
625
|
refresh(name?: string): Promise<McpConnectResult>;
|
|
592
626
|
/** 关闭全部连接并卸载全部 MCP 工具 */
|
|
593
627
|
closeAll(): Promise<void>;
|
|
594
|
-
/** 某服务器注入到 ToolRegistry 的工具 key
|
|
628
|
+
/** 某服务器注入到 ToolRegistry 的工具 key 列表(懒模式下为已加载的) */
|
|
595
629
|
serverToolKeys(server: string): string[];
|
|
596
|
-
/**
|
|
630
|
+
/** 某服务器提供的工具总数(连接时索引) */
|
|
631
|
+
serverToolTotal(server: string): number;
|
|
632
|
+
/** 全部 MCP 注入的工具 key(不含元工具) */
|
|
597
633
|
allToolKeys(): string[];
|
|
634
|
+
/** 是否处于按需加载模式 */
|
|
635
|
+
isLazyActive(): boolean;
|
|
636
|
+
/** 已索引的 MCP 工具总数(连接时) */
|
|
637
|
+
indexedToolCount(): number;
|
|
598
638
|
/** 服务器是否已连接 */
|
|
599
639
|
isConnected(name: string): boolean;
|
|
600
|
-
/**
|
|
640
|
+
/** 记录服务器工具索引,并按当前模式重建注入 */
|
|
601
641
|
private registerServerTools;
|
|
642
|
+
/**
|
|
643
|
+
* 应用注册模式:
|
|
644
|
+
* - 模式未变化:全量模式下增量重注册;懒模式下只确保元工具存在
|
|
645
|
+
* - 模式变化:清空后重建(懒模式已加载工具需重新检索,属预期)
|
|
646
|
+
*/
|
|
647
|
+
private applyRegistrationMode;
|
|
648
|
+
/** 根据配置 / 环境变量 / 阈值判断是否启用按需加载 */
|
|
649
|
+
private shouldUseLazy;
|
|
650
|
+
/** 注册单个真实工具 */
|
|
651
|
+
private registerOneTool;
|
|
602
652
|
/** 从 ToolRegistry 卸载某服务器全部工具 */
|
|
603
|
-
private
|
|
653
|
+
private removeServerToolKeys;
|
|
654
|
+
/** 卸载当前注入的全部工具(含元工具) */
|
|
655
|
+
private clearInjected;
|
|
656
|
+
private registerMetaTools;
|
|
657
|
+
private removeMetaTools;
|
|
658
|
+
/** 懒模式:加载单个工具到 registry(受 maxLoaded 限制) */
|
|
659
|
+
private loadTool;
|
|
660
|
+
private loadToolByKey;
|
|
661
|
+
/** mcp_search_tools 实现 */
|
|
662
|
+
private searchTools;
|
|
663
|
+
/** 按名称查找工具(完整 key / 原始名 / server/tool) */
|
|
664
|
+
private findTool;
|
|
665
|
+
/** mcp_call_tool 实现 */
|
|
666
|
+
private callToolViaMeta;
|
|
604
667
|
}
|
|
605
668
|
|
|
669
|
+
/** 追踪模式 */
|
|
670
|
+
type VcsMode = "native" | "shadow" | "off";
|
|
671
|
+
/** 配置取值:auto 表示自动探测 */
|
|
672
|
+
type VcsConfigMode = "auto" | "native" | "shadow" | "off";
|
|
673
|
+
/** 解析后的方案 */
|
|
674
|
+
interface VcsPlan {
|
|
675
|
+
mode: VcsMode;
|
|
676
|
+
/** 工作区绝对路径 */
|
|
677
|
+
workTree: string;
|
|
678
|
+
/** git 目录绝对路径;mode=off 时为 null */
|
|
679
|
+
gitDir: string | null;
|
|
680
|
+
/** 状态说明(供日志 / 命令输出) */
|
|
681
|
+
reason: string;
|
|
682
|
+
}
|
|
683
|
+
/** 一轮的提交记录 */
|
|
684
|
+
interface TurnCommit {
|
|
685
|
+
/**
|
|
686
|
+
* 快照序号(从 1 开始,按本会话提交顺序)。
|
|
687
|
+
* `commitTurn()` 的返回值里为 0——序号由 `listTurns()` 统一给出,
|
|
688
|
+
* 提交时再算一次只会多花一次 git 调用。
|
|
689
|
+
*/
|
|
690
|
+
turn: number;
|
|
691
|
+
/** commit sha */
|
|
692
|
+
commit: string;
|
|
693
|
+
/** 提交时间(ISO) */
|
|
694
|
+
ts: string;
|
|
695
|
+
/** 本轮改动涉及的文件(工作区相对路径) */
|
|
696
|
+
files: string[];
|
|
697
|
+
/** 本轮结束状态(completed / interrupted / error …) */
|
|
698
|
+
status: string;
|
|
699
|
+
}
|
|
700
|
+
/** 影子仓库目录(相对工作区) */
|
|
701
|
+
declare const SHADOW_DIR: string;
|
|
702
|
+
interface ResolveVcsOptions {
|
|
703
|
+
/** auto(默认)/ native / shadow / off */
|
|
704
|
+
mode?: VcsConfigMode;
|
|
705
|
+
platform?: NodeJS.Platform;
|
|
706
|
+
/** 是否探测到 git 可执行文件(测试注入) */
|
|
707
|
+
gitAvailable?: () => boolean;
|
|
708
|
+
}
|
|
709
|
+
/** 探测一个目录是否是 git 仓库根(`.git` 为目录或文件均可) */
|
|
710
|
+
declare function isGitRepo(dir: string): boolean;
|
|
711
|
+
/**
|
|
712
|
+
* 解析当前工作区该用哪种追踪方式。
|
|
713
|
+
*
|
|
714
|
+
* - `off`:显式关闭
|
|
715
|
+
* - `native`:项目本身是 git 仓库
|
|
716
|
+
* - `shadow`:项目不是 git 仓库(或用户显式要求)
|
|
717
|
+
* - 自动模式:优先 native,其次 shadow
|
|
718
|
+
*/
|
|
719
|
+
declare function resolveVcsPlan(workspace: string, opts?: ResolveVcsOptions): VcsPlan;
|
|
720
|
+
/** 会话的 git ref 名 */
|
|
721
|
+
declare function agentRef(sessionId: string): string;
|
|
722
|
+
/** 会话的独立 index 路径(避免与用户暂存区互相破坏) */
|
|
723
|
+
declare function sessionIndexPath(plan: VcsPlan, sessionId: string): string;
|
|
724
|
+
|
|
725
|
+
/** 恢复结果 */
|
|
726
|
+
interface RestoreResult {
|
|
727
|
+
/** 实际写回的文件(工作区相对路径) */
|
|
728
|
+
restored: string[];
|
|
729
|
+
/** 写回前内容与快照不同的文件(即真正被改动覆盖的) */
|
|
730
|
+
overwritten: string[];
|
|
731
|
+
/** 该轮里没有该文件(被删除或路径写错) */
|
|
732
|
+
missing: string[];
|
|
733
|
+
}
|
|
734
|
+
declare class SessionVcs {
|
|
735
|
+
readonly plan: VcsPlan;
|
|
736
|
+
readonly sessionId: string;
|
|
737
|
+
private readonly ref;
|
|
738
|
+
private readonly index;
|
|
739
|
+
private readonly shadowDir;
|
|
740
|
+
/**
|
|
741
|
+
* 排除规则文件,通过 `-c core.excludesFile` 传给 git。
|
|
742
|
+
*
|
|
743
|
+
* 不用 pathspec `:(exclude).agent`:当 `.agent` 同时被忽略规则覆盖时,
|
|
744
|
+
* git add 会直接报 "paths are ignored by one of your .gitignore files" 而失败。
|
|
745
|
+
* 也不用仓库级 .gitignore:不能改用户的文件。
|
|
746
|
+
*/
|
|
747
|
+
private readonly excludeFile;
|
|
748
|
+
/** 串行队列:保证同一会话的 git 操作不并发 */
|
|
749
|
+
private queue;
|
|
750
|
+
private readyOnce;
|
|
751
|
+
constructor(plan: VcsPlan, sessionId: string);
|
|
752
|
+
get enabled(): boolean;
|
|
753
|
+
/** 串行执行;失败不污染队列(否则一次失败会卡死后续操作) */
|
|
754
|
+
private enqueue;
|
|
755
|
+
/**
|
|
756
|
+
* 初始化(幂等,必须在队列内调用)。
|
|
757
|
+
*
|
|
758
|
+
* shadow 模式要做两件事:建裸仓库、写 `info/exclude`。后者不能省:
|
|
759
|
+
* 影子仓库的对象库就在工作区内的 `.agent/vcs`,不排除会把自己也提交进去。
|
|
760
|
+
*/
|
|
761
|
+
private ensureReadyUnlocked;
|
|
762
|
+
/** 取当前 ref 指向的提交;还没有提交时返回 null */
|
|
763
|
+
private headCommitUnlocked;
|
|
764
|
+
/**
|
|
765
|
+
* 在本轮改动发生**之前**记一个基线。
|
|
766
|
+
*
|
|
767
|
+
* 没有基线时,首个快照是 root commit,会把工作区里所有已有文件都算作
|
|
768
|
+
* 「本会话的改动」——多会话共享工作区时,A 会在自己的第一轮里看到 B 的文件,
|
|
769
|
+
* `/changes` 的语义就错了。所以基线要在 turn 开始(工具执行前)建立,
|
|
770
|
+
* 之后每个快照的 diff 才是该会话真实的改动。
|
|
771
|
+
*
|
|
772
|
+
* 幂等:已有 ref 就直接返回。
|
|
773
|
+
*/
|
|
774
|
+
beginTurn(): Promise<void>;
|
|
775
|
+
/**
|
|
776
|
+
* 记录本轮结束时的快照。
|
|
777
|
+
*
|
|
778
|
+
* 返回 null 表示「没有可提交的改动」或追踪未启用——纯问答的一轮不产生
|
|
779
|
+
* 提交是正常的,不算错误。
|
|
780
|
+
*
|
|
781
|
+
* 不接受轮次编号:快照是按「有改动的轮次」顺序排列的,`listTurns()`
|
|
782
|
+
* 返回的序号即快照序号。若把对话轮次也写进编号,两者会因空轮次而错位。
|
|
783
|
+
*/
|
|
784
|
+
commitTurn(status: string): Promise<TurnCommit | null>;
|
|
785
|
+
/** 某提交相对其 parent 改动/新增/删除的文件 */
|
|
786
|
+
private filesOfUnlocked;
|
|
787
|
+
/** 从提交消息里读回 status / ts(由 commitTurn 写入) */
|
|
788
|
+
private readMessageUnlocked;
|
|
789
|
+
/** 列出本会话的全部轮次提交(从早到晚,turn 从 1 开始) */
|
|
790
|
+
private listTurnsUnlocked;
|
|
791
|
+
/** 公开:列出轮次 */
|
|
792
|
+
listTurns(): Promise<TurnCommit[]>;
|
|
793
|
+
/** 某一轮的完整 patch(用于 /changes 展开查看) */
|
|
794
|
+
diffTurn(turn: number): Promise<string>;
|
|
795
|
+
/** 读取某提交里某个文件的内容;不存在返回 null */
|
|
796
|
+
private fileAtUnlocked;
|
|
797
|
+
/**
|
|
798
|
+
* 把某一轮的文件恢复到工作区(按文件粒度)。
|
|
799
|
+
*
|
|
800
|
+
* 用途:某会话的改动被覆盖了,从它的快照里挑回需要的文件。
|
|
801
|
+
* 语义是「恢复」,所以默认覆盖当前内容;会把「内容确实变了」的文件记入
|
|
802
|
+
* `overwritten`,并支持 `dryRun` 先看会改动哪些文件。
|
|
803
|
+
* 只做文件级恢复,不做行级合并——行级冲突交给人和 git。
|
|
804
|
+
*/
|
|
805
|
+
restoreTurn(turn: number, opts?: {
|
|
806
|
+
paths?: string[];
|
|
807
|
+
dryRun?: boolean;
|
|
808
|
+
}): Promise<RestoreResult>;
|
|
809
|
+
/** 丢掉本会话的追踪记录(不还原文件) */
|
|
810
|
+
forget(): Promise<boolean>;
|
|
811
|
+
/** 等排队的操作全部完成(退出前调用,保证快照落盘) */
|
|
812
|
+
flush(): Promise<void>;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* VcsHook — 把引擎生命周期接到变更追踪
|
|
817
|
+
*
|
|
818
|
+
* 只在 turn 结束时记一次快照,不在每次工具调用时记:一轮里模型可能改十几个
|
|
819
|
+
* 文件、又反复调整,逐个记会产生大量无意义提交,也让「回滚到某一轮」变得难选。
|
|
820
|
+
*
|
|
821
|
+
* EngineHook 的回调是同步签名,而 git 操作是异步的。这里用内部队列
|
|
822
|
+
* 串行接住(不阻塞主流程),并提供 `flush()` 在退出/查询前等待落盘。
|
|
823
|
+
* 快照失败不抛异常——追踪是旁路能力,不能因为它让对话失败。
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
declare class VcsHook implements EngineHook {
|
|
827
|
+
readonly vcs: SessionVcs;
|
|
828
|
+
/** 最近一次失败原因(供 /vcs 展示,避免静默失效) */
|
|
829
|
+
lastError: string | null;
|
|
830
|
+
/** 最近一次成功提交 */
|
|
831
|
+
lastCommit: TurnCommit | null;
|
|
832
|
+
constructor(vcs: SessionVcs);
|
|
833
|
+
onTurnStart(): void;
|
|
834
|
+
onTurnEnd(status: string): void;
|
|
835
|
+
/** 等待排队中的快照全部落盘 */
|
|
836
|
+
flush(): Promise<void>;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
interface GitResult {
|
|
840
|
+
status: number | null;
|
|
841
|
+
stdout: string;
|
|
842
|
+
stderr: string;
|
|
843
|
+
/** 启动失败(git 不存在等) */
|
|
844
|
+
error?: string;
|
|
845
|
+
}
|
|
846
|
+
interface GitRunOptions {
|
|
847
|
+
/** 独立 index 文件路径;不传则用 git 默认 index */
|
|
848
|
+
index?: string;
|
|
849
|
+
/** 覆盖工作目录(默认 workTree) */
|
|
850
|
+
cwd?: string;
|
|
851
|
+
/** 写入 stdin(如 commit 消息) */
|
|
852
|
+
input?: string;
|
|
853
|
+
timeoutMs?: number;
|
|
854
|
+
/**
|
|
855
|
+
* 不注入 GIT_DIR / GIT_WORK_TREE。
|
|
856
|
+
*
|
|
857
|
+
* `git init --bare <dir>` 会因为已存在的 GIT_WORK_TREE 直接报
|
|
858
|
+
* `fatal: GIT_WORK_TREE not allowed without specifying GIT_DIR`,
|
|
859
|
+
* 所以初始化必须走这个模式。
|
|
860
|
+
*/
|
|
861
|
+
isolated?: boolean;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* 执行一条 git 命令。
|
|
865
|
+
*
|
|
866
|
+
* 失败不抛异常——调用方需要区分「没有提交」「有冲突」「git 不可用」,
|
|
867
|
+
* 统一按 status/stderr 判断比 try/catch 更好组合。
|
|
868
|
+
*/
|
|
869
|
+
declare function runGit(plan: VcsPlan, args: string[], opts?: GitRunOptions): Promise<GitResult>;
|
|
870
|
+
/** 成功判断:status === 0 */
|
|
871
|
+
declare function gitOk(r: GitResult): boolean;
|
|
872
|
+
/** 取 stderr/stdout 的首行,用于错误提示 */
|
|
873
|
+
declare function gitMessage(r: GitResult): string;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* 终端工具(控制台「终端」面板的长驻会话 → Agent 的只读上下文)
|
|
877
|
+
*
|
|
878
|
+
* ## 为什么是「只读」
|
|
879
|
+
*
|
|
880
|
+
* 终端和 `run_shell` 是两套东西(见 `server/terminals/TerminalManager.ts` 文件头):
|
|
881
|
+
* 前者是用户手敲的长驻 PTY,shell 自己在回显与行编辑;后者是一次性命令、结果进对话。
|
|
882
|
+
*
|
|
883
|
+
* 让 Agent 往 PTY 写字节等于把用户正在敲的半行打断、还要和 readline / 全屏 TUI
|
|
884
|
+
* 抢状态机——没有结构化边界,失败方式不可预期。因此这里只提供**读取**:
|
|
885
|
+
* 用户跑挂了什么、终端里刷出了什么报错,Agent 自己能看见就够了。
|
|
886
|
+
*
|
|
887
|
+
* 写回需要走别的通道(由用户在界面上确认后执行),不在本模块。
|
|
888
|
+
*
|
|
889
|
+
* ## 两条容易踩的坑
|
|
890
|
+
*
|
|
891
|
+
* 1. **终端历史会过期**。用户可能十分钟前 `cd` 过、文件也改过了。所以工具描述里
|
|
892
|
+
* 明确写了「终端内容可能过期,工作区真实状态以文件工具 / run_shell 为准」。
|
|
893
|
+
* 2. **内容是明文**。终端里可能打印过 token、连接串。这里做一层轻量掩码
|
|
894
|
+
* (`maskSecrets`),但它**不是安全边界**,只是降低误传概率。
|
|
895
|
+
*/
|
|
896
|
+
|
|
897
|
+
/** 终端元信息(`TerminalManager.list()` 的一项,只取本模块用到的字段) */
|
|
898
|
+
interface TerminalMetaView {
|
|
899
|
+
id: string;
|
|
900
|
+
label: string;
|
|
901
|
+
projectId: string;
|
|
902
|
+
cwd: string;
|
|
903
|
+
status: "running" | "exited";
|
|
904
|
+
lastActiveAt: string;
|
|
905
|
+
exitCode?: number | null;
|
|
906
|
+
pty?: boolean;
|
|
907
|
+
}
|
|
908
|
+
/** 历史记录的一行(`TerminalManager.history()`) */
|
|
909
|
+
interface TerminalRecordView {
|
|
910
|
+
t: "cmd" | "out" | "exit";
|
|
911
|
+
ts: string;
|
|
912
|
+
cmd?: string;
|
|
913
|
+
data?: string;
|
|
914
|
+
code?: number | null;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* 终端工具依赖的最小能力面。
|
|
918
|
+
*
|
|
919
|
+
* 刻意用结构类型而不是直接 import `TerminalManager`:tools 层不反向依赖
|
|
920
|
+
* server/terminals 的具体实现,测试里也能传一个假实现。
|
|
921
|
+
*/
|
|
922
|
+
interface TerminalSource {
|
|
923
|
+
list(projectId?: string): TerminalMetaView[];
|
|
924
|
+
get(terminalId: string): TerminalMetaView | null;
|
|
925
|
+
isRunning(terminalId: string): boolean;
|
|
926
|
+
/** 回放缓冲(运行中的终端;已退出的返回空串) */
|
|
927
|
+
replayOutput(terminalId: string): string;
|
|
928
|
+
history(terminalId: string, opts?: {
|
|
929
|
+
limit?: number;
|
|
930
|
+
}): Promise<TerminalRecordView[]>;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* 注册终端只读工具。
|
|
934
|
+
*
|
|
935
|
+
* @param projectId 当前会话所属项目。终端管理器是节点级单例,必须按它做隔离,
|
|
936
|
+
* 否则 A 项目的会话能读到 B 项目终端里的内容(跨租户泄漏)。
|
|
937
|
+
*/
|
|
938
|
+
declare function registerTerminalTools(registry: ToolRegistry, opts: {
|
|
939
|
+
terminals: TerminalSource;
|
|
940
|
+
projectId: string;
|
|
941
|
+
}): void;
|
|
942
|
+
|
|
606
943
|
/** 二进制的来源(用于错误信息与文档,也便于诊断「为什么用的是那个」) */
|
|
607
944
|
type BinSource = "env" | "agent-bin" | "bundled" | "path";
|
|
608
945
|
interface ResolvedBin {
|
|
@@ -682,6 +1019,7 @@ declare function downloadFfmpeg(workspace: string, opts?: DownloadOptions): Prom
|
|
|
682
1019
|
* 方式一(一键装配):
|
|
683
1020
|
* import { createDefaultEngine, Mode } from "@zqagent/core";
|
|
684
1021
|
* const engine = createDefaultEngine({ workspace: ".", mode: Mode.AUTO });
|
|
1022
|
+
* engine.setApprover(async () => ApprovalOutcome.ONCE); // 见 docs/embedding.md
|
|
685
1023
|
*
|
|
686
1024
|
* 方式二(完全自定义):
|
|
687
1025
|
* import { TurnEngine, ToolRegistry, PermissionEngine, OpenAIProvider, Mode } from "@zqagent/core";
|
|
@@ -689,20 +1027,26 @@ declare function downloadFfmpeg(workspace: string, opts?: DownloadOptions): Prom
|
|
|
689
1027
|
* const registry = new ToolRegistry();
|
|
690
1028
|
* // ... 注册自定义工具
|
|
691
1029
|
* const permissions = new PermissionEngine({ workspaceRoot: ".", mode: Mode.AUTO });
|
|
692
|
-
* const engine = new TurnEngine({ provider, registry, permissions, model: "
|
|
1030
|
+
* const engine = new TurnEngine({ provider, registry, permissions, model: "your-model", instructions: "..." });
|
|
693
1031
|
*/
|
|
694
1032
|
|
|
695
1033
|
/** createDefaultEngine 参数 */
|
|
696
1034
|
interface CreateEngineOpts {
|
|
697
1035
|
/** 工作区根目录 */
|
|
698
1036
|
workspace: string;
|
|
699
|
-
/**
|
|
1037
|
+
/**
|
|
1038
|
+
* 模型标识(缺省取环境变量 OPENAI_MODEL)。
|
|
1039
|
+
*
|
|
1040
|
+
* 都没有时留空,**不会**兜底成某个厂商的具体型号:早先写死 `gpt-4o`,
|
|
1041
|
+
* 用户既没配供应商也没这个型号的 Key,第一轮请求必然失败,还让人以为
|
|
1042
|
+
* 系统已经替他选好了。空模型在 `TurnEngine.run()` 处给出明确报错。
|
|
1043
|
+
*/
|
|
700
1044
|
model?: string;
|
|
701
1045
|
/** LLM Provider(缺省时自动创建 OpenAIProvider) */
|
|
702
1046
|
provider?: ProviderClient;
|
|
703
1047
|
/** 运行模式(默认 INTERACTIVE) */
|
|
704
1048
|
mode?: Mode;
|
|
705
|
-
/**
|
|
1049
|
+
/** 单轮最大迭代次数(缺省用 DEFAULT_MAX_ITERATIONS) */
|
|
706
1050
|
maxIterations?: number;
|
|
707
1051
|
/**
|
|
708
1052
|
* 推理强度(可选)。缺省时取环境变量 OPENAI_REASONING_EFFORT
|
|
@@ -712,10 +1056,36 @@ interface CreateEngineOpts {
|
|
|
712
1056
|
reasoningEffort?: ReasoningEffort;
|
|
713
1057
|
/** 命令白名单(Auto 模式下自动放行的命令前缀,默认空数组) */
|
|
714
1058
|
allowedCommands?: string[];
|
|
1059
|
+
/**
|
|
1060
|
+
* shell 免审策略(默认 approve,保持既有语义)。
|
|
1061
|
+
* workspace / sandbox 需配合 `sandbox` 使用:沙箱生效时工作区内的
|
|
1062
|
+
* 命令不再逐条审批;沙箱不可用时 workspace 退化为路径判定。
|
|
1063
|
+
*/
|
|
1064
|
+
shellPolicy?: ShellPolicy;
|
|
1065
|
+
/** OS 级沙箱配置(默认 auto:探测到 sandbox-exec / bwrap 就启用) */
|
|
1066
|
+
sandbox?: SandboxOptions;
|
|
1067
|
+
/**
|
|
1068
|
+
* 变更追踪(默认 **off**,不改变既有行为)。
|
|
1069
|
+
* 启用后每轮结束记一个快照;多会话共享工作区时用它审计与回滚。
|
|
1070
|
+
* CLI 与 server 各自装配(要按会话区分 ref),这里供嵌入式调用方显式开启。
|
|
1071
|
+
*/
|
|
1072
|
+
vcs?: {
|
|
1073
|
+
mode?: VcsConfigMode;
|
|
1074
|
+
/** 快照的会话标识(决定 refs/agent/<id>);缺省为 "default" */
|
|
1075
|
+
sessionId?: string;
|
|
1076
|
+
};
|
|
715
1077
|
/** 系统提示词(缺省时使用 buildInstructions("code", ...) 生成) */
|
|
716
1078
|
instructions?: string;
|
|
717
1079
|
/** 代理类型:code=编程助手 / cowork=通用协作(影响默认 instructions) */
|
|
718
1080
|
agentType?: "code" | "cowork";
|
|
1081
|
+
/**
|
|
1082
|
+
* 界面语言(zh / en / zh-TW / ja / ko / es)。
|
|
1083
|
+
*
|
|
1084
|
+
* 决定默认系统提示词用哪一套模板,以及会话自动命名、压缩摘要的语言。
|
|
1085
|
+
* 显式传了 `instructions` 时以它为准,`lang` 仍继续影响命名与摘要。
|
|
1086
|
+
* 缺省简体中文。
|
|
1087
|
+
*/
|
|
1088
|
+
lang?: string;
|
|
719
1089
|
/** 初始对话历史(可选) */
|
|
720
1090
|
messages?: Message[];
|
|
721
1091
|
/** 引擎生命周期钩子(可选) */
|
|
@@ -744,6 +1114,17 @@ interface CreateEngineOpts {
|
|
|
744
1114
|
toolResultDir?: string;
|
|
745
1115
|
/** LLM 请求日志根目录(按日期分目录),不传则不记录 */
|
|
746
1116
|
logDir?: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* 未注入 approver 时的兜底审批策略(创建时即注入,可被后续
|
|
1119
|
+
* `engine.setApprover()` 覆盖)。
|
|
1120
|
+
*
|
|
1121
|
+
* - `error`(默认):第一次需要审批时抛出带修复指引的错误,
|
|
1122
|
+
* 避免「忘记注入 approver → 写文件/跑命令被静默拒绝」;
|
|
1123
|
+
* - `deny`:直接拒绝,保持未注入 approver 的旧行为;
|
|
1124
|
+
* - `allow`:自动放行所有需要审批的工具(等同于信任模型输出,
|
|
1125
|
+
* 仅建议在隔离环境或完全可信的输入下使用)。
|
|
1126
|
+
*/
|
|
1127
|
+
defaultApproval?: "error" | "deny" | "allow";
|
|
747
1128
|
}
|
|
748
1129
|
/**
|
|
749
1130
|
* 一键装配完整的 TurnEngine
|
|
@@ -751,12 +1132,13 @@ interface CreateEngineOpts {
|
|
|
751
1132
|
* 自动创建 OpenAIProvider(若未传入),注册全部 18 个内置工具,
|
|
752
1133
|
* 构建权限引擎,生成默认系统提示词,组装并返回 TurnEngine 实例。
|
|
753
1134
|
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
1135
|
+
* **注意:审批回调需要调用方提供。** 未调用 `engine.setApprover(...)` 时,
|
|
1136
|
+
* 按 `defaultApproval` 处理(默认 `"error"`:第一次需要授权就报错,
|
|
1137
|
+
* 避免静默拒绝)。
|
|
756
1138
|
*
|
|
757
1139
|
* @param opts 装配参数
|
|
758
1140
|
* @returns 已装配好的 TurnEngine 实例
|
|
759
1141
|
*/
|
|
760
1142
|
declare function createDefaultEngine(opts: CreateEngineOpts): TurnEngine;
|
|
761
1143
|
|
|
762
|
-
export {
|
|
1144
|
+
export { type AgentDef, AgentRegistry, BUILTIN_AGENTS, CODE_INSTRUCTIONS, COWORK_INSTRUCTIONS, CompactionDoneInfo, CompactionStartInfo, CompositeHook, type ConfinementResult, ConsoleHook, type ConsoleHookOptions, type CreateEngineOpts, DEFAULT_ALLOWED_COMMANDS, DISCUSS_MODE_CONTEXT, type DownloadResult, EngineErrorInfo, EngineHook, EventType, type GitResult, MCP_CALL_TOOL, MCP_GUIDANCE, MCP_SEARCH_TOOL, MarkdownRenderer, McpBuiltinContext, type McpConnectResult, type McpLazyOptions, McpManager, type McpManagerOptions, McpServerConfig, Message, Mode, OCR_GUIDANCE, PLAN_MODE_CONTEXT, PROMPT_LANGS, type PermissionConfig, type PromptLang, type PromptSet, ProviderClient, ReasoningEffort, type ResolveVcsOptions, type ResolvedBin, type ResolvedMedia, type RestoreResult, SHADOW_DIR, SandboxMode, SandboxOptions, SessionVcs, ShellPolicy, SubagentHook, type TerminalMetaView, type TerminalRecordView, type TerminalSource, TokenUsage, ToolRegistry, type TurnCommit, TurnEngine, type VcsConfigMode, VcsHook, type VcsMode, type VcsPlan, agentRef, assessCommand, buildEnvBlock, buildExplorerInstructions, buildInstructions, createDefaultEngine, downloadFfmpeg, getPrompts, gitMessage, gitOk, installHints, isGitRepo, loadPermissionConfig, matchPromptLang, normalizePromptLang, promptSets, registerTerminalTools, resetFfmpegCache, resolveMedia, resolveVcsPlan, runGit, sessionIndexPath };
|