gitspace 0.2.0-rc.20 → 0.2.0-rc.21
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/package.json +11 -6
- package/.claude/settings.local.json +0 -10
- package/.gitspace/bundle.json +0 -50
- package/.gitspace/events.json +0 -11
- package/.gitspace/processes.json +0 -23
- package/.gitspace/scripts/select/01-status.sh +0 -39
- package/.gitspace/scripts/setup/01-install-deps.sh +0 -12
- package/.gitspace/scripts/setup/02-typecheck.sh +0 -16
- package/AGENTS.md +0 -469
- package/CLAUDE.md +0 -1
- package/bun.lock +0 -794
- package/docs/CONNECTION.md +0 -623
- package/docs/GATEWAY-WORKER.md +0 -319
- package/docs/GETTING-STARTED.md +0 -448
- package/docs/GITSPACE-PLATFORM.md +0 -1819
- package/docs/INFRASTRUCTURE.md +0 -1347
- package/docs/PROTOCOL.md +0 -619
- package/docs/QUICKSTART.md +0 -183
- package/docs/RELAY.md +0 -327
- package/docs/REMOTE-DESIGN.md +0 -554
- package/docs/ROADMAP.md +0 -564
- package/docs/SITE_DOCS_FIGMA_MAKE.md +0 -1176
- package/docs/STACK-DESIGN.md +0 -588
- package/docs/UNIFIED_ARCHITECTURE.md +0 -138
- package/experiments/pty-benchmark.ts +0 -148
- package/experiments/pty-latency.ts +0 -100
- package/experiments/router/client.ts +0 -199
- package/experiments/router/protocol.ts +0 -74
- package/experiments/router/router.ts +0 -217
- package/experiments/router/session.ts +0 -180
- package/experiments/router/test.ts +0 -133
- package/experiments/socket-bandwidth.ts +0 -77
- package/homebrew/gitspace.rb +0 -45
- package/landing-page/ATTRIBUTIONS.md +0 -3
- package/landing-page/README.md +0 -11
- package/landing-page/bun.lock +0 -801
- package/landing-page/guidelines/Guidelines.md +0 -61
- package/landing-page/index.html +0 -37
- package/landing-page/package.json +0 -90
- package/landing-page/postcss.config.mjs +0 -15
- package/landing-page/public/_redirects +0 -1
- package/landing-page/public/favicon.png +0 -0
- package/landing-page/src/app/App.tsx +0 -53
- package/landing-page/src/app/components/figma/ImageWithFallback.tsx +0 -27
- package/landing-page/src/app/components/ui/accordion.tsx +0 -66
- package/landing-page/src/app/components/ui/alert-dialog.tsx +0 -157
- package/landing-page/src/app/components/ui/alert.tsx +0 -66
- package/landing-page/src/app/components/ui/aspect-ratio.tsx +0 -11
- package/landing-page/src/app/components/ui/avatar.tsx +0 -53
- package/landing-page/src/app/components/ui/badge.tsx +0 -46
- package/landing-page/src/app/components/ui/breadcrumb.tsx +0 -109
- package/landing-page/src/app/components/ui/button.tsx +0 -57
- package/landing-page/src/app/components/ui/calendar.tsx +0 -75
- package/landing-page/src/app/components/ui/card.tsx +0 -92
- package/landing-page/src/app/components/ui/carousel.tsx +0 -241
- package/landing-page/src/app/components/ui/chart.tsx +0 -353
- package/landing-page/src/app/components/ui/checkbox.tsx +0 -32
- package/landing-page/src/app/components/ui/collapsible.tsx +0 -33
- package/landing-page/src/app/components/ui/command.tsx +0 -177
- package/landing-page/src/app/components/ui/context-menu.tsx +0 -252
- package/landing-page/src/app/components/ui/dialog.tsx +0 -135
- package/landing-page/src/app/components/ui/drawer.tsx +0 -132
- package/landing-page/src/app/components/ui/dropdown-menu.tsx +0 -257
- package/landing-page/src/app/components/ui/form.tsx +0 -168
- package/landing-page/src/app/components/ui/hover-card.tsx +0 -44
- package/landing-page/src/app/components/ui/input-otp.tsx +0 -77
- package/landing-page/src/app/components/ui/input.tsx +0 -21
- package/landing-page/src/app/components/ui/label.tsx +0 -24
- package/landing-page/src/app/components/ui/menubar.tsx +0 -276
- package/landing-page/src/app/components/ui/navigation-menu.tsx +0 -168
- package/landing-page/src/app/components/ui/pagination.tsx +0 -127
- package/landing-page/src/app/components/ui/popover.tsx +0 -48
- package/landing-page/src/app/components/ui/progress.tsx +0 -31
- package/landing-page/src/app/components/ui/radio-group.tsx +0 -45
- package/landing-page/src/app/components/ui/resizable.tsx +0 -56
- package/landing-page/src/app/components/ui/scroll-area.tsx +0 -58
- package/landing-page/src/app/components/ui/select.tsx +0 -189
- package/landing-page/src/app/components/ui/separator.tsx +0 -28
- package/landing-page/src/app/components/ui/sheet.tsx +0 -139
- package/landing-page/src/app/components/ui/sidebar.tsx +0 -726
- package/landing-page/src/app/components/ui/skeleton.tsx +0 -13
- package/landing-page/src/app/components/ui/slider.tsx +0 -63
- package/landing-page/src/app/components/ui/sonner.tsx +0 -25
- package/landing-page/src/app/components/ui/switch.tsx +0 -31
- package/landing-page/src/app/components/ui/table.tsx +0 -116
- package/landing-page/src/app/components/ui/tabs.tsx +0 -66
- package/landing-page/src/app/components/ui/textarea.tsx +0 -18
- package/landing-page/src/app/components/ui/toggle-group.tsx +0 -73
- package/landing-page/src/app/components/ui/toggle.tsx +0 -47
- package/landing-page/src/app/components/ui/tooltip.tsx +0 -61
- package/landing-page/src/app/components/ui/use-mobile.ts +0 -21
- package/landing-page/src/app/components/ui/utils.ts +0 -6
- package/landing-page/src/components/docs/DocsContent.tsx +0 -801
- package/landing-page/src/components/docs/DocsSidebar.tsx +0 -90
- package/landing-page/src/components/landing/CTA.tsx +0 -59
- package/landing-page/src/components/landing/Comparison.tsx +0 -84
- package/landing-page/src/components/landing/FaultyTerminal.tsx +0 -424
- package/landing-page/src/components/landing/Features.tsx +0 -201
- package/landing-page/src/components/landing/Hero.tsx +0 -142
- package/landing-page/src/components/landing/Pricing.tsx +0 -140
- package/landing-page/src/components/landing/Roadmap.tsx +0 -86
- package/landing-page/src/components/landing/Security.tsx +0 -81
- package/landing-page/src/components/landing/TerminalWindow.tsx +0 -27
- package/landing-page/src/components/landing/UseCases.tsx +0 -55
- package/landing-page/src/components/landing/Workflow.tsx +0 -101
- package/landing-page/src/components/layout/DashboardNavbar.tsx +0 -37
- package/landing-page/src/components/layout/Footer.tsx +0 -55
- package/landing-page/src/components/layout/LandingNavbar.tsx +0 -82
- package/landing-page/src/components/ui/badge.tsx +0 -39
- package/landing-page/src/components/ui/breadcrumb.tsx +0 -115
- package/landing-page/src/components/ui/button.tsx +0 -57
- package/landing-page/src/components/ui/card.tsx +0 -79
- package/landing-page/src/components/ui/mock-terminal.tsx +0 -68
- package/landing-page/src/components/ui/separator.tsx +0 -28
- package/landing-page/src/lib/utils.ts +0 -6
- package/landing-page/src/main.tsx +0 -10
- package/landing-page/src/pages/Dashboard.tsx +0 -133
- package/landing-page/src/pages/DocsPage.tsx +0 -79
- package/landing-page/src/pages/LandingPage.tsx +0 -31
- package/landing-page/src/pages/TerminalView.tsx +0 -106
- package/landing-page/src/styles/fonts.css +0 -0
- package/landing-page/src/styles/index.css +0 -3
- package/landing-page/src/styles/tailwind.css +0 -4
- package/landing-page/src/styles/theme.css +0 -181
- package/landing-page/vite.config.ts +0 -19
- package/scripts/GHOSTTY_TAB_BUG.md +0 -106
- package/scripts/build.ts +0 -298
- package/scripts/migrate-secrets.ts +0 -77
- package/scripts/release.ts +0 -140
- package/scripts/sample-events.ts +0 -263
- package/scripts/test-tabs-minimal.ts +0 -68
- package/scripts/test-tabs-workaround.ts +0 -95
- package/scripts/test-tabs.ts +0 -171
- package/src/__tests__/test-utils.ts +0 -298
- package/src/app/input/__tests__/sessionCommands.test.ts +0 -40
- package/src/app/input/sessionCommands.ts +0 -94
- package/src/app/session/__tests__/useAttachController.test.ts +0 -229
- package/src/app/session/createSessionBackend.bun.ts +0 -76
- package/src/app/session/createSessionBackend.web.ts +0 -104
- package/src/app/session/types.ts +0 -16
- package/src/app/session/useAttachController.ts +0 -220
- package/src/app/session/useProcessActions.ts +0 -201
- package/src/app/session/useSessionClient.ts +0 -35
- package/src/app/session/useWorkspaceDeleteFlow.ts +0 -170
- package/src/app.tui.tsx +0 -2929
- package/src/app.web.tsx +0 -1454
- package/src/commands/__tests__/connect-key.test.ts +0 -10
- package/src/commands/__tests__/events.test.ts +0 -201
- package/src/commands/__tests__/notifications.test.ts +0 -349
- package/src/commands/__tests__/process.test.ts +0 -251
- package/src/commands/__tests__/serve-messages.test.ts +0 -190
- package/src/commands/__tests__/serve-process-hosting.test.ts +0 -63
- package/src/commands/access.ts +0 -298
- package/src/commands/add.ts +0 -455
- package/src/commands/auth.ts +0 -369
- package/src/commands/bundle.ts +0 -232
- package/src/commands/config.ts +0 -242
- package/src/commands/connect-key.ts +0 -1
- package/src/commands/connect.ts +0 -576
- package/src/commands/directory.ts +0 -16
- package/src/commands/events.ts +0 -157
- package/src/commands/host.ts +0 -566
- package/src/commands/identity.ts +0 -184
- package/src/commands/linear.ts +0 -717
- package/src/commands/list.ts +0 -181
- package/src/commands/migrate.ts +0 -52
- package/src/commands/notifications.ts +0 -351
- package/src/commands/process.ts +0 -104
- package/src/commands/relay.ts +0 -315
- package/src/commands/remove.ts +0 -279
- package/src/commands/review.ts +0 -787
- package/src/commands/serve.ts +0 -1946
- package/src/commands/share.ts +0 -451
- package/src/commands/status.ts +0 -125
- package/src/commands/switch.ts +0 -361
- package/src/commands/tmux.ts +0 -317
- package/src/components/DPad.web.tsx +0 -343
- package/src/components/DiffViewer.web.tsx +0 -1192
- package/src/components/Events.tsx +0 -137
- package/src/components/Events.tui.tsx +0 -129
- package/src/components/Events.web.tsx +0 -386
- package/src/components/FloatingControls.web.tsx +0 -112
- package/src/components/FloatingJogWheel.web.tsx +0 -240
- package/src/components/Flow.tsx +0 -458
- package/src/components/Flow.tui.tsx +0 -343
- package/src/components/Flow.web.tsx +0 -442
- package/src/components/Inbox.tsx +0 -448
- package/src/components/Inbox.tui.tsx +0 -262
- package/src/components/Inbox.web.tsx +0 -329
- package/src/components/MachineList.tsx +0 -187
- package/src/components/MachineList.tui.tsx +0 -161
- package/src/components/MachineList.web.tsx +0 -210
- package/src/components/NumPad.web.tsx +0 -270
- package/src/components/ProjectList.tsx +0 -175
- package/src/components/ProjectList.tui.tsx +0 -109
- package/src/components/ProjectList.web.tsx +0 -143
- package/src/components/ProjectOnboardingStep.ts +0 -23
- package/src/components/ProjectOnboardingStep.tui.tsx +0 -88
- package/src/components/ProjectOnboardingStep.web.tsx +0 -59
- package/src/components/RemoteMachineScreen.tui.tsx +0 -690
- package/src/components/ScriptTerminal.tui.tsx +0 -160
- package/src/components/ScriptTerminal.web.tsx +0 -89
- package/src/components/SessionTerminal.tui.tsx +0 -406
- package/src/components/SessionTerminal.web.tsx +0 -467
- package/src/components/SpacesBrowser.tsx +0 -540
- package/src/components/SpacesBrowser.tui.tsx +0 -258
- package/src/components/SpacesBrowser.web.tsx +0 -332
- package/src/components/TerminalControls.web.tsx +0 -464
- package/src/components/ThreadPanel.web.tsx +0 -798
- package/src/components/__tests__/SpacesBrowser.test.ts +0 -541
- package/src/components/__tests__/SpacesBrowser.tui.test.tsx +0 -249
- package/src/components/__tests__/script-terminal-buffer.tui.test.ts +0 -72
- package/src/components/index.ts +0 -105
- package/src/components/review-decision-colors.ts +0 -11
- package/src/components/script-terminal-buffer.tui.ts +0 -37
- package/src/components/session-terminal-page-navigation.ts +0 -48
- package/src/components/terminal-bracketed-paste.tui.test.ts +0 -43
- package/src/components/terminal-bracketed-paste.tui.ts +0 -46
- package/src/core/__tests__/access.test.ts +0 -240
- package/src/core/__tests__/bundle-refresh.test.ts +0 -567
- package/src/core/__tests__/bundle.test.ts +0 -209
- package/src/core/__tests__/github-review.test.ts +0 -781
- package/src/core/__tests__/project-lifecycle.test.ts +0 -137
- package/src/core/__tests__/workspace-lifecycle.test.ts +0 -159
- package/src/core/__tests__/workspace.test.ts +0 -149
- package/src/core/access.ts +0 -277
- package/src/core/bundle-refresh.ts +0 -1064
- package/src/core/bundle.ts +0 -326
- package/src/core/config.ts +0 -405
- package/src/core/git.ts +0 -768
- package/src/core/github-review.ts +0 -761
- package/src/core/github.ts +0 -151
- package/src/core/identity.ts +0 -631
- package/src/core/linear.ts +0 -403
- package/src/core/preferences-service.ts +0 -17
- package/src/core/project-catalog.ts +0 -52
- package/src/core/project-lifecycle.ts +0 -163
- package/src/core/review-executor.ts +0 -316
- package/src/core/review.ts +0 -407
- package/src/core/secret-runtime.ts +0 -167
- package/src/core/shell.ts +0 -117
- package/src/core/trusted-relays.ts +0 -315
- package/src/core/workspace-lifecycle.ts +0 -216
- package/src/core/workspace.ts +0 -363
- package/src/hooks/__tests__/useLocalSession.tui.test.ts +0 -557
- package/src/hooks/index.ts +0 -8
- package/src/hooks/index.tui.ts +0 -32
- package/src/hooks/useDaemonStatus.tui.ts +0 -174
- package/src/hooks/useLocalSession.tui.ts +0 -395
- package/src/hooks/useRelayConnection.web.ts +0 -54
- package/src/hooks/useRemoteMachines.tui.ts +0 -166
- package/src/hooks/useRemoteTerminal.tui.ts +0 -22
- package/src/hooks/useReview.web.ts +0 -248
- package/src/hooks/useTerminal.web.ts +0 -36
- package/src/hooks/useUserActivity.ts +0 -61
- package/src/hooks/useVisualViewport.web.ts +0 -104
- package/src/index.ts +0 -1376
- package/src/lib/events/__tests__/collector-filter.test.ts +0 -105
- package/src/lib/events/__tests__/store-query.test.ts +0 -103
- package/src/lib/events/collector.ts +0 -494
- package/src/lib/events/filters.ts +0 -26
- package/src/lib/events/index.ts +0 -11
- package/src/lib/events/indexer.ts +0 -14
- package/src/lib/events/paths.ts +0 -69
- package/src/lib/events/reader.ts +0 -212
- package/src/lib/events/store.ts +0 -141
- package/src/lib/invite.web.ts +0 -58
- package/src/lib/preferences-service.web.ts +0 -41
- package/src/lib/processes/__tests__/config.test.ts +0 -83
- package/src/lib/processes/__tests__/names.test.ts +0 -125
- package/src/lib/processes/__tests__/schema.test.ts +0 -208
- package/src/lib/processes/__tests__/watchdog.test.ts +0 -210
- package/src/lib/processes/autostart.ts +0 -16
- package/src/lib/processes/config.ts +0 -187
- package/src/lib/processes/control.ts +0 -53
- package/src/lib/processes/editor.ts +0 -32
- package/src/lib/processes/events-config.ts +0 -37
- package/src/lib/processes/index.ts +0 -14
- package/src/lib/processes/instances.ts +0 -20
- package/src/lib/processes/manager.ts +0 -131
- package/src/lib/processes/names.ts +0 -71
- package/src/lib/processes/registry.ts +0 -26
- package/src/lib/processes/runner.ts +0 -211
- package/src/lib/processes/scheduler.ts +0 -17
- package/src/lib/processes/schema.ts +0 -74
- package/src/lib/processes/session-list.ts +0 -15
- package/src/lib/processes/state.ts +0 -82
- package/src/lib/processes/watchdog.test.ts +0 -79
- package/src/lib/processes/watchdog.ts +0 -106
- package/src/lib/remote-session/__tests__/protocol.test.ts +0 -291
- package/src/lib/remote-session/index.ts +0 -7
- package/src/lib/remote-session/protocol.ts +0 -443
- package/src/lib/remote-session/session-handler.ts +0 -1298
- package/src/lib/remote-session/workspace-scanner.ts +0 -161
- package/src/lib/sonner.web.ts +0 -1
- package/src/lib/storage/identity-store.web.ts +0 -94
- package/src/lib/tmux-lite/README.md +0 -81
- package/src/lib/tmux-lite/cli.ts +0 -855
- package/src/lib/tmux-lite/crypto/__tests__/helpers/handshake-runner.ts +0 -349
- package/src/lib/tmux-lite/crypto/__tests__/helpers/mock-relay.ts +0 -291
- package/src/lib/tmux-lite/crypto/__tests__/helpers/test-identities.ts +0 -142
- package/src/lib/tmux-lite/crypto/__tests__/integration/authorization.integration.test.ts +0 -339
- package/src/lib/tmux-lite/crypto/__tests__/integration/e2e-communication.integration.test.ts +0 -477
- package/src/lib/tmux-lite/crypto/__tests__/integration/error-handling.integration.test.ts +0 -499
- package/src/lib/tmux-lite/crypto/__tests__/integration/handshake.integration.test.ts +0 -371
- package/src/lib/tmux-lite/crypto/__tests__/integration/security.integration.test.ts +0 -573
- package/src/lib/tmux-lite/crypto/access-control.test.ts +0 -512
- package/src/lib/tmux-lite/crypto/access-control.ts +0 -320
- package/src/lib/tmux-lite/crypto/frames.test.ts +0 -262
- package/src/lib/tmux-lite/crypto/frames.ts +0 -141
- package/src/lib/tmux-lite/crypto/handshake.ts +0 -894
- package/src/lib/tmux-lite/crypto/identity.test.ts +0 -220
- package/src/lib/tmux-lite/crypto/identity.ts +0 -286
- package/src/lib/tmux-lite/crypto/index.ts +0 -51
- package/src/lib/tmux-lite/crypto/invites.test.ts +0 -381
- package/src/lib/tmux-lite/crypto/invites.ts +0 -215
- package/src/lib/tmux-lite/crypto/keyexchange.ts +0 -435
- package/src/lib/tmux-lite/crypto/keys.test.ts +0 -58
- package/src/lib/tmux-lite/crypto/keys.ts +0 -47
- package/src/lib/tmux-lite/crypto/secretbox.test.ts +0 -169
- package/src/lib/tmux-lite/crypto/secretbox.ts +0 -124
- package/src/lib/tmux-lite/handshake-handler.ts +0 -451
- package/src/lib/tmux-lite/process-run.integration.test.ts +0 -266
- package/src/lib/tmux-lite/protocol.test.ts +0 -307
- package/src/lib/tmux-lite/protocol.ts +0 -291
- package/src/lib/tmux-lite/relay-client.ts +0 -506
- package/src/lib/tmux-lite/server-lifecycle.test.ts +0 -212
- package/src/lib/tmux-lite/server.ts +0 -1412
- package/src/lib/tmux-lite/shell-integration.sh +0 -37
- package/src/lib/tmux-lite/terminal-queries.test.ts +0 -54
- package/src/lib/tmux-lite/terminal-queries.ts +0 -49
- package/src/notifications/__tests__/useNotifications.test.ts +0 -739
- package/src/notifications/index.ts +0 -32
- package/src/notifications/policy.test.ts +0 -424
- package/src/notifications/policy.ts +0 -139
- package/src/notifications/types.ts +0 -82
- package/src/notifications/useNotifications.ts +0 -350
- package/src/pages/ReviewPage.web.tsx +0 -511
- package/src/preferences/index.ts +0 -1
- package/src/preferences/types.ts +0 -9
- package/src/relay/__tests__/e2e-flow.test.ts +0 -1284
- package/src/relay/__tests__/helpers/auth.ts +0 -354
- package/src/relay/__tests__/helpers/ports.ts +0 -51
- package/src/relay/__tests__/protocol-validation.test.ts +0 -265
- package/src/relay/authorization.ts +0 -303
- package/src/relay/embedded-assets.generated.d.ts +0 -15
- package/src/relay/identity.ts +0 -352
- package/src/relay/index.ts +0 -57
- package/src/relay/pipes.test.ts +0 -427
- package/src/relay/pipes.ts +0 -195
- package/src/relay/protocol.ts +0 -804
- package/src/relay/registries.test.ts +0 -437
- package/src/relay/registries.ts +0 -593
- package/src/relay/server.test.ts +0 -1323
- package/src/relay/server.ts +0 -1128
- package/src/relay/signing.ts +0 -238
- package/src/relay/types.ts +0 -69
- package/src/relay-client/__tests__/machine-directory-client.test.ts +0 -152
- package/src/relay-client/__tests__/useMachineDirectory.test.ts +0 -172
- package/src/relay-client/adapters/browser.ts +0 -27
- package/src/relay-client/adapters/node.ts +0 -29
- package/src/relay-client/index.ts +0 -33
- package/src/relay-client/machine-directory-client.ts +0 -244
- package/src/relay-client/useMachineDirectory.ts +0 -175
- package/src/serve/client-session-manager.ts +0 -635
- package/src/serve/daemon.ts +0 -497
- package/src/serve/pty-session.ts +0 -236
- package/src/serve/types.ts +0 -174
- package/src/session/__tests__/backend-manager.test.ts +0 -101
- package/src/session/__tests__/local-session-backend.test.ts +0 -1129
- package/src/session/__tests__/reducer.test.ts +0 -80
- package/src/session/__tests__/remote-session-backend.test.ts +0 -995
- package/src/session/__tests__/session-name.test.ts +0 -35
- package/src/session/__tests__/useBundleRefreshAttachFlow.test.ts +0 -431
- package/src/session/__tests__/useRemoteSessionClient.test.ts +0 -424
- package/src/session/__tests__/workspace-shell-hooks.integration.test.ts +0 -268
- package/src/session/__tests__/workspace-shell-hooks.test.ts +0 -24
- package/src/session/adapters/browser-remote.ts +0 -101
- package/src/session/adapters/node-remote.ts +0 -135
- package/src/session/backend-key.ts +0 -5
- package/src/session/backend-manager.ts +0 -80
- package/src/session/backend.ts +0 -93
- package/src/session/backends/local-session-backend.ts +0 -1119
- package/src/session/backends/remote-session-backend.ts +0 -1378
- package/src/session/crypto/__tests__/web-terminal.test.ts +0 -1158
- package/src/session/crypto/frames.web.ts +0 -205
- package/src/session/crypto/handshake.web.ts +0 -396
- package/src/session/crypto/identity.web.ts +0 -133
- package/src/session/crypto/keyexchange.web.ts +0 -246
- package/src/session/crypto/relay-signing.web.ts +0 -53
- package/src/session/events.ts +0 -38
- package/src/session/index.ts +0 -116
- package/src/session/reducer.ts +0 -274
- package/src/session/selectors.ts +0 -28
- package/src/session/session-name.ts +0 -50
- package/src/session/types.ts +0 -101
- package/src/session/useBundleRefreshAttachFlow.ts +0 -608
- package/src/session/useRemoteSessionClient.ts +0 -424
- package/src/session/useSessionEngine.ts +0 -432
- package/src/session/workspace-shell-hooks.ts +0 -35
- package/src/tui/__tests__/input-text.test.ts +0 -24
- package/src/tui/__tests__/local-terminal-sync.test.ts +0 -82
- package/src/tui/__tests__/session-terminal-page-navigation.test.ts +0 -94
- package/src/tui/app.tsx +0 -2
- package/src/tui/index.ts +0 -18
- package/src/tui/input-text.ts +0 -38
- package/src/tui/local-terminal-sync.ts +0 -41
- package/src/types/bundle-refresh.ts +0 -42
- package/src/types/bundle.ts +0 -130
- package/src/types/config.ts +0 -287
- package/src/types/errors.ts +0 -292
- package/src/types/events.ts +0 -91
- package/src/types/identity.ts +0 -284
- package/src/types/processes.ts +0 -45
- package/src/types/review.ts +0 -349
- package/src/types/script-phase.ts +0 -3
- package/src/types/workspace-fuzzy.ts +0 -49
- package/src/types/workspace.ts +0 -151
- package/src/utils/__tests__/onboarding.test.ts +0 -358
- package/src/utils/__tests__/run-scripts.test.ts +0 -535
- package/src/utils/__tests__/run-workspace-scripts.test.ts +0 -406
- package/src/utils/__tests__/workspace-setup.integration.test.ts +0 -633
- package/src/utils/__tests__/workspace-state.test.ts +0 -78
- package/src/utils/bun-socket-writer.ts +0 -80
- package/src/utils/clipboard.ts +0 -53
- package/src/utils/deps.test.ts +0 -31
- package/src/utils/deps.ts +0 -145
- package/src/utils/device.web.ts +0 -163
- package/src/utils/fuzzy-match.ts +0 -125
- package/src/utils/hostnames.ts +0 -43
- package/src/utils/hunk-header.ts +0 -17
- package/src/utils/id.ts +0 -9
- package/src/utils/logger.ts +0 -127
- package/src/utils/markdown.ts +0 -254
- package/src/utils/normalize-env-key.ts +0 -13
- package/src/utils/onboarding.ts +0 -279
- package/src/utils/prompts.ts +0 -176
- package/src/utils/run-commands.ts +0 -112
- package/src/utils/run-scripts.ts +0 -337
- package/src/utils/run-workspace-scripts.ts +0 -355
- package/src/utils/sanitize.test.ts +0 -149
- package/src/utils/sanitize.ts +0 -162
- package/src/utils/secrets.ts +0 -836
- package/src/utils/shell-escape.ts +0 -40
- package/src/utils/utf8.ts +0 -79
- package/src/utils/workspace-id.ts +0 -55
- package/src/utils/workspace-state.ts +0 -427
- package/src/version.generated.d.ts +0 -2
- package/todo-security.md +0 -92
- package/tsconfig.json +0 -29
- package/web/README.md +0 -73
- package/web/bun.lock +0 -675
- package/web/eslint.config.js +0 -23
- package/web/index.css +0 -249
- package/web/index.html +0 -16
- package/web/main.tsx +0 -10
- package/web/package.json +0 -39
- package/web/public/vite.svg +0 -1
- package/web/tsconfig.app.json +0 -35
- package/web/tsconfig.json +0 -7
- package/web/tsconfig.node.json +0 -26
- package/web/vite.config.ts +0 -39
- package/worker/bun.lock +0 -237
- package/worker/package.json +0 -22
- package/worker/schema.sql +0 -96
- package/worker/src/handlers/auth.ts +0 -451
- package/worker/src/handlers/subdomains.ts +0 -376
- package/worker/src/handlers/user.ts +0 -98
- package/worker/src/index.ts +0 -70
- package/worker/src/middleware/auth.ts +0 -152
- package/worker/src/services/cloudflare.ts +0 -609
- package/worker/src/types.ts +0 -96
- package/worker/tsconfig.json +0 -15
- package/worker/wrangler.toml +0 -26
|
@@ -1,1119 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Session as TmuxSession,
|
|
3
|
-
InboxItem,
|
|
4
|
-
SessionCtrl,
|
|
5
|
-
SessionEvent,
|
|
6
|
-
} from '../../lib/tmux-lite/protocol.js';
|
|
7
|
-
import {
|
|
8
|
-
listSessions,
|
|
9
|
-
ensureServer,
|
|
10
|
-
createSession,
|
|
11
|
-
killSession,
|
|
12
|
-
getInbox,
|
|
13
|
-
clearInbox,
|
|
14
|
-
markInboxRead,
|
|
15
|
-
} from '../../lib/tmux-lite/cli.js';
|
|
16
|
-
import {
|
|
17
|
-
encodeControl,
|
|
18
|
-
encodePTY,
|
|
19
|
-
parseFrames,
|
|
20
|
-
decodeControl,
|
|
21
|
-
FrameType,
|
|
22
|
-
} from '../../lib/tmux-lite/protocol.js';
|
|
23
|
-
import {
|
|
24
|
-
getNotificationConfig,
|
|
25
|
-
updateNotificationConfig,
|
|
26
|
-
} from '../../core/config.js';
|
|
27
|
-
import { listProjectSummaries } from '../../core/project-catalog.js';
|
|
28
|
-
import { scanWorkspaces } from '../../lib/remote-session/workspace-scanner.js';
|
|
29
|
-
import { deleteWorkspaceCore } from '../../core/workspace.js';
|
|
30
|
-
import { prepareWorkspaceForSession } from '../../core/workspace-lifecycle.js';
|
|
31
|
-
import {
|
|
32
|
-
getBundleRefreshPlan as getBundleRefreshPlanCore,
|
|
33
|
-
applyBundleRefreshSubmission,
|
|
34
|
-
} from '../../core/bundle-refresh.js';
|
|
35
|
-
import { createBufferedSocketWriter } from '../../utils/bun-socket-writer.js';
|
|
36
|
-
import { findUtf8Boundary } from '../../utils/utf8.js';
|
|
37
|
-
import {
|
|
38
|
-
matchesWorkspaceId,
|
|
39
|
-
resolveWorkspaceName,
|
|
40
|
-
toCanonicalWorkspaceId,
|
|
41
|
-
} from '../../utils/workspace-id.js';
|
|
42
|
-
import { buildSessionName } from '../session-name.js';
|
|
43
|
-
import { buildWorkspaceSessionHooks } from '../workspace-shell-hooks.js';
|
|
44
|
-
import type {
|
|
45
|
-
AttachSessionParams,
|
|
46
|
-
BackendDescriptor,
|
|
47
|
-
DeleteWorkspaceParams,
|
|
48
|
-
SessionBackend,
|
|
49
|
-
} from '../backend.js';
|
|
50
|
-
import type { BackendEvent } from '../events.js';
|
|
51
|
-
import type { NotificationConfig } from '../../notifications/types.js';
|
|
52
|
-
import type { BundleRefreshPlan, BundleRefreshSubmission } from '../../types/bundle-refresh.js';
|
|
53
|
-
import type { ReviewOperation, ReviewResult } from '../../types/review.js';
|
|
54
|
-
import { executeLocalReviewOperation } from '../../core/review-executor.js';
|
|
55
|
-
import type { WideEventFilter } from '../../types/events.js';
|
|
56
|
-
import {
|
|
57
|
-
SpacesError,
|
|
58
|
-
WorkspaceDeleteError,
|
|
59
|
-
type WorkspaceDeleteErrorCode,
|
|
60
|
-
} from '../../types/errors.js';
|
|
61
|
-
import { parseProcessSessionName } from '../../lib/processes/names.js';
|
|
62
|
-
import {
|
|
63
|
-
loadProcessesConfig,
|
|
64
|
-
loadProcessesConfigWithDiagnostics,
|
|
65
|
-
getProcessDefinition,
|
|
66
|
-
} from '../../lib/processes/config.js';
|
|
67
|
-
import { getProcessSpecs, startProcessInstance, stopProcessInstance } from '../../lib/processes/manager.js';
|
|
68
|
-
import { startProcessScheduler } from '../../lib/processes/scheduler.js';
|
|
69
|
-
import { normalizeProcessInstanceCount } from '../../lib/processes/instances.js';
|
|
70
|
-
import { readWorkspaceSnapshots } from '../../lib/events/reader.js';
|
|
71
|
-
import { resolveWorkspaceRef } from '../../lib/events/paths.js';
|
|
72
|
-
import { loadSavedEventFilters } from '../../lib/events/filters.js';
|
|
73
|
-
import { readProjectConfig } from '../../core/config.js';
|
|
74
|
-
import { existsSync } from 'fs';
|
|
75
|
-
|
|
76
|
-
export interface LocalSessionBackendDependencies {
|
|
77
|
-
listSessions: typeof listSessions;
|
|
78
|
-
ensureServer: typeof ensureServer;
|
|
79
|
-
createSession: typeof createSession;
|
|
80
|
-
killSession: typeof killSession;
|
|
81
|
-
getInbox: typeof getInbox;
|
|
82
|
-
clearInbox: typeof clearInbox;
|
|
83
|
-
markInboxRead: typeof markInboxRead;
|
|
84
|
-
getNotificationConfig: typeof getNotificationConfig;
|
|
85
|
-
updateNotificationConfig: typeof updateNotificationConfig;
|
|
86
|
-
listProjectSummaries: typeof listProjectSummaries;
|
|
87
|
-
scanWorkspaces: typeof scanWorkspaces;
|
|
88
|
-
deleteWorkspaceCore: typeof deleteWorkspaceCore;
|
|
89
|
-
prepareWorkspaceForSession: typeof prepareWorkspaceForSession;
|
|
90
|
-
getBundleRefreshPlanCore: typeof getBundleRefreshPlanCore;
|
|
91
|
-
applyBundleRefreshSubmission: typeof applyBundleRefreshSubmission;
|
|
92
|
-
connectSessionSocket: (
|
|
93
|
-
socketPath: string,
|
|
94
|
-
handlers: LocalSessionSocketHandlers
|
|
95
|
-
) => Promise<LocalSessionSocketConnection>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface LocalSessionSocketHandlers {
|
|
99
|
-
onPtyData: (data: Uint8Array) => void;
|
|
100
|
-
onControl: (event: SessionEvent) => void;
|
|
101
|
-
onClose: () => void;
|
|
102
|
-
onError: (error: Error) => void;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface LocalSessionSocketConnection {
|
|
106
|
-
sendControl: (control: SessionCtrl) => void;
|
|
107
|
-
sendPty: (data: Uint8Array) => void;
|
|
108
|
-
close: () => void;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface LocalSessionBackendOptions {
|
|
112
|
-
descriptor?: BackendDescriptor;
|
|
113
|
-
deps?: Partial<LocalSessionBackendDependencies>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const DEFAULT_DESCRIPTOR: BackendDescriptor = {
|
|
117
|
-
key: 'local',
|
|
118
|
-
kind: 'local',
|
|
119
|
-
label: 'Local',
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
function toSessionInfo(
|
|
123
|
-
session: TmuxSession,
|
|
124
|
-
workspaceId: string
|
|
125
|
-
): {
|
|
126
|
-
id: string;
|
|
127
|
-
name: string;
|
|
128
|
-
workspaceId: string;
|
|
129
|
-
attached: boolean;
|
|
130
|
-
createdAt: number;
|
|
131
|
-
processTitle?: string;
|
|
132
|
-
exitCode?: number;
|
|
133
|
-
socketPath?: string;
|
|
134
|
-
cwd?: string;
|
|
135
|
-
pid?: number;
|
|
136
|
-
} {
|
|
137
|
-
return {
|
|
138
|
-
id: session.id,
|
|
139
|
-
name: session.name,
|
|
140
|
-
workspaceId,
|
|
141
|
-
attached: session.attached,
|
|
142
|
-
createdAt: session.createdAt,
|
|
143
|
-
processTitle: session.processTitle,
|
|
144
|
-
exitCode: session.exitCode,
|
|
145
|
-
socketPath: session.socketPath,
|
|
146
|
-
cwd: session.cwd,
|
|
147
|
-
pid: session.pid,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function toError(error: unknown, fallback: string): Error {
|
|
152
|
-
if (error instanceof Error) {
|
|
153
|
-
return error;
|
|
154
|
-
}
|
|
155
|
-
return new SpacesError(fallback, 'SYSTEM_ERROR', 2);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function toWorkspaceDeleteErrorCode(error: unknown): WorkspaceDeleteErrorCode | undefined {
|
|
159
|
-
if (!error || typeof error !== 'object' || !('code' in error)) {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const code = (error as { code?: unknown }).code;
|
|
164
|
-
if (
|
|
165
|
-
code === 'REMOVE_SCRIPT_FAILED' ||
|
|
166
|
-
code === 'WORKSPACE_NOT_FOUND' ||
|
|
167
|
-
code === 'WORKTREE_REMOVE_FAILED' ||
|
|
168
|
-
code === 'DELETE_FAILED'
|
|
169
|
-
) {
|
|
170
|
-
return code;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function getDefaultTerminalSize(): { cols: number; rows: number } {
|
|
177
|
-
const cols = process.stdout.columns || 80;
|
|
178
|
-
const rows = process.stdout.rows || 24;
|
|
179
|
-
return { cols, rows };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function concatUint8Array(parts: Uint8Array[]): Uint8Array {
|
|
183
|
-
const total = parts.reduce((sum, part) => sum + part.length, 0);
|
|
184
|
-
const combined = new Uint8Array(total);
|
|
185
|
-
let offset = 0;
|
|
186
|
-
for (const part of parts) {
|
|
187
|
-
combined.set(part, offset);
|
|
188
|
-
offset += part.length;
|
|
189
|
-
}
|
|
190
|
-
return combined;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function isAttachRetryableError(error: unknown): boolean {
|
|
194
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
195
|
-
return (
|
|
196
|
-
message.includes('Timed out attaching to session') ||
|
|
197
|
-
message.includes('Local session socket closed') ||
|
|
198
|
-
message.includes('Local session socket error') ||
|
|
199
|
-
message.includes('Failed to connect to session')
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function toExitedSessionError(session: TmuxSession): Error {
|
|
204
|
-
const suffix = typeof session.exitCode === 'number' ? ` (exit ${session.exitCode})` : '';
|
|
205
|
-
return new SpacesError(`Session has already exited: ${session.name}${suffix}`, 'USER_ERROR', 1);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function scriptFailureCodeForPhase(phase: 'pre' | 'setup' | 'select'): string {
|
|
209
|
-
if (phase === 'setup') {
|
|
210
|
-
return 'SETUP_SCRIPT_FAILED';
|
|
211
|
-
}
|
|
212
|
-
if (phase === 'select') {
|
|
213
|
-
return 'SELECT_SCRIPT_FAILED';
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return 'PRE_SCRIPT_FAILED';
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async function connectSessionSocket(
|
|
220
|
-
socketPath: string,
|
|
221
|
-
handlers: LocalSessionSocketHandlers
|
|
222
|
-
): Promise<LocalSessionSocketConnection> {
|
|
223
|
-
let frameBuffer = Buffer.alloc(0);
|
|
224
|
-
let closed = false;
|
|
225
|
-
let writer: ReturnType<typeof createBufferedSocketWriter> | null = null;
|
|
226
|
-
|
|
227
|
-
const socket = await Bun.connect({
|
|
228
|
-
unix: socketPath,
|
|
229
|
-
socket: {
|
|
230
|
-
drain() {
|
|
231
|
-
writer?.flush();
|
|
232
|
-
},
|
|
233
|
-
data(_socket, data) {
|
|
234
|
-
if (closed) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
let parseResult;
|
|
239
|
-
frameBuffer = Buffer.concat([frameBuffer, Buffer.from(data)]);
|
|
240
|
-
try {
|
|
241
|
-
parseResult = parseFrames(frameBuffer);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
frameBuffer = Buffer.alloc(0);
|
|
244
|
-
handlers.onError(toError(error, 'Failed to parse local session frames'));
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
frameBuffer = Buffer.from(parseResult.remaining);
|
|
249
|
-
|
|
250
|
-
for (const frame of parseResult.frames) {
|
|
251
|
-
if (frame.type === FrameType.PTY) {
|
|
252
|
-
handlers.onPtyData(new Uint8Array(frame.payload));
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (frame.type !== FrameType.CONTROL) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
const event = decodeControl(frame.payload) as SessionEvent;
|
|
262
|
-
handlers.onControl(event);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
handlers.onError(toError(error, 'Failed to decode local session control frame'));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
close() {
|
|
269
|
-
if (closed) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
closed = true;
|
|
273
|
-
handlers.onClose();
|
|
274
|
-
},
|
|
275
|
-
error(_socket, error) {
|
|
276
|
-
handlers.onError(toError(error, 'Local session socket error'));
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
writer = createBufferedSocketWriter(socket);
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
sendControl: (control) => {
|
|
285
|
-
if (closed || !writer) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
writer.write(encodeControl(control));
|
|
289
|
-
},
|
|
290
|
-
sendPty: (data) => {
|
|
291
|
-
if (closed || !writer) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
writer.write(encodePTY(Buffer.from(data)));
|
|
295
|
-
},
|
|
296
|
-
close: () => {
|
|
297
|
-
if (closed) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
closed = true;
|
|
301
|
-
socket.end();
|
|
302
|
-
},
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function buildDeps(
|
|
307
|
-
overrides?: Partial<LocalSessionBackendDependencies>
|
|
308
|
-
): LocalSessionBackendDependencies {
|
|
309
|
-
return {
|
|
310
|
-
listSessions,
|
|
311
|
-
ensureServer,
|
|
312
|
-
createSession,
|
|
313
|
-
killSession,
|
|
314
|
-
getInbox,
|
|
315
|
-
clearInbox,
|
|
316
|
-
markInboxRead,
|
|
317
|
-
getNotificationConfig,
|
|
318
|
-
updateNotificationConfig,
|
|
319
|
-
listProjectSummaries,
|
|
320
|
-
scanWorkspaces,
|
|
321
|
-
deleteWorkspaceCore,
|
|
322
|
-
prepareWorkspaceForSession,
|
|
323
|
-
getBundleRefreshPlanCore,
|
|
324
|
-
applyBundleRefreshSubmission,
|
|
325
|
-
connectSessionSocket,
|
|
326
|
-
...overrides,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export class LocalSessionBackend implements SessionBackend {
|
|
331
|
-
readonly descriptor: BackendDescriptor;
|
|
332
|
-
private readonly deps: LocalSessionBackendDependencies;
|
|
333
|
-
private readonly handlers = new Set<(event: BackendEvent) => void>();
|
|
334
|
-
private connected = false;
|
|
335
|
-
private attachedSessionId: string | null = null;
|
|
336
|
-
private sessionSocket: LocalSessionSocketConnection | null = null;
|
|
337
|
-
private sessionSocketSessionId: string | null = null;
|
|
338
|
-
private sessionSocketGeneration = 0;
|
|
339
|
-
private closingSessionSocket = false;
|
|
340
|
-
private ptyOutputHandler: ((data: Uint8Array) => void) | null = null;
|
|
341
|
-
private pendingPtyChunks: Uint8Array[] = [];
|
|
342
|
-
private pendingUtf8Bytes = new Uint8Array(0);
|
|
343
|
-
private viewOnly = false;
|
|
344
|
-
|
|
345
|
-
constructor(options: LocalSessionBackendOptions = {}) {
|
|
346
|
-
this.descriptor = options.descriptor ?? DEFAULT_DESCRIPTOR;
|
|
347
|
-
this.deps = buildDeps(options.deps);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
onEvent(handler: (event: BackendEvent) => void): () => void {
|
|
351
|
-
this.handlers.add(handler);
|
|
352
|
-
return () => {
|
|
353
|
-
this.handlers.delete(handler);
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
setPtyOutputHandler(handler: ((data: Uint8Array) => void) | null): void {
|
|
358
|
-
this.ptyOutputHandler = handler;
|
|
359
|
-
if (!handler || this.pendingPtyChunks.length === 0) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const pending = [...this.pendingPtyChunks];
|
|
364
|
-
this.pendingPtyChunks = [];
|
|
365
|
-
for (const chunk of pending) {
|
|
366
|
-
this.emitPtyData(chunk);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
async connect(): Promise<void> {
|
|
371
|
-
await this.deps.ensureServer();
|
|
372
|
-
this.connected = true;
|
|
373
|
-
this.emit({ type: 'status', status: 'connected' });
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
async disconnect(): Promise<void> {
|
|
377
|
-
await this.closeSessionSocket(false);
|
|
378
|
-
this.connected = false;
|
|
379
|
-
const wasAttached = this.attachedSessionId !== null;
|
|
380
|
-
this.attachedSessionId = null;
|
|
381
|
-
this.emit({ type: 'status', status: 'disconnected' });
|
|
382
|
-
if (wasAttached) {
|
|
383
|
-
this.emit({ type: 'detached' });
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
async listProjects(): Promise<void> {
|
|
388
|
-
const projects = this.deps.listProjectSummaries().map((project) => ({
|
|
389
|
-
name: project.name,
|
|
390
|
-
repository: project.repository,
|
|
391
|
-
workspaceCount: project.workspaceCount,
|
|
392
|
-
isCurrent: project.isCurrent,
|
|
393
|
-
}));
|
|
394
|
-
this.emit({ type: 'projects', projects });
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
async listWorkspaces(): Promise<void> {
|
|
398
|
-
const [workspaces, sessions] = await Promise.all([
|
|
399
|
-
this.deps.scanWorkspaces(),
|
|
400
|
-
this.deps.listSessions(),
|
|
401
|
-
]);
|
|
402
|
-
|
|
403
|
-
const counts = new Map<string, number>();
|
|
404
|
-
for (const session of sessions) {
|
|
405
|
-
const current = counts.get(session.cwd) ?? 0;
|
|
406
|
-
counts.set(session.cwd, current + 1);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const mappedWorkspaces = workspaces.map((workspace) => {
|
|
410
|
-
const processConfig = loadProcessesConfigWithDiagnostics(workspace.path);
|
|
411
|
-
return {
|
|
412
|
-
...workspace,
|
|
413
|
-
id: toCanonicalWorkspaceId(workspace),
|
|
414
|
-
sessionCount: counts.get(workspace.path) ?? 0,
|
|
415
|
-
processes: processConfig.config.processes.map((p) => ({
|
|
416
|
-
name: p.name,
|
|
417
|
-
instances: p.instances,
|
|
418
|
-
ports: p.ports,
|
|
419
|
-
})),
|
|
420
|
-
processConfigError: processConfig.error ?? undefined,
|
|
421
|
-
};
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
this.emit({
|
|
425
|
-
type: 'workspaces',
|
|
426
|
-
workspaces: mappedWorkspaces,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
async listSessions(workspaceId?: string): Promise<void> {
|
|
431
|
-
const [sessions, workspaces] = await Promise.all([
|
|
432
|
-
this.deps.listSessions(),
|
|
433
|
-
this.deps.scanWorkspaces(),
|
|
434
|
-
]);
|
|
435
|
-
|
|
436
|
-
const workspaceByPath = new Map(workspaces.map((workspace) => [workspace.path, workspace]));
|
|
437
|
-
|
|
438
|
-
const filtered = sessions
|
|
439
|
-
.map((session) => {
|
|
440
|
-
const parsed = parseProcessSessionName(session.name);
|
|
441
|
-
let workspace = workspaceByPath.get(session.cwd);
|
|
442
|
-
if (!workspace && parsed) {
|
|
443
|
-
workspace = workspaces.find((w) => w.id === parsed.workspaceId);
|
|
444
|
-
}
|
|
445
|
-
if (!workspace) {
|
|
446
|
-
workspace = workspaces.find((w) => session.cwd.startsWith(w.path));
|
|
447
|
-
}
|
|
448
|
-
const id = workspace ? toCanonicalWorkspaceId(workspace) : (parsed?.workspaceId ? `unknown:${parsed.workspaceId}` : 'unknown');
|
|
449
|
-
const info = toSessionInfo(session, id);
|
|
450
|
-
return {
|
|
451
|
-
...info,
|
|
452
|
-
processName: parsed?.processName,
|
|
453
|
-
processInstance: parsed?.instance,
|
|
454
|
-
};
|
|
455
|
-
})
|
|
456
|
-
.filter((session) => {
|
|
457
|
-
if (!workspaceId) {
|
|
458
|
-
return true;
|
|
459
|
-
}
|
|
460
|
-
return (
|
|
461
|
-
session.workspaceId === workspaceId ||
|
|
462
|
-
session.workspaceId.endsWith(`:${workspaceId}`)
|
|
463
|
-
);
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
this.emit({ type: 'sessions', sessions: filtered });
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
async attachSession(params: AttachSessionParams): Promise<void> {
|
|
470
|
-
if (!this.connected) {
|
|
471
|
-
await this.connect();
|
|
472
|
-
}
|
|
473
|
-
this.viewOnly = params.viewOnly ?? false;
|
|
474
|
-
|
|
475
|
-
let targetSession: TmuxSession | null = null;
|
|
476
|
-
|
|
477
|
-
if (params.sessionId) {
|
|
478
|
-
const sessions = await this.deps.listSessions();
|
|
479
|
-
targetSession = sessions.find((session) => session.id === params.sessionId) ?? null;
|
|
480
|
-
if (!targetSession) {
|
|
481
|
-
throw new SpacesError(`Session not found: ${params.sessionId}`, 'USER_ERROR', 1);
|
|
482
|
-
}
|
|
483
|
-
if (typeof targetSession.exitCode === 'number') {
|
|
484
|
-
throw toExitedSessionError(targetSession);
|
|
485
|
-
}
|
|
486
|
-
} else if (params.workspaceId) {
|
|
487
|
-
const workspaceId = params.workspaceId;
|
|
488
|
-
const workspaces = await this.deps.scanWorkspaces();
|
|
489
|
-
const workspace = workspaces.find(
|
|
490
|
-
(item) => matchesWorkspaceId(item, workspaceId)
|
|
491
|
-
);
|
|
492
|
-
if (!workspace) {
|
|
493
|
-
throw new SpacesError(`Workspace not found: ${workspaceId}`, 'USER_ERROR', 1);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const sessions = await this.deps.listSessions();
|
|
497
|
-
const fullName = buildSessionName({
|
|
498
|
-
projectName: workspace.projectName,
|
|
499
|
-
workspaceName: workspace.id,
|
|
500
|
-
requestedName: params.sessionName,
|
|
501
|
-
sessions,
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
if (params.command) {
|
|
505
|
-
// Skip workspace scripts when a custom command is specified
|
|
506
|
-
targetSession = await this.deps.createSession(fullName, workspace.path, {
|
|
507
|
-
command: params.command,
|
|
508
|
-
args: params.args,
|
|
509
|
-
env: params.env,
|
|
510
|
-
});
|
|
511
|
-
} else {
|
|
512
|
-
let currentPhase: 'pre' | 'setup' | 'select' = 'pre';
|
|
513
|
-
|
|
514
|
-
const scriptResult = await this.deps.prepareWorkspaceForSession({
|
|
515
|
-
projectName: workspace.projectName,
|
|
516
|
-
workspacePath: workspace.path,
|
|
517
|
-
workspaceName: workspace.id,
|
|
518
|
-
interactiveScripts: false,
|
|
519
|
-
bundleMode: 'error-if-changed',
|
|
520
|
-
scriptPolicy: params.scriptPolicy ?? 'auto',
|
|
521
|
-
onOutput: (data) => {
|
|
522
|
-
this.emitPtyData(data);
|
|
523
|
-
this.emit({
|
|
524
|
-
type: 'script_output',
|
|
525
|
-
phase: currentPhase,
|
|
526
|
-
data,
|
|
527
|
-
});
|
|
528
|
-
},
|
|
529
|
-
onPhaseStart: (phase) => {
|
|
530
|
-
currentPhase = phase;
|
|
531
|
-
},
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
if (!scriptResult.success) {
|
|
535
|
-
const bundleNeedsRefresh =
|
|
536
|
-
'bundleNeedsRefresh' in scriptResult && scriptResult.bundleNeedsRefresh;
|
|
537
|
-
|
|
538
|
-
if ('bundleNeedsRefresh' in scriptResult && scriptResult.bundleNeedsRefresh) {
|
|
539
|
-
this.emit({
|
|
540
|
-
type: 'command_error',
|
|
541
|
-
code: 'BUNDLE_REFRESH_REQUIRED',
|
|
542
|
-
message: scriptResult.error,
|
|
543
|
-
});
|
|
544
|
-
} else {
|
|
545
|
-
this.emit({
|
|
546
|
-
type: 'command_error',
|
|
547
|
-
code: scriptFailureCodeForPhase(scriptResult.phase),
|
|
548
|
-
message: scriptResult.error,
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
this.emit({
|
|
553
|
-
type: 'script_output',
|
|
554
|
-
phase: scriptResult.phase,
|
|
555
|
-
data: new Uint8Array(0),
|
|
556
|
-
done: true,
|
|
557
|
-
error: scriptResult.error,
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
const error = new SpacesError(
|
|
561
|
-
`Workspace scripts failed during ${scriptResult.phase}: ${scriptResult.error}`
|
|
562
|
-
) as Error & { code?: string };
|
|
563
|
-
if (bundleNeedsRefresh) {
|
|
564
|
-
error.code = 'BUNDLE_REFRESH_REQUIRED';
|
|
565
|
-
} else {
|
|
566
|
-
error.code = scriptFailureCodeForPhase(scriptResult.phase);
|
|
567
|
-
}
|
|
568
|
-
throw error;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
this.emit({
|
|
572
|
-
type: 'script_output',
|
|
573
|
-
phase: currentPhase,
|
|
574
|
-
data: new Uint8Array(0),
|
|
575
|
-
done: true,
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
targetSession = await this.deps.createSession(fullName, workspace.path, {
|
|
579
|
-
hooks: buildWorkspaceSessionHooks(workspace.projectName, workspace.id),
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
} else {
|
|
583
|
-
throw new SpacesError('attachSession requires sessionId or workspaceId', 'USER_ERROR', 1);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
await this.attachToSessionSocketWithRetry(targetSession, params);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
async detachSession(): Promise<void> {
|
|
590
|
-
if (this.sessionSocket) {
|
|
591
|
-
this.sessionSocket.sendControl({ type: 'detach' });
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
const hadAttached = this.attachedSessionId !== null;
|
|
595
|
-
await this.closeSessionSocket(false);
|
|
596
|
-
this.attachedSessionId = null;
|
|
597
|
-
this.viewOnly = false;
|
|
598
|
-
if (hadAttached) {
|
|
599
|
-
this.emit({ type: 'detached' });
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
async writePtyData(data: Uint8Array): Promise<void> {
|
|
604
|
-
if (this.viewOnly) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
const socket = this.sessionSocket;
|
|
608
|
-
if (!socket || !this.attachedSessionId) {
|
|
609
|
-
throw new SpacesError('No attached local session', 'SYSTEM_ERROR', 2);
|
|
610
|
-
}
|
|
611
|
-
socket.sendPty(data);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
async resizePty(cols: number, rows: number): Promise<void> {
|
|
615
|
-
const socket = this.sessionSocket;
|
|
616
|
-
if (!socket || !this.attachedSessionId) {
|
|
617
|
-
throw new SpacesError('No attached local session', 'SYSTEM_ERROR', 2);
|
|
618
|
-
}
|
|
619
|
-
socket.sendControl({ type: 'resize', cols, rows });
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
async killSession(sessionId: string): Promise<void> {
|
|
623
|
-
await this.deps.killSession(sessionId);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
async deleteWorkspace(
|
|
627
|
-
projectName: string,
|
|
628
|
-
workspaceId: string,
|
|
629
|
-
params: DeleteWorkspaceParams = {}
|
|
630
|
-
): Promise<void> {
|
|
631
|
-
const resolvedWorkspaceId = resolveWorkspaceName(projectName, workspaceId);
|
|
632
|
-
const scriptPolicy = params.scriptPolicy ?? 'auto';
|
|
633
|
-
let emittedDone = false;
|
|
634
|
-
|
|
635
|
-
try {
|
|
636
|
-
const result = await this.deps.deleteWorkspaceCore(projectName, resolvedWorkspaceId, {
|
|
637
|
-
nonInteractive: true,
|
|
638
|
-
removeScriptPolicy: scriptPolicy === 'skip' ? 'skip' : 'enforce',
|
|
639
|
-
onScriptOutput: (data) => {
|
|
640
|
-
this.emitPtyData(data);
|
|
641
|
-
this.emit({
|
|
642
|
-
type: 'script_output',
|
|
643
|
-
phase: 'remove',
|
|
644
|
-
data,
|
|
645
|
-
});
|
|
646
|
-
},
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
if (!result.success) {
|
|
650
|
-
const errorCode: WorkspaceDeleteErrorCode = result.errorCode ?? 'DELETE_FAILED';
|
|
651
|
-
const message = result.error ?? `Failed to delete workspace ${resolvedWorkspaceId}`;
|
|
652
|
-
|
|
653
|
-
this.emit({
|
|
654
|
-
type: 'command_error',
|
|
655
|
-
code: errorCode,
|
|
656
|
-
message,
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
this.emit({
|
|
660
|
-
type: 'script_output',
|
|
661
|
-
phase: 'remove',
|
|
662
|
-
data: new Uint8Array(0),
|
|
663
|
-
done: true,
|
|
664
|
-
error: message,
|
|
665
|
-
});
|
|
666
|
-
emittedDone = true;
|
|
667
|
-
|
|
668
|
-
throw new WorkspaceDeleteError(message, errorCode);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
this.emit({
|
|
672
|
-
type: 'script_output',
|
|
673
|
-
phase: 'remove',
|
|
674
|
-
data: new Uint8Array(0),
|
|
675
|
-
done: true,
|
|
676
|
-
});
|
|
677
|
-
emittedDone = true;
|
|
678
|
-
} catch (error) {
|
|
679
|
-
if (!emittedDone) {
|
|
680
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
681
|
-
const errorCode = toWorkspaceDeleteErrorCode(error) ?? 'DELETE_FAILED';
|
|
682
|
-
this.emit({
|
|
683
|
-
type: 'script_output',
|
|
684
|
-
phase: 'remove',
|
|
685
|
-
data: new Uint8Array(0),
|
|
686
|
-
done: true,
|
|
687
|
-
error: message,
|
|
688
|
-
});
|
|
689
|
-
this.emit({
|
|
690
|
-
type: 'command_error',
|
|
691
|
-
code: errorCode,
|
|
692
|
-
message,
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
if (!(error instanceof WorkspaceDeleteError)) {
|
|
696
|
-
throw new WorkspaceDeleteError(message, errorCode);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
throw error;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
async getBundleRefreshPlan(projectName: string, workspaceId: string): Promise<BundleRefreshPlan> {
|
|
704
|
-
const workspace = await this.resolveWorkspace(projectName, workspaceId);
|
|
705
|
-
return this.deps.getBundleRefreshPlanCore(projectName, workspace.path, workspace.id);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
async applyBundleRefresh(
|
|
709
|
-
projectName: string,
|
|
710
|
-
workspaceId: string,
|
|
711
|
-
submission: BundleRefreshSubmission
|
|
712
|
-
): Promise<void> {
|
|
713
|
-
const workspace = await this.resolveWorkspace(projectName, workspaceId);
|
|
714
|
-
await this.deps.applyBundleRefreshSubmission(projectName, workspace.path, submission);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
async sendReviewRequest(operation: ReviewOperation): Promise<ReviewResult> {
|
|
718
|
-
return executeLocalReviewOperation(operation, this.deps.scanWorkspaces);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
async requestInbox(): Promise<void> {
|
|
722
|
-
const [items, sessions] = await Promise.all([
|
|
723
|
-
this.deps.getInbox(),
|
|
724
|
-
this.deps.listSessions(),
|
|
725
|
-
]);
|
|
726
|
-
|
|
727
|
-
const activeSessionIds = new Set(sessions.map((session) => session.id));
|
|
728
|
-
const activeUnread = new Set<string>();
|
|
729
|
-
for (const item of items) {
|
|
730
|
-
if (!item.read && activeSessionIds.has(item.sessionId)) {
|
|
731
|
-
activeUnread.add(item.sessionId);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
this.emit({
|
|
736
|
-
type: 'inbox',
|
|
737
|
-
items: items as InboxItem[],
|
|
738
|
-
unreadCount: activeUnread.size,
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
async clearInbox(id?: string): Promise<void> {
|
|
743
|
-
await this.deps.clearInbox(id);
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
async markInboxRead(id: string): Promise<void> {
|
|
747
|
-
await this.deps.markInboxRead(id);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
async getNotificationConfig(): Promise<void> {
|
|
751
|
-
const config = this.deps.getNotificationConfig() as NotificationConfig;
|
|
752
|
-
this.emit({ type: 'notification_config', config });
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
async updateNotificationConfig(config: NotificationConfig): Promise<void> {
|
|
756
|
-
const updated = this.deps.updateNotificationConfig(config) as NotificationConfig;
|
|
757
|
-
this.emit({ type: 'notification_config', config: updated });
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
async startProcess(workspaceId: string, processName: string, instance?: number): Promise<void> {
|
|
761
|
-
const workspaces = await this.deps.scanWorkspaces();
|
|
762
|
-
const workspace = workspaces.find(
|
|
763
|
-
(w) => w.id === workspaceId || toCanonicalWorkspaceId(w) === workspaceId
|
|
764
|
-
);
|
|
765
|
-
if (!workspace) {
|
|
766
|
-
throw new SpacesError(`Workspace not found: ${workspaceId}`, 'USER_ERROR', 1);
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
const processConfig = loadProcessesConfig(workspace.path);
|
|
770
|
-
const processDefinition = getProcessDefinition(processConfig, processName);
|
|
771
|
-
if (!processDefinition) {
|
|
772
|
-
throw new SpacesError(`Process not found: ${processName}`, 'USER_ERROR', 1);
|
|
773
|
-
}
|
|
774
|
-
if (normalizeProcessInstanceCount(processDefinition.instances) === 0) {
|
|
775
|
-
throw new SpacesError(`Process is disabled (instances: 0): ${processName}`, 'USER_ERROR', 1);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
const specs = getProcessSpecs(workspace.path).filter((s) =>
|
|
779
|
-
s.name === processName && (instance === undefined || s.instance === instance)
|
|
780
|
-
);
|
|
781
|
-
if (specs.length === 0) {
|
|
782
|
-
throw new SpacesError(`Process not found: ${processName}`, 'USER_ERROR', 1);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const sessionIds: string[] = [];
|
|
786
|
-
const startedSpecs: typeof specs = [];
|
|
787
|
-
try {
|
|
788
|
-
for (const spec of specs) {
|
|
789
|
-
const result = await startProcessInstance(workspace.path, spec);
|
|
790
|
-
sessionIds.push(result.sessionId);
|
|
791
|
-
startedSpecs.push(spec);
|
|
792
|
-
}
|
|
793
|
-
} catch (error) {
|
|
794
|
-
for (const startedSpec of startedSpecs) {
|
|
795
|
-
try {
|
|
796
|
-
await stopProcessInstance(workspace.path, startedSpec);
|
|
797
|
-
} catch {
|
|
798
|
-
// Best-effort rollback; preserve original start error
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
throw error;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
if (!this.processSchedulers.has(workspace.path)) {
|
|
805
|
-
this.processSchedulers.set(workspace.path, startProcessScheduler(workspace.path));
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
this.emit({
|
|
809
|
-
type: 'process_started',
|
|
810
|
-
workspaceId,
|
|
811
|
-
processName,
|
|
812
|
-
sessionId: sessionIds[0],
|
|
813
|
-
sessionIds,
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
async stopProcess(workspaceId: string, processName: string): Promise<void> {
|
|
818
|
-
const workspaces = await this.deps.scanWorkspaces();
|
|
819
|
-
const workspace = workspaces.find(
|
|
820
|
-
(w) => w.id === workspaceId || toCanonicalWorkspaceId(w) === workspaceId
|
|
821
|
-
);
|
|
822
|
-
if (!workspace) {
|
|
823
|
-
throw new SpacesError(`Workspace not found: ${workspaceId}`, 'USER_ERROR', 1);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const specs = getProcessSpecs(workspace.path).filter((s) => s.name === processName);
|
|
827
|
-
if (specs.length === 0) {
|
|
828
|
-
throw new SpacesError(`Process not found: ${processName}`, 'USER_ERROR', 1);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
for (const spec of specs) {
|
|
832
|
-
await stopProcessInstance(workspace.path, spec);
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
this.emit({
|
|
836
|
-
type: 'process_stopped',
|
|
837
|
-
workspaceId,
|
|
838
|
-
processName,
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
async requestEvents(
|
|
843
|
-
workspacePath: string,
|
|
844
|
-
filter?: WideEventFilter,
|
|
845
|
-
limit?: number,
|
|
846
|
-
sinceMs?: number,
|
|
847
|
-
): Promise<void> {
|
|
848
|
-
const workspaceRef = resolveWorkspaceRef(workspacePath);
|
|
849
|
-
if (!workspaceRef || !existsSync(workspaceRef.workspacePath)) {
|
|
850
|
-
this.emit({ type: 'events', events: [], liveEventIds: [], savedEventFilters: [] });
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const savedEventFilters = loadSavedEventFilters(workspaceRef.workspacePath);
|
|
855
|
-
|
|
856
|
-
const projectConfig = readProjectConfig(workspaceRef.projectName);
|
|
857
|
-
const snapshots = readWorkspaceSnapshots(workspaceRef.workspacePath, {
|
|
858
|
-
maxBytes: projectConfig.events?.snapshotCacheMaxBytes,
|
|
859
|
-
maxTimeline: projectConfig.events?.maxTimeline,
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
const filtered = snapshots
|
|
863
|
-
.filter((snapshot) => {
|
|
864
|
-
if (sinceMs !== undefined && snapshot.updatedAt < sinceMs) return false;
|
|
865
|
-
if (!filter) return true;
|
|
866
|
-
if (filter.processName && snapshot.processName !== filter.processName) return false;
|
|
867
|
-
if (filter.level && snapshot.level !== filter.level) return false;
|
|
868
|
-
if (filter.message && !snapshot.message.includes(filter.message)) return false;
|
|
869
|
-
if (filter.eventName && snapshot.eventName !== filter.eventName) return false;
|
|
870
|
-
if (filter.correlationId && snapshot.correlationId !== filter.correlationId) return false;
|
|
871
|
-
return true;
|
|
872
|
-
})
|
|
873
|
-
.slice(0, limit ?? 200);
|
|
874
|
-
|
|
875
|
-
const events = filtered.map((snapshot) => ({
|
|
876
|
-
eventId: snapshot.lastEventId,
|
|
877
|
-
eventName: snapshot.eventName,
|
|
878
|
-
level: snapshot.level,
|
|
879
|
-
timestamp: new Date(snapshot.updatedAt).toISOString(),
|
|
880
|
-
timestampMs: snapshot.updatedAt,
|
|
881
|
-
message: snapshot.message,
|
|
882
|
-
sessionId: '',
|
|
883
|
-
workspaceId: workspaceRef.workspaceId,
|
|
884
|
-
projectName: workspaceRef.projectName,
|
|
885
|
-
processName: snapshot.processName,
|
|
886
|
-
processInstance: snapshot.processInstance,
|
|
887
|
-
raw: snapshot.raw ?? {},
|
|
888
|
-
kind: 'wide' as const,
|
|
889
|
-
correlationId: snapshot.correlationId,
|
|
890
|
-
timeline: Object.values(snapshot.timelineMap),
|
|
891
|
-
timelineMap: snapshot.timelineMap,
|
|
892
|
-
timelineOrder: snapshot.timelineOrder,
|
|
893
|
-
}));
|
|
894
|
-
|
|
895
|
-
this.emit({ type: 'events', events, liveEventIds: [], savedEventFilters });
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
private processSchedulers = new Map<string, NodeJS.Timer>();
|
|
899
|
-
|
|
900
|
-
private async attachToSessionSocket(
|
|
901
|
-
session: TmuxSession,
|
|
902
|
-
params: AttachSessionParams
|
|
903
|
-
): Promise<void> {
|
|
904
|
-
await this.closeSessionSocket(true);
|
|
905
|
-
|
|
906
|
-
const size = getDefaultTerminalSize();
|
|
907
|
-
const cols = params.cols ?? size.cols;
|
|
908
|
-
const rows = params.rows ?? size.rows;
|
|
909
|
-
const expectedSessionId = session.id;
|
|
910
|
-
const expectedGeneration = ++this.sessionSocketGeneration;
|
|
911
|
-
|
|
912
|
-
await new Promise<void>((resolve, reject) => {
|
|
913
|
-
let settled = false;
|
|
914
|
-
const settleResolve = () => {
|
|
915
|
-
if (settled) {
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
settled = true;
|
|
919
|
-
clearTimeout(timeout);
|
|
920
|
-
resolve();
|
|
921
|
-
};
|
|
922
|
-
const settleReject = (error: Error) => {
|
|
923
|
-
if (settled) {
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
settled = true;
|
|
927
|
-
clearTimeout(timeout);
|
|
928
|
-
reject(error);
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
const timeout = setTimeout(() => {
|
|
932
|
-
settleReject(new SpacesError(`Timed out attaching to session ${session.name}`, 'SYSTEM_ERROR', 2));
|
|
933
|
-
}, 15000);
|
|
934
|
-
|
|
935
|
-
void (async () => {
|
|
936
|
-
try {
|
|
937
|
-
const connection = await this.deps.connectSessionSocket(session.socketPath, {
|
|
938
|
-
onPtyData: (data) => {
|
|
939
|
-
if (
|
|
940
|
-
this.sessionSocketGeneration !== expectedGeneration ||
|
|
941
|
-
this.sessionSocketSessionId !== expectedSessionId
|
|
942
|
-
) {
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
this.emitPtyData(data);
|
|
946
|
-
},
|
|
947
|
-
onControl: (event) => {
|
|
948
|
-
if (
|
|
949
|
-
this.sessionSocketGeneration !== expectedGeneration ||
|
|
950
|
-
this.sessionSocketSessionId !== expectedSessionId
|
|
951
|
-
) {
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
if (event.type === 'attached') {
|
|
955
|
-
this.attachedSessionId = session.id;
|
|
956
|
-
this.emit({
|
|
957
|
-
type: 'attached',
|
|
958
|
-
sessionId: session.id,
|
|
959
|
-
sessionName: session.name,
|
|
960
|
-
viewOnly: this.viewOnly,
|
|
961
|
-
});
|
|
962
|
-
settleResolve();
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
this.handleSessionControl(event, session.id);
|
|
966
|
-
},
|
|
967
|
-
onClose: () => {
|
|
968
|
-
if (
|
|
969
|
-
this.sessionSocketGeneration !== expectedGeneration ||
|
|
970
|
-
this.sessionSocketSessionId !== expectedSessionId
|
|
971
|
-
) {
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
|
-
if (this.closingSessionSocket) {
|
|
975
|
-
this.closingSessionSocket = false;
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
const hadAttached = this.attachedSessionId !== null;
|
|
980
|
-
this.sessionSocket = null;
|
|
981
|
-
this.sessionSocketSessionId = null;
|
|
982
|
-
this.attachedSessionId = null;
|
|
983
|
-
|
|
984
|
-
if (!settled) {
|
|
985
|
-
settleReject(new SpacesError(`Local session socket closed: ${session.name}`, 'SYSTEM_ERROR', 2));
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
if (hadAttached) {
|
|
990
|
-
this.emit({ type: 'detached' });
|
|
991
|
-
}
|
|
992
|
-
},
|
|
993
|
-
onError: (error) => {
|
|
994
|
-
this.emit({ type: 'error', message: error.message });
|
|
995
|
-
settleReject(error);
|
|
996
|
-
},
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
this.sessionSocket = connection;
|
|
1000
|
-
this.sessionSocketSessionId = expectedSessionId;
|
|
1001
|
-
connection.sendControl({ type: 'attach-init', cols, rows, clientType: 'cli' });
|
|
1002
|
-
} catch (error) {
|
|
1003
|
-
settleReject(toError(error, `Failed to connect to session ${session.name}`));
|
|
1004
|
-
}
|
|
1005
|
-
})();
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
private async attachToSessionSocketWithRetry(
|
|
1010
|
-
session: TmuxSession,
|
|
1011
|
-
params: AttachSessionParams
|
|
1012
|
-
): Promise<void> {
|
|
1013
|
-
try {
|
|
1014
|
-
await this.attachToSessionSocket(session, params);
|
|
1015
|
-
return;
|
|
1016
|
-
} catch (error) {
|
|
1017
|
-
if (!isAttachRetryableError(error)) {
|
|
1018
|
-
throw error;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
const latestSessions = await this.deps.listSessions();
|
|
1023
|
-
const refreshed = latestSessions.find((item) => item.id === session.id) ?? session;
|
|
1024
|
-
|
|
1025
|
-
if (typeof refreshed.exitCode === 'number') {
|
|
1026
|
-
throw toExitedSessionError(refreshed);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
await this.attachToSessionSocket(refreshed, params);
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
private async closeSessionSocket(emitDetached: boolean): Promise<void> {
|
|
1033
|
-
const socket = this.sessionSocket;
|
|
1034
|
-
const hadAttached = this.attachedSessionId !== null;
|
|
1035
|
-
|
|
1036
|
-
// Invalidate any stale socket callbacks from earlier connections.
|
|
1037
|
-
this.sessionSocketGeneration += 1;
|
|
1038
|
-
|
|
1039
|
-
if (socket) {
|
|
1040
|
-
this.closingSessionSocket = true;
|
|
1041
|
-
socket.close();
|
|
1042
|
-
this.sessionSocket = null;
|
|
1043
|
-
this.sessionSocketSessionId = null;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
this.attachedSessionId = null;
|
|
1047
|
-
this.pendingUtf8Bytes = new Uint8Array(0);
|
|
1048
|
-
this.pendingPtyChunks = [];
|
|
1049
|
-
|
|
1050
|
-
if (emitDetached && hadAttached) {
|
|
1051
|
-
this.emit({ type: 'detached' });
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
private handleSessionControl(event: SessionEvent, sessionId: string): void {
|
|
1056
|
-
if (event.type === 'kicked') {
|
|
1057
|
-
void this.closeSessionSocket(true);
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
if (event.type === 'exited') {
|
|
1062
|
-
const exitCode = typeof event.code === 'number' ? event.code : undefined;
|
|
1063
|
-
this.emit({ type: 'session_exited', sessionId, exitCode });
|
|
1064
|
-
void this.closeSessionSocket(false);
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
private async resolveWorkspace(
|
|
1070
|
-
projectName: string,
|
|
1071
|
-
workspaceId: string
|
|
1072
|
-
): Promise<{ id: string; path: string }> {
|
|
1073
|
-
const resolvedWorkspaceId = resolveWorkspaceName(projectName, workspaceId);
|
|
1074
|
-
const workspaces = await this.deps.scanWorkspaces();
|
|
1075
|
-
const workspace = workspaces.find(
|
|
1076
|
-
(item) =>
|
|
1077
|
-
item.projectName === projectName &&
|
|
1078
|
-
(item.id === resolvedWorkspaceId || matchesWorkspaceId(item, workspaceId))
|
|
1079
|
-
);
|
|
1080
|
-
|
|
1081
|
-
if (!workspace) {
|
|
1082
|
-
throw new SpacesError(`Workspace not found: ${workspaceId}`, 'USER_ERROR', 1);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
return {
|
|
1086
|
-
id: toCanonicalWorkspaceId(workspace),
|
|
1087
|
-
path: workspace.path,
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
private emitPtyData(data: Uint8Array): void {
|
|
1092
|
-
if (!this.ptyOutputHandler) {
|
|
1093
|
-
this.pendingPtyChunks.push(data);
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
const combined = this.pendingUtf8Bytes.length
|
|
1098
|
-
? concatUint8Array([this.pendingUtf8Bytes, data])
|
|
1099
|
-
: data;
|
|
1100
|
-
|
|
1101
|
-
const boundary = findUtf8Boundary(combined);
|
|
1102
|
-
if (boundary < combined.length) {
|
|
1103
|
-
this.pendingUtf8Bytes = combined.slice(boundary);
|
|
1104
|
-
} else {
|
|
1105
|
-
this.pendingUtf8Bytes = new Uint8Array(0);
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
const chunk = combined.slice(0, boundary);
|
|
1109
|
-
if (chunk.length > 0) {
|
|
1110
|
-
this.ptyOutputHandler(chunk);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
private emit(event: BackendEvent): void {
|
|
1115
|
-
for (const handler of this.handlers) {
|
|
1116
|
-
handler(event);
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
}
|