@code-yeongyu/senpi 2026.8.23 → 2026.8.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +24 -9
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/config.d.ts +6 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +24 -14
- package/dist/config.js.map +1 -1
- package/dist/core/agent-abort-provenance.d.ts +5 -5
- package/dist/core/agent-abort-provenance.d.ts.map +1 -1
- package/dist/core/agent-abort-provenance.js +8 -1
- package/dist/core/agent-abort-provenance.js.map +1 -1
- package/dist/core/agent-session.d.ts +14 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +129 -29
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +35 -8
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/brand.d.ts +2 -0
- package/dist/core/brand.d.ts.map +1 -1
- package/dist/core/brand.js +1 -0
- package/dist/core/brand.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +1 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +24 -8
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js +10 -0
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +0 -8
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation-types.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/monitor-continuation-types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation-types.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +2 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +31 -3
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/terminal-provider-error.js +1 -1
- package/dist/core/extensions/builtin/goal/terminal-provider-error.js.map +1 -1
- package/dist/core/extensions/builtin/goal/wait-ticker.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/wait-ticker.js +14 -9
- package/dist/core/extensions/builtin/goal/wait-ticker.js.map +1 -1
- package/dist/core/extensions/builtin/loop-guard/notice.d.ts.map +1 -1
- package/dist/core/extensions/builtin/loop-guard/notice.js +5 -1
- package/dist/core/extensions/builtin/loop-guard/notice.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/config-schema.d.ts +2 -2
- package/dist/core/extensions/builtin/ttsr/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/index.js +6 -6
- package/dist/core/extensions/builtin/ttsr/index.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/message-update.d.ts +10 -0
- package/dist/core/extensions/builtin/ttsr/message-update.d.ts.map +1 -0
- package/dist/core/extensions/builtin/ttsr/message-update.js +38 -0
- package/dist/core/extensions/builtin/ttsr/message-update.js.map +1 -0
- package/dist/core/extensions/builtin/ttsr/remediation.d.ts +5 -10
- package/dist/core/extensions/builtin/ttsr/remediation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/remediation.js +19 -3
- package/dist/core/extensions/builtin/ttsr/remediation.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/stream-remediation.d.ts +1 -1
- package/dist/core/extensions/builtin/ttsr/stream-remediation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/stream-remediation.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/types.d.ts +1 -1
- package/dist/core/extensions/builtin/ttsr/types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/types.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/watch.d.ts +1 -1
- package/dist/core/extensions/builtin/ttsr/watch.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/watch.js +2 -2
- package/dist/core/extensions/builtin/ttsr/watch.js.map +1 -1
- package/dist/core/extensions/builtin/webfetch/webfetch/fetcher.d.ts.map +1 -1
- package/dist/core/extensions/builtin/webfetch/webfetch/fetcher.js +5 -23
- package/dist/core/extensions/builtin/webfetch/webfetch/fetcher.js.map +1 -1
- package/dist/core/extensions/builtin/webfetch/webfetch/response-body.d.ts +11 -0
- package/dist/core/extensions/builtin/webfetch/webfetch/response-body.d.ts.map +1 -0
- package/dist/core/extensions/builtin/webfetch/webfetch/response-body.js +54 -0
- package/dist/core/extensions/builtin/webfetch/webfetch/response-body.js.map +1 -0
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +107 -45
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +17 -6
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +3 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/keybindings.d.ts +20 -19
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -5
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config-schema.d.ts +17 -5
- package/dist/core/model-config-schema.d.ts.map +1 -1
- package/dist/core/model-config-schema.js +1 -1
- package/dist/core/model-config-schema.js.map +1 -1
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +7 -5
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +3 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +3 -2
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +0 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +0 -18
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +14 -10
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -0
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +3 -6
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +0 -1
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-timeout-retry.d.ts.map +1 -1
- package/dist/core/provider-timeout-retry.js +8 -12
- package/dist/core/provider-timeout-retry.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +3 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/retry-fallback/profile-override.d.ts +24 -0
- package/dist/core/retry-fallback/profile-override.d.ts.map +1 -0
- package/dist/core/retry-fallback/profile-override.js +138 -0
- package/dist/core/retry-fallback/profile-override.js.map +1 -0
- package/dist/core/retry-fallback/settings.d.ts +1 -0
- package/dist/core/retry-fallback/settings.d.ts.map +1 -1
- package/dist/core/retry-fallback/settings.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +20 -5
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +4 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +32 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +18 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +88 -7
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +11 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +14 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +35 -19
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +0 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +2 -5
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +3 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/index.d.ts +4 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +13 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -0
- package/dist/core/tools/powershell.js +39 -0
- package/dist/core/tools/powershell.js.map +1 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +5 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +6 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -0
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts +3 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +27 -6
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -2
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/app-server/daemon/probe.js +1 -1
- package/dist/modes/app-server/daemon/probe.js.map +1 -1
- package/dist/modes/app-server/daemon.js +13 -2
- package/dist/modes/app-server/daemon.js.map +1 -1
- package/dist/modes/app-server/transports/websocket-connection-handler.d.ts.map +1 -1
- package/dist/modes/app-server/transports/websocket-connection-handler.js +4 -0
- package/dist/modes/app-server/transports/websocket-connection-handler.js.map +1 -1
- package/dist/modes/interactive/aborted-error-label.d.ts +4 -1
- package/dist/modes/interactive/aborted-error-label.d.ts.map +1 -1
- package/dist/modes/interactive/aborted-error-label.js +27 -5
- package/dist/modes/interactive/aborted-error-label.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +68 -17
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +6 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +28 -13
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/streaming-reveal.d.ts +8 -0
- package/dist/modes/interactive/streaming-reveal.d.ts.map +1 -1
- package/dist/modes/interactive/streaming-reveal.js +12 -0
- package/dist/modes/interactive/streaming-reveal.js.map +1 -1
- package/dist/modes/json-event.d.ts +16 -13
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +20 -6
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +3 -0
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +7 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +12 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts +1 -0
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +186 -2
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/shell.d.ts +3 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +17 -5
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +60 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/docs/AGENTS.md +3 -1
- package/docs/compaction.md +0 -2
- package/docs/custom-provider.md +6 -6
- package/docs/environment-variables.md +8 -8
- package/docs/extensions.md +6 -5
- package/docs/json.md +7 -2
- package/docs/keybindings.md +1 -1
- package/docs/packages.md +2 -2
- package/docs/rpc.md +32 -3
- package/docs/sdk.md +7 -2
- package/docs/settings.md +9 -1
- package/docs/terminal-setup.md +11 -9
- package/docs/usage.md +4 -1
- package/docs/windows.md +24 -2
- package/examples/AGENTS.md +21 -6
- package/examples/extensions/AGENTS.md +50 -0
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +90 -88
- package/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +40 -40
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +20 -21
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +24 -25
- package/node_modules/@anthropic-ai/claude-agent-sdk/package.json +2 -2
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk-tools.d.ts +102 -5
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts +31 -15
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +80 -78
- package/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/client-bedrock-runtime/package.json +13 -13
- package/node_modules/@aws-sdk/core/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-http/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-login/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-node/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-process/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +6 -6
- package/node_modules/@aws-sdk/eventstream-handler-node/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-eventstream/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-websocket/package.json +6 -6
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +8 -8
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +3 -3
- package/node_modules/@aws-sdk/token-providers/package.json +6 -6
- package/node_modules/@aws-sdk/types/package.json +2 -2
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +26 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +5 -5
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager-proxy.ts +39 -5
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/AGENTS.md +40 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/AGENTS.md +40 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-notification.ts +3 -8
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-notification-queue.ts +2 -6
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +7 -4
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +2 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +7 -6
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.d.ts +4 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.js +8 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +6 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts +1 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +25 -13
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +91 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +93 -54
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +2 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js +97 -46
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +1 -14
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +50 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +129 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +8 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +16 -3
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js +10 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +8 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +17 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/backoff.d.ts +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/backoff.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/backoff.js +24 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/backoff.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.d.ts +36 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js +109 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/failure.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/failure.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/failure.js +109 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/failure.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/index.d.ts +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/index.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/index.js +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/index.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/planner.d.ts +46 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/planner.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/planner.js +41 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/planner.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js +93 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/types.d.ts +121 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/types.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/types.js +11 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/types.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +25 -5
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/sleep.d.ts +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/sleep.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/sleep.js +15 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/sleep.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/package.json +22 -18
- package/node_modules/@earendil-works/pi-pty/dist/index.d.ts +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.d.ts +30 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.js +76 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-bun.js.map +1 -0
- package/node_modules/@earendil-works/pi-pty/dist/session-types.d.ts +3 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session-types.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session.d.ts +2 -0
- package/node_modules/@earendil-works/pi-pty/dist/session.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/session.js +19 -9
- package/node_modules/@earendil-works/pi-pty/dist/session.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +3 -3
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +9 -4
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +8 -2
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +24 -4
- package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +2 -2
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +2 -2
- package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +2 -8
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.d.ts +7 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.js +19 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-module-path.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +11 -14
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +5 -5
- package/node_modules/@smithy/signature-v4/dist-cjs/index.js +19 -7
- package/node_modules/@smithy/signature-v4/dist-es/HeaderFormatter.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/getCanonicalQuery.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/getPayloadHash.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/headerUtil.js +10 -3
- package/node_modules/@smithy/signature-v4/dist-es/moveHeadersToQuery.js +4 -1
- package/node_modules/@smithy/signature-v4/dist-es/prepareRequest.js +4 -1
- package/node_modules/@smithy/signature-v4/package.json +2 -2
- package/node_modules/typebox/build/format/email.mjs +1 -1
- package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
- package/node_modules/typebox/build/format/json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/json_pointer.mjs +2 -2
- package/node_modules/typebox/build/format/json_pointer_uri_fragment.d.mts +2 -2
- package/node_modules/typebox/build/format/json_pointer_uri_fragment.mjs +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
- package/node_modules/typebox/build/system/memory/assign.mjs +2 -1
- package/node_modules/typebox/build/system/memory/create.mjs +3 -4
- package/node_modules/typebox/build/system/memory/discard.mjs +2 -2
- package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
- package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
- package/node_modules/typebox/build/system/memory/update.mjs +3 -2
- package/node_modules/typebox/package.json +1 -1
- package/package.json +110 -108
- package/dist/core/radius.d.ts +0 -2
- package/dist/core/radius.d.ts.map +0 -1
- package/dist/core/radius.js +0 -2
- package/dist/core/radius.js.map +0 -1
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/LICENSE +0 -201
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/README.md +0 -62
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +0 -154
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/constants.js +0 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +0 -16
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +0 -80
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +0 -11
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +0 -10
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/index.js +0 -4
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +0 -5
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/constants.d.ts +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromEnvSigningName.d.ts +0 -18
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromSso.d.ts +0 -12
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromStatic.d.ts +0 -9
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getNewSsoOidcToken.d.ts +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getSsoOidcClient.d.ts +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/index.d.ts +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/nodeProvider.d.ts +0 -18
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/constants.d.ts +0 -3
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromEnvSigningName.d.ts +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromSso.d.ts +0 -10
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromStatic.d.ts +0 -5
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getNewSsoOidcToken.d.ts +0 -9
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getSsoOidcClient.d.ts +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/index.d.ts +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/nodeProvider.d.ts +0 -3
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenExpiry.d.ts +0 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenKey.d.ts +0 -1
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/writeSSOTokenToFile.d.ts +0 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenExpiry.d.ts +0 -5
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenKey.d.ts +0 -4
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/writeSSOTokenToFile.d.ts +0 -5
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +0 -69
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"probe.js","sourceRoot":"","sources":["../../../../src/modes/app-server/daemon/probe.ts"],"names":[],"mappings":"AAAA,OA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,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,IAAY;IACpD,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { readFile, rm } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport WebSocket from \"ws\";\nimport { VERSION } from \"../../../config.ts\";\nimport type { AppServerListen } from \"../index.ts\";\n\ntype TokenPaths = {\n\treadonly tokenFile: string;\n};\n\ntype SettingsPaths = {\n\treadonly settingsFile: string;\n};\n\ntype CleanupPaths = {\n\treadonly pidFile: string;\n\treadonly settingsFile: string;\n};\n\ntype ProbeOutput = Readonly<Record<string, string | number | undefined>>;\n\nexport async function probeListen(\n\tpaths: TokenPaths,\n\tlisten: AppServerListen,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\tif (listen.kind === \"stdio\" || signal?.aborted) return undefined;\n\tlet token: string | undefined;\n\ttry {\n\t\ttoken = (await readFile(paths.tokenFile, \"utf8\")).trim();\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\") && listen.kind === \"ws\") return undefined;\n\t\tif (!isNodeErrorCode(error, \"ENOENT\")) throw error;\n\t\ttoken = undefined;\n\t}\n\tconst probeTarget =\n\t\tlisten.kind === \"ws\"\n\t\t\t? listen.url\n\t\t\t: `ws+unix://${listen.path ?? join(dirname(paths.tokenFile), \"app-server.sock\")}:/`;\n\treturn probeWebSocket(probeTarget, token && token.length > 0 ? token : undefined, timeoutMs, signal);\n}\n\nexport function probeWebSocket(\n\turl: string,\n\ttoken: string | undefined,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\treturn new Promise((resolveProbe) => {\n\t\tif (signal?.aborted) {\n\t\t\tresolveProbe(undefined);\n\t\t\treturn;\n\t\t}\n\t\tlet settled = false;\n\t\tconst socket = new WebSocket(url, token ? { headers: { Authorization: `Bearer ${token}` } } : undefined);\n\t\tconst finish = (result: string | undefined): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tclearTimeout(timeout);\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tsocket.terminate();\n\t\t\tresolveProbe(result);\n\t\t};\n\t\tconst onAbort = (): void => finish(undefined);\n\t\tconst timeout = setTimeout(() => finish(undefined), timeoutMs);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tsocket.once(\"open\", () => {\n\t\t\tsocket.send(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: 1,\n\t\t\t\t\tmethod: \"initialize\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tclientInfo: { name: \"senpi_app_server_daemon\", title: \"senpi app-server daemon\", version: VERSION },\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\t\tsocket.once(\"message\", (data, isBinary) => {\n\t\t\tif (isBinary) {\n\t\t\t\tfinish(undefined);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfinish(readInitializeProbe(data.toString(\"utf8\")));\n\t\t});\n\t\tsocket.once(\"error\", () => finish(undefined));\n\t\tsocket.once(\"close\", () => finish(undefined));\n\t});\n}\n\nexport async function pollProbe(\n\tpaths: TokenPaths,\n\tlisten: AppServerListen,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (Date.now() <= deadline) {\n\t\tif (signal?.aborted) return undefined;\n\t\tconst probe = await probeListen(paths, listen, 2_000, signal);\n\t\tif (probe) return probe;\n\t\tif (signal?.aborted) return undefined;\n\t\tawait delay(100, signal);\n\t}\n\treturn undefined;\n}\n\nexport function readInitializeProbe(text: string): string | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch (error: unknown) {\n\t\tif (error instanceof SyntaxError) return undefined;\n\t\tthrow error;\n\t}\n\tif (!isRecord(parsed) || parsed.id !== 1 || !isRecord(parsed.result)) return undefined;\n\tconst userAgent = parsed.result.userAgent;\n\treturn typeof userAgent === \"string\" ? userAgent : undefined;\n}\n\nexport async function readSettings(paths: SettingsPaths): Promise<{ readonly listen: AppServerListen } | undefined> {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(await readFile(paths.settingsFile, \"utf8\"));\n\t\tif (!isRecord(parsed)) return undefined;\n\t\tconst listen = parseListen(parsed.listen);\n\t\treturn listen ? { listen } : undefined;\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\") || error instanceof SyntaxError) return undefined;\n\t\tthrow error;\n\t}\n}\n\nexport function parseListen(value: unknown): AppServerListen | undefined {\n\tif (!isRecord(value) || typeof value.kind !== \"string\" || typeof value.url !== \"string\") return undefined;\n\tif (value.kind === \"stdio\" && value.url === \"stdio://\") return { kind: \"stdio\", url: \"stdio://\" };\n\tif (value.kind === \"unix\") {\n\t\treturn typeof value.path === \"string\"\n\t\t\t? { kind: \"unix\", url: value.url, path: value.path }\n\t\t\t: { kind: \"unix\", url: value.url };\n\t}\n\tif (value.kind === \"ws\" && typeof value.host === \"string\" && typeof value.port === \"number\") {\n\t\treturn { kind: \"ws\", url: value.url, host: value.host, port: value.port };\n\t}\n\treturn undefined;\n}\n\nexport async function cleanupState(paths: CleanupPaths, listen: AppServerListen): Promise<void> {\n\tawait rm(paths.pidFile, { force: true });\n\tawait rm(paths.settingsFile, { force: true });\n\tif (listen.kind === \"unix\" && listen.path) await rm(listen.path, { force: true });\n}\n\nexport function runningOutput(\n\tstatus: \"already-running\" | \"running\",\n\tpid: number | undefined,\n\tlisten: AppServerListen,\n\tversion: string,\n): ProbeOutput {\n\tif (pid === undefined) return runningUnmanagedOutput(listen, version);\n\treturn { status, pid, listen: listen.url, version };\n}\n\nexport function runningUnmanagedOutput(listen: AppServerListen, version: string): ProbeOutput {\n\treturn { status: \"running-unmanaged\", listen: listen.url, version };\n}\n\nfunction delay(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolveDelay) => {\n\t\tif (signal?.aborted) {\n\t\t\tresolveDelay();\n\t\t\treturn;\n\t\t}\n\t\tconst finish = (): void => {\n\t\t\tclearTimeout(timeout);\n\t\t\tsignal?.removeEventListener(\"abort\", finish);\n\t\t\tresolveDelay();\n\t\t};\n\t\tconst timeout = setTimeout(finish, ms);\n\t\tsignal?.addEventListener(\"abort\", finish, { once: true });\n\t});\n}\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === code;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"probe.js","sourceRoot":"","sources":["../../../../src/modes/app-server/daemon/probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAkB7C,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,KAAiB,EACjB,MAAuB,EACvB,SAAiB,EACjB,MAAoB;IAEpB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,SAAS,CAAC;IACjE,IAAI,KAAyB,CAAC;IAC9B,IAAI,CAAC;QACJ,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACzB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;YAAE,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AC;YACf,OAAO;QACR,CAAC;QACD,MAAM,MAAM,GAAG,GAAS,EAAE;YACzB,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC7C,YAAY,EAAE,CAAC;QAChB,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,IAAY;IACpD,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { readFile, rm } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport WebSocket from \"ws\";\nimport { VERSION } from \"../../../config.ts\";\nimport type { AppServerListen } from \"../index.ts\";\n\ntype TokenPaths = {\n\treadonly tokenFile: string;\n};\n\ntype SettingsPaths = {\n\treadonly settingsFile: string;\n};\n\ntype CleanupPaths = {\n\treadonly pidFile: string;\n\treadonly settingsFile: string;\n};\n\ntype ProbeOutput = Readonly<Record<string, string | number | undefined>>;\n\nexport async function probeListen(\n\tpaths: TokenPaths,\n\tlisten: AppServerListen,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\tif (listen.kind === \"stdio\" || signal?.aborted) return undefined;\n\tlet token: string | undefined;\n\ttry {\n\t\ttoken = (await readFile(paths.tokenFile, \"utf8\")).trim();\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\") && listen.kind === \"ws\") return undefined;\n\t\tif (!isNodeErrorCode(error, \"ENOENT\")) throw error;\n\t\ttoken = undefined;\n\t}\n\tconst probeTarget =\n\t\tlisten.kind === \"ws\"\n\t\t\t? listen.url\n\t\t\t: `ws+unix://${listen.path ?? join(dirname(paths.tokenFile), \"app-server.sock\")}:/`;\n\treturn probeWebSocket(probeTarget, token && token.length > 0 ? token : undefined, timeoutMs, signal);\n}\n\nexport function probeWebSocket(\n\turl: string,\n\ttoken: string | undefined,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\treturn new Promise((resolveProbe) => {\n\t\tif (signal?.aborted) {\n\t\t\tresolveProbe(undefined);\n\t\t\treturn;\n\t\t}\n\t\tlet settled = false;\n\t\tconst socket = new WebSocket(url, token ? { headers: { Authorization: `Bearer ${token}` } } : undefined);\n\t\tconst finish = (result: string | undefined): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tclearTimeout(timeout);\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tsocket.terminate();\n\t\t\tresolveProbe(result);\n\t\t};\n\t\tconst onAbort = (): void => finish(undefined);\n\t\tconst timeout = setTimeout(() => finish(undefined), timeoutMs);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tsocket.once(\"open\", () => {\n\t\t\tsocket.send(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: 1,\n\t\t\t\t\tmethod: \"initialize\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tclientInfo: { name: \"senpi_app_server_daemon\", title: \"senpi app-server daemon\", version: VERSION },\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\t\tsocket.once(\"message\", (data, isBinary) => {\n\t\t\tif (isBinary) {\n\t\t\t\tfinish(undefined);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfinish(readInitializeProbe(data.toString(\"utf8\")));\n\t\t});\n\t\tsocket.on(\"error\", () => finish(undefined));\n\t\tsocket.once(\"close\", () => finish(undefined));\n\t});\n}\n\nexport async function pollProbe(\n\tpaths: TokenPaths,\n\tlisten: AppServerListen,\n\ttimeoutMs: number,\n\tsignal?: AbortSignal,\n): Promise<string | undefined> {\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (Date.now() <= deadline) {\n\t\tif (signal?.aborted) return undefined;\n\t\tconst probe = await probeListen(paths, listen, 2_000, signal);\n\t\tif (probe) return probe;\n\t\tif (signal?.aborted) return undefined;\n\t\tawait delay(100, signal);\n\t}\n\treturn undefined;\n}\n\nexport function readInitializeProbe(text: string): string | undefined {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(text);\n\t} catch (error: unknown) {\n\t\tif (error instanceof SyntaxError) return undefined;\n\t\tthrow error;\n\t}\n\tif (!isRecord(parsed) || parsed.id !== 1 || !isRecord(parsed.result)) return undefined;\n\tconst userAgent = parsed.result.userAgent;\n\treturn typeof userAgent === \"string\" ? userAgent : undefined;\n}\n\nexport async function readSettings(paths: SettingsPaths): Promise<{ readonly listen: AppServerListen } | undefined> {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(await readFile(paths.settingsFile, \"utf8\"));\n\t\tif (!isRecord(parsed)) return undefined;\n\t\tconst listen = parseListen(parsed.listen);\n\t\treturn listen ? { listen } : undefined;\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\") || error instanceof SyntaxError) return undefined;\n\t\tthrow error;\n\t}\n}\n\nexport function parseListen(value: unknown): AppServerListen | undefined {\n\tif (!isRecord(value) || typeof value.kind !== \"string\" || typeof value.url !== \"string\") return undefined;\n\tif (value.kind === \"stdio\" && value.url === \"stdio://\") return { kind: \"stdio\", url: \"stdio://\" };\n\tif (value.kind === \"unix\") {\n\t\treturn typeof value.path === \"string\"\n\t\t\t? { kind: \"unix\", url: value.url, path: value.path }\n\t\t\t: { kind: \"unix\", url: value.url };\n\t}\n\tif (value.kind === \"ws\" && typeof value.host === \"string\" && typeof value.port === \"number\") {\n\t\treturn { kind: \"ws\", url: value.url, host: value.host, port: value.port };\n\t}\n\treturn undefined;\n}\n\nexport async function cleanupState(paths: CleanupPaths, listen: AppServerListen): Promise<void> {\n\tawait rm(paths.pidFile, { force: true });\n\tawait rm(paths.settingsFile, { force: true });\n\tif (listen.kind === \"unix\" && listen.path) await rm(listen.path, { force: true });\n}\n\nexport function runningOutput(\n\tstatus: \"already-running\" | \"running\",\n\tpid: number | undefined,\n\tlisten: AppServerListen,\n\tversion: string,\n): ProbeOutput {\n\tif (pid === undefined) return runningUnmanagedOutput(listen, version);\n\treturn { status, pid, listen: listen.url, version };\n}\n\nexport function runningUnmanagedOutput(listen: AppServerListen, version: string): ProbeOutput {\n\treturn { status: \"running-unmanaged\", listen: listen.url, version };\n}\n\nfunction delay(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolveDelay) => {\n\t\tif (signal?.aborted) {\n\t\t\tresolveDelay();\n\t\t\treturn;\n\t\t}\n\t\tconst finish = (): void => {\n\t\t\tclearTimeout(timeout);\n\t\t\tsignal?.removeEventListener(\"abort\", finish);\n\t\t\tresolveDelay();\n\t\t};\n\t\tconst timeout = setTimeout(finish, ms);\n\t\tsignal?.addEventListener(\"abort\", finish, { once: true });\n\t});\n}\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === code;\n}\n"]}
|
|
@@ -122,9 +122,20 @@ async function statusDaemon(paths, listen) {
|
|
|
122
122
|
async function spawnDaemon(paths, listen) {
|
|
123
123
|
const stderr = await open(paths.stderrLog, "w");
|
|
124
124
|
try {
|
|
125
|
-
const
|
|
125
|
+
const daemonExec = process.versions.bun
|
|
126
|
+
? process.env.npm_node_execpath && !/[/\\]bun(?:$|[/\\])/.test(process.env.npm_node_execpath)
|
|
127
|
+
? process.env.npm_node_execpath
|
|
128
|
+
: "/opt/homebrew/bin/node"
|
|
129
|
+
: process.execPath;
|
|
130
|
+
const child = spawn(daemonExec, [
|
|
131
|
+
...(process.versions.bun ? [] : process.execArgv),
|
|
132
|
+
resolveCliMainPath(),
|
|
133
|
+
"app-server",
|
|
134
|
+
"--listen",
|
|
135
|
+
listen.url,
|
|
136
|
+
], {
|
|
126
137
|
detached: true,
|
|
127
|
-
env: process.env,
|
|
138
|
+
env: { ...process.env, SENPI_RUNTIME: "node" },
|
|
128
139
|
stdio: ["ignore", "ignore", stderr.fd],
|
|
129
140
|
});
|
|
130
141
|
const exited = observeDaemonExit(child);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../../src/modes/app-server/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EACN,YAAY,EACZ,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,sBAAsB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEN,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AA4B7B,MAAM,WAAW,GAAG,EAA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AAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { type ChildProcess, spawn } from \"node:child_process\";\nimport { mkdir, open, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport * as properLockfile from \"proper-lockfile\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { inspectAppServerListenOccupancy } from \"./daemon/occupancy.ts\";\nimport {\n\tcleanupState,\n\tpollProbe,\n\tprobeListen,\n\treadSettings,\n\trunningOutput,\n\trunningUnmanagedOutput,\n} from \"./daemon/probe.ts\";\nimport {\n\ttype DaemonPidFile,\n\tparseDaemonPidFile,\n\tprocessMatchesPidFile,\n\treadProcessStartTime,\n\tstopValidatedPid,\n\twaitForGone,\n\twaitForStartTime,\n} from \"./daemon/process.ts\";\nimport type { AppServerDaemonCommandOptions, AppServerListen } from \"./index.ts\";\n\nexport interface DaemonPaths {\n\treadonly dir: string;\n\treadonly pidFile: string;\n\treadonly lockFile: string;\n\treadonly settingsFile: string;\n\treadonly stderrLog: string;\n\treadonly tokenFile: string;\n}\n\ntype DaemonOutput = Readonly<Record<string, string | number | undefined>>;\n\ntype SpawnedDaemon = {\n\treadonly pid: number;\n\treadonly exited: Promise<DaemonExit>;\n};\n\ntype DaemonExit =\n\t| { readonly kind: \"error\"; readonly error: Error }\n\t| { readonly kind: \"exit\"; readonly code: number | null; readonly signal: NodeJS.Signals | null };\n\ntype DaemonReadiness =\n\t| { readonly kind: \"ready\"; readonly version: string }\n\t| { readonly kind: \"timed-out\" }\n\t| { readonly kind: \"exited\"; readonly exit: DaemonExit };\n\nconst lockOptions = { stale: 60_000, retries: { retries: 100, minTimeout: 20, maxTimeout: 100 } } as const;\n\nexport function createDaemonPaths(agentDir = getAgentDir()): DaemonPaths {\n\tconst dir = join(agentDir, \"app-server-daemon\");\n\treturn {\n\t\tdir,\n\t\tpidFile: join(dir, \"app-server.pid\"),\n\t\tlockFile: join(dir, \"daemon.lock\"),\n\t\tsettingsFile: join(dir, \"settings.json\"),\n\t\tstderrLog: join(dir, \"stderr.log\"),\n\t\ttokenFile: join(agentDir, \"app-server\", \"ws-token\"),\n\t};\n}\n\nexport async function withDaemonStateLock<T>(paths: DaemonPaths, task: () => Promise<T>): Promise<T> {\n\tawait mkdir(paths.dir, { recursive: true });\n\tconst release = await properLockfile.lock(paths.dir, { ...lockOptions, lockfilePath: paths.lockFile });\n\ttry {\n\t\treturn await task();\n\t} finally {\n\t\tawait release();\n\t}\n}\n\nexport async function runAppServerDaemonCommand(options: AppServerDaemonCommandOptions): Promise<void> {\n\tconst paths = createDaemonPaths();\n\tconst output = await withDaemonStateLock(paths, async () => {\n\t\ttry {\n\t\t\treturn await runLockedDaemonCommand(options, paths);\n\t\t} catch (error: unknown) {\n\t\t\tprocess.exitCode = 1;\n\t\t\treturn { status: \"error\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t});\n\tprocess.stdout.write(`${JSON.stringify(output)}\\n`);\n}\n\nasync function runLockedDaemonCommand(\n\toptions: AppServerDaemonCommandOptions,\n\tpaths: DaemonPaths,\n): Promise<DaemonOutput> {\n\tconst settings = await readSettings(paths);\n\tconst listen = options.verb === \"start\" ? options.listen : (settings?.listen ?? options.listen);\n\tswitch (options.verb) {\n\t\tcase \"start\":\n\t\t\treturn startDaemon(paths, listen);\n\t\tcase \"stop\":\n\t\t\treturn stopDaemon(paths, listen);\n\t\tcase \"status\":\n\t\t\treturn statusDaemon(paths, listen);\n\t\tcase \"restart\": {\n\t\t\tconst restartListen = settings?.listen ?? options.listen;\n\t\t\tawait stopDaemon(paths, restartListen);\n\t\t\treturn startDaemon(paths, restartListen);\n\t\t}\n\t}\n}\n\nasync function startDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst occupancy = await inspectAppServerListenOccupancy(paths, listen);\n\tif (occupancy.kind === \"app-server\") {\n\t\tconst pidFile = await readPidFile(paths);\n\t\tconst pid = pidFile && (await processMatchesPidFile(pidFile)) ? pidFile.pid : undefined;\n\t\tif (pid !== undefined) return runningOutput(\"already-running\", pid, listen, occupancy.version);\n\t\treturn { status: \"already-running\", listen: listen.url, version: occupancy.version };\n\t}\n\tconst pidFile = await readPidFile(paths);\n\tif (pidFile && (await processMatchesPidFile(pidFile))) {\n\t\tconst lateProbe = await pollProbe(paths, listen, 10_000);\n\t\tif (lateProbe) return runningOutput(\"already-running\", pidFile.pid, listen, lateProbe);\n\t\tthrow new Error(`managed daemon pid ${pidFile.pid} did not answer initialize`);\n\t}\n\tconst spawned = await spawnDaemon(paths, listen);\n\tconst readiness = await waitForDaemonReady(paths, listen, spawned.exited);\n\tif (readiness.kind === \"ready\") {\n\t\treturn { status: \"started\", pid: spawned.pid, listen: listen.url };\n\t}\n\tawait stopValidatedPid(\n\t\t{ pid: spawned.pid, processStartTime: (await readProcessStartTime(spawned.pid)) ?? \"\" },\n\t\t\"SIGTERM\",\n\t);\n\tconst message =\n\t\treadiness.kind === \"exited\"\n\t\t\t? `spawned daemon ${describeDaemonExit(readiness.exit)} before answering initialize`\n\t\t\t: \"spawned daemon did not answer initialize within 10s\";\n\tconst diagnostic = await appendDaemonStderr(paths, message);\n\tawait cleanupState(paths, listen);\n\tthrow new Error(diagnostic);\n}\n\nasync function stopDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst pidFile = await readPidFile(paths);\n\tif (!pidFile) {\n\t\tif (!(await probeListen(paths, listen, 2_000))) await cleanupState(paths, listen);\n\t\treturn { status: \"not-running\" };\n\t}\n\tif (!(await processMatchesPidFile(pidFile))) {\n\t\tawait cleanupState(paths, listen);\n\t\treturn { status: \"not-running\" };\n\t}\n\tawait stopValidatedPid(pidFile, \"SIGTERM\");\n\tif (await processMatchesPidFile(pidFile)) {\n\t\tawait stopValidatedPid(pidFile, \"SIGKILL\");\n\t}\n\tawait waitForGone(pidFile, 10_000);\n\tawait cleanupState(paths, listen);\n\treturn { status: \"stopped\" };\n}\n\nasync function statusDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst probe = await probeListen(paths, listen, 2_000);\n\tconst pidFile = await readPidFile(paths);\n\tconst pidMatches = pidFile ? await processMatchesPidFile(pidFile) : false;\n\tif (probe && pidFile && pidMatches) return runningOutput(\"running\", pidFile.pid, listen, probe);\n\tif (probe) return runningUnmanagedOutput(listen, probe);\n\tif (pidFile && !pidMatches) await cleanupState(paths, listen);\n\treturn { status: \"not-running\" };\n}\n\nasync function spawnDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<SpawnedDaemon> {\n\tconst stderr = await open(paths.stderrLog, \"w\");\n\ttry {\n\t\tconst child = spawn(\n\t\t\tprocess.execPath,\n\t\t\t[...process.execArgv, resolveCliMainPath(), \"app-server\", \"--listen\", listen.url],\n\t\t\t{\n\t\t\t\tdetached: true,\n\t\t\t\tenv: process.env,\n\t\t\t\tstdio: [\"ignore\", \"ignore\", stderr.fd],\n\t\t\t},\n\t\t);\n\t\tconst exited = observeDaemonExit(child);\n\t\tchild.unref();\n\t\tconst pid = child.pid;\n\t\tif (pid === undefined) throw new Error(\"failed to spawn daemon process\");\n\t\tconst startTime = await waitForStartTime(pid, 2_000);\n\t\tawait writeFile(paths.pidFile, `${JSON.stringify({ pid, processStartTime: startTime })}\\n`, { mode: 0o600 });\n\t\tawait writeFile(paths.settingsFile, `${JSON.stringify({ listen })}\\n`, { mode: 0o600 });\n\t\treturn { pid, exited };\n\t} finally {\n\t\tawait stderr.close();\n\t}\n}\n\nasync function waitForDaemonReady(\n\tpaths: DaemonPaths,\n\tlisten: AppServerListen,\n\texited: Promise<DaemonExit>,\n): Promise<DaemonReadiness> {\n\tconst controller = new AbortController();\n\ttry {\n\t\tconst probe = pollProbe(paths, listen, 10_000, controller.signal).then(\n\t\t\t(version): DaemonReadiness => (version ? { kind: \"ready\", version } : { kind: \"timed-out\" }),\n\t\t);\n\t\tconst childExit = exited.then((exit): DaemonReadiness => ({ kind: \"exited\", exit }));\n\t\treturn await Promise.race([probe, childExit]);\n\t} finally {\n\t\tcontroller.abort();\n\t}\n}\n\nfunction observeDaemonExit(child: ChildProcess): Promise<DaemonExit> {\n\treturn new Promise((resolveExit) => {\n\t\tchild.once(\"error\", (error) => resolveExit({ kind: \"error\", error }));\n\t\tchild.once(\"exit\", (code, signal) => resolveExit({ kind: \"exit\", code, signal }));\n\t});\n}\n\nfunction describeDaemonExit(exit: DaemonExit): string {\n\tif (exit.kind === \"error\") return `failed to launch (${exit.error.message})`;\n\tif (exit.signal) return `was terminated by ${exit.signal}`;\n\treturn `exited with code ${exit.code ?? \"unknown\"}`;\n}\n\nasync function appendDaemonStderr(paths: DaemonPaths, message: string): Promise<string> {\n\ttry {\n\t\tconst stderr = (await readFile(paths.stderrLog, \"utf8\")).trim();\n\t\treturn stderr ? `${message}\\n${stderr}` : message;\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\")) return message;\n\t\tthrow error;\n\t}\n}\n\nasync function readPidFile(paths: DaemonPaths): Promise<DaemonPidFile | undefined> {\n\ttry {\n\t\treturn parseDaemonPidFile(await readFile(paths.pidFile, \"utf8\"));\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\")) return undefined;\n\t\tthrow error;\n\t}\n}\n\nfunction resolveCliMainPath(): string {\n\tconst modulePath = fileURLToPath(import.meta.url);\n\tconst extension = modulePath.endsWith(\".ts\") ? \".ts\" : \".js\";\n\treturn resolve(dirname(modulePath), \"..\", \"..\", `cli-main${extension}`);\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === code;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../../src/modes/app-server/daemon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,IAAI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I,EAAE,CAAC;QAChE,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACnD,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACzB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,OAAO,CAAC;QACrD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,KAAkB;IAC5C,IAAI,CAAC;QACJ,OAAO,kBAAkB,CAAC,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAClE,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACzB,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,SAAS,CAAC;QACvD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB;IAC1B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,SAAS,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,eAAe,CAAC,KAAc,EAAE,IAAY;IACpD,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { type ChildProcess, spawn } from \"node:child_process\";\nimport { mkdir, open, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport * as properLockfile from \"proper-lockfile\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { inspectAppServerListenOccupancy } from \"./daemon/occupancy.ts\";\nimport {\n\tcleanupState,\n\tpollProbe,\n\tprobeListen,\n\treadSettings,\n\trunningOutput,\n\trunningUnmanagedOutput,\n} from \"./daemon/probe.ts\";\nimport {\n\ttype DaemonPidFile,\n\tparseDaemonPidFile,\n\tprocessMatchesPidFile,\n\treadProcessStartTime,\n\tstopValidatedPid,\n\twaitForGone,\n\twaitForStartTime,\n} from \"./daemon/process.ts\";\nimport type { AppServerDaemonCommandOptions, AppServerListen } from \"./index.ts\";\n\nexport interface DaemonPaths {\n\treadonly dir: string;\n\treadonly pidFile: string;\n\treadonly lockFile: string;\n\treadonly settingsFile: string;\n\treadonly stderrLog: string;\n\treadonly tokenFile: string;\n}\n\ntype DaemonOutput = Readonly<Record<string, string | number | undefined>>;\n\ntype SpawnedDaemon = {\n\treadonly pid: number;\n\treadonly exited: Promise<DaemonExit>;\n};\n\ntype DaemonExit =\n\t| { readonly kind: \"error\"; readonly error: Error }\n\t| { readonly kind: \"exit\"; readonly code: number | null; readonly signal: NodeJS.Signals | null };\n\ntype DaemonReadiness =\n\t| { readonly kind: \"ready\"; readonly version: string }\n\t| { readonly kind: \"timed-out\" }\n\t| { readonly kind: \"exited\"; readonly exit: DaemonExit };\n\nconst lockOptions = { stale: 60_000, retries: { retries: 100, minTimeout: 20, maxTimeout: 100 } } as const;\n\nexport function createDaemonPaths(agentDir = getAgentDir()): DaemonPaths {\n\tconst dir = join(agentDir, \"app-server-daemon\");\n\treturn {\n\t\tdir,\n\t\tpidFile: join(dir, \"app-server.pid\"),\n\t\tlockFile: join(dir, \"daemon.lock\"),\n\t\tsettingsFile: join(dir, \"settings.json\"),\n\t\tstderrLog: join(dir, \"stderr.log\"),\n\t\ttokenFile: join(agentDir, \"app-server\", \"ws-token\"),\n\t};\n}\n\nexport async function withDaemonStateLock<T>(paths: DaemonPaths, task: () => Promise<T>): Promise<T> {\n\tawait mkdir(paths.dir, { recursive: true });\n\tconst release = await properLockfile.lock(paths.dir, { ...lockOptions, lockfilePath: paths.lockFile });\n\ttry {\n\t\treturn await task();\n\t} finally {\n\t\tawait release();\n\t}\n}\n\nexport async function runAppServerDaemonCommand(options: AppServerDaemonCommandOptions): Promise<void> {\n\tconst paths = createDaemonPaths();\n\tconst output = await withDaemonStateLock(paths, async () => {\n\t\ttry {\n\t\t\treturn await runLockedDaemonCommand(options, paths);\n\t\t} catch (error: unknown) {\n\t\t\tprocess.exitCode = 1;\n\t\t\treturn { status: \"error\", message: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t});\n\tprocess.stdout.write(`${JSON.stringify(output)}\\n`);\n}\n\nasync function runLockedDaemonCommand(\n\toptions: AppServerDaemonCommandOptions,\n\tpaths: DaemonPaths,\n): Promise<DaemonOutput> {\n\tconst settings = await readSettings(paths);\n\tconst listen = options.verb === \"start\" ? options.listen : (settings?.listen ?? options.listen);\n\tswitch (options.verb) {\n\t\tcase \"start\":\n\t\t\treturn startDaemon(paths, listen);\n\t\tcase \"stop\":\n\t\t\treturn stopDaemon(paths, listen);\n\t\tcase \"status\":\n\t\t\treturn statusDaemon(paths, listen);\n\t\tcase \"restart\": {\n\t\t\tconst restartListen = settings?.listen ?? options.listen;\n\t\t\tawait stopDaemon(paths, restartListen);\n\t\t\treturn startDaemon(paths, restartListen);\n\t\t}\n\t}\n}\n\nasync function startDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst occupancy = await inspectAppServerListenOccupancy(paths, listen);\n\tif (occupancy.kind === \"app-server\") {\n\t\tconst pidFile = await readPidFile(paths);\n\t\tconst pid = pidFile && (await processMatchesPidFile(pidFile)) ? pidFile.pid : undefined;\n\t\tif (pid !== undefined) return runningOutput(\"already-running\", pid, listen, occupancy.version);\n\t\treturn { status: \"already-running\", listen: listen.url, version: occupancy.version };\n\t}\n\tconst pidFile = await readPidFile(paths);\n\tif (pidFile && (await processMatchesPidFile(pidFile))) {\n\t\tconst lateProbe = await pollProbe(paths, listen, 10_000);\n\t\tif (lateProbe) return runningOutput(\"already-running\", pidFile.pid, listen, lateProbe);\n\t\tthrow new Error(`managed daemon pid ${pidFile.pid} did not answer initialize`);\n\t}\n\tconst spawned = await spawnDaemon(paths, listen);\n\tconst readiness = await waitForDaemonReady(paths, listen, spawned.exited);\n\tif (readiness.kind === \"ready\") {\n\t\treturn { status: \"started\", pid: spawned.pid, listen: listen.url };\n\t}\n\tawait stopValidatedPid(\n\t\t{ pid: spawned.pid, processStartTime: (await readProcessStartTime(spawned.pid)) ?? \"\" },\n\t\t\"SIGTERM\",\n\t);\n\tconst message =\n\t\treadiness.kind === \"exited\"\n\t\t\t? `spawned daemon ${describeDaemonExit(readiness.exit)} before answering initialize`\n\t\t\t: \"spawned daemon did not answer initialize within 10s\";\n\tconst diagnostic = await appendDaemonStderr(paths, message);\n\tawait cleanupState(paths, listen);\n\tthrow new Error(diagnostic);\n}\n\nasync function stopDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst pidFile = await readPidFile(paths);\n\tif (!pidFile) {\n\t\tif (!(await probeListen(paths, listen, 2_000))) await cleanupState(paths, listen);\n\t\treturn { status: \"not-running\" };\n\t}\n\tif (!(await processMatchesPidFile(pidFile))) {\n\t\tawait cleanupState(paths, listen);\n\t\treturn { status: \"not-running\" };\n\t}\n\tawait stopValidatedPid(pidFile, \"SIGTERM\");\n\tif (await processMatchesPidFile(pidFile)) {\n\t\tawait stopValidatedPid(pidFile, \"SIGKILL\");\n\t}\n\tawait waitForGone(pidFile, 10_000);\n\tawait cleanupState(paths, listen);\n\treturn { status: \"stopped\" };\n}\n\nasync function statusDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<DaemonOutput> {\n\tconst probe = await probeListen(paths, listen, 2_000);\n\tconst pidFile = await readPidFile(paths);\n\tconst pidMatches = pidFile ? await processMatchesPidFile(pidFile) : false;\n\tif (probe && pidFile && pidMatches) return runningOutput(\"running\", pidFile.pid, listen, probe);\n\tif (probe) return runningUnmanagedOutput(listen, probe);\n\tif (pidFile && !pidMatches) await cleanupState(paths, listen);\n\treturn { status: \"not-running\" };\n}\n\nasync function spawnDaemon(paths: DaemonPaths, listen: AppServerListen): Promise<SpawnedDaemon> {\n\tconst stderr = await open(paths.stderrLog, \"w\");\n\ttry {\n\t\tconst daemonExec = process.versions.bun\n\t\t\t? process.env.npm_node_execpath && !/[/\\\\]bun(?:$|[/\\\\])/.test(process.env.npm_node_execpath)\n\t\t\t\t? process.env.npm_node_execpath\n\t\t\t\t: \"/opt/homebrew/bin/node\"\n\t\t\t: process.execPath;\n\t\tconst child = spawn(\n\t\t\tdaemonExec,\n\t\t\t[\n\t\t\t\t...(process.versions.bun ? [] : process.execArgv),\n\t\t\t\tresolveCliMainPath(),\n\t\t\t\t\"app-server\",\n\t\t\t\t\"--listen\",\n\t\t\t\tlisten.url,\n\t\t\t],\n\t\t\t{\n\t\t\t\tdetached: true,\n\t\t\t\tenv: { ...process.env, SENPI_RUNTIME: \"node\" },\n\t\t\t\tstdio: [\"ignore\", \"ignore\", stderr.fd],\n\t\t\t},\n\t\t);\n\t\tconst exited = observeDaemonExit(child);\n\t\tchild.unref();\n\t\tconst pid = child.pid;\n\t\tif (pid === undefined) throw new Error(\"failed to spawn daemon process\");\n\t\tconst startTime = await waitForStartTime(pid, 2_000);\n\t\tawait writeFile(paths.pidFile, `${JSON.stringify({ pid, processStartTime: startTime })}\\n`, { mode: 0o600 });\n\t\tawait writeFile(paths.settingsFile, `${JSON.stringify({ listen })}\\n`, { mode: 0o600 });\n\t\treturn { pid, exited };\n\t} finally {\n\t\tawait stderr.close();\n\t}\n}\n\nasync function waitForDaemonReady(\n\tpaths: DaemonPaths,\n\tlisten: AppServerListen,\n\texited: Promise<DaemonExit>,\n): Promise<DaemonReadiness> {\n\tconst controller = new AbortController();\n\ttry {\n\t\tconst probe = pollProbe(paths, listen, 10_000, controller.signal).then(\n\t\t\t(version): DaemonReadiness => (version ? { kind: \"ready\", version } : { kind: \"timed-out\" }),\n\t\t);\n\t\tconst childExit = exited.then((exit): DaemonReadiness => ({ kind: \"exited\", exit }));\n\t\treturn await Promise.race([probe, childExit]);\n\t} finally {\n\t\tcontroller.abort();\n\t}\n}\n\nfunction observeDaemonExit(child: ChildProcess): Promise<DaemonExit> {\n\treturn new Promise((resolveExit) => {\n\t\tchild.once(\"error\", (error) => resolveExit({ kind: \"error\", error }));\n\t\tchild.once(\"exit\", (code, signal) => resolveExit({ kind: \"exit\", code, signal }));\n\t});\n}\n\nfunction describeDaemonExit(exit: DaemonExit): string {\n\tif (exit.kind === \"error\") return `failed to launch (${exit.error.message})`;\n\tif (exit.signal) return `was terminated by ${exit.signal}`;\n\treturn `exited with code ${exit.code ?? \"unknown\"}`;\n}\n\nasync function appendDaemonStderr(paths: DaemonPaths, message: string): Promise<string> {\n\ttry {\n\t\tconst stderr = (await readFile(paths.stderrLog, \"utf8\")).trim();\n\t\treturn stderr ? `${message}\\n${stderr}` : message;\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\")) return message;\n\t\tthrow error;\n\t}\n}\n\nasync function readPidFile(paths: DaemonPaths): Promise<DaemonPidFile | undefined> {\n\ttry {\n\t\treturn parseDaemonPidFile(await readFile(paths.pidFile, \"utf8\"));\n\t} catch (error: unknown) {\n\t\tif (isNodeErrorCode(error, \"ENOENT\")) return undefined;\n\t\tthrow error;\n\t}\n}\n\nfunction resolveCliMainPath(): string {\n\tconst modulePath = fileURLToPath(import.meta.url);\n\tconst extension = modulePath.endsWith(\".ts\") ? \".ts\" : \".js\";\n\treturn resolve(dirname(modulePath), \"..\", \"..\", `cli-main${extension}`);\n}\n\nfunction isNodeErrorCode(error: unknown, code: string): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === code;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-connection-handler.d.ts","sourceRoot":"","sources":["../../../../src/modes/app-server/transports/websocket-connection-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAkB,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAGhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAgC,KAAK,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAKvG,MAAM,MAAM,mCAAmC,GAAG;IACjD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5E,oBAAoB,IAAI,IAAI,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,wBAAgB,yCAAyC,CAAC,OAAO,EAAE;IAClE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACrC,GAAG,mCAAmC,
|
|
1
|
+
{"version":3,"file":"websocket-connection-handler.d.ts","sourceRoot":"","sources":["../../../../src/modes/app-server/transports/websocket-connection-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAkB,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAGhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAgC,KAAK,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAKvG,MAAM,MAAM,mCAAmC,GAAG;IACjD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5E,oBAAoB,IAAI,IAAI,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,wBAAgB,yCAAyC,CAAC,OAAO,EAAE;IAClE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,6BAA6B,CAAC;IAC7C,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CACrC,GAAG,mCAAmC,CAuEtC;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1F"}
|
|
@@ -5,6 +5,10 @@ const DEFAULT_OUTBOUND_QUEUE_BYTES = 16 * 1024 * 1024;
|
|
|
5
5
|
const WEBSOCKET_RETRY_LATER = 1013;
|
|
6
6
|
export function createAppServerWebSocketConnectionHandler(options) {
|
|
7
7
|
const webSocketServer = new WebSocketServer({ noServer: true });
|
|
8
|
+
webSocketServer.on("error", (error) => {
|
|
9
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10
|
+
process.stderr.write(`app-server websocket server error: ${message}\n`);
|
|
11
|
+
});
|
|
8
12
|
const connections = new Set();
|
|
9
13
|
let nextConnectionId = 1;
|
|
10
14
|
const handleUpgrade = (request, socket, head) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-connection-handler.js","sourceRoot":"","sources":["../../../../src/modes/app-server/transports/websocket-connection-handler.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,OAAO,EAAE,4BAA4B,EAAsC,MAAM,qBAAqB,CAAC;AAEvG,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,qBAAqB,GAAG,IAAI,CAAC;AASnC,MAAM,UAAU,yCAAyC,CAAC,OAMzD;IACA,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAa,CAAC;IACzC,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,MAAM,aAAa,GAAG,CAAC,OAAwB,EAAE,MAAc,EAAE,IAAY,EAAQ,EAAE;QACtF,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YACxC,OAAO;QACR,CAAC;QACD,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACzB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;YAC1C,OAAO;QACR,CAAC;QACD,IAAI,CAAC,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1D,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;YAC3C,OAAO;QACR,CAAC;QACD,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAA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ED,SAAS,SAAS,CAAC,OAAwB;IAC1C,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;AAC7C,CAAC;AAED,SAAS,aAAa,CAAC,MAAc,EAAE,UAA2B,EAAE,MAAc;IACjF,MAAM,CAAC,KAAK,CAAC,YAAY,UAAU,IAAI,MAAM,oDAAoD,CAAC,CAAC;IACnG,MAAM,CAAC,OAAO,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { IncomingMessage, Server } from \"node:http\";\nimport type { Duplex } from \"node:stream\";\nimport WebSocket, { WebSocketServer } from \"ws\";\nimport type { RpcEnvelope } from \"../rpc/envelope.ts\";\nimport { parseNdjsonLine, serializeNdjsonMessage } from \"../rpc/ndjson.ts\";\nimport type { TransportKind } from \"../server/connection.ts\";\nimport type { ServerCore } from \"../server/server-core.ts\";\nimport { isWebSocketRequestAuthorized, type ResolvedWebSocketListenerAuth } from \"./websocket-auth.ts\";\n\nconst DEFAULT_OUTBOUND_QUEUE_BYTES = 16 * 1024 * 1024;\nconst WEBSOCKET_RETRY_LATER = 1013;\n\nexport type AppServerWebSocketConnectionHandler = {\n\treadonly connectionCount: number;\n\thandleUpgrade(request: IncomingMessage, socket: Duplex, head: Buffer): void;\n\tterminateConnections(): void;\n\tclose(): Promise<void>;\n};\n\nexport function createAppServerWebSocketConnectionHandler(options: {\n\treadonly core: ServerCore;\n\treadonly auth: ResolvedWebSocketListenerAuth;\n\treadonly transportKind: TransportKind;\n\treadonly connectionIdPrefix: string;\n\treadonly outboundQueueBytes?: number;\n}): AppServerWebSocketConnectionHandler {\n\tconst webSocketServer = new WebSocketServer({ noServer: true });\n\tconst connections = new Set<WebSocket>();\n\tlet nextConnectionId = 1;\n\tconst handleUpgrade = (request: IncomingMessage, socket: Duplex, head: Buffer): void => {\n\t\tif (hasOrigin(request)) {\n\t\t\trejectUpgrade(socket, 403, \"Forbidden\");\n\t\t\treturn;\n\t\t}\n\t\tif (request.url !== \"/\") {\n\t\t\trejectUpgrade(socket, 400, \"Bad Request\");\n\t\t\treturn;\n\t\t}\n\t\tif (!isWebSocketRequestAuthorized(request, options.auth)) {\n\t\t\trejectUpgrade(socket, 401, \"Unauthorized\");\n\t\t\treturn;\n\t\t}\n\t\twebSocketServer.handleUpgrade(request, socket, head, (websocket) => {\n\t\t\tconst connectionId = `${options.connectionIdPrefix}-${nextConnectionId}`;\n\t\t\tnextConnectionId += 1;\n\t\t\tconnections.add(websocket);\n\t\t\toptions.core.addConnection({\n\t\t\t\tid: connectionId,\n\t\t\t\ttransportKind: options.transportKind,\n\t\t\t\tsend: (message) => sendWebSocketMessage(websocket, message, options.outboundQueueBytes),\n\t\t\t\tclose: () => websocket.close(WEBSOCKET_RETRY_LATER, \"slow-client\"),\n\t\t\t});\n\t\t\twebsocket.on(\"message\", (data, isBinary) => {\n\t\t\t\tif (isBinary) return;\n\t\t\t\tconst parsed = parseNdjsonLine(data.toString(\"utf8\"));\n\t\t\t\tif (parsed.kind === \"parse-error\") {\n\t\t\t\t\tsendWebSocketMessage(websocket, parsed.message, options.outboundQueueBytes).catch((error: unknown) => {\n\t\t\t\t\t\tterminateOnTransportError(websocket, error);\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// A rejected dispatch (e.g. the response send failing on a dying socket)\n\t\t\t\t// must not surface as an unhandled rejection that kills the server.\n\t\t\t\toptions.core.receive(connectionId, parsed).catch((error: unknown) => {\n\t\t\t\t\tterminateOnTransportError(websocket, error);\n\t\t\t\t});\n\t\t\t});\n\t\t\twebsocket.on(\"error\", (error: unknown) => {\n\t\t\t\t// A socket-level error with no listener throws and can crash the\n\t\t\t\t// server; isolate the fault to this connection instead.\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tprocess.stderr.write(`app-server websocket connection error: ${message}\\n`);\n\t\t\t\twebsocket.terminate();\n\t\t\t});\n\t\t\twebsocket.on(\"close\", () => {\n\t\t\t\tconnections.delete(websocket);\n\t\t\t\toptions.core.removeConnection(connectionId);\n\t\t\t});\n\t\t});\n\t};\n\treturn {\n\t\tget connectionCount() {\n\t\t\treturn connections.size;\n\t\t},\n\t\thandleUpgrade,\n\t\tterminateConnections() {\n\t\t\tfor (const websocket of connections) websocket.terminate();\n\t\t},\n\t\tclose() {\n\t\t\treturn closeServer(webSocketServer);\n\t\t},\n\t};\n}\n\nexport function closeServer(server: Pick<Server | WebSocketServer, \"close\">): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tserver.close((error) => {\n\t\t\tif (error) return reject(error);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction sendWebSocketMessage(\n\twebsocket: WebSocket,\n\tmessage: RpcEnvelope,\n\toutboundQueueBytes = DEFAULT_OUTBOUND_QUEUE_BYTES,\n): Promise<void> {\n\tconst payload = serializeNdjsonMessage(message).trimEnd();\n\tif (websocket.bufferedAmount + Buffer.byteLength(payload) > outboundQueueBytes) {\n\t\tconst closed = waitForSocketClose(websocket);\n\t\twebsocket.close(WEBSOCKET_RETRY_LATER, \"slow-client\");\n\t\treturn closed;\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\twebsocket.send(payload, (error) => {\n\t\t\tif (error) return reject(error);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction terminateOnTransportError(websocket: WebSocket, error: unknown): void {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tprocess.stderr.write(`app-server websocket transport error: ${message}\\n`);\n\twebsocket.terminate();\n}\n\nfunction waitForSocketClose(websocket: WebSocket): Promise<void> {\n\tif (websocket.readyState === WebSocket.CLOSED) return Promise.resolve();\n\treturn new Promise((resolve) => {\n\t\twebsocket.once(\"close\", () => resolve());\n\t});\n}\n\nfunction hasOrigin(request: IncomingMessage): boolean {\n\treturn request.headers.origin !== undefined;\n}\n\nfunction rejectUpgrade(socket: Duplex, statusCode: 400 | 401 | 403, reason: string): void {\n\tsocket.write(`HTTP/1.1 ${statusCode} ${reason}\\r\\nConnection: close\\r\\nContent-Length: 0\\r\\n\\r\\n`);\n\tsocket.destroy();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"websocket-connection-handler.js","sourceRoot":"","sources":["../../../../src/modes/app-server/transports/websocket-connection-handler.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,OAAO,EAAE,4BAA4B,EAAsC,MAAM,qBAAqB,CAAC;AAEvG,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACtD,MAAM,qBAAqB,GAAG,IAAI,CAAC;AASnC,MAAM,UAAU,yCAAyC,CAAC,OAMzD;IACA,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAc,EAAE,EAAE;QAC9C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,OAAO,IAAI,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,GAAG,EAAa,CAAC;IACzC,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,MAAM,aAAa,GAAG,CAAC,OAAwB,EAAE,MAAc,EAAE,IAAY,EAAQ,EAAE;QACtF,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YACxC,OAAO;QACR,CAAC;QACD,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACzB,aAAa,CAAC,MAAM,EAAE,GAAG,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AC/C,IAAI,SAAS,CAAC,UAAU,KAAK,SAAS,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IACxE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,OAAwB;IAC1C,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;AAC7C,CAAC;AAED,SAAS,aAAa,CAAC,MAAc,EAAE,UAA2B,EAAE,MAAc;IACjF,MAAM,CAAC,KAAK,CAAC,YAAY,UAAU,IAAI,MAAM,oDAAoD,CAAC,CAAC;IACnG,MAAM,CAAC,OAAO,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { IncomingMessage, Server } from \"node:http\";\nimport type { Duplex } from \"node:stream\";\nimport WebSocket, { WebSocketServer } from \"ws\";\nimport type { RpcEnvelope } from \"../rpc/envelope.ts\";\nimport { parseNdjsonLine, serializeNdjsonMessage } from \"../rpc/ndjson.ts\";\nimport type { TransportKind } from \"../server/connection.ts\";\nimport type { ServerCore } from \"../server/server-core.ts\";\nimport { isWebSocketRequestAuthorized, type ResolvedWebSocketListenerAuth } from \"./websocket-auth.ts\";\n\nconst DEFAULT_OUTBOUND_QUEUE_BYTES = 16 * 1024 * 1024;\nconst WEBSOCKET_RETRY_LATER = 1013;\n\nexport type AppServerWebSocketConnectionHandler = {\n\treadonly connectionCount: number;\n\thandleUpgrade(request: IncomingMessage, socket: Duplex, head: Buffer): void;\n\tterminateConnections(): void;\n\tclose(): Promise<void>;\n};\n\nexport function createAppServerWebSocketConnectionHandler(options: {\n\treadonly core: ServerCore;\n\treadonly auth: ResolvedWebSocketListenerAuth;\n\treadonly transportKind: TransportKind;\n\treadonly connectionIdPrefix: string;\n\treadonly outboundQueueBytes?: number;\n}): AppServerWebSocketConnectionHandler {\n\tconst webSocketServer = new WebSocketServer({ noServer: true });\n\twebSocketServer.on(\"error\", (error: unknown) => {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`app-server websocket server error: ${message}\\n`);\n\t});\n\tconst connections = new Set<WebSocket>();\n\tlet nextConnectionId = 1;\n\tconst handleUpgrade = (request: IncomingMessage, socket: Duplex, head: Buffer): void => {\n\t\tif (hasOrigin(request)) {\n\t\t\trejectUpgrade(socket, 403, \"Forbidden\");\n\t\t\treturn;\n\t\t}\n\t\tif (request.url !== \"/\") {\n\t\t\trejectUpgrade(socket, 400, \"Bad Request\");\n\t\t\treturn;\n\t\t}\n\t\tif (!isWebSocketRequestAuthorized(request, options.auth)) {\n\t\t\trejectUpgrade(socket, 401, \"Unauthorized\");\n\t\t\treturn;\n\t\t}\n\t\twebSocketServer.handleUpgrade(request, socket, head, (websocket) => {\n\t\t\tconst connectionId = `${options.connectionIdPrefix}-${nextConnectionId}`;\n\t\t\tnextConnectionId += 1;\n\t\t\tconnections.add(websocket);\n\t\t\toptions.core.addConnection({\n\t\t\t\tid: connectionId,\n\t\t\t\ttransportKind: options.transportKind,\n\t\t\t\tsend: (message) => sendWebSocketMessage(websocket, message, options.outboundQueueBytes),\n\t\t\t\tclose: () => websocket.close(WEBSOCKET_RETRY_LATER, \"slow-client\"),\n\t\t\t});\n\t\t\twebsocket.on(\"message\", (data, isBinary) => {\n\t\t\t\tif (isBinary) return;\n\t\t\t\tconst parsed = parseNdjsonLine(data.toString(\"utf8\"));\n\t\t\t\tif (parsed.kind === \"parse-error\") {\n\t\t\t\t\tsendWebSocketMessage(websocket, parsed.message, options.outboundQueueBytes).catch((error: unknown) => {\n\t\t\t\t\t\tterminateOnTransportError(websocket, error);\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// A rejected dispatch (e.g. the response send failing on a dying socket)\n\t\t\t\t// must not surface as an unhandled rejection that kills the server.\n\t\t\t\toptions.core.receive(connectionId, parsed).catch((error: unknown) => {\n\t\t\t\t\tterminateOnTransportError(websocket, error);\n\t\t\t\t});\n\t\t\t});\n\t\t\twebsocket.on(\"error\", (error: unknown) => {\n\t\t\t\t// A socket-level error with no listener throws and can crash the\n\t\t\t\t// server; isolate the fault to this connection instead.\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tprocess.stderr.write(`app-server websocket connection error: ${message}\\n`);\n\t\t\t\twebsocket.terminate();\n\t\t\t});\n\t\t\twebsocket.on(\"close\", () => {\n\t\t\t\tconnections.delete(websocket);\n\t\t\t\toptions.core.removeConnection(connectionId);\n\t\t\t});\n\t\t});\n\t};\n\treturn {\n\t\tget connectionCount() {\n\t\t\treturn connections.size;\n\t\t},\n\t\thandleUpgrade,\n\t\tterminateConnections() {\n\t\t\tfor (const websocket of connections) websocket.terminate();\n\t\t},\n\t\tclose() {\n\t\t\treturn closeServer(webSocketServer);\n\t\t},\n\t};\n}\n\nexport function closeServer(server: Pick<Server | WebSocketServer, \"close\">): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tserver.close((error) => {\n\t\t\tif (error) return reject(error);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction sendWebSocketMessage(\n\twebsocket: WebSocket,\n\tmessage: RpcEnvelope,\n\toutboundQueueBytes = DEFAULT_OUTBOUND_QUEUE_BYTES,\n): Promise<void> {\n\tconst payload = serializeNdjsonMessage(message).trimEnd();\n\tif (websocket.bufferedAmount + Buffer.byteLength(payload) > outboundQueueBytes) {\n\t\tconst closed = waitForSocketClose(websocket);\n\t\twebsocket.close(WEBSOCKET_RETRY_LATER, \"slow-client\");\n\t\treturn closed;\n\t}\n\treturn new Promise((resolve, reject) => {\n\t\twebsocket.send(payload, (error) => {\n\t\t\tif (error) return reject(error);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction terminateOnTransportError(websocket: WebSocket, error: unknown): void {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tprocess.stderr.write(`app-server websocket transport error: ${message}\\n`);\n\twebsocket.terminate();\n}\n\nfunction waitForSocketClose(websocket: WebSocket): Promise<void> {\n\tif (websocket.readyState === WebSocket.CLOSED) return Promise.resolve();\n\treturn new Promise((resolve) => {\n\t\twebsocket.once(\"close\", () => resolve());\n\t});\n}\n\nfunction hasOrigin(request: IncomingMessage): boolean {\n\treturn request.headers.origin !== undefined;\n}\n\nfunction rejectUpgrade(socket: Duplex, statusCode: 400 | 401 | 403, reason: string): void {\n\tsocket.write(`HTTP/1.1 ${statusCode} ${reason}\\r\\nConnection: close\\r\\nContent-Length: 0\\r\\n\\r\\n`);\n\tsocket.destroy();\n}\n"]}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai/compat";
|
|
2
|
+
import type { AgentAbortSource } from "../../core/agent-abort-provenance.ts";
|
|
3
|
+
export declare function abortedMessageForRendering(message: AssistantMessage, retryAttempt: number, abortSource: AgentAbortSource | undefined): AssistantMessage;
|
|
4
|
+
export declare function abortedErrorLabel(persisted: string | undefined, retryAttempt: number, abortSource: AgentAbortSource | undefined): string;
|
|
2
5
|
//# sourceMappingURL=aborted-error-label.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aborted-error-label.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/aborted-error-label.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"aborted-error-label.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/aborted-error-label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAO7E,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,gBAAgB,GAAG,SAAS,GACvC,gBAAgB,CAGlB;AAED,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,gBAAgB,GAAG,SAAS,GACvC,MAAM,CAWR"}
|
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const PERSISTED_SOURCE_LABELS = new Set(["Operation aborted", "System operation aborted"]);
|
|
2
|
+
// Labels this module itself persists on the live path. A transcript replay has
|
|
3
|
+
// no live provenance and must render them verbatim, never re-prefix them.
|
|
4
|
+
const PERSISTED_PROVIDER_LABEL_RE = /^(?:Provider retry failed after \d+ attempts?|Provider request failed(?::.*)?)$/;
|
|
5
|
+
export function abortedMessageForRendering(message, retryAttempt, abortSource) {
|
|
6
|
+
if (message.stopReason !== "aborted")
|
|
7
|
+
return message;
|
|
8
|
+
return { ...message, errorMessage: abortedErrorLabel(message.errorMessage, retryAttempt, abortSource) };
|
|
9
|
+
}
|
|
10
|
+
export function abortedErrorLabel(persisted, retryAttempt, abortSource) {
|
|
11
|
+
if (abortSource === "user")
|
|
12
|
+
return "Operation aborted";
|
|
13
|
+
if (abortSource === "system")
|
|
14
|
+
return "System operation aborted";
|
|
15
|
+
if (abortSource === "provider")
|
|
16
|
+
return persisted ?? "Provider request failed";
|
|
17
|
+
if (persisted !== undefined && PERSISTED_SOURCE_LABELS.has(persisted))
|
|
18
|
+
return persisted;
|
|
19
|
+
if (persisted !== undefined && PERSISTED_PROVIDER_LABEL_RE.test(persisted))
|
|
3
20
|
return persisted;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
21
|
+
const legacyRetry = persisted?.match(/^Aborted after (\d+) retry attempts?$/);
|
|
22
|
+
if (legacyRetry)
|
|
23
|
+
return `Provider retry failed after ${legacyRetry[1]} attempt${legacyRetry[1] === "1" ? "" : "s"}`;
|
|
24
|
+
if (retryAttempt > 0)
|
|
25
|
+
return `Provider retry failed after ${retryAttempt} attempt${retryAttempt === 1 ? "" : "s"}`;
|
|
26
|
+
if (persisted !== undefined && persisted !== "Request was aborted")
|
|
27
|
+
return `Provider request failed: ${persisted}`;
|
|
28
|
+
return "Provider request failed";
|
|
7
29
|
}
|
|
8
30
|
//# sourceMappingURL=aborted-error-label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aborted-error-label.js","sourceRoot":"","sources":["../../../src/modes/interactive/aborted-error-label.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aborted-error-label.js","sourceRoot":"","sources":["../../../src/modes/interactive/aborted-error-label.ts"],"names":[],"mappings":"AAGA,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAC3F,+EAA+E;AAC/E,0EAA0E;AAC1E,MAAM,2BAA2B,GAAG,iFAAiF,CAAC;AAEtH,MAAM,UAAU,0BAA0B,CACzC,OAAyB,EACzB,YAAoB,EACpB,WAAyC;IAEzC,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IACrD,OAAO,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,iBAAiB,CAAC,OAAO,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,CAAC;AACzG,CAAC;AAED,MAAM,UAAU,iBAAiB,CAChC,SAA6B,EAC7B,YAAoB,EACpB,WAAyC;IAEzC,IAAI,WAAW,KAAK,MAAM;QAAE,OAAO,mBAAmB,CAAC;IACvD,IAAI,WAAW,KAAK,QAAQ;QAAE,OAAO,0BAA0B,CAAC;IAChE,IAAI,WAAW,KAAK,UAAU;QAAE,OAAO,SAAS,IAAI,yBAAyB,CAAC;IAC9E,IAAI,SAAS,KAAK,SAAS,IAAI,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACxF,IAAI,SAAS,KAAK,SAAS,IAAI,2BAA2B,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7F,MAAM,WAAW,GAAG,SAAS,EAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC9E,IAAI,WAAW;QAAE,OAAO,+BAA+B,WAAW,CAAC,CAAC,CAAC,WAAW,WAAW,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACpH,IAAI,YAAY,GAAG,CAAC;QAAE,OAAO,+BAA+B,YAAY,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACnH,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,qBAAqB;QAAE,OAAO,4BAA4B,SAAS,EAAE,CAAC;IACnH,OAAO,yBAAyB,CAAC;AAClC,CAAC","sourcesContent":["import type { AssistantMessage } from \"@earendil-works/pi-ai/compat\";\nimport type { AgentAbortSource } from \"../../core/agent-abort-provenance.ts\";\n\nconst PERSISTED_SOURCE_LABELS = new Set([\"Operation aborted\", \"System operation aborted\"]);\n// Labels this module itself persists on the live path. A transcript replay has\n// no live provenance and must render them verbatim, never re-prefix them.\nconst PERSISTED_PROVIDER_LABEL_RE = /^(?:Provider retry failed after \\d+ attempts?|Provider request failed(?::.*)?)$/;\n\nexport function abortedMessageForRendering(\n\tmessage: AssistantMessage,\n\tretryAttempt: number,\n\tabortSource: AgentAbortSource | undefined,\n): AssistantMessage {\n\tif (message.stopReason !== \"aborted\") return message;\n\treturn { ...message, errorMessage: abortedErrorLabel(message.errorMessage, retryAttempt, abortSource) };\n}\n\nexport function abortedErrorLabel(\n\tpersisted: string | undefined,\n\tretryAttempt: number,\n\tabortSource: AgentAbortSource | undefined,\n): string {\n\tif (abortSource === \"user\") return \"Operation aborted\";\n\tif (abortSource === \"system\") return \"System operation aborted\";\n\tif (abortSource === \"provider\") return persisted ?? \"Provider request failed\";\n\tif (persisted !== undefined && PERSISTED_SOURCE_LABELS.has(persisted)) return persisted;\n\tif (persisted !== undefined && PERSISTED_PROVIDER_LABEL_RE.test(persisted)) return persisted;\n\tconst legacyRetry = persisted?.match(/^Aborted after (\\d+) retry attempts?$/);\n\tif (legacyRetry) return `Provider retry failed after ${legacyRetry[1]} attempt${legacyRetry[1] === \"1\" ? \"\" : \"s\"}`;\n\tif (retryAttempt > 0) return `Provider retry failed after ${retryAttempt} attempt${retryAttempt === 1 ? \"\" : \"s\"}`;\n\tif (persisted !== undefined && persisted !== \"Request was aborted\") return `Provider request failed: ${persisted}`;\n\treturn \"Provider request failed\";\n}\n"]}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Container, SelectList } from "@earendil-works/pi-tui";
|
|
2
|
+
import { Container, type Focusable, SelectList } from "@earendil-works/pi-tui";
|
|
3
3
|
/**
|
|
4
4
|
* Component that renders a thinking level selector with borders
|
|
5
5
|
*/
|
|
6
|
-
export declare class ThinkingSelectorComponent extends Container {
|
|
6
|
+
export declare class ThinkingSelectorComponent extends Container implements Focusable {
|
|
7
|
+
private searchInput;
|
|
7
8
|
private selectList;
|
|
8
|
-
|
|
9
|
+
private selectListChildIndex;
|
|
10
|
+
private allItems;
|
|
11
|
+
private onSelect;
|
|
12
|
+
private onCancel;
|
|
13
|
+
private onSelectAsDefault?;
|
|
14
|
+
private _focused;
|
|
15
|
+
get focused(): boolean;
|
|
16
|
+
set focused(value: boolean);
|
|
17
|
+
constructor(currentLevel: ThinkingLevel, availableLevels: ThinkingLevel[], onSelect: (level: ThinkingLevel) => void, onCancel: () => void, onSelectAsDefault?: (level: ThinkingLevel) => void, defaultThinkingLevel?: ThinkingLevel);
|
|
18
|
+
private buildSelectList;
|
|
19
|
+
private applyFilter;
|
|
20
|
+
handleInput(keyData: string): void;
|
|
9
21
|
getSelectList(): SelectList;
|
|
10
22
|
}
|
|
11
23
|
//# sourceMappingURL=thinking-selector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAMd,UAAU,EAIV,MAAM,wBAAwB,CAAC;AAoBhC;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAU,YAAW,SAAS;IAC5E,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,iBAAiB,CAAC,CAAiC;IAC3D,OAAO,CAAC,QAAQ,CAAS;IAEzB,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAGzB;gBAGA,YAAY,EAAE,aAAa,EAC3B,eAAe,EAAE,aAAa,EAAE,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACxC,QAAQ,EAAE,MAAM,IAAI,EACpB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAClD,oBAAoB,CAAC,EAAE,aAAa;IAsCrC,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,WAAW;IAUnB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAsBlC,aAAa,IAAI,UAAU;CAG3B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Container, SelectList } from "@earendil-works/pi-tui";
|
|
2
|
-
import { getSelectListTheme } from "../theme/theme.js";
|
|
1
|
+
import { Container, fuzzyFilter, getKeybindings, Input, matchesKey, SelectList, Spacer, Text, } from "@earendil-works/pi-tui";
|
|
2
|
+
import { getSelectListTheme, theme } from "../theme/theme.js";
|
|
3
3
|
import { DynamicBorder } from "./dynamic-border.js";
|
|
4
|
+
import { keyDisplayText } from "./keybinding-hints.js";
|
|
4
5
|
const THINKING_SELECT_LIST_LAYOUT = {
|
|
5
6
|
minPrimaryColumnWidth: 12,
|
|
6
7
|
maxPrimaryColumnWidth: 32,
|
|
@@ -18,32 +19,82 @@ const LEVEL_DESCRIPTIONS = {
|
|
|
18
19
|
* Component that renders a thinking level selector with borders
|
|
19
20
|
*/
|
|
20
21
|
export class ThinkingSelectorComponent extends Container {
|
|
21
|
-
|
|
22
|
+
get focused() {
|
|
23
|
+
return this._focused;
|
|
24
|
+
}
|
|
25
|
+
set focused(value) {
|
|
26
|
+
this._focused = value;
|
|
27
|
+
this.searchInput.focused = value;
|
|
28
|
+
}
|
|
29
|
+
constructor(currentLevel, availableLevels, onSelect, onCancel, onSelectAsDefault, defaultThinkingLevel) {
|
|
22
30
|
super();
|
|
23
|
-
|
|
31
|
+
this._focused = false;
|
|
32
|
+
this.onSelect = onSelect;
|
|
33
|
+
this.onCancel = onCancel;
|
|
34
|
+
this.onSelectAsDefault = onSelectAsDefault;
|
|
35
|
+
this.allItems = availableLevels.map((level) => ({
|
|
24
36
|
value: level,
|
|
25
37
|
label: level,
|
|
26
|
-
description: LEVEL_DESCRIPTIONS[level],
|
|
38
|
+
description: level === defaultThinkingLevel ? `${LEVEL_DESCRIPTIONS[level]} · default` : LEVEL_DESCRIPTIONS[level],
|
|
27
39
|
}));
|
|
28
40
|
// Add top border
|
|
29
41
|
this.addChild(new DynamicBorder());
|
|
42
|
+
this.addChild(new Spacer(1));
|
|
43
|
+
this.addChild(new Text("Thinking Level", 0, 0));
|
|
44
|
+
this.addChild(new Spacer(1));
|
|
45
|
+
this.addChild(new Text(`${keyDisplayText("app.thinking.cycle")} cycles thinking levels in-session`, 0, 0));
|
|
46
|
+
this.addChild(new Spacer(1));
|
|
47
|
+
this.searchInput = new Input();
|
|
48
|
+
this.searchInput.onSubmit = () => this.selectList.handleInput("\r");
|
|
49
|
+
this.addChild(this.searchInput);
|
|
50
|
+
this.addChild(new Spacer(1));
|
|
30
51
|
// Create selector
|
|
31
|
-
this.selectList =
|
|
32
|
-
|
|
33
|
-
const currentIndex = thinkingLevels.findIndex((item) => item.value === currentLevel);
|
|
34
|
-
if (currentIndex !== -1) {
|
|
35
|
-
this.selectList.setSelectedIndex(currentIndex);
|
|
36
|
-
}
|
|
37
|
-
this.selectList.onSelect = (item) => {
|
|
38
|
-
onSelect(item.value);
|
|
39
|
-
};
|
|
40
|
-
this.selectList.onCancel = () => {
|
|
41
|
-
onCancel();
|
|
42
|
-
};
|
|
52
|
+
this.selectList = this.buildSelectList(this.allItems, currentLevel);
|
|
53
|
+
this.selectListChildIndex = this.children.length;
|
|
43
54
|
this.addChild(this.selectList);
|
|
55
|
+
this.addChild(new Spacer(1));
|
|
56
|
+
this.addChild(new Text(theme.fg("dim", " Enter to select · Ctrl+S to set as default · Esc to cancel"), 0, 0));
|
|
44
57
|
// Add bottom border
|
|
45
58
|
this.addChild(new DynamicBorder());
|
|
46
59
|
}
|
|
60
|
+
buildSelectList(items, preselect) {
|
|
61
|
+
const list = new SelectList(items, Math.max(1, items.length), getSelectListTheme(), THINKING_SELECT_LIST_LAYOUT);
|
|
62
|
+
const currentIndex = items.findIndex((item) => item.value === preselect);
|
|
63
|
+
if (currentIndex !== -1) {
|
|
64
|
+
list.setSelectedIndex(currentIndex);
|
|
65
|
+
}
|
|
66
|
+
list.onSelect = (item) => this.onSelect(item.value);
|
|
67
|
+
list.onCancel = () => this.onCancel();
|
|
68
|
+
return list;
|
|
69
|
+
}
|
|
70
|
+
applyFilter(query) {
|
|
71
|
+
const filtered = query
|
|
72
|
+
? fuzzyFilter(this.allItems, query, (item) => `${item.label} ${item.description ?? ""}`)
|
|
73
|
+
: this.allItems;
|
|
74
|
+
const selectedValue = this.selectList.getSelectedItem()?.value;
|
|
75
|
+
const newList = this.buildSelectList(filtered, selectedValue);
|
|
76
|
+
this.children[this.selectListChildIndex] = newList;
|
|
77
|
+
this.selectList = newList;
|
|
78
|
+
}
|
|
79
|
+
handleInput(keyData) {
|
|
80
|
+
if (matchesKey(keyData, "ctrl+s") && this.onSelectAsDefault) {
|
|
81
|
+
const item = this.selectList.getSelectedItem();
|
|
82
|
+
if (item)
|
|
83
|
+
this.onSelectAsDefault(item.value);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const kb = getKeybindings();
|
|
87
|
+
const isNav = kb.matches(keyData, "tui.select.up") ||
|
|
88
|
+
kb.matches(keyData, "tui.select.down") ||
|
|
89
|
+
kb.matches(keyData, "tui.select.confirm") ||
|
|
90
|
+
kb.matches(keyData, "tui.select.cancel");
|
|
91
|
+
if (isNav) {
|
|
92
|
+
this.selectList.handleInput(keyData);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.searchInput.handleInput(keyData);
|
|
96
|
+
this.applyFilter(this.searchInput.getValue());
|
|
97
|
+
}
|
|
47
98
|
getSelectList() {
|
|
48
99
|
return this.selectList;
|
|
49
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AACA,OAAO,EACN,SAAS,EAET,WAAW,EACX,cAAc,EACd,KAAK,EACL,UAAU,EAEV,UAAU,EAEV,MAAM,EACN,IAA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import {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tgetKeybindings,\n\tInput,\n\tmatchesKey,\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\tSpacer,\n\tText,\n} from \"@earendil-works/pi-tui\";\nimport { getSelectListTheme, theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\nconst THINKING_SELECT_LIST_LAYOUT: SelectListLayoutOptions = {\n\tminPrimaryColumnWidth: 12,\n\tmaxPrimaryColumnWidth: 32,\n};\n\nconst LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string> = {\n\toff: \"No reasoning\",\n\tminimal: \"Very brief reasoning (~1k tokens)\",\n\tlow: \"Light reasoning (~2k tokens)\",\n\tmedium: \"Moderate reasoning (~8k tokens)\",\n\thigh: \"Deep reasoning (~16k tokens)\",\n\txhigh: \"Extended reasoning (~32k tokens or native xhigh effort)\",\n\tmax: \"Maximum reasoning\",\n};\n\n/**\n * Component that renders a thinking level selector with borders\n */\nexport class ThinkingSelectorComponent extends Container implements Focusable {\n\tprivate searchInput: Input;\n\tprivate selectList: SelectList;\n\tprivate selectListChildIndex: number;\n\tprivate allItems: SelectItem[];\n\tprivate onSelect: (level: ThinkingLevel) => void;\n\tprivate onCancel: () => void;\n\tprivate onSelectAsDefault?: (level: ThinkingLevel) => void;\n\tprivate _focused = false;\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(\n\t\tcurrentLevel: ThinkingLevel,\n\t\tavailableLevels: ThinkingLevel[],\n\t\tonSelect: (level: ThinkingLevel) => void,\n\t\tonCancel: () => void,\n\t\tonSelectAsDefault?: (level: ThinkingLevel) => void,\n\t\tdefaultThinkingLevel?: ThinkingLevel,\n\t) {\n\t\tsuper();\n\t\tthis.onSelect = onSelect;\n\t\tthis.onCancel = onCancel;\n\t\tthis.onSelectAsDefault = onSelectAsDefault;\n\n\t\tthis.allItems = availableLevels.map((level) => ({\n\t\t\tvalue: level,\n\t\t\tlabel: level,\n\t\t\tdescription:\n\t\t\t\tlevel === defaultThinkingLevel ? `${LEVEL_DESCRIPTIONS[level]} · default` : LEVEL_DESCRIPTIONS[level],\n\t\t}));\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(\"Thinking Level\", 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(`${keyDisplayText(\"app.thinking.cycle\")} cycles thinking levels in-session`, 0, 0));\n\t\tthis.addChild(new Spacer(1));\n\n\t\tthis.searchInput = new Input();\n\t\tthis.searchInput.onSubmit = () => this.selectList.handleInput(\"\\r\");\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create selector\n\t\tthis.selectList = this.buildSelectList(this.allItems, currentLevel);\n\t\tthis.selectListChildIndex = this.children.length;\n\t\tthis.addChild(this.selectList);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"dim\", \" Enter to select · Ctrl+S to set as default · Esc to cancel\"), 0, 0));\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tprivate buildSelectList(items: SelectItem[], preselect?: ThinkingLevel): SelectList {\n\t\tconst list = new SelectList(items, Math.max(1, items.length), getSelectListTheme(), THINKING_SELECT_LIST_LAYOUT);\n\t\tconst currentIndex = items.findIndex((item) => item.value === preselect);\n\t\tif (currentIndex !== -1) {\n\t\t\tlist.setSelectedIndex(currentIndex);\n\t\t}\n\t\tlist.onSelect = (item) => this.onSelect(item.value as ThinkingLevel);\n\t\tlist.onCancel = () => this.onCancel();\n\t\treturn list;\n\t}\n\n\tprivate applyFilter(query: string): void {\n\t\tconst filtered = query\n\t\t\t? fuzzyFilter(this.allItems, query, (item) => `${item.label} ${item.description ?? \"\"}`)\n\t\t\t: this.allItems;\n\t\tconst selectedValue = this.selectList.getSelectedItem()?.value as ThinkingLevel | undefined;\n\t\tconst newList = this.buildSelectList(filtered, selectedValue);\n\t\tthis.children[this.selectListChildIndex] = newList;\n\t\tthis.selectList = newList;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tif (matchesKey(keyData, \"ctrl+s\") && this.onSelectAsDefault) {\n\t\t\tconst item = this.selectList.getSelectedItem();\n\t\t\tif (item) this.onSelectAsDefault(item.value as ThinkingLevel);\n\t\t\treturn;\n\t\t}\n\n\t\tconst kb = getKeybindings();\n\t\tconst isNav =\n\t\t\tkb.matches(keyData, \"tui.select.up\") ||\n\t\t\tkb.matches(keyData, \"tui.select.down\") ||\n\t\t\tkb.matches(keyData, \"tui.select.confirm\") ||\n\t\t\tkb.matches(keyData, \"tui.select.cancel\");\n\t\tif (isNav) {\n\t\t\tthis.selectList.handleInput(keyData);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.searchInput.handleInput(keyData);\n\t\tthis.applyFilter(this.searchInput.getValue());\n\t}\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-editor.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/external-editor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"external-editor.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/external-editor.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,oBAAoB,GAC7B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAE/B,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAsCxG;AAED,MAAM,MAAM,cAAc,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAEvH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAoBlH"}
|
|
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { stripBom } from "../../utils/text.js";
|
|
5
6
|
export async function editInExternalEditor(options) {
|
|
6
7
|
const directory = mkdtempSync(join(tmpdir(), "pi-editor-"));
|
|
7
8
|
const filePath = join(directory, "prompt.md");
|
|
@@ -29,7 +30,7 @@ export async function editInExternalEditor(options) {
|
|
|
29
30
|
if (outcome.code !== 0) {
|
|
30
31
|
return { status: "failed" };
|
|
31
32
|
}
|
|
32
|
-
return { status: "complete", content: readFileSync(filePath, "utf-8").replace(/\n$/, "") };
|
|
33
|
+
return { status: "complete", content: stripBom(readFileSync(filePath, "utf-8")).replace(/\n$/, "") };
|
|
33
34
|
}
|
|
34
35
|
finally {
|
|
35
36
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-editor.js","sourceRoot":"","sources":["../../../src/modes/interactive/external-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aA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AM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAgE,CAAC,OAAO,EAAE,EAAE;QAC5G,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE;YAC1D,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;SACnC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACtD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,gFAAgF;IAChF,+EAA+E;IAC/E,0EAA0E;IAC1E,IAAI,CAAC,OAAO,CAAC,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1D,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IACtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { stripBom } from \"../../utils/text.ts\";\n\nexport interface ExternalEditorOptions {\n\tcommand: string;\n\tcontent: string;\n}\n\nexport type ExternalEditorResult =\n\t| { status: \"complete\"; content: string }\n\t| { status: \"failed\" }\n\t| { status: \"launch-failed\" };\n\nexport async function editInExternalEditor(options: ExternalEditorOptions): Promise<ExternalEditorResult> {\n\tconst directory = mkdtempSync(join(tmpdir(), \"pi-editor-\"));\n\tconst filePath = join(directory, \"prompt.md\");\n\ttry {\n\t\twriteFileSync(filePath, options.content, \"utf-8\");\n\t\tconst [editor, ...editorArgs] = options.command.split(\" \");\n\t\tprocess.stdout.write(`Launching external editor: ${options.command}\\nPi will resume when the editor exits.\\n`);\n\n\t\t// Do not use spawnSync here. On Windows, synchronous child_process calls can keep\n\t\t// Node/libuv's console input read active after the parent pauses stdin, racing\n\t\t// vim/nvim for the console input buffer until Ctrl+C cancels the pending read.\n\t\t// Keep launch failures distinct from editor failures. Under process pressure,\n\t\t// `error` can report EAGAIN before the editor starts; folding that into a\n\t\t// nonzero exit makes callers and tests assume editor side effects occurred.\n\t\tconst outcome = await new Promise<{ launched: false } | { launched: true; code: number | null }>((resolve) => {\n\t\t\tconst child = spawn(editor, [...editorArgs, filePath], {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: process.platform === \"win32\",\n\t\t\t});\n\t\t\tchild.on(\"error\", () => resolve({ launched: false }));\n\t\t\tchild.on(\"close\", (code) => resolve({ launched: true, code }));\n\t\t});\n\n\t\tif (!outcome.launched) {\n\t\t\treturn { status: \"launch-failed\" };\n\t\t}\n\t\tif (outcome.code !== 0) {\n\t\t\treturn { status: \"failed\" };\n\t\t}\n\n\t\treturn { status: \"complete\", content: stripBom(readFileSync(filePath, \"utf-8\")).replace(/\\n$/, \"\") };\n\t} finally {\n\t\ttry {\n\t\t\trmSync(directory, { recursive: true, force: true });\n\t\t} catch {\n\t\t\t// Cleanup is best effort.\n\t\t}\n\t}\n}\n\nexport type EditFileResult = { status: \"complete\" } | { status: \"exited\"; code: number } | { status: \"launch-failed\" };\n\nexport async function editFileInExternalEditor(options: { command: string; path: string }): Promise<EditFileResult> {\n\tconst [editor, ...editorArgs] = options.command.split(\" \");\n\t// `close` reports code === null both for a signaled process and (historically)\n\t// around spawn errors, so the `error` event is the ONLY reliable spawn-failure\n\t// signal. Anything else means the editor actually launched.\n\tconst outcome = await new Promise<{ launched: false } | { launched: true; code: number | null }>((resolve) => {\n\t\tconst child = spawn(editor, [...editorArgs, options.path], {\n\t\t\tstdio: \"inherit\",\n\t\t\tshell: process.platform === \"win32\",\n\t\t});\n\t\tchild.on(\"error\", () => resolve({ launched: false }));\n\t\tchild.on(\"close\", (code) => resolve({ launched: true, code }));\n\t});\n\n\t// The editor never ran, so a freshly seeded file carries no user content and is\n\t// safe to remove. Once it launched -- nonzero exit or killed by a signal -- it\n\t// may have written the file, so the caller must keep whatever is on disk.\n\tif (!outcome.launched) return { status: \"launch-failed\" };\n\tif (outcome.code === 0) return { status: \"complete\" };\n\treturn { status: \"exited\", code: outcome.code ?? -1 };\n}\n"]}
|
|
@@ -49,6 +49,11 @@ export interface InteractiveModeOptions {
|
|
|
49
49
|
uiMode?: TuiMode;
|
|
50
50
|
/** Providers that were migrated to auth.json (shows warning) */
|
|
51
51
|
migratedProviders?: string[];
|
|
52
|
+
/** Runtime diagnostics collected during session creation. */
|
|
53
|
+
startupDiagnostics?: Array<{
|
|
54
|
+
type: "info" | "warning" | "error";
|
|
55
|
+
message: string;
|
|
56
|
+
}>;
|
|
52
57
|
/** Warning message if session model couldn't be restored */
|
|
53
58
|
modelFallbackMessage?: string;
|
|
54
59
|
/** Cwd to trust after reload if it gained a .pi directory during this implicitly trusted session. */
|
|
@@ -237,6 +242,7 @@ export declare class InteractiveMode {
|
|
|
237
242
|
run(): Promise<void>;
|
|
238
243
|
private checkForPackageUpdates;
|
|
239
244
|
private checkTmuxSetup;
|
|
245
|
+
private checkTmuxKeyboardSetup;
|
|
240
246
|
/**
|
|
241
247
|
* Get changelog entries to display on startup.
|
|
242
248
|
* Only shows new entries since last seen version, skips for resumed sessions.
|