@felan-ai/felan 0.28.3 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +20 -0
- package/README.md +127 -40
- package/dist/acp/daemon-session.d.ts +34 -0
- package/dist/acp/daemon-session.d.ts.map +1 -0
- package/dist/acp/daemon-session.js +142 -0
- package/dist/acp/daemon-session.js.map +1 -0
- package/dist/acp/login.d.ts +4 -2
- package/dist/acp/login.d.ts.map +1 -1
- package/dist/acp/login.js +155 -251
- package/dist/acp/login.js.map +1 -1
- package/dist/acp/protocol-interactions.d.ts +25 -0
- package/dist/acp/protocol-interactions.d.ts.map +1 -0
- package/dist/acp/protocol-interactions.js +297 -0
- package/dist/acp/protocol-interactions.js.map +1 -0
- package/dist/acp/protocol-updates.d.ts +20 -0
- package/dist/acp/protocol-updates.d.ts.map +1 -0
- package/dist/acp/protocol-updates.js +114 -0
- package/dist/acp/protocol-updates.js.map +1 -0
- package/dist/acp/session-registry.d.ts +4 -9
- package/dist/acp/session-registry.d.ts.map +1 -1
- package/dist/acp/session-registry.js +178 -386
- package/dist/acp/session-registry.js.map +1 -1
- package/dist/cli-config.d.ts +7 -0
- package/dist/cli-config.d.ts.map +1 -0
- package/dist/cli-config.js +18 -0
- package/dist/cli-config.js.map +1 -0
- package/dist/cli-main.d.ts +12 -7
- package/dist/cli-main.d.ts.map +1 -1
- package/dist/cli-main.js +106 -105
- package/dist/cli-main.js.map +1 -1
- package/dist/client/agent-host.d.ts +52 -0
- package/dist/client/agent-host.d.ts.map +1 -0
- package/dist/client/agent-host.js +413 -0
- package/dist/client/agent-host.js.map +1 -0
- package/dist/client/agents-presenter.d.ts +12 -0
- package/dist/client/agents-presenter.d.ts.map +1 -0
- package/dist/client/agents-presenter.js +66 -0
- package/dist/client/agents-presenter.js.map +1 -0
- package/dist/client/client.d.ts +181 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +806 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/daemon-blocked.d.ts +12 -0
- package/dist/client/daemon-blocked.d.ts.map +1 -0
- package/dist/client/daemon-blocked.js +27 -0
- package/dist/client/daemon-blocked.js.map +1 -0
- package/dist/client/daemon-stop.d.ts +5 -0
- package/dist/client/daemon-stop.d.ts.map +1 -0
- package/dist/client/daemon-stop.js +36 -0
- package/dist/client/daemon-stop.js.map +1 -0
- package/dist/client/diagnostics.d.ts +55 -0
- package/dist/client/diagnostics.d.ts.map +1 -0
- package/dist/client/diagnostics.js +47 -0
- package/dist/client/diagnostics.js.map +1 -0
- package/dist/client/hint-renderers.d.ts +16 -0
- package/dist/client/hint-renderers.d.ts.map +1 -0
- package/dist/client/hint-renderers.js +28 -0
- package/dist/client/hint-renderers.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +5 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/message-display.d.ts +21 -0
- package/dist/client/message-display.d.ts.map +1 -0
- package/dist/client/message-display.js +115 -0
- package/dist/client/message-display.js.map +1 -0
- package/dist/client/powerline-presenter.d.ts +13 -0
- package/dist/client/powerline-presenter.d.ts.map +1 -0
- package/dist/client/powerline-presenter.js +67 -0
- package/dist/client/powerline-presenter.js.map +1 -0
- package/dist/client/presenters.d.ts +43 -0
- package/dist/client/presenters.d.ts.map +1 -0
- package/dist/client/presenters.js +118 -0
- package/dist/client/presenters.js.map +1 -0
- package/dist/client/reducer.d.ts +37 -0
- package/dist/client/reducer.d.ts.map +1 -0
- package/dist/client/reducer.js +173 -0
- package/dist/client/reducer.js.map +1 -0
- package/dist/client/session-title.d.ts +6 -0
- package/dist/client/session-title.d.ts.map +1 -0
- package/dist/client/session-title.js +13 -0
- package/dist/client/session-title.js.map +1 -0
- package/dist/client/transport.d.ts +14 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +46 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client/ui.d.ts +25 -0
- package/dist/client/ui.d.ts.map +1 -0
- package/dist/client/ui.js +123 -0
- package/dist/client/ui.js.map +1 -0
- package/dist/client-application.d.ts +37 -0
- package/dist/client-application.d.ts.map +1 -0
- package/dist/client-application.js +126 -0
- package/dist/client-application.js.map +1 -0
- package/dist/compaction-presentation.d.ts +6 -4
- package/dist/compaction-presentation.d.ts.map +1 -1
- package/dist/compaction-presentation.js +11 -37
- package/dist/compaction-presentation.js.map +1 -1
- package/dist/daemon-command.d.ts +10 -0
- package/dist/daemon-command.d.ts.map +1 -0
- package/dist/daemon-command.js +163 -0
- package/dist/daemon-command.js.map +1 -0
- package/dist/daemon-entrypoint.d.ts +5 -0
- package/dist/daemon-entrypoint.d.ts.map +1 -0
- package/dist/daemon-entrypoint.js +17 -0
- package/dist/daemon-entrypoint.js.map +1 -0
- package/dist/daemon-host.d.ts +2 -0
- package/dist/daemon-host.d.ts.map +1 -0
- package/dist/daemon-host.js +18 -0
- package/dist/daemon-host.js.map +1 -0
- package/dist/dependency-onboarding.js +3 -3
- package/dist/dependency-onboarding.js.map +1 -1
- package/dist/execution-completion.d.ts +3 -0
- package/dist/execution-completion.d.ts.map +1 -0
- package/dist/execution-completion.js +2 -0
- package/dist/execution-completion.js.map +1 -0
- package/dist/headless.d.ts +39 -0
- package/dist/headless.d.ts.map +1 -0
- package/dist/headless.js +315 -0
- package/dist/headless.js.map +1 -0
- package/dist/host.json +55 -0
- package/dist/index.d.ts +9 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -10
- package/dist/index.js.map +1 -1
- package/dist/memory/{history-view.d.ts → history-renderer.d.ts} +13 -6
- package/dist/memory/history-renderer.d.ts.map +1 -0
- package/dist/memory/{history-view.js → history-renderer.js} +34 -30
- package/dist/memory/history-renderer.js.map +1 -0
- package/dist/memory/history.d.ts +1 -31
- package/dist/memory/history.d.ts.map +1 -1
- package/dist/memory/history.js +1 -306
- package/dist/memory/history.js.map +1 -1
- package/dist/memory/ui.d.ts +5 -0
- package/dist/memory/ui.d.ts.map +1 -0
- package/dist/memory/ui.js +2 -0
- package/dist/memory/ui.js.map +1 -0
- package/dist/process-restart.d.ts +4 -6
- package/dist/process-restart.d.ts.map +1 -1
- package/dist/process-restart.js +17 -96
- package/dist/process-restart.js.map +1 -1
- package/dist/{browser → providers/browser}/authorization-host.d.ts +2 -1
- package/dist/providers/browser/authorization-host.d.ts.map +1 -0
- package/dist/{browser → providers/browser}/authorization-host.js +9 -22
- package/dist/providers/browser/authorization-host.js.map +1 -0
- package/dist/providers/browser/chrome-devtools.d.ts.map +1 -0
- package/dist/providers/browser/chrome-devtools.js.map +1 -0
- package/dist/providers/browser/connection-lease.d.ts.map +1 -0
- package/dist/providers/browser/connection-lease.js.map +1 -0
- package/dist/providers/browser-authorization.d.ts +6 -0
- package/dist/providers/browser-authorization.d.ts.map +1 -0
- package/dist/providers/browser-authorization.js +30 -0
- package/dist/providers/browser-authorization.js.map +1 -0
- package/dist/providers/classifier.d.ts.map +1 -0
- package/dist/providers/classifier.js.map +1 -0
- package/dist/providers/codemode.d.ts.map +1 -0
- package/dist/providers/codemode.js.map +1 -0
- package/dist/providers/configuration.d.ts +23 -0
- package/dist/providers/configuration.d.ts.map +1 -0
- package/dist/providers/configuration.js +154 -0
- package/dist/providers/configuration.js.map +1 -0
- package/dist/providers/credential-storage.d.ts +10 -0
- package/dist/providers/credential-storage.d.ts.map +1 -0
- package/dist/providers/credential-storage.js +57 -0
- package/dist/providers/credential-storage.js.map +1 -0
- package/dist/providers/dependencies.d.ts +3 -0
- package/dist/providers/dependencies.d.ts.map +1 -0
- package/dist/providers/dependencies.js +31 -0
- package/dist/providers/dependencies.js.map +1 -0
- package/dist/providers/execution-binding.d.ts +7 -0
- package/dist/providers/execution-binding.d.ts.map +1 -0
- package/dist/providers/execution-binding.js +180 -0
- package/dist/providers/execution-binding.js.map +1 -0
- package/dist/providers/execution-services.d.ts +24 -0
- package/dist/providers/execution-services.d.ts.map +1 -0
- package/dist/providers/execution-services.js +91 -0
- package/dist/providers/execution-services.js.map +1 -0
- package/dist/providers/extension-catalog.d.ts +30 -0
- package/dist/providers/extension-catalog.d.ts.map +1 -0
- package/dist/providers/extension-catalog.js +39 -0
- package/dist/providers/extension-catalog.js.map +1 -0
- package/dist/providers/extension-services.d.ts +14 -0
- package/dist/providers/extension-services.d.ts.map +1 -0
- package/dist/providers/extension-services.js +2 -0
- package/dist/providers/extension-services.js.map +1 -0
- package/dist/providers/extensions.d.ts +7 -0
- package/dist/providers/extensions.d.ts.map +1 -0
- package/dist/providers/extensions.js +32 -0
- package/dist/providers/extensions.js.map +1 -0
- package/dist/providers/felan-platform.d.ts +6 -0
- package/dist/providers/felan-platform.d.ts.map +1 -0
- package/dist/providers/felan-platform.js +11 -0
- package/dist/providers/felan-platform.js.map +1 -0
- package/dist/providers/global-settings.d.ts +46 -0
- package/dist/providers/global-settings.d.ts.map +1 -0
- package/dist/providers/global-settings.js +187 -0
- package/dist/providers/global-settings.js.map +1 -0
- package/dist/providers/llama/extension.d.ts +10 -0
- package/dist/providers/llama/extension.d.ts.map +1 -0
- package/dist/providers/llama/extension.js +34 -0
- package/dist/providers/llama/extension.js.map +1 -0
- package/dist/providers/llama/management.d.ts +5 -0
- package/dist/providers/llama/management.d.ts.map +1 -0
- package/dist/providers/llama/management.js +176 -0
- package/dist/providers/llama/management.js.map +1 -0
- package/dist/providers/llama/presentation.d.ts +32 -0
- package/dist/providers/llama/presentation.d.ts.map +1 -0
- package/dist/providers/llama/presentation.js +141 -0
- package/dist/providers/llama/presentation.js.map +1 -0
- package/dist/providers/llama/sdk.d.ts +71 -0
- package/dist/providers/llama/sdk.d.ts.map +1 -0
- package/dist/providers/llama/sdk.js +25 -0
- package/dist/providers/llama/sdk.js.map +1 -0
- package/dist/providers/local-model-runtime.d.ts +4 -0
- package/dist/providers/local-model-runtime.d.ts.map +1 -0
- package/dist/providers/local-model-runtime.js +11 -0
- package/dist/providers/local-model-runtime.js.map +1 -0
- package/dist/providers/local-resources.d.ts +6 -0
- package/dist/providers/local-resources.d.ts.map +1 -0
- package/dist/providers/local-resources.js +13 -0
- package/dist/providers/local-resources.js.map +1 -0
- package/dist/providers/mcp/callback-server.d.ts +3 -0
- package/dist/providers/mcp/callback-server.d.ts.map +1 -0
- package/dist/{mcp → providers/mcp}/callback-server.js +5 -1
- package/dist/providers/mcp/callback-server.js.map +1 -0
- package/dist/providers/mcp-callback.d.ts +6 -0
- package/dist/providers/mcp-callback.d.ts.map +1 -0
- package/dist/providers/mcp-callback.js +67 -0
- package/dist/providers/mcp-callback.js.map +1 -0
- package/dist/providers/model-defaults.d.ts.map +1 -0
- package/dist/providers/model-defaults.js.map +1 -0
- package/dist/providers/models-subscription.d.ts +14 -0
- package/dist/providers/models-subscription.d.ts.map +1 -0
- package/dist/{powerline.js → providers/models-subscription.js} +28 -83
- package/dist/providers/models-subscription.js.map +1 -0
- package/dist/providers/models.d.ts +18 -0
- package/dist/providers/models.d.ts.map +1 -0
- package/dist/providers/models.js +371 -0
- package/dist/providers/models.js.map +1 -0
- package/dist/providers/pi-lock.d.ts.map +1 -0
- package/dist/{pi-lock.js → providers/pi-lock.js} +1 -1
- package/dist/providers/pi-lock.js.map +1 -0
- package/dist/providers/platform.d.ts +3 -0
- package/dist/providers/platform.d.ts.map +1 -0
- package/dist/providers/platform.js +14 -0
- package/dist/providers/platform.js.map +1 -0
- package/dist/providers/process-adapter.d.ts +3 -0
- package/dist/providers/process-adapter.d.ts.map +1 -0
- package/dist/providers/process-adapter.js +46 -0
- package/dist/providers/process-adapter.js.map +1 -0
- package/dist/providers/process-bootstrap.d.ts +17 -0
- package/dist/providers/process-bootstrap.d.ts.map +1 -0
- package/dist/providers/process-bootstrap.js +87 -0
- package/dist/providers/process-bootstrap.js.map +1 -0
- package/dist/providers/project-trust.d.ts +8 -0
- package/dist/providers/project-trust.d.ts.map +1 -0
- package/dist/providers/project-trust.js +112 -0
- package/dist/providers/project-trust.js.map +1 -0
- package/dist/providers/runtime-dependencies.d.ts +6 -0
- package/dist/providers/runtime-dependencies.d.ts.map +1 -0
- package/dist/providers/runtime-dependencies.js +31 -0
- package/dist/providers/runtime-dependencies.js.map +1 -0
- package/dist/providers/runtime.d.ts +6 -0
- package/dist/providers/runtime.d.ts.map +1 -0
- package/dist/providers/runtime.js +15 -0
- package/dist/providers/runtime.js.map +1 -0
- package/dist/{savings.d.ts → providers/savings.d.ts} +7 -0
- package/dist/providers/savings.d.ts.map +1 -0
- package/dist/{savings.js → providers/savings.js} +46 -1
- package/dist/providers/savings.js.map +1 -0
- package/dist/providers/secrets.d.ts +15 -0
- package/dist/providers/secrets.d.ts.map +1 -0
- package/dist/providers/secrets.js +233 -0
- package/dist/providers/secrets.js.map +1 -0
- package/dist/providers/session-runtime.d.ts +16 -0
- package/dist/providers/session-runtime.d.ts.map +1 -0
- package/dist/providers/session-runtime.js +193 -0
- package/dist/providers/session-runtime.js.map +1 -0
- package/dist/providers/sessions.d.ts +6 -0
- package/dist/providers/sessions.d.ts.map +1 -0
- package/dist/providers/sessions.js +97 -0
- package/dist/providers/sessions.js.map +1 -0
- package/dist/providers/settings-store.d.ts +4 -0
- package/dist/providers/settings-store.d.ts.map +1 -0
- package/dist/providers/settings-store.js +70 -0
- package/dist/providers/settings-store.js.map +1 -0
- package/dist/{settings.d.ts → providers/settings.d.ts} +7 -24
- package/dist/providers/settings.d.ts.map +1 -0
- package/dist/providers/settings.js +170 -0
- package/dist/providers/settings.js.map +1 -0
- package/dist/providers/setup/auth-driver.d.ts +16 -0
- package/dist/providers/setup/auth-driver.d.ts.map +1 -0
- package/dist/providers/setup/auth-driver.js +92 -0
- package/dist/providers/setup/auth-driver.js.map +1 -0
- package/dist/providers/setup/auth-wire.d.ts +51 -0
- package/dist/providers/setup/auth-wire.d.ts.map +1 -0
- package/dist/providers/setup/auth-wire.js +17 -0
- package/dist/providers/setup/auth-wire.js.map +1 -0
- package/dist/providers/setup/auth-worker.d.ts +14 -0
- package/dist/providers/setup/auth-worker.d.ts.map +1 -0
- package/dist/providers/setup/auth-worker.js +187 -0
- package/dist/providers/setup/auth-worker.js.map +1 -0
- package/dist/providers/setup/manager.d.ts +45 -0
- package/dist/providers/setup/manager.d.ts.map +1 -0
- package/dist/providers/setup/manager.js +283 -0
- package/dist/providers/setup/manager.js.map +1 -0
- package/dist/providers/setup/parent-guard.d.ts +3 -0
- package/dist/providers/setup/parent-guard.d.ts.map +1 -0
- package/dist/providers/setup/parent-guard.js +14 -0
- package/dist/providers/setup/parent-guard.js.map +1 -0
- package/dist/providers/setup-open.d.ts +9 -0
- package/dist/providers/setup-open.d.ts.map +1 -0
- package/dist/providers/setup-open.js +32 -0
- package/dist/providers/setup-open.js.map +1 -0
- package/dist/providers/system-prompt.d.ts.map +1 -0
- package/dist/providers/system-prompt.js.map +1 -0
- package/dist/providers/tool-policy.d.ts +2 -0
- package/dist/providers/tool-policy.d.ts.map +1 -0
- package/dist/providers/tool-policy.js +14 -0
- package/dist/providers/tool-policy.js.map +1 -0
- package/dist/providers/ui/extension-ui.d.ts +7 -0
- package/dist/providers/ui/extension-ui.d.ts.map +1 -0
- package/dist/providers/ui/extension-ui.js +42 -0
- package/dist/providers/ui/extension-ui.js.map +1 -0
- package/dist/providers/ui/port.d.ts +24 -0
- package/dist/providers/ui/port.d.ts.map +1 -0
- package/dist/providers/ui/port.js +2 -0
- package/dist/providers/ui/port.js.map +1 -0
- package/dist/savings-command.d.ts +1 -1
- package/dist/savings-command.d.ts.map +1 -1
- package/dist/savings-command.js +1 -1
- package/dist/savings-command.js.map +1 -1
- package/dist/session-picker.d.ts +13 -12
- package/dist/session-picker.d.ts.map +1 -1
- package/dist/session-picker.js +13 -23
- package/dist/session-picker.js.map +1 -1
- package/dist/subagents/agent-navigator.d.ts +24 -11
- package/dist/subagents/agent-navigator.d.ts.map +1 -1
- package/dist/subagents/agent-navigator.js +154 -86
- package/dist/subagents/agent-navigator.js.map +1 -1
- package/dist/subagents/agent-transcript.d.ts +8 -2
- package/dist/subagents/agent-transcript.d.ts.map +1 -1
- package/dist/subagents/agent-transcript.js +312 -29
- package/dist/subagents/agent-transcript.js.map +1 -1
- package/dist/subagents/completion-presentation.d.ts +13 -0
- package/dist/subagents/completion-presentation.d.ts.map +1 -1
- package/dist/subagents/completion-presentation.js +15 -42
- package/dist/subagents/completion-presentation.js.map +1 -1
- package/dist/subagents/transcript-components.d.ts +107 -0
- package/dist/subagents/transcript-components.d.ts.map +1 -0
- package/dist/subagents/transcript-components.js +306 -0
- package/dist/subagents/transcript-components.js.map +1 -0
- package/dist/subagents/types.d.ts +77 -0
- package/dist/subagents/types.d.ts.map +1 -0
- package/dist/subagents/types.js +2 -0
- package/dist/subagents/types.js.map +1 -0
- package/dist/themes/felan-dark.json +1 -1
- package/dist/tool-activity/mode.d.ts +5 -0
- package/dist/tool-activity/mode.d.ts.map +1 -0
- package/dist/tool-activity/mode.js +17 -0
- package/dist/tool-activity/mode.js.map +1 -0
- package/dist/tool-activity/presentation.d.ts.map +1 -1
- package/dist/tool-activity/presentation.js +104 -28
- package/dist/tool-activity/presentation.js.map +1 -1
- package/dist/tool-activity/state.d.ts +9 -2
- package/dist/tool-activity/state.d.ts.map +1 -1
- package/dist/tool-activity/state.js +43 -3
- package/dist/tool-activity/state.js.map +1 -1
- package/dist/tui/ask-user-preferences.d.ts +9 -0
- package/dist/tui/ask-user-preferences.d.ts.map +1 -0
- package/dist/tui/ask-user-preferences.js +16 -0
- package/dist/tui/ask-user-preferences.js.map +1 -0
- package/dist/tui/command-help.d.ts +13 -0
- package/dist/tui/command-help.d.ts.map +1 -0
- package/dist/tui/command-help.js +57 -0
- package/dist/tui/command-help.js.map +1 -0
- package/dist/tui/commands.d.ts +22 -0
- package/dist/tui/commands.d.ts.map +1 -0
- package/dist/tui/commands.js +404 -0
- package/dist/tui/commands.js.map +1 -0
- package/dist/tui/completion-text.d.ts +9 -0
- package/dist/tui/completion-text.d.ts.map +1 -0
- package/dist/tui/completion-text.js +33 -0
- package/dist/tui/completion-text.js.map +1 -0
- package/dist/tui/controller.d.ts +110 -0
- package/dist/tui/controller.d.ts.map +1 -0
- package/dist/tui/controller.js +579 -0
- package/dist/tui/controller.js.map +1 -0
- package/dist/tui/dialogs.d.ts +57 -0
- package/dist/tui/dialogs.d.ts.map +1 -0
- package/dist/tui/dialogs.js +242 -0
- package/dist/tui/dialogs.js.map +1 -0
- package/dist/tui/generic-ui.d.ts +4 -0
- package/dist/tui/generic-ui.d.ts.map +1 -0
- package/dist/tui/generic-ui.js +132 -0
- package/dist/tui/generic-ui.js.map +1 -0
- package/dist/tui/herdr.d.ts +56 -0
- package/dist/tui/herdr.d.ts.map +1 -0
- package/dist/tui/herdr.js +219 -0
- package/dist/tui/herdr.js.map +1 -0
- package/dist/tui/interactions.d.ts +36 -0
- package/dist/tui/interactions.d.ts.map +1 -0
- package/dist/tui/interactions.js +253 -0
- package/dist/tui/interactions.js.map +1 -0
- package/dist/tui/keybindings.d.ts +15 -0
- package/dist/tui/keybindings.d.ts.map +1 -0
- package/dist/tui/keybindings.js +101 -0
- package/dist/tui/keybindings.js.map +1 -0
- package/dist/tui/markdown.d.ts +4 -0
- package/dist/tui/markdown.d.ts.map +1 -0
- package/dist/tui/markdown.js +6 -0
- package/dist/tui/markdown.js.map +1 -0
- package/dist/tui/preferences-schema.d.ts +121 -0
- package/dist/tui/preferences-schema.d.ts.map +1 -0
- package/dist/tui/preferences-schema.js +42 -0
- package/dist/tui/preferences-schema.js.map +1 -0
- package/dist/tui/preferences-store.d.ts +22 -0
- package/dist/tui/preferences-store.d.ts.map +1 -0
- package/dist/tui/preferences-store.js +240 -0
- package/dist/tui/preferences-store.js.map +1 -0
- package/dist/tui/preferences.d.ts +42 -0
- package/dist/tui/preferences.d.ts.map +1 -0
- package/dist/tui/preferences.js +246 -0
- package/dist/tui/preferences.js.map +1 -0
- package/dist/tui/presentation-preferences.d.ts +11 -0
- package/dist/tui/presentation-preferences.d.ts.map +1 -0
- package/dist/tui/presentation-preferences.js +29 -0
- package/dist/tui/presentation-preferences.js.map +1 -0
- package/dist/tui/presentation-ui.d.ts +7 -0
- package/dist/tui/presentation-ui.d.ts.map +1 -0
- package/dist/tui/presentation-ui.js +17 -0
- package/dist/tui/presentation-ui.js.map +1 -0
- package/dist/tui/presenters.d.ts +18 -0
- package/dist/tui/presenters.d.ts.map +1 -0
- package/dist/tui/presenters.js +118 -0
- package/dist/tui/presenters.js.map +1 -0
- package/dist/tui/remote.d.ts +7 -0
- package/dist/tui/remote.d.ts.map +1 -0
- package/dist/tui/remote.js +139 -0
- package/dist/tui/remote.js.map +1 -0
- package/dist/tui/renderers/ask-user/single-select-layout.d.ts +20 -0
- package/dist/tui/renderers/ask-user/single-select-layout.d.ts.map +1 -0
- package/dist/tui/renderers/ask-user/single-select-layout.js +111 -0
- package/dist/tui/renderers/ask-user/single-select-layout.js.map +1 -0
- package/dist/tui/renderers/ask-user.d.ts +21 -0
- package/dist/tui/renderers/ask-user.d.ts.map +1 -0
- package/dist/tui/renderers/ask-user.js +1348 -0
- package/dist/tui/renderers/ask-user.js.map +1 -0
- package/dist/tui/renderers/codebase-memory.d.ts +3 -0
- package/dist/tui/renderers/codebase-memory.d.ts.map +1 -0
- package/dist/tui/renderers/codebase-memory.js +38 -0
- package/dist/tui/renderers/codebase-memory.js.map +1 -0
- package/dist/tui/renderers/codex.d.ts +5 -0
- package/dist/tui/renderers/codex.d.ts.map +1 -0
- package/dist/tui/renderers/codex.js +9 -0
- package/dist/tui/renderers/codex.js.map +1 -0
- package/dist/tui/renderers/context-view.d.ts +3 -0
- package/dist/tui/renderers/context-view.d.ts.map +1 -0
- package/dist/tui/renderers/context-view.js +69 -0
- package/dist/tui/renderers/context-view.js.map +1 -0
- package/dist/{fusion → tui/renderers/fusion}/model-picker.d.ts +2 -1
- package/dist/tui/renderers/fusion/model-picker.d.ts.map +1 -0
- package/dist/{fusion → tui/renderers/fusion}/model-picker.js +1 -0
- package/dist/tui/renderers/fusion/model-picker.js.map +1 -0
- package/dist/tui/renderers/fusion.d.ts +7 -0
- package/dist/tui/renderers/fusion.d.ts.map +1 -0
- package/dist/tui/renderers/fusion.js +266 -0
- package/dist/tui/renderers/fusion.js.map +1 -0
- package/dist/tui/renderers/insights/charts.d.ts +14 -0
- package/dist/tui/renderers/insights/charts.d.ts.map +1 -0
- package/dist/tui/renderers/insights/charts.js +77 -0
- package/dist/tui/renderers/insights/charts.js.map +1 -0
- package/dist/tui/renderers/insights/panel.d.ts +55 -0
- package/dist/tui/renderers/insights/panel.d.ts.map +1 -0
- package/dist/tui/renderers/insights/panel.js +310 -0
- package/dist/tui/renderers/insights/panel.js.map +1 -0
- package/dist/tui/renderers/insights.d.ts +4 -0
- package/dist/tui/renderers/insights.d.ts.map +1 -0
- package/dist/tui/renderers/insights.js +51 -0
- package/dist/tui/renderers/insights.js.map +1 -0
- package/dist/tui/renderers/memory.d.ts +5 -0
- package/dist/tui/renderers/memory.d.ts.map +1 -0
- package/dist/tui/renderers/memory.js +99 -0
- package/dist/tui/renderers/memory.js.map +1 -0
- package/dist/tui/renderers/navigation.d.ts +7 -0
- package/dist/tui/renderers/navigation.d.ts.map +1 -0
- package/dist/tui/renderers/navigation.js +14 -0
- package/dist/tui/renderers/navigation.js.map +1 -0
- package/dist/tui/renderers/powerline/colors.d.ts +18 -0
- package/dist/tui/renderers/powerline/colors.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/colors.js +42 -0
- package/dist/tui/renderers/powerline/colors.js.map +1 -0
- package/dist/tui/renderers/powerline/config.d.ts +44 -0
- package/dist/tui/renderers/powerline/config.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/config.js +123 -0
- package/dist/tui/renderers/powerline/config.js.map +1 -0
- package/dist/tui/renderers/powerline/footer-renderer.d.ts +7 -0
- package/dist/tui/renderers/powerline/footer-renderer.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/footer-renderer.js +74 -0
- package/dist/tui/renderers/powerline/footer-renderer.js.map +1 -0
- package/dist/tui/renderers/powerline/projected-footer.d.ts +24 -0
- package/dist/tui/renderers/powerline/projected-footer.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/projected-footer.js +33 -0
- package/dist/tui/renderers/powerline/projected-footer.js.map +1 -0
- package/dist/tui/renderers/powerline/segments.d.ts +18 -0
- package/dist/tui/renderers/powerline/segments.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/segments.js +331 -0
- package/dist/tui/renderers/powerline/segments.js.map +1 -0
- package/dist/tui/renderers/powerline/symbols.d.ts +27 -0
- package/dist/tui/renderers/powerline/symbols.d.ts.map +1 -0
- package/dist/tui/renderers/powerline/symbols.js +17 -0
- package/dist/tui/renderers/powerline/symbols.js.map +1 -0
- package/dist/tui/renderers/powerline.d.ts +4 -0
- package/dist/tui/renderers/powerline.d.ts.map +1 -0
- package/dist/tui/renderers/powerline.js +4 -0
- package/dist/tui/renderers/powerline.js.map +1 -0
- package/dist/tui/renderers/prewalk/plan-review.d.ts +28 -0
- package/dist/tui/renderers/prewalk/plan-review.d.ts.map +1 -0
- package/dist/tui/renderers/prewalk/plan-review.js +414 -0
- package/dist/tui/renderers/prewalk/plan-review.js.map +1 -0
- package/dist/tui/renderers/prewalk.d.ts +5 -0
- package/dist/tui/renderers/prewalk.d.ts.map +1 -0
- package/dist/tui/renderers/prewalk.js +43 -0
- package/dist/tui/renderers/prewalk.js.map +1 -0
- package/dist/tui/renderers/processes/background-bash-view.d.ts +45 -0
- package/dist/tui/renderers/processes/background-bash-view.d.ts.map +1 -0
- package/dist/tui/renderers/processes/background-bash-view.js +405 -0
- package/dist/tui/renderers/processes/background-bash-view.js.map +1 -0
- package/dist/tui/renderers/processes/completion-message.d.ts +26 -0
- package/dist/tui/renderers/processes/completion-message.d.ts.map +1 -0
- package/dist/tui/renderers/processes/completion-message.js +97 -0
- package/dist/tui/renderers/processes/completion-message.js.map +1 -0
- package/dist/tui/renderers/processes/process-view.d.ts +40 -0
- package/dist/tui/renderers/processes/process-view.d.ts.map +1 -0
- package/dist/tui/renderers/processes/process-view.js +250 -0
- package/dist/tui/renderers/processes/process-view.js.map +1 -0
- package/dist/tui/renderers/processes.d.ts +12 -0
- package/dist/tui/renderers/processes.d.ts.map +1 -0
- package/dist/tui/renderers/processes.js +80 -0
- package/dist/tui/renderers/processes.js.map +1 -0
- package/dist/tui/renderers/prompt-history/picker.d.ts +64 -0
- package/dist/tui/renderers/prompt-history/picker.d.ts.map +1 -0
- package/dist/tui/renderers/prompt-history/picker.js +430 -0
- package/dist/tui/renderers/prompt-history/picker.js.map +1 -0
- package/dist/tui/renderers/prompt-history.d.ts +16 -0
- package/dist/tui/renderers/prompt-history.d.ts.map +1 -0
- package/dist/tui/renderers/prompt-history.js +113 -0
- package/dist/tui/renderers/prompt-history.js.map +1 -0
- package/dist/tui/renderers/tasks/tasks-overlay.d.ts +37 -0
- package/dist/tui/renderers/tasks/tasks-overlay.d.ts.map +1 -0
- package/dist/tui/renderers/tasks/tasks-overlay.js +461 -0
- package/dist/tui/renderers/tasks/tasks-overlay.js.map +1 -0
- package/dist/tui/renderers/tasks.d.ts +18 -0
- package/dist/tui/renderers/tasks.d.ts.map +1 -0
- package/dist/tui/renderers/tasks.js +97 -0
- package/dist/tui/renderers/tasks.js.map +1 -0
- package/dist/tui/run.d.ts +22 -0
- package/dist/tui/run.d.ts.map +1 -0
- package/dist/tui/run.js +249 -0
- package/dist/tui/run.js.map +1 -0
- package/dist/tui/screen.d.ts +73 -0
- package/dist/tui/screen.d.ts.map +1 -0
- package/dist/tui/screen.js +371 -0
- package/dist/tui/screen.js.map +1 -0
- package/dist/tui/session-navigator.d.ts +53 -0
- package/dist/tui/session-navigator.d.ts.map +1 -0
- package/dist/tui/session-navigator.js +256 -0
- package/dist/tui/session-navigator.js.map +1 -0
- package/dist/tui/settings-menu.d.ts +31 -0
- package/dist/tui/settings-menu.d.ts.map +1 -0
- package/dist/tui/settings-menu.js +78 -0
- package/dist/tui/settings-menu.js.map +1 -0
- package/dist/tui/setup-ui.d.ts +14 -0
- package/dist/tui/setup-ui.d.ts.map +1 -0
- package/dist/tui/setup-ui.js +122 -0
- package/dist/tui/setup-ui.js.map +1 -0
- package/dist/tui/setup.d.ts +29 -0
- package/dist/tui/setup.d.ts.map +1 -0
- package/dist/tui/setup.js +414 -0
- package/dist/tui/setup.js.map +1 -0
- package/dist/tui/shell-execution.d.ts +20 -0
- package/dist/tui/shell-execution.d.ts.map +1 -0
- package/dist/tui/shell-execution.js +64 -0
- package/dist/tui/shell-execution.js.map +1 -0
- package/dist/tui/startup-header.d.ts +4 -0
- package/dist/tui/startup-header.d.ts.map +1 -0
- package/dist/tui/startup-header.js +19 -0
- package/dist/tui/startup-header.js.map +1 -0
- package/dist/tui/streaming-markdown.d.ts +21 -0
- package/dist/tui/streaming-markdown.d.ts.map +1 -0
- package/dist/tui/streaming-markdown.js +118 -0
- package/dist/tui/streaming-markdown.js.map +1 -0
- package/dist/tui/theme-config.d.ts +26 -0
- package/dist/tui/theme-config.d.ts.map +1 -0
- package/dist/tui/theme-config.js +87 -0
- package/dist/tui/theme-config.js.map +1 -0
- package/dist/tui/theme-picker.d.ts +23 -0
- package/dist/tui/theme-picker.d.ts.map +1 -0
- package/dist/tui/theme-picker.js +91 -0
- package/dist/tui/theme-picker.js.map +1 -0
- package/dist/tui/theme.d.ts +15 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/theme.js +216 -0
- package/dist/tui/theme.js.map +1 -0
- package/dist/tui/tool-inspector.d.ts +24 -0
- package/dist/tui/tool-inspector.d.ts.map +1 -0
- package/dist/tui/tool-inspector.js +81 -0
- package/dist/tui/tool-inspector.js.map +1 -0
- package/dist/tui/tool-presentation.d.ts +3 -0
- package/dist/tui/tool-presentation.d.ts.map +1 -0
- package/dist/tui/tool-presentation.js +22 -0
- package/dist/tui/tool-presentation.js.map +1 -0
- package/dist/tui/transcript.d.ts +6 -0
- package/dist/tui/transcript.d.ts.map +1 -0
- package/dist/tui/transcript.js +78 -0
- package/dist/tui/transcript.js.map +1 -0
- package/dist/tui/tree-navigator.d.ts +71 -0
- package/dist/tui/tree-navigator.d.ts.map +1 -0
- package/dist/tui/tree-navigator.js +522 -0
- package/dist/tui/tree-navigator.js.map +1 -0
- package/npm-shrinkwrap.json +3637 -0
- package/package.json +79 -30
- package/dist/acp/interactions.d.ts +0 -22
- package/dist/acp/interactions.d.ts.map +0 -1
- package/dist/acp/interactions.js +0 -353
- package/dist/acp/interactions.js.map +0 -1
- package/dist/application.d.ts +0 -23
- package/dist/application.d.ts.map +0 -1
- package/dist/application.js +0 -267
- package/dist/application.js.map +0 -1
- package/dist/browser/authorization-host.d.ts.map +0 -1
- package/dist/browser/authorization-host.js.map +0 -1
- package/dist/browser/chrome-devtools.d.ts.map +0 -1
- package/dist/browser/chrome-devtools.js.map +0 -1
- package/dist/browser/connection-lease.d.ts.map +0 -1
- package/dist/browser/connection-lease.js.map +0 -1
- package/dist/classifier-settings.d.ts +0 -10
- package/dist/classifier-settings.d.ts.map +0 -1
- package/dist/classifier-settings.js +0 -98
- package/dist/classifier-settings.js.map +0 -1
- package/dist/classifier.d.ts.map +0 -1
- package/dist/classifier.js.map +0 -1
- package/dist/codemode.d.ts.map +0 -1
- package/dist/codemode.js.map +0 -1
- package/dist/codex.d.ts +0 -3
- package/dist/codex.d.ts.map +0 -1
- package/dist/codex.js +0 -8
- package/dist/codex.js.map +0 -1
- package/dist/command-autocomplete.d.ts +0 -3
- package/dist/command-autocomplete.d.ts.map +0 -1
- package/dist/command-autocomplete.js +0 -10
- package/dist/command-autocomplete.js.map +0 -1
- package/dist/cwd-command.d.ts +0 -13
- package/dist/cwd-command.d.ts.map +0 -1
- package/dist/cwd-command.js +0 -176
- package/dist/cwd-command.js.map +0 -1
- package/dist/dependencies.d.ts +0 -37
- package/dist/dependencies.d.ts.map +0 -1
- package/dist/dependencies.js +0 -372
- package/dist/dependencies.js.map +0 -1
- package/dist/extension-settings.d.ts +0 -12
- package/dist/extension-settings.d.ts.map +0 -1
- package/dist/extension-settings.js +0 -241
- package/dist/extension-settings.js.map +0 -1
- package/dist/extensions.d.ts +0 -62
- package/dist/extensions.d.ts.map +0 -1
- package/dist/extensions.js +0 -265
- package/dist/extensions.js.map +0 -1
- package/dist/fusion/host.d.ts +0 -3
- package/dist/fusion/host.d.ts.map +0 -1
- package/dist/fusion/host.js +0 -333
- package/dist/fusion/host.js.map +0 -1
- package/dist/fusion/model-picker.d.ts.map +0 -1
- package/dist/fusion/model-picker.js.map +0 -1
- package/dist/herdr.d.ts +0 -29
- package/dist/herdr.d.ts.map +0 -1
- package/dist/herdr.js +0 -247
- package/dist/herdr.js.map +0 -1
- package/dist/insights.d.ts +0 -5
- package/dist/insights.d.ts.map +0 -1
- package/dist/insights.js +0 -140
- package/dist/insights.js.map +0 -1
- package/dist/lock.d.ts +0 -27
- package/dist/lock.d.ts.map +0 -1
- package/dist/lock.js +0 -432
- package/dist/lock.js.map +0 -1
- package/dist/logger.d.ts +0 -7
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -48
- package/dist/logger.js.map +0 -1
- package/dist/mcp/callback-server.d.ts +0 -11
- package/dist/mcp/callback-server.d.ts.map +0 -1
- package/dist/mcp/callback-server.js.map +0 -1
- package/dist/mcp/config.d.ts +0 -20
- package/dist/mcp/config.d.ts.map +0 -1
- package/dist/mcp/config.js +0 -352
- package/dist/mcp/config.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -3
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -25
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/oauth-host.d.ts +0 -42
- package/dist/mcp/oauth-host.d.ts.map +0 -1
- package/dist/mcp/oauth-host.js +0 -524
- package/dist/mcp/oauth-host.js.map +0 -1
- package/dist/mcp/oauth-store.d.ts +0 -27
- package/dist/mcp/oauth-store.d.ts.map +0 -1
- package/dist/mcp/oauth-store.js +0 -138
- package/dist/mcp/oauth-store.js.map +0 -1
- package/dist/memory/control.d.ts +0 -8
- package/dist/memory/control.d.ts.map +0 -1
- package/dist/memory/control.js +0 -167
- package/dist/memory/control.js.map +0 -1
- package/dist/memory/coordinator.d.ts +0 -53
- package/dist/memory/coordinator.d.ts.map +0 -1
- package/dist/memory/coordinator.js +0 -807
- package/dist/memory/coordinator.js.map +0 -1
- package/dist/memory/dreamer.d.ts +0 -50
- package/dist/memory/dreamer.d.ts.map +0 -1
- package/dist/memory/dreamer.js +0 -527
- package/dist/memory/dreamer.js.map +0 -1
- package/dist/memory/history-view.d.ts.map +0 -1
- package/dist/memory/history-view.js.map +0 -1
- package/dist/memory/lease.d.ts +0 -13
- package/dist/memory/lease.d.ts.map +0 -1
- package/dist/memory/lease.js +0 -188
- package/dist/memory/lease.js.map +0 -1
- package/dist/memory/project.d.ts +0 -7
- package/dist/memory/project.d.ts.map +0 -1
- package/dist/memory/project.js +0 -41
- package/dist/memory/project.js.map +0 -1
- package/dist/memory/run-retention.d.ts +0 -12
- package/dist/memory/run-retention.d.ts.map +0 -1
- package/dist/memory/run-retention.js +0 -294
- package/dist/memory/run-retention.js.map +0 -1
- package/dist/memory/run.d.ts +0 -79
- package/dist/memory/run.d.ts.map +0 -1
- package/dist/memory/run.js +0 -417
- package/dist/memory/run.js.map +0 -1
- package/dist/memory/store.d.ts +0 -116
- package/dist/memory/store.d.ts.map +0 -1
- package/dist/memory/store.js +0 -751
- package/dist/memory/store.js.map +0 -1
- package/dist/model-defaults.d.ts.map +0 -1
- package/dist/model-defaults.js.map +0 -1
- package/dist/model-selector.d.ts +0 -5
- package/dist/model-selector.d.ts.map +0 -1
- package/dist/model-selector.js +0 -87
- package/dist/model-selector.js.map +0 -1
- package/dist/output-style-instructions.d.ts +0 -6
- package/dist/output-style-instructions.d.ts.map +0 -1
- package/dist/output-style-instructions.js +0 -53
- package/dist/output-style-instructions.js.map +0 -1
- package/dist/overlay-images.d.ts +0 -9
- package/dist/overlay-images.d.ts.map +0 -1
- package/dist/overlay-images.js +0 -99
- package/dist/overlay-images.js.map +0 -1
- package/dist/pi-extensions.d.ts +0 -28
- package/dist/pi-extensions.d.ts.map +0 -1
- package/dist/pi-extensions.js +0 -141
- package/dist/pi-extensions.js.map +0 -1
- package/dist/pi-llama.d.ts +0 -2
- package/dist/pi-llama.d.ts.map +0 -1
- package/dist/pi-llama.js +0 -15
- package/dist/pi-llama.js.map +0 -1
- package/dist/pi-lock.d.ts.map +0 -1
- package/dist/pi-lock.js.map +0 -1
- package/dist/powerline.d.ts +0 -12
- package/dist/powerline.d.ts.map +0 -1
- package/dist/powerline.js.map +0 -1
- package/dist/project-trust-prompt.d.ts +0 -30
- package/dist/project-trust-prompt.d.ts.map +0 -1
- package/dist/project-trust-prompt.js +0 -122
- package/dist/project-trust-prompt.js.map +0 -1
- package/dist/project-trust.d.ts +0 -8
- package/dist/project-trust.d.ts.map +0 -1
- package/dist/project-trust.js +0 -36
- package/dist/project-trust.js.map +0 -1
- package/dist/prompt-history.d.ts +0 -11
- package/dist/prompt-history.d.ts.map +0 -1
- package/dist/prompt-history.js +0 -96
- package/dist/prompt-history.js.map +0 -1
- package/dist/restart-command.d.ts +0 -9
- package/dist/restart-command.d.ts.map +0 -1
- package/dist/restart-command.js +0 -94
- package/dist/restart-command.js.map +0 -1
- package/dist/resume.d.ts +0 -5
- package/dist/resume.d.ts.map +0 -1
- package/dist/resume.js +0 -46
- package/dist/resume.js.map +0 -1
- package/dist/runtime-factory.d.ts +0 -12
- package/dist/runtime-factory.d.ts.map +0 -1
- package/dist/runtime-factory.js +0 -12
- package/dist/runtime-factory.js.map +0 -1
- package/dist/runtime.d.ts +0 -59
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -534
- package/dist/runtime.js.map +0 -1
- package/dist/savings.d.ts.map +0 -1
- package/dist/savings.js.map +0 -1
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -359
- package/dist/settings.js.map +0 -1
- package/dist/startup-header.d.ts +0 -9
- package/dist/startup-header.d.ts.map +0 -1
- package/dist/startup-header.js +0 -151
- package/dist/startup-header.js.map +0 -1
- package/dist/subagents/catalog.d.ts +0 -8
- package/dist/subagents/catalog.d.ts.map +0 -1
- package/dist/subagents/catalog.js +0 -136
- package/dist/subagents/catalog.js.map +0 -1
- package/dist/subagents/host.d.ts +0 -133
- package/dist/subagents/host.d.ts.map +0 -1
- package/dist/subagents/host.js +0 -1420
- package/dist/subagents/host.js.map +0 -1
- package/dist/subagents/store.d.ts +0 -25
- package/dist/subagents/store.d.ts.map +0 -1
- package/dist/subagents/store.js +0 -35
- package/dist/subagents/store.js.map +0 -1
- package/dist/system-prompt.d.ts.map +0 -1
- package/dist/system-prompt.js.map +0 -1
- package/dist/tui-compatibility.d.ts +0 -4
- package/dist/tui-compatibility.d.ts.map +0 -1
- package/dist/tui-compatibility.js +0 -244
- package/dist/tui-compatibility.js.map +0 -1
- package/dist/update-notification.d.ts +0 -3
- package/dist/update-notification.d.ts.map +0 -1
- package/dist/update-notification.js +0 -50
- package/dist/update-notification.js.map +0 -1
- /package/dist/{browser → providers/browser}/chrome-devtools.d.ts +0 -0
- /package/dist/{browser → providers/browser}/chrome-devtools.js +0 -0
- /package/dist/{browser → providers/browser}/connection-lease.d.ts +0 -0
- /package/dist/{browser → providers/browser}/connection-lease.js +0 -0
- /package/dist/{classifier.d.ts → providers/classifier.d.ts} +0 -0
- /package/dist/{classifier.js → providers/classifier.js} +0 -0
- /package/dist/{codemode.d.ts → providers/codemode.d.ts} +0 -0
- /package/dist/{codemode.js → providers/codemode.js} +0 -0
- /package/dist/{model-defaults.d.ts → providers/model-defaults.d.ts} +0 -0
- /package/dist/{model-defaults.js → providers/model-defaults.js} +0 -0
- /package/dist/{pi-lock.d.ts → providers/pi-lock.d.ts} +0 -0
- /package/dist/{system-prompt.d.ts → providers/system-prompt.d.ts} +0 -0
- /package/dist/{system-prompt.js → providers/system-prompt.js} +0 -0
package/dist/subagents/host.js
DELETED
|
@@ -1,1420 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { mkdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { HostAgentRuntime, SessionManager, createAgentCoreSession, } from '@felan-ai/agent-core';
|
|
4
|
-
import { bindSubagentSession, } from '@felan-ai/ext-subagents';
|
|
5
|
-
import { CURRENT_SESSION_VERSION, } from '@earendil-works/pi-coding-agent';
|
|
6
|
-
import { createLocalExtensionImporter } from '../extensions.js';
|
|
7
|
-
import { createLocalAgentLogger } from '../logger.js';
|
|
8
|
-
import { createLocalCodexStreamFunctionWrapper } from '../codex.js';
|
|
9
|
-
import { createLocalAgentRuntimeFactoryRequest, } from '../runtime-factory.js';
|
|
10
|
-
import { loadLocalChildSystemPromptAppends } from '../system-prompt.js';
|
|
11
|
-
import { discoverLocalSubagents } from './catalog.js';
|
|
12
|
-
import { LocalSubagentStore } from './store.js';
|
|
13
|
-
const EXT_SUBAGENTS = '@felan-ai/ext-subagents';
|
|
14
|
-
const MAX_RESULT_BYTES = 256 * 1024;
|
|
15
|
-
const SYNTHESIS_PROMPT = 'Stop using tools. Summarize the work completed, findings, and any remaining uncertainty in a concise final response.';
|
|
16
|
-
export function createLocalSubagentExtensionImporter(options, subagents, memoryHost) {
|
|
17
|
-
return createLocalExtensionImporter(subagents, options.modelRuntime, options.importExtension, undefined, memoryHost === undefined ? undefined : { role: 'reader', host: memoryHost }, options.outputStyle, undefined, undefined, options.backgroundBashCoordinator, options.backgroundBashCoordinatorOwner);
|
|
18
|
-
}
|
|
19
|
-
export class LocalSubagentHost {
|
|
20
|
-
descriptors;
|
|
21
|
-
policy;
|
|
22
|
-
#manager;
|
|
23
|
-
#sessionId;
|
|
24
|
-
constructor(manager, sessionId) {
|
|
25
|
-
this.#manager = manager;
|
|
26
|
-
this.#sessionId = sessionId;
|
|
27
|
-
this.descriptors = manager.descriptors;
|
|
28
|
-
this.policy = manager.policy;
|
|
29
|
-
}
|
|
30
|
-
static async create(options) {
|
|
31
|
-
const definitions = await discoverLocalSubagents(options.cwd, options.agentDir, options.homeDir);
|
|
32
|
-
const manager = await LocalSubagentManager.create(options, definitions);
|
|
33
|
-
return new LocalSubagentHost(manager, options.sessionId);
|
|
34
|
-
}
|
|
35
|
-
attachParent(port) {
|
|
36
|
-
return this.#manager.attachParent(this.#sessionId, port);
|
|
37
|
-
}
|
|
38
|
-
spawn(request, signal) {
|
|
39
|
-
return this.#manager.spawn(this.#sessionId, request, signal);
|
|
40
|
-
}
|
|
41
|
-
list(options) {
|
|
42
|
-
return this.#manager.list(this.#sessionId, options);
|
|
43
|
-
}
|
|
44
|
-
getResult(agentId, options) {
|
|
45
|
-
return this.#manager.getResult(this.#sessionId, agentId, options);
|
|
46
|
-
}
|
|
47
|
-
listLocalSubagents() {
|
|
48
|
-
return this.#manager.listLocalSubagents(this.#sessionId);
|
|
49
|
-
}
|
|
50
|
-
getLocalSubagent(agentId) {
|
|
51
|
-
return this.#manager.getLocalSubagent(this.#sessionId, agentId);
|
|
52
|
-
}
|
|
53
|
-
steer(agentId, message) {
|
|
54
|
-
return this.#manager.steer(this.#sessionId, agentId, message);
|
|
55
|
-
}
|
|
56
|
-
cancel(agentId, reason) {
|
|
57
|
-
return this.#manager.cancel(this.#sessionId, agentId, reason);
|
|
58
|
-
}
|
|
59
|
-
subscribe(listener) {
|
|
60
|
-
return this.#manager.subscribe(listener);
|
|
61
|
-
}
|
|
62
|
-
hasPendingWork() {
|
|
63
|
-
return this.#manager.hasPendingWork(this.#sessionId);
|
|
64
|
-
}
|
|
65
|
-
getUsage() {
|
|
66
|
-
return this.#manager.getUsage();
|
|
67
|
-
}
|
|
68
|
-
subscribeUsage(listener) {
|
|
69
|
-
return this.#manager.subscribeUsage(listener);
|
|
70
|
-
}
|
|
71
|
-
async shutdown() {
|
|
72
|
-
await this.#manager.shutdown();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export class LocalSubagentManager {
|
|
76
|
-
definitions;
|
|
77
|
-
descriptors;
|
|
78
|
-
policy;
|
|
79
|
-
#options;
|
|
80
|
-
#store;
|
|
81
|
-
#savingsReporter;
|
|
82
|
-
#children = new Map();
|
|
83
|
-
#ports = new Map();
|
|
84
|
-
#jobs = new Map();
|
|
85
|
-
#queue = [];
|
|
86
|
-
#listeners = new Set();
|
|
87
|
-
#usageListeners = new Set();
|
|
88
|
-
#deliveries = new Map();
|
|
89
|
-
#deliveryAttempts = new Map();
|
|
90
|
-
#deliveryTimers = new Map();
|
|
91
|
-
#concurrency;
|
|
92
|
-
#maxDepth;
|
|
93
|
-
#active = 0;
|
|
94
|
-
#closed = false;
|
|
95
|
-
#save = Promise.resolve();
|
|
96
|
-
#control = Promise.resolve();
|
|
97
|
-
#shutdown;
|
|
98
|
-
constructor(options, definitions) {
|
|
99
|
-
this.#options = options;
|
|
100
|
-
this.definitions = new Map(definitions.map((definition) => [definition.descriptor.id, definition]));
|
|
101
|
-
this.descriptors = Object.freeze(definitions.map((definition) => definition.descriptor));
|
|
102
|
-
this.#concurrency = boundedInteger(options.settings?.concurrency, 4, 1, 32);
|
|
103
|
-
this.#maxDepth = boundedInteger(options.settings?.maxDepth, 3, 1, 10);
|
|
104
|
-
this.#savingsReporter = options.savings?.createReporter(EXT_SUBAGENTS);
|
|
105
|
-
this.policy = Object.freeze({
|
|
106
|
-
maxPromptBytes: 128 * 1024,
|
|
107
|
-
maxDescriptionBytes: 512,
|
|
108
|
-
maxSteerBytes: 32 * 1024,
|
|
109
|
-
});
|
|
110
|
-
this.#store = new LocalSubagentStore(options.agentDir, options.sessionId);
|
|
111
|
-
}
|
|
112
|
-
static async create(options, definitions) {
|
|
113
|
-
const manager = new LocalSubagentManager(options, definitions);
|
|
114
|
-
const loaded = await manager.#store.load();
|
|
115
|
-
let reconciled = false;
|
|
116
|
-
const interrupted = new Set();
|
|
117
|
-
for (const stored of loaded) {
|
|
118
|
-
const child = fromStored(stored);
|
|
119
|
-
if (child.record.status === 'queued' || child.record.status === 'running') {
|
|
120
|
-
child.record = terminalRecord(child.record, 'cancelled', {
|
|
121
|
-
code: 'host_shutdown',
|
|
122
|
-
message: 'Local subagent was interrupted when the previous Felan Code process exited',
|
|
123
|
-
});
|
|
124
|
-
child.completionPending = child.deliveryId !== undefined;
|
|
125
|
-
interrupted.add(child.record.agentId);
|
|
126
|
-
reconciled = true;
|
|
127
|
-
}
|
|
128
|
-
manager.#children.set(child.record.agentId, child);
|
|
129
|
-
}
|
|
130
|
-
for (const child of manager.#children.values()) {
|
|
131
|
-
if (!child.sessionFile)
|
|
132
|
-
continue;
|
|
133
|
-
const usage = await loadSessionUsage(child.sessionFile, child.record.agentId);
|
|
134
|
-
if (usage)
|
|
135
|
-
child.usage = usage;
|
|
136
|
-
else
|
|
137
|
-
delete child.usage;
|
|
138
|
-
if (usage && (interrupted.has(child.record.agentId) || child.reportedSavings === undefined)) {
|
|
139
|
-
child.reportedSavings = { ...usage };
|
|
140
|
-
reconciled = true;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (reconciled)
|
|
144
|
-
await manager.#persist();
|
|
145
|
-
return manager;
|
|
146
|
-
}
|
|
147
|
-
attachParent(sessionId, port) {
|
|
148
|
-
this.#ports.set(sessionId, port);
|
|
149
|
-
const replay = setTimeout(() => {
|
|
150
|
-
this.#deliverPending(sessionId).catch(() => { });
|
|
151
|
-
}, 0);
|
|
152
|
-
replay.unref();
|
|
153
|
-
return () => {
|
|
154
|
-
clearTimeout(replay);
|
|
155
|
-
if (this.#ports.get(sessionId) === port)
|
|
156
|
-
this.#ports.delete(sessionId);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
async spawn(parentSessionId, request, signal) {
|
|
160
|
-
if (this.#closed)
|
|
161
|
-
return failure('host_unavailable', 'Local subagent host is closed');
|
|
162
|
-
if (signal?.aborted)
|
|
163
|
-
return failure('invalid_request', 'Subagent startup was aborted');
|
|
164
|
-
if (byteLength(request.prompt) > this.policy.maxPromptBytes
|
|
165
|
-
|| byteLength(request.description) > this.policy.maxDescriptionBytes) {
|
|
166
|
-
return failure('invalid_request', 'Subagent prompt or description exceeds local policy');
|
|
167
|
-
}
|
|
168
|
-
if (request.maxTurns !== undefined && (!Number.isInteger(request.maxTurns) || request.maxTurns < 1 || request.maxTurns > 100)) {
|
|
169
|
-
return failure('invalid_request', 'maxTurns must be an integer from 1 to 100');
|
|
170
|
-
}
|
|
171
|
-
if (request.timeoutSeconds !== undefined
|
|
172
|
-
&& (!Number.isInteger(request.timeoutSeconds) || request.timeoutSeconds < 1 || request.timeoutSeconds > 86_400)) {
|
|
173
|
-
return failure('invalid_request', 'timeoutSeconds must be an integer from 1 to 86400');
|
|
174
|
-
}
|
|
175
|
-
const definition = this.definitions.get(request.type);
|
|
176
|
-
if (!definition)
|
|
177
|
-
return failure('unknown_agent_type', `Unknown subagent type: ${request.type}`);
|
|
178
|
-
const resolvedModel = this.#resolveModel(request.model);
|
|
179
|
-
if (!resolvedModel.ok)
|
|
180
|
-
return resolvedModel;
|
|
181
|
-
if (!this.#supportsThinking(resolvedModel.value, request.thinking)) {
|
|
182
|
-
return failure('unsupported_thinking', 'The resolved model does not support the requested thinking level');
|
|
183
|
-
}
|
|
184
|
-
const normalizedRequest = {
|
|
185
|
-
...request,
|
|
186
|
-
...(resolvedModel.value === undefined ? {} : { model: resolvedModel.value }),
|
|
187
|
-
};
|
|
188
|
-
const admitted = await this.#serializeControl(async () => {
|
|
189
|
-
if (this.#closed)
|
|
190
|
-
return failure('host_unavailable', 'Local subagent host is closed');
|
|
191
|
-
if (signal?.aborted)
|
|
192
|
-
return failure('invalid_request', 'Subagent startup was aborted');
|
|
193
|
-
const context = this.#sessionContext(parentSessionId);
|
|
194
|
-
if (!context)
|
|
195
|
-
return failure('parent_unavailable', 'Parent subagent is unavailable');
|
|
196
|
-
if (context.depth >= this.#maxDepth) {
|
|
197
|
-
return failure('depth_exceeded', 'Maximum local subagent depth reached');
|
|
198
|
-
}
|
|
199
|
-
const parent = context.child;
|
|
200
|
-
const parentJob = this.#jobs.get(parentSessionId);
|
|
201
|
-
if (parent
|
|
202
|
-
&& (isTerminal(parent.record.status) || parentJob?.terminalStatus !== undefined)) {
|
|
203
|
-
return failure('parent_unavailable', 'Parent subagent is no longer active');
|
|
204
|
-
}
|
|
205
|
-
if (parent
|
|
206
|
-
&& !this.definitions.get(parent.record.type)?.descriptor.allowNesting) {
|
|
207
|
-
return failure('depth_exceeded', `${parent.record.type} does not allow nested subagents`);
|
|
208
|
-
}
|
|
209
|
-
if (this.#closed)
|
|
210
|
-
return failure('host_unavailable', 'Local subagent host is closed');
|
|
211
|
-
if (signal?.aborted)
|
|
212
|
-
return failure('invalid_request', 'Subagent startup was aborted');
|
|
213
|
-
const agentId = randomUUID();
|
|
214
|
-
const now = new Date().toISOString();
|
|
215
|
-
const record = {
|
|
216
|
-
agentId,
|
|
217
|
-
parentSessionId,
|
|
218
|
-
rootSessionId: context.rootSessionId,
|
|
219
|
-
type: request.type,
|
|
220
|
-
description: request.description,
|
|
221
|
-
status: 'queued',
|
|
222
|
-
createdAt: now,
|
|
223
|
-
};
|
|
224
|
-
const child = {
|
|
225
|
-
record,
|
|
226
|
-
request: normalizedRequest,
|
|
227
|
-
depth: context.depth + 1,
|
|
228
|
-
deliveryId: randomUUID(),
|
|
229
|
-
completionPending: false,
|
|
230
|
-
};
|
|
231
|
-
const job = this.#job(child, normalizedRequest.prompt);
|
|
232
|
-
this.#children.set(agentId, child);
|
|
233
|
-
this.#jobs.set(agentId, job);
|
|
234
|
-
try {
|
|
235
|
-
await this.#persist();
|
|
236
|
-
}
|
|
237
|
-
catch {
|
|
238
|
-
this.#children.delete(agentId);
|
|
239
|
-
this.#jobs.delete(agentId);
|
|
240
|
-
return failure('host_unavailable', 'Local subagent startup could not be persisted');
|
|
241
|
-
}
|
|
242
|
-
if (signal?.aborted) {
|
|
243
|
-
this.#children.delete(agentId);
|
|
244
|
-
this.#jobs.delete(agentId);
|
|
245
|
-
await this.#persist();
|
|
246
|
-
return failure('invalid_request', 'Subagent startup was aborted');
|
|
247
|
-
}
|
|
248
|
-
this.#emit();
|
|
249
|
-
return success({ child, job });
|
|
250
|
-
});
|
|
251
|
-
if (!admitted.ok)
|
|
252
|
-
return admitted;
|
|
253
|
-
const { child, job } = admitted.value;
|
|
254
|
-
const queued = cloneRecord(child.record);
|
|
255
|
-
this.#queue.push(job);
|
|
256
|
-
this.#drain();
|
|
257
|
-
return success(queued);
|
|
258
|
-
}
|
|
259
|
-
async list(parentSessionId, options) {
|
|
260
|
-
return this.#serializeControl(async () => {
|
|
261
|
-
if (!this.#sessionContext(parentSessionId))
|
|
262
|
-
return failure('parent_unavailable', 'Parent subagent is unavailable');
|
|
263
|
-
const direct = new Set([parentSessionId]);
|
|
264
|
-
if (options.includeDescendants) {
|
|
265
|
-
let changed = true;
|
|
266
|
-
while (changed) {
|
|
267
|
-
changed = false;
|
|
268
|
-
for (const child of this.#latestChildren()) {
|
|
269
|
-
if (direct.has(child.record.parentSessionId) && !direct.has(child.record.agentId)) {
|
|
270
|
-
direct.add(child.record.agentId);
|
|
271
|
-
changed = true;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const limit = boundedInteger(options.limit, 20, 1, 50);
|
|
277
|
-
const records = this.#latestChildren()
|
|
278
|
-
.filter((child) => direct.has(child.record.parentSessionId))
|
|
279
|
-
.map((child) => cloneRecord(child.record))
|
|
280
|
-
.sort((left, right) => (subagentStatusPriority(left.status) - subagentStatusPriority(right.status)
|
|
281
|
-
|| left.createdAt.localeCompare(right.createdAt)));
|
|
282
|
-
return success(records.slice(0, limit));
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
async getResult(parentSessionId, agentId, options) {
|
|
286
|
-
const authorized = await this.#serializeControl(async () => this.#directChild(parentSessionId, agentId));
|
|
287
|
-
if (!authorized.ok)
|
|
288
|
-
return authorized;
|
|
289
|
-
const result = await this.#resultRecord(authorized.value);
|
|
290
|
-
if (options?.acknowledge !== true || !isTerminal(result.status))
|
|
291
|
-
return success(result);
|
|
292
|
-
await this.#serializeControl(async () => {
|
|
293
|
-
const current = this.#directChild(parentSessionId, agentId);
|
|
294
|
-
if (!current.ok || current.value !== authorized.value)
|
|
295
|
-
return;
|
|
296
|
-
const child = current.value;
|
|
297
|
-
if (!child.completionPending || child.deliveryId === undefined)
|
|
298
|
-
return;
|
|
299
|
-
const deliveryId = child.deliveryId;
|
|
300
|
-
child.completionPending = false;
|
|
301
|
-
this.#ports.get(parentSessionId)?.acknowledgeCompletion?.(deliveryId);
|
|
302
|
-
await this.#persist();
|
|
303
|
-
this.#emit();
|
|
304
|
-
});
|
|
305
|
-
return success(result);
|
|
306
|
-
}
|
|
307
|
-
listLocalSubagents(parentSessionId) {
|
|
308
|
-
return this.#latestChildren()
|
|
309
|
-
.filter((child) => child.record.parentSessionId === parentSessionId)
|
|
310
|
-
.map(localView)
|
|
311
|
-
.sort((left, right) => left.createdAt.localeCompare(right.createdAt));
|
|
312
|
-
}
|
|
313
|
-
getLocalSubagent(parentSessionId, agentId) {
|
|
314
|
-
return this.listLocalSubagents(parentSessionId)
|
|
315
|
-
.find((child) => child.agentId === agentId);
|
|
316
|
-
}
|
|
317
|
-
async steer(parentSessionId, agentId, message) {
|
|
318
|
-
const prepared = await this.#serializeControl(async () => {
|
|
319
|
-
if (this.#closed)
|
|
320
|
-
return failure('host_unavailable', 'Local subagent host is closed');
|
|
321
|
-
const authorized = this.#directChild(parentSessionId, agentId);
|
|
322
|
-
if (!authorized.ok)
|
|
323
|
-
return authorized;
|
|
324
|
-
const child = authorized.value;
|
|
325
|
-
if (child.record.status === 'queued' || child.record.status === 'running') {
|
|
326
|
-
const steered = await this.#steerActive(child, message);
|
|
327
|
-
return steered.ok ? success({ kind: 'active', child: steered.value }) : steered;
|
|
328
|
-
}
|
|
329
|
-
if (!isContinuable(child)) {
|
|
330
|
-
return failure('not_steerable', 'Only retained completed or recoverable subagents can be continued');
|
|
331
|
-
}
|
|
332
|
-
return success({
|
|
333
|
-
kind: 'completed',
|
|
334
|
-
child,
|
|
335
|
-
sessionFile: child.sessionFile,
|
|
336
|
-
deliveryId: child.completionPending ? child.deliveryId : undefined,
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
if (!prepared.ok)
|
|
340
|
-
return prepared;
|
|
341
|
-
if (prepared.value.kind === 'active')
|
|
342
|
-
return success(cloneRecord(prepared.value.child.record));
|
|
343
|
-
const completion = prepared.value;
|
|
344
|
-
const sessionFile = completion.sessionFile;
|
|
345
|
-
if (!sessionFile)
|
|
346
|
-
return failure('not_steerable', 'The retained subagent session is unavailable');
|
|
347
|
-
try {
|
|
348
|
-
await preflightSessionFile(sessionFile, agentId);
|
|
349
|
-
}
|
|
350
|
-
catch {
|
|
351
|
-
return failure('not_steerable', 'The retained subagent session is unavailable');
|
|
352
|
-
}
|
|
353
|
-
const continued = await this.#serializeControl(async () => {
|
|
354
|
-
if (this.#closed)
|
|
355
|
-
return failure('host_unavailable', 'Local subagent host is closed');
|
|
356
|
-
const authorized = this.#directChild(parentSessionId, agentId);
|
|
357
|
-
if (!authorized.ok)
|
|
358
|
-
return authorized;
|
|
359
|
-
const child = authorized.value;
|
|
360
|
-
if (child.sessionFile !== sessionFile) {
|
|
361
|
-
return failure('not_steerable', 'The retained subagent session changed before continuation');
|
|
362
|
-
}
|
|
363
|
-
if (child.record.status === 'queued' || child.record.status === 'running') {
|
|
364
|
-
const steered = await this.#steerActive(child, message);
|
|
365
|
-
return steered.ok ? success({ child: steered.value, job: undefined }) : steered;
|
|
366
|
-
}
|
|
367
|
-
if (!isContinuable(child)) {
|
|
368
|
-
return failure('not_steerable', 'The retained subagent session changed before continuation');
|
|
369
|
-
}
|
|
370
|
-
const previousRecord = child.record;
|
|
371
|
-
const previousDeliveryId = child.deliveryId;
|
|
372
|
-
const previousCompletionPending = child.completionPending;
|
|
373
|
-
const previousDeliveryAttempt = previousDeliveryId === undefined
|
|
374
|
-
? undefined
|
|
375
|
-
: this.#deliveryAttempts.get(previousDeliveryId);
|
|
376
|
-
const previousDeliveryTimer = previousDeliveryId === undefined
|
|
377
|
-
? undefined
|
|
378
|
-
: this.#deliveryTimers.get(previousDeliveryId);
|
|
379
|
-
const previousDeliveryInFlight = previousDeliveryId !== undefined
|
|
380
|
-
&& this.#deliveries.has(previousDeliveryId);
|
|
381
|
-
if (previousCompletionPending && previousDeliveryId !== undefined) {
|
|
382
|
-
this.#ports.get(parentSessionId)?.acknowledgeCompletion?.(previousDeliveryId);
|
|
383
|
-
}
|
|
384
|
-
child.record = {
|
|
385
|
-
agentId: child.record.agentId,
|
|
386
|
-
parentSessionId: child.record.parentSessionId,
|
|
387
|
-
rootSessionId: child.record.rootSessionId,
|
|
388
|
-
type: child.record.type,
|
|
389
|
-
description: child.record.description,
|
|
390
|
-
status: 'queued',
|
|
391
|
-
createdAt: child.record.createdAt,
|
|
392
|
-
};
|
|
393
|
-
child.deliveryId = randomUUID();
|
|
394
|
-
child.completionPending = false;
|
|
395
|
-
if (previousDeliveryId !== undefined) {
|
|
396
|
-
this.#deliveryAttempts.delete(previousDeliveryId);
|
|
397
|
-
const timer = this.#deliveryTimers.get(previousDeliveryId);
|
|
398
|
-
if (timer !== undefined)
|
|
399
|
-
clearTimeout(timer);
|
|
400
|
-
this.#deliveryTimers.delete(previousDeliveryId);
|
|
401
|
-
}
|
|
402
|
-
const job = this.#job(child, message);
|
|
403
|
-
this.#jobs.set(agentId, job);
|
|
404
|
-
try {
|
|
405
|
-
await this.#persist();
|
|
406
|
-
}
|
|
407
|
-
catch {
|
|
408
|
-
this.#jobs.delete(agentId);
|
|
409
|
-
child.record = previousRecord;
|
|
410
|
-
child.completionPending = previousCompletionPending;
|
|
411
|
-
if (previousDeliveryId === undefined)
|
|
412
|
-
delete child.deliveryId;
|
|
413
|
-
else
|
|
414
|
-
child.deliveryId = previousDeliveryId;
|
|
415
|
-
if (previousDeliveryId !== undefined) {
|
|
416
|
-
if (previousDeliveryAttempt === undefined)
|
|
417
|
-
this.#deliveryAttempts.delete(previousDeliveryId);
|
|
418
|
-
else
|
|
419
|
-
this.#deliveryAttempts.set(previousDeliveryId, previousDeliveryAttempt);
|
|
420
|
-
if (previousDeliveryTimer !== undefined) {
|
|
421
|
-
this.#scheduleDeliveryRetry(child, previousDeliveryId, previousDeliveryAttempt ?? 0);
|
|
422
|
-
}
|
|
423
|
-
else if (previousCompletionPending && !previousDeliveryInFlight) {
|
|
424
|
-
this.#scheduleDeliveryRetry(child, previousDeliveryId, previousDeliveryAttempt ?? 0);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return failure('host_unavailable', 'Subagent continuation could not be persisted');
|
|
428
|
-
}
|
|
429
|
-
this.#queue.push(job);
|
|
430
|
-
this.#emit();
|
|
431
|
-
return success({ child, job });
|
|
432
|
-
});
|
|
433
|
-
if (!continued.ok)
|
|
434
|
-
return continued;
|
|
435
|
-
if (continued.value.job)
|
|
436
|
-
this.#drain();
|
|
437
|
-
return success(cloneRecord(continued.value.child.record));
|
|
438
|
-
}
|
|
439
|
-
async cancel(parentSessionId, agentId, reason = 'Cancelled by parent') {
|
|
440
|
-
const authorized = this.#directChild(parentSessionId, agentId);
|
|
441
|
-
if (!authorized.ok)
|
|
442
|
-
return authorized;
|
|
443
|
-
await this.#cancelTree(agentId, reason, 'cancelled', 'cancelled_by_parent', false);
|
|
444
|
-
return success(cloneRecord(this.#latest(agentId).record));
|
|
445
|
-
}
|
|
446
|
-
subscribe(listener) {
|
|
447
|
-
this.#listeners.add(listener);
|
|
448
|
-
listener(this.#latestChildren().map(localView));
|
|
449
|
-
return () => this.#listeners.delete(listener);
|
|
450
|
-
}
|
|
451
|
-
hasPendingWork(sessionId) {
|
|
452
|
-
const context = this.#sessionContext(sessionId);
|
|
453
|
-
if (!context)
|
|
454
|
-
return false;
|
|
455
|
-
return this.#latestChildren().some((child) => {
|
|
456
|
-
if (child.record.rootSessionId !== context.rootSessionId)
|
|
457
|
-
return false;
|
|
458
|
-
if (!isTerminal(child.record.status))
|
|
459
|
-
return true;
|
|
460
|
-
return child.record.parentSessionId === sessionId && child.completionPending;
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
getUsage() {
|
|
464
|
-
const totals = emptyUsageTotals();
|
|
465
|
-
for (const child of this.#children.values())
|
|
466
|
-
addUsage(totals, child.usage);
|
|
467
|
-
return totals;
|
|
468
|
-
}
|
|
469
|
-
subscribeUsage(listener) {
|
|
470
|
-
this.#usageListeners.add(listener);
|
|
471
|
-
return () => this.#usageListeners.delete(listener);
|
|
472
|
-
}
|
|
473
|
-
async shutdown() {
|
|
474
|
-
this.#shutdown ??= this.#performShutdown();
|
|
475
|
-
await this.#shutdown;
|
|
476
|
-
}
|
|
477
|
-
async #performShutdown() {
|
|
478
|
-
this.#closed = true;
|
|
479
|
-
for (const timer of this.#deliveryTimers.values())
|
|
480
|
-
clearTimeout(timer);
|
|
481
|
-
this.#deliveryTimers.clear();
|
|
482
|
-
await this.#serializeControl(async () => { });
|
|
483
|
-
for (const child of this.#latestChildren()) {
|
|
484
|
-
if (!isTerminal(child.record.status))
|
|
485
|
-
await this.#cancelTree(child.record.agentId, 'Local host exited');
|
|
486
|
-
}
|
|
487
|
-
await Promise.allSettled([...this.#jobs.values()].map((job) => job.runPromise ?? job.cancelPromise ?? Promise.resolve()));
|
|
488
|
-
await Promise.allSettled(this.#deliveries.values());
|
|
489
|
-
await this.#save;
|
|
490
|
-
}
|
|
491
|
-
async #steerActive(child, message) {
|
|
492
|
-
const job = this.#jobs.get(child.record.agentId);
|
|
493
|
-
if (!job || job.terminalStatus) {
|
|
494
|
-
return failure('not_steerable', 'Subagent session is unavailable');
|
|
495
|
-
}
|
|
496
|
-
if (job.control)
|
|
497
|
-
await job.control.steer(message);
|
|
498
|
-
else
|
|
499
|
-
job.queuedMessages.push(message);
|
|
500
|
-
return success(child);
|
|
501
|
-
}
|
|
502
|
-
#job(child, initialMessage) {
|
|
503
|
-
return {
|
|
504
|
-
child,
|
|
505
|
-
controller: new AbortController(),
|
|
506
|
-
initialMessage,
|
|
507
|
-
queuedMessages: [],
|
|
508
|
-
slotHeld: false,
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
#drain() {
|
|
512
|
-
this.#serializeControl(async () => {
|
|
513
|
-
while (!this.#closed && this.#active < this.#concurrency && this.#queue.length > 0) {
|
|
514
|
-
const job = this.#queue.shift();
|
|
515
|
-
if (job.child.record.status !== 'queued')
|
|
516
|
-
continue;
|
|
517
|
-
await this.#beginRun(job);
|
|
518
|
-
}
|
|
519
|
-
}).catch(() => { });
|
|
520
|
-
}
|
|
521
|
-
async #beginRun(job) {
|
|
522
|
-
if (job.runPromise || job.child.record.status !== 'queued')
|
|
523
|
-
return;
|
|
524
|
-
if (!job.slotHeld) {
|
|
525
|
-
if (this.#active >= this.#concurrency) {
|
|
526
|
-
this.#queue.unshift(job);
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
job.slotHeld = true;
|
|
530
|
-
this.#active += 1;
|
|
531
|
-
}
|
|
532
|
-
job.child.record = {
|
|
533
|
-
...job.child.record,
|
|
534
|
-
status: 'running',
|
|
535
|
-
startedAt: new Date().toISOString(),
|
|
536
|
-
};
|
|
537
|
-
await this.#persist();
|
|
538
|
-
this.#emit();
|
|
539
|
-
job.runPromise = this.#run(job);
|
|
540
|
-
}
|
|
541
|
-
async #run(job) {
|
|
542
|
-
const child = job.child;
|
|
543
|
-
let timeout;
|
|
544
|
-
let outcome;
|
|
545
|
-
try {
|
|
546
|
-
if (child.request.timeoutSeconds) {
|
|
547
|
-
timeout = setTimeout(() => {
|
|
548
|
-
this.#cancelTree(child.record.agentId, `Subagent timed out after ${child.request.timeoutSeconds} seconds`, 'timed_out', 'timed_out').catch(() => { });
|
|
549
|
-
}, child.request.timeoutSeconds * 1_000);
|
|
550
|
-
timeout.unref();
|
|
551
|
-
}
|
|
552
|
-
const definition = this.definitions.get(child.record.type);
|
|
553
|
-
if (!job.controller.signal.aborted) {
|
|
554
|
-
const queuedAtStart = job.queuedMessages.splice(0);
|
|
555
|
-
const input = {
|
|
556
|
-
sessionId: child.record.agentId,
|
|
557
|
-
rootSessionId: child.record.rootSessionId,
|
|
558
|
-
depth: child.depth,
|
|
559
|
-
subagents: new LocalSubagentHost(this, child.record.agentId),
|
|
560
|
-
request: child.request,
|
|
561
|
-
definition,
|
|
562
|
-
cwd: this.#options.cwd,
|
|
563
|
-
signal: job.controller.signal,
|
|
564
|
-
initialMessage: [job.initialMessage, ...queuedAtStart].join('\n\n'),
|
|
565
|
-
onReady: async (control) => {
|
|
566
|
-
job.control = control;
|
|
567
|
-
if (job.terminalStatus)
|
|
568
|
-
this.#cancelControl(job);
|
|
569
|
-
await job.cancelPromise;
|
|
570
|
-
if (job.terminalStatus)
|
|
571
|
-
return;
|
|
572
|
-
const pending = job.queuedMessages.splice(0);
|
|
573
|
-
for (const message of pending)
|
|
574
|
-
await control.steer(message);
|
|
575
|
-
},
|
|
576
|
-
...(child.sessionFile === undefined ? {} : { sessionFile: child.sessionFile }),
|
|
577
|
-
};
|
|
578
|
-
outcome = this.#options.runChild
|
|
579
|
-
? await this.#options.runChild(input)
|
|
580
|
-
: await this.#runAgentCore(input, async (session, sessionFile) => {
|
|
581
|
-
child.session = session;
|
|
582
|
-
child.sessionFile = sessionFile;
|
|
583
|
-
child.usage = usageFromEntries(session.sessionManager.getEntries());
|
|
584
|
-
child.usageUnsubscribe?.();
|
|
585
|
-
child.usageUnsubscribe = session.subscribe((event) => {
|
|
586
|
-
if (event.type !== 'message_end'
|
|
587
|
-
|| event.message.role !== 'assistant')
|
|
588
|
-
return;
|
|
589
|
-
child.usage ??= emptyUsageTotals();
|
|
590
|
-
child.usage.input += event.message.usage.input;
|
|
591
|
-
child.usage.output += event.message.usage.output;
|
|
592
|
-
child.usage.cacheRead += event.message.usage.cacheRead;
|
|
593
|
-
child.usage.cacheWrite += event.message.usage.cacheWrite;
|
|
594
|
-
child.usage.cacheWrite1h += event.message.usage.cacheWrite1h ?? 0;
|
|
595
|
-
child.usage.cost += event.message.usage.cost.total;
|
|
596
|
-
this.#emitUsage();
|
|
597
|
-
});
|
|
598
|
-
await this.#persist();
|
|
599
|
-
this.#emit();
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
await job.cancelPromise;
|
|
603
|
-
outcome ??= {};
|
|
604
|
-
}
|
|
605
|
-
catch {
|
|
606
|
-
await job.cancelPromise;
|
|
607
|
-
outcome = { error: { code: 'internal_error', message: 'Local subagent failed unexpectedly' } };
|
|
608
|
-
}
|
|
609
|
-
finally {
|
|
610
|
-
if (timeout)
|
|
611
|
-
clearTimeout(timeout);
|
|
612
|
-
let savingsMeasurement;
|
|
613
|
-
await this.#serializeControl(async () => {
|
|
614
|
-
child.usageUnsubscribe?.();
|
|
615
|
-
delete child.usageUnsubscribe;
|
|
616
|
-
if (outcome?.sessionFile) {
|
|
617
|
-
child.sessionFile = outcome.sessionFile;
|
|
618
|
-
}
|
|
619
|
-
if (child.session) {
|
|
620
|
-
child.usage = usageFromEntries(child.session.sessionManager.getEntries());
|
|
621
|
-
}
|
|
622
|
-
else if (child.sessionFile) {
|
|
623
|
-
const usage = await loadSessionUsage(child.sessionFile, child.record.agentId);
|
|
624
|
-
if (usage)
|
|
625
|
-
child.usage = usage;
|
|
626
|
-
else
|
|
627
|
-
delete child.usage;
|
|
628
|
-
}
|
|
629
|
-
const terminalBeforeCleanup = isTerminal(child.record.status);
|
|
630
|
-
if (!terminalBeforeCleanup) {
|
|
631
|
-
if (job.terminalStatus) {
|
|
632
|
-
child.record = terminalRecord(child.record, job.terminalStatus, job.terminalError);
|
|
633
|
-
}
|
|
634
|
-
else if (outcome?.turnLimitReached) {
|
|
635
|
-
child.record = terminalRecord(child.record, 'cancelled', {
|
|
636
|
-
code: 'turn_limit_reached',
|
|
637
|
-
message: `Subagent reached its ${child.request.maxTurns} turn limit`,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
else if (outcome?.error) {
|
|
641
|
-
child.record = terminalRecord(child.record, 'failed', outcome.error);
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
child.record = {
|
|
645
|
-
...terminalRecord(child.record, 'completed'),
|
|
646
|
-
result: boundResult(outcome?.result ?? ''),
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
savingsMeasurement = this.#prepareExploreSavings(child);
|
|
651
|
-
if (job.slotHeld) {
|
|
652
|
-
job.slotHeld = false;
|
|
653
|
-
this.#active -= 1;
|
|
654
|
-
}
|
|
655
|
-
this.#jobs.delete(child.record.agentId);
|
|
656
|
-
if (!terminalBeforeCleanup && child.deliveryId)
|
|
657
|
-
child.completionPending = true;
|
|
658
|
-
await this.#persist();
|
|
659
|
-
this.#emit();
|
|
660
|
-
});
|
|
661
|
-
if (savingsMeasurement && this.#savingsReporter) {
|
|
662
|
-
try {
|
|
663
|
-
await this.#savingsReporter.report(savingsMeasurement);
|
|
664
|
-
}
|
|
665
|
-
catch { }
|
|
666
|
-
}
|
|
667
|
-
try {
|
|
668
|
-
if (child.deliveryId)
|
|
669
|
-
await this.#deliver(child, child.deliveryId);
|
|
670
|
-
}
|
|
671
|
-
finally {
|
|
672
|
-
this.#drain();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
#requestCancellation(job, status, error) {
|
|
677
|
-
if (job.terminalStatus || isTerminal(job.child.record.status))
|
|
678
|
-
return;
|
|
679
|
-
job.terminalStatus = status;
|
|
680
|
-
job.terminalError = error;
|
|
681
|
-
job.controller.abort();
|
|
682
|
-
this.#cancelControl(job);
|
|
683
|
-
}
|
|
684
|
-
#cancelControl(job) {
|
|
685
|
-
if (!job.control || job.cancelPromise)
|
|
686
|
-
return;
|
|
687
|
-
job.cancelPromise = job.control.cancel().catch(() => { });
|
|
688
|
-
}
|
|
689
|
-
async #runAgentCore(input, onSession) {
|
|
690
|
-
const runtimeRequest = createLocalAgentRuntimeFactoryRequest(input.cwd, this.#options.agentDir, input.rootSessionId);
|
|
691
|
-
const memoryHost = this.#options.memoryHostFactory?.({
|
|
692
|
-
cwd: input.cwd,
|
|
693
|
-
sessionStorageRoot: runtimeRequest.sessionStorageRoot,
|
|
694
|
-
});
|
|
695
|
-
await Promise.all([
|
|
696
|
-
mkdir(this.#store.sessionDirectory(), { recursive: true }),
|
|
697
|
-
mkdir(runtimeRequest.sessionStorageRoot, { recursive: true }),
|
|
698
|
-
mkdir(runtimeRequest.agentStorageRoot, { recursive: true }),
|
|
699
|
-
]);
|
|
700
|
-
if (input.signal.aborted)
|
|
701
|
-
return {};
|
|
702
|
-
const sessionManager = input.sessionFile
|
|
703
|
-
? SessionManager.open(input.sessionFile, this.#store.sessionDirectory(), input.cwd)
|
|
704
|
-
: SessionManager.create(input.cwd, this.#store.sessionDirectory(), { id: input.sessionId });
|
|
705
|
-
const sessionFile = sessionManager.getSessionFile();
|
|
706
|
-
if (!sessionFile) {
|
|
707
|
-
return {
|
|
708
|
-
error: { code: 'internal_error', message: 'Subagent session file could not be created' },
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
const model = input.request.model ? this.#exactModel(input.request.model) : undefined;
|
|
712
|
-
if (input.request.model && !model) {
|
|
713
|
-
return { error: { code: 'unsupported_model', message: 'The requested model is unavailable' } };
|
|
714
|
-
}
|
|
715
|
-
const canNest = input.definition.descriptor.allowNesting && input.depth < this.#maxDepth;
|
|
716
|
-
const extensionPackages = canNest
|
|
717
|
-
? this.#options.extensionPackages
|
|
718
|
-
: this.#options.extensionPackages.filter((packageName) => packageName !== EXT_SUBAGENTS);
|
|
719
|
-
if (input.signal.aborted)
|
|
720
|
-
return {};
|
|
721
|
-
const appendSystemPrompt = await loadLocalChildSystemPromptAppends(this.#options.agentDir, input.definition.prompt);
|
|
722
|
-
const runtime = this.#options.runtimeFactory?.(runtimeRequest)
|
|
723
|
-
?? new HostAgentRuntime(input.cwd, {
|
|
724
|
-
...runtimeRequest,
|
|
725
|
-
logger: createLocalAgentLogger(runtimeRequest.agentStorageRoot),
|
|
726
|
-
...(this.#options.classifier === undefined ? {} : { classifier: this.#options.classifier }),
|
|
727
|
-
});
|
|
728
|
-
const wrapStreamFunction = await createLocalCodexStreamFunctionWrapper(extensionPackages, runtime, this.#options.agentDir);
|
|
729
|
-
const created = await createAgentCoreSession({
|
|
730
|
-
runtime,
|
|
731
|
-
...(!this.#options.dynamicThinking || input.request.thinking !== undefined ? {} : {
|
|
732
|
-
dynamicThinking: true,
|
|
733
|
-
}),
|
|
734
|
-
...(wrapStreamFunction === undefined ? {} : { wrapStreamFunction }),
|
|
735
|
-
extensionPackages,
|
|
736
|
-
importExtension: createLocalSubagentExtensionImporter(this.#options, input.subagents, memoryHost),
|
|
737
|
-
modelRuntime: this.#options.modelRuntime,
|
|
738
|
-
settingsManager: this.#options.settingsManager,
|
|
739
|
-
sessionManager,
|
|
740
|
-
appendSystemPrompt,
|
|
741
|
-
...(this.#options.skillPaths === undefined ? {} : { skillPaths: this.#options.skillPaths }),
|
|
742
|
-
...(model === undefined ? {} : { model }),
|
|
743
|
-
...(input.request.thinking === undefined ? {} : { thinkingLevel: input.request.thinking }),
|
|
744
|
-
...(this.#options.scopedModels === undefined
|
|
745
|
-
? {}
|
|
746
|
-
: { scopedModels: this.#options.scopedModels }),
|
|
747
|
-
...(this.#options.extensionConfigOverrides === undefined
|
|
748
|
-
? {}
|
|
749
|
-
: { extensionConfigOverrides: this.#options.extensionConfigOverrides }),
|
|
750
|
-
...(this.#options.savings === undefined ? {} : { savings: this.#options.savings }),
|
|
751
|
-
...(this.#options.inlineExtensions === undefined
|
|
752
|
-
? {}
|
|
753
|
-
: { inlineExtensions: this.#options.inlineExtensions }),
|
|
754
|
-
});
|
|
755
|
-
try {
|
|
756
|
-
await onSession(created.session, sessionFile);
|
|
757
|
-
bindSubagentSession({ host: input.subagents, session: created.session });
|
|
758
|
-
if (input.signal.aborted)
|
|
759
|
-
return sessionFileOutcome(created.session.sessionFile);
|
|
760
|
-
await created.session.bindExtensions(this.#options.extensionUiContext === undefined
|
|
761
|
-
? { mode: 'print' }
|
|
762
|
-
: { mode: 'rpc', uiContext: this.#options.extensionUiContext });
|
|
763
|
-
if (input.definition.toolProfile === 'inspection') {
|
|
764
|
-
created.session.setActiveToolsByName(inspectionToolNames(created.session.getActiveToolNames()));
|
|
765
|
-
}
|
|
766
|
-
if (input.signal.aborted)
|
|
767
|
-
return sessionFileOutcome(created.session.sessionFile);
|
|
768
|
-
let turns = 0;
|
|
769
|
-
let turnLimitReached = false;
|
|
770
|
-
let synthesisRequested = false;
|
|
771
|
-
let cancellation;
|
|
772
|
-
const cancel = () => {
|
|
773
|
-
cancellation ??= created.session.abort();
|
|
774
|
-
return cancellation;
|
|
775
|
-
};
|
|
776
|
-
const unsubscribe = created.session.subscribe((event) => {
|
|
777
|
-
if (event.type !== 'turn_end')
|
|
778
|
-
return;
|
|
779
|
-
turns += 1;
|
|
780
|
-
if (input.request.maxTurns
|
|
781
|
-
&& event.message.role === 'assistant'
|
|
782
|
-
&& event.message.stopReason === 'toolUse') {
|
|
783
|
-
if (turns >= input.request.maxTurns) {
|
|
784
|
-
turnLimitReached = true;
|
|
785
|
-
cancel().catch(() => { });
|
|
786
|
-
}
|
|
787
|
-
else if (turns >= input.request.maxTurns - 1 && !synthesisRequested) {
|
|
788
|
-
synthesisRequested = true;
|
|
789
|
-
created.session.setActiveToolsByName([]);
|
|
790
|
-
created.session.steer(SYNTHESIS_PROMPT).catch(() => { });
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
const abort = () => {
|
|
795
|
-
cancel().catch(() => { });
|
|
796
|
-
};
|
|
797
|
-
input.signal.addEventListener('abort', abort, { once: true });
|
|
798
|
-
try {
|
|
799
|
-
if (input.signal.aborted) {
|
|
800
|
-
await cancel();
|
|
801
|
-
return sessionFileOutcome(created.session.sessionFile);
|
|
802
|
-
}
|
|
803
|
-
await input.onReady({
|
|
804
|
-
steer: async (message) => { await created.session.steer(message); },
|
|
805
|
-
cancel,
|
|
806
|
-
});
|
|
807
|
-
if (input.signal.aborted) {
|
|
808
|
-
await cancel();
|
|
809
|
-
return sessionFileOutcome(created.session.sessionFile);
|
|
810
|
-
}
|
|
811
|
-
let initialMessage = input.initialMessage;
|
|
812
|
-
if (input.request.maxTurns === 1) {
|
|
813
|
-
synthesisRequested = true;
|
|
814
|
-
created.session.setActiveToolsByName([]);
|
|
815
|
-
initialMessage = `${initialMessage}\n\n${SYNTHESIS_PROMPT}`;
|
|
816
|
-
}
|
|
817
|
-
await created.session.prompt(initialMessage);
|
|
818
|
-
await cancellation;
|
|
819
|
-
const assistant = [...created.session.messages].reverse().find((message) => message.role === 'assistant');
|
|
820
|
-
if (turnLimitReached) {
|
|
821
|
-
return {
|
|
822
|
-
...sessionFileOutcome(created.session.sessionFile),
|
|
823
|
-
turnLimitReached: true,
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
if (!assistant) {
|
|
827
|
-
return {
|
|
828
|
-
error: { code: 'internal_error', message: 'Subagent completed without an assistant response' },
|
|
829
|
-
...sessionFileOutcome(created.session.sessionFile),
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
if (assistant.stopReason !== 'stop') {
|
|
833
|
-
return {
|
|
834
|
-
error: {
|
|
835
|
-
code: assistant.stopReason === 'error' ? 'model_request_failed' : 'internal_error',
|
|
836
|
-
message: assistant.stopReason === 'error'
|
|
837
|
-
? `Model request failed: ${sanitizeModelError(assistant.errorMessage)}`
|
|
838
|
-
: `Subagent ended without a final response (${assistant.stopReason})`,
|
|
839
|
-
},
|
|
840
|
-
...sessionFileOutcome(created.session.sessionFile),
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
const result = assistant.content
|
|
844
|
-
.filter((part) => part.type === 'text')
|
|
845
|
-
.map((part) => part.text)
|
|
846
|
-
.join('\n');
|
|
847
|
-
if (!result.trim()) {
|
|
848
|
-
return {
|
|
849
|
-
error: { code: 'internal_error', message: 'Subagent completed without a final result' },
|
|
850
|
-
...sessionFileOutcome(created.session.sessionFile),
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
return {
|
|
854
|
-
result,
|
|
855
|
-
...sessionFileOutcome(created.session.sessionFile),
|
|
856
|
-
...(turnLimitReached ? { turnLimitReached: true } : {}),
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
finally {
|
|
860
|
-
input.signal.removeEventListener('abort', abort);
|
|
861
|
-
await cancellation;
|
|
862
|
-
unsubscribe();
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
finally {
|
|
866
|
-
await shutdownSubagentSession(created.session);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
#resolveModel(selector) {
|
|
870
|
-
if (!selector)
|
|
871
|
-
return success(undefined);
|
|
872
|
-
if (selector === 'inherit') {
|
|
873
|
-
return failure('unsupported_model', 'Parent model is unavailable');
|
|
874
|
-
}
|
|
875
|
-
const model = this.#exactModel(selector);
|
|
876
|
-
return model && this.#options.modelRuntime.hasConfiguredAuth(model.provider)
|
|
877
|
-
? success(`${model.provider}/${model.id}`)
|
|
878
|
-
: failure('unsupported_model', 'The requested model is unavailable or unauthenticated');
|
|
879
|
-
}
|
|
880
|
-
#supportsThinking(modelReference, thinking) {
|
|
881
|
-
if (thinking === undefined || thinking === 'off')
|
|
882
|
-
return true;
|
|
883
|
-
if (!modelReference)
|
|
884
|
-
return false;
|
|
885
|
-
const model = this.#exactModel(modelReference);
|
|
886
|
-
if (!model?.reasoning)
|
|
887
|
-
return false;
|
|
888
|
-
const mapped = model.thinkingLevelMap?.[thinking];
|
|
889
|
-
return thinking === 'xhigh' || thinking === 'max'
|
|
890
|
-
? mapped !== undefined && mapped !== null
|
|
891
|
-
: mapped !== null;
|
|
892
|
-
}
|
|
893
|
-
#exactModel(reference) {
|
|
894
|
-
const separator = reference.indexOf('/');
|
|
895
|
-
if (separator <= 0 || separator === reference.length - 1)
|
|
896
|
-
return undefined;
|
|
897
|
-
return this.#options.modelRuntime.getModel(reference.slice(0, separator), reference.slice(separator + 1));
|
|
898
|
-
}
|
|
899
|
-
#directChild(parentSessionId, agentId) {
|
|
900
|
-
const child = this.#children.get(agentId);
|
|
901
|
-
if (!child)
|
|
902
|
-
return failure('not_found', `Subagent not found: ${agentId}`);
|
|
903
|
-
if (child.record.parentSessionId !== parentSessionId) {
|
|
904
|
-
return failure('not_child', 'The subagent is not a direct child of this session');
|
|
905
|
-
}
|
|
906
|
-
return success(child);
|
|
907
|
-
}
|
|
908
|
-
#sessionContext(sessionId) {
|
|
909
|
-
if (sessionId === this.#options.sessionId) {
|
|
910
|
-
return { rootSessionId: sessionId, depth: 0 };
|
|
911
|
-
}
|
|
912
|
-
const child = this.#children.get(sessionId);
|
|
913
|
-
if (!child)
|
|
914
|
-
return undefined;
|
|
915
|
-
return { rootSessionId: child.record.rootSessionId, depth: child.depth, child };
|
|
916
|
-
}
|
|
917
|
-
async #cancelTree(agentId, reason, status = 'cancelled', errorCode = 'host_shutdown', waitForCleanup = true) {
|
|
918
|
-
const cancellation = await this.#serializeControl(async () => {
|
|
919
|
-
const descendants = this.#latestChildren()
|
|
920
|
-
.filter((entry) => entry.record.parentSessionId === agentId && !isTerminal(entry.record.status))
|
|
921
|
-
.map((entry) => entry.record.agentId);
|
|
922
|
-
const child = this.#latest(agentId);
|
|
923
|
-
if (!child || isTerminal(child.record.status)) {
|
|
924
|
-
return { descendants, cleanup: Promise.resolve(), deliveryId: undefined };
|
|
925
|
-
}
|
|
926
|
-
const job = this.#jobs.get(agentId);
|
|
927
|
-
if (child.record.status === 'queued') {
|
|
928
|
-
const queueIndex = job ? this.#queue.indexOf(job) : -1;
|
|
929
|
-
if (queueIndex >= 0)
|
|
930
|
-
this.#queue.splice(queueIndex, 1);
|
|
931
|
-
job?.controller.abort();
|
|
932
|
-
if (job?.slotHeld) {
|
|
933
|
-
job.slotHeld = false;
|
|
934
|
-
this.#active -= 1;
|
|
935
|
-
}
|
|
936
|
-
child.record = terminalRecord(child.record, status, {
|
|
937
|
-
code: errorCode,
|
|
938
|
-
message: reason,
|
|
939
|
-
});
|
|
940
|
-
if (child.deliveryId)
|
|
941
|
-
child.completionPending = true;
|
|
942
|
-
this.#jobs.delete(agentId);
|
|
943
|
-
await this.#persist();
|
|
944
|
-
this.#emit();
|
|
945
|
-
return { descendants, cleanup: Promise.resolve(), deliveryId: child.deliveryId };
|
|
946
|
-
}
|
|
947
|
-
if (!job)
|
|
948
|
-
return { descendants, cleanup: Promise.resolve(), deliveryId: undefined };
|
|
949
|
-
this.#requestCancellation(job, status, {
|
|
950
|
-
code: errorCode,
|
|
951
|
-
message: reason,
|
|
952
|
-
});
|
|
953
|
-
child.record = terminalRecord(child.record, status, {
|
|
954
|
-
code: errorCode,
|
|
955
|
-
message: reason,
|
|
956
|
-
});
|
|
957
|
-
if (child.deliveryId)
|
|
958
|
-
child.completionPending = true;
|
|
959
|
-
await this.#persist();
|
|
960
|
-
this.#emit();
|
|
961
|
-
return { descendants, cleanup: job.runPromise ?? Promise.resolve(), deliveryId: undefined };
|
|
962
|
-
});
|
|
963
|
-
await Promise.all(cancellation.descendants.map((childId) => (this.#cancelTree(childId, reason, status, errorCode, waitForCleanup))));
|
|
964
|
-
if (waitForCleanup)
|
|
965
|
-
await cancellation.cleanup;
|
|
966
|
-
if (cancellation.deliveryId) {
|
|
967
|
-
try {
|
|
968
|
-
const child = this.#latest(agentId);
|
|
969
|
-
if (child) {
|
|
970
|
-
if (waitForCleanup)
|
|
971
|
-
await this.#deliver(child, cancellation.deliveryId);
|
|
972
|
-
else
|
|
973
|
-
void this.#deliver(child, cancellation.deliveryId).catch(() => { });
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
finally {
|
|
977
|
-
this.#drain();
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
async #deliver(child, deliveryId) {
|
|
982
|
-
if (!child.completionPending || child.deliveryId !== deliveryId)
|
|
983
|
-
return;
|
|
984
|
-
const existing = this.#deliveries.get(deliveryId);
|
|
985
|
-
if (existing)
|
|
986
|
-
return existing;
|
|
987
|
-
const notice = completionNotice(child.record, deliveryId);
|
|
988
|
-
const delivery = (async () => {
|
|
989
|
-
const port = this.#ports.get(child.record.parentSessionId);
|
|
990
|
-
if (!port)
|
|
991
|
-
return;
|
|
992
|
-
try {
|
|
993
|
-
const outcome = await port.deliverCompletion(notice);
|
|
994
|
-
if (outcome === 'delivered') {
|
|
995
|
-
this.#deliveryAttempts.delete(deliveryId);
|
|
996
|
-
const timer = this.#deliveryTimers.get(deliveryId);
|
|
997
|
-
if (timer !== undefined)
|
|
998
|
-
clearTimeout(timer);
|
|
999
|
-
this.#deliveryTimers.delete(deliveryId);
|
|
1000
|
-
await this.#serializeControl(async () => {
|
|
1001
|
-
if (child.deliveryId !== deliveryId)
|
|
1002
|
-
return;
|
|
1003
|
-
child.completionPending = false;
|
|
1004
|
-
await this.#persist();
|
|
1005
|
-
this.#emit();
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
this.#scheduleDeliveryRetry(child, deliveryId);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
catch {
|
|
1013
|
-
this.#scheduleDeliveryRetry(child, deliveryId);
|
|
1014
|
-
}
|
|
1015
|
-
})();
|
|
1016
|
-
this.#deliveries.set(deliveryId, delivery);
|
|
1017
|
-
try {
|
|
1018
|
-
await delivery;
|
|
1019
|
-
}
|
|
1020
|
-
finally {
|
|
1021
|
-
if (this.#deliveries.get(deliveryId) === delivery)
|
|
1022
|
-
this.#deliveries.delete(deliveryId);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
#scheduleDeliveryRetry(child, deliveryId, completedAttempts) {
|
|
1026
|
-
if (this.#closed || this.#deliveryTimers.has(deliveryId))
|
|
1027
|
-
return;
|
|
1028
|
-
const attempt = completedAttempts ?? this.#deliveryAttempts.get(deliveryId) ?? 0;
|
|
1029
|
-
const nextAttempt = attempt + 1;
|
|
1030
|
-
this.#deliveryAttempts.set(deliveryId, nextAttempt);
|
|
1031
|
-
const delay = Math.min(5_000, 100 * (2 ** Math.min(nextAttempt - 1, 5)));
|
|
1032
|
-
const retry = setTimeout(() => {
|
|
1033
|
-
this.#deliveryTimers.delete(deliveryId);
|
|
1034
|
-
this.#deliver(child, deliveryId).catch(() => { });
|
|
1035
|
-
}, delay);
|
|
1036
|
-
retry.unref();
|
|
1037
|
-
this.#deliveryTimers.set(deliveryId, retry);
|
|
1038
|
-
}
|
|
1039
|
-
async #deliverPending(parentSessionId) {
|
|
1040
|
-
const children = [...this.#children.values()]
|
|
1041
|
-
.filter((child) => child.record.parentSessionId === parentSessionId && child.completionPending);
|
|
1042
|
-
for (const child of children) {
|
|
1043
|
-
if (child.deliveryId)
|
|
1044
|
-
await this.#deliver(child, child.deliveryId);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
#latest(agentId) {
|
|
1048
|
-
return this.#children.get(agentId);
|
|
1049
|
-
}
|
|
1050
|
-
#latestChildren() {
|
|
1051
|
-
return [...this.#children.values()];
|
|
1052
|
-
}
|
|
1053
|
-
#emit() {
|
|
1054
|
-
const records = this.#latestChildren().map(localView);
|
|
1055
|
-
for (const listener of this.#listeners)
|
|
1056
|
-
listener(records);
|
|
1057
|
-
this.#emitUsage();
|
|
1058
|
-
}
|
|
1059
|
-
#emitUsage() {
|
|
1060
|
-
for (const listener of this.#usageListeners)
|
|
1061
|
-
listener();
|
|
1062
|
-
}
|
|
1063
|
-
#prepareExploreSavings(child) {
|
|
1064
|
-
if (child.record.type !== 'explore' || !child.usage)
|
|
1065
|
-
return undefined;
|
|
1066
|
-
if (!this.#savingsReporter
|
|
1067
|
-
|| child.record.status !== 'completed'
|
|
1068
|
-
|| !child.record.result?.trim()
|
|
1069
|
-
|| !child.request.parentModel
|
|
1070
|
-
|| !child.request.model
|
|
1071
|
-
|| child.request.parentModel.toLowerCase() === child.request.model.toLowerCase()) {
|
|
1072
|
-
child.reportedSavings = { ...child.usage };
|
|
1073
|
-
return undefined;
|
|
1074
|
-
}
|
|
1075
|
-
const usage = subtractUsage(child.usage, child.reportedSavings);
|
|
1076
|
-
if (!usage) {
|
|
1077
|
-
child.reportedSavings = { ...child.usage };
|
|
1078
|
-
return undefined;
|
|
1079
|
-
}
|
|
1080
|
-
const parent = modelReference(child.request.parentModel);
|
|
1081
|
-
const actual = modelReference(child.request.model);
|
|
1082
|
-
if (!parent || !actual) {
|
|
1083
|
-
child.reportedSavings = { ...child.usage };
|
|
1084
|
-
return undefined;
|
|
1085
|
-
}
|
|
1086
|
-
const tokens = savingsTokens(usage);
|
|
1087
|
-
child.reportedSavings = { ...child.usage };
|
|
1088
|
-
return {
|
|
1089
|
-
category: 'model-routing',
|
|
1090
|
-
operation: 'explore-child',
|
|
1091
|
-
baseline: { model: parent, tokens },
|
|
1092
|
-
actual: {
|
|
1093
|
-
model: actual,
|
|
1094
|
-
tokens,
|
|
1095
|
-
...(usage.cost > 0 ? { costUsd: usage.cost } : {}),
|
|
1096
|
-
},
|
|
1097
|
-
basis: {
|
|
1098
|
-
kind: 'estimated-baseline',
|
|
1099
|
-
method: 'parent-model-reprice-observed-child-usage-v1',
|
|
1100
|
-
},
|
|
1101
|
-
dimensions: { techniques: ['explore', 'same-usage-reprice'] },
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
async #persist() {
|
|
1105
|
-
const snapshot = [...this.#children.values()].map(toStored);
|
|
1106
|
-
this.#save = this.#save.catch(() => { }).then(() => this.#store.save(snapshot));
|
|
1107
|
-
await this.#save;
|
|
1108
|
-
}
|
|
1109
|
-
async #serializeControl(operation) {
|
|
1110
|
-
const previous = this.#control;
|
|
1111
|
-
let release;
|
|
1112
|
-
this.#control = new Promise((resolve) => {
|
|
1113
|
-
release = resolve;
|
|
1114
|
-
});
|
|
1115
|
-
await previous;
|
|
1116
|
-
try {
|
|
1117
|
-
return await operation();
|
|
1118
|
-
}
|
|
1119
|
-
finally {
|
|
1120
|
-
release();
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
async #resultRecord(child) {
|
|
1124
|
-
const record = cloneRecord(child.record);
|
|
1125
|
-
if (record.status !== 'completed' || !child.sessionFile || !record.completedAt)
|
|
1126
|
-
return record;
|
|
1127
|
-
try {
|
|
1128
|
-
const result = await finalAssistantText(child.sessionFile, record.completedAt);
|
|
1129
|
-
return result === undefined ? record : { ...record, result };
|
|
1130
|
-
}
|
|
1131
|
-
catch {
|
|
1132
|
-
return record;
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
async function shutdownSubagentSession(session) {
|
|
1137
|
-
try {
|
|
1138
|
-
if (session.extensionRunner.hasHandlers('session_shutdown')) {
|
|
1139
|
-
await session.extensionRunner.emit({ type: 'session_shutdown', reason: 'quit' });
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
finally {
|
|
1143
|
-
session.dispose();
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
export function inspectionToolNames(activeToolNames) {
|
|
1147
|
-
const blocked = new Set([
|
|
1148
|
-
'bash',
|
|
1149
|
-
'edit',
|
|
1150
|
-
'write',
|
|
1151
|
-
'exec_command',
|
|
1152
|
-
'write_stdin',
|
|
1153
|
-
'write_background_bash',
|
|
1154
|
-
'stop_background_bash',
|
|
1155
|
-
'apply_patch',
|
|
1156
|
-
'enter_prewalk',
|
|
1157
|
-
]);
|
|
1158
|
-
const safe = activeToolNames.filter((name) => !blocked.has(name));
|
|
1159
|
-
if (!safe.includes('read'))
|
|
1160
|
-
safe.unshift('read');
|
|
1161
|
-
return safe;
|
|
1162
|
-
}
|
|
1163
|
-
function completionNotice(record, deliveryId) {
|
|
1164
|
-
return {
|
|
1165
|
-
deliveryId,
|
|
1166
|
-
parentSessionId: record.parentSessionId,
|
|
1167
|
-
agentId: record.agentId,
|
|
1168
|
-
type: record.type,
|
|
1169
|
-
status: record.status,
|
|
1170
|
-
...(record.result === undefined ? {} : { summary: record.result.slice(0, 4_000) }),
|
|
1171
|
-
...(record.error === undefined ? {} : { error: record.error }),
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
function terminalRecord(record, status, error) {
|
|
1175
|
-
return {
|
|
1176
|
-
...record,
|
|
1177
|
-
status,
|
|
1178
|
-
completedAt: new Date().toISOString(),
|
|
1179
|
-
...(error === undefined ? {} : { error }),
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
function isTerminal(status) {
|
|
1183
|
-
return status === 'completed' || status === 'failed' || status === 'timed_out' || status === 'cancelled';
|
|
1184
|
-
}
|
|
1185
|
-
function isContinuable(child) {
|
|
1186
|
-
if (!child.sessionFile)
|
|
1187
|
-
return false;
|
|
1188
|
-
if (child.record.status === 'completed')
|
|
1189
|
-
return true;
|
|
1190
|
-
if (child.record.status === 'failed' && child.record.error?.code === 'model_request_failed')
|
|
1191
|
-
return true;
|
|
1192
|
-
if (child.record.status !== 'cancelled')
|
|
1193
|
-
return false;
|
|
1194
|
-
return child.record.error?.code === 'turn_limit_reached'
|
|
1195
|
-
|| child.record.error?.code === 'host_shutdown';
|
|
1196
|
-
}
|
|
1197
|
-
function sanitizeModelError(value) {
|
|
1198
|
-
const normalized = (value ?? 'unknown provider error')
|
|
1199
|
-
.replace(/[\u0000-\u001F\u007F-\u009F]/gu, ' ')
|
|
1200
|
-
.replace(/\s+/gu, ' ')
|
|
1201
|
-
.trim();
|
|
1202
|
-
if (!normalized)
|
|
1203
|
-
return 'unknown provider error';
|
|
1204
|
-
return normalized.length <= 300 ? normalized : `${normalized.slice(0, 299)}…`;
|
|
1205
|
-
}
|
|
1206
|
-
function success(value) {
|
|
1207
|
-
return { ok: true, value };
|
|
1208
|
-
}
|
|
1209
|
-
function failure(code, message) {
|
|
1210
|
-
return { ok: false, error: { code, message } };
|
|
1211
|
-
}
|
|
1212
|
-
function cloneRecord(record) {
|
|
1213
|
-
return structuredClone(record);
|
|
1214
|
-
}
|
|
1215
|
-
function localView(child) {
|
|
1216
|
-
return {
|
|
1217
|
-
...cloneRecord(child.record),
|
|
1218
|
-
...(child.request.model === undefined ? {} : { model: child.request.model }),
|
|
1219
|
-
...(child.session === undefined ? {} : { session: child.session }),
|
|
1220
|
-
...(child.usage === undefined ? {} : { usage: { ...child.usage } }),
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1223
|
-
function fromStored(stored) {
|
|
1224
|
-
return structuredClone(stored);
|
|
1225
|
-
}
|
|
1226
|
-
function toStored(child) {
|
|
1227
|
-
return structuredClone({
|
|
1228
|
-
record: child.record,
|
|
1229
|
-
request: child.request,
|
|
1230
|
-
depth: child.depth,
|
|
1231
|
-
...(child.reportedSavings === undefined ? {} : { reportedSavings: child.reportedSavings }),
|
|
1232
|
-
...(child.sessionFile === undefined ? {} : { sessionFile: child.sessionFile }),
|
|
1233
|
-
...(child.deliveryId === undefined ? {} : { deliveryId: child.deliveryId }),
|
|
1234
|
-
completionPending: child.completionPending,
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
function boundedInteger(value, fallback, minimum, maximum) {
|
|
1238
|
-
return value === undefined || !Number.isInteger(value)
|
|
1239
|
-
? fallback
|
|
1240
|
-
: Math.max(minimum, Math.min(maximum, value));
|
|
1241
|
-
}
|
|
1242
|
-
function subagentStatusPriority(status) {
|
|
1243
|
-
switch (status) {
|
|
1244
|
-
case 'running': return 0;
|
|
1245
|
-
case 'queued': return 1;
|
|
1246
|
-
case 'failed':
|
|
1247
|
-
case 'timed_out':
|
|
1248
|
-
case 'cancelled': return 2;
|
|
1249
|
-
case 'completed': return 3;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
function boundResult(result) {
|
|
1253
|
-
const bytes = Buffer.from(result);
|
|
1254
|
-
return bytes.byteLength <= MAX_RESULT_BYTES
|
|
1255
|
-
? result
|
|
1256
|
-
: `${new TextDecoder().decode(bytes.subarray(0, MAX_RESULT_BYTES))}\n[truncated]`;
|
|
1257
|
-
}
|
|
1258
|
-
function byteLength(value) {
|
|
1259
|
-
return Buffer.byteLength(value);
|
|
1260
|
-
}
|
|
1261
|
-
function emptyUsageTotals() {
|
|
1262
|
-
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cacheWrite1h: 0, cost: 0 };
|
|
1263
|
-
}
|
|
1264
|
-
function addUsage(target, source) {
|
|
1265
|
-
if (!source)
|
|
1266
|
-
return;
|
|
1267
|
-
target.input += source.input;
|
|
1268
|
-
target.output += source.output;
|
|
1269
|
-
target.cacheRead += source.cacheRead;
|
|
1270
|
-
target.cacheWrite += source.cacheWrite;
|
|
1271
|
-
target.cacheWrite1h += source.cacheWrite1h;
|
|
1272
|
-
target.cost += source.cost;
|
|
1273
|
-
}
|
|
1274
|
-
function usageFromEntries(entries) {
|
|
1275
|
-
const totals = emptyUsageTotals();
|
|
1276
|
-
for (const entry of entries) {
|
|
1277
|
-
if (entry.type !== 'message' || entry.message.role !== 'assistant')
|
|
1278
|
-
continue;
|
|
1279
|
-
totals.input += entry.message.usage.input;
|
|
1280
|
-
totals.output += entry.message.usage.output;
|
|
1281
|
-
totals.cacheRead += entry.message.usage.cacheRead;
|
|
1282
|
-
totals.cacheWrite += entry.message.usage.cacheWrite;
|
|
1283
|
-
totals.cacheWrite1h += entry.message.usage.cacheWrite1h ?? 0;
|
|
1284
|
-
totals.cost += entry.message.usage.cost.total;
|
|
1285
|
-
}
|
|
1286
|
-
return totals;
|
|
1287
|
-
}
|
|
1288
|
-
async function loadSessionUsage(sessionFile, expectedSessionId) {
|
|
1289
|
-
try {
|
|
1290
|
-
const totals = emptyUsageTotals();
|
|
1291
|
-
let headerValidated = false;
|
|
1292
|
-
for (const line of (await readFile(sessionFile, 'utf8')).split('\n')) {
|
|
1293
|
-
if (!line.trim())
|
|
1294
|
-
continue;
|
|
1295
|
-
let entry;
|
|
1296
|
-
try {
|
|
1297
|
-
entry = JSON.parse(line);
|
|
1298
|
-
}
|
|
1299
|
-
catch {
|
|
1300
|
-
if (!headerValidated)
|
|
1301
|
-
return undefined;
|
|
1302
|
-
continue;
|
|
1303
|
-
}
|
|
1304
|
-
if (!headerValidated) {
|
|
1305
|
-
if (typeof entry !== 'object'
|
|
1306
|
-
|| entry === null
|
|
1307
|
-
|| Reflect.get(entry, 'type') !== 'session'
|
|
1308
|
-
|| Reflect.get(entry, 'id') !== expectedSessionId)
|
|
1309
|
-
return undefined;
|
|
1310
|
-
headerValidated = true;
|
|
1311
|
-
continue;
|
|
1312
|
-
}
|
|
1313
|
-
addPersistedAssistantUsage(totals, entry);
|
|
1314
|
-
}
|
|
1315
|
-
return headerValidated ? totals : undefined;
|
|
1316
|
-
}
|
|
1317
|
-
catch {
|
|
1318
|
-
return undefined;
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
function addPersistedAssistantUsage(target, entry) {
|
|
1322
|
-
if (typeof entry !== 'object'
|
|
1323
|
-
|| entry === null
|
|
1324
|
-
|| Reflect.get(entry, 'type') !== 'message')
|
|
1325
|
-
return;
|
|
1326
|
-
const message = Reflect.get(entry, 'message');
|
|
1327
|
-
if (typeof message !== 'object' || message === null || Reflect.get(message, 'role') !== 'assistant')
|
|
1328
|
-
return;
|
|
1329
|
-
const usage = Reflect.get(message, 'usage');
|
|
1330
|
-
if (typeof usage !== 'object' || usage === null)
|
|
1331
|
-
return;
|
|
1332
|
-
const cost = Reflect.get(usage, 'cost');
|
|
1333
|
-
if (typeof cost !== 'object' || cost === null)
|
|
1334
|
-
return;
|
|
1335
|
-
const values = {
|
|
1336
|
-
input: Reflect.get(usage, 'input'),
|
|
1337
|
-
output: Reflect.get(usage, 'output'),
|
|
1338
|
-
cacheRead: Reflect.get(usage, 'cacheRead'),
|
|
1339
|
-
cacheWrite: Reflect.get(usage, 'cacheWrite'),
|
|
1340
|
-
cacheWrite1h: Reflect.get(usage, 'cacheWrite1h') ?? 0,
|
|
1341
|
-
cost: Reflect.get(cost, 'total'),
|
|
1342
|
-
};
|
|
1343
|
-
if (!Object.values(values).every((value) => typeof value === 'number' && Number.isFinite(value)))
|
|
1344
|
-
return;
|
|
1345
|
-
addUsage(target, values);
|
|
1346
|
-
}
|
|
1347
|
-
function subtractUsage(current, previous) {
|
|
1348
|
-
const baseline = previous ?? emptyUsageTotals();
|
|
1349
|
-
const result = {
|
|
1350
|
-
input: current.input - baseline.input,
|
|
1351
|
-
output: current.output - baseline.output,
|
|
1352
|
-
cacheRead: current.cacheRead - baseline.cacheRead,
|
|
1353
|
-
cacheWrite: current.cacheWrite - baseline.cacheWrite,
|
|
1354
|
-
cacheWrite1h: current.cacheWrite1h - baseline.cacheWrite1h,
|
|
1355
|
-
cost: current.cost - baseline.cost,
|
|
1356
|
-
};
|
|
1357
|
-
if (Object.values(result).some((value) => !Number.isFinite(value) || value < 0))
|
|
1358
|
-
return undefined;
|
|
1359
|
-
return result.input + result.output + result.cacheRead + result.cacheWrite > 0 ? result : undefined;
|
|
1360
|
-
}
|
|
1361
|
-
function savingsTokens(usage) {
|
|
1362
|
-
return {
|
|
1363
|
-
input: usage.input,
|
|
1364
|
-
output: usage.output,
|
|
1365
|
-
cacheRead: usage.cacheRead,
|
|
1366
|
-
cacheWrite: usage.cacheWrite,
|
|
1367
|
-
cacheWrite1h: usage.cacheWrite1h,
|
|
1368
|
-
};
|
|
1369
|
-
}
|
|
1370
|
-
function modelReference(value) {
|
|
1371
|
-
const separator = value.indexOf('/');
|
|
1372
|
-
if (separator <= 0 || separator === value.length - 1)
|
|
1373
|
-
return undefined;
|
|
1374
|
-
return { provider: value.slice(0, separator), id: value.slice(separator + 1) };
|
|
1375
|
-
}
|
|
1376
|
-
function sessionFileOutcome(sessionFile) {
|
|
1377
|
-
return sessionFile === undefined ? {} : { sessionFile };
|
|
1378
|
-
}
|
|
1379
|
-
async function preflightSessionFile(sessionFile, expectedSessionId) {
|
|
1380
|
-
const contents = await readFile(sessionFile, 'utf8');
|
|
1381
|
-
let header;
|
|
1382
|
-
for (const line of contents.split('\n')) {
|
|
1383
|
-
if (!line.trim())
|
|
1384
|
-
continue;
|
|
1385
|
-
const entry = JSON.parse(line);
|
|
1386
|
-
header ??= entry;
|
|
1387
|
-
}
|
|
1388
|
-
if (typeof header !== 'object'
|
|
1389
|
-
|| header === null
|
|
1390
|
-
|| Reflect.get(header, 'type') !== 'session'
|
|
1391
|
-
|| Reflect.get(header, 'version') !== CURRENT_SESSION_VERSION
|
|
1392
|
-
|| Reflect.get(header, 'id') !== expectedSessionId
|
|
1393
|
-
|| typeof Reflect.get(header, 'timestamp') !== 'string'
|
|
1394
|
-
|| typeof Reflect.get(header, 'cwd') !== 'string') {
|
|
1395
|
-
throw new Error('Retained session file has an invalid header');
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
async function finalAssistantText(sessionFile, completedAt) {
|
|
1399
|
-
let result;
|
|
1400
|
-
for (const line of (await readFile(sessionFile, 'utf8')).split('\n')) {
|
|
1401
|
-
if (!line)
|
|
1402
|
-
continue;
|
|
1403
|
-
const entry = JSON.parse(line);
|
|
1404
|
-
if (entry.type !== 'message'
|
|
1405
|
-
|| entry.message?.role !== 'assistant'
|
|
1406
|
-
|| typeof entry.timestamp !== 'string'
|
|
1407
|
-
|| entry.timestamp > completedAt
|
|
1408
|
-
|| !Array.isArray(entry.message.content))
|
|
1409
|
-
continue;
|
|
1410
|
-
result = entry.message.content
|
|
1411
|
-
.filter((part) => (typeof part === 'object'
|
|
1412
|
-
&& part !== null
|
|
1413
|
-
&& Reflect.get(part, 'type') === 'text'
|
|
1414
|
-
&& typeof Reflect.get(part, 'text') === 'string'))
|
|
1415
|
-
.map((part) => part.text)
|
|
1416
|
-
.join('\n');
|
|
1417
|
-
}
|
|
1418
|
-
return result;
|
|
1419
|
-
}
|
|
1420
|
-
//# sourceMappingURL=host.js.map
|