synabun 2.3.1 → 2.4.1

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 (370) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +189 -0
  4. package/browser-extension/engine.js +508 -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 +250 -0
  17. package/browser-extension/popup-view.js +151 -0
  18. package/browser-extension/popup.css +166 -0
  19. package/browser-extension/popup.html +108 -0
  20. package/browser-extension/popup.js +359 -0
  21. package/browser-extension/protocol.js +232 -0
  22. package/browser-extension/service-worker.js +275 -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/lib/data-home-files.js +45 -0
  28. package/lib/data-home-migration.js +34 -58
  29. package/mcp-server/dist/http.d.ts +2 -0
  30. package/mcp-server/dist/http.d.ts.map +1 -1
  31. package/mcp-server/dist/http.js +9 -1
  32. package/mcp-server/dist/http.js.map +1 -1
  33. package/mcp-server/dist/index.d.ts +11 -0
  34. package/mcp-server/dist/index.d.ts.map +1 -1
  35. package/mcp-server/dist/index.js +38 -3
  36. package/mcp-server/dist/index.js.map +1 -1
  37. package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
  38. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
  39. package/mcp-server/dist/services/browser-route-flow.js +10 -3
  40. package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
  41. package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
  42. package/mcp-server/dist/services/codex-config-heal.js +7 -0
  43. package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.d.ts +95 -3
  45. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  46. package/mcp-server/dist/services/neural-interface.js +168 -23
  47. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  48. package/mcp-server/dist/services/team-context.d.ts +18 -0
  49. package/mcp-server/dist/services/team-context.d.ts.map +1 -0
  50. package/mcp-server/dist/services/team-context.js +29 -0
  51. package/mcp-server/dist/services/team-context.js.map +1 -0
  52. package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
  53. package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
  54. package/mcp-server/dist/services/tool-catalog.js +22 -6
  55. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  56. package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
  57. package/mcp-server/dist/services/tool-list.js +4 -0
  58. package/mcp-server/dist/services/tool-list.js.map +1 -1
  59. package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
  60. package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
  61. package/mcp-server/dist/services/tool-runtime.js +18 -1
  62. package/mcp-server/dist/services/tool-runtime.js.map +1 -1
  63. package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
  64. package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
  65. package/mcp-server/dist/tools/agent-definition.js +483 -0
  66. package/mcp-server/dist/tools/agent-definition.js.map +1 -0
  67. package/mcp-server/dist/tools/agents.d.ts +92 -9
  68. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  69. package/mcp-server/dist/tools/agents.js +163 -20
  70. package/mcp-server/dist/tools/agents.js.map +1 -1
  71. package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
  72. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  73. package/mcp-server/dist/tools/browser-advanced.js +70 -6
  74. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  75. package/mcp-server/dist/tools/git-tools.d.ts +4 -2
  76. package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
  77. package/mcp-server/dist/tools/git-tools.js +283 -2
  78. package/mcp-server/dist/tools/git-tools.js.map +1 -1
  79. package/mcp-server/dist/tools/morelogin.d.ts +8 -2
  80. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  81. package/mcp-server/dist/tools/morelogin.js +22 -5
  82. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  83. package/mcp-server/dist/tools/team.d.ts +32 -0
  84. package/mcp-server/dist/tools/team.d.ts.map +1 -0
  85. package/mcp-server/dist/tools/team.js +87 -0
  86. package/mcp-server/dist/tools/team.js.map +1 -0
  87. package/mcp-server/package-lock.json +2 -2
  88. package/mcp-server/package.json +1 -1
  89. package/mcp-server/src/http.ts +9 -1
  90. package/mcp-server/src/index.ts +34 -4
  91. package/mcp-server/src/services/browser-route-flow.ts +12 -5
  92. package/mcp-server/src/services/codex-config-heal.ts +7 -0
  93. package/mcp-server/src/services/neural-interface.ts +191 -29
  94. package/mcp-server/src/services/team-context.ts +27 -0
  95. package/mcp-server/src/services/tool-catalog.ts +26 -8
  96. package/mcp-server/src/services/tool-list.ts +4 -0
  97. package/mcp-server/src/services/tool-runtime.ts +21 -2
  98. package/mcp-server/src/tools/agent-definition.ts +458 -0
  99. package/mcp-server/src/tools/agents.ts +177 -19
  100. package/mcp-server/src/tools/browser-advanced.ts +60 -6
  101. package/mcp-server/src/tools/git-tools.ts +249 -3
  102. package/mcp-server/src/tools/morelogin.ts +20 -5
  103. package/mcp-server/src/tools/team.ts +97 -0
  104. package/neural-interface/i18n/en.json +1119 -47
  105. package/neural-interface/i18n/pt-BR.json +1119 -47
  106. package/neural-interface/lib/account-usage.js +1 -1
  107. package/neural-interface/lib/agents/builtins.json +207 -0
  108. package/neural-interface/lib/agents/density.js +101 -0
  109. package/neural-interface/lib/agents/forge-host.js +223 -0
  110. package/neural-interface/lib/agents/native-export-targets.js +190 -0
  111. package/neural-interface/lib/agents/native-export.js +365 -0
  112. package/neural-interface/lib/agents/registry.js +885 -0
  113. package/neural-interface/lib/agents/resolve.js +603 -0
  114. package/neural-interface/lib/agents/schema.js +642 -0
  115. package/neural-interface/lib/agents/split.js +37 -0
  116. package/neural-interface/lib/agents-studio-api.js +591 -0
  117. package/neural-interface/lib/assistant-api.js +76 -7
  118. package/neural-interface/lib/assistant-brains/opencode.js +60 -11
  119. package/neural-interface/lib/assistant-catalog.js +2 -0
  120. package/neural-interface/lib/assistant-continuity.js +49 -0
  121. package/neural-interface/lib/assistant-dispatch.js +351 -121
  122. package/neural-interface/lib/assistant-persona.js +105 -8
  123. package/neural-interface/lib/assistant-route-gate.js +24 -9
  124. package/neural-interface/lib/assistant-router.js +432 -47
  125. package/neural-interface/lib/assistant-run-tail.js +151 -0
  126. package/neural-interface/lib/assistant-run-wait.js +183 -0
  127. package/neural-interface/lib/assistant-runtime.js +449 -94
  128. package/neural-interface/lib/assistant-task-prompt.js +11 -2
  129. package/neural-interface/lib/assistant-usage.js +3 -2
  130. package/neural-interface/lib/automation-approval.js +2 -2
  131. package/neural-interface/lib/backup-service.js +64 -105
  132. package/neural-interface/lib/browser-close-evidence.js +80 -0
  133. package/neural-interface/lib/browser-default.js +210 -0
  134. package/neural-interface/lib/browser-extension-adapter.js +264 -0
  135. package/neural-interface/lib/browser-extension-bridge.js +441 -0
  136. package/neural-interface/lib/browser-extension-folder.js +116 -0
  137. package/neural-interface/lib/browser-extension-setup.js +140 -0
  138. package/neural-interface/lib/browser-profile-choices.js +3 -3
  139. package/neural-interface/lib/browser-tool-policy.js +1 -1
  140. package/neural-interface/lib/claude-account-links.js +301 -0
  141. package/neural-interface/lib/claude-accounts.js +45 -20
  142. package/neural-interface/lib/claude-agent-bridge.js +142 -10
  143. package/neural-interface/lib/claude-model-catalog.js +6 -0
  144. package/neural-interface/lib/claude-panel-session.js +33 -0
  145. package/neural-interface/lib/codex-accounts.js +67 -24
  146. package/neural-interface/lib/coordination/README.md +384 -0
  147. package/neural-interface/lib/coordination/service.js +563 -0
  148. package/neural-interface/lib/coordination/store.js +1138 -0
  149. package/neural-interface/lib/db.js +22 -1
  150. package/neural-interface/lib/effort-levels.js +10 -1
  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 +194 -8
  157. package/neural-interface/lib/native-loop-runtime.js +26 -7
  158. package/neural-interface/lib/opencode-build-preflight.js +28 -8
  159. package/neural-interface/lib/opencode-native-boundary.js +83 -13
  160. package/neural-interface/lib/opencode-serve-records.js +14 -9
  161. package/neural-interface/lib/page-session.js +1 -1
  162. package/neural-interface/lib/peer-identity.js +73 -29
  163. package/neural-interface/lib/process-identity.js +68 -7
  164. package/neural-interface/lib/request-gate.js +3 -0
  165. package/neural-interface/lib/screenshot-location.js +33 -0
  166. package/neural-interface/lib/session-cache-builder.js +41 -3
  167. package/neural-interface/lib/skills/creation.js +1 -1
  168. package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
  169. package/neural-interface/lib/studio-attention.js +56 -0
  170. package/neural-interface/lib/teams/README.md +382 -0
  171. package/neural-interface/lib/teams/api.js +287 -0
  172. package/neural-interface/lib/teams/brief.js +185 -0
  173. package/neural-interface/lib/teams/claims.js +315 -0
  174. package/neural-interface/lib/teams/git.js +293 -0
  175. package/neural-interface/lib/teams/index.js +122 -0
  176. package/neural-interface/lib/teams/integration.js +580 -0
  177. package/neural-interface/lib/teams/landing.js +184 -0
  178. package/neural-interface/lib/teams/recovery.js +256 -0
  179. package/neural-interface/lib/teams/scheduler.js +1474 -0
  180. package/neural-interface/lib/teams/schema.js +559 -0
  181. package/neural-interface/lib/teams/state.js +181 -0
  182. package/neural-interface/lib/teams/test-runner.js +86 -0
  183. package/neural-interface/lib/teams/test-sandbox.js +99 -0
  184. package/neural-interface/lib/teams/worktrees.js +757 -0
  185. package/neural-interface/lib/tool-permission-choices.js +226 -0
  186. package/neural-interface/lib/whatsapp/cards.js +24 -10
  187. package/neural-interface/lib/worker-confinement.js +206 -6
  188. package/neural-interface/package-lock.json +2 -2
  189. package/neural-interface/package.json +1 -1
  190. package/neural-interface/public/extension-setup.html +107 -0
  191. package/neural-interface/public/index.html +103 -12
  192. package/neural-interface/public/offline.html +4 -3
  193. package/neural-interface/public/shared/agent-runtime-options.js +3 -1
  194. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
  195. package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
  196. package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
  197. package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
  198. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
  199. package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
  200. package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
  201. package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
  202. package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
  203. package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
  204. package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
  205. package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
  206. package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
  207. package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
  208. package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
  209. package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
  210. package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
  211. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
  212. package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
  213. package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
  214. package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
  215. package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
  216. package/neural-interface/public/shared/agy/agy-panel.js +142 -28
  217. package/neural-interface/public/shared/agy/agy-styles.js +25 -5
  218. package/neural-interface/public/shared/api.js +2 -1
  219. package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
  220. package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
  221. package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
  222. package/neural-interface/public/shared/assistant/asst-control.js +3 -0
  223. package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
  224. package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
  225. package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
  226. package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
  227. package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
  228. package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
  229. package/neural-interface/public/shared/assistant/asst-render.js +37 -6
  230. package/neural-interface/public/shared/assistant/asst-route.js +80 -12
  231. package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
  232. package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
  233. package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
  234. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
  235. package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
  236. package/neural-interface/public/shared/assistant/asst-state.js +66 -1
  237. package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
  238. package/neural-interface/public/shared/assistant/route-identity.js +16 -0
  239. package/neural-interface/public/shared/cc-dropdown.js +21 -15
  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 +34 -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/owner-authority-view.js +4 -10
  279. package/neural-interface/public/shared/page-session.js +1 -1
  280. package/neural-interface/public/shared/schedules-view.js +2 -2
  281. package/neural-interface/public/shared/session-project-items.js +11 -0
  282. package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
  283. package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
  284. package/neural-interface/public/shared/settings/settings-ia.js +4 -2
  285. package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
  286. package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
  287. package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
  288. package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
  289. package/neural-interface/public/shared/sidepanel-shown.js +73 -0
  290. package/neural-interface/public/shared/start-bridge.js +2 -2
  291. package/neural-interface/public/shared/storage.js +6 -1
  292. package/neural-interface/public/shared/studio-attention.js +83 -0
  293. package/neural-interface/public/shared/styles.css +694 -50
  294. package/neural-interface/public/shared/term-browser-tabs.js +34 -0
  295. package/neural-interface/public/shared/transcript-rows.js +334 -0
  296. package/neural-interface/public/shared/tray-auto-close.js +106 -0
  297. package/neural-interface/public/shared/ui-agents.js +97 -0
  298. package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
  299. package/neural-interface/public/shared/ui-automation-studio.js +3 -3
  300. package/neural-interface/public/shared/ui-claude-panel.js +162 -95
  301. package/neural-interface/public/shared/ui-code-copy.js +256 -0
  302. package/neural-interface/public/shared/ui-codex-panel.js +14 -10
  303. package/neural-interface/public/shared/ui-context-menu.js +1 -1
  304. package/neural-interface/public/shared/ui-file-explorer.js +2 -3
  305. package/neural-interface/public/shared/ui-games.js +1 -1
  306. package/neural-interface/public/shared/ui-loading.js +83 -19
  307. package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
  308. package/neural-interface/public/shared/ui-menubar.js +23 -0
  309. package/neural-interface/public/shared/ui-native-loop-router.js +50 -21
  310. package/neural-interface/public/shared/ui-navbar.js +15 -9
  311. package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
  312. package/neural-interface/public/shared/ui-owner-authority.js +48 -25
  313. package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
  314. package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
  315. package/neural-interface/public/shared/ui-sessions.js +3 -3
  316. package/neural-interface/public/shared/ui-settings-entry.js +55 -0
  317. package/neural-interface/public/shared/ui-settings.js +363 -400
  318. package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
  319. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
  320. package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
  321. package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
  322. package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
  323. package/neural-interface/public/shared/ui-styleguide.js +10 -2
  324. package/neural-interface/public/shared/ui-sync.js +6 -0
  325. package/neural-interface/public/shared/ui-terminal.js +13 -9
  326. package/neural-interface/public/shared/ui-tooltip.js +28 -7
  327. package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
  328. package/neural-interface/public/shared/ui-tray-columns.js +375 -0
  329. package/neural-interface/public/shared/ui-whiteboard.js +51 -6
  330. package/neural-interface/public/shared/ui-worker-end.js +28 -1
  331. package/neural-interface/public/shared/ui-workspaces.js +13 -0
  332. package/neural-interface/public/shared/window-keys.js +71 -0
  333. package/neural-interface/public/sw.js +4 -3
  334. package/neural-interface/public/variant/2d/main.js +2 -0
  335. package/neural-interface/public/variant/3d/app.js +620 -0
  336. package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
  337. package/neural-interface/public/variant/3d/main.js +30 -544
  338. package/neural-interface/public/variant/3d/map-controls.js +4 -2
  339. package/neural-interface/public/vendor/fonts/fonts.css +508 -0
  340. package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
  341. package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
  342. package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
  343. package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
  344. package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
  345. package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
  346. package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
  347. package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
  348. package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
  349. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
  350. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
  351. package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
  352. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  353. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
  354. package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
  355. package/neural-interface/public/vendor/fonts/manifest.json +142 -0
  356. package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
  357. package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
  358. package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
  359. package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
  360. package/neural-interface/scripts/boot-graph.mjs +270 -0
  361. package/neural-interface/scripts/vendor-fonts.mjs +124 -0
  362. package/neural-interface/server.js +1083 -164
  363. package/npm-shrinkwrap.json +2 -2
  364. package/package.json +4 -1
  365. package/skills/agent-forge/SKILL.md +182 -0
  366. package/skills/agent-forge/evals/evals.json +56 -0
  367. package/skills/agent-forge/references/definition-fields.md +61 -0
  368. package/skills/agent-forge/references/examples.md +105 -0
  369. package/skills/agent-forge/references/instructions.md +51 -0
  370. package/skills/agent-forge/references/review-and-export.md +84 -0
@@ -0,0 +1,184 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: landing a team's result in the user's branch
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A team's joined work waits on its integration branch. The user's branch receives it only here, in a step of its
6
+ // own that somebody asks for (owner decision, 2026-11-15): `land(teamId, { targetBranch, mode })`.
7
+ //
8
+ // mode 'ff' the target branch is moved forward to the integration branch. Possible only while the target
9
+ // has not moved away from what the team was built on.
10
+ // mode 'merge' a merge commit of the target and the integration branch is made (always a merge commit, also
11
+ // when a fast-forward would do), and the target is moved to it. The merge is computed without a
12
+ // checkout (`git merge-tree`); one that conflicts is refused, never resolved.
13
+ //
14
+ // A landing changes nothing and answers with a report when:
15
+ // NOT_FAST_FORWARD mode 'ff' and the target has commits the integration branch lacks
16
+ // MERGE_CONFLICT mode 'merge' and the two do not merge cleanly
17
+ // TESTS_NOT_PASSED the test command has not passed on the integration branch's head (`allowUntested` lands
18
+ // a team that has no test command, or whose head was not tested, on the caller's word)
19
+ // TEAM_NOT_READY a slice is not joined yet (`allowPartial` lands what is joined)
20
+ // DIRTY_FILES_AFFECTED the landing would change a file that has uncommitted changes in the checkout that has
21
+ // the target branch (or would write over a file that is there and untracked or ignored)
22
+ // CHECKOUT_BUSY that checkout is in the middle of a merge, a rebase, a cherry-pick, a revert or a bisect
23
+ // CHECKOUT_REFUSED git itself would not update that checkout (it checks again as it starts)
24
+ // TARGET_MOVED the target moved while the landing was prepared
25
+ // and the report says what the user can run themselves (`userShouldRun`).
26
+ //
27
+ // Where the target is checked out (the user's own checkout, usually), the branch, the index and the files are
28
+ // updated together by a fast-forward of that checkout to the commit prepared above. git carries every uncommitted
29
+ // change of a file the landing does not touch across unchanged, staged or not, and refuses before it changes
30
+ // anything when one would be overwritten; nothing is stashed, and no hook runs. Where the target is checked out
31
+ // nowhere, only the branch is moved (compare-and-swap on its old commit).
32
+
33
+ import { existsSync, lstatSync } from 'node:fs';
34
+ import { join } from 'node:path';
35
+ import { integrationBranchName, isTeamSlug, parseBranchName } from './schema.js';
36
+ import { gitSaid, identityEnv, line, nulList, operationsUnderWay, parseNameStatus } from './git.js';
37
+ import { refuse, sliceState } from './state.js';
38
+ import { changesOf, commitOf, listWorktrees, repoLockKey } from './worktrees.js';
39
+
40
+ const isDirectory = (path) => { try { return lstatSync(path).isDirectory(); } catch { return false; } };
41
+ const present = (path) => { try { lstatSync(path); return true; } catch { return false; } };
42
+ const exists = (path) => existsSync(path);
43
+
44
+ export const LANDING_MODES = Object.freeze(['ff', 'merge']);
45
+
46
+ /** Do two project-relative paths name the same file, or is one inside the other? */
47
+ function touches(a, b) {
48
+ const x = a.replace(/\/+$/, '');
49
+ const y = b.replace(/\/+$/, '');
50
+ return x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`);
51
+ }
52
+
53
+ /**
54
+ * @param {object} deps
55
+ * @param {object} deps.state createTeamState(...)
56
+ * @param {Function} deps.git createGitRunner(...)
57
+ * @param {object} deps.locks createLocks()
58
+ * @param {object} deps.claims createTeamClaims(...)
59
+ * @param {{ name: string, email: string }|null} [deps.identity]
60
+ * @param {() => number} [deps.now]
61
+ */
62
+ export function createTeamLanding({ state, git, locks, claims, identity = null, now = Date.now } = {}) {
63
+ const isAncestor = async (cwd, older, newer) => (await git(['merge-base', '--is-ancestor', older, newer], { cwd })).ok;
64
+
65
+ /**
66
+ * Bring a team's integration branch into a branch of the user's.
67
+ *
68
+ * @param {string} teamId
69
+ * @param {object} [options]
70
+ * @param {string} [options.targetBranch] default: the branch the project was on when the team was created
71
+ * @param {'ff'|'merge'} [options.mode] default 'ff'
72
+ * @param {boolean} [options.allowUntested] land although the tests have not passed on the integration head
73
+ * @param {boolean} [options.allowPartial] land although some slices are not joined
74
+ * @returns {Promise<{ ok: true, landed: object, changed: object[] } | { ok: false, code: string, message: string, report?: object }>}
75
+ */
76
+ async function land(teamId, { targetBranch = null, mode = 'ff', allowUntested = false, allowPartial = false } = {}) {
77
+ const record = isTeamSlug(teamId) ? state.record(teamId) : null;
78
+ if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
79
+ if (record.plan.readOnly) return refuse('TEAM_READ_ONLY', 'Read-only teams never commit, integrate or land.');
80
+ if (!LANDING_MODES.includes(mode)) return refuse('INVALID_MODE', 'mode is "ff" (move the branch forward) or "merge" (make a merge commit).');
81
+ if (record.state === 'merged') return refuse('ALREADY_LANDED', `Team "${teamId}" has landed already (${record.landed?.targetBranch || 'its target'}).`, { landed: record.landed || null });
82
+ if (['creating', 'integrating', 'landing'].includes(record.state)) return refuse('TEAM_NEEDS_RECOVERY', `Team "${teamId}" is recorded as ${record.state}: run recover() first.`, { state: record.state });
83
+ if (['failed', 'cancelled'].includes(record.state) || record.removed) return refuse('TEAM_NOT_ACTIVE', `Team "${teamId}" is ${record.removed ? 'removed' : record.state}: there is nothing to land.`, { state: record.state });
84
+ const target = typeof targetBranch === 'string' && targetBranch.trim() ? targetBranch.trim() : record.baseBranch;
85
+ if (!target) return refuse('TARGET_REQUIRED', 'The project was on no branch when the team was created: name the branch to land on (targetBranch).');
86
+ if (parseBranchName(target)) return refuse('TARGET_IS_TEAM_BRANCH', `${target} is a team's own branch: a landing goes to a branch of yours.`);
87
+ const cwd = record.projectPath;
88
+ if (!isDirectory(cwd)) return refuse('PROJECT_NOT_FOUND', `${cwd} is not a folder.`);
89
+ if (!(await git(['check-ref-format', '--branch', target], { cwd })).ok) return refuse('TARGET_NOT_FOUND', `"${target.slice(0, 120)}" is not a branch name.`);
90
+ const source = integrationBranchName(teamId);
91
+
92
+ return locks.run(repoLockKey(cwd), () => locks.run(`team:${teamId}`, async () => {
93
+ const head = await commitOf(git, cwd, `refs/heads/${source}`);
94
+ if (!head) return refuse('INTEGRATION_BRANCH_MISSING', `${source} is not there. Run recover() first.`);
95
+ if (head !== record.integration.head) return refuse('INTEGRATION_MOVED', `${source} is at ${head}, not at the commit SynaBun left it on (${record.integration.head}): somebody moved it.`, { head, recorded: record.integration.head });
96
+
97
+ const open = record.plan.slices.map((slice) => ({ id: slice.id, state: sliceState(record, slice.id) })).filter((slice) => !['integrated', 'cancelled'].includes(slice.state));
98
+ if (open.length && !allowPartial) return refuse('TEAM_NOT_READY', `Team "${teamId}" is not finished: ${open.map((slice) => `${slice.id} is ${slice.state}`).join(', ')}.`, { report: { teamId, slices: open } });
99
+
100
+ const tests = record.integration.tests;
101
+ const tested = !!tests && tests.ok === true && tests.commit === head;
102
+ if (!tested && !allowUntested) {
103
+ const why = !record.testCommand && !tests ? 'the team has no test command' : !tests || tests.commit !== head ? 'the tests have not been run on this commit' : 'the tests failed on this commit';
104
+ return refuse('TESTS_NOT_PASSED', `${source} (${head.slice(0, 12)}) has not passed its tests: ${why}. Nothing was landed.`, { report: { teamId, integrationHead: head, tests: tests || null, testCommand: record.testCommand } });
105
+ }
106
+
107
+ const targetHead = await commitOf(git, cwd, `refs/heads/${target}`);
108
+ if (!targetHead) return refuse('TARGET_NOT_FOUND', `There is no branch named ${target} in this project.`);
109
+ if (head === targetHead || await isAncestor(cwd, head, targetHead)) return refuse('NOTHING_TO_LAND', `${target} already has everything on ${source}.`, { report: { teamId, targetBranch: target, targetHead, integrationHead: head } });
110
+
111
+ const byHand = (how) => [`git checkout ${target}`, how === 'ff' ? `git merge --ff-only ${source}` : `git merge --no-ff ${source}`];
112
+ const fastForward = await isAncestor(cwd, targetHead, head);
113
+ if (mode === 'ff' && !fastForward) {
114
+ const counts = /^(\d+)\s+(\d+)/.exec((await git(['rev-list', '--left-right', '--count', `${targetHead}...${head}`], { cwd })).stdout || '');
115
+ return refuse('NOT_FAST_FORWARD', `${target} has moved since the team started: it has ${counts ? counts[1] : 'some'} commit(s) that ${source} does not have, so it cannot be moved forward to it. Land with mode "merge", or merge it yourself.`, {
116
+ report: { teamId, targetBranch: target, targetHead, integrationHead: head, baseCommit: record.baseCommit, targetOnly: counts ? Number(counts[1]) : null, integrationOnly: counts ? Number(counts[2]) : null, userShouldRun: byHand('merge') },
117
+ });
118
+ }
119
+
120
+ // The commit the target is moved to: the integration head, or a merge commit made without a checkout.
121
+ let to = head;
122
+ let mergeCommit = null;
123
+ if (mode === 'merge') {
124
+ const merged = await git(['merge-tree', '--write-tree', '--name-only', '--no-messages', '-z', targetHead, head], { cwd });
125
+ const parts = nulList(merged.stdout);
126
+ if (merged.status === 1) return refuse('MERGE_CONFLICT', `${source} does not merge cleanly into ${target}: ${parts.slice(1, 6).join(', ')}${parts.length > 6 ? '…' : ''}. Nothing was landed and nothing was resolved.`, { report: { teamId, targetBranch: target, targetHead, integrationHead: head, files: parts.slice(1), userShouldRun: byHand('merge') } });
127
+ if (!merged.ok || !/^[0-9a-f]{40,64}$/.test(parts[0] || '')) return refuse('MERGE_UNAVAILABLE', `git could not work the merge out without a checkout (${gitSaid(merged)}); it needs git 2.38 or newer. Nothing was landed.`, { report: { userShouldRun: byHand('merge') } });
128
+ const made = await git(['commit-tree', parts[0], '-p', targetHead, '-p', head, '-m', `Merge team ${teamId} (${source}) into ${target}\n\nSynaBun-Team: ${teamId}`], { cwd, env: await identityEnv(git, cwd, identity) });
129
+ mergeCommit = line(made);
130
+ if (!made.ok || !mergeCommit) return refuse('MERGE_UNAVAILABLE', `The merge commit could not be made: ${gitSaid(made)}. Nothing was landed.`, { report: { userShouldRun: byHand('merge') } });
131
+ to = mergeCommit;
132
+ }
133
+ const changed = parseNameStatus((await git(['diff', '--name-status', '-z', '--no-renames', targetHead, to], { cwd })).stdout);
134
+
135
+ // The checkout that has the target branch, if any: the landing must not disturb what is uncommitted there.
136
+ const checkout = (await listWorktrees(git, cwd)).find((entry) => entry.branch === target) || null;
137
+ if (checkout) {
138
+ const place = checkout.path;
139
+ if (!isDirectory(place)) return refuse('CHECKOUT_REFUSED', `${target} is registered as checked out in ${place}, which is not there. Run "git worktree prune", then land again.`, { report: { checkout: place, userShouldRun: ['git worktree prune'] } });
140
+ const busy = await operationsUnderWay(git, place, { exists });
141
+ if (busy.any) {
142
+ const what = busy.merge ? 'merge' : busy.rebase ? 'rebase' : busy.cherryPick ? 'cherry-pick' : busy.revert ? 'revert' : 'bisect';
143
+ return refuse('CHECKOUT_BUSY', `${place} is in the middle of a ${what}: a landing there cannot be guaranteed to leave it as it is. Finish or abort the ${what}, then land again or merge it yourself.`, { report: { checkout: place, operation: what, userShouldRun: byHand(mode) } });
144
+ }
145
+ const changes = await changesOf(git, place);
146
+ if (changes === null) return refuse('CHECKOUT_REFUSED', `The uncommitted changes of ${place} could not be read, so the landing cannot be guaranteed to leave them alone.`, { report: { checkout: place, userShouldRun: byHand(mode) } });
147
+ const dirty = [...new Set(changes.flatMap((change) => [change.path, change.from].filter(Boolean)))];
148
+ const affected = changed.filter((entry) => dirty.some((path) => touches(entry.path, path))).map((entry) => ({ path: entry.path, status: entry.status, why: 'uncommitted changes' }));
149
+ // A file the landing adds where one already is (untracked files are in `dirty`; an ignored one is not).
150
+ const covered = changed.filter((entry) => entry.status === 'A' && !affected.some((each) => each.path === entry.path) && present(join(place, entry.path))).map((entry) => ({ path: entry.path, status: entry.status, why: 'a file that is not tracked is already there' }));
151
+ if (affected.length || covered.length) {
152
+ const files = [...affected, ...covered];
153
+ return refuse('DIRTY_FILES_AFFECTED', `The landing would change ${files.length} file(s) that have uncommitted changes in ${place}: ${files.slice(0, 5).map((file) => file.path).join(', ')}${files.length > 5 ? '…' : ''}. Nothing was landed. Commit or put those changes aside yourself, then land again.`, { report: { teamId, checkout: place, targetBranch: target, files, userShouldRun: byHand(mode) } });
154
+ }
155
+ }
156
+
157
+ const previous = record.state;
158
+ const landing = { targetBranch: target, mode, from: targetHead, to, integrationHead: head, mergeCommit, checkout: checkout?.path || null, startedAt: now() };
159
+ state.writeTeam(teamId, 'landing', { landing });
160
+ if (checkout) {
161
+ // Branch, index and files together; a file the landing does not touch keeps its uncommitted changes.
162
+ const moved = await git(['merge', '--ff-only', '-q', to], { cwd: checkout.path });
163
+ const after = await commitOf(git, cwd, `refs/heads/${target}`);
164
+ if (!moved.ok || after !== to) {
165
+ state.writeTeam(teamId, previous, { landing: null });
166
+ if (after === targetHead) return refuse('CHECKOUT_REFUSED', `git would not update ${checkout.path}: ${gitSaid(moved)}. Nothing was landed.`, { report: { checkout: checkout.path, userShouldRun: byHand(mode) } });
167
+ return refuse('TARGET_MOVED', `${target} is at ${after}, neither where it was nor where the landing put it. Nothing more was done; look at ${checkout.path} before landing again.`, { report: { checkout: checkout.path, targetHead: after, from: targetHead, to } });
168
+ }
169
+ } else {
170
+ const moved = await git(['update-ref', '-m', `synabun: land team ${teamId}`, `refs/heads/${target}`, to, targetHead], { cwd });
171
+ if (!moved.ok) {
172
+ state.writeTeam(teamId, previous, { landing: null });
173
+ return refuse('TARGET_MOVED', `${target} moved while the landing was prepared: ${gitSaid(moved)}. Nothing was landed.`, { report: { targetBranch: target, from: targetHead, to } });
174
+ }
175
+ }
176
+ const landed = { ...landing, files: changed.length, at: now(), partial: open.length > 0, tested };
177
+ state.writeTeam(teamId, 'merged', { landing: null, landed });
178
+ claims.end(teamId);
179
+ return { ok: true, landed, changed };
180
+ }));
181
+ }
182
+
183
+ return { land };
184
+ }
@@ -0,0 +1,256 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: recovery after a crash
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A team's steps are written to the journal before and after they run (lib/teams/state.js). recover() is called
6
+ // once when the server starts, before anything else touches a team: it reads where each team stood and what git
7
+ // and the disk say, and brings the two together.
8
+ //
9
+ // creating the team was being made. It has no work yet, so what is half-made is taken apart and made again
10
+ // (worktrees and branches that still point at the base commit); the team is `planned`, or `failed`
11
+ // when it cannot be made.
12
+ // integrating a slice was being joined, or its tests were running. A cherry-pick or merge under way is aborted
13
+ // and the integration branch goes back to the commit before the join. The slice is `done` again,
14
+ // ready to be joined: its commits are on its own branch, nothing of it is lost.
15
+ // landing the user's branch was being moved. Where it is now decides: at the landing's commit, the team is
16
+ // `merged`; where it was, the team is as before; anywhere else, it is reported.
17
+ // any other a worktree whose folder is gone is put back from its branch (the commits are there; what was
18
+ // uncommitted in the folder went with the folder); a slice whose branch is gone too is `failed`.
19
+ //
20
+ // Recovery never deletes work: it removes only what a creation left half-made (no worker had started), and it moves
21
+ // only the integration branch, back to a commit SynaBun itself recorded, when everything after that commit is a
22
+ // copy of commits a slice still has. Anything it does not understand it leaves alone and lists under `attention`.
23
+ // The user's checkout and branch are never touched.
24
+
25
+ import { existsSync, lstatSync, realpathSync, rmSync, rmdirSync } from 'node:fs';
26
+ import { join, resolve } from 'node:path';
27
+ import { INTEGRATION_SLICE_ID, branchName, integrationBranchName, integrationWorktreePath, worktreesRoot } from './schema.js';
28
+ import { gitSaid, operationsUnderWay } from './git.js';
29
+ import { SETTLED_SLICE_STATES, TERMINAL_TEAM_STATES, sliceState } from './state.js';
30
+ import { branchAt, changesOf, commitOf, listWorktrees, repoLockKey, repositoryOf } from './worktrees.js';
31
+
32
+ const isDirectory = (path) => { try { return lstatSync(path).isDirectory(); } catch { return false; } };
33
+ const present = (path) => { try { lstatSync(path); return true; } catch { return false; } };
34
+ const exists = (path) => existsSync(path);
35
+ const realOf = (path) => { try { return realpathSync(path); } catch { return resolve(path); } };
36
+
37
+ /**
38
+ * @param {object} deps
39
+ * @param {object} deps.state createTeamState(...)
40
+ * @param {Function} deps.git createGitRunner(...)
41
+ * @param {object} deps.locks createLocks()
42
+ * @param {object} deps.worktrees createTeamWorktrees(...)
43
+ * @param {object} deps.claims createTeamClaims(...)
44
+ * @param {object} deps.integration createTeamIntegration(...)
45
+ * @param {() => number} [deps.now]
46
+ * @param {(tag: string, detail: any) => void} [deps.log]
47
+ */
48
+ export function createTeamRecovery({ state, git, locks, worktrees, claims, integration, now = Date.now, log = () => {} } = {}) {
49
+ /** A team that was being created: take the half-made pieces apart and make them again. */
50
+ async function recoverCreation(record, report) {
51
+ const plan = record.plan;
52
+ const cwd = plan.projectPath;
53
+ const pieces = [...plan.slices.map((slice) => slice.id), ...(plan.readOnly ? [] : [INTEGRATION_SLICE_ID])].map((sliceId) => worktrees.placeOf(plan, sliceId));
54
+ // Nothing of a team in creation has work in it. Should one piece have some all the same, nothing is removed.
55
+ const registered = (await listWorktrees(git, cwd)).map((entry) => realOf(entry.path));
56
+ for (const piece of pieces) {
57
+ const head = await commitOf(git, cwd, `refs/heads/${piece.branch}`);
58
+ if (head && head !== plan.baseCommit) { report.attention.push({ code: 'branch_has_commits', sliceId: piece.sliceId, branch: piece.branch, head }); return; }
59
+ // Only a folder git knows as a worktree is asked for its changes (git asked in a plain folder answers for the
60
+ // repository around it). A folder under the team's own folder that is no worktree is a checkout that stopped:
61
+ // the team's folder was not there before the creation began.
62
+ if (isDirectory(piece.path) && registered.includes(realOf(piece.path))) {
63
+ const changes = await changesOf(git, piece.path);
64
+ // A checkout that stopped half-way shows the files it did not write as deleted: that is not work.
65
+ if (changes && changes.some((change) => change.index !== 'D' && change.worktree !== 'D')) { report.attention.push({ code: 'unexpected_changes', sliceId: piece.sliceId, path: piece.path }); return; }
66
+ }
67
+ }
68
+ for (const piece of pieces) {
69
+ if (present(piece.path)) {
70
+ await git(['worktree', 'remove', '--force', piece.path], { cwd });
71
+ if (present(piece.path)) rmSync(piece.path, { recursive: true, force: true });
72
+ }
73
+ }
74
+ await git(['worktree', 'prune'], { cwd });
75
+ const built = await worktrees.materialize(plan);
76
+ if (!built.ok) {
77
+ await worktrees.unmake(plan, built.made);
78
+ // Branches the stopped creation had made: they point at the base and hold nothing.
79
+ for (const piece of pieces) {
80
+ if (await commitOf(git, cwd, `refs/heads/${piece.branch}`) === plan.baseCommit) await git(['branch', '-D', piece.branch], { cwd });
81
+ }
82
+ try { rmdirSync(join(worktreesRoot(cwd), plan.teamId)); } catch { /* not empty, or not there */ }
83
+ state.writeTeam(plan.teamId, 'failed', { error: built.failed, failedAt: now(), recovered: true });
84
+ report.actions.push({ action: 'creation_failed', error: built.failed.error });
85
+ return;
86
+ }
87
+ state.writeTeam(plan.teamId, 'planned', { worktrees: built.made.map(({ sliceId, path, branch }) => ({ sliceId, path, branch })), recovered: true });
88
+ report.actions.push({ action: 'creation_completed', worktrees: built.made.length });
89
+ }
90
+
91
+ /** A team that was in the middle of a join or a test run: the integration branch back to the commit before it. */
92
+ async function recoverIntegration(record, report) {
93
+ const teamId = record.teamId;
94
+ const cwd = record.projectPath;
95
+ const under = record.integrating && typeof record.integrating === 'object' ? record.integrating : {};
96
+ const before = under.before || record.integration.head;
97
+ const place = integrationWorktreePath(cwd, teamId);
98
+ const branch = integrationBranchName(teamId);
99
+ if (!isDirectory(place)) {
100
+ // The folder is gone: put it back from the branch first, then carry on as for one that is there.
101
+ await git(['worktree', 'prune'], { cwd });
102
+ const added = await git(['worktree', 'add', '-q', place, branch], { cwd });
103
+ if (!added.ok) { report.attention.push({ code: 'integration_worktree_missing', error: gitSaid(added) }); return; }
104
+ report.actions.push({ action: 'worktree_restored', sliceId: INTEGRATION_SLICE_ID });
105
+ }
106
+ if (await branchAt(git, place) !== branch) {
107
+ // Not the integration worktree as SynaBun left it (a plain folder, another branch): nothing is reset.
108
+ report.attention.push({ code: 'integration_worktree_not_on_its_branch', path: place, branch });
109
+ state.writeTeam(teamId, 'running', { integrating: null, recoveredAt: now() });
110
+ if (under.sliceId && sliceState(record, under.sliceId) === 'integrating') state.writeSlice(teamId, under.sliceId, 'done', { recovered: true });
111
+ return;
112
+ }
113
+ const head = await commitOf(git, place, 'HEAD');
114
+ if (head !== before) {
115
+ // What is on the branch after `before` must be the slice's own commits again (a cherry-pick's copies, or a
116
+ // merge of the slice): only then is going back to `before` no loss.
117
+ const sliceHead = under.sliceHead || (under.sliceId ? await commitOf(git, cwd, `refs/heads/${branchName(teamId, under.sliceId)}`) : null);
118
+ const descends = (await git(['merge-base', '--is-ancestor', before, head], { cwd })).ok;
119
+ const foreign = descends && sliceHead
120
+ ? (await git(['cherry', sliceHead, head, before], { cwd })).stdout.split('\n').filter((each) => each.startsWith('+ ')).length
121
+ : descends && !under.sliceId ? 0 : -1;
122
+ if (foreign !== 0) {
123
+ report.attention.push({ code: 'integration_has_other_commits', head, before, branch });
124
+ state.writeTeam(teamId, 'running', { integrating: null, recoveredAt: now() });
125
+ if (under.sliceId && sliceState(record, under.sliceId) === 'integrating') state.writeSlice(teamId, under.sliceId, 'done', { recovered: true });
126
+ return;
127
+ }
128
+ }
129
+ const clean = await integration.settle(place, before);
130
+ report.actions.push({ action: 'integration_reset', to: before, from: head, clean, phase: under.phase || null });
131
+ if (under.sliceId && sliceState(record, under.sliceId) === 'integrating') {
132
+ state.writeSlice(teamId, under.sliceId, 'done', { recovered: true });
133
+ report.actions.push({ action: 'slice_ready_again', sliceId: under.sliceId });
134
+ }
135
+ state.writeTeam(teamId, 'running', { integrating: null, recoveredAt: now() });
136
+ }
137
+
138
+ /** A team whose landing was under way: where the target branch is now says whether it landed. */
139
+ async function recoverLanding(record, report) {
140
+ const teamId = record.teamId;
141
+ const cwd = record.projectPath;
142
+ const landing = record.landing && typeof record.landing === 'object' ? record.landing : null;
143
+ const ready = record.plan.slices.every((slice) => ['integrated', 'cancelled'].includes(sliceState(record, slice.id)));
144
+ if (!landing) { state.writeTeam(teamId, ready ? 'ready' : 'running', { landing: null, recoveredAt: now() }); return; }
145
+ const at = await commitOf(git, cwd, `refs/heads/${landing.targetBranch}`);
146
+ if (at && at === landing.to) {
147
+ state.writeTeam(teamId, 'merged', { landing: null, landed: { ...landing, at: now(), recovered: true } });
148
+ claims.end(teamId);
149
+ report.actions.push({ action: 'landing_confirmed', targetBranch: landing.targetBranch, to: landing.to });
150
+ return;
151
+ }
152
+ state.writeTeam(teamId, ready ? 'ready' : 'running', { landing: null, recoveredAt: now() });
153
+ report.actions.push({ action: 'landing_not_done', targetBranch: landing.targetBranch, at });
154
+ if (at !== landing.from) report.attention.push({ code: 'target_moved', targetBranch: landing.targetBranch, at, from: landing.from, to: landing.to });
155
+ if (landing.checkout && at === landing.from && isDirectory(landing.checkout)) {
156
+ // The branch did not move. Should the checkout's files have been written before the crash, they show as
157
+ // uncommitted changes there: the user's to look at, never SynaBun's to change.
158
+ const changes = await changesOf(git, landing.checkout);
159
+ const diff = await git(['diff', '--name-only', '-z', '--no-renames', landing.from, landing.to], { cwd });
160
+ const files = new Set(diff.stdout.split('\0').filter(Boolean));
161
+ const touched = (changes || []).map((change) => change.path).filter((path) => files.has(path));
162
+ if (touched.length) report.attention.push({ code: 'checkout_may_be_half_updated', checkout: landing.checkout, files: touched.slice(0, 50), userShouldRun: [`git -C ${landing.checkout} status`] });
163
+ }
164
+ }
165
+
166
+ /** Worktrees whose folder is gone, slices left in the middle of a join. */
167
+ async function recoverPieces(record, report) {
168
+ const teamId = record.teamId;
169
+ const cwd = record.projectPath;
170
+ let registered = await listWorktrees(git, cwd);
171
+ for (const sliceId of [...record.plan.slices.map((slice) => slice.id), ...(record.plan.readOnly ? [] : [INTEGRATION_SLICE_ID])]) {
172
+ const current = sliceId === INTEGRATION_SLICE_ID ? null : sliceState(record, sliceId);
173
+ if (current && SETTLED_SLICE_STATES.includes(current) && current !== 'integrated') continue;
174
+ const info = await worktrees.pieceInfo(record, sliceId, registered);
175
+ if (info.exists && info.registered) {
176
+ if (!info.onBranch) report.attention.push({ code: 'not_on_its_branch', sliceId, path: info.path, branch: info.branch, on: info.checkedOut });
177
+ if (sliceId === INTEGRATION_SLICE_ID && info.head && info.head !== record.integration.head) report.attention.push({ code: 'integration_moved', head: info.head, recorded: record.integration.head });
178
+ continue;
179
+ }
180
+ if (info.exists && !info.registered) { report.attention.push({ code: 'folder_is_not_a_worktree', sliceId, path: info.path }); continue; }
181
+ await git(['worktree', 'prune'], { cwd });
182
+ if (!info.branchExists) {
183
+ if (sliceId === INTEGRATION_SLICE_ID) {
184
+ // The branch is gone: start it again where SynaBun left it, when that commit is still there.
185
+ const at = await commitOf(git, cwd, record.integration.head);
186
+ const added = at ? await git(['worktree', 'add', '-q', '-b', info.branch, info.path, at], { cwd }) : null;
187
+ if (added?.ok) report.actions.push({ action: 'integration_branch_restored', at });
188
+ else report.attention.push({ code: 'integration_branch_missing', branch: info.branch });
189
+ } else if (current !== 'integrated') {
190
+ state.writeSlice(teamId, sliceId, 'failed', { reason: 'its branch and its worktree are gone', failedAt: now() });
191
+ report.actions.push({ action: 'slice_failed', sliceId, reason: 'missing' });
192
+ }
193
+ continue;
194
+ }
195
+ const added = await git(['worktree', 'add', '-q', info.path, info.branch], { cwd });
196
+ if (added.ok) report.actions.push({ action: 'worktree_restored', sliceId });
197
+ else report.attention.push({ code: 'worktree_not_restored', sliceId, path: info.path, error: gitSaid(added) });
198
+ registered = await listWorktrees(git, cwd);
199
+ }
200
+ const fresh = state.record(teamId);
201
+ for (const slice of fresh.plan.slices) {
202
+ if (sliceState(fresh, slice.id) === 'integrating' && fresh.state !== 'integrating') {
203
+ state.writeSlice(teamId, slice.id, 'done', { recovered: true });
204
+ report.actions.push({ action: 'slice_ready_again', sliceId: slice.id });
205
+ }
206
+ }
207
+ // An operation left open in a slice's worktree is the worker's to see; it is only said here.
208
+ for (const slice of fresh.plan.slices) {
209
+ const path = worktrees.placeOf(fresh.plan, slice.id).path;
210
+ if (SETTLED_SLICE_STATES.includes(sliceState(fresh, slice.id))) continue;
211
+ if (await branchAt(git, path) !== branchName(teamId, slice.id)) continue; // said above, or not a worktree
212
+ const busy = await operationsUnderWay(git, path, { exists });
213
+ if (busy.cherryPick || busy.rebase || busy.revert) report.attention.push({ code: 'slice_operation_under_way', sliceId: slice.id, path });
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Bring every team (or one) to a state that matches git and the disk. Call it once at start-up, before any other
219
+ * function of a team. Safe to call again: a team that is consistent is left as it is.
220
+ *
221
+ * @param {{ teamId?: string }} [options]
222
+ * @returns {Promise<{ ok: true, teams: { teamId: string, state: string, was: string, actions: object[], attention: object[] }[], claims: object[] }>}
223
+ */
224
+ async function recover({ teamId = null } = {}) {
225
+ const out = [];
226
+ for (const entry of state.teams()) {
227
+ if (teamId && entry.teamId !== teamId) continue;
228
+ const first = state.record(entry.teamId);
229
+ if (!first || first.removed || TERMINAL_TEAM_STATES.includes(first.state)) continue;
230
+ const report = { teamId: first.teamId, was: first.state, state: first.state, actions: [], attention: [] };
231
+ out.push(report);
232
+ const repo = await repositoryOf(git, first.projectPath);
233
+ if (!repo.ok) { report.attention.push({ code: repo.code, message: repo.message }); continue; }
234
+ try {
235
+ await locks.run(repoLockKey(first.projectPath), () => locks.run(`team:${first.teamId}`, async () => {
236
+ const record = state.record(first.teamId);
237
+ if (record.state === 'creating') await recoverCreation(record, report);
238
+ else if (record.state === 'integrating') await recoverIntegration(record, report);
239
+ else if (record.state === 'landing') await recoverLanding(record, report);
240
+ const after = state.record(first.teamId);
241
+ if (!TERMINAL_TEAM_STATES.includes(after.state) && after.state !== 'creating') await recoverPieces(after, report);
242
+ // An empty folder a failed creation left behind.
243
+ if (after.state === 'failed') { try { rmdirSync(join(worktreesRoot(after.projectPath), after.teamId)); } catch { /* not empty, or not there */ } }
244
+ }));
245
+ } catch (error) {
246
+ log('teams:recover-failed', { teamId: first.teamId, error: error?.message || String(error) });
247
+ report.attention.push({ code: 'recovery_failed', message: error?.message || String(error) });
248
+ }
249
+ report.state = state.record(first.teamId)?.state || report.state;
250
+ }
251
+ const restored = claims.restore();
252
+ return { ok: true, teams: out, claims: restored };
253
+ }
254
+
255
+ return { recover };
256
+ }