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.
- package/CHANGELOG.md +41 -0
- package/README.md +1 -1
- package/browser-extension/content.js +189 -0
- package/browser-extension/engine.js +508 -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 +250 -0
- package/browser-extension/popup-view.js +151 -0
- package/browser-extension/popup.css +166 -0
- package/browser-extension/popup.html +108 -0
- package/browser-extension/popup.js +359 -0
- package/browser-extension/protocol.js +232 -0
- package/browser-extension/service-worker.js +275 -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/lib/data-home-files.js +45 -0
- package/lib/data-home-migration.js +34 -58
- 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 +95 -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 +92 -9
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +163 -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 +191 -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 +177 -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 +1119 -47
- package/neural-interface/i18n/pt-BR.json +1119 -47
- package/neural-interface/lib/account-usage.js +1 -1
- package/neural-interface/lib/agents/builtins.json +207 -0
- 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 +885 -0
- package/neural-interface/lib/agents/resolve.js +603 -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-brains/opencode.js +60 -11
- 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 +351 -121
- 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 +432 -47
- 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 +449 -94
- 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/backup-service.js +64 -105
- 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 +264 -0
- package/neural-interface/lib/browser-extension-bridge.js +441 -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 +26 -7
- package/neural-interface/lib/opencode-build-preflight.js +28 -8
- 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 +73 -29
- 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/session-cache-builder.js +41 -3
- 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 +103 -12
- package/neural-interface/public/offline.html +4 -3
- 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/api.js +2 -1
- 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 +37 -6
- package/neural-interface/public/shared/assistant/asst-route.js +80 -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/cc-dropdown.js +21 -15
- 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 +34 -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/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- 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/start-bridge.js +2 -2
- 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 +694 -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 +83 -19
- 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 +50 -21
- 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-owner-authority.js +48 -25
- 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 +363 -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 +6 -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/sw.js +4 -3
- 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 +30 -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 +1083 -164
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -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
|
@@ -42,8 +42,10 @@ import { MAX_MEDIA_BYTES, MAX_RUN_MEDIA_BYTES, copyRunMedia, mediaType, mediaUrl
|
|
|
42
42
|
import { loadPlaybook } from './assistant-playbooks.js';
|
|
43
43
|
import { loadStyleGuideForRun } from './style-guide/store.js';
|
|
44
44
|
import { claimCheckWaived, normalizeTestDensity, testingApplies } from './assistant-test-density.js';
|
|
45
|
+
import { normalizeAgentDensity } from './agents/density.js'; // agents-p4
|
|
45
46
|
import { normalizeEffort } from './effort-levels.js';
|
|
46
47
|
import { acpCommandOf, createTurnEvidence, recordProviderEvent, evidenceSnapshot, claimEvidenceLine } from './assistant-evidence.js';
|
|
48
|
+
import { runAwaitsAnswer } from '../public/shared/sidepanel-session-status.js';
|
|
47
49
|
import { BUDGET_MAX_USD, codexUsageCostUsd, floorCents } from './assistant-budget.js';
|
|
48
50
|
import { MIN_SPEND_USD, PROVIDER_LABELS, UNPRICED_PROVIDER_REASON, isFreePrice, isUnpricedProvider } from './assistant-budget-split.js';
|
|
49
51
|
import { createBudgetPlanner } from './assistant-budget-planner.js';
|
|
@@ -52,6 +54,12 @@ import { claudeTokensCostUsd } from './assistant-pricing.js';
|
|
|
52
54
|
import { RemotePolicyError, clampDispatchSpec, getSessionPolicy, readRegisteredProjects } from './remote-policy.js';
|
|
53
55
|
import { validateWorkerReply } from './worker-question.js';
|
|
54
56
|
import { limitFromText } from '../public/shared/assistant/asst-limit.js';
|
|
57
|
+
// agents-p1: a dispatch's agent_ref (lib/agents/resolve.js).
|
|
58
|
+
import { agentCorrections, agentIntake, agentPinOf, agentRefOf, routedAgent, carryAgentRun, getAgentResolver, stampAgentRun } from './agents/resolve.js';
|
|
59
|
+
// Agents P2 (durable agent messaging): run events, typed waits, the follow-up outbox and the transcript on disk.
|
|
60
|
+
import { createCoordinationService, sharedCoordinationService } from './coordination/service.js';
|
|
61
|
+
import { createRunWaits } from './assistant-run-wait.js';
|
|
62
|
+
import { createRunTailStore, pageText } from './assistant-run-tail.js';
|
|
55
63
|
|
|
56
64
|
// Antigravity (Google's `agy`, over ACP: lib/native-loop-providers.js createAntigravityNativeLoopAdapter) is a worker
|
|
57
65
|
// provider only: never a brain, no accounts, its usage reported in tokens and never priced.
|
|
@@ -454,6 +462,10 @@ export function createAssistantDispatcher({
|
|
|
454
462
|
// Clarification (assistant-clarify.js): { forDispatch(sessionId, { briefId, independent }) }.
|
|
455
463
|
// A brain's dispatch waits while its questions are open and carries the user's brief.
|
|
456
464
|
clarifier = null,
|
|
465
|
+
// agents-p1: the agent resolver (lib/agents/resolve.js createAgentResolver, or what returns one). A dispatch's
|
|
466
|
+
// agent_ref is resolved through it at intake. Default: the one server.js set for the process (none: such a
|
|
467
|
+
// dispatch is refused, AGENTS_UNAVAILABLE; a dispatch without agent_ref never asks).
|
|
468
|
+
agents = getAgentResolver,
|
|
457
469
|
// Live limit overrides (assistant-config.json `limits`, re-read on every check), the brain's own
|
|
458
470
|
// spend per assistant session (the runtime: its total, and by the provider it ran on) and list
|
|
459
471
|
// prices for Codex usage (assistant-budget.js createModelPricing).
|
|
@@ -480,9 +492,16 @@ export function createAssistantDispatcher({
|
|
|
480
492
|
// The session's Test density (assistant-test-density.js): (assistantSessionId) => level | null.
|
|
481
493
|
// Read when a prompt is composed; null or an unknown value is the default level.
|
|
482
494
|
testDensity = () => null,
|
|
495
|
+
// agents-p4: the session's Agent density (lib/agents/density.js): (assistantSessionId) => level | null. How many
|
|
496
|
+
// workers one task may get; the team scheduler (lib/teams/scheduler.js) asks the dispatcher for it and enforces it.
|
|
497
|
+
agentDensity = () => null,
|
|
483
498
|
// After a restart, resolves once this server answers its workers (a resumed CLI connects to SynaBun's MCP as it
|
|
484
499
|
// starts): runs are resumed only then. null: at once.
|
|
485
500
|
serverReady = null,
|
|
501
|
+
// The coordination service (lib/coordination/service.js): the durable log run events go to, the follow-up outbox
|
|
502
|
+
// and typed waits. Given none, the dispatcher takes the one server.js shares (shareCoordinationService), else it
|
|
503
|
+
// keeps its own in memory (a test: nothing survives the process).
|
|
504
|
+
coordination: givenCoordination = null,
|
|
486
505
|
} = {}) {
|
|
487
506
|
if (typeof getRuntime !== 'function') throw new Error('createAssistantDispatcher requires getRuntime()');
|
|
488
507
|
if (!dataDir) throw new Error('createAssistantDispatcher requires dataDir');
|
|
@@ -502,6 +521,11 @@ export function createAssistantDispatcher({
|
|
|
502
521
|
return limits;
|
|
503
522
|
}
|
|
504
523
|
const registryPath = resolve(dataDir, 'assistant-dispatches.json');
|
|
524
|
+
// ── Agents P2: durable messaging ───────────────────────────────────────────
|
|
525
|
+
const sharedCoordination = givenCoordination || sharedCoordinationService();
|
|
526
|
+
const coordination = sharedCoordination || createCoordinationService({ log: (tag, detail) => log(null, tag, detail) });
|
|
527
|
+
// A run's transcript tail and the whole text of its last turn, kept on disk: <dataDir>/run-tails/<runId>.*.json.
|
|
528
|
+
const tails = createRunTailStore({ dir: resolve(dataDir, 'run-tails'), log: (tag, detail) => log(null, tag, detail) });
|
|
505
529
|
// What image / video creation runs generated, and design runs' screenshots: <dataDir>/media/<runId>/<n>-<name>.
|
|
506
530
|
const mediaRoot = resolve(dataDir, 'media');
|
|
507
531
|
// A guarded worker's own scratch folder (lib/worker-confinement.js): <dataDir>/scratch/<runId>, removed when empty.
|
|
@@ -529,7 +553,43 @@ export function createAssistantDispatcher({
|
|
|
529
553
|
// Assistant listens (both filled by loadRegistry). Follow-ups sent to a run while it is away wait here for it.
|
|
530
554
|
const bootResumes = [];
|
|
531
555
|
const bootInterrupts = [];
|
|
532
|
-
|
|
556
|
+
// ── Agents P2: follow-ups wait in the coordination store's outbox ──────────
|
|
557
|
+
// Text sent to a run while it works, or while a restart has it away (suspended / resuming), used to sit in arrays
|
|
558
|
+
// in memory. Now each is a row of the outbox: it survives a restart, keeps its place, is marked sent in the step
|
|
559
|
+
// that hands it to the run's provider, and the queue refuses more than its bound.
|
|
560
|
+
/** Queue a follow-up for a run → { id, position }. Throws FOLLOW_UP_QUEUE_FULL (409) at the bound. */
|
|
561
|
+
function queueFollowUp(entry, item) {
|
|
562
|
+
try {
|
|
563
|
+
return coordination.followUps.enqueue({ runId: entry.runId, text: item.text, sessionId: entry.assistantSessionId || null, origin: item.origin, taskId: item.taskId, at: item.at });
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (error?.code === 'OUTBOX_FULL') {
|
|
566
|
+
throw new DispatchError('FOLLOW_UP_QUEUE_FULL', `Run ${entry.runId} already has ${error.queued} follow-up${error.queued === 1 ? '' : 's'} waiting (at most ${error.limit}). Wait until it took some (agent_wait), or send one message that says it all.`, { status: 409, queued: error.queued, limit: error.limit });
|
|
567
|
+
}
|
|
568
|
+
throw new DispatchError('FOLLOW_UP_NOT_QUEUED', `The follow-up for run ${entry.runId} could not be queued: ${error?.message || error}`, { status: 500 });
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
/** The run's oldest follow-up not handed to its provider yet ({ id, kind: 'follow-up', text, origin, taskId, at }), or null. */
|
|
572
|
+
function nextFollowUp(runId) {
|
|
573
|
+
try { return coordination.followUps.next(runId); } catch { return null; }
|
|
574
|
+
}
|
|
575
|
+
function followUpCount(runId) {
|
|
576
|
+
try { return coordination.followUps.count(runId); } catch { return 0; }
|
|
577
|
+
}
|
|
578
|
+
/** The run will take no more follow-ups (it ended, was stopped, did not resume): they leave the queue → the items. */
|
|
579
|
+
function cancelFollowUps(runId) {
|
|
580
|
+
try { return coordination.followUps.cancel(runId); } catch { return []; }
|
|
581
|
+
}
|
|
582
|
+
/** After a restart: follow-ups queued for runs that are gone or ended reach nobody. Their run's notes say so. */
|
|
583
|
+
function settleOrphanFollowUps() {
|
|
584
|
+
let runIds = [];
|
|
585
|
+
try { runIds = coordination.followUps.runs(); } catch { runIds = []; }
|
|
586
|
+
for (const runId of runIds) {
|
|
587
|
+
const entry = entries.get(runId);
|
|
588
|
+
if (entry && !TERMINAL_STATES.has(entry.state)) continue;
|
|
589
|
+
const dropped = cancelFollowUps(runId);
|
|
590
|
+
if (entry && dropped.length) entry.notes = [...(Array.isArray(entry.notes) ? entry.notes : []), `${dropped.length} queued follow-up${dropped.length === 1 ? '' : 's'} not delivered: the run ended first (the first: "${clip(dropped[0].text, 160)}")`];
|
|
591
|
+
}
|
|
592
|
+
}
|
|
533
593
|
const resumeInProgress = new Set(); // runIds resumeRun works on (they hold their slot; the others waiting do not)
|
|
534
594
|
// The server is going down (suspendForShutdown ran): a resume under way stops where it is, for the next start.
|
|
535
595
|
let closing = false;
|
|
@@ -562,6 +622,7 @@ export function createAssistantDispatcher({
|
|
|
562
622
|
entry.tools = []; entry.toolsRequested = [];
|
|
563
623
|
entry.toolListError = { code: error.code, message: error.message, original: row.tools ?? row.mcpProfile };
|
|
564
624
|
delete entry.mcpProfile; delete entry.rawSpec;
|
|
625
|
+
delete entry.heldAgent;
|
|
565
626
|
entry.state = 'failed'; entry.completionReason = 'tools_invalid';
|
|
566
627
|
}
|
|
567
628
|
// A failure cause being judged when the server went down is never coming.
|
|
@@ -625,7 +686,7 @@ export function createAssistantDispatcher({
|
|
|
625
686
|
const terminal = rows.filter((row) => !ACTIVE_STATES.has(row.state));
|
|
626
687
|
const retained = [...active, ...terminal.slice(0, Math.max(0, limits.retention - active.length))];
|
|
627
688
|
const retainedIds = new Set(retained.map((row) => row.runId));
|
|
628
|
-
for (const row of terminal) if (!retainedIds.has(row.runId)) { entries.delete(row.runId); live.delete(row.runId); meters.delete(row.runId); }
|
|
689
|
+
for (const row of terminal) if (!retainedIds.has(row.runId)) { entries.delete(row.runId); live.delete(row.runId); meters.delete(row.runId); tails.remove(row.runId); }
|
|
629
690
|
try { writeJsonAtomic(registryPath, retained); } catch (error) { log(null, 'assistant:registry-error', error?.message || String(error)); }
|
|
630
691
|
};
|
|
631
692
|
if (force) { if (persistTimer) { clearTimeout(persistTimer); persistTimer = null; } write(); return; }
|
|
@@ -678,7 +739,8 @@ export function createAssistantDispatcher({
|
|
|
678
739
|
const elapsedMs = startedAt ? Math.max(0, end - new Date(startedAt).getTime()) : 0;
|
|
679
740
|
// The brief goes to the worker's prompt; views name it only. The meters' state stays inside, and so does what a
|
|
680
741
|
// resume after a restart needs (resumeInfo: the CLI's pid, the turn in progress); `resumes` counts them.
|
|
681
|
-
|
|
742
|
+
// agents-p4: a team slice's brief (the TEAM block's content) goes to the worker's prompt; views carry `team` only.
|
|
743
|
+
const { heldAgent: _heldAgent, rawSpec: _rawSpec, brief: _brief, usageState: _usageState, resumeInfo: _resumeInfo, crashed: _crashed, refusedAtShutdown: _refusedAtShutdown, aliveAt: _aliveAt, teamBrief: _teamBrief, ...rest } = entry;
|
|
682
744
|
return {
|
|
683
745
|
...rest,
|
|
684
746
|
tools: toolsView({ ...entry, tools: runtimeRun?.tools ?? entry.tools }),
|
|
@@ -767,6 +829,9 @@ export function createAssistantDispatcher({
|
|
|
767
829
|
touch(entry);
|
|
768
830
|
persist({ force: TERMINAL_STATES.has(entry.state) });
|
|
769
831
|
const payload = { type: 'assistant:dispatch', reason, run: view(entry), ...extra };
|
|
832
|
+
// Agents P2: the event goes into the durable log in the step that changed the run, under an id that names it
|
|
833
|
+
// (recording it again stores nothing), before anyone is told. It never throws: the run goes on either way.
|
|
834
|
+
coordination.recordDispatch(payload);
|
|
770
835
|
if (['turn_completed', 'idle', 'failed', 'stopped', 'completed'].includes(reason)) { try { completeSkillUsage(entry); } catch {} }
|
|
771
836
|
try { broadcastSync(payload); } catch {}
|
|
772
837
|
for (const listener of listeners) { try { listener(payload); } catch {} }
|
|
@@ -827,27 +892,27 @@ export function createAssistantDispatcher({
|
|
|
827
892
|
const mark = entries.get(runId)?.delivered;
|
|
828
893
|
return mark && typeof mark === 'object' ? { ...mark } : null;
|
|
829
894
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
function satisfies(entry, until, sinceVersion) {
|
|
839
|
-
if (!entry) return true;
|
|
840
|
-
// A failed run whose cause is still being judged is not final yet: its
|
|
841
|
-
// 'failed' event (with the cause and the matching escalation) follows
|
|
842
|
-
// within the surface timeout.
|
|
843
|
-
const terminal = TERMINAL_STATES.has(entry.state) && !entry.judging;
|
|
844
|
-
if (until === 'terminal') return terminal;
|
|
845
|
-
if (until === 'event') return terminal || entry.state === 'awaiting_permission' || entry.state === 'awaiting_route' || (Number(entry.version) || 0) !== sinceVersion;
|
|
846
|
-
// 'idle' (default): the run is not busy — idle, awaiting a decision (a
|
|
847
|
-
// permission or the user's model choice), or finished.
|
|
848
|
-
return entry.state === 'idle' || entry.state === 'awaiting_permission' || entry.state === 'awaiting_route' || terminal;
|
|
895
|
+
/**
|
|
896
|
+
* Agents P2: events a brain read through agent_wait until:"event" are settled in its session's mailbox by their
|
|
897
|
+
* ids (never a second turn for them). The log keeps them: the same cursor returns them again. → how many.
|
|
898
|
+
*/
|
|
899
|
+
function markEventsDelivered(assistantSessionId, eventIds) {
|
|
900
|
+
if (!assistantSessionId || !Array.isArray(eventIds) || !eventIds.length) return 0;
|
|
901
|
+
try { return coordination.mailbox.ack(String(assistantSessionId), eventIds).acked; } catch { return 0; }
|
|
849
902
|
}
|
|
850
903
|
|
|
904
|
+
// ── waiters (Agents P2: lib/assistant-run-wait.js) ─────────────────────────
|
|
905
|
+
// until 'idle' / 'terminal' read the runs' state; until 'event' waits on typed events of the coordination log
|
|
906
|
+
// after a cursor. A workflow's runs are looked up at every check, so one added later is waited for too.
|
|
907
|
+
const runWaits = createRunWaits({
|
|
908
|
+
entries, view, coordination, now,
|
|
909
|
+
// A failed run whose cause is still being judged is not final yet: its 'failed' event follows.
|
|
910
|
+
isTerminal: (entry) => TERMINAL_STATES.has(entry.state) && !entry.judging,
|
|
911
|
+
waitCapMs: () => limits.waitCapMs,
|
|
912
|
+
fail: (code, message, extra) => new DispatchError(code, message, extra),
|
|
913
|
+
});
|
|
914
|
+
function notifyWaiters() { runWaits.notify(); }
|
|
915
|
+
|
|
851
916
|
// ── validation ─────────────────────────────────────────────────────────────
|
|
852
917
|
function suggestModels(catalogValue, provider, model) {
|
|
853
918
|
const rows = catalogValue?.models?.[provider] || [];
|
|
@@ -857,7 +922,7 @@ export function createAssistantDispatcher({
|
|
|
857
922
|
}
|
|
858
923
|
|
|
859
924
|
/** `taskClass`: the run's class (its route's, else the spec's); image / video creation needs a model that makes the medium. */
|
|
860
|
-
function normalizeSpec(spec = {}, { catalogValue = null, taskClass = null } = {}) {
|
|
925
|
+
function normalizeSpec(spec = {}, { catalogValue = null, taskClass = null, builtin = false } = {}) {
|
|
861
926
|
const provider = String(spec.provider || '').trim().toLowerCase();
|
|
862
927
|
if (!NATIVE_PROVIDERS.has(provider)) throw new DispatchError('INVALID_PROVIDER', `provider must be one of ${[...NATIVE_PROVIDERS].join(', ')}`);
|
|
863
928
|
const task = String(spec.task || '').trim();
|
|
@@ -968,6 +1033,15 @@ export function createAssistantDispatcher({
|
|
|
968
1033
|
}
|
|
969
1034
|
// Image / video creation (the router already routed it to a maker; this is the backstop).
|
|
970
1035
|
const medium = requiredOutput(taskClass);
|
|
1036
|
+
if (builtin && taskClass === 'computer') {
|
|
1037
|
+
if (!usesComputer) throw new DispatchError('COMPUTER_UNAVAILABLE', 'The bundled desktop operator needs a desktop grant.', { status: 409 });
|
|
1038
|
+
if (designFit(catalogValue, { kind: 'dispatch', provider, model }) !== 'ok') {
|
|
1039
|
+
throw new DispatchError('COMPUTER_NEEDS_VISION', 'The desktop operator needs an available model confirmed to see images.', { status: 409 });
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (builtin && medium && !catalogValue) {
|
|
1043
|
+
throw new DispatchError('MODEL_CANNOT_GENERATE', `The model catalog is unavailable to confirm ${medium} generation.`, { status: 409 });
|
|
1044
|
+
}
|
|
971
1045
|
if (medium && catalogValue) {
|
|
972
1046
|
const row = model ? findModel(catalogValue, provider, model)?.row || null : defaultModelRow(catalogValue, provider);
|
|
973
1047
|
if (!rowMakes(row, medium)) {
|
|
@@ -1440,7 +1514,38 @@ export function createAssistantDispatcher({
|
|
|
1440
1514
|
return true;
|
|
1441
1515
|
}
|
|
1442
1516
|
|
|
1443
|
-
|
|
1517
|
+
function applyRouteAgent(original, input, route, ctx, pinned = null) {
|
|
1518
|
+
// Scope follows the actual worker folder, including team worktrees. Re-read approval
|
|
1519
|
+
// at dispatch: the route may have been proposed before the project or revision was known.
|
|
1520
|
+
const selected = routedAgent(agents, route.taskClass, input.cwd || input.project || PACKAGE_ROOT, route.agentRequest, pinned);
|
|
1521
|
+
if (!selected.resolved) return { input, note: selected.note };
|
|
1522
|
+
const { provider, model, effort, accountId, codexAccountId, claudeAccountId } = input;
|
|
1523
|
+
const spec = selected.resolver.prepare({
|
|
1524
|
+
...original, provider, model, effort, accountId, codexAccountId, claudeAccountId,
|
|
1525
|
+
taskClass: route.taskClass,
|
|
1526
|
+
}, selected.resolved, { ...ctx, routed: true, classDefault: route.agentRequest ? null : route.taskClass });
|
|
1527
|
+
// An explicit profile was already resolved before routing. A profile inherited from
|
|
1528
|
+
// the role still needs the dispatcher's normal identity check.
|
|
1529
|
+
if (input.moreloginEnvId) {
|
|
1530
|
+
delete spec.moreloginProfile;
|
|
1531
|
+
delete spec.morelogin_profile;
|
|
1532
|
+
Object.assign(spec, { moreloginEnvId: input.moreloginEnvId, moreloginEnvName: input.moreloginEnvName });
|
|
1533
|
+
}
|
|
1534
|
+
return { input: spec, resolved: selected.resolved };
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
function appliedRoute(route, input, note) {
|
|
1538
|
+
const pin = agentPinOf(input);
|
|
1539
|
+
const { agentRef, agentRevision, agentRequest, agentCorrection, ...rest } = route;
|
|
1540
|
+
const requested = agentRefOf(input) || (pin && !pin.classDefault ? pin.requested : agentRequest);
|
|
1541
|
+
return { ...rest, ...(requested ? { agentRequest: requested } : {}),
|
|
1542
|
+
...(pin ? { agentRef: pin.ref, agentRevision: pin.revision } : {}),
|
|
1543
|
+
corrections: [...(route.corrections || []).filter(c => c.reason !== 'class_agent_unavailable'), ...(note ? [note] : [])] };
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// agents-p4: `team` (lib/teams/brief.js teamBrief) and `runId` are the team scheduler's own (lib/teams/scheduler.js):
|
|
1547
|
+
// the slice a run works and the id its claims were taken under. No request body reaches these options.
|
|
1548
|
+
async function dispatch(rawSpec = {}, { assistantSessionId = null, origin = 'assistant', brief: carried = null, notes: callerNotes = null, agentOf = null, team = null, runId: givenRunId = null } = {}) {
|
|
1444
1549
|
const sessionId = assistantSessionId ? String(assistantSessionId) : null;
|
|
1445
1550
|
const idempotencyKey = rawSpec.idempotencyKey || rawSpec.idempotency_key ? String(rawSpec.idempotencyKey || rawSpec.idempotency_key).slice(0, 200) : null;
|
|
1446
1551
|
if (idempotencyKey && sessionId) {
|
|
@@ -1452,6 +1557,12 @@ export function createAssistantDispatcher({
|
|
|
1452
1557
|
}
|
|
1453
1558
|
refreshLimits();
|
|
1454
1559
|
refuseSessionOver(sessionId);
|
|
1560
|
+
// agents-p1: the agent the dispatch names (agent_ref) is applied before anything else reads the spec: what the
|
|
1561
|
+
// dispatch says itself wins, the definition fills the rest and never widens it (lib/agents/resolve.js). The very
|
|
1562
|
+
// same object comes back for a dispatch that names none.
|
|
1563
|
+
const original = rawSpec;
|
|
1564
|
+
const agentContext = { assistantSessionId: sessionId, origin, desktop, resolveExternalTools };
|
|
1565
|
+
rawSpec = agentIntake(agents, rawSpec, agentContext);
|
|
1455
1566
|
// "true" (a string) is computer use too: normalizeSpec reads it so, and so must the gate.
|
|
1456
1567
|
rawSpec = { ...rawSpec, usesComputer: rawSpec.usesComputer === true || rawSpec.usesComputer === 'true' };
|
|
1457
1568
|
// The MoreLogin profile it names for the worker's browser tab, as MoreLogin lists it (refused here when it cannot
|
|
@@ -1477,15 +1588,7 @@ export function createAssistantDispatcher({
|
|
|
1477
1588
|
let routed = null;
|
|
1478
1589
|
// Skills owns the runtime selection and its provider-specific workspace. Never bind Assistant routes.
|
|
1479
1590
|
if (router && !isSkillsRun(rawSpec) && origin !== 'ui' && sessionId) {
|
|
1480
|
-
routed = await router.resolveDispatch({ sessionId, spec: rawSpec, origin });
|
|
1481
|
-
// A hold names an open card, but an answer that was already in flight (it waited on the same
|
|
1482
|
-
// catalog read) can decide that card before this continuation runs. Approved for this
|
|
1483
|
-
// session: the dispatch is resolved again with that route_id, so the run starts on it as any
|
|
1484
|
-
// dispatch with an approved route does (its validation, the remote clamps and claim, the
|
|
1485
|
-
// rails). Declined, cancelled or expired: the attachment below fails and it is refused.
|
|
1486
|
-
for (let i = 0; i < 2 && routed?.action === 'hold' && routeApprovedFor(routed.routeId, sessionId); i += 1) {
|
|
1487
|
-
routed = { ...(await router.resolveDispatch({ sessionId, spec: { ...rawSpec, routeId: routed.routeId }, origin })), approvedMeanwhile: true };
|
|
1488
|
-
}
|
|
1591
|
+
routed = await router.resolveDispatch({ sessionId, spec: rawSpec, origin, team });
|
|
1489
1592
|
}
|
|
1490
1593
|
// A remote session's approved route, claimed by resolveDispatch, is used up only by the run it
|
|
1491
1594
|
// starts: a dispatch refused before its run exists gives the route back, so retrying the route_id
|
|
@@ -1494,7 +1597,26 @@ export function createAssistantDispatcher({
|
|
|
1494
1597
|
try {
|
|
1495
1598
|
// An approved route may have moved it to another provider: clamp for that one
|
|
1496
1599
|
// (a route approved for design brings design's defaults).
|
|
1497
|
-
let input
|
|
1600
|
+
let input, agentNote, heldAgent;
|
|
1601
|
+
for (let attempt = 0; ; attempt++) {
|
|
1602
|
+
input = routed?.spec || rawSpec;
|
|
1603
|
+
const route = routed?.route;
|
|
1604
|
+
if (knownClass(route?.taskClass) && !agentPinOf(rawSpec) && !agentRefOf(original) && !agentOf) {
|
|
1605
|
+
const selected = applyRouteAgent(original, input, route, agentContext);
|
|
1606
|
+
input = selected.input.moreloginProfile ? await withBrowserProfile(selected.input) : selected.input;
|
|
1607
|
+
agentNote = selected.note;
|
|
1608
|
+
if (routed.action === 'hold') heldAgent = { input: original, resolved: selected.resolved };
|
|
1609
|
+
}
|
|
1610
|
+
// An in-flight approval may finish during routing or a role's asynchronous profile lookup.
|
|
1611
|
+
// Rebind both the model and the role on the approved route before attaching a waiting run.
|
|
1612
|
+
if (routed?.action !== 'hold' || attempt >= 2 || !routeApprovedFor(routed.routeId, sessionId)) break;
|
|
1613
|
+
routed = { ...(await router.resolveDispatch({ sessionId, spec: { ...rawSpec, routeId: routed.routeId }, origin, team })), approvedMeanwhile: true };
|
|
1614
|
+
}
|
|
1615
|
+
const dispatchRoute = routed?.route;
|
|
1616
|
+
const routeClass = knownClass(dispatchRoute?.taskClass);
|
|
1617
|
+
if (routed?.spec || dispatchRoute) input = clampRemote(withClassDefaults(input, routeClass), sessionId, remoteNotes);
|
|
1618
|
+
if (agentNote) remoteNotes.push(agentNote.text);
|
|
1619
|
+
if (dispatchRoute) routed.route = appliedRoute(dispatchRoute, input, agentNote);
|
|
1498
1620
|
// UI / callers without an Assistant session bypass the router, but may
|
|
1499
1621
|
// still ask for Auto. A routed concrete account is never picked again here.
|
|
1500
1622
|
if (!routed?.route && accountUsage && ['codex', 'claude-code'].includes(input.provider)) {
|
|
@@ -1512,21 +1634,42 @@ export function createAssistantDispatcher({
|
|
|
1512
1634
|
// A route approved for other work cannot carry image / video creation or design, nor the other way round:
|
|
1513
1635
|
// the class decides the model's capability check, the worker's media block or rules and what is collected.
|
|
1514
1636
|
const declaredClass = knownClass(rawSpec.taskClass);
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1637
|
+
const pin = agentPinOf(input) || agentOf?.agentPin;
|
|
1638
|
+
const builtin = pin?.source === 'builtin' || !!pin?.classDefault;
|
|
1639
|
+
const classMismatch = builtin && dispatchRoute
|
|
1640
|
+
? (declaredClass || knownClass(input.taskClass)) !== routeClass
|
|
1641
|
+
: declaredClass && routeClass && runContract(declaredClass) !== runContract(routeClass);
|
|
1642
|
+
if (classMismatch) {
|
|
1517
1643
|
throw new DispatchError('ROUTE_CLASS_MISMATCH', `Route ${routed.route.routeId || ''} was approved for ${routeClass} work, but this dispatch says task_class "${declaredClass}". Call agent_route with task_class "${declaredClass}" and dispatch with its route_id.`, { status: 409, routeId: routed.route.routeId || null, routeClass, taskClass: declaredClass });
|
|
1518
1644
|
}
|
|
1519
1645
|
// The route's spec (a route_id alone can make it a design dispatch, with design's defaults):
|
|
1520
1646
|
// its browser settings must agree too (the route already exists).
|
|
1521
1647
|
if (routed?.spec) refuseBrowserConflict(input);
|
|
1522
|
-
|
|
1648
|
+
// agents-p4: a team's slices start on a route that is approved already; none waits on a card of its own.
|
|
1649
|
+
if (team && routed?.action === 'hold') throw new DispatchError('TEAM_ROUTE_REQUIRED', 'A team slice starts on an approved route: route the team\'s task with agent_route first and start the team with that route_id.', { status: 409, routeId: routed.routeId || null });
|
|
1650
|
+
if (routed?.action === 'hold') {
|
|
1651
|
+
return holdForRoute(input, routed, { sessionId, origin, idempotencyKey, brief, remoteNotes, agentNote, heldAgent });
|
|
1652
|
+
}
|
|
1523
1653
|
// The run's class: its route's (the brain may omit task_class with a route_id), else the spec's.
|
|
1524
1654
|
// Its capability backstop runs in normalizeSpec on the final target, however that was chosen.
|
|
1525
1655
|
const taskClass = routeClass || knownClass(input.taskClass);
|
|
1526
|
-
const spec = normalizeSpec(input, { catalogValue, taskClass });
|
|
1656
|
+
const spec = normalizeSpec(input, { catalogValue, taskClass, builtin });
|
|
1527
1657
|
const queuedCount = [...entries.values()].filter((e) => e.state === 'queued' && e.assistantSessionId === sessionId).length;
|
|
1528
|
-
|
|
1658
|
+
if (givenRunId && entries.has(String(givenRunId))) throw new DispatchError('RUN_EXISTS', `Run ${givenRunId} exists already.`, { status: 409 }); // agents-p4
|
|
1659
|
+
runId = givenRunId ? String(givenRunId) : randomId();
|
|
1529
1660
|
const entry = { ...baseEntry(runId, sessionId, origin), ...specFields(spec), notes: [...(spec.notes || []), ...remoteNotes] };
|
|
1661
|
+
stampAgentRun(entry, input); // agents-p1: agentRef, agentRevision, agentPin (nothing for a dispatch without an agent)
|
|
1662
|
+
// agents-p4: a team slice's run names its team and slice from its first event on (the durable log files it under
|
|
1663
|
+
// the team), and keeps the slice's brief for its prompt. Its worker is confined by its worktree (worker-confinement.js).
|
|
1664
|
+
if (team && team.teamId && team.sliceId) {
|
|
1665
|
+
entry.teamId = String(team.teamId);
|
|
1666
|
+
entry.team = { teamId: String(team.teamId), sliceId: String(team.sliceId) };
|
|
1667
|
+
entry.teamBrief = team;
|
|
1668
|
+
entry.notes.push(`team ${team.teamId}, slice ${team.sliceId}: ${team.readOnly ? 'read-only worktree; cleaned when the worker ends, changes kept and reported' : 'confined to its worktree and its own files; SynaBun commits and joins its work'}`);
|
|
1669
|
+
}
|
|
1670
|
+
// A run dispatched again as another run (escalate, which names its parent in `agentOf`) is its parent's agent
|
|
1671
|
+
// from the moment its record exists: its first events in the durable log (queued, started) say so too.
|
|
1672
|
+
if (agentOf) carryAgentRun(agentOf, entry);
|
|
1530
1673
|
if (taskClass) entry.taskClass = taskClass;
|
|
1531
1674
|
if (brief) { entry.brief = brief; entry.notes.push(`carries the user's brief ${brief.briefId || ''}`.trim()); }
|
|
1532
1675
|
if (routed?.route) entry.route = routed.route;
|
|
@@ -1535,16 +1678,17 @@ export function createAssistantDispatcher({
|
|
|
1535
1678
|
if (spec.idempotencyKey && sessionId) idempotency.set(`${sessionId}:${spec.idempotencyKey}`, { runId, at: now() });
|
|
1536
1679
|
let budgetCorrections = [];
|
|
1537
1680
|
try { budgetCorrections = await fitBudget(entry, { routed: !!routed?.route }); } catch (error) { entries.delete(runId); throw error; }
|
|
1538
|
-
entry.taskId = taskAtDispatch(sessionId);
|
|
1681
|
+
entry.taskId = routed?.route?.taskId || taskAtDispatch(sessionId);
|
|
1539
1682
|
const launched = await launchOrQueue(entry, spec, { queuedCount, strict: true });
|
|
1540
|
-
const
|
|
1683
|
+
const corrections = [...budgetCorrections, ...(agentNote ? [agentNote] : []), ...agentCorrections(input)]; // agents-p1: what the agent's definition was held to
|
|
1684
|
+
const withCorrections = corrections.length ? { ...launched, corrections } : launched;
|
|
1541
1685
|
// The route's own "decided" event (it had no run attached) still tells the brain to dispatch.
|
|
1542
1686
|
return routed?.approvedMeanwhile
|
|
1543
1687
|
? { ...withCorrections, next: 'The user picked this route while the dispatch was on its way, so this run started on it. Do not dispatch it again when the route_decided event for this route arrives.' }
|
|
1544
1688
|
: withCorrections;
|
|
1545
1689
|
} catch (error) {
|
|
1546
1690
|
// A run that exists (it failed or stopped at start) used the route; a refusal before one did not.
|
|
1547
|
-
if (routed?.claimed && !(runId && entries.has(runId))) router.releaseRoute?.(routed.route?.routeId);
|
|
1691
|
+
if (routed?.claimed && !(runId && entries.has(runId))) router.releaseRoute?.(routed.route?.routeId, routed.claim);
|
|
1548
1692
|
throw error;
|
|
1549
1693
|
}
|
|
1550
1694
|
}
|
|
@@ -1619,7 +1763,7 @@ export function createAssistantDispatcher({
|
|
|
1619
1763
|
}
|
|
1620
1764
|
|
|
1621
1765
|
/** Accept a dispatch the router is holding for the user's model choice. */
|
|
1622
|
-
function holdForRoute(input, routed, { sessionId, origin, idempotencyKey, brief = null, remoteNotes = [] }) {
|
|
1766
|
+
function holdForRoute(input, routed, { sessionId, origin, idempotencyKey, brief = null, remoteNotes = [], agentNote = null, heldAgent = null }) {
|
|
1623
1767
|
const task = String(input.task || '').trim();
|
|
1624
1768
|
if (!task) throw new DispatchError('TASK_REQUIRED', 'task is required');
|
|
1625
1769
|
if (task.length > 20_000) throw new DispatchError('TASK_TOO_LONG', 'task must be at most 20000 characters');
|
|
@@ -1639,8 +1783,10 @@ export function createAssistantDispatcher({
|
|
|
1639
1783
|
workflowId: input.workflowId ? String(input.workflowId) : null, parentRunId: input.parentRunId ? String(input.parentRunId) : null,
|
|
1640
1784
|
usesBrowser: !!input.usesBrowser, usesComputer: input.usesComputer === true, capability: normalizeCapability(input.capability || 'full'),
|
|
1641
1785
|
idempotencyKey, rawSpec: { ...input }, route: routed.route,
|
|
1786
|
+
...(heldAgent ? { heldAgent } : {}),
|
|
1642
1787
|
notes: ['awaiting the user\'s model choice on the route card', ...remoteNotes],
|
|
1643
1788
|
};
|
|
1789
|
+
stampAgentRun(entry, input); // agents-p1
|
|
1644
1790
|
const heldClass = knownClass(routed.route?.taskClass) || knownClass(input.taskClass);
|
|
1645
1791
|
if (heldClass) entry.taskClass = heldClass;
|
|
1646
1792
|
const selection = dispatchTools({ ...input, taskClass: heldClass });
|
|
@@ -1651,7 +1797,7 @@ export function createAssistantDispatcher({
|
|
|
1651
1797
|
entry.usesBrowser = input.usesBrowser === true || selection.groups.some(isBrowserGroup);
|
|
1652
1798
|
if (brief) entry.brief = brief;
|
|
1653
1799
|
// A held run belongs to the task that asked for it, whenever the user picks its model.
|
|
1654
|
-
entry.taskId = taskAtDispatch(sessionId);
|
|
1800
|
+
entry.taskId = routed?.route?.taskId || taskAtDispatch(sessionId);
|
|
1655
1801
|
// The run waits on its route card, so the card must still be open: one that closed meanwhile
|
|
1656
1802
|
// (the user wrote something else, a Stop) would leave a run nothing ever starts or declines.
|
|
1657
1803
|
// Attached before the run exists: a refusal leaves no entry and no idempotency key behind.
|
|
@@ -1664,10 +1810,30 @@ export function createAssistantDispatcher({
|
|
|
1664
1810
|
emit(entry, 'route_pending', { routeId: routed.routeId });
|
|
1665
1811
|
return {
|
|
1666
1812
|
ok: true, queued: true, awaitingRoute: true, routeId: routed.routeId, run: view(entry),
|
|
1813
|
+
...(agentNote ? { corrections: [agentNote] } : {}),
|
|
1667
1814
|
next: 'This run is waiting for the user to pick its model on the route card. Do not dispatch it again. It starts automatically after the pick; the decision arrives as a [SynaBun Mailbox] route_decided event. If the user picks "here" instead, this run never starts and that event asks you to do the task yourself.',
|
|
1668
1815
|
};
|
|
1669
1816
|
}
|
|
1670
1817
|
|
|
1818
|
+
function workerForRoutePick(entry, target, agentRequest) {
|
|
1819
|
+
const runtime = { provider: target.provider, model: target.model || null, effort: target.effort ?? null,
|
|
1820
|
+
accountId: target.accountId || null, codexAccountId: null, claudeAccountId: null };
|
|
1821
|
+
if (!entry.heldAgent) return { input: { ...entry.rawSpec, ...runtime } };
|
|
1822
|
+
// Keep the role pinned while the card is open. The final provider can deliver a different
|
|
1823
|
+
// set of external servers, and the owner can select a proposal with a different agent.
|
|
1824
|
+
const original = entry.heldAgent.input;
|
|
1825
|
+
const sameRole = agentRequest === entry.route?.agentRequest;
|
|
1826
|
+
const route = { ...entry.route, agentRequest };
|
|
1827
|
+
const input = { ...original, ...runtime };
|
|
1828
|
+
if (entry.rawSpec?.moreloginEnvId && (sameRole || original.moreloginProfile || original.morelogin_profile || original.moreloginEnvId || original.morelogin_env_id)) {
|
|
1829
|
+
input.moreloginEnvId = entry.rawSpec.moreloginEnvId;
|
|
1830
|
+
input.moreloginEnvName = entry.rawSpec.moreloginEnvName;
|
|
1831
|
+
}
|
|
1832
|
+
const selected = applyRouteAgent(original, input, route, { assistantSessionId: entry.assistantSessionId,
|
|
1833
|
+
origin: entry.origin, desktop, resolveExternalTools }, sameRole ? entry.heldAgent.resolved : null);
|
|
1834
|
+
return { input: withClassDefaults(selected.input, entry.taskClass), route, note: selected.note };
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1671
1837
|
/**
|
|
1672
1838
|
* Why the held run `runId` could not start on `target`, else null: the router's checkHeld, asked
|
|
1673
1839
|
* before it approves a route card's pick, so a pick resolveRoute would refuse is not approved,
|
|
@@ -1675,7 +1841,7 @@ export function createAssistantDispatcher({
|
|
|
1675
1841
|
* catalog as it stands: MODEL_CANNOT_SEE, MODEL_UNAVAILABLE) and, for every run, browser
|
|
1676
1842
|
* settings on that provider (BROWSER_SETTINGS_CONFLICT). Other refusals still come in resolveRoute.
|
|
1677
1843
|
*/
|
|
1678
|
-
function heldRouteRefusal(runId, target) {
|
|
1844
|
+
function heldRouteRefusal(runId, target, { agentRequest } = {}) {
|
|
1679
1845
|
const entry = entries.get(String(runId || ''));
|
|
1680
1846
|
if (!entry || entry.state !== 'awaiting_route' || !target?.provider) return null;
|
|
1681
1847
|
const provider = String(target.provider).trim().toLowerCase();
|
|
@@ -1684,25 +1850,45 @@ export function createAssistantDispatcher({
|
|
|
1684
1850
|
try { catalogValue = catalog?.peek?.() || null; } catch { catalogValue = null; }
|
|
1685
1851
|
const refusal = designRefusal(catalogValue, provider, model, entry.taskClass || null);
|
|
1686
1852
|
if (refusal) return refusal;
|
|
1853
|
+
if (entry.heldAgent) {
|
|
1854
|
+
try {
|
|
1855
|
+
const pick = workerForRoutePick(entry, target, agentRequest);
|
|
1856
|
+
const input = clampRemote(pick.input, entry.assistantSessionId);
|
|
1857
|
+
const pin = agentPinOf(input);
|
|
1858
|
+
normalizeSpec(input, { catalogValue, taskClass: entry.taskClass, builtin: pin?.source === 'builtin' || !!pin?.classDefault });
|
|
1859
|
+
return null;
|
|
1860
|
+
} catch (error) { return error; }
|
|
1861
|
+
}
|
|
1687
1862
|
const conflict = browserSettingsConflict({ ...(entry.rawSpec || {}), provider, model }, provider);
|
|
1688
1863
|
return conflict ? new DispatchError('BROWSER_SETTINGS_CONFLICT', conflict, { status: 400 }) : null;
|
|
1689
1864
|
}
|
|
1690
1865
|
|
|
1691
1866
|
/** The user picked a target for a held run: validate, then start or queue it. */
|
|
1692
|
-
async function resolveRoute(runId, { target, routeId = null, decidedBy = 'user', remembered = false, optionId = null } = {}) {
|
|
1867
|
+
async function resolveRoute(runId, { target, routeId = null, decidedBy = 'user', remembered = false, optionId = null, agentRequest } = {}) {
|
|
1693
1868
|
const entry = entries.get(runId);
|
|
1694
1869
|
if (!entry || entry.state !== 'awaiting_route' || !target?.provider) return { ok: false, code: 'NOT_HELD' };
|
|
1695
1870
|
const catalogValue = await catalogSnapshot();
|
|
1696
|
-
let input = { ...(entry.rawSpec || {}), provider: target.provider, model: target.model || null, effort: target.effort ?? null, accountId: target.accountId || null, codexAccountId: null, claudeAccountId: null };
|
|
1697
1871
|
let spec;
|
|
1698
|
-
// The picked provider may need another clamp (Codex under strict worker approvals), or the level fell meanwhile.
|
|
1699
1872
|
const remoteNotes = [];
|
|
1700
|
-
try {
|
|
1873
|
+
try {
|
|
1874
|
+
const pick = workerForRoutePick(entry, target, agentRequest);
|
|
1875
|
+
let input = pick.input.moreloginProfile || pick.input.morelogin_profile ? await withBrowserProfile(pick.input) : pick.input;
|
|
1876
|
+
input = clampRemote(input, entry.assistantSessionId, remoteNotes);
|
|
1877
|
+
const pin = entry.heldAgent ? agentPinOf(input) : entry.agentPin;
|
|
1878
|
+
spec = normalizeSpec(input, { catalogValue, taskClass: entry.taskClass || null, builtin: pin?.source === 'builtin' || !!pin?.classDefault });
|
|
1879
|
+
if (pick.route) {
|
|
1880
|
+
if (entry.agentRef && !pin) Object.assign(entry, { agentRef: null, agentRevision: null, agentPin: null });
|
|
1881
|
+
stampAgentRun(entry, input);
|
|
1882
|
+
entry.route = appliedRoute(pick.route, input, pick.note);
|
|
1883
|
+
if (pick.note) remoteNotes.push(pick.note.text);
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1701
1886
|
catch (error) {
|
|
1702
1887
|
entry.state = 'failed'; entry.completionReason = 'route_invalid'; entry.finishedAt = iso(now()); entry.turnState = 'terminal';
|
|
1703
1888
|
entry.error = error?.message || String(error);
|
|
1704
1889
|
entry.notes.push(`route target rejected: ${entry.error}`);
|
|
1705
1890
|
delete entry.rawSpec;
|
|
1891
|
+
delete entry.heldAgent;
|
|
1706
1892
|
emit(entry, 'failed');
|
|
1707
1893
|
return { ok: false, error };
|
|
1708
1894
|
}
|
|
@@ -1713,6 +1899,7 @@ export function createAssistantDispatcher({
|
|
|
1713
1899
|
target: describeTarget(target, { catalog: catalogValue }), decidedAt: iso(now()),
|
|
1714
1900
|
};
|
|
1715
1901
|
delete entry.rawSpec;
|
|
1902
|
+
delete entry.heldAgent;
|
|
1716
1903
|
entry.state = 'queued';
|
|
1717
1904
|
emit(entry, 'route_decided', { routeId });
|
|
1718
1905
|
try { return await launchOrQueue(entry, spec); }
|
|
@@ -1728,6 +1915,7 @@ export function createAssistantDispatcher({
|
|
|
1728
1915
|
entry.route = { ...(entry.route || {}), status, decidedBy: reason === 'route_expired' ? 'timeout' : 'user', decidedAt: iso(now()) };
|
|
1729
1916
|
if (reason === 'route_here') entry.notes.push('the user chose to do this task here, in the conversation: this worker was not started');
|
|
1730
1917
|
delete entry.rawSpec;
|
|
1918
|
+
delete entry.heldAgent;
|
|
1731
1919
|
emit(entry, 'stopped');
|
|
1732
1920
|
return true;
|
|
1733
1921
|
}
|
|
@@ -1754,9 +1942,9 @@ export function createAssistantDispatcher({
|
|
|
1754
1942
|
usesBrowser: entry.usesBrowser, usesComputer: entry.usesComputer, maxMinutes: entry.maxMinutes, budgetUsd: entry.budgetUsd,
|
|
1755
1943
|
...(entry.moreloginEnvId ? { moreloginEnvId: entry.moreloginEnvId, moreloginEnvName: entry.moreloginEnvName || null } : {}),
|
|
1756
1944
|
outputSchema: entry.outputSchema, taskClass: entry.taskClass || null,
|
|
1757
|
-
}, { assistantSessionId: entry.assistantSessionId, origin: 'ui', brief: entry.brief || null });
|
|
1945
|
+
}, { assistantSessionId: entry.assistantSessionId, origin: 'ui', brief: entry.brief || null, agentOf: entry });
|
|
1758
1946
|
const child = entries.get(result?.run?.runId);
|
|
1759
|
-
if (child) { child.escalationDepth = (Number(entry.escalationDepth) || 0) + 1; child.escalatedFrom = runId; }
|
|
1947
|
+
if (child) { child.escalationDepth = (Number(entry.escalationDepth) || 0) + 1; child.escalatedFrom = runId; carryAgentRun(entry, child); /* agents-p1 */ }
|
|
1760
1948
|
entry.notes.push(`${retry ? 'retried on' : 'escalated to'} ${to.provider}/${to.model || 'default'} as ${result?.run?.runId || '?'}`);
|
|
1761
1949
|
if (entry.limit && typeof entry.limit === 'object') entry.limit = { ...entry.limit, retriedAt: iso(now()) };
|
|
1762
1950
|
emit(entry, 'escalated', { childRunId: result?.run?.runId || null });
|
|
@@ -1997,7 +2185,7 @@ export function createAssistantDispatcher({
|
|
|
1997
2185
|
/** What a run's worker keeps in memory while it lives (never saved): its turn loop, transcript tail, waits. */
|
|
1998
2186
|
function newLiveState(entry) {
|
|
1999
2187
|
return {
|
|
2000
|
-
entry, ctx: null, ring: [], ringChars: 0,
|
|
2188
|
+
entry, ctx: null, ring: [], ringChars: 0, waitResolve: null, idleTimer: null,
|
|
2001
2189
|
pendingResolvers: new Map(), dead: false, lastEventAt: now(), stalledFlagged: false, turnCounter: 0, abortReason: null,
|
|
2002
2190
|
evidence: null, // the current turn's commands / tool results / edited files (assistant-evidence.js)
|
|
2003
2191
|
completed: false, // its turn loop ended on a completion (agent_complete, a closed finished tab, a removal)
|
|
@@ -2055,6 +2243,8 @@ export function createAssistantDispatcher({
|
|
|
2055
2243
|
title: entry.title, tags: entry.tags, workflowId: entry.workflowId, parentRunId: entry.parentRunId,
|
|
2056
2244
|
// The user's brief after a clarification (assistant-task-prompt.js briefBlock).
|
|
2057
2245
|
brief: entry.brief || null,
|
|
2246
|
+
// agents-p4: a team slice's TEAM block (assistant-task-prompt.js teamBlock); null for every other run.
|
|
2247
|
+
team: entry.teamBrief || null,
|
|
2058
2248
|
// Image / video creation: the prompt's media block and what the adapter collects ('image' | 'video');
|
|
2059
2249
|
// design collects its screenshots and images the same way ('image').
|
|
2060
2250
|
taskClass: entry.taskClass || null, collectMedia: collectedMedia(entry.taskClass),
|
|
@@ -2239,13 +2429,20 @@ export function createAssistantDispatcher({
|
|
|
2239
2429
|
startUsageMetering(entry, liveState);
|
|
2240
2430
|
const waitForFollowUp = () => new Promise((resolveWait) => {
|
|
2241
2431
|
const finish = (value) => { if (liveState.idleTimer) { clearTimeout(liveState.idleTimer); liveState.idleTimer = null; } liveState.waitResolve = null; resolveWait(value); };
|
|
2242
|
-
|
|
2432
|
+
// The outbox first (Agents P2): what was queued while the turn worked, or while a restart had the run away.
|
|
2433
|
+
const queued = nextFollowUp(entry.runId);
|
|
2434
|
+
if (queued) { finish(queued); return; }
|
|
2243
2435
|
if (liveState.abortReason) { finish({ kind: 'abort' }); return; }
|
|
2244
|
-
|
|
2436
|
+
// sendTurn signals { kind: 'follow-up' } once its text is in the outbox: the oldest queued one is taken from there.
|
|
2437
|
+
liveState.waitResolve = (value) => {
|
|
2438
|
+
if (value?.kind !== 'follow-up') { finish(value); return; }
|
|
2439
|
+
const next = nextFollowUp(entry.runId);
|
|
2440
|
+
if (next) finish(next);
|
|
2441
|
+
};
|
|
2245
2442
|
liveState.idleTimer = setTimeout(() => finish({ kind: 'timeout' }), entry.idleTimeoutMs);
|
|
2246
2443
|
liveState.idleTimer.unref?.();
|
|
2247
2444
|
});
|
|
2248
|
-
const runInnerTurn = async (prompt, meta, { origin = 'assistant', label = null, followUp = null, taskId = entry.taskId || null } = {}) => {
|
|
2445
|
+
const runInnerTurn = async (prompt, meta, { origin = 'assistant', label = null, followUp = null, taskId = entry.taskId || null, outboxId = null } = {}) => {
|
|
2249
2446
|
liveState.turnCounter += 1;
|
|
2250
2447
|
const turnNumber = liveState.turnCounter;
|
|
2251
2448
|
const startedAt = iso(now());
|
|
@@ -2271,6 +2468,9 @@ export function createAssistantDispatcher({
|
|
|
2271
2468
|
liveState.evidence = createTurnEvidence();
|
|
2272
2469
|
// Money booked while this turn runs (OpenCode steps, Codex rollout records).
|
|
2273
2470
|
liveState.turnMeteredUsd = 0;
|
|
2471
|
+
// A queued follow-up is sent exactly here, as its prompt goes to the provider: a restart from now on continues
|
|
2472
|
+
// this turn (resumeInfo.inFlight) and never sends the text a second time.
|
|
2473
|
+
if (outboxId) { try { coordination.followUps.markSent([outboxId]); } catch (error) { log(entry.runId, 'assistant:follow-up-error', error?.message || String(error)); } }
|
|
2274
2474
|
let raw = await inner.runTurn(prompt, { ...meta, turn: turnNumber, outputSchema: entry.outputSchema || undefined });
|
|
2275
2475
|
if (entry.provider === 'codex') settleCodexTurn(entry, liveState, raw);
|
|
2276
2476
|
else if (entry.provider === 'antigravity') settleAntigravityTurn(entry, liveState, raw);
|
|
@@ -2365,6 +2565,8 @@ export function createAssistantDispatcher({
|
|
|
2365
2565
|
// (the OpenCode panel's pill): a warm worker whose turn ended asking waits on the user, it does not rest.
|
|
2366
2566
|
ctx.setOutcome?.(parsed.status || null);
|
|
2367
2567
|
entry.lastText = text.slice(0, 20_000);
|
|
2568
|
+
// The whole text goes to disk (lib/assistant-run-tail.js): agent_read format "text" pages through it with `offset`.
|
|
2569
|
+
tails.saveText(entry.runId, { turn: turnNumber, text });
|
|
2368
2570
|
// The turn has ended: its result is in. Idle time from here on is not work.
|
|
2369
2571
|
pauseWork(entry, liveState);
|
|
2370
2572
|
// Blocked or contract-less turns offer a one-tier escalation (the run
|
|
@@ -2443,15 +2645,18 @@ export function createAssistantDispatcher({
|
|
|
2443
2645
|
entry.notes.push(`follow-up dropped: ${blocked.message}${blocked.code === 'BUDGET_SHARE_EXHAUSTED' ? '; no unspent budget could be moved to it' : ''}`);
|
|
2444
2646
|
return budgetStop(entry, blocked);
|
|
2445
2647
|
}
|
|
2446
|
-
// No work time left: a turn started now would only be cut off.
|
|
2648
|
+
// No work time left: a turn started now would only be cut off. The run ends as the cap's timer ends it
|
|
2649
|
+
// (stopped, time_cap), so its brain hears it in its mailbox; the follow-up stays in the outbox until
|
|
2650
|
+
// finalize cancels it, and the stop event names it.
|
|
2447
2651
|
if (workLeftMs(entry) <= 0) {
|
|
2448
2652
|
entry.completionReason = 'time_cap';
|
|
2449
2653
|
entry.notes.push(`follow-up dropped: its ${entry.maxMinutes} minutes of work time are used up`);
|
|
2654
|
+
stop(entry.runId, 'time_cap').catch(() => {});
|
|
2450
2655
|
return { providerSessionId: inner.identity?.()?.providerSessionId };
|
|
2451
2656
|
}
|
|
2452
2657
|
try {
|
|
2453
2658
|
const followPrompt = buildFollowUpPrompt(next.text, state, { turn: liveState.turnCounter + 1, maxTurns: entry.maxTurns, origin: next.origin, testDensity: changedTestDensity(entry) });
|
|
2454
|
-
await runInnerTurn(followPrompt, meta, { origin: next.origin, label: clip(next.text, 80), followUp: next.text, taskId: next.taskId || entry.taskId || null });
|
|
2659
|
+
await runInnerTurn(followPrompt, meta, { origin: next.origin, label: clip(next.text, 80), followUp: next.text, taskId: next.taskId || entry.taskId || null, outboxId: next.id || null });
|
|
2455
2660
|
} catch (error) {
|
|
2456
2661
|
pauseWork(entry, liveState);
|
|
2457
2662
|
return handleTurnError(error, liveState, entry, ctx);
|
|
@@ -3445,10 +3650,9 @@ export function createAssistantDispatcher({
|
|
|
3445
3650
|
const liveState = newLiveState(entry);
|
|
3446
3651
|
liveState.turnCounter = turned;
|
|
3447
3652
|
liveState.resume = { mode, taskId: inFlight?.taskId || null };
|
|
3448
|
-
// Follow-ups sent while it was away wait
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
liveState.followUps.push(...waiting);
|
|
3653
|
+
// Follow-ups sent while it was away wait in the outbox: its turn loop takes them like any queued follow-up.
|
|
3654
|
+
// The transcript tail kept on disk goes on where it was.
|
|
3655
|
+
for (const line of tails.readTail(entry.runId)) pushRingLine(liveState, line);
|
|
3452
3656
|
live.set(entry.runId, liveState);
|
|
3453
3657
|
const desktopGrant = mintDesktopGrant(entry);
|
|
3454
3658
|
const state = runState(entry, {
|
|
@@ -3528,8 +3732,7 @@ export function createAssistantDispatcher({
|
|
|
3528
3732
|
const index = queue.indexOf(entry.runId);
|
|
3529
3733
|
if (index !== -1) queue.splice(index, 1);
|
|
3530
3734
|
// Follow-ups accepted for it while it was away (agent_send) reach nobody: its end says so, with the first of them.
|
|
3531
|
-
const waiting =
|
|
3532
|
-
awaitingResume.delete(entry.runId);
|
|
3735
|
+
const waiting = cancelFollowUps(entry.runId);
|
|
3533
3736
|
const undelivered = waiting.length ? `; ${waiting.length} follow-up${waiting.length === 1 ? '' : 's'} sent while it was away ${waiting.length === 1 ? 'was' : 'were'} not delivered (${waiting.length === 1 ? '' : 'the first: '}"${clip(waiting[0].text, 160)}")` : '';
|
|
3534
3737
|
// Nothing of it may go on: a CLI a crash left behind is ended too.
|
|
3535
3738
|
endOldProcess(entry).then(() => persist()).catch(() => {});
|
|
@@ -3580,20 +3783,25 @@ export function createAssistantDispatcher({
|
|
|
3580
3783
|
}
|
|
3581
3784
|
// A follow-up works for the task in progress when it is sent, which may be a later one than the run's.
|
|
3582
3785
|
const item = { kind: 'follow-up', text: message, origin, at: iso(now()), taskId: taskNow(entry.assistantSessionId) || entry.taskId || null };
|
|
3786
|
+
// Every follow-up goes through the outbox (Agents P2), also one an idle run takes at once: the queue is one, in
|
|
3787
|
+
// order, and what it holds outlives a restart.
|
|
3788
|
+
const idle = !away && !!liveState.waitResolve;
|
|
3789
|
+
if (!idle && !allowQueue) {
|
|
3790
|
+
throw new DispatchError('TURN_ACTIVE', away
|
|
3791
|
+
? `Run ${runId} is ${entry.state === 'suspended' ? 'suspended while the server restarts' : 'being resumed after a server restart'}; retry when it is idle or pass queue:true`
|
|
3792
|
+
: `Run ${runId} is busy; retry when idle or pass queue:true`, { status: 409 });
|
|
3793
|
+
}
|
|
3794
|
+
const queued = queueFollowUp(entry, item);
|
|
3583
3795
|
if (origin === 'user') emit(entry, 'user_intervened', { text: clip(message, 200) });
|
|
3584
|
-
if (
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
waiting.push(item);
|
|
3588
|
-
awaitingResume.set(runId, waiting);
|
|
3589
|
-
emit(entry, 'follow_up_queued', { queued: waiting.length });
|
|
3590
|
-
return { ok: true, queued: true, position: waiting.length, run: view(entry), note: 'The run resumes after the server restart; this follow-up goes to it then.' };
|
|
3796
|
+
if (idle) {
|
|
3797
|
+
liveState.waitResolve({ kind: 'follow-up' });
|
|
3798
|
+
return { ok: true, queued: false, turn: liveState.turnCounter + 1, followUpId: queued.id, run: view(entry) };
|
|
3591
3799
|
}
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3800
|
+
emit(entry, 'follow_up_queued', { queued: queued.position });
|
|
3801
|
+
return {
|
|
3802
|
+
ok: true, queued: true, position: queued.position, followUpId: queued.id, run: view(entry),
|
|
3803
|
+
...(away ? { note: 'The run resumes after the server restart; this follow-up goes to it then.' } : {}),
|
|
3804
|
+
};
|
|
3597
3805
|
}
|
|
3598
3806
|
/**
|
|
3599
3807
|
* Before a follow-up: when the run's provider share is used up, the session's unspent budget is
|
|
@@ -3640,6 +3848,7 @@ export function createAssistantDispatcher({
|
|
|
3640
3848
|
if (index !== -1) queue.splice(index, 1);
|
|
3641
3849
|
entry.state = 'stopped'; entry.completionReason = reason; entry.finishedAt = iso(now()); entry.turnState = 'terminal';
|
|
3642
3850
|
delete entry.rawSpec;
|
|
3851
|
+
delete entry.heldAgent;
|
|
3643
3852
|
if (held) { try { router?.cancelForRun?.(runId, 'run_stopped'); } catch {} }
|
|
3644
3853
|
emit(entry, 'stopped');
|
|
3645
3854
|
return { ok: true, run: view(entry) };
|
|
@@ -3651,7 +3860,7 @@ export function createAssistantDispatcher({
|
|
|
3651
3860
|
if (entry.state === 'resuming' || entry.state === 'suspended') {
|
|
3652
3861
|
const index = queue.indexOf(runId);
|
|
3653
3862
|
if (index !== -1) queue.splice(index, 1);
|
|
3654
|
-
|
|
3863
|
+
cancelFollowUps(runId);
|
|
3655
3864
|
// A CLI a crash left behind (this start has not ended it yet) goes with the run.
|
|
3656
3865
|
if (entry.state === 'resuming') await endOldProcess(entry);
|
|
3657
3866
|
}
|
|
@@ -3673,8 +3882,12 @@ export function createAssistantDispatcher({
|
|
|
3673
3882
|
function finalize(entry, runtimeRun) {
|
|
3674
3883
|
if (TERMINAL_STATES.has(entry.state)) return;
|
|
3675
3884
|
const liveState = live.get(entry.runId);
|
|
3676
|
-
// Follow-ups
|
|
3677
|
-
|
|
3885
|
+
// Follow-ups still queued for it (behind a turn, or for its resume after a restart) go with it: its notes say so.
|
|
3886
|
+
const unsent = cancelFollowUps(entry.runId);
|
|
3887
|
+
const undelivered = unsent.length ? `${unsent.length} queued follow-up${unsent.length === 1 ? '' : 's'} not delivered: the run ended first (the first: "${clip(unsent[0].text, 160)}")` : null;
|
|
3888
|
+
if (undelivered) entry.notes.push(undelivered);
|
|
3889
|
+
// What its transcript showed last stays readable (agent_read format "tail") after the worker is gone.
|
|
3890
|
+
if (liveState) tails.flush(entry.runId, liveState.ring);
|
|
3678
3891
|
pauseWork(entry, liveState);
|
|
3679
3892
|
let status = runtimeRun?.status || 'completed';
|
|
3680
3893
|
// A completed worker whose loop file was swept meanwhile (a stale-file cleanup) reaches the
|
|
@@ -3707,7 +3920,8 @@ export function createAssistantDispatcher({
|
|
|
3707
3920
|
return;
|
|
3708
3921
|
}
|
|
3709
3922
|
if (entry.state === 'failed' || entry.lastResult?.status === 'blocked') { noteLimit(entry); entry.escalation = computeEscalation(entry); }
|
|
3710
|
-
|
|
3923
|
+
// The end event says which follow-ups never reached the worker (a stop the brain hears of carries it to its mailbox).
|
|
3924
|
+
emit(entry, entry.state, undelivered ? { text: undelivered } : {});
|
|
3711
3925
|
// A memory already stored for the run (by the worker or the brain) is the run's memory.
|
|
3712
3926
|
// An evaluation run (lib/skills/evals.js) is a measurement, not work to remember: it stores no memory.
|
|
3713
3927
|
if (memory?.rememberDispatch && !isEvalRun(entry) && !syncMemory(entry, { announce: true }) && (entry.state === 'completed' || (entry.state === 'stopped' && entry.lastResult))) {
|
|
@@ -3730,6 +3944,8 @@ export function createAssistantDispatcher({
|
|
|
3730
3944
|
const removed = liveState.ring.shift();
|
|
3731
3945
|
liveState.ringChars -= removed?.length || 0;
|
|
3732
3946
|
}
|
|
3947
|
+
// Kept on disk too (at most once a second), so the tail is still there after the run or a restart.
|
|
3948
|
+
tails.touch(liveState.entry.runId, () => liveState.ring);
|
|
3733
3949
|
}
|
|
3734
3950
|
/**
|
|
3735
3951
|
* An Antigravity message chunk (ACP agent_message_chunk): the text joins the message's line when that line is
|
|
@@ -3747,6 +3963,7 @@ export function createAssistantDispatcher({
|
|
|
3747
3963
|
liveState.ring[liveState.ring.length - 1] = line;
|
|
3748
3964
|
liveState.ringChars += line.length - open.line.length;
|
|
3749
3965
|
open.line = line;
|
|
3966
|
+
tails.touch(liveState.entry.runId, () => liveState.ring);
|
|
3750
3967
|
}
|
|
3751
3968
|
return;
|
|
3752
3969
|
}
|
|
@@ -3882,6 +4099,19 @@ export function createAssistantDispatcher({
|
|
|
3882
4099
|
.slice(0, Math.max(1, Math.min(500, Number(limit) || 100)))
|
|
3883
4100
|
.map((entry) => view(entry));
|
|
3884
4101
|
}
|
|
4102
|
+
// Check live entries directly: a long queue must not hide an older worker behind the roster's page limit.
|
|
4103
|
+
function hasRunAwaitingOwner() {
|
|
4104
|
+
for (const entry of entries.values()) {
|
|
4105
|
+
if (entry.removedAt || !ACTIVE_STATES.has(entry.state) || entry.state === 'suspended') continue;
|
|
4106
|
+
if (entry.state === 'awaiting_route' || entry.route?.status === 'pending' || entry.state === 'awaiting_permission') return true;
|
|
4107
|
+
if (runAwaitsAnswer({ status: runStatusFromState(entry.state), turnState: entry.turnState, pending: entry.pending, lastResult: entry.lastResult })) return true;
|
|
4108
|
+
}
|
|
4109
|
+
return false;
|
|
4110
|
+
}
|
|
4111
|
+
// Unbounded inventory, including removed runs, for conservative team cleanup checks.
|
|
4112
|
+
function teamRuns(teamId, workflowId) {
|
|
4113
|
+
return [...entries.values()].filter(entry => entry.teamId === teamId || entry.team?.teamId === teamId || entry.workflowId === workflowId).map(entry => view(entry));
|
|
4114
|
+
}
|
|
3885
4115
|
function totals({ assistantSessionId = null, workflowId = null } = {}) {
|
|
3886
4116
|
const rows = [...entries.values()].filter((entry) => (!assistantSessionId || entry.assistantSessionId === assistantSessionId) && (!workflowId || entry.workflowId === workflowId));
|
|
3887
4117
|
// tokens: the five classes plus total, from the runs' ledger views (a run without one counts its legacy input / output).
|
|
@@ -3910,60 +4140,45 @@ export function createAssistantDispatcher({
|
|
|
3910
4140
|
out.queue = queue.map((runId, index) => ({ runId, position: index + 1, title: entries.get(runId)?.title || null, provider: entries.get(runId)?.provider || null }));
|
|
3911
4141
|
return out;
|
|
3912
4142
|
}
|
|
3913
|
-
|
|
4143
|
+
/**
|
|
4144
|
+
* agent_read. `offset` (Agents P2, additive) pages through the text of format "text" / "tail": without it the
|
|
4145
|
+
* answer is the END of the text, at most `maxChars`, and says where that page starts (`offset`) and how long the
|
|
4146
|
+
* whole is (`totalChars`); with it the page starts there and `nextOffset` is where the following one starts.
|
|
4147
|
+
*/
|
|
4148
|
+
function transcript(runId, { format = 'result', tail = 40, maxChars = 4000, offset = null } = {}) {
|
|
3914
4149
|
const entry = requireEntry(runId);
|
|
3915
4150
|
const liveState = live.get(runId);
|
|
3916
4151
|
const cap = Math.max(200, Math.min(20_000, Number(maxChars) || 4000));
|
|
3917
4152
|
const base = { runId, state: entry.state, turnState: entry.turnState, outcome: entry.lastResult?.status || null, turns: (entry.turns || []).length };
|
|
3918
4153
|
if (format === 'result') return { ...base, result: entry.lastResult, turnsSummary: (entry.turns || []).map((turn) => ({ n: turn.n, origin: turn.origin, status: turn.result?.status || null, summary: clip(turn.result?.summary, 200), costUsd: turn.costUsd })) };
|
|
3919
4154
|
if (format === 'text') {
|
|
3920
|
-
|
|
3921
|
-
|
|
4155
|
+
// The whole text of the last turn is on disk; the registry keeps its first 20,000 characters only.
|
|
4156
|
+
const kept = tails.readText(runId);
|
|
4157
|
+
const lastTurn = (entry.turns || []).at(-1)?.n ?? null;
|
|
4158
|
+
const text = kept && (kept.turn === null || lastTurn === null || kept.turn === lastTurn) ? kept.text : String(entry.lastText || '');
|
|
4159
|
+
return { ...base, ...pageText(text, { offset, maxChars: cap }) };
|
|
3922
4160
|
}
|
|
3923
4161
|
if (format === 'files') return { ...base, files: entry.lastResult?.files || [] };
|
|
3924
4162
|
// A skill-evaluation run's tool calls and its start catalog (kept while the run lives).
|
|
3925
4163
|
if (format === 'tools') return { ...base, calls: liveState?.evalCalls ? [...liveState.evalCalls] : [], init: liveState?.evalInit || null, unavailable: !liveState ? 'tool calls are only kept for live runs' : null };
|
|
3926
4164
|
if (format === 'events' || format === 'tail') {
|
|
3927
|
-
|
|
3928
|
-
const
|
|
3929
|
-
|
|
4165
|
+
// A live run's ring, else what was kept of it on disk (the run ended, or the server restarted since).
|
|
4166
|
+
const all = liveState ? liveState.ring : tails.readTail(runId);
|
|
4167
|
+
const lines = all.slice(-Math.max(1, Math.min(500, Number(tail) || 40)));
|
|
4168
|
+
return {
|
|
4169
|
+
...base, tail: lines, ...pageText(lines.join('\n'), { offset, maxChars: cap }),
|
|
4170
|
+
unavailable: !liveState && !all.length ? 'no transcript was kept for this run' : null,
|
|
4171
|
+
};
|
|
3930
4172
|
}
|
|
3931
4173
|
throw new DispatchError('INVALID_FORMAT', `Unknown transcript format ${format}`);
|
|
3932
4174
|
}
|
|
3933
4175
|
function pendingPermissions(runId) { return [...(requireEntry(runId).pending || [])]; }
|
|
3934
4176
|
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
for (const id of ids) requireEntry(id);
|
|
3941
|
-
const started = now();
|
|
3942
|
-
const budget = Math.max(1000, Math.min(limits.waitCapMs, Number(timeoutMs) || 30_000));
|
|
3943
|
-
const baseline = new Map(ids.map((id) => [id, Number(entries.get(id)?.version) || 0]));
|
|
3944
|
-
const check = () => {
|
|
3945
|
-
const satisfied = ids.filter((id) => satisfies(entries.get(id), until, baseline.get(id)));
|
|
3946
|
-
return mode === 'any' ? satisfied.length > 0 : satisfied.length === ids.length;
|
|
3947
|
-
};
|
|
3948
|
-
if (!check()) {
|
|
3949
|
-
await new Promise((resolveWait) => {
|
|
3950
|
-
const waiter = { check, resolve: () => { clearTimeout(timer); resolveWait(); } };
|
|
3951
|
-
const timer = setTimeout(() => { waiters.delete(waiter); resolveWait(); }, budget);
|
|
3952
|
-
timer.unref?.();
|
|
3953
|
-
waiters.add(waiter);
|
|
3954
|
-
});
|
|
3955
|
-
}
|
|
3956
|
-
const done = ids.filter((id) => satisfies(entries.get(id), until, baseline.get(id)));
|
|
3957
|
-
const pendingIds = ids.filter((id) => !done.includes(id));
|
|
3958
|
-
const timedOut = !check();
|
|
3959
|
-
return {
|
|
3960
|
-
ok: true, timedOut, waitedMs: now() - started, until, mode,
|
|
3961
|
-
done: done.map((id) => view(entries.get(id))),
|
|
3962
|
-
pending: pendingIds.map((id) => view(entries.get(id))),
|
|
3963
|
-
needsInput: ids.map((id) => entries.get(id)).filter((e) => e?.lastResult?.status === 'needs_input' && e.state === 'idle').map((e) => ({ runId: e.runId, question: e.lastResult.question })),
|
|
3964
|
-
permissions: ids.flatMap((id) => (entries.get(id)?.pending || []).map((request) => ({ runId: id, ...request }))),
|
|
3965
|
-
};
|
|
3966
|
-
}
|
|
4177
|
+
/**
|
|
4178
|
+
* agent_wait (lib/assistant-run-wait.js). Additive since Agents P2: `afterSeq` and `kinds` for until 'event',
|
|
4179
|
+
* `unseenFor` (the asking brain's session), and `events` / `cursor` in the answer.
|
|
4180
|
+
*/
|
|
4181
|
+
function wait(options = {}) { return runWaits.wait(options); }
|
|
3967
4182
|
|
|
3968
4183
|
// ── removal (the user clears finished runs from the agents tray) ──────────
|
|
3969
4184
|
/**
|
|
@@ -3976,7 +4191,7 @@ export function createAssistantDispatcher({
|
|
|
3976
4191
|
function finishedIdle(entry, { outcomes = ['done', 'blocked'] } = {}) {
|
|
3977
4192
|
return entry.state === 'idle' && !entry.judging
|
|
3978
4193
|
&& outcomes.includes(entry.lastResult?.status)
|
|
3979
|
-
&& !(
|
|
4194
|
+
&& !followUpCount(entry.runId);
|
|
3980
4195
|
}
|
|
3981
4196
|
async function finishIdleForRemoval(entry) {
|
|
3982
4197
|
if (!finishedIdle(entry)) return;
|
|
@@ -4043,18 +4258,27 @@ export function createAssistantDispatcher({
|
|
|
4043
4258
|
pauseWork(entry);
|
|
4044
4259
|
entry.state = 'interrupted'; entry.completionReason = reason; entry.finishedAt = iso(now()); entry.turnState = 'terminal'; entry.pending = [];
|
|
4045
4260
|
delete entry.rawSpec;
|
|
4261
|
+
delete entry.heldAgent;
|
|
4046
4262
|
// What the run's meter can still read is booked now; nothing provisional outlives the process.
|
|
4047
4263
|
try { finishUsage(entry, live.get(entry.runId) || null); } catch {}
|
|
4048
4264
|
releaseDesktop(entry);
|
|
4049
4265
|
}
|
|
4050
4266
|
}
|
|
4051
4267
|
persist({ force: true });
|
|
4268
|
+
// Agents P2: the transcript tails are written; a service this dispatcher made for itself goes with it (the one
|
|
4269
|
+
// server.js shares is closed there, after the runtime).
|
|
4270
|
+
tails.flushAll();
|
|
4271
|
+
if (!sharedCoordination) coordination.close();
|
|
4052
4272
|
}
|
|
4053
4273
|
|
|
4054
4274
|
loadRegistry();
|
|
4275
|
+
settleOrphanFollowUps();
|
|
4055
4276
|
attachRuntime();
|
|
4056
4277
|
stalledTimer = setInterval(() => { attachRuntime(); checkStalled(); beat(); }, 60_000);
|
|
4057
4278
|
stalledTimer.unref?.();
|
|
4279
|
+
// Transcript files of runs the registry dropped go, a while after the start (never on its path).
|
|
4280
|
+
const tailSweep = setTimeout(() => { try { tails.sweep(entries.keys()); } catch { /* the next start tries again */ } }, 30_000);
|
|
4281
|
+
tailSweep.unref?.();
|
|
4058
4282
|
// After a restart: the cut-off runs are resumed, or said to have ended, once the Assistant listens (server.js makes
|
|
4059
4283
|
// its runtime, which subscribes, right after this dispatcher, in the same tick).
|
|
4060
4284
|
if (bootResumes.length || bootInterrupts.length) {
|
|
@@ -4062,14 +4286,20 @@ export function createAssistantDispatcher({
|
|
|
4062
4286
|
}
|
|
4063
4287
|
|
|
4064
4288
|
return {
|
|
4065
|
-
dispatch, sendTurn, complete, completeClosedTab, stop, killAll, get, peek, list, totals, wait, transcript, pendingPermissions,
|
|
4289
|
+
dispatch, sendTurn, complete, completeClosedTab, stop, killAll, get, peek, teamRuns, hasRunAwaitingOwner, list, totals, wait, transcript, pendingPermissions,
|
|
4066
4290
|
respondPermission, subscribe, shutdown, limits, suspendForShutdown,
|
|
4067
4291
|
sessionBudget, checkSession, refreshLimits, providerSpend, coverFollowUp, budget,
|
|
4068
4292
|
resolveRoute, declineRoute, heldRouteRefusal, escalate,
|
|
4069
|
-
markDelivered, deliveryState, noteBrowserRoute, noteBrowserProfile,
|
|
4293
|
+
markDelivered, deliveryState, markEventsDelivered, noteBrowserRoute, noteBrowserProfile,
|
|
4070
4294
|
remove, removeFinished,
|
|
4071
4295
|
mediaFile,
|
|
4072
4296
|
accountInUse: (provider, accountId) => activeEntries((e) => e.provider === provider && e.accountId === accountId).length > 0,
|
|
4073
|
-
|
|
4297
|
+
// agents-p4: the session's Agent density as the server reads it (the default when it is not set or cannot be read).
|
|
4298
|
+
agentDensity: (assistantSessionId) => { try { return normalizeAgentDensity(agentDensity(assistantSessionId || null)); } catch { return normalizeAgentDensity(null); } },
|
|
4299
|
+
// Agents P2: the coordination service this dispatcher records into (the Assistant runtime reads its mailbox from it),
|
|
4300
|
+
// and when this server answers its workers (the runtime delivers the mailboxes a restart left open only then).
|
|
4301
|
+
coordination,
|
|
4302
|
+
whenServerReady: () => Promise.resolve(typeof serverReady === 'function' ? serverReady() : null).catch(() => null),
|
|
4303
|
+
_internals: { entries, live, queue, processQueue, attachRuntime, registryPath, tails, runWaits },
|
|
4074
4304
|
};
|
|
4075
4305
|
}
|