wave-agent-sdk 1.0.5 → 1.0.7

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 (202) hide show
  1. package/dist/agent.d.ts +34 -1
  2. package/dist/agent.js +49 -4
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.js +1 -1
  5. package/dist/managers/aiManager.d.ts +36 -0
  6. package/dist/managers/aiManager.js +240 -11
  7. package/dist/managers/messageManager.d.ts +2 -4
  8. package/dist/managers/messageManager.js +14 -7
  9. package/dist/managers/slashCommandManager.js +28 -0
  10. package/dist/managers/subagentManager.d.ts +0 -2
  11. package/dist/services/aiService.d.ts +2 -3
  12. package/dist/services/aiService.js +4 -18
  13. package/dist/services/configurationService.d.ts +7 -0
  14. package/dist/services/configurationService.js +10 -0
  15. package/dist/telemetry/instrumentation.d.ts +1 -1
  16. package/dist/telemetry/instrumentation.js +57 -28
  17. package/dist/tools/bashTool.js +16 -6
  18. package/dist/tools/grepTool.js +11 -3
  19. package/dist/types/core.d.ts +1 -34
  20. package/dist/types/index.d.ts +4 -0
  21. package/dist/types/messaging.d.ts +2 -0
  22. package/dist/utils/cacheControlUtils.d.ts +5 -27
  23. package/dist/utils/cacheControlUtils.js +12 -73
  24. package/dist/utils/containerSetup.js +0 -3
  25. package/dist/utils/messageOperations.d.ts +2 -1
  26. package/dist/utils/messageOperations.js +2 -1
  27. package/dist/utils/notificationXml.js +5 -0
  28. package/dist/utils/ripgrep.d.ts +4 -4
  29. package/dist/utils/ripgrep.js +4 -27
  30. package/package.json +20 -8
  31. package/bin/rg +0 -79
  32. package/dist/managers/forkedAgentManager.d.ts +0 -50
  33. package/dist/managers/forkedAgentManager.js +0 -130
  34. package/scripts/install_ripgrep.js +0 -111
  35. package/scripts/postinstall.js +0 -38
  36. package/src/agent.ts +0 -1271
  37. package/src/constants/subagents.ts +0 -4
  38. package/src/constants/toolLimits.ts +0 -15
  39. package/src/constants/tools.ts +0 -24
  40. package/src/core/plugin.ts +0 -237
  41. package/src/core/session.ts +0 -9
  42. package/src/index.ts +0 -38
  43. package/src/managers/MemoryRuleManager.ts +0 -198
  44. package/src/managers/aiManager.ts +0 -2429
  45. package/src/managers/backgroundTaskManager.ts +0 -480
  46. package/src/managers/bangManager.ts +0 -119
  47. package/src/managers/cronManager.ts +0 -401
  48. package/src/managers/foregroundTaskManager.ts +0 -30
  49. package/src/managers/forkedAgentManager.ts +0 -216
  50. package/src/managers/hookManager.ts +0 -1089
  51. package/src/managers/liveConfigManager.ts +0 -445
  52. package/src/managers/lspManager.ts +0 -470
  53. package/src/managers/mcpManager.ts +0 -1010
  54. package/src/managers/messageManager.ts +0 -1184
  55. package/src/managers/messageQueue.ts +0 -157
  56. package/src/managers/permissionManager.ts +0 -1140
  57. package/src/managers/planManager.ts +0 -112
  58. package/src/managers/pluginManager.ts +0 -330
  59. package/src/managers/pluginScopeManager.ts +0 -124
  60. package/src/managers/reversionManager.ts +0 -178
  61. package/src/managers/skillManager.ts +0 -578
  62. package/src/managers/slashCommandManager.ts +0 -564
  63. package/src/managers/subagentManager.ts +0 -915
  64. package/src/managers/toolManager.ts +0 -489
  65. package/src/managers/workflowManager.ts +0 -493
  66. package/src/prompts/autoMemory.ts +0 -33
  67. package/src/prompts/autoMemoryExtraction.ts +0 -146
  68. package/src/prompts/index.ts +0 -506
  69. package/src/prompts/planModeReminders.ts +0 -126
  70. package/src/services/GitService.ts +0 -131
  71. package/src/services/MarketplaceService.ts +0 -1052
  72. package/src/services/MemoryRuleService.ts +0 -71
  73. package/src/services/aiService.ts +0 -919
  74. package/src/services/authService.ts +0 -565
  75. package/src/services/autoMemoryService.ts +0 -280
  76. package/src/services/configurationService.ts +0 -1520
  77. package/src/services/fileWatcher.ts +0 -319
  78. package/src/services/hook.ts +0 -348
  79. package/src/services/initializationService.ts +0 -357
  80. package/src/services/interactionService.ts +0 -229
  81. package/src/services/jsonlHandler.ts +0 -295
  82. package/src/services/memory.ts +0 -234
  83. package/src/services/pluginLoader.ts +0 -252
  84. package/src/services/remoteSettingsService.ts +0 -366
  85. package/src/services/reversionService.ts +0 -122
  86. package/src/services/session.ts +0 -917
  87. package/src/services/taskManager.ts +0 -321
  88. package/src/telemetry/events.ts +0 -65
  89. package/src/telemetry/instrumentation.ts +0 -499
  90. package/src/telemetry/sessionTracing.ts +0 -348
  91. package/src/tools/agentTool.ts +0 -322
  92. package/src/tools/askUserQuestion.ts +0 -160
  93. package/src/tools/bashTool.ts +0 -621
  94. package/src/tools/buildTool.ts +0 -61
  95. package/src/tools/cronCreateTool.ts +0 -161
  96. package/src/tools/cronDeleteTool.ts +0 -51
  97. package/src/tools/cronListTool.ts +0 -47
  98. package/src/tools/editTool.ts +0 -313
  99. package/src/tools/enterPlanMode.ts +0 -124
  100. package/src/tools/enterWorktreeTool.ts +0 -190
  101. package/src/tools/exitPlanMode.ts +0 -139
  102. package/src/tools/exitWorktreeTool.ts +0 -236
  103. package/src/tools/globTool.ts +0 -167
  104. package/src/tools/grepTool.ts +0 -399
  105. package/src/tools/lspTool.ts +0 -883
  106. package/src/tools/readTool.ts +0 -426
  107. package/src/tools/skillTool.ts +0 -248
  108. package/src/tools/taskManagementTools.ts +0 -574
  109. package/src/tools/taskStopTool.ts +0 -78
  110. package/src/tools/types.ts +0 -137
  111. package/src/tools/webFetchTool.ts +0 -373
  112. package/src/tools/workflowTool.ts +0 -205
  113. package/src/tools/writeTool.ts +0 -267
  114. package/src/types/agent.ts +0 -128
  115. package/src/types/auth.ts +0 -19
  116. package/src/types/commands.ts +0 -30
  117. package/src/types/config.ts +0 -43
  118. package/src/types/configuration.ts +0 -168
  119. package/src/types/core.ts +0 -105
  120. package/src/types/cron.ts +0 -13
  121. package/src/types/environment.ts +0 -106
  122. package/src/types/fileSearch.ts +0 -4
  123. package/src/types/history.ts +0 -7
  124. package/src/types/hooks.ts +0 -256
  125. package/src/types/index.ts +0 -41
  126. package/src/types/lsp.ts +0 -98
  127. package/src/types/marketplace.ts +0 -71
  128. package/src/types/mcp.ts +0 -43
  129. package/src/types/memoryRule.ts +0 -31
  130. package/src/types/messaging.ts +0 -114
  131. package/src/types/permissions.ts +0 -80
  132. package/src/types/plugins.ts +0 -39
  133. package/src/types/processes.ts +0 -99
  134. package/src/types/reversion.ts +0 -29
  135. package/src/types/session.ts +0 -12
  136. package/src/types/skills.ts +0 -108
  137. package/src/types/tasks.ts +0 -13
  138. package/src/types/telemetry.ts +0 -98
  139. package/src/types/tools.ts +0 -44
  140. package/src/types/workflow.ts +0 -6
  141. package/src/utils/abortUtils.ts +0 -118
  142. package/src/utils/atomicWrite.ts +0 -61
  143. package/src/utils/bashParser.ts +0 -899
  144. package/src/utils/cacheControlUtils.ts +0 -426
  145. package/src/utils/commandArgumentParser.ts +0 -161
  146. package/src/utils/commandPathResolver.ts +0 -88
  147. package/src/utils/configPaths.ts +0 -220
  148. package/src/utils/configValidator.ts +0 -100
  149. package/src/utils/constants.ts +0 -39
  150. package/src/utils/container.ts +0 -92
  151. package/src/utils/containerSetup.ts +0 -371
  152. package/src/utils/convertMessagesForAPI.ts +0 -326
  153. package/src/utils/cronTasks.ts +0 -128
  154. package/src/utils/cronTasksLock.ts +0 -182
  155. package/src/utils/cronToHuman.ts +0 -99
  156. package/src/utils/customCommands.ts +0 -95
  157. package/src/utils/editUtils.ts +0 -20
  158. package/src/utils/fileFormat.ts +0 -40
  159. package/src/utils/fileSearch.ts +0 -151
  160. package/src/utils/fileUtils.ts +0 -223
  161. package/src/utils/gitUtils.ts +0 -315
  162. package/src/utils/globalLogger.ts +0 -128
  163. package/src/utils/groupMessagesByApiRound.ts +0 -121
  164. package/src/utils/hookMatcher.ts +0 -176
  165. package/src/utils/markdownParser.ts +0 -317
  166. package/src/utils/mcpUtils.ts +0 -138
  167. package/src/utils/messageOperations.ts +0 -659
  168. package/src/utils/modelCapabilities.ts +0 -30
  169. package/src/utils/nameGenerator.ts +0 -99
  170. package/src/utils/notificationXml.ts +0 -57
  171. package/src/utils/openaiClient.ts +0 -251
  172. package/src/utils/parseCronExpression.ts +0 -78
  173. package/src/utils/path.ts +0 -72
  174. package/src/utils/pathEncoder.ts +0 -400
  175. package/src/utils/pathSafety.ts +0 -40
  176. package/src/utils/promptHistory.ts +0 -168
  177. package/src/utils/ripgrep.ts +0 -35
  178. package/src/utils/shellResolver.ts +0 -190
  179. package/src/utils/skillParser.ts +0 -246
  180. package/src/utils/stringUtils.ts +0 -156
  181. package/src/utils/subagentParser.ts +0 -279
  182. package/src/utils/taskReminder.ts +0 -96
  183. package/src/utils/tokenCalculation.ts +0 -43
  184. package/src/utils/tokenEstimate.ts +0 -34
  185. package/src/utils/toolResultStorage.ts +0 -117
  186. package/src/utils/worktreeSession.ts +0 -26
  187. package/src/utils/worktreeUtils.ts +0 -786
  188. package/src/workflow/budgetTracker.ts +0 -34
  189. package/src/workflow/concurrencyLimiter.ts +0 -47
  190. package/src/workflow/journal.ts +0 -95
  191. package/src/workflow/progressReporter.ts +0 -141
  192. package/src/workflow/runState.ts +0 -65
  193. package/src/workflow/scriptRuntime.ts +0 -274
  194. package/src/workflow/structuredOutput.ts +0 -123
  195. package/src/workflow/types.ts +0 -101
  196. package/src/workflow/workflowApis.ts +0 -410
  197. package/vendor/ripgrep/linux-aarch64/rg +0 -0
  198. package/vendor/ripgrep/linux-x86_64/rg +0 -0
  199. package/vendor/ripgrep/macos-aarch64/rg +0 -0
  200. package/vendor/ripgrep/macos-x86_64/rg +0 -0
  201. package/vendor/ripgrep/windows-aarch64/rg.exe +0 -0
  202. package/vendor/ripgrep/windows-x86_64/rg.exe +0 -0
@@ -452,7 +452,7 @@ export function getMessageContent(message) {
452
452
  }
453
453
  return "";
454
454
  }
455
- export const addNotificationMessageToMessages = ({ messages, taskId, taskType, status, summary, outputFile, }) => {
455
+ export const addNotificationMessageToMessages = ({ messages, taskId, taskType, status, summary, outputFile, result, }) => {
456
456
  const block = {
457
457
  type: "task_notification",
458
458
  taskId,
@@ -460,6 +460,7 @@ export const addNotificationMessageToMessages = ({ messages, taskId, taskType, s
460
460
  status,
461
461
  summary,
462
462
  ...(outputFile !== undefined && { outputFile }),
463
+ ...(result !== undefined && { result }),
463
464
  };
464
465
  const notificationMessage = {
465
466
  id: generateMessageId(),
@@ -5,6 +5,9 @@ export function taskNotificationToXml(block) {
5
5
  if (block.outputFile) {
6
6
  xml += `<output-file>${block.outputFile}</output-file>\n`;
7
7
  }
8
+ if (block.result) {
9
+ xml += `<result>${block.result}</result>\n`;
10
+ }
8
11
  xml += `<status>${block.status}</status>\n`;
9
12
  xml += `<summary>${block.summary}</summary>\n`;
10
13
  xml += `</task-notification>`;
@@ -25,6 +28,7 @@ export function parseTaskNotificationXml(xml) {
25
28
  return null;
26
29
  }
27
30
  const outputFile = extractTag(xml, "output-file") || undefined;
31
+ const result = extractTag(xml, "result") || undefined;
28
32
  return {
29
33
  type: "task_notification",
30
34
  taskId,
@@ -32,6 +36,7 @@ export function parseTaskNotificationXml(xml) {
32
36
  status,
33
37
  summary,
34
38
  ...(outputFile && { outputFile }),
39
+ ...(result && { result }),
35
40
  };
36
41
  }
37
42
  catch {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Path to the ripgrep binary bundled in the vendor directory.
3
- * Uses findUpSync to locate the package root, working correctly even
4
- * when bundled (e.g. esbuild into a VS Code extension).
2
+ * Path to the ripgrep binary, provided by the @vscode/ripgrep dependency.
3
+ * The wrapper resolves the platform-specific binary package at import time
4
+ * via optionalDependencies + os/cpu filtering.
5
5
  */
6
- export declare const rgPath: string;
6
+ export { rgPath } from "@vscode/ripgrep";
@@ -1,29 +1,6 @@
1
- import path from "path";
2
- import process from "process";
3
- import { getPackageRoot } from "./configPaths.js";
4
1
  /**
5
- * Detect the current platform and architecture to find the correct bundled ripgrep binary.
2
+ * Path to the ripgrep binary, provided by the @vscode/ripgrep dependency.
3
+ * The wrapper resolves the platform-specific binary package at import time
4
+ * via optionalDependencies + os/cpu filtering.
6
5
  */
7
- function getPlatformKey() {
8
- const platform = process.platform;
9
- const arch = process.arch;
10
- if (platform === "darwin") {
11
- return arch === "arm64" ? "macos-aarch64" : "macos-x86_64";
12
- }
13
- else if (platform === "linux") {
14
- return arch === "arm64" ? "linux-aarch64" : "linux-x86_64";
15
- }
16
- else if (platform === "win32") {
17
- return arch === "arm64" ? "windows-aarch64" : "windows-x86_64";
18
- }
19
- throw new Error(`Unsupported platform: ${platform}-${arch}`);
20
- }
21
- const platformKey = getPlatformKey();
22
- const isWindows = platformKey.startsWith("windows");
23
- const binaryName = isWindows ? "rg.exe" : "rg";
24
- /**
25
- * Path to the ripgrep binary bundled in the vendor directory.
26
- * Uses findUpSync to locate the package root, working correctly even
27
- * when bundled (e.g. esbuild into a VS Code extension).
28
- */
29
- export const rgPath = path.join(getPackageRoot(), `vendor/ripgrep/${platformKey}/${binaryName}`);
6
+ export { rgPath } from "@vscode/ripgrep";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-agent-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "SDK for building AI-powered development tools and agents",
5
5
  "keywords": [
6
6
  "ai",
@@ -13,6 +13,22 @@
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./types": {
22
+ "types": "./dist/types/index.d.ts",
23
+ "default": "./dist/types/index.js"
24
+ },
25
+ "./constants": {
26
+ "types": "./dist/constants/tools.d.ts",
27
+ "default": "./dist/constants/tools.js"
28
+ },
29
+ "./package.json": "./package.json",
30
+ "./*": "./*"
31
+ },
16
32
  "repository": {
17
33
  "type": "git",
18
34
  "url": "https://github.com/netease-lcap/wave-agent.git",
@@ -20,10 +36,6 @@
20
36
  },
21
37
  "files": [
22
38
  "dist",
23
- "src",
24
- "bin",
25
- "vendor",
26
- "scripts",
27
39
  "builtin",
28
40
  "README.md"
29
41
  ],
@@ -33,9 +45,10 @@
33
45
  "@opentelemetry/api-logs": "^0.217.0",
34
46
  "@opentelemetry/exporter-logs-otlp-http": "^0.217.0",
35
47
  "@opentelemetry/exporter-trace-otlp-http": "^0.217.0",
48
+ "@opentelemetry/resources": "^2.7.1",
36
49
  "@opentelemetry/sdk-logs": "^0.217.0",
37
- "@opentelemetry/sdk-node": "^0.217.0",
38
- "@opentelemetry/sdk-trace-node": "^2.7.1",
50
+ "@opentelemetry/sdk-trace-base": "^2.7.1",
51
+ "@vscode/ripgrep": "^1.18.0",
39
52
  "chokidar": "^4.0.3",
40
53
  "cron-parser": "^5.5.0",
41
54
  "find-up": "^8.0.0",
@@ -59,7 +72,6 @@
59
72
  },
60
73
  "license": "MIT",
61
74
  "scripts": {
62
- "postinstall": "node scripts/postinstall.js",
63
75
  "build": "rimraf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
64
76
  "type-check": "tsc --noEmit --incremental",
65
77
  "watch": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --watch",
package/bin/rg DELETED
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env dotslash
2
-
3
- {
4
- "name": "rg",
5
- "platforms": {
6
- "macos-aarch64": {
7
- "size": 1787248,
8
- "hash": "blake3",
9
- "digest": "8d9942032585ea8ee805937634238d9aee7b210069f4703c88fbe568e26fb78a",
10
- "format": "tar.gz",
11
- "path": "ripgrep-14.1.1-aarch64-apple-darwin/rg",
12
- "providers": [
13
- {
14
- "url": "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-aarch64-apple-darwin.tar.gz"
15
- }
16
- ]
17
- },
18
- "linux-aarch64": {
19
- "size": 2047405,
20
- "hash": "blake3",
21
- "digest": "0b670b8fa0a3df2762af2fc82cc4932f684ca4c02dbd1260d4f3133fd4b2a515",
22
- "format": "tar.gz",
23
- "path": "ripgrep-14.1.1-aarch64-unknown-linux-gnu/rg",
24
- "providers": [
25
- {
26
- "url": "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-aarch64-unknown-linux-gnu.tar.gz"
27
- }
28
- ]
29
- },
30
- "macos-x86_64": {
31
- "size": 2082672,
32
- "hash": "blake3",
33
- "digest": "e9b862fc8da3127f92791f0ff6a799504154ca9d36c98bf3e60a81c6b1f7289e",
34
- "format": "tar.gz",
35
- "path": "ripgrep-14.1.1-x86_64-apple-darwin/rg",
36
- "providers": [
37
- {
38
- "url": "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-apple-darwin.tar.gz"
39
- }
40
- ]
41
- },
42
- "linux-x86_64": {
43
- "size": 2566310,
44
- "hash": "blake3",
45
- "digest": "f73cca4e54d78c31f832c7f6e2c0b4db8b04fa3eaa747915727d570893dbee76",
46
- "format": "tar.gz",
47
- "path": "ripgrep-14.1.1-x86_64-unknown-linux-musl/rg",
48
- "providers": [
49
- {
50
- "url": "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz"
51
- }
52
- ]
53
- },
54
- "windows-x86_64": {
55
- "size": 2058893,
56
- "hash": "blake3",
57
- "digest": "a8ce1a6fed4f8093ee997e57f33254e94b2cd18e26358b09db599c89882eadbd",
58
- "format": "zip",
59
- "path": "ripgrep-14.1.1-x86_64-pc-windows-msvc/rg.exe",
60
- "providers": [
61
- {
62
- "url": "https://github.com/BurntSushi/ripgrep/releases/download/14.1.1/ripgrep-14.1.1-x86_64-pc-windows-msvc.zip"
63
- }
64
- ]
65
- },
66
- "windows-aarch64": {
67
- "size": 1667740,
68
- "hash": "blake3",
69
- "digest": "47b971a8c4fca1d23a4e7c19bd4d88465ebc395598458133139406d3bf85f3fa",
70
- "format": "zip",
71
- "path": "rg.exe",
72
- "providers": [
73
- {
74
- "url": "https://github.com/microsoft/ripgrep-prebuilt/releases/download/v13.0.0-13/ripgrep-v13.0.0-13-aarch64-pc-windows-msvc.zip"
75
- }
76
- ]
77
- }
78
- }
79
- }
@@ -1,50 +0,0 @@
1
- import * as fs from "fs";
2
- import type { Message } from "../types/index.js";
3
- import { Container } from "../utils/container.js";
4
- import { type SubagentInstance } from "./subagentManager.js";
5
- import type { PermissionMode } from "../types/permissions.js";
6
- export interface ForkedAgentEntry {
7
- id: string;
8
- instance: SubagentInstance;
9
- logPath: string;
10
- logStream?: fs.WriteStream;
11
- status: "running" | "completed" | "failed";
12
- }
13
- export interface ForkedAgentManagerCallbacks {
14
- onForkedAgentStatusChange?: (entries: ForkedAgentEntry[]) => void;
15
- }
16
- export declare class ForkedAgentManager {
17
- private container;
18
- private activeForks;
19
- private inFlightPromises;
20
- private callbacks;
21
- constructor(container: Container, options?: {
22
- callbacks?: ForkedAgentManagerCallbacks;
23
- });
24
- private get subagentManager();
25
- /**
26
- * Creates a forked subagent with conversation history and executes it asynchronously (fire-and-forget).
27
- * Does NOT interact with BackgroundTaskManager.
28
- */
29
- forkAndExecute(subagentType: string, messages: Message[], parameters: {
30
- description: string;
31
- allowedTools?: string[];
32
- model?: string;
33
- permissionModeOverride?: PermissionMode;
34
- maxTurns?: number;
35
- }, prompt: string): Promise<string>;
36
- private executeFork;
37
- /**
38
- * Abort a running forked agent.
39
- */
40
- stop(id: string): boolean;
41
- /**
42
- * Stop all running forked agents, wait for in-flight executions to settle, and clear the map.
43
- */
44
- cleanup(): Promise<void>;
45
- /**
46
- * Returns list of active forked agents.
47
- */
48
- getActiveForks(): ForkedAgentEntry[];
49
- private notifyChange;
50
- }
@@ -1,130 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import * as os from "os";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { logger } from "../utils/globalLogger.js";
6
- export class ForkedAgentManager {
7
- constructor(container, options = {}) {
8
- this.container = container;
9
- this.activeForks = new Map();
10
- this.inFlightPromises = new Set();
11
- this.callbacks = options.callbacks || {};
12
- }
13
- get subagentManager() {
14
- return this.container.get("SubagentManager");
15
- }
16
- /**
17
- * Creates a forked subagent with conversation history and executes it asynchronously (fire-and-forget).
18
- * Does NOT interact with BackgroundTaskManager.
19
- */
20
- async forkAndExecute(subagentType, messages, parameters, prompt) {
21
- const id = randomUUID();
22
- // Create log file for debugging
23
- const logPath = path.join(os.tmpdir(), `wave-forked-agent-${id}.log`);
24
- const logStream = fs.createWriteStream(logPath, { flags: "a" });
25
- const entry = {
26
- id,
27
- instance: {}, // Temporary placeholder
28
- logPath,
29
- logStream,
30
- status: "running",
31
- };
32
- this.activeForks.set(id, entry);
33
- // Fire-and-forget execution
34
- const forkPromise = this.executeFork(entry, subagentType, messages, parameters, prompt).catch((error) => {
35
- logger.error("Forked agent execution failed:", error);
36
- });
37
- this.inFlightPromises.add(forkPromise);
38
- forkPromise.finally(() => this.inFlightPromises.delete(forkPromise));
39
- return id;
40
- }
41
- async executeFork(entry, subagentType, messages, parameters, prompt) {
42
- try {
43
- const configuration = await this.subagentManager.findSubagent(subagentType);
44
- if (!configuration) {
45
- throw new Error(`Subagent type ${subagentType} not found`);
46
- }
47
- const instance = await this.subagentManager.createInstance(configuration, {
48
- description: parameters.description,
49
- subagent_type: subagentType,
50
- prompt: "",
51
- allowedTools: parameters.allowedTools,
52
- model: parameters.model,
53
- permissionModeOverride: parameters.permissionModeOverride,
54
- maxTurns: parameters.maxTurns,
55
- }, false);
56
- // Pre-load the message manager with conversation history
57
- instance.messageManager.setMessages(messages);
58
- instance.logStream = entry.logStream;
59
- entry.instance = instance;
60
- // Execute the agent asynchronously
61
- const result = await this.subagentManager.executeAgent(instance, prompt, undefined, false);
62
- // Write final response and completion to log
63
- try {
64
- if (entry.logStream && !entry.logStream.destroyed) {
65
- entry.logStream.write(`[${new Date().toISOString()}] Final response:\n${result}\n`);
66
- entry.logStream.write(`[${new Date().toISOString()}] Agent completed\n`);
67
- entry.logStream.end();
68
- }
69
- }
70
- catch {
71
- // Stream may have been destroyed during cleanup
72
- }
73
- entry.status = "completed";
74
- this.notifyChange();
75
- }
76
- catch (error) {
77
- const errorMessage = error instanceof Error ? error.message : String(error);
78
- try {
79
- if (entry.logStream && !entry.logStream.destroyed) {
80
- entry.logStream.write(`[${new Date().toISOString()}] Agent failed: ${errorMessage}\n`);
81
- entry.logStream.end();
82
- }
83
- }
84
- catch {
85
- // Stream may have been destroyed during cleanup
86
- }
87
- entry.status = "failed";
88
- this.notifyChange();
89
- }
90
- }
91
- /**
92
- * Abort a running forked agent.
93
- */
94
- stop(id) {
95
- const entry = this.activeForks.get(id);
96
- if (!entry) {
97
- return false;
98
- }
99
- entry.instance?.aiManager?.abortAIMessage();
100
- entry.logStream?.destroy();
101
- this.activeForks.delete(id);
102
- this.notifyChange();
103
- return true;
104
- }
105
- /**
106
- * Stop all running forked agents, wait for in-flight executions to settle, and clear the map.
107
- */
108
- async cleanup() {
109
- for (const [, entry] of this.activeForks) {
110
- entry.instance?.aiManager?.abortAIMessage();
111
- // Suppress async write errors from in-flight writes
112
- entry.logStream?.on("error", () => { });
113
- entry.logStream?.destroy();
114
- }
115
- this.activeForks.clear();
116
- this.notifyChange();
117
- // Wait for all in-flight fork executions to settle before returning
118
- await Promise.allSettled(this.inFlightPromises);
119
- this.inFlightPromises.clear();
120
- }
121
- /**
122
- * Returns list of active forked agents.
123
- */
124
- getActiveForks() {
125
- return Array.from(this.activeForks.values());
126
- }
127
- notifyChange() {
128
- this.callbacks.onForkedAgentStatusChange?.(Array.from(this.activeForks.values()));
129
- }
130
- }
@@ -1,111 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { execSync } from "child_process";
4
- import { fileURLToPath } from "url";
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- const MANIFEST_PATH = path.resolve(__dirname, "../bin/rg");
10
- const VENDOR_DIR = path.resolve(__dirname, "../vendor/ripgrep");
11
-
12
- async function main() {
13
- if (!fs.existsSync(MANIFEST_PATH)) {
14
- console.error(`Manifest not found: ${MANIFEST_PATH}`);
15
- process.exit(1);
16
- }
17
-
18
- const manifestContent = fs.readFileSync(MANIFEST_PATH, "utf-8");
19
- const jsonContent = manifestContent.replace(/^#!.*\r?\n/, "");
20
- const manifest = JSON.parse(jsonContent);
21
- const platforms = manifest.platforms;
22
-
23
- if (!fs.existsSync(VENDOR_DIR)) {
24
- fs.mkdirSync(VENDOR_DIR, { recursive: true });
25
- }
26
-
27
- for (const [platform, info] of Object.entries(platforms)) {
28
- const platformDir = path.join(VENDOR_DIR, platform);
29
- const isWindows = platform.startsWith("windows");
30
- const binaryName = isWindows ? "rg.exe" : "rg";
31
- const binaryPath = path.join(platformDir, binaryName);
32
-
33
- if (fs.existsSync(binaryPath)) {
34
- if (!isWindows) {
35
- const stats = fs.statSync(binaryPath);
36
- if ((stats.mode & 0o777) !== 0o755) {
37
- try {
38
- fs.chmodSync(binaryPath, 0o755);
39
- } catch (e) {
40
- console.warn(`Failed to set permissions for ${binaryPath}: ${e}`);
41
- }
42
- }
43
- }
44
- continue;
45
- }
46
-
47
- console.log(`Installing ripgrep for ${platform}...`);
48
- fs.mkdirSync(platformDir, { recursive: true });
49
-
50
- const url = info.providers[0].url;
51
- const tempFile = path.join(platformDir, `download.${info.format}`);
52
-
53
- try {
54
- // Download using curl
55
- console.log(`Downloading ${url}...`);
56
- execSync(`curl -L -o "${tempFile}" "${url}"`, { stdio: "inherit" });
57
-
58
- // Extract
59
- console.log(`Extracting ${tempFile}...`);
60
- if (info.format === "tar.gz") {
61
- // Extract specific file from tar.gz
62
- const extractDir = path.join(platformDir, "extract");
63
- fs.mkdirSync(extractDir, { recursive: true });
64
- execSync(`tar -xzf "${tempFile}" -C "${extractDir}"`, {
65
- stdio: "inherit",
66
- });
67
- const extractedBinary = path.join(extractDir, info.path);
68
- if (fs.existsSync(extractedBinary)) {
69
- fs.renameSync(extractedBinary, binaryPath);
70
- } else {
71
- throw new Error(`Binary not found in archive: ${info.path}`);
72
- }
73
- // Clean up extract dir
74
- fs.rmSync(extractDir, { recursive: true, force: true });
75
- } else if (info.format === "zip") {
76
- const extractDir = path.join(platformDir, "extract");
77
- fs.mkdirSync(extractDir, { recursive: true });
78
- execSync(`unzip -o "${tempFile}" -d "${extractDir}"`, {
79
- stdio: "inherit",
80
- });
81
- const extractedBinary = path.join(extractDir, info.path);
82
- if (fs.existsSync(extractedBinary)) {
83
- fs.renameSync(extractedBinary, binaryPath);
84
- } else {
85
- throw new Error(`Binary not found in archive: ${info.path}`);
86
- }
87
- // Clean up extract dir
88
- fs.rmSync(extractDir, { recursive: true, force: true });
89
- }
90
-
91
- // Make executable
92
- if (!isWindows) {
93
- fs.chmodSync(binaryPath, 0o755);
94
- }
95
-
96
- console.log(`Successfully installed ripgrep for ${platform}`);
97
- } catch (error) {
98
- console.error(`Failed to install ripgrep for ${platform}:`, error);
99
- } finally {
100
- // Clean up temp file
101
- if (fs.existsSync(tempFile)) {
102
- fs.unlinkSync(tempFile);
103
- }
104
- }
105
- }
106
- }
107
-
108
- main().catch((err) => {
109
- console.error(err);
110
- process.exit(1);
111
- });
@@ -1,38 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
- const VENDOR_DIR = path.resolve(__dirname, "../vendor/ripgrep");
9
-
10
- function chmodRecursive(dir) {
11
- if (!fs.existsSync(dir)) return;
12
-
13
- const files = fs.readdirSync(dir);
14
- for (const file of files) {
15
- const fullPath = path.join(dir, file);
16
- const stats = fs.statSync(fullPath);
17
-
18
- if (stats.isDirectory()) {
19
- chmodRecursive(fullPath);
20
- } else if (file === "rg" || file === "rg.exe") {
21
- if (process.platform !== "win32") {
22
- const currentMode = stats.mode & 0o777;
23
- if (currentMode !== 0o755) {
24
- try {
25
- fs.chmodSync(fullPath, 0o755);
26
- console.log(`Set execution permission for ${fullPath}`);
27
- } catch (e) {
28
- console.warn(
29
- `Failed to set execution permission for ${fullPath}: ${e.message}`,
30
- );
31
- }
32
- }
33
- }
34
- }
35
- }
36
- }
37
-
38
- chmodRecursive(VENDOR_DIR);