@slopus/rig 0.0.4 → 0.0.6

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 (374) hide show
  1. package/README.md +144 -1
  2. package/dist/agent/Agent.d.ts +16 -0
  3. package/dist/agent/Agent.d.ts.map +1 -1
  4. package/dist/agent/Agent.js +106 -0
  5. package/dist/agent/compaction/compactConversation.d.ts +22 -0
  6. package/dist/agent/compaction/compactConversation.d.ts.map +1 -0
  7. package/dist/agent/compaction/compactConversation.js +77 -0
  8. package/dist/agent/compaction/estimateMessagesTokens.d.ts +3 -0
  9. package/dist/agent/compaction/estimateMessagesTokens.d.ts.map +1 -0
  10. package/dist/agent/compaction/estimateMessagesTokens.js +39 -0
  11. package/dist/agent/compaction/formatMessagesForCompaction.d.ts +3 -0
  12. package/dist/agent/compaction/formatMessagesForCompaction.d.ts.map +1 -0
  13. package/dist/agent/compaction/formatMessagesForCompaction.js +30 -0
  14. package/dist/agent/compaction/requestCompactionSummary.d.ts +11 -0
  15. package/dist/agent/compaction/requestCompactionSummary.d.ts.map +1 -0
  16. package/dist/agent/compaction/requestCompactionSummary.js +43 -0
  17. package/dist/agent/context/AgentContext.d.ts +8 -0
  18. package/dist/agent/context/AgentContext.d.ts.map +1 -1
  19. package/dist/agent/context/BashContext.d.ts +23 -0
  20. package/dist/agent/context/BashContext.d.ts.map +1 -1
  21. package/dist/agent/context/GoalContext.d.ts +7 -0
  22. package/dist/agent/context/GoalContext.d.ts.map +1 -0
  23. package/dist/agent/context/GoalContext.js +1 -0
  24. package/dist/agent/context/SubagentContext.d.ts +20 -1
  25. package/dist/agent/context/SubagentContext.d.ts.map +1 -1
  26. package/dist/agent/context/TaskContext.d.ts +8 -0
  27. package/dist/agent/context/TaskContext.d.ts.map +1 -0
  28. package/dist/agent/context/TaskContext.js +1 -0
  29. package/dist/agent/context/UserInputContext.d.ts +7 -0
  30. package/dist/agent/context/UserInputContext.d.ts.map +1 -0
  31. package/dist/agent/context/UserInputContext.js +1 -0
  32. package/dist/agent/context/assertCanWritePath.d.ts +3 -0
  33. package/dist/agent/context/assertCanWritePath.d.ts.map +1 -0
  34. package/dist/agent/context/assertCanWritePath.js +11 -0
  35. package/dist/agent/context/createJustBashBashContext.d.ts.map +1 -1
  36. package/dist/agent/context/createJustBashBashContext.js +127 -0
  37. package/dist/agent/context/createNodeAgentContext.d.ts +8 -0
  38. package/dist/agent/context/createNodeAgentContext.d.ts.map +1 -1
  39. package/dist/agent/context/createNodeAgentContext.js +15 -2
  40. package/dist/agent/context/createNodeBashContext.d.ts +2 -0
  41. package/dist/agent/context/createNodeBashContext.d.ts.map +1 -1
  42. package/dist/agent/context/createNodeBashContext.js +123 -4
  43. package/dist/agent/context/createNodeFileSystemContext.d.ts +2 -0
  44. package/dist/agent/context/createNodeFileSystemContext.d.ts.map +1 -1
  45. package/dist/agent/context/createNodeFileSystemContext.js +18 -8
  46. package/dist/agent/context/createSandboxedCommand.d.ts +7 -0
  47. package/dist/agent/context/createSandboxedCommand.d.ts.map +1 -0
  48. package/dist/agent/context/createSandboxedCommand.js +47 -0
  49. package/dist/agent/context/findGitWritablePaths.d.ts +2 -0
  50. package/dist/agent/context/findGitWritablePaths.d.ts.map +1 -0
  51. package/dist/agent/context/findGitWritablePaths.js +54 -0
  52. package/dist/agent/context/isPathInsideWorkspace.d.ts +2 -0
  53. package/dist/agent/context/isPathInsideWorkspace.d.ts.map +1 -0
  54. package/dist/agent/context/isPathInsideWorkspace.js +14 -0
  55. package/dist/agent/context/resolvePotentialPath.d.ts +2 -0
  56. package/dist/agent/context/resolvePotentialPath.d.ts.map +1 -0
  57. package/dist/agent/context/resolvePotentialPath.js +32 -0
  58. package/dist/agent/createPermissionInstructions.d.ts +3 -0
  59. package/dist/agent/createPermissionInstructions.d.ts.map +1 -0
  60. package/dist/agent/createPermissionInstructions.js +12 -0
  61. package/dist/agent/createSubagentInstructions.js +1 -1
  62. package/dist/agent/createSystemPrompt.d.ts.map +1 -1
  63. package/dist/agent/createSystemPrompt.js +4 -0
  64. package/dist/agent/index.d.ts +7 -3
  65. package/dist/agent/index.d.ts.map +1 -1
  66. package/dist/agent/loop.d.ts +16 -2
  67. package/dist/agent/loop.d.ts.map +1 -1
  68. package/dist/agent/loop.js +115 -15
  69. package/dist/agent/printAgentMessageToConsole.d.ts +1 -0
  70. package/dist/agent/printAgentMessageToConsole.d.ts.map +1 -1
  71. package/dist/agent/types.d.ts +1 -0
  72. package/dist/agent/types.d.ts.map +1 -1
  73. package/dist/app/CodingAssistantAgentBackend.d.ts +11 -1
  74. package/dist/app/CodingAssistantAgentBackend.d.ts.map +1 -1
  75. package/dist/app/CodingAssistantApp.d.ts +7 -1
  76. package/dist/app/CodingAssistantApp.d.ts.map +1 -1
  77. package/dist/app/CodingAssistantApp.js +678 -45
  78. package/dist/app/ScrollbackPreservingTerminal.d.ts +5 -0
  79. package/dist/app/ScrollbackPreservingTerminal.d.ts.map +1 -0
  80. package/dist/app/ScrollbackPreservingTerminal.js +7 -0
  81. package/dist/app/StartupStatusApp.js +1 -1
  82. package/dist/app/createCodingAssistantAgent.d.ts +6 -1
  83. package/dist/app/createCodingAssistantAgent.d.ts.map +1 -1
  84. package/dist/app/createCodingAssistantAgent.js +22 -5
  85. package/dist/app/createSlashCommands.d.ts.map +1 -1
  86. package/dist/app/createSlashCommands.js +42 -0
  87. package/dist/app/highlightAgentCode.d.ts.map +1 -1
  88. package/dist/app/highlightAgentCode.js +10 -7
  89. package/dist/app/humanizeGoalStatus.d.ts +3 -0
  90. package/dist/app/humanizeGoalStatus.d.ts.map +1 -0
  91. package/dist/app/humanizeGoalStatus.js +9 -0
  92. package/dist/app/humanizePermissionMode.d.ts +3 -0
  93. package/dist/app/humanizePermissionMode.d.ts.map +1 -0
  94. package/dist/app/humanizePermissionMode.js +9 -0
  95. package/dist/app/humanizeToolName.d.ts +2 -0
  96. package/dist/app/humanizeToolName.d.ts.map +1 -0
  97. package/dist/app/humanizeToolName.js +40 -0
  98. package/dist/app/main.d.ts.map +1 -1
  99. package/dist/app/main.js +4 -0
  100. package/dist/app/renderAgentMarkdown.d.ts.map +1 -1
  101. package/dist/app/renderAgentMarkdown.js +2 -1
  102. package/dist/app/runApp.d.ts +2 -0
  103. package/dist/app/runApp.d.ts.map +1 -1
  104. package/dist/app/runApp.js +48 -3
  105. package/dist/app/sanitizeTerminalText.d.ts +2 -0
  106. package/dist/app/sanitizeTerminalText.d.ts.map +1 -0
  107. package/dist/app/sanitizeTerminalText.js +55 -0
  108. package/dist/app/upsertSubagentSummary.d.ts +3 -0
  109. package/dist/app/upsertSubagentSummary.d.ts.map +1 -0
  110. package/dist/app/upsertSubagentSummary.js +6 -0
  111. package/dist/client/ProtocolHttpClient.d.ts +12 -1
  112. package/dist/client/ProtocolHttpClient.d.ts.map +1 -1
  113. package/dist/client/ProtocolHttpClient.js +21 -0
  114. package/dist/client/RemoteAgent.d.ts +11 -1
  115. package/dist/client/RemoteAgent.d.ts.map +1 -1
  116. package/dist/client/RemoteAgent.js +91 -1
  117. package/dist/config/createConfigFile.d.ts.map +1 -1
  118. package/dist/config/createConfigFile.js +5 -0
  119. package/dist/config/defaultConfig.d.ts.map +1 -1
  120. package/dist/config/defaultConfig.js +2 -0
  121. package/dist/config/mergeConfigValues.d.ts.map +1 -1
  122. package/dist/config/mergeConfigValues.js +8 -1
  123. package/dist/config/parseConfigToml.d.ts.map +1 -1
  124. package/dist/config/parseConfigToml.js +88 -0
  125. package/dist/config/serializeMcpServers.d.ts +3 -0
  126. package/dist/config/serializeMcpServers.d.ts.map +1 -0
  127. package/dist/config/serializeMcpServers.js +34 -0
  128. package/dist/config/types.d.ts +6 -0
  129. package/dist/config/types.d.ts.map +1 -1
  130. package/dist/config/writeRuntimeConfig.d.ts.map +1 -1
  131. package/dist/config/writeRuntimeConfig.js +3 -0
  132. package/dist/goals/SessionGoal.d.ts +14 -0
  133. package/dist/goals/SessionGoal.d.ts.map +1 -0
  134. package/dist/goals/SessionGoal.js +1 -0
  135. package/dist/goals/createGoalContinuationPrompt.d.ts +3 -0
  136. package/dist/goals/createGoalContinuationPrompt.d.ts.map +1 -0
  137. package/dist/goals/createGoalContinuationPrompt.js +17 -0
  138. package/dist/goals/index.d.ts +5 -0
  139. package/dist/goals/index.d.ts.map +1 -0
  140. package/dist/goals/index.js +3 -0
  141. package/dist/goals/isGoalStatus.d.ts +3 -0
  142. package/dist/goals/isGoalStatus.d.ts.map +1 -0
  143. package/dist/goals/isGoalStatus.js +3 -0
  144. package/dist/goals/normalizeGoalObjective.d.ts +3 -0
  145. package/dist/goals/normalizeGoalObjective.d.ts.map +1 -0
  146. package/dist/goals/normalizeGoalObjective.js +11 -0
  147. package/dist/mcp/McpClientManager.d.ts +12 -0
  148. package/dist/mcp/McpClientManager.d.ts.map +1 -0
  149. package/dist/mcp/McpClientManager.js +123 -0
  150. package/dist/mcp/connectMcpServer.d.ts +8 -0
  151. package/dist/mcp/connectMcpServer.d.ts.map +1 -0
  152. package/dist/mcp/connectMcpServer.js +47 -0
  153. package/dist/mcp/createMcpTool.d.ts +11 -0
  154. package/dist/mcp/createMcpTool.d.ts.map +1 -0
  155. package/dist/mcp/createMcpTool.js +43 -0
  156. package/dist/mcp/index.d.ts +5 -0
  157. package/dist/mcp/index.d.ts.map +1 -0
  158. package/dist/mcp/index.js +3 -0
  159. package/dist/mcp/loadMcpServerConfigs.d.ts +4 -0
  160. package/dist/mcp/loadMcpServerConfigs.d.ts.map +1 -0
  161. package/dist/mcp/loadMcpServerConfigs.js +122 -0
  162. package/dist/mcp/mcpResultToContentBlocks.d.ts +3 -0
  163. package/dist/mcp/mcpResultToContentBlocks.d.ts.map +1 -0
  164. package/dist/mcp/mcpResultToContentBlocks.js +51 -0
  165. package/dist/mcp/mergeMcpTools.d.ts +7 -0
  166. package/dist/mcp/mergeMcpTools.d.ts.map +1 -0
  167. package/dist/mcp/mergeMcpTools.js +34 -0
  168. package/dist/mcp/normalizeMcpName.d.ts +2 -0
  169. package/dist/mcp/normalizeMcpName.d.ts.map +1 -0
  170. package/dist/mcp/normalizeMcpName.js +3 -0
  171. package/dist/mcp/types.d.ts +37 -0
  172. package/dist/mcp/types.d.ts.map +1 -0
  173. package/dist/mcp/types.js +1 -0
  174. package/dist/permissions/PermissionContext.d.ts +7 -0
  175. package/dist/permissions/PermissionContext.d.ts.map +1 -0
  176. package/dist/permissions/PermissionContext.js +1 -0
  177. package/dist/permissions/PermissionMode.d.ts +3 -0
  178. package/dist/permissions/PermissionMode.d.ts.map +1 -0
  179. package/dist/permissions/PermissionMode.js +1 -0
  180. package/dist/permissions/createPermissionContext.d.ts +4 -0
  181. package/dist/permissions/createPermissionContext.d.ts.map +1 -0
  182. package/dist/permissions/createPermissionContext.js +16 -0
  183. package/dist/permissions/index.d.ts +13 -0
  184. package/dist/permissions/index.d.ts.map +1 -0
  185. package/dist/permissions/index.js +9 -0
  186. package/dist/permissions/isPermissionMode.d.ts +3 -0
  187. package/dist/permissions/isPermissionMode.d.ts.map +1 -0
  188. package/dist/permissions/isPermissionMode.js +6 -0
  189. package/dist/permissions/parseAutoPermissionReview.d.ts +7 -0
  190. package/dist/permissions/parseAutoPermissionReview.d.ts.map +1 -0
  191. package/dist/permissions/parseAutoPermissionReview.js +33 -0
  192. package/dist/permissions/parsePermissionMode.d.ts +3 -0
  193. package/dist/permissions/parsePermissionMode.d.ts.map +1 -0
  194. package/dist/permissions/parsePermissionMode.js +6 -0
  195. package/dist/permissions/requestAutoPermissionApproval.d.ts +9 -0
  196. package/dist/permissions/requestAutoPermissionApproval.d.ts.map +1 -0
  197. package/dist/permissions/requestAutoPermissionApproval.js +26 -0
  198. package/dist/permissions/reviewAutoPermission.d.ts +13 -0
  199. package/dist/permissions/reviewAutoPermission.d.ts.map +1 -0
  200. package/dist/permissions/reviewAutoPermission.js +70 -0
  201. package/dist/permissions/shouldElevateToolInAutoMode.d.ts +2 -0
  202. package/dist/permissions/shouldElevateToolInAutoMode.d.ts.map +1 -0
  203. package/dist/permissions/shouldElevateToolInAutoMode.js +37 -0
  204. package/dist/permissions/shouldReviewToolInAutoMode.d.ts +2 -0
  205. package/dist/permissions/shouldReviewToolInAutoMode.d.ts.map +1 -0
  206. package/dist/permissions/shouldReviewToolInAutoMode.js +85 -0
  207. package/dist/permissions/summarizePermissionAction.d.ts +2 -0
  208. package/dist/permissions/summarizePermissionAction.d.ts.map +1 -0
  209. package/dist/permissions/summarizePermissionAction.js +29 -0
  210. package/dist/protocol/SessionProtocol.d.ts +49 -2
  211. package/dist/protocol/SessionProtocol.d.ts.map +1 -1
  212. package/dist/protocol/index.d.ts +4 -1
  213. package/dist/protocol/index.d.ts.map +1 -1
  214. package/dist/providers/claude-sdk.d.ts.map +1 -1
  215. package/dist/providers/claude-sdk.js +7 -6
  216. package/dist/providers/models.d.ts +12 -12
  217. package/dist/providers/models.d.ts.map +1 -1
  218. package/dist/providers/models.js +18 -0
  219. package/dist/providers/types.d.ts +3 -0
  220. package/dist/providers/types.d.ts.map +1 -1
  221. package/dist/review/createCodeReviewPrompt.d.ts +2 -0
  222. package/dist/review/createCodeReviewPrompt.d.ts.map +1 -0
  223. package/dist/review/createCodeReviewPrompt.js +11 -0
  224. package/dist/review/index.d.ts +2 -0
  225. package/dist/review/index.d.ts.map +1 -0
  226. package/dist/review/index.js +1 -0
  227. package/dist/server/AgentSessionManager.d.ts +10 -1
  228. package/dist/server/AgentSessionManager.d.ts.map +1 -1
  229. package/dist/server/AgentSessionManager.js +203 -12
  230. package/dist/server/InMemorySession.d.ts +34 -1
  231. package/dist/server/InMemorySession.d.ts.map +1 -1
  232. package/dist/server/InMemorySession.js +558 -10
  233. package/dist/server/InMemorySessionStore.d.ts +2 -0
  234. package/dist/server/InMemorySessionStore.d.ts.map +1 -1
  235. package/dist/server/InMemorySessionStore.js +7 -0
  236. package/dist/server/PersistentSessionStore.d.ts +2 -0
  237. package/dist/server/PersistentSessionStore.d.ts.map +1 -1
  238. package/dist/server/PersistentSessionStore.js +80 -5
  239. package/dist/server/createGoalTitle.d.ts +2 -0
  240. package/dist/server/createGoalTitle.d.ts.map +1 -0
  241. package/dist/server/createGoalTitle.js +4 -0
  242. package/dist/server/createProtocolHttpServer.d.ts.map +1 -1
  243. package/dist/server/createProtocolHttpServer.js +119 -2
  244. package/dist/server/runLocalProtocolServer.d.ts.map +1 -1
  245. package/dist/server/runLocalProtocolServer.js +18 -2
  246. package/dist/tasks/index.d.ts +2 -0
  247. package/dist/tasks/index.d.ts.map +1 -0
  248. package/dist/tasks/index.js +1 -0
  249. package/dist/tasks/types.d.ts +39 -0
  250. package/dist/tasks/types.d.ts.map +1 -0
  251. package/dist/tasks/types.js +1 -0
  252. package/dist/tools/Agent.d.ts +13 -3
  253. package/dist/tools/Agent.d.ts.map +1 -1
  254. package/dist/tools/Agent.js +40 -12
  255. package/dist/tools/claude/AskUserQuestion.d.ts +23 -0
  256. package/dist/tools/claude/AskUserQuestion.d.ts.map +1 -0
  257. package/dist/tools/claude/AskUserQuestion.js +52 -0
  258. package/dist/tools/claude/Bash.d.ts +2 -0
  259. package/dist/tools/claude/Bash.d.ts.map +1 -1
  260. package/dist/tools/claude/Bash.js +20 -2
  261. package/dist/tools/claude/SendMessage.d.ts +10 -0
  262. package/dist/tools/claude/SendMessage.d.ts.map +1 -0
  263. package/dist/tools/claude/SendMessage.js +33 -0
  264. package/dist/tools/claude/TaskCreate.d.ts +12 -0
  265. package/dist/tools/claude/TaskCreate.d.ts.map +1 -0
  266. package/dist/tools/claude/TaskCreate.js +34 -0
  267. package/dist/tools/claude/TaskGet.d.ts +16 -0
  268. package/dist/tools/claude/TaskGet.d.ts.map +1 -0
  269. package/dist/tools/claude/TaskGet.js +44 -0
  270. package/dist/tools/claude/TaskList.d.ts +10 -0
  271. package/dist/tools/claude/TaskList.d.ts.map +1 -0
  272. package/dist/tools/claude/TaskList.js +51 -0
  273. package/dist/tools/claude/TaskOutput.d.ts +17 -0
  274. package/dist/tools/claude/TaskOutput.d.ts.map +1 -0
  275. package/dist/tools/claude/TaskOutput.js +74 -0
  276. package/dist/tools/claude/TaskStop.d.ts +10 -0
  277. package/dist/tools/claude/TaskStop.d.ts.map +1 -0
  278. package/dist/tools/claude/TaskStop.js +42 -0
  279. package/dist/tools/claude/TaskUpdate.d.ts +21 -0
  280. package/dist/tools/claude/TaskUpdate.d.ts.map +1 -0
  281. package/dist/tools/claude/TaskUpdate.js +55 -0
  282. package/dist/tools/claude/index.d.ts +111 -5
  283. package/dist/tools/claude/index.d.ts.map +1 -1
  284. package/dist/tools/claude/index.js +24 -2
  285. package/dist/tools/claude/parseBackgroundTaskId.d.ts +2 -0
  286. package/dist/tools/claude/parseBackgroundTaskId.d.ts.map +1 -0
  287. package/dist/tools/claude/parseBackgroundTaskId.js +7 -0
  288. package/dist/tools/claude/taskSchemas.d.ts +14 -0
  289. package/dist/tools/claude/taskSchemas.d.ts.map +1 -0
  290. package/dist/tools/claude/taskSchemas.js +18 -0
  291. package/dist/tools/codex/exec_command.d.ts +8 -6
  292. package/dist/tools/codex/exec_command.d.ts.map +1 -1
  293. package/dist/tools/codex/exec_command.js +37 -18
  294. package/dist/tools/codex/followup_task.d.ts +11 -0
  295. package/dist/tools/codex/followup_task.d.ts.map +1 -0
  296. package/dist/tools/codex/followup_task.js +18 -0
  297. package/dist/tools/codex/humanizeTaskName.d.ts +2 -0
  298. package/dist/tools/codex/humanizeTaskName.d.ts.map +1 -0
  299. package/dist/tools/codex/humanizeTaskName.js +4 -0
  300. package/dist/tools/codex/index.d.ts +90 -7
  301. package/dist/tools/codex/index.d.ts.map +1 -1
  302. package/dist/tools/codex/index.js +24 -0
  303. package/dist/tools/codex/interrupt_agent.d.ts +10 -0
  304. package/dist/tools/codex/interrupt_agent.d.ts.map +1 -0
  305. package/dist/tools/codex/interrupt_agent.js +17 -0
  306. package/dist/tools/codex/list_agents.d.ts +12 -0
  307. package/dist/tools/codex/list_agents.d.ts.map +1 -0
  308. package/dist/tools/codex/list_agents.js +23 -0
  309. package/dist/tools/codex/request_user_input.d.ts +16 -0
  310. package/dist/tools/codex/request_user_input.d.ts.map +1 -0
  311. package/dist/tools/codex/request_user_input.js +58 -0
  312. package/dist/tools/codex/requireSubagentContext.d.ts +3 -0
  313. package/dist/tools/codex/requireSubagentContext.d.ts.map +1 -0
  314. package/dist/tools/codex/requireSubagentContext.js +6 -0
  315. package/dist/tools/codex/spawn_agent.d.ts +9 -0
  316. package/dist/tools/codex/spawn_agent.d.ts.map +1 -0
  317. package/dist/tools/codex/spawn_agent.js +35 -0
  318. package/dist/tools/codex/subagentSchemas.d.ts +8 -0
  319. package/dist/tools/codex/subagentSchemas.d.ts.map +1 -0
  320. package/dist/tools/codex/subagentSchemas.js +13 -0
  321. package/dist/tools/codex/unifiedExecOutput.d.ts +14 -0
  322. package/dist/tools/codex/unifiedExecOutput.d.ts.map +1 -0
  323. package/dist/tools/codex/unifiedExecOutput.js +44 -0
  324. package/dist/tools/codex/update_plan.d.ts +10 -0
  325. package/dist/tools/codex/update_plan.d.ts.map +1 -0
  326. package/dist/tools/codex/update_plan.js +34 -0
  327. package/dist/tools/codex/wait_agent.d.ts +13 -0
  328. package/dist/tools/codex/wait_agent.d.ts.map +1 -0
  329. package/dist/tools/codex/wait_agent.js +32 -0
  330. package/dist/tools/codex/write_stdin.d.ts +6 -1
  331. package/dist/tools/codex/write_stdin.d.ts.map +1 -1
  332. package/dist/tools/codex/write_stdin.js +44 -12
  333. package/dist/tools/goals/create_goal.d.ts +11 -0
  334. package/dist/tools/goals/create_goal.d.ts.map +1 -0
  335. package/dist/tools/goals/create_goal.js +29 -0
  336. package/dist/tools/goals/get_goal.d.ts +9 -0
  337. package/dist/tools/goals/get_goal.d.ts.map +1 -0
  338. package/dist/tools/goals/get_goal.js +26 -0
  339. package/dist/tools/goals/goalSchemas.d.ts +8 -0
  340. package/dist/tools/goals/goalSchemas.d.ts.map +1 -0
  341. package/dist/tools/goals/goalSchemas.js +13 -0
  342. package/dist/tools/goals/index.d.ts +30 -0
  343. package/dist/tools/goals/index.d.ts.map +1 -0
  344. package/dist/tools/goals/index.js +7 -0
  345. package/dist/tools/goals/update_goal.d.ts +11 -0
  346. package/dist/tools/goals/update_goal.d.ts.map +1 -0
  347. package/dist/tools/goals/update_goal.js +33 -0
  348. package/dist/tools/index.d.ts +1 -0
  349. package/dist/tools/index.d.ts.map +1 -1
  350. package/dist/tools/index.js +1 -0
  351. package/dist/tools/pi/bash.d.ts.map +1 -1
  352. package/dist/tools/pi/bash.js +2 -0
  353. package/dist/tools/utils/readSessionWithProgress.d.ts +9 -0
  354. package/dist/tools/utils/readSessionWithProgress.d.ts.map +1 -0
  355. package/dist/tools/utils/readSessionWithProgress.js +27 -0
  356. package/dist/tools/utils/shell.d.ts +2 -0
  357. package/dist/tools/utils/shell.d.ts.map +1 -1
  358. package/dist/tools/utils/shell.js +37 -0
  359. package/dist/tools/utils/summarizeShellOutput.d.ts.map +1 -1
  360. package/dist/tools/utils/summarizeShellOutput.js +2 -0
  361. package/dist/user-input/index.d.ts +2 -0
  362. package/dist/user-input/index.d.ts.map +1 -0
  363. package/dist/user-input/index.js +1 -0
  364. package/dist/user-input/types.d.ts +19 -0
  365. package/dist/user-input/types.d.ts.map +1 -0
  366. package/dist/user-input/types.js +1 -0
  367. package/dist/web/assets/highlighted-body-OFNGDK62-BuJOCQJD.js +1 -0
  368. package/dist/web/assets/highlighted-body-OFNGDK62-TwhCqUaJ.js +1 -0
  369. package/dist/web/assets/index-B6Bc6sUJ.css +1 -0
  370. package/dist/web/assets/index-BC99-iZC.js +341 -0
  371. package/dist/web/assets/index-BZN9jSiw.js +341 -0
  372. package/dist/web/assets/index-CcF0unjO.css +1 -0
  373. package/dist/web/index.html +2 -2
  374. package/package.json +2 -1
@@ -1,7 +1,12 @@
1
1
  import { createId } from "@paralleldrive/cuid2";
2
2
  import { assistantMessageToAgentMessage } from "../agent/assistantMessageToAgentMessage.js";
3
+ import { createGoalContinuationPrompt, normalizeGoalObjective, } from "../goals/index.js";
3
4
  import { createCodingAssistantAgent, } from "../app/createCodingAssistantAgent.js";
5
+ import { createCodeReviewPrompt } from "../review/index.js";
6
+ import { mergeMcpTools } from "../mcp/index.js";
7
+ import { DEFAULT_PERMISSION_MODE, parsePermissionMode, } from "../permissions/index.js";
4
8
  import { generateSessionTitle } from "./generateSessionTitle.js";
9
+ import { createGoalTitle } from "./createGoalTitle.js";
5
10
  import { getProviderIdForModel } from "./getProviderIdForModel.js";
6
11
  import { resolveInitialModelSelection } from "./resolveInitialModelSelection.js";
7
12
  import { SessionEventLog } from "./SessionEventLog.js";
@@ -14,24 +19,34 @@ export class InMemorySession {
14
19
  #agentMetadata;
15
20
  #agentId;
16
21
  #createEventId;
22
+ #createRuntime;
23
+ #contextMessages;
17
24
  #draining;
18
25
  #effort;
26
+ #goal;
19
27
  #instructions;
20
28
  #interruption;
21
29
  #lastMessageAt;
22
30
  #messages = [];
31
+ #mcpLoaded = false;
32
+ #mcpServers = [];
33
+ #mcpToolProvider;
23
34
  #modelCatalog;
24
35
  #modelId;
25
36
  #models;
37
+ #nextTaskId = 1;
26
38
  #now;
27
39
  #partialPositions = new Set();
40
+ #pendingUserInputs = new Map();
28
41
  #persistence;
29
42
  #providerId;
43
+ #permissionMode;
30
44
  #queue = [];
31
45
  #request;
32
46
  #restoredActiveRunId;
33
47
  #runtime;
34
48
  #status = "idle";
49
+ #tasks = [];
35
50
  #title;
36
51
  #titleError;
37
52
  #titleStatus = "idle";
@@ -39,7 +54,9 @@ export class InMemorySession {
39
54
  constructor(options) {
40
55
  this.#agentManager = options.agentManager;
41
56
  this.#createEventId = options.createEventId;
57
+ this.#createRuntime = options.createRuntime ?? createCodingAssistantAgent;
42
58
  this.#now = options.now ?? Date.now;
59
+ this.#mcpToolProvider = options.mcpToolProvider;
43
60
  this.#modelCatalog = options.modelCatalog;
44
61
  this.#persistence = options.persistence;
45
62
  this.#request = { ...options.request };
@@ -60,6 +77,9 @@ export class InMemorySession {
60
77
  const selection = resolveInitialModelSelection(this.#modelCatalog, requestedModelId, requestedProviderId);
61
78
  this.#modelId = selection.model.id;
62
79
  this.#providerId = selection.providerId;
80
+ this.#permissionMode = parsePermissionMode(options.restore?.permissionMode ??
81
+ options.request.permissionMode ??
82
+ DEFAULT_PERMISSION_MODE);
63
83
  const requestedEffort = options.restore?.effort ?? options.request.effort;
64
84
  this.#effort =
65
85
  requestedEffort !== undefined &&
@@ -67,6 +87,11 @@ export class InMemorySession {
67
87
  ? requestedEffort
68
88
  : selection.model.defaultThinkingLevel;
69
89
  this.#instructions = options.restore?.instructions ?? options.request.instructions;
90
+ this.#goal = options.restore?.goal === undefined ? undefined : { ...options.restore.goal };
91
+ this.#contextMessages =
92
+ options.restore?.contextMessages === undefined
93
+ ? undefined
94
+ : [...options.restore.contextMessages];
70
95
  this.#models = this.#modelsForProvider(this.#providerId);
71
96
  this.#status = options.restore?.status ?? "idle";
72
97
  this.#lastMessageAt = options.restore?.lastMessageAt;
@@ -76,6 +101,9 @@ export class InMemorySession {
76
101
  this.#titleStatus =
77
102
  options.restore?.titleStatus ??
78
103
  (this.#agentMetadata.description !== undefined ? "ready" : "idle");
104
+ this.#tasks =
105
+ options.restore?.tasks === undefined ? [] : options.restore.tasks.map(cloneTask);
106
+ this.#nextTaskId = options.restore?.nextTaskId ?? nextTaskId(this.#tasks);
79
107
  this.#tools = options.restore?.tools ?? [];
80
108
  this.#interruption = options.restore?.interruption;
81
109
  this.#queue = [...(options.restore?.queuedRuns ?? [])];
@@ -98,6 +126,9 @@ export class InMemorySession {
98
126
  this.emitCreatedEvent();
99
127
  }
100
128
  }
129
+ else {
130
+ this.#continueGoalIfIdle();
131
+ }
101
132
  }
102
133
  abort() {
103
134
  const runId = this.#activeRun?.runId;
@@ -109,6 +140,7 @@ export class InMemorySession {
109
140
  this.#persistence?.deleteQueuedRun(this.id, queued.runId);
110
141
  }
111
142
  this.#queue = [];
143
+ this.#pauseActiveGoal();
112
144
  this.#activeRun?.controller.abort();
113
145
  this.#restoredActiveRunId = undefined;
114
146
  void this.#runtime?.processManager.killAll({ forceAfterMs: 500 });
@@ -174,6 +206,234 @@ export class InMemorySession {
174
206
  });
175
207
  return this.snapshot();
176
208
  }
209
+ changePermissionMode(request) {
210
+ const permissionMode = parsePermissionMode(request.permissionMode);
211
+ this.#permissionMode = permissionMode;
212
+ this.#runtime?.context.permissions?.setMode(permissionMode);
213
+ this.#append("permission_mode_changed", { permissionMode });
214
+ return this.snapshot();
215
+ }
216
+ setGoal(request) {
217
+ if (this.isSubagent()) {
218
+ throw new Error("Goals can only be managed from the primary session.");
219
+ }
220
+ if (this.#goal !== undefined && this.#goal.status !== "complete") {
221
+ throw new Error("This session already has an unfinished goal. Complete or clear it before starting another.");
222
+ }
223
+ const now = this.#now();
224
+ this.#goal = {
225
+ createdAt: now,
226
+ objective: normalizeGoalObjective(request.objective),
227
+ status: "active",
228
+ updatedAt: now,
229
+ };
230
+ this.#lastMessageAt = now;
231
+ this.#append("goal_changed", { goal: { ...this.#goal } });
232
+ if (this.#titleStatus === "idle") {
233
+ this.#title = createGoalTitle(this.#goal.objective);
234
+ this.#titleStatus = "ready";
235
+ this.#append("session_title_changed", {
236
+ status: this.#titleStatus,
237
+ title: this.#title,
238
+ });
239
+ }
240
+ this.#continueGoalIfIdle();
241
+ return { ...this.#goal };
242
+ }
243
+ changeGoalStatus(request, options = {}) {
244
+ if (this.isSubagent()) {
245
+ throw new Error("Goals can only be managed from the primary session.");
246
+ }
247
+ if (this.#goal === undefined) {
248
+ throw new Error("This session does not have a goal.");
249
+ }
250
+ if (request.status === "active" && this.#goal.status === "complete") {
251
+ throw new Error("A completed goal cannot be resumed. Start a new goal instead.");
252
+ }
253
+ this.#goal = { ...this.#goal, status: request.status, updatedAt: this.#now() };
254
+ this.#append("goal_changed", { goal: { ...this.#goal } });
255
+ if (request.status === "active") {
256
+ this.#continueGoalIfIdle();
257
+ }
258
+ else if (options.stopActiveGoalRun !== false) {
259
+ this.#discardQueuedGoalRuns();
260
+ if (this.#activeRun?.kind === "goal") {
261
+ this.#activeRun.controller.abort();
262
+ void this.#runtime?.processManager.killAll({ forceAfterMs: 500 });
263
+ }
264
+ }
265
+ return { ...this.#goal };
266
+ }
267
+ clearGoal() {
268
+ if (this.isSubagent()) {
269
+ throw new Error("Goals can only be managed from the primary session.");
270
+ }
271
+ if (this.#goal === undefined)
272
+ return false;
273
+ this.#goal = undefined;
274
+ this.#discardQueuedGoalRuns();
275
+ if (this.#activeRun?.kind === "goal") {
276
+ this.#activeRun.controller.abort();
277
+ void this.#runtime?.processManager.killAll({ forceAfterMs: 500 });
278
+ }
279
+ this.#append("goal_changed", { goal: null });
280
+ return true;
281
+ }
282
+ goal() {
283
+ return this.#goal === undefined ? undefined : { ...this.#goal };
284
+ }
285
+ requestUserInput(request, options = {}) {
286
+ if (this.isSubagent()) {
287
+ throw new Error("Only the primary session can ask the user a question.");
288
+ }
289
+ if (this.#pendingUserInputs.has(request.requestId)) {
290
+ throw new Error("A user input request with this identifier is already pending.");
291
+ }
292
+ if (isSignalAborted(options.signal)) {
293
+ return Promise.reject(new Error("The user input request was cancelled."));
294
+ }
295
+ const response = new Promise((resolve, reject) => {
296
+ const pending = { request, resolve };
297
+ if (options.signal !== undefined)
298
+ pending.signal = options.signal;
299
+ const onAbort = () => {
300
+ if (this.#pendingUserInputs.get(request.requestId) !== pending)
301
+ return;
302
+ this.#pendingUserInputs.delete(request.requestId);
303
+ this.#append("user_input_resolved", {
304
+ requestId: request.requestId,
305
+ status: "cancelled",
306
+ });
307
+ reject(new Error("The user input request was cancelled."));
308
+ };
309
+ pending.onAbort = onAbort;
310
+ options.signal?.addEventListener("abort", onAbort, { once: true });
311
+ this.#pendingUserInputs.set(request.requestId, pending);
312
+ });
313
+ this.#append("user_input_requested", request);
314
+ if (isSignalAborted(options.signal)) {
315
+ this.#pendingUserInputs.get(request.requestId)?.onAbort?.();
316
+ }
317
+ return response;
318
+ }
319
+ answerUserInput(requestId, response) {
320
+ const pending = this.#pendingUserInputs.get(requestId);
321
+ if (pending === undefined)
322
+ return undefined;
323
+ const responseAnswers = response?.answers;
324
+ if (responseAnswers === null ||
325
+ typeof responseAnswers !== "object" ||
326
+ Array.isArray(responseAnswers)) {
327
+ throw new Error("Choose an answer for every question before continuing.");
328
+ }
329
+ const answers = {};
330
+ for (const question of pending.request.questions) {
331
+ const selected = responseAnswers[question.id];
332
+ if (!Array.isArray(selected) ||
333
+ selected.length === 0 ||
334
+ selected.some((answer) => typeof answer !== "string" || answer.trim() === "")) {
335
+ throw new Error(`Answer the ${question.header} question before continuing.`);
336
+ }
337
+ if (!question.multiSelect && selected.length > 1) {
338
+ throw new Error(`Choose one answer for the ${question.header} question.`);
339
+ }
340
+ answers[question.id] = [...selected];
341
+ }
342
+ this.#pendingUserInputs.delete(requestId);
343
+ if (pending.onAbort !== undefined) {
344
+ pending.signal?.removeEventListener("abort", pending.onAbort);
345
+ }
346
+ const normalizedResponse = { answers };
347
+ this.#append("user_input_resolved", {
348
+ answers,
349
+ requestId,
350
+ status: "answered",
351
+ });
352
+ pending.resolve(normalizedResponse);
353
+ return this.snapshot();
354
+ }
355
+ createTask(request) {
356
+ const task = {
357
+ blockedBy: [],
358
+ blocks: [],
359
+ description: request.description,
360
+ id: String(this.#nextTaskId),
361
+ status: "pending",
362
+ subject: request.subject,
363
+ ...(request.activeForm !== undefined ? { activeForm: request.activeForm } : {}),
364
+ ...(request.metadata !== undefined ? { metadata: { ...request.metadata } } : {}),
365
+ };
366
+ this.#nextTaskId += 1;
367
+ this.#tasks.push(task);
368
+ this.#recordTasksChanged();
369
+ return cloneTask(task);
370
+ }
371
+ getTask(taskId) {
372
+ const task = this.#tasks.find((candidate) => candidate.id === taskId);
373
+ return task === undefined ? undefined : cloneTask(task);
374
+ }
375
+ listTasks() {
376
+ return this.#tasks.map(cloneTask);
377
+ }
378
+ updateTask(taskId, request) {
379
+ const index = this.#tasks.findIndex((candidate) => candidate.id === taskId);
380
+ const existing = this.#tasks[index];
381
+ if (existing === undefined) {
382
+ return { error: "Task not found", success: false, taskId, updatedFields: [] };
383
+ }
384
+ if (request.status === "deleted") {
385
+ this.#tasks.splice(index, 1);
386
+ this.#tasks = this.#tasks.map((task) => ({
387
+ ...task,
388
+ blockedBy: task.blockedBy.filter((dependency) => dependency !== taskId),
389
+ blocks: task.blocks.filter((dependency) => dependency !== taskId),
390
+ }));
391
+ this.#recordTasksChanged();
392
+ return {
393
+ statusChange: { from: existing.status, to: "deleted" },
394
+ success: true,
395
+ taskId,
396
+ updatedFields: ["deleted"],
397
+ };
398
+ }
399
+ const dependencyError = this.#validateTaskDependencies(taskId, request);
400
+ if (dependencyError !== undefined) {
401
+ return { error: dependencyError, success: false, taskId, updatedFields: [] };
402
+ }
403
+ const task = cloneTask(existing);
404
+ const updatedFields = [];
405
+ updateTaskString(task, "subject", request.subject, updatedFields);
406
+ updateTaskString(task, "description", request.description, updatedFields);
407
+ updateTaskString(task, "activeForm", request.activeForm, updatedFields);
408
+ updateTaskString(task, "owner", request.owner, updatedFields);
409
+ if (request.metadata !== undefined) {
410
+ const metadata = { ...task.metadata };
411
+ for (const [key, value] of Object.entries(request.metadata)) {
412
+ if (value === null)
413
+ delete metadata[key];
414
+ else
415
+ metadata[key] = value;
416
+ }
417
+ task.metadata = metadata;
418
+ updatedFields.push("metadata");
419
+ }
420
+ let statusChange;
421
+ if (request.status !== undefined && request.status !== task.status) {
422
+ statusChange = { from: task.status, to: request.status };
423
+ task.status = request.status;
424
+ updatedFields.push("status");
425
+ }
426
+ this.#tasks[index] = task;
427
+ this.#addTaskDependencies(taskId, request, updatedFields);
428
+ if (updatedFields.length > 0)
429
+ this.#recordTasksChanged();
430
+ return {
431
+ success: true,
432
+ taskId,
433
+ updatedFields,
434
+ ...(statusChange !== undefined ? { statusChange } : {}),
435
+ };
436
+ }
177
437
  emitCreatedEvent() {
178
438
  this.#append("session_created", { session: this.snapshot() });
179
439
  }
@@ -185,6 +445,7 @@ export class InMemorySession {
185
445
  this.#activeRun = undefined;
186
446
  this.#restoredActiveRunId = undefined;
187
447
  this.#activePartial = undefined;
448
+ this.#pauseActiveGoal();
188
449
  const interruptedRunIds = [
189
450
  ...(interruption.runId !== undefined ? [interruption.runId] : []),
190
451
  ...this.#queue.map((queued) => queued.runId),
@@ -212,12 +473,39 @@ export class InMemorySession {
212
473
  this.#interruption = undefined;
213
474
  this.#restoredActiveRunId = undefined;
214
475
  this.#messages = [];
476
+ this.#contextMessages = undefined;
215
477
  this.#partialPositions.clear();
216
478
  this.#activePartial = undefined;
479
+ const hadTasks = this.#tasks.length > 0;
480
+ const hadGoal = this.#goal !== undefined;
481
+ this.#goal = undefined;
482
+ this.#tasks = [];
483
+ this.#nextTaskId = 1;
217
484
  this.#persistence?.clearMessages(this.id);
485
+ if (hadTasks)
486
+ this.#recordTasksChanged();
487
+ if (hadGoal)
488
+ this.#append("goal_changed", { goal: null });
218
489
  this.#append("session_reset", { snapshot: this.#agentSnapshot() });
219
490
  return this.snapshot();
220
491
  }
492
+ async compact(signal) {
493
+ if (this.#activeRun !== undefined || this.#queue.length > 0) {
494
+ throw new Error("Wait for the active response to finish before compacting.");
495
+ }
496
+ const previousStatus = this.#status;
497
+ this.#status = "running";
498
+ this.#saveSession();
499
+ try {
500
+ const result = await this.#ensureRuntime().agent.compact(signal);
501
+ this.#syncContextMessages();
502
+ return result;
503
+ }
504
+ finally {
505
+ this.#status = previousStatus;
506
+ this.#saveSession();
507
+ }
508
+ }
221
509
  isSubagent() {
222
510
  return this.#agentMetadata.type === "subagent";
223
511
  }
@@ -231,6 +519,7 @@ export class InMemorySession {
231
519
  ...(this.#instructions !== undefined ? { instructions: this.#instructions } : {}),
232
520
  modelId: this.#modelId,
233
521
  ...(this.#request.apiKey !== undefined ? { apiKey: this.#request.apiKey } : {}),
522
+ permissionMode: this.#permissionMode,
234
523
  };
235
524
  }
236
525
  snapshot() {
@@ -241,6 +530,7 @@ export class InMemorySession {
241
530
  agentId: this.#agentId,
242
531
  cwd: this.#request.cwd,
243
532
  providerId: this.#providerId,
533
+ permissionMode: this.#permissionMode,
244
534
  modelId: this.#modelId,
245
535
  modelLocked: this.#modelLocked(),
246
536
  models: this.#models,
@@ -248,6 +538,10 @@ export class InMemorySession {
248
538
  snapshot,
249
539
  titleStatus: this.#titleStatus,
250
540
  agent: this.agentMetadata(),
541
+ pendingUserInputs: [...this.#pendingUserInputs.values()].map((pending) => pending.request),
542
+ mcpServers: this.#mcpServers,
543
+ tasks: this.listTasks(),
544
+ ...(this.#goal !== undefined ? { goal: { ...this.#goal } } : {}),
251
545
  ...(snapshot.effort !== undefined ? { effort: snapshot.effort } : {}),
252
546
  ...(this.#title !== undefined ? { title: this.#title } : {}),
253
547
  ...(this.#titleError !== undefined ? { titleError: this.#titleError } : {}),
@@ -260,6 +554,7 @@ export class InMemorySession {
260
554
  id: this.id,
261
555
  cwd: this.#request.cwd,
262
556
  providerId: this.#providerId,
557
+ permissionMode: this.#permissionMode,
263
558
  modelId: this.#modelId,
264
559
  ...(this.#effort !== undefined ? { effort: this.#effort } : {}),
265
560
  status: this.#status,
@@ -274,21 +569,33 @@ export class InMemorySession {
274
569
  }
275
570
  state() {
276
571
  const activeRunId = this.#activeRun?.runId ?? this.#restoredActiveRunId;
572
+ const runtimeSnapshot = this.#runtime?.agent.snapshot();
573
+ const contextMessages = runtimeSnapshot?.contextMessages === undefined
574
+ ? this.#contextMessages
575
+ : [
576
+ ...runtimeSnapshot.contextMessages,
577
+ ...runtimeSnapshot.queue.map((queued) => queued.message),
578
+ ];
277
579
  const state = {
278
580
  agent: this.agentMetadata(),
279
581
  agentId: this.#agentId,
280
582
  cwd: this.#request.cwd,
583
+ ...(contextMessages !== undefined ? { contextMessages: [...contextMessages] } : {}),
281
584
  ...(this.#effort !== undefined ? { effort: this.#effort } : {}),
282
585
  id: this.id,
283
586
  ...(this.#instructions !== undefined ? { instructions: this.#instructions } : {}),
587
+ ...(this.#goal !== undefined ? { goal: { ...this.#goal } } : {}),
284
588
  ...(this.#interruption !== undefined ? { interruption: this.#interruption } : {}),
285
589
  ...(this.#lastMessageAt !== undefined ? { lastMessageAt: this.#lastMessageAt } : {}),
286
590
  messages: [...this.#messages],
287
591
  modelId: this.#modelId,
288
592
  models: this.#models,
289
593
  providerId: this.#providerId,
594
+ permissionMode: this.#permissionMode,
290
595
  queuedRuns: [...this.#queue],
596
+ nextTaskId: this.#nextTaskId,
291
597
  status: this.#status,
598
+ tasks: this.listTasks(),
292
599
  ...(this.#title !== undefined ? { title: this.#title } : {}),
293
600
  ...(this.#titleError !== undefined ? { titleError: this.#titleError } : {}),
294
601
  titleStatus: this.#titleStatus,
@@ -303,15 +610,25 @@ export class InMemorySession {
303
610
  const runId = createId();
304
611
  const displayText = request.displayText ?? request.text;
305
612
  const blocks = request.content ?? [
306
- { type: "text", text: request.text },
613
+ { type: "text", text: createCodeReviewPrompt(request.text) ?? request.text },
307
614
  ];
308
615
  const userMessage = {
309
616
  role: "user",
310
617
  id: createId(),
311
618
  blocks,
312
619
  };
620
+ const visibleMessage = {
621
+ role: "user",
622
+ id: userMessage.id,
623
+ blocks: blocks.some((block) => block.type === "image")
624
+ ? blocks
625
+ : displayText.length > 0
626
+ ? [{ type: "text", text: displayText }]
627
+ : [],
628
+ };
313
629
  const queued = {
314
630
  displayText,
631
+ kind: "user",
315
632
  runId,
316
633
  text: request.text,
317
634
  userMessage,
@@ -321,10 +638,11 @@ export class InMemorySession {
321
638
  this.#persistence?.insertQueuedRun(this.id, queued);
322
639
  this.#status = this.#activeRun === undefined ? "queued" : "running";
323
640
  this.#lastMessageAt = this.#now();
324
- this.#storeMessage(this.#messages.length, userMessage, false, runId);
641
+ this.#separateModelContextFromVisibleTranscript();
642
+ this.#storeMessage(this.#messages.length, visibleMessage, false, runId);
325
643
  const event = this.#append("message_submitted", {
326
644
  displayText,
327
- message: userMessage,
645
+ message: visibleMessage,
328
646
  runId,
329
647
  });
330
648
  this.#startTitleGeneration(request.text);
@@ -335,6 +653,39 @@ export class InMemorySession {
335
653
  sessionId: this.id,
336
654
  };
337
655
  }
656
+ steer(request) {
657
+ const activeRun = this.#activeRun;
658
+ if (activeRun === undefined) {
659
+ throw new Error("There is no active run to steer.");
660
+ }
661
+ const displayText = request.displayText ?? request.text;
662
+ const blocks = request.content ?? [
663
+ { type: "text", text: request.text },
664
+ ];
665
+ const userMessage = {
666
+ role: "user",
667
+ id: createId(),
668
+ blocks,
669
+ };
670
+ const agent = this.#ensureRuntime().agent;
671
+ if (agent.status === "running")
672
+ agent.steerMessage(userMessage);
673
+ else
674
+ agent.enqueueMessage(userMessage);
675
+ this.#interruption = undefined;
676
+ this.#lastMessageAt = this.#now();
677
+ this.#storeMessage(this.#messages.length, userMessage, false, activeRun.runId);
678
+ const event = this.#append("message_submitted", {
679
+ displayText,
680
+ message: userMessage,
681
+ runId: activeRun.runId,
682
+ });
683
+ return {
684
+ eventId: event.id,
685
+ runId: activeRun.runId,
686
+ sessionId: this.id,
687
+ };
688
+ }
338
689
  subagentSummary() {
339
690
  if (this.#agentMetadata.type !== "subagent" ||
340
691
  this.#agentMetadata.parentSessionId === undefined) {
@@ -352,6 +703,9 @@ export class InMemorySession {
352
703
  ? { parentToolCallId: this.#agentMetadata.parentToolCallId }
353
704
  : {}),
354
705
  status: this.#status,
706
+ ...(this.#agentMetadata.taskName !== undefined
707
+ ? { taskName: this.#agentMetadata.taskName }
708
+ : {}),
355
709
  updatedAt: this.events.lastCreatedAt() ?? this.#now(),
356
710
  };
357
711
  }
@@ -386,6 +740,13 @@ export class InMemorySession {
386
740
  queue: runtimeSnapshot?.queue ?? [],
387
741
  tools: this.#tools,
388
742
  ...(this.#effort !== undefined ? { effort: this.#effort } : {}),
743
+ ...((runtimeSnapshot?.contextMessages ?? this.#contextMessages) !== undefined
744
+ ? {
745
+ contextMessages: [
746
+ ...(runtimeSnapshot?.contextMessages ?? this.#contextMessages ?? []),
747
+ ],
748
+ }
749
+ : {}),
389
750
  ...(this.#instructions !== undefined ? { instructions: this.#instructions } : {}),
390
751
  ...(runtimeSnapshot?.lastRunId !== undefined
391
752
  ? { lastRunId: runtimeSnapshot.lastRunId }
@@ -401,6 +762,65 @@ export class InMemorySession {
401
762
  }
402
763
  return "idle";
403
764
  }
765
+ #validateTaskDependencies(taskId, request) {
766
+ for (const dependency of [...(request.addBlocks ?? []), ...(request.addBlockedBy ?? [])]) {
767
+ if (dependency === taskId)
768
+ return "A task cannot depend on itself.";
769
+ if (!this.#tasks.some((task) => task.id === dependency)) {
770
+ return `Task ${dependency} was not found.`;
771
+ }
772
+ }
773
+ return undefined;
774
+ }
775
+ #addTaskDependencies(taskId, request, updatedFields) {
776
+ const task = this.#tasks.find((candidate) => candidate.id === taskId);
777
+ if (task === undefined)
778
+ return;
779
+ for (const blockedTaskId of request.addBlocks ?? []) {
780
+ const blockedTask = this.#tasks.find((candidate) => candidate.id === blockedTaskId);
781
+ if (blockedTask === undefined)
782
+ continue;
783
+ if (!task.blocks.includes(blockedTaskId)) {
784
+ task.blocks = [...task.blocks, blockedTaskId];
785
+ pushUnique(updatedFields, "blocks");
786
+ }
787
+ if (!blockedTask.blockedBy.includes(taskId)) {
788
+ blockedTask.blockedBy = [...blockedTask.blockedBy, taskId];
789
+ }
790
+ }
791
+ for (const blockingTaskId of request.addBlockedBy ?? []) {
792
+ const blockingTask = this.#tasks.find((candidate) => candidate.id === blockingTaskId);
793
+ if (blockingTask === undefined)
794
+ continue;
795
+ if (!task.blockedBy.includes(blockingTaskId)) {
796
+ task.blockedBy = [...task.blockedBy, blockingTaskId];
797
+ pushUnique(updatedFields, "blockedBy");
798
+ }
799
+ if (!blockingTask.blocks.includes(taskId)) {
800
+ blockingTask.blocks = [...blockingTask.blocks, taskId];
801
+ }
802
+ }
803
+ }
804
+ #recordTasksChanged() {
805
+ this.#append("tasks_changed", { tasks: this.listTasks() });
806
+ }
807
+ async #ensureMcpTools(runtime) {
808
+ if (this.#mcpLoaded)
809
+ return;
810
+ if (this.#mcpToolProvider === undefined) {
811
+ this.#mcpLoaded = true;
812
+ return;
813
+ }
814
+ const loaded = await this.#mcpToolProvider.load(this.#request.cwd);
815
+ const merged = mergeMcpTools(runtime.agent.tools, loaded);
816
+ runtime.agent.setTools(merged.tools);
817
+ this.#tools = runtime.agent.tools.map((tool) => tool.name);
818
+ this.#mcpServers = merged.servers;
819
+ this.#mcpLoaded = true;
820
+ if (merged.servers.length > 0) {
821
+ this.#append("mcp_servers_changed", { servers: merged.servers });
822
+ }
823
+ }
404
824
  #append(type, data) {
405
825
  const event = {
406
826
  createdAt: this.#now(),
@@ -478,24 +898,48 @@ export class InMemorySession {
478
898
  cwd: this.#request.cwd,
479
899
  messages: this.#committedMessages(),
480
900
  modelId: this.#modelId,
901
+ permissionMode: this.#permissionMode,
481
902
  providerId: this.#providerId,
903
+ userInput: {
904
+ request: (request, requestOptions) => this.requestUserInput(request, requestOptions),
905
+ },
906
+ tasks: {
907
+ create: (request) => this.#taskSession().createTask(request),
908
+ get: (taskId) => this.#taskSession().getTask(taskId),
909
+ list: () => this.#taskSession().listTasks(),
910
+ update: (taskId, request) => this.#taskSession().updateTask(taskId, request),
911
+ },
482
912
  };
913
+ if (!this.isSubagent()) {
914
+ options.goals = {
915
+ create: (request) => this.setGoal(request),
916
+ get: () => this.goal(),
917
+ update: (status) => this.changeGoalStatus({ status }, { stopActiveGoalRun: false }),
918
+ };
919
+ }
920
+ if (this.#contextMessages !== undefined) {
921
+ options.contextMessages = this.#contextMessages;
922
+ }
483
923
  if (this.#effort !== undefined)
484
924
  options.effort = this.#effort;
485
925
  if (this.#instructions !== undefined)
486
926
  options.instructions = this.#instructions;
487
927
  if (this.#request.apiKey !== undefined)
488
928
  options.apiKey = this.#request.apiKey;
489
- if (this.#agentManager !== undefined) {
929
+ const agentManager = this.#agentManager;
930
+ if (agentManager !== undefined) {
490
931
  options.subagents = {
491
- canSpawn: this.#agentMetadata.depth < this.#agentManager.maxDepth,
932
+ canSpawn: this.#agentMetadata.depth < agentManager.maxDepth,
492
933
  depth: this.#agentMetadata.depth,
493
- maxDepth: this.#agentManager.maxDepth,
494
- spawn: (request, signal) => this.#agentManager?.spawn(this.id, request, signal) ??
495
- Promise.reject(new Error("Subagent management is unavailable.")),
934
+ followUp: (target, message) => agentManager.followUp(this.id, target, message),
935
+ interrupt: (target) => agentManager.interrupt(this.id, target),
936
+ list: (pathPrefix) => agentManager.list(this.id, pathPrefix),
937
+ maxDepth: agentManager.maxDepth,
938
+ spawn: (request, signal) => agentManager.spawn(this.id, request, signal),
939
+ wait: (timeoutMs, signal) => agentManager.wait(this.id, timeoutMs, signal),
496
940
  };
497
941
  }
498
- const runtime = createCodingAssistantAgent(options);
942
+ const runtime = this.#createRuntime(options);
499
943
  const snapshot = runtime.agent.snapshot();
500
944
  this.#runtime = runtime;
501
945
  this.#agentId = snapshot.id;
@@ -508,6 +952,9 @@ export class InMemorySession {
508
952
  this.#saveSession();
509
953
  return runtime;
510
954
  }
955
+ #taskSession() {
956
+ return this.#agentManager?.taskSession(this.id) ?? this;
957
+ }
511
958
  async #drainQueue() {
512
959
  for (;;) {
513
960
  const queued = this.#queue.shift();
@@ -525,6 +972,16 @@ export class InMemorySession {
525
972
  #saveSession() {
526
973
  this.#persistence?.saveSession(this.state());
527
974
  }
975
+ #separateModelContextFromVisibleTranscript() {
976
+ if (this.#contextMessages !== undefined)
977
+ return;
978
+ const runtimeSnapshot = this.#runtime?.agent.snapshot();
979
+ this.#contextMessages = [
980
+ ...(runtimeSnapshot?.contextMessages ??
981
+ runtimeSnapshot?.messages ??
982
+ this.#committedMessages()),
983
+ ];
984
+ }
528
985
  #completionForRun(runId) {
529
986
  const events = this.events.since(undefined) ?? [];
530
987
  for (let index = events.length - 1; index >= 0; index -= 1) {
@@ -592,13 +1049,18 @@ export class InMemorySession {
592
1049
  }
593
1050
  async #runQueued(queued) {
594
1051
  const controller = new AbortController();
595
- this.#activeRun = { controller, runId: queued.runId };
1052
+ this.#activeRun = { controller, kind: queued.kind, runId: queued.runId };
596
1053
  this.#restoredActiveRunId = undefined;
597
1054
  this.#status = "running";
598
1055
  this.#append("run_started", { runId: queued.runId });
599
1056
  try {
600
1057
  const runtime = this.#ensureRuntime();
1058
+ await this.#ensureMcpTools(runtime);
601
1059
  runtime.agent.enqueueMessage(queued.userMessage);
1060
+ if (this.#contextMessages !== undefined) {
1061
+ this.#contextMessages = [...this.#contextMessages, queued.userMessage];
1062
+ this.#saveSession();
1063
+ }
602
1064
  const result = await runtime.agent.run({
603
1065
  signal: controller.signal,
604
1066
  onEvent: (event) => this.#appendAgentEvent(queued.runId, event),
@@ -608,6 +1070,9 @@ export class InMemorySession {
608
1070
  return;
609
1071
  }
610
1072
  this.#appendRunFinished(queued.runId, result);
1073
+ if (result.stopReason !== "aborted" && result.stopReason !== "error") {
1074
+ this.#continueGoalIfIdle();
1075
+ }
611
1076
  }
612
1077
  catch (error) {
613
1078
  if (this.#activeRun?.runId !== queued.runId) {
@@ -615,6 +1080,7 @@ export class InMemorySession {
615
1080
  }
616
1081
  this.#status = "error";
617
1082
  this.#activePartial = undefined;
1083
+ this.#pauseActiveGoal();
618
1084
  if (this.#activeRun?.runId === queued.runId) {
619
1085
  this.#activeRun = undefined;
620
1086
  }
@@ -627,9 +1093,16 @@ export class InMemorySession {
627
1093
  if (this.#activeRun?.runId === queued.runId) {
628
1094
  this.#activeRun = undefined;
629
1095
  }
1096
+ this.#syncContextMessages();
630
1097
  this.#saveSession();
631
1098
  }
632
1099
  }
1100
+ #syncContextMessages() {
1101
+ const snapshot = this.#runtime?.agent.snapshot();
1102
+ if (snapshot !== undefined) {
1103
+ this.#contextMessages = [...(snapshot.contextMessages ?? snapshot.messages)];
1104
+ }
1105
+ }
633
1106
  #startDrainQueue() {
634
1107
  if (this.#draining !== undefined) {
635
1108
  return;
@@ -638,6 +1111,54 @@ export class InMemorySession {
638
1111
  this.#draining = undefined;
639
1112
  });
640
1113
  }
1114
+ #continueGoalIfIdle() {
1115
+ if (this.isSubagent() ||
1116
+ this.#goal?.status !== "active" ||
1117
+ this.#restoredActiveRunId !== undefined ||
1118
+ this.#status === "running" ||
1119
+ this.#activeRun !== undefined ||
1120
+ this.#queue.length > 0) {
1121
+ return;
1122
+ }
1123
+ const runId = createId();
1124
+ const text = createGoalContinuationPrompt(this.#goal);
1125
+ const userMessage = {
1126
+ blocks: [{ type: "text", text }],
1127
+ id: createId(),
1128
+ role: "user",
1129
+ };
1130
+ const queued = {
1131
+ displayText: "Continuing active goal",
1132
+ kind: "goal",
1133
+ runId,
1134
+ text,
1135
+ userMessage,
1136
+ };
1137
+ this.#queue.push(queued);
1138
+ this.#persistence?.insertQueuedRun(this.id, queued);
1139
+ this.#status = "queued";
1140
+ this.#saveSession();
1141
+ this.#startDrainQueue();
1142
+ }
1143
+ #discardQueuedGoalRuns() {
1144
+ const goalRunIds = this.#queue
1145
+ .filter((queued) => queued.kind === "goal")
1146
+ .map((queued) => queued.runId);
1147
+ if (goalRunIds.length === 0)
1148
+ return;
1149
+ this.#queue = this.#queue.filter((queued) => queued.kind !== "goal");
1150
+ for (const runId of goalRunIds)
1151
+ this.#persistence?.deleteQueuedRun(this.id, runId);
1152
+ if (this.#activeRun === undefined && this.#queue.length === 0)
1153
+ this.#status = "idle";
1154
+ this.#saveSession();
1155
+ }
1156
+ #pauseActiveGoal() {
1157
+ if (this.#goal?.status !== "active")
1158
+ return;
1159
+ this.#goal = { ...this.#goal, status: "paused", updatedAt: this.#now() };
1160
+ this.#append("goal_changed", { goal: { ...this.#goal } });
1161
+ }
641
1162
  #storeMessage(position, message, isPartial, runId) {
642
1163
  const entry = {
643
1164
  isPartial,
@@ -674,3 +1195,30 @@ export class InMemorySession {
674
1195
  this.#storeMessage(position, message, true, runId);
675
1196
  }
676
1197
  }
1198
+ function isSignalAborted(signal) {
1199
+ return signal?.aborted === true;
1200
+ }
1201
+ function cloneTask(task) {
1202
+ return {
1203
+ ...task,
1204
+ blockedBy: [...task.blockedBy],
1205
+ blocks: [...task.blocks],
1206
+ ...(task.metadata !== undefined ? { metadata: { ...task.metadata } } : {}),
1207
+ };
1208
+ }
1209
+ function nextTaskId(tasks) {
1210
+ return (tasks.reduce((highest, task) => {
1211
+ const value = Number.parseInt(task.id, 10);
1212
+ return Number.isSafeInteger(value) ? Math.max(highest, value) : highest;
1213
+ }, 0) + 1);
1214
+ }
1215
+ function updateTaskString(task, key, value, updatedFields) {
1216
+ if (value === undefined || task[key] === value)
1217
+ return;
1218
+ task[key] = value;
1219
+ updatedFields.push(key);
1220
+ }
1221
+ function pushUnique(values, value) {
1222
+ if (!values.includes(value))
1223
+ values.push(value);
1224
+ }