synabun 2.4.1 → 2.4.3

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 (345) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +46 -6
  4. package/lib/data-home-files.js +4 -2
  5. package/lib/first-launch-protection.js +8 -2
  6. package/lib/release-npm-ci.mjs +23 -1
  7. package/lib/update-snapshot.js +11 -4
  8. package/mcp-server/dist/http.d.ts.map +1 -1
  9. package/mcp-server/dist/http.js +25 -2
  10. package/mcp-server/dist/http.js.map +1 -1
  11. package/mcp-server/dist/index.d.ts.map +1 -1
  12. package/mcp-server/dist/index.js +62 -17
  13. package/mcp-server/dist/index.js.map +1 -1
  14. package/mcp-server/dist/services/browser-bench.d.ts +22 -22
  15. package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
  16. package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
  17. package/mcp-server/dist/services/memory-maintenance.js +34 -45
  18. package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
  19. package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
  20. package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
  21. package/mcp-server/dist/services/memory-migration-copy.js +467 -0
  22. package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
  23. package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
  24. package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
  25. package/mcp-server/dist/services/memory-migration-worker.js +60 -0
  26. package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
  27. package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
  28. package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
  29. package/mcp-server/dist/services/memory-retrieval.js +188 -40
  30. package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
  31. package/mcp-server/dist/services/memory-schema.d.ts +58 -2
  32. package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
  33. package/mcp-server/dist/services/memory-schema.js +190 -13
  34. package/mcp-server/dist/services/memory-schema.js.map +1 -1
  35. package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
  36. package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
  37. package/mcp-server/dist/services/memory-sessions.js +56 -20
  38. package/mcp-server/dist/services/memory-sessions.js.map +1 -1
  39. package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
  40. package/mcp-server/dist/services/memory-verification.js +8 -5
  41. package/mcp-server/dist/services/memory-verification.js.map +1 -1
  42. package/mcp-server/dist/services/neural-interface.d.ts +5 -0
  43. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.js +19 -2
  45. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  46. package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
  47. package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
  48. package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
  49. package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
  50. package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
  51. package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
  52. package/mcp-server/dist/services/retrieval-reader.js +145 -0
  53. package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
  54. package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
  55. package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
  56. package/mcp-server/dist/services/sqlite-write.js +94 -0
  57. package/mcp-server/dist/services/sqlite-write.js.map +1 -0
  58. package/mcp-server/dist/services/sqlite.d.ts +39 -0
  59. package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
  60. package/mcp-server/dist/services/sqlite.js +249 -8
  61. package/mcp-server/dist/services/sqlite.js.map +1 -1
  62. package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
  63. package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
  64. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  65. package/mcp-server/dist/services/typesafe-config.js +32 -10
  66. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  67. package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
  68. package/mcp-server/dist/services/typesafe.js +9 -7
  69. package/mcp-server/dist/services/typesafe.js.map +1 -1
  70. package/mcp-server/dist/services/vector-cache.d.ts +32 -0
  71. package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
  72. package/mcp-server/dist/services/vector-cache.js +161 -8
  73. package/mcp-server/dist/services/vector-cache.js.map +1 -1
  74. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  75. package/mcp-server/dist/tools/agents.d.ts +11 -7
  76. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  77. package/mcp-server/dist/tools/agents.js +27 -9
  78. package/mcp-server/dist/tools/agents.js.map +1 -1
  79. package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
  80. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  81. package/mcp-server/dist/tools/browser-advanced.js +10 -3
  82. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  83. package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
  84. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
  85. package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
  86. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
  87. package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
  88. package/mcp-server/dist/tools/browser-interact.js +6 -1
  89. package/mcp-server/dist/tools/browser-interact.js.map +1 -1
  90. package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
  91. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  92. package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
  93. package/mcp-server/package-lock.json +5 -5
  94. package/mcp-server/package.json +1 -1
  95. package/mcp-server/src/http.ts +20 -2
  96. package/mcp-server/src/index.ts +59 -17
  97. package/mcp-server/src/services/memory-maintenance.ts +31 -28
  98. package/mcp-server/src/services/memory-migration-copy.ts +419 -0
  99. package/mcp-server/src/services/memory-migration-worker.ts +55 -0
  100. package/mcp-server/src/services/memory-retrieval.ts +173 -32
  101. package/mcp-server/src/services/memory-schema.ts +194 -12
  102. package/mcp-server/src/services/memory-sessions.ts +54 -21
  103. package/mcp-server/src/services/memory-verification.ts +7 -4
  104. package/mcp-server/src/services/neural-interface.ts +22 -2
  105. package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
  106. package/mcp-server/src/services/retrieval-reader.ts +131 -0
  107. package/mcp-server/src/services/sqlite-write.ts +60 -0
  108. package/mcp-server/src/services/sqlite.ts +246 -8
  109. package/mcp-server/src/services/typesafe-config.ts +25 -6
  110. package/mcp-server/src/services/typesafe.ts +9 -7
  111. package/mcp-server/src/services/vector-cache.ts +154 -9
  112. package/mcp-server/src/tools/agents.ts +26 -9
  113. package/mcp-server/src/tools/browser-advanced.ts +10 -3
  114. package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
  115. package/mcp-server/src/tools/browser-interact.ts +5 -1
  116. package/neural-interface/i18n/en.json +313 -2
  117. package/neural-interface/i18n/pt-BR.json +321 -10
  118. package/neural-interface/lib/agents/split.js +32 -4
  119. package/neural-interface/lib/assistant-api.js +52 -8
  120. package/neural-interface/lib/assistant-brains/claude.js +2 -0
  121. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  122. package/neural-interface/lib/assistant-catalog.js +2 -2
  123. package/neural-interface/lib/assistant-config.js +0 -7
  124. package/neural-interface/lib/assistant-dispatch.js +281 -95
  125. package/neural-interface/lib/assistant-envelope.js +40 -0
  126. package/neural-interface/lib/assistant-persona.js +16 -4
  127. package/neural-interface/lib/assistant-pricing.js +65 -14
  128. package/neural-interface/lib/assistant-router.js +131 -47
  129. package/neural-interface/lib/assistant-run-wait.js +45 -28
  130. package/neural-interface/lib/assistant-runtime.js +133 -42
  131. package/neural-interface/lib/backup-contents.js +158 -0
  132. package/neural-interface/lib/backup-crypto-io.js +330 -0
  133. package/neural-interface/lib/backup-crypto-worker.js +130 -0
  134. package/neural-interface/lib/backup-crypto.js +525 -0
  135. package/neural-interface/lib/backup-download.js +268 -0
  136. package/neural-interface/lib/backup-encryption.js +318 -0
  137. package/neural-interface/lib/backup-groups.js +287 -0
  138. package/neural-interface/lib/backup-restore-session.js +176 -0
  139. package/neural-interface/lib/backup-restore-stage.js +60 -0
  140. package/neural-interface/lib/backup-service.js +788 -233
  141. package/neural-interface/lib/backup-zip-reader.js +30 -18
  142. package/neural-interface/lib/backup-zip-writer.js +34 -10
  143. package/neural-interface/lib/browser-extension-adapter.js +89 -15
  144. package/neural-interface/lib/browser-extension-archive.js +149 -0
  145. package/neural-interface/lib/browser-extension-bridge.js +24 -10
  146. package/neural-interface/lib/browser-extension-folder.js +596 -76
  147. package/neural-interface/lib/browser-extension-package.js +200 -0
  148. package/neural-interface/lib/browser-extension-pin.js +84 -0
  149. package/neural-interface/lib/browser-extension-pin.json +33 -0
  150. package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
  151. package/neural-interface/lib/browser-extension-setup.js +105 -18
  152. package/neural-interface/lib/claude-agent-bridge.js +1 -0
  153. package/neural-interface/lib/claude-session-cleanup.js +5 -1
  154. package/neural-interface/lib/cli-install.js +23 -3
  155. package/neural-interface/lib/cli-update-planner.js +171 -9
  156. package/neural-interface/lib/client-diagnostics.js +42 -0
  157. package/neural-interface/lib/confined-fs.js +7 -2
  158. package/neural-interface/lib/coordination/README.md +8 -2
  159. package/neural-interface/lib/coordination/contract.js +161 -0
  160. package/neural-interface/lib/coordination/database.js +999 -0
  161. package/neural-interface/lib/coordination/operations.js +436 -0
  162. package/neural-interface/lib/coordination/service.js +68 -537
  163. package/neural-interface/lib/coordination/storage-worker.js +101 -0
  164. package/neural-interface/lib/coordination/store.js +219 -1111
  165. package/neural-interface/lib/db.js +70 -32
  166. package/neural-interface/lib/health-count.js +37 -0
  167. package/neural-interface/lib/loop-stall.js +139 -0
  168. package/neural-interface/lib/maritaca/client.js +2 -2
  169. package/neural-interface/lib/maritaca/models.js +12 -17
  170. package/neural-interface/lib/maritaca/opencode.js +4 -2
  171. package/neural-interface/lib/memory-api.js +9 -1
  172. package/neural-interface/lib/memory-session-capture.js +42 -10
  173. package/neural-interface/lib/memory-store-gate.js +313 -0
  174. package/neural-interface/lib/memory-store-migrate.js +65 -0
  175. package/neural-interface/lib/memory-timers.js +7 -7
  176. package/neural-interface/lib/native-loop-providers.js +23 -17
  177. package/neural-interface/lib/native-loop-runtime.js +48 -9
  178. package/neural-interface/lib/opencode-build-preflight.js +18 -1
  179. package/neural-interface/lib/opencode-native-boundary.js +69 -8
  180. package/neural-interface/lib/opencode-provider-view.js +14 -3
  181. package/neural-interface/lib/opencode-shell-read.js +107 -0
  182. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  183. package/neural-interface/lib/opencode-turn-release.js +173 -0
  184. package/neural-interface/lib/opencode-v2-client.js +4 -1
  185. package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
  186. package/neural-interface/lib/opencode2-client.js +343 -7
  187. package/neural-interface/lib/opencode2-translate.js +161 -4
  188. package/neural-interface/lib/recall-impact.js +122 -0
  189. package/neural-interface/lib/scratch-evidence.js +420 -0
  190. package/neural-interface/lib/scratch-process-guard.js +139 -0
  191. package/neural-interface/lib/scratch-references.js +279 -0
  192. package/neural-interface/lib/scratch-retention-core.js +385 -0
  193. package/neural-interface/lib/scratch-retention-worker.js +37 -0
  194. package/neural-interface/lib/scratch-retention.js +151 -0
  195. package/neural-interface/lib/session-cache-builder.js +31 -43
  196. package/neural-interface/lib/session-cache-worker.js +157 -0
  197. package/neural-interface/lib/session-indexer.js +28 -21
  198. package/neural-interface/lib/session-search-index.js +85 -0
  199. package/neural-interface/lib/skills/creation.js +1 -1
  200. package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
  201. package/neural-interface/lib/style-guide/store.js +43 -3
  202. package/neural-interface/lib/system-restore.js +50 -0
  203. package/neural-interface/lib/teams/api.js +15 -6
  204. package/neural-interface/lib/teams/claims.js +67 -31
  205. package/neural-interface/lib/teams/index.js +7 -7
  206. package/neural-interface/lib/teams/integration.js +40 -40
  207. package/neural-interface/lib/teams/landing.js +6 -6
  208. package/neural-interface/lib/teams/recovery.js +24 -23
  209. package/neural-interface/lib/teams/scheduler.js +194 -95
  210. package/neural-interface/lib/teams/state.js +14 -14
  211. package/neural-interface/lib/teams/worktrees.js +27 -27
  212. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  213. package/neural-interface/lib/whatsapp/bridge.js +54 -7
  214. package/neural-interface/lib/worker-confinement.js +47 -2
  215. package/neural-interface/lib/worker-mcp-channel.js +2 -0
  216. package/neural-interface/lib/worker-resume.js +5 -0
  217. package/neural-interface/lib/worker-stop.js +86 -0
  218. package/neural-interface/package-lock.json +5 -5
  219. package/neural-interface/package.json +1 -1
  220. package/neural-interface/public/extension-setup.html +5 -2
  221. package/neural-interface/public/index.html +233 -24
  222. package/neural-interface/public/onboarding.html +259 -34
  223. package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
  224. package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
  225. package/neural-interface/public/shared/agy/agy-options.js +11 -0
  226. package/neural-interface/public/shared/agy/agy-panel.js +67 -20
  227. package/neural-interface/public/shared/agy/agy-styles.js +14 -12
  228. package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
  229. package/neural-interface/public/shared/api.js +1 -1
  230. package/neural-interface/public/shared/assistant/asst-api.js +28 -3
  231. package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
  232. package/neural-interface/public/shared/assistant/asst-control.js +2 -0
  233. package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
  234. package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
  235. package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
  236. package/neural-interface/public/shared/assistant/asst-render.js +243 -44
  237. package/neural-interface/public/shared/assistant/asst-route.js +100 -21
  238. package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
  239. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  240. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  241. package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
  242. package/neural-interface/public/shared/assistant/asst-state.js +11 -0
  243. package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
  244. package/neural-interface/public/shared/assistant/route-identity.js +2 -1
  245. package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
  246. package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
  247. package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
  248. package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
  249. package/neural-interface/public/shared/client-diagnostics.js +94 -0
  250. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  251. package/neural-interface/public/shared/cp/cp-styles.js +1 -1
  252. package/neural-interface/public/shared/effort-i18n.js +118 -0
  253. package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
  254. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  255. package/neural-interface/public/shared/html-shell.js +4 -52
  256. package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
  257. package/neural-interface/public/shared/memory-store-wait.js +52 -0
  258. package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
  259. package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
  260. package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
  261. package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
  262. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  264. package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
  265. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  269. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
  272. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  273. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
  274. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  275. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  276. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
  277. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  278. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  279. package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
  280. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  281. package/neural-interface/public/shared/output-format.js +294 -0
  282. package/neural-interface/public/shared/provider-icons.js +6 -0
  283. package/neural-interface/public/shared/schedules-view.js +2 -1
  284. package/neural-interface/public/shared/server-presence.js +77 -0
  285. package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
  286. package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
  287. package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
  288. package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
  289. package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
  290. package/neural-interface/public/shared/settings/settings-ia.js +1 -1
  291. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  292. package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
  293. package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
  294. package/neural-interface/public/shared/studio-attention.js +6 -0
  295. package/neural-interface/public/shared/styles.css +341 -437
  296. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  297. package/neural-interface/public/shared/transcript-rows.js +28 -3
  298. package/neural-interface/public/shared/tray-auto-close.js +49 -6
  299. package/neural-interface/public/shared/ui-agents.js +1 -2
  300. package/neural-interface/public/shared/ui-automation-studio.js +168 -108
  301. package/neural-interface/public/shared/ui-claude-panel.js +62 -65
  302. package/neural-interface/public/shared/ui-loading.js +124 -17
  303. package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
  304. package/neural-interface/public/shared/ui-navbar.js +2 -1
  305. package/neural-interface/public/shared/ui-output.js +533 -0
  306. package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
  307. package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
  308. package/neural-interface/public/shared/ui-sessions.js +2 -2
  309. package/neural-interface/public/shared/ui-settings-entry.js +18 -0
  310. package/neural-interface/public/shared/ui-settings.js +224 -65
  311. package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
  312. package/neural-interface/public/shared/ui-tooltip.js +16 -0
  313. package/neural-interface/public/shared/ui-tutorial.js +5 -6
  314. package/neural-interface/public/shared/ui-worker-end.js +27 -8
  315. package/neural-interface/public/shared/worker-end.js +9 -4
  316. package/neural-interface/public/variant/2d/main.js +5 -0
  317. package/neural-interface/public/variant/3d/app.js +10 -0
  318. package/neural-interface/public/variant/3d/main.js +5 -1
  319. package/neural-interface/scripts/scratch-retention.mjs +20 -0
  320. package/neural-interface/server.js +725 -173
  321. package/npm-shrinkwrap.json +5 -5
  322. package/package.json +1 -2
  323. package/scripts/restore-data-home-from-backup.mjs +175 -8
  324. package/setup.js +18 -4
  325. package/browser-extension/content.js +0 -189
  326. package/browser-extension/engine.js +0 -508
  327. package/browser-extension/icons/icon-128.png +0 -0
  328. package/browser-extension/icons/icon-16.png +0 -0
  329. package/browser-extension/icons/icon-32.png +0 -0
  330. package/browser-extension/icons/icon-48.png +0 -0
  331. package/browser-extension/icons/status-off-16.png +0 -0
  332. package/browser-extension/icons/status-off-32.png +0 -0
  333. package/browser-extension/icons/status-off-48.png +0 -0
  334. package/browser-extension/icons/status-on-16.png +0 -0
  335. package/browser-extension/icons/status-on-32.png +0 -0
  336. package/browser-extension/icons/status-on-48.png +0 -0
  337. package/browser-extension/manifest.json +0 -56
  338. package/browser-extension/popup-strings.js +0 -250
  339. package/browser-extension/popup-view.js +0 -151
  340. package/browser-extension/popup.css +0 -166
  341. package/browser-extension/popup.html +0 -108
  342. package/browser-extension/popup.js +0 -359
  343. package/browser-extension/service-worker.js +0 -275
  344. package/browser-extension/setup-content.js +0 -36
  345. package/browser-extension/tokens.css +0 -326
@@ -45,6 +45,7 @@ import { browserPolicyRoots } from './browser-policy-roots.js';
45
45
  import { stripFollowups } from '../public/shared/assistant/asst-followups.js';
46
46
  import { readJsonStrict } from './rulesets/fs-safe.js';
47
47
  import { redactTerminalSecrets } from './terminal-token-redaction.js';
48
+ import { readSafeShellOutputPage } from './opencode-shell-read.js';
48
49
 
49
50
  export const BRAIN_PROVIDERS = new Set(['claude-code', 'codex', 'opencode', 'antigravity']);
50
51
  // Every tab is called SynaBun; the session title (the history list) comes from
@@ -97,6 +98,8 @@ export const BRAIN_CREDENTIAL_RE = /^sbb_[A-Za-z0-9_-]{43}$/;
97
98
  export function mintBrainCredential() { return `sbb_${randomBytes(32).toString('base64url')}`; }
98
99
  /** The brains whose SynaBun MCP names the session id as its pin (the Claude CLI's header, agy's environment). */
99
100
  const BRAIN_PIN_PROVIDERS = new Set(['claude-code', 'antigravity']);
101
+ // Route cards raised by the brain's own turn: they close with that brain. A held dispatch's card outlives it.
102
+ const BRAIN_CARD_ORIGINS = ['agent_route', 'vision_guard'];
100
103
  // An OpenCode brain of a remote session reaches the web through these on its own
101
104
  // (no SynaBun browser, no approval): the gate plugin refuses them.
102
105
  const REMOTE_OPENCODE_WEB_TOOLS = new Set(['webfetch', 'websearch', 'codesearch']);
@@ -1201,6 +1204,52 @@ export function createAssistantRuntime({
1201
1204
  const raw = JSON.stringify({ type: 'assistant:limit', sessionId: live.record.id, limit: live.limit });
1202
1205
  for (const ws of sockets) { if (ws.readyState === 1) { try { ws.send(raw); } catch {} } }
1203
1206
  }
1207
+ /**
1208
+ * The shell commands of the brain's tool calls (an OpenCode brain: assistant-brains/opencode.js `shells`) are a
1209
+ * view as well: which command belongs to which call, whether it runs, how it ended. A change goes to the open
1210
+ * sockets, the whole list to a socket when it attaches and to all of them when the brain is gone (an empty one).
1211
+ * Never buffered, replayed, journaled or shown to the packet observers, and what a command printed is in none
1212
+ * of it: a panel reads that in pages (shellOutput), so nothing of it reaches the model, the transcript, a memory
1213
+ * or a meter.
1214
+ */
1215
+ function brainShells(live) {
1216
+ try { const list = live.brain?.shells?.(); return Array.isArray(list) ? list : []; } catch { return []; }
1217
+ }
1218
+ function sendShell(live, shell) {
1219
+ if (!shell?.id) return;
1220
+ const raw = JSON.stringify({ type: 'assistant:shell', sessionId: live.record.id, shell });
1221
+ for (const ws of live.sockets) { if (ws.readyState === 1) { try { ws.send(raw); } catch {} } }
1222
+ }
1223
+ function sendShells(live, sockets = live.sockets) {
1224
+ const raw = JSON.stringify({ type: 'assistant:shells', sessionId: live.record.id, shells: redactTerminalSecrets(brainShells(live)) });
1225
+ for (const ws of sockets) { if (ws.readyState === 1) { try { ws.send(raw); } catch {} } }
1226
+ }
1227
+ /** The session's shell commands as its brain knows them now; null for an unknown session. */
1228
+ function shellList(sessionId) {
1229
+ const live = sessions.get(String(sessionId || ''));
1230
+ return live ? redactTerminalSecrets(brainShells(live)) : null;
1231
+ }
1232
+ /**
1233
+ * A page of what one of the session's commands printed, for the owner's panel (GET
1234
+ * /api/assistant/sessions/:id/shells/:shellId/output). The session's own brain reads it, and only for a command
1235
+ * it ran: another conversation's command is not readable through this one. What comes back is scrubbed of
1236
+ * SynaBun's run secrets like everything a brain says. → { status, data } or { ok: false, status, error }.
1237
+ */
1238
+ async function shellOutput(sessionId, { shellId, cursor, tail, limit } = {}) {
1239
+ const live = sessions.get(String(sessionId || ''));
1240
+ if (!live) return { ok: false, status: 404, code: 'SESSION_NOT_FOUND', error: `Unknown assistant session ${sessionId}` };
1241
+ const brain = live.brain;
1242
+ if (typeof brain?.shellOutput !== 'function') return { ok: false, status: 404, code: 'SHELL_OUTPUT_GONE', error: 'The output of that command is no longer available.' };
1243
+ // Scrubbed on the whole window around the page (opencode-shell-read.js readSafeShellOutputPage): matched on the
1244
+ // complete read plus what lies on both sides first, cut after, so a secret at a page boundary, or one followed by
1245
+ // what looks like the start of another, never leaves in pieces. Every read the brain does is a raw page.
1246
+ const running = brainShells(live).some((shell) => shell.id === shellId && shell.status === 'running');
1247
+ const page = await readSafeShellOutputPage((q) => brain.shellOutput({ shellId, cursor: q.cursor, limit: q.limit }), { cursor, tail, limit, running });
1248
+ if (!page || page.ok === false || !(Number(page.status) < 400)) {
1249
+ return { ok: false, status: Number(page?.status) >= 400 ? Number(page.status) : 502, code: Number(page?.status) === 404 ? 'SHELL_OUTPUT_GONE' : 'SHELL_OUTPUT_FAILED', error: page?.error || 'The output could not be read.' };
1250
+ }
1251
+ return { status: 200, data: page.data };
1252
+ }
1204
1253
  /** `next`: a limitNotice() value. True when the session's notice changed (and the sockets heard). */
1205
1254
  function setLimit(live, next, { remember = true } = {}) {
1206
1255
  if (next === undefined) return false;
@@ -1409,6 +1458,10 @@ export function createAssistantRuntime({
1409
1458
  // launch credential or a worker's terminal token an agent printed (lib/terminal-token-redaction.js).
1410
1459
  packet = redactTerminalSecrets(packet);
1411
1460
  const id = live.record.id;
1461
+ // A shell command of the brain's tool call changed (OpenCode): a view for the panels that are open, nothing else.
1462
+ if (packet.type === 'assistant:shell') { sendShell(live, packet.shell); return; }
1463
+ // The brain's list was replaced (another provider conversation): every open panel gets the list it has now.
1464
+ if (packet.type === 'assistant:shells') { sendShells(live); return; }
1412
1465
  if (packet.type === 'event') {
1413
1466
  const event = packet.event || {};
1414
1467
  // The usage limit comes with every response: the session keeps its state and says so when
@@ -1522,6 +1575,8 @@ export function createAssistantRuntime({
1522
1575
  else settleClaudeEstimate(live, 'interrupted');
1523
1576
  }
1524
1577
  live.running = false;
1578
+ // A new turn counts its own failed Stops (stopTurn: "Stop anyway" from the second one on).
1579
+ live.stopFailures = 0;
1525
1580
  // A remote session's computer use ends with its turn (the approval and the live grant); a
1526
1581
  // prompt the CLI still holds starts its own turn, unapproved.
1527
1582
  endComputerTurn(live, packet.type === 'aborted' ? 'stopped' : 'turn_ended');
@@ -1767,6 +1822,8 @@ export function createAssistantRuntime({
1767
1822
  // Pending background work re-arms this timer through the `done` of the turn
1768
1823
  // the CLI starts when that work reports back.
1769
1824
  if (live.sockets.size || sessionBusy(live) || live.brain?.hasPendingWork?.()) return;
1825
+ // A model choice waits for the user with no time limit: disposing this brain would close its card.
1826
+ if ((router?.pendingCards?.(live.record.id) || []).some((card) => BRAIN_CARD_ORIGINS.includes(card?.request?.origin))) { scheduleDispose(live); return; }
1770
1827
  disposeBrain(live, 'idle').catch(() => {});
1771
1828
  }, settings.idleDisposeMs);
1772
1829
  live.disposeTimer.unref?.();
@@ -2318,6 +2375,8 @@ export function createAssistantRuntime({
2318
2375
  live.pendingControls.clear();
2319
2376
  clearControlTimers(live);
2320
2377
  try { await brain.dispose?.(); } catch (error) { log('assistant:brain-dispose-error', error?.message || String(error)); }
2378
+ // Its commands ended with its serve: the open panels stop following them (the next brain has none yet).
2379
+ if (!live.brain) sendShells(live);
2321
2380
  // The next brain reports its own routing reach, and its own OpenCode serve says hello again.
2322
2381
  live.gatePluginAt = null;
2323
2382
  live.gate?.setUnavailable(null);
@@ -2330,7 +2389,8 @@ export function createAssistantRuntime({
2330
2389
  live.brainComputerMode = null;
2331
2390
  // A "do it here" continuation goes with its brain; the plan's turn does not (it starts the next brain).
2332
2391
  dropWork(live, 'continuation');
2333
- try { router?.cancelForSession?.(live.record.id, reason === 'closed' ? 'session_closed' : 'brain_disposed', { origins: ['agent_route', 'vision_guard'] }); } catch {}
2392
+ // Closing the session ends every card, a held dispatch's too: cards have no deadline, so nothing else would release its run.
2393
+ try { router?.cancelForSession?.(live.record.id, reason === 'closed' ? 'session_closed' : 'brain_disposed', reason === 'closed' ? {} : { origins: BRAIN_CARD_ORIGINS }); } catch {}
2334
2394
  // Clarify cards outlive a brain (the answers reach the next one as a mailbox turn), not the session.
2335
2395
  if (reason === 'closed') { try { clarifier?.cancelForSession?.(live.record.id, 'session_closed'); } catch {} }
2336
2396
  live.record.status = reason === 'closed' ? 'ended' : 'idle';
@@ -2803,17 +2863,17 @@ export function createAssistantRuntime({
2803
2863
  // at once when the session is free;
2804
2864
  // everything else waits `mailboxDebounceMs` (150 ms at most) so results that arrive together go in one turn;
2805
2865
  // while the brain is busy everything waits in the store, low-priority progress folded, and goes when it is free.
2806
- function mailboxCount(live, options) {
2807
- try { return coordination.mailbox.count(live.record.id, options); } catch { return 0; }
2866
+ function mailboxCount(live) {
2867
+ try { return coordination.mailbox.cachedCount(live.record.id); } catch { return 0; }
2808
2868
  }
2809
2869
  /** A look at what a session has open (the `live.mailbox` view): nothing is handed out or acknowledged. */
2810
- function mailboxPeek(sessionId) {
2811
- try { return coordination.mailbox.pending(sessionId, { limit: 1000, peek: true }).items; } catch { return []; }
2870
+ async function mailboxPeek(sessionId) {
2871
+ try { return (await coordination.mailbox.pending(sessionId, { limit: 1000, peek: true })).items; } catch { return []; }
2812
2872
  }
2813
2873
  /** Something the brain must hear that is not a run's own event (a memory reminder, a route's or a clarify card's outcome). */
2814
- function enqueueMailbox(live, item) {
2815
- try { coordination.mailbox.post(live.record.id, item); }
2816
- catch (error) { log('assistant:mailbox-error', `${live.record.id}: ${error?.message || error}`); }
2874
+ async function enqueueMailbox(live, item) {
2875
+ try { await coordination.mailbox.post(live.record.id, item); return true; }
2876
+ catch (error) { log('assistant:mailbox-error', `${live.record.id}: ${error?.message || error}`); return false; }
2817
2877
  // The store's wake-up (onMailboxEvent) schedules the delivery.
2818
2878
  }
2819
2879
  /** An event was addressed to this session (the store's wake-up, after its append committed). */
@@ -2869,8 +2929,8 @@ export function createAssistantRuntime({
2869
2929
  return !!mark && Number(mark.turn) >= turn;
2870
2930
  }
2871
2931
  /** Events the brain read by itself meanwhile are settled without a turn. → how many. */
2872
- function settleRead(live) {
2873
- try { return coordination.mailbox.discard(live.record.id, (item) => alreadyRead(item)); } catch { return 0; }
2932
+ async function settleRead(live) {
2933
+ try { return await coordination.mailbox.discard(live.record.id, (item) => alreadyRead(item)); } catch { return 0; }
2874
2934
  }
2875
2935
  /**
2876
2936
  * Out of money: the events wait (a raise or No limit re-schedules them), said once. The brain's
@@ -2898,7 +2958,8 @@ export function createAssistantRuntime({
2898
2958
  return false;
2899
2959
  }
2900
2960
  /** The mailbox now, if the scheduler would start it (no debounce: it is asked for). */
2901
- function deliverMailbox(live) {
2961
+ async function deliverMailbox(live) {
2962
+ if (!await coordination.mailbox.count(live.record.id)) return null;
2902
2963
  if (shuttingDown || live.closing || !mailboxCount(live) || sessions.get(live.record.id) !== live || live.record.status === 'ended') return Promise.resolve(null);
2903
2964
  if (sessionBusy(live) || live.planCard || nextWork(live) || !mailboxAllowed(live)) { pumpSoon(live); return Promise.resolve(null); }
2904
2965
  return startWork(live, { kind: 'mailbox', gen: null });
@@ -2907,9 +2968,9 @@ export function createAssistantRuntime({
2907
2968
  async function runMailboxTurn(live) {
2908
2969
  // Read while it waited (inside the debounce, or while the brain was busy with the turn that waited for it):
2909
2970
  // not news any more.
2910
- settleRead(live);
2971
+ await settleRead(live);
2911
2972
  let batch = null;
2912
- try { batch = coordination.mailbox.pending(live.record.id, { limit: settings.mailboxItems }); }
2973
+ try { batch = await coordination.mailbox.pending(live.record.id, { limit: settings.mailboxItems }); }
2913
2974
  catch (error) { log('assistant:mailbox-error', `${live.record.id}: ${error?.message || error}`); return null; }
2914
2975
  let unread = batch.items;
2915
2976
  let more = batch.more;
@@ -2949,7 +3010,7 @@ export function createAssistantRuntime({
2949
3010
  if (result?.ok) {
2950
3011
  // The turn that carries them was started: only now are they acknowledged. A turn that was refused, failed
2951
3012
  // or found the brain busy leaves every one of them open, also across a restart.
2952
- try { coordination.mailbox.ack(live.record.id, items.map((item) => item.eventId).filter(Boolean)); }
3013
+ try { await coordination.mailbox.ack(live.record.id, items.map((item) => item.eventId).filter(Boolean)); }
2953
3014
  catch (error) { log('assistant:mailbox-error', `${live.record.id}: ${error?.message || error}`); }
2954
3015
  live.mailboxAttempts = 0;
2955
3016
  return result;
@@ -2960,12 +3021,12 @@ export function createAssistantRuntime({
2960
3021
  if (result?.code !== 'ASSISTANT_BUSY' && result?.code !== 'TURN_CANCELLED') holdMailbox(live, result);
2961
3022
  return result;
2962
3023
  }
2963
- function onDispatchEvent(payload) {
3024
+ async function onDispatchEvent(payload) {
2964
3025
  const run = payload?.run;
2965
3026
  if (!run?.assistantSessionId) return;
2966
3027
  const live = sessions.get(run.assistantSessionId);
2967
3028
  // A session that is gone hears nothing: what was addressed to it is settled, so it does not wait in the store for good.
2968
- if (!live) { dropMailbox(run.assistantSessionId); return; }
3029
+ if (!live) { await dropMailbox(run.assistantSessionId); return; }
2969
3030
  // The conversation's thread record: its runs, their outcomes and follow-ups.
2970
3031
  try { userContext?.onDispatch(live.record, payload); } catch {}
2971
3032
  if (!live.record.dispatchRunIds?.includes(run.runId)) { live.record.dispatchRunIds = [...(live.record.dispatchRunIds || []), run.runId].slice(-100); touch(live); }
@@ -2979,14 +3040,14 @@ export function createAssistantRuntime({
2979
3040
  // Agents P2: the event is in the coordination log. The dispatcher appended it in the step that changed the run;
2980
3041
  // recording it here again stores nothing (same id), and is what a dispatcher without the service relies on.
2981
3042
  // Which reasons reach the brain, and how urgently, is the service's rule. The store's wake-up schedules the turn.
2982
- const recorded = coordination.recordDispatch(payload);
3043
+ const recorded = await coordination.recordDispatch(payload);
2983
3044
  // Already read by the brain (agent_wait in the same turn that dispatched it): no second turn. Only this event is
2984
3045
  // looked at here; the whole mailbox is gone through once, when a turn is composed.
2985
3046
  if (recorded?.delivered && alreadyRead({ kind: payload.reason === 'turn_completed' ? 'result' : payload.reason, turn: payload.turn, run })) {
2986
- try { coordination.mailbox.ack(live.record.id, [recorded.id]); } catch {}
3047
+ try { await coordination.mailbox.ack(live.record.id, [recorded.id]); } catch {}
2987
3048
  }
2988
3049
  }
2989
- function onRunRemoved(payload) {
3050
+ async function onRunRemoved(payload) {
2990
3051
  const live = payload?.assistantSessionId ? sessions.get(payload.assistantSessionId) : null;
2991
3052
  if (!live) return;
2992
3053
  const removed = new Set((payload.runIds || []).map(String));
@@ -2998,7 +3059,7 @@ export function createAssistantRuntime({
2998
3059
  }
2999
3060
  // A result can be waiting in the mailbox while the user clears its run.
3000
3061
  // Do not let that stale result (or its memory reminder) start another turn.
3001
- try { coordination.mailbox.discard(live.record.id, (item) => removed.has(String(item?.run?.runId || item?.runId || ''))); } catch {}
3062
+ try { await coordination.mailbox.discard(live.record.id, (item) => removed.has(String(item?.run?.runId || item?.runId || ''))); } catch {}
3002
3063
  if (!mailboxCount(live) && live.mailboxTimer) {
3003
3064
  clearTimeout(live.mailboxTimer);
3004
3065
  live.mailboxTimer = null;
@@ -3008,32 +3069,32 @@ export function createAssistantRuntime({
3008
3069
  * Everything open for a session that no longer exists is settled (nobody will ever read it). Never while the
3009
3070
  * sessions index could not be read: a session this start does not know yet may be there after the next one.
3010
3071
  */
3011
- function dropMailbox(sessionId) {
3072
+ async function dropMailbox(sessionId) {
3012
3073
  if (!indexReady) return;
3013
- try { if (coordination.mailbox.count(sessionId)) coordination.mailbox.discard(sessionId, null); } catch {}
3074
+ try { if (await coordination.mailbox.count(sessionId)) await coordination.mailbox.discard(sessionId, null); } catch {}
3014
3075
  }
3015
3076
  /**
3016
3077
  * After a restart: what a session's brain was not told before the server went down is still open in the store,
3017
3078
  * and is delivered now. A session that was removed gets nothing; one that is closed waits until it is opened again.
3018
3079
  */
3019
- function resumeMailboxes() {
3080
+ async function resumeMailboxes() {
3020
3081
  if (shuttingDown) return;
3021
3082
  let open = [];
3022
- try { open = coordination.mailbox.sessions(); } catch { open = []; }
3083
+ try { open = await coordination.mailbox.sessions(); } catch { open = []; }
3023
3084
  for (const { sessionId } of open) {
3024
3085
  const live = sessions.get(sessionId);
3025
- if (!live) { dropMailbox(sessionId); continue; }
3086
+ if (!live) { await dropMailbox(sessionId); continue; }
3026
3087
  if (live.record.status === 'ended') continue;
3027
3088
  scheduleMailbox(live, 0);
3028
3089
  }
3029
3090
  }
3030
- function onPermissionBroadcast(message) {
3091
+ async function onPermissionBroadcast(message) {
3031
3092
  const live = message?.assistantSessionId ? sessions.get(message.assistantSessionId) : null;
3032
3093
  if (!live) return;
3033
3094
  if (message.type === 'assistant:permission-request') {
3034
3095
  sendToSockets(live, { type: 'event', event: { type: 'synabun.dispatch_control_request', runId: message.runId, request_id: message.request?.requestId, provider: dispatcher?.get?.(message.runId)?.provider || null, request: message.request } });
3035
3096
  } else if (message.type === 'assistant:permission-resolved') {
3036
- try { coordination.mailbox.discard(live.record.id, (item) => item.run?.runId === message.runId && item.request?.requestId === message.requestId); } catch {}
3097
+ try { await coordination.mailbox.discard(live.record.id, (item) => item.run?.runId === message.runId && item.request?.requestId === message.requestId); } catch {}
3037
3098
  sendToSockets(live, { type: 'event', event: { type: 'synabun.dispatch_control_resolved', runId: message.runId, request_id: message.requestId, resolvedBy: message.resolvedBy, behavior: message.behavior } });
3038
3099
  }
3039
3100
  }
@@ -3330,7 +3391,7 @@ export function createAssistantRuntime({
3330
3391
  sessions.delete(id);
3331
3392
  if (live.mailboxTimer) { clearTimeout(live.mailboxTimer); live.mailboxTimer = null; }
3332
3393
  if (live.mailboxRetryTimer) { clearTimeout(live.mailboxRetryTimer); live.mailboxRetryTimer = null; }
3333
- dropMailbox(id);
3394
+ await dropMailbox(id);
3334
3395
  const usageTimer = usageTimers.get(id);
3335
3396
  if (usageTimer) clearTimeout(usageTimer);
3336
3397
  usageTimers.delete(id);
@@ -3454,17 +3515,42 @@ export function createAssistantRuntime({
3454
3515
  * included), and closes the plan card (late answers are refused), which
3455
3516
  * releases its hold: the mailbox goes on. The in-turn route cards close.
3456
3517
  */
3457
- async function stopTurn(id, { origin = 'api' } = {}) {
3518
+ async function stopTurn(id, { origin = 'api', force: forced = false, forceAfterFailures = 0 } = {}) {
3458
3519
  const live = sessions.get(String(id || ''));
3459
3520
  if (!live) return { ok: false, code: 'SESSION_NOT_FOUND', message: `Unknown assistant session ${id}` };
3460
- newGeneration(live, 'stopped');
3461
- // A remote session: computer use stops with the turn, before the brain is even asked to (its
3462
- // approval, its open request, the live grant; an action in progress is aborted).
3463
- endComputerTurn(live, 'stopped');
3464
- try { router?.cancelForSession?.(live.record.id, 'aborted', { origins: ['agent_route', 'vision_guard'] }); } catch {}
3465
- if (origin !== 'ui') log('assistant:stop', `${live.record.id}: turn stopped from ${origin}`);
3466
- try { await live.brain?.abort?.(); } catch (error) { return { ok: false, code: 'STOP_FAILED', message: error?.message || String(error) }; }
3467
- return { ok: true };
3521
+ // `forceAfterFailures` (WhatsApp's /stop, which has no "Stop anyway" button): this Stop is a Stop anyway once
3522
+ // that many Stops of THIS turn failed (live.stopFailures is reset when a turn ends), never because of an earlier turn.
3523
+ const force = forced === true || (Number(forceAfterFailures) > 0 && (live.stopFailures || 0) >= Number(forceAfterFailures));
3524
+ // A Stop the brain may fail (an OpenCode command in the background to end) tears the turn down only once it
3525
+ // worked: a failed one leaves the turn, its queue and its cards as they were (the command still runs).
3526
+ const mayFail = !force && live.brain?.stopMayFail?.() === true;
3527
+ const tearDown = () => {
3528
+ newGeneration(live, 'stopped');
3529
+ // A remote session: computer use stops with the turn, before the brain is even asked to (its
3530
+ // approval, its open request, the live grant; an action in progress is aborted).
3531
+ endComputerTurn(live, 'stopped');
3532
+ try { router?.cancelForSession?.(live.record.id, 'aborted', { origins: BRAIN_CARD_ORIGINS }); } catch {}
3533
+ };
3534
+ if (!mayFail) tearDown();
3535
+ if (origin !== 'ui') log('assistant:stop', `${live.record.id}: turn stopped from ${origin}${force ? ' (stop anyway)' : ''}`);
3536
+ let stopped = null;
3537
+ try { stopped = await live.brain?.abort?.(force ? { force: true } : undefined); } catch (error) {
3538
+ const message = error?.message || String(error);
3539
+ if (error?.code !== 'SHELL_STOP_FAILED') return { ok: false, code: 'STOP_FAILED', message };
3540
+ // The turn goes on: every panel of the session hears which command still runs and why, and from the second
3541
+ // failure of this turn on it offers "Stop anyway" (abort with `force`).
3542
+ const failures = (live.stopFailures || 0) + 1;
3543
+ live.stopFailures = failures;
3544
+ const shells = Array.isArray(error.shells) ? error.shells.map((shell) => ({ id: String(shell?.id || ''), command: String(shell?.command || ''), reason: String(shell?.reason || '') })) : [];
3545
+ const packet = { type: 'stop_failed', code: 'SHELL_STOP_FAILED', message, shells, failures, canForce: failures >= 2 };
3546
+ sendToSockets(live, packet);
3547
+ return { ok: false, code: 'STOP_FAILED', message, shells, failures, canForce: failures >= 2 };
3548
+ }
3549
+ if (mayFail) tearDown();
3550
+ live.stopFailures = 0;
3551
+ const abandoned = Array.isArray(stopped?.abandoned) ? stopped.abandoned.map((shell) => ({ id: String(shell?.id || ''), command: String(shell?.command || '') })) : [];
3552
+ if (abandoned.length) sendToSockets(live, { type: 'stop_abandoned', shells: abandoned });
3553
+ return { ok: true, ...(abandoned.length ? { abandoned } : {}) };
3468
3554
  }
3469
3555
  function controlResolved(live, requestId, origin) {
3470
3556
  sendToSockets(live, { type: 'control_resolved', request_id: requestId, origin: String(origin || 'ui') });
@@ -3649,6 +3735,8 @@ export function createAssistantRuntime({
3649
3735
  try { const budgetNow = sessionMoney(live.record.id); if (budgetNow) ws.send(JSON.stringify({ type: 'assistant:budget', sessionId: live.record.id, reason: 'attached', budget: budgetNow })); } catch {}
3650
3736
  // The limit notice as it is now (null clears one this panel still shows from before).
3651
3737
  sendLimit(live, [ws]);
3738
+ // The shell commands of the brain's tool calls as they are now (an empty list ends what this panel still follows).
3739
+ sendShells(live, [ws]);
3652
3740
  const replay = live.buffer.splice(0, live.buffer.length);
3653
3741
  try { ws.send(JSON.stringify({ type: 'reattach_result', ok: true, sessionId: live.record.id, running: live.running, replayed: replay.length })); } catch {}
3654
3742
  for (const packet of replay) { try { ws.send(JSON.stringify(packet)); } catch {} }
@@ -3701,7 +3789,8 @@ export function createAssistantRuntime({
3701
3789
  return;
3702
3790
  }
3703
3791
  case 'abort':
3704
- await stopTurn(live.record.id, { origin: 'ui' });
3792
+ // `force`: the panel's "Stop anyway", offered after a second Stop that could not end a command.
3793
+ await stopTurn(live.record.id, { origin: 'ui', force: msg.force === true });
3705
3794
  return;
3706
3795
  case 'set_route_mode':
3707
3796
  applyRouteMode(live, msg.mode);
@@ -3885,7 +3974,7 @@ export function createAssistantRuntime({
3885
3974
  }
3886
3975
  if (phase !== 'card' && phase !== 'pending' && phase !== 'auto') publishPendingRoutes(live);
3887
3976
  }
3888
- function routerMailbox(id, item) { const live = sessions.get(id); if (live && item) enqueueMailbox(live, item); }
3977
+ function routerMailbox(id, item) { const live = sessions.get(id); if (live && item) return enqueueMailbox(live, item); }
3889
3978
  /** agent_route answered (or failed) for this session: the route gate follows it (`meta.taskClass`: a chat route holds). */
3890
3979
  function routerRouted(id, result, meta = {}) { const live = sessions.get(id); if (live) ensureGate(live)?.onRouteResult(result, meta); }
3891
3980
  function routerRouteFailed(id, error) {
@@ -4389,7 +4478,7 @@ export function createAssistantRuntime({
4389
4478
  metered('flush', () => usage?.flush?.());
4390
4479
  // A coordination service this runtime made for itself goes with it (a shared one is closed by its owner).
4391
4480
  // What a brain was not told stays open in the store and is delivered by the next start.
4392
- if (ownsCoordination) coordination.close();
4481
+ if (ownsCoordination) await coordination.close();
4393
4482
  }
4394
4483
 
4395
4484
  loadIndex();
@@ -4399,8 +4488,8 @@ export function createAssistantRuntime({
4399
4488
  }
4400
4489
  if (dispatcher?.subscribe) {
4401
4490
  unsubscribeDispatcher = dispatcher.subscribe((payload) => {
4402
- if (payload?.type === 'assistant:dispatch') onDispatchEvent(payload);
4403
- else if (payload?.type === 'assistant:run-removed') onRunRemoved(payload);
4491
+ if (payload?.type === 'assistant:dispatch') return onDispatchEvent(payload);
4492
+ else if (payload?.type === 'assistant:run-removed') return onRunRemoved(payload);
4404
4493
  });
4405
4494
  }
4406
4495
  // Agents P2: the store wakes the mailbox of the session an event was addressed to (after its append committed).
@@ -4434,6 +4523,8 @@ export function createAssistantRuntime({
4434
4523
  clarifySession, clarifyEvent, clarifyGate, clarifySinks,
4435
4524
  getComputerUse, getComputerTurn, supersedeComputerApproval, abortTurn, notifySession,
4436
4525
  brainSpend, brainSpendByProvider, budgetSession, onBudgetChanged, onBudgetSplit, sendBudget, currentTask, usageView,
4526
+ // The shell commands of a session's OpenCode brain and a page of what one printed (the panel's terminal blocks).
4527
+ shellList, shellOutput,
4437
4528
  // Programmatic surface (the WhatsApp bridge) and remote sessions.
4438
4529
  observe, submit, stopTurn, answerControl, answerDispatchControl, pendingControls, isBusy, sessionPolicy, sessionChannel,
4439
4530
  // whatsapp_send_file's caller identity (POST /api/assistant/whatsapp/send-file).
@@ -0,0 +1,158 @@
1
+ // ═══════════════════════════════════════════
2
+ // BACKUP CONTENTS — the owner's choice of what a backup holds, and how big it is
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // Settings → Backups → What to back up. One choice for every backup this server makes on request or on schedule
6
+ // (the download into a folder, the browser download, the scheduled backup, Back up now), kept in
7
+ // DATA_HOME/data/backup-selection.json as { version, groups: { id: boolean } }. A group nothing was said about has
8
+ // its default (backup-groups.js): everything that cannot be made again is on, caches and working folders are off.
9
+ //
10
+ // The sizes next to the switches are measured on a worker thread (backup-service.js measureBackupContents: names and
11
+ // sizes, no file opened), never in a request: a request only reads the last measurement and, when it is missing, old
12
+ // or asked for again, starts one. The page asks again while `estimate.state` is `measuring`.
13
+ //
14
+ // createBackupContentsService({ configPath, measure, … }) the choice and the measurement
15
+ // backupContentsHandlers(service) GET and PUT /api/system/backup/contents
16
+ // ═══════════════════════════════════════════
17
+
18
+ import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
19
+ import { dirname } from 'node:path';
20
+ import { BACKUP_GROUPS, BACKUP_GROUP_IDS, irreplaceableLeftOut, normalizeBackupSelection, selectedBackupGroups } from './backup-groups.js';
21
+
22
+ export const BACKUP_ESTIMATE_TTL_MS = 5 * 60_000;
23
+
24
+ const emptySize = () => ({ files: 0, bytes: 0, archiveBytes: 0 });
25
+
26
+ /**
27
+ * @param {object} o
28
+ * @param {string} o.configPath where the choice is kept
29
+ * @param {() => Promise<{ groups: object, never: object }>} o.measure one measurement (a worker thread)
30
+ * @param {number} [o.ttlMs] how long a measurement is shown before a new one is made
31
+ * @param {() => number} [o.now]
32
+ * @param {(line: string) => void} [o.log]
33
+ */
34
+ export function createBackupContentsService({ configPath, measure, ttlMs = BACKUP_ESTIMATE_TTL_MS, now = Date.now, log = () => {} } = {}) {
35
+ if (!configPath || typeof measure !== 'function') throw new Error('configPath and measure are required');
36
+ let measured = null; // { at, groups, never }
37
+ let measuring = null; // the measurement under way
38
+ let failure = null; // the last one's error, until one succeeds
39
+
40
+ function selection() {
41
+ try { return normalizeBackupSelection(JSON.parse(readFileSync(configPath, 'utf-8'))?.groups); }
42
+ catch { return normalizeBackupSelection(null); }
43
+ }
44
+
45
+ /** The ids a backup made now would hold. */
46
+ const groups = () => selectedBackupGroups(selection());
47
+
48
+ function save(value) {
49
+ mkdirSync(dirname(configPath), { recursive: true });
50
+ const temp = `${configPath}.${process.pid}.tmp`;
51
+ try {
52
+ writeFileSync(temp, `${JSON.stringify({ version: 1, groups: value }, null, 2)}\n`, 'utf-8');
53
+ renameSync(temp, configPath);
54
+ } catch (error) {
55
+ try { if (existsSync(temp)) unlinkSync(temp); } catch { /* nothing to remove */ }
56
+ throw error;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Switch groups on or off: `patch` is { id: boolean } for the groups that change. Refused (status 400): anything
62
+ * but booleans for known groups, and a choice that leaves nothing to back up.
63
+ */
64
+ function setSelection(patch) {
65
+ if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
66
+ throw Object.assign(new Error('Say which groups to switch: { groups: { id: true | false } }.'), { status: 400, code: 'SELECTION_INVALID' });
67
+ }
68
+ const next = selection();
69
+ for (const [id, value] of Object.entries(patch)) {
70
+ if (!BACKUP_GROUP_IDS.includes(id)) throw Object.assign(new Error(`There is no backup group "${String(id).slice(0, 40)}".`), { status: 400, code: 'GROUP_UNKNOWN' });
71
+ if (typeof value !== 'boolean') throw Object.assign(new Error(`"${id}" is switched with true or false.`), { status: 400, code: 'SELECTION_INVALID' });
72
+ next[id] = value;
73
+ }
74
+ if (!selectedBackupGroups(next).length) {
75
+ throw Object.assign(new Error('A backup needs at least one group switched on.'), { status: 400, code: 'NOTHING_SELECTED' });
76
+ }
77
+ save(next);
78
+ return next;
79
+ }
80
+
81
+ /** Start a measurement unless one is running; the one under way otherwise. Never throws, never rejects. */
82
+ function measureNow() {
83
+ if (measuring) return measuring;
84
+ measuring = Promise.resolve()
85
+ .then(() => measure())
86
+ .then((result) => {
87
+ const sizes = {};
88
+ for (const id of BACKUP_GROUP_IDS) {
89
+ const got = result?.groups?.[id] || {};
90
+ sizes[id] = { files: Number(got.files) || 0, bytes: Number(got.bytes) || 0, archiveBytes: Number(got.archiveBytes) || 0 };
91
+ }
92
+ measured = { at: now(), groups: sizes, never: { files: Number(result?.never?.files) || 0, bytes: Number(result?.never?.bytes) || 0 } };
93
+ failure = null;
94
+ }, (error) => {
95
+ failure = error?.message || String(error);
96
+ log(`[backup] The size of the backup groups could not be measured: ${failure}`);
97
+ })
98
+ .finally(() => { measuring = null; });
99
+ return measuring;
100
+ }
101
+
102
+ /**
103
+ * What the page shows. Reads the last measurement and starts a new one when there is none, when it is older than
104
+ * `ttlMs`, or when `refresh` asks; the answer never waits for it.
105
+ */
106
+ function snapshot({ refresh = false } = {}) {
107
+ const chosen = selection();
108
+ if (refresh || !measured || now() - measured.at >= ttlMs) measureNow();
109
+ const selected = emptySize();
110
+ const everything = emptySize();
111
+ const rows = BACKUP_GROUPS.map((group) => {
112
+ const size = measured ? measured.groups[group.id] : null;
113
+ if (size) {
114
+ for (const key of ['files', 'bytes', 'archiveBytes']) {
115
+ everything[key] += size[key];
116
+ if (chosen[group.id]) selected[key] += size[key];
117
+ }
118
+ }
119
+ return { id: group.id, kind: group.kind, default: group.default, enabled: chosen[group.id], ...(size || { files: null, bytes: null, archiveBytes: null }) };
120
+ });
121
+ return {
122
+ ok: true,
123
+ groups: rows,
124
+ totals: measured ? { selected, everything } : null,
125
+ never: measured ? measured.never : null,
126
+ irreplaceableOff: irreplaceableLeftOut(chosen),
127
+ estimate: {
128
+ state: measuring ? 'measuring' : measured ? 'ready' : failure ? 'failed' : 'none',
129
+ measuredAt: measured ? new Date(measured.at).toISOString() : null,
130
+ error: failure,
131
+ },
132
+ };
133
+ }
134
+
135
+ return {
136
+ selection, groups, setSelection, snapshot,
137
+ /** Settles when the measurement under way ended (tests, shutdown). */
138
+ idle: () => (measuring || Promise.resolve()),
139
+ /** The data changed in a way a measurement cannot know (a restore): the next reading measures again. */
140
+ invalidate: () => { measured = null; },
141
+ };
142
+ }
143
+
144
+ /**
145
+ * GET (the state; `?refresh=1` measures again) and PUT ({ groups: { id: boolean } }) of /api/system/backup/contents.
146
+ * @param {ReturnType<typeof createBackupContentsService>} service
147
+ */
148
+ export function backupContentsHandlers(service) {
149
+ const refuse = (res, error) => res.status(Number(error?.status) || 500).json({ ok: false, error: error?.message || String(error), code: error?.code || null });
150
+ return {
151
+ status(req, res) {
152
+ try { res.json(service.snapshot({ refresh: req.query?.refresh === '1' })); } catch (error) { refuse(res, error); }
153
+ },
154
+ update(req, res) {
155
+ try { service.setSelection(req.body?.groups); res.json(service.snapshot()); } catch (error) { refuse(res, error); }
156
+ },
157
+ };
158
+ }