parasor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +208 -0
- package/THIRD-PARTY-NOTICES.md +138 -0
- package/bin/parasor.mjs +3 -0
- package/node_modules/@parasor/shared/dist/client.d.ts +8 -0
- package/node_modules/@parasor/shared/dist/client.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/client.js +2 -0
- package/node_modules/@parasor/shared/dist/client.js.map +1 -0
- package/node_modules/@parasor/shared/dist/drops.d.ts +24 -0
- package/node_modules/@parasor/shared/dist/drops.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/drops.js +2 -0
- package/node_modules/@parasor/shared/dist/drops.js.map +1 -0
- package/node_modules/@parasor/shared/dist/file-uploads.d.ts +56 -0
- package/node_modules/@parasor/shared/dist/file-uploads.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/file-uploads.js +13 -0
- package/node_modules/@parasor/shared/dist/file-uploads.js.map +1 -0
- package/node_modules/@parasor/shared/dist/ide-commands.d.ts +8 -0
- package/node_modules/@parasor/shared/dist/ide-commands.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/ide-commands.js +59 -0
- package/node_modules/@parasor/shared/dist/ide-commands.js.map +1 -0
- package/node_modules/@parasor/shared/dist/pane-commands.d.ts +7 -0
- package/node_modules/@parasor/shared/dist/pane-commands.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/pane-commands.js +47 -0
- package/node_modules/@parasor/shared/dist/pane-commands.js.map +1 -0
- package/node_modules/@parasor/shared/dist/pane-model.d.ts +63 -0
- package/node_modules/@parasor/shared/dist/pane-model.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/pane-model.js +89 -0
- package/node_modules/@parasor/shared/dist/pane-model.js.map +1 -0
- package/node_modules/@parasor/shared/dist/panes.d.ts +33 -0
- package/node_modules/@parasor/shared/dist/panes.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/panes.js +2 -0
- package/node_modules/@parasor/shared/dist/panes.js.map +1 -0
- package/node_modules/@parasor/shared/dist/runtime.d.ts +180 -0
- package/node_modules/@parasor/shared/dist/runtime.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/runtime.js +2 -0
- package/node_modules/@parasor/shared/dist/runtime.js.map +1 -0
- package/node_modules/@parasor/shared/dist/state.d.ts +192 -0
- package/node_modules/@parasor/shared/dist/state.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/state.js +10 -0
- package/node_modules/@parasor/shared/dist/state.js.map +1 -0
- package/node_modules/@parasor/shared/dist/terminal.d.ts +191 -0
- package/node_modules/@parasor/shared/dist/terminal.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/terminal.js +174 -0
- package/node_modules/@parasor/shared/dist/terminal.js.map +1 -0
- package/node_modules/@parasor/shared/dist/types.d.ts +13 -0
- package/node_modules/@parasor/shared/dist/types.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/types.js +13 -0
- package/node_modules/@parasor/shared/dist/types.js.map +1 -0
- package/node_modules/@parasor/shared/dist/worktree-local-files.d.ts +14 -0
- package/node_modules/@parasor/shared/dist/worktree-local-files.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/worktree-local-files.js +41 -0
- package/node_modules/@parasor/shared/dist/worktree-local-files.js.map +1 -0
- package/node_modules/@parasor/shared/dist/ws-events.d.ts +152 -0
- package/node_modules/@parasor/shared/dist/ws-events.d.ts.map +1 -0
- package/node_modules/@parasor/shared/dist/ws-events.js +2 -0
- package/node_modules/@parasor/shared/dist/ws-events.js.map +1 -0
- package/node_modules/@parasor/shared/package.json +13 -0
- package/package.json +61 -0
- package/server/agent-detector/agent-state-store.d.ts +23 -0
- package/server/agent-detector/agent-state-store.d.ts.map +1 -0
- package/server/agent-detector/agent-state-store.js +110 -0
- package/server/agent-detector/agent-state-store.js.map +1 -0
- package/server/agent-detector/detector.d.ts +80 -0
- package/server/agent-detector/detector.d.ts.map +1 -0
- package/server/agent-detector/detector.js +219 -0
- package/server/agent-detector/detector.js.map +1 -0
- package/server/agent-detector/event-map.d.ts +25 -0
- package/server/agent-detector/event-map.d.ts.map +1 -0
- package/server/agent-detector/event-map.js +136 -0
- package/server/agent-detector/event-map.js.map +1 -0
- package/server/agent-detector/manual-agent-tracker.d.ts +19 -0
- package/server/agent-detector/manual-agent-tracker.d.ts.map +1 -0
- package/server/agent-detector/manual-agent-tracker.js +123 -0
- package/server/agent-detector/manual-agent-tracker.js.map +1 -0
- package/server/agent-detector/output-eligibility.d.ts +3 -0
- package/server/agent-detector/output-eligibility.d.ts.map +1 -0
- package/server/agent-detector/output-eligibility.js +39 -0
- package/server/agent-detector/output-eligibility.js.map +1 -0
- package/server/application/files/errors.d.ts +28 -0
- package/server/application/files/errors.d.ts.map +1 -0
- package/server/application/files/errors.js +55 -0
- package/server/application/files/errors.js.map +1 -0
- package/server/application/files/local-filesystem.d.ts +36 -0
- package/server/application/files/local-filesystem.d.ts.map +1 -0
- package/server/application/files/local-filesystem.js +171 -0
- package/server/application/files/local-filesystem.js.map +1 -0
- package/server/application/files/project-file-queries.d.ts +16 -0
- package/server/application/files/project-file-queries.d.ts.map +1 -0
- package/server/application/files/project-file-queries.js +126 -0
- package/server/application/files/project-file-queries.js.map +1 -0
- package/server/application/integrations/errors.d.ts +16 -0
- package/server/application/integrations/errors.d.ts.map +1 -0
- package/server/application/integrations/errors.js +31 -0
- package/server/application/integrations/errors.js.map +1 -0
- package/server/application/integrations/hook-notify.d.ts +32 -0
- package/server/application/integrations/hook-notify.d.ts.map +1 -0
- package/server/application/integrations/hook-notify.js +118 -0
- package/server/application/integrations/hook-notify.js.map +1 -0
- package/server/application/integrations/open-url.d.ts +11 -0
- package/server/application/integrations/open-url.d.ts.map +1 -0
- package/server/application/integrations/open-url.js +23 -0
- package/server/application/integrations/open-url.js.map +1 -0
- package/server/application/ports.d.ts +11 -0
- package/server/application/ports.d.ts.map +1 -0
- package/server/application/ports.js +2 -0
- package/server/application/ports.js.map +1 -0
- package/server/application/workspace/errors.d.ts +21 -0
- package/server/application/workspace/errors.d.ts.map +1 -0
- package/server/application/workspace/errors.js +21 -0
- package/server/application/workspace/errors.js.map +1 -0
- package/server/application/workspace/pane-commands.d.ts +47 -0
- package/server/application/workspace/pane-commands.d.ts.map +1 -0
- package/server/application/workspace/pane-commands.js +193 -0
- package/server/application/workspace/pane-commands.js.map +1 -0
- package/server/application/workspace/project-commands.d.ts +34 -0
- package/server/application/workspace/project-commands.d.ts.map +1 -0
- package/server/application/workspace/project-commands.js +81 -0
- package/server/application/workspace/project-commands.js.map +1 -0
- package/server/application/workspace/project-queries.d.ts +21 -0
- package/server/application/workspace/project-queries.d.ts.map +1 -0
- package/server/application/workspace/project-queries.js +216 -0
- package/server/application/workspace/project-queries.js.map +1 -0
- package/server/application/workspace/session-commands.d.ts +24 -0
- package/server/application/workspace/session-commands.d.ts.map +1 -0
- package/server/application/workspace/session-commands.js +123 -0
- package/server/application/workspace/session-commands.js.map +1 -0
- package/server/application/workspace/session-queries.d.ts +14 -0
- package/server/application/workspace/session-queries.d.ts.map +1 -0
- package/server/application/workspace/session-queries.js +47 -0
- package/server/application/workspace/session-queries.js.map +1 -0
- package/server/application/workspace/worktree-commands.d.ts +98 -0
- package/server/application/workspace/worktree-commands.d.ts.map +1 -0
- package/server/application/workspace/worktree-commands.js +323 -0
- package/server/application/workspace/worktree-commands.js.map +1 -0
- package/server/application/workspace/worktree-local-files.d.ts +11 -0
- package/server/application/workspace/worktree-local-files.d.ts.map +1 -0
- package/server/application/workspace/worktree-local-files.js +223 -0
- package/server/application/workspace/worktree-local-files.js.map +1 -0
- package/server/application/workspace/worktree-reconcile.d.ts +21 -0
- package/server/application/workspace/worktree-reconcile.d.ts.map +1 -0
- package/server/application/workspace/worktree-reconcile.js +49 -0
- package/server/application/workspace/worktree-reconcile.js.map +1 -0
- package/server/auth/origin.d.ts +17 -0
- package/server/auth/origin.d.ts.map +1 -0
- package/server/auth/origin.js +93 -0
- package/server/auth/origin.js.map +1 -0
- package/server/auth/pairing-token.d.ts +28 -0
- package/server/auth/pairing-token.d.ts.map +1 -0
- package/server/auth/pairing-token.js +46 -0
- package/server/auth/pairing-token.js.map +1 -0
- package/server/auth/token-exchange.d.ts +11 -0
- package/server/auth/token-exchange.d.ts.map +1 -0
- package/server/auth/token-exchange.js +27 -0
- package/server/auth/token-exchange.js.map +1 -0
- package/server/auth/token.d.ts +18 -0
- package/server/auth/token.d.ts.map +1 -0
- package/server/auth/token.js +115 -0
- package/server/auth/token.js.map +1 -0
- package/server/bootstrap/create-app-server.d.ts +49 -0
- package/server/bootstrap/create-app-server.d.ts.map +1 -0
- package/server/bootstrap/create-app-server.js +154 -0
- package/server/bootstrap/create-app-server.js.map +1 -0
- package/server/bootstrap/project-runtime.d.ts +29 -0
- package/server/bootstrap/project-runtime.d.ts.map +1 -0
- package/server/bootstrap/project-runtime.js +253 -0
- package/server/bootstrap/project-runtime.js.map +1 -0
- package/server/bootstrap/pty-env.d.ts +3 -0
- package/server/bootstrap/pty-env.d.ts.map +1 -0
- package/server/bootstrap/pty-env.js +15 -0
- package/server/bootstrap/pty-env.js.map +1 -0
- package/server/bootstrap/reconcile-state.d.ts +16 -0
- package/server/bootstrap/reconcile-state.d.ts.map +1 -0
- package/server/bootstrap/reconcile-state.js +73 -0
- package/server/bootstrap/reconcile-state.js.map +1 -0
- package/server/bootstrap/runtime-loops.d.ts +51 -0
- package/server/bootstrap/runtime-loops.d.ts.map +1 -0
- package/server/bootstrap/runtime-loops.js +189 -0
- package/server/bootstrap/runtime-loops.js.map +1 -0
- package/server/bootstrap/runtime-port.d.ts +4 -0
- package/server/bootstrap/runtime-port.d.ts.map +1 -0
- package/server/bootstrap/runtime-port.js +52 -0
- package/server/bootstrap/runtime-port.js.map +1 -0
- package/server/bootstrap/safety-gate.d.ts +22 -0
- package/server/bootstrap/safety-gate.d.ts.map +1 -0
- package/server/bootstrap/safety-gate.js +43 -0
- package/server/bootstrap/safety-gate.js.map +1 -0
- package/server/bootstrap/shutdown-marker.d.ts +35 -0
- package/server/bootstrap/shutdown-marker.d.ts.map +1 -0
- package/server/bootstrap/shutdown-marker.js +100 -0
- package/server/bootstrap/shutdown-marker.js.map +1 -0
- package/server/bootstrap/shutdown-runtime.d.ts +62 -0
- package/server/bootstrap/shutdown-runtime.d.ts.map +1 -0
- package/server/bootstrap/shutdown-runtime.js +66 -0
- package/server/bootstrap/shutdown-runtime.js.map +1 -0
- package/server/bootstrap/startup-banner.d.ts +34 -0
- package/server/bootstrap/startup-banner.d.ts.map +1 -0
- package/server/bootstrap/startup-banner.js +114 -0
- package/server/bootstrap/startup-banner.js.map +1 -0
- package/server/bootstrap/wire-runtime.d.ts +42 -0
- package/server/bootstrap/wire-runtime.d.ts.map +1 -0
- package/server/bootstrap/wire-runtime.js +205 -0
- package/server/bootstrap/wire-runtime.js.map +1 -0
- package/server/cli/help.d.ts +3 -0
- package/server/cli/help.d.ts.map +1 -0
- package/server/cli/help.js +39 -0
- package/server/cli/help.js.map +1 -0
- package/server/cli/hook-client.d.ts +12 -0
- package/server/cli/hook-client.d.ts.map +1 -0
- package/server/cli/hook-client.js +81 -0
- package/server/cli/hook-client.js.map +1 -0
- package/server/cli/hook.d.ts +3 -0
- package/server/cli/hook.d.ts.map +1 -0
- package/server/cli/hook.js +152 -0
- package/server/cli/hook.js.map +1 -0
- package/server/cli/main.d.ts +2 -0
- package/server/cli/main.d.ts.map +1 -0
- package/server/cli/main.js +133 -0
- package/server/cli/main.js.map +1 -0
- package/server/cli/notify.d.ts +19 -0
- package/server/cli/notify.d.ts.map +1 -0
- package/server/cli/notify.js +77 -0
- package/server/cli/notify.js.map +1 -0
- package/server/cli/open.d.ts +2 -0
- package/server/cli/open.d.ts.map +1 -0
- package/server/cli/open.js +47 -0
- package/server/cli/open.js.map +1 -0
- package/server/cli/probe-daemon-version.d.ts +46 -0
- package/server/cli/probe-daemon-version.d.ts.map +1 -0
- package/server/cli/probe-daemon-version.js +167 -0
- package/server/cli/probe-daemon-version.js.map +1 -0
- package/server/cli/pty-host.d.ts +36 -0
- package/server/cli/pty-host.d.ts.map +1 -0
- package/server/cli/pty-host.js +390 -0
- package/server/cli/pty-host.js.map +1 -0
- package/server/cli/qr.d.ts +2 -0
- package/server/cli/qr.d.ts.map +1 -0
- package/server/cli/qr.js +70 -0
- package/server/cli/qr.js.map +1 -0
- package/server/cli/restart-confirm.d.ts +33 -0
- package/server/cli/restart-confirm.d.ts.map +1 -0
- package/server/cli/restart-confirm.js +107 -0
- package/server/cli/restart-confirm.js.map +1 -0
- package/server/cli/restart.d.ts +17 -0
- package/server/cli/restart.d.ts.map +1 -0
- package/server/cli/restart.js +145 -0
- package/server/cli/restart.js.map +1 -0
- package/server/cli/service-darwin.d.ts +70 -0
- package/server/cli/service-darwin.d.ts.map +1 -0
- package/server/cli/service-darwin.js +562 -0
- package/server/cli/service-darwin.js.map +1 -0
- package/server/cli/service-linux.d.ts +81 -0
- package/server/cli/service-linux.d.ts.map +1 -0
- package/server/cli/service-linux.js +412 -0
- package/server/cli/service-linux.js.map +1 -0
- package/server/cli/service.d.ts +33 -0
- package/server/cli/service.d.ts.map +1 -0
- package/server/cli/service.js +133 -0
- package/server/cli/service.js.map +1 -0
- package/server/cli/shim-installer.d.ts +35 -0
- package/server/cli/shim-installer.d.ts.map +1 -0
- package/server/cli/shim-installer.js +662 -0
- package/server/cli/shim-installer.js.map +1 -0
- package/server/cli/shim-open.d.ts +2 -0
- package/server/cli/shim-open.d.ts.map +1 -0
- package/server/cli/shim-open.js +128 -0
- package/server/cli/shim-open.js.map +1 -0
- package/server/cli/shutdown-deps.d.ts +41 -0
- package/server/cli/shutdown-deps.d.ts.map +1 -0
- package/server/cli/shutdown-deps.js +158 -0
- package/server/cli/shutdown-deps.js.map +1 -0
- package/server/cli/stop.d.ts +11 -0
- package/server/cli/stop.d.ts.map +1 -0
- package/server/cli/stop.js +123 -0
- package/server/cli/stop.js.map +1 -0
- package/server/cli/unknown-command.d.ts +8 -0
- package/server/cli/unknown-command.d.ts.map +1 -0
- package/server/cli/unknown-command.js +14 -0
- package/server/cli/unknown-command.js.map +1 -0
- package/server/debug/agent-status-recorder.d.ts +57 -0
- package/server/debug/agent-status-recorder.d.ts.map +1 -0
- package/server/debug/agent-status-recorder.js +209 -0
- package/server/debug/agent-status-recorder.js.map +1 -0
- package/server/debug/terminal-trace-recorder.d.ts +41 -0
- package/server/debug/terminal-trace-recorder.d.ts.map +1 -0
- package/server/debug/terminal-trace-recorder.js +112 -0
- package/server/debug/terminal-trace-recorder.js.map +1 -0
- package/server/fonts/catalog.d.ts +35 -0
- package/server/fonts/catalog.d.ts.map +1 -0
- package/server/fonts/catalog.js +76 -0
- package/server/fonts/catalog.js.map +1 -0
- package/server/fonts/installer.d.ts +45 -0
- package/server/fonts/installer.d.ts.map +1 -0
- package/server/fonts/installer.js +201 -0
- package/server/fonts/installer.js.map +1 -0
- package/server/fonts/routes.d.ts +4 -0
- package/server/fonts/routes.d.ts.map +1 -0
- package/server/fonts/routes.js +91 -0
- package/server/fonts/routes.js.map +1 -0
- package/server/fs/drops.d.ts +50 -0
- package/server/fs/drops.d.ts.map +1 -0
- package/server/fs/drops.js +137 -0
- package/server/fs/drops.js.map +1 -0
- package/server/fs/file-uploads.d.ts +57 -0
- package/server/fs/file-uploads.d.ts.map +1 -0
- package/server/fs/file-uploads.js +214 -0
- package/server/fs/file-uploads.js.map +1 -0
- package/server/fs/file-watcher.d.ts +22 -0
- package/server/fs/file-watcher.d.ts.map +1 -0
- package/server/fs/file-watcher.js +105 -0
- package/server/fs/file-watcher.js.map +1 -0
- package/server/fs/git-watcher.d.ts +76 -0
- package/server/fs/git-watcher.d.ts.map +1 -0
- package/server/fs/git-watcher.js +356 -0
- package/server/fs/git-watcher.js.map +1 -0
- package/server/fs/media.d.ts +35 -0
- package/server/fs/media.d.ts.map +1 -0
- package/server/fs/media.js +271 -0
- package/server/fs/media.js.map +1 -0
- package/server/fs/service.d.ts +97 -0
- package/server/fs/service.d.ts.map +1 -0
- package/server/fs/service.js +306 -0
- package/server/fs/service.js.map +1 -0
- package/server/fs/upload-staging.d.ts +76 -0
- package/server/fs/upload-staging.d.ts.map +1 -0
- package/server/fs/upload-staging.js +283 -0
- package/server/fs/upload-staging.js.map +1 -0
- package/server/fs/watcher-lifecycle.d.ts +24 -0
- package/server/fs/watcher-lifecycle.d.ts.map +1 -0
- package/server/fs/watcher-lifecycle.js +105 -0
- package/server/fs/watcher-lifecycle.js.map +1 -0
- package/server/index.d.ts +17 -0
- package/server/index.d.ts.map +1 -0
- package/server/index.js +510 -0
- package/server/index.js.map +1 -0
- package/server/ipc/socket-server.d.ts +28 -0
- package/server/ipc/socket-server.d.ts.map +1 -0
- package/server/ipc/socket-server.js +206 -0
- package/server/ipc/socket-server.js.map +1 -0
- package/server/lib/git-exec.d.ts +38 -0
- package/server/lib/git-exec.d.ts.map +1 -0
- package/server/lib/git-exec.js +96 -0
- package/server/lib/git-exec.js.map +1 -0
- package/server/lib/open-in-ide.d.ts +22 -0
- package/server/lib/open-in-ide.d.ts.map +1 -0
- package/server/lib/open-in-ide.js +90 -0
- package/server/lib/open-in-ide.js.map +1 -0
- package/server/lib/open-in-os.d.ts +20 -0
- package/server/lib/open-in-os.d.ts.map +1 -0
- package/server/lib/open-in-os.js +51 -0
- package/server/lib/open-in-os.js.map +1 -0
- package/server/lib/path.d.ts +2 -0
- package/server/lib/path.d.ts.map +1 -0
- package/server/lib/path.js +10 -0
- package/server/lib/path.js.map +1 -0
- package/server/lib/promise-mutex.d.ts +7 -0
- package/server/lib/promise-mutex.d.ts.map +1 -0
- package/server/lib/promise-mutex.js +26 -0
- package/server/lib/promise-mutex.js.map +1 -0
- package/server/lib/sd-notify.d.ts +8 -0
- package/server/lib/sd-notify.d.ts.map +1 -0
- package/server/lib/sd-notify.js +27 -0
- package/server/lib/sd-notify.js.map +1 -0
- package/server/net/local-machine.d.ts +7 -0
- package/server/net/local-machine.d.ts.map +1 -0
- package/server/net/local-machine.js +79 -0
- package/server/net/local-machine.js.map +1 -0
- package/server/net/reachable-host.d.ts +12 -0
- package/server/net/reachable-host.d.ts.map +1 -0
- package/server/net/reachable-host.js +25 -0
- package/server/net/reachable-host.js.map +1 -0
- package/server/network/endpoints.d.ts +14 -0
- package/server/network/endpoints.d.ts.map +1 -0
- package/server/network/endpoints.js +104 -0
- package/server/network/endpoints.js.map +1 -0
- package/server/network/qr.d.ts +16 -0
- package/server/network/qr.d.ts.map +1 -0
- package/server/network/qr.js +89 -0
- package/server/network/qr.js.map +1 -0
- package/server/port-forwarder/forwarder.d.ts +47 -0
- package/server/port-forwarder/forwarder.d.ts.map +1 -0
- package/server/port-forwarder/forwarder.js +159 -0
- package/server/port-forwarder/forwarder.js.map +1 -0
- package/server/port-scanner/scanner.d.ts +24 -0
- package/server/port-scanner/scanner.d.ts.map +1 -0
- package/server/port-scanner/scanner.js +193 -0
- package/server/port-scanner/scanner.js.map +1 -0
- package/server/pty/connection-lifecycle.d.ts +50 -0
- package/server/pty/connection-lifecycle.d.ts.map +1 -0
- package/server/pty/connection-lifecycle.js +113 -0
- package/server/pty/connection-lifecycle.js.map +1 -0
- package/server/pty/daemon-connect.d.ts +52 -0
- package/server/pty/daemon-connect.d.ts.map +1 -0
- package/server/pty/daemon-connect.js +62 -0
- package/server/pty/daemon-connect.js.map +1 -0
- package/server/pty/handshake-timeout-race.d.ts +22 -0
- package/server/pty/handshake-timeout-race.d.ts.map +1 -0
- package/server/pty/handshake-timeout-race.js +23 -0
- package/server/pty/handshake-timeout-race.js.map +1 -0
- package/server/pty/headless-replay-snapshot.d.ts +28 -0
- package/server/pty/headless-replay-snapshot.d.ts.map +1 -0
- package/server/pty/headless-replay-snapshot.js +285 -0
- package/server/pty/headless-replay-snapshot.js.map +1 -0
- package/server/pty/headless-terminal-state-cache.d.ts +31 -0
- package/server/pty/headless-terminal-state-cache.d.ts.map +1 -0
- package/server/pty/headless-terminal-state-cache.js +119 -0
- package/server/pty/headless-terminal-state-cache.js.map +1 -0
- package/server/pty/hello-ack-validator.d.ts +15 -0
- package/server/pty/hello-ack-validator.d.ts.map +1 -0
- package/server/pty/hello-ack-validator.js +30 -0
- package/server/pty/hello-ack-validator.js.map +1 -0
- package/server/pty/host-daemon/bootstrap.d.ts +100 -0
- package/server/pty/host-daemon/bootstrap.d.ts.map +1 -0
- package/server/pty/host-daemon/bootstrap.js +611 -0
- package/server/pty/host-daemon/bootstrap.js.map +1 -0
- package/server/pty/host-daemon/daemon.d.ts +111 -0
- package/server/pty/host-daemon/daemon.d.ts.map +1 -0
- package/server/pty/host-daemon/daemon.js +648 -0
- package/server/pty/host-daemon/daemon.js.map +1 -0
- package/server/pty/host-daemon/entry.d.ts +3 -0
- package/server/pty/host-daemon/entry.d.ts.map +1 -0
- package/server/pty/host-daemon/entry.js +72 -0
- package/server/pty/host-daemon/entry.js.map +1 -0
- package/server/pty/host-daemon/lockfile.d.ts +12 -0
- package/server/pty/host-daemon/lockfile.d.ts.map +1 -0
- package/server/pty/host-daemon/lockfile.js +120 -0
- package/server/pty/host-daemon/lockfile.js.map +1 -0
- package/server/pty/host-daemon/mode-marker.d.ts +77 -0
- package/server/pty/host-daemon/mode-marker.d.ts.map +1 -0
- package/server/pty/host-daemon/mode-marker.js +228 -0
- package/server/pty/host-daemon/mode-marker.js.map +1 -0
- package/server/pty/host-daemon/orphan-cleanup.d.ts +42 -0
- package/server/pty/host-daemon/orphan-cleanup.d.ts.map +1 -0
- package/server/pty/host-daemon/orphan-cleanup.js +84 -0
- package/server/pty/host-daemon/orphan-cleanup.js.map +1 -0
- package/server/pty/host-daemon/paths.d.ts +10 -0
- package/server/pty/host-daemon/paths.d.ts.map +1 -0
- package/server/pty/host-daemon/paths.js +56 -0
- package/server/pty/host-daemon/paths.js.map +1 -0
- package/server/pty/host-daemon/server-connection.d.ts +44 -0
- package/server/pty/host-daemon/server-connection.d.ts.map +1 -0
- package/server/pty/host-daemon/server-connection.js +100 -0
- package/server/pty/host-daemon/server-connection.js.map +1 -0
- package/server/pty/host-daemon/service-detection.d.ts +24 -0
- package/server/pty/host-daemon/service-detection.d.ts.map +1 -0
- package/server/pty/host-daemon/service-detection.js +16 -0
- package/server/pty/host-daemon/service-detection.js.map +1 -0
- package/server/pty/host-daemon/socket-ready.d.ts +22 -0
- package/server/pty/host-daemon/socket-ready.d.ts.map +1 -0
- package/server/pty/host-daemon/socket-ready.js +33 -0
- package/server/pty/host-daemon/socket-ready.js.map +1 -0
- package/server/pty/host-daemon/spawn-daemon.d.ts +45 -0
- package/server/pty/host-daemon/spawn-daemon.d.ts.map +1 -0
- package/server/pty/host-daemon/spawn-daemon.js +155 -0
- package/server/pty/host-daemon/spawn-daemon.js.map +1 -0
- package/server/pty/host-daemon/terminate-daemon.d.ts +16 -0
- package/server/pty/host-daemon/terminate-daemon.d.ts.map +1 -0
- package/server/pty/host-daemon/terminate-daemon.js +128 -0
- package/server/pty/host-daemon/terminate-daemon.js.map +1 -0
- package/server/pty/host-protocol/frames.d.ts +110 -0
- package/server/pty/host-protocol/frames.d.ts.map +1 -0
- package/server/pty/host-protocol/frames.js +255 -0
- package/server/pty/host-protocol/frames.js.map +1 -0
- package/server/pty/host-protocol/messages.d.ts +140 -0
- package/server/pty/host-protocol/messages.d.ts.map +1 -0
- package/server/pty/host-protocol/messages.js +117 -0
- package/server/pty/host-protocol/messages.js.map +1 -0
- package/server/pty/host.d.ts +273 -0
- package/server/pty/host.d.ts.map +1 -0
- package/server/pty/host.js +184 -0
- package/server/pty/host.js.map +1 -0
- package/server/pty/in-process-host.d.ts +224 -0
- package/server/pty/in-process-host.d.ts.map +1 -0
- package/server/pty/in-process-host.js +1183 -0
- package/server/pty/in-process-host.js.map +1 -0
- package/server/pty/osc7-lifecycle.d.ts +8 -0
- package/server/pty/osc7-lifecycle.d.ts.map +1 -0
- package/server/pty/osc7-lifecycle.js +22 -0
- package/server/pty/osc7-lifecycle.js.map +1 -0
- package/server/pty/osc7-parser.d.ts +23 -0
- package/server/pty/osc7-parser.d.ts.map +1 -0
- package/server/pty/osc7-parser.js +91 -0
- package/server/pty/osc7-parser.js.map +1 -0
- package/server/pty/remote-host.d.ts +188 -0
- package/server/pty/remote-host.d.ts.map +1 -0
- package/server/pty/remote-host.js +810 -0
- package/server/pty/remote-host.js.map +1 -0
- package/server/pty/request-correlator.d.ts +59 -0
- package/server/pty/request-correlator.d.ts.map +1 -0
- package/server/pty/request-correlator.js +75 -0
- package/server/pty/request-correlator.js.map +1 -0
- package/server/pty/scrollback-log.d.ts +130 -0
- package/server/pty/scrollback-log.d.ts.map +1 -0
- package/server/pty/scrollback-log.js +344 -0
- package/server/pty/scrollback-log.js.map +1 -0
- package/server/pty/scrollback-sanitize.d.ts +2 -0
- package/server/pty/scrollback-sanitize.d.ts.map +1 -0
- package/server/pty/scrollback-sanitize.js +54 -0
- package/server/pty/scrollback-sanitize.js.map +1 -0
- package/server/pty/session-mirror.d.ts +67 -0
- package/server/pty/session-mirror.d.ts.map +1 -0
- package/server/pty/session-mirror.js +112 -0
- package/server/pty/session-mirror.js.map +1 -0
- package/server/pty/session-policy.d.ts +85 -0
- package/server/pty/session-policy.d.ts.map +1 -0
- package/server/pty/session-policy.js +186 -0
- package/server/pty/session-policy.js.map +1 -0
- package/server/pty/version-mismatch-recovery.d.ts +71 -0
- package/server/pty/version-mismatch-recovery.d.ts.map +1 -0
- package/server/pty/version-mismatch-recovery.js +63 -0
- package/server/pty/version-mismatch-recovery.js.map +1 -0
- package/server/routes/debug-agent-status.d.ts +5 -0
- package/server/routes/debug-agent-status.d.ts.map +1 -0
- package/server/routes/debug-agent-status.js +22 -0
- package/server/routes/debug-agent-status.js.map +1 -0
- package/server/routes/debug-diagnostics.d.ts +8 -0
- package/server/routes/debug-diagnostics.d.ts.map +1 -0
- package/server/routes/debug-diagnostics.js +34 -0
- package/server/routes/debug-diagnostics.js.map +1 -0
- package/server/routes/debug-terminal-trace.d.ts +16 -0
- package/server/routes/debug-terminal-trace.d.ts.map +1 -0
- package/server/routes/debug-terminal-trace.js +545 -0
- package/server/routes/debug-terminal-trace.js.map +1 -0
- package/server/routes/drops.d.ts +13 -0
- package/server/routes/drops.d.ts.map +1 -0
- package/server/routes/drops.js +126 -0
- package/server/routes/drops.js.map +1 -0
- package/server/routes/file-uploads.d.ts +9 -0
- package/server/routes/file-uploads.d.ts.map +1 -0
- package/server/routes/file-uploads.js +119 -0
- package/server/routes/file-uploads.js.map +1 -0
- package/server/routes/files.d.ts +9 -0
- package/server/routes/files.d.ts.map +1 -0
- package/server/routes/files.js +441 -0
- package/server/routes/files.js.map +1 -0
- package/server/routes/filesystem.d.ts +6 -0
- package/server/routes/filesystem.d.ts.map +1 -0
- package/server/routes/filesystem.js +76 -0
- package/server/routes/filesystem.js.map +1 -0
- package/server/routes/git.d.ts +38 -0
- package/server/routes/git.d.ts.map +1 -0
- package/server/routes/git.js +585 -0
- package/server/routes/git.js.map +1 -0
- package/server/routes/healthz.d.ts +8 -0
- package/server/routes/healthz.d.ts.map +1 -0
- package/server/routes/healthz.js +24 -0
- package/server/routes/healthz.js.map +1 -0
- package/server/routes/hook.d.ts +14 -0
- package/server/routes/hook.d.ts.map +1 -0
- package/server/routes/hook.js +86 -0
- package/server/routes/hook.js.map +1 -0
- package/server/routes/ide-commands.d.ts +9 -0
- package/server/routes/ide-commands.d.ts.map +1 -0
- package/server/routes/ide-commands.js +23 -0
- package/server/routes/ide-commands.js.map +1 -0
- package/server/routes/lib/resolve-worktree.d.ts +30 -0
- package/server/routes/lib/resolve-worktree.d.ts.map +1 -0
- package/server/routes/lib/resolve-worktree.js +35 -0
- package/server/routes/lib/resolve-worktree.js.map +1 -0
- package/server/routes/open.d.ts +4 -0
- package/server/routes/open.d.ts.map +1 -0
- package/server/routes/open.js +21 -0
- package/server/routes/open.js.map +1 -0
- package/server/routes/pane-commands.d.ts +9 -0
- package/server/routes/pane-commands.d.ts.map +1 -0
- package/server/routes/pane-commands.js +23 -0
- package/server/routes/pane-commands.js.map +1 -0
- package/server/routes/projects.d.ts +15 -0
- package/server/routes/projects.d.ts.map +1 -0
- package/server/routes/projects.js +363 -0
- package/server/routes/projects.js.map +1 -0
- package/server/routes/server-notices.d.ts +4 -0
- package/server/routes/server-notices.d.ts.map +1 -0
- package/server/routes/server-notices.js +29 -0
- package/server/routes/server-notices.js.map +1 -0
- package/server/routes/service-config.d.ts +11 -0
- package/server/routes/service-config.d.ts.map +1 -0
- package/server/routes/service-config.js +64 -0
- package/server/routes/service-config.js.map +1 -0
- package/server/routes/sessions.d.ts +7 -0
- package/server/routes/sessions.d.ts.map +1 -0
- package/server/routes/sessions.js +218 -0
- package/server/routes/sessions.js.map +1 -0
- package/server/service/caffeinate.d.ts +33 -0
- package/server/service/caffeinate.d.ts.map +1 -0
- package/server/service/caffeinate.js +72 -0
- package/server/service/caffeinate.js.map +1 -0
- package/server/state/app-state.d.ts +167 -0
- package/server/state/app-state.d.ts.map +1 -0
- package/server/state/app-state.js +335 -0
- package/server/state/app-state.js.map +1 -0
- package/server/state/project-manager.d.ts +30 -0
- package/server/state/project-manager.d.ts.map +1 -0
- package/server/state/project-manager.js +128 -0
- package/server/state/project-manager.js.map +1 -0
- package/server/state/server-notices.d.ts +12 -0
- package/server/state/server-notices.d.ts.map +1 -0
- package/server/state/server-notices.js +32 -0
- package/server/state/server-notices.js.map +1 -0
- package/server/state/worktree-cache.d.ts +25 -0
- package/server/state/worktree-cache.d.ts.map +1 -0
- package/server/state/worktree-cache.js +53 -0
- package/server/state/worktree-cache.js.map +1 -0
- package/server/ws/events.d.ts +45 -0
- package/server/ws/events.d.ts.map +1 -0
- package/server/ws/events.js +134 -0
- package/server/ws/events.js.map +1 -0
- package/server/ws/keepalive.d.ts +27 -0
- package/server/ws/keepalive.d.ts.map +1 -0
- package/server/ws/keepalive.js +63 -0
- package/server/ws/keepalive.js.map +1 -0
- package/server/ws/terminal-attach.d.ts +13 -0
- package/server/ws/terminal-attach.d.ts.map +1 -0
- package/server/ws/terminal-attach.js +233 -0
- package/server/ws/terminal-attach.js.map +1 -0
- package/server/ws/terminal-flow.d.ts +17 -0
- package/server/ws/terminal-flow.d.ts.map +1 -0
- package/server/ws/terminal-flow.js +64 -0
- package/server/ws/terminal-flow.js.map +1 -0
- package/server/ws/terminal.d.ts +69 -0
- package/server/ws/terminal.d.ts.map +1 -0
- package/server/ws/terminal.js +311 -0
- package/server/ws/terminal.js.map +1 -0
- package/web/assets/EditorPane-CzzT3iYY.js +123 -0
- package/web/assets/SymbolsNerdFontMono-Regular-CwEZqMeU.woff2 +0 -0
- package/web/assets/TerminalPane-CjbYzePr.js +68 -0
- package/web/assets/TerminalPane-DkTCHfhq.css +1 -0
- package/web/assets/file-icons-JBi09j0r.js +6 -0
- package/web/assets/index-CTTkRpnn.css +2 -0
- package/web/assets/index-CmhewzMp.js +34 -0
- package/web/assets/session-resume-7f-tB-ZU.js +2 -0
- package/web/assets/terminal-trace-PuuFRybC.js +2803 -0
- package/web/assets/useVirtualKeyboard-DgJb9u9d.js +1 -0
- package/web/index.html +52 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type AgentState, type AppState, type GitState, type Notification, type PortInfo, type Worktree, type WsEventMessage } from "@parasor/shared";
|
|
2
|
+
import type { WSContext } from "hono/ws";
|
|
3
|
+
export interface HydrationSources {
|
|
4
|
+
getState: () => Readonly<AppState>;
|
|
5
|
+
getAgentStates: () => Record<string, AgentState>;
|
|
6
|
+
getNotifications: () => Notification[];
|
|
7
|
+
getPorts: () => Record<string, PortInfo[]>;
|
|
8
|
+
getGitStates: () => Record<string, Record<string, GitState | null>>;
|
|
9
|
+
/**
|
|
10
|
+
* Per-project worktree snapshot. Sync because it reads from a
|
|
11
|
+
* runtime-maintained `WorktreeCache` -- see `wireRuntime`. Keeping
|
|
12
|
+
* this synchronous lets `addClient` capture seq + state + worktrees
|
|
13
|
+
* atomically in one tick, avoiding the broadcast/snapshot race that
|
|
14
|
+
* would otherwise leak events to a connecting client.
|
|
15
|
+
*/
|
|
16
|
+
getWorktrees: () => Record<string, Worktree[]>;
|
|
17
|
+
}
|
|
18
|
+
export type ClientCountListener = (count: number) => void;
|
|
19
|
+
export declare class EventBus {
|
|
20
|
+
private clients;
|
|
21
|
+
private seq;
|
|
22
|
+
private lock;
|
|
23
|
+
private sources;
|
|
24
|
+
private notifications;
|
|
25
|
+
private clientCountListeners;
|
|
26
|
+
setHydrationSources(sources: HydrationSources): void;
|
|
27
|
+
addNotification(n: Notification): void;
|
|
28
|
+
getNotifications(): Notification[];
|
|
29
|
+
getClientCount(): number;
|
|
30
|
+
onClientCountChanged(listener: ClientCountListener): () => void;
|
|
31
|
+
addClient(ws: WSContext): Promise<void>;
|
|
32
|
+
removeClient(ws: WSContext): void;
|
|
33
|
+
private emitClientCount;
|
|
34
|
+
broadcast(message: WsEventMessage): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Handle a single client->server frame on `/ws/events`. The browser
|
|
38
|
+
* cannot issue WS-protocol pings from JS, so we offer an app-layer
|
|
39
|
+
* ping that detects silent-dead TCP paths (NAT idle timeout, mobile
|
|
40
|
+
* background freeze) where neither side observes a close. Echoes
|
|
41
|
+
* `pong` with the same `ts`. Unknown / malformed frames are ignored
|
|
42
|
+
* -- forward-compat for future client->server messages.
|
|
43
|
+
*/
|
|
44
|
+
export declare function handleEventClientMessage(ws: Pick<WSContext, "send">, raw: unknown): void;
|
|
45
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/ws/events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EAGb,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,QAAQ,EAEb,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAA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AE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAC3B,GAAG,EAAE,OAAO,GACX,IAAI,CAiBN"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { DEFAULT_DROP_SIZE_HARD_MAX_BYTES, DEFAULT_DROP_SIZE_MAX_BYTES, } from "@parasor/shared";
|
|
2
|
+
import { PromiseMutex } from "../lib/promise-mutex.js";
|
|
3
|
+
// Cap retained notifications so a long-running daemon does not grow the
|
|
4
|
+
// hydration payload without bound (every reconnect ships the full list).
|
|
5
|
+
const NOTIFICATION_RETENTION_LIMIT = 200;
|
|
6
|
+
export class EventBus {
|
|
7
|
+
clients = new Set();
|
|
8
|
+
seq = 0;
|
|
9
|
+
lock = new PromiseMutex();
|
|
10
|
+
sources = null;
|
|
11
|
+
notifications = [];
|
|
12
|
+
clientCountListeners = new Set();
|
|
13
|
+
setHydrationSources(sources) {
|
|
14
|
+
this.sources = sources;
|
|
15
|
+
}
|
|
16
|
+
addNotification(n) {
|
|
17
|
+
this.notifications.push(n);
|
|
18
|
+
const overflow = this.notifications.length - NOTIFICATION_RETENTION_LIMIT;
|
|
19
|
+
if (overflow > 0)
|
|
20
|
+
this.notifications.splice(0, overflow);
|
|
21
|
+
}
|
|
22
|
+
getNotifications() {
|
|
23
|
+
return this.notifications;
|
|
24
|
+
}
|
|
25
|
+
getClientCount() {
|
|
26
|
+
return this.clients.size;
|
|
27
|
+
}
|
|
28
|
+
onClientCountChanged(listener) {
|
|
29
|
+
this.clientCountListeners.add(listener);
|
|
30
|
+
return () => {
|
|
31
|
+
this.clientCountListeners.delete(listener);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async addClient(ws) {
|
|
35
|
+
const release = await this.lock.acquire();
|
|
36
|
+
const snapshotSeq = this.seq;
|
|
37
|
+
const payload = this.sources
|
|
38
|
+
? {
|
|
39
|
+
seq: snapshotSeq,
|
|
40
|
+
state: structuredClone(this.sources.getState()),
|
|
41
|
+
agentStates: this.sources.getAgentStates(),
|
|
42
|
+
notifications: this.sources.getNotifications(),
|
|
43
|
+
ports: this.sources.getPorts(),
|
|
44
|
+
gitStates: this.sources.getGitStates(),
|
|
45
|
+
worktrees: this.sources.getWorktrees(),
|
|
46
|
+
hostPlatform: process.platform,
|
|
47
|
+
}
|
|
48
|
+
: {
|
|
49
|
+
seq: snapshotSeq,
|
|
50
|
+
state: {
|
|
51
|
+
version: 1,
|
|
52
|
+
projects: [],
|
|
53
|
+
projectStates: {},
|
|
54
|
+
sessions: [],
|
|
55
|
+
sessionRecords: [],
|
|
56
|
+
ideCommands: [],
|
|
57
|
+
paneCommands: [],
|
|
58
|
+
serviceConfig: {
|
|
59
|
+
preventIdleSleep: false,
|
|
60
|
+
portDetection: "all-interfaces",
|
|
61
|
+
dropSizeMaxBytes: DEFAULT_DROP_SIZE_MAX_BYTES,
|
|
62
|
+
dropSizeHardMaxBytes: DEFAULT_DROP_SIZE_HARD_MAX_BYTES,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
agentStates: {},
|
|
66
|
+
notifications: [],
|
|
67
|
+
ports: {},
|
|
68
|
+
gitStates: {},
|
|
69
|
+
worktrees: {},
|
|
70
|
+
hostPlatform: process.platform,
|
|
71
|
+
};
|
|
72
|
+
this.clients.add(ws);
|
|
73
|
+
ws.send(JSON.stringify({ type: "app-state-snapshot", payload }));
|
|
74
|
+
release();
|
|
75
|
+
this.emitClientCount();
|
|
76
|
+
}
|
|
77
|
+
removeClient(ws) {
|
|
78
|
+
const had = this.clients.delete(ws);
|
|
79
|
+
if (had)
|
|
80
|
+
this.emitClientCount();
|
|
81
|
+
}
|
|
82
|
+
emitClientCount() {
|
|
83
|
+
const count = this.clients.size;
|
|
84
|
+
for (const listener of this.clientCountListeners) {
|
|
85
|
+
listener(count);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
broadcast(message) {
|
|
89
|
+
this.seq++;
|
|
90
|
+
const envelope = { seq: this.seq, message };
|
|
91
|
+
const data = JSON.stringify(envelope);
|
|
92
|
+
let dropped = false;
|
|
93
|
+
for (const client of this.clients) {
|
|
94
|
+
if (client.readyState === 1) {
|
|
95
|
+
try {
|
|
96
|
+
client.send(data);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
this.clients.delete(client);
|
|
100
|
+
dropped = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (dropped)
|
|
105
|
+
this.emitClientCount();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Handle a single client->server frame on `/ws/events`. The browser
|
|
110
|
+
* cannot issue WS-protocol pings from JS, so we offer an app-layer
|
|
111
|
+
* ping that detects silent-dead TCP paths (NAT idle timeout, mobile
|
|
112
|
+
* background freeze) where neither side observes a close. Echoes
|
|
113
|
+
* `pong` with the same `ts`. Unknown / malformed frames are ignored
|
|
114
|
+
* -- forward-compat for future client->server messages.
|
|
115
|
+
*/
|
|
116
|
+
export function handleEventClientMessage(ws, raw) {
|
|
117
|
+
if (typeof raw !== "string")
|
|
118
|
+
return;
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(raw);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (parsed === null ||
|
|
127
|
+
typeof parsed !== "object" ||
|
|
128
|
+
parsed.type !== "ping" ||
|
|
129
|
+
!Number.isFinite(parsed.ts)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
ws.send(JSON.stringify({ type: "pong", ts: parsed.ts }));
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/ws/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gCAAgC,EAChC,2BAA2B,GAQ5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE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I,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IACD,IACE,MAAM,KAAK,IAAI;QACf,OAAO,MAAM,KAAK,QAAQ;QACzB,MAA6B,CAAC,IAAI,KAAK,MAAM;QAC9C,CAAC,MAAM,CAAC,QAAQ,CAAE,MAA2B,CAAC,EAAE,CAAC,EACjD,CAAC;QACD,OAAO;IACT,CAAC;IACD,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAG,MAAyB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal shape of the `ws` package WebSocket we rely on. Declared locally so
|
|
3
|
+
* the server package does not need a direct dependency on `ws` (it arrives
|
|
4
|
+
* transitively through @hono/node-ws).
|
|
5
|
+
*/
|
|
6
|
+
export interface KeepaliveSocket {
|
|
7
|
+
readyState: number;
|
|
8
|
+
readonly OPEN: number;
|
|
9
|
+
ping(): void;
|
|
10
|
+
terminate(): void;
|
|
11
|
+
on(event: "pong", listener: () => void): void;
|
|
12
|
+
off(event: "pong", listener: () => void): void;
|
|
13
|
+
}
|
|
14
|
+
export interface KeepaliveOptions {
|
|
15
|
+
pingIntervalMs: number;
|
|
16
|
+
pongTimeoutMs: number;
|
|
17
|
+
onTimeout?: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Attach ping/pong keepalive to a ws WebSocket. Mobile carriers, corporate
|
|
21
|
+
* proxies, and Tailscale can silently drop idle TCP connections; without a
|
|
22
|
+
* keepalive the client thinks the socket is healthy while the server sees
|
|
23
|
+
* nothing. The interval ping forces a half-open state to surface, and the
|
|
24
|
+
* pong deadline tears the connection down so the client reconnects.
|
|
25
|
+
*/
|
|
26
|
+
export declare function attachKeepalive(raw: KeepaliveSocket, options: KeepaliveOptions): () => void;
|
|
27
|
+
//# sourceMappingURL=keepalive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepalive.d.ts","sourceRoot":"","sources":["../../src/ws/keepalive.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,IAAI,IAAI,CAAC;IACb,SAAS,IAAI,IAAI,CAAC;IAClB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC9C,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAChD;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,gBAAgB,GACxB,MAAM,IAAI,CAmDZ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach ping/pong keepalive to a ws WebSocket. Mobile carriers, corporate
|
|
3
|
+
* proxies, and Tailscale can silently drop idle TCP connections; without a
|
|
4
|
+
* keepalive the client thinks the socket is healthy while the server sees
|
|
5
|
+
* nothing. The interval ping forces a half-open state to surface, and the
|
|
6
|
+
* pong deadline tears the connection down so the client reconnects.
|
|
7
|
+
*/
|
|
8
|
+
export function attachKeepalive(raw, options) {
|
|
9
|
+
const { pingIntervalMs, pongTimeoutMs, onTimeout } = options;
|
|
10
|
+
if (pingIntervalMs <= 0)
|
|
11
|
+
return () => { };
|
|
12
|
+
let disposed = false;
|
|
13
|
+
let pongDeadline = null;
|
|
14
|
+
const clearDeadline = () => {
|
|
15
|
+
if (pongDeadline !== null) {
|
|
16
|
+
clearTimeout(pongDeadline);
|
|
17
|
+
pongDeadline = null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const onPong = () => {
|
|
21
|
+
clearDeadline();
|
|
22
|
+
};
|
|
23
|
+
raw.on("pong", onPong);
|
|
24
|
+
const pingTimer = setInterval(() => {
|
|
25
|
+
if (disposed)
|
|
26
|
+
return;
|
|
27
|
+
if (raw.readyState !== raw.OPEN)
|
|
28
|
+
return;
|
|
29
|
+
if (pongDeadline !== null)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
raw.ping();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (pongTimeoutMs <= 0)
|
|
38
|
+
return;
|
|
39
|
+
pongDeadline = setTimeout(() => {
|
|
40
|
+
pongDeadline = null;
|
|
41
|
+
if (disposed)
|
|
42
|
+
return;
|
|
43
|
+
onTimeout?.();
|
|
44
|
+
try {
|
|
45
|
+
raw.terminate();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// already closed; nothing to do
|
|
49
|
+
}
|
|
50
|
+
}, pongTimeoutMs);
|
|
51
|
+
pongDeadline.unref?.();
|
|
52
|
+
}, pingIntervalMs);
|
|
53
|
+
pingTimer.unref?.();
|
|
54
|
+
return () => {
|
|
55
|
+
if (disposed)
|
|
56
|
+
return;
|
|
57
|
+
disposed = true;
|
|
58
|
+
clearInterval(pingTimer);
|
|
59
|
+
clearDeadline();
|
|
60
|
+
raw.off("pong", onPong);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=keepalive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepalive.js","sourceRoot":"","sources":["../../src/ws/keepalive.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,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C;IACzB,CAAC,EAAE,cAAc,CAAC,CAAC;IACnB,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;IAEpB,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ;YAAE,OAAO;QACrB,QAAQ,GAAG,IAAI,CAAC;QAChB,aAAa,CAAC,SAAS,CAAC,CAAC;QACzB,aAAa,EAAE,CAAC;QAChB,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type WsTerminalClientMessage } from "@parasor/shared";
|
|
2
|
+
import type { RelayContext } from "./terminal.js";
|
|
3
|
+
type WsTerminalInitMessage = Extract<WsTerminalClientMessage, {
|
|
4
|
+
type: "init";
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* First-frame attach: choose the binary or legacy path from declared
|
|
8
|
+
* capabilities. The caller ({@link handleInitFrame}) has already validated that
|
|
9
|
+
* `msg` is the mandatory `init` and recorded the handshake.
|
|
10
|
+
*/
|
|
11
|
+
export declare function attachClient(ctx: RelayContext, msg: WsTerminalInitMessage): Promise<void>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=terminal-attach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-attach.d.ts","sourceRoot":"","sources":["../../src/ws/terminal-attach.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAE7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,eAAe,CAAC;AAG9D,KAAK,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAmFhF;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,qBAAqB,GACzB,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { encodeExitFrame, encodeOutputFrame, } from "@parasor/shared";
|
|
2
|
+
import { applyServerBackpressure } from "./terminal-flow.js";
|
|
3
|
+
const OUTPUT_TRACE_SAMPLE_CHUNKS = 100;
|
|
4
|
+
const OUTPUT_TRACE_SAMPLE_BYTES = 64 * 1024;
|
|
5
|
+
const OUTPUT_TRACE_SAMPLE_MS = 1000;
|
|
6
|
+
function sendJson(ws, msg) {
|
|
7
|
+
if (ws.readyState === 1)
|
|
8
|
+
ws.send(JSON.stringify(msg));
|
|
9
|
+
}
|
|
10
|
+
class OutputTraceSampler {
|
|
11
|
+
ctx;
|
|
12
|
+
wire;
|
|
13
|
+
chunks = 0;
|
|
14
|
+
bytes = 0;
|
|
15
|
+
firstAt = 0;
|
|
16
|
+
firstGeneration = null;
|
|
17
|
+
lastGeneration = null;
|
|
18
|
+
firstSeq = null;
|
|
19
|
+
lastSeq = null;
|
|
20
|
+
emittedFirst = false;
|
|
21
|
+
constructor(ctx, wire) {
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
this.wire = wire;
|
|
24
|
+
}
|
|
25
|
+
record(chunk) {
|
|
26
|
+
if (!this.ctx.traceRecorder?.isEnabled())
|
|
27
|
+
return;
|
|
28
|
+
const now = performance.now();
|
|
29
|
+
if (this.chunks === 0) {
|
|
30
|
+
this.firstAt = now;
|
|
31
|
+
this.firstGeneration = chunk.generation ?? null;
|
|
32
|
+
this.firstSeq = chunk.seq === undefined ? null : String(chunk.seq);
|
|
33
|
+
}
|
|
34
|
+
this.chunks += 1;
|
|
35
|
+
this.bytes += chunk.byteLength;
|
|
36
|
+
this.lastGeneration = chunk.generation ?? this.lastGeneration;
|
|
37
|
+
this.lastSeq = chunk.seq === undefined ? this.lastSeq : String(chunk.seq);
|
|
38
|
+
if (!this.emittedFirst ||
|
|
39
|
+
this.chunks >= OUTPUT_TRACE_SAMPLE_CHUNKS ||
|
|
40
|
+
this.bytes >= OUTPUT_TRACE_SAMPLE_BYTES ||
|
|
41
|
+
now - this.firstAt >= OUTPUT_TRACE_SAMPLE_MS) {
|
|
42
|
+
this.flush(now);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
flush(now) {
|
|
46
|
+
if (this.chunks === 0)
|
|
47
|
+
return;
|
|
48
|
+
this.ctx.traceRecorder?.record("ws-output", {
|
|
49
|
+
wire: this.wire,
|
|
50
|
+
chunks: this.chunks,
|
|
51
|
+
byteLength: this.bytes,
|
|
52
|
+
windowMs: Math.round((now - this.firstAt) * 10) / 10,
|
|
53
|
+
firstGeneration: this.firstGeneration,
|
|
54
|
+
lastGeneration: this.lastGeneration,
|
|
55
|
+
firstSeq: this.firstSeq,
|
|
56
|
+
lastSeq: this.lastSeq,
|
|
57
|
+
}, { sessionId: this.ctx.sessionId, clientId: this.ctx.clientId });
|
|
58
|
+
this.emittedFirst = true;
|
|
59
|
+
this.chunks = 0;
|
|
60
|
+
this.bytes = 0;
|
|
61
|
+
this.firstAt = 0;
|
|
62
|
+
this.firstGeneration = null;
|
|
63
|
+
this.lastGeneration = null;
|
|
64
|
+
this.firstSeq = null;
|
|
65
|
+
this.lastSeq = null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* First-frame attach: choose the binary or legacy path from declared
|
|
70
|
+
* capabilities. The caller ({@link handleInitFrame}) has already validated that
|
|
71
|
+
* `msg` is the mandatory `init` and recorded the handshake.
|
|
72
|
+
*/
|
|
73
|
+
export async function attachClient(ctx, msg) {
|
|
74
|
+
const declared = msg.capabilities;
|
|
75
|
+
if (declared?.binary) {
|
|
76
|
+
await attachBinaryClient(ctx, msg, declared);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await attachLegacyClient(ctx, msg);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Binary capability path: atomically attach (replay decision + chunk listener
|
|
83
|
+
* registered under the host mutex), ack, then flush full/delta replay. Honors
|
|
84
|
+
* the attach fencing mid-await close race by releasing the freshly minted entry.
|
|
85
|
+
*/
|
|
86
|
+
async function attachBinaryClient(ctx, msg, declared) {
|
|
87
|
+
const { ws, state, sessionId, clientId, ptyManager, traceRecorder } = ctx;
|
|
88
|
+
const outputTrace = new OutputTraceSampler(ctx, "binary");
|
|
89
|
+
// -- the host method holds
|
|
90
|
+
// its own mutex while computing the replay decision and registering
|
|
91
|
+
// the chunk listener, so init-ack / replay / live OUTPUT cannot
|
|
92
|
+
// interleave on the wire.
|
|
93
|
+
traceRecorder?.record("pty-attach-start", { mode: "binary", cols: msg.cols, rows: msg.rows }, { sessionId, clientId });
|
|
94
|
+
const attachStart = performance.now();
|
|
95
|
+
const result = await ptyManager.attachClient(sessionId, clientId, msg.cols, msg.rows, {
|
|
96
|
+
binary: declared.binary,
|
|
97
|
+
chunkedReplay: declared.chunkedReplay,
|
|
98
|
+
lastSeen: declared.lastSeen,
|
|
99
|
+
}, {
|
|
100
|
+
onChunk: (generation, seq, data) => {
|
|
101
|
+
outputTrace.record({ byteLength: data.byteLength, generation, seq });
|
|
102
|
+
if (ws.readyState === 1) {
|
|
103
|
+
ws.send(encodeOutputFrame(generation, seq, data));
|
|
104
|
+
applyServerBackpressure(ws, state, sessionId, clientId, ptyManager);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
onExit: (exitCode) => {
|
|
108
|
+
if (ws.readyState === 1) {
|
|
109
|
+
ws.send(encodeExitFrame(exitCode));
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
if (!result.ok) {
|
|
114
|
+
traceRecorder?.record("pty-attach-failed", {
|
|
115
|
+
mode: "binary",
|
|
116
|
+
durationMs: Math.round((performance.now() - attachStart) * 10) / 10,
|
|
117
|
+
reason: "unavailable",
|
|
118
|
+
}, { sessionId, clientId });
|
|
119
|
+
ws.close(1008, "Session unavailable");
|
|
120
|
+
traceRecorder?.record("ws-close", { code: 1008, reason: "Session unavailable" }, { sessionId, clientId });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
state.attachToken = result.attachToken;
|
|
124
|
+
traceRecorder?.record("pty-attach-complete", {
|
|
125
|
+
mode: "binary",
|
|
126
|
+
durationMs: Math.round((performance.now() - attachStart) * 10) / 10,
|
|
127
|
+
replay: result.replay,
|
|
128
|
+
binary: result.capabilities.binary,
|
|
129
|
+
chunkedReplay: result.capabilities.chunkedReplay,
|
|
130
|
+
...(result.replayDiagnostics
|
|
131
|
+
? { replayDiagnostics: result.replayDiagnostics }
|
|
132
|
+
: {}),
|
|
133
|
+
}, { sessionId, clientId });
|
|
134
|
+
// Attach fencing: WS may have closed while attachClient() was awaiting.
|
|
135
|
+
// The host has already minted a fresh entry under our token; if we
|
|
136
|
+
// skip the cleanup detach (no init-ack will fire), the entry leaks
|
|
137
|
+
// forever. Release it now using the just-captured token so a future
|
|
138
|
+
// reconnect with the same clientId is not blocked by ghost state.
|
|
139
|
+
if (ws.readyState !== 1) {
|
|
140
|
+
ptyManager.detachClient(sessionId, clientId, result.attachToken);
|
|
141
|
+
traceRecorder?.record("pty-attach-abandoned", {
|
|
142
|
+
mode: "binary",
|
|
143
|
+
durationMs: Math.round((performance.now() - attachStart) * 10) / 10,
|
|
144
|
+
attachToken: result.attachToken,
|
|
145
|
+
}, { sessionId, clientId });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
sendJson(ws, {
|
|
149
|
+
type: "init-ack",
|
|
150
|
+
capabilities: result.capabilities,
|
|
151
|
+
serverState: result.serverState,
|
|
152
|
+
replay: result.replay,
|
|
153
|
+
});
|
|
154
|
+
traceRecorder?.record("ws-init-ack", {
|
|
155
|
+
replay: result.replay,
|
|
156
|
+
generation: result.serverState.generation,
|
|
157
|
+
binary: result.capabilities.binary,
|
|
158
|
+
chunkedReplay: result.capabilities.chunkedReplay,
|
|
159
|
+
}, { sessionId, clientId });
|
|
160
|
+
if (result.replay === "full" && result.fullReplay) {
|
|
161
|
+
const fullReplay = result.fullReplay;
|
|
162
|
+
traceRecorder?.recordLazy("ws-replay", () => ({
|
|
163
|
+
replay: "full",
|
|
164
|
+
dataLength: fullReplay.length,
|
|
165
|
+
...(result.replayDiagnostics
|
|
166
|
+
? { replayDiagnostics: result.replayDiagnostics }
|
|
167
|
+
: {}),
|
|
168
|
+
}), { sessionId, clientId });
|
|
169
|
+
sendJson(ws, { type: "replay", data: fullReplay });
|
|
170
|
+
}
|
|
171
|
+
else if (result.replay === "delta" && result.chunks) {
|
|
172
|
+
for (const chunk of result.chunks) {
|
|
173
|
+
if (ws.readyState !== 1)
|
|
174
|
+
break;
|
|
175
|
+
traceRecorder?.recordLazy("ws-replay", () => ({
|
|
176
|
+
replay: "delta",
|
|
177
|
+
byteLength: chunk.data.byteLength,
|
|
178
|
+
generation: chunk.generation,
|
|
179
|
+
seq: String(chunk.seq),
|
|
180
|
+
}), { sessionId, clientId });
|
|
181
|
+
ws.send(encodeOutputFrame(chunk.generation, chunk.seq, chunk.data));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// If the negotiated path turned out to be legacy (server doesn't
|
|
185
|
+
// support binary, e.g. RemotePtyHost), `binaryAttached` stays
|
|
186
|
+
// false so subsequent JSON input/resize/refresh keeps working.
|
|
187
|
+
state.binaryAttached = result.capabilities.binary;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Legacy path -- old client without capabilities. String OUTPUT is relayed
|
|
191
|
+
* verbatim via the host's `initClient` listener. Honors the same attach fencing
|
|
192
|
+
* mid-await close race as the binary path.
|
|
193
|
+
*/
|
|
194
|
+
async function attachLegacyClient(ctx, msg) {
|
|
195
|
+
const { ws, state, sessionId, clientId, ptyManager, traceRecorder } = ctx;
|
|
196
|
+
const outputTrace = new OutputTraceSampler(ctx, "legacy");
|
|
197
|
+
traceRecorder?.record("pty-attach-start", { mode: "legacy", cols: msg.cols, rows: msg.rows }, { sessionId, clientId });
|
|
198
|
+
const legacyAttachStart = performance.now();
|
|
199
|
+
const initResult = await ptyManager.initClient(sessionId, clientId, msg.cols, msg.rows, (data) => {
|
|
200
|
+
outputTrace.record({ byteLength: Buffer.byteLength(data, "utf8") });
|
|
201
|
+
if (ws.readyState === 1) {
|
|
202
|
+
ws.send(data);
|
|
203
|
+
applyServerBackpressure(ws, state, sessionId, clientId, ptyManager);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
if (!initResult.ok) {
|
|
207
|
+
traceRecorder?.record("pty-attach-failed", {
|
|
208
|
+
mode: "legacy",
|
|
209
|
+
durationMs: Math.round((performance.now() - legacyAttachStart) * 10) / 10,
|
|
210
|
+
reason: "unavailable",
|
|
211
|
+
}, { sessionId, clientId });
|
|
212
|
+
ws.close(1008, "Session unavailable");
|
|
213
|
+
traceRecorder?.record("ws-close", { code: 1008, reason: "Session unavailable" }, { sessionId, clientId });
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
state.attachToken = initResult.attachToken;
|
|
217
|
+
traceRecorder?.record("pty-attach-complete", {
|
|
218
|
+
mode: "legacy",
|
|
219
|
+
durationMs: Math.round((performance.now() - legacyAttachStart) * 10) / 10,
|
|
220
|
+
}, { sessionId, clientId });
|
|
221
|
+
// Attach fencing: same race as the binary path -- release the freshly-
|
|
222
|
+
// minted entry if the WS closed mid-await so we do not leak a ghost
|
|
223
|
+
// listener under this clientId.
|
|
224
|
+
if (ws.readyState !== 1) {
|
|
225
|
+
ptyManager.detachClient(sessionId, clientId, initResult.attachToken);
|
|
226
|
+
traceRecorder?.record("pty-attach-abandoned", {
|
|
227
|
+
mode: "legacy",
|
|
228
|
+
durationMs: Math.round((performance.now() - legacyAttachStart) * 10) / 10,
|
|
229
|
+
attachToken: initResult.attachToken,
|
|
230
|
+
}, { sessionId, clientId });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=terminal-attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-attach.js","sourceRoot":"","sources":["../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,GAAG,EAAE;KAC1E,EACD,EAAE,SAAS,EAAE,QAAQ,EAAE,CACxB,CAAC;IACF,uEAAuE;IACvE,oEAAoE;IACpE,gCAAgC;IAChC,IAAI,EAAE,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACxB,UAAU,CAAC,YAAY,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QACrE,aAAa,EAAE,MAAM,CACnB,sBAAsB,EACtB;YACE,IAAI,EAAE,QAAQ;YACd,UAAU,EACR,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,iBAAiB,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;YAC/D,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,EACD,EAAE,SAAS,EAAE,QAAQ,EAAE,CACxB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PtyHost } from "../pty/host.js";
|
|
2
|
+
import type { TerminalRelayState, TerminalWs } from "./terminal.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reconcile the host's single per-client `flowPaused` bit against the relay's
|
|
5
|
+
* two independent pause reasons. Pause when either the client or the server
|
|
6
|
+
* wants it; resume only when both are clear. Idempotent -- the host no-ops a
|
|
7
|
+
* repeated pause/resume -- so it is safe to call after any reason flips.
|
|
8
|
+
*/
|
|
9
|
+
export declare function syncPtyFlow(state: TerminalRelayState, sessionId: string, clientId: string, ptyManager: PtyHost): void;
|
|
10
|
+
/**
|
|
11
|
+
* Apply send backpressure after relaying a chunk to {@link ws}. Pauses the PTY
|
|
12
|
+
* when the socket's send buffer is congested and starts a drain poll that
|
|
13
|
+
* resumes it once the buffer empties; closes 1013 if the buffer blows past the
|
|
14
|
+
* hard ceiling. No-op when the transport does not expose `bufferedAmount`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyServerBackpressure(ws: TerminalWs, state: TerminalRelayState, sessionId: string, clientId: string, ptyManager: PtyHost): void;
|
|
17
|
+
//# sourceMappingURL=terminal-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-flow.d.ts","sourceRoot":"","sources":["../../src/ws/terminal-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAgBpE;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,kBAAkB,EACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,GAClB,IAAI,CAMN;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,UAAU,EACd,KAAK,EAAE,kBAAkB,EACzB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,GAClB,IAAI,CA6BN"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Server-side send backpressure for the terminal socket. A client that stops
|
|
3
|
+
* draining its socket (mobile background, slow link, frozen tab the keepalive
|
|
4
|
+
* has not yet reaped) would otherwise grow the server's per-socket send buffer
|
|
5
|
+
* without bound. When `bufferedAmount` reaches the high-water mark we pause the
|
|
6
|
+
* PTY via the existing flow-control path; a poll resumes it once the buffer
|
|
7
|
+
* drains to the low-water mark. The hard ceiling is the backstop: a socket that
|
|
8
|
+
* blows past it is closed (1013) and the client reconnects + replays.
|
|
9
|
+
*/
|
|
10
|
+
const BACKPRESSURE_HIGH_WATER = 1024 * 1024; // 1 MiB -- pause the PTY
|
|
11
|
+
const BACKPRESSURE_LOW_WATER = 256 * 1024; // 256 KiB -- resume the PTY
|
|
12
|
+
const BACKPRESSURE_HARD_LIMIT = 8 * 1024 * 1024; // 8 MiB -- give up, close 1013
|
|
13
|
+
const BACKPRESSURE_DRAIN_POLL_MS = 100;
|
|
14
|
+
/**
|
|
15
|
+
* Reconcile the host's single per-client `flowPaused` bit against the relay's
|
|
16
|
+
* two independent pause reasons. Pause when either the client or the server
|
|
17
|
+
* wants it; resume only when both are clear. Idempotent -- the host no-ops a
|
|
18
|
+
* repeated pause/resume -- so it is safe to call after any reason flips.
|
|
19
|
+
*/
|
|
20
|
+
export function syncPtyFlow(state, sessionId, clientId, ptyManager) {
|
|
21
|
+
if (state.clientPaused || state.serverPaused) {
|
|
22
|
+
ptyManager.pauseOutput(sessionId, clientId);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
ptyManager.resumeOutput(sessionId, clientId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Apply send backpressure after relaying a chunk to {@link ws}. Pauses the PTY
|
|
30
|
+
* when the socket's send buffer is congested and starts a drain poll that
|
|
31
|
+
* resumes it once the buffer empties; closes 1013 if the buffer blows past the
|
|
32
|
+
* hard ceiling. No-op when the transport does not expose `bufferedAmount`.
|
|
33
|
+
*/
|
|
34
|
+
export function applyServerBackpressure(ws, state, sessionId, clientId, ptyManager) {
|
|
35
|
+
const buffered = ws.raw?.bufferedAmount ?? 0;
|
|
36
|
+
if (buffered > BACKPRESSURE_HARD_LIMIT) {
|
|
37
|
+
ws.close(1013, "backpressure");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (buffered < BACKPRESSURE_HIGH_WATER)
|
|
41
|
+
return;
|
|
42
|
+
if (state.serverPaused)
|
|
43
|
+
return;
|
|
44
|
+
state.serverPaused = true;
|
|
45
|
+
syncPtyFlow(state, sessionId, clientId, ptyManager);
|
|
46
|
+
const timer = setInterval(() => {
|
|
47
|
+
const depth = ws.raw?.bufferedAmount ?? 0;
|
|
48
|
+
if (ws.readyState !== 1 || depth <= BACKPRESSURE_LOW_WATER) {
|
|
49
|
+
clearInterval(timer);
|
|
50
|
+
state.drainTimer = undefined;
|
|
51
|
+
if (state.serverPaused) {
|
|
52
|
+
state.serverPaused = false;
|
|
53
|
+
// Honor a still-active client-driven pause: resume only if the client
|
|
54
|
+
// is not itself paused (syncPtyFlow ANDs the two reasons).
|
|
55
|
+
if (ws.readyState === 1) {
|
|
56
|
+
syncPtyFlow(state, sessionId, clientId, ptyManager);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, BACKPRESSURE_DRAIN_POLL_MS);
|
|
61
|
+
timer.unref?.();
|
|
62
|
+
state.drainTimer = timer;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=terminal-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-flow.js","sourceRoot":"","sources":["../../src/ws/terminal-flow.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,yBAAyB;AACtE,MAAM,sBAAsB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,4BAA4B;AACvE,MAAM,uBAAuB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,+BAA+B;AAChF,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,KAAyB,EACzB,SAAiB,EACjB,QAAgB,EAChB,UAAmB;IAEnB,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAC7C,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,EAAc,EACd,KAAyB,EACzB,SAAiB,EACjB,QAAgB,EAChB,UAAmB;IAEnB,MAAM,QAAQ,GAAG,EAAE,C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