synabun 2.3.0 → 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 (367) hide show
  1. package/CHANGELOG.md +38 -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 +1174 -47
  103. package/neural-interface/i18n/pt-BR.json +1174 -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-profiles.js +1 -1
  135. package/neural-interface/lib/browser-tool-policy.js +1 -1
  136. package/neural-interface/lib/claude-account-links.js +301 -0
  137. package/neural-interface/lib/claude-accounts.js +45 -20
  138. package/neural-interface/lib/claude-agent-bridge.js +142 -10
  139. package/neural-interface/lib/claude-model-catalog.js +6 -0
  140. package/neural-interface/lib/claude-panel-session.js +33 -0
  141. package/neural-interface/lib/cli-install-api.js +23 -0
  142. package/neural-interface/lib/codex-accounts.js +67 -24
  143. package/neural-interface/lib/coordination/README.md +384 -0
  144. package/neural-interface/lib/coordination/service.js +563 -0
  145. package/neural-interface/lib/coordination/store.js +1138 -0
  146. package/neural-interface/lib/db.js +22 -1
  147. package/neural-interface/lib/editor-completion-opencode.js +4 -3
  148. package/neural-interface/lib/effort-levels.js +10 -1
  149. package/neural-interface/lib/maritaca/opencode-proxy.js +7 -2
  150. package/neural-interface/lib/maritaca/opencode.js +35 -0
  151. package/neural-interface/lib/memory-list-page.js +49 -0
  152. package/neural-interface/lib/memory-list-stamp.js +60 -0
  153. package/neural-interface/lib/morelogin-outside-close.js +186 -0
  154. package/neural-interface/lib/morelogin-profile-failures.js +206 -0
  155. package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
  156. package/neural-interface/lib/morelogin.js +219 -7
  157. package/neural-interface/lib/native-loop-runtime.js +24 -1
  158. package/neural-interface/lib/opencode-build-preflight.js +116 -0
  159. package/neural-interface/lib/opencode-launch-error.js +13 -0
  160. package/neural-interface/lib/opencode-native-boundary.js +800 -84
  161. package/neural-interface/lib/opencode-serve-probe.js +426 -0
  162. package/neural-interface/lib/opencode-serve-records.js +14 -9
  163. package/neural-interface/lib/opencode-serve-scan.js +108 -0
  164. package/neural-interface/lib/page-session.js +1 -1
  165. package/neural-interface/lib/peer-identity.js +60 -21
  166. package/neural-interface/lib/process-identity.js +235 -7
  167. package/neural-interface/lib/request-gate.js +3 -0
  168. package/neural-interface/lib/screenshot-location.js +33 -0
  169. package/neural-interface/lib/skills/creation.js +1 -1
  170. package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
  171. package/neural-interface/lib/studio-attention.js +56 -0
  172. package/neural-interface/lib/teams/README.md +382 -0
  173. package/neural-interface/lib/teams/api.js +287 -0
  174. package/neural-interface/lib/teams/brief.js +185 -0
  175. package/neural-interface/lib/teams/claims.js +315 -0
  176. package/neural-interface/lib/teams/git.js +293 -0
  177. package/neural-interface/lib/teams/index.js +122 -0
  178. package/neural-interface/lib/teams/integration.js +580 -0
  179. package/neural-interface/lib/teams/landing.js +184 -0
  180. package/neural-interface/lib/teams/recovery.js +256 -0
  181. package/neural-interface/lib/teams/scheduler.js +1474 -0
  182. package/neural-interface/lib/teams/schema.js +559 -0
  183. package/neural-interface/lib/teams/state.js +181 -0
  184. package/neural-interface/lib/teams/test-runner.js +86 -0
  185. package/neural-interface/lib/teams/test-sandbox.js +99 -0
  186. package/neural-interface/lib/teams/worktrees.js +757 -0
  187. package/neural-interface/lib/tool-permission-choices.js +226 -0
  188. package/neural-interface/lib/whatsapp/cards.js +24 -10
  189. package/neural-interface/lib/worker-confinement.js +206 -6
  190. package/neural-interface/lib/worker-mcp-channel.js +38 -1
  191. package/neural-interface/package-lock.json +4 -2
  192. package/neural-interface/package.json +3 -1
  193. package/neural-interface/public/extension-setup.html +107 -0
  194. package/neural-interface/public/index.html +52 -12
  195. package/neural-interface/public/shared/agent-runtime-options.js +3 -1
  196. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
  197. package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
  198. package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
  199. package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
  200. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
  201. package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
  202. package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
  203. package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
  204. package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
  205. package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
  206. package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
  207. package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
  208. package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
  209. package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
  210. package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
  211. package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
  212. package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
  213. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
  214. package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
  215. package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
  216. package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
  217. package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
  218. package/neural-interface/public/shared/agy/agy-panel.js +142 -28
  219. package/neural-interface/public/shared/agy/agy-styles.js +25 -5
  220. package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
  221. package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
  222. package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
  223. package/neural-interface/public/shared/assistant/asst-control.js +3 -0
  224. package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
  225. package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
  226. package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
  227. package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
  228. package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
  229. package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
  230. package/neural-interface/public/shared/assistant/asst-render.js +36 -6
  231. package/neural-interface/public/shared/assistant/asst-route.js +78 -12
  232. package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
  233. package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
  234. package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
  235. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
  236. package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
  237. package/neural-interface/public/shared/assistant/asst-state.js +66 -1
  238. package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
  239. package/neural-interface/public/shared/assistant/route-identity.js +16 -0
  240. package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
  241. package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
  242. package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
  243. package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
  244. package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
  245. package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
  246. package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
  247. package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
  248. package/neural-interface/public/shared/code-copy.js +120 -0
  249. package/neural-interface/public/shared/constants.js +7 -0
  250. package/neural-interface/public/shared/context-menu-model.js +1 -0
  251. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  252. package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
  253. package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
  254. package/neural-interface/public/shared/cp/cp-styles.js +9 -0
  255. package/neural-interface/public/shared/dom-change-flag.js +66 -0
  256. package/neural-interface/public/shared/dom-morph.js +124 -0
  257. package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
  258. package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
  259. package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
  260. package/neural-interface/public/shared/html-shell.js +33 -4
  261. package/neural-interface/public/shared/i18n.js +14 -1
  262. package/neural-interface/public/shared/idle-queue.js +78 -0
  263. package/neural-interface/public/shared/iface-config.js +227 -0
  264. package/neural-interface/public/shared/lazy-module.js +108 -0
  265. package/neural-interface/public/shared/memory-list.js +117 -0
  266. package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
  267. package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
  268. package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
  269. package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
  272. package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
  273. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
  274. package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
  275. package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
  276. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
  277. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
  278. package/neural-interface/public/shared/opencode-verify-view.js +175 -0
  279. package/neural-interface/public/shared/schedules-view.js +2 -2
  280. package/neural-interface/public/shared/session-project-items.js +11 -0
  281. package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
  282. package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
  283. package/neural-interface/public/shared/settings/settings-ia.js +4 -2
  284. package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
  285. package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
  286. package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
  287. package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
  288. package/neural-interface/public/shared/sidepanel-shown.js +73 -0
  289. package/neural-interface/public/shared/storage.js +6 -1
  290. package/neural-interface/public/shared/studio-attention.js +83 -0
  291. package/neural-interface/public/shared/styles.css +713 -61
  292. package/neural-interface/public/shared/term-browser-tabs.js +34 -0
  293. package/neural-interface/public/shared/transcript-rows.js +334 -0
  294. package/neural-interface/public/shared/tray-auto-close.js +106 -0
  295. package/neural-interface/public/shared/ui-agents.js +97 -0
  296. package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
  297. package/neural-interface/public/shared/ui-automation-studio.js +3 -3
  298. package/neural-interface/public/shared/ui-claude-panel.js +162 -95
  299. package/neural-interface/public/shared/ui-code-copy.js +256 -0
  300. package/neural-interface/public/shared/ui-codex-panel.js +14 -10
  301. package/neural-interface/public/shared/ui-context-menu.js +1 -1
  302. package/neural-interface/public/shared/ui-file-explorer.js +2 -3
  303. package/neural-interface/public/shared/ui-games.js +1 -1
  304. package/neural-interface/public/shared/ui-loading.js +12 -1
  305. package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
  306. package/neural-interface/public/shared/ui-menubar.js +23 -0
  307. package/neural-interface/public/shared/ui-native-loop-router.js +1 -1
  308. package/neural-interface/public/shared/ui-navbar.js +15 -9
  309. package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
  310. package/neural-interface/public/shared/ui-opencode-verify.js +120 -0
  311. package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
  312. package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
  313. package/neural-interface/public/shared/ui-sessions.js +3 -3
  314. package/neural-interface/public/shared/ui-settings-entry.js +55 -0
  315. package/neural-interface/public/shared/ui-settings.js +372 -402
  316. package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
  317. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
  318. package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
  319. package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
  320. package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
  321. package/neural-interface/public/shared/ui-styleguide.js +10 -2
  322. package/neural-interface/public/shared/ui-sync.js +5 -0
  323. package/neural-interface/public/shared/ui-terminal.js +13 -9
  324. package/neural-interface/public/shared/ui-tooltip.js +28 -7
  325. package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
  326. package/neural-interface/public/shared/ui-tray-columns.js +375 -0
  327. package/neural-interface/public/shared/ui-whiteboard.js +51 -6
  328. package/neural-interface/public/shared/ui-worker-end.js +28 -1
  329. package/neural-interface/public/shared/ui-workspaces.js +13 -0
  330. package/neural-interface/public/shared/window-keys.js +71 -0
  331. package/neural-interface/public/variant/2d/main.js +2 -0
  332. package/neural-interface/public/variant/3d/app.js +620 -0
  333. package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
  334. package/neural-interface/public/variant/3d/main.js +21 -544
  335. package/neural-interface/public/variant/3d/map-controls.js +4 -2
  336. package/neural-interface/public/vendor/fonts/fonts.css +508 -0
  337. package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
  338. package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
  339. package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
  340. package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
  341. package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
  342. package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
  343. package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
  344. package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
  345. package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
  346. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
  347. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
  348. package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
  349. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  350. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
  351. package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
  352. package/neural-interface/public/vendor/fonts/manifest.json +142 -0
  353. package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
  354. package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
  355. package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
  356. package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
  357. package/neural-interface/scripts/boot-graph.mjs +270 -0
  358. package/neural-interface/scripts/vendor-fonts.mjs +124 -0
  359. package/neural-interface/server.js +1164 -157
  360. package/npm-shrinkwrap.json +2 -2
  361. package/package.json +3 -1
  362. package/skills/agent-forge/SKILL.md +182 -0
  363. package/skills/agent-forge/evals/evals.json +56 -0
  364. package/skills/agent-forge/references/definition-fields.md +61 -0
  365. package/skills/agent-forge/references/examples.md +105 -0
  366. package/skills/agent-forge/references/instructions.md +51 -0
  367. package/skills/agent-forge/references/review-and-export.md +84 -0
@@ -0,0 +1,580 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: finishing a slice and joining it on the integration branch
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A slice's worker leaves its changes in the slice's worktree. What happens next is the server's, in three steps:
6
+ //
7
+ // finishSlice commits the slice's own files on the slice's branch (the worker does not use git to write: see
8
+ // lib/worker-confinement.js), then checks after the fact what the branch changed against what the
9
+ // slice owns. A slice that changed anything else is `rejected`: nothing of it is joined.
10
+ // integrate takes a finished slice's commits onto the integration branch, in the team's integration
11
+ // worktree, by cherry-pick; runs the team's test command on exactly that commit; and only then
12
+ // calls the slice `integrated`. A slice is joined after the slices it depends on.
13
+ // resolveInSlice after a conflict: brings the integration branch into the slice's worktree and leaves the
14
+ // conflicts there for the slice's owner. Finishing the slice again commits the result.
15
+ //
16
+ // Nothing is ever resolved by force:
17
+ // - a conflict stops the join, the cherry-pick is aborted, the integration worktree is exactly as before, the
18
+ // slice is `conflict`, and the answer is a report of the files and both sides (the commit and slice on the
19
+ // integration branch, the commit of the slice, the three versions' ids, the first conflict of each file);
20
+ // - failed tests take the integration branch back to the commit before the join (the last good one), the slice is
21
+ // `tests-failed`, and the answer has the end of the test output.
22
+ //
23
+ // Every step is written to the store's journal before and after it runs (`integrating` with what is under way), so
24
+ // recover() can bring a team back from a crash in the middle of any of them (lib/teams/recovery.js).
25
+ //
26
+ // The commits SynaBun makes use the repository's own identity (user.name / user.email, as the user's commits do),
27
+ // carry `SynaBun-Team` and `SynaBun-Slice` trailers, are not signed, and run no hook.
28
+
29
+ import { existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs';
30
+ import { join, resolve } from 'node:path';
31
+ import { EVENT_KINDS } from '../coordination/store.js';
32
+ import { branchName, integrationBranchName, integrationOrder, integrationWorktreePath, pathOwner, worktreePath } from './schema.js';
33
+ import { gitOutput, gitSaid, identityEnv, line, nulList, operationsUnderWay, parseIndexEntries } from './git.js';
34
+ import { TERMINAL_TEAM_STATES, planSlice, refuse, sliceState } from './state.js';
35
+ import { branchAt, changesOf, commitOf } from './worktrees.js';
36
+
37
+ const isDirectory = (path) => { try { return lstatSync(path).isDirectory(); } catch { return false; } };
38
+ const exists = (path) => existsSync(path);
39
+ const realOf = (path) => { try { return realpathSync(path); } catch { return resolve(path); } };
40
+ /** Slice states a slice can be finished from: a worker has been at it. */
41
+ const FINISHABLE = new Set(['running', 'done', 'rejected', 'conflict', 'tests-failed']);
42
+ const LIST_CAP = 120;
43
+ const cap = (list, n = LIST_CAP) => (list.length > n ? [...list.slice(0, n), { more: list.length - n }] : list);
44
+ const short = (text, n = 400) => String(text ?? '').slice(0, n);
45
+
46
+ /** Does this file still have the markers git writes into a conflict? */
47
+ function hasConflictMarkers(file) {
48
+ try {
49
+ const text = readFileSync(file, 'utf8');
50
+ return /^<{7} /m.test(text) && /^>{7} /m.test(text);
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ /** The first conflict of a file, markers included, bounded. */
57
+ function firstConflict(file, limit = 1500) {
58
+ try {
59
+ const text = readFileSync(file, 'utf8');
60
+ const from = text.search(/^<{7} /m);
61
+ if (from < 0) return null;
62
+ const rest = text.slice(from);
63
+ const end = rest.search(/^>{7} .*$/m);
64
+ const upTo = end < 0 ? rest.length : end + (rest.slice(end).indexOf('\n') + 1 || rest.length - end);
65
+ return rest.slice(0, Math.min(upTo, limit));
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * @param {object} deps
73
+ * @param {object} deps.store a coordination store
74
+ * @param {object} deps.state createTeamState(...)
75
+ * @param {Function} deps.git createGitRunner(...)
76
+ * @param {object} deps.locks createLocks()
77
+ * @param {object} deps.claims createTeamClaims(...)
78
+ * @param {Function} deps.runTests the test-command runner: `({ cwd, command, commit, teamId, sliceId, projectPath })
79
+ * => Promise<{ ok, exitCode?, output?, durationMs? }>` (default: lib/teams/test-runner.js)
80
+ * @param {{ name: string, email: string }|null} [deps.identity] who SynaBun's commits are by (default: the repository's own)
81
+ * @param {() => number} [deps.now]
82
+ * @param {(tag: string, detail: any) => void} [deps.log]
83
+ */
84
+ export function createTeamIntegration({ store, state, git, locks, claims, runTests, identity = null, now = Date.now, log = () => {} } = {}) {
85
+ const teamKey = (teamId) => `team:${teamId}`;
86
+ const sliceKey = (teamId, sliceId) => `slice:${teamId}/${sliceId}`;
87
+ const isAncestor = async (cwd, older, newer) => (await git(['merge-base', '--is-ancestor', older, newer], { cwd })).ok;
88
+
89
+ function announce(kind, teamId, payload) {
90
+ try { store.append({ teamId, kind, payload }); } catch (error) { log('teams:announce-failed', { teamId, error: error?.message || String(error) }); }
91
+ }
92
+
93
+ /** The record and the slice, or the refusal. */
94
+ function load(teamId, sliceId) {
95
+ const record = state.record(teamId);
96
+ if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
97
+ if (record.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Read-only teams never commit, integrate or land.');
98
+ const slice = planSlice(record, sliceId);
99
+ if (!slice) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
100
+ if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed) return refuse('TEAM_NOT_ACTIVE', `Team "${teamId}" is ${record.removed ? 'removed' : record.state}.`, { state: record.state });
101
+ if (record.state === 'creating' || record.state === 'landing') return refuse('TEAM_NEEDS_RECOVERY', `Team "${teamId}" is recorded as ${record.state}: run recover() first.`, { state: record.state });
102
+ return { ok: true, record, slice };
103
+ }
104
+
105
+ /** The message of the commit SynaBun makes for a slice: a subject, the caller's body, and the trailers. */
106
+ function commitMessage(teamId, slice, message, runId) {
107
+ const given = typeof message === 'string' ? message.replace(/\r\n?/g, '\n').trim() : '';
108
+ const [subject, ...body] = (given || `${slice.title} (team ${teamId}, slice ${slice.id})`).split('\n');
109
+ const trailers = [`SynaBun-Team: ${teamId}`, `SynaBun-Slice: ${slice.id}`, ...(runId ? [`SynaBun-Run: ${String(runId).slice(0, 120)}`] : [])];
110
+ return [short(subject, 200), body.join('\n').trim(), trailers.join('\n')].filter(Boolean).join('\n\n');
111
+ }
112
+
113
+ /** A pathspec list on standard input, for a git write in a slice's worktree: every path literal. */
114
+ const pathspecs = (paths) => ({ input: `${paths.join('\0')}\0`, env: { GIT_LITERAL_PATHSPECS: '1' } });
115
+
116
+ /**
117
+ * Put the index entries of `paths` back as `entries` (parseIndexEntries) had them before an attempt: a path that
118
+ * had none is taken out of the index, one that had some gets exactly those (an unmerged path its stages again).
119
+ * Only the slice's worktree, which finishSlice has checked is a worktree of its own on the slice's branch. The
120
+ * files themselves are never touched. True when it was done.
121
+ */
122
+ async function restoreIndex(worktree, paths, entries) {
123
+ if (!paths.length) return true;
124
+ const head = line(await git(['rev-parse', 'HEAD'], { cwd: worktree }));
125
+ const zeros = '0'.repeat(head.length || 40);
126
+ const input = paths.flatMap((path) => [`0 ${zeros}\t${path}`, ...(entries.get(path) || [])]);
127
+ return (await git(['update-index', '-z', '--index-info'], { cwd: worktree, input: `${input.join('\0')}\0` })).ok;
128
+ }
129
+
130
+ /**
131
+ * Stage the slice's own changed files. A file git tracks is staged with `add -u`, which takes the file as it is
132
+ * (changed or deleted) without walking a folder: a plain `add` of a tracked file inside an ignored folder (a built
133
+ * `dist/` the project force-tracks) stages it and then fails all the same, because git's walk counts a path inside
134
+ * an ignored folder as ignored. A new file is staged with a plain `add`, never `-f`: a new file the .gitignore
135
+ * covers never shows up as changed, so it is never asked for (finishSlice names those in `ignored`). A path with
136
+ * no index entry that is not new (a staged deletion) is already as it should be.
137
+ * @returns {Promise<{ ok: true } | { ok: false, command: string, result: object }>}
138
+ */
139
+ async function stageOwn(worktree, tracked, fresh) {
140
+ if (tracked.length) {
141
+ const result = await git(['add', '-u', '--pathspec-from-file=-', '--pathspec-file-nul'], { cwd: worktree, ...pathspecs(tracked) });
142
+ if (!result.ok) return { ok: false, command: 'git add -u', result };
143
+ }
144
+ if (fresh.length) {
145
+ const result = await git(['add', '--pathspec-from-file=-', '--pathspec-file-nul'], { cwd: worktree, ...pathspecs(fresh) });
146
+ if (!result.ok) return { ok: false, command: 'git add', result };
147
+ }
148
+ return { ok: true };
149
+ }
150
+
151
+ /**
152
+ * The new files in a slice's worktree that the .gitignore covers and the slice owns: never committed, named in the
153
+ * answer so the owner sees what stayed out. A folder nothing of which is tracked is one entry with a trailing `/`.
154
+ */
155
+ async function ignoredOwn(worktree, plan, sliceId) {
156
+ const result = await git(['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'], { cwd: worktree });
157
+ if (!result.ok) return [];
158
+ return nulList(result.stdout).filter((path) => pathOwner(plan, path.replace(/\/+$/, '')) === sliceId).sort().map((path) => ({ path }));
159
+ }
160
+
161
+ /**
162
+ * A slice's worker is done: commit the slice's own files on its branch and check what the branch changed.
163
+ *
164
+ * Only files the slice owns are committed. A change to any other file is left where it is, uncommitted, and makes
165
+ * the slice `rejected` (unless `allowStray`: then the slice is done and the leftovers are reported). A commit a
166
+ * worker made itself that touches a file outside the slice's ownership rejects the slice whatever is passed.
167
+ *
168
+ * A file git tracks is committed even inside a folder the .gitignore covers (a force-tracked build output); a new
169
+ * file the .gitignore covers is never force-added: it stays out and is named in `ignored`. When staging or the
170
+ * commit fails, the answer carries everything git said (`git.output`, bounded) and the index of the slice's own
171
+ * paths is put back as it was before the attempt (`indexRestored`).
172
+ *
173
+ * @param {string} teamId
174
+ * @param {string} sliceId
175
+ * @param {object} [options]
176
+ * @param {string} [options.message] the commit's message (default: the slice's title); trailers are added
177
+ * @param {boolean} [options.allowStray] finish although files outside the slice's ownership are changed in the
178
+ * worktree (they stay uncommitted and are never joined)
179
+ * @param {string} [options.runId] the run that worked the slice
180
+ * @returns {Promise<{ ok: true, sliceId: string, head: string, committed: boolean, changed: object[], stray: object[], warnings: object[], ignored: { path: string }[] }
181
+ * | { ok: false, code: 'OWNERSHIP_VIOLATION'|'STRAY_CHANGES'|string, message: string, violations?: object[], stray?: object[] }>}
182
+ */
183
+ async function finishSlice(teamId, sliceId, { message = null, allowStray = false, runId = null, isCurrent = () => true } = {}) {
184
+ const loaded = load(teamId, sliceId);
185
+ if (!loaded.ok) return loaded;
186
+ const { record, slice } = loaded;
187
+ const current = sliceState(record, sliceId);
188
+ if (!FINISHABLE.has(current)) return refuse(current === 'integrated' ? 'SLICE_ALREADY_INTEGRATED' : 'SLICE_NOT_STARTED', `Slice "${sliceId}" is ${current}: only a slice a worker has been at can be finished.`, { state: current });
189
+ const worktree = worktreePath(record.projectPath, teamId, sliceId);
190
+ const branch = branchName(teamId, sliceId);
191
+
192
+ return locks.run(sliceKey(teamId, sliceId), async () => {
193
+ if (!isDirectory(worktree)) return refuse('SLICE_WORKTREE_MISSING', `The worktree of slice "${sliceId}" is not there (${worktree}). Run recover() first.`, { path: worktree });
194
+ const on = await branchAt(git, worktree);
195
+ if (on !== branch) return refuse('SLICE_BRANCH_MOVED', `The worktree of slice "${sliceId}" is on ${on || 'no branch'}, not on ${branch}: its work was not committed.`, { path: worktree, branch, on: on || null });
196
+ const busy = await operationsUnderWay(git, worktree, { exists });
197
+ if (busy.cherryPick || busy.rebase || busy.revert || busy.bisect) return refuse('SLICE_WORKTREE_BUSY', `The worktree of slice "${sliceId}" is in the middle of a ${busy.rebase ? 'rebase' : busy.cherryPick ? 'cherry-pick' : busy.revert ? 'revert' : 'bisect'}: finish or abort it first.`, { path: worktree });
198
+ if (busy.merge) {
199
+ const unmerged = nulList((await git(['diff', '--name-only', '--diff-filter=U', '-z'], { cwd: worktree })).stdout);
200
+ const unresolved = unmerged.filter((path) => hasConflictMarkers(join(worktree, path)));
201
+ if (unresolved.length) return refuse('UNRESOLVED_CONFLICTS', `Slice "${sliceId}" still has conflicts to resolve in ${unresolved.slice(0, 5).join(', ')}${unresolved.length > 5 ? '…' : ''}.`, { files: unresolved });
202
+ }
203
+ const changes = await changesOf(git, worktree);
204
+ if (changes === null) return refuse('GIT_FAILED', `The changes in the worktree of slice "${sliceId}" could not be read.`);
205
+ const paths = [...new Set(changes.flatMap((change) => [change.path, change.from].filter(Boolean)))];
206
+ const mine = paths.filter((path) => pathOwner(record.plan, path) === sliceId);
207
+ // A file that is not the slice's and is staged already (a program the worker ran staged it) is taken out of
208
+ // the index, so the commit holds the slice's own files only; the file itself stays as it is. Not during a
209
+ // merge: what is staged then is the integration branch's own work, and belongs in the merge commit.
210
+ if (!busy.merge) {
211
+ const staged = [...new Set(changes.filter((change) => change.index !== ' ' && change.index !== '?').flatMap((change) => [change.path, change.from].filter(Boolean)))]
212
+ .filter((path) => pathOwner(record.plan, path) !== sliceId);
213
+ if (staged.length) {
214
+ const unstaged = await git(['reset', '-q', '--pathspec-from-file=-', '--pathspec-file-nul'], { cwd: worktree, ...pathspecs(staged) });
215
+ if (!unstaged.ok) return refuse('GIT_FAILED', `The files slice "${sliceId}" does not own could not be taken out of its commit: ${gitOutput(unstaged)}`, { git: { command: 'git reset', status: unstaged.status, output: gitOutput(unstaged) } });
216
+ }
217
+ }
218
+ // What the index holds for the slice's own paths before this attempt stages anything: a staging or a commit
219
+ // that fails puts exactly that back, so a failed attempt leaves nothing staged behind (a worker cannot clear
220
+ // the index itself: its git is read-only).
221
+ let before = new Map();
222
+ if (mine.length) {
223
+ const index = await git(['ls-files', '-s', '-z'], { cwd: worktree });
224
+ if (!index.ok) return refuse('GIT_FAILED', `The index of slice "${sliceId}" could not be read: ${gitOutput(index)}`, { git: { command: 'git ls-files', status: index.status, output: gitOutput(index) } });
225
+ const all = parseIndexEntries(index.stdout);
226
+ before = new Map(mine.filter((path) => all.has(path)).map((path) => [path, all.get(path)]));
227
+ }
228
+ const fresh = new Set(changes.filter((change) => change.index === '?').map((change) => change.path));
229
+ /** A failed step: the index of the slice's own paths put back, and the refusal with everything git said. */
230
+ const failed = async (code, what, command, result) => {
231
+ const restored = await restoreIndex(worktree, mine, before);
232
+ if (!restored) log('teams:index-not-restored', { teamId, sliceId });
233
+ const output = gitOutput(result);
234
+ return refuse(code, `${what} (${command}): ${output}${restored ? '' : '\nThe index of its worktree could not be put back as it was.'}`, { sliceId, git: { command, status: result?.status ?? null, output }, indexRestored: restored });
235
+ };
236
+ if (mine.length) {
237
+ const staged = await stageOwn(worktree, mine.filter((path) => before.has(path)), mine.filter((path) => !before.has(path) && fresh.has(path)));
238
+ if (!staged.ok) return failed('GIT_FAILED', `The files of slice "${sliceId}" could not be staged`, staged.command, staged.result);
239
+ }
240
+ const ignored = await ignoredOwn(worktree, record.plan, sliceId);
241
+ const nothingStaged = (await git(['diff', '--cached', '--quiet'], { cwd: worktree })).ok;
242
+ let committed = false;
243
+ if (!nothingStaged || busy.merge) {
244
+ const commit = await git(['commit', '-q', '--no-verify', '-m', commitMessage(teamId, slice, message, runId)], { cwd: worktree, env: await identityEnv(git, worktree, identity) });
245
+ if (!commit.ok) return failed('COMMIT_FAILED', `The work of slice "${sliceId}" could not be committed`, 'git commit', commit);
246
+ committed = true;
247
+ }
248
+ const verdict = await claims.verifyOwnership(teamId, sliceId);
249
+ // A newer turn can start during git I/O. Its claims stay live and its result
250
+ // will verify the entire branch, including any commit already made here.
251
+ if (!isCurrent()) return { ok: false, sliceId, skipped: 'new-turn' };
252
+ if (verdict.ok === false && verdict.code) return verdict;
253
+ const data = {
254
+ head: verdict.head, reference: verdict.reference, finishedAt: now(),
255
+ changed: cap(verdict.changed.map((entry) => ({ path: short(entry.path), status: entry.status }))),
256
+ stray: cap(verdict.stray.map((entry) => ({ path: short(entry.path), owner: entry.owner, status: entry.status }))),
257
+ warnings: cap(verdict.warnings.map((entry) => ({ code: entry.code, path: short(entry.path) })), 40),
258
+ ignored: cap(ignored.map((entry) => ({ path: short(entry.path) }))),
259
+ };
260
+ if (verdict.violations.length) {
261
+ const violations = verdict.violations.map((entry) => ({ path: entry.path, status: entry.status, owner: entry.owner }));
262
+ state.writeSlice(teamId, sliceId, 'rejected', { ...data, violations: cap(violations.map((entry) => ({ ...entry, path: short(entry.path) }))) }, runId);
263
+ return refuse('OWNERSHIP_VIOLATION', `Slice "${sliceId}" committed changes to files it does not own (${violations.slice(0, 5).map((entry) => entry.path).join(', ')}${violations.length > 5 ? '…' : ''}): it is rejected and nothing of it is joined.`, { sliceId, head: verdict.head, violations, stray: verdict.stray, ignored, committed });
264
+ }
265
+ if (verdict.stray.length && !allowStray) {
266
+ state.writeSlice(teamId, sliceId, 'rejected', data, runId);
267
+ return refuse('STRAY_CHANGES', `Slice "${sliceId}" changed files it does not own (${verdict.stray.slice(0, 5).map((entry) => entry.path).join(', ')}${verdict.stray.length > 5 ? '…' : ''}). They were left uncommitted in its worktree and the slice is rejected; its own files are committed.`, { sliceId, head: verdict.head, stray: verdict.stray, ignored, committed });
268
+ }
269
+ state.writeSlice(teamId, sliceId, 'done', { ...data, violations: [] }, runId);
270
+ claims.release(teamId, sliceId);
271
+ return { ok: true, sliceId, head: verdict.head, committed, changed: verdict.changed, stray: verdict.stray, warnings: verdict.warnings, ignored };
272
+ });
273
+ }
274
+
275
+ /**
276
+ * The integration worktree back to a commit, with nothing left over (it is SynaBun's own: nobody works there).
277
+ * Only ever a folder that is a linked worktree of its own: a reset aimed at a plain folder would reach the
278
+ * repository around it, and the project's own checkout is the user's. False when it could not be done.
279
+ */
280
+ async function settle(place, commit) {
281
+ // A linked worktree has a `.git` file; the project's own checkout has a `.git` folder and is never reset.
282
+ let linked = false;
283
+ try { linked = lstatSync(join(place, '.git')).isFile(); } catch { linked = false; }
284
+ if (!linked) return false;
285
+ const top = line(await git(['rev-parse', '--show-toplevel'], { cwd: place }));
286
+ if (!top || realOf(top) !== realOf(place)) return false;
287
+ const busy = await operationsUnderWay(git, place, { exists });
288
+ if (busy.cherryPick) await git(['cherry-pick', '--abort'], { cwd: place });
289
+ if (busy.merge) await git(['merge', '--abort'], { cwd: place });
290
+ if (busy.revert) await git(['revert', '--abort'], { cwd: place });
291
+ await git(['reset', '--hard', '-q', commit], { cwd: place });
292
+ await git(['clean', '-fd', '-q'], { cwd: place });
293
+ const head = await commitOf(git, place, 'HEAD');
294
+ const left = await changesOf(git, place);
295
+ return head === commit && Array.isArray(left) && left.length === 0;
296
+ }
297
+
298
+ /** What a join that stopped on a conflict looked like, read before it is aborted. */
299
+ async function conflictReport(record, sliceId, { place, before, sliceHead, method }) {
300
+ const unmerged = await git(['ls-files', '-u', '-z'], { cwd: place });
301
+ const files = new Map();
302
+ for (const item of nulList(unmerged.stdout)) {
303
+ const match = /^(\d+) ([0-9a-f]+) ([123])\t([\s\S]+)$/.exec(item);
304
+ if (!match) continue;
305
+ const entry = files.get(match[4]) || { path: match[4], base: null, ours: null, theirs: null };
306
+ entry[match[3] === '1' ? 'base' : match[3] === '2' ? 'ours' : 'theirs'] = match[2];
307
+ files.set(match[4], entry);
308
+ }
309
+ const stopped = method === 'cherry-pick' ? (await commitOf(git, place, 'CHERRY_PICK_HEAD')) || sliceHead : sliceHead;
310
+ const subjectOf = async (commit) => line(await git(['log', '-1', '--format=%s', commit], { cwd: place }));
311
+ const out = [];
312
+ for (const entry of [...files.values()].slice(0, LIST_CAP)) {
313
+ // The side that is already on the integration branch: the last commit there that touched the file, and the
314
+ // slice it came from (its trailer; the file's owner by the plan when the commit has none).
315
+ const last = await git(['log', '-1', '--format=%H%x00%s%x00%(trailers:key=SynaBun-Slice,valueonly,separator=%x2C)', `${record.baseCommit}..${before}`, '--', entry.path], { cwd: place, env: { GIT_LITERAL_PATHSPECS: '1' } });
316
+ const [commit, subject, trailer] = (last.stdout || '').trim().split('\0');
317
+ out.push({
318
+ path: entry.path,
319
+ owner: pathOwner(record.plan, entry.path),
320
+ ours: { side: 'integration', commit: commit || before, subject: subject || '', slice: (trailer || '').split(',')[0].trim() || null, blob: entry.ours },
321
+ theirs: { side: 'slice', commit: stopped, subject: await subjectOf(stopped), slice: sliceId, blob: entry.theirs },
322
+ base: entry.base,
323
+ excerpt: out.length < 12 ? firstConflict(join(place, entry.path)) : null,
324
+ });
325
+ }
326
+ return {
327
+ teamId: record.teamId, sliceId, method,
328
+ integrationBranch: integrationBranchName(record.teamId), integrationHead: before,
329
+ sliceBranch: branchName(record.teamId, sliceId), sliceHead, stoppedAt: stopped,
330
+ files: out,
331
+ };
332
+ }
333
+
334
+ /** Run the team's test command on a commit of the integration worktree, and leave the worktree on that commit. */
335
+ async function testsOn(record, place, commit, command, sliceId) {
336
+ const started = now();
337
+ const head = await commitOf(git, place, 'HEAD');
338
+ if (head !== commit) return { ok: false, commit, command, at: started, error: `the integration worktree is on ${head}, not on ${commit}` };
339
+ let result;
340
+ try {
341
+ result = await runTests({ cwd: place, command, commit, teamId: record.teamId, sliceId, projectPath: record.projectPath });
342
+ } catch (error) {
343
+ result = { ok: false, error: error?.message || String(error) };
344
+ }
345
+ // What was tested is the commit: a test run that moved the branch did not test it.
346
+ const after = await commitOf(git, place, 'HEAD');
347
+ const moved = after !== commit;
348
+ await settle(place, commit);
349
+ return {
350
+ ok: result?.ok === true && !moved, commit, command, at: started, durationMs: Number(result?.durationMs) || now() - started,
351
+ exitCode: result?.exitCode ?? null, timedOut: result?.timedOut === true,
352
+ output: short(result?.output ?? '', 8000).slice(-8000),
353
+ ...(moved ? { error: 'the test command moved the integration branch' } : result?.error ? { error: short(result.error) } : {}),
354
+ };
355
+ }
356
+
357
+ /**
358
+ * Join a finished slice on the integration branch: its commits are cherry-picked there, the test command runs on
359
+ * exactly the resulting commit, and the slice is `integrated` only when both went well.
360
+ *
361
+ * @param {string} teamId
362
+ * @param {string} sliceId
363
+ * @param {object} [options]
364
+ * @param {boolean} [options.test] run the team's test command (default true; without a command nothing is run and
365
+ * the integration head counts as untested)
366
+ * @param {string|string[]} [options.testCommand] a command for this join instead of the team's
367
+ * @returns {Promise<{ ok: true, sliceId: string, method: string, commit: string, before: string, tests: object|null, ready: boolean }
368
+ * | { ok: false, code: 'CONFLICT'|'TESTS_FAILED'|string, message: string, report?: object }>}
369
+ */
370
+ async function integrate(teamId, sliceId, { test = true, testCommand = undefined, isCurrent = () => true } = {}) {
371
+ return locks.run(teamKey(teamId), async () => {
372
+ const loaded = load(teamId, sliceId);
373
+ if (!loaded.ok) return loaded;
374
+ const { record, slice } = loaded;
375
+ if (record.state === 'integrating') return refuse('TEAM_NEEDS_RECOVERY', `Team "${teamId}" is recorded in the middle of a join: run recover() first.`, { state: record.state });
376
+ const current = sliceState(record, sliceId);
377
+ const own = record.slices[sliceId] || {};
378
+ if (current === 'integrated') return { ok: true, sliceId, already: true, method: own.method || null, commit: own.integrationCommit || record.integration.head, before: record.integration.head, tests: record.integration.tests, ready: record.state === 'ready' };
379
+ if (current !== 'done') return refuse('SLICE_NOT_DONE', `Slice "${sliceId}" is ${current}: only a finished slice (finishSlice) is joined.`, { state: current });
380
+ const waiting = slice.dependsOn.filter((dep) => sliceState(record, dep) !== 'integrated');
381
+ if (waiting.length) return refuse('DEPENDENCIES_NOT_INTEGRATED', `Slice "${sliceId}" is joined after ${waiting.join(', ')}.`, { waiting });
382
+
383
+ const cwd = record.projectPath;
384
+ const place = integrationWorktreePath(cwd, teamId);
385
+ const branch = integrationBranchName(teamId);
386
+ if (!isDirectory(place)) return refuse('INTEGRATION_WORKTREE_MISSING', `The integration worktree of team "${teamId}" is not there (${place}). Run recover() first.`, { path: place });
387
+ const on = await branchAt(git, place);
388
+ if (on !== branch) return refuse('INTEGRATION_MOVED', `The integration worktree is on ${on || 'no branch'}, not on ${branch}.`, { path: place });
389
+ const before = await commitOf(git, place, 'HEAD');
390
+ if (before !== record.integration.head) return refuse('INTEGRATION_MOVED', `${branch} is at ${before}, not at the commit SynaBun left it on (${record.integration.head}): somebody moved it. Run recover() to take it from here.`, { head: before, recorded: record.integration.head });
391
+ if (!await settle(place, before)) return refuse('INTEGRATION_WORKTREE_DIRTY', `The integration worktree of team "${teamId}" could not be cleaned.`, { path: place });
392
+ const sliceHead = await commitOf(git, cwd, `refs/heads/${branchName(teamId, sliceId)}`);
393
+ if (!sliceHead) return refuse('SLICE_BRANCH_MISSING', `The branch of slice "${sliceId}" is not there.`);
394
+ if (sliceHead !== own.head) return refuse('SLICE_MOVED', `The branch of slice "${sliceId}" moved since the slice was finished: finish it again.`, { head: sliceHead, finished: own.head || null });
395
+
396
+ const from = own.integratedHead || own.startCommit || record.baseCommit;
397
+ const fresh = Number(line(await git(['rev-list', '--count', `${from}..${sliceHead}`], { cwd })) || 0);
398
+ const nothingNew = fresh === 0 || await isAncestor(cwd, sliceHead, before);
399
+ const merges = nothingNew ? 0 : Number(line(await git(['rev-list', '--count', '--merges', `${from}..${sliceHead}`], { cwd })) || 0);
400
+ const method = nothingNew ? 'none' : merges === 0 ? 'cherry-pick' : (await isAncestor(cwd, before, sliceHead)) ? 'fast-forward' : 'merge';
401
+
402
+ const under = { sliceId, before, sliceHead, method, startedAt: now() };
403
+ state.writeTeam(teamId, 'integrating', { integrating: { ...under, phase: 'applying' } });
404
+ state.writeSlice(teamId, sliceId, 'integrating', {}, own.runId || null);
405
+
406
+ // A follow-up can supersede this turn while git or the tests are running.
407
+ // The next turn keeps the slice. Only the disposable integration candidate is rolled back.
408
+ function superseded(clean) {
409
+ if (!clean) return refuse('TEAM_NEEDS_RECOVERY', 'The superseded candidate could not be rolled back. Inspect the integration worktree before retrying.', { sliceId });
410
+ state.writeSlice(teamId, sliceId, 'running', {}, own.runId || null);
411
+ state.writeTeam(teamId, 'running', { integrating: null });
412
+ const assigned = claims.assign(teamId, sliceId, own.runId);
413
+ return assigned.ok ? { ok: false, sliceId, skipped: 'new-turn' } : assigned;
414
+ }
415
+
416
+ if (method !== 'none') {
417
+ const env = await identityEnv(git, place, identity);
418
+ const applied = method === 'cherry-pick'
419
+ ? await git(['cherry-pick', '--allow-empty', '--keep-redundant-commits', `${from}..${sliceHead}`], { cwd: place, env })
420
+ : method === 'fast-forward'
421
+ ? await git(['merge', '--ff-only', '-q', sliceHead], { cwd: place, env })
422
+ : await git(['merge', '--no-ff', '--no-edit', '-q', '-m', `Join slice ${sliceId} of team ${teamId}\n\nSynaBun-Team: ${teamId}\nSynaBun-Slice: ${sliceId}`, sliceHead], { cwd: place, env });
423
+ if (!applied.ok) {
424
+ const report = await conflictReport(record, sliceId, { place, before, sliceHead, method });
425
+ const clean = await settle(place, before);
426
+ if (!isCurrent()) return superseded(clean);
427
+ if (!clean) log('teams:integration-not-clean', { teamId, sliceId });
428
+ if (!report.files.length) {
429
+ // Not a conflict: git could not apply the commits for another reason. The slice is still finished.
430
+ state.writeSlice(teamId, sliceId, 'done', { lastJoinError: short(gitSaid(applied)) }, own.runId || null);
431
+ state.writeTeam(teamId, 'running', { integrating: null });
432
+ return refuse('INTEGRATION_FAILED', `Slice "${sliceId}" could not be joined: ${gitSaid(applied)}. The integration branch is unchanged.`, { sliceId, before });
433
+ }
434
+ report.clean = clean;
435
+ const stored = { ...report, files: cap(report.files.map((file) => ({ ...file, path: short(file.path), excerpt: file.excerpt ? short(file.excerpt, 1500) : null })), 40) };
436
+ state.writeSlice(teamId, sliceId, 'conflict', { conflict: stored, conflictAt: now() }, own.runId || null);
437
+ state.writeTeam(teamId, 'running', { integrating: null });
438
+ announce(EVENT_KINDS.INTEGRATION_CONFLICT, teamId, { teamId, sliceId, files: report.files.map((file) => file.path).slice(0, 50), integrationHead: before, sliceHead });
439
+ return refuse('CONFLICT', `Slice "${sliceId}" conflicts with what is already on ${branch} in ${report.files.slice(0, 5).map((file) => file.path).join(', ')}${report.files.length > 5 ? '…' : ''}. The join was aborted and the integration branch is unchanged; nothing was resolved.`, { sliceId, report });
440
+ }
441
+ }
442
+
443
+ const candidate = await commitOf(git, place, 'HEAD');
444
+ const command = testCommand === undefined ? record.testCommand : testCommand;
445
+ let tests = record.integration.tests;
446
+ let lastGood = record.integration.lastGood;
447
+ if (method !== 'none' && test !== false && command) {
448
+ state.writeTeam(teamId, 'integrating', { integrating: { ...under, candidate, phase: 'testing' } });
449
+ tests = await testsOn(record, place, candidate, command, sliceId);
450
+ if (!tests.ok) {
451
+ const clean = await settle(place, before);
452
+ if (!isCurrent()) return superseded(clean);
453
+ state.writeSlice(teamId, sliceId, 'tests-failed', { tests: { ...tests, output: short(tests.output, 6000).slice(-6000) }, candidate, testsFailedAt: now() }, own.runId || null);
454
+ state.writeTeam(teamId, 'running', { integrating: null });
455
+ return refuse('TESTS_FAILED', `The tests failed on ${candidate.slice(0, 12)} (slice "${sliceId}" joined on ${branch}). The integration branch is back at ${before.slice(0, 12)}, the last good commit.`, { sliceId, report: { teamId, sliceId, candidate, before, tests, clean } });
456
+ }
457
+ lastGood = candidate;
458
+ }
459
+ if (!isCurrent()) return superseded(await settle(place, before));
460
+ state.writeSlice(teamId, sliceId, 'integrated', { integrationCommit: candidate, integratedHead: sliceHead, method, integratedAt: now() }, own.runId || null);
461
+ const after = state.record(teamId);
462
+ const ready = after.plan.slices.every((each) => ['integrated', 'cancelled'].includes(sliceState(after, each.id)));
463
+ state.writeTeam(teamId, ready ? 'ready' : 'running', { integrating: null, integration: { head: candidate, lastGood, tests: tests && tests.commit === candidate ? { ...tests, output: short(tests.output, 2000).slice(-2000) } : tests } });
464
+ claims.release(teamId, sliceId);
465
+ if (ready) announce(EVENT_KINDS.INTEGRATION_READY, teamId, { teamId, integrationBranch: branch, head: candidate, tested: !!tests && tests.commit === candidate && tests.ok === true });
466
+ return { ok: true, sliceId, method, commit: candidate, before, tests: tests && tests.commit === candidate ? tests : null, ready };
467
+ });
468
+ }
469
+
470
+ /**
471
+ * Join every finished slice, in dependency order (integrationOrder). A slice that is not finished, or waits for
472
+ * one that is not joined, is skipped; a slice that fails to join does not stop the ones that do not depend on it.
473
+ * The scheduler wraps each join and its retry handling in the same slice reservation as worker events.
474
+ * @returns {Promise<{ ok: boolean, ready: boolean, results: object[] }>}
475
+ */
476
+ async function integrateAll(teamId, options = {}, joinSlice = integrate) {
477
+ const first = state.record(teamId);
478
+ if (!first) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
479
+ if (first.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Read-only teams never commit, integrate or land.');
480
+ const results = [];
481
+ for (const sliceId of integrationOrder(first.plan)) {
482
+ const record = state.record(teamId);
483
+ const current = sliceState(record, sliceId);
484
+ if (current === 'integrated') { results.push({ sliceId, ok: true, already: true }); continue; }
485
+ if (current !== 'done') { results.push({ sliceId, ok: false, skipped: current }); continue; }
486
+ const waiting = planSlice(record, sliceId).dependsOn.filter((dep) => sliceState(record, dep) !== 'integrated');
487
+ if (waiting.length) { results.push({ sliceId, ok: false, skipped: 'blocked', waiting }); continue; }
488
+ results.push({ sliceId, ...(await joinSlice(teamId, sliceId, options)) });
489
+ }
490
+ const last = state.record(teamId);
491
+ return { ok: results.every((each) => each.ok), ready: last.state === 'ready', results };
492
+ }
493
+
494
+ /**
495
+ * Run the test command on the integration branch as it is now, and record the answer for that commit. Nothing is
496
+ * taken back when they fail: the commit simply does not count as tested.
497
+ */
498
+ async function testIntegration(teamId, { testCommand = undefined } = {}) {
499
+ return locks.run(teamKey(teamId), async () => {
500
+ const record = state.record(teamId);
501
+ if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
502
+ if (record.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Read-only teams never commit, integrate or land.');
503
+ if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed || ['creating', 'integrating', 'landing'].includes(record.state)) return refuse('TEAM_NOT_ACTIVE', `Team "${teamId}" is ${record.removed ? 'removed' : record.state}.`, { state: record.state });
504
+ const command = testCommand === undefined ? record.testCommand : testCommand;
505
+ if (!command) return refuse('NO_TEST_COMMAND', `Team "${teamId}" has no test command.`);
506
+ const place = integrationWorktreePath(record.projectPath, teamId);
507
+ if (!isDirectory(place)) return refuse('INTEGRATION_WORKTREE_MISSING', `The integration worktree of team "${teamId}" is not there (${place}).`);
508
+ if (await branchAt(git, place) !== integrationBranchName(teamId)) return refuse('INTEGRATION_MOVED', `The integration worktree is not on ${integrationBranchName(teamId)}.`, { path: place });
509
+ const head = await commitOf(git, place, 'HEAD');
510
+ if (head !== record.integration.head) return refuse('INTEGRATION_MOVED', `${integrationBranchName(teamId)} is at ${head}, not at ${record.integration.head}.`, { head, recorded: record.integration.head });
511
+ const previous = record.state;
512
+ state.writeTeam(teamId, 'integrating', { integrating: { sliceId: null, before: head, candidate: head, phase: 'testing', startedAt: now() } });
513
+ const tests = await testsOn(record, place, head, command, null);
514
+ state.writeTeam(teamId, previous, { integrating: null, integration: { head, lastGood: tests.ok ? head : record.integration.lastGood, tests: { ...tests, output: short(tests.output, 2000).slice(-2000) } } });
515
+ return tests.ok ? { ok: true, commit: head, tests } : refuse('TESTS_FAILED', `The tests failed on ${head.slice(0, 12)}.`, { report: { teamId, candidate: head, tests } });
516
+ });
517
+ }
518
+
519
+ /**
520
+ * After a conflict: bring the integration branch into the slice's worktree and leave the conflicts there, for the
521
+ * slice's owner to resolve in its own files. The slice is `running` again (its claims are taken again); finishing
522
+ * it commits the result, and it is then joined without a cherry-pick.
523
+ * @returns {Promise<{ ok: true, sliceId: string, worktree: string, integrationHead: string, conflicts: string[] } | { ok: false, code: string }>}
524
+ */
525
+ async function resolveInSlice(teamId, sliceId, { runId = null } = {}) {
526
+ const loaded = load(teamId, sliceId);
527
+ if (!loaded.ok) return loaded;
528
+ const { record } = loaded;
529
+ const current = sliceState(record, sliceId);
530
+ if (current !== 'conflict') return refuse('SLICE_NOT_IN_CONFLICT', `Slice "${sliceId}" is ${current}: there is no conflict to bring into its worktree.`, { state: current });
531
+ const worktree = worktreePath(record.projectPath, teamId, sliceId);
532
+ const branch = branchName(teamId, sliceId);
533
+ return locks.run(sliceKey(teamId, sliceId), async () => {
534
+ if (!isDirectory(worktree)) return refuse('SLICE_WORKTREE_MISSING', `The worktree of slice "${sliceId}" is not there (${worktree}).`, { path: worktree });
535
+ const on = await branchAt(git, worktree);
536
+ if (on !== branch) return refuse('SLICE_BRANCH_MOVED', `The worktree of slice "${sliceId}" is on ${on || 'no branch'}, not on ${branch}.`, { path: worktree });
537
+ if ((await operationsUnderWay(git, worktree, { exists })).any) return refuse('SLICE_WORKTREE_BUSY', `The worktree of slice "${sliceId}" is in the middle of another operation.`, { path: worktree });
538
+ const integration = await commitOf(git, record.projectPath, `refs/heads/${integrationBranchName(teamId)}`);
539
+ const merged = await git(['merge', '--no-commit', '--no-ff', integration], { cwd: worktree, env: await identityEnv(git, worktree, identity) });
540
+ const conflicts = nulList((await git(['diff', '--name-only', '--diff-filter=U', '-z'], { cwd: worktree })).stdout);
541
+ const started = (await operationsUnderWay(git, worktree, { exists })).merge;
542
+ if (!started) return refuse('MERGE_NOT_STARTED', `The integration branch could not be brought into slice "${sliceId}": ${gitSaid(merged)}`, { path: worktree });
543
+ const claimed = claims.assign(teamId, sliceId, runId);
544
+ if (!claimed.ok) { await git(['merge', '--abort'], { cwd: worktree }); return claimed; }
545
+ state.writeSlice(teamId, sliceId, 'running', { resolving: { integrationHead: integration, files: cap(conflicts.map((path) => short(path)), 60) }, rework: true, startedAt: now() }, runId);
546
+ return { ok: true, sliceId, worktree, branch, integrationHead: integration, conflicts };
547
+ });
548
+ }
549
+
550
+ /**
551
+ * Somebody committed on the integration branch itself, in its worktree (an integrator worker fixing what the
552
+ * slices together broke, the owner): take its head as the team's. Only a move forward from the commit SynaBun
553
+ * left it on is taken, and only a worktree with nothing uncommitted. The new head counts as untested.
554
+ * @returns {Promise<{ ok: true, head: string, previous: string, commits: number } | { ok: false, code: string }>}
555
+ */
556
+ async function acceptIntegrationHead(teamId) {
557
+ return locks.run(teamKey(teamId), async () => {
558
+ const record = state.record(teamId);
559
+ if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
560
+ if (record.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Read-only teams never commit, integrate or land.');
561
+ if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed || ['creating', 'integrating', 'landing'].includes(record.state)) return refuse('TEAM_NOT_ACTIVE', `Team "${teamId}" is ${record.removed ? 'removed' : record.state}.`, { state: record.state });
562
+ const place = integrationWorktreePath(record.projectPath, teamId);
563
+ const branch = integrationBranchName(teamId);
564
+ if (!isDirectory(place)) return refuse('INTEGRATION_WORKTREE_MISSING', `The integration worktree of team "${teamId}" is not there (${place}).`);
565
+ if (await branchAt(git, place) !== branch) return refuse('INTEGRATION_MOVED', `The integration worktree is not on ${branch}.`, { path: place });
566
+ if ((await operationsUnderWay(git, place, { exists })).any) return refuse('INTEGRATION_WORKTREE_DIRTY', 'The integration worktree is in the middle of an operation: finish or abort it first.', { path: place });
567
+ const left = await changesOf(git, place);
568
+ if (!Array.isArray(left) || left.length) return refuse('INTEGRATION_WORKTREE_DIRTY', `The integration worktree has uncommitted changes (${(left || []).slice(0, 5).map((change) => change.path).join(', ')}): commit or drop them first.`, { path: place });
569
+ const head = await commitOf(git, place, 'HEAD');
570
+ const previous = record.integration.head;
571
+ if (head === previous) return { ok: true, head, previous, commits: 0 };
572
+ if (!await isAncestor(record.projectPath, previous, head)) return refuse('INTEGRATION_REWOUND', `${branch} no longer has ${previous.slice(0, 12)}, the commit SynaBun left it on: only commits added on top of it are taken.`, { head, recorded: previous });
573
+ const commits = Number(line(await git(['rev-list', '--count', `${previous}..${head}`], { cwd: record.projectPath })) || 0);
574
+ state.writeTeam(teamId, record.state, { integration: { head, lastGood: record.integration.lastGood, tests: record.integration.tests }, acceptedAt: now() });
575
+ return { ok: true, head, previous, commits };
576
+ });
577
+ }
578
+
579
+ return { finishSlice, integrate, integrateAll, testIntegration, resolveInSlice, acceptIntegrationHead, settle, conflictReport };
580
+ }