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
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun — Coordination service
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// The one place that owns the coordination store (store.js) while the server runs, and what the Assistant's
|
|
6
|
+
// dispatcher and runtime say to each other through it:
|
|
7
|
+
//
|
|
8
|
+
// run events every lifecycle event of a dispatched run (assistant-dispatch.js `emit`) is appended to the log in
|
|
9
|
+
// the step that changed the run, under an id that is the same however often it is recorded, with a
|
|
10
|
+
// priority, and addressed to the Assistant session that owns the run when its brain must hear it.
|
|
11
|
+
// the mailbox what a session's brain has not been told yet: the open events addressed to `session:<id>`. The
|
|
12
|
+
// runtime composes a turn from them and acknowledges them only once that turn was started. Nothing
|
|
13
|
+
// is dropped for being many: critical events go first, low-priority progress is folded by the store.
|
|
14
|
+
// run waits agent_wait until:"event" reads typed events of the log after a cursor.
|
|
15
|
+
// follow-ups text sent to a run while it works, or while a server restart has it away, waits in the store's
|
|
16
|
+
// outbox until the run's provider is handed it (assistant-dispatch.js).
|
|
17
|
+
// team a channel per team for the phase that adds worker-to-worker messages: post, read with a cursor,
|
|
18
|
+
// wait and acknowledge, scoped by team and run. Nothing here exposes it to a worker yet.
|
|
19
|
+
//
|
|
20
|
+
// Everything is synchronous except the waits. A store that cannot be opened (a damaged file, one a newer SynaBun
|
|
21
|
+
// wrote) is replaced by one in memory, loudly: the Assistant keeps working, without durability, until the file is
|
|
22
|
+
// dealt with. README.md beside this file documents the API.
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
COORDINATION_LIMITS, CoordinationError, EVENT_KINDS, KIND_PRIORITY,
|
|
26
|
+
coordinationDbPath, createCoordinationStore, runRecipient, sessionRecipient, teamRecipient,
|
|
27
|
+
} from './store.js';
|
|
28
|
+
|
|
29
|
+
export const COORDINATION_SERVICE_LIMITS = Object.freeze({
|
|
30
|
+
// Events one mailbox message carries. More than that stay open and follow in the next message (none is dropped).
|
|
31
|
+
mailboxItems: 30,
|
|
32
|
+
// A run's follow-ups that may wait at once (the admission bound of its queue).
|
|
33
|
+
followUpsPerRun: 20,
|
|
34
|
+
// Events settled this long ago leave the log (an event somebody has not acknowledged never does).
|
|
35
|
+
pruneAfterMs: 14 * 24 * 60 * 60 * 1000,
|
|
36
|
+
pruneEveryMs: 6 * 60 * 60 * 1000,
|
|
37
|
+
// What a run event's payload keeps of the run and its result (the brain reads the rest with agent_read).
|
|
38
|
+
summaryChars: 400, questionChars: 2000, textChars: 600, errorChars: 600, titleChars: 120, files: 50, followUps: 10, media: 12,
|
|
39
|
+
// A pinned agent ref is `<scope>:<id>@<revision>` (lib/agents/schema.js formatAgentRef): never near this long.
|
|
40
|
+
agentRefChars: 160,
|
|
41
|
+
teamText: 8000, teamRecipients: COORDINATION_LIMITS.recipients,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Why a stopped run is told to its brain: a stop by the user, a budget, or its work time (time_cap: max_minutes
|
|
46
|
+
* used up; agent_send is refused from then on). Any other stop was the brain's own, or needs no reaction.
|
|
47
|
+
*/
|
|
48
|
+
export const MAILBOX_STOP_REASONS = Object.freeze(new Set(['user', 'budget_cap', 'session_budget_cap', 'budget_unpriced', 'budget_share', 'time_cap']));
|
|
49
|
+
|
|
50
|
+
const K = EVENT_KINDS;
|
|
51
|
+
/**
|
|
52
|
+
* The dispatcher's emit reasons: the kind each is logged as, and whether the owning session's brain is told
|
|
53
|
+
* (`mailbox`). A reason that is not listed is progress, logged and told to nobody.
|
|
54
|
+
*/
|
|
55
|
+
export const RUN_EVENT_REASONS = Object.freeze({
|
|
56
|
+
turn_completed: { kind: K.RUN_RESULT, mailbox: true, item: 'result' },
|
|
57
|
+
needs_input: { kind: K.RUN_NEEDS_INPUT, mailbox: true },
|
|
58
|
+
permission_request: { kind: K.RUN_PERMISSION, mailbox: true },
|
|
59
|
+
failed: { kind: K.RUN_FAILED, mailbox: true },
|
|
60
|
+
interrupted: { kind: K.RUN_INTERRUPTED, mailbox: true },
|
|
61
|
+
stalled: { kind: K.RUN_STALLED, mailbox: true },
|
|
62
|
+
budget_exceeded: { kind: K.RUN_BUDGET, mailbox: true, priority: 'critical' },
|
|
63
|
+
budget_warning: { kind: K.RUN_BUDGET, mailbox: true },
|
|
64
|
+
budget_unpriced: { kind: K.RUN_BUDGET, mailbox: true },
|
|
65
|
+
stopped: { kind: K.RUN_STOPPED, mailbox: true },
|
|
66
|
+
completed: { kind: K.RUN_COMPLETED, mailbox: false },
|
|
67
|
+
user_intervened: { kind: K.RUN_NOTICE, mailbox: true },
|
|
68
|
+
queue_started: { kind: K.RUN_PROGRESS, mailbox: true },
|
|
69
|
+
suspended: { kind: K.RUN_PROGRESS, mailbox: true },
|
|
70
|
+
resumed: { kind: K.RUN_PROGRESS, mailbox: true },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/** A mailbox item's own kind (what the brain and the panel read) → the event kind it is stored as. */
|
|
74
|
+
export const MAILBOX_ITEM_KINDS = Object.freeze({
|
|
75
|
+
result: K.RUN_RESULT, needs_input: K.RUN_NEEDS_INPUT, permission_request: K.RUN_PERMISSION, failed: K.RUN_FAILED,
|
|
76
|
+
interrupted: K.RUN_INTERRUPTED, stalled: K.RUN_STALLED, stopped: K.RUN_STOPPED, user_intervened: K.RUN_NOTICE,
|
|
77
|
+
budget_warning: K.RUN_BUDGET, budget_exceeded: K.RUN_BUDGET, budget_unpriced: K.RUN_BUDGET,
|
|
78
|
+
queue_started: K.RUN_PROGRESS, suspended: K.RUN_PROGRESS, resumed: K.RUN_PROGRESS,
|
|
79
|
+
memory_due: K.SESSION_MEMORY_DUE,
|
|
80
|
+
route_decided: K.ROUTE_DECIDED, route_expired: K.ROUTE_EXPIRED, route_declined: K.ROUTE_DECLINED,
|
|
81
|
+
clarify_answered: K.CLARIFY_ANSWERED, clarify_declined: K.CLARIFY_DECLINED,
|
|
82
|
+
});
|
|
83
|
+
const ITEM_PRIORITY = Object.freeze({ budget_exceeded: 'critical' });
|
|
84
|
+
/** A mailbox item of a kind nothing above names. */
|
|
85
|
+
export const SESSION_NOTICE_KIND = 'session.notice';
|
|
86
|
+
|
|
87
|
+
/** What agent_wait until:"event" waits for when the caller names no kinds: everything but progress. */
|
|
88
|
+
export const RUN_WAIT_KINDS = Object.freeze([
|
|
89
|
+
K.RUN_RESULT, K.RUN_NEEDS_INPUT, K.RUN_PERMISSION, K.RUN_FAILED, K.RUN_STALLED, K.RUN_STOPPED, K.RUN_INTERRUPTED,
|
|
90
|
+
K.RUN_COMPLETED, K.RUN_BUDGET, K.RUN_NOTICE, K.RUN_MESSAGE,
|
|
91
|
+
]);
|
|
92
|
+
/** Every kind a run's events are logged as (agent_wait's `kinds` takes these). */
|
|
93
|
+
export const RUN_EVENT_KINDS = Object.freeze([...RUN_WAIT_KINDS, K.RUN_PROGRESS]);
|
|
94
|
+
|
|
95
|
+
const SESSION_PREFIX = 'session:';
|
|
96
|
+
const clip = (value, max) => {
|
|
97
|
+
const text = String(value ?? '');
|
|
98
|
+
return text.length > max ? `${text.slice(0, Math.max(0, max - 1))}…` : text;
|
|
99
|
+
};
|
|
100
|
+
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
101
|
+
|
|
102
|
+
/** The recipient name of one member of a team: its messages on that team's channel, and nothing else. */
|
|
103
|
+
export const teamMemberRecipient = (teamId, runId) => `team:${teamId}:run:${runId}`;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A run as an event carries it: what a mailbox line, a wait and the panel's chip need, never the worker's text or
|
|
107
|
+
* its turns (a run view is tens of kilobytes; this is a few hundred bytes).
|
|
108
|
+
*/
|
|
109
|
+
export function runBrief(run, limits = COORDINATION_SERVICE_LIMITS) {
|
|
110
|
+
if (!isObject(run)) return null;
|
|
111
|
+
const escalation = isObject(run.escalation) ? {
|
|
112
|
+
kind: run.escalation.kind ?? null, reason: run.escalation.reason ?? null, cause: run.escalation.cause ?? null,
|
|
113
|
+
needs: run.escalation.needs ? clip(run.escalation.needs, 200) : null,
|
|
114
|
+
to: isObject(run.escalation.to) ? { provider: run.escalation.to.provider ?? null, model: run.escalation.to.model ?? null, tier: run.escalation.to.tier ?? null } : null,
|
|
115
|
+
} : null;
|
|
116
|
+
const out = {
|
|
117
|
+
runId: String(run.runId || ''),
|
|
118
|
+
provider: run.provider ?? null,
|
|
119
|
+
model: run.model ?? null,
|
|
120
|
+
title: run.title ? clip(run.title, limits.titleChars) : null,
|
|
121
|
+
state: run.state ?? null,
|
|
122
|
+
outcome: run.outcome ?? run.lastResult?.status ?? null,
|
|
123
|
+
};
|
|
124
|
+
if (!out.title && run.task) out.task = clip(run.task, limits.titleChars);
|
|
125
|
+
if (run.completionReason) out.completionReason = String(run.completionReason);
|
|
126
|
+
if (Number.isFinite(Number(run.costUsd)) && Number(run.costUsd) > 0) out.costUsd = Number(run.costUsd);
|
|
127
|
+
if (typeof run.memoryStored === 'boolean') out.memoryStored = run.memoryStored;
|
|
128
|
+
if (run.workflowId) out.workflowId = String(run.workflowId);
|
|
129
|
+
if (run.assistantSessionId) out.assistantSessionId = String(run.assistantSessionId);
|
|
130
|
+
// The agent the run runs as (lib/agents/resolve.js stampAgentRun): the pinned ref and its revision. A plain
|
|
131
|
+
// worker's brief has neither key.
|
|
132
|
+
if (run.agentRef) {
|
|
133
|
+
out.agentRef = clip(run.agentRef, limits.agentRefChars);
|
|
134
|
+
if (Number.isInteger(Number(run.agentRevision)) && Number(run.agentRevision) > 0) out.agentRevision = Number(run.agentRevision);
|
|
135
|
+
}
|
|
136
|
+
if (isObject(run.limit)) out.limit = { resetsAt: run.limit.resetsAt ?? null };
|
|
137
|
+
if (escalation) out.escalation = escalation;
|
|
138
|
+
if (run.error) out.error = clip(run.error, limits.errorChars);
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A mailbox item with its run cut down to a brief (a route's or a brief's own fields stay as they are). */
|
|
143
|
+
export function compactItem(item, limits = COORDINATION_SERVICE_LIMITS) {
|
|
144
|
+
if (!isObject(item)) return {};
|
|
145
|
+
const out = { ...item };
|
|
146
|
+
if (isObject(item.run)) {
|
|
147
|
+
// The task the item's turn worked for is read from the run before its turns are left out.
|
|
148
|
+
if (out.taskId === undefined) {
|
|
149
|
+
const turn = Number(item.turn);
|
|
150
|
+
const record = Number.isFinite(turn) && Array.isArray(item.run.turns) ? item.run.turns.find((row) => row?.n === turn) : null;
|
|
151
|
+
out.taskId = record?.taskId || item.run.taskId || null;
|
|
152
|
+
}
|
|
153
|
+
out.run = runBrief(item.run, limits);
|
|
154
|
+
}
|
|
155
|
+
if (typeof item.summary === 'string') out.summary = clip(item.summary, limits.summaryChars);
|
|
156
|
+
if (typeof item.question === 'string') out.question = clip(item.question, limits.questionChars);
|
|
157
|
+
if (Array.isArray(item.files)) out.files = item.files.slice(0, limits.files);
|
|
158
|
+
if (Array.isArray(item.follow_ups)) out.follow_ups = item.follow_ups.slice(0, limits.followUps);
|
|
159
|
+
if (Array.isArray(item.media)) out.media = item.media.slice(0, limits.media);
|
|
160
|
+
delete out.at;
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The id a run event is stored under: the same for the same event however often it is recorded (the dispatcher in
|
|
166
|
+
* the step that changed the run, the runtime when it hears of it), so the second append stores nothing.
|
|
167
|
+
* A turn's result and its question are named by the turn; a relayed request by its request id; everything else by
|
|
168
|
+
* the run's version and time of that change. null when the payload carries nothing that could name it.
|
|
169
|
+
*/
|
|
170
|
+
export function runEventId(payload) {
|
|
171
|
+
const run = payload?.run;
|
|
172
|
+
const reason = String(payload?.reason || '');
|
|
173
|
+
if (!run?.runId || !reason) return null;
|
|
174
|
+
const base = `run:${run.runId}`;
|
|
175
|
+
const requestId = payload.request?.requestId;
|
|
176
|
+
if ((reason === 'needs_input' || reason === 'permission_request') && requestId) return `${base}:request:${requestId}`;
|
|
177
|
+
const turn = Number(payload.turn);
|
|
178
|
+
if (Number.isInteger(turn) && turn > 0) {
|
|
179
|
+
if (reason === 'turn_completed') return `${base}:turn:${turn}:result`;
|
|
180
|
+
if (reason === 'needs_input') return `${base}:turn:${turn}:needs_input`;
|
|
181
|
+
}
|
|
182
|
+
const version = Number(run.version);
|
|
183
|
+
if (!Number.isFinite(version) || !run.updatedAt) return null;
|
|
184
|
+
const id = `${base}:${reason}:v${version}:${run.updatedAt}`;
|
|
185
|
+
return id.length > COORDINATION_LIMITS.id ? null : id;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** What a run event carries: the mailbox item of that reason, as the brain will read it. */
|
|
189
|
+
function runEventPayload(payload, spec, limits) {
|
|
190
|
+
const run = payload.run;
|
|
191
|
+
const reason = String(payload.reason);
|
|
192
|
+
const kind = spec?.item || reason;
|
|
193
|
+
const carriesResult = kind === 'result' || kind === 'needs_input';
|
|
194
|
+
const result = isObject(run.lastResult) ? run.lastResult : null;
|
|
195
|
+
const turn = Number.isFinite(Number(payload.turn)) ? Number(payload.turn) : null;
|
|
196
|
+
const turnRecord = turn !== null && Array.isArray(run.turns) ? run.turns.find((row) => row?.n === turn) : null;
|
|
197
|
+
const item = {
|
|
198
|
+
kind, reason, run: runBrief(run, limits), turn,
|
|
199
|
+
taskId: turnRecord?.taskId || run.taskId || null,
|
|
200
|
+
summary: result?.summary ? clip(result.summary, limits.summaryChars) : null,
|
|
201
|
+
question: result?.question ? clip(result.question, limits.questionChars) : (payload.question ? clip(payload.question, limits.questionChars) : null),
|
|
202
|
+
files: Array.isArray(result?.files) ? result.files.slice(0, limits.files) : [],
|
|
203
|
+
follow_ups: Array.isArray(result?.follow_ups) ? result.follow_ups.slice(0, limits.followUps) : [],
|
|
204
|
+
request: payload.request || null,
|
|
205
|
+
error: run.error ? clip(run.error, limits.errorChars) : null,
|
|
206
|
+
text: payload.text ? clip(payload.text, limits.textChars) : null,
|
|
207
|
+
// Jev's reading of the result: a "done" its own output does not show, and a status read without a ## Result block.
|
|
208
|
+
unverified: carriesResult ? (result?.unverifiedClaim?.evidence || null) : null,
|
|
209
|
+
resultSource: carriesResult ? (result?.source || null) : null,
|
|
210
|
+
// Image / video creation: the files this turn generated ({ kind, path, url, mime, bytes }).
|
|
211
|
+
media: carriesResult && Array.isArray(result?.media) ? result.media.slice(0, limits.media) : [],
|
|
212
|
+
};
|
|
213
|
+
// Progress (a queued follow-up, a memory, a permission answered): the few words that say what moved.
|
|
214
|
+
for (const key of ['queued', 'position', 'memoryId', 'requestId', 'behavior', 'resolvedBy', 'routeId', 'childRunId', 'resumes', 'sinceMs']) {
|
|
215
|
+
if (payload[key] !== undefined && payload[key] !== null && typeof payload[key] !== 'object') item[key] = payload[key];
|
|
216
|
+
}
|
|
217
|
+
return item;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** An event as a wait returns it: enough to decide what to do next, with the seq to continue from. */
|
|
221
|
+
export function eventBrief(event) {
|
|
222
|
+
const payload = isObject(event?.payload) ? event.payload : {};
|
|
223
|
+
const out = { seq: event.seq, id: event.id, kind: event.kind, priority: event.priority, runId: event.runId ?? null, at: event.createdAt };
|
|
224
|
+
if (event.teamId) out.teamId = event.teamId;
|
|
225
|
+
for (const key of ['reason', 'turn', 'summary', 'question', 'error', 'text', 'from']) {
|
|
226
|
+
if (payload[key] !== undefined && payload[key] !== null && payload[key] !== '') out[key] = payload[key];
|
|
227
|
+
}
|
|
228
|
+
if (isObject(payload.run)) {
|
|
229
|
+
if (payload.run.state) out.state = payload.run.state;
|
|
230
|
+
if (payload.run.outcome) out.outcome = payload.run.outcome;
|
|
231
|
+
// Which agent says it (absent for a plain worker).
|
|
232
|
+
if (payload.run.agentRef) out.agentRef = payload.run.agentRef;
|
|
233
|
+
}
|
|
234
|
+
if (isObject(payload.request)) out.request = { requestId: payload.request.requestId ?? null, kind: payload.request.kind ?? null, toolName: payload.request.toolName ?? null };
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A mailbox event as the runtime composes a turn from it (the item, with the event it came from). */
|
|
239
|
+
function itemOf(event) {
|
|
240
|
+
const payload = isObject(event.payload) ? event.payload : {};
|
|
241
|
+
const item = { ...payload, eventId: event.id, seq: event.seq, eventKind: event.kind, priority: event.priority, at: event.createdAt };
|
|
242
|
+
if (!item.kind) item.kind = event.kind;
|
|
243
|
+
if (event.delivery?.merged) item.merged = event.delivery.merged;
|
|
244
|
+
if (event.delivery?.redelivered) item.redelivered = true;
|
|
245
|
+
return item;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param {object} [options]
|
|
250
|
+
* @param {object} [options.store] an open store (the service then never closes it unless `ownsStore`)
|
|
251
|
+
* @param {string} [options.path] the database file; `:memory:` for one that lives with the process
|
|
252
|
+
* @param {string} [options.dataDir] DATA_HOME/data: the file is `coordinationDbPath(dataDir)`
|
|
253
|
+
* @param {() => number} [options.now]
|
|
254
|
+
* @param {(tag: string, detail: any) => void} [options.log]
|
|
255
|
+
* @param {object} [options.limits] overrides of COORDINATION_SERVICE_LIMITS
|
|
256
|
+
* @param {boolean} [options.autoPrune] drop settled old events every few hours (default: only for a file)
|
|
257
|
+
* With neither `store`, `path` nor `dataDir` the store is in memory: nothing survives the process (tests, and a
|
|
258
|
+
* dispatcher or runtime made without a service).
|
|
259
|
+
*/
|
|
260
|
+
export function createCoordinationService({ store: givenStore = null, path = null, dataDir = null, now = Date.now, log = () => {}, limits: limitOverrides = {}, autoPrune = null } = {}) {
|
|
261
|
+
const limits = { ...COORDINATION_SERVICE_LIMITS, ...(isObject(limitOverrides) ? limitOverrides : {}) };
|
|
262
|
+
const file = path || (dataDir ? coordinationDbPath(dataDir) : ':memory:');
|
|
263
|
+
let store = givenStore;
|
|
264
|
+
let degraded = null;
|
|
265
|
+
if (!store) {
|
|
266
|
+
try { store = createCoordinationStore({ path: file, now, log }); }
|
|
267
|
+
catch (error) {
|
|
268
|
+
// Without a mailbox the Assistant hears nothing of its workers: better one that forgets at a restart.
|
|
269
|
+
degraded = { code: error?.code || 'OPEN_FAILED', message: error?.message || String(error), path: file };
|
|
270
|
+
try { log('coordination:degraded', `the coordination store could not be opened (${degraded.message}); events are kept in memory only until the server restarts`); } catch { /* the logger must not stop the start */ }
|
|
271
|
+
store = createCoordinationStore({ path: ':memory:', now, log });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const durable = !degraded && (givenStore ? givenStore.path !== ':memory:' : file !== ':memory:');
|
|
275
|
+
let pruneTimer = null;
|
|
276
|
+
let closed = false;
|
|
277
|
+
|
|
278
|
+
const safely = (tag, fn, fallback = null) => {
|
|
279
|
+
try { return fn(); }
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (!closed) { try { log(tag, error?.message || String(error)); } catch { /* nothing to tell */ } }
|
|
282
|
+
return fallback;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// ── run events ─────────────────────────────────────────────────────────────
|
|
287
|
+
/**
|
|
288
|
+
* A dispatcher event (`{ type: 'assistant:dispatch', reason, run, … }`) into the log. Idempotent: recording the
|
|
289
|
+
* same event again stores nothing. Never throws (the run's state change must go on): a failure is logged and
|
|
290
|
+
* answered with null.
|
|
291
|
+
* @returns {{ id: string, seq: number, duplicate: boolean, kind: string, priority: string, delivered: boolean } | null}
|
|
292
|
+
*/
|
|
293
|
+
function recordDispatch(payload) {
|
|
294
|
+
const run = payload?.run;
|
|
295
|
+
const reason = String(payload?.reason || '');
|
|
296
|
+
if (!run?.runId || !reason || closed) return null;
|
|
297
|
+
const spec = RUN_EVENT_REASONS[reason] || { kind: K.RUN_PROGRESS, mailbox: false };
|
|
298
|
+
const sessionId = run.assistantSessionId ? String(run.assistantSessionId) : null;
|
|
299
|
+
let delivered = spec.mailbox === true && !!sessionId;
|
|
300
|
+
// A stop the brain asked for itself, or one that needs no reaction, is not news to it.
|
|
301
|
+
if (reason === 'stopped' && !MAILBOX_STOP_REASONS.has(run.completionReason)) delivered = false;
|
|
302
|
+
// needs_input already carries the question; its turn_completed twin would hand the brain the same event twice.
|
|
303
|
+
if (reason === 'turn_completed' && run.lastResult?.status === 'needs_input') delivered = false;
|
|
304
|
+
const priority = spec.priority || KIND_PRIORITY[spec.kind] || 'normal';
|
|
305
|
+
return safely('coordination:record-error', () => {
|
|
306
|
+
const out = store.append({
|
|
307
|
+
id: runEventId(payload) || undefined,
|
|
308
|
+
kind: spec.kind, priority, sessionId, runId: String(run.runId), teamId: run.teamId ? String(run.teamId) : null,
|
|
309
|
+
payload: runEventPayload(payload, spec, limits),
|
|
310
|
+
to: delivered ? [sessionRecipient(sessionId)] : [],
|
|
311
|
+
});
|
|
312
|
+
return { ...out, kind: spec.kind, priority, delivered };
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Events of runs after a position in the log, oldest first, as a wait returns them. Delivers and acknowledges
|
|
318
|
+
* nothing, so asking again from the same position gives the same events (a lost answer is simply asked again).
|
|
319
|
+
* @param {{ runIds: string[], afterSeq?: number, kinds?: string[]|null, limit?: number }} query
|
|
320
|
+
*/
|
|
321
|
+
function runEvents({ runIds, afterSeq = 0, kinds = null, limit = 100 } = {}) {
|
|
322
|
+
const ids = [...new Set((Array.isArray(runIds) ? runIds : [runIds]).filter(Boolean).map(String))];
|
|
323
|
+
if (!ids.length) return [];
|
|
324
|
+
const out = [];
|
|
325
|
+
// The log filter takes a bounded list: a large workflow is asked in parts and merged by seq.
|
|
326
|
+
for (let at = 0; at < ids.length; at += COORDINATION_LIMITS.runIds) {
|
|
327
|
+
out.push(...store.events({ runIds: ids.slice(at, at + COORDINATION_LIMITS.runIds), afterSeq, kinds: kinds && kinds.length ? kinds : null, limit }));
|
|
328
|
+
}
|
|
329
|
+
return out.sort((a, b) => a.seq - b.seq).slice(0, Math.max(1, Math.min(COORDINATION_LIMITS.readLimit, Number(limit) || 100))).map(eventBrief);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ── the mailbox of an Assistant session ────────────────────────────────────
|
|
333
|
+
const mailbox = Object.freeze({
|
|
334
|
+
/**
|
|
335
|
+
* Something the session's brain must hear that is not a run's own event: a memory reminder, a route card's
|
|
336
|
+
* outcome, the answers to its questions. `item.kind` is what the brain reads; it decides the event kind and
|
|
337
|
+
* priority unless `kind` / `priority` say otherwise.
|
|
338
|
+
* @returns {{ id: string, seq: number, duplicate: boolean, kind: string, priority: string }}
|
|
339
|
+
*/
|
|
340
|
+
post(sessionId, item, { id = null, kind = null, priority = null, runId = null, coalesceKey = null } = {}) {
|
|
341
|
+
const session = String(sessionId || '');
|
|
342
|
+
if (!session) throw new CoordinationError('FIELD_REQUIRED', 'sessionId is required.', { field: 'sessionId' });
|
|
343
|
+
const body = compactItem(item, limits);
|
|
344
|
+
const eventKind = kind || MAILBOX_ITEM_KINDS[body.kind] || SESSION_NOTICE_KIND;
|
|
345
|
+
const level = priority || ITEM_PRIORITY[body.kind] || KIND_PRIORITY[eventKind] || 'normal';
|
|
346
|
+
const run = runId || body.run?.runId || body.runId || null;
|
|
347
|
+
const out = store.append({
|
|
348
|
+
id: id || undefined, kind: eventKind, priority: level, sessionId: session, runId: run ? String(run) : null,
|
|
349
|
+
payload: body, coalesceKey: coalesceKey || undefined, to: [sessionRecipient(session)],
|
|
350
|
+
});
|
|
351
|
+
return { ...out, kind: eventKind, priority: level };
|
|
352
|
+
},
|
|
353
|
+
/**
|
|
354
|
+
* What the session has not been told, in the order to tell it: critical first, then the rest oldest first, with
|
|
355
|
+
* low-priority progress folded. At most `limit` items; `more` says how many stay for the next message. Handing
|
|
356
|
+
* them out acknowledges nothing: call `ack` once the turn that carries them was started.
|
|
357
|
+
* @returns {{ items: object[], more: number }}
|
|
358
|
+
*/
|
|
359
|
+
pending(sessionId, { limit = limits.mailboxItems, peek = false } = {}) {
|
|
360
|
+
const recipient = sessionRecipient(String(sessionId));
|
|
361
|
+
const max = Math.max(1, Math.min(COORDINATION_LIMITS.readLimit, Math.floor(Number(limit)) || limits.mailboxItems));
|
|
362
|
+
const events = store.pending(recipient, { limit: max, peek, coalesce: !peek });
|
|
363
|
+
const open = events.length < max ? events.length : store.openCount(recipient);
|
|
364
|
+
return { items: events.map(itemOf), more: Math.max(0, open - events.length) };
|
|
365
|
+
},
|
|
366
|
+
/** How many events the session has not been told (`priority` narrows it, e.g. 'critical'). */
|
|
367
|
+
count(sessionId, { priority = null } = {}) {
|
|
368
|
+
return store.openCount(sessionRecipient(String(sessionId)), priority ? { priority } : {});
|
|
369
|
+
},
|
|
370
|
+
/** The session's brain was handed these events (a turn that carries them started): never again. */
|
|
371
|
+
ack(sessionId, eventIds) {
|
|
372
|
+
return store.ack(sessionRecipient(String(sessionId)), eventIds);
|
|
373
|
+
},
|
|
374
|
+
/**
|
|
375
|
+
* Settle open events without telling the brain: the run they speak of was removed, its request was answered
|
|
376
|
+
* elsewhere, its result was read through agent_wait. `match(item)` picks them. → how many were settled.
|
|
377
|
+
*/
|
|
378
|
+
discard(sessionId, match) {
|
|
379
|
+
const recipient = sessionRecipient(String(sessionId));
|
|
380
|
+
const ids = [];
|
|
381
|
+
// Looked at page by page from the oldest, so a long mailbox is searched whole.
|
|
382
|
+
let afterSeq = 0;
|
|
383
|
+
for (;;) {
|
|
384
|
+
const page = store.read({ recipient, afterSeq, limit: COORDINATION_LIMITS.readLimit, peek: true });
|
|
385
|
+
if (!page.length) break;
|
|
386
|
+
for (const event of page) { if (!match || match(itemOf(event))) ids.push(event.id); }
|
|
387
|
+
afterSeq = page[page.length - 1].seq;
|
|
388
|
+
if (page.length < COORDINATION_LIMITS.readLimit) break;
|
|
389
|
+
}
|
|
390
|
+
return ids.length ? store.ack(recipient, ids).acked : 0;
|
|
391
|
+
},
|
|
392
|
+
/** Every session that has something open (after a restart: whose brain still has to hear of it). */
|
|
393
|
+
sessions() {
|
|
394
|
+
return store.recipients({ prefix: SESSION_PREFIX }).map((row) => ({ sessionId: row.recipient.slice(SESSION_PREFIX.length), open: row.open, oldestSeq: row.oldestSeq }));
|
|
395
|
+
},
|
|
396
|
+
/**
|
|
397
|
+
* Be told when an event is addressed to a session (a wake-up after its append committed, in this process).
|
|
398
|
+
* `fn(sessionId, event)`. → stop listening.
|
|
399
|
+
*/
|
|
400
|
+
subscribe(fn) {
|
|
401
|
+
return store.subscribe(
|
|
402
|
+
(event, info) => info.recipients.some((recipient) => recipient.startsWith(SESSION_PREFIX)),
|
|
403
|
+
(event, info) => {
|
|
404
|
+
for (const recipient of info.recipients) {
|
|
405
|
+
if (recipient.startsWith(SESSION_PREFIX)) fn(recipient.slice(SESSION_PREFIX.length), event);
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
);
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// ── follow-ups for runs (the outbox) ───────────────────────────────────────
|
|
413
|
+
const followUpView = (row) => ({
|
|
414
|
+
id: row.id, runId: row.runId, kind: 'follow-up', text: row.text, origin: row.meta?.origin || 'assistant', taskId: row.meta?.taskId || null,
|
|
415
|
+
at: row.meta?.at || row.createdAt, attempts: row.attempts,
|
|
416
|
+
});
|
|
417
|
+
const followUps = Object.freeze({
|
|
418
|
+
/**
|
|
419
|
+
* Queue text for a run. It waits, in order, across restarts, until `markSent` says the run's provider got it.
|
|
420
|
+
* @throws {CoordinationError} `OUTBOX_FULL` (409) when the run already has `followUpsPerRun` waiting
|
|
421
|
+
* @returns {{ id: string, duplicate: boolean, position: number }}
|
|
422
|
+
*/
|
|
423
|
+
enqueue({ runId, text, sessionId = null, origin = 'assistant', taskId = null, at = null, id = null } = {}) {
|
|
424
|
+
const out = store.outbox.enqueue({
|
|
425
|
+
id: id || undefined, runId, text, sessionId: sessionId || null,
|
|
426
|
+
meta: { origin: String(origin || 'assistant'), taskId: taskId || null, at: at || new Date(now()).toISOString() },
|
|
427
|
+
maxQueued: limits.followUpsPerRun,
|
|
428
|
+
});
|
|
429
|
+
return { ...out, position: store.outbox.count(runId) };
|
|
430
|
+
},
|
|
431
|
+
/** The run's oldest follow-up that was not sent yet, or null. Taking it marks nothing. */
|
|
432
|
+
next(runId) {
|
|
433
|
+
const [row] = store.outbox.take(runId, { limit: 1 });
|
|
434
|
+
return row ? followUpView(row) : null;
|
|
435
|
+
},
|
|
436
|
+
/** These follow-ups were handed to their run's provider. */
|
|
437
|
+
markSent(ids) { return store.outbox.markSent(ids); },
|
|
438
|
+
count(runId) { return store.outbox.count(runId); },
|
|
439
|
+
/** The run ended, or was stopped, before it took them: they leave the queue. → the items, oldest first. */
|
|
440
|
+
cancel(runId, ids = null) { return store.outbox.cancel({ runId, ids }).cancelled.map(followUpView); },
|
|
441
|
+
/** The runs that have follow-ups waiting. */
|
|
442
|
+
runs() { return store.outbox.runs(); },
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// ── a team's channel ───────────────────────────────────────────────────────
|
|
446
|
+
function teamMembers(teamId) {
|
|
447
|
+
const state = store.journal.state(teamId);
|
|
448
|
+
return [...new Set(Object.values(state.slices).map((entry) => entry.runId).filter(Boolean))];
|
|
449
|
+
}
|
|
450
|
+
const team = Object.freeze({
|
|
451
|
+
recipient: teamMemberRecipient,
|
|
452
|
+
leadRecipient: teamRecipient,
|
|
453
|
+
/**
|
|
454
|
+
* The runs that work a team's slices now, by the journal (each slice's newest entry that names a run).
|
|
455
|
+
*/
|
|
456
|
+
members: teamMembers,
|
|
457
|
+
/**
|
|
458
|
+
* Say something on a team's channel.
|
|
459
|
+
* @param {object} message
|
|
460
|
+
* @param {string} message.teamId
|
|
461
|
+
* @param {string} [message.fromRunId] who says it (a member's run id; none: the lead)
|
|
462
|
+
* @param {'all'|'lead'|string|string[]} [message.to] 'all' (default): every other member and the lead; 'lead': the
|
|
463
|
+
* team's lead only; a run id or a list: those members
|
|
464
|
+
* @param {string[]} [message.members] the team's runs, when the caller knows them (default: the journal's)
|
|
465
|
+
* @param {string} [message.kind] default `team.message`
|
|
466
|
+
* @param {string} [message.text] at most 8000 characters
|
|
467
|
+
* @param {any} [message.payload] more than text (merged into the event's payload)
|
|
468
|
+
* @param {string} [message.id] the caller's own id (posting it again stores nothing)
|
|
469
|
+
* @returns {{ id: string, seq: number, duplicate: boolean, recipients: string[] }}
|
|
470
|
+
*/
|
|
471
|
+
post({ teamId, fromRunId = null, to = 'all', members = null, kind = K.TEAM_MESSAGE, text = null, payload = null, priority = null, id = null, sessionId = null } = {}) {
|
|
472
|
+
if (!teamId) throw new CoordinationError('FIELD_REQUIRED', 'teamId is required.', { field: 'teamId' });
|
|
473
|
+
if (text !== null && text !== undefined) {
|
|
474
|
+
if (typeof text !== 'string' || !text.trim()) throw new CoordinationError('FIELD_REQUIRED', 'text is required: what is said.', { field: 'text' });
|
|
475
|
+
if (text.length > limits.teamText) throw new CoordinationError('FIELD_INVALID', `text is at most ${limits.teamText} characters.`, { field: 'text' });
|
|
476
|
+
}
|
|
477
|
+
const from = fromRunId ? String(fromRunId) : null;
|
|
478
|
+
const known = (Array.isArray(members) ? members.map(String) : teamMembers(teamId)).filter((runId) => runId !== from);
|
|
479
|
+
let recipients;
|
|
480
|
+
if (to === 'lead') recipients = [teamRecipient(teamId)];
|
|
481
|
+
else if (to === 'all' || to === null || to === undefined) recipients = [...known.map((runId) => teamMemberRecipient(teamId, runId)), ...(from ? [teamRecipient(teamId)] : [])];
|
|
482
|
+
else recipients = (Array.isArray(to) ? to : [to]).map(String).filter((runId) => runId !== from).map((runId) => teamMemberRecipient(teamId, runId));
|
|
483
|
+
recipients = [...new Set(recipients)];
|
|
484
|
+
if (recipients.length > limits.teamRecipients) throw new CoordinationError('RECIPIENTS_TOO_MANY', `A team message reaches at most ${limits.teamRecipients} recipients.`, { field: 'to' });
|
|
485
|
+
const body = { ...(isObject(payload) ? payload : (payload === null || payload === undefined ? {} : { value: payload })), from: from || 'lead' };
|
|
486
|
+
if (typeof text === 'string') body.text = text;
|
|
487
|
+
const out = store.append({ id: id || undefined, kind, priority: priority || undefined, teamId: String(teamId), runId: from, sessionId: sessionId || null, payload: body, to: recipients });
|
|
488
|
+
return { ...out, recipients };
|
|
489
|
+
},
|
|
490
|
+
/**
|
|
491
|
+
* A member's messages on its team's channel after a position (default: its cursor), oldest first. Reading
|
|
492
|
+
* acknowledges nothing: an event comes back until `ack` names it.
|
|
493
|
+
* @param {{ teamId: string, runId?: string, afterSeq?: number, kinds?: string[], limit?: number, peek?: boolean }} query
|
|
494
|
+
* no `runId`: the lead's mailbox
|
|
495
|
+
*/
|
|
496
|
+
read({ teamId, runId = null, afterSeq = null, kinds = null, limit = null, peek = false } = {}) {
|
|
497
|
+
return store.read({ recipient: runId ? teamMemberRecipient(teamId, runId) : teamRecipient(teamId), afterSeq, kinds, limit, peek });
|
|
498
|
+
},
|
|
499
|
+
/** Wait until that mailbox has something, then read it (`timedOut: true` with no events after `timeoutMs`). */
|
|
500
|
+
wait({ teamId, runId = null, afterSeq = null, kinds = null, timeoutMs = undefined, limit = null, signal = null } = {}) {
|
|
501
|
+
return store.waitFor({ recipient: runId ? teamMemberRecipient(teamId, runId) : teamRecipient(teamId), afterSeq, kinds, timeoutMs, limit, signal });
|
|
502
|
+
},
|
|
503
|
+
/** The member dealt with these events (`eventIds`), or with everything up to a seq (`throughSeq`). */
|
|
504
|
+
ack({ teamId, runId = null, eventIds = null, throughSeq = null } = {}) {
|
|
505
|
+
const recipient = runId ? teamMemberRecipient(teamId, runId) : teamRecipient(teamId);
|
|
506
|
+
return throughSeq !== null && throughSeq !== undefined ? store.ackThrough(recipient, throughSeq) : store.ack(recipient, eventIds || []);
|
|
507
|
+
},
|
|
508
|
+
/** The channel itself: every event of the team after a position, whoever it was addressed to. Delivers nothing. */
|
|
509
|
+
log({ teamId, afterSeq = 0, kinds = null, limit = null } = {}) {
|
|
510
|
+
return store.events({ teamId, afterSeq, kinds, limit });
|
|
511
|
+
},
|
|
512
|
+
cursor({ teamId, runId = null } = {}) {
|
|
513
|
+
return store.cursor(runId ? teamMemberRecipient(teamId, runId) : teamRecipient(teamId));
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
// ── housekeeping ───────────────────────────────────────────────────────────
|
|
518
|
+
function prune() {
|
|
519
|
+
return safely('coordination:prune-error', () => store.prune({ olderThanMs: limits.pruneAfterMs }), { events: 0, claims: 0, outbox: 0 });
|
|
520
|
+
}
|
|
521
|
+
if (autoPrune === true || (autoPrune === null && durable)) {
|
|
522
|
+
pruneTimer = setInterval(prune, limits.pruneEveryMs);
|
|
523
|
+
pruneTimer.unref?.();
|
|
524
|
+
}
|
|
525
|
+
/** Stop: every wait is answered (`closed: true`) and the file is closed. What is open stays in it. Safe to call twice. */
|
|
526
|
+
function close() {
|
|
527
|
+
if (closed) return;
|
|
528
|
+
closed = true;
|
|
529
|
+
if (pruneTimer) { clearInterval(pruneTimer); pruneTimer = null; }
|
|
530
|
+
try { store.close(); } catch (error) { try { log('coordination:close-error', error?.message || String(error)); } catch { /* nothing to tell */ } }
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return Object.freeze({
|
|
534
|
+
store,
|
|
535
|
+
limits,
|
|
536
|
+
/** false: the store lives in memory (a test, or the file could not be opened: `degraded` says why). */
|
|
537
|
+
durable,
|
|
538
|
+
degraded,
|
|
539
|
+
recordDispatch, runEvents,
|
|
540
|
+
lastSeq: () => (closed ? 0 : store.lastSeq()),
|
|
541
|
+
mailbox, followUps, team,
|
|
542
|
+
prune, close,
|
|
543
|
+
stats: () => ({ ...store.stats(), durable, degraded }),
|
|
544
|
+
get closed() { return closed; },
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// ── the server's one service ─────────────────────────────────────────────────
|
|
549
|
+
// server.js makes one service on DATA_HOME/data/coordination.db and shares it here; a dispatcher or a runtime that
|
|
550
|
+
// is given none takes it, so both read and write the same store without it being passed through every call. A test
|
|
551
|
+
// shares nothing: each dispatcher and runtime then keeps a store of its own in memory.
|
|
552
|
+
let shared = null;
|
|
553
|
+
/** Make `service` the one a dispatcher and a runtime use when they are given none. → the service. */
|
|
554
|
+
export function shareCoordinationService(service) {
|
|
555
|
+
shared = service || null;
|
|
556
|
+
return service;
|
|
557
|
+
}
|
|
558
|
+
/** The shared service while it is open, else null. */
|
|
559
|
+
export function sharedCoordinationService() {
|
|
560
|
+
return shared && !shared.closed ? shared : null;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export { CoordinationError, EVENT_KINDS, KIND_PRIORITY, coordinationDbPath, runRecipient, sessionRecipient, teamRecipient };
|