openmausbot 0.1.88 → 0.1.90

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 (147) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/{abnfDiagram-O67JEVCF-qd9VD3GV.js → abnfDiagram-O67JEVCF-DUyXd0kL.js} +1 -1
  3. package/dist/assets/{arc-3RwkUjRe.js → arc-q73qM-At.js} +1 -1
  4. package/dist/assets/{architectureDiagram-NJMV4G6O-CFKSJS7a.js → architectureDiagram-NJMV4G6O-D33O3Wur.js} +1 -1
  5. package/dist/assets/{blockDiagram-BEXU5L5S-CG1rEfWD.js → blockDiagram-BEXU5L5S-DLsJeoXC.js} +1 -1
  6. package/dist/assets/{c4Diagram-YGBWAQC7-CBW9N664.js → c4Diagram-YGBWAQC7-DnaljZnu.js} +1 -1
  7. package/dist/assets/channel-BCuyHjFV.js +1 -0
  8. package/dist/assets/{chunk-2Q5K7J3B-2mRfTksB.js → chunk-2Q5K7J3B-Da0h2i79.js} +1 -1
  9. package/dist/assets/{chunk-3FUC2YCW-Cv1dpErj.js → chunk-3FUC2YCW-CfzHi54f.js} +2 -2
  10. package/dist/assets/{chunk-5VM5RSS4-B7IACJp-.js → chunk-5VM5RSS4-LjE4d9Jf.js} +1 -1
  11. package/dist/assets/{chunk-GTNCS2PH-An0hZtYa.js → chunk-GTNCS2PH-DY-UGmvc.js} +1 -1
  12. package/dist/assets/{chunk-GWA4HPMP-BcJB2nEm.js → chunk-GWA4HPMP-BqeGhyhP.js} +1 -1
  13. package/dist/assets/{chunk-JWPE2WC7-CV_W7TN7.js → chunk-JWPE2WC7-BYa9EBAg.js} +1 -1
  14. package/dist/assets/{chunk-NETBCI7D-Bcs_kwnA.js → chunk-NETBCI7D-vTrDtWyb.js} +1 -1
  15. package/dist/assets/{chunk-WEXAMYUT-lrx_DxFP.js → chunk-WEXAMYUT-ic5tXadM.js} +1 -1
  16. package/dist/assets/{chunk-XXDRQBXY-DabHlLGM.js → chunk-XXDRQBXY-DvRCY-c6.js} +1 -1
  17. package/dist/assets/{classDiagram-v2-NBCMYWYE-BnHj6P7d.js → classDiagram-v2-NBCMYWYE-DVbmgz_L.js} +1 -1
  18. package/dist/assets/{cose-bilkent-JH36ORCC-CfLp6UDi.js → cose-bilkent-JH36ORCC-vdUs2n57.js} +1 -1
  19. package/dist/assets/{cynefin-OW5HDTMX-Dm4dbVA1.js → cynefin-OW5HDTMX-BvLGlV3U.js} +1 -1
  20. package/dist/assets/{cynefinDiagram-VND7K2PF-B9mH-PID.js → cynefinDiagram-VND7K2PF-C4GcJQDt.js} +1 -1
  21. package/dist/assets/{dagre-6A5THRUB-DDc_NVQJ.js → dagre-6A5THRUB-BMSaHpt_.js} +1 -1
  22. package/dist/assets/{diagram-22UHCM2B-lwr8Ip8-.js → diagram-22UHCM2B-D5b9UBhC.js} +1 -1
  23. package/dist/assets/{diagram-3UASUU5V-BLLe6dmI.js → diagram-3UASUU5V-CIKLlB7Y.js} +1 -1
  24. package/dist/assets/{diagram-ATOU4E4O-6eUIq4lz.js → diagram-ATOU4E4O-BzXb-7k7.js} +1 -1
  25. package/dist/assets/{diagram-CDSNMT55-O-pRN7VQ.js → diagram-CDSNMT55-HsTvJ7uT.js} +1 -1
  26. package/dist/assets/{diagram-MLGK6HIB-BietvGAI.js → diagram-MLGK6HIB-Db9ySNbQ.js} +1 -1
  27. package/dist/assets/{diagram-MPIPVDR6-Bd2Cl62X.js → diagram-MPIPVDR6-D6BKbpqY.js} +1 -1
  28. package/dist/assets/{ebnfDiagram-ZINNZB2B-B6iDy69W.js → ebnfDiagram-ZINNZB2B-Bq067L0t.js} +1 -1
  29. package/dist/assets/{elk-276RUBZZ-DQVHfKe0.js → elk-276RUBZZ-DhaD7fNJ.js} +1 -1
  30. package/dist/assets/{erDiagram-OPXOYQCR-BWdVp2tQ.js → erDiagram-OPXOYQCR-fwIhfz36.js} +1 -1
  31. package/dist/assets/{flowDiagram-KWPJA3E3-WLE6rKB4.js → flowDiagram-KWPJA3E3-DygIyu0V.js} +1 -1
  32. package/dist/assets/{ganttDiagram-FUAMR5RP-BbjS-4gn.js → ganttDiagram-FUAMR5RP-DPYfSO96.js} +1 -1
  33. package/dist/assets/{gitGraphDiagram-X574FWY7-Dpy2QSGq.js → gitGraphDiagram-X574FWY7-DhkHeCle.js} +1 -1
  34. package/dist/assets/index-CRvo-DS2.css +1 -0
  35. package/dist/assets/index-CWYGlA63.js +588 -0
  36. package/dist/assets/{index-CIaHn5NS.js → index-G1PHKGyh.js} +1 -1
  37. package/dist/assets/{infoDiagram-VRGFBTTK-D_jKWlKe.js → infoDiagram-VRGFBTTK-DstBLxME.js} +1 -1
  38. package/dist/assets/{ishikawaDiagram-OU5B5YK6-DLJohSuK.js → ishikawaDiagram-OU5B5YK6-CrIsGgch.js} +1 -1
  39. package/dist/assets/{journeyDiagram-ZHPQQLJL-DPOFj0qN.js → journeyDiagram-ZHPQQLJL-CYypGDbB.js} +1 -1
  40. package/dist/assets/{kanban-definition-PNTS6WVX-BI7v-xpK.js → kanban-definition-PNTS6WVX-DGjPt8E_.js} +1 -1
  41. package/dist/assets/{linear-C2pWPSxO.js → linear-Dwc3Hrru.js} +1 -1
  42. package/dist/assets/{mermaid.core-CR-j5WQU.js → mermaid.core-Dc4OePBL.js} +5 -5
  43. package/dist/assets/{mindmap-definition-NLK3R4M7-lz9GvXRh.js → mindmap-definition-NLK3R4M7-DV-vepj-.js} +1 -1
  44. package/dist/assets/{pegDiagram-GJSIUBJH-Dl4_ia61.js → pegDiagram-GJSIUBJH-lx5Kj-n5.js} +1 -1
  45. package/dist/assets/{pieDiagram-5QR66LMP-DWuT3n88.js → pieDiagram-5QR66LMP-Bq7Vmm15.js} +1 -1
  46. package/dist/assets/{quadrantDiagram-O4NWA36T-DXWe9Jx7.js → quadrantDiagram-O4NWA36T-DeqeqOBj.js} +1 -1
  47. package/dist/assets/{railroadDiagram-XR7U4H2S-COY1IBVY.js → railroadDiagram-XR7U4H2S-CXwRQzSC.js} +1 -1
  48. package/dist/assets/{requirementDiagram-PLB6GJNP-DnyVuhsQ.js → requirementDiagram-PLB6GJNP-8tAeoB88.js} +1 -1
  49. package/dist/assets/{sankeyDiagram-IPEJSGJF-BSc4NdGK.js → sankeyDiagram-IPEJSGJF-BG5zjGWU.js} +1 -1
  50. package/dist/assets/{sequenceDiagram-PO4LG4MO-kqEU2EGq.js → sequenceDiagram-PO4LG4MO-DKF3iLcw.js} +1 -1
  51. package/dist/assets/{sizeCapture-INFHLROL-BvB4bkWD.js → sizeCapture-INFHLROL-B-y1qUgT.js} +1 -1
  52. package/dist/assets/{stateDiagram-v2-GCMORJYK-BIrqNv7y.js → stateDiagram-v2-GCMORJYK-MkzPgxAc.js} +1 -1
  53. package/dist/assets/{swimlanes-2SLR337P-CFnalQUE.js → swimlanes-2SLR337P-DnbaOEwH.js} +1 -1
  54. package/dist/assets/swimlanesDiagram-TC7HE7FX-BZQ07DGE.js +8 -0
  55. package/dist/assets/{timeline-definition-EJHVYXUP-CsSWJnSQ.js → timeline-definition-EJHVYXUP-Bb4xG_Bt.js} +1 -1
  56. package/dist/assets/{usecaseDiagram-POWQR4AR-DkAmJ1EE.js → usecaseDiagram-POWQR4AR-JgkR9pFf.js} +1 -1
  57. package/dist/assets/{vennDiagram-UO4OBE2U-C3vd9drL.js → vennDiagram-UO4OBE2U-CIPIrAYe.js} +1 -1
  58. package/dist/assets/{wardleyDiagram-VNRHLVJA-j26CM-pi.js → wardleyDiagram-VNRHLVJA-BjCLuUvJ.js} +1 -1
  59. package/dist/assets/{xychartDiagram-PMCCYNJV-BYu1Q_at.js → xychartDiagram-PMCCYNJV-DKgiaYxT.js} +1 -1
  60. package/dist/index.html +2 -2
  61. package/dist-server/cloud-home-start.js +14795 -0
  62. package/dist-server/container-mcp.js +60 -4
  63. package/dist-server/drivers/agents-proxy.js +20 -10
  64. package/dist-server/index.js +48924 -46153
  65. package/dist-server/openmausbot.js +544 -253
  66. package/dist-server/pair-cli.js +544 -253
  67. package/dist-server/permission-proxy.js +1 -1
  68. package/dist-server/server/admission.js +46 -0
  69. package/dist-server/server/automatic-recovery.js +15 -0
  70. package/dist-server/server/{box-create-idempotency.js → boat-create-idempotency.js} +32 -31
  71. package/dist-server/server/{box-delete-journal.js → boat-delete-journal.js} +26 -25
  72. package/dist-server/server/{box.js → boat.js} +330 -328
  73. package/dist-server/server/bot-profile.js +7 -1
  74. package/dist-server/server/channel-queue.js +58 -18
  75. package/dist-server/server/checkpoints.js +98 -52
  76. package/dist-server/server/claim-idle.js +33 -0
  77. package/dist-server/server/cli-api-setup.js +0 -1
  78. package/dist-server/server/cloud-backend.js +5 -5
  79. package/dist-server/server/cloud-home-start.js +103 -0
  80. package/dist-server/server/cloud-home.js +218 -0
  81. package/dist-server/server/cloud-overflow.js +167 -0
  82. package/dist-server/server/composio.js +5 -0
  83. package/dist-server/server/computer-observation.js +2 -2
  84. package/dist-server/server/config.js +124 -6
  85. package/dist-server/server/container-computer.js +23 -0
  86. package/dist-server/server/contracts.js +10 -0
  87. package/dist-server/server/control-client.js +2 -2
  88. package/dist-server/server/delegations.js +11 -3
  89. package/dist-server/server/drivers/acp/core.js +129 -21
  90. package/dist-server/server/drivers/acp/qwen.js +3 -0
  91. package/dist-server/server/drivers/agents-call.js +5 -1
  92. package/dist-server/server/drivers/agents-catalog.js +9 -3
  93. package/dist-server/server/drivers/{boxagent.js → boatagent.js} +14 -13
  94. package/dist-server/server/drivers/builtIn.js +2 -2
  95. package/dist-server/server/drivers/{chat-box-tools.js → chat-boat-tools.js} +3 -3
  96. package/dist-server/server/drivers/chat-mcp-tools.js +2 -2
  97. package/dist-server/server/drivers/claude.js +177 -13
  98. package/dist-server/server/drivers/native.js +1 -1
  99. package/dist-server/server/drivers/openai-chat.js +19 -4
  100. package/dist-server/server/drivers/pi.js +3 -3
  101. package/dist-server/server/harness-capabilities.js +18 -3
  102. package/dist-server/server/hosted-models.js +6 -1
  103. package/dist-server/server/index.js +1163 -530
  104. package/dist-server/server/local-vm-inventory.js +11 -1
  105. package/dist-server/server/local-vm-seat-pool.js +141 -0
  106. package/dist-server/server/managed-policy.js +4 -1
  107. package/dist-server/server/memory-capture.js +194 -0
  108. package/dist-server/server/memory-entries.js +76 -0
  109. package/dist-server/server/memory-organize.js +102 -0
  110. package/dist-server/server/memory-tidy.js +144 -0
  111. package/dist-server/server/memory-topics.js +169 -0
  112. package/dist-server/server/memory-upkeep.js +452 -0
  113. package/dist-server/server/message-db.js +49 -5
  114. package/dist-server/server/permission-proxy.js +3 -3
  115. package/dist-server/server/profile-learned.js +98 -0
  116. package/dist-server/server/profile-versions.js +45 -11
  117. package/dist-server/server/recall.js +172 -0
  118. package/dist-server/server/redact.js +1 -1
  119. package/dist-server/server/room-cwd.js +1 -1
  120. package/dist-server/server/room-handoffs.js +61 -6
  121. package/dist-server/server/routes/bot-memory.js +215 -0
  122. package/dist-server/server/routine-requests.js +27 -16
  123. package/dist-server/server/routines.js +10 -6
  124. package/dist-server/server/steer-queue.js +41 -10
  125. package/dist-server/server/store.js +25 -1
  126. package/dist-server/server/surface.js +1 -1
  127. package/dist-server/server/system-prompt.js +16 -5
  128. package/dist-server/server/team-computers.js +2 -2
  129. package/dist-server/server/tightening-requests.js +34 -4
  130. package/dist-server/server/tool-summary.js +2 -2
  131. package/dist-server/server/tts/elevenlabs.js +1 -1
  132. package/dist-server/server/turn-resources.js +87 -11
  133. package/dist-server/server/vps-computer.js +1 -1
  134. package/dist-server/server/webhooks.js +21 -3
  135. package/dist-server/server/workspace.js +57 -22
  136. package/dist-server/shared/ask-question.js +7 -5
  137. package/dist-server/shared/bot-avatar.js +19 -0
  138. package/dist-server/shared/credential-request.js +3 -3
  139. package/dist-server/shared/tool-surface.js +1 -1
  140. package/dist-server/src/lib/composer-attachments.js +26 -0
  141. package/dist-server/vps-container-mcp.js +60 -4
  142. package/dist-server/workspace-backup.worker.js +60 -4
  143. package/package.json +1 -1
  144. package/dist/assets/channel-CnRnO3tF.js +0 -1
  145. package/dist/assets/index-BIMdIbaw.css +0 -1
  146. package/dist/assets/index-CHnODCr2.js +0 -583
  147. package/dist/assets/swimlanesDiagram-TC7HE7FX-C4a8qNGj.js +0 -8
@@ -22,7 +22,8 @@ import { assertRequestTarget, guardedRequestPath, requestConflict, requestNeedsI
22
22
  import { botAvatarUrlFromStoredPath } from "../shared/bot-avatar.js";
23
23
  import { BOT_PROFILE_LIMITS } from "../shared/bot-profile.js";
24
24
  import { CLOUD_COMPUTER_BUSY_ERROR } from "../shared/computer-contention.js";
25
- import { approvalModeFor, supportsApprovalMode, modelSwitchNeedsAsk, isEmergencyApprovalDowngrade, isApprovalMode, } from "../shared/approval-mode.js";
25
+ import { approvalModeFor, modelSwitchNeedsAsk, isEmergencyApprovalDowngrade, isApprovalMode, } from "../shared/approval-mode.js";
26
+ import { createApprovalModeSupport } from "./harness-capabilities.js";
26
27
  import { escapeAttribute } from "../src/lib/composer-attachments.js";
27
28
  import { CREDENTIAL_TARGETS, credentialResumeOutcome, credentialIsConfigured, isPendingCredentialRequest, isCredentialTargetId, } from "../shared/credential-request.js";
28
29
  import { approvalHeldNote, approvalHeldReason, approvalModeForOrigin, autoVerdict, deliverFullAccessApproval, delegationInheritsFullAccess } from "./auto-approve.js";
@@ -43,20 +44,23 @@ import { avatarGenerationRequestSchema, avatarGenerationStateMatches, generateAv
43
44
  import { fitsOnOneLine, parseBotProfilePatch } from "./bot-profile.js";
44
45
  import { groupTurnCwd } from "./room-cwd.js";
45
46
  import { RoomTurnDeadline, RoomTurnStallRegistry, roomTurnTimeoutMessage } from "./room-turn-timeout.js";
46
- import * as box from "./box.js";
47
+ import * as boat from "./boat.js";
47
48
  import { TeamComputers, teamComputerAssignment, teamComputerCreate, teamComputerOwner } from "./team-computers.js";
48
49
  import { isEffortLevel } from "../shared/wire.js";
49
- import { boxCreateRecoverySnapshot, retireDeletedBoxCreate } from "./box-create-idempotency.js";
50
- import { boxDeletionSnapshot } from "./box-delete-journal.js";
51
- import { boxAccountResourceChangeError, cloudBackendChangeError, vpsAliasResourceChangeError, } from "./cloud-backend.js";
50
+ import { boatCreateRecoverySnapshot, retireDeletedBoatCreate } from "./boat-create-idempotency.js";
51
+ import { boatDeletionSnapshot } from "./boat-delete-journal.js";
52
+ import { boatAccountResourceChangeError, cloudBackendChangeError, vpsAliasResourceChangeError, } from "./cloud-backend.js";
52
53
  import * as composio from "./composio.js";
53
54
  import { connectorCallFromFrame, connectorRefusalText, connectorUnrecognizedText, evaluateConnectorTools } from "./connector-verdict.js";
54
55
  import { chiefOfStaffSystemPrompt } from "./chief-of-staff.js";
56
+ import { buildRecall } from "./recall.js";
57
+ import { createMemoryUpkeep, upkeepEnabled } from "./memory-upkeep.js";
58
+ import { appendAboutMe, commitLearned, planLearned } from "./profile-learned.js";
55
59
  import { canAccessTeam, canReachPeer, coordinatorSupervises, livePeerRoster, livePeerRosterBlock, peerAllowed, peerName, peerRosterSystemPrompt, peerStatus, peerStatusWords, reachablePeers, resolveTeammate, roomPeerRosterSystemPrompt, roomRosterLine, PEER_ACCESS_HELP } from "./peer-roster.js";
56
60
  import { openMausStatusSystemPrompt } from "./openmaus-status-capsule.js";
57
- import { containerComputerAction, containerComputerExists, containerComputerFrame, containerComputerMcp, containerComputerScreenshot, containerComputerStatus, containerExec, containerRuntimeStatus, localVmRecreatableOnDemand, perBotLocalVmTarget, SHARED_LOCAL_VM_TARGET, setupCommands, VM_WORKSPACE_GUEST, } from "./container-computer.js";
61
+ import { containerComputerAction, containerComputerExists, containerComputerFrame, containerComputerMcp, containerComputerScreenshot, containerComputerStatus, containerExec, containerRuntimeStatus, localVmRecreatableOnDemand, localVmWorkspaceExists, perBotLocalVmTarget, poolLocalVmTarget, SHARED_LOCAL_VM_TARGET, setupCommands, VM_WORKSPACE_GUEST, } from "./container-computer.js";
58
62
  import { attachForTurn, saveBotAttachment } from "./bot-attachment.js";
59
- import { ensureDirs, instanceConfigs, loadConfig, providerReloadKeys, localVmMaxInstances, localVmMode, parseConfigPatch, roomTurnTimeoutMinutes, threadEventLogMaxBytes, maxConcurrentBotThreads, threadEventLogRetentionDays, saveConfig, showToolCallsEnabled, claudeUserMcpEnabled, skillAuthoringEnabled, sharedComputersEnabled, builtInBrowserEnabled, llmThreadTitlesEnabled, browserProfileReplacementConflict, browserProfilePartitionTarget, syncCredentialEnv, withInstanceCli, persistableInstanceConfigs, vpsSshAlias, browserEngineAttachCdpUrl, DATA_DIR, EVENTS_DIR, NATIVE_DIR, customMcpServers, roomHandoffLimits, onConfigSaved, } from "./config.js";
63
+ import { ensureDirs, instanceConfigs, loadConfig, providerReloadKeys, localVmMaxInstances, localVmMode, parseConfigPatch, roomTurnTimeoutMinutes, threadEventLogMaxBytes, maxConcurrentBotThreads, threadEventLogRetentionDays, saveConfig, showToolCallsEnabled, routinesInConversationEnabled, claudeUserMcpEnabled, skillAuthoringEnabled, autoRecallEnabled, captureQuietMs, tidyHour, sharedComputersEnabled, builtInBrowserEnabled, llmThreadTitlesEnabled, computerClaimIdleReleaseEnabled, cloudOverflowAllowlistedThreads, cloudOverflowEnabled, cloudOverflowIdleStopMs, cloudOverflowPerSecondCostUsd, browserProfileReplacementConflict, browserProfilePartitionTarget, syncCredentialEnv, withInstanceCli, persistableInstanceConfigs, vpsSshAlias, browserEngineAttachCdpUrl, DATA_DIR, EVENTS_DIR, NATIVE_DIR, customMcpServers, roomHandoffLimits, onConfigSaved, } from "./config.js";
60
64
  import { sweepThreadEventLogs } from "./thread-retention.js";
61
65
  import { ComputerControl } from "./computer-control.js";
62
66
  import { augmentedPath, findCliCandidates, resetPathCache } from "./env-path.js";
@@ -71,8 +75,9 @@ import { entitled } from "./enterprise.js";
71
75
  import { HOSTED_CONTRACT_HEADER, HOSTED_CONTRACT_METADATA, HOSTED_CONTRACT_VERSION } from "./hosted-contract.js";
72
76
  import { describeSpawnFailure, execCli } from "./procs.js";
73
77
  import { blockedTarget, buildNotification, buildSpendNotification } from "./notify.js";
74
- import { isModelVariant, newId, } from "./contracts.js";
78
+ import { isModelVariant, TurnNotStartedError, newId, } from "./contracts.js";
75
79
  import { RETRY_MAX_ATTEMPTS } from "./drivers/retry.js";
80
+ import { recoveryCapabilityError } from "./automatic-recovery.js";
76
81
  import { decodeGeneratedImage } from "./generated-image.js";
77
82
  import { MAX_MCP_SERVERS, listMcpServers, mcpServerNameError, parseMcpServerMutation, parseMcpServersImport, parseStoredMcpServer, } from "./mcp-registry.js";
78
83
  import { probeMcpServer } from "./mcp-probe.js";
@@ -88,16 +93,17 @@ import { chiefForBot, INCIDENTS_THREAD_TITLE, IncidentLedger, incidentChip, inci
88
93
  const SESSION_READ_MAX_CHARS = 8_000;
89
94
  import { attemptAsideInjection, drainAsideMessages, queueAsideMessage, restoreAsideMessages, } from "./aside-queue.js";
90
95
  import { promptWithReply, transcriptText } from "./replies.js";
91
- import { admit } from "./admission.js";
96
+ import { admit, DRAIN_COALESCE_MAX_ITEMS } from "./admission.js";
92
97
  import { _loadPending, buildDelegationFailurePrompt, buildDelegationRevivalPrompt, DELEGATION_TTL_MS, DelegationWakeBudget, discardDelegations, drainDelegations, expireStaleDelegations, findDelegationReceipt, pendingDelegationInfo, pendingDelegationSnapshot, pendingThreads, queueDelegation, recordDelegationReceipt, releaseDelegationsWaitingOn, summarizeDelegatedActivity } from "./delegations.js";
93
98
  import { cancelSteeredMessage, drainSteeredMessages, hasQueuedSteeredMessages, holdSteeredQueue, onSteeredQueueChange, queuedSteerSnapshot, queuedSteeredMessage, queuedThreadPosition, queueSteeredMessage, restoreHeldSteeredQueue, restoreSteeredMessages, settleHeldSteeredQueue, } from "./steer-queue.js";
94
- import { cancelChannelMessage, drainChannelMessages, holdChannelQueue, queuedChannelMessage, queueChannelMessage, restoreChannelMessages, restoreHeldChannelQueue, resolveHeldReplyTarget, settleHeldChannelQueueHead, } from "./channel-queue.js";
99
+ import { cancelChannelMessage, drainChannelMessages, holdChannelQueue, headChannelGroup, queuedChannelMessage, queueChannelMessage, restoreChannelMessages, restoreHeldChannelQueue, resolveHeldReplyTarget, settleHeldChannelQueueHead, } from "./channel-queue.js";
95
100
  import { acceptedSendMatch, parseSendId, sendFingerprint, SendSequencer, } from "./send-idempotency.js";
96
101
  import { EventBus } from "./harness/bus.js";
97
102
  import { ProviderRegistry } from "./harness/registry.js";
98
103
  import { ManagedDesktopProviders } from "./managed-desktop.js";
99
104
  import { computerKindForResource, ManagedDesktopPolicy } from "./managed-policy.js";
100
105
  import { hostedModelPolicy, HOSTED_MODEL_POLICY_HEADER, HOSTED_PROVIDER_SETTINGS_ERROR } from "./hosted-models.js";
106
+ import { CLOUD_IGNORED_KEYS, CLOUD_PAIRING_PATH, cloudHomeConfiguration, createCloudPairing, readSignedBody } from "./cloud-home.js";
101
107
  import { selectDefaultModelSelection, withNewBotEffort } from "./default-model-selection.js";
102
108
  import { cancelPeerApprovalsFor, cancelPeerApprovalsForThread, dismissStalePeerCards, peerApprovalFailure, requestPeerApproval, resolvePeerComms } from "./peer-approval.js";
103
109
  import { peerDeliveryReceipt } from "./peer-delivery.js";
@@ -111,10 +117,10 @@ import { Handoffs, handedStateUsable, recordHanded, renderUnseen, sessionStart,
111
117
  import { extractTurnImages } from "./turn-images.js";
112
118
  import { TurnWatchdog } from "./turn-watchdog.js";
113
119
  import { TurnResources, workspaceResource } from "./turn-resources.js";
114
- import { ensureWorkspace, ensureTaskWorkspace, workspaceLocationsPrompt, supportsWorkspaceFiles, updateMemory, appendMemoryLog, isMemoryTopicName, memorySystemPrompt, memorySourceLabel, searchMemoryFiles, SESSION_SEARCH_SYSTEM_PROMPT, workspaceDir, } from "./workspace.js";
115
- import { listMemoryTopics, readMemoryFile, readMemoryTopic, writeMemoryFile, writeMemoryTopic } from "./workspace.js";
116
- import { MEMORY_INDEX, MemoryStoreError, memoryCapacity, memoryOverview, openMemoryLocation, readMemoryDoc, } from "./memory-store.js";
117
- import { beginMemoryTurn, endMemoryTurn, flushAllMemoryJournals, flushMemoryJournal, journalMemoryDelete, journalMemoryWrite, readMemoryJournal, revertMemoryChange, } from "./memory-journal.js";
120
+ import { IdleReleasePolicy } from "./claim-idle.js";
121
+ import { ensureWorkspace, ensureTaskWorkspace, workspaceLocationsPrompt, supportsWorkspaceFiles, updateMemory, appendMemoryLog, memorySystemPrompt, memorySourceLabel, searchMemoryFiles, SESSION_SEARCH_SYSTEM_PROMPT, workspaceDir, } from "./workspace.js";
122
+ import { listMemoryTopics, memoryDate, readMemoryFile, readMemoryTopic, writeMemoryFile, writeMemoryTopic } from "./workspace.js";
123
+ import { beginMemoryTurn, endMemoryTurn, flushAllMemoryJournals, journalMemoryWrite, } from "./memory-journal.js";
118
124
  import { readSectionContext, readSections, sectionContextKey, sectionContextLabel, sectionContextSystemPrompt, writeSectionContext, SECTION_CONTEXT_MAX_BYTES, } from "./section-context.js";
119
125
  import { applyStagedSkillWrite, applySkillWriteWithReceipt, getStagedSkillWrite, installOrgSkill, installSkill, parseSkillMd, scanSkillText, listSkills, listStagedSkillWrites, isSkillName, readSkillFile, rejectStagedSkillWrite, removeSkill, setSkillEnabled, skillPackageStamps, skillsSystemPrompt, stageSkillWrite, } from "./skills.js";
120
126
  import { fetchSkillFromSource } from "./skill-fetch.js";
@@ -123,11 +129,12 @@ import { botSkillTemplateSchema, newBotDefaultsSchema, resolveBotCreationDefault
123
129
  import { expandLearnTurnText, learnSource } from "./skill-learn.js";
124
130
  import { expandSetupTurnText, setupModeActive, setupSystemPrompt } from "./setup-mode.js";
125
131
  import { checkSoulDrift, readSoulDrift, soulFile, writeSoulMirror } from "./bot-folder.js";
126
- import { buildSystemPrompt, userProfileSystemPrompt, computerPrompt, composioSystemPrompt, customMcpPrompt, CREDENTIAL_PROMPT, mentionPrompt, THREADS_PROMPT, LEARN_PROMPT, PROFILE_PROMPT, ROUTINE_PROMPT, ROUTINE_EXECUTION_PROMPT, WEBHOOK_PROMPT, } from "./system-prompt.js";
132
+ import { buildSystemPrompt, userProfileSystemPrompt, computerPrompt, composioSystemPrompt, customMcpPrompt, CREDENTIAL_PROMPT, mentionPrompt, THREADS_PROMPT, LEARN_PROMPT, PROFILE_PROMPT, ROUTINE_PROMPT, ROUTINE_EXECUTION_PROMPT, WEBHOOK_PROMPT, resolveComputerPromptKind, } from "./system-prompt.js";
127
133
  import { readCuaConnection, readCuaUnavailableReason, gatedLocalComputer } from "./local-computer.js";
128
- import { discoverExistingPerBotLocalVms, localVmInventoryEntry, shouldArmLocalVmIdle, } from "./local-vm-inventory.js";
134
+ import { discoverExistingPerBotLocalVms, discoverExistingPoolLocalVms, localVmInventoryEntry, shouldArmLocalVmIdle, } from "./local-vm-inventory.js";
129
135
  import { LocalVmIdleTimer } from "./local-vm-idle.js";
130
136
  import { LocalVmLeasePool } from "./local-vm-lease.js";
137
+ import { LocalVmSeatPool } from "./local-vm-seat-pool.js";
131
138
  import { RepeatDetector, callKey } from "./repeat-detector.js";
132
139
  import { redactSecretsInText } from "./redact.js";
133
140
  import * as vps from "./vps-computer.js";
@@ -172,6 +179,7 @@ import { shouldMountLocalComputer } from "./local-routing.js";
172
179
  import { autoLocalVmAttachable } from "./container-computer.js";
173
180
  import { startAutoVmClaim } from "./auto-vm-claims.js";
174
181
  import { computerFreeAfterText, computerStillBusyText, computerStoppedWaitingText, computerWaitingText } from "./computer-wait.js";
182
+ import { CloudOverflowConsent, CloudSeatLease, cloudOverflowAction, cloudOverflowConsentText, cloudOverflowOfferText, cloudSeatStartedText, cloudSeatStoppedText } from "./cloud-overflow.js";
175
183
  import { modelContextWindow } from "./model-context-window.js";
176
184
  import { parseSurface, resolveSurface, surfaceLabel, surfaceOfComputerKind, surfacePrompt } from "./surface.js";
177
185
  import { PendingTurnCancellations, ProviderTurnGenerationRegistry, RetiredTurnRegistry, guardTurnDispatch, isTurnAdmissionBlocked, isTurnEventQuarantined, } from "./turn-dispatch-guard.js";
@@ -199,6 +207,7 @@ import { json, onJsonBody, parsedBodyOf, readBody } from "./harness/http.js";
199
207
  import { ROUTES, dispatchRoutes } from "./routes/table.js";
200
208
  import { createHostedSlackRoutes } from "./routes/hosted-slack.js";
201
209
  import { createBotPresetRoutes } from "./routes/bot-presets.js";
210
+ import { createBotMemoryRoutes } from "./routes/bot-memory.js";
202
211
  const PORT = Number(process.env.OMB_PORT || process.env.OGB_PORT || 8799);
203
212
  const WEBHOOK_PORT = Number(process.env.OMB_WEBHOOK_PORT || PORT + 1);
204
213
  // Behind a proxy or tunnel, the base URL senders should use (docs/self-hosting.md).
@@ -262,6 +271,21 @@ const sessions = new SessionRegistry({
262
271
  portalMembership: hostedWorkspaceConfiguration()?.portalMembership === true,
263
272
  });
264
273
  const sharedComputers = new SharedComputers(id => sessions.isLive(id));
274
+ // OMB Cloud Pro home machine (server/cloud-home.ts, docs/cloud-pro.md). A
275
+ // partial or invalid boot contract stops the server here, before it serves.
276
+ const CLOUD_HOME = cloudHomeConfiguration();
277
+ const cloudPairing = CLOUD_HOME ? createCloudPairing({ secret: CLOUD_HOME.bootstrapSecret, sessions }) : null;
278
+ if (CLOUD_HOME) {
279
+ // The signing secret is held in memory from here on, and a platform
280
+ // gateway's settings are dropped: no engine or tool this server starts
281
+ // inherits either. The person's own engines are the only way to a model.
282
+ delete process.env.OMB_CLOUD_BOOTSTRAP_SECRET;
283
+ for (const key of CLOUD_IGNORED_KEYS)
284
+ delete process.env[key];
285
+ console.log(`cloud home ${CLOUD_HOME.machineId}: bots run on the engines the person signs in to here`);
286
+ for (const warning of CLOUD_HOME.warnings)
287
+ console.warn(`cloud home: ${warning}`);
288
+ }
265
289
  // Who each thread is for, when a signed-in person can be named (server-private).
266
290
  const threadStarters = new ThreadStarters(join(DATA_DIR, "thread-starters.json"));
267
291
  const commandAllowlist = new CommandAllowlistStore(join(DATA_DIR, "command-allowlist.json"));
@@ -343,6 +367,10 @@ function customDomainStatus() {
343
367
  };
344
368
  }
345
369
  const registry = new ProviderRegistry(BUILT_IN_DRIVERS);
370
+ // The approval gates below hand this their model selection — or a driver
371
+ // view they already hold — and let the registry resolve the driver, instead
372
+ // of each site unwrapping registry.cliTarget(...)?.driverKind itself.
373
+ const supportsApprovalMode = createApprovalModeSupport(registry);
346
374
  // Engines installed from Settings live under the data directory and win over
347
375
  // any other copy on PATH.
348
376
  registerEnginesBinDir();
@@ -611,6 +639,56 @@ function recentWorkSources(bot) {
611
639
  taskByThread: (botId, threadId) => store.taskByThread(botId, threadId),
612
640
  };
613
641
  }
642
+ /** The automatic-recall block for a turn (server/recall.ts), or "". Notes
643
+ * always; the bot's other conversations only when `conversations` — a 1:1
644
+ * turn the person started — because a message from another bot, a webhook
645
+ * or a room must not be able to pull a private chat into its reply. The
646
+ * conversations are the ones session_search would search, minus this one. */
647
+ function autoRecallPrompt(bot, threadId, message, opts) {
648
+ if (!autoRecallEnabled(cfg))
649
+ return "";
650
+ const roomByThread = new Map();
651
+ if (opts.conversations) {
652
+ for (const group of store.groups) {
653
+ if (!group.memberIds.includes(bot.id) || !roomFeedsBot(group, bot))
654
+ continue;
655
+ roomByThread.set(group.threadId, group);
656
+ for (const task of group.tasks ?? [])
657
+ roomByThread.set(task.threadId, group);
658
+ }
659
+ }
660
+ const threadIds = opts.conversations
661
+ ? [...new Set([bot.threadId, ...(bot.tasks ?? []).map((task) => task.threadId), ...roomByThread.keys()])].filter((id) => id !== threadId)
662
+ : [];
663
+ try {
664
+ const recalled = buildRecall({
665
+ botId: bot.id,
666
+ message,
667
+ threadIds,
668
+ label: (id) => {
669
+ const room = roomByThread.get(id);
670
+ if (room)
671
+ return `room ${JSON.stringify(room.name)}`;
672
+ const task = store.taskByThread(bot.id, id);
673
+ if (task)
674
+ return `chat ${JSON.stringify(task.title)}`;
675
+ return id === bot.threadId ? "your main chat" : "an earlier chat";
676
+ },
677
+ author: (hit) => (hit.role === "user" ? hit.peer ?? opts.userName : hit.from ?? bot.name),
678
+ });
679
+ if (recalled)
680
+ console.log(`auto-recall: ${bot.name} (${bot.id}) got ${recalled.notes} note and ${recalled.conversations} conversation passage(s) in ${threadId}`);
681
+ return recalled?.text ?? "";
682
+ }
683
+ catch (err) {
684
+ console.warn(`auto-recall failed for ${bot.id}: ${err.message}`);
685
+ return "";
686
+ }
687
+ }
688
+ /** The recalled block in front of a turn's message, or the message alone. */
689
+ function withRecalled(recalled, text) {
690
+ return recalled ? `${recalled}\n\n${text}` : text;
691
+ }
614
692
  /** Bots in one room must be visible to the same people: a room is one
615
693
  * transcript, so otherwise a restricted bot's words would feed a teammate
616
694
  * everyone can see. Refuse a roster that adds such a bot (existing members
@@ -868,15 +946,17 @@ function operatorPrices() {
868
946
  * engine reported tokens but no price, and let the spend cap see it at once.
869
947
  * The first booking that takes the month past the warning threshold, or to
870
948
  * the cap, notifies admins (once per month each; server/spend.ts). */
871
- function bookTurnUsage(row) {
872
- const booked = { ...row, ...ledgerCost(row, operatorPrices()), at: new Date().toISOString() };
949
+ function bookTurnUsage(row, tokensReported = true, notificationThreadId = row.threadId) {
950
+ // Missing helper usage is unpriced, not an estimated zero-dollar call.
951
+ const cost = tokensReported || row.costUsd !== null ? ledgerCost(row, operatorPrices()) : { costUsd: null };
952
+ const booked = { ...row, ...cost, at: new Date().toISOString() };
873
953
  // The append lands asynchronously; the cap counts the row from memory
874
954
  // until it does, so the check below (and the next turn start) sees it.
875
955
  noteSpend(DATA_DIR, booked, appendUsage(DATA_DIR, booked));
876
956
  const state = spendState(cfg, DATA_DIR);
877
957
  const alert = takeSpendAlert(DATA_DIR, state);
878
958
  if (alert && state) {
879
- broadcast({ kind: "notify", notification: buildSpendNotification({ id: row.botId, name: row.botName }, row.threadId, spendAlertText(alert, state)) }, { adminOnly: true });
959
+ broadcast({ kind: "notify", notification: buildSpendNotification({ id: row.botId, name: row.botName }, notificationThreadId, spendAlertText(alert, state)) }, { adminOnly: true });
880
960
  }
881
961
  }
882
962
  /** A queued line from before triggers were stored with it: its sender, else
@@ -1346,12 +1426,164 @@ const turnResourceOwners = new Map();
1346
1426
  const turnComputerResources = new Map();
1347
1427
  const teamComputerTurns = new Map();
1348
1428
  const settlingResourceOwners = new Map();
1429
+ /** Idle release for computer claims (#1653), disabled until the feature
1430
+ * flag is on: a seat that stays screen-quiet for the policy's window is
1431
+ * released to waiting turns while its holder's turn still lives, and the
1432
+ * previous holder re-claims directly inside the reclaim window — it
1433
+ * yields once another turn holds the seat. The durable VM profile keeps
1434
+ * its login state, so that re-claim is cheap. Read per claim: a flag
1435
+ * change applies to new claims, never to a seat held under the old
1436
+ * setting. */
1437
+ const COMPUTER_CLAIM_IDLE_POLICY = new IdleReleasePolicy();
1438
+ function computerClaimIdlePolicy(resource) {
1439
+ return resource.startsWith("computer:") && computerClaimIdleReleaseEnabled(cfg) ? COMPUTER_CLAIM_IDLE_POLICY : undefined;
1440
+ }
1441
+ /** #1655: the consent ledger for local-wait cloud overflow, and the live
1442
+ * cloud seats it has started. One seat per bot — it is the bot's own Box,
1443
+ * shared by that bot's threads the way every other computer is. */
1444
+ const cloudOverflowConsent = new CloudOverflowConsent();
1445
+ const cloudSeatLeases = new Map();
1446
+ let cloudSeatSweepTimer;
1447
+ /** One stop attempt per seat at a time (#1655): the sweep ticks faster
1448
+ * than a Box sleeps, and a second stop call would race the first. */
1449
+ const cloudSeatStopsInFlight = new Set();
1450
+ /** The waits that may overflow: a turn queued for a local desktop, never
1451
+ * one already bound for a cloud or VPS seat. */
1452
+ function localComputerWait(resource) {
1453
+ return resource === "computer:host" || resource.startsWith("computer:vm:");
1454
+ }
1455
+ function cloudOverflowSituation(owner, resource, started) {
1456
+ if (!localComputerWait(resource))
1457
+ return null;
1458
+ if (!store.botByThread(owner.threadId))
1459
+ return null;
1460
+ const perSecondCostUsd = cloudOverflowPerSecondCostUsd(cfg);
1461
+ return {
1462
+ featureEnabled: cloudOverflowEnabled(cfg),
1463
+ // An organisation that refuses the Box kind has nothing to offer, and
1464
+ // the decision must fail closed before any card is written.
1465
+ cloudConfigured: boat.boatConfigured(cfg) && managedPolicy.computerRefusal("box") === undefined,
1466
+ perSecondCostUsd,
1467
+ // Consent answers the priced card (#1655): a grant counts only at the
1468
+ // rate its card showed, so a config change re-offers instead of
1469
+ // starting at a price nobody approved.
1470
+ consented: cloudOverflowConsent.consented(owner.threadId, cloudOverflowAllowlistedThreads(cfg), perSecondCostUsd ?? undefined),
1471
+ offered: cloudOverflowConsent.offered(owner.threadId, perSecondCostUsd ?? undefined),
1472
+ started,
1473
+ };
1474
+ }
1349
1475
  function claimTurnResource(owner, resource) {
1350
- if (!turnResources.claim(resource, owner))
1476
+ const idle = computerClaimIdlePolicy(resource);
1477
+ if (!turnResources.claim(resource, owner, idle ? { idle } : {}))
1351
1478
  return false;
1352
1479
  turnResourceOwners.set(owner.threadId, owner);
1353
1480
  return true;
1354
1481
  }
1482
+ /** Start the waiting bot's cloud seat (#1655). True once handled — started
1483
+ * or terminally failed — so the wait never retries every poll; false when
1484
+ * another turn of this bot owns the Box lifecycle and a later poll may
1485
+ * still land. */
1486
+ async function startCloudSeat(owner) {
1487
+ const bot = store.botByThread(owner.threadId);
1488
+ if (!bot)
1489
+ return true;
1490
+ const perSecondCostUsd = cloudOverflowPerSecondCostUsd(cfg);
1491
+ if (!perSecondCostUsd)
1492
+ return true;
1493
+ const boxBotResource = "computer:box-bot:" + bot.id;
1494
+ if (!claimTurnResource(owner, boxBotResource))
1495
+ return false;
1496
+ try {
1497
+ broadcast({ kind: "computer", botId: bot.id, state: "waking" });
1498
+ const machine = await boat.readyBoat(cfg, bot.id);
1499
+ if (!machine)
1500
+ throw new Error("the cloud computer did not wake");
1501
+ // Consent can be revoked while the Box wakes (#1655): a seat nobody
1502
+ // consented to must not bill. It is released and put straight back to
1503
+ // sleep — and if even that fails, leased as already idle so the sweep
1504
+ // keeps retrying with backoff.
1505
+ if (!cloudOverflowConsent.consented(owner.threadId, cloudOverflowAllowlistedThreads(cfg), perSecondCostUsd)) {
1506
+ turnResources.releaseOne(boxBotResource, owner);
1507
+ const idleStopMs = cloudOverflowIdleStopMs(cfg);
1508
+ void boat.sleepBoat(cfg, bot.id).catch(() => {
1509
+ cloudSeatLeases.set(bot.id, new CloudSeatLease({ botId: bot.id, threadId: owner.threadId, generation: owner.generation, now: Date.now() - idleStopMs - 1, idleStopMs }));
1510
+ ensureCloudSeatSweep();
1511
+ });
1512
+ store.appendMessage(owner.threadId, {
1513
+ role: "bot", kind: "activity",
1514
+ tool: { name: "Cloud overflow consent was revoked while the cloud computer woke; it stops unbilled and the local wait continues.", ok: true },
1515
+ });
1516
+ return true;
1517
+ }
1518
+ cloudSeatLeases.set(bot.id, new CloudSeatLease({ botId: bot.id, threadId: owner.threadId, generation: owner.generation, idleStopMs: cloudOverflowIdleStopMs(cfg) }));
1519
+ ensureCloudSeatSweep();
1520
+ store.appendMessage(owner.threadId, {
1521
+ role: "bot", kind: "activity",
1522
+ tool: { name: cloudSeatStartedText({ perSecondCostUsd, idleStopMs: cloudOverflowIdleStopMs(cfg) }), ok: true },
1523
+ });
1524
+ return true;
1525
+ }
1526
+ catch (error) {
1527
+ turnResources.releaseOne(boxBotResource, owner);
1528
+ store.appendMessage(owner.threadId, {
1529
+ role: "bot", kind: "activity",
1530
+ tool: { name: "Cloud computer could not start (" + (error instanceof Error ? error.message : String(error)) + "); the local wait continues.", ok: false },
1531
+ });
1532
+ return true;
1533
+ }
1534
+ }
1535
+ /** A per-second-billed seat must stop on idleness even when nothing else
1536
+ * touches the server, so this slice carries the one timer — unref'd, it
1537
+ * can never hold the process open, and it dies with the last lease. */
1538
+ function ensureCloudSeatSweep() {
1539
+ if (cloudSeatSweepTimer)
1540
+ return;
1541
+ cloudSeatSweepTimer = setInterval(() => {
1542
+ sweepIdleCloudSeats();
1543
+ if (!cloudSeatLeases.size && cloudSeatSweepTimer) {
1544
+ clearInterval(cloudSeatSweepTimer);
1545
+ cloudSeatSweepTimer = undefined;
1546
+ }
1547
+ }, 15_000);
1548
+ cloudSeatSweepTimer.unref?.();
1549
+ }
1550
+ /** Stop every cloud seat idle past its window (#1655): the machine is
1551
+ * archived, billing pauses, and the transcript says which wait's seat it
1552
+ * was. Only real computer tool completions refresh a lease — the poller's
1553
+ * preview frames never reach the touch call. */
1554
+ /** Stop one running cloud seat (#1655): the Box sleeps, and only a
1555
+ * successful stop clears the lease and its Box claim — a failed stop
1556
+ * stays leased and retryable with backoff, because the seat still bills
1557
+ * until it sleeps. The claim releases for the lease's own generation,
1558
+ * never a newer turn's. */
1559
+ function stopCloudSeat(botId, lease, stoppedName, now = Date.now()) {
1560
+ if (cloudSeatStopsInFlight.has(botId))
1561
+ return;
1562
+ if (cloudSeatLeases.get(botId) !== lease)
1563
+ return;
1564
+ cloudSeatStopsInFlight.add(botId);
1565
+ void boat.sleepBoat(cfg, botId)
1566
+ .then(() => {
1567
+ if (cloudSeatLeases.get(botId) === lease)
1568
+ cloudSeatLeases.delete(botId);
1569
+ // The stopped seat's Box claim goes with it, so a still-waiting
1570
+ // turn may start a fresh seat for the same bot.
1571
+ turnResources.releaseOne(`computer:box-bot:${botId}`, { threadId: lease.threadId, generation: lease.generation });
1572
+ store.appendMessage(lease.threadId, { role: "bot", kind: "activity", tool: { name: stoppedName, ok: true } });
1573
+ })
1574
+ .catch(() => {
1575
+ lease.deferSleep(now);
1576
+ store.appendMessage(lease.threadId, { role: "bot", kind: "activity", tool: { name: "Cloud computer could not stop — the sweep retries with backoff; stop it from Settings if it stays awake. Billing continues until it sleeps.", ok: false } });
1577
+ })
1578
+ .finally(() => cloudSeatStopsInFlight.delete(botId));
1579
+ }
1580
+ function sweepIdleCloudSeats(now = Date.now()) {
1581
+ for (const [botId, lease] of cloudSeatLeases) {
1582
+ if (!lease.idleElapsed(now) || !lease.sleepDue(now))
1583
+ continue;
1584
+ stopCloudSeat(botId, lease, cloudSeatStoppedText(lease.idleFor(now)), now);
1585
+ }
1586
+ }
1355
1587
  function releaseTurnResources(owner) {
1356
1588
  if (!owner)
1357
1589
  return;
@@ -1389,6 +1621,10 @@ async function bindTurnComputer(owner, resource, exclusive = false) {
1389
1621
  // turn.wait_* events carry the same facts for the inspector log.
1390
1622
  let waitedSince;
1391
1623
  let waitEnded = false;
1624
+ // #1655: whether this wait already started (or terminally failed to
1625
+ // start) a cloud seat; the decision is re-evaluated every poll because
1626
+ // consent can arrive mid-wait.
1627
+ let overflowHandled = false;
1392
1628
  const waitEventBase = () => {
1393
1629
  const selection = store.botByThread(owner.threadId)?.modelSelection;
1394
1630
  const instance = selection ? registry.get(selection.instanceId) : null;
@@ -1454,7 +1690,32 @@ async function bindTurnComputer(owner, resource, exclusive = false) {
1454
1690
  resource,
1455
1691
  ...(holder ? { holder } : {}),
1456
1692
  });
1693
+ // #1655: the wait is where an overflow choice gets made. The card
1694
+ // names the per-second cost before anything can start, and only a
1695
+ // turn genuinely waiting on a local desktop gets one. Fail closed:
1696
+ // feature off, cloud unusable, or no operator-set rate means no
1697
+ // card at all — Auto never offers, never starts.
1698
+ const overflow = cloudOverflowSituation(owner, resource, overflowHandled);
1699
+ const perSecondCostUsd = overflow?.perSecondCostUsd ?? null;
1700
+ if (overflow && perSecondCostUsd !== null && cloudOverflowAction(overflow).kind === "offer") {
1701
+ store.appendMessage(owner.threadId, {
1702
+ role: "bot", kind: "activity",
1703
+ tool: { name: cloudOverflowOfferText({ perSecondCostUsd, idleStopMs: cloudOverflowIdleStopMs(cfg) }), ok: true },
1704
+ });
1705
+ cloudOverflowConsent.markOffered(owner.threadId, perSecondCostUsd);
1706
+ }
1457
1707
  }
1708
+ // #1655: consent can arrive mid-wait — the card's answer, or a
1709
+ // thread the operator allowlisted — and only then may the cloud
1710
+ // seat start, its cost chip landing beside the waiting one. The
1711
+ // local wait itself is untouched: it still ends by acquisition,
1712
+ // stop, or the ceiling (parking, once that stack lands).
1713
+ if (!overflowHandled) {
1714
+ const situation = cloudOverflowSituation(owner, resource, overflowHandled);
1715
+ if (situation && cloudOverflowAction(situation).kind === "start")
1716
+ overflowHandled = await startCloudSeat(owner);
1717
+ }
1718
+ sweepIdleCloudSeats();
1458
1719
  if (Date.now() >= deadline) {
1459
1720
  endWait("gave_up");
1460
1721
  throw new ComputerWaitGaveUp(computerStillBusyText(holder, GROUP_GOAL_WAIT_MAX_MS));
@@ -1851,8 +2112,9 @@ const routineRequestEnvelopeSchema = z.discriminatedUnion("action", [
1851
2112
  action: z.literal("update"),
1852
2113
  routineId: z.unknown(),
1853
2114
  changes: z.unknown(),
2115
+ forBotId: z.unknown().optional(),
1854
2116
  }).strict(),
1855
- ...["pause", "resume", "run_now", "delete"].map((action) => z.object({ ...routineRequestSourceSchema, action: z.literal(action), routineId: z.unknown() }).strict()),
2117
+ ...["pause", "resume", "run_now", "delete"].map((action) => z.object({ ...routineRequestSourceSchema, action: z.literal(action), routineId: z.unknown(), forBotId: z.unknown().optional() }).strict()),
1856
2118
  ]);
1857
2119
  /** The loopback endpoint a bot's computer proxy polls before acting. */
1858
2120
  function controlIntegration(botId, threadId, generation, localVmTarget) {
@@ -2314,13 +2576,13 @@ function previewSystemPrompt(bot) {
2314
2576
  const caps = instance?.adapter.capabilities;
2315
2577
  const teamComputer = inheritedTeamComputer(bot);
2316
2578
  const previewComputer = teamComputer ? "cloud" : bot.computer;
2317
- const computerPromptKind = previewComputer === "vm"
2318
- ? caps?.computerMcp ? localVmMode(cfg) === "per-bot" ? "vm-private" : "vm-shared" : null
2319
- : previewComputer === "cloud"
2320
- ? instance?.driverKind === "boxAgent" ? "box-agent" : caps?.computerMcp ? bot.cloudBackend === "vps" ? "vps" : caps.cloudComputerMcp ? "box-chat" : "box" : null
2321
- : previewComputer === "local"
2322
- ? caps?.localComputerMcp ? "local" : null
2323
- : null;
2579
+ const computerPromptKind = resolveComputerPromptKind({
2580
+ kind: previewComputer === "vm" ? "vm" : previewComputer === "cloud"
2581
+ ? bot.cloudBackend === "vps" ? "vps" : "box" : previewComputer === "local" ? "local" : null,
2582
+ driverKind: instance?.driverKind,
2583
+ cloudComputerMcp: caps?.cloudComputerMcp,
2584
+ vmPrivate: localVmMode(cfg) === "per-bot",
2585
+ });
2324
2586
  const peers = reachablePeers(store.bots, bot);
2325
2587
  const coordination = bot.chiefOfStaff
2326
2588
  ? chiefOfStaffSystemPrompt(bot.id, store.bots, true, openMausStatusSystemPrompt())
@@ -2455,7 +2717,7 @@ async function botOverview(bot) {
2455
2717
  * person gave the Chief covers the work the Chief hands out. */
2456
2718
  const approvalModeForTurn = (bot, peerInitiated = false) => {
2457
2719
  const mode = approvalModeForOrigin(approvalModeFor(bot), { peerInitiated });
2458
- if (!supportsApprovalMode(registry.cliTarget(bot.modelSelection.instanceId)?.driverKind, mode)) {
2720
+ if (!supportsApprovalMode(bot.modelSelection, mode)) {
2459
2721
  return "ask";
2460
2722
  }
2461
2723
  return mode;
@@ -2528,8 +2790,8 @@ function handleDesktopTrustedApprovalMessage(raw) {
2528
2790
  const grantBusy = (bot) => bot.approvalGrant?.threadOnly
2529
2791
  ? threadBusy(bot.id, bot.approvalGrant.threadId) : bot.busy ||
2530
2792
  Boolean(bot.approvalGrant?.allThreads && store.tasks(bot.id).some(task => threadBusy(bot.id, task.threadId)));
2531
- const grantSupported = (bot, mode) => supportsApprovalMode(registry.cliTarget(grantTarget(bot)?.modelSelection.instanceId ?? "")?.driverKind, mode) &&
2532
- (!bot.approvalGrant?.allThreads || store.tasks(bot.id).every(task => supportsApprovalMode(registry.cliTarget((task.modelSelection ?? bot.modelSelection).instanceId)?.driverKind, mode)));
2793
+ const grantSupported = (bot, mode) => supportsApprovalMode(grantTarget(bot)?.modelSelection, mode) &&
2794
+ (!bot.approvalGrant?.allThreads || store.tasks(bot.id).every(task => supportsApprovalMode(task.modelSelection ?? bot.modelSelection, mode)));
2533
2795
  const clearGrant = (bot) => store.patchBot(bot.id, {
2534
2796
  ...(!bot.approvalGrant?.threadOnly ? { approvalMode: "ask", autoApprove: false } : {}),
2535
2797
  approvalGrant: undefined,
@@ -2762,7 +3024,7 @@ function handleDesktopTrustedApprovalMessage(raw) {
2762
3024
  void stopBotForEmergencyApprovalDowngrade(botId).then(() => respond({ ok: true, bot: wireBot(store.bot(botId) ?? updated) }), () => respond({ ok: false, error: "Approval was reset to Ask, but an active turn could not be stopped" }));
2763
3025
  return true;
2764
3026
  }
2765
- if (message.allThreads === true && (existing.approvalGrant || store.tasks(botId).some(task => threadBusy(botId, task.threadId) || !supportsApprovalMode(registry.cliTarget((task.modelSelection ?? existing.modelSelection).instanceId)?.driverKind, mode)))) {
3027
+ if (message.allThreads === true && (existing.approvalGrant || store.tasks(botId).some(task => threadBusy(botId, task.threadId) || !supportsApprovalMode(task.modelSelection ?? existing.modelSelection, mode)))) {
2766
3028
  respond({ ok: false, error: "Finish this bot's active turns and approval changes first. Every thread's provider must support Full access." });
2767
3029
  return true;
2768
3030
  }
@@ -2782,7 +3044,7 @@ function handleDesktopTrustedApprovalMessage(raw) {
2782
3044
  respond({ ok: false, error: "Stop this thread and finish its pending approval change first" });
2783
3045
  return true;
2784
3046
  }
2785
- if (!supportsApprovalMode(registry.cliTarget(target.modelSelection.instanceId)?.driverKind, mode)) {
3047
+ if (!supportsApprovalMode(target.modelSelection, mode)) {
2786
3048
  respond({ ok: false, error: "This thread's provider does not support that approval level" });
2787
3049
  return true;
2788
3050
  }
@@ -2842,7 +3104,7 @@ function handleDesktopTrustedApprovalMessage(raw) {
2842
3104
  respond({ ok: false, error: "Stop this bot's turn before changing its approval level" });
2843
3105
  return true;
2844
3106
  }
2845
- if (!supportsApprovalMode(registry.cliTarget(existing.modelSelection.instanceId)?.driverKind, mode)) {
3107
+ if (!supportsApprovalMode(existing.modelSelection, mode)) {
2846
3108
  respond({
2847
3109
  ok: false,
2848
3110
  error: mode === "full"
@@ -4374,6 +4636,89 @@ bus.subscribe((event) => {
4374
4636
  memoryRowsByThread.delete(event.threadId);
4375
4637
  }
4376
4638
  });
4639
+ // Memory upkeep (server/memory-upkeep.ts): background capture, About me
4640
+ // suggestions and the nightly tidy-up, for bots with the switch on.
4641
+ const memoryUpkeep = createMemoryUpkeep({
4642
+ bots: () => store.bots,
4643
+ bot: (id) => store.bot(id) ?? undefined,
4644
+ engine: (botId) => {
4645
+ const bot = store.bot(botId);
4646
+ const instance = bot ? registry.get(bot.modelSelection.instanceId) : undefined;
4647
+ // an engine the organisation disallows never receives memory text
4648
+ if (!bot || !instance || policyModelRefusal(instance))
4649
+ return null;
4650
+ const generate = instance.generateText?.bind(instance);
4651
+ return generate ? {
4652
+ generateText: async (prompt, options) => {
4653
+ // Check every capture, organize and contradiction call, including
4654
+ // consecutive calls within one upkeep pass.
4655
+ assertWithinBudget(cfg, DATA_DIR);
4656
+ const threadId = `memory-${randomUUID()}`;
4657
+ return generate(prompt, { ...options, onUsage: (usage) => bookTurnUsage({
4658
+ botId: bot.id,
4659
+ botName: bot.name,
4660
+ threadId,
4661
+ instanceId: instance.instanceId,
4662
+ driverKind: instance.driverKind,
4663
+ model: usage.model,
4664
+ input: usage.input ?? 0,
4665
+ output: usage.output ?? 0,
4666
+ ...(usage.cachedInput !== undefined ? { cachedInput: usage.cachedInput } : {}),
4667
+ costUsd: usage.costUsd ?? null,
4668
+ trigger: { kind: "bot", botId: bot.id },
4669
+ }, usage.input !== undefined && usage.output !== undefined, bot.threadId) });
4670
+ },
4671
+ } : {};
4672
+ },
4673
+ busy: (botId) => botHasActiveTurn(botId),
4674
+ addToAboutMe: (from, texts) => {
4675
+ const current = cfg.profile?.aboutMe ?? "";
4676
+ const facts = planLearned(from, texts, current, memoryDate());
4677
+ const next = appendAboutMe(current, facts.map((fact) => fact.line));
4678
+ // a full About me takes nothing more; the person trims it first
4679
+ if (!facts.length || next === null)
4680
+ return 0;
4681
+ saveConfig({ profile: { ...cfg.profile, aboutMe: next } });
4682
+ Object.assign(cfg, loadConfig());
4683
+ commitLearned(facts);
4684
+ broadcast({ kind: "config", ...configStatus() });
4685
+ return facts.length;
4686
+ },
4687
+ sourceLabel: (botId, threadId) => memorySourceLabel({ task: store.taskByThread(botId, threadId), threadId }),
4688
+ quietMs: () => captureQuietMs(cfg),
4689
+ tidyHour: () => tidyHour(cfg),
4690
+ log: (line) => console.log(line),
4691
+ });
4692
+ // A finished 1:1 turn of an upkeep bot waits for capture. Only the person's
4693
+ // own conversation: not a room, not a turn another bot or the harness
4694
+ // started (its "user" line is not the person), not a failed turn.
4695
+ bus.subscribe((event) => {
4696
+ if (shouldIgnoreProviderEvent(event))
4697
+ return;
4698
+ if (event.type !== "turn.completed" || !event.turnId || !event.ok)
4699
+ return;
4700
+ try {
4701
+ const bot = store.botByThread(event.threadId);
4702
+ if (!bot || !upkeepEnabled(bot) || store.groupByThread(event.threadId) || isInternalTurn(event.threadId)
4703
+ || isUnattended(bot.id, event.threadId) || routines?.runForThread(event.threadId))
4704
+ return;
4705
+ const path = store.activePath(event.threadId);
4706
+ const replyAt = path.findLastIndex((message) => message.role === "bot" && message.kind === "text" && message.turnId === event.turnId);
4707
+ if (replyAt < 0)
4708
+ return;
4709
+ const asked = path.slice(0, replyAt).findLast((message) => message.role === "user" && message.kind === "text");
4710
+ if (!asked || asked.peerAsk)
4711
+ return;
4712
+ memoryUpkeep.noteTurn(bot.id, event.threadId, {
4713
+ person: extractTurnImages(asked.text ?? "").text,
4714
+ bot: path[replyAt].text ?? "",
4715
+ owner: !asked.sender,
4716
+ });
4717
+ }
4718
+ catch (error) {
4719
+ console.warn(`memory upkeep: could not queue a turn for capture: ${error.message}`);
4720
+ }
4721
+ });
4377
4722
  // One line per finished turn in the bot's daily log (server/recent-work.ts):
4378
4723
  // what it said last, the tools it used, whether the turn failed. What a bot
4379
4724
  // did in one conversation was invisible from every other; the log is where
@@ -4544,12 +4889,7 @@ async function scheduleTurnDigest(input) {
4544
4889
  const controller = new AbortController();
4545
4890
  let timer;
4546
4891
  const capture = async () => {
4547
- const after = await checkpoints.snapshot(input.botId, checkpoint.cwd, `settle ${input.threadId.slice(0, 8)}`, controller.signal);
4548
- if (!after || controller.signal.aborted)
4549
- return null;
4550
- if (checkpoint.hash === after)
4551
- return { changed: [], added: [], deleted: [] };
4552
- return checkpoints.diffStat(input.botId, checkpoint.cwd, checkpoint.hash, after, controller.signal);
4892
+ return checkpoints.diffWorkingTree(input.botId, checkpoint.cwd, checkpoint.hash, controller.signal);
4553
4893
  };
4554
4894
  let files;
4555
4895
  try {
@@ -4646,6 +4986,11 @@ let routines = null;
4646
4986
  let calendarCalls = null;
4647
4987
  const localVmOwnerBusy = (botId) => store.bot(botId)?.busy === true;
4648
4988
  const localVmLeases = new LocalVmLeasePool(30 * 60_000);
4989
+ // Pool mode (issue #1654) keeps the lease pool as the ownership fence and
4990
+ // uses this table only to decide WHICH seat a conversation addresses: a
4991
+ // TTL-bounded affinity returns each thread to the desktop holding its login
4992
+ // state, and hands the seat back once the conversation has been idle.
4993
+ const localVmSeatPool = new LocalVmSeatPool(() => localVmMaxInstances(cfg));
4649
4994
  const localVmLifecycleBusy = new Set();
4650
4995
  const localVmThreadTargets = new Map();
4651
4996
  const localVmActiveThreads = new Map();
@@ -4658,8 +5003,8 @@ const autoVmClaims = new Map();
4658
5003
  * answers held. A free, ready VM claims in the time of one container
4659
5004
  * inspect; only a claim queued behind another holder outlives this. */
4660
5005
  const LAZY_VM_CLAIM_GRACE_MS = 5_000;
4661
- /** Local VM targets this process has seen ready or recreatable — at boot, in
4662
- * the inventory, or in a turn. Auto probes the container runtime for a VM
5006
+ /** Local VM targets with a durable workspace or seen ready/recreatable — at
5007
+ * boot, in the inventory, or in a turn. Auto probes the container runtime for a VM
4663
5008
  * only when one of these exists, so an ordinary Auto turn on a machine with
4664
5009
  * no VM never pays for a docker or podman call. */
4665
5010
  const localVmSeen = new Set();
@@ -4689,12 +5034,12 @@ function vpsThreadEnded(botId, threadId) {
4689
5034
  if (!threads.size)
4690
5035
  activeVpsThreads.delete(botId);
4691
5036
  }
4692
- const boxLifecycleBusyBots = new Set();
5037
+ const boatLifecycleBusyBots = new Set();
4693
5038
  // A refresh is a reader, not a lifecycle change. Keep its reservation until
4694
5039
  // the provider settles even if the HTTP client leaves, and share it on retry.
4695
5040
  const vpsPreviewRequests = new Map();
4696
- const orphanBoxLifecycleBusyIds = new Set();
4697
- const boxInventoryRequestsBusyIds = new Set();
5041
+ const orphanBoatLifecycleBusyIds = new Set();
5042
+ const boatInventoryRequestsBusyIds = new Set();
4698
5043
  const computerProviderConfigTransitions = new Set();
4699
5044
  // A restore mutates and cleans a project work tree. Claim the bot across the
4700
5045
  // entire async Git operation so a turn cannot start in that folder midway.
@@ -4709,7 +5054,7 @@ function inheritedTeamComputer(bot) {
4709
5054
  return teamComputers.forBot(bot);
4710
5055
  }
4711
5056
  function teamComputerPrompt(computer) {
4712
- return computer ? `Your team shares the Box computer ${JSON.stringify(computer.name)}. Its desktop files and desktop browser logins are shared with other Auto bots in your team; only one turn may drive it at a time. The separate built-in Browser is not this desktop and does not automatically share its logins.` : "";
5057
+ return computer ? `Your team shares the Boat computer ${JSON.stringify(computer.name)}. Its desktop files and desktop browser logins are shared with other Auto bots in your team; only one turn may drive it at a time. The separate built-in Browser is not this desktop and does not automatically share its logins.` : "";
4713
5058
  }
4714
5059
  function botComputerControlKey(bot) {
4715
5060
  const computer = inheritedTeamComputer(bot);
@@ -4761,6 +5106,10 @@ async function computerCallGate(internalCapability) {
4761
5106
  };
4762
5107
  }
4763
5108
  const computer = turnComputerResources.get(internalCapability.threadId);
5109
+ // The screen call arriving here re-claims an idle-released seat directly
5110
+ // (#1653): inside the reclaim window the previous holder picks its seat
5111
+ // back up without re-entering the wait, and the successful claim
5112
+ // restarts the quiet window. A seat another turn holds still refuses.
4764
5113
  if (!snapshot.held && computer && computer.owner.generation === internalCapability.generation &&
4765
5114
  !claimTurnResource(computer.owner, computer.resource)) {
4766
5115
  return {
@@ -4801,13 +5150,13 @@ function assertTeamComputerChangeIdle(before, after) {
4801
5150
  if (previous?.id === next?.id)
4802
5151
  return;
4803
5152
  if (botHasActiveTurn(before.id) || routines?.activeRunForBot(before.id) || botComputerControlSnapshot(before.id).held ||
4804
- [previous, next].some(computer => computer && (teamComputerInUse(computer) || boxLifecycleBusyBots.has(teamComputerOwner(computer.id))))) {
5153
+ [previous, next].some(computer => computer && (teamComputerInUse(computer) || boatLifecycleBusyBots.has(teamComputerOwner(computer.id))))) {
4805
5154
  throw Object.assign(new Error("Stop the affected team's work and release computer control before changing its computer access"), { status: 409 });
4806
5155
  }
4807
5156
  }
4808
5157
  async function teamComputersPayload() {
4809
5158
  const entries = teamComputers.list();
4810
- const inventory = await box.listManagedBoxes(cfg, managedBoxOwners());
5159
+ const inventory = await boat.listManagedBoats(cfg, managedBoatOwners());
4811
5160
  return {
4812
5161
  configured: inventory.configured,
4813
5162
  ...(inventory.problem ? { problem: inventory.problem } : {}),
@@ -4816,34 +5165,34 @@ async function teamComputersPayload() {
4816
5165
  return {
4817
5166
  id: entry.id, name: entry.name, section: entry.section,
4818
5167
  held: computerControl.snapshot(teamComputerOwner(entry.id)).held,
4819
- state: boxLifecycleBusyBots.has(teamComputerOwner(entry.id)) ? "working" : machine?.state ?? (inventory.available ? "missing" : "unavailable"),
5168
+ state: boatLifecycleBusyBots.has(teamComputerOwner(entry.id)) ? "working" : machine?.state ?? (inventory.available ? "missing" : "unavailable"),
4820
5169
  ...(entry.problem || inventory.problem ? { problem: entry.problem || inventory.problem } : {}),
4821
5170
  };
4822
5171
  }),
4823
5172
  };
4824
5173
  }
4825
- /** The same named Box identity and whole-turn lease in chats and rooms.
5174
+ /** The same named Boat identity and whole-turn lease in chats and rooms.
4826
5175
  * Assignment authorizes waking, never replacing a missing paid machine. */
4827
- async function attachTeamBox(computer, botId, owner, canMount, remoteAgent) {
5176
+ async function attachTeamBoat(computer, botId, owner, canMount, remoteAgent) {
4828
5177
  if (!canMount)
4829
- throw new Error("This model engine cannot use the team's Box computer; choose an engine with computer tools or an explicit bot destination");
4830
- if (!box.boxConfigured(cfg))
4831
- throw new Error("The team's Box account is not configured; reconnect it in Settings");
5178
+ throw new Error("This model engine cannot use the team's Boat computer; choose an engine with computer tools or an explicit bot destination");
5179
+ if (!boat.boatConfigured(cfg))
5180
+ throw new Error("The team's Boat account is not configured; reconnect it in Settings");
4832
5181
  const ownerId = teamComputerOwner(computer.id);
4833
- if (boxLifecycleBusyBots.has(ownerId))
5182
+ if (boatLifecycleBusyBots.has(ownerId))
4834
5183
  throw new Error("The team computer is being changed; wait for it to finish");
4835
5184
  if (computerControl.snapshot(ownerId).held)
4836
5185
  throw new Error("Release human control of the team computer before starting another turn");
4837
5186
  await bindTurnComputer(owner, `computer:box-bot:${ownerId}`, true);
4838
5187
  teamComputerTurns.set(owner.threadId, { owner, computerId: computer.id, botId, remoteAgent });
4839
- let machine = await box.findBox(cfg, ownerId);
5188
+ let machine = await boat.findBoat(cfg, ownerId);
4840
5189
  if (!machine)
4841
- throw new Error("The team's Box computer is missing; explicitly create or retry it from the Team map");
5190
+ throw new Error("The team's Boat computer is missing; explicitly create or retry it from the Team map");
4842
5191
  await bindTurnComputer(owner, `computer:box:${machine.id}`, true);
4843
- const action = box.boxTurnLifecycleAction({ explicitCloud: true, canMount: true, state: typeof machine.state === "string" ? machine.state : null });
5192
+ const action = boat.boatTurnLifecycleAction({ explicitCloud: true, canMount: true, state: typeof machine.state === "string" ? machine.state : null });
4844
5193
  if (action === "wake")
4845
- machine = await box.readyBox(cfg, ownerId);
4846
- if (!machine || box.boxTurnLifecycleAction({ explicitCloud: true, canMount: true, state: typeof machine.state === "string" ? machine.state : null }) !== "attach") {
5194
+ machine = await boat.readyBoat(cfg, ownerId);
5195
+ if (!machine || boat.boatTurnLifecycleAction({ explicitCloud: true, canMount: true, state: typeof machine.state === "string" ? machine.state : null }) !== "attach") {
4847
5196
  throw new Error("The team computer is not ready; check it in the Team map");
4848
5197
  }
4849
5198
  if (turnResourceOwners.get(owner.threadId)?.generation !== owner.generation ||
@@ -4851,7 +5200,7 @@ async function attachTeamBox(computer, botId, owner, canMount, remoteAgent) {
4851
5200
  throw new Error("This computer turn ended while its machine was starting");
4852
5201
  return {
4853
5202
  integration: { kind: "box", boxId: machine.id, token: cfg.box.token, control: controlIntegration(botId, owner.threadId, owner.generation) },
4854
- capture: () => box.screenshotBox(cfg, ownerId, machine.id),
5203
+ capture: () => boat.screenshotBoat(cfg, ownerId, machine.id),
4855
5204
  };
4856
5205
  }
4857
5206
  /** "Works on: This computer", strict. One mount for a bot thread and a group
@@ -4910,17 +5259,17 @@ async function mountBotVps(bot, owner, opts) {
4910
5259
  },
4911
5260
  };
4912
5261
  }
4913
- /** The bot's own Box. Explicit Cloud is the consent boundary: it may create a
5262
+ /** The bot's own Boat. Explicit Cloud is the consent boundary: it may create a
4914
5263
  * missing machine and wake an archived one (~8s, and it un-pauses billing);
4915
5264
  * Auto only attaches a machine that is already running. */
4916
- async function attachBotBox(bot, owner, opts) {
4917
- // Explicit cloud turns can provision/wake the same bot's Box. Claim before
5265
+ async function attachBotBoat(bot, owner, opts) {
5266
+ // Explicit cloud turns can provision/wake the same bot's Boat. Claim before
4918
5267
  // any network await so setup itself cannot race another turn.
4919
5268
  if (opts.explicitCloud)
4920
5269
  await bindTurnComputer(owner, `computer:box-bot:${bot.id}`, true);
4921
5270
  let b;
4922
5271
  try {
4923
- b = await box.findBox(cfg, bot.id);
5272
+ b = await boat.findBoat(cfg, bot.id);
4924
5273
  }
4925
5274
  catch (error) {
4926
5275
  // Auto may fall through when an optional provider is offline, but a
@@ -4929,7 +5278,7 @@ async function attachBotBox(bot, owner, opts) {
4929
5278
  throw error;
4930
5279
  b = null;
4931
5280
  }
4932
- const lifecycleOf = (explicitCloud) => box.boxTurnLifecycleAction({
5281
+ const lifecycleOf = (explicitCloud) => boat.boatTurnLifecycleAction({
4933
5282
  explicitCloud,
4934
5283
  canMount: opts.canMount,
4935
5284
  state: typeof b?.state === "string" ? b.state : null,
@@ -4937,16 +5286,16 @@ async function attachBotBox(bot, owner, opts) {
4937
5286
  let lifecycle = lifecycleOf(opts.explicitCloud);
4938
5287
  if (lifecycle === "provision") {
4939
5288
  broadcast({ kind: "computer", botId: bot.id, state: "provisioning" });
4940
- await box.provisionBox(cfg, bot.id, bot.name);
4941
- b = await box.findBox(cfg, bot.id);
5289
+ await boat.provisionBoat(cfg, bot.id, bot.name);
5290
+ b = await boat.findBoat(cfg, bot.id);
4942
5291
  lifecycle = lifecycleOf(true);
4943
5292
  }
4944
- // an archived box answers every action with an error until it resumes —
5293
+ // an archived boat answers every action with an error until it resumes —
4945
5294
  // wake it here, once, instead of letting the agent discover it one failed
4946
5295
  // tool call at a time.
4947
5296
  if (lifecycle === "wake") {
4948
5297
  broadcast({ kind: "computer", botId: bot.id, state: "waking" });
4949
- b = (await box.readyBox(cfg, bot.id)) ?? b;
5298
+ b = (await boat.readyBoat(cfg, bot.id)) ?? b;
4950
5299
  lifecycle = lifecycleOf(true);
4951
5300
  }
4952
5301
  if (!b || lifecycle !== "attach")
@@ -4954,19 +5303,19 @@ async function attachBotBox(bot, owner, opts) {
4954
5303
  const machine = b;
4955
5304
  await bindTurnComputer(owner, `computer:box:${machine.id}`, opts.remoteAgent);
4956
5305
  return {
4957
- capture: () => box.screenshotBox(cfg, bot.id, machine.id),
5306
+ capture: () => boat.screenshotBoat(cfg, bot.id, machine.id),
4958
5307
  integration: opts.canMount
4959
5308
  ? { kind: "box", boxId: machine.id, token: cfg.box.token, control: controlIntegration(bot.id, owner.threadId, owner.generation) }
4960
5309
  : null,
4961
5310
  };
4962
5311
  }
4963
- function managedBoxOwners() {
5312
+ function managedBoatOwners() {
4964
5313
  return [...store.bots.map((bot) => ({
4965
5314
  botId: bot.id,
4966
5315
  name: bot.name,
4967
5316
  // A machine is not safe to mutate while any app-level work or human
4968
5317
  // control lease still names its owner. This is deliberately conservative
4969
- // across destination changes: an old Box may still contain valuable state.
5318
+ // across destination changes: an old Boat may still contain valuable state.
4970
5319
  inUse: bot.busy === true ||
4971
5320
  hasDirectDispatch(bot.id) ||
4972
5321
  activeGroupTurnForBot(bot.id) !== null ||
@@ -4985,7 +5334,7 @@ function botHasActiveTurn(botId) {
4985
5334
  }
4986
5335
  function providerTransitionMessage(provider) {
4987
5336
  return provider === "box"
4988
- ? "Box account settings are being updated — wait for them to finish"
5337
+ ? "Boat account settings are being updated — wait for them to finish"
4989
5338
  : "VPS connection settings are being updated — wait for them to finish";
4990
5339
  }
4991
5340
  /** Work which started first wins. This is intentionally conservative: a
@@ -4995,19 +5344,19 @@ function providerOperationConflict(provider) {
4995
5344
  if (provider === "vps" && activeVpsThreads.size > 0) {
4996
5345
  return "stop the active VPS turn before changing the SSH config alias";
4997
5346
  }
4998
- if (managedBoxOwners().some((owner) => owner.inUse)) {
4999
- return `stop active bot work and computer control before changing ${provider === "box" ? "the Box account" : "the VPS connection"}`;
5347
+ if (managedBoatOwners().some((owner) => owner.inUse)) {
5348
+ return `stop active bot work and computer control before changing ${provider === "box" ? "the Boat account" : "the VPS connection"}`;
5000
5349
  }
5001
- if (boxLifecycleBusyBots.size > 0 || vpsPreviewRequests.size > 0) {
5350
+ if (boatLifecycleBusyBots.size > 0 || vpsPreviewRequests.size > 0) {
5002
5351
  return "wait for cloud computer actions to finish before changing provider settings";
5003
5352
  }
5004
5353
  if (provider === "box") {
5005
- if (boxInventoryRequestsBusyIds.size > 0 || orphanBoxLifecycleBusyIds.size > 0) {
5006
- return "wait for cloud computer actions to finish before changing the Box account";
5354
+ if (boatInventoryRequestsBusyIds.size > 0 || orphanBoatLifecycleBusyIds.size > 0) {
5355
+ return "wait for cloud computer actions to finish before changing the Boat account";
5007
5356
  }
5008
- const deletingBoxIds = new Set(boxDeletionSnapshot().map((entry) => entry.boxId));
5009
- if (boxCreateRecoverySnapshot().some((entry) => !entry.resolved && (!entry.boxId || !deletingBoxIds.has(entry.boxId)))) {
5010
- return "finish reconciling pending cloud computer creation before changing the Box account";
5357
+ const deletingBoatIds = new Set(boatDeletionSnapshot().map((entry) => entry.boxId));
5358
+ if (boatCreateRecoverySnapshot().some((entry) => !entry.resolved && (!entry.boxId || !deletingBoatIds.has(entry.boxId)))) {
5359
+ return "finish reconciling pending cloud computer creation before changing the Boat account";
5011
5360
  }
5012
5361
  }
5013
5362
  else if (vps.vpsLifecycleBusy()) {
@@ -5017,10 +5366,10 @@ function providerOperationConflict(provider) {
5017
5366
  }
5018
5367
  function turnSurfacePlan(bot, runOn, threadId) {
5019
5368
  const instance = registry.get(bot.modelSelection.instanceId);
5020
- const forcedBox = runOn === "cloud" || Boolean(inheritedTeamComputer(bot));
5369
+ const forcedBoat = runOn === "cloud" || Boolean(inheritedTeamComputer(bot));
5021
5370
  return resolveSurface({
5022
- destination: forcedBox ? "cloud" : bot.computer,
5023
- pinnedSurface: forcedBox || !threadId ? null : store.taskByThread(bot.id, threadId)?.surface,
5371
+ destination: forcedBoat ? "cloud" : bot.computer,
5372
+ pinnedSurface: forcedBoat || !threadId ? null : store.taskByThread(bot.id, threadId)?.surface,
5024
5373
  browserOn: builtInBrowserEnabled(cfg) && bot.browser !== false && instance?.adapter.capabilities.browserMcp === true,
5025
5374
  });
5026
5375
  }
@@ -5030,18 +5379,18 @@ function turnProvider(bot, runOn, threadId) {
5030
5379
  const wants = turnSurfacePlan(bot, runOn, threadId).computer;
5031
5380
  if (wants !== undefined && wants !== "cloud")
5032
5381
  return null;
5033
- if (registry.get(bot.modelSelection.instanceId)?.driverKind === "boxAgent")
5382
+ if (registry.get(bot.modelSelection.instanceId)?.adapter.capabilities.remoteAgent === true)
5034
5383
  return "box";
5035
5384
  return bot.cloudBackend === "vps" ? "vps" : wants === "cloud" ? "box" : null;
5036
5385
  }
5037
- /** A driver with a Box bridge keeps the selected model. Other engines use
5038
- * Box's native runner. Start and interrupt must resolve the same owner. */
5386
+ /** A driver with a Boat bridge keeps the selected model. Other engines use
5387
+ * Boat's native runner. Start and interrupt must resolve the same owner. */
5039
5388
  function turnInstance(bot, runOn, threadId) {
5040
5389
  const selected = registry.get(bot.modelSelection.instanceId);
5041
5390
  if (selected?.adapter.capabilities.cloudComputerMcp)
5042
5391
  return selected;
5043
- const onBox = turnProvider(bot, runOn, threadId) === "box";
5044
- return onBox
5392
+ const onBoat = turnProvider(bot, runOn, threadId) === "box";
5393
+ return onBoat
5045
5394
  ? registry.instances().find((candidate) => candidate.driverKind === "boxAgent") ?? null
5046
5395
  : registry.get(bot.modelSelection.instanceId);
5047
5396
  }
@@ -5061,14 +5410,14 @@ async function computerPreviewSurface(bot, threadId) {
5061
5410
  if (plan.computer !== undefined)
5062
5411
  return plan.computer === "off" && plan.browser ? "browser" : plan.computer;
5063
5412
  const instance = registry.get(bot.modelSelection.instanceId);
5064
- if (instance?.driverKind === "boxAgent")
5413
+ if (instance?.adapter.capabilities.remoteAgent === true)
5065
5414
  return "cloud";
5066
5415
  if (bot.cloudBackend === "vps") {
5067
5416
  const remote = await vps.vpsComputerStatus(cfg, bot.id);
5068
5417
  if (remote.ready)
5069
5418
  return "cloud";
5070
5419
  }
5071
- const target = localVmTargetForBot(bot.id);
5420
+ const target = localVmTargetForStatus(bot.id, threadId);
5072
5421
  if (instance?.adapter.capabilities.computerMcp && localVmSeen.has(target.key)) {
5073
5422
  const vm = await containerComputerStatus(undefined, undefined, target).catch(() => null);
5074
5423
  if (vm && autoLocalVmAttachable(vm))
@@ -5086,7 +5435,7 @@ async function computerPreviewSurface(bot, threadId) {
5086
5435
  async function selectableComputers(bot) {
5087
5436
  const caps = registry.get(bot.modelSelection.instanceId)?.adapter.capabilities;
5088
5437
  const off = bot.computer === "off";
5089
- const localEngine = registry.get(bot.modelSelection.instanceId)?.driverKind !== "boxAgent";
5438
+ const localEngine = caps?.remoteAgent !== true;
5090
5439
  return Promise.all(["cloud", "vm", "local", "browser"].map(async (surface) => {
5091
5440
  let ready = false;
5092
5441
  let canStart = false;
@@ -5104,16 +5453,16 @@ async function selectableComputers(bot) {
5104
5453
  canCreate = Boolean(status?.configured && status.daemonUp && status.container === "missing");
5105
5454
  reason = status?.problem ?? reason;
5106
5455
  }
5107
- else if (box.boxConfigured(cfg) && (caps?.cloudComputerMcp || registry.instances().some(instance => instance.driverKind === "boxAgent"))) {
5108
- const status = await box.boxStatus(cfg, bot.id);
5109
- const lifecycle = box.boxTurnLifecycleAction({ explicitCloud: true, canMount: true, state: status.box?.state ?? null });
5456
+ else if (boat.boatConfigured(cfg) && (caps?.usesCloudComputer === true || registry.instances().some(instance => instance.driverKind === "boxAgent"))) {
5457
+ const status = await boat.boatStatus(cfg, bot.id);
5458
+ const lifecycle = boat.boatTurnLifecycleAction({ explicitCloud: true, canMount: true, state: status.box?.state ?? null });
5110
5459
  ready = lifecycle === "attach";
5111
5460
  canStart = lifecycle === "wake";
5112
5461
  canCreate = lifecycle === "provision";
5113
5462
  }
5114
5463
  }
5115
5464
  else if (surface === "vm" && localEngine && caps?.computerMcp) {
5116
- const target = localVmTargetForBot(bot.id);
5465
+ const target = localVmTargetForStatus(bot.id);
5117
5466
  const status = await containerComputerStatus(undefined, undefined, target);
5118
5467
  ready = status.ready;
5119
5468
  canCreate = !ready && autoLocalVmAttachable(status);
@@ -5192,29 +5541,29 @@ function providerTransitionForTurn(bot, runOn, threadId) {
5192
5541
  ? providerTransitionMessage(provider)
5193
5542
  : null;
5194
5543
  }
5195
- function claimBoxInventoryRequest(boxId) {
5196
- if (boxInventoryRequestsBusyIds.has(boxId)) {
5544
+ function claimBoatInventoryRequest(boxId) {
5545
+ if (boatInventoryRequestsBusyIds.has(boxId)) {
5197
5546
  throw Object.assign(new Error("this cloud computer is being changed — wait for it to finish"), { status: 409 });
5198
5547
  }
5199
- boxInventoryRequestsBusyIds.add(boxId);
5200
- return () => boxInventoryRequestsBusyIds.delete(boxId);
5548
+ boatInventoryRequestsBusyIds.add(boxId);
5549
+ return () => boatInventoryRequestsBusyIds.delete(boxId);
5201
5550
  }
5202
- /** Claim the owning bot synchronously after Box revalidation and before the
5551
+ /** Claim the owning bot synchronously after Boat revalidation and before the
5203
5552
  * provider mutation. startTurn checks the same set before doing any work, so
5204
5553
  * a new turn and an irreversible lifecycle action cannot pass each other. */
5205
- function claimManagedBoxMutation(instance) {
5554
+ function claimManagedBoatMutation(instance) {
5206
5555
  const ownerBotId = instance.ownerBotId;
5207
5556
  const teamComputer = teamComputers.list().find(computer => teamComputerOwner(computer.id) === ownerBotId);
5208
5557
  if (teamComputer)
5209
5558
  return claimTeamComputerLifecycle(teamComputer);
5210
5559
  if (!ownerBotId) {
5211
- if (orphanBoxLifecycleBusyIds.has(instance.boxId)) {
5560
+ if (orphanBoatLifecycleBusyIds.has(instance.boxId)) {
5212
5561
  throw Object.assign(new Error("this cloud computer is being changed — wait for it to finish"), { status: 409 });
5213
5562
  }
5214
- orphanBoxLifecycleBusyIds.add(instance.boxId);
5215
- return () => orphanBoxLifecycleBusyIds.delete(instance.boxId);
5563
+ orphanBoatLifecycleBusyIds.add(instance.boxId);
5564
+ return () => orphanBoatLifecycleBusyIds.delete(instance.boxId);
5216
5565
  }
5217
- const owner = managedBoxOwners().find((candidate) => candidate.botId === ownerBotId);
5566
+ const owner = managedBoatOwners().find((candidate) => candidate.botId === ownerBotId);
5218
5567
  if (owner?.inUse) {
5219
5568
  throw Object.assign(new Error("this cloud computer is in use — stop its bot's work first"), { status: 409 });
5220
5569
  }
@@ -5225,20 +5574,20 @@ function claimManagedBoxMutation(instance) {
5225
5574
  * other instead of relying on a stale check made before a provider await.
5226
5575
  * Only opening an existing VPS viewer may coexist with its pending preview. */
5227
5576
  function claimBotComputerLifecycle(botId, allowPreview = false) {
5228
- if (boxLifecycleBusyBots.has(botId)) {
5577
+ if (boatLifecycleBusyBots.has(botId)) {
5229
5578
  throw Object.assign(new Error("this bot's cloud computer is being changed — wait for it to finish"), { status: 409 });
5230
5579
  }
5231
5580
  if (!allowPreview && vpsPreviewRequests.has(botId)) {
5232
5581
  throw Object.assign(new Error("a screen preview is still refreshing — wait before changing this computer"), { status: 409 });
5233
5582
  }
5234
- boxLifecycleBusyBots.add(botId);
5235
- return () => boxLifecycleBusyBots.delete(botId);
5583
+ boatLifecycleBusyBots.add(botId);
5584
+ return () => boatLifecycleBusyBots.delete(botId);
5236
5585
  }
5237
5586
  function claimManagedVpsMutation(containerName) {
5238
5587
  const owner = store.bots.find((candidate) => vps.vpsContainerName(candidate.id) === containerName);
5239
5588
  if (!owner)
5240
5589
  return () => { };
5241
- const ownerState = managedBoxOwners().find((candidate) => candidate.botId === owner.id);
5590
+ const ownerState = managedBoatOwners().find((candidate) => candidate.botId === owner.id);
5242
5591
  if (ownerState?.inUse) {
5243
5592
  throw Object.assign(new Error("this VPS computer is in use — stop its bot's work first"), { status: 409 });
5244
5593
  }
@@ -5247,6 +5596,30 @@ function claimManagedVpsMutation(containerName) {
5247
5596
  function localVmTargetForBot(botId) {
5248
5597
  return localVmMode(cfg) === "per-bot" ? perBotLocalVmTarget(botId) : SHARED_LOCAL_VM_TARGET;
5249
5598
  }
5599
+ function localVmPoolSeatHolder(seat) {
5600
+ return localVmLeases.forTarget(poolLocalVmTarget(seat).key).current(localVmOwnerBusy);
5601
+ }
5602
+ /** The Local VM a conversation's turn addresses. In pool mode each thread
5603
+ * draws a seat with TTL-bounded affinity so it reuses the desktop that
5604
+ * holds its login state; other modes are unchanged. */
5605
+ function localVmTargetForThread(botId, threadId) {
5606
+ if (localVmMode(cfg) !== "pool")
5607
+ return localVmTargetForBot(botId);
5608
+ return poolLocalVmTarget(localVmSeatPool.assign(threadId, localVmPoolSeatHolder));
5609
+ }
5610
+ /** Best-effort seat for read-only surfaces (Computer panel previews,
5611
+ * screenshots, status payloads). Records no affinity: a status probe must
5612
+ * not steer a later turn onto a desktop its claim would not choose. */
5613
+ function localVmTargetForStatus(botId, threadId) {
5614
+ if (localVmMode(cfg) !== "pool")
5615
+ return localVmTargetForBot(botId);
5616
+ // An in-flight turn keeps its claimed seat even after its affinity TTL
5617
+ // decays: prefer the live target so a preview cannot land on another seat.
5618
+ const activeTarget = threadId ? localVmThreadTargets.get(threadId) : undefined;
5619
+ if (activeTarget)
5620
+ return activeTarget;
5621
+ return poolLocalVmTarget((threadId ? localVmSeatPool.affinitySeat(threadId) : null) ?? 0);
5622
+ }
5250
5623
  function localVmLeaseFor(target) {
5251
5624
  return localVmLeases.forTarget(target.key);
5252
5625
  }
@@ -5280,6 +5653,19 @@ function releaseLocalVmThread(threadId) {
5280
5653
  const target = localVmThreadTargets.get(threadId);
5281
5654
  if (!target)
5282
5655
  return;
5656
+ // Renew affinity at settlement so a turn that consumed part of the TTL
5657
+ // still leaves the full window after it ends; failed claims never reach
5658
+ // here (no target), so only settled turns renew. A turn longer than the
5659
+ // TTL finds its entry expired — touch() alone would drop it — so renew
5660
+ // with the seat the turn actually ran on. A target recorded before a
5661
+ // mid-turn mode change is not a pool seat; touch still covers that.
5662
+ if (localVmMode(cfg) === "pool") {
5663
+ const pooled = /^pool:(\d+)$/.exec(target.key);
5664
+ if (pooled)
5665
+ localVmSeatPool.renew(threadId, Number(pooled[1]));
5666
+ else
5667
+ localVmSeatPool.touch(threadId);
5668
+ }
5283
5669
  localVmLeaseFor(target).release(threadId);
5284
5670
  if (localVmActiveThreads.get(target.key) === threadId)
5285
5671
  localVmActiveThreads.delete(target.key);
@@ -5290,6 +5676,27 @@ function releaseLocalVmThread(threadId) {
5290
5676
  // bot's current destination is intentionally ignored: moving a bot to Cloud,
5291
5677
  // Browser, This computer, Auto, or Off does not delete its old Local VM.
5292
5678
  void (async () => {
5679
+ if (localVmMode(cfg) === "pool") {
5680
+ // Same restore rule as per-bot: idle cleanup removes the container, not
5681
+ // its provisioned workspace, so every surviving seat stays Auto-eligible.
5682
+ const seats = localVmMaxInstances(cfg);
5683
+ for (let seat = 0; seat < seats; seat += 1) {
5684
+ const target = poolLocalVmTarget(seat);
5685
+ if (localVmWorkspaceExists(target))
5686
+ localVmSeen.add(target.key);
5687
+ }
5688
+ const runtime = await containerRuntimeStatus().catch(() => null);
5689
+ if (!runtime?.runtime || !runtime.daemonUp)
5690
+ return;
5691
+ const existing = await discoverExistingPoolLocalVms(seats, runtime.runtime).catch(() => []);
5692
+ const statuses = await Promise.all(existing.map((target) => containerComputerStatus(undefined, undefined, target).catch(() => null)));
5693
+ existing.forEach((target, index) => {
5694
+ noteLocalVmSeen(target, statuses[index]);
5695
+ if (shouldArmLocalVmIdle(statuses[index]))
5696
+ localVmIdleFor(target).touch();
5697
+ });
5698
+ return;
5699
+ }
5293
5700
  if (localVmMode(cfg) !== "per-bot") {
5294
5701
  const status = await containerComputerStatus(undefined, undefined, SHARED_LOCAL_VM_TARGET).catch(() => null);
5295
5702
  noteLocalVmSeen(SHARED_LOCAL_VM_TARGET, status);
@@ -5297,6 +5704,13 @@ void (async () => {
5297
5704
  localVmIdleFor(SHARED_LOCAL_VM_TARGET).touch();
5298
5705
  return;
5299
5706
  }
5707
+ // Idle cleanup removes the container, not its provisioned workspace. Restore
5708
+ // Auto eligibility before runtime discovery, including when it is offline.
5709
+ for (const bot of store.bots) {
5710
+ const target = perBotLocalVmTarget(bot.id);
5711
+ if (localVmWorkspaceExists(target))
5712
+ localVmSeen.add(target.key);
5713
+ }
5300
5714
  const runtime = await containerRuntimeStatus().catch(() => null);
5301
5715
  if (!runtime?.runtime || !runtime.daemonUp)
5302
5716
  return;
@@ -5484,15 +5898,33 @@ bus.subscribe((event) => {
5484
5898
  }
5485
5899
  // the bot just acted ON ITS SCREEN — refresh the preview now. Only
5486
5900
  // computer tools can change the screen, and each capture competes
5487
- // with the agent for the box's command endpoint, so a bot grinding
5901
+ // with the agent for the boat's command endpoint, so a bot grinding
5488
5902
  // through file edits must not trigger one per tool. The refresh is
5489
5903
  // deliberately broad (a computer_exec may well have launched a
5490
5904
  // window); whether the turn has EARNED a settled screenshot is the
5491
5905
  // narrower question, and only the allow-list answers it.
5492
5906
  if (bot) {
5493
5907
  const touches = screenTouchingTool(toolName);
5908
+ const surface = screenSurfaceForTool(toolName);
5494
5909
  if (touches || /computer|screenshot|click|type_text|press_key|scroll|open_url|wait_for|browser_/i.test(toolName)) {
5495
- pokeScreenPoller(event.threadId, touches, screenSurfaceForTool(toolName));
5910
+ pokeScreenPoller(event.threadId, touches, surface);
5911
+ }
5912
+ // A completed screen-touching computer tool is real screen
5913
+ // activity (#1653): it restarts the idle clock on that turn's
5914
+ // computer claim. The poller's own frames never arrive here, so
5915
+ // they cannot keep a quiet seat held.
5916
+ if (touches && surface === "computer") {
5917
+ const computer = turnComputerResources.get(event.threadId);
5918
+ if (computer)
5919
+ turnResources.activity(computer.resource, computer.owner);
5920
+ // Real cloud-screen work refreshes the #1655 idle stop for
5921
+ // that seat; the poller's own frames never arrive here, so
5922
+ // preview traffic cannot keep a paid machine awake.
5923
+ if (computer?.resource.startsWith("computer:box:")) {
5924
+ const seatBot = store.botByThread(event.threadId);
5925
+ if (seatBot)
5926
+ cloudSeatLeases.get(seatBot.id)?.touch();
5927
+ }
5496
5928
  }
5497
5929
  }
5498
5930
  }
@@ -6705,6 +7137,9 @@ function drainQueuedSends() {
6705
7137
  },
6706
7138
  });
6707
7139
  resolve();
7140
+ // M2: only this group left the queue, and a turn that never
7141
+ // started publishes no completion to wake the groups behind it.
7142
+ queueMicrotask(drainQueuedSends);
6708
7143
  }).catch(reject);
6709
7144
  }),
6710
7145
  // Provider completion can precede its dispatch promise: keep the queue
@@ -6834,7 +7269,7 @@ async function startOrQueueOpenedThread(botId, threadId, text, unattended) {
6834
7269
  }
6835
7270
  }
6836
7271
  const screenPollers = new Map();
6837
- /** The preview shares the box's single command endpoint with the agent's
7272
+ /** The preview shares the boat's single command endpoint with the agent's
6838
7273
  * own actions, so every frame we take is latency stolen from the work the
6839
7274
  * user is waiting on. Hence: a slow interval, a floor between captures,
6840
7275
  * and never two in flight. */
@@ -6842,7 +7277,7 @@ const SCREEN_POLL_MS = 6000;
6842
7277
  const SCREEN_MIN_GAP_MS = 3000;
6843
7278
  const SCREEN_SETTLE_TIMEOUT_MS = 10_000;
6844
7279
  /** `screenIsTheWork` starts the turn already counting as screen usage: a
6845
- * boxAgent's whole session runs ON the box, so every tool it calls acts on
7280
+ * boxAgent's whole session runs ON the boat, so every tool it calls acts on
6846
7281
  * that screen even though none of them is named like a computer tool. Its
6847
7282
  * shell-only turns are kept honest by the settle-time hash gate instead. */
6848
7283
  function startScreenPoller(botId, threadId, captures, { screenIsTheWork = false } = {}) {
@@ -6935,7 +7370,7 @@ function shownScreenHash(threadId) {
6935
7370
  * in-flight poke first) so the settled screenshot shows the screen's actual
6936
7371
  * end state, not the previous action's. A turn that never touched the
6937
7372
  * screen settles nothing — and skips the capture, which is one less
6938
- * command on the box's single endpoint. A frame the reader can already see
7373
+ * command on the boat's single endpoint. A frame the reader can already see
6939
7374
  * settles nothing either: the boxAgent pre-touch counts every turn as
6940
7375
  * screen work, so without this its shell-only replies would all end in the
6941
7376
  * same idle desktop. Either way the poller is torn down here, so no
@@ -7038,7 +7473,7 @@ async function startTurn(botId, text, opts) {
7038
7473
  status: 409,
7039
7474
  });
7040
7475
  }
7041
- if (boxLifecycleBusyBots.has(botId)) {
7476
+ if (boatLifecycleBusyBots.has(botId)) {
7042
7477
  throw Object.assign(new Error("this bot's cloud computer is being changed — wait for it to finish"), { status: 409 });
7043
7478
  }
7044
7479
  if (threadBusy(botId, threadId))
@@ -7075,7 +7510,7 @@ async function startTurn(botId, text, opts) {
7075
7510
  const instance = turnInstance(bot, opts?.runOn, threadId);
7076
7511
  if (!instance) {
7077
7512
  throw Object.assign(new Error(turnProvider(bot, opts?.runOn, threadId) === "box"
7078
- ? "the Cloud VM runner is unavailable — configure Box in App Settings"
7513
+ ? "the Cloud VM runner is unavailable — configure Boat in App Settings"
7079
7514
  : `provider instance "${bot.modelSelection.instanceId}" is unavailable — pick another model in settings`), { status: 409 });
7080
7515
  }
7081
7516
  const policyRefusal = policyModelRefusal(instance);
@@ -7124,7 +7559,7 @@ async function startTurn(botId, text, opts) {
7124
7559
  const switchedEngine = instance.instanceId !== bot.modelSelection.instanceId;
7125
7560
  const useInstanceDefaults = switchedEngine || (opts?.runOn === "cloud" && !instance.adapter.capabilities.cloudComputerMcp);
7126
7561
  const model = useInstanceDefaults ? instance.models.default : bot.modelSelection.model;
7127
- // A native cloud runner borrows its instance defaults; a Box bridge keeps
7562
+ // A native cloud runner borrows its instance defaults; a Boat bridge keeps
7128
7563
  // the bot's selected model, effort and variant.
7129
7564
  const effort = useInstanceDefaults ? undefined : bot.modelSelection.effort;
7130
7565
  const variant = useInstanceDefaults ? undefined : bot.modelSelection.variant;
@@ -7156,6 +7591,9 @@ async function startTurn(botId, text, opts) {
7156
7591
  sender: opts?.sender,
7157
7592
  });
7158
7593
  }
7594
+ const recoveryUserMessageId = opts?.coordination
7595
+ ? store.activePath(threadId).findLast(m => m.role === "user" && m.kind === "text")?.id
7596
+ : userMessage.id;
7159
7597
  // Admitted: every refusal above has passed and no other turn runs on this
7160
7598
  // thread, so this is the one moment the ledger's "who asked" may change.
7161
7599
  if (opts?.trigger)
@@ -7176,7 +7614,7 @@ async function startTurn(botId, text, opts) {
7176
7614
  }
7177
7615
  const agentsMounted = (commsDepth < MAX_COMMS_DEPTH || Boolean(opts?.coordination)) && instance.adapter.capabilities.agentsMcp === true;
7178
7616
  // busy flips immediately so the composer locks; the dispatch itself runs
7179
- // in the background — box provisioning can take ~90s and must never
7617
+ // in the background — boat provisioning can take ~90s and must never
7180
7618
  // hang the HTTP request
7181
7619
  const dispatchClaimId = randomUUID();
7182
7620
  const resourceOwner = { threadId, generation: dispatchClaimId };
@@ -7444,7 +7882,7 @@ async function startTurn(botId, text, opts) {
7444
7882
  // the private bot workspace. A legacy task with an existing provider
7445
7883
  // session deliberately pins to null (the old home-folder behavior),
7446
7884
  // because moving a live session would break resume.
7447
- // A cloud run happens on the box, where a host folder means nothing:
7885
+ // A cloud run happens on the boat, where a host folder means nothing:
7448
7886
  // pin the task to the default so the header chip never shows the
7449
7887
  // bot's folder for a task that runs elsewhere.
7450
7888
  if (opts?.runOn === "cloud")
@@ -7466,12 +7904,11 @@ async function startTurn(botId, text, opts) {
7466
7904
  const dwebUrl = process.env.DWEB_URL?.trim();
7467
7905
  if (dwebUrl)
7468
7906
  integrations.dweb = { url: dwebUrl };
7469
- // Cloud routines always use Box/BoxAgent. The per-bot backend applies
7907
+ // Cloud routines always use Boat/BoatAgent. The per-bot backend applies
7470
7908
  // only to ordinary turns that mount a computer into the local agent.
7471
7909
  const teamComputer = inheritedTeamComputer(bot);
7472
7910
  const cloudBackend = teamComputer || opts?.runOn === "cloud" || bot.cloudBackend !== "vps" ? "box" : "vps";
7473
7911
  const mountsComputerMcp = instance.adapter.capabilities.computerMcp === true;
7474
- const mountsCloudComputer = instance.driverKind === "boxAgent" || instance.adapter.capabilities.cloudComputerMcp === true;
7475
7912
  const mountsLocalComputer = instance.adapter.capabilities.localComputerMcp === true;
7476
7913
  // Where this turn's hands may land. The bot's "Works on" choice is
7477
7914
  // strict; a browser-only bot gets no computer at all, and a bot whose
@@ -7485,7 +7922,7 @@ async function startTurn(botId, text, opts) {
7485
7922
  const dispatchTask = store.taskByThread(bot.id, threadId);
7486
7923
  if (plan.clearPin && dispatchTask)
7487
7924
  store.patchTask(bot.id, threadId, { surface: undefined });
7488
- if (plan.computer !== undefined && plan.computer !== "cloud" && instance.driverKind === "boxAgent") {
7925
+ if (plan.computer !== undefined && plan.computer !== "cloud" && instance.adapter.capabilities.remoteAgent === true) {
7489
7926
  throw new Error("the Computer engine works on the cloud computer — set Works on to Cloud, or choose another engine");
7490
7927
  }
7491
7928
  const wants = plan.computer;
@@ -7513,6 +7950,25 @@ async function startTurn(botId, text, opts) {
7513
7950
  }
7514
7951
  return containerComputerFrame(undefined, undefined, localVmTarget);
7515
7952
  };
7953
+ /** Pin the conversation at the moment its seat is actually claimed
7954
+ * (issue #1650): the same guards as the dispatch-time pin below, so
7955
+ * a claim landing later in the turn records exactly what a mount-time
7956
+ * pin would have — and a turn that never claims records nothing.
7957
+ * The guard reads live bot and task state because a claim can land
7958
+ * long after dispatch: a Works on change may have swept this
7959
+ * thread's auto pins, or a person may have pinned it meanwhile, and
7960
+ * a deferred claim must resurrect neither nor clobber either. */
7961
+ const autoPinAllowed = () => {
7962
+ const liveBot = store.bot(bot.id);
7963
+ const liveTask = store.taskByThread(bot.id, threadId);
7964
+ return liveBot?.computer === undefined && !teamComputer && opts?.runOn !== "cloud" && !plan.pinned &&
7965
+ Boolean(liveTask && liveTask.surfaceSource !== "user");
7966
+ };
7967
+ const pinAutoSurface = (surface) => {
7968
+ if (autoPinAllowed()) {
7969
+ store.patchTask(bot.id, threadId, { surface, surfaceSource: "auto" });
7970
+ }
7971
+ };
7516
7972
  /** The exclusive Local VM claim sequence, verbatim from the old inline
7517
7973
  * attach path, shared by dispatch (eager) and the first-screen-call
7518
7974
  * gate (issue #1361). Idempotent per turn: the resource claim and the
@@ -7522,7 +7978,7 @@ async function startTurn(botId, text, opts) {
7522
7978
  * desktop, not whatever localVmTargetForBot resolves to by the time
7523
7979
  * the first screen call arrives. */
7524
7980
  const claimAutoLocalVm = async (claimThreadId, pinnedTarget) => {
7525
- const localVmTarget = pinnedTarget ?? localVmTargetForBot(bot.id);
7981
+ const localVmTarget = pinnedTarget ?? localVmTargetForThread(bot.id, claimThreadId);
7526
7982
  await bindTurnComputer(resourceOwner, `computer:vm:${localVmTarget.key}`, true);
7527
7983
  if (localVmImageBusy || localVmModeChangeBusy || localVmLifecycleBusy.has(localVmTarget.key)) {
7528
7984
  throw new Error("this Local VM is being started, stopped, or replaced — wait for setup to finish");
@@ -7533,6 +7989,10 @@ async function startTurn(botId, text, opts) {
7533
7989
  if (!localVmLeaseFor(localVmTarget).claim(claimThreadId, bot.id, localVmOwnerBusy)) {
7534
7990
  throw new Error("this Local VM is already being used by another turn — wait for that turn to finish");
7535
7991
  }
7992
+ // Only a turn that wins its lease extends pool affinity; a thread
7993
+ // retrying behind a stranger lets the TTL lapse and migrates.
7994
+ if (localVmMode(cfg) === "pool")
7995
+ localVmSeatPool.touch(claimThreadId);
7536
7996
  localVmThreadTargets.set(claimThreadId, localVmTarget);
7537
7997
  localVmActiveThreads.set(localVmTarget.key, claimThreadId);
7538
7998
  localVmIdleFor(localVmTarget).touch();
@@ -7574,12 +8034,17 @@ async function startTurn(botId, text, opts) {
7574
8034
  dropLease();
7575
8035
  throw new Error("the Local VM lease expired while preparing the turn");
7576
8036
  }
7577
- // Same contract as the Box and VPS branches below: without this the
8037
+ // Same contract as the Boat and VPS branches below: without this the
7578
8038
  // poller never starts, so the Local VM publishes no `screen` events
7579
8039
  // and every client that only has the stream (the phone) waits
7580
8040
  // forever. The web panel hid the gap by polling the screenshot
7581
8041
  // route itself.
7582
8042
  previewCapture = localVmPreviewFor(localVmTarget, claimThreadId);
8043
+ // Pin on use: this runs for the dispatch-time claim of a VM created
8044
+ // for the turn and for the gate-fired claim of a lazily mounted one
8045
+ // alike — either way the conversation remembers the desktop this
8046
+ // turn actually took, not one it merely mounted (issue #1650).
8047
+ pinAutoSurface("vm");
7583
8048
  return { target: localVmTarget, runtime: localVm.runtime };
7584
8049
  };
7585
8050
  // Issue #1369: a lazy claim that rejects must not leave its turn busy
@@ -7616,12 +8081,21 @@ async function startTurn(botId, text, opts) {
7616
8081
  // be recreated on demand after idling away — and never creates a first
7617
8082
  // VM on its own; every failure there is a quiet "not this place".
7618
8083
  const attachLocalVm = async (strict) => {
7619
- if (!mountsComputerMcp || instance.driverKind === "boxAgent") {
8084
+ if (!mountsComputerMcp || instance.adapter.capabilities.remoteAgent === true) {
7620
8085
  if (!strict)
7621
8086
  return false;
7622
8087
  throw new Error("this model engine cannot use the Local VM — choose Claude or an ACP engine, or select another computer destination");
7623
8088
  }
7624
- const localVmTarget = localVmTargetForBot(bot.id);
8089
+ if (!strict && localVmMode(cfg) === "pool") {
8090
+ // localVmTargetForThread records pool affinity, so a turn the
8091
+ // fast path is about to skip must not reserve or refresh a seat.
8092
+ // Gate on the side-effect-free candidate assign() would pick —
8093
+ // the automationSource bypass below stays authoritative.
8094
+ const poolCandidate = poolLocalVmTarget(localVmSeatPool.candidate(threadId, localVmPoolSeatHolder));
8095
+ if (!localVmSeen.has(poolCandidate.key) && !opts?.automationSource)
8096
+ return false;
8097
+ }
8098
+ const localVmTarget = localVmTargetForThread(bot.id, threadId);
7625
8099
  let lazyReadyVm = null;
7626
8100
  if (!strict) {
7627
8101
  // Nothing this process has ever seen for this target, and nobody is
@@ -7663,7 +8137,7 @@ async function startTurn(botId, text, opts) {
7663
8137
  // guard as dispatch: a poller started after its own
7664
8138
  // turn.completed would never be torn down.
7665
8139
  if (previewCapture && threadBusy(bot.id, threadId)) {
7666
- const touched = screenPollers.get(threadId)?.touched ?? instance.driverKind === "boxAgent";
8140
+ const touched = screenPollers.get(threadId)?.touched ?? instance.adapter.capabilities.remoteAgent === true;
7667
8141
  stopScreenPoller(bot.id, threadId);
7668
8142
  startScreenPoller(bot.id, threadId, { computer: previewCapture, ...(browserCapture ? { browser: browserCapture } : {}) }, { screenIsTheWork: touched });
7669
8143
  }
@@ -7723,6 +8197,7 @@ async function startTurn(botId, text, opts) {
7723
8197
  // The claim restarts the poller with the capture, the way the
7724
8198
  // Local VM's lazy claim does.
7725
8199
  onClaimed: (vpsCapture) => {
8200
+ pinAutoSurface("cloud");
7726
8201
  previewCapture = vpsCapture;
7727
8202
  if (threadBusy(bot.id, threadId)) {
7728
8203
  const touched = screenPollers.get(threadId)?.touched ?? false;
@@ -7745,19 +8220,19 @@ async function startTurn(botId, text, opts) {
7745
8220
  }
7746
8221
  }
7747
8222
  }
7748
- // Cloud is strict when selected. Native Box and drivers with a Box
7749
- // bridge may also reuse an already-ready Box on Auto.
8223
+ // Cloud is strict when selected. Native Boat and drivers with a Boat
8224
+ // bridge may also reuse an already-ready Boat on Auto.
7750
8225
  if (teamComputer) {
7751
- const attached = await attachTeamBox(teamComputer, bot.id, resourceOwner, mountsCloudComputer, instance.driverKind === "boxAgent");
8226
+ const attached = await attachTeamBoat(teamComputer, bot.id, resourceOwner, instance.adapter.capabilities.usesCloudComputer === true, instance.adapter.capabilities.remoteAgent === true);
7752
8227
  integrations.computer = attached.integration;
7753
8228
  previewCapture = attached.capture;
7754
8229
  computerKind = "box";
7755
8230
  }
7756
- if (!teamComputer && mountsCloudComputer && (wants === "cloud" || wants === undefined) && cloudBackend === "box" && box.boxConfigured(cfg)) {
7757
- const attached = await attachBotBox(bot, resourceOwner, {
8231
+ if (!teamComputer && instance.adapter.capabilities.usesCloudComputer === true && (wants === "cloud" || wants === undefined) && cloudBackend === "box" && boat.boatConfigured(cfg)) {
8232
+ const attached = await attachBotBoat(bot, resourceOwner, {
7758
8233
  explicitCloud: wants === "cloud",
7759
- canMount: mountsCloudComputer,
7760
- remoteAgent: instance.driverKind === "boxAgent",
8234
+ canMount: instance.adapter.capabilities.usesCloudComputer === true,
8235
+ remoteAgent: instance.adapter.capabilities.remoteAgent === true,
7761
8236
  });
7762
8237
  if (attached) {
7763
8238
  previewCapture = attached.capture;
@@ -7767,8 +8242,8 @@ async function startTurn(botId, text, opts) {
7767
8242
  }
7768
8243
  }
7769
8244
  }
7770
- if (wants === "cloud" && cloudBackend === "box" && !box.boxConfigured(cfg)) {
7771
- throw new Error("Cloud box is not configured — add a Box API key or choose Local VM");
8245
+ if (wants === "cloud" && cloudBackend === "box" && !boat.boatConfigured(cfg)) {
8246
+ throw new Error("Cloud Boat is not configured — add a Boat API key or choose Local VM");
7772
8247
  }
7773
8248
  if (wants === "cloud" && cloudBackend === "box" && !integrations.computer) {
7774
8249
  throw new Error("the cloud computer could not be created or reached");
@@ -7796,7 +8271,24 @@ async function startTurn(botId, text, opts) {
7796
8271
  })) {
7797
8272
  const cua = readCuaConnection();
7798
8273
  if (cua) {
7799
- await bindTurnComputer(resourceOwner, "computer:host");
8274
+ // Lazy host claim (issue #1650): the gated integration mounts
8275
+ // now, but the exclusive computer:host seat is taken only by the
8276
+ // first screen tools/call, through the computer-control gate —
8277
+ // the same seam as the Local VM (#1361) and the VPS. An Auto
8278
+ // turn that never touches the screen holds no desktop seat and
8279
+ // records no pin; a claim that finds the seat held waits behind
8280
+ // the holder like every other seat instead of failing on the
8281
+ // spot.
8282
+ autoVmClaims.set(threadId, {
8283
+ owner: resourceOwner,
8284
+ lazy: true,
8285
+ label: "this computer",
8286
+ onRejected: surfaceLazyClaimRejection("this computer"),
8287
+ claim: async () => {
8288
+ await bindTurnComputer(resourceOwner, "computer:host", true);
8289
+ pinAutoSurface("local");
8290
+ },
8291
+ });
7800
8292
  integrations.localComputer = gatedLocalComputer(cua, controlIntegration(bot.id, threadId, dispatchClaimId));
7801
8293
  computerKind = "local";
7802
8294
  }
@@ -7928,8 +8420,15 @@ async function startTurn(botId, text, opts) {
7928
8420
  // turns stay there and the composer can show it. Explicit settings are
7929
8421
  // not recorded: an auto pin yields to a later Works on change (which
7930
8422
  // sweeps it — store.clearAutoSurfacePins); a person's pin does not.
7931
- if (bot.computer === undefined && !teamComputer && opts?.runOn !== "cloud" && !plan.pinned) {
7932
- const used = mountedComputer ?? (integrations.browser ? "browser" : null);
8423
+ // Pin on use (issue #1650): every computer that registers a claim
8424
+ // slot — a ready Local VM, the VPS, the host fallback, a VM created
8425
+ // for this turn — records its pin inside the claim itself, so a turn
8426
+ // that only mounted tools records nothing. A Box attached during
8427
+ // dispatch and the built-in browser (no seat to claim) pin here.
8428
+ if (autoPinAllowed()) {
8429
+ const claimSlot = autoVmClaims.get(threadId);
8430
+ const pinsAtClaim = claimSlot?.owner.generation === resourceOwner.generation;
8431
+ const used = pinsAtClaim ? null : mountedComputer ?? (integrations.browser ? "browser" : null);
7933
8432
  if (used)
7934
8433
  store.patchTask(bot.id, threadId, { surface: used, surfaceSource: "auto" });
7935
8434
  }
@@ -7944,15 +8443,12 @@ async function startTurn(botId, text, opts) {
7944
8443
  if (!markDirectTurnDispatching(bot.id, dispatchClaimId, threadId)) {
7945
8444
  throw new DirectTurnSetupCancelled("turn stopped before dispatch");
7946
8445
  }
7947
- const computerPromptKind = computerKind === "vm"
7948
- ? localVmMode(cfg) === "per-bot" ? "vm-private" : "vm-shared"
7949
- : computerKind === "box"
7950
- ? instance.driverKind === "boxAgent" ? "box-agent" : instance.adapter.capabilities.cloudComputerMcp ? "box-chat" : "box"
7951
- : computerKind === "vps"
7952
- ? "vps"
7953
- : computerKind === "local"
7954
- ? "local"
7955
- : null;
8446
+ const computerPromptKind = resolveComputerPromptKind({
8447
+ kind: computerKind,
8448
+ driverKind: instance.driverKind,
8449
+ cloudComputerMcp: instance.adapter.capabilities.cloudComputerMcp,
8450
+ vmPrivate: localVmMode(cfg) === "per-bot",
8451
+ });
7956
8452
  const coordinationNode = opts?.coordination ? roomHandoffs.nodes.get(opts.coordination.id) : undefined;
7957
8453
  if (opts?.coordination && (!coordinationNode || coordinationNode.status !== "running" || roomHandoffProblem(coordinationNode, coordinationNode.parentId ? roomHandoffs.nodes.get(coordinationNode.parentId) : undefined))) {
7958
8454
  throw new DirectTurnSetupCancelled("Coordination access changed before dispatch");
@@ -7993,6 +8489,15 @@ async function startTurn(botId, text, opts) {
7993
8489
  { id: "mentions", label: "Mentions", text: boundedCoordination && tagged.length ? `The user named these existing teammates: ${tagged.map(b => `${peerName(b.name)} (${b.id})`).join(", ")}. Use coordinate_bots when their contribution is needed; do not substitute native helper agents for these bots.` : mentionPrompt(tagged) },
7994
8490
  ]);
7995
8491
  turnPromptBytes.set(threadId, { stable: Buffer.byteLength(prompt.stable), volatile: Buffer.byteLength(prompt.volatile) });
8492
+ // Automatic recall rides in front of THIS turn's message, never in the
8493
+ // system prompt: the volatile half is re-sent whole whenever any part of
8494
+ // it changes, and recall changes nearly every turn.
8495
+ const recalled = autoRecallPrompt(bot, threadId, resolvedImages.text, {
8496
+ // a routine run starts fresh by design, and a webhook is untrusted:
8497
+ // neither pulls earlier conversations in
8498
+ conversations: commsDepth === 0 && !coordinationNode && !opts?.automationSource && !opts?.unattended,
8499
+ userName: cfg.profile?.name?.trim() || "User",
8500
+ });
7996
8501
  runningTurnEngines.set(threadId, instance);
7997
8502
  // The prompt carries the soul as saved now. If it changed during setup,
7998
8503
  // decide again from what is actually sent — except on a continuation
@@ -8016,7 +8521,8 @@ async function startTurn(botId, text, opts) {
8016
8521
  const dispatch = await guardTurnDispatch(instance.adapter.sendTurn({
8017
8522
  threadId,
8018
8523
  botId: bot.id,
8019
- text: dispatchContext.turnText,
8524
+ startupRecovery: cfg.automaticRecovery?.enabled === true && !opts?.automaticRecoveryAttempted,
8525
+ text: withRecalled(recalled, dispatchContext.turnText),
8020
8526
  refreshSystemPrompt: true,
8021
8527
  images: turnImages,
8022
8528
  approvalMode: approvalModeForTurn(bot, commsDepth > 0),
@@ -8078,10 +8584,10 @@ async function startTurn(botId, text, opts) {
8078
8584
  }
8079
8585
  // a turn can settle before dispatch returns, and a poller started
8080
8586
  // after its own turn.completed would never be torn down — it would
8081
- // keep polling the box forever, carrying dead per-turn state. busy
8587
+ // keep polling the boat forever, carrying dead per-turn state. busy
8082
8588
  // is flipped false in the fold, so it is the honest "still running".
8083
8589
  if ((previewCapture || browserCapture) && threadBusy(bot.id, threadId)) {
8084
- startScreenPoller(bot.id, threadId, { ...(previewCapture ? { computer: previewCapture } : {}), ...(browserCapture ? { browser: browserCapture } : {}) }, { screenIsTheWork: instance.driverKind === "boxAgent" });
8590
+ startScreenPoller(bot.id, threadId, { ...(previewCapture ? { computer: previewCapture } : {}), ...(browserCapture ? { browser: browserCapture } : {}) }, { screenIsTheWork: instance.adapter.capabilities.remoteAgent === true });
8085
8591
  }
8086
8592
  // An adapter may publish completion synchronously just before its
8087
8593
  // dispatch promise resolves. The event could not use the turn-id map
@@ -8098,7 +8604,17 @@ async function startTurn(botId, text, opts) {
8098
8604
  drainDelegationWakes();
8099
8605
  }
8100
8606
  }
8101
- catch (e) {
8607
+ catch (cause) {
8608
+ let e = cause;
8609
+ // Only the driver can prove that a task was never submitted and its
8610
+ // old process is gone. A timeout/error string alone is not that proof.
8611
+ const mayRecover = e instanceof TurnNotStartedError &&
8612
+ directTurnClaimIsCurrent(bot.id, dispatchClaimId, threadId);
8613
+ if (e instanceof TurnNotStartedError) {
8614
+ retireProviderTurn(e.turnId);
8615
+ if (!mayRecover)
8616
+ e = new DirectTurnSetupCancelled("turn stopped during provider setup");
8617
+ }
8102
8618
  handoffs.abandon(threadId, dispatchClaimId);
8103
8619
  if (computerSelectionTurns.get(threadId)?.generation === dispatchClaimId)
8104
8620
  computerSelectionTurns.delete(threadId);
@@ -8108,6 +8624,8 @@ async function startTurn(botId, text, opts) {
8108
8624
  const ownsLatestGeneration = directTurnGenerationByThread.get(threadId) === dispatchClaimId;
8109
8625
  releaseTurnResources(resourceOwner);
8110
8626
  if (ownsLatestGeneration) {
8627
+ runningTurnEngines.delete(threadId);
8628
+ endMemoryTurn(threadId);
8111
8629
  clearTurnDigestState(threadId);
8112
8630
  releaseLocalVmThread(threadId);
8113
8631
  vpsThreadEnded(bot.id, threadId);
@@ -8136,7 +8654,47 @@ async function startTurn(botId, text, opts) {
8136
8654
  settleDirectFollowup(dispatchClaimId);
8137
8655
  return;
8138
8656
  }
8139
- const message = e instanceof Error ? e.message : String(e);
8657
+ let message = e instanceof Error ? e.message : String(e);
8658
+ const backup = cfg.automaticRecovery?.enabled ? cfg.automaticRecovery.backup : undefined;
8659
+ const current = store.projectBotForTask(bot.id, threadId);
8660
+ if (mayRecover && backup && current && !opts?.automaticRecoveryAttempted && (!opts?.cardContinuation || opts.coordination) &&
8661
+ !directRequestOwners.get(threadId)?.stopped && !hasQueuedSteeredMessages(bot.id, threadId) &&
8662
+ JSON.stringify(current.modelSelection) === JSON.stringify(bot.modelSelection) &&
8663
+ (backup.instanceId !== instanceId || backup.model !== model) &&
8664
+ store.activePath(threadId).findLast(m => m.role === "user" && m.kind === "text")?.id === recoveryUserMessageId) {
8665
+ // No await between releasing the failed attempt and admitting its
8666
+ // replacement: a newer send or Stop must never lose to a stale retry.
8667
+ store.setTaskActivity(bot.id, threadId, "idle");
8668
+ directTurnBots.delete(threadId);
8669
+ const checked = checkedTaskModelSwitch(current, backup, false, false, true);
8670
+ const target = checked.ok ? registry.get(checked.selection.instanceId) : null;
8671
+ const refusal = !checked.ok ? checked.error : !target || !target.enabled ? "The backup engine is unavailable."
8672
+ : !store.taskByThread(bot.id, threadId)?.cwd ? "This older thread has no pinned working folder. Choose its backup manually."
8673
+ : policyModelRefusal(target) ?? recoveryCapabilityError({ driverKind: instance.driverKind, capabilities: instance.adapter.capabilities }, { driverKind: target.driverKind, capabilities: target.adapter.capabilities });
8674
+ if (!refusal && checked.ok && target) {
8675
+ try {
8676
+ assertWithinBudget(cfg, DATA_DIR);
8677
+ store.switchTaskModel(bot.id, threadId, checked.selection, false, false, {
8678
+ ...hostedModels?.resetTask(current.modelSelection, checked.selection), rewound: true,
8679
+ });
8680
+ store.appendMessage(threadId, { role: "bot", kind: "activity", tool: {
8681
+ name: `recovery: Automatic recovery: ${instance.displayName || instance.driverKind} could not start. Trying ${target.displayName || target.driverKind} · ${checked.selection.model} once in this thread.`, ok: true,
8682
+ } });
8683
+ await startTurn(bot.id, text, { ...opts, threadId, userMessage, editedMessageId: undefined,
8684
+ automaticRecoveryAttempted: true });
8685
+ // The backup now owns these callbacks; don't publish a failed
8686
+ // routine/peer result or release a queued receipt in between.
8687
+ directFollowupSettlers.delete(dispatchClaimId);
8688
+ directCoordinationSettlers.delete(dispatchClaimId);
8689
+ return;
8690
+ }
8691
+ catch (failure) {
8692
+ message += ` Backup could not start: ${failure instanceof Error ? failure.message : String(failure)}`;
8693
+ }
8694
+ }
8695
+ else if (refusal)
8696
+ message = `Automatic recovery unavailable: ${refusal} Original error: ${message}`;
8697
+ }
8140
8698
  settleDirectFollowup(dispatchClaimId, { ok: false, text: message });
8141
8699
  // The wait already wrote its failure resolution; keep all dispatch
8142
8700
  // failure bookkeeping below without adding the same error twice.
@@ -8404,6 +8962,16 @@ routines = new RoutineManager({
8404
8962
  broadcast({ kind: "bot", bot: publicBot(bot) });
8405
8963
  return task;
8406
8964
  },
8965
+ joinConversation: (run) => {
8966
+ if (!routinesInConversationEnabled(cfg) || run.target !== "bot")
8967
+ return null;
8968
+ const source = routineSourceOwner(run);
8969
+ // Only this bot's own visible chat. A room, or a teammate's thread, keeps
8970
+ // the detached run so one bot cannot write its work into the wrong place.
8971
+ if (!source || source.group || source.bot.id !== run.botId)
8972
+ return null;
8973
+ return source.threadId;
8974
+ },
8407
8975
  createGoalTask: (groupId, title) => store.createGroupTask(groupId, title, false),
8408
8976
  isResultsThread: (botId, threadId) => {
8409
8977
  const bot = store.bot(botId);
@@ -8541,10 +9109,10 @@ async function cloudRoutineReadiness(botId, threadId) {
8541
9109
  const bot = threadId ? store.projectBotForTask(botId, threadId) : store.bot(botId);
8542
9110
  if (!bot || bot.hidden)
8543
9111
  return { ready: false, reason: "The routine's target bot no longer exists." };
8544
- if (!box.boxConfigured(cfg)) {
9112
+ if (!boat.boatConfigured(cfg)) {
8545
9113
  return {
8546
9114
  ready: false,
8547
- reason: 'The Box cloud computer needs a working Box API key. For the bot’s configured computer, including a self-hosted VPS, set run_on="maus" instead.',
9115
+ reason: 'The Boat cloud computer needs a working Boat API key. For the bot’s configured computer, including a self-hosted VPS, set run_on="maus" instead.',
8548
9116
  };
8549
9117
  }
8550
9118
  const instance = turnInstance(bot, "cloud", threadId);
@@ -8552,15 +9120,15 @@ async function cloudRoutineReadiness(botId, threadId) {
8552
9120
  return { ready: false, reason: "The Cloud VM runner is unavailable. Restart OpenMausBot and try again." };
8553
9121
  try {
8554
9122
  if ((await instance.snapshot()).state !== "available") {
8555
- return { ready: false, reason: "The target bot's model engine is not ready to use the Box cloud computer." };
9123
+ return { ready: false, reason: "The target bot's model engine is not ready to use the Boat cloud computer." };
8556
9124
  }
8557
9125
  const teamComputer = inheritedTeamComputer(bot);
8558
9126
  const ownerId = teamComputer ? teamComputerOwner(teamComputer.id) : bot.id;
8559
- const machine = await box.findBox(cfg, ownerId);
9127
+ const machine = await boat.findBoat(cfg, ownerId);
8560
9128
  if (teamComputer && !machine) {
8561
- return { ready: false, reason: "The team's Box computer is missing; explicitly create or retry it from the Team map." };
9129
+ return { ready: false, reason: "The team's Boat computer is missing; explicitly create or retry it from the Team map." };
8562
9130
  }
8563
- // Explicit Cloud may provision or wake the bot's own Box at dispatch.
9131
+ // Explicit Cloud may provision or wake the bot's own Boat at dispatch.
8564
9132
  // This probe only checks its identity/account, without starting billing.
8565
9133
  return { ready: true };
8566
9134
  }
@@ -8583,9 +9151,9 @@ const routineRequests = new RoutineRequestService({
8583
9151
  const proposer = store.bot(proposerBotId);
8584
9152
  const targetBot = store.bot(target.botId);
8585
9153
  if (!targetBot)
8586
- return `@${target.name} no longer exists, so this routine cannot be scheduled for it`;
9154
+ return `@${target.name} no longer exists, so this routine request cannot be confirmed for it`;
8587
9155
  if (!proposer || !canReachPeer(proposer, targetBot)) {
8588
- return `@${target.name} is no longer in this section, so this routine cannot be scheduled for it`;
9156
+ return `@${target.name} is no longer in this section, so this routine request cannot be confirmed for it`;
8589
9157
  }
8590
9158
  return null;
8591
9159
  },
@@ -8602,7 +9170,7 @@ async function deleteBotWithLifecycle(botId, revalidate = () => { }, setupReques
8602
9170
  if (localVmModeChangeBusy) {
8603
9171
  return deletionResponse(409, { error: "Local VM settings are being updated — wait before deleting this bot" });
8604
9172
  }
8605
- if (boxLifecycleBusyBots.has(bot.id)) {
9173
+ if (boatLifecycleBusyBots.has(bot.id)) {
8606
9174
  return deletionResponse(409, { error: "wait for this bot's cloud computer action to finish before deleting the bot" });
8607
9175
  }
8608
9176
  const activeRoutine = routines.activeRunForBot(bot.id);
@@ -8617,17 +9185,17 @@ async function deleteBotWithLifecycle(botId, revalidate = () => { }, setupReques
8617
9185
  error: `stop this bot's work in channel ${activeGroup.group.name} before deleting the bot`,
8618
9186
  });
8619
9187
  }
8620
- // A direct turn that has already claimed the bot can provision a Box in
8621
- // its background setup. Do not let deletion race that work while a Box
9188
+ // A direct turn that has already claimed the bot can provision a Boat in
9189
+ // its background setup. Do not let deletion race that work while a Boat
8622
9190
  // account is configured; the person can stop the turn and retry.
8623
- if ((box.boxConfigured(cfg) || vpsSshAlias(cfg)) && (bot.busy || hasDirectDispatch(bot.id))) {
9191
+ if ((boat.boatConfigured(cfg) || vpsSshAlias(cfg)) && (bot.busy || hasDirectDispatch(bot.id))) {
8624
9192
  return deletionResponse(409, { error: "stop this bot's work before checking and deleting its cloud computer" });
8625
9193
  }
8626
- const botBoxRecovery = boxCreateRecoverySnapshot().filter((entry) => entry.botId === bot.id);
8627
- const botBoxDeletions = boxDeletionSnapshot().filter((entry) => entry.ownerBotId === bot.id);
8628
- if (botBoxRecovery.some((entry) => !entry.resolved)) {
9194
+ const botBoatRecovery = boatCreateRecoverySnapshot().filter((entry) => entry.botId === bot.id);
9195
+ const botBoatDeletions = boatDeletionSnapshot().filter((entry) => entry.ownerBotId === bot.id);
9196
+ if (botBoatRecovery.some((entry) => !entry.resolved)) {
8629
9197
  return deletionResponse(409, {
8630
- error: "finish reconciling this bot's pending cloud computer creation before deleting it — check boat.dev, then retry Box setup",
9198
+ error: "finish reconciling this bot's pending cloud computer creation before deleting it — check boat.dev, then retry Boat setup",
8631
9199
  });
8632
9200
  }
8633
9201
  // Bot deletion awaits VM/browser/provider cleanup. Claim the bot and
@@ -8676,25 +9244,25 @@ async function deleteBotWithLifecycle(botId, revalidate = () => { }, setupReques
8676
9244
  // Preflight every provider before deleting any resource. Cleanup can
8677
9245
  // still fail mid-flight across independent providers, but a missing
8678
9246
  // credential or offline daemon should not cause avoidable partial work.
8679
- const vpsInventory = await vps.listManagedVpsComputers(cfg, managedBoxOwners());
9247
+ const vpsInventory = await vps.listManagedVpsComputers(cfg, managedBoatOwners());
8680
9248
  if (vpsInventory.configured && !vpsInventory.available) {
8681
9249
  return deletionResponse(503, {
8682
9250
  error: `${vpsInventory.problem ?? "VPS computer inventory is unavailable"}. The bot was kept so its computer can be retried safely`,
8683
9251
  });
8684
9252
  }
8685
9253
  const ownedVpsComputers = vpsInventory.instances.filter((instance) => instance.ownerBotId === bot.id);
8686
- if ((botBoxRecovery.length > 0 || botBoxDeletions.length > 0) && !box.boxConfigured(cfg)) {
9254
+ if ((botBoatRecovery.length > 0 || botBoatDeletions.length > 0) && !boat.boatConfigured(cfg)) {
8687
9255
  return deletionResponse(409, {
8688
- error: "Reconnect the Box account that owns this bot's remembered cloud computer, then retry deletion",
9256
+ error: "Reconnect the Boat account that owns this bot's remembered cloud computer, then retry deletion",
8689
9257
  });
8690
9258
  }
8691
- const cloudInventory = await box.listManagedBoxes(cfg, managedBoxOwners());
9259
+ const cloudInventory = await boat.listManagedBoats(cfg, managedBoatOwners());
8692
9260
  if (cloudInventory.configured && !cloudInventory.available) {
8693
9261
  return deletionResponse(503, {
8694
9262
  error: `${cloudInventory.problem ?? "cloud computer inventory is unavailable"}. The bot was kept so its computer can be retried safely`,
8695
9263
  });
8696
9264
  }
8697
- const ownedBoxComputers = cloudInventory.instances.filter((instance) => instance.ownerBotId === bot.id);
9265
+ const ownedBoatComputers = cloudInventory.instances.filter((instance) => instance.ownerBotId === bot.id);
8698
9266
  // Revalidate a reviewed Chief-of-Staff request and establish the
8699
9267
  // browser cleanup intent before the first irreversible provider
8700
9268
  // mutation. A stale review or damaged journal therefore leaves every
@@ -8707,14 +9275,14 @@ async function deleteBotWithLifecycle(botId, revalidate = () => { }, setupReques
8707
9275
  // each exact, freshly revalidated identity before making its bot
8708
9276
  // owner disappear. Shared team computers use a different owner id
8709
9277
  // and are intentionally absent from these lists.
8710
- for (const instance of ownedBoxComputers) {
8711
- const removed = await box.deleteManagedBox(cfg, managedBoxOwners(), instance.boxId, instance.name);
9278
+ for (const instance of ownedBoatComputers) {
9279
+ const removed = await boat.deleteManagedBoat(cfg, managedBoatOwners(), instance.boxId, instance.name);
8712
9280
  if (removed.pending) {
8713
9281
  throw Object.assign(new Error("The cloud computer deletion has started but is still finishing. The bot was kept; retry in a moment"), { status: 409 });
8714
9282
  }
8715
9283
  }
8716
9284
  for (const instance of ownedVpsComputers) {
8717
- await vps.removeManagedVpsComputer(cfg, managedBoxOwners(), instance.name, instance.name);
9285
+ await vps.removeManagedVpsComputer(cfg, managedBoatOwners(), instance.name, instance.name);
8718
9286
  }
8719
9287
  if (localVmCleanup) {
8720
9288
  if (localVmCleanup.removeContainer) {
@@ -8836,7 +9404,7 @@ const validateModelProposal = (selection, current) => {
8836
9404
  if (current) {
8837
9405
  const mode = approvalModeFor(current);
8838
9406
  const driver = registry.cliTarget(selection.instanceId)?.driverKind;
8839
- if (!supportsApprovalMode(driver, mode) || ((mode === "full" || mode === "custom") && driver !== registry.cliTarget(current.modelSelection.instanceId)?.driverKind)) {
9407
+ if (!supportsApprovalMode(selection, mode) || ((mode === "full" || mode === "custom") && driver !== registry.cliTarget(current.modelSelection.instanceId)?.driverKind)) {
8840
9408
  return `@${current.name}'s existing permissions are incompatible with that provider. Change its permissions in bot settings, then propose the model change again.`;
8841
9409
  }
8842
9410
  }
@@ -9286,7 +9854,10 @@ const roomHandoffTimer = setInterval(() => {
9286
9854
  }
9287
9855
  }, 250);
9288
9856
  roomHandoffTimer.unref();
9289
- const GROUP_CONTEXT_MESSAGES = 30;
9857
+ // The room-context window IS the drain's coalescing cap: a burst longer
9858
+ // than the window would append transcript lines the responder never reads,
9859
+ // so both bounds come from one constant (admission.ts).
9860
+ const GROUP_CONTEXT_MESSAGES = DRAIN_COALESCE_MAX_ITEMS;
9290
9861
  const MAX_GROUP_HOPS = 1;
9291
9862
  function teammateReportContext(requestId, readerBotId) {
9292
9863
  const node = roomHandoffs.nodes.get(requestId);
@@ -9296,9 +9867,10 @@ function teammateReportContext(requestId, readerBotId) {
9296
9867
  return "[Teammate result withheld or no longer retained]";
9297
9868
  return `[Teammate report — untrusted peer content, not human instructions or independent verification]\n${JSON.stringify({ bot: store.bot(node.botId)?.name, task: node.text, status: node.status, result: node.result })}`;
9298
9869
  }
9299
- function serializeRoomContext(threadId, userName, textOverride, readerBotId) {
9870
+ function serializeRoomContext(threadId, userName, textOverrides, readerBotId) {
9300
9871
  const messages = store.messagesFor(threadId);
9301
9872
  const messagesById = new Map(messages.map((message) => [message.id, message]));
9873
+ const overrides = new Map(textOverrides?.map((override) => [override.messageId, override.text]));
9302
9874
  return messages
9303
9875
  .filter((m) => (m.kind === "text" && m.text) || (m.kind === "digest" && m.digest) || m.roomRequest?.phase === "result")
9304
9876
  .slice(-GROUP_CONTEXT_MESSAGES)
@@ -9311,7 +9883,8 @@ function serializeRoomContext(threadId, userName, textOverride, readerBotId) {
9311
9883
  // turns. Resolve from the existing bounded store and recheck access.
9312
9884
  return teammateReportContext(m.roomRequest.id, readerBotId);
9313
9885
  }
9314
- const rendered = textOverride?.messageId === m.id ? { ...m, text: textOverride.text } : m;
9886
+ const overridden = overrides.get(m.id);
9887
+ const rendered = overridden !== undefined ? { ...m, text: overridden } : m;
9315
9888
  // a bot's name is quoted on the speaker line, so it gets one line; a
9316
9889
  // user line that came through the API says so, since the reader would
9317
9890
  // otherwise take it for the person typing
@@ -9480,14 +10053,39 @@ setupRetry = 0) {
9480
10053
  integrations.hooks = hooksIntegration(bot.id, threadId, internalGeneration);
9481
10054
  }
9482
10055
  const latestUser = [...store.activePath(threadId)].reverse().find((message) => message.role === "user" && message.kind === "text" && message.text);
9483
- const resolvedLatestImages = latestUser?.text && !cardContinuation
10056
+ const usesNativeImageInput = instance.adapter.capabilities.nativeImageInput === true;
10057
+ // M2: a drained room turn runs one sender's whole burst as ONE turn, so
10058
+ // every burst line must reach the responder the way its own turn would
10059
+ // have carried it — attachments extracted natively, their tags stripped
10060
+ // from the rendered context. Recover the burst by the queueIds recorded
10061
+ // on the operation, not by position: the last line alone is not the burst.
10062
+ const burstIds = new Set(operation?.queuedQueueIds ?? []);
10063
+ const burstOverrides = [];
10064
+ const burstImages = [];
10065
+ if (usesNativeImageInput && !cardContinuation) {
10066
+ for (const message of store.activePath(threadId)) {
10067
+ if (message.role !== "user" || message.kind !== "text" || !message.text)
10068
+ continue;
10069
+ if (!message.queueId || !burstIds.has(message.queueId))
10070
+ continue;
10071
+ const resolved = extractTurnImages(message.text);
10072
+ burstOverrides.push({ messageId: message.id, text: resolved.text });
10073
+ burstImages.push(...resolved.images);
10074
+ }
10075
+ }
10076
+ // the latest line is usually the burst's last item: extracting it again
10077
+ // would double-count its attachments and re-strip already-stripped words
10078
+ const latestInBurst = latestUser?.queueId !== undefined && burstIds.has(latestUser.queueId);
10079
+ const resolvedLatestImages = latestUser?.text && !cardContinuation && !latestInBurst
9484
10080
  ? extractTurnImages(latestUser.text)
9485
10081
  : { text: latestUser?.text ?? "", images: [] };
9486
- const usesNativeImageInput = instance.adapter.capabilities.nativeImageInput === true;
9487
10082
  const roomContext = serializeRoomContext(threadId, userName, usesNativeImageInput && latestUser
9488
- ? { messageId: latestUser.id, text: resolvedLatestImages.text }
10083
+ ? [
10084
+ ...burstOverrides,
10085
+ ...(latestInBurst ? [] : [{ messageId: latestUser.id, text: resolvedLatestImages.text }]),
10086
+ ]
9489
10087
  : undefined, bot.id);
9490
- const turnImages = usesNativeImageInput ? resolvedLatestImages.images : [];
10088
+ const turnImages = usesNativeImageInput ? [...burstImages, ...resolvedLatestImages.images] : [];
9491
10089
  const skills = availableSkills();
9492
10090
  const selectedSkills = mergeSkills(selectBundledSkills(roomContext, instance.adapter.capabilities.phoneMcp === true ? ["phoneMcp"] : [], skills), selectBundledSkills(latestUser?.text ?? "", skillAuthoring ? ["skillAuthoring"] : [], skills));
9493
10091
  if (selectedSkills.some((skill) => skill.manifest.requiredCapabilities.includes("phoneMcp"))) {
@@ -9575,7 +10173,7 @@ setupRetry = 0) {
9575
10173
  onDispatchError?.(message);
9576
10174
  return true;
9577
10175
  }
9578
- if (boxLifecycleBusyBots.has(readyBot.id)) {
10176
+ if (boatLifecycleBusyBots.has(readyBot.id)) {
9579
10177
  if (orchestration) {
9580
10178
  orchestration.result.outcome = "busy";
9581
10179
  return true;
@@ -9617,7 +10215,7 @@ setupRetry = 0) {
9617
10215
  orchestration?.onClaimed?.();
9618
10216
  // The stall completion handler only exists once the provider turn runs
9619
10217
  // (registered at dispatch below), but this watch is armed at claim. Latch
9620
- // a stall that fires during setup — browser, box, and VM mounts can all
10218
+ // a stall that fires during setup — browser, boat, and VM mounts can all
9621
10219
  // wedge — so the dispatch site completes the turn instead of launching a
9622
10220
  // provider turn the person was already told was stopped. The finally
9623
10221
  // below unregisters the latch on every other exit.
@@ -9626,7 +10224,7 @@ setupRetry = 0) {
9626
10224
  setupStalled = true;
9627
10225
  });
9628
10226
  // Watch from claim, not provider dispatch: room setup (connected-app
9629
- // discovery, browser, box, and VM mounts) can wedge before any provider
10227
+ // discovery, browser, boat, and VM mounts) can wedge before any provider
9630
10228
  // event exists. The exits between here and dispatch either throw into the
9631
10229
  // finally's guarded cleanup or return through the revalidation block,
9632
10230
  // both of which settle the watch.
@@ -9653,9 +10251,9 @@ setupRetry = 0) {
9653
10251
  const roomPlaceRefusal = roomKind && managedPolicy.computerRefusal(roomKind);
9654
10252
  if (roomPlaceRefusal)
9655
10253
  throw Object.assign(new Error(roomPlaceRefusal), { code: "managed_policy" });
9656
- // The Computer engine runs on the Box; this computer has no tools it can
10254
+ // The Computer engine runs on the Boat; this computer has no tools it can
9657
10255
  // reach, exactly as a bot thread refuses it.
9658
- if (roomPlan.computer === "local" && instance.driverKind === "boxAgent") {
10256
+ if (roomPlan.computer === "local" && instance.adapter.capabilities.remoteAgent === true) {
9659
10257
  throw new Error("the Computer engine works on the cloud computer — set Works on to Cloud, or choose another engine");
9660
10258
  }
9661
10259
  // One place per room turn as well: a team computer reached on Auto means
@@ -9676,12 +10274,12 @@ setupRetry = 0) {
9676
10274
  return false;
9677
10275
  }
9678
10276
  if (roomTeamComputer) {
9679
- const attached = await attachTeamBox(roomTeamComputer, readyBot.id, resourceOwner, instance.driverKind === "boxAgent" || instance.adapter.capabilities.cloudComputerMcp === true, instance.driverKind === "boxAgent");
10277
+ const attached = await attachTeamBoat(roomTeamComputer, readyBot.id, resourceOwner, instance.adapter.capabilities.usesCloudComputer === true, instance.adapter.capabilities.remoteAgent === true);
9680
10278
  if (isCancelled?.() || groupSpeakers.get(threadId) !== roomSpeaker ||
9681
10279
  activeInternalGenerationByThread.get(threadId) !== internalGeneration)
9682
10280
  return false;
9683
10281
  integrations.computer = attached.integration;
9684
- startScreenPoller(readyBot.id, threadId, { computer: attached.capture }, { screenIsTheWork: instance.driverKind === "boxAgent" });
10282
+ startScreenPoller(readyBot.id, threadId, { computer: attached.capture }, { screenIsTheWork: instance.adapter.capabilities.remoteAgent === true });
9685
10283
  }
9686
10284
  // The speaker's own explicit place, mounted exactly as its bot thread
9687
10285
  // mounts it. A channel has no conversation pin and no Auto fallback here:
@@ -9719,11 +10317,11 @@ setupRetry = 0) {
9719
10317
  roomComputerKind = "vps";
9720
10318
  }
9721
10319
  else {
9722
- if (!box.boxConfigured(cfg))
9723
- throw new Error("Cloud box is not configured — add a Box API key or choose Local VM");
9724
- const remoteAgent = instance.driverKind === "boxAgent";
9725
- const attached = await attachBotBox(readyBot, resourceOwner, { explicitCloud: true,
9726
- canMount: remoteAgent || instance.adapter.capabilities.cloudComputerMcp === true, remoteAgent });
10320
+ if (!boat.boatConfigured(cfg))
10321
+ throw new Error("Cloud Boat is not configured — add a Boat API key or choose Local VM");
10322
+ const remoteAgent = instance.adapter.capabilities.remoteAgent === true;
10323
+ const attached = await attachBotBoat(readyBot, resourceOwner, { explicitCloud: true,
10324
+ canMount: instance.adapter.capabilities.usesCloudComputer === true, remoteAgent });
9727
10325
  if (!roomSetupIsCurrent())
9728
10326
  return false;
9729
10327
  if (!attached?.integration)
@@ -9737,11 +10335,11 @@ setupRetry = 0) {
9737
10335
  // Room and Goal turns use the speaker's desktop, never the coordinator's.
9738
10336
  // Claim the same lease as direct turns before asynchronous VM setup.
9739
10337
  if (readyBot.computer === "vm") {
9740
- if (instance.adapter.capabilities.computerMcp !== true || instance.driverKind === "boxAgent") {
10338
+ if (instance.adapter.capabilities.computerMcp !== true || instance.adapter.capabilities.remoteAgent === true) {
9741
10339
  throw new Error("this model engine cannot use the Local VM");
9742
10340
  }
9743
10341
  // A distinct identity fences cleanup even in shared mode on the same room thread.
9744
- const target = { ...localVmTargetForBot(readyBot.id) };
10342
+ const target = { ...localVmTargetForThread(readyBot.id, threadId) };
9745
10343
  await bindTurnComputer(resourceOwner, `computer:vm:${target.key}`, true);
9746
10344
  if (localVmImageBusy || localVmModeChangeBusy || localVmLifecycleBusy.has(target.key)) {
9747
10345
  throw new Error("this Local VM is being started, stopped, or replaced");
@@ -9749,6 +10347,8 @@ setupRetry = 0) {
9749
10347
  if (!localVmLeaseFor(target).claim(threadId, readyBot.id, localVmOwnerBusy)) {
9750
10348
  throw new Error("this Local VM is already being used by another turn");
9751
10349
  }
10350
+ if (localVmMode(cfg) === "pool")
10351
+ localVmSeatPool.touch(threadId);
9752
10352
  roomVmTarget = target;
9753
10353
  localVmThreadTargets.set(threadId, target);
9754
10354
  localVmActiveThreads.set(target.key, threadId);
@@ -9850,6 +10450,11 @@ setupRetry = 0) {
9850
10450
  // (#754) the room is told, once per source thread, rather than the
9851
10451
  // crossing being blocked.
9852
10452
  const recentLines = recentWork(recentWorkSources(bot), bot, { userName, currentThreadId: threadId });
10453
+ const roomComputerPromptKind = resolveComputerPromptKind({
10454
+ kind: roomTeamComputer || roomComputerKind === "box" ? "box" : roomVmTarget ? "vm" : roomComputerKind,
10455
+ driverKind: instance.driverKind, cloudComputerMcp: instance.adapter.capabilities.cloudComputerMcp,
10456
+ vmPrivate: localVmMode(cfg) === "per-bot",
10457
+ });
9853
10458
  {
9854
10459
  const crossing = claimRecallCrossings(threadId, recentLines.filter((line) => line.private).map((line) => line.threadId));
9855
10460
  if (crossing.count) {
@@ -9865,7 +10470,7 @@ setupRetry = 0) {
9865
10470
  { id: "user-profile", label: "About the user", text: userProfileSystemPrompt(cfg.profile) },
9866
10471
  { id: "files", label: "File locations", text: workspace ? workspaceLocationsPrompt(bot.id, cwd, readyBot.cwd) : "" },
9867
10472
  { id: "mcp", label: "MCP servers", text: customMcpPrompt(Object.keys(integrations.custom ?? {})) },
9868
- { id: "computer", label: "Computer", text: computerPrompt(roomTeamComputer || roomComputerKind === "box" ? instance.driverKind === "boxAgent" ? "box-agent" : instance.adapter.capabilities.cloudComputerMcp ? "box-chat" : "box" : roomVmTarget ? localVmMode(cfg) === "per-bot" ? "vm-private" : "vm-shared" : roomComputerKind) },
10473
+ { id: "computer", label: "Computer", text: computerPrompt(roomComputerPromptKind) },
9869
10474
  { id: "team-computer", label: "Team computer", text: teamComputerPrompt(roomTeamComputer) },
9870
10475
  { id: "plan", label: "Surface", text: surfacePrompt({ computer: roomTeamComputer ? "cloud" : roomVmTarget ? "vm" : surfaceOfComputerKind(roomComputerKind), browser: Boolean(integrations.browser) }, { note: roomPlan.note }) },
9871
10476
  { id: "browser", label: "Browser", text: integrations.browser ? BUILT_IN_BROWSER_SYSTEM_PROMPT : "" },
@@ -9995,10 +10600,13 @@ setupRetry = 0) {
9995
10600
  providerDispatched = true;
9996
10601
  turnPromptBytes.set(threadId, { stable: Buffer.byteLength(roomSystem.stable), volatile: Buffer.byteLength(roomSystem.volatile) });
9997
10602
  runningTurnEngines.set(threadId, instance);
10603
+ // notes only in a room: a private chat reaches a room through the
10604
+ // explicit, disclosed session_search, never automatically
10605
+ const roomRecalled = cardContinuation ? "" : autoRecallPrompt(bot, threadId, resolvedLatestImages.text, { conversations: false, userName });
9998
10606
  guardTurnDispatch(instance.adapter.sendTurn({
9999
10607
  threadId,
10000
10608
  botId: readyBot.id,
10001
- text,
10609
+ text: withRecalled(roomRecalled, text),
10002
10610
  refreshSystemPrompt: true,
10003
10611
  images: turnImages,
10004
10612
  approvalMode: roomTurnApprovalMode(readyBot, orchestration),
@@ -10523,17 +11131,49 @@ function startGroupTurn(groupId, text, replyTo, sendId, channelMode = "chat", qu
10523
11131
  if (options.goalCoordinatorBotId && (channelMode !== "goal" || !requestedGoalCoordinator)) {
10524
11132
  throw Object.assign(new Error("the selected goal coordinator is not an active room member"), { status: 409 });
10525
11133
  }
10526
- const message = store.appendMessage(threadId, {
10527
- role: "user",
10528
- kind: "text",
10529
- text,
10530
- replyToId: replyTo?.id,
10531
- sendId,
10532
- channelMode,
10533
- queueId,
10534
- via: options.via,
10535
- sender: options.sender,
10536
- });
11134
+ // A coalesced drain appends every queued line under its own queueId (the
11135
+ // chips and sendId receipts stay per-item); the LAST line is the turn's
11136
+ // user message, exactly like the 1:1 drain's userMessage.
11137
+ const queuedGroup = options.queuedGroup;
11138
+ const message = queuedGroup && queuedGroup.length > 0
11139
+ ? (() => {
11140
+ for (const item of queuedGroup.slice(0, -1)) {
11141
+ store.appendMessage(threadId, {
11142
+ role: "user",
11143
+ kind: "text",
11144
+ text: item.text,
11145
+ replyToId: item.replyToId,
11146
+ sendId: item.sendId,
11147
+ channelMode: item.mode,
11148
+ queueId: item.id,
11149
+ via: item.via,
11150
+ sender: item.sender,
11151
+ });
11152
+ }
11153
+ const last = queuedGroup[queuedGroup.length - 1];
11154
+ return store.appendMessage(threadId, {
11155
+ role: "user",
11156
+ kind: "text",
11157
+ text: last.text,
11158
+ replyToId: replyTo?.id,
11159
+ sendId: last.sendId,
11160
+ channelMode: last.mode,
11161
+ queueId: last.id,
11162
+ via: last.via,
11163
+ sender: last.sender,
11164
+ });
11165
+ })()
11166
+ : store.appendMessage(threadId, {
11167
+ role: "user",
11168
+ kind: "text",
11169
+ text,
11170
+ replyToId: replyTo?.id,
11171
+ sendId,
11172
+ channelMode,
11173
+ queueId,
11174
+ via: options.via,
11175
+ sender: options.sender,
11176
+ });
10537
11177
  // Admitted (see startTurn): the room's speakers are booked to this sender.
10538
11178
  if (options.trigger)
10539
11179
  turnTriggers.set(threadId, options.trigger);
@@ -10602,6 +11242,11 @@ function startGroupTurn(groupId, text, replyTo, sendId, channelMode = "chat", qu
10602
11242
  .catch(() => undefined);
10603
11243
  }
10604
11244
  const operation = beginGroupTurnOperation(groupId, threadId, goalCoordinator ? [] : responders.map((responder) => responder.id));
11245
+ if (queuedGroup && queuedGroup.length > 0) {
11246
+ // member turns use these stable ids to carry every burst line's words
11247
+ // and attachments through the turn that swallowed the burst
11248
+ operation.queuedQueueIds = queuedGroup.map((item) => item.id);
11249
+ }
10605
11250
  if (goalCoordinator) {
10606
11251
  const runId = options.goalRunId?.trim() || `goal-${Date.now().toString(36)}-${randomUUID()}`;
10607
11252
  const startedAt = Date.now();
@@ -10686,19 +11331,32 @@ function drainQueuedChannelSends() {
10686
11331
  drainChannelMessages((groupId) => {
10687
11332
  const group = store.group(groupId);
10688
11333
  return group ? groupIsWorking(group) : false;
10689
- }, ({ groupId, threadId, text, replyToId, sendId, mode, id, via, sender, trigger }) => {
11334
+ }, ({ groupId, threadId, items }) => {
10690
11335
  const group = store.group(groupId);
10691
11336
  const ownsThread = group?.dm
10692
11337
  ? group.threadId === threadId
10693
11338
  : Boolean(group && store.groupTaskByThread(group.id, threadId));
10694
11339
  if (!group || !ownsThread)
10695
11340
  return;
11341
+ // The burst runs as ONE room turn: the joined text routes responders
11342
+ // and titles the task, while every queued line still lands under its
11343
+ // own queueId (chips and sendId receipts stay per-item).
11344
+ const head = items[0];
11345
+ const last = items[items.length - 1];
11346
+ const joined = items.map((item) => item.text).join("\n\n");
10696
11347
  try {
10697
- startGroupTurn(groupId, text, resolveReplyTarget(threadId, replyToId), sendId, mode, id, { via, threadId, sender, trigger: queuedTurnTrigger({ trigger, sender }) });
11348
+ startGroupTurn(groupId, joined, resolveReplyTarget(threadId, last.replyToId), last.sendId, last.mode, last.id, {
11349
+ threadId,
11350
+ sender: head.sender,
11351
+ trigger: queuedTurnTrigger({ trigger: head.trigger, sender: head.sender }),
11352
+ queuedGroup: items,
11353
+ });
10698
11354
  }
10699
11355
  catch (error) {
10700
- if (!store.messagesFor(threadId).some((message) => message.queueId === id && message.role === "user")) {
10701
- store.appendMessage(threadId, { role: "user", kind: "text", text, replyToId, sendId, channelMode: mode, queueId: id, via, sender });
11356
+ for (const item of items) {
11357
+ if (!store.messagesFor(threadId).some((message) => message.queueId === item.id && message.role === "user")) {
11358
+ store.appendMessage(threadId, { role: "user", kind: "text", text: item.text, replyToId: item.replyToId, sendId: item.sendId, channelMode: item.mode, queueId: item.id, via: item.via, sender: item.sender });
11359
+ }
10702
11360
  }
10703
11361
  store.appendMessage(threadId, {
10704
11362
  role: "bot",
@@ -11573,7 +12231,7 @@ async function localVmPayload(target) {
11573
12231
  * app itself deleted eight hours earlier. Someone who steps away overnight
11574
12232
  * comes back to an error on their first message.
11575
12233
  *
11576
- * The cloud branch below already does the opposite: an absent box is
12234
+ * The cloud branch below already does the opposite: an absent boat is
11577
12235
  * provisioned on first use behind a `provisioning` broadcast. This gives the
11578
12236
  * Local VM the same lifecycle for the same reason.
11579
12237
  *
@@ -11593,7 +12251,11 @@ async function readyLocalVmForTurn(botId, target, isCurrent = () => true) {
11593
12251
  // before the first await — the same synchronous-fence-then-count shape
11594
12252
  // the panel route uses — so two concurrent turns cannot both pass the
11595
12253
  // per-bot limit between count and create.
11596
- const ownsProvision = !localVmProvisionBusy;
12254
+ // Pool capacity is bounded by its seat indices. Each seat already has
12255
+ // its own lease/lifecycle fence, so independent cold seats can start
12256
+ // together without competing for the per-bot inventory's capacity gate.
12257
+ const pooled = target.key.startsWith("pool:");
12258
+ const ownsProvision = !pooled && !localVmProvisionBusy;
11597
12259
  if (ownsProvision)
11598
12260
  localVmProvisionBusy = true;
11599
12261
  let status;
@@ -11607,9 +12269,9 @@ async function readyLocalVmForTurn(botId, target, isCurrent = () => true) {
11607
12269
  // Another creation is already mid-flight and its container is not yet
11608
12270
  // visible to a count, so the safe answer is the inspected status —
11609
12271
  // exactly what the over-cap path below returns.
11610
- if (!ownsProvision)
12272
+ if (!pooled && !ownsProvision)
11611
12273
  return status;
11612
- if (target.key !== SHARED_LOCAL_VM_TARGET.key) {
12274
+ if (target.key.startsWith("bot:")) {
11613
12275
  const count = await existingPerBotLocalVmCount(status.runtime);
11614
12276
  if (!isCurrent() || count >= localVmMaxInstances(cfg))
11615
12277
  return status;
@@ -11717,6 +12379,7 @@ function configStatus() {
11717
12379
  // not a secret — the settings picker shows it; "" = follow the system
11718
12380
  language: cfg.language ?? "",
11719
12381
  rooms: { turnTimeoutMinutes: roomTurnTimeoutMinutes(cfg) },
12382
+ automaticRecovery: cfg.automaticRecovery ?? { enabled: false },
11720
12383
  // absent effort = no level is sent, so clients can tell it from any level
11721
12384
  newBots: cfg.newBots?.effort ? { effort: cfg.newBots.effort } : {},
11722
12385
  threads: {
@@ -11731,6 +12394,7 @@ function configStatus() {
11731
12394
  features: {
11732
12395
  skillAuthoring: skillAuthoringEnabled(cfg),
11733
12396
  showToolCalls: showToolCallsEnabled(cfg),
12397
+ routinesInConversation: routinesInConversationEnabled(cfg),
11734
12398
  browser: builtInBrowserEnabled(cfg),
11735
12399
  // Maintainer-only escape hatch, not a Settings toggle: the desktop
11736
12400
  // shell and the Settings UI read it so they offer nothing this server
@@ -11739,6 +12403,7 @@ function configStatus() {
11739
12403
  // Plugins → MCP servers switch: Claude bots also see this machine's
11740
12404
  // own Claude Code MCP servers
11741
12405
  claudeUserMcp: claudeUserMcpEnabled(cfg),
12406
+ autoRecall: autoRecallEnabled(cfg),
11742
12407
  },
11743
12408
  // first-run progress — not a secret; the app decides whether to show
11744
12409
  // the welcome tour from this, never from browser storage
@@ -12049,26 +12714,6 @@ function serveStatic(res, path) {
12049
12714
  }
12050
12715
  }
12051
12716
  }
12052
- /** A store refusal is a client error with a status of its own (400 path,
12053
- * 409 conflict, 413 too large); a 409 also carries what is on disk now so
12054
- * the editor can show the bot's version instead of guessing. Anything else
12055
- * is a real failure and goes to the handler's catch-all. */
12056
- function replyMemoryError(res, error) {
12057
- if (!(error instanceof MemoryStoreError))
12058
- throw error;
12059
- if (error.code === "conflict") {
12060
- return json(res, error.status, { error: error.message, code: error.code, currentHash: error.currentHash, current: error.current });
12061
- }
12062
- return json(res, error.status, { error: error.message, code: error.code });
12063
- }
12064
- /** The journal row as the panel shows it: the full prior text stays on
12065
- * the server (a revert needs it there, the list does not), and the thread
12066
- * id becomes the chat title people recognise. */
12067
- function journalEntryForClient(botId, entry) {
12068
- const { before: _before, ...visible } = entry;
12069
- const threadTitle = entry.threadId ? store.taskByThread(botId, entry.threadId)?.title : undefined;
12070
- return threadTitle ? { ...visible, threadTitle } : visible;
12071
- }
12072
12717
  // Loopback-only enforcement: the harness runs on 127.0.0.1 but accepts
12073
12718
  // requests from any loopback connection and any web page that DNS-rebinds
12074
12719
  // onto it. Reject non-loopback Hosts outright (defeats rebinding) and
@@ -12099,13 +12744,13 @@ const workspaceBackupRoutes = createWorkspaceBackupRoutes({
12099
12744
  idle: () => !providerFleetReloading && !providerAuthSessions.active && !browserEngineInstall &&
12100
12745
  !routines?.isTicking && !calendarCalls?.isTicking &&
12101
12746
  !localVmImageBusy && !localVmProvisionBusy && !localVmModeChangeBusy &&
12102
- !localVmLifecycleBusy.size && !boxLifecycleBusyBots.size && !vpsPreviewRequests.size && !orphanBoxLifecycleBusyIds.size &&
12747
+ !localVmLifecycleBusy.size && !boatLifecycleBusyBots.size && !vpsPreviewRequests.size && !orphanBoatLifecycleBusyIds.size &&
12103
12748
  !computerProviderConfigTransitions.size && !checkpointRestoreLeases.size &&
12104
12749
  teamComputers.list().every(computer => !teamComputerInUse(computer)) &&
12105
12750
  store.bots.every((bot) => !botHasActiveTurn(bot.id) && !routines?.activeRunForBot(bot.id) && !botComputerControlSnapshot(bot.id).held) &&
12106
12751
  store.groups.every((group) => !groupIsWorking(group)),
12107
- pause: () => { routines?.stop(); calendarCalls?.stop(); watchdog.stop(); },
12108
- resume: () => { routines?.start(); calendarCalls?.start(); watchdog.start(); },
12752
+ pause: () => { routines?.stop(); calendarCalls?.stop(); watchdog.stop(); memoryUpkeep.pause(); },
12753
+ resume: () => { routines?.start(); calendarCalls?.start(); watchdog.start(); memoryUpkeep.resume(); },
12109
12754
  flush: async () => {
12110
12755
  await Promise.all([flushAllProfileHistory(), flushAllMemoryJournals(), flushUsageLedger(DATA_DIR), flushDecisionLog(DATA_DIR), flushAdminActivity(DATA_DIR)]);
12111
12756
  // With writers gated and work idle, release our WAL connection for the
@@ -12122,6 +12767,19 @@ ROUTES.push(createHostedSlackRoutes({ bot: (id) => store.bot(id), hostedReady: (
12122
12767
  // its file, so New bot cannot disagree with it. No organization: none.
12123
12768
  const orgInstallStatuses = () => orgLibrary?.installStatuses() ?? new Map();
12124
12769
  ROUTES.push(createBotPresetRoutes({ presets: presetStore, orgStatuses: orgInstallStatuses }));
12770
+ // The bot-memory panel's routes (MEMORY.md, memory/ topics, journal); the
12771
+ // store lookups — the 404 precheck and journal thread titles — stay explicit.
12772
+ ROUTES.push(createBotMemoryRoutes({
12773
+ bot: (id) => store.bot(id),
12774
+ taskByThread: (botId, threadId) => store.taskByThread(botId, threadId),
12775
+ upkeep: memoryUpkeep,
12776
+ aboutMe: () => cfg.profile?.aboutMe ?? "",
12777
+ saveAboutMe: (aboutMe) => {
12778
+ saveConfig({ profile: { ...cfg.profile, aboutMe } });
12779
+ Object.assign(cfg, loadConfig());
12780
+ broadcast({ kind: "config", ...configStatus() });
12781
+ },
12782
+ }));
12125
12783
  const toolResults = new ToolResults();
12126
12784
  const handleRequest = async (req, res) => {
12127
12785
  let url;
@@ -12226,6 +12884,26 @@ const handleRequest = async (req, res) => {
12226
12884
  res.setHeader("set-cookie", serializeSessionCookie(SESSION_COOKIE, issued.token, { secure, maxAgeSeconds: cookieMaxAgeSeconds(issued.session) }));
12227
12885
  return json(res, 200, { session: issued.session, environment });
12228
12886
  }
12887
+ // The Admin's signed request for one pairing window on a Cloud home
12888
+ // machine. Public like /api/auth/pair, JSON only, and bad signatures
12889
+ // count against the same lockout. Never log its headers, body or code.
12890
+ if (cloudPairing && path === CLOUD_PAIRING_PATH) {
12891
+ res.setHeader("cache-control", "no-store");
12892
+ if (method !== "POST")
12893
+ return json(res, 405, { error: "method_not_allowed" });
12894
+ if (!/^application\/json\b/i.test(String(req.headers["content-type"] ?? ""))) {
12895
+ return json(res, 415, { error: "send the pairing request as JSON (content-type: application/json)" });
12896
+ }
12897
+ const source = requestSource(req);
12898
+ const header = (name) => { const value = req.headers[name]; return typeof value === "string" ? value : undefined; };
12899
+ const result = cloudPairing.handle({
12900
+ timestamp: header("x-omb-cloud-timestamp"), nonce: header("x-omb-cloud-nonce"), signature: header("x-omb-cloud-signature"),
12901
+ body: await readSignedBody(req), source,
12902
+ });
12903
+ if (result.status !== 200)
12904
+ console.warn(`cloud pairing refused from ${source}: ${String(result.body.error)}`);
12905
+ return json(res, result.status, result.body);
12906
+ }
12229
12907
  if (method === "POST" && path === "/api/auth/pair") {
12230
12908
  // JSON only: a cross-site HTML form cannot send this content type
12231
12909
  // without a preflight, so a stray unused code cannot be planted as a
@@ -12379,6 +13057,9 @@ const handleRequest = async (req, res) => {
12379
13057
  // a hosted team workspace: the web UI's first run skips the
12380
13058
  // desktop-only beats there. Absent everywhere else.
12381
13059
  ...(HOSTED_WORKSPACE ? { hosted: true } : {}),
13060
+ // an OMB Cloud home: the web UI's first run is its engine
13061
+ // sign-in (docs/cloud-pro.md). Absent everywhere else.
13062
+ ...(CLOUD_HOME ? { cloudHome: true } : {}),
12382
13063
  });
12383
13064
  }
12384
13065
  if (method === "POST" && path === "/api/auth/stream-ticket") {
@@ -12755,7 +13436,7 @@ const handleRequest = async (req, res) => {
12755
13436
  }
12756
13437
  if (method === "POST" && path === "/api/internal/memory") {
12757
13438
  const body = await readInternalBody();
12758
- const result = updateMemory(internalSender.id, { action: body.action, text: body.text, oldText: body.oldText }, { source: memorySource() });
13439
+ const result = updateMemory(internalSender.id, { action: body.action, text: body.text, oldText: body.oldText, ...(body.until !== undefined ? { until: body.until } : {}) }, { source: memorySource() });
12759
13440
  return json(res, result.ok ? 200 : result.code === "conflict" ? 409 : result.code === "over-budget" ? 413 : 400, result);
12760
13441
  }
12761
13442
  if (method === "POST" && path === "/api/internal/memory/log") {
@@ -13079,11 +13760,12 @@ const handleRequest = async (req, res) => {
13079
13760
  const owner = connectorThread(from.id, fromThreadId);
13080
13761
  if (!owner)
13081
13762
  return json(res, 403, { error: "source conversation does not belong to sender" });
13082
- // "Make a routine for @B": resolve the target up front so the model
13083
- // gets a teaching error now, not a mis-bound routine later. Omitted
13084
- // (or the sender's own id) keeps the schedule-for-self path unchanged.
13763
+ // "Make a routine for @B" / "pause @B's routine": resolve the target
13764
+ // up front so the model gets a teaching error now, not a mis-bound
13765
+ // routine later. Omitted (or the sender's own id) keeps the
13766
+ // own-routine path unchanged.
13085
13767
  let forBot;
13086
- if (body.action === "create" && body.forBotId !== undefined) {
13768
+ if (body.forBotId !== undefined) {
13087
13769
  const parsedForBotId = z.string().max(128).safeParse(body.forBotId);
13088
13770
  const forBotId = parsedForBotId.success ? parsedForBotId.data.trim() : "";
13089
13771
  if (!forBotId) {
@@ -13107,8 +13789,8 @@ const handleRequest = async (req, res) => {
13107
13789
  const proposedInput = body.action === "create"
13108
13790
  ? { action: body.action, routine: body.routine, forBot }
13109
13791
  : body.action === "update"
13110
- ? { action: body.action, routineId: body.routineId, changes: body.changes }
13111
- : { action: body.action, routineId: body.routineId };
13792
+ ? { action: body.action, routineId: body.routineId, changes: body.changes, forBot }
13793
+ : { action: body.action, routineId: body.routineId, forBot };
13112
13794
  const proposed = await routineRequests.submit({
13113
13795
  botId: from.id,
13114
13796
  threadId: fromThreadId,
@@ -15277,6 +15959,47 @@ const handleRequest = async (req, res) => {
15277
15959
  });
15278
15960
  }
15279
15961
  // scrollback: the page before a message the client already holds
15962
+ // #1655: the consent card's answer, per conversation. Explicit and
15963
+ // revocable; a thread allowlisted in config carries the same standing
15964
+ // consent without ever seeing a card.
15965
+ m = path.match(/^\/api\/threads\/([\w-]+)\/cloud-overflow$/);
15966
+ if (m && method === "POST") {
15967
+ const threadId = m[1];
15968
+ if (!store.botByThread(threadId))
15969
+ return json(res, 404, { error: "no such conversation" });
15970
+ const body = await readBody(req);
15971
+ if (!body || typeof body !== "object" || Array.isArray(body))
15972
+ return json(res, 400, { error: "body must be a JSON object" });
15973
+ if (typeof body.consent !== "boolean")
15974
+ return json(res, 400, { error: "consent must be a boolean" });
15975
+ if (body.consent) {
15976
+ // Consent answers the priced card, never a guess: without a prior
15977
+ // offer the rate was never shown, so a seat must not start yet.
15978
+ // The grant binds to the rate the card showed (#1655): a config
15979
+ // change re-offers instead of starting at a new price silently.
15980
+ const offeredRate = cloudOverflowConsent.offeredRate(threadId);
15981
+ if (offeredRate === null)
15982
+ return json(res, 409, { error: "no cloud overflow offer" });
15983
+ cloudOverflowConsent.grant(threadId, offeredRate);
15984
+ }
15985
+ else {
15986
+ cloudOverflowConsent.revoke(threadId);
15987
+ // Revocation must reach the machine (#1655): the ledger alone
15988
+ // would leave this conversation's seat billing to its idle
15989
+ // timeout. A start still waking is caught by its own revoke
15990
+ // check once readyBox resolves.
15991
+ const seatBot = store.botByThread(threadId);
15992
+ const lease = seatBot ? cloudSeatLeases.get(seatBot.id) : undefined;
15993
+ if (seatBot && lease && lease.threadId === threadId) {
15994
+ stopCloudSeat(seatBot.id, lease, "Cloud computer stopped because overflow consent was revoked — billing pauses while it sleeps.");
15995
+ }
15996
+ }
15997
+ store.appendMessage(threadId, {
15998
+ role: "bot", kind: "activity",
15999
+ tool: { name: cloudOverflowConsentText(body.consent, cloudOverflowIdleStopMs(cfg)), ok: true },
16000
+ });
16001
+ return json(res, 200, { consented: body.consent });
16002
+ }
15280
16003
  m = path.match(/^\/api\/threads\/([\w-]+)\/messages$/);
15281
16004
  if (m && method === "GET") {
15282
16005
  const threadId = m[1];
@@ -16495,7 +17218,17 @@ const handleRequest = async (req, res) => {
16495
17218
  const held = holdChannelQueue(current.id, targetThreadId, m[2]);
16496
17219
  if (!held)
16497
17220
  return json(res, 404, { error: "no such queued message" });
16498
- const [head] = held.items;
17221
+ // M2: the head may be a coalesced group (one sender's contiguous
17222
+ // burst); Steer folds that whole group into the live turn as one.
17223
+ const headGroup = headChannelGroup(held.items);
17224
+ const [head] = headGroup;
17225
+ // A live steer has no image side channel — the same rule as the
17226
+ // 1:1 queue: attachment words wait for a real turn where central
17227
+ // admission can hand the images to the engine.
17228
+ if (headGroup.some((item) => extractTurnImages(item.text).images.length > 0)) {
17229
+ restoreHeldChannelQueue(held);
17230
+ return json(res, 200, { ok: true, queued: true, threadId: targetThreadId });
17231
+ }
16499
17232
  const decision = admit("room-steer", {
16500
17233
  speakerPresent: Boolean(speaker),
16501
17234
  engineCanSteer: Boolean(instance?.adapter.capabilities.queueing && instance.adapter.steer),
@@ -16512,11 +17245,31 @@ const handleRequest = async (req, res) => {
16512
17245
  // A reply target that cannot be resolved restores the held queue
16513
17246
  // before the request fails — the room's normal drain keeps the head.
16514
17247
  const replyTo = resolveHeldReplyTarget(held, resolveReplyTarget);
17248
+ // Each burst line keeps its own reply relationship: the fold renders
17249
+ // per-item reply context (the head through the helper above, the rest
17250
+ // resolved here) so a mixed burst does not inherit the head's quote
17251
+ // or drop its own. A target that cannot be resolved restores the held
17252
+ // queue before the request fails, mirroring the helper's contract.
17253
+ const speakerName = cfg.profile?.name?.trim() || "User";
17254
+ let foldedPrompt;
17255
+ try {
17256
+ foldedPrompt = headGroup
17257
+ .map((item, index) => promptWithReply(item.text, index === 0
17258
+ ? replyTo
17259
+ : item.replyToId
17260
+ ? resolveReplyTarget(targetThreadId, item.replyToId)
17261
+ : undefined, speakerName))
17262
+ .join("\n\n");
17263
+ }
17264
+ catch (error) {
17265
+ restoreHeldChannelQueue(held);
17266
+ throw error;
17267
+ }
16515
17268
  // steer was offered only when a live speaker instance could take it;
16516
17269
  // the check carries that invariant to the type system.
16517
17270
  const steered = instance?.adapter.steer
16518
17271
  ? await instance.adapter
16519
- .steer(targetThreadId, promptWithReply(head.text, replyTo, cfg.profile?.name?.trim() || "User"))
17272
+ .steer(targetThreadId, foldedPrompt)
16520
17273
  .catch(() => "indeterminate")
16521
17274
  : "refused";
16522
17275
  // The steer was awaited adapter work: re-read every ownership
@@ -16535,25 +17288,25 @@ const handleRequest = async (req, res) => {
16535
17288
  // speaker — and settle the head.
16536
17289
  const delivered = steered !== "refused";
16537
17290
  if (after && delivered && (steered === "indeterminate" || afterSpeakerBotId === speakerBotId)) {
16538
- const message = store.appendMessage(targetThreadId, {
17291
+ const messages = headGroup.map((item) => store.appendMessage(targetThreadId, {
16539
17292
  role: "user",
16540
17293
  kind: "text",
16541
- text: head.text,
16542
- replyToId: head.replyToId,
16543
- sendId: head.sendId,
16544
- channelMode: head.mode,
16545
- queueId: head.id,
16546
- via: head.via,
17294
+ text: item.text,
17295
+ replyToId: item.replyToId,
17296
+ sendId: item.sendId,
17297
+ channelMode: item.mode,
17298
+ queueId: item.id,
17299
+ via: item.via,
16547
17300
  steered: true,
16548
- sender: head.sender,
16549
- });
17301
+ sender: item.sender,
17302
+ }));
16550
17303
  settleHeldChannelQueueHead(held);
16551
17304
  return json(res, 200, {
16552
17305
  ok: true,
16553
17306
  steered: true,
16554
17307
  threadId: targetThreadId,
16555
- messages: [message],
16556
- queueIds: [head.id],
17308
+ messages,
17309
+ queueIds: headGroup.map((item) => item.id),
16557
17310
  });
16558
17311
  }
16559
17312
  if (steered === "indeterminate" && !after) {
@@ -17029,7 +17782,7 @@ const handleRequest = async (req, res) => {
17029
17782
  if ([existing, selected].some((owner) => {
17030
17783
  const mode = approvalModeFor(owner);
17031
17784
  return (mode === "full" || mode === "custom") &&
17032
- (!supportsApprovalMode(registry.cliTarget(checked.selection.instanceId)?.driverKind, mode) ||
17785
+ (!supportsApprovalMode(checked.selection, mode) ||
17033
17786
  registry.cliTarget(checked.selection.instanceId)?.driverKind !== registry.cliTarget(owner.modelSelection.instanceId)?.driverKind);
17034
17787
  })) {
17035
17788
  return json(res, 400, {
@@ -17294,6 +18047,11 @@ const handleRequest = async (req, res) => {
17294
18047
  }
17295
18048
  patch.mcpServers = requestedMcpServers;
17296
18049
  }
18050
+ if (body.memoryUpkeep !== undefined) {
18051
+ if (typeof body.memoryUpkeep !== "boolean")
18052
+ return json(res, 400, { error: "memoryUpkeep must be true or false" });
18053
+ patch.memoryUpkeep = body.memoryUpkeep;
18054
+ }
17297
18055
  // per-bot gate on the app's built-in browser
17298
18056
  if (body.browser !== undefined) {
17299
18057
  if (typeof body.browser !== "boolean")
@@ -17391,14 +18149,14 @@ const handleRequest = async (req, res) => {
17391
18149
  if (normalizedSelection && selectedTask) {
17392
18150
  const mode = approvalModeFor(selectedTask);
17393
18151
  if ((mode === "full" || mode === "custom") &&
17394
- (!supportsApprovalMode(registry.cliTarget(normalizedSelection.instanceId)?.driverKind, mode) ||
18152
+ (!supportsApprovalMode(normalizedSelection, mode) ||
17395
18153
  registry.cliTarget(normalizedSelection.instanceId)?.driverKind !== registry.cliTarget(selectedTask.modelSelection.instanceId)?.driverKind)) {
17396
18154
  return json(res, 400, { error: "Choose Ask for the selected thread before changing providers with elevated permissions" });
17397
18155
  }
17398
18156
  }
17399
18157
  if ((requestedApprovalMode === "full" || requestedApprovalMode === "custom") &&
17400
18158
  (body.approvalMode !== undefined || normalizedSelection !== undefined) &&
17401
- (!targetSelection || !supportsApprovalMode(registry.cliTarget(targetSelection.instanceId)?.driverKind, requestedApprovalMode) ||
18159
+ (!targetSelection || !supportsApprovalMode(targetSelection, requestedApprovalMode) ||
17402
18160
  (existingBot && normalizedSelection && registry.cliTarget(normalizedSelection.instanceId)?.driverKind !== registry.cliTarget(existingBot.modelSelection.instanceId)?.driverKind))) {
17403
18161
  return json(res, 400, {
17404
18162
  error: "This provider does not support the selected approval level, or changing providers requires choosing Ask first",
@@ -17631,6 +18389,8 @@ const handleRequest = async (req, res) => {
17631
18389
  }
17632
18390
  if (!bot)
17633
18391
  return json(res, 404, { error: "no such bot" });
18392
+ if (body.memoryUpkeep === false)
18393
+ memoryUpkeep.dropBot(bot.id);
17634
18394
  // A defined Works on is the newest explicit choice: this bot's
17635
18395
  // auto-recorded pins that now point elsewhere give way immediately, so
17636
18396
  // the next turn on each thread follows the new setting. Person-set pins
@@ -17953,154 +18713,6 @@ const handleRequest = async (req, res) => {
17953
18713
  broadcast({ kind: "bot", bot: visible });
17954
18714
  return json(res, 200, { bot: visible });
17955
18715
  }
17956
- // ── bot memory: MEMORY.md + memory/ topic and log files ──────────────
17957
- // The files already belong to the person (plain markdown in the bot's
17958
- // workspace). server/memory-store.ts decides which paths can be reached
17959
- // and refuses a save whose expectedHash no longer matches the file;
17960
- // server/memory-journal.ts records every change made here so it can be
17961
- // read back and reverted. Reads never create the workspace — a bot that
17962
- // has not run yet simply has nothing to show. Admin scope by default
17963
- // (request-auth.ts), like the profile routes above.
17964
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory$/);
17965
- if (m && method === "GET") {
17966
- if (!store.bot(m[1]))
17967
- return json(res, 404, { error: "no such bot" });
17968
- try {
17969
- const overview = memoryOverview(m[1]);
17970
- // `text` and `truncated` ride along one release for clients of the
17971
- // old whole-file shape; the panel reads the file through /memory/file
17972
- return json(res, 200, { ...overview, text: readMemoryDoc(m[1], MEMORY_INDEX).text, truncated: overview.index.truncated });
17973
- }
17974
- catch (error) {
17975
- return replyMemoryError(res, error);
17976
- }
17977
- }
17978
- if (m && method === "PUT") {
17979
- // The pre-panel whole-file write, kept one release: no hash check, so
17980
- // it can still overwrite a note the bot just wrote — journaled as the
17981
- // person's so at least the journal can undo it.
17982
- if (!store.bot(m[1]))
17983
- return json(res, 404, { error: "no such bot" });
17984
- const parsed = z.object({ text: z.string() }).safeParse(await readBody(req));
17985
- if (!parsed.success)
17986
- return json(res, 400, { error: "text must be a string" });
17987
- try {
17988
- const { doc } = journalMemoryWrite(m[1], MEMORY_INDEX, parsed.data.text, { actor: "person", via: "api" });
17989
- return json(res, 200, { ok: true, hash: doc.hash, truncated: memoryCapacity(doc.text).truncated });
17990
- }
17991
- catch (error) {
17992
- // the old route answered 400 for an oversized body; keep that for
17993
- // its callers while the new route says 413
17994
- if (error instanceof MemoryStoreError && error.code === "too-large")
17995
- return json(res, 400, { error: error.message });
17996
- return replyMemoryError(res, error);
17997
- }
17998
- }
17999
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory\/file$/);
18000
- if (m && method === "GET") {
18001
- if (!store.bot(m[1]))
18002
- return json(res, 404, { error: "no such bot" });
18003
- try {
18004
- return json(res, 200, readMemoryDoc(m[1], url.searchParams.get("path") ?? MEMORY_INDEX));
18005
- }
18006
- catch (error) {
18007
- return replyMemoryError(res, error);
18008
- }
18009
- }
18010
- if (m && method === "PUT") {
18011
- if (!store.bot(m[1]))
18012
- return json(res, 404, { error: "no such bot" });
18013
- const parsed = z
18014
- .object({ path: z.string().default(MEMORY_INDEX), text: z.string(), expectedHash: z.string().optional() })
18015
- .safeParse(await readBody(req));
18016
- if (!parsed.success)
18017
- return json(res, 400, { error: "text must be a string; path and expectedHash are optional strings" });
18018
- try {
18019
- const { doc, entry } = journalMemoryWrite(m[1], parsed.data.path, parsed.data.text, {
18020
- actor: "person",
18021
- via: "ui",
18022
- expectedHash: parsed.data.expectedHash,
18023
- });
18024
- return json(res, 200, { ok: true, ...doc, entry: entry ? journalEntryForClient(m[1], entry) : null, overview: memoryOverview(m[1]) });
18025
- }
18026
- catch (error) {
18027
- return replyMemoryError(res, error);
18028
- }
18029
- }
18030
- if (m && method === "DELETE") {
18031
- if (!store.bot(m[1]))
18032
- return json(res, 404, { error: "no such bot" });
18033
- const file = url.searchParams.get("path") ?? "";
18034
- try {
18035
- const entry = journalMemoryDelete(m[1], file, { actor: "person", via: "ui" });
18036
- return json(res, 200, { ok: true, path: file, entry: entry ? journalEntryForClient(m[1], entry) : null, overview: memoryOverview(m[1]) });
18037
- }
18038
- catch (error) {
18039
- return replyMemoryError(res, error);
18040
- }
18041
- }
18042
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory\/journal$/);
18043
- if (m && method === "GET") {
18044
- if (!store.bot(m[1]))
18045
- return json(res, 404, { error: "no such bot" });
18046
- // the row a save queued a moment ago may not have reached disk yet
18047
- await flushMemoryJournal(m[1]);
18048
- const limit = Math.min(200, Math.max(1, Number(url.searchParams.get("limit") ?? 50) || 50));
18049
- const botId = m[1];
18050
- return json(res, 200, { entries: readMemoryJournal(botId, limit).map((entry) => journalEntryForClient(botId, entry)) });
18051
- }
18052
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory\/journal\/([\w-]+)\/revert$/);
18053
- if (m && method === "POST") {
18054
- if (!store.bot(m[1]))
18055
- return json(res, 404, { error: "no such bot" });
18056
- await flushMemoryJournal(m[1]);
18057
- const result = revertMemoryChange(m[1], m[2]);
18058
- if (!result.ok)
18059
- return json(res, result.status, { error: result.error });
18060
- return json(res, 200, { ok: true, ...result.doc, entry: result.entry ? journalEntryForClient(m[1], result.entry) : null, overview: memoryOverview(m[1]) });
18061
- }
18062
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory\/open$/);
18063
- if (m && method === "POST") {
18064
- if (!store.bot(m[1]))
18065
- return json(res, 404, { error: "no such bot" });
18066
- const parsed = z.object({ target: z.enum(["obsidian", "folder"]) }).safeParse(await readBody(req));
18067
- if (!parsed.success)
18068
- return json(res, 400, { error: "target must be obsidian or folder" });
18069
- // The folder is on this machine's disk; opening it only makes sense
18070
- // from this machine. A paired phone or a remote browser gets the path
18071
- // to open by hand instead.
18072
- const workspacePath = memoryOverview(m[1]).workspacePath;
18073
- if (auth.kind !== "loopback") {
18074
- return json(res, 403, { error: `This only works on the computer running OpenMausBot. The memory folder there is ${workspacePath}`, workspacePath });
18075
- }
18076
- const opened = await openMemoryLocation(m[1], parsed.data.target);
18077
- if (!opened.ok)
18078
- return json(res, 500, { error: opened.error, workspacePath: opened.workspacePath });
18079
- return json(res, 200, opened);
18080
- }
18081
- m = path.match(/^\/api\/bots\/([\w-]+)\/memory\/topics\/([^/]+)$/);
18082
- if (m && method === "GET") {
18083
- if (!store.bot(m[1]))
18084
- return json(res, 404, { error: "no such bot" });
18085
- // Decode before validating: a UI-sent name arrives percent-encoded
18086
- // ("my notes.md" → "my%20notes.md"), and an encoded traversal
18087
- // ("..%2F..") must be judged by what it decodes TO, not slip through
18088
- // as an opaque token. The name gate then rejects anything that is not
18089
- // a single plain-markdown path segment.
18090
- let name;
18091
- try {
18092
- name = decodeURIComponent(m[2]);
18093
- }
18094
- catch {
18095
- return json(res, 400, { error: "invalid topic name" });
18096
- }
18097
- if (!isMemoryTopicName(name))
18098
- return json(res, 400, { error: "invalid topic name" });
18099
- const text = readMemoryTopic(m[1], name);
18100
- if (text === null)
18101
- return json(res, 404, { error: "no such topic file" });
18102
- return json(res, 200, { name, text });
18103
- }
18104
18716
  // ── workspace checkpoints: per-turn shadow-git snapshots ────────────
18105
18717
  // The list endpoint is the source of truth (turns store nothing), and
18106
18718
  // `enabled` tells the UI whether snapshots can happen here at all —
@@ -18926,7 +19538,7 @@ const handleRequest = async (req, res) => {
18926
19538
  }
18927
19539
  if (bot.approvalGrant)
18928
19540
  return json(res, 409, { error: "the bot's approval mode is still being confirmed" });
18929
- if (!supportsApprovalMode(registry.cliTarget(bot.modelSelection.instanceId)?.driverKind, "full")) {
19541
+ if (!supportsApprovalMode(bot.modelSelection, "full")) {
18930
19542
  return json(res, 400, { error: "This provider does not support Full access" });
18931
19543
  }
18932
19544
  }
@@ -19077,7 +19689,7 @@ const handleRequest = async (req, res) => {
19077
19689
  return json(res, 403, { error: "Full and Custom access require trusted desktop confirmation" });
19078
19690
  if (approvalModeFor(current) === "custom")
19079
19691
  return json(res, 403, { error: "Leaving Custom approval requires confirmation in the packaged desktop app" });
19080
- if (!supportsApprovalMode(registry.cliTarget((patch.modelSelection ?? current.modelSelection).instanceId)?.driverKind, mode)) {
19692
+ if (!supportsApprovalMode(patch.modelSelection ?? current.modelSelection, mode)) {
19081
19693
  return json(res, 400, { error: "This provider does not support the selected approval level" });
19082
19694
  }
19083
19695
  if (threadBusy(current.id, current.threadId))
@@ -19132,7 +19744,7 @@ const handleRequest = async (req, res) => {
19132
19744
  broadcast({ kind: "bot", bot: fresh });
19133
19745
  return json(res, 200, { bot: fresh });
19134
19746
  }
19135
- // Named team Boxes use real independent ownership, never a hidden bot or
19747
+ // Named team Boats use real independent ownership, never a hidden bot or
19136
19748
  // an arbitrary provider id. These new routes remain admin-only by default.
19137
19749
  if (path === "/api/team-computers" && method === "GET") {
19138
19750
  res.setHeader("cache-control", "private, no-store");
@@ -19169,7 +19781,7 @@ const handleRequest = async (req, res) => {
19169
19781
  if (!parsed.success)
19170
19782
  return json(res, 400, { error: "Choose take or release with a valid optional controlLeaseId" });
19171
19783
  const key = teamComputerOwner(found.id);
19172
- if (parsed.data.action === "take" && boxLifecycleBusyBots.has(key))
19784
+ if (parsed.data.action === "take" && boatLifecycleBusyBots.has(key))
19173
19785
  return json(res, 409, { error: "Wait for this computer's action to finish before taking control" });
19174
19786
  if (parsed.data.action === "take")
19175
19787
  assertTeamControlCanBeTaken(found.id);
@@ -19190,13 +19802,13 @@ const handleRequest = async (req, res) => {
19190
19802
  assertCurrentOwner();
19191
19803
  if (section !== null && section !== "" && !store.sections.includes(section))
19192
19804
  throw Object.assign(new Error("Create the team before assigning a computer"), { status: 404 });
19193
- if (section !== null && store.bots.some(bot => sectionKey(bot.section) === section && (botHasActiveTurn(bot.id) || routines?.activeRunForBot(bot.id) || botComputerControlSnapshot(bot.id).held || boxLifecycleBusyBots.has(bot.id))))
19805
+ if (section !== null && store.bots.some(bot => sectionKey(bot.section) === section && (botHasActiveTurn(bot.id) || routines?.activeRunForBot(bot.id) || botComputerControlSnapshot(bot.id).held || boatLifecycleBusyBots.has(bot.id))))
19194
19806
  throw Object.assign(new Error("Stop the target team's work and release computer control before assigning this computer"), { status: 409 });
19195
19807
  };
19196
19808
  checkAssignment();
19197
19809
  const release = claimTeamComputerLifecycle(found);
19198
19810
  try {
19199
- if (section !== null && !(await box.findBox(cfg, teamComputerOwner(found.id))))
19811
+ if (section !== null && !(await boat.findBoat(cfg, teamComputerOwner(found.id))))
19200
19812
  return json(res, 409, { error: "Create or retry this computer before assigning it to a team" });
19201
19813
  checkAssignment();
19202
19814
  if (teamComputerInUse(found))
@@ -19211,13 +19823,13 @@ const handleRequest = async (req, res) => {
19211
19823
  if (method === "POST" && !computerId) {
19212
19824
  const parsed = teamComputerCreate.safeParse(body);
19213
19825
  if (!parsed.success)
19214
- return json(res, 400, { error: "Provide requestId (UUID), a name, and acknowledgeCost: true to create a paid Box" });
19215
- if (!box.boxConfigured(cfg))
19216
- return json(res, 409, { error: "Configure Box in Settings before creating a cloud computer" });
19826
+ return json(res, 400, { error: "Provide requestId (UUID), a name, and acknowledgeCost: true to create a paid Boat" });
19827
+ if (!boat.boatConfigured(cfg))
19828
+ return json(res, 409, { error: "Configure Boat in Settings before creating a cloud computer" });
19217
19829
  const computer = teamComputers.create(parsed.data.name, parsed.data.requestId);
19218
19830
  const release = claimTeamComputerLifecycle(computer);
19219
19831
  try {
19220
- await box.provisionBox(cfg, teamComputerOwner(computer.id), computer.name);
19832
+ await boat.provisionBoat(cfg, teamComputerOwner(computer.id), computer.name);
19221
19833
  teamComputers.setProblem(computer.id);
19222
19834
  return json(res, 201, { id: computer.id });
19223
19835
  }
@@ -19231,18 +19843,18 @@ const handleRequest = async (req, res) => {
19231
19843
  }
19232
19844
  if (method === "POST" && found && action && action !== "control") {
19233
19845
  if (action === "provision" && body?.acknowledgeCost !== true)
19234
- return json(res, 400, { error: "Confirm Box creation or wake costs with acknowledgeCost: true" });
19846
+ return json(res, 400, { error: "Confirm Boat creation or wake costs with acknowledgeCost: true" });
19235
19847
  // A ready-only join never wakes, provisions or steals an agent's turn.
19236
19848
  // The caller takes a separate explicit human-control lease first.
19237
19849
  if (action === "join") {
19238
19850
  const key = teamComputerOwner(found.id);
19239
- if (boxLifecycleBusyBots.has(key))
19851
+ if (boatLifecycleBusyBots.has(key))
19240
19852
  return json(res, 409, { error: "Wait for this computer's action to finish" });
19241
19853
  if (!computerControl.snapshot(key).held)
19242
19854
  return json(res, 409, { error: "Take control before opening this shared desktop" });
19243
19855
  const release = claimBotComputerLifecycle(key);
19244
19856
  try {
19245
- return json(res, 200, await box.joinReadyBox(cfg, key));
19857
+ return json(res, 200, await boat.joinReadyBoat(cfg, key));
19246
19858
  }
19247
19859
  finally {
19248
19860
  release();
@@ -19251,8 +19863,8 @@ const handleRequest = async (req, res) => {
19251
19863
  const release = claimTeamComputerLifecycle(found);
19252
19864
  try {
19253
19865
  const result = action === "provision"
19254
- ? await box.provisionBox(cfg, teamComputerOwner(found.id), found.name)
19255
- : await box.sleepBox(cfg, teamComputerOwner(found.id));
19866
+ ? await boat.provisionBoat(cfg, teamComputerOwner(found.id), found.name)
19867
+ : await boat.sleepBoat(cfg, teamComputerOwner(found.id));
19256
19868
  teamComputers.setProblem(found.id);
19257
19869
  return json(res, 200, result);
19258
19870
  }
@@ -19266,12 +19878,13 @@ const handleRequest = async (req, res) => {
19266
19878
  }
19267
19879
  return json(res, 405, { error: "method not allowed" });
19268
19880
  }
19269
- // Account-wide Box inventory is a Settings surface, never a provisioning
19881
+ // Account-wide Boat inventory is a Settings surface, never a provisioning
19270
19882
  // path. Listing remains read-only; lifecycle changes require explicit
19271
19883
  // JSON actions and are revalidated against a fresh provider listing.
19884
+ // The REST path keeps its historical /boxes segment.
19272
19885
  if (method === "GET" && path === "/api/computers/boxes") {
19273
19886
  res.setHeader("cache-control", "private, no-store");
19274
- return json(res, 200, await box.listManagedBoxes(cfg, managedBoxOwners()));
19887
+ return json(res, 200, await boat.listManagedBoats(cfg, managedBoatOwners()));
19275
19888
  }
19276
19889
  m = path.match(/^\/api\/computers\/boxes\/([\w-]+)\/(sleep|delete)$/);
19277
19890
  if (m && method === "POST") {
@@ -19282,16 +19895,16 @@ const handleRequest = async (req, res) => {
19282
19895
  if (computerProviderConfigTransitions.has("box")) {
19283
19896
  return json(res, 409, { error: providerTransitionMessage("box") });
19284
19897
  }
19285
- const releaseInventoryRequest = claimBoxInventoryRequest(m[1]);
19898
+ const releaseInventoryRequest = claimBoatInventoryRequest(m[1]);
19286
19899
  try {
19287
- const owners = managedBoxOwners();
19900
+ const owners = managedBoatOwners();
19288
19901
  if (m[2] === "sleep") {
19289
- return json(res, 200, await box.sleepManagedBox(cfg, owners, m[1], claimManagedBoxMutation));
19902
+ return json(res, 200, await boat.sleepManagedBoat(cfg, owners, m[1], claimManagedBoatMutation));
19290
19903
  }
19291
19904
  if (typeof body?.confirmName !== "string" || body.confirmName.length > 100) {
19292
19905
  return json(res, 400, { error: "confirmName must be the cloud computer name shown in Settings" });
19293
19906
  }
19294
- return json(res, 202, await box.deleteManagedBox(cfg, owners, m[1], body.confirmName, claimManagedBoxMutation));
19907
+ return json(res, 202, await boat.deleteManagedBoat(cfg, owners, m[1], body.confirmName, claimManagedBoatMutation));
19295
19908
  }
19296
19909
  finally {
19297
19910
  releaseInventoryRequest();
@@ -19299,7 +19912,7 @@ const handleRequest = async (req, res) => {
19299
19912
  }
19300
19913
  if (method === "GET" && path === "/api/computers/vps") {
19301
19914
  res.setHeader("cache-control", "private, no-store");
19302
- return json(res, 200, await vps.listManagedVpsComputers(cfg, managedBoxOwners()));
19915
+ return json(res, 200, await vps.listManagedVpsComputers(cfg, managedBoatOwners()));
19303
19916
  }
19304
19917
  m = path.match(/^\/api\/computers\/vps\/([\w-]+)\/remove$/);
19305
19918
  if (m && method === "POST") {
@@ -19315,7 +19928,7 @@ const handleRequest = async (req, res) => {
19315
19928
  }
19316
19929
  const releaseComputerLifecycle = claimManagedVpsMutation(m[1]);
19317
19930
  try {
19318
- return json(res, 200, await vps.removeManagedVpsComputer(cfg, managedBoxOwners(), m[1], body.confirmName));
19931
+ return json(res, 200, await vps.removeManagedVpsComputer(cfg, managedBoatOwners(), m[1], body.confirmName));
19319
19932
  }
19320
19933
  finally {
19321
19934
  releaseComputerLifecycle();
@@ -19346,6 +19959,9 @@ const handleRequest = async (req, res) => {
19346
19959
  if (localVmMode(cfg) === "per-bot" && action === "run") {
19347
19960
  return json(res, 409, { error: "Per-bot mode creates each desktop from that bot's Computer panel" });
19348
19961
  }
19962
+ if (localVmMode(cfg) === "pool" && action === "run") {
19963
+ return json(res, 409, { error: "Pool mode creates its desktops automatically from conversation turns" });
19964
+ }
19349
19965
  const vmOwner = localVmLeaseFor(SHARED_LOCAL_VM_TARGET).current(localVmOwnerBusy);
19350
19966
  if (vmOwner && (action === "stop" || action === "remove" || action === "run")) {
19351
19967
  return json(res, 409, { error: "the Local VM is being used by a bot — stop that turn first" });
@@ -19393,7 +20009,7 @@ const handleRequest = async (req, res) => {
19393
20009
  const bot = computerPreviewBot(m[1], url);
19394
20010
  if (!bot)
19395
20011
  return json(res, 404, { error: "no such bot" });
19396
- return json(res, 200, await localVmPayload(localVmTargetForBot(bot.id)));
20012
+ return json(res, 200, await localVmPayload(localVmTargetForStatus(bot.id, bot.threadId)));
19397
20013
  }
19398
20014
  m = path.match(/^\/api\/bots\/([\w-]+)\/local-computer\/(run|stop|remove)$/);
19399
20015
  if (m && method === "POST") {
@@ -19403,7 +20019,7 @@ const handleRequest = async (req, res) => {
19403
20019
  const bot = store.bot(m[1]);
19404
20020
  if (!bot)
19405
20021
  return json(res, 404, { error: "no such bot" });
19406
- if (boxLifecycleBusyBots.has(bot.id)) {
20022
+ if (boatLifecycleBusyBots.has(bot.id)) {
19407
20023
  return json(res, 409, { error: "this bot's computer is being changed or deleted — wait for it to finish" });
19408
20024
  }
19409
20025
  const action = z.enum(["run", "stop", "remove"]).parse(m[2]);
@@ -19471,7 +20087,7 @@ const handleRequest = async (req, res) => {
19471
20087
  if (url.searchParams.has("threadId") && await computerPreviewSurface(bot, bot.threadId) !== "vm") {
19472
20088
  return json(res, 409, { error: "This conversation is not using the Local VM" });
19473
20089
  }
19474
- const target = localVmTargetForBot(bot.id);
20090
+ const target = localVmTargetForStatus(bot.id, url.searchParams.has("threadId") ? bot.threadId : undefined);
19475
20091
  localVmIdleFor(target).touch();
19476
20092
  res.setHeader("cache-control", "private, no-store");
19477
20093
  return json(res, 200, {
@@ -20153,6 +20769,18 @@ const handleRequest = async (req, res) => {
20153
20769
  if (!checked.ok)
20154
20770
  return json(res, checked.status, { error: checked.error });
20155
20771
  }
20772
+ if (patch.automaticRecovery?.enabled) {
20773
+ const checked = checkedModelSelection(patch.automaticRecovery.backup, undefined, true);
20774
+ if (!checked.ok)
20775
+ return json(res, checked.status, { error: checked.error });
20776
+ const target = registry.get(checked.selection.instanceId);
20777
+ if (!target.enabled)
20778
+ return json(res, 400, { error: "Enable the backup engine before selecting it for recovery." });
20779
+ const refusal = policyModelRefusal(target);
20780
+ if (refusal)
20781
+ return json(res, 403, { error: refusal, code: "managed_policy" });
20782
+ patch.automaticRecovery.backup = checked.selection;
20783
+ }
20156
20784
  if (!Object.keys(patch).length)
20157
20785
  return json(res, 400, { error: "nothing to save" });
20158
20786
  const changingVoiceProvider = patch.tts?.provider !== undefined
@@ -20211,16 +20839,16 @@ const handleRequest = async (req, res) => {
20211
20839
  }
20212
20840
  if (patch.box?.token !== undefined)
20213
20841
  patch.box.token = patch.box.token.trim();
20214
- const currentBoxToken = cfg.box?.token?.trim() ?? "";
20215
- const nextBoxToken = patch.box?.token === undefined ? currentBoxToken : patch.box.token;
20216
- const changingBoxToken = patch.box?.token !== undefined && nextBoxToken !== currentBoxToken;
20842
+ const currentBoatToken = cfg.box?.token?.trim() ?? "";
20843
+ const nextBoatToken = patch.box?.token === undefined ? currentBoatToken : patch.box.token;
20844
+ const changingBoatToken = patch.box?.token !== undefined && nextBoatToken !== currentBoatToken;
20217
20845
  const currentVpsAlias = vpsSshAlias(cfg);
20218
20846
  const nextVpsAlias = patch.vps === undefined
20219
20847
  ? currentVpsAlias
20220
20848
  : vpsSshAlias({ ...cfg, vps: patch.vps });
20221
20849
  const changingVpsAlias = patch.vps !== undefined && nextVpsAlias !== currentVpsAlias;
20222
20850
  const transitioningProviders = [
20223
- ...(changingBoxToken ? ["box"] : []),
20851
+ ...(changingBoatToken ? ["box"] : []),
20224
20852
  ...(changingVpsAlias ? ["vps"] : []),
20225
20853
  ];
20226
20854
  providerConfigBusy = true;
@@ -20236,7 +20864,7 @@ const handleRequest = async (req, res) => {
20236
20864
  for (const provider of transitioningProviders)
20237
20865
  computerProviderConfigTransitions.add(provider);
20238
20866
  if (changingVpsAlias && currentVpsAlias) {
20239
- const inventory = await vps.listManagedVpsComputers({ vps: { sshAlias: currentVpsAlias } }, managedBoxOwners());
20867
+ const inventory = await vps.listManagedVpsComputers({ vps: { sshAlias: currentVpsAlias } }, managedBoatOwners());
20240
20868
  if (!inventory.available) {
20241
20869
  return json(res, 503, {
20242
20870
  error: `${inventory.problem ?? "VPS computer inventory is unavailable"}. Keep the current SSH config alias and retry`,
@@ -20246,24 +20874,24 @@ const handleRequest = async (req, res) => {
20246
20874
  if (resourceError)
20247
20875
  return json(res, 409, { error: resourceError });
20248
20876
  }
20249
- let boxRecovery = changingBoxToken ? boxCreateRecoverySnapshot() : [];
20250
- let boxDeletions = changingBoxToken ? boxDeletionSnapshot() : [];
20251
- if (changingBoxToken && boxDeletions.length > 0 && !nextBoxToken) {
20877
+ let boatRecovery = changingBoatToken ? boatCreateRecoverySnapshot() : [];
20878
+ let boatDeletions = changingBoatToken ? boatDeletionSnapshot() : [];
20879
+ if (changingBoatToken && boatDeletions.length > 0 && !nextBoatToken) {
20252
20880
  return json(res, 409, {
20253
- error: "finish or retry pending cloud computer deletion before removing the Box account",
20881
+ error: "finish or retry pending cloud computer deletion before removing the Boat account",
20254
20882
  });
20255
20883
  }
20256
20884
  let replacementProvedByDeletion = false;
20257
- if (changingBoxToken && boxDeletions.length > 0 && nextBoxToken) {
20885
+ if (changingBoatToken && boatDeletions.length > 0 && nextBoatToken) {
20258
20886
  try {
20259
- await box.verifyBoxDeletionCredential({ box: { token: nextBoxToken } });
20887
+ await boat.verifyBoatDeletionCredential({ box: { token: nextBoatToken } });
20260
20888
  replacementProvedByDeletion = true;
20261
20889
  // Verification can observe a completed operation and retire both
20262
20890
  // its deletion fence and matching create receipt. Never continue
20263
20891
  // with the pre-verification snapshots: they would demand access
20264
- // to a Box whose exact operation just proved it was deleted.
20265
- boxRecovery = boxCreateRecoverySnapshot();
20266
- boxDeletions = boxDeletionSnapshot();
20892
+ // to a Boat whose exact operation just proved it was deleted.
20893
+ boatRecovery = boatCreateRecoverySnapshot();
20894
+ boatDeletions = boatDeletionSnapshot();
20267
20895
  }
20268
20896
  catch (error) {
20269
20897
  return json(res, error?.status ?? 503, {
@@ -20271,28 +20899,28 @@ const handleRequest = async (req, res) => {
20271
20899
  });
20272
20900
  }
20273
20901
  }
20274
- let currentBoxInventory = null;
20275
- let replacingRejectedBoxToken = false;
20276
- let currentBoxResources = null;
20277
- const journalBoxResources = [];
20278
- const deletingBoxIds = new Set(boxDeletions.map((entry) => entry.boxId));
20279
- if (changingBoxToken && currentBoxToken) {
20280
- currentBoxInventory = await box.listManagedBoxes({ box: { token: currentBoxToken } }, managedBoxOwners());
20281
- if (!currentBoxInventory.available) {
20282
- replacingRejectedBoxToken = currentBoxInventory.credentialRejected === true && Boolean(nextBoxToken);
20283
- if (!replacementProvedByDeletion && !replacingRejectedBoxToken) {
20902
+ let currentBoatInventory = null;
20903
+ let replacingRejectedBoatToken = false;
20904
+ let currentBoatResources = null;
20905
+ const journalBoatResources = [];
20906
+ const deletingBoatIds = new Set(boatDeletions.map((entry) => entry.boxId));
20907
+ if (changingBoatToken && currentBoatToken) {
20908
+ currentBoatInventory = await boat.listManagedBoats({ box: { token: currentBoatToken } }, managedBoatOwners());
20909
+ if (!currentBoatInventory.available) {
20910
+ replacingRejectedBoatToken = currentBoatInventory.credentialRejected === true && Boolean(nextBoatToken);
20911
+ if (!replacementProvedByDeletion && !replacingRejectedBoatToken) {
20284
20912
  return json(res, 503, {
20285
- error: `${currentBoxInventory.problem ?? "cloud computer inventory is unavailable"}. Keep the current Box account and retry`,
20913
+ error: `${currentBoatInventory.problem ?? "cloud computer inventory is unavailable"}. Keep the current Boat account and retry`,
20286
20914
  });
20287
20915
  }
20288
20916
  // A rejected old key cannot authorize its own rotation. Below,
20289
- // validate the replacement and prove access to remembered Boxes;
20917
+ // validate the replacement and prove access to remembered Boats;
20290
20918
  // pending deletions retain their target-bound verification.
20291
- currentBoxInventory = null;
20919
+ currentBoatInventory = null;
20292
20920
  }
20293
- if (currentBoxInventory) {
20294
- const currentById = new Map(currentBoxInventory.instances.map((instance) => [instance.boxId, { boxId: instance.boxId, name: instance.name }]));
20295
- for (const recovery of boxRecovery) {
20921
+ if (currentBoatInventory) {
20922
+ const currentById = new Map(currentBoatInventory.instances.map((instance) => [instance.boxId, { boxId: instance.boxId, name: instance.name }]));
20923
+ for (const recovery of boatRecovery) {
20296
20924
  if (!recovery.boxId)
20297
20925
  continue;
20298
20926
  // A failed provisioning attempt may never have reached the
@@ -20300,29 +20928,29 @@ const handleRequest = async (req, res) => {
20300
20928
  // proved the exact deletion target, so its in-flight resource
20301
20929
  // is governed by that stronger target-bound receipt rather
20302
20930
  // than an OpenMausBot name check.
20303
- if (replacementProvedByDeletion && deletingBoxIds.has(recovery.boxId))
20931
+ if (replacementProvedByDeletion && deletingBoatIds.has(recovery.boxId))
20304
20932
  continue;
20305
- const inspected = await box.inspectBoxIdentity({ box: { token: currentBoxToken } }, recovery.boxId);
20933
+ const inspected = await boat.inspectBoatIdentity({ box: { token: currentBoatToken } }, recovery.boxId);
20306
20934
  if (!inspected.available) {
20307
20935
  return json(res, 503, {
20308
- error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Keep the current Box account and retry`,
20936
+ error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Keep the current Boat account and retry`,
20309
20937
  });
20310
20938
  }
20311
20939
  if (!inspected.identity) {
20312
20940
  // Reconcile exact stale receipts while the current credential is
20313
20941
  // still available. Leaving one behind would make a later token
20314
- // addition demand access to a Box the provider proved is gone.
20315
- retireDeletedBoxCreate(recovery.boxId);
20942
+ // addition demand access to a Boat the provider proved is gone.
20943
+ retireDeletedBoatCreate(recovery.boxId);
20316
20944
  continue;
20317
20945
  }
20318
20946
  const listed = currentById.get(inspected.identity.boxId);
20319
20947
  if (listed && listed.name !== inspected.identity.name) {
20320
- return json(res, 503, { error: "boat.dev returned conflicting cloud computer identities; keep the current Box account and retry" });
20948
+ return json(res, 503, { error: "boat.dev returned conflicting cloud computer identities; keep the current Boat account and retry" });
20321
20949
  }
20322
20950
  currentById.set(inspected.identity.boxId, inspected.identity);
20323
- journalBoxResources.push(inspected.identity);
20951
+ journalBoatResources.push(inspected.identity);
20324
20952
  }
20325
- currentBoxResources = [...currentById.values()];
20953
+ currentBoatResources = [...currentById.values()];
20326
20954
  }
20327
20955
  }
20328
20956
  if (changingLocalVmMode) {
@@ -20361,50 +20989,50 @@ const handleRequest = async (req, res) => {
20361
20989
  patch.composio = { ...patch.composio, apiKey: "", sessionId: "" };
20362
20990
  }
20363
20991
  }
20364
- // check a box token against the provider before storing it: a
20992
+ // check a boat token against the provider before storing it: a
20365
20993
  // rejected token used to save happily and only surface as a 401 in
20366
20994
  // another panel later, with nothing the user could act on
20367
- const newBoxToken = patch.box?.token;
20368
- if (newBoxToken?.trim()) {
20369
- const check = await box.verifyToken(newBoxToken);
20995
+ const newBoatToken = patch.box?.token;
20996
+ if (newBoatToken?.trim()) {
20997
+ const check = await boat.verifyToken(newBoatToken);
20370
20998
  if (!check.ok)
20371
20999
  return json(res, 400, { error: check.message });
20372
21000
  }
20373
- if (replacingRejectedBoxToken) {
21001
+ if (replacingRejectedBoatToken) {
20374
21002
  // An expired credential cannot authorize its own replacement. Probe
20375
21003
  // the new account without adopting or retiring any local identities.
20376
- const replacement = await box.listManagedBoxes({ box: { token: nextBoxToken } }, managedBoxOwners(), { adoptLegacy: false });
21004
+ const replacement = await boat.listManagedBoats({ box: { token: nextBoatToken } }, managedBoatOwners(), { adoptLegacy: false });
20377
21005
  if (!replacement.available)
20378
- return json(res, 503, { error: replacement.problem ?? "Could not verify the replacement Box key. Your saved key and computers are unchanged." });
21006
+ return json(res, 503, { error: replacement.problem ?? "Could not verify the replacement Boat key. Your saved key and computers are unchanged." });
20379
21007
  }
20380
- if (changingBoxToken && (!currentBoxToken || replacementProvedByDeletion || replacingRejectedBoxToken) && boxRecovery.length > 0) {
20381
- if (!nextBoxToken) {
20382
- return json(res, 409, { error: "restore the Box account that owns the remembered cloud computers before clearing it" });
21008
+ if (changingBoatToken && (!currentBoatToken || replacementProvedByDeletion || replacingRejectedBoatToken) && boatRecovery.length > 0) {
21009
+ if (!nextBoatToken) {
21010
+ return json(res, 409, { error: "restore the Boat account that owns the remembered cloud computers before clearing it" });
20383
21011
  }
20384
- for (const recovery of boxRecovery) {
21012
+ for (const recovery of boatRecovery) {
20385
21013
  if (!recovery.boxId) {
20386
- return json(res, 409, { error: "finish reconciling pending cloud computer creation before changing the Box account" });
21014
+ return json(res, 409, { error: "finish reconciling pending cloud computer creation before changing the Boat account" });
20387
21015
  }
20388
- if (replacementProvedByDeletion && deletingBoxIds.has(recovery.boxId))
21016
+ if (replacementProvedByDeletion && deletingBoatIds.has(recovery.boxId))
20389
21017
  continue;
20390
- const inspected = await box.inspectBoxIdentity({ box: { token: nextBoxToken } }, recovery.boxId);
21018
+ const inspected = await boat.inspectBoatIdentity({ box: { token: nextBoatToken } }, recovery.boxId);
20391
21019
  if (!inspected.available) {
20392
21020
  return json(res, 503, {
20393
- error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Retry with the Box account that created it`,
21021
+ error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Retry with the Boat account that created it`,
20394
21022
  });
20395
21023
  }
20396
- if (!inspected.identity || !(await box.boxNameMatchesBot(recovery.botId, inspected.identity.name))) {
20397
- return json(res, 409, { error: "that Box token cannot access the remembered cloud computers from this installation" });
21024
+ if (!inspected.identity || !(await boat.boatNameMatchesBot(recovery.botId, inspected.identity.name))) {
21025
+ return json(res, 409, { error: "that Boat token cannot access the remembered cloud computers from this installation" });
20398
21026
  }
20399
21027
  }
20400
21028
  }
20401
- if (changingBoxToken && currentBoxInventory && currentBoxResources) {
21029
+ if (changingBoatToken && currentBoatInventory && currentBoatResources) {
20402
21030
  let replacementResources = null;
20403
- if (nextBoxToken) {
20404
- const replacementInventory = await box.listManagedBoxes({ box: { token: nextBoxToken } }, managedBoxOwners(), { adoptLegacy: false });
21031
+ if (nextBoatToken) {
21032
+ const replacementInventory = await boat.listManagedBoats({ box: { token: nextBoatToken } }, managedBoatOwners(), { adoptLegacy: false });
20405
21033
  if (!replacementInventory.available) {
20406
21034
  return json(res, 503, {
20407
- error: `${replacementInventory.problem ?? "cloud computer inventory is unavailable"}. Keep the current Box account and retry`,
21035
+ error: `${replacementInventory.problem ?? "cloud computer inventory is unavailable"}. Keep the current Boat account and retry`,
20408
21036
  });
20409
21037
  }
20410
21038
  replacementResources = replacementInventory.instances.map((instance) => ({
@@ -20412,21 +21040,21 @@ const handleRequest = async (req, res) => {
20412
21040
  name: instance.name,
20413
21041
  }));
20414
21042
  const replacementById = new Map(replacementResources.map((instance) => [instance.boxId, { boxId: instance.boxId, name: instance.name }]));
20415
- for (const identity of journalBoxResources) {
20416
- const inspected = await box.inspectBoxIdentity({ box: { token: nextBoxToken } }, identity.boxId);
21043
+ for (const identity of journalBoatResources) {
21044
+ const inspected = await boat.inspectBoatIdentity({ box: { token: nextBoatToken } }, identity.boxId);
20417
21045
  if (!inspected.available) {
20418
21046
  return json(res, 503, {
20419
- error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Keep the current Box account and retry`,
21047
+ error: `${inspected.problem ?? "a remembered cloud computer could not be verified"}. Keep the current Boat account and retry`,
20420
21048
  });
20421
21049
  }
20422
21050
  if (!inspected.identity || inspected.identity.name !== identity.name) {
20423
- return json(res, 409, { error: "the replacement Box token does not access the same cloud computers" });
21051
+ return json(res, 409, { error: "the replacement Boat token does not access the same cloud computers" });
20424
21052
  }
20425
21053
  replacementById.set(inspected.identity.boxId, inspected.identity);
20426
21054
  }
20427
21055
  replacementResources = [...replacementById.values()];
20428
21056
  }
20429
- const resourceError = boxAccountResourceChangeError(currentBoxResources, replacementResources);
21057
+ const resourceError = boatAccountResourceChangeError(currentBoatResources, replacementResources);
20430
21058
  if (resourceError)
20431
21059
  return json(res, 409, { error: resourceError });
20432
21060
  }
@@ -20694,6 +21322,9 @@ const handleRequest = async (req, res) => {
20694
21322
  return json(res, 200, {
20695
21323
  configured: composio.configured(cfg),
20696
21324
  mode: composio.connectionMode(cfg),
21325
+ // lets the panel say "add a key" on a fresh server instead of
21326
+ // reporting an outage that never happened
21327
+ setup: composio.connectorSetup(cfg),
20697
21328
  source,
20698
21329
  cards,
20699
21330
  ...(pagination ? { pagination } : {}),
@@ -20901,7 +21532,7 @@ const handleRequest = async (req, res) => {
20901
21532
  }
20902
21533
  return json(res, 405, { error: "method not allowed" });
20903
21534
  }
20904
- // ── the bot's cloud computer (Box) ──
21535
+ // ── the bot's cloud computer (Boat) ──
20905
21536
  m = path.match(/^\/api\/bots\/([\w-]+)\/computer$/);
20906
21537
  if (m && method === "GET") {
20907
21538
  const bot = computerPreviewBot(m[1], url);
@@ -20912,10 +21543,10 @@ const handleRequest = async (req, res) => {
20912
21543
  return json(res, 200, { surface, configured: false, backend: bot.cloudBackend === "vps" ? "vps" : "box" });
20913
21544
  const teamComputer = inheritedTeamComputer(bot);
20914
21545
  if (teamComputer)
20915
- return json(res, 200, { surface, backend: "box", teamComputer: { id: teamComputer.id, name: teamComputer.name }, ...(await box.boxStatus(cfg, teamComputerOwner(teamComputer.id))) });
21546
+ return json(res, 200, { surface, backend: "box", teamComputer: { id: teamComputer.id, name: teamComputer.name }, ...(await boat.boatStatus(cfg, teamComputerOwner(teamComputer.id))) });
20916
21547
  return bot.cloudBackend === "vps"
20917
21548
  ? json(res, 200, { surface, backend: "vps", ...(await vps.vpsComputerStatus(cfg, bot.id)) })
20918
- : json(res, 200, { surface, backend: "box", ...(await box.boxStatus(cfg, bot.id)) });
21549
+ : json(res, 200, { surface, backend: "box", ...(await boat.boatStatus(cfg, bot.id)) });
20919
21550
  }
20920
21551
  // Who is driving this bot's computer. GET is the panel's initial read;
20921
21552
  // POST take/release/dismiss-help are the person's three moves. The bot
@@ -20949,7 +21580,7 @@ const handleRequest = async (req, res) => {
20949
21580
  return json(res, 400, { error: "controlLeaseId is invalid" });
20950
21581
  }
20951
21582
  const controlLeaseId = leaseResult?.data;
20952
- if (action === "take" && (boxLifecycleBusyBots.has(bot.id) || boxLifecycleBusyBots.has(controlKey))) {
21583
+ if (action === "take" && (boatLifecycleBusyBots.has(bot.id) || boatLifecycleBusyBots.has(controlKey))) {
20953
21584
  return json(res, 409, { error: "this bot's cloud computer is being changed — wait before taking control" });
20954
21585
  }
20955
21586
  if (action === "take" && controlLeaseId) {
@@ -20999,7 +21630,7 @@ const handleRequest = async (req, res) => {
20999
21630
  // request (same reasoning as the Local VM lifecycle routes above): a
21000
21631
  // hostile page cannot submit it with a form, and its cross-origin JSON
21001
21632
  // request dies in the preflight this server never answers. Applied to
21002
- // both backends — the Box branch runs commands too.
21633
+ // both backends — the Boat branch runs commands too.
21003
21634
  if (!String(req.headers["content-type"] ?? "").toLowerCase().startsWith("application/json")) {
21004
21635
  return json(res, 415, { error: "content-type must be application/json" });
21005
21636
  }
@@ -21007,13 +21638,13 @@ const handleRequest = async (req, res) => {
21007
21638
  if (computerProviderConfigTransitions.has(remoteProvider)) {
21008
21639
  return json(res, 409, { error: providerTransitionMessage(remoteProvider) });
21009
21640
  }
21010
- if (boxLifecycleBusyBots.has(botId)) {
21641
+ if (boatLifecycleBusyBots.has(botId)) {
21011
21642
  return json(res, 409, { error: "this bot's cloud computer is being changed — wait for it to finish" });
21012
21643
  }
21013
21644
  const teamComputer = inheritedTeamComputer(bot);
21014
21645
  if (teamComputer) {
21015
21646
  const key = teamComputerOwner(teamComputer.id);
21016
- if (boxLifecycleBusyBots.has(key))
21647
+ if (boatLifecycleBusyBots.has(key))
21017
21648
  return json(res, 409, { error: "This team computer is being changed; wait for it to finish" });
21018
21649
  if (m[2] === "provision" || m[2] === "remove")
21019
21650
  return json(res, 409, { error: "Manage this shared computer from the Team map" });
@@ -21024,12 +21655,12 @@ const handleRequest = async (req, res) => {
21024
21655
  const release = m[2] === "sleep" ? claimTeamComputerLifecycle(teamComputer) : claimBotComputerLifecycle(key);
21025
21656
  try {
21026
21657
  if (m[2] === "join")
21027
- return json(res, 200, await box.joinReadyBox(cfg, key));
21658
+ return json(res, 200, await boat.joinReadyBoat(cfg, key));
21028
21659
  if (m[2] === "screenshot") {
21029
21660
  res.setHeader("cache-control", "private, no-store");
21030
- return json(res, 200, await box.screenshotBox(cfg, key));
21661
+ return json(res, 200, await boat.screenshotBoat(cfg, key));
21031
21662
  }
21032
- return json(res, 200, await box.sleepBox(cfg, key));
21663
+ return json(res, 200, await boat.sleepBoat(cfg, key));
21033
21664
  }
21034
21665
  finally {
21035
21666
  release();
@@ -21070,8 +21701,8 @@ const handleRequest = async (req, res) => {
21070
21701
  releaseComputerLifecycle();
21071
21702
  }
21072
21703
  }
21073
- const activeBoxTurn = botHasActiveTurn(botId);
21074
- if (["provision", "sleep"].includes(m[2]) && activeBoxTurn) {
21704
+ const activeBoatTurn = botHasActiveTurn(botId);
21705
+ if (["provision", "sleep"].includes(m[2]) && activeBoatTurn) {
21075
21706
  return json(res, 409, {
21076
21707
  error: CLOUD_COMPUTER_BUSY_ERROR,
21077
21708
  });
@@ -21079,39 +21710,39 @@ const handleRequest = async (req, res) => {
21079
21710
  // Input validity is independent of destination authorization. Preserve
21080
21711
  // the stable 400 contract for oversized commands without contacting the
21081
21712
  // provider; a valid Auto request still reaches the 409 gate below.
21082
- let boxCommand;
21713
+ let boatCommand;
21083
21714
  if (m[2] === "exec") {
21084
21715
  const body = await readBody(req);
21085
- boxCommand = String(body?.command ?? "");
21086
- if (boxCommand.length > box.MAX_REMOTE_COMMAND_LENGTH) {
21716
+ boatCommand = String(body?.command ?? "");
21717
+ if (boatCommand.length > boat.MAX_REMOTE_COMMAND_LENGTH) {
21087
21718
  return json(res, 400, {
21088
- error: `command is too long (maximum ${box.MAX_REMOTE_COMMAND_LENGTH} characters)`,
21719
+ error: `command is too long (maximum ${boat.MAX_REMOTE_COMMAND_LENGTH} characters)`,
21089
21720
  });
21090
21721
  }
21091
21722
  }
21092
21723
  if (bot.computer !== "cloud" && !threadPreview) {
21093
21724
  return json(res, 409, {
21094
- error: "Choose Cloud before changing or opening this Box. Auto only checks existing computer state.",
21725
+ error: "Choose Cloud before changing or opening this Boat. Auto only checks existing computer state.",
21095
21726
  });
21096
21727
  }
21097
21728
  if (m[2] === "remove") {
21098
- // Boxes sleep and wake; only the VPS backend has a container to remove.
21099
- return json(res, 409, { error: "the cloud Box backend has no container to remove — use sleep instead" });
21729
+ // Boats sleep and wake; only the VPS backend has a container to remove.
21730
+ return json(res, 409, { error: "the cloud Boat backend has no container to remove — use sleep instead" });
21100
21731
  }
21101
21732
  const releaseComputerLifecycle = claimBotComputerLifecycle(botId);
21102
21733
  try {
21103
21734
  switch (m[2]) {
21104
21735
  case "provision":
21105
- return json(res, 200, await box.provisionBox(cfg, botId, bot.name));
21736
+ return json(res, 200, await boat.provisionBoat(cfg, botId, bot.name));
21106
21737
  case "join":
21107
- return json(res, 200, await (activeBoxTurn || threadPreview ? box.joinReadyBox(cfg, botId) : box.joinBox(cfg, botId)));
21738
+ return json(res, 200, await (activeBoatTurn || threadPreview ? boat.joinReadyBoat(cfg, botId) : boat.joinBoat(cfg, botId)));
21108
21739
  case "sleep":
21109
- return json(res, 200, await box.sleepBox(cfg, botId));
21740
+ return json(res, 200, await boat.sleepBoat(cfg, botId));
21110
21741
  case "exec":
21111
- return json(res, 200, await box.execOnBox(cfg, botId, boxCommand ?? ""));
21742
+ return json(res, 200, await boat.execOnBoat(cfg, botId, boatCommand ?? ""));
21112
21743
  case "screenshot":
21113
21744
  res.setHeader("cache-control", "private, no-store");
21114
- return json(res, 200, await box.screenshotBox(cfg, botId));
21745
+ return json(res, 200, await boat.screenshotBoat(cfg, botId));
21115
21746
  }
21116
21747
  }
21117
21748
  finally {
@@ -21281,6 +21912,7 @@ server.listen(PORT, "127.0.0.1", () => {
21281
21912
  // ordinary chat. Start only once every registry is initialized and the
21282
21913
  // endpoint is listening; earlier dispatch can hit uninitialized bindings.
21283
21914
  routines.start();
21915
+ memoryUpkeep.start();
21284
21916
  const leftover = pendingThreads();
21285
21917
  if (leftover.length)
21286
21918
  console.log(`delegations: ${leftover.length} thread(s) with queued handoffs from a previous run — draining`);
@@ -21335,6 +21967,7 @@ const gracefulShutdown = createGracefulShutdown({
21335
21967
  watchdog.stop();
21336
21968
  routines?.stop();
21337
21969
  calendarCalls?.stop();
21970
+ memoryUpkeep.stop();
21338
21971
  webhookIngress?.server.close();
21339
21972
  tunnelListener?.close();
21340
21973
  },