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/agent.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type QueuedMessage } from "./managers/messageQueue.js";
|
|
2
2
|
import { SlashCommand, CustomSlashCommand, AgentOptions } from "./types/index.js";
|
|
3
3
|
import type { Message, McpServerStatus, GatewayConfig, ModelConfig, Usage, PermissionMode, ForegroundTask } from "./types/index.js";
|
|
4
|
+
import type { WorktreeSession } from "./utils/worktreeSession.js";
|
|
4
5
|
export declare class Agent {
|
|
5
6
|
private messageManager;
|
|
6
7
|
private aiManager;
|
|
@@ -21,9 +22,8 @@ export declare class Agent {
|
|
|
21
22
|
private goalManager;
|
|
22
23
|
private hookManager;
|
|
23
24
|
private reversionManager;
|
|
24
|
-
private notificationQueue;
|
|
25
25
|
private messageQueue;
|
|
26
|
-
private
|
|
26
|
+
private dispatchPromise;
|
|
27
27
|
private memoryRuleManager;
|
|
28
28
|
private liveConfigManager;
|
|
29
29
|
private taskManager;
|
|
@@ -71,6 +71,12 @@ export declare class Agent {
|
|
|
71
71
|
* @param newCwd - The new working directory
|
|
72
72
|
*/
|
|
73
73
|
setWorkdir(newCwd: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Set this session's worktree session state (used by CLI -w startup to inject the
|
|
76
|
+
* session created before the agent existed). Delegates to AIManager so the state is
|
|
77
|
+
* stored in this agent's own DI container.
|
|
78
|
+
*/
|
|
79
|
+
setWorktreeSession(session: WorktreeSession | null): void;
|
|
74
80
|
/** Get project memory content */
|
|
75
81
|
get projectMemory(): string;
|
|
76
82
|
/** Get user memory content */
|
|
@@ -83,7 +89,7 @@ export declare class Agent {
|
|
|
83
89
|
get isCompacting(): boolean;
|
|
84
90
|
/** Get bash command execution status */
|
|
85
91
|
get isCommandRunning(): boolean;
|
|
86
|
-
/** Get queued messages */
|
|
92
|
+
/** Get queued user-facing messages (excludes background notifications) */
|
|
87
93
|
get queuedMessages(): QueuedMessage[];
|
|
88
94
|
/** Get goal status string */
|
|
89
95
|
get goalStatus(): string;
|
|
@@ -107,13 +113,29 @@ export declare class Agent {
|
|
|
107
113
|
*/
|
|
108
114
|
removeQueuedMessageById(id: string): boolean;
|
|
109
115
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
116
|
+
* Update a queued message's content by its ID (does not change queue order)
|
|
117
|
+
* @param id - The ID of the message to update
|
|
118
|
+
* @param patch - The fields to update
|
|
119
|
+
* @returns true if the message was updated, false if not found
|
|
120
|
+
*/
|
|
121
|
+
updateQueuedMessageById(id: string, patch: {
|
|
122
|
+
content?: string;
|
|
123
|
+
images?: Array<{
|
|
124
|
+
path: string;
|
|
125
|
+
mimeType: string;
|
|
126
|
+
}>;
|
|
127
|
+
type?: "message" | "bang";
|
|
128
|
+
}): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Unified dispatch trigger — checks state machine before processing.
|
|
131
|
+
* Handles user messages, bang commands, and background task notifications
|
|
132
|
+
* through a single serialized path. Called from onMessageEnqueued,
|
|
133
|
+
* onLoadingChange(false), and onCommandRunningChange(false).
|
|
113
134
|
*/
|
|
114
|
-
private
|
|
135
|
+
private tryDispatch;
|
|
115
136
|
/**
|
|
116
|
-
* Process the next queued
|
|
137
|
+
* Process the next queued item when the agent becomes idle.
|
|
138
|
+
* Handles three item types: user messages, bang commands, and notifications.
|
|
117
139
|
*/
|
|
118
140
|
private processQueuedMessage;
|
|
119
141
|
/** Get background bash shell output */
|
|
@@ -200,11 +222,6 @@ export declare class Agent {
|
|
|
200
222
|
*/
|
|
201
223
|
restoreSession(sessionId: string): Promise<void>;
|
|
202
224
|
abortAIMessage(): void;
|
|
203
|
-
/**
|
|
204
|
-
* Process pending background task notifications by injecting them as user messages
|
|
205
|
-
* and triggering a new AI response cycle.
|
|
206
|
-
*/
|
|
207
|
-
private processPendingNotifications;
|
|
208
225
|
/** Execute bash command (bang command) */
|
|
209
226
|
bang(command: string): Promise<void>;
|
|
210
227
|
clearMessages(): Promise<void>;
|
|
@@ -374,4 +391,3 @@ export declare class Agent {
|
|
|
374
391
|
*/
|
|
375
392
|
get hasRunningBackgroundWork(): boolean;
|
|
376
393
|
}
|
|
377
|
-
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.js
CHANGED
|
@@ -51,7 +51,7 @@ export class Agent {
|
|
|
51
51
|
*/
|
|
52
52
|
constructor(options) {
|
|
53
53
|
this.bangManager = null;
|
|
54
|
-
this.
|
|
54
|
+
this.dispatchPromise = null; // Track current dispatch for teardown
|
|
55
55
|
this.sessionStartTime = Date.now();
|
|
56
56
|
const { logger, workdir, systemPrompt, stream = true } = options;
|
|
57
57
|
// Set working directory early as we need it for loading configuration
|
|
@@ -111,36 +111,27 @@ export class Agent {
|
|
|
111
111
|
this.bangManager = this.container.get("BangManager");
|
|
112
112
|
this.cronManager = this.container.get("CronManager");
|
|
113
113
|
this.goalManager = this.container.get("GoalManager");
|
|
114
|
-
this.notificationQueue = this.container.get("NotificationQueue");
|
|
115
114
|
this.messageQueue = this.container.get("MessageQueue");
|
|
116
|
-
// Wire up notification queue to trigger AI when notifications arrive while idle
|
|
117
|
-
this.notificationQueue.onNotificationsEnqueued = () => {
|
|
118
|
-
// If the AI is NOT loading (idle), trigger a new AI cycle to process notifications
|
|
119
|
-
if (!this.aiManager.isLoading) {
|
|
120
|
-
const pendingPromise = this.processPendingNotifications().catch((error) => {
|
|
121
|
-
this.logger?.error("Failed to process pending notifications:", error);
|
|
122
|
-
});
|
|
123
|
-
this.pendingNotificationPromises.push(pendingPromise);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
115
|
// Wire up CWD change callback from AIManager to sync Agent's workdir
|
|
127
116
|
this.aiManager.setOnCwdChange((newCwd) => {
|
|
128
117
|
this.workdir = newCwd;
|
|
129
118
|
this.container.register("Workdir", newCwd);
|
|
130
119
|
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
131
120
|
});
|
|
132
|
-
// Wire up message queue to process when agent becomes idle
|
|
133
|
-
|
|
121
|
+
// Wire up message queue to process when agent becomes idle.
|
|
122
|
+
// Both user messages and background task notifications enqueue here,
|
|
123
|
+
// unified through a single dispatch path (tryDispatch).
|
|
124
|
+
this.messageQueue.onMessageEnqueued = () => this.tryDispatch();
|
|
134
125
|
// Wire up AI loading changes to process queue when AI becomes idle
|
|
135
126
|
this.aiManager.onLoadingChange = (loading) => {
|
|
136
127
|
if (!loading)
|
|
137
|
-
this.
|
|
128
|
+
this.tryDispatch();
|
|
138
129
|
};
|
|
139
130
|
// Wire up bang manager callback for command running changes
|
|
140
131
|
this.bangManager.onCommandRunningChange = (running) => {
|
|
141
132
|
this.options.callbacks?.onCommandRunningChange?.(running);
|
|
142
133
|
if (!running)
|
|
143
|
-
this.
|
|
134
|
+
this.tryDispatch();
|
|
144
135
|
};
|
|
145
136
|
// Set initial permission mode if provided
|
|
146
137
|
if (options.permissionMode) {
|
|
@@ -184,6 +175,14 @@ export class Agent {
|
|
|
184
175
|
this.container.register("Workdir", newCwd);
|
|
185
176
|
this.options.callbacks?.onWorkdirChange?.(newCwd);
|
|
186
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Set this session's worktree session state (used by CLI -w startup to inject the
|
|
180
|
+
* session created before the agent existed). Delegates to AIManager so the state is
|
|
181
|
+
* stored in this agent's own DI container.
|
|
182
|
+
*/
|
|
183
|
+
setWorktreeSession(session) {
|
|
184
|
+
this.aiManager.setWorktreeSession(session);
|
|
185
|
+
}
|
|
187
186
|
/** Get project memory content */
|
|
188
187
|
get projectMemory() {
|
|
189
188
|
const memoryService = this.container.get("MemoryService");
|
|
@@ -210,9 +209,11 @@ export class Agent {
|
|
|
210
209
|
get isCommandRunning() {
|
|
211
210
|
return this.bangManager?.isCommandRunning ?? false;
|
|
212
211
|
}
|
|
213
|
-
/** Get queued messages */
|
|
212
|
+
/** Get queued user-facing messages (excludes background notifications) */
|
|
214
213
|
get queuedMessages() {
|
|
215
|
-
return this.messageQueue
|
|
214
|
+
return this.messageQueue
|
|
215
|
+
.getQueue()
|
|
216
|
+
.filter((m) => m.type !== "notification");
|
|
216
217
|
}
|
|
217
218
|
/** Get goal status string */
|
|
218
219
|
get goalStatus() {
|
|
@@ -258,11 +259,25 @@ export class Agent {
|
|
|
258
259
|
return removed;
|
|
259
260
|
}
|
|
260
261
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
262
|
+
* Update a queued message's content by its ID (does not change queue order)
|
|
263
|
+
* @param id - The ID of the message to update
|
|
264
|
+
* @param patch - The fields to update
|
|
265
|
+
* @returns true if the message was updated, false if not found
|
|
266
|
+
*/
|
|
267
|
+
updateQueuedMessageById(id, patch) {
|
|
268
|
+
const updated = this.messageQueue.updateById(id, patch);
|
|
269
|
+
if (updated) {
|
|
270
|
+
this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
|
|
271
|
+
}
|
|
272
|
+
return updated;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Unified dispatch trigger — checks state machine before processing.
|
|
276
|
+
* Handles user messages, bang commands, and background task notifications
|
|
277
|
+
* through a single serialized path. Called from onMessageEnqueued,
|
|
278
|
+
* onLoadingChange(false), and onCommandRunningChange(false).
|
|
264
279
|
*/
|
|
265
|
-
|
|
280
|
+
tryDispatch() {
|
|
266
281
|
if (this.messageQueue.state !== "idle")
|
|
267
282
|
return;
|
|
268
283
|
if (!this.messageQueue.hasPending())
|
|
@@ -270,17 +285,19 @@ export class Agent {
|
|
|
270
285
|
if (this.aiManager.isLoading || this.isCommandRunning)
|
|
271
286
|
return;
|
|
272
287
|
this.messageQueue.transitionTo("dispatching");
|
|
273
|
-
this.processQueuedMessage()
|
|
288
|
+
this.dispatchPromise = this.processQueuedMessage()
|
|
274
289
|
.catch((error) => {
|
|
275
290
|
this.logger?.error("Failed to process queued message:", error);
|
|
276
291
|
})
|
|
277
292
|
.finally(() => {
|
|
278
293
|
this.messageQueue.transitionTo("idle");
|
|
279
|
-
this.
|
|
294
|
+
this.dispatchPromise = null;
|
|
295
|
+
this.tryDispatch(); // Re-check after processing
|
|
280
296
|
});
|
|
281
297
|
}
|
|
282
298
|
/**
|
|
283
|
-
* Process the next queued
|
|
299
|
+
* Process the next queued item when the agent becomes idle.
|
|
300
|
+
* Handles three item types: user messages, bang commands, and notifications.
|
|
284
301
|
*/
|
|
285
302
|
async processQueuedMessage() {
|
|
286
303
|
const next = this.messageQueue.dequeue();
|
|
@@ -292,6 +309,26 @@ export class Agent {
|
|
|
292
309
|
await this.bangManager?.executeCommand(next.content);
|
|
293
310
|
await this.messageManager.saveSession();
|
|
294
311
|
}
|
|
312
|
+
else if (next.type === "notification") {
|
|
313
|
+
// Drain all pending notifications and batch them into a single AI turn
|
|
314
|
+
const allNotifications = [
|
|
315
|
+
next.content,
|
|
316
|
+
...this.messageQueue.drainNotifications(),
|
|
317
|
+
];
|
|
318
|
+
for (const xml of allNotifications) {
|
|
319
|
+
const block = parseTaskNotificationXml(xml);
|
|
320
|
+
if (block) {
|
|
321
|
+
this.messageManager.addNotificationMessage({
|
|
322
|
+
taskId: block.taskId,
|
|
323
|
+
taskType: block.taskType,
|
|
324
|
+
status: block.status,
|
|
325
|
+
summary: block.summary,
|
|
326
|
+
outputFile: block.outputFile,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
await this.aiManager.sendAIMessage({ recursionDepth: 0 });
|
|
331
|
+
}
|
|
295
332
|
else {
|
|
296
333
|
await this.sendMessage(next.content, next.images);
|
|
297
334
|
}
|
|
@@ -468,29 +505,6 @@ export class Agent {
|
|
|
468
505
|
abortAIMessage() {
|
|
469
506
|
this.aiManager.abortAIMessage();
|
|
470
507
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Process pending background task notifications by injecting them as user messages
|
|
473
|
-
* and triggering a new AI response cycle.
|
|
474
|
-
*/
|
|
475
|
-
async processPendingNotifications() {
|
|
476
|
-
const notifications = this.notificationQueue.dequeueAll();
|
|
477
|
-
if (notifications.length === 0)
|
|
478
|
-
return;
|
|
479
|
-
for (const notification of notifications) {
|
|
480
|
-
const block = parseTaskNotificationXml(notification);
|
|
481
|
-
if (block) {
|
|
482
|
-
this.messageManager.addNotificationMessage({
|
|
483
|
-
taskId: block.taskId,
|
|
484
|
-
taskType: block.taskType,
|
|
485
|
-
status: block.status,
|
|
486
|
-
summary: block.summary,
|
|
487
|
-
outputFile: block.outputFile,
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
// Trigger AI to process the notifications
|
|
492
|
-
await this.aiManager.sendAIMessage({ recursionDepth: 0 });
|
|
493
|
-
}
|
|
494
508
|
/** Execute bash command (bang command) */
|
|
495
509
|
async bang(command) {
|
|
496
510
|
// If the agent is busy, enqueue the bang command
|
|
@@ -619,8 +633,9 @@ export class Agent {
|
|
|
619
633
|
/** Unified interrupt method, interrupts both AI messages and command execution */
|
|
620
634
|
abortMessage() {
|
|
621
635
|
if (this.aiManager.isLoading || this.isCommandRunning) {
|
|
622
|
-
// Clear queue first to prevent processQueuedMessage
|
|
623
|
-
// when abortAIMessage triggers onLoadingChange(false)
|
|
636
|
+
// Clear user-facing queue items first to prevent processQueuedMessage
|
|
637
|
+
// from dequeuing when abortAIMessage triggers onLoadingChange(false).
|
|
638
|
+
// Notifications are preserved so background task results aren't lost.
|
|
624
639
|
this.messageQueue.clear();
|
|
625
640
|
this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
|
|
626
641
|
}
|
|
@@ -694,14 +709,13 @@ export class Agent {
|
|
|
694
709
|
exitReason: "destroy",
|
|
695
710
|
}).catch(() => { });
|
|
696
711
|
await shutdownTelemetry();
|
|
697
|
-
// Clear
|
|
712
|
+
// Clear message queue callback first to prevent any late triggers from
|
|
698
713
|
// starting async work during teardown
|
|
699
|
-
this.
|
|
700
|
-
// Await any pending
|
|
714
|
+
this.messageQueue.onMessageEnqueued = undefined;
|
|
715
|
+
// Await any pending dispatch to prevent race conditions
|
|
701
716
|
// with test teardown (e.g., V8 coverage stream cleanup)
|
|
702
|
-
if (this.
|
|
703
|
-
await
|
|
704
|
-
this.pendingNotificationPromises = [];
|
|
717
|
+
if (this.dispatchPromise) {
|
|
718
|
+
await this.dispatchPromise.catch(() => { });
|
|
705
719
|
}
|
|
706
720
|
// Fire SessionEnd hooks (fire-and-forget, don't block shutdown)
|
|
707
721
|
try {
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export declare const GOAL_EVALUATION_SYSTEM_PROMPT = "You are a goal evaluator. Given a goal condition and a conversation, determine whether the goal has been achieved.\n\nRules:\n- Judge ONLY based on what the conversation shows \u2014 tool outputs, test results, file contents, etc.\n- Do NOT assume work is done without evidence in the conversation.\n- Be strict and conservative: when uncertain, return met: false.\n- Be concise: your reason should be 1-2 sentences.\n\nRespond with JSON only, no other text:\n{\"met\": boolean, \"reason\": \"short explanation\"}";
|
|
2
|
-
//# sourceMappingURL=goalPrompts.d.ts.map
|
|
@@ -9,4 +9,3 @@ export declare const BASH_MAX_OUTPUT_CHARS = 30000;
|
|
|
9
9
|
export declare const SKILL_BASH_MAX_OUTPUT_CHARS = 30000;
|
|
10
10
|
/** Preview size in characters when output is persisted to disk. */
|
|
11
11
|
export declare const PREVIEW_SIZE_BYTES = 2048;
|
|
12
|
-
//# sourceMappingURL=toolLimits.d.ts.map
|
|
@@ -22,4 +22,3 @@ export declare const WEB_FETCH_TOOL_NAME = "WebFetch";
|
|
|
22
22
|
export declare const ENTER_WORKTREE_TOOL_NAME = "EnterWorktree";
|
|
23
23
|
export declare const EXIT_WORKTREE_TOOL_NAME = "ExitWorktree";
|
|
24
24
|
export declare const WORKFLOW_TOOL_NAME = "Workflow";
|
|
25
|
-
//# sourceMappingURL=tools.d.ts.map
|
package/dist/core/plugin.d.ts
CHANGED
package/dist/core/session.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GatewayConfig, ModelConfig, Usage } from "../types/index.js";
|
|
2
2
|
import { Container } from "../utils/container.js";
|
|
3
|
+
import type { WorktreeSession } from "../utils/worktreeSession.js";
|
|
3
4
|
export interface AIManagerCallbacks {
|
|
4
5
|
onCompactionStateChange?: (isCompacting: boolean) => void;
|
|
5
6
|
onUsageAdded?: (usage: Usage) => void;
|
|
@@ -20,6 +21,7 @@ export interface AIManagerOptions {
|
|
|
20
21
|
export declare class AIManager {
|
|
21
22
|
private container;
|
|
22
23
|
isLoading: boolean;
|
|
24
|
+
private turnGeneration;
|
|
23
25
|
private abortController;
|
|
24
26
|
onLoadingChange?: (loading: boolean) => void;
|
|
25
27
|
private toolAbortController;
|
|
@@ -60,9 +62,21 @@ export declare class AIManager {
|
|
|
60
62
|
getOriginalWorkdir(): string;
|
|
61
63
|
/**
|
|
62
64
|
* Update the working directory mid-session (e.g., when entering/exiting a worktree).
|
|
63
|
-
*
|
|
65
|
+
* Only updates this session's DI container; it does NOT change the process-level
|
|
66
|
+
* process.cwd(), so concurrent sessions in the same stdio process are unaffected.
|
|
67
|
+
* Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is
|
|
68
|
+
* notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged
|
|
69
|
+
* hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks).
|
|
64
70
|
*/
|
|
65
71
|
setWorkdir(newWorkdir: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get this session's worktree session state (null if not in a worktree).
|
|
74
|
+
*/
|
|
75
|
+
getWorktreeSession(): WorktreeSession | null;
|
|
76
|
+
/**
|
|
77
|
+
* Set this session's worktree session state.
|
|
78
|
+
*/
|
|
79
|
+
setWorktreeSession(session: WorktreeSession | null): void;
|
|
66
80
|
setOnCwdChange(callback: (newCwd: string) => void): void;
|
|
67
81
|
private isCompacting;
|
|
68
82
|
private callbacks;
|
|
@@ -126,4 +140,3 @@ export declare class AIManager {
|
|
|
126
140
|
*/
|
|
127
141
|
private executePostToolUseHooks;
|
|
128
142
|
}
|
|
129
|
-
//# sourceMappingURL=aiManager.d.ts.map
|
|
@@ -53,6 +53,7 @@ export class AIManager {
|
|
|
53
53
|
constructor(container, options) {
|
|
54
54
|
this.container = container;
|
|
55
55
|
this.isLoading = false;
|
|
56
|
+
this.turnGeneration = 0; // Guards against concurrent sendAIMessage turns
|
|
56
57
|
this.abortController = null;
|
|
57
58
|
this.toolAbortController = null;
|
|
58
59
|
this.consecutiveCompactionFailures = 0;
|
|
@@ -135,11 +136,27 @@ export class AIManager {
|
|
|
135
136
|
}
|
|
136
137
|
/**
|
|
137
138
|
* Update the working directory mid-session (e.g., when entering/exiting a worktree).
|
|
138
|
-
*
|
|
139
|
+
* Only updates this session's DI container; it does NOT change the process-level
|
|
140
|
+
* process.cwd(), so concurrent sessions in the same stdio process are unaffected.
|
|
141
|
+
* Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is
|
|
142
|
+
* notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged
|
|
143
|
+
* hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks).
|
|
139
144
|
*/
|
|
140
145
|
setWorkdir(newWorkdir) {
|
|
141
146
|
this.container.register("Workdir", newWorkdir);
|
|
142
|
-
|
|
147
|
+
this._onCwdChange?.(newWorkdir);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get this session's worktree session state (null if not in a worktree).
|
|
151
|
+
*/
|
|
152
|
+
getWorktreeSession() {
|
|
153
|
+
return (this.container.get("WorktreeSession") ?? null);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Set this session's worktree session state.
|
|
157
|
+
*/
|
|
158
|
+
setWorktreeSession(session) {
|
|
159
|
+
this.container.register("WorktreeSession", session);
|
|
143
160
|
}
|
|
144
161
|
setOnCwdChange(callback) {
|
|
145
162
|
this._onCwdChange = callback;
|
|
@@ -225,6 +242,9 @@ export class AIManager {
|
|
|
225
242
|
options?.callbacks?.onLoadingChange?.(isLoading);
|
|
226
243
|
}
|
|
227
244
|
abortAIMessage() {
|
|
245
|
+
// Bump generation so the in-flight turn's end-of-turn setIsLoading(false)
|
|
246
|
+
// is skipped (generation mismatch), preventing it from racing with this abort.
|
|
247
|
+
this.turnGeneration++;
|
|
228
248
|
// Interrupt AI service
|
|
229
249
|
if (this.abortController) {
|
|
230
250
|
try {
|
|
@@ -544,6 +564,14 @@ export class AIManager {
|
|
|
544
564
|
async sendAIMessage(options = {}) {
|
|
545
565
|
const { recursionDepth = 0, model, allowedRules, maxTokens } = options;
|
|
546
566
|
let turnOffset = recursionDepth;
|
|
567
|
+
// Reserve this turn synchronously before any async work. Bumping the
|
|
568
|
+
// generation invalidates any in-flight turn's end-of-turn cleanup, and
|
|
569
|
+
// recording myGeneration lets us skip cleanup if a newer turn (or abort)
|
|
570
|
+
// has superseded us. setIsLoading(true) here also closes the "idle but
|
|
571
|
+
// previous turn not finished" race window by marking us busy immediately.
|
|
572
|
+
this.turnGeneration++;
|
|
573
|
+
const myGeneration = this.turnGeneration;
|
|
574
|
+
this.setIsLoading(true);
|
|
547
575
|
outer: while (true) {
|
|
548
576
|
let shouldRestart = false;
|
|
549
577
|
// OpenTelemetry: start interaction span for this turn (initial call only)
|
|
@@ -561,9 +589,8 @@ export class AIManager {
|
|
|
561
589
|
prompt_length: String(userPromptText.length),
|
|
562
590
|
}).catch(() => { }); // Non-blocking
|
|
563
591
|
}
|
|
564
|
-
//
|
|
592
|
+
// Apply allowed rules for the initial call
|
|
565
593
|
if (turnOffset === 0) {
|
|
566
|
-
this.setIsLoading(true);
|
|
567
594
|
if (allowedRules && allowedRules.length > 0) {
|
|
568
595
|
this.permissionManager?.addTemporaryRules(allowedRules);
|
|
569
596
|
}
|
|
@@ -657,6 +684,7 @@ export class AIManager {
|
|
|
657
684
|
originalWorkdir: this.getOriginalWorkdir(),
|
|
658
685
|
language: this.getLanguage(),
|
|
659
686
|
isSubagent: !!this.subagentType,
|
|
687
|
+
worktreeSession: this.getWorktreeSession(),
|
|
660
688
|
autoMemory: autoMemoryOptions,
|
|
661
689
|
}), // Pass custom system prompt
|
|
662
690
|
maxTokens: maxTokens, // Pass max tokens override
|
|
@@ -941,6 +969,12 @@ export class AIManager {
|
|
|
941
969
|
error_type: error instanceof Error ? error.constructor.name : "Unknown",
|
|
942
970
|
message: error instanceof Error ? error.message : String(error),
|
|
943
971
|
}).catch(() => { }); // Non-blocking
|
|
972
|
+
// Finalize any streaming text/reasoning blocks so the UI stops ticking
|
|
973
|
+
// its in-progress timer (e.g. when the request is aborted mid-thought).
|
|
974
|
+
this.messageManager.finalizeStreamingBlocks();
|
|
975
|
+
// Finalize any tool blocks stuck in start/streaming/running so the UI
|
|
976
|
+
// stops showing the yellow "running" spinner (e.g. abort mid-tool-stream).
|
|
977
|
+
this.messageManager.finalizeAbortedToolBlocks(error instanceof Error ? error.message : undefined);
|
|
944
978
|
this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
|
|
945
979
|
// Exit inner loop on error
|
|
946
980
|
break inner;
|
|
@@ -953,8 +987,6 @@ export class AIManager {
|
|
|
953
987
|
endInteractionSpan();
|
|
954
988
|
// Save session in each iteration to ensure message persistence
|
|
955
989
|
await this.messageManager.saveSession();
|
|
956
|
-
// Set loading to false first
|
|
957
|
-
this.setIsLoading(false);
|
|
958
990
|
// Clear temporary rules
|
|
959
991
|
this.permissionManager?.clearTemporaryRules();
|
|
960
992
|
// Clear abort controllers
|
|
@@ -1035,11 +1067,11 @@ export class AIManager {
|
|
|
1035
1067
|
}
|
|
1036
1068
|
// Inject pending notifications from background tasks (after Stop hooks,
|
|
1037
1069
|
// aligned with Claude Code which fires Stop hooks unconditionally)
|
|
1038
|
-
const
|
|
1039
|
-
? this.container.get("
|
|
1070
|
+
const messageQueue = this.container.has("MessageQueue")
|
|
1071
|
+
? this.container.get("MessageQueue")
|
|
1040
1072
|
: undefined;
|
|
1041
|
-
if (
|
|
1042
|
-
const notifications =
|
|
1073
|
+
if (messageQueue && messageQueue.hasNotifications()) {
|
|
1074
|
+
const notifications = messageQueue.drainNotifications();
|
|
1043
1075
|
for (const notification of notifications) {
|
|
1044
1076
|
const block = parseTaskNotificationXml(notification);
|
|
1045
1077
|
if (block) {
|
|
@@ -1057,8 +1089,16 @@ export class AIManager {
|
|
|
1057
1089
|
turnOffset = 0;
|
|
1058
1090
|
}
|
|
1059
1091
|
}
|
|
1060
|
-
if (!shouldRestart)
|
|
1092
|
+
if (!shouldRestart) {
|
|
1093
|
+
// Release loading state only after ALL cleanup is done (session save,
|
|
1094
|
+
// Stop hooks, notification injection). Generation check ensures a
|
|
1095
|
+
// superseded (aborted or newer) turn doesn't clobber the current
|
|
1096
|
+
// loading state.
|
|
1097
|
+
if (myGeneration === this.turnGeneration) {
|
|
1098
|
+
this.setIsLoading(false);
|
|
1099
|
+
}
|
|
1061
1100
|
break outer;
|
|
1101
|
+
}
|
|
1062
1102
|
}
|
|
1063
1103
|
}
|
|
1064
1104
|
/**
|
|
@@ -1088,6 +1128,19 @@ export class AIManager {
|
|
|
1088
1128
|
prompt: j.prompt,
|
|
1089
1129
|
}))
|
|
1090
1130
|
: undefined;
|
|
1131
|
+
// Extract text content from the last assistant message so hooks can
|
|
1132
|
+
// inspect the final response without reading the transcript file.
|
|
1133
|
+
const allMessages = this.messageManager.getMessages();
|
|
1134
|
+
const lastAssistant = [...allMessages]
|
|
1135
|
+
.reverse()
|
|
1136
|
+
.find((m) => m.role === "assistant");
|
|
1137
|
+
const lastAssistantText = lastAssistant
|
|
1138
|
+
? lastAssistant.blocks
|
|
1139
|
+
.filter((b) => b.type === "text")
|
|
1140
|
+
.map((b) => b.content)
|
|
1141
|
+
.join("\n")
|
|
1142
|
+
.trim() || undefined
|
|
1143
|
+
: undefined;
|
|
1091
1144
|
const context = {
|
|
1092
1145
|
event: hookName,
|
|
1093
1146
|
projectDir: this.getWorkdir(),
|
|
@@ -1098,6 +1151,7 @@ export class AIManager {
|
|
|
1098
1151
|
subagentType: this.subagentType, // Include subagent type in hook context
|
|
1099
1152
|
backgroundTasks, // Stop-only: running background tasks snapshot
|
|
1100
1153
|
sessionCrons, // Stop-only: session cron jobs snapshot
|
|
1154
|
+
lastAssistantMessage: lastAssistantText, // Stop/SubagentStop: last assistant message text
|
|
1101
1155
|
// Stop hooks don't need toolName, toolInput, toolResponse, or userPrompt
|
|
1102
1156
|
env: Object.fromEntries(Object.entries(process.env).filter((e) => e[1] !== undefined)), // Include environment variables
|
|
1103
1157
|
};
|
|
@@ -15,7 +15,6 @@ export declare class BackgroundTaskManager {
|
|
|
15
15
|
private callbacks;
|
|
16
16
|
private workdir;
|
|
17
17
|
constructor(container: Container, options: BackgroundTaskManagerOptions);
|
|
18
|
-
private get notificationQueue();
|
|
19
18
|
/**
|
|
20
19
|
* Fire the onBackgroundTasksChange callback so UI consumers refresh.
|
|
21
20
|
* Public so other managers (e.g. WorkflowManager) can trigger a refresh
|
|
@@ -26,7 +25,7 @@ export declare class BackgroundTaskManager {
|
|
|
26
25
|
addTask(task: BackgroundTask): void;
|
|
27
26
|
getTask(id: string): BackgroundTask | undefined;
|
|
28
27
|
getAllTasks(): BackgroundTask[];
|
|
29
|
-
startShell(command: string, timeout?: number): {
|
|
28
|
+
startShell(command: string, timeout?: number, cwd?: string): {
|
|
30
29
|
id: string;
|
|
31
30
|
child: ChildProcess;
|
|
32
31
|
detach: () => void;
|
|
@@ -43,4 +42,3 @@ export declare class BackgroundTaskManager {
|
|
|
43
42
|
stopTask(id: string): boolean;
|
|
44
43
|
cleanup(): void;
|
|
45
44
|
}
|
|
46
|
-
//# sourceMappingURL=backgroundTaskManager.d.ts.map
|