wave-agent-sdk 0.2.1 → 0.5.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 (194) hide show
  1. package/dist/agent.d.ts +66 -20
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +156 -83
  4. package/dist/constants/prompts.d.ts +7 -2
  5. package/dist/constants/prompts.d.ts.map +1 -1
  6. package/dist/constants/prompts.js +41 -5
  7. package/dist/constants/tools.d.ts +2 -2
  8. package/dist/constants/tools.js +2 -2
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/managers/MemoryRuleManager.d.ts.map +1 -1
  13. package/dist/managers/MemoryRuleManager.js +16 -2
  14. package/dist/managers/aiManager.d.ts +14 -4
  15. package/dist/managers/aiManager.d.ts.map +1 -1
  16. package/dist/managers/aiManager.js +61 -9
  17. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  18. package/dist/managers/backgroundBashManager.js +1 -0
  19. package/dist/managers/backgroundTaskManager.d.ts +35 -0
  20. package/dist/managers/backgroundTaskManager.d.ts.map +1 -0
  21. package/dist/managers/backgroundTaskManager.js +249 -0
  22. package/dist/managers/bashManager.d.ts.map +1 -1
  23. package/dist/managers/bashManager.js +0 -3
  24. package/dist/managers/foregroundTaskManager.d.ts +9 -0
  25. package/dist/managers/foregroundTaskManager.d.ts.map +1 -0
  26. package/dist/managers/foregroundTaskManager.js +20 -0
  27. package/dist/managers/liveConfigManager.d.ts +1 -1
  28. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  29. package/dist/managers/lspManager.d.ts.map +1 -1
  30. package/dist/managers/lspManager.js +3 -1
  31. package/dist/managers/messageManager.d.ts +34 -4
  32. package/dist/managers/messageManager.d.ts.map +1 -1
  33. package/dist/managers/messageManager.js +104 -13
  34. package/dist/managers/permissionManager.d.ts.map +1 -1
  35. package/dist/managers/permissionManager.js +11 -13
  36. package/dist/managers/pluginManager.d.ts.map +1 -1
  37. package/dist/managers/pluginManager.js +3 -2
  38. package/dist/managers/pluginScopeManager.d.ts +13 -2
  39. package/dist/managers/pluginScopeManager.d.ts.map +1 -1
  40. package/dist/managers/pluginScopeManager.js +38 -0
  41. package/dist/managers/reversionManager.d.ts +39 -0
  42. package/dist/managers/reversionManager.d.ts.map +1 -0
  43. package/dist/managers/reversionManager.js +118 -0
  44. package/dist/managers/slashCommandManager.d.ts +4 -1
  45. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  46. package/dist/managers/slashCommandManager.js +16 -6
  47. package/dist/managers/subagentManager.d.ts +13 -2
  48. package/dist/managers/subagentManager.d.ts.map +1 -1
  49. package/dist/managers/subagentManager.js +144 -35
  50. package/dist/managers/toolManager.d.ts +11 -1
  51. package/dist/managers/toolManager.d.ts.map +1 -1
  52. package/dist/managers/toolManager.js +11 -3
  53. package/dist/services/GitService.d.ts.map +1 -1
  54. package/dist/services/GitService.js +6 -2
  55. package/dist/services/MarketplaceService.d.ts +14 -1
  56. package/dist/services/MarketplaceService.d.ts.map +1 -1
  57. package/dist/services/MarketplaceService.js +72 -4
  58. package/dist/services/MemoryRuleService.d.ts +1 -1
  59. package/dist/services/MemoryRuleService.d.ts.map +1 -1
  60. package/dist/services/MemoryRuleService.js +13 -2
  61. package/dist/services/aiService.js +1 -1
  62. package/dist/services/configurationService.d.ts +18 -2
  63. package/dist/services/configurationService.d.ts.map +1 -1
  64. package/dist/services/configurationService.js +62 -0
  65. package/dist/services/fileWatcher.d.ts +0 -5
  66. package/dist/services/fileWatcher.d.ts.map +1 -1
  67. package/dist/services/fileWatcher.js +0 -11
  68. package/dist/services/memory.js +1 -1
  69. package/dist/services/pluginLoader.d.ts.map +1 -1
  70. package/dist/services/pluginLoader.js +6 -1
  71. package/dist/services/reversionService.d.ts +24 -0
  72. package/dist/services/reversionService.d.ts.map +1 -0
  73. package/dist/services/reversionService.js +76 -0
  74. package/dist/services/session.d.ts +7 -0
  75. package/dist/services/session.d.ts.map +1 -1
  76. package/dist/services/session.js +126 -3
  77. package/dist/tools/bashTool.d.ts +0 -8
  78. package/dist/tools/bashTool.d.ts.map +1 -1
  79. package/dist/tools/bashTool.js +52 -174
  80. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  81. package/dist/tools/deleteFileTool.js +9 -0
  82. package/dist/tools/editTool.d.ts.map +1 -1
  83. package/dist/tools/editTool.js +15 -4
  84. package/dist/tools/multiEditTool.d.ts.map +1 -1
  85. package/dist/tools/multiEditTool.js +16 -5
  86. package/dist/tools/taskOutputTool.d.ts +3 -0
  87. package/dist/tools/taskOutputTool.d.ts.map +1 -0
  88. package/dist/tools/taskOutputTool.js +149 -0
  89. package/dist/tools/taskStopTool.d.ts +3 -0
  90. package/dist/tools/taskStopTool.d.ts.map +1 -0
  91. package/dist/tools/taskStopTool.js +65 -0
  92. package/dist/tools/taskTool.d.ts.map +1 -1
  93. package/dist/tools/taskTool.js +105 -63
  94. package/dist/tools/types.d.ts +7 -0
  95. package/dist/tools/types.d.ts.map +1 -1
  96. package/dist/tools/writeTool.d.ts.map +1 -1
  97. package/dist/tools/writeTool.js +9 -0
  98. package/dist/types/commands.d.ts +1 -0
  99. package/dist/types/commands.d.ts.map +1 -1
  100. package/dist/types/configuration.d.ts +3 -0
  101. package/dist/types/configuration.d.ts.map +1 -1
  102. package/dist/types/environment.d.ts +2 -1
  103. package/dist/types/environment.d.ts.map +1 -1
  104. package/dist/types/environment.js +0 -6
  105. package/dist/types/history.d.ts +5 -0
  106. package/dist/types/history.d.ts.map +1 -0
  107. package/dist/types/history.js +1 -0
  108. package/dist/types/index.d.ts +1 -0
  109. package/dist/types/index.d.ts.map +1 -1
  110. package/dist/types/index.js +1 -0
  111. package/dist/types/marketplace.d.ts +4 -0
  112. package/dist/types/marketplace.d.ts.map +1 -1
  113. package/dist/types/messaging.d.ts +7 -1
  114. package/dist/types/messaging.d.ts.map +1 -1
  115. package/dist/types/processes.d.ts +24 -4
  116. package/dist/types/processes.d.ts.map +1 -1
  117. package/dist/types/reversion.d.ts +29 -0
  118. package/dist/types/reversion.d.ts.map +1 -0
  119. package/dist/types/reversion.js +1 -0
  120. package/dist/utils/builtinSubagents.d.ts.map +1 -1
  121. package/dist/utils/builtinSubagents.js +16 -0
  122. package/dist/utils/constants.d.ts +2 -2
  123. package/dist/utils/constants.d.ts.map +1 -1
  124. package/dist/utils/constants.js +2 -2
  125. package/dist/utils/editUtils.d.ts +4 -9
  126. package/dist/utils/editUtils.d.ts.map +1 -1
  127. package/dist/utils/editUtils.js +54 -55
  128. package/dist/utils/messageOperations.d.ts +3 -1
  129. package/dist/utils/messageOperations.d.ts.map +1 -1
  130. package/dist/utils/messageOperations.js +8 -1
  131. package/dist/utils/openaiClient.d.ts.map +1 -1
  132. package/dist/utils/openaiClient.js +56 -26
  133. package/dist/utils/promptHistory.d.ts +20 -0
  134. package/dist/utils/promptHistory.d.ts.map +1 -0
  135. package/dist/utils/promptHistory.js +117 -0
  136. package/package.json +5 -3
  137. package/src/agent.ts +193 -109
  138. package/src/constants/prompts.ts +45 -5
  139. package/src/constants/tools.ts +2 -2
  140. package/src/index.ts +1 -1
  141. package/src/managers/MemoryRuleManager.ts +18 -2
  142. package/src/managers/aiManager.ts +87 -18
  143. package/src/managers/backgroundBashManager.ts +1 -0
  144. package/src/managers/backgroundTaskManager.ts +306 -0
  145. package/src/managers/bashManager.ts +0 -4
  146. package/src/managers/foregroundTaskManager.ts +26 -0
  147. package/src/managers/liveConfigManager.ts +2 -1
  148. package/src/managers/lspManager.ts +3 -1
  149. package/src/managers/messageManager.ts +136 -18
  150. package/src/managers/permissionManager.ts +11 -13
  151. package/src/managers/pluginManager.ts +4 -3
  152. package/src/managers/pluginScopeManager.ts +57 -8
  153. package/src/managers/reversionManager.ts +152 -0
  154. package/src/managers/slashCommandManager.ts +30 -7
  155. package/src/managers/subagentManager.ts +176 -31
  156. package/src/managers/toolManager.ts +23 -4
  157. package/src/services/GitService.ts +6 -2
  158. package/src/services/MarketplaceService.ts +100 -4
  159. package/src/services/MemoryRuleService.ts +18 -6
  160. package/src/services/aiService.ts +1 -1
  161. package/src/services/configurationService.ts +79 -1
  162. package/src/services/fileWatcher.ts +0 -13
  163. package/src/services/memory.ts +1 -1
  164. package/src/services/pluginLoader.ts +7 -1
  165. package/src/services/reversionService.ts +94 -0
  166. package/src/services/session.ts +161 -3
  167. package/src/tools/bashTool.ts +73 -200
  168. package/src/tools/deleteFileTool.ts +15 -0
  169. package/src/tools/editTool.ts +20 -10
  170. package/src/tools/multiEditTool.ts +21 -11
  171. package/src/tools/taskOutputTool.ts +174 -0
  172. package/src/tools/taskStopTool.ts +72 -0
  173. package/src/tools/taskTool.ts +130 -74
  174. package/src/tools/types.ts +7 -0
  175. package/src/tools/writeTool.ts +14 -0
  176. package/src/types/commands.ts +3 -0
  177. package/src/types/configuration.ts +4 -0
  178. package/src/types/environment.ts +3 -1
  179. package/src/types/history.ts +4 -0
  180. package/src/types/index.ts +1 -0
  181. package/src/types/marketplace.ts +5 -0
  182. package/src/types/messaging.ts +9 -1
  183. package/src/types/processes.ts +33 -4
  184. package/src/types/reversion.ts +29 -0
  185. package/src/utils/builtinSubagents.ts +18 -0
  186. package/src/utils/constants.ts +2 -2
  187. package/src/utils/editUtils.ts +66 -58
  188. package/src/utils/messageOperations.ts +10 -0
  189. package/src/utils/openaiClient.ts +69 -35
  190. package/src/utils/promptHistory.ts +133 -0
  191. package/dist/utils/bashHistory.d.ts +0 -50
  192. package/dist/utils/bashHistory.d.ts.map +0 -1
  193. package/dist/utils/bashHistory.js +0 -256
  194. package/src/utils/bashHistory.ts +0 -320
package/dist/agent.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { type MessageManagerCallbacks } from "./managers/messageManager.js";
2
2
  import { type SubagentManagerCallbacks } from "./managers/subagentManager.js";
3
3
  import { type McpManagerCallbacks } from "./managers/mcpManager.js";
4
- import { type BackgroundBashManagerCallbacks } from "./managers/backgroundBashManager.js";
4
+ import { type BackgroundTaskManagerCallbacks } from "./managers/backgroundTaskManager.js";
5
5
  import type { SlashCommand, CustomSlashCommand, ILspManager, PluginConfig } from "./types/index.js";
6
- import type { Message, Logger, McpServerStatus, GatewayConfig, ModelConfig, Usage, PermissionMode, PermissionCallback } from "./types/index.js";
6
+ import type { Message, Logger, McpServerStatus, GatewayConfig, ModelConfig, Usage, PermissionMode, PermissionCallback, BackgroundTask, ForegroundTask } from "./types/index.js";
7
7
  import { ClientOptions } from "openai";
8
8
  /**
9
9
  * Configuration options for Agent instances
@@ -21,6 +21,8 @@ export interface AgentOptions {
21
21
  fastModel?: string;
22
22
  maxInputTokens?: number;
23
23
  maxTokens?: number;
24
+ /** Preferred language for agent communication */
25
+ language?: string;
24
26
  callbacks?: AgentCallbacks;
25
27
  restoreSessionId?: string;
26
28
  continueLastSession?: boolean;
@@ -42,14 +44,16 @@ export interface AgentOptions {
42
44
  /**Optional local plugins to load */
43
45
  plugins?: PluginConfig[];
44
46
  }
45
- export interface AgentCallbacks extends MessageManagerCallbacks, BackgroundBashManagerCallbacks, McpManagerCallbacks, SubagentManagerCallbacks {
47
+ export interface AgentCallbacks extends MessageManagerCallbacks, BackgroundTaskManagerCallbacks, McpManagerCallbacks, SubagentManagerCallbacks {
48
+ onTasksChange?: (tasks: BackgroundTask[]) => void;
46
49
  onPermissionModeChange?: (mode: PermissionMode) => void;
50
+ onBackgroundCurrentTask?: () => void;
47
51
  }
48
52
  export declare class Agent {
49
53
  private messageManager;
50
54
  private aiManager;
51
55
  private bashManager;
52
- private backgroundBashManager;
56
+ private backgroundTaskManager;
53
57
  private logger?;
54
58
  private toolManager;
55
59
  private mcpManager;
@@ -61,8 +65,10 @@ export declare class Agent {
61
65
  private pluginManager;
62
66
  private skillManager;
63
67
  private hookManager;
68
+ private reversionManager;
64
69
  private memoryRuleManager;
65
70
  private liveConfigManager;
71
+ private foregroundTaskManager;
66
72
  private configurationService;
67
73
  private workdir;
68
74
  private systemPrompt?;
@@ -74,17 +80,7 @@ export declare class Agent {
74
80
  getGatewayConfig(): GatewayConfig;
75
81
  getModelConfig(): ModelConfig;
76
82
  getMaxInputTokens(): number;
77
- /**
78
- * Update agent configuration dynamically
79
- *
80
- * @param config - Configuration updates for gateway, model, and token limit
81
- */
82
- updateConfig(config: {
83
- gateway?: Partial<GatewayConfig>;
84
- model?: Partial<ModelConfig>;
85
- maxInputTokens?: number;
86
- maxTokens?: number;
87
- }): void;
83
+ getLanguage(): string | undefined;
88
84
  /**
89
85
  * Agent constructor - handles configuration resolution and validation
90
86
  *
@@ -118,7 +114,7 @@ export declare class Agent {
118
114
  /** Get user memory content */
119
115
  get userMemory(): string;
120
116
  /** Get combined memory content (project + user + modular rules) */
121
- get combinedMemory(): string;
117
+ getCombinedMemory(): Promise<string>;
122
118
  /** Get AI loading status */
123
119
  get isLoading(): boolean;
124
120
  /** Get message compression status */
@@ -133,6 +129,14 @@ export declare class Agent {
133
129
  } | null;
134
130
  /** Kill background bash shell */
135
131
  killBackgroundShell(id: string): boolean;
132
+ /** Get background task output */
133
+ getBackgroundTaskOutput(id: string, filter?: string): {
134
+ stdout: string;
135
+ stderr: string;
136
+ status: string;
137
+ } | null;
138
+ /** Stop background task */
139
+ stopBackgroundTask(id: string): boolean;
136
140
  /**
137
141
  * Static async factory method for creating Agent instances
138
142
  *
@@ -205,8 +209,29 @@ export declare class Agent {
205
209
  abortBashCommand(): void;
206
210
  /** Interrupt slash command execution */
207
211
  abortSlashCommand(): void;
212
+ /**
213
+ * Register a foreground task that can be backgrounded
214
+ */
215
+ registerForegroundTask(task: ForegroundTask): void;
216
+ /**
217
+ * Unregister a foreground task
218
+ */
219
+ unregisterForegroundTask(id: string): void;
220
+ /**
221
+ * Background the current foreground task
222
+ */
223
+ backgroundCurrentTask(): Promise<void>;
208
224
  /** Destroy managers, clean up resources */
209
225
  destroy(): Promise<void>;
226
+ /**
227
+ * Get a subagent instance by its ID
228
+ * @param subagentId - The ID of the subagent instance
229
+ */
230
+ getSubagentInstance(subagentId: string): import("./managers/subagentManager.js").SubagentInstance | null;
231
+ /**
232
+ * Trigger the rewind UI callback
233
+ */
234
+ triggerShowRewind(): void;
210
235
  /**
211
236
  * Send a message to the AI agent with optional images
212
237
  *
@@ -255,6 +280,10 @@ export declare class Agent {
255
280
  getCustomCommand(commandId: string): CustomSlashCommand | undefined;
256
281
  /** Get all custom commands */
257
282
  getCustomCommands(): CustomSlashCommand[];
283
+ /**
284
+ * Register a custom slash command
285
+ */
286
+ registerSlashCommand(command: SlashCommand): void;
258
287
  /**
259
288
  * Get the current permission mode
260
289
  */
@@ -265,14 +294,31 @@ export declare class Agent {
265
294
  */
266
295
  setPermissionMode(mode: PermissionMode): void;
267
296
  /**
268
- * Handle plan mode transition, generating or clearing plan file path
269
- * @param mode - The current effective permission mode
297
+ * Truncate history to a specific index and revert file changes.
298
+ * @param index - The index of the user message to truncate to.
270
299
  */
271
- private handlePlanModeTransition;
300
+ truncateHistory(index: number): Promise<void>;
301
+ /**
302
+ * Get the current plan file path (for testing and UI)
303
+ */
304
+ getPlanFilePath(): string | undefined;
305
+ /**
306
+ * Get all currently allowed rules (for testing and UI)
307
+ */
308
+ getAllowedRules(): string[];
309
+ /**
310
+ * Check permission for a tool call (for testing)
311
+ */
312
+ checkPermission(context: import("./types/permissions.js").ToolPermissionContext): Promise<import("./types/permissions.js").PermissionDecision>;
272
313
  /**
273
314
  * Add a persistent permission rule
274
315
  * @param rule - The rule to add (e.g., "Bash(ls)")
275
316
  */
276
- private addPermissionRule;
317
+ addPermissionRule(rule: string): Promise<void>;
318
+ /**
319
+ * Handle plan mode transition, generating or clearing plan file path
320
+ * @param mode - The current effective permission mode
321
+ */
322
+ private handlePlanModeTransition;
277
323
  }
278
324
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CA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I,eAAe,EAAE;IAIzC,yBAAyB;IACZ,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInE,4BAA4B;IACf,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMtE,uCAAuC;IAChC,gBAAgB,IAAI,YAAY,EAAE;IAIzC,oCAAoC;IAC7B,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIlD,6BAA6B;IACtB,oBAAoB,IAAI,IAAI;IAInC,iCAAiC;IAC1B,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI1E,8BAA8B;IACvB,iBAAiB,IAAI,kBAAkB,EAAE;IAIhD;;OAEG;IACI,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxD;;OAEG;IACI,iBAAiB,IAAI,cAAc;IAI1C;;;OAGG;IACI,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IASpD;;;OAGG;IACU,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D;;OAEG;IACI,eAAe,IAAI,MAAM,GAAG,SAAS;IAI5C;;OAEG;IACI,eAAe,IAAI,MAAM,EAAE;IAIlC;;OAEG;IACU,eAAe,CAC1B,OAAO,EAAE,OAAO,wBAAwB,EAAE,qBAAqB,GAC9D,OAAO,CAAC,OAAO,wBAAwB,EAAE,kBAAkB,CAAC;IAI/D;;;OAGG;IACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC3D;;;OAGG;IACH,OAAO,CAAC,wBAAwB;CAejC"}
package/dist/agent.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { ForegroundTaskManager } from "./managers/foregroundTaskManager.js";
1
2
  import { MessageManager, } from "./managers/messageManager.js";
2
3
  import { AIManager } from "./managers/aiManager.js";
3
4
  import { ToolManager } from "./managers/toolManager.js";
@@ -6,10 +7,12 @@ import * as memory from "./services/memory.js";
6
7
  import { McpManager } from "./managers/mcpManager.js";
7
8
  import { LspManager } from "./managers/lspManager.js";
8
9
  import { BashManager } from "./managers/bashManager.js";
9
- import { BackgroundBashManager, } from "./managers/backgroundBashManager.js";
10
+ import { BackgroundTaskManager, } from "./managers/backgroundTaskManager.js";
10
11
  import { SlashCommandManager } from "./managers/slashCommandManager.js";
11
12
  import { PluginManager } from "./managers/pluginManager.js";
12
13
  import { HookManager } from "./managers/hookManager.js";
14
+ import { ReversionManager } from "./managers/reversionManager.js";
15
+ import { ReversionService } from "./services/reversionService.js";
13
16
  import { PermissionManager } from "./managers/permissionManager.js";
14
17
  import { PlanManager } from "./managers/planManager.js";
15
18
  import { MemoryRuleManager } from "./managers/MemoryRuleManager.js";
@@ -33,35 +36,8 @@ export class Agent {
33
36
  getMaxInputTokens() {
34
37
  return this.configurationService.resolveMaxInputTokens(this.options.maxInputTokens);
35
38
  }
36
- /**
37
- * Update agent configuration dynamically
38
- *
39
- * @param config - Configuration updates for gateway, model, and token limit
40
- */
41
- updateConfig(config) {
42
- if (config.gateway) {
43
- this.options.apiKey = config.gateway.apiKey ?? this.options.apiKey;
44
- this.options.baseURL = config.gateway.baseURL ?? this.options.baseURL;
45
- this.options.defaultHeaders =
46
- config.gateway.defaultHeaders ?? this.options.defaultHeaders;
47
- this.options.fetchOptions =
48
- config.gateway.fetchOptions ?? this.options.fetchOptions;
49
- this.options.fetch = config.gateway.fetch ?? this.options.fetch;
50
- }
51
- if (config.model) {
52
- this.options.agentModel =
53
- config.model.agentModel ?? this.options.agentModel;
54
- this.options.fastModel = config.model.fastModel ?? this.options.fastModel;
55
- this.options.maxTokens = config.model.maxTokens ?? this.options.maxTokens;
56
- }
57
- if (config.maxInputTokens !== undefined) {
58
- this.options.maxInputTokens = config.maxInputTokens;
59
- }
60
- if (config.maxTokens !== undefined) {
61
- this.options.maxTokens = config.maxTokens;
62
- }
63
- // Re-validate configuration after update
64
- this.resolveAndValidateConfig();
39
+ getLanguage() {
40
+ return this.configurationService.resolveLanguage(this.options.language);
65
41
  }
66
42
  /**
67
43
  * Agent constructor - handles configuration resolution and validation
@@ -88,8 +64,14 @@ export class Agent {
88
64
  this.stream = stream; // Save streaming mode flag
89
65
  // Store options for dynamic configuration resolution
90
66
  this.options = options;
91
- this.backgroundBashManager = new BackgroundBashManager({
92
- callbacks,
67
+ this.foregroundTaskManager = new ForegroundTaskManager();
68
+ this.backgroundTaskManager = new BackgroundTaskManager({
69
+ callbacks: {
70
+ ...callbacks,
71
+ onTasksChange: (tasks) => {
72
+ callbacks.onTasksChange?.(tasks);
73
+ },
74
+ },
93
75
  workdir: this.workdir,
94
76
  });
95
77
  this.mcpManager = new McpManager({ callbacks, logger: this.logger }); // Initialize MCP manager
@@ -113,16 +95,19 @@ export class Agent {
113
95
  logger: this.logger,
114
96
  workdir: this.workdir,
115
97
  });
98
+ // Initialize memory rule manager
99
+ this.memoryRuleManager = new MemoryRuleManager({
100
+ workdir: this.workdir,
101
+ });
116
102
  // Initialize MessageManager
117
103
  this.messageManager = new MessageManager({
118
104
  callbacks,
119
105
  workdir: this.workdir,
120
106
  logger: this.logger,
107
+ memoryRuleManager: this.memoryRuleManager,
121
108
  });
122
- // Initialize memory rule manager
123
- this.memoryRuleManager = new MemoryRuleManager({
124
- workdir: this.workdir,
125
- });
109
+ // Initialize ReversionManager
110
+ this.reversionManager = new ReversionManager(new ReversionService(this.messageManager.getTranscriptPath()));
126
111
  // Create a wrapper for canUseTool that triggers notification hooks
127
112
  const canUseToolWithNotification = options.canUseTool
128
113
  ? async (context) => {
@@ -166,8 +151,11 @@ export class Agent {
166
151
  lspManager: this.lspManager,
167
152
  logger: this.logger,
168
153
  permissionManager: this.permissionManager,
154
+ reversionManager: this.reversionManager,
169
155
  permissionMode: options.permissionMode, // Let PermissionManager handle defaultMode resolution
170
156
  canUseToolCallback: canUseToolWithNotification,
157
+ backgroundTaskManager: this.backgroundTaskManager,
158
+ foregroundTaskManager: this.foregroundTaskManager,
171
159
  }); // Initialize tool registry with permission support
172
160
  this.liveConfigManager = new LiveConfigManager({
173
161
  workdir: this.workdir,
@@ -194,15 +182,18 @@ export class Agent {
194
182
  getGatewayConfig: () => this.getGatewayConfig(),
195
183
  getModelConfig: () => this.getModelConfig(),
196
184
  getMaxInputTokens: () => this.getMaxInputTokens(),
185
+ getLanguage: () => this.getLanguage(),
197
186
  hookManager: this.hookManager,
198
187
  onUsageAdded: (usage) => this.addUsage(usage),
188
+ backgroundTaskManager: this.backgroundTaskManager,
189
+ memoryRuleManager: this.memoryRuleManager,
199
190
  });
200
191
  // Initialize AI manager with resolved configuration
201
192
  this.aiManager = new AIManager({
202
193
  messageManager: this.messageManager,
203
194
  toolManager: this.toolManager,
204
195
  logger: this.logger,
205
- backgroundBashManager: this.backgroundBashManager,
196
+ backgroundTaskManager: this.backgroundTaskManager,
206
197
  hookManager: this.hookManager,
207
198
  permissionManager: this.permissionManager,
208
199
  callbacks: {
@@ -214,15 +205,18 @@ export class Agent {
214
205
  workdir: this.workdir,
215
206
  systemPrompt: this.systemPrompt,
216
207
  stream: this.stream, // Pass streaming mode flag
208
+ reversionManager: this.reversionManager,
217
209
  getGatewayConfig: () => this.getGatewayConfig(),
218
210
  getModelConfig: () => this.getModelConfig(),
219
211
  getMaxInputTokens: () => this.getMaxInputTokens(),
212
+ getLanguage: () => this.getLanguage(),
220
213
  getEnvironmentVars: () => this.configurationService.getEnvironmentVars(), // Provide access to configuration environment variables
221
214
  });
222
215
  // Initialize command manager
223
216
  this.slashCommandManager = new SlashCommandManager({
224
217
  messageManager: this.messageManager,
225
218
  aiManager: this.aiManager,
219
+ backgroundTaskManager: this.backgroundTaskManager,
226
220
  workdir: this.workdir,
227
221
  logger: this.logger,
228
222
  });
@@ -301,27 +295,8 @@ export class Agent {
301
295
  return this._userMemoryContent;
302
296
  }
303
297
  /** Get combined memory content (project + user + modular rules) */
304
- get combinedMemory() {
305
- let combined = "";
306
- if (this._projectMemoryContent.trim()) {
307
- combined += this._projectMemoryContent;
308
- }
309
- if (this._userMemoryContent.trim()) {
310
- if (combined) {
311
- combined += "\n\n";
312
- }
313
- combined += this._userMemoryContent;
314
- }
315
- // Add modular memory rules
316
- const filesInContext = this.messageManager.getFilesInContext();
317
- const activeRules = this.memoryRuleManager.getActiveRules(filesInContext);
318
- if (activeRules.length > 0) {
319
- if (combined) {
320
- combined += "\n\n";
321
- }
322
- combined += activeRules.map((r) => r.content).join("\n\n");
323
- }
324
- return combined;
298
+ async getCombinedMemory() {
299
+ return this.messageManager.getCombinedMemory();
325
300
  }
326
301
  /** Get AI loading status */
327
302
  get isLoading() {
@@ -337,11 +312,19 @@ export class Agent {
337
312
  }
338
313
  /** Get background bash shell output */
339
314
  getBackgroundShellOutput(id, filter) {
340
- return this.backgroundBashManager.getOutput(id, filter);
315
+ return this.backgroundTaskManager.getOutput(id, filter);
341
316
  }
342
317
  /** Kill background bash shell */
343
318
  killBackgroundShell(id) {
344
- return this.backgroundBashManager.killShell(id);
319
+ return this.backgroundTaskManager.stopTask(id);
320
+ }
321
+ /** Get background task output */
322
+ getBackgroundTaskOutput(id, filter) {
323
+ return this.backgroundTaskManager.getOutput(id, filter);
324
+ }
325
+ /** Stop background task */
326
+ stopBackgroundTask(id) {
327
+ return this.backgroundTaskManager.stopTask(id);
345
328
  }
346
329
  /**
347
330
  * Static async factory method for creating Agent instances
@@ -457,6 +440,8 @@ export class Agent {
457
440
  }
458
441
  // Resolve and validate configuration after loading settings.json
459
442
  this.resolveAndValidateConfig();
443
+ // Set global logger for SDK-wide access before discovering rules
444
+ setGlobalLogger(this.logger || null);
460
445
  // Discover modular memory rules
461
446
  try {
462
447
  await this.memoryRuleManager.discoverRules();
@@ -464,8 +449,6 @@ export class Agent {
464
449
  catch (error) {
465
450
  this.logger?.error("Failed to discover memory rules:", error);
466
451
  }
467
- // Set global logger for SDK-wide access after validation
468
- setGlobalLogger(this.logger || null);
469
452
  // Initialize live configuration reload
470
453
  try {
471
454
  this.logger?.debug("Initializing live configuration reload...");
@@ -669,14 +652,38 @@ export class Agent {
669
652
  abortSlashCommand() {
670
653
  this.slashCommandManager.abortCurrentCommand();
671
654
  }
655
+ /**
656
+ * Register a foreground task that can be backgrounded
657
+ */
658
+ registerForegroundTask(task) {
659
+ this.foregroundTaskManager.registerForegroundTask(task);
660
+ }
661
+ /**
662
+ * Unregister a foreground task
663
+ */
664
+ unregisterForegroundTask(id) {
665
+ this.foregroundTaskManager.unregisterForegroundTask(id);
666
+ }
667
+ /**
668
+ * Background the current foreground task
669
+ */
670
+ async backgroundCurrentTask() {
671
+ await this.foregroundTaskManager.backgroundCurrentTask();
672
+ this.options.callbacks?.onBackgroundCurrentTask?.();
673
+ // If there was no foreground task (e.g. a tool that doesn't register one),
674
+ // or even if there was, we should stop the AI recursion loop.
675
+ if (!this.foregroundTaskManager.hasActiveTasks()) {
676
+ this.aiManager.abortRecursion();
677
+ }
678
+ }
672
679
  /** Destroy managers, clean up resources */
673
680
  async destroy() {
674
681
  await this.messageManager.saveSession();
675
682
  this.abortAIMessage(); // This will abort tools including Task tool (subagents)
676
683
  this.abortBashCommand();
677
684
  this.abortSlashCommand();
678
- // Cleanup background bash manager
679
- this.backgroundBashManager.cleanup();
685
+ // Cleanup background task manager
686
+ this.backgroundTaskManager.cleanup();
680
687
  // Cleanup MCP connections
681
688
  await this.mcpManager.cleanup();
682
689
  // Cleanup LSP connections
@@ -694,6 +701,19 @@ export class Agent {
694
701
  }
695
702
  // Cleanup memory store
696
703
  }
704
+ /**
705
+ * Get a subagent instance by its ID
706
+ * @param subagentId - The ID of the subagent instance
707
+ */
708
+ getSubagentInstance(subagentId) {
709
+ return this.subagentManager.getInstance(subagentId);
710
+ }
711
+ /**
712
+ * Trigger the rewind UI callback
713
+ */
714
+ triggerShowRewind() {
715
+ this.messageManager.triggerShowRewind();
716
+ }
697
717
  /**
698
718
  * Send a message to the AI agent with optional images
699
719
  *
@@ -806,7 +826,18 @@ export class Agent {
806
826
  const memoryText = message.substring(1).trim();
807
827
  const typeLabel = type === "project" ? "Project Memory" : "User Memory";
808
828
  const storagePath = "AGENTS.md";
809
- this.messageManager.addMemoryBlock(`${typeLabel}: ${memoryText}`, true, type, storagePath);
829
+ const messages = this.messageManager.getMessages();
830
+ const lastMessage = messages[messages.length - 1];
831
+ if (lastMessage && lastMessage.role === "assistant") {
832
+ lastMessage.blocks.push({
833
+ type: "memory",
834
+ content: `${typeLabel}: ${memoryText}`,
835
+ isSuccess: true,
836
+ memoryType: type,
837
+ storagePath,
838
+ });
839
+ this.messageManager.setMessages(messages);
840
+ }
810
841
  }
811
842
  catch (error) {
812
843
  // Add failed MemoryBlock to the last assistant message
@@ -814,7 +845,18 @@ export class Agent {
814
845
  const typeLabel = type === "project" ? "Project Memory" : "User Memory";
815
846
  const storagePath = "AGENTS.md";
816
847
  const errorMessage = error instanceof Error ? error.message : String(error);
817
- this.messageManager.addMemoryBlock(`${typeLabel}: ${memoryText} - Error: ${errorMessage}`, false, type, storagePath);
848
+ const messages = this.messageManager.getMessages();
849
+ const lastMessage = messages[messages.length - 1];
850
+ if (lastMessage && lastMessage.role === "assistant") {
851
+ lastMessage.blocks.push({
852
+ type: "memory",
853
+ content: `${typeLabel}: ${memoryText} - Error: ${errorMessage}`,
854
+ isSuccess: false,
855
+ memoryType: type,
856
+ storagePath,
857
+ });
858
+ this.messageManager.setMessages(messages);
859
+ }
818
860
  }
819
861
  }
820
862
  // ========== MCP Management Methods ==========
@@ -851,6 +893,12 @@ export class Agent {
851
893
  getCustomCommands() {
852
894
  return this.slashCommandManager.getCustomCommands();
853
895
  }
896
+ /**
897
+ * Register a custom slash command
898
+ */
899
+ registerSlashCommand(command) {
900
+ this.slashCommandManager.registerCommand(command);
901
+ }
854
902
  /**
855
903
  * Get the current permission mode
856
904
  */
@@ -868,24 +916,29 @@ export class Agent {
868
916
  this.options.callbacks?.onPermissionModeChange?.(mode);
869
917
  }
870
918
  /**
871
- * Handle plan mode transition, generating or clearing plan file path
872
- * @param mode - The current effective permission mode
919
+ * Truncate history to a specific index and revert file changes.
920
+ * @param index - The index of the user message to truncate to.
873
921
  */
874
- handlePlanModeTransition(mode) {
875
- if (mode === "plan") {
876
- this.planManager
877
- .getOrGeneratePlanFilePath()
878
- .then(({ path }) => {
879
- this.logger?.debug("Plan file path generated", { path });
880
- this.permissionManager.setPlanFilePath(path);
881
- })
882
- .catch((error) => {
883
- this.logger?.error("Failed to generate plan file path", error);
884
- });
885
- }
886
- else {
887
- this.permissionManager.setPlanFilePath(undefined);
888
- }
922
+ async truncateHistory(index) {
923
+ await this.messageManager.truncateHistory(index, this.reversionManager);
924
+ }
925
+ /**
926
+ * Get the current plan file path (for testing and UI)
927
+ */
928
+ getPlanFilePath() {
929
+ return this.permissionManager.getPlanFilePath();
930
+ }
931
+ /**
932
+ * Get all currently allowed rules (for testing and UI)
933
+ */
934
+ getAllowedRules() {
935
+ return this.permissionManager.getAllowedRules();
936
+ }
937
+ /**
938
+ * Check permission for a tool call (for testing)
939
+ */
940
+ async checkPermission(context) {
941
+ return this.permissionManager.checkPermission(context);
889
942
  }
890
943
  /**
891
944
  * Add a persistent permission rule
@@ -920,4 +973,24 @@ export class Agent {
920
973
  }
921
974
  }
922
975
  }
976
+ /**
977
+ * Handle plan mode transition, generating or clearing plan file path
978
+ * @param mode - The current effective permission mode
979
+ */
980
+ handlePlanModeTransition(mode) {
981
+ if (mode === "plan") {
982
+ this.planManager
983
+ .getOrGeneratePlanFilePath()
984
+ .then(({ path }) => {
985
+ this.logger?.debug("Plan file path generated", { path });
986
+ this.permissionManager.setPlanFilePath(path);
987
+ })
988
+ .catch((error) => {
989
+ this.logger?.error("Failed to generate plan file path", error);
990
+ });
991
+ }
992
+ else {
993
+ this.permissionManager.setPlanFilePath(undefined);
994
+ }
995
+ }
923
996
  }
@@ -2,10 +2,15 @@ export declare const BASE_SYSTEM_PROMPT = "You are an interactive CLI tool that
2
2
  export declare const TASK_MANAGEMENT_POLICY = "\n# Task Management\nYou have access to the TodoWrite tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.\nThese tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.\nIt is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.";
3
3
  export declare const ASK_USER_POLICY = "\n# Asking questions as you work\nYou have access to the AskUserQuestion tool to ask the user questions when you need clarification, want to validate assumptions, or need to make a decision you're unsure about. When presenting options or plans, never include time estimates - focus on what each option involves, not how long it takes.";
4
4
  export declare const SUBAGENT_POLICY = "\n- When doing file search, prefer to use the Task tool in order to reduce context usage.\n- You should proactively use the Task tool with specialized agents when the task at hand matches the agent's description.\n- VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the Task tool with subagent_type=Explore instead of running search commands directly.";
5
- export declare const FILE_TOOL_POLICY = "\n- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools: Read for reading files instead of cat/head/tail, Edit/MultiEdit for editing instead of sed/awk, Write for creating files instead of cat with heredoc or echo redirection, and LS/Glob/Grep for searching and listing files instead of find/ls/grep.";
5
+ export declare const FILE_TOOL_POLICY_PREFIX = "\n- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools:";
6
+ export declare const READ_FILE_POLICY = " Read for reading files instead of cat/head/tail";
7
+ export declare const EDIT_FILE_POLICY = " Edit/MultiEdit for editing instead of sed/awk";
8
+ export declare const WRITE_FILE_POLICY = " Write for creating files instead of cat with heredoc or echo redirection";
9
+ export declare const SEARCH_FILE_POLICY = " LS/Glob/Grep for searching and listing files instead of find/ls/grep";
6
10
  export declare const BASH_POLICY = "\n- Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.\n- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run \"git status\" and \"git diff\", send a single message with two tool calls to run the calls in parallel.";
7
11
  export declare const DEFAULT_SYSTEM_PROMPT = "You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\n\n# Doing tasks\nThe user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:\n- NEVER propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first. Understand existing code before suggesting modifications.\n- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it.\n- Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.\n - Don't add features, refactor code, or make \"improvements\" beyond what was asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need extra configurability. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.\n - Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.\n - Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the minimum needed for the current task\u2014three similar lines of code is better than a premature abstraction.\n- Avoid backwards-compatibility hacks like renaming unused `_vars`, re-exporting types, adding `// removed` comments for removed code, etc. If something is unused, delete it completely.\n\n# Tool usage policy\n- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency.\n- However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.\n- If the user specifies that they want you to run tools \"in parallel\", you MUST send a single message with multiple tool use content blocks.";
8
- export declare const INIT_PROMPT = "Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Wave Code to operate in this repository.\n\nWhat to add:\n1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.\n2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the \"big picture\" architecture that requires reading multiple files to understand.\n\nUsage notes:\n- If there's already a AGENTS.md, suggest improvements to it.\n- When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like \"Provide helpful error messages to users\", \"Write unit tests for all new utilities\", \"Never include sensitive information (API keys, tokens) in code or commits\".\n- Avoid listing every component or file structure that can be easily discovered.\n- Don't include generic development practices.\n- If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.\n- If there is a README.md, make sure to include the important parts.\n- Do not make up information such as \"Common Development Tasks\", \"Tips for Development\", \"Support and Documentation\" unless this is expressly included in other files that you read.\n- Be sure to prefix the file with the following text:\n\n```\n# AGENTS.md\n\nThis file provides guidance to Wave Code when working with code in this repository.\n```";
12
+ export declare const GENERAL_PURPOSE_SYSTEM_PROMPT = "You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.\n\nYour strengths:\n- Searching for code, configurations, and patterns across large codebases\n- Analyzing multiple files to understand system architecture\n- Investigating complex questions that require exploring many files\n- Performing multi-step research tasks\n\nGuidelines:\n- For file searches: Use Grep or Glob when you need to search broadly. Use Read when you know the specific file path.\n- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.\n- Be thorough: Check multiple locations, consider different naming conventions, look for related files.\n- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.\n- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.\n- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.\n- For clear communication, avoid using emojis.";
13
+ export declare const INIT_PROMPT = "Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.\n\nWhat to add:\n1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.\n2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the \"big picture\" architecture that requires reading multiple files to understand.\n\nUsage notes:\n- If there's already a AGENTS.md, suggest improvements to it.\n- When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like \"Provide helpful error messages to users\", \"Write unit tests for all new utilities\", \"Never include sensitive information (API keys, tokens) in code or commits\".\n- Avoid listing every component or file structure that can be easily discovered.\n- Don't include generic development practices.\n- If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.\n- If there is a README.md, make sure to include the important parts.\n- Do not make up information such as \"Common Development Tasks\", \"Tips for Development\", \"Support and Documentation\" unless this is expressly included in other files that you read.\n- Be sure to prefix the file with the following text:\n\n```\n# AGENTS.md\n\nThis file provides guidance to Agent when working with code in this repository.\n```";
9
14
  export declare function buildSystemPrompt(basePrompt: string, tools: {
10
15
  name?: string;
11
16
  function?: {
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/constants/prompts.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,kBAAkB,ksFAe8G,CAAC;AAE9I,eAAO,MAAM,sBAAsB,+lBAImH,CAAC;AAEvJ,eAAO,MAAM,eAAe,mVAEgS,CAAC;AAE7T,eAAO,MAAM,eAAe,meAG0P,CAAC;AAEvR,eAAO,MAAM,gBAAgB,+YACwc,CAAC;AAEte,eAAO,MAAM,WAAW,sjBAE4O,CAAC;AAErQ,eAAO,MAAM,qBAAqB,ksFAAqB,CAAC;AAExD,eAAO,MAAM,WAAW,0kDAoBjB,CAAC;AAER,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,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