wave-agent-sdk 0.19.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/builtin/plugins/sdd/scripts/session-start.js +1 -1
  2. package/builtin/plugins/sdd/skills/specify/SKILL.md +3 -4
  3. package/builtin/skills/settings/ENV.md +15 -9
  4. package/builtin/skills/settings/HOOKS.md +27 -2
  5. package/dist/agent.d.ts +9 -20
  6. package/dist/agent.js +28 -99
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/managers/aiManager.d.ts +71 -8
  10. package/dist/managers/aiManager.js +290 -85
  11. package/dist/managers/backgroundTaskManager.d.ts +6 -0
  12. package/dist/managers/backgroundTaskManager.js +11 -0
  13. package/dist/managers/bangManager.d.ts +6 -0
  14. package/dist/managers/bangManager.js +11 -0
  15. package/dist/managers/hookManager.d.ts +8 -2
  16. package/dist/managers/hookManager.js +14 -4
  17. package/dist/managers/mcpManager.d.ts +18 -4
  18. package/dist/managers/mcpManager.js +40 -18
  19. package/dist/managers/messageManager.d.ts +9 -5
  20. package/dist/managers/messageManager.js +36 -12
  21. package/dist/managers/subagentManager.d.ts +6 -0
  22. package/dist/managers/subagentManager.js +33 -22
  23. package/dist/managers/toolManager.js +5 -0
  24. package/dist/prompts/index.d.ts +0 -1
  25. package/dist/prompts/index.js +0 -4
  26. package/dist/services/aiService.d.ts +1 -34
  27. package/dist/services/aiService.js +18 -130
  28. package/dist/services/autoMemoryService.d.ts +27 -2
  29. package/dist/services/autoMemoryService.js +124 -36
  30. package/dist/services/configurationService.d.ts +21 -2
  31. package/dist/services/configurationService.js +86 -24
  32. package/dist/services/initializationService.js +14 -4
  33. package/dist/services/interactionService.js +35 -7
  34. package/dist/services/remoteSettingsService.d.ts +12 -0
  35. package/dist/services/remoteSettingsService.js +15 -1
  36. package/dist/services/session.d.ts +13 -0
  37. package/dist/services/session.js +64 -0
  38. package/dist/services/taskManager.js +7 -1
  39. package/dist/tools/bashTool.js +1 -0
  40. package/dist/tools/enterWorktreeTool.js +14 -3
  41. package/dist/tools/exitWorktreeTool.js +11 -10
  42. package/dist/tools/types.d.ts +7 -0
  43. package/dist/types/agent.d.ts +0 -2
  44. package/dist/types/config.d.ts +9 -0
  45. package/dist/types/core.d.ts +1 -1
  46. package/dist/types/hooks.d.ts +2 -2
  47. package/dist/utils/containerSetup.js +13 -4
  48. package/dist/utils/openaiClient.js +2 -1
  49. package/dist/utils/pathEncoder.js +7 -2
  50. package/dist/utils/worktreeUtils.d.ts +17 -0
  51. package/dist/utils/worktreeUtils.js +339 -1
  52. package/package.json +1 -1
  53. package/src/agent.ts +43 -112
  54. package/src/index.ts +1 -0
  55. package/src/managers/aiManager.ts +389 -110
  56. package/src/managers/backgroundTaskManager.ts +15 -0
  57. package/src/managers/bangManager.ts +15 -0
  58. package/src/managers/hookManager.ts +20 -5
  59. package/src/managers/mcpManager.ts +60 -18
  60. package/src/managers/messageManager.ts +51 -23
  61. package/src/managers/subagentManager.ts +36 -25
  62. package/src/managers/toolManager.ts +7 -0
  63. package/src/prompts/index.ts +0 -4
  64. package/src/services/aiService.ts +25 -203
  65. package/src/services/autoMemoryService.ts +145 -39
  66. package/src/services/configurationService.ts +100 -24
  67. package/src/services/initializationService.ts +17 -4
  68. package/src/services/interactionService.ts +49 -6
  69. package/src/services/remoteSettingsService.ts +16 -1
  70. package/src/services/session.ts +68 -0
  71. package/src/services/taskManager.ts +10 -1
  72. package/src/tools/bashTool.ts +1 -0
  73. package/src/tools/enterWorktreeTool.ts +19 -2
  74. package/src/tools/exitWorktreeTool.ts +15 -12
  75. package/src/tools/types.ts +7 -0
  76. package/src/types/agent.ts +0 -6
  77. package/src/types/config.ts +9 -0
  78. package/src/types/core.ts +1 -1
  79. package/src/types/hooks.ts +2 -2
  80. package/src/utils/containerSetup.ts +15 -5
  81. package/src/utils/openaiClient.ts +2 -0
  82. package/src/utils/pathEncoder.ts +7 -2
  83. package/src/utils/worktreeUtils.ts +401 -1
  84. package/dist/constants/goalPrompts.d.ts +0 -1
  85. package/dist/constants/goalPrompts.js +0 -10
  86. package/dist/managers/goalManager.d.ts +0 -42
  87. package/dist/managers/goalManager.js +0 -177
  88. package/src/constants/goalPrompts.ts +0 -10
  89. package/src/managers/goalManager.ts +0 -232
package/src/agent.ts CHANGED
@@ -8,7 +8,6 @@ import { McpManager } from "./managers/mcpManager.js";
8
8
  import { LspManager } from "./managers/lspManager.js";
9
9
  import { BangManager } from "./managers/bangManager.js";
10
10
  import { CronManager } from "./managers/cronManager.js";
11
- import { GoalManager } from "./managers/goalManager.js";
12
11
  import { BackgroundTaskManager } from "./managers/backgroundTaskManager.js";
13
12
  import { MessageQueue, type QueuedMessage } from "./managers/messageQueue.js";
14
13
  import { SlashCommandManager } from "./managers/slashCommandManager.js";
@@ -38,9 +37,6 @@ import { LiveConfigManager } from "./managers/liveConfigManager.js";
38
37
  import { configValidator } from "./utils/configValidator.js";
39
38
  import { SkillManager } from "./managers/skillManager.js";
40
39
  import { TaskManager } from "./services/taskManager.js";
41
- import { btw } from "./services/aiService.js";
42
- import { convertMessagesForAPI } from "./utils/convertMessagesForAPI.js";
43
- import { supportsVision } from "./utils/modelCapabilities.js";
44
40
  import type { WorktreeSession } from "./utils/worktreeSession.js";
45
41
  import { parseTaskNotificationXml } from "./utils/notificationXml.js";
46
42
  import { InitializationService } from "./services/initializationService.js";
@@ -73,7 +69,6 @@ export class Agent {
73
69
  private pluginManager: PluginManager; // Add plugin manager instance
74
70
  private skillManager: SkillManager; // Add skill manager instance
75
71
  private cronManager: CronManager; // Add cron manager instance
76
- private goalManager: GoalManager; // Add goal manager instance
77
72
  private hookManager: HookManager; // Add hooks manager instance
78
73
  private reversionManager: ReversionManager;
79
74
  private messageQueue: MessageQueue; // Unified queue for messages, bang commands, and notifications
@@ -95,7 +90,10 @@ export class Agent {
95
90
 
96
91
  // Dynamic configuration getter methods
97
92
  public getGatewayConfig(): GatewayConfig {
98
- return this.configurationService.resolveGatewayConfig();
93
+ return {
94
+ ...this.configurationService.resolveGatewayConfig(),
95
+ sessionId: this.messageManager.getSessionId(),
96
+ };
99
97
  }
100
98
 
101
99
  public getModelConfig(): ModelConfig {
@@ -205,7 +203,6 @@ export class Agent {
205
203
  this.pluginManager = this.container.get("PluginManager")!;
206
204
  this.bangManager = this.container.get("BangManager")!;
207
205
  this.cronManager = this.container.get("CronManager")!;
208
- this.goalManager = this.container.get("GoalManager")!;
209
206
  this.messageQueue = this.container.get("MessageQueue")!;
210
207
 
211
208
  // Wire up CWD change callback from AIManager to sync Agent's workdir
@@ -235,16 +232,6 @@ export class Agent {
235
232
  if (options.permissionMode) {
236
233
  this.setPermissionMode(options.permissionMode);
237
234
  }
238
-
239
- // Wire up goal state change callback
240
- this.goalManager.setOnGoalStateChange((active, condition, elapsed) => {
241
- this.options.callbacks?.onGoalStateChange?.(active, condition, elapsed);
242
- });
243
-
244
- // Wire up goal evaluating callback
245
- this.goalManager.setOnGoalEvaluating((evaluating) => {
246
- this.options.callbacks?.onGoalEvaluating?.(evaluating);
247
- });
248
235
  }
249
236
 
250
237
  // Public getter methods
@@ -337,16 +324,6 @@ export class Agent {
337
324
  .filter((m) => m.type !== "notification");
338
325
  }
339
326
 
340
- /** Get goal status string */
341
- public get goalStatus(): string {
342
- return this.goalManager.getStatusString();
343
- }
344
-
345
- /** Check if a goal is active */
346
- public get isGoalActive(): boolean {
347
- return this.goalManager.isGoalActive();
348
- }
349
-
350
327
  /**
351
328
  * Remove a queued message by index
352
329
  * @param index - The index of the message to remove
@@ -706,9 +683,6 @@ export class Agent {
706
683
  public async clearMessages(): Promise<void> {
707
684
  this.aiManager.abortAIMessage();
708
685
 
709
- // Clear any active goal
710
- this.goalManager.clearGoal();
711
-
712
686
  // Capture old session info before clearing
713
687
  const oldSessionId = this.messageManager.getSessionId();
714
688
  const transcriptPath = this.messageManager.getTranscriptPath();
@@ -778,75 +752,6 @@ export class Agent {
778
752
  await this.messageManager.saveSession();
779
753
  }
780
754
 
781
- /**
782
- * Set an autonomous goal for the session
783
- * @param condition - The goal condition to achieve
784
- */
785
- public async setGoal(condition: string): Promise<void> {
786
- // Check plan mode
787
- if (this.getPermissionMode() === "plan") {
788
- this.messageManager.addUserMessage({
789
- content:
790
- "<system-reminder>Cannot set a goal in plan mode. Exit plan mode first.</system-reminder>",
791
- isMeta: true,
792
- });
793
- return;
794
- }
795
-
796
- this.goalManager.setGoal(condition);
797
- this.messageManager.addUserMessage({
798
- content: `<system-reminder>Goal set: ${condition}. The agent will work autonomously until this goal is achieved.</system-reminder>`,
799
- isMeta: true,
800
- });
801
- // Add the goal as a user directive to start working
802
- this.messageManager.addUserMessage({
803
- content: condition,
804
- });
805
- this.aiManager.sendAIMessage();
806
-
807
- await this.messageManager.saveSession();
808
- }
809
-
810
- /**
811
- * Clear the current autonomous goal
812
- */
813
- public async clearGoal(): Promise<void> {
814
- if (this.goalManager.isGoalActive()) {
815
- this.goalManager.clearGoal();
816
- this.messageManager.addUserMessage({
817
- content: "<system-reminder>Goal cleared.</system-reminder>",
818
- isMeta: true,
819
- });
820
- } else {
821
- this.messageManager.addUserMessage({
822
- content: "<system-reminder>No active goal to clear.</system-reminder>",
823
- isMeta: true,
824
- });
825
- }
826
-
827
- await this.messageManager.saveSession();
828
- }
829
-
830
- /**
831
- * Show the current goal status
832
- */
833
- public async showGoalStatus(): Promise<void> {
834
- if (this.goalManager.isGoalActive()) {
835
- this.messageManager.addUserMessage({
836
- content: `<system-reminder>${this.goalManager.getStatusString()}</system-reminder>`,
837
- isMeta: true,
838
- });
839
- } else {
840
- this.messageManager.addUserMessage({
841
- content:
842
- "<system-reminder>No active goal. Use /goal <condition> to set one.</system-reminder>",
843
- isMeta: true,
844
- });
845
- }
846
-
847
- await this.messageManager.saveSession();
848
- }
849
-
850
755
  /** Unified interrupt method, interrupts both AI messages and command execution */
851
756
  public abortMessage(): void {
852
757
  // Guard: prevent tryDispatch (triggered by abortAIMessage → setIsLoading(false))
@@ -924,7 +829,9 @@ export class Agent {
924
829
  cwd: this.workdir,
925
830
  worktreePath,
926
831
  env: Object.fromEntries(
927
- Object.entries(process.env).filter((e) => e[1] !== undefined),
832
+ Object.entries(this.configurationService.getMergedEnv()).filter(
833
+ (e) => e[1] !== undefined,
834
+ ),
928
835
  ) as Record<string, string>,
929
836
  },
930
837
  );
@@ -989,6 +896,21 @@ export class Agent {
989
896
  this.subagentManager.cleanup();
990
897
  // Cleanup forked agent manager
991
898
  await this.forkedAgentManager.cleanup();
899
+ // Drain an in-flight auto-memory extraction fork so the process doesn't
900
+ // exit mid-extraction
901
+ try {
902
+ const autoMemoryService =
903
+ this.container.get<
904
+ import("./services/autoMemoryService.js").AutoMemoryService
905
+ >("AutoMemoryService");
906
+ if (autoMemoryService) {
907
+ await autoMemoryService.drain();
908
+ }
909
+ } catch (error) {
910
+ this.logger?.warn(
911
+ `Auto-memory extraction drain failed: ${(error as Error).message}`,
912
+ );
913
+ }
992
914
  // Cleanup skill manager
993
915
  await this.skillManager.destroy();
994
916
  // Cleanup live configuration reload
@@ -1013,21 +935,30 @@ export class Agent {
1013
935
  }
1014
936
 
1015
937
  /**
1016
- * Ask a side question without tool use
938
+ * Ask a side question without interrupting the main agent.
939
+ *
940
+ * Runs a single-turn fork of the conversation that reuses the main loop's
941
+ * system prompt, tools, and memory injection (prompt-cache friendly) and
942
+ * never executes tools. The abort signal lets the UI cancel a pending
943
+ * question (loading dismiss); aborts propagate as thrown errors.
944
+ *
1017
945
  * @param question - The side question to ask
946
+ * @param abortSignal - Optional signal to abort the pending request
1018
947
  * @returns Promise that resolves to the AI's answer
1019
948
  */
1020
- public async askBtw(question: string): Promise<string> {
1021
- const messages = convertMessagesForAPI(this.messageManager.getMessages(), {
1022
- supportsVision: supportsVision(this.getModelConfig().capabilities),
1023
- });
1024
- const result = await btw({
1025
- gatewayConfig: this.getGatewayConfig(),
1026
- modelConfig: this.getModelConfig(),
1027
- messages,
949
+ public async askBtw(
950
+ question: string,
951
+ abortSignal?: AbortSignal,
952
+ onContent?: (content: string) => void,
953
+ onReasoning?: (content: string) => void,
954
+ ): Promise<string> {
955
+ const result = await this.aiManager.runBtwFork(
1028
956
  question,
1029
- });
1030
- return result.content;
957
+ abortSignal,
958
+ onContent,
959
+ onReasoning,
960
+ );
961
+ return result.content ?? result.error ?? "No response received";
1031
962
  }
1032
963
 
1033
964
  /**
@@ -1061,7 +992,7 @@ export class Agent {
1061
992
  images?: Array<{ path: string; mimeType: string }>,
1062
993
  ): Promise<void> {
1063
994
  // If the agent is busy, enqueue the message — unless it's an immediate
1064
- // slash command (e.g., /goal clear, /clear, /compact) that should execute
995
+ // slash command (e.g., /clear, /compact) that should execute
1065
996
  // right away even while AI is processing
1066
997
  if (this.aiManager.isLoading || this.isCommandRunning) {
1067
998
  const trimmed = content.trim();
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export * from "./utils/tokenCalculation.js";
29
29
  export * from "./utils/gitUtils.js";
30
30
  export * from "./utils/nameGenerator.js";
31
31
  export * from "./utils/worktreeSession.js";
32
+ export * from "./utils/worktreeUtils.js";
32
33
  export { loadMergedWaveConfig } from "./services/configurationService.js";
33
34
  export * from "./types/index.js";
34
35