rvlib-shipkit 2.29.0 → 2.30.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/CHANGELOG.md +20 -1
- package/package.json +2 -1
- package/src/advisors/app-graph.ts +1 -1
- package/src/advisors/expose.ts +5 -1
- package/src/advisors/r2.ts +7 -9
- package/src/advisors/routes.ts +29 -2
- package/src/advisors/scan.ts +11 -0
- package/src/agent-time/accounts-usage.ts +8 -0
- package/src/agent-time/claude-sessions.ts +32 -0
- package/src/agent-time/hooks.ts +1 -1
- package/src/agent-time/live.ts +5 -2
- package/src/agent-time/registry.ts +186 -89
- package/src/agent-time/store.ts +6 -4
- package/src/asks/ask-doc.ts +2 -2
- package/src/asks/ask-store.ts +22 -7
- package/src/check.ts +9 -1
- package/src/checks/SK001-package-json-shape.check.ts +1 -0
- package/src/checks/SK003-claude-md-shape.check.ts +1 -0
- package/src/checks/SK004-gitignore-policy.check.ts +12 -6
- package/src/checks/SK008-reviewer-agent.check.ts +4 -7
- package/src/checks/SK013-one-way-in-policy.check.ts +1 -0
- package/src/checks/SK017-vscode-hub-task.check.ts +1 -0
- package/src/checks/SK024-identity-colors.check.ts +1 -1
- package/src/checks/SK027-agent-wiki-links.check.ts +2 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -0
- package/src/checks/SK034-commit-gates-armed.check.ts +1 -0
- package/src/checks/SK039-vscode-watch-generated.check.ts +1 -0
- package/src/checks/SK049-thread-answers-hook.check.ts +9 -5
- package/src/checks/SK050-retired-commands.check.ts +1 -0
- package/src/checks/SK051-no-formatter.check.ts +1 -0
- package/src/cli/channel-run.ts +17 -0
- package/src/cli/cmd_Advisors.ts +28 -7
- package/src/cli/cmd_Asks.ts +2 -2
- package/src/cli/cmd_Backup.ts +5 -1
- package/src/cli/cmd_CacheAudit.ts +1 -1
- package/src/cli/cmd_Channel.ts +43 -0
- package/src/cli/cmd_GlobalProcesses.ts +1 -0
- package/src/cli/cmd_Home.ts +12 -5
- package/src/cli/cmd_Hooks.ts +1 -1
- package/src/cli/cmd_Hq.ts +43 -0
- package/src/cli/cmd_Lanes.ts +15 -3
- package/src/cli/cmd_Media.ts +8 -3
- package/src/cli/cmd_Orchestrator.ts +253 -84
- package/src/cli/cmd_OrchestratorRole.ts +163 -0
- package/src/cli/cmd_Review.ts +142 -165
- package/src/cli/cmd_Secret.ts +44 -14
- package/src/cli/cmd_Shot.ts +2 -4
- package/src/cli/cmd_Sound.ts +1 -0
- package/src/cli/cmd_Urls.ts +3 -3
- package/src/cli/inbox-hook-run.ts +109 -0
- package/src/cli/registry.ts +6 -2
- package/src/cli/review-here.ts +136 -0
- package/src/cli.ts +45 -14
- package/src/collections/actions.ts +5 -4
- package/src/collections/checks.ts +5 -0
- package/src/collections/collection-types.ts +4 -3
- package/src/collections/pings.ts +4 -1
- package/src/collections/providers.ts +6 -4
- package/src/collections/tests.ts +7 -4
- package/src/core/app-icon-frame.ts +62 -0
- package/src/core/app-icon.ts +179 -17
- package/src/core/archived.ts +10 -7
- package/src/core/check-ctx.ts +38 -4
- package/src/core/check-pass.ts +7 -0
- package/src/core/foreign.ts +87 -0
- package/src/core/gui-color.ts +75 -0
- package/src/core/hub-theme.ts +1 -3
- package/src/core/layout.ts +3 -0
- package/src/core/machine-commit.ts +9 -1
- package/src/core/one-lib.ts +2 -1
- package/src/core/one-way-in-policy.ts +17 -12
- package/src/core/owner-word-policy.ts +123 -0
- package/src/core/panel-shades.ts +140 -0
- package/src/core/repo-gui-color.ts +16 -0
- package/src/core/role-policy.ts +17 -0
- package/src/core/scope.ts +6 -3
- package/src/core/tmux-policy.ts +264 -0
- package/src/core/unit-icon.ts +43 -0
- package/src/fleet/push-fleet.ts +2 -0
- package/src/fleet/scan-fleet.ts +3 -0
- package/src/gate/cache-audit.ts +7 -1
- package/src/gate/gate-checks.ts +14 -9
- package/src/gate/run-fix.ts +30 -5
- package/src/gate/run-fixers.ts +8 -3
- package/src/home/activity-shape.ts +2 -0
- package/src/home/activity.ts +2 -1
- package/src/home/daemon-guard.ts +20 -2
- package/src/home/daemon-jobs.ts +26 -18
- package/src/home/gui-app/ShipkitGui.swift +2012 -144
- package/src/home/gui-app/icon.svg +8 -0
- package/src/home/gui-app.ts +94 -30
- package/src/home/home-routes.ts +53 -9
- package/src/home/home-start.ts +27 -3
- package/src/home/inbox-shape.ts +7 -3
- package/src/home/log-follow.ts +117 -0
- package/src/home/machine-fold.ts +1 -1
- package/src/home/open-app.ts +9 -3
- package/src/home/page-build.ts +5 -1
- package/src/home/page-held.ts +1 -1
- package/src/home/pm-config.ts +0 -8
- package/src/home/pm.ts +62 -5
- package/src/home/process-apps.ts +70 -23
- package/src/home/process-rows.ts +16 -1
- package/src/home/push-sources.ts +18 -13
- package/src/home/resources.ts +16 -7
- package/src/home/run-daemon.ts +4 -1
- package/src/home/run-pm.ts +1 -1
- package/src/home/serve-daemon.ts +13 -4
- package/src/home/serve-web.ts +141 -17
- package/src/home/space-page.ts +3 -3
- package/src/home/space-route.ts +2 -2
- package/src/home/supervise.ts +2 -1
- package/src/home/vault-page.ts +2 -1
- package/src/home/web-places.ts +239 -0
- package/src/home/widgets.ts +16 -2
- package/src/hooks/commit-message.ts +11 -9
- package/src/hooks/one-way-in-guard.ts +145 -68
- package/src/hooks/run-hooks.ts +15 -5
- package/src/hooks/shared-file.ts +273 -83
- package/src/hooks/shell-writes.ts +620 -0
- package/src/hooks/write-log.ts +149 -0
- package/src/hq/door-route.ts +63 -7
- package/src/hq/door.ts +45 -12
- package/src/hq/history-send.ts +3 -1
- package/src/hq/hq-db.ts +10 -3
- package/src/hq/hq-local.ts +24 -5
- package/src/hq/hq-routes.ts +3 -1
- package/src/hq/hq-store.ts +9 -3
- package/src/hq/kinds/index.ts +2 -1
- package/src/hq/kinds/kind.ts +9 -4
- package/src/hq/kinds/presence-rule.ts +56 -0
- package/src/hq/kinds/presence.ts +210 -0
- package/src/hq/kinds/report.ts +8 -5
- package/src/hq/lead-order.ts +68 -0
- package/src/hq/outbox.ts +7 -0
- package/src/hq/replica.ts +5 -7
- package/src/hq/report-facts.ts +14 -7
- package/src/hq/report.ts +47 -2
- package/src/hq/switch.ts +1 -0
- package/src/hq/terminal-hop.ts +64 -0
- package/src/hq/thread-sync.ts +13 -6
- package/src/http/door-forward.ts +10 -12
- package/src/http/door-names.ts +9 -0
- package/src/http/hop-caller.ts +23 -0
- package/src/http/hop-names.ts +14 -0
- package/src/http/loopback-serve.ts +28 -6
- package/src/http/owner-word.ts +128 -0
- package/src/http/same-origin.ts +12 -0
- package/src/{serve → http}/secret-gate.ts +3 -3
- package/src/ledger/run-log.ts +25 -1
- package/src/media-store/backup/sources.ts +53 -6
- package/src/media-store/backup/thread-copy.ts +9 -5
- package/src/media-store/copy/config.ts +10 -9
- package/src/media-store/daemon.ts +5 -2
- package/src/media-store/put.ts +3 -0
- package/src/media-store/space.ts +14 -16
- package/src/media-store/upload.ts +4 -0
- package/src/messages/collection.ts +2 -2
- package/src/messages/model.ts +6 -1
- package/src/messages/routes.ts +3 -0
- package/src/orchestrator/brief.md +8 -6
- package/src/orchestrator/channel-declare.ts +58 -0
- package/src/orchestrator/channel.ts +226 -0
- package/src/orchestrator/guards.ts +12 -3
- package/src/orchestrator/host.ts +35 -0
- package/src/orchestrator/lead-shape.ts +86 -0
- package/src/orchestrator/now.ts +88 -0
- package/src/orchestrator/phone.ts +4 -1
- package/src/orchestrator/places-file.ts +38 -0
- package/src/orchestrator/places-look.ts +180 -0
- package/src/orchestrator/places-shape.ts +151 -0
- package/src/orchestrator/places.ts +50 -0
- package/src/orchestrator/presence-shape.ts +13 -2
- package/src/orchestrator/presence.ts +26 -15
- package/src/orchestrator/push.ts +5 -10
- package/src/orchestrator/role-shape.ts +270 -0
- package/src/orchestrator/role.ts +242 -0
- package/src/orchestrator/routes.ts +136 -31
- package/src/orchestrator/sessions-shape.ts +78 -0
- package/src/orchestrator/sessions.ts +86 -0
- package/src/orchestrator/share.ts +71 -0
- package/src/orchestrator/start-notice.ts +61 -0
- package/src/orchestrator/start.ts +137 -0
- package/src/orchestrator/started.ts +55 -0
- package/src/orchestrator/stuck.ts +196 -0
- package/src/orchestrator/unheard.ts +18 -7
- package/src/pages/frame-client.ts +44 -6
- package/src/problems/failure-words.ts +80 -0
- package/src/release/run-bump.ts +26 -5
- package/src/release/run-release.ts +34 -14
- package/src/repo-config.ts +37 -9
- package/src/review/aside-at.ts +19 -0
- package/src/review/band.ts +3 -3
- package/src/review/doc-save.ts +1 -1
- package/src/review/inbox-hook.ts +12 -4
- package/src/review/inbox-read.ts +20 -7
- package/src/review/instruction-guards.ts +137 -0
- package/src/review/instructions.ts +14 -2
- package/src/review/item-db.ts +52 -2
- package/src/review/mentions.ts +6 -4
- package/src/review/model.ts +3 -2
- package/src/review/parties.ts +88 -19
- package/src/review/push.ts +32 -15
- package/src/review/routes.ts +12 -4
- package/src/review/secret-route.ts +5 -5
- package/src/review/snooze.ts +1 -16
- package/src/review/store-parties.ts +4 -2
- package/src/review/take-back.ts +2 -1
- package/src/review/threads.ts +13 -2
- package/src/review/unit.ts +3 -2
- package/src/review/view-layout.ts +8 -1
- package/src/review/watchers.ts +25 -4
- package/src/secrets/key-pair.ts +14 -0
- package/src/secrets/lapse.ts +3 -3
- package/src/secrets/manager.ts +5 -1
- package/src/secrets/name-template.ts +83 -0
- package/src/secrets/name.ts +3 -0
- package/src/secrets/read.ts +10 -6
- package/src/secrets/secrets-view.ts +299 -0
- package/src/secrets/who-reads.ts +2 -1
- package/src/serve/frame-part.ts +49 -0
- package/src/serve/hub-app/accounts-line.tsx +33 -45
- package/src/serve/hub-app/activity-st.ts +6 -5
- package/src/serve/hub-app/activity-view.tsx +10 -9
- package/src/serve/hub-app/advice-box.tsx +6 -5
- package/src/serve/hub-app/advisor-app.tsx +2 -0
- package/src/serve/hub-app/advisor-face.tsx +3 -2
- package/src/serve/hub-app/advisor.html +1 -0
- package/src/serve/hub-app/advisors-view.tsx +52 -10
- package/src/serve/hub-app/advisors.css +4 -0
- package/src/serve/hub-app/app-bridge.ts +31 -5
- package/src/serve/hub-app/asked-page.ts +24 -0
- package/src/serve/hub-app/asks-page.tsx +10 -6
- package/src/serve/hub-app/auto-text.tsx +7 -5
- package/src/serve/hub-app/card-head.tsx +3 -2
- package/src/serve/hub-app/check-view.tsx +10 -9
- package/src/serve/hub-app/checks-svc.ts +96 -32
- package/src/serve/hub-app/clock-svc.ts +24 -8
- package/src/serve/hub-app/code-copy.ts +1 -1
- package/src/serve/hub-app/col-card.tsx +2 -1
- package/src/serve/hub-app/col-list-page.tsx +12 -6
- package/src/serve/hub-app/col-list-st.ts +12 -2
- package/src/serve/hub-app/col-tables-view.tsx +8 -44
- package/src/serve/hub-app/col-tables.ts +0 -14
- package/src/serve/hub-app/cols-svc.ts +6 -12
- package/src/serve/hub-app/columns.ts +94 -0
- package/src/serve/hub-app/comfy-view.tsx +8 -7
- package/src/serve/hub-app/commands/commands-page.tsx +4 -3
- package/src/serve/hub-app/commands/commands-st.ts +2 -2
- package/src/serve/hub-app/controls.css +69 -23
- package/src/serve/hub-app/cycle-button.tsx +2 -1
- package/src/serve/hub-app/database-st.ts +1 -1
- package/src/serve/hub-app/database-view.tsx +4 -2
- package/src/serve/hub-app/deaf.tsx +27 -0
- package/src/serve/hub-app/dock-st.ts +21 -16
- package/src/serve/hub-app/dock-view.tsx +19 -12
- package/src/serve/hub-app/empty-section.tsx +30 -0
- package/src/serve/hub-app/entry-bar.css +1 -1
- package/src/serve/hub-app/entry-bar.tsx +11 -6
- package/src/serve/hub-app/entry-list.css +32 -0
- package/src/serve/hub-app/entry-list.tsx +123 -0
- package/src/serve/hub-app/entry-pick.ts +1 -1
- package/src/serve/hub-app/entry-sections.ts +140 -0
- package/src/serve/hub-app/event-stream-reader.ts +56 -0
- package/src/serve/hub-app/floating.tsx +68 -14
- package/src/serve/hub-app/geometry-view.tsx +3 -2
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/hash-route.ts +14 -2
- package/src/serve/hub-app/header-bar.tsx +53 -36
- package/src/serve/hub-app/home-st.ts +131 -14
- package/src/serve/hub-app/home-strip.css +24 -13
- package/src/serve/hub-app/home-strip.tsx +131 -66
- package/src/serve/hub-app/home.html +5 -0
- package/src/serve/hub-app/hub-app.tsx +94 -102
- package/src/serve/hub-app/hub.css +61 -94
- package/src/serve/hub-app/icons.tsx +16 -0
- package/src/serve/hub-app/identities-st.ts +19 -54
- package/src/serve/hub-app/identities-view.tsx +25 -24
- package/src/serve/hub-app/identity-address.ts +2 -2
- package/src/serve/hub-app/in-sight.ts +10 -0
- package/src/serve/hub-app/inbox-st.ts +20 -2
- package/src/serve/hub-app/inbox-view.tsx +16 -9
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/index.html +5 -0
- package/src/serve/hub-app/insights-view.tsx +6 -5
- package/src/serve/hub-app/instructions.css +4 -1
- package/src/serve/hub-app/kept-cols.tsx +83 -20
- package/src/serve/hub-app/kept-width.tsx +76 -0
- package/src/serve/hub-app/keys.ts +116 -38
- package/src/serve/hub-app/layout-st.ts +109 -99
- package/src/serve/hub-app/lightbox-zoom.css +36 -0
- package/src/serve/hub-app/list-filter.tsx +15 -6
- package/src/serve/hub-app/list-head.tsx +29 -0
- package/src/serve/hub-app/list-row.ts +8 -0
- package/src/serve/hub-app/list-walk.ts +26 -105
- package/src/serve/hub-app/live-socket.ts +274 -0
- package/src/serve/hub-app/live-sources.ts +189 -0
- package/src/serve/hub-app/live-svc.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +75 -14
- package/src/serve/hub-app/main-panel.css +211 -0
- package/src/serve/hub-app/main-panel.tsx +259 -0
- package/src/serve/hub-app/md.ts +4 -4
- package/src/serve/hub-app/media-svc.ts +5 -5
- package/src/serve/hub-app/media-view.tsx +13 -12
- package/src/serve/hub-app/messages/messages-page.tsx +8 -7
- package/src/serve/hub-app/messages/messages-st.ts +5 -2
- package/src/serve/hub-app/new-thread-st.ts +170 -0
- package/src/serve/hub-app/new-thread.tsx +133 -107
- package/src/serve/hub-app/orchestrator-line.tsx +115 -45
- package/src/serve/hub-app/orchestrator-places.tsx +86 -0
- package/src/serve/hub-app/orchestrator.css +57 -5
- package/src/serve/hub-app/page-keys.ts +107 -68
- package/src/serve/hub-app/page-reload.ts +46 -6
- package/src/serve/hub-app/pages-frames.tsx +40 -3
- package/src/serve/hub-app/pages-svc.ts +3 -1
- package/src/serve/hub-app/palette-st.ts +198 -43
- package/src/serve/hub-app/palette-view.tsx +32 -8
- package/src/serve/hub-app/panel-head-action.tsx +39 -0
- package/src/serve/hub-app/panel-head.tsx +70 -0
- package/src/serve/hub-app/panel-repo.ts +42 -0
- package/src/serve/hub-app/panel-source.ts +195 -0
- package/src/serve/hub-app/panel-tint.css +6 -0
- package/src/serve/hub-app/panel-tint.ts +23 -0
- package/src/serve/hub-app/panel-walk.ts +107 -0
- package/src/serve/hub-app/pill-row.tsx +2 -1
- package/src/serve/hub-app/place-path.ts +4 -0
- package/src/serve/hub-app/places-svc.ts +75 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/polled.ts +11 -1
- package/src/serve/hub-app/presence-st.ts +66 -32
- package/src/serve/hub-app/processes-view.tsx +2 -2
- package/src/serve/hub-app/project-bar.tsx +116 -0
- package/src/serve/hub-app/project-list.css +20 -173
- package/src/serve/hub-app/project-list.tsx +30 -298
- package/src/serve/hub-app/projects-svc.ts +59 -32
- package/src/serve/hub-app/push-sign.tsx +2 -1
- package/src/serve/hub-app/push-svc.ts +86 -69
- package/src/serve/hub-app/quiet-st.ts +5 -3
- package/src/serve/hub-app/rail-groups.ts +144 -0
- package/src/serve/hub-app/reader-chips.tsx +2 -1
- package/src/serve/hub-app/recordings-st.ts +2 -1
- package/src/serve/hub-app/recordings-view.tsx +19 -47
- package/src/serve/hub-app/recordings.css +0 -2
- package/src/serve/hub-app/reflections-page.tsx +10 -6
- package/src/serve/hub-app/releases/releases-page.tsx +6 -5
- package/src/serve/hub-app/repo-sections.ts +127 -38
- package/src/serve/hub-app/repo-st.ts +57 -36
- package/src/serve/hub-app/review/advisor-bar.tsx +3 -2
- package/src/serve/hub-app/review/ask-proof.tsx +79 -0
- package/src/serve/hub-app/review/attach-view.tsx +11 -10
- package/src/serve/hub-app/review/box-view.ts +479 -0
- package/src/serve/hub-app/review/box-zoom.tsx +70 -0
- package/src/serve/hub-app/review/diff-view.tsx +3 -2
- package/src/serve/hub-app/review/doc-body.tsx +2 -1
- package/src/serve/hub-app/review/dock.tsx +3 -2
- package/src/serve/hub-app/review/draft-body.tsx +4 -3
- package/src/serve/hub-app/review/faces.tsx +0 -8
- package/src/serve/hub-app/review/group-block.tsx +8 -7
- package/src/serve/hub-app/review/heard-line.tsx +4 -3
- package/src/serve/hub-app/review/instructions-view.tsx +3 -2
- package/src/serve/hub-app/review/item-verdict.tsx +40 -40
- package/src/serve/hub-app/review/kind-states.tsx +5 -4
- package/src/serve/hub-app/review/kit.tsx +24 -4
- package/src/serve/hub-app/review/lane-bar.tsx +30 -28
- package/src/serve/hub-app/review/lightbox.tsx +6 -4
- package/src/serve/hub-app/review/live-bar.tsx +7 -6
- package/src/serve/hub-app/review/live-view.tsx +6 -5
- package/src/serve/hub-app/review/object-card.tsx +2 -1
- package/src/serve/hub-app/review/object-panel.tsx +11 -10
- package/src/serve/hub-app/review/pano-view.tsx +3 -2
- package/src/serve/hub-app/review/question-views.tsx +6 -5
- package/src/serve/hub-app/review/review-cells.tsx +21 -20
- package/src/serve/hub-app/review/review-host.ts +3 -0
- package/src/serve/hub-app/review/review-kit.ts +7 -5
- package/src/serve/hub-app/review/review-list.tsx +98 -52
- package/src/serve/hub-app/review/review-page.tsx +3 -3
- package/src/serve/hub-app/review/review-st.ts +70 -14
- package/src/serve/hub-app/review/review-thread.tsx +234 -138
- package/src/serve/hub-app/review/review-views.tsx +166 -191
- package/src/serve/hub-app/review/space3d.tsx +17 -9
- package/src/serve/hub-app/review/thread-close.tsx +24 -32
- package/src/serve/hub-app/review/thread-st.ts +39 -25
- package/src/serve/hub-app/review/trailer-body.tsx +5 -4
- package/src/serve/hub-app/review/trailer-page.tsx +18 -16
- package/src/serve/hub-app/review/trailer-st.ts +3 -2
- package/src/serve/hub-app/review/trailer-timeline.tsx +10 -9
- package/src/serve/hub-app/review/trailer-voices.tsx +29 -28
- package/src/serve/hub-app/review.css +159 -42
- package/src/serve/hub-app/row-acts.tsx +126 -0
- package/src/serve/hub-app/row-face.tsx +29 -0
- package/src/serve/hub-app/running-rows.tsx +142 -0
- package/src/serve/hub-app/running-st.ts +110 -0
- package/src/serve/hub-app/search-view.tsx +3 -2
- package/src/serve/hub-app/secrets-page.tsx +290 -0
- package/src/serve/hub-app/secrets-st.ts +181 -0
- package/src/serve/hub-app/secrets.css +65 -0
- package/src/serve/hub-app/section-head.tsx +3 -2
- package/src/serve/hub-app/session-chips.tsx +55 -0
- package/src/serve/hub-app/shell.ts +56 -0
- package/src/serve/hub-app/site/site-part.tsx +6 -5
- package/src/serve/hub-app/site/site-st.ts +0 -6
- package/src/serve/hub-app/site.css +0 -1
- package/src/serve/hub-app/social/calendar.tsx +7 -6
- package/src/serve/hub-app/social/comms-page.tsx +29 -26
- package/src/serve/hub-app/social/group-editor.tsx +2 -1
- package/src/serve/hub-app/social/kit.tsx +12 -11
- package/src/serve/hub-app/social/next-release.tsx +3 -2
- package/src/serve/hub-app/social/post-card.tsx +21 -20
- package/src/serve/hub-app/social/post-page.tsx +2 -1
- package/src/serve/hub-app/social/problems.tsx +3 -2
- package/src/serve/hub-app/social/social-page.tsx +29 -27
- package/src/serve/hub-app/social/social-st.ts +4 -2
- package/src/serve/hub-app/social/stage-popup.tsx +11 -10
- package/src/serve/hub-app/social.css +7 -5
- package/src/serve/hub-app/source-acts.ts +79 -0
- package/src/serve/hub-app/source-page.tsx +17 -0
- package/src/serve/hub-app/space-view.tsx +5 -4
- package/src/serve/hub-app/stores/stores-page.tsx +21 -19
- package/src/serve/hub-app/stores/stores-st.ts +1 -1
- package/src/serve/hub-app/stores.css +1 -1
- package/src/serve/hub-app/terminal-history-st.ts +112 -0
- package/src/serve/hub-app/terminal-keys.ts +79 -0
- package/src/serve/hub-app/terminal-lib.ts +110 -0
- package/src/serve/hub-app/terminal-links.ts +55 -0
- package/src/serve/hub-app/terminal-list-st.ts +304 -0
- package/src/serve/hub-app/terminal-log-st.ts +242 -0
- package/src/serve/hub-app/terminal-out.ts +135 -0
- package/src/serve/hub-app/terminal-pages.tsx +115 -0
- package/src/serve/hub-app/terminal-panel.tsx +60 -9
- package/src/serve/hub-app/terminal-sources.tsx +335 -0
- package/src/serve/hub-app/terminal-st.ts +447 -167
- package/src/serve/hub-app/terminal-stream.ts +233 -0
- package/src/serve/hub-app/terminal-tab.tsx +64 -0
- package/src/serve/hub-app/terminal-widths.ts +30 -0
- package/src/serve/hub-app/terminal.css +50 -4
- package/src/serve/hub-app/test-view.tsx +5 -3
- package/src/serve/hub-app/tests-view.tsx +16 -15
- package/src/serve/hub-app/theme-st.ts +5 -0
- package/src/serve/hub-app/thread-row.tsx +39 -31
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-view.tsx +2 -1
- package/src/serve/hub-app/time.css +1 -1
- package/src/serve/hub-app/timeline-chart.tsx +5 -4
- package/src/serve/hub-app/timeline-view.tsx +10 -9
- package/src/serve/hub-app/tips.ts +247 -0
- package/src/serve/hub-app/tree-build.ts +40 -8
- package/src/serve/hub-app/tree-svc.ts +167 -134
- package/src/serve/hub-app/unit-icons.ts +26 -0
- package/src/serve/hub-app/url-address.ts +154 -0
- package/src/serve/hub-app/url-faces.ts +88 -0
- package/src/serve/hub-app/url-forms.tsx +183 -0
- package/src/serve/hub-app/urls-svc.ts +167 -5
- package/src/serve/hub-app/urls-view.tsx +56 -20
- package/src/serve/hub-app/urls.css +26 -0
- package/src/serve/hub-app/vault-view.tsx +5 -4
- package/src/serve/hub-app/veille/veille-page.tsx +34 -33
- package/src/serve/hub-app/veille/veille-st.ts +6 -3
- package/src/serve/hub-app/view-layout.css +3 -3
- package/src/serve/hub-app/when-view.tsx +5 -4
- package/src/serve/hub-app/wikis-view.tsx +6 -5
- package/src/serve/hub-app/words.tsx +9 -2
- package/src/serve/hub-runtime.ts +3 -2
- package/src/serve/orchestrator-host.ts +58 -0
- package/src/serve/page-live.ts +147 -0
- package/src/serve/project-gutter-route.ts +63 -2
- package/src/serve/read-worker.ts +7 -2
- package/src/serve/runs-stamp.ts +33 -0
- package/src/serve/secrets-read.ts +156 -0
- package/src/serve/serve-hub.ts +71 -22
- package/src/serve/terminal-claudes.ts +185 -0
- package/src/serve/terminal-guard.ts +10 -5
- package/src/serve/terminal-host.ts +517 -0
- package/src/serve/terminal-record.ts +104 -0
- package/src/serve/terminal-route.ts +466 -103
- package/src/serve/terminal-shells.ts +3 -0
- package/src/serve/terminal-watch.ts +102 -0
- package/src/shipkit-files.ts +9 -4
- package/src/shot/client.ts +4 -9
- package/src/shot/shooter.ts +2 -4
- package/src/shot/shot-ask.ts +2 -7
- package/src/shot/shot-theme.ts +6 -17
- package/src/social/routes.ts +2 -2
- package/src/social/writes.ts +3 -0
- package/src/suite/test-units.ts +6 -2
- package/src/trailer/sound/eleven.ts +1 -0
- package/src/urls/added.ts +111 -0
- package/src/urls/icons.ts +294 -0
- package/src/urls/places.ts +139 -0
- package/src/urls/routes.ts +17 -7
- package/src/urls/rows.ts +48 -15
- package/src/urls/unit.ts +57 -3
- package/src/urls/write-routes.ts +207 -0
- package/src/vault/vault-destroy.ts +2 -1
- package/src/vault/vault-import.ts +4 -11
- package/src/vault/vault-restore.ts +3 -2
- package/src/veille/chrome.ts +18 -3
- package/src/veille/identity.ts +6 -0
- package/src/view3d/cam.ts +30 -46
- package/src/view3d/lib.ts +20 -2
- package/src/view3d/viewer.ts +62 -88
- package/src/wiki/agent-paths.ts +2 -1
- package/src/orchestrator/deliver.ts +0 -81
- package/src/orchestrator/drill.ts +0 -129
- package/src/orchestrator/keeper.ts +0 -332
- package/src/orchestrator/pm.ts +0 -20
- package/src/orchestrator/state.ts +0 -92
- package/src/orchestrator/switch.ts +0 -86
- package/src/orchestrator/tmux.ts +0 -82
- package/src/serve/hub-app/rail-fly.tsx +0 -95
- package/src/serve/hub-app/side-lists.ts +0 -72
- package/src/serve/hub-app/sidebar.tsx +0 -62
- package/src/serve/hub-app/tree-row.tsx +0 -125
|
@@ -1,18 +1,43 @@
|
|
|
1
|
-
// the hub's terminal (wiki tools/shipkit/hub.md, The terminal panel): a pty on this Mac
|
|
2
|
-
// shipkit keeps for the repo (`sk-<repo>`, in its folder), so
|
|
1
|
+
// the hub's terminal (wiki tools/shipkit/hub.md, The terminal panel): a pty on this Mac that looks at the tmux session
|
|
2
|
+
// shipkit keeps for the repo (`sk-<repo>`, in its folder), so a shell outlives a reload, a closed panel and a hub
|
|
3
3
|
// restart, and `tmux attach -t sk-<repo>` reaches it from any terminal. No tmux: a login shell that ends with the panel.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// A page reads all of it on its ONE socket (serve/page-live.ts, a WebSocket: a browser gives a host six HTTP
|
|
5
|
+
// connections for all its tabs, and a WebSocket is none of them): each thing it reads is a PART, started by a short POST
|
|
6
|
+
// that names the socket's id and a key of the page's own, and each line of a part comes under that key. POST open
|
|
7
|
+
// starts a terminal's part (a pty's output), POST watch a list's (the repo's terminals and the Claude Code sessions
|
|
8
|
+
// of its folder, no pty), POST machine every project's lists, POST log a process's log, POST close ends one; a
|
|
9
|
+
// check's run is one too (serve-hub.ts, POST /api/check/run with the socket's id); what he types goes on the socket,
|
|
10
|
+
// to a part of that socket alone (pageTake); POST window acts on a terminal. A page never attaches the repo's session
|
|
11
|
+
// itself: it attaches a VIEW of it, a session of its own in the same group (the same windows, its own current one,
|
|
12
|
+
// no status line), so two pages show two terminals; a view ends with its client.
|
|
13
|
+
// One reader a session feeds every part (terminal-watch.ts). Every request passes terminalRefusal first.
|
|
6
14
|
// The one constraint a reader breaks first: a pty that is not closed keeps this process's loop alive, so every end
|
|
7
|
-
// path goes through `end
|
|
15
|
+
// path goes through the part's `end`, and a socket that ends ends each of its parts
|
|
8
16
|
import { randomBytes } from 'crypto'
|
|
9
|
-
import { existsSync } from 'fs'
|
|
17
|
+
import { existsSync, realpathSync } from 'fs'
|
|
18
|
+
import { homedir } from 'os'
|
|
19
|
+
import { dirname, isAbsolute, join } from 'path'
|
|
20
|
+
import { readAccountsUsage } from '../agent-time/accounts-usage-disk.ts'
|
|
21
|
+
import { homeDir } from '../home/home-paths.ts'
|
|
22
|
+
import { recordOf, type TerminalRecord } from './terminal-record.ts'
|
|
10
23
|
import { NO_STORE } from '../review/http.ts'
|
|
11
|
-
import {
|
|
24
|
+
import { claudeWatch, type ClaudeSources, diskClaudes } from './terminal-claudes.ts'
|
|
12
25
|
import { terminalRefusal } from './terminal-guard.ts'
|
|
26
|
+
import { type HopDeps, isTerminalHop, terminalHopRefusal } from '../hq/terminal-hop.ts'
|
|
27
|
+
import { type ListLine, type SessionWatch, sessionWatch } from './terminal-watch.ts'
|
|
28
|
+
import { type Acted, type ClaudeStart, HISTORY_LINES, ownEnv, type TerminalHost, type Tmux, tmuxBin, tmuxHost, windowAct } from './terminal-host.ts'
|
|
13
29
|
|
|
14
|
-
/** one line of the
|
|
15
|
-
|
|
30
|
+
/** one line of a part: `hello` first, with the part's id; of a terminal's (`o` its output, `v` the window its view
|
|
31
|
+
* shows now, `exit`), of a list's (`w`, `c`), of a log's (`o`), of a check's run (`r`, one event of the run, no
|
|
32
|
+
* `hello`); `gone` last when the hub itself ended the part (its routes stopped, a page opened too many): the page
|
|
33
|
+
* asks for it again */
|
|
34
|
+
export type TermLine = { t: 'hello'; id: string; tmux: string | null } | { t: 'o'; d: string } | { t: 'v'; window: string } | ListLine | { t: 'exit'; code: number; /** tmux still holds the session: only its client went, the page attaches again */ kept?: boolean } | { t: 'r'; e: Record<string, unknown> } | { t: 'gone' }
|
|
35
|
+
|
|
36
|
+
/** one frame of a page's terminals on its socket: the first (`hello`, the id every part names), else a line of one of
|
|
37
|
+
* its parts under the key the page gave that part, with its repo where the part is every project's lists */
|
|
38
|
+
export type PageFrame = { t: 'hello'; id: string } | { k: string; repo?: string; l: TermLine }
|
|
39
|
+
/** what a page says on its socket to one of its parts, by the part's id: keys, a size, hidden or shown */
|
|
40
|
+
export type PageSend = { id?: unknown; data?: unknown; hidden?: unknown; cols?: unknown; rows?: unknown }
|
|
16
41
|
|
|
17
42
|
/** a pty and the program in it, as the route drives it */
|
|
18
43
|
export type Pty = { write(d: string): void; resize(cols: number, rows: number): void; kill(): void; exited: Promise<number> }
|
|
@@ -32,145 +57,483 @@ export const bunPty: SpawnPty = (o) => {
|
|
|
32
57
|
}
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
const size = (v: unknown, min: number, max: number, def: number): number => (typeof v === 'number' && Number.isInteger(v) && v >= min && v <= max ? v : def)
|
|
61
|
+
/** parts one hub keeps, terminals and lists: a page that reconnects in a loop never piles up shells */
|
|
62
|
+
const MAX_SESSIONS = 24
|
|
63
|
+
/** sockets of pages one process keeps: a page that opens one in a loop never piles them up */
|
|
64
|
+
const MAX_PAGES = 64
|
|
65
|
+
/** a bound on one write: a paste of a whole file is still far under it */
|
|
66
|
+
const INPUT_MAX = 256_000
|
|
67
|
+
/** the list of terminals is read again this long after the shell printed (a program started or ended), at most once
|
|
68
|
+
* in LIST_GAP_MS while it prints on, and every LIST_EVERY_MS for what changed with no output (a window behind) */
|
|
69
|
+
const LIST_SETTLE_MS = 400
|
|
70
|
+
const LIST_GAP_MS = 2_000
|
|
71
|
+
const LIST_EVERY_MS = 10_000
|
|
40
72
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
73
|
+
/** one part of a page's socket: a terminal's (its pty; `view`, its view of the repo's terminals) or a list's (no pty).
|
|
74
|
+
* `host`: what keeps the repo's terminals (terminal-host.ts), null for a plain login shell; `lists`: the terminals
|
|
75
|
+
* are the repo's, so they can be acted on. `end`: these routes end it, and say so */
|
|
76
|
+
type Session = { pty: Pty | null; end: () => void; host: TerminalHost | null; view: string | null; lists: boolean; /** the repo of the hop whose page asked it, null for a page of this machine */ scope: string | null }
|
|
43
77
|
|
|
44
|
-
|
|
45
|
-
|
|
78
|
+
const ANSWER = { headers: NO_STORE }
|
|
79
|
+
const taken = (): Response => new Response(null, { status: 204, ...ANSWER })
|
|
80
|
+
/** a part was asked on a socket this process does not hold (it ended, the hub restarted): the page opens one again */
|
|
81
|
+
export const noPage = (): Response => new Response('no such socket of a page: it ended, open one again', { status: 410, ...ANSWER })
|
|
46
82
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
83
|
+
/** a page's socket as its parts see it: `parts`, what ends each, by its key; `takes`, what each terminal's part does
|
|
84
|
+
* with what the page says to it, by the part's id */
|
|
85
|
+
type Page = { put: (f: PageFrame) => void; parts: Map<string, () => void>; takes: Map<string, (b: PageSend) => void>; end: () => void; evicted: () => void; /** a hop's one repo, null for a page of this machine: a part is asked under its scope alone */ scope: string | null }
|
|
86
|
+
/** every page's socket of this process, by its id: 128 random bits only the page that opened it read. One table for
|
|
87
|
+
* every repo's routes and the machine's, so a page of the home holds one socket for all its projects */
|
|
88
|
+
const PAGES = new Map<string, Page>()
|
|
89
|
+
/** how many pages hold a socket now (a check counts them) */
|
|
90
|
+
export const pageStreams = (): number => PAGES.size
|
|
91
|
+
|
|
92
|
+
/** how many sockets of pages one process holds: the one opened past it ends the oldest */
|
|
93
|
+
export const PAGES_MAX = MAX_PAGES
|
|
94
|
+
|
|
95
|
+
/** a page's socket opened (serve/page-live.ts): `hello` with its id goes to `put`, then each line of each part
|
|
96
|
+
* started on it. `end`: it closed, and each of its parts ends with it. `evicted`: this process ended it to make room
|
|
97
|
+
* (too many pages): its socket must close too, or its page would hold terminals that read nothing and say live */
|
|
98
|
+
export function pageOpen(put: (f: PageFrame) => void, evicted: () => void = () => {}, scope: string | null = null): { id: string; end(): void } {
|
|
99
|
+
const id = randomBytes(16).toString('hex')
|
|
100
|
+
let done = false
|
|
101
|
+
const parts = new Map<string, () => void>()
|
|
102
|
+
const end = (): void => {
|
|
103
|
+
if (done) return
|
|
104
|
+
done = true
|
|
105
|
+
PAGES.delete(id)
|
|
106
|
+
for (const stop of [...parts.values()]) stop()
|
|
107
|
+
}
|
|
108
|
+
PAGES.set(id, { put: (f) => { if (!done) put(f) }, parts, takes: new Map(), end, evicted, scope })
|
|
109
|
+
// the oldest goes when pages opened too many, its socket with it
|
|
110
|
+
const oldest = PAGES.size > MAX_PAGES ? PAGES.values().next().value : undefined
|
|
111
|
+
if (oldest != null) {
|
|
112
|
+
oldest.end()
|
|
113
|
+
oldest.evicted()
|
|
114
|
+
}
|
|
115
|
+
put({ t: 'hello', id })
|
|
116
|
+
return { id, end }
|
|
52
117
|
}
|
|
53
118
|
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export function shellEnv(env: Record<string, string | undefined> = process.env): Record<string, string> {
|
|
59
|
-
const out: Record<string, string> = {}
|
|
60
|
-
for (const [k, v] of Object.entries(env)) if (v != null && !SCRUB.test(k) && !AGENT_ENV.includes(k)) out[k] = v
|
|
61
|
-
return { ...out, TERM: 'xterm-256color', COLORTERM: 'truecolor' }
|
|
119
|
+
/** what a page said on its socket: typed into one of ITS terminals, by the part's id. A part of another page, or one
|
|
120
|
+
* that ended, takes nothing */
|
|
121
|
+
export function pageTake(page: string, b: PageSend): void {
|
|
122
|
+
if (typeof b.id === 'string') PAGES.get(page)?.takes.get(b.id)?.(b)
|
|
62
123
|
}
|
|
63
124
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
125
|
+
/** what a POST that starts or ends a part names: the socket's id, and the page's own key for the part */
|
|
126
|
+
export type PartAsk = { page?: unknown; key?: unknown }
|
|
127
|
+
export type PagePart = { put(l: TermLine, repo?: string): void; end(): void; ended(): boolean; onEnd(f: () => void): void; /** what the page says to the part of this id reaches `f`, until the part ends */ takes(id: string, f: (b: PageSend) => void): void }
|
|
128
|
+
|
|
129
|
+
/** a new part of a page's socket, under the key the page gave it: its lines go out under that key. A part the socket
|
|
130
|
+
* already has under that key ends first, so a page holds one part a key. null: this process holds no such socket,
|
|
131
|
+
* or none of that `scope` (a hop's socket is of one repo, and asks under it alone; a page of this machine under none) */
|
|
132
|
+
export function pagePart(b: PartAsk, scope: string | null = null): PagePart | null {
|
|
133
|
+
const page = typeof b.page === 'string' ? PAGES.get(b.page) : undefined
|
|
134
|
+
const key = b.key
|
|
135
|
+
if (page == null || page.scope !== scope || typeof key !== 'string' || key === '' || key.length > 64) return null
|
|
136
|
+
page.parts.get(key)?.()
|
|
137
|
+
let done = false
|
|
138
|
+
const ends: (() => void)[] = []
|
|
139
|
+
const end = (): void => {
|
|
140
|
+
if (done) return
|
|
141
|
+
done = true
|
|
142
|
+
if (page.parts.get(key) === end) page.parts.delete(key)
|
|
143
|
+
for (const f of ends.splice(0)) f()
|
|
144
|
+
}
|
|
145
|
+
page.parts.set(key, end)
|
|
146
|
+
return {
|
|
147
|
+
put: (l, repo) => { if (!done) page.put(repo == null ? { k: key, l } : { k: key, repo, l }) },
|
|
148
|
+
end,
|
|
149
|
+
ended: () => done,
|
|
150
|
+
onEnd: (f) => void ends.push(f),
|
|
151
|
+
takes: (id, f) => {
|
|
152
|
+
if (done) return
|
|
153
|
+
page.takes.set(id, f)
|
|
154
|
+
ends.push(() => void page.takes.delete(id))
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
|
71
158
|
|
|
72
|
-
/**
|
|
73
|
-
|
|
159
|
+
/** the page ends a part by its key (POST /api/terminal/close): a part already gone is no error */
|
|
160
|
+
export function closePart(b: PartAsk, scope: string | null = null): Response {
|
|
161
|
+
const page = typeof b.page === 'string' ? PAGES.get(b.page) : undefined
|
|
162
|
+
if (page?.scope === scope && typeof b.key === 'string') page.parts.get(b.key)?.()
|
|
163
|
+
return taken()
|
|
164
|
+
}
|
|
74
165
|
|
|
75
166
|
/** the xterm files the panel loads on its first open, by their published name */
|
|
76
167
|
const LIB: Record<string, { mod: string; type: string }> = {
|
|
77
168
|
'xterm.mjs': { mod: '@xterm/xterm/lib/xterm.mjs', type: 'text/javascript; charset=utf-8' },
|
|
78
169
|
'xterm.css': { mod: '@xterm/xterm/css/xterm.css', type: 'text/css; charset=utf-8' },
|
|
79
170
|
'addon-fit.mjs': { mod: '@xterm/addon-fit/lib/addon-fit.mjs', type: 'text/javascript; charset=utf-8' },
|
|
171
|
+
'addon-unicode-graphemes.mjs': { mod: '@xterm/addon-unicode-graphemes/lib/addon-unicode-graphemes.mjs', type: 'text/javascript; charset=utf-8' },
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export type TerminalDeps = {
|
|
175
|
+
root: string
|
|
176
|
+
name: string
|
|
177
|
+
spawn?: SpawnPty
|
|
178
|
+
tmux?: () => string | null
|
|
179
|
+
run?: (argv: string[]) => void
|
|
180
|
+
/** a tmux command run to its end, in place of the real one (a test) */
|
|
181
|
+
ask?: (argv: string[]) => { ok: boolean; out: string }
|
|
182
|
+
/** in place of LIST_SETTLE_MS (a test) */
|
|
183
|
+
listSettleMs?: number
|
|
184
|
+
/** what « + claude » runs for an account, or why it cannot; absent: his launcher of that name, else `claude` */
|
|
185
|
+
claude?: (account: string | undefined) => ClaudeStart | string
|
|
186
|
+
/** where the Claude Code sessions at work in the repo are read from (terminal-claudes.ts), given the host's own
|
|
187
|
+
* reader of panes; null: none are listed */
|
|
188
|
+
claudes?: ClaudeSources | ((tmux: Tmux) => ClaudeSources) | null
|
|
189
|
+
/** the socket of shipkit's own tmux server and where its config is written, and what writes it (a test); absent:
|
|
190
|
+
* the machine's home (`terminals.sock`, `terminals.conf`), the disk. A hub under test names both */
|
|
191
|
+
socket?: string
|
|
192
|
+
conf?: string
|
|
193
|
+
/** the record of the terminals (terminal-record.ts); absent: the machine's one file, `terminals.json` in its home,
|
|
194
|
+
* or beside the socket a hub under test names */
|
|
195
|
+
record?: TerminalRecord
|
|
196
|
+
writeConf?: (file: string, text: string) => void
|
|
197
|
+
/** how a hop of the hq Mac's page is judged, in place of this machine's own (a test) */
|
|
198
|
+
hop?: HopDeps
|
|
80
199
|
}
|
|
81
200
|
|
|
82
|
-
|
|
201
|
+
/** Claude Code in a login shell, so its PATH is his own and not the daemon's; `args`: its own arguments, as given */
|
|
202
|
+
export const plainClaude = (shell = process.env.SHELL || '/bin/zsh', args: readonly string[] = []): ClaudeStart => ({ argv: args.length === 0 ? [shell, '-l', '-c', 'exec claude'] : [shell, '-l', '-c', 'exec claude "$@"', 'sh', ...args] })
|
|
83
203
|
|
|
84
|
-
/**
|
|
204
|
+
/** an account's launcher where his login shell has one of its name (`cc3`: it sets the account's config folder and
|
|
205
|
+
* runs his own checks), else `claude` with the config folder its status line reported, else the reason. The name
|
|
206
|
+
* and the folder are arguments, never words of the script; what follows them goes to Claude Code as it is */
|
|
207
|
+
export const AS_ACCOUNT = 'n="$1"; d="$2"; shift 2; command -v "$n" >/dev/null 2>&1 && exec "$n" "$@"; [ -n "$d" ] && CLAUDE_CONFIG_DIR="$d" exec claude "$@"; echo "no command $n on your PATH, and the config folder of $n is not known yet: run $n once in a terminal"; exit 1'
|
|
208
|
+
|
|
209
|
+
/** Claude Code as one of the machine's accounts (cc1, cc2: the names the hub's main panel shows), or the shell's own
|
|
210
|
+
* account with none asked. A folder a status line named by its name alone is under his home */
|
|
211
|
+
export function claudeAs(account: string | undefined, accounts: () => { name: string; dir: string | null }[] = readAccountsUsage, o: { shell?: string; home?: string; /** Claude Code's own arguments */ args?: readonly string[] } = {}): ClaudeStart | string {
|
|
212
|
+
const shell = o.shell ?? (process.env.SHELL || '/bin/zsh')
|
|
213
|
+
if (account == null || account === '') return plainClaude(shell, o.args)
|
|
214
|
+
const a = accounts().find((x) => x.name === account)
|
|
215
|
+
if (a == null) return `no Claude account ${account} is known on this Mac`
|
|
216
|
+
const dir = a.dir == null || a.dir === '' ? '' : isAbsolute(a.dir) ? a.dir : join(o.home ?? homedir(), a.dir)
|
|
217
|
+
return { argv: [shell, '-l', '-c', AS_ACCOUNT, 'sh', a.name, dir, ...(o.args ?? [])] }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** one hub's terminal routes: the parts it started live as long as the hub, or the socket each is on */
|
|
85
221
|
export function terminalRoutes(d: TerminalDeps) {
|
|
86
222
|
const sessions = new Map<string, Session>()
|
|
223
|
+
const watches = new Map<string, SessionWatch>()
|
|
87
224
|
const spawn = d.spawn ?? bunPty
|
|
88
|
-
// the shell's own env,
|
|
89
|
-
const run = d.run ?? ((argv: string[]) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
225
|
+
// the shell's own env, as his terminal would give it
|
|
226
|
+
const run = d.run ?? ((argv: string[]) => {
|
|
227
|
+
try { Bun.spawnSync(argv, { env: ownEnv(), stdout: 'ignore', stderr: 'ignore' }) } catch { /* no such binary: nothing ran */ }
|
|
228
|
+
})
|
|
229
|
+
const ask = d.ask ?? ((argv: string[]) => {
|
|
230
|
+
try {
|
|
231
|
+
const r = Bun.spawnSync(argv, { env: ownEnv(), stdout: 'pipe', stderr: 'ignore' })
|
|
232
|
+
return { ok: r.exitCode === 0, out: r.stdout.toString() }
|
|
233
|
+
} catch {
|
|
234
|
+
// no such binary: the same as a tmux that refuses
|
|
235
|
+
return { ok: false, out: '' }
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
// the repo's folder as a session names it: by its path, and by its real one where a link leads to it
|
|
239
|
+
const folders = ((): string[] => {
|
|
240
|
+
try { return [...new Set([d.root, realpathSync(d.root)])] } catch { return [d.root] }
|
|
241
|
+
})()
|
|
242
|
+
let own: TerminalHost | null = null
|
|
243
|
+
/** what keeps this repo's terminals, null on a Mac with no tmux: shipkit's own server, and no other */
|
|
244
|
+
const hostNow = (): TerminalHost | null => {
|
|
245
|
+
const bin = (d.tmux ?? tmuxBin)()
|
|
246
|
+
if (bin == null) return null
|
|
247
|
+
return (own ??= tmuxHost({ bin, repo: d.name, root: d.root, ask, run, own: { socket: d.socket ?? join(homeDir(), 'terminals.sock'), conf: d.conf ?? join(homeDir(), 'terminals.conf'), ...(d.writeConf == null ? {} : { write: d.writeConf }), record: d.record ?? recordOf(join(d.socket == null ? homeDir() : dirname(d.socket), 'terminals.json')) } }))
|
|
248
|
+
}
|
|
249
|
+
/** the one reader of the repo's terminals, made at its first listener and forgotten at its last */
|
|
250
|
+
const watchOf = (host: TerminalHost): SessionWatch => {
|
|
251
|
+
let w = watches.get(host.reach)
|
|
252
|
+
if (w == null) {
|
|
253
|
+
const claudes = d.claudes === null ? null : claudeWatch(typeof d.claudes === 'function' ? d.claudes(host.tmux) : (d.claudes ?? diskClaudes({ accounts: readAccountsUsage, tmux: host.tmux })))
|
|
254
|
+
w = sessionWatch({ read: () => host.read(), claudes: claudes == null ? null : (windows) => claudes.read(folders, host.group, windows), settleMs: d.listSettleMs ?? LIST_SETTLE_MS, gapMs: LIST_GAP_MS, everyMs: LIST_EVERY_MS, idle: () => void watches.delete(host.reach) })
|
|
255
|
+
watches.set(host.reach, w)
|
|
256
|
+
}
|
|
257
|
+
return w
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** one part of a page's socket and its place among the hub's: `begin` starts what feeds it and returns its side of
|
|
261
|
+
* the session, or null when nothing started (its lines said why). Its first line is `hello`, with the id that
|
|
262
|
+
* send, window and history take */
|
|
263
|
+
function part(b: PartAsk, scope: string | null, begin: (o: { id: string; put: (l: TermLine) => void; end: () => void; ended: () => boolean; onEnd: (f: () => void) => void }) => Omit<Session, 'end' | 'scope'> | null): Response {
|
|
264
|
+
const p = pagePart(b, scope)
|
|
265
|
+
if (p == null) return noPage()
|
|
96
266
|
const id = randomBytes(16).toString('hex')
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
267
|
+
p.onEnd(() => void sessions.delete(id))
|
|
268
|
+
const mine = begin({ id, put: p.put, end: p.end, ended: p.ended, onEnd: p.onEnd })
|
|
269
|
+
if (mine == null || p.ended()) return (p.end(), taken())
|
|
270
|
+
// ended from here (these routes stop, a page opened too many) it says so, and the page asks for it again
|
|
271
|
+
sessions.set(id, { ...mine, scope, end: () => (p.put({ t: 'gone' }), p.end()) })
|
|
272
|
+
// what he types on the page's socket for this part: its keys, its size, hidden or shown
|
|
273
|
+
if (mine.pty != null) p.takes(id, (b) => typed(mine, b))
|
|
274
|
+
// the oldest goes when a page opened too many
|
|
275
|
+
if (sessions.size > MAX_SESSIONS) sessions.values().next().value?.end()
|
|
276
|
+
return taken()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** what a page said to one of its terminals: a write over the bound on one is dropped whole, never cut */
|
|
280
|
+
function typed(s: Omit<Session, 'end' | 'scope'>, b: PageSend): void {
|
|
281
|
+
if (s.pty == null) return
|
|
282
|
+
if (typeof b.data === 'string' && b.data.length <= INPUT_MAX) s.pty.write(b.data)
|
|
283
|
+
if (typeof b.hidden === 'boolean' && s.view != null) s.host?.hidden(s.view, b.hidden)
|
|
284
|
+
if (b.cols != null || b.rows != null) s.pty.resize(size(b.cols, 2, 500, 80), size(b.rows, 2, 200, 24))
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** a terminal of the repo, looked at through a view of the page's own; with no tmux a login shell */
|
|
288
|
+
function open(b: PartAsk, scope: string | null, cols: number, rows: number, window: string | null): Response {
|
|
289
|
+
return part(b, scope, ({ id, put, end, ended, onEnd }) => {
|
|
290
|
+
const host = hostNow()
|
|
291
|
+
const view = host?.viewName(id) ?? null
|
|
292
|
+
put({ t: 'hello', id, tmux: host?.group ?? null })
|
|
293
|
+
let pty: Pty
|
|
294
|
+
try {
|
|
295
|
+
if (host != null && !host.alive()) host.start()
|
|
296
|
+
const watch = host == null ? null : watchOf(host)
|
|
297
|
+
const argv = host != null ? host.viewArgv(view!, window) : [process.env.SHELL || '/bin/zsh', '-l']
|
|
298
|
+
pty = spawn({ argv, cwd: existsSync(d.root) ? d.root : process.cwd(), env: ownEnv(), cols, rows, data: (b) => (put({ t: 'o', d: Buffer.from(b).toString('base64') }), watch?.kick()) })
|
|
299
|
+
// which terminal the view shows is the host's word, said each time it moved
|
|
300
|
+
if (watch != null) onEnd(watch.join({ view: [view!, (w) => put({ t: 'v', window: w })] }))
|
|
301
|
+
} catch (e) {
|
|
302
|
+
put({ t: 'o', d: Buffer.from(`the shell did not start: ${(e as Error).message}\r\n`).toString('base64') })
|
|
303
|
+
put({ t: 'exit', code: 1 })
|
|
304
|
+
return null
|
|
305
|
+
}
|
|
306
|
+
onEnd(() => pty.kill())
|
|
307
|
+
void pty.exited.then((code) => {
|
|
308
|
+
// a client that died leaves the terminals where they are: the page is told, and looks at them again
|
|
309
|
+
const kept = !ended() && host != null && host.alive()
|
|
310
|
+
put({ t: 'exit', code, ...(kept ? { kept } : {}) })
|
|
311
|
+
end()
|
|
312
|
+
})
|
|
313
|
+
return { pty, host, view, lists: host != null }
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** the repo's terminals and the Claude sessions of its folder, with no pty: what a list reads. A hop's list is the
|
|
318
|
+
* terminals alone: a Claude Code session's pid, its session and its account never leave this machine */
|
|
319
|
+
function watch(b: PartAsk, scope: string | null): Response {
|
|
320
|
+
const host = hostNow()
|
|
321
|
+
return part(b, scope, ({ id, put, onEnd }) => {
|
|
322
|
+
put({ t: 'hello', id, tmux: host?.group ?? null })
|
|
323
|
+
// nothing keeps a terminal on this Mac: an empty list, said once, so the page does not wait for one
|
|
324
|
+
if (host == null) put({ t: 'w', windows: [] })
|
|
325
|
+
else onEnd(watchOf(host).join({ lists: scope == null ? put : (l) => void (l.t === 'c' ? null : put(l)) }))
|
|
326
|
+
return { pty: null, host, view: null, lists: host != null }
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** the repo's terminals and Claude sessions for a caller in this process (every project's lists, below): each
|
|
331
|
+
* line goes to `put`, and the id acts on a terminal as a list part's does. `gone`: these routes ended it (a hub
|
|
332
|
+
* that reloads), never the caller's own `leave` */
|
|
333
|
+
function listen(put: (l: TermLine) => void, gone: () => void): { id: string; leave: () => void } {
|
|
334
|
+
const id = randomBytes(16).toString('hex')
|
|
335
|
+
const host = hostNow()
|
|
100
336
|
let done = false
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
try { ctl.enqueue(enc.encode(`${JSON.stringify(l)}\n`)) } catch { end() }
|
|
104
|
-
}
|
|
105
|
-
let beat: ReturnType<typeof setInterval> | null = null
|
|
106
|
-
let pty: Pty | null = null
|
|
107
|
-
function end(): void {
|
|
337
|
+
const ends: (() => void)[] = []
|
|
338
|
+
const leave = (): void => {
|
|
108
339
|
if (done) return
|
|
109
340
|
done = true
|
|
110
|
-
if (beat != null) clearInterval(beat)
|
|
111
341
|
sessions.delete(id)
|
|
112
|
-
|
|
113
|
-
try { ctl?.close() } catch { /* the reader went away first */ }
|
|
342
|
+
for (const f of ends.splice(0)) f()
|
|
114
343
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// the oldest goes when a page opened too many
|
|
133
|
-
if (sessions.size > MAX_SESSIONS) sessions.values().next().value?.end()
|
|
134
|
-
beat = setInterval(() => put({ t: 'beat' }), BEAT_MS)
|
|
135
|
-
},
|
|
136
|
-
cancel: end,
|
|
137
|
-
})
|
|
138
|
-
return new Response(stream, { headers: { ...NO_STORE, 'content-type': 'application/x-ndjson; charset=utf-8' } })
|
|
344
|
+
put({ t: 'hello', id, tmux: host?.group ?? null })
|
|
345
|
+
// a project with no terminal says so at once, as an empty list: a page waits for each project's first word
|
|
346
|
+
if (host == null) put({ t: 'w', windows: [] })
|
|
347
|
+
else ends.push(watchOf(host).join({ lists: put }))
|
|
348
|
+
sessions.set(id, { pty: null, host, view: null, lists: host != null, scope: null, end: () => { if (!done) (leave(), gone()) } })
|
|
349
|
+
return { id, leave }
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** an act on one of the repo's terminals. With none running (no terminal opened since the Mac started) the
|
|
353
|
+
* terminal asked for is the first one */
|
|
354
|
+
function act(host: TerminalHost, view: string | null, a: NonNullable<ReturnType<typeof windowAct>>): Acted {
|
|
355
|
+
const claude = d.claude ?? claudeAs
|
|
356
|
+
if ((a.act !== 'new' && a.act !== 'claude') || host.alive()) return host.act(a, view, claude)
|
|
357
|
+
const start = a.act === 'claude' ? claude(a.account) : null
|
|
358
|
+
if (typeof start === 'string') return { ok: false, why: start }
|
|
359
|
+
const window = host.start(start == null ? [] : ['-n', 'claude', '--', ...start.argv])
|
|
360
|
+
return window != null ? { ok: true, window } : { ok: false, why: 'the terminal did not start' }
|
|
139
361
|
}
|
|
140
362
|
|
|
141
363
|
return {
|
|
142
364
|
sessions,
|
|
365
|
+
watches,
|
|
366
|
+
listen,
|
|
143
367
|
/** a request under `/api/terminal/` or `/api/terminal-lib/`; null for any other path */
|
|
144
|
-
async handle(req: Request, path: string, srv: { requestIP(r: Request): { address: string } | null
|
|
368
|
+
async handle(req: Request, path: string, srv: { requestIP(r: Request): { address: string } | null }): Promise<Response | null> {
|
|
145
369
|
if (path.startsWith('/api/terminal-lib/')) {
|
|
146
370
|
const f = LIB[path.slice('/api/terminal-lib/'.length)]
|
|
147
371
|
if (f == null || req.method !== 'GET') return new Response('not a terminal file', { status: 404 })
|
|
148
372
|
return new Response(Bun.file(Bun.resolveSync(f.mod, import.meta.dir)), { headers: { 'content-type': f.type, 'cache-control': 'max-age=86400' } })
|
|
149
373
|
}
|
|
150
374
|
if (!path.startsWith('/api/terminal/')) return null
|
|
151
|
-
|
|
375
|
+
// a hop of the hq Mac's page (hq/terminal-hop.ts) is judged by its key, and acts under its one repo alone
|
|
376
|
+
const hop = isTerminalHop(req)
|
|
377
|
+
const why = hop ? terminalHopRefusal(req, d.hop) : terminalRefusal(req, srv.requestIP(req)?.address ?? null)
|
|
152
378
|
if (why != null) return new Response(why, { status: 403, headers: NO_STORE })
|
|
153
|
-
const
|
|
379
|
+
const scope = hop ? d.name : null
|
|
380
|
+
const b = (await req.json().catch(() => null)) as { page?: unknown; key?: unknown; id?: unknown; cols?: unknown; rows?: unknown; lines?: unknown; attach?: unknown; act?: unknown; window?: unknown; name?: unknown; account?: unknown } | null
|
|
154
381
|
if (b == null || typeof b !== 'object') return new Response('the body is no json object', { status: 400, headers: NO_STORE })
|
|
382
|
+
if (path === '/api/terminal/close') return closePart(b, scope)
|
|
383
|
+
if (path === '/api/terminal/watch') return watch(b, scope)
|
|
155
384
|
if (path === '/api/terminal/open') {
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
return open(size(b.cols, 2, 500, 80), size(b.rows, 2, 200, 24), typeof b.
|
|
385
|
+
// a session of another server is never attached by its name: every terminal the hub shows is the host's
|
|
386
|
+
if (b.attach != null) return new Response('a session is no longer shown by its name: the orchestrator is a terminal of the project, in the main panel', { status: 404, headers: NO_STORE })
|
|
387
|
+
return open(b, scope, size(b.cols, 2, 500, 80), size(b.rows, 2, 200, 24), typeof b.window === 'string' && /^@\d+$/.test(b.window) ? b.window : null)
|
|
388
|
+
}
|
|
389
|
+
// a part of a hop is acted on by that hop alone, a part of a page of this machine by such a page alone
|
|
390
|
+
const found = typeof b.id === 'string' ? sessions.get(b.id) : undefined
|
|
391
|
+
const s = found?.scope === scope ? found : undefined
|
|
392
|
+
if (path === '/api/terminal/history') {
|
|
393
|
+
// the last lines of the terminal a view shows, its screen included: what the page draws when he scrolls up
|
|
394
|
+
if (s?.host == null || s.view == null) return new Response('this terminal keeps no history to read', { status: 404, headers: NO_STORE })
|
|
395
|
+
return new Response(s.host.history(s.view, size(b.lines, 1, HISTORY_LINES, 10_000)), { headers: { ...NO_STORE, 'content-type': 'text/plain; charset=utf-8' } })
|
|
159
396
|
}
|
|
160
|
-
if (path === '/api/terminal/
|
|
161
|
-
const s = typeof b.id === 'string' ? sessions.get(b.id) : undefined
|
|
397
|
+
if (path === '/api/terminal/window') {
|
|
162
398
|
if (s == null) return new Response('no such terminal: open it again', { status: 404, headers: NO_STORE })
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return new Response(null, { status: 204, headers: NO_STORE })
|
|
399
|
+
const a = windowAct(b)
|
|
400
|
+
if (s.host == null || !s.lists || a == null) return new Response(a == null ? 'not an act on a terminal' : 'this shell is the only terminal here', { status: 400, headers: NO_STORE })
|
|
401
|
+
const did = act(s.host, s.view, a)
|
|
402
|
+
// every page on these terminals reads its list again, after a refused act too: its list was stale
|
|
403
|
+
watches.get(s.host.reach)?.now()
|
|
404
|
+
if (!did.ok) return new Response(did.why, { status: 409, headers: NO_STORE })
|
|
405
|
+
return did.window == null ? new Response(null, { status: 204, headers: NO_STORE }) : Response.json({ window: did.window }, { headers: NO_STORE })
|
|
171
406
|
}
|
|
172
407
|
return new Response('not a terminal route', { status: 404, headers: NO_STORE })
|
|
173
408
|
},
|
|
174
409
|
stop: (): void => { for (const s of [...sessions.values()]) s.end() },
|
|
175
410
|
}
|
|
176
411
|
}
|
|
412
|
+
|
|
413
|
+
export type TerminalRoutes = ReturnType<typeof terminalRoutes>
|
|
414
|
+
const SHARED = new Map<string, TerminalRoutes>()
|
|
415
|
+
|
|
416
|
+
/** the one set of terminal routes of a repo in this process: its hub's own (serve-hub.ts) and the machine's lists
|
|
417
|
+
* read the same parts' ids, so an act through `/r/<repo>/api/terminal/window` knows an id either one gave */
|
|
418
|
+
export function terminalRoutesOf(d: TerminalDeps): TerminalRoutes {
|
|
419
|
+
const key = `${d.name}\0${d.root}`
|
|
420
|
+
let t = SHARED.get(key)
|
|
421
|
+
if (t == null) {
|
|
422
|
+
const made = terminalRoutes(d)
|
|
423
|
+
t = { ...made, stop: () => (SHARED.delete(key), made.stop()) }
|
|
424
|
+
SHARED.set(key, t)
|
|
425
|
+
}
|
|
426
|
+
return t
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** a repo whose routes ended its list (its hub reloaded) is listened to again this long after */
|
|
430
|
+
const REJOIN_MS = 500
|
|
431
|
+
type Repo = { name: string; root: string }
|
|
432
|
+
|
|
433
|
+
/** every project's terminals and Claude Code sessions as ONE part of a page's socket (POST /api/terminal/machine):
|
|
434
|
+
* each line is a repo's own, under its repo (`hello` with the id that repo's window route takes, `w`, `c`), and each
|
|
435
|
+
* repo says a first `w`, an empty one where it has no terminal. `of`: the routes of a repo (a test's own) */
|
|
436
|
+
export function machineLists(b: PartAsk, repos: Repo[], of: (r: Repo) => Pick<TerminalRoutes, 'listen'> = terminalRoutesOf): Response {
|
|
437
|
+
const p = pagePart(b)
|
|
438
|
+
if (p == null) return noPage()
|
|
439
|
+
const leaves = new Map<string, () => void>()
|
|
440
|
+
p.onEnd(() => {
|
|
441
|
+
for (const leave of [...leaves.values()]) leave()
|
|
442
|
+
leaves.clear()
|
|
443
|
+
})
|
|
444
|
+
const join = (r: Repo): void => {
|
|
445
|
+
if (p.ended()) return
|
|
446
|
+
const s = of(r).listen((l) => p.put(l, r.name), () => {
|
|
447
|
+
leaves.delete(r.name)
|
|
448
|
+
setTimeout(() => join(r), REJOIN_MS)
|
|
449
|
+
})
|
|
450
|
+
leaves.set(r.name, s.leave)
|
|
451
|
+
}
|
|
452
|
+
for (const r of repos) join(r)
|
|
453
|
+
return taken()
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** a stream this process reads for a page: its answer once asked, cut by the signal */
|
|
457
|
+
export type Follow = (signal: AbortSignal) => Promise<Response>
|
|
458
|
+
/** the streams one process reads for pages, logs and frames' channels together: one asked past it is refused, and
|
|
459
|
+
* its page asks again later, twice as late each time. Never the oldest ended: two pages would trade one read for ever */
|
|
460
|
+
export const FOLLOWS_MAX = 64
|
|
461
|
+
const FOLLOWS = new Set<() => void>()
|
|
462
|
+
/** how many streams this process reads for pages now (a check counts them) */
|
|
463
|
+
export const followsHeld = (): number => FOLLOWS.size
|
|
464
|
+
/** a source that did not answer by then refuses the part: the page asks again */
|
|
465
|
+
const FOLLOW_ANSWER_MS = 3_000
|
|
466
|
+
|
|
467
|
+
/** a stream read here for a page, as ONE part of its socket, so the page holds no request open for it: the source is
|
|
468
|
+
* asked first, and its refusal is the POST's answer (404 as it is, 504 where it said nothing in time, else 502); then `hello`, each piece as an `o`
|
|
469
|
+
* line, and `gone` when the source ended the stream (it restarted), so the page asks again. The part's end ends
|
|
470
|
+
* the read at its source */
|
|
471
|
+
export async function followPart(b: PartAsk, ask: Follow, o: { answerMs?: number } = {}): Promise<Response> {
|
|
472
|
+
const p = pagePart(b)
|
|
473
|
+
if (p == null) return noPage()
|
|
474
|
+
if (FOLLOWS.size >= FOLLOWS_MAX) {
|
|
475
|
+
p.end()
|
|
476
|
+
return new Response(`this hub reads ${FOLLOWS_MAX} streams for its pages already: asked again in a moment`, { status: 503, ...ANSWER })
|
|
477
|
+
}
|
|
478
|
+
const ctl = new AbortController()
|
|
479
|
+
p.onEnd(() => ctl.abort())
|
|
480
|
+
let late = false
|
|
481
|
+
const slow = setTimeout(() => (late = true, ctl.abort()), o.answerMs ?? FOLLOW_ANSWER_MS)
|
|
482
|
+
let r: Response
|
|
483
|
+
try {
|
|
484
|
+
r = await ask(ctl.signal)
|
|
485
|
+
} catch {
|
|
486
|
+
if (p.ended() && !late) return taken()
|
|
487
|
+
p.end()
|
|
488
|
+
// 504: it is there and said nothing yet (a server that sends its headers with its first piece), so a page
|
|
489
|
+
// that can read the stream itself does; 502: it is not there
|
|
490
|
+
return late ? new Response('the source of the stream said nothing in time', { status: 504, ...ANSWER }) : new Response('the source of the stream does not answer', { status: 502, ...ANSWER })
|
|
491
|
+
} finally {
|
|
492
|
+
clearTimeout(slow)
|
|
493
|
+
}
|
|
494
|
+
if (p.ended()) return (void r.body?.cancel().catch(() => {}), taken())
|
|
495
|
+
if (!r.ok || r.body == null) {
|
|
496
|
+
p.end()
|
|
497
|
+
return new Response(await r.text().catch(() => ''), { status: r.status === 404 ? 404 : 502, ...ANSWER })
|
|
498
|
+
}
|
|
499
|
+
const gone = (): void => (p.put({ t: 'gone' }), p.end())
|
|
500
|
+
FOLLOWS.add(gone)
|
|
501
|
+
p.onEnd(() => void FOLLOWS.delete(gone))
|
|
502
|
+
p.put({ t: 'hello', id: randomBytes(16).toString('hex'), tmux: null })
|
|
503
|
+
const reader = r.body.getReader()
|
|
504
|
+
// a source that reads no signal (a stream made in this process) ends by its reader
|
|
505
|
+
p.onEnd(() => void reader.cancel().catch(() => {}))
|
|
506
|
+
void (async () => {
|
|
507
|
+
try {
|
|
508
|
+
for (;;) {
|
|
509
|
+
const c = await reader.read()
|
|
510
|
+
if (c.done || p.ended()) break
|
|
511
|
+
p.put({ t: 'o', d: Buffer.from(c.value).toString('base64') })
|
|
512
|
+
}
|
|
513
|
+
} catch { /* the read ended with the part, or its source went */ }
|
|
514
|
+
gone()
|
|
515
|
+
})()
|
|
516
|
+
return taken()
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** a process's log as pm streams it (GET /api/pm/log): `id` the process, `lines` its last lines read first */
|
|
520
|
+
export type LogAsk = (id: string, lines: number, signal: AbortSignal) => Promise<Response>
|
|
521
|
+
|
|
522
|
+
/** the machine's own terminal routes (the home's, home-routes.ts): every project's lists as one part of a page's
|
|
523
|
+
* socket, a process's log as one (`log`: how pm is asked for it), a part ended. A project's own parts (a terminal,
|
|
524
|
+
* its list) are asked under the project (`/r/<repo>/api/terminal/`) and name the same socket. null for any other
|
|
525
|
+
* path */
|
|
526
|
+
export async function machineTerminal(req: Request, path: string, srv: { requestIP(r: Request): { address: string } | null } | undefined, repos: () => Repo[] | Promise<Repo[]>, of?: (r: Repo) => Pick<TerminalRoutes, 'listen'>, log?: LogAsk): Promise<Response | null> {
|
|
527
|
+
if (path !== '/api/terminal/machine' && path !== '/api/terminal/close' && !(path === '/api/terminal/log' && log != null)) return null
|
|
528
|
+
const why = terminalRefusal(req, srv?.requestIP(req)?.address ?? null)
|
|
529
|
+
if (why != null) return new Response(why, { status: 403, headers: NO_STORE })
|
|
530
|
+
const b = (await req.json().catch(() => null)) as (PartAsk & { id?: unknown; lines?: unknown }) | null
|
|
531
|
+
if (b == null || typeof b !== 'object') return new Response('the body is no json object', { status: 400, headers: NO_STORE })
|
|
532
|
+
if (path === '/api/terminal/close') return closePart(b)
|
|
533
|
+
if (path === '/api/terminal/log' && log != null) {
|
|
534
|
+
const id = b.id
|
|
535
|
+
if (typeof id !== 'string' || id === '' || id.length > 128) return new Response('a log is asked by the id of its process', { status: 400, headers: NO_STORE })
|
|
536
|
+
return followPart(b, (signal) => log(id, size(b.lines, 1, 10_000, 2_000), signal))
|
|
537
|
+
}
|
|
538
|
+
return machineLists(b, await repos(), of)
|
|
539
|
+
}
|