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
@@ -0,0 +1,418 @@
1
+ import { createServer } from 'node:http';
2
+ import { createHash, randomBytes } from 'node:crypto';
3
+ import { chmodSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { dirname } from 'node:path';
5
+ import { lookup } from 'node:dns/promises';
6
+ import { WebSocketServer } from 'ws';
7
+ import { anyOrigin, channel, command, COMMAND_WAIT, CONTROL, controlSurface, equalMac, ERROR_TEXT, fail, handle, HISTORY, inventory, localHost, mac, MAX_MESSAGE, nonce, object, pairingKey, parse, payload, portOf, publicOrigin, safeError, string } from '../../browser-extension/protocol.js';
8
+
9
+ const manifest = JSON.parse(readFileSync(new URL('../../browser-extension/manifest.json', import.meta.url), 'utf8'));
10
+ export const EXTENSION_ID = createHash('sha256').update(Buffer.from(manifest.key, 'base64')).digest('hex').slice(0, 32).replace(/[0-9a-f]/g, c => String.fromCharCode(97 + parseInt(c, 16)));
11
+ const empty = () => ({ tabs: [], sites: [], allowNewTabs: false, uploads: false, downloads: false });
12
+ export async function publicDestination(url, resolver = lookup) {
13
+ const origin = publicOrigin(url);
14
+ const addresses = await resolver(new URL(origin).hostname, { all: true });
15
+ if (!addresses.length || addresses.some(({ address }) => {
16
+ if (address.includes(':')) return !/^2[0-9a-f]{3}:/i.test(address) || /^2001:(0:|db8:)/i.test(address);
17
+ const [a, b] = address.split('.').map(Number);
18
+ return a === 0 || a === 10 || a === 127 || a >= 224 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 100 && b >= 64 && b <= 127;
19
+ })) fail('SITE_NOT_APPROVED');
20
+ return origin;
21
+ }
22
+
23
+ // An address that is this computer: loopback, unspecified, or one of its own interface addresses (`selfHosts`).
24
+ function selfAddress(address, selfHosts) {
25
+ return localHost(address, selfHosts) || /^::ffff:/i.test(address) && localHost(address.slice(7), selfHosts);
26
+ }
27
+
28
+ /**
29
+ * Where the paired credential and the owner's mode are kept across restarts: one JSON file, readable by the owner only
30
+ * (0600, in a 0700 folder), replaced in one rename. It holds the credential (an HMAC key: never logged, never in a
31
+ * status), its expiry, the port, whether the owner disconnected, and the mode with its version. Never throws.
32
+ */
33
+ export function createBridgeStore(path) {
34
+ return {
35
+ path,
36
+ read() {
37
+ try { if (!lstatSync(path).isFile()) return null; const value = JSON.parse(readFileSync(path, 'utf8')); return value && typeof value === 'object' ? value : null; }
38
+ catch { return null; }
39
+ },
40
+ write(value) {
41
+ const folder = dirname(path);
42
+ mkdirSync(folder, { recursive: true, mode: 0o700 }); try { chmodSync(folder, 0o700); } catch {}
43
+ const temporary = `${path}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
44
+ try { writeFileSync(temporary, JSON.stringify(value), { mode: 0o600, flag: 'wx' }); renameSync(temporary, path); }
45
+ finally { rmSync(temporary, { force: true }); }
46
+ try { chmodSync(path, 0o600); } catch {}
47
+ },
48
+ };
49
+ }
50
+
51
+ /** Isolated loopback transport. Constructing it neither listens nor reads/writes user data (restore() does). */
52
+ // `commandWait` is how long a request waits for the extension's answer (COMMAND_WAIT; smaller only in tests), on the
53
+ // monotonic `clock`. Each command carries what is left of that wait when it is sent, as its `deadline`.
54
+ // `fullControl` is the mode before the owner chose one (on: agents may use any http(s) site and any tab of the paired
55
+ // browser; off: only what the owner shares). `store` keeps the pairing and the mode across restarts (createBridgeStore).
56
+ // SynaBun's own addresses stay out of reach in both modes: `forbiddenOrigins` (its public aliases, any port),
57
+ // `blockedPorts` (its ports; the bridge's own is always added) on this computer, which is localhost, a loopback address
58
+ // or one of `selfHosts` (its names and interface addresses) or a name that resolves to one (`lookupAddresses`).
59
+ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory = () => {}, resolvePublic = publicDestination, now = Date.now, forbiddenOrigins = () => [], revokedTabsKept = 1024,
60
+ commandWait = COMMAND_WAIT, clock = () => performance.now(), fullControl = true, store = null, blockedPorts = () => [], selfHosts = () => [],
61
+ lookupAddresses = host => lookup(host, { all: true }) } = {}) {
62
+ if (!Number.isSafeInteger(commandWait) || commandWait < 1 || commandWait > COMMAND_WAIT) fail('INVALID_MESSAGE');
63
+ let server, wss, listening, pair = null, credential = null, peer = null, state = empty(), enabled = true;
64
+ // The owner's mode and its version. The newer version wins on either side: the server's (Settings) or the
65
+ // extension's (its popup, reported in an inventory). Only the owner changes it: setMode() behind the owner route,
66
+ // or the popup. Nothing an agent sends carries a mode.
67
+ let mode = { fullControl: fullControl === true, version: 0 };
68
+ // A server process does not know the agents of the previous one: the first extension it hears from (one that knows
69
+ // the `reset` message) gives every tab back to the owner.
70
+ let resetDue = true;
71
+ let revision = 0, pairingAttempts = 0, credentialUntil = 0;
72
+ // When the current credential was paired (a stored one: 30 days before its expiry), and whether a pairing window is
73
+ // the one-button setup's (`pair.setup`: its one-time token, made by beginSetupPairing, never a typed code).
74
+ let pairedAt = 0;
75
+ const PAIRING_LIFE = 30 * 86400000;
76
+ // `authentication` moves on revoke, disconnect and every new pairing: a handshake commits only in the generation it
77
+ // began in, and a peer is obeyed only in the generation it was admitted in. `revocations` moves when any owner
78
+ // revocation begins: a command issued before it is never forwarded after it, and its result is refused.
79
+ let authentication = 0, revocations = 0;
80
+ // revokedSites: origin → the newest approval version known when the owner revoked it here. An inventory brings the
81
+ // site back only with a newer version, which only the owner's gesture in the popup creates.
82
+ // revokedTabs holds one random handle per tab revoked here, so it is the record that grows with use: it keeps the
83
+ // newest `revokedTabsKept` (1024), dropping the oldest. The site maps hold one entry per distinct origin and are kept whole
84
+ // (dropping one would let a stale inventory bring its site back). A new pairing clears all three.
85
+ const revokedTabs = new Set(), revokedSites = new Map(), siteVersions = new Map();
86
+ const revokeTabRecord = tab => {
87
+ revokedTabs.delete(tab); revokedTabs.add(tab);
88
+ for (const old of revokedTabs) { if (revokedTabs.size <= revokedTabsKept) break; revokedTabs.delete(old); }
89
+ };
90
+ const blockedHosts = () => forbiddenOrigins().map(value => { try { return new URL(value.includes('://') ? value : `https://${value}`).hostname; } catch { return ''; } }).filter(Boolean);
91
+ const hostList = values => [...new Set((values || []).map(String).map(h => h.replace(/^\[|\]$/g, '')).filter(h => h.length <= 253 && /^[a-zA-Z0-9.:%-]+$/.test(h)))].slice(0, 200);
92
+ // What no command may reach: SynaBun's own addresses (protocol.js controlSurface), sent with every command too.
93
+ const targets = () => {
94
+ let ports = []; try { ports = blockedPorts() || []; } catch {}
95
+ const own = server?.address()?.port || port;
96
+ ports = [...new Set([own, ...ports].map(Number).filter(p => Number.isSafeInteger(p) && p >= 1 && p <= 65535))].slice(0, 32);
97
+ let self = []; try { self = selfHosts() || []; } catch {}
98
+ return { blockedHosts: hostList(blockedHosts()), blockedPorts: ports, selfHosts: hostList(self) };
99
+ };
100
+ // Full control: any http(s) page or the blank page, never a browser page nor SynaBun's own (by its form).
101
+ const openable = url => { anyOrigin(url); if (controlSurface(url, targets())) fail('SYNABUN_PAGE_BLOCKED'); };
102
+ // ... and by DNS: a name on one of SynaBun's ports that resolves to this computer (or cannot be resolved) is refused.
103
+ async function openDestination(url) {
104
+ openable(url);
105
+ if (url === 'about:blank') return;
106
+ const u = new URL(url), seen = targets();
107
+ if (!seen.blockedPorts.includes(portOf(u))) return;
108
+ let addresses;
109
+ try { addresses = await lookupAddresses(u.hostname.replace(/^\[|\]$/g, '')); } catch { fail('SYNABUN_PAGE_BLOCKED'); }
110
+ if (!addresses?.length || addresses.some(({ address }) => selfAddress(String(address), seen.selfHosts))) fail('SYNABUN_PAGE_BLOCKED');
111
+ }
112
+ // Writes the pairing and the mode (owner-only file). A failure is logged by its code and never stops the bridge.
113
+ function persist() {
114
+ if (!store) return;
115
+ try {
116
+ store.write({ v: 1, ...(credential ? { credential, credentialUntil } : {}), port: server?.address()?.port || port, paused: !enabled,
117
+ fullControl: mode.fullControl, modeVersion: mode.version });
118
+ } catch { note('persist', null, 'OPERATION_FAILED'); }
119
+ }
120
+ const pending = new Map();
121
+ const sockets = new Set();
122
+ const note = (op, tab, code) => { try { log({ command: op, tab: typeof tab === 'string' && /^[a-f0-9]{32}$/.test(tab) ? tab : null, code: code === 'OK' || Object.hasOwn(ERROR_TEXT, code) ? code : 'OPERATION_FAILED' }); } catch {} };
123
+ const coded = code => () => Object.assign(new Error(code), { code });
124
+ const notConnected = coded('NOT_CONNECTED'), cancelled = coded('CANCELLED');
125
+ // Rejects pending requests at once. `keepControl` spares the owner's own revocations, which must still reach the extension.
126
+ function settle(error, keepControl = false) {
127
+ for (const [id, p] of pending) {
128
+ if (keepControl && CONTROL.includes(p.op)) continue;
129
+ clearTimeout(p.timer); pending.delete(id); p.reject(error());
130
+ }
131
+ }
132
+ // The extension's mode, when an inventory carries it: a newer one is the owner's latest choice (the popup) and is
133
+ // taken; switching to restricted that way is a revocation. An older one (or the same version saying otherwise) is
134
+ // told the server's choice, once per connection and version.
135
+ function peerMode(from, fullControlNow, version) {
136
+ if (version > mode.version) {
137
+ const narrowing = mode.fullControl && !fullControlNow;
138
+ mode = { fullControl: fullControlNow, version }; persist();
139
+ if (narrowing) revoking();
140
+ } else if (version < mode.version || fullControlNow !== mode.fullControl) pushMode(from);
141
+ }
142
+ function pushMode(to = peer) {
143
+ const key = `${mode.version}:${mode.fullControl}`;
144
+ if (!to || to !== peer || to.pushedMode === key) return;
145
+ to.pushedMode = key;
146
+ void request('mode', null, 'owner', { fullControl: mode.fullControl, version: mode.version }).catch(() => { if (to.pushedMode === key) to.pushedMode = null; });
147
+ }
148
+ function update(value, from = null) {
149
+ const { versions, fullControl: fullControlNow, modeVersion, ...next } = inventory(value);
150
+ if (from && modeVersion !== undefined) peerMode(from, fullControlNow, modeVersion);
151
+ if (from && !from.ready) {
152
+ from.ready = true;
153
+ // Only an extension that knows `reset` (it reports a mode) is sent one; an older one keeps what it holds.
154
+ if (resetDue && modeVersion !== undefined) { resetDue = false; void request('reset', null, 'owner').catch(() => { resetDue = true; }); }
155
+ }
156
+ if (versions) next.sites.forEach((site, i) => siteVersions.set(site, Math.max(siteVersions.get(site) || 0, versions[i])));
157
+ next.tabs = next.tabs.filter(t => !revokedTabs.has(t.handle));
158
+ next.sites = next.sites.filter((site, i) => !revokedSites.has(site) || (versions ? versions[i] : siteVersions.get(site) || 0) > revokedSites.get(site));
159
+ state = next; revision++; onInventory({ ...state, fullControl: mode.fullControl });
160
+ }
161
+ // An owner revocation begins: cancel everything issued before it, synchronously, before the extension is told.
162
+ function revoking() { revocations++; settle(cancelled, true); }
163
+ // Ends the connection and every handshake still under way; nothing admitted before acts after.
164
+ function cut() {
165
+ enabled = false; authentication++; revocations++;
166
+ peer = null; for (const ws of sockets) ws.close();
167
+ settle(notConnected);
168
+ }
169
+ // The owner's Disconnect: kept across a restart (the bridge stays off until Resume).
170
+ function disconnect() { cut(); persist(); }
171
+ function forget() { cut(); credential = null; credentialUntil = 0; pairedAt = 0; pair = null; update(empty()); }
172
+ // Revoke pairing: the stored credential goes too, so a restart does not bring it back.
173
+ function revoke() { forget(); persist(); }
174
+ async function start() {
175
+ if (listening) return listening;
176
+ listening = new Promise((resolve, reject) => {
177
+ server = createServer((_req, res) => { res.writeHead(404); res.end(); });
178
+ wss = new WebSocketServer({ noServer: true, maxPayload: MAX_MESSAGE, perMessageDeflate: false });
179
+ server.on('upgrade', (req, socket, head) => {
180
+ if (req.socket.remoteAddress !== '127.0.0.1' || req.headers.origin !== `chrome-extension://${EXTENSION_ID}` || req.url !== '/bridge'
181
+ || req.headers.host !== `127.0.0.1:${server.address()?.port}` || sockets.size >= 4) { socket.destroy(); return; }
182
+ wss.handleUpgrade(req, socket, head, ws => { void connect(ws); });
183
+ });
184
+ server.once('error', error => { listening = null; reject(error); });
185
+ server.listen(port, '127.0.0.1', () => resolve(server.address().port));
186
+ });
187
+ return listening;
188
+ }
189
+ async function connect(ws) {
190
+ sockets.add(ws);
191
+ const session = nonce(), admitted = authentication;
192
+ let wire = null, chain = Promise.resolve(), outbound = Promise.resolve();
193
+ // A command is checked, and its deadline set to what is left of the request's wait, right before it is signed, and
194
+ // checked again in the same synchronous step that sends it (encode's `deliver`): a refusal then uses no sequence
195
+ // number, so the channel stays in step. A command with less than a millisecond left is not sent (TIMEOUT).
196
+ const send = body => {
197
+ const check = () => {
198
+ if (body.type !== 'command') return;
199
+ const p = pending.get(body.id);
200
+ if (!p || peer?.ws !== ws) fail('NOT_CONNECTED');
201
+ if (!CONTROL.includes(body.op) && p.issued !== revocations) fail('CANCELLED');
202
+ if (clock() >= p.expires) fail('TIMEOUT');
203
+ authorize(body.op, body.tab, body.owner, body.args);
204
+ };
205
+ outbound = outbound.catch(() => {}).then(async () => {
206
+ if (body.type === 'command') {
207
+ check();
208
+ body = command({ ...body, deadline: Math.max(1, Math.min(commandWait, Math.floor(pending.get(body.id).expires - clock()))) });
209
+ }
210
+ await wire.encode(body, raw => { check(); if (ws.readyState !== 1) fail('NOT_CONNECTED'); ws.send(raw); });
211
+ }); return outbound;
212
+ };
213
+ const timer = setTimeout(() => ws.close(), 10000); timer.unref?.();
214
+ let lastSeen = Date.now();
215
+ const heartbeat = setInterval(() => { if (Date.now() - lastSeen > 65000) ws.close(); else if (wire) void send({ type: 'ping' }).catch(() => ws.close()); }, 20000); heartbeat.unref?.();
216
+ ws.send(JSON.stringify({ type: 'challenge', session }));
217
+ ws.on('message', raw => {
218
+ chain = chain.then(async () => {
219
+ if (!wire) {
220
+ // `version`: the extension's manifest version (1.2.0 and later send it), so the owner is told when the browser
221
+ // still runs an older copy than the folder holds. Optional: an older extension sends none.
222
+ const hello = parse(raw.toString(), 2048); object(hello, ['type', 'mode', 'client', 'proof', 'version']);
223
+ if (hello.type !== 'hello' || !['pair', 'resume'].includes(hello.mode)) fail('AUTH_FAILED');
224
+ handle(hello.client); string(hello.proof, 64);
225
+ if (hello.version !== undefined && !/^\d{1,5}(\.\d{1,5}){0,3}$/.test(string(hello.version, 23))) fail('AUTH_FAILED');
226
+ if (admitted !== authentication) fail('AUTH_FAILED');
227
+ const isPair = hello.mode === 'pair', pairWindow = pair;
228
+ if (isPair && (!pairWindow || pairWindow.until < now() || ++pairingAttempts > 5)) fail('PAIRING_EXPIRED');
229
+ const key = isPair ? pairWindow.key : now() < credentialUntil ? credential : null;
230
+ if (!enabled || !key || !await equalMac(key, `hello:${session}:${hello.client}`, hello.proof)) fail('AUTH_FAILED');
231
+ // A setup's token was presented: the setup shows "Pairing…" until the extension is connected.
232
+ if (isPair && pairWindow.setup) pairWindow.attempted = true;
233
+ // Authenticate the server too. A fake loopback server learns no reusable credential.
234
+ const proof = await mac(key, `welcome:${session}:${hello.client}`);
235
+ // The awaits above leave room for a revoke, a disconnect or a new pairing. Commit only if none happened: the
236
+ // same generation, the bridge on, this socket open, and the key still the current credential or pairing window.
237
+ if (admitted !== authentication || !enabled || ws.readyState !== 1
238
+ || (isPair ? pair !== pairWindow || pairWindow.until < now() : key !== credential || now() >= credentialUntil)) fail('AUTH_FAILED');
239
+ const previous = peer;
240
+ peer = { ws, send, session, key, generation: admitted, ready: false, pushedMode: null, version: hello.version || null }; previous?.ws.close();
241
+ if (previous) settle(notConnected);
242
+ // A new pairing starts from a cleared extension: nothing of a previous process to hand back.
243
+ // A setup's token is gone with it (single use): `pair` is cleared in this same step. A setup pairing, like a
244
+ // typed one, starts from nothing revoked (beginPairing clears these when its window opens).
245
+ if (isPair) {
246
+ if (pairWindow.setup) { revokedTabs.clear(); revokedSites.clear(); siteVersions.clear(); }
247
+ credential = key; pairedAt = now(); credentialUntil = pairedAt + PAIRING_LIFE; pair = null; resetDue = false; update(empty()); persist();
248
+ }
249
+ wire = channel(key, session, 'server'); clearTimeout(timer);
250
+ ws.send(JSON.stringify({ type: 'welcome', proof }));
251
+ return;
252
+ }
253
+ if (peer?.ws !== ws || !enabled) fail('AUTH_FAILED');
254
+ const message = payload(await wire.decode(raw.toString())); lastSeen = Date.now();
255
+ if (message.type === 'pong') return;
256
+ if (message.type === 'unpair') { revoke(); return; }
257
+ if (message.type !== 'state' && message.type !== 'result') fail('INVALID_MESSAGE');
258
+ update(message.inventory, peer);
259
+ if (message.type === 'result') {
260
+ const p = pending.get(message.id); if (!p) return;
261
+ pending.delete(message.id); clearTimeout(p.timer);
262
+ try {
263
+ if (!CONTROL.includes(p.op) && p.issued !== revocations) fail('CANCELLED');
264
+ if (p.op !== 'create' && p.op !== 'claim' && p.op !== 'release' && !CONTROL.includes(p.op)) authorize(p.op, p.tab, p.owner, p.args);
265
+ p.resolve(message.result);
266
+ } catch (error) { p.reject(error); }
267
+ }
268
+ }).catch(error => { note('transport', null, safeError(error).code); ws.close(); });
269
+ });
270
+ ws.on('error', () => {});
271
+ ws.on('close', () => {
272
+ clearTimeout(timer); clearInterval(heartbeat); sockets.delete(ws);
273
+ if (peer?.ws === ws) { peer = null; settle(notConnected); }
274
+ });
275
+ }
276
+ function authorize(op, tab, owner, args = {}) {
277
+ if (!enabled || !peer || peer.ws.readyState !== 1) fail('EXTENSION_NOT_CONNECTED');
278
+ // The peer must hold the credential that is current now, admitted in the current generation: a replaced credential
279
+ // is refused even before it would have expired.
280
+ if (peer.generation !== authentication || !credential || peer.key !== credential || now() >= credentialUntil) fail('AUTH_FAILED');
281
+ if (CONTROL.includes(op)) { if (owner !== 'owner') fail('NOT_OWNED'); return; }
282
+ // Until the extension's first inventory on this connection (and the reset that may follow it) nothing else goes.
283
+ if (!peer.ready) fail('EXTENSION_NOT_CONNECTED');
284
+ if (op === 'create') { if (!mode.fullControl && !state.allowNewTabs) fail('PERMISSION_REQUIRED'); return; }
285
+ const t = state.tabs.find(t => t.handle === tab); if (!t) fail('TAB_CLOSED');
286
+ if (op === 'claim') { if (t.owner && t.owner !== owner) fail('NOT_OWNED'); if (mode.fullControl) openable(t.url); return; }
287
+ if (t.owner !== owner) fail('NOT_OWNED');
288
+ if (op === 'release') return;
289
+ if (mode.fullControl) {
290
+ // Full control: no sharing step. Any http(s) page, never a browser page or SynaBun's own.
291
+ for (const url of [t.url, args.url].filter(Boolean)) openable(url);
292
+ if (op === 'download' && !state.downloads) fail('PERMISSION_REQUIRED');
293
+ return;
294
+ }
295
+ for (const url of [t.url, args.url].filter(Boolean)) if (url !== 'about:blank' && blockedHosts().includes(new URL(url).hostname)) fail('SITE_NOT_APPROVED');
296
+ if (t.url !== 'about:blank' && !state.sites.includes(publicOrigin(t.url))) fail('SITE_NOT_APPROVED');
297
+ if (t.url === 'about:blank' && op !== 'navigate' && !HISTORY.includes(op)) fail('SITE_NOT_APPROVED');
298
+ if (args.url && !state.sites.includes(publicOrigin(args.url))) fail('SITE_NOT_APPROVED');
299
+ if (op === 'upload' && !state.uploads || op === 'download' && !state.downloads) fail('PERMISSION_REQUIRED');
300
+ }
301
+ async function request(op, tab, owner, args = {}) {
302
+ // The revocation generation this command was issued in; an owner revocation that begins later cancels it.
303
+ const issued = revocations, stale = () => !CONTROL.includes(op) && issued !== revocations;
304
+ if (pending.size >= 32) fail('TIMEOUT');
305
+ const msg = command({ type: 'command', id: nonce(), op, tab, owner, args, ...targets(), deadline: commandWait });
306
+ try {
307
+ authorize(op, tab, owner, args);
308
+ const version = revision, connection = peer, full = mode.fullControl;
309
+ const current = state.tabs.find(t => t.handle === tab)?.url;
310
+ // The destination rule of the mode, by DNS too: restricted, public addresses only; full control, never this
311
+ // computer on one of SynaBun's ports.
312
+ const check = url => full ? openDestination(url) : resolvePublic(url);
313
+ if (!['release', 'claim', 'create'].includes(op) && !CONTROL.includes(op)) {
314
+ if (current && current !== 'about:blank') await check(current);
315
+ if (args.url && args.url !== 'about:blank') await check(args.url);
316
+ } else if (op === 'claim' && full && current && current !== 'about:blank') await check(current);
317
+ if (stale()) fail('CANCELLED');
318
+ if (version !== revision || connection !== peer) authorize(op, tab, owner, args);
319
+ const via = peer;
320
+ const result = await new Promise((resolve, reject) => {
321
+ // The wait starts here, and the deadline the command carries is what is left of it when it is sent. When the
322
+ // wait ends the command is forgotten (a late result finds no pending entry and is dropped) and the extension is
323
+ // told to stop it, ahead of its queue; its own deadline will already have stopped it.
324
+ const timer = setTimeout(() => {
325
+ pending.delete(msg.id); reject(Object.assign(new Error('TIMEOUT'), { code: 'TIMEOUT' }));
326
+ if (peer === via && via.ws.readyState === 1) void via.send({ type: 'cancel', id: msg.id }).catch(() => {});
327
+ }, commandWait);
328
+ pending.set(msg.id, { resolve, reject, timer, op, tab, owner, args, issued, expires: clock() + commandWait });
329
+ via.send(msg).catch(error => { clearTimeout(timer); pending.delete(msg.id); reject(['CANCELLED', 'TIMEOUT'].includes(error?.code) ? coded(error.code)() : notConnected()); });
330
+ });
331
+ if (HISTORY.includes(op) && result.ok) {
332
+ // The extension already refused an unapproved landing page and the result handler re-authorized against the
333
+ // new inventory. Also hold the landing page to navigate's rules: the URL the result names is the one the
334
+ // inventory holds, and it resolves to a public address. Otherwise nothing of it reaches the agent.
335
+ const landed = state.tabs.find(t => t.handle === tab)?.url;
336
+ if (!landed || result.url !== landed) fail(mode.fullControl ? 'TAB_NOT_APPROVED' : 'SITE_NOT_APPROVED');
337
+ if (landed !== 'about:blank') await (mode.fullControl ? openDestination(landed) : resolvePublic(landed));
338
+ if (stale()) fail('CANCELLED');
339
+ authorize(op, tab, owner, args);
340
+ }
341
+ note(op, tab || result.tab, result.code || 'OK'); return result;
342
+ } catch (error) { note(op, tab, safeError(error).code); throw error; }
343
+ }
344
+ return {
345
+ request, authorize,
346
+ // Whether an agent may be shown or given this page in full control (the session listing): never a browser page
347
+ // or SynaBun's own.
348
+ openable: url => { try { openable(url); return true; } catch { return false; } },
349
+ // Loads the pairing and the mode a previous process stored, and listens again when the pairing is still valid,
350
+ // so the extension reconnects by itself. Returns { restored, listening } (`listening`: the port, or a rejection).
351
+ restore() {
352
+ const saved = store?.read();
353
+ if (!saved) return { restored: false };
354
+ if (typeof saved.fullControl === 'boolean' && Number.isSafeInteger(saved.modeVersion) && saved.modeVersion >= 0) mode = { fullControl: saved.fullControl, version: saved.modeVersion };
355
+ const valid = typeof saved.credential === 'string' && /^[a-f0-9]{64}$/.test(saved.credential) && Number.isSafeInteger(saved.credentialUntil)
356
+ && saved.credentialUntil > now() && Number.isInteger(saved.port) && saved.port >= 1024 && saved.port <= 65535;
357
+ if (!valid) { if (saved.credential !== undefined) persist(); return { restored: false }; }
358
+ credential = saved.credential; credentialUntil = saved.credentialUntil; pairedAt = credentialUntil - PAIRING_LIFE; port = saved.port; enabled = saved.paused !== true;
359
+ const listening = start(); listening.catch(() => {});
360
+ return { restored: true, listening };
361
+ },
362
+ // The owner's mode switch (Settings → Browser, behind the owner route). Restricted is a revocation: everything
363
+ // issued before it is cancelled at once, and the extension is told ahead of its queue.
364
+ async setMode(fullControlNext) {
365
+ if (typeof fullControlNext !== 'boolean') fail('INVALID_MESSAGE');
366
+ if (fullControlNext !== mode.fullControl) {
367
+ if (!fullControlNext) revoking();
368
+ mode = { fullControl: fullControlNext, version: Math.max(mode.version + 1, now()) }; persist();
369
+ if (peer?.ready) { peer.pushedMode = `${mode.version}:${mode.fullControl}`; await request('mode', null, 'owner', { fullControl: mode.fullControl, version: mode.version }).catch(() => { if (peer) peer.pushedMode = null; }); }
370
+ }
371
+ return { fullControl: mode.fullControl };
372
+ },
373
+ mode: () => ({ ...mode }),
374
+ async beginPairing(requestedPort = port) {
375
+ if (!Number.isInteger(requestedPort) || (requestedPort < 1024 && !(requestedPort === 0 && port === 0)) || requestedPort > 65535) fail('INVALID_MESSAGE');
376
+ if (!server?.listening) port = requestedPort;
377
+ await start(); forget(); enabled = true; persist(); pairingAttempts = 0; revokedTabs.clear(); revokedSites.clear(); siteVersions.clear();
378
+ const code = randomBytes(10).toString('hex'); pair = { key: await pairingKey(code), until: now() + 120000 };
379
+ return { code, expiresAt: pair.until, port: server.address().port, extensionId: EXTENSION_ID };
380
+ },
381
+ // The one-button setup's pairing window (lib/browser-extension-setup.js; docs → One-button setup). The token is a
382
+ // random 256-bit value that stands in for the typed code in the same HMAC handshake (pairingKey(token)): it never
383
+ // crosses the socket, a pairing commits once and clears it, it expires at `until`, five failed proofs end it, and
384
+ // it exists only while the owner's setup is active (endSetupPairing, a typed pairing, Revoke). Unlike a typed
385
+ // pairing, opening the window does not end the current pairing: the token replaces the credential only when an
386
+ // extension proves it. Returns { token, port, expiresAt }; the caller hands the token to the setup page only.
387
+ async beginSetupPairing({ until, requestedPort = port } = {}) {
388
+ if (!Number.isSafeInteger(until) || until <= now()) fail('INVALID_MESSAGE');
389
+ if (!server?.listening) {
390
+ if (!Number.isInteger(requestedPort) || (requestedPort < 1024 && !(requestedPort === 0 && port === 0)) || requestedPort > 65535) fail('INVALID_MESSAGE');
391
+ port = requestedPort;
392
+ }
393
+ await start();
394
+ const token = randomBytes(32).toString('hex');
395
+ const key = await pairingKey(token);
396
+ // A Disconnect is the owner's; starting a setup is the owner asking to connect, so the bridge listens again.
397
+ enabled = true; pairingAttempts = 0; pair = { key, until, setup: true, attempted: false }; persist();
398
+ return { token, port: server.address().port, expiresAt: until };
399
+ },
400
+ endSetupPairing() { if (pair?.setup) pair = null; },
401
+ setupPairing: () => ({ active: !!pair?.setup && pair.until >= now() && pairingAttempts <= 5, attempted: pair?.setup ? pair.attempted === true : false }),
402
+ // Diagnostics: how many revocation records the bridge keeps (counts only).
403
+ records: () => ({ revokedTabs: revokedTabs.size, revokedSites: revokedSites.size, siteVersions: siteVersions.size }),
404
+ status: () => ({ connected: !!peer && enabled && peer.ready === true, paired: !!credential, port: server?.address()?.port || port, extensionId: EXTENSION_ID,
405
+ fullControl: mode.fullControl, pairedAt: credential ? pairedAt : 0, extensionVersion: peer?.ready ? peer.version : null, ...structuredClone(state) }),
406
+ disconnect,
407
+ resume: () => { enabled = true; persist(); },
408
+ revoke,
409
+ async revokeTab(tab) { handle(tab); revoking(); revokeTabRecord(tab); update(state); return request('revokeTab', tab, 'owner'); },
410
+ async revokeSite(site) {
411
+ publicOrigin(site); revoking();
412
+ revokedSites.set(site, Math.max(revokedSites.get(site) || 0, siteVersions.get(site) || 0)); update(state);
413
+ return request('revokeSite', null, 'owner', { site });
414
+ },
415
+ // Stops this process's bridge; what is stored stays (a restart reconnects).
416
+ async close() { forget(); for (const ws of sockets) ws.terminate(); if (wss) wss.close(); if (server) await new Promise(resolve => server.close(resolve)); listening = null; },
417
+ };
418
+ }
@@ -0,0 +1,116 @@
1
+ // The extension folder the owner loads in the browser ("Load unpacked"): a copy of the bundled browser-extension/ in
2
+ // the owner's data home (DATA_HOME/browser-extension/unpacked), so an npm update or a moved checkout never breaks the
3
+ // loaded extension. It is refreshed when the bundled copy changes and is not older than what is there; the browser
4
+ // then needs the extension's Reload (the server tells the owner: status `reloadNeeded`).
5
+ //
6
+ // The copy keeps the manifest's `key`, so the extension's ID is the same from this folder as from the bundled one
7
+ // (lib/browser-extension-bridge.js EXTENSION_ID). Only the setup page's content script changes: its matches name this
8
+ // server's own app port (127.0.0.1 and localhost), so the script runs on SynaBun's setup page and nowhere else.
9
+ //
10
+ // What is copied is an allowlist (the manifest, scripts, pages, styles, the icons), read as regular files only (a link
11
+ // is never followed). The folder is replaced in one rename where the system allows it; where it does not (Windows,
12
+ // a folder the browser holds open), the files are written in place. Nothing here is logged with a path.
13
+ import { createHash, randomBytes } from 'node:crypto';
14
+ import { chmodSync, lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
15
+ import { dirname, join } from 'node:path';
16
+
17
+ /** The path of the setup page, and the content-script file that reads its one-time pairing token. */
18
+ export const SETUP_PAGE_PATH = '/extension-setup';
19
+ export const SETUP_SCRIPT = 'setup-content.js';
20
+ const FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(js|json|html|css|png)$/;
21
+
22
+ /** The setup page's origins for an app port: the content script's matches, and what the service worker accepts. */
23
+ export function setupMatches(appPort) {
24
+ const port = Number(appPort);
25
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw Object.assign(new Error('Invalid app port.'), { code: 'INVALID_MESSAGE' });
26
+ return [`http://127.0.0.1:${port}${SETUP_PAGE_PATH}*`, `http://localhost:${port}${SETUP_PAGE_PATH}*`];
27
+ }
28
+ /** The bundled files, by path relative to the folder: regular files of the allowlist, one level of `icons/`. */
29
+ export function bundledFiles(source) {
30
+ const files = [];
31
+ for (const [dir, prefix] of [[source, ''], [join(source, 'icons'), 'icons/']]) {
32
+ let names = [];
33
+ try { names = readdirSync(dir); } catch { continue; }
34
+ for (const name of names.sort()) {
35
+ if (!FILE.test(name)) continue;
36
+ const path = join(dir, name);
37
+ try { if (!lstatSync(path).isFile()) continue; } catch { continue; }
38
+ files.push({ rel: prefix + name, path });
39
+ }
40
+ }
41
+ return files;
42
+ }
43
+ /** The manifest the folder gets: the bundled one, with the setup content script set to `appPort`. */
44
+ export function folderManifest(manifest, appPort) {
45
+ const copy = structuredClone(manifest);
46
+ copy.content_scripts = [{ matches: setupMatches(appPort), js: [SETUP_SCRIPT], run_at: 'document_idle', all_frames: false }];
47
+ return copy;
48
+ }
49
+ /** Compares dotted versions (1.10.0 > 1.9.0). */
50
+ export function compareVersions(a, b) {
51
+ const pa = String(a || '0').split('.').map(n => Number.parseInt(n, 10) || 0), pb = String(b || '0').split('.').map(n => Number.parseInt(n, 10) || 0);
52
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) { const d = (pa[i] || 0) - (pb[i] || 0); if (d) return Math.sign(d); }
53
+ return 0;
54
+ }
55
+ function contents(source, appPort) {
56
+ const files = bundledFiles(source).map(f => ({ ...f, bytes: readFileSync(f.path) }));
57
+ const manifestFile = files.find(f => f.rel === 'manifest.json');
58
+ if (!manifestFile) throw Object.assign(new Error('The bundled extension has no manifest.'), { code: 'EXTENSION_FOLDER_FAILED' });
59
+ const manifest = folderManifest(JSON.parse(manifestFile.bytes.toString('utf8')), appPort);
60
+ manifestFile.bytes = Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`);
61
+ const digest = createHash('sha256');
62
+ for (const f of files) digest.update(f.rel).update('\0').update(f.bytes).update('\0');
63
+ return { files, version: String(manifest.version || '0'), digest: digest.digest('hex') };
64
+ }
65
+ function readMarker(path) {
66
+ try { if (!lstatSync(path).isFile()) return null; const v = JSON.parse(readFileSync(path, 'utf8')); return v && typeof v === 'object' ? v : null; } catch { return null; }
67
+ }
68
+ function writeFiles(folder, files) {
69
+ mkdirSync(join(folder, 'icons'), { recursive: true, mode: 0o700 });
70
+ for (const f of files) writeFileSync(join(folder, f.rel), f.bytes, { mode: 0o600 });
71
+ }
72
+
73
+ /**
74
+ * Prepares or refreshes the owner's extension folder. `force` refreshes even when the bundled version is older than
75
+ * what is there (never used at start). Returns { folder, version, changed, previousVersion, appPort }. Throws
76
+ * EXTENSION_FOLDER_FAILED when the folder cannot be written.
77
+ */
78
+ export function prepareExtensionFolder({ source, home, appPort, now = Date.now, force = false }) {
79
+ const root = join(home, 'browser-extension'), folder = join(root, 'unpacked'), markerPath = join(root, 'unpacked.json');
80
+ const { files, version, digest } = contents(source, appPort);
81
+ const marker = readMarker(markerPath);
82
+ const present = (() => { try { return lstatSync(join(folder, 'manifest.json')).isFile(); } catch { return false; } })();
83
+ const same = present && marker?.digest === digest;
84
+ const older = present && marker?.version && compareVersions(version, marker.version) < 0;
85
+ if (same || older && !force) return { folder, version: marker?.version || version, changed: false, previousVersion: marker?.version || null, appPort: marker?.appPort ?? Number(appPort), stale: !same };
86
+ try {
87
+ mkdirSync(root, { recursive: true, mode: 0o700 }); try { chmodSync(root, 0o700); } catch {}
88
+ const staging = join(root, `unpacked.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
89
+ try {
90
+ writeFiles(staging, files);
91
+ // One rename where the system allows it; else the files are written in place (a folder the browser holds open).
92
+ const retired = `${folder}.${randomBytes(6).toString('hex')}.old`;
93
+ let swapped = false;
94
+ try {
95
+ if (present || (() => { try { lstatSync(folder); return true; } catch { return false; } })()) renameSync(folder, retired);
96
+ renameSync(staging, folder); swapped = true;
97
+ } catch {
98
+ try { lstatSync(folder); } catch { try { renameSync(retired, folder); } catch {} }
99
+ }
100
+ if (!swapped) writeFiles(folder, files);
101
+ rmSync(retired, { recursive: true, force: true });
102
+ } finally { rmSync(staging, { recursive: true, force: true }); }
103
+ const record = { v: 1, version, digest, appPort: Number(appPort), preparedAt: now() };
104
+ const temporary = `${markerPath}.${randomBytes(6).toString('hex')}.tmp`;
105
+ writeFileSync(temporary, JSON.stringify(record), { mode: 0o600 }); renameSync(temporary, markerPath);
106
+ } catch (error) {
107
+ if (error?.code === 'EXTENSION_FOLDER_FAILED') throw error;
108
+ throw Object.assign(new Error('The extension folder could not be written.'), { code: 'EXTENSION_FOLDER_FAILED' });
109
+ }
110
+ return { folder, version, changed: true, previousVersion: marker?.version || null, appPort: Number(appPort), stale: false };
111
+ }
112
+ /** What the folder holds now, without writing: { folder, version, prepared }. */
113
+ export function extensionFolderState(home) {
114
+ const root = join(home, 'browser-extension'), marker = readMarker(join(root, 'unpacked.json'));
115
+ return { folder: join(root, 'unpacked'), version: marker?.version || null, prepared: !!marker, appPort: marker?.appPort ?? null, preparedAt: marker?.preparedAt ?? null, root: dirname(join(root, 'unpacked')) };
116
+ }