synabun 2.4.0 → 2.4.2

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 (319) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +73 -11
  4. package/browser-extension/engine.js +196 -15
  5. package/browser-extension/manifest.json +4 -2
  6. package/browser-extension/popup-strings.js +10 -4
  7. package/browser-extension/popup-view.js +1 -1
  8. package/browser-extension/popup.css +1 -0
  9. package/browser-extension/popup.html +4 -1
  10. package/browser-extension/popup.js +22 -10
  11. package/browser-extension/protocol.js +102 -11
  12. package/browser-extension/service-worker.js +20 -4
  13. package/browser-extension/tokens.css +1 -1
  14. package/docs/browser-extension-bridge.md +25 -5
  15. package/lib/data-home-files.js +47 -0
  16. package/lib/data-home-migration.js +34 -58
  17. package/lib/first-launch-protection.js +8 -2
  18. package/lib/update-snapshot.js +11 -4
  19. package/mcp-server/dist/http.d.ts.map +1 -1
  20. package/mcp-server/dist/http.js +25 -2
  21. package/mcp-server/dist/http.js.map +1 -1
  22. package/mcp-server/dist/index.d.ts.map +1 -1
  23. package/mcp-server/dist/index.js +62 -17
  24. package/mcp-server/dist/index.js.map +1 -1
  25. package/mcp-server/dist/services/browser-bench.d.ts +22 -22
  26. package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
  27. package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
  28. package/mcp-server/dist/services/memory-maintenance.js +34 -45
  29. package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
  30. package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
  31. package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
  32. package/mcp-server/dist/services/memory-migration-copy.js +467 -0
  33. package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
  34. package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
  35. package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
  36. package/mcp-server/dist/services/memory-migration-worker.js +60 -0
  37. package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
  38. package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
  39. package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
  40. package/mcp-server/dist/services/memory-retrieval.js +188 -40
  41. package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
  42. package/mcp-server/dist/services/memory-schema.d.ts +58 -2
  43. package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
  44. package/mcp-server/dist/services/memory-schema.js +190 -13
  45. package/mcp-server/dist/services/memory-schema.js.map +1 -1
  46. package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
  47. package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
  48. package/mcp-server/dist/services/memory-sessions.js +56 -20
  49. package/mcp-server/dist/services/memory-sessions.js.map +1 -1
  50. package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
  51. package/mcp-server/dist/services/memory-verification.js +8 -5
  52. package/mcp-server/dist/services/memory-verification.js.map +1 -1
  53. package/mcp-server/dist/services/neural-interface.d.ts +6 -0
  54. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  55. package/mcp-server/dist/services/neural-interface.js +19 -2
  56. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  57. package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
  58. package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
  59. package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
  60. package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
  61. package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
  62. package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
  63. package/mcp-server/dist/services/retrieval-reader.js +145 -0
  64. package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
  65. package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
  66. package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
  67. package/mcp-server/dist/services/sqlite-write.js +94 -0
  68. package/mcp-server/dist/services/sqlite-write.js.map +1 -0
  69. package/mcp-server/dist/services/sqlite.d.ts +39 -0
  70. package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
  71. package/mcp-server/dist/services/sqlite.js +249 -8
  72. package/mcp-server/dist/services/sqlite.js.map +1 -1
  73. package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
  74. package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
  75. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  76. package/mcp-server/dist/services/typesafe-config.js +32 -10
  77. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  78. package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
  79. package/mcp-server/dist/services/typesafe.js +9 -7
  80. package/mcp-server/dist/services/typesafe.js.map +1 -1
  81. package/mcp-server/dist/services/vector-cache.d.ts +32 -0
  82. package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
  83. package/mcp-server/dist/services/vector-cache.js +161 -8
  84. package/mcp-server/dist/services/vector-cache.js.map +1 -1
  85. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  86. package/mcp-server/dist/tools/agents.d.ts +13 -8
  87. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  88. package/mcp-server/dist/tools/agents.js +35 -15
  89. package/mcp-server/dist/tools/agents.js.map +1 -1
  90. package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
  91. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  92. package/mcp-server/dist/tools/browser-advanced.js +10 -3
  93. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  94. package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
  95. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
  96. package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
  97. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
  98. package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
  99. package/mcp-server/dist/tools/browser-interact.js +6 -1
  100. package/mcp-server/dist/tools/browser-interact.js.map +1 -1
  101. package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
  102. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  103. package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
  104. package/mcp-server/package-lock.json +2 -2
  105. package/mcp-server/package.json +1 -1
  106. package/mcp-server/src/http.ts +20 -2
  107. package/mcp-server/src/index.ts +59 -17
  108. package/mcp-server/src/services/memory-maintenance.ts +31 -28
  109. package/mcp-server/src/services/memory-migration-copy.ts +419 -0
  110. package/mcp-server/src/services/memory-migration-worker.ts +55 -0
  111. package/mcp-server/src/services/memory-retrieval.ts +173 -32
  112. package/mcp-server/src/services/memory-schema.ts +194 -12
  113. package/mcp-server/src/services/memory-sessions.ts +54 -21
  114. package/mcp-server/src/services/memory-verification.ts +7 -4
  115. package/mcp-server/src/services/neural-interface.ts +23 -2
  116. package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
  117. package/mcp-server/src/services/retrieval-reader.ts +131 -0
  118. package/mcp-server/src/services/sqlite-write.ts +60 -0
  119. package/mcp-server/src/services/sqlite.ts +246 -8
  120. package/mcp-server/src/services/typesafe-config.ts +25 -6
  121. package/mcp-server/src/services/typesafe.ts +9 -7
  122. package/mcp-server/src/services/vector-cache.ts +154 -9
  123. package/mcp-server/src/tools/agents.ts +33 -14
  124. package/mcp-server/src/tools/browser-advanced.ts +10 -3
  125. package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
  126. package/mcp-server/src/tools/browser-interact.ts +5 -1
  127. package/neural-interface/i18n/en.json +266 -2
  128. package/neural-interface/i18n/pt-BR.json +267 -3
  129. package/neural-interface/lib/agents/builtins.json +207 -0
  130. package/neural-interface/lib/agents/registry.js +60 -15
  131. package/neural-interface/lib/agents/resolve.js +69 -10
  132. package/neural-interface/lib/agents/split.js +32 -4
  133. package/neural-interface/lib/assistant-api.js +19 -8
  134. package/neural-interface/lib/assistant-brains/claude.js +2 -0
  135. package/neural-interface/lib/assistant-brains/opencode.js +60 -11
  136. package/neural-interface/lib/assistant-catalog.js +2 -2
  137. package/neural-interface/lib/assistant-config.js +0 -7
  138. package/neural-interface/lib/assistant-dispatch.js +384 -119
  139. package/neural-interface/lib/assistant-persona.js +17 -5
  140. package/neural-interface/lib/assistant-pricing.js +65 -14
  141. package/neural-interface/lib/assistant-router.js +181 -54
  142. package/neural-interface/lib/assistant-run-wait.js +45 -28
  143. package/neural-interface/lib/assistant-runtime.js +48 -34
  144. package/neural-interface/lib/backup-contents.js +158 -0
  145. package/neural-interface/lib/backup-crypto-io.js +330 -0
  146. package/neural-interface/lib/backup-crypto-worker.js +130 -0
  147. package/neural-interface/lib/backup-crypto.js +525 -0
  148. package/neural-interface/lib/backup-download.js +268 -0
  149. package/neural-interface/lib/backup-encryption.js +318 -0
  150. package/neural-interface/lib/backup-groups.js +287 -0
  151. package/neural-interface/lib/backup-restore-session.js +176 -0
  152. package/neural-interface/lib/backup-restore-stage.js +60 -0
  153. package/neural-interface/lib/backup-service.js +836 -322
  154. package/neural-interface/lib/backup-zip-reader.js +30 -18
  155. package/neural-interface/lib/backup-zip-writer.js +34 -10
  156. package/neural-interface/lib/browser-extension-adapter.js +109 -24
  157. package/neural-interface/lib/browser-extension-bridge.js +42 -8
  158. package/neural-interface/lib/claude-agent-bridge.js +1 -0
  159. package/neural-interface/lib/claude-session-cleanup.js +5 -1
  160. package/neural-interface/lib/cli-update-planner.js +105 -6
  161. package/neural-interface/lib/client-diagnostics.js +42 -0
  162. package/neural-interface/lib/confined-fs.js +7 -2
  163. package/neural-interface/lib/coordination/README.md +8 -2
  164. package/neural-interface/lib/coordination/contract.js +161 -0
  165. package/neural-interface/lib/coordination/database.js +999 -0
  166. package/neural-interface/lib/coordination/operations.js +436 -0
  167. package/neural-interface/lib/coordination/service.js +68 -537
  168. package/neural-interface/lib/coordination/storage-worker.js +101 -0
  169. package/neural-interface/lib/coordination/store.js +219 -1111
  170. package/neural-interface/lib/db.js +70 -32
  171. package/neural-interface/lib/health-count.js +37 -0
  172. package/neural-interface/lib/loop-stall.js +139 -0
  173. package/neural-interface/lib/maritaca/client.js +2 -2
  174. package/neural-interface/lib/maritaca/models.js +12 -17
  175. package/neural-interface/lib/maritaca/opencode.js +4 -2
  176. package/neural-interface/lib/memory-api.js +9 -1
  177. package/neural-interface/lib/memory-session-capture.js +42 -10
  178. package/neural-interface/lib/memory-store-gate.js +313 -0
  179. package/neural-interface/lib/memory-store-migrate.js +65 -0
  180. package/neural-interface/lib/memory-timers.js +7 -7
  181. package/neural-interface/lib/native-loop-providers.js +13 -16
  182. package/neural-interface/lib/native-loop-runtime.js +34 -14
  183. package/neural-interface/lib/opencode-build-preflight.js +30 -8
  184. package/neural-interface/lib/opencode-native-boundary.js +69 -8
  185. package/neural-interface/lib/opencode-provider-view.js +14 -3
  186. package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
  187. package/neural-interface/lib/opencode2-client.js +2 -1
  188. package/neural-interface/lib/peer-identity.js +13 -8
  189. package/neural-interface/lib/recall-impact.js +122 -0
  190. package/neural-interface/lib/scratch-evidence.js +420 -0
  191. package/neural-interface/lib/scratch-process-guard.js +139 -0
  192. package/neural-interface/lib/scratch-references.js +279 -0
  193. package/neural-interface/lib/scratch-retention-core.js +385 -0
  194. package/neural-interface/lib/scratch-retention-worker.js +37 -0
  195. package/neural-interface/lib/scratch-retention.js +151 -0
  196. package/neural-interface/lib/session-cache-builder.js +70 -44
  197. package/neural-interface/lib/session-cache-worker.js +157 -0
  198. package/neural-interface/lib/session-indexer.js +28 -21
  199. package/neural-interface/lib/session-search-index.js +85 -0
  200. package/neural-interface/lib/skills/creation.js +1 -1
  201. package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
  202. package/neural-interface/lib/style-guide/store.js +43 -3
  203. package/neural-interface/lib/system-restore.js +50 -0
  204. package/neural-interface/lib/teams/api.js +15 -6
  205. package/neural-interface/lib/teams/claims.js +67 -31
  206. package/neural-interface/lib/teams/index.js +7 -7
  207. package/neural-interface/lib/teams/integration.js +40 -40
  208. package/neural-interface/lib/teams/landing.js +6 -6
  209. package/neural-interface/lib/teams/recovery.js +24 -23
  210. package/neural-interface/lib/teams/scheduler.js +196 -97
  211. package/neural-interface/lib/teams/schema.js +1 -1
  212. package/neural-interface/lib/teams/state.js +14 -14
  213. package/neural-interface/lib/teams/worktrees.js +27 -27
  214. package/neural-interface/lib/whatsapp/bridge.js +2 -1
  215. package/neural-interface/lib/worker-confinement.js +47 -2
  216. package/neural-interface/lib/worker-mcp-channel.js +2 -0
  217. package/neural-interface/lib/worker-resume.js +5 -0
  218. package/neural-interface/lib/worker-stop.js +86 -0
  219. package/neural-interface/package-lock.json +2 -2
  220. package/neural-interface/package.json +1 -1
  221. package/neural-interface/public/index.html +260 -0
  222. package/neural-interface/public/offline.html +4 -3
  223. package/neural-interface/public/onboarding.html +259 -34
  224. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +2 -2
  225. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +1 -1
  226. package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
  227. package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
  228. package/neural-interface/public/shared/agents/studio/ax-ui.js +2 -2
  229. package/neural-interface/public/shared/agy/agy-options.js +11 -0
  230. package/neural-interface/public/shared/agy/agy-panel.js +29 -10
  231. package/neural-interface/public/shared/agy/agy-styles.js +14 -12
  232. package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
  233. package/neural-interface/public/shared/api.js +3 -2
  234. package/neural-interface/public/shared/assistant/asst-api.js +3 -3
  235. package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
  236. package/neural-interface/public/shared/assistant/asst-control.js +2 -0
  237. package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
  238. package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
  239. package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
  240. package/neural-interface/public/shared/assistant/asst-render.js +106 -38
  241. package/neural-interface/public/shared/assistant/asst-route.js +102 -21
  242. package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
  243. package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
  244. package/neural-interface/public/shared/assistant/asst-state.js +11 -0
  245. package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
  246. package/neural-interface/public/shared/assistant/route-identity.js +2 -1
  247. package/neural-interface/public/shared/cc-dropdown.js +21 -15
  248. package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
  249. package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
  250. package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
  251. package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
  252. package/neural-interface/public/shared/client-diagnostics.js +94 -0
  253. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  254. package/neural-interface/public/shared/cp/cp-styles.js +1 -1
  255. package/neural-interface/public/shared/effort-i18n.js +118 -0
  256. package/neural-interface/public/shared/html-shell.js +4 -51
  257. package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
  258. package/neural-interface/public/shared/memory-store-wait.js +52 -0
  259. package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
  260. package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
  261. package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
  262. package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -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-modelpicker.js +8 -1
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
  269. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
  272. package/neural-interface/public/shared/output-format.js +294 -0
  273. package/neural-interface/public/shared/owner-authority-view.js +4 -10
  274. package/neural-interface/public/shared/page-session.js +1 -1
  275. package/neural-interface/public/shared/provider-icons.js +6 -0
  276. package/neural-interface/public/shared/schedules-view.js +2 -1
  277. package/neural-interface/public/shared/server-presence.js +77 -0
  278. package/neural-interface/public/shared/settings/settings-ai-browser.js +5 -5
  279. package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
  280. package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
  281. package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
  282. package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
  283. package/neural-interface/public/shared/settings/settings-ia.js +1 -1
  284. package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
  285. package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
  286. package/neural-interface/public/shared/start-bridge.js +2 -2
  287. package/neural-interface/public/shared/studio-attention.js +6 -0
  288. package/neural-interface/public/shared/styles.css +354 -438
  289. package/neural-interface/public/shared/transcript-rows.js +28 -3
  290. package/neural-interface/public/shared/tray-auto-close.js +18 -5
  291. package/neural-interface/public/shared/ui-agents.js +1 -2
  292. package/neural-interface/public/shared/ui-automation-studio.js +168 -108
  293. package/neural-interface/public/shared/ui-claude-panel.js +42 -65
  294. package/neural-interface/public/shared/ui-loading.js +185 -25
  295. package/neural-interface/public/shared/ui-native-loop-router.js +59 -20
  296. package/neural-interface/public/shared/ui-navbar.js +2 -1
  297. package/neural-interface/public/shared/ui-output.js +533 -0
  298. package/neural-interface/public/shared/ui-owner-authority.js +48 -25
  299. package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
  300. package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
  301. package/neural-interface/public/shared/ui-sessions.js +2 -2
  302. package/neural-interface/public/shared/ui-settings-entry.js +18 -0
  303. package/neural-interface/public/shared/ui-settings.js +234 -67
  304. package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
  305. package/neural-interface/public/shared/ui-sync.js +1 -0
  306. package/neural-interface/public/shared/ui-tooltip.js +16 -0
  307. package/neural-interface/public/shared/ui-tutorial.js +5 -6
  308. package/neural-interface/public/shared/ui-worker-end.js +27 -8
  309. package/neural-interface/public/shared/worker-end.js +9 -4
  310. package/neural-interface/public/sw.js +4 -3
  311. package/neural-interface/public/variant/2d/main.js +5 -0
  312. package/neural-interface/public/variant/3d/app.js +10 -0
  313. package/neural-interface/public/variant/3d/main.js +17 -4
  314. package/neural-interface/scripts/scratch-retention.mjs +20 -0
  315. package/neural-interface/server.js +507 -160
  316. package/npm-shrinkwrap.json +2 -2
  317. package/package.json +2 -1
  318. package/scripts/restore-data-home-from-backup.mjs +175 -8
  319. package/setup.js +18 -4
@@ -16,6 +16,8 @@
16
16
  // PATH, so the update silently does nothing and the badge never clears.
17
17
  // ═══════════════════════════════════════════
18
18
 
19
+ import { semverNewer } from './synabun-version.js';
20
+
19
21
  /**
20
22
  * npm package name per tool key. OpenCode has none: npm's opencode-ai is
21
23
  * OpenCode 1, which SynaBun does not drive, and OpenCode 2 is installed by its
@@ -57,6 +59,67 @@ export const BREW_KINDS = {
57
59
  'opencode': 'formula',
58
60
  };
59
61
 
62
+ /**
63
+ * Where OpenCode 2 publishes its newest version, per install channel (checked
64
+ * 2026-11-21 against OpenCode 2.3.2). It has no npm package SynaBun could ask
65
+ * the registry about under the old name (opencode-ai is OpenCode 1), so without
66
+ * these the update check had nothing to compare an install with.
67
+ * vendor what OpenCode's own installer reads to find the release it
68
+ * downloads (https://opencode.ai/v2/install): JSON with a
69
+ * `version`. The yardstick of every install Homebrew does not own.
70
+ * brewFormula the formula of OpenCode's Homebrew tap as it is published.
71
+ * `brew outdated` only knows the local clone of a tap, which
72
+ * nothing refreshes until the user runs brew themselves (the
73
+ * probe runs with HOMEBREW_NO_AUTO_UPDATE), so a tap install
74
+ * never showed an update. The formula is exactly what
75
+ * `brew upgrade` installs once the tap is refreshed, so it can
76
+ * never run ahead of Homebrew the way npm does for a cask.
77
+ * brewToken the formula that file is (the tap's `opencode` is OpenCode 1).
78
+ */
79
+ export const OPENCODE_UPDATE_SOURCES = Object.freeze({
80
+ vendor: 'https://opencode.ai/update/api/latest/cli/npm',
81
+ brewFormula: 'https://raw.githubusercontent.com/anomalyco/homebrew-tap/HEAD/opencode-v2.rb',
82
+ brewToken: 'opencode-v2',
83
+ });
84
+
85
+ const PLAIN_VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
86
+ const plainVersion = (value) => {
87
+ const text = typeof value === 'string' ? value.trim().replace(/^v(?=\d)/i, '') : '';
88
+ return PLAIN_VERSION_RE.test(text) ? text : null;
89
+ };
90
+
91
+ /** The `version` of OpenCode's update API answer (`{"version":"2.3.2",…}`), or null. */
92
+ export function parseVendorLatest(body) {
93
+ let data = body;
94
+ if (typeof body === 'string') {
95
+ try { data = JSON.parse(body); } catch { return null; }
96
+ }
97
+ if (!data || typeof data !== 'object' || data.active === false) return null;
98
+ return plainVersion(data.version);
99
+ }
100
+
101
+ /** The `version "…"` line of a Homebrew formula file, or null. */
102
+ export function parseFormulaVersion(text) {
103
+ const match = String(text ?? '').match(/^[ \t]*version[ \t]+["']([^"'\s]+)["'][ \t]*$/m);
104
+ return match ? plainVersion(match[1]) : null;
105
+ }
106
+
107
+ /**
108
+ * Where a tool's newest version is read from when it has no npm package:
109
+ * `{ url, channel, read(text) }`, or null (an npm tool, a tool with no such
110
+ * source, a Homebrew install of a formula SynaBun does not know the tap of:
111
+ * `brew outdated` alone speaks for that one).
112
+ */
113
+ export function upstreamVersionSource(toolKey, installSource, brewToken = null) {
114
+ if (toolKey !== 'opencode') return null;
115
+ if (isBrewSource(installSource)) {
116
+ const bare = String(brewToken || '').split('/').pop();
117
+ if (installSource !== 'brew-formula' || bare !== OPENCODE_UPDATE_SOURCES.brewToken) return null;
118
+ return { url: OPENCODE_UPDATE_SOURCES.brewFormula, channel: 'brew-formula', read: parseFormulaVersion };
119
+ }
120
+ return { url: OPENCODE_UPDATE_SOURCES.vendor, channel: 'vendor', read: parseVendorLatest };
121
+ }
122
+
60
123
  /** Tools that can update themselves when they own their own install. */
61
124
  const SELF_UPDATERS = {
62
125
  'claude-code': 'claude update',
@@ -226,9 +289,16 @@ export function quoteCommandPath(file, platform = process.platform) {
226
289
  * very installation the panels use, also when a terminal's PATH does not name
227
290
  * its folder (a Windows server started before the CLI was installed, a folder
228
291
  * found among the known install locations).
292
+ *
293
+ * `refreshBrew` (brewNeedsRefresh): the newer version is in the tap as it is
294
+ * published, and this machine's Homebrew has not heard of it yet. `brew
295
+ * upgrade` refreshes by itself only once in a while (HOMEBREW_AUTO_UPDATE_SECS,
296
+ * a day by default) and would answer "already installed", leaving the badge
297
+ * lit: the command refreshes first.
229
298
  */
230
- export function buildUpdateCommand(toolKey, installSource, { brewToken = null, binPath = null, platform = null } = {}) {
231
- const command = planUpdateCommand(toolKey, installSource, { brewToken, platform });
299
+ export function buildUpdateCommand(toolKey, installSource, { brewToken = null, binPath = null, platform = null, refreshBrew = false } = {}) {
300
+ const planned = planUpdateCommand(toolKey, installSource, { brewToken, platform });
301
+ const command = planned && refreshBrew && isBrewSource(installSource) ? `brew update && ${planned}` : planned;
232
302
  const name = TOOL_COMMANDS[toolKey];
233
303
  if (!command || !binPath || !name) return command;
234
304
  if (command !== name && !command.startsWith(`${name} `)) return command;
@@ -331,22 +401,51 @@ export function parseBrewOutdated(raw) {
331
401
  *
332
402
  * When the brew probe itself failed we fail CLOSED (latest = installed)
333
403
  * rather than falling back to npm, for the same reason.
404
+ *
405
+ * `npmLatest` is the upstream version of an install Homebrew does not own: the
406
+ * npm registry's for Claude Code and Codex, OpenCode's own update API for
407
+ * OpenCode 2 (upstreamVersionSource). `brewUpstream` is the version of the
408
+ * tool's formula as its tap publishes it (OpenCode's tap only): what Homebrew
409
+ * installs once the tap is refreshed, so it counts when it is newer than the
410
+ * install and `brew outdated` has not heard of it yet.
334
411
  */
335
412
  export function resolveLatest({
336
413
  installSource,
337
414
  brewToken = null,
338
415
  brewOutdated = null,
339
416
  npmLatest = null,
417
+ brewUpstream = null,
340
418
  installed = null,
341
419
  } = {}) {
342
420
  if (!isBrewSource(installSource)) return npmLatest;
343
421
  if (!installed) return null;
344
422
  if (!brewOutdated) return installed;
423
+ const hit = brewOutdatedVersion(brewOutdated, brewToken);
424
+ if (hit) return hit;
425
+ return brewUpstream && semverNewer(installed, brewUpstream) ? brewUpstream : installed;
426
+ }
427
+
428
+ function brewOutdatedVersion(brewOutdated, brewToken) {
345
429
  const token = brewToken || null;
346
- const hit = (token && brewOutdated.get(token))
347
- || (token && brewOutdated.get(String(token).split('/').pop()))
348
- || null;
349
- return hit || installed;
430
+ if (!token || !brewOutdated) return null;
431
+ return brewOutdated.get(token) || brewOutdated.get(String(token).split('/').pop()) || null;
432
+ }
433
+
434
+ /**
435
+ * Whether the update of a Homebrew install has to refresh Homebrew first
436
+ * (buildUpdateCommand `refreshBrew`): the tap publishes a newer version than
437
+ * the one installed, and `brew outdated` does not list the tool.
438
+ */
439
+ export function brewNeedsRefresh({
440
+ installSource,
441
+ brewToken = null,
442
+ brewOutdated = null,
443
+ brewUpstream = null,
444
+ installed = null,
445
+ } = {}) {
446
+ if (!isBrewSource(installSource) || !installed || !brewOutdated || !brewUpstream) return false;
447
+ if (brewOutdatedVersion(brewOutdated, brewToken)) return false;
448
+ return semverNewer(installed, brewUpstream);
350
449
  }
351
450
 
352
451
  /**
@@ -0,0 +1,42 @@
1
+ import express from 'express';
2
+ import { DIAGNOSTIC_BATCH, validDiagnosticEntry } from '../public/shared/loading-diagnostic-entry.js';
3
+
4
+ // Leave this stream for its route's small parser behind the request/peer gates.
5
+ // Every other request uses the same application/json match as express.json().
6
+ export function useDefaultJsonParser(req) {
7
+ if (req.method === 'POST' && /^\/api\/client-diagnostics\/?$/i.test(req.path)) return false;
8
+ return req.is('application/json');
9
+ }
10
+
11
+ // Cap chunked bodies and whitespace too. Parser errors can contain the raw body.
12
+ const parse = express.json({ limit: 12 * 1024, inflate: false });
13
+ export function parseClientDiagnostics(req, res, next) {
14
+ if (!req.is('application/json')) return res.sendStatus(415);
15
+ parse(req, res, err => err ? res.sendStatus(err.status || 400) : next());
16
+ }
17
+
18
+ export function createClientDiagnostics({ ownerPage, refuseOwner, log = console.log, now = Date.now }) {
19
+ const pages = new Map();
20
+ let resetAt = 0;
21
+ return (req, res) => {
22
+ // Host has already passed the server's host gate. Compare the scheme and port too.
23
+ if (req.headers.origin !== `${req.protocol}://${req.headers.host}`) return res.sendStatus(403);
24
+ if (!ownerPage(req)) return refuseOwner(req, res, 'Client diagnostics require the owner’s page.');
25
+ const batch = req.body;
26
+ if (!Array.isArray(batch) || !batch.length || batch.length > DIAGNOSTIC_BATCH) return res.sendStatus(400);
27
+ if (!batch.every(entry => validDiagnosticEntry(entry) && entry.pageId === batch[0].pageId)) return res.sendStatus(400);
28
+
29
+ const time = now();
30
+ if (time >= resetAt) { pages.clear(); resetAt = time + 60000; }
31
+ const id = batch[0].pageId;
32
+ const count = pages.get(id) || 0;
33
+ // One page can drain the entire retained trail at once. Bound the accounting
34
+ // itself as well, even if an owner client invents a fresh ID for every request.
35
+ if (count + batch.length > 240 || (!count && pages.size >= 256)) return res.sendStatus(429);
36
+ pages.set(id, count + batch.length);
37
+ for (const { iso, pageId, event, currentBoot, visibility, data } of batch) {
38
+ log(`[client-diag] ${iso} ${pageId} ${event} ${JSON.stringify({ currentBoot, visibility, ...data })}`);
39
+ }
40
+ res.status(204).end();
41
+ };
42
+ }
@@ -76,6 +76,12 @@ function openExisting(real, flags) {
76
76
  * @returns a Buffer, or a string when `encoding` is given
77
77
  */
78
78
  export function readConfinedFile(base, path, { maxBytes = MAX_FILE_BYTES, encoding = null } = {}) {
79
+ const { bytes } = readConfinedFileWithMetadata(base, path, { maxBytes });
80
+ return encoding ? bytes.toString(encoding) : bytes;
81
+ }
82
+
83
+ /** Bytes and modification time from the same verified, open regular file. */
84
+ export function readConfinedFileWithMetadata(base, path, { maxBytes = MAX_FILE_BYTES } = {}) {
79
85
  const real = canonicalInside(base, path);
80
86
  const fd = openExisting(real, constants.O_RDONLY);
81
87
  try {
@@ -89,8 +95,7 @@ export function readConfinedFile(base, path, { maxBytes = MAX_FILE_BYTES, encodi
89
95
  if (n <= 0) break;
90
96
  got += n;
91
97
  }
92
- const data = got === st.size ? buf : buf.subarray(0, got);
93
- return encoding ? data.toString(encoding) : data;
98
+ return { bytes: got === st.size ? buf : buf.subarray(0, got), lastModified: Math.trunc(st.mtimeMs) };
94
99
  } finally { try { closeSync(fd); } catch {} }
95
100
  }
96
101
 
@@ -161,10 +161,15 @@ Project-relative patterns with forward slashes. `*` and `?` match inside one seg
161
161
  One SQLite file in WAL mode (`node:sqlite`, no new dependency), `DATA_HOME/data/coordination.db` by `coordinationDbPath(dataDir)`. Apart from `memory.db` on purpose. A backup includes it without anything being registered: `backup-service.js` takes a consistent snapshot of every `.db` in the data home. A restore therefore brings back the open events and claims of that time. Phase P2 treats them like a restart: the sessions restored with them are told what was open for them, and what is open for a session that no longer exists is settled.
162
162
 
163
163
  ```js
164
- const store = createCoordinationStore({ path, now, newId, busyTimeoutMs, synchronous, log, migrations });
164
+ const store = createCoordinationStore({ path });
165
+ await store.ready;
165
166
  ```
166
167
 
167
- Only `path` is required. Everything is synchronous except `waitFor`. Invalid input throws `CoordinationError` (`code`, `status`).
168
+ A dedicated worker opens and migrates the file. All database methods below return promises. SQLite reads and writes share a FIFO, so even a read submitted immediately after an unawaited write observes its commit if it succeeds. Subscriptions register synchronously. Long polls release the queue after registration. The server keeps committed claim and count projections in memory for the synchronous worker guard and scheduling predicates.
169
+
170
+ The worker retries locked transactions with backoff for up to `busyTimeoutMs` (default 5 seconds). An exhausted request rejects with `SQLITE_BUSY`. Unexpected exit rejects outstanding requests with `WORKER_EXIT` and reopens the disk store. A write that lost its reply may already have committed. Reconcile by stable event or outbox ID before resubmitting. A lost in-memory store stays unavailable.
171
+
172
+ Await `store.close()` after scheduler shutdown. It stops admission and drains accepted requests, closes the WAL connection and answers outstanding waits. At the 8-second default shutdown deadline, it terminates the worker and reports `DRAIN_TIMEOUT`. The schema and existing WAL files are compatible across this change. Custom JavaScript migration callbacks are exercised inside the database engine. The worker uses the versioned steps in `MIGRATIONS`.
168
173
 
169
174
  ### Event schema
170
175
 
@@ -284,6 +289,7 @@ The Assistant's mailbox was a list in the runtime's memory: batched for a fixed
284
289
 
285
290
  ```js
286
291
  const service = createCoordinationService({ dataDir }); // or { path }, or { store }; nothing: in memory
292
+ await service.ready;
287
293
  shareCoordinationService(service); // server.js: the dispatcher and the runtime take it by themselves
288
294
  ```
289
295
 
@@ -0,0 +1,161 @@
1
+ import { join } from 'node:path';
2
+
3
+ export const COORDINATION_SCHEMA_VERSION = 1;
4
+ export const COORDINATION_DB_FILE = 'coordination.db';
5
+ /** Most urgent first. `pending` hands out critical events before everything else. */
6
+ export const EVENT_PRIORITIES = Object.freeze(['critical', 'normal', 'low']);
7
+ export const DEFAULT_EVENT_PRIORITY = 'normal';
8
+
9
+ /**
10
+ * Event kinds the phases agree on, so two modules never name one thing twice. The store takes any kind of the
11
+ * right form; a kind listed here gets its priority from KIND_PRIORITY when an event names none.
12
+ */
13
+ export const EVENT_KINDS = Object.freeze({
14
+ RUN_PROGRESS: 'run.progress', // a worker is still at it (what it is doing now)
15
+ RUN_RESULT: 'run.result', // a worker turn ended with a ## Result
16
+ RUN_NEEDS_INPUT: 'run.needs_input', // a worker asked a question only the user or the brain can answer
17
+ RUN_PERMISSION: 'run.permission', // a worker waits for a permission decision
18
+ RUN_FAILED: 'run.failed', // a run ended without a result
19
+ RUN_STALLED: 'run.stalled', // a run shows no sign of life
20
+ RUN_MESSAGE: 'run.message', // text from one agent to another (payload.text, payload.from)
21
+ RUN_STOPPED: 'run.stopped', // a run was stopped (the user, a budget, a cap); payload.run.completionReason says by what
22
+ RUN_INTERRUPTED: 'run.interrupted', // a server restart ended a run that could not be resumed
23
+ RUN_COMPLETED: 'run.completed', // a run ended after its work was done (its result came as run.result)
24
+ RUN_BUDGET: 'run.budget', // the session budget: a warning, the cap reached, usage that cannot be priced
25
+ RUN_NOTICE: 'run.notice', // something the owner of a run should hear once (the user wrote to the worker)
26
+ SESSION_MEMORY_DUE: 'session.memory_due', // a finished run has no memory yet (the runtime's reminder to its brain)
27
+ ROUTE_DECIDED: 'route.decided', // the user picked a model on a route card
28
+ ROUTE_EXPIRED: 'route.expired', // a route card closed without an answer (cards have no deadline)
29
+ ROUTE_DECLINED: 'route.declined', // the user declined a route card
30
+ CLARIFY_ANSWERED: 'clarify.answered', // the user answered the Assistant's questions
31
+ CLARIFY_DECLINED: 'clarify.declined', // the user skipped them
32
+ TEAM_MESSAGE: 'team.message', // text on a team's channel (payload.text, payload.from)
33
+ TEAM_STATE: 'team.state', // a team moved to another state (lib/teams/schema.js TEAM_STATES)
34
+ SLICE_STATE: 'slice.state', // a slice moved to another state (SLICE_STATES)
35
+ SLICE_PROGRESS: 'slice.progress', // a slice's worker is still at it
36
+ CLAIM_CONFLICT: 'claim.conflict', // a worker needs a file another slice holds
37
+ INTEGRATION_CONFLICT: 'integration.conflict', // joining a slice on the integration branch did not apply cleanly
38
+ INTEGRATION_READY: 'integration.ready', // every slice is joined; the branch waits for the user
39
+ });
40
+ export const KIND_PRIORITY = Object.freeze({
41
+ 'run.progress': 'low', 'slice.progress': 'low',
42
+ 'run.result': 'normal', 'run.message': 'normal', 'team.state': 'normal', 'slice.state': 'normal', 'integration.ready': 'normal',
43
+ 'run.stopped': 'normal', 'run.completed': 'normal', 'run.budget': 'normal', 'run.notice': 'normal',
44
+ 'session.memory_due': 'normal', 'team.message': 'normal',
45
+ // A card's outcome is the user's own act: whoever relayed it (the WhatsApp bridge) finishes its bookkeeping first,
46
+ // so it rides the short debounce of normal events instead of starting a turn inside that call.
47
+ 'route.decided': 'normal', 'route.expired': 'normal', 'route.declined': 'normal', 'clarify.answered': 'normal', 'clarify.declined': 'normal',
48
+ 'run.needs_input': 'critical', 'run.permission': 'critical', 'run.failed': 'critical', 'run.stalled': 'critical',
49
+ 'run.interrupted': 'critical',
50
+ 'claim.conflict': 'critical', 'integration.conflict': 'critical',
51
+ });
52
+
53
+ export const COORDINATION_LIMITS = Object.freeze({
54
+ id: 200, kind: 64, recipient: 200, recipients: 64, payloadBytes: 256 * 1024, readLimit: 1000, defaultReadLimit: 100,
55
+ outboxText: 20000, state: 40, journalDataBytes: 64 * 1024, claimGlobs: 64, runIds: 500,
56
+ defaultWaitMs: 30_000, maxWaitMs: 10 * 60_000,
57
+ });
58
+
59
+ /** The recipient name of an Assistant session, of a run, of a team's integrator: one spelling for every module. */
60
+ export const sessionRecipient = (sessionId) => `session:${sessionId}`;
61
+ export const runRecipient = (runId) => `run:${runId}`;
62
+ export const teamRecipient = (teamId) => `team:${teamId}`;
63
+
64
+ /** Where the store lives under a data folder (DATA_HOME/data). */
65
+ export function coordinationDbPath(dataDir) {
66
+ if (typeof dataDir !== 'string' || !dataDir) throw new CoordinationError('PATH_REQUIRED', 'coordinationDbPath needs the data folder.');
67
+ return join(dataDir, COORDINATION_DB_FILE);
68
+ }
69
+
70
+ export class CoordinationError extends Error {
71
+ /** @param {string} code @param {string} message @param {object} [extra] */
72
+ constructor(code, message, extra = {}) {
73
+ super(message);
74
+ this.name = 'CoordinationError';
75
+ this.code = code;
76
+ this.status = code === 'CLOSED' ? 503 : 400;
77
+ Object.assign(this, extra);
78
+ }
79
+ }
80
+
81
+
82
+ const SCHEMA_V1 = `
83
+ CREATE TABLE events (
84
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
85
+ id TEXT NOT NULL UNIQUE,
86
+ session_id TEXT,
87
+ team_id TEXT,
88
+ run_id TEXT,
89
+ kind TEXT NOT NULL,
90
+ priority TEXT NOT NULL CHECK (priority IN ('critical', 'normal', 'low')),
91
+ payload TEXT NOT NULL DEFAULT 'null',
92
+ coalesce_key TEXT,
93
+ created_at INTEGER NOT NULL
94
+ );
95
+ CREATE INDEX events_team ON events (team_id, seq);
96
+ CREATE INDEX events_session ON events (session_id, seq);
97
+ CREATE INDEX events_run ON events (run_id, seq);
98
+
99
+ CREATE TABLE deliveries (
100
+ recipient TEXT NOT NULL,
101
+ event_id TEXT NOT NULL REFERENCES events (id) ON DELETE CASCADE,
102
+ seq INTEGER NOT NULL,
103
+ delivered_at INTEGER,
104
+ acked_at INTEGER,
105
+ attempts INTEGER NOT NULL DEFAULT 0,
106
+ coalesced_into TEXT,
107
+ merged INTEGER NOT NULL DEFAULT 0,
108
+ PRIMARY KEY (recipient, event_id)
109
+ ) WITHOUT ROWID;
110
+ CREATE INDEX deliveries_seq ON deliveries (recipient, seq);
111
+ CREATE INDEX deliveries_open ON deliveries (recipient, seq) WHERE acked_at IS NULL;
112
+ CREATE INDEX deliveries_event ON deliveries (event_id);
113
+
114
+ CREATE TABLE cursors (
115
+ recipient TEXT PRIMARY KEY,
116
+ seq INTEGER NOT NULL,
117
+ updated_at INTEGER NOT NULL
118
+ ) WITHOUT ROWID;
119
+
120
+ CREATE TABLE claims (
121
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
122
+ team_id TEXT NOT NULL,
123
+ slice_id TEXT NOT NULL,
124
+ glob TEXT NOT NULL,
125
+ run_id TEXT,
126
+ created_at INTEGER NOT NULL,
127
+ released_at INTEGER
128
+ );
129
+ CREATE INDEX claims_team ON claims (team_id, released_at);
130
+ CREATE UNIQUE INDEX claims_one_active ON claims (team_id, slice_id, glob) WHERE released_at IS NULL;
131
+
132
+ CREATE TABLE team_tasks (
133
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
134
+ team_id TEXT NOT NULL,
135
+ slice_id TEXT NOT NULL DEFAULT '',
136
+ state TEXT NOT NULL,
137
+ run_id TEXT,
138
+ data TEXT NOT NULL DEFAULT '{}',
139
+ created_at INTEGER NOT NULL
140
+ );
141
+ CREATE INDEX team_tasks_team ON team_tasks (team_id, slice_id, id);
142
+
143
+ CREATE TABLE outbox (
144
+ n INTEGER PRIMARY KEY AUTOINCREMENT,
145
+ id TEXT NOT NULL UNIQUE,
146
+ run_id TEXT NOT NULL,
147
+ text TEXT NOT NULL,
148
+ session_id TEXT,
149
+ meta TEXT NOT NULL DEFAULT '{}',
150
+ created_at INTEGER NOT NULL,
151
+ sent_at INTEGER,
152
+ attempts INTEGER NOT NULL DEFAULT 0
153
+ );
154
+ CREATE INDEX outbox_run ON outbox (run_id, n);
155
+ CREATE INDEX outbox_unsent ON outbox (run_id, n) WHERE sent_at IS NULL;
156
+ `;
157
+
158
+ /** Every schema change, in order. A new one is appended with the next version; one that shipped is never edited. */
159
+ export const MIGRATIONS = Object.freeze([
160
+ Object.freeze({ version: 1, name: 'events, deliveries, cursors, claims, team_tasks, outbox', up: (db) => db.exec(SCHEMA_V1) }),
161
+ ]);