synabun 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +189 -0
  4. package/browser-extension/engine.js +508 -0
  5. package/browser-extension/icons/icon-128.png +0 -0
  6. package/browser-extension/icons/icon-16.png +0 -0
  7. package/browser-extension/icons/icon-32.png +0 -0
  8. package/browser-extension/icons/icon-48.png +0 -0
  9. package/browser-extension/icons/status-off-16.png +0 -0
  10. package/browser-extension/icons/status-off-32.png +0 -0
  11. package/browser-extension/icons/status-off-48.png +0 -0
  12. package/browser-extension/icons/status-on-16.png +0 -0
  13. package/browser-extension/icons/status-on-32.png +0 -0
  14. package/browser-extension/icons/status-on-48.png +0 -0
  15. package/browser-extension/manifest.json +56 -0
  16. package/browser-extension/popup-strings.js +250 -0
  17. package/browser-extension/popup-view.js +151 -0
  18. package/browser-extension/popup.css +166 -0
  19. package/browser-extension/popup.html +108 -0
  20. package/browser-extension/popup.js +359 -0
  21. package/browser-extension/protocol.js +232 -0
  22. package/browser-extension/service-worker.js +275 -0
  23. package/browser-extension/setup-content.js +36 -0
  24. package/browser-extension/tokens.css +326 -0
  25. package/docs/browser-extension-bridge.md +84 -0
  26. package/docs/whatsapp.md +1 -1
  27. package/lib/data-home-files.js +45 -0
  28. package/lib/data-home-migration.js +34 -58
  29. package/mcp-server/dist/http.d.ts +2 -0
  30. package/mcp-server/dist/http.d.ts.map +1 -1
  31. package/mcp-server/dist/http.js +9 -1
  32. package/mcp-server/dist/http.js.map +1 -1
  33. package/mcp-server/dist/index.d.ts +11 -0
  34. package/mcp-server/dist/index.d.ts.map +1 -1
  35. package/mcp-server/dist/index.js +38 -3
  36. package/mcp-server/dist/index.js.map +1 -1
  37. package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
  38. package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
  39. package/mcp-server/dist/services/browser-route-flow.js +10 -3
  40. package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
  41. package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
  42. package/mcp-server/dist/services/codex-config-heal.js +7 -0
  43. package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.d.ts +95 -3
  45. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  46. package/mcp-server/dist/services/neural-interface.js +168 -23
  47. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  48. package/mcp-server/dist/services/team-context.d.ts +18 -0
  49. package/mcp-server/dist/services/team-context.d.ts.map +1 -0
  50. package/mcp-server/dist/services/team-context.js +29 -0
  51. package/mcp-server/dist/services/team-context.js.map +1 -0
  52. package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
  53. package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
  54. package/mcp-server/dist/services/tool-catalog.js +22 -6
  55. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  56. package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
  57. package/mcp-server/dist/services/tool-list.js +4 -0
  58. package/mcp-server/dist/services/tool-list.js.map +1 -1
  59. package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
  60. package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
  61. package/mcp-server/dist/services/tool-runtime.js +18 -1
  62. package/mcp-server/dist/services/tool-runtime.js.map +1 -1
  63. package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
  64. package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
  65. package/mcp-server/dist/tools/agent-definition.js +483 -0
  66. package/mcp-server/dist/tools/agent-definition.js.map +1 -0
  67. package/mcp-server/dist/tools/agents.d.ts +92 -9
  68. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  69. package/mcp-server/dist/tools/agents.js +163 -20
  70. package/mcp-server/dist/tools/agents.js.map +1 -1
  71. package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
  72. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  73. package/mcp-server/dist/tools/browser-advanced.js +70 -6
  74. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  75. package/mcp-server/dist/tools/git-tools.d.ts +4 -2
  76. package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
  77. package/mcp-server/dist/tools/git-tools.js +283 -2
  78. package/mcp-server/dist/tools/git-tools.js.map +1 -1
  79. package/mcp-server/dist/tools/morelogin.d.ts +8 -2
  80. package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
  81. package/mcp-server/dist/tools/morelogin.js +22 -5
  82. package/mcp-server/dist/tools/morelogin.js.map +1 -1
  83. package/mcp-server/dist/tools/team.d.ts +32 -0
  84. package/mcp-server/dist/tools/team.d.ts.map +1 -0
  85. package/mcp-server/dist/tools/team.js +87 -0
  86. package/mcp-server/dist/tools/team.js.map +1 -0
  87. package/mcp-server/package-lock.json +2 -2
  88. package/mcp-server/package.json +1 -1
  89. package/mcp-server/src/http.ts +9 -1
  90. package/mcp-server/src/index.ts +34 -4
  91. package/mcp-server/src/services/browser-route-flow.ts +12 -5
  92. package/mcp-server/src/services/codex-config-heal.ts +7 -0
  93. package/mcp-server/src/services/neural-interface.ts +191 -29
  94. package/mcp-server/src/services/team-context.ts +27 -0
  95. package/mcp-server/src/services/tool-catalog.ts +26 -8
  96. package/mcp-server/src/services/tool-list.ts +4 -0
  97. package/mcp-server/src/services/tool-runtime.ts +21 -2
  98. package/mcp-server/src/tools/agent-definition.ts +458 -0
  99. package/mcp-server/src/tools/agents.ts +177 -19
  100. package/mcp-server/src/tools/browser-advanced.ts +60 -6
  101. package/mcp-server/src/tools/git-tools.ts +249 -3
  102. package/mcp-server/src/tools/morelogin.ts +20 -5
  103. package/mcp-server/src/tools/team.ts +97 -0
  104. package/neural-interface/i18n/en.json +1119 -47
  105. package/neural-interface/i18n/pt-BR.json +1119 -47
  106. package/neural-interface/lib/account-usage.js +1 -1
  107. package/neural-interface/lib/agents/builtins.json +207 -0
  108. package/neural-interface/lib/agents/density.js +101 -0
  109. package/neural-interface/lib/agents/forge-host.js +223 -0
  110. package/neural-interface/lib/agents/native-export-targets.js +190 -0
  111. package/neural-interface/lib/agents/native-export.js +365 -0
  112. package/neural-interface/lib/agents/registry.js +885 -0
  113. package/neural-interface/lib/agents/resolve.js +603 -0
  114. package/neural-interface/lib/agents/schema.js +642 -0
  115. package/neural-interface/lib/agents/split.js +37 -0
  116. package/neural-interface/lib/agents-studio-api.js +591 -0
  117. package/neural-interface/lib/assistant-api.js +76 -7
  118. package/neural-interface/lib/assistant-brains/opencode.js +60 -11
  119. package/neural-interface/lib/assistant-catalog.js +2 -0
  120. package/neural-interface/lib/assistant-continuity.js +49 -0
  121. package/neural-interface/lib/assistant-dispatch.js +351 -121
  122. package/neural-interface/lib/assistant-persona.js +105 -8
  123. package/neural-interface/lib/assistant-route-gate.js +24 -9
  124. package/neural-interface/lib/assistant-router.js +432 -47
  125. package/neural-interface/lib/assistant-run-tail.js +151 -0
  126. package/neural-interface/lib/assistant-run-wait.js +183 -0
  127. package/neural-interface/lib/assistant-runtime.js +449 -94
  128. package/neural-interface/lib/assistant-task-prompt.js +11 -2
  129. package/neural-interface/lib/assistant-usage.js +3 -2
  130. package/neural-interface/lib/automation-approval.js +2 -2
  131. package/neural-interface/lib/backup-service.js +64 -105
  132. package/neural-interface/lib/browser-close-evidence.js +80 -0
  133. package/neural-interface/lib/browser-default.js +210 -0
  134. package/neural-interface/lib/browser-extension-adapter.js +264 -0
  135. package/neural-interface/lib/browser-extension-bridge.js +441 -0
  136. package/neural-interface/lib/browser-extension-folder.js +116 -0
  137. package/neural-interface/lib/browser-extension-setup.js +140 -0
  138. package/neural-interface/lib/browser-profile-choices.js +3 -3
  139. package/neural-interface/lib/browser-tool-policy.js +1 -1
  140. package/neural-interface/lib/claude-account-links.js +301 -0
  141. package/neural-interface/lib/claude-accounts.js +45 -20
  142. package/neural-interface/lib/claude-agent-bridge.js +142 -10
  143. package/neural-interface/lib/claude-model-catalog.js +6 -0
  144. package/neural-interface/lib/claude-panel-session.js +33 -0
  145. package/neural-interface/lib/codex-accounts.js +67 -24
  146. package/neural-interface/lib/coordination/README.md +384 -0
  147. package/neural-interface/lib/coordination/service.js +563 -0
  148. package/neural-interface/lib/coordination/store.js +1138 -0
  149. package/neural-interface/lib/db.js +22 -1
  150. package/neural-interface/lib/effort-levels.js +10 -1
  151. package/neural-interface/lib/memory-list-page.js +49 -0
  152. package/neural-interface/lib/memory-list-stamp.js +60 -0
  153. package/neural-interface/lib/morelogin-outside-close.js +186 -0
  154. package/neural-interface/lib/morelogin-profile-failures.js +206 -0
  155. package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
  156. package/neural-interface/lib/morelogin.js +194 -8
  157. package/neural-interface/lib/native-loop-runtime.js +26 -7
  158. package/neural-interface/lib/opencode-build-preflight.js +28 -8
  159. package/neural-interface/lib/opencode-native-boundary.js +83 -13
  160. package/neural-interface/lib/opencode-serve-records.js +14 -9
  161. package/neural-interface/lib/page-session.js +1 -1
  162. package/neural-interface/lib/peer-identity.js +73 -29
  163. package/neural-interface/lib/process-identity.js +68 -7
  164. package/neural-interface/lib/request-gate.js +3 -0
  165. package/neural-interface/lib/screenshot-location.js +33 -0
  166. package/neural-interface/lib/session-cache-builder.js +41 -3
  167. package/neural-interface/lib/skills/creation.js +1 -1
  168. package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
  169. package/neural-interface/lib/studio-attention.js +56 -0
  170. package/neural-interface/lib/teams/README.md +382 -0
  171. package/neural-interface/lib/teams/api.js +287 -0
  172. package/neural-interface/lib/teams/brief.js +185 -0
  173. package/neural-interface/lib/teams/claims.js +315 -0
  174. package/neural-interface/lib/teams/git.js +293 -0
  175. package/neural-interface/lib/teams/index.js +122 -0
  176. package/neural-interface/lib/teams/integration.js +580 -0
  177. package/neural-interface/lib/teams/landing.js +184 -0
  178. package/neural-interface/lib/teams/recovery.js +256 -0
  179. package/neural-interface/lib/teams/scheduler.js +1474 -0
  180. package/neural-interface/lib/teams/schema.js +559 -0
  181. package/neural-interface/lib/teams/state.js +181 -0
  182. package/neural-interface/lib/teams/test-runner.js +86 -0
  183. package/neural-interface/lib/teams/test-sandbox.js +99 -0
  184. package/neural-interface/lib/teams/worktrees.js +757 -0
  185. package/neural-interface/lib/tool-permission-choices.js +226 -0
  186. package/neural-interface/lib/whatsapp/cards.js +24 -10
  187. package/neural-interface/lib/worker-confinement.js +206 -6
  188. package/neural-interface/package-lock.json +2 -2
  189. package/neural-interface/package.json +1 -1
  190. package/neural-interface/public/extension-setup.html +107 -0
  191. package/neural-interface/public/index.html +103 -12
  192. package/neural-interface/public/offline.html +4 -3
  193. package/neural-interface/public/shared/agent-runtime-options.js +3 -1
  194. package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
  195. package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
  196. package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
  197. package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
  198. package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
  199. package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
  200. package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
  201. package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
  202. package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
  203. package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
  204. package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
  205. package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
  206. package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
  207. package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
  208. package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
  209. package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
  210. package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
  211. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
  212. package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
  213. package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
  214. package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
  215. package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
  216. package/neural-interface/public/shared/agy/agy-panel.js +142 -28
  217. package/neural-interface/public/shared/agy/agy-styles.js +25 -5
  218. package/neural-interface/public/shared/api.js +2 -1
  219. package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
  220. package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
  221. package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
  222. package/neural-interface/public/shared/assistant/asst-control.js +3 -0
  223. package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
  224. package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
  225. package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
  226. package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
  227. package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
  228. package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
  229. package/neural-interface/public/shared/assistant/asst-render.js +37 -6
  230. package/neural-interface/public/shared/assistant/asst-route.js +80 -12
  231. package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
  232. package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
  233. package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
  234. package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
  235. package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
  236. package/neural-interface/public/shared/assistant/asst-state.js +66 -1
  237. package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
  238. package/neural-interface/public/shared/assistant/route-identity.js +16 -0
  239. package/neural-interface/public/shared/cc-dropdown.js +21 -15
  240. package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
  241. package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
  242. package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
  243. package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
  244. package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
  245. package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
  246. package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
  247. package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
  248. package/neural-interface/public/shared/code-copy.js +120 -0
  249. package/neural-interface/public/shared/constants.js +7 -0
  250. package/neural-interface/public/shared/context-menu-model.js +1 -0
  251. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  252. package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
  253. package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
  254. package/neural-interface/public/shared/cp/cp-styles.js +9 -0
  255. package/neural-interface/public/shared/dom-change-flag.js +66 -0
  256. package/neural-interface/public/shared/dom-morph.js +124 -0
  257. package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
  258. package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
  259. package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
  260. package/neural-interface/public/shared/html-shell.js +34 -4
  261. package/neural-interface/public/shared/i18n.js +14 -1
  262. package/neural-interface/public/shared/idle-queue.js +78 -0
  263. package/neural-interface/public/shared/iface-config.js +227 -0
  264. package/neural-interface/public/shared/lazy-module.js +108 -0
  265. package/neural-interface/public/shared/memory-list.js +117 -0
  266. package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
  267. package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
  268. package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
  269. package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
  272. package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
  273. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
  274. package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
  275. package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
  276. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
  277. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
  278. package/neural-interface/public/shared/owner-authority-view.js +4 -10
  279. package/neural-interface/public/shared/page-session.js +1 -1
  280. package/neural-interface/public/shared/schedules-view.js +2 -2
  281. package/neural-interface/public/shared/session-project-items.js +11 -0
  282. package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
  283. package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
  284. package/neural-interface/public/shared/settings/settings-ia.js +4 -2
  285. package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
  286. package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
  287. package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
  288. package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
  289. package/neural-interface/public/shared/sidepanel-shown.js +73 -0
  290. package/neural-interface/public/shared/start-bridge.js +2 -2
  291. package/neural-interface/public/shared/storage.js +6 -1
  292. package/neural-interface/public/shared/studio-attention.js +83 -0
  293. package/neural-interface/public/shared/styles.css +694 -50
  294. package/neural-interface/public/shared/term-browser-tabs.js +34 -0
  295. package/neural-interface/public/shared/transcript-rows.js +334 -0
  296. package/neural-interface/public/shared/tray-auto-close.js +106 -0
  297. package/neural-interface/public/shared/ui-agents.js +97 -0
  298. package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
  299. package/neural-interface/public/shared/ui-automation-studio.js +3 -3
  300. package/neural-interface/public/shared/ui-claude-panel.js +162 -95
  301. package/neural-interface/public/shared/ui-code-copy.js +256 -0
  302. package/neural-interface/public/shared/ui-codex-panel.js +14 -10
  303. package/neural-interface/public/shared/ui-context-menu.js +1 -1
  304. package/neural-interface/public/shared/ui-file-explorer.js +2 -3
  305. package/neural-interface/public/shared/ui-games.js +1 -1
  306. package/neural-interface/public/shared/ui-loading.js +83 -19
  307. package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
  308. package/neural-interface/public/shared/ui-menubar.js +23 -0
  309. package/neural-interface/public/shared/ui-native-loop-router.js +50 -21
  310. package/neural-interface/public/shared/ui-navbar.js +15 -9
  311. package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
  312. package/neural-interface/public/shared/ui-owner-authority.js +48 -25
  313. package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
  314. package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
  315. package/neural-interface/public/shared/ui-sessions.js +3 -3
  316. package/neural-interface/public/shared/ui-settings-entry.js +55 -0
  317. package/neural-interface/public/shared/ui-settings.js +363 -400
  318. package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
  319. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
  320. package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
  321. package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
  322. package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
  323. package/neural-interface/public/shared/ui-styleguide.js +10 -2
  324. package/neural-interface/public/shared/ui-sync.js +6 -0
  325. package/neural-interface/public/shared/ui-terminal.js +13 -9
  326. package/neural-interface/public/shared/ui-tooltip.js +28 -7
  327. package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
  328. package/neural-interface/public/shared/ui-tray-columns.js +375 -0
  329. package/neural-interface/public/shared/ui-whiteboard.js +51 -6
  330. package/neural-interface/public/shared/ui-worker-end.js +28 -1
  331. package/neural-interface/public/shared/ui-workspaces.js +13 -0
  332. package/neural-interface/public/shared/window-keys.js +71 -0
  333. package/neural-interface/public/sw.js +4 -3
  334. package/neural-interface/public/variant/2d/main.js +2 -0
  335. package/neural-interface/public/variant/3d/app.js +620 -0
  336. package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
  337. package/neural-interface/public/variant/3d/main.js +30 -544
  338. package/neural-interface/public/variant/3d/map-controls.js +4 -2
  339. package/neural-interface/public/vendor/fonts/fonts.css +508 -0
  340. package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
  341. package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
  342. package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
  343. package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
  344. package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
  345. package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
  346. package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
  347. package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
  348. package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
  349. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
  350. package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
  351. package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
  352. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
  353. package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
  354. package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
  355. package/neural-interface/public/vendor/fonts/manifest.json +142 -0
  356. package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
  357. package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
  358. package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
  359. package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
  360. package/neural-interface/scripts/boot-graph.mjs +270 -0
  361. package/neural-interface/scripts/vendor-fonts.mjs +124 -0
  362. package/neural-interface/server.js +1083 -164
  363. package/npm-shrinkwrap.json +2 -2
  364. package/package.json +4 -1
  365. package/skills/agent-forge/SKILL.md +182 -0
  366. package/skills/agent-forge/evals/evals.json +56 -0
  367. package/skills/agent-forge/references/definition-fields.md +61 -0
  368. package/skills/agent-forge/references/examples.md +105 -0
  369. package/skills/agent-forge/references/instructions.md +51 -0
  370. package/skills/agent-forge/references/review-and-export.md +84 -0
@@ -0,0 +1,642 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun — Agents: the AgentDefinition contract
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // An agent is a named, reviewed way to launch a worker: who it is (name, description, instructions), what it runs
6
+ // on (provider, model, effort, account), what it may touch (tools, MCP servers, capability, permission policy,
7
+ // browser, computer, MoreLogin profile, skills), where it applies (the global library or one project) and what it
8
+ // is for (task classes, memory category). A definition is kept as revisions, like a skill of the library
9
+ // (lib/skills/library.js, reviews.js): a draft is edited, sent to review, and only an approval makes it something a
10
+ // run may use. An approved revision is never edited; a change is a new draft on top of it.
11
+ //
12
+ // draft ──► in_review ──► approved ──► withdrawn
13
+ // │ ├──► draft (changes requested: back to the editor)
14
+ // │ └──► withdrawn
15
+ // └──► withdrawn
16
+ //
17
+ // This module is the contract only: the shape, the canonical form (normalize), what is refused (validate), what is
18
+ // merely worth a second look (lint), the revision rules and the fields a dispatch takes from a definition. The
19
+ // registry that stores definitions, the resolver that turns an `agent_ref` into a run and the page are later
20
+ // phases; they import this file and never keep a second copy of these rules.
21
+ //
22
+ // Pure: no file, network or clock access (callers pass the time). node:crypto only hashes, node:path only reads
23
+ // the text of a path. Which tool groups exist, which are gated and which drive the browser is the tool catalog's
24
+ // to say (mcp-server tool-catalog.ts, read through the same resolver a dispatch uses): no list of groups is kept here.
25
+
26
+ import { createHash } from 'node:crypto';
27
+ import { isAbsolute, normalize as normalizePath, sep } from 'node:path';
28
+ import { DEFAULT_TOOLS, isBrowserGroup } from '../../../mcp-server/dist/services/tool-catalog.js';
29
+ import { resolveToolList } from '../../../mcp-server/dist/services/tool-list.js';
30
+
31
+ export const AGENT_SCHEMA_VERSION = 1;
32
+
33
+ /** Worker runtimes (assistant-config.js ROUTE_PROVIDERS; tests/agents-schema.test.mjs checks they stay equal). */
34
+ export const AGENT_PROVIDERS = Object.freeze(['claude-code', 'codex', 'opencode', 'antigravity']);
35
+ /** The providers whose runs name an account (assistant-config.js ROUTE_ACCOUNT_PROVIDERS). */
36
+ export const AGENT_ACCOUNT_PROVIDERS = Object.freeze(['claude-code', 'codex']);
37
+ /** Lowest authority first (lib/worker-confinement.js says what each one means). */
38
+ export const AGENT_CAPABILITIES = Object.freeze(['read-only', 'workspace', 'full']);
39
+ export const AGENT_PERMISSION_POLICIES = Object.freeze(['auto', 'ask', 'restricted']);
40
+ /** The Assistant's task classes (assistant-router.js TASK_CLASSES; checked equal by the test). */
41
+ export const AGENT_TASK_CLASSES = Object.freeze(['chat', 'quick', 'code', 'complex', 'review', 'research', 'browser', 'computer', 'automation', 'design', 'image_gen', 'video_gen']);
42
+ export const AGENT_STATUSES = Object.freeze(['draft', 'in_review', 'approved', 'withdrawn']);
43
+ export const AGENT_SCOPE_KINDS = Object.freeze(['global', 'project']);
44
+ /** Who made a revision (lib/skills/library.js AUTHOR_KINDS). Only the owner approves. */
45
+ export const AGENT_AUTHOR_KINDS = Object.freeze(['owner', 'assistant', 'agent', 'system']);
46
+
47
+ /** Ids an agent cannot have: words an `agent_ref` or a menu already uses for something else. */
48
+ export const RESERVED_AGENT_IDS = Object.freeze(['all', 'assistant', 'auto', 'default', 'global', 'me', 'new', 'none', 'project', 'synabun']);
49
+
50
+ export const AGENT_LIMITS = Object.freeze({
51
+ id: 64, name: 80, description: 400, instructions: 16000, model: 200, effort: 40, accountId: 64,
52
+ mcpServers: 32, mcpServerName: 64, skills: 32, skillRef: 129, taskClasses: 12,
53
+ moreloginProfile: 200, memoryCategory: 64, icon: 40, color: 81, projectPath: 1024, authorRef: 200,
54
+ });
55
+ /** Instructions longer than this are a lint warning: every run of the agent pays for them. */
56
+ export const LONG_INSTRUCTIONS_CHARS = 6000;
57
+
58
+ /** The fields that say what an agent is. The etag is their digest; everything else is revision metadata. */
59
+ export const AGENT_CONTENT_FIELDS = Object.freeze([
60
+ 'id', 'name', 'description', 'instructions', 'provider', 'model', 'effort', 'accountId', 'tools', 'mcpServers',
61
+ 'capability', 'permissionPolicy', 'usesBrowser', 'usesComputer', 'moreloginProfile', 'skills', 'scope',
62
+ 'memoryCategory', 'taskClasses', 'icon', 'color',
63
+ ]);
64
+ export const AGENT_META_FIELDS = Object.freeze(['schemaVersion', 'revision', 'parentRevision', 'status', 'author', 'createdAt', 'approvedAt', 'etag']);
65
+
66
+ /** What a field holds when a definition does not say. `capability` is `workspace`, not the dispatcher's `full`: an agent that is not guarded says so. */
67
+ export const AGENT_DEFAULTS = Object.freeze({
68
+ model: null, effort: null, accountId: null, tools: null, mcpServers: Object.freeze([]), capability: 'workspace',
69
+ permissionPolicy: 'auto', usesBrowser: false, usesComputer: false, moreloginProfile: null, skills: Object.freeze([]),
70
+ scope: Object.freeze({ kind: 'global' }), memoryCategory: null, taskClasses: Object.freeze([]), icon: null, color: null,
71
+ });
72
+
73
+ const ID_RE = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
74
+ const ACCOUNT_RE = /^[a-z0-9-]{1,64}$/;
75
+ const SKILL_RE = /^(?:skl_[0-9a-f]{20}|[a-z0-9][a-z0-9-]{0,63}(?::[a-z0-9][a-z0-9-]{0,63})?)$/;
76
+ const CATEGORY_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
77
+ const ICON_RE = /^[a-z0-9][a-z0-9-]{0,39}$/;
78
+ /** A style-guide token: "{group.key}" or "group.key" (lib/style-guide/schema.js parseAlias). */
79
+ const TOKEN_RE = /^([A-Za-z0-9-]{1,40})\.([A-Za-z0-9-]{1,40})$/;
80
+ const RAW_COLOR_RE = /^(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix)\s*\(.*\)|var\s*\(.*\)|--[\w-]+)$/i;
81
+ const ETAG_RE = /^sha256:[0-9a-f]{64}$/;
82
+ const ISO_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
83
+ const AUTO_WORDS = new Set(['', 'auto', 'default']);
84
+ // Control characters other than tab, line feed and carriage return: never part of a name or of instructions.
85
+ // eslint-disable-next-line no-control-regex
86
+ const CONTROL_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
87
+ // eslint-disable-next-line no-control-regex
88
+ const LINE_CONTROL_RE = /[\u0000-\u001f\u007f]/;
89
+
90
+ export class AgentSchemaError extends Error {
91
+ /** @param {string} code @param {string} message @param {object} [extra] */
92
+ constructor(code, message, extra = {}) {
93
+ super(message);
94
+ this.name = 'AgentSchemaError';
95
+ this.code = code;
96
+ this.status = 400;
97
+ Object.assign(this, extra);
98
+ }
99
+ }
100
+
101
+ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
102
+ const has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
103
+ /** A field under either spelling: `permissionPolicy` or `permission_policy` (the MCP tools use the second). */
104
+ function pick(input, key) {
105
+ if (has(input, key)) return input[key];
106
+ const snake = key.replace(/[A-Z]/g, (ch) => `_${ch.toLowerCase()}`);
107
+ return snake !== key && has(input, snake) ? input[snake] : undefined;
108
+ }
109
+ const text = (value) => (typeof value === 'string' ? value : '');
110
+ const oneLine = (value) => text(value).replace(/\s+/g, ' ').trim();
111
+ const lower = (value) => text(value).trim().toLowerCase();
112
+ function uniqueSorted(values) { return [...new Set(values)].sort(); }
113
+ function stringList(value) {
114
+ if (!Array.isArray(value)) return [];
115
+ return value.filter((item) => typeof item === 'string').map((item) => item.trim()).filter(Boolean);
116
+ }
117
+ function bool(value, fallback) {
118
+ if (value === true || value === false) return value;
119
+ if (value === 'true') return true;
120
+ if (value === 'false') return false;
121
+ return fallback;
122
+ }
123
+ function isoOrNull(value) {
124
+ if (value === null || value === undefined || value === '') return null;
125
+ if (typeof value === 'number' && Number.isFinite(value)) return new Date(value).toISOString();
126
+ if (value instanceof Date && Number.isFinite(value.getTime())) return value.toISOString();
127
+ return typeof value === 'string' ? value.trim() : null;
128
+ }
129
+
130
+ /** "{primary.500}" / "primary.500" → "primary.500"; anything else as written (validate refuses it). */
131
+ function normalizeColor(value) {
132
+ const raw = text(value).trim();
133
+ if (!raw) return null;
134
+ const bare = raw.startsWith('{') && raw.endsWith('}') ? raw.slice(1, -1).trim() : raw;
135
+ return TOKEN_RE.test(bare) ? bare : raw;
136
+ }
137
+
138
+ function normalizeScope(value) {
139
+ if (!isObject(value)) return { kind: 'global' };
140
+ const kind = lower(value.kind);
141
+ if (kind !== 'project') return { kind: AGENT_SCOPE_KINDS.includes(kind) ? kind : 'global' };
142
+ const raw = text(value.path).trim();
143
+ // A path is compared by its text, so it is kept in one form: no "a/../b", no doubled or trailing separator.
144
+ let path = raw && isAbsolute(raw) ? normalizePath(raw) : raw;
145
+ while (path.length > 1 && path.endsWith(sep) && !/^[A-Za-z]:\\$/.test(path)) path = path.slice(0, -1);
146
+ return { kind: 'project', path };
147
+ }
148
+
149
+ function normalizeAuthor(value) {
150
+ const kind = isObject(value) ? lower(value.kind) : lower(value);
151
+ const ref = isObject(value) && typeof value.ref === 'string' && value.ref.trim() ? value.ref.trim().slice(0, AGENT_LIMITS.authorRef) : null;
152
+ return { kind: AGENT_AUTHOR_KINDS.includes(kind) ? kind : 'owner', ref };
153
+ }
154
+
155
+ /** The list a dispatch of this definition names: its groups, then `mcp:<name>` for each MCP server. */
156
+ function dispatchToolItems(def) {
157
+ return [...(def.tools || []).filter((id) => !id.startsWith('mcp:')), ...def.mcpServers.map((name) => `mcp:${name}`)];
158
+ }
159
+ /**
160
+ * The tool groups a definition names, as the catalog reads them (`all` is every selectable group). Empty when it
161
+ * names none, and when the list is one the catalog refuses (validate says why).
162
+ */
163
+ function namedGroups(def) {
164
+ if (!def.tools) return [];
165
+ const read = resolveToolList(def.tools.filter((id) => !id.startsWith('mcp:')), { source: 'runtime' });
166
+ return read.ok ? read.groups : [];
167
+ }
168
+ /** Does the definition drive the SynaBun browser: by its switch, or by a browser group it names? */
169
+ function usesBrowserTools(def) {
170
+ return def.usesBrowser || namedGroups(def).some(isBrowserGroup);
171
+ }
172
+ const TOOL_PROBLEM_CODES = Object.freeze({ unknown: 'unknown_tool', gated: 'gated_tool', 'too-long': 'too_long', 'too-many': 'too_many', 'non-selectable': 'invalid_format', 'not-a-string': 'invalid_type' });
173
+
174
+ /**
175
+ * A definition in its one canonical form: every field present, spellings folded (`uses_browser`, "Read-Only",
176
+ * "{primary.500}", `mcp:name`), lists de-duplicated and sorted, unknown keys dropped. Never throws and never
177
+ * judges: a value that cannot be what its field holds is kept as written when it is text (so `validate` can name
178
+ * it) and replaced by the default otherwise. The etag is recomputed from the content, never taken from the input.
179
+ * @param {object} [input]
180
+ * @returns {object} an AgentDefinition (see the README for the field list)
181
+ */
182
+ export function normalizeAgentDefinition(input = {}) {
183
+ const src = isObject(input) ? input : {};
184
+ const provider = lower(pick(src, 'provider')) || null;
185
+ const model = text(pick(src, 'model')).trim();
186
+ const effort = lower(pick(src, 'effort'));
187
+ const accountId = lower(pick(src, 'accountId'));
188
+ const rawTools = pick(src, 'tools');
189
+ const servers = stringList(pick(src, 'mcpServers')).map((name) => (name.toLowerCase().startsWith('mcp:') ? name.slice(4).trim() : name)).filter(Boolean);
190
+ const moreloginProfile = text(pick(src, 'moreloginProfile')).trim();
191
+ const memoryCategory = lower(pick(src, 'memoryCategory'));
192
+ const icon = lower(pick(src, 'icon'));
193
+ const content = {
194
+ id: lower(pick(src, 'id')),
195
+ name: oneLine(pick(src, 'name')),
196
+ description: oneLine(pick(src, 'description')),
197
+ instructions: text(pick(src, 'instructions')).replace(/\r\n?/g, '\n').trim(),
198
+ provider,
199
+ model: model && !AUTO_WORDS.has(model.toLowerCase()) ? model : null,
200
+ effort: effort && !AUTO_WORDS.has(effort) ? effort : null,
201
+ accountId: accountId && accountId !== 'default' ? accountId : null,
202
+ // null: the worker's default tools (as a dispatch with no `tools`); []: the always-on tools only.
203
+ tools: Array.isArray(rawTools) ? uniqueSorted(stringList(rawTools).map((id) => id.toLowerCase())) : null,
204
+ mcpServers: servers.includes('*') ? ['*'] : uniqueSorted(servers),
205
+ capability: lower(pick(src, 'capability')).replace(/_/g, '-') || AGENT_DEFAULTS.capability,
206
+ permissionPolicy: lower(pick(src, 'permissionPolicy')) || AGENT_DEFAULTS.permissionPolicy,
207
+ usesBrowser: bool(pick(src, 'usesBrowser'), false),
208
+ usesComputer: bool(pick(src, 'usesComputer'), false),
209
+ moreloginProfile: moreloginProfile || null,
210
+ skills: uniqueSorted(stringList(pick(src, 'skills')).map((ref) => ref.toLowerCase())),
211
+ scope: normalizeScope(pick(src, 'scope')),
212
+ memoryCategory: memoryCategory || null,
213
+ taskClasses: uniqueSorted(stringList(pick(src, 'taskClasses')).map((cls) => cls.toLowerCase().replace(/-/g, '_'))),
214
+ icon: icon || null,
215
+ color: normalizeColor(pick(src, 'color')),
216
+ };
217
+ const revision = Number(pick(src, 'revision'));
218
+ const parent = Number(pick(src, 'parentRevision'));
219
+ const status = lower(pick(src, 'status')).replace(/-/g, '_');
220
+ return {
221
+ schemaVersion: AGENT_SCHEMA_VERSION,
222
+ ...content,
223
+ revision: Number.isInteger(revision) && revision >= 1 ? revision : 1,
224
+ parentRevision: Number.isInteger(parent) && parent >= 1 ? parent : null,
225
+ status: status || 'draft',
226
+ author: normalizeAuthor(pick(src, 'author')),
227
+ createdAt: isoOrNull(pick(src, 'createdAt')),
228
+ approvedAt: isoOrNull(pick(src, 'approvedAt')),
229
+ etag: computeEtag(content),
230
+ };
231
+ }
232
+
233
+ /** The content fields of a definition, in their fixed order (what the etag covers and what a review compares). */
234
+ export function contentOf(definition = {}) {
235
+ const out = {};
236
+ for (const field of AGENT_CONTENT_FIELDS) out[field] = definition[field] === undefined ? null : definition[field];
237
+ return out;
238
+ }
239
+
240
+ /**
241
+ * The digest of a definition's content, `sha256:<64 hex>`. Two definitions with one etag run the same agent; the
242
+ * revision number, status, dates and author are not part of it. An approval belongs to the etag it was given for.
243
+ * Give it a normalized definition (or its `contentOf`).
244
+ */
245
+ export function computeEtag(definition = {}) {
246
+ const content = contentOf(definition);
247
+ const scope = isObject(content.scope) ? content.scope : { kind: 'global' };
248
+ // Keys are written in a fixed order so the digest never depends on how an object was built.
249
+ const canonical = AGENT_CONTENT_FIELDS.map((field) => [field, field === 'scope'
250
+ ? (scope.kind === 'project' ? { kind: 'project', path: scope.path ?? '' } : { kind: scope.kind ?? 'global' })
251
+ : content[field]]);
252
+ return `sha256:${createHash('sha256').update(JSON.stringify([AGENT_SCHEMA_VERSION, canonical])).digest('hex')}`;
253
+ }
254
+
255
+ const issue = (field, code, message) => ({ field, code, message });
256
+
257
+ function typeProblems(src) {
258
+ const out = [];
259
+ const want = (key, kind, test) => {
260
+ const value = pick(src, key);
261
+ if (value === undefined || value === null) return;
262
+ if (!test(value)) out.push(issue(key, 'invalid_type', `${key} must be ${kind}.`));
263
+ };
264
+ const isString = (v) => typeof v === 'string';
265
+ const isBool = (v) => v === true || v === false || v === 'true' || v === 'false';
266
+ const isStrings = (v) => Array.isArray(v) && v.every(isString);
267
+ for (const key of ['id', 'name', 'description', 'instructions', 'provider', 'model', 'effort', 'accountId', 'capability', 'permissionPolicy', 'moreloginProfile', 'memoryCategory', 'icon', 'color', 'status']) want(key, 'text', isString);
268
+ for (const key of ['usesBrowser', 'usesComputer']) want(key, 'true or false', isBool);
269
+ for (const key of ['tools', 'mcpServers', 'skills', 'taskClasses']) want(key, 'a list of text items', isStrings);
270
+ want('scope', 'an object like { kind: "global" } or { kind: "project", path }', isObject);
271
+ want('revision', 'a whole number from 1', (v) => Number.isInteger(Number(v)) && Number(v) >= 1 && typeof v !== 'boolean');
272
+ want('parentRevision', 'a whole number from 1', (v) => Number.isInteger(Number(v)) && Number(v) >= 1 && typeof v !== 'boolean');
273
+ return out;
274
+ }
275
+
276
+ /**
277
+ * Is this a definition SynaBun may keep and run? Structured errors, never an exception.
278
+ *
279
+ * @param {object} input a definition in any accepted spelling (it is normalized first)
280
+ * @param {object} [options]
281
+ * @param {Iterable<string>} [options.knownMcpServers] the MCP servers that exist: a name outside it is `unknown_mcp_server`
282
+ * @param {boolean} [options.requireMeta] a stored revision: `createdAt` is required and `etag`, when the input carries one, must match the content
283
+ * @returns {{ ok: boolean, errors: { field: string, code: string, message: string }[], value: object }}
284
+ * `value` is the normalized definition (also when `ok` is false, so a form can show it).
285
+ */
286
+ export function validateAgentDefinition(input, { knownMcpServers = null, requireMeta = false } = {}) {
287
+ if (!isObject(input)) {
288
+ return { ok: false, errors: [issue('', 'invalid_type', 'An agent definition is an object.')], value: normalizeAgentDefinition({}) };
289
+ }
290
+ const errors = typeProblems(input);
291
+ const typed = new Set(errors.map((error) => error.field));
292
+ const def = normalizeAgentDefinition(input);
293
+ const add = (field, code, message) => { if (!typed.has(field)) errors.push(issue(field, code, message)); };
294
+ const tooLong = (field, value, max) => { if (typeof value === 'string' && value.length > max) add(field, 'too_long', `${field} is at most ${max} characters.`); };
295
+
296
+ // ── identity ──
297
+ if (!def.id) add('id', 'required', 'id is required: a lower-case name like "release-notes".');
298
+ else if (def.id.length > AGENT_LIMITS.id) add('id', 'too_long', `id is at most ${AGENT_LIMITS.id} characters.`);
299
+ else if (!ID_RE.test(def.id)) add('id', 'invalid_format', 'id uses lower-case letters, digits and hyphens, and starts and ends with a letter or a digit.');
300
+ else if (RESERVED_AGENT_IDS.includes(def.id)) add('id', 'reserved', `"${def.id}" is a reserved word; pick another id.`);
301
+ if (!def.name) add('name', 'required', 'name is required.');
302
+ tooLong('name', def.name, AGENT_LIMITS.name);
303
+ tooLong('description', def.description, AGENT_LIMITS.description);
304
+ tooLong('instructions', def.instructions, AGENT_LIMITS.instructions);
305
+ if (LINE_CONTROL_RE.test(def.name)) add('name', 'invalid_format', 'name has a control character.');
306
+ if (CONTROL_RE.test(def.instructions)) add('instructions', 'invalid_format', 'instructions have a control character.');
307
+
308
+ // ── what it runs on ──
309
+ if (!def.provider) add('provider', 'required', `provider is required: one of ${AGENT_PROVIDERS.join(', ')}.`);
310
+ else if (!AGENT_PROVIDERS.includes(def.provider)) add('provider', 'unknown_value', `provider must be one of ${AGENT_PROVIDERS.join(', ')}.`);
311
+ tooLong('model', def.model, AGENT_LIMITS.model);
312
+ if (def.model && LINE_CONTROL_RE.test(def.model)) add('model', 'invalid_format', 'model has a control character.');
313
+ if (def.effort && !/^[a-z0-9][a-z0-9_-]{0,39}$/.test(def.effort)) add('effort', 'invalid_format', `effort is a level name of at most ${AGENT_LIMITS.effort} characters, like "high".`);
314
+ if (def.accountId && def.accountId !== 'auto' && !ACCOUNT_RE.test(def.accountId)) add('accountId', 'invalid_format', 'accountId is an account profile id (lower-case letters, digits, hyphens) or "auto".');
315
+
316
+ // ── what it may touch ──
317
+ for (const id of def.tools || []) {
318
+ if (id.startsWith('mcp:')) add('tools', 'mcp_in_tools', `"${id}" is an MCP server: name it in mcpServers ("${id.slice(4)}"), not in tools.`);
319
+ }
320
+ if (def.mcpServers.length > AGENT_LIMITS.mcpServers) add('mcpServers', 'too_many', `mcpServers lists at most ${AGENT_LIMITS.mcpServers} servers.`);
321
+ // The list is read by the resolver a dispatch uses (tool-list.ts), so what is kept here is what can start: unknown
322
+ // and gated groups, server names that cannot be selected and lists over the catalog's limits are its to refuse.
323
+ const read = resolveToolList(dispatchToolItems(def), { source: 'dispatch', provider: def.provider, usesBrowser: def.usesBrowser });
324
+ if (!read.ok) {
325
+ for (const problem of read.problems) {
326
+ const field = problem.item.startsWith('mcp:') ? 'mcpServers' : 'tools';
327
+ const what = problem.reason === 'too-many' ? `The tool list has ${problem.item}` : `"${problem.item}"`;
328
+ add(field, TOOL_PROBLEM_CODES[problem.reason] || 'invalid_tool', `${what}${problem.hint ? `: ${problem.hint}` : ' is not something a tool list can name'}.`);
329
+ }
330
+ }
331
+ const servers = knownMcpServers ? new Set(knownMcpServers) : null;
332
+ for (const name of def.mcpServers) {
333
+ if (servers && name !== '*' && !servers.has(name)) add('mcpServers', 'unknown_mcp_server', `Unknown MCP server "${name}".`);
334
+ }
335
+ if (!AGENT_CAPABILITIES.includes(def.capability)) add('capability', 'unknown_value', `capability must be one of ${AGENT_CAPABILITIES.join(', ')}.`);
336
+ if (!AGENT_PERMISSION_POLICIES.includes(def.permissionPolicy)) add('permissionPolicy', 'unknown_value', `permissionPolicy must be one of ${AGENT_PERMISSION_POLICIES.join(', ')}.`);
337
+ const browserTools = namedGroups(def).filter(isBrowserGroup);
338
+ // The dispatcher refuses the same pair (assistant-tools.js browserToolsConflict): a definition that can never start is not kept.
339
+ if (!def.usesBrowser && browserTools.length) add('usesBrowser', 'browser_tools_without_browser', `tools names browser groups (${def.tools.includes('all') ? 'all' : browserTools.join(', ')}) but usesBrowser is false: set it, or drop them.`);
340
+ tooLong('moreloginProfile', def.moreloginProfile, AGENT_LIMITS.moreloginProfile);
341
+ if (def.moreloginProfile && !def.usesBrowser) add('moreloginProfile', 'profile_without_browser', 'moreloginProfile names the MoreLogin profile of the agent\'s browser tab: set usesBrowser with it, or leave it out.');
342
+ if (def.skills.length > AGENT_LIMITS.skills) add('skills', 'too_many', `skills lists at most ${AGENT_LIMITS.skills} skills.`);
343
+ for (const ref of def.skills) if (!SKILL_RE.test(ref)) add('skills', 'invalid_format', `"${ref.slice(0, 80)}" is not a skill name ("release-notes", "plugin:skill") or a library id (skl_…).`);
344
+
345
+ // ── where it applies, what it is for ──
346
+ const rawScope = pick(input, 'scope');
347
+ if (isObject(rawScope) && !AGENT_SCOPE_KINDS.includes(lower(rawScope.kind))) add('scope', 'unknown_value', `scope.kind must be one of ${AGENT_SCOPE_KINDS.join(', ')}.`);
348
+ if (def.scope.kind === 'project') {
349
+ if (isObject(rawScope) && rawScope.path !== undefined && typeof rawScope.path !== 'string') add('scope.path', 'invalid_type', 'scope.path must be text.');
350
+ else if (!def.scope.path) add('scope.path', 'required', 'A project agent names its project: scope.path is the project folder.');
351
+ else if (def.scope.path.includes('\u0000') || LINE_CONTROL_RE.test(def.scope.path)) add('scope.path', 'invalid_format', 'scope.path has a control character.');
352
+ else if (!isAbsolute(def.scope.path)) add('scope.path', 'path_not_absolute', 'scope.path must be an absolute path.');
353
+ else if (def.scope.path.length > AGENT_LIMITS.projectPath) add('scope.path', 'too_long', `scope.path is at most ${AGENT_LIMITS.projectPath} characters.`);
354
+ }
355
+ if (def.memoryCategory && !CATEGORY_RE.test(def.memoryCategory)) add('memoryCategory', 'invalid_format', 'memoryCategory is a category name: lower-case letters, digits and hyphens.');
356
+ if (def.taskClasses.length > AGENT_LIMITS.taskClasses) add('taskClasses', 'too_many', `taskClasses lists at most ${AGENT_LIMITS.taskClasses} classes.`);
357
+ for (const cls of def.taskClasses) if (!/^[a-z][a-z0-9_]{0,39}$/.test(cls)) add('taskClasses', 'invalid_format', `"${cls.slice(0, 80)}" is not a task class name.`);
358
+ if (def.icon && !ICON_RE.test(def.icon)) add('icon', 'invalid_format', 'icon is an icon name (lower-case letters, digits, hyphens): never markup, a path or a URL.');
359
+ if (def.color && !TOKEN_RE.test(def.color)) {
360
+ if (RAW_COLOR_RE.test(def.color)) add('color', 'raw_color', 'color is a style-guide token name like "status.info": never a raw colour value.');
361
+ else add('color', 'invalid_format', 'color is a style-guide token name in the form "group.key" (for example "primary.500" or "status.info").');
362
+ }
363
+
364
+ // ── revision metadata ──
365
+ if (!AGENT_STATUSES.includes(def.status)) add('status', 'unknown_value', `status must be one of ${AGENT_STATUSES.join(', ')}.`);
366
+ for (const field of ['createdAt', 'approvedAt']) {
367
+ if (def[field] !== null && !(ISO_RE.test(def[field]) && Number.isFinite(Date.parse(def[field])))) add(field, 'invalid_date', `${field} must be an ISO 8601 UTC time like 2026-11-15T12:00:00.000Z.`);
368
+ }
369
+ if (def.parentRevision !== null && def.parentRevision >= def.revision) add('parentRevision', 'invalid_revision', 'parentRevision is an earlier revision than revision.');
370
+ if (def.status === 'approved' && !def.approvedAt) add('approvedAt', 'required', 'An approved revision says when it was approved.');
371
+ if (def.status !== 'approved' && def.status !== 'withdrawn' && def.approvedAt) add('approvedAt', 'not_approved', 'approvedAt belongs to an approved revision only.');
372
+ if (def.approvedAt && def.createdAt && ISO_RE.test(def.approvedAt) && ISO_RE.test(def.createdAt) && Date.parse(def.approvedAt) < Date.parse(def.createdAt)) add('approvedAt', 'invalid_date', 'approvedAt is not earlier than createdAt.');
373
+ const author = pick(input, 'author');
374
+ if (author !== undefined && author !== null) {
375
+ const kind = isObject(author) ? author.kind : author;
376
+ if (typeof kind !== 'string' || !AGENT_AUTHOR_KINDS.includes(kind.trim().toLowerCase())) add('author', 'unknown_value', `author.kind must be one of ${AGENT_AUTHOR_KINDS.join(', ')}.`);
377
+ }
378
+ const givenEtag = pick(input, 'etag');
379
+ if (givenEtag !== undefined && givenEtag !== null) {
380
+ if (typeof givenEtag !== 'string' || !ETAG_RE.test(givenEtag)) add('etag', 'invalid_format', 'etag is "sha256:" and 64 hex digits.');
381
+ else if (requireMeta && givenEtag !== def.etag) add('etag', 'etag_mismatch', 'etag is not the digest of this content: the definition was changed after its etag was written.');
382
+ }
383
+ if (requireMeta && !def.createdAt) add('createdAt', 'required', 'A stored revision says when it was made.');
384
+
385
+ return { ok: errors.length === 0, errors, value: def };
386
+ }
387
+
388
+ /**
389
+ * Softer findings on a definition that `validate` accepts: things an owner should look at before approving, never a
390
+ * refusal. Runs on the normalized form; pass what the caller knows to get the checks that need it.
391
+ *
392
+ * @param {object} input
393
+ * @param {object} [options]
394
+ * @param {Iterable<string>} [options.knownTaskClasses] defaults to AGENT_TASK_CLASSES
395
+ * @param {Iterable<string>} [options.knownSkills] skill names / ids that exist
396
+ * @param {Iterable<string>} [options.knownColorTokens] style-guide tokens ("group.key") the project defines
397
+ * @param {Iterable<string>} [options.knownCategories] memory categories that exist
398
+ * @param {Iterable<string>} [options.knownModels] model ids the provider lists
399
+ * @returns {{ field: string, code: string, message: string }[]}
400
+ */
401
+ export function lintAgentDefinition(input, { knownTaskClasses = AGENT_TASK_CLASSES, knownSkills = null, knownColorTokens = null, knownCategories = null, knownModels = null } = {}) {
402
+ const def = normalizeAgentDefinition(input);
403
+ const out = [];
404
+ const warn = (field, code, message) => out.push(issue(field, code, message));
405
+ const browserUse = usesBrowserTools(def);
406
+
407
+ if (!def.instructions) warn('instructions', 'empty_instructions', 'The agent has no instructions: it would run as a plain worker under another name.');
408
+ else if (def.instructions.length > LONG_INSTRUCTIONS_CHARS) warn('instructions', 'long_instructions', `The instructions are over ${LONG_INSTRUCTIONS_CHARS} characters: every run of this agent pays for them.`);
409
+ if (!def.description) warn('description', 'empty_description', 'The agent has no description: the Assistant chooses agents by it.');
410
+ if (def.capability === 'full' && browserUse) warn('capability', 'full_with_browser', 'Full capability with browser use: pages are untrusted input and nothing guards what the worker then does. Such a run starts only when tagged "user-authorized-full".');
411
+ if (def.capability === 'full' && def.usesComputer) warn('capability', 'full_with_computer', 'Full capability with computer use: the screen is untrusted input and nothing guards what the worker then does. Such a run starts only when tagged "user-authorized-full".');
412
+ if (def.capability === 'full' && !browserUse && !def.usesComputer) warn('capability', 'full_capability', 'Full capability is never guarded: the worker can write anywhere this user can. Workspace is enough for most coding agents.');
413
+ if (def.capability === 'read-only' && def.taskClasses.some((cls) => cls === 'code' || cls === 'complex' || cls === 'quick')) warn('capability', 'read_only_for_code', 'A read-only agent cannot edit files, but it is offered for coding tasks.');
414
+ if (def.usesComputer && def.taskClasses.length && !def.taskClasses.includes('computer')) warn('taskClasses', 'computer_without_class', 'usesComputer is on but the agent is not offered for the "computer" task class.');
415
+ if (def.permissionPolicy === 'restricted' && def.capability === 'full') warn('permissionPolicy', 'restricted_with_full', 'permissionPolicy "restricted" runs a workspace-write sandbox, which contradicts capability "full".');
416
+ if ((def.tools || []).includes('all')) warn('tools', 'all_tools', 'tools "all" gives the agent every selectable SynaBun group; list the ones it needs.');
417
+ const readTools = def.tools ? resolveToolList(def.tools.filter((id) => !id.startsWith('mcp:')), { source: 'runtime' }) : null;
418
+ for (const id of readTools?.ok ? readTools.dropped : []) warn('tools', 'always_on_tool', `"${id}" is always available to a worker: naming it changes nothing.`);
419
+ if (def.mcpServers.includes('*')) warn('mcpServers', 'all_mcp_servers', 'mcpServers "*" gives the agent every MCP server you allow; list the ones it needs.');
420
+ if (def.accountId && def.provider && !AGENT_ACCOUNT_PROVIDERS.includes(def.provider)) warn('accountId', 'account_ignored', `${def.provider} has no accounts in SynaBun: accountId is ignored.`);
421
+ const classes = new Set(knownTaskClasses);
422
+ for (const cls of def.taskClasses) if (!classes.has(cls)) warn('taskClasses', 'unknown_task_class', `Unknown task class "${cls}": the Assistant never routes one, so it never picks this agent for it.`);
423
+ if (!def.taskClasses.length) warn('taskClasses', 'no_task_classes', 'No task class is named: the agent is offered only when it is asked for by name.');
424
+ if (knownSkills) { const set = new Set(knownSkills); for (const ref of def.skills) if (!set.has(ref)) warn('skills', 'unknown_skill', `Skill "${ref}" was not found.`); }
425
+ if (knownColorTokens && def.color && !new Set(knownColorTokens).has(def.color)) warn('color', 'unknown_color_token', `The style guide has no token "${def.color}".`);
426
+ if (knownCategories && def.memoryCategory && !new Set(knownCategories).has(def.memoryCategory)) warn('memoryCategory', 'unknown_category', `Memory category "${def.memoryCategory}" does not exist yet; it is created the first time the agent saves.`);
427
+ if (knownModels && def.model && !new Set(knownModels).has(def.model)) warn('model', 'unknown_model', `Model "${def.model}" is not in the provider's list.`);
428
+ return out;
429
+ }
430
+
431
+ // ── revisions ────────────────────────────────────────────────────────────────
432
+
433
+ /** Which status may follow which. A revision that reached `withdrawn` stays there; a change of an approved one is a new draft. */
434
+ export const AGENT_STATUS_TRANSITIONS = Object.freeze({
435
+ draft: Object.freeze(['in_review', 'withdrawn']),
436
+ in_review: Object.freeze(['approved', 'draft', 'withdrawn']),
437
+ approved: Object.freeze(['withdrawn']),
438
+ withdrawn: Object.freeze([]),
439
+ });
440
+
441
+ export function canTransition(from, to) {
442
+ return (AGENT_STATUS_TRANSITIONS[from] || []).includes(to);
443
+ }
444
+ /** Only a draft is edited in place. */
445
+ export function isEditable(definition) { return definition?.status === 'draft'; }
446
+ /** Only an approved revision is something a run may use. */
447
+ export function isRunnable(definition) { return definition?.status === 'approved'; }
448
+
449
+ const actorKind = (actor) => (isObject(actor) ? lower(actor.kind) : lower(actor));
450
+ const stamp = (now) => (typeof now === 'number' ? new Date(now).toISOString() : String(now));
451
+
452
+ /**
453
+ * A first draft, or the next draft over an earlier revision of the same agent.
454
+ * @param {object} input the content (and optionally `author`)
455
+ * @param {object} options
456
+ * @param {string|number} options.now the time, as an ISO string or epoch milliseconds (this module reads no clock)
457
+ * @param {object|null} [options.base] the revision this draft is made over: its number becomes `parentRevision`
458
+ * @param {number} [options.revision] the number the registry gives this draft (default: base's + 1, or 1)
459
+ * @param {object|string} [options.author] who is making it (default: the input's, else owner)
460
+ */
461
+ export function createDraft(input, { now, base = null, revision = null, author = null } = {}) {
462
+ if (now === undefined || now === null) throw new AgentSchemaError('now_required', 'createDraft needs the time: pass { now }.');
463
+ const baseRevision = base ? Number(base.revision) : null;
464
+ if (base && isObject(input) && lower(pick(input, 'id')) && lower(pick(input, 'id')) !== base.id) {
465
+ throw new AgentSchemaError('id_changed', 'A revision keeps the id of the agent it revises.', { field: 'id' });
466
+ }
467
+ return normalizeAgentDefinition({
468
+ ...(base ? contentOf(base) : {}),
469
+ ...(isObject(input) ? input : {}),
470
+ revision: revision ?? (baseRevision ? baseRevision + 1 : 1),
471
+ parentRevision: baseRevision,
472
+ status: 'draft',
473
+ author: author ?? (isObject(input) ? pick(input, 'author') : null) ?? 'owner',
474
+ createdAt: stamp(now),
475
+ approvedAt: null,
476
+ });
477
+ }
478
+
479
+ /**
480
+ * Move a revision to another status. Returns a new definition; the one given is not changed.
481
+ * Approving is the owner's alone: an agent, the Assistant or the system never approves what it or another made.
482
+ * @param {object} definition
483
+ * @param {string} to one of AGENT_STATUSES
484
+ * @param {object} options
485
+ * @param {string|number} options.now
486
+ * @param {object|string} options.actor `{ kind }` or the kind: owner | assistant | agent | system
487
+ * @throws {AgentSchemaError} `invalid_transition`, `approval_requires_owner`, `not_valid` (with `errors`)
488
+ */
489
+ export function applyTransition(definition, to, { now, actor } = {}) {
490
+ const def = normalizeAgentDefinition(definition);
491
+ const target = lower(to).replace(/-/g, '_');
492
+ if (now === undefined || now === null) throw new AgentSchemaError('now_required', 'applyTransition needs the time: pass { now }.');
493
+ if (!canTransition(def.status, target)) {
494
+ throw new AgentSchemaError('invalid_transition', `A revision that is ${def.status} cannot become ${target || 'that'}.`, { status: 409, from: def.status, to: target });
495
+ }
496
+ const who = actorKind(actor);
497
+ if (!AGENT_AUTHOR_KINDS.includes(who)) throw new AgentSchemaError('actor_required', `applyTransition needs who is acting: one of ${AGENT_AUTHOR_KINDS.join(', ')}.`);
498
+ if (target === 'approved' && who !== 'owner') {
499
+ throw new AgentSchemaError('approval_requires_owner', 'Only the owner approves an agent definition.', { status: 403 });
500
+ }
501
+ const next = { ...def, status: target, approvedAt: target === 'approved' ? stamp(now) : (target === 'withdrawn' ? def.approvedAt : null) };
502
+ if (target === 'in_review' || target === 'approved') {
503
+ const checked = validateAgentDefinition(next);
504
+ if (!checked.ok) throw new AgentSchemaError('not_valid', 'The definition has errors; fix them first.', { errors: checked.errors });
505
+ }
506
+ return next;
507
+ }
508
+
509
+ const CAPABILITY_RANK = Object.freeze({ 'read-only': 0, workspace: 1, full: 2 });
510
+ // How much a policy lets a worker do without asking: "ask" relays every permission, "restricted" sandboxes, "auto" is free.
511
+ const POLICY_RANK = Object.freeze({ ask: 0, restricted: 1, auto: 2 });
512
+
513
+ /** What a definition lets its worker do, in one flat record (the review's "what can it do" and the base of privilegeDelta). */
514
+ export function privilegesOf(definition) {
515
+ const def = normalizeAgentDefinition(definition);
516
+ return {
517
+ capability: def.capability,
518
+ permissionPolicy: def.permissionPolicy,
519
+ tools: def.tools,
520
+ mcpServers: def.mcpServers,
521
+ usesBrowser: usesBrowserTools(def),
522
+ usesComputer: def.usesComputer,
523
+ moreloginProfile: def.moreloginProfile,
524
+ skills: def.skills,
525
+ scope: def.scope.kind,
526
+ };
527
+ }
528
+
529
+ /**
530
+ * What `after` may do that `before` may not (lib/skills/reviews.js authorityDelta, for agents). `before` null: a
531
+ * first revision, compared with an agent that may do nothing. A change that only narrows is not an escalation.
532
+ * `tools: null` is the worker's default list, compared group by group as the tool catalog's DEFAULT_TOOLS (or the
533
+ * list given as `defaultTools`; with `defaultTools: null` a move to or from the default list counts as an
534
+ * escalation, because it cannot be told).
535
+ * @param {object|null} before
536
+ * @param {object} after
537
+ * @param {{ defaultTools?: Iterable<string>|null }} [options]
538
+ * @returns {{ escalates: boolean, changes: { field: string, from: any, to: any, escalates: boolean }[] }}
539
+ */
540
+ export function privilegeDelta(before, after, { defaultTools = DEFAULT_TOOLS } = {}) {
541
+ const b = before ? privilegesOf(before) : { capability: null, permissionPolicy: null, tools: [], mcpServers: [], usesBrowser: false, usesComputer: false, moreloginProfile: null, skills: [], scope: null };
542
+ const a = privilegesOf(after);
543
+ const changes = [];
544
+ const note = (field, from, to, escalates) => changes.push({ field, from, to, escalates });
545
+ if (a.capability !== b.capability) note('capability', b.capability, a.capability, (CAPABILITY_RANK[a.capability] ?? 3) > (CAPABILITY_RANK[b.capability] ?? -1));
546
+ if (a.permissionPolicy !== b.permissionPolicy) note('permissionPolicy', b.permissionPolicy, a.permissionPolicy, (POLICY_RANK[a.permissionPolicy] ?? 3) > (POLICY_RANK[b.permissionPolicy] ?? -1));
547
+ const same = (x, y) => (x === null || y === null ? x === y : x.length === y.length && x.every((item, i) => item === y[i]));
548
+ // `wild`: the item that stands for everything ("all", "*"). `fallback`: what a null list means, when known.
549
+ const list = (field, from, to, wild, fallback) => {
550
+ if (same(from, to)) return;
551
+ const defaults = fallback ? [...fallback] : null;
552
+ const had = from === null ? defaults : from;
553
+ const has = to === null ? defaults : to;
554
+ // A default list nobody spelled out cannot be compared: shown, and counted as wider.
555
+ if (had === null || has === null) { note(field, from, to, true); return; }
556
+ const widened = !!wild && has.includes(wild) && !had.includes(wild);
557
+ const added = had.includes(wild) ? [] : has.filter((item) => !had.includes(item));
558
+ note(field, from, to, widened || added.length > 0);
559
+ };
560
+ list('tools', b.tools, a.tools, 'all', defaultTools);
561
+ list('mcpServers', b.mcpServers, a.mcpServers, '*', null);
562
+ list('skills', b.skills, a.skills, null, null);
563
+ if (a.usesBrowser !== b.usesBrowser) note('usesBrowser', b.usesBrowser, a.usesBrowser, a.usesBrowser);
564
+ if (a.usesComputer !== b.usesComputer) note('usesComputer', b.usesComputer, a.usesComputer, a.usesComputer);
565
+ if (a.moreloginProfile !== b.moreloginProfile) note('moreloginProfile', b.moreloginProfile, a.moreloginProfile, !!a.moreloginProfile);
566
+ if (a.scope !== b.scope) note('scope', b.scope, a.scope, a.scope === 'global');
567
+ return { escalates: changes.some((change) => change.escalates), changes };
568
+ }
569
+
570
+ // ── what a run takes from a definition ───────────────────────────────────────
571
+
572
+ /**
573
+ * The fields a dispatch gets from an agent, in the dispatcher's own spelling (assistant-dispatch.js normalizeSpec):
574
+ * what `agent_ref` pins on a run. `tools` is the dispatch list: the definition's groups plus `mcp:<name>` for each
575
+ * MCP server (`mcp:*` for all), or undefined when the definition names neither (the worker's defaults apply).
576
+ * The task text, cwd, session and budget are the dispatch's own and are not here.
577
+ */
578
+ export function dispatchFields(definition) {
579
+ const def = normalizeAgentDefinition(definition);
580
+ const servers = def.mcpServers.map((name) => `mcp:${name}`);
581
+ const out = {
582
+ provider: def.provider,
583
+ capability: def.capability,
584
+ permissionPolicy: def.permissionPolicy,
585
+ usesBrowser: def.usesBrowser,
586
+ usesComputer: def.usesComputer,
587
+ };
588
+ if (def.model) out.model = def.model;
589
+ if (def.effort) out.effort = def.effort;
590
+ if (def.accountId && AGENT_ACCOUNT_PROVIDERS.includes(def.provider)) out.accountId = def.accountId;
591
+ if (def.tools !== null || servers.length) out.tools = [...(def.tools || []), ...servers];
592
+ if (def.moreloginProfile && def.usesBrowser) out.moreloginProfile = def.moreloginProfile;
593
+ return out;
594
+ }
595
+
596
+ // ── agent_ref ────────────────────────────────────────────────────────────────
597
+
598
+ const REF_RE = /^(?:(global|project):)?([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?:@([1-9][0-9]{0,8}))?$/;
599
+
600
+ /**
601
+ * An `agent_ref` as a dispatch or a team slice writes it: `<id>`, `<id>@<revision>`, `global:<id>`,
602
+ * `project:<id>@<revision>`. Without a scope the project's agent of that id wins over the global one; without a
603
+ * revision the approved one is meant.
604
+ * @returns {{ id: string, revision: number|null, scope: 'global'|'project'|null } | null} null: not a ref
605
+ */
606
+ export function parseAgentRef(ref) {
607
+ const match = typeof ref === 'string' ? REF_RE.exec(ref.trim().toLowerCase()) : null;
608
+ if (!match || RESERVED_AGENT_IDS.includes(match[2])) return null;
609
+ return { id: match[2], revision: match[3] ? Number(match[3]) : null, scope: match[1] || null };
610
+ }
611
+
612
+ /** The ref of a definition or of `{ id, revision, scope }` parts: the text `parseAgentRef` reads back. */
613
+ export function formatAgentRef({ id, revision = null, scope = null } = {}) {
614
+ const kind = isObject(scope) ? scope.kind : scope;
615
+ const out = `${kind === 'global' || kind === 'project' ? `${kind}:` : ''}${String(id || '').trim().toLowerCase()}${Number.isInteger(revision) && revision >= 1 ? `@${revision}` : ''}`;
616
+ if (!parseAgentRef(out)) throw new AgentSchemaError('invalid_ref', `Not an agent ref: ${out || '(empty)'}`);
617
+ return out;
618
+ }
619
+
620
+ /**
621
+ * Where a ref is looked up, first match wins: the project's own agents, then the global library (the owner's
622
+ * choice: a global library plus per-project agents). A ref that names a scope is looked up there only.
623
+ * @param {{ scope: string|null }} parsed a parseAgentRef result
624
+ * @param {string|null} projectPath the project the run is for
625
+ * @returns {{ kind: 'project', path: string }|{ kind: 'global' }}[]
626
+ */
627
+ export function resolutionOrder(parsed, projectPath = null) {
628
+ const project = projectPath ? [{ kind: 'project', path: normalizeScope({ kind: 'project', path: projectPath }).path }] : [];
629
+ if (parsed?.scope === 'global') return [{ kind: 'global' }];
630
+ if (parsed?.scope === 'project') return project;
631
+ return [...project, { kind: 'global' }];
632
+ }
633
+
634
+ /** Do two scopes name the same place? */
635
+ export function sameScope(a, b) {
636
+ const x = normalizeScope(a);
637
+ const y = normalizeScope(b);
638
+ return x.kind === y.kind && (x.kind !== 'project' || x.path === y.path);
639
+ }
640
+
641
+ // The short names the phase plan uses.
642
+ export { normalizeAgentDefinition as normalize, validateAgentDefinition as validate, lintAgentDefinition as lint };