wave-agent-sdk 0.0.7 → 0.0.8

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 (172) hide show
  1. package/dist/agent.d.ts +32 -20
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +202 -20
  4. package/dist/constants/events.d.ts +28 -0
  5. package/dist/constants/events.d.ts.map +1 -0
  6. package/dist/constants/events.js +27 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/managers/aiManager.d.ts +34 -1
  11. package/dist/managers/aiManager.d.ts.map +1 -1
  12. package/dist/managers/aiManager.js +243 -128
  13. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  14. package/dist/managers/backgroundBashManager.js +7 -6
  15. package/dist/managers/hookManager.d.ts +9 -4
  16. package/dist/managers/hookManager.d.ts.map +1 -1
  17. package/dist/managers/hookManager.js +62 -30
  18. package/dist/managers/liveConfigManager.d.ts +58 -0
  19. package/dist/managers/liveConfigManager.d.ts.map +1 -0
  20. package/dist/managers/liveConfigManager.js +160 -0
  21. package/dist/managers/messageManager.d.ts +38 -13
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +163 -30
  24. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  25. package/dist/managers/slashCommandManager.js +4 -1
  26. package/dist/managers/subagentManager.d.ts +51 -0
  27. package/dist/managers/subagentManager.d.ts.map +1 -1
  28. package/dist/managers/subagentManager.js +189 -18
  29. package/dist/services/aiService.d.ts +13 -5
  30. package/dist/services/aiService.d.ts.map +1 -1
  31. package/dist/services/aiService.js +350 -74
  32. package/dist/services/configurationWatcher.d.ts +120 -0
  33. package/dist/services/configurationWatcher.d.ts.map +1 -0
  34. package/dist/services/configurationWatcher.js +439 -0
  35. package/dist/services/fileWatcher.d.ts +69 -0
  36. package/dist/services/fileWatcher.d.ts.map +1 -0
  37. package/dist/services/fileWatcher.js +213 -0
  38. package/dist/services/hook.d.ts +91 -9
  39. package/dist/services/hook.d.ts.map +1 -1
  40. package/dist/services/hook.js +393 -43
  41. package/dist/services/jsonlHandler.d.ts +62 -0
  42. package/dist/services/jsonlHandler.d.ts.map +1 -0
  43. package/dist/services/jsonlHandler.js +257 -0
  44. package/dist/services/memory.d.ts +9 -0
  45. package/dist/services/memory.d.ts.map +1 -1
  46. package/dist/services/memory.js +81 -12
  47. package/dist/services/memoryStore.d.ts +81 -0
  48. package/dist/services/memoryStore.d.ts.map +1 -0
  49. package/dist/services/memoryStore.js +200 -0
  50. package/dist/services/session.d.ts +64 -49
  51. package/dist/services/session.d.ts.map +1 -1
  52. package/dist/services/session.js +310 -132
  53. package/dist/tools/bashTool.d.ts.map +1 -1
  54. package/dist/tools/bashTool.js +5 -4
  55. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  56. package/dist/tools/deleteFileTool.js +2 -1
  57. package/dist/tools/editTool.d.ts.map +1 -1
  58. package/dist/tools/editTool.js +3 -2
  59. package/dist/tools/multiEditTool.d.ts.map +1 -1
  60. package/dist/tools/multiEditTool.js +4 -3
  61. package/dist/tools/readTool.d.ts.map +1 -1
  62. package/dist/tools/readTool.js +2 -1
  63. package/dist/tools/writeTool.d.ts.map +1 -1
  64. package/dist/tools/writeTool.js +5 -6
  65. package/dist/types/commands.d.ts +4 -0
  66. package/dist/types/commands.d.ts.map +1 -1
  67. package/dist/types/core.d.ts +35 -0
  68. package/dist/types/core.d.ts.map +1 -1
  69. package/dist/types/environment.d.ts +42 -0
  70. package/dist/types/environment.d.ts.map +1 -0
  71. package/dist/types/environment.js +21 -0
  72. package/dist/types/hooks.d.ts +8 -2
  73. package/dist/types/hooks.d.ts.map +1 -1
  74. package/dist/types/hooks.js +8 -2
  75. package/dist/types/index.d.ts +2 -0
  76. package/dist/types/index.d.ts.map +1 -1
  77. package/dist/types/index.js +2 -0
  78. package/dist/types/memoryStore.d.ts +82 -0
  79. package/dist/types/memoryStore.d.ts.map +1 -0
  80. package/dist/types/memoryStore.js +7 -0
  81. package/dist/types/messaging.d.ts +14 -2
  82. package/dist/types/messaging.d.ts.map +1 -1
  83. package/dist/types/session.d.ts +20 -0
  84. package/dist/types/session.d.ts.map +1 -0
  85. package/dist/types/session.js +7 -0
  86. package/dist/utils/bashHistory.d.ts.map +1 -1
  87. package/dist/utils/bashHistory.js +27 -26
  88. package/dist/utils/cacheControlUtils.d.ts +121 -0
  89. package/dist/utils/cacheControlUtils.d.ts.map +1 -0
  90. package/dist/utils/cacheControlUtils.js +367 -0
  91. package/dist/utils/commandPathResolver.d.ts +52 -0
  92. package/dist/utils/commandPathResolver.d.ts.map +1 -0
  93. package/dist/utils/commandPathResolver.js +145 -0
  94. package/dist/utils/configPaths.d.ts +85 -0
  95. package/dist/utils/configPaths.d.ts.map +1 -0
  96. package/dist/utils/configPaths.js +121 -0
  97. package/dist/utils/configResolver.d.ts +37 -10
  98. package/dist/utils/configResolver.d.ts.map +1 -1
  99. package/dist/utils/configResolver.js +127 -23
  100. package/dist/utils/constants.d.ts +1 -1
  101. package/dist/utils/constants.js +1 -1
  102. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  103. package/dist/utils/convertMessagesForAPI.js +7 -5
  104. package/dist/utils/customCommands.d.ts.map +1 -1
  105. package/dist/utils/customCommands.js +66 -21
  106. package/dist/utils/fileUtils.d.ts +15 -0
  107. package/dist/utils/fileUtils.d.ts.map +1 -0
  108. package/dist/utils/fileUtils.js +61 -0
  109. package/dist/utils/globalLogger.d.ts +102 -0
  110. package/dist/utils/globalLogger.d.ts.map +1 -0
  111. package/dist/utils/globalLogger.js +136 -0
  112. package/dist/utils/mcpUtils.d.ts.map +1 -1
  113. package/dist/utils/mcpUtils.js +25 -3
  114. package/dist/utils/messageOperations.d.ts +20 -8
  115. package/dist/utils/messageOperations.d.ts.map +1 -1
  116. package/dist/utils/messageOperations.js +25 -16
  117. package/dist/utils/pathEncoder.d.ts +104 -0
  118. package/dist/utils/pathEncoder.d.ts.map +1 -0
  119. package/dist/utils/pathEncoder.js +272 -0
  120. package/dist/utils/subagentParser.d.ts.map +1 -1
  121. package/dist/utils/subagentParser.js +2 -1
  122. package/dist/utils/tokenCalculation.d.ts +26 -0
  123. package/dist/utils/tokenCalculation.d.ts.map +1 -0
  124. package/dist/utils/tokenCalculation.js +36 -0
  125. package/package.json +6 -3
  126. package/src/agent.ts +298 -34
  127. package/src/constants/events.ts +38 -0
  128. package/src/index.ts +2 -0
  129. package/src/managers/aiManager.ts +323 -170
  130. package/src/managers/backgroundBashManager.ts +7 -6
  131. package/src/managers/hookManager.ts +83 -40
  132. package/src/managers/liveConfigManager.ts +248 -0
  133. package/src/managers/messageManager.ts +230 -63
  134. package/src/managers/slashCommandManager.ts +4 -1
  135. package/src/managers/subagentManager.ts +283 -21
  136. package/src/services/aiService.ts +474 -83
  137. package/src/services/configurationWatcher.ts +622 -0
  138. package/src/services/fileWatcher.ts +301 -0
  139. package/src/services/hook.ts +538 -47
  140. package/src/services/jsonlHandler.ts +319 -0
  141. package/src/services/memory.ts +92 -12
  142. package/src/services/memoryStore.ts +279 -0
  143. package/src/services/session.ts +381 -157
  144. package/src/tools/bashTool.ts +5 -4
  145. package/src/tools/deleteFileTool.ts +2 -1
  146. package/src/tools/editTool.ts +3 -2
  147. package/src/tools/multiEditTool.ts +4 -3
  148. package/src/tools/readTool.ts +2 -1
  149. package/src/tools/writeTool.ts +7 -6
  150. package/src/types/commands.ts +6 -0
  151. package/src/types/core.ts +44 -0
  152. package/src/types/environment.ts +60 -0
  153. package/src/types/hooks.ts +21 -8
  154. package/src/types/index.ts +2 -0
  155. package/src/types/memoryStore.ts +94 -0
  156. package/src/types/messaging.ts +14 -2
  157. package/src/types/session.ts +25 -0
  158. package/src/utils/bashHistory.ts +27 -27
  159. package/src/utils/cacheControlUtils.ts +540 -0
  160. package/src/utils/commandPathResolver.ts +189 -0
  161. package/src/utils/configPaths.ts +163 -0
  162. package/src/utils/configResolver.ts +182 -22
  163. package/src/utils/constants.ts +1 -1
  164. package/src/utils/convertMessagesForAPI.ts +7 -5
  165. package/src/utils/customCommands.ts +90 -22
  166. package/src/utils/fileUtils.ts +65 -0
  167. package/src/utils/globalLogger.ts +145 -0
  168. package/src/utils/mcpUtils.ts +34 -3
  169. package/src/utils/messageOperations.ts +42 -20
  170. package/src/utils/pathEncoder.ts +379 -0
  171. package/src/utils/subagentParser.ts +2 -1
  172. package/src/utils/tokenCalculation.ts +43 -0
@@ -1,7 +1,13 @@
1
1
  import OpenAI from "openai";
2
+ import { logger } from "../utils/globalLogger.js";
3
+ import { transformMessagesForClaudeCache, addCacheControlToLastTool, isClaudeModel, extendUsageWithCacheMetrics, } from "../utils/cacheControlUtils.js";
2
4
  import * as os from "os";
3
5
  import * as fs from "fs";
4
6
  import * as path from "path";
7
+ /**
8
+ * Use parametersChunk as compact param for better performance
9
+ * Instead of parsing JSON, we use the raw chunk for efficient streaming
10
+ */
5
11
  /**
6
12
  * Check if a directory is a git repository
7
13
  * @param dirPath Directory path to check
@@ -44,7 +50,7 @@ function getModelConfig(modelName, baseConfig = {}) {
44
50
  return config;
45
51
  }
46
52
  export async function callAgent(options) {
47
- const { gatewayConfig, modelConfig, messages, abortSignal, memory, workdir, tools, model, systemPrompt, } = options;
53
+ const { gatewayConfig, modelConfig, messages, abortSignal, memory, workdir, tools, model, systemPrompt, onContentUpdate, onToolUpdate, } = options;
48
54
  try {
49
55
  // Create OpenAI client with injected configuration
50
56
  const openai = new OpenAI({
@@ -83,55 +89,273 @@ Today's date: ${new Date().toISOString().split("T")[0]}
83
89
  content: systemContent,
84
90
  };
85
91
  // ChatCompletionMessageParam[] is already in OpenAI format, add system prompt to the beginning
86
- const openaiMessages = [systemMessage, ...messages];
92
+ let openaiMessages = [
93
+ systemMessage,
94
+ ...messages,
95
+ ];
96
+ // Apply cache control for Claude models
97
+ const currentModel = model || modelConfig.agentModel;
98
+ if (isClaudeModel(currentModel)) {
99
+ openaiMessages = transformMessagesForClaudeCache(openaiMessages, currentModel);
100
+ }
87
101
  // Get model configuration - use injected modelConfig with optional override
88
102
  const openaiModelConfig = getModelConfig(model || modelConfig.agentModel, {
89
103
  temperature: 0,
90
- max_completion_tokens: 32768,
91
104
  });
105
+ // Determine if streaming is needed
106
+ const isStreaming = !!(onContentUpdate || onToolUpdate);
92
107
  // Prepare API call parameters
93
108
  const createParams = {
94
109
  ...openaiModelConfig,
95
110
  messages: openaiMessages,
111
+ stream: isStreaming,
96
112
  };
97
113
  // Only add tools if they exist
98
114
  if (tools && tools.length > 0) {
99
- createParams.tools = tools;
100
- }
101
- // Call OpenAI API (non-streaming)
102
- const response = await openai.chat.completions.create(createParams, {
103
- signal: abortSignal,
104
- });
105
- const finalMessage = response.choices[0]?.message;
106
- const totalUsage = response.usage
107
- ? {
108
- prompt_tokens: response.usage.prompt_tokens,
109
- completion_tokens: response.usage.completion_tokens,
110
- total_tokens: response.usage.total_tokens,
115
+ // Apply cache control to tools for Claude models
116
+ if (isClaudeModel(currentModel)) {
117
+ createParams.tools = addCacheControlToLastTool(tools);
118
+ }
119
+ else {
120
+ createParams.tools = tools;
111
121
  }
112
- : undefined;
113
- const result = {};
114
- // Return content
115
- if (finalMessage?.content) {
116
- result.content = finalMessage.content;
117
122
  }
118
- // Return tool call
119
- if (finalMessage?.tool_calls && finalMessage.tool_calls.length > 0) {
120
- result.tool_calls = finalMessage.tool_calls;
123
+ if (isStreaming) {
124
+ // Handle streaming response
125
+ const { data: stream, response } = await openai.chat.completions
126
+ .create(createParams, {
127
+ signal: abortSignal,
128
+ })
129
+ .withResponse();
130
+ // Extract response headers
131
+ const responseHeaders = {};
132
+ response.headers.forEach((value, key) => {
133
+ responseHeaders[key] = value;
134
+ });
135
+ return await processStreamingResponse(stream, onContentUpdate, onToolUpdate, abortSignal, responseHeaders, currentModel);
121
136
  }
122
- // Return token usage information
123
- if (totalUsage) {
124
- result.usage = totalUsage;
137
+ else {
138
+ // Handle non-streaming response
139
+ const { data: response, response: rawResponse } = await openai.chat.completions
140
+ .create(createParams, {
141
+ signal: abortSignal,
142
+ })
143
+ .withResponse();
144
+ // Extract response headers
145
+ const responseHeaders = {};
146
+ rawResponse.headers.forEach((value, key) => {
147
+ responseHeaders[key] = value;
148
+ });
149
+ const finalMessage = response.choices[0]?.message;
150
+ const finishReason = response.choices[0]?.finish_reason || null;
151
+ let totalUsage = response.usage
152
+ ? {
153
+ prompt_tokens: response.usage.prompt_tokens,
154
+ completion_tokens: response.usage.completion_tokens,
155
+ total_tokens: response.usage.total_tokens,
156
+ }
157
+ : undefined;
158
+ // Extend usage with cache metrics for Claude models
159
+ if (totalUsage && isClaudeModel(currentModel) && response.usage) {
160
+ totalUsage = extendUsageWithCacheMetrics(totalUsage, response.usage);
161
+ }
162
+ const result = {};
163
+ if (finalMessage) {
164
+ const { content: finalContent, tool_calls: finalToolCalls, ...otherFields } = finalMessage;
165
+ if (typeof finalContent === "string" && finalContent.length > 0) {
166
+ result.content = finalContent;
167
+ }
168
+ if (Array.isArray(finalToolCalls) && finalToolCalls.length > 0) {
169
+ result.tool_calls = finalToolCalls;
170
+ }
171
+ if (Object.keys(otherFields).length > 0) {
172
+ const metadata = {};
173
+ for (const [key, value] of Object.entries(otherFields)) {
174
+ if (value !== undefined) {
175
+ metadata[key] = value;
176
+ }
177
+ }
178
+ if (Object.keys(metadata).length > 0) {
179
+ result.metadata = metadata;
180
+ }
181
+ }
182
+ }
183
+ if (totalUsage) {
184
+ result.usage = totalUsage;
185
+ }
186
+ if (finishReason) {
187
+ result.finish_reason = finishReason;
188
+ }
189
+ if (Object.keys(responseHeaders).length > 0) {
190
+ result.response_headers = responseHeaders;
191
+ }
192
+ return result;
125
193
  }
126
- return result;
127
194
  }
128
195
  catch (error) {
129
196
  if (error.name === "AbortError") {
130
197
  throw new Error("Request was aborted");
131
198
  }
132
- // // logger.error("Failed to call OpenAI:", error);
199
+ logger.error("Failed to call OpenAI:", error);
200
+ throw error;
201
+ }
202
+ }
203
+ /**
204
+ * Process streaming response from OpenAI API
205
+ * @param stream Async iterator of chat completion chunks
206
+ * @param onContentUpdate Callback for content updates
207
+ * @param onToolUpdate Callback for tool updates
208
+ * @param abortSignal Optional abort signal
209
+ * @param responseHeaders Response headers from the initial request
210
+ * @param modelName Model name for cache control processing
211
+ * @returns Final result with accumulated content and tool calls
212
+ */
213
+ async function processStreamingResponse(stream, onContentUpdate, onToolUpdate, abortSignal, responseHeaders, modelName) {
214
+ let accumulatedContent = "";
215
+ const toolCalls = [];
216
+ const additionalDeltaFields = {};
217
+ let usage = undefined;
218
+ let finishReason = null;
219
+ try {
220
+ for await (const chunk of stream) {
221
+ // Check for abort signal
222
+ if (abortSignal?.aborted) {
223
+ throw new Error("Request was aborted");
224
+ }
225
+ // Check for usage information in any chunk
226
+ if (chunk.usage) {
227
+ let chunkUsage = {
228
+ prompt_tokens: chunk.usage.prompt_tokens,
229
+ completion_tokens: chunk.usage.completion_tokens,
230
+ total_tokens: chunk.usage.total_tokens,
231
+ };
232
+ // Extend usage with cache metrics for Claude models
233
+ if (modelName && isClaudeModel(modelName)) {
234
+ chunkUsage = extendUsageWithCacheMetrics(chunkUsage, chunk.usage);
235
+ }
236
+ usage = chunkUsage;
237
+ }
238
+ // Check for finish_reason in the choice
239
+ const choice = chunk.choices?.[0];
240
+ if (choice?.finish_reason) {
241
+ finishReason = choice.finish_reason;
242
+ }
243
+ const delta = choice?.delta;
244
+ if (!delta) {
245
+ continue;
246
+ }
247
+ const { content, tool_calls: toolCallUpdates, ...deltaMetadata } = delta;
248
+ if (Object.keys(deltaMetadata).length > 0) {
249
+ Object.assign(additionalDeltaFields, deltaMetadata);
250
+ }
251
+ if (typeof content === "string" && content.length > 0) {
252
+ // Note: OpenAI API already handles UTF-8 character boundaries correctly in streaming,
253
+ // ensuring that delta.content always contains complete UTF-8 strings
254
+ accumulatedContent += content;
255
+ if (onContentUpdate) {
256
+ onContentUpdate(accumulatedContent);
257
+ }
258
+ }
259
+ if (Array.isArray(toolCallUpdates)) {
260
+ for (const rawToolCall of toolCallUpdates) {
261
+ const toolCallDelta = rawToolCall;
262
+ if (!toolCallDelta.function) {
263
+ continue;
264
+ }
265
+ const functionDelta = toolCallDelta.function;
266
+ let existingCall;
267
+ let isNew = false;
268
+ if (toolCallDelta.id) {
269
+ existingCall = toolCalls.find((t) => t.id === toolCallDelta.id);
270
+ if (!existingCall) {
271
+ existingCall = {
272
+ id: toolCallDelta.id,
273
+ type: "function",
274
+ function: {
275
+ name: functionDelta.name || "",
276
+ arguments: "",
277
+ },
278
+ };
279
+ toolCalls.push(existingCall);
280
+ isNew = true;
281
+ }
282
+ }
283
+ else {
284
+ existingCall = toolCalls[toolCalls.length - 1];
285
+ }
286
+ if (!existingCall) {
287
+ continue;
288
+ }
289
+ if (functionDelta.name) {
290
+ existingCall.function.name = functionDelta.name;
291
+ }
292
+ // Emit start stage when a new tool call is created and we have the tool name
293
+ if (onToolUpdate && isNew && existingCall.function.name) {
294
+ onToolUpdate({
295
+ id: existingCall.id,
296
+ name: existingCall.function.name,
297
+ parameters: "", // Empty parameters for start stage
298
+ parametersChunk: "", // Empty chunk for start stage
299
+ stage: "start", // New tool call triggers start stage
300
+ });
301
+ isNew = false; // Prevent duplicate start emissions
302
+ }
303
+ if (functionDelta.arguments) {
304
+ existingCall.function.arguments += functionDelta.arguments;
305
+ }
306
+ // Emit streaming updates for all chunks with actual content (including first chunk)
307
+ if (onToolUpdate &&
308
+ existingCall.function.name &&
309
+ functionDelta.arguments &&
310
+ functionDelta.arguments.length > 0 // Only emit streaming for chunks with actual content
311
+ ) {
312
+ onToolUpdate({
313
+ id: existingCall.id,
314
+ name: existingCall.function.name,
315
+ parameters: existingCall.function.arguments,
316
+ parametersChunk: functionDelta.arguments,
317
+ stage: "streaming",
318
+ });
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ catch (error) {
325
+ if (error.message === "Request was aborted") {
326
+ throw error;
327
+ }
133
328
  throw error;
134
329
  }
330
+ // Prepare final result
331
+ const result = {};
332
+ if (accumulatedContent) {
333
+ result.content = accumulatedContent;
334
+ }
335
+ if (toolCalls.length > 0) {
336
+ result.tool_calls = toolCalls;
337
+ }
338
+ if (usage) {
339
+ result.usage = usage;
340
+ }
341
+ if (finishReason) {
342
+ result.finish_reason = finishReason;
343
+ }
344
+ if (responseHeaders && Object.keys(responseHeaders).length > 0) {
345
+ result.response_headers = responseHeaders;
346
+ }
347
+ if (Object.keys(additionalDeltaFields).length > 0) {
348
+ result.metadata = {};
349
+ for (const [key, value] of Object.entries(additionalDeltaFields)) {
350
+ if (value !== undefined) {
351
+ result.metadata[key] = value;
352
+ }
353
+ }
354
+ if (Object.keys(result.metadata).length === 0) {
355
+ delete result.metadata;
356
+ }
357
+ }
358
+ return result;
135
359
  }
136
360
  export async function compressMessages(options) {
137
361
  const { gatewayConfig, modelConfig, messages, abortSignal } = options;
@@ -143,7 +367,7 @@ export async function compressMessages(options) {
143
367
  // Get model configuration - use injected fast model
144
368
  const openaiModelConfig = getModelConfig(modelConfig.fastModel, {
145
369
  temperature: 0.1,
146
- max_tokens: 1500,
370
+ max_tokens: 2048,
147
371
  });
148
372
  try {
149
373
  const response = await openai.chat.completions.create({
@@ -151,54 +375,106 @@ export async function compressMessages(options) {
151
375
  messages: [
152
376
  {
153
377
  role: "system",
154
- content: `You are an expert conversation history compression specialist. Your task is to create comprehensive yet concise summaries that preserve critical development context.
155
-
156
- ## Primary Request and Intent
157
- Compress conversation history while maintaining all essential technical and procedural information.
158
-
159
- ## Key Technical Concepts
160
- - Code modifications and file operations
161
- - Tool executions and their results
162
- - Error handling and debugging processes
163
- - User requirements and assistant solutions
164
- - Technical discussions and decisions
165
-
166
- ## Compression Strategy
167
- 1. **Preserve Critical Information**:
168
- - All file paths, function names, and code examples
169
- - Tool execution results and outcomes
170
- - Error messages and resolution steps
171
- - User requirements and implementation approaches
172
- - Technical decisions and their reasoning
173
-
174
- 2. **Structure Organization**:
175
- - Group related actions and discussions
176
- - Maintain chronological flow for complex operations
177
- - Separate different technical topics clearly
178
-
179
- 3. **Context Preservation**:
180
- - Keep enough detail for future reference
181
- - Maintain relationships between requests and solutions
182
- - Preserve debugging context and error resolution paths
183
-
184
- ## Output Requirements:
185
- - Use third-person narrative format
186
- - Target 300-800 words (scale based on complexity)
187
- - Maintain the original conversation language
188
- - Structure with clear sections for multi-topic conversations
189
- - Focus on actionable information and outcomes
190
-
191
- ## Format Template:
192
- For technical conversations, structure as:
193
- - **User Requests**: Key requirements and goals
194
- - **Technical Implementation**: Code changes, file operations, tool usage
195
- - **Problem Resolution**: Errors encountered and solutions applied
196
- - **Outcomes**: Final results and current state`,
378
+ content: `Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
379
+ This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
380
+
381
+ Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
382
+
383
+ 1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
384
+ - The user's explicit requests and intents
385
+ - Your approach to addressing the user's requests
386
+ - Key decisions, technical concepts and code patterns
387
+ - Specific details like:
388
+ - file names
389
+ - full code snippets
390
+ - function signatures
391
+ - file edits
392
+ - Errors that you ran into and how you fixed them
393
+ - Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
394
+ 2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
395
+
396
+ Your summary should include the following sections:
397
+
398
+ 1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail
399
+ 2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
400
+ 3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
401
+ 4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
402
+ 5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
403
+ 6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users' feedback and changing intent.
404
+ 6. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
405
+ 7. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
406
+ 8. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's most recent explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests or really old requests that were already completed without confirming with the user first.
407
+ If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation.
408
+
409
+ Here's an example of how your output should be structured:
410
+
411
+ <example>
412
+ <analysis>
413
+ [Your thought process, ensuring all points are covered thoroughly and accurately]
414
+ </analysis>
415
+
416
+ <summary>
417
+ 1. Primary Request and Intent:
418
+ [Detailed description]
419
+
420
+ 2. Key Technical Concepts:
421
+ - [Concept 1]
422
+ - [Concept 2]
423
+ - [...]
424
+
425
+ 3. Files and Code Sections:
426
+ - [File Name 1]
427
+ - [Summary of why this file is important]
428
+ - [Summary of the changes made to this file, if any]
429
+ - [Important Code Snippet]
430
+ - [File Name 2]
431
+ - [Important Code Snippet]
432
+ - [...]
433
+
434
+ 4. Errors and fixes:
435
+ - [Detailed description of error 1]:
436
+ - [How you fixed the error]
437
+ - [User feedback on the error if any]
438
+ - [...]
439
+
440
+ 5. Problem Solving:
441
+ [Description of solved problems and ongoing troubleshooting]
442
+
443
+ 6. All user messages:
444
+ - [Detailed non tool use user message]
445
+ - [...]
446
+
447
+ 7. Pending Tasks:
448
+ - [Task 1]
449
+ - [Task 2]
450
+ - [...]
451
+
452
+ 8. Current Work:
453
+ [Precise description of current work]
454
+
455
+ 9. Optional Next Step:
456
+ [Optional Next step to take]
457
+
458
+ </summary>
459
+ </example>
460
+
461
+ Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.
462
+
463
+ There may be additional summarization instructions provided in the included context. If so, remember to follow these instructions when creating the above summary. Examples of instructions include:
464
+ <example>
465
+ ## Compact Instructions
466
+ When summarizing the conversation focus on typescript code changes and also remember the mistakes you made and how you fixed them.
467
+ </example>
468
+
469
+ <example>
470
+ # Summary instructions
471
+ When you are using compact - please focus on test output and code changes. Include file reads verbatim.
472
+ </example>`,
197
473
  },
198
474
  ...messages,
199
475
  {
200
476
  role: "user",
201
- content: `Please compress this conversation following the structured approach. Focus on preserving all technical details, file operations, and problem-solving context while creating a concise summary.`,
477
+ content: `Please create a detailed summary of the conversation so far.`,
202
478
  },
203
479
  ],
204
480
  }, {
@@ -222,7 +498,7 @@ For technical conversations, structure as:
222
498
  if (error.name === "AbortError") {
223
499
  throw new Error("Compression request was aborted");
224
500
  }
225
- // // logger.error("Failed to compress messages:", error);
501
+ logger.error("Failed to compress messages:", error);
226
502
  return {
227
503
  content: "Failed to compress conversation history",
228
504
  usage: undefined,
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Configuration Watcher Service
3
+ *
4
+ * Orchestrates live configuration reload functionality by coordinating file watching,
5
+ * configuration validation, and error recovery. Provides automatic reload of settings.json
6
+ * changes without restart.
7
+ */
8
+ import { EventEmitter } from "events";
9
+ import { type FileWatchEvent } from "./fileWatcher.js";
10
+ import type { WaveConfiguration } from "../types/hooks.js";
11
+ import type { Logger } from "../types/index.js";
12
+ export interface ConfigurationChangeEvent {
13
+ type: "settings_changed" | "memory_changed" | "env_changed";
14
+ path: string;
15
+ timestamp: number;
16
+ changes: {
17
+ added: string[];
18
+ modified: string[];
19
+ removed: string[];
20
+ };
21
+ isValid: boolean;
22
+ errorMessage?: string;
23
+ }
24
+ export interface ConfigurationReloadService {
25
+ initializeWatching(userPaths: string[], projectPaths?: string[]): Promise<void>;
26
+ reloadConfiguration(): Promise<WaveConfiguration>;
27
+ getCurrentConfiguration(): WaveConfiguration | null;
28
+ validateEnvironmentVariables(env: Record<string, string>): {
29
+ isValid: boolean;
30
+ errors: string[];
31
+ warnings: string[];
32
+ };
33
+ shutdown(): Promise<void>;
34
+ }
35
+ export declare class ConfigurationWatcher extends EventEmitter implements ConfigurationReloadService {
36
+ private fileWatcher;
37
+ private logger?;
38
+ private currentConfiguration;
39
+ private lastValidConfiguration;
40
+ private userConfigPaths?;
41
+ private projectConfigPaths?;
42
+ private workdir;
43
+ private isWatching;
44
+ private reloadInProgress;
45
+ constructor(workdir: string, logger?: Logger);
46
+ /**
47
+ * Initialize configuration watching
48
+ * Maps to FR-004: System MUST watch settings.json files
49
+ * Supports watching multiple file paths (e.g., settings.local.json and settings.json)
50
+ */
51
+ initializeWatching(userPaths: string[], projectPaths?: string[]): Promise<void>;
52
+ /**
53
+ * Reload configuration from files
54
+ * Maps to FR-008: Continue with previous valid configuration on errors
55
+ */
56
+ reloadConfiguration(): Promise<WaveConfiguration>;
57
+ /**
58
+ * Get current effective configuration
59
+ * Maps to FR-002: Merged configuration with project precedence
60
+ */
61
+ getCurrentConfiguration(): WaveConfiguration | null;
62
+ /**
63
+ * Validate environment variables
64
+ * Maps to FR-003: Validate env field format
65
+ */
66
+ validateEnvironmentVariables(env: Record<string, string>): {
67
+ isValid: boolean;
68
+ errors: string[];
69
+ warnings: string[];
70
+ };
71
+ /**
72
+ * Stop watching and cleanup resources
73
+ * Maps to cleanup requirements
74
+ */
75
+ shutdown(): Promise<void>;
76
+ /**
77
+ * Watch an additional file (like AGENTS.md) for changes
78
+ * Maps to T033: Add AGENTS.md file watching to HookManager
79
+ */
80
+ watchAdditionalFile(filePath: string, callback: (event: FileWatchEvent) => void): Promise<void>;
81
+ /**
82
+ * Stop watching an additional file
83
+ */
84
+ unwatchAdditionalFile(filePath: string): Promise<void>;
85
+ /**
86
+ * Check if watching is active
87
+ */
88
+ isWatchingActive(): boolean;
89
+ /**
90
+ * Get watcher status for monitoring
91
+ */
92
+ getWatcherStatus(): {
93
+ isActive: boolean;
94
+ configurationLoaded: boolean;
95
+ hasValidConfiguration: boolean;
96
+ reloadInProgress: boolean;
97
+ watchedFiles: {
98
+ path: string;
99
+ isActive: boolean;
100
+ method: "native" | "polling" | "failed";
101
+ errorCount: number;
102
+ }[];
103
+ };
104
+ private setupFileWatcherEvents;
105
+ private handleFileChange;
106
+ /**
107
+ * Validate configuration structure and content
108
+ */
109
+ private validateConfiguration;
110
+ private detectChanges;
111
+ /**
112
+ * Get the first existing user config path for error reporting
113
+ */
114
+ private getFirstExistingUserPath;
115
+ /**
116
+ * Get the first existing project config path for error reporting
117
+ */
118
+ private getFirstExistingProjectPath;
119
+ }
120
+ //# sourceMappingURL=configurationWatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configurationWatcher.d.ts","sourceRoot":"","sources":["../../src/services/configurationWatcher.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAE7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMhD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,aAAa,CAAC;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,0BAA0B;IACzC,kBAAkB,CAChB,SAAS,EAAE,MAAM,EAAE,EACnB,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,mBAAmB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD,uBAAuB,IAAI,iBAAiB,GAAG,IAAI,CAAC;IACpD,4BAA4B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;QACzD,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;IACF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,qBAAa,oBACX,SAAQ,YACR,YAAW,0BAA0B;IAErC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,sBAAsB,CAAkC;IAChE,OAAO,CAAC,eAAe,CAAC,CAAW;IACnC,OAAO,CAAC,kBAAkB,CAAC,CAAW;IACtC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,gBAAgB,CAAkB;gBAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ5C;;;;OAIG;IACG,kBAAkB,CACtB,SAAS,EAAE,MAAM,EAAE,EACnB,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC;IAuDhB;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAuJvD;;;OAGG;IACH,uBAAuB,IAAI,iBAAiB,GAAG,IAAI;IAInD;;;OAGG;IACH,4BAA4B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;QACzD,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB;IA6CD;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB/B;;;OAGG;IACG,mBAAmB,CACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GACxC,OAAO,CAAC,IAAI,CAAC;IAchB;;OAEG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5D;;OAEG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;IACH,gBAAgB;;;;;;;;;;;;IAgBhB,OAAO,CAAC,sBAAsB;YAOhB,gBAAgB;IAyC9B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA6D7B,OAAO,CAAC,aAAa;IAuDrB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAOhC;;OAEG;IACH,OAAO,CAAC,2BAA2B;CAMpC"}