@prestyj/cli 5.33.0 → 5.35.0

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 (327) hide show
  1. package/README.md +18 -18
  2. package/assets/motion/skills/source-ingest/SKILL.md +1 -1
  3. package/dist/app-sidecar/app-settings.js +3 -0
  4. package/dist/app-sidecar/app-settings.js.map +1 -1
  5. package/dist/app-sidecar/autopilot-runner.d.ts +7 -0
  6. package/dist/app-sidecar/autopilot-runner.js +79 -19
  7. package/dist/app-sidecar/autopilot-runner.js.map +1 -1
  8. package/dist/app-sidecar/live-preview/dev-url.d.ts +32 -0
  9. package/dist/app-sidecar/live-preview/dev-url.js +97 -0
  10. package/dist/app-sidecar/live-preview/dev-url.js.map +1 -0
  11. package/dist/app-sidecar/live-preview/frame-server.d.ts +31 -0
  12. package/dist/app-sidecar/live-preview/frame-server.js +193 -0
  13. package/dist/app-sidecar/live-preview/frame-server.js.map +1 -0
  14. package/dist/app-sidecar/live-preview/manager.d.ts +44 -0
  15. package/dist/app-sidecar/live-preview/manager.js +215 -0
  16. package/dist/app-sidecar/live-preview/manager.js.map +1 -0
  17. package/dist/app-sidecar/live-preview/proxy.d.ts +30 -0
  18. package/dist/app-sidecar/live-preview/proxy.js +235 -0
  19. package/dist/app-sidecar/live-preview/proxy.js.map +1 -0
  20. package/dist/app-sidecar/live-preview/routes.d.ts +4 -0
  21. package/dist/app-sidecar/live-preview/routes.js +52 -0
  22. package/dist/app-sidecar/live-preview/routes.js.map +1 -0
  23. package/dist/app-sidecar/live-preview/servers.d.ts +36 -0
  24. package/dist/app-sidecar/live-preview/servers.js +228 -0
  25. package/dist/app-sidecar/live-preview/servers.js.map +1 -0
  26. package/dist/app-sidecar/mcp-routes.js +9 -0
  27. package/dist/app-sidecar/mcp-routes.js.map +1 -1
  28. package/dist/app-sidecar/mcp-shell-command.d.ts +36 -0
  29. package/dist/app-sidecar/mcp-shell-command.js +302 -0
  30. package/dist/app-sidecar/mcp-shell-command.js.map +1 -0
  31. package/dist/app-sidecar/mcp-sync.d.ts +18 -0
  32. package/dist/app-sidecar/mcp-sync.js +38 -0
  33. package/dist/app-sidecar/mcp-sync.js.map +1 -0
  34. package/dist/app-sidecar/nolan-context.js +1 -1
  35. package/dist/app-sidecar/nolan-context.js.map +1 -1
  36. package/dist/app-sidecar/prompt-routes.js +31 -26
  37. package/dist/app-sidecar/prompt-routes.js.map +1 -1
  38. package/dist/app-sidecar/route-context.d.ts +3 -1
  39. package/dist/app-sidecar/run-control-routes.js +8 -1
  40. package/dist/app-sidecar/run-control-routes.js.map +1 -1
  41. package/dist/app-sidecar/shell-routes.js +7 -0
  42. package/dist/app-sidecar/shell-routes.js.map +1 -1
  43. package/dist/app-sidecar/task-routes.js +1 -1
  44. package/dist/app-sidecar/task-routes.js.map +1 -1
  45. package/dist/app-sidecar/workspace-routes.js +35 -37
  46. package/dist/app-sidecar/workspace-routes.js.map +1 -1
  47. package/dist/app-sidecar.js +136 -38
  48. package/dist/app-sidecar.js.map +1 -1
  49. package/dist/cli/mcp.js +19 -5
  50. package/dist/cli/mcp.js.map +1 -1
  51. package/dist/cli/shared.js +4 -0
  52. package/dist/cli/shared.js.map +1 -1
  53. package/dist/cli.js +16 -4
  54. package/dist/cli.js.map +1 -1
  55. package/dist/config.js +2 -0
  56. package/dist/config.js.map +1 -1
  57. package/dist/core/agent-session/mcp-tools.d.ts +20 -1
  58. package/dist/core/agent-session/mcp-tools.js +34 -2
  59. package/dist/core/agent-session/mcp-tools.js.map +1 -1
  60. package/dist/core/agent-session/verification-tracker.js +2 -10
  61. package/dist/core/agent-session/verification-tracker.js.map +1 -1
  62. package/dist/core/agent-session.d.ts +30 -0
  63. package/dist/core/agent-session.js +205 -14
  64. package/dist/core/agent-session.js.map +1 -1
  65. package/dist/core/agents.d.ts +2 -12
  66. package/dist/core/agents.js +5 -1
  67. package/dist/core/agents.js.map +1 -1
  68. package/dist/core/ask-user.d.ts +2 -0
  69. package/dist/core/ask-user.js +8 -1
  70. package/dist/core/ask-user.js.map +1 -1
  71. package/dist/core/autopilot-cycle.js +1 -1
  72. package/dist/core/autopilot-cycle.js.map +1 -1
  73. package/dist/core/autopilot-gate.js +3 -3
  74. package/dist/core/autopilot-gate.js.map +1 -1
  75. package/dist/core/checklist-items.d.ts +2 -2
  76. package/dist/core/checklist-items.js +14 -2
  77. package/dist/core/checklist-items.js.map +1 -1
  78. package/dist/core/checklist-prompt.d.ts +1 -1
  79. package/dist/core/checklist-prompt.js +1 -1
  80. package/dist/core/claude-code/complete.d.ts +2 -0
  81. package/dist/core/claude-code/complete.js +3 -0
  82. package/dist/core/claude-code/complete.js.map +1 -1
  83. package/dist/core/claude-code/transcripts.d.ts +29 -0
  84. package/dist/core/claude-code/transcripts.js +117 -0
  85. package/dist/core/claude-code/transcripts.js.map +1 -0
  86. package/dist/core/codex-request-shape.js +1 -1
  87. package/dist/core/compaction/compactor.d.ts +2 -0
  88. package/dist/core/compaction/compactor.js +7 -3
  89. package/dist/core/compaction/compactor.js.map +1 -1
  90. package/dist/core/compaction/plan-step-policy.d.ts +1 -1
  91. package/dist/core/compaction/plan-step-policy.js +1 -1
  92. package/dist/core/compaction/policy.js +3 -2
  93. package/dist/core/compaction/policy.js.map +1 -1
  94. package/dist/core/compaction/tool-result-pruner.d.ts +12 -2
  95. package/dist/core/compaction/tool-result-pruner.js +14 -3
  96. package/dist/core/compaction/tool-result-pruner.js.map +1 -1
  97. package/dist/core/extensions/plugin-bundles.d.ts +0 -9
  98. package/dist/core/extensions/plugin-bundles.js +0 -185
  99. package/dist/core/extensions/plugin-bundles.js.map +1 -1
  100. package/dist/core/goals-store.d.ts +0 -2
  101. package/dist/core/goals-store.js +0 -5
  102. package/dist/core/goals-store.js.map +1 -1
  103. package/dist/core/live-preview.d.ts +24 -0
  104. package/dist/core/live-preview.js +76 -0
  105. package/dist/core/live-preview.js.map +1 -0
  106. package/dist/core/mcp/client.d.ts +19 -0
  107. package/dist/core/mcp/client.js +60 -5
  108. package/dist/core/mcp/client.js.map +1 -1
  109. package/dist/core/mcp/deferred-catalog.d.ts +7 -1
  110. package/dist/core/mcp/deferred-catalog.js +6 -2
  111. package/dist/core/mcp/deferred-catalog.js.map +1 -1
  112. package/dist/core/mcp/index.d.ts +1 -1
  113. package/dist/core/mcp/index.js.map +1 -1
  114. package/dist/core/mcp/oauth-provider.d.ts +7 -1
  115. package/dist/core/mcp/oauth-provider.js +11 -4
  116. package/dist/core/mcp/oauth-provider.js.map +1 -1
  117. package/dist/core/mcp/oauth-store.d.ts +6 -0
  118. package/dist/core/mcp/oauth-store.js +14 -0
  119. package/dist/core/mcp/oauth-store.js.map +1 -1
  120. package/dist/core/mcp/parse-add-command.d.ts +29 -3
  121. package/dist/core/mcp/parse-add-command.js +196 -26
  122. package/dist/core/mcp/parse-add-command.js.map +1 -1
  123. package/dist/core/mcp/store.d.ts +16 -0
  124. package/dist/core/mcp/store.js +28 -0
  125. package/dist/core/mcp/store.js.map +1 -1
  126. package/dist/core/mcp/types.d.ts +9 -0
  127. package/dist/core/nolan-ask-answer.d.ts +24 -0
  128. package/dist/core/nolan-ask-answer.js +96 -0
  129. package/dist/core/nolan-ask-answer.js.map +1 -0
  130. package/dist/core/nolan-context.d.ts +21 -1
  131. package/dist/core/nolan-context.js +55 -0
  132. package/dist/core/nolan-context.js.map +1 -1
  133. package/dist/core/nolan-prompt.d.ts +1 -1
  134. package/dist/core/nolan-prompt.js +14 -7
  135. package/dist/core/nolan-prompt.js.map +1 -1
  136. package/dist/core/opencode-catalog-store.d.ts +20 -0
  137. package/dist/core/opencode-catalog-store.js +82 -0
  138. package/dist/core/opencode-catalog-store.js.map +1 -0
  139. package/dist/core/package-cooldown.d.ts +0 -2
  140. package/dist/core/package-cooldown.js +0 -4
  141. package/dist/core/package-cooldown.js.map +1 -1
  142. package/dist/core/process-manager.d.ts +1 -1
  143. package/dist/core/process-manager.js +1 -1
  144. package/dist/core/prompt-commands.js +83 -44
  145. package/dist/core/prompt-commands.js.map +1 -1
  146. package/dist/core/runtime-mode.d.ts +0 -8
  147. package/dist/core/runtime-mode.js.map +1 -1
  148. package/dist/core/session-history.d.ts +2 -1
  149. package/dist/core/session-history.js +20 -4
  150. package/dist/core/session-history.js.map +1 -1
  151. package/dist/core/session-manager.d.ts +5 -0
  152. package/dist/core/session-manager.js +12 -7
  153. package/dist/core/session-manager.js.map +1 -1
  154. package/dist/core/session-storage.d.ts +0 -2
  155. package/dist/core/session-storage.js +0 -2
  156. package/dist/core/session-storage.js.map +1 -1
  157. package/dist/core/settings-manager.d.ts +2 -0
  158. package/dist/core/settings-manager.js +3 -1
  159. package/dist/core/settings-manager.js.map +1 -1
  160. package/dist/core/shell-path.d.ts +2 -0
  161. package/dist/core/shell-path.js +10 -1
  162. package/dist/core/shell-path.js.map +1 -1
  163. package/dist/core/skills.d.ts +2 -0
  164. package/dist/core/skills.js +5 -0
  165. package/dist/core/skills.js.map +1 -1
  166. package/dist/core/subagent-policy.js +1 -1
  167. package/dist/core/subagent-policy.js.map +1 -1
  168. package/dist/core/task-store.d.ts +0 -1
  169. package/dist/core/task-store.js +0 -3
  170. package/dist/core/task-store.js.map +1 -1
  171. package/dist/core/trophies/catalog-more.js +5 -5
  172. package/dist/core/trophies/catalog-more.js.map +1 -1
  173. package/dist/core/trophies/catalog.js +3 -3
  174. package/dist/core/trophies/catalog.js.map +1 -1
  175. package/dist/core/trophies/engine.js +1 -1
  176. package/dist/core/trophies/engine.js.map +1 -1
  177. package/dist/modes/acp-mode.d.ts +1 -1
  178. package/dist/modes/acp-mode.js +1 -1
  179. package/dist/modes/acp-mode.js.map +1 -1
  180. package/dist/motion-agent/motion-agent.d.ts +1 -1
  181. package/dist/motion-agent/motion-agent.js +1 -1
  182. package/dist/motion-agent/motion-agent.js.map +1 -1
  183. package/dist/motion-agent/motion-review.d.ts +0 -75
  184. package/dist/motion-agent/motion-review.js +0 -189
  185. package/dist/motion-agent/motion-review.js.map +1 -1
  186. package/dist/system-prompt.d.ts +5 -1
  187. package/dist/system-prompt.js +16 -8
  188. package/dist/system-prompt.js.map +1 -1
  189. package/dist/test-support/system-tools.d.ts +6 -0
  190. package/dist/test-support/system-tools.js +36 -0
  191. package/dist/test-support/system-tools.js.map +1 -0
  192. package/dist/tools/ask-user.js +3 -2
  193. package/dist/tools/ask-user.js.map +1 -1
  194. package/dist/tools/bash.d.ts +2 -2
  195. package/dist/tools/bash.js +363 -358
  196. package/dist/tools/bash.js.map +1 -1
  197. package/dist/tools/browser-api.d.ts +27 -0
  198. package/dist/tools/browser-api.js +449 -0
  199. package/dist/tools/browser-api.js.map +1 -0
  200. package/dist/tools/browser-sandbox.d.ts +16 -0
  201. package/dist/tools/browser-sandbox.js +158 -0
  202. package/dist/tools/browser-sandbox.js.map +1 -0
  203. package/dist/tools/browser-session.d.ts +69 -0
  204. package/dist/tools/browser-session.js +220 -0
  205. package/dist/tools/browser-session.js.map +1 -0
  206. package/dist/tools/browser-snapshot.d.ts +19 -0
  207. package/dist/tools/browser-snapshot.js +109 -0
  208. package/dist/tools/browser-snapshot.js.map +1 -0
  209. package/dist/tools/browser.d.ts +11 -0
  210. package/dist/tools/browser.js +106 -0
  211. package/dist/tools/browser.js.map +1 -0
  212. package/dist/tools/goals.d.ts +3 -3
  213. package/dist/tools/html-extract.d.ts +1 -1
  214. package/dist/tools/html-extract.js +1 -1
  215. package/dist/tools/index.d.ts +4 -1
  216. package/dist/tools/index.js +6 -3
  217. package/dist/tools/index.js.map +1 -1
  218. package/dist/tools/live-preview.d.ts +21 -0
  219. package/dist/tools/live-preview.js +37 -0
  220. package/dist/tools/live-preview.js.map +1 -0
  221. package/dist/tools/path-utils.d.ts +0 -15
  222. package/dist/tools/path-utils.js +0 -17
  223. package/dist/tools/path-utils.js.map +1 -1
  224. package/dist/tools/prompt-hints.js +3 -2
  225. package/dist/tools/prompt-hints.js.map +1 -1
  226. package/dist/tools/subagent-shared.d.ts +3 -4
  227. package/dist/tools/subagent-shared.js +8 -9
  228. package/dist/tools/subagent-shared.js.map +1 -1
  229. package/dist/tools/tool-tiers.d.ts +1 -1
  230. package/dist/tools/tool-tiers.js +2 -2
  231. package/dist/tools/tool-tiers.js.map +1 -1
  232. package/dist/tools/truncate.d.ts +0 -2
  233. package/dist/tools/truncate.js +0 -2
  234. package/dist/tools/truncate.js.map +1 -1
  235. package/dist/tools/web-fetch.d.ts +7 -1
  236. package/dist/tools/web-fetch.js +15 -4
  237. package/dist/tools/web-fetch.js.map +1 -1
  238. package/dist/ui/App.d.ts +2 -1
  239. package/dist/ui/App.js +0 -1
  240. package/dist/ui/App.js.map +1 -1
  241. package/dist/ui/app-items.d.ts +0 -2
  242. package/dist/ui/app-items.js +0 -2
  243. package/dist/ui/app-items.js.map +1 -1
  244. package/dist/ui/components/ActivityIndicator.d.ts +1 -1
  245. package/dist/ui/components/AnimationContext.d.ts +1 -1
  246. package/dist/ui/components/AssistantMessage.d.ts +1 -1
  247. package/dist/ui/components/BackgroundTasksBar.d.ts +2 -1
  248. package/dist/ui/components/Banner.d.ts +2 -1
  249. package/dist/ui/components/ChatFooterPane.d.ts +2 -1
  250. package/dist/ui/components/ChatInputStack.d.ts +1 -1
  251. package/dist/ui/components/ChatLayout.d.ts +4 -4
  252. package/dist/ui/components/ChatLivePane.d.ts +1 -1
  253. package/dist/ui/components/ChatScreen.d.ts +1 -1
  254. package/dist/ui/components/ChatStatusRow.d.ts +1 -1
  255. package/dist/ui/components/CompactionNotice.d.ts +3 -2
  256. package/dist/ui/components/DiffFrame.d.ts +1 -1
  257. package/dist/ui/components/DiffView.d.ts +2 -1
  258. package/dist/ui/components/Footer.d.ts +2 -1
  259. package/dist/ui/components/Footer.js +4 -4
  260. package/dist/ui/components/Footer.js.map +1 -1
  261. package/dist/ui/components/FooterStatusRow.d.ts +2 -1
  262. package/dist/ui/components/FullScreenOverlayRouter.d.ts +2 -1
  263. package/dist/ui/components/GoalOverlay.d.ts +2 -1
  264. package/dist/ui/components/GoalStatusBar.d.ts +2 -1
  265. package/dist/ui/components/IdealHookMessage.d.ts +1 -1
  266. package/dist/ui/components/InputArea.d.ts +1 -1
  267. package/dist/ui/components/LiveToolPanel.d.ts +2 -1
  268. package/dist/ui/components/Markdown.d.ts +2 -2
  269. package/dist/ui/components/ModelSelector.d.ts +2 -1
  270. package/dist/ui/components/ModelSelector.js +2 -0
  271. package/dist/ui/components/ModelSelector.js.map +1 -1
  272. package/dist/ui/components/Overlay.d.ts +1 -1
  273. package/dist/ui/components/PixelOverlay.d.ts +2 -1
  274. package/dist/ui/components/PlanModeLogo.d.ts +2 -1
  275. package/dist/ui/components/PlanOverlay.d.ts +3 -2
  276. package/dist/ui/components/QueueIndicator.d.ts +2 -1
  277. package/dist/ui/components/RewindOverlay.d.ts +2 -1
  278. package/dist/ui/components/SelectList.d.ts +2 -1
  279. package/dist/ui/components/ServerToolExecution.d.ts +2 -1
  280. package/dist/ui/components/SessionSelector.d.ts +2 -1
  281. package/dist/ui/components/SessionSummary.d.ts +2 -1
  282. package/dist/ui/components/SettingsSelector.d.ts +2 -1
  283. package/dist/ui/components/SkillsOverlay.d.ts +2 -1
  284. package/dist/ui/components/SlashCommandMenu.d.ts +2 -1
  285. package/dist/ui/components/SlashStyledSelectList.d.ts +2 -1
  286. package/dist/ui/components/Spinner.d.ts +2 -1
  287. package/dist/ui/components/StreamingArea.d.ts +1 -1
  288. package/dist/ui/components/SubAgentPanel.d.ts +2 -1
  289. package/dist/ui/components/TaskOverlay.d.ts +2 -1
  290. package/dist/ui/components/TaskPickerMenu.d.ts +2 -1
  291. package/dist/ui/components/ThemeSelector.d.ts +2 -1
  292. package/dist/ui/components/ThinkingBlock.d.ts +1 -1
  293. package/dist/ui/components/ToolExecution.d.ts +2 -1
  294. package/dist/ui/components/ToolGroupExecution.d.ts +2 -1
  295. package/dist/ui/components/TranscriptViewport.d.ts +1 -1
  296. package/dist/ui/components/UserMessage.d.ts +2 -1
  297. package/dist/ui/constants/figures.d.ts +0 -8
  298. package/dist/ui/constants/figures.js +0 -8
  299. package/dist/ui/constants/figures.js.map +1 -1
  300. package/dist/ui/layout-decisions.d.ts +0 -5
  301. package/dist/ui/layout-decisions.js +1 -10
  302. package/dist/ui/layout-decisions.js.map +1 -1
  303. package/dist/ui/terminal-history-status-renderers.d.ts +0 -1
  304. package/dist/ui/terminal-history-status-renderers.js +0 -12
  305. package/dist/ui/terminal-history-status-renderers.js.map +1 -1
  306. package/dist/ui/tool-line-summary.js +1 -0
  307. package/dist/ui/tool-line-summary.js.map +1 -1
  308. package/dist/ui/transcript/MiscRows.d.ts +8 -7
  309. package/dist/ui/transcript/StatusRow.d.ts +1 -1
  310. package/dist/ui/transcript/ToolRows.d.ts +7 -6
  311. package/dist/ui/transcript/TranscriptItemFrame.d.ts +1 -1
  312. package/dist/ui/transcript/presentation.d.ts +1 -2
  313. package/dist/ui/transcript/presentation.js +0 -4
  314. package/dist/ui/transcript/presentation.js.map +1 -1
  315. package/dist/utils/image.d.ts +0 -4
  316. package/dist/utils/image.js +0 -10
  317. package/dist/utils/image.js.map +1 -1
  318. package/dist/web.d.ts +5 -0
  319. package/dist/web.js +5 -0
  320. package/dist/web.js.map +1 -0
  321. package/package.json +13 -5
  322. package/dist/motion-agent/motion-review-gate.d.ts +0 -48
  323. package/dist/motion-agent/motion-review-gate.js +0 -88
  324. package/dist/motion-agent/motion-review-gate.js.map +0 -1
  325. package/dist/tools/screenshot.d.ts +0 -24
  326. package/dist/tools/screenshot.js +0 -161
  327. package/dist/tools/screenshot.js.map +0 -1
@@ -11,6 +11,7 @@ import { type BlockedSkill, type Skill } from "./skills.js";
11
11
  import type { BackgroundProcess } from "./process-manager.js";
12
12
  import { type ChildModelPick, type SubAgentSnapshot } from "./subagent-manager.js";
13
13
  import type { MCPElicitHandler } from "./mcp/index.js";
14
+ import type { MCPServerConfig } from "./mcp/types.js";
14
15
  import { type ContextLimits } from "./context-limits.js";
15
16
  import { type ImportForeignTranscriptResult } from "./foreign-session-import.js";
16
17
  import { type CacheExpiryStatus } from "./cache-expiry.js";
@@ -51,6 +52,15 @@ export declare class PaidModelConfirmationError extends Error {
51
52
  /** A chat attachment (image / video / other file) prepared for the model. The
52
53
  * raw base64 `data` rides native blocks; `path` (when persisted to disk) lets
53
54
  * the agent's tools open the file directly. */
55
+ /** What applying one MCP config change did in a session. */
56
+ export interface McpServerChange {
57
+ name: string;
58
+ removed: boolean;
59
+ connected: boolean;
60
+ toolCount: number;
61
+ error?: string;
62
+ requiresAuth?: boolean;
63
+ }
54
64
  export interface SessionAttachment {
55
65
  kind: "image" | "video" | "file";
56
66
  mediaType: string;
@@ -428,6 +438,7 @@ export declare class AgentSession {
428
438
  private lspManager?;
429
439
  private testImpact?;
430
440
  private debugManager?;
441
+ private browserManager?;
431
442
  private subAgentManager?;
432
443
  /**
433
444
  * Out-of-band push notifications (finished children, background-process
@@ -527,6 +538,8 @@ export declare class AgentSession {
527
538
  */
528
539
  /** Commands the user ran themselves, held until their next message. */
529
540
  private pendingUserShell;
541
+ /** MCP servers the user added or removed mid-session, not yet told to the model. */
542
+ private pendingMcpNotices;
530
543
  private persistedTranscriptCount;
531
544
  /** Current leaf entry ID in the session DAG — used to chain parentIds for branching. */
532
545
  private currentLeafId;
@@ -563,6 +576,18 @@ export declare class AgentSession {
563
576
  * turn, so background-connected servers become available on the next prompt.
564
577
  */
565
578
  private connectMcpServers;
579
+ /**
580
+ * The user added, changed or removed one MCP server mid-session: connect,
581
+ * reconnect or drop just that server, without a restart. `config` is its
582
+ * current effective config, or undefined when it is gone (or not allowed).
583
+ *
584
+ * Append-only for the prompt cache: new tools go into the tool_search
585
+ * catalog (or are appended when deferral is off), and the model learns about
586
+ * the change from a hidden note with the next message, never from a
587
+ * re-rendered system prompt. Returns null when nothing changed here.
588
+ */
589
+ applyMcpServerChange(name: string, config: MCPServerConfig | undefined): Promise<McpServerChange | null>;
590
+ private takeMcpNotice;
566
591
  /** Persist `cwd` as a trusted project for project-scope MCP. Called by the
567
592
  * sidecar's `/mcp/add` handler when a user adds a project-scope server via
568
593
  * the MCP modal — the explicit add is itself the trust signal. The next
@@ -625,6 +650,7 @@ export declare class AgentSession {
625
650
  private claudeCodeProcess;
626
651
  /** Append a deferred built-in to the live tool list (append-only). */
627
652
  private promoteDeferredBuiltin;
653
+ private reloadUsedTools;
628
654
  private wrapToPromote;
629
655
  /**
630
656
  * Publish cached tool definitions into the deferred catalog so `tool_search`
@@ -824,6 +850,7 @@ export declare class AgentSession {
824
850
  * compaction/plan-step-policy.ts says the shrink pays for itself.
825
851
  */
826
852
  private maybeCompactPostTurn;
853
+ private withLiveAccessToken;
827
854
  compact(existingCredentials?: {
828
855
  accessToken: string;
829
856
  accountId?: string;
@@ -1239,6 +1266,9 @@ export declare class AgentSession {
1239
1266
  private prewarmController;
1240
1267
  /** Claude Code session that has seen this history (Claude subscription route). */
1241
1268
  private claudeCodeSession;
1269
+ private releaseClaudeCodeTranscript;
1270
+ /** Keep the retention pass off the transcript this chat would resume. */
1271
+ private holdClaudeCodeTranscript;
1242
1272
  /** This chat's running Claude Code process, reused while `key` (its start settings) matches. */
1243
1273
  private claudeCodeLive;
1244
1274
  /**
@@ -13,12 +13,13 @@ import { loadWorkspaceCustomCommands } from "./custom-commands.js";
13
13
  import { expandPromptCommand } from "./prompt-command-expansion.js";
14
14
  import { SettingsManager } from "./settings-manager.js";
15
15
  import { AuthStorage, NotLoggedInError } from "./auth-storage.js";
16
- import { dualAuthProvider } from "@prestyj/core";
16
+ import { claudeCodeConfigDir, dualAuthProvider } from "@prestyj/core";
17
17
  import { getClaudeCliUserAgent } from "./claude-code-version.js";
18
+ import { claudeCodeTranscriptExists, holdClaudeCodeTranscript, pruneClaudeCodeTranscriptsOnce, } from "./claude-code/transcripts.js";
18
19
  import { runSideWebSearch, runSideWebSearchViaClaudeCode, SIDE_SEARCH_MODEL, } from "../tools/side-web-search.js";
19
20
  import { kimiCodingHeaders, isKimiCodingEndpoint } from "./oauth/kimi.js";
20
21
  import { isGrokCliEndpoint } from "./oauth/xai.js";
21
- import { SessionManager, } from "./session-manager.js";
22
+ import { SessionManager, processIsAlive, } from "./session-manager.js";
22
23
  import { ExtensionLoader } from "./extensions/loader.js";
23
24
  import { shouldCompact, compact, } from "./compaction/compactor.js";
24
25
  import { getHistoryMessageVisibility } from "./session-history.js";
@@ -344,6 +345,7 @@ export class AgentSession {
344
345
  lspManager;
345
346
  testImpact;
346
347
  debugManager;
348
+ browserManager;
347
349
  subAgentManager;
348
350
  /**
349
351
  * Out-of-band push notifications (finished children, background-process
@@ -446,6 +448,8 @@ export class AgentSession {
446
448
  */
447
449
  /** Commands the user ran themselves, held until their next message. */
448
450
  pendingUserShell = [];
451
+ /** MCP servers the user added or removed mid-session, not yet told to the model. */
452
+ pendingMcpNotices = [];
449
453
  persistedTranscriptCount() {
450
454
  return this.messages.slice(0, this.lastPersistedIndex).filter((m) => m.role !== "system")
451
455
  .length;
@@ -561,7 +565,7 @@ export class AgentSession {
561
565
  : this.opts.globalSubagents
562
566
  ? await discoverAgents({ globalAgentsDir: paths.agentsDir })
563
567
  : [];
564
- const { tools: builtInTools, processManager, rebuildReadTool, clearReadTracker, recordBashReads, lspManager, testImpact, debugManager, subAgentManager, } = await createTools(this.cwd, {
568
+ const { tools: builtInTools, processManager, rebuildReadTool, clearReadTracker, recordBashReads, lspManager, testImpact, debugManager, browserManager, subAgentManager, } = await createTools(this.cwd, {
565
569
  agents,
566
570
  shareWorkspaceRoots: this.opts.shareRootsWithSubAgents,
567
571
  defaultSubAgent: this.opts.defaultSubAgent,
@@ -677,7 +681,7 @@ export class AgentSession {
677
681
  this.tools = core;
678
682
  this.deferredBuiltinToolNames = deferred.map((t) => t.name);
679
683
  this.deferredToolCatalog = [...deferred];
680
- this.mcp.addDeferred(deferred);
684
+ this.mcp.addDeferred(deferred, { builtin: true });
681
685
  }
682
686
  }
683
687
  this.rebuildReadTool = rebuildReadTool;
@@ -687,6 +691,7 @@ export class AgentSession {
687
691
  this.lspManager = lspManager;
688
692
  this.testImpact = testImpact;
689
693
  this.debugManager = debugManager;
694
+ this.browserManager = browserManager;
690
695
  this.subAgentManager = subAgentManager;
691
696
  this.bindManagerCancellation(this.opts.signal);
692
697
  // Connect MCP servers. Child sessions skip user-configured servers to avoid
@@ -756,6 +761,7 @@ export class AgentSession {
756
761
  message: error instanceof Error ? error.message : String(error),
757
762
  });
758
763
  });
764
+ void pruneClaudeCodeTranscriptsOnce(claudeCodeConfigDir());
759
765
  }
760
766
  // EZ Coder owns its command registry. Other agents start with an isolated
761
767
  // empty registry and can register their own commands in their own file.
@@ -881,7 +887,9 @@ export class AgentSession {
881
887
  // empty catalog and tool_search would answer "the catalog is empty" for
882
888
  // capabilities that genuinely exist — a wrong answer, not a slow one.
883
889
  await this.seedMcpCatalogFromCache(servers);
884
- const connected = await mcpManager.connectAll(servers);
890
+ const results = await mcpManager.connectAllDetailed(servers);
891
+ this.mcp.recordServers(servers, results);
892
+ const connected = results.flatMap((r) => r.tools);
885
893
  // Defense-in-depth: even from a whitelisted server, only push tools that
886
894
  // pass the allow-list (no-op when there's no allow-list).
887
895
  const mcpTools = this.opts.allowedTools
@@ -907,6 +915,80 @@ export class AgentSession {
907
915
  log("WARN", "mcp", `MCP initialization failed: ${err instanceof Error ? err.message : String(err)}`);
908
916
  }
909
917
  }
918
+ /**
919
+ * The user added, changed or removed one MCP server mid-session: connect,
920
+ * reconnect or drop just that server, without a restart. `config` is its
921
+ * current effective config, or undefined when it is gone (or not allowed).
922
+ *
923
+ * Append-only for the prompt cache: new tools go into the tool_search
924
+ * catalog (or are appended when deferral is off), and the model learns about
925
+ * the change from a hidden note with the next message, never from a
926
+ * re-rendered system prompt. Returns null when nothing changed here.
927
+ */
928
+ async applyMcpServerChange(name, config) {
929
+ const manager = this.mcp.manager;
930
+ if (!manager)
931
+ return null;
932
+ const whitelist = this.opts.allowedMcpServers;
933
+ if (this.opts.allowedTools && !whitelist?.includes(name))
934
+ return null;
935
+ const wanted = config && config.enabled !== false ? config : undefined;
936
+ const previous = this.mcp.serverState(name);
937
+ // Same config still connected: nothing to do. Same config that failed
938
+ // (e.g. before an OAuth sign-in) is retried.
939
+ if (wanted && previous?.ok && previous.config === JSON.stringify(wanted))
940
+ return null;
941
+ if (!wanted && !previous)
942
+ return null;
943
+ if (previous) {
944
+ await manager.disconnect(name);
945
+ this.mcp.removeServer(name);
946
+ }
947
+ if (!wanted) {
948
+ this.pendingMcpNotices.push(`- MCP server "${name}" was removed by the user. Its mcp__${name}__* tools no longer work; don't call them.`);
949
+ log("INFO", "mcp", `Removed MCP server "${name}" mid-session`);
950
+ return { name, removed: true, connected: false, toolCount: 0 };
951
+ }
952
+ const [result] = await manager.connectAllDetailed([wanted]);
953
+ const ok = result?.ok ?? false;
954
+ this.mcp.recordServers([wanted], result ? [result] : []);
955
+ const tools = (result?.tools ?? []).filter((t) => !this.opts.allowedTools || this.isToolAllowed(t.name));
956
+ this.addMcpTools(tools);
957
+ if (ok) {
958
+ const deferred = !this.opts.allowedTools && this.settingsManager.get("deferredMcpTools");
959
+ const names = tools.map((t) => t.name);
960
+ const shown = names.slice(0, 20).join(", ") + (names.length > 20 ? ", …" : "");
961
+ this.pendingMcpNotices.push(`- The user connected MCP server "${name}" with ${tools.length} tool${tools.length === 1 ? "" : "s"}` +
962
+ (names.length > 0 ? `: ${shown}.` : ".") +
963
+ (deferred
964
+ ? " Load them with tool_search (e.g. by capability or the server name) when they help."
965
+ : " They are in your tool list now."));
966
+ }
967
+ log("INFO", "mcp", `Applied MCP server "${name}" mid-session`, {
968
+ ok: String(ok),
969
+ tools: String(tools.length),
970
+ });
971
+ return {
972
+ name,
973
+ removed: false,
974
+ connected: ok,
975
+ toolCount: tools.length,
976
+ ...(result?.error ? { error: result.error } : {}),
977
+ ...(result?.requiresAuth ? { requiresAuth: true } : {}),
978
+ };
979
+ }
980
+ takeMcpNotice() {
981
+ if (this.pendingMcpNotices.length === 0)
982
+ return null;
983
+ const lines = this.pendingMcpNotices.splice(0);
984
+ return {
985
+ role: "user",
986
+ provenance: { source: "runtime", kind: "notification", visibility: "hidden" },
987
+ content: "MCP update. The user changed MCP servers during this session:\n" +
988
+ lines.join("\n") +
989
+ "\nTrust this over anything earlier that disagrees. Do not restate this note; just proceed.",
990
+ };
991
+ }
910
992
  /** Persist `cwd` as a trusted project for project-scope MCP. Called by the
911
993
  * sidecar's `/mcp/add` handler when a user adds a project-scope server via
912
994
  * the MCP modal — the explicit add is itself the trust signal. The next
@@ -1069,7 +1151,14 @@ export class AgentSession {
1069
1151
  /** One run on the Claude subscription route: Claude Code drives the loop with our prompt and tools. */
1070
1152
  async runClaudeCodeLoop(process, options) {
1071
1153
  let loopMessages = await this.prepareDynamicContext();
1072
- const resume = claudeCodeResumeId(this.claudeCodeSession, loopMessages);
1154
+ let resume = claudeCodeResumeId(this.claudeCodeSession, loopMessages);
1155
+ // Claude Code fails a resume whose transcript is gone (retention pass, or
1156
+ // removed by hand); our history can seed a fresh session instead.
1157
+ if (resume &&
1158
+ !(await claudeCodeTranscriptExists(process.env.CLAUDE_CONFIG_DIR ?? claudeCodeConfigDir(), resume))) {
1159
+ log("INFO", "claude-code", "Transcript missing; seeding a fresh session from history");
1160
+ resume = undefined;
1161
+ }
1073
1162
  // A fresh Claude Code session gets our history as text; summarize it first
1074
1163
  // when it would not fit.
1075
1164
  if (!resume &&
@@ -1135,6 +1224,35 @@ export class AgentSession {
1135
1224
  policy: CLAUDE_CODE_CACHE_TTL,
1136
1225
  });
1137
1226
  }
1227
+ // Same line names as the public-API route, which logs them from the agent loop.
1228
+ if (event.type === "turn_end") {
1229
+ const cacheRead = event.usage.cacheRead ?? 0;
1230
+ const cacheWrite = event.usage.cacheWrite ?? 0;
1231
+ const promptTokens = event.usage.inputTokens + cacheRead + cacheWrite;
1232
+ log("INFO", "stream", "cache_health", {
1233
+ promptTokens,
1234
+ cacheRead,
1235
+ cacheWrite,
1236
+ ...(promptTokens > 0
1237
+ ? { ratio: Math.round((cacheRead / promptTokens) * 100) / 100 }
1238
+ : {}),
1239
+ ...(event.timing.ttftMs !== undefined ? { ttftMs: event.timing.ttftMs } : {}),
1240
+ providerDurationMs: event.timing.providerDurationMs,
1241
+ outputTokens: event.usage.outputTokens,
1242
+ provider: this.provider,
1243
+ model: this.model,
1244
+ transport: "claude_code",
1245
+ });
1246
+ }
1247
+ else if (event.type === "retry") {
1248
+ log("INFO", "stream", "retry", {
1249
+ reason: event.reason,
1250
+ attempt: event.attempt,
1251
+ maxAttempts: event.maxAttempts,
1252
+ delayMs: event.delayMs,
1253
+ transport: "claude_code",
1254
+ });
1255
+ }
1138
1256
  this.eventBus.forwardAgentEvent(event);
1139
1257
  }
1140
1258
  }
@@ -1202,6 +1320,7 @@ export class AgentSession {
1202
1320
  const history = this.messages.filter((m) => m.role !== "system");
1203
1321
  const state = { sessionId, messageCount: history.length, anchor: history.at(-1) };
1204
1322
  this.claudeCodeSession = state;
1323
+ this.holdClaudeCodeTranscript();
1205
1324
  if (!this.sessionPath)
1206
1325
  return;
1207
1326
  await this.sessionManager.appendEntry(this.sessionPath, {
@@ -1229,6 +1348,26 @@ export class AgentSession {
1229
1348
  this.tools.push(tool);
1230
1349
  return tool;
1231
1350
  }
1351
+ // A restored conversation still calls the on-demand tools it used; Claude
1352
+ // Code refuses any name missing from the list this process gives it.
1353
+ reloadUsedTools(messages) {
1354
+ if (this.deferredBuiltinToolNames.length === 0)
1355
+ return;
1356
+ for (const message of messages) {
1357
+ if (message.role === "assistant" && Array.isArray(message.content)) {
1358
+ for (const part of message.content) {
1359
+ if (part.type === "tool_call")
1360
+ this.promoteDeferredBuiltin(part.name);
1361
+ }
1362
+ }
1363
+ else if (message.role === "tool") {
1364
+ for (const result of message.content) {
1365
+ for (const name of result.loadedTools ?? [])
1366
+ this.promoteDeferredBuiltin(name);
1367
+ }
1368
+ }
1369
+ }
1370
+ }
1232
1371
  wrapToPromote(trigger, followUps, when = () => true) {
1233
1372
  const index = this.tools.findIndex((t) => t.name === trigger);
1234
1373
  const tool = index >= 0 ? this.tools[index] : undefined;
@@ -1651,6 +1790,7 @@ export class AgentSession {
1651
1790
  if (planNotice) {
1652
1791
  log("INFO", "session", "Injecting plan state update instead of rebuilding the prompt");
1653
1792
  }
1793
+ const mcpNotice = this.takeMcpNotice();
1654
1794
  if (environmentDelta) {
1655
1795
  // The model has now been told; only a further change re-triggers this.
1656
1796
  this.renderedEnvironment = this.promptEnvironment();
@@ -1722,15 +1862,17 @@ export class AgentSession {
1722
1862
  return [
1723
1863
  ...(environmentDelta ? [environmentDelta] : []),
1724
1864
  ...(planNotice ? [planNotice] : []),
1865
+ ...(mcpNotice ? [mcpNotice] : []),
1725
1866
  ...(userShell ? [userShell] : []),
1726
1867
  ...steeringMessages,
1727
1868
  ...(notificationMessage ? [notificationMessage] : []),
1728
1869
  ];
1729
1870
  }
1730
- if (environmentDelta || planNotice || notificationMessage) {
1871
+ if (environmentDelta || planNotice || mcpNotice || notificationMessage) {
1731
1872
  return [
1732
1873
  ...(environmentDelta ? [environmentDelta] : []),
1733
1874
  ...(planNotice ? [planNotice] : []),
1875
+ ...(mcpNotice ? [mcpNotice] : []),
1734
1876
  ...(notificationMessage ? [notificationMessage] : []),
1735
1877
  ];
1736
1878
  }
@@ -2406,7 +2548,7 @@ export class AgentSession {
2406
2548
  if (shouldPruneToolResults(activeTokens, policy.targetTokens)) {
2407
2549
  const cacheCold = this.getCacheExpiryStatus()?.expired ?? false;
2408
2550
  const pruneResult = pruneStaleToolResults(messages, {
2409
- minimumTokens: pruneMinimumTokens(activeTokens, cacheCold),
2551
+ minimumTokens: pruneMinimumTokens(activeTokens, cacheCold, policy.targetTokens),
2410
2552
  });
2411
2553
  if (pruneResult.pruned) {
2412
2554
  this.cacheDiagnostics.noteEdit("tool_prune", pruneResult.freedTokens);
@@ -2732,11 +2874,13 @@ export class AgentSession {
2732
2874
  const servers = await getAllMcpServers(this.provider, apiKey, this.cwd, {
2733
2875
  allowProjectScope: this.settingsManager.isProjectTrusted(this.cwd),
2734
2876
  });
2735
- const mcpTools = await mcpManager.connectAll(servers);
2877
+ const results = await mcpManager.connectAllDetailed(servers);
2878
+ const mcpTools = results.flatMap((r) => r.tools);
2736
2879
  // Drop stale MCP tools from both the live set and deferred catalog before
2737
2880
  // re-adding. Some tools may already have been promoted out of the catalog.
2738
2881
  this.tools = this.tools.filter((t) => !t.name.startsWith("mcp__"));
2739
2882
  this.mcp.clearMcpTools();
2883
+ this.mcp.recordServers(servers, results);
2740
2884
  this.addMcpTools(mcpTools);
2741
2885
  }
2742
2886
  catch (err) {
@@ -3027,6 +3171,18 @@ export class AgentSession {
3027
3171
  }
3028
3172
  })();
3029
3173
  }
3174
+ // A caller's token was captured at run start; the loop may have rotated it since.
3175
+ async withLiveAccessToken(captured) {
3176
+ try {
3177
+ const live = await this.authStorage.resolveCredentials(this.provider, {
3178
+ storageKeys: this.currentAuthStorageKeys(),
3179
+ });
3180
+ return { ...captured, accessToken: live.accessToken };
3181
+ }
3182
+ catch {
3183
+ return captured;
3184
+ }
3185
+ }
3030
3186
  async compact(existingCredentials, mode = "manual",
3031
3187
  /** User-stated focus (`/compact <focus>`): what must survive verbatim. */
3032
3188
  focus,
@@ -3037,12 +3193,13 @@ export class AgentSession {
3037
3193
  ? AbortSignal.any([this.opts.signal, abortSignal])
3038
3194
  : (abortSignal ?? this.opts.signal);
3039
3195
  const claudeCode = existingCredentials ? null : await this.claudeCodeProcess();
3040
- const creds = existingCredentials ??
3041
- (claudeCode
3196
+ const creds = existingCredentials
3197
+ ? await this.withLiveAccessToken(existingCredentials)
3198
+ : claudeCode
3042
3199
  ? { accessToken: "" }
3043
3200
  : await this.authStorage.resolveCredentials(this.provider, {
3044
3201
  storageKeys: this.currentAuthStorageKeys(),
3045
- }));
3202
+ });
3046
3203
  const contextWindow = getContextWindow(this.model, {
3047
3204
  provider: this.provider,
3048
3205
  accountId: creds.accountId,
@@ -3885,6 +4042,8 @@ export class AgentSession {
3885
4042
  }
3886
4043
  const toolNames = this.tools.map((tool) => tool.name);
3887
4044
  const deferredToolNames = this.deferredToolNamesForPrompt(toolNames);
4045
+ // A missing Claude Code binary fails the run itself with a clear message, not the prompt build.
4046
+ const deferredNeedSearch = deferredToolNames.length > 0 && (await this.claudeCodeProcess().then(Boolean, () => false));
3888
4047
  // Whatever is rendered now is what the model has been told.
3889
4048
  this.announcedLanguages = new Set(this.activeLanguages);
3890
4049
  if (this.agentPrompt !== undefined) {
@@ -3892,6 +4051,7 @@ export class AgentSession {
3892
4051
  cwd: this.cwd,
3893
4052
  toolNames,
3894
4053
  deferredToolNames,
4054
+ deferredNeedSearch,
3895
4055
  context: this.opts.agentContext,
3896
4056
  role: this.opts.agentRole,
3897
4057
  environment: this.recordRenderedEnvironment(),
@@ -3899,7 +4059,7 @@ export class AgentSession {
3899
4059
  ...(this.languagesApply() ? { activeLanguages: this.activeLanguages } : {}),
3900
4060
  });
3901
4061
  }
3902
- return buildSystemPrompt(this.cwd, this.skills, planMode, approvedPlanPath, toolNames, this.activeLanguages, this.provider, this.recordRenderedEnvironment(), deferredToolNames, this.contextLimits);
4062
+ return buildSystemPrompt(this.cwd, this.skills, planMode, approvedPlanPath, toolNames, this.activeLanguages, this.provider, this.recordRenderedEnvironment(), deferredToolNames, this.contextLimits, undefined, deferredNeedSearch);
3903
4063
  }
3904
4064
  /**
3905
4065
  * Bring the system prompt to the exact state the next provider request will
@@ -3928,6 +4088,12 @@ export class AgentSession {
3928
4088
  * update is saved in order with the rest of the conversation.
3929
4089
  */
3930
4090
  async announceNewLanguages() {
4091
+ const mcpNotice = this.takeMcpNotice();
4092
+ if (mcpNotice) {
4093
+ this.messages.push(mcpNotice);
4094
+ await this.persistMessage(mcpNotice);
4095
+ this.lastPersistedIndex = this.messages.length;
4096
+ }
3931
4097
  const planNotice = this.takePlanNotice();
3932
4098
  if (planNotice) {
3933
4099
  this.messages.push(planNotice);
@@ -4229,6 +4395,7 @@ export class AgentSession {
4229
4395
  generation,
4230
4396
  startedAt: new Date().toISOString(),
4231
4397
  afterMessageCount: this.persistedTranscriptCount(),
4398
+ pid: process.pid,
4232
4399
  });
4233
4400
  }
4234
4401
  /** Close the run journal. Its absence is what marks a run as crashed. */
@@ -4358,6 +4525,13 @@ export class AgentSession {
4358
4525
  prewarmController = null;
4359
4526
  /** Claude Code session that has seen this history (Claude subscription route). */
4360
4527
  claudeCodeSession = null;
4528
+ releaseClaudeCodeTranscript;
4529
+ /** Keep the retention pass off the transcript this chat would resume. */
4530
+ holdClaudeCodeTranscript() {
4531
+ this.releaseClaudeCodeTranscript?.();
4532
+ const sessionId = this.claudeCodeSession?.sessionId;
4533
+ this.releaseClaudeCodeTranscript = sessionId ? holdClaudeCodeTranscript(sessionId) : undefined;
4534
+ }
4361
4535
  /** This chat's running Claude Code process, reused while `key` (its start settings) matches. */
4362
4536
  claudeCodeLive = null;
4363
4537
  /**
@@ -4530,6 +4704,8 @@ export class AgentSession {
4530
4704
  // step leaves background commands running after the app has quit.
4531
4705
  this.stopBackgroundProcesses();
4532
4706
  this.installedWatchStop?.();
4707
+ this.releaseClaudeCodeTranscript?.();
4708
+ this.releaseClaudeCodeTranscript = undefined;
4533
4709
  // Quiesce any in-flight post-turn compaction BEFORE tearing down state:
4534
4710
  // the background compact() snapshots and replaces `this.messages`, so
4535
4711
  // letting it run past this point would checkpoint a near-empty history
@@ -4553,7 +4729,11 @@ export class AgentSession {
4553
4729
  this.stopBackgroundProcesses();
4554
4730
  this.lspManager?.shutdownAll();
4555
4731
  this.debugManager?.shutdown();
4556
- await Promise.all([this.subAgentManager?.shutdownAll(), this.mcp.manager?.dispose()]);
4732
+ await Promise.all([
4733
+ this.subAgentManager?.shutdownAll(),
4734
+ this.mcp.manager?.dispose(),
4735
+ this.browserManager?.shutdown(),
4736
+ ]);
4557
4737
  await this.extensionLoader.deactivateAll();
4558
4738
  this.setSessionPath("");
4559
4739
  this.eventBus.removeAllListeners();
@@ -4655,7 +4835,9 @@ export class AgentSession {
4655
4835
  // not fail when Anthropic's stricter many-image limit activates later.
4656
4836
  const systemMsg = this.messages[0]; // Already built
4657
4837
  this.messages = [systemMsg, ...loadedMessages];
4838
+ this.reloadUsedTools(loadedMessages);
4658
4839
  this.claudeCodeSession = parseClaudeCodeSessionState(savedClaudeCode?.type === "custom" ? savedClaudeCode.data : null, loadedMessages);
4840
+ this.holdClaudeCodeTranscript();
4659
4841
  // Reads recorded for the previous conversation don't carry over.
4660
4842
  this.clearReadTracker?.();
4661
4843
  const normalizedImageCount = await normalizeMessageImages(this.messages);
@@ -4748,6 +4930,15 @@ export class AgentSession {
4748
4930
  */
4749
4931
  async recordInterruptedRuns(runs) {
4750
4932
  for (const run of runs) {
4933
+ // Another app has this chat open and is still running it: not a crash.
4934
+ if (run.pid !== undefined && run.pid !== process.pid && processIsAlive(run.pid)) {
4935
+ log("WARN", "session", "Unfinished run belongs to another live process; left open", {
4936
+ generation: String(run.generation),
4937
+ startedAt: run.startedAt,
4938
+ pid: String(run.pid),
4939
+ });
4940
+ continue;
4941
+ }
4751
4942
  log("WARN", "session", "Restored a session with an unfinished run", {
4752
4943
  generation: String(run.generation),
4753
4944
  startedAt: run.startedAt,