@ddlqhd/agent-sdk 0.1.0
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 +53 -0
- package/dist/chunk-5QMA2YBY.cjs +2880 -0
- package/dist/chunk-5QMA2YBY.cjs.map +1 -0
- package/dist/chunk-5Y56A64C.cjs +5 -0
- package/dist/chunk-5Y56A64C.cjs.map +1 -0
- package/dist/chunk-A3S3AGE3.js +3 -0
- package/dist/chunk-A3S3AGE3.js.map +1 -0
- package/dist/chunk-CNSGZVRN.cjs +152 -0
- package/dist/chunk-CNSGZVRN.cjs.map +1 -0
- package/dist/chunk-JF5AJQMU.cjs +2788 -0
- package/dist/chunk-JF5AJQMU.cjs.map +1 -0
- package/dist/chunk-NDSL7NPN.js +807 -0
- package/dist/chunk-NDSL7NPN.js.map +1 -0
- package/dist/chunk-OHXW2YM6.js +2708 -0
- package/dist/chunk-OHXW2YM6.js.map +1 -0
- package/dist/chunk-Q3SOMX26.js +2854 -0
- package/dist/chunk-Q3SOMX26.js.map +1 -0
- package/dist/chunk-WH3APNQ5.js +147 -0
- package/dist/chunk-WH3APNQ5.js.map +1 -0
- package/dist/chunk-X35MHWXE.cjs +817 -0
- package/dist/chunk-X35MHWXE.cjs.map +1 -0
- package/dist/cli/index.cjs +926 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +24 -0
- package/dist/cli/index.d.ts +24 -0
- package/dist/cli/index.js +916 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index-DPsZ1zat.d.ts +447 -0
- package/dist/index-RTPmFjMp.d.cts +447 -0
- package/dist/index.cjs +508 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +664 -0
- package/dist/index.d.ts +664 -0
- package/dist/index.js +204 -0
- package/dist/index.js.map +1 -0
- package/dist/models/index.cjs +62 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +165 -0
- package/dist/models/index.d.ts +165 -0
- package/dist/models/index.js +5 -0
- package/dist/models/index.js.map +1 -0
- package/dist/tools/index.cjs +207 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +108 -0
- package/dist/tools/index.d.ts +108 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types-C0aX_Qdp.d.cts +917 -0
- package/dist/types-C0aX_Qdp.d.ts +917 -0
- package/package.json +80 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
import { S as StorageConfig, M as Message, a as SessionInfo, b as StorageAdapter, T as ToolResult, c as ToolDefinition, A as AgentConfig, d as SystemPrompt, e as StreamEvent, f as AgentResult, g as MCPServerConfig, h as SessionTokenUsage, i as TokenUsage, j as StreamChunk, P as ParsedSkill, k as MemoryConfig } from './types-C0aX_Qdp.js';
|
|
2
|
+
export { l as AgentCallbacks, m as AskUserQuestionAnswer, n as AskUserQuestionItem, o as AskUserQuestionResolver, p as AssistantMessage, C as CLIConfig, q as CanUseToolCallback, r as ChatOptions, s as CommandHookConfig, t as CompletionResult, u as ContentPart, v as ContextManagerConfig, w as CreateAskUserQuestionToolOptions, F as FlatCommandHookEntry, x as FunctionHook, H as HookContext, y as HookEventType, z as HookGroupConfig, B as HookManager, D as HookResult, E as HooksSettings, G as HooksSettingsFile, I as ImageContent, J as MCPOptions, K as MCPPromptArgument, L as MCPResourceContent, N as MessageRole, O as ModelAdapter, Q as ModelCapabilities, R as ModelParams, U as RunOptions, V as SessionListOptions, W as SkillConfig, X as SkillDefinition, Y as SkillMetadata, Z as SkillOptions, _ as StreamChunkType, $ as StreamEventAnnotations, a0 as StreamEventType, a1 as SystemMessage, a2 as SystemPromptConfig, a3 as TextContent, a4 as ThinkingContent, a5 as ToolCall, a6 as ToolExecutionContext, a7 as ToolExecutionPolicy, a8 as ToolHandler, a9 as ToolListOptions, aa as ToolMessage, ab as ToolResultMetadata, ac as ToolSchema, ad as UserMessage, ae as buildHookEnv, af as createAskUserQuestionTool, ag as createFunctionHook, ah as formatAnswerSummary, ai as formatAskUserQuestionPrompt, aj as getInteractionTools, ak as matchTool, al as mergeCommandHookLayers, am as questionTool } from './types-C0aX_Qdp.js';
|
|
3
|
+
import { T as ToolRegistry, S as SkillRegistry } from './index-DPsZ1zat.js';
|
|
4
|
+
export { C as CreateAgentToolOptions, D as DEFAULT_GREP_HEAD_LIMIT, M as MAX_LINE_LENGTH, a as SkillLoader, b as SkillLoaderConfig, c as SubagentRequest, d as SubagentRunner, e as ToolExecuteOptions, f as ToolRegistryConfig, g as agentTool, h as bashTool, i as createAgentTool, j as createSkillLoader, k as createSkillRegistry, l as createSkillTool, m as createTool, n as editTool, o as getAllBuiltinTools, p as getFileSystemTools, q as getGlobalRegistry, r as getGrepTools, s as getSafeBuiltinTools, t as getShellTools, u as getSkillTools, v as getSubagentTools, w as getTaskTools, x as getWebTools, y as globTool, z as grepTool, A as loadHooksSettingsFromProject, B as loadHooksSettingsFromUser, E as parseHooksSettingsFile, F as readFileTool, G as subagentRequestSchema, H as taskCreateTool, I as taskListTool, J as taskUpdateTool, K as truncateMatchLineForDisplay, L as webFetchTool, N as webSearchTool, O as writeFileTool } from './index-DPsZ1zat.js';
|
|
5
|
+
export { AnthropicAdapter, AnthropicConfig, CreateModelConfig, ModelProvider, OllamaAdapter, OllamaConfig, OpenAIAdapter, OpenAIConfig, createAnthropic, createModel, createOllama, createOpenAI } from './models/index.js';
|
|
6
|
+
import 'zod';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 会话管理器配置
|
|
10
|
+
*/
|
|
11
|
+
interface SessionManagerConfig extends StorageConfig {
|
|
12
|
+
/** 存储路径 */
|
|
13
|
+
basePath?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 会话管理器
|
|
17
|
+
*/
|
|
18
|
+
declare class SessionManager {
|
|
19
|
+
private storage;
|
|
20
|
+
private currentSessionId;
|
|
21
|
+
constructor(config?: SessionManagerConfig);
|
|
22
|
+
/**
|
|
23
|
+
* 获取当前会话 ID
|
|
24
|
+
*/
|
|
25
|
+
get sessionId(): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* 创建新会话
|
|
28
|
+
*/
|
|
29
|
+
createSession(sessionId?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* 恢复会话
|
|
32
|
+
*/
|
|
33
|
+
resumeSession(sessionId: string): Promise<Message[]>;
|
|
34
|
+
/**
|
|
35
|
+
* 保存消息到当前会话
|
|
36
|
+
*/
|
|
37
|
+
saveMessages(messages: Message[]): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* 加载当前会话消息
|
|
40
|
+
*/
|
|
41
|
+
loadMessages(): Promise<Message[]>;
|
|
42
|
+
/**
|
|
43
|
+
* 追加消息
|
|
44
|
+
*/
|
|
45
|
+
appendMessage(message: Message): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 列出所有会话
|
|
48
|
+
*/
|
|
49
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
50
|
+
/**
|
|
51
|
+
* 删除会话
|
|
52
|
+
*/
|
|
53
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* 检查会话是否存在
|
|
56
|
+
*/
|
|
57
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* 获取会话信息
|
|
60
|
+
*/
|
|
61
|
+
getSessionInfo(sessionId: string): Promise<SessionInfo | null>;
|
|
62
|
+
/**
|
|
63
|
+
* 清空当前会话
|
|
64
|
+
*/
|
|
65
|
+
clearCurrentSession(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* 获取底层存储适配器
|
|
68
|
+
*/
|
|
69
|
+
getStorage(): StorageAdapter;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 创建会话管理器
|
|
73
|
+
*/
|
|
74
|
+
declare function createSessionManager(config?: StorageConfig): SessionManager;
|
|
75
|
+
|
|
76
|
+
interface StdioMCPConfig {
|
|
77
|
+
name: string;
|
|
78
|
+
command: string;
|
|
79
|
+
args?: string[];
|
|
80
|
+
env?: Record<string, string>;
|
|
81
|
+
}
|
|
82
|
+
interface HttpMCPConfig {
|
|
83
|
+
name: string;
|
|
84
|
+
url: string;
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
}
|
|
87
|
+
type MCPClientConfig = StdioMCPConfig | HttpMCPConfig;
|
|
88
|
+
interface MCPTool {
|
|
89
|
+
name: string;
|
|
90
|
+
description?: string;
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: 'object';
|
|
93
|
+
properties?: Record<string, unknown>;
|
|
94
|
+
required?: string[];
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
interface MCPResource {
|
|
98
|
+
uri: string;
|
|
99
|
+
name: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
mimeType?: string;
|
|
102
|
+
}
|
|
103
|
+
interface MCPPrompt {
|
|
104
|
+
name: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
arguments?: Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
required?: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
interface PromptMessage {
|
|
113
|
+
role: 'user' | 'assistant';
|
|
114
|
+
content: string;
|
|
115
|
+
}
|
|
116
|
+
declare class MCPClient {
|
|
117
|
+
private client;
|
|
118
|
+
private transport;
|
|
119
|
+
private _name;
|
|
120
|
+
private _connected;
|
|
121
|
+
private _tools;
|
|
122
|
+
private _serverInfo?;
|
|
123
|
+
constructor(config: MCPClientConfig);
|
|
124
|
+
connect(): Promise<void>;
|
|
125
|
+
disconnect(): Promise<void>;
|
|
126
|
+
listTools(): Promise<MCPTool[]>;
|
|
127
|
+
callTool(name: string, args: unknown): Promise<ToolResult>;
|
|
128
|
+
listResources(): Promise<MCPResource[]>;
|
|
129
|
+
readResource(uri: string): Promise<string>;
|
|
130
|
+
listPrompts(): Promise<MCPPrompt[]>;
|
|
131
|
+
getPrompt(name: string, args?: Record<string, string>): Promise<PromptMessage[]>;
|
|
132
|
+
toToolDefinitions(): ToolDefinition[];
|
|
133
|
+
private convertSchema;
|
|
134
|
+
get name(): string;
|
|
135
|
+
get connected(): boolean;
|
|
136
|
+
get serverInfo(): {
|
|
137
|
+
name: string;
|
|
138
|
+
version: string;
|
|
139
|
+
} | undefined;
|
|
140
|
+
get tools(): MCPTool[];
|
|
141
|
+
}
|
|
142
|
+
declare function createMCPClient(config: MCPClientConfig): MCPClient;
|
|
143
|
+
|
|
144
|
+
declare class MCPAdapter {
|
|
145
|
+
private clients;
|
|
146
|
+
private toolMap;
|
|
147
|
+
addServer(config: MCPClientConfig): Promise<void>;
|
|
148
|
+
removeServer(name: string): Promise<void>;
|
|
149
|
+
getToolDefinitions(): ToolDefinition[];
|
|
150
|
+
executeTool(fullName: string, args: unknown): Promise<ToolResult>;
|
|
151
|
+
getClient(name: string): MCPClient | undefined;
|
|
152
|
+
getServerNames(): string[];
|
|
153
|
+
isConnected(name: string): boolean;
|
|
154
|
+
disconnectAll(): Promise<void>;
|
|
155
|
+
listAllTools(): Promise<Map<string, MCPTool[]>>;
|
|
156
|
+
listAllResources(): Promise<Map<string, Awaited<ReturnType<MCPClient['listResources']>>>>;
|
|
157
|
+
get size(): number;
|
|
158
|
+
}
|
|
159
|
+
declare function createMCPAdapter(): MCPAdapter;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 流式执行选项
|
|
163
|
+
*/
|
|
164
|
+
interface StreamOptions {
|
|
165
|
+
sessionId?: string;
|
|
166
|
+
systemPrompt?: SystemPrompt;
|
|
167
|
+
signal?: AbortSignal;
|
|
168
|
+
/** Pass through to {@link ModelParams.includeRawStreamEvents} (e.g. Anthropic `providerRaw` on chunks). */
|
|
169
|
+
includeRawStreamEvents?: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Agent 类
|
|
173
|
+
* 核心执行引擎,管理对话循环和工具调用
|
|
174
|
+
*/
|
|
175
|
+
declare class Agent {
|
|
176
|
+
private config;
|
|
177
|
+
private toolRegistry;
|
|
178
|
+
private sessionManager;
|
|
179
|
+
private messages;
|
|
180
|
+
private mcpAdapter;
|
|
181
|
+
private skillRegistry;
|
|
182
|
+
private initPromise;
|
|
183
|
+
private contextManager;
|
|
184
|
+
private hookDiscoverPromise;
|
|
185
|
+
private agentDepth;
|
|
186
|
+
private activeSubagentRuns;
|
|
187
|
+
private sessionUsage;
|
|
188
|
+
constructor(config: AgentConfig);
|
|
189
|
+
/**
|
|
190
|
+
* 注册内置 + 自定义工具,或仅 {@link AgentConfig.exclusiveTools}。
|
|
191
|
+
*/
|
|
192
|
+
private registerInitialTools;
|
|
193
|
+
/**
|
|
194
|
+
* 异步初始化(skills 和 MCP)
|
|
195
|
+
*/
|
|
196
|
+
private initializeAsync;
|
|
197
|
+
/**
|
|
198
|
+
* 等待初始化完成
|
|
199
|
+
* CLI 应在开始交互前调用此方法
|
|
200
|
+
*/
|
|
201
|
+
waitForInit(): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* 初始化 MCP 服务器
|
|
204
|
+
*/
|
|
205
|
+
private initializeMCP;
|
|
206
|
+
private annotateStreamEvent;
|
|
207
|
+
private static createEmptySessionUsage;
|
|
208
|
+
private resetSessionState;
|
|
209
|
+
/**
|
|
210
|
+
* 构建系统提示词
|
|
211
|
+
* 处理默认提示词、替换模式、追加模式
|
|
212
|
+
*/
|
|
213
|
+
private buildSystemPrompt;
|
|
214
|
+
/**
|
|
215
|
+
* 流式执行
|
|
216
|
+
*/
|
|
217
|
+
stream(input: string, options?: StreamOptions): AsyncIterable<StreamEvent>;
|
|
218
|
+
/**
|
|
219
|
+
* 非流式执行
|
|
220
|
+
*/
|
|
221
|
+
run(input: string, options?: StreamOptions): Promise<AgentResult>;
|
|
222
|
+
/**
|
|
223
|
+
* 注册工具
|
|
224
|
+
*/
|
|
225
|
+
registerTool(tool: Parameters<ToolRegistry['register']>[0]): void;
|
|
226
|
+
/**
|
|
227
|
+
* 注册多个工具
|
|
228
|
+
*/
|
|
229
|
+
registerTools(tools: Parameters<ToolRegistry['registerMany']>[0]): void;
|
|
230
|
+
/**
|
|
231
|
+
* 获取工具注册中心
|
|
232
|
+
*/
|
|
233
|
+
getToolRegistry(): ToolRegistry;
|
|
234
|
+
/**
|
|
235
|
+
* 获取会话管理器
|
|
236
|
+
*/
|
|
237
|
+
getSessionManager(): SessionManager;
|
|
238
|
+
/**
|
|
239
|
+
* 加载 Skill
|
|
240
|
+
*/
|
|
241
|
+
loadSkill(path: string): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* 获取 Skill 注册中心
|
|
244
|
+
*/
|
|
245
|
+
getSkillRegistry(): SkillRegistry;
|
|
246
|
+
/**
|
|
247
|
+
* 处理用户输入,检测并处理 skill 调用
|
|
248
|
+
* @param input 用户输入
|
|
249
|
+
* @returns 处理结果
|
|
250
|
+
*/
|
|
251
|
+
processInput(input: string): Promise<{
|
|
252
|
+
invoked: boolean;
|
|
253
|
+
skillName?: string;
|
|
254
|
+
prompt: string;
|
|
255
|
+
}>;
|
|
256
|
+
/**
|
|
257
|
+
* 调用 skill 并返回处理后的 prompt
|
|
258
|
+
* @param name Skill 名称
|
|
259
|
+
* @param args 参数字符串
|
|
260
|
+
* @returns 处理后的 prompt
|
|
261
|
+
*/
|
|
262
|
+
invokeSkill(name: string, args?: string): Promise<string>;
|
|
263
|
+
/**
|
|
264
|
+
* 解析 skill 调用格式
|
|
265
|
+
* 格式: /skill-name [args]
|
|
266
|
+
* @param input 用户输入
|
|
267
|
+
* @returns 解析结果或 null
|
|
268
|
+
*/
|
|
269
|
+
private parseSkillInvocation;
|
|
270
|
+
/**
|
|
271
|
+
* 连接 MCP 服务器
|
|
272
|
+
*/
|
|
273
|
+
connectMCP(config: MCPServerConfig): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* 断开指定 MCP 服务器
|
|
276
|
+
*/
|
|
277
|
+
disconnectMCP(name: string): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* 断开所有 MCP 服务器
|
|
280
|
+
*/
|
|
281
|
+
disconnectAllMCP(): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* 获取 MCP 适配器
|
|
284
|
+
*/
|
|
285
|
+
getMCPAdapter(): MCPAdapter | null;
|
|
286
|
+
/**
|
|
287
|
+
* 销毁 Agent,清理资源
|
|
288
|
+
*/
|
|
289
|
+
destroy(): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* 获取消息历史
|
|
292
|
+
*/
|
|
293
|
+
getMessages(): Message[];
|
|
294
|
+
/**
|
|
295
|
+
* 清空消息历史
|
|
296
|
+
*/
|
|
297
|
+
clearMessages(): void;
|
|
298
|
+
/**
|
|
299
|
+
* 设置系统提示 (运行时替换)
|
|
300
|
+
*/
|
|
301
|
+
setSystemPrompt(prompt: SystemPrompt): void;
|
|
302
|
+
/**
|
|
303
|
+
* 追加系统提示内容
|
|
304
|
+
*/
|
|
305
|
+
appendSystemPrompt(additionalContent: string): void;
|
|
306
|
+
/**
|
|
307
|
+
* 获取当前系统提示内容
|
|
308
|
+
*/
|
|
309
|
+
getSystemPrompt(): string | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* 手动触发上下文压缩
|
|
312
|
+
*/
|
|
313
|
+
compressContext(): Promise<{
|
|
314
|
+
messageCount: number;
|
|
315
|
+
stats: {
|
|
316
|
+
originalMessageCount: number;
|
|
317
|
+
compressedMessageCount: number;
|
|
318
|
+
durationMs: number;
|
|
319
|
+
};
|
|
320
|
+
}>;
|
|
321
|
+
/**
|
|
322
|
+
* 获取上下文状态
|
|
323
|
+
*/
|
|
324
|
+
getContextStatus(): {
|
|
325
|
+
used: number;
|
|
326
|
+
usable: number;
|
|
327
|
+
needsCompaction: boolean;
|
|
328
|
+
compressCount: number;
|
|
329
|
+
} | null;
|
|
330
|
+
/**
|
|
331
|
+
* 获取会话累计 Token 使用量
|
|
332
|
+
*/
|
|
333
|
+
getSessionUsage(): SessionTokenUsage;
|
|
334
|
+
/**
|
|
335
|
+
* 检查并执行上下文压缩
|
|
336
|
+
* @returns 压缩事件数组(可能为空)
|
|
337
|
+
*/
|
|
338
|
+
private checkContextCompression;
|
|
339
|
+
private getSubagentConfig;
|
|
340
|
+
private resolveSubagentTools;
|
|
341
|
+
private runSubagent;
|
|
342
|
+
/**
|
|
343
|
+
* 获取默认系统提示词
|
|
344
|
+
*/
|
|
345
|
+
static getDefaultSystemPrompt(): string;
|
|
346
|
+
/**
|
|
347
|
+
* 执行工具调用
|
|
348
|
+
*/
|
|
349
|
+
private executeTools;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* 创建 Agent 实例
|
|
353
|
+
*/
|
|
354
|
+
declare function createAgent(config: AgentConfig): Agent;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Agent SDK 默认系统提示词
|
|
358
|
+
*
|
|
359
|
+
* 占位符说明:
|
|
360
|
+
* - {{SKILL_LIST}}: 会被运行时注入的skill列表替换
|
|
361
|
+
*/
|
|
362
|
+
declare const DEFAULT_SYSTEM_PROMPT = "You are an AI assistant powered by the Agent SDK. You can help users with various tasks by using your built-in tools and capabilities.\n\n## Core Capabilities\n\n### Tools\nYou have access to a set of tools that allow you to:\n- **File Operations**: read, write, list, delete files and directories\n- **Code Execution**: run shell commands, Python scripts, Node.js code\n- **Web Access**: make HTTP requests, fetch webpages, download files\n- **Custom Tools**: additional tools registered by the user or skills\n\nWhen to use tools:\n- Use tools when the task requires real-world actions (file I/O, computation, API calls)\n- Prefer reading files before modifying them\n- Use the simplest tool that gets the job done\n- Run multiple independent tool calls in parallel when possible\n\n**Prefer dedicated tools over Bash:** Do not use `Bash` to do work that has a first-class tool. This keeps actions reviewable and consistent.\n- **Read** for file contents \u2014 not `cat`, `head`, `tail`, or `sed` to print files\n- **Write** to create or overwrite files \u2014 not shell redirection or heredocs\n- **Edit** for targeted file changes \u2014 not `sed`, `awk`, or ad-hoc scripts to patch files\n- **Glob** to find paths by pattern \u2014 not `find` or `ls` for discovery\n- **Grep** to search file contents \u2014 not `grep` or `rg` in the shell (built-in line-by-line regex search; correct integration)\n- **WebFetch** / **WebSearch** when the task needs HTTP or web search (when configured)\n\nReserve **Bash** for real shell needs: `git`, package managers, build commands, compilers, and other operations that require a shell or are not covered above.\n\n### Skills\nSkills are instruction guides for specialized tasks. When activated, you receive the skill's full content including any referenced file paths.\n\n{{SKILL_LIST}}\n\n**Usage:**\n- **Listing skills**: When the user asks about available skills (e.g., \"what skills do you have\", \"\u4F60\u6709\u54EA\u4E9B\u6280\u80FD\", \"list your skills\") \u2192 Simply describe the skills listed above. Do NOT activate any skill.\n- **Activating skills**: When the user has a specific task that matches a skill's purpose \u2192 Call `Skill` with the skill name, then follow the returned instructions.\n- After activation, use the provided Base Path to read any referenced files.\n\n### Sessions\n- Conversations are persisted in sessions\n- Use session IDs to maintain context across multiple interactions\n- Previous messages provide important context for current tasks\n\n## Task Execution Principles\n\n1. **Plan First for Complex Tasks**: For multi-step tasks, you MUST call `TaskCreate` BEFORE any other tool. Do NOT skip this step.\n2. **Be Direct**: Go straight to the point. Try the simplest approach first.\n3. **Be Concise**: If you can say it in one sentence, don't use three.\n4. **Read Before Modify**: Always understand existing code before changing it.\n5. **No Over-Engineering**: Only make changes directly requested or clearly necessary.\n6. **Prefer Edit Over Create**: Modify existing files rather than creating new ones when appropriate.\n7. **Handle Errors Gracefully**: Report errors clearly with actionable suggestions.\n\n## Task Management with Todo List\n\n**MANDATORY**: For multi-step tasks, call `TaskCreate` FIRST.\n\n**Workflow:**\n1. Receive complex task -> call `TaskCreate` immediately\n2. Start first task (in_progress) -> complete -> mark completed\n3. Move to next task -> repeat\n4. Cancel tasks that become irrelevant\n\n**Example:**\nUser: \"Open Google, search X, summarize results, open first link, extract info\"\n-> Multi-step task detected -> call `TaskCreate` FIRST, then execute.\n\n## Output Format\n\n- Lead with the answer or action, not the reasoning\n- Skip filler words and unnecessary preamble\n- Use code blocks with language hints for code\n- Structure longer responses with headers and lists\n- Reference file paths with line numbers when relevant (e.g., `src/index.ts:42`)\n\n## Security Guidelines\n\n- Do not introduce security vulnerabilities (injection, XSS, etc.)\n- Validate user inputs at boundaries\n- Do not execute untrusted code without sandboxing\n- Respect file system permissions and access controls\n\n### High-risk actions (confirm with the user first)\n\nThere is no automatic approval UI: **ask in the conversation** (or use `AskUserQuestion`) before proceeding when an action is destructive, hard to reverse, or affects others. Examples:\n- Deleting files or branches, dropping data, `rm -rf`, overwriting uncommitted work\n- Hard-to-reverse git: force-push, `reset --hard`, rewriting published history, amending shared commits\n- Actions visible outside this machine: pushing code, opening/closing/commenting on PRs or issues, sending messages, posting to external services, changing shared CI/CD or cloud permissions\n- Broad dependency or infrastructure changes (e.g. major version bumps, lockfile rewrites) when impact is unclear\n\nDefault to explaining what you intend and getting explicit agreement unless the user already directed that exact action.\n\n## Tool hooks\n\nWhen hooks are configured (e.g. PreToolUse), a tool call may be **blocked** or its **inputs adjusted** before execution. If a tool fails with a message indicating a hook blocked or rejected the call, **do not** retry the identical tool call unchanged \u2014 read the reason, change your approach, or ask the user. Treat hook feedback as binding policy from the environment.\n\n## Interaction Style\n\n- Be helpful and proactive\n- Ask clarifying questions when instructions are ambiguous\n- Provide suggestions when you see opportunities for improvement\n- Acknowledge limitations honestly\n- Maintain a professional, friendly tone";
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Same directory as {@link Agent} session storage: `<userBase>/.claude/sessions`.
|
|
366
|
+
*/
|
|
367
|
+
declare function getSessionStoragePath(userBasePath?: string): string;
|
|
368
|
+
/**
|
|
369
|
+
* Most recently updated session id from JSONL storage, or `undefined` if none.
|
|
370
|
+
*/
|
|
371
|
+
declare function getLatestSessionId(userBasePath?: string): Promise<string | undefined>;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* JSONL 文件存储配置
|
|
375
|
+
*/
|
|
376
|
+
interface JsonlStorageConfig {
|
|
377
|
+
basePath?: string;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* JSONL 文件存储实现
|
|
381
|
+
* 每个会话一个 .jsonl 文件,每行一条消息
|
|
382
|
+
*/
|
|
383
|
+
declare class JsonlStorage implements StorageAdapter {
|
|
384
|
+
private basePath;
|
|
385
|
+
constructor(config?: JsonlStorageConfig);
|
|
386
|
+
/**
|
|
387
|
+
* 获取会话文件路径
|
|
388
|
+
*/
|
|
389
|
+
private getFilePath;
|
|
390
|
+
/**
|
|
391
|
+
* 获取元数据文件路径
|
|
392
|
+
*/
|
|
393
|
+
private getMetaFilePath;
|
|
394
|
+
/**
|
|
395
|
+
* 确保目录存在
|
|
396
|
+
*/
|
|
397
|
+
private ensureDir;
|
|
398
|
+
/**
|
|
399
|
+
* 保存消息(追加模式)
|
|
400
|
+
*/
|
|
401
|
+
save(sessionId: string, messages: Message[]): Promise<void>;
|
|
402
|
+
/**
|
|
403
|
+
* 加载消息
|
|
404
|
+
*/
|
|
405
|
+
load(sessionId: string): Promise<Message[]>;
|
|
406
|
+
/**
|
|
407
|
+
* 列出所有会话
|
|
408
|
+
*/
|
|
409
|
+
list(): Promise<SessionInfo[]>;
|
|
410
|
+
/**
|
|
411
|
+
* 删除会话
|
|
412
|
+
*/
|
|
413
|
+
delete(sessionId: string): Promise<void>;
|
|
414
|
+
/**
|
|
415
|
+
* 检查会话是否存在
|
|
416
|
+
*/
|
|
417
|
+
exists(sessionId: string): Promise<boolean>;
|
|
418
|
+
/**
|
|
419
|
+
* 清空所有会话
|
|
420
|
+
*/
|
|
421
|
+
clear(): Promise<void>;
|
|
422
|
+
/**
|
|
423
|
+
* 获取会话统计
|
|
424
|
+
*/
|
|
425
|
+
getStats(sessionId: string): Promise<{
|
|
426
|
+
messageCount: number;
|
|
427
|
+
createdAt: number;
|
|
428
|
+
updatedAt: number;
|
|
429
|
+
size: number;
|
|
430
|
+
} | null>;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* 创建 JSONL 存储
|
|
434
|
+
*/
|
|
435
|
+
declare function createJsonlStorage(config?: JsonlStorageConfig): JsonlStorage;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* 内存存储实现
|
|
439
|
+
* 用于测试或临时会话,重启后数据丢失
|
|
440
|
+
*/
|
|
441
|
+
declare class MemoryStorage implements StorageAdapter {
|
|
442
|
+
private sessions;
|
|
443
|
+
private metadata;
|
|
444
|
+
/**
|
|
445
|
+
* 保存消息
|
|
446
|
+
*/
|
|
447
|
+
save(sessionId: string, messages: Message[]): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* 加载消息
|
|
450
|
+
*/
|
|
451
|
+
load(sessionId: string): Promise<Message[]>;
|
|
452
|
+
/**
|
|
453
|
+
* 列出所有会话
|
|
454
|
+
*/
|
|
455
|
+
list(): Promise<SessionInfo[]>;
|
|
456
|
+
/**
|
|
457
|
+
* 删除会话
|
|
458
|
+
*/
|
|
459
|
+
delete(sessionId: string): Promise<void>;
|
|
460
|
+
/**
|
|
461
|
+
* 检查会话是否存在
|
|
462
|
+
*/
|
|
463
|
+
exists(sessionId: string): Promise<boolean>;
|
|
464
|
+
/**
|
|
465
|
+
* 清空所有会话
|
|
466
|
+
*/
|
|
467
|
+
clear(): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* 获取会话数量
|
|
470
|
+
*/
|
|
471
|
+
get size(): number;
|
|
472
|
+
/**
|
|
473
|
+
* 导出所有数据
|
|
474
|
+
*/
|
|
475
|
+
export(): Record<string, Message[]>;
|
|
476
|
+
/**
|
|
477
|
+
* 导入数据
|
|
478
|
+
*/
|
|
479
|
+
import(data: Record<string, Message[]>): void;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 创建内存存储
|
|
483
|
+
*/
|
|
484
|
+
declare function createMemoryStorage(): MemoryStorage;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 存储工厂函数
|
|
488
|
+
*/
|
|
489
|
+
declare function createStorage(config?: StorageConfig & {
|
|
490
|
+
basePath?: string;
|
|
491
|
+
}): StorageAdapter;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Agent 流类
|
|
495
|
+
* 实现 AsyncIterable 接口,支持 for await...of 遍历
|
|
496
|
+
*/
|
|
497
|
+
declare class AgentStream implements AsyncIterable<StreamEvent> {
|
|
498
|
+
private events;
|
|
499
|
+
private resolvers;
|
|
500
|
+
private isEnded;
|
|
501
|
+
private error;
|
|
502
|
+
private abortController;
|
|
503
|
+
constructor();
|
|
504
|
+
/**
|
|
505
|
+
* 实现 AsyncIterable 接口
|
|
506
|
+
*/
|
|
507
|
+
[Symbol.asyncIterator](): AsyncIterator<StreamEvent>;
|
|
508
|
+
/**
|
|
509
|
+
* 推送事件
|
|
510
|
+
*/
|
|
511
|
+
push(event: StreamEvent): void;
|
|
512
|
+
/**
|
|
513
|
+
* 结束流
|
|
514
|
+
*/
|
|
515
|
+
end(usage?: TokenUsage): void;
|
|
516
|
+
/**
|
|
517
|
+
* Marks the stream complete without pushing an event. Use when the producer already emitted a terminal `{ type: 'end' }` and iterators must unblock.
|
|
518
|
+
*/
|
|
519
|
+
finalize(): void;
|
|
520
|
+
/**
|
|
521
|
+
* 抛出错误
|
|
522
|
+
*/
|
|
523
|
+
throwError(error: Error): void;
|
|
524
|
+
/**
|
|
525
|
+
* 中止流
|
|
526
|
+
*/
|
|
527
|
+
abort(): void;
|
|
528
|
+
/**
|
|
529
|
+
* 获取中止信号
|
|
530
|
+
*/
|
|
531
|
+
get signal(): AbortSignal;
|
|
532
|
+
/**
|
|
533
|
+
* 合并多个流
|
|
534
|
+
*/
|
|
535
|
+
static merge(...streams: AgentStream[]): AgentStream;
|
|
536
|
+
/**
|
|
537
|
+
* 转换为数组
|
|
538
|
+
*/
|
|
539
|
+
toArray(): Promise<StreamEvent[]>;
|
|
540
|
+
/**
|
|
541
|
+
* 收集文本内容
|
|
542
|
+
*/
|
|
543
|
+
collectText(): Promise<string>;
|
|
544
|
+
/**
|
|
545
|
+
* 过滤事件
|
|
546
|
+
*/
|
|
547
|
+
filter(predicate: (event: StreamEvent) => boolean): AgentStream;
|
|
548
|
+
/**
|
|
549
|
+
* 转换事件
|
|
550
|
+
*/
|
|
551
|
+
map<T>(transform: (event: StreamEvent) => T): AsyncIterable<T>;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 创建 Agent 流
|
|
555
|
+
*/
|
|
556
|
+
declare function createStream(): AgentStream;
|
|
557
|
+
/**
|
|
558
|
+
* 从 AsyncIterable 创建 Agent 流
|
|
559
|
+
*/
|
|
560
|
+
declare function fromAsyncIterable(iterable: AsyncIterable<StreamEvent>): AgentStream;
|
|
561
|
+
|
|
562
|
+
interface StreamChunkProcessorOptions {
|
|
563
|
+
/** Emit `text_start` / `text_end` around assistant text deltas (Claude-style content blocks). Default true. */
|
|
564
|
+
emitTextBoundaries?: boolean;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Stateful conversion from model `StreamChunk` to normalized `StreamEvent`s.
|
|
568
|
+
* Used by `Agent` so streaming tool JSON and text blocks behave consistently.
|
|
569
|
+
*/
|
|
570
|
+
declare class StreamChunkProcessor {
|
|
571
|
+
private currentToolCall;
|
|
572
|
+
private lastUsage;
|
|
573
|
+
private inTextBlock;
|
|
574
|
+
private readonly emitTextBoundaries;
|
|
575
|
+
constructor(options?: StreamChunkProcessorOptions);
|
|
576
|
+
processChunk(chunk: StreamChunk): StreamEvent[];
|
|
577
|
+
/** End open text block and finalize any in-progress streamed tool call. */
|
|
578
|
+
flush(): StreamEvent[];
|
|
579
|
+
getUsage(): TokenUsage | undefined;
|
|
580
|
+
private finalizeStreamingToolCall;
|
|
581
|
+
private safeParseJSON;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* 解析 SKILL.md 文件
|
|
586
|
+
* 格式:
|
|
587
|
+
* ---
|
|
588
|
+
* name: skill-name
|
|
589
|
+
* description: "Skill description"
|
|
590
|
+
* version: "1.0.0"
|
|
591
|
+
* ---
|
|
592
|
+
*
|
|
593
|
+
* # Instructions
|
|
594
|
+
* ...
|
|
595
|
+
*/
|
|
596
|
+
declare function parseSkillMd(content: string): ParsedSkill;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* MemoryManager handles the loading of long-term memory files
|
|
600
|
+
* (CLAUDE.md) from user home directory and workspace root.
|
|
601
|
+
*/
|
|
602
|
+
declare class MemoryManager {
|
|
603
|
+
private workspaceRoot;
|
|
604
|
+
private userBasePath;
|
|
605
|
+
private config;
|
|
606
|
+
constructor(workspaceRoot?: string, config?: MemoryConfig, userBasePath?: string);
|
|
607
|
+
/**
|
|
608
|
+
* Loads memory content from both user home ({userBasePath}/.claude/CLAUDE.md)
|
|
609
|
+
* and workspace root (./CLAUDE.md).
|
|
610
|
+
* @returns Combined memory content wrapped in system-minder tags
|
|
611
|
+
*/
|
|
612
|
+
loadMemory(): string;
|
|
613
|
+
/**
|
|
614
|
+
* Checks if memory files exist.
|
|
615
|
+
* @returns Object indicating existence of each memory file type
|
|
616
|
+
*/
|
|
617
|
+
checkMemoryFiles(): {
|
|
618
|
+
userHome: boolean;
|
|
619
|
+
workspace: boolean;
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* MCP 配置文件格式 (Claude Desktop 兼容)
|
|
625
|
+
*/
|
|
626
|
+
interface MCPConfigFile {
|
|
627
|
+
mcpServers: {
|
|
628
|
+
[name: string]: {
|
|
629
|
+
/** 命令 (stdio transport) */
|
|
630
|
+
command?: string;
|
|
631
|
+
/** 命令参数 */
|
|
632
|
+
args?: string[];
|
|
633
|
+
/** 环境变量 */
|
|
634
|
+
env?: Record<string, string>;
|
|
635
|
+
/** URL (HTTP transport) */
|
|
636
|
+
url?: string;
|
|
637
|
+
/** HTTP headers */
|
|
638
|
+
headers?: Record<string, string>;
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* MCP 配置加载结果
|
|
644
|
+
*/
|
|
645
|
+
interface MCPConfigLoadResult {
|
|
646
|
+
servers: MCPServerConfig[];
|
|
647
|
+
/** 主配置文件路径 */
|
|
648
|
+
configPath?: string;
|
|
649
|
+
/** 所有加载的配置文件路径 */
|
|
650
|
+
configPaths?: string[];
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* 加载 MCP 配置
|
|
654
|
+
* @param configPath 可选的配置文件路径,如未提供则自动加载用户目录和工作目录配置
|
|
655
|
+
* @param startDir 搜索起始目录,默认为当前工作目录
|
|
656
|
+
* @param userBasePath 用户级基础路径,默认 ~ (homedir)
|
|
657
|
+
*/
|
|
658
|
+
declare function loadMCPConfig(configPath?: string, startDir?: string, userBasePath?: string): MCPConfigLoadResult;
|
|
659
|
+
/**
|
|
660
|
+
* 验证 MCP 配置
|
|
661
|
+
*/
|
|
662
|
+
declare function validateMCPConfig(config: MCPConfigFile): string[];
|
|
663
|
+
|
|
664
|
+
export { Agent, AgentConfig, AgentResult, AgentStream, DEFAULT_SYSTEM_PROMPT, type HttpMCPConfig, JsonlStorage, MCPAdapter, MCPClient, type MCPClientConfig, type MCPConfigFile, type MCPConfigLoadResult, type MCPPrompt, type MCPResource, MCPServerConfig, type MCPTool, MemoryConfig, MemoryManager, MemoryStorage, Message, ParsedSkill, type PromptMessage, SessionInfo, SessionManager, SessionTokenUsage, SkillRegistry, type StdioMCPConfig, StorageAdapter, StorageConfig, StreamChunk, StreamChunkProcessor, type StreamChunkProcessorOptions, StreamEvent, type StreamOptions, SystemPrompt, TokenUsage, ToolDefinition, ToolRegistry, ToolResult, createAgent, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createStorage, createStream, fromAsyncIterable, getLatestSessionId, getSessionStoragePath, loadMCPConfig, parseSkillMd, validateMCPConfig };
|