@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.
Files changed (50) hide show
  1. package/README.md +53 -0
  2. package/dist/chunk-5QMA2YBY.cjs +2880 -0
  3. package/dist/chunk-5QMA2YBY.cjs.map +1 -0
  4. package/dist/chunk-5Y56A64C.cjs +5 -0
  5. package/dist/chunk-5Y56A64C.cjs.map +1 -0
  6. package/dist/chunk-A3S3AGE3.js +3 -0
  7. package/dist/chunk-A3S3AGE3.js.map +1 -0
  8. package/dist/chunk-CNSGZVRN.cjs +152 -0
  9. package/dist/chunk-CNSGZVRN.cjs.map +1 -0
  10. package/dist/chunk-JF5AJQMU.cjs +2788 -0
  11. package/dist/chunk-JF5AJQMU.cjs.map +1 -0
  12. package/dist/chunk-NDSL7NPN.js +807 -0
  13. package/dist/chunk-NDSL7NPN.js.map +1 -0
  14. package/dist/chunk-OHXW2YM6.js +2708 -0
  15. package/dist/chunk-OHXW2YM6.js.map +1 -0
  16. package/dist/chunk-Q3SOMX26.js +2854 -0
  17. package/dist/chunk-Q3SOMX26.js.map +1 -0
  18. package/dist/chunk-WH3APNQ5.js +147 -0
  19. package/dist/chunk-WH3APNQ5.js.map +1 -0
  20. package/dist/chunk-X35MHWXE.cjs +817 -0
  21. package/dist/chunk-X35MHWXE.cjs.map +1 -0
  22. package/dist/cli/index.cjs +926 -0
  23. package/dist/cli/index.cjs.map +1 -0
  24. package/dist/cli/index.d.cts +24 -0
  25. package/dist/cli/index.d.ts +24 -0
  26. package/dist/cli/index.js +916 -0
  27. package/dist/cli/index.js.map +1 -0
  28. package/dist/index-DPsZ1zat.d.ts +447 -0
  29. package/dist/index-RTPmFjMp.d.cts +447 -0
  30. package/dist/index.cjs +508 -0
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/index.d.cts +664 -0
  33. package/dist/index.d.ts +664 -0
  34. package/dist/index.js +204 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/models/index.cjs +62 -0
  37. package/dist/models/index.cjs.map +1 -0
  38. package/dist/models/index.d.cts +165 -0
  39. package/dist/models/index.d.ts +165 -0
  40. package/dist/models/index.js +5 -0
  41. package/dist/models/index.js.map +1 -0
  42. package/dist/tools/index.cjs +207 -0
  43. package/dist/tools/index.cjs.map +1 -0
  44. package/dist/tools/index.d.cts +108 -0
  45. package/dist/tools/index.d.ts +108 -0
  46. package/dist/tools/index.js +6 -0
  47. package/dist/tools/index.js.map +1 -0
  48. package/dist/types-C0aX_Qdp.d.cts +917 -0
  49. package/dist/types-C0aX_Qdp.d.ts +917 -0
  50. package/package.json +80 -0
@@ -0,0 +1,917 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Hook 事件类型(运行时)
5
+ */
6
+ type HookEventType = 'preToolUse' | 'postToolUse' | 'postToolUseFailure';
7
+ /**
8
+ * Hook 执行上下文
9
+ */
10
+ interface HookContext {
11
+ eventType: HookEventType;
12
+ toolName: string;
13
+ /** 已校验的工具参数 */
14
+ toolInput: Record<string, unknown>;
15
+ toolCallId?: string;
16
+ timestamp: number;
17
+ projectDir?: string;
18
+ /** PostToolUse:handler 返回的原始结果(未经 outputHandler) */
19
+ toolResultRaw?: ToolResult;
20
+ /** PostToolUse:将返回给调用方的最终结果 */
21
+ toolResultFinal?: ToolResult;
22
+ /** PostToolUseFailure */
23
+ errorMessage?: string;
24
+ failureKind?: 'validation' | 'handler_throw' | 'tool_error';
25
+ }
26
+ /**
27
+ * PreToolUse 阶段 Hook 执行结果
28
+ */
29
+ interface HookResult {
30
+ allowed: boolean;
31
+ reason?: string;
32
+ updatedInput?: Record<string, unknown>;
33
+ }
34
+ /**
35
+ * JavaScript 函数 Hook(代码设置方式)
36
+ */
37
+ interface FunctionHook {
38
+ id: string;
39
+ event: HookEventType;
40
+ matcher?: string;
41
+ handler: (context: HookContext) => Promise<HookResult | void>;
42
+ description?: string;
43
+ }
44
+ /**
45
+ * Shell 命令 Hook 配置(配置文件解析后)
46
+ */
47
+ interface CommandHookConfig {
48
+ id?: string;
49
+ type: 'command';
50
+ command: string;
51
+ timeout?: number;
52
+ async?: boolean;
53
+ }
54
+ interface HookGroupConfig {
55
+ matcher?: string;
56
+ hooks: CommandHookConfig[];
57
+ }
58
+ /**
59
+ * 配置文件解析后的设置(内部)
60
+ */
61
+ interface HooksSettings {
62
+ disableAllHooks?: boolean;
63
+ hooks: Record<HookEventType, HookGroupConfig[]>;
64
+ }
65
+ /** 磁盘 JSON(hooks 下为 PascalCase 键) */
66
+ interface HooksSettingsFile {
67
+ disableAllHooks?: boolean;
68
+ hooks?: {
69
+ PreToolUse?: HookGroupConfig[];
70
+ PostToolUse?: HookGroupConfig[];
71
+ PostToolUseFailure?: HookGroupConfig[];
72
+ };
73
+ }
74
+
75
+ /** 扁平化的文件 command hook(含 matcher) */
76
+ interface FlatCommandHookEntry {
77
+ matcher?: string;
78
+ hook: CommandHookConfig;
79
+ }
80
+ /**
81
+ * matcher 为 JavaScript 正则源码(不含定界符)
82
+ */
83
+ declare function matchTool(toolName: string, matcher?: string): boolean;
84
+ declare function buildHookEnv(context: HookContext): NodeJS.ProcessEnv;
85
+ /**
86
+ * 合并项目层与用户层 command hook(§6.3)
87
+ */
88
+ declare function mergeCommandHookLayers(project: HookGroupConfig[], user: HookGroupConfig[]): FlatCommandHookEntry[];
89
+ declare class HookManager {
90
+ private runtimeEnabled;
91
+ private mergedDisableAll;
92
+ private mergedHooks;
93
+ private functionHooks;
94
+ private projectHooks;
95
+ private userHooks;
96
+ private emptySettings;
97
+ private rebuildMerged;
98
+ private shouldRunHooks;
99
+ private getHooksForEvent;
100
+ private getFunctionHooksForEvent;
101
+ private runCommandHook;
102
+ private fireAsyncCommandHook;
103
+ private runFunctionHookSafe;
104
+ register(hook: FunctionHook): void;
105
+ unregister(id: string): boolean;
106
+ loadProjectConfig(projectDir: string): Promise<void>;
107
+ loadUserConfig(): Promise<void>;
108
+ discoverAndLoad(projectDir?: string): Promise<void>;
109
+ setEnabled(enabled: boolean): void;
110
+ isEnabled(): boolean;
111
+ executePreToolUse(context: HookContext): Promise<HookResult>;
112
+ executePostToolUse(context: HookContext): Promise<void>;
113
+ executePostToolUseFailure(context: HookContext): Promise<void>;
114
+ static create(): HookManager;
115
+ }
116
+ declare function createFunctionHook(config: {
117
+ id: string;
118
+ event: HookEventType;
119
+ matcher?: string;
120
+ description?: string;
121
+ handler: (context: HookContext) => Promise<HookResult | void>;
122
+ }): FunctionHook;
123
+
124
+ declare const questionsSchema: z.ZodObject<{
125
+ questions: z.ZodArray<z.ZodObject<{
126
+ question: z.ZodString;
127
+ header: z.ZodString;
128
+ options: z.ZodArray<z.ZodObject<{
129
+ label: z.ZodString;
130
+ description: z.ZodString;
131
+ }, "strip", z.ZodTypeAny, {
132
+ description: string;
133
+ label: string;
134
+ }, {
135
+ description: string;
136
+ label: string;
137
+ }>, "many">;
138
+ multiSelect: z.ZodDefault<z.ZodBoolean>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ options: {
141
+ description: string;
142
+ label: string;
143
+ }[];
144
+ question: string;
145
+ header: string;
146
+ multiSelect: boolean;
147
+ }, {
148
+ options: {
149
+ description: string;
150
+ label: string;
151
+ }[];
152
+ question: string;
153
+ header: string;
154
+ multiSelect?: boolean | undefined;
155
+ }>, "many">;
156
+ }, "strip", z.ZodTypeAny, {
157
+ questions: {
158
+ options: {
159
+ description: string;
160
+ label: string;
161
+ }[];
162
+ question: string;
163
+ header: string;
164
+ multiSelect: boolean;
165
+ }[];
166
+ }, {
167
+ questions: {
168
+ options: {
169
+ description: string;
170
+ label: string;
171
+ }[];
172
+ question: string;
173
+ header: string;
174
+ multiSelect?: boolean | undefined;
175
+ }[];
176
+ }>;
177
+ type AskUserQuestionItem = z.infer<typeof questionsSchema>['questions'][number];
178
+ type AskUserQuestionAnswer = {
179
+ questionIndex: number;
180
+ selectedLabels: string[];
181
+ otherText?: string;
182
+ };
183
+ /**
184
+ * Host-provided implementation: CLI (TTY), web UI (WebSocket), tests, etc.
185
+ */
186
+ type AskUserQuestionResolver = (questions: AskUserQuestionItem[]) => Promise<AskUserQuestionAnswer[]>;
187
+ /**
188
+ * Format questions for display (static fallback body).
189
+ */
190
+ declare function formatAskUserQuestionPrompt(questions: AskUserQuestionItem[]): string;
191
+ declare function formatAnswerSummary(questions: AskUserQuestionItem[], answers: AskUserQuestionAnswer[]): string;
192
+ interface CreateAskUserQuestionToolOptions {
193
+ /**
194
+ * When set, collects answers interactively. When omitted, the tool returns only formatted questions (non-blocking).
195
+ */
196
+ resolve?: AskUserQuestionResolver;
197
+ }
198
+ /**
199
+ * AskUserQuestion — interactive behavior is entirely determined by {@link CreateAskUserQuestionToolOptions.resolve}.
200
+ */
201
+ declare function createAskUserQuestionTool(options?: CreateAskUserQuestionToolOptions): ToolDefinition;
202
+ declare const questionTool: ToolDefinition;
203
+ /**
204
+ * Interaction tools (AskUserQuestion).
205
+ */
206
+ declare function getInteractionTools(options?: CreateAskUserQuestionToolOptions): ToolDefinition[];
207
+
208
+ /**
209
+ * 压缩器接口
210
+ */
211
+ interface Compressor {
212
+ /** 压缩名称 (用于日志) */
213
+ name: string;
214
+ /**
215
+ * 执行压缩
216
+ * @param messages 原始消息列表
217
+ * @param targetTokens 目标 token 数
218
+ * @returns 压缩后的消息列表
219
+ */
220
+ compress(messages: Message[], targetTokens: number): Promise<Message[]>;
221
+ }
222
+
223
+ /**
224
+ * 文本内容部分
225
+ */
226
+ interface TextContent {
227
+ type: 'text';
228
+ text: string;
229
+ }
230
+ /**
231
+ * 思考内容部分 (用于支持 extended thinking)
232
+ */
233
+ interface ThinkingContent {
234
+ type: 'thinking';
235
+ thinking: string;
236
+ signature?: string;
237
+ }
238
+ /**
239
+ * 图片内容部分
240
+ */
241
+ interface ImageContent {
242
+ type: 'image';
243
+ imageUrl: string;
244
+ mimeType?: string;
245
+ }
246
+ /**
247
+ * 内容部分联合类型
248
+ */
249
+ type ContentPart = TextContent | ThinkingContent | ImageContent;
250
+ /**
251
+ * 工具调用
252
+ */
253
+ interface ToolCall {
254
+ id: string;
255
+ name: string;
256
+ arguments: unknown;
257
+ }
258
+ /**
259
+ * 消息角色
260
+ */
261
+ type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
262
+ /**
263
+ * 消息
264
+ */
265
+ interface Message {
266
+ role: MessageRole;
267
+ content: string | ContentPart[];
268
+ toolCalls?: ToolCall[];
269
+ toolCallId?: string;
270
+ name?: string;
271
+ timestamp?: number;
272
+ }
273
+ /**
274
+ * 系统消息
275
+ */
276
+ interface SystemMessage extends Message {
277
+ role: 'system';
278
+ content: string;
279
+ }
280
+ /**
281
+ * 用户消息
282
+ */
283
+ interface UserMessage extends Message {
284
+ role: 'user';
285
+ content: string | ContentPart[];
286
+ }
287
+ /**
288
+ * 助手消息
289
+ */
290
+ interface AssistantMessage extends Message {
291
+ role: 'assistant';
292
+ content: string;
293
+ toolCalls?: ToolCall[];
294
+ }
295
+ /**
296
+ * 工具结果消息
297
+ */
298
+ interface ToolMessage extends Message {
299
+ role: 'tool';
300
+ content: string;
301
+ toolCallId: string;
302
+ }
303
+ /**
304
+ * 模型参数
305
+ */
306
+ interface ModelParams {
307
+ messages: Message[];
308
+ tools?: ToolDefinition[];
309
+ temperature?: number;
310
+ maxTokens?: number;
311
+ stopSequences?: string[];
312
+ signal?: AbortSignal;
313
+ /**
314
+ * When true, adapters may attach `providerRaw` on each {@link StreamChunk} (e.g. Anthropic SSE JSON object).
315
+ */
316
+ includeRawStreamEvents?: boolean;
317
+ }
318
+ /**
319
+ * 流式块类型
320
+ */
321
+ type StreamChunkType = 'text' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'thinking' | 'error' | 'done' | 'metadata';
322
+ /**
323
+ * 流式块
324
+ */
325
+ interface StreamChunk {
326
+ type: StreamChunkType;
327
+ content?: string;
328
+ toolCall?: ToolCall;
329
+ toolCallId?: string;
330
+ error?: Error;
331
+ metadata?: Record<string, unknown>;
332
+ /** When `type === 'metadata'`, distinguishes prompt vs completion usage timing (e.g. Anthropic). */
333
+ usagePhase?: 'input' | 'output';
334
+ signature?: string;
335
+ /** Raw provider streaming payload when {@link ModelParams.includeRawStreamEvents} is enabled */
336
+ providerRaw?: unknown;
337
+ }
338
+ /**
339
+ * 完成结果
340
+ */
341
+ interface CompletionResult {
342
+ content: string;
343
+ /** Ollama extended thinking trace (when using thinking-capable models). */
344
+ thinking?: string;
345
+ toolCalls?: ToolCall[];
346
+ usage?: TokenUsage;
347
+ metadata?: Record<string, unknown>;
348
+ }
349
+ /**
350
+ * Token 使用统计
351
+ */
352
+ interface TokenUsage {
353
+ promptTokens: number;
354
+ completionTokens: number;
355
+ totalTokens: number;
356
+ }
357
+ /**
358
+ * 会话 Token 使用统计
359
+ *
360
+ * 关键区分:
361
+ * - contextTokens: 当前上下文大小 (最近一次 API 返回的 input_tokens,用于压缩判断)
362
+ * - inputTokens: 累计输入消耗
363
+ * - outputTokens: 累计输出消耗
364
+ * - totalTokens: 累计总消耗 (inputTokens + outputTokens)
365
+ */
366
+ interface SessionTokenUsage {
367
+ /** 当前上下文 tokens (最近一次 API 返回的 input_tokens,用于压缩判断) */
368
+ contextTokens: number;
369
+ /** 累计输入 tokens */
370
+ inputTokens: number;
371
+ /** 累计输出 tokens */
372
+ outputTokens: number;
373
+ /** 累计缓存读取 tokens */
374
+ cacheReadTokens: number;
375
+ /** 累计缓存写入 tokens */
376
+ cacheWriteTokens: number;
377
+ /** 累计总 tokens (inputTokens + outputTokens) */
378
+ totalTokens: number;
379
+ }
380
+ /**
381
+ * 模型能力描述
382
+ */
383
+ interface ModelCapabilities {
384
+ /** 上下文窗口长度 (tokens) */
385
+ contextLength: number;
386
+ /** 最大输出 token 数 */
387
+ maxOutputTokens?: number;
388
+ }
389
+ /**
390
+ * 模型适配器接口
391
+ */
392
+ interface ModelAdapter {
393
+ /** 模型名称 */
394
+ name: string;
395
+ /** 模型能力 (可选) */
396
+ capabilities?: ModelCapabilities;
397
+ /** 流式生成 */
398
+ stream(params: ModelParams): AsyncIterable<StreamChunk>;
399
+ /** 完整生成 */
400
+ complete(params: ModelParams): Promise<CompletionResult>;
401
+ }
402
+ /**
403
+ * 工具结果元数据
404
+ */
405
+ interface ToolResultMetadata {
406
+ /** 是否被截断 */
407
+ truncated?: boolean;
408
+ /** 原始内容长度 */
409
+ originalLength?: number;
410
+ /** 原始行数 */
411
+ originalLineCount?: number;
412
+ /** 显示的行数 */
413
+ displayedLineCount?: number;
414
+ /** 完整内容保存路径 */
415
+ storagePath?: string;
416
+ /** 行数统计 */
417
+ lineCount?: number;
418
+ /** 其他自定义字段 */
419
+ [key: string]: unknown;
420
+ }
421
+ /**
422
+ * 工具结果
423
+ */
424
+ interface ToolResult {
425
+ content: string;
426
+ isError?: boolean;
427
+ metadata?: ToolResultMetadata;
428
+ }
429
+ /**
430
+ * Tool 执行上下文
431
+ */
432
+ interface ToolExecutionContext {
433
+ /** 工具调用 ID */
434
+ toolCallId?: string;
435
+ /** Agent 配置的工作目录 */
436
+ projectDir?: string;
437
+ /** 当前 agent 深度(根 agent 为 0) */
438
+ agentDepth?: number;
439
+ }
440
+ /**
441
+ * 工具处理函数
442
+ */
443
+ type ToolHandler = (args: any, context?: ToolExecutionContext) => Promise<ToolResult>;
444
+ /**
445
+ * 工具定义
446
+ */
447
+ interface ToolDefinition {
448
+ /** 工具名称 */
449
+ name: string;
450
+ /** 工具描述 */
451
+ description: string;
452
+ /** 参数 Schema (Zod) */
453
+ parameters: z.ZodSchema;
454
+ /** 处理函数 */
455
+ handler: ToolHandler;
456
+ /** 是否危险操作 */
457
+ isDangerous?: boolean;
458
+ /** 工具分类 (e.g., "filesystem", "shell", "web", "planning") */
459
+ category?: string;
460
+ }
461
+ /**
462
+ * 工具 Schema (用于模型调用)
463
+ */
464
+ interface ToolSchema {
465
+ name: string;
466
+ description: string;
467
+ parameters: Record<string, unknown>;
468
+ }
469
+ /**
470
+ * 会话信息
471
+ */
472
+ interface SessionInfo {
473
+ id: string;
474
+ createdAt: number;
475
+ updatedAt: number;
476
+ messageCount: number;
477
+ metadata?: Record<string, unknown>;
478
+ }
479
+ /**
480
+ * 存储配置
481
+ */
482
+ interface StorageConfig {
483
+ type: 'jsonl' | 'memory';
484
+ }
485
+ /**
486
+ * 存储适配器接口
487
+ */
488
+ interface StorageAdapter {
489
+ /** 保存消息 */
490
+ save(sessionId: string, messages: Message[]): Promise<void>;
491
+ /** 加载消息 */
492
+ load(sessionId: string): Promise<Message[]>;
493
+ /** 列出会话 */
494
+ list(): Promise<SessionInfo[]>;
495
+ /** 删除会话 */
496
+ delete(sessionId: string): Promise<void>;
497
+ /** 会话是否存在 */
498
+ exists(sessionId: string): Promise<boolean>;
499
+ }
500
+ /**
501
+ * 流式事件类型
502
+ */
503
+ type StreamEventType = 'text_delta' | 'text_start' | 'text_end' | 'tool_call' | 'tool_call_start' | 'tool_call_delta' | 'tool_call_end' | 'tool_result' | 'tool_error' | 'thinking' | 'start' | 'end' | 'model_usage' | 'session_summary' | 'context_compressed';
504
+ /**
505
+ * Optional fields on any stream event (observability, Claude-style correlation).
506
+ */
507
+ interface StreamEventAnnotations {
508
+ streamEventId?: string;
509
+ /** Agent model-call iteration (0-based) when produced by {@link Agent.stream} */
510
+ iteration?: number;
511
+ /**
512
+ * Current session id when {@link Agent.stream} annotates events (including `session_summary`).
513
+ * Not duplicated on the `session_summary` variant payload; use this field for correlation.
514
+ */
515
+ sessionId?: string;
516
+ }
517
+ /**
518
+ * 流式事件
519
+ */
520
+ type StreamEvent = ({
521
+ type: 'start';
522
+ timestamp: number;
523
+ } | {
524
+ type: 'text_start';
525
+ content?: string;
526
+ } | {
527
+ type: 'text_delta';
528
+ content: string;
529
+ } | {
530
+ type: 'text_end';
531
+ content?: string;
532
+ } | {
533
+ type: 'tool_call_start';
534
+ id: string;
535
+ name: string;
536
+ } | {
537
+ type: 'tool_call_delta';
538
+ id: string;
539
+ arguments: string;
540
+ } | {
541
+ type: 'tool_call';
542
+ id: string;
543
+ name: string;
544
+ arguments: unknown;
545
+ } | {
546
+ type: 'tool_call_end';
547
+ id: string;
548
+ } | {
549
+ type: 'tool_result';
550
+ toolCallId: string;
551
+ result: string;
552
+ } | {
553
+ type: 'tool_error';
554
+ toolCallId: string;
555
+ error: Error;
556
+ } | {
557
+ type: 'thinking';
558
+ content: string;
559
+ signature?: string;
560
+ } | {
561
+ type: 'model_usage';
562
+ usage: TokenUsage;
563
+ /** Present when the provider distinguishes prompt vs completion usage timing (e.g. Anthropic). */
564
+ phase?: 'input' | 'output';
565
+ } | {
566
+ type: 'session_summary';
567
+ /** Authoritative cumulative usage for the completed run (prefer over end.usage when both exist). */
568
+ usage: TokenUsage;
569
+ iterations: number;
570
+ } | {
571
+ type: 'end';
572
+ timestamp: number;
573
+ /**
574
+ * Optional usage (e.g. aborted mid-stream). When a session_summary event was emitted, use its usage for totals.
575
+ */
576
+ usage?: TokenUsage;
577
+ /** Omitted or `complete` = normal completion */
578
+ reason?: 'complete' | 'aborted' | 'error';
579
+ error?: Error;
580
+ partialContent?: string;
581
+ } | {
582
+ type: 'context_compressed';
583
+ stats: {
584
+ originalMessageCount: number;
585
+ compressedMessageCount: number;
586
+ durationMs: number;
587
+ };
588
+ }) & StreamEventAnnotations;
589
+ /**
590
+ * MCP 服务器配置
591
+ */
592
+ interface MCPServerConfig {
593
+ /** 服务器名称 */
594
+ name: string;
595
+ /** 传输类型 */
596
+ transport: 'stdio' | 'http';
597
+ /** stdio 配置 */
598
+ command?: string;
599
+ args?: string[];
600
+ env?: Record<string, string>;
601
+ /** HTTP 配置 */
602
+ url?: string;
603
+ headers?: Record<string, string>;
604
+ }
605
+ /**
606
+ * MCP 资源内容
607
+ */
608
+ interface MCPResourceContent {
609
+ uri: string;
610
+ mimeType?: string;
611
+ text?: string;
612
+ blob?: string;
613
+ }
614
+ /**
615
+ * MCP Prompt 参数
616
+ */
617
+ interface MCPPromptArgument {
618
+ name: string;
619
+ description?: string;
620
+ required?: boolean;
621
+ }
622
+ /**
623
+ * Skill 元数据
624
+ */
625
+ interface SkillMetadata {
626
+ /** Skill 名称 */
627
+ name: string;
628
+ /** 描述 */
629
+ description: string;
630
+ /** 版本 */
631
+ version?: string;
632
+ /** 作者 */
633
+ author?: string;
634
+ /** 依赖的 Skills */
635
+ dependencies?: string[];
636
+ /** 标签 */
637
+ tags?: string[];
638
+ /** 参数提示,显示在自动补全中,如 "[filename]" */
639
+ argumentHint?: string;
640
+ /** 禁止模型自动调用此 skill,只能通过 /skill-name 手动调用 */
641
+ disableModelInvocation?: boolean;
642
+ /** 是否在 / 菜单中显示,默认 true */
643
+ userInvocable?: boolean;
644
+ }
645
+ /**
646
+ * Skill 定义
647
+ * Skill 只是一个指导书,不提供工具
648
+ */
649
+ interface SkillDefinition {
650
+ /** 元数据 */
651
+ metadata: SkillMetadata;
652
+ /** 文件路径 */
653
+ path: string;
654
+ /** 指令内容 */
655
+ instructions: string;
656
+ }
657
+ /**
658
+ * Skill 解析结果
659
+ */
660
+ interface ParsedSkill {
661
+ metadata: SkillMetadata;
662
+ content: string;
663
+ }
664
+ /**
665
+ * 系统提示配置
666
+ */
667
+ interface SystemPromptConfig {
668
+ /** 提示内容 */
669
+ content: string;
670
+ /** 模式: 'replace' 替换默认提示词, 'append' 追加到默认提示词 */
671
+ mode?: 'replace' | 'append';
672
+ /** 是否包含环境信息,默认 true */
673
+ includeEnvironment?: boolean;
674
+ }
675
+ /**
676
+ * 系统提示类型 - 支持字符串或配置对象
677
+ */
678
+ type SystemPrompt = string | SystemPromptConfig;
679
+ /**
680
+ * 上下文管理配置
681
+ */
682
+ interface ContextManagerConfig {
683
+ /** 上下文窗口大小 (从模型 capabilities 自动获取) */
684
+ contextLength?: number;
685
+ /** 最大输出 token 数 (从模型 capabilities 自动获取) */
686
+ maxOutputTokens?: number;
687
+ /** 压缩预留空间 (tokens), 默认 min(20000, maxOutputTokens) */
688
+ reserved?: number;
689
+ /** 自定义压缩器 */
690
+ compressor?: Compressor;
691
+ /** 是否启用 prune (清理旧工具输出), 默认 true */
692
+ prune?: boolean;
693
+ /** prune 触发阈值 (tokens), 默认 20000 */
694
+ pruneMinimum?: number;
695
+ /** prune 保护范围 (最近 N tokens 的工具输出不清理), 默认 40000 */
696
+ pruneProtect?: number;
697
+ }
698
+ /**
699
+ * 非自动批准的工具在调用前回调;返回 true 表示允许执行(与 Claude Agent SDK 的 canUseTool 概念对齐)。
700
+ */
701
+ type CanUseToolCallback = (toolName: string, input: Record<string, unknown>) => boolean | Promise<boolean>;
702
+ /**
703
+ * {@link ToolRegistry} 可选执行策略(与 {@link AgentConfig} 中 allowedTools / disallowedTools / canUseTool 对应)。
704
+ */
705
+ interface ToolExecutionPolicy {
706
+ disallowedTools?: string[];
707
+ /**
708
+ * 与 {@link AgentConfig.allowedTools} 相同。若设为**空数组** `[]`,则没有任何工具自动批准,每次执行均需 {@link canUseTool} 放行(未配置则拒绝)。
709
+ */
710
+ allowedTools?: string[];
711
+ canUseTool?: CanUseToolCallback;
712
+ }
713
+ /**
714
+ * Agent 配置
715
+ */
716
+ interface AgentConfig {
717
+ /** 模型适配器 */
718
+ model: ModelAdapter;
719
+ /** 系统提示 (字符串或配置对象) */
720
+ systemPrompt?: SystemPrompt;
721
+ /**
722
+ * 追加到默认内置工具(及 MCP)之后的自定义工具;同名会覆盖内置定义。
723
+ * 与 {@link exclusiveTools} 互斥:若设置了 `exclusiveTools`,则忽略本字段。
724
+ */
725
+ tools?: ToolDefinition[];
726
+ /**
727
+ * 自动批准的工具名列表(与注册名一致)。命中的调用直接执行,无需 {@link canUseTool}。
728
+ * 未列出的工具仍可对模型可见;其调用需经 `canUseTool`(若配置),否则拒绝。
729
+ * **未设置**时保持兼容:所有非 {@link disallowedTools} 工具均视为自动批准。
730
+ * **空数组** `[]` 表示无任何自动批准:所有工具调用均需 `canUseTool` 放行,未配置 `canUseTool` 则全部拒绝。
731
+ */
732
+ allowedTools?: string[];
733
+ /**
734
+ * 禁止的工具名:不注册、不纳入模型工具列表、不可执行(内置 / MCP / 自定义均按注册名生效)。
735
+ */
736
+ disallowedTools?: string[];
737
+ /**
738
+ * 当工具不在 {@link allowedTools} 中(且 `allowedTools` 已配置)时调用;返回 true 则执行。
739
+ */
740
+ canUseTool?: CanUseToolCallback;
741
+ /**
742
+ * 仅注册此处列出的工具(用于子 Agent 等排他场景),不合并默认内置,不追加 {@link tools}。
743
+ * 仍应用 {@link disallowedTools} 过滤。
744
+ */
745
+ exclusiveTools?: ToolDefinition[];
746
+ /**
747
+ * AskUserQuestion 交互解析(CLI / Web 等实现)。未设置时该工具仅返回题面、不阻塞。
748
+ */
749
+ askUserQuestion?: AskUserQuestionResolver;
750
+ /** Skill 路径列表 */
751
+ skills?: string[];
752
+ /** MCP 服务器配置 */
753
+ mcpServers?: MCPServerConfig[];
754
+ /** 用户级基础路径,默认 ~ (homedir),用于定位 .claude/ 目录 */
755
+ userBasePath?: string;
756
+ /** 存储配置 */
757
+ storage?: StorageConfig;
758
+ /** 最大迭代次数 */
759
+ maxIterations?: number;
760
+ /** 温度 */
761
+ temperature?: number;
762
+ /** 最大 Token 数 */
763
+ maxTokens?: number;
764
+ /** 是否启用流式 */
765
+ streaming?: boolean;
766
+ /** 会话 ID (用于恢复会话) */
767
+ sessionId?: string;
768
+ /** 回调函数 */
769
+ callbacks?: AgentCallbacks;
770
+ /** 是否启用长期记忆 */
771
+ memory?: boolean;
772
+ /** 记忆配置 */
773
+ memoryConfig?: MemoryConfig;
774
+ /** Skill 加载配置 */
775
+ skillConfig?: SkillConfig;
776
+ /** 上下文管理配置 */
777
+ contextManagement?: boolean | ContextManagerConfig;
778
+ /** 工作目录,默认 process.cwd() */
779
+ cwd?: string;
780
+ /** 是否注入环境信息到 system prompt,默认 true */
781
+ includeEnvironment?: boolean;
782
+ /** 工具 Hook 管理器(与配置文件合并规则见文档) */
783
+ hookManager?: HookManager;
784
+ /**
785
+ * 解析项目级 `.claude/settings.json` 的目录;设置后将在 Agent 初始化时加载 Hook 配置
786
+ */
787
+ hookConfigDir?: string;
788
+ /** Subagent 工具行为配置 */
789
+ subagent?: {
790
+ /** 是否启用 Agent 工具,默认 true */
791
+ enabled?: boolean;
792
+ /** 子代理最大深度,默认 1(禁止嵌套) */
793
+ maxDepth?: number;
794
+ /** 并发子代理上限,默认 5 */
795
+ maxParallel?: number;
796
+ /** 子代理默认超时(毫秒),默认 120000 */
797
+ timeoutMs?: number;
798
+ /** 是否允许子代理使用危险工具,默认 false */
799
+ allowDangerousTools?: boolean;
800
+ /** 子代理默认允许工具列表(为空时自动使用安全工具) */
801
+ defaultAllowedTools?: string[];
802
+ };
803
+ }
804
+ /**
805
+ * 记忆配置选项
806
+ */
807
+ interface MemoryConfig {
808
+ /** 工作空间记忆文件路径 */
809
+ workspacePath?: string;
810
+ }
811
+ /**
812
+ * Skill 加载配置选项
813
+ */
814
+ interface SkillConfig {
815
+ /** 是否启用默认路径加载,默认 true */
816
+ autoLoad?: boolean;
817
+ /** 工作空间 skills 路径,默认 ./.claude/skills/ */
818
+ workspacePath?: string;
819
+ /** 额外的 skills 路径列表 */
820
+ additionalPaths?: string[];
821
+ }
822
+ /**
823
+ * Agent 回调
824
+ */
825
+ interface AgentCallbacks {
826
+ /** 流式事件回调 */
827
+ onEvent?: (event: StreamEvent) => void;
828
+ /** 工具执行前回调 */
829
+ beforeToolCall?: (toolCall: ToolCall) => Promise<boolean | void>;
830
+ /** 工具执行后回调 */
831
+ afterToolCall?: (toolCall: ToolCall, result: ToolResult) => void;
832
+ /** 错误回调 */
833
+ onError?: (error: Error) => void;
834
+ }
835
+ /**
836
+ * Agent 执行结果
837
+ */
838
+ interface AgentResult {
839
+ /** 最终内容 */
840
+ content: string;
841
+ /** 工具调用历史 */
842
+ toolCalls?: Array<{
843
+ name: string;
844
+ arguments: unknown;
845
+ result: string;
846
+ }>;
847
+ /** Token 使用 */
848
+ usage?: TokenUsage;
849
+ /** 会话 ID */
850
+ sessionId: string;
851
+ /** 迭代次数 */
852
+ iterations: number;
853
+ }
854
+ /**
855
+ * CLI 配置
856
+ */
857
+ interface CLIConfig {
858
+ /** 模型 */
859
+ model?: string;
860
+ /** API Key */
861
+ apiKey?: string;
862
+ /** 基础 URL */
863
+ baseUrl?: string;
864
+ /** 模型名称 */
865
+ modelName?: string;
866
+ /** 温度 */
867
+ temperature?: number;
868
+ /** 最大 Token */
869
+ maxTokens?: number;
870
+ /** 输出格式 */
871
+ output?: 'text' | 'json' | 'markdown';
872
+ /** 是否流式 */
873
+ stream?: boolean;
874
+ /** 会话 ID */
875
+ session?: string;
876
+ /** 恢复最近一次会话(CLI chat/run) */
877
+ resume?: boolean;
878
+ /** 详细输出 */
879
+ verbose?: boolean;
880
+ /** MCP 配置文件路径 */
881
+ mcpConfig?: string;
882
+ /** 用户级基础路径,默认 ~ (homedir) */
883
+ userBasePath?: string;
884
+ /** 工作目录 */
885
+ cwd?: string;
886
+ /**
887
+ * Ollama `/api/chat` `think` option (boolean or GPT-OSS level).
888
+ * Used only when `-m`/`--model` is `ollama`.
889
+ */
890
+ ollamaThink?: boolean | 'low' | 'medium' | 'high';
891
+ }
892
+ /**
893
+ * CLI 命令选项
894
+ */
895
+ interface ChatOptions extends CLIConfig {
896
+ systemPrompt?: string;
897
+ tools?: string[];
898
+ }
899
+ interface RunOptions extends CLIConfig {
900
+ file?: string;
901
+ files?: string[];
902
+ }
903
+ interface ToolListOptions {
904
+ format?: 'table' | 'json';
905
+ }
906
+ interface SessionListOptions {
907
+ format?: 'table' | 'json';
908
+ limit?: number;
909
+ }
910
+ interface MCPOptions {
911
+ name?: string;
912
+ }
913
+ interface SkillOptions {
914
+ path?: string;
915
+ }
916
+
917
+ export { type StreamEventAnnotations as $, type AgentConfig as A, HookManager as B, type CLIConfig as C, type HookResult as D, type HooksSettings as E, type FlatCommandHookEntry as F, type HooksSettingsFile as G, type HookContext as H, type ImageContent as I, type MCPOptions as J, type MCPPromptArgument as K, type MCPResourceContent as L, type Message as M, type MessageRole as N, type ModelAdapter as O, type ParsedSkill as P, type ModelCapabilities as Q, type ModelParams as R, type StorageConfig as S, type ToolResult as T, type RunOptions as U, type SessionListOptions as V, type SkillConfig as W, type SkillDefinition as X, type SkillMetadata as Y, type SkillOptions as Z, type StreamChunkType as _, type SessionInfo as a, type StreamEventType as a0, type SystemMessage as a1, type SystemPromptConfig as a2, type TextContent as a3, type ThinkingContent as a4, type ToolCall as a5, type ToolExecutionContext as a6, type ToolExecutionPolicy as a7, type ToolHandler as a8, type ToolListOptions as a9, type ToolMessage as aa, type ToolResultMetadata as ab, type ToolSchema as ac, type UserMessage as ad, buildHookEnv as ae, createAskUserQuestionTool as af, createFunctionHook as ag, formatAnswerSummary as ah, formatAskUserQuestionPrompt as ai, getInteractionTools as aj, matchTool as ak, mergeCommandHookLayers as al, questionTool as am, type StorageAdapter as b, type ToolDefinition as c, type SystemPrompt as d, type StreamEvent as e, type AgentResult as f, type MCPServerConfig as g, type SessionTokenUsage as h, type TokenUsage as i, type StreamChunk as j, type MemoryConfig as k, type AgentCallbacks as l, type AskUserQuestionAnswer as m, type AskUserQuestionItem as n, type AskUserQuestionResolver as o, type AssistantMessage as p, type CanUseToolCallback as q, type ChatOptions as r, type CommandHookConfig as s, type CompletionResult as t, type ContentPart as u, type ContextManagerConfig as v, type CreateAskUserQuestionToolOptions as w, type FunctionHook as x, type HookEventType as y, type HookGroupConfig as z };