wave-agent-sdk 0.0.8 → 0.0.10

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 (236) hide show
  1. package/dist/agent.d.ts +92 -23
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +340 -137
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/managers/aiManager.d.ts +14 -36
  8. package/dist/managers/aiManager.d.ts.map +1 -1
  9. package/dist/managers/aiManager.js +74 -77
  10. package/dist/managers/backgroundBashManager.d.ts.map +1 -1
  11. package/dist/managers/backgroundBashManager.js +4 -3
  12. package/dist/managers/hookManager.d.ts +3 -8
  13. package/dist/managers/hookManager.d.ts.map +1 -1
  14. package/dist/managers/hookManager.js +39 -29
  15. package/dist/managers/liveConfigManager.d.ts +55 -18
  16. package/dist/managers/liveConfigManager.d.ts.map +1 -1
  17. package/dist/managers/liveConfigManager.js +372 -90
  18. package/dist/managers/lspManager.d.ts +43 -0
  19. package/dist/managers/lspManager.d.ts.map +1 -0
  20. package/dist/managers/lspManager.js +326 -0
  21. package/dist/managers/messageManager.d.ts +8 -16
  22. package/dist/managers/messageManager.d.ts.map +1 -1
  23. package/dist/managers/messageManager.js +52 -74
  24. package/dist/managers/permissionManager.d.ts +66 -0
  25. package/dist/managers/permissionManager.d.ts.map +1 -0
  26. package/dist/managers/permissionManager.js +208 -0
  27. package/dist/managers/skillManager.d.ts +1 -0
  28. package/dist/managers/skillManager.d.ts.map +1 -1
  29. package/dist/managers/skillManager.js +2 -1
  30. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  31. package/dist/managers/slashCommandManager.js +0 -1
  32. package/dist/managers/subagentManager.d.ts +8 -23
  33. package/dist/managers/subagentManager.d.ts.map +1 -1
  34. package/dist/managers/subagentManager.js +97 -117
  35. package/dist/managers/toolManager.d.ts +38 -1
  36. package/dist/managers/toolManager.d.ts.map +1 -1
  37. package/dist/managers/toolManager.js +66 -2
  38. package/dist/services/aiService.d.ts +3 -1
  39. package/dist/services/aiService.d.ts.map +1 -1
  40. package/dist/services/aiService.js +123 -30
  41. package/dist/services/configurationService.d.ts +116 -0
  42. package/dist/services/configurationService.d.ts.map +1 -0
  43. package/dist/services/configurationService.js +585 -0
  44. package/dist/services/fileWatcher.d.ts.map +1 -1
  45. package/dist/services/fileWatcher.js +5 -6
  46. package/dist/services/hook.d.ts +7 -124
  47. package/dist/services/hook.d.ts.map +1 -1
  48. package/dist/services/hook.js +46 -458
  49. package/dist/services/jsonlHandler.d.ts +24 -15
  50. package/dist/services/jsonlHandler.d.ts.map +1 -1
  51. package/dist/services/jsonlHandler.js +67 -88
  52. package/dist/services/memory.d.ts +0 -9
  53. package/dist/services/memory.d.ts.map +1 -1
  54. package/dist/services/memory.js +2 -49
  55. package/dist/services/session.d.ts +82 -33
  56. package/dist/services/session.d.ts.map +1 -1
  57. package/dist/services/session.js +275 -181
  58. package/dist/tools/bashTool.d.ts.map +1 -1
  59. package/dist/tools/bashTool.js +72 -13
  60. package/dist/tools/deleteFileTool.d.ts.map +1 -1
  61. package/dist/tools/deleteFileTool.js +25 -0
  62. package/dist/tools/editTool.d.ts.map +1 -1
  63. package/dist/tools/editTool.js +30 -6
  64. package/dist/tools/lspTool.d.ts +6 -0
  65. package/dist/tools/lspTool.d.ts.map +1 -0
  66. package/dist/tools/lspTool.js +589 -0
  67. package/dist/tools/multiEditTool.d.ts.map +1 -1
  68. package/dist/tools/multiEditTool.js +26 -7
  69. package/dist/tools/readTool.d.ts.map +1 -1
  70. package/dist/tools/readTool.js +111 -2
  71. package/dist/tools/skillTool.js +2 -2
  72. package/dist/tools/todoWriteTool.d.ts.map +1 -1
  73. package/dist/tools/todoWriteTool.js +23 -0
  74. package/dist/tools/types.d.ts +11 -8
  75. package/dist/tools/types.d.ts.map +1 -1
  76. package/dist/tools/writeTool.d.ts.map +1 -1
  77. package/dist/tools/writeTool.js +25 -9
  78. package/dist/types/commands.d.ts +0 -1
  79. package/dist/types/commands.d.ts.map +1 -1
  80. package/dist/types/config.d.ts +4 -0
  81. package/dist/types/config.d.ts.map +1 -1
  82. package/dist/types/configuration.d.ts +69 -0
  83. package/dist/types/configuration.d.ts.map +1 -0
  84. package/dist/types/configuration.js +8 -0
  85. package/dist/types/core.d.ts +10 -0
  86. package/dist/types/core.d.ts.map +1 -1
  87. package/dist/types/environment.d.ts +41 -0
  88. package/dist/types/environment.d.ts.map +1 -1
  89. package/dist/types/fileSearch.d.ts +5 -0
  90. package/dist/types/fileSearch.d.ts.map +1 -0
  91. package/dist/types/fileSearch.js +1 -0
  92. package/dist/types/hooks.d.ts +11 -2
  93. package/dist/types/hooks.d.ts.map +1 -1
  94. package/dist/types/hooks.js +1 -7
  95. package/dist/types/index.d.ts +5 -0
  96. package/dist/types/index.d.ts.map +1 -1
  97. package/dist/types/index.js +5 -0
  98. package/dist/types/lsp.d.ts +90 -0
  99. package/dist/types/lsp.d.ts.map +1 -0
  100. package/dist/types/lsp.js +4 -0
  101. package/dist/types/messaging.d.ts +6 -11
  102. package/dist/types/messaging.d.ts.map +1 -1
  103. package/dist/types/permissions.d.ts +35 -0
  104. package/dist/types/permissions.d.ts.map +1 -0
  105. package/dist/types/permissions.js +12 -0
  106. package/dist/types/session.d.ts +1 -6
  107. package/dist/types/session.d.ts.map +1 -1
  108. package/dist/types/skills.d.ts +1 -0
  109. package/dist/types/skills.d.ts.map +1 -1
  110. package/dist/types/tools.d.ts +35 -0
  111. package/dist/types/tools.d.ts.map +1 -0
  112. package/dist/types/tools.js +4 -0
  113. package/dist/utils/abortUtils.d.ts +34 -0
  114. package/dist/utils/abortUtils.d.ts.map +1 -0
  115. package/dist/utils/abortUtils.js +92 -0
  116. package/dist/utils/bashHistory.d.ts +4 -0
  117. package/dist/utils/bashHistory.d.ts.map +1 -1
  118. package/dist/utils/bashHistory.js +21 -4
  119. package/dist/utils/builtinSubagents.d.ts +7 -0
  120. package/dist/utils/builtinSubagents.d.ts.map +1 -0
  121. package/dist/utils/builtinSubagents.js +65 -0
  122. package/dist/utils/cacheControlUtils.d.ts +8 -33
  123. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  124. package/dist/utils/cacheControlUtils.js +83 -126
  125. package/dist/utils/constants.d.ts +0 -12
  126. package/dist/utils/constants.d.ts.map +1 -1
  127. package/dist/utils/constants.js +1 -13
  128. package/dist/utils/convertMessagesForAPI.d.ts +2 -1
  129. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  130. package/dist/utils/convertMessagesForAPI.js +33 -14
  131. package/dist/utils/fileSearch.d.ts +14 -0
  132. package/dist/utils/fileSearch.d.ts.map +1 -0
  133. package/dist/utils/fileSearch.js +88 -0
  134. package/dist/utils/fileUtils.d.ts +14 -2
  135. package/dist/utils/fileUtils.d.ts.map +1 -1
  136. package/dist/utils/fileUtils.js +101 -17
  137. package/dist/utils/globalLogger.d.ts +0 -14
  138. package/dist/utils/globalLogger.d.ts.map +1 -1
  139. package/dist/utils/globalLogger.js +0 -16
  140. package/dist/utils/largeOutputHandler.d.ts +15 -0
  141. package/dist/utils/largeOutputHandler.d.ts.map +1 -0
  142. package/dist/utils/largeOutputHandler.js +40 -0
  143. package/dist/utils/markdownParser.d.ts.map +1 -1
  144. package/dist/utils/markdownParser.js +1 -17
  145. package/dist/utils/messageOperations.d.ts +1 -11
  146. package/dist/utils/messageOperations.d.ts.map +1 -1
  147. package/dist/utils/messageOperations.js +7 -24
  148. package/dist/utils/pathEncoder.d.ts +4 -0
  149. package/dist/utils/pathEncoder.d.ts.map +1 -1
  150. package/dist/utils/pathEncoder.js +16 -9
  151. package/dist/utils/subagentParser.d.ts +2 -2
  152. package/dist/utils/subagentParser.d.ts.map +1 -1
  153. package/dist/utils/subagentParser.js +10 -7
  154. package/dist/utils/tokenEstimator.d.ts +39 -0
  155. package/dist/utils/tokenEstimator.d.ts.map +1 -0
  156. package/dist/utils/tokenEstimator.js +55 -0
  157. package/package.json +5 -8
  158. package/src/agent.ts +460 -216
  159. package/src/index.ts +2 -0
  160. package/src/managers/aiManager.ts +107 -111
  161. package/src/managers/backgroundBashManager.ts +4 -3
  162. package/src/managers/hookManager.ts +44 -39
  163. package/src/managers/liveConfigManager.ts +524 -138
  164. package/src/managers/lspManager.ts +434 -0
  165. package/src/managers/messageManager.ts +73 -103
  166. package/src/managers/permissionManager.ts +276 -0
  167. package/src/managers/skillManager.ts +3 -1
  168. package/src/managers/slashCommandManager.ts +1 -2
  169. package/src/managers/subagentManager.ts +116 -159
  170. package/src/managers/toolManager.ts +95 -3
  171. package/src/services/aiService.ts +207 -26
  172. package/src/services/configurationService.ts +762 -0
  173. package/src/services/fileWatcher.ts +5 -6
  174. package/src/services/hook.ts +50 -631
  175. package/src/services/jsonlHandler.ts +84 -100
  176. package/src/services/memory.ts +2 -59
  177. package/src/services/session.ts +338 -213
  178. package/src/tools/bashTool.ts +89 -16
  179. package/src/tools/deleteFileTool.ts +36 -0
  180. package/src/tools/editTool.ts +41 -7
  181. package/src/tools/lspTool.ts +760 -0
  182. package/src/tools/multiEditTool.ts +37 -8
  183. package/src/tools/readTool.ts +125 -2
  184. package/src/tools/skillTool.ts +2 -2
  185. package/src/tools/todoWriteTool.ts +33 -1
  186. package/src/tools/types.ts +15 -9
  187. package/src/tools/writeTool.ts +36 -10
  188. package/src/types/commands.ts +0 -1
  189. package/src/types/config.ts +5 -0
  190. package/src/types/configuration.ts +73 -0
  191. package/src/types/core.ts +11 -0
  192. package/src/types/environment.ts +44 -0
  193. package/src/types/fileSearch.ts +4 -0
  194. package/src/types/hooks.ts +14 -11
  195. package/src/types/index.ts +5 -0
  196. package/src/types/lsp.ts +96 -0
  197. package/src/types/messaging.ts +8 -13
  198. package/src/types/permissions.ts +48 -0
  199. package/src/types/session.ts +3 -8
  200. package/src/types/skills.ts +1 -0
  201. package/src/types/tools.ts +38 -0
  202. package/src/utils/abortUtils.ts +118 -0
  203. package/src/utils/bashHistory.ts +28 -4
  204. package/src/utils/builtinSubagents.ts +71 -0
  205. package/src/utils/cacheControlUtils.ts +106 -171
  206. package/src/utils/constants.ts +1 -16
  207. package/src/utils/convertMessagesForAPI.ts +38 -14
  208. package/src/utils/fileSearch.ts +107 -0
  209. package/src/utils/fileUtils.ts +114 -19
  210. package/src/utils/globalLogger.ts +0 -17
  211. package/src/utils/largeOutputHandler.ts +55 -0
  212. package/src/utils/markdownParser.ts +1 -19
  213. package/src/utils/messageOperations.ts +7 -35
  214. package/src/utils/pathEncoder.ts +24 -9
  215. package/src/utils/subagentParser.ts +11 -8
  216. package/src/utils/tokenEstimator.ts +68 -0
  217. package/dist/constants/events.d.ts +0 -28
  218. package/dist/constants/events.d.ts.map +0 -1
  219. package/dist/constants/events.js +0 -27
  220. package/dist/services/configurationWatcher.d.ts +0 -120
  221. package/dist/services/configurationWatcher.d.ts.map +0 -1
  222. package/dist/services/configurationWatcher.js +0 -439
  223. package/dist/services/memoryStore.d.ts +0 -81
  224. package/dist/services/memoryStore.d.ts.map +0 -1
  225. package/dist/services/memoryStore.js +0 -200
  226. package/dist/types/memoryStore.d.ts +0 -82
  227. package/dist/types/memoryStore.d.ts.map +0 -1
  228. package/dist/types/memoryStore.js +0 -7
  229. package/dist/utils/configResolver.d.ts +0 -65
  230. package/dist/utils/configResolver.d.ts.map +0 -1
  231. package/dist/utils/configResolver.js +0 -210
  232. package/src/constants/events.ts +0 -38
  233. package/src/services/configurationWatcher.ts +0 -622
  234. package/src/services/memoryStore.ts +0 -279
  235. package/src/types/memoryStore.ts +0 -94
  236. package/src/utils/configResolver.ts +0 -302
@@ -1,26 +1,33 @@
1
1
  /**
2
- * Hook Services
2
+ * Hook Execution Services
3
3
  *
4
- * Consolidated hook services providing both execution and configuration functionality.
5
- * Combines hook command execution and settings management into a single module.
4
+ * Provides hook command execution functionality and hook-specific configuration loading.
5
+ * This module focuses on hook execution while delegating general Wave configuration
6
+ * management to ConfigurationService.
6
7
  */
7
8
  import { spawn } from "child_process";
8
- import { existsSync, readFileSync } from "fs";
9
- import { getUserConfigPath, getProjectConfigPath, getUserConfigPaths, getProjectConfigPaths, hasAnyConfig, getConfigurationInfo, } from "../utils/configPaths.js";
10
- import { getSessionFilePath, isValidHookEvent, } from "../types/hooks.js";
11
- import { isValidEnvironmentVars, } from "../types/environment.js";
9
+ import { generateSessionFilePath } from "./session.js";
12
10
  // =============================================================================
13
11
  // Hook Execution Functions
14
12
  // =============================================================================
15
13
  /**
16
14
  * Build JSON input data for hook stdin
17
15
  */
18
- function buildHookJsonInput(context) {
16
+ async function buildHookJsonInput(context) {
17
+ const workdir = context.cwd || context.projectDir || process.cwd();
18
+ let transcriptPath = context.transcriptPath;
19
+ if (!transcriptPath && context.sessionId) {
20
+ try {
21
+ transcriptPath = await generateSessionFilePath(context.sessionId, workdir);
22
+ }
23
+ catch {
24
+ transcriptPath = "";
25
+ }
26
+ }
19
27
  const jsonInput = {
20
28
  session_id: context.sessionId || "unknown",
21
- transcript_path: context.transcriptPath ||
22
- (context.sessionId ? getSessionFilePath(context.sessionId) : ""),
23
- cwd: context.cwd || context.projectDir,
29
+ transcript_path: transcriptPath || "",
30
+ cwd: workdir,
24
31
  hook_event_name: context.event,
25
32
  };
26
33
  // Add optional fields based on event type
@@ -43,12 +50,21 @@ function buildHookJsonInput(context) {
43
50
  if (context.subagentType !== undefined) {
44
51
  jsonInput.subagent_type = context.subagentType;
45
52
  }
53
+ // Add notification fields for Notification events
54
+ if (context.event === "Notification") {
55
+ if (context.message !== undefined) {
56
+ jsonInput.message = context.message;
57
+ }
58
+ if (context.notificationType !== undefined) {
59
+ jsonInput.notification_type = context.notificationType;
60
+ }
61
+ }
46
62
  return jsonInput;
47
63
  }
48
64
  /**
49
65
  * Execute a single hook command
50
66
  */
51
- export async function executeCommand(command, context, options, additionalEnvVars) {
67
+ export async function executeCommand(command, context, options) {
52
68
  const defaultTimeout = 10000; // 10 seconds
53
69
  const maxTimeout = 300000; // 5 minutes
54
70
  const skipExecution = process.env.NODE_ENV === "test" &&
@@ -66,6 +82,17 @@ export async function executeCommand(command, context, options, additionalEnvVar
66
82
  timedOut: false,
67
83
  };
68
84
  }
85
+ // Prepare JSON input for hooks that need it
86
+ let jsonInput = null;
87
+ if ("sessionId" in context) {
88
+ try {
89
+ const hookJsonInput = await buildHookJsonInput(context);
90
+ jsonInput = JSON.stringify(hookJsonInput, null, 2);
91
+ }
92
+ catch {
93
+ // Continue execution even if JSON input preparation fails
94
+ }
95
+ }
69
96
  return new Promise((resolve) => {
70
97
  let stdout = "";
71
98
  let stderr = "";
@@ -78,8 +105,8 @@ export async function executeCommand(command, context, options, additionalEnvVar
78
105
  stdio: ["pipe", "pipe", "pipe"],
79
106
  cwd: context.projectDir,
80
107
  env: {
81
- ...process.env,
82
- ...additionalEnvVars, // Merge additional environment variables from Wave configuration
108
+ ...process.env, // Environment variables from process.env
109
+ ...("env" in context ? context.env || {} : {}), // Additional environment variables from configuration (if ExtendedHookExecutionContext)
83
110
  HOOK_EVENT: context.event,
84
111
  HOOK_TOOL_NAME: context.toolName || "",
85
112
  HOOK_PROJECT_DIR: context.projectDir,
@@ -108,11 +135,10 @@ export async function executeCommand(command, context, options, additionalEnvVar
108
135
  stderr += data.toString();
109
136
  });
110
137
  }
111
- // Send JSON input to stdin if we have extended context
112
- if (childProcess.stdin && "sessionId" in context) {
138
+ // Send JSON input to stdin if we have prepared it
139
+ if (childProcess.stdin && jsonInput) {
113
140
  try {
114
- const jsonInput = buildHookJsonInput(context);
115
- childProcess.stdin.write(JSON.stringify(jsonInput, null, 2));
141
+ childProcess.stdin.write(jsonInput);
116
142
  childProcess.stdin.end();
117
143
  }
118
144
  catch {
@@ -153,10 +179,10 @@ export async function executeCommand(command, context, options, additionalEnvVar
153
179
  /**
154
180
  * Execute multiple commands in sequence
155
181
  */
156
- export async function executeCommands(commands, context, options, additionalEnvVars) {
182
+ export async function executeCommands(commands, context, options) {
157
183
  const results = [];
158
184
  for (const command of commands) {
159
- const result = await executeCommand(command, context, options, additionalEnvVars);
185
+ const result = await executeCommand(command, context, options);
160
186
  results.push(result);
161
187
  // Stop on first failure unless continueOnFailure is set
162
188
  if (!result.success && !options?.continueOnFailure) {
@@ -186,441 +212,3 @@ export function isCommandSafe(command) {
186
212
  ];
187
213
  return !dangerousPatterns.some((pattern) => pattern.test(trimmed.toLowerCase()));
188
214
  }
189
- // =============================================================================
190
- // Environment Variable Functions
191
- // =============================================================================
192
- /**
193
- * Validate environment variable configuration
194
- */
195
- export function validateEnvironmentConfig(env, configPath) {
196
- const result = {
197
- isValid: true,
198
- errors: [],
199
- warnings: [],
200
- };
201
- // Check if env is defined
202
- if (env === undefined || env === null) {
203
- return result; // undefined/null env is valid (means no env vars)
204
- }
205
- // Validate that env is a Record<string, string>
206
- if (!isValidEnvironmentVars(env)) {
207
- result.isValid = false;
208
- result.errors.push(`Invalid env field format${configPath ? ` in ${configPath}` : ""}. Environment variables must be a Record<string, string>.`);
209
- return result;
210
- }
211
- // Additional validation for environment variable names
212
- const envVars = env;
213
- for (const [key, value] of Object.entries(envVars)) {
214
- // Check for valid environment variable naming convention
215
- if (!/^[A-Z_][A-Z0-9_]*$/i.test(key)) {
216
- result.warnings.push(`Environment variable '${key}' does not follow standard naming convention (alphanumeric and underscores only).`);
217
- }
218
- // Check for empty values
219
- if (value === "") {
220
- result.warnings.push(`Environment variable '${key}' has an empty value.`);
221
- }
222
- // Check for reserved variable names that might cause conflicts
223
- const reservedNames = [
224
- "PATH",
225
- "HOME",
226
- "USER",
227
- "PWD",
228
- "SHELL",
229
- "TERM",
230
- "NODE_ENV",
231
- ];
232
- if (reservedNames.includes(key.toUpperCase())) {
233
- result.warnings.push(`Environment variable '${key}' overrides a system variable, which may cause unexpected behavior.`);
234
- }
235
- }
236
- return result;
237
- }
238
- /**
239
- * Merge environment configurations with project taking precedence over user
240
- */
241
- export function mergeEnvironmentConfig(userEnv, projectEnv, options = {}) {
242
- const userVars = userEnv || {};
243
- const projectVars = projectEnv || {};
244
- const mergedVars = {};
245
- const conflicts = [];
246
- // Start with user environment variables
247
- Object.assign(mergedVars, userVars);
248
- // Override with project environment variables and track conflicts
249
- for (const [key, projectValue] of Object.entries(projectVars)) {
250
- const userValue = userVars[key];
251
- if (userValue !== undefined &&
252
- userValue !== projectValue &&
253
- options.includeConflictWarnings !== false) {
254
- // Conflict detected - project value takes precedence
255
- conflicts.push({
256
- key,
257
- userValue,
258
- projectValue,
259
- resolvedValue: projectValue,
260
- });
261
- }
262
- mergedVars[key] = projectValue;
263
- }
264
- return {
265
- userVars,
266
- projectVars,
267
- mergedVars,
268
- conflicts,
269
- };
270
- }
271
- // =============================================================================
272
- // Hook Settings Functions (using centralized config path utilities)
273
- // =============================================================================
274
- /**
275
- * Get the user-specific hooks configuration file path (legacy function)
276
- * @deprecated Use getUserConfigPaths() from configPaths.ts for better priority support
277
- */
278
- export function getUserHooksConfigPath() {
279
- return getUserConfigPath();
280
- }
281
- /**
282
- * Get the project-specific hooks configuration file path (legacy function)
283
- * @deprecated Use getProjectConfigPaths() from configPaths.ts for better priority support
284
- */
285
- export function getProjectHooksConfigPath(workdir) {
286
- return getProjectConfigPath(workdir);
287
- }
288
- /**
289
- * Get the user-specific hooks configuration file paths in priority order
290
- * @deprecated Use getUserConfigPaths() from configPaths.ts directly
291
- */
292
- export function getUserHooksConfigPaths() {
293
- return getUserConfigPaths();
294
- }
295
- /**
296
- * Get the project-specific hooks configuration file paths in priority order
297
- * @deprecated Use getProjectConfigPaths() from configPaths.ts directly
298
- */
299
- export function getProjectHooksConfigPaths(workdir) {
300
- return getProjectConfigPaths(workdir);
301
- }
302
- /**
303
- * Load Wave configuration from a JSON file with graceful fallback
304
- * This version is optimized for live reload scenarios where invalid config should not crash the system
305
- */
306
- export function loadWaveConfigFromFileWithFallback(filePath, previousValidConfig) {
307
- if (!existsSync(filePath)) {
308
- return { config: null, usedFallback: false };
309
- }
310
- try {
311
- const content = readFileSync(filePath, "utf-8");
312
- const config = JSON.parse(content);
313
- // Validate basic structure
314
- if (!config || typeof config !== "object") {
315
- const error = `Invalid configuration structure in ${filePath}`;
316
- return {
317
- config: previousValidConfig || null,
318
- error,
319
- usedFallback: !!previousValidConfig,
320
- };
321
- }
322
- // Validate environment variables if present
323
- if (config.env !== undefined) {
324
- const envValidation = validateEnvironmentConfig(config.env, filePath);
325
- if (!envValidation.isValid) {
326
- const error = `Environment variable validation failed in ${filePath}: ${envValidation.errors.join(", ")}`;
327
- return {
328
- config: previousValidConfig || null,
329
- error,
330
- usedFallback: !!previousValidConfig,
331
- };
332
- }
333
- // Log warnings if any
334
- if (envValidation.warnings.length > 0) {
335
- console.warn(`Environment variable warnings in ${filePath}:\n- ${envValidation.warnings.join("\n- ")}`);
336
- }
337
- }
338
- // Return valid configuration
339
- return {
340
- config: {
341
- hooks: config.hooks || undefined,
342
- env: config.env || undefined,
343
- },
344
- usedFallback: false,
345
- };
346
- }
347
- catch (error) {
348
- let errorMessage;
349
- if (error instanceof SyntaxError) {
350
- errorMessage = `Invalid JSON syntax in ${filePath}: ${error.message}`;
351
- }
352
- else {
353
- errorMessage = `Error loading configuration from ${filePath}: ${error.message}`;
354
- }
355
- return {
356
- config: previousValidConfig || null,
357
- error: errorMessage,
358
- usedFallback: !!previousValidConfig,
359
- };
360
- }
361
- }
362
- /**
363
- * Load Wave configuration from multiple file paths in priority order
364
- * Returns the first valid configuration found, or null if none exist
365
- */
366
- export function loadWaveConfigFromFiles(filePaths) {
367
- for (const filePath of filePaths) {
368
- const config = loadWaveConfigFromFile(filePath);
369
- if (config !== null) {
370
- return config;
371
- }
372
- }
373
- return null;
374
- }
375
- /**
376
- * Load Wave configuration from multiple file paths with graceful fallback
377
- * Returns the first valid configuration found with fallback support
378
- */
379
- export function loadWaveConfigFromFilesWithFallback(filePaths, previousValidConfig) {
380
- let lastError;
381
- for (const filePath of filePaths) {
382
- const result = loadWaveConfigFromFileWithFallback(filePath, previousValidConfig);
383
- if (result.config !== null && !result.usedFallback) {
384
- // Found a valid config at this path
385
- return {
386
- config: result.config,
387
- error: result.error,
388
- usedFallback: result.usedFallback,
389
- usedPath: filePath,
390
- };
391
- }
392
- if (result.error) {
393
- lastError = result.error;
394
- }
395
- }
396
- // No valid config found in any path
397
- return {
398
- config: previousValidConfig || null,
399
- error: lastError,
400
- usedFallback: !!previousValidConfig,
401
- };
402
- }
403
- /**
404
- * Load and merge Wave configuration with graceful fallback for live reload
405
- * Provides error recovery by falling back to previous valid configuration
406
- */
407
- export function loadMergedWaveConfigWithFallback(workdir, previousValidConfig) {
408
- const errors = [];
409
- let usedFallback = false;
410
- // Load user config with fallback (check .local.json first, then .json)
411
- const userResult = loadWaveConfigFromFilesWithFallback(getUserHooksConfigPaths(), previousValidConfig);
412
- if (userResult.error) {
413
- errors.push(`User config: ${userResult.error}`);
414
- }
415
- if (userResult.usedFallback) {
416
- usedFallback = true;
417
- }
418
- // Load project config with fallback (check .local.json first, then .json)
419
- const projectResult = loadWaveConfigFromFilesWithFallback(getProjectHooksConfigPaths(workdir), previousValidConfig);
420
- if (projectResult.error) {
421
- errors.push(`Project config: ${projectResult.error}`);
422
- }
423
- if (projectResult.usedFallback) {
424
- usedFallback = true;
425
- }
426
- const userConfig = userResult.config;
427
- const projectConfig = projectResult.config;
428
- // If both configs failed and no fallback available
429
- if (!userConfig && !projectConfig && errors.length > 0) {
430
- return {
431
- config: previousValidConfig || null,
432
- errors,
433
- usedFallback: !!previousValidConfig,
434
- };
435
- }
436
- // No configuration found at all
437
- if (!userConfig && !projectConfig) {
438
- return { config: null, errors, usedFallback };
439
- }
440
- // Only one configuration found
441
- if (!userConfig)
442
- return { config: projectConfig, errors, usedFallback };
443
- if (!projectConfig)
444
- return { config: userConfig, errors, usedFallback };
445
- // Merge configurations (project overrides user)
446
- try {
447
- const mergedHooks = {};
448
- // Merge environment variables using the new mergeEnvironmentConfig function
449
- const environmentContext = mergeEnvironmentConfig(userConfig.env, projectConfig.env, { includeConflictWarnings: true });
450
- // Merge hooks (combine arrays, project configs come after user configs)
451
- const allEvents = new Set([
452
- ...Object.keys(userConfig.hooks || {}),
453
- ...Object.keys(projectConfig.hooks || {}),
454
- ]);
455
- for (const event of allEvents) {
456
- if (!isValidHookEvent(event))
457
- continue;
458
- const userEventConfigs = userConfig.hooks?.[event] || [];
459
- const projectEventConfigs = projectConfig.hooks?.[event] || [];
460
- // Project configurations take precedence
461
- mergedHooks[event] = [...userEventConfigs, ...projectEventConfigs];
462
- }
463
- const mergedConfig = {
464
- hooks: Object.keys(mergedHooks).length > 0 ? mergedHooks : undefined,
465
- env: Object.keys(environmentContext.mergedVars).length > 0
466
- ? environmentContext.mergedVars
467
- : undefined,
468
- };
469
- return { config: mergedConfig, errors, usedFallback };
470
- }
471
- catch (error) {
472
- errors.push(`Merge error: ${error.message}`);
473
- return {
474
- config: previousValidConfig || null,
475
- errors,
476
- usedFallback: !!previousValidConfig,
477
- };
478
- }
479
- }
480
- /**
481
- * Load Wave configuration from a JSON file
482
- * Supports both hooks and environment variables with proper validation
483
- */
484
- export function loadWaveConfigFromFile(filePath) {
485
- if (!existsSync(filePath)) {
486
- return null;
487
- }
488
- try {
489
- const content = readFileSync(filePath, "utf-8");
490
- const config = JSON.parse(content);
491
- // Validate basic structure
492
- if (!config || typeof config !== "object") {
493
- throw new Error(`Invalid configuration structure in ${filePath}`);
494
- }
495
- // Validate environment variables if present
496
- if (config.env !== undefined) {
497
- const envValidation = validateEnvironmentConfig(config.env, filePath);
498
- if (!envValidation.isValid) {
499
- throw new Error(`Environment variable validation failed in ${filePath}: ${envValidation.errors.join(", ")}`);
500
- }
501
- // Log warnings if any
502
- if (envValidation.warnings.length > 0) {
503
- console.warn(`Environment variable warnings in ${filePath}:\n- ${envValidation.warnings.join("\n- ")}`);
504
- }
505
- }
506
- return {
507
- hooks: config.hooks || undefined,
508
- env: config.env || undefined,
509
- };
510
- }
511
- catch (error) {
512
- if (error instanceof SyntaxError) {
513
- throw new Error(`Invalid JSON syntax in ${filePath}: ${error.message}`);
514
- }
515
- // Re-throw validation errors and other errors as-is
516
- throw error;
517
- }
518
- }
519
- /**
520
- * Load hooks configuration from a JSON file (legacy function)
521
- */
522
- export function loadHooksConfigFromFile(filePath) {
523
- const waveConfig = loadWaveConfigFromFile(filePath);
524
- if (!waveConfig) {
525
- return null;
526
- }
527
- return waveConfig.hooks || null;
528
- }
529
- /**
530
- * Load user-specific Wave configuration
531
- * Checks .local.json first, then falls back to .json
532
- */
533
- export function loadUserWaveConfig() {
534
- return loadWaveConfigFromFiles(getUserHooksConfigPaths());
535
- }
536
- /**
537
- * Load project-specific Wave configuration
538
- * Checks .local.json first, then falls back to .json
539
- */
540
- export function loadProjectWaveConfig(workdir) {
541
- return loadWaveConfigFromFiles(getProjectHooksConfigPaths(workdir));
542
- }
543
- /**
544
- * Load user-specific hooks configuration (legacy function)
545
- */
546
- export function loadUserHooksConfig() {
547
- const waveConfig = loadUserWaveConfig();
548
- return waveConfig?.hooks || null;
549
- }
550
- /**
551
- * Load project-specific hooks configuration (legacy function)
552
- */
553
- export function loadProjectHooksConfig(workdir) {
554
- const waveConfig = loadProjectWaveConfig(workdir);
555
- return waveConfig?.hooks || null;
556
- }
557
- /**
558
- * Load and merge Wave configuration from both user and project sources
559
- * Project configuration takes precedence over user configuration
560
- * Checks .local.json files first, then falls back to .json files
561
- */
562
- export function loadMergedWaveConfig(workdir) {
563
- const userConfig = loadUserWaveConfig();
564
- const projectConfig = loadProjectWaveConfig(workdir);
565
- // No configuration found
566
- if (!userConfig && !projectConfig) {
567
- return null;
568
- }
569
- // Only one configuration found
570
- if (!userConfig)
571
- return projectConfig;
572
- if (!projectConfig)
573
- return userConfig;
574
- // Merge configurations (project overrides user)
575
- const mergedHooks = {};
576
- // Merge environment variables using the new mergeEnvironmentConfig function
577
- const environmentContext = mergeEnvironmentConfig(userConfig.env, projectConfig.env, { includeConflictWarnings: true });
578
- // Log environment variable conflicts if any
579
- if (environmentContext.conflicts.length > 0) {
580
- console.warn(`Environment variable conflicts detected (project values take precedence):\n${environmentContext.conflicts
581
- .map((conflict) => `- ${conflict.key}: "${conflict.userValue}" → "${conflict.projectValue}"`)
582
- .join("\n")}`);
583
- }
584
- // Merge hooks (combine arrays, project configs come after user configs)
585
- const allEvents = new Set([
586
- ...Object.keys(userConfig.hooks || {}),
587
- ...Object.keys(projectConfig.hooks || {}),
588
- ]);
589
- for (const event of allEvents) {
590
- if (!isValidHookEvent(event))
591
- continue;
592
- const userEventConfigs = userConfig.hooks?.[event] || [];
593
- const projectEventConfigs = projectConfig.hooks?.[event] || [];
594
- // Project configurations take precedence
595
- mergedHooks[event] = [...userEventConfigs, ...projectEventConfigs];
596
- }
597
- return {
598
- hooks: Object.keys(mergedHooks).length > 0 ? mergedHooks : undefined,
599
- env: Object.keys(environmentContext.mergedVars).length > 0
600
- ? environmentContext.mergedVars
601
- : undefined,
602
- };
603
- }
604
- /**
605
- * Load and merge hooks configuration from both user and project sources (legacy function)
606
- */
607
- export function loadMergedHooksConfig(workdir) {
608
- const waveConfig = loadMergedWaveConfig(workdir);
609
- return waveConfig?.hooks || null;
610
- }
611
- /**
612
- * Check if hooks configuration exists (user or project)
613
- * Checks both .local.json and .json variants
614
- * @deprecated Use hasAnyConfig() from configPaths.ts for better functionality
615
- */
616
- export function hasHooksConfiguration(workdir) {
617
- return hasAnyConfig(workdir);
618
- }
619
- /**
620
- * Get hooks configuration information for debugging
621
- * Includes both .local.json and .json variants
622
- * @deprecated Use getConfigurationInfo() from configPaths.ts for better functionality
623
- */
624
- export function getHooksConfigurationInfo(workdir) {
625
- return getConfigurationInfo(workdir);
626
- }
@@ -3,7 +3,7 @@
3
3
  * Handles reading and writing JSONL (JSON Lines) session files for improved performance
4
4
  */
5
5
  import type { Message } from "../types/index.js";
6
- import type { SessionMessage, SessionMetadataLine } from "../types/session.js";
6
+ import type { SessionMessage, SessionFilename } from "../types/session.js";
7
7
  /**
8
8
  * JSONL write options
9
9
  */
@@ -17,9 +17,9 @@ export declare class JsonlHandler {
17
17
  private readonly defaultWriteOptions;
18
18
  constructor();
19
19
  /**
20
- * Create a new session file with metadata header
20
+ * Create a new session file (simplified - no metadata header)
21
21
  */
22
- createSession(filePath: string, sessionId: string, workdir: string, sessionType?: "main" | "subagent", parentSessionId?: string, subagentType?: string): Promise<void>;
22
+ createSession(filePath: string): Promise<void>;
23
23
  /**
24
24
  * Append a single message to JSONL file
25
25
  */
@@ -33,23 +33,13 @@ export declare class JsonlHandler {
33
33
  */
34
34
  append(filePath: string, messages: SessionMessage[], options?: JsonlWriteOptions): Promise<void>;
35
35
  /**
36
- * Read all messages from JSONL file
37
- * Includes metadata handling for backward compatibility
36
+ * Read all messages from JSONL file (simplified - no metadata handling)
38
37
  */
39
38
  read(filePath: string): Promise<SessionMessage[]>;
40
39
  /**
41
- * Get the last message from JSONL file using efficient file reading
40
+ * Get the last message from JSONL file using efficient file reading (simplified)
42
41
  */
43
42
  getLastMessage(filePath: string): Promise<SessionMessage | null>;
44
- /**
45
- * Read session metadata from first line (streaming - only reads first line)
46
- */
47
- readMetadata(filePath: string): Promise<SessionMetadataLine | null>;
48
- /**
49
- * Check if a session file has metadata (first line check only)
50
- * Very efficient - only reads first line
51
- */
52
- hasMetadata(filePath: string): Promise<boolean>;
53
43
  /**
54
44
  * Validate messages before writing
55
45
  */
@@ -58,5 +48,24 @@ export declare class JsonlHandler {
58
48
  * Ensure directory exists for the given file path
59
49
  */
60
50
  private ensureDirectory;
51
+ /**
52
+ * Parse session metadata from filename
53
+ * @param filePath - Path to the session file
54
+ * @returns Parsed session filename metadata
55
+ */
56
+ parseSessionFilename(filePath: string): SessionFilename;
57
+ /**
58
+ * Validate filename format
59
+ * @param filename - Filename to validate
60
+ * @returns True if valid, false otherwise
61
+ */
62
+ isValidSessionFilename(filename: string): boolean;
63
+ /**
64
+ * Generate simple filename for sessions
65
+ * @param sessionId - UUID session identifier
66
+ * @param sessionType - Type of session ("main" or "subagent")
67
+ * @returns Generated filename
68
+ */
69
+ generateSessionFilename(sessionId: string, sessionType: "main" | "subagent"): string;
61
70
  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