@code-yeongyu/senpi 2026.9.7 → 2026.9.9-2
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 +122 -3
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +2 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +48 -4
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +192 -40
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction-execution.d.ts.map +1 -1
- package/dist/core/compaction/compaction-execution.js +5 -5
- package/dist/core/compaction/compaction-execution.js.map +1 -1
- package/dist/core/compaction/compaction-settings.d.ts +2 -0
- package/dist/core/compaction/compaction-settings.d.ts.map +1 -1
- package/dist/core/compaction/compaction-settings.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +3 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +14 -8
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/stream-watchdog.d.ts +29 -0
- package/dist/core/compaction/stream-watchdog.d.ts.map +1 -1
- package/dist/core/compaction/stream-watchdog.js +35 -0
- package/dist/core/compaction/stream-watchdog.js.map +1 -1
- package/dist/core/compaction-settings-access.d.ts +6 -0
- package/dist/core/compaction-settings-access.d.ts.map +1 -1
- package/dist/core/compaction-settings-access.js.map +1 -1
- package/dist/core/compaction-settings-resolver.d.ts +2 -0
- package/dist/core/compaction-settings-resolver.d.ts.map +1 -1
- package/dist/core/compaction-settings-resolver.js +5 -0
- package/dist/core/compaction-settings-resolver.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.js +1 -1
- package/dist/core/dynamic-prompt/working-task.js.map +1 -1
- package/dist/core/extensions/builtin/cache-keepalive/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cache-keepalive/index.js +4 -21
- package/dist/core/extensions/builtin/cache-keepalive/index.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts +2 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js +10 -25
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js.map +1 -1
- 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 +36 -19
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js +21 -10
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +4 -17
- 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 +23 -33
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js +5 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.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 +5 -3
- 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 +8 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +6 -5
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +6 -5
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/circuit-breaker.d.ts +8 -0
- package/dist/core/extensions/builtin/compaction/circuit-breaker.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/circuit-breaker.js +8 -0
- package/dist/core/extensions/builtin/compaction/circuit-breaker.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +8 -0
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +125 -20
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.d.ts +18 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.js +20 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +54 -11
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts +3 -0
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.js +47 -23
- package/dist/core/extensions/builtin/compaction/lane-policy.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts +1 -1
- package/dist/core/extensions/builtin/compaction/model-usability-budget.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/model-usability-budget.js +23 -3
- package/dist/core/extensions/builtin/compaction/model-usability-budget.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/resume-admission.d.ts +7 -0
- package/dist/core/extensions/builtin/compaction/resume-admission.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/resume-admission.js +7 -0
- package/dist/core/extensions/builtin/compaction/resume-admission.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/speculative-summary.d.ts +2 -0
- package/dist/core/extensions/builtin/compaction/speculative-summary.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/speculative-summary.js +5 -2
- package/dist/core/extensions/builtin/compaction/speculative-summary.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/speculative.js +9 -3
- package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/summarization-retry.d.ts +10 -4
- package/dist/core/extensions/builtin/compaction/summarization-retry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/summarization-retry.js +14 -5
- package/dist/core/extensions/builtin/compaction/summarization-retry.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 +11 -0
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js +6 -4
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm.d.ts +25 -1
- package/dist/core/extensions/builtin/goal/cache-warm.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm.js +29 -10
- package/dist/core/extensions/builtin/goal/cache-warm.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +3 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +17 -2
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +1 -0
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +8 -3
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.d.ts +5 -1
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.js +9 -26
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -1
- package/dist/core/extensions/builtin/hooks/plugin-manifest.js +2 -2
- package/dist/core/extensions/builtin/hooks/plugin-manifest.js.map +1 -1
- package/dist/core/extensions/builtin/hooks/safety.js +2 -2
- package/dist/core/extensions/builtin/hooks/safety.js.map +1 -1
- package/dist/core/extensions/builtin/imagegen/params.d.ts +36 -0
- package/dist/core/extensions/builtin/imagegen/params.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/params.js +55 -0
- package/dist/core/extensions/builtin/imagegen/params.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/reference-images.d.ts +11 -0
- package/dist/core/extensions/builtin/imagegen/reference-images.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/reference-images.js +55 -0
- package/dist/core/extensions/builtin/imagegen/reference-images.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/skill/SKILL.md +47 -4
- package/dist/core/extensions/builtin/imagegen/tool.d.ts +10 -19
- package/dist/core/extensions/builtin/imagegen/tool.d.ts.map +1 -1
- package/dist/core/extensions/builtin/imagegen/tool.js +21 -45
- package/dist/core/extensions/builtin/imagegen/tool.js.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.d.ts +18 -0
- package/dist/core/extensions/builtin/monitor-state-event.d.ts.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.js +23 -0
- package/dist/core/extensions/builtin/monitor-state-event.js.map +1 -1
- package/dist/core/extensions/builtin/oauth-login-interaction.d.ts +24 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.d.ts.map +1 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.js +77 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.js.map +1 -0
- package/dist/core/extensions/builtin/permission-system/external-dir.d.ts.map +1 -1
- package/dist/core/extensions/builtin/permission-system/external-dir.js +5 -51
- package/dist/core/extensions/builtin/permission-system/external-dir.js.map +1 -1
- package/dist/core/extensions/builtin/permission-system/parsers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/permission-system/parsers.js +5 -7
- package/dist/core/extensions/builtin/permission-system/parsers.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +1 -1
- 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.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +14 -7
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +34 -13
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +6 -10
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +14 -9
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +15 -15
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +49 -21
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/service-tier.d.ts +2 -0
- package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
- package/dist/core/extensions/builtin/service-tier.js +17 -1
- package/dist/core/extensions/builtin/service-tier.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.js +3 -0
- package/dist/core/extensions/builtin/terminal/durable-command.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.js +2 -0
- package/dist/core/extensions/builtin/terminal/durable-file.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +14 -2
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +27 -5
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +17 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +76 -14
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.js +6 -1
- package/dist/core/extensions/builtin/terminal/notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.d.ts +3 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.js +13 -0
- package/dist/core/extensions/builtin/terminal/session-bundle.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/shared.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/shared.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/shared.js +15 -2
- package/dist/core/extensions/builtin/terminal/shared.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 +8 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.js +1 -0
- package/dist/core/extensions/builtin/tool-search/index.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/service.d.ts +4 -0
- package/dist/core/extensions/builtin/tool-search/service.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/service.js +11 -0
- package/dist/core/extensions/builtin/tool-search/service.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +2 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +17 -8
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +8 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +14 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/high-reasoning-warning.d.ts.map +1 -1
- package/dist/core/high-reasoning-warning.js +4 -6
- package/dist/core/high-reasoning-warning.js.map +1 -1
- package/dist/core/resource-loader.d.ts +2 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +11 -7
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +38 -7
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +11 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-write-reservation.d.ts +4 -0
- package/dist/core/session-write-reservation.d.ts.map +1 -0
- package/dist/core/session-write-reservation.js +12 -0
- package/dist/core/session-write-reservation.js.map +1 -0
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-shapes.js.map +1 -1
- package/dist/core/tools/bounded-realpath.d.ts +28 -0
- package/dist/core/tools/bounded-realpath.d.ts.map +1 -0
- package/dist/core/tools/bounded-realpath.js +53 -0
- package/dist/core/tools/bounded-realpath.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +15 -13
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/filesystem-policy.d.ts +7 -0
- package/dist/core/tools/filesystem-policy.d.ts.map +1 -1
- package/dist/core/tools/filesystem-policy.js +25 -15
- package/dist/core/tools/filesystem-policy.js.map +1 -1
- package/dist/core/tools/read-classifiers.d.ts +17 -0
- package/dist/core/tools/read-classifiers.d.ts.map +1 -0
- package/dist/core/tools/read-classifiers.js +26 -0
- package/dist/core/tools/read-classifiers.js.map +1 -0
- package/dist/core/tools/read.d.ts +5 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +21 -1
- 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 +13 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +14 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +166 -147
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +4 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/memory-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/memory-tips.js +6 -0
- package/dist/modes/interactive/tips/catalog/memory-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/subagent-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/subagent-tips.js +6 -0
- package/dist/modes/interactive/tips/catalog/subagent-tips.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 +1 -1
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +31 -5
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/host-watchdog.d.ts +11 -0
- package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
- package/dist/modes/rpc/host-watchdog.js +16 -2
- package/dist/modes/rpc/host-watchdog.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.d.ts +2 -0
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +72 -24
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/session-binding.js +3 -0
- package/dist/modes/rpc/session-binding.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +57 -25
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +23 -1
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +108 -1
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +4 -2
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +1 -1
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-worker-client.d.ts +47 -0
- package/dist/modes/rpc/session-worker-client.d.ts.map +1 -0
- package/dist/modes/rpc/session-worker-client.js +226 -0
- package/dist/modes/rpc/session-worker-client.js.map +1 -0
- package/dist/modes/rpc/session-worker-protocol.d.ts +103 -0
- package/dist/modes/rpc/session-worker-protocol.d.ts.map +1 -0
- package/dist/modes/rpc/session-worker-protocol.js +12 -0
- package/dist/modes/rpc/session-worker-protocol.js.map +1 -0
- package/dist/modes/rpc/session-worker-requests.d.ts +24 -0
- package/dist/modes/rpc/session-worker-requests.d.ts.map +1 -0
- package/dist/modes/rpc/session-worker-requests.js +71 -0
- package/dist/modes/rpc/session-worker-requests.js.map +1 -0
- package/dist/modes/rpc/session-worker.d.ts +2 -0
- package/dist/modes/rpc/session-worker.d.ts.map +1 -0
- package/dist/modes/rpc/session-worker.js +229 -0
- package/dist/modes/rpc/session-worker.js.map +1 -0
- package/dist/modes/rpc/socket-ownership.d.ts +46 -0
- package/dist/modes/rpc/socket-ownership.d.ts.map +1 -0
- package/dist/modes/rpc/socket-ownership.js +178 -0
- package/dist/modes/rpc/socket-ownership.js.map +1 -0
- package/dist/modes/rpc/worker-session-registry.d.ts +37 -0
- package/dist/modes/rpc/worker-session-registry.d.ts.map +1 -0
- package/dist/modes/rpc/worker-session-registry.js +207 -0
- package/dist/modes/rpc/worker-session-registry.js.map +1 -0
- package/dist/utils/fs-watch.d.ts +17 -0
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js +38 -10
- package/dist/utils/fs-watch.js.map +1 -1
- package/dist/utils/paths.d.ts +33 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +109 -3
- package/dist/utils/paths.js.map +1 -1
- package/docs/development.md +3 -2
- package/docs/providers.md +5 -1
- package/docs/rpc.md +70 -9
- package/docs/settings.md +2 -0
- package/docs/skills.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +55 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +14 -1
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/runtime-factory.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +7 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/AGENTS.md +7 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/kernel.ts +4 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +29 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +10 -6
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.d.ts +16 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.js +44 -8
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-startup.ts +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/transport.ts +9 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/kernel.ts +4 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/session-env.ts +56 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +9 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/output-meta.ts +26 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +17 -24
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +12 -3
- 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/dist/assistant-terminal-state.d.ts +7 -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 +19 -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/empty-assistant-recovery.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +24 -16
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -1
- 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 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.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.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +70 -183
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.js +260 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-edit.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-edit.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-edit.js +11 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-edit.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-params.d.ts +25 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-params.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-params.js +58 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images-params.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.d.ts +3 -6
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.js +15 -33
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.d.ts +40 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.js +138 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +2 -3
- 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 +42 -139
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.js +29 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.js +20 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +61 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +61 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/images.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/images.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/images.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/images.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/amazon-bedrock.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/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.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-codex.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.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/tool-call-middleware/recovery-stream-terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-stream-terminal.js +16 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-stream-terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +7 -0
- 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 +1 -1
- 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 +14 -3
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.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 +7 -7
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ownership-checked removal for Unix domain socket path entries.
|
|
3
|
+
*
|
|
4
|
+
* A socket path is a rendezvous name, not a capability: once a host unlinks
|
|
5
|
+
* its entry, any other process may bind the same path. Teardown that removes
|
|
6
|
+
* "its" socket by path alone can therefore delete a NEWER host's freshly
|
|
7
|
+
* published entry after a takeover renamed a replacement over that path. The
|
|
8
|
+
* startup path already refuses to touch a socket owned by a live server
|
|
9
|
+
* (`prepareSocketPath`); these helpers give every teardown path the same rule:
|
|
10
|
+
* capture the bound entry's filesystem identity (dev + ino) at listen time and
|
|
11
|
+
* unlink only while the path still stat-matches that identity.
|
|
12
|
+
*/
|
|
13
|
+
import { mkdir, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
14
|
+
import { dirname } from "node:path";
|
|
15
|
+
/**
|
|
16
|
+
* Name of the sidecar, inside the lifecycle supervisor's private scratch
|
|
17
|
+
* directory, that records which public socket entry that supervisor bound. The
|
|
18
|
+
* directory is per-supervisor, so a replacement supervisor's token can never be
|
|
19
|
+
* mistaken for the old one's.
|
|
20
|
+
*/
|
|
21
|
+
export const PUBLIC_SOCKET_IDENTITY_FILE = "public-socket.owner";
|
|
22
|
+
/** Default bound on waiting for a supervisor to publish its ownership token. */
|
|
23
|
+
export const SOCKET_IDENTITY_WAIT_MS = 30_000;
|
|
24
|
+
function sameSocketIdentity(a, b) {
|
|
25
|
+
return a.dev === b.dev && a.ino === b.ino;
|
|
26
|
+
}
|
|
27
|
+
/** Reads the current identity of a socket path entry; `undefined` once absent. */
|
|
28
|
+
export async function statSocketIdentity(socketPath) {
|
|
29
|
+
try {
|
|
30
|
+
const { dev, ino } = await stat(socketPath);
|
|
31
|
+
return { dev, ino };
|
|
32
|
+
}
|
|
33
|
+
catch (cause) {
|
|
34
|
+
if (isNodeErrorCode(cause, "ENOENT"))
|
|
35
|
+
return undefined;
|
|
36
|
+
throw cause;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Records a bound socket identity for teardown paths that cannot hold it in memory. */
|
|
40
|
+
export async function writeSocketIdentityFile(path, identity) {
|
|
41
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
42
|
+
const tmpPath = `${path}.${process.pid}.tmp`;
|
|
43
|
+
await writeFile(tmpPath, `${JSON.stringify(identity)}\n`, { mode: 0o600 });
|
|
44
|
+
await rename(tmpPath, path);
|
|
45
|
+
}
|
|
46
|
+
export async function readSocketIdentityFile(path) {
|
|
47
|
+
let raw;
|
|
48
|
+
try {
|
|
49
|
+
raw = await readFile(path, "utf8");
|
|
50
|
+
}
|
|
51
|
+
catch (cause) {
|
|
52
|
+
if (isNodeErrorCode(cause, "ENOENT"))
|
|
53
|
+
return undefined;
|
|
54
|
+
throw cause;
|
|
55
|
+
}
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Truncated or in-progress JSON is not a token: callers wait or leave the path.
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (typeof parsed !== "object" ||
|
|
65
|
+
parsed === null ||
|
|
66
|
+
typeof parsed.dev !== "number" ||
|
|
67
|
+
typeof parsed.ino !== "number") {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return { dev: parsed.dev, ino: parsed.ino };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Waits, bounded, for an identity file to appear. The lifecycle supervisor
|
|
74
|
+
* publishes its public-socket token after this host's internal listener is
|
|
75
|
+
* ready, so supervised hosts poll briefly instead of assuming ordering.
|
|
76
|
+
*/
|
|
77
|
+
export async function waitForSocketIdentityFile(path, timeoutMs = SOCKET_IDENTITY_WAIT_MS, intervalMs = 25) {
|
|
78
|
+
const deadline = Date.now() + timeoutMs;
|
|
79
|
+
for (;;) {
|
|
80
|
+
const identity = await readSocketIdentityFile(path);
|
|
81
|
+
if (identity !== undefined)
|
|
82
|
+
return identity;
|
|
83
|
+
if (Date.now() >= deadline)
|
|
84
|
+
return undefined;
|
|
85
|
+
await delayUnrefed(intervalMs);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Unlinks a socket path only while it still refers to the entry `identity`
|
|
90
|
+
* describes. An absent path is nothing to do; a mismatched identity means a
|
|
91
|
+
* newer host owns the name now and is left alone; an unknown identity can
|
|
92
|
+
* never be proven ours, so the path is left and the decision is logged.
|
|
93
|
+
*/
|
|
94
|
+
export async function unlinkOwnedSocket(socketPath, identity, log) {
|
|
95
|
+
if (process.platform === "win32" || socketPath.startsWith("\0"))
|
|
96
|
+
return;
|
|
97
|
+
let current;
|
|
98
|
+
try {
|
|
99
|
+
current = await statSocketIdentity(socketPath);
|
|
100
|
+
}
|
|
101
|
+
catch (cause) {
|
|
102
|
+
log(`socket ${socketPath} ownership could not be verified (${errorMessage(cause)}); leaving it`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (current === undefined)
|
|
106
|
+
return;
|
|
107
|
+
if (identity === undefined) {
|
|
108
|
+
log(`socket path ${socketPath} ownership unknown; leaving it`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!sameSocketIdentity(current, identity)) {
|
|
112
|
+
log(`socket path ${socketPath} now owned by another host; leaving it`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
await unlink(socketPath);
|
|
117
|
+
}
|
|
118
|
+
catch (cause) {
|
|
119
|
+
if (!isNodeErrorCode(cause, "ENOENT")) {
|
|
120
|
+
log(`socket ${socketPath} removal failed (${errorMessage(cause)})`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Runs `close` with the socket path's current entry shielded from libuv's
|
|
126
|
+
* close-time unlink.
|
|
127
|
+
*
|
|
128
|
+
* libuv unlinks the NAME a pipe was bound to when its listening handle
|
|
129
|
+
* closes - even when a takeover has renamed a DIFFERENT socket over that
|
|
130
|
+
* name, so an ordinary `server.close()` silently deletes the newer host's
|
|
131
|
+
* freshly published entry. Moving the current entry aside for the duration
|
|
132
|
+
* of the close (libuv's unlink then hits ENOENT) and restoring it afterwards
|
|
133
|
+
* keeps the filesystem exactly as it was; ownership-checked removal via
|
|
134
|
+
* `unlinkOwnedSocket` decides afterwards what may actually be deleted.
|
|
135
|
+
*/
|
|
136
|
+
export async function shieldSocketDuringClose(socketPath, close) {
|
|
137
|
+
if (process.platform === "win32" || socketPath.startsWith("\0"))
|
|
138
|
+
return close();
|
|
139
|
+
const shieldPath = `${socketPath}.shield-${process.pid}`;
|
|
140
|
+
let shielded = false;
|
|
141
|
+
try {
|
|
142
|
+
if ((await statSocketIdentity(socketPath)) !== undefined) {
|
|
143
|
+
await rename(socketPath, shieldPath);
|
|
144
|
+
shielded = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// Without a shield the close degrades to today's behavior; the
|
|
149
|
+
// ownership-checked unlink still runs afterwards.
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
await close();
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
if (shielded) {
|
|
156
|
+
try {
|
|
157
|
+
await rename(shieldPath, socketPath);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Best effort: a failed restore leaves the entry under the shield
|
|
161
|
+
// name; startup probes treat a dead entry as replaceable.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function delayUnrefed(ms) {
|
|
167
|
+
return new Promise((resolve) => {
|
|
168
|
+
const timer = setTimeout(resolve, ms);
|
|
169
|
+
timer.unref?.();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function errorMessage(cause) {
|
|
173
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
174
|
+
}
|
|
175
|
+
function isNodeErrorCode(cause, code) {
|
|
176
|
+
return cause instanceof Error && "code" in cause && cause.code === code;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMapp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AC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,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":["/**\n * Ownership-checked removal for Unix domain socket path entries.\n *\n * A socket path is a rendezvous name, not a capability: once a host unlinks\n * its entry, any other process may bind the same path. Teardown that removes\n * \"its\" socket by path alone can therefore delete a NEWER host's freshly\n * published entry after a takeover renamed a replacement over that path. The\n * startup path already refuses to touch a socket owned by a live server\n * (`prepareSocketPath`); these helpers give every teardown path the same rule:\n * capture the bound entry's filesystem identity (dev + ino) at listen time and\n * unlink only while the path still stat-matches that identity.\n */\nimport { mkdir, readFile, rename, stat, unlink, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\n\n/** Filesystem identity of one bound socket path entry. */\nexport interface SocketFileIdentity {\n\treadonly dev: number;\n\treadonly ino: number;\n}\n\n/**\n * Name of the sidecar, inside the lifecycle supervisor's private scratch\n * directory, that records which public socket entry that supervisor bound. The\n * directory is per-supervisor, so a replacement supervisor's token can never be\n * mistaken for the old one's.\n */\nexport const PUBLIC_SOCKET_IDENTITY_FILE = \"public-socket.owner\";\n\n/** Default bound on waiting for a supervisor to publish its ownership token. */\nexport const SOCKET_IDENTITY_WAIT_MS = 30_000;\n\nfunction sameSocketIdentity(a: SocketFileIdentity, b: SocketFileIdentity): boolean {\n\treturn a.dev === b.dev && a.ino === b.ino;\n}\n\n/** Reads the current identity of a socket path entry; `undefined` once absent. */\nexport async function statSocketIdentity(socketPath: string): Promise<SocketFileIdentity | undefined> {\n\ttry {\n\t\tconst { dev, ino } = await stat(socketPath);\n\t\treturn { dev, ino };\n\t} catch (cause) {\n\t\tif (isNodeErrorCode(cause, \"ENOENT\")) return undefined;\n\t\tthrow cause;\n\t}\n}\n\n/** Records a bound socket identity for teardown paths that cannot hold it in memory. */\nexport async function writeSocketIdentityFile(path: string, identity: SocketFileIdentity): Promise<void> {\n\tawait mkdir(dirname(path), { recursive: true, mode: 0o700 });\n\tconst tmpPath = `${path}.${process.pid}.tmp`;\n\tawait writeFile(tmpPath, `${JSON.stringify(identity)}\\n`, { mode: 0o600 });\n\tawait rename(tmpPath, path);\n}\n\nexport async function readSocketIdentityFile(path: string): Promise<SocketFileIdentity | undefined> {\n\tlet raw: string;\n\ttry {\n\t\traw = await readFile(path, \"utf8\");\n\t} catch (cause) {\n\t\tif (isNodeErrorCode(cause, \"ENOENT\")) return undefined;\n\t\tthrow cause;\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\t// Truncated or in-progress JSON is not a token: callers wait or leave the path.\n\t\treturn undefined;\n\t}\n\tif (\n\t\ttypeof parsed !== \"object\" ||\n\t\tparsed === null ||\n\t\ttypeof (parsed as { dev?: unknown }).dev !== \"number\" ||\n\t\ttypeof (parsed as { ino?: unknown }).ino !== \"number\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn { dev: (parsed as { dev: number }).dev, ino: (parsed as { ino: number }).ino };\n}\n\n/**\n * Waits, bounded, for an identity file to appear. The lifecycle supervisor\n * publishes its public-socket token after this host's internal listener is\n * ready, so supervised hosts poll briefly instead of assuming ordering.\n */\nexport async function waitForSocketIdentityFile(\n\tpath: string,\n\ttimeoutMs: number = SOCKET_IDENTITY_WAIT_MS,\n\tintervalMs = 25,\n): Promise<SocketFileIdentity | undefined> {\n\tconst deadline = Date.now() + timeoutMs;\n\tfor (;;) {\n\t\tconst identity = await readSocketIdentityFile(path);\n\t\tif (identity !== undefined) return identity;\n\t\tif (Date.now() >= deadline) return undefined;\n\t\tawait delayUnrefed(intervalMs);\n\t}\n}\n\n/**\n * Unlinks a socket path only while it still refers to the entry `identity`\n * describes. An absent path is nothing to do; a mismatched identity means a\n * newer host owns the name now and is left alone; an unknown identity can\n * never be proven ours, so the path is left and the decision is logged.\n */\nexport async function unlinkOwnedSocket(\n\tsocketPath: string,\n\tidentity: SocketFileIdentity | undefined,\n\tlog: (message: string) => void,\n): Promise<void> {\n\tif (process.platform === \"win32\" || socketPath.startsWith(\"\\0\")) return;\n\tlet current: SocketFileIdentity | undefined;\n\ttry {\n\t\tcurrent = await statSocketIdentity(socketPath);\n\t} catch (cause) {\n\t\tlog(`socket ${socketPath} ownership could not be verified (${errorMessage(cause)}); leaving it`);\n\t\treturn;\n\t}\n\tif (current === undefined) return;\n\tif (identity === undefined) {\n\t\tlog(`socket path ${socketPath} ownership unknown; leaving it`);\n\t\treturn;\n\t}\n\tif (!sameSocketIdentity(current, identity)) {\n\t\tlog(`socket path ${socketPath} now owned by another host; leaving it`);\n\t\treturn;\n\t}\n\ttry {\n\t\tawait unlink(socketPath);\n\t} catch (cause) {\n\t\tif (!isNodeErrorCode(cause, \"ENOENT\")) {\n\t\t\tlog(`socket ${socketPath} removal failed (${errorMessage(cause)})`);\n\t\t}\n\t}\n}\n\n/**\n * Runs `close` with the socket path's current entry shielded from libuv's\n * close-time unlink.\n *\n * libuv unlinks the NAME a pipe was bound to when its listening handle\n * closes - even when a takeover has renamed a DIFFERENT socket over that\n * name, so an ordinary `server.close()` silently deletes the newer host's\n * freshly published entry. Moving the current entry aside for the duration\n * of the close (libuv's unlink then hits ENOENT) and restoring it afterwards\n * keeps the filesystem exactly as it was; ownership-checked removal via\n * `unlinkOwnedSocket` decides afterwards what may actually be deleted.\n */\nexport async function shieldSocketDuringClose(socketPath: string, close: () => Promise<void>): Promise<void> {\n\tif (process.platform === \"win32\" || socketPath.startsWith(\"\\0\")) return close();\n\tconst shieldPath = `${socketPath}.shield-${process.pid}`;\n\tlet shielded = false;\n\ttry {\n\t\tif ((await statSocketIdentity(socketPath)) !== undefined) {\n\t\t\tawait rename(socketPath, shieldPath);\n\t\t\tshielded = true;\n\t\t}\n\t} catch {\n\t\t// Without a shield the close degrades to today's behavior; the\n\t\t// ownership-checked unlink still runs afterwards.\n\t}\n\ttry {\n\t\tawait close();\n\t} finally {\n\t\tif (shielded) {\n\t\t\ttry {\n\t\t\t\tawait rename(shieldPath, socketPath);\n\t\t\t} catch {\n\t\t\t\t// Best effort: a failed restore leaves the entry under the shield\n\t\t\t\t// name; startup probes treat a dead entry as replaceable.\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction delayUnrefed(ms: number): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tconst timer = setTimeout(resolve, ms);\n\t\ttimer.unref?.();\n\t});\n}\n\nfunction errorMessage(cause: unknown): string {\n\treturn cause instanceof Error ? cause.message : String(cause);\n}\n\nfunction isNodeErrorCode(cause: unknown, code: string): boolean {\n\treturn cause instanceof Error && \"code\" in cause && cause.code === code;\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CliRuntimeConfiguration } from "../../main.ts";
|
|
2
|
+
import { type OpenRpcSession, type RpcSessionEntry, type RpcSessionLaunchProfile } from "./session-registry.ts";
|
|
3
|
+
/** Transport-side lifecycle owner. Caller paths are never inspected on this event loop. */
|
|
4
|
+
export declare class WorkerSessionRegistry {
|
|
5
|
+
private readonly entries;
|
|
6
|
+
private readonly reservations;
|
|
7
|
+
private serial;
|
|
8
|
+
readonly closeGraceMs: number;
|
|
9
|
+
private readonly now;
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options: {
|
|
12
|
+
configuration: CliRuntimeConfiguration;
|
|
13
|
+
closeGraceMs: number;
|
|
14
|
+
now: () => number;
|
|
15
|
+
});
|
|
16
|
+
get size(): number;
|
|
17
|
+
openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession>;
|
|
18
|
+
peek(handle: string): RpcSessionEntry | undefined;
|
|
19
|
+
getForCommand(handle: string, command: string): RpcSessionEntry;
|
|
20
|
+
beginClose(handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry;
|
|
21
|
+
close(handle: string): Promise<void>;
|
|
22
|
+
closeMarked(handle: string): Promise<void>;
|
|
23
|
+
list(): Array<{
|
|
24
|
+
sessionId: string;
|
|
25
|
+
durableSessionId?: string;
|
|
26
|
+
sessionPath?: string;
|
|
27
|
+
cwd: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
status: Exclude<RpcSessionEntry["state"], "quarantined">;
|
|
30
|
+
}>;
|
|
31
|
+
/** Only compare spellings already tied to a granted identity; do not inspect caller paths here. */
|
|
32
|
+
private knownReservationKey;
|
|
33
|
+
private attach;
|
|
34
|
+
private reserve;
|
|
35
|
+
private openResult;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=worker-session-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-session-registry.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/worker-session-registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAE5B,MAAM,uBAAuB,CAAC;AAI/B,2FAA2F;AAC3F,qBAAa,qBAAqB;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAC9D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA6B;IAC1D,OAAO,CAAC,MAAM,CAAK;IACnB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IAEnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsF;gBAElG,OAAO,EAAE;QAAE,aAAa,EAAE,uBAAuB,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,MAAM,CAAA;KAAE;IAMxG,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEK,WAAW,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,cAAc,CAAC;IA4D5E,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIjD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe;IAa/D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,eAAe;IAkBlF,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBhD,IAAI,IAAI,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC;KACzD,CAAC;IAcF,mGAAmG;IACnG,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,UAAU;CAKlB"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { ProviderScope } from "@earendil-works/pi-ai/node/provider-scope";
|
|
3
|
+
import { RpcSessionRegistryError, } from "./session-registry.js";
|
|
4
|
+
import { SessionWorkerClient } from "./session-worker-client.js";
|
|
5
|
+
import { SESSION_WORKER_LIMITS } from "./session-worker-protocol.js";
|
|
6
|
+
/** Transport-side lifecycle owner. Caller paths are never inspected on this event loop. */
|
|
7
|
+
export class WorkerSessionRegistry {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.entries = new Map();
|
|
10
|
+
this.reservations = new Map();
|
|
11
|
+
this.serial = 0;
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.closeGraceMs = options.closeGraceMs;
|
|
14
|
+
this.now = options.now;
|
|
15
|
+
}
|
|
16
|
+
get size() {
|
|
17
|
+
return this.entries.size;
|
|
18
|
+
}
|
|
19
|
+
async openSession(profile) {
|
|
20
|
+
if (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath)))
|
|
21
|
+
throw new RpcSessionRegistryError("invalid_path");
|
|
22
|
+
if (profile.sessionPath) {
|
|
23
|
+
const key = this.knownReservationKey(profile.sessionPath);
|
|
24
|
+
const owner = key ? this.reservations.get(key) : undefined;
|
|
25
|
+
if (key && owner)
|
|
26
|
+
return this.attach(owner, key);
|
|
27
|
+
}
|
|
28
|
+
if (this.size >= SESSION_WORKER_LIMITS.workers)
|
|
29
|
+
throw new Error("too_many_sessions");
|
|
30
|
+
const handle = `rpc-${++this.serial}`;
|
|
31
|
+
const entry = {
|
|
32
|
+
state: "opening",
|
|
33
|
+
scope: new ProviderScope(),
|
|
34
|
+
profile: Object.freeze({ ...profile }),
|
|
35
|
+
cwd: profile.cwd,
|
|
36
|
+
attachments: 1,
|
|
37
|
+
lastCommandAt: this.now(),
|
|
38
|
+
lifecycleMutex: Promise.resolve(),
|
|
39
|
+
};
|
|
40
|
+
const worker = new SessionWorkerClient({
|
|
41
|
+
reserve: (path) => this.reserve(handle, path),
|
|
42
|
+
exit: () => {
|
|
43
|
+
if (this.entries.get(handle) !== entry)
|
|
44
|
+
return;
|
|
45
|
+
entry.state = "closed";
|
|
46
|
+
this.entries.delete(handle);
|
|
47
|
+
for (const [path, owner] of this.reservations)
|
|
48
|
+
if (owner === handle)
|
|
49
|
+
this.reservations.delete(path);
|
|
50
|
+
entry.closeResolve?.();
|
|
51
|
+
},
|
|
52
|
+
failure: (error) => {
|
|
53
|
+
entry.state = "quarantined";
|
|
54
|
+
process.stderr.write(`senpi rpc session ${handle} quarantined: ${error}\n`);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
entry.worker = worker;
|
|
58
|
+
this.entries.set(handle, entry);
|
|
59
|
+
try {
|
|
60
|
+
const path = await worker.prepare(this.options.configuration, profile);
|
|
61
|
+
const owner = this.reservations.get(path);
|
|
62
|
+
if (owner) {
|
|
63
|
+
const attached = this.attach(owner, path);
|
|
64
|
+
entry.state = "quarantined";
|
|
65
|
+
worker.quarantine();
|
|
66
|
+
return attached;
|
|
67
|
+
}
|
|
68
|
+
if (!this.reserve(handle, path))
|
|
69
|
+
throw new RpcSessionRegistryError("session_path_in_use");
|
|
70
|
+
entry.reservationKey = path;
|
|
71
|
+
entry.sessionPath = path;
|
|
72
|
+
const snapshot = await worker.commit();
|
|
73
|
+
if (entry.state !== "opening")
|
|
74
|
+
throw new RpcSessionRegistryError("session_closing");
|
|
75
|
+
entry.durableSessionId = snapshot.state.sessionId;
|
|
76
|
+
entry.cwd = snapshot.state.cwd;
|
|
77
|
+
entry.state = "open";
|
|
78
|
+
return this.openResult(handle, entry);
|
|
79
|
+
}
|
|
80
|
+
catch (cause) {
|
|
81
|
+
entry.state = "quarantined";
|
|
82
|
+
worker.quarantine();
|
|
83
|
+
throw cause;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
peek(handle) {
|
|
87
|
+
return this.entries.get(handle);
|
|
88
|
+
}
|
|
89
|
+
getForCommand(handle, command) {
|
|
90
|
+
const entry = this.entries.get(handle);
|
|
91
|
+
if (!entry)
|
|
92
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
93
|
+
if (entry.state === "quarantined" ||
|
|
94
|
+
(entry.state === "closing" && !["abort", "abort_bash", "extension_ui_response"].includes(command)))
|
|
95
|
+
throw new RpcSessionRegistryError("session_closing");
|
|
96
|
+
if (entry.state !== "open" && entry.state !== "closing")
|
|
97
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
98
|
+
entry.lastCommandAt = this.now();
|
|
99
|
+
return entry;
|
|
100
|
+
}
|
|
101
|
+
beginClose(handle, onRole) {
|
|
102
|
+
const entry = this.entries.get(handle);
|
|
103
|
+
if (!entry)
|
|
104
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
105
|
+
if (entry.state === "closing" || entry.state === "quarantined") {
|
|
106
|
+
onRole?.(false);
|
|
107
|
+
return entry;
|
|
108
|
+
}
|
|
109
|
+
if (entry.state !== "open" && entry.state !== "opening")
|
|
110
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
111
|
+
entry.attachments--;
|
|
112
|
+
if (entry.attachments > 0)
|
|
113
|
+
return entry;
|
|
114
|
+
entry.state = "closing";
|
|
115
|
+
entry.closeCompletion = new Promise((resolve) => {
|
|
116
|
+
entry.closeResolve = resolve;
|
|
117
|
+
});
|
|
118
|
+
onRole?.(true);
|
|
119
|
+
return entry;
|
|
120
|
+
}
|
|
121
|
+
close(handle) {
|
|
122
|
+
const entry = this.beginClose(handle);
|
|
123
|
+
return entry.state === "closing" ? this.closeMarked(handle) : Promise.resolve();
|
|
124
|
+
}
|
|
125
|
+
async closeMarked(handle) {
|
|
126
|
+
const entry = this.entries.get(handle);
|
|
127
|
+
if (entry?.state !== "closing" || !entry.worker)
|
|
128
|
+
throw new RpcSessionRegistryError("unknown_session");
|
|
129
|
+
if (entry.closeStarted)
|
|
130
|
+
return entry.closeCompletion;
|
|
131
|
+
entry.closeStarted = true;
|
|
132
|
+
// Reply on a bounded deadline, but keep entry, attachments and reservations until exit.
|
|
133
|
+
let timer;
|
|
134
|
+
await Promise.race([
|
|
135
|
+
entry.worker.close(this.closeGraceMs),
|
|
136
|
+
new Promise((resolve) => {
|
|
137
|
+
timer = setTimeout(() => {
|
|
138
|
+
if (entry.state !== "closed")
|
|
139
|
+
entry.state = "quarantined";
|
|
140
|
+
resolve();
|
|
141
|
+
}, this.closeGraceMs);
|
|
142
|
+
}),
|
|
143
|
+
]);
|
|
144
|
+
if (timer)
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
}
|
|
147
|
+
list() {
|
|
148
|
+
return [...this.entries].map(([sessionId, entry]) => {
|
|
149
|
+
const state = entry.worker?.snapshot?.state;
|
|
150
|
+
return {
|
|
151
|
+
sessionId,
|
|
152
|
+
durableSessionId: state?.sessionId ?? entry.durableSessionId,
|
|
153
|
+
sessionPath: state?.sessionFile ?? entry.sessionPath,
|
|
154
|
+
cwd: state?.cwd ?? entry.cwd,
|
|
155
|
+
name: state?.sessionName,
|
|
156
|
+
status: entry.state === "quarantined" ? "closing" : entry.state,
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** Only compare spellings already tied to a granted identity; do not inspect caller paths here. */
|
|
161
|
+
knownReservationKey(path) {
|
|
162
|
+
if (this.reservations.has(path))
|
|
163
|
+
return path;
|
|
164
|
+
for (const entry of this.entries.values()) {
|
|
165
|
+
if (entry.profile.sessionPath === path && entry.reservationKey)
|
|
166
|
+
return entry.reservationKey;
|
|
167
|
+
const snapshot = entry.worker?.snapshot;
|
|
168
|
+
if (snapshot?.state.sessionFile === path)
|
|
169
|
+
return snapshot.sessionPath;
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
attach(owner, path) {
|
|
174
|
+
const entry = this.entries.get(owner);
|
|
175
|
+
if (entry?.state !== "open" || !entry.worker?.bindingReady || entry.worker.snapshot?.sessionPath !== path)
|
|
176
|
+
throw new RpcSessionRegistryError("session_path_in_use");
|
|
177
|
+
const result = this.openResult(owner, entry);
|
|
178
|
+
entry.attachments++;
|
|
179
|
+
entry.lastCommandAt = this.now();
|
|
180
|
+
return { ...result, attached: true };
|
|
181
|
+
}
|
|
182
|
+
reserve(handle, path) {
|
|
183
|
+
const entry = this.entries.get(handle);
|
|
184
|
+
if (!entry)
|
|
185
|
+
return false;
|
|
186
|
+
const owner = this.reservations.get(path);
|
|
187
|
+
if (owner)
|
|
188
|
+
return owner === handle;
|
|
189
|
+
if (entry.state !== "opening" && entry.state !== "open")
|
|
190
|
+
return false;
|
|
191
|
+
let count = 0;
|
|
192
|
+
for (const current of this.reservations.values())
|
|
193
|
+
if (current === handle)
|
|
194
|
+
count++;
|
|
195
|
+
if (count >= SESSION_WORKER_LIMITS.reservations)
|
|
196
|
+
return false;
|
|
197
|
+
this.reservations.set(path, handle);
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
openResult(handle, entry) {
|
|
201
|
+
const state = entry.worker?.snapshot?.state;
|
|
202
|
+
if (!state)
|
|
203
|
+
throw new RpcSessionRegistryError("open_failed");
|
|
204
|
+
return { sessionId: handle, durableSessionId: state.sessionId, sessionPath: state.sessionFile };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=worker-session-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-session-registry.js","sourceRoot":"","sources":["../../../src/modes/rpc/worker-session-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAE1E,OAAO,EAIN,uBAAuB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,2FAA2F;AAC3F,MAAM,OAAO,qBAAqB;IASjC,YAAY,OAA4F;QARvF,YAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;QAC7C,iBAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;QAClD,WAAM,GAAG,CAAC,CAAC;QAOlB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAgC;QACjD,IA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["import { isAbsolute } from \"node:path\";\nimport { ProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport type { CliRuntimeConfiguration } from \"../../main.ts\";\nimport {\n\ttype OpenRpcSession,\n\ttype RpcSessionEntry,\n\ttype RpcSessionLaunchProfile,\n\tRpcSessionRegistryError,\n} from \"./session-registry.ts\";\nimport { SessionWorkerClient } from \"./session-worker-client.ts\";\nimport { SESSION_WORKER_LIMITS } from \"./session-worker-protocol.ts\";\n\n/** Transport-side lifecycle owner. Caller paths are never inspected on this event loop. */\nexport class WorkerSessionRegistry {\n\tprivate readonly entries = new Map<string, RpcSessionEntry>();\n\tprivate readonly reservations = new Map<string, string>();\n\tprivate serial = 0;\n\treadonly closeGraceMs: number;\n\tprivate readonly now: () => number;\n\n\tprivate readonly options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number };\n\n\tconstructor(options: { configuration: CliRuntimeConfiguration; closeGraceMs: number; now: () => number }) {\n\t\tthis.options = options;\n\t\tthis.closeGraceMs = options.closeGraceMs;\n\t\tthis.now = options.now;\n\t}\n\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\tasync openSession(profile: RpcSessionLaunchProfile): Promise<OpenRpcSession> {\n\t\tif (!isAbsolute(profile.cwd) || (profile.sessionPath !== undefined && !isAbsolute(profile.sessionPath)))\n\t\t\tthrow new RpcSessionRegistryError(\"invalid_path\");\n\t\tif (profile.sessionPath) {\n\t\t\tconst key = this.knownReservationKey(profile.sessionPath);\n\t\t\tconst owner = key ? this.reservations.get(key) : undefined;\n\t\t\tif (key && owner) return this.attach(owner, key);\n\t\t}\n\t\tif (this.size >= SESSION_WORKER_LIMITS.workers) throw new Error(\"too_many_sessions\");\n\t\tconst handle = `rpc-${++this.serial}`;\n\t\tconst entry: RpcSessionEntry = {\n\t\t\tstate: \"opening\",\n\t\t\tscope: new ProviderScope(),\n\t\t\tprofile: Object.freeze({ ...profile }),\n\t\t\tcwd: profile.cwd,\n\t\t\tattachments: 1,\n\t\t\tlastCommandAt: this.now(),\n\t\t\tlifecycleMutex: Promise.resolve(),\n\t\t};\n\t\tconst worker = new SessionWorkerClient({\n\t\t\treserve: (path) => this.reserve(handle, path),\n\t\t\texit: () => {\n\t\t\t\tif (this.entries.get(handle) !== entry) return;\n\t\t\t\tentry.state = \"closed\";\n\t\t\t\tthis.entries.delete(handle);\n\t\t\t\tfor (const [path, owner] of this.reservations) if (owner === handle) this.reservations.delete(path);\n\t\t\t\tentry.closeResolve?.();\n\t\t\t},\n\t\t\tfailure: (error) => {\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tprocess.stderr.write(`senpi rpc session ${handle} quarantined: ${error}\\n`);\n\t\t\t},\n\t\t});\n\t\tentry.worker = worker;\n\t\tthis.entries.set(handle, entry);\n\t\ttry {\n\t\t\tconst path = await worker.prepare(this.options.configuration, profile);\n\t\t\tconst owner = this.reservations.get(path);\n\t\t\tif (owner) {\n\t\t\t\tconst attached = this.attach(owner, path);\n\t\t\t\tentry.state = \"quarantined\";\n\t\t\t\tworker.quarantine();\n\t\t\t\treturn attached;\n\t\t\t}\n\t\t\tif (!this.reserve(handle, path)) throw new RpcSessionRegistryError(\"session_path_in_use\");\n\t\t\tentry.reservationKey = path;\n\t\t\tentry.sessionPath = path;\n\t\t\tconst snapshot = await worker.commit();\n\t\t\tif (entry.state !== \"opening\") throw new RpcSessionRegistryError(\"session_closing\");\n\t\t\tentry.durableSessionId = snapshot.state.sessionId;\n\t\t\tentry.cwd = snapshot.state.cwd;\n\t\t\tentry.state = \"open\";\n\t\t\treturn this.openResult(handle, entry);\n\t\t} catch (cause) {\n\t\t\tentry.state = \"quarantined\";\n\t\t\tworker.quarantine();\n\t\t\tthrow cause;\n\t\t}\n\t}\n\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 (\n\t\t\tentry.state === \"quarantined\" ||\n\t\t\t(entry.state === \"closing\" && ![\"abort\", \"abort_bash\", \"extension_ui_response\"].includes(command))\n\t\t)\n\t\t\tthrow new RpcSessionRegistryError(\"session_closing\");\n\t\tif (entry.state !== \"open\" && entry.state !== \"closing\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.lastCommandAt = this.now();\n\t\treturn entry;\n\t}\n\n\tbeginClose(handle: string, onRole?: (finalizer: boolean) => void): RpcSessionEntry {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.state === \"closing\" || entry.state === \"quarantined\") {\n\t\t\tonRole?.(false);\n\t\t\treturn entry;\n\t\t}\n\t\tif (entry.state !== \"open\" && entry.state !== \"opening\") throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tentry.attachments--;\n\t\tif (entry.attachments > 0) return entry;\n\t\tentry.state = \"closing\";\n\t\tentry.closeCompletion = new Promise((resolve) => {\n\t\t\tentry.closeResolve = resolve;\n\t\t});\n\t\tonRole?.(true);\n\t\treturn entry;\n\t}\n\n\tclose(handle: string): Promise<void> {\n\t\tconst entry = this.beginClose(handle);\n\t\treturn entry.state === \"closing\" ? this.closeMarked(handle) : Promise.resolve();\n\t}\n\n\tasync closeMarked(handle: string): Promise<void> {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (entry?.state !== \"closing\" || !entry.worker) throw new RpcSessionRegistryError(\"unknown_session\");\n\t\tif (entry.closeStarted) return entry.closeCompletion;\n\t\tentry.closeStarted = true;\n\t\t// Reply on a bounded deadline, but keep entry, attachments and reservations until exit.\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tawait Promise.race([\n\t\t\tentry.worker.close(this.closeGraceMs),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tif (entry.state !== \"closed\") entry.state = \"quarantined\";\n\t\t\t\t\tresolve();\n\t\t\t\t}, this.closeGraceMs);\n\t\t\t}),\n\t\t]);\n\t\tif (timer) clearTimeout(timer);\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: Exclude<RpcSessionEntry[\"state\"], \"quarantined\">;\n\t}> {\n\t\treturn [...this.entries].map(([sessionId, entry]) => {\n\t\t\tconst state = entry.worker?.snapshot?.state;\n\t\t\treturn {\n\t\t\t\tsessionId,\n\t\t\t\tdurableSessionId: state?.sessionId ?? entry.durableSessionId,\n\t\t\t\tsessionPath: state?.sessionFile ?? entry.sessionPath,\n\t\t\t\tcwd: state?.cwd ?? entry.cwd,\n\t\t\t\tname: state?.sessionName,\n\t\t\t\tstatus: entry.state === \"quarantined\" ? \"closing\" : entry.state,\n\t\t\t};\n\t\t});\n\t}\n\n\t/** Only compare spellings already tied to a granted identity; do not inspect caller paths here. */\n\tprivate knownReservationKey(path: string): string | undefined {\n\t\tif (this.reservations.has(path)) return path;\n\t\tfor (const entry of this.entries.values()) {\n\t\t\tif (entry.profile.sessionPath === path && entry.reservationKey) return entry.reservationKey;\n\t\t\tconst snapshot = entry.worker?.snapshot;\n\t\t\tif (snapshot?.state.sessionFile === path) return snapshot.sessionPath;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate attach(owner: string, path: string): OpenRpcSession {\n\t\tconst entry = this.entries.get(owner);\n\t\tif (entry?.state !== \"open\" || !entry.worker?.bindingReady || entry.worker.snapshot?.sessionPath !== path)\n\t\t\tthrow new RpcSessionRegistryError(\"session_path_in_use\");\n\t\tconst result = this.openResult(owner, entry);\n\t\tentry.attachments++;\n\t\tentry.lastCommandAt = this.now();\n\t\treturn { ...result, attached: true };\n\t}\n\n\tprivate reserve(handle: string, path: string): boolean {\n\t\tconst entry = this.entries.get(handle);\n\t\tif (!entry) return false;\n\t\tconst owner = this.reservations.get(path);\n\t\tif (owner) return owner === handle;\n\t\tif (entry.state !== \"opening\" && entry.state !== \"open\") return false;\n\t\tlet count = 0;\n\t\tfor (const current of this.reservations.values()) if (current === handle) count++;\n\t\tif (count >= SESSION_WORKER_LIMITS.reservations) return false;\n\t\tthis.reservations.set(path, handle);\n\t\treturn true;\n\t}\n\n\tprivate openResult(handle: string, entry: RpcSessionEntry): OpenRpcSession {\n\t\tconst state = entry.worker?.snapshot?.state;\n\t\tif (!state) throw new RpcSessionRegistryError(\"open_failed\");\n\t\treturn { sessionId: handle, durableSessionId: state.sessionId, sessionPath: state.sessionFile };\n\t}\n}\n"]}
|
package/dist/utils/fs-watch.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { type FSWatcher, type WatchListener, type WatchOptions } from "node:fs";
|
|
2
2
|
export declare const FS_WATCH_RETRY_DELAY_MS = 5000;
|
|
3
3
|
export declare function closeWatcher(watcher: FSWatcher | null | undefined): void;
|
|
4
|
+
/**
|
|
5
|
+
* The path to hand to `fs.watch`. On Windows libuv aborts the whole process when a directory
|
|
6
|
+
* watch is created through a non-canonical (8.3 short-name) path (issue #1229), so the canonical
|
|
7
|
+
* form is looked up there. Elsewhere the caller's path is used as-is: POSIX realpath opens every
|
|
8
|
+
* directory it resolves, which blocks forever on a wedged autofs trigger, and fs.watch does not
|
|
9
|
+
* need the canonical form on those platforms.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canonicalWatchPath(path: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Prove that a directory can be opened before a synchronous `fs.watch` touches it. The watcher
|
|
14
|
+
* opens the directory on the calling thread; on a wedged mount (a macOS autofs trigger whose
|
|
15
|
+
* automounter never answers) that open never returns and would block the host main thread. This
|
|
16
|
+
* probe performs the same open on the async pool, so a caller can bound it with a deadline. It
|
|
17
|
+
* rejects with the open error (for example EACCES on an execute-only directory, which fs.watch
|
|
18
|
+
* would refuse as well).
|
|
19
|
+
*/
|
|
20
|
+
export declare function probeDirectoryOpenable(directory: string): Promise<void>;
|
|
4
21
|
export declare function watchWithErrorHandler(path: string, listener: WatchListener<string>, onError: () => void, options?: WatchOptions): FSWatcher | null;
|
|
5
22
|
//# sourceMappingURL=fs-watch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-watch.d.ts","sourceRoot":"","sources":["../../src/utils/fs-watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAS,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fs-watch.d.ts","sourceRoot":"","sources":["../../src/utils/fs-watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAS,MAAM,SAAS,CAAC;AAGrG,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAUxE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ7E;AAED,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAC/B,OAAO,EAAE,MAAM,IAAI,EACnB,OAAO,CAAC,EAAE,YAAY,GACpB,SAAS,GAAG,IAAI,CASlB"}
|
package/dist/utils/fs-watch.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { realpathSync, watch } from "node:fs";
|
|
2
|
+
import { opendir } from "node:fs/promises";
|
|
2
3
|
export const FS_WATCH_RETRY_DELAY_MS = 5000;
|
|
3
4
|
export function closeWatcher(watcher) {
|
|
4
5
|
if (!watcher) {
|
|
@@ -11,18 +12,45 @@ export function closeWatcher(watcher) {
|
|
|
11
12
|
// Ignore watcher close errors
|
|
12
13
|
}
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The path to hand to `fs.watch`. On Windows libuv aborts the whole process when a directory
|
|
17
|
+
* watch is created through a non-canonical (8.3 short-name) path (issue #1229), so the canonical
|
|
18
|
+
* form is looked up there. Elsewhere the caller's path is used as-is: POSIX realpath opens every
|
|
19
|
+
* directory it resolves, which blocks forever on a wedged autofs trigger, and fs.watch does not
|
|
20
|
+
* need the canonical form on those platforms.
|
|
21
|
+
*/
|
|
22
|
+
export function canonicalWatchPath(path) {
|
|
23
|
+
if (process.platform !== "win32")
|
|
24
|
+
return path;
|
|
25
|
+
try {
|
|
26
|
+
return realpathSync.native(path);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Keep the raw path when it does not exist yet.
|
|
30
|
+
return path;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Prove that a directory can be opened before a synchronous `fs.watch` touches it. The watcher
|
|
35
|
+
* opens the directory on the calling thread; on a wedged mount (a macOS autofs trigger whose
|
|
36
|
+
* automounter never answers) that open never returns and would block the host main thread. This
|
|
37
|
+
* probe performs the same open on the async pool, so a caller can bound it with a deadline. It
|
|
38
|
+
* rejects with the open error (for example EACCES on an execute-only directory, which fs.watch
|
|
39
|
+
* would refuse as well).
|
|
40
|
+
*/
|
|
41
|
+
export async function probeDirectoryOpenable(directory) {
|
|
42
|
+
const handle = await opendir(directory);
|
|
43
|
+
try {
|
|
44
|
+
// Bun opens the directory lazily on the first read; Node opens it in opendir itself.
|
|
45
|
+
await handle.read();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await handle.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
14
51
|
export function watchWithErrorHandler(path, listener, onError, options) {
|
|
15
52
|
try {
|
|
16
|
-
|
|
17
|
-
if (process.platform === "win32") {
|
|
18
|
-
try {
|
|
19
|
-
watchPath = realpathSync.native(path);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
// Keep the raw path when it does not exist yet.
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const watcher = watch(watchPath, { ...options, encoding: "utf8" }, listener);
|
|
53
|
+
const watcher = watch(canonicalWatchPath(path), { ...options, encoding: "utf8" }, listener);
|
|
26
54
|
watcher.on("error", onError);
|
|
27
55
|
return watcher;
|
|
28
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-watch.js","sourceRoot":"","sources":["../../src/utils/fs-watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAyC,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fs-watch.js","sourceRoot":"","sources":["../../src/utils/fs-watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAyC,KAAK,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C,MAAM,UAAU,YAAY,CAAC,OAAqC;IACjE,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO;IACR,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACR,8BAA8B;IAC/B,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC9C,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IAC9C,IAAI,CAAC;QACJ,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACR,gDAAgD;QAChD,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,SAAiB;IAC7D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC;QACJ,qFAAqF;QACrF,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;YAAS,CAAC;QACV,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,QAA+B,EAC/B,OAAmB,EACnB,OAAsB;IAEtB,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC5F,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["import { type FSWatcher, realpathSync, type WatchListener, type WatchOptions, watch } from \"node:fs\";\nimport { opendir } from \"node:fs/promises\";\n\nexport const FS_WATCH_RETRY_DELAY_MS = 5000;\n\nexport function closeWatcher(watcher: FSWatcher | null | undefined): void {\n\tif (!watcher) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\twatcher.close();\n\t} catch {\n\t\t// Ignore watcher close errors\n\t}\n}\n\n/**\n * The path to hand to `fs.watch`. On Windows libuv aborts the whole process when a directory\n * watch is created through a non-canonical (8.3 short-name) path (issue #1229), so the canonical\n * form is looked up there. Elsewhere the caller's path is used as-is: POSIX realpath opens every\n * directory it resolves, which blocks forever on a wedged autofs trigger, and fs.watch does not\n * need the canonical form on those platforms.\n */\nexport function canonicalWatchPath(path: string): string {\n\tif (process.platform !== \"win32\") return path;\n\ttry {\n\t\treturn realpathSync.native(path);\n\t} catch {\n\t\t// Keep the raw path when it does not exist yet.\n\t\treturn path;\n\t}\n}\n\n/**\n * Prove that a directory can be opened before a synchronous `fs.watch` touches it. The watcher\n * opens the directory on the calling thread; on a wedged mount (a macOS autofs trigger whose\n * automounter never answers) that open never returns and would block the host main thread. This\n * probe performs the same open on the async pool, so a caller can bound it with a deadline. It\n * rejects with the open error (for example EACCES on an execute-only directory, which fs.watch\n * would refuse as well).\n */\nexport async function probeDirectoryOpenable(directory: string): Promise<void> {\n\tconst handle = await opendir(directory);\n\ttry {\n\t\t// Bun opens the directory lazily on the first read; Node opens it in opendir itself.\n\t\tawait handle.read();\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nexport function watchWithErrorHandler(\n\tpath: string,\n\tlistener: WatchListener<string>,\n\tonError: () => void,\n\toptions?: WatchOptions,\n): FSWatcher | null {\n\ttry {\n\t\tconst watcher = watch(canonicalWatchPath(path), { ...options, encoding: \"utf8\" }, listener);\n\t\twatcher.on(\"error\", onError);\n\t\treturn watcher;\n\t} catch {\n\t\tonError();\n\t\treturn null;\n\t}\n}\n"]}
|
package/dist/utils/paths.d.ts
CHANGED
|
@@ -17,6 +17,39 @@ export interface PathInputOptions {
|
|
|
17
17
|
* entries.
|
|
18
18
|
*/
|
|
19
19
|
export declare function canonicalizePath(path: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* {@link canonicalizePath} that refuses to guess.
|
|
22
|
+
*
|
|
23
|
+
* The convenience form hands back its input when resolution fails, which is what most callers
|
|
24
|
+
* want: they compare two canonical spellings and an unresolvable path simply compares unequal.
|
|
25
|
+
* A security decision cannot use that, because the raw input is indistinguishable from a
|
|
26
|
+
* canonical answer - so a path that could not be resolved would be keyed, compared, or trusted
|
|
27
|
+
* under a spelling the filesystem never confirmed. This form throws instead, leaving the caller
|
|
28
|
+
* to decide what an unresolvable path means.
|
|
29
|
+
*/
|
|
30
|
+
export declare function canonicalizePathStrict(path: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve symlinks without ever open(2)-ing a component, tolerating every error.
|
|
33
|
+
*
|
|
34
|
+
* Bun's `fs.realpath*` opens every directory it resolves, so an autofs trigger such as macOS
|
|
35
|
+
* `/home` blocks the calling thread (on the host main thread that freezes the TUI) and an
|
|
36
|
+
* execute-only directory fails with EACCES; lstat needs only search permission and never mounts
|
|
37
|
+
* anything. Components from the first unresolvable one onward are kept verbatim, so a file that
|
|
38
|
+
* does not exist yet still lands where its symlinked parent points.
|
|
39
|
+
*
|
|
40
|
+
* Never throws, so the resolved path may be incomplete. Use it where an approximate answer is
|
|
41
|
+
* better than a blocked thread — the external-path classifier and the monitor parent identity —
|
|
42
|
+
* and use {@link realpathWithoutOpenStrict} where an incomplete answer must not be trusted.
|
|
43
|
+
*/
|
|
44
|
+
export declare function realpathWithoutOpen(inputPath: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* {@link realpathWithoutOpen} that refuses to answer with a guess: a missing component is still
|
|
47
|
+
* tolerated (its name is appended verbatim, which is what a not-yet-created target needs), but
|
|
48
|
+
* EACCES, EIO, ELOOP and hop exhaustion throw instead of returning an unresolved path. Callers
|
|
49
|
+
* that feed a canonical path into a containment or identity decision need this contract, because
|
|
50
|
+
* an unresolved path can name a different file than the one the I/O will reach.
|
|
51
|
+
*/
|
|
52
|
+
export declare function realpathWithoutOpenStrict(inputPath: string): string;
|
|
20
53
|
export declare function getFileRevision(path: string): string | undefined;
|
|
21
54
|
/**
|
|
22
55
|
* Returns true if the value is NOT a package source (npm:, git:, etc.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM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