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,559 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Teams: the team plan contract
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // A team is one task given to several workers at once. Its plan says how the task is cut: a pinned base commit and
6
+ // a list of slices, each with the files it owns, the slices it waits for and the agent that does it. The rules a
7
+ // plan must pass are what make working side by side safe:
8
+ //
9
+ // - no file is owned by two slices (owned paths never overlap), so two workers never write the same file;
10
+ // - the slices' dependencies have no cycle, so there is an order to join them in;
11
+ // - at most one slice changes dependency lockfiles, and lockfiles belong to that slice only;
12
+ // - there are no more slices than the user's Agent density allows (lib/agents/density.js);
13
+ // - every owned path stays inside the project.
14
+ //
15
+ // Every slice works in its own git worktree, on its own branch, cut from the plan's base commit:
16
+ //
17
+ // <project>/.worktrees/<team>/<slice> branch synabun/<team>/<slice>
18
+ // <project>/.worktrees/<team>/integration branch synabun/<team>/integration (where finished slices are joined)
19
+ //
20
+ // The user's own checkout and branch are never a worker's (owner decision, 2026-11-15): the joined result waits on
21
+ // the integration branch for the user to merge. Worktrees live under the project's own .worktrees folder, never
22
+ // beside the project.
23
+ //
24
+ // This module is the contract only: the shape, the canonical form, what is refused, and the helpers that answer
25
+ // "who owns this file", "in what order are slices joined" and "where does this slice work". Running git, claiming
26
+ // files while work is under way (lib/coordination/store.js) and scheduling are later phases.
27
+ //
28
+ // Pure: no file, network, git or clock access. node:path only reads the text of a path.
29
+
30
+ import { isAbsolute, join, relative, resolve, sep } from 'node:path';
31
+ import { DEFAULT_AGENT_DENSITY, MAX_TEAM_WORKERS, maxWorkers, normalizeAgentDensity } from '../agents/density.js';
32
+ import { parseAgentRef } from '../agents/schema.js';
33
+
34
+ export const TEAM_PLAN_SCHEMA_VERSION = 1;
35
+ /** The folder inside a project that holds every team's worktrees. */
36
+ export const WORKTREES_DIR = '.worktrees';
37
+ /** The first part of every branch a team makes. */
38
+ export const BRANCH_PREFIX = 'synabun';
39
+ /** The slice id that is never a slice: the worktree and branch where a team's finished slices are joined. */
40
+ export const INTEGRATION_SLICE_ID = 'integration';
41
+ export const RESERVED_SLICE_IDS = Object.freeze([INTEGRATION_SLICE_ID]);
42
+
43
+ export const TEAM_LIMITS = Object.freeze({
44
+ id: 40, title: 80, task: 16000, ownedPaths: 64, glob: 300, dependsOn: MAX_TEAM_WORKERS - 1, projectPath: 1024, agentRef: 90,
45
+ });
46
+
47
+ /**
48
+ * Dependency lockfiles by file name, wherever they are in the tree. They belong to the plan's one lockfile owner:
49
+ * two workers installing packages at once produce a lockfile nobody can merge.
50
+ */
51
+ export const LOCKFILE_NAMES = Object.freeze([
52
+ 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
53
+ 'cargo.lock', 'poetry.lock', 'uv.lock', 'pdm.lock', 'pipfile.lock', 'composer.lock', 'gemfile.lock', 'go.sum',
54
+ 'mix.lock', 'pubspec.lock', 'podfile.lock', 'packages.lock.json', 'flake.lock', 'gradle.lockfile',
55
+ ]);
56
+
57
+ /** Folders no slice may own: git's own data and the worktrees themselves. */
58
+ export const RESERVED_PATH_ROOTS = Object.freeze(['.git', WORKTREES_DIR]);
59
+
60
+ /**
61
+ * The states a team and a slice move through, for the journal of lib/coordination/store.js (which stores any state
62
+ * name and does not enforce these). `ready`: every slice is joined on the integration branch and waits for the user.
63
+ * `creating`, `integrating` and `landing` are written before the step they name runs, so a crash in the middle of it
64
+ * is seen (lib/teams/recovery.js). A slice is `planned` when its task is recorded, `rejected` when it changed files
65
+ * it does not own, `conflict` when its commits do not apply on the integration branch, `tests-failed` when the test
66
+ * command failed on the commit that joined it (lib/teams/integration.js).
67
+ */
68
+ export const TEAM_STATES = Object.freeze(['creating', 'planned', 'running', 'integrating', 'ready', 'landing', 'merged', 'completed', 'failed', 'cancelled']);
69
+ export const SLICE_STATES = Object.freeze(['planned', 'pending', 'blocked', 'running', 'done', 'rejected', 'integrating', 'integrated', 'conflict', 'tests-failed', 'completed', 'failed', 'cancelled']);
70
+
71
+ const SLUG_RE = /^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/;
72
+ const COMMIT_RE = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
73
+ // eslint-disable-next-line no-control-regex
74
+ const CONTROL_RE = /[\u0000-\u001f\u007f]/;
75
+ // eslint-disable-next-line no-control-regex
76
+ const TEXT_CONTROL_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
77
+
78
+ export class TeamPlanError extends Error {
79
+ /** @param {string} code @param {string} message @param {object} [extra] */
80
+ constructor(code, message, extra = {}) {
81
+ super(message);
82
+ this.name = 'TeamPlanError';
83
+ this.code = code;
84
+ this.status = 400;
85
+ Object.assign(this, extra);
86
+ }
87
+ }
88
+
89
+ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
90
+ const has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
91
+ function pick(input, key) {
92
+ if (has(input, key)) return input[key];
93
+ const snake = key.replace(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
94
+ return snake !== key && has(input, snake) ? input[snake] : undefined;
95
+ }
96
+ const text = (value) => (typeof value === 'string' ? value : '');
97
+ const lower = (value) => text(value).trim().toLowerCase();
98
+ const issue = (field, code, message, extra = {}) => ({ field, code, message, ...extra });
99
+
100
+ /** Is this a team or slice id? Lower-case letters, digits and hyphens, at most 40: safe as a folder and as a branch part. */
101
+ export function isTeamSlug(value) {
102
+ return typeof value === 'string' && SLUG_RE.test(value);
103
+ }
104
+
105
+ // ── owned paths ──────────────────────────────────────────────────────────────
106
+ //
107
+ // An owned path is a project-relative pattern with forward slashes. `*` and `?` match inside one path segment,
108
+ // `**` (a whole segment) matches any number of segments. A pattern also owns everything beneath what it matches,
109
+ // as a git pathspec does: `src/api` owns `src/api/users.js`. Character classes, braces and negation are refused, so
110
+ // "do these two patterns share a file" always has an exact answer. Matching ignores letter case: two files whose
111
+ // names differ only in case are one file on the default macOS and Windows file systems.
112
+
113
+ /**
114
+ * An owned path in its canonical form: `./` and doubled slashes removed, a trailing slash turned into `/**`.
115
+ * Returns the text unchanged when it cannot be read as a pattern (`ownedPathProblem` says why).
116
+ */
117
+ export function normalizeOwnedPath(value) {
118
+ let glob = text(value).trim();
119
+ if (!glob) return '';
120
+ while (glob.startsWith('./')) glob = glob.slice(2);
121
+ glob = glob.replace(/\/{2,}/g, '/');
122
+ if (glob.length > 1 && glob.endsWith('/')) glob = `${glob}**`;
123
+ glob = glob.replace(/(?:\/\*\*){2,}/g, '/**').replace(/^(?:\*\*\/){2,}/, '**/');
124
+ return glob;
125
+ }
126
+
127
+ /**
128
+ * Why a (normalized) owned path is refused, or null.
129
+ * @returns {{ code: string, message: string } | null}
130
+ */
131
+ export function ownedPathProblem(glob) {
132
+ if (typeof glob !== 'string' || !glob) return { code: 'required', message: 'An owned path is a project-relative pattern like "src/api/**".' };
133
+ if (glob.length > TEAM_LIMITS.glob) return { code: 'too_long', message: `An owned path is at most ${TEAM_LIMITS.glob} characters.` };
134
+ if (CONTROL_RE.test(glob)) return { code: 'invalid_glob', message: 'An owned path has a control character.' };
135
+ if (glob.includes('\\')) return { code: 'invalid_glob', message: 'An owned path uses forward slashes; a backslash is not allowed.' };
136
+ if (glob.startsWith('/') || glob.startsWith('~') || /^[A-Za-z]:/.test(glob)) return { code: 'path_escape', message: `"${glob}" is not relative to the project: owned paths never leave it.` };
137
+ const segments = glob.split('/');
138
+ if (segments.includes('..')) return { code: 'path_escape', message: `"${glob}" climbs out of its folder with "..": owned paths never leave the project.` };
139
+ if (segments.includes('.') || segments.includes('')) return { code: 'invalid_glob', message: `"${glob}" has an empty or "." segment.` };
140
+ if (/[[\]{}!]/.test(glob)) return { code: 'unsupported_glob', message: `"${glob}" uses [ ], { } or !: owned paths take *, ? and ** only.` };
141
+ if (segments.some((segment) => segment.includes('**') && segment !== '**')) return { code: 'invalid_glob', message: `"${glob}": ** stands alone between slashes.` };
142
+ const first = segments[0].toLowerCase();
143
+ if (RESERVED_PATH_ROOTS.includes(first)) return { code: 'reserved_path', message: `"${glob}" is inside ${segments[0]}, which no slice may own.` };
144
+ return null;
145
+ }
146
+
147
+ /** Is this file name a dependency lockfile (LOCKFILE_NAMES, by its last segment, any letter case)? */
148
+ export function isLockfilePath(relPath) {
149
+ const name = text(relPath).split('/').pop().toLowerCase();
150
+ return LOCKFILE_NAMES.includes(name);
151
+ }
152
+
153
+ /** Does the pattern name a lockfile outright (its last segment is a lockfile's name)? `src/**` does not. */
154
+ function namesLockfile(glob) {
155
+ return isLockfilePath(glob);
156
+ }
157
+
158
+ /** Do two single-segment patterns (`*`, `?`, letters) match a common name? */
159
+ function segmentsMeet(p, q) {
160
+ const memo = new Map();
161
+ const meet = (i, j) => {
162
+ const key = i * (q.length + 1) + j;
163
+ if (memo.has(key)) return memo.get(key);
164
+ let out;
165
+ if (i === p.length && j === q.length) out = true;
166
+ else if (i < p.length && p[i] === '*') out = meet(i + 1, j) || (j < q.length && meet(i, j + 1));
167
+ else if (j < q.length && q[j] === '*') out = meet(i, j + 1) || (i < p.length && meet(i + 1, j));
168
+ else if (i === p.length || j === q.length) out = false;
169
+ else out = (p[i] === '?' || q[j] === '?' || p[i] === q[j]) && meet(i + 1, j + 1);
170
+ memo.set(key, out);
171
+ return out;
172
+ };
173
+ return meet(0, 0);
174
+ }
175
+
176
+ /** A pattern as segments, with the "and everything beneath" `**` at its end. */
177
+ function patternSegments(glob) {
178
+ const segments = normalizeOwnedPath(glob).toLowerCase().split('/');
179
+ if (segments[segments.length - 1] !== '**') segments.push('**');
180
+ return segments;
181
+ }
182
+
183
+ /**
184
+ * Is there a file both patterns own? Exact for the supported syntax; each pattern also owns what is beneath it.
185
+ * `src/api/**` and `src/**\/*.test.js` overlap; `src/api/**` and `src/ui/**` do not.
186
+ */
187
+ export function globsOverlap(a, b) {
188
+ const x = patternSegments(a);
189
+ const y = patternSegments(b);
190
+ const memo = new Map();
191
+ const meet = (i, j) => {
192
+ const key = i * (y.length + 1) + j;
193
+ if (memo.has(key)) return memo.get(key);
194
+ let out;
195
+ if (i === x.length && j === y.length) out = true;
196
+ else if (i < x.length && x[i] === '**') out = meet(i + 1, j) || (j < y.length && meet(i, j + 1));
197
+ else if (j < y.length && y[j] === '**') out = meet(i, j + 1) || (i < x.length && meet(i + 1, j));
198
+ else if (i === x.length || j === y.length) out = false;
199
+ else out = segmentsMeet(x[i], y[j]) && meet(i + 1, j + 1);
200
+ memo.set(key, out);
201
+ return out;
202
+ };
203
+ return meet(0, 0);
204
+ }
205
+
206
+ /** A project-relative file path in the form patterns are matched against: forward slashes, no `./`. null: not inside the project. */
207
+ export function normalizeRelPath(relPath) {
208
+ let path = text(relPath).trim().replace(/\\/g, '/');
209
+ while (path.startsWith('./')) path = path.slice(2);
210
+ path = path.replace(/\/{2,}/g, '/').replace(/\/$/, '');
211
+ if (!path || path.startsWith('/') || /^[A-Za-z]:/.test(path) || CONTROL_RE.test(path)) return null;
212
+ const segments = path.split('/');
213
+ if (segments.includes('..') || segments.includes('.')) return null;
214
+ return path;
215
+ }
216
+
217
+ /** Does the pattern own this project-relative file (or a folder above it)? */
218
+ export function matchesOwnedPath(glob, relPath) {
219
+ const path = normalizeRelPath(relPath);
220
+ if (path === null) return false;
221
+ // A file path is a pattern without wildcards: the same question as an overlap, with nothing beneath the file.
222
+ const x = patternSegments(glob);
223
+ const y = path.toLowerCase().split('/');
224
+ const memo = new Map();
225
+ const meet = (i, j) => {
226
+ const key = i * (y.length + 1) + j;
227
+ if (memo.has(key)) return memo.get(key);
228
+ let out;
229
+ if (i === x.length) out = j === y.length;
230
+ else if (x[i] === '**') out = meet(i + 1, j) || (j < y.length && meet(i, j + 1));
231
+ else if (j === y.length) out = false;
232
+ else out = segmentsMeet(x[i], y[j].replace(/[*?]/g, '\u0001')) && meet(i + 1, j + 1);
233
+ memo.set(key, out);
234
+ return out;
235
+ };
236
+ return meet(0, 0);
237
+ }
238
+
239
+ // ── the plan ─────────────────────────────────────────────────────────────────
240
+
241
+ function normalizeSlice(value) {
242
+ const src = isObject(value) ? value : {};
243
+ const owned = Array.isArray(pick(src, 'ownedPaths')) ? pick(src, 'ownedPaths') : [];
244
+ const deps = Array.isArray(pick(src, 'dependsOn')) ? pick(src, 'dependsOn') : [];
245
+ const agentRef = lower(pick(src, 'agentRef'));
246
+ return {
247
+ id: lower(pick(src, 'id')),
248
+ title: text(pick(src, 'title')).replace(/\s+/g, ' ').trim(),
249
+ task: text(pick(src, 'task')).replace(/\r\n?/g, '\n').trim(),
250
+ agentRef: agentRef || null,
251
+ ownedPaths: [...new Set(owned.filter((item) => typeof item === 'string').map(normalizeOwnedPath).filter(Boolean))],
252
+ dependsOn: [...new Set(deps.filter((item) => typeof item === 'string').map((id) => id.trim().toLowerCase()).filter(Boolean))],
253
+ lockfileOwner: pick(src, 'lockfileOwner') === true || pick(src, 'lockfileOwner') === 'true',
254
+ };
255
+ }
256
+
257
+ /**
258
+ * A plan in its canonical form: every field present, ids lower-cased, owned paths normalized, unknown keys dropped.
259
+ * Never throws and never judges (`validateTeamPlan` does). `id` is accepted for `teamId`.
260
+ * @returns {{ schemaVersion: number, teamId: string, projectPath: string, baseCommit: string, slices: object[] }}
261
+ */
262
+ export function normalizeTeamPlan(input = {}) {
263
+ const src = isObject(input) ? input : {};
264
+ const rawPath = text(pick(src, 'projectPath')).trim();
265
+ const slices = Array.isArray(src.slices) ? src.slices : [];
266
+ return {
267
+ schemaVersion: TEAM_PLAN_SCHEMA_VERSION,
268
+ ...(src.readOnly === true || src.read_only === true ? { readOnly: true } : {}),
269
+ teamId: lower(pick(src, 'teamId') ?? src.id),
270
+ // Compared by its text everywhere, so kept in one form (no "a/../b", no trailing separator).
271
+ projectPath: rawPath && isAbsolute(rawPath) ? resolve(rawPath) : rawPath,
272
+ baseCommit: lower(pick(src, 'baseCommit')),
273
+ slices: slices.map(normalizeSlice),
274
+ ...(text(pick(src, 'fewerReason')).trim() ? { fewerReason: text(pick(src, 'fewerReason')).trim() } : {}),
275
+ };
276
+ }
277
+
278
+ /** The dependency cycle a plan's slices form, as the ids along it (`['a', 'b', 'a']`), or null. Unknown ids are ignored. */
279
+ export function dependencyCycle(plan) {
280
+ const slices = normalizeTeamPlan(plan).slices;
281
+ const byId = new Map(slices.map((slice) => [slice.id, slice]));
282
+ const state = new Map(); // id → 1 on the path being walked, 2 finished
283
+ const path = [];
284
+ const walk = (id) => {
285
+ state.set(id, 1);
286
+ path.push(id);
287
+ for (const dep of byId.get(id).dependsOn) {
288
+ if (!byId.has(dep)) continue;
289
+ if (state.get(dep) === 1) return [...path.slice(path.indexOf(dep)), dep];
290
+ if (!state.has(dep)) { const found = walk(dep); if (found) return found; }
291
+ }
292
+ path.pop();
293
+ state.set(id, 2);
294
+ return null;
295
+ };
296
+ for (const slice of slices) {
297
+ if (state.has(slice.id) || !slice.id) continue;
298
+ const found = walk(slice.id);
299
+ if (found) return found;
300
+ }
301
+ return null;
302
+ }
303
+
304
+ /**
305
+ * Is this a plan a team may run? Structured errors, never an exception.
306
+ *
307
+ * @param {object} input
308
+ * @param {object} [options]
309
+ * @param {string} [options.density] the session's Agent density (lib/agents/density.js): the plan has at most
310
+ * `maxWorkers(density)` slices. Without it, and without `maxSlices`, the
311
+ * default level applies (Solo: one slice).
312
+ * @param {number} [options.maxSlices] the cap as a number, when the caller has already worked it out (never above
313
+ * the highest level's)
314
+ * @returns {{ ok: boolean, errors: { field: string, code: string, message: string }[], value: object }}
315
+ * `field` names the place: `slices[2].ownedPaths[0]`. `value` is the normalized plan, also when `ok` is false.
316
+ */
317
+ export function validateTeamPlan(input, { density = null, maxSlices = null } = {}) {
318
+ const plan = normalizeTeamPlan(input);
319
+ const errors = [];
320
+ const add = (field, code, message, extra) => errors.push(issue(field, code, message, extra));
321
+ if (!isObject(input)) return { ok: false, errors: [issue('', 'invalid_type', 'A team plan is an object.')], value: plan };
322
+
323
+ // ── the team ──
324
+ if (!plan.teamId) add('teamId', 'required', 'teamId is required: a short lower-case name like "auth-rework".');
325
+ else if (!isTeamSlug(plan.teamId)) add('teamId', 'invalid_format', `teamId uses lower-case letters, digits and hyphens (at most ${TEAM_LIMITS.id}), and starts and ends with a letter or a digit.`);
326
+ if (!plan.projectPath) add('projectPath', 'required', 'projectPath is required: the project folder.');
327
+ else if (CONTROL_RE.test(plan.projectPath)) add('projectPath', 'invalid_format', 'projectPath has a control character.');
328
+ else if (!isAbsolute(plan.projectPath)) add('projectPath', 'path_not_absolute', 'projectPath must be an absolute path.');
329
+ else if (plan.projectPath.length > TEAM_LIMITS.projectPath) add('projectPath', 'too_long', `projectPath is at most ${TEAM_LIMITS.projectPath} characters.`);
330
+ if (!plan.baseCommit) add('baseCommit', 'required', 'baseCommit is required: the full commit id every slice starts from.');
331
+ else if (!COMMIT_RE.test(plan.baseCommit)) add('baseCommit', 'invalid_format', 'baseCommit is a full commit id (40 or 64 hex digits), never a branch name or a short id.');
332
+
333
+ // ── how many ──
334
+ if (!Array.isArray(input.slices)) add('slices', 'invalid_type', 'slices must be a list.');
335
+ else if (!plan.slices.length) add('slices', 'required', 'A plan has at least one slice.');
336
+ const level = density === null || density === undefined ? null : normalizeAgentDensity(density, null);
337
+ if (density !== null && density !== undefined && level === null) add('density', 'unknown_value', `Unknown Agent density "${String(density).slice(0, 40)}".`);
338
+ let cap = level ? maxWorkers(level) : maxWorkers(DEFAULT_AGENT_DENSITY);
339
+ const asked = Number(maxSlices);
340
+ if (maxSlices !== null && maxSlices !== undefined && Number.isInteger(asked) && asked >= 1) cap = Math.min(asked, level ? maxWorkers(level) : MAX_TEAM_WORKERS);
341
+ if (plan.slices.length > cap) {
342
+ const why = level
343
+ ? `Agent density ${level} allows ${cap}`
344
+ : (Number.isInteger(asked) && asked >= 1 ? `at most ${cap} are allowed` : `no Agent density was given, so ${DEFAULT_AGENT_DENSITY} applies and allows ${cap}`);
345
+ add('slices', 'too_many_slices', `The plan has ${plan.slices.length} slices; ${why}. Use fewer slices, or one worker.`, { limit: cap, count: plan.slices.length });
346
+ }
347
+
348
+ // ── each slice ──
349
+ const seen = new Map();
350
+ const rawSlices = Array.isArray(input.slices) ? input.slices : [];
351
+ plan.slices.forEach((slice, index) => {
352
+ const at = `slices[${index}]`;
353
+ const raw = rawSlices[index];
354
+ if (!isObject(raw)) { add(at, 'invalid_type', 'A slice is an object.'); return; }
355
+ if (!slice.id) add(`${at}.id`, 'required', 'A slice has an id: a short lower-case name like "api".');
356
+ else if (!isTeamSlug(slice.id)) add(`${at}.id`, 'invalid_format', `A slice id uses lower-case letters, digits and hyphens (at most ${TEAM_LIMITS.id}), and starts and ends with a letter or a digit.`);
357
+ else if (RESERVED_SLICE_IDS.includes(slice.id)) add(`${at}.id`, 'reserved', `"${slice.id}" is the name of the team's integration worktree; pick another slice id.`);
358
+ else if (seen.has(slice.id)) add(`${at}.id`, 'duplicate', `Slice id "${slice.id}" is used twice (also slices[${seen.get(slice.id)}]).`);
359
+ else seen.set(slice.id, index);
360
+ if (!slice.title) add(`${at}.title`, 'required', 'A slice has a title.');
361
+ else if (slice.title.length > TEAM_LIMITS.title) add(`${at}.title`, 'too_long', `A slice title is at most ${TEAM_LIMITS.title} characters.`);
362
+ if (!slice.task) add(`${at}.task`, 'required', 'A slice has a task: the instructions its worker gets.');
363
+ else if (slice.task.length > TEAM_LIMITS.task) add(`${at}.task`, 'too_long', `A slice task is at most ${TEAM_LIMITS.task} characters.`);
364
+ else if (TEXT_CONTROL_RE.test(slice.task)) add(`${at}.task`, 'invalid_format', 'A slice task has a control character.');
365
+ const rawRef = pick(raw, 'agentRef');
366
+ if (rawRef !== undefined && rawRef !== null && rawRef !== '') {
367
+ if (typeof rawRef !== 'string') add(`${at}.agentRef`, 'invalid_type', 'agentRef must be text.');
368
+ else if (!parseAgentRef(rawRef)) add(`${at}.agentRef`, 'invalid_format', `"${rawRef.slice(0, 80)}" is not an agent ref ("<id>", "<id>@<revision>", "global:<id>", "project:<id>").`);
369
+ }
370
+ const rawOwned = pick(raw, 'ownedPaths');
371
+ if ((!plan.readOnly || rawOwned != null) && (!Array.isArray(rawOwned) || rawOwned.some((item) => typeof item !== 'string'))) add(`${at}.ownedPaths`, 'invalid_type', 'ownedPaths must be a list of patterns.');
372
+ else if (!plan.readOnly && !slice.ownedPaths.length) add(`${at}.ownedPaths`, 'required', 'A slice owns at least one path: the files only it may write.');
373
+ if (plan.readOnly && (slice.ownedPaths.length || slice.lockfileOwner || slice.dependsOn.length)) add(at, 'read_only_slice', 'Research/review slices only read and report: no owned paths, lockfile owner or dependencies.');
374
+ if (slice.ownedPaths.length > TEAM_LIMITS.ownedPaths) add(`${at}.ownedPaths`, 'too_many', `A slice owns at most ${TEAM_LIMITS.ownedPaths} patterns.`);
375
+ slice.ownedPaths.forEach((glob, n) => {
376
+ const problem = ownedPathProblem(glob);
377
+ if (problem) add(`${at}.ownedPaths[${n}]`, problem.code, problem.message);
378
+ else if (namesLockfile(glob) && !slice.lockfileOwner) add(`${at}.ownedPaths[${n}]`, 'lockfile_not_owner', `"${glob}" is a dependency lockfile: only the slice with lockfileOwner: true may own it.`);
379
+ });
380
+ const rawDeps = pick(raw, 'dependsOn');
381
+ if (rawDeps !== undefined && rawDeps !== null && (!Array.isArray(rawDeps) || rawDeps.some((item) => typeof item !== 'string'))) add(`${at}.dependsOn`, 'invalid_type', 'dependsOn must be a list of slice ids.');
382
+ if (slice.dependsOn.includes(slice.id) && slice.id) add(`${at}.dependsOn`, 'self_dependency', `Slice "${slice.id}" depends on itself.`);
383
+ const rawLock = pick(raw, 'lockfileOwner');
384
+ if (rawLock !== undefined && rawLock !== null && typeof rawLock !== 'boolean' && rawLock !== 'true' && rawLock !== 'false') add(`${at}.lockfileOwner`, 'invalid_type', 'lockfileOwner must be true or false.');
385
+ });
386
+
387
+ // ── between slices ──
388
+ const ids = new Set(plan.slices.map((slice) => slice.id).filter(Boolean));
389
+ plan.slices.forEach((slice, index) => {
390
+ for (const dep of slice.dependsOn) {
391
+ if (dep !== slice.id && !ids.has(dep)) add(`slices[${index}].dependsOn`, 'unknown_dependency', `Slice "${slice.id || index}" depends on "${dep}", which is not a slice of this plan.`);
392
+ }
393
+ });
394
+ const cycle = dependencyCycle(plan);
395
+ if (cycle && cycle.length > 2) add('slices', 'dependency_cycle', `The slices depend on each other in a circle: ${cycle.join(' → ')}.`, { cycle });
396
+ const owners = plan.slices.map((slice, index) => ({ slice, index })).filter(({ slice }) => slice.lockfileOwner);
397
+ if (owners.length > 1) {
398
+ add('slices', 'multiple_lockfile_owners', `More than one slice is the lockfile owner (${owners.map(({ slice, index }) => slice.id || `slices[${index}]`).join(', ')}): at most one slice changes dependency lockfiles.`, { slices: owners.map(({ slice }) => slice.id) });
399
+ }
400
+ for (let i = 0; i < plan.slices.length; i += 1) {
401
+ for (let j = i + 1; j < plan.slices.length; j += 1) {
402
+ let reported = false;
403
+ for (let m = 0; m < plan.slices[i].ownedPaths.length && !reported; m += 1) {
404
+ const a = plan.slices[i].ownedPaths[m];
405
+ // A pattern that names a lockfile is the lockfile owner's (checked above) and lockfiles are owned by rule,
406
+ // whatever else covers them: it is not weighed against another slice's wider pattern.
407
+ if (ownedPathProblem(a) || namesLockfile(a)) continue;
408
+ for (let n = 0; n < plan.slices[j].ownedPaths.length; n += 1) {
409
+ const b = plan.slices[j].ownedPaths[n];
410
+ if (ownedPathProblem(b) || namesLockfile(b) || !globsOverlap(a, b)) continue;
411
+ add(`slices[${j}].ownedPaths[${n}]`, 'overlapping_paths', `"${b}" of slice "${plan.slices[j].id || j}" overlaps "${a}" of slice "${plan.slices[i].id || i}": a file is owned by one slice only.`, { with: { slice: plan.slices[i].id, path: a } });
412
+ reported = true; // one finding per pair of slices is enough to act on
413
+ break;
414
+ }
415
+ }
416
+ }
417
+ }
418
+ return { ok: errors.length === 0, errors, value: plan };
419
+ }
420
+
421
+ /**
422
+ * The slice that owns a project-relative file, as its id, or null when no slice does. A dependency lockfile
423
+ * belongs to the plan's lockfile owner and to nobody else: a slice whose pattern merely covers one (`packages/**`)
424
+ * does not own it, and with no lockfile owner in the plan nobody may change one.
425
+ * Meant for a valid plan (one where at most one slice matches a file).
426
+ */
427
+ export function pathOwner(plan, relPath) {
428
+ const value = normalizeTeamPlan(plan);
429
+ const path = normalizeRelPath(relPath);
430
+ if (path === null) return null;
431
+ if (RESERVED_PATH_ROOTS.includes(path.split('/')[0].toLowerCase())) return null;
432
+ if (isLockfilePath(path)) return value.slices.find((slice) => slice.lockfileOwner)?.id ?? null;
433
+ for (const slice of value.slices) {
434
+ if (slice.ownedPaths.some((glob) => !ownedPathProblem(glob) && matchesOwnedPath(glob, path))) return slice.id;
435
+ }
436
+ return null;
437
+ }
438
+
439
+ /**
440
+ * The patterns a slice claims in the coordination store while it works (lib/coordination/store.js `claim`): its
441
+ * owned paths without the ones that name a lockfile outright. Lockfiles are owned by rule (`pathOwner`), not by a
442
+ * claim, because the lockfile owner may name one that another slice's wider pattern covers. For a valid plan the
443
+ * claimable paths of two slices never overlap, so every slice's claim is granted.
444
+ * @returns {string[]} empty for a slice the plan does not have
445
+ */
446
+ export function claimablePaths(plan, sliceId) {
447
+ const slice = normalizeTeamPlan(plan).slices.find((each) => each.id === String(sliceId ?? '').trim().toLowerCase());
448
+ return slice ? slice.ownedPaths.filter((glob) => !ownedPathProblem(glob) && !namesLockfile(glob)) : [];
449
+ }
450
+
451
+ /**
452
+ * The order in which finished slices are joined on the integration branch: every slice after the slices it depends
453
+ * on, and otherwise in the order the plan lists them (so the same plan always gives the same order).
454
+ * @returns {string[]} slice ids
455
+ * @throws {TeamPlanError} `dependency_cycle` (with `cycle`), `unknown_dependency`
456
+ */
457
+ export function integrationOrder(plan) {
458
+ const slices = normalizeTeamPlan(plan).slices;
459
+ const ids = new Set(slices.map((slice) => slice.id));
460
+ if (ids.size !== slices.length || ids.has('')) throw new TeamPlanError('duplicate', 'Every slice needs an id of its own.');
461
+ for (const slice of slices) {
462
+ const missing = slice.dependsOn.find((dep) => !ids.has(dep));
463
+ if (missing) throw new TeamPlanError('unknown_dependency', `Slice "${slice.id}" depends on "${missing}", which is not a slice of this plan.`, { slice: slice.id, dependency: missing });
464
+ }
465
+ const cycle = dependencyCycle({ slices });
466
+ if (cycle) throw new TeamPlanError('dependency_cycle', `The slices depend on each other in a circle: ${cycle.join(' → ')}.`, { cycle });
467
+ const done = new Set();
468
+ const order = [];
469
+ while (order.length < slices.length) {
470
+ // The first listed slice whose dependencies are all joined already.
471
+ const next = slices.find((slice) => !done.has(slice.id) && slice.dependsOn.every((dep) => done.has(dep)));
472
+ done.add(next.id);
473
+ order.push(next.id);
474
+ }
475
+ return order;
476
+ }
477
+
478
+ /**
479
+ * The slices that can run now: not finished, and every slice they depend on finished.
480
+ * @param {object} plan
481
+ * @param {Iterable<string>} finished ids of slices whose work is done
482
+ * @returns {string[]} slice ids, in plan order
483
+ */
484
+ export function readySlices(plan, finished = []) {
485
+ const done = new Set(finished);
486
+ return normalizeTeamPlan(plan).slices
487
+ .filter((slice) => !done.has(slice.id) && slice.dependsOn.every((dep) => done.has(dep)))
488
+ .map((slice) => slice.id);
489
+ }
490
+
491
+ // ── where a slice works ──────────────────────────────────────────────────────
492
+
493
+ function slug(kind, value) {
494
+ if (!isTeamSlug(value)) throw new TeamPlanError('invalid_format', `${kind} "${String(value).slice(0, 60)}" is not a lower-case name of letters, digits and hyphens.`, { field: kind });
495
+ return value;
496
+ }
497
+ function projectRoot(projectPath) {
498
+ if (typeof projectPath !== 'string' || !projectPath.trim() || !isAbsolute(projectPath.trim()) || CONTROL_RE.test(projectPath)) {
499
+ throw new TeamPlanError('path_not_absolute', 'projectPath must be an absolute path.', { field: 'projectPath' });
500
+ }
501
+ return resolve(projectPath.trim());
502
+ }
503
+
504
+ /** `<project>/.worktrees`: the one folder that holds every team's worktrees of a project. */
505
+ export function worktreesRoot(projectPath) {
506
+ return join(projectRoot(projectPath), WORKTREES_DIR);
507
+ }
508
+
509
+ /**
510
+ * Where a slice's worktree is: always `<project>/.worktrees/<team>/<slice>`, never beside the project and never the
511
+ * project itself. `sliceId` may be `integration` (the team's integration worktree).
512
+ * @throws {TeamPlanError} for a relative project path, or an id that is not a plain lower-case name (so no id can
513
+ * climb out of the folder)
514
+ */
515
+ export function worktreePath(projectPath, teamId, sliceId) {
516
+ const root = projectRoot(projectPath);
517
+ const out = join(root, WORKTREES_DIR, slug('teamId', teamId), slug('sliceId', sliceId));
518
+ // What the ids were checked for, asked of the result itself.
519
+ if (relative(root, out) !== join(WORKTREES_DIR, teamId, sliceId)) {
520
+ throw new TeamPlanError('path_escape', 'A worktree path left the project\'s .worktrees folder.');
521
+ }
522
+ return out;
523
+ }
524
+
525
+ /** `<project>/.worktrees/<team>/integration`. */
526
+ export function integrationWorktreePath(projectPath, teamId) {
527
+ return worktreePath(projectPath, teamId, INTEGRATION_SLICE_ID);
528
+ }
529
+
530
+ /** `synabun/<team>/<slice>`: the branch a slice's worker commits on. */
531
+ export function branchName(teamId, sliceId) {
532
+ return `${BRANCH_PREFIX}/${slug('teamId', teamId)}/${slug('sliceId', sliceId)}`;
533
+ }
534
+
535
+ /** `synabun/<team>/integration`: where a team's finished slices are joined, for the user to merge. */
536
+ export function integrationBranchName(teamId) {
537
+ return branchName(teamId, INTEGRATION_SLICE_ID);
538
+ }
539
+
540
+ /** `synabun/<team>/<slice>` → `{ teamId, sliceId }`, or null for any other branch (the user's own, for one). */
541
+ export function parseBranchName(branch) {
542
+ const match = typeof branch === 'string' ? /^synabun\/([^/]+)\/([^/]+)$/.exec(branch.trim()) : null;
543
+ return match && isTeamSlug(match[1]) && isTeamSlug(match[2]) ? { teamId: match[1], sliceId: match[2] } : null;
544
+ }
545
+
546
+ /**
547
+ * Is this absolute path a team worktree of the project, or inside one? `{ teamId, sliceId }`, else null.
548
+ * (What a guard asks before it lets a worker write: a worker's folder is one of these, never the project itself.)
549
+ */
550
+ export function parseWorktreePath(projectPath, candidate) {
551
+ if (typeof candidate !== 'string' || !isAbsolute(candidate)) return null;
552
+ const rel = relative(worktreesRoot(projectPath), resolve(candidate));
553
+ if (!rel || rel.startsWith('..') || isAbsolute(rel)) return null;
554
+ const [teamId, sliceId] = rel.split(sep);
555
+ return isTeamSlug(teamId) && isTeamSlug(sliceId) ? { teamId, sliceId } : null;
556
+ }
557
+
558
+ // The short names the phase plan uses.
559
+ export { normalizeTeamPlan as normalize, validateTeamPlan as validate };