wave-agent-sdk 0.19.5 → 0.19.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.
- package/dist/agent.d.ts +30 -14
- package/dist/agent.js +70 -56
- package/dist/constants/goalPrompts.d.ts +0 -1
- package/dist/constants/subagents.d.ts +0 -1
- package/dist/constants/toolLimits.d.ts +0 -1
- package/dist/constants/tools.d.ts +0 -1
- package/dist/core/plugin.d.ts +0 -1
- package/dist/core/session.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/managers/MemoryRuleManager.d.ts +0 -1
- package/dist/managers/aiManager.d.ts +15 -2
- package/dist/managers/aiManager.js +65 -11
- package/dist/managers/backgroundTaskManager.d.ts +1 -3
- package/dist/managers/backgroundTaskManager.js +20 -22
- package/dist/managers/bangManager.d.ts +0 -1
- package/dist/managers/bangManager.js +2 -1
- package/dist/managers/cronManager.d.ts +0 -1
- package/dist/managers/foregroundTaskManager.d.ts +0 -1
- package/dist/managers/forkedAgentManager.d.ts +0 -1
- package/dist/managers/goalManager.d.ts +0 -1
- package/dist/managers/hookManager.d.ts +0 -1
- package/dist/managers/liveConfigManager.d.ts +0 -1
- package/dist/managers/lspManager.d.ts +0 -1
- package/dist/managers/mcpManager.d.ts +0 -1
- package/dist/managers/messageManager.d.ts +7 -1
- package/dist/managers/messageManager.js +64 -5
- package/dist/managers/messageQueue.d.ts +25 -2
- package/dist/managers/messageQueue.js +53 -1
- package/dist/managers/permissionManager.d.ts +0 -1
- package/dist/managers/permissionManager.js +3 -3
- package/dist/managers/planManager.d.ts +0 -1
- package/dist/managers/pluginManager.d.ts +0 -1
- package/dist/managers/pluginScopeManager.d.ts +0 -1
- package/dist/managers/reversionManager.d.ts +0 -1
- package/dist/managers/skillManager.d.ts +0 -1
- package/dist/managers/slashCommandManager.d.ts +0 -1
- package/dist/managers/subagentManager.d.ts +0 -3
- package/dist/managers/subagentManager.js +15 -14
- package/dist/managers/toolManager.d.ts +0 -1
- package/dist/managers/workflowManager.d.ts +1 -2
- package/dist/managers/workflowManager.js +4 -4
- package/dist/prompts/autoMemory.d.ts +0 -1
- package/dist/prompts/autoMemoryExtraction.d.ts +0 -1
- package/dist/prompts/index.d.ts +3 -2
- package/dist/prompts/index.js +2 -4
- package/dist/prompts/planModeReminders.d.ts +0 -1
- package/dist/services/GitService.d.ts +0 -1
- package/dist/services/MarketplaceService.d.ts +0 -1
- package/dist/services/MemoryRuleService.d.ts +0 -1
- package/dist/services/aiService.d.ts +0 -1
- package/dist/services/authService.d.ts +0 -1
- package/dist/services/autoMemoryService.d.ts +0 -1
- package/dist/services/configurationService.d.ts +0 -1
- package/dist/services/fileWatcher.d.ts +0 -1
- package/dist/services/hook.d.ts +0 -1
- package/dist/services/hook.js +6 -0
- package/dist/services/initializationService.d.ts +0 -1
- package/dist/services/interactionService.d.ts +0 -1
- package/dist/services/interactionService.js +10 -0
- package/dist/services/jsonlHandler.d.ts +0 -1
- package/dist/services/memory.d.ts +0 -1
- package/dist/services/pluginLoader.d.ts +0 -1
- package/dist/services/remoteSettingsService.d.ts +0 -1
- package/dist/services/reversionService.d.ts +0 -1
- package/dist/services/session.d.ts +0 -1
- package/dist/services/taskManager.d.ts +0 -1
- package/dist/services/taskManager.js +8 -1
- package/dist/telemetry/events.d.ts +0 -1
- package/dist/telemetry/instrumentation.d.ts +0 -1
- package/dist/telemetry/sessionTracing.d.ts +0 -1
- package/dist/tools/agentTool.d.ts +0 -1
- package/dist/tools/askUserQuestion.d.ts +0 -1
- package/dist/tools/bashTool.d.ts +0 -1
- package/dist/tools/bashTool.js +7 -5
- package/dist/tools/buildTool.d.ts +0 -1
- package/dist/tools/cronCreateTool.d.ts +0 -1
- package/dist/tools/cronDeleteTool.d.ts +0 -1
- package/dist/tools/cronListTool.d.ts +0 -1
- package/dist/tools/editTool.d.ts +0 -1
- package/dist/tools/enterPlanMode.d.ts +0 -1
- package/dist/tools/enterWorktreeTool.d.ts +0 -1
- package/dist/tools/enterWorktreeTool.js +3 -8
- package/dist/tools/exitPlanMode.d.ts +0 -1
- package/dist/tools/exitWorktreeTool.d.ts +0 -1
- package/dist/tools/exitWorktreeTool.js +5 -8
- package/dist/tools/globTool.d.ts +0 -1
- package/dist/tools/grepTool.d.ts +0 -1
- package/dist/tools/lspTool.d.ts +0 -1
- package/dist/tools/readTool.d.ts +0 -1
- package/dist/tools/skillTool.d.ts +0 -1
- package/dist/tools/taskManagementTools.d.ts +0 -1
- package/dist/tools/taskStopTool.d.ts +0 -1
- package/dist/tools/types.d.ts +0 -1
- package/dist/tools/webFetchTool.d.ts +0 -1
- package/dist/tools/workflowTool.d.ts +0 -1
- package/dist/tools/writeTool.d.ts +0 -1
- package/dist/types/agent.d.ts +0 -1
- package/dist/types/auth.d.ts +0 -1
- package/dist/types/commands.d.ts +0 -1
- package/dist/types/config.d.ts +0 -1
- package/dist/types/configuration.d.ts +0 -1
- package/dist/types/core.d.ts +0 -1
- package/dist/types/cron.d.ts +0 -1
- package/dist/types/environment.d.ts +0 -1
- package/dist/types/fileSearch.d.ts +0 -1
- package/dist/types/history.d.ts +0 -1
- package/dist/types/hooks.d.ts +2 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/lsp.d.ts +0 -1
- package/dist/types/marketplace.d.ts +0 -1
- package/dist/types/mcp.d.ts +0 -1
- package/dist/types/memoryRule.d.ts +0 -1
- package/dist/types/messaging.d.ts +2 -1
- package/dist/types/permissions.d.ts +0 -1
- package/dist/types/plugins.d.ts +0 -1
- package/dist/types/processes.d.ts +0 -1
- package/dist/types/reversion.d.ts +0 -1
- package/dist/types/session.d.ts +0 -1
- package/dist/types/skills.d.ts +0 -1
- package/dist/types/tasks.d.ts +0 -1
- package/dist/types/telemetry.d.ts +0 -1
- package/dist/types/tools.d.ts +0 -1
- package/dist/types/workflow.d.ts +0 -1
- package/dist/utils/abortUtils.d.ts +0 -1
- package/dist/utils/atomicWrite.d.ts +0 -1
- package/dist/utils/bashParser.d.ts +0 -1
- package/dist/utils/cacheControlUtils.d.ts +0 -1
- package/dist/utils/commandArgumentParser.d.ts +0 -1
- package/dist/utils/commandPathResolver.d.ts +0 -1
- package/dist/utils/configPaths.d.ts +0 -1
- package/dist/utils/configValidator.d.ts +0 -1
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/container.d.ts +0 -1
- package/dist/utils/containerSetup.d.ts +0 -1
- package/dist/utils/containerSetup.js +3 -3
- package/dist/utils/convertMessagesForAPI.d.ts +0 -1
- package/dist/utils/cronTasks.d.ts +0 -1
- package/dist/utils/cronTasksLock.d.ts +0 -1
- package/dist/utils/cronToHuman.d.ts +0 -1
- package/dist/utils/customCommands.d.ts +0 -1
- package/dist/utils/editUtils.d.ts +0 -1
- package/dist/utils/fileFormat.d.ts +0 -1
- package/dist/utils/fileSearch.d.ts +0 -1
- package/dist/utils/fileUtils.d.ts +0 -1
- package/dist/utils/gitUtils.d.ts +0 -1
- package/dist/utils/globalLogger.d.ts +0 -1
- package/dist/utils/groupMessagesByApiRound.d.ts +0 -1
- package/dist/utils/hookMatcher.d.ts +0 -1
- package/dist/utils/markdownParser.d.ts +0 -1
- package/dist/utils/mcpUtils.d.ts +0 -1
- package/dist/utils/messageOperations.d.ts +0 -1
- package/dist/utils/modelCapabilities.d.ts +0 -1
- package/dist/utils/nameGenerator.d.ts +0 -1
- package/dist/utils/notificationXml.d.ts +0 -1
- package/dist/utils/openaiClient.d.ts +0 -1
- package/dist/utils/parseCronExpression.d.ts +0 -1
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/pathEncoder.d.ts +0 -1
- package/dist/utils/pathSafety.d.ts +0 -1
- package/dist/utils/promptHistory.d.ts +0 -1
- package/dist/utils/ripgrep.d.ts +0 -1
- package/dist/utils/shellResolver.d.ts +0 -1
- package/dist/utils/shellResolver.js +156 -7
- package/dist/utils/skillParser.d.ts +0 -1
- package/dist/utils/stringUtils.d.ts +0 -1
- package/dist/utils/subagentParser.d.ts +0 -1
- package/dist/utils/taskReminder.d.ts +0 -1
- package/dist/utils/tokenCalculation.d.ts +0 -1
- package/dist/utils/tokenEstimate.d.ts +0 -1
- package/dist/utils/toolResultStorage.d.ts +0 -1
- package/dist/utils/worktreeSession.d.ts +6 -7
- package/dist/utils/worktreeSession.js +7 -11
- package/dist/utils/worktreeUtils.d.ts +0 -1
- package/dist/workflow/budgetTracker.d.ts +0 -1
- package/dist/workflow/concurrencyLimiter.d.ts +0 -1
- package/dist/workflow/journal.d.ts +0 -1
- package/dist/workflow/progressReporter.d.ts +0 -1
- package/dist/workflow/runState.d.ts +0 -1
- package/dist/workflow/scriptRuntime.d.ts +0 -1
- package/dist/workflow/structuredOutput.d.ts +0 -1
- package/dist/workflow/types.d.ts +0 -1
- package/dist/workflow/workflowApis.d.ts +0 -1
- package/package.json +1 -1
- package/src/agent.ts +80 -67
- package/src/managers/aiManager.ts +79 -12
- package/src/managers/backgroundTaskManager.ts +21 -23
- package/src/managers/bangManager.ts +2 -1
- package/src/managers/messageManager.ts +72 -6
- package/src/managers/messageQueue.ts +60 -2
- package/src/managers/permissionManager.ts +6 -3
- package/src/managers/subagentManager.ts +22 -16
- package/src/managers/workflowManager.ts +5 -5
- package/src/prompts/index.ts +4 -4
- package/src/services/hook.ts +9 -0
- package/src/services/interactionService.ts +11 -0
- package/src/services/taskManager.ts +8 -1
- package/src/tools/bashTool.ts +11 -5
- package/src/tools/enterWorktreeTool.ts +4 -14
- package/src/tools/exitWorktreeTool.ts +5 -13
- package/src/types/hooks.ts +2 -0
- package/src/types/messaging.ts +2 -0
- package/src/utils/containerSetup.ts +3 -3
- package/src/utils/shellResolver.ts +167 -8
- package/src/utils/worktreeSession.ts +6 -16
- package/dist/agent.d.ts.map +0 -1
- package/dist/constants/goalPrompts.d.ts.map +0 -1
- package/dist/constants/subagents.d.ts.map +0 -1
- package/dist/constants/toolLimits.d.ts.map +0 -1
- package/dist/constants/tools.d.ts.map +0 -1
- package/dist/core/plugin.d.ts.map +0 -1
- package/dist/core/session.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/managers/MemoryRuleManager.d.ts.map +0 -1
- package/dist/managers/aiManager.d.ts.map +0 -1
- package/dist/managers/backgroundTaskManager.d.ts.map +0 -1
- package/dist/managers/bangManager.d.ts.map +0 -1
- package/dist/managers/cronManager.d.ts.map +0 -1
- package/dist/managers/foregroundTaskManager.d.ts.map +0 -1
- package/dist/managers/forkedAgentManager.d.ts.map +0 -1
- package/dist/managers/goalManager.d.ts.map +0 -1
- package/dist/managers/hookManager.d.ts.map +0 -1
- package/dist/managers/liveConfigManager.d.ts.map +0 -1
- package/dist/managers/lspManager.d.ts.map +0 -1
- package/dist/managers/mcpManager.d.ts.map +0 -1
- package/dist/managers/messageManager.d.ts.map +0 -1
- package/dist/managers/messageQueue.d.ts.map +0 -1
- package/dist/managers/notificationQueue.d.ts +0 -8
- package/dist/managers/notificationQueue.d.ts.map +0 -1
- package/dist/managers/notificationQueue.js +0 -17
- package/dist/managers/permissionManager.d.ts.map +0 -1
- package/dist/managers/planManager.d.ts.map +0 -1
- package/dist/managers/pluginManager.d.ts.map +0 -1
- package/dist/managers/pluginScopeManager.d.ts.map +0 -1
- package/dist/managers/reversionManager.d.ts.map +0 -1
- package/dist/managers/skillManager.d.ts.map +0 -1
- package/dist/managers/slashCommandManager.d.ts.map +0 -1
- package/dist/managers/subagentManager.d.ts.map +0 -1
- package/dist/managers/toolManager.d.ts.map +0 -1
- package/dist/managers/workflowManager.d.ts.map +0 -1
- package/dist/prompts/autoMemory.d.ts.map +0 -1
- package/dist/prompts/autoMemoryExtraction.d.ts.map +0 -1
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/planModeReminders.d.ts.map +0 -1
- package/dist/services/GitService.d.ts.map +0 -1
- package/dist/services/MarketplaceService.d.ts.map +0 -1
- package/dist/services/MemoryRuleService.d.ts.map +0 -1
- package/dist/services/aiService.d.ts.map +0 -1
- package/dist/services/authService.d.ts.map +0 -1
- package/dist/services/autoMemoryService.d.ts.map +0 -1
- package/dist/services/configurationService.d.ts.map +0 -1
- package/dist/services/fileWatcher.d.ts.map +0 -1
- package/dist/services/hook.d.ts.map +0 -1
- package/dist/services/initializationService.d.ts.map +0 -1
- package/dist/services/interactionService.d.ts.map +0 -1
- package/dist/services/jsonlHandler.d.ts.map +0 -1
- package/dist/services/memory.d.ts.map +0 -1
- package/dist/services/pluginLoader.d.ts.map +0 -1
- package/dist/services/remoteSettingsService.d.ts.map +0 -1
- package/dist/services/reversionService.d.ts.map +0 -1
- package/dist/services/session.d.ts.map +0 -1
- package/dist/services/taskManager.d.ts.map +0 -1
- package/dist/telemetry/events.d.ts.map +0 -1
- package/dist/telemetry/instrumentation.d.ts.map +0 -1
- package/dist/telemetry/sessionTracing.d.ts.map +0 -1
- package/dist/tools/agentTool.d.ts.map +0 -1
- package/dist/tools/askUserQuestion.d.ts.map +0 -1
- package/dist/tools/bashTool.d.ts.map +0 -1
- package/dist/tools/buildTool.d.ts.map +0 -1
- package/dist/tools/cronCreateTool.d.ts.map +0 -1
- package/dist/tools/cronDeleteTool.d.ts.map +0 -1
- package/dist/tools/cronListTool.d.ts.map +0 -1
- package/dist/tools/editTool.d.ts.map +0 -1
- package/dist/tools/enterPlanMode.d.ts.map +0 -1
- package/dist/tools/enterWorktreeTool.d.ts.map +0 -1
- package/dist/tools/exitPlanMode.d.ts.map +0 -1
- package/dist/tools/exitWorktreeTool.d.ts.map +0 -1
- package/dist/tools/globTool.d.ts.map +0 -1
- package/dist/tools/grepTool.d.ts.map +0 -1
- package/dist/tools/lspTool.d.ts.map +0 -1
- package/dist/tools/readTool.d.ts.map +0 -1
- package/dist/tools/skillTool.d.ts.map +0 -1
- package/dist/tools/taskManagementTools.d.ts.map +0 -1
- package/dist/tools/taskStopTool.d.ts.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/webFetchTool.d.ts.map +0 -1
- package/dist/tools/workflowTool.d.ts.map +0 -1
- package/dist/tools/writeTool.d.ts.map +0 -1
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/auth.d.ts.map +0 -1
- package/dist/types/commands.d.ts.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/configuration.d.ts.map +0 -1
- package/dist/types/core.d.ts.map +0 -1
- package/dist/types/cron.d.ts.map +0 -1
- package/dist/types/environment.d.ts.map +0 -1
- package/dist/types/fileSearch.d.ts.map +0 -1
- package/dist/types/history.d.ts.map +0 -1
- package/dist/types/hooks.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/lsp.d.ts.map +0 -1
- package/dist/types/marketplace.d.ts.map +0 -1
- package/dist/types/mcp.d.ts.map +0 -1
- package/dist/types/memoryRule.d.ts.map +0 -1
- package/dist/types/messaging.d.ts.map +0 -1
- package/dist/types/permissions.d.ts.map +0 -1
- package/dist/types/plugins.d.ts.map +0 -1
- package/dist/types/processes.d.ts.map +0 -1
- package/dist/types/reversion.d.ts.map +0 -1
- package/dist/types/session.d.ts.map +0 -1
- package/dist/types/skills.d.ts.map +0 -1
- package/dist/types/tasks.d.ts.map +0 -1
- package/dist/types/telemetry.d.ts.map +0 -1
- package/dist/types/tools.d.ts.map +0 -1
- package/dist/types/workflow.d.ts.map +0 -1
- package/dist/utils/abortUtils.d.ts.map +0 -1
- package/dist/utils/atomicWrite.d.ts.map +0 -1
- package/dist/utils/bashParser.d.ts.map +0 -1
- package/dist/utils/cacheControlUtils.d.ts.map +0 -1
- package/dist/utils/commandArgumentParser.d.ts.map +0 -1
- package/dist/utils/commandPathResolver.d.ts.map +0 -1
- package/dist/utils/configPaths.d.ts.map +0 -1
- package/dist/utils/configValidator.d.ts.map +0 -1
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/container.d.ts.map +0 -1
- package/dist/utils/containerSetup.d.ts.map +0 -1
- package/dist/utils/convertMessagesForAPI.d.ts.map +0 -1
- package/dist/utils/cronTasks.d.ts.map +0 -1
- package/dist/utils/cronTasksLock.d.ts.map +0 -1
- package/dist/utils/cronToHuman.d.ts.map +0 -1
- package/dist/utils/customCommands.d.ts.map +0 -1
- package/dist/utils/editUtils.d.ts.map +0 -1
- package/dist/utils/fileFormat.d.ts.map +0 -1
- package/dist/utils/fileSearch.d.ts.map +0 -1
- package/dist/utils/fileUtils.d.ts.map +0 -1
- package/dist/utils/gitUtils.d.ts.map +0 -1
- package/dist/utils/globalLogger.d.ts.map +0 -1
- package/dist/utils/groupMessagesByApiRound.d.ts.map +0 -1
- package/dist/utils/hookMatcher.d.ts.map +0 -1
- package/dist/utils/markdownParser.d.ts.map +0 -1
- package/dist/utils/mcpUtils.d.ts.map +0 -1
- package/dist/utils/messageOperations.d.ts.map +0 -1
- package/dist/utils/modelCapabilities.d.ts.map +0 -1
- package/dist/utils/nameGenerator.d.ts.map +0 -1
- package/dist/utils/notificationXml.d.ts.map +0 -1
- package/dist/utils/openaiClient.d.ts.map +0 -1
- package/dist/utils/parseCronExpression.d.ts.map +0 -1
- package/dist/utils/path.d.ts.map +0 -1
- package/dist/utils/pathEncoder.d.ts.map +0 -1
- package/dist/utils/pathSafety.d.ts.map +0 -1
- package/dist/utils/promptHistory.d.ts.map +0 -1
- package/dist/utils/ripgrep.d.ts.map +0 -1
- package/dist/utils/shellResolver.d.ts.map +0 -1
- package/dist/utils/skillParser.d.ts.map +0 -1
- package/dist/utils/stringUtils.d.ts.map +0 -1
- package/dist/utils/subagentParser.d.ts.map +0 -1
- package/dist/utils/taskReminder.d.ts.map +0 -1
- package/dist/utils/tokenCalculation.d.ts.map +0 -1
- package/dist/utils/tokenEstimate.d.ts.map +0 -1
- package/dist/utils/toolResultStorage.d.ts.map +0 -1
- package/dist/utils/worktreeSession.d.ts.map +0 -1
- package/dist/utils/worktreeUtils.d.ts.map +0 -1
- package/dist/workflow/budgetTracker.d.ts.map +0 -1
- package/dist/workflow/concurrencyLimiter.d.ts.map +0 -1
- package/dist/workflow/journal.d.ts.map +0 -1
- package/dist/workflow/progressReporter.d.ts.map +0 -1
- package/dist/workflow/runState.d.ts.map +0 -1
- package/dist/workflow/scriptRuntime.d.ts.map +0 -1
- package/dist/workflow/structuredOutput.d.ts.map +0 -1
- package/dist/workflow/types.d.ts.map +0 -1
- package/dist/workflow/workflowApis.d.ts.map +0 -1
- package/src/managers/notificationQueue.ts +0 -19
package/dist/workflow/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/agent.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { BangManager } from "./managers/bangManager.js";
|
|
|
10
10
|
import { CronManager } from "./managers/cronManager.js";
|
|
11
11
|
import { GoalManager } from "./managers/goalManager.js";
|
|
12
12
|
import { BackgroundTaskManager } from "./managers/backgroundTaskManager.js";
|
|
13
|
-
import { NotificationQueue } from "./managers/notificationQueue.js";
|
|
14
13
|
import { MessageQueue, type QueuedMessage } from "./managers/messageQueue.js";
|
|
15
14
|
import { SlashCommandManager } from "./managers/slashCommandManager.js";
|
|
16
15
|
import { PluginManager } from "./managers/pluginManager.js";
|
|
@@ -42,6 +41,7 @@ import { TaskManager } from "./services/taskManager.js";
|
|
|
42
41
|
import { btw } from "./services/aiService.js";
|
|
43
42
|
import { convertMessagesForAPI } from "./utils/convertMessagesForAPI.js";
|
|
44
43
|
import { supportsVision } from "./utils/modelCapabilities.js";
|
|
44
|
+
import type { WorktreeSession } from "./utils/worktreeSession.js";
|
|
45
45
|
import { parseTaskNotificationXml } from "./utils/notificationXml.js";
|
|
46
46
|
import { InitializationService } from "./services/initializationService.js";
|
|
47
47
|
import { InteractionService } from "./services/interactionService.js";
|
|
@@ -76,9 +76,8 @@ export class Agent {
|
|
|
76
76
|
private goalManager: GoalManager; // Add goal manager instance
|
|
77
77
|
private hookManager: HookManager; // Add hooks manager instance
|
|
78
78
|
private reversionManager: ReversionManager;
|
|
79
|
-
private
|
|
80
|
-
private
|
|
81
|
-
private pendingNotificationPromises: Promise<void>[] = []; // Track pending notification processing
|
|
79
|
+
private messageQueue: MessageQueue; // Unified queue for messages, bang commands, and notifications
|
|
80
|
+
private dispatchPromise: Promise<void> | null = null; // Track current dispatch for teardown
|
|
82
81
|
private memoryRuleManager: MemoryRuleManager; // Add memory rule manager instance
|
|
83
82
|
private liveConfigManager: LiveConfigManager; // Add live configuration manager
|
|
84
83
|
private taskManager: TaskManager;
|
|
@@ -206,25 +205,8 @@ export class Agent {
|
|
|
206
205
|
this.bangManager = this.container.get("BangManager")!;
|
|
207
206
|
this.cronManager = this.container.get("CronManager")!;
|
|
208
207
|
this.goalManager = this.container.get("GoalManager")!;
|
|
209
|
-
this.notificationQueue = this.container.get("NotificationQueue")!;
|
|
210
208
|
this.messageQueue = this.container.get("MessageQueue")!;
|
|
211
209
|
|
|
212
|
-
// Wire up notification queue to trigger AI when notifications arrive while idle
|
|
213
|
-
this.notificationQueue.onNotificationsEnqueued = () => {
|
|
214
|
-
// If the AI is NOT loading (idle), trigger a new AI cycle to process notifications
|
|
215
|
-
if (!this.aiManager.isLoading) {
|
|
216
|
-
const pendingPromise = this.processPendingNotifications().catch(
|
|
217
|
-
(error) => {
|
|
218
|
-
this.logger?.error(
|
|
219
|
-
"Failed to process pending notifications:",
|
|
220
|
-
error,
|
|
221
|
-
);
|
|
222
|
-
},
|
|
223
|
-
);
|
|
224
|
-
this.pendingNotificationPromises.push(pendingPromise);
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
210
|
// Wire up CWD change callback from AIManager to sync Agent's workdir
|
|
229
211
|
this.aiManager.setOnCwdChange((newCwd) => {
|
|
230
212
|
this.workdir = newCwd;
|
|
@@ -232,18 +214,20 @@ export class Agent {
|
|
|
232
214
|
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
233
215
|
});
|
|
234
216
|
|
|
235
|
-
// Wire up message queue to process when agent becomes idle
|
|
236
|
-
|
|
217
|
+
// Wire up message queue to process when agent becomes idle.
|
|
218
|
+
// Both user messages and background task notifications enqueue here,
|
|
219
|
+
// unified through a single dispatch path (tryDispatch).
|
|
220
|
+
this.messageQueue.onMessageEnqueued = () => this.tryDispatch();
|
|
237
221
|
|
|
238
222
|
// Wire up AI loading changes to process queue when AI becomes idle
|
|
239
223
|
this.aiManager.onLoadingChange = (loading: boolean) => {
|
|
240
|
-
if (!loading) this.
|
|
224
|
+
if (!loading) this.tryDispatch();
|
|
241
225
|
};
|
|
242
226
|
|
|
243
227
|
// Wire up bang manager callback for command running changes
|
|
244
228
|
this.bangManager.onCommandRunningChange = (running: boolean) => {
|
|
245
229
|
this.options.callbacks?.onCommandRunningChange?.(running);
|
|
246
|
-
if (!running) this.
|
|
230
|
+
if (!running) this.tryDispatch();
|
|
247
231
|
};
|
|
248
232
|
|
|
249
233
|
// Set initial permission mode if provided
|
|
@@ -298,6 +282,15 @@ export class Agent {
|
|
|
298
282
|
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
299
283
|
}
|
|
300
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Set this session's worktree session state (used by CLI -w startup to inject the
|
|
287
|
+
* session created before the agent existed). Delegates to AIManager so the state is
|
|
288
|
+
* stored in this agent's own DI container.
|
|
289
|
+
*/
|
|
290
|
+
public setWorktreeSession(session: WorktreeSession | null): void {
|
|
291
|
+
this.aiManager.setWorktreeSession(session);
|
|
292
|
+
}
|
|
293
|
+
|
|
301
294
|
/** Get project memory content */
|
|
302
295
|
public get projectMemory(): string {
|
|
303
296
|
const memoryService =
|
|
@@ -336,9 +329,11 @@ export class Agent {
|
|
|
336
329
|
return this.bangManager?.isCommandRunning ?? false;
|
|
337
330
|
}
|
|
338
331
|
|
|
339
|
-
/** Get queued messages */
|
|
332
|
+
/** Get queued user-facing messages (excludes background notifications) */
|
|
340
333
|
public get queuedMessages(): QueuedMessage[] {
|
|
341
|
-
return this.messageQueue
|
|
334
|
+
return this.messageQueue
|
|
335
|
+
.getQueue()
|
|
336
|
+
.filter((m) => m.type !== "notification");
|
|
342
337
|
}
|
|
343
338
|
|
|
344
339
|
/** Get goal status string */
|
|
@@ -390,28 +385,52 @@ export class Agent {
|
|
|
390
385
|
}
|
|
391
386
|
|
|
392
387
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
388
|
+
* Update a queued message's content by its ID (does not change queue order)
|
|
389
|
+
* @param id - The ID of the message to update
|
|
390
|
+
* @param patch - The fields to update
|
|
391
|
+
* @returns true if the message was updated, false if not found
|
|
392
|
+
*/
|
|
393
|
+
public updateQueuedMessageById(
|
|
394
|
+
id: string,
|
|
395
|
+
patch: {
|
|
396
|
+
content?: string;
|
|
397
|
+
images?: Array<{ path: string; mimeType: string }>;
|
|
398
|
+
type?: "message" | "bang";
|
|
399
|
+
},
|
|
400
|
+
): boolean {
|
|
401
|
+
const updated = this.messageQueue.updateById(id, patch);
|
|
402
|
+
if (updated) {
|
|
403
|
+
this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
|
|
404
|
+
}
|
|
405
|
+
return updated;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Unified dispatch trigger — checks state machine before processing.
|
|
410
|
+
* Handles user messages, bang commands, and background task notifications
|
|
411
|
+
* through a single serialized path. Called from onMessageEnqueued,
|
|
412
|
+
* onLoadingChange(false), and onCommandRunningChange(false).
|
|
396
413
|
*/
|
|
397
|
-
private
|
|
414
|
+
private tryDispatch(): void {
|
|
398
415
|
if (this.messageQueue.state !== "idle") return;
|
|
399
416
|
if (!this.messageQueue.hasPending()) return;
|
|
400
417
|
if (this.aiManager.isLoading || this.isCommandRunning) return;
|
|
401
418
|
|
|
402
419
|
this.messageQueue.transitionTo("dispatching");
|
|
403
|
-
this.processQueuedMessage()
|
|
420
|
+
this.dispatchPromise = this.processQueuedMessage()
|
|
404
421
|
.catch((error) => {
|
|
405
422
|
this.logger?.error("Failed to process queued message:", error);
|
|
406
423
|
})
|
|
407
424
|
.finally(() => {
|
|
408
425
|
this.messageQueue.transitionTo("idle");
|
|
409
|
-
this.
|
|
426
|
+
this.dispatchPromise = null;
|
|
427
|
+
this.tryDispatch(); // Re-check after processing
|
|
410
428
|
});
|
|
411
429
|
}
|
|
412
430
|
|
|
413
431
|
/**
|
|
414
|
-
* Process the next queued
|
|
432
|
+
* Process the next queued item when the agent becomes idle.
|
|
433
|
+
* Handles three item types: user messages, bang commands, and notifications.
|
|
415
434
|
*/
|
|
416
435
|
private async processQueuedMessage(): Promise<void> {
|
|
417
436
|
const next = this.messageQueue.dequeue();
|
|
@@ -423,6 +442,25 @@ export class Agent {
|
|
|
423
442
|
if (next.type === "bang") {
|
|
424
443
|
await this.bangManager?.executeCommand(next.content);
|
|
425
444
|
await this.messageManager.saveSession();
|
|
445
|
+
} else if (next.type === "notification") {
|
|
446
|
+
// Drain all pending notifications and batch them into a single AI turn
|
|
447
|
+
const allNotifications = [
|
|
448
|
+
next.content,
|
|
449
|
+
...this.messageQueue.drainNotifications(),
|
|
450
|
+
];
|
|
451
|
+
for (const xml of allNotifications) {
|
|
452
|
+
const block = parseTaskNotificationXml(xml);
|
|
453
|
+
if (block) {
|
|
454
|
+
this.messageManager.addNotificationMessage({
|
|
455
|
+
taskId: block.taskId,
|
|
456
|
+
taskType: block.taskType,
|
|
457
|
+
status: block.status,
|
|
458
|
+
summary: block.summary,
|
|
459
|
+
outputFile: block.outputFile,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
await this.aiManager.sendAIMessage({ recursionDepth: 0 });
|
|
426
464
|
} else {
|
|
427
465
|
await this.sendMessage(next.content, next.images);
|
|
428
466
|
}
|
|
@@ -650,31 +688,6 @@ export class Agent {
|
|
|
650
688
|
this.aiManager.abortAIMessage();
|
|
651
689
|
}
|
|
652
690
|
|
|
653
|
-
/**
|
|
654
|
-
* Process pending background task notifications by injecting them as user messages
|
|
655
|
-
* and triggering a new AI response cycle.
|
|
656
|
-
*/
|
|
657
|
-
private async processPendingNotifications(): Promise<void> {
|
|
658
|
-
const notifications = this.notificationQueue.dequeueAll();
|
|
659
|
-
if (notifications.length === 0) return;
|
|
660
|
-
|
|
661
|
-
for (const notification of notifications) {
|
|
662
|
-
const block = parseTaskNotificationXml(notification);
|
|
663
|
-
if (block) {
|
|
664
|
-
this.messageManager.addNotificationMessage({
|
|
665
|
-
taskId: block.taskId,
|
|
666
|
-
taskType: block.taskType,
|
|
667
|
-
status: block.status,
|
|
668
|
-
summary: block.summary,
|
|
669
|
-
outputFile: block.outputFile,
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// Trigger AI to process the notifications
|
|
675
|
-
await this.aiManager.sendAIMessage({ recursionDepth: 0 });
|
|
676
|
-
}
|
|
677
|
-
|
|
678
691
|
/** Execute bash command (bang command) */
|
|
679
692
|
public async bang(command: string): Promise<void> {
|
|
680
693
|
// If the agent is busy, enqueue the bang command
|
|
@@ -835,8 +848,9 @@ export class Agent {
|
|
|
835
848
|
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
836
849
|
public abortMessage(): void {
|
|
837
850
|
if (this.aiManager.isLoading || this.isCommandRunning) {
|
|
838
|
-
// Clear queue first to prevent processQueuedMessage
|
|
839
|
-
// when abortAIMessage triggers onLoadingChange(false)
|
|
851
|
+
// Clear user-facing queue items first to prevent processQueuedMessage
|
|
852
|
+
// from dequeuing when abortAIMessage triggers onLoadingChange(false).
|
|
853
|
+
// Notifications are preserved so background task results aren't lost.
|
|
840
854
|
this.messageQueue.clear();
|
|
841
855
|
this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
|
|
842
856
|
}
|
|
@@ -926,15 +940,14 @@ export class Agent {
|
|
|
926
940
|
}).catch(() => {});
|
|
927
941
|
await shutdownTelemetry();
|
|
928
942
|
|
|
929
|
-
// Clear
|
|
943
|
+
// Clear message queue callback first to prevent any late triggers from
|
|
930
944
|
// starting async work during teardown
|
|
931
|
-
this.
|
|
945
|
+
this.messageQueue.onMessageEnqueued = undefined;
|
|
932
946
|
|
|
933
|
-
// Await any pending
|
|
947
|
+
// Await any pending dispatch to prevent race conditions
|
|
934
948
|
// with test teardown (e.g., V8 coverage stream cleanup)
|
|
935
|
-
if (this.
|
|
936
|
-
await
|
|
937
|
-
this.pendingNotificationPromises = [];
|
|
949
|
+
if (this.dispatchPromise) {
|
|
950
|
+
await this.dispatchPromise.catch(() => {});
|
|
938
951
|
}
|
|
939
952
|
|
|
940
953
|
// Fire SessionEnd hooks (fire-and-forget, don't block shutdown)
|
|
@@ -38,9 +38,10 @@ import {
|
|
|
38
38
|
buildExitedPlanModeReminder,
|
|
39
39
|
} from "../prompts/planModeReminders.js";
|
|
40
40
|
import { Container } from "../utils/container.js";
|
|
41
|
+
import type { WorktreeSession } from "../utils/worktreeSession.js";
|
|
41
42
|
import { recoverTruncatedJson } from "../utils/stringUtils.js";
|
|
42
43
|
import { ConfigurationService } from "../services/configurationService.js";
|
|
43
|
-
import type {
|
|
44
|
+
import type { MessageQueue } from "./messageQueue.js";
|
|
44
45
|
|
|
45
46
|
import { logger } from "../utils/globalLogger.js";
|
|
46
47
|
import {
|
|
@@ -114,6 +115,7 @@ export interface AIManagerOptions {
|
|
|
114
115
|
|
|
115
116
|
export class AIManager {
|
|
116
117
|
public isLoading: boolean = false;
|
|
118
|
+
private turnGeneration = 0; // Guards against concurrent sendAIMessage turns
|
|
117
119
|
private abortController: AbortController | null = null;
|
|
118
120
|
onLoadingChange?: (loading: boolean) => void;
|
|
119
121
|
private toolAbortController: AbortController | null = null;
|
|
@@ -260,11 +262,31 @@ export class AIManager {
|
|
|
260
262
|
|
|
261
263
|
/**
|
|
262
264
|
* Update the working directory mid-session (e.g., when entering/exiting a worktree).
|
|
263
|
-
*
|
|
265
|
+
* Only updates this session's DI container; it does NOT change the process-level
|
|
266
|
+
* process.cwd(), so concurrent sessions in the same stdio process are unaffected.
|
|
267
|
+
* Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is
|
|
268
|
+
* notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged
|
|
269
|
+
* hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks).
|
|
264
270
|
*/
|
|
265
271
|
public setWorkdir(newWorkdir: string): void {
|
|
266
272
|
this.container.register("Workdir", newWorkdir);
|
|
267
|
-
|
|
273
|
+
this._onCwdChange?.(newWorkdir);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Get this session's worktree session state (null if not in a worktree).
|
|
278
|
+
*/
|
|
279
|
+
public getWorktreeSession(): WorktreeSession | null {
|
|
280
|
+
return (
|
|
281
|
+
this.container.get<WorktreeSession | null>("WorktreeSession") ?? null
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Set this session's worktree session state.
|
|
287
|
+
*/
|
|
288
|
+
public setWorktreeSession(session: WorktreeSession | null): void {
|
|
289
|
+
this.container.register("WorktreeSession", session);
|
|
268
290
|
}
|
|
269
291
|
|
|
270
292
|
public setOnCwdChange(callback: (newCwd: string) => void): void {
|
|
@@ -376,6 +398,10 @@ export class AIManager {
|
|
|
376
398
|
}
|
|
377
399
|
|
|
378
400
|
public abortAIMessage(): void {
|
|
401
|
+
// Bump generation so the in-flight turn's end-of-turn setIsLoading(false)
|
|
402
|
+
// is skipped (generation mismatch), preventing it from racing with this abort.
|
|
403
|
+
this.turnGeneration++;
|
|
404
|
+
|
|
379
405
|
// Interrupt AI service
|
|
380
406
|
if (this.abortController) {
|
|
381
407
|
try {
|
|
@@ -797,6 +823,15 @@ export class AIManager {
|
|
|
797
823
|
const { recursionDepth = 0, model, allowedRules, maxTokens } = options;
|
|
798
824
|
let turnOffset = recursionDepth;
|
|
799
825
|
|
|
826
|
+
// Reserve this turn synchronously before any async work. Bumping the
|
|
827
|
+
// generation invalidates any in-flight turn's end-of-turn cleanup, and
|
|
828
|
+
// recording myGeneration lets us skip cleanup if a newer turn (or abort)
|
|
829
|
+
// has superseded us. setIsLoading(true) here also closes the "idle but
|
|
830
|
+
// previous turn not finished" race window by marking us busy immediately.
|
|
831
|
+
this.turnGeneration++;
|
|
832
|
+
const myGeneration = this.turnGeneration;
|
|
833
|
+
this.setIsLoading(true);
|
|
834
|
+
|
|
800
835
|
outer: while (true) {
|
|
801
836
|
let shouldRestart = false;
|
|
802
837
|
|
|
@@ -818,9 +853,8 @@ export class AIManager {
|
|
|
818
853
|
}).catch(() => {}); // Non-blocking
|
|
819
854
|
}
|
|
820
855
|
|
|
821
|
-
//
|
|
856
|
+
// Apply allowed rules for the initial call
|
|
822
857
|
if (turnOffset === 0) {
|
|
823
|
-
this.setIsLoading(true);
|
|
824
858
|
if (allowedRules && allowedRules.length > 0) {
|
|
825
859
|
this.permissionManager?.addTemporaryRules(allowedRules);
|
|
826
860
|
}
|
|
@@ -942,6 +976,7 @@ export class AIManager {
|
|
|
942
976
|
originalWorkdir: this.getOriginalWorkdir(),
|
|
943
977
|
language: this.getLanguage(),
|
|
944
978
|
isSubagent: !!this.subagentType,
|
|
979
|
+
worktreeSession: this.getWorktreeSession(),
|
|
945
980
|
autoMemory: autoMemoryOptions,
|
|
946
981
|
},
|
|
947
982
|
), // Pass custom system prompt
|
|
@@ -1326,6 +1361,16 @@ export class AIManager {
|
|
|
1326
1361
|
message: error instanceof Error ? error.message : String(error),
|
|
1327
1362
|
}).catch(() => {}); // Non-blocking
|
|
1328
1363
|
|
|
1364
|
+
// Finalize any streaming text/reasoning blocks so the UI stops ticking
|
|
1365
|
+
// its in-progress timer (e.g. when the request is aborted mid-thought).
|
|
1366
|
+
this.messageManager.finalizeStreamingBlocks();
|
|
1367
|
+
|
|
1368
|
+
// Finalize any tool blocks stuck in start/streaming/running so the UI
|
|
1369
|
+
// stops showing the yellow "running" spinner (e.g. abort mid-tool-stream).
|
|
1370
|
+
this.messageManager.finalizeAbortedToolBlocks(
|
|
1371
|
+
error instanceof Error ? error.message : undefined,
|
|
1372
|
+
);
|
|
1373
|
+
|
|
1329
1374
|
this.messageManager.addErrorBlock(
|
|
1330
1375
|
error instanceof Error ? error.message : "Unknown error occurred",
|
|
1331
1376
|
);
|
|
@@ -1343,8 +1388,6 @@ export class AIManager {
|
|
|
1343
1388
|
|
|
1344
1389
|
// Save session in each iteration to ensure message persistence
|
|
1345
1390
|
await this.messageManager.saveSession();
|
|
1346
|
-
// Set loading to false first
|
|
1347
|
-
this.setIsLoading(false);
|
|
1348
1391
|
|
|
1349
1392
|
// Clear temporary rules
|
|
1350
1393
|
this.permissionManager?.clearTemporaryRules();
|
|
@@ -1443,11 +1486,11 @@ export class AIManager {
|
|
|
1443
1486
|
|
|
1444
1487
|
// Inject pending notifications from background tasks (after Stop hooks,
|
|
1445
1488
|
// aligned with Claude Code which fires Stop hooks unconditionally)
|
|
1446
|
-
const
|
|
1447
|
-
? this.container.get<
|
|
1489
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
1490
|
+
? this.container.get<MessageQueue>("MessageQueue")
|
|
1448
1491
|
: undefined;
|
|
1449
|
-
if (
|
|
1450
|
-
const notifications =
|
|
1492
|
+
if (messageQueue && messageQueue.hasNotifications()) {
|
|
1493
|
+
const notifications = messageQueue.drainNotifications();
|
|
1451
1494
|
for (const notification of notifications) {
|
|
1452
1495
|
const block = parseTaskNotificationXml(notification);
|
|
1453
1496
|
if (block) {
|
|
@@ -1466,7 +1509,16 @@ export class AIManager {
|
|
|
1466
1509
|
}
|
|
1467
1510
|
}
|
|
1468
1511
|
|
|
1469
|
-
if (!shouldRestart)
|
|
1512
|
+
if (!shouldRestart) {
|
|
1513
|
+
// Release loading state only after ALL cleanup is done (session save,
|
|
1514
|
+
// Stop hooks, notification injection). Generation check ensures a
|
|
1515
|
+
// superseded (aborted or newer) turn doesn't clobber the current
|
|
1516
|
+
// loading state.
|
|
1517
|
+
if (myGeneration === this.turnGeneration) {
|
|
1518
|
+
this.setIsLoading(false);
|
|
1519
|
+
}
|
|
1520
|
+
break outer;
|
|
1521
|
+
}
|
|
1470
1522
|
}
|
|
1471
1523
|
}
|
|
1472
1524
|
|
|
@@ -1502,6 +1554,20 @@ export class AIManager {
|
|
|
1502
1554
|
}))
|
|
1503
1555
|
: undefined;
|
|
1504
1556
|
|
|
1557
|
+
// Extract text content from the last assistant message so hooks can
|
|
1558
|
+
// inspect the final response without reading the transcript file.
|
|
1559
|
+
const allMessages = this.messageManager.getMessages();
|
|
1560
|
+
const lastAssistant = [...allMessages]
|
|
1561
|
+
.reverse()
|
|
1562
|
+
.find((m) => m.role === "assistant");
|
|
1563
|
+
const lastAssistantText = lastAssistant
|
|
1564
|
+
? lastAssistant.blocks
|
|
1565
|
+
.filter((b) => b.type === "text")
|
|
1566
|
+
.map((b) => b.content)
|
|
1567
|
+
.join("\n")
|
|
1568
|
+
.trim() || undefined
|
|
1569
|
+
: undefined;
|
|
1570
|
+
|
|
1505
1571
|
const context: ExtendedHookExecutionContext = {
|
|
1506
1572
|
event: hookName,
|
|
1507
1573
|
projectDir: this.getWorkdir(),
|
|
@@ -1512,6 +1578,7 @@ export class AIManager {
|
|
|
1512
1578
|
subagentType: this.subagentType, // Include subagent type in hook context
|
|
1513
1579
|
backgroundTasks, // Stop-only: running background tasks snapshot
|
|
1514
1580
|
sessionCrons, // Stop-only: session cron jobs snapshot
|
|
1581
|
+
lastAssistantMessage: lastAssistantText, // Stop/SubagentStop: last assistant message text
|
|
1515
1582
|
// Stop hooks don't need toolName, toolInput, toolResponse, or userPrompt
|
|
1516
1583
|
env: Object.fromEntries(
|
|
1517
1584
|
Object.entries(process.env).filter((e) => e[1] !== undefined),
|
|
@@ -6,7 +6,8 @@ import { BackgroundTask, BackgroundShell } from "../types/processes.js";
|
|
|
6
6
|
import { stripAnsiColors } from "../utils/stringUtils.js";
|
|
7
7
|
import { logger } from "../utils/globalLogger.js";
|
|
8
8
|
import { Container } from "../utils/container.js";
|
|
9
|
-
import {
|
|
9
|
+
import { MessageQueue } from "./messageQueue.js";
|
|
10
|
+
import { resolveShellPath } from "../utils/shellResolver.js";
|
|
10
11
|
|
|
11
12
|
export interface BackgroundTaskManagerCallbacks {
|
|
12
13
|
onBackgroundTasksChange?: (tasks: BackgroundTask[]) => void;
|
|
@@ -31,10 +32,6 @@ export class BackgroundTaskManager {
|
|
|
31
32
|
this.workdir = options.workdir;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
private get notificationQueue(): NotificationQueue {
|
|
35
|
-
return this.container.get<NotificationQueue>("NotificationQueue")!;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
35
|
/**
|
|
39
36
|
* Fire the onBackgroundTasksChange callback so UI consumers refresh.
|
|
40
37
|
* Public so other managers (e.g. WorkflowManager) can trigger a refresh
|
|
@@ -64,15 +61,16 @@ export class BackgroundTaskManager {
|
|
|
64
61
|
public startShell(
|
|
65
62
|
command: string,
|
|
66
63
|
timeout?: number,
|
|
64
|
+
cwd?: string,
|
|
67
65
|
): { id: string; child: ChildProcess; detach: () => void } {
|
|
68
66
|
const id = this.generateId();
|
|
69
67
|
const startTime = Date.now();
|
|
70
68
|
|
|
71
69
|
const child = spawn(command, {
|
|
72
|
-
shell: true,
|
|
70
|
+
shell: resolveShellPath() ?? true,
|
|
73
71
|
stdio: "pipe",
|
|
74
72
|
detached: true,
|
|
75
|
-
cwd: this.workdir,
|
|
73
|
+
cwd: cwd ?? this.workdir,
|
|
76
74
|
env: {
|
|
77
75
|
...process.env,
|
|
78
76
|
},
|
|
@@ -176,13 +174,13 @@ export class BackgroundTaskManager {
|
|
|
176
174
|
|
|
177
175
|
// Skip notification if task was manually killed (user/agent-initiated stop)
|
|
178
176
|
if (!wasKilled) {
|
|
179
|
-
const
|
|
180
|
-
? this.container.get<
|
|
177
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
178
|
+
? this.container.get<MessageQueue>("MessageQueue")
|
|
181
179
|
: undefined;
|
|
182
|
-
if (
|
|
180
|
+
if (messageQueue) {
|
|
183
181
|
const statusStr = shell.status;
|
|
184
182
|
const summary = `Command "${command}" ${statusStr} with exit code ${code ?? 0}`;
|
|
185
|
-
|
|
183
|
+
messageQueue.enqueueNotification(
|
|
186
184
|
`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>${statusStr}</status>\n<summary>${summary}</summary>\n</task-notification>`,
|
|
187
185
|
);
|
|
188
186
|
}
|
|
@@ -206,12 +204,12 @@ export class BackgroundTaskManager {
|
|
|
206
204
|
this.notifyTasksChange();
|
|
207
205
|
|
|
208
206
|
// Enqueue error notification
|
|
209
|
-
const
|
|
210
|
-
? this.container.get<
|
|
207
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
208
|
+
? this.container.get<MessageQueue>("MessageQueue")
|
|
211
209
|
: undefined;
|
|
212
|
-
if (
|
|
210
|
+
if (messageQueue) {
|
|
213
211
|
const summary = `Command "${command}" failed with error: ${stripAnsiColors(error.message)}`;
|
|
214
|
-
|
|
212
|
+
messageQueue.enqueueNotification(
|
|
215
213
|
`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>failed</status>\n<summary>${summary}</summary>\n</task-notification>`,
|
|
216
214
|
);
|
|
217
215
|
}
|
|
@@ -335,13 +333,13 @@ export class BackgroundTaskManager {
|
|
|
335
333
|
|
|
336
334
|
// Skip notification if task was manually killed (user/agent-initiated stop)
|
|
337
335
|
if (!wasKilled) {
|
|
338
|
-
const
|
|
339
|
-
? this.container.get<
|
|
336
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
337
|
+
? this.container.get<MessageQueue>("MessageQueue")
|
|
340
338
|
: undefined;
|
|
341
|
-
if (
|
|
339
|
+
if (messageQueue) {
|
|
342
340
|
const statusStr = shell.status;
|
|
343
341
|
const summary = `Command "${command}" ${statusStr} with exit code ${code ?? 0}`;
|
|
344
|
-
|
|
342
|
+
messageQueue.enqueueNotification(
|
|
345
343
|
`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>${statusStr}</status>\n<summary>${summary}</summary>\n</task-notification>`,
|
|
346
344
|
);
|
|
347
345
|
}
|
|
@@ -362,12 +360,12 @@ export class BackgroundTaskManager {
|
|
|
362
360
|
this.notifyTasksChange();
|
|
363
361
|
|
|
364
362
|
// Enqueue error notification
|
|
365
|
-
const
|
|
366
|
-
? this.container.get<
|
|
363
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
364
|
+
? this.container.get<MessageQueue>("MessageQueue")
|
|
367
365
|
: undefined;
|
|
368
|
-
if (
|
|
366
|
+
if (messageQueue) {
|
|
369
367
|
const summary = `Command "${command}" failed with error: ${stripAnsiColors(error.message)}`;
|
|
370
|
-
|
|
368
|
+
messageQueue.enqueueNotification(
|
|
371
369
|
`<task-notification>\n<task-id>${id}</task-id>\n<task-type>shell</task-type>\n<output-file>${logPath}</output-file>\n<status>failed</status>\n<summary>${summary}</summary>\n</task-notification>`,
|
|
372
370
|
);
|
|
373
371
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn, type ChildProcess } from "child_process";
|
|
2
2
|
import type { MessageManager } from "./messageManager.js";
|
|
3
3
|
import { Container } from "../utils/container.js";
|
|
4
|
+
import { resolveShellPath } from "../utils/shellResolver.js";
|
|
4
5
|
|
|
5
6
|
export interface BangManagerOptions {
|
|
6
7
|
workdir: string;
|
|
@@ -45,7 +46,7 @@ export class BangManager {
|
|
|
45
46
|
|
|
46
47
|
return new Promise<number>((resolve) => {
|
|
47
48
|
const child = spawn(command, {
|
|
48
|
-
shell: true,
|
|
49
|
+
shell: resolveShellPath() ?? true,
|
|
49
50
|
stdio: "pipe",
|
|
50
51
|
cwd: this.workdir,
|
|
51
52
|
env: {
|