synabun 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +169 -0
  4. package/browser-extension/engine.js +477 -0
  5. package/browser-extension/icons/icon-128.png +0 -0
  6. package/browser-extension/icons/icon-16.png +0 -0
  7. package/browser-extension/icons/icon-32.png +0 -0
  8. package/browser-extension/icons/icon-48.png +0 -0
  9. package/browser-extension/icons/status-off-16.png +0 -0
  10. package/browser-extension/icons/status-off-32.png +0 -0
  11. package/browser-extension/icons/status-off-48.png +0 -0
  12. package/browser-extension/icons/status-on-16.png +0 -0
  13. package/browser-extension/icons/status-on-32.png +0 -0
  14. package/browser-extension/icons/status-on-48.png +0 -0
  15. package/browser-extension/manifest.json +56 -0
  16. package/browser-extension/popup-strings.js +244 -0
  17. package/browser-extension/popup-view.js +151 -0
  18. package/browser-extension/popup.css +165 -0
  19. package/browser-extension/popup.html +105 -0
  20. package/browser-extension/popup.js +347 -0
  21. package/browser-extension/protocol.js +226 -0
  22. package/browser-extension/service-worker.js +267 -0
  23. package/browser-extension/setup-content.js +36 -0
  24. package/browser-extension/tokens.css +326 -0
  25. package/docs/browser-extension-bridge.md +84 -0
  26. package/docs/whatsapp.md +1 -1
  27. package/mcp-server/dist/http.d.ts +2 -0
  28. package/mcp-server/dist/http.d.ts.map +1 -1
  29. package/mcp-server/dist/http.js +9 -1
  30. package/mcp-server/dist/http.js.map +1 -1
  31. package/mcp-server/dist/index.d.ts +11 -0
  32. package/mcp-server/dist/index.d.ts.map +1 -1
  33. package/mcp-server/dist/index.js +38 -3
  34. package/mcp-server/dist/index.js.map +1 -1
  35. package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
  36. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
  37. package/mcp-server/dist/services/browser-route-flow.js +10 -3
  38. package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
  39. package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
  40. package/mcp-server/dist/services/codex-config-heal.js +7 -0
  41. package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
  42. package/mcp-server/dist/services/neural-interface.d.ts +94 -3
  43. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.js +168 -23
  45. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  46. package/mcp-server/dist/services/team-context.d.ts +18 -0
  47. package/mcp-server/dist/services/team-context.d.ts.map +1 -0
  48. package/mcp-server/dist/services/team-context.js +29 -0
  49. package/mcp-server/dist/services/team-context.js.map +1 -0
  50. package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
  51. package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
  52. package/mcp-server/dist/services/tool-catalog.js +22 -6
  53. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  54. package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
  55. package/mcp-server/dist/services/tool-list.js +4 -0
  56. package/mcp-server/dist/services/tool-list.js.map +1 -1
  57. package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
  58. package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
  59. package/mcp-server/dist/services/tool-runtime.js +18 -1
  60. package/mcp-server/dist/services/tool-runtime.js.map +1 -1
  61. package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
  62. package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
  63. package/mcp-server/dist/tools/agent-definition.js +483 -0
  64. package/mcp-server/dist/tools/agent-definition.js.map +1 -0
  65. package/mcp-server/dist/tools/agents.d.ts +91 -9
  66. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  67. package/mcp-server/dist/tools/agents.js +161 -20
  68. package/mcp-server/dist/tools/agents.js.map +1 -1
  69. package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
  70. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  71. package/mcp-server/dist/tools/browser-advanced.js +70 -6
  72. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  73. package/mcp-server/dist/tools/git-tools.d.ts +4 -2
  74. package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
  75. package/mcp-server/dist/tools/git-tools.js +283 -2
  76. package/mcp-server/dist/tools/git-tools.js.map +1 -1
  77. package/mcp-server/dist/tools/morelogin.d.ts +8 -2
  78. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  79. package/mcp-server/dist/tools/morelogin.js +22 -5
  80. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  81. package/mcp-server/dist/tools/team.d.ts +32 -0
  82. package/mcp-server/dist/tools/team.d.ts.map +1 -0
  83. package/mcp-server/dist/tools/team.js +87 -0
  84. package/mcp-server/dist/tools/team.js.map +1 -0
  85. package/mcp-server/package-lock.json +2 -2
  86. package/mcp-server/package.json +1 -1
  87. package/mcp-server/src/http.ts +9 -1
  88. package/mcp-server/src/index.ts +34 -4
  89. package/mcp-server/src/services/browser-route-flow.ts +12 -5
  90. package/mcp-server/src/services/codex-config-heal.ts +7 -0
  91. package/mcp-server/src/services/neural-interface.ts +190 -29
  92. package/mcp-server/src/services/team-context.ts +27 -0
  93. package/mcp-server/src/services/tool-catalog.ts +26 -8
  94. package/mcp-server/src/services/tool-list.ts +4 -0
  95. package/mcp-server/src/services/tool-runtime.ts +21 -2
  96. package/mcp-server/src/tools/agent-definition.ts +458 -0
  97. package/mcp-server/src/tools/agents.ts +175 -19
  98. package/mcp-server/src/tools/browser-advanced.ts +60 -6
  99. package/mcp-server/src/tools/git-tools.ts +249 -3
  100. package/mcp-server/src/tools/morelogin.ts +20 -5
  101. package/mcp-server/src/tools/team.ts +97 -0
  102. package/neural-interface/i18n/en.json +1117 -47
  103. package/neural-interface/i18n/pt-BR.json +1117 -47
  104. package/neural-interface/lib/account-usage.js +1 -1
  105. package/neural-interface/lib/agents/density.js +101 -0
  106. package/neural-interface/lib/agents/forge-host.js +223 -0
  107. package/neural-interface/lib/agents/native-export-targets.js +190 -0
  108. package/neural-interface/lib/agents/native-export.js +365 -0
  109. package/neural-interface/lib/agents/registry.js +840 -0
  110. package/neural-interface/lib/agents/resolve.js +544 -0
  111. package/neural-interface/lib/agents/schema.js +642 -0
  112. package/neural-interface/lib/agents/split.js +37 -0
  113. package/neural-interface/lib/agents-studio-api.js +591 -0
  114. package/neural-interface/lib/assistant-api.js +76 -7
  115. package/neural-interface/lib/assistant-catalog.js +2 -0
  116. package/neural-interface/lib/assistant-continuity.js +49 -0
  117. package/neural-interface/lib/assistant-dispatch.js +229 -102
  118. package/neural-interface/lib/assistant-persona.js +105 -8
  119. package/neural-interface/lib/assistant-route-gate.js +24 -9
  120. package/neural-interface/lib/assistant-router.js +384 -42
  121. package/neural-interface/lib/assistant-run-tail.js +151 -0
  122. package/neural-interface/lib/assistant-run-wait.js +183 -0
  123. package/neural-interface/lib/assistant-runtime.js +440 -93
  124. package/neural-interface/lib/assistant-task-prompt.js +11 -2
  125. package/neural-interface/lib/assistant-usage.js +3 -2
  126. package/neural-interface/lib/automation-approval.js +2 -2
  127. package/neural-interface/lib/browser-close-evidence.js +80 -0
  128. package/neural-interface/lib/browser-default.js +210 -0
  129. package/neural-interface/lib/browser-extension-adapter.js +255 -0
  130. package/neural-interface/lib/browser-extension-bridge.js +418 -0
  131. package/neural-interface/lib/browser-extension-folder.js +116 -0
  132. package/neural-interface/lib/browser-extension-setup.js +140 -0
  133. package/neural-interface/lib/browser-profile-choices.js +3 -3
  134. package/neural-interface/lib/browser-tool-policy.js +1 -1
  135. package/neural-interface/lib/claude-account-links.js +301 -0
  136. package/neural-interface/lib/claude-accounts.js +45 -20
  137. package/neural-interface/lib/claude-agent-bridge.js +142 -10
  138. package/neural-interface/lib/claude-model-catalog.js +6 -0
  139. package/neural-interface/lib/claude-panel-session.js +33 -0
  140. package/neural-interface/lib/codex-accounts.js +67 -24
  141. package/neural-interface/lib/coordination/README.md +384 -0
  142. package/neural-interface/lib/coordination/service.js +563 -0
  143. package/neural-interface/lib/coordination/store.js +1138 -0
  144. package/neural-interface/lib/db.js +22 -1
  145. package/neural-interface/lib/effort-levels.js +10 -1
  146. package/neural-interface/lib/memory-list-page.js +49 -0
  147. package/neural-interface/lib/memory-list-stamp.js +60 -0
  148. package/neural-interface/lib/morelogin-outside-close.js +186 -0
  149. package/neural-interface/lib/morelogin-profile-failures.js +206 -0
  150. package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
  151. package/neural-interface/lib/morelogin.js +194 -8
  152. package/neural-interface/lib/native-loop-runtime.js +20 -0
  153. package/neural-interface/lib/opencode-build-preflight.js +16 -1
  154. package/neural-interface/lib/opencode-native-boundary.js +83 -13
  155. package/neural-interface/lib/opencode-serve-records.js +14 -9
  156. package/neural-interface/lib/page-session.js +1 -1
  157. package/neural-interface/lib/peer-identity.js +60 -21
  158. package/neural-interface/lib/process-identity.js +68 -7
  159. package/neural-interface/lib/request-gate.js +3 -0
  160. package/neural-interface/lib/screenshot-location.js +33 -0
  161. package/neural-interface/lib/skills/creation.js +1 -1
  162. package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
  163. package/neural-interface/lib/studio-attention.js +56 -0
  164. package/neural-interface/lib/teams/README.md +382 -0
  165. package/neural-interface/lib/teams/api.js +287 -0
  166. package/neural-interface/lib/teams/brief.js +185 -0
  167. package/neural-interface/lib/teams/claims.js +315 -0
  168. package/neural-interface/lib/teams/git.js +293 -0
  169. package/neural-interface/lib/teams/index.js +122 -0
  170. package/neural-interface/lib/teams/integration.js +580 -0
  171. package/neural-interface/lib/teams/landing.js +184 -0
  172. package/neural-interface/lib/teams/recovery.js +256 -0
  173. package/neural-interface/lib/teams/scheduler.js +1474 -0
  174. package/neural-interface/lib/teams/schema.js +559 -0
  175. package/neural-interface/lib/teams/state.js +181 -0
  176. package/neural-interface/lib/teams/test-runner.js +86 -0
  177. package/neural-interface/lib/teams/test-sandbox.js +99 -0
  178. package/neural-interface/lib/teams/worktrees.js +757 -0
  179. package/neural-interface/lib/tool-permission-choices.js +226 -0
  180. package/neural-interface/lib/whatsapp/cards.js +24 -10
  181. package/neural-interface/lib/worker-confinement.js +206 -6
  182. package/neural-interface/package-lock.json +2 -2
  183. package/neural-interface/package.json +1 -1
  184. package/neural-interface/public/extension-setup.html +107 -0
  185. package/neural-interface/public/index.html +52 -12
  186. package/neural-interface/public/shared/agent-runtime-options.js +3 -1
  187. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
  188. package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
  189. package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
  190. package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
  191. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
  192. package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
  193. package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
  194. package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
  195. package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
  196. package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
  197. package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
  198. package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
  199. package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
  200. package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
  201. package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
  202. package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
  203. package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
  204. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
  205. package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
  206. package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
  207. package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
  208. package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
  209. package/neural-interface/public/shared/agy/agy-panel.js +142 -28
  210. package/neural-interface/public/shared/agy/agy-styles.js +25 -5
  211. package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
  212. package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
  213. package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
  214. package/neural-interface/public/shared/assistant/asst-control.js +3 -0
  215. package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
  216. package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
  217. package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
  218. package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
  219. package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
  220. package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
  221. package/neural-interface/public/shared/assistant/asst-render.js +36 -6
  222. package/neural-interface/public/shared/assistant/asst-route.js +78 -12
  223. package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
  224. package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
  225. package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
  226. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
  227. package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
  228. package/neural-interface/public/shared/assistant/asst-state.js +66 -1
  229. package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
  230. package/neural-interface/public/shared/assistant/route-identity.js +16 -0
  231. package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
  232. package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
  233. package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
  234. package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
  235. package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
  236. package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
  237. package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
  238. package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
  239. package/neural-interface/public/shared/code-copy.js +120 -0
  240. package/neural-interface/public/shared/constants.js +7 -0
  241. package/neural-interface/public/shared/context-menu-model.js +1 -0
  242. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  243. package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
  244. package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
  245. package/neural-interface/public/shared/cp/cp-styles.js +9 -0
  246. package/neural-interface/public/shared/dom-change-flag.js +66 -0
  247. package/neural-interface/public/shared/dom-morph.js +124 -0
  248. package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
  249. package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
  250. package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
  251. package/neural-interface/public/shared/html-shell.js +33 -4
  252. package/neural-interface/public/shared/i18n.js +14 -1
  253. package/neural-interface/public/shared/idle-queue.js +78 -0
  254. package/neural-interface/public/shared/iface-config.js +227 -0
  255. package/neural-interface/public/shared/lazy-module.js +108 -0
  256. package/neural-interface/public/shared/memory-list.js +117 -0
  257. package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
  258. package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
  259. package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
  260. package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
  261. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
  262. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
  264. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
  265. package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
  269. package/neural-interface/public/shared/schedules-view.js +2 -2
  270. package/neural-interface/public/shared/session-project-items.js +11 -0
  271. package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
  272. package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
  273. package/neural-interface/public/shared/settings/settings-ia.js +4 -2
  274. package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
  275. package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
  276. package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
  277. package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
  278. package/neural-interface/public/shared/sidepanel-shown.js +73 -0
  279. package/neural-interface/public/shared/storage.js +6 -1
  280. package/neural-interface/public/shared/studio-attention.js +83 -0
  281. package/neural-interface/public/shared/styles.css +682 -50
  282. package/neural-interface/public/shared/term-browser-tabs.js +34 -0
  283. package/neural-interface/public/shared/transcript-rows.js +334 -0
  284. package/neural-interface/public/shared/tray-auto-close.js +106 -0
  285. package/neural-interface/public/shared/ui-agents.js +97 -0
  286. package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
  287. package/neural-interface/public/shared/ui-automation-studio.js +3 -3
  288. package/neural-interface/public/shared/ui-claude-panel.js +162 -95
  289. package/neural-interface/public/shared/ui-code-copy.js +256 -0
  290. package/neural-interface/public/shared/ui-codex-panel.js +14 -10
  291. package/neural-interface/public/shared/ui-context-menu.js +1 -1
  292. package/neural-interface/public/shared/ui-file-explorer.js +2 -3
  293. package/neural-interface/public/shared/ui-games.js +1 -1
  294. package/neural-interface/public/shared/ui-loading.js +12 -1
  295. package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
  296. package/neural-interface/public/shared/ui-menubar.js +23 -0
  297. package/neural-interface/public/shared/ui-native-loop-router.js +1 -1
  298. package/neural-interface/public/shared/ui-navbar.js +15 -9
  299. package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
  300. package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
  301. package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
  302. package/neural-interface/public/shared/ui-sessions.js +3 -3
  303. package/neural-interface/public/shared/ui-settings-entry.js +55 -0
  304. package/neural-interface/public/shared/ui-settings.js +355 -400
  305. package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
  306. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
  307. package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
  308. package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
  309. package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
  310. package/neural-interface/public/shared/ui-styleguide.js +10 -2
  311. package/neural-interface/public/shared/ui-sync.js +5 -0
  312. package/neural-interface/public/shared/ui-terminal.js +13 -9
  313. package/neural-interface/public/shared/ui-tooltip.js +28 -7
  314. package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
  315. package/neural-interface/public/shared/ui-tray-columns.js +375 -0
  316. package/neural-interface/public/shared/ui-whiteboard.js +51 -6
  317. package/neural-interface/public/shared/ui-worker-end.js +28 -1
  318. package/neural-interface/public/shared/ui-workspaces.js +13 -0
  319. package/neural-interface/public/shared/window-keys.js +71 -0
  320. package/neural-interface/public/variant/2d/main.js +2 -0
  321. package/neural-interface/public/variant/3d/app.js +620 -0
  322. package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
  323. package/neural-interface/public/variant/3d/main.js +21 -544
  324. package/neural-interface/public/variant/3d/map-controls.js +4 -2
  325. package/neural-interface/public/vendor/fonts/fonts.css +508 -0
  326. package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
  327. package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
  328. package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
  329. package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
  330. package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
  331. package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
  332. package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
  333. package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
  334. package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
  335. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
  336. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
  337. package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
  338. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  339. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
  340. package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
  341. package/neural-interface/public/vendor/fonts/manifest.json +142 -0
  342. package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
  343. package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
  344. package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
  345. package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
  346. package/neural-interface/scripts/boot-graph.mjs +270 -0
  347. package/neural-interface/scripts/vendor-fonts.mjs +124 -0
  348. package/neural-interface/server.js +1050 -140
  349. package/npm-shrinkwrap.json +2 -2
  350. package/package.json +3 -1
  351. package/skills/agent-forge/SKILL.md +182 -0
  352. package/skills/agent-forge/evals/evals.json +56 -0
  353. package/skills/agent-forge/references/definition-fields.md +61 -0
  354. package/skills/agent-forge/references/examples.md +105 -0
  355. package/skills/agent-forge/references/instructions.md +51 -0
  356. package/skills/agent-forge/references/review-and-export.md +84 -0
@@ -520,7 +520,7 @@ export function getAllMemories({ includeVectors = false, includeTrash = false }
520
520
  related_memory_ids, file_checksums, trashed_at, source_session_chunks
521
521
  ${vectorCol}
522
522
  FROM memories ${where}
523
- ORDER BY created_at DESC
523
+ ORDER BY created_at DESC, id DESC
524
524
  `).all();
525
525
 
526
526
  return rows.map(row => {
@@ -533,6 +533,27 @@ export function getAllMemories({ includeVectors = false, includeTrash = false }
533
533
  });
534
534
  }
535
535
 
536
+ /**
537
+ * One page of the live memories, in the order of getAllMemories() (newest first; equal times by id, so the pages
538
+ * of an unchanged store are the same every time and never overlap), and how many live memories there are.
539
+ * GET /api/memories?links=false&offset=…&limit=… (the page's progressive memory list) reads only its own rows.
540
+ * @param {{ offset?: number, limit: number }} options
541
+ * @returns {{ rows: Array<object>, total: number }}
542
+ */
543
+ export function getMemoriesPage({ offset = 0, limit } = {}) {
544
+ const d = getDb();
545
+ const total = d.prepare('SELECT COUNT(*) AS n FROM memories WHERE trashed_at IS NULL').get().n;
546
+ const rows = d.prepare(`
547
+ SELECT id, content, category, subcategory, project, tags, importance, source,
548
+ created_at, updated_at, accessed_at, access_count, related_files,
549
+ related_memory_ids, file_checksums, trashed_at, source_session_chunks
550
+ FROM memories WHERE trashed_at IS NULL
551
+ ORDER BY created_at DESC, id DESC
552
+ LIMIT ? OFFSET ?
553
+ `).all(limit, offset);
554
+ return { rows: rows.map((row) => ({ id: row.id, ...rowToPayload(row) })), total };
555
+ }
556
+
536
557
  /**
537
558
  * Get all memories with vectors for link computation.
538
559
  */
@@ -81,6 +81,9 @@ export function modelEfforts(row) {
81
81
  */
82
82
  export const EFFORT_OFF = 'none';
83
83
 
84
+ /** A Claude Code row whose CLI said it cannot run with thinking off (`supportsThinkingOff: false` → row.thinkingOff). */
85
+ export function thinkingAlwaysOn(row) { return !!row && (row.thinkingOff === false || row.supportsThinkingOff === false); }
86
+
84
87
  /**
85
88
  * Can this provider/row run with thinking off? Codex and OpenCode only when the
86
89
  * model lists `none`; Claude Code whenever the model thinks at all (the SDK
@@ -88,6 +91,9 @@ export const EFFORT_OFF = 'none';
88
91
  */
89
92
  export function supportsEffortOff(provider, row) {
90
93
  const levels = modelEfforts(row);
94
+ // A model whose CLI says its thinking cannot be turned off (thinkingOff false: Opus 5.5 rejects disabled thinking,
95
+ // and the CLI then sends adaptive thinking at whatever effort its settings give): Off is corrected to the lowest level.
96
+ if (provider === 'claude-code' && thinkingAlwaysOn(row)) return false;
91
97
  if (provider === 'claude-code') return levels ? levels.some((id) => id.toLowerCase() !== EFFORT_OFF) : !!row;
92
98
  if (provider === 'antigravity') return false;
93
99
  return !!levels?.some((id) => id.toLowerCase() === EFFORT_OFF);
@@ -136,7 +142,10 @@ export function normalizeEffort({ provider = null, model = null, effort = null,
136
142
  // Off on a model that can switch its thinking off stays Off (Claude Code lists no `none`: see supportsEffortOff).
137
143
  if (raw.toLowerCase() === EFFORT_OFF && supportsEffortOff(provider, row)) return { effort: EFFORT_OFF, corrected: null };
138
144
  const next = clampEffort(raw, levels, { fallback: row?.defaultEffort || null });
139
- return next === raw ? { effort: raw, corrected: null } : { effort: next, corrected: { from: raw, to: next } };
145
+ if (next === raw) return { effort: raw, corrected: null };
146
+ // Off asked of a model that always thinks: it runs at the lowest level, and the correction says why.
147
+ const alwaysOn = raw.toLowerCase() === EFFORT_OFF && provider === 'claude-code' && thinkingAlwaysOn(row);
148
+ return { effort: next, corrected: { from: raw, to: next, ...(alwaysOn ? { reason: 'thinking_always_on' } : {}) } };
140
149
  }
141
150
 
142
151
  /** The model's levels for a provider/model pair (null when unknown). */
@@ -0,0 +1,49 @@
1
+ // One page of the page's memory list (`GET /api/memories?links=false&offset=…&limit=…`).
2
+ //
3
+ // The 3D page used to fetch every memory in one answer (about 32 MB for 24,000 memories) and parse it in one go. It
4
+ // now asks for pages (public/shared/memory-list.js): the first arrives in a fraction of the time, each parse is a
5
+ // short task, and the server reads only the rows of the page. Without `limit` the route answers as it always did
6
+ // (every memory, the same body and ETag): other callers and a page from before this change are unaffected.
7
+ //
8
+ // A page carries `page.version`, the ETag the whole list would have now: a client that sees two versions across its
9
+ // pages knows the list changed while it read them and starts again. Each page has an ETag of its own (the version
10
+ // plus the page's place), so a reload of an unchanged list is answered `304 Not Modified` page by page.
11
+
12
+ /** The largest page a request may ask for. */
13
+ export const MEMORY_PAGE_MAX = 10_000;
14
+
15
+ /**
16
+ * The page a query asks for: null when it asks for no page (no `limit`), `{ error }` when the numbers are not
17
+ * usable, else `{ offset, limit }` (limit at most MEMORY_PAGE_MAX).
18
+ * @param {Record<string, unknown>} query
19
+ */
20
+ export function parseMemoryPage(query = {}) {
21
+ const rawLimit = query.limit;
22
+ if (rawLimit === undefined || rawLimit === null || rawLimit === '') return null;
23
+ const asInt = (value) => (typeof value === 'string' && /^\d{1,9}$/.test(value) ? Number(value) : NaN);
24
+ const limit = asInt(rawLimit);
25
+ if (!Number.isInteger(limit) || limit < 1) return { error: 'limit must be a whole number of at least 1' };
26
+ const rawOffset = query.offset;
27
+ const offset = rawOffset === undefined || rawOffset === '' ? 0 : asInt(rawOffset);
28
+ if (!Number.isInteger(offset) || offset < 0) return { error: 'offset must be a whole number of at least 0' };
29
+ return { offset, limit: Math.min(limit, MEMORY_PAGE_MAX) };
30
+ }
31
+
32
+ /** The ETag part that tells one page from another of the same list. */
33
+ export function pageEtagPart({ offset, limit }) {
34
+ return `page:${offset}:${limit}`;
35
+ }
36
+
37
+ /**
38
+ * The page's description in the answer. `total` counts the stored memories; the bridge's nodes (if any) ride on the
39
+ * last page, after them, as in the unpaged answer.
40
+ */
41
+ export function describePage({ offset, limit, total, count, version }) {
42
+ const end = offset + limit;
43
+ return { offset, limit, count, total, next: end < total ? end : null, version: version ?? null };
44
+ }
45
+
46
+ /** Whether this page is the last one, the one that carries what follows the stored memories. */
47
+ export function isLastPage({ offset, limit, total }) {
48
+ return offset + limit >= total;
49
+ }
@@ -0,0 +1,60 @@
1
+ // What the page's first memory list (`GET /api/memories?links=false`) depends on, as one short string, and
2
+ // the ETag made from it.
3
+ //
4
+ // The 3D map asks for every memory on every load: about 32 MB of JSON for 24,000 memories. Answering meant
5
+ // reading every row, building every node and serialising all of it, half a second of the server doing
6
+ // nothing else, right when the page also wants its style sheet and four hundred modules; and that was done
7
+ // even when the browser already held the very same answer, because only the finished body said whether it
8
+ // had changed. The stamp says it first, from two small queries: a page that still holds the list gets
9
+ // `304 Not Modified` before a single row is read.
10
+ //
11
+ // The stamp changes whenever the answer would:
12
+ // - `memory_changes` (filled by triggers on the memories table, whoever writes: this server, an MCP server,
13
+ // a hook) has a row for every insert and delete and for every update of a column the list carries, the
14
+ // trash included;
15
+ // - the three columns no trigger watches are read straight from the table: the number of live memories,
16
+ // the sum of access counts and the newest `accessed_at` / `updated_at` (a recall changes those and
17
+ // nothing else).
18
+ // A stamp that cannot be made (an older database, a busy one) is null: the route then answers as it always
19
+ // did.
20
+
21
+ import { createHash } from 'node:crypto';
22
+
23
+ const CHANGE_SEQ = "SELECT COALESCE(MAX(seq), 0) AS seq FROM memory_changes WHERE entity IN ('memories', 'memory_filters')";
24
+ const LIVE_ROWS = "SELECT COUNT(*) AS n, COALESCE(SUM(access_count), 0) AS accesses, COALESCE(MAX(accessed_at), '') AS accessed, "
25
+ + "COALESCE(MAX(updated_at), '') AS updated FROM memories WHERE trashed_at IS NULL";
26
+
27
+ /**
28
+ * The stamp of the live memories in `db` (a node:sqlite database), or null when it cannot be read.
29
+ * @param {{ prepare(sql: string): { get(): any } }} db
30
+ */
31
+ export function memoryListStamp(db) {
32
+ try {
33
+ const { seq } = db.prepare(CHANGE_SEQ).get();
34
+ const row = db.prepare(LIVE_ROWS).get();
35
+ return [seq, row.n, row.accesses, row.accessed, row.updated].join('|');
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * The ETag of a memory list: the stamp plus whatever else shapes the answer (the slim form, the bridge's
43
+ * nodes). Weak: it names what the answer is made from, not its bytes. null when any part is unknown.
44
+ * @param {Array<string | number | boolean | null | undefined>} parts
45
+ */
46
+ export function memoryListEtag(parts) {
47
+ if (!Array.isArray(parts) || !parts.length || parts.some((part) => part === null || part === undefined)) return null;
48
+ return `W/"ml-${createHash('sha1').update(parts.map(String).join('\u0000')).digest('hex').slice(0, 24)}"`;
49
+ }
50
+
51
+ /** Does an `If-None-Match` header name this ETag? Weak comparison (RFC 9110): a `W/` prefix is ignored. */
52
+ export function etagMatches(header, etag) {
53
+ if (!header || !etag) return false;
54
+ const bare = (value) => String(value).trim().replace(/^W\//, '');
55
+ const wanted = bare(etag);
56
+ return String(header).split(',').some((candidate) => {
57
+ const value = candidate.trim();
58
+ return value === '*' || bare(value) === wanted;
59
+ });
60
+ }
@@ -0,0 +1,186 @@
1
+ /**
2
+ * A MoreLogin profile closed outside SynaBun, remembered per profile (2026-11-15, widened the same night).
3
+ *
4
+ * Every start of a profile that is not running spends one of the MoreLogin plan's 20 daily launches
5
+ * (lib/morelogin-start-cooldown.js). When a profile's browser goes away and SynaBun did not close it (server.js: the
6
+ * context's close handler, after lib/browser-close-evidence.js wrote its evidence line), whoever closed it wanted it
7
+ * closed. Before this, SynaBun opened it again at the next browser call: on 2026-11-15 one close of P-1 cost two
8
+ * launches within a minute (loops' recover / create, 21:13:44 and 21:14:34 local), and at 23:01 a close of P-4 that
9
+ * orphaned no loop was undone 26 s later by the same interactive session's next browser_navigate ("a replacement tab
10
+ * … is open"), one more launch.
11
+ *
12
+ * Now the close is remembered for the profile, and NO automatic path starts it again while the mark holds: a browser
13
+ * tool call (browser_navigate, browser_session create, a replacement tab, /api/browser/acquire), a loop's create /
14
+ * recover, a run's morelogin "use" followed by a browser call, a run's or agent's morelogin "start", a script
15
+ * (fetch-deals.mjs): lib/morelogin.js startProfile refuses at once with MORELOGIN_CLOSED_OUTSIDE (409, needsUser),
16
+ * before MoreLogin is asked for a start. Nobody is moved to another profile or browser in its place.
17
+ *
18
+ * What lifts it:
19
+ * - the owner starts it: SynaBun's Start (Settings → Connected tools → MoreLogin, the owner's page; a session the owner's
20
+ * page creates), or the MoreLogin app, after which MoreLogin lists it running with a debug port. Attaching to a
21
+ * running profile is always allowed (it spends nothing) and a successful attach or start clears the mark;
22
+ * - a NEW scheduled run fires (a schedule's or a quick timer's trigger, server.js `schedule:browser`): it may start
23
+ * the profile as usual, subject to the start-limit hold, and its start clears the mark. A recovery or a create of a
24
+ * run already under way is not a firing;
25
+ * - MoreLogin's next daily reset (00:00 UTC after the close): the mark expires there. The reason it exists is the
26
+ * day's launch budget, and a new day has a new budget; a stale mark would otherwise hold a profile shut for good.
27
+ * A new dispatched worker or a new assistant turn does NOT lift it: they are automatic too, and the point is that
28
+ * the person who closed the profile wanted it closed.
29
+ * A close SynaBun made itself (POST /api/morelogin/stop, its own teardown, the OpenCode serve boundary's revocation,
30
+ * which keeps the window: "SynaBun let go of profile") is never recorded here.
31
+ *
32
+ * `owners`: the runs the close orphaned (server.js finishBlockedLoop ends those loops after their turn; the status
33
+ * route counts them). They no longer decide who is held: everybody is.
34
+ *
35
+ * State: in memory and in DATA_HOME/data/morelogin-outside-closes.json (a restart must not forget it), read again
36
+ * whenever the file changed under it (a script in another process sees the server's marks, and the other way round).
37
+ */
38
+ import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
39
+ import { dirname, join } from 'node:path';
40
+ import { getDataHome } from '../../lib/paths.js';
41
+ import { formatLocalTime, nextMoreLoginDayReset } from './morelogin-start-cooldown.js';
42
+
43
+ const MAX_ENTRIES = 200;
44
+ const MAX_OWNERS = 100;
45
+ const MAX_NAME = 120;
46
+
47
+ /** Until when a close at `at` holds: MoreLogin's next daily reset (the first 00:00 UTC after it). */
48
+ export function outsideCloseUntil(at) {
49
+ return nextMoreLoginDayReset(at);
50
+ }
51
+
52
+ /** The file the marks live in (read through getDataHome each time: SYNABUN_DATA_HOME decides, tests use a temp one). */
53
+ export function outsideCloseFile() {
54
+ return join(getDataHome(), 'data', 'morelogin-outside-closes.json');
55
+ }
56
+
57
+ let _entries = null; // envId → { envId, at, until, name, sessionId, owners: string[] }
58
+ let _loadedFrom = null;
59
+ let _loadedStamp = null;
60
+
61
+ function fileStamp(file) {
62
+ try { const s = statSync(file); return `${s.size}:${s.mtimeMs}`; } catch { return 'none'; }
63
+ }
64
+
65
+ const cleanName = (name) => (typeof name === 'string' && name.trim() ? name.trim().replace(/[\u0000-\u001f"]/g, '').slice(0, MAX_NAME) : null);
66
+
67
+ function load() {
68
+ const file = outsideCloseFile();
69
+ const stamp = fileStamp(file);
70
+ if (_entries && _loadedFrom === file && _loadedStamp === stamp) return _entries;
71
+ _entries = new Map();
72
+ _loadedFrom = file;
73
+ _loadedStamp = stamp;
74
+ try {
75
+ const raw = JSON.parse(readFileSync(file, 'utf8'));
76
+ for (const e of Array.isArray(raw?.closes) ? raw.closes : []) {
77
+ const at = Number(e?.at);
78
+ if (!e?.envId || !Number.isFinite(at)) continue;
79
+ // A mark written before the expiry existed (version 1) holds until the reset after its close, like a new one.
80
+ const until = Number.isFinite(Number(e.until)) && Number(e.until) > at ? Number(e.until) : outsideCloseUntil(at);
81
+ const owners = Array.isArray(e.owners) ? e.owners.filter((o) => typeof o === 'string' && o).slice(0, MAX_OWNERS) : [];
82
+ _entries.set(String(e.envId), {
83
+ envId: String(e.envId), at, until, name: cleanName(e.name),
84
+ sessionId: typeof e.sessionId === 'string' ? e.sessionId.slice(0, 128) : null, owners,
85
+ });
86
+ }
87
+ } catch { /* none yet, or unreadable: nothing is blocked */ }
88
+ return _entries;
89
+ }
90
+
91
+ function save() {
92
+ const file = outsideCloseFile();
93
+ try {
94
+ mkdirSync(dirname(file), { recursive: true });
95
+ const tmp = `${file}.${process.pid}.tmp`;
96
+ writeFileSync(tmp, JSON.stringify({ version: 2, closes: [..._entries.values()] }, null, 2) + '\n', { mode: 0o600 });
97
+ renameSync(tmp, file);
98
+ _loadedStamp = fileStamp(file);
99
+ } catch (err) {
100
+ console.warn(`[morelogin] could not save the profiles closed outside SynaBun (${err?.message || err}); they hold in memory until a restart`);
101
+ }
102
+ }
103
+
104
+ function prune(now) {
105
+ let changed = false;
106
+ for (const [id, e] of load()) if (!(now < e.until)) { _entries.delete(id); changed = true; }
107
+ return changed;
108
+ }
109
+
110
+ const copy = (e) => ({ ...e, owners: [...e.owners] });
111
+
112
+ /**
113
+ * Note that `envId` (MoreLogin calls it `name`) was closed outside SynaBun, orphaning the runs `owners`. A second
114
+ * close before the mark is lifted adds its runs to the same mark (the newest time, and its expiry, are kept).
115
+ */
116
+ export function noteOutsideClose(envId, { at = Date.now(), sessionId = null, owners = [], name = null } = {}) {
117
+ if (!envId) return null;
118
+ const entries = load();
119
+ prune(at);
120
+ const id = String(envId);
121
+ const before = entries.get(id);
122
+ const merged = [...new Set([...(before?.owners || []), ...owners.filter((o) => typeof o === 'string' && o)])].slice(-MAX_OWNERS);
123
+ const entry = {
124
+ envId: id, at, until: outsideCloseUntil(at), name: cleanName(name) || before?.name || null,
125
+ sessionId: sessionId ? String(sessionId).slice(0, 128) : null, owners: merged,
126
+ };
127
+ entries.delete(id); // newest last
128
+ entries.set(id, entry);
129
+ while (entries.size > MAX_ENTRIES) entries.delete(entries.keys().next().value);
130
+ save();
131
+ return copy(entry);
132
+ }
133
+
134
+ /**
135
+ * The mark that holds for `envId` now, or null. It holds for every caller (any session, run, agent or script); only
136
+ * the owner's start and a new scheduled firing go past it (lib/morelogin.js startProfile `allowAfterOutsideClose`).
137
+ */
138
+ export function outsideCloseFor(envId, now = Date.now()) {
139
+ if (!envId) return null;
140
+ // Before the widening the second argument was the run's id: a string is never a time.
141
+ if (typeof now !== 'number') now = Date.now();
142
+ const e = load().get(String(envId));
143
+ if (!e) return null;
144
+ if (!(now < e.until)) { _entries.delete(String(envId)); save(); return null; }
145
+ return copy(e);
146
+ }
147
+
148
+ /** Every mark that holds now: [{ envId, name, at, until, closedAt, closedLocal, holdUntil, holdUntilLocal, sessionId, owners }]. */
149
+ export function listOutsideCloses(now = Date.now()) {
150
+ if (prune(now)) save();
151
+ return [...load().values()].map((e) => ({
152
+ ...copy(e),
153
+ closedAt: new Date(e.at).toISOString(), closedLocal: formatLocalTime(e.at),
154
+ holdUntil: new Date(e.until).toISOString(), holdUntilLocal: formatLocalTime(e.until),
155
+ }));
156
+ }
157
+
158
+ /** The profile runs again (attached to, or started by someone allowed to): the mark is over for everybody. */
159
+ export function clearOutsideClose(envId) {
160
+ if (!envId) return false;
161
+ const had = load().delete(String(envId));
162
+ if (had) save();
163
+ return had;
164
+ }
165
+
166
+ /**
167
+ * The refusal of a start of a profile closed outside SynaBun. `label`: how the profile is named (`MoreLogin profile
168
+ * "P-4" (id)`), else the name the mark kept, else its id. Code MORELOGIN_CLOSED_OUTSIDE, status 409, needsUser,
169
+ * closedAt, holdUntil; never retried by SynaBun, never answered with another profile.
170
+ */
171
+ export function outsideCloseError(envId, entry, { label = null } = {}) {
172
+ const name = label || (entry?.name ? `MoreLogin profile "${entry.name}" (${envId})` : `MoreLogin profile ${envId}`);
173
+ const when = entry?.at ? formatLocalTime(entry.at) : 'an earlier moment';
174
+ const until = entry?.until ? ` SynaBun stops holding it at MoreLogin's daily reset (${formatLocalTime(entry.until)}).` : '';
175
+ const e = new Error(`${name} was closed outside SynaBun at ${when}, and SynaBun will not reopen it by itself: whoever closed it may have wanted it closed, and each start spends one of MoreLogin's daily launches. Nothing was started, and nothing was moved to another profile or browser. To go on, start the profile in MoreLogin or in SynaBun (Settings → Connected tools → MoreLogin → Start): browser calls then attach to it without a new launch. Otherwise wait for its next scheduled run, which starts it as usual.${until} This needs the user, not a retry: report it and stop`);
176
+ e.code = 'MORELOGIN_CLOSED_OUTSIDE';
177
+ e.status = 409;
178
+ e.needsUser = true;
179
+ e.envId = String(envId);
180
+ if (entry?.at) e.closedAt = new Date(entry.at).toISOString();
181
+ if (entry?.until) e.holdUntil = new Date(entry.until).toISOString();
182
+ return e;
183
+ }
184
+
185
+ /** Forget what is held in memory: the next call reads the file again (what a new process or a reload sees). */
186
+ export function _reloadOutsideClosesForTests() { _entries = null; _loadedFrom = null; }
@@ -0,0 +1,206 @@
1
+ /**
2
+ * A run's own browser profile failed in that run: the run may not move to another profile (2026-11-15).
3
+ *
4
+ * Every start of a MoreLogin profile that is not running spends one of the plan's 20 daily launches. On 2026-11-15 at
5
+ * 21:13:36 run 8d50b0303fd3aabcdab1eceb52850b90, which had chosen P-4 itself (`morelogin use`, so not pinned), could
6
+ * not connect to P-4 ("Browser context management is not supported": MoreLogin listed P-4 running with no window); at
7
+ * 21:13:43 it called `morelogin use` with P-1 and its next browser call started P-1 (21:13:44, one launch). A pinned
8
+ * run is refused such a move already (PROFILE_PINNED); a run that chose its profile itself was not.
9
+ *
10
+ * Now a failure of the run's own profile (a start or a connection that failed in one of the run's acquisitions:
11
+ * server.js acquireSharedBrowserTab, an automation's POST /api/browser/sessions in the default profile, its own
12
+ * POST /api/morelogin/start of that profile) is noted for the run. While it holds, the run's `morelogin use` of any
13
+ * other profile, or back to the default browser when that is another profile or Chrome (POST /api/morelogin/use, which
14
+ * `browser_session create` with `moreloginProfile` calls too), and its `morelogin start` of another profile are
15
+ * refused with 409 PROFILE_FAILED_NO_SWITCH: which profile failed, when, why, and how to go on. Asking `use` for the
16
+ * failed profile itself is no move and stays allowed, and so does a start of it (that is how it is fixed).
17
+ *
18
+ * The bar lifts when:
19
+ * - the failed profile connects again in this run: an acquisition of the run lands in a session of that profile
20
+ * (the user started or fixed it, in MoreLogin or Settings → Connected tools → MoreLogin → Start, and the run's next
21
+ * browser call attached). A start that only reports success does not lift it: the connection must work;
22
+ * - the run no longer works in that profile because the owner moved it (profileSwitchDecision `lifted`): its
23
+ * effective profile (its pin, else the default AI browser) is not the failed one any more. The run cannot move
24
+ * itself while barred, so any such change is the owner's (a new default in Settings → Connected tools → MoreLogin);
25
+ * - the run ends (server.js forgetRunMoreLoginProfile, with its pin), or the entry is older than
26
+ * PROFILE_FAILURE_MAX_AGE_MS.
27
+ * The owner's own actions are never asked: the owner's page has no session to switch (POST /api/morelogin/use answers it
28
+ * SESSION_REQUIRED), and its Start, Stop and default change go through as before.
29
+ *
30
+ * State: in memory and in DATA_HOME/data/morelogin-profile-failures.json (a restart resumes runs: a barred run must stay
31
+ * barred), like the sessions' profile choices (lib/browser-profile-choices.js). Never throws.
32
+ */
33
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
34
+ import { dirname } from 'node:path';
35
+
36
+ export const PROFILE_FAILED_NO_SWITCH = 'PROFILE_FAILED_NO_SWITCH';
37
+ /** Entries kept at most (the oldest go first). */
38
+ export const PROFILE_FAILURES_MAX = 500;
39
+ /** An entry older than this no longer bars anything (its run has long ended). */
40
+ export const PROFILE_FAILURE_MAX_AGE_MS = 7 * 24 * 60 * 60_000;
41
+
42
+ const OWNER_RE = /^[A-Za-z0-9_:-]{1,128}$/;
43
+ const cleanId = (value) => {
44
+ const id = value === null || value === undefined ? '' : String(value).trim();
45
+ return id && id.length <= 128 && !/[\u0000-\u001f]/.test(id) ? id : '';
46
+ };
47
+ const cleanText = (value, max) => (typeof value === 'string' ? value.replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, max) : '');
48
+
49
+ /** "2026-11-15 21:13:36 (UTC-03:00)": the local time a failure happened, to the second. */
50
+ export function formatFailureTime(ms) {
51
+ const d = new Date(ms);
52
+ const p = (n) => String(n).padStart(2, '0');
53
+ const off = -d.getTimezoneOffset();
54
+ const abs = Math.abs(off);
55
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())} (UTC${off >= 0 ? '+' : '-'}${p(Math.floor(abs / 60))}:${p(abs % 60)})`;
56
+ }
57
+
58
+ /**
59
+ * The reason of a failure as the refusal quotes it: the failure's first sentence (a start error carries its whole
60
+ * advice after it), at most 240 characters, never empty.
61
+ */
62
+ export function failureReasonOf(text) {
63
+ const flat = cleanText(String(text ?? ''), 2000);
64
+ if (!flat) return 'no reason was given';
65
+ const first = flat.split(/(?<=[.!?])\s+(?=[A-Z])/)[0] || flat;
66
+ return first.length > 240 ? `${first.slice(0, 237).trimEnd()}…` : first;
67
+ }
68
+
69
+ /**
70
+ * What a switch of a run with this failure is: `none` (no failure held), `lifted` (the run no longer works in the
71
+ * failed profile: the owner moved it, so the failure is over), `same` (the target is the failed profile itself: no
72
+ * move) or `barred`. `current`: the run's effective profile now (an envId, or null for a browser that is no profile:
73
+ * Chrome, the mirror, the extension); `sameTarget`: whether what it asks for is the failed profile.
74
+ */
75
+ export function profileSwitchDecision({ failure = null, current = null, sameTarget = false } = {}) {
76
+ if (!failure?.envId) return 'none';
77
+ if ((current === null || current === undefined ? null : String(current)) !== String(failure.envId)) return 'lifted';
78
+ return sameTarget === true ? 'same' : 'barred';
79
+ }
80
+
81
+ /**
82
+ * Whether a `use` request's reference ({ envId, name, profile }, as POST /api/morelogin/use takes it) names the failed
83
+ * profile itself: its id, or its name without regard to case. Then it is no move, and the request is resolved and
84
+ * answered as usual; anything else is refused before MoreLogin is asked for its list.
85
+ */
86
+ export function namesFailedProfile(ref, failure) {
87
+ if (!failure?.envId || !ref || typeof ref !== 'object') return false;
88
+ const id = String(failure.envId);
89
+ const name = cleanText(failure.name, 200).toLowerCase();
90
+ const same = (value) => {
91
+ const text = value === null || value === undefined ? '' : cleanText(String(value), 200);
92
+ return !!text && (text === id || (!!name && text.toLowerCase() === name));
93
+ };
94
+ return same(ref.envId) || same(ref.name) || same(ref.profile);
95
+ }
96
+
97
+ /**
98
+ * The refusal of a run's switch after its own profile failed. `label` / `targetLabel`: how the failed profile and the
99
+ * target are named (`MoreLogin profile "P-4" (id)`, `the default browser`); `action`: 'use' (a move) or 'start' (a
100
+ * start of another profile). Code PROFILE_FAILED_NO_SWITCH, status 409, needsUser, with envId, failedAt, failedCode.
101
+ */
102
+ export function profileSwitchBarError(failure, { label = null, targetLabel = null, action = 'use' } = {}) {
103
+ const name = label || `profile ${failure?.envId}`;
104
+ const there = targetLabel || 'another profile';
105
+ const when = Number.isFinite(Number(failure?.at)) ? formatFailureTime(Number(failure.at)) : 'an earlier moment';
106
+ const why = failureReasonOf(failure?.reason);
107
+ const code = failure?.code ? `${failure.code}: ` : '';
108
+ const starting = action === 'start';
109
+ const e = new Error(`This run cannot ${starting ? 'start' : 'move to'} ${there}: its own profile, ${name}, failed in this run at ${when} (${code}${why}). After its own profile fails, a run does not ${starting ? 'start another profile or move to one' : 'switch to another profile or browser'}: each start of another MoreLogin profile spends one of the plan's daily launches, and the run's work belongs in its own profile. Nothing was ${starting ? 'started' : 'changed'}: the run still works in ${name}. To go on, the user starts or fixes ${name} (in MoreLogin, or SynaBun → Settings → Connected tools → MoreLogin → Start); the run's next browser call then connects to it, and from then on it may switch again. Otherwise the owner moves the run (where it is set up, or the default in Settings → Connected tools → MoreLogin (Default AI browser)). This needs the user, not a retry: report it and stop`);
110
+ e.code = PROFILE_FAILED_NO_SWITCH;
111
+ e.status = 409;
112
+ e.needsUser = true;
113
+ e.envId = String(failure?.envId ?? '');
114
+ if (Number.isFinite(Number(failure?.at))) e.failedAt = new Date(Number(failure.at)).toISOString();
115
+ if (failure?.code) e.failedCode = String(failure.code);
116
+ return e;
117
+ }
118
+
119
+ /**
120
+ * The failures file. Every method is synchronous and never throws: a file that cannot be read holds no failures, and a
121
+ * write that fails is logged and leaves the entry in memory (it bars until a restart).
122
+ * @param {{ file?: string|null, now?: () => number, log?: (line: string) => void, max?: number, maxAgeMs?: number }} opts
123
+ */
124
+ export function createProfileFailureStore({ file = null, now = Date.now, log = () => {}, max = PROFILE_FAILURES_MAX, maxAgeMs = PROFILE_FAILURE_MAX_AGE_MS } = {}) {
125
+ /** ownerKey → { envId, name, at, code, reason }, oldest first. */
126
+ let rows = null;
127
+
128
+ const fresh = (row) => row && Number.isFinite(Number(row.at)) && now() - Number(row.at) < maxAgeMs;
129
+
130
+ function read() {
131
+ const out = new Map();
132
+ try {
133
+ if (!file || !existsSync(file)) return out;
134
+ const data = JSON.parse(readFileSync(file, 'utf-8'));
135
+ const list = data && typeof data === 'object' && data.failures && typeof data.failures === 'object' ? Object.entries(data.failures) : [];
136
+ for (const [owner, row] of list.filter(([owner, row]) => OWNER_RE.test(owner) && fresh(row)).sort((a, b) => Number(a[1].at) - Number(b[1].at))) {
137
+ const envId = cleanId(row.envId);
138
+ if (!envId) continue;
139
+ out.set(owner, { envId, name: cleanText(row.name, 200) || null, at: Number(row.at), code: cleanText(row.code, 64) || null, reason: cleanText(row.reason, 600) || null });
140
+ }
141
+ } catch (error) {
142
+ log(`the runs' failed browser profiles could not be read (${error?.message || error}): no run is barred from switching`);
143
+ }
144
+ return out;
145
+ }
146
+
147
+ function write() {
148
+ if (!file) return;
149
+ try {
150
+ mkdirSync(dirname(file), { recursive: true });
151
+ const temp = `${file}.${process.pid}.tmp`;
152
+ writeFileSync(temp, JSON.stringify({ version: 1, failures: Object.fromEntries(rows) }, null, 2), { mode: 0o600 });
153
+ renameSync(temp, file);
154
+ } catch (error) {
155
+ log(`a run's failed browser profile was not saved (${error?.message || error}): it bars the run until the server restarts`);
156
+ }
157
+ }
158
+
159
+ const loaded = () => (rows ||= read());
160
+ const copy = (row) => ({ ...row });
161
+
162
+ return {
163
+ /** The failure held for `ownerKey` ({ envId, name, at, code, reason }), or null. An expired one is dropped. */
164
+ get(ownerKey) {
165
+ const map = loaded();
166
+ const row = map.get(String(ownerKey || ''));
167
+ if (!row) return null;
168
+ if (!fresh(row)) { map.delete(String(ownerKey)); write(); return null; }
169
+ return copy(row);
170
+ },
171
+ /**
172
+ * `ownerKey`'s own profile `envId` failed now (or at `at`). A later failure replaces an earlier one (the newest
173
+ * profile and reason are what the refusal names). Returns the entry, or null when nothing was noted.
174
+ */
175
+ note(ownerKey, { envId, name = null, code = null, reason = null, at = now() } = {}) {
176
+ const owner = String(ownerKey || '');
177
+ const id = cleanId(envId);
178
+ if (!OWNER_RE.test(owner) || !id) return null;
179
+ const map = loaded();
180
+ const row = { envId: id, name: cleanText(name, 200) || null, at: Number.isFinite(Number(at)) ? Number(at) : now(), code: cleanText(code, 64) || null, reason: cleanText(reason, 600) || null };
181
+ map.delete(owner); // newest last
182
+ map.set(owner, row);
183
+ while (map.size > max) map.delete(map.keys().next().value);
184
+ write();
185
+ return copy(row);
186
+ },
187
+ /**
188
+ * The failure of `ownerKey` is over: always, or only when it is about `envId` (a connection to another profile
189
+ * says nothing about the failed one). Returns the entry that was dropped, or null.
190
+ */
191
+ clear(ownerKey, { envId = null } = {}) {
192
+ const map = loaded();
193
+ const owner = String(ownerKey || '');
194
+ const row = map.get(owner);
195
+ if (!row) return null;
196
+ if (envId !== null && envId !== undefined && String(envId) !== row.envId) return null;
197
+ map.delete(owner);
198
+ write();
199
+ return copy(row);
200
+ },
201
+ /** Every failure held now: [ownerKey, entry], oldest first. */
202
+ entries() {
203
+ return [...loaded()].filter(([, row]) => fresh(row)).map(([owner, row]) => [owner, copy(row)]);
204
+ },
205
+ };
206
+ }