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.
- package/CHANGELOG.md +24 -0
- package/README.md +1 -1
- package/browser-extension/content.js +169 -0
- package/browser-extension/engine.js +477 -0
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +56 -0
- package/browser-extension/popup-strings.js +244 -0
- package/browser-extension/popup-view.js +151 -0
- package/browser-extension/popup.css +165 -0
- package/browser-extension/popup.html +105 -0
- package/browser-extension/popup.js +347 -0
- package/browser-extension/protocol.js +226 -0
- package/browser-extension/service-worker.js +267 -0
- package/browser-extension/setup-content.js +36 -0
- package/browser-extension/tokens.css +326 -0
- package/docs/browser-extension-bridge.md +84 -0
- package/docs/whatsapp.md +1 -1
- package/mcp-server/dist/http.d.ts +2 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +9 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts +11 -0
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +38 -3
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.js +10 -3
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.js +7 -0
- package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +94 -3
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +168 -23
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/team-context.d.ts +18 -0
- package/mcp-server/dist/services/team-context.d.ts.map +1 -0
- package/mcp-server/dist/services/team-context.js +29 -0
- package/mcp-server/dist/services/team-context.js.map +1 -0
- package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
- package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +22 -6
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-list.js +4 -0
- package/mcp-server/dist/services/tool-list.js.map +1 -1
- package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
- package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-runtime.js +18 -1
- package/mcp-server/dist/services/tool-runtime.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
- package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
- package/mcp-server/dist/tools/agent-definition.js +483 -0
- package/mcp-server/dist/tools/agent-definition.js.map +1 -0
- package/mcp-server/dist/tools/agents.d.ts +91 -9
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +161 -20
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +70 -6
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/git-tools.d.ts +4 -2
- package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/git-tools.js +283 -2
- package/mcp-server/dist/tools/git-tools.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +8 -2
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +22 -5
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/team.d.ts +32 -0
- package/mcp-server/dist/tools/team.d.ts.map +1 -0
- package/mcp-server/dist/tools/team.js +87 -0
- package/mcp-server/dist/tools/team.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +9 -1
- package/mcp-server/src/index.ts +34 -4
- package/mcp-server/src/services/browser-route-flow.ts +12 -5
- package/mcp-server/src/services/codex-config-heal.ts +7 -0
- package/mcp-server/src/services/neural-interface.ts +190 -29
- package/mcp-server/src/services/team-context.ts +27 -0
- package/mcp-server/src/services/tool-catalog.ts +26 -8
- package/mcp-server/src/services/tool-list.ts +4 -0
- package/mcp-server/src/services/tool-runtime.ts +21 -2
- package/mcp-server/src/tools/agent-definition.ts +458 -0
- package/mcp-server/src/tools/agents.ts +175 -19
- package/mcp-server/src/tools/browser-advanced.ts +60 -6
- package/mcp-server/src/tools/git-tools.ts +249 -3
- package/mcp-server/src/tools/morelogin.ts +20 -5
- package/mcp-server/src/tools/team.ts +97 -0
- package/neural-interface/i18n/en.json +1117 -47
- package/neural-interface/i18n/pt-BR.json +1117 -47
- package/neural-interface/lib/account-usage.js +1 -1
- package/neural-interface/lib/agents/density.js +101 -0
- package/neural-interface/lib/agents/forge-host.js +223 -0
- package/neural-interface/lib/agents/native-export-targets.js +190 -0
- package/neural-interface/lib/agents/native-export.js +365 -0
- package/neural-interface/lib/agents/registry.js +840 -0
- package/neural-interface/lib/agents/resolve.js +544 -0
- package/neural-interface/lib/agents/schema.js +642 -0
- package/neural-interface/lib/agents/split.js +37 -0
- package/neural-interface/lib/agents-studio-api.js +591 -0
- package/neural-interface/lib/assistant-api.js +76 -7
- package/neural-interface/lib/assistant-catalog.js +2 -0
- package/neural-interface/lib/assistant-continuity.js +49 -0
- package/neural-interface/lib/assistant-dispatch.js +229 -102
- package/neural-interface/lib/assistant-persona.js +105 -8
- package/neural-interface/lib/assistant-route-gate.js +24 -9
- package/neural-interface/lib/assistant-router.js +384 -42
- package/neural-interface/lib/assistant-run-tail.js +151 -0
- package/neural-interface/lib/assistant-run-wait.js +183 -0
- package/neural-interface/lib/assistant-runtime.js +440 -93
- package/neural-interface/lib/assistant-task-prompt.js +11 -2
- package/neural-interface/lib/assistant-usage.js +3 -2
- package/neural-interface/lib/automation-approval.js +2 -2
- package/neural-interface/lib/browser-close-evidence.js +80 -0
- package/neural-interface/lib/browser-default.js +210 -0
- package/neural-interface/lib/browser-extension-adapter.js +255 -0
- package/neural-interface/lib/browser-extension-bridge.js +418 -0
- package/neural-interface/lib/browser-extension-folder.js +116 -0
- package/neural-interface/lib/browser-extension-setup.js +140 -0
- package/neural-interface/lib/browser-profile-choices.js +3 -3
- package/neural-interface/lib/browser-tool-policy.js +1 -1
- package/neural-interface/lib/claude-account-links.js +301 -0
- package/neural-interface/lib/claude-accounts.js +45 -20
- package/neural-interface/lib/claude-agent-bridge.js +142 -10
- package/neural-interface/lib/claude-model-catalog.js +6 -0
- package/neural-interface/lib/claude-panel-session.js +33 -0
- package/neural-interface/lib/codex-accounts.js +67 -24
- package/neural-interface/lib/coordination/README.md +384 -0
- package/neural-interface/lib/coordination/service.js +563 -0
- package/neural-interface/lib/coordination/store.js +1138 -0
- package/neural-interface/lib/db.js +22 -1
- package/neural-interface/lib/effort-levels.js +10 -1
- package/neural-interface/lib/memory-list-page.js +49 -0
- package/neural-interface/lib/memory-list-stamp.js +60 -0
- package/neural-interface/lib/morelogin-outside-close.js +186 -0
- package/neural-interface/lib/morelogin-profile-failures.js +206 -0
- package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
- package/neural-interface/lib/morelogin.js +194 -8
- package/neural-interface/lib/native-loop-runtime.js +20 -0
- package/neural-interface/lib/opencode-build-preflight.js +16 -1
- package/neural-interface/lib/opencode-native-boundary.js +83 -13
- package/neural-interface/lib/opencode-serve-records.js +14 -9
- package/neural-interface/lib/page-session.js +1 -1
- package/neural-interface/lib/peer-identity.js +60 -21
- package/neural-interface/lib/process-identity.js +68 -7
- package/neural-interface/lib/request-gate.js +3 -0
- package/neural-interface/lib/screenshot-location.js +33 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
- package/neural-interface/lib/studio-attention.js +56 -0
- package/neural-interface/lib/teams/README.md +382 -0
- package/neural-interface/lib/teams/api.js +287 -0
- package/neural-interface/lib/teams/brief.js +185 -0
- package/neural-interface/lib/teams/claims.js +315 -0
- package/neural-interface/lib/teams/git.js +293 -0
- package/neural-interface/lib/teams/index.js +122 -0
- package/neural-interface/lib/teams/integration.js +580 -0
- package/neural-interface/lib/teams/landing.js +184 -0
- package/neural-interface/lib/teams/recovery.js +256 -0
- package/neural-interface/lib/teams/scheduler.js +1474 -0
- package/neural-interface/lib/teams/schema.js +559 -0
- package/neural-interface/lib/teams/state.js +181 -0
- package/neural-interface/lib/teams/test-runner.js +86 -0
- package/neural-interface/lib/teams/test-sandbox.js +99 -0
- package/neural-interface/lib/teams/worktrees.js +757 -0
- package/neural-interface/lib/tool-permission-choices.js +226 -0
- package/neural-interface/lib/whatsapp/cards.js +24 -10
- package/neural-interface/lib/worker-confinement.js +206 -6
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +107 -0
- package/neural-interface/public/index.html +52 -12
- package/neural-interface/public/shared/agent-runtime-options.js +3 -1
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
- package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
- package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
- package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
- package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
- package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
- package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
- package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
- package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
- package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
- package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
- package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
- package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
- package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
- package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
- package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
- package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
- package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
- package/neural-interface/public/shared/agy/agy-panel.js +142 -28
- package/neural-interface/public/shared/agy/agy-styles.js +25 -5
- package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
- package/neural-interface/public/shared/assistant/asst-control.js +3 -0
- package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
- package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
- package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
- package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
- package/neural-interface/public/shared/assistant/asst-render.js +36 -6
- package/neural-interface/public/shared/assistant/asst-route.js +78 -12
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
- package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
- package/neural-interface/public/shared/assistant/asst-state.js +66 -1
- package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
- package/neural-interface/public/shared/assistant/route-identity.js +16 -0
- package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
- package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
- package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
- package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
- package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
- package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
- package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
- package/neural-interface/public/shared/code-copy.js +120 -0
- package/neural-interface/public/shared/constants.js +7 -0
- package/neural-interface/public/shared/context-menu-model.js +1 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
- package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
- package/neural-interface/public/shared/cp/cp-styles.js +9 -0
- package/neural-interface/public/shared/dom-change-flag.js +66 -0
- package/neural-interface/public/shared/dom-morph.js +124 -0
- package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
- package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
- package/neural-interface/public/shared/html-shell.js +33 -4
- package/neural-interface/public/shared/i18n.js +14 -1
- package/neural-interface/public/shared/idle-queue.js +78 -0
- package/neural-interface/public/shared/iface-config.js +227 -0
- package/neural-interface/public/shared/lazy-module.js +108 -0
- package/neural-interface/public/shared/memory-list.js +117 -0
- package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
- package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
- package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
- package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
- package/neural-interface/public/shared/schedules-view.js +2 -2
- package/neural-interface/public/shared/session-project-items.js +11 -0
- package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
- package/neural-interface/public/shared/settings/settings-ia.js +4 -2
- package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
- package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
- package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
- package/neural-interface/public/shared/sidepanel-shown.js +73 -0
- package/neural-interface/public/shared/storage.js +6 -1
- package/neural-interface/public/shared/studio-attention.js +83 -0
- package/neural-interface/public/shared/styles.css +682 -50
- package/neural-interface/public/shared/term-browser-tabs.js +34 -0
- package/neural-interface/public/shared/transcript-rows.js +334 -0
- package/neural-interface/public/shared/tray-auto-close.js +106 -0
- package/neural-interface/public/shared/ui-agents.js +97 -0
- package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
- package/neural-interface/public/shared/ui-automation-studio.js +3 -3
- package/neural-interface/public/shared/ui-claude-panel.js +162 -95
- package/neural-interface/public/shared/ui-code-copy.js +256 -0
- package/neural-interface/public/shared/ui-codex-panel.js +14 -10
- package/neural-interface/public/shared/ui-context-menu.js +1 -1
- package/neural-interface/public/shared/ui-file-explorer.js +2 -3
- package/neural-interface/public/shared/ui-games.js +1 -1
- package/neural-interface/public/shared/ui-loading.js +12 -1
- package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
- package/neural-interface/public/shared/ui-menubar.js +23 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +1 -1
- package/neural-interface/public/shared/ui-navbar.js +15 -9
- package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
- package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
- package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
- package/neural-interface/public/shared/ui-sessions.js +3 -3
- package/neural-interface/public/shared/ui-settings-entry.js +55 -0
- package/neural-interface/public/shared/ui-settings.js +355 -400
- package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
- package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
- package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
- package/neural-interface/public/shared/ui-styleguide.js +10 -2
- package/neural-interface/public/shared/ui-sync.js +5 -0
- package/neural-interface/public/shared/ui-terminal.js +13 -9
- package/neural-interface/public/shared/ui-tooltip.js +28 -7
- package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
- package/neural-interface/public/shared/ui-tray-columns.js +375 -0
- package/neural-interface/public/shared/ui-whiteboard.js +51 -6
- package/neural-interface/public/shared/ui-worker-end.js +28 -1
- package/neural-interface/public/shared/ui-workspaces.js +13 -0
- package/neural-interface/public/shared/window-keys.js +71 -0
- package/neural-interface/public/variant/2d/main.js +2 -0
- package/neural-interface/public/variant/3d/app.js +620 -0
- package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
- package/neural-interface/public/variant/3d/main.js +21 -544
- package/neural-interface/public/variant/3d/map-controls.js +4 -2
- package/neural-interface/public/vendor/fonts/fonts.css +508 -0
- package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/manifest.json +142 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
- package/neural-interface/scripts/boot-graph.mjs +270 -0
- package/neural-interface/scripts/vendor-fonts.mjs +124 -0
- package/neural-interface/server.js +1050 -140
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -1
- package/skills/agent-forge/SKILL.md +182 -0
- package/skills/agent-forge/evals/evals.json +56 -0
- package/skills/agent-forge/references/definition-fields.md +61 -0
- package/skills/agent-forge/references/examples.md +105 -0
- package/skills/agent-forge/references/instructions.md +51 -0
- package/skills/agent-forge/references/review-and-export.md +84 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun — Agents: from an `agent_ref` to a run (phase P1)
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// A dispatch may name an agent: `agent_ref: "release-notes"` (also `release-notes@3`, `global:release-notes`,
|
|
6
|
+
// `project:release-notes@2`; lib/agents/schema.js parseAgentRef). This module turns that into the fields the
|
|
7
|
+
// dispatcher takes, and is the only place that decides how a definition and a dispatch combine:
|
|
8
|
+
//
|
|
9
|
+
// 1. Where the agent is looked up: the project the run is for first (a definition pinned to the run's folder or
|
|
10
|
+
// to a folder above it, the deepest one first), then the global library. Only an approved revision is used;
|
|
11
|
+
// an id nobody has is AGENT_UNKNOWN, one with nothing approved is AGENT_NOT_APPROVED.
|
|
12
|
+
// 2. Who wins: what the dispatch says itself always wins over the definition. An approved route's provider,
|
|
13
|
+
// model, effort and account stay binding (the router writes them over the spec after this module ran). The
|
|
14
|
+
// definition fills everything the dispatch left out.
|
|
15
|
+
// 3. A definition never widens what the session or the dispatch allows. What it asks for beyond that is taken
|
|
16
|
+
// down, and said: each such change is a correction on the run and in the dispatch's answer.
|
|
17
|
+
// capability `full` with browser or computer use needs the dispatch's own "user-authorized-full" tag
|
|
18
|
+
// (the dispatcher's rule); without it the agent runs as `workspace`. A ceiling the caller
|
|
19
|
+
// gives (`limits.capability`) is kept too.
|
|
20
|
+
// computer off for a session whose Computer toggle is off.
|
|
21
|
+
// MCP servers only the ones the dispatcher would deliver to that provider in that folder (asked of the
|
|
22
|
+
// dispatcher's own check, so the two can never disagree); the rest are left out.
|
|
23
|
+
// browser a dispatch that says `uses_browser: false` gets no browser groups and no MoreLogin profile
|
|
24
|
+
// from the definition.
|
|
25
|
+
// One thing is refused instead of taken down: a MoreLogin profile the owner has not allowed agents to choose.
|
|
26
|
+
// It goes through the dispatcher's own check like a dispatch's `morelogin_profile` and the run does not start
|
|
27
|
+
// (MORELOGIN_PROFILE_NOT_ALLOWED), because the alternative is the default browser, which is another identity:
|
|
28
|
+
// the dispatcher never puts a run there in place of the profile it was meant for.
|
|
29
|
+
// 4. What the run keeps: the ref, the revision number and the etag it resolved to (`agentRef`, `agentRevision`,
|
|
30
|
+
// `agentPin` on the run record), so a later edit of the agent does not change a run under way, and the
|
|
31
|
+
// definition's instructions as a delimited role block at the top of the run's context.
|
|
32
|
+
//
|
|
33
|
+
// Reads the registry (lib/agents/registry.js); writes nothing.
|
|
34
|
+
|
|
35
|
+
import { sep } from 'node:path';
|
|
36
|
+
import { isBrowserGroup } from '../../../mcp-server/dist/services/tool-catalog.js';
|
|
37
|
+
import { resolveToolList } from '../../../mcp-server/dist/services/tool-list.js';
|
|
38
|
+
import {
|
|
39
|
+
AGENT_CAPABILITIES, dispatchFields, formatAgentRef, isRunnable, normalizeAgentDefinition, parseAgentRef, resolutionOrder, sameScope,
|
|
40
|
+
validateAgentDefinition,
|
|
41
|
+
} from './schema.js';
|
|
42
|
+
|
|
43
|
+
/** The tag a dispatch carries when the user asked for a full-capability run that reads pages or drives the desktop. */
|
|
44
|
+
export const FULL_AUTHORIZED_TAG = 'user-authorized-full';
|
|
45
|
+
export const ROLE_BLOCK_OPEN = '=== AGENT ROLE';
|
|
46
|
+
export const ROLE_BLOCK_CLOSE = '=== END AGENT ROLE ===';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Where a resolved agent rides on a dispatch spec, from this module to the run record. A symbol: a request body
|
|
50
|
+
* cannot carry one, so nothing a caller sends can pass for a resolved agent.
|
|
51
|
+
*/
|
|
52
|
+
export const AGENT_PIN = Symbol('synabun.agentPin');
|
|
53
|
+
|
|
54
|
+
export class AgentResolveError extends Error {
|
|
55
|
+
/** @param {string} code @param {number} status @param {string} message @param {object} [extra] */
|
|
56
|
+
constructor(code, status, message, extra = {}) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = 'AgentResolveError';
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.status = status;
|
|
61
|
+
Object.assign(this, extra);
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
const { name: _name, ...rest } = { ...this };
|
|
65
|
+
return { ...rest, code: this.code, message: this.message };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
70
|
+
const given = (value) => value !== undefined && value !== null && !(typeof value === 'string' && value.trim() === '');
|
|
71
|
+
const firstGiven = (...values) => values.find(given);
|
|
72
|
+
const flag = (value) => (value === true || value === 'true' ? true : value === false || value === 'false' ? false : undefined);
|
|
73
|
+
const projectPathOf = (path) => (given(path) ? normalizeAgentDefinition({ scope: { kind: 'project', path: String(path) } }).scope.path : null);
|
|
74
|
+
/** Is `child` the folder `parent`, or inside it? Both normalized, compared as text. */
|
|
75
|
+
function isWithin(parent, child) {
|
|
76
|
+
if (!parent || !child) return false;
|
|
77
|
+
if (parent === child) return true;
|
|
78
|
+
return child.startsWith(parent.endsWith(sep) ? parent : `${parent}${sep}`);
|
|
79
|
+
}
|
|
80
|
+
const CAPABILITY_RANK = Object.freeze(Object.fromEntries(AGENT_CAPABILITIES.map((name, index) => [name, index])));
|
|
81
|
+
|
|
82
|
+
/** The ref a dispatch names, under either spelling. undefined when it names none. */
|
|
83
|
+
export function agentRefOf(spec) {
|
|
84
|
+
if (!isObject(spec)) return undefined;
|
|
85
|
+
const ref = firstGiven(spec.agentRef, spec.agent_ref);
|
|
86
|
+
return ref === undefined ? undefined : String(ref).trim();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The scopes a ref is looked up in for a run in `projectPath`, first match wins: every project the registry has
|
|
91
|
+
* that agent pinned to and that the run's folder is (or is inside), the deepest first, then the global library.
|
|
92
|
+
* A worker of a team runs in `<project>/.worktrees/<team>/<slice>`: the project's agents are its agents too.
|
|
93
|
+
* @param {{ id: string, scope: string|null }} parsed a parseAgentRef result
|
|
94
|
+
* @param {{ kind: string, path?: string }[]} stored the scopes that id is stored under
|
|
95
|
+
* @param {string|null} projectPath
|
|
96
|
+
*/
|
|
97
|
+
export function lookupOrder(parsed, stored, projectPath = null) {
|
|
98
|
+
if (parsed?.scope === 'global') return resolutionOrder(parsed, null);
|
|
99
|
+
const cwd = projectPathOf(projectPath);
|
|
100
|
+
const projects = (stored || [])
|
|
101
|
+
.filter((scope) => scope.kind === 'project' && cwd && isWithin(scope.path, cwd))
|
|
102
|
+
.sort((a, b) => b.path.length - a.path.length);
|
|
103
|
+
return [
|
|
104
|
+
...projects.flatMap((scope) => resolutionOrder({ ...parsed, scope: 'project' }, scope.path)),
|
|
105
|
+
...(parsed?.scope === 'project' ? [] : resolutionOrder({ ...parsed, scope: 'global' }, null)),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The approved revision a ref names.
|
|
111
|
+
* @param {string} ref
|
|
112
|
+
* @param {object} o
|
|
113
|
+
* @param {object} o.registry lib/agents/registry.js
|
|
114
|
+
* @param {string|null} [o.projectPath] the folder the run is for
|
|
115
|
+
* @returns {{ definition: object, id: string, revision: number, etag: string, scope: object, name: string, ref: string, requested: string }}
|
|
116
|
+
* `ref` is the pinned form (`global:release-notes@3`): what resolves to this same revision again.
|
|
117
|
+
* @throws {AgentResolveError} AGENT_REF_INVALID (400), AGENT_UNKNOWN (404), AGENT_NOT_APPROVED (409)
|
|
118
|
+
*/
|
|
119
|
+
export function resolveAgentRef(ref, { registry, projectPath = null } = {}) {
|
|
120
|
+
const requested = typeof ref === 'string' ? ref.trim() : '';
|
|
121
|
+
const parsed = parseAgentRef(requested);
|
|
122
|
+
if (!parsed) {
|
|
123
|
+
throw new AgentResolveError('AGENT_REF_INVALID', 400, `"${requested.slice(0, 80)}" is not an agent ref. Write an agent id from agent_catalog ("release-notes"), optionally with a revision ("release-notes@3") or a library ("global:release-notes", "project:release-notes").`, { agentRef: requested.slice(0, 200) });
|
|
124
|
+
}
|
|
125
|
+
if (!registry) throw new AgentResolveError('AGENTS_UNAVAILABLE', 503, 'Agents are not available on this server.', { agentRef: requested });
|
|
126
|
+
const stored = registry.scopesOf(parsed.id);
|
|
127
|
+
const seen = [];
|
|
128
|
+
for (const scope of lookupOrder(parsed, stored, projectPath)) {
|
|
129
|
+
if (!stored.some((other) => sameScope(other, scope))) continue;
|
|
130
|
+
const key = { id: parsed.id, scope };
|
|
131
|
+
const definition = registry.revision(key, parsed.revision ?? 'approved');
|
|
132
|
+
if (!definition || !isRunnable(definition)) {
|
|
133
|
+
let status = definition?.status || null;
|
|
134
|
+
if (!status) { try { status = parsed.revision ? 'no_such_revision' : registry.get(key).status; } catch { status = 'unreadable'; } }
|
|
135
|
+
seen.push({ scope: scope.kind, ...(scope.kind === 'project' ? { path: scope.path } : {}), status });
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
definition, id: definition.id, revision: definition.revision, etag: definition.etag, scope: definition.scope, name: definition.name,
|
|
140
|
+
ref: formatAgentRef({ id: definition.id, revision: definition.revision, scope: definition.scope }), requested,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (!seen.length) {
|
|
144
|
+
const where = parsed.scope === 'global' ? 'the global library' : parsed.scope === 'project' ? 'this project' : 'this project or the global library';
|
|
145
|
+
throw new AgentResolveError('AGENT_UNKNOWN', 404, `There is no agent "${parsed.id}" in ${where}. agent_catalog lists the agents that can run (agents).`, { agentRef: requested, agentId: parsed.id });
|
|
146
|
+
}
|
|
147
|
+
const what = parsed.revision ? `Revision ${parsed.revision} of agent "${parsed.id}" is not approved` : `Agent "${parsed.id}" has no approved revision`;
|
|
148
|
+
throw new AgentResolveError('AGENT_NOT_APPROVED', 409, `${what} (${seen.map((row) => `${row.scope}: ${String(row.status).replace(/_/g, ' ')}`).join('; ')}). Only a revision the owner approved runs: ask the owner to review it in Agents, or dispatch without agent_ref.`, { agentRef: requested, agentId: parsed.id, found: seen });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── the role block ───────────────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A definition's instructions as the block a worker reads: delimited, named, and placed first in the run's
|
|
155
|
+
* context. The task, the user's brief and SynaBun's own rules for the run stay above it.
|
|
156
|
+
*/
|
|
157
|
+
export function agentRoleBlock(definition, { ref = null } = {}) {
|
|
158
|
+
const def = normalizeAgentDefinition(definition);
|
|
159
|
+
// A line of the instructions that looks like one of the block's own fences is not one.
|
|
160
|
+
const body = def.instructions.split('\n').map((line) => (/^\s*===\s*(?:END\s+)?AGENT ROLE/i.test(line) ? line.replace(/===/g, '= = =') : line)).join('\n');
|
|
161
|
+
const lines = [
|
|
162
|
+
`${ROLE_BLOCK_OPEN}: ${def.name || def.id} (agent ${ref || def.id}, revision ${def.revision}) ===`,
|
|
163
|
+
`You run as the SynaBun agent "${def.name || def.id}". What follows says who that agent is and how it works; do the TASK as that agent. The TASK, the user's brief and SynaBun's rules for this run come first where they differ.`,
|
|
164
|
+
];
|
|
165
|
+
if (def.description) lines.push(`What this agent is for: ${def.description}`);
|
|
166
|
+
lines.push('', body || '(This agent has no instructions of its own.)');
|
|
167
|
+
const extras = [];
|
|
168
|
+
if (def.skills.length) extras.push(`Skills this agent works with, when they fit the task: ${def.skills.join(', ')}.`);
|
|
169
|
+
if (def.memoryCategory) extras.push(`Memory: file what this agent learns under the category "${def.memoryCategory}", unless the task names another.`);
|
|
170
|
+
if (extras.length) lines.push('', ...extras);
|
|
171
|
+
lines.push(ROLE_BLOCK_CLOSE);
|
|
172
|
+
return lines.join('\n');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** A context without any role block (a run that is dispatched again carries its context along). */
|
|
176
|
+
export function stripRoleBlocks(context) {
|
|
177
|
+
const text = typeof context === 'string' ? context : '';
|
|
178
|
+
if (!text.includes(ROLE_BLOCK_OPEN)) return text.trim();
|
|
179
|
+
const out = [];
|
|
180
|
+
let inside = false;
|
|
181
|
+
for (const line of text.split('\n')) {
|
|
182
|
+
if (!inside && line.startsWith(ROLE_BLOCK_OPEN)) { inside = true; continue; }
|
|
183
|
+
if (inside) { if (line.trim() === ROLE_BLOCK_CLOSE) inside = false; continue; }
|
|
184
|
+
out.push(line);
|
|
185
|
+
}
|
|
186
|
+
return out.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The run's context with the role block first. */
|
|
190
|
+
export function withRoleBlock(context, block) {
|
|
191
|
+
const rest = stripRoleBlocks(context);
|
|
192
|
+
return rest ? `${block}\n\n${rest}` : block;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── a definition over a dispatch ─────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
const correction = (field, from, to, reason, text) => ({ field, from, to, reason, text });
|
|
198
|
+
|
|
199
|
+
/** The SynaBun groups a tool list names that drive the browser (`all` names every one). */
|
|
200
|
+
function browserGroupsOf(tools) {
|
|
201
|
+
const groups = (Array.isArray(tools) ? tools : []).filter((item) => typeof item === 'string' && !item.startsWith('mcp:'));
|
|
202
|
+
const read = resolveToolList(groups, { source: 'runtime' });
|
|
203
|
+
return read.ok ? read.groups.filter(isBrowserGroup) : [];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The MCP servers of a list the dispatcher would deliver, asked of its own check (`resolveExternalTools`, which
|
|
208
|
+
* refuses a list that names one it cannot deliver and says which). → { kept, dropped: [{ ref, reason }] }.
|
|
209
|
+
* Without a check, a caller's own list (`allowed`: names, or `*`) decides; with neither, nothing is known and the
|
|
210
|
+
* list is left as it is: the dispatcher still checks it when it builds the run.
|
|
211
|
+
*/
|
|
212
|
+
function deliverableServers(refs, { resolveExternalTools = null, spec = {}, allowed = null } = {}) {
|
|
213
|
+
let kept = [...refs];
|
|
214
|
+
const dropped = [];
|
|
215
|
+
if (Array.isArray(allowed) || allowed === '*') {
|
|
216
|
+
const names = allowed === '*' ? null : new Set(allowed.map(String));
|
|
217
|
+
for (const ref of [...kept]) {
|
|
218
|
+
if (ref === 'mcp:*' ? allowed !== '*' && !names.has('*') : names && !names.has(ref.slice(4))) {
|
|
219
|
+
kept = kept.filter((item) => item !== ref);
|
|
220
|
+
dropped.push({ ref, reason: 'not_allowed' });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (typeof resolveExternalTools === 'function') {
|
|
225
|
+
for (let round = 0; round < 3 && kept.length; round += 1) {
|
|
226
|
+
try { resolveExternalTools(spec, kept); break; } catch (error) {
|
|
227
|
+
const problems = Array.isArray(error?.problems) ? error.problems.filter((problem) => typeof problem?.item === 'string' && kept.includes(problem.item)) : [];
|
|
228
|
+
// A check that fails without naming an item (a provider whose MCP settings cannot be read) proves nothing
|
|
229
|
+
// about any of them: none is taken.
|
|
230
|
+
const bad = problems.length ? problems : kept.map((item) => ({ item, reason: error?.code === 'MCP_DISCOVERY_FAILED' ? 'unverified' : (error?.code ? String(error.code).toLowerCase() : 'unverified') }));
|
|
231
|
+
for (const problem of bad) dropped.push({ ref: problem.item, reason: String(problem.reason || 'unavailable') });
|
|
232
|
+
kept = kept.filter((item) => !bad.some((problem) => problem.item === item));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { kept, dropped };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* A dispatch spec with a definition applied: what the spec says wins, the definition fills the rest, and nothing
|
|
241
|
+
* the definition asks for goes past what the session and the dispatch allow.
|
|
242
|
+
*
|
|
243
|
+
* @param {object} rawSpec the dispatch as the dispatcher received it (its own spelling: provider, model, effort,
|
|
244
|
+
* accountId, tools, capability, permissionPolicy, usesBrowser, usesComputer, moreloginProfile, tags, cwd, context)
|
|
245
|
+
* @param {object} definition an AgentDefinition
|
|
246
|
+
* @param {object} [ctx]
|
|
247
|
+
* @param {string|null} [ctx.assistantSessionId]
|
|
248
|
+
* @param {{ sessionAllows?(id): boolean }|null} [ctx.desktop] computer use (lib/desktop/service.js)
|
|
249
|
+
* @param {Function|null} [ctx.resolveExternalTools] the dispatcher's own MCP server check
|
|
250
|
+
* @param {{ capability?: string, usesComputer?: boolean, mcpServers?: string[]|'*', moreloginProfiles?: string[]|((name: string) => boolean) }} [ctx.limits]
|
|
251
|
+
* ceilings the caller sets on top (a server that wires none leaves the dispatcher's own checks to decide)
|
|
252
|
+
* @param {string} [ctx.ref] the pinned ref, for the role block
|
|
253
|
+
* @returns {{ spec: object, corrections: object[], filled: string[] }} `spec` is a copy; `filled` names the fields
|
|
254
|
+
* the definition supplied
|
|
255
|
+
*/
|
|
256
|
+
export function applyAgent(rawSpec = {}, definition, ctx = {}) {
|
|
257
|
+
const def = normalizeAgentDefinition(definition);
|
|
258
|
+
const fields = dispatchFields(def);
|
|
259
|
+
const limits = isObject(ctx.limits) ? ctx.limits : {};
|
|
260
|
+
const spec = { ...rawSpec };
|
|
261
|
+
delete spec.agentRef;
|
|
262
|
+
delete spec.agent_ref;
|
|
263
|
+
const corrections = [];
|
|
264
|
+
const filled = [];
|
|
265
|
+
const fill = (key, value) => { spec[key] = value; filled.push(key); };
|
|
266
|
+
const tags = Array.isArray(rawSpec.tags) ? rawSpec.tags.map((tag) => String(tag).trim()) : [];
|
|
267
|
+
const name = def.name || def.id;
|
|
268
|
+
|
|
269
|
+
// ── what it runs on ──
|
|
270
|
+
const provider = given(rawSpec.provider) ? String(rawSpec.provider).trim().toLowerCase() : fields.provider;
|
|
271
|
+
if (!given(rawSpec.provider)) fill('provider', provider);
|
|
272
|
+
const sameProvider = provider === fields.provider;
|
|
273
|
+
if (sameProvider) {
|
|
274
|
+
// "auto" is the dispatch saying it has no preference (the dispatcher reads it as no model): the agent's applies.
|
|
275
|
+
const modelSaid = given(rawSpec.model) && String(rawSpec.model).trim().toLowerCase() !== 'auto';
|
|
276
|
+
if (!modelSaid && fields.model) fill('model', fields.model);
|
|
277
|
+
if (!given(rawSpec.effort) && fields.effort) fill('effort', fields.effort);
|
|
278
|
+
if (!given(firstGiven(rawSpec.accountId, rawSpec.codexAccountId, rawSpec.claudeAccountId)) && fields.accountId) fill('accountId', fields.accountId);
|
|
279
|
+
} else if (fields.model || fields.effort || fields.accountId) {
|
|
280
|
+
corrections.push(correction('provider', fields.provider, provider, 'explicit_provider', `agent ${name}: the dispatch runs on ${provider}, not the agent's ${fields.provider}, so the agent's model, effort and account were not applied`));
|
|
281
|
+
}
|
|
282
|
+
if (!given(rawSpec.permissionPolicy)) fill('permissionPolicy', fields.permissionPolicy);
|
|
283
|
+
|
|
284
|
+
// ── browser: the dispatch's own word first ──
|
|
285
|
+
const browserSaid = flag(rawSpec.usesBrowser);
|
|
286
|
+
if (browserSaid === undefined && fields.usesBrowser) fill('usesBrowser', true);
|
|
287
|
+
|
|
288
|
+
// ── tools and MCP servers ──
|
|
289
|
+
if (!Array.isArray(rawSpec.tools) && Array.isArray(fields.tools)) {
|
|
290
|
+
let tools = [...fields.tools];
|
|
291
|
+
if (browserSaid === false) {
|
|
292
|
+
const browser = browserGroupsOf(tools);
|
|
293
|
+
if (browser.length) {
|
|
294
|
+
const read = resolveToolList(tools.filter((item) => !item.startsWith('mcp:')), { source: 'runtime' });
|
|
295
|
+
const groups = (read.ok ? read.groups : tools.filter((item) => !item.startsWith('mcp:'))).filter((id) => !browser.includes(id));
|
|
296
|
+
corrections.push(correction('tools', browser, [], 'browser_off', `agent ${name}: the dispatch says uses_browser false, so the agent's browser groups (${browser.join(', ')}) were left out`));
|
|
297
|
+
tools = [...groups, ...tools.filter((item) => item.startsWith('mcp:'))];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
fill('tools', tools);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ── MoreLogin profile ──
|
|
304
|
+
const profileSaid = firstGiven(rawSpec.moreloginProfile, rawSpec.morelogin_profile, rawSpec.moreloginEnvId, rawSpec.morelogin_env_id);
|
|
305
|
+
if (!given(profileSaid) && fields.moreloginProfile) {
|
|
306
|
+
const allowed = limits.moreloginProfiles;
|
|
307
|
+
const refused = typeof allowed === 'function' ? allowed(fields.moreloginProfile) !== true : Array.isArray(allowed) ? !allowed.map(String).includes(fields.moreloginProfile) : false;
|
|
308
|
+
if (browserSaid === false) {
|
|
309
|
+
corrections.push(correction('moreloginProfile', fields.moreloginProfile, null, 'browser_off', `agent ${name}: the dispatch says uses_browser false, so the agent's MoreLogin profile "${fields.moreloginProfile}" was not used`));
|
|
310
|
+
} else if (refused) {
|
|
311
|
+
corrections.push(correction('moreloginProfile', fields.moreloginProfile, null, 'profile_not_allowed', `agent ${name}: MoreLogin profile "${fields.moreloginProfile}" is not one this session may use and was left out`));
|
|
312
|
+
} else fill('moreloginProfile', fields.moreloginProfile);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ── computer use ──
|
|
316
|
+
const computerSaid = flag(rawSpec.usesComputer);
|
|
317
|
+
if (computerSaid === undefined && fields.usesComputer) {
|
|
318
|
+
let allowed = limits.usesComputer !== false;
|
|
319
|
+
let reason = 'computer_not_allowed';
|
|
320
|
+
if (allowed && ctx.assistantSessionId && typeof ctx.desktop?.sessionAllows === 'function') {
|
|
321
|
+
try { allowed = ctx.desktop.sessionAllows(String(ctx.assistantSessionId)) !== false; } catch { allowed = false; }
|
|
322
|
+
reason = 'computer_session_off';
|
|
323
|
+
}
|
|
324
|
+
if (allowed) fill('usesComputer', true);
|
|
325
|
+
else corrections.push(correction('usesComputer', true, false, reason, `agent ${name}: computer use is ${reason === 'computer_session_off' ? 'switched off for this assistant session' : 'not allowed for this run'}, so the agent runs without it (the user turns the Computer toggle on)`));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ── capability: the definition's is a request, the session's and the dispatch's ceiling stands ──
|
|
329
|
+
if (!given(rawSpec.capability)) {
|
|
330
|
+
let capability = fields.capability;
|
|
331
|
+
const ceiling = given(limits.capability) && CAPABILITY_RANK[limits.capability] !== undefined ? limits.capability : null;
|
|
332
|
+
if (ceiling && CAPABILITY_RANK[capability] > CAPABILITY_RANK[ceiling]) {
|
|
333
|
+
corrections.push(correction('capability', capability, ceiling, 'capability_ceiling', `agent ${name}: capability "${capability}" is more than this session allows; it runs as "${ceiling}"`));
|
|
334
|
+
capability = ceiling;
|
|
335
|
+
}
|
|
336
|
+
const reads = flag(spec.usesBrowser) === true || browserGroupsOf(spec.tools).length > 0;
|
|
337
|
+
const drives = flag(spec.usesComputer) === true;
|
|
338
|
+
if (capability === 'full' && (reads || drives) && !tags.includes(FULL_AUTHORIZED_TAG)) {
|
|
339
|
+
corrections.push(correction('capability', 'full', 'workspace', 'full_not_authorized', `agent ${name}: capability "full" with ${drives ? 'computer' : 'browser'} use needs the dispatch's own "${FULL_AUTHORIZED_TAG}" tag (an explicit request of the user); it runs as "workspace"`));
|
|
340
|
+
capability = 'workspace';
|
|
341
|
+
}
|
|
342
|
+
fill('capability', capability);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ── MCP servers: last, so the dispatcher's own check reads the run as it will be ──
|
|
346
|
+
if (filled.includes('tools')) {
|
|
347
|
+
const refs = spec.tools.filter((item) => item.startsWith('mcp:'));
|
|
348
|
+
if (refs.length) {
|
|
349
|
+
const { kept, dropped } = deliverableServers(refs, { resolveExternalTools: ctx.resolveExternalTools, spec: { ...spec, provider }, allowed: limits.mcpServers ?? null });
|
|
350
|
+
if (dropped.length) {
|
|
351
|
+
spec.tools = [...spec.tools.filter((item) => !item.startsWith('mcp:')), ...kept];
|
|
352
|
+
corrections.push(correction('mcpServers', refs.map((ref) => ref.slice(4)), kept.map((ref) => ref.slice(4)), 'mcp_not_available', `agent ${name}: MCP server${dropped.length === 1 ? '' : 's'} ${dropped.map((row) => `${row.ref.slice(4)} (${row.reason.replace(/[-_]/g, ' ')})`).join(', ')} ${dropped.length === 1 ? 'is' : 'are'} not available to this run and ${dropped.length === 1 ? 'was' : 'were'} left out`));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ── the role block ──
|
|
358
|
+
spec.context = withRoleBlock(rawSpec.context, agentRoleBlock(def, { ref: ctx.ref || null }));
|
|
359
|
+
return { spec, corrections, filled };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ── the run record ───────────────────────────────────────────────────────────
|
|
363
|
+
|
|
364
|
+
/** The pin a prepared spec carries, or null. */
|
|
365
|
+
export function agentPinOf(input) {
|
|
366
|
+
const pin = isObject(input) ? input[AGENT_PIN] : null;
|
|
367
|
+
return isObject(pin) ? pin : null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Write a resolved agent onto a run record as it is created: `agentRef` (the pinned ref), `agentRevision`, and
|
|
372
|
+
* `agentPin` ({ id, revision, etag, scope, name, requested, corrections }), plus a note per correction. Does
|
|
373
|
+
* nothing for a dispatch without an agent.
|
|
374
|
+
*/
|
|
375
|
+
export function stampAgentRun(entry, input) {
|
|
376
|
+
const pin = agentPinOf(input);
|
|
377
|
+
if (!pin || !isObject(entry)) return entry;
|
|
378
|
+
entry.agentRef = pin.ref;
|
|
379
|
+
entry.agentRevision = pin.revision;
|
|
380
|
+
entry.agentPin = {
|
|
381
|
+
id: pin.id, revision: pin.revision, etag: pin.etag, scope: pin.scope, name: pin.name, requested: pin.requested,
|
|
382
|
+
...(pin.status && pin.status !== 'approved' ? { status: pin.status, test: true } : {}),
|
|
383
|
+
corrections: pin.corrections || [],
|
|
384
|
+
};
|
|
385
|
+
if (!Array.isArray(entry.notes)) entry.notes = [];
|
|
386
|
+
entry.notes.push(`runs as agent "${pin.name}" (${pin.ref}${pin.status && pin.status !== 'approved' ? `, ${pin.status}: a test run` : ''})`);
|
|
387
|
+
for (const item of pin.corrections || []) if (item?.text && !entry.notes.includes(item.text)) entry.notes.push(item.text);
|
|
388
|
+
return entry;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** The corrections of a prepared spec, for the dispatch's answer. */
|
|
392
|
+
export function agentCorrections(input) {
|
|
393
|
+
return agentPinOf(input)?.corrections || [];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** A run that is dispatched again as another run (an escalation, a retry) keeps the agent it ran as. */
|
|
397
|
+
export function carryAgentRun(parent, child) {
|
|
398
|
+
if (!isObject(parent) || !isObject(child) || !parent.agentRef || child.agentRef) return child;
|
|
399
|
+
child.agentRef = parent.agentRef;
|
|
400
|
+
child.agentRevision = parent.agentRevision ?? null;
|
|
401
|
+
if (isObject(parent.agentPin)) child.agentPin = { ...parent.agentPin };
|
|
402
|
+
return child;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ── the resolver ─────────────────────────────────────────────────────────────
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @param {object} o
|
|
409
|
+
* @param {object} o.registry lib/agents/registry.js
|
|
410
|
+
* @param {(ctx: object) => object|null} [o.limits] ceilings for a run on top of the dispatcher's own checks
|
|
411
|
+
* ({ capability, usesComputer, mcpServers, moreloginProfiles }), asked per dispatch
|
|
412
|
+
*/
|
|
413
|
+
export function createAgentResolver({ registry, limits = null } = {}) {
|
|
414
|
+
if (!registry) throw new Error('createAgentResolver needs { registry }');
|
|
415
|
+
|
|
416
|
+
const resolve = (ref, { projectPath = null } = {}) => resolveAgentRef(ref, { registry, projectPath });
|
|
417
|
+
|
|
418
|
+
/** A definition applied to a spec, with its pin on the result. */
|
|
419
|
+
function prepare(rawSpec, resolved, ctx = {}) {
|
|
420
|
+
let extra = null;
|
|
421
|
+
try { extra = typeof limits === 'function' ? limits({ ...ctx, rawSpec, definition: resolved.definition }) : limits; } catch { extra = null; }
|
|
422
|
+
const applied = applyAgent(rawSpec, resolved.definition, { ...ctx, ref: resolved.ref, limits: { ...(isObject(extra) ? extra : {}), ...(isObject(ctx.limits) ? ctx.limits : {}) } });
|
|
423
|
+
applied.spec[AGENT_PIN] = {
|
|
424
|
+
id: resolved.id, revision: resolved.revision, etag: resolved.etag, scope: resolved.scope, name: resolved.name || resolved.id,
|
|
425
|
+
ref: resolved.ref, requested: resolved.requested || resolved.ref, status: resolved.definition.status,
|
|
426
|
+
corrections: applied.corrections, filled: applied.filled,
|
|
427
|
+
};
|
|
428
|
+
return applied.spec;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The dispatcher's intake: a spec that names an agent comes back with the agent applied; one that names none
|
|
433
|
+
* comes back as it is.
|
|
434
|
+
* @param {object} rawSpec
|
|
435
|
+
* @param {{ assistantSessionId?: string|null, origin?: string, desktop?: object|null, resolveExternalTools?: Function|null }} [ctx]
|
|
436
|
+
*/
|
|
437
|
+
function intake(rawSpec = {}, ctx = {}) {
|
|
438
|
+
const ref = agentRefOf(rawSpec);
|
|
439
|
+
if (ref === undefined) return rawSpec;
|
|
440
|
+
const resolved = resolve(ref, { projectPath: firstGiven(rawSpec.cwd, rawSpec.project) ?? null });
|
|
441
|
+
return prepare(rawSpec, resolved, ctx);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* A spec for a run of one stored revision, approved or not: the owner's test run of a draft
|
|
446
|
+
* (lib/agents-studio-api.js). Never reached from a dispatch's `agent_ref`.
|
|
447
|
+
*/
|
|
448
|
+
function prepareRevision(rawSpec, definition, ctx = {}) {
|
|
449
|
+
const def = normalizeAgentDefinition(definition);
|
|
450
|
+
const checked = validateAgentDefinition(def);
|
|
451
|
+
if (!checked.ok) throw new AgentResolveError('AGENT_NOT_VALID', 400, 'The definition has errors; fix them before running it.', { errors: checked.errors });
|
|
452
|
+
return prepare(rawSpec, {
|
|
453
|
+
definition: def, id: def.id, revision: def.revision, etag: def.etag, scope: def.scope, name: def.name,
|
|
454
|
+
ref: formatAgentRef({ id: def.id, revision: def.revision, scope: def.scope }), requested: ctx.requested || null,
|
|
455
|
+
}, ctx);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* agent_route: a proposal that names an agent gets the provider, model, effort and account the agent runs on,
|
|
460
|
+
* where the proposal leaves them out. A proposal with an agent is a dispatch: an agent is a worker.
|
|
461
|
+
* @param {object} body the agent_route request
|
|
462
|
+
* @returns {object} the body, with such proposals filled (the same object when none names an agent)
|
|
463
|
+
*/
|
|
464
|
+
function expandProposals(body = {}) {
|
|
465
|
+
if (!isObject(body) || !Array.isArray(body.proposals) || !body.proposals.some((proposal) => agentRefOf(proposal) !== undefined)) return body;
|
|
466
|
+
const projectPath = firstGiven(body.cwd, body.project) ?? null;
|
|
467
|
+
const proposals = body.proposals.map((proposal) => {
|
|
468
|
+
const ref = agentRefOf(proposal);
|
|
469
|
+
if (ref === undefined) return proposal;
|
|
470
|
+
const resolved = resolve(ref, { projectPath });
|
|
471
|
+
const fields = dispatchFields(resolved.definition);
|
|
472
|
+
const provider = given(proposal.provider) ? proposal.provider : fields.provider;
|
|
473
|
+
const same = provider === fields.provider;
|
|
474
|
+
const account = firstGiven(proposal.account_id, proposal.accountId);
|
|
475
|
+
return {
|
|
476
|
+
...proposal, kind: 'dispatch', provider,
|
|
477
|
+
...(same && !given(proposal.model) && fields.model ? { model: fields.model } : {}),
|
|
478
|
+
...(same && !given(proposal.effort) && fields.effort ? { effort: fields.effort } : {}),
|
|
479
|
+
...(same && !given(account) && fields.accountId ? { account_id: fields.accountId } : {}),
|
|
480
|
+
...(given(proposal.reason) ? {} : { reason: `agent ${resolved.name || resolved.id}` }),
|
|
481
|
+
agent_ref: resolved.ref,
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
return { ...body, proposals };
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* The agents that can run, as agent_catalog lists them. With `projectPath`: what a run in that folder would
|
|
489
|
+
* get for each id (the project's own agent in place of the global one of the same id).
|
|
490
|
+
*/
|
|
491
|
+
function runnable({ projectPath = null } = {}) {
|
|
492
|
+
const rows = [];
|
|
493
|
+
const taken = new Set();
|
|
494
|
+
const approved = registry.list({ status: 'approved' }).filter((agent) => agent.approvedRevision);
|
|
495
|
+
const cwd = projectPathOf(projectPath);
|
|
496
|
+
const ordered = cwd
|
|
497
|
+
? [...approved.filter((agent) => agent.scope.kind === 'project' && isWithin(agent.scope.path, cwd)).sort((a, b) => b.scope.path.length - a.scope.path.length), ...approved.filter((agent) => agent.scope.kind === 'global')]
|
|
498
|
+
: approved;
|
|
499
|
+
for (const agent of ordered) {
|
|
500
|
+
if (cwd) { if (taken.has(agent.id)) continue; taken.add(agent.id); }
|
|
501
|
+
rows.push({
|
|
502
|
+
ref: formatAgentRef({ id: agent.id, scope: agent.scope }), id: agent.id, name: agent.name, description: agent.description,
|
|
503
|
+
provider: agent.provider, model: agent.model, effort: agent.effort, taskClasses: agent.taskClasses,
|
|
504
|
+
scope: agent.scope.kind, ...(agent.scope.kind === 'project' ? { projectPath: agent.scope.path } : {}),
|
|
505
|
+
revision: agent.approvedRevision, capability: agent.capability, usesBrowser: agent.usesBrowser, usesComputer: agent.usesComputer,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
return rows;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return { registry, resolve, prepare, prepareRevision, intake, expandProposals, runnable };
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// ── one resolver for the process ─────────────────────────────────────────────
|
|
515
|
+
// The dispatcher and the Assistant's API take the resolver as a dependency; where none is handed to them they ask
|
|
516
|
+
// here (server.js sets it once, in its Agents block). A test passes its own and never sets this one.
|
|
517
|
+
|
|
518
|
+
let current = null;
|
|
519
|
+
/** Make `resolver` the one the dispatcher and the Assistant's API use (null: none). */
|
|
520
|
+
export function setAgentResolver(resolver) { current = resolver || null; return current; }
|
|
521
|
+
export function getAgentResolver() { return current; }
|
|
522
|
+
|
|
523
|
+
const resolverOf = (agents) => { try { return (typeof agents === 'function' ? agents() : agents) || null; } catch { return null; } };
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* The dispatcher's one call: `rawSpec` with the agent it names applied, or `rawSpec` itself when it names none.
|
|
527
|
+
* A spec that names an agent on a server with no resolver is refused, never started as a plain worker.
|
|
528
|
+
* @param {object|(() => object)|null} agents a resolver (createAgentResolver), or what returns one
|
|
529
|
+
*/
|
|
530
|
+
export function agentIntake(agents, rawSpec = {}, ctx = {}) {
|
|
531
|
+
const ref = agentRefOf(rawSpec);
|
|
532
|
+
if (ref === undefined) return rawSpec;
|
|
533
|
+
const resolver = resolverOf(agents);
|
|
534
|
+
if (!resolver) throw new AgentResolveError('AGENTS_UNAVAILABLE', 503, 'This dispatch names an agent, and agents are not available on this server. Nothing was started.', { agentRef: ref.slice(0, 200) });
|
|
535
|
+
return resolver.intake(rawSpec, ctx);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** agent_route's proposals with their agents filled in; the body itself when there is nothing to fill. */
|
|
539
|
+
export function expandAgentProposals(agents, body = {}) {
|
|
540
|
+
if (!isObject(body) || !Array.isArray(body.proposals) || !body.proposals.some((proposal) => agentRefOf(proposal) !== undefined)) return body;
|
|
541
|
+
const resolver = resolverOf(agents);
|
|
542
|
+
if (!resolver) throw new AgentResolveError('AGENTS_UNAVAILABLE', 503, 'A proposal names an agent, and agents are not available on this server.');
|
|
543
|
+
return resolver.expandProposals(body);
|
|
544
|
+
}
|