painapple-code 1.0.0__py3-none-any.whl
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.
- painapple_code/__init__.py +30 -0
- painapple_code/__main__.py +18 -0
- painapple_code/_version.py +24 -0
- painapple_code/auth_middleware.py +930 -0
- painapple_code/cli/__init__.py +204 -0
- painapple_code/cli/deploy/__init__.py +15 -0
- painapple_code/cli/deploy/claude_seed.py +41 -0
- painapple_code/cli/deploy/config.py +260 -0
- painapple_code/cli/deploy/container.py +715 -0
- painapple_code/cli/deploy/launch.py +163 -0
- painapple_code/cli/deploy/runtime.py +223 -0
- painapple_code/cli/lifecycle_cmd.py +443 -0
- painapple_code/cli/list_cmd.py +572 -0
- painapple_code/cli/manage_cmd.py +670 -0
- painapple_code/cli/netinfo.py +125 -0
- painapple_code/cli/profiles.py +390 -0
- painapple_code/cli/serve_args.py +163 -0
- painapple_code/cli/serve_config.py +256 -0
- painapple_code/cli/setup_cmd.py +664 -0
- painapple_code/cli/ui.py +438 -0
- painapple_code/cost_analytics.py +879 -0
- painapple_code/data/models.defaults.yaml +18 -0
- painapple_code/data/models.yaml +18 -0
- painapple_code/data/presets.defaults.json +32 -0
- painapple_code/data/strings.yaml +2269 -0
- painapple_code/helpers.py +406 -0
- painapple_code/paths.py +1514 -0
- painapple_code/prompt_explorer.py +984 -0
- painapple_code/providers/__init__.py +224 -0
- painapple_code/providers/base.py +710 -0
- painapple_code/providers/claude/__init__.py +74 -0
- painapple_code/providers/claude/capabilities.py +218 -0
- painapple_code/providers/claude/errors.py +79 -0
- painapple_code/providers/claude/launch.py +50 -0
- painapple_code/providers/claude/summary.py +89 -0
- painapple_code/providers/claude/translate.py +74 -0
- painapple_code/providers/claude_sdk/__init__.py +139 -0
- painapple_code/providers/claude_sdk/driver.py +412 -0
- painapple_code/providers/codex/__init__.py +87 -0
- painapple_code/providers/codex/capabilities.py +321 -0
- painapple_code/providers/codex/errors.py +70 -0
- painapple_code/providers/codex/launch.py +142 -0
- painapple_code/providers/codex/summary.py +196 -0
- painapple_code/providers/codex/translate.py +204 -0
- painapple_code/providers/codex_app_server/__init__.py +100 -0
- painapple_code/providers/codex_app_server/capabilities.py +41 -0
- painapple_code/providers/codex_app_server/launch.py +202 -0
- painapple_code/providers/codex_app_server/summary.py +291 -0
- painapple_code/providers/codex_app_server/translate.py +263 -0
- painapple_code/providers/codex_app_server/transport.py +238 -0
- painapple_code/routes/__init__.py +0 -0
- painapple_code/routes/api_agents.py +441 -0
- painapple_code/routes/api_app.py +368 -0
- painapple_code/routes/api_app_commit_sections.py +127 -0
- painapple_code/routes/api_app_config.py +997 -0
- painapple_code/routes/api_app_session_prefs.py +217 -0
- painapple_code/routes/api_browser.py +690 -0
- painapple_code/routes/api_commands.py +374 -0
- painapple_code/routes/api_costs.py +128 -0
- painapple_code/routes/api_drafts.py +139 -0
- painapple_code/routes/api_exec.py +149 -0
- painapple_code/routes/api_files.py +542 -0
- painapple_code/routes/api_git.py +657 -0
- painapple_code/routes/api_logs.py +649 -0
- painapple_code/routes/api_plugins.py +275 -0
- painapple_code/routes/api_project_config.py +418 -0
- painapple_code/routes/api_prompts.py +231 -0
- painapple_code/routes/api_providers.py +53 -0
- painapple_code/routes/api_search.py +411 -0
- painapple_code/routes/api_session_stash.py +234 -0
- painapple_code/routes/api_session_welcome.py +151 -0
- painapple_code/routes/api_sessions.py +742 -0
- painapple_code/routes/api_shadow.py +323 -0
- painapple_code/routes/api_shadow_db.py +512 -0
- painapple_code/routes/api_shadow_files.py +332 -0
- painapple_code/routes/api_shadow_search.py +476 -0
- painapple_code/routes/api_skills.py +610 -0
- painapple_code/routes/api_tasks.py +147 -0
- painapple_code/routes/api_terminal.py +540 -0
- painapple_code/routes/api_upload.py +293 -0
- painapple_code/routes/api_viewer.py +229 -0
- painapple_code/routes/dependencies.py +109 -0
- painapple_code/routes/ws_chat.py +837 -0
- painapple_code/server.py +2208 -0
- painapple_code/server_logging.py +263 -0
- painapple_code/services/__init__.py +0 -0
- painapple_code/services/agent_session.py +2738 -0
- painapple_code/session_store.py +253 -0
- painapple_code/session_store_core.py +879 -0
- painapple_code/shadow_db.py +830 -0
- painapple_code/shadow_db_plans.py +369 -0
- painapple_code/shadow_db_queries.py +595 -0
- painapple_code/shadow_db_schema.py +676 -0
- painapple_code/shadow_git.py +1296 -0
- painapple_code/shadow_git_frontmatter.py +314 -0
- painapple_code/shadow_git_sections.py +520 -0
- painapple_code/shadow_git_summary.py +462 -0
- painapple_code/shadow_parser.py +560 -0
- painapple_code/static/css/00-variables.css +276 -0
- painapple_code/static/css/01-base.css +245 -0
- painapple_code/static/css/02-tooltips.css +36 -0
- painapple_code/static/css/09-left-rail.css +448 -0
- painapple_code/static/css/10-header.css +777 -0
- painapple_code/static/css/11-connection-bar.css +120 -0
- painapple_code/static/css/20-messages.css +750 -0
- painapple_code/static/css/21-tool-blocks.css +2340 -0
- painapple_code/static/css/22-edit-diff.css +619 -0
- painapple_code/static/css/23-thinking.css +1584 -0
- painapple_code/static/css/24-background-tasks.css +359 -0
- painapple_code/static/css/25-context-block.css +252 -0
- painapple_code/static/css/26-session-setup.css +144 -0
- painapple_code/static/css/30-markdown.css +854 -0
- painapple_code/static/css/40-input.css +2418 -0
- painapple_code/static/css/41-autocomplete.css +127 -0
- painapple_code/static/css/42-activity-strip.css +97 -0
- painapple_code/static/css/43-file-autocomplete.css +121 -0
- painapple_code/static/css/44-snippets-autocomplete.css +224 -0
- painapple_code/static/css/45-selection-bar.css +433 -0
- painapple_code/static/css/46-keyboard-bar.css +119 -0
- painapple_code/static/css/47-keyboard-longpress.css +116 -0
- painapple_code/static/css/47-token-profile.css +106 -0
- painapple_code/static/css/50-welcome.css +3095 -0
- painapple_code/static/css/51-modals.css +301 -0
- painapple_code/static/css/52-utilities.css +77 -0
- painapple_code/static/css/53-image-upload.css +456 -0
- painapple_code/static/css/54-todo-list.css +102 -0
- painapple_code/static/css/55-file-upload.css +113 -0
- painapple_code/static/css/56-chat-navigator.css +218 -0
- painapple_code/static/css/56-permission-card.css +332 -0
- painapple_code/static/css/56-plan-approval.css +204 -0
- painapple_code/static/css/56-question-form.css +602 -0
- painapple_code/static/css/57-swipe-indicator.css +95 -0
- painapple_code/static/css/58-session-families.css +627 -0
- painapple_code/static/css/59-about.css +196 -0
- painapple_code/static/css/61-log-explorer.css +723 -0
- painapple_code/static/css/62-json-tree.css +489 -0
- painapple_code/static/css/62-skills-widget.css +650 -0
- painapple_code/static/css/63-commands-widget.css +30 -0
- painapple_code/static/css/63-plugins-widget.css +174 -0
- painapple_code/static/css/63-terminal.css +516 -0
- painapple_code/static/css/64-search-files-widget.css +448 -0
- painapple_code/static/css/65-snippets-widget.css +426 -0
- painapple_code/static/css/66-active-sessions.css +979 -0
- painapple_code/static/css/66-agents-widget.css +265 -0
- painapple_code/static/css/66-file-explorer-widget.css +855 -0
- painapple_code/static/css/66-git-panel.css +791 -0
- painapple_code/static/css/66-history-explorer.css +1496 -0
- painapple_code/static/css/67-diff-viewer.css +602 -0
- painapple_code/static/css/67-editor-view.css +748 -0
- painapple_code/static/css/67-file-preview-widget.css +1873 -0
- painapple_code/static/css/68-browser-widget.css +337 -0
- painapple_code/static/css/68-compare-wizard.css +355 -0
- painapple_code/static/css/68-csv-preview.css +106 -0
- painapple_code/static/css/68-diff-preview.css +103 -0
- painapple_code/static/css/68-helpers-install-widget.css +491 -0
- painapple_code/static/css/68-image-annotate.css +346 -0
- painapple_code/static/css/68-terminal-view.css +98 -0
- painapple_code/static/css/68-uploads-widget.css +229 -0
- painapple_code/static/css/69-cost-analytics.css +537 -0
- painapple_code/static/css/70-config-panel.css +3736 -0
- painapple_code/static/css/70-excalidraw.css +136 -0
- painapple_code/static/css/70-prompt-explorer.css +890 -0
- painapple_code/static/css/71-chart.css +111 -0
- painapple_code/static/css/72-discussion-sidebar.css +678 -0
- painapple_code/static/css/74-debug-logs.css +656 -0
- painapple_code/static/css/80-open-dialog.css +146 -0
- painapple_code/static/css/80-quick-switcher.css +383 -0
- painapple_code/static/css/80-widget-system.css +1763 -0
- painapple_code/static/css/81-quick-actions.css +1020 -0
- painapple_code/static/css/82-context-popover.css +1233 -0
- painapple_code/static/css/83-context-menu.css +339 -0
- painapple_code/static/css/85-lazy-loading.css +102 -0
- painapple_code/static/css/86-zen-mode.css +708 -0
- painapple_code/static/css/87-grid-switcher.css +346 -0
- painapple_code/static/css/login.css +198 -0
- painapple_code/static/dist/app.bundle.js +7177 -0
- painapple_code/static/feature-triage.html +446 -0
- painapple_code/static/icons/apple-touch-icon.png +0 -0
- painapple_code/static/icons/favicon-32.png +0 -0
- painapple_code/static/icons/favicon.ico +0 -0
- painapple_code/static/icons/icon-128.png +0 -0
- painapple_code/static/icons/icon-144.png +0 -0
- painapple_code/static/icons/icon-152.png +0 -0
- painapple_code/static/icons/icon-180.png +0 -0
- painapple_code/static/icons/icon-192.png +0 -0
- painapple_code/static/icons/icon-384.png +0 -0
- painapple_code/static/icons/icon-512.png +0 -0
- painapple_code/static/icons/icon-72.png +0 -0
- painapple_code/static/icons/icon-96.png +0 -0
- painapple_code/static/js/action-delegate.js +187 -0
- painapple_code/static/js/activity-strip.js +193 -0
- painapple_code/static/js/app/context-menus.js +619 -0
- painapple_code/static/js/app/file-preview.js +163 -0
- painapple_code/static/js/app/init-ui.js +574 -0
- painapple_code/static/js/app/input-events.js +561 -0
- painapple_code/static/js/app/input-resize.js +313 -0
- painapple_code/static/js/app/message-actions.js +419 -0
- painapple_code/static/js/app/panels.js +210 -0
- painapple_code/static/js/app/rendering-delegators.js +246 -0
- painapple_code/static/js/app/server-loading.js +365 -0
- painapple_code/static/js/app/session-ops.js +287 -0
- painapple_code/static/js/app/session-switch.js +443 -0
- painapple_code/static/js/app/settings-helpers.js +280 -0
- painapple_code/static/js/app/startup-welcome.js +290 -0
- painapple_code/static/js/app-context.js +157 -0
- painapple_code/static/js/app.js +2134 -0
- painapple_code/static/js/auth-fetch.js +46 -0
- painapple_code/static/js/background-tasks.js +274 -0
- painapple_code/static/js/boot.js +73 -0
- painapple_code/static/js/caret-position.js +171 -0
- painapple_code/static/js/chat-navigator.js +710 -0
- painapple_code/static/js/chat-search.js +323 -0
- painapple_code/static/js/command-executor.js +176 -0
- painapple_code/static/js/command-store.js +497 -0
- painapple_code/static/js/components.js +1414 -0
- painapple_code/static/js/config.js +218 -0
- painapple_code/static/js/context-menu.js +740 -0
- painapple_code/static/js/controllers/chat-controller.js +4252 -0
- painapple_code/static/js/controllers/dialog-controller.js +217 -0
- painapple_code/static/js/controllers/tab-controller.js +1828 -0
- painapple_code/static/js/controllers/thinking-controller.js +915 -0
- painapple_code/static/js/diff-utils.js +486 -0
- painapple_code/static/js/drafts-pill.js +95 -0
- painapple_code/static/js/editor-view.js +815 -0
- painapple_code/static/js/effort-settings.js +430 -0
- painapple_code/static/js/feature-triage.js +811 -0
- painapple_code/static/js/file-autocomplete.js +516 -0
- painapple_code/static/js/file-tabs.js +123 -0
- painapple_code/static/js/gestures.js +448 -0
- painapple_code/static/js/grid-switcher.js +334 -0
- painapple_code/static/js/input-handler.js +1472 -0
- painapple_code/static/js/keyboard-bar.js +495 -0
- painapple_code/static/js/layout-switcher.js +109 -0
- painapple_code/static/js/linkify-utils.js +200 -0
- painapple_code/static/js/login.js +141 -0
- painapple_code/static/js/open-dialog.js +879 -0
- painapple_code/static/js/orphan-terminals.js +373 -0
- painapple_code/static/js/path-utils.js +179 -0
- painapple_code/static/js/perf-marks.js +102 -0
- painapple_code/static/js/permission-settings.js +475 -0
- painapple_code/static/js/pointer-input.js +59 -0
- painapple_code/static/js/preview/json-tree-menu.js +226 -0
- painapple_code/static/js/preview/json-tree-toolbar.js +291 -0
- painapple_code/static/js/preview/json-tree.js +457 -0
- painapple_code/static/js/preview/preview-breadcrumb.js +387 -0
- painapple_code/static/js/preview/preview-edit.js +367 -0
- painapple_code/static/js/preview/preview-events.js +361 -0
- painapple_code/static/js/preview/preview-history.js +567 -0
- painapple_code/static/js/preview/preview-inline-edit.js +869 -0
- painapple_code/static/js/preview/preview-poll.js +108 -0
- painapple_code/static/js/preview/preview-render.js +572 -0
- painapple_code/static/js/preview/preview-search.js +421 -0
- painapple_code/static/js/preview/preview-state.js +256 -0
- painapple_code/static/js/preview/preview-utils.js +251 -0
- painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
- painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
- painapple_code/static/js/preview-plugins/diff-plugin.js +258 -0
- painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
- painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
- painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
- painapple_code/static/js/preview-plugins/index.js +34 -0
- painapple_code/static/js/preview-plugins/json-plugin.js +99 -0
- painapple_code/static/js/preview-plugins/jsonl-plugin.js +152 -0
- painapple_code/static/js/preview-plugins/markdown-plugin.js +266 -0
- painapple_code/static/js/preview-plugins/panzoom-plugin.js +63 -0
- painapple_code/static/js/preview-plugins/plugin-helpers.js +282 -0
- painapple_code/static/js/project-color-picker.js +110 -0
- painapple_code/static/js/project-colors.js +163 -0
- painapple_code/static/js/prompt-favorites.js +187 -0
- painapple_code/static/js/quick-actions-menu.js +1736 -0
- painapple_code/static/js/quick-actions-registry.js +1239 -0
- painapple_code/static/js/quick-switcher/controller.js +294 -0
- painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
- painapple_code/static/js/quick-switcher/index.js +30 -0
- painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
- painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
- painapple_code/static/js/quick-switcher/providers/file-provider.js +291 -0
- painapple_code/static/js/quick-switcher/providers/panel-provider.js +132 -0
- painapple_code/static/js/quick-switcher/providers/project-provider.js +361 -0
- painapple_code/static/js/quick-switcher/providers/read-files-provider.js +104 -0
- painapple_code/static/js/quick-switcher/providers/skills-provider.js +129 -0
- painapple_code/static/js/quick-switcher/registry.js +69 -0
- painapple_code/static/js/quick-switcher/ui/item.js +54 -0
- painapple_code/static/js/quick-switcher/ui/picker.js +464 -0
- painapple_code/static/js/recent-opens.js +40 -0
- painapple_code/static/js/scroll-manager.js +530 -0
- painapple_code/static/js/scroll-state-machine.js +359 -0
- painapple_code/static/js/selection/action-bar.js +793 -0
- painapple_code/static/js/selection/index.js +15 -0
- painapple_code/static/js/selection/selection-handler.js +877 -0
- painapple_code/static/js/selection/state.js +181 -0
- painapple_code/static/js/session/agent-progress.js +202 -0
- painapple_code/static/js/session/handle-agent-message.js +481 -0
- painapple_code/static/js/session/handle-message.js +550 -0
- painapple_code/static/js/session/interactive.js +587 -0
- painapple_code/static/js/session/message-store.js +271 -0
- painapple_code/static/js/session/messages.js +253 -0
- painapple_code/static/js/session/persistence.js +179 -0
- painapple_code/static/js/session/restore.js +136 -0
- painapple_code/static/js/session/sync.js +333 -0
- painapple_code/static/js/session-container-pool.js +371 -0
- painapple_code/static/js/session-setup-panel.js +274 -0
- painapple_code/static/js/session.js +1047 -0
- painapple_code/static/js/shortcut-hints.js +272 -0
- painapple_code/static/js/shortcuts.js +1146 -0
- painapple_code/static/js/skills-autocomplete.js +262 -0
- painapple_code/static/js/snippets-autocomplete.js +738 -0
- painapple_code/static/js/stash-refs-view.js +83 -0
- painapple_code/static/js/stash-ui.js +768 -0
- painapple_code/static/js/stash.js +785 -0
- painapple_code/static/js/status-bar.js +1184 -0
- painapple_code/static/js/token-profile.js +274 -0
- painapple_code/static/js/tool-renderer-blocks.js +1626 -0
- painapple_code/static/js/tool-renderer-thinking.js +813 -0
- painapple_code/static/js/tool-renderer.js +1500 -0
- painapple_code/static/js/tooltips.js +197 -0
- painapple_code/static/js/upload-manager.js +1019 -0
- painapple_code/static/js/utils.js +521 -0
- painapple_code/static/js/welcome/api.js +363 -0
- painapple_code/static/js/welcome/cards.js +626 -0
- painapple_code/static/js/welcome/context-menu.js +585 -0
- painapple_code/static/js/welcome/families.js +801 -0
- painapple_code/static/js/welcome/preview.js +234 -0
- painapple_code/static/js/welcome/state.js +129 -0
- painapple_code/static/js/welcome.js +1874 -0
- painapple_code/static/js/widget-system/base-widget.js +717 -0
- painapple_code/static/js/widget-system/device-manager.js +178 -0
- painapple_code/static/js/widget-system/event-bus.js +152 -0
- painapple_code/static/js/widget-system/icons.js +120 -0
- painapple_code/static/js/widget-system/index.js +49 -0
- painapple_code/static/js/widget-system/init.js +54 -0
- painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
- painapple_code/static/js/widget-system/types/floating.js +915 -0
- painapple_code/static/js/widget-system/types/index.js +40 -0
- painapple_code/static/js/widget-system/types/modal.js +147 -0
- painapple_code/static/js/widget-system/types/sidebar.js +158 -0
- painapple_code/static/js/widget-system/types/tab.js +146 -0
- painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
- painapple_code/static/js/widget-system/widget-manager.js +1187 -0
- painapple_code/static/js/widgets/about-widget.js +260 -0
- painapple_code/static/js/widgets/active-sessions-widget.js +760 -0
- painapple_code/static/js/widgets/agents-widget.js +897 -0
- painapple_code/static/js/widgets/browser-widget.js +579 -0
- painapple_code/static/js/widgets/commands-widget.js +694 -0
- painapple_code/static/js/widgets/config/commit-sections.js +449 -0
- painapple_code/static/js/widgets/config/dir-autocomplete.js +224 -0
- painapple_code/static/js/widgets/config/gestures.js +161 -0
- painapple_code/static/js/widgets/config/models-tab.js +988 -0
- painapple_code/static/js/widgets/config/quick-actions-tab.js +882 -0
- painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
- painapple_code/static/js/widgets/config/state.js +517 -0
- painapple_code/static/js/widgets/config/system-controls.js +90 -0
- painapple_code/static/js/widgets/config-widget.js +1535 -0
- painapple_code/static/js/widgets/cost-analytics-widget.js +621 -0
- painapple_code/static/js/widgets/debug-widget.js +693 -0
- painapple_code/static/js/widgets/diff-viewer-widget.js +1420 -0
- painapple_code/static/js/widgets/discussion-widget.js +1107 -0
- painapple_code/static/js/widgets/file-explorer-widget.js +2166 -0
- painapple_code/static/js/widgets/file-preview-widget.js +861 -0
- painapple_code/static/js/widgets/git-widget.js +794 -0
- painapple_code/static/js/widgets/helpers-install-widget.js +720 -0
- painapple_code/static/js/widgets/history-explorer-widget.js +1804 -0
- painapple_code/static/js/widgets/image-annotate-widget.js +951 -0
- painapple_code/static/js/widgets/image-preview-widget.js +692 -0
- painapple_code/static/js/widgets/index.js +176 -0
- painapple_code/static/js/widgets/log-explorer-widget.js +1057 -0
- painapple_code/static/js/widgets/plugins-widget.js +305 -0
- painapple_code/static/js/widgets/prompt-explorer-widget.js +1119 -0
- painapple_code/static/js/widgets/search-files-widget.js +529 -0
- painapple_code/static/js/widgets/skills-widget.js +843 -0
- painapple_code/static/js/widgets/snippets-widget.js +479 -0
- painapple_code/static/js/widgets/sub-agents-widget.js +333 -0
- painapple_code/static/js/widgets/tasks-widget.js +379 -0
- painapple_code/static/js/widgets/terminal/connection.js +283 -0
- painapple_code/static/js/widgets/terminal/gestures.js +357 -0
- painapple_code/static/js/widgets/terminal/init.js +642 -0
- painapple_code/static/js/widgets/terminal/link-providers.js +532 -0
- painapple_code/static/js/widgets/terminal/osc52.js +213 -0
- painapple_code/static/js/widgets/terminal/render.js +159 -0
- painapple_code/static/js/widgets/terminal/size.js +54 -0
- painapple_code/static/js/widgets/terminal/state.js +211 -0
- painapple_code/static/js/widgets/terminal/wrap-utils.js +101 -0
- painapple_code/static/js/widgets/terminal-widget.js +793 -0
- painapple_code/static/js/widgets/uploads-widget.js +461 -0
- painapple_code/static/js/widgets/zen-widget.js +1001 -0
- painapple_code/static/login.html +51 -0
- painapple_code/static/manifest.json +73 -0
- painapple_code/static/sw.js +293 -0
- painapple_code/static/vendor/LICENSES.txt +769 -0
- painapple_code/static/vendor/README.md +103 -0
- painapple_code/static/vendor/codemirror.js +35 -0
- painapple_code/static/vendor/codemirror.js.LEGAL.txt +304 -0
- painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
- painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
- painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
- painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
- painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
- painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
- painapple_code/static/vendor/highlight.min.js +1213 -0
- painapple_code/static/vendor/marked.min.js +6 -0
- painapple_code/static/vendor/purify.min.js +3 -0
- painapple_code/static/vendor/xterm-addon-fit.js +2 -0
- painapple_code/static/vendor/xterm.css +209 -0
- painapple_code/static/vendor/xterm.js +2 -0
- painapple_code/static/web-client.html +635 -0
- painapple_code/subprocess_registry.py +535 -0
- painapple_code/tls_cert.py +79 -0
- painapple_code/tools/agents/shadow-git-helper.md +400 -0
- painapple_code/tools/excalidraw-to-svg.js +143 -0
- painapple_code/tools/install-helpers.sh +148 -0
- painapple_code/tools/shadow-git +320 -0
- painapple_code/tools/shadow-query +120 -0
- painapple_code/tools/vegalite-to-svg.js +79 -0
- painapple_code/turn_query.py +766 -0
- painapple_code/turn_tracker.py +221 -0
- painapple_code/utils/__init__.py +0 -0
- painapple_code/utils/agent_cli.py +306 -0
- painapple_code/utils/chart.py +103 -0
- painapple_code/utils/excalidraw.py +107 -0
- painapple_code/utils/file_lock.py +162 -0
- painapple_code/utils/file_paths.py +648 -0
- painapple_code/utils/generate_icons.py +251 -0
- painapple_code/utils/proc.py +205 -0
- painapple_code/utils/pty_backend.py +59 -0
- painapple_code/utils/pty_posix.py +160 -0
- painapple_code/utils/pty_windows.py +245 -0
- painapple_code/utils/token_profiles.py +91 -0
- painapple_code/viewer_templates.py +657 -0
- painapple_code/welcome_search.py +879 -0
- painapple_code-1.0.0.dist-info/METADATA +292 -0
- painapple_code-1.0.0.dist-info/RECORD +436 -0
- painapple_code-1.0.0.dist-info/WHEEL +5 -0
- painapple_code-1.0.0.dist-info/entry_points.txt +2 -0
- painapple_code-1.0.0.dist-info/licenses/LICENSE +661 -0
- painapple_code-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +261 -0
- painapple_code-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1874 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Welcome Screen - Session Discovery (orchestrator).
|
|
3
|
+
*
|
|
4
|
+
* Public API surface for app.js, controllers, and other consumers. The
|
|
5
|
+
* heavy lifting (rendering, family building, preview, context menus, data
|
|
6
|
+
* loading) lives under `welcome/`:
|
|
7
|
+
*
|
|
8
|
+
* welcome/state.js Shared state object + module-level mutables
|
|
9
|
+
* welcome/cards.js Session/family/fork/favorite card renderers
|
|
10
|
+
* welcome/families.js Family build + grouping + compact renderers + task mode
|
|
11
|
+
* welcome/preview.js Session preview bottom sheet
|
|
12
|
+
* welcome/context-menu.js Long-press + session/project context menus
|
|
13
|
+
* welcome/api.js Data loaders + favorite/rename mutations + project filter
|
|
14
|
+
*
|
|
15
|
+
* This file glues them together: main render (renderWelcomeScreen),
|
|
16
|
+
* keyboard navigation, event-listener wiring, "back to sessions" state
|
|
17
|
+
* persistence, and the 20 public exports.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { CONFIG, debug } from './config.js';
|
|
21
|
+
import { escapeHtml, extractApiError } from './utils.js';
|
|
22
|
+
import { loadUserConfig, saveUserConfig } from './widgets/config-widget.js';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
state,
|
|
26
|
+
expandedGroups,
|
|
27
|
+
expandedFamilies,
|
|
28
|
+
fullyExpandedFamilies,
|
|
29
|
+
RECENT_INCREMENT,
|
|
30
|
+
recentLimit,
|
|
31
|
+
favoritesLimit,
|
|
32
|
+
longPress,
|
|
33
|
+
savedWelcomeState,
|
|
34
|
+
saveWelcomeState,
|
|
35
|
+
} from './welcome/state.js';
|
|
36
|
+
import {
|
|
37
|
+
renderSessionFamily,
|
|
38
|
+
renderSearchBar,
|
|
39
|
+
patchSearchBar,
|
|
40
|
+
renderFavoritesSection,
|
|
41
|
+
} from './welcome/cards.js';
|
|
42
|
+
import {
|
|
43
|
+
buildSessionFamilies,
|
|
44
|
+
groupFamiliesByProject,
|
|
45
|
+
renderTaskMode,
|
|
46
|
+
renderFamilyProjectGroup,
|
|
47
|
+
renderProjectsQuickStart,
|
|
48
|
+
} from './welcome/families.js';
|
|
49
|
+
import {
|
|
50
|
+
showPreview,
|
|
51
|
+
closeSessionPreview,
|
|
52
|
+
} from './welcome/preview.js';
|
|
53
|
+
import {
|
|
54
|
+
setupLongPress,
|
|
55
|
+
wasLongPressRecent,
|
|
56
|
+
showProjectContextMenu,
|
|
57
|
+
closeWelcomeContextMenu,
|
|
58
|
+
} from './welcome/context-menu.js';
|
|
59
|
+
import {
|
|
60
|
+
loadRecentSessions,
|
|
61
|
+
loadProjects,
|
|
62
|
+
loadFavorites,
|
|
63
|
+
loadActiveSessions,
|
|
64
|
+
updateOpenSessionIds,
|
|
65
|
+
mergeLocalSessions,
|
|
66
|
+
toggleFavorite,
|
|
67
|
+
setProjectFilter,
|
|
68
|
+
clearProjectFilter,
|
|
69
|
+
filterSelectedProject,
|
|
70
|
+
} from './welcome/api.js';
|
|
71
|
+
import { basename } from './path-utils.js';
|
|
72
|
+
|
|
73
|
+
// Re-export close helpers used by app.js for global Escape handling.
|
|
74
|
+
export { closeSessionPreview, closeWelcomeContextMenu };
|
|
75
|
+
|
|
76
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
77
|
+
// MAIN WELCOME SCREEN
|
|
78
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
79
|
+
|
|
80
|
+
// How many project chips the row shows before collapsing behind "+N more".
|
|
81
|
+
// Matches the unvisited row's own default cap so the two read as one grid.
|
|
82
|
+
const PROJECTS_DEFAULT_CAP = 8;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render the full welcome screen.
|
|
86
|
+
*/
|
|
87
|
+
export function renderWelcomeScreen(container) {
|
|
88
|
+
const { sessions: allSessions, projects, isSearching, taskMode, pendingTask, quickSearchFilter } = state;
|
|
89
|
+
|
|
90
|
+
// Apply project filter first (if set)
|
|
91
|
+
let sessions = allSessions;
|
|
92
|
+
const projectFilter = state.projectFilter;
|
|
93
|
+
if (projectFilter) {
|
|
94
|
+
sessions = sessions.filter(s => s.project_path === projectFilter.path);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Then apply quick search filter
|
|
98
|
+
if (quickSearchFilter) {
|
|
99
|
+
const q = quickSearchFilter.toLowerCase();
|
|
100
|
+
sessions = sessions.filter(s => {
|
|
101
|
+
const name = (s.name || '').toLowerCase();
|
|
102
|
+
const summary = (s.summary || '').toLowerCase();
|
|
103
|
+
const project = (s.project || '').toLowerCase();
|
|
104
|
+
const projectPath = (s.project_path || '').toLowerCase();
|
|
105
|
+
return name.includes(q) || summary.includes(q) || project.includes(q) || projectPath.includes(q);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Filter projects based on quick search too
|
|
110
|
+
let filteredProjects = projects || [];
|
|
111
|
+
if (quickSearchFilter) {
|
|
112
|
+
const q = quickSearchFilter.toLowerCase();
|
|
113
|
+
filteredProjects = filteredProjects.filter(p =>
|
|
114
|
+
p.name.toLowerCase().includes(q) ||
|
|
115
|
+
p.path.toLowerCase().includes(q)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Task mode - showing related sessions for a task
|
|
120
|
+
if (taskMode && pendingTask) {
|
|
121
|
+
container.innerHTML = `
|
|
122
|
+
<div id="welcome" class="welcome-screen welcome-screen--task">
|
|
123
|
+
${renderTaskMode(state.searchResults?.results || [], pendingTask)}
|
|
124
|
+
</div>
|
|
125
|
+
`;
|
|
126
|
+
attachEventListeners(container);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Default welcome screen - build session families for grouping
|
|
131
|
+
// Build family map from all sessions
|
|
132
|
+
const familyMap = buildSessionFamilies(sessions);
|
|
133
|
+
state.familyMap = familyMap;
|
|
134
|
+
|
|
135
|
+
// Get root sessions (families) sorted by last activity of root or newest branch
|
|
136
|
+
const getFamilyActivity = (family) => {
|
|
137
|
+
const rootDate = new Date(family.root?.last_activity || family.root?.created_at || 0);
|
|
138
|
+
const branchDates = family.branches.map(b =>
|
|
139
|
+
new Date(b.session.last_activity || b.session.created_at || 0)
|
|
140
|
+
);
|
|
141
|
+
return Math.max(rootDate, ...branchDates);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const sortedFamilies = Array.from(familyMap.values())
|
|
145
|
+
.filter(f => f.root) // Only families with a visible root
|
|
146
|
+
.sort((a, b) => getFamilyActivity(b) - getFamilyActivity(a));
|
|
147
|
+
|
|
148
|
+
// Split into recent (using recentLimit) and rest
|
|
149
|
+
// When quick search is active, show more results (10 instead of default 3)
|
|
150
|
+
const effectiveLimit = quickSearchFilter ? 10 : recentLimit.value;
|
|
151
|
+
const recentFamilies = sortedFamilies.slice(0, effectiveLimit);
|
|
152
|
+
const remainingFamilies = sortedFamilies.slice(effectiveLimit);
|
|
153
|
+
const hasMoreRecent = sortedFamilies.length > effectiveLimit;
|
|
154
|
+
|
|
155
|
+
// Group remaining families by project
|
|
156
|
+
const projectGroups = groupFamiliesByProject(remainingFamilies);
|
|
157
|
+
|
|
158
|
+
// Determine if we're filtering
|
|
159
|
+
const hasFilter = !!quickSearchFilter || !!projectFilter;
|
|
160
|
+
|
|
161
|
+
// Build selectable items list for keyboard navigation:
|
|
162
|
+
// Projects first, then unvisited workspace siblings, then favorites, then recent sessions
|
|
163
|
+
// Projects are ranked by session count and capped, same as the unvisited
|
|
164
|
+
// row below — but with an expand toggle, because otherwise project #9 is
|
|
165
|
+
// unreachable from the UI entirely (no overflow, no scroll, nothing).
|
|
166
|
+
const sortedProjects = filteredProjects
|
|
167
|
+
.slice()
|
|
168
|
+
.sort((a, b) => (b.session_count || 0) - (a.session_count || 0));
|
|
169
|
+
const projectsTotal = sortedProjects.length;
|
|
170
|
+
const projectsCollapsible = projectsTotal > PROJECTS_DEFAULT_CAP;
|
|
171
|
+
let topFilteredProjects = state.projectsExpanded
|
|
172
|
+
? sortedProjects
|
|
173
|
+
: sortedProjects.slice(0, PROJECTS_DEFAULT_CAP);
|
|
174
|
+
|
|
175
|
+
// The actively filtered project always gets a chip, wherever it ranks.
|
|
176
|
+
// Session count is a poor proxy for "what the user cares about right now",
|
|
177
|
+
// and the filtered project is precisely the one they've told us about — a
|
|
178
|
+
// row that omits it while showing eight others reads as "this project
|
|
179
|
+
// doesn't exist".
|
|
180
|
+
if (projectFilter && !topFilteredProjects.some(p => p.path === projectFilter.path)) {
|
|
181
|
+
const pinned = sortedProjects.find(p => p.path === projectFilter.path);
|
|
182
|
+
if (pinned) topFilteredProjects = [pinned, ...topFilteredProjects];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Filter workspace dirs by quick search too (name + path match like projects)
|
|
186
|
+
let filteredWorkspaceDirs = state.workspaceDirs || [];
|
|
187
|
+
if (quickSearchFilter) {
|
|
188
|
+
const q = quickSearchFilter.toLowerCase();
|
|
189
|
+
filteredWorkspaceDirs = filteredWorkspaceDirs.filter(d =>
|
|
190
|
+
d.name.toLowerCase().includes(q) ||
|
|
191
|
+
d.path.toLowerCase().includes(q)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
// Default cap is 8, but bump to 20 on a sparse welcome (≤2 session
|
|
195
|
+
// families) so the empty space below gets used. User-toggled expand
|
|
196
|
+
// still wins and shows everything.
|
|
197
|
+
const unvisitedTotal = filteredWorkspaceDirs.length;
|
|
198
|
+
const defaultUnvisitedCap = sortedFamilies.length <= 2 ? 20 : 8;
|
|
199
|
+
const topWorkspaceDirs = state.unvisitedExpanded
|
|
200
|
+
? filteredWorkspaceDirs
|
|
201
|
+
: filteredWorkspaceDirs.slice(0, defaultUnvisitedCap);
|
|
202
|
+
|
|
203
|
+
// Compute filtered favorites (same logic as renderFavoritesSection)
|
|
204
|
+
let navFavorites = state.favorites.filter(f => f.session !== null);
|
|
205
|
+
if (projectFilter) {
|
|
206
|
+
navFavorites = navFavorites.filter(f => {
|
|
207
|
+
const s = f.session || {};
|
|
208
|
+
return s.project_path === projectFilter.path;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (quickSearchFilter) {
|
|
212
|
+
const q = quickSearchFilter.toLowerCase();
|
|
213
|
+
navFavorites = navFavorites.filter(f => {
|
|
214
|
+
const s = f.session || {};
|
|
215
|
+
const name = (s.name || '').toLowerCase();
|
|
216
|
+
const summary = (s.summary || '').toLowerCase();
|
|
217
|
+
const project = (s.project || '').toLowerCase();
|
|
218
|
+
const note = (f.note || '').toLowerCase();
|
|
219
|
+
return name.includes(q) || summary.includes(q) || project.includes(q) || note.includes(q);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// Must match what renderFavorites() actually shows, so arrow-key nav never
|
|
223
|
+
// targets a collapsed-away row.
|
|
224
|
+
const visibleFavorites = navFavorites.slice(0, favoritesLimit.value);
|
|
225
|
+
|
|
226
|
+
state.selectableItems = [
|
|
227
|
+
...topFilteredProjects.map(p => ({ type: 'project', path: p.path, name: p.name })),
|
|
228
|
+
...topWorkspaceDirs.map(d => ({ type: 'project', path: d.path, name: d.name })),
|
|
229
|
+
...visibleFavorites.map(f => ({ type: 'favorite', session: f.session, session_id: f.session_id })),
|
|
230
|
+
...recentFamilies.map(f => ({ type: 'session', session: f.root }))
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
// Track section boundaries for keyboard navigation. Unvisited workspace
|
|
234
|
+
// dirs share the "project row" with real projects — same chip class, same
|
|
235
|
+
// start-session action — so they live in the projects span for nav math.
|
|
236
|
+
const projectsRowCount = topFilteredProjects.length + topWorkspaceDirs.length;
|
|
237
|
+
state.projectCount = projectsRowCount;
|
|
238
|
+
state.favoritesStartIndex = projectsRowCount;
|
|
239
|
+
state.sessionStartIndex = projectsRowCount + visibleFavorites.length;
|
|
240
|
+
|
|
241
|
+
// While a search is running the first result is always selected. It's the
|
|
242
|
+
// only affordance that tells the user the list is arrow-navigable, and it
|
|
243
|
+
// makes type-then-Enter open the top hit like any other search box. Owned
|
|
244
|
+
// here rather than in the input handler so every path that moves the filter
|
|
245
|
+
// (typing, typeIntoQuickSearch, openQuickSearch with a seed) gets it — and
|
|
246
|
+
// so a narrowing search that pushed the selection past the end re-anchors
|
|
247
|
+
// instead of pointing at nothing.
|
|
248
|
+
if (quickSearchFilter && state.selectableItems.length > 0) {
|
|
249
|
+
if (state.selectedResultIndex < 0 || state.selectedResultIndex >= state.selectableItems.length) {
|
|
250
|
+
state.selectedResultIndex = 0;
|
|
251
|
+
}
|
|
252
|
+
} else if (state.selectedResultIndex >= state.selectableItems.length) {
|
|
253
|
+
state.selectedResultIndex = -1;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Section start indices for rendering
|
|
257
|
+
const favoritesStartIndex = state.favoritesStartIndex;
|
|
258
|
+
const sessionStartIndex = state.sessionStartIndex;
|
|
259
|
+
|
|
260
|
+
const loadingHtml = isSearching ? `
|
|
261
|
+
<div class="welcome-loading">
|
|
262
|
+
<div class="loading-spinner"></div>
|
|
263
|
+
<span>Searching...</span>
|
|
264
|
+
</div>
|
|
265
|
+
` : '';
|
|
266
|
+
|
|
267
|
+
const bodyHtml = `
|
|
268
|
+
${renderProjectsQuickStart(topFilteredProjects, 0, topWorkspaceDirs, topFilteredProjects.length, unvisitedTotal, state.unvisitedExpanded, {
|
|
269
|
+
projectsTotal,
|
|
270
|
+
projectsCollapsible,
|
|
271
|
+
projectsExpanded: state.projectsExpanded,
|
|
272
|
+
activeProjectPath: projectFilter?.path || '',
|
|
273
|
+
})}
|
|
274
|
+
|
|
275
|
+
${renderFavoritesSection(favoritesStartIndex)}
|
|
276
|
+
|
|
277
|
+
${allSessions.length > 0 ? `
|
|
278
|
+
<!-- Recent Session Families -->
|
|
279
|
+
<div class="welcome-section welcome-section--recent">
|
|
280
|
+
<div class="welcome-section-header">
|
|
281
|
+
<h3>${projectFilter ? projectFilter.name : (quickSearchFilter ? 'Sessions' : 'Recent')}</h3>
|
|
282
|
+
</div>
|
|
283
|
+
${recentFamilies.length > 0 ? `
|
|
284
|
+
<div class="welcome-families-grid">
|
|
285
|
+
${recentFamilies.map((f, i) => renderSessionFamily(f, expandedFamilies.has(`family-${f.rootId}`), sessionStartIndex + i)).join('')}
|
|
286
|
+
</div>
|
|
287
|
+
${hasMoreRecent ? `
|
|
288
|
+
<button class="welcome-load-more" data-action="load-more-recent">
|
|
289
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
290
|
+
<polyline points="6 9 12 15 18 9"/>
|
|
291
|
+
</svg>
|
|
292
|
+
<span>Show ${Math.min(RECENT_INCREMENT, sortedFamilies.length - effectiveLimit)} more</span>
|
|
293
|
+
<span class="welcome-load-more-hint">${sortedFamilies.length - effectiveLimit} remaining</span>
|
|
294
|
+
</button>
|
|
295
|
+
` : ''}
|
|
296
|
+
` : `
|
|
297
|
+
<div class="welcome-no-results">
|
|
298
|
+
<p>No sessions match "<strong>${escapeHtml(state.quickSearchFilter || '')}</strong>"</p>
|
|
299
|
+
</div>
|
|
300
|
+
`}
|
|
301
|
+
</div>
|
|
302
|
+
|
|
303
|
+
<!-- All Sessions Grouped by Project -->
|
|
304
|
+
${remainingFamilies.length > 0 && !hasMoreRecent ? `
|
|
305
|
+
<div class="welcome-section welcome-section--all">
|
|
306
|
+
<div class="welcome-section-header">
|
|
307
|
+
<h3>By Project</h3>
|
|
308
|
+
</div>
|
|
309
|
+
<div class="task-project-groups">
|
|
310
|
+
${projectGroups.map((group, i) => renderFamilyProjectGroup(group, expandedGroups.has(`welcome-project-${i}`), i)).join('')}
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
` : ''}
|
|
314
|
+
` : `
|
|
315
|
+
<div class="welcome-empty">
|
|
316
|
+
<p>No sessions yet. Type a message to start!</p>
|
|
317
|
+
</div>
|
|
318
|
+
`}
|
|
319
|
+
`;
|
|
320
|
+
|
|
321
|
+
// Incremental path: if a live search bar is already on screen, update the
|
|
322
|
+
// body and patch the bar in place instead of rebuilding the whole tree.
|
|
323
|
+
// Rebuilding would destroy the focused <input>, and on iOS/iPadOS a blur
|
|
324
|
+
// dismisses the on-screen keyboard — which then instantly reopens from the
|
|
325
|
+
// refocus. That open/close flicker shifts the layout under the user's
|
|
326
|
+
// finger, so a tap lands on whatever card slid into that spot.
|
|
327
|
+
const liveBar = container.querySelector('.welcome-screen > .welcome-search-bar');
|
|
328
|
+
const liveBody = container.querySelector('.welcome-screen > .welcome-body');
|
|
329
|
+
const liveLoading = container.querySelector('.welcome-screen > .welcome-loading-host');
|
|
330
|
+
|
|
331
|
+
if (liveBar && liveBody && liveLoading &&
|
|
332
|
+
patchSearchBar(liveBar, allSessions.length, sessions.length, hasFilter)) {
|
|
333
|
+
liveLoading.innerHTML = loadingHtml;
|
|
334
|
+
liveBody.innerHTML = bodyHtml;
|
|
335
|
+
attachEventListeners(container);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
container.innerHTML = `
|
|
340
|
+
<div id="welcome" class="welcome-screen">
|
|
341
|
+
<div class="welcome-loading-host">${loadingHtml}</div>
|
|
342
|
+
${renderSearchBar(allSessions.length, sessions.length, hasFilter)}
|
|
343
|
+
<div class="welcome-body">${bodyHtml}</div>
|
|
344
|
+
</div>
|
|
345
|
+
`;
|
|
346
|
+
|
|
347
|
+
attachEventListeners(container);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
351
|
+
// KEYBOARD NAVIGATION
|
|
352
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Scroll the selected item into view for keyboard navigation.
|
|
356
|
+
*/
|
|
357
|
+
function scrollSelectedIntoView(container) {
|
|
358
|
+
requestAnimationFrame(() => {
|
|
359
|
+
const selected = container.querySelector('.welcome-project-chip.selected, .favorites-row.selected, .session-family.selected');
|
|
360
|
+
if (selected) {
|
|
361
|
+
selected.scrollIntoView({ block: 'nearest', behavior: 'auto' });
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Handle arrow key navigation on the welcome screen.
|
|
368
|
+
* Returns true if the key was handled (caller should preventDefault).
|
|
369
|
+
*/
|
|
370
|
+
function handleWelcomeArrowNav(key) {
|
|
371
|
+
const itemCount = state.selectableItems?.length || 0;
|
|
372
|
+
if (itemCount === 0 && key !== 'ArrowUp') return false;
|
|
373
|
+
|
|
374
|
+
const favStart = state.favoritesStartIndex || 0;
|
|
375
|
+
const sessionStart = state.sessionStartIndex || 0;
|
|
376
|
+
const currentIdx = state.selectedResultIndex;
|
|
377
|
+
|
|
378
|
+
if (key === 'ArrowDown') {
|
|
379
|
+
if (currentIdx < 0) {
|
|
380
|
+
state.selectedResultIndex = itemCount > 0 ? 0 : -1;
|
|
381
|
+
} else if (currentIdx < favStart) {
|
|
382
|
+
state.selectedResultIndex = favStart < sessionStart ? favStart : (sessionStart < itemCount ? sessionStart : currentIdx);
|
|
383
|
+
} else if (currentIdx < sessionStart) {
|
|
384
|
+
state.selectedResultIndex = sessionStart < itemCount ? sessionStart : currentIdx;
|
|
385
|
+
} else {
|
|
386
|
+
state.selectedResultIndex = Math.min(currentIdx + 1, itemCount - 1);
|
|
387
|
+
}
|
|
388
|
+
return true;
|
|
389
|
+
} else if (key === 'ArrowUp') {
|
|
390
|
+
if (currentIdx < 0) {
|
|
391
|
+
return false;
|
|
392
|
+
} else if (currentIdx >= sessionStart) {
|
|
393
|
+
if (currentIdx === sessionStart) {
|
|
394
|
+
if (favStart < sessionStart) {
|
|
395
|
+
state.selectedResultIndex = favStart;
|
|
396
|
+
} else if (favStart > 0) {
|
|
397
|
+
state.selectedResultIndex = 0;
|
|
398
|
+
} else {
|
|
399
|
+
state.selectedResultIndex = -1;
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
state.selectedResultIndex = currentIdx - 1;
|
|
403
|
+
}
|
|
404
|
+
} else if (currentIdx >= favStart) {
|
|
405
|
+
state.selectedResultIndex = favStart > 0 ? 0 : -1;
|
|
406
|
+
} else {
|
|
407
|
+
state.selectedResultIndex = -1;
|
|
408
|
+
}
|
|
409
|
+
return true;
|
|
410
|
+
} else if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
|
411
|
+
const delta = key === 'ArrowRight' ? 1 : -1;
|
|
412
|
+
if (currentIdx < 0) {
|
|
413
|
+
if (itemCount > 0) {
|
|
414
|
+
state.selectedResultIndex = 0;
|
|
415
|
+
}
|
|
416
|
+
} else if (currentIdx < favStart) {
|
|
417
|
+
const newIdx = currentIdx + delta;
|
|
418
|
+
if (newIdx >= 0 && newIdx < favStart) {
|
|
419
|
+
state.selectedResultIndex = newIdx;
|
|
420
|
+
}
|
|
421
|
+
} else if (currentIdx < sessionStart) {
|
|
422
|
+
const newIdx = currentIdx + delta;
|
|
423
|
+
if (newIdx >= favStart && newIdx < sessionStart) {
|
|
424
|
+
state.selectedResultIndex = newIdx;
|
|
425
|
+
}
|
|
426
|
+
} else {
|
|
427
|
+
const newIdx = currentIdx + delta;
|
|
428
|
+
if (newIdx >= sessionStart && newIdx < itemCount) {
|
|
429
|
+
state.selectedResultIndex = newIdx;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return true;
|
|
433
|
+
} else if (key === 'Enter') {
|
|
434
|
+
if (currentIdx >= 0 && state.selectableItems?.[currentIdx]) {
|
|
435
|
+
const item = state.selectableItems[currentIdx];
|
|
436
|
+
if (item.type === 'project') {
|
|
437
|
+
window.dispatchEvent(new CustomEvent('welcome:new-session-on-project', {
|
|
438
|
+
detail: { projectPath: item.path }
|
|
439
|
+
}));
|
|
440
|
+
} else if ((item.type === 'session' || item.type === 'favorite') && item.session) {
|
|
441
|
+
const sessionId = item.session_id || item.session.session_id;
|
|
442
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
443
|
+
detail: { sessionId, projectPath: item.session.project_path, fromWelcome: true }
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** One-time document-level arrow key handler for welcome screen navigation. */
|
|
454
|
+
let _welcomeArrowHandlerInstalled = false;
|
|
455
|
+
function installWelcomeArrowHandler() {
|
|
456
|
+
if (_welcomeArrowHandlerInstalled) return;
|
|
457
|
+
_welcomeArrowHandlerInstalled = true;
|
|
458
|
+
|
|
459
|
+
document.addEventListener('keydown', (e) => {
|
|
460
|
+
// Only handle arrow keys and Enter
|
|
461
|
+
if (!['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Enter'].includes(e.key)) return;
|
|
462
|
+
|
|
463
|
+
// Skip if already handled (e.g. by the searchInput keydown handler)
|
|
464
|
+
if (e.defaultPrevented) return;
|
|
465
|
+
|
|
466
|
+
// Only when welcome screen is visible
|
|
467
|
+
const container = document.getElementById('welcome-container');
|
|
468
|
+
if (!container) return;
|
|
469
|
+
|
|
470
|
+
// Skip if search input is focused (it has its own handler)
|
|
471
|
+
if (document.activeElement?.classList.contains('welcome-search-input')) return;
|
|
472
|
+
|
|
473
|
+
// Skip if focused on any input/textarea/editable
|
|
474
|
+
if (document.activeElement?.matches('input, textarea, [contenteditable="true"]')) return;
|
|
475
|
+
|
|
476
|
+
// Skip if overlay/modal is open
|
|
477
|
+
if (document.querySelector('#modal-overlay.visible, .quick-actions-overlay.visible')) return;
|
|
478
|
+
|
|
479
|
+
// Alt+Enter: filter by selected item's project
|
|
480
|
+
if (e.key === 'Enter' && e.altKey) {
|
|
481
|
+
e.preventDefault();
|
|
482
|
+
filterSelectedProject(container);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (handleWelcomeArrowNav(e.key)) {
|
|
487
|
+
e.preventDefault();
|
|
488
|
+
renderWelcomeScreen(container);
|
|
489
|
+
scrollSelectedIntoView(container);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
495
|
+
// EVENT HANDLERS
|
|
496
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
497
|
+
|
|
498
|
+
// The live "load more" IntersectionObserver — one at a time, replaced on each
|
|
499
|
+
// render (see attachEventListeners).
|
|
500
|
+
let welcomeLoadMoreObserver = null;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Open the session-list limit popup anchored to the limit selector.
|
|
504
|
+
*/
|
|
505
|
+
function openLimitSelector(e, container) {
|
|
506
|
+
e.stopPropagation();
|
|
507
|
+
const btn = e.target.closest('[data-action="toggle-limit-selector"]');
|
|
508
|
+
if (!btn) return;
|
|
509
|
+
|
|
510
|
+
// Close if already open
|
|
511
|
+
const existing = container.querySelector('.limit-popup');
|
|
512
|
+
if (existing) { existing.remove(); return; }
|
|
513
|
+
|
|
514
|
+
const presets = [50, 100, 200, 500];
|
|
515
|
+
const current = CONFIG.SESSION_LIST_LIMIT;
|
|
516
|
+
const popup = document.createElement('div');
|
|
517
|
+
popup.className = 'limit-popup';
|
|
518
|
+
popup.innerHTML = presets.map(n =>
|
|
519
|
+
`<button class="limit-option ${n === current ? 'active' : ''}" data-limit="${n}">${n}</button>`
|
|
520
|
+
).join('');
|
|
521
|
+
btn.appendChild(popup);
|
|
522
|
+
|
|
523
|
+
popup.addEventListener('click', async (ev) => {
|
|
524
|
+
const opt = ev.target.closest('[data-limit]');
|
|
525
|
+
if (!opt) return;
|
|
526
|
+
ev.stopPropagation();
|
|
527
|
+
const newLimit = parseInt(opt.dataset.limit, 10);
|
|
528
|
+
const cfg = loadUserConfig();
|
|
529
|
+
cfg.sessionListLimit = newLimit;
|
|
530
|
+
saveUserConfig(cfg);
|
|
531
|
+
popup.remove();
|
|
532
|
+
// Reload sessions with new limit
|
|
533
|
+
await loadRecentSessions();
|
|
534
|
+
renderWelcomeScreen(container);
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// Close on outside click
|
|
538
|
+
const closePopup = (ev) => {
|
|
539
|
+
if (!popup.contains(ev.target)) {
|
|
540
|
+
popup.remove();
|
|
541
|
+
document.removeEventListener('click', closePopup, true);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
setTimeout(() => document.addEventListener('click', closePopup, true), 0);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function attachEventListeners(container) {
|
|
548
|
+
// Note: Click-to-blur for type-anywhere is handled in app.js messagesContainer handler
|
|
549
|
+
// (more reliable since it's attached to stable element, not recreated welcome DOM)
|
|
550
|
+
|
|
551
|
+
// Helper to find session data by ID (including branches inside families)
|
|
552
|
+
const findSession = (sessionId) => {
|
|
553
|
+
// Check direct sessions first
|
|
554
|
+
const allSessions = [
|
|
555
|
+
...state.sessions,
|
|
556
|
+
...(state.searchResults?.results || [])
|
|
557
|
+
];
|
|
558
|
+
const direct = allSessions.find(s => s.session_id === sessionId);
|
|
559
|
+
if (direct) return direct;
|
|
560
|
+
|
|
561
|
+
// Check inside family branches
|
|
562
|
+
if (state.familyMap) {
|
|
563
|
+
for (const family of state.familyMap.values()) {
|
|
564
|
+
// Check root
|
|
565
|
+
if (family.root?.session_id === sessionId) {
|
|
566
|
+
return family.root;
|
|
567
|
+
}
|
|
568
|
+
// Check branches
|
|
569
|
+
const branch = family.branches?.find(b => b.session?.session_id === sessionId);
|
|
570
|
+
if (branch) {
|
|
571
|
+
return branch.session;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return null;
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
// Session card clicks - show preview (not open directly)
|
|
580
|
+
container.querySelectorAll('.welcome-session-card').forEach(card => {
|
|
581
|
+
const sessionId = card.dataset.sessionId;
|
|
582
|
+
const session = findSession(sessionId);
|
|
583
|
+
|
|
584
|
+
// Setup long press / right-click context menu
|
|
585
|
+
if (session) {
|
|
586
|
+
setupLongPress(card, session, container);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
card.addEventListener('click', (e) => {
|
|
590
|
+
// Don't trigger if clicking a button
|
|
591
|
+
if (e.target.closest('button')) return;
|
|
592
|
+
// Don't trigger if context menu is open (belt-and-suspenders)
|
|
593
|
+
if (state.contextMenuSession) return;
|
|
594
|
+
// Use wasLongPressRecent() for more robust detection across event cycles
|
|
595
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
596
|
+
e.stopPropagation();
|
|
597
|
+
// Delay reset to catch any other stray click events
|
|
598
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Show preview instead of opening directly
|
|
603
|
+
if (session) {
|
|
604
|
+
showPreview(session, container);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// Button actions within card
|
|
609
|
+
card.querySelectorAll('button[data-action]').forEach(btn => {
|
|
610
|
+
btn.addEventListener('click', (e) => {
|
|
611
|
+
e.stopPropagation();
|
|
612
|
+
const action = btn.dataset.action;
|
|
613
|
+
const projectPath = card.dataset.projectPath;
|
|
614
|
+
|
|
615
|
+
if (action === 'continue') {
|
|
616
|
+
// Open directly
|
|
617
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
618
|
+
detail: { sessionId, projectPath }
|
|
619
|
+
}));
|
|
620
|
+
} else if (action === 'details') {
|
|
621
|
+
// Show preview
|
|
622
|
+
if (session) {
|
|
623
|
+
showPreview(session, container);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
// Recent session card clicks - open directly (compact view)
|
|
631
|
+
container.querySelectorAll('.welcome-recent-card').forEach(card => {
|
|
632
|
+
const sessionId = card.dataset.sessionId;
|
|
633
|
+
const session = findSession(sessionId);
|
|
634
|
+
|
|
635
|
+
// Setup long press / right-click context menu
|
|
636
|
+
if (session) {
|
|
637
|
+
setupLongPress(card, session, container);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Preview button click
|
|
641
|
+
const previewBtn = card.querySelector('[data-action="preview-recent"]');
|
|
642
|
+
if (previewBtn && session) {
|
|
643
|
+
previewBtn.addEventListener('click', (e) => {
|
|
644
|
+
e.stopPropagation();
|
|
645
|
+
showPreview(session, container);
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// Favorite star toggle
|
|
650
|
+
const starBtn = card.querySelector('[data-action="toggle-favorite"]');
|
|
651
|
+
if (starBtn && session) {
|
|
652
|
+
starBtn.addEventListener('click', (e) => {
|
|
653
|
+
e.stopPropagation();
|
|
654
|
+
e.preventDefault();
|
|
655
|
+
toggleFavorite(sessionId, container);
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
card.addEventListener('click', (e) => {
|
|
660
|
+
// Don't trigger if clicking preview button or star
|
|
661
|
+
if (e.target.closest('[data-action="preview-recent"]')) return;
|
|
662
|
+
if (e.target.closest('[data-action="toggle-favorite"]')) return;
|
|
663
|
+
// Don't trigger if context menu is open
|
|
664
|
+
if (state.contextMenuSession) return;
|
|
665
|
+
// Don't trigger if long press was triggered
|
|
666
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
667
|
+
e.stopPropagation();
|
|
668
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const projectPath = card.dataset.projectPath;
|
|
673
|
+
|
|
674
|
+
// Cmd+click (Mac) or Ctrl+click (Win/Linux) opens in background tab
|
|
675
|
+
if (e.metaKey || e.ctrlKey) {
|
|
676
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session-new-tab', {
|
|
677
|
+
detail: { sessionId, projectPath, background: true }
|
|
678
|
+
}));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Save welcome state before opening (for "back to sessions" feature)
|
|
683
|
+
saveWelcomeState(container);
|
|
684
|
+
|
|
685
|
+
// Open session directly (compact cards are for quick access)
|
|
686
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
687
|
+
detail: { sessionId, projectPath, fromWelcome: true }
|
|
688
|
+
}));
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// Welcome session row clicks - show preview
|
|
693
|
+
container.querySelectorAll('.welcome-session-row').forEach(row => {
|
|
694
|
+
const sessionId = row.dataset.sessionId;
|
|
695
|
+
const session = findSession(sessionId);
|
|
696
|
+
|
|
697
|
+
// Setup long press / right-click context menu
|
|
698
|
+
if (session) {
|
|
699
|
+
setupLongPress(row, session, container);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
row.addEventListener('click', (e) => {
|
|
703
|
+
// Don't trigger if context menu is open
|
|
704
|
+
if (state.contextMenuSession) return;
|
|
705
|
+
// Don't trigger if long press was triggered
|
|
706
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
707
|
+
e.stopPropagation();
|
|
708
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// Show preview
|
|
713
|
+
if (session) {
|
|
714
|
+
showPreview(session, container);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
// Session family toggle (expand/collapse branches)
|
|
720
|
+
container.querySelectorAll('[data-action="toggle-family"]').forEach(el => {
|
|
721
|
+
el.addEventListener('click', (e) => {
|
|
722
|
+
e.stopPropagation();
|
|
723
|
+
const familyId = el.dataset.family;
|
|
724
|
+
if (familyId) {
|
|
725
|
+
if (expandedFamilies.has(familyId)) {
|
|
726
|
+
expandedFamilies.delete(familyId);
|
|
727
|
+
// Also reset full expansion when collapsing
|
|
728
|
+
fullyExpandedFamilies.delete(familyId);
|
|
729
|
+
} else {
|
|
730
|
+
expandedFamilies.add(familyId);
|
|
731
|
+
}
|
|
732
|
+
renderWelcomeScreen(container);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// Show all forks in a family
|
|
738
|
+
container.querySelectorAll('[data-action="show-all-forks"]').forEach(el => {
|
|
739
|
+
el.addEventListener('click', (e) => {
|
|
740
|
+
e.stopPropagation();
|
|
741
|
+
const familyId = el.dataset.family;
|
|
742
|
+
if (familyId) {
|
|
743
|
+
fullyExpandedFamilies.add(familyId);
|
|
744
|
+
renderWelcomeScreen(container);
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// Session family root clicks - open session
|
|
750
|
+
container.querySelectorAll('.session-family-root').forEach(card => {
|
|
751
|
+
const sessionId = card.dataset.sessionId;
|
|
752
|
+
const session = findSession(sessionId);
|
|
753
|
+
|
|
754
|
+
// Setup long press / right-click context menu
|
|
755
|
+
if (session) {
|
|
756
|
+
setupLongPress(card, session, container);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// Preview button
|
|
760
|
+
const previewBtn = card.querySelector('[data-action="preview-family-root"]');
|
|
761
|
+
if (previewBtn && session) {
|
|
762
|
+
previewBtn.addEventListener('click', (e) => {
|
|
763
|
+
e.stopPropagation();
|
|
764
|
+
showPreview(session, container);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Favorite star toggle
|
|
769
|
+
const starBtn = card.querySelector('[data-action="toggle-favorite"]');
|
|
770
|
+
if (starBtn && session) {
|
|
771
|
+
starBtn.addEventListener('click', (e) => {
|
|
772
|
+
e.stopPropagation();
|
|
773
|
+
e.preventDefault();
|
|
774
|
+
toggleFavorite(sessionId, container);
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// New session on project button
|
|
779
|
+
const newSessionBtn = card.querySelector('[data-action="new-session-on-project"]');
|
|
780
|
+
if (newSessionBtn && session) {
|
|
781
|
+
newSessionBtn.addEventListener('click', (e) => {
|
|
782
|
+
e.stopPropagation();
|
|
783
|
+
e.preventDefault();
|
|
784
|
+
const projectPath = newSessionBtn.dataset.projectPath;
|
|
785
|
+
window.dispatchEvent(new CustomEvent('welcome:new-session-on-project', {
|
|
786
|
+
detail: { projectPath }
|
|
787
|
+
}));
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Filter by project click
|
|
792
|
+
const filterProjectEl = card.querySelector('[data-action="filter-project"]');
|
|
793
|
+
if (filterProjectEl) {
|
|
794
|
+
// Click to filter
|
|
795
|
+
filterProjectEl.addEventListener('click', (e) => {
|
|
796
|
+
e.stopPropagation();
|
|
797
|
+
e.preventDefault();
|
|
798
|
+
// Don't filter if we just showed context menu via long press
|
|
799
|
+
if (wasLongPressRecent()) return;
|
|
800
|
+
const projectPath = filterProjectEl.dataset.projectPath;
|
|
801
|
+
const projectName = filterProjectEl.dataset.projectName;
|
|
802
|
+
setProjectFilter(projectPath, projectName, container);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// Right-click for context menu (desktop)
|
|
806
|
+
filterProjectEl.addEventListener('contextmenu', (e) => {
|
|
807
|
+
e.stopPropagation();
|
|
808
|
+
e.preventDefault();
|
|
809
|
+
const projectPath = filterProjectEl.dataset.projectPath;
|
|
810
|
+
const projectName = filterProjectEl.dataset.projectName;
|
|
811
|
+
showProjectContextMenu(projectPath, projectName, e.clientX, e.clientY, container);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// Long-press for context menu (touch devices)
|
|
815
|
+
let projectLongPressTimer = null;
|
|
816
|
+
filterProjectEl.addEventListener('touchstart', (e) => {
|
|
817
|
+
const projectPath = filterProjectEl.dataset.projectPath;
|
|
818
|
+
const projectName = filterProjectEl.dataset.projectName;
|
|
819
|
+
const touch = e.touches[0];
|
|
820
|
+
projectLongPressTimer = setTimeout(() => {
|
|
821
|
+
e.preventDefault();
|
|
822
|
+
longPress.triggered = true;
|
|
823
|
+
longPress.timestamp = Date.now();
|
|
824
|
+
showProjectContextMenu(projectPath, projectName, touch.clientX, touch.clientY, container);
|
|
825
|
+
}, 400);
|
|
826
|
+
}, { passive: false });
|
|
827
|
+
|
|
828
|
+
filterProjectEl.addEventListener('touchend', () => {
|
|
829
|
+
if (projectLongPressTimer) {
|
|
830
|
+
clearTimeout(projectLongPressTimer);
|
|
831
|
+
projectLongPressTimer = null;
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
filterProjectEl.addEventListener('touchmove', () => {
|
|
836
|
+
if (projectLongPressTimer) {
|
|
837
|
+
clearTimeout(projectLongPressTimer);
|
|
838
|
+
projectLongPressTimer = null;
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
card.addEventListener('click', (e) => {
|
|
844
|
+
// Don't trigger on buttons
|
|
845
|
+
if (e.target.closest('button')) return;
|
|
846
|
+
if (e.target.closest('[data-action]')) return;
|
|
847
|
+
if (state.contextMenuSession) return;
|
|
848
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
849
|
+
e.stopPropagation();
|
|
850
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const projectPath = card.dataset.projectPath;
|
|
855
|
+
|
|
856
|
+
// Alt+click: filter by this session's project
|
|
857
|
+
if (e.altKey && projectPath) {
|
|
858
|
+
const s = findSession(sessionId);
|
|
859
|
+
setProjectFilter(projectPath, s?.project || basename(projectPath), container);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// Cmd+click (Mac) or Ctrl+click (Win/Linux) opens in background tab
|
|
864
|
+
if (e.metaKey || e.ctrlKey) {
|
|
865
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session-new-tab', {
|
|
866
|
+
detail: { sessionId, projectPath, background: true }
|
|
867
|
+
}));
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// Save state and open session
|
|
872
|
+
saveWelcomeState(container);
|
|
873
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
874
|
+
detail: { sessionId, projectPath, fromWelcome: true }
|
|
875
|
+
}));
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
// Fork row clicks - open the fork session
|
|
880
|
+
container.querySelectorAll('.family-fork-row').forEach(row => {
|
|
881
|
+
const sessionId = row.dataset.sessionId;
|
|
882
|
+
const session = findSession(sessionId);
|
|
883
|
+
|
|
884
|
+
// Setup long press for forks too
|
|
885
|
+
if (session) {
|
|
886
|
+
setupLongPress(row, session, container);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Preview button on fork
|
|
890
|
+
const previewBtn = row.querySelector('[data-action="preview-fork"]');
|
|
891
|
+
if (previewBtn && session) {
|
|
892
|
+
previewBtn.addEventListener('click', (e) => {
|
|
893
|
+
e.stopPropagation();
|
|
894
|
+
showPreview(session, container);
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
row.addEventListener('click', (e) => {
|
|
899
|
+
if (e.target.closest('button')) return;
|
|
900
|
+
if (state.contextMenuSession) return;
|
|
901
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
902
|
+
e.stopPropagation();
|
|
903
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const projectPath = row.dataset.projectPath;
|
|
908
|
+
|
|
909
|
+
// Alt+click: filter by this session's project
|
|
910
|
+
if (e.altKey && projectPath) {
|
|
911
|
+
const s = findSession(sessionId);
|
|
912
|
+
setProjectFilter(projectPath, s?.project || basename(projectPath), container);
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// Cmd+click (Mac) or Ctrl+click (Win/Linux) opens in background tab
|
|
917
|
+
if (e.metaKey || e.ctrlKey) {
|
|
918
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session-new-tab', {
|
|
919
|
+
detail: { sessionId, projectPath, background: true }
|
|
920
|
+
}));
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Save state and open branch session
|
|
925
|
+
saveWelcomeState(container);
|
|
926
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
927
|
+
detail: { sessionId, projectPath, fromWelcome: true }
|
|
928
|
+
}));
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// Compact family clicks (in project groups) - open root session
|
|
933
|
+
container.querySelectorAll('.compact-family').forEach(card => {
|
|
934
|
+
const sessionId = card.dataset.sessionId;
|
|
935
|
+
const session = findSession(sessionId);
|
|
936
|
+
|
|
937
|
+
if (session) {
|
|
938
|
+
setupLongPress(card, session, container);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
card.addEventListener('click', (e) => {
|
|
942
|
+
if (state.contextMenuSession) return;
|
|
943
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
944
|
+
e.stopPropagation();
|
|
945
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const projectPath = card.dataset.projectPath;
|
|
950
|
+
|
|
951
|
+
// Alt+click: filter by this session's project
|
|
952
|
+
if (e.altKey && projectPath) {
|
|
953
|
+
const s = findSession(sessionId);
|
|
954
|
+
setProjectFilter(projectPath, s?.project || basename(projectPath), container);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// Cmd+click (Mac) or Ctrl+click (Win/Linux) opens in background tab
|
|
959
|
+
if (e.metaKey || e.ctrlKey) {
|
|
960
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session-new-tab', {
|
|
961
|
+
detail: { sessionId, projectPath, background: true }
|
|
962
|
+
}));
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// Save state and open session
|
|
967
|
+
saveWelcomeState(container);
|
|
968
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
969
|
+
detail: { sessionId, projectPath, fromWelcome: true }
|
|
970
|
+
}));
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
// Favorite row clicks
|
|
975
|
+
container.querySelectorAll('.favorites-row').forEach(card => {
|
|
976
|
+
const sessionId = card.dataset.sessionId;
|
|
977
|
+
const projectPath = card.dataset.projectPath;
|
|
978
|
+
|
|
979
|
+
// Find session in favorites
|
|
980
|
+
const favorite = state.favorites.find(f => f.session_id === sessionId);
|
|
981
|
+
const session = favorite?.session;
|
|
982
|
+
|
|
983
|
+
// Setup long press for context menu (if session exists)
|
|
984
|
+
if (session) {
|
|
985
|
+
setupLongPress(card, { ...session, session_id: sessionId, project_path: projectPath }, container);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// Star toggle (unfavorite)
|
|
989
|
+
const starBtn = card.querySelector('[data-action="toggle-favorite"]');
|
|
990
|
+
if (starBtn) {
|
|
991
|
+
starBtn.addEventListener('click', (e) => {
|
|
992
|
+
e.stopPropagation();
|
|
993
|
+
e.preventDefault();
|
|
994
|
+
toggleFavorite(sessionId, container);
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// Click to open (if session still exists)
|
|
999
|
+
card.addEventListener('click', (e) => {
|
|
1000
|
+
if (e.target.closest('[data-action="toggle-favorite"]')) return;
|
|
1001
|
+
if (state.contextMenuSession) return;
|
|
1002
|
+
if (longPress.triggered || wasLongPressRecent()) {
|
|
1003
|
+
e.stopPropagation();
|
|
1004
|
+
setTimeout(() => { longPress.triggered = false; }, 100);
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// If session is deleted, can't open
|
|
1009
|
+
if (!session) return;
|
|
1010
|
+
|
|
1011
|
+
// Alt+click: filter by this session's project
|
|
1012
|
+
if (e.altKey && projectPath) {
|
|
1013
|
+
setProjectFilter(projectPath, session.project || basename(projectPath), container);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// Cmd+click (Mac) or Ctrl+click (Win/Linux) opens in background tab
|
|
1018
|
+
if (e.metaKey || e.ctrlKey) {
|
|
1019
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session-new-tab', {
|
|
1020
|
+
detail: { sessionId, projectPath, background: true }
|
|
1021
|
+
}));
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// Save state and open
|
|
1026
|
+
saveWelcomeState(container);
|
|
1027
|
+
window.dispatchEvent(new CustomEvent('welcome:open-session', {
|
|
1028
|
+
detail: { sessionId, projectPath, fromWelcome: true }
|
|
1029
|
+
}));
|
|
1030
|
+
});
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
// "Show all favorites" button — expand the limit to show every favorite,
|
|
1034
|
+
// mirroring the "Load more recent" pattern.
|
|
1035
|
+
container.querySelector('[data-action="show-all-favorites"]')?.addEventListener('click', () => {
|
|
1036
|
+
debug.log('[Welcome] Show all favorites requested');
|
|
1037
|
+
favoritesLimit.value = Infinity;
|
|
1038
|
+
renderWelcomeScreen(container);
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
// "Load more recent" button - click handler
|
|
1042
|
+
const loadMoreBtn = container.querySelector('[data-action="load-more-recent"]');
|
|
1043
|
+
loadMoreBtn?.addEventListener('click', () => {
|
|
1044
|
+
recentLimit.value += RECENT_INCREMENT;
|
|
1045
|
+
renderWelcomeScreen(container);
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
// Auto-load more when scrolling to bottom (IntersectionObserver)
|
|
1049
|
+
if (loadMoreBtn) {
|
|
1050
|
+
// Drop the previous render's observer first — its target node is gone,
|
|
1051
|
+
// so it can never fire and disconnect itself. Without this, typing in
|
|
1052
|
+
// the search box leaks one live observer per keystroke.
|
|
1053
|
+
welcomeLoadMoreObserver?.disconnect();
|
|
1054
|
+
|
|
1055
|
+
// Use #welcome-container itself as the scroll root (per-tab scroll architecture)
|
|
1056
|
+
const scrollContainer = container.closest('#welcome-container') || container;
|
|
1057
|
+
const observer = new IntersectionObserver((entries) => {
|
|
1058
|
+
entries.forEach(entry => {
|
|
1059
|
+
if (entry.isIntersecting) {
|
|
1060
|
+
observer.disconnect(); // Prevent multiple triggers
|
|
1061
|
+
// Save scroll position before re-render
|
|
1062
|
+
const scrollTop = scrollContainer.scrollTop;
|
|
1063
|
+
recentLimit.value += RECENT_INCREMENT;
|
|
1064
|
+
renderWelcomeScreen(container);
|
|
1065
|
+
// Restore scroll position after re-render
|
|
1066
|
+
requestAnimationFrame(() => {
|
|
1067
|
+
scrollContainer.scrollTop = scrollTop;
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
}, {
|
|
1072
|
+
root: scrollContainer,
|
|
1073
|
+
rootMargin: '100px' // Trigger 100px before button is visible
|
|
1074
|
+
});
|
|
1075
|
+
observer.observe(loadMoreBtn);
|
|
1076
|
+
welcomeLoadMoreObserver = observer;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Unified search bar - filter as you type.
|
|
1080
|
+
// The bar (and its <input>) survives re-renders, so bind exactly once —
|
|
1081
|
+
// re-binding on every render would stack duplicate handlers on the same node.
|
|
1082
|
+
const searchBar = container.querySelector('.welcome-search-bar');
|
|
1083
|
+
const searchInput = container.querySelector('[data-action="welcome-search-input"]');
|
|
1084
|
+
if (searchInput && searchBar && !searchBar.dataset.ppBound) {
|
|
1085
|
+
searchBar.dataset.ppBound = '1';
|
|
1086
|
+
|
|
1087
|
+
searchInput.addEventListener('input', (e) => {
|
|
1088
|
+
state.quickSearchFilter = e.target.value;
|
|
1089
|
+
state.quickSearchActive = !!e.target.value; // Mark as active if has value
|
|
1090
|
+
state.selectedResultIndex = -1; // Re-anchor: the render re-selects the first result
|
|
1091
|
+
// No refocus/caret-restore needed: renderWelcomeScreen patches the bar
|
|
1092
|
+
// in place and never touches this input, so focus, caret and the
|
|
1093
|
+
// on-screen keyboard all stay exactly where they are.
|
|
1094
|
+
renderWelcomeScreen(container);
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
// Handle Escape, Arrow keys for navigation, Enter to open
|
|
1098
|
+
searchInput.addEventListener('keydown', async (e) => {
|
|
1099
|
+
// Escape is deliberately NOT handled here. The global shortcut
|
|
1100
|
+
// ladder (app.handleEscape → clearWelcomeSearch) fires for it even
|
|
1101
|
+
// while this input has focus, so a local branch would run first and
|
|
1102
|
+
// then get overrun by the ladder — which is how the old "clear the
|
|
1103
|
+
// selection, keep the query" stage silently never held. One owner:
|
|
1104
|
+
// clearWelcomeSearch().
|
|
1105
|
+
if (e.key === 'Backspace' && state.projectFilter && !searchInput.value) {
|
|
1106
|
+
e.preventDefault();
|
|
1107
|
+
clearProjectFilter(container);
|
|
1108
|
+
} else if (['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
|
1109
|
+
if (handleWelcomeArrowNav(e.key)) {
|
|
1110
|
+
e.preventDefault();
|
|
1111
|
+
renderWelcomeScreen(container);
|
|
1112
|
+
scrollSelectedIntoView(container);
|
|
1113
|
+
}
|
|
1114
|
+
} else if (e.key === 'Enter' && e.altKey) {
|
|
1115
|
+
e.preventDefault();
|
|
1116
|
+
filterSelectedProject(container);
|
|
1117
|
+
} else if (e.key === 'Enter') {
|
|
1118
|
+
e.preventDefault();
|
|
1119
|
+
handleWelcomeArrowNav('Enter');
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
// Buttons inside the bar are delegated: patchSearchBar adds/removes the
|
|
1124
|
+
// clear button and the project-filter chip, so they have no stable node
|
|
1125
|
+
// to bind to.
|
|
1126
|
+
searchBar.addEventListener('click', (e) => {
|
|
1127
|
+
const action = e.target.closest('[data-action]')?.dataset.action;
|
|
1128
|
+
|
|
1129
|
+
// Clear search button (clears both text and project filter)
|
|
1130
|
+
if (action === 'clear-welcome-search') {
|
|
1131
|
+
e.stopPropagation();
|
|
1132
|
+
state.quickSearchActive = false;
|
|
1133
|
+
state.quickSearchFilter = '';
|
|
1134
|
+
state.projectFilter = null;
|
|
1135
|
+
state.selectedResultIndex = -1;
|
|
1136
|
+
renderWelcomeScreen(container);
|
|
1137
|
+
container.querySelector('.welcome-search-input')?.focus();
|
|
1138
|
+
|
|
1139
|
+
// Remove project filter chip (keeps text search)
|
|
1140
|
+
} else if (action === 'remove-project-filter') {
|
|
1141
|
+
e.stopPropagation();
|
|
1142
|
+
state.projectFilter = null;
|
|
1143
|
+
renderWelcomeScreen(container);
|
|
1144
|
+
container.querySelector('.welcome-search-input')?.focus();
|
|
1145
|
+
|
|
1146
|
+
// New session button in search bar
|
|
1147
|
+
} else if (action === 'new-session-picker') {
|
|
1148
|
+
e.stopPropagation();
|
|
1149
|
+
state.showProjectPicker = true;
|
|
1150
|
+
renderWelcomeScreen(container);
|
|
1151
|
+
|
|
1152
|
+
// Session list limit quick-selector
|
|
1153
|
+
} else if (action === 'toggle-limit-selector') {
|
|
1154
|
+
openLimitSelector(e, container);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// Quick-start project chips - start new session on project
|
|
1160
|
+
container.querySelector('[data-action="toggle-unvisited"]')?.addEventListener('click', (e) => {
|
|
1161
|
+
e.stopPropagation();
|
|
1162
|
+
state.unvisitedExpanded = !state.unvisitedExpanded;
|
|
1163
|
+
renderWelcomeScreen(container);
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
container.querySelector('[data-action="toggle-projects"]')?.addEventListener('click', (e) => {
|
|
1167
|
+
e.stopPropagation();
|
|
1168
|
+
state.projectsExpanded = !state.projectsExpanded;
|
|
1169
|
+
renderWelcomeScreen(container);
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
container.querySelectorAll('[data-action="quick-start-project"]').forEach(chip => {
|
|
1173
|
+
chip.addEventListener('click', (e) => {
|
|
1174
|
+
e.stopPropagation();
|
|
1175
|
+
// Don't start session if we just showed context menu via long press
|
|
1176
|
+
if (wasLongPressRecent()) return;
|
|
1177
|
+
const projectPath = chip.dataset.projectPath;
|
|
1178
|
+
const projectName = chip.dataset.projectName;
|
|
1179
|
+
|
|
1180
|
+
// Alt+click: filter by this project
|
|
1181
|
+
if (e.altKey && projectPath) {
|
|
1182
|
+
setProjectFilter(projectPath, projectName || basename(projectPath), container);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
if (projectPath) {
|
|
1187
|
+
window.dispatchEvent(new CustomEvent('welcome:new-session-on-project', {
|
|
1188
|
+
detail: { projectPath }
|
|
1189
|
+
}));
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
// Right-click for context menu (desktop)
|
|
1194
|
+
chip.addEventListener('contextmenu', (e) => {
|
|
1195
|
+
e.stopPropagation();
|
|
1196
|
+
e.preventDefault();
|
|
1197
|
+
const projectPath = chip.dataset.projectPath;
|
|
1198
|
+
const projectName = chip.dataset.projectName;
|
|
1199
|
+
showProjectContextMenu(projectPath, projectName, e.clientX, e.clientY, container);
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
// Long-press for context menu (touch devices)
|
|
1203
|
+
let chipLongPressTimer = null;
|
|
1204
|
+
chip.addEventListener('touchstart', (e) => {
|
|
1205
|
+
const projectPath = chip.dataset.projectPath;
|
|
1206
|
+
const projectName = chip.dataset.projectName;
|
|
1207
|
+
const touch = e.touches[0];
|
|
1208
|
+
chipLongPressTimer = setTimeout(() => {
|
|
1209
|
+
e.preventDefault();
|
|
1210
|
+
longPress.triggered = true;
|
|
1211
|
+
longPress.timestamp = Date.now();
|
|
1212
|
+
showProjectContextMenu(projectPath, projectName, touch.clientX, touch.clientY, container);
|
|
1213
|
+
}, 400);
|
|
1214
|
+
}, { passive: false });
|
|
1215
|
+
|
|
1216
|
+
chip.addEventListener('touchend', () => {
|
|
1217
|
+
if (chipLongPressTimer) {
|
|
1218
|
+
clearTimeout(chipLongPressTimer);
|
|
1219
|
+
chipLongPressTimer = null;
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
chip.addEventListener('touchmove', () => {
|
|
1224
|
+
if (chipLongPressTimer) {
|
|
1225
|
+
clearTimeout(chipLongPressTimer);
|
|
1226
|
+
chipLongPressTimer = null;
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
|
|
1231
|
+
// Toggle welcome project groups
|
|
1232
|
+
container.querySelectorAll('[data-action="toggle-welcome-group"]').forEach(el => {
|
|
1233
|
+
el.addEventListener('click', (e) => {
|
|
1234
|
+
e.stopPropagation();
|
|
1235
|
+
const groupId = el.dataset.group;
|
|
1236
|
+
if (groupId) {
|
|
1237
|
+
if (expandedGroups.has(groupId)) {
|
|
1238
|
+
expandedGroups.delete(groupId);
|
|
1239
|
+
} else {
|
|
1240
|
+
expandedGroups.add(groupId);
|
|
1241
|
+
}
|
|
1242
|
+
renderWelcomeScreen(container);
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// New session in project button (in project group headers)
|
|
1248
|
+
container.querySelectorAll('[data-action="new-session-in-project"]').forEach(btn => {
|
|
1249
|
+
btn.addEventListener('click', (e) => {
|
|
1250
|
+
e.stopPropagation();
|
|
1251
|
+
e.preventDefault();
|
|
1252
|
+
const projectPath = btn.dataset.projectPath;
|
|
1253
|
+
if (projectPath) {
|
|
1254
|
+
window.dispatchEvent(new CustomEvent('welcome:start-project', {
|
|
1255
|
+
detail: { path: projectPath }
|
|
1256
|
+
}));
|
|
1257
|
+
} else {
|
|
1258
|
+
// No path - just create a new session
|
|
1259
|
+
window.dispatchEvent(new CustomEvent('welcome:new-session'));
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
// Project picker - stop propagation and check for recent long press
|
|
1265
|
+
const projectToggle = container.querySelector('[data-action="toggle-projects"]');
|
|
1266
|
+
if (projectToggle) {
|
|
1267
|
+
projectToggle.addEventListener('click', (e) => {
|
|
1268
|
+
e.stopPropagation();
|
|
1269
|
+
// Ignore if long press was recently triggered (prevents accidental toggle)
|
|
1270
|
+
if (wasLongPressRecent()) return;
|
|
1271
|
+
state.showProjectPicker = !state.showProjectPicker;
|
|
1272
|
+
renderWelcomeScreen(container);
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
container.querySelectorAll('.welcome-project-item[data-path]').forEach(item => {
|
|
1277
|
+
item.addEventListener('click', (e) => {
|
|
1278
|
+
e.stopPropagation();
|
|
1279
|
+
if (wasLongPressRecent()) return;
|
|
1280
|
+
const path = item.dataset.path;
|
|
1281
|
+
|
|
1282
|
+
// Alt+click: filter by this project
|
|
1283
|
+
if (e.altKey && path) {
|
|
1284
|
+
const name = item.querySelector('.project-name')?.textContent || basename(path);
|
|
1285
|
+
setProjectFilter(path, name, container);
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
window.dispatchEvent(new CustomEvent('welcome:start-project', {
|
|
1290
|
+
detail: { path }
|
|
1291
|
+
}));
|
|
1292
|
+
});
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
container.querySelector('[data-action="browse-project"]')?.addEventListener('click', (e) => {
|
|
1296
|
+
e.stopPropagation();
|
|
1297
|
+
if (wasLongPressRecent()) return;
|
|
1298
|
+
window.dispatchEvent(new CustomEvent('welcome:browse-project'));
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
// Start new session (from search results or no-results view)
|
|
1302
|
+
container.querySelectorAll('[data-action="start-new-session"]').forEach(btn => {
|
|
1303
|
+
btn.addEventListener('click', (e) => {
|
|
1304
|
+
e.stopPropagation();
|
|
1305
|
+
e.preventDefault();
|
|
1306
|
+
window.dispatchEvent(new CustomEvent('welcome:new-session'));
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
// Start task from search
|
|
1312
|
+
container.querySelector('[data-action="start-task"]')?.addEventListener('click', () => {
|
|
1313
|
+
// Use first result's project or selected project
|
|
1314
|
+
const firstResult = state.searchResults?.results?.[0];
|
|
1315
|
+
if (firstResult?.project_path) {
|
|
1316
|
+
window.dispatchEvent(new CustomEvent('welcome:start-project', {
|
|
1317
|
+
detail: { path: firstResult.project_path, query: state.searchQuery }
|
|
1318
|
+
}));
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1323
|
+
// TASK MODE HANDLERS
|
|
1324
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1325
|
+
|
|
1326
|
+
// Helper to get session data from either card or row
|
|
1327
|
+
const getSessionElement = (btn) => {
|
|
1328
|
+
return btn.closest('.welcome-session-card') || btn.closest('.task-session-row');
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
// "Continue here" button in task mode - resume existing session with pending task
|
|
1332
|
+
container.querySelectorAll('[data-action="continue-with-task"]').forEach(btn => {
|
|
1333
|
+
btn.addEventListener('click', (e) => {
|
|
1334
|
+
e.stopPropagation();
|
|
1335
|
+
const el = getSessionElement(btn);
|
|
1336
|
+
const sessionId = el?.dataset.sessionId;
|
|
1337
|
+
const projectPath = el?.dataset.projectPath;
|
|
1338
|
+
const task = state.pendingTask;
|
|
1339
|
+
|
|
1340
|
+
if (sessionId && task) {
|
|
1341
|
+
window.dispatchEvent(new CustomEvent('welcome:continue-with-task', {
|
|
1342
|
+
detail: { sessionId, projectPath, task }
|
|
1343
|
+
}));
|
|
1344
|
+
// Reset state
|
|
1345
|
+
state.taskMode = false;
|
|
1346
|
+
state.pendingTask = null;
|
|
1347
|
+
state.searchResults = null;
|
|
1348
|
+
expandedGroups.clear();
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
// "Fork" button in task mode - create a fork of session and send task there
|
|
1354
|
+
container.querySelectorAll('[data-action="fork-with-task"]').forEach(btn => {
|
|
1355
|
+
btn.addEventListener('click', (e) => {
|
|
1356
|
+
e.stopPropagation();
|
|
1357
|
+
const el = getSessionElement(btn);
|
|
1358
|
+
const sessionId = el?.dataset.sessionId;
|
|
1359
|
+
const projectPath = el?.dataset.projectPath;
|
|
1360
|
+
const task = state.pendingTask;
|
|
1361
|
+
|
|
1362
|
+
if (sessionId && task) {
|
|
1363
|
+
window.dispatchEvent(new CustomEvent('welcome:fork-with-task', {
|
|
1364
|
+
detail: { sessionId, projectPath, task }
|
|
1365
|
+
}));
|
|
1366
|
+
// Reset state
|
|
1367
|
+
state.taskMode = false;
|
|
1368
|
+
state.pendingTask = null;
|
|
1369
|
+
state.searchResults = null;
|
|
1370
|
+
expandedGroups.clear();
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
// Toggle project group expand/collapse
|
|
1376
|
+
container.querySelectorAll('[data-action="toggle-group"]').forEach(el => {
|
|
1377
|
+
el.addEventListener('click', (e) => {
|
|
1378
|
+
e.stopPropagation();
|
|
1379
|
+
const groupId = el.dataset.group;
|
|
1380
|
+
if (groupId) {
|
|
1381
|
+
if (expandedGroups.has(groupId)) {
|
|
1382
|
+
expandedGroups.delete(groupId);
|
|
1383
|
+
} else {
|
|
1384
|
+
expandedGroups.add(groupId);
|
|
1385
|
+
}
|
|
1386
|
+
renderWelcomeScreen(container);
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
// "Start Fresh" button - create new session with pending task
|
|
1392
|
+
container.querySelector('[data-action="start-fresh"]')?.addEventListener('click', () => {
|
|
1393
|
+
const task = state.pendingTask;
|
|
1394
|
+
if (task) {
|
|
1395
|
+
window.dispatchEvent(new CustomEvent('welcome:start-fresh-task', {
|
|
1396
|
+
detail: { task }
|
|
1397
|
+
}));
|
|
1398
|
+
// Reset state
|
|
1399
|
+
state.taskMode = false;
|
|
1400
|
+
state.pendingTask = null;
|
|
1401
|
+
state.searchResults = null;
|
|
1402
|
+
expandedGroups.clear();
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1406
|
+
// "Cancel" button - go back to welcome screen
|
|
1407
|
+
container.querySelector('[data-action="cancel-task"]')?.addEventListener('click', () => {
|
|
1408
|
+
state.taskMode = false;
|
|
1409
|
+
state.pendingTask = null;
|
|
1410
|
+
state.searchResults = null;
|
|
1411
|
+
expandedGroups.clear();
|
|
1412
|
+
renderWelcomeScreen(container);
|
|
1413
|
+
window.dispatchEvent(new CustomEvent('welcome:clear-input'));
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1418
|
+
// PUBLIC API — INIT + SEARCH + REFRESH
|
|
1419
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* Initialize the welcome screen.
|
|
1423
|
+
*
|
|
1424
|
+
* @param {HTMLElement} container - Container element to render into
|
|
1425
|
+
* @param {string} sessionId - Session/tab identifier (used to track state per-session)
|
|
1426
|
+
*/
|
|
1427
|
+
export async function initWelcomeScreen(container, sessionId = null) {
|
|
1428
|
+
// Install document-level arrow key handler (once)
|
|
1429
|
+
installWelcomeArrowHandler();
|
|
1430
|
+
|
|
1431
|
+
// Check if this is a different session/tab than before
|
|
1432
|
+
// If so, we must reset state to avoid leaking search results between tabs
|
|
1433
|
+
const isSameSession = sessionId && state.forSessionId === sessionId;
|
|
1434
|
+
const hasSearchState = state.taskMode;
|
|
1435
|
+
|
|
1436
|
+
// Only preserve state if:
|
|
1437
|
+
// 1. It's the SAME session (switching back to a tab with search results)
|
|
1438
|
+
// 2. AND we actually have search state to preserve
|
|
1439
|
+
const preserveSearchState = isSameSession && hasSearchState;
|
|
1440
|
+
|
|
1441
|
+
if (preserveSearchState) {
|
|
1442
|
+
// Only reset transient state (preview, context menu)
|
|
1443
|
+
state.previewSession = null;
|
|
1444
|
+
state.previewMessages = null;
|
|
1445
|
+
state.previewLoading = false;
|
|
1446
|
+
state.contextMenuSession = null;
|
|
1447
|
+
state.contextMenuPos = null;
|
|
1448
|
+
state.contextMenuContainer = null;
|
|
1449
|
+
debug.log('[Welcome] Preserving search state for session:', sessionId);
|
|
1450
|
+
} else {
|
|
1451
|
+
// Full reset for new sessions or tabs
|
|
1452
|
+
debug.log('[Welcome] Reset state for session:', sessionId, '(was:', state.forSessionId, ')');
|
|
1453
|
+
state.forSessionId = sessionId;
|
|
1454
|
+
state.searchResults = null;
|
|
1455
|
+
state.searchQuery = '';
|
|
1456
|
+
state.isSearching = false;
|
|
1457
|
+
state.showProjectPicker = false;
|
|
1458
|
+
state.taskMode = false;
|
|
1459
|
+
state.pendingTask = null;
|
|
1460
|
+
state.quickSearchFilter = ''; // Clear search text
|
|
1461
|
+
state.quickSearchActive = false; // Reset search active state
|
|
1462
|
+
state.previewSession = null;
|
|
1463
|
+
state.previewMessages = null;
|
|
1464
|
+
state.previewLoading = false;
|
|
1465
|
+
state.contextMenuSession = null;
|
|
1466
|
+
state.contextMenuPos = null;
|
|
1467
|
+
state.contextMenuContainer = null;
|
|
1468
|
+
expandedGroups.clear();
|
|
1469
|
+
recentLimit.value = 10; // Reset to default
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// Render immediately with current state (may be empty on first load)
|
|
1473
|
+
// This prevents a blank flash if the container becomes visible before API calls complete
|
|
1474
|
+
renderWelcomeScreen(container);
|
|
1475
|
+
|
|
1476
|
+
// Load data in parallel
|
|
1477
|
+
await Promise.all([
|
|
1478
|
+
loadRecentSessions(),
|
|
1479
|
+
loadProjects(),
|
|
1480
|
+
loadFavorites(),
|
|
1481
|
+
loadActiveSessions(),
|
|
1482
|
+
]);
|
|
1483
|
+
|
|
1484
|
+
// Enrich with local session status
|
|
1485
|
+
updateOpenSessionIds();
|
|
1486
|
+
mergeLocalSessions();
|
|
1487
|
+
|
|
1488
|
+
// Re-render with real data
|
|
1489
|
+
renderWelcomeScreen(container);
|
|
1490
|
+
|
|
1491
|
+
// Auto-focus search input on desktop (devices with physical keyboard)
|
|
1492
|
+
// This ensures typing immediately goes to search bar
|
|
1493
|
+
if (!/iPhone/.test(navigator.userAgent)) {
|
|
1494
|
+
requestAnimationFrame(() => {
|
|
1495
|
+
const searchInput = container.querySelector('.welcome-search-input');
|
|
1496
|
+
if (!searchInput) return;
|
|
1497
|
+
// Only claim focus when nothing else owns it — this async load can
|
|
1498
|
+
// land after the user opened a widget (e.g. Search in Files) or
|
|
1499
|
+
// started typing elsewhere; yanking focus from them is hostile.
|
|
1500
|
+
const ae = document.activeElement;
|
|
1501
|
+
if (!ae || ae === document.body || container.contains(ae)) {
|
|
1502
|
+
searchInput.focus();
|
|
1503
|
+
debug.log('[Welcome] Auto-focused search input');
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* Handle task message - search for related sessions and show options.
|
|
1511
|
+
*
|
|
1512
|
+
* Instead of immediately creating a new session, this:
|
|
1513
|
+
* 1. Searches for related existing sessions
|
|
1514
|
+
* 2. Shows them with "Continue here" or "Start Fresh" options
|
|
1515
|
+
* 3. User chooses to resume an existing session or start new
|
|
1516
|
+
*
|
|
1517
|
+
* @param {string} task - The task/message user wants to send
|
|
1518
|
+
* @param {HTMLElement} container - Container to re-render
|
|
1519
|
+
*/
|
|
1520
|
+
export async function handleWelcomeTask(task, container) {
|
|
1521
|
+
state.isSearching = true;
|
|
1522
|
+
state.pendingTask = task;
|
|
1523
|
+
renderWelcomeScreen(container);
|
|
1524
|
+
|
|
1525
|
+
try {
|
|
1526
|
+
// Search for related sessions based on the task
|
|
1527
|
+
// Fetch more to allow grouping by project
|
|
1528
|
+
const response = await fetch(`${CONFIG.API_BASE}/api/welcome/search`, {
|
|
1529
|
+
method: 'POST',
|
|
1530
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1531
|
+
body: JSON.stringify({ query: task, limit: 30 }),
|
|
1532
|
+
});
|
|
1533
|
+
|
|
1534
|
+
if (!response.ok) throw new Error('Search failed');
|
|
1535
|
+
|
|
1536
|
+
const data = await response.json();
|
|
1537
|
+
state.searchResults = data;
|
|
1538
|
+
} catch (e) {
|
|
1539
|
+
console.error('Task search failed:', e);
|
|
1540
|
+
state.searchResults = { results: [] };
|
|
1541
|
+
} finally {
|
|
1542
|
+
state.isSearching = false;
|
|
1543
|
+
state.taskMode = true;
|
|
1544
|
+
renderWelcomeScreen(container);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* Check if we're in task mode (showing related sessions for a task).
|
|
1550
|
+
*/
|
|
1551
|
+
export function isTaskMode() {
|
|
1552
|
+
return state.taskMode;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Get the pending task.
|
|
1557
|
+
*/
|
|
1558
|
+
export function getPendingTask() {
|
|
1559
|
+
return state.pendingTask;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
/**
|
|
1563
|
+
* Reset the welcome screen to default state.
|
|
1564
|
+
*/
|
|
1565
|
+
export function resetWelcomeScreen(container) {
|
|
1566
|
+
state.taskMode = false;
|
|
1567
|
+
state.searchResults = null;
|
|
1568
|
+
state.searchQuery = '';
|
|
1569
|
+
state.pendingTask = null;
|
|
1570
|
+
state.showProjectPicker = false;
|
|
1571
|
+
state.previewSession = null;
|
|
1572
|
+
state.previewMessages = null;
|
|
1573
|
+
state.previewLoading = false;
|
|
1574
|
+
state.contextMenuSession = null;
|
|
1575
|
+
state.contextMenuPos = null;
|
|
1576
|
+
state.contextMenuContainer = null;
|
|
1577
|
+
state.quickSearchFilter = '';
|
|
1578
|
+
state.quickSearchActive = false;
|
|
1579
|
+
state.selectedResultIndex = -1;
|
|
1580
|
+
expandedGroups.clear();
|
|
1581
|
+
renderWelcomeScreen(container);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
/**
|
|
1586
|
+
* Open/focus the search input on welcome screen.
|
|
1587
|
+
* @param {string} [initialValue] - Optional initial text to put in search
|
|
1588
|
+
* @returns {boolean} - True if opened, false if not on welcome screen
|
|
1589
|
+
*/
|
|
1590
|
+
export function openQuickSearch(initialValue = '') {
|
|
1591
|
+
const container = document.getElementById('welcome-container');
|
|
1592
|
+
if (!container) return false;
|
|
1593
|
+
|
|
1594
|
+
state.quickSearchActive = !!initialValue;
|
|
1595
|
+
state.quickSearchFilter = initialValue;
|
|
1596
|
+
renderWelcomeScreen(container);
|
|
1597
|
+
|
|
1598
|
+
// Focus the input after re-render
|
|
1599
|
+
requestAnimationFrame(() => {
|
|
1600
|
+
const input = container.querySelector('.welcome-search-input');
|
|
1601
|
+
if (input) {
|
|
1602
|
+
input.focus();
|
|
1603
|
+
// Put cursor at end
|
|
1604
|
+
input.selectionStart = input.selectionEnd = input.value.length;
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
return true;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* Check if quick search is active.
|
|
1613
|
+
*/
|
|
1614
|
+
export function isQuickSearchActive() {
|
|
1615
|
+
return state.quickSearchActive;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Check if welcome search has content that can be cleared.
|
|
1620
|
+
*/
|
|
1621
|
+
export function hasWelcomeSearchContent() {
|
|
1622
|
+
return !!(state.quickSearchFilter || state.projectFilter);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* Clear/reset the welcome search.
|
|
1627
|
+
* @returns {boolean} True if something was cleared
|
|
1628
|
+
*/
|
|
1629
|
+
export function clearWelcomeSearch() {
|
|
1630
|
+
if (!hasWelcomeSearchContent()) return false;
|
|
1631
|
+
|
|
1632
|
+
const container = document.getElementById('welcome-container');
|
|
1633
|
+
if (!container) return false;
|
|
1634
|
+
|
|
1635
|
+
// Two-stage Escape. During a search the first result is the resting
|
|
1636
|
+
// selection (renderWelcomeScreen re-anchors it), so "deselect but keep the
|
|
1637
|
+
// query" isn't a reachable state — an Escape that arrives after the user
|
|
1638
|
+
// arrowed away steps back to the first result instead of throwing the
|
|
1639
|
+
// query away. A second Escape then clears, as before.
|
|
1640
|
+
if (state.quickSearchFilter && state.selectedResultIndex > 0) {
|
|
1641
|
+
state.selectedResultIndex = 0;
|
|
1642
|
+
renderWelcomeScreen(container);
|
|
1643
|
+
scrollSelectedIntoView(container);
|
|
1644
|
+
return true;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
state.quickSearchActive = false;
|
|
1648
|
+
state.quickSearchFilter = '';
|
|
1649
|
+
state.projectFilter = null;
|
|
1650
|
+
state.selectedResultIndex = -1;
|
|
1651
|
+
|
|
1652
|
+
renderWelcomeScreen(container);
|
|
1653
|
+
|
|
1654
|
+
// Re-focus empty input
|
|
1655
|
+
requestAnimationFrame(() => {
|
|
1656
|
+
container.querySelector('.welcome-search-input')?.focus();
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* Type a character into the search input.
|
|
1664
|
+
* Opens quick search if not already active.
|
|
1665
|
+
* @param {string} char - Character to append
|
|
1666
|
+
*/
|
|
1667
|
+
export function typeIntoQuickSearch(char) {
|
|
1668
|
+
const container = document.getElementById('welcome-container');
|
|
1669
|
+
if (!container) {
|
|
1670
|
+
console.debug('[TypeIntoQuickSearch] No welcome-container found');
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
console.debug('[TypeIntoQuickSearch] Adding char:', char, 'to filter:', state.quickSearchFilter);
|
|
1675
|
+
|
|
1676
|
+
// Append character to filter
|
|
1677
|
+
state.quickSearchActive = true;
|
|
1678
|
+
state.quickSearchFilter = (state.quickSearchFilter || '') + char;
|
|
1679
|
+
|
|
1680
|
+
renderWelcomeScreen(container);
|
|
1681
|
+
|
|
1682
|
+
// Focus and set cursor
|
|
1683
|
+
requestAnimationFrame(() => {
|
|
1684
|
+
const input = container.querySelector('.welcome-search-input');
|
|
1685
|
+
if (input) {
|
|
1686
|
+
input.focus();
|
|
1687
|
+
input.selectionStart = input.selectionEnd = input.value.length;
|
|
1688
|
+
console.debug('[TypeIntoQuickSearch] Focused input, value:', input.value);
|
|
1689
|
+
} else {
|
|
1690
|
+
console.debug('[TypeIntoQuickSearch] No .welcome-search-input found in container');
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Refresh sessions data including status indicators.
|
|
1697
|
+
*/
|
|
1698
|
+
export async function refreshSessions(container) {
|
|
1699
|
+
await Promise.all([
|
|
1700
|
+
loadRecentSessions(),
|
|
1701
|
+
loadActiveSessions(),
|
|
1702
|
+
]);
|
|
1703
|
+
updateOpenSessionIds();
|
|
1704
|
+
mergeLocalSessions();
|
|
1705
|
+
|
|
1706
|
+
renderWelcomeScreen(container);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1710
|
+
// WELCOME STATE PERSISTENCE (for "Back to sessions" feature)
|
|
1711
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Get the saved welcome state (for restoring after "back to sessions").
|
|
1715
|
+
*/
|
|
1716
|
+
export function getSavedWelcomeState() {
|
|
1717
|
+
return savedWelcomeState.value;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Clear the saved welcome state.
|
|
1722
|
+
*/
|
|
1723
|
+
export function clearSavedWelcomeState() {
|
|
1724
|
+
savedWelcomeState.value = null;
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Restore the saved welcome state after returning from a session.
|
|
1729
|
+
*/
|
|
1730
|
+
export function restoreWelcomeState(container) {
|
|
1731
|
+
if (!savedWelcomeState.value) return false;
|
|
1732
|
+
|
|
1733
|
+
debug.log('[Welcome] Restoring state:', savedWelcomeState.value);
|
|
1734
|
+
|
|
1735
|
+
// Restore state variables
|
|
1736
|
+
state.taskMode = savedWelcomeState.value.taskMode || false;
|
|
1737
|
+
state.pendingTask = savedWelcomeState.value.pendingTask || null;
|
|
1738
|
+
state.searchResults = savedWelcomeState.value.searchResults || null;
|
|
1739
|
+
|
|
1740
|
+
// Restore expanded groups
|
|
1741
|
+
expandedGroups.clear();
|
|
1742
|
+
if (savedWelcomeState.value.expandedGroups) {
|
|
1743
|
+
savedWelcomeState.value.expandedGroups.forEach(g => expandedGroups.add(g));
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
// Render
|
|
1747
|
+
renderWelcomeScreen(container);
|
|
1748
|
+
|
|
1749
|
+
// Capture values before clearing - rAF callback runs after savedWelcomeState is nulled
|
|
1750
|
+
const scrollTop = savedWelcomeState.value.scrollTop;
|
|
1751
|
+
const inputValue = savedWelcomeState.value.inputValue;
|
|
1752
|
+
|
|
1753
|
+
// Clear saved state now (before async callbacks)
|
|
1754
|
+
savedWelcomeState.value = null;
|
|
1755
|
+
|
|
1756
|
+
// Restore scroll position after render
|
|
1757
|
+
requestAnimationFrame(() => {
|
|
1758
|
+
const welcomeEl = container.querySelector('.welcome-screen');
|
|
1759
|
+
if (welcomeEl && scrollTop) {
|
|
1760
|
+
welcomeEl.scrollTop = scrollTop;
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// Restore input value
|
|
1765
|
+
const searchInput = document.querySelector('.input-area textarea');
|
|
1766
|
+
if (searchInput && inputValue) {
|
|
1767
|
+
searchInput.value = inputValue;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
return true;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1774
|
+
// FAVORITES API (exported for use from other modules)
|
|
1775
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Check if a session is favorited.
|
|
1779
|
+
* @param {string} sessionId
|
|
1780
|
+
* @returns {boolean}
|
|
1781
|
+
*/
|
|
1782
|
+
export function isFavoriteSession(sessionId) {
|
|
1783
|
+
return state.favoritesSet.has(sessionId);
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
* Get all favorited session IDs.
|
|
1788
|
+
* @returns {Set<string>}
|
|
1789
|
+
*/
|
|
1790
|
+
export function getFavoriteIds() {
|
|
1791
|
+
return new Set(state.favoritesSet);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* Toggle favorite status for a session.
|
|
1796
|
+
* Can be called from outside welcome.js (e.g., tab context menu).
|
|
1797
|
+
* Dispatches 'welcome:favorites-changed' event for UI sync.
|
|
1798
|
+
*
|
|
1799
|
+
* @param {string} sessionId
|
|
1800
|
+
* @param {string} [note] - Optional note (only used when adding)
|
|
1801
|
+
* @returns {Promise<boolean>} New favorite status
|
|
1802
|
+
*/
|
|
1803
|
+
export async function toggleFavoriteSession(sessionId, note = null) {
|
|
1804
|
+
// Validate sessionId
|
|
1805
|
+
if (!sessionId) {
|
|
1806
|
+
console.error('toggleFavoriteSession: No session ID provided');
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
const isFav = state.favoritesSet.has(sessionId);
|
|
1811
|
+
debug.log(`toggleFavoriteSession: ${sessionId}, currently ${isFav ? 'favorited' : 'not favorited'}`);
|
|
1812
|
+
|
|
1813
|
+
try {
|
|
1814
|
+
if (isFav) {
|
|
1815
|
+
// Remove from favorites
|
|
1816
|
+
const response = await fetch(`${CONFIG.API_BASE}/api/favorites/${sessionId}`, {
|
|
1817
|
+
method: 'DELETE',
|
|
1818
|
+
});
|
|
1819
|
+
if (!response.ok) {
|
|
1820
|
+
const err = await response.json().catch(() => ({}));
|
|
1821
|
+
throw new Error(extractApiError(err, `Failed to remove favorite (${response.status})`));
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
state.favoritesSet.delete(sessionId);
|
|
1825
|
+
state.favorites = state.favorites.filter(f => f.session_id !== sessionId);
|
|
1826
|
+
} else {
|
|
1827
|
+
// Add to favorites (only include note if it's not null/undefined)
|
|
1828
|
+
const body = note ? { note } : {};
|
|
1829
|
+
const response = await fetch(`${CONFIG.API_BASE}/api/favorites/${sessionId}`, {
|
|
1830
|
+
method: 'POST',
|
|
1831
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1832
|
+
body: JSON.stringify(body),
|
|
1833
|
+
});
|
|
1834
|
+
if (!response.ok) {
|
|
1835
|
+
const err = await response.json().catch(() => ({}));
|
|
1836
|
+
throw new Error(extractApiError(err, `Failed to add favorite (${response.status})`));
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
state.favoritesSet.add(sessionId);
|
|
1840
|
+
// Note: full session data will be fetched on next welcome screen load
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// Dispatch event so welcome screen can refresh if visible
|
|
1844
|
+
window.dispatchEvent(new CustomEvent('welcome:favorites-changed', {
|
|
1845
|
+
detail: { sessionId, isFavorite: !isFav }
|
|
1846
|
+
}));
|
|
1847
|
+
|
|
1848
|
+
return !isFav;
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
console.error('Failed to toggle favorite:', e);
|
|
1851
|
+
// Return null to indicate error - caller should handle this
|
|
1852
|
+
return null;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* Load favorites from server (for initial load or refresh).
|
|
1858
|
+
* Updates internal state and returns the favorites list.
|
|
1859
|
+
*/
|
|
1860
|
+
export async function loadFavoritesFromServer() {
|
|
1861
|
+
try {
|
|
1862
|
+
const response = await fetch(`${CONFIG.API_BASE}/api/favorites`);
|
|
1863
|
+
if (!response.ok) throw new Error('Failed to load favorites');
|
|
1864
|
+
|
|
1865
|
+
const data = await response.json();
|
|
1866
|
+
state.favorites = data.favorites || [];
|
|
1867
|
+
state.favoritesSet = new Set(state.favorites.map(f => f.session_id));
|
|
1868
|
+
return state.favorites;
|
|
1869
|
+
} catch (e) {
|
|
1870
|
+
console.error('Failed to load favorites:', e);
|
|
1871
|
+
return [];
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|