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,384 @@
1
+ # Agents system: the contracts (phase P0) and durable messaging (phase P2)
2
+
3
+ Phase P0 made four modules that later phases build on. Phase P2 wired the last of them, the coordination store, into the Assistant: its dispatcher and its runtime now talk through `lib/coordination/service.js` (the section [The coordination service](#libcoordinationservicejs-phase-p2) below). The first three are still wired into nothing. This file is the reference for the workers of the phases that follow.
4
+
5
+ | Module | What it is | Tests |
6
+ |---|---|---|
7
+ | `lib/agents/schema.js` | The AgentDefinition contract: shape, canonical form, errors, warnings, revisions, `agent_ref` | `tests/agents-schema.test.mjs` |
8
+ | `lib/agents/density.js` | Agent density: how many workers one task may get, and the wording | `tests/agents-density.test.mjs` |
9
+ | `lib/teams/schema.js` | The team plan: slices, owned paths, dependencies, worktree and branch names | `tests/teams-schema.test.mjs` |
10
+ | `lib/coordination/store.js` | The durable store: events, deliveries, claims, journal, outbox | `tests/coordination-store.test.mjs` |
11
+ | `lib/coordination/service.js` | The one owner of the store while the server runs: run events, the Assistant's mailbox, typed run-event reads, follow-ups, the team channel | `tests/coordination-service.test.mjs` |
12
+ | `lib/assistant-run-wait.js` | `agent_wait`: state waits, typed event waits with a cursor, workflow waits that follow the workflow | `tests/assistant-dispatch-durable.test.mjs` |
13
+ | `lib/assistant-run-tail.js` | A run's transcript tail and the whole text of its last turn on disk, read in pages | `tests/assistant-dispatch-durable.test.mjs` |
14
+
15
+ Run one with `node --test tests/<name>.test.mjs` from `neural-interface/`.
16
+
17
+ The first three are pure (no file, network, git or clock access; `node:path` and `node:crypto` only compute; `agents/schema.js` also imports the tool catalog from `mcp-server/dist`, which is data). The store is the only one that touches the disk. Each validator comes under a short and a long name (`validate` / `validateAgentDefinition`, `normalize` / `normalizeTeamPlan`, …): import the long one where two modules meet in one file.
18
+
19
+ ## Owner decisions these contracts encode
20
+
21
+ Taken with the owner on 2026-11-15; a later phase follows them, it does not reopen them.
22
+
23
+ - **Density starts at Solo.** One worker per task unless the user raises the level. A level is a cap, never a quota.
24
+ - **Agents never use the user's branch or checkout.** Every worker of a team works in its own worktree under `<project>/.worktrees/`, on its own branch. A dirty working tree is therefore not a reason to stop, and nothing is stashed or committed for the user.
25
+ - **The result lands on an integration branch, and the user merges it.** `synabun/<team>/integration`. Nothing is merged into the user's branch by SynaBun unless the owner later allows that.
26
+ - **Agent definitions live in a global library plus per project.** A project's agent of an id wins over the global one.
27
+ - **Only the owner approves an agent definition.** What the Assistant or an agent makes waits in review.
28
+
29
+ ## `lib/agents/schema.js`
30
+
31
+ An agent is a named, reviewed way to launch a worker.
32
+
33
+ ### Fields
34
+
35
+ Content (what the etag covers, `AGENT_CONTENT_FIELDS`):
36
+
37
+ | Field | Type | Notes |
38
+ |---|---|---|
39
+ | `id` | slug | lower-case letters, digits, hyphens, 1 to 64; not one of `RESERVED_AGENT_IDS` |
40
+ | `name` | text | required, one line, at most 80 |
41
+ | `description` | text | at most 400; the Assistant picks agents by it |
42
+ | `instructions` | text | at most 16,000 |
43
+ | `provider` | `claude-code` \| `codex` \| `opencode` \| `antigravity` | required |
44
+ | `model`, `effort` | text \| null | null: the provider default |
45
+ | `accountId` | text \| null | Claude Code and Codex only; `auto` allowed |
46
+ | `tools` | string[] \| null | SynaBun group ids, or `all`. `null`: the worker's default list; `[]`: always-on tools only. Never `mcp:` items, never a gated group (`agents`, `skills`, `computer`), never a group the tool catalog does not have |
47
+ | `mcpServers` | string[] | exact server names (1 to 64 letters, digits, `.`, `_`, `:`, `-`), or `['*']` |
48
+ | `capability` | `read-only` \| `workspace` \| `full` | default `workspace` (the dispatcher's own default is `full`) |
49
+ | `permissionPolicy` | `auto` \| `ask` \| `restricted` | default `auto` |
50
+ | `usesBrowser`, `usesComputer` | boolean | |
51
+ | `moreloginProfile` | text \| null | needs `usesBrowser` |
52
+ | `skills` | string[] | skill names (`name`, `plugin:name`) or library ids (`skl_…`) |
53
+ | `scope` | `{ kind: 'global' }` \| `{ kind: 'project', path }` | `path` absolute, kept normalized |
54
+ | `memoryCategory` | text \| null | a category name |
55
+ | `taskClasses` | string[] | the Assistant's task classes |
56
+ | `icon` | text \| null | an icon name, never markup or a URL |
57
+ | `color` | text \| null | a style-guide token name `group.key` (`status.info`, `primary.500`); a raw colour is refused |
58
+
59
+ Revision metadata (`AGENT_META_FIELDS`): `schemaVersion`, `revision` (from 1), `parentRevision`, `status` (`draft` \| `in_review` \| `approved` \| `withdrawn`), `author` (`{ kind: owner | assistant | agent | system, ref }`), `createdAt`, `approvedAt` (ISO 8601 UTC), `etag` (`sha256:<64 hex>` of the content).
60
+
61
+ ### Exports
62
+
63
+ - `normalize(input)` → a definition with every field, spellings folded (`uses_browser`, `{status.info}`, `mcp:name`), lists de-duplicated and sorted. Never throws. Recomputes the etag.
64
+ - `validate(input, { knownMcpServers, requireMeta })` → `{ ok, errors: [{ field, code, message }], value }`. `value` is the normalized definition, also when `ok` is false. `tools` and `mcpServers` are read by the resolver a dispatch uses (`resolveToolList` of the tool catalog), so what validates is what can start: an unknown group is `unknown_tool` (with what it probably meant), a gated one `gated_tool`. Pass the MCP servers that exist as `knownMcpServers` to refuse unknown names; `requireMeta: true` for a stored revision (needs `createdAt`, and a given `etag` must match the content).
65
+ - `lint(input, { knownTaskClasses, knownSkills, knownColorTokens, knownCategories, knownModels })` → `[{ field, code, message }]`. Never a refusal. Codes include `full_with_browser`, `full_with_computer`, `full_capability`, `empty_instructions`, `empty_description`, `long_instructions`, `unknown_task_class`, `no_task_classes`, `all_tools`, `always_on_tool`, `all_mcp_servers`, `account_ignored`, `read_only_for_code`.
66
+ - Revisions: `AGENT_STATUS_TRANSITIONS`, `canTransition(from, to)`, `isEditable(def)` (draft only), `isRunnable(def)` (approved only), `createDraft(input, { now, base, revision, author })`, `applyTransition(def, to, { now, actor })`. `applyTransition` throws `AgentSchemaError` with `invalid_transition`, `approval_requires_owner` (403) or `not_valid` (with `errors`). The module reads no clock: pass `now`.
67
+ - Review: `privilegesOf(def)`, `privilegeDelta(before, after, { defaultTools })` → `{ escalates, changes: [{ field, from, to, escalates }] }`. `before` null is a first revision. `tools: null` is compared group by group as the catalog's `DEFAULT_TOOLS` (override with `defaultTools`).
68
+ - Runs: `dispatchFields(def)` → the fields a dispatch takes, in the dispatcher's spelling (`provider`, `model`, `effort`, `accountId`, `tools` with `mcp:<name>` appended, `capability`, `permissionPolicy`, `usesBrowser`, `usesComputer`, `moreloginProfile`). The task, cwd, session and budget stay the dispatch's own.
69
+ - Refs: `parseAgentRef(ref)` → `{ id, revision, scope } | null`, `formatAgentRef(parts)`, `resolutionOrder(parsed, projectPath)` (project first, then global), `sameScope(a, b)`. A ref is `<id>`, `<id>@<revision>`, `global:<id>` or `project:<id>@<revision>`.
70
+ - `computeEtag(def)`, `contentOf(def)`, and the constant lists (`AGENT_PROVIDERS`, `AGENT_CAPABILITIES`, `AGENT_PERMISSION_POLICIES`, `AGENT_TASK_CLASSES`, `AGENT_STATUSES`, `AGENT_LIMITS`, …).
71
+
72
+ The provider, task class, capability and permission policy lists are copies; `tests/agents-schema.test.mjs` compares them with `assistant-config.js`, `assistant-router.js` and `mcp-server/src/tools/agents.ts` and fails when one drifts. Tool groups are not copied: the module imports `mcp-server/dist/services/tool-catalog.js` and `tool-list.js` (the catalog is the one table of groups, and `tests/tool-catalog-single-source.test.mjs` fails on a second one anywhere in `lib/`). Never write a list of group ids into an Agents module: ask the catalog (`isBrowserGroup`, `isGatedGroup`, `SELECTABLE_GROUP_IDS`).
73
+
74
+ ### For the registry and resolver phase
75
+
76
+ - Store revisions as written by `createDraft` / `applyTransition`; validate what is read back with `requireMeta: true`.
77
+ - An approved revision is never edited. A change is `createDraft(patch, { base: approved })`, which gets the next revision number and `parentRevision`.
78
+ - Resolve only `isRunnable` revisions, and pin the revision number and etag on the run so a later edit does not change a run under way.
79
+ - `agent_dispatch` already has an `agent` field (OpenCode's native agent). Use a new `agent_ref` field; do not change what `agent` means.
80
+ - A definition with `capability: 'full'` and browser or computer use starts only when the dispatch carries the tag `user-authorized-full` (the dispatcher's existing rule). The resolver must not add that tag by itself.
81
+
82
+ ## `lib/agents/density.js`
83
+
84
+ | Level | Label | Workers on one task |
85
+ |---|---|---|
86
+ | `solo` (default) | Solo | 1 |
87
+ | `pair` | Pair | 2 |
88
+ | `team` | Team | 4 |
89
+ | `swarm` | Swarm | 6 |
90
+
91
+ Exports: `AGENT_DENSITIES`, `DEFAULT_AGENT_DENSITY`, `AGENT_DENSITY_LABELS`, `AGENT_DENSITY_WORKERS`, `MAX_TEAM_WORKERS`, `AGENTS_HEADER` (`[SynaBun Agents]`), `normalize(value, fallback)` (also `normalizeAgentDensity`), `agentDensityLabel(level)`, `maxWorkers(level)`, `allowsTeams(level)`, `clampWorkers(level, requested)`, `fitsDensity(level, workers)`, `densityForWorkers(n)`, `agentDensitySummary(level)`, `agentDensityPersonaLine(level, { where })`, `agentDensityStamp(level)`.
92
+
93
+ It mirrors `assistant-test-density.js` on purpose, so it is wired the same way: a per-session value on the session record (`null` is the default), a `set_agent_density` socket message, the persona line among the Rails, `agentDensityStamp()` sent to a running brain when the level changes, and the cap enforced by the server (`validate` of a team plan with `{ density }`), never by the brain's prompt alone.
94
+
95
+ ## `lib/teams/schema.js`
96
+
97
+ A team is one task given to several workers. Its plan:
98
+
99
+ ```js
100
+ {
101
+ teamId: 'auth-rework', // slug, at most 40
102
+ projectPath: '/Users/me/app', // absolute
103
+ baseCommit: '<40 or 64 hex>', // a full commit id, never a branch name
104
+ slices: [{
105
+ id: 'api', // slug; 'integration' is reserved
106
+ title: 'The API',
107
+ task: 'What this worker is told.',
108
+ agentRef: 'backend@2', // optional (see parseAgentRef)
109
+ ownedPaths: ['src/api/**', 'package.json'],
110
+ dependsOn: [], // slice ids
111
+ lockfileOwner: true, // at most one slice
112
+ }],
113
+ }
114
+ ```
115
+
116
+ `validate(plan, { density, maxSlices })` → `{ ok, errors: [{ field, code, message, … }], value }`, with `field` naming the place (`slices[1].ownedPaths[0]`). It refuses:
117
+
118
+ | Code | Meaning |
119
+ |---|---|
120
+ | `overlapping_paths` | two slices own a common file (`with` names the other slice and pattern) |
121
+ | `dependency_cycle` | the slices wait for each other in a circle (`cycle` lists it) |
122
+ | `multiple_lockfile_owners` | more than one slice has `lockfileOwner: true` |
123
+ | `lockfile_not_owner` | a slice names a lockfile outright without being the lockfile owner |
124
+ | `too_many_slices` | more slices than the density allows (`limit`, `count`). With no `density` and no `maxSlices`, Solo applies: one slice |
125
+ | `path_escape` | an owned path is absolute, starts with `~` or a drive, or has a `..` segment |
126
+ | `reserved_path`, `unsupported_glob`, `invalid_glob` | inside `.git` or `.worktrees`; uses `[ ]`, `{ }` or `!`; malformed |
127
+ | `unknown_dependency`, `self_dependency`, `duplicate`, `reserved`, `required`, `invalid_format`, `invalid_type`, `too_long`, `too_many` | the rest |
128
+
129
+ ### Owned paths
130
+
131
+ Project-relative patterns with forward slashes. `*` and `?` match inside one segment, `**` (a whole segment) any number of segments. Three rules follow from "a file has one owner":
132
+
133
+ - A pattern also owns everything beneath what it matches, like a git pathspec: `src/api` owns `src/api/users.js`.
134
+ - Matching ignores letter case (two names that differ only in case are one file on the default macOS and Windows file systems).
135
+ - Lockfiles (`LOCKFILE_NAMES`, by file name, anywhere in the tree) belong to the lockfile owner and to nobody else. A slice whose pattern merely covers one does not own it; with no lockfile owner in the plan, nobody may change one.
136
+
137
+ ### Exports
138
+
139
+ - `normalize(plan)`, `validate(plan, options)` (also `normalizeTeamPlan`, `validateTeamPlan`).
140
+ - `pathOwner(plan, relPath)` → slice id or null.
141
+ - `integrationOrder(plan)` → slice ids, each after the slices it depends on, otherwise in plan order (deterministic). Throws `TeamPlanError` (`dependency_cycle`, `unknown_dependency`, `duplicate`).
142
+ - `readySlices(plan, finished)` → the slices that can run now.
143
+ - `claimablePaths(plan, sliceId)` → the patterns a slice claims in the store while it works: its owned paths without the ones that name a lockfile (those are owned by rule). Of a valid plan, every slice's claim of them is granted.
144
+ - `dependencyCycle(plan)` → the cycle or null.
145
+ - `worktreePath(projectPath, teamId, sliceId)` → always `<project>/.worktrees/<team>/<slice>`. Throws for a relative project path or an id that is not a slug, so no id can climb out.
146
+ - `worktreesRoot(projectPath)`, `integrationWorktreePath(projectPath, teamId)`, `parseWorktreePath(projectPath, absPath)` → `{ teamId, sliceId } | null`.
147
+ - `branchName(teamId, sliceId)` → `synabun/<team>/<slice>`; `integrationBranchName(teamId)`; `parseBranchName(branch)`.
148
+ - `globsOverlap(a, b)`, `matchesOwnedPath(glob, relPath)`, `normalizeOwnedPath(glob)`, `ownedPathProblem(glob)`, `normalizeRelPath(path)`, `isLockfilePath(path)`, `isTeamSlug(value)`.
149
+ - Constants: `WORKTREES_DIR`, `BRANCH_PREFIX`, `INTEGRATION_SLICE_ID`, `LOCKFILE_NAMES`, `RESERVED_PATH_ROOTS`, `TEAM_LIMITS`, `TEAM_STATES`, `SLICE_STATES`.
150
+
151
+ ### For the worktree and scheduler phases
152
+
153
+ - This module runs no git. The phase that does must check that `<project>/.worktrees/<team>` does not exist before it creates a team: a hand-made worktree may already sit under `.worktrees` with the same name as a team id.
154
+ - `.worktrees/` must be ignored in the project. Add it to `.git/info/exclude` when it is not, never to the project's `.gitignore`.
155
+ - `baseCommit` is what the user's branch pointed at when the plan was made. A dirty working tree does not matter to a team: workers never see it.
156
+ - `TEAM_STATES` and `SLICE_STATES` are the names for the store's journal. The store does not enforce them.
157
+ - A plan with one slice is valid at every level: one worker in a worktree.
158
+
159
+ ## `lib/coordination/store.js`
160
+
161
+ One SQLite file in WAL mode (`node:sqlite`, no new dependency), `DATA_HOME/data/coordination.db` by `coordinationDbPath(dataDir)`. Apart from `memory.db` on purpose. A backup includes it without anything being registered: `backup-service.js` takes a consistent snapshot of every `.db` in the data home. A restore therefore brings back the open events and claims of that time. Phase P2 treats them like a restart: the sessions restored with them are told what was open for them, and what is open for a session that no longer exists is settled.
162
+
163
+ ```js
164
+ const store = createCoordinationStore({ path, now, newId, busyTimeoutMs, synchronous, log, migrations });
165
+ ```
166
+
167
+ Only `path` is required. Everything is synchronous except `waitFor`. Invalid input throws `CoordinationError` (`code`, `status`).
168
+
169
+ ### Event schema
170
+
171
+ | Field | Type | Notes |
172
+ |---|---|---|
173
+ | `id` | text | the caller's, or generated. Appending an existing id stores nothing and returns `duplicate: true` |
174
+ | `seq` | integer | assigned by the store, only ever grows, never reused |
175
+ | `sessionId`, `teamId`, `runId` | text \| null | what the event belongs to |
176
+ | `kind` | text | lower-case, `a.b` style, at most 64 |
177
+ | `priority` | `critical` \| `normal` \| `low` | default: `KIND_PRIORITY[kind]`, else `normal` |
178
+ | `payload` | JSON | at most 256 KB |
179
+ | `createdAt` | ISO 8601 UTC | |
180
+
181
+ `append` also takes `to` (one recipient or a list) and `coalesceKey`. A mailbox read adds `delivery: { recipient, deliveredAt, ackedAt, attempts, redelivered, merged }`.
182
+
183
+ Recipients are plain names. Use `sessionRecipient(id)` → `session:<id>`, `runRecipient(id)` → `run:<id>`, `teamRecipient(id)` → `team:<id>`. The store does not expand groups: whoever appends lists every recipient.
184
+
185
+ Kinds the phases share (`EVENT_KINDS`, with their default priority):
186
+
187
+ | Kind | Priority | | Kind | Priority |
188
+ |---|---|---|---|---|
189
+ | `run.progress` | low | | `team.state` | normal |
190
+ | `run.result` | normal | | `slice.state` | normal |
191
+ | `run.needs_input` | critical | | `slice.progress` | low |
192
+ | `run.permission` | critical | | `claim.conflict` | critical |
193
+ | `run.failed` | critical | | `integration.conflict` | critical |
194
+ | `run.stalled` | critical | | `integration.ready` | normal |
195
+ | `run.interrupted` | critical | | `team.message` | normal |
196
+ | `run.message` | normal | | `session.memory_due` | normal |
197
+ | `run.stopped` | normal | | `route.decided`, `route.expired`, `route.declined` | normal |
198
+ | `run.completed` | normal | | `clarify.answered`, `clarify.declined` | normal |
199
+ | `run.budget` | normal (the cap reached: critical) | | | |
200
+ | `run.notice` | normal | | | |
201
+
202
+ The second half of the list came with phase P2: what the dispatcher emits beyond the first seven, and the Assistant session's own items (a memory reminder, a route card's or a clarify card's outcome).
203
+
204
+ Any other kind of the right form is accepted. Add a shared one to `EVENT_KINDS` and `KIND_PRIORITY` rather than spelling it in two places.
205
+
206
+ ### Delivery semantics
207
+
208
+ - **At-least-once.** An event addressed to a recipient stays open for it until that recipient acknowledges it. Reading does not acknowledge. An open event is handed out again by the next read, also by a store opened on the file after a restart. Consumers must be idempotent; `delivery.redelivered` (attempts above 1) says the event was handed out before.
209
+ - **Idempotent append.** Give every event a deterministic `id` (for example `run:<runId>:turn:<n>:result`). A retry then stores nothing and wakes nobody.
210
+ - **Cursor.** Per recipient, the seq up to which everything addressed to it is acknowledged. It never moves back. `read` starts from it by default.
211
+ - **Order.** `read` is oldest first. `pending` is critical events first (oldest first among themselves), then everything else oldest first.
212
+ - **Coalescing.** `coalesce(recipient)` folds open `low` events that say the same kind of thing (same `coalesceKey`, else same kind, run, team and session) into the newest, which reports how many it stands for in `delivery.merged`. Critical and normal events are never touched, and the log keeps every event.
213
+ - **Wake-ups are not deliveries.** `subscribe` and `waitFor` are called after the transaction that appended an event has committed, in this process only, in seq order. A duplicate id and a rolled-back append wake nobody. What must not be missed is read from the mailbox.
214
+ - **One writer.** The Neural Interface server writes (the `/mcp` endpoint is mounted in it). Another process that opens the file reads and writes safely but is not woken: it passes `pollMs` to `waitFor`.
215
+
216
+ ### API
217
+
218
+ Events and the log:
219
+
220
+ - `append(event)` → `{ id, seq, duplicate }`
221
+ - `appendMany(events)` → the same per event, all in one transaction or none
222
+ - `get(id)` → the event with `to`, or null
223
+ - `events({ afterSeq, teamId, sessionId, runId, runIds, kinds, limit })` → the log, oldest first; delivers nothing. `runIds`: several runs at once (at most 500; an empty list matches nothing)
224
+ - `lastSeq()`
225
+
226
+ The mailbox:
227
+
228
+ - `read({ recipient, afterSeq, kinds, limit, includeAcked, peek })` → open events after `afterSeq` (default: the cursor). Records the delivery unless `peek`.
229
+ - `pending(recipient, { kinds, limit, peek, coalesce })` → everything open, critical first
230
+ - `ack(recipient, eventIds)` → `{ acked, cursor }`; harmless to repeat
231
+ - `ackThrough(recipient, seq)` → `{ acked, cursor }`
232
+ - `cursor(recipient)`
233
+ - `coalesce(recipient)` → `{ merged, kept: [{ id, seq, merged }] }`
234
+ - `openCount(recipient, { kinds, priority })` → how many events the recipient has not acknowledged (hands out nothing)
235
+ - `recipients({ prefix })` → `[{ recipient, open, oldestSeq }]`: who has something open (after a restart: whose mailbox still holds events)
236
+
237
+ Wake-ups:
238
+
239
+ - `subscribe(filter, fn)` → `unsubscribe()`. `filter`: `{ recipient, kinds, priority, teamId, sessionId, runId }`, a predicate `(event, { recipients })`, or null. `fn(event, { recipients })`.
240
+ - `waitFor({ recipient, kinds, afterSeq, timeoutMs, limit, teamId, sessionId, runId, signal, pollMs })` → `Promise<{ events, timedOut, closed, aborted }>`. With `recipient` it waits on the mailbox and reads like `read`; without one it waits on the log for events after `afterSeq` (default: the newest now). Resolves at once when something is there. A timeout resolves with `timedOut: true`, never rejects. Default 30 s, at most 10 minutes. Its timers are unreferenced: a wait nobody answers never keeps a process alive (a server going down, a script that is done); `close()` answers it.
241
+
242
+ Claims (team-scoped; patterns are owned paths of `lib/teams/schema.js`):
243
+
244
+ - `claim({ teamId, sliceId, runId, globs })` (for a planned slice, `globs` is `claimablePaths(plan, sliceId)`) → `{ ok: true, claims }` or `{ ok: false, code: 'CLAIM_CONFLICT', conflicts: [{ glob, heldBy }] }`. All of the patterns are taken or none. A slice re-claiming its own pattern keeps the one claim.
245
+ - `release({ teamId, sliceId, runId, globs })` → `{ released }`; `teamId` alone releases the team's
246
+ - `claimsFor({ teamId, sliceId, runId, path, includeReleased })` → claims; `path` asks who holds a file
247
+
248
+ Journal of team tasks (append-only; the newest entry of a team or slice is its state):
249
+
250
+ - `journal.write({ teamId, sliceId, state, runId, data })` → the entry. No `sliceId`: the team itself. `data` is what recovery needs (the plan, a branch, a commit, an error), at most 64 KB.
251
+ - `journal.read({ teamId, sliceId, afterId, limit })`
252
+ - `journal.state(teamId)` → `{ teamId, team, slices: { [sliceId]: entry } }`
253
+ - `journal.teams({ states })` → each team's newest own entry (after a restart: which teams were under way)
254
+
255
+ Outbox (follow-ups for runs):
256
+
257
+ - `outbox.enqueue({ id, runId, text, sessionId, meta, maxQueued })` → `{ id, duplicate }`. `maxQueued` is the admission bound: with that many of the run's items unsent, nothing is stored and `OUTBOX_FULL` (409, with `queued` and `limit`) is thrown
258
+ - `outbox.take(runId, { limit })` → unsent items in the order they were queued. Taking marks nothing: an item comes back until `markSent` names it.
259
+ - `outbox.markSent(ids)` → `{ sent }`
260
+ - `outbox.count(runId)` → how many are unsent
261
+ - `outbox.cancel({ runId, ids })` → `{ cancelled }`: unsent items leave the queue for good (the run ended before it could take them); sent ones are left alone
262
+ - `outbox.get(id)`, `outbox.runs()` → the runs with something queued
263
+
264
+ Housekeeping:
265
+
266
+ - `prune({ olderThanMs })` → `{ events, claims, outbox }`. Never drops an event somebody has not acknowledged; never prunes the journal.
267
+ - `stats()`, `appliedMigrations()`, `close()` (answers every waiter with `closed: true`; safe to call twice), `closed`.
268
+
269
+ ### Schema
270
+
271
+ Tables: `events`, `deliveries`, `cursors`, `claims`, `team_tasks`, `outbox`, `migrations`. Version 1 is `MIGRATIONS[0]`. A change is a new entry appended to `MIGRATIONS` with the next version; an entry that shipped is never edited. A file written by a newer SynaBun is refused (`SCHEMA_NEWER`) and left as it is; a migration that fails is rolled back (`MIGRATION_FAILED`).
272
+
273
+ ### For the phases that use it
274
+
275
+ - Go through the service (`lib/coordination/service.js`), not through a second store on the file: it is the one owner while the server runs, and `server.js` shares it (`shareCoordinationService`). A module that needs the store itself (claims, the journal) takes `service.store`.
276
+ - A worker's MCP `wait` is `service.team.wait(…)` (or `store.waitFor({ recipient: runRecipient(runId), … })`) with the tool's own cap; keep it under the MCP client's request timeout as `agent_wait` does (50 s default).
277
+ - Never append inside another module's SQLite transaction or state lock, and never call a model while holding one of this store's transactions (there is no way to: every method returns before it could).
278
+ - Tests open the store on a temporary file, or in memory (`path` is injectable; a service made with no path lives in memory). Never point a test at `DATA_HOME`.
279
+ - No schema change came with phase P2: version 1 is still the only migration. The next one is `MIGRATIONS[1]`.
280
+
281
+ ## `lib/coordination/service.js` (phase P2)
282
+
283
+ The Assistant's mailbox was a list in the runtime's memory: batched for a fixed 2 s, cut at 40 items whatever they were, gone at a restart, removed before the turn that carried it had started. `agent_wait until:"event"` fired on any change of a run, follow-ups for a busy or suspended run sat in arrays, and a run's transcript tail died with its worker. Phase P2 replaced all of that with the store, behind one service.
284
+
285
+ ```js
286
+ const service = createCoordinationService({ dataDir }); // or { path }, or { store }; nothing: in memory
287
+ shareCoordinationService(service); // server.js: the dispatcher and the runtime take it by themselves
288
+ ```
289
+
290
+ `server.js` has one block (marked `Agents P2`) that creates it on `DATA_HOME/data/coordination.db`, shares it and keeps it in `_assistantCoordination`: the one instance of the server (a test reads `server.js` and fails on a second `createCoordinationService(`). It is closed on every stop path: on SIGINT / SIGTERM after the Assistant's own shutdown handlers, and at the end of the graceful shutdown (Restart Server, `/api/server/shutdown`, an update) once the workers are suspended or stopped and before the memory database closes; closing twice does nothing. A crash leaves the write-ahead log, which the next open reads back. The later team scheduler takes this service's `store` for `createTeams({ store })` (`lib/teams/`): claims, the journal, the team channel and the run events are then one file at one schema version (`tests/agents-integration-seams.test.mjs`). A dispatcher or a runtime that is given no service and finds none shared keeps one in memory (tests). A file that cannot be opened (damaged, or written by a newer SynaBun) is left as it is and replaced by a store in memory, with a warning: `service.degraded` says why, `service.durable` is false.
291
+
292
+ ### What is wired
293
+
294
+ | Where | What |
295
+ |---|---|
296
+ | `assistant-dispatch.js` `emit` | `service.recordDispatch(payload)` before the broadcast and the listeners: the event is in the log in the step that changed the run |
297
+ | `assistant-dispatch.js` `wait` | `createRunWaits` (`assistant-run-wait.js`): `until:"event"` reads typed events after a cursor; a workflow's runs are looked up at every check |
298
+ | `assistant-dispatch.js` `sendTurn`, the turn loop, `resumeRun`, `notResumed`, `stop`, `finalize` | follow-ups go through `service.followUps` (the outbox) |
299
+ | `assistant-dispatch.js` `transcript`, `pushRingLine`, `finalize` | `createRunTailStore` (`assistant-run-tail.js`): the tail and the last turn's text on disk |
300
+ | `assistant-runtime.js` mailbox section | `service.mailbox`: the mailbox is the open events of `session:<id>` |
301
+ | `assistant-api.js` `/wait`, `/runs/:id/wait`, `/runs/:id/transcript` | pass `afterSeq`, `kinds`, `offset`; settle what a brain read with an event wait |
302
+ | `mcp-server/src/tools/agents.ts` | `agent_wait` `after_seq` / `kinds` (and `run_ids` up to 50), `agent_read` `offset` |
303
+
304
+ ### Run events
305
+
306
+ `service.recordDispatch(payload)` takes the dispatcher's `{ type: 'assistant:dispatch', reason, run, … }` and appends one event. It never throws (a failure is logged and answered with null: the run goes on).
307
+
308
+ | Dispatcher reason | Kind | Priority | Told to the owning session |
309
+ |---|---|---|---|
310
+ | `turn_completed` | `run.result` | normal | yes (not when the turn ended asking: `needs_input` carries it) |
311
+ | `needs_input` | `run.needs_input` | critical | yes |
312
+ | `permission_request` | `run.permission` | critical | yes |
313
+ | `failed` | `run.failed` | critical | yes |
314
+ | `interrupted` | `run.interrupted` | critical | yes |
315
+ | `stalled` | `run.stalled` | critical | yes |
316
+ | `budget_exceeded` | `run.budget` | critical | yes |
317
+ | `budget_warning`, `budget_unpriced` | `run.budget` | normal | yes |
318
+ | `stopped` | `run.stopped` | normal | only for a stop by the user, a budget or the work-time cap (`time_cap`: the cap's timer, or a queued follow-up dropped because the work time is used up) (`MAILBOX_STOP_REASONS`); its `text` names the follow-ups that were never delivered |
319
+ | `user_intervened` | `run.notice` | normal | yes |
320
+ | `queue_started`, `suspended`, `resumed` | `run.progress` | low | yes (folded per run) |
321
+ | `completed` | `run.completed` | normal | no (its result came as `run.result`) |
322
+ | everything else (`turn_started`, `idle`, `running`, `follow_up_queued`, `memory_stored`, `tools_changed`, …) | `run.progress` | low | no: logged only |
323
+
324
+ - **Stable ids.** `runEventId(payload)`: a turn's result is `run:<runId>:turn:<n>:result`, its question `run:<runId>:turn:<n>:needs_input`, a relayed request `run:<runId>:request:<requestId>`, anything else `run:<runId>:<reason>:v<version>:<updatedAt>` (the run's version and time of that change). Recording the same event again stores nothing. The runtime records every dispatcher event it hears too: with the shared service that is always a duplicate, and it is what makes a dispatcher without the service (a test's stand-in) work.
325
+ - **Payload.** The mailbox item of that reason, small: `kind` (what the brain reads: `result`, `needs_input`, `failed`, …), `reason`, `turn`, `taskId`, `summary` (400 characters), `question`, `files` (50), `follow_ups` (10), `request`, `error`, `text`, `unverified`, `resultSource`, `media`, and `run`: a brief (`runBrief`: id, provider, model, title, state, outcome, completion reason, cost, memory flag, workflow, limit, escalation, and for a run that runs as an agent its `agentRef` and `agentRevision`, from the run's first event on; a plain worker's brief has neither key, and the pin's detail and the role block never ride in an event). An event wait's events (`eventBrief`) carry `agentRef` too. Never the worker's text or its turns: a run view is tens of kilobytes, an event a few hundred bytes.
326
+ - `service.runEvents({ runIds, afterSeq, kinds, limit })` → the events of those runs after a position, oldest first, as `eventBrief` (`seq`, `id`, `kind`, `priority`, `runId`, `at`, and `reason`, `turn`, `summary`, `question`, `error`, `text`, `state`, `outcome`, `request` when there). Reads the log: nothing is delivered or acknowledged, so the same position gives the same events again.
327
+ - `RUN_WAIT_KINDS`: what an event wait takes when no kinds are named (everything but `run.progress`). `RUN_EVENT_KINDS`: every kind a run's events are logged as. `mcp-server/src/tools/agents.ts` carries a copy; `tests/coordination-service.test.mjs` fails when one drifts.
328
+
329
+ ### The mailbox
330
+
331
+ `service.mailbox`, per Assistant session (`session:<id>`):
332
+
333
+ - `post(sessionId, item, { id, kind, priority, runId, coalesceKey })` → `{ id, seq, duplicate, kind, priority }`. For what is not a run's own event: `memory_due`, `route_decided` / `route_expired` / `route_declined`, `clarify_answered` / `clarify_declined`. `item.kind` picks the event kind (`MAILBOX_ITEM_KINDS`; unknown: `session.notice`). `item.run` is cut down to a brief.
334
+ - `pending(sessionId, { limit, peek })` → `{ items, more }`: critical first, then oldest first, low-priority progress folded (`merged` on the newest). At most `limit` (default 30) items; `more` is how many stay open. Each item is the event's payload plus `eventId`, `seq`, `eventKind`, `priority`, `at`, and `redelivered` when it was handed out before.
335
+ - `ack(sessionId, eventIds)`, `count(sessionId, { priority })`, `discard(sessionId, match)` (settle without telling: a removed run, a request answered elsewhere, a result the brain read itself; `match` null: everything), `sessions()` (who has something open), `subscribe(fn)` (`fn(sessionId, event)` after an append committed).
336
+
337
+ How the runtime uses it (`assistant-runtime.js`, the mailbox section):
338
+
339
+ - **No batch window.** A critical event schedules its turn with no timer (`pumpSoon`); it starts as soon as the session is free (measured on a file-backed store: 0.4 to 2.4 ms from the event to the brain's turn, 101.5 ms for a result; both took 2,000 ms). Every other event waits `mailboxDebounceMs` (default 100, never above 150; `mailboxBatchMs`, the old 2 s setting, is read as this) so results that arrive together go in one turn. A critical event inside that window takes the waiting ones with it, at once.
340
+ - **Busy.** While a turn runs, or a plan card is open, nothing is delivered and nothing is handed out: events wait in the store and go when the session is free (the turn's end pumps; `busyRecheckMs` covers a brain that frees up without one).
341
+ - **Acknowledged after the start.** The turn is composed from `pending`, sent with `runQuery`, and only `{ ok: true }` (the brain took the prompt) acknowledges its events. A refusal, a failure or `ASSISTANT_BUSY` leaves every one of them open. After a failed start the turn is tried again (`mailboxRetryDelaysMs`, default 1 s, 5 s, 30 s), then the mailbox holds until a turn of the session ends, a new event arrives or the budget changes: it never spins.
342
+ - **A restart.** Open events stay in the file. Once the server answers its workers (`dispatcher.whenServerReady()`, then `mailboxBootDelayMs`), every session with something open is delivered again. A session that was removed has its events settled; one the user closed keeps them until it is opened again (and a closed session stays closed across a graceful restart).
343
+ - **Duplicates.** An event has one id and one delivery per session: appended twice it is one event, acknowledged it is never handed out again. A result the brain read with `agent_wait`, `agent_read` or `agent_status` (the dispatcher's delivery mark) is settled when it is recorded and again before a turn is composed; events it read with `agent_wait until:"event"` are settled by their ids once the answer is out.
344
+ - **Depth.** Nothing is dropped for being many. A message carries at most `mailboxItems` (30) events and says how many follow; the rest go in the next turn. `live.mailbox` in the runtime is a look at the store (`pending` with `peek`), kept for diagnostics and tests; nothing is stored on the session.
345
+ - `mailboxAuto: false` (a test setting) stops the scheduler from starting mailbox turns; `_internals.deliverMailbox(live)` starts one.
346
+
347
+ ### Run waits (`lib/assistant-run-wait.js`)
348
+
349
+ `dispatcher.wait({ runId, runIds, workflowId, assistantSessionId, until, mode, timeoutMs, afterSeq, kinds, unseenFor })`:
350
+
351
+ - `until: 'idle' | 'terminal'` read the runs' state as before. The answer gained `cursor` (the log's newest seq), nothing else changed.
352
+ - `until: 'event'` waits for typed events. `kinds` narrows them (default `RUN_WAIT_KINDS`; an unknown kind is `INVALID_KINDS`, 400). `afterSeq` is the cursor of an earlier answer (`INVALID_CURSOR` when it is not a whole number from 0). Without one the wait starts at the newest event, or, with `unseenFor: <sessionId>` (the API passes the asking brain's session), at the oldest event of those runs that session has not been told yet. The answer adds `events` (at most 50, with their `seq`) and `cursor`: pass it back to go on from there.
353
+ - `mode` defaults to `'any'` for an event wait (the next event of any of the runs) and to `'all'` for a state wait (a barrier).
354
+ - A run that ended always answers an event wait. One that waits for a decision (`awaiting_permission`, `awaiting_route`) answers at once only without a cursor; with one, only what is new does, so a caller that saw the request does not spin.
355
+ - A workflow's members are looked up at every check and at the answer: a run dispatched into it after the wait began is waited for. One wait follows at most 200 runs (it used to take 20 and ignore the rest); `notWaitedFor` says how many were left out, `TOO_MANY_RUNS` refuses a longer explicit list.
356
+
357
+ ### Follow-ups
358
+
359
+ `service.followUps`: `enqueue({ runId, text, sessionId, origin, taskId, at, id })` → `{ id, duplicate, position }` (throws `OUTBOX_FULL` past `followUpsPerRun`, 20), `next(runId)` (the oldest unsent, or null), `markSent(ids)`, `count(runId)`, `cancel(runId, ids)` → the items, `runs()`.
360
+
361
+ In the dispatcher every follow-up goes through it, also one an idle run takes at once: `sendTurn` queues it and wakes the turn loop, which takes the oldest unsent item. It is marked sent in `runInnerTurn` right before the provider is handed the prompt, so a restart from then on continues that turn (`resumeInfo.inFlight`) and never sends the text twice; one that was taken but not handed over yet comes back. `sendTurn` answers with `followUpId`, and refuses the 21st waiting follow-up with `FOLLOW_UP_QUEUE_FULL` (409, `queued`, `limit`). A run that ends, is stopped or does not resume has its unsent follow-ups cancelled, and its notes say how many and quote the first; at a start, follow-ups queued for runs that are gone or ended are cancelled the same way (`settleOrphanFollowUps`).
362
+
363
+ ### Transcripts (`lib/assistant-run-tail.js`)
364
+
365
+ `<dataDir>/run-tails/<run>.tail.json` holds the run's last transcript lines (the dispatcher's ring; written at most once a second while it works, and when it ends); `<run>.text.json` the whole text of its last turn (at most 1,000,000 characters). `transcript(runId, { format, tail, maxChars, offset })` reads a live run's ring, else the file, so `agent_read` `tail` works after the run ended and after a restart, and a resumed run's tail goes on where it was. `offset` pages the text of `text` and `tail`: without it the answer is the END of the text (as before) with `offset` (where that page starts), `totalChars` and `nextOffset: null`; with it the page starts there and `nextOffset` is where the next one starts. The files go with the run when the registry drops it (and a sweep a while after each start).
366
+
367
+ ### The team channel: what the `team` tool sits on
368
+
369
+ Phase P4 exposed it: a team slice's worker reaches it through the MCP `team` tool, `/api/assistant/team/*` and the team scheduler's `post` / `read` / `wait` / `ack` (`lib/teams/scheduler.js`; `docs/agents.md` → Teams → The tools). `service.team` is the API under it; it is tested (`tests/coordination-service.test.mjs`).
370
+
371
+ - A team has a **lead** mailbox, `teamRecipient(teamId)` (`team:<id>`: the scheduler, the integrator, or the Assistant session that runs the team), and one mailbox per **member**, `teamMemberRecipient(teamId, runId)` (`team:<id>:run:<runId>`). A member's mailbox holds that team's messages for that run and nothing else, so reading, waiting and acknowledging are scoped by team and run by construction; the same run in another team has another mailbox.
372
+ - `team.post({ teamId, fromRunId, to, members, kind, text, payload, priority, id, sessionId })` → `{ id, seq, duplicate, recipients }`. `to`: `'all'` (default: every other member and the lead, never the sender), `'lead'`, a run id or a list. `members`: the team's runs when the caller knows them; default `team.members(teamId)`, the runs the journal's newest slice entries name (the worktree phase writes those). `kind` defaults to `team.message`; `text` is at most 8,000 characters; `payload` is merged into the event's payload beside `from` and `text`. Give retries an `id`.
373
+ - `team.read({ teamId, runId, afterSeq, kinds, limit, peek })` → the member's events after a position (default: its cursor), oldest first; no `runId`: the lead's. Reading acknowledges nothing.
374
+ - `team.wait({ teamId, runId, afterSeq, kinds, timeoutMs, limit, signal })` → `{ events, timedOut, closed, aborted }`, like the store's `waitFor`.
375
+ - `team.ack({ teamId, runId, eventIds })` or `{ throughSeq }` → `{ acked, cursor }`. `team.cursor({ teamId, runId })`.
376
+ - `team.log({ teamId, afterSeq, kinds, limit })` → everything said in the team, whoever it was for (a timeline; delivers nothing).
377
+
378
+ What that phase had to decide, and did (`lib/teams/scheduler.js`): the caller is its run's proven pin and its team is the scheduler's record of that run, never an argument; a worker that waits warm gets a message as a follow-up (`dispatcher.sendTurn`, origin `peer`) and a working one keeps it in its mailbox until its next `team` call or the end of its turn; a post to the lead is a `team_message` event of the session's mailbox (kind `team.lead_message`; the scheduler appends it itself, with the team's id, rather than through `MAILBOX_ITEM_KINDS`); posts are counted per worker; a team run's record carries `teamId`, so its events are in `team.log`. The list as it was written for that phase:
379
+
380
+ - **Who may post as whom.** The service trusts `fromRunId`. The tool must take the caller's run from its proven pin (`X-Synabun-Terminal` with its proof, as `runReadAllowed` in `assistant-api.js` does) and its team from the journal, never from an argument.
381
+ - **Reaching a worker.** A message in a member's mailbox wakes nobody by itself: a worker reads at its `wait` call. To put text into a worker's conversation instead, use `dispatcher.sendTurn(runId, text)` (the outbox; bounded at 20 per run).
382
+ - **The lead.** For a team the Assistant runs, post `to: 'lead'` events also into the session's mailbox (`service.mailbox.post(sessionId, { kind: … })`) when the brain must react, with a kind added to `MAILBOX_ITEM_KINDS` and to `formatMailbox` in `assistant-persona.js`. `claim.conflict` and `integration.conflict` are critical already.
383
+ - **Limits.** No rate limit, no per-team quota and no pruning of read team messages beyond the store's `prune` (settled events older than 14 days). Add what the tool needs.
384
+ - **Run events of a team's runs** carry no `teamId` today (the dispatcher's run view has none). Once a run record knows its team, set `run.teamId` and `recordDispatch` stores it, so `team.log` shows the runs' results in the channel.