mixdog 0.7.18 → 0.8.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/README.md +37 -331
- package/package.json +67 -99
- package/scripts/boot-smoke.mjs +94 -0
- package/scripts/build-tui.mjs +52 -0
- package/scripts/compact-smoke.mjs +199 -0
- package/scripts/lead-workflow-smoke.mjs +598 -0
- package/scripts/live-worker-smoke.mjs +239 -0
- package/scripts/output-style-smoke.mjs +101 -0
- package/scripts/session-context-bench.mjs +172 -0
- package/scripts/smoke-loop-report.mjs +221 -0
- package/scripts/smoke-loop.mjs +201 -0
- package/scripts/smoke.mjs +113 -0
- package/scripts/tool-failures.mjs +143 -0
- package/scripts/tool-smoke.mjs +452 -0
- package/src/agents/debugger/AGENT.md +3 -0
- package/src/agents/debugger/agent.json +6 -0
- package/src/agents/explore/AGENT.md +4 -0
- package/src/agents/explore/agent.json +6 -0
- package/src/agents/heavy-worker/AGENT.md +3 -0
- package/src/agents/heavy-worker/agent.json +6 -0
- package/src/agents/maintainer/AGENT.md +3 -0
- package/src/agents/maintainer/agent.json +6 -0
- package/src/agents/reviewer/AGENT.md +3 -0
- package/src/agents/reviewer/agent.json +6 -0
- package/src/agents/scheduler-task.md +3 -0
- package/src/agents/web-researcher/AGENT.md +3 -0
- package/src/agents/web-researcher/agent.json +6 -0
- package/src/agents/webhook-handler.md +3 -0
- package/src/agents/worker/AGENT.md +3 -0
- package/src/agents/worker/agent.json +6 -0
- package/src/app.mjs +90 -0
- package/src/cli.mjs +11 -0
- package/src/defaults/hidden-roles.json +72 -0
- package/src/defaults/mixdog-config.template.json +15 -0
- package/src/hooks/lib/permission-evaluator.cjs +488 -0
- package/src/hooks/lib/settings-loader.cjs +112 -0
- package/src/lib/keychain-cjs.cjs +332 -0
- package/src/lib/plugin-paths.cjs +28 -0
- package/src/lib/rules-builder.cjs +315 -0
- package/src/mixdog-session-runtime.mjs +3813 -0
- package/src/output-styles/default.md +38 -0
- package/src/output-styles/extreme-simple.md +17 -0
- package/src/output-styles/simple.md +17 -0
- package/src/repl.mjs +330 -0
- package/src/rules/bridge/00-common.md +5 -0
- package/src/rules/bridge/20-skip-protocol.md +11 -0
- package/src/rules/bridge/30-explorer.md +4 -0
- package/src/rules/bridge/40-cycle1-agent.md +28 -0
- package/src/rules/bridge/41-cycle2-agent.md +59 -0
- package/src/rules/lead/00-tool-lead.md +5 -0
- package/src/rules/lead/01-general.md +5 -0
- package/src/rules/lead/02-channels.md +3 -0
- package/src/rules/lead/04-workflow.md +12 -0
- package/src/rules/shared/00-language.md +3 -0
- package/src/rules/shared/01-tool.md +3 -0
- package/src/runtime/agent/orchestrator/bridge-trace.mjs +814 -0
- package/src/runtime/agent/orchestrator/cache-mtime.mjs +60 -0
- package/src/runtime/agent/orchestrator/config.mjs +446 -0
- package/src/runtime/agent/orchestrator/context/collect.mjs +796 -0
- package/src/runtime/agent/orchestrator/dispatch-persist.mjs +417 -0
- package/src/runtime/agent/orchestrator/internal-roles.mjs +188 -0
- package/src/runtime/agent/orchestrator/internal-tools.mjs +88 -0
- package/src/runtime/agent/orchestrator/mcp/client.mjs +345 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +2104 -0
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +784 -0
- package/src/runtime/agent/orchestrator/providers/api-usage.mjs +341 -0
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +1679 -0
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +959 -0
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +213 -0
- package/src/runtime/agent/orchestrator/providers/model-cache.mjs +38 -0
- package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +471 -0
- package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +615 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +808 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +1719 -0
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +2587 -0
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +1953 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +136 -0
- package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +317 -0
- package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +109 -0
- package/src/runtime/agent/orchestrator/providers/registry.mjs +247 -0
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +332 -0
- package/src/runtime/agent/orchestrator/providers/statusline-route-meta.mjs +11 -0
- package/src/runtime/agent/orchestrator/providers/trace-utils.mjs +50 -0
- package/src/runtime/agent/orchestrator/session/cache/post-edit-marks.mjs +42 -0
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +142 -0
- package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +318 -0
- package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +367 -0
- package/src/runtime/agent/orchestrator/session/compact.mjs +882 -0
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +233 -0
- package/src/runtime/agent/orchestrator/session/loop.mjs +2269 -0
- package/src/runtime/agent/orchestrator/session/manager.mjs +2972 -0
- package/src/runtime/agent/orchestrator/session/result-classification.mjs +65 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +870 -0
- package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +166 -0
- package/src/runtime/agent/orchestrator/smart-bridge/bridge-llm.mjs +339 -0
- package/src/runtime/agent/orchestrator/smart-bridge/cache-strategy.mjs +419 -0
- package/src/runtime/agent/orchestrator/stall-policy.mjs +227 -0
- package/src/runtime/agent/orchestrator/tool-loop-guard.mjs +235 -0
- package/src/runtime/agent/orchestrator/tools/bash-session.mjs +723 -0
- package/src/runtime/agent/orchestrator/tools/builtin/advisory-lock.mjs +171 -0
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +389 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +637 -0
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +165 -0
- package/src/runtime/agent/orchestrator/tools/builtin/fuzzy-match.mjs +104 -0
- package/src/runtime/agent/orchestrator/tools/builtin/glob-walk.mjs +194 -0
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +596 -0
- package/src/runtime/agent/orchestrator/tools/builtin/native-edit-runner.mjs +110 -0
- package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +153 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +118 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-open.mjs +189 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-tool.mjs +731 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +168 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +602 -0
- package/src/runtime/agent/orchestrator/tools/builtin/rg-runner.mjs +465 -0
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +160 -0
- package/src/runtime/agent/orchestrator/tools/builtin/search-tool.mjs +982 -0
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +1087 -0
- package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +231 -0
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +223 -0
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +478 -0
- package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +24 -0
- package/src/runtime/agent/orchestrator/tools/code-graph.mjs +4102 -0
- package/src/runtime/agent/orchestrator/tools/destructive-warning.mjs +323 -0
- package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.mjs +154 -0
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +26 -0
- package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +143 -0
- package/src/runtime/agent/orchestrator/tools/patch-tool-defs.mjs +18 -0
- package/src/runtime/agent/orchestrator/tools/patch.mjs +2772 -0
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +114 -0
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +880 -0
- package/src/runtime/agent/orchestrator/tools/shell-snapshot.mjs +312 -0
- package/src/runtime/channels/backends/discord.mjs +781 -0
- package/src/runtime/channels/data/voice-runtime-manifest.json +138 -0
- package/src/runtime/channels/index.mjs +3309 -0
- package/src/runtime/channels/lib/config.mjs +285 -0
- package/src/runtime/channels/lib/drop-trace.mjs +71 -0
- package/src/runtime/channels/lib/event-pipeline.mjs +81 -0
- package/src/runtime/channels/lib/holidays.mjs +138 -0
- package/src/runtime/channels/lib/hook-pipe-server.mjs +671 -0
- package/src/runtime/channels/lib/output-forwarder.mjs +765 -0
- package/src/runtime/channels/lib/runtime-paths.mjs +497 -0
- package/src/runtime/channels/lib/scheduler.mjs +710 -0
- package/src/runtime/channels/lib/session-discovery.mjs +102 -0
- package/src/runtime/channels/lib/state-file.mjs +68 -0
- package/src/runtime/channels/lib/status-snapshot.mjs +224 -0
- package/src/runtime/channels/lib/tool-format.mjs +122 -0
- package/src/runtime/channels/lib/transcript-discovery.mjs +195 -0
- package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +734 -0
- package/src/runtime/channels/lib/webhook.mjs +1288 -0
- package/src/runtime/channels/tool-defs.mjs +177 -0
- package/src/runtime/lib/keychain-cjs.cjs +289 -0
- package/src/runtime/memory/data/runtime-manifest.json +40 -0
- package/src/runtime/memory/index.mjs +3706 -0
- package/src/runtime/memory/lib/core-memory-store.mjs +336 -0
- package/src/runtime/memory/lib/embedding-provider.mjs +275 -0
- package/src/runtime/memory/lib/embedding-worker.mjs +331 -0
- package/src/runtime/memory/lib/memory-cycle-requests.mjs +276 -0
- package/src/runtime/memory/lib/memory-cycle1.mjs +783 -0
- package/src/runtime/memory/lib/memory-cycle2.mjs +1389 -0
- package/src/runtime/memory/lib/memory-cycle3.mjs +646 -0
- package/src/runtime/memory/lib/memory-embed.mjs +300 -0
- package/src/runtime/memory/lib/memory-ops-policy.mjs +149 -0
- package/src/runtime/memory/lib/memory-recall-store.mjs +644 -0
- package/src/runtime/memory/lib/memory.mjs +418 -0
- package/src/runtime/memory/lib/pg/adapter.mjs +328 -0
- package/src/runtime/memory/lib/pg/process.mjs +366 -0
- package/src/runtime/memory/lib/pg/supervisor.mjs +495 -0
- package/src/runtime/memory/lib/runtime-fetcher.mjs +464 -0
- package/src/runtime/memory/lib/trace-store.mjs +734 -0
- package/src/runtime/memory/tool-defs.mjs +79 -0
- package/src/runtime/search/index.mjs +925 -0
- package/src/runtime/search/lib/config.mjs +61 -0
- package/src/runtime/search/lib/web-tools.mjs +1278 -0
- package/src/runtime/search/tool-defs.mjs +64 -0
- package/src/runtime/shared/atomic-file.mjs +435 -0
- package/src/runtime/shared/background-tasks.mjs +376 -0
- package/src/runtime/shared/child-guardian.mjs +98 -0
- package/src/runtime/shared/config.mjs +393 -0
- package/src/runtime/shared/err-text.mjs +121 -0
- package/src/runtime/shared/launcher-control.mjs +259 -0
- package/src/runtime/shared/llm/http-agent.mjs +129 -0
- package/src/runtime/shared/open-url.mjs +37 -0
- package/src/runtime/shared/plugin-paths.mjs +25 -0
- package/src/runtime/shared/process-shutdown.mjs +147 -0
- package/src/runtime/shared/schedules-store.mjs +70 -0
- package/src/runtime/shared/tool-execution-contract.mjs +104 -0
- package/src/runtime/shared/tool-surface.mjs +947 -0
- package/src/runtime/shared/user-cwd.mjs +221 -0
- package/src/runtime/shared/user-data-guard.mjs +232 -0
- package/src/runtime/shared/workspace-router.mjs +259 -0
- package/src/standalone/bridge-tool.mjs +1414 -0
- package/src/standalone/channel-admin.mjs +366 -0
- package/src/standalone/channel-worker-preload.cjs +3 -0
- package/src/standalone/channel-worker.mjs +353 -0
- package/src/standalone/explore-tool.mjs +233 -0
- package/src/standalone/hook-bus.mjs +246 -0
- package/src/standalone/plugin-admin.mjs +247 -0
- package/src/standalone/provider-admin.mjs +338 -0
- package/src/standalone/seeds.mjs +94 -0
- package/src/standalone/usage-dashboard.mjs +510 -0
- package/src/tui/App.jsx +5446 -0
- package/src/tui/components/AnsiText.jsx +199 -0
- package/src/tui/components/ContextPanel.jsx +265 -0
- package/src/tui/components/Markdown.jsx +205 -0
- package/src/tui/components/MarkdownTable.jsx +204 -0
- package/src/tui/components/Message.jsx +103 -0
- package/src/tui/components/Picker.jsx +317 -0
- package/src/tui/components/PromptInput.jsx +584 -0
- package/src/tui/components/QueuedCommands.jsx +47 -0
- package/src/tui/components/SlashCommandPalette.jsx +114 -0
- package/src/tui/components/Spinner.jsx +317 -0
- package/src/tui/components/StatusLine.jsx +87 -0
- package/src/tui/components/TextEntryPanel.jsx +323 -0
- package/src/tui/components/ToolExecution.jsx +791 -0
- package/src/tui/components/TurnDone.jsx +78 -0
- package/src/tui/components/UsagePanel.jsx +331 -0
- package/src/tui/dist/index.mjs +12420 -0
- package/src/tui/engine.mjs +2410 -0
- package/src/tui/figures.mjs +50 -0
- package/src/tui/hooks/useEngine.mjs +16 -0
- package/src/tui/index.jsx +254 -0
- package/src/tui/input-editing.mjs +242 -0
- package/src/tui/markdown/format-token.mjs +194 -0
- package/src/tui/paste-attachments.mjs +198 -0
- package/src/tui/runtime/shared/process-shutdown.mjs +1 -0
- package/src/tui/spinner-verbs.mjs +45 -0
- package/src/tui/theme.mjs +67 -0
- package/src/tui/time-format.mjs +53 -0
- package/src/ui/ansi.mjs +115 -0
- package/src/ui/markdown.mjs +195 -0
- package/src/ui/statusline.mjs +730 -0
- package/src/ui/tool-card.mjs +99 -0
- package/src/vendor/statusline/bin/statusline-lib.mjs +805 -0
- package/src/vendor/statusline/bin/statusline-route.mjs +596 -0
- package/src/vendor/statusline/scripts/lib/gateway-settings.mjs +285 -0
- package/src/vendor/statusline/src/gateway/claude-current.mjs +320 -0
- package/src/vendor/statusline/src/gateway/route-meta.mjs +753 -0
- package/src/vendor/statusline/src/gateway/session-routes.mjs +244 -0
- package/src/workflows/default/WORKFLOW.md +7 -0
- package/src/workflows/default/workflow.json +14 -0
- package/vendor/ink/build/ansi-tokenizer.d.ts +38 -0
- package/vendor/ink/build/ansi-tokenizer.js +316 -0
- package/vendor/ink/build/ansi-tokenizer.js.map +1 -0
- package/vendor/ink/build/colorize.d.ts +3 -0
- package/vendor/ink/build/colorize.js +48 -0
- package/vendor/ink/build/colorize.js.map +1 -0
- package/vendor/ink/build/components/AccessibilityContext.d.ts +3 -0
- package/vendor/ink/build/components/AccessibilityContext.js +5 -0
- package/vendor/ink/build/components/AccessibilityContext.js.map +1 -0
- package/vendor/ink/build/components/AnimationContext.d.ts +9 -0
- package/vendor/ink/build/components/AnimationContext.js +13 -0
- package/vendor/ink/build/components/AnimationContext.js.map +1 -0
- package/vendor/ink/build/components/App.d.ts +24 -0
- package/vendor/ink/build/components/App.js +554 -0
- package/vendor/ink/build/components/App.js.map +1 -0
- package/vendor/ink/build/components/AppContext.d.ts +80 -0
- package/vendor/ink/build/components/AppContext.js +25 -0
- package/vendor/ink/build/components/AppContext.js.map +1 -0
- package/vendor/ink/build/components/BackgroundContext.d.ts +4 -0
- package/vendor/ink/build/components/BackgroundContext.js +3 -0
- package/vendor/ink/build/components/BackgroundContext.js.map +1 -0
- package/vendor/ink/build/components/Box.d.ts +130 -0
- package/vendor/ink/build/components/Box.js +34 -0
- package/vendor/ink/build/components/Box.js.map +1 -0
- package/vendor/ink/build/components/CursorContext.d.ts +11 -0
- package/vendor/ink/build/components/CursorContext.js +8 -0
- package/vendor/ink/build/components/CursorContext.js.map +1 -0
- package/vendor/ink/build/components/ErrorBoundary.d.ts +18 -0
- package/vendor/ink/build/components/ErrorBoundary.js +23 -0
- package/vendor/ink/build/components/ErrorBoundary.js.map +1 -0
- package/vendor/ink/build/components/ErrorOverview.d.ts +6 -0
- package/vendor/ink/build/components/ErrorOverview.js +90 -0
- package/vendor/ink/build/components/ErrorOverview.js.map +1 -0
- package/vendor/ink/build/components/FocusContext.d.ts +16 -0
- package/vendor/ink/build/components/FocusContext.js +17 -0
- package/vendor/ink/build/components/FocusContext.js.map +1 -0
- package/vendor/ink/build/components/Newline.d.ts +13 -0
- package/vendor/ink/build/components/Newline.js +8 -0
- package/vendor/ink/build/components/Newline.js.map +1 -0
- package/vendor/ink/build/components/Spacer.d.ts +7 -0
- package/vendor/ink/build/components/Spacer.js +11 -0
- package/vendor/ink/build/components/Spacer.js.map +1 -0
- package/vendor/ink/build/components/Static.d.ts +24 -0
- package/vendor/ink/build/components/Static.js +28 -0
- package/vendor/ink/build/components/Static.js.map +1 -0
- package/vendor/ink/build/components/StderrContext.d.ts +15 -0
- package/vendor/ink/build/components/StderrContext.js +13 -0
- package/vendor/ink/build/components/StderrContext.js.map +1 -0
- package/vendor/ink/build/components/StdinContext.d.ts +28 -0
- package/vendor/ink/build/components/StdinContext.js +20 -0
- package/vendor/ink/build/components/StdinContext.js.map +1 -0
- package/vendor/ink/build/components/StdoutContext.d.ts +15 -0
- package/vendor/ink/build/components/StdoutContext.js +13 -0
- package/vendor/ink/build/components/StdoutContext.js.map +1 -0
- package/vendor/ink/build/components/Text.d.ts +55 -0
- package/vendor/ink/build/components/Text.js +50 -0
- package/vendor/ink/build/components/Text.js.map +1 -0
- package/vendor/ink/build/components/Transform.d.ts +16 -0
- package/vendor/ink/build/components/Transform.js +15 -0
- package/vendor/ink/build/components/Transform.js.map +1 -0
- package/vendor/ink/build/cursor-helpers.d.ts +39 -0
- package/vendor/ink/build/cursor-helpers.js +62 -0
- package/vendor/ink/build/cursor-helpers.js.map +1 -0
- package/vendor/ink/build/devtools-window-polyfill.d.ts +1 -0
- package/vendor/ink/build/devtools-window-polyfill.js +68 -0
- package/vendor/ink/build/devtools-window-polyfill.js.map +1 -0
- package/vendor/ink/build/devtools.d.ts +1 -0
- package/vendor/ink/build/devtools.js +36 -0
- package/vendor/ink/build/devtools.js.map +1 -0
- package/vendor/ink/build/dom.d.ts +62 -0
- package/vendor/ink/build/dom.js +143 -0
- package/vendor/ink/build/dom.js.map +1 -0
- package/vendor/ink/build/get-max-width.d.ts +3 -0
- package/vendor/ink/build/get-max-width.js +10 -0
- package/vendor/ink/build/get-max-width.js.map +1 -0
- package/vendor/ink/build/hooks/use-animation.d.ts +49 -0
- package/vendor/ink/build/hooks/use-animation.js +87 -0
- package/vendor/ink/build/hooks/use-animation.js.map +1 -0
- package/vendor/ink/build/hooks/use-app.d.ts +5 -0
- package/vendor/ink/build/hooks/use-app.js +8 -0
- package/vendor/ink/build/hooks/use-app.js.map +1 -0
- package/vendor/ink/build/hooks/use-box-metrics.d.ts +59 -0
- package/vendor/ink/build/hooks/use-box-metrics.js +81 -0
- package/vendor/ink/build/hooks/use-box-metrics.js.map +1 -0
- package/vendor/ink/build/hooks/use-cursor.d.ts +12 -0
- package/vendor/ink/build/hooks/use-cursor.js +29 -0
- package/vendor/ink/build/hooks/use-cursor.js.map +1 -0
- package/vendor/ink/build/hooks/use-focus-manager.d.ts +43 -0
- package/vendor/ink/build/hooks/use-focus-manager.js +18 -0
- package/vendor/ink/build/hooks/use-focus-manager.js.map +1 -0
- package/vendor/ink/build/hooks/use-focus.d.ts +30 -0
- package/vendor/ink/build/hooks/use-focus.js +43 -0
- package/vendor/ink/build/hooks/use-focus.js.map +1 -0
- package/vendor/ink/build/hooks/use-input.d.ts +132 -0
- package/vendor/ink/build/hooks/use-input.js +126 -0
- package/vendor/ink/build/hooks/use-input.js.map +1 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.d.ts +6 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js +12 -0
- package/vendor/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
- package/vendor/ink/build/hooks/use-paste.d.ts +35 -0
- package/vendor/ink/build/hooks/use-paste.js +62 -0
- package/vendor/ink/build/hooks/use-paste.js.map +1 -0
- package/vendor/ink/build/hooks/use-stderr.d.ts +5 -0
- package/vendor/ink/build/hooks/use-stderr.js +8 -0
- package/vendor/ink/build/hooks/use-stderr.js.map +1 -0
- package/vendor/ink/build/hooks/use-stdin.d.ts +7 -0
- package/vendor/ink/build/hooks/use-stdin.js +9 -0
- package/vendor/ink/build/hooks/use-stdin.js.map +1 -0
- package/vendor/ink/build/hooks/use-stdout.d.ts +5 -0
- package/vendor/ink/build/hooks/use-stdout.js +8 -0
- package/vendor/ink/build/hooks/use-stdout.js.map +1 -0
- package/vendor/ink/build/hooks/use-window-size.d.ts +18 -0
- package/vendor/ink/build/hooks/use-window-size.js +22 -0
- package/vendor/ink/build/hooks/use-window-size.js.map +1 -0
- package/vendor/ink/build/index.d.ts +42 -0
- package/vendor/ink/build/index.js +24 -0
- package/vendor/ink/build/index.js.map +1 -0
- package/vendor/ink/build/ink.d.ts +146 -0
- package/vendor/ink/build/ink.js +1022 -0
- package/vendor/ink/build/ink.js.map +1 -0
- package/vendor/ink/build/input-parser.d.ts +10 -0
- package/vendor/ink/build/input-parser.js +194 -0
- package/vendor/ink/build/input-parser.js.map +1 -0
- package/vendor/ink/build/instances.d.ts +3 -0
- package/vendor/ink/build/instances.js +8 -0
- package/vendor/ink/build/instances.js.map +1 -0
- package/vendor/ink/build/kitty-keyboard.d.ts +23 -0
- package/vendor/ink/build/kitty-keyboard.js +32 -0
- package/vendor/ink/build/kitty-keyboard.js.map +1 -0
- package/vendor/ink/build/log-update.d.ts +20 -0
- package/vendor/ink/build/log-update.js +261 -0
- package/vendor/ink/build/log-update.js.map +1 -0
- package/vendor/ink/build/measure-element.d.ts +20 -0
- package/vendor/ink/build/measure-element.js +13 -0
- package/vendor/ink/build/measure-element.js.map +1 -0
- package/vendor/ink/build/measure-text.d.ts +6 -0
- package/vendor/ink/build/measure-text.js +21 -0
- package/vendor/ink/build/measure-text.js.map +1 -0
- package/vendor/ink/build/output.d.ts +35 -0
- package/vendor/ink/build/output.js +328 -0
- package/vendor/ink/build/output.js.map +1 -0
- package/vendor/ink/build/parse-keypress.d.ts +20 -0
- package/vendor/ink/build/parse-keypress.js +495 -0
- package/vendor/ink/build/parse-keypress.js.map +1 -0
- package/vendor/ink/build/reconciler.d.ts +4 -0
- package/vendor/ink/build/reconciler.js +306 -0
- package/vendor/ink/build/reconciler.js.map +1 -0
- package/vendor/ink/build/render-background.d.ts +4 -0
- package/vendor/ink/build/render-background.js +25 -0
- package/vendor/ink/build/render-background.js.map +1 -0
- package/vendor/ink/build/render-border.d.ts +4 -0
- package/vendor/ink/build/render-border.js +84 -0
- package/vendor/ink/build/render-border.js.map +1 -0
- package/vendor/ink/build/render-node-to-output.d.ts +14 -0
- package/vendor/ink/build/render-node-to-output.js +162 -0
- package/vendor/ink/build/render-node-to-output.js.map +1 -0
- package/vendor/ink/build/render-to-string.d.ts +38 -0
- package/vendor/ink/build/render-to-string.js +116 -0
- package/vendor/ink/build/render-to-string.js.map +1 -0
- package/vendor/ink/build/render.d.ts +176 -0
- package/vendor/ink/build/render.js +71 -0
- package/vendor/ink/build/render.js.map +1 -0
- package/vendor/ink/build/renderer.d.ts +8 -0
- package/vendor/ink/build/renderer.js +64 -0
- package/vendor/ink/build/renderer.js.map +1 -0
- package/vendor/ink/build/sanitize-ansi.d.ts +2 -0
- package/vendor/ink/build/sanitize-ansi.js +27 -0
- package/vendor/ink/build/sanitize-ansi.js.map +1 -0
- package/vendor/ink/build/squash-text-nodes.d.ts +3 -0
- package/vendor/ink/build/squash-text-nodes.js +36 -0
- package/vendor/ink/build/squash-text-nodes.js.map +1 -0
- package/vendor/ink/build/styles.d.ts +302 -0
- package/vendor/ink/build/styles.js +303 -0
- package/vendor/ink/build/styles.js.map +1 -0
- package/vendor/ink/build/utils.d.ts +9 -0
- package/vendor/ink/build/utils.js +19 -0
- package/vendor/ink/build/utils.js.map +1 -0
- package/vendor/ink/build/wrap-text.d.ts +3 -0
- package/vendor/ink/build/wrap-text.js +38 -0
- package/vendor/ink/build/wrap-text.js.map +1 -0
- package/vendor/ink/build/write-synchronized.d.ts +4 -0
- package/vendor/ink/build/write-synchronized.js +9 -0
- package/vendor/ink/build/write-synchronized.js.map +1 -0
- package/vendor/ink/license +10 -0
- package/vendor/ink/package.json +137 -0
- package/.claude-plugin/marketplace.json +0 -34
- package/.claude-plugin/plugin.json +0 -20
- package/.gitattributes +0 -34
- package/.mcp.json +0 -14
- package/ARCHITECTURE.md +0 -77
- package/CHANGELOG.md +0 -30
- package/CONTRIBUTING.md +0 -45
- package/DATA-FLOW.md +0 -79
- package/LICENSE +0 -21
- package/SECURITY.md +0 -138
- package/UNINSTALL.md +0 -115
- package/agents/maintenance.md +0 -5
- package/agents/memory-classification.md +0 -30
- package/agents/scheduler-task.md +0 -18
- package/agents/webhook-handler.md +0 -27
- package/agents/worker.md +0 -24
- package/bin/bridge +0 -133
- package/bin/statusline-launcher.mjs +0 -82
- package/bin/statusline-lib.mjs +0 -581
- package/bin/statusline-route.mjs +0 -273
- package/bin/statusline.mjs +0 -638
- package/bun.lock +0 -927
- package/commands/config.md +0 -16
- package/commands/doctor.md +0 -13
- package/commands/model.md +0 -61
- package/commands/setup.md +0 -17
- package/defaults/hidden-roles.json +0 -68
- package/defaults/memory-chunk-prompt.md +0 -63
- package/defaults/mixdog-config.template.json +0 -27
- package/defaults/user-workflow.json +0 -8
- package/defaults/user-workflow.md +0 -17
- package/hooks/hooks.json +0 -73
- package/hooks/lib/active-instance.cjs +0 -77
- package/hooks/lib/permission-evaluator.cjs +0 -411
- package/hooks/lib/permission-route.cjs +0 -63
- package/hooks/lib/settings-loader.cjs +0 -117
- package/hooks/post-tool-use.cjs +0 -84
- package/hooks/pre-mcp-sandbox.cjs +0 -158
- package/hooks/pre-tool-subagent.cjs +0 -258
- package/hooks/session-start.cjs +0 -1493
- package/hooks/shim-launcher.cjs +0 -65
- package/hooks/turn-timer.cjs +0 -82
- package/lib/claude-md-writer.cjs +0 -386
- package/lib/keychain-cjs.cjs +0 -290
- package/lib/plugin-paths.cjs +0 -69
- package/lib/rules-builder.cjs +0 -241
- package/native/README.md +0 -117
- package/native/prebuilt/linux-aarch64/mixdog-shim +0 -0
- package/native/prebuilt/linux-x86_64/mixdog-shim +0 -0
- package/native/prebuilt/macos-aarch64/mixdog-shim +0 -0
- package/native/prebuilt/macos-x86_64/mixdog-shim +0 -0
- package/native/prebuilt/windows-x86_64/mixdog-shim.exe +0 -0
- package/prompts/code-review.txt +0 -16
- package/prompts/security-audit.txt +0 -17
- package/rules/bridge/00-common.md +0 -39
- package/rules/bridge/20-skip-protocol.md +0 -18
- package/rules/bridge/30-explorer.md +0 -33
- package/rules/bridge/40-cycle1-agent.md +0 -52
- package/rules/bridge/41-cycle2-agent.md +0 -62
- package/rules/lead/00-tool-lead.md +0 -61
- package/rules/lead/01-general.md +0 -26
- package/rules/lead/02-channels.md +0 -49
- package/rules/lead/03-team.md +0 -27
- package/rules/lead/04-workflow.md +0 -20
- package/rules/shared/00-language.md +0 -14
- package/rules/shared/01-tool.md +0 -138
- package/scripts/bootstrap.mjs +0 -130
- package/scripts/bridge-unify-smoke.mjs +0 -308
- package/scripts/build-runtime-linux.sh +0 -348
- package/scripts/build-runtime-macos.sh +0 -217
- package/scripts/build-runtime-windows.ps1 +0 -242
- package/scripts/builtin-utils-smoke.mjs +0 -398
- package/scripts/bump.mjs +0 -80
- package/scripts/check-json.mjs +0 -45
- package/scripts/check-syntax-changed.mjs +0 -102
- package/scripts/check-syntax.mjs +0 -58
- package/scripts/code-graph-batch.test.mjs +0 -33
- package/scripts/config-preserve-smoke.mjs +0 -180
- package/scripts/doctor.mjs +0 -489
- package/scripts/edit-normalize-fuzz.mjs +0 -130
- package/scripts/edit-normalize-smoke.mjs +0 -401
- package/scripts/edit-operation-smoke.mjs +0 -369
- package/scripts/edit2-smoke.mjs +0 -63
- package/scripts/ensure-deps.mjs +0 -259
- package/scripts/fuzzy-e2e.mjs +0 -28
- package/scripts/fuzzy-smoke.mjs +0 -26
- package/scripts/gateway-model.mjs +0 -596
- package/scripts/generate-runtime-manifest.mjs +0 -166
- package/scripts/guard-smoke.mjs +0 -66
- package/scripts/hidden-role-schema-smoke.mjs +0 -162
- package/scripts/hook-routing-smoke.mjs +0 -29
- package/scripts/inject-input.ps1 +0 -204
- package/scripts/io-complex-smoke.mjs +0 -667
- package/scripts/io-explore-bench.mjs +0 -424
- package/scripts/io-guardrails-smoke.mjs +0 -205
- package/scripts/io-mini-bench-baseline.json +0 -11
- package/scripts/io-mini-bench.mjs +0 -216
- package/scripts/io-route-harness.mjs +0 -933
- package/scripts/io-telemetry-report.mjs +0 -691
- package/scripts/lib/gateway-inventory.mjs +0 -178
- package/scripts/lib/gateway-settings.mjs +0 -78
- package/scripts/mutation-bench.mjs +0 -564
- package/scripts/mutation-io-smoke.mjs +0 -1097
- package/scripts/native-patch-bridge-smoke.mjs +0 -288
- package/scripts/native-patch-smoke.mjs +0 -304
- package/scripts/openai-oauth-catalog-smoke.mjs +0 -53
- package/scripts/patch-interior-context-smoke.mjs +0 -49
- package/scripts/patch-newline-utf8-smoke.mjs +0 -157
- package/scripts/perf-hook-smoke.mjs +0 -71
- package/scripts/permission-eval-smoke.mjs +0 -443
- package/scripts/prep-patch.mjs +0 -53
- package/scripts/prep-shim.mjs +0 -96
- package/scripts/provider-cache-smoke.mjs +0 -687
- package/scripts/report-runtime-health.mjs +0 -132
- package/scripts/resolve-bun.mjs +0 -60
- package/scripts/run-mcp.mjs +0 -1473
- package/scripts/salvage-v4a-shatter.test.mjs +0 -58
- package/scripts/scoped-cache-io-smoke.mjs +0 -103
- package/scripts/shell-policy-round3-smoke.mjs +0 -46
- package/scripts/smoke-runtime-negative.ps1 +0 -100
- package/scripts/smoke-runtime-negative.sh +0 -95
- package/scripts/stall-policy-smoke.mjs +0 -50
- package/scripts/start-memory-worker.mjs +0 -23
- package/scripts/statusline-launcher-smoke.mjs +0 -235
- package/scripts/stress-atomic-write.mjs +0 -1028
- package/scripts/test-fault-inject.mjs +0 -164
- package/scripts/test-large-file.mjs +0 -174
- package/scripts/tool-edge-smoke.mjs +0 -209
- package/scripts/uninstall.mjs +0 -238
- package/scripts/webhook-selfheal-smoke.mjs +0 -27
- package/scripts/write-overwrite-guard-smoke.mjs +0 -56
- package/server-main.mjs +0 -3350
- package/server.mjs +0 -468
- package/setup/config-merge.mjs +0 -246
- package/setup/install.mjs +0 -574
- package/setup/launch-core.mjs +0 -617
- package/setup/launch.mjs +0 -101
- package/setup/locate-claude.mjs +0 -56
- package/setup/mixdog-cli.mjs +0 -122
- package/setup/setup-server.mjs +0 -3305
- package/setup/setup.html +0 -3740
- package/setup/tui.mjs +0 -325
- package/skills/retro-skill-proposer/SKILL.md +0 -92
- package/skills/schedule-add/SKILL.md +0 -77
- package/skills/setup/SKILL.md +0 -356
- package/skills/webhook-add/SKILL.md +0 -81
- package/src/agent/bridge-stall-watchdog.mjs +0 -337
- package/src/agent/index.mjs +0 -2229
- package/src/agent/orchestrator/ai-wrapped-dispatch.mjs +0 -1010
- package/src/agent/orchestrator/bridge-retry.mjs +0 -220
- package/src/agent/orchestrator/bridge-trace.mjs +0 -601
- package/src/agent/orchestrator/cache-mtime.mjs +0 -58
- package/src/agent/orchestrator/config.mjs +0 -405
- package/src/agent/orchestrator/context/collect.mjs +0 -651
- package/src/agent/orchestrator/dispatch-persist.mjs +0 -549
- package/src/agent/orchestrator/drain-registry.mjs +0 -50
- package/src/agent/orchestrator/explore-validator.mjs +0 -8
- package/src/agent/orchestrator/internal-roles.mjs +0 -118
- package/src/agent/orchestrator/internal-tools.mjs +0 -88
- package/src/agent/orchestrator/jobs.mjs +0 -116
- package/src/agent/orchestrator/mcp/client.mjs +0 -364
- package/src/agent/orchestrator/providers/anthropic-oauth.mjs +0 -1884
- package/src/agent/orchestrator/providers/anthropic.mjs +0 -598
- package/src/agent/orchestrator/providers/gemini.mjs +0 -1530
- package/src/agent/orchestrator/providers/grok-oauth.mjs +0 -779
- package/src/agent/orchestrator/providers/model-catalog.mjs +0 -374
- package/src/agent/orchestrator/providers/openai-compat-stream.mjs +0 -366
- package/src/agent/orchestrator/providers/openai-compat.mjs +0 -1511
- package/src/agent/orchestrator/providers/openai-oauth-ws.mjs +0 -1891
- package/src/agent/orchestrator/providers/openai-oauth.mjs +0 -1456
- package/src/agent/orchestrator/providers/openai-ws.mjs +0 -127
- package/src/agent/orchestrator/providers/registry.mjs +0 -192
- package/src/agent/orchestrator/providers/retry-classifier.mjs +0 -325
- package/src/agent/orchestrator/session/cache/post-edit-marks.mjs +0 -42
- package/src/agent/orchestrator/session/cache/prefetch-cache.mjs +0 -142
- package/src/agent/orchestrator/session/cache/read-cache.mjs +0 -319
- package/src/agent/orchestrator/session/cache/scoped-cache.mjs +0 -361
- package/src/agent/orchestrator/session/loop.mjs +0 -1619
- package/src/agent/orchestrator/session/manager.mjs +0 -1991
- package/src/agent/orchestrator/session/result-classification.mjs +0 -65
- package/src/agent/orchestrator/session/store.mjs +0 -632
- package/src/agent/orchestrator/session/stream-watchdog.mjs +0 -130
- package/src/agent/orchestrator/session/tool-result-offload.mjs +0 -166
- package/src/agent/orchestrator/session/trim.mjs +0 -491
- package/src/agent/orchestrator/smart-bridge/CACHE-SHARD.md +0 -115
- package/src/agent/orchestrator/smart-bridge/bridge-llm.mjs +0 -331
- package/src/agent/orchestrator/smart-bridge/cache-obs.mjs +0 -150
- package/src/agent/orchestrator/smart-bridge/cache-strategy.mjs +0 -228
- package/src/agent/orchestrator/smart-bridge/index.mjs +0 -215
- package/src/agent/orchestrator/smart-bridge/profiles.mjs +0 -37
- package/src/agent/orchestrator/smart-bridge/registry.mjs +0 -348
- package/src/agent/orchestrator/stall-policy.mjs +0 -201
- package/src/agent/orchestrator/tool-loop-guard.mjs +0 -75
- package/src/agent/orchestrator/tools/bash-session.mjs +0 -722
- package/src/agent/orchestrator/tools/builtin/advisory-lock.mjs +0 -171
- package/src/agent/orchestrator/tools/builtin/arg-guard.mjs +0 -511
- package/src/agent/orchestrator/tools/builtin/bash-tool.mjs +0 -480
- package/src/agent/orchestrator/tools/builtin/builtin-tools.mjs +0 -256
- package/src/agent/orchestrator/tools/builtin/edit-base-guard.mjs +0 -58
- package/src/agent/orchestrator/tools/builtin/edit-byte-plan.mjs +0 -240
- package/src/agent/orchestrator/tools/builtin/edit-byte-utils.mjs +0 -113
- package/src/agent/orchestrator/tools/builtin/edit-commit.mjs +0 -74
- package/src/agent/orchestrator/tools/builtin/edit-context-utils.mjs +0 -242
- package/src/agent/orchestrator/tools/builtin/edit-diagnostics.mjs +0 -211
- package/src/agent/orchestrator/tools/builtin/edit-engine.mjs +0 -1364
- package/src/agent/orchestrator/tools/builtin/edit-failure-context.mjs +0 -126
- package/src/agent/orchestrator/tools/builtin/edit-hint.mjs +0 -141
- package/src/agent/orchestrator/tools/builtin/edit-match-utils.mjs +0 -194
- package/src/agent/orchestrator/tools/builtin/edit-partial-write.mjs +0 -60
- package/src/agent/orchestrator/tools/builtin/edit-stale-refresh.mjs +0 -168
- package/src/agent/orchestrator/tools/builtin/edit-tool.mjs +0 -173
- package/src/agent/orchestrator/tools/builtin/edit-utf8-guard.mjs +0 -48
- package/src/agent/orchestrator/tools/builtin/fuzzy-match.mjs +0 -99
- package/src/agent/orchestrator/tools/builtin/glob-walk.mjs +0 -193
- package/src/agent/orchestrator/tools/builtin/list-tool.mjs +0 -597
- package/src/agent/orchestrator/tools/builtin/native-edit-runner.mjs +0 -110
- package/src/agent/orchestrator/tools/builtin/notebook-edit-tool.mjs +0 -300
- package/src/agent/orchestrator/tools/builtin/path-diagnostics.mjs +0 -152
- package/src/agent/orchestrator/tools/builtin/read-formatting.mjs +0 -118
- package/src/agent/orchestrator/tools/builtin/read-open.mjs +0 -190
- package/src/agent/orchestrator/tools/builtin/read-single-tool.mjs +0 -728
- package/src/agent/orchestrator/tools/builtin/read-snapshot-runtime.mjs +0 -173
- package/src/agent/orchestrator/tools/builtin/read-streaming.mjs +0 -602
- package/src/agent/orchestrator/tools/builtin/rename-tool.mjs +0 -196
- package/src/agent/orchestrator/tools/builtin/rg-runner.mjs +0 -422
- package/src/agent/orchestrator/tools/builtin/search-builders.mjs +0 -158
- package/src/agent/orchestrator/tools/builtin/search-tool.mjs +0 -869
- package/src/agent/orchestrator/tools/builtin/shell-jobs.mjs +0 -962
- package/src/agent/orchestrator/tools/builtin/shell-runtime.mjs +0 -223
- package/src/agent/orchestrator/tools/builtin/snapshot-store.mjs +0 -206
- package/src/agent/orchestrator/tools/builtin/write-tool.mjs +0 -401
- package/src/agent/orchestrator/tools/builtin.mjs +0 -503
- package/src/agent/orchestrator/tools/code-graph-tool-defs.mjs +0 -24
- package/src/agent/orchestrator/tools/code-graph.mjs +0 -4095
- package/src/agent/orchestrator/tools/cwd-tool.mjs +0 -298
- package/src/agent/orchestrator/tools/destructive-warning.mjs +0 -323
- package/src/agent/orchestrator/tools/edit-normalize.mjs +0 -603
- package/src/agent/orchestrator/tools/graph-binary-fetcher.mjs +0 -154
- package/src/agent/orchestrator/tools/graph-manifest.json +0 -26
- package/src/agent/orchestrator/tools/host-input.mjs +0 -204
- package/src/agent/orchestrator/tools/patch-binary-fetcher.mjs +0 -143
- package/src/agent/orchestrator/tools/patch-manifest.json +0 -26
- package/src/agent/orchestrator/tools/patch-tool-defs.mjs +0 -20
- package/src/agent/orchestrator/tools/patch.mjs +0 -2754
- package/src/agent/orchestrator/tools/progress-message.mjs +0 -118
- package/src/agent/orchestrator/tools/shell-command.mjs +0 -865
- package/src/agent/orchestrator/tools/shell-policy-imports.mjs +0 -7
- package/src/agent/orchestrator/tools/shell-snapshot.mjs +0 -313
- package/src/agent/orchestrator/workflow-store.mjs +0 -93
- package/src/agent/tool-defs.mjs +0 -110
- package/src/channels/backends/discord.mjs +0 -784
- package/src/channels/data/voice-runtime-manifest.json +0 -138
- package/src/channels/index.mjs +0 -3268
- package/src/channels/lib/config.mjs +0 -292
- package/src/channels/lib/drop-trace.mjs +0 -71
- package/src/channels/lib/event-pipeline.mjs +0 -81
- package/src/channels/lib/holidays.mjs +0 -138
- package/src/channels/lib/hook-pipe-server.mjs +0 -822
- package/src/channels/lib/output-forwarder.mjs +0 -765
- package/src/channels/lib/runtime-paths.mjs +0 -552
- package/src/channels/lib/scheduler.mjs +0 -723
- package/src/channels/lib/session-discovery.mjs +0 -103
- package/src/channels/lib/state-file.mjs +0 -68
- package/src/channels/lib/status-snapshot.mjs +0 -219
- package/src/channels/lib/tool-format.mjs +0 -140
- package/src/channels/lib/transcript-discovery.mjs +0 -195
- package/src/channels/lib/voice-runtime-fetcher.mjs +0 -734
- package/src/channels/lib/webhook.mjs +0 -1318
- package/src/channels/tool-defs.mjs +0 -170
- package/src/daemon/host.mjs +0 -118
- package/src/daemon/mcp-transport.mjs +0 -47
- package/src/daemon/session.mjs +0 -100
- package/src/daemon/thin-client.mjs +0 -71
- package/src/daemon/transport.mjs +0 -163
- package/src/gateway/claude-current.mjs +0 -255
- package/src/gateway/oauth-usage.mjs +0 -598
- package/src/gateway/route-meta.mjs +0 -629
- package/src/gateway/server.mjs +0 -713
- package/src/memory/data/runtime-manifest.json +0 -40
- package/src/memory/index.mjs +0 -3332
- package/src/memory/lib/core-memory-store.mjs +0 -330
- package/src/memory/lib/embedding-provider.mjs +0 -269
- package/src/memory/lib/embedding-worker.mjs +0 -323
- package/src/memory/lib/memory-cycle1.mjs +0 -645
- package/src/memory/lib/memory-cycle2.mjs +0 -1284
- package/src/memory/lib/memory-cycle3.mjs +0 -540
- package/src/memory/lib/memory-embed.mjs +0 -299
- package/src/memory/lib/memory-ops-policy.mjs +0 -190
- package/src/memory/lib/memory-recall-store.mjs +0 -638
- package/src/memory/lib/memory.mjs +0 -412
- package/src/memory/lib/pg/adapter.mjs +0 -308
- package/src/memory/lib/pg/process.mjs +0 -360
- package/src/memory/lib/pg/supervisor.mjs +0 -396
- package/src/memory/lib/runtime-fetcher.mjs +0 -458
- package/src/memory/lib/trace-store.mjs +0 -728
- package/src/memory/tool-defs.mjs +0 -79
- package/src/search/index.mjs +0 -1173
- package/src/search/lib/backends/anthropic-oauth.mjs +0 -98
- package/src/search/lib/backends/exa.mjs +0 -50
- package/src/search/lib/backends/firecrawl.mjs +0 -61
- package/src/search/lib/backends/gemini-api.mjs +0 -83
- package/src/search/lib/backends/grok-oauth.mjs +0 -86
- package/src/search/lib/backends/index.mjs +0 -150
- package/src/search/lib/backends/openai-api.mjs +0 -144
- package/src/search/lib/backends/openai-oauth.mjs +0 -102
- package/src/search/lib/backends/openai-web-search.mjs +0 -76
- package/src/search/lib/backends/tavily.mjs +0 -55
- package/src/search/lib/backends/xai-api.mjs +0 -113
- package/src/search/lib/config.mjs +0 -192
- package/src/search/lib/provider-usage.mjs +0 -67
- package/src/search/lib/providers.mjs +0 -47
- package/src/search/lib/search-intent.mjs +0 -109
- package/src/search/lib/setup-handler.mjs +0 -261
- package/src/search/lib/web-tools.mjs +0 -1219
- package/src/search/tool-defs.mjs +0 -83
- package/src/setup/defender-exclusion.mjs +0 -183
- package/src/shared/atomic-file.mjs +0 -436
- package/src/shared/config.mjs +0 -372
- package/src/shared/daemon-recycle.mjs +0 -108
- package/src/shared/disable-claude-builtins.mjs +0 -91
- package/src/shared/err-text.mjs +0 -12
- package/src/shared/llm/http-agent.mjs +0 -123
- package/src/shared/open-url.mjs +0 -62
- package/src/shared/plugin-paths.mjs +0 -58
- package/src/shared/schedules-store.mjs +0 -70
- package/src/shared/seed.mjs +0 -161
- package/src/shared/user-cwd.mjs +0 -225
- package/src/shared/user-data-guard.mjs +0 -244
- package/src/status/aggregator.mjs +0 -584
- package/src/status/server.mjs +0 -413
- package/tools.json +0 -1671
- /package/{defaults → src/defaults}/cycle3-review-prompt.md +0 -0
- /package/{defaults → src/defaults}/memory-promote-prompt.md +0 -0
- /package/{hooks → src/hooks}/lib/permission-rules.cjs +0 -0
- /package/{lib → src/lib}/config-cjs.cjs +0 -0
- /package/{lib → src/lib}/hook-pipe-path.cjs +0 -0
- /package/{lib → src/lib}/mixdog-debug.cjs +0 -0
- /package/{lib → src/lib}/text-utils.cjs +0 -0
- /package/{rules → src/rules}/bridge/42-cycle3-agent.md +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/activity-bus.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/providers/anthropic-betas.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/session/abort-lookup.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/session/cache/scoped-cache-outcome.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/session/cache/util.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/session/read-dedup.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/session/save-session-worker.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/smart-bridge/session-builder.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/bash-policy-scan.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/atomic-write.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/binary-file.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/cache-layers.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/cwd-utils.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/device-paths.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/diagnostics-tool.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/diff-utils.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/fs-reachability.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/grep-formatting.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/hash-utils.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/list-formatting.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/open-config-tool.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/path-locks.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/path-utils.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-args.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-batch.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-constants.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-image-resize.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-image.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-lines.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-mode-tool.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-range-index.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-ranges.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-special-files.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-tool.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/read-windows.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/shell-analysis.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/shell-output.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/snapshot-helpers.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/snapshot-validation.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/text-stats.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/builtin/windows-roots.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/code-graph-prewarm-worker.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/env-scrub.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/mutation-content-cache.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/mutation-planner.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/next-call-utils.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/result-compression.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/shell-exec-policy.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/shell-policy-danger-target.mjs +0 -0
- /package/src/{agent → runtime/agent}/orchestrator/tools/shell-policy.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/cli-worker-host.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/config-lock.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/event-queue.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/executor.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/format.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/interaction-workflows.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/memory-client.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/session-control.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/settings.mjs +0 -0
- /package/src/{channels → runtime/channels}/lib/whisper-server.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/agent-ipc.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/bridge-trace-queries.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/llm-worker-host.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-cycle.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-extraction.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-maintenance-store.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-recall-id-patch.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-recall-read-query.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-recall-scope-filter.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-retrievers.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-score.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/memory-text-utils.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/model-profile.mjs +0 -0
- /package/src/{memory → runtime/memory}/lib/project-id-resolver.mjs +0 -0
- /package/src/{search → runtime/search}/lib/cache.mjs +0 -0
- /package/src/{search → runtime/search}/lib/formatter.mjs +0 -0
- /package/src/{search → runtime/search}/lib/state.mjs +0 -0
- /package/src/{shared → runtime/shared}/abort-controller.mjs +0 -0
- /package/src/{shared → runtime/shared}/llm/cost.mjs +0 -0
- /package/src/{shared → runtime/shared}/llm/index.mjs +0 -0
- /package/src/{shared → runtime/shared}/llm/pid-cleanup.mjs +0 -0
- /package/src/{shared → runtime/shared}/llm/usage-log.mjs +0 -0
- /package/src/{shared → runtime/shared}/wsl.mjs +0 -0
|
@@ -0,0 +1,1414 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import {
|
|
4
|
+
TOOL_ASYNC_EXECUTION_CONTRACT,
|
|
5
|
+
cancelBackgroundTask,
|
|
6
|
+
cleanupBackgroundTasks,
|
|
7
|
+
executionModeSchemaDescription,
|
|
8
|
+
getBackgroundTask,
|
|
9
|
+
listBackgroundTasks,
|
|
10
|
+
resolveExecutionMode,
|
|
11
|
+
startBackgroundTask,
|
|
12
|
+
taskIdFromArgs,
|
|
13
|
+
} from '../runtime/shared/background-tasks.mjs';
|
|
14
|
+
import { presentErrorText } from '../runtime/shared/err-text.mjs';
|
|
15
|
+
import { updateJsonAtomicSync } from '../runtime/shared/atomic-file.mjs';
|
|
16
|
+
import { prepareBridgeSession } from '../runtime/agent/orchestrator/smart-bridge/session-builder.mjs';
|
|
17
|
+
import { clearGatewaySessionRoute, writeGatewaySessionRoute } from '../vendor/statusline/src/gateway/session-routes.mjs';
|
|
18
|
+
|
|
19
|
+
const ROLE_PERMISSION_ALIASES = new Map([
|
|
20
|
+
['readonly', 'read'],
|
|
21
|
+
['read-only', 'read'],
|
|
22
|
+
['read', 'read'],
|
|
23
|
+
['full', 'full'],
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
const PRESET_ALIASES = new Map([
|
|
27
|
+
['opus-xhigh', { base: 'opus-high', effort: 'xhigh', id: 'opus-xhigh', name: 'OPUS XHIGH' }],
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const DEFAULT_AGENT_PRESETS = Object.freeze({
|
|
31
|
+
explore: 'sonnet-high',
|
|
32
|
+
'web-researcher': 'sonnet-high',
|
|
33
|
+
maintainer: 'haiku',
|
|
34
|
+
worker: 'sonnet-high',
|
|
35
|
+
'heavy-worker': 'opus-high',
|
|
36
|
+
reviewer: 'opus-xhigh',
|
|
37
|
+
debugger: 'opus-xhigh',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const BRIDGE_TOOL = {
|
|
41
|
+
name: 'bridge',
|
|
42
|
+
title: 'Bridge Agent',
|
|
43
|
+
annotations: {
|
|
44
|
+
title: 'Bridge Agent',
|
|
45
|
+
readOnlyHint: false,
|
|
46
|
+
destructiveHint: true,
|
|
47
|
+
idempotentHint: false,
|
|
48
|
+
openWorldHint: true,
|
|
49
|
+
bridgeHidden: true,
|
|
50
|
+
},
|
|
51
|
+
description: 'Delegate scoped work to workflow agents. Prefer async by default: spawn independent agents in parallel with distinct tags, then keep doing Lead-side work that does not need their result. After async spawn, do not call status/read, do not interfere, and do not poll; wait for the completion notification only when the next step depends on that result. status/read are manual recovery or explicit user-requested controls only. Use sync only when the next step must block.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
type: { type: 'string', enum: ['spawn', 'send', 'list', 'close', 'cancel', 'status', 'read', 'cleanup'], description: 'Action. Default spawn; send follows up to an existing tag/session. status/read are manual recovery controls, not normal polling.' },
|
|
56
|
+
mode: { type: 'string', enum: ['async', 'sync'], description: `${executionModeSchemaDescription('async')} Prefer async for model handoffs; use sync only for an explicit blocking handoff.` },
|
|
57
|
+
task_id: { type: 'string', description: 'Manual status/read/cancel recovery task id; not needed for normal async completion.' },
|
|
58
|
+
agent: { type: 'string', description: 'Workflow agent id to run.' },
|
|
59
|
+
tag: { type: 'string', description: 'Stable agent handle; distinct tag per parallel agent.' },
|
|
60
|
+
sessionId: { type: 'string', description: 'Raw sess_ id.' },
|
|
61
|
+
prompt: { type: 'string', description: 'Scoped task brief: anchors, constraints, done condition.' },
|
|
62
|
+
message: { type: 'string', description: 'Follow-up for send, or spawn brief.' },
|
|
63
|
+
file: { type: 'string', description: 'Prompt file.' },
|
|
64
|
+
cwd: { type: 'string', description: 'Working directory.' },
|
|
65
|
+
context: { type: 'string', description: 'Extra agent context.' },
|
|
66
|
+
firstResponseTimeoutMs: { type: 'number', minimum: 0, description: 'Abort only when the agent produces no first stream/tool activity within this many ms. Default 120s. 0 disables this watchdog.' },
|
|
67
|
+
idleTimeoutMs: { type: 'number', minimum: 0, description: 'Stale watchdog after first stream/tool activity. Default 30m. 0 disables stale abort.' },
|
|
68
|
+
},
|
|
69
|
+
additionalProperties: true,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const FINISHED_JOB_TTL_MS = 30 * 60_000;
|
|
74
|
+
const MAX_JOBS = 200;
|
|
75
|
+
const TERMINAL_REAP_MS = 60 * 60_000;
|
|
76
|
+
const WORKER_INDEX_FILE = 'bridge-workers.json';
|
|
77
|
+
function envTimeoutMs(name, fallback) {
|
|
78
|
+
const raw = process.env[name];
|
|
79
|
+
if (raw === undefined || raw === '') return fallback;
|
|
80
|
+
const n = Number(raw);
|
|
81
|
+
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : fallback;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const DEFAULT_FIRST_RESPONSE_TIMEOUT_MS = envTimeoutMs('MIXDOG_BRIDGE_FIRST_RESPONSE_TIMEOUT_MS', 120_000);
|
|
85
|
+
const DEFAULT_STALE_TIMEOUT_MS = envTimeoutMs('MIXDOG_BRIDGE_STALE_TIMEOUT_MS', 30 * 60_000);
|
|
86
|
+
const ACTIVE_STAGES = new Set(['connecting', 'requesting', 'streaming', 'tool_running', 'running', 'cancelling']);
|
|
87
|
+
|
|
88
|
+
function clean(value) {
|
|
89
|
+
return String(value ?? '').trim();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function normalizeAgentName(value) {
|
|
93
|
+
const id = clean(value).toLowerCase().replace(/[\s_]+/g, '-');
|
|
94
|
+
if (id === 'explorer') return 'explore';
|
|
95
|
+
if (id === 'maint' || id === 'maintenance' || id === 'memory') return 'maintainer';
|
|
96
|
+
if (id === 'heavy' || id === 'heavyworker') return 'heavy-worker';
|
|
97
|
+
if (id === 'review') return 'reviewer';
|
|
98
|
+
if (id === 'debug') return 'debugger';
|
|
99
|
+
return id;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function resolveBridgeExecutionMode(args = {}, context = {}, defaultMode = 'async') {
|
|
103
|
+
const fallback = context.invocationSource !== 'user-command' ? 'async' : defaultMode;
|
|
104
|
+
return resolveExecutionMode(args, fallback);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function normalizePermission(value) {
|
|
108
|
+
const key = clean(value).toLowerCase();
|
|
109
|
+
return ROLE_PERMISSION_ALIASES.get(key) || (key ? key : undefined);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function positiveInt(value) {
|
|
113
|
+
const n = Number(value);
|
|
114
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function terminalPidForContext(context = {}) {
|
|
118
|
+
return positiveInt(context?.clientHostPid);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function bridgeScope(args = {}, context = {}) {
|
|
122
|
+
const scope = clean(args.scope || args.terminal || args.term).toLowerCase();
|
|
123
|
+
if (args.allTerminals === true || scope === 'all' || scope === 'global') return {};
|
|
124
|
+
return context || {};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function sessionMatchesContext(session, context = {}) {
|
|
128
|
+
const wantedPid = terminalPidForContext(context);
|
|
129
|
+
if (!wantedPid) return true;
|
|
130
|
+
const sessionPid = positiveInt(session?.clientHostPid);
|
|
131
|
+
return !!sessionPid && sessionPid === wantedPid;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function rowMatchesContext(row, context = {}) {
|
|
135
|
+
const wantedPid = terminalPidForContext(context);
|
|
136
|
+
if (!wantedPid) return true;
|
|
137
|
+
const rowPid = positiveInt(row?.clientHostPid);
|
|
138
|
+
return !!rowPid && rowPid === wantedPid;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function nonNegativeInt(value) {
|
|
142
|
+
if (value === undefined || value === null || value === '') return null;
|
|
143
|
+
const n = Number(value);
|
|
144
|
+
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function resolveWatchdogMs(value, fallback) {
|
|
148
|
+
const explicit = nonNegativeInt(value);
|
|
149
|
+
if (explicit !== null) return explicit;
|
|
150
|
+
return nonNegativeInt(fallback) ?? 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function presetKey(preset) {
|
|
154
|
+
return clean(preset?.id || preset?.name);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function bridgeRouteForStatusline(preset = {}) {
|
|
158
|
+
const provider = clean(preset.provider);
|
|
159
|
+
const model = clean(preset.model);
|
|
160
|
+
if (!provider || !model) return null;
|
|
161
|
+
const out = {
|
|
162
|
+
mode: 'fixed',
|
|
163
|
+
defaultProvider: provider,
|
|
164
|
+
defaultModel: model,
|
|
165
|
+
};
|
|
166
|
+
const id = clean(preset.id);
|
|
167
|
+
const name = clean(preset.name);
|
|
168
|
+
const modelDisplay = clean(preset.modelDisplay || preset.display || preset.displayName);
|
|
169
|
+
const effort = clean(preset.effort);
|
|
170
|
+
if (id) out.presetId = id;
|
|
171
|
+
if (name) out.presetName = name;
|
|
172
|
+
if (modelDisplay) out.modelDisplay = modelDisplay;
|
|
173
|
+
if (effort) {
|
|
174
|
+
out.effort = effort;
|
|
175
|
+
out.displayEffort = effort;
|
|
176
|
+
}
|
|
177
|
+
if (preset.fast === true || preset.fast === false) out.fast = preset.fast;
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function writeBridgeStatuslineRoute(sessionId, preset) {
|
|
182
|
+
const route = bridgeRouteForStatusline(preset);
|
|
183
|
+
if (!sessionId || !route) return false;
|
|
184
|
+
try { return writeGatewaySessionRoute(sessionId, route); } catch { return false; }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function clearBridgeStatuslineRoute(sessionId) {
|
|
188
|
+
if (!sessionId) return false;
|
|
189
|
+
try { return clearGatewaySessionRoute(sessionId); } catch { return false; }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function findPreset(config, key) {
|
|
193
|
+
const wanted = clean(key).toLowerCase();
|
|
194
|
+
if (!wanted) return null;
|
|
195
|
+
const presets = Array.isArray(config?.presets) ? config.presets : [];
|
|
196
|
+
return presets.find((p) => {
|
|
197
|
+
return clean(p?.id).toLowerCase() === wanted || clean(p?.name).toLowerCase() === wanted;
|
|
198
|
+
}) || null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function synthesizePreset(config, key) {
|
|
202
|
+
const alias = PRESET_ALIASES.get(clean(key).toLowerCase());
|
|
203
|
+
if (!alias) return null;
|
|
204
|
+
const base = findPreset(config, alias.base);
|
|
205
|
+
if (!base) return null;
|
|
206
|
+
return {
|
|
207
|
+
...base,
|
|
208
|
+
id: alias.id,
|
|
209
|
+
name: alias.name,
|
|
210
|
+
effort: alias.effort,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function normalizeAgentRoute(routeLike) {
|
|
215
|
+
const provider = clean(routeLike?.provider);
|
|
216
|
+
const model = clean(routeLike?.model);
|
|
217
|
+
if (!provider || !model) return null;
|
|
218
|
+
return {
|
|
219
|
+
provider,
|
|
220
|
+
model,
|
|
221
|
+
effort: clean(routeLike?.effort) || undefined,
|
|
222
|
+
fast: routeLike?.fast === true,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function agentPresetName(role) {
|
|
227
|
+
return `AGENT ${String(role || '').toUpperCase()}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function readRoles(dataDir) {
|
|
231
|
+
const file = resolve(dataDir, 'user-workflow.json');
|
|
232
|
+
if (!existsSync(file)) return new Map();
|
|
233
|
+
const raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
234
|
+
const roles = new Map();
|
|
235
|
+
for (const role of raw?.roles || []) {
|
|
236
|
+
if (!role?.name || !role?.preset) continue;
|
|
237
|
+
roles.set(String(role.name), {
|
|
238
|
+
name: String(role.name),
|
|
239
|
+
preset: String(role.preset),
|
|
240
|
+
permission: normalizePermission(role.permission) || 'full',
|
|
241
|
+
desc_path: typeof role.desc_path === 'string' ? role.desc_path : null,
|
|
242
|
+
maxLoopIterations: positiveInt(role.maxLoopIterations),
|
|
243
|
+
idleTimeoutMs: nonNegativeInt(role.idleTimeoutMs),
|
|
244
|
+
firstResponseTimeoutMs: nonNegativeInt(role.firstResponseTimeoutMs),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return roles;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function resolvePrompt(args, cwd) {
|
|
251
|
+
const prompt = clean(args.prompt || args.message);
|
|
252
|
+
const file = clean(args.file);
|
|
253
|
+
if (prompt && file) throw new Error('bridge: provide only one of prompt/message or file');
|
|
254
|
+
if (prompt) return prompt;
|
|
255
|
+
if (file) {
|
|
256
|
+
const target = isAbsolute(file) ? file : resolve(cwd || process.cwd(), file);
|
|
257
|
+
return readFileSync(target, 'utf8');
|
|
258
|
+
}
|
|
259
|
+
throw new Error('bridge: prompt/message/file is required');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function withCwdHeader(prompt, cwd) {
|
|
263
|
+
if (!cwd) return prompt;
|
|
264
|
+
if (String(prompt).startsWith('[effective-cwd]')) return prompt;
|
|
265
|
+
return `[effective-cwd] ${cwd}\n\n${prompt}`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function oneLine(value, max = 180) {
|
|
269
|
+
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
270
|
+
return text.length > max ? `${text.slice(0, max)}...` : text;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function compactIso(value) {
|
|
274
|
+
const text = clean(value);
|
|
275
|
+
if (!text) return '';
|
|
276
|
+
return text.replace('T', ' ').replace(/\.\d+Z$/, 'Z');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function stripFinalAnswerWrapper(value) {
|
|
280
|
+
const text = String(value ?? '').trim();
|
|
281
|
+
const match = /^<final-answer\b[^>]*>([\s\S]*?)<\/final-answer>\s*$/i.exec(text);
|
|
282
|
+
return match ? match[1].trim() : text;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function renderResult(value) {
|
|
286
|
+
if (typeof value === 'string') return value;
|
|
287
|
+
if (value && typeof value === 'object') {
|
|
288
|
+
const lines = [];
|
|
289
|
+
|
|
290
|
+
if (Array.isArray(value.workers) || Array.isArray(value.jobs)) {
|
|
291
|
+
lines.push(`bridge mode: ${value.bridgeMode || 'async'}`);
|
|
292
|
+
const workers = Array.isArray(value.workers) ? value.workers : [];
|
|
293
|
+
lines.push(`agents: ${workers.length}`);
|
|
294
|
+
for (const worker of workers) {
|
|
295
|
+
const stale = Number.isFinite(worker.staleSeconds) ? ` stale=${worker.staleSeconds}s` : '';
|
|
296
|
+
const tokens = worker.windowTokens ? ` ctx=${worker.windowTokens}${worker.windowCap ? `/${worker.windowCap}` : ''}` : '';
|
|
297
|
+
const terminal = worker.clientHostPid ? ` term=${worker.clientHostPid}` : '';
|
|
298
|
+
lines.push(`- ${worker.tag} ${worker.role || 'agent'} ${worker.status || 'idle'}/${worker.stage || 'idle'} ${worker.provider}/${worker.model}${terminal}${stale}${tokens}`);
|
|
299
|
+
}
|
|
300
|
+
const jobs = Array.isArray(value.jobs) ? value.jobs : [];
|
|
301
|
+
lines.push(`tasks: ${jobs.length}`);
|
|
302
|
+
for (const job of jobs) {
|
|
303
|
+
const target = job.tag || job.sessionId || '-';
|
|
304
|
+
const terminal = job.clientHostPid ? ` term=${job.clientHostPid}` : '';
|
|
305
|
+
lines.push(`- ${job.task_id} ${job.type} ${job.status} target=${target}${terminal}${job.error ? ` error=${presentErrorText(job.error, { surface: 'bridge' })}` : ''}`);
|
|
306
|
+
}
|
|
307
|
+
if (workers.length === 0 && jobs.length === 0) lines.push('(no bridge agents or tasks)');
|
|
308
|
+
return lines.join('\n');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (value.task_id) {
|
|
312
|
+
lines.push(`bridge task: ${value.task_id}`);
|
|
313
|
+
lines.push(`status: ${value.status}${value.mode ? ` (${value.mode})` : ''}`);
|
|
314
|
+
if (value.type) lines.push(`type: ${value.type}`);
|
|
315
|
+
if (value.tag || value.sessionId) lines.push(`target: ${value.tag || '-'} ${value.sessionId || ''}`.trim());
|
|
316
|
+
if (value.role) lines.push(`agent: ${value.role}`);
|
|
317
|
+
if (value.provider && value.model) lines.push(`model: ${value.provider}/${value.model}`);
|
|
318
|
+
if (value.effort) lines.push(`effort: ${value.effort}`);
|
|
319
|
+
if (value.fast === true || value.fast === false) lines.push(`fast: ${value.fast ? 'on' : 'off'}`);
|
|
320
|
+
if (value.maxLoopIterations || value.idleTimeoutMs || value.firstResponseTimeoutMs) {
|
|
321
|
+
const limitParts = [];
|
|
322
|
+
if (value.maxLoopIterations) limitParts.push(`loop=${value.maxLoopIterations}`);
|
|
323
|
+
if (value.firstResponseTimeoutMs) limitParts.push(`first=${Math.round(value.firstResponseTimeoutMs / 1000)}s`);
|
|
324
|
+
if (value.idleTimeoutMs) limitParts.push(`stale=${Math.round(value.idleTimeoutMs / 1000)}s`);
|
|
325
|
+
lines.push(`limits: ${limitParts.join(' ')}`);
|
|
326
|
+
}
|
|
327
|
+
if (value.stage || value.workerStatus) lines.push(`agent: ${value.workerStatus || 'unknown'}/${value.stage || 'unknown'}`);
|
|
328
|
+
if (value.startedAt) lines.push(`started: ${compactIso(value.startedAt)}`);
|
|
329
|
+
if (value.finishedAt) lines.push(`finished: ${compactIso(value.finishedAt)}`);
|
|
330
|
+
if (value.error) lines.push(`error: ${presentErrorText(value.error, { surface: 'bridge' })}`);
|
|
331
|
+
if (value.status === 'running') lines.push('notification: completion will be delivered to the owner session; use read/status only for manual recovery.');
|
|
332
|
+
if (value.result !== undefined) {
|
|
333
|
+
const result = value.result;
|
|
334
|
+
const content = typeof result === 'string' ? result : result?.content;
|
|
335
|
+
if (content) lines.push('', stripFinalAnswerWrapper(content));
|
|
336
|
+
else lines.push('', JSON.stringify(result, null, 2));
|
|
337
|
+
}
|
|
338
|
+
return lines.join('\n');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (value.queued) {
|
|
342
|
+
return [
|
|
343
|
+
'bridge message queued',
|
|
344
|
+
`target: ${value.tag || '-'} ${value.sessionId || ''}`.trim(),
|
|
345
|
+
value.role ? `agent: ${value.role}` : null,
|
|
346
|
+
`queueDepth: ${value.queueDepth ?? 1}`,
|
|
347
|
+
].filter(Boolean).join('\n');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (value.closed !== undefined) {
|
|
351
|
+
return [
|
|
352
|
+
`bridge close: ${value.closed ? 'ok' : 'not closed'}`,
|
|
353
|
+
value.tag ? `tag: ${value.tag}` : null,
|
|
354
|
+
value.sessionId ? `sessionId: ${value.sessionId}` : null,
|
|
355
|
+
value.task_id ? `task_id: ${value.task_id}` : null,
|
|
356
|
+
value.forgotten ? 'forgotten: true' : null,
|
|
357
|
+
].filter(Boolean).join('\n');
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (value.content !== undefined) {
|
|
361
|
+
const header = [
|
|
362
|
+
value.respawned ? 'bridge respawned' : 'bridge result',
|
|
363
|
+
value.tag ? `tag=${value.tag}` : null,
|
|
364
|
+
value.role ? `agent=${value.role}` : null,
|
|
365
|
+
value.provider && value.model ? `${value.provider}/${value.model}` : null,
|
|
366
|
+
].filter(Boolean).join(' ');
|
|
367
|
+
return `${header}\n${stripFinalAnswerWrapper(value.content)}`;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return JSON.stringify(value, null, 2);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function createStandaloneBridge({ cfgMod, reg, mgr, dataDir, cwd: defaultCwd, defaultMode: initialMode }) {
|
|
374
|
+
const tags = new Map();
|
|
375
|
+
const tagRoles = new Map();
|
|
376
|
+
const tagCwds = new Map();
|
|
377
|
+
const jobs = new Map();
|
|
378
|
+
const reapTimers = new Map();
|
|
379
|
+
let tagSeq = 0;
|
|
380
|
+
let jobSeq = 0;
|
|
381
|
+
// Inline normalization here (normalizeMode is defined below — avoid
|
|
382
|
+
// use-before-def). When nothing is injected, the Lead defaults to async.
|
|
383
|
+
let defaultMode = (String(initialMode ?? 'async').toLowerCase() === 'async') ? 'async' : 'sync';
|
|
384
|
+
|
|
385
|
+
function normalizeMode(value) {
|
|
386
|
+
const mode = clean(value).toLowerCase();
|
|
387
|
+
return mode === 'async' ? 'async' : 'sync';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function modeFor(args = {}, context = {}) {
|
|
391
|
+
return resolveBridgeExecutionMode(args, context, defaultMode);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function nextJobId(type) {
|
|
395
|
+
jobSeq += 1;
|
|
396
|
+
return `job_${Date.now()}_${jobSeq}_${clean(type) || 'bridge'}`;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function workerIndexPath() {
|
|
400
|
+
return dataDir ? resolve(dataDir, WORKER_INDEX_FILE) : null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function workerRowKey(row = {}) {
|
|
404
|
+
return clean(row.sessionId) || clean(row.tag);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function workerRowTime(row = {}) {
|
|
408
|
+
return Date.parse(row.updatedAt || row.finishedAt || row.lastUsedAt || row.createdAt || '') || 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function isTerminalWorkerStatus(status) {
|
|
412
|
+
return /^(idle|closed|completed|failed|error|cancelled|canceled|killed|timeout)$/i.test(clean(status));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function keepWorkerRow(row = {}) {
|
|
416
|
+
if (!clean(row.tag) || !clean(row.sessionId)) return false;
|
|
417
|
+
const t = workerRowTime(row);
|
|
418
|
+
if (!t) return true;
|
|
419
|
+
if (!isTerminalWorkerStatus(row.status || row.stage)) return true;
|
|
420
|
+
return Date.now() - t < TERMINAL_REAP_MS;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function normalizeWorkerRows(value) {
|
|
424
|
+
const source = Array.isArray(value?.workers)
|
|
425
|
+
? value.workers
|
|
426
|
+
: (value?.workers && typeof value.workers === 'object'
|
|
427
|
+
? Object.values(value.workers)
|
|
428
|
+
: (Array.isArray(value) ? value : []));
|
|
429
|
+
return source
|
|
430
|
+
.filter((row) => row && typeof row === 'object')
|
|
431
|
+
.map((row) => ({
|
|
432
|
+
tag: clean(row.tag),
|
|
433
|
+
sessionId: clean(row.sessionId),
|
|
434
|
+
role: clean(row.role) || null,
|
|
435
|
+
provider: clean(row.provider) || null,
|
|
436
|
+
model: clean(row.model) || null,
|
|
437
|
+
preset: clean(row.preset) || null,
|
|
438
|
+
effort: clean(row.effort) || null,
|
|
439
|
+
fast: row.fast === true ? true : (row.fast === false ? false : null),
|
|
440
|
+
status: clean(row.status) || 'idle',
|
|
441
|
+
stage: clean(row.stage) || clean(row.status) || 'idle',
|
|
442
|
+
createdAt: clean(row.createdAt) || null,
|
|
443
|
+
updatedAt: clean(row.updatedAt) || null,
|
|
444
|
+
lastUsedAt: clean(row.lastUsedAt) || null,
|
|
445
|
+
finishedAt: clean(row.finishedAt) || null,
|
|
446
|
+
clientHostPid: positiveInt(row.clientHostPid),
|
|
447
|
+
cwd: clean(row.cwd) || null,
|
|
448
|
+
task_id: clean(row.task_id || row.taskId) || null,
|
|
449
|
+
error: clean(row.error) || null,
|
|
450
|
+
permission: clean(row.permission) || null,
|
|
451
|
+
toolPermission: clean(row.toolPermission) || null,
|
|
452
|
+
messages: positiveInt(row.messages) || 0,
|
|
453
|
+
tools: positiveInt(row.tools) || 0,
|
|
454
|
+
}))
|
|
455
|
+
.filter(keepWorkerRow);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function readWorkerRows(context = {}) {
|
|
459
|
+
const file = workerIndexPath();
|
|
460
|
+
if (!file || !existsSync(file)) return [];
|
|
461
|
+
try {
|
|
462
|
+
const rows = normalizeWorkerRows(JSON.parse(readFileSync(file, 'utf8')));
|
|
463
|
+
return rows.filter((row) => rowMatchesContext(row, context));
|
|
464
|
+
} catch {
|
|
465
|
+
return [];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function writeWorkerRows(mutator) {
|
|
470
|
+
const file = workerIndexPath();
|
|
471
|
+
if (!file || typeof mutator !== 'function') return null;
|
|
472
|
+
try {
|
|
473
|
+
return updateJsonAtomicSync(file, (cur) => {
|
|
474
|
+
const byKey = new Map();
|
|
475
|
+
for (const row of normalizeWorkerRows(cur)) {
|
|
476
|
+
const key = workerRowKey(row);
|
|
477
|
+
if (key) byKey.set(key, row);
|
|
478
|
+
}
|
|
479
|
+
mutator(byKey);
|
|
480
|
+
const workers = {};
|
|
481
|
+
for (const row of [...byKey.values()].filter(keepWorkerRow)) {
|
|
482
|
+
const key = workerRowKey(row);
|
|
483
|
+
if (key) workers[key] = row;
|
|
484
|
+
}
|
|
485
|
+
return { version: 1, updatedAt: new Date().toISOString(), workers };
|
|
486
|
+
}, { lock: true });
|
|
487
|
+
} catch {
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function workerRowFromSession(session, fallbackTag = '', extra = {}) {
|
|
493
|
+
const tag = clean(session?.bridgeTag) || clean(fallbackTag) || clean(extra.tag);
|
|
494
|
+
const sessionId = clean(session?.id || extra.sessionId);
|
|
495
|
+
if (!tag || !sessionId) return null;
|
|
496
|
+
const runtime = mgr.getSessionRuntime?.(sessionId);
|
|
497
|
+
const status = clean(extra.status) || (session?.closed === true ? 'closed' : clean(session?.status) || 'idle');
|
|
498
|
+
const stage = clean(extra.stage) || clean(runtime?.stage) || status;
|
|
499
|
+
const nowIso = new Date().toISOString();
|
|
500
|
+
return {
|
|
501
|
+
tag,
|
|
502
|
+
sessionId,
|
|
503
|
+
role: clean(extra.role) || clean(session?.role) || null,
|
|
504
|
+
provider: clean(extra.provider) || clean(session?.provider) || null,
|
|
505
|
+
model: clean(extra.model) || clean(session?.model) || null,
|
|
506
|
+
preset: clean(extra.preset) || clean(session?.presetName) || null,
|
|
507
|
+
effort: clean(extra.effort) || clean(session?.effort) || null,
|
|
508
|
+
fast: extra.fast === true || extra.fast === false ? extra.fast : (session?.fast === true ? true : null),
|
|
509
|
+
status,
|
|
510
|
+
stage,
|
|
511
|
+
createdAt: clean(session?.createdAt) || clean(extra.createdAt) || nowIso,
|
|
512
|
+
updatedAt: clean(extra.updatedAt) || nowIso,
|
|
513
|
+
lastUsedAt: clean(session?.lastUsedAt) || null,
|
|
514
|
+
finishedAt: clean(extra.finishedAt) || null,
|
|
515
|
+
clientHostPid: positiveInt(extra.clientHostPid) || positiveInt(session?.clientHostPid),
|
|
516
|
+
cwd: clean(session?.cwd) || clean(extra.cwd) || null,
|
|
517
|
+
task_id: clean(extra.task_id || extra.taskId) || null,
|
|
518
|
+
error: clean(extra.error) || null,
|
|
519
|
+
permission: clean(session?.permission) || null,
|
|
520
|
+
toolPermission: clean(session?.toolPermission) || null,
|
|
521
|
+
messages: Array.isArray(session?.messages) ? session.messages.length : 0,
|
|
522
|
+
tools: Array.isArray(session?.tools) ? session.tools.length : 0,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function workerRowToSession(row = {}) {
|
|
527
|
+
return {
|
|
528
|
+
id: row.sessionId,
|
|
529
|
+
bridgeTag: row.tag,
|
|
530
|
+
role: row.role || null,
|
|
531
|
+
provider: row.provider || null,
|
|
532
|
+
model: row.model || null,
|
|
533
|
+
presetName: row.preset || null,
|
|
534
|
+
effort: row.effort || null,
|
|
535
|
+
fast: row.fast === true,
|
|
536
|
+
status: row.status || 'idle',
|
|
537
|
+
stage: row.stage || row.status || 'idle',
|
|
538
|
+
createdAt: row.createdAt || null,
|
|
539
|
+
updatedAt: row.updatedAt || null,
|
|
540
|
+
lastUsedAt: row.lastUsedAt || null,
|
|
541
|
+
clientHostPid: row.clientHostPid || null,
|
|
542
|
+
cwd: row.cwd || null,
|
|
543
|
+
permission: row.permission || null,
|
|
544
|
+
toolPermission: row.toolPermission || null,
|
|
545
|
+
messageCount: Math.max(0, Number(row.messages || 0)),
|
|
546
|
+
toolCount: Math.max(0, Number(row.tools || 0)),
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function upsertWorkerRow(row) {
|
|
551
|
+
const normalized = normalizeWorkerRows({ workers: [row] })[0];
|
|
552
|
+
if (!normalized) return false;
|
|
553
|
+
tags.set(normalized.tag, normalized.sessionId);
|
|
554
|
+
if (normalized.role) tagRoles.set(normalized.tag, normalized.role);
|
|
555
|
+
if (normalized.cwd) tagCwds.set(normalized.tag, normalized.cwd);
|
|
556
|
+
writeWorkerRows((byKey) => {
|
|
557
|
+
const key = workerRowKey(normalized);
|
|
558
|
+
const prev = byKey.get(key) || {};
|
|
559
|
+
const merged = { ...prev, ...normalized };
|
|
560
|
+
for (const field of ['role', 'provider', 'model', 'preset', 'effort', 'fast', 'clientHostPid', 'cwd', 'task_id', 'permission', 'toolPermission']) {
|
|
561
|
+
if ((merged[field] === null || merged[field] === '') && prev[field] != null && prev[field] !== '') {
|
|
562
|
+
merged[field] = prev[field];
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
byKey.set(key, {
|
|
566
|
+
...merged,
|
|
567
|
+
createdAt: normalized.createdAt || prev.createdAt || new Date().toISOString(),
|
|
568
|
+
updatedAt: normalized.updatedAt || new Date().toISOString(),
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function upsertWorkerSession(session, fallbackTag = '', extra = {}) {
|
|
575
|
+
return upsertWorkerRow(workerRowFromSession(session, fallbackTag, extra));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function removeWorkerRow({ tag = '', sessionId = '' } = {}) {
|
|
579
|
+
const targetTag = clean(tag);
|
|
580
|
+
const targetSessionId = clean(sessionId);
|
|
581
|
+
writeWorkerRows((byKey) => {
|
|
582
|
+
for (const [key, row] of [...byKey.entries()]) {
|
|
583
|
+
if ((targetSessionId && row.sessionId === targetSessionId) || (targetTag && row.tag === targetTag)) {
|
|
584
|
+
byKey.delete(key);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function refreshTagsFromIndex(context = {}) {
|
|
591
|
+
const rows = readWorkerRows(context);
|
|
592
|
+
for (const row of rows) {
|
|
593
|
+
if (!row.tag || !row.sessionId) continue;
|
|
594
|
+
tags.set(row.tag, row.sessionId);
|
|
595
|
+
if (row.role) tagRoles.set(row.tag, row.role);
|
|
596
|
+
if (row.cwd) tagCwds.set(row.tag, row.cwd);
|
|
597
|
+
}
|
|
598
|
+
return rows;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function wantsSessionScan(args = {}) {
|
|
602
|
+
return args.recover === true || args.scanSessions === true || args.scan_sessions === true;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function resolveTag(target, context = {}, options = {}) {
|
|
606
|
+
const scanSessions = options.scanSessions === true;
|
|
607
|
+
refreshTagsFromSessions({ scanSessions, context });
|
|
608
|
+
const value = clean(target);
|
|
609
|
+
if (!value) return null;
|
|
610
|
+
if (value.startsWith('sess_')) {
|
|
611
|
+
const session = getLiveSession(value);
|
|
612
|
+
if (session && sessionMatchesContext(session, context)) return value;
|
|
613
|
+
const row = readWorkerRows(context).find((item) => item.sessionId === value);
|
|
614
|
+
return row ? value : null;
|
|
615
|
+
}
|
|
616
|
+
const matches = bridgeSessionEntries({ scanSessions, context })
|
|
617
|
+
.filter((entry) => entry.tag === value);
|
|
618
|
+
if (matches.length === 1) return matches[0].session.id;
|
|
619
|
+
if (matches.length > 1) {
|
|
620
|
+
throw new Error(`bridge: tag "${value}" is ambiguous across terminals; use sessionId`);
|
|
621
|
+
}
|
|
622
|
+
const sessionId = tags.get(value) || null;
|
|
623
|
+
const session = getLiveSession(sessionId);
|
|
624
|
+
return session && sessionMatchesContext(session, context) ? sessionId : null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function getLiveSession(sessionId) {
|
|
628
|
+
if (!sessionId) return null;
|
|
629
|
+
const session = mgr.getSession(sessionId);
|
|
630
|
+
return session && session.closed !== true ? session : null;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function tagForSession(sessionId) {
|
|
634
|
+
const session = getLiveSession(sessionId);
|
|
635
|
+
const persistedTag = clean(session?.bridgeTag);
|
|
636
|
+
if (persistedTag) return persistedTag;
|
|
637
|
+
for (const [tag, sid] of tags.entries()) {
|
|
638
|
+
if (sid === sessionId) return tag;
|
|
639
|
+
}
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function bridgeSessionEntries({ scanSessions = false, context = {} } = {}) {
|
|
644
|
+
const rows = [];
|
|
645
|
+
const seen = new Set();
|
|
646
|
+
const add = (session, fallbackTag = '') => {
|
|
647
|
+
const tag = clean(session?.bridgeTag) || clean(fallbackTag);
|
|
648
|
+
if (!tag || !session?.id || session.closed === true) return;
|
|
649
|
+
if (!sessionMatchesContext(session, context)) return;
|
|
650
|
+
if (seen.has(session.id)) return;
|
|
651
|
+
seen.add(session.id);
|
|
652
|
+
rows.push({ tag, session });
|
|
653
|
+
};
|
|
654
|
+
const addIndexRow = (row) => {
|
|
655
|
+
const tag = clean(row?.tag);
|
|
656
|
+
const sessionId = clean(row?.sessionId);
|
|
657
|
+
if (!tag || !sessionId || !rowMatchesContext(row, context)) return;
|
|
658
|
+
if (seen.has(sessionId)) return;
|
|
659
|
+
seen.add(sessionId);
|
|
660
|
+
rows.push({ tag, session: workerRowToSession(row), indexRow: row });
|
|
661
|
+
};
|
|
662
|
+
for (const row of readWorkerRows(context)) addIndexRow(row);
|
|
663
|
+
if (scanSessions) {
|
|
664
|
+
for (const session of mgr.listSessions({ includeClosed: false }) || []) {
|
|
665
|
+
add(session, session?.bridgeTag);
|
|
666
|
+
if (clean(session?.bridgeTag)) upsertWorkerSession(session, session.bridgeTag);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
for (const [tag, sessionId] of tags.entries()) {
|
|
670
|
+
add(getLiveSession(sessionId), tag);
|
|
671
|
+
}
|
|
672
|
+
return rows;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function nextTag(role, context = {}) {
|
|
676
|
+
refreshTagsFromSessions({ context });
|
|
677
|
+
let tag;
|
|
678
|
+
do {
|
|
679
|
+
tag = `${clean(role) || 'agent'}${++tagSeq}`;
|
|
680
|
+
} while (resolveTag(tag, context));
|
|
681
|
+
return tag;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function refreshTagsFromSessions({ scanSessions = false, context = {} } = {}) {
|
|
685
|
+
const indexedRows = refreshTagsFromIndex(context);
|
|
686
|
+
const indexedKeys = new Set(indexedRows.map((row) => `${row.tag}\0${row.sessionId}`));
|
|
687
|
+
for (const [tag, sessionId] of [...tags.entries()]) {
|
|
688
|
+
if (indexedKeys.has(`${tag}\0${sessionId}`)) continue;
|
|
689
|
+
const session = getLiveSession(sessionId);
|
|
690
|
+
if (!session || session.closed) tags.delete(tag);
|
|
691
|
+
}
|
|
692
|
+
if (!scanSessions) return;
|
|
693
|
+
for (const session of mgr.listSessions({ includeClosed: false }) || []) {
|
|
694
|
+
const tag = clean(session?.bridgeTag);
|
|
695
|
+
if (!tag || tags.has(tag)) continue;
|
|
696
|
+
if (!sessionMatchesContext(session, context)) continue;
|
|
697
|
+
tags.set(tag, session.id);
|
|
698
|
+
if (session.role) tagRoles.set(tag, session.role);
|
|
699
|
+
if (session.cwd) tagCwds.set(tag, session.cwd);
|
|
700
|
+
upsertWorkerSession(session, tag);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function bindTag(tag, session, extra = {}) {
|
|
705
|
+
if (!tag || !session?.id) return;
|
|
706
|
+
tags.set(tag, session.id);
|
|
707
|
+
if (session.role) tagRoles.set(tag, session.role);
|
|
708
|
+
if (session.cwd) tagCwds.set(tag, session.cwd);
|
|
709
|
+
upsertWorkerSession(session, tag, extra);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function forgetTag(tag) {
|
|
713
|
+
if (!tag) return;
|
|
714
|
+
const sessionId = tags.get(tag) || '';
|
|
715
|
+
tags.delete(tag);
|
|
716
|
+
tagRoles.delete(tag);
|
|
717
|
+
tagCwds.delete(tag);
|
|
718
|
+
removeWorkerRow({ tag, sessionId });
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function cancelReap(sessionId) {
|
|
722
|
+
const handle = reapTimers.get(sessionId);
|
|
723
|
+
if (!handle) return false;
|
|
724
|
+
clearTimeout(handle);
|
|
725
|
+
reapTimers.delete(sessionId);
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function scheduleReap(sessionId) {
|
|
730
|
+
if (!sessionId) return;
|
|
731
|
+
cancelReap(sessionId);
|
|
732
|
+
const handle = setTimeout(() => {
|
|
733
|
+
reapTimers.delete(sessionId);
|
|
734
|
+
try { mgr.hideSessionFromList?.(sessionId); } catch {}
|
|
735
|
+
const tag = tagForSession(sessionId);
|
|
736
|
+
if (tag) forgetTag(tag);
|
|
737
|
+
removeWorkerRow({ tag, sessionId });
|
|
738
|
+
clearBridgeStatuslineRoute(sessionId);
|
|
739
|
+
try { mgr.closeSession(sessionId, 'terminal-reap'); } catch {}
|
|
740
|
+
}, TERMINAL_REAP_MS);
|
|
741
|
+
handle.unref?.();
|
|
742
|
+
reapTimers.set(sessionId, handle);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function isSessionBusy(sessionId) {
|
|
746
|
+
const runtime = mgr.getSessionRuntime?.(sessionId);
|
|
747
|
+
if (runtime?.controller?.signal && !runtime.controller.signal.aborted) return true;
|
|
748
|
+
if (runtime?.stage) return ACTIVE_STAGES.has(runtime.stage);
|
|
749
|
+
const session = getLiveSession(sessionId);
|
|
750
|
+
return ACTIVE_STAGES.has(session?.status || '');
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function pruneJobs({ force = false } = {}) {
|
|
754
|
+
const now = Date.now();
|
|
755
|
+
for (const [jobId, job] of [...jobs.entries()]) {
|
|
756
|
+
if (job.status === 'running' && !force) continue;
|
|
757
|
+
const finishedAt = job.finishedAt ? Date.parse(job.finishedAt) : 0;
|
|
758
|
+
if (force || (finishedAt > 0 && now - finishedAt > FINISHED_JOB_TTL_MS)) {
|
|
759
|
+
jobs.delete(jobId);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (jobs.size <= MAX_JOBS) return;
|
|
763
|
+
const removable = [...jobs.values()]
|
|
764
|
+
.filter((job) => job.status !== 'running')
|
|
765
|
+
.sort((a, b) => Date.parse(a.finishedAt || a.startedAt || 0) - Date.parse(b.finishedAt || b.startedAt || 0));
|
|
766
|
+
while (jobs.size > MAX_JOBS && removable.length > 0) {
|
|
767
|
+
const job = removable.shift();
|
|
768
|
+
jobs.delete(job.jobId);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
async function ensureProvider(config, provider) {
|
|
773
|
+
const providers = { ...(config.providers || {}) };
|
|
774
|
+
providers[provider] = { ...(providers[provider] || {}), enabled: true };
|
|
775
|
+
await reg.initProviders(providers);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function resolvePreset(config, args, roleCfg) {
|
|
779
|
+
if (args.provider && args.model) {
|
|
780
|
+
return {
|
|
781
|
+
presetName: args.preset || '__direct__',
|
|
782
|
+
preset: {
|
|
783
|
+
id: '__direct__',
|
|
784
|
+
name: '__DIRECT__',
|
|
785
|
+
type: 'bridge',
|
|
786
|
+
provider: clean(args.provider),
|
|
787
|
+
model: clean(args.model),
|
|
788
|
+
effort: clean(args.effort) || undefined,
|
|
789
|
+
fast: args.fast === true,
|
|
790
|
+
tools: 'full',
|
|
791
|
+
},
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const agentName = normalizeAgentName(args.agent || args.role);
|
|
796
|
+
const agentRoute = !clean(args.preset)
|
|
797
|
+
? (normalizeAgentRoute(config?.agents?.[agentName])
|
|
798
|
+
|| (agentName === 'maintainer' ? normalizeAgentRoute(config?.agents?.maintenance) : null))
|
|
799
|
+
: null;
|
|
800
|
+
if (agentRoute) {
|
|
801
|
+
return {
|
|
802
|
+
presetName: agentPresetName(agentName),
|
|
803
|
+
preset: {
|
|
804
|
+
id: `agent-${agentName}`,
|
|
805
|
+
name: agentPresetName(agentName),
|
|
806
|
+
type: 'bridge',
|
|
807
|
+
provider: agentRoute.provider,
|
|
808
|
+
model: agentRoute.model,
|
|
809
|
+
effort: agentRoute.effort,
|
|
810
|
+
fast: agentRoute.fast === true,
|
|
811
|
+
tools: 'full',
|
|
812
|
+
},
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const presetName = clean(args.preset) || roleCfg?.preset || DEFAULT_AGENT_PRESETS[agentName];
|
|
817
|
+
if (!presetName) throw new Error(`bridge: agent "${agentName}" has no model assignment`);
|
|
818
|
+
const preset = findPreset(config, presetName) || synthesizePreset(config, presetName);
|
|
819
|
+
if (!preset) throw new Error(`bridge: preset "${presetName}" not found`);
|
|
820
|
+
return { presetName, preset };
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function list({ scanSessions = false, context = {} } = {}) {
|
|
824
|
+
refreshTagsFromSessions({ scanSessions, context });
|
|
825
|
+
const now = Date.now();
|
|
826
|
+
const rows = [];
|
|
827
|
+
for (const { tag, session } of bridgeSessionEntries({ scanSessions, context })) {
|
|
828
|
+
const sessionId = session.id;
|
|
829
|
+
const runtime = mgr.getSessionRuntime?.(sessionId);
|
|
830
|
+
const status = session.closed === true ? 'closed' : (session.status || 'idle');
|
|
831
|
+
const stage = session.stage || (status === 'idle' || status === 'error' || status === 'closed'
|
|
832
|
+
? status
|
|
833
|
+
: (runtime?.stage || status));
|
|
834
|
+
rows.push({
|
|
835
|
+
tag,
|
|
836
|
+
sessionId,
|
|
837
|
+
role: session.role || null,
|
|
838
|
+
provider: session.provider,
|
|
839
|
+
model: session.model,
|
|
840
|
+
preset: session.presetName || null,
|
|
841
|
+
effort: session.effort || null,
|
|
842
|
+
fast: session.fast === true,
|
|
843
|
+
status,
|
|
844
|
+
stage,
|
|
845
|
+
createdAt: session.createdAt || null,
|
|
846
|
+
updatedAt: session.updatedAt || null,
|
|
847
|
+
lastUsedAt: session.lastUsedAt || null,
|
|
848
|
+
clientHostPid: session.clientHostPid || null,
|
|
849
|
+
lastStreamDeltaAt: runtime?.lastStreamDeltaAt ? new Date(runtime.lastStreamDeltaAt).toISOString() : null,
|
|
850
|
+
staleSeconds: runtime?.lastStreamDeltaAt ? Math.floor((now - runtime.lastStreamDeltaAt) / 1000) : null,
|
|
851
|
+
windowTokens: Number(session.lastContextTokens ?? session.lastInputTokens) || 0,
|
|
852
|
+
windowCap: Number(session.contextWindow) || null,
|
|
853
|
+
permission: session.permission || null,
|
|
854
|
+
toolPermission: session.toolPermission || null,
|
|
855
|
+
messages: Array.isArray(session.messages) ? session.messages.length : Math.max(0, Number(session.messageCount || 0)),
|
|
856
|
+
tools: Array.isArray(session.tools) ? session.tools.length : Math.max(0, Number(session.toolCount || 0)),
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
return rows;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function jobWorkerSnapshot(sessionId) {
|
|
863
|
+
if (!sessionId) return null;
|
|
864
|
+
const session = mgr.getSession(sessionId);
|
|
865
|
+
if (!session) return null;
|
|
866
|
+
const runtime = mgr.getSessionRuntime?.(sessionId);
|
|
867
|
+
const status = session.closed === true ? 'closed' : (session.status || 'idle');
|
|
868
|
+
return {
|
|
869
|
+
workerStatus: status,
|
|
870
|
+
stage: runtime?.stage || status,
|
|
871
|
+
clientHostPid: session.clientHostPid || null,
|
|
872
|
+
lastStreamDeltaAt: runtime?.lastStreamDeltaAt ? new Date(runtime.lastStreamDeltaAt).toISOString() : null,
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function listJobs(context = {}) {
|
|
877
|
+
const wantedPid = terminalPidForContext(context);
|
|
878
|
+
const rows = listBackgroundTasks({ surface: 'bridge', context }).map((task) => ({
|
|
879
|
+
task_id: task.task_id,
|
|
880
|
+
type: task.operation,
|
|
881
|
+
status: task.status,
|
|
882
|
+
tag: task.tag || null,
|
|
883
|
+
sessionId: task.sessionId || null,
|
|
884
|
+
role: task.role || null,
|
|
885
|
+
preset: task.preset || null,
|
|
886
|
+
provider: task.provider || null,
|
|
887
|
+
model: task.model || null,
|
|
888
|
+
effort: task.effort || null,
|
|
889
|
+
fast: task.fast === true || task.fast === false ? task.fast : null,
|
|
890
|
+
maxLoopIterations: task.maxLoopIterations || null,
|
|
891
|
+
idleTimeoutMs: task.idleTimeoutMs || null,
|
|
892
|
+
firstResponseTimeoutMs: task.firstResponseTimeoutMs || null,
|
|
893
|
+
startedAt: task.startedAt,
|
|
894
|
+
finishedAt: task.finishedAt || null,
|
|
895
|
+
error: task.error || null,
|
|
896
|
+
...jobWorkerSnapshot(task.sessionId),
|
|
897
|
+
}));
|
|
898
|
+
return wantedPid ? rows.filter((row) => positiveInt(row.clientHostPid) === wantedPid) : rows;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function getJob(args, context = {}) {
|
|
902
|
+
const taskId = taskIdFromArgs(args);
|
|
903
|
+
if (!taskId) throw new Error('bridge read/status: task_id is required');
|
|
904
|
+
const task = getBackgroundTask(taskId, { surface: 'bridge', context });
|
|
905
|
+
if (!task) throw new Error(`bridge read/status: task "${taskId}" not found`);
|
|
906
|
+
return task;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function renderJob(job, includeResult = false) {
|
|
910
|
+
const meta = job.meta || {};
|
|
911
|
+
return {
|
|
912
|
+
task_id: job.taskId,
|
|
913
|
+
type: job.operation,
|
|
914
|
+
status: job.status,
|
|
915
|
+
tag: meta.tag || null,
|
|
916
|
+
sessionId: meta.sessionId || null,
|
|
917
|
+
role: meta.role || null,
|
|
918
|
+
preset: meta.preset || null,
|
|
919
|
+
provider: meta.provider || null,
|
|
920
|
+
model: meta.model || null,
|
|
921
|
+
effort: meta.effort || null,
|
|
922
|
+
fast: meta.fast === true || meta.fast === false ? meta.fast : null,
|
|
923
|
+
maxLoopIterations: meta.maxLoopIterations || null,
|
|
924
|
+
idleTimeoutMs: meta.idleTimeoutMs || null,
|
|
925
|
+
firstResponseTimeoutMs: meta.firstResponseTimeoutMs || null,
|
|
926
|
+
startedAt: job.startedAt,
|
|
927
|
+
finishedAt: job.finishedAt || null,
|
|
928
|
+
error: job.error || null,
|
|
929
|
+
...jobWorkerSnapshot(meta.sessionId),
|
|
930
|
+
...(includeResult && job.result !== undefined ? { result: job.result } : {}),
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function preparedSpawnMeta(prepared, extras = {}) {
|
|
935
|
+
return {
|
|
936
|
+
...(extras || {}),
|
|
937
|
+
tag: prepared.tag,
|
|
938
|
+
sessionId: prepared.session.id,
|
|
939
|
+
role: prepared.role,
|
|
940
|
+
preset: presetKey(prepared.preset) || prepared.presetName,
|
|
941
|
+
provider: prepared.preset.provider,
|
|
942
|
+
model: prepared.preset.model,
|
|
943
|
+
effort: prepared.preset.effort || null,
|
|
944
|
+
fast: prepared.preset.fast === true,
|
|
945
|
+
maxLoopIterations: prepared.maxLoopIterations || null,
|
|
946
|
+
idleTimeoutMs: prepared.idleTimeoutMs || null,
|
|
947
|
+
firstResponseTimeoutMs: prepared.firstResponseTimeoutMs || null,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function pendingSpawnMeta(args = {}, extras = {}) {
|
|
952
|
+
const role = normalizeAgentName(args.agent || args.role);
|
|
953
|
+
return {
|
|
954
|
+
...(extras || {}),
|
|
955
|
+
tag: clean(args.tag) || null,
|
|
956
|
+
sessionId: null,
|
|
957
|
+
role: role || null,
|
|
958
|
+
preset: clean(args.preset) || null,
|
|
959
|
+
provider: clean(args.provider) || null,
|
|
960
|
+
model: clean(args.model) || null,
|
|
961
|
+
effort: clean(args.effort) || null,
|
|
962
|
+
fast: args.fast === true ? true : null,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function mergeJobMeta(job, meta = {}) {
|
|
967
|
+
if (!job || !meta || typeof meta !== 'object') return;
|
|
968
|
+
const next = { ...(job.meta || {}), ...meta };
|
|
969
|
+
job.meta = next;
|
|
970
|
+
if (job.input && typeof job.input === 'object') {
|
|
971
|
+
job.input = {
|
|
972
|
+
...job.input,
|
|
973
|
+
tag: next.tag || job.input.tag || null,
|
|
974
|
+
sessionId: next.sessionId || job.input.sessionId || null,
|
|
975
|
+
role: next.role || job.input.role || null,
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
job.label = next.tag || next.sessionId || job.label;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function closePreparedSpawn(prepared, reason = 'bridge-task-cancel') {
|
|
982
|
+
if (!prepared?.session?.id) return;
|
|
983
|
+
try { mgr.closeSession(prepared.session.id, reason); } catch {}
|
|
984
|
+
try { clearBridgeStatuslineRoute(prepared.session.id); } catch {}
|
|
985
|
+
if (prepared.tag) forgetTag(prepared.tag);
|
|
986
|
+
removeWorkerRow({ tag: prepared.tag, sessionId: prepared.session.id });
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function startJob(type, meta, run, notifyContext = null) {
|
|
990
|
+
const clientHostPid = terminalPidForContext(notifyContext);
|
|
991
|
+
const jobMeta = {
|
|
992
|
+
...(meta || {}),
|
|
993
|
+
...(clientHostPid ? { clientHostPid } : {}),
|
|
994
|
+
};
|
|
995
|
+
let task;
|
|
996
|
+
task = startBackgroundTask({
|
|
997
|
+
surface: 'bridge',
|
|
998
|
+
operation: type,
|
|
999
|
+
label: jobMeta?.tag || jobMeta?.sessionId || type,
|
|
1000
|
+
input: { type, tag: jobMeta?.tag || null, sessionId: jobMeta?.sessionId || null, role: jobMeta?.role || null },
|
|
1001
|
+
context: notifyContext,
|
|
1002
|
+
meta: jobMeta,
|
|
1003
|
+
resultType: 'bridge_task_result',
|
|
1004
|
+
renderResult: (result) => renderResult(result),
|
|
1005
|
+
cancel: () => {
|
|
1006
|
+
const currentMeta = task?.meta || jobMeta;
|
|
1007
|
+
if (currentMeta?.sessionId) {
|
|
1008
|
+
try { mgr.closeSession(currentMeta.sessionId, 'bridge-task-cancel'); } catch {}
|
|
1009
|
+
}
|
|
1010
|
+
},
|
|
1011
|
+
run: async () => {
|
|
1012
|
+
// Yield one macrotask before doing bridge work. startBackgroundTask uses
|
|
1013
|
+
// a Promise microtask, which otherwise begins CPU-heavy spawn prep
|
|
1014
|
+
// before the TUI receives/render the "running" result.
|
|
1015
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1016
|
+
if (task?.status === 'cancelled') return null;
|
|
1017
|
+
return await run(task);
|
|
1018
|
+
},
|
|
1019
|
+
});
|
|
1020
|
+
return task;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function startDeferredSpawnJob(args, callerCwd, context, notifyContext, extras = {}) {
|
|
1024
|
+
return startJob('spawn', pendingSpawnMeta(args, extras), async (job) => {
|
|
1025
|
+
const prepared = await prepareSpawn(args, callerCwd, context);
|
|
1026
|
+
mergeJobMeta(job, preparedSpawnMeta(prepared, extras));
|
|
1027
|
+
upsertWorkerSession(prepared.session, prepared.tag, {
|
|
1028
|
+
...preparedSpawnMeta(prepared, extras),
|
|
1029
|
+
status: 'running',
|
|
1030
|
+
stage: 'running',
|
|
1031
|
+
task_id: job.taskId,
|
|
1032
|
+
startedAt: job.startedAt,
|
|
1033
|
+
});
|
|
1034
|
+
if (job?.status === 'cancelled') {
|
|
1035
|
+
closePreparedSpawn(prepared);
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
return await runSpawn(prepared);
|
|
1039
|
+
}, notifyContext);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
function startProgressIdleWatchdog(sessionId, idleTimeoutMs, firstResponseTimeoutMs = DEFAULT_FIRST_RESPONSE_TIMEOUT_MS) {
|
|
1043
|
+
const staleMs = resolveWatchdogMs(idleTimeoutMs, DEFAULT_STALE_TIMEOUT_MS);
|
|
1044
|
+
const firstMs = resolveWatchdogMs(firstResponseTimeoutMs, DEFAULT_FIRST_RESPONSE_TIMEOUT_MS);
|
|
1045
|
+
if (!sessionId || (!staleMs && !firstMs)) return null;
|
|
1046
|
+
if (typeof mgr.getSessionProgressSnapshot !== 'function' && typeof mgr.getSessionLastProgressAt !== 'function') return null;
|
|
1047
|
+
if (typeof mgr.linkParentSignalToSession !== 'function') return null;
|
|
1048
|
+
const controller = new AbortController();
|
|
1049
|
+
try { mgr.linkParentSignalToSession(sessionId, controller.signal); } catch { return null; }
|
|
1050
|
+
const timer = setInterval(() => {
|
|
1051
|
+
const now = Date.now();
|
|
1052
|
+
const snapshot = typeof mgr.getSessionProgressSnapshot === 'function'
|
|
1053
|
+
? mgr.getSessionProgressSnapshot(sessionId)
|
|
1054
|
+
: null;
|
|
1055
|
+
if (snapshot) {
|
|
1056
|
+
if (snapshot.waitingForFirstActivity) {
|
|
1057
|
+
const startedAt = snapshot.modelRequestStartedAt || snapshot.askStartedAt;
|
|
1058
|
+
if (firstMs && startedAt && now - startedAt > firstMs) {
|
|
1059
|
+
try { controller.abort(new Error(`bridge first response stale (${firstMs}ms)`)); } catch {}
|
|
1060
|
+
}
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const last = snapshot.lastProgressAt || snapshot.firstActivityAt;
|
|
1064
|
+
if (staleMs && last && now - last > staleMs) {
|
|
1065
|
+
try { controller.abort(new Error(`bridge task stale (${staleMs}ms without stream/tool progress)`)); } catch {}
|
|
1066
|
+
}
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const last = mgr.getSessionLastProgressAt(sessionId);
|
|
1070
|
+
if (staleMs && last && now - last > staleMs) {
|
|
1071
|
+
try { controller.abort(new Error(`bridge task stale (${staleMs}ms without progress)`)); } catch {}
|
|
1072
|
+
}
|
|
1073
|
+
}, 1000);
|
|
1074
|
+
timer.unref?.();
|
|
1075
|
+
return {
|
|
1076
|
+
stop: () => {
|
|
1077
|
+
try { clearInterval(timer); } catch {}
|
|
1078
|
+
},
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
async function prepareSpawn(args, callerCwd = null, context = {}) {
|
|
1083
|
+
refreshTagsFromSessions({ context });
|
|
1084
|
+
const config = cfgMod.loadConfig();
|
|
1085
|
+
const roles = readRoles(dataDir);
|
|
1086
|
+
const role = normalizeAgentName(args.agent || args.role);
|
|
1087
|
+
if (!role) throw new Error('bridge spawn: agent is required');
|
|
1088
|
+
const roleCfg = roles.get(role);
|
|
1089
|
+
const { presetName, preset } = resolvePreset(config, args, roleCfg);
|
|
1090
|
+
await ensureProvider(config, preset.provider);
|
|
1091
|
+
|
|
1092
|
+
const tag = clean(args.tag) || nextTag(role, context);
|
|
1093
|
+
if (resolveTag(tag, context, { scanSessions: wantsSessionScan(args) })) throw new Error(`bridge spawn: tag "${tag}" already exists`);
|
|
1094
|
+
const baseCwd = resolve(callerCwd || defaultCwd || process.cwd());
|
|
1095
|
+
const workerCwd = clean(args.cwd) ? resolve(baseCwd, args.cwd) : baseCwd;
|
|
1096
|
+
const prompt = withCwdHeader(await resolvePrompt(args, workerCwd), workerCwd);
|
|
1097
|
+
const runtimeSpec = cfgMod.resolveRuntimeSpec(preset, { lane: 'bridge', agentId: tag });
|
|
1098
|
+
const maxLoopIterations = positiveInt(args.maxLoopIterations) || roleCfg?.maxLoopIterations || null;
|
|
1099
|
+
const idleTimeoutMs = resolveWatchdogMs(args.idleTimeoutMs, roleCfg?.idleTimeoutMs ?? DEFAULT_STALE_TIMEOUT_MS);
|
|
1100
|
+
const firstResponseTimeoutMs = resolveWatchdogMs(args.firstResponseTimeoutMs, roleCfg?.firstResponseTimeoutMs ?? DEFAULT_FIRST_RESPONSE_TIMEOUT_MS);
|
|
1101
|
+
const { session, effectiveCwd } = prepareBridgeSession({
|
|
1102
|
+
role,
|
|
1103
|
+
presetName,
|
|
1104
|
+
preset,
|
|
1105
|
+
runtimeSpec,
|
|
1106
|
+
owner: 'bridge',
|
|
1107
|
+
cwd: workerCwd,
|
|
1108
|
+
sourceType: 'cli',
|
|
1109
|
+
sourceName: role,
|
|
1110
|
+
clientHostPid: terminalPidForContext(context) || null,
|
|
1111
|
+
bridgeTag: tag,
|
|
1112
|
+
taskType: clean(args.taskType) || clean(args.typeHint) || undefined,
|
|
1113
|
+
maxLoopIterations: maxLoopIterations || undefined,
|
|
1114
|
+
permission: normalizePermission(roleCfg?.permission) || 'full',
|
|
1115
|
+
cacheKeyOverride: args.cacheKey || undefined,
|
|
1116
|
+
});
|
|
1117
|
+
// Lead sessions write a gateway-session route when created; bridge agents
|
|
1118
|
+
// are built through prepareBridgeSession(), so mirror that registration here
|
|
1119
|
+
// or the vendored L1/L2 statusline cannot resolve the agent route/model.
|
|
1120
|
+
writeBridgeStatuslineRoute(session.id, preset);
|
|
1121
|
+
bindTag(tag, session, {
|
|
1122
|
+
role,
|
|
1123
|
+
preset: presetKey(preset) || presetName,
|
|
1124
|
+
provider: preset.provider,
|
|
1125
|
+
model: preset.model,
|
|
1126
|
+
effort: preset.effort || null,
|
|
1127
|
+
fast: preset.fast === true,
|
|
1128
|
+
status: 'idle',
|
|
1129
|
+
stage: 'idle',
|
|
1130
|
+
});
|
|
1131
|
+
cancelReap(session.id);
|
|
1132
|
+
return { args, tag, session, role, preset, presetName, workerCwd: effectiveCwd || workerCwd, prompt, maxLoopIterations, idleTimeoutMs, firstResponseTimeoutMs };
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
async function runSpawn(prepared) {
|
|
1136
|
+
const { args, tag, session, role, preset, presetName, workerCwd, prompt, idleTimeoutMs, firstResponseTimeoutMs } = prepared;
|
|
1137
|
+
const watchdog = startProgressIdleWatchdog(session.id, idleTimeoutMs, firstResponseTimeoutMs);
|
|
1138
|
+
let finalStatus = 'idle';
|
|
1139
|
+
upsertWorkerSession(session, tag, {
|
|
1140
|
+
role,
|
|
1141
|
+
preset: presetKey(preset) || presetName,
|
|
1142
|
+
provider: preset.provider,
|
|
1143
|
+
model: preset.model,
|
|
1144
|
+
effort: preset.effort || null,
|
|
1145
|
+
fast: preset.fast === true,
|
|
1146
|
+
status: 'running',
|
|
1147
|
+
stage: 'running',
|
|
1148
|
+
});
|
|
1149
|
+
try {
|
|
1150
|
+
const result = await mgr.askSession(session.id, prompt, args.context || null, null, workerCwd);
|
|
1151
|
+
const content = result?.content || '';
|
|
1152
|
+
return {
|
|
1153
|
+
tag,
|
|
1154
|
+
sessionId: session.id,
|
|
1155
|
+
role,
|
|
1156
|
+
preset: presetKey(preset) || presetName,
|
|
1157
|
+
provider: preset.provider,
|
|
1158
|
+
model: preset.model,
|
|
1159
|
+
effort: preset.effort || null,
|
|
1160
|
+
fast: preset.fast === true,
|
|
1161
|
+
content,
|
|
1162
|
+
};
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
finalStatus = 'error';
|
|
1165
|
+
throw error;
|
|
1166
|
+
} finally {
|
|
1167
|
+
watchdog?.stop?.();
|
|
1168
|
+
upsertWorkerSession(session, tag, {
|
|
1169
|
+
role,
|
|
1170
|
+
preset: presetKey(preset) || presetName,
|
|
1171
|
+
provider: preset.provider,
|
|
1172
|
+
model: preset.model,
|
|
1173
|
+
effort: preset.effort || null,
|
|
1174
|
+
fast: preset.fast === true,
|
|
1175
|
+
status: finalStatus,
|
|
1176
|
+
stage: finalStatus,
|
|
1177
|
+
finishedAt: new Date().toISOString(),
|
|
1178
|
+
});
|
|
1179
|
+
scheduleReap(session.id);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
async function spawn(args) {
|
|
1184
|
+
return await runSpawn(await prepareSpawn(args));
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
async function prepareSend(args, context = {}) {
|
|
1188
|
+
refreshTagsFromSessions({ scanSessions: wantsSessionScan(args), context });
|
|
1189
|
+
const target = clean(args.tag || args.sessionId);
|
|
1190
|
+
if (!target) throw new Error('bridge send: tag or sessionId is required');
|
|
1191
|
+
const sessionId = resolveTag(target, context, { scanSessions: wantsSessionScan(args) });
|
|
1192
|
+
if (!sessionId) throw new Error(`bridge send: target "${target}" not found`);
|
|
1193
|
+
const session = mgr.getSession(sessionId);
|
|
1194
|
+
if (!session || session.closed) throw new Error(`bridge send: session "${sessionId}" is closed`);
|
|
1195
|
+
cancelReap(sessionId);
|
|
1196
|
+
const prompt = await resolvePrompt(args, session.cwd || defaultCwd);
|
|
1197
|
+
return { args, session, sessionId, prompt };
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
async function runSend(prepared) {
|
|
1201
|
+
const { args, session, sessionId, prompt } = prepared;
|
|
1202
|
+
const watchdog = startProgressIdleWatchdog(
|
|
1203
|
+
sessionId,
|
|
1204
|
+
resolveWatchdogMs(args.idleTimeoutMs, DEFAULT_STALE_TIMEOUT_MS),
|
|
1205
|
+
resolveWatchdogMs(args.firstResponseTimeoutMs, DEFAULT_FIRST_RESPONSE_TIMEOUT_MS),
|
|
1206
|
+
);
|
|
1207
|
+
const tag = tagForSession(sessionId);
|
|
1208
|
+
let finalStatus = 'idle';
|
|
1209
|
+
upsertWorkerSession(session, tag, { status: 'running', stage: 'running' });
|
|
1210
|
+
try {
|
|
1211
|
+
const result = await mgr.askSession(sessionId, prompt, args.context || null, null, session.cwd || defaultCwd);
|
|
1212
|
+
return {
|
|
1213
|
+
tag,
|
|
1214
|
+
sessionId,
|
|
1215
|
+
role: session.role || null,
|
|
1216
|
+
provider: session.provider,
|
|
1217
|
+
model: session.model,
|
|
1218
|
+
content: result?.content || '',
|
|
1219
|
+
};
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
finalStatus = 'error';
|
|
1222
|
+
throw error;
|
|
1223
|
+
} finally {
|
|
1224
|
+
watchdog?.stop?.();
|
|
1225
|
+
upsertWorkerSession(session, tag, {
|
|
1226
|
+
status: finalStatus,
|
|
1227
|
+
stage: finalStatus,
|
|
1228
|
+
finishedAt: new Date().toISOString(),
|
|
1229
|
+
});
|
|
1230
|
+
scheduleReap(sessionId);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
async function send(args) {
|
|
1235
|
+
return await runSend(await prepareSend(args));
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
function close(args, context = {}) {
|
|
1239
|
+
const scopedContext = bridgeScope(args, context);
|
|
1240
|
+
refreshTagsFromSessions({ scanSessions: wantsSessionScan(args), context: scopedContext });
|
|
1241
|
+
const taskId = taskIdFromArgs(args);
|
|
1242
|
+
const task = taskId ? getBackgroundTask(taskId, { surface: 'bridge', context }) : null;
|
|
1243
|
+
const taskMeta = task?.meta || {};
|
|
1244
|
+
const target = clean(args.tag || args.sessionId || taskMeta.sessionId);
|
|
1245
|
+
if (!target) {
|
|
1246
|
+
if (task?.taskId) {
|
|
1247
|
+
cancelBackgroundTask(task.taskId, 'cancelled by bridge close');
|
|
1248
|
+
return { closed: true, tag: taskMeta.tag || null, sessionId: null, task_id: task.taskId };
|
|
1249
|
+
}
|
|
1250
|
+
throw new Error('bridge close: tag or sessionId is required');
|
|
1251
|
+
}
|
|
1252
|
+
const sessionId = resolveTag(target, scopedContext, { scanSessions: wantsSessionScan(args) });
|
|
1253
|
+
if (!sessionId) {
|
|
1254
|
+
if (!target.startsWith('sess_') && tagRoles.has(target)) {
|
|
1255
|
+
forgetTag(target);
|
|
1256
|
+
if (task?.taskId) cancelBackgroundTask(task.taskId, 'cancelled by bridge close');
|
|
1257
|
+
return { closed: true, forgotten: true, tag: target, sessionId: null, task_id: task?.taskId || null };
|
|
1258
|
+
}
|
|
1259
|
+
throw new Error(`bridge close: target "${target}" not found`);
|
|
1260
|
+
}
|
|
1261
|
+
cancelReap(sessionId);
|
|
1262
|
+
const tag = tagForSession(sessionId);
|
|
1263
|
+
if (tag) forgetTag(tag);
|
|
1264
|
+
removeWorkerRow({ tag, sessionId });
|
|
1265
|
+
clearBridgeStatuslineRoute(sessionId);
|
|
1266
|
+
const ok = mgr.closeSession(sessionId, 'cli-bridge-close');
|
|
1267
|
+
if (task?.taskId) cancelBackgroundTask(task.taskId, 'cancelled by bridge close');
|
|
1268
|
+
return { closed: ok, tag, sessionId, task_id: task?.taskId || null };
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
function cleanup(args = {}, context = {}) {
|
|
1272
|
+
const scopedContext = bridgeScope(args, context);
|
|
1273
|
+
const beforeTags = tags.size;
|
|
1274
|
+
refreshTagsFromSessions({ scanSessions: wantsSessionScan(args), context: scopedContext });
|
|
1275
|
+
const cleaned = cleanupBackgroundTasks({ surface: 'bridge', context: scopedContext, force: args.force === true });
|
|
1276
|
+
return {
|
|
1277
|
+
jobsRemoved: cleaned.removed,
|
|
1278
|
+
tagsRemoved: beforeTags - tags.size,
|
|
1279
|
+
jobs: listJobs(scopedContext).length,
|
|
1280
|
+
workers: list({ scanSessions: wantsSessionScan(args), context: scopedContext }).length,
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
function closeAll(reason = 'cli-bridge-close-all') {
|
|
1285
|
+
refreshTagsFromSessions({ scanSessions: false });
|
|
1286
|
+
const closed = [];
|
|
1287
|
+
const failed = [];
|
|
1288
|
+
for (const { tag, session } of bridgeSessionEntries({ scanSessions: false, context: {} })) {
|
|
1289
|
+
try {
|
|
1290
|
+
closed.push(close({ sessionId: session.id }));
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
failed.push({ tag, error: presentErrorText(err, { surface: 'bridge' }) });
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
for (const task of listBackgroundTasks({ surface: 'bridge' })) {
|
|
1296
|
+
if (task?.status !== 'running') continue;
|
|
1297
|
+
cancelBackgroundTask(task.task_id, reason);
|
|
1298
|
+
closed.push({ closed: true, tag: task.tag || null, sessionId: task.sessionId || null, task_id: task.task_id });
|
|
1299
|
+
}
|
|
1300
|
+
for (const timer of reapTimers.values()) clearTimeout(timer);
|
|
1301
|
+
reapTimers.clear();
|
|
1302
|
+
writeWorkerRows((byKey) => byKey.clear());
|
|
1303
|
+
return { closed, failed };
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
function coldRespawnArgs(args = {}, context = {}) {
|
|
1307
|
+
const target = clean(args.tag || args.sessionId);
|
|
1308
|
+
if (!target || target.startsWith('sess_') || resolveTag(target, context)) return null;
|
|
1309
|
+
const recoveredRole = clean(args.agent || args.role) || tagRoles.get(target);
|
|
1310
|
+
if (!recoveredRole) return null;
|
|
1311
|
+
return {
|
|
1312
|
+
...args,
|
|
1313
|
+
type: 'spawn',
|
|
1314
|
+
tag: target,
|
|
1315
|
+
agent: recoveredRole,
|
|
1316
|
+
role: recoveredRole,
|
|
1317
|
+
prompt: args.prompt ?? args.message,
|
|
1318
|
+
cwd: args.cwd ?? tagCwds.get(target) ?? undefined,
|
|
1319
|
+
respawned: true,
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
async function execute(args = {}, context = {}) {
|
|
1324
|
+
try {
|
|
1325
|
+
const type = clean(args.type) || 'spawn';
|
|
1326
|
+
const callerCwd = clean(context.cwd || context.callerCwd);
|
|
1327
|
+
const scopedContext = bridgeScope(args, context);
|
|
1328
|
+
const notifyContext = context;
|
|
1329
|
+
if (type === 'list') return renderResult({ bridgeMode: defaultMode, workers: list({ scanSessions: wantsSessionScan(args), context: scopedContext }), jobs: listJobs(scopedContext) });
|
|
1330
|
+
if (type === 'status') return renderResult(renderJob(getJob(args, scopedContext), false));
|
|
1331
|
+
if (type === 'read') return renderResult(renderJob(getJob(args, scopedContext), true));
|
|
1332
|
+
if (type === 'cleanup') return renderResult(cleanup(args, scopedContext));
|
|
1333
|
+
if (type === 'cancel') return renderResult(close(args, scopedContext));
|
|
1334
|
+
if (type === 'close') return renderResult(close(args, scopedContext));
|
|
1335
|
+
if (type === 'send') {
|
|
1336
|
+
const respawnArgs = coldRespawnArgs(args, scopedContext);
|
|
1337
|
+
if (respawnArgs) {
|
|
1338
|
+
if (modeFor(args, context) === 'async') {
|
|
1339
|
+
const job = startDeferredSpawnJob(respawnArgs, callerCwd, context, notifyContext, { respawned: true });
|
|
1340
|
+
return renderResult({ mode: 'async', respawned: true, ...renderJob(job, false) });
|
|
1341
|
+
}
|
|
1342
|
+
const prepared = await prepareSpawn(respawnArgs, callerCwd, context);
|
|
1343
|
+
return renderResult({ respawned: true, ...(await runSpawn(prepared)) });
|
|
1344
|
+
}
|
|
1345
|
+
const prepared = await prepareSend(args, scopedContext);
|
|
1346
|
+
if (isSessionBusy(prepared.sessionId) && typeof mgr.enqueuePendingMessage === 'function') {
|
|
1347
|
+
const queueDepth = mgr.enqueuePendingMessage(prepared.sessionId, prepared.prompt);
|
|
1348
|
+
return renderResult({
|
|
1349
|
+
queued: true,
|
|
1350
|
+
tag: tagForSession(prepared.sessionId),
|
|
1351
|
+
sessionId: prepared.sessionId,
|
|
1352
|
+
role: prepared.session.role || null,
|
|
1353
|
+
queueDepth,
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
if (modeFor(args, context) === 'async') {
|
|
1357
|
+
const job = startJob('send', {
|
|
1358
|
+
tag: tagForSession(prepared.sessionId),
|
|
1359
|
+
sessionId: prepared.sessionId,
|
|
1360
|
+
role: prepared.session.role || null,
|
|
1361
|
+
provider: prepared.session.provider || null,
|
|
1362
|
+
model: prepared.session.model || null,
|
|
1363
|
+
preset: prepared.session.presetName || null,
|
|
1364
|
+
effort: prepared.session.effort || null,
|
|
1365
|
+
fast: prepared.session.fast === true,
|
|
1366
|
+
}, () => runSend(prepared), notifyContext);
|
|
1367
|
+
return renderResult({ mode: 'async', ...renderJob(job, false) });
|
|
1368
|
+
}
|
|
1369
|
+
return renderResult(await runSend(prepared));
|
|
1370
|
+
}
|
|
1371
|
+
if (type === 'spawn') {
|
|
1372
|
+
if (modeFor(args, context) === 'async') {
|
|
1373
|
+
const job = startDeferredSpawnJob(args, callerCwd, context, notifyContext);
|
|
1374
|
+
return renderResult({ mode: 'async', ...renderJob(job, false) });
|
|
1375
|
+
}
|
|
1376
|
+
const prepared = await prepareSpawn(args, callerCwd, context);
|
|
1377
|
+
return renderResult(await runSpawn(prepared));
|
|
1378
|
+
}
|
|
1379
|
+
throw new Error(`bridge: unknown type "${type}"`);
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
return `Error: ${presentErrorText(err, { surface: 'bridge' })}`;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
return {
|
|
1386
|
+
tools: [BRIDGE_TOOL],
|
|
1387
|
+
execute,
|
|
1388
|
+
getStatus: (context = {}) => {
|
|
1389
|
+
const scopedContext = bridgeScope({}, context);
|
|
1390
|
+
const pid = terminalPidForContext(scopedContext);
|
|
1391
|
+
return {
|
|
1392
|
+
bridgeMode: defaultMode,
|
|
1393
|
+
workers: list({ scanSessions: false, context: scopedContext }),
|
|
1394
|
+
jobs: listJobs(scopedContext),
|
|
1395
|
+
scope: pid ? { clientHostPid: pid } : { allTerminals: true },
|
|
1396
|
+
};
|
|
1397
|
+
},
|
|
1398
|
+
recoverWorkers: (context = {}) => {
|
|
1399
|
+
const scopedContext = bridgeScope({ recover: true }, context);
|
|
1400
|
+
refreshTagsFromSessions({ scanSessions: true, context: scopedContext });
|
|
1401
|
+
return list({ scanSessions: false, context: scopedContext });
|
|
1402
|
+
},
|
|
1403
|
+
getDefaultMode: () => defaultMode,
|
|
1404
|
+
setDefaultMode: (mode) => {
|
|
1405
|
+
defaultMode = normalizeMode(mode);
|
|
1406
|
+
return defaultMode;
|
|
1407
|
+
},
|
|
1408
|
+
toggleDefaultMode: () => {
|
|
1409
|
+
defaultMode = defaultMode === 'sync' ? 'async' : 'sync';
|
|
1410
|
+
return defaultMode;
|
|
1411
|
+
},
|
|
1412
|
+
closeAll,
|
|
1413
|
+
};
|
|
1414
|
+
}
|