kaizen-agent 1.85.2 → 1.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.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/rea.ts +99 -11
- package/cli/settings.ts +16 -17
- package/cli/state.ts +15 -29
- package/cli/task-service.ts +114 -34
- package/cli/tasks.ts +8 -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 +197 -61
- package/package.json +21 -4
- package/skills/kaizen/spec.md +12 -4
- package/skills/optional/disk-cleanup/SKILL.md +60 -0
- package/skills/optional/disk-cleanup/skill.json +1 -0
- package/skills/optional/disk-cleanup/tui.py +90 -0
- 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 +103 -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 +132 -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 +383 -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/term-paste.ts +10 -0
- package/web/{term.ts → term/term.ts} +101 -27
- 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 -86
- 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 -615
- 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 -500
- package/web/notebook.js +0 -514
- package/web/notebook.ts +0 -1254
- package/web/popup.html +0 -141
- package/web/video.js +0 -570
- /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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The annotator's note model, board side: what the page sends, what the board keeps (and saves without the crops),
|
|
2
|
+
// the settings, and the two request bodies (Copy -> /annotate/format, Send -> /annotate/send). No DOM, no requests.
|
|
3
|
+
import { MAX_BOARD_NOTES, mapUrl, safeCrop } from "./rules.ts";
|
|
4
|
+
|
|
5
|
+
export type Note = Record<string, any> & { id: string; n: number };
|
|
6
|
+
export type Settings = {
|
|
7
|
+
mode: string;
|
|
8
|
+
level: string;
|
|
9
|
+
components: boolean;
|
|
10
|
+
color: string;
|
|
11
|
+
clear: boolean;
|
|
12
|
+
block: boolean;
|
|
13
|
+
};
|
|
14
|
+
export const DEFAULTS: Settings = {
|
|
15
|
+
mode: "element",
|
|
16
|
+
level: "standard",
|
|
17
|
+
components: true,
|
|
18
|
+
color: "#3c82f7",
|
|
19
|
+
clear: false,
|
|
20
|
+
block: true,
|
|
21
|
+
};
|
|
22
|
+
export const LEVELS = ["compact", "standard", "detailed", "forensic"];
|
|
23
|
+
|
|
24
|
+
// What the page needs to draw a marker for each note (the board keeps the rest).
|
|
25
|
+
export const markersOf = (notes: Note[]) =>
|
|
26
|
+
notes.map((n) => ({
|
|
27
|
+
n: n.n,
|
|
28
|
+
kind: n.kind,
|
|
29
|
+
selector: n.selector,
|
|
30
|
+
items: n.items,
|
|
31
|
+
pb: n.pb,
|
|
32
|
+
page: n.page,
|
|
33
|
+
comment: n.comment,
|
|
34
|
+
intent: n.intent,
|
|
35
|
+
severity: n.severity,
|
|
36
|
+
}));
|
|
37
|
+
// Saved and sent to /annotate/format without the crops (a crop is up to ~1 MB of PNG).
|
|
38
|
+
export const withoutCrops = (notes: Note[]) => notes.map(({ crop, ...n }) => n);
|
|
39
|
+
export const group = (kind: unknown) => kind === "multi" || kind === "area";
|
|
40
|
+
|
|
41
|
+
// A note from the page becomes a board note: a fresh id and number, the crop only if it is a small PNG, and its address
|
|
42
|
+
// only if it is on the proxy (shown as the app's own). Null once the board holds as many as it will.
|
|
43
|
+
export function fromPage(
|
|
44
|
+
raw: Record<string, any>,
|
|
45
|
+
count: number,
|
|
46
|
+
n: number,
|
|
47
|
+
px: { origin: string; target: string },
|
|
48
|
+
): Note | null {
|
|
49
|
+
if (count >= MAX_BOARD_NOTES) return null;
|
|
50
|
+
return {
|
|
51
|
+
...raw,
|
|
52
|
+
id: Math.random().toString(36).slice(2),
|
|
53
|
+
n,
|
|
54
|
+
crop: safeCrop(raw.crop),
|
|
55
|
+
url: mapUrl(String(raw.url || ""), px.origin, px.target) ?? "",
|
|
56
|
+
page: String(raw.page || ""),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export const without = (notes: Note[], n: number) => notes.filter((x) => x.n !== n);
|
|
60
|
+
// The edited comment, or the same list when it is empty or unchanged.
|
|
61
|
+
export const editedComment = (notes: Note[], n: number, text: string): Note[] => {
|
|
62
|
+
const t = text.trim();
|
|
63
|
+
return t && notes.some((x) => x.n === n && x.comment !== t)
|
|
64
|
+
? notes.map((x) => (x.n === n ? { ...x, comment: t } : x))
|
|
65
|
+
: notes;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const formatBody = (notes: Note[], s: Pick<Settings, "level" | "components">) => ({
|
|
69
|
+
notes: withoutCrops(notes),
|
|
70
|
+
level: s.level,
|
|
71
|
+
components: s.components,
|
|
72
|
+
});
|
|
73
|
+
export const sendBody = (
|
|
74
|
+
run: { dir: string; id: string },
|
|
75
|
+
notes: Note[],
|
|
76
|
+
s: Pick<Settings, "level" | "components">,
|
|
77
|
+
) => ({ dir: run.dir, id: run.id, notes: notes.map((n) => ({ ...n })), level: s.level, components: s.components });
|
|
78
|
+
export const plural = (n: number, w: string) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
79
|
+
|
|
80
|
+
// Notes and settings live in localStorage (the notes per workspace, as before: same keys).
|
|
81
|
+
const read = <T>(k: string, d: T): T => {
|
|
82
|
+
try {
|
|
83
|
+
return { ...d, ...JSON.parse(localStorage.getItem(k) || "{}") };
|
|
84
|
+
} catch {
|
|
85
|
+
return d;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const write = (k: string, v: unknown) => {
|
|
89
|
+
try {
|
|
90
|
+
localStorage.setItem(k, JSON.stringify(v));
|
|
91
|
+
} catch {
|
|
92
|
+
/* private window */
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
export const loadSettings = (): Settings => read("kz-annotate", DEFAULTS);
|
|
96
|
+
export const saveSettings = (s: Settings) => write("kz-annotate", s);
|
|
97
|
+
export const loadNotes = (ws: string): Note[] => {
|
|
98
|
+
try {
|
|
99
|
+
const l = JSON.parse(localStorage.getItem("kz-ann:" + ws) || "[]");
|
|
100
|
+
return Array.isArray(l) ? l : [];
|
|
101
|
+
} catch {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
export const saveNotes = (ws: string, notes: Note[]) => write("kz-ann:" + ws, withoutCrops(notes));
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The annotator's rules that need no page: selection geometry, where the note box and tips sit, what a note holds,
|
|
2
|
+
// and the plan for the picture of what was picked. web/annotate/annotate.ts (the script injected into the framed page)
|
|
3
|
+
// reads them from here, so a test can hold them without a browser.
|
|
4
|
+
export type Rect = { left: number; top: number; width: number; height: number; right: number; bottom: number };
|
|
5
|
+
|
|
6
|
+
// A class name worth putting in a selector: short, and not a generated hash (css-1x2y3z, sc-, jsx-, _foo).
|
|
7
|
+
export const goodClass = (c: string) => c.length < 24 && !/\d{3,}|^css-|^_|^sc-|^jsx-/.test(c);
|
|
8
|
+
|
|
9
|
+
export const union = (rs: Rect[]): Rect => {
|
|
10
|
+
const left = Math.min(...rs.map((r) => r.left)),
|
|
11
|
+
top = Math.min(...rs.map((r) => r.top)),
|
|
12
|
+
right = Math.max(...rs.map((r) => r.right)),
|
|
13
|
+
bottom = Math.max(...rs.map((r) => r.bottom));
|
|
14
|
+
return { left, top, right, bottom, width: right - left, height: bottom - top };
|
|
15
|
+
};
|
|
16
|
+
// The rectangle of an area drag, from where it began to where the pointer is.
|
|
17
|
+
export const rectOf = (d: { x0: number; y0: number; x1: number; y1: number }): Rect => {
|
|
18
|
+
const left = Math.min(d.x0, d.x1),
|
|
19
|
+
top = Math.min(d.y0, d.y1),
|
|
20
|
+
width = Math.abs(d.x1 - d.x0),
|
|
21
|
+
height = Math.abs(d.y1 - d.y0);
|
|
22
|
+
return { left, top, width, height, right: left + width, bottom: top + height };
|
|
23
|
+
};
|
|
24
|
+
// An area counts when it is at least 8 x 8; a smaller drag was a click.
|
|
25
|
+
export const areaBigEnough = (r: Rect) => r.width >= 8 && r.height >= 8;
|
|
26
|
+
// An element belongs to an area when it is not tiny and sits inside it (a pixel of slack).
|
|
27
|
+
export const insideArea = (b: Rect, r: Rect) =>
|
|
28
|
+
b.width >= 4 &&
|
|
29
|
+
b.height >= 4 &&
|
|
30
|
+
b.left >= r.left - 1 &&
|
|
31
|
+
b.top >= r.top - 1 &&
|
|
32
|
+
b.right <= r.right + 1 &&
|
|
33
|
+
b.bottom <= r.bottom + 1;
|
|
34
|
+
export const AREA_MAX = 20;
|
|
35
|
+
|
|
36
|
+
export const quote = (text: string, fallback: string) => {
|
|
37
|
+
const t = text.replace(/\s+/g, " ").trim();
|
|
38
|
+
return t ? `"${t.slice(0, 60)}${t.length > 60 ? "…" : ""}"` : fallback;
|
|
39
|
+
};
|
|
40
|
+
export const areaLabel = (r: Rect, n: number) => `area ${Math.round(r.width)}x${Math.round(r.height)} (${n} elements)`;
|
|
41
|
+
|
|
42
|
+
// Where the note box opens: under the pick when there is room, else above it, always inside the window.
|
|
43
|
+
export const composerPos = (r: Rect, vw: number, vh: number) => ({
|
|
44
|
+
left: Math.max(8, Math.min(vw - 316, r.left)),
|
|
45
|
+
top: r.bottom + 330 < vh ? Math.min(r.bottom + 8, vh - 200) : Math.max(8, r.top - 190),
|
|
46
|
+
});
|
|
47
|
+
// A marker sits at the top right corner of what it marks; its comment under the block.
|
|
48
|
+
export const markerPos = (r: Rect, vw: number) => ({
|
|
49
|
+
left: Math.min(vw - 12, r.left + r.width),
|
|
50
|
+
top: Math.max(12, r.top),
|
|
51
|
+
});
|
|
52
|
+
export const tipPos = (r: Rect, vw: number, vh: number) => ({
|
|
53
|
+
left: Math.max(8, Math.min(vw - 268, r.left)),
|
|
54
|
+
top: Math.min(r.top + r.height + 8, vh - 90),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// What the page measured about the pick, as the board's note.
|
|
58
|
+
export type Pick = { kind: string; rect: Rect; count: number; selected?: string };
|
|
59
|
+
export type Facts = {
|
|
60
|
+
selector: string;
|
|
61
|
+
items: string[];
|
|
62
|
+
path: string;
|
|
63
|
+
text: string;
|
|
64
|
+
tag: string;
|
|
65
|
+
url: string;
|
|
66
|
+
page: string;
|
|
67
|
+
attrs: string;
|
|
68
|
+
styles: string;
|
|
69
|
+
nearby: string;
|
|
70
|
+
source: string;
|
|
71
|
+
components: string;
|
|
72
|
+
};
|
|
73
|
+
export const buildNote = (
|
|
74
|
+
p: Pick,
|
|
75
|
+
f: Facts,
|
|
76
|
+
entry: { comment: string; intent: string; severity: string },
|
|
77
|
+
scroll: { x: number; y: number },
|
|
78
|
+
) => ({
|
|
79
|
+
kind: p.kind,
|
|
80
|
+
comment: entry.comment,
|
|
81
|
+
intent: entry.intent,
|
|
82
|
+
severity: entry.severity,
|
|
83
|
+
selector: f.selector,
|
|
84
|
+
items: p.count > 1 ? f.items : [],
|
|
85
|
+
path: f.path,
|
|
86
|
+
text: f.text.slice(0, 200),
|
|
87
|
+
tag: f.tag,
|
|
88
|
+
url: f.url,
|
|
89
|
+
box: `${Math.round(p.rect.left + scroll.x)},${Math.round(p.rect.top + scroll.y)} ${Math.round(p.rect.width)}x${Math.round(p.rect.height)}`,
|
|
90
|
+
pb: { x: p.rect.left + scroll.x, y: p.rect.top + scroll.y, w: p.rect.width, h: p.rect.height },
|
|
91
|
+
page: f.page,
|
|
92
|
+
attrs: f.attrs,
|
|
93
|
+
styles: f.styles,
|
|
94
|
+
nearby: f.nearby,
|
|
95
|
+
selected: p.selected || "",
|
|
96
|
+
source: f.source,
|
|
97
|
+
components: f.components,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// The picture of a pick: the element is cloned into an SVG and drawn on a canvas. Too big (over 2400 px) or tiny (under
|
|
101
|
+
// 2) means no picture; the crop is the part the user picked, in the element's own pixels.
|
|
102
|
+
export const CROP_MAX = 2400;
|
|
103
|
+
export const CROP_BUDGET = 1500; // nodes cloned at most
|
|
104
|
+
export const CROP_CHARS = 1_300_000; // a PNG data URL longer than this is tried again smaller
|
|
105
|
+
export const tooBig = (r: { width: number; height: number }) => r.width > CROP_MAX || r.height > CROP_MAX;
|
|
106
|
+
export const cropWindow = (br: Rect, want: Rect) => {
|
|
107
|
+
if (br.width < 2 || br.height < 2 || tooBig(br)) return null;
|
|
108
|
+
const w = Math.ceil(br.width),
|
|
109
|
+
h = Math.ceil(br.height);
|
|
110
|
+
const sx = Math.max(0, want.left - br.left),
|
|
111
|
+
sy = Math.max(0, want.top - br.top);
|
|
112
|
+
const sw = Math.min(w - sx, want.width),
|
|
113
|
+
sh = Math.min(h - sy, want.height);
|
|
114
|
+
return sw < 2 || sh < 2 ? null : { w, h, sx, sy, sw, sh };
|
|
115
|
+
};
|
|
116
|
+
// The scales to try, largest first: the device pixel ratio (at most 2) down to 0.5, never past 1600 px on the long side.
|
|
117
|
+
export const cropScales = (sw: number, sh: number, dpr: number) => {
|
|
118
|
+
const out: number[] = [];
|
|
119
|
+
for (let k = Math.min(2, dpr || 1); k >= 0.5; k -= 0.5) out.push(Math.min(k, 1600 / Math.max(sw, sh)));
|
|
120
|
+
return out;
|
|
121
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Pure rules of the annotator, board side (lib/annotate/session.ts), kept apart so a test can load them without a page.
|
|
2
|
+
|
|
3
|
+
// A message from the page counts only from the frame itself, the proxy's origin and this open's token.
|
|
4
|
+
export const accept = (
|
|
5
|
+
e: { source: unknown; origin: string; data: any },
|
|
6
|
+
frameWin: unknown,
|
|
7
|
+
origin: string,
|
|
8
|
+
token: string,
|
|
9
|
+
) => !!origin && e.source === frameWin && e.origin === origin && !!e.data && e.data.kz === 1 && e.data.t === token;
|
|
10
|
+
|
|
11
|
+
// The desktop app's Browser tab is a <webview>: the page's messages arrive over its IPC channel, from
|
|
12
|
+
// that element only, so the token is all there is to check.
|
|
13
|
+
export const acceptHost = (d: any, token: string) => !!d && d.kz === 1 && d.t === token && !!token;
|
|
14
|
+
|
|
15
|
+
// The page reports its address on the proxy; the board shows the app's own. Anything not on the proxy's
|
|
16
|
+
// origin (a javascript: or data: URL, another site) is null: the page is untrusted and must not set the board's address.
|
|
17
|
+
export const mapUrl = (href: string, origin: string, target: string): string | null => {
|
|
18
|
+
try {
|
|
19
|
+
const u = new URL(href);
|
|
20
|
+
return u.origin === origin ? target + u.pathname + u.search + u.hash : null;
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// A crop from the page goes into an <img src> in the board: only a small PNG data URL passes.
|
|
27
|
+
export const safeCrop = (c: unknown): string | undefined =>
|
|
28
|
+
typeof c === "string" && c.length < 1_400_000 && /^data:image\/png;base64,[A-Za-z0-9+/=]+$/.test(c) ? c : undefined;
|
|
29
|
+
export const MAX_BOARD_NOTES = 200;
|
|
30
|
+
|
|
31
|
+
// The Browser tab's page is on the proxy only when it is a localhost page (any other site is framed or loaded directly).
|
|
32
|
+
export const isLoopbackUrl = (u: string) => /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(u);
|
|
33
|
+
export const isHttpUrl = (u: string) => /^https?:\/\//.test(u);
|
|
34
|
+
|
|
35
|
+
// One token per open: the page signs every message with it and the board takes only messages that carry it.
|
|
36
|
+
export const newToken = () =>
|
|
37
|
+
[...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// The Browser tab's annotator, board side: the state (a Zustand store), the keys and the conversation with the page.
|
|
2
|
+
// The page is served by the board's proxy on another origin (cli/annotate-proxy.ts) and runs web/annotate/annotate.ts
|
|
3
|
+
// (web/dist/annotate.js); the two talk only by postMessage, and this side accepts a message only from the frame window,
|
|
4
|
+
// from the proxy's origin, with the token the proxy handed out when it was opened. Notes live here (and in localStorage,
|
|
5
|
+
// without crops). The toolbar and the notes list are components/annotate; this file draws nothing.
|
|
6
|
+
import { create } from "zustand";
|
|
7
|
+
import { post, toast } from "@lib/core";
|
|
8
|
+
import {
|
|
9
|
+
editedComment,
|
|
10
|
+
formatBody,
|
|
11
|
+
fromPage,
|
|
12
|
+
loadNotes,
|
|
13
|
+
loadSettings,
|
|
14
|
+
markersOf,
|
|
15
|
+
plural,
|
|
16
|
+
saveNotes,
|
|
17
|
+
saveSettings,
|
|
18
|
+
sendBody,
|
|
19
|
+
without,
|
|
20
|
+
type Note,
|
|
21
|
+
type Settings,
|
|
22
|
+
} from "./notes.ts";
|
|
23
|
+
import { accept, acceptHost, isHttpUrl, isLoopbackUrl, mapUrl, newToken } from "./rules.ts";
|
|
24
|
+
|
|
25
|
+
export type Px = { origin: string; token: string; target: string };
|
|
26
|
+
export type AnnState = {
|
|
27
|
+
settings: Settings;
|
|
28
|
+
on: boolean; // picking
|
|
29
|
+
hide: boolean; // markers hidden on the page
|
|
30
|
+
pause: boolean; // page animations frozen
|
|
31
|
+
want: boolean; // the Annotate button is pressed
|
|
32
|
+
list: boolean; // the notes list is open
|
|
33
|
+
setOpen: boolean; // the settings box (inside the list) is open
|
|
34
|
+
px: Px | null; // the proxy this page was opened through, or the webview's own origin
|
|
35
|
+
notes: Note[];
|
|
36
|
+
flash: number | null; // the note whose marker was just clicked on the page
|
|
37
|
+
};
|
|
38
|
+
export type AnnotatorOpts = {
|
|
39
|
+
frame: () => HTMLElement | null; // an <iframe>, or in the desktop app a <webview> (talks over IPC, not postMessage)
|
|
40
|
+
wsKey: string;
|
|
41
|
+
run: () => { dir: string; id: string } | null;
|
|
42
|
+
onLocation: (u: string) => void;
|
|
43
|
+
reload: () => void;
|
|
44
|
+
};
|
|
45
|
+
export type Annotator = ReturnType<typeof createAnnotator>;
|
|
46
|
+
|
|
47
|
+
export function createAnnotator(o: AnnotatorOpts) {
|
|
48
|
+
const notes = loadNotes(o.wsKey);
|
|
49
|
+
const use = create<AnnState>(() => ({
|
|
50
|
+
settings: loadSettings(),
|
|
51
|
+
on: false,
|
|
52
|
+
hide: false,
|
|
53
|
+
pause: false,
|
|
54
|
+
want: false,
|
|
55
|
+
list: false,
|
|
56
|
+
setOpen: false,
|
|
57
|
+
px: null,
|
|
58
|
+
notes,
|
|
59
|
+
flash: null,
|
|
60
|
+
}));
|
|
61
|
+
const get = use.getState,
|
|
62
|
+
set = use.setState;
|
|
63
|
+
let counter = notes.reduce((m, n) => Math.max(m, n.n), 0);
|
|
64
|
+
// The Browser pane is on screen (its workspace is shown, on the run view, and this tab is the one in front). A kept, hidden
|
|
65
|
+
// pane keeps its window listeners, so keys and the page's messages are ignored while it is not: `x` on Tasks must not wipe
|
|
66
|
+
// the notes, and `s` must not send them to the run of another workspace.
|
|
67
|
+
let shown = true;
|
|
68
|
+
let flashTimer: ReturnType<typeof setTimeout> | undefined;
|
|
69
|
+
|
|
70
|
+
const webview = () => {
|
|
71
|
+
const f = o.frame();
|
|
72
|
+
return f?.tagName === "WEBVIEW" ? (f as any) : null;
|
|
73
|
+
};
|
|
74
|
+
const frameWin = () => (o.frame() as HTMLIFrameElement | null)?.contentWindow ?? null;
|
|
75
|
+
const say = (m: Record<string, unknown>) => {
|
|
76
|
+
const { px } = get();
|
|
77
|
+
if (!px) return;
|
|
78
|
+
const msg = { kz: 1, t: px.token, ...m };
|
|
79
|
+
const web = webview();
|
|
80
|
+
if (web) {
|
|
81
|
+
try {
|
|
82
|
+
web.send("kz-ann", msg);
|
|
83
|
+
} catch {
|
|
84
|
+
/* not loaded yet: the page says ready when it is */
|
|
85
|
+
}
|
|
86
|
+
} else frameWin()?.postMessage(msg, px.origin);
|
|
87
|
+
};
|
|
88
|
+
// What the page is told: how to pick, and the notes' markers.
|
|
89
|
+
const push = () => {
|
|
90
|
+
const s = get();
|
|
91
|
+
say({
|
|
92
|
+
type: "config",
|
|
93
|
+
cfg: {
|
|
94
|
+
on: s.on,
|
|
95
|
+
mode: s.settings.mode,
|
|
96
|
+
hide: s.hide,
|
|
97
|
+
block: s.settings.block,
|
|
98
|
+
color: s.settings.color,
|
|
99
|
+
components: s.settings.components,
|
|
100
|
+
pause: s.pause,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
say({ type: "markers", list: markersOf(s.notes) });
|
|
104
|
+
};
|
|
105
|
+
const setNotes = (next: Note[]) => {
|
|
106
|
+
set({ notes: next });
|
|
107
|
+
saveNotes(o.wsKey, next);
|
|
108
|
+
say({ type: "markers", list: markersOf(next) });
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const clear = () => setNotes([]);
|
|
112
|
+
async function copy() {
|
|
113
|
+
const { notes: ns, settings: s } = get();
|
|
114
|
+
if (!ns.length) return;
|
|
115
|
+
const r = await post("/annotate/format", formatBody(ns, s));
|
|
116
|
+
if (!r?.ok) return;
|
|
117
|
+
try {
|
|
118
|
+
await navigator.clipboard.writeText(r.text);
|
|
119
|
+
} catch {
|
|
120
|
+
say({ type: "copy", text: r.text });
|
|
121
|
+
}
|
|
122
|
+
toast(`Copied ${plural(ns.length, "note")}`);
|
|
123
|
+
if (s.clear) clear();
|
|
124
|
+
}
|
|
125
|
+
async function send() {
|
|
126
|
+
const run = o.run();
|
|
127
|
+
if (!run) return void toast("Open this run's agent first: there is nothing to send to.");
|
|
128
|
+
const { notes: ns, settings: s } = get();
|
|
129
|
+
if (!ns.length) return;
|
|
130
|
+
const r = await post("/annotate/send", sendBody(run, ns, s));
|
|
131
|
+
if (!r?.ok) return;
|
|
132
|
+
toast(`Sent ${plural(r.sent, "note")} to the agent${r.crops ? `, ${plural(r.crops, "crop")} saved` : ""}`);
|
|
133
|
+
if (s.clear) clear();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const api = {
|
|
137
|
+
use,
|
|
138
|
+
live(on: boolean) {
|
|
139
|
+
shown = on;
|
|
140
|
+
},
|
|
141
|
+
// Picking mode and the tools.
|
|
142
|
+
setMode(m: string) {
|
|
143
|
+
const settings = { ...get().settings, mode: m };
|
|
144
|
+
set({ settings, on: true });
|
|
145
|
+
saveSettings(settings);
|
|
146
|
+
push();
|
|
147
|
+
},
|
|
148
|
+
pick() {
|
|
149
|
+
set({ on: !get().on });
|
|
150
|
+
push();
|
|
151
|
+
},
|
|
152
|
+
togglePause() {
|
|
153
|
+
set({ pause: !get().pause });
|
|
154
|
+
push();
|
|
155
|
+
},
|
|
156
|
+
toggleHide() {
|
|
157
|
+
set({ hide: !get().hide });
|
|
158
|
+
push();
|
|
159
|
+
},
|
|
160
|
+
toggleList() {
|
|
161
|
+
set({ list: !get().list });
|
|
162
|
+
},
|
|
163
|
+
toggleSettings() {
|
|
164
|
+
const open = !get().setOpen;
|
|
165
|
+
set({ setOpen: open, ...(open ? { list: true } : {}) });
|
|
166
|
+
},
|
|
167
|
+
// The Annotate button's second press, or the bar's own close: back to the page's own address.
|
|
168
|
+
close() {
|
|
169
|
+
set({ want: false, on: false, pause: false, list: false, px: null });
|
|
170
|
+
o.reload();
|
|
171
|
+
},
|
|
172
|
+
clear,
|
|
173
|
+
copy,
|
|
174
|
+
send,
|
|
175
|
+
// A setting changed: saved at once; the page is told the ones it acts on (colour, blocking, component names).
|
|
176
|
+
setting(k: keyof Settings, v: string | boolean) {
|
|
177
|
+
const settings = { ...get().settings, [k]: v };
|
|
178
|
+
set({ settings });
|
|
179
|
+
saveSettings(settings);
|
|
180
|
+
if (k === "color" || k === "block" || k === "components") push();
|
|
181
|
+
},
|
|
182
|
+
removeNote(n: number) {
|
|
183
|
+
setNotes(without(get().notes, n));
|
|
184
|
+
},
|
|
185
|
+
editNote(n: number, text: string) {
|
|
186
|
+
const next = editedComment(get().notes, n, text);
|
|
187
|
+
if (next !== get().notes) {
|
|
188
|
+
set({ notes: next });
|
|
189
|
+
saveNotes(o.wsKey, next);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
// Pressing a mode that is already on turns picking off.
|
|
193
|
+
mode(m: string) {
|
|
194
|
+
const s = get();
|
|
195
|
+
return s.on && s.settings.mode === m ? api.pick() : api.setMode(m);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
// Keys on the board's own side (the page forwards the same ones from inside the frame).
|
|
199
|
+
key(k: string) {
|
|
200
|
+
if (k === "toggle") return api.pick();
|
|
201
|
+
if (!get().on) return;
|
|
202
|
+
if (k === "p") api.togglePause();
|
|
203
|
+
else if (k === "h") api.toggleHide();
|
|
204
|
+
else if (k === "c") void copy();
|
|
205
|
+
else if (k === "s") void send();
|
|
206
|
+
else if (k === "x") clear();
|
|
207
|
+
else if (k === "esc") api.pick();
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
proxied: () => !!get().px,
|
|
211
|
+
active: () => get().on,
|
|
212
|
+
// Open this address, through the proxy when Annotate is on; returns the address for the frame, or null to load it directly.
|
|
213
|
+
async open(u: string): Promise<string | null> {
|
|
214
|
+
inject = false;
|
|
215
|
+
const { want } = get();
|
|
216
|
+
// A public site in the desktop app's webview: no proxy can add the script, so the board puts it in after each load.
|
|
217
|
+
if (want && webview() && isHttpUrl(u) && !isLoopbackUrl(u)) {
|
|
218
|
+
const origin = new URL(u).origin;
|
|
219
|
+
set({ px: { origin, token: newToken(), target: origin }, on: false });
|
|
220
|
+
inject = true;
|
|
221
|
+
return null; // loaded directly; dom-ready puts the annotator in
|
|
222
|
+
}
|
|
223
|
+
if (!want || !isLoopbackUrl(u)) {
|
|
224
|
+
set({ px: null, on: false, pause: false });
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const r = await post("/annotate/open", { url: u });
|
|
228
|
+
if (!r?.ok) {
|
|
229
|
+
set({ want: false, px: null });
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
set({ px: { origin: r.origin, token: r.token, target: new URL(u).origin } });
|
|
233
|
+
return r.url;
|
|
234
|
+
},
|
|
235
|
+
closeProxy() {
|
|
236
|
+
inject = false;
|
|
237
|
+
set({ px: null, on: false, pause: false });
|
|
238
|
+
},
|
|
239
|
+
toggle() {
|
|
240
|
+
set({ want: !get().want });
|
|
241
|
+
o.reload();
|
|
242
|
+
},
|
|
243
|
+
// The window's listeners: keys, the page's messages, the webview's own events. Returns the way back.
|
|
244
|
+
listen,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// A message from the page.
|
|
248
|
+
const handle = (d: any) => {
|
|
249
|
+
const { px } = get();
|
|
250
|
+
if (!px) return;
|
|
251
|
+
if (d.type === "ready") {
|
|
252
|
+
set({ on: true });
|
|
253
|
+
push();
|
|
254
|
+
} else if (d.type === "loc") {
|
|
255
|
+
const u = mapUrl(String(d.href), px.origin, px.target);
|
|
256
|
+
if (u) o.onLocation(u);
|
|
257
|
+
} else if (d.type === "key") api.key(String(d.key));
|
|
258
|
+
else if (d.type === "marker") {
|
|
259
|
+
set({ flash: Number(d.n) });
|
|
260
|
+
clearTimeout(flashTimer);
|
|
261
|
+
flashTimer = setTimeout(() => set({ flash: null }), 900);
|
|
262
|
+
} else if (d.type === "note" && d.note) {
|
|
263
|
+
const note = fromPage(d.note, get().notes.length, counter + 1, px);
|
|
264
|
+
if (!note) return;
|
|
265
|
+
counter++;
|
|
266
|
+
setNotes([...get().notes, note]);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
// Typed keys: Ctrl/Cmd+Shift+F toggles; P H C S X and Escape work when nothing is being typed into.
|
|
270
|
+
const onKey = (e: KeyboardEvent) => {
|
|
271
|
+
if (!shown || !get().px) return;
|
|
272
|
+
const t = e.target as HTMLElement;
|
|
273
|
+
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === "f") {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
return api.key("toggle");
|
|
276
|
+
}
|
|
277
|
+
if (
|
|
278
|
+
(t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) ||
|
|
279
|
+
e.ctrlKey ||
|
|
280
|
+
e.metaKey ||
|
|
281
|
+
e.altKey
|
|
282
|
+
)
|
|
283
|
+
return;
|
|
284
|
+
const k = e.key.toLowerCase();
|
|
285
|
+
if (k === "escape") api.key("esc");
|
|
286
|
+
else if (k.length === 1 && "phcsx".includes(k)) api.key(k);
|
|
287
|
+
};
|
|
288
|
+
const onMsg = (e: MessageEvent) => {
|
|
289
|
+
const { px } = get();
|
|
290
|
+
// A hidden pane still takes `ready` (a page that reloaded while away must get its picker config and markers again) and
|
|
291
|
+
// `loc` (its address); keys, notes and markers are for a pane on screen.
|
|
292
|
+
const t = e.data?.type;
|
|
293
|
+
if ((shown || t === "ready" || t === "loc") && px && accept(e, frameWin(), px.origin, px.token)) handle(e.data);
|
|
294
|
+
};
|
|
295
|
+
// The desktop app's webview: put the script in after each load, with this open's token (annotate.js reads __kzAnnToken).
|
|
296
|
+
// The webview's preload relays its messages; only ones carrying the token are taken (acceptHost).
|
|
297
|
+
let inject = false,
|
|
298
|
+
src: string | null = null;
|
|
299
|
+
const injectNow = async () => {
|
|
300
|
+
const web = webview();
|
|
301
|
+
if (!web || !inject || !get().px) return;
|
|
302
|
+
try {
|
|
303
|
+
const origin = new URL(web.getURL()).origin;
|
|
304
|
+
set({ px: { ...get().px!, origin, target: origin } });
|
|
305
|
+
} catch {
|
|
306
|
+
/* about:blank */
|
|
307
|
+
}
|
|
308
|
+
src ??= await fetch("/annotate.js").then(
|
|
309
|
+
(r) => (r.ok ? r.text() : null),
|
|
310
|
+
() => null,
|
|
311
|
+
);
|
|
312
|
+
const px = get().px;
|
|
313
|
+
if (!src || !inject || !px) return;
|
|
314
|
+
web.executeJavaScript(`window.__kzAnnToken=${JSON.stringify(px.token)};\n${src}`).catch(() => {});
|
|
315
|
+
};
|
|
316
|
+
const onIpc = (e: any) => {
|
|
317
|
+
const px = get().px;
|
|
318
|
+
if (px && e.channel === "kz-ann" && acceptHost(e.args?.[0], px.token)) handle(e.args[0]);
|
|
319
|
+
};
|
|
320
|
+
const onDom = () => void injectNow();
|
|
321
|
+
function listen() {
|
|
322
|
+
const web = webview();
|
|
323
|
+
addEventListener("keydown", onKey);
|
|
324
|
+
addEventListener("message", onMsg);
|
|
325
|
+
web?.addEventListener("dom-ready", onDom);
|
|
326
|
+
web?.addEventListener("ipc-message", onIpc);
|
|
327
|
+
return () => {
|
|
328
|
+
removeEventListener("keydown", onKey);
|
|
329
|
+
removeEventListener("message", onMsg);
|
|
330
|
+
web?.removeEventListener("dom-ready", onDom);
|
|
331
|
+
web?.removeEventListener("ipc-message", onIpc);
|
|
332
|
+
clearTimeout(flashTimer);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return api;
|
|
336
|
+
}
|