@code-yeongyu/senpi 2026.9.2 → 2026.9.3-3
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 +188 -2
- package/dist/beta/omo-local-update-fingerprint.d.ts.map +1 -1
- package/dist/beta/omo-local-update-fingerprint.js +0 -1
- package/dist/beta/omo-local-update-fingerprint.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +39 -33
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/build.js +2 -5
- package/dist/core/dynamic-prompt/build.js.map +1 -1
- package/dist/core/dynamic-prompt/index.d.ts +1 -2
- package/dist/core/dynamic-prompt/index.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/index.js +1 -2
- package/dist/core/dynamic-prompt/index.js.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.js +9 -24
- package/dist/core/dynamic-prompt/intent-gate.js.map +1 -1
- package/dist/core/dynamic-prompt/policies.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/policies.js +3 -7
- package/dist/core/dynamic-prompt/policies.js.map +1 -1
- package/dist/core/dynamic-prompt/style.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/style.js +6 -8
- package/dist/core/dynamic-prompt/style.js.map +1 -1
- package/dist/core/dynamic-prompt/verification.js +1 -1
- package/dist/core/dynamic-prompt/verification.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.d.ts +2 -0
- package/dist/core/dynamic-prompt/working-task.d.ts.map +1 -0
- package/dist/core/dynamic-prompt/working-task.js +10 -0
- package/dist/core/dynamic-prompt/working-task.js.map +1 -0
- package/dist/core/extensions/builtin/bash-timeout/index.d.ts +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js +7 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts +11 -7
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.js +4 -8
- package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js +15 -18
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts +3 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js +80 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts +18 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js +57 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js +13 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js +6 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js +2 -23
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts +2 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +30 -24
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +2 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js +15 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js +19 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +31 -13
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js +8 -14
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js +23 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js +4 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +15 -7
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +11 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +12 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js +27 -9
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
- package/dist/core/extensions/builtin/eval-only-routing.d.ts +10 -0
- package/dist/core/extensions/builtin/eval-only-routing.d.ts.map +1 -0
- package/dist/core/extensions/builtin/eval-only-routing.js +16 -0
- package/dist/core/extensions/builtin/eval-only-routing.js.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts +3 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.js +115 -0
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -0
- package/dist/core/extensions/builtin/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/index.js +2 -0
- package/dist/core/extensions/builtin/index.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +52 -50
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +8 -4
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +2 -6
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +9 -3
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +10 -4
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +57 -43
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +39 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +57 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts +4 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js +16 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +61 -76
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +8 -2
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +13 -5
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts +4 -3
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +18 -18
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +7 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +37 -8
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +31 -16
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js +14 -2
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +27 -10
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +17 -8
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -6
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -9
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/index.d.ts +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +9 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts +2 -0
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +71 -12
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/custom-capability.d.ts +5 -0
- package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
- package/dist/modes/rpc/custom-capability.js +5 -0
- package/dist/modes/rpc/custom-capability.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +6 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
- package/dist/modes/rpc/host-ensure.js +36 -9
- package/dist/modes/rpc/host-ensure.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +16 -4
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/login-prompts.d.ts +24 -0
- package/dist/modes/rpc/login-prompts.d.ts.map +1 -0
- package/dist/modes/rpc/login-prompts.js +44 -0
- package/dist/modes/rpc/login-prompts.js.map +1 -0
- package/dist/modes/rpc/media-placeholders.d.ts +49 -0
- package/dist/modes/rpc/media-placeholders.d.ts.map +1 -0
- package/dist/modes/rpc/media-placeholders.js +151 -0
- package/dist/modes/rpc/media-placeholders.js.map +1 -0
- package/dist/modes/rpc/multi-session-host.d.ts +7 -4
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +10 -4
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +16 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +73 -7
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +23 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +1 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +22 -0
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +134 -95
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-fanout.d.ts +51 -0
- package/dist/modes/rpc/session-event-fanout.d.ts.map +1 -0
- package/dist/modes/rpc/session-event-fanout.js +170 -0
- package/dist/modes/rpc/session-event-fanout.js.map +1 -0
- package/dist/modes/rpc/session-event-writer.d.ts +9 -14
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +68 -106
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +9 -8
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +14 -42
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-teardown.d.ts +12 -0
- package/dist/modes/rpc/session-teardown.d.ts.map +1 -0
- package/dist/modes/rpc/session-teardown.js +117 -0
- package/dist/modes/rpc/session-teardown.js.map +1 -0
- package/dist/modes/rpc/socket-event-fanout.d.ts +8 -1
- package/dist/modes/rpc/socket-event-fanout.d.ts.map +1 -1
- package/dist/modes/rpc/socket-event-fanout.js +32 -9
- package/dist/modes/rpc/socket-event-fanout.js.map +1 -1
- package/docs/rpc.md +114 -6
- package/docs/settings.md +8 -30
- package/docs/terminal-tools.md +26 -6
- package/docs/windows.md +1 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.d.ts +18 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +155 -106
- package/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +144 -83
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +21 -32
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +25 -36
- package/node_modules/@anthropic-ai/claude-agent-sdk/package.json +2 -2
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk-tools.d.ts +93 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts +473 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +140 -93
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +83 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +4 -2
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/skill-contribution.ts +43 -9
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +21 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +6 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.d.ts +10 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.js +126 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +24 -7
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/SKILL.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/references/runtime-apis.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +5 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +3 -0
- 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 +2 -2
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +26 -4
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +16 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +40 -6
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.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/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.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/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.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/utils/retry-profile/profiles.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +16 -16
- package/dist/core/dynamic-prompt/exploration.d.ts +0 -2
- package/dist/core/dynamic-prompt/exploration.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/exploration.js +0 -6
- package/dist/core/dynamic-prompt/exploration.js.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.d.ts +0 -2
- package/dist/core/dynamic-prompt/parallel-tools.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.js +0 -8
- package/dist/core/dynamic-prompt/parallel-tools.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-registry.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAChG,OAAO,EAEN,mBAAmB,EAEnB,yBAAyB,GACzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAgC/D,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IASjD,YAAY,IAAqC,EAAE,MAAe;QACjE,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAmBD,SAAS,aAAa,CAAC,IAAY;IAClC,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,YAAY,CAAC,YAA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gC;QACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YACzG,MAAM,IAAI,uBAAuB,CAAC,cAAc,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;IAEO,mBAAmB;QAC1B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM;gBAAE,KAAK,IAAI,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { basename, dirname, isAbsolute, resolve } from \"node:path\";\nimport { ProviderScope, runWithProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport {\n\ttype AgentSessionLaunchProfile,\n\tAgentSessionRuntime,\n\ttype CreateAgentSessionRuntimeFactory,\n\tcreateAgentSessionRuntime,\n} from \"../../core/agent-session-runtime.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\n\n/** The immutable flags selected when a routing session is opened. */\nexport interface RpcSessionLaunchProfile extends AgentSessionLaunchProfile {\n\tsessionPath?: string;\n}\n\nexport type SessionRuntime = AgentSessionRuntime;\nexport type RpcSessionState = \"opening\" | \"open\" | \"closing\" | \"closed\";\n\nexport interface RpcSessionEntry {\n\tstate: RpcSessionState;\n\truntime?: SessionRuntime;\n\t/** Resolves replacement against the runtime currently owned by this entry. */\n\tswitchSession?: SessionRuntime[\"switchSession\"];\n\t/** Rebind callback installed by the shared RPC connection handler. */\n\trebindSession?: Parameters<SessionRuntime[\"setRebindSession\"]>[0];\n\tscope: ProviderScope;\n\tprofile: Readonly<RpcSessionLaunchProfile>;\n\tdurableSessionId?: string;\n\tsessionPath?: string;\n\t/** Canonical reservation key for path-opened sessions; matches the reservations set. */\n\treservationKey?: string;\n\t/** Current runtime cwd, which can change when a session is replaced. */\n\tcwd: string;\n\t/** Live attachments (open + later attaches). The runtime is disposed only when the last one closes. */\n\tattachments: number;\n\t/** Timestamp of the last routed command / observed activity; drives idle eviction. */\n\tlastCommandAt: number;\n\tlifecycleMutex: Promise<void>;\n}\n\nexport class RpcSessionRegistryError extends Error {\n\treadonly code:\n\t\t| \"unknown_session\"\n\t\t| \"session_closing\"\n\t\t| \"session_path_in_use\"\n\t\t| \"invalid_path\"\n\t\t| \"open_failed\"\n\t\t| \"too_many_sessions\";\n\n\tconstructor(code: RpcSessionRegistryError[\"code\"], reason?: string) {\n\t\tsuper(code === \"open_failed\" && reason ? `${code}: ${reason}` : code);\n\t\tthis.code = code;\n\t\tthis.name = \"RpcSessionRegistryError\";\n\t}\n}\n\nexport interface RpcSessionRegistryOptions {\n\tagentDir: string;\n\tcreateRuntime: CreateAgentSessionRuntimeFactory;\n\t/** Injectable clock (defaults to Date.now) so idle bookkeeping is testable. */\n\tnow?: () => number;\n\t/** Cap on concurrently opening/open sessions; attach-on-open is exempt. */\n\tmaxSessions?: number;\n}\n\nexport interface OpenRpcSession {\n\tsessionId: string;\n\tdurableSessionId: string;\n\tsessionPath?: string;\n\t/** True when this open attached to an already-open session instead of creating one. */\n\tattached?: boolean;\n}\n\nfunction canonicalPath(path: string): string {\n\tconst absolutePath = resolve(path);\n\tif (existsSync(absolutePath)) return realpathSync(absolutePath);\n\treturn `${realpathSync(dirname(absolutePath))}/${basename(absolutePath)}`;\n}\n\nfunction frozenProfile(profile: RpcSessionLaunchProfile): Readonly<RpcSessionLaunchProfile> {\n\treturn Object.freeze({\n\t\t...profile,\n\t\t...(profile.creationModel ? { creationModel: Object.freeze({ ...profile.creationModel }) } : {}),\n\t});\n}\n\n/** Process-local lifecycle owner for multi-session RPC runtimes. */\nexport class RpcSessionRegistry {\n\tprivate readonly entries = new Map<string, RpcSessionEntry>();\n\tprivate readonly reservations = new Set<string>();\n\tprivate nextHandle = 0;\n\tprivate readonly options: RpcSessionRegistryOptions;\n\tprivate readonly now: () => number;\n\n\tconstructor(options: RpcSessionRegistryOptions) {\n\t\tthis.options = options;\n\t\tthis.now = options.now ?? Date.now;\n\t}\n\n\t/** Number of live entries, including ones still opening or closing. */\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\tasync openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession> {\n\t\tthis.validateProfile(profile);\n\t\tthis.syncRuntimeMetadata();\n\t\tconst sessionPath = profile.sessionPath ? canonicalPath(profile.sessionPath) : undefined;\n\t\tif (sessionPath && this.reservations.has(sessionPath)) {\n\t\t\t// Attach-on-open: a live session outlives individual client attachments, so a\n\t\t\t// resume (or a second surface) for an already-hosted path joins the existing\n\t\t\t// runtime instead of failing. Entries still opening or closing keep the\n\t\t\t// exclusive reservation and reject as before.\n\t\t\tconst existing = [...this.entries].find(\n\t\t\t\t([, entry]) => entry.reservationKey === sessionPath && entry.state === \"open\",\n\t\t\t);\n\t\t\tif (!existing) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tconst [handle, entry] = existing;\n\t\t\tentry.attachments += 1;\n\t\t\tif (!entry.durableSessionId) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tentry.lastCommandAt = this.now();\n\t\t\treturn {\n\t\t\t\tsessionId: handle,\n\t\t\t\tdurableSessionId: entry.durableSessionId,\n\t\t\t\tsessionPath: entry.sessionPath,\n\t\t\t\tattached: true,\n\t\t\t};\n\t\t}\n\t\tconst maxSessions = this.options.maxSessions;\n\t\tif (maxSessions !== undefined && this.countActiveSessions() >= maxSessions) {\n\t\t\t// Reconnect-churn backstop: every open_session owns a complete runtime\n\t\t\t// (hundreds of MB measured), so admission is bounded. Attachments to a\n\t\t\t// live session add none and stay allowed via the branch above.\n\t\t\tthrow new RpcSessionRegistryError(\"too_many_sessions\");\n\t\t}\n\t\tif (sessionPath) this.reservations.add(sessionPath);\n\n\t\t// Resume vs create parity (D1 + omo SenpiSessionRuntime.ts:198-200):\n\t\t// Create-only launch semantics mirror classic startup flags. A resumed\n\t\t// session restores its persisted model and thinking level instead of being\n\t\t// overridden by the new open_session request.\n\t\tconst isResume = sessionPath !== undefined && existsSync(sessionPath);\n\t\tconst storedProfile = frozenProfile({ ...profile, ...(sessionPath ? { sessionPath } : {}) });\n\t\tconst runtimeProfile = isResume\n\t\t\t? frozenProfile({ ...storedProfile, creationModel: undefined, initialThinkingLevel: undefined })\n\t\t\t: storedProfile;\n\n\t\tconst handle = `rpc-${++this.nextHandle}`;\n\t\tconst entry: RpcSessionEntry = {\n\t\t\tstate: \"opening\",\n\t\t\tscope: new ProviderScope(),\n\t\t\tprofile: storedProfile,\n\t\t\tsessionPath,\n\t\t\treservationKey: sessionPath,\n\t\t\tcwd: storedProfile.cwd,\n\t\t\tattachments: 1,\n\t\t\tlastCommandAt: this.now(),\n\t\t\tlifecycleMutex: Promise.resolve(),\n\t\t};\n\t\tentry.switchSession = (sessionPath, options) => {\n\t\t\tconst operation = entry.lifecycleMutex.then(async () => {\n\t\t\t\tif (entry.state !== \"open\" || !entry.runtime) {\n\t\t\t\t\tthrow new RpcSessionRegistryError(\"unknown_session\");\n\t\t\t\t}\n\t\t\t\tconst runtime = entry.runtime;\n\t\t\t\tconst cwdOverride = options?.cwdOverride;\n\t\t\t\tconst cwdChanged = cwdOverride !== undefined && runtime.session.sessionManager.getCwd() !== cwdOverride;\n\t\t\t\tconst result = await runtime.switchSession(sessionPath, options);\n\t\t\t\tif (result.cancelled || !cwdChanged) return result;\n\n\t\t\t\t// A multi-session binding outlives an individual replacement. Keep the\n\t\t\t\t// entry's runtime object aligned with the replacement so every attached\n\t\t\t\t// client resolves getters and future commands against the new cwd-bound\n\t\t\t\t// runtime, not the object created during open_session.\n\t\t\t\tconst replacement = new AgentSessionRuntime(\n\t\t\t\t\truntime.session,\n\t\t\t\t\truntime.services,\n\t\t\t\t\tthis.options.createRuntime,\n\t\t\t\t\t[...runtime.diagnostics],\n\t\t\t\t\truntime.modelFallbackMessage,\n\t\t\t\t\truntime.launchProfile,\n\t\t\t\t);\n\t\t\t\treplacement.setRebindSession(entry.rebindSession);\n\t\t\t\tentry.runtime = replacement;\n\t\t\t\tthis.syncRuntimeMetadata();\n\t\t\t\treturn result;\n\t\t\t});\n\t\t\tentry.lifecycleMutex = operation.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn operation;\n\t\t};\n\t\tthis.entries.set(handle, entry);\n\t\ttry {\n\t\t\tconst manager = sessionPath\n\t\t\t\t? SessionManager.open(sessionPath, undefined, storedProfile.cwd)\n\t\t\t\t: SessionManager.create(storedProfile.cwd);\n\t\t\tentry.runtime = await runWithProviderScope(entry.scope, () =>\n\t\t\t\tcreateAgentSessionRuntime(this.options.createRuntime, {\n\t\t\t\t\tcwd: manager.getCwd(),\n\t\t\t\t\tagentDir: this.options.agentDir,\n\t\t\t\t\tsessionManager: manager,\n\t\t\t\t\tlaunchProfile: runtimeProfile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tentry.durableSessionId = manager.getSessionId();\n\t\t\tentry.sessionPath ??= manager.getSessionFile();\n\t\t\tentry.state = \"open\";\n\t\t\treturn { sessionId: handle, durableSessionId: entry.durableSessionId, sessionPath: entry.sessionPath };\n\t\t} catch (error) {\n\t\t\t// Runtime construction may have started extensions, watchers, and provider\n\t\t\t// registrations before it rejects. Keep the reservation and entry private\n\t\t\t// until all of those resources have been torn down, then release them as\n\t\t\t// one rollback so the path can immediately be opened again.\n\t\t\ttry {\n\t\t\t\tawait entry.runtime?.dispose();\n\t\t\t} catch {\n\t\t\t\t// The original construction error remains the externally visible cause.\n\t\t\t} finally {\n\t\t\t\ttry {\n\t\t\t\t\tawait entry.scope.close?.();\n\t\t\t\t} finally {\n\t\t\t\t\tthis.entries.delete(handle);\n\t\t\t\t\tif (sessionPath) this.reservations.delete(sessionPath);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (error instanceof RpcSessionRegistryError) throw error;\n\t\t\tthrow new RpcSessionRegistryError(\"open_failed\", error instanceof Error ? error.message : undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Read-only lookup with no state transitions or attachment accounting.\n\t * Exists so lifecycle decisions (e.g. deferring a dropped connection's\n\t * release while a turn is still streaming) can inspect the live entry\n\t * without claiming it.\n\t */\n\tpeek(handle: string): RpcSessionEntry | undefined {\n\t\treturn this.entries.get(handle);\n\t}\n\n\tgetForCommand(handle: string, command: string): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.state === \"closing\" && ![\"abort\", \"abort_bash\", \"extension_ui_response\"].includes(command)) {\n\t\t\tthrow new RpcSessionRegistryError(\"session_closing\");\n\t\t}\n\t\tif (entry.state !== \"open\" && entry.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\t// Every routed command counts as activity for idle eviction. Lookups that\n\t\t// must not refresh idleness (sweeps, listing) use peek()/list() instead.\n\t\tentry.lastCommandAt = this.now();\n\t\treturn entry;\n\t}\n\n\t/**\n\t * Starts a close synchronously. Call this before disposing any session-owned\n\t * binding so a concurrent command cannot reach a half-disposed handler.\n\t * Each call releases one attachment; the entry transitions to \"closing\" only\n\t * when the last attachment closes, so callers must check the returned state\n\t * and skip finalization while other attachments remain.\n\t */\n\tbeginClose(handle: string): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"open\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.attachments -= 1;\n\t\tif (entry.attachments > 0) return entry;\n\t\tentry.state = \"closing\";\n\t\treturn entry;\n\t}\n\n\tasync close(handle: string): Promise<void> {\n\t\tconst entry = this.beginClose(handle);\n\t\t// Other attachments may still own the live session; only the last close finalizes.\n\t\tif (entry.state !== \"closing\") return;\n\t\treturn this.closeMarked(handle);\n\t}\n\n\t/** Completes a close previously made visible by beginClose(). */\n\tasync closeMarked(handle: string): Promise<void> {\n\t\tthis.syncRuntimeMetadata();\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tconst previousLifecycle = entry.lifecycleMutex;\n\t\tentry.lifecycleMutex = (async () => {\n\t\t\tawait previousLifecycle;\n\t\t\ttry {\n\t\t\t\tawait entry.runtime?.session.abort();\n\t\t\t\tawait entry.runtime?.session.waitForIdle();\n\t\t\t\tawait entry.runtime?.dispose();\n\t\t\t\tawait entry.scope.close?.();\n\t\t\t} finally {\n\t\t\t\tentry.state = \"closed\";\n\t\t\t\tthis.entries.delete(handle);\n\t\t\t\tif (entry.reservationKey) this.reservations.delete(entry.reservationKey);\n\t\t\t}\n\t\t})();\n\t\treturn entry.lifecycleMutex;\n\t}\n\n\tlist(): Array<{\n\t\tsessionId: string;\n\t\tdurableSessionId?: string;\n\t\tsessionPath?: string;\n\t\tcwd: string;\n\t\tname?: string;\n\t\tstatus: RpcSessionState;\n\t}> {\n\t\tthis.syncRuntimeMetadata();\n\t\treturn [...this.entries].map(([sessionId, entry]) => ({\n\t\t\tsessionId,\n\t\t\tdurableSessionId: entry.durableSessionId,\n\t\t\tsessionPath: entry.sessionPath,\n\t\t\tcwd: entry.cwd,\n\t\t\tname: entry.runtime?.session.sessionManager.getSessionName(),\n\t\t\tstatus: entry.state,\n\t\t}));\n\t}\n\n\t/** Reconcile path and durable identity after runtime replacement. */\n\tprivate syncRuntimeMetadata(): void {\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tconst manager = entry.runtime?.session.sessionManager;\n\t\t\tif (!manager) continue;\n\t\t\tconst currentPath = manager.getSessionFile();\n\t\t\t// Preserve the originally canonicalized key while the runtime still points at\n\t\t\t// the same path. SessionManager may expose a symlink-resolved spelling after\n\t\t\t// opening a file that did not exist yet; treating that as replacement would\n\t\t\t// break ordinary attach-on-open aliases.\n\t\t\tif (currentPath !== entry.sessionPath) {\n\t\t\t\tconst currentKey = currentPath ? canonicalPath(currentPath) : undefined;\n\t\t\t\tif (entry.reservationKey) this.reservations.delete(entry.reservationKey);\n\t\t\t\tif (currentKey) this.reservations.add(currentKey);\n\t\t\t\tentry.reservationKey = currentKey;\n\t\t\t\tentry.sessionPath = currentPath;\n\t\t\t}\n\t\t\tentry.durableSessionId = manager.getSessionId();\n\t\t\tentry.cwd = manager.getCwd();\n\t\t}\n\t}\n\n\tprivate validateProfile(profile: RpcSessionLaunchProfile): void {\n\t\tif (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath))) {\n\t\t\tthrow new RpcSessionRegistryError(\"invalid_path\");\n\t\t}\n\t}\n\n\tprivate countActiveSessions(): number {\n\t\tlet count = 0;\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (entry.state === \"opening\" || entry.state === \"open\") count += 1;\n\t\t}\n\t\treturn count;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-registry.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAChG,OAAO,EAEN,mBAAmB,EAEnB,yBAAyB,GACzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,EAA4B,MAAM,uBAAuB,CAAC;AAmCtH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IASjD,YAAY,IAAqC,EAAE,MAAe;QACjE,KAAK,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C;YAC3C,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM;gBAAE,KAAK,IAAI,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["import { existsSync, realpathSync } from \"node:fs\";\nimport { basename, dirname, isAbsolute, resolve } from \"node:path\";\nimport { ProviderScope, runWithProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport {\n\ttype AgentSessionLaunchProfile,\n\tAgentSessionRuntime,\n\ttype CreateAgentSessionRuntimeFactory,\n\tcreateAgentSessionRuntime,\n} from \"../../core/agent-session-runtime.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { beginSessionClose, closeMarkedSession, closeSession, type SessionTeardownHost } from \"./session-teardown.ts\";\n\n/** The immutable flags selected when a routing session is opened. */\nexport interface RpcSessionLaunchProfile extends AgentSessionLaunchProfile {\n\tsessionPath?: string;\n}\n\nexport type SessionRuntime = AgentSessionRuntime;\nexport type RpcSessionState = \"opening\" | \"open\" | \"closing\" | \"closed\";\n\nexport interface RpcSessionEntry {\n\tstate: RpcSessionState;\n\truntime?: SessionRuntime;\n\t/** Resolves replacement against the runtime currently owned by this entry. */\n\tswitchSession?: SessionRuntime[\"switchSession\"];\n\t/** Rebind callback installed by the shared RPC connection handler. */\n\trebindSession?: Parameters<SessionRuntime[\"setRebindSession\"]>[0];\n\tscope: ProviderScope;\n\tprofile: Readonly<RpcSessionLaunchProfile>;\n\tdurableSessionId?: string;\n\tsessionPath?: string;\n\t/** Canonical reservation key for path-opened sessions; matches the reservations set. */\n\treservationKey?: string;\n\t/** Current runtime cwd, which can change when a session is replaced. */\n\tcwd: string;\n\t/** Live attachments (open + later attaches). The runtime is disposed only when the last one closes. */\n\tattachments: number;\n\t/** Timestamp of the last routed command / observed activity; drives idle eviction. */\n\tlastCommandAt: number;\n\tlifecycleMutex: Promise<void>;\n\tcloseCompletion?: Promise<void>;\n\tcloseResolve?: () => void;\n\tcloseStarted?: boolean;\n}\n\nexport class RpcSessionRegistryError extends Error {\n\treadonly code:\n\t\t| \"unknown_session\"\n\t\t| \"session_closing\"\n\t\t| \"session_path_in_use\"\n\t\t| \"invalid_path\"\n\t\t| \"open_failed\"\n\t\t| \"too_many_sessions\";\n\n\tconstructor(code: RpcSessionRegistryError[\"code\"], reason?: string) {\n\t\tsuper(code === \"open_failed\" && reason ? `${code}: ${reason}` : code);\n\t\tthis.code = code;\n\t\tthis.name = \"RpcSessionRegistryError\";\n\t}\n}\n\nexport interface RpcSessionRegistryOptions {\n\tagentDir: string;\n\tcreateRuntime: CreateAgentSessionRuntimeFactory;\n\t/** Injectable clock (defaults to Date.now) so idle bookkeeping is testable. */\n\tnow?: () => number;\n\t/** Cap on concurrently opening/open sessions; attach-on-open is exempt. */\n\tmaxSessions?: number;\n\t/** Maximum time to wait for graceful runtime teardown before forced release. */\n\tcloseGraceMs?: number;\n}\n\nexport interface OpenRpcSession {\n\tsessionId: string;\n\tdurableSessionId: string;\n\tsessionPath?: string;\n\t/** True when this open attached to an already-open session instead of creating one. */\n\tattached?: boolean;\n}\n\nfunction canonicalPath(path: string): string {\n\tconst absolutePath = resolve(path);\n\tif (existsSync(absolutePath)) return realpathSync(absolutePath);\n\treturn `${realpathSync(dirname(absolutePath))}/${basename(absolutePath)}`;\n}\n\nfunction frozenProfile(profile: RpcSessionLaunchProfile): Readonly<RpcSessionLaunchProfile> {\n\treturn Object.freeze({\n\t\t...profile,\n\t\t...(profile.creationModel ? { creationModel: Object.freeze({ ...profile.creationModel }) } : {}),\n\t});\n}\n\n/** Process-local lifecycle owner for multi-session RPC runtimes. */\nexport class RpcSessionRegistry {\n\tprivate readonly entries = new Map<string, RpcSessionEntry>();\n\tprivate readonly reservations = new Set<string>();\n\tprivate readonly teardownHost: SessionTeardownHost;\n\tprivate nextHandle = 0;\n\tprivate readonly options: RpcSessionRegistryOptions;\n\tprivate readonly now: () => number;\n\treadonly closeGraceMs: number;\n\n\tconstructor(options: RpcSessionRegistryOptions) {\n\t\tthis.options = options;\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.closeGraceMs = options.closeGraceMs ?? 10_000;\n\t\tthis.teardownHost = {\n\t\t\tcloseGraceMs: this.closeGraceMs,\n\t\t\tget: (handle) => this.entries.get(handle),\n\t\t\tdelete: (handle) => this.entries.delete(handle),\n\t\t\treleaseReservation: (key) => this.reservations.delete(key),\n\t\t\tsync: () => this.syncRuntimeMetadata(),\n\t\t};\n\t}\n\n\t/** Number of live entries, including ones still opening or closing. */\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\tasync openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession> {\n\t\tthis.validateProfile(profile);\n\t\tthis.syncRuntimeMetadata();\n\t\tconst sessionPath = profile.sessionPath ? canonicalPath(profile.sessionPath) : undefined;\n\t\tif (sessionPath && this.reservations.has(sessionPath)) {\n\t\t\t// Attach-on-open: a live session outlives individual client attachments, so a\n\t\t\t// resume (or a second surface) for an already-hosted path joins the existing\n\t\t\t// runtime instead of failing. Entries still opening or closing keep the\n\t\t\t// exclusive reservation and reject as before.\n\t\t\tconst existing = [...this.entries].find(\n\t\t\t\t([, entry]) => entry.reservationKey === sessionPath && entry.state === \"open\",\n\t\t\t);\n\t\t\tif (!existing) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tconst [handle, entry] = existing;\n\t\t\tentry.attachments += 1;\n\t\t\tif (!entry.durableSessionId) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tentry.lastCommandAt = this.now();\n\t\t\treturn {\n\t\t\t\tsessionId: handle,\n\t\t\t\tdurableSessionId: entry.durableSessionId,\n\t\t\t\tsessionPath: entry.sessionPath,\n\t\t\t\tattached: true,\n\t\t\t};\n\t\t}\n\t\tconst maxSessions = this.options.maxSessions;\n\t\tif (maxSessions !== undefined && this.countActiveSessions() >= maxSessions) {\n\t\t\t// Reconnect-churn backstop: every open_session owns a complete runtime\n\t\t\t// (hundreds of MB measured), so admission is bounded. Attachments to a\n\t\t\t// live session add none and stay allowed via the branch above.\n\t\t\tthrow new RpcSessionRegistryError(\"too_many_sessions\");\n\t\t}\n\t\tif (sessionPath) this.reservations.add(sessionPath);\n\n\t\t// Resume vs create parity (D1 + omo SenpiSessionRuntime.ts:198-200):\n\t\t// Create-only launch semantics mirror classic startup flags. A resumed\n\t\t// session restores its persisted model and thinking level instead of being\n\t\t// overridden by the new open_session request.\n\t\tconst isResume = sessionPath !== undefined && existsSync(sessionPath);\n\t\tconst storedProfile = frozenProfile({ ...profile, ...(sessionPath ? { sessionPath } : {}) });\n\t\tconst runtimeProfile = isResume\n\t\t\t? frozenProfile({ ...storedProfile, creationModel: undefined, initialThinkingLevel: undefined })\n\t\t\t: storedProfile;\n\n\t\tconst handle = `rpc-${++this.nextHandle}`;\n\t\tconst entry: RpcSessionEntry = {\n\t\t\tstate: \"opening\",\n\t\t\tscope: new ProviderScope(),\n\t\t\tprofile: storedProfile,\n\t\t\tsessionPath,\n\t\t\treservationKey: sessionPath,\n\t\t\tcwd: storedProfile.cwd,\n\t\t\tattachments: 1,\n\t\t\tlastCommandAt: this.now(),\n\t\t\tlifecycleMutex: Promise.resolve(),\n\t\t};\n\t\tentry.switchSession = (sessionPath, options) => {\n\t\t\tconst operation = entry.lifecycleMutex.then(async () => {\n\t\t\t\tif (entry.state !== \"open\" || !entry.runtime) {\n\t\t\t\t\tthrow new RpcSessionRegistryError(\"unknown_session\");\n\t\t\t\t}\n\t\t\t\tconst runtime = entry.runtime;\n\t\t\t\tconst cwdOverride = options?.cwdOverride;\n\t\t\t\tconst cwdChanged = cwdOverride !== undefined && runtime.session.sessionManager.getCwd() !== cwdOverride;\n\t\t\t\tconst result = await runtime.switchSession(sessionPath, options);\n\t\t\t\tif (result.cancelled || !cwdChanged) return result;\n\n\t\t\t\t// A multi-session binding outlives an individual replacement. Keep the\n\t\t\t\t// entry's runtime object aligned with the replacement so every attached\n\t\t\t\t// client resolves getters and future commands against the new cwd-bound\n\t\t\t\t// runtime, not the object created during open_session.\n\t\t\t\tconst replacement = new AgentSessionRuntime(\n\t\t\t\t\truntime.session,\n\t\t\t\t\truntime.services,\n\t\t\t\t\tthis.options.createRuntime,\n\t\t\t\t\t[...runtime.diagnostics],\n\t\t\t\t\truntime.modelFallbackMessage,\n\t\t\t\t\truntime.launchProfile,\n\t\t\t\t);\n\t\t\t\treplacement.setRebindSession(entry.rebindSession);\n\t\t\t\tentry.runtime = replacement;\n\t\t\t\tthis.syncRuntimeMetadata();\n\t\t\t\treturn result;\n\t\t\t});\n\t\t\tentry.lifecycleMutex = operation.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn operation;\n\t\t};\n\t\tthis.entries.set(handle, entry);\n\t\ttry {\n\t\t\tconst manager = sessionPath\n\t\t\t\t? SessionManager.open(sessionPath, undefined, storedProfile.cwd)\n\t\t\t\t: SessionManager.create(storedProfile.cwd);\n\t\t\tentry.runtime = await runWithProviderScope(entry.scope, () =>\n\t\t\t\tcreateAgentSessionRuntime(this.options.createRuntime, {\n\t\t\t\t\tcwd: manager.getCwd(),\n\t\t\t\t\tagentDir: this.options.agentDir,\n\t\t\t\t\tsessionManager: manager,\n\t\t\t\t\tlaunchProfile: runtimeProfile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tentry.durableSessionId = manager.getSessionId();\n\t\t\tentry.sessionPath ??= manager.getSessionFile();\n\t\t\tentry.state = \"open\";\n\t\t\treturn { sessionId: handle, durableSessionId: entry.durableSessionId, sessionPath: entry.sessionPath };\n\t\t} catch (error) {\n\t\t\t// Runtime construction may have started extensions, watchers, and provider\n\t\t\t// registrations before it rejects. Keep the reservation and entry private\n\t\t\t// until all of those resources have been torn down, then release them as\n\t\t\t// one rollback so the path can immediately be opened again.\n\t\t\ttry {\n\t\t\t\tawait entry.runtime?.dispose();\n\t\t\t} catch {\n\t\t\t\t// The original construction error remains the externally visible cause.\n\t\t\t} finally {\n\t\t\t\ttry {\n\t\t\t\t\tawait entry.scope.close?.();\n\t\t\t\t} finally {\n\t\t\t\t\tthis.entries.delete(handle);\n\t\t\t\t\tif (sessionPath) this.reservations.delete(sessionPath);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (error instanceof RpcSessionRegistryError) throw error;\n\t\t\tthrow new RpcSessionRegistryError(\"open_failed\", error instanceof Error ? error.message : undefined);\n\t\t}\n\t}\n\n\t/**\n\t * Read-only lookup with no state transitions or attachment accounting.\n\t * Exists so lifecycle decisions (e.g. deferring a dropped connection's\n\t * release while a turn is still streaming) can inspect the live entry\n\t * without claiming it.\n\t */\n\tpeek(handle: string): RpcSessionEntry | undefined {\n\t\treturn this.entries.get(handle);\n\t}\n\n\tgetForCommand(handle: string, command: string): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.state === \"closing\" && ![\"abort\", \"abort_bash\", \"extension_ui_response\"].includes(command)) {\n\t\t\tthrow new RpcSessionRegistryError(\"session_closing\");\n\t\t}\n\t\tif (entry.state !== \"open\" && entry.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\t// Every routed command counts as activity for idle eviction. Lookups that\n\t\t// must not refresh idleness (sweeps, listing) use peek()/list() instead.\n\t\tentry.lastCommandAt = this.now();\n\t\treturn entry;\n\t}\n\n\t/** Starts a close synchronously and returns the live entry for routing decisions. */\n\tbeginClose(handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry {\n\t\treturn beginSessionClose(this.teardownHost, handle, onRole);\n\t}\n\n\tasync close(handle: string): Promise<void> {\n\t\treturn closeSession(this.teardownHost, handle);\n\t}\n\n\t/** Completes a close previously made visible by beginClose(). */\n\tasync closeMarked(handle: string): Promise<void> {\n\t\treturn closeMarkedSession(this.teardownHost, handle);\n\t}\n\n\tlist(): Array<{\n\t\tsessionId: string;\n\t\tdurableSessionId?: string;\n\t\tsessionPath?: string;\n\t\tcwd: string;\n\t\tname?: string;\n\t\tstatus: RpcSessionState;\n\t}> {\n\t\tthis.syncRuntimeMetadata();\n\t\treturn [...this.entries].map(([sessionId, entry]) => ({\n\t\t\tsessionId,\n\t\t\tdurableSessionId: entry.durableSessionId,\n\t\t\tsessionPath: entry.sessionPath,\n\t\t\tcwd: entry.cwd,\n\t\t\tname: entry.runtime?.session.sessionManager.getSessionName(),\n\t\t\tstatus: entry.state,\n\t\t}));\n\t}\n\n\t/** Reconcile path and durable identity after runtime replacement. */\n\tprivate syncRuntimeMetadata(): void {\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tconst manager = entry.runtime?.session.sessionManager;\n\t\t\tif (!manager) continue;\n\t\t\tconst currentPath = manager.getSessionFile();\n\t\t\t// Preserve the originally canonicalized key while the runtime still points at\n\t\t\t// the same path. SessionManager may expose a symlink-resolved spelling after\n\t\t\t// opening a file that did not exist yet; treating that as replacement would\n\t\t\t// break ordinary attach-on-open aliases.\n\t\t\tif (currentPath !== entry.sessionPath) {\n\t\t\t\tconst currentKey = currentPath ? canonicalPath(currentPath) : undefined;\n\t\t\t\tif (entry.reservationKey) this.reservations.delete(entry.reservationKey);\n\t\t\t\tif (currentKey) this.reservations.add(currentKey);\n\t\t\t\tentry.reservationKey = currentKey;\n\t\t\t\tentry.sessionPath = currentPath;\n\t\t\t}\n\t\t\tentry.durableSessionId = manager.getSessionId();\n\t\t\tentry.cwd = manager.getCwd();\n\t\t}\n\t}\n\n\tprivate validateProfile(profile: RpcSessionLaunchProfile): void {\n\t\tif (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath))) {\n\t\t\tthrow new RpcSessionRegistryError(\"invalid_path\");\n\t\t}\n\t}\n\n\tprivate countActiveSessions(): number {\n\t\tlet count = 0;\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (entry.state === \"opening\" || entry.state === \"open\") count += 1;\n\t\t}\n\t\treturn count;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RpcSessionEntry } from "./session-registry.ts";
|
|
2
|
+
export interface SessionTeardownHost {
|
|
3
|
+
readonly closeGraceMs: number;
|
|
4
|
+
get(handle: string): RpcSessionEntry | undefined;
|
|
5
|
+
delete(handle: string): void;
|
|
6
|
+
releaseReservation(key: string): void;
|
|
7
|
+
sync(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function beginSessionClose(host: SessionTeardownHost, handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry;
|
|
10
|
+
export declare function closeSession(host: SessionTeardownHost, handle: string): Promise<void>;
|
|
11
|
+
export declare function closeMarkedSession(host: SessionTeardownHost, handle: string): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=session-teardown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-teardown.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/session-teardown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IACjD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,IAAI,IAAI,IAAI,CAAC;CACb;AAMD,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,mBAAmB,EACzB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GACnC,eAAe,CAgBjB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0E3F"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { RpcSessionRegistryError } from "./session-registry.js";
|
|
2
|
+
function reportDetachedFailure(handle, cause) {
|
|
3
|
+
process.stderr.write(`senpi rpc session ${handle} teardown failed: ${String(cause)}\n`);
|
|
4
|
+
}
|
|
5
|
+
export function beginSessionClose(host, handle, onRole) {
|
|
6
|
+
const entry = host.get(handle);
|
|
7
|
+
if (!entry)
|
|
8
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
9
|
+
if (entry.state === "closing") {
|
|
10
|
+
onRole?.(false);
|
|
11
|
+
return entry;
|
|
12
|
+
}
|
|
13
|
+
if (entry.state !== "open")
|
|
14
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
15
|
+
entry.attachments -= 1;
|
|
16
|
+
if (entry.attachments > 0)
|
|
17
|
+
return entry;
|
|
18
|
+
entry.state = "closing";
|
|
19
|
+
onRole?.(true);
|
|
20
|
+
entry.closeCompletion = new Promise((resolve) => {
|
|
21
|
+
entry.closeResolve = resolve;
|
|
22
|
+
});
|
|
23
|
+
return entry;
|
|
24
|
+
}
|
|
25
|
+
export function closeSession(host, handle) {
|
|
26
|
+
const entry = beginSessionClose(host, handle);
|
|
27
|
+
if (entry.state !== "closing")
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
return closeMarkedSession(host, handle);
|
|
30
|
+
}
|
|
31
|
+
export function closeMarkedSession(host, handle) {
|
|
32
|
+
host.sync();
|
|
33
|
+
const entry = host.get(handle);
|
|
34
|
+
if (entry?.state !== "closing")
|
|
35
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
36
|
+
const completion = entry.closeCompletion;
|
|
37
|
+
if (!completion)
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
if (entry.closeStarted)
|
|
40
|
+
return completion;
|
|
41
|
+
entry.closeStarted = true;
|
|
42
|
+
const previousLifecycle = entry.lifecycleMutex;
|
|
43
|
+
let releaseTimer;
|
|
44
|
+
let released = false;
|
|
45
|
+
let disposePromise;
|
|
46
|
+
let scopeClosed = false;
|
|
47
|
+
const disposeOnce = () => {
|
|
48
|
+
if (disposePromise)
|
|
49
|
+
return disposePromise;
|
|
50
|
+
disposePromise = Promise.resolve(entry.runtime?.dispose());
|
|
51
|
+
return disposePromise;
|
|
52
|
+
};
|
|
53
|
+
const closeScopeOnce = async () => {
|
|
54
|
+
if (scopeClosed)
|
|
55
|
+
return;
|
|
56
|
+
scopeClosed = true;
|
|
57
|
+
await entry.scope.close?.();
|
|
58
|
+
};
|
|
59
|
+
const release = () => {
|
|
60
|
+
if (released)
|
|
61
|
+
return;
|
|
62
|
+
released = true;
|
|
63
|
+
if (releaseTimer)
|
|
64
|
+
clearTimeout(releaseTimer);
|
|
65
|
+
entry.state = "closed";
|
|
66
|
+
host.delete(handle);
|
|
67
|
+
if (entry.reservationKey)
|
|
68
|
+
host.releaseReservation(entry.reservationKey);
|
|
69
|
+
};
|
|
70
|
+
const graceful = (async () => {
|
|
71
|
+
await previousLifecycle;
|
|
72
|
+
try {
|
|
73
|
+
await entry.runtime?.session.abort();
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
reportDetachedFailure(handle, cause);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
await entry.runtime?.session.waitForIdle();
|
|
80
|
+
}
|
|
81
|
+
catch (cause) {
|
|
82
|
+
reportDetachedFailure(handle, cause);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
await disposeOnce();
|
|
86
|
+
}
|
|
87
|
+
catch (cause) {
|
|
88
|
+
reportDetachedFailure(handle, cause);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
await closeScopeOnce();
|
|
92
|
+
}
|
|
93
|
+
catch (cause) {
|
|
94
|
+
reportDetachedFailure(handle, cause);
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
let settled = false;
|
|
98
|
+
const finish = () => {
|
|
99
|
+
if (settled)
|
|
100
|
+
return;
|
|
101
|
+
settled = true;
|
|
102
|
+
release();
|
|
103
|
+
entry.closeResolve?.();
|
|
104
|
+
};
|
|
105
|
+
releaseTimer = setTimeout(() => {
|
|
106
|
+
void disposeOnce().catch((cause) => reportDetachedFailure(handle, cause));
|
|
107
|
+
void closeScopeOnce().catch((cause) => reportDetachedFailure(handle, cause));
|
|
108
|
+
void graceful.catch((cause) => reportDetachedFailure(handle, cause));
|
|
109
|
+
finish();
|
|
110
|
+
}, host.closeGraceMs);
|
|
111
|
+
void graceful.then(finish, (cause) => {
|
|
112
|
+
reportDetachedFailure(handle, cause);
|
|
113
|
+
finish();
|
|
114
|
+
});
|
|
115
|
+
return completion;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=session-teardown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-teardown.js","sourceRoot":"","sources":["../../../src/modes/rpc/session-teardown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAUhE,SAAS,qBAAqB,CAAC,MAAc,EAAE,KAAc;IAC5D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,MAAM,qBAAqB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAChC,IAAyB,EACzB,MAAc,EACd,MAAqC;IAErC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;IACjE,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,IAAI,KAAK,CAAC,KAAK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AC;QACrC,MAAM,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { RpcSessionEntry } from \"./session-registry.ts\";\nimport { RpcSessionRegistryError } from \"./session-registry.ts\";\n\nexport interface SessionTeardownHost {\n\treadonly closeGraceMs: number;\n\tget(handle: string): RpcSessionEntry | undefined;\n\tdelete(handle: string): void;\n\treleaseReservation(key: string): void;\n\tsync(): void;\n}\n\nfunction reportDetachedFailure(handle: string, cause: unknown): void {\n\tprocess.stderr.write(`senpi rpc session ${handle} teardown failed: ${String(cause)}\\n`);\n}\n\nexport function beginSessionClose(\n\thost: SessionTeardownHost,\n\thandle: string,\n\tonRole?: (finalizer: boolean) => void,\n): RpcSessionEntry {\n\tconst entry = host.get(handle);\n\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\tif (entry.state === \"closing\") {\n\t\tonRole?.(false);\n\t\treturn entry;\n\t}\n\tif (entry.state !== \"open\") throw new RpcSessionRegistryError(\"unknown_session\");\n\tentry.attachments -= 1;\n\tif (entry.attachments > 0) return entry;\n\tentry.state = \"closing\";\n\tonRole?.(true);\n\tentry.closeCompletion = new Promise<void>((resolve) => {\n\t\tentry.closeResolve = resolve;\n\t});\n\treturn entry;\n}\n\nexport function closeSession(host: SessionTeardownHost, handle: string): Promise<void> {\n\tconst entry = beginSessionClose(host, handle);\n\tif (entry.state !== \"closing\") return Promise.resolve();\n\treturn closeMarkedSession(host, handle);\n}\n\nexport function closeMarkedSession(host: SessionTeardownHost, handle: string): Promise<void> {\n\thost.sync();\n\tconst entry = host.get(handle);\n\tif (entry?.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\tconst completion = entry.closeCompletion;\n\tif (!completion) return Promise.resolve();\n\tif (entry.closeStarted) return completion;\n\tentry.closeStarted = true;\n\n\tconst previousLifecycle = entry.lifecycleMutex;\n\tlet releaseTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet released = false;\n\tlet disposePromise: Promise<void> | undefined;\n\tlet scopeClosed = false;\n\tconst disposeOnce = (): Promise<void> => {\n\t\tif (disposePromise) return disposePromise;\n\t\tdisposePromise = Promise.resolve(entry.runtime?.dispose());\n\t\treturn disposePromise;\n\t};\n\tconst closeScopeOnce = async (): Promise<void> => {\n\t\tif (scopeClosed) return;\n\t\tscopeClosed = true;\n\t\tawait entry.scope.close?.();\n\t};\n\tconst release = (): void => {\n\t\tif (released) return;\n\t\treleased = true;\n\t\tif (releaseTimer) clearTimeout(releaseTimer);\n\t\tentry.state = \"closed\";\n\t\thost.delete(handle);\n\t\tif (entry.reservationKey) host.releaseReservation(entry.reservationKey);\n\t};\n\tconst graceful = (async (): Promise<void> => {\n\t\tawait previousLifecycle;\n\t\ttry {\n\t\t\tawait entry.runtime?.session.abort();\n\t\t} catch (cause) {\n\t\t\treportDetachedFailure(handle, cause);\n\t\t}\n\t\ttry {\n\t\t\tawait entry.runtime?.session.waitForIdle();\n\t\t} catch (cause) {\n\t\t\treportDetachedFailure(handle, cause);\n\t\t}\n\t\ttry {\n\t\t\tawait disposeOnce();\n\t\t} catch (cause) {\n\t\t\treportDetachedFailure(handle, cause);\n\t\t}\n\t\ttry {\n\t\t\tawait closeScopeOnce();\n\t\t} catch (cause) {\n\t\t\treportDetachedFailure(handle, cause);\n\t\t}\n\t})();\n\tlet settled = false;\n\tconst finish = (): void => {\n\t\tif (settled) return;\n\t\tsettled = true;\n\t\trelease();\n\t\tentry.closeResolve?.();\n\t};\n\treleaseTimer = setTimeout(() => {\n\t\tvoid disposeOnce().catch((cause) => reportDetachedFailure(handle, cause));\n\t\tvoid closeScopeOnce().catch((cause) => reportDetachedFailure(handle, cause));\n\t\tvoid graceful.catch((cause) => reportDetachedFailure(handle, cause));\n\t\tfinish();\n\t}, host.closeGraceMs);\n\n\tvoid graceful.then(finish, (cause) => {\n\t\treportDetachedFailure(handle, cause);\n\t\tfinish();\n\t});\n\treturn completion;\n}\n"]}
|
|
@@ -2,6 +2,13 @@ type SocketSink = {
|
|
|
2
2
|
writeRaw(chunk: string): void;
|
|
3
3
|
waitForBackpressure(): Promise<void>;
|
|
4
4
|
};
|
|
5
|
+
export declare class SocketEventQueueOverflowError extends Error {
|
|
6
|
+
readonly queuedBytes: number;
|
|
7
|
+
readonly incomingBytes: number;
|
|
8
|
+
readonly maxQueueBytes: number;
|
|
9
|
+
readonly incomingPreview: string;
|
|
10
|
+
constructor(queuedBytes: number, incomingBytes: number, maxQueueBytes: number, incomingPreview: string);
|
|
11
|
+
}
|
|
5
12
|
/** Independent FIFO actor for one socket. It never shares a drain promise with another sink. */
|
|
6
13
|
export declare class SocketEventSinkActor {
|
|
7
14
|
private readonly queue;
|
|
@@ -13,7 +20,7 @@ export declare class SocketEventSinkActor {
|
|
|
13
20
|
private readonly onFailure;
|
|
14
21
|
private readonly maxQueueBytes;
|
|
15
22
|
constructor(sink: SocketSink, onFailure: (cause: unknown) => void, maxQueueBytes?: number);
|
|
16
|
-
enqueue(line: string, key?: string, onWritten?: () => void): void;
|
|
23
|
+
enqueue(line: string, key?: string, onWritten?: () => void, demotedLine?: string): void;
|
|
17
24
|
flush(): Promise<void>;
|
|
18
25
|
close(): void;
|
|
19
26
|
private drain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-event-fanout.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/socket-event-fanout.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"socket-event-fanout.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/socket-event-fanout.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC;AAqBF,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;gBAErB,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;CAUtG;AAED,gGAAgG;AAChG,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;IAC1C,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,CAAgB;IACjC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAU;IAE1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EAAE,aAAa,SAAsB;IAMtG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IA4CjF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,KAAK;CA0Bb"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
// A handful of image tool results is several MiB of base64 each; four of them
|
|
2
|
+
// blew the previous 4 MiB cap in one burst on a healthy reader. Overflow is a
|
|
3
|
+
// fail-closed disconnect (the client must resync), so the cap has to be well
|
|
4
|
+
// above any single burst a normal session produces.
|
|
5
|
+
const DEFAULT_QUEUE_BYTES = 64 * 1024 * 1024;
|
|
6
|
+
export class SocketEventQueueOverflowError extends Error {
|
|
7
|
+
constructor(queuedBytes, incomingBytes, maxQueueBytes, incomingPreview) {
|
|
8
|
+
super(`socket event queue overflow: ${queuedBytes} queued + ${incomingBytes} incoming > ${maxQueueBytes} (incoming: ${incomingPreview})`);
|
|
9
|
+
this.name = "SocketEventQueueOverflowError";
|
|
10
|
+
this.queuedBytes = queuedBytes;
|
|
11
|
+
this.incomingBytes = incomingBytes;
|
|
12
|
+
this.maxQueueBytes = maxQueueBytes;
|
|
13
|
+
this.incomingPreview = incomingPreview;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
2
16
|
/** Independent FIFO actor for one socket. It never shares a drain promise with another sink. */
|
|
3
17
|
export class SocketEventSinkActor {
|
|
4
18
|
constructor(sink, onFailure, maxQueueBytes = DEFAULT_QUEUE_BYTES) {
|
|
@@ -9,21 +23,30 @@ export class SocketEventSinkActor {
|
|
|
9
23
|
this.onFailure = onFailure;
|
|
10
24
|
this.maxQueueBytes = maxQueueBytes;
|
|
11
25
|
}
|
|
12
|
-
enqueue(line, key, onWritten) {
|
|
26
|
+
enqueue(line, key, onWritten, demotedLine) {
|
|
13
27
|
if (this.closed)
|
|
14
28
|
return;
|
|
15
29
|
const bytes = Buffer.byteLength(line);
|
|
16
30
|
if (key !== undefined) {
|
|
17
31
|
const existing = this.queue.find((entry) => entry.key === key);
|
|
18
32
|
if (existing) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
// Lossless supersession. The old behaviour replaced the queued line
|
|
34
|
+
// outright, which threw away every delta a stalled reader had not yet
|
|
35
|
+
// received (a desktop client assembles text from deltas). Keep the
|
|
36
|
+
// superseded record - demoted to its delta-only form when the producer
|
|
37
|
+
// supplied one - and let only the newest record carry the snapshot.
|
|
38
|
+
if (existing.demotedLine !== undefined) {
|
|
39
|
+
this.queuedBytes -= existing.bytes;
|
|
40
|
+
existing.line = existing.demotedLine;
|
|
41
|
+
existing.bytes = Buffer.byteLength(existing.line);
|
|
42
|
+
this.queuedBytes += existing.bytes;
|
|
43
|
+
existing.demotedLine = undefined;
|
|
44
|
+
}
|
|
45
|
+
existing.key = undefined;
|
|
24
46
|
}
|
|
25
47
|
}
|
|
26
48
|
if (this.queuedBytes + bytes > this.maxQueueBytes) {
|
|
49
|
+
const overflow = new SocketEventQueueOverflowError(this.queuedBytes, bytes, this.maxQueueBytes, line.slice(0, 120));
|
|
27
50
|
this.closed = true;
|
|
28
51
|
this.queue.length = 0;
|
|
29
52
|
this.queuedBytes = 0;
|
|
@@ -33,10 +56,10 @@ export class SocketEventSinkActor {
|
|
|
33
56
|
catch (cause) {
|
|
34
57
|
this.onFailure(cause);
|
|
35
58
|
}
|
|
36
|
-
this.onFailure(
|
|
59
|
+
this.onFailure(overflow);
|
|
37
60
|
return;
|
|
38
61
|
}
|
|
39
|
-
this.queue.push({ line, bytes, key, onWritten });
|
|
62
|
+
this.queue.push({ line, bytes, key, demotedLine, onWritten });
|
|
40
63
|
this.queuedBytes += bytes;
|
|
41
64
|
void this.drain();
|
|
42
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-event-fanout.js","sourceRoot":"","sources":["../../../src/modes/rpc/socket-event-fanout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socket-event-fanout.js","sourceRoot":"","sources":["../../../src/modes/rpc/socket-event-fanout.ts"],"names":[],"mappings":"AAkBA,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,oDAAoD;AACpD,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7C,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAMvD,YAAY,WAAmB,EAAE,aAAqB,EAAE,aAAqB,EAAE,eAAuB;QACrG,KAAK,CACJ,gCAAgC,WAA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CAAC,GAAG,EAAE;YACjB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC1B,2EAA2E;YAC3E,oEAAoE;YACpE,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;gBAAE,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9D,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;CACD","sourcesContent":["type SocketSink = {\n\twriteRaw(chunk: string): void;\n\twaitForBackpressure(): Promise<void>;\n};\n\ntype QueueEntry = {\n\tline: string;\n\tbytes: number;\n\tkey?: string;\n\t/**\n\t * The record with its cumulative snapshot fields blanked (delta kept). When a\n\t * later record with the same key supersedes this one, the entry is rewritten to\n\t * this line instead of being replaced, so a stalled reader never loses a delta.\n\t */\n\tdemotedLine?: string;\n\tonWritten?: () => void;\n};\n\n// A handful of image tool results is several MiB of base64 each; four of them\n// blew the previous 4 MiB cap in one burst on a healthy reader. Overflow is a\n// fail-closed disconnect (the client must resync), so the cap has to be well\n// above any single burst a normal session produces.\nconst DEFAULT_QUEUE_BYTES = 64 * 1024 * 1024;\n\nexport class SocketEventQueueOverflowError extends Error {\n\treadonly queuedBytes: number;\n\treadonly incomingBytes: number;\n\treadonly maxQueueBytes: number;\n\treadonly incomingPreview: string;\n\n\tconstructor(queuedBytes: number, incomingBytes: number, maxQueueBytes: number, incomingPreview: string) {\n\t\tsuper(\n\t\t\t`socket event queue overflow: ${queuedBytes} queued + ${incomingBytes} incoming > ${maxQueueBytes} (incoming: ${incomingPreview})`,\n\t\t);\n\t\tthis.name = \"SocketEventQueueOverflowError\";\n\t\tthis.queuedBytes = queuedBytes;\n\t\tthis.incomingBytes = incomingBytes;\n\t\tthis.maxQueueBytes = maxQueueBytes;\n\t\tthis.incomingPreview = incomingPreview;\n\t}\n}\n\n/** Independent FIFO actor for one socket. It never shares a drain promise with another sink. */\nexport class SocketEventSinkActor {\n\tprivate readonly queue: QueueEntry[] = [];\n\tprivate queuedBytes = 0;\n\tprivate draining?: Promise<void>;\n\tprivate closed = false;\n\tprivate failure?: unknown;\n\n\tprivate readonly sink: SocketSink;\n\tprivate readonly onFailure: (cause: unknown) => void;\n\tprivate readonly maxQueueBytes: number;\n\n\tconstructor(sink: SocketSink, onFailure: (cause: unknown) => void, maxQueueBytes = DEFAULT_QUEUE_BYTES) {\n\t\tthis.sink = sink;\n\t\tthis.onFailure = onFailure;\n\t\tthis.maxQueueBytes = maxQueueBytes;\n\t}\n\n\tenqueue(line: string, key?: string, onWritten?: () => void, demotedLine?: string): void {\n\t\tif (this.closed) return;\n\t\tconst bytes = Buffer.byteLength(line);\n\t\tif (key !== undefined) {\n\t\t\tconst existing = this.queue.find((entry) => entry.key === key);\n\t\t\tif (existing) {\n\t\t\t\t// Lossless supersession. The old behaviour replaced the queued line\n\t\t\t\t// outright, which threw away every delta a stalled reader had not yet\n\t\t\t\t// received (a desktop client assembles text from deltas). Keep the\n\t\t\t\t// superseded record - demoted to its delta-only form when the producer\n\t\t\t\t// supplied one - and let only the newest record carry the snapshot.\n\t\t\t\tif (existing.demotedLine !== undefined) {\n\t\t\t\t\tthis.queuedBytes -= existing.bytes;\n\t\t\t\t\texisting.line = existing.demotedLine;\n\t\t\t\t\texisting.bytes = Buffer.byteLength(existing.line);\n\t\t\t\t\tthis.queuedBytes += existing.bytes;\n\t\t\t\t\texisting.demotedLine = undefined;\n\t\t\t\t}\n\t\t\t\texisting.key = undefined;\n\t\t\t}\n\t\t}\n\t\tif (this.queuedBytes + bytes > this.maxQueueBytes) {\n\t\t\tconst overflow = new SocketEventQueueOverflowError(\n\t\t\t\tthis.queuedBytes,\n\t\t\t\tbytes,\n\t\t\t\tthis.maxQueueBytes,\n\t\t\t\tline.slice(0, 120),\n\t\t\t);\n\t\t\tthis.closed = true;\n\t\t\tthis.queue.length = 0;\n\t\t\tthis.queuedBytes = 0;\n\t\t\ttry {\n\t\t\t\tthis.sink.writeRaw(`${JSON.stringify({ type: \"overflow\", error: \"overflow, resync required\" })}\\n`);\n\t\t\t} catch (cause) {\n\t\t\t\tthis.onFailure(cause);\n\t\t\t}\n\t\t\tthis.onFailure(overflow);\n\t\t\treturn;\n\t\t}\n\t\tthis.queue.push({ line, bytes, key, demotedLine, onWritten });\n\t\tthis.queuedBytes += bytes;\n\t\tvoid this.drain();\n\t}\n\n\tasync flush(): Promise<void> {\n\t\twhile (this.draining) await this.draining;\n\t\tif (this.failure !== undefined) throw this.failure;\n\t}\n\n\tclose(): void {\n\t\tthis.closed = true;\n\t\tthis.queue.length = 0;\n\t\tthis.queuedBytes = 0;\n\t}\n\n\tprivate drain(): Promise<void> {\n\t\tif (this.draining) return this.draining;\n\t\tthis.draining = (async () => {\n\t\t\ttry {\n\t\t\t\twhile (!this.closed && this.queue.length > 0) {\n\t\t\t\t\tconst entry = this.queue.shift()!;\n\t\t\t\t\tthis.queuedBytes -= entry.bytes;\n\t\t\t\t\tthis.sink.writeRaw(entry.line);\n\t\t\t\t\tawait this.sink.waitForBackpressure();\n\t\t\t\t\tentry.onWritten?.();\n\t\t\t\t}\n\t\t\t} catch (cause) {\n\t\t\t\tthis.failure = cause;\n\t\t\t\tthis.closed = true;\n\t\t\t\tthis.queue.length = 0;\n\t\t\t\tthis.queuedBytes = 0;\n\t\t\t\tthis.onFailure(cause);\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.draining = undefined;\n\t\t\t// An enqueue that lands between the loop's exit and this reaction sees the\n\t\t\t// stale settled promise and starts nothing; reschedule for it here.\n\t\t\tif (!this.closed && this.queue.length > 0) void this.drain();\n\t\t});\n\t\treturn this.draining;\n\t}\n}\n"]}
|
package/docs/rpc.md
CHANGED
|
@@ -39,6 +39,33 @@ Rebranded distributions read the equivalent variable under their configured envi
|
|
|
39
39
|
`extension_events` opts the client into generic extension-owned event records; clients that omit it
|
|
40
40
|
retain the previous wire stream unchanged.
|
|
41
41
|
|
|
42
|
+
#### media_placeholders
|
|
43
|
+
|
|
44
|
+
A client that advertises `media_placeholders` in `set_client_info` tells the host it does not want
|
|
45
|
+
inline media bytes on the wire. For that connection the host replaces every image block inside a
|
|
46
|
+
tool result (`ToolResultMessage.content` and `tool_execution_end.result.content`, including the
|
|
47
|
+
entries carried by `get_entries`, `get_messages`, `get_tree`, `open_session` state and attach-time
|
|
48
|
+
snapshot replay) with an `image_ref` placeholder:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"type": "image_ref",
|
|
53
|
+
"mimeType": "image/png",
|
|
54
|
+
"byteLength": 553000,
|
|
55
|
+
"ref": {"toolCallId": "call_abc123", "contentIndex": 1}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`byteLength` is the decoded size of the omitted payload. The original block is fetched on demand with
|
|
60
|
+
[`get_media`](#get_media) using the `ref`. User-authored images (`prompt`/`steer`/`follow_up`
|
|
61
|
+
`images`) are never replaced.
|
|
62
|
+
|
|
63
|
+
A connection that does not advertise the capability receives byte-identical output to before. The
|
|
64
|
+
capability is advertised by the host in `get_protocol_info.capabilities` in both classic and
|
|
65
|
+
multi-session mode, but the transform itself is applied only by the multi-session host: classic
|
|
66
|
+
single-connection stdio mode never rewrites its output, so a stdio client always receives inline
|
|
67
|
+
media even if it names the capability. `get_media` is answered in both modes.
|
|
68
|
+
|
|
42
69
|
## Multi-session mode (D1 wire protocol)
|
|
43
70
|
|
|
44
71
|
Multi-session mode lets one `senpi --mode rpc` process serve several independent conversations concurrently over the same stdio JSONL stream. Classic single-session mode is byte-identical to today; the only additive classic-mode behavior is that `get_protocol_info` is answered.
|
|
@@ -62,10 +89,14 @@ On Windows, listeners and clients deterministically map the logical socket path
|
|
|
62
89
|
`\\.\pipe\senpi-rpc-<sha256[:32]>`. Callers keep using the same `unix://` CLI value; the logical path remains the
|
|
63
90
|
ownership and settings identity, and callers never construct the pipe name themselves.
|
|
64
91
|
|
|
65
|
-
Socket event visibility is
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
Socket event visibility is attachment-scoped for session content: each connection receives agent output only from sessions
|
|
93
|
+
attached to that connection, with every record tagged by its routing `sessionId`. Content-free lifecycle records
|
|
94
|
+
(`agent_start`, `agent_settled`, `agent_idle`, `session_opened`, and `session_closed`) are broadcast to all registered
|
|
95
|
+
connections, including the supervisor's unattached observer, so host lifecycle accounting remains accurate without exposing
|
|
96
|
+
session content. Correlated responses and dialog extension UI
|
|
97
|
+
requests (select, confirm, input, and editor) are requester-only; other extension UI state records go to the session's
|
|
98
|
+
attached connections. To observe a foreign session, open it by its existing
|
|
99
|
+
`sessionPath`; the host attaches that connection during `open_session`.
|
|
69
100
|
|
|
70
101
|
### Client information and rendered components
|
|
71
102
|
|
|
@@ -175,7 +206,7 @@ so they hold even for embedders and hand-started hosts that have no supervisor.
|
|
|
175
206
|
| --- | --- | --- | --- |
|
|
176
207
|
| `get_protocol_info` | - | `{ protocolVersion: 1, serverVersion: string, capabilities: string[], mode: "classic"\|"multi" }` | Answered in BOTH modes; side-effect-free; the capability probe. Multi-session hosts include `multi_session` plus the negotiated launch capabilities. |
|
|
177
208
|
| `open_session` | `sessionPath?`, `cwd?`, `provider?`, `modelId?`, `thinkingLevel?`, `permissionPreset?` (all optional; paths MUST be absolute) | `{ sessionId, state: RpcSessionState, attached?: true }` | `sessionPath` = today's `--session` semantics (open-if-exists else create persisting there, `session-manager.ts:926-940`); `provider`/`modelId` applied only on create (resume restores the session's model — mirrors `SenpiSessionRuntime.ts:198-200`); params form the immutable launch profile (D8). When the path is already held by a fully-open session, the open ATTACHES to it: same routing handle, `attached: true`, one more attachment counted; the runtime is torn down only when the last attachment closes. Fails with `too_many_sessions` at the occupancy cap (see [Shared host occupancy](#shared-host-occupancy-idle-eviction-session-cap-empty-host-exit)); idle sessions past the eviction window are closed by the host itself. |
|
|
178
|
-
| `close_session` | `sessionId` | `{}` | Aborts active work, awaits agent idle + settled persistence
|
|
209
|
+
| `close_session` | `sessionId` | `{}` | Aborts active work, awaits agent idle + settled persistence for up to the host grace window (default 10s), then force-releases the session; its response is the LAST record tagged with that handle for the first closer — no events after (test-pinned). A concurrent close joins the same teardown and receives its own successful response. |
|
|
179
210
|
| `list_sessions` | - | `{ sessions: [{ sessionId, durableSessionId, sessionPath, cwd, name, status }] }` | Includes `opening`/`closing` entries with their status. |
|
|
180
211
|
| every existing command | + `sessionId` (REQUIRED in multi mode) | unchanged | Routed to that session. |
|
|
181
212
|
|
|
@@ -195,6 +226,7 @@ In the response `error` field, machine-matchable:
|
|
|
195
226
|
- `invalid_path` (relative `sessionPath`/`cwd`)
|
|
196
227
|
- `too_many_sessions` (`open_session` while `SENPI_RPC_MAX_SESSIONS` sessions are already opening/open; attaching to a live session never fails this way)
|
|
197
228
|
- `open_failed: <detail>`
|
|
229
|
+
- `media_not_found` (`get_media` for an unknown `toolCallId`, or a `contentIndex` that does not point at an image block)
|
|
198
230
|
|
|
199
231
|
### Tagging
|
|
200
232
|
|
|
@@ -206,7 +238,7 @@ Strict FIFO per session; one total stdout order; cross-session order unspecified
|
|
|
206
238
|
|
|
207
239
|
### Duplicate/idempotency
|
|
208
240
|
|
|
209
|
-
Duplicate `open_session` while a path reservation is held by a fully-open session → ATTACH (`attached: true`, same handle); while held by an `opening`/`closing` entry → `session_path_in_use`. `close_session` releases one attachment; the runtime is disposed only when the last attachment closes. `close_session` on unknown/already-closed → `unknown_session` error. Request `id`s are client-owned; the server echoes them without dedup.
|
|
241
|
+
Duplicate `open_session` while a path reservation is held by a fully-open session → ATTACH (`attached: true`, same handle); while held by an `opening`/`closing` entry → `session_path_in_use`. `close_session` releases one attachment; the runtime is disposed only when the last attachment closes. A close for an entry already `closing` joins its in-flight teardown. `close_session` on unknown/already-closed → `unknown_session` error. The grace window is configurable by the host through `SENPI_RPC_CLOSE_GRACE_MS`. Request `id`s are client-owned; the server echoes them without dedup.
|
|
210
242
|
|
|
211
243
|
## Protocol Overview
|
|
212
244
|
|
|
@@ -445,6 +477,51 @@ Response:
|
|
|
445
477
|
|
|
446
478
|
Messages are `AgentMessage` objects (see [Message Types](#message-types)).
|
|
447
479
|
|
|
480
|
+
#### get_media
|
|
481
|
+
|
|
482
|
+
Fetch one media block that was omitted for a [`media_placeholders`](#media_placeholders) client. The
|
|
483
|
+
parameters are exactly the placeholder's `ref`.
|
|
484
|
+
|
|
485
|
+
```json
|
|
486
|
+
{"type": "get_media", "toolCallId": "call_abc123", "contentIndex": 1}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Response:
|
|
490
|
+
```json
|
|
491
|
+
{
|
|
492
|
+
"type": "response",
|
|
493
|
+
"command": "get_media",
|
|
494
|
+
"success": true,
|
|
495
|
+
"data": {
|
|
496
|
+
"toolCallId": "call_abc123",
|
|
497
|
+
"contentIndex": 1,
|
|
498
|
+
"content": {"type": "image", "data": "<base64>", "mimeType": "image/png"}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
`content` is the original `ImageContent` block, byte-for-byte. `contentIndex` indexes the tool
|
|
504
|
+
result's `content` array. The host looks the tool call up in the durable session entries first (so a
|
|
505
|
+
block stays fetchable after the live message window moved on), then in the current messages for a
|
|
506
|
+
result that has not been persisted yet.
|
|
507
|
+
|
|
508
|
+
When the tool call is unknown, the index is out of range, or the index points at a non-image block,
|
|
509
|
+
the response fails with `error` and `errorCode` both set to `media_not_found`:
|
|
510
|
+
|
|
511
|
+
```json
|
|
512
|
+
{
|
|
513
|
+
"type": "response",
|
|
514
|
+
"command": "get_media",
|
|
515
|
+
"success": false,
|
|
516
|
+
"error": "media_not_found",
|
|
517
|
+
"errorCode": "media_not_found"
|
|
518
|
+
}
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
The command is answered in classic and multi-session mode alike; in multi-session mode it takes the
|
|
522
|
+
usual `sessionId` envelope. It is answerable regardless of whether the connection advertised
|
|
523
|
+
`media_placeholders`.
|
|
524
|
+
|
|
448
525
|
### Model
|
|
449
526
|
|
|
450
527
|
#### set_model
|
|
@@ -1705,6 +1782,37 @@ Emitted when an extension throws an error.
|
|
|
1705
1782
|
}
|
|
1706
1783
|
```
|
|
1707
1784
|
|
|
1785
|
+
## OAuth login
|
|
1786
|
+
|
|
1787
|
+
Logins are fire-command-then-subscribe: the command answers as soon as the flow has started, and the URL plus the terminal result arrive as events.
|
|
1788
|
+
|
|
1789
|
+
- `login_start` `{provider}`: responds immediately with `success: true` (flow started). A second `login_start` for the same provider aborts the earlier attempt.
|
|
1790
|
+
- `auth_login_url` `{provider, url}`: the URL (or device-code verification URL) the user must open.
|
|
1791
|
+
- `auth_login_end` `{provider, success, error?}`: exactly one per login; `error` is a non-secret message.
|
|
1792
|
+
- `login_cancel` `{provider}`: aborts the in-flight login; the client then sees `auth_login_end` with `success: false`.
|
|
1793
|
+
|
|
1794
|
+
Some providers need input mid-flow (a pasted authorization code, a text or secret value, a choice between accounts). Those prompts reuse the extension UI dialog channel described in the next section:
|
|
1795
|
+
|
|
1796
|
+
- `text`, `secret`, and `manual_code` prompts arrive as an `extension_ui_request` with `method: "input"`. `title` is the provider's prompt message and `placeholder` is present when the provider supplied one.
|
|
1797
|
+
- `select` prompts arrive with `method: "select"`; `options` holds the option labels.
|
|
1798
|
+
|
|
1799
|
+
Answer with `extension_ui_response` `{id, value}`. For `select`, `value` is the chosen label and is mapped back to the option id in-process. Sending `{id, cancelled: true}` cancels the login, and `auth_login_end` reports `success: false` with `error: "Login cancelled"`.
|
|
1800
|
+
|
|
1801
|
+
A client that never answers loses nothing. The browser/callback completion path still finishes the login, and the pending request is released when the login ends or is cancelled, so an open dialog never blocks completion. Secrets don't cross the wire in either direction: only the prompt message, placeholder, and labels are emitted, and the answer is consumed in-process and never echoed.
|
|
1802
|
+
|
|
1803
|
+
Example exchange (Anthropic, user pastes the code instead of finishing in the browser):
|
|
1804
|
+
|
|
1805
|
+
```jsonl
|
|
1806
|
+
{"id": "login-1", "type": "login_start", "provider": "anthropic"}
|
|
1807
|
+
{"id": "login-1", "type": "response", "command": "login_start", "success": true}
|
|
1808
|
+
{"type": "auth_login_url", "provider": "anthropic", "url": "https://claude.ai/oauth/authorize?..."}
|
|
1809
|
+
{"type": "extension_ui_request", "id": "uuid-7", "method": "input", "title": "Complete login in your browser, or paste the authorization code / redirect URL here:", "placeholder": "http://localhost:53692/callback"}
|
|
1810
|
+
{"type": "extension_ui_response", "id": "uuid-7", "value": "<pasted code>"}
|
|
1811
|
+
{"type": "auth_login_end", "provider": "anthropic", "success": true}
|
|
1812
|
+
```
|
|
1813
|
+
|
|
1814
|
+
If the user completes the flow in the browser instead, the same `extension_ui_request` is emitted, no response is needed, and `auth_login_end` arrives on its own.
|
|
1815
|
+
|
|
1708
1816
|
## Extension UI Protocol
|
|
1709
1817
|
|
|
1710
1818
|
Extensions can request user interaction via `ctx.ui.select()`, `ctx.ui.confirm()`, etc. In RPC mode, these are translated into a request/response sub-protocol on top of the base command/event flow.
|