kaizen-agent 1.86.0 → 1.87.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cli/annotate-proxy.ts +6 -3
- package/cli/build-web.ts +46 -16
- package/cli/dev.ts +67 -0
- package/cli/docs.ts +1 -1
- package/cli/notes.ts +9 -3
- package/cli/ports.ts +121 -0
- package/cli/settings.ts +16 -17
- package/cli/state.ts +15 -29
- package/cli/task-service.ts +79 -17
- package/cli/tasks.ts +2 -2
- package/cli/term-image.ts +18 -0
- package/cli/ui-audit.allow.json +0 -1
- package/cli/ui-audit.ts +12 -12
- package/cli/web.ts +188 -58
- package/package.json +21 -4
- package/skills/kaizen/spec.md +10 -3
- package/tsconfig.json +16 -0
- package/web/README.md +105 -0
- package/web/{annotate.js → annotate/annotate.ts} +51 -50
- package/web/boot/boot.ts +7 -0
- package/web/components/annotate/annotate-bar.tsx +78 -0
- package/web/components/annotate/annotate-panel.tsx +20 -0
- package/web/components/annotate/annotate-settings.tsx +60 -0
- package/web/components/annotate/index.ts +1 -0
- package/web/components/annotate/notes-list.tsx +75 -0
- package/web/components/board/board-card.tsx +177 -0
- package/web/components/board/board-column.tsx +212 -0
- package/web/components/board/board-mode-switch.tsx +21 -0
- package/web/components/board/board-popups.tsx +45 -0
- package/web/components/board/card-footer.tsx +58 -0
- package/web/components/board/card-form.tsx +168 -0
- package/web/components/board/card-kids.tsx +53 -0
- package/web/components/board/clear-menu.tsx +36 -0
- package/web/components/board/filter-box.tsx +42 -0
- package/web/components/board/index.ts +6 -0
- package/web/components/board/run-form.tsx +129 -0
- package/web/components/board/severity-menu.tsx +44 -0
- package/web/components/board/status-strip.tsx +75 -0
- package/web/components/board/task-form.tsx +140 -0
- package/web/components/board/ws-card.tsx +38 -0
- package/web/components/context/context-panel.tsx +244 -0
- package/web/components/context/index.ts +1 -0
- package/web/components/decision/decision-bar.tsx +422 -0
- package/web/components/decision/index.ts +1 -0
- package/web/components/decision/inline-form.tsx +47 -0
- package/web/components/decision/plan-answers-form.tsx +78 -0
- package/web/components/decision/revise-form.tsx +65 -0
- package/web/components/decision/task-reply-form.tsx +48 -0
- package/web/components/footer/foot-bar.tsx +67 -0
- package/web/components/footer/index.ts +1 -0
- package/web/components/git/git-ask.tsx +88 -0
- package/web/components/git/git-commits.tsx +53 -0
- package/web/components/git/git-confirm.tsx +78 -0
- package/web/components/git/git-counts.tsx +10 -0
- package/web/components/git/git-files.tsx +113 -0
- package/web/components/git/git-head.tsx +70 -0
- package/web/components/git/git-icon.tsx +25 -0
- package/web/components/git/git-message.tsx +44 -0
- package/web/components/git/git-split.tsx +64 -0
- package/web/components/git/git-tab.tsx +55 -0
- package/web/components/git/index.ts +1 -0
- package/web/components/home/chat-list.tsx +57 -0
- package/web/components/home/home-composer.tsx +169 -0
- package/web/components/home/home-message.tsx +120 -0
- package/web/components/home/home-window.tsx +253 -0
- package/web/components/home/home-ws-add.tsx +47 -0
- package/web/components/home/index.ts +6 -0
- package/web/components/home/onboarding-dialog.tsx +371 -0
- package/web/components/icebox/board-chip.tsx +27 -0
- package/web/components/icebox/board-menu.tsx +41 -0
- package/web/components/icebox/bulk-bar.tsx +41 -0
- package/web/components/icebox/capture-box.tsx +155 -0
- package/web/components/icebox/choice-menu.tsx +39 -0
- package/web/components/icebox/collection-dialog.tsx +60 -0
- package/web/components/icebox/favicon.tsx +39 -0
- package/web/components/icebox/index.ts +10 -0
- package/web/components/icebox/kind-label.tsx +22 -0
- package/web/components/icebox/kind-menu.tsx +20 -0
- package/web/components/icebox/promote-form.tsx +93 -0
- package/web/components/icebox/reply-box.tsx +88 -0
- package/web/components/icebox/request-actions.tsx +141 -0
- package/web/components/icebox/request-badges.tsx +13 -0
- package/web/components/icebox/request-card.tsx +99 -0
- package/web/components/icebox/request-detail.tsx +43 -0
- package/web/components/icebox/request-images.tsx +33 -0
- package/web/components/icebox/request-phone-row.tsx +181 -0
- package/web/components/icebox/request-row.tsx +120 -0
- package/web/components/icebox/service-chip.tsx +58 -0
- package/web/components/icebox/snooze-menu.tsx +83 -0
- package/web/components/icebox/source-card.tsx +225 -0
- package/web/components/icebox/source-drawer.tsx +112 -0
- package/web/components/icebox/source-form.tsx +147 -0
- package/web/components/icebox/swipe-deck.tsx +242 -0
- package/web/components/layout/index.ts +1 -0
- package/web/components/layout/page-frame.tsx +44 -0
- package/web/components/markdown/index.ts +1 -0
- package/web/components/markdown/markdown.tsx +156 -0
- package/web/components/notebook/editor-pane.tsx +23 -0
- package/web/components/notebook/index.ts +5 -0
- package/web/components/notebook/note-body.tsx +172 -0
- package/web/components/notebook/note-tree.tsx +99 -0
- package/web/components/notebook/notes-head.tsx +37 -0
- package/web/components/notebook/notes-side.tsx +46 -0
- package/web/components/notes/index.ts +1 -0
- package/web/components/notes/note-composer.tsx +90 -0
- package/web/components/notes/notes-chat.tsx +58 -0
- package/web/components/panes/browser-pane.tsx +281 -0
- package/web/components/panes/index.ts +3 -0
- package/web/components/panes/preview-pane.tsx +91 -0
- package/web/components/panes/terminal-pane.tsx +52 -0
- package/web/components/phone/haptic.tsx +29 -0
- package/web/components/phone/index.ts +6 -0
- package/web/components/phone/phone-card.tsx +118 -0
- package/web/components/phone/phone-home.tsx +304 -0
- package/web/components/phone/phone-sheets.tsx +103 -0
- package/web/components/phone/qr-code.tsx +6 -0
- package/web/components/phone/usage-chips.tsx +85 -0
- package/web/components/phone/whatsapp-card.tsx +85 -0
- package/web/components/project/add-project-dialog.tsx +435 -0
- package/web/components/project/index.ts +3 -0
- package/web/components/project/project-bar.tsx +101 -0
- package/web/components/project/ws-menu.tsx +21 -0
- package/web/components/rail/agent-chips.tsx +110 -0
- package/web/components/rail/index.ts +4 -0
- package/web/components/rail/rail-filter.tsx +118 -0
- package/web/components/rail/rail-list.tsx +259 -0
- package/web/components/rail/source-marks.tsx +21 -0
- package/web/components/resources/index.ts +1 -0
- package/web/components/resources/resources-popup.tsx +490 -0
- package/web/components/run/doc-body.tsx +123 -0
- package/web/components/run/file-viewer.tsx +53 -0
- package/web/components/run/fix-form.tsx +88 -0
- package/web/components/run/index.ts +16 -0
- package/web/components/run/inline-md.tsx +30 -0
- package/web/components/run/key-hint.tsx +29 -0
- package/web/components/run/pane-gutter.tsx +52 -0
- package/web/components/run/pane-header.tsx +35 -0
- package/web/components/run/pane.tsx +140 -0
- package/web/components/run/panel-grip.tsx +49 -0
- package/web/components/run/panel-head.tsx +56 -0
- package/web/components/run/panel-tabs.tsx +35 -0
- package/web/components/run/phase-steps.tsx +37 -0
- package/web/components/run/project-notes.tsx +49 -0
- package/web/components/run/run-add-menu.tsx +80 -0
- package/web/components/run/run-bar.tsx +40 -0
- package/web/components/run/run-empty.tsx +10 -0
- package/web/components/run/run-footer.tsx +53 -0
- package/web/components/run/run-history.tsx +24 -0
- package/web/components/run/run-panes.tsx +78 -0
- package/web/components/run/run-picker.tsx +51 -0
- package/web/components/run/run-progress.tsx +30 -0
- package/web/components/run/run-tabs.tsx +147 -0
- package/web/components/run/run-wait.tsx +18 -0
- package/web/components/search/index.ts +1 -0
- package/web/components/search/search-palette.tsx +159 -0
- package/web/components/settings/account-rows.tsx +128 -0
- package/web/components/settings/agent-rows.tsx +249 -0
- package/web/components/settings/automation-rows.tsx +211 -0
- package/web/components/settings/browser-row.tsx +111 -0
- package/web/components/settings/cleanup-row.tsx +32 -0
- package/web/components/settings/commit-input.tsx +39 -0
- package/web/components/settings/index.ts +4 -0
- package/web/components/settings/integration-row.tsx +158 -0
- package/web/components/settings/mic-row.tsx +48 -0
- package/web/components/settings/orchestration-flow.tsx +87 -0
- package/web/components/settings/setting-row.tsx +131 -0
- package/web/components/settings/settings-item.tsx +78 -0
- package/web/components/settings/settings-loading.tsx +41 -0
- package/web/components/settings/settings-nav.tsx +119 -0
- package/web/components/settings/settings-scope.tsx +66 -0
- package/web/components/settings/settings-section.tsx +33 -0
- package/web/components/settings/skill-card.tsx +131 -0
- package/web/components/settings/stepper.tsx +74 -0
- package/web/components/settings/update-bar.tsx +167 -0
- package/web/components/shared/action-menu.tsx +76 -0
- package/web/components/shared/ask-host.tsx +18 -0
- package/web/components/shared/attach-button.tsx +23 -0
- package/web/components/shared/chip.tsx +19 -0
- package/web/components/shared/client-mark.tsx +15 -0
- package/web/components/shared/confirm-dialog.tsx +35 -0
- package/web/components/shared/empty-state.tsx +29 -0
- package/web/components/shared/field.tsx +77 -0
- package/web/components/shared/filter-popover.tsx +29 -0
- package/web/components/shared/form-frame.tsx +19 -0
- package/web/components/shared/icon-button.tsx +50 -0
- package/web/components/shared/index.ts +18 -0
- package/web/components/shared/mic-button.tsx +75 -0
- package/web/components/shared/pager.tsx +49 -0
- package/web/components/shared/picker.tsx +108 -0
- package/web/components/shared/project-mark.tsx +38 -0
- package/web/components/shared/segmented.tsx +43 -0
- package/web/components/shared/state-dot.tsx +4 -0
- package/web/components/shared/status-mark.tsx +26 -0
- package/web/components/shell/index.ts +3 -0
- package/web/components/shell/rail.tsx +259 -0
- package/web/components/shell/sprite.tsx +124 -0
- package/web/components/shell/wordmark.tsx +13 -0
- package/web/components/task/artifact-view.tsx +148 -0
- package/web/components/task/chat-bubble.tsx +43 -0
- package/web/components/task/filter-menu.tsx +38 -0
- package/web/components/task/index.ts +7 -0
- package/web/components/task/result-checks.tsx +34 -0
- package/web/components/task/result-view.tsx +113 -0
- package/web/components/task/status-badge.tsx +24 -0
- package/web/components/task/task-row.tsx +34 -0
- package/web/components/task/typing-dots.tsx +16 -0
- package/web/components/terminal/index.ts +3 -0
- package/web/components/terminal/terminal-bar.tsx +91 -0
- package/web/components/terminal/terminal-grid.tsx +149 -0
- package/web/components/terminal/terminal-modes.tsx +23 -0
- package/web/components/terminal/terminal-tile.tsx +139 -0
- package/web/dist/annotate.js +24 -0
- package/web/dist/board.css +718 -0
- package/web/dist/board.js +115 -0
- package/web/dist/boot.js +2 -0
- package/web/dist/notebook.css +319 -0
- package/web/dist/notebook.js +89 -0
- package/web/dist/popup.css +41 -0
- package/web/dist/popup.js +13 -0
- package/web/{term.js → dist/term.js} +48 -48
- package/web/dist/ui.css +3 -0
- package/web/dist/video.js +108 -0
- package/web/html/board.html +17 -0
- package/web/html/notes.html +14 -0
- package/web/html/popup.html +13 -0
- package/web/{video.html → html/video.html} +14 -15
- package/web/lib/annotate/index.ts +2 -0
- package/web/lib/annotate/notes.ts +105 -0
- package/web/lib/annotate/page.ts +121 -0
- package/web/lib/annotate/rules.ts +37 -0
- package/web/lib/annotate/session.ts +336 -0
- package/web/lib/board/board-actions.ts +119 -0
- package/web/lib/board/board-open.ts +12 -0
- package/web/lib/board/board-store.ts +159 -0
- package/web/lib/board/filter-box.ts +7 -0
- package/web/lib/board/index.ts +10 -0
- package/web/lib/board/nav.ts +29 -0
- package/web/lib/board/on-state.ts +90 -0
- package/web/lib/board/popups.ts +22 -0
- package/web/lib/board/snapshot.ts +105 -0
- package/web/lib/board/strip.ts +43 -0
- package/web/{board → lib/board}/ws-board.ts +1 -1
- package/web/lib/context/context-rules.ts +27 -0
- package/web/lib/context/context-store.ts +95 -0
- package/web/lib/context/feed.ts +28 -0
- package/web/lib/context/index.ts +3 -0
- package/web/lib/core/api.ts +86 -0
- package/web/lib/core/ask.ts +24 -0
- package/web/lib/core/board.ts +290 -0
- package/web/lib/core/brief.ts +31 -0
- package/web/lib/core/format.ts +8 -0
- package/web/lib/core/host.ts +107 -0
- package/web/lib/core/index.ts +16 -0
- package/web/{board → lib/core}/labels.ts +6 -5
- package/web/lib/core/layers.ts +7 -0
- package/web/lib/core/leave.ts +7 -0
- package/web/lib/core/motion.ts +10 -0
- package/web/{board/toast.ts → lib/core/notices.ts} +2 -20
- package/web/lib/core/notifier.ts +15 -0
- package/web/lib/core/store.ts +39 -0
- package/web/lib/core/term-handle.ts +8 -0
- package/web/lib/core/toast.ts +29 -0
- package/web/lib/core/utils.ts +15 -0
- package/web/lib/decision/index.ts +1 -0
- package/web/lib/decision/plan-questions.ts +39 -0
- package/web/lib/dictation/chunks.ts +93 -0
- package/web/lib/dictation/dictation-store.ts +22 -0
- package/web/lib/dictation/engine.ts +265 -0
- package/web/lib/dictation/index.ts +5 -0
- package/web/lib/dictation/mic.ts +42 -0
- package/web/lib/dictation/terminal-dictation.ts +50 -0
- package/web/lib/footer/footer-rules.ts +13 -0
- package/web/lib/footer/footer-store.ts +42 -0
- package/web/lib/footer/index.ts +2 -0
- package/web/lib/git/git-actions.ts +110 -0
- package/web/lib/git/git-panel.ts +43 -0
- package/web/lib/git/git-store.ts +47 -0
- package/web/lib/git/git.ts +170 -0
- package/web/lib/git/index.ts +4 -0
- package/web/lib/home/home-engine.ts +16 -0
- package/web/lib/home/home-events.ts +9 -0
- package/web/lib/home/home-store.ts +247 -0
- package/web/lib/home/home-window.ts +193 -0
- package/web/lib/home/home.ts +85 -0
- package/web/lib/home/index.ts +7 -0
- package/web/lib/home/onboarding.ts +199 -0
- package/web/lib/home/use-float-drag.ts +62 -0
- package/web/lib/icebox/icebox-actions.ts +518 -0
- package/web/lib/icebox/icebox-store.ts +112 -0
- package/web/lib/icebox/icebox-view.ts +48 -0
- package/web/lib/icebox/icebox.ts +273 -0
- package/web/lib/icebox/index.ts +8 -0
- package/web/lib/icebox/use-card-drag.ts +82 -0
- package/web/lib/icebox/use-ice-keys.ts +75 -0
- package/web/lib/icebox/use-icebox.ts +41 -0
- package/web/lib/icebox/use-row-swipe.ts +107 -0
- package/web/lib/markdown/index.ts +1 -0
- package/web/lib/markdown/markdown.ts +136 -0
- package/web/lib/notebook/autosave.ts +131 -0
- package/web/lib/notebook/deal.ts +58 -0
- package/web/lib/notebook/engine-complete.ts +128 -0
- package/web/lib/notebook/engine-preview.ts +287 -0
- package/web/lib/notebook/engine-types.ts +26 -0
- package/web/lib/notebook/engine-widgets.ts +218 -0
- package/web/lib/notebook/engine.ts +74 -0
- package/web/lib/notebook/index.ts +9 -0
- package/web/lib/notebook/kit-loader.ts +16 -0
- package/web/lib/notebook/kit.ts +12 -0
- package/web/{notes-lib.ts → lib/notebook/text.ts} +11 -10
- package/web/lib/notebook/vault-actions.ts +239 -0
- package/web/lib/notebook/vault-rules.ts +74 -0
- package/web/lib/notebook/vault-session.ts +73 -0
- package/web/lib/notebook/vault-store.ts +63 -0
- package/web/lib/notes/index.ts +4 -0
- package/web/lib/notes/md-html.ts +115 -0
- package/web/lib/notes/notes-actions.ts +32 -0
- package/web/lib/notes/notes-store.ts +22 -0
- package/web/lib/notes/notes.ts +58 -0
- package/web/{board → lib/notes}/rich.ts +1 -2
- package/web/lib/phone/index.ts +7 -0
- package/web/lib/phone/phone-actions.ts +77 -0
- package/web/lib/phone/phone-home.ts +102 -0
- package/web/lib/phone/phone-setup.ts +59 -0
- package/web/lib/phone/phone-sheet.ts +25 -0
- package/web/lib/phone/phone-store.ts +32 -0
- package/web/lib/phone/sheet-swipe.ts +55 -0
- package/web/lib/phone/use-phone-setup.ts +89 -0
- package/web/lib/project/add-project.ts +37 -0
- package/web/lib/project/branch.ts +14 -0
- package/web/lib/project/index.ts +5 -0
- package/web/lib/project/project-bar.ts +76 -0
- package/web/lib/project/project-pick.ts +36 -0
- package/web/lib/project/ws-menu.ts +8 -0
- package/web/lib/rail/agents.ts +63 -0
- package/web/lib/rail/card-links.ts +20 -0
- package/web/lib/rail/index.ts +7 -0
- package/web/lib/rail/rail-actions.ts +74 -0
- package/web/lib/rail/rail-boot.ts +99 -0
- package/web/lib/rail/rail-store.ts +85 -0
- package/web/lib/rail/rules.ts +241 -0
- package/web/lib/rail/source-marks.ts +17 -0
- package/web/lib/rail/use-rank-drag.ts +108 -0
- package/web/lib/resources/index.ts +3 -0
- package/web/lib/resources/resources-actions.ts +59 -0
- package/web/lib/resources/resources-store.ts +48 -0
- package/web/lib/resources/rules.ts +56 -0
- package/web/lib/router/index.ts +3 -0
- package/web/lib/router/route-rules.ts +96 -0
- package/web/lib/router/route-store.ts +115 -0
- package/web/lib/router/use-route-classes.ts +15 -0
- package/web/lib/run/browser.ts +53 -0
- package/web/lib/run/card-terminal.ts +32 -0
- package/web/lib/run/doc.ts +42 -0
- package/web/lib/run/grip.ts +8 -0
- package/web/lib/run/index.ts +19 -0
- package/web/lib/run/kept.ts +58 -0
- package/web/lib/run/layout-store.ts +156 -0
- package/web/lib/run/layout.ts +195 -0
- package/web/lib/run/panel-actions.ts +104 -0
- package/web/lib/run/panel-derive.ts +148 -0
- package/web/lib/run/panel-store.ts +125 -0
- package/web/lib/run/preview.ts +105 -0
- package/web/lib/run/run-actions.ts +118 -0
- package/web/lib/run/run-view-store.ts +134 -0
- package/web/lib/run/term-loader.ts +19 -0
- package/web/lib/run/use-panel-run.ts +125 -0
- package/web/lib/run/use-run-lifecycle.ts +70 -0
- package/web/lib/run/viewer.ts +12 -0
- package/web/lib/run/workspace.ts +281 -0
- package/web/lib/run/ws-actions.ts +293 -0
- package/web/lib/run/ws-derive.ts +50 -0
- package/web/lib/run/ws-draw.ts +102 -0
- package/web/lib/run/ws-store.ts +21 -0
- package/web/lib/run/ws-tabs.ts +125 -0
- package/web/lib/search/index.ts +3 -0
- package/web/lib/search/search-match.ts +48 -0
- package/web/lib/search/search-rows.ts +228 -0
- package/web/lib/search/search.ts +30 -0
- package/web/lib/search/use-search-rows.ts +22 -0
- package/web/lib/server/attention.ts +29 -0
- package/web/lib/server/index.ts +6 -0
- package/web/lib/server/poll-rules.ts +57 -0
- package/web/lib/server/poller.ts +210 -0
- package/web/lib/server/server-store.ts +39 -0
- package/web/lib/server/types.ts +31 -0
- package/web/lib/server/use-server.ts +19 -0
- package/web/lib/settings/agent-favicons.ts +14 -0
- package/web/lib/settings/index.ts +7 -0
- package/web/lib/settings/panel-settings.ts +29 -0
- package/web/lib/settings/settings-actions.ts +357 -0
- package/web/lib/settings/settings-store.ts +114 -0
- package/web/lib/settings/settings.ts +413 -0
- package/web/lib/settings/skill-icons.ts +24 -0
- package/web/lib/settings/update.ts +70 -0
- package/web/lib/shared/data-urls.ts +32 -0
- package/web/lib/shared/index.ts +4 -0
- package/web/lib/shared/use-draft.ts +38 -0
- package/web/lib/shared/use-narrow.ts +11 -0
- package/web/lib/shared/use-pager.ts +24 -0
- package/web/lib/shell/appearance.ts +97 -0
- package/web/lib/shell/help-store.ts +4 -0
- package/web/lib/shell/index.ts +4 -0
- package/web/lib/shell/shell-store.ts +23 -0
- package/web/lib/shell/stored-look.ts +47 -0
- package/web/lib/task/index.ts +7 -0
- package/web/lib/task/task-results.ts +92 -0
- package/web/lib/task/tasks.ts +134 -0
- package/web/lib/task/use-live-frame.ts +85 -0
- package/web/lib/task/use-saved-text.ts +25 -0
- package/web/lib/task/use-task.ts +161 -0
- package/web/lib/task/use-tasks.ts +50 -0
- package/web/{board → lib/task}/zoom.ts +25 -12
- package/web/lib/terminal/hidden-badge.ts +15 -0
- package/web/lib/terminal/index.ts +8 -0
- package/web/lib/terminal/layout.ts +138 -0
- package/web/{term-font.ts → lib/terminal/term-font.ts} +3 -2
- package/web/lib/terminal/terminal-store.ts +65 -0
- package/web/lib/terminal/terms-feed.ts +37 -0
- package/web/lib/terminal/use-arranged.ts +15 -0
- package/web/lib/terminal/use-terminal-keys.ts +37 -0
- package/web/lib/url/index.ts +1 -0
- package/web/lib/url/safe-url.ts +9 -0
- package/web/notebook/notebook.ts +27 -0
- package/web/notebook/notes-lib.ts +3 -0
- package/web/pages/board/App.tsx +76 -0
- package/web/pages/board/header.tsx +83 -0
- package/web/pages/board/help.tsx +59 -0
- package/web/pages/board/host-bridge.ts +94 -0
- package/web/pages/board/host.tsx +19 -0
- package/web/pages/board/keys.ts +112 -0
- package/web/pages/board/live.ts +39 -0
- package/web/pages/board/main.ts +32 -0
- package/web/pages/board/pages.tsx +86 -0
- package/web/pages/board/panel.tsx +157 -0
- package/web/pages/board/portal.tsx +39 -0
- package/web/pages/board/use-boot.ts +13 -0
- package/web/pages/board/views.ts +63 -0
- package/web/pages/board-page.tsx +62 -0
- package/web/pages/home-page.tsx +127 -0
- package/web/pages/icebox-page.tsx +440 -0
- package/web/pages/notebook/App.tsx +35 -0
- package/web/pages/notebook-page.tsx +50 -0
- package/web/pages/popup/App.tsx +207 -0
- package/web/pages/settings-page.tsx +111 -0
- package/web/pages/task-page.tsx +397 -0
- package/web/pages/tasks-page.tsx +151 -0
- package/web/pages/terminal-page.tsx +15 -0
- package/web/popup/popup.ts +7 -0
- package/web/{term.ts → term/term.ts} +48 -20
- package/web/ui/alert-dialog.tsx +39 -0
- package/web/ui/badge.tsx +20 -0
- package/web/ui/button.tsx +37 -0
- package/web/ui/checkbox.tsx +20 -0
- package/web/ui/command.tsx +41 -0
- package/web/ui/dialog.tsx +28 -0
- package/web/ui/dropdown-menu.tsx +54 -0
- package/web/ui/icon.tsx +17 -0
- package/web/ui/index.ts +21 -0
- package/web/ui/input.tsx +9 -0
- package/web/ui/label.tsx +7 -0
- package/web/ui/legacy/board.css +715 -0
- package/web/{notes.html → ui/legacy/notes.css} +23 -157
- package/web/ui/legacy/popup.css +40 -0
- package/web/ui/popover.tsx +28 -0
- package/web/ui/select.tsx +61 -0
- package/web/ui/sheet.tsx +43 -0
- package/web/ui/skeleton.tsx +6 -0
- package/web/ui/sonner.tsx +25 -0
- package/web/ui/spinner.tsx +12 -0
- package/web/ui/switch.tsx +18 -0
- package/web/ui/tabs.tsx +18 -0
- package/web/ui/textarea.tsx +14 -0
- package/web/ui/theme.css +125 -0
- package/web/ui/toggle.tsx +8 -0
- package/web/ui/tooltip.tsx +26 -0
- package/web/{video.ts → video/video.ts} +5 -5
- package/web/board/add-project.ts +0 -147
- package/web/board/agent-favicons.ts +0 -9
- package/web/board/agent-term.ts +0 -51
- package/web/board/annotate-lib.ts +0 -19
- package/web/board/annotate.ts +0 -221
- package/web/board/api.ts +0 -180
- package/web/board/approvals.ts +0 -109
- package/web/board/badge.ts +0 -115
- package/web/board/cards.ts +0 -1080
- package/web/board/chat.ts +0 -128
- package/web/board/context.ts +0 -248
- package/web/board/dictation.ts +0 -343
- package/web/board/dom.ts +0 -132
- package/web/board/drafts.ts +0 -21
- package/web/board/fixes.ts +0 -89
- package/web/board/git.ts +0 -416
- package/web/board/home-ws.ts +0 -266
- package/web/board/home.ts +0 -421
- package/web/board/icebox.ts +0 -1788
- package/web/board/keys.ts +0 -121
- package/web/board/live.ts +0 -87
- package/web/board/main.ts +0 -94
- package/web/board/markdown.ts +0 -210
- package/web/board/onboarding.ts +0 -227
- package/web/board/panel.ts +0 -437
- package/web/board/phone-setup.ts +0 -79
- package/web/board/phone.ts +0 -219
- package/web/board/projects.ts +0 -277
- package/web/board/resources.ts +0 -170
- package/web/board/run-pick.ts +0 -41
- package/web/board/run-view.ts +0 -1316
- package/web/board/search-match.ts +0 -20
- package/web/board/search.ts +0 -330
- package/web/board/settings-accounts.ts +0 -76
- package/web/board/settings-agents.ts +0 -102
- package/web/board/settings-automations.ts +0 -71
- package/web/board/settings-cleanup.ts +0 -42
- package/web/board/settings-orchestration.ts +0 -32
- package/web/board/settings-pages.ts +0 -62
- package/web/board/settings-skills.ts +0 -103
- package/web/board/settings-voice.ts +0 -28
- package/web/board/settings.ts +0 -490
- package/web/board/store.ts +0 -47
- package/web/board/task-page.ts +0 -628
- package/web/board/task-results.ts +0 -234
- package/web/board/tasks.ts +0 -242
- package/web/board/terms.ts +0 -390
- package/web/board/update.ts +0 -171
- package/web/board/viewer.ts +0 -47
- package/web/board/views.ts +0 -164
- package/web/board/whatsapp-setup.ts +0 -149
- package/web/board/workspace.ts +0 -650
- package/web/board/ws-board-ui.ts +0 -95
- package/web/board/ws-tabs.ts +0 -227
- package/web/board.html +0 -1563
- package/web/board.js +0 -505
- package/web/notebook.js +0 -519
- package/web/notebook.ts +0 -1254
- package/web/popup.html +0 -141
- package/web/video.js +0 -575
- /package/web/{term.css → dist/term.css} +0 -0
- /package/web/{board/term-sessions.ts → lib/terminal/sessions.ts} +0 -0
- /package/web/{board/terminal-viewport.ts → lib/terminal/viewport.ts} +0 -0
- /package/web/{term-paste.ts → term/term-paste.ts} +0 -0
package/web/board/run-view.ts
DELETED
|
@@ -1,1316 +0,0 @@
|
|
|
1
|
-
// The workspace centre (?view=ws&dir=&ws=; a run's or task's old address resolves to its
|
|
2
|
-
// workspace and picks that run in the panel): a tab bar over one folder holding terminals and the
|
|
3
|
-
// Browser, never runs. Agent terminals are tabs, named by stage for a run's ("Build · Claude"),
|
|
4
|
-
// beside shells started with POST /shell {ws}, the project's localhost, the Preview, project
|
|
5
|
-
// notes and History (finished runs, read-only in the panel). The run panel (#panel, drawn by
|
|
6
|
-
// panel.ts) docks on the right and shows one run, chosen in its picker (run-pick.ts); the centre
|
|
7
|
-
// never follows it. A workspace with no tab opens a shell in its folder. Terminal tabs are
|
|
8
|
-
// kzTerm mounts on /pty that live as long as their tab, so a tab switch or a /state tick never
|
|
9
|
-
// reconnects them. Split right or down shows a second tab beside the first, sized with the
|
|
10
|
-
// Terminal page's handles.
|
|
11
|
-
import { pick } from "./projects.ts";
|
|
12
|
-
import { store } from "./store.ts";
|
|
13
|
-
import { toast } from "./toast.ts";
|
|
14
|
-
import { $, html, ico, raw, toggleSwitch } from "./dom.ts";
|
|
15
|
-
import { key } from "./cards.ts";
|
|
16
|
-
import { open } from "./panel.ts";
|
|
17
|
-
import { termLoad } from "./agent-term.ts";
|
|
18
|
-
import { load, post } from "./api.ts";
|
|
19
|
-
import { attach, md, preview } from "./markdown.ts";
|
|
20
|
-
import { layout } from "./terms.ts";
|
|
21
|
-
import { cardHref, markCurrent, railData, stateOf, titleOf, wsHref, wsOfCard } from "./workspace.ts";
|
|
22
|
-
import { type Node, type Box, awaiting, chosen, devUrl, finished, historyOf, leaves, liveIn, loopbackUrl, migrate, nearestPane, newRun, pickable, previewIn, previewOpens, prune, reviewing, stageTabs, toOpen, wsKey } from "./ws-tabs.ts";
|
|
23
|
-
import { drawPick, hidePick, initPick, setOpen } from "./run-pick.ts";
|
|
24
|
-
import { age } from "./labels.ts";
|
|
25
|
-
import { go } from "./views.ts";
|
|
26
|
-
import { isPhone } from "./phone.ts";
|
|
27
|
-
import { annotator } from "./annotate.ts";
|
|
28
|
-
|
|
29
|
-
type Tab = { id: string; kind: "agent" | "shell" | "local" | "preview" | "note" | "wait" | "history"; title: string; key?: string; note?: string; agent?: string };
|
|
30
|
-
// Per workspace: the extra items opened (localhost, preview, notes, History),
|
|
31
|
-
// tabs closed, and the screens. A screen is one tab of the bar: one or more items side by
|
|
32
|
-
// side or stacked.
|
|
33
|
-
type Screen = { id: string; tree: Node; focus: string };
|
|
34
|
-
// tmux: the focused pane splits in two, the new item right of or under it.
|
|
35
|
-
function splitAt(n: Node, at: string, add: string, dir: "cols" | "rows", before = false): Node {
|
|
36
|
-
if (typeof n === "string") return n === at ? { dir, kids: before ? [add, n] : [n, add], sizes: [1, 1] } : n;
|
|
37
|
-
return { ...n, kids: n.kids.map((k) => splitAt(k, at, add, dir, before)) };
|
|
38
|
-
}
|
|
39
|
-
// seen: the runs that already opened the Browser on their Preview, so a run does it once.
|
|
40
|
-
type Saved = { tabs: Tab[]; hidden: string[]; hb?: Record<string, number>; screens: Screen[]; on: string | null; seen?: string[] };
|
|
41
|
-
const ALL: Record<string, Saved> = (() => {
|
|
42
|
-
try {
|
|
43
|
-
return JSON.parse(localStorage.getItem("kz-runtabs") || "{}");
|
|
44
|
-
} catch {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
48
|
-
const save = () => {
|
|
49
|
-
try {
|
|
50
|
-
localStorage.setItem("kz-runtabs", JSON.stringify(ALL));
|
|
51
|
-
} catch {}
|
|
52
|
-
};
|
|
53
|
-
// The workspace shown, and the card whose panel is up (the picker's).
|
|
54
|
-
let ctx: { dir: string; ws: string; k: string } | null = null;
|
|
55
|
-
let card: any = null;
|
|
56
|
-
let shells: any[] = [];
|
|
57
|
-
let noPty = false;
|
|
58
|
-
// Every agent installed for this project (from /agents), each offered as a bare session.
|
|
59
|
-
let agents: { name: string; cmd: string; yolo?: boolean; bypassDefault?: boolean }[] = [];
|
|
60
|
-
let defAgent = "";
|
|
61
|
-
// The agents with their own mark in the sprite; the rest show the generic one.
|
|
62
|
-
const MARKS = ["claude", "codex", "gemini"];
|
|
63
|
-
// Tab id -> its pane, and for a terminal the function that unmounts it.
|
|
64
|
-
const panes = new Map<string, { el: HTMLElement; off: (() => void) | null }>();
|
|
65
|
-
const byKey = (k: string) => store.S.cards.find((x) => key(x) === k);
|
|
66
|
-
const saved = (): Saved => {
|
|
67
|
-
const s = (ALL[ctx!.k] ||= { tabs: [], hidden: [], screens: [], on: null });
|
|
68
|
-
// Layouts saved while runs were tabs: those tabs are gone, the panel picks runs now.
|
|
69
|
-
s.tabs = s.tabs.filter((t: any) => t.kind !== "run");
|
|
70
|
-
s.hidden = s.hidden.filter((h) => !h.startsWith("rn:"));
|
|
71
|
-
if (!Array.isArray(s.screens) || s.screens.some((sc: any) => !sc.tree)) (s.screens = []), delete (s as any).split; // older saves
|
|
72
|
-
return s;
|
|
73
|
-
};
|
|
74
|
-
// Where the next item goes: a new screen (null), or beside/below the items of a screen.
|
|
75
|
-
let target: { screen: string; dir: "cols" | "rows" } | null = null;
|
|
76
|
-
// Every item sits in exactly one screen; a new one goes to `target` or its own screen.
|
|
77
|
-
function screens(): Screen[] {
|
|
78
|
-
const s = saved(),
|
|
79
|
-
ids = tabs().map((t) => t.id);
|
|
80
|
-
// In place: the panes on screen hold these objects, and a gutter drag writes its sizes into them.
|
|
81
|
-
s.screens = s.screens.filter((sc) => {
|
|
82
|
-
const tree = prune(sc.tree, (id) => ids.includes(id));
|
|
83
|
-
if (!tree) return false;
|
|
84
|
-
sc.tree = tree;
|
|
85
|
-
if (!leaves(tree).includes(sc.focus)) sc.focus = leaves(tree)[0];
|
|
86
|
-
return true;
|
|
87
|
-
});
|
|
88
|
-
for (const id of ids)
|
|
89
|
-
if (!s.screens.some((sc) => leaves(sc.tree).includes(id))) {
|
|
90
|
-
const into = target && s.screens.find((sc) => sc.id === target!.screen);
|
|
91
|
-
if (into) (into.tree = splitAt(into.tree, into.focus, id, target!.dir)), (into.focus = id), (s.on = into.id);
|
|
92
|
-
else s.screens.push({ id: "s" + Date.now().toString(36) + Math.random().toString(36).slice(2, 5), tree: id, focus: id });
|
|
93
|
-
target = null;
|
|
94
|
-
}
|
|
95
|
-
if (!s.screens.some((sc) => sc.id === s.on)) s.on = s.screens[0]?.id ?? null;
|
|
96
|
-
return s.screens;
|
|
97
|
-
}
|
|
98
|
-
const loopback = /^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname);
|
|
99
|
-
|
|
100
|
-
const AGENTS = ["claude", "codex", "gemini", "agy", "opencode", "cursor"];
|
|
101
|
-
const wsCards = () => (ctx ? liveIn(store.S.cards, ctx.dir, ctx.ws, wsOfCard) : []);
|
|
102
|
-
|
|
103
|
-
function tabs(): Tab[] {
|
|
104
|
-
const s = saved(),
|
|
105
|
-
out: Tab[] = [];
|
|
106
|
-
const named = (a?: string) => agents.find((x) => x.cmd === a)?.name ?? "Agent";
|
|
107
|
-
const live = wsCards(),
|
|
108
|
-
liveKeys = new Set(live.map(key));
|
|
109
|
-
// A finished run's agent that is still open keeps its tab, as the sidebar keeps it.
|
|
110
|
-
const open = store.S.cards.filter((c) => c.state === ctx!.dir && wsOfCard(c) === ctx!.ws && !liveKeys.has(key(c)) && c.pty?.alive);
|
|
111
|
-
// Each live run's terminals: its stage terminals ("Build · Claude"), other sessions, shells, the waiting note.
|
|
112
|
-
for (const c of [...live, ...open]) {
|
|
113
|
-
const k = key(c),
|
|
114
|
-
runAgent = AGENTS.find((a) => a === c.pty?.agent) ?? AGENTS.find((a) => c.tags?.includes(a)) ?? undefined;
|
|
115
|
-
for (const t of stageTabs(c, named(runAgent))) out.push({ id: "agent:" + t.key, kind: "agent", agent: runAgent, title: t.title, key: t.key });
|
|
116
|
-
for (const sh of shells.filter((x) => x.run === k)) out.push({ id: "sh:" + sh.key, kind: sh.agent ? "agent" : "shell", agent: sh.agent || undefined, title: sh.title, key: sh.key });
|
|
117
|
-
// The run's own session is running in another terminal: a tab that says so.
|
|
118
|
-
if (elsewhere.has(k)) out.push({ id: "wait:" + k, kind: "wait", agent: "claude", title: named("claude") });
|
|
119
|
-
}
|
|
120
|
-
// The workspace's own shells and agents, and those of its finished runs.
|
|
121
|
-
const owned = new Set(store.S.cards.filter((c) => c.state === ctx!.dir && wsOfCard(c) === ctx!.ws).map(key));
|
|
122
|
-
for (const sh of shells.filter((x) => x.run === ctx!.k || (owned.has(x.run) && !liveKeys.has(x.run))))
|
|
123
|
-
out.push({ id: "sh:" + sh.key, kind: sh.agent ? "agent" : "shell", agent: sh.agent || undefined, title: sh.title, key: sh.key });
|
|
124
|
-
// Opened by hand: History, localhost, Preview, notes.
|
|
125
|
-
const mine = s.tabs.map((t) => (t.kind === "local" ? { ...t, title: "Browser" } : t)); // "local" was saved before the rename
|
|
126
|
-
// A closed agent tab stays hidden only for that agent: one started again under the same key (a resume) is a new
|
|
127
|
-
// agent (born differs) and the sidebar lists it, so its tab comes back.
|
|
128
|
-
for (const a of store.S.agents ?? []) {
|
|
129
|
-
const id = "agent:" + a.key;
|
|
130
|
-
if (s.hb && id in s.hb && s.hb[id] !== (a.born ?? 0)) (s.hidden = s.hidden.filter((h) => h !== id)), delete s.hb[id], save();
|
|
131
|
-
}
|
|
132
|
-
const all = [...out.filter((t) => !s.hidden.includes(t.id)), ...mine];
|
|
133
|
-
return all.filter((t, i) => all.findIndex((x) => x.id === t.id) === i);
|
|
134
|
-
}
|
|
135
|
-
// An agent's tab shows the agent's own mark when the sprite has one.
|
|
136
|
-
const icon = (t: Tab) =>
|
|
137
|
-
t.agent && MARKS.includes(t.agent) ? raw(`<svg><use href="#i-${t.agent}"/></svg>`) : ico({ agent: "ai", shell: "term", local: "link", preview: "eye", note: "note", wait: "ai", history: "note" }[t.kind]);
|
|
138
|
-
const elsewhere = new Set<string>();
|
|
139
|
-
|
|
140
|
-
let switched: string | null = null; // the project a deep link last switched the board to
|
|
141
|
-
const none = (t: string) => void ($("rtabs").innerHTML = String(html`<span class="rnone">${t}</span>`));
|
|
142
|
-
// Called by go("run") and on every /state: draws the tab strip and keeps the panes.
|
|
143
|
-
export async function showRunView(nav = false) {
|
|
144
|
-
const p = new URLSearchParams(location.search),
|
|
145
|
-
dir = p.get("dir"),
|
|
146
|
-
id = p.get("id"),
|
|
147
|
-
task = p.get("idea");
|
|
148
|
-
let ws = p.get("ws"),
|
|
149
|
-
want: any = null; // the card the address names, whose tab is selected
|
|
150
|
-
// A project this board is not showing: a deep link names its project, switched to once, as a rail click does.
|
|
151
|
-
const away = async () => {
|
|
152
|
-
if (store.all || !dir || dir === store.dir || dir === switched) return false;
|
|
153
|
-
switched = dir;
|
|
154
|
-
await pick(dir).catch(() => {});
|
|
155
|
-
return true;
|
|
156
|
-
};
|
|
157
|
-
if (p.get("view") === "ws" && ws) {
|
|
158
|
-
if (await away()) return showRunView(nav);
|
|
159
|
-
} else {
|
|
160
|
-
const find = (cs) => cs.find((x) => x.state === dir && (id ? x.kind === "run" && x.id === id : x.kind === "idea" && x.text === task));
|
|
161
|
-
const c = find(store.S.cards);
|
|
162
|
-
// A launched task becomes a run: its agent session moves to the run's card, and the view follows.
|
|
163
|
-
const pk = task && (c ?? card)?.kind === "idea" && (c ?? card)?.pty?.key;
|
|
164
|
-
const run = pk && store.S.cards.find((x) => x.kind === "run" && x.state === dir && (x.pty?.key === pk || x.pty?.all?.includes(pk)));
|
|
165
|
-
if (run) {
|
|
166
|
-
history.replaceState(null, "", cardHref(run));
|
|
167
|
-
markCurrent();
|
|
168
|
-
return showRunView(nav);
|
|
169
|
-
}
|
|
170
|
-
if (!c) {
|
|
171
|
-
if (await away()) return showRunView(nav);
|
|
172
|
-
if (!store.all && find(railData().cards)) location.href = "/?all=1&" + p.toString();
|
|
173
|
-
else (stopPanes(), (ctx = card = null), none(`That ${id ? "run" : "idea"} was not found.`));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
want = c;
|
|
177
|
-
ws = wsOfCard(c);
|
|
178
|
-
}
|
|
179
|
-
if (!dir || !ws) return void (stopPanes(), (ctx = card = null), none("That workspace was not found."));
|
|
180
|
-
const k = wsKey(dir, ws);
|
|
181
|
-
const fresh = ctx?.k !== k;
|
|
182
|
-
// Each workspace has its own centre: switching unmounts this one's panes (its shells keep running on the server).
|
|
183
|
-
if (fresh) (stopPanes(), (card = null), (ctx = { dir, ws, k }));
|
|
184
|
-
if (fresh && !was.has(k)) was.set(k, new Set(mineNow().filter(reviewing).map(key))); // what is already in review does not open the Browser
|
|
185
|
-
if (fresh) seenRuns.set(k, new Set(mineNow().map(key))); // what is here on arrival is not new
|
|
186
|
-
if (fresh) previewAt.delete(k); // nor is a preview: arriving only records it
|
|
187
|
-
// The header titles a phone's workspace: the run, else the branch.
|
|
188
|
-
const w = railData().projects?.find((x) => x.dir === dir)?.workspaces?.find((x) => x.path === ws);
|
|
189
|
-
document.querySelector(".hdr h1")!.textContent = want ? titleOf(want) : w?.branch || ws.split(/[\\/]/).pop() || "Workspace";
|
|
190
|
-
// Layouts saved per run before workspaces move to their workspace; keys no card owns stay.
|
|
191
|
-
if (migrate(ALL, store.S.cards, key, wsOfCard)) save();
|
|
192
|
-
try {
|
|
193
|
-
const r = await fetch("/shells?dir=" + encodeURIComponent(dir));
|
|
194
|
-
shells = r.ok ? await r.json() : [];
|
|
195
|
-
} catch {}
|
|
196
|
-
if (fresh) {
|
|
197
|
-
try {
|
|
198
|
-
const d = await (await fetch("/agents?dir=" + encodeURIComponent(dir))).json();
|
|
199
|
-
agents = d.agents ?? [];
|
|
200
|
-
defAgent = d.default ?? "";
|
|
201
|
-
} catch {}
|
|
202
|
-
}
|
|
203
|
-
if (ctx?.k !== k) return;
|
|
204
|
-
// Every navigation (a notification, a Board card, a link) picks the card's run in the panel, even for an address already open: a finished run opens read-only.
|
|
205
|
-
// A fresh visit forgets the old pick (waiting first again); one made during the visit stays.
|
|
206
|
-
if (fresh) picked.delete(k);
|
|
207
|
-
if (want?.kind === "run" && (nav || fresh)) picked.set(k, key(want));
|
|
208
|
-
// A workspace with nothing open starts a shell in its folder (no agent, no run). A live run whose own Claude
|
|
209
|
-
// session is not open anywhere on the board is resumed here, once per visit.
|
|
210
|
-
if (!noPty) {
|
|
211
|
-
if (!tabs().length && !autoShell.has(k)) return void (autoShell.add(k), newPty());
|
|
212
|
-
// Not while a launch from the board is coming up: its terminal is not tied to the new run card yet, and
|
|
213
|
-
// resuming the run here would open a second agent on the same session beside it (the stray "Agent" tab).
|
|
214
|
-
const launching = !!store.wantPty && Date.now() - store.wantPty.at < 20_000;
|
|
215
|
-
if (want && want.kind === "run" && !finished(want) && !want.pty && !launching && !shells.some((x) => x.run === key(want)) && !autoShell.has(key(want))) {
|
|
216
|
-
autoShell.add(key(want));
|
|
217
|
-
void openAgent(want, false, false);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (!showTerm()) draw();
|
|
221
|
-
}
|
|
222
|
-
// The terminal the sidebar asked for, selected once the workspace's tabs are known.
|
|
223
|
-
let wantTerm: string | null = null;
|
|
224
|
-
function showTerm() {
|
|
225
|
-
// A launch from the board names its terminal (store.wantPty): it is selected once its tab exists,
|
|
226
|
-
// and the ask lapses after a while so a launch that never came up cannot pull focus later.
|
|
227
|
-
const w = store.wantPty && Date.now() - store.wantPty.at < 20_000 ? store.wantPty.key : null;
|
|
228
|
-
if (store.wantPty && !w) store.wantPty = null;
|
|
229
|
-
// Asked for by name (the sidebar's mark, a launch): shown even if its tab was closed before.
|
|
230
|
-
const want = wantTerm || w, s = saved();
|
|
231
|
-
if (want) s.hidden = s.hidden.filter((h) => h !== "agent:" + want && h !== "sh:" + want);
|
|
232
|
-
const t = tabs().find((x) => x.key === want);
|
|
233
|
-
wantTerm = null;
|
|
234
|
-
if (t && store.wantPty?.key === t.key) store.wantPty = null;
|
|
235
|
-
return !!t && (show(t.id), true);
|
|
236
|
-
}
|
|
237
|
-
const autoShell = new Set<string>();
|
|
238
|
-
|
|
239
|
-
function draw() {
|
|
240
|
-
const s = saved(),
|
|
241
|
-
ts = tabs(),
|
|
242
|
-
scs = screens(),
|
|
243
|
-
cur = scs.find((sc) => sc.id === s.on);
|
|
244
|
-
const item = (id: string) => ts.find((t) => t.id === id)!;
|
|
245
|
-
const PTY = !noPty;
|
|
246
|
-
const mark = (a) => (MARKS.includes(a.cmd) ? raw(`<svg><use href="#i-${a.cmd}"/></svg>`) : ico("ai"));
|
|
247
|
-
const dflt = agents.find((a) => a.cmd === defAgent);
|
|
248
|
-
// Agents first, the default on top, then the tools.
|
|
249
|
-
const agentRow = (a) => html`<button data-n="agent:${a.cmd}">${mark(a)}<span>${a.name}<small>${a === dflt ? "default agent, in this folder" : "the agent alone, no run"}</small></span></button>`;
|
|
250
|
-
// Bypass for this launch, on top of the agents. It starts from Settings → Agents → Permissions (the default agent's) and resets each time the menu opens.
|
|
251
|
-
const yolo = agents.some((a) => a.yolo) ? html`<label class="agent-yolo"><span>Bypass permissions<small>run commands without asking</small></span>${toggleSwitch(!!(dflt ?? agents[0]).bypassDefault, { sm: true, box: true, attrs: { "aria-label": "Bypass permissions" } })}</label>` : "";
|
|
252
|
-
const menu = html`<div class="menu-pop">${PTY && agents.length ? html`${yolo}${agentRow(dflt ?? agents[0])}${agents.filter((a) => a !== (dflt ?? agents[0])).map(agentRow)}<hr>` : ""}${PTY ? html`<button data-n="shell">${ico("term")}<span>Shell<small>a terminal in this folder</small></span></button>` : ""}<button data-n="local">${ico("link")}<span>Browser<small>localhost pages, e.g. the dev server</small></span></button><button data-n="preview">${ico("eye")}<span>Preview<small>the run's Preview</small></span></button><button data-n="history">${ico("note")}<span>History<small>finished runs in this workspace</small></span></button></div>`;
|
|
253
|
-
$("rtabs").innerHTML = String(
|
|
254
|
-
html`${scs.map((sc) => {
|
|
255
|
-
const ids = leaves(sc.tree),
|
|
256
|
-
first = item(ids[0]),
|
|
257
|
-
title = ids.map((id) => item(id).title).join(" + ");
|
|
258
|
-
return html`<button class="rtab${sc.id === s.on ? " on" : ""}" data-t="${sc.id}" draggable="true" title="${title}">${icon(first)}<span>${title}</span><i data-xs="${sc.id}" role="button" aria-label="Close ${title}" title="Close tab">×</i></button>`;
|
|
259
|
-
})}<details class="radd" data-mode="tab"><summary class="ib xs" title="New tab" aria-label="New tab">${ico("plus")}</summary>${menu}</details><span class="sp"></span><button type="button" class="ib xs" data-pv title="Run app: start the dev server if it is off and open the app" aria-label="Run app">${ico("play")}</button>${cur ? html`<details class="radd rsplit" data-mode="cols"><summary class="ib xs" title="Split right: add to this tab" aria-label="Split right">${ico("lcols")}</summary>${menu}</details><details class="radd rsplit" data-mode="rows"><summary class="ib xs" title="Split down: add to this tab" aria-label="Split down">${ico("lrows")}</summary>${menu}</details>` : ""}`,
|
|
260
|
-
);
|
|
261
|
-
$("rside").setAttribute("aria-pressed", String(document.body.classList.contains("rflip")));
|
|
262
|
-
$("rtabs").querySelector(".rtab.on")?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
263
|
-
// Panes: made once per item, kept (hidden) while it is open, so terminals never reconnect.
|
|
264
|
-
const box = $("rpanes");
|
|
265
|
-
for (const [id, p] of panes)
|
|
266
|
-
if (!ts.some((t) => t.id === id)) {
|
|
267
|
-
p.off?.();
|
|
268
|
-
p.el.remove();
|
|
269
|
-
panes.delete(id);
|
|
270
|
-
}
|
|
271
|
-
for (const t of ts) if (!panes.has(t.id)) makePane(t);
|
|
272
|
-
const shown = cur ? leaves(cur.tree) : [];
|
|
273
|
-
for (const [id, p] of panes) {
|
|
274
|
-
p.el.hidden = !shown.includes(id);
|
|
275
|
-
p.el.classList.toggle("split", shown.length > 1);
|
|
276
|
-
p.el.classList.toggle("focus", shown.length > 1 && id === cur?.focus);
|
|
277
|
-
p.el.querySelector(".ph span")!.textContent = item(id)?.title ?? "";
|
|
278
|
-
if (item(id)?.kind === "history") fillHistory(p.el);
|
|
279
|
-
}
|
|
280
|
-
// The tree is rebuilt only when it changes: moving a pane in the DOM reloads its frame.
|
|
281
|
-
const sig = cur ? cur.id + JSON.stringify(cur.tree) : "";
|
|
282
|
-
if (sig !== shownSig) {
|
|
283
|
-
shownSig = sig;
|
|
284
|
-
for (const [, p] of panes) if (p.el.parentElement !== box) box.append(p.el);
|
|
285
|
-
box.querySelector(".rtree")?.remove();
|
|
286
|
-
if (cur) box.prepend(build(cur.tree, cur));
|
|
287
|
-
}
|
|
288
|
-
// One empty note at most: every draw used to append another.
|
|
289
|
-
box.querySelector(".rempty")?.remove();
|
|
290
|
-
if (!scs.length) box.insertAdjacentHTML("beforeend", String(html`<div class="empty rempty"><b>No tabs open</b><p>Open an agent, a shell, the project's localhost or the Preview with +.</p></div>`));
|
|
291
|
-
mountPanel();
|
|
292
|
-
wire();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// The run panel (#panel) stays docked on the right of the centre and shows one run: the one picked
|
|
296
|
-
// in its header (run-pick.ts), first the run waiting on you, else the newest. A pick is sticky; a
|
|
297
|
-
// run that starts waiting later does not replace it: the picker's trigger and, with the panel
|
|
298
|
-
// collapsed, the panel button show a dot. Only a run created during the visit takes the pick
|
|
299
|
-
// (followNew). With no run the panel is parked.
|
|
300
|
-
const picked = new Map<string, string>();
|
|
301
|
-
// Every card seen in the workspace this visit. It only grows, so a restored run or a /state tick
|
|
302
|
-
// missing cards never reads as new.
|
|
303
|
-
const seenRuns = new Map<string, Set<string>>();
|
|
304
|
-
function followNew() {
|
|
305
|
-
const seen = ctx && seenRuns.get(ctx.k);
|
|
306
|
-
if (!seen) return;
|
|
307
|
-
const c = newRun(pickable(store.S.cards, ctx!.dir, ctx!.ws, wsOfCard), seen, key);
|
|
308
|
-
for (const m of mineNow()) seen.add(key(m));
|
|
309
|
-
if (c) picked.set(ctx!.k, key(c));
|
|
310
|
-
}
|
|
311
|
-
let pickOpen = false;
|
|
312
|
-
// Shows a run in the panel (a picker row, a History row); the centre stays as it is.
|
|
313
|
-
const pickRun = (k: string) => (picked.set(ctx!.k, k), draw()); // the sidebar count asked for the picker dropped down
|
|
314
|
-
function mountPanel() {
|
|
315
|
-
const live = pickable(store.S.cards, ctx!.dir, ctx!.ws, wsOfCard),
|
|
316
|
-
hist = historyOf(store.S.cards, ctx!.dir, ctx!.ws, wsOfCard),
|
|
317
|
-
c = chosen(live, hist, picked.get(ctx!.k), key);
|
|
318
|
-
$("panel").classList.toggle("parked", !c);
|
|
319
|
-
$("rside").hidden = !c;
|
|
320
|
-
// Collapsed (a phone: sheet down) and a run waits: a dot on the panel button, no pop-open.
|
|
321
|
-
$("rside").toggleAttribute("data-dot", document.body.classList.contains("rflip") !== isPhone() && live.some(awaiting));
|
|
322
|
-
if (!c) return void ((card = null), (pickOpen = false), hidePick());
|
|
323
|
-
picked.set(ctx!.k, key(c));
|
|
324
|
-
$("panel").classList.toggle("ro", hist.includes(c)); // a run from History: no edit buttons (the commit and push ones stay)
|
|
325
|
-
card = c;
|
|
326
|
-
drawPick(live, hist, c);
|
|
327
|
-
if (store.openKey !== key(c)) void open(c, false);
|
|
328
|
-
if (pickOpen) (setOpen(true), (pickOpen = false));
|
|
329
|
-
}
|
|
330
|
-
// History: the workspace's finished runs, newest first; one opens read-only.
|
|
331
|
-
function fillHistory(el: HTMLElement) {
|
|
332
|
-
const list = historyOf(store.S.cards, ctx!.dir, ctx!.ws, wsOfCard),
|
|
333
|
-
now = Date.now();
|
|
334
|
-
const box = el.querySelector(".rhist")!;
|
|
335
|
-
box.innerHTML = String(
|
|
336
|
-
list.length
|
|
337
|
-
? html`${list.map((c) => html`<button class="rrow" data-hist="${key(c)}"><span class="si ${stateOf(c)}"></span><b>${titleOf(c)}</b><small>${c.status} · ${age(c.moved ?? now, now)} ago</small></button>`)}`
|
|
338
|
-
: html`<p class="rnone">No finished runs in this workspace yet.</p>`,
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
let shownSig = "";
|
|
343
|
-
// Moves an item out of its tab into another one (split beside a pane there, or next to its
|
|
344
|
-
// focused pane), or into a tab of its own (to = null). Terminals keep running; frames reload.
|
|
345
|
-
function moveItem(id: string, to: string | null, at?: { pane: string; dir: "cols" | "rows"; before: boolean }) {
|
|
346
|
-
const s = saved();
|
|
347
|
-
if (at?.pane === id) return;
|
|
348
|
-
// Dropped on the tab it is already in, with no pane edge to split at: nothing to do.
|
|
349
|
-
if (!at && to && s.screens.find((sc) => sc.id === to && leaves(sc.tree).includes(id))) return;
|
|
350
|
-
for (const sc of s.screens) {
|
|
351
|
-
sc.tree = prune(sc.tree, (x) => x !== id) ?? "";
|
|
352
|
-
if (sc.tree !== "" && !leaves(sc.tree).includes(sc.focus)) sc.focus = leaves(sc.tree)[0];
|
|
353
|
-
}
|
|
354
|
-
s.screens = s.screens.filter((sc) => sc.tree !== "");
|
|
355
|
-
const dest = to && s.screens.find((sc) => sc.id === to);
|
|
356
|
-
if (dest) {
|
|
357
|
-
dest.tree = splitAt(dest.tree, at?.pane ?? dest.focus, id, at?.dir ?? "cols", at?.before ?? false);
|
|
358
|
-
dest.focus = id;
|
|
359
|
-
s.on = dest.id;
|
|
360
|
-
} else {
|
|
361
|
-
const sid = "s" + Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
|
|
362
|
-
s.screens.push({ id: sid, tree: id, focus: id });
|
|
363
|
-
s.on = sid;
|
|
364
|
-
}
|
|
365
|
-
save();
|
|
366
|
-
draw();
|
|
367
|
-
}
|
|
368
|
-
let dragging: string | null = null;
|
|
369
|
-
// One node of the layout tree as DOM: a pane, or a flex row/column of its children with a
|
|
370
|
-
// draggable gutter between each pair (sizes saved on the node).
|
|
371
|
-
function build(n: Node, sc: Screen): HTMLElement {
|
|
372
|
-
if (typeof n === "string") return panes.get(n)!.el;
|
|
373
|
-
const el = document.createElement("div");
|
|
374
|
-
el.className = "rtree " + n.dir;
|
|
375
|
-
n.kids.forEach((k, i) => {
|
|
376
|
-
if (i) {
|
|
377
|
-
const g = document.createElement("div");
|
|
378
|
-
g.className = "rgut";
|
|
379
|
-
g.onpointerdown = (e) => {
|
|
380
|
-
e.preventDefault();
|
|
381
|
-
const a = el.children[2 * i - 2] as HTMLElement,
|
|
382
|
-
b = el.children[2 * i] as HTMLElement,
|
|
383
|
-
horiz = n.dir === "cols",
|
|
384
|
-
ra = a.getBoundingClientRect(),
|
|
385
|
-
rb = b.getBoundingClientRect(),
|
|
386
|
-
total = horiz ? ra.width + rb.width : ra.height + rb.height,
|
|
387
|
-
sum = n.sizes[i - 1] + n.sizes[i],
|
|
388
|
-
start = horiz ? ra.left : ra.top;
|
|
389
|
-
g.setPointerCapture(e.pointerId);
|
|
390
|
-
// A frame under the pointer (the Browser, Preview) takes the moves for itself: frames ignore it while dragging.
|
|
391
|
-
document.body.classList.add("rdrag");
|
|
392
|
-
g.onpointermove = (m) => {
|
|
393
|
-
const f = Math.min(0.9, Math.max(0.1, ((horiz ? m.clientX : m.clientY) - start) / total));
|
|
394
|
-
n.sizes[i - 1] = sum * f;
|
|
395
|
-
n.sizes[i] = sum * (1 - f);
|
|
396
|
-
a.style.flexGrow = String(n.sizes[i - 1]);
|
|
397
|
-
b.style.flexGrow = String(n.sizes[i]);
|
|
398
|
-
};
|
|
399
|
-
g.onpointerup = g.onlostpointercapture = () => {
|
|
400
|
-
if (!g.onpointermove) return;
|
|
401
|
-
document.body.classList.remove("rdrag");
|
|
402
|
-
g.onpointermove = g.onpointerup = g.onlostpointercapture = null;
|
|
403
|
-
shownSig = sc.id + JSON.stringify(sc.tree);
|
|
404
|
-
save();
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
el.append(g);
|
|
408
|
-
}
|
|
409
|
-
const c = build(k, sc);
|
|
410
|
-
c.style.flex = `${n.sizes[i] ?? 1} 1 0`;
|
|
411
|
-
el.append(c);
|
|
412
|
-
});
|
|
413
|
-
return el;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
function makePane(t: Tab) {
|
|
417
|
-
const el = document.createElement("section");
|
|
418
|
-
el.className = "rpane";
|
|
419
|
-
el.dataset.t = t.id;
|
|
420
|
-
// The header is the handle: drag it onto a tab, onto + (a new tab) or onto a pane's edge;
|
|
421
|
-
// ⋯ does the same from a menu. × closes the item.
|
|
422
|
-
el.innerHTML = String(html`<header class="ph" draggable="true"><span>${t.title}</span><details class="pmove"><summary title="Move to another tab" aria-label="Move ${t.title}">⋯</summary><div class="menu-pop"></div></details><button data-x="${t.id}" title="Close" aria-label="Close ${t.title}">×</button></header>`);
|
|
423
|
-
const p = { el, off: null as null | (() => void) };
|
|
424
|
-
panes.set(t.id, p);
|
|
425
|
-
$("rpanes").append(el);
|
|
426
|
-
if (t.kind === "history") {
|
|
427
|
-
el.insertAdjacentHTML("beforeend", String(html`<div class="rhist md"></div>`));
|
|
428
|
-
fillHistory(el);
|
|
429
|
-
} else if (t.kind === "agent" || t.kind === "shell") {
|
|
430
|
-
const term = document.createElement("div");
|
|
431
|
-
term.className = "term";
|
|
432
|
-
el.append(term);
|
|
433
|
-
termLoad()
|
|
434
|
-
.then((m) => {
|
|
435
|
-
if (panes.get(t.id) === p) p.off = m(term, t.key, () => load(true));
|
|
436
|
-
})
|
|
437
|
-
.catch(() => (term.textContent = "The terminal could not load."));
|
|
438
|
-
} else if (t.kind === "wait")
|
|
439
|
-
el.insertAdjacentHTML(
|
|
440
|
-
"beforeend",
|
|
441
|
-
String(html`<div class="empty rwait"><b>This run's agent is running in another terminal</b><p>One conversation cannot run in two places. Close it there, then open it here.</p><button type="button" class="rwin" data-b="recheck" data-k="${t.id.slice(5)}">${ico("refresh")}<span>Open here</span></button></div>`),
|
|
442
|
-
);
|
|
443
|
-
else if (t.kind === "local") browser(el);
|
|
444
|
-
else if (t.kind === "note") el.insertAdjacentHTML("beforeend", String(html`<iframe class="rframe" title="${t.title}" src="/notebook?dir=${encodeURIComponent(ctx!.dir)}¬e=${encodeURIComponent(t.note!)}&embed=1"></iframe>`));
|
|
445
|
-
else void previewPane(el);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// The Browser tab: a URL bar over an iframe. The address is kept per workspace; a run's
|
|
449
|
-
// Preview sets it when the run reaches review (autoBrowse).
|
|
450
|
-
function browser(el: HTMLElement) {
|
|
451
|
-
const k = "kz-browse:" + ctx!.k;
|
|
452
|
-
let url = "http://localhost:3000";
|
|
453
|
-
try {
|
|
454
|
-
url = localStorage.getItem(k) || url;
|
|
455
|
-
} catch {}
|
|
456
|
-
const back: string[] = [],
|
|
457
|
-
fwd: string[] = [];
|
|
458
|
-
el.insertAdjacentHTML(
|
|
459
|
-
"beforeend",
|
|
460
|
-
String(html`<form class="urlbar"><button type="button" data-b="back" title="Back" aria-label="Back">‹</button><button type="button" data-b="fwd" title="Forward" aria-label="Forward">›</button><button type="button" data-b="reload" title="Reload" aria-label="Reload">${ico("refresh")}</button><input class="sel" aria-label="Address" spellcheck="false" value="${url}"><button type="button" class="rwin" data-b="ann" title="Pick elements on this page and send notes to the agent (localhost pages)">${ico("eye")}<span>Annotate</span></button><a class="rwin" data-b="tab" target="_blank" rel="noopener" href="${url}" title="Open in a new browser tab">${ico("popout")}<span>New tab</span></a></form>`),
|
|
461
|
-
);
|
|
462
|
-
const f = el.querySelector("form")!,
|
|
463
|
-
inp = f.querySelector("input")!,
|
|
464
|
-
ext = f.querySelector<HTMLAnchorElement>("a.rwin");
|
|
465
|
-
(el as any).browseTo = (u: string) => go(u);
|
|
466
|
-
// On a phone over the tailnet, localhost is the phone itself: framing it shows nothing useful.
|
|
467
|
-
const local = (u) => /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(u);
|
|
468
|
-
// In the desktop app the page is a <webview> in its own persistent session (desktop/src/browser-pane.ts):
|
|
469
|
-
// a first-party page with its own cookies, as in Orca. An iframe on the board's 127.0.0.1 origin made
|
|
470
|
-
// localhost:8000 third-party, so its Lax session cookie never came back (a login answered 419), and the
|
|
471
|
-
// framing blocks screen capture. Browsers, and an older app without the flag, keep the iframe.
|
|
472
|
-
const web = !!(window as any).kaizenDesktop?.browserPane;
|
|
473
|
-
const frame = document.createElement(web ? "webview" : "iframe") as HTMLIFrameElement;
|
|
474
|
-
frame.className = "rframe";
|
|
475
|
-
frame.title = "Browser";
|
|
476
|
-
if (web) frame.setAttribute("allowpopups", "");
|
|
477
|
-
else {
|
|
478
|
-
// Dev apps run; a framed page cannot navigate the board itself (no allow-top-navigation).
|
|
479
|
-
frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals allow-downloads");
|
|
480
|
-
// Without these the browser blocks microphone, camera and screen capture for the framed page.
|
|
481
|
-
frame.setAttribute("allow", "display-capture; microphone; camera; clipboard-read; clipboard-write; fullscreen");
|
|
482
|
-
}
|
|
483
|
-
const note = document.createElement("p");
|
|
484
|
-
note.className = "rnote";
|
|
485
|
-
const far = "This page is on the computer running kaizen; from this device localhost is the device itself. Use Open in browser on that computer.";
|
|
486
|
-
// The annotator (annotate.ts): its toolbar sits above this row, its notes list beside the frame.
|
|
487
|
-
const row = document.createElement("div");
|
|
488
|
-
row.className = "annrow";
|
|
489
|
-
row.append(frame);
|
|
490
|
-
el.append(row, note);
|
|
491
|
-
const annBtn = f.querySelector<HTMLButtonElement>("[data-b=ann]")!;
|
|
492
|
-
annBtn.hidden = !loopback; // from a phone, localhost is the phone itself
|
|
493
|
-
const ann = annotator({
|
|
494
|
-
host: el, frame, wsKey: ctx!.k, button: annBtn,
|
|
495
|
-
run: () => (card?.id ? { dir: card.state, id: card.id } : null),
|
|
496
|
-
reload: () => go(url, false),
|
|
497
|
-
// The framed page navigated on its own: show its address, do not load it again.
|
|
498
|
-
onLocation: (u) => {
|
|
499
|
-
if (u === url) return;
|
|
500
|
-
back.push(url), (fwd.length = 0);
|
|
501
|
-
url = u;
|
|
502
|
-
inp.value = u;
|
|
503
|
-
if (ext) ext.href = u;
|
|
504
|
-
try { localStorage.setItem(k, u); } catch {}
|
|
505
|
-
},
|
|
506
|
-
});
|
|
507
|
-
const go = (u, push = true) => {
|
|
508
|
-
if (push && url !== u) back.push(url), (fwd.length = 0);
|
|
509
|
-
url = u;
|
|
510
|
-
inp.value = u;
|
|
511
|
-
if (ext) ext.href = u;
|
|
512
|
-
try {
|
|
513
|
-
localStorage.setItem(k, u);
|
|
514
|
-
} catch {}
|
|
515
|
-
const hide = !loopback && local(u);
|
|
516
|
-
frame.hidden = hide;
|
|
517
|
-
note.hidden = !hide;
|
|
518
|
-
note.textContent = far;
|
|
519
|
-
if (hide) return void expose(u);
|
|
520
|
-
// Annotate on: a loopback page is framed through the board's proxy (annotate-proxy.ts), which adds the picker.
|
|
521
|
-
const seq = ++nav;
|
|
522
|
-
void ann.open(u).then((via) => {
|
|
523
|
-
if (seq !== nav) return;
|
|
524
|
-
frame.src = via ?? u;
|
|
525
|
-
if (via || web) return; // a webview is a top-level page: nothing refuses to be framed
|
|
526
|
-
frameCheck(u);
|
|
527
|
-
});
|
|
528
|
-
};
|
|
529
|
-
let nav = 0;
|
|
530
|
-
const frameCheck = (u: string) => {
|
|
531
|
-
// Most public sites refuse to be framed (X-Frame-Options / frame-ancestors), and the
|
|
532
|
-
// browser only shows its own error page. The board asks the site first and says so.
|
|
533
|
-
void fetch("/frameable?url=" + encodeURIComponent(u))
|
|
534
|
-
.then((r) => r.json())
|
|
535
|
-
.then((j) => {
|
|
536
|
-
if (url !== u || j.frameable !== false) return;
|
|
537
|
-
frame.hidden = true;
|
|
538
|
-
frame.removeAttribute("src");
|
|
539
|
-
note.hidden = false;
|
|
540
|
-
// The fallback card: the page refuses to be framed, so offer it outside the board.
|
|
541
|
-
note.textContent = "";
|
|
542
|
-
note.insertAdjacentHTML("beforeend", String(html`<b>This page refuses to be shown inside kaizen</b>${new URL(u).host} sends a header that forbids framing. <a class="rwin" target="_blank" rel="noopener" href="${u}">${ico("popout")}<span>Open in new tab</span></a>${winBtn(u)}`));
|
|
543
|
-
})
|
|
544
|
-
.catch(() => {});
|
|
545
|
-
};
|
|
546
|
-
// On a phone: the board serves that port to the tailnet and the frame opens its tailnet address.
|
|
547
|
-
const expose = (u: string) => {
|
|
548
|
-
note.textContent = "Opening this page for this device…";
|
|
549
|
-
void fetch("/expose", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ url: u }) })
|
|
550
|
-
.then((r) => r.json())
|
|
551
|
-
.then((j) => {
|
|
552
|
-
if (url !== u) return;
|
|
553
|
-
if (!j.ok) return void (note.textContent = `${far} (${j.error})`);
|
|
554
|
-
note.hidden = !j.hint;
|
|
555
|
-
note.textContent = j.hint || "";
|
|
556
|
-
frame.hidden = false;
|
|
557
|
-
frame.src = j.url;
|
|
558
|
-
if (ext) ext.href = j.url;
|
|
559
|
-
})
|
|
560
|
-
.catch(() => url === u && (note.textContent = far));
|
|
561
|
-
};
|
|
562
|
-
f.onsubmit = (e) => {
|
|
563
|
-
e.preventDefault();
|
|
564
|
-
let u = inp.value.trim();
|
|
565
|
-
if (!/^https?:\/\//.test(u)) u = "http://" + u;
|
|
566
|
-
go(u);
|
|
567
|
-
};
|
|
568
|
-
el.onclick = (e) => {
|
|
569
|
-
const b = (e.target as Element).closest<HTMLElement>("[data-b]")?.dataset.b;
|
|
570
|
-
if (b === "win") void openWindow(url);
|
|
571
|
-
else if (b === "ann") ann.toggle();
|
|
572
|
-
else if (b === "reload") go(url, false);
|
|
573
|
-
else if (b === "back" && back.length) fwd.push(url), go(back.pop()!, false);
|
|
574
|
-
else if (b === "fwd" && fwd.length) back.push(url), go(fwd.pop()!, false);
|
|
575
|
-
};
|
|
576
|
-
if (web) {
|
|
577
|
-
// The page navigated on its own (a link, a form, a redirect after login): show its address.
|
|
578
|
-
// Through the annotator's proxy the page reports its address itself (onLocation).
|
|
579
|
-
const nav2 = (e: any) => {
|
|
580
|
-
if (e.isMainFrame === false || ann.proxied() || !/^https?:\/\//.test(e.url) || e.url === url) return;
|
|
581
|
-
back.push(url), (fwd.length = 0);
|
|
582
|
-
url = e.url;
|
|
583
|
-
inp.value = url;
|
|
584
|
-
if (ext) ext.href = url;
|
|
585
|
-
try { localStorage.setItem(k, url); } catch {}
|
|
586
|
-
};
|
|
587
|
-
frame.addEventListener("did-navigate", nav2);
|
|
588
|
-
frame.addEventListener("did-navigate-in-page", nav2);
|
|
589
|
-
}
|
|
590
|
-
go(url, false);
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// A Chromium app window on the board's computer (POST /open-url): for dev servers that
|
|
594
|
-
// refuse to be framed. Only offered when the page itself is on that computer.
|
|
595
|
-
// One labelled button: a Chromium app window on the board's computer, for loopback pages only.
|
|
596
|
-
const winBtn = (u: string) =>
|
|
597
|
-
loopback && loopbackUrl(u)
|
|
598
|
-
? html`<button type="button" class="rwin" data-b="win" title="Open in an app window">${ico("popout")}<span>Open in app window</span></button>`
|
|
599
|
-
: "";
|
|
600
|
-
async function openWindow(u: string) {
|
|
601
|
-
const r = await fetch("/open-url", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ url: u }) }).catch(() => null);
|
|
602
|
-
if (!r?.ok) toast("Could not open a browser window" + (r ? ": " + ((await r.json().catch(() => ({}))) as any).error : ""));
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// The run's Preview: its screenshots (each opens the image viewer on click), with an Open
|
|
606
|
-
// app link when it names a localhost address. The address is framed only when the Preview
|
|
607
|
-
// has no images: the dev server a run used is often gone, and a dead frame hides the proof.
|
|
608
|
-
// No run, no `## Preview`: what an agent last showed with `kaizen preview <image|url>` in this workspace.
|
|
609
|
-
async function directPreview(el: HTMLElement) {
|
|
610
|
-
if (!ctx) return false;
|
|
611
|
-
const p = await fetchPreview(ctx.dir, ctx.ws);
|
|
612
|
-
if (!p) return false;
|
|
613
|
-
const u = p.image ? fileUrl(ctx.dir, p.image) : p.url!;
|
|
614
|
-
el.insertAdjacentHTML("beforeend", String(p.image ? html`<div class="rprev"><figure><img src="${u}" alt="Latest change" style="max-width:100%"><figcaption>${p.image.split("/").pop()}</figcaption></figure></div>` : html`<iframe class="rframe" title="Preview" src="${u}"></iframe>`));
|
|
615
|
-
return true;
|
|
616
|
-
}
|
|
617
|
-
async function previewPane(el: HTMLElement) {
|
|
618
|
-
let doc = store.runDoc && store.runDoc.id === card?.id ? store.runDoc : null;
|
|
619
|
-
if (!doc && card?.kind === "run")
|
|
620
|
-
try {
|
|
621
|
-
doc = await (await fetch(`/run/${encodeURIComponent(card.id)}?dir=${encodeURIComponent(card.state)}`)).json();
|
|
622
|
-
} catch {}
|
|
623
|
-
const pv = doc && preview(doc.impl);
|
|
624
|
-
(el as any).refresh = () => (el.replaceChildren(), void previewPane(el));
|
|
625
|
-
if (!pv && (await directPreview(el))) return;
|
|
626
|
-
const url = loopbackUrl(pv);
|
|
627
|
-
const shots = pv && /!\[[^\]]*\]\(/.test(pv);
|
|
628
|
-
if (url && loopback && !shots) return void el.insertAdjacentHTML("beforeend", String(html`<iframe class="rframe" title="Preview" src="${/^https?:\/\//i.test(String(url)) ? url : "about:blank"}"></iframe>`));
|
|
629
|
-
const bar = url ? html`<div class="urlbar"><span class="sel">${url}</span>${winBtn(url)}</div>` : "";
|
|
630
|
-
el.insertAdjacentHTML("beforeend", String(html`${bar}<div class="rprev md">${pv ? raw(md(attach(pv, card))) : html`<p class="rnone">This run has no Preview yet.</p>`}</div>`));
|
|
631
|
-
el.querySelector<HTMLElement>(".urlbar [data-b=win]")?.addEventListener("click", () => void openWindow(url!));
|
|
632
|
-
// The screenshots as a grid, each captioned by its file name, after the Preview's text.
|
|
633
|
-
const box = el.querySelector(".rprev")!,
|
|
634
|
-
imgs = [...box.querySelectorAll("img")];
|
|
635
|
-
if (imgs.length) {
|
|
636
|
-
const grid = document.createElement("div");
|
|
637
|
-
grid.className = "shots";
|
|
638
|
-
for (const im of imgs) {
|
|
639
|
-
const p = im.parentElement!;
|
|
640
|
-
const fig = document.createElement("figure");
|
|
641
|
-
const cap = document.createElement("figcaption");
|
|
642
|
-
cap.textContent = im.alt || decodeURIComponent((im.getAttribute("src") || "").split("/").pop() || "");
|
|
643
|
-
fig.append(im.closest("a") ?? im, cap);
|
|
644
|
-
grid.append(fig);
|
|
645
|
-
if (p !== box && !p.textContent!.trim() && !p.querySelector("img")) p.remove();
|
|
646
|
-
}
|
|
647
|
-
box.append(grid);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
function addTab(t: Tab) {
|
|
652
|
-
const s = saved();
|
|
653
|
-
if (!s.tabs.some((x) => x.id === t.id)) s.tabs.push(t);
|
|
654
|
-
// Already open somewhere: moving it into the target screen means taking it out of its old one.
|
|
655
|
-
else if (target) for (const sc of s.screens) sc.tree = prune(sc.tree, (id) => id !== t.id) ?? sc.tree;
|
|
656
|
-
show(t.id);
|
|
657
|
-
}
|
|
658
|
-
// Automatic opens (a run's Preview, `kaizen preview`) bring a tab forward only when it is not open yet;
|
|
659
|
-
// an open one just navigates, so the user can leave it.
|
|
660
|
-
const autoTab = (t: Tab) => { if (!saved().tabs.some((x) => x.id === t.id)) addTab(t); };
|
|
661
|
-
// After an item is added: run screens() (which places it) and show the screen holding it.
|
|
662
|
-
function show(id: string) {
|
|
663
|
-
const s = saved();
|
|
664
|
-
s.on = screens().find((sc) => leaves(sc.tree).includes(id))?.id ?? s.on;
|
|
665
|
-
save();
|
|
666
|
-
draw();
|
|
667
|
-
}
|
|
668
|
-
export const openNoteTab = (name: string) => addTab({ id: "note:" + name, kind: "note", title: name.slice(name.lastIndexOf("/") + 1), note: name });
|
|
669
|
-
const openPreview = () => {
|
|
670
|
-
addTab({ id: "preview", kind: "preview", title: "Preview" });
|
|
671
|
-
if (isPhone()) $("pclose").click(); // Preview is a centre tab: the sheet would sit over it
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
// The run's recorded session, resumed in a board terminal tied to it. While it still runs in
|
|
675
|
-
// another terminal the server says so (409 live) and a tab explains; with no session, a shell.
|
|
676
|
-
async function openAgent(c, again = false, focus = true) {
|
|
677
|
-
const k = key(c);
|
|
678
|
-
const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: c.state, ws: ctx!.ws, run: k, resume: true }) }).catch(() => null);
|
|
679
|
-
if (r?.ok) {
|
|
680
|
-
elsewhere.delete(k);
|
|
681
|
-
const sh = await r.json();
|
|
682
|
-
shells.push(sh);
|
|
683
|
-
return focus ? show("sh:" + sh.key) : draw();
|
|
684
|
-
}
|
|
685
|
-
const j: any = r ? await r.json().catch(() => ({})) : {};
|
|
686
|
-
if (r?.status === 409 && j.live) {
|
|
687
|
-
elsewhere.add(k);
|
|
688
|
-
if (again) toast("Still running in another terminal");
|
|
689
|
-
return draw();
|
|
690
|
-
}
|
|
691
|
-
elsewhere.delete(k);
|
|
692
|
-
if (again) toast(j.error || "Could not resume the session");
|
|
693
|
-
else draw();
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
// `yolo` only when the + menu's switch was flipped; otherwise the server applies that agent's saved setting.
|
|
697
|
-
async function newPty(agent?: string, yolo?: boolean) {
|
|
698
|
-
const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: ctx!.dir, ws: ctx!.ws, run: ctx!.k, ...(agent ? { agent, yolo } : {}) }) });
|
|
699
|
-
if (r.status === 501) {
|
|
700
|
-
noPty = true;
|
|
701
|
-
return draw();
|
|
702
|
-
}
|
|
703
|
-
if (!r.ok) {
|
|
704
|
-
// 429 (too many terminals), 403, anything else: say why, and keep the tab bar drawn.
|
|
705
|
-
let why = "";
|
|
706
|
-
try {
|
|
707
|
-
why = (await r.json()).error;
|
|
708
|
-
} catch {}
|
|
709
|
-
toast(why ? "No new terminal: " + why : "No new terminal (" + r.status + ")");
|
|
710
|
-
return draw();
|
|
711
|
-
}
|
|
712
|
-
const sh = await r.json();
|
|
713
|
-
shells.push(sh);
|
|
714
|
-
show("sh:" + sh.key);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// The Run app button (play icon; the + menu's Preview is the run's Preview tab): the workspace's app in the Browser tab. A dev server already listening
|
|
718
|
-
// opens at once; otherwise the board starts the folder's dev script in a terminal here, waits
|
|
719
|
-
// for its port, then opens it. No dev script: the run's Preview (report and screenshots).
|
|
720
|
-
let starting = false;
|
|
721
|
-
async function previewApp() {
|
|
722
|
-
if (!ctx || starting) return;
|
|
723
|
-
const c = ctx;
|
|
724
|
-
const ports = async (): Promise<number[]> => {
|
|
725
|
-
try {
|
|
726
|
-
return await (await fetch("/devports?ws=" + encodeURIComponent(c.ws))).json();
|
|
727
|
-
} catch {
|
|
728
|
-
return [];
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
// The newest run here names the page to open (its ## Preview), when it has one.
|
|
732
|
-
const card = store.S.cards.filter((x) => x.state === c.dir && wsOfCard(x) === c.ws && x.id).sort((a, b) => String(b.id).localeCompare(String(a.id)))[0];
|
|
733
|
-
let pv = "";
|
|
734
|
-
try {
|
|
735
|
-
if (card) pv = preview((await (await fetch(`/run/${encodeURIComponent(card.id)}?dir=${encodeURIComponent(c.dir)}`)).json()).impl) ?? "";
|
|
736
|
-
} catch {}
|
|
737
|
-
const openAt = (u: string) => {
|
|
738
|
-
try {
|
|
739
|
-
localStorage.setItem("kz-browse:" + c.k, u);
|
|
740
|
-
} catch {}
|
|
741
|
-
addTab({ id: "local", kind: "local", title: "Browser" });
|
|
742
|
-
(panes.get("local")?.el as any)?.browseTo?.(u);
|
|
743
|
-
};
|
|
744
|
-
const now = await ports();
|
|
745
|
-
if (now.length) return openAt(devUrl(pv, now)!);
|
|
746
|
-
const u = devUrl(pv, []);
|
|
747
|
-
const r = await fetch("/shell", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ dir: c.dir, ws: c.ws, run: c.k, dev: true }) }).catch(() => null);
|
|
748
|
-
if (!r?.ok) {
|
|
749
|
-
let why = "";
|
|
750
|
-
try {
|
|
751
|
-
why = (await r!.json()).error;
|
|
752
|
-
} catch {}
|
|
753
|
-
toast(why ? `Preview: ${why}` : "Preview: the dev server did not start");
|
|
754
|
-
return openPreview();
|
|
755
|
-
}
|
|
756
|
-
const sh = await r.json();
|
|
757
|
-
if (!shells.some((x) => x.key === sh.key)) shells.push(sh);
|
|
758
|
-
draw();
|
|
759
|
-
starting = true;
|
|
760
|
-
toast("Starting the app…");
|
|
761
|
-
try {
|
|
762
|
-
// Up to a minute for the first port; Linux only reads ports, elsewhere the run's address after a pause.
|
|
763
|
-
for (let i = 0; i < 40 && ctx?.k === c.k; i++) {
|
|
764
|
-
await new Promise((ok) => setTimeout(ok, 1500));
|
|
765
|
-
const p = await ports();
|
|
766
|
-
if (p.length) return openAt(devUrl(pv, p)!);
|
|
767
|
-
if (i === 5 && u && !navigator.platform.startsWith("Linux")) return openAt(u);
|
|
768
|
-
}
|
|
769
|
-
if (ctx?.k === c.k) toast("The app did not open a port. Its terminal tab shows why.");
|
|
770
|
-
} finally {
|
|
771
|
-
starting = false;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
async function closeTab(id: string) {
|
|
776
|
-
const s = saved();
|
|
777
|
-
if (id.startsWith("sh:")) {
|
|
778
|
-
await post("/pty/exit", { key: id.slice(3) });
|
|
779
|
-
shells = shells.filter((x) => "sh:" + x.key !== id);
|
|
780
|
-
} else if (id.startsWith("agent:")) {
|
|
781
|
-
// Closing the tab ends the agent, so the sidebar stops listing it; one mid-turn asks first.
|
|
782
|
-
const k = id.slice(6),
|
|
783
|
-
a = store.S.agents?.find((x) => x.key === k);
|
|
784
|
-
if (a?.busy && !confirm("This agent is still working. End it?")) return;
|
|
785
|
-
s.hidden.push(id);
|
|
786
|
-
(s.hb ||= {})[id] = a?.born ?? 0;
|
|
787
|
-
await post("/pty/exit", { key: k });
|
|
788
|
-
load(true);
|
|
789
|
-
}
|
|
790
|
-
else if (id.startsWith("wait:")) elsewhere.delete(id.slice(5));
|
|
791
|
-
else s.tabs = s.tabs.filter((t) => t.id !== id);
|
|
792
|
-
save();
|
|
793
|
-
draw();
|
|
794
|
-
}
|
|
795
|
-
// A tab's ×: everything in it closes (shells end, the agent is only hidden).
|
|
796
|
-
async function closeScreen(sid: string) {
|
|
797
|
-
const sc = saved().screens.find((x) => x.id === sid);
|
|
798
|
-
for (const id of sc ? leaves(sc.tree) : []) await closeTab(id);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// A pane's ⋯ menu, filled when it opens: every other tab, and a tab of its own.
|
|
802
|
-
function onMoveMenu(e: Event) {
|
|
803
|
-
const d = e.target as HTMLDetailsElement;
|
|
804
|
-
if (!d.classList?.contains("pmove") || !d.open) return;
|
|
805
|
-
const s = saved(),
|
|
806
|
-
id = d.closest<HTMLElement>(".rpane")!.dataset.t!,
|
|
807
|
-
ts = tabs(),
|
|
808
|
-
name = (sc: Screen) => leaves(sc.tree).map((x) => ts.find((t) => t.id === x)?.title ?? "").join(" + ");
|
|
809
|
-
const m = d.querySelector<HTMLElement>(".menu-pop")!;
|
|
810
|
-
m.innerHTML = String(
|
|
811
|
-
html`<b class="mh">Move to</b>${s.screens.filter((sc) => !leaves(sc.tree).includes(id)).map((sc) => html`<button data-mv="${sc.id}">${ico("arrow")}<span>${name(sc)}</span></button>`)}<button data-mv="">${ico("plus")}<span>New tab</span></button>`,
|
|
812
|
-
);
|
|
813
|
-
const r = d.querySelector("summary")!.getBoundingClientRect();
|
|
814
|
-
m.style.top = r.bottom + 4 + "px";
|
|
815
|
-
m.style.left = Math.max(8, r.right - m.offsetWidth) + "px";
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
// + makes a new tab; split right/down adds to the tab shown. `n` is a menu item's data-n.
|
|
819
|
-
function openNew(n: string, mode: string, yolo?: boolean) {
|
|
820
|
-
const s = saved();
|
|
821
|
-
target = mode === "tab" || !s.on ? null : { screen: s.on, dir: mode as "cols" | "rows" };
|
|
822
|
-
if (n === "shell") void newPty();
|
|
823
|
-
else if (n.startsWith("agent:")) void newPty(n.slice(6), yolo);
|
|
824
|
-
else if (n === "local") addTab({ id: "local", kind: "local", title: "Browser" });
|
|
825
|
-
else if (n === "history") addTab({ id: "history", kind: "history", title: "History" });
|
|
826
|
-
else openPreview();
|
|
827
|
-
}
|
|
828
|
-
// Ctrl+Space r / d: a second terminal like the focused one (same agent, or a shell), split right or down.
|
|
829
|
-
// Anything else (Browser, Preview, notes) has no copy to make, so the menu opens to pick from.
|
|
830
|
-
function likeFocused(): string | null {
|
|
831
|
-
const sc = screens().find((x) => x.id === saved().on);
|
|
832
|
-
const t = sc && tabs().find((x) => x.id === sc.focus);
|
|
833
|
-
if (t?.kind === "shell") return "shell";
|
|
834
|
-
if (t?.kind === "agent") return "agent:" + (t.agent ?? (defAgent || agents[0]?.cmd || ""));
|
|
835
|
-
return null;
|
|
836
|
-
}
|
|
837
|
-
function wire() {
|
|
838
|
-
const bar = $("rtabs"),
|
|
839
|
-
s = saved();
|
|
840
|
-
bar.onclick = (e) => {
|
|
841
|
-
const t = e.target as HTMLElement;
|
|
842
|
-
const xs = t.closest<HTMLElement>("[data-xs]")?.dataset.xs;
|
|
843
|
-
if (xs) return void closeScreen(xs);
|
|
844
|
-
const tab = t.closest<HTMLElement>("[data-t]")?.dataset.t;
|
|
845
|
-
if (tab) {
|
|
846
|
-
s.on = tab;
|
|
847
|
-
save();
|
|
848
|
-
return draw();
|
|
849
|
-
}
|
|
850
|
-
if (t.closest("[data-pv]")) return void previewApp();
|
|
851
|
-
const n = t.closest<HTMLElement>("[data-n]")?.dataset.n;
|
|
852
|
-
if (n) {
|
|
853
|
-
const d = t.closest<HTMLDetailsElement>(".radd")!,
|
|
854
|
-
sw = d.querySelector<HTMLInputElement>(".agent-yolo input");
|
|
855
|
-
d.open = false;
|
|
856
|
-
openNew(n, d.dataset.mode as string, sw && sw.checked !== sw.defaultChecked ? sw.checked : undefined);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
};
|
|
860
|
-
$("rside").onclick = () => {
|
|
861
|
-
document.body.classList.toggle("rflip");
|
|
862
|
-
draw();
|
|
863
|
-
};
|
|
864
|
-
// The +, split right and split down menus open under their button, kept inside the
|
|
865
|
-
// centre panel; one open at a time. A pane's own × closes just that item.
|
|
866
|
-
const adds = [...bar.querySelectorAll<HTMLDetailsElement>(".radd")];
|
|
867
|
-
for (const add of adds)
|
|
868
|
-
add.ontoggle = () => {
|
|
869
|
-
if (!add.open) return;
|
|
870
|
-
for (const o of adds) if (o !== add) o.open = false;
|
|
871
|
-
const sw = add.querySelector<HTMLInputElement>(".agent-yolo input");
|
|
872
|
-
if (sw) sw.checked = sw.defaultChecked;
|
|
873
|
-
const m = add.querySelector<HTMLElement>(".menu-pop")!,
|
|
874
|
-
r = add.querySelector("summary")!.getBoundingClientRect(),
|
|
875
|
-
box = $("runv").getBoundingClientRect();
|
|
876
|
-
m.style.top = r.bottom + 4 + "px";
|
|
877
|
-
m.style.left = Math.max(box.left + 4, Math.min(r.left, box.right - m.offsetWidth - 4)) + "px";
|
|
878
|
-
};
|
|
879
|
-
$("rpanes").onclick = (e) => {
|
|
880
|
-
const x = (e.target as HTMLElement).closest<HTMLElement>(".ph [data-x]")?.dataset.x;
|
|
881
|
-
if (x) return void closeTab(x);
|
|
882
|
-
const rk = (e.target as HTMLElement).closest<HTMLElement>("[data-b=recheck]")?.dataset.k;
|
|
883
|
-
if (rk && byKey(rk)) return void openAgent(byKey(rk), true);
|
|
884
|
-
const hist = (e.target as HTMLElement).closest<HTMLElement>("[data-hist]")?.dataset.hist;
|
|
885
|
-
if (hist && byKey(hist)) return pickRun(hist);
|
|
886
|
-
const mv = (e.target as HTMLElement).closest<HTMLElement>("[data-mv]");
|
|
887
|
-
if (mv) {
|
|
888
|
-
const id = mv.closest<HTMLElement>(".rpane")!.dataset.t!;
|
|
889
|
-
mv.closest("details")!.open = false;
|
|
890
|
-
return moveItem(id, mv.dataset.mv || null);
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
// Moving panes: the header's ⋯ menu lists the other tabs; dragging the header drops it on a
|
|
894
|
-
// tab, on + (a tab of its own) or on a pane's edge (split there on that side).
|
|
895
|
-
const box = $("rpanes");
|
|
896
|
-
box.ontoggle = null;
|
|
897
|
-
box.addEventListener("toggle", onMoveMenu, true);
|
|
898
|
-
box.ondragstart = (e) => {
|
|
899
|
-
const id = (e.target as HTMLElement).closest<HTMLElement>(".ph")?.closest<HTMLElement>(".rpane")?.dataset.t;
|
|
900
|
-
if (!id) return;
|
|
901
|
-
dragging = id;
|
|
902
|
-
e.dataTransfer!.setData("text/plain", id);
|
|
903
|
-
e.dataTransfer!.effectAllowed = "move";
|
|
904
|
-
};
|
|
905
|
-
// A tab is the handle too: dragging it moves its focused pane (the only one, unsplit).
|
|
906
|
-
bar.ondragstart = (e) => {
|
|
907
|
-
const sc = saved().screens.find((x) => x.id === (e.target as HTMLElement).closest<HTMLElement>(".rtab")?.dataset.t);
|
|
908
|
-
if (!sc) return;
|
|
909
|
-
dragging = leaves(sc.tree).includes(sc.focus) ? sc.focus : leaves(sc.tree)[0];
|
|
910
|
-
e.dataTransfer!.setData("text/plain", dragging);
|
|
911
|
-
e.dataTransfer!.effectAllowed = "move";
|
|
912
|
-
};
|
|
913
|
-
box.ondragend = bar.ondragend = () => {
|
|
914
|
-
dragging = null;
|
|
915
|
-
document.querySelectorAll(".rdrop,.rdrop-l,.rdrop-r,.rdrop-t,.rdrop-b").forEach((x) => x.classList.remove("rdrop", "rdrop-l", "rdrop-r", "rdrop-t", "rdrop-b"));
|
|
916
|
-
};
|
|
917
|
-
const edge = (el: HTMLElement, e: DragEvent) => {
|
|
918
|
-
const r = el.getBoundingClientRect(),
|
|
919
|
-
x = (e.clientX - r.left) / r.width,
|
|
920
|
-
y = (e.clientY - r.top) / r.height;
|
|
921
|
-
const d = [["l", x], ["r", 1 - x], ["t", y], ["b", 1 - y]].sort((a, b) => (a[1] as number) - (b[1] as number))[0][0] as string;
|
|
922
|
-
return d;
|
|
923
|
-
};
|
|
924
|
-
box.ondragover = (e) => {
|
|
925
|
-
const pane = (e.target as HTMLElement).closest<HTMLElement>(".rpane");
|
|
926
|
-
if (!dragging || !pane || pane.dataset.t === dragging) return;
|
|
927
|
-
e.preventDefault();
|
|
928
|
-
const d = edge(pane, e);
|
|
929
|
-
pane.classList.remove("rdrop-l", "rdrop-r", "rdrop-t", "rdrop-b");
|
|
930
|
-
pane.classList.add("rdrop-" + d);
|
|
931
|
-
};
|
|
932
|
-
box.ondragleave = (e) => (e.target as HTMLElement).closest(".rpane")?.classList.remove("rdrop-l", "rdrop-r", "rdrop-t", "rdrop-b");
|
|
933
|
-
box.ondrop = (e) => {
|
|
934
|
-
const pane = (e.target as HTMLElement).closest<HTMLElement>(".rpane"),
|
|
935
|
-
id = dragging;
|
|
936
|
-
if (!id || !pane || pane.dataset.t === id) return;
|
|
937
|
-
e.preventDefault();
|
|
938
|
-
const d = edge(pane, e);
|
|
939
|
-
moveItem(id, s.on, { pane: pane.dataset.t!, dir: d === "l" || d === "r" ? "cols" : "rows", before: d === "l" || d === "t" });
|
|
940
|
-
};
|
|
941
|
-
bar.ondragover = (e) => {
|
|
942
|
-
const t = (e.target as HTMLElement).closest<HTMLElement>(".rtab,.radd[data-mode=tab]");
|
|
943
|
-
if (!dragging || !t) return;
|
|
944
|
-
e.preventDefault();
|
|
945
|
-
bar.querySelectorAll(".rdrop").forEach((x) => x.classList.remove("rdrop"));
|
|
946
|
-
t.classList.add("rdrop");
|
|
947
|
-
};
|
|
948
|
-
bar.ondrop = (e) => {
|
|
949
|
-
const t = (e.target as HTMLElement).closest<HTMLElement>(".rtab,.radd[data-mode=tab]"),
|
|
950
|
-
id = dragging;
|
|
951
|
-
if (!id || !t) return;
|
|
952
|
-
e.preventDefault();
|
|
953
|
-
moveItem(id, t.classList.contains("rtab") ? t.dataset.t! : null);
|
|
954
|
-
};
|
|
955
|
-
// The pane last clicked is the one a split divides.
|
|
956
|
-
$("rpanes").onpointerdown = (e) => {
|
|
957
|
-
const id = (e.target as HTMLElement).closest<HTMLElement>(".rpane")?.dataset.t,
|
|
958
|
-
sc = saved().screens.find((x) => x.id === saved().on);
|
|
959
|
-
if (id && sc && sc.focus !== id) {
|
|
960
|
-
sc.focus = id;
|
|
961
|
-
save();
|
|
962
|
-
for (const [k, p] of panes) p.el.classList.toggle("focus", p.el.classList.contains("split") && k === id);
|
|
963
|
-
}
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
// Leaving the workspace: its terminals unmount; the shells keep running on the server.
|
|
968
|
-
function stopPanes() {
|
|
969
|
-
$("panel").classList.add("parked");
|
|
970
|
-
for (const p of panes.values()) p.off?.();
|
|
971
|
-
panes.clear();
|
|
972
|
-
$("rpanes").innerHTML = "";
|
|
973
|
-
}
|
|
974
|
-
export function runStop() {
|
|
975
|
-
stopPanes();
|
|
976
|
-
card = ctx = null;
|
|
977
|
-
$("panel").classList.remove("pn");
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
// The strip's Project notes: the project's notes as a tree in the panel; a note opens as a centre tab.
|
|
981
|
-
async function projectNotes() {
|
|
982
|
-
const pn = $("panel");
|
|
983
|
-
if (pn.classList.toggle("pn") === false) return;
|
|
984
|
-
const box = $("pnlist");
|
|
985
|
-
box.innerHTML = "";
|
|
986
|
-
try {
|
|
987
|
-
const d = await (await fetch("/vault?dir=" + encodeURIComponent(ctx!.dir))).json();
|
|
988
|
-
const names: string[] = (d.notes ?? []).map((n) => n.name).sort();
|
|
989
|
-
// Folders first-level as headings, notes under them: "Project/Web board" shows under Project.
|
|
990
|
-
const groups = new Map<string, string[]>();
|
|
991
|
-
for (const n of names) {
|
|
992
|
-
const i = n.lastIndexOf("/"),
|
|
993
|
-
g = i < 0 ? "" : n.slice(0, i);
|
|
994
|
-
if (!groups.has(g)) groups.set(g, []);
|
|
995
|
-
groups.get(g)!.push(n);
|
|
996
|
-
}
|
|
997
|
-
box.innerHTML = String(
|
|
998
|
-
html`<h3>Project notes</h3>${names.length ? [...groups].map(([g, ns]) => html`${g ? html`<div class="tf dir">${ico("side")}${g}</div>` : ""}<div class="${g ? "tree" : ""}">${ns.map((n) => html`<button class="tf" data-note="${n}">${ico("note")}${n.slice(n.lastIndexOf("/") + 1)}</button>`)}</div>`) : html`<p class="rnone">No notes in this project yet.</p>`}`,
|
|
999
|
-
);
|
|
1000
|
-
} catch {
|
|
1001
|
-
box.textContent = "The notes could not load.";
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// The keys of the workspace's runs that were at review/done on the last tick, per workspace.
|
|
1006
|
-
const was = new Map<string, Set<string>>();
|
|
1007
|
-
// A run in the open workspace moves into review or done with a localhost address in its ## Preview:
|
|
1008
|
-
// the Browser opens on it, once per run. The first tick of a workspace only records.
|
|
1009
|
-
const mineNow = () => store.S.cards.filter((c) => c.state === ctx!.dir && wsOfCard(c) === ctx!.ws);
|
|
1010
|
-
async function autoBrowse() {
|
|
1011
|
-
if (!ctx) return;
|
|
1012
|
-
const k = ctx.k,
|
|
1013
|
-
mine = mineNow(),
|
|
1014
|
-
prev = was.get(k);
|
|
1015
|
-
was.set(k, new Set(mine.filter(reviewing).map(key)));
|
|
1016
|
-
if (!prev) return;
|
|
1017
|
-
for (const c of toOpen(mine, prev, saved().seen ?? [], key)) {
|
|
1018
|
-
let u: string | undefined;
|
|
1019
|
-
try {
|
|
1020
|
-
const doc = await (await fetch(`/run/${encodeURIComponent(c.id)}?dir=${encodeURIComponent(c.state)}`)).json();
|
|
1021
|
-
// Only an address the report names: with none, the lowest port in the workspace was a guess
|
|
1022
|
-
// (it once opened Claude Code's own local port, "not found").
|
|
1023
|
-
const pv = preview(doc.impl);
|
|
1024
|
-
if (!loopbackUrl(pv)) continue;
|
|
1025
|
-
u = devUrl(pv, await (await fetch("/devports?ws=" + encodeURIComponent(ctx.ws))).json());
|
|
1026
|
-
} catch {}
|
|
1027
|
-
if (!u || ctx?.k !== k || saved().seen?.includes(key(c))) continue;
|
|
1028
|
-
(saved().seen ||= []).push(key(c));
|
|
1029
|
-
try {
|
|
1030
|
-
localStorage.setItem("kz-browse:" + k, u);
|
|
1031
|
-
} catch {}
|
|
1032
|
-
autoTab({ id: "local", kind: "local", title: "Browser" });
|
|
1033
|
-
(panes.get("local")?.el as any)?.browseTo?.(u);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
// `kaizen preview <url|image>` (cli/preview.ts) wrote what an agent changed: the Browser tab opens
|
|
1038
|
-
// on it, inside the board. Never an outside window. Only in the workspace it was written from, and
|
|
1039
|
-
// only while you watch it: each visit's first look records the newest (`previewAt`, per visit), so a
|
|
1040
|
-
// click, a switch or a reload never opens a tab, or reopens one you closed.
|
|
1041
|
-
const previewAt = new Map<string, number>();
|
|
1042
|
-
const fileUrl = (dir: string, image: string) => `${location.origin}/file?dir=${encodeURIComponent(dir)}&p=${encodeURIComponent(image)}`;
|
|
1043
|
-
// The latest preview written for this workspace, or null.
|
|
1044
|
-
async function fetchPreview(dir: string, ws: string) {
|
|
1045
|
-
let p: { url?: string; image?: string; ws?: string; at?: number } = {};
|
|
1046
|
-
try {
|
|
1047
|
-
p = await (await fetch("/preview?dir=" + encodeURIComponent(dir))).json();
|
|
1048
|
-
} catch {}
|
|
1049
|
-
return p.at && p.ws && previewIn(p.ws, ws) && (p.url || p.image) ? p : null;
|
|
1050
|
-
}
|
|
1051
|
-
async function pollPreview() {
|
|
1052
|
-
if (!ctx) return;
|
|
1053
|
-
const k = ctx.k, dir = ctx.dir;
|
|
1054
|
-
const p = await fetchPreview(dir, ctx.ws);
|
|
1055
|
-
if (ctx?.k !== k) return;
|
|
1056
|
-
const at = p?.at ?? 0, last = previewAt.get(k);
|
|
1057
|
-
if (last !== undefined && at <= last) return;
|
|
1058
|
-
previewAt.set(k, at);
|
|
1059
|
-
if (!p || !previewOpens(at, last)) return;
|
|
1060
|
-
if (p.image) {
|
|
1061
|
-
// A screenshot belongs in Preview; a live page in the Browser.
|
|
1062
|
-
autoTab({ id: "preview", kind: "preview", title: "Preview" });
|
|
1063
|
-
(panes.get("preview")?.el as any)?.refresh?.();
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
try {
|
|
1067
|
-
localStorage.setItem("kz-browse:" + k, p.url!);
|
|
1068
|
-
} catch {}
|
|
1069
|
-
autoTab({ id: "local", kind: "local", title: "Browser" });
|
|
1070
|
-
(panes.get("local")?.el as any)?.browseTo?.(p.url!);
|
|
1071
|
-
}
|
|
1072
|
-
setInterval(() => void pollPreview(), 3000);
|
|
1073
|
-
|
|
1074
|
-
// A phone's run sheet: drag it down from anywhere its content is at the top, or tap outside it.
|
|
1075
|
-
function initSheet() {
|
|
1076
|
-
const p = $("panel"),
|
|
1077
|
-
b = document.body;
|
|
1078
|
-
const on = () => isPhone() && b.classList.contains("runv") && b.classList.contains("rflip");
|
|
1079
|
-
const shut = () => $("pclose").click();
|
|
1080
|
-
let y0: number | null = null,
|
|
1081
|
-
t0 = 0,
|
|
1082
|
-
dy = 0;
|
|
1083
|
-
const scrolled = (t: EventTarget | null) => ((t as Element).closest?.(".body")?.scrollTop ?? 0) > 0;
|
|
1084
|
-
p.addEventListener(
|
|
1085
|
-
"touchstart",
|
|
1086
|
-
(e) => {
|
|
1087
|
-
y0 = on() && e.touches.length === 1 && !scrolled(e.target) ? e.touches[0].clientY : null;
|
|
1088
|
-
t0 = Date.now();
|
|
1089
|
-
dy = 0;
|
|
1090
|
-
},
|
|
1091
|
-
{ passive: true },
|
|
1092
|
-
);
|
|
1093
|
-
p.addEventListener(
|
|
1094
|
-
"touchmove",
|
|
1095
|
-
(e) => {
|
|
1096
|
-
if (y0 === null) return;
|
|
1097
|
-
if (scrolled(e.target)) return void (y0 = null);
|
|
1098
|
-
dy = e.touches[0].clientY - y0;
|
|
1099
|
-
// A finger drifts a few pixels in a tap; taking those as a drag would cancel its click.
|
|
1100
|
-
if (dy <= 10) return void (p.style.translate = "");
|
|
1101
|
-
e.preventDefault();
|
|
1102
|
-
p.style.transition = "none";
|
|
1103
|
-
p.style.translate = `0 ${dy}px`;
|
|
1104
|
-
},
|
|
1105
|
-
{ passive: false },
|
|
1106
|
-
);
|
|
1107
|
-
const end = () => {
|
|
1108
|
-
if (y0 === null) return;
|
|
1109
|
-
y0 = null;
|
|
1110
|
-
p.style.transition = "";
|
|
1111
|
-
if (dy > 100 || (dy > 30 && Date.now() - t0 < 250)) {
|
|
1112
|
-
p.style.translate = "0 100%";
|
|
1113
|
-
setTimeout(() => (shut(), (p.style.translate = "")), 180);
|
|
1114
|
-
} else p.style.translate = "";
|
|
1115
|
-
};
|
|
1116
|
-
p.addEventListener("touchend", end);
|
|
1117
|
-
p.addEventListener("touchcancel", end);
|
|
1118
|
-
// composedPath, not target: a strip button redraws #ptabs in its own click, so by here
|
|
1119
|
-
// the target is detached and closest() would call a tap inside the sheet an outside one.
|
|
1120
|
-
addEventListener("click", (e) => on() && !e.composedPath().some((n) => (n as Element).matches?.("#panel,#rside,dialog,.toast")) && shut());
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
// The keyboard, tmux style: Ctrl+Space puts focus in the current pane, then one more key
|
|
1124
|
-
// moves it: arrows or hjkl between panes, 1-9, n, p between tabs.
|
|
1125
|
-
const focusPane = (id?: string) => {
|
|
1126
|
-
const el = id ? panes.get(id)?.el : null;
|
|
1127
|
-
requestAnimationFrame(() => el?.querySelector<HTMLElement>("textarea,input,iframe")?.focus());
|
|
1128
|
-
};
|
|
1129
|
-
const setPane = (sc: Screen, id: string) => {
|
|
1130
|
-
sc.focus = id;
|
|
1131
|
-
save();
|
|
1132
|
-
draw();
|
|
1133
|
-
focusPane(id);
|
|
1134
|
-
};
|
|
1135
|
-
const DIRS = { ArrowLeft: "l", h: "l", ArrowRight: "r", l: "r", ArrowUp: "u", k: "u", ArrowDown: "d", j: "d" } as const;
|
|
1136
|
-
function paneKey(k: string) {
|
|
1137
|
-
if (k === "?") {
|
|
1138
|
-
(document.activeElement as HTMLElement)?.blur(); // Escape closes it only from outside the terminal
|
|
1139
|
-
return void $("help").classList.add("on");
|
|
1140
|
-
}
|
|
1141
|
-
if (k === "x") {
|
|
1142
|
-
const sc = screens().find((x) => x.id === saved().on);
|
|
1143
|
-
if (sc) void closeTab(sc.focus).then(() => focusPane(screens().find((x) => x.id === saved().on)?.focus));
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
const mode = { c: "tab", r: "cols", d: "rows" }[k];
|
|
1147
|
-
const same = mode && mode !== "tab" && !noPty ? likeFocused() : null;
|
|
1148
|
-
if (same) return void openNew(same, mode!);
|
|
1149
|
-
if (mode) {
|
|
1150
|
-
const add = $("rtabs").querySelector<HTMLDetailsElement>(`.radd[data-mode=${mode}]`);
|
|
1151
|
-
if (add) add.open = true;
|
|
1152
|
-
requestAnimationFrame(() => add?.querySelector<HTMLElement>(".menu-pop button")?.focus());
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
const s = saved(),
|
|
1156
|
-
scs = screens(),
|
|
1157
|
-
at = scs.findIndex((x) => x.id === s.on),
|
|
1158
|
-
sc = scs[at];
|
|
1159
|
-
if (!sc) return;
|
|
1160
|
-
if (DIRS[k]) {
|
|
1161
|
-
const boxes: Record<string, Box> = {};
|
|
1162
|
-
for (const id of leaves(sc.tree)) {
|
|
1163
|
-
const el = panes.get(id)?.el;
|
|
1164
|
-
if (el) boxes[id] = el.getBoundingClientRect();
|
|
1165
|
-
}
|
|
1166
|
-
const to = nearestPane(boxes, sc.focus, DIRS[k]);
|
|
1167
|
-
if (to) setPane(sc, to);
|
|
1168
|
-
return;
|
|
1169
|
-
}
|
|
1170
|
-
const i = k === "n" ? (at + 1) % scs.length : k === "p" ? (at - 1 + scs.length) % scs.length : /^[1-9]$/.test(k) ? +k - 1 : -1;
|
|
1171
|
-
const to = scs[i];
|
|
1172
|
-
if (!to) return;
|
|
1173
|
-
s.on = to.id;
|
|
1174
|
-
save();
|
|
1175
|
-
draw();
|
|
1176
|
-
focusPane(to.focus);
|
|
1177
|
-
}
|
|
1178
|
-
// While the prefix waits for its key, a chip says so and lists the keys.
|
|
1179
|
-
function keyHint(on: boolean) {
|
|
1180
|
-
document.getElementById("keyhint")?.remove();
|
|
1181
|
-
if (!on) return;
|
|
1182
|
-
const h = document.createElement("div");
|
|
1183
|
-
h.id = "keyhint";
|
|
1184
|
-
h.setAttribute("role", "status");
|
|
1185
|
-
const keys = [["←↓↑→", "pane"], ["1-9", "tab"], ["n p", "next, prev"], ["c", "new tab"], ["r", "split right, same as this pane"], ["d", "split down, same as this pane"], ["x", "close pane"], ["?", "all keys"]];
|
|
1186
|
-
h.innerHTML = String(html`${keys.map(([k, t]) => html`<span><kbd>${k}</kbd>${t}</span>`)}`);
|
|
1187
|
-
document.body.append(h);
|
|
1188
|
-
}
|
|
1189
|
-
function initPaneKeys() {
|
|
1190
|
-
let armed: Timer | undefined;
|
|
1191
|
-
// Capture: xterm must not see these. Ctrl+B would reach an agent or a tmux inside the pane.
|
|
1192
|
-
addEventListener(
|
|
1193
|
-
"keydown",
|
|
1194
|
-
(e) => {
|
|
1195
|
-
if (!ctx || !document.body.classList.contains("runv") || document.querySelector("dialog[open]")) return;
|
|
1196
|
-
if (e.ctrlKey && !e.shiftKey && e.code === "Space") {
|
|
1197
|
-
e.preventDefault();
|
|
1198
|
-
e.stopPropagation();
|
|
1199
|
-
focusPane(screens().find((x) => x.id === saved().on)?.focus);
|
|
1200
|
-
clearTimeout(armed);
|
|
1201
|
-
keyHint(true);
|
|
1202
|
-
armed = setTimeout(() => ((armed = undefined), keyHint(false)), 2000);
|
|
1203
|
-
return;
|
|
1204
|
-
}
|
|
1205
|
-
// The open +, split right or split down menu: arrows or j k walk it, Enter picks, Escape closes.
|
|
1206
|
-
const add = $("rtabs").querySelector<HTMLDetailsElement>(".radd[open]");
|
|
1207
|
-
if (add) {
|
|
1208
|
-
const step = { ArrowDown: 1, j: 1, ArrowUp: -1, k: -1 }[e.key];
|
|
1209
|
-
if (step || e.key === "Escape") {
|
|
1210
|
-
e.preventDefault();
|
|
1211
|
-
e.stopPropagation();
|
|
1212
|
-
if (!step) return void ((add.open = false), focusPane(screens().find((x) => x.id === saved().on)?.focus));
|
|
1213
|
-
const items = [...add.querySelectorAll<HTMLElement>(".menu-pop button")];
|
|
1214
|
-
items[(items.indexOf(document.activeElement as HTMLElement) + step + items.length) % items.length]?.focus();
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
if (!armed || ["Control", "Shift", "Alt", "Meta"].includes(e.key)) return;
|
|
1219
|
-
e.preventDefault();
|
|
1220
|
-
e.stopPropagation();
|
|
1221
|
-
clearTimeout(armed);
|
|
1222
|
-
armed = undefined;
|
|
1223
|
-
keyHint(false);
|
|
1224
|
-
paneKey(e.key);
|
|
1225
|
-
},
|
|
1226
|
-
true,
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
export function initRunView() {
|
|
1231
|
-
initPaneKeys();
|
|
1232
|
-
// A phone's sheet closes with the panel's ×, which here hides the sheet rather than closing the card.
|
|
1233
|
-
document.addEventListener(
|
|
1234
|
-
"click",
|
|
1235
|
-
(e) => {
|
|
1236
|
-
if (!document.body.classList.contains("runv") || !(e.target as Element).closest?.("#pclose")) return;
|
|
1237
|
-
e.stopPropagation();
|
|
1238
|
-
document.body.classList.remove("rflip");
|
|
1239
|
-
setOpen(false);
|
|
1240
|
-
},
|
|
1241
|
-
true,
|
|
1242
|
-
);
|
|
1243
|
-
initSheet();
|
|
1244
|
-
initPick(pickRun);
|
|
1245
|
-
// The sidebar's agent mark: open that workspace with the agent's terminal tab selected.
|
|
1246
|
-
addEventListener("kz-open-term", (e: any) => {
|
|
1247
|
-
e.preventDefault();
|
|
1248
|
-
const { dir, ws, key } = e.detail;
|
|
1249
|
-
wantTerm = key;
|
|
1250
|
-
if (ctx?.k === wsKey(dir, ws) && document.body.classList.contains("runv")) return void showTerm();
|
|
1251
|
-
history.pushState(null, "", wsHref(dir, ws));
|
|
1252
|
-
markCurrent();
|
|
1253
|
-
go("ws");
|
|
1254
|
-
});
|
|
1255
|
-
// Search's Tabs group: open the workspace on the screen holding that tab.
|
|
1256
|
-
addEventListener("kz-open-tab", (e: any) => {
|
|
1257
|
-
e.preventDefault();
|
|
1258
|
-
const { dir, ws, id } = e.detail;
|
|
1259
|
-
const k = wsKey(dir, ws),
|
|
1260
|
-
s = ALL[k],
|
|
1261
|
-
sc = s?.screens?.find((x) => leaves(x.tree).includes(id));
|
|
1262
|
-
if (sc) (s.on = sc.id), save();
|
|
1263
|
-
if (ctx?.k === k && document.body.classList.contains("runv")) return void draw();
|
|
1264
|
-
history.pushState(null, "", wsHref(dir, ws));
|
|
1265
|
-
markCurrent();
|
|
1266
|
-
go("ws");
|
|
1267
|
-
});
|
|
1268
|
-
addEventListener("kz-run-preview", openPreview);
|
|
1269
|
-
$("pnotes").onclick = () => void projectNotes();
|
|
1270
|
-
$("pnlist").onclick = (e) => {
|
|
1271
|
-
const n = (e.target as HTMLElement).closest<HTMLElement>("[data-note]")?.dataset.note;
|
|
1272
|
-
if (n) openNoteTab(n);
|
|
1273
|
-
};
|
|
1274
|
-
// A /state change: new or ended sessions, the card's own state. Panes stay mounted.
|
|
1275
|
-
addEventListener("kz-state", () => {
|
|
1276
|
-
void autoBrowse();
|
|
1277
|
-
followNew();
|
|
1278
|
-
if (ctx && document.body.classList.contains("runv")) void showRunView();
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
// Opens a card's workspace, its address in the history.
|
|
1282
|
-
export function openWorkspace(c) {
|
|
1283
|
-
const u = cardHref(c);
|
|
1284
|
-
if (location.pathname + location.search !== u) history.pushState(null, "", u);
|
|
1285
|
-
markCurrent();
|
|
1286
|
-
go("run");
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
// The run view's right panel: drag its left edge to resize it; the width is kept for next
|
|
1290
|
-
// time and a double-click puts it back to the default.
|
|
1291
|
-
const GRIP_KEY = "kz-rpanel-w", GRIP_MIN = 260;
|
|
1292
|
-
function initGrip() {
|
|
1293
|
-
const grip = document.getElementById("rgrip"), panel = document.getElementById("panel"), root = document.documentElement;
|
|
1294
|
-
if (!grip || !panel) return;
|
|
1295
|
-
const set = (w: number) => root.style.setProperty("--rpanel-w", `${Math.round(Math.min(Math.max(GRIP_MIN, innerWidth * 0.6), Math.max(GRIP_MIN, w)))}px`);
|
|
1296
|
-
try { const w = Number(localStorage.getItem(GRIP_KEY)); if (w) set(w); } catch { /* private window: default width */ }
|
|
1297
|
-
grip.onpointerdown = (e) => {
|
|
1298
|
-
e.preventDefault();
|
|
1299
|
-
grip.setPointerCapture(e.pointerId);
|
|
1300
|
-
document.body.classList.add("rdrag");
|
|
1301
|
-
const move = (m: PointerEvent) => set(panel.getBoundingClientRect().right - m.clientX);
|
|
1302
|
-
const up = () => {
|
|
1303
|
-
grip.removeEventListener("pointermove", move);
|
|
1304
|
-
document.body.classList.remove("rdrag");
|
|
1305
|
-
try { localStorage.setItem(GRIP_KEY, String(Math.round(panel.getBoundingClientRect().width))); } catch { /* not kept */ }
|
|
1306
|
-
};
|
|
1307
|
-
grip.addEventListener("pointermove", move);
|
|
1308
|
-
grip.addEventListener("pointerup", up, { once: true });
|
|
1309
|
-
grip.addEventListener("pointercancel", up, { once: true });
|
|
1310
|
-
};
|
|
1311
|
-
grip.ondblclick = () => {
|
|
1312
|
-
root.style.removeProperty("--rpanel-w");
|
|
1313
|
-
try { localStorage.removeItem(GRIP_KEY); } catch { /* nothing kept */ }
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
if (typeof document !== "undefined") initGrip();
|