agentdev 0.1.9 → 0.2.1

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 (42) hide show
  1. package/dist/BasicAgent-7TNMYC3X.js +13 -0
  2. package/dist/ExplorerAgent-L3ZTVQGM.js +13 -0
  3. package/dist/{chunk-QFHPUAUQ.js → chunk-35LBACUK.js} +8 -8
  4. package/dist/{chunk-QFHPUAUQ.js.map → chunk-35LBACUK.js.map} +1 -1
  5. package/dist/{chunk-NORTAQIL.js → chunk-4WK7UENZ.js} +1011 -11
  6. package/dist/chunk-4WK7UENZ.js.map +1 -0
  7. package/dist/{chunk-BAP2GCYH.js → chunk-7GTVQ55R.js} +1 -1
  8. package/dist/chunk-7GTVQ55R.js.map +1 -0
  9. package/dist/{chunk-G5ECPY4K.js → chunk-EK6KGS2M.js} +87 -8
  10. package/dist/{chunk-G5ECPY4K.js.map → chunk-EK6KGS2M.js.map} +1 -1
  11. package/dist/{chunk-5T4C2XRT.js → chunk-KE3KYZVJ.js} +21 -8
  12. package/dist/chunk-KE3KYZVJ.js.map +1 -0
  13. package/dist/{chunk-EECW6PYP.js → chunk-UL2ZBPBL.js} +60 -4
  14. package/dist/chunk-UL2ZBPBL.js.map +1 -0
  15. package/dist/{chunk-A354ZCZF.js → chunk-XRB6MD2J.js} +5593 -982
  16. package/dist/chunk-XRB6MD2J.js.map +1 -0
  17. package/dist/cli/server.js +2 -2
  18. package/dist/cli/viewer.js +2 -2
  19. package/dist/create-feature-cli.js +26 -7
  20. package/dist/features/mcp/templates/mcp-tool.render.js +14 -1
  21. package/dist/features/mcp/templates/mcp-tool.render.js.map +1 -1
  22. package/dist/features/shell/templates/bash.render.d.ts +1 -1
  23. package/dist/features/websearch/templates/web-fetch.render.d.ts +1 -1
  24. package/dist/index.d.ts +778 -21
  25. package/dist/index.js +17 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/{notification-NWVOS2WR.js → notification-QPH37BHW.js} +29 -6
  28. package/dist/notification-QPH37BHW.js.map +1 -0
  29. package/dist/{tools-LDR3LIJP.js → tools-OKH7SPMP.js} +2 -2
  30. package/dist/{types-CF5UsxD9.d.ts → types-NVwNUVFR.d.ts} +180 -14
  31. package/package.json +7 -14
  32. package/dist/BasicAgent-UWXLSZP2.js +0 -13
  33. package/dist/ExplorerAgent-LCM3JQS4.js +0 -13
  34. package/dist/chunk-5T4C2XRT.js.map +0 -1
  35. package/dist/chunk-A354ZCZF.js.map +0 -1
  36. package/dist/chunk-BAP2GCYH.js.map +0 -1
  37. package/dist/chunk-EECW6PYP.js.map +0 -1
  38. package/dist/chunk-NORTAQIL.js.map +0 -1
  39. package/dist/notification-NWVOS2WR.js.map +0 -1
  40. /package/dist/{BasicAgent-UWXLSZP2.js.map → BasicAgent-7TNMYC3X.js.map} +0 -0
  41. /package/dist/{ExplorerAgent-LCM3JQS4.js.map → ExplorerAgent-L3ZTVQGM.js.map} +0 -0
  42. /package/dist/{tools-LDR3LIJP.js.map → tools-OKH7SPMP.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { E as EnrichedMessage, M as MessageTag, a as Message, L as LLMResponse, T as ToolCall, b as Tool, A as AgentConfig, I as InlineRenderTemplate, c as LogContextRef, d as ToolRenderConfig, H as HookInspectorSnapshot, e as AgentOverviewSnapshot, f as AgentInfo, N as Notification, U as UserInputRequest, g as UserInputResponse, h as UsageStatsSnapshot, i as TemplateSource, j as TemplateLoader, k as UsageStats, P as PlaceholderContext, l as UsageInfo, m as UserInputAction, n as LLMClient, o as MessageRole, p as AgentSession } from './types-CF5UsxD9.js';
2
- export { C as CacheStats, q as ContextMiddleware, D as DebugHubIPCMessage, r as TemplateComposer, s as TemplateError, t as TemplateLoaderOptions, u as TemplateResult, v as ToolMetadata, w as getDefaultUDSPath } from './types-CF5UsxD9.js';
1
+ import { E as EnrichedMessage, M as MessageTag, a as Message, L as LLMResponse, T as ToolCall, b as Tool, A as AgentConfig, I as InlineRenderTemplate, c as LogContextRef, d as ToolRenderConfig, H as HookInspectorSnapshot, e as AgentOverviewSnapshot, f as AgentInfo, N as Notification, U as UserInputRequest, g as UserInputResponse, h as UsageStatsSnapshot, i as TemplateSource, j as TemplateLoader, k as UsageStats, P as PlaceholderContext, l as UsageInfo, m as UserInputAction, n as UserInputQuestion, o as UserInputChoiceAnswer, p as LLMClient, q as MessageRole, r as AgentSession } from './types-NVwNUVFR.js';
2
+ export { C as CacheStats, s as ContextMiddleware, D as DebugHubIPCMessage, t as MessageUsage, u as TemplateComposer, v as TemplateError, w as TemplateLoaderOptions, x as TemplateResult, y as ToolMetadata, z as getDefaultUDSPath } from './types-NVwNUVFR.js';
3
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
+ import { EventEmitter } from 'events';
5
+ import { Diagnostic } from 'vscode-languageserver-types';
4
6
  import { IncomingMessage, ServerResponse } from 'http';
5
7
 
6
8
  /**
@@ -272,6 +274,54 @@ interface PackageInfo {
272
274
  /** 包根目录绝对路径 */
273
275
  root: string;
274
276
  }
277
+ /**
278
+ * Feature Manifest 配置项
279
+ *
280
+ * 用于声明 Feature 在 Agent Project 级别可配置的静态参数。
281
+ * Claw 等消费端可根据该契约自动渲染表单。
282
+ */
283
+ interface FeatureManifestSettingProperty {
284
+ type: 'string' | 'number' | 'boolean' | 'select' | 'file' | 'directory' | 'group';
285
+ title: string;
286
+ description?: string;
287
+ default?: unknown;
288
+ options?: Array<{
289
+ label: string;
290
+ value: string | number | boolean;
291
+ }>;
292
+ placeholder?: string;
293
+ /** number 类型下的最小值 */
294
+ min?: number;
295
+ /** number 类型下的最大值 */
296
+ max?: number;
297
+ /** number 类型下的步进值 */
298
+ step?: number;
299
+ /** file 类型下的可接受文件类型,如 '.mp3,.wav' 或 'audio/*' */
300
+ accept?: string | string[];
301
+ /** directory 类型下的最大条目数 */
302
+ maxItems?: number;
303
+ /** type: 'group' 时的嵌套子属性 */
304
+ properties?: Record<string, FeatureManifestSettingProperty>;
305
+ /** 条件可见性:仅当同级指定属性值在 values 中时渲染此字段 */
306
+ showWhen?: {
307
+ property: string;
308
+ values: (string | number | boolean)[];
309
+ };
310
+ }
311
+ interface FeatureManifestDefinition {
312
+ schemaVersion: 1;
313
+ settings?: {
314
+ properties: Record<string, FeatureManifestSettingProperty>;
315
+ /** 有序分区,用于 UI 分组渲染。省略则平铺全部属性 */
316
+ sections?: Array<{
317
+ id: string;
318
+ title: string;
319
+ description?: string;
320
+ /** 分区内属性 key 的显示顺序 */
321
+ properties: string[];
322
+ }>;
323
+ };
324
+ }
275
325
  /**
276
326
  * Feature 初始化上下文
277
327
  */
@@ -383,6 +433,13 @@ interface AgentFeature {
383
433
  * ```
384
434
  */
385
435
  getRenderTemplates?(): Record<string, InlineRenderTemplate>;
436
+ /**
437
+ * 声明 Feature 的项目级静态配置契约(Manifest)
438
+ *
439
+ * 该契约回答“这个 Feature 平时怎么工作”,
440
+ * 与 Flow 节点中的 Mode(什么时候、以什么状态工作)是正交的。
441
+ */
442
+ getFeatureManifest?(): FeatureManifestDefinition | null;
386
443
  /**
387
444
  * 声明上下文注入器
388
445
  */
@@ -489,6 +546,13 @@ interface CallStartContext {
489
546
  /** Agent 实例(用于访问 setUserInput/getUserInput 等 API) */
490
547
  agent?: any;
491
548
  }
549
+ /**
550
+ * Call 结束原因
551
+ *
552
+ * 让 @CallFinish 钩子能结构化地判断 call 为什么结束,
553
+ * 不再需要解析 response 字符串前缀。
554
+ */
555
+ type CallFinishReason = 'completed' | 'interrupted' | 'api_error' | 'error' | 'max_steps' | 'continuation' | 'exception';
492
556
  /**
493
557
  * Call 结束上下文
494
558
  */
@@ -503,6 +567,8 @@ interface CallFinishContext {
503
567
  steps: number;
504
568
  /** 是否成功完成 */
505
569
  completed: boolean;
570
+ /** 结束原因 */
571
+ finishReason: CallFinishReason;
506
572
  }
507
573
  /**
508
574
  * Step 开始上下文
@@ -518,6 +584,8 @@ interface StepStartContext {
518
584
  context: Context;
519
585
  /** 原始用户输入 */
520
586
  input: string;
587
+ /** Agent 实例(用于访问当前会话中的 Feature、工具和输入状态) */
588
+ agent?: any;
521
589
  }
522
590
  /**
523
591
  * Step 结束上下文
@@ -719,6 +787,8 @@ declare function createTool(config: {
719
787
  parameters?: Record<string, any>;
720
788
  execute: (args: any, context?: any) => Promise<any>;
721
789
  render?: ToolRenderInput;
790
+ executionMode?: 'normal' | 'exclusive';
791
+ parallelizable?: boolean;
722
792
  }, sourceFile?: string): Tool;
723
793
  /**
724
794
  * 工具注册表 - 管理多个工具
@@ -726,24 +796,51 @@ declare function createTool(config: {
726
796
  declare class ToolRegistry {
727
797
  private tools;
728
798
  private enabled;
799
+ private disabled;
729
800
  private pendingDisabled;
801
+ private pendingRemoved;
730
802
  private sources;
803
+ private superseded;
731
804
  /**
732
805
  * 注册工具(默认启用,记录来源)
733
806
  */
734
807
  register(tool: Tool, source?: string): this;
735
808
  /**
736
- * 禁用工具
809
+ * 禁用工具(LLM 可见,但执行时会被拦截)
737
810
  */
738
811
  disable(name: string): boolean;
739
812
  /**
740
813
  * 启用工具
741
814
  */
742
815
  enable(name: string): boolean;
816
+ /**
817
+ * 移除工具(LLM 不可见,承接旧 disable 行为)
818
+ */
819
+ remove(name: string): boolean;
820
+ /**
821
+ * 取消移除工具,恢复为启用状态
822
+ */
823
+ unremove(name: string): boolean;
743
824
  /**
744
825
  * 检查工具是否启用
745
826
  */
746
827
  isEnabled(name: string): boolean;
828
+ /**
829
+ * 检查工具是否禁用(屏蔽)
830
+ */
831
+ isDisabled(name: string): boolean;
832
+ /**
833
+ * 检查工具是否移除
834
+ */
835
+ isRemoved(name: string): boolean;
836
+ /**
837
+ * 检查工具是否为 exclusive 模式
838
+ */
839
+ isExclusive(name: string): boolean;
840
+ /**
841
+ * 检查工具是否可并行执行
842
+ */
843
+ isParallelizable(name: string): boolean;
747
844
  /**
748
845
  * 获取工具来源(调试用)
749
846
  */
@@ -753,6 +850,7 @@ declare class ToolRegistry {
753
850
  */
754
851
  getEntries(): Array<{
755
852
  tool: Tool;
853
+ state: 'enabled' | 'disabled' | 'removed' | 'superseded';
756
854
  enabled: boolean;
757
855
  source?: string;
758
856
  }>;
@@ -761,7 +859,7 @@ declare class ToolRegistry {
761
859
  */
762
860
  get(name: string): Tool | undefined;
763
861
  /**
764
- * 获取所有工具(只返回启用的)
862
+ * 获取所有 LLM 可见工具(启用 + 禁用)
765
863
  */
766
864
  getAll(): Tool[];
767
865
  /**
@@ -811,11 +909,14 @@ declare class DebugHub {
811
909
  private nextId;
812
910
  private readonly processId;
813
911
  private pendingInputRequests;
912
+ private queuedInputHandler?;
913
+ private interruptHandler?;
814
914
  private activeInputRequests;
815
915
  private udsClient?;
816
916
  private udsPath;
817
917
  private workerPort;
818
918
  private clientReady;
919
+ private stopped;
819
920
  private registrationLock;
820
921
  private messageQueue;
821
922
  private reconnectTimer?;
@@ -889,6 +990,13 @@ declare class DebugHub {
889
990
  getCurrentAgentId(): string | null;
890
991
  getTransportMode(): 'viewer-worker' | 'claw';
891
992
  getCapabilities(): DebugCapabilities;
993
+ setQueuedInputHandler(handler?: (agentId: string, input: {
994
+ id: string;
995
+ text: string;
996
+ timestamp: number;
997
+ }) => void | Promise<void>): void;
998
+ setInterruptHandler(handler?: (agentId: string, clearQueue: boolean) => void | Promise<void>): void;
999
+ consumeQueuedInput(agentId: string, inputId: string): void;
892
1000
  /**
893
1001
  * 根据 Agent 实例获取其 ID
894
1002
  */
@@ -943,6 +1051,45 @@ declare class DebugHub {
943
1051
  private sendToWorker;
944
1052
  }
945
1053
 
1054
+ /**
1055
+ * Continuation Request 类型定义
1056
+ *
1057
+ * 控制工具(如 checkpoint、rollback)通过 registerContinuationRequest()
1058
+ * 登记一个 continuation request,使当前 onCall 在合法边界停止。
1059
+ * 宿主(如 CallArbiter)通过 consumeContinuationRequest() 消费该请求,
1060
+ * 决定是否在同一个逻辑 envelope 内启动下一个 onCall segment。
1061
+ */
1062
+ /**
1063
+ * Checkpoint continuation request
1064
+ *
1065
+ * Agent 建立了一个命名检查点,希望继续执行。
1066
+ * 宿主应捕获当前 runtime snapshot 并将其与 checkpointId 关联,
1067
+ * 然后启动 continuation segment。
1068
+ */
1069
+ interface CheckpointContinuationRequest {
1070
+ kind: 'checkpoint';
1071
+ checkpointId: string;
1072
+ /** 可选附加元数据(如 Agent 的自由备注) */
1073
+ metadata?: Record<string, unknown>;
1074
+ }
1075
+ /**
1076
+ * Rollback continuation request
1077
+ *
1078
+ * Agent 希望回退到指定 checkpoint,并携带一个失败分支的摘要。
1079
+ * 宿主应恢复到 checkpoint 的 runtime snapshot,
1080
+ * 然后以摘要作为 continuation segment 的输入启动新的 onCall。
1081
+ */
1082
+ interface RollbackContinuationRequest {
1083
+ kind: 'rollback';
1084
+ checkpointId: string;
1085
+ /** Agent 生成的失败分支摘要 */
1086
+ summary: string;
1087
+ }
1088
+ /**
1089
+ * 受类型约束的 continuation request
1090
+ */
1091
+ type CallContinuationRequest = CheckpointContinuationRequest | RollbackContinuationRequest;
1092
+
946
1093
  interface FeatureCheckpoint {
947
1094
  featureName: string;
948
1095
  snapshot: FeatureStateSnapshot;
@@ -960,6 +1107,26 @@ interface CallRollbackSnapshot {
960
1107
  draftInput: string;
961
1108
  runtime: AgentRuntimeSnapshot;
962
1109
  }
1110
+ /**
1111
+ * 命名检查点 — 由 Agent 自主建立的可恢复快照
1112
+ *
1113
+ * 与 CallRollbackSnapshot 的区别:
1114
+ * - CallRollbackSnapshot 面向"回到某个用户 call 之前",是 onCall 的副产品
1115
+ * - NamedCheckpoint 面向"Agent 主动建立的恢复点",有稳定 ID,可跨 segment 引用
1116
+ *
1117
+ * checkpoint 表示控制工具执行完成、tool result 已写入、
1118
+ * 当前 segment 已完全结束之后的 runtime 状态(协议完整)。
1119
+ */
1120
+ interface NamedCheckpoint {
1121
+ /** 全局唯一的 checkpoint ID(由 Agent 提供) */
1122
+ id: string;
1123
+ /** 创建时间戳 */
1124
+ createdAt: number;
1125
+ /** 创建时的 callIndex */
1126
+ sourceCallIndex: number;
1127
+ /** 完整的 runtime snapshot */
1128
+ runtime: AgentRuntimeSnapshot;
1129
+ }
963
1130
  interface AgentSessionSnapshot {
964
1131
  version: number;
965
1132
  sessionId: string;
@@ -967,6 +1134,8 @@ interface AgentSessionSnapshot {
967
1134
  agentType: string;
968
1135
  runtime: AgentRuntimeSnapshot;
969
1136
  rollbackHistory: CallRollbackSnapshot[];
1137
+ /** 命名检查点列表(可选,用于 checkpoint/rollback 能力) */
1138
+ namedCheckpoints?: NamedCheckpoint[];
970
1139
  }
971
1140
  interface SessionStore {
972
1141
  save(sessionId: string, snapshot: AgentSessionSnapshot): Promise<string>;
@@ -1023,8 +1192,12 @@ declare class AgentBase {
1023
1192
  protected _callIndex: number;
1024
1193
  protected _callStartTimes: Map<number, number>;
1025
1194
  protected _callCheckpoints: CallRollbackCheckpoint[];
1195
+ protected _namedCheckpoints: NamedCheckpoint[];
1026
1196
  protected usageStats: UsageStats;
1197
+ private _continuationRequest;
1027
1198
  private _pendingInput;
1199
+ private _abortController;
1200
+ private _stepAutoSave?;
1028
1201
  private templateResolver?;
1029
1202
  private toolExecutor?;
1030
1203
  private reactRunner?;
@@ -1051,6 +1224,27 @@ declare class AgentBase {
1051
1224
  * @returns 当前输入缓存,如果未设置则返回空字符串
1052
1225
  */
1053
1226
  getUserInput(): string;
1227
+ /**
1228
+ * 登记一个 continuation request
1229
+ *
1230
+ * 控制工具(如 checkpoint、rollback)在正常完成执行后调用此方法,
1231
+ * 使当前 onCall 在工具结果闭合后停止,并将请求传递给宿主。
1232
+ *
1233
+ * 该方法仅在 onCall 执行期间有效。onCall 开始时会清理上一次的遗留请求。
1234
+ */
1235
+ registerContinuationRequest(request: CallContinuationRequest): void;
1236
+ /**
1237
+ * 消费当前 continuation request(一次性)
1238
+ *
1239
+ * 宿主(如 CallArbiter)在 onCall 返回后调用此方法,
1240
+ * 判断是否需要在同一逻辑 envelope 内启动下一个 segment。
1241
+ *
1242
+ * - 请求只能消费一次,消费后自动清除。
1243
+ * - onCall 开始时也会清理上次未消费的请求。
1244
+ *
1245
+ * @returns 当前 continuation request,如果没有则返回 null
1246
+ */
1247
+ consumeContinuationRequest(): CallContinuationRequest | null;
1054
1248
  /**
1055
1249
  * 唯一的公开入口 - 执行 Agent
1056
1250
  */
@@ -1081,13 +1275,64 @@ declare class AgentBase {
1081
1275
  * 从会话快照恢复
1082
1276
  */
1083
1277
  restoreSessionSnapshot(snapshot: AgentSessionSnapshot): Promise<this>;
1278
+ /**
1279
+ * 中断正在运行的 onCall
1280
+ * 会触发 AbortController,在下一个检查点(step 间或 tool 执行中)优雅停止
1281
+ * 返回 true 表示成功触发中断,false 表示当前没有正在运行的 call
1282
+ */
1283
+ interrupt(): boolean;
1284
+ /**
1285
+ * 当前是否正在执行 onCall
1286
+ */
1287
+ isRunning(): boolean;
1084
1288
  rollbackToCall(callIndex: number): Promise<{
1085
1289
  draftInput: string;
1086
1290
  }>;
1291
+ /**
1292
+ * 创建一个命名检查点
1293
+ *
1294
+ * 捕获当前完整 runtime snapshot 并将其与 checkpointId 关联。
1295
+ * 应在 onCall 完全退出后、由宿主(CallArbiter)的 checkpoint barrier 调用。
1296
+ *
1297
+ * @param id 全局唯一的 checkpoint ID
1298
+ * @returns 创建的 NamedCheckpoint
1299
+ */
1300
+ createNamedCheckpoint(id: string): Promise<NamedCheckpoint>;
1301
+ /**
1302
+ * 回退到命名检查点
1303
+ *
1304
+ * 恢复到指定 checkpoint 的 runtime snapshot,
1305
+ * 并剪除该 checkpoint 之后创建的所有命名检查点。
1306
+ * 应在 onCall 完全退出后、由宿主(CallArbiter)的 rollback barrier 调用。
1307
+ *
1308
+ * @param id 目标 checkpoint ID
1309
+ * @throws 如果 checkpoint 不存在
1310
+ */
1311
+ rollbackToNamedCheckpoint(id: string): Promise<void>;
1312
+ /**
1313
+ * 获取所有命名检查点(只读视图)
1314
+ */
1315
+ getNamedCheckpoints(): readonly NamedCheckpoint[];
1316
+ /**
1317
+ * 清除所有命名检查点
1318
+ *
1319
+ * 用于单 checkpoint 模式:创建新 checkpoint 前清除旧的。
1320
+ */
1321
+ clearNamedCheckpoints(): void;
1087
1322
  /**
1088
1323
  * 保存会话到持久化存储
1089
1324
  */
1090
1325
  saveSession(sessionId: string, store?: SessionStore): Promise<string>;
1326
+ /**
1327
+ * 启用 Step 级自动保存:每个 ReAct step 完成后自动将 session 快照写入磁盘。
1328
+ * 不会替换 CallFinish 后的 saveSession 调用——后者仍作为兜底全量保存。
1329
+ */
1330
+ enableStepAutoSave(sessionId: string, store: SessionStore): void;
1331
+ /**
1332
+ * 禁用 Step 级自动保存
1333
+ */
1334
+ disableStepAutoSave(): void;
1335
+ private _createStepSaveFn;
1091
1336
  /**
1092
1337
  * 从持久化存储加载会话
1093
1338
  */
@@ -1158,6 +1403,13 @@ declare class AgentBase {
1158
1403
  * 使用 Feature(链式调用)
1159
1404
  */
1160
1405
  use(feature: AgentFeature): this;
1406
+ /**
1407
+ * 彻底移除一个 Feature:移除其工具并从 features Map 中删除
1408
+ *
1409
+ * @example
1410
+ * agent.removeFeature('subagent') // 移除 SubAgentFeature
1411
+ */
1412
+ removeFeature(featureName: string): this;
1161
1413
  /**
1162
1414
  * 启用 Feature 的所有工具
1163
1415
  *
@@ -1172,6 +1424,13 @@ declare class AgentBase {
1172
1424
  * agent.disable('mcp') // 禁用 MCP 工具
1173
1425
  */
1174
1426
  disable(featureName: string): this;
1427
+ /**
1428
+ * 移除 Feature 的所有工具(从 LLM 工具列表物理移除)
1429
+ *
1430
+ * @example
1431
+ * agent.remove('mcp') // 移除 MCP 工具
1432
+ */
1433
+ remove(featureName: string): this;
1175
1434
  /**
1176
1435
  * 检查 Feature 是否启用
1177
1436
  *
@@ -1187,6 +1446,35 @@ declare class AgentBase {
1187
1446
  * 确保 Feature 工具已注册
1188
1447
  */
1189
1448
  private ensureFeatureTools;
1449
+ /**
1450
+ * 为单个 Feature 执行工具注册、onInitiate 和 hooks 收集。
1451
+ *
1452
+ * 被 ensureFeatureTools() 和 mountFeature() 共用。
1453
+ */
1454
+ private initSingleFeature;
1455
+ /**
1456
+ * 动态挂载 Feature(运行时)
1457
+ *
1458
+ * 与 use() 不同,mountFeature 会在 agent 已初始化的情况下
1459
+ * 立即对新 feature 执行工具注册、onInitiate 和 hooks 收集。
1460
+ *
1461
+ * 如果 agent 尚未初始化(未发生首次 onCall),feature 会被加入 Map,
1462
+ * 后续由 ensureFeatureTools() 统一处理。
1463
+ *
1464
+ * @example
1465
+ * await agent.mountFeature(new SomeFeature());
1466
+ */
1467
+ mountFeature(feature: AgentFeature): Promise<this>;
1468
+ /**
1469
+ * 在所有 Feature 工具注册完毕后、inspector snapshot 推送之前调用。
1470
+ * 子类可重写此方法注册额外工具(如统一代理工具覆盖同名 feature 工具)。
1471
+ */
1472
+ protected onFeatureToolsReady(): Promise<void>;
1473
+ /**
1474
+ * 收集所有 Feature 自带的 skills
1475
+ * 约定:Feature 目录下存在 skills/ 目录则自动发现
1476
+ */
1477
+ private collectFeatureSkills;
1190
1478
  /**
1191
1479
  * 解析相对路径(处理 ./ 和 ../)
1192
1480
  * @param baseDir 基础目录
@@ -1480,6 +1768,7 @@ declare class MCPConnectionManager {
1480
1768
  private sendDirectRequest;
1481
1769
  private normalizeToolCallResponse;
1482
1770
  private rejectAllPendingRequests;
1771
+ private stopProcess;
1483
1772
  dispose(): Promise<void>;
1484
1773
  }
1485
1774
 
@@ -1521,6 +1810,8 @@ declare class MCPFeature implements AgentFeature {
1521
1810
  readonly description = "\u8FDE\u63A5 MCP \u670D\u52A1\u5668\u5E76\u628A\u53D1\u73B0\u5230\u7684\u8FDC\u7A0B\u80FD\u529B\u6302\u8F7D\u6210\u6807\u51C6\u5DE5\u5177\u3002";
1522
1811
  private readonly manager;
1523
1812
  private clients;
1813
+ private readonly input?;
1814
+ private readonly options;
1524
1815
  private config?;
1525
1816
  private mcpContext?;
1526
1817
  /**
@@ -1536,6 +1827,9 @@ declare class MCPFeature implements AgentFeature {
1536
1827
  */
1537
1828
  getTemplateNames(): string[];
1538
1829
  constructor(input?: MCPFeatureInput, options?: MCPFeatureOptions);
1830
+ getFeatureManifest(): FeatureManifestDefinition;
1831
+ private resolveFeatureConfig;
1832
+ private resolveRuntimeConfig;
1539
1833
  /**
1540
1834
  * 获取同步工具(无)
1541
1835
  */
@@ -1543,7 +1837,7 @@ declare class MCPFeature implements AgentFeature {
1543
1837
  /**
1544
1838
  * 获取异步工具(需要连接 MCP 服务器)
1545
1839
  */
1546
- getAsyncTools(_ctx: FeatureInitContext): Promise<Tool[]>;
1840
+ getAsyncTools(ctx: FeatureInitContext): Promise<Tool[]>;
1547
1841
  /**
1548
1842
  * 声明上下文注入器
1549
1843
  * 为所有 MCP 工具注入 _mcpContext
@@ -1592,6 +1886,8 @@ interface AuditFeatureConfig {
1592
1886
  dbPath?: string;
1593
1887
  /** 缓存有效期(天数,0 表示永久,默认 0) */
1594
1888
  cacheTtlDays?: number;
1889
+ /** 工作目录(默认 process.cwd()) */
1890
+ workspaceDir?: string;
1595
1891
  }
1596
1892
  /**
1597
1893
  * AuditFeature 实现
@@ -1665,6 +1961,8 @@ declare class AuditFeature implements AgentFeature {
1665
1961
  interface AudioFeedbackConfig {
1666
1962
  /** 音频文件路径(相对于 feature 目录或绝对路径) */
1667
1963
  audioPath?: string;
1964
+ /** 失败时的音频文件路径(留空时使用内置 error.mp3) */
1965
+ errorAudioPath?: string;
1668
1966
  /** 是否启用音频反馈(默认:true) */
1669
1967
  enabled?: boolean;
1670
1968
  /** 音量(0-1,默认:0.5) */
@@ -1685,6 +1983,27 @@ declare class AudioFeedbackFeature implements AgentFeature {
1685
1983
  private readonly runtime;
1686
1984
  private logger?;
1687
1985
  constructor(config?: AudioFeedbackConfig);
1986
+ getFeatureManifest(): FeatureManifestDefinition;
1987
+ getFlowModes(): {
1988
+ id: string;
1989
+ title: string;
1990
+ description: string;
1991
+ }[];
1992
+ getFlowVariables(): ({
1993
+ key: string;
1994
+ type: "boolean";
1995
+ title: string;
1996
+ description: string;
1997
+ resolver: () => boolean;
1998
+ } | {
1999
+ key: string;
2000
+ type: "number";
2001
+ title: string;
2002
+ description: string;
2003
+ resolver: () => number;
2004
+ })[];
2005
+ applyFlowMode(modeId: string): void;
2006
+ resetFlowModes(): void;
1688
2007
  /**
1689
2008
  * 公开 API:启用或禁用音频反馈
1690
2009
  */
@@ -1701,8 +2020,26 @@ declare class AudioFeedbackFeature implements AgentFeature {
1701
2020
  restoreState(snapshot: FeatureStateSnapshot): void;
1702
2021
  /**
1703
2022
  * 核心功能:在 call 完成时播放音频
2023
+ *
2024
+ * 根据 finishReason 区分成功 / 失败,播放不同音效:
2025
+ * - completed → 成功音
2026
+ * - interrupted / api_error / error / exception / max_steps → 失败音
2027
+ * - continuation → 不播放(call 暂停续接,非真正结束)
1704
2028
  */
1705
2029
  playAudioOnCallFinish(ctx: CallFinishContext): Promise<void>;
2030
+ /**
2031
+ * 稳健的跨平台音频播放
2032
+ *
2033
+ * 替代第三方 sound-play 库。sound-play 在 Windows 上使用
2034
+ * `Start-Sleep -s $player.NaturalDuration.TimeSpan.TotalSeconds` 来
2035
+ * 等待播放结束,但 NaturalDuration 在 MediaPlayer.Open() 的异步加载
2036
+ * 完成前会抛出 InvalidOperationException,导致 PowerShell 进程提前
2037
+ * 退出、声音被截断——表现为"有时有声音有时没有"。
2038
+ *
2039
+ * 本方法在 Windows 上使用 Dispatcher.PushFrame 消息循环正确等待
2040
+ * MediaOpened 事件,确保媒体加载完毕后再读取时长。
2041
+ */
2042
+ private _playSound;
1706
2043
  }
1707
2044
 
1708
2045
  interface MemoryFeatureConfig {
@@ -1712,6 +2049,8 @@ interface MemoryFeatureConfig {
1712
2049
  forceInject?: boolean;
1713
2050
  /** 读取 CLAUDE.md 的工作目录 */
1714
2051
  workspaceDir?: string;
2052
+ /** 宿主资源目录;如果提供,优先从这里读取 CLAUDE.md */
2053
+ resourceRoot?: string;
1715
2054
  }
1716
2055
  declare class MemoryFeature implements AgentFeature {
1717
2056
  readonly name = "memory";
@@ -1719,7 +2058,7 @@ declare class MemoryFeature implements AgentFeature {
1719
2058
  readonly source: string;
1720
2059
  readonly description = "\u81EA\u52A8\u8BFB\u53D6\u5E76\u6CE8\u5165\u9879\u76EE CLAUDE.md \u6587\u4EF6\u4F5C\u4E3A\u7CFB\u7EDF\u63D0\u793A\u8BCD\u3002";
1721
2060
  private filename;
1722
- private workspaceDir;
2061
+ private sourceRoot;
1723
2062
  private _packageInfo;
1724
2063
  constructor(config?: MemoryFeatureConfig);
1725
2064
  /**
@@ -1761,6 +2100,12 @@ interface SkillMetadata {
1761
2100
  interface SkillsOptions {
1762
2101
  /** skills 目录,默认 cwd/.agentdev/skills */
1763
2102
  dir?: string;
2103
+ /** 是否扫描 cwd/.agentdev/skills,默认 true */
2104
+ scanAgentdevDir?: boolean;
2105
+ /** 是否扫描 cwd/.claude/skills,默认 false */
2106
+ scanClaudeDir?: boolean;
2107
+ /** 额外 skills 目录列表,至多 5 个 */
2108
+ extraDirs?: string[];
1764
2109
  }
1765
2110
 
1766
2111
  /**
@@ -1785,6 +2130,12 @@ interface SkillsOptions {
1785
2130
  interface SkillFeatureConfig extends SkillsOptions {
1786
2131
  /** Skills 目录路径 */
1787
2132
  dir?: string;
2133
+ /** 是否扫描 .agentdev/skills,默认 true */
2134
+ scanAgentdevDir?: boolean;
2135
+ /** 是否扫描 .claude/skills,默认 false */
2136
+ scanClaudeDir?: boolean;
2137
+ /** 额外 skills 目录列表 */
2138
+ extraDirs?: string[];
1788
2139
  }
1789
2140
  /**
1790
2141
  * Skill Feature 输入类型
@@ -1800,6 +2151,10 @@ declare class SkillFeature implements AgentFeature {
1800
2151
  readonly description = "\u53D1\u73B0\u672C\u5730 skills\uFF0C\u5E76\u63D0\u4F9B invoke_skill \u5DE5\u5177\u4E0E\u6280\u80FD\u6570\u636E\u6E90\u3002";
1801
2152
  private skillsDir?;
1802
2153
  private skills;
2154
+ private featureSkills;
2155
+ private scanAgentdevDir;
2156
+ private scanClaudeDir;
2157
+ private extraDirs;
1803
2158
  /**
1804
2159
  * 缓存包信息
1805
2160
  */
@@ -1817,6 +2172,35 @@ declare class SkillFeature implements AgentFeature {
1817
2172
  * 获取同步工具(invoke_skill)
1818
2173
  */
1819
2174
  getTools(): Tool[];
2175
+ /**
2176
+ * 向 Flow 暴露 Skills 相关变量
2177
+ */
2178
+ getFlowVariables(): ({
2179
+ key: string;
2180
+ type: string;
2181
+ title: string;
2182
+ description: string;
2183
+ resolver: () => string[];
2184
+ } | {
2185
+ key: string;
2186
+ type: string;
2187
+ title: string;
2188
+ description: string;
2189
+ resolver: () => string;
2190
+ })[];
2191
+ /**
2192
+ * 向 Flow 暴露可直接复用的节点 Prompt 模板
2193
+ */
2194
+ getFlowNodeTemplates(): {
2195
+ id: string;
2196
+ name: string;
2197
+ description: string;
2198
+ prompt: string;
2199
+ tools: {
2200
+ enable: string[];
2201
+ };
2202
+ }[];
2203
+ getFeatureManifest(): FeatureManifestDefinition;
1820
2204
  /**
1821
2205
  * 声明上下文注入器
1822
2206
  * 为 invoke_skill 工具注入 _context.skills
@@ -1827,6 +2211,11 @@ declare class SkillFeature implements AgentFeature {
1827
2211
  * 执行 Skills 发现并注册数据源
1828
2212
  */
1829
2213
  onInitiate(ctx: FeatureInitContext): Promise<void>;
2214
+ /**
2215
+ * 注入来自其他 Feature 的 skills
2216
+ * 由 Agent 在 onInitiate 之前调用
2217
+ */
2218
+ addFeatureSkills(skills: SkillMetadata[]): void;
1830
2219
  /**
1831
2220
  * 获取已加载的 Skills
1832
2221
  */
@@ -2218,6 +2607,10 @@ interface QQBotFeatureConfig {
2218
2607
  systemPrompt?: string;
2219
2608
  /** 附加配置(传递给 Gateway) */
2220
2609
  cfg?: Record<string, unknown>;
2610
+ /** 工作目录(默认 process.cwd()) */
2611
+ workspaceDir?: string;
2612
+ /** 宿主资源目录;默认从这里查找 .agentdev/qqbot.config.json */
2613
+ resourceRoot?: string;
2221
2614
  }
2222
2615
  /**
2223
2616
  * QQBotFeature - QQ 机器人 Feature
@@ -2273,7 +2666,15 @@ declare class QQBotFeature implements AgentFeature {
2273
2666
  /**
2274
2667
  * Shell Feature 工具定义
2275
2668
  *
2276
- * 提供 run_shell_command 工具,通过 Git Bash 执行 Shell 命令
2669
+ * 提供 bash 工具,通过 Git Bash 执行 Shell 命令,支持 AbortSignal 中断。
2670
+ *
2671
+ * 改进点(照搬 Claude Code 的优秀实践):
2672
+ * 1. 命令引用:eval + 单引号包裹,彻底解决 syntax error near unexpected token '('
2673
+ * 2. 非 -i 模式:去掉 interactive flag,消除 job control 警告
2674
+ * 3. stdin redirect:自动添加 < /dev/null 防止命令挂起
2675
+ * 4. Windows null rewrite:>nul → >/dev/null
2676
+ * 5. 动态 Git Bash 路径检测
2677
+ * 6. 输出截断:防止大输出撑爆 LLM 上下文
2277
2678
  */
2278
2679
 
2279
2680
  interface ShellExecutionResult {
@@ -2283,10 +2684,10 @@ interface ShellExecutionResult {
2283
2684
  }
2284
2685
 
2285
2686
  /**
2286
- * Shell Feature - Git Bash 命令执行工具 + 安全删除/恢复工具
2687
+ * Shell Feature - Shell 命令执行工具 + 安全删除/恢复工具
2287
2688
  *
2288
- * 通过 Git Bash 执行 Shell 命令,description 从内部配置加载
2289
- * 提供安全删除、列表和恢复功能
2689
+ * 支持 Git Bash PowerShell 两种 Shell 环境。
2690
+ * 根据用户配置和运行时探测结果,条件注册 Bash 和/或 PowerShell 工具。
2290
2691
  *
2291
2692
  * @example
2292
2693
  * ```typescript
@@ -2297,6 +2698,7 @@ interface ShellExecutionResult {
2297
2698
 
2298
2699
  interface ShellFeatureConfig {
2299
2700
  workspaceDir?: string;
2701
+ workdir?: string;
2300
2702
  resourceRoot?: string;
2301
2703
  }
2302
2704
  /**
@@ -2306,13 +2708,20 @@ declare class ShellFeature implements AgentFeature {
2306
2708
  readonly name = "shell";
2307
2709
  readonly dependencies: string[];
2308
2710
  readonly source: string;
2309
- readonly description = "\u63D0\u4F9B bash \u6267\u884C\u80FD\u529B\uFF0C\u4EE5\u53CA\u5B89\u5168\u5220\u9664\u3001\u6062\u590D\u548C\u67E5\u770B\u5783\u573E\u6876\u5DE5\u5177\u3002";
2711
+ readonly description = "\u63D0\u4F9B Bash/PowerShell \u547D\u4EE4\u6267\u884C\u80FD\u529B\uFF0C\u4EE5\u53CA\u5B89\u5168\u5220\u9664\u3001\u6062\u590D\u548C\u67E5\u770B\u5783\u573E\u6876\u5DE5\u5177\u3002";
2310
2712
  private bashDescription?;
2713
+ private powershellDescription?;
2311
2714
  private _packageInfo;
2312
2715
  private readonly workspaceDir;
2716
+ private readonly workdir;
2313
2717
  private readonly resourceRoot;
2314
2718
  constructor(config?: ShellFeatureConfig);
2315
2719
  run(command: string): Promise<ShellExecutionResult>;
2720
+ getFeatureManifest(): FeatureManifestDefinition;
2721
+ /**
2722
+ * 解析 featureConfig 为结构化配置
2723
+ */
2724
+ private resolveShellConfig;
2316
2725
  /**
2317
2726
  * 获取包信息(统一打包方案)
2318
2727
  */
@@ -2326,9 +2735,9 @@ declare class ShellFeature implements AgentFeature {
2326
2735
  */
2327
2736
  getTools(): Tool[];
2328
2737
  /**
2329
- * 获取异步工具(bash 工具,加载 description)
2738
+ * 获取异步工具(bash/powershell 工具,条件注册)
2330
2739
  */
2331
- getAsyncTools(_ctx: FeatureInitContext): Promise<Tool[]>;
2740
+ getAsyncTools(ctx: FeatureInitContext): Promise<Tool[]>;
2332
2741
  }
2333
2742
 
2334
2743
  /**
@@ -2697,6 +3106,8 @@ declare class TodoFeature implements AgentFeature {
2697
3106
  * TTS Feature 配置选项
2698
3107
  */
2699
3108
  interface TTSFeatureConfig {
3109
+ /** 工作目录(默认 process.cwd()) */
3110
+ workspaceDir?: string;
2700
3111
  /**
2701
3112
  * Python 可执行文件路径
2702
3113
  * 默认:项目 .venv 中的 Python 或系统 PATH 中的 python
@@ -2945,6 +3356,8 @@ declare class UserInputFeature implements AgentFeature {
2945
3356
  */
2946
3357
  getUserInput(prompt?: string, timeout?: number): Promise<string>;
2947
3358
  getUserInputEvent(prompt?: string, timeout?: number, actions?: UserInputAction[]): Promise<UserInputResponse>;
3359
+ requestUserChoices(prompt: string, questions: UserInputQuestion[], timeout?: number): Promise<UserInputChoiceAnswer[]>;
3360
+ private normalizeChoiceQuestions;
2948
3361
  getTools(): Tool[];
2949
3362
  onInitiate(_ctx: FeatureInitContext): Promise<void>;
2950
3363
  onDestroy(_ctx: FeatureContext): Promise<void>;
@@ -3024,6 +3437,8 @@ interface VisualUnderstandingResult {
3024
3437
  * VisualFeature 配置
3025
3438
  */
3026
3439
  interface VisualFeatureConfig {
3440
+ /** 工作目录(默认 process.cwd()) */
3441
+ workspaceDir?: string;
3027
3442
  /** LLM 服务地址(默认 localhost:7575) */
3028
3443
  baseUrl?: string;
3029
3444
  /** 视觉理解模型名称(默认 Qwen3.5-4B-Q5_K_M) */
@@ -3474,6 +3889,117 @@ declare class WebSearchFeature implements AgentFeature {
3474
3889
  getTemplateNames(): string[];
3475
3890
  }
3476
3891
 
3892
+ interface DiffStats {
3893
+ filesChanged: string[];
3894
+ insertions: number;
3895
+ deletions: number;
3896
+ }
3897
+
3898
+ /**
3899
+ * FileHistoryFeature - 文件修改历史追踪与回退
3900
+ *
3901
+ * 独立 Feature,无侵入地接入 AgentDev 的 checkpoint/rollback 体系:
3902
+ *
3903
+ * - @ToolUse 反向钩子:在 write/edit 执行前自动备份文件
3904
+ * - @CallStart 反向钩子:在每轮用户输入时创建快照
3905
+ * - captureState/restoreState:与 Agent 的 CallRollback 集成(仅恢复内存状态)
3906
+ * - rewindToSnapshot / rewindToLastSnapshot:用户显式触发的文件回退
3907
+ *
3908
+ * 文件回退是独立于对话回退的操作(与 Claude Code 的设计一致),
3909
+ * 用户可以选择"仅回退代码"/"仅回退对话"/"两者都回退"。
3910
+ *
3911
+ * 使用方式(消费端,如 Claw):
3912
+ * const fh = agent.features?.get('file-history');
3913
+ * if (fh) {
3914
+ * const snapshots = fh.getSnapshotList();
3915
+ * await fh.rewindToSnapshot(selectedId);
3916
+ * }
3917
+ */
3918
+
3919
+ interface FileHistoryFeatureConfig {
3920
+ /** 覆盖工作区目录,默认 process.cwd() */
3921
+ workspaceDir?: string;
3922
+ }
3923
+ type SnapshotInfo = {
3924
+ id: number;
3925
+ timestamp: number;
3926
+ trackedFileCount: number;
3927
+ };
3928
+ declare class FileHistoryFeature implements AgentFeature {
3929
+ readonly name = "file-history";
3930
+ readonly dependencies: string[];
3931
+ readonly source: string;
3932
+ readonly description = "\u8FFD\u8E2A\u6587\u4EF6\u4FEE\u6539\u5386\u53F2\uFF0C\u652F\u6301\u4EE3\u7801\u56DE\u9000\u5230\u4EFB\u610F\u8F6E\u6B21\u7684\u72B6\u6001\u3002";
3933
+ private _packageInfo;
3934
+ private logger;
3935
+ private state;
3936
+ private readonly workspaceDir;
3937
+ constructor(config?: FileHistoryFeatureConfig);
3938
+ getPackageInfo(): PackageInfo | null;
3939
+ onInitiate(ctx: FeatureInitContext): Promise<void>;
3940
+ onDestroy(_ctx: FeatureContext): Promise<void>;
3941
+ /**
3942
+ * @ToolUse 反向钩子:在 write/edit 工具执行前备份文件
3943
+ *
3944
+ * 在所有 Feature 的 @ToolUse 钩子中,本钩子只关注 write/edit 两个工具,
3945
+ * 其余一律放行 (Decision.Continue)。
3946
+ */
3947
+ trackFileEdits(ctx: ToolContext): Promise<DecisionResult>;
3948
+ /**
3949
+ * @CallStart 反向钩子:每轮用户输入时创建文件快照
3950
+ *
3951
+ * 第一次 CallStart 创建空快照,后续 CallStart 检测已追踪文件是否有变化,
3952
+ * 有变化的创建新版本备份。
3953
+ */
3954
+ onCallStart(_ctx: any): Promise<void>;
3955
+ /**
3956
+ * 捕获当前文件历史状态(纯内存,不碰磁盘)
3957
+ *
3958
+ * 由 Agent 的 commitCallCheckpoint 调用。
3959
+ * 保存快照元数据,使得 rollbackToCall 时能恢复到对应的文件历史状态。
3960
+ */
3961
+ captureState(): FeatureStateSnapshot;
3962
+ /**
3963
+ * 恢复文件历史状态(仅恢复内存,不恢复磁盘文件)
3964
+ *
3965
+ * 在三种场景下被调用:step rollback、call rollback、session load。
3966
+ * 这里只恢复内存中的快照索引,不做文件回退。
3967
+ * 文件回退由用户显式调用 rewindToSnapshot / rewindToLastSnapshot 触发。
3968
+ */
3969
+ restoreState(snapshot: FeatureStateSnapshot): void;
3970
+ /**
3971
+ * 获取快照列表(供 UI 展示)
3972
+ */
3973
+ getSnapshotList(): SnapshotInfo[];
3974
+ /**
3975
+ * 获取当前追踪的文件数量
3976
+ */
3977
+ getTrackedFileCount(): number;
3978
+ /**
3979
+ * 获取快照数量
3980
+ */
3981
+ getSnapshotCount(): number;
3982
+ /**
3983
+ * 回退文件到指定快照
3984
+ *
3985
+ * @returns 被修改的文件路径列表
3986
+ */
3987
+ rewindToSnapshot(snapshotId: number): Promise<string[]>;
3988
+ /**
3989
+ * 回退文件到当前内存状态的最后一个快照
3990
+ *
3991
+ * 典型用法:先 rollbackToCall 恢复对话 + 内存状态,再调此方法恢复文件。
3992
+ * await agent.rollbackToCall(targetCallIndex)
3993
+ * const fh = agent.features?.get('file-history')
3994
+ * await fh?.rewindToLastSnapshot()
3995
+ */
3996
+ rewindToLastSnapshot(): Promise<string[]>;
3997
+ /**
3998
+ * 计算回退到指定快照的 diff 统计(预览用,不修改文件)
3999
+ */
4000
+ getDiffStats(snapshotId: number): Promise<DiffStats>;
4001
+ }
4002
+
3477
4003
  interface OpencodeBasicFeatureConfig {
3478
4004
  workspaceDir?: string;
3479
4005
  }
@@ -3588,6 +4114,130 @@ declare class ExampleFeature implements AgentFeature {
3588
4114
  handleStepFinish(ctx: StepFinishDecisionContext): Promise<typeof Decision.Continue>;
3589
4115
  }
3590
4116
 
4117
+ /**
4118
+ * LSP Feature 类型定义
4119
+ */
4120
+ /**
4121
+ * LSP Server handle returned by spawn functions
4122
+ */
4123
+ interface LspServerHandle {
4124
+ process: any;
4125
+ initialization?: Record<string, any>;
4126
+ }
4127
+ /**
4128
+ * Configuration for a single LSP server
4129
+ */
4130
+ interface LspServerConfig {
4131
+ disabled?: boolean;
4132
+ binary?: string;
4133
+ /** Launch mode override */
4134
+ mode?: 'exec' | 'runtime';
4135
+ /** Runtime type, only meaningful when mode='runtime' */
4136
+ runtime?: 'nodejs' | 'uv';
4137
+ /** npm package name for nodejs runtime (npx <package>) */
4138
+ package?: string;
4139
+ /** Package name for uv runtime (uv tool run <package>), if different */
4140
+ uvPackage?: string;
4141
+ /** Additional arguments passed to the server */
4142
+ args?: string[];
4143
+ command?: string[];
4144
+ extensions?: string[];
4145
+ env?: Record<string, string>;
4146
+ initialization?: Record<string, any>;
4147
+ }
4148
+ /**
4149
+ * LSP Feature configuration
4150
+ */
4151
+ interface LspFeatureConfig {
4152
+ workdir?: string;
4153
+ binDir?: string;
4154
+ disableDownload?: boolean;
4155
+ /** Shared runtime binary paths */
4156
+ runtimes?: {
4157
+ nodejs?: string;
4158
+ uv?: string;
4159
+ };
4160
+ servers?: Record<string, LspServerConfig>;
4161
+ }
4162
+
4163
+ /**
4164
+ * LSP Client - 通过 JSON-RPC 与 LSP 服务器通信
4165
+ */
4166
+
4167
+ /**
4168
+ * LSP Client - 处理与 LSP 服务器的 JSON-RPC 通信
4169
+ */
4170
+ declare class LspClient extends EventEmitter {
4171
+ private serverID;
4172
+ private handle;
4173
+ private root;
4174
+ private logger;
4175
+ private connection;
4176
+ private diagnostics;
4177
+ private files;
4178
+ constructor(serverID: string, handle: LspServerHandle, root: string, logger: {
4179
+ info: (msg: string, data?: any) => void;
4180
+ error: (msg: string, data?: any) => void;
4181
+ });
4182
+ private setupHandlers;
4183
+ initialize(): Promise<void>;
4184
+ get serverId(): string;
4185
+ get clientRoot(): string;
4186
+ getDiagnostics(): Map<string, Diagnostic[]>;
4187
+ notifyOpen(filePath: string): Promise<void>;
4188
+ waitForDiagnostics(filePath: string): Promise<void>;
4189
+ definition(filePath: string, line: number, character: number): Promise<unknown>;
4190
+ references(filePath: string, line: number, character: number): Promise<unknown>;
4191
+ hover(filePath: string, line: number, character: number): Promise<unknown>;
4192
+ documentSymbol(uri: string): Promise<unknown>;
4193
+ workspaceSymbol(query: string): Promise<unknown>;
4194
+ implementation(filePath: string, line: number, character: number): Promise<unknown>;
4195
+ prepareCallHierarchy(filePath: string, line: number, character: number): Promise<unknown>;
4196
+ incomingCalls(filePath: string, line: number, character: number): Promise<unknown>;
4197
+ outgoingCalls(filePath: string, line: number, character: number): Promise<unknown>;
4198
+ shutdown(): Promise<void>;
4199
+ }
4200
+
4201
+ /**
4202
+ * LSP Feature - Language Server Protocol 代码智能
4203
+ *
4204
+ * 为 AI agent 提供代码智能能力:跳转定义、查找引用、悬停提示等
4205
+ * 支持 14 种语言的 LSP 服务器,每个支持 exec / runtime 两种启动模式
4206
+ */
4207
+
4208
+ declare class LspFeature implements AgentFeature {
4209
+ readonly name = "lsp";
4210
+ readonly dependencies: string[];
4211
+ readonly source: string;
4212
+ readonly description = "LSP (Language Server Protocol) - \u63D0\u4F9B\u4EE3\u7801\u667A\u80FD\u80FD\u529B\uFF1A\u8DF3\u8F6C\u5B9A\u4E49\u3001\u67E5\u627E\u5F15\u7528\u3001\u60AC\u505C\u63D0\u793A\u7B49";
4213
+ private config;
4214
+ private _packageInfo;
4215
+ private logger;
4216
+ private clients;
4217
+ private spawning;
4218
+ private broken;
4219
+ constructor(config?: LspFeatureConfig);
4220
+ getPackageInfo(): PackageInfo | null;
4221
+ getTemplateNames(): string[];
4222
+ getTools(): Tool[];
4223
+ getAsyncTools(_ctx: FeatureInitContext): Promise<Tool[]>;
4224
+ onInitiate(ctx: FeatureInitContext): Promise<void>;
4225
+ onDestroy(): Promise<void>;
4226
+ getFeatureManifest(): FeatureManifestDefinition;
4227
+ captureState(): {
4228
+ activeServerIds: string[];
4229
+ };
4230
+ restoreState(_state: any): void;
4231
+ getWorkdir(): string;
4232
+ hasServer(file: string): Promise<boolean>;
4233
+ touchFile(file: string): Promise<void>;
4234
+ executeOnFile<T>(file: string, fn: (client: LspClient) => Promise<T>): Promise<T[]>;
4235
+ executeAll<T>(fn: (client: LspClient) => Promise<T>): Promise<T[]>;
4236
+ private getClientsForFile;
4237
+ private spawnServer;
4238
+ private shutdownAll;
4239
+ }
4240
+
3591
4241
  /**
3592
4242
  * 配置加载
3593
4243
  * 从 config 目录读取 JSON 配置文件
@@ -3596,6 +4246,17 @@ declare class ExampleFeature implements AgentFeature {
3596
4246
  * - loadConfig() - 异步加载(用于特殊场景)
3597
4247
  * - loadConfigSync() - 同步加载(推荐,用于 Agent 构造)
3598
4248
  */
4249
+ /**
4250
+ * 自定义请求头条目
4251
+ * - valueMode 'static': 使用 value 原样
4252
+ * - valueMode 'uuid': 每次请求生成新的 UUID v4
4253
+ * - valueMode 'random': 每次请求生成新的随机数
4254
+ */
4255
+ interface CustomHeaderEntry {
4256
+ key: string;
4257
+ value: string;
4258
+ valueMode?: 'static' | 'uuid' | 'random';
4259
+ }
3599
4260
  /**
3600
4261
  * 统一配置类型
3601
4262
  * 字段允许冗余,各 LLM 实现只取自己需要的
@@ -3609,6 +4270,10 @@ interface ModelConfig {
3609
4270
  thinkingBudgetTokens?: number;
3610
4271
  thinkingKeepTurns?: number;
3611
4272
  providerOptions?: Record<string, unknown>;
4273
+ /** 追加到每次 LLM API 请求的自定义请求头 */
4274
+ customHeaders?: CustomHeaderEntry[];
4275
+ /** OpenAI 专用接口面:chat / responses */
4276
+ apiSurface?: 'chat' | 'responses';
3612
4277
  region?: string;
3613
4278
  projectId?: string;
3614
4279
  }
@@ -3684,6 +4349,10 @@ interface BasicAgentConfig {
3684
4349
  tools?: Tool[];
3685
4350
  /** Skills 目录(可选,默认使用 .agentdev/skills) */
3686
4351
  skillsDir?: string;
4352
+ /** SkillFeature 完整配置(可选,覆盖 skillsDir) */
4353
+ skillConfig?: SkillFeatureConfig;
4354
+ /** Feature 特定配置(可选) */
4355
+ features?: AgentConfig['features'];
3687
4356
  /** 调试器和模板解析使用的项目根目录 */
3688
4357
  projectRoot?: string;
3689
4358
  /** 工具默认操作的工作目录 */
@@ -3863,13 +4532,19 @@ interface CompiledAnthropicRequest {
3863
4532
  }
3864
4533
  declare class AnthropicLLM implements LLMClient {
3865
4534
  private readonly apiKey;
3866
- private readonly modelName;
4535
+ private readonly _modelName;
3867
4536
  private readonly baseUrl;
3868
4537
  private readonly maxTokens;
3869
4538
  private readonly thinkingBudgetTokens?;
3870
4539
  private readonly thinkingKeepTurns;
3871
- constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, thinkingBudgetTokens?: number | undefined, thinkingKeepTurns?: number);
3872
- chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;
4540
+ private readonly customHeaders?;
4541
+ private initPromise;
4542
+ /** 返回当前 LLM 实例使用的模型名 */
4543
+ get modelName(): string;
4544
+ constructor(apiKey: string, _modelName?: string, baseUrl?: string, maxTokens?: number, thinkingBudgetTokens?: number | undefined, thinkingKeepTurns?: number, customHeaders?: CustomHeaderEntry[] | undefined);
4545
+ chat(messages: Message[], tools: Tool[], options?: {
4546
+ signal?: AbortSignal;
4547
+ }): Promise<LLMResponse>;
3873
4548
  }
3874
4549
  declare function compileContextForAnthropic(messages: Message[], tools: Tool[]): CompiledAnthropicRequest;
3875
4550
  declare function createAnthropicLLM(config: AgentConfigFile): AnthropicLLM;
@@ -3883,14 +4558,20 @@ declare function createAnthropicLLM(apiKey: string, modelName: string, baseUrl?:
3883
4558
 
3884
4559
  declare class OpenAILLM implements LLMClient {
3885
4560
  private client;
3886
- private modelName;
4561
+ private _modelName;
3887
4562
  private maxTokens?;
3888
4563
  private providerOptions?;
3889
- constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, providerOptions?: Record<string, unknown>);
4564
+ private customHeaders?;
4565
+ private initPromise;
4566
+ /** 返回当前 LLM 实例使用的模型名 */
4567
+ get modelName(): string;
4568
+ constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, providerOptions?: Record<string, unknown>, customHeaders?: CustomHeaderEntry[]);
3890
4569
  /**
3891
- * 聊天 - 核心方法(内部使用流式处理)
4570
+ * 聊天 - 核心方法(内部使用流式处理,带重试)
3892
4571
  */
3893
- chat(messages: Message[], tools: Tool[]): Promise<LLMResponse>;
4572
+ chat(messages: Message[], tools: Tool[], options?: {
4573
+ signal?: AbortSignal;
4574
+ }): Promise<LLMResponse>;
3894
4575
  }
3895
4576
 
3896
4577
  /**
@@ -3916,6 +4597,53 @@ declare function createOpenAILLM(config: AgentConfigFile): OpenAILLM;
3916
4597
  declare function createOpenAILLM(modelConfig: ModelConfig): OpenAILLM;
3917
4598
  declare function createOpenAILLM(apiKey: string, modelName: string, baseUrl?: string): OpenAILLM;
3918
4599
 
4600
+ /**
4601
+ * OpenAI Responses LLM 适配器
4602
+ *
4603
+ * 只负责把框架的 Message / Tool 编译为 Responses 输入,
4604
+ * 再把 Responses 输出收敛回 LLMResponse。
4605
+ */
4606
+
4607
+ type ResponsesRequest = {
4608
+ model: string;
4609
+ input: any[];
4610
+ tools?: Array<Record<string, unknown>>;
4611
+ max_output_tokens?: number;
4612
+ parallel_tool_calls?: boolean;
4613
+ reasoning?: Record<string, unknown>;
4614
+ previous_response_id?: string;
4615
+ store?: boolean;
4616
+ text?: Record<string, unknown>;
4617
+ include?: Array<string>;
4618
+ [key: string]: unknown;
4619
+ };
4620
+ declare class OpenAIResponsesLLM implements LLMClient {
4621
+ private client;
4622
+ private _modelName;
4623
+ private maxTokens?;
4624
+ private thinkingBudgetTokens?;
4625
+ private providerOptions?;
4626
+ private customHeaders?;
4627
+ private initPromise;
4628
+ /** 返回当前 LLM 实例使用的模型名 */
4629
+ get modelName(): string;
4630
+ constructor(apiKey: string, modelName?: string, baseUrl?: string, maxTokens?: number, thinkingBudgetTokens?: number, providerOptions?: Record<string, unknown>, customHeaders?: CustomHeaderEntry[]);
4631
+ chat(messages: Message[], tools: Tool[], options?: {
4632
+ signal?: AbortSignal;
4633
+ }): Promise<LLMResponse>;
4634
+ private createResponsesCompletion;
4635
+ }
4636
+ interface CompileOpenAIResponsesOptions {
4637
+ modelName?: string;
4638
+ maxTokens?: number;
4639
+ thinkingBudgetTokens?: number;
4640
+ providerOptions?: Record<string, unknown>;
4641
+ }
4642
+ declare function compileContextForOpenAIResponses(messages: Message[], tools: Tool[], options?: CompileOpenAIResponsesOptions): ResponsesRequest;
4643
+ declare function createOpenAIResponsesLLM(config: AgentConfigFile): OpenAIResponsesLLM;
4644
+ declare function createOpenAIResponsesLLM(modelConfig: ModelConfig): OpenAIResponsesLLM;
4645
+ declare function createOpenAIResponsesLLM(apiKey: string, modelName: string, baseUrl?: string): OpenAIResponsesLLM;
4646
+
3919
4647
  declare function createLLM(config: AgentConfigFile): LLMClient;
3920
4648
  declare function createLLM(modelConfig: ModelConfig): LLMClient;
3921
4649
  declare function createLLM(apiKey: string, modelName: string, provider?: string, baseUrl?: string): LLMClient;
@@ -4029,6 +4757,27 @@ declare class ViewerWorker {
4029
4757
  * 提交用户输入
4030
4758
  */
4031
4759
  private handlePostInput;
4760
+ /**
4761
+ * 排队用户输入(运行期间提交的消息)
4762
+ */
4763
+ private handleQueueInput;
4764
+ /**
4765
+ * 获取排队中的用户输入
4766
+ */
4767
+ private handleGetQueuedInputs;
4768
+ /**
4769
+ * 消费第一条排队消息
4770
+ */
4771
+ private handleDequeueInput;
4772
+ private handleConsumeQueuedInput;
4773
+ /**
4774
+ * 中断正在运行的 Agent
4775
+ */
4776
+ private handleInterrupt;
4777
+ /**
4778
+ * 查询 Agent 是否正在运行
4779
+ */
4780
+ private handleGetRunning;
4032
4781
  /**
4033
4782
  * 获取或创建会话
4034
4783
  */
@@ -4062,6 +4811,12 @@ declare class ViewerWorker {
4062
4811
  */
4063
4812
  handlePushMessages(msg: any): void;
4064
4813
  private createEmptyOverview;
4814
+ private createEmptyRuntimeState;
4815
+ private cloneRuntimeState;
4816
+ private getRuntimeStageFromLLMPhase;
4817
+ private updateRuntimeStage;
4818
+ private getSessionRuntimeState;
4819
+ private getMergedOverview;
4065
4820
  /**
4066
4821
  * 检查消息是否发生变化
4067
4822
  */
@@ -4330,6 +5085,8 @@ declare function createListRenderer<T = any>(config: Omit<DataSourceRenderer<T>,
4330
5085
  declare function discover(options?: SkillsOptions): Promise<SkillMetadata[]>;
4331
5086
 
4332
5087
  interface LoadAllMCPConfigsOptions {
5088
+ loadDefaultDir?: boolean;
5089
+ extraConfigFiles?: string[];
4333
5090
  excludeServers?: string[];
4334
5091
  }
4335
5092
  declare function getDefaultMCPConfigDir(rootDir?: string): string;
@@ -4373,4 +5130,4 @@ declare function renderMCPToolCall(serverName: string, toolName: string, args: R
4373
5130
  */
4374
5131
  declare function renderMCPToolResult(result: any, success?: boolean): string;
4375
5132
 
4376
- export { AgentBase as Agent, AgentConfig, type AgentConfigFile, type AgentFeature, AgentInfo, type AgentInitiateContext, AgentPool, AgentSession, type AgentSessionSnapshot, AnthropicLLM, AudioFeedbackFeature, AuditFeature, type AuditFeatureConfig, BasicAgent, type BasicAgentConfig, CallFinish, type CallFinishContext, CallStart, type CallStartContext, type CaptureResult, Context, type ContextInjector, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, Decision, type DecisionResult, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureContext, type FeatureInitContext, type FeatureStateSnapshot, FileSessionStore, type HookResult, InlineRenderTemplate, type KnownUser, LLMClient, LLMResponse, type LoadAllMCPConfigsOptions, type Logger, type LoggerBindings, MCPClient, type MCPClientConfig, type MCPConfig, type MCPConfigMountOptions, type MCPConnectionInfo, MCPConnectionManager, MCPConnectionState, type MCPDiscoveredTool, type MCPDiscoveredToolSet, MCPFeature, type MCPFeatureOptions, type MCPHTTPConfig, type MCPMountedConfigResult, type MCPMountedToolSet, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPStatistics, MCPToolAdapter, type MCPToolAdapterConfig, type MCPToolCreationOptions, type MCPToolDiscoveryOptions, type MCPToolManagementOptions, type MCPToolPatch, type MCPToolResult, MCP_RENDER_TEMPLATES, MemoryFeature, type MemoryFeatureConfig, Message, MessageRole, type ModelConfig, OpenAILLM, OpencodeBasicFeature, type PackageInfo, PlaceholderContext, PlaceholderResolver, PluginCompatFeature, QQBotFeature, type QQBotFeatureConfig, type QQBotSendOptions, type QQBotSendResult, type SessionStore, ShellFeature, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, StepFinish, type StepFinishedContext, StepStart, type StepStartContext, SubAgentFeature, type SystemContext$1 as SystemContext, TTSFeature, type TTSFeatureConfig, type TTSResult, type TTSState, type TaskStatus, TemplateLoader, TemplateSource, TodoFeature, type TodoFeatureConfig, type TodoTask, type TodoTaskSummary, Tool, ToolCall, type ToolContext, type ToolContextValue, ToolFinished, ToolRegistry, ToolRenderConfig, type ToolResult, ToolUse, UserInputFeature, type UserInputFeatureConfig, ViewerWorker, VisualFeature, type VisualFeatureConfig, type VisualUnderstandingResult, WebSearchFeature, type WebSearchFeatureConfig, type WindowInfo, assistant, compileContextForAnthropic, createAnthropicLLM, createDefaultMCPToolName, createLLM, createListRenderer, createLogger, createMCPTool, createMCPToolAdapters, createMCPToolsFromClient, createManagedMCPToolsFromClient, createMessage, createOpenAILLM, createTool, discover, discoverMCPTools, discoverManagedMCPTools, getClawRuntimeUrl, getDebugCapabilities, getDefaultMCPConfigDir, getDefaultSessionStore, getMCPRenderTemplate, getPackageInfoFromSource, installConsoleBridge, listConfigs, loadAllMCPConfigs, loadConfig, loadConfigSync, loadMCPConfigFromInput, mountMCPToolsFromConfig, renderMCPToolCall, renderMCPToolResult, resolveDebugTransportMode, runWithLogScope, system, toolResult, user };
5133
+ export { AgentBase as Agent, AgentConfig, type AgentConfigFile, type AgentFeature, AgentInfo, type AgentInitiateContext, AgentPool, AgentSession, type AgentSessionSnapshot, AnthropicLLM, AudioFeedbackFeature, AuditFeature, type AuditFeatureConfig, BasicAgent, type BasicAgentConfig, type CallContinuationRequest, CallFinish, type CallFinishContext, type CallFinishReason, CallStart, type CallStartContext, type CaptureResult, type CheckpointContinuationRequest, Context, type ContextInjector, type ContextSnapshot, DataSourceRegistry, type DataSourceRenderer, type DebugCapabilities, DebugHub, Decision, type DecisionResult, ExampleFeature, type ExampleFeatureConfig, type ExampleFeatureRuntimeState, type ExampleFeatureSnapshot, ExplorerAgent, type ExplorerAgentConfig, type SystemContext as ExplorerSystemContext, type FeatureContext, type FeatureInitContext, type FeatureManifestDefinition, type FeatureManifestSettingProperty, type FeatureStateSnapshot, FileHistoryFeature, type FileHistoryFeatureConfig, FileSessionStore, type HookResult, InlineRenderTemplate, type KnownUser, LLMClient, LLMResponse, type LoadAllMCPConfigsOptions, type Logger, type LoggerBindings, LspFeature, type LspFeatureConfig, MCPClient, type MCPClientConfig, type MCPConfig, type MCPConfigMountOptions, type MCPConnectionInfo, MCPConnectionManager, MCPConnectionState, type MCPDiscoveredTool, type MCPDiscoveredToolSet, MCPFeature, type MCPFeatureOptions, type MCPHTTPConfig, type MCPMountedConfigResult, type MCPMountedToolSet, type MCPSSEConfig, type MCPServerConfig, type MCPSstdioConfig, type MCPStatistics, MCPToolAdapter, type MCPToolAdapterConfig, type MCPToolCreationOptions, type MCPToolDiscoveryOptions, type MCPToolManagementOptions, type MCPToolPatch, type MCPToolResult, MCP_RENDER_TEMPLATES, MemoryFeature, type MemoryFeatureConfig, Message, MessageRole, type ModelConfig, type NamedCheckpoint, OpenAILLM, OpenAIResponsesLLM, OpencodeBasicFeature, type PackageInfo, PlaceholderContext, PlaceholderResolver, PluginCompatFeature, QQBotFeature, type QQBotFeatureConfig, type QQBotSendOptions, type QQBotSendResult, type RollbackContinuationRequest, type SessionStore, ShellFeature, SkillFeature, type SkillFeatureConfig, type SkillMetadata, type SkillsOptions, type SnapshotInfo, StepFinish, type StepFinishedContext, StepStart, type StepStartContext, SubAgentFeature, type SystemContext$1 as SystemContext, TTSFeature, type TTSFeatureConfig, type TTSResult, type TTSState, type TaskStatus, TemplateLoader, TemplateSource, TodoFeature, type TodoFeatureConfig, type TodoTask, type TodoTaskSummary, Tool, ToolCall, type ToolContext, type ToolContextValue, ToolFinished, ToolRegistry, ToolRenderConfig, type ToolResult, ToolUse, UserInputFeature, type UserInputFeatureConfig, ViewerWorker, VisualFeature, type VisualFeatureConfig, type VisualUnderstandingResult, WebSearchFeature, type WebSearchFeatureConfig, type WindowInfo, assistant, compileContextForAnthropic, compileContextForOpenAIResponses, createAnthropicLLM, createDefaultMCPToolName, createLLM, createListRenderer, createLogger, createMCPTool, createMCPToolAdapters, createMCPToolsFromClient, createManagedMCPToolsFromClient, createMessage, createOpenAILLM, createOpenAIResponsesLLM, createTool, discover, discoverMCPTools, discoverManagedMCPTools, getClawRuntimeUrl, getDebugCapabilities, getDefaultMCPConfigDir, getDefaultSessionStore, getMCPRenderTemplate, getPackageInfoFromSource, installConsoleBridge, listConfigs, loadAllMCPConfigs, loadConfig, loadConfigSync, loadMCPConfigFromInput, mountMCPToolsFromConfig, renderMCPToolCall, renderMCPToolResult, resolveDebugTransportMode, runWithLogScope, system, toolResult, user };