synabun 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +169 -0
  4. package/browser-extension/engine.js +477 -0
  5. package/browser-extension/icons/icon-128.png +0 -0
  6. package/browser-extension/icons/icon-16.png +0 -0
  7. package/browser-extension/icons/icon-32.png +0 -0
  8. package/browser-extension/icons/icon-48.png +0 -0
  9. package/browser-extension/icons/status-off-16.png +0 -0
  10. package/browser-extension/icons/status-off-32.png +0 -0
  11. package/browser-extension/icons/status-off-48.png +0 -0
  12. package/browser-extension/icons/status-on-16.png +0 -0
  13. package/browser-extension/icons/status-on-32.png +0 -0
  14. package/browser-extension/icons/status-on-48.png +0 -0
  15. package/browser-extension/manifest.json +56 -0
  16. package/browser-extension/popup-strings.js +244 -0
  17. package/browser-extension/popup-view.js +151 -0
  18. package/browser-extension/popup.css +165 -0
  19. package/browser-extension/popup.html +105 -0
  20. package/browser-extension/popup.js +347 -0
  21. package/browser-extension/protocol.js +226 -0
  22. package/browser-extension/service-worker.js +267 -0
  23. package/browser-extension/setup-content.js +36 -0
  24. package/browser-extension/tokens.css +326 -0
  25. package/docs/browser-extension-bridge.md +84 -0
  26. package/docs/whatsapp.md +1 -1
  27. package/mcp-server/dist/http.d.ts +2 -0
  28. package/mcp-server/dist/http.d.ts.map +1 -1
  29. package/mcp-server/dist/http.js +9 -1
  30. package/mcp-server/dist/http.js.map +1 -1
  31. package/mcp-server/dist/index.d.ts +11 -0
  32. package/mcp-server/dist/index.d.ts.map +1 -1
  33. package/mcp-server/dist/index.js +38 -3
  34. package/mcp-server/dist/index.js.map +1 -1
  35. package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
  36. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
  37. package/mcp-server/dist/services/browser-route-flow.js +10 -3
  38. package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
  39. package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
  40. package/mcp-server/dist/services/codex-config-heal.js +7 -0
  41. package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
  42. package/mcp-server/dist/services/neural-interface.d.ts +94 -3
  43. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.js +168 -23
  45. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  46. package/mcp-server/dist/services/team-context.d.ts +18 -0
  47. package/mcp-server/dist/services/team-context.d.ts.map +1 -0
  48. package/mcp-server/dist/services/team-context.js +29 -0
  49. package/mcp-server/dist/services/team-context.js.map +1 -0
  50. package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
  51. package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
  52. package/mcp-server/dist/services/tool-catalog.js +22 -6
  53. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  54. package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
  55. package/mcp-server/dist/services/tool-list.js +4 -0
  56. package/mcp-server/dist/services/tool-list.js.map +1 -1
  57. package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
  58. package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
  59. package/mcp-server/dist/services/tool-runtime.js +18 -1
  60. package/mcp-server/dist/services/tool-runtime.js.map +1 -1
  61. package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
  62. package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
  63. package/mcp-server/dist/tools/agent-definition.js +483 -0
  64. package/mcp-server/dist/tools/agent-definition.js.map +1 -0
  65. package/mcp-server/dist/tools/agents.d.ts +91 -9
  66. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  67. package/mcp-server/dist/tools/agents.js +161 -20
  68. package/mcp-server/dist/tools/agents.js.map +1 -1
  69. package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
  70. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  71. package/mcp-server/dist/tools/browser-advanced.js +70 -6
  72. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  73. package/mcp-server/dist/tools/git-tools.d.ts +4 -2
  74. package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
  75. package/mcp-server/dist/tools/git-tools.js +283 -2
  76. package/mcp-server/dist/tools/git-tools.js.map +1 -1
  77. package/mcp-server/dist/tools/morelogin.d.ts +8 -2
  78. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  79. package/mcp-server/dist/tools/morelogin.js +22 -5
  80. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  81. package/mcp-server/dist/tools/team.d.ts +32 -0
  82. package/mcp-server/dist/tools/team.d.ts.map +1 -0
  83. package/mcp-server/dist/tools/team.js +87 -0
  84. package/mcp-server/dist/tools/team.js.map +1 -0
  85. package/mcp-server/package-lock.json +2 -2
  86. package/mcp-server/package.json +1 -1
  87. package/mcp-server/src/http.ts +9 -1
  88. package/mcp-server/src/index.ts +34 -4
  89. package/mcp-server/src/services/browser-route-flow.ts +12 -5
  90. package/mcp-server/src/services/codex-config-heal.ts +7 -0
  91. package/mcp-server/src/services/neural-interface.ts +190 -29
  92. package/mcp-server/src/services/team-context.ts +27 -0
  93. package/mcp-server/src/services/tool-catalog.ts +26 -8
  94. package/mcp-server/src/services/tool-list.ts +4 -0
  95. package/mcp-server/src/services/tool-runtime.ts +21 -2
  96. package/mcp-server/src/tools/agent-definition.ts +458 -0
  97. package/mcp-server/src/tools/agents.ts +175 -19
  98. package/mcp-server/src/tools/browser-advanced.ts +60 -6
  99. package/mcp-server/src/tools/git-tools.ts +249 -3
  100. package/mcp-server/src/tools/morelogin.ts +20 -5
  101. package/mcp-server/src/tools/team.ts +97 -0
  102. package/neural-interface/i18n/en.json +1117 -47
  103. package/neural-interface/i18n/pt-BR.json +1117 -47
  104. package/neural-interface/lib/account-usage.js +1 -1
  105. package/neural-interface/lib/agents/density.js +101 -0
  106. package/neural-interface/lib/agents/forge-host.js +223 -0
  107. package/neural-interface/lib/agents/native-export-targets.js +190 -0
  108. package/neural-interface/lib/agents/native-export.js +365 -0
  109. package/neural-interface/lib/agents/registry.js +840 -0
  110. package/neural-interface/lib/agents/resolve.js +544 -0
  111. package/neural-interface/lib/agents/schema.js +642 -0
  112. package/neural-interface/lib/agents/split.js +37 -0
  113. package/neural-interface/lib/agents-studio-api.js +591 -0
  114. package/neural-interface/lib/assistant-api.js +76 -7
  115. package/neural-interface/lib/assistant-catalog.js +2 -0
  116. package/neural-interface/lib/assistant-continuity.js +49 -0
  117. package/neural-interface/lib/assistant-dispatch.js +229 -102
  118. package/neural-interface/lib/assistant-persona.js +105 -8
  119. package/neural-interface/lib/assistant-route-gate.js +24 -9
  120. package/neural-interface/lib/assistant-router.js +384 -42
  121. package/neural-interface/lib/assistant-run-tail.js +151 -0
  122. package/neural-interface/lib/assistant-run-wait.js +183 -0
  123. package/neural-interface/lib/assistant-runtime.js +440 -93
  124. package/neural-interface/lib/assistant-task-prompt.js +11 -2
  125. package/neural-interface/lib/assistant-usage.js +3 -2
  126. package/neural-interface/lib/automation-approval.js +2 -2
  127. package/neural-interface/lib/browser-close-evidence.js +80 -0
  128. package/neural-interface/lib/browser-default.js +210 -0
  129. package/neural-interface/lib/browser-extension-adapter.js +255 -0
  130. package/neural-interface/lib/browser-extension-bridge.js +418 -0
  131. package/neural-interface/lib/browser-extension-folder.js +116 -0
  132. package/neural-interface/lib/browser-extension-setup.js +140 -0
  133. package/neural-interface/lib/browser-profile-choices.js +3 -3
  134. package/neural-interface/lib/browser-tool-policy.js +1 -1
  135. package/neural-interface/lib/claude-account-links.js +301 -0
  136. package/neural-interface/lib/claude-accounts.js +45 -20
  137. package/neural-interface/lib/claude-agent-bridge.js +142 -10
  138. package/neural-interface/lib/claude-model-catalog.js +6 -0
  139. package/neural-interface/lib/claude-panel-session.js +33 -0
  140. package/neural-interface/lib/codex-accounts.js +67 -24
  141. package/neural-interface/lib/coordination/README.md +384 -0
  142. package/neural-interface/lib/coordination/service.js +563 -0
  143. package/neural-interface/lib/coordination/store.js +1138 -0
  144. package/neural-interface/lib/db.js +22 -1
  145. package/neural-interface/lib/effort-levels.js +10 -1
  146. package/neural-interface/lib/memory-list-page.js +49 -0
  147. package/neural-interface/lib/memory-list-stamp.js +60 -0
  148. package/neural-interface/lib/morelogin-outside-close.js +186 -0
  149. package/neural-interface/lib/morelogin-profile-failures.js +206 -0
  150. package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
  151. package/neural-interface/lib/morelogin.js +194 -8
  152. package/neural-interface/lib/native-loop-runtime.js +20 -0
  153. package/neural-interface/lib/opencode-build-preflight.js +16 -1
  154. package/neural-interface/lib/opencode-native-boundary.js +83 -13
  155. package/neural-interface/lib/opencode-serve-records.js +14 -9
  156. package/neural-interface/lib/page-session.js +1 -1
  157. package/neural-interface/lib/peer-identity.js +60 -21
  158. package/neural-interface/lib/process-identity.js +68 -7
  159. package/neural-interface/lib/request-gate.js +3 -0
  160. package/neural-interface/lib/screenshot-location.js +33 -0
  161. package/neural-interface/lib/skills/creation.js +1 -1
  162. package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
  163. package/neural-interface/lib/studio-attention.js +56 -0
  164. package/neural-interface/lib/teams/README.md +382 -0
  165. package/neural-interface/lib/teams/api.js +287 -0
  166. package/neural-interface/lib/teams/brief.js +185 -0
  167. package/neural-interface/lib/teams/claims.js +315 -0
  168. package/neural-interface/lib/teams/git.js +293 -0
  169. package/neural-interface/lib/teams/index.js +122 -0
  170. package/neural-interface/lib/teams/integration.js +580 -0
  171. package/neural-interface/lib/teams/landing.js +184 -0
  172. package/neural-interface/lib/teams/recovery.js +256 -0
  173. package/neural-interface/lib/teams/scheduler.js +1474 -0
  174. package/neural-interface/lib/teams/schema.js +559 -0
  175. package/neural-interface/lib/teams/state.js +181 -0
  176. package/neural-interface/lib/teams/test-runner.js +86 -0
  177. package/neural-interface/lib/teams/test-sandbox.js +99 -0
  178. package/neural-interface/lib/teams/worktrees.js +757 -0
  179. package/neural-interface/lib/tool-permission-choices.js +226 -0
  180. package/neural-interface/lib/whatsapp/cards.js +24 -10
  181. package/neural-interface/lib/worker-confinement.js +206 -6
  182. package/neural-interface/package-lock.json +2 -2
  183. package/neural-interface/package.json +1 -1
  184. package/neural-interface/public/extension-setup.html +107 -0
  185. package/neural-interface/public/index.html +52 -12
  186. package/neural-interface/public/shared/agent-runtime-options.js +3 -1
  187. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
  188. package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
  189. package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
  190. package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
  191. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
  192. package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
  193. package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
  194. package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
  195. package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
  196. package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
  197. package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
  198. package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
  199. package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
  200. package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
  201. package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
  202. package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
  203. package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
  204. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
  205. package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
  206. package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
  207. package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
  208. package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
  209. package/neural-interface/public/shared/agy/agy-panel.js +142 -28
  210. package/neural-interface/public/shared/agy/agy-styles.js +25 -5
  211. package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
  212. package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
  213. package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
  214. package/neural-interface/public/shared/assistant/asst-control.js +3 -0
  215. package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
  216. package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
  217. package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
  218. package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
  219. package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
  220. package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
  221. package/neural-interface/public/shared/assistant/asst-render.js +36 -6
  222. package/neural-interface/public/shared/assistant/asst-route.js +78 -12
  223. package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
  224. package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
  225. package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
  226. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
  227. package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
  228. package/neural-interface/public/shared/assistant/asst-state.js +66 -1
  229. package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
  230. package/neural-interface/public/shared/assistant/route-identity.js +16 -0
  231. package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
  232. package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
  233. package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
  234. package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
  235. package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
  236. package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
  237. package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
  238. package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
  239. package/neural-interface/public/shared/code-copy.js +120 -0
  240. package/neural-interface/public/shared/constants.js +7 -0
  241. package/neural-interface/public/shared/context-menu-model.js +1 -0
  242. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  243. package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
  244. package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
  245. package/neural-interface/public/shared/cp/cp-styles.js +9 -0
  246. package/neural-interface/public/shared/dom-change-flag.js +66 -0
  247. package/neural-interface/public/shared/dom-morph.js +124 -0
  248. package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
  249. package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
  250. package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
  251. package/neural-interface/public/shared/html-shell.js +33 -4
  252. package/neural-interface/public/shared/i18n.js +14 -1
  253. package/neural-interface/public/shared/idle-queue.js +78 -0
  254. package/neural-interface/public/shared/iface-config.js +227 -0
  255. package/neural-interface/public/shared/lazy-module.js +108 -0
  256. package/neural-interface/public/shared/memory-list.js +117 -0
  257. package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
  258. package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
  259. package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
  260. package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
  261. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
  262. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
  264. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
  265. package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
  269. package/neural-interface/public/shared/schedules-view.js +2 -2
  270. package/neural-interface/public/shared/session-project-items.js +11 -0
  271. package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
  272. package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
  273. package/neural-interface/public/shared/settings/settings-ia.js +4 -2
  274. package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
  275. package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
  276. package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
  277. package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
  278. package/neural-interface/public/shared/sidepanel-shown.js +73 -0
  279. package/neural-interface/public/shared/storage.js +6 -1
  280. package/neural-interface/public/shared/studio-attention.js +83 -0
  281. package/neural-interface/public/shared/styles.css +682 -50
  282. package/neural-interface/public/shared/term-browser-tabs.js +34 -0
  283. package/neural-interface/public/shared/transcript-rows.js +334 -0
  284. package/neural-interface/public/shared/tray-auto-close.js +106 -0
  285. package/neural-interface/public/shared/ui-agents.js +97 -0
  286. package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
  287. package/neural-interface/public/shared/ui-automation-studio.js +3 -3
  288. package/neural-interface/public/shared/ui-claude-panel.js +162 -95
  289. package/neural-interface/public/shared/ui-code-copy.js +256 -0
  290. package/neural-interface/public/shared/ui-codex-panel.js +14 -10
  291. package/neural-interface/public/shared/ui-context-menu.js +1 -1
  292. package/neural-interface/public/shared/ui-file-explorer.js +2 -3
  293. package/neural-interface/public/shared/ui-games.js +1 -1
  294. package/neural-interface/public/shared/ui-loading.js +12 -1
  295. package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
  296. package/neural-interface/public/shared/ui-menubar.js +23 -0
  297. package/neural-interface/public/shared/ui-native-loop-router.js +1 -1
  298. package/neural-interface/public/shared/ui-navbar.js +15 -9
  299. package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
  300. package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
  301. package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
  302. package/neural-interface/public/shared/ui-sessions.js +3 -3
  303. package/neural-interface/public/shared/ui-settings-entry.js +55 -0
  304. package/neural-interface/public/shared/ui-settings.js +355 -400
  305. package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
  306. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
  307. package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
  308. package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
  309. package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
  310. package/neural-interface/public/shared/ui-styleguide.js +10 -2
  311. package/neural-interface/public/shared/ui-sync.js +5 -0
  312. package/neural-interface/public/shared/ui-terminal.js +13 -9
  313. package/neural-interface/public/shared/ui-tooltip.js +28 -7
  314. package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
  315. package/neural-interface/public/shared/ui-tray-columns.js +375 -0
  316. package/neural-interface/public/shared/ui-whiteboard.js +51 -6
  317. package/neural-interface/public/shared/ui-worker-end.js +28 -1
  318. package/neural-interface/public/shared/ui-workspaces.js +13 -0
  319. package/neural-interface/public/shared/window-keys.js +71 -0
  320. package/neural-interface/public/variant/2d/main.js +2 -0
  321. package/neural-interface/public/variant/3d/app.js +620 -0
  322. package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
  323. package/neural-interface/public/variant/3d/main.js +21 -544
  324. package/neural-interface/public/variant/3d/map-controls.js +4 -2
  325. package/neural-interface/public/vendor/fonts/fonts.css +508 -0
  326. package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
  327. package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
  328. package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
  329. package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
  330. package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
  331. package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
  332. package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
  333. package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
  334. package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
  335. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
  336. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
  337. package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
  338. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  339. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
  340. package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
  341. package/neural-interface/public/vendor/fonts/manifest.json +142 -0
  342. package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
  343. package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
  344. package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
  345. package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
  346. package/neural-interface/scripts/boot-graph.mjs +270 -0
  347. package/neural-interface/scripts/vendor-fonts.mjs +124 -0
  348. package/neural-interface/server.js +1050 -140
  349. package/npm-shrinkwrap.json +2 -2
  350. package/package.json +3 -1
  351. package/skills/agent-forge/SKILL.md +182 -0
  352. package/skills/agent-forge/evals/evals.json +56 -0
  353. package/skills/agent-forge/references/definition-fields.md +61 -0
  354. package/skills/agent-forge/references/examples.md +105 -0
  355. package/skills/agent-forge/references/instructions.md +51 -0
  356. package/skills/agent-forge/references/review-and-export.md +84 -0
@@ -0,0 +1,315 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: path claims, and what a slice may write
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A plan says which files each slice owns (lib/teams/schema.js: no file has two owners). While a team works, each
6
+ // slice holds its owned paths as claims in the coordination store (lib/coordination/store.js), taken when the team
7
+ // starts and given back when the slice finishes. Three things read them:
8
+ //
9
+ // checkWrite(teamId, sliceId, path) may this slice write this file? Allow or deny, with the slice that owns it.
10
+ // the worker guard lib/worker-confinement.js asks the same question before a worker's write
11
+ // (the slice's context is registered there by its worktree, so a run whose
12
+ // working directory is a slice's worktree is confined without being told).
13
+ // verifyOwnership(teamId, sliceId) after the fact: what the slice's branch changed, against what it owns.
14
+ //
15
+ // The rule, for a file of the project (a path relative to the slice's worktree):
16
+ // - the slice's own (pathOwner says so, and its claim is still held): allowed;
17
+ // - a dependency lockfile: the plan's lockfile owner only, by rule, whatever pattern covers it;
18
+ // - a file git ignores (build output, node_modules, a cache): allowed. It is never committed, so it never reaches
19
+ // another slice;
20
+ // - anything else, another slice's file or one nobody owns: denied. The worker asks the owner over the team
21
+ // channel instead.
22
+ // - `.git` and `.worktrees`: nobody's.
23
+ //
24
+ // The guard reads tool calls and command lines. A program a worker runs (a script, a build, a test runner) writes
25
+ // what it writes without being seen: that limit is the guard's own (lib/worker-confinement.js says it at its top).
26
+ // verifyOwnership is what closes it: a slice whose branch changed a file outside its ownership is rejected when it
27
+ // finishes (lib/teams/integration.js `finishSlice`), and nothing of it is joined.
28
+
29
+ import { realpathSync } from 'node:fs';
30
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
31
+ import { EVENT_KINDS, teamRecipient } from '../coordination/store.js';
32
+ import { runGitReadSync } from '../git-read.js';
33
+ import { realPlace, registerTeamSlice, unregisterTeamSlice } from '../worker-confinement.js';
34
+ import {
35
+ RESERVED_PATH_ROOTS, claimablePaths, globsOverlap, integrationBranchName, isLockfilePath, isTeamSlug, normalizeRelPath, pathOwner,
36
+ branchName, worktreePath,
37
+ } from './schema.js';
38
+ import { parseNameStatus, parseStatus } from './git.js';
39
+ import { SETTLED_SLICE_STATES, TERMINAL_TEAM_STATES, planSlice, refuse, sliceState } from './state.js';
40
+
41
+ /** Dependency manifests by file name: changing one is the lockfile owner's job (a warning, not a refusal). */
42
+ export const MANIFEST_NAMES = Object.freeze([
43
+ 'package.json', 'pnpm-workspace.yaml', 'cargo.toml', 'pyproject.toml', 'requirements.txt', 'pipfile', 'go.mod', 'gemfile',
44
+ 'composer.json', 'pubspec.yaml', 'podfile', 'mix.exs', 'deno.json', 'build.gradle', 'build.gradle.kts', 'pom.xml',
45
+ ]);
46
+ export const isManifestPath = (relPath) => MANIFEST_NAMES.includes(String(relPath || '').split('/').pop().toLowerCase());
47
+
48
+ /** Slice states in which a slice holds its claims: it is waiting for a worker or one is working it. */
49
+ const CLAIMING_SLICE_STATES = new Set(['planned', 'pending', 'blocked', 'running']);
50
+
51
+ const realOf = (path) => { try { return realpathSync(path); } catch { return resolve(path); } };
52
+
53
+ /** Is this project-relative path ignored by git in this worktree? Asked of git, as a read. */
54
+ function gitIgnores(worktree, relPath) {
55
+ try {
56
+ const result = runGitReadSync(worktree, ['check-ignore', '-q', '--', relPath], { timeout: 5000, stdio: ['ignore', 'ignore', 'ignore'] });
57
+ return !result.error && result.status === 0;
58
+ } catch {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * @param {object} deps
65
+ * @param {object} deps.store a coordination store
66
+ * @param {object} deps.state createTeamState(...)
67
+ * @param {Function} [deps.git] createGitRunner(...): needed by verifyOwnership only
68
+ * @param {(worktree: string, relPath: string) => boolean} [deps.isIgnored] default: `git check-ignore`
69
+ * @param {{ register: Function, unregister: Function }} [deps.registry] where slice contexts are registered for
70
+ * the worker guard (default: lib/worker-confinement.js's own registry)
71
+ * @param {(tag: string, detail: any) => void} [deps.log]
72
+ */
73
+ export function createTeamClaims({ store, state, git = null, isIgnored = gitIgnores, registry = { register: registerTeamSlice, unregister: unregisterTeamSlice }, log = () => {} } = {}) {
74
+ const plans = new Map(); // teamId → the team's plan (a plan does not change once the team exists)
75
+ const contexts = new Map(); // `${teamId}/${sliceId}` → the context registered with the worker guard
76
+
77
+ function planOf(teamId) {
78
+ if (plans.has(teamId)) return plans.get(teamId);
79
+ const record = isTeamSlug(teamId) ? state.record(teamId) : null;
80
+ if (!record) return null;
81
+ plans.set(teamId, record.plan);
82
+ return record.plan;
83
+ }
84
+
85
+ /** Does the slice own something inside this folder? (`mkdir -p src` on the way to `src/api/x.js`.) */
86
+ function ownsBeneath(plan, sliceId, relPath) {
87
+ if (/[*?[\]{}!]/.test(relPath)) return false;
88
+ const slice = plan.slices.find((each) => each.id === sliceId);
89
+ return !!slice && slice.ownedPaths.some((glob) => globsOverlap(`${relPath}/**`, glob));
90
+ }
91
+
92
+ /**
93
+ * The answer for a project-relative path. `allow`, the slice that owns the file (`owner`, null when nobody does),
94
+ * a `code` and whether the slice owns something beneath the path (`beneath`, for a folder).
95
+ */
96
+ function checkRelative(teamId, sliceId, relPath) {
97
+ const plan = planOf(teamId);
98
+ if (!plan || !plan.slices.some((slice) => slice.id === sliceId)) return { allow: false, owner: null, relPath: String(relPath ?? ''), code: 'unknown_slice', beneath: false };
99
+ const path = normalizeRelPath(relPath);
100
+ if (path === null) return { allow: false, owner: null, relPath: String(relPath ?? ''), code: 'invalid_path', beneath: false };
101
+ if (RESERVED_PATH_ROOTS.includes(path.split('/')[0].toLowerCase())) return { allow: false, owner: null, relPath: path, code: 'reserved_path', beneath: false };
102
+ const owner = pathOwner(plan, path);
103
+ const beneath = ownsBeneath(plan, sliceId, path);
104
+ if (owner === sliceId) {
105
+ if (isLockfilePath(path)) return { allow: true, owner, relPath: path, code: 'lockfile_owner', beneath };
106
+ // The claim is what says the slice is at work on it: a slice that finished gave its claims back.
107
+ const held = store.claimsFor({ teamId, sliceId, path }).length > 0;
108
+ return held ? { allow: true, owner, relPath: path, code: 'owned', beneath } : { allow: false, owner, relPath: path, code: 'claim_released', beneath };
109
+ }
110
+ if (plan.readOnly) return { allow: false, owner: null, relPath: path, code: 'unowned', beneath: false };
111
+ let ignored = false;
112
+ try { ignored = isIgnored(worktreePath(plan.projectPath, teamId, sliceId), path) === true; } catch { ignored = false; }
113
+ if (ignored) return { allow: true, owner, relPath: path, code: 'ignored', beneath };
114
+ return { allow: false, owner, relPath: path, code: isLockfilePath(path) ? 'lockfile' : owner ? 'other_slice' : 'unowned', beneath };
115
+ }
116
+
117
+ const DENIALS = {
118
+ unknown_slice: () => 'That slice is not part of the team.',
119
+ invalid_path: (v) => `"${v.relPath.slice(0, 200)}" is not a path inside the project.`,
120
+ reserved_path: (v) => `${v.relPath} is git's own data or a worktree folder: no slice writes there.`,
121
+ outside_worktree: (v) => `${v.relPath} is outside this slice's worktree: a slice writes its own worktree only, never the user's checkout or another slice's.`,
122
+ claim_released: (v) => `${v.relPath} is this slice's, but the slice has finished and gave its claims back.`,
123
+ lockfile: (v) => (v.owner ? `${v.relPath} is a dependency lockfile: only the lockfile owner (slice "${v.owner}") changes it.` : `${v.relPath} is a dependency lockfile and this team has no lockfile owner: nobody changes it.`),
124
+ other_slice: (v) => `${v.relPath} belongs to slice "${v.owner}".`,
125
+ unowned: (v) => `${v.relPath} is not owned by any slice of this team.`,
126
+ };
127
+
128
+ /**
129
+ * May this slice write this file? `path` is relative to the project (the slice's worktree is a checkout of it), or
130
+ * absolute: then it must be inside the slice's own worktree.
131
+ * @returns {{ allow: boolean, decision: 'allow'|'deny', owner: string|null, relPath: string, code: string, message: string }}
132
+ */
133
+ function checkWrite(teamId, sliceId, path) {
134
+ let verdict;
135
+ if (typeof path === 'string' && isAbsolute(path)) {
136
+ const plan = planOf(teamId);
137
+ const known = plan?.slices.some((slice) => slice.id === sliceId);
138
+ const root = known ? realOf(worktreePath(plan.projectPath, teamId, sliceId)) : null;
139
+ const rel = root ? relative(root, realPlace(resolve(path))) : null;
140
+ if (!known) verdict = { allow: false, owner: null, relPath: path, code: 'unknown_slice', beneath: false };
141
+ else if (!rel || rel.startsWith('..') || isAbsolute(rel)) verdict = { allow: false, owner: null, relPath: path, code: 'outside_worktree', beneath: false };
142
+ else verdict = checkRelative(teamId, sliceId, rel.split(sep).join('/'));
143
+ } else {
144
+ verdict = checkRelative(teamId, sliceId, path);
145
+ }
146
+ const message = verdict.allow ? '' : `${(DENIALS[verdict.code] || DENIALS.unowned)(verdict)} Ask ${verdict.owner && verdict.owner !== sliceId ? `slice "${verdict.owner}"` : 'the team'} over the team channel instead of writing it.`;
147
+ return { allow: verdict.allow, decision: verdict.allow ? 'allow' : 'deny', owner: verdict.owner, relPath: verdict.relPath, code: verdict.code, message };
148
+ }
149
+
150
+ /** What the worker guard gets for a slice (lib/worker-confinement.js `resolveWorkerConfinement({ team })`). */
151
+ function context(teamId, sliceId) {
152
+ const plan = planOf(teamId);
153
+ const slice = plan?.slices.find((each) => each.id === sliceId);
154
+ if (!slice) return null;
155
+ return Object.freeze({
156
+ teamId, sliceId,
157
+ worktree: realOf(worktreePath(plan.projectPath, teamId, sliceId)),
158
+ projectPath: plan.projectPath,
159
+ ownedPaths: Object.freeze([...slice.ownedPaths]),
160
+ lockfileOwner: slice.lockfileOwner === true,
161
+ channel: teamRecipient(teamId),
162
+ check: (relPath) => checkRelative(teamId, sliceId, relPath),
163
+ });
164
+ }
165
+
166
+ function register(teamId, sliceId) {
167
+ const made = context(teamId, sliceId);
168
+ if (!made) return null;
169
+ const key = `${teamId}/${sliceId}`;
170
+ try { registry.register(made); contexts.set(key, made); } catch (error) { log('teams:register-failed', { teamId, sliceId, error: error?.message || String(error) }); }
171
+ return made;
172
+ }
173
+
174
+ function claimSlice(plan, sliceId, runId) {
175
+ const globs = claimablePaths(plan, sliceId);
176
+ if (!globs.length) return { ok: true, claims: [] }; // a slice that owns lockfiles only: owned by rule
177
+ return store.claim({ teamId: plan.teamId, sliceId, runId: runId || null, globs });
178
+ }
179
+
180
+ function announceConflict(teamId, sliceId, conflicts) {
181
+ try {
182
+ store.append({
183
+ teamId, kind: EVENT_KINDS.CLAIM_CONFLICT,
184
+ payload: { teamId, sliceId, conflicts: conflicts.map((each) => ({ glob: each.glob, heldBy: each.heldBy?.sliceId || null })) },
185
+ });
186
+ } catch (error) { log('teams:announce-failed', { teamId, error: error?.message || String(error) }); }
187
+ }
188
+
189
+ /**
190
+ * Take every slice's claims: called when the team starts. All of them or none: a clash (which a valid plan does
191
+ * not have) gives back what this call took and answers `CLAIM_CONFLICT`.
192
+ * @param {string} teamId
193
+ * @param {{ only?: (sliceId: string) => boolean }} [options] which slices (default: every slice)
194
+ */
195
+ function start(teamId, { only = null } = {}) {
196
+ const plan = planOf(teamId);
197
+ if (!plan) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
198
+ const taken = [];
199
+ const claims = [];
200
+ for (const slice of plan.slices) {
201
+ if (only && !only(slice.id)) continue;
202
+ const result = claimSlice(plan, slice.id, null);
203
+ if (!result.ok) {
204
+ for (const sliceId of taken) store.release({ teamId, sliceId });
205
+ announceConflict(teamId, slice.id, result.conflicts);
206
+ return refuse('CLAIM_CONFLICT', `Slice "${slice.id}" could not take its files: ${result.conflicts.map((each) => `${each.glob} is held by slice "${each.heldBy.sliceId}"`).join('; ')}.`, { sliceId: slice.id, conflicts: result.conflicts });
207
+ }
208
+ taken.push(slice.id);
209
+ claims.push(...result.claims);
210
+ register(teamId, slice.id);
211
+ }
212
+ return { ok: true, claims };
213
+ }
214
+
215
+ /** A slice goes to a run: its claims are (re)taken in that run's name and its context registered. */
216
+ function assign(teamId, sliceId, runId = null) {
217
+ const plan = planOf(teamId);
218
+ if (!plan || !plan.slices.some((slice) => slice.id === sliceId)) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
219
+ const result = claimSlice(plan, sliceId, runId);
220
+ if (!result.ok) {
221
+ announceConflict(teamId, sliceId, result.conflicts);
222
+ return refuse('CLAIM_CONFLICT', `Slice "${sliceId}" could not take its files: ${result.conflicts.map((each) => `${each.glob} is held by slice "${each.heldBy.sliceId}"`).join('; ')}.`, { sliceId, conflicts: result.conflicts });
223
+ }
224
+ register(teamId, sliceId);
225
+ return { ok: true, claims: result.claims };
226
+ }
227
+
228
+ /**
229
+ * Give claims back: a slice's when it finishes, the whole team's with no `sliceId`. The slice's context stays
230
+ * registered with the worker guard (a worker still running there is refused: its claims are gone) until `end`.
231
+ */
232
+ function release(teamId, sliceId = null) {
233
+ return store.release(sliceId ? { teamId, sliceId } : { teamId });
234
+ }
235
+
236
+ /** The team is over (landed, discarded, removed): every claim back, every context off the worker guard. */
237
+ function end(teamId) {
238
+ const released = isTeamSlug(teamId) ? store.release({ teamId }).released : 0;
239
+ for (const [key, made] of [...contexts]) {
240
+ if (!key.startsWith(`${teamId}/`)) continue;
241
+ try { registry.unregister(made); } catch { /* already gone */ }
242
+ contexts.delete(key);
243
+ }
244
+ plans.delete(teamId);
245
+ return { released };
246
+ }
247
+
248
+ /**
249
+ * After a restart: the claims of every team under way are taken again where they should be held, and every slice
250
+ * is registered with the worker guard again (the registry is in memory). Claims of teams that are over are given
251
+ * back.
252
+ */
253
+ function restore() {
254
+ const out = [];
255
+ for (const entry of state.teams()) {
256
+ const record = state.record(entry.teamId);
257
+ if (!record) continue;
258
+ if (TERMINAL_TEAM_STATES.includes(record.state) || record.removed) { out.push({ teamId: record.teamId, released: end(record.teamId).released }); continue; }
259
+ plans.set(record.teamId, record.plan);
260
+ const claimed = [];
261
+ const conflicts = [];
262
+ for (const slice of record.plan.slices) {
263
+ const current = sliceState(record, slice.id);
264
+ if (!SETTLED_SLICE_STATES.includes(current)) register(record.teamId, slice.id);
265
+ if (!CLAIMING_SLICE_STATES.has(current)) continue;
266
+ const result = claimSlice(record.plan, slice.id, record.slices[slice.id]?.runId || null);
267
+ if (result.ok) claimed.push(slice.id); else conflicts.push({ sliceId: slice.id, conflicts: result.conflicts });
268
+ }
269
+ out.push({ teamId: record.teamId, claimed, conflicts });
270
+ }
271
+ return out;
272
+ }
273
+
274
+ /**
275
+ * After the fact: what the slice's branch changed since it parted from the integration branch, and what is still
276
+ * uncommitted in its worktree, against what the slice owns. A file a program wrote without the guard seeing it
277
+ * shows up here.
278
+ *
279
+ * @returns {Promise<{ ok: boolean, head: string, reference: string, changed: object[], violations: object[],
280
+ * uncommitted: object[], stray: object[], warnings: object[] } | { ok: false, code: string }>}
281
+ * `ok`: the branch changed nothing outside the slice's ownership. `violations`: committed changes that are not
282
+ * the slice's. `stray`: uncommitted changes that are not the slice's (git-ignored files never count).
283
+ */
284
+ async function verifyOwnership(teamId, sliceId) {
285
+ if (typeof git !== 'function') throw new Error('verifyOwnership needs a git runner.');
286
+ const record = isTeamSlug(teamId) ? state.record(teamId) : null;
287
+ if (!record) return refuse('TEAM_NOT_FOUND', `No team named "${teamId}" is recorded.`);
288
+ const slice = planSlice(record, sliceId);
289
+ if (!slice) return refuse('SLICE_NOT_FOUND', `Team "${teamId}" has no slice "${sliceId}".`);
290
+ const cwd = record.projectPath;
291
+ const rev = async (name) => { const out = await git(['rev-parse', '--verify', '--quiet', `${name}^{commit}`], { cwd }); return out.ok ? out.stdout.trim() : null; };
292
+ const head = await rev(`refs/heads/${branchName(teamId, sliceId)}`);
293
+ if (!head) return refuse('SLICE_BRANCH_MISSING', `The branch of slice "${sliceId}" is not there.`);
294
+ const integration = (await rev(`refs/heads/${integrationBranchName(teamId)}`)) || record.integration.head;
295
+ const base = await git(['merge-base', head, integration], { cwd });
296
+ const reference = (base.ok && base.stdout.trim()) || record.slices[sliceId]?.startCommit || record.baseCommit;
297
+ const diff = await git(['diff', '--name-status', '-z', '--no-renames', reference, head], { cwd });
298
+ if (!diff.ok) return refuse('GIT_FAILED', `The slice's changes could not be read: ${diff.stderr.trim().slice(0, 300)}`);
299
+ const changed = parseNameStatus(diff.stdout).map((entry) => ({ ...entry, owner: pathOwner(record.plan, entry.path) }));
300
+ const violations = changed.filter((entry) => entry.owner !== sliceId).map((entry) => ({ ...entry, committed: true }));
301
+ const worktree = worktreePath(record.projectPath, teamId, sliceId);
302
+ const status = await git(['status', '--porcelain=v1', '-z', '--untracked-files=all'], { cwd: worktree });
303
+ const uncommitted = status.ok
304
+ ? parseStatus(status.stdout).flatMap((entry) => [entry.path, entry.from].filter(Boolean).map((path) => ({ path, status: `${entry.index}${entry.worktree}`.trim() || '?', owner: pathOwner(record.plan, path) })))
305
+ : [];
306
+ const stray = uncommitted.filter((entry) => entry.owner !== sliceId).map((entry) => ({ ...entry, committed: false }));
307
+ const warnings = slice.lockfileOwner ? [] : changed.filter((entry) => entry.owner === sliceId && isManifestPath(entry.path)).map((entry) => ({
308
+ code: 'manifest_changed', path: entry.path,
309
+ message: `${entry.path} is a dependency manifest and slice "${sliceId}" is not the lockfile owner: a change of dependencies there leaves the lockfile behind.`,
310
+ }));
311
+ return { ok: violations.length === 0, head, reference, changed, violations, uncommitted, stray, warnings };
312
+ }
313
+
314
+ return { start, assign, release, end, restore, checkWrite, checkRelative, context, verifyOwnership, planOf };
315
+ }
@@ -0,0 +1,293 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: how git is run for a team
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A team's git work happens in three kinds of place: the worktrees SynaBun made for it (slices and integration),
6
+ // the repository's own data (branches, the list of worktrees), and, for a landing only, the checkout that has the
7
+ // user's branch. Every command is an argument array, never a command line, and is run the same careful way:
8
+ //
9
+ // hooks `-c core.hooksPath=<the null device>`: nothing a repository's hooks name is started. A team's
10
+ // commits are bookkeeping on SynaBun's own branches; the project's checks are the test command
11
+ // that runs on the integration commit.
12
+ // file monitor a read is given lib/git-read.js's arguments (a program named in core.fsmonitor is never
13
+ // started; git's built-in monitor is kept); a write is given `core.fsmonitor=false`.
14
+ // signing `-c commit.gpgsign=false`: a signing program would wait for a passphrase nobody types.
15
+ // remotes GIT_ALLOW_PROTOCOL empty, GIT_NO_LAZY_FETCH=1: nothing here needs a remote.
16
+ // recorded fixes `-c rerere.enabled=false`: a conflict is reported, never resolved from an old recording.
17
+ // editor, prompt GIT_EDITOR / GIT_SEQUENCE_EDITOR `true`, GIT_TERMINAL_PROMPT=0, `--no-pager`.
18
+ // housekeeping `-c gc.auto=0`: no pruning starts in the middle of a team's work.
19
+ //
20
+ // Clean and smudge filters (git-lfs) still run: a checkout without them is not the project.
21
+ //
22
+ // The runner never throws for a command that fails: it answers `{ ok, status, stdout, stderr }` and the caller
23
+ // decides. It throws TeamGitError only when git itself cannot be started.
24
+
25
+ import { execFile } from 'node:child_process';
26
+ import { devNull } from 'node:os';
27
+ import { gitRead, withGitFallback } from '../git-read.js';
28
+
29
+ export class TeamGitError extends Error {
30
+ /** @param {string} code @param {string} message @param {object} [extra] */
31
+ constructor(code, message, extra = {}) {
32
+ super(message);
33
+ this.name = 'TeamGitError';
34
+ this.code = code;
35
+ Object.assign(this, extra);
36
+ }
37
+ }
38
+
39
+ /** Commands that only ask: they go through lib/git-read.js. */
40
+ const READ_COMMANDS = new Set([
41
+ 'rev-parse', 'rev-list', 'status', 'diff', 'log', 'show', 'ls-files', 'for-each-ref', 'show-ref', 'symbolic-ref',
42
+ 'merge-base', 'cat-file', 'check-ignore', 'check-ref-format', 'cherry', 'config', 'merge-tree', 'ls-tree', 'diff-tree',
43
+ 'name-rev', 'describe',
44
+ ]);
45
+ /** Sub-commands that make a read command a write. */
46
+ const isRead = (args) => {
47
+ const [command, ...rest] = args;
48
+ if (!READ_COMMANDS.has(command)) return command === 'worktree' && rest[0] === 'list';
49
+ // `symbolic-ref HEAD` asks; with a second name, -d or -m it writes.
50
+ if (command === 'symbolic-ref') return !rest.some((arg) => arg === '-d' || arg === '--delete' || arg === '-m') && rest.filter((arg) => !arg.startsWith('-')).length <= 1;
51
+ if (command === 'config') return rest.some((arg) => /^(?:--get|--get-all|--get-regexp|--list|-l)$/.test(arg));
52
+ return true;
53
+ };
54
+
55
+ const WRITE_OPTIONS = Object.freeze([
56
+ '--no-pager',
57
+ '-c', `core.hooksPath=${devNull}`,
58
+ '-c', 'core.fsmonitor=false',
59
+ '-c', 'commit.gpgsign=false',
60
+ '-c', 'tag.gpgsign=false',
61
+ '-c', 'log.showSignature=false',
62
+ '-c', 'rerere.enabled=false',
63
+ '-c', 'merge.autoStash=false',
64
+ '-c', 'gc.auto=0',
65
+ '-c', 'advice.detachedHead=false',
66
+ ]);
67
+
68
+ /** What every team command's environment adds. */
69
+ export const TEAM_GIT_ENV = Object.freeze({
70
+ GIT_TERMINAL_PROMPT: '0',
71
+ GIT_EDITOR: 'true',
72
+ GIT_SEQUENCE_EDITOR: 'true',
73
+ GIT_MERGE_AUTOEDIT: 'no',
74
+ GIT_NO_LAZY_FETCH: '1',
75
+ GIT_ALLOW_PROTOCOL: '',
76
+ LC_ALL: 'C',
77
+ });
78
+
79
+ /** The environment variables of the calling process that would aim git somewhere else: never passed on. */
80
+ const AIMING_ENV = ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_PREFIX'];
81
+
82
+ function baseEnv(env) {
83
+ const out = { ...env };
84
+ for (const name of AIMING_ENV) delete out[name];
85
+ return out;
86
+ }
87
+
88
+ /**
89
+ * The git runner a team uses.
90
+ *
91
+ * @param {object} [options]
92
+ * @param {string} [options.binary] the git program (default `git`, found on PATH; SynaBun's own copy on a
93
+ * Windows PC without one, through lib/git-read.js)
94
+ * @param {object} [options.env] the environment to start from (default: this process's)
95
+ * @param {number} [options.timeoutMs] per command (default 2 minutes)
96
+ * @param {number} [options.maxBuffer] per stream (default 64 MB)
97
+ * @param {(entry: object) => void} [options.onCommand] told every command and its answer (tests, a log)
98
+ * @returns {(args: string[], options?: { cwd: string, input?: string, env?: object, timeoutMs?: number }) =>
99
+ * Promise<{ ok: boolean, status: number, stdout: string, stderr: string }>}
100
+ */
101
+ export function createGitRunner({ binary = 'git', env = process.env, timeoutMs = 120_000, maxBuffer = 64 * 1024 * 1024, onCommand = null } = {}) {
102
+ const started = baseEnv(env);
103
+ return async function git(args, { cwd, input = null, env: extra = null, timeoutMs: limit = timeoutMs } = {}) {
104
+ if (!Array.isArray(args) || !args.length || args.some((arg) => typeof arg !== 'string')) throw new TeamGitError('GIT_ARGUMENTS', 'A git command is a list of text arguments.');
105
+ if (typeof cwd !== 'string' || !cwd) throw new TeamGitError('GIT_FOLDER', 'A git command needs the folder it runs in.');
106
+ let argv;
107
+ let childEnv;
108
+ if (isRead(args)) {
109
+ const read = await gitRead(cwd, args, { binary, env: { ...started, ...(extra || {}) } });
110
+ argv = read.args;
111
+ childEnv = { ...read.env, LC_ALL: 'C', GIT_EDITOR: 'true' };
112
+ } else {
113
+ argv = [...WRITE_OPTIONS, ...args];
114
+ childEnv = withGitFallback({ ...started, ...TEAM_GIT_ENV, ...(extra || {}) });
115
+ }
116
+ const result = await new Promise((done, fail) => {
117
+ let child;
118
+ try {
119
+ child = execFile(binary, argv, { cwd, env: childEnv, timeout: limit, maxBuffer, windowsHide: true, shell: false, encoding: 'utf8' }, (error, stdout, stderr) => {
120
+ if (error && typeof error.code !== 'number') {
121
+ if (error.code === 'ENOENT') { fail(new TeamGitError('GIT_UNAVAILABLE', `git could not be started (${binary}): ${error.message}`)); return; }
122
+ // Killed by the timeout or by a signal, or its output was too long: a failed command, with why.
123
+ done({ ok: false, status: -1, stdout: String(stdout || ''), stderr: `${String(stderr || '')}${error.killed ? `\ngit ${args[0]} was stopped after ${limit} ms.` : `\n${error.message}`}`.trim() });
124
+ return;
125
+ }
126
+ const status = error ? error.code : 0;
127
+ done({ ok: status === 0, status, stdout: String(stdout || ''), stderr: String(stderr || '') });
128
+ });
129
+ } catch (error) {
130
+ fail(new TeamGitError('GIT_UNAVAILABLE', `git could not be started (${binary}): ${error.message}`));
131
+ return;
132
+ }
133
+ if (input !== null && input !== undefined) child.stdin?.end(input);
134
+ else child.stdin?.end();
135
+ });
136
+ if (typeof onCommand === 'function') {
137
+ try { onCommand({ cwd, args, status: result.status }); } catch { /* a listener's failure is not the command's */ }
138
+ }
139
+ return result;
140
+ };
141
+ }
142
+
143
+ // ── Reading git's answers ───────────────────────────────────────────────────
144
+
145
+ /** The first line of a command's output, trimmed; '' when it failed. */
146
+ export const line = (result) => (result && result.ok ? result.stdout.split('\n')[0].trim() : '');
147
+
148
+ /** A NUL-separated list (`-z`) as its items. */
149
+ export const nulList = (text) => String(text || '').split('\0').filter((item) => item.length > 0);
150
+
151
+ /** What a failed command said, in one line, for a report. */
152
+ export function gitSaid(result) {
153
+ const text = `${result?.stderr || ''}\n${result?.stdout || ''}`.split('\n').map((each) => each.trim()).filter(Boolean);
154
+ return (text.find((each) => /^(?:fatal|error):/i.test(each)) || text[0] || `git exited with ${result?.status}`).slice(0, 400);
155
+ }
156
+
157
+ /** How much of a failed command's output a report carries at most (gitOutput). */
158
+ export const GIT_OUTPUT_MAX = 4096;
159
+
160
+ /**
161
+ * Everything a failed command said, every line (stderr, then stdout), for a report a person reads: git's own words
162
+ * often run over several lines ("The following paths are ignored…", then the paths, then a hint), and the first
163
+ * line alone does not say which. Longer than `max`: its beginning and its end, with a note of what was left out.
164
+ */
165
+ export function gitOutput(result, max = GIT_OUTPUT_MAX) {
166
+ const text = [result?.stderr, result?.stdout].map((each) => String(each || '').replace(/\r\n?/g, '\n').trim()).filter(Boolean).join('\n');
167
+ if (!text) return `git exited with ${result?.status}`;
168
+ if (text.length <= max) return text;
169
+ const tail = Math.floor(max / 4);
170
+ const head = Math.max(0, max - tail - 64);
171
+ return `${text.slice(0, head)}\n… ${text.length - head - tail} characters left out …\n${text.slice(-tail)}`;
172
+ }
173
+
174
+ /**
175
+ * `git ls-files -s -z` as a map from each path to its index entries, each as git printed it
176
+ * (`<mode> <object> <stage>\t<path>`): one entry for a path at stage 0, up to three for an unmerged one. These are
177
+ * the lines `git update-index --index-info` takes back.
178
+ */
179
+ export function parseIndexEntries(text) {
180
+ const out = new Map();
181
+ for (const item of nulList(text)) {
182
+ const tab = item.indexOf('\t');
183
+ if (tab < 0 || !/^\d+ [0-9a-f]+ [0-3]$/.test(item.slice(0, tab))) continue;
184
+ const path = item.slice(tab + 1);
185
+ if (!out.has(path)) out.set(path, []);
186
+ out.get(path).push(item);
187
+ }
188
+ return out;
189
+ }
190
+
191
+ /**
192
+ * `git worktree list --porcelain` as entries: `{ path, head, branch, detached, bare, locked, prunable }`. `branch`
193
+ * is the short name (`synabun/team/slice`), null for a detached or bare entry.
194
+ */
195
+ export function parseWorktreeList(text) {
196
+ const out = [];
197
+ let entry = null;
198
+ for (const raw of String(text || '').split('\n')) {
199
+ if (!raw.trim()) { if (entry) out.push(entry); entry = null; continue; }
200
+ const at = raw.indexOf(' ');
201
+ const key = at < 0 ? raw : raw.slice(0, at);
202
+ const value = at < 0 ? '' : raw.slice(at + 1);
203
+ if (key === 'worktree') { if (entry) out.push(entry); entry = { path: value, head: null, branch: null, detached: false, bare: false, locked: false, prunable: false }; continue; }
204
+ if (!entry) continue;
205
+ if (key === 'HEAD') entry.head = value;
206
+ else if (key === 'branch') entry.branch = value.replace(/^refs\/heads\//, '');
207
+ else if (key === 'detached') entry.detached = true;
208
+ else if (key === 'bare') entry.bare = true;
209
+ else if (key === 'locked') entry.locked = true;
210
+ else if (key === 'prunable') entry.prunable = true;
211
+ }
212
+ if (entry) out.push(entry);
213
+ return out;
214
+ }
215
+
216
+ /**
217
+ * `git status --porcelain=v1 -z` as entries `{ path, index, worktree, from? }`. A rename or a copy carries the path
218
+ * it came from; both paths count as changed. `??` is an untracked file, `!!` an ignored one.
219
+ */
220
+ export function parseStatus(text) {
221
+ const items = String(text || '').split('\0');
222
+ const out = [];
223
+ for (let i = 0; i < items.length; i += 1) {
224
+ const item = items[i];
225
+ if (item.length < 4) continue;
226
+ const entry = { index: item[0], worktree: item[1], path: item.slice(3) };
227
+ if (entry.index === 'R' || entry.index === 'C' || entry.worktree === 'R' || entry.worktree === 'C') { entry.from = items[i + 1] || null; i += 1; }
228
+ out.push(entry);
229
+ }
230
+ return out;
231
+ }
232
+
233
+ /** `git diff --name-status -z --no-renames` as entries `{ status, path }`. */
234
+ export function parseNameStatus(text) {
235
+ const items = String(text || '').split('\0');
236
+ const out = [];
237
+ for (let i = 0; i + 1 < items.length; i += 2) {
238
+ if (!items[i]) break;
239
+ out.push({ status: items[i][0], path: items[i + 1] });
240
+ }
241
+ return out;
242
+ }
243
+
244
+ /** A promise chain per key: what is run under one key runs one at a time, in the order it was asked. */
245
+ export function createLocks() {
246
+ const tails = new Map();
247
+ return {
248
+ /** @template T @param {string} key @param {() => Promise<T>} fn @returns {Promise<T>} */
249
+ run(key, fn) {
250
+ const before = tails.get(key) || Promise.resolve();
251
+ const mine = before.then(fn, fn);
252
+ const tail = mine.then(() => {}, () => {});
253
+ tails.set(key, tail);
254
+ tail.then(() => { if (tails.get(key) === tail) tails.delete(key); });
255
+ return mine;
256
+ },
257
+ /** How many keys have something running or waiting. */
258
+ size: () => tails.size,
259
+ };
260
+ }
261
+
262
+ // ── Who commits ─────────────────────────────────────────────────────────────
263
+
264
+ /** The name SynaBun commits under in a repository that has no identity of its own. */
265
+ export const FALLBACK_IDENTITY = Object.freeze({ name: 'SynaBun Agents', email: 'agents@synabun.invalid' });
266
+
267
+ /**
268
+ * The environment a commit of SynaBun's is made with. The repository's own identity (user.name / user.email, as
269
+ * the user's commits have it) when it has one; `identity` when the caller names one; FALLBACK_IDENTITY for a
270
+ * repository without any, where git would refuse to commit.
271
+ * @param {Function} git @param {string} cwd @param {{ name?: string, email?: string }|null} [identity]
272
+ */
273
+ export async function identityEnv(git, cwd, identity = null) {
274
+ const named = (who) => ({ GIT_AUTHOR_NAME: who.name, GIT_AUTHOR_EMAIL: who.email, GIT_COMMITTER_NAME: who.name, GIT_COMMITTER_EMAIL: who.email });
275
+ if (identity && typeof identity.name === 'string' && identity.name && typeof identity.email === 'string' && identity.email) return named(identity);
276
+ const name = line(await git(['config', '--get', 'user.name'], { cwd }));
277
+ const email = line(await git(['config', '--get', 'user.email'], { cwd }));
278
+ if (name && email) return {};
279
+ return named({ name: name || FALLBACK_IDENTITY.name, email: email || FALLBACK_IDENTITY.email });
280
+ }
281
+
282
+ /** Which operations a checkout is in the middle of: `{ merge, cherryPick, revert, rebase, bisect, any }`. */
283
+ export async function operationsUnderWay(git, cwd, { exists }) {
284
+ // One question to git (where this checkout keeps its own state), then the markers git leaves there.
285
+ const dir = line(await git(['rev-parse', '--absolute-git-dir'], { cwd }));
286
+ const at = (name) => !!dir && exists(`${dir}/${name}`);
287
+ const out = {
288
+ merge: at('MERGE_HEAD'), cherryPick: at('CHERRY_PICK_HEAD') || at('sequencer'), revert: at('REVERT_HEAD'),
289
+ rebase: at('rebase-merge') || at('rebase-apply'), bisect: at('BISECT_LOG'),
290
+ };
291
+ out.any = out.merge || out.cherryPick || out.revert || out.rebase || out.bisect;
292
+ return out;
293
+ }