@celljs/ta-host 4.8.0 → 4.9.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/README.en.md +33 -5
- package/README.md +33 -5
- package/cell.schema.json +4 -0
- package/cell.yml +2 -0
- package/esm/node/client-tool-broker.d.ts +11 -3
- package/esm/node/client-tool-broker.js +23 -3
- package/esm/node/host-protocol.d.ts +22 -1
- package/esm/node/host-protocol.js +1 -0
- package/esm/node/index.d.ts +4 -0
- package/esm/node/index.js +4 -0
- package/esm/node/live-run.d.ts +22 -0
- package/esm/node/live-run.js +58 -0
- package/esm/node/message-page.d.ts +17 -0
- package/esm/node/message-page.js +71 -0
- package/esm/node/package-server-impl.d.ts +9 -1
- package/esm/node/package-server-impl.js +16 -1
- package/esm/node/relay-bridge.d.ts +9 -1
- package/esm/node/relay-bridge.js +44 -4
- package/esm/node/session-catalog.d.ts +69 -0
- package/esm/node/session-catalog.js +211 -0
- package/esm/node/session-info-util.d.ts +4 -1
- package/esm/node/session-info-util.js +8 -3
- package/esm/node/settings-store.d.ts +1 -4
- package/esm/node/settings-store.js +11 -3
- package/esm/node/sign-in/access-server-impl.d.ts +19 -0
- package/esm/node/sign-in/access-server-impl.js +82 -0
- package/esm/node/sign-in/access-store.d.ts +65 -0
- package/esm/node/sign-in/access-store.js +175 -0
- package/esm/node/sign-in/index.d.ts +7 -0
- package/esm/node/sign-in/index.js +8 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +58 -0
- package/esm/node/sign-in/sign-in-flow.js +104 -0
- package/esm/node/sign-in/sign-in-middleware.d.ts +10 -0
- package/esm/node/sign-in/sign-in-middleware.js +48 -0
- package/esm/node/sign-in/sign-in-pages.d.ts +31 -0
- package/esm/node/sign-in/sign-in-pages.js +118 -0
- package/esm/node/sign-in/sign-in-provider.d.ts +135 -0
- package/esm/node/sign-in/sign-in-provider.js +225 -0
- package/esm/node/sign-in/ta-sign-in.d.ts +10 -0
- package/esm/node/sign-in/ta-sign-in.js +32 -0
- package/esm/node/ta-access.d.ts +7 -0
- package/esm/node/ta-access.js +30 -1
- package/esm/node/ta-server-impl.d.ts +8 -3
- package/esm/node/ta-server-impl.js +25 -6
- package/esm/node/ta-session-factory.d.ts +1 -1
- package/esm/node/ta-session-factory.js +14 -4
- package/esm/node/ta-session-registry.d.ts +2 -0
- package/esm/node/ta-session-registry.js +23 -3
- package/esm/node/ta-session.d.ts +24 -2
- package/esm/node/ta-session.js +83 -6
- package/esm/node/temporary-packages.d.ts +46 -0
- package/esm/node/temporary-packages.js +114 -0
- package/esm/node/temporary-purge.d.ts +13 -0
- package/esm/node/temporary-purge.js +51 -0
- package/esm/node/web-extension-catalog.d.ts +28 -1
- package/esm/node/web-extension-catalog.js +173 -5
- package/esm/node/web-extension-util.d.ts +5 -1
- package/esm/node/web-extension-util.js +36 -5
- package/esm/node/workspace-service.js +1 -1
- package/lib/node/client-tool-broker.d.ts +11 -3
- package/lib/node/client-tool-broker.js +23 -3
- package/lib/node/host-protocol.d.ts +22 -1
- package/lib/node/host-protocol.js +2 -1
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +4 -0
- package/lib/node/live-run.d.ts +23 -0
- package/lib/node/live-run.js +62 -0
- package/lib/node/message-page.d.ts +18 -0
- package/lib/node/message-page.js +74 -0
- package/lib/node/package-server-impl.d.ts +9 -1
- package/lib/node/package-server-impl.js +15 -0
- package/lib/node/relay-bridge.d.ts +9 -1
- package/lib/node/relay-bridge.js +43 -3
- package/lib/node/session-catalog.d.ts +70 -0
- package/lib/node/session-catalog.js +214 -0
- package/lib/node/session-info-util.d.ts +4 -1
- package/lib/node/session-info-util.js +7 -2
- package/lib/node/settings-store.d.ts +1 -4
- package/lib/node/settings-store.js +11 -3
- package/lib/node/sign-in/access-server-impl.d.ts +20 -0
- package/lib/node/sign-in/access-server-impl.js +85 -0
- package/lib/node/sign-in/access-store.d.ts +66 -0
- package/lib/node/sign-in/access-store.js +179 -0
- package/lib/node/sign-in/index.d.ts +8 -0
- package/lib/node/sign-in/index.js +24 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +59 -0
- package/lib/node/sign-in/sign-in-flow.js +108 -0
- package/lib/node/sign-in/sign-in-middleware.d.ts +11 -0
- package/lib/node/sign-in/sign-in-middleware.js +51 -0
- package/lib/node/sign-in/sign-in-pages.d.ts +32 -0
- package/lib/node/sign-in/sign-in-pages.js +121 -0
- package/lib/node/sign-in/sign-in-provider.d.ts +136 -0
- package/lib/node/sign-in/sign-in-provider.js +232 -0
- package/lib/node/sign-in/ta-sign-in.d.ts +11 -0
- package/lib/node/sign-in/ta-sign-in.js +35 -0
- package/lib/node/ta-access.d.ts +7 -0
- package/lib/node/ta-access.js +30 -1
- package/lib/node/ta-server-impl.d.ts +8 -3
- package/lib/node/ta-server-impl.js +24 -5
- package/lib/node/ta-session-factory.d.ts +1 -1
- package/lib/node/ta-session-factory.js +14 -4
- package/lib/node/ta-session-registry.d.ts +2 -0
- package/lib/node/ta-session-registry.js +23 -3
- package/lib/node/ta-session.d.ts +24 -2
- package/lib/node/ta-session.js +83 -6
- package/lib/node/temporary-packages.d.ts +47 -0
- package/lib/node/temporary-packages.js +118 -0
- package/lib/node/temporary-purge.d.ts +14 -0
- package/lib/node/temporary-purge.js +54 -0
- package/lib/node/web-extension-catalog.d.ts +28 -1
- package/lib/node/web-extension-catalog.js +172 -4
- package/lib/node/web-extension-util.d.ts +5 -1
- package/lib/node/web-extension-util.js +36 -5
- package/lib/node/workspace-service.js +1 -1
- package/package.json +17 -12
- package/esm/node/auth-server-impl.js.map +0 -1
- package/esm/node/client-channel.js.map +0 -1
- package/esm/node/client-tool-broker.js.map +0 -1
- package/esm/node/event-log.js.map +0 -1
- package/esm/node/exec-environment-factory.js.map +0 -1
- package/esm/node/extension-data-notifier.js.map +0 -1
- package/esm/node/extension-data.js.map +0 -1
- package/esm/node/extension-providers.js.map +0 -1
- package/esm/node/host-protocol.js.map +0 -1
- package/esm/node/index.js.map +0 -1
- package/esm/node/module.js.map +0 -1
- package/esm/node/package-host-extension.js.map +0 -1
- package/esm/node/package-hosts.js.map +0 -1
- package/esm/node/package-server-impl.js.map +0 -1
- package/esm/node/package-switch.js.map +0 -1
- package/esm/node/receipt-book.js.map +0 -1
- package/esm/node/relay-bridge.js.map +0 -1
- package/esm/node/remote/index.js.map +0 -1
- package/esm/node/remote/pi-directories.js.map +0 -1
- package/esm/node/remote/port-forwards.js.map +0 -1
- package/esm/node/remote/remote-hosts.js.map +0 -1
- package/esm/node/remote/remote-protocol.js.map +0 -1
- package/esm/node/remote/remote-server-impl.js.map +0 -1
- package/esm/node/remote-ui-context.js.map +0 -1
- package/esm/node/session-files.js.map +0 -1
- package/esm/node/session-info-util.js.map +0 -1
- package/esm/node/session-storage/file-session-storage.js.map +0 -1
- package/esm/node/session-storage/index.js.map +0 -1
- package/esm/node/session-storage/session-storage-protocol.js.map +0 -1
- package/esm/node/session-storage/stored-session.js.map +0 -1
- package/esm/node/settings-server-impl.js.map +0 -1
- package/esm/node/settings-store.js.map +0 -1
- package/esm/node/ta-access.js.map +0 -1
- package/esm/node/ta-errors.js.map +0 -1
- package/esm/node/ta-event-util.js.map +0 -1
- package/esm/node/ta-server-impl.js.map +0 -1
- package/esm/node/ta-session-factory.js.map +0 -1
- package/esm/node/ta-session-registry.js.map +0 -1
- package/esm/node/ta-session.js.map +0 -1
- package/esm/node/terminal-protocol.js.map +0 -1
- package/esm/node/terminal-service.js.map +0 -1
- package/esm/node/terminal-util.js.map +0 -1
- package/esm/node/web-extension-catalog.js.map +0 -1
- package/esm/node/web-extension-util.js.map +0 -1
- package/esm/node/working-directory.js.map +0 -1
- package/esm/node/workspace-files.js.map +0 -1
- package/esm/node/workspace-protocol.js.map +0 -1
- package/esm/node/workspace-server-impl.js.map +0 -1
- package/esm/node/workspace-service.js.map +0 -1
- package/esm/node/workspace-util.js.map +0 -1
- package/lib/node/auth-server-impl.d.ts.map +0 -1
- package/lib/node/auth-server-impl.js.map +0 -1
- package/lib/node/auth-server-impl.spec.d.ts +0 -2
- package/lib/node/auth-server-impl.spec.d.ts.map +0 -1
- package/lib/node/auth-server-impl.spec.js +0 -47
- package/lib/node/auth-server-impl.spec.js.map +0 -1
- package/lib/node/client-channel.d.ts.map +0 -1
- package/lib/node/client-channel.js.map +0 -1
- package/lib/node/client-channel.spec.d.ts +0 -2
- package/lib/node/client-channel.spec.d.ts.map +0 -1
- package/lib/node/client-channel.spec.js +0 -106
- package/lib/node/client-channel.spec.js.map +0 -1
- package/lib/node/client-tool-broker.d.ts.map +0 -1
- package/lib/node/client-tool-broker.js.map +0 -1
- package/lib/node/client-tool-broker.spec.d.ts +0 -2
- package/lib/node/client-tool-broker.spec.d.ts.map +0 -1
- package/lib/node/client-tool-broker.spec.js +0 -49
- package/lib/node/client-tool-broker.spec.js.map +0 -1
- package/lib/node/event-log.d.ts.map +0 -1
- package/lib/node/event-log.js.map +0 -1
- package/lib/node/event-log.spec.d.ts +0 -2
- package/lib/node/event-log.spec.d.ts.map +0 -1
- package/lib/node/event-log.spec.js +0 -48
- package/lib/node/event-log.spec.js.map +0 -1
- package/lib/node/exec-environment-factory.d.ts.map +0 -1
- package/lib/node/exec-environment-factory.js.map +0 -1
- package/lib/node/extension-data-notifier.d.ts.map +0 -1
- package/lib/node/extension-data-notifier.js.map +0 -1
- package/lib/node/extension-data-notifier.spec.d.ts +0 -2
- package/lib/node/extension-data-notifier.spec.d.ts.map +0 -1
- package/lib/node/extension-data-notifier.spec.js +0 -35
- package/lib/node/extension-data-notifier.spec.js.map +0 -1
- package/lib/node/extension-data.d.ts.map +0 -1
- package/lib/node/extension-data.js.map +0 -1
- package/lib/node/extension-data.spec.d.ts +0 -2
- package/lib/node/extension-data.spec.d.ts.map +0 -1
- package/lib/node/extension-data.spec.js +0 -99
- package/lib/node/extension-data.spec.js.map +0 -1
- package/lib/node/extension-providers.d.ts.map +0 -1
- package/lib/node/extension-providers.js.map +0 -1
- package/lib/node/host-protocol.d.ts.map +0 -1
- package/lib/node/host-protocol.js.map +0 -1
- package/lib/node/index.d.ts.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/module.d.ts.map +0 -1
- package/lib/node/module.js.map +0 -1
- package/lib/node/package-host-extension.d.ts.map +0 -1
- package/lib/node/package-host-extension.js.map +0 -1
- package/lib/node/package-hosts.d.ts.map +0 -1
- package/lib/node/package-hosts.js.map +0 -1
- package/lib/node/package-hosts.spec.d.ts +0 -2
- package/lib/node/package-hosts.spec.d.ts.map +0 -1
- package/lib/node/package-hosts.spec.js +0 -53
- package/lib/node/package-hosts.spec.js.map +0 -1
- package/lib/node/package-server-impl.d.ts.map +0 -1
- package/lib/node/package-server-impl.js.map +0 -1
- package/lib/node/package-switch.d.ts.map +0 -1
- package/lib/node/package-switch.js.map +0 -1
- package/lib/node/receipt-book.d.ts.map +0 -1
- package/lib/node/receipt-book.js.map +0 -1
- package/lib/node/receipt-book.spec.d.ts +0 -2
- package/lib/node/receipt-book.spec.d.ts.map +0 -1
- package/lib/node/receipt-book.spec.js +0 -39
- package/lib/node/receipt-book.spec.js.map +0 -1
- package/lib/node/relay-bridge.d.ts.map +0 -1
- package/lib/node/relay-bridge.js.map +0 -1
- package/lib/node/remote/index.d.ts.map +0 -1
- package/lib/node/remote/index.js.map +0 -1
- package/lib/node/remote/pi-directories.d.ts.map +0 -1
- package/lib/node/remote/pi-directories.js.map +0 -1
- package/lib/node/remote/port-forwards.d.ts.map +0 -1
- package/lib/node/remote/port-forwards.js.map +0 -1
- package/lib/node/remote/remote-hosts.d.ts.map +0 -1
- package/lib/node/remote/remote-hosts.js.map +0 -1
- package/lib/node/remote/remote-protocol.d.ts.map +0 -1
- package/lib/node/remote/remote-protocol.js.map +0 -1
- package/lib/node/remote/remote-server-impl.d.ts.map +0 -1
- package/lib/node/remote/remote-server-impl.js.map +0 -1
- package/lib/node/remote/remote.spec.d.ts +0 -2
- package/lib/node/remote/remote.spec.d.ts.map +0 -1
- package/lib/node/remote/remote.spec.js +0 -130
- package/lib/node/remote/remote.spec.js.map +0 -1
- package/lib/node/remote-ui-context.d.ts.map +0 -1
- package/lib/node/remote-ui-context.js.map +0 -1
- package/lib/node/remote-ui-context.spec.d.ts +0 -2
- package/lib/node/remote-ui-context.spec.d.ts.map +0 -1
- package/lib/node/remote-ui-context.spec.js +0 -85
- package/lib/node/remote-ui-context.spec.js.map +0 -1
- package/lib/node/session-files.d.ts.map +0 -1
- package/lib/node/session-files.js.map +0 -1
- package/lib/node/session-files.spec.d.ts +0 -2
- package/lib/node/session-files.spec.d.ts.map +0 -1
- package/lib/node/session-files.spec.js +0 -51
- package/lib/node/session-files.spec.js.map +0 -1
- package/lib/node/session-info-util.d.ts.map +0 -1
- package/lib/node/session-info-util.js.map +0 -1
- package/lib/node/session-info-util.spec.d.ts +0 -2
- package/lib/node/session-info-util.spec.d.ts.map +0 -1
- package/lib/node/session-info-util.spec.js +0 -22
- package/lib/node/session-info-util.spec.js.map +0 -1
- package/lib/node/session-storage/file-session-storage.d.ts.map +0 -1
- package/lib/node/session-storage/file-session-storage.js.map +0 -1
- package/lib/node/session-storage/file-session-storage.spec.d.ts +0 -2
- package/lib/node/session-storage/file-session-storage.spec.d.ts.map +0 -1
- package/lib/node/session-storage/file-session-storage.spec.js +0 -70
- package/lib/node/session-storage/file-session-storage.spec.js.map +0 -1
- package/lib/node/session-storage/index.d.ts.map +0 -1
- package/lib/node/session-storage/index.js.map +0 -1
- package/lib/node/session-storage/session-storage-protocol.d.ts.map +0 -1
- package/lib/node/session-storage/session-storage-protocol.js.map +0 -1
- package/lib/node/session-storage/stored-session.d.ts.map +0 -1
- package/lib/node/session-storage/stored-session.js.map +0 -1
- package/lib/node/session-storage/stored-session.spec.d.ts +0 -2
- package/lib/node/session-storage/stored-session.spec.d.ts.map +0 -1
- package/lib/node/session-storage/stored-session.spec.js +0 -73
- package/lib/node/session-storage/stored-session.spec.js.map +0 -1
- package/lib/node/settings-server-impl.d.ts.map +0 -1
- package/lib/node/settings-server-impl.js.map +0 -1
- package/lib/node/settings-store.d.ts.map +0 -1
- package/lib/node/settings-store.js.map +0 -1
- package/lib/node/settings-store.spec.d.ts +0 -2
- package/lib/node/settings-store.spec.d.ts.map +0 -1
- package/lib/node/settings-store.spec.js +0 -148
- package/lib/node/settings-store.spec.js.map +0 -1
- package/lib/node/ta-access.d.ts.map +0 -1
- package/lib/node/ta-access.js.map +0 -1
- package/lib/node/ta-access.spec.d.ts +0 -2
- package/lib/node/ta-access.spec.d.ts.map +0 -1
- package/lib/node/ta-access.spec.js +0 -33
- package/lib/node/ta-access.spec.js.map +0 -1
- package/lib/node/ta-errors.d.ts.map +0 -1
- package/lib/node/ta-errors.js.map +0 -1
- package/lib/node/ta-errors.spec.d.ts +0 -2
- package/lib/node/ta-errors.spec.d.ts.map +0 -1
- package/lib/node/ta-errors.spec.js +0 -25
- package/lib/node/ta-errors.spec.js.map +0 -1
- package/lib/node/ta-event-util.d.ts.map +0 -1
- package/lib/node/ta-event-util.js.map +0 -1
- package/lib/node/ta-event-util.spec.d.ts +0 -2
- package/lib/node/ta-event-util.spec.d.ts.map +0 -1
- package/lib/node/ta-event-util.spec.js +0 -28
- package/lib/node/ta-event-util.spec.js.map +0 -1
- package/lib/node/ta-server-impl.d.ts.map +0 -1
- package/lib/node/ta-server-impl.js.map +0 -1
- package/lib/node/ta-session-factory.d.ts.map +0 -1
- package/lib/node/ta-session-factory.js.map +0 -1
- package/lib/node/ta-session-registry.d.ts.map +0 -1
- package/lib/node/ta-session-registry.js.map +0 -1
- package/lib/node/ta-session.d.ts.map +0 -1
- package/lib/node/ta-session.js.map +0 -1
- package/lib/node/terminal-protocol.d.ts.map +0 -1
- package/lib/node/terminal-protocol.js.map +0 -1
- package/lib/node/terminal-service.d.ts.map +0 -1
- package/lib/node/terminal-service.js.map +0 -1
- package/lib/node/terminal-service.spec.d.ts +0 -2
- package/lib/node/terminal-service.spec.d.ts.map +0 -1
- package/lib/node/terminal-service.spec.js +0 -110
- package/lib/node/terminal-service.spec.js.map +0 -1
- package/lib/node/terminal-util.d.ts.map +0 -1
- package/lib/node/terminal-util.js.map +0 -1
- package/lib/node/terminal-util.spec.d.ts +0 -2
- package/lib/node/terminal-util.spec.d.ts.map +0 -1
- package/lib/node/terminal-util.spec.js +0 -95
- package/lib/node/terminal-util.spec.js.map +0 -1
- package/lib/node/web-extension-catalog.d.ts.map +0 -1
- package/lib/node/web-extension-catalog.js.map +0 -1
- package/lib/node/web-extension-catalog.spec.d.ts +0 -2
- package/lib/node/web-extension-catalog.spec.d.ts.map +0 -1
- package/lib/node/web-extension-catalog.spec.js +0 -157
- package/lib/node/web-extension-catalog.spec.js.map +0 -1
- package/lib/node/web-extension-util.d.ts.map +0 -1
- package/lib/node/web-extension-util.js.map +0 -1
- package/lib/node/working-directory.d.ts.map +0 -1
- package/lib/node/working-directory.js.map +0 -1
- package/lib/node/workspace-files.d.ts.map +0 -1
- package/lib/node/workspace-files.js.map +0 -1
- package/lib/node/workspace-files.spec.d.ts +0 -2
- package/lib/node/workspace-files.spec.d.ts.map +0 -1
- package/lib/node/workspace-files.spec.js +0 -133
- package/lib/node/workspace-files.spec.js.map +0 -1
- package/lib/node/workspace-protocol.d.ts.map +0 -1
- package/lib/node/workspace-protocol.js.map +0 -1
- package/lib/node/workspace-server-impl.d.ts.map +0 -1
- package/lib/node/workspace-server-impl.js.map +0 -1
- package/lib/node/workspace-service.d.ts.map +0 -1
- package/lib/node/workspace-service.js.map +0 -1
- package/lib/node/workspace-service.spec.d.ts +0 -2
- package/lib/node/workspace-service.spec.d.ts.map +0 -1
- package/lib/node/workspace-service.spec.js +0 -113
- package/lib/node/workspace-service.spec.js.map +0 -1
- package/lib/node/workspace-util.d.ts.map +0 -1
- package/lib/node/workspace-util.js.map +0 -1
- package/lib/node/workspace-util.spec.d.ts +0 -2
- package/lib/node/workspace-util.spec.d.ts.map +0 -1
- package/lib/node/workspace-util.spec.js +0 -44
- package/lib/node/workspace-util.spec.js.map +0 -1
- package/src/node/auth-server-impl.spec.ts +0 -49
- package/src/node/auth-server-impl.ts +0 -258
- package/src/node/client-channel.spec.ts +0 -117
- package/src/node/client-channel.ts +0 -94
- package/src/node/client-tool-broker.spec.ts +0 -53
- package/src/node/client-tool-broker.ts +0 -106
- package/src/node/event-log.spec.ts +0 -52
- package/src/node/event-log.ts +0 -59
- package/src/node/exec-environment-factory.ts +0 -66
- package/src/node/extension-data-notifier.spec.ts +0 -34
- package/src/node/extension-data-notifier.ts +0 -124
- package/src/node/extension-data.spec.ts +0 -105
- package/src/node/extension-data.ts +0 -180
- package/src/node/extension-providers.ts +0 -49
- package/src/node/host-protocol.ts +0 -62
- package/src/node/index.ts +0 -39
- package/src/node/module.ts +0 -4
- package/src/node/package-host-extension.ts +0 -23
- package/src/node/package-hosts.spec.ts +0 -54
- package/src/node/package-hosts.ts +0 -204
- package/src/node/package-server-impl.ts +0 -87
- package/src/node/package-switch.ts +0 -80
- package/src/node/receipt-book.spec.ts +0 -41
- package/src/node/receipt-book.ts +0 -40
- package/src/node/relay-bridge.ts +0 -94
- package/src/node/remote/index.ts +0 -5
- package/src/node/remote/pi-directories.ts +0 -49
- package/src/node/remote/port-forwards.ts +0 -148
- package/src/node/remote/remote-hosts.ts +0 -170
- package/src/node/remote/remote-protocol.ts +0 -57
- package/src/node/remote/remote-server-impl.ts +0 -60
- package/src/node/remote/remote.spec.ts +0 -142
- package/src/node/remote-ui-context.spec.ts +0 -93
- package/src/node/remote-ui-context.ts +0 -197
- package/src/node/session-files.spec.ts +0 -52
- package/src/node/session-files.ts +0 -41
- package/src/node/session-info-util.spec.ts +0 -23
- package/src/node/session-info-util.ts +0 -55
- package/src/node/session-storage/file-session-storage.spec.ts +0 -72
- package/src/node/session-storage/file-session-storage.ts +0 -145
- package/src/node/session-storage/index.ts +0 -3
- package/src/node/session-storage/session-storage-protocol.ts +0 -81
- package/src/node/session-storage/stored-session.spec.ts +0 -80
- package/src/node/session-storage/stored-session.ts +0 -149
- package/src/node/settings-server-impl.ts +0 -42
- package/src/node/settings-store.spec.ts +0 -158
- package/src/node/settings-store.ts +0 -327
- package/src/node/ta-access.spec.ts +0 -36
- package/src/node/ta-access.ts +0 -156
- package/src/node/ta-errors.spec.ts +0 -25
- package/src/node/ta-errors.ts +0 -75
- package/src/node/ta-event-util.spec.ts +0 -29
- package/src/node/ta-event-util.ts +0 -23
- package/src/node/ta-server-impl.ts +0 -341
- package/src/node/ta-session-factory.ts +0 -216
- package/src/node/ta-session-registry.ts +0 -75
- package/src/node/ta-session.ts +0 -241
- package/src/node/terminal-protocol.ts +0 -18
- package/src/node/terminal-service.spec.ts +0 -119
- package/src/node/terminal-service.ts +0 -291
- package/src/node/terminal-util.spec.ts +0 -109
- package/src/node/terminal-util.ts +0 -197
- package/src/node/web-extension-catalog.spec.ts +0 -172
- package/src/node/web-extension-catalog.ts +0 -177
- package/src/node/web-extension-util.ts +0 -144
- package/src/node/working-directory.ts +0 -71
- package/src/node/workspace-files.spec.ts +0 -145
- package/src/node/workspace-files.ts +0 -256
- package/src/node/workspace-protocol.ts +0 -24
- package/src/node/workspace-server-impl.ts +0 -108
- package/src/node/workspace-service.spec.ts +0 -123
- package/src/node/workspace-service.ts +0 -235
- package/src/node/workspace-util.spec.ts +0 -47
- package/src/node/workspace-util.ts +0 -103
package/src/node/ta-session.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import type { SessionLock } from '@celljs/ta-harness';
|
|
3
|
-
import type {
|
|
4
|
-
RpcExtensionUIResponse,
|
|
5
|
-
TaAttachResult,
|
|
6
|
-
TaClientToolResult,
|
|
7
|
-
TaEvent,
|
|
8
|
-
TaNavigateResult,
|
|
9
|
-
TaPromptInput,
|
|
10
|
-
TaPromptReceipt,
|
|
11
|
-
TaSessionInfo,
|
|
12
|
-
} from '@celljs/ta-protocol';
|
|
13
|
-
import type { ClientChannel } from './client-channel';
|
|
14
|
-
import type { ClientToolBroker } from './client-tool-broker';
|
|
15
|
-
import { EventLog } from './event-log';
|
|
16
|
-
import type { TaHostOptions } from './host-protocol';
|
|
17
|
-
import { ReceiptBook } from './receipt-book';
|
|
18
|
-
import { RemoteUiContext } from './remote-ui-context';
|
|
19
|
-
import { SessionInfoUtil } from './session-info-util';
|
|
20
|
-
import { TaEventUtil } from './ta-event-util';
|
|
21
|
-
|
|
22
|
-
type AgentSessionRuntime = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSessionRuntime;
|
|
23
|
-
type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSession;
|
|
24
|
-
type PromptDisposition = 'started' | 'queued' | 'handled';
|
|
25
|
-
|
|
26
|
-
export interface TaSessionContext {
|
|
27
|
-
runtime: AgentSessionRuntime;
|
|
28
|
-
lock: SessionLock;
|
|
29
|
-
/** The tools of the session that its clients run. */
|
|
30
|
-
clientTools: ClientToolBroker;
|
|
31
|
-
options: TaHostOptions;
|
|
32
|
-
/** The session should end: it has been idle, or an extension asked. */
|
|
33
|
-
requestClose(session: TaSession): void;
|
|
34
|
-
/** TaOpenSessionOptions.group. */
|
|
35
|
-
group?: string;
|
|
36
|
-
/** The location of the directory pi works in (PiDirectories.fromPi); default: that directory. */
|
|
37
|
-
locate?(cwd: string): string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* One open session of `ta serve`: pi's runtime, its event log, and the clients attached to it. Its id
|
|
42
|
-
* stays the same while the runtime moves between conversations.
|
|
43
|
-
*/
|
|
44
|
-
export class TaSession {
|
|
45
|
-
readonly id = randomUUID();
|
|
46
|
-
readonly createdAt = Date.now();
|
|
47
|
-
readonly ui: RemoteUiContext;
|
|
48
|
-
readonly runtime: AgentSessionRuntime;
|
|
49
|
-
protected readonly log: EventLog;
|
|
50
|
-
protected readonly receipts = new ReceiptBook();
|
|
51
|
-
protected readonly channels = new Set<ClientChannel>();
|
|
52
|
-
protected unsubscribe?: () => void;
|
|
53
|
-
protected idleTimer?: ReturnType<typeof setTimeout>;
|
|
54
|
-
protected started = false;
|
|
55
|
-
|
|
56
|
-
constructor(protected readonly context: TaSessionContext) {
|
|
57
|
-
this.runtime = context.runtime;
|
|
58
|
-
this.log = new EventLog(this.id, context.options.eventBufferBytes);
|
|
59
|
-
this.ui = new RemoteUiContext(event => this.publish(event));
|
|
60
|
-
context.clientTools.connect(event => this.publish(event));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get pi(): AgentSession {
|
|
64
|
-
return this.runtime.session;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Where the session works, as clients name it: a path, or an `ssh://` location. */
|
|
68
|
-
get cwd(): string {
|
|
69
|
-
return this.context.locate ? this.context.locate(this.runtime.cwd) : this.runtime.cwd;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async start(): Promise<void> {
|
|
73
|
-
this.runtime.setRebindSession(() => this.bind());
|
|
74
|
-
await this.bind();
|
|
75
|
-
this.started = true;
|
|
76
|
-
this.watchIdle();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
info(): TaSessionInfo {
|
|
80
|
-
const { pi } = this;
|
|
81
|
-
// Without a model pi's agent holds a placeholder that no runtime knows.
|
|
82
|
-
const model = pi.model && pi.modelRuntime.getModel(pi.model.provider, pi.model.id);
|
|
83
|
-
return {
|
|
84
|
-
sessionId: this.id,
|
|
85
|
-
piSessionId: pi.sessionId,
|
|
86
|
-
cwd: this.cwd,
|
|
87
|
-
sessionFile: pi.sessionFile,
|
|
88
|
-
sessionName: pi.sessionName,
|
|
89
|
-
firstMessage: SessionInfoUtil.firstMessage(pi.messages),
|
|
90
|
-
model: model ? `${model.provider}/${model.id}` : undefined,
|
|
91
|
-
isStreaming: pi.isStreaming,
|
|
92
|
-
messageCount: pi.messages.length,
|
|
93
|
-
attached: this.channels.size,
|
|
94
|
-
createdAt: this.createdAt,
|
|
95
|
-
updatedAt: SessionInfoUtil.updatedAt(pi.messages, this.createdAt),
|
|
96
|
-
group: this.context.group,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
attach(channel: ClientChannel, afterSeq?: number): TaAttachResult {
|
|
101
|
-
this.channels.add(channel);
|
|
102
|
-
this.watchIdle();
|
|
103
|
-
const { events, gap } = afterSeq === undefined ? { events: [], gap: false } : this.log.since(afterSeq);
|
|
104
|
-
return {
|
|
105
|
-
info: this.info(),
|
|
106
|
-
events,
|
|
107
|
-
pendingUi: this.ui.pendingRequests,
|
|
108
|
-
shownUi: this.ui.shownRequests,
|
|
109
|
-
pendingClientTools: this.context.clientTools.pendingRequests,
|
|
110
|
-
lastSeq: this.log.lastSeq,
|
|
111
|
-
gap,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
detach(channel: ClientChannel): void {
|
|
116
|
-
if (this.channels.delete(channel)) {
|
|
117
|
-
this.watchIdle();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
respondUi(response: RpcExtensionUIResponse): boolean {
|
|
122
|
-
return this.ui.respond(response);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
respondClientTool(result: TaClientToolResult): boolean {
|
|
126
|
-
return this.context.clientTools.respond(result);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
prompt(input: TaPromptInput): Promise<TaPromptReceipt> {
|
|
130
|
-
return this.accept(
|
|
131
|
-
input,
|
|
132
|
-
() =>
|
|
133
|
-
new Promise<PromptDisposition>((resolve, reject) => {
|
|
134
|
-
this.pi
|
|
135
|
-
.prompt(input.message, {
|
|
136
|
-
images: input.images,
|
|
137
|
-
streamingBehavior: input.streamingBehavior ?? 'followUp',
|
|
138
|
-
source: 'rpc',
|
|
139
|
-
preflightResult: resolve,
|
|
140
|
-
})
|
|
141
|
-
// After the preflight, failures of the run reach the clients as events.
|
|
142
|
-
.then(() => resolve('handled'), reject);
|
|
143
|
-
}),
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
steer(input: TaPromptInput): Promise<TaPromptReceipt> {
|
|
148
|
-
return this.accept(input, () => this.pi.steer(input.message, input.images, { source: 'rpc' }));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
followUp(input: TaPromptInput): Promise<TaPromptReceipt> {
|
|
152
|
-
return this.accept(input, () => this.pi.followUp(input.message, input.images, { source: 'rpc' }));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** pi's runtime says nothing of a move in the tree: the clients are told to read the conversation again. */
|
|
156
|
-
async navigateTree(targetId: string, options?: Parameters<AgentSession['navigateTree']>[1]): Promise<TaNavigateResult> {
|
|
157
|
-
const { cancelled, editorText } = await this.pi.navigateTree(targetId, options);
|
|
158
|
-
if (!cancelled) {
|
|
159
|
-
this.publish({ type: 'session_replaced', info: this.info() });
|
|
160
|
-
}
|
|
161
|
-
return { cancelled, editorText };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async close(): Promise<void> {
|
|
165
|
-
clearTimeout(this.idleTimer);
|
|
166
|
-
this.ui.cancelAll();
|
|
167
|
-
this.context.clientTools.cancelAll();
|
|
168
|
-
this.publish({ type: 'session_closed' });
|
|
169
|
-
this.channels.clear();
|
|
170
|
-
this.unsubscribe?.();
|
|
171
|
-
if (this.pi.isStreaming) {
|
|
172
|
-
await this.pi.abort();
|
|
173
|
-
}
|
|
174
|
-
await this.runtime.dispose();
|
|
175
|
-
this.context.lock.releaseAll();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
protected async accept(input: TaPromptInput, run: () => Promise<PromptDisposition>): Promise<TaPromptReceipt> {
|
|
179
|
-
const duplicate = this.receipts.take(input);
|
|
180
|
-
if (duplicate) {
|
|
181
|
-
return duplicate;
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
const disposition = await run();
|
|
185
|
-
return { clientMessageId: input.clientMessageId, status: disposition === 'queued' ? 'queued' : 'accepted' };
|
|
186
|
-
} catch (error) {
|
|
187
|
-
this.receipts.forget(input.clientMessageId);
|
|
188
|
-
throw error;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** Connects this object to the session the runtime has now: at the start and after each replacement. */
|
|
193
|
-
protected async bind(): Promise<void> {
|
|
194
|
-
this.unsubscribe?.();
|
|
195
|
-
const { pi, runtime } = this;
|
|
196
|
-
await pi.bindExtensions({
|
|
197
|
-
uiContext: this.ui,
|
|
198
|
-
mode: 'rpc',
|
|
199
|
-
commandContextActions: {
|
|
200
|
-
waitForIdle: () => pi.waitForIdle(),
|
|
201
|
-
newSession: options => runtime.newSession(options),
|
|
202
|
-
fork: async (entryId, options) => ({ cancelled: (await runtime.fork(entryId, options)).cancelled }),
|
|
203
|
-
navigateTree: async (targetId, options) => ({ cancelled: (await this.navigateTree(targetId, options)).cancelled }),
|
|
204
|
-
switchSession: (sessionPath, options) => runtime.switchSession(sessionPath, options),
|
|
205
|
-
reload: () => pi.reload(),
|
|
206
|
-
},
|
|
207
|
-
shutdownHandler: () => this.context.requestClose(this),
|
|
208
|
-
onError: error => this.publish({ type: 'extension_error', extensionPath: error.extensionPath, event: error.event, error: error.error }),
|
|
209
|
-
});
|
|
210
|
-
this.unsubscribe = pi.subscribe(event => {
|
|
211
|
-
this.publish(TaEventUtil.toWire(event));
|
|
212
|
-
if (event.type === 'agent_settled') {
|
|
213
|
-
this.watchIdle();
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
if (this.started) {
|
|
217
|
-
this.publish({ type: 'session_replaced', info: this.info() });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
protected publish(event: TaEvent): void {
|
|
222
|
-
const logged = this.log.append(event);
|
|
223
|
-
for (const channel of this.channels) {
|
|
224
|
-
channel.send(logged);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
protected isIdle(): boolean {
|
|
229
|
-
return this.channels.size === 0 && !this.pi.isStreaming && this.ui.pendingRequests.length === 0;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** One timer per session, armed only when nothing is attached: an idle server does no work. */
|
|
233
|
-
protected watchIdle(): void {
|
|
234
|
-
clearTimeout(this.idleTimer);
|
|
235
|
-
this.idleTimer = undefined;
|
|
236
|
-
if (this.isIdle()) {
|
|
237
|
-
this.idleTimer = setTimeout(() => this.isIdle() && this.context.requestClose(this), this.context.options.idleTimeoutMs);
|
|
238
|
-
this.idleTimer.unref();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
-
import type { TaOpenTerminalOptions, TaTerminalInfo } from '@celljs/ta-protocol';
|
|
3
|
-
|
|
4
|
-
export const TaTerminals = Symbol('TaTerminals');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The shells of the web client's terminal. Each belongs to the connection that opened it and sends it
|
|
8
|
-
* its output (TaClient.onTerminalData). When that connection drops, the shell waits 30 s for another
|
|
9
|
-
* to take it (listTerminals, writeTerminal or resizeTerminal) and keeps its output meanwhile; then it ends.
|
|
10
|
-
*/
|
|
11
|
-
export interface TaTerminals {
|
|
12
|
-
open(connection: RpcConnection, options: TaOpenTerminalOptions & { cwd: string }): Promise<TaTerminalInfo>;
|
|
13
|
-
write(connection: RpcConnection, terminalId: string, data: string): void;
|
|
14
|
-
resize(connection: RpcConnection, terminalId: string, cols: number, rows: number): Promise<void>;
|
|
15
|
-
close(connection: RpcConnection, terminalId: string): Promise<void>;
|
|
16
|
-
list(connection: RpcConnection): TaTerminalInfo[];
|
|
17
|
-
closeAll(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from 'bun:test';
|
|
2
|
-
import { realpathSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
5
|
-
import { LocalExecEnvironment } from '@celljs/ta-exec';
|
|
6
|
-
import { DefaultTaTerminals } from './terminal-service';
|
|
7
|
-
|
|
8
|
-
/** A connection that keeps what the shells sent it. */
|
|
9
|
-
class FakeConnection {
|
|
10
|
-
readonly id = String(Math.random());
|
|
11
|
-
closed = false;
|
|
12
|
-
output = '';
|
|
13
|
-
exitCode?: number;
|
|
14
|
-
protected readonly closeListeners: (() => void)[] = [];
|
|
15
|
-
|
|
16
|
-
client() {
|
|
17
|
-
return {
|
|
18
|
-
onTerminalData: async (_terminalId: string, data: string, exitCode?: number) => {
|
|
19
|
-
this.output += data;
|
|
20
|
-
this.exitCode ??= exitCode;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
onClose(listener: () => void) {
|
|
26
|
-
this.closeListeners.push(listener);
|
|
27
|
-
return { dispose: () => undefined };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
close() {
|
|
31
|
-
this.closed = true;
|
|
32
|
-
for (const listener of this.closeListeners) {
|
|
33
|
-
listener();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function until(check: () => boolean, what: string): Promise<void> {
|
|
39
|
-
for (let i = 0; i < 500 && !check(); i++) {
|
|
40
|
-
await Bun.sleep(10);
|
|
41
|
-
}
|
|
42
|
-
if (!check()) {
|
|
43
|
-
throw new Error(`Timed out waiting until ${what}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe('DefaultTaTerminals', () => {
|
|
48
|
-
const cwd = realpathSync(tmpdir());
|
|
49
|
-
const terminals = new DefaultTaTerminals();
|
|
50
|
-
Object.assign(terminals, { environments: { create: (dir: string) => new LocalExecEnvironment(dir), defaultCwd: async () => cwd } });
|
|
51
|
-
const as = (connection: FakeConnection) => connection as unknown as RpcConnection;
|
|
52
|
-
|
|
53
|
-
afterEach(() => terminals.closeAll());
|
|
54
|
-
|
|
55
|
-
it('runs a shell and sends its output to the connection that opened it', async () => {
|
|
56
|
-
const connection = new FakeConnection();
|
|
57
|
-
const info = await terminals.open(as(connection), { cwd, cols: 80, rows: 24 });
|
|
58
|
-
expect(info.cwd).toBe(cwd);
|
|
59
|
-
expect(info.terminalId).toBeString();
|
|
60
|
-
terminals.write(as(connection), info.terminalId, 'echo ta-$((40+2))\r');
|
|
61
|
-
await until(() => connection.output.includes('ta-42'), 'the shell answered');
|
|
62
|
-
expect(connection.output).not.toContain('ta-tty=');
|
|
63
|
-
expect(terminals.list(as(connection))).toEqual([info]);
|
|
64
|
-
await terminals.resize(as(connection), info.terminalId, 100, 30);
|
|
65
|
-
terminals.write(as(connection), info.terminalId, 'exit\r');
|
|
66
|
-
await until(() => connection.exitCode !== undefined, 'the shell ended');
|
|
67
|
-
expect(terminals.list(as(connection))).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('sizes the shell as its view asked, even before the shell named its terminal', async () => {
|
|
71
|
-
const connection = new FakeConnection();
|
|
72
|
-
const info = await terminals.open(as(connection), { cwd, cols: 80, rows: 24 });
|
|
73
|
-
if (!info.pty) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
await terminals.resize(as(connection), info.terminalId, 101, 31);
|
|
77
|
-
await Bun.sleep(300);
|
|
78
|
-
terminals.write(as(connection), info.terminalId, 'stty size\r');
|
|
79
|
-
await until(() => connection.output.includes('31 101'), 'the shell has the size of its view');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('asks each machine for its own shell and system', async () => {
|
|
83
|
-
const asked: string[] = [];
|
|
84
|
-
const service = new DefaultTaTerminals();
|
|
85
|
-
const detect = (service as unknown as { detect(env: { exec: unknown; local: boolean }, machine: string): Promise<{ system: string }> }).detect.bind(
|
|
86
|
-
service,
|
|
87
|
-
);
|
|
88
|
-
const env = (system: string) => ({
|
|
89
|
-
local: false,
|
|
90
|
-
exec: async (_command: string, options: { onData(data: Uint8Array): void }) => {
|
|
91
|
-
asked.push(system);
|
|
92
|
-
options.onData(new TextEncoder().encode(`${system}\n/usr/bin/script\n/bin/zsh`));
|
|
93
|
-
return { exitCode: 0 };
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
expect((await detect(env('Linux'), 'box')).system).toBe('Linux');
|
|
97
|
-
expect((await detect(env('Darwin'), '')).system).toBe('Darwin');
|
|
98
|
-
expect((await detect(env('Darwin'), 'box')).system).toBe('Linux');
|
|
99
|
-
expect(asked).toEqual(['Linux', 'Darwin']);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('keeps a shell for another connection after its own dropped', async () => {
|
|
103
|
-
const first = new FakeConnection();
|
|
104
|
-
const info = await terminals.open(as(first), { cwd, cols: 80, rows: 24 });
|
|
105
|
-
const stranger = new FakeConnection();
|
|
106
|
-
expect(terminals.list(as(stranger))).toEqual([]);
|
|
107
|
-
expect(() => terminals.write(as(stranger), info.terminalId, 'x')).toThrow('No terminal');
|
|
108
|
-
terminals.write(as(first), info.terminalId, 'echo first-$((1+2))\r');
|
|
109
|
-
await until(() => first.output.includes('first-3'), 'the first connection got the output');
|
|
110
|
-
first.close();
|
|
111
|
-
const second = new FakeConnection();
|
|
112
|
-
expect(terminals.list(as(second))).toEqual([info]);
|
|
113
|
-
await until(() => second.output.startsWith('\x1bc') && second.output.includes('first-3'), 'the second connection got what the shell showed before');
|
|
114
|
-
terminals.write(as(second), info.terminalId, 'echo back-$((1+1))\r');
|
|
115
|
-
await until(() => second.output.includes('back-2'), 'the second connection got the output');
|
|
116
|
-
await terminals.close(as(second), info.terminalId);
|
|
117
|
-
expect(terminals.list(as(second))).toEqual([]);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { type Application, ApplicationLifecycle, Autowired, Component } from '@celljs/core';
|
|
2
|
-
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
3
|
-
import { type ExecEnvironment, ExecEnvironmentFactory, type ExecProcess } from '@celljs/ta-exec';
|
|
4
|
-
import { TaClient, TaLocation, type TaOpenTerminalOptions, type TaTerminalInfo } from '@celljs/ta-protocol';
|
|
5
|
-
import { TaErrors } from './ta-errors';
|
|
6
|
-
import { TaTerminals } from './terminal-protocol';
|
|
7
|
-
import { PipeDiscipline, type TerminalPlatform, TerminalUtil, TtyMarker } from './terminal-util';
|
|
8
|
-
|
|
9
|
-
/** How long a shell waits for a connection after its own dropped. */
|
|
10
|
-
export const TERMINAL_ORPHAN_MS = 30000;
|
|
11
|
-
/** Output a shell keeps while no connection takes it; older output goes first. */
|
|
12
|
-
const MAX_PENDING_CHARS = 256 * 1024;
|
|
13
|
-
/** Output of the same moment leaves in one message. */
|
|
14
|
-
const FLUSH_MS = 8;
|
|
15
|
-
const DEFAULT_COLS = 80;
|
|
16
|
-
const DEFAULT_ROWS = 24;
|
|
17
|
-
|
|
18
|
-
class Terminal {
|
|
19
|
-
owner?: RpcConnection;
|
|
20
|
-
orphanTimer?: ReturnType<typeof setTimeout>;
|
|
21
|
-
pending = '';
|
|
22
|
-
/** The last output, for a page that takes the shell again after its own went (a reload). */
|
|
23
|
-
history = '';
|
|
24
|
-
flushTimer?: ReturnType<typeof setTimeout>;
|
|
25
|
-
sending = false;
|
|
26
|
-
/** The code the shell ended with, as it said, or as its process did. */
|
|
27
|
-
exitCode?: number;
|
|
28
|
-
/** Its process ended. */
|
|
29
|
-
exited = false;
|
|
30
|
-
/** The size its view asked for last; it waits for the name of the terminal when that is not known yet. */
|
|
31
|
-
size?: { cols: number; rows: number };
|
|
32
|
-
/** Its client knows it ended: nothing more goes. */
|
|
33
|
-
ended = false;
|
|
34
|
-
readonly decoder = new TextDecoder();
|
|
35
|
-
readonly marker = new TtyMarker();
|
|
36
|
-
readonly discipline?: PipeDiscipline;
|
|
37
|
-
|
|
38
|
-
constructor(
|
|
39
|
-
readonly info: TaTerminalInfo,
|
|
40
|
-
readonly env: ExecEnvironment,
|
|
41
|
-
readonly platform: TerminalPlatform,
|
|
42
|
-
readonly process: ExecProcess,
|
|
43
|
-
pty: boolean,
|
|
44
|
-
owner: RpcConnection,
|
|
45
|
-
) {
|
|
46
|
-
this.owner = owner;
|
|
47
|
-
this.discipline = pty ? undefined : new PipeDiscipline();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@Component([TaTerminals, ApplicationLifecycle])
|
|
52
|
-
export class DefaultTaTerminals implements TaTerminals, ApplicationLifecycle<Application> {
|
|
53
|
-
@Autowired(ExecEnvironmentFactory)
|
|
54
|
-
protected readonly environments: ExecEnvironmentFactory;
|
|
55
|
-
|
|
56
|
-
protected readonly terminals = new Map<string, Terminal>();
|
|
57
|
-
protected readonly watched = new WeakSet<RpcConnection>();
|
|
58
|
-
/** By machine: `''` for this one (or the exec server), else the host of `ssh://`. */
|
|
59
|
-
protected readonly platforms = new Map<string, Promise<TerminalPlatform>>();
|
|
60
|
-
protected nextId = 0;
|
|
61
|
-
|
|
62
|
-
async open(connection: RpcConnection, options: TaOpenTerminalOptions & { cwd: string }): Promise<TaTerminalInfo> {
|
|
63
|
-
const env = this.environments.create(options.cwd);
|
|
64
|
-
const stat = await env.stat(env.cwd);
|
|
65
|
-
if (!stat?.isDirectory) {
|
|
66
|
-
throw TaErrors.invalidArgument(`${options.cwd} is not a directory.`, 'Open the terminal in a directory that exists.');
|
|
67
|
-
}
|
|
68
|
-
const platform = await this.detect(env, this.machine(options.cwd));
|
|
69
|
-
const launch = TerminalUtil.launch(platform, TerminalUtil.size(options.cols, DEFAULT_COLS), TerminalUtil.size(options.rows, DEFAULT_ROWS));
|
|
70
|
-
// `pty`: false when the shell runs on pipes, so that the view can say why some programs behave otherwise.
|
|
71
|
-
const info: TaTerminalInfo & { pty: boolean } = { terminalId: `t${++this.nextId}`, cwd: options.cwd, shell: platform.shell, pty: launch.pty };
|
|
72
|
-
const terminal = new Terminal(info, env, platform, env.spawn(launch.command, launch.args), launch.pty, connection);
|
|
73
|
-
this.terminals.set(info.terminalId, terminal);
|
|
74
|
-
this.watch(connection);
|
|
75
|
-
const receive = (data: Uint8Array) => this.output(terminal, terminal.decoder.decode(data, { stream: true }));
|
|
76
|
-
terminal.process.onStdout(receive);
|
|
77
|
-
terminal.process.onStderr(receive);
|
|
78
|
-
terminal.process.onExit(code => this.exited(terminal, code));
|
|
79
|
-
return info;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
write(connection: RpcConnection, terminalId: string, data: string): void {
|
|
83
|
-
const terminal = this.require(connection, terminalId);
|
|
84
|
-
if (!terminal.discipline) {
|
|
85
|
-
terminal.process.write(data);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const { echo, send } = terminal.discipline.input(data);
|
|
89
|
-
this.queue(terminal, echo);
|
|
90
|
-
if (send) {
|
|
91
|
-
terminal.process.write(send);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async resize(connection: RpcConnection, terminalId: string, cols: number, rows: number): Promise<void> {
|
|
96
|
-
const terminal = this.require(connection, terminalId);
|
|
97
|
-
terminal.size = { cols: TerminalUtil.size(cols, DEFAULT_COLS), rows: TerminalUtil.size(rows, DEFAULT_ROWS) };
|
|
98
|
-
await this.applySize(terminal);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** A view sizes its shell as soon as it shows, often before the shell named its terminal: the size waits for it. */
|
|
102
|
-
protected async applySize(terminal: Terminal): Promise<void> {
|
|
103
|
-
if (terminal.marker.tty && terminal.size) {
|
|
104
|
-
const command = TerminalUtil.resizeCommand(terminal.platform, terminal.marker.tty, terminal.size.cols, terminal.size.rows);
|
|
105
|
-
await terminal.env.exec(command, { timeout: 5000 });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
close(connection: RpcConnection, terminalId: string): Promise<void> {
|
|
110
|
-
return this.end(this.require(connection, terminalId));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
list(connection: RpcConnection): TaTerminalInfo[] {
|
|
114
|
-
const own: TaTerminalInfo[] = [];
|
|
115
|
-
for (const terminal of this.terminals.values()) {
|
|
116
|
-
if (!terminal.owner) {
|
|
117
|
-
this.adopt(terminal, connection);
|
|
118
|
-
}
|
|
119
|
-
if (terminal.owner === connection) {
|
|
120
|
-
own.push(terminal.info);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return own;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
onStop(): Promise<void> {
|
|
127
|
-
return this.closeAll();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async closeAll(): Promise<void> {
|
|
131
|
-
await Promise.all([...this.terminals.values()].map(terminal => this.end(terminal)));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** The shell of this connection, or one nobody has: it becomes this connection's. */
|
|
135
|
-
protected require(connection: RpcConnection, terminalId: string): Terminal {
|
|
136
|
-
const terminal = this.terminals.get(terminalId);
|
|
137
|
-
if (!terminal || (terminal.owner && terminal.owner !== connection)) {
|
|
138
|
-
throw TaErrors.invalidArgument(
|
|
139
|
-
`No terminal of this connection has the id ${terminalId}.`,
|
|
140
|
-
'Open one with openTerminal; listTerminals has those still open.',
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
if (!terminal.owner) {
|
|
144
|
-
this.adopt(terminal, connection);
|
|
145
|
-
}
|
|
146
|
-
return terminal;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* A connection takes a shell nobody has. What its page shows went with the page: it gets the last
|
|
151
|
-
* output again, after a reset, so that a page that kept its screen does not show it twice.
|
|
152
|
-
*/
|
|
153
|
-
protected adopt(terminal: Terminal, connection: RpcConnection): void {
|
|
154
|
-
clearTimeout(terminal.orphanTimer);
|
|
155
|
-
terminal.orphanTimer = undefined;
|
|
156
|
-
terminal.owner = connection;
|
|
157
|
-
terminal.pending = terminal.history ? `${TerminalUtil.RESET}${terminal.history}` : terminal.pending;
|
|
158
|
-
this.watch(connection);
|
|
159
|
-
this.schedule(terminal);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
protected watch(connection: RpcConnection): void {
|
|
163
|
-
if (this.watched.has(connection)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this.watched.add(connection);
|
|
167
|
-
connection.onClose(() => {
|
|
168
|
-
for (const terminal of this.terminals.values()) {
|
|
169
|
-
if (terminal.owner === connection) {
|
|
170
|
-
terminal.owner = undefined;
|
|
171
|
-
terminal.orphanTimer = setTimeout(() => void this.end(terminal), TERMINAL_ORPHAN_MS);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
protected output(terminal: Terminal, text: string): void {
|
|
178
|
-
const { text: rest, exitCode } = TerminalUtil.takeExitCode(text);
|
|
179
|
-
terminal.exitCode ??= exitCode;
|
|
180
|
-
const named = terminal.marker.tty !== undefined;
|
|
181
|
-
const shown = terminal.marker.feed(rest);
|
|
182
|
-
if (!named && terminal.marker.tty !== undefined) {
|
|
183
|
-
void this.applySize(terminal).catch(() => undefined);
|
|
184
|
-
}
|
|
185
|
-
this.queue(terminal, terminal.discipline ? terminal.discipline.output(shown) : shown);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
protected queue(terminal: Terminal, text: string): void {
|
|
189
|
-
if (!text) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
terminal.pending += text;
|
|
193
|
-
if (terminal.pending.length > MAX_PENDING_CHARS) {
|
|
194
|
-
terminal.pending = TerminalUtil.tail(terminal.pending, MAX_PENDING_CHARS);
|
|
195
|
-
}
|
|
196
|
-
terminal.history = TerminalUtil.tail(terminal.history + text, MAX_PENDING_CHARS);
|
|
197
|
-
this.schedule(terminal);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
protected schedule(terminal: Terminal): void {
|
|
201
|
-
const due = terminal.pending || terminal.exited;
|
|
202
|
-
if (terminal.flushTimer === undefined && terminal.owner && !terminal.ended && due) {
|
|
203
|
-
terminal.flushTimer = setTimeout(() => this.flush(terminal), FLUSH_MS);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** One message at a time: the next leaves when the client has the last. */
|
|
208
|
-
protected flush(terminal: Terminal): void {
|
|
209
|
-
terminal.flushTimer = undefined;
|
|
210
|
-
const owner = terminal.owner;
|
|
211
|
-
if (!owner || owner.closed || terminal.sending) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const data = terminal.pending;
|
|
215
|
-
const exitCode = terminal.exited ? (terminal.exitCode ?? -1) : undefined;
|
|
216
|
-
terminal.pending = '';
|
|
217
|
-
terminal.sending = true;
|
|
218
|
-
owner
|
|
219
|
-
.client<TaClient>(TaClient)
|
|
220
|
-
.onTerminalData(terminal.info.terminalId, data, exitCode)
|
|
221
|
-
.then(
|
|
222
|
-
() => {
|
|
223
|
-
if (exitCode !== undefined) {
|
|
224
|
-
terminal.ended = true;
|
|
225
|
-
this.terminals.delete(terminal.info.terminalId);
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
() => {
|
|
229
|
-
// Lost on the way: it goes again to whoever takes the shell.
|
|
230
|
-
terminal.pending = data + terminal.pending;
|
|
231
|
-
},
|
|
232
|
-
)
|
|
233
|
-
.finally(() => {
|
|
234
|
-
terminal.sending = false;
|
|
235
|
-
this.schedule(terminal);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
protected exited(terminal: Terminal, exitCode: number | null): void {
|
|
240
|
-
const rest = terminal.decoder.decode() + terminal.marker.flush();
|
|
241
|
-
this.queue(terminal, terminal.discipline ? terminal.discipline.output(rest) : rest);
|
|
242
|
-
terminal.exitCode ??= exitCode ?? undefined;
|
|
243
|
-
terminal.exited = true;
|
|
244
|
-
clearTimeout(terminal.orphanTimer);
|
|
245
|
-
if (terminal.owner) {
|
|
246
|
-
this.schedule(terminal);
|
|
247
|
-
} else {
|
|
248
|
-
this.terminals.delete(terminal.info.terminalId);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/** Hangs up its terminal, which ends what runs there, then the wrapper. */
|
|
253
|
-
protected async end(terminal: Terminal): Promise<void> {
|
|
254
|
-
clearTimeout(terminal.orphanTimer);
|
|
255
|
-
this.terminals.delete(terminal.info.terminalId);
|
|
256
|
-
if (terminal.marker.tty) {
|
|
257
|
-
await terminal.env.exec(TerminalUtil.hangUpCommand(terminal.marker.tty), { timeout: 5000 }).catch(() => undefined);
|
|
258
|
-
}
|
|
259
|
-
terminal.process.kill();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** The machine of a location: its shell, `script` and system are those of that machine. */
|
|
263
|
-
protected machine(location: string): string {
|
|
264
|
-
try {
|
|
265
|
-
return TaLocation.parse(location)?.host ?? '';
|
|
266
|
-
} catch {
|
|
267
|
-
return '';
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
protected detect(env: ExecEnvironment, machine: string): Promise<TerminalPlatform> {
|
|
272
|
-
let platform = this.platforms.get(machine);
|
|
273
|
-
if (platform) {
|
|
274
|
-
return platform;
|
|
275
|
-
}
|
|
276
|
-
platform = (async () => {
|
|
277
|
-
let output = '';
|
|
278
|
-
const decoder = new TextDecoder();
|
|
279
|
-
const { exitCode } = await env.exec(`${TerminalUtil.PROBE} 2>/dev/null`, {
|
|
280
|
-
timeout: 5000,
|
|
281
|
-
onData: data => (output += decoder.decode(data, { stream: true })),
|
|
282
|
-
});
|
|
283
|
-
const fallback = env.local && process.platform === 'win32' ? (process.env.ComSpec ?? 'cmd.exe') : '/bin/sh';
|
|
284
|
-
return exitCode === 0 ? TerminalUtil.parsePlatform(output, fallback) : { system: '', script: false, shell: fallback };
|
|
285
|
-
})();
|
|
286
|
-
// A machine that could not answer is asked again next time.
|
|
287
|
-
platform.catch(() => this.platforms.delete(machine));
|
|
288
|
-
this.platforms.set(machine, platform);
|
|
289
|
-
return platform;
|
|
290
|
-
}
|
|
291
|
-
}
|