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,1119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Explorer Widget - Redesigned for usability
|
|
3
|
+
*
|
|
4
|
+
* Design principles:
|
|
5
|
+
* - Show more text by default (recognition is key)
|
|
6
|
+
* - One-tap copy (most common action)
|
|
7
|
+
* - Timeline grouping (Today, Yesterday, This Week, etc.)
|
|
8
|
+
* - Expand to see full prompt
|
|
9
|
+
* - Touch-friendly with large tap targets
|
|
10
|
+
* - Clean, scannable layout
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import S from '../strings.js';
|
|
14
|
+
import { escapeHtml, $, formatTimeOrDate } from '../utils.js';
|
|
15
|
+
import { CONFIG, debug } from '../config.js';
|
|
16
|
+
import { WidgetManager, ICONS } from '../widget-system/index.js';
|
|
17
|
+
import * as PromptFavorites from '../prompt-favorites.js';
|
|
18
|
+
import { MarkdownRenderer } from '../components.js';
|
|
19
|
+
import { SHORTCUTS, resolveKeys, formatKeyForDisplay } from '../shortcuts.js';
|
|
20
|
+
import { getProjectColor } from '../project-colors.js';
|
|
21
|
+
import { showToast } from '../context-menu.js';
|
|
22
|
+
import { basename } from '../path-utils.js';
|
|
23
|
+
|
|
24
|
+
let mdRenderer = null;
|
|
25
|
+
function getMarkdown() {
|
|
26
|
+
if (!mdRenderer) mdRenderer = new MarkdownRenderer();
|
|
27
|
+
return mdRenderer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
31
|
+
// STATE
|
|
32
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
33
|
+
|
|
34
|
+
class PromptExplorerState {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.prompts = [];
|
|
37
|
+
this.total = 0;
|
|
38
|
+
this.loading = false;
|
|
39
|
+
this.error = null;
|
|
40
|
+
this.container = null;
|
|
41
|
+
this.searchQuery = '';
|
|
42
|
+
this.expandedId = null; // Currently expanded prompt
|
|
43
|
+
this.responseCache = new Map(); // prompt_id -> { state: 'loading'|'ready'|'error', text: string }
|
|
44
|
+
this._searchDebounce = null;
|
|
45
|
+
// Query parsing info from API
|
|
46
|
+
this.queryInfo = null; // { filters: [], highlight_terms: [] }
|
|
47
|
+
this.showHints = false; // Toggle search syntax hints
|
|
48
|
+
this.currentProjectOnly = localStorage.getItem('pe-current-project-only') !== 'false'; // default true
|
|
49
|
+
// View switcher: 'history' (sent prompts) | 'drafts' (saved for later)
|
|
50
|
+
this.view = 'history';
|
|
51
|
+
this.drafts = [];
|
|
52
|
+
this.draftsLoading = false;
|
|
53
|
+
this.draftsError = null;
|
|
54
|
+
this.armedDeleteId = null; // Two-click delete confirmation (no window.confirm on iPad)
|
|
55
|
+
this.armedClearAll = false; // Two-click confirm for "Clear All" drafts
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const state = new PromptExplorerState();
|
|
60
|
+
|
|
61
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
62
|
+
// SEARCH SYNTAX HINTS
|
|
63
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
64
|
+
|
|
65
|
+
const SEARCH_SYNTAX = [
|
|
66
|
+
{ syntax: '"exact phrase"', desc: 'Exact match' },
|
|
67
|
+
{ syntax: '-exclude', desc: 'Exclude term' },
|
|
68
|
+
{ syntax: 'word1 OR word2', desc: 'Either term' },
|
|
69
|
+
{ syntax: 'in:response', desc: 'Search Claude\'s responses' },
|
|
70
|
+
{ syntax: 'fav:', desc: 'Favorited prompts only' },
|
|
71
|
+
{ syntax: 'long:', desc: 'Long prompts (>500 chars)' },
|
|
72
|
+
{ syntax: 'short:', desc: 'Short prompts (<100 chars)' },
|
|
73
|
+
{ syntax: 'has:image', desc: 'Prompts with images' },
|
|
74
|
+
{ syntax: 'has:stash', desc: 'Prompts with stash context' },
|
|
75
|
+
{ syntax: 'today:', desc: 'Today only' },
|
|
76
|
+
{ syntax: 'week:', desc: 'Last 7 days' },
|
|
77
|
+
{ syntax: 'after:2026-01-15', desc: 'After date' },
|
|
78
|
+
{ syntax: 'project:name', desc: 'Filter by project' },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const _pf = S.widgets.prompt_explorer.quick_filters;
|
|
82
|
+
const QUICK_FILTERS = [
|
|
83
|
+
{ label: _pf.favorites, query: 'fav:' },
|
|
84
|
+
{ label: _pf.today, query: 'today:' },
|
|
85
|
+
{ label: _pf.this_week, query: 'week:' },
|
|
86
|
+
{ label: _pf.long, query: 'long:' },
|
|
87
|
+
{ label: _pf.with_images, query: 'has:image' },
|
|
88
|
+
{ label: _pf.with_stash, query: 'has:stash' },
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
92
|
+
// UTILITIES
|
|
93
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Group prompts by time period
|
|
97
|
+
*/
|
|
98
|
+
function groupByTimePeriod(prompts) {
|
|
99
|
+
const now = new Date();
|
|
100
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
101
|
+
const yesterday = new Date(today.getTime() - 86400000);
|
|
102
|
+
const thisWeek = new Date(today.getTime() - 7 * 86400000);
|
|
103
|
+
const thisMonth = new Date(today.getTime() - 30 * 86400000);
|
|
104
|
+
|
|
105
|
+
const _tp = S.time_periods;
|
|
106
|
+
const groups = {
|
|
107
|
+
[_tp.today]: [],
|
|
108
|
+
[_tp.yesterday]: [],
|
|
109
|
+
[_tp.this_week]: [],
|
|
110
|
+
[_tp.this_month]: [],
|
|
111
|
+
[_tp.older]: []
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
for (const prompt of prompts) {
|
|
115
|
+
const date = new Date(prompt.timestamp);
|
|
116
|
+
if (date >= today) {
|
|
117
|
+
groups[_tp.today].push(prompt);
|
|
118
|
+
} else if (date >= yesterday) {
|
|
119
|
+
groups[_tp.yesterday].push(prompt);
|
|
120
|
+
} else if (date >= thisWeek) {
|
|
121
|
+
groups[_tp.this_week].push(prompt);
|
|
122
|
+
} else if (date >= thisMonth) {
|
|
123
|
+
groups[_tp.this_month].push(prompt);
|
|
124
|
+
} else {
|
|
125
|
+
groups[_tp.older].push(prompt);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return groups;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get short project name
|
|
134
|
+
*/
|
|
135
|
+
function getProjectName(path) {
|
|
136
|
+
if (!path) return '';
|
|
137
|
+
const parts = path.split('/');
|
|
138
|
+
return parts[parts.length - 1] || parts[parts.length - 2] || '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Highlight search matches - supports multiple terms from parsed query
|
|
143
|
+
*/
|
|
144
|
+
function highlightMatches(text, query) {
|
|
145
|
+
if (!text) return escapeHtml(text);
|
|
146
|
+
|
|
147
|
+
// Get highlight terms from query info if available
|
|
148
|
+
let terms = [];
|
|
149
|
+
if (state.queryInfo?.highlight_terms?.length) {
|
|
150
|
+
terms = state.queryInfo.highlight_terms;
|
|
151
|
+
} else if (query) {
|
|
152
|
+
// Fallback to simple query split
|
|
153
|
+
terms = query.split(/\s+/).filter(t => t && !t.startsWith('-') && t !== 'OR');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (terms.length === 0) return escapeHtml(text);
|
|
157
|
+
|
|
158
|
+
const escaped = escapeHtml(text);
|
|
159
|
+
try {
|
|
160
|
+
// Build pattern for all terms
|
|
161
|
+
const patterns = terms.map(t => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
162
|
+
const pattern = new RegExp(`(${patterns.join('|')})`, 'gi');
|
|
163
|
+
return escaped.replace(pattern, '<mark>$1</mark>');
|
|
164
|
+
} catch {
|
|
165
|
+
return escaped;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
170
|
+
// DATA LOADING
|
|
171
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
172
|
+
|
|
173
|
+
async function loadPrompts() {
|
|
174
|
+
state.loading = true;
|
|
175
|
+
state.error = null;
|
|
176
|
+
renderContent();
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const params = new URLSearchParams({ limit: '100' });
|
|
180
|
+
if (state.searchQuery) {
|
|
181
|
+
params.set('q', state.searchQuery);
|
|
182
|
+
}
|
|
183
|
+
if (state.currentProjectOnly) {
|
|
184
|
+
const cwd = window.app?.activeSession?.cwd;
|
|
185
|
+
if (cwd) params.set('project', cwd);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const url = `${CONFIG.API_BASE}/api/prompts?${params}`;
|
|
189
|
+
const response = await fetch(url);
|
|
190
|
+
const data = await response.json();
|
|
191
|
+
|
|
192
|
+
state.prompts = data.prompts || [];
|
|
193
|
+
state.total = data.total || 0;
|
|
194
|
+
state.queryInfo = data.query || null; // Store parsed query info
|
|
195
|
+
state.loading = false;
|
|
196
|
+
renderContent();
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error('Failed to load prompts:', error);
|
|
199
|
+
state.loading = false;
|
|
200
|
+
state.error = 'Failed to load prompts';
|
|
201
|
+
state.queryInfo = null;
|
|
202
|
+
renderContent();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function debouncedSearch(query) {
|
|
207
|
+
state.searchQuery = query;
|
|
208
|
+
if (state._searchDebounce) clearTimeout(state._searchDebounce);
|
|
209
|
+
// 400ms debounce - enough time to type several characters
|
|
210
|
+
state._searchDebounce = setTimeout(() => loadPrompts(), 400);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function loadDrafts() {
|
|
214
|
+
state.draftsLoading = true;
|
|
215
|
+
state.draftsError = null;
|
|
216
|
+
renderContent();
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const response = await fetch(`${CONFIG.API_BASE}/api/drafts`);
|
|
220
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
221
|
+
const data = await response.json();
|
|
222
|
+
state.drafts = data.drafts || [];
|
|
223
|
+
state.draftsLoading = false;
|
|
224
|
+
renderContent();
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.error('Failed to load drafts:', error);
|
|
227
|
+
state.draftsLoading = false;
|
|
228
|
+
state.draftsError = S.widgets.prompt_explorer.drafts.error;
|
|
229
|
+
renderContent();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
234
|
+
// ACTIONS
|
|
235
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
236
|
+
|
|
237
|
+
async function copyPrompt(prompt, btn) {
|
|
238
|
+
try {
|
|
239
|
+
await navigator.clipboard.writeText(prompt.content);
|
|
240
|
+
// Visual feedback
|
|
241
|
+
const originalHTML = btn.innerHTML;
|
|
242
|
+
btn.innerHTML = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg> Copied!`;
|
|
243
|
+
btn.classList.add('copied');
|
|
244
|
+
setTimeout(() => {
|
|
245
|
+
btn.innerHTML = originalHTML;
|
|
246
|
+
btn.classList.remove('copied');
|
|
247
|
+
}, 1500);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error('Copy failed:', error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function insertPrompt(prompt) {
|
|
254
|
+
const input = $('#message-input');
|
|
255
|
+
if (input) {
|
|
256
|
+
input.value = prompt.content;
|
|
257
|
+
input.focus();
|
|
258
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
259
|
+
}
|
|
260
|
+
WidgetManager.close('prompt-explorer');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function openSession(prompt) {
|
|
264
|
+
const app = window.app;
|
|
265
|
+
if (!app) return;
|
|
266
|
+
|
|
267
|
+
WidgetManager.close('prompt-explorer');
|
|
268
|
+
|
|
269
|
+
// Check if session is already open in a tab
|
|
270
|
+
const existing = app.sessionManager?.sessions?.find(s => s.storeId === prompt.session_id);
|
|
271
|
+
if (existing) {
|
|
272
|
+
app.switchToSession(existing);
|
|
273
|
+
// Scroll to the specific prompt after a brief delay for render
|
|
274
|
+
setTimeout(() => {
|
|
275
|
+
app.chatCtrl?.scrollToMessage(prompt.timestamp, prompt.id);
|
|
276
|
+
}, 100);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Load from server if not already open
|
|
281
|
+
const loaded = await app.loadSessionFromServer(prompt.session_id);
|
|
282
|
+
if (loaded) {
|
|
283
|
+
// Scroll to the specific prompt after session loads
|
|
284
|
+
setTimeout(() => {
|
|
285
|
+
app.chatCtrl?.scrollToMessage(prompt.timestamp, prompt.id);
|
|
286
|
+
}, 200);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function runInNewSession(prompt) {
|
|
291
|
+
const app = window.app;
|
|
292
|
+
if (!app) return;
|
|
293
|
+
|
|
294
|
+
WidgetManager.close('prompt-explorer');
|
|
295
|
+
|
|
296
|
+
// Create a new session
|
|
297
|
+
const session = app.createSession();
|
|
298
|
+
if (!session) return;
|
|
299
|
+
|
|
300
|
+
// Set CWD from original prompt's project
|
|
301
|
+
const cwd = prompt.project_path;
|
|
302
|
+
if (cwd) {
|
|
303
|
+
session.cwd = cwd;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// cwd set → switch into chat view to populate the input
|
|
307
|
+
app.tabCtrl?.switchToSession(session);
|
|
308
|
+
app.els.messageInput.value = prompt.content;
|
|
309
|
+
app.els.messageInput.focus();
|
|
310
|
+
app.adjustTextareaHeight?.();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function switchView(view) {
|
|
314
|
+
if (state.view === view) return;
|
|
315
|
+
state.view = view;
|
|
316
|
+
state.armedDeleteId = null;
|
|
317
|
+
state.armedClearAll = false;
|
|
318
|
+
|
|
319
|
+
// Search area only applies to history; tabs re-render for active state
|
|
320
|
+
const searchArea = state.container?.querySelector('.pe-search-area');
|
|
321
|
+
if (searchArea) searchArea.style.display = view === 'drafts' ? 'none' : '';
|
|
322
|
+
state.container?.querySelectorAll('.pe-tab').forEach(btn => {
|
|
323
|
+
btn.classList.toggle('active', btn.dataset.view === view);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
if (view === 'drafts') {
|
|
327
|
+
loadDrafts();
|
|
328
|
+
} else {
|
|
329
|
+
renderContent();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Open the widget directly on the Drafts view (used by the input-area
|
|
335
|
+
* drafts pill). Handles both cold-open and already-open-on-History.
|
|
336
|
+
*/
|
|
337
|
+
export function openPromptExplorerDrafts() {
|
|
338
|
+
const wasDrafts = state.view === 'drafts';
|
|
339
|
+
state.view = 'drafts';
|
|
340
|
+
state.armedDeleteId = null;
|
|
341
|
+
state.armedClearAll = false;
|
|
342
|
+
WidgetManager.open('prompt-explorer'); // onOpen loads drafts for this view
|
|
343
|
+
if (!wasDrafts && state.container) {
|
|
344
|
+
// Widget may have been open on History — sync tabs + search area
|
|
345
|
+
const searchArea = state.container.querySelector('.pe-search-area');
|
|
346
|
+
if (searchArea) searchArea.style.display = 'none';
|
|
347
|
+
state.container.querySelectorAll('.pe-tab').forEach(btn =>
|
|
348
|
+
btn.classList.toggle('active', btn.dataset.view === 'drafts'));
|
|
349
|
+
loadDrafts();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Load a draft into the chat input — sending it consumes (deletes) it. */
|
|
354
|
+
function insertDraft(draft) {
|
|
355
|
+
const handler = window.app?.inputHandler;
|
|
356
|
+
if (!handler) return;
|
|
357
|
+
handler.insertSavedDraft(draft);
|
|
358
|
+
WidgetManager.close('prompt-explorer');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function copyDraft(draft, btn) {
|
|
362
|
+
try {
|
|
363
|
+
await navigator.clipboard.writeText(draft.text);
|
|
364
|
+
btn.classList.add('copied');
|
|
365
|
+
setTimeout(() => btn.classList.remove('copied'), 1500);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
console.error('Copy failed:', error);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Two-click delete: first click arms the button, second commits. */
|
|
372
|
+
async function deleteDraft(draft) {
|
|
373
|
+
if (state.armedDeleteId !== draft.id) {
|
|
374
|
+
state.armedDeleteId = draft.id;
|
|
375
|
+
renderContent();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
state.armedDeleteId = null;
|
|
379
|
+
state.armedClearAll = false;
|
|
380
|
+
try {
|
|
381
|
+
const res = await fetch(`${CONFIG.API_BASE}/api/drafts/${encodeURIComponent(draft.id)}`, {
|
|
382
|
+
method: 'DELETE'
|
|
383
|
+
});
|
|
384
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
385
|
+
state.drafts = state.drafts.filter(d => d.id !== draft.id);
|
|
386
|
+
// If this draft mirrored the live input (auto-sync link), unlink so
|
|
387
|
+
// the next sync doesn't 404 — note the still-typed text re-banks as
|
|
388
|
+
// a fresh draft on the next tick, by design
|
|
389
|
+
const handler = window.app?.inputHandler;
|
|
390
|
+
if (handler?.pendingDraftId === draft.id) handler.unlinkSavedDraft();
|
|
391
|
+
window.dispatchEvent(new CustomEvent('drafts-changed'));
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error('Failed to delete draft:', error);
|
|
394
|
+
}
|
|
395
|
+
renderContent();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** Two-click Clear All: first click arms the button, second wipes every draft. */
|
|
399
|
+
async function clearAllDrafts() {
|
|
400
|
+
if (!state.armedClearAll) {
|
|
401
|
+
state.armedClearAll = true;
|
|
402
|
+
renderContent();
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
state.armedClearAll = false;
|
|
406
|
+
try {
|
|
407
|
+
const res = await fetch(`${CONFIG.API_BASE}/api/drafts`, { method: 'DELETE' });
|
|
408
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
409
|
+
state.drafts = [];
|
|
410
|
+
state.armedDeleteId = null;
|
|
411
|
+
// Every draft is gone — unlink the live input's auto-sync draft (if any)
|
|
412
|
+
// so the next sync doesn't 404 against a deleted ID
|
|
413
|
+
const handler = window.app?.inputHandler;
|
|
414
|
+
if (handler?.pendingDraftId) handler.unlinkSavedDraft();
|
|
415
|
+
window.dispatchEvent(new CustomEvent('drafts-changed'));
|
|
416
|
+
showToast(S.widgets.prompt_explorer.drafts.cleared);
|
|
417
|
+
} catch (error) {
|
|
418
|
+
console.error('Failed to clear drafts:', error);
|
|
419
|
+
showToast(S.widgets.prompt_explorer.drafts.clear_failed);
|
|
420
|
+
}
|
|
421
|
+
renderContent();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function toggleExpand(promptId) {
|
|
425
|
+
const wasExpanded = state.expandedId === promptId;
|
|
426
|
+
state.expandedId = wasExpanded ? null : promptId;
|
|
427
|
+
renderContent();
|
|
428
|
+
if (!wasExpanded) {
|
|
429
|
+
ensureResponseFetched(promptId);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async function ensureResponseFetched(promptId) {
|
|
434
|
+
const cached = state.responseCache.get(promptId);
|
|
435
|
+
if (cached && cached.state !== 'error') return;
|
|
436
|
+
|
|
437
|
+
state.responseCache.set(promptId, { state: 'loading', text: '' });
|
|
438
|
+
try {
|
|
439
|
+
const url = `${CONFIG.API_BASE}/api/prompts/response/${encodeURIComponent(promptId)}`;
|
|
440
|
+
const res = await fetch(url);
|
|
441
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
442
|
+
const data = await res.json();
|
|
443
|
+
state.responseCache.set(promptId, { state: 'ready', text: data.response || '' });
|
|
444
|
+
} catch (err) {
|
|
445
|
+
console.error('Failed to load full response:', err);
|
|
446
|
+
state.responseCache.set(promptId, { state: 'error', text: '' });
|
|
447
|
+
}
|
|
448
|
+
if (state.expandedId === promptId) renderContent();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
452
|
+
// RENDERING
|
|
453
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
454
|
+
|
|
455
|
+
function renderViewTabs() {
|
|
456
|
+
const _t = S.widgets.prompt_explorer.tabs;
|
|
457
|
+
return `
|
|
458
|
+
<div class="pe-tabs">
|
|
459
|
+
<button class="pe-tab ${state.view === 'history' ? 'active' : ''}" data-view="history">${_t.history}</button>
|
|
460
|
+
<button class="pe-tab ${state.view === 'drafts' ? 'active' : ''}" data-view="drafts">${_t.drafts}</button>
|
|
461
|
+
</div>
|
|
462
|
+
`;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function renderDraftCard(draft) {
|
|
466
|
+
const _d = S.widgets.prompt_explorer.drafts;
|
|
467
|
+
const projectName = getProjectName(draft.cwd);
|
|
468
|
+
const projectColor = getProjectColor(draft.cwd);
|
|
469
|
+
const time = formatTimeOrDate(draft.updatedAt || draft.createdAt);
|
|
470
|
+
const preview = draft.text.length > 300 ? draft.text.substring(0, 300) + '...' : draft.text;
|
|
471
|
+
const isArmed = state.armedDeleteId === draft.id;
|
|
472
|
+
|
|
473
|
+
return `
|
|
474
|
+
<div class="pe-card pe-draft-card" data-id="${escapeHtml(draft.id)}">
|
|
475
|
+
<div class="pe-card-header">
|
|
476
|
+
<span class="pe-draft-title">${escapeHtml(draft.title || _d.untitled || 'Draft')}</span>
|
|
477
|
+
<span class="pe-card-time">${time}</span>
|
|
478
|
+
${projectName ? `
|
|
479
|
+
<span class="pe-card-project">
|
|
480
|
+
${projectColor ? `<span class="project-color-dot" style="background: ${projectColor}"></span>` : ''}
|
|
481
|
+
${escapeHtml(projectName)}
|
|
482
|
+
</span>
|
|
483
|
+
` : ''}
|
|
484
|
+
</div>
|
|
485
|
+
<div class="pe-card-content">${escapeHtml(preview)}</div>
|
|
486
|
+
<div class="pe-card-actions">
|
|
487
|
+
<button class="pe-btn pe-btn-insert" data-action="use-draft" data-tooltip="${escapeHtml(_d.use)}">
|
|
488
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
489
|
+
<path d="M12 5v14M5 12h14"/>
|
|
490
|
+
</svg>
|
|
491
|
+
${_d.use}
|
|
492
|
+
</button>
|
|
493
|
+
<button class="pe-btn pe-btn-copy" data-action="copy-draft" data-tooltip="${escapeHtml(_d.copy)}">
|
|
494
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
495
|
+
<rect x="9" y="9" width="13" height="13" rx="2"/>
|
|
496
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
|
497
|
+
</svg>
|
|
498
|
+
${_d.copy}
|
|
499
|
+
</button>
|
|
500
|
+
<button class="pe-btn pe-btn-delete-draft ${isArmed ? 'armed' : ''}" data-action="delete-draft">
|
|
501
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
502
|
+
<polyline points="3 6 5 6 21 6"/>
|
|
503
|
+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
|
|
504
|
+
</svg>
|
|
505
|
+
${isArmed ? _d.delete_confirm : _d.delete}
|
|
506
|
+
</button>
|
|
507
|
+
</div>
|
|
508
|
+
</div>
|
|
509
|
+
`;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function renderDraftsList() {
|
|
513
|
+
const _d = S.widgets.prompt_explorer.drafts;
|
|
514
|
+
|
|
515
|
+
if (state.draftsLoading) {
|
|
516
|
+
return `<div class="pe-loading">
|
|
517
|
+
<div class="pe-spinner"></div>
|
|
518
|
+
<span>${_d.loading}</span>
|
|
519
|
+
</div>`;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (state.draftsError) {
|
|
523
|
+
return `<div class="pe-error">${escapeHtml(state.draftsError)}</div>`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (state.drafts.length === 0) {
|
|
527
|
+
// Show the actual (possibly user-remapped) binding in the hint
|
|
528
|
+
const sc = SHORTCUTS.find(s => s.id === 'savePromptDraft');
|
|
529
|
+
const key = sc ? formatKeyForDisplay(resolveKeys(sc)[0] || 'Ctrl+Shift+S') : 'Ctrl+Shift+S';
|
|
530
|
+
return `<div class="pe-empty">${escapeHtml(_d.empty).replace('{shortcut}', `<kbd>${escapeHtml(key)}</kbd>`)}</div>`;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const clearArmed = state.armedClearAll;
|
|
534
|
+
const toolbar = `
|
|
535
|
+
<div class="pe-drafts-toolbar">
|
|
536
|
+
<button class="pe-clear-all-drafts ${clearArmed ? 'armed' : ''}" data-action="clear-all-drafts">
|
|
537
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
538
|
+
<polyline points="3 6 5 6 21 6"/>
|
|
539
|
+
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
|
|
540
|
+
</svg>
|
|
541
|
+
${clearArmed ? _d.clear_all_confirm : _d.clear_all}
|
|
542
|
+
</button>
|
|
543
|
+
</div>`;
|
|
544
|
+
|
|
545
|
+
return `${toolbar}<div class="pe-list">${state.drafts.map(d => renderDraftCard(d)).join('')}</div>`;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function renderSearchBar() {
|
|
549
|
+
const hasFilters = state.queryInfo?.filters?.length > 0;
|
|
550
|
+
|
|
551
|
+
return `
|
|
552
|
+
<div class="pe-search-area">
|
|
553
|
+
<div class="pe-search">
|
|
554
|
+
<svg class="pe-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
555
|
+
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
|
|
556
|
+
</svg>
|
|
557
|
+
<input
|
|
558
|
+
type="text"
|
|
559
|
+
class="pe-search-input"
|
|
560
|
+
placeholder="Search prompts... (try: long: or -exclude)"
|
|
561
|
+
value="${escapeHtml(state.searchQuery)}"
|
|
562
|
+
autofocus
|
|
563
|
+
/>
|
|
564
|
+
<label class="pe-project-filter">
|
|
565
|
+
<input type="checkbox"
|
|
566
|
+
class="pe-project-checkbox"
|
|
567
|
+
data-action="toggle-project-filter"
|
|
568
|
+
${state.currentProjectOnly ? 'checked' : ''}>
|
|
569
|
+
<span>${S.widgets.prompt_explorer.current_project_only}</span>
|
|
570
|
+
</label>
|
|
571
|
+
<button class="pe-hints-toggle ${state.showHints ? 'active' : ''}" data-tooltip="Search syntax help">
|
|
572
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
573
|
+
<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/>
|
|
574
|
+
<line x1="12" y1="17" x2="12.01" y2="17"/>
|
|
575
|
+
</svg>
|
|
576
|
+
</button>
|
|
577
|
+
${state.searchQuery ? `
|
|
578
|
+
<button class="pe-search-clear" data-tooltip="Clear">
|
|
579
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
580
|
+
<circle cx="12" cy="12" r="10"/><path d="m15 9-6 6M9 9l6 6"/>
|
|
581
|
+
</svg>
|
|
582
|
+
</button>
|
|
583
|
+
` : ''}
|
|
584
|
+
</div>
|
|
585
|
+
|
|
586
|
+
${!state.searchQuery ? `
|
|
587
|
+
<div class="pe-quick-filters">
|
|
588
|
+
${QUICK_FILTERS.map(f => `
|
|
589
|
+
<button class="pe-quick-filter" data-query="${escapeHtml(f.query)}">${f.label}</button>
|
|
590
|
+
`).join('')}
|
|
591
|
+
</div>
|
|
592
|
+
` : ''}
|
|
593
|
+
|
|
594
|
+
${hasFilters ? `
|
|
595
|
+
<div class="pe-active-filters">
|
|
596
|
+
${state.queryInfo.filters.map(f => `
|
|
597
|
+
<span class="pe-filter-chip" data-type="${f.type}">
|
|
598
|
+
${escapeHtml(f.label)}
|
|
599
|
+
<button class="pe-filter-remove" data-filter="${escapeHtml(f.label)}" data-tooltip="Remove">×</button>
|
|
600
|
+
</span>
|
|
601
|
+
`).join('')}
|
|
602
|
+
</div>
|
|
603
|
+
` : ''}
|
|
604
|
+
|
|
605
|
+
${state.showHints ? `
|
|
606
|
+
<div class="pe-hints">
|
|
607
|
+
<div class="pe-hints-title">Search Syntax</div>
|
|
608
|
+
<div class="pe-hints-grid">
|
|
609
|
+
${SEARCH_SYNTAX.map(h => `
|
|
610
|
+
<div class="pe-hint">
|
|
611
|
+
<code class="pe-hint-syntax">${escapeHtml(h.syntax)}</code>
|
|
612
|
+
<span class="pe-hint-desc">${h.desc}</span>
|
|
613
|
+
</div>
|
|
614
|
+
`).join('')}
|
|
615
|
+
</div>
|
|
616
|
+
</div>
|
|
617
|
+
` : ''}
|
|
618
|
+
</div>
|
|
619
|
+
`;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function renderStashRefs(refs) {
|
|
623
|
+
if (!refs || refs.length === 0) return '';
|
|
624
|
+
const items = refs.map(ref => {
|
|
625
|
+
const icon = ref.type === 'file'
|
|
626
|
+
? '<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>'
|
|
627
|
+
: '<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>';
|
|
628
|
+
const label = ref.type === 'file' && ref.filePath
|
|
629
|
+
? basename(ref.filePath)
|
|
630
|
+
: (ref.selectedText || '').substring(0, 80);
|
|
631
|
+
const note = ref.note ? `<span class="pe-stash-note">${escapeHtml(ref.note)}</span>` : '';
|
|
632
|
+
return `<div class="pe-stash-item">${icon} <span class="pe-stash-text">${escapeHtml(label)}${label.length >= 80 ? '...' : ''}</span>${note}</div>`;
|
|
633
|
+
}).join('');
|
|
634
|
+
return `<div class="pe-stash-refs"><div class="pe-stash-label"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> ${refs.length} stash ref${refs.length > 1 ? 's' : ''}</div>${items}</div>`;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function renderFullResponse(promptId) {
|
|
638
|
+
const entry = state.responseCache.get(promptId);
|
|
639
|
+
if (!entry || entry.state === 'loading') {
|
|
640
|
+
return `<div class="pe-card-full-response loading">
|
|
641
|
+
<div class="pe-spinner"></div>
|
|
642
|
+
<span>Loading response…</span>
|
|
643
|
+
</div>`;
|
|
644
|
+
}
|
|
645
|
+
if (entry.state === 'error') {
|
|
646
|
+
return `<div class="pe-card-full-response error">Failed to load response.</div>`;
|
|
647
|
+
}
|
|
648
|
+
if (!entry.text) {
|
|
649
|
+
return `<div class="pe-card-full-response empty">No response recorded.</div>`;
|
|
650
|
+
}
|
|
651
|
+
let rendered;
|
|
652
|
+
try {
|
|
653
|
+
rendered = getMarkdown().render(entry.text);
|
|
654
|
+
} catch {
|
|
655
|
+
rendered = `<pre>${escapeHtml(entry.text)}</pre>`;
|
|
656
|
+
}
|
|
657
|
+
return `<div class="pe-card-full-response">
|
|
658
|
+
<div class="pe-full-response-label">
|
|
659
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>
|
|
660
|
+
Response
|
|
661
|
+
</div>
|
|
662
|
+
<div class="pe-full-response-body markdown-content">${rendered}</div>
|
|
663
|
+
</div>`;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function renderPromptCard(prompt) {
|
|
667
|
+
const isExpanded = state.expandedId === prompt.id;
|
|
668
|
+
const projectName = getProjectName(prompt.project_path);
|
|
669
|
+
const sessionName = prompt.session_name || 'Unnamed';
|
|
670
|
+
const time = formatTimeOrDate(prompt.timestamp);
|
|
671
|
+
const isFavorite = prompt.is_favorite;
|
|
672
|
+
|
|
673
|
+
// Show more text by default - 300 chars collapsed, full when expanded
|
|
674
|
+
const displayText = isExpanded
|
|
675
|
+
? prompt.content
|
|
676
|
+
: (prompt.content.length > 300 ? prompt.content.substring(0, 300) + '...' : prompt.content);
|
|
677
|
+
|
|
678
|
+
const highlightedText = state.searchQuery
|
|
679
|
+
? highlightMatches(displayText, state.searchQuery)
|
|
680
|
+
: escapeHtml(displayText);
|
|
681
|
+
|
|
682
|
+
const needsExpand = prompt.content.length > 300 || !!prompt.response_preview;
|
|
683
|
+
|
|
684
|
+
return `
|
|
685
|
+
<div class="pe-card ${isExpanded ? 'expanded' : ''} ${isFavorite ? 'is-favorite' : ''}" data-id="${prompt.id}">
|
|
686
|
+
<div class="pe-card-header">
|
|
687
|
+
<button class="pe-btn-favorite ${isFavorite ? 'active' : ''}" data-action="favorite" data-tooltip="${isFavorite ? 'Remove from favorites' : 'Add to favorites'}">
|
|
688
|
+
<svg class="heart-outline" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
689
|
+
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
|
|
690
|
+
</svg>
|
|
691
|
+
<svg class="heart-filled" viewBox="0 0 24 24" fill="currentColor" stroke="none">
|
|
692
|
+
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
|
|
693
|
+
</svg>
|
|
694
|
+
</button>
|
|
695
|
+
<span class="pe-card-time">${time}</span>
|
|
696
|
+
<span class="pe-card-project">${escapeHtml(projectName)}</span>
|
|
697
|
+
<span class="pe-card-session" data-tooltip="${escapeHtml(sessionName)}">${escapeHtml(sessionName.length > 25 ? sessionName.substring(0, 25) + '...' : sessionName)}</span>
|
|
698
|
+
</div>
|
|
699
|
+
<div class="pe-card-content ${needsExpand && !isExpanded ? 'truncated' : ''}">${highlightedText}</div>
|
|
700
|
+
${prompt.stash_refs ? renderStashRefs(prompt.stash_refs) : ''}
|
|
701
|
+
${prompt.response_preview && !isExpanded ? `
|
|
702
|
+
<div class="pe-card-response">
|
|
703
|
+
<span class="pe-response-arrow">→</span>
|
|
704
|
+
<span class="pe-response-text">${escapeHtml(prompt.response_preview.substring(0, 100))}${prompt.response_preview.length > 100 ? '...' : ''}</span>
|
|
705
|
+
</div>
|
|
706
|
+
` : ''}
|
|
707
|
+
${isExpanded ? renderFullResponse(prompt.id) : ''}
|
|
708
|
+
<div class="pe-card-actions">
|
|
709
|
+
<button class="pe-btn pe-btn-copy" data-action="copy" data-tooltip="Copy to clipboard">
|
|
710
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
711
|
+
<rect x="9" y="9" width="13" height="13" rx="2"/>
|
|
712
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
|
713
|
+
</svg>
|
|
714
|
+
Copy
|
|
715
|
+
</button>
|
|
716
|
+
<button class="pe-btn pe-btn-insert" data-action="insert" data-tooltip="Paste into current input">
|
|
717
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
718
|
+
<path d="M12 5v14M5 12h14"/>
|
|
719
|
+
</svg>
|
|
720
|
+
Use
|
|
721
|
+
</button>
|
|
722
|
+
<button class="pe-btn pe-btn-run-new" data-action="run-new" data-tooltip="Open in new session for editing">
|
|
723
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
724
|
+
<path d="M5 12h14"/><path d="m12 5 7 7-7 7"/>
|
|
725
|
+
</svg>
|
|
726
|
+
Open New
|
|
727
|
+
</button>
|
|
728
|
+
<button class="pe-btn pe-btn-session" data-action="session" data-tooltip="Open original session">
|
|
729
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
730
|
+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
|
|
731
|
+
<polyline points="15 3 21 3 21 9"/>
|
|
732
|
+
<line x1="10" y1="14" x2="21" y2="3"/>
|
|
733
|
+
</svg>
|
|
734
|
+
Session
|
|
735
|
+
</button>
|
|
736
|
+
${needsExpand ? `
|
|
737
|
+
<button class="pe-btn pe-btn-expand" data-action="expand">
|
|
738
|
+
${isExpanded ? '▲ Less' : '▼ More'}
|
|
739
|
+
</button>
|
|
740
|
+
` : ''}
|
|
741
|
+
</div>
|
|
742
|
+
</div>
|
|
743
|
+
`;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function renderGroupedPrompts() {
|
|
747
|
+
if (state.loading) {
|
|
748
|
+
return `<div class="pe-loading">
|
|
749
|
+
<div class="pe-spinner"></div>
|
|
750
|
+
<span>Loading prompts...</span>
|
|
751
|
+
</div>`;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (state.error) {
|
|
755
|
+
return `<div class="pe-error">${escapeHtml(state.error)}</div>`;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (state.prompts.length === 0) {
|
|
759
|
+
return `<div class="pe-empty">
|
|
760
|
+
${state.searchQuery
|
|
761
|
+
? `No prompts matching "<strong>${escapeHtml(state.searchQuery)}</strong>"`
|
|
762
|
+
: 'No prompts yet. Start chatting with Claude!'}
|
|
763
|
+
</div>`;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// If searching, don't group - just show flat list
|
|
767
|
+
if (state.searchQuery) {
|
|
768
|
+
return `
|
|
769
|
+
<div class="pe-results-header">
|
|
770
|
+
Found ${state.total} prompt${state.total !== 1 ? 's' : ''}
|
|
771
|
+
</div>
|
|
772
|
+
<div class="pe-list">
|
|
773
|
+
${state.prompts.map(p => renderPromptCard(p)).join('')}
|
|
774
|
+
</div>
|
|
775
|
+
`;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// Group by time period
|
|
779
|
+
const groups = groupByTimePeriod(state.prompts);
|
|
780
|
+
let html = '';
|
|
781
|
+
|
|
782
|
+
for (const [period, prompts] of Object.entries(groups)) {
|
|
783
|
+
if (prompts.length === 0) continue;
|
|
784
|
+
|
|
785
|
+
html += `
|
|
786
|
+
<div class="pe-group">
|
|
787
|
+
<div class="pe-group-header">
|
|
788
|
+
<span class="pe-group-title">${period}</span>
|
|
789
|
+
<span class="pe-group-count">${prompts.length}</span>
|
|
790
|
+
</div>
|
|
791
|
+
<div class="pe-list">
|
|
792
|
+
${prompts.map(p => renderPromptCard(p)).join('')}
|
|
793
|
+
</div>
|
|
794
|
+
</div>
|
|
795
|
+
`;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
return html;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function renderContent() {
|
|
802
|
+
if (!state.container) return;
|
|
803
|
+
|
|
804
|
+
// Check if we already have the structure
|
|
805
|
+
let contentEl = state.container.querySelector('.pe-content');
|
|
806
|
+
|
|
807
|
+
if (!contentEl) {
|
|
808
|
+
// First render - create full structure
|
|
809
|
+
state.container.innerHTML = `
|
|
810
|
+
${renderViewTabs()}
|
|
811
|
+
${renderSearchBar()}
|
|
812
|
+
<div class="pe-content">
|
|
813
|
+
${state.view === 'drafts' ? renderDraftsList() : renderGroupedPrompts()}
|
|
814
|
+
</div>
|
|
815
|
+
`;
|
|
816
|
+
const searchArea = state.container.querySelector('.pe-search-area');
|
|
817
|
+
if (searchArea && state.view === 'drafts') searchArea.style.display = 'none';
|
|
818
|
+
attachTabListeners();
|
|
819
|
+
attachSearchListeners();
|
|
820
|
+
} else {
|
|
821
|
+
// Subsequent renders - only update results, preserve search input
|
|
822
|
+
contentEl.innerHTML = state.view === 'drafts' ? renderDraftsList() : renderGroupedPrompts();
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
if (state.view === 'drafts') {
|
|
826
|
+
attachDraftListeners();
|
|
827
|
+
} else {
|
|
828
|
+
attachCardListeners();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function attachTabListeners() {
|
|
833
|
+
state.container?.querySelectorAll('.pe-tab').forEach(btn => {
|
|
834
|
+
btn.addEventListener('click', () => switchView(btn.dataset.view));
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
function attachDraftListeners() {
|
|
839
|
+
if (!state.container) return;
|
|
840
|
+
|
|
841
|
+
const clearAllBtn = state.container.querySelector('.pe-clear-all-drafts');
|
|
842
|
+
if (clearAllBtn) {
|
|
843
|
+
clearAllBtn.addEventListener('click', (e) => {
|
|
844
|
+
e.stopPropagation();
|
|
845
|
+
clearAllDrafts();
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
state.container.querySelectorAll('.pe-draft-card').forEach(card => {
|
|
850
|
+
const draft = state.drafts.find(d => d.id === card.dataset.id);
|
|
851
|
+
if (!draft) return;
|
|
852
|
+
|
|
853
|
+
// Double-click to load into input (same convention as history cards)
|
|
854
|
+
card.addEventListener('dblclick', (e) => {
|
|
855
|
+
if (!e.target.closest('.pe-btn')) insertDraft(draft);
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
card.querySelectorAll('.pe-btn').forEach(btn => {
|
|
859
|
+
btn.addEventListener('click', (e) => {
|
|
860
|
+
e.stopPropagation();
|
|
861
|
+
switch (btn.dataset.action) {
|
|
862
|
+
case 'use-draft': insertDraft(draft); break;
|
|
863
|
+
case 'copy-draft': copyDraft(draft, btn); break;
|
|
864
|
+
case 'delete-draft': deleteDraft(draft); break;
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function attachSearchListeners() {
|
|
872
|
+
if (!state.container) return;
|
|
873
|
+
|
|
874
|
+
const searchInput = state.container.querySelector('.pe-search-input');
|
|
875
|
+
if (searchInput) {
|
|
876
|
+
searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value));
|
|
877
|
+
searchInput.addEventListener('keydown', (e) => {
|
|
878
|
+
if (e.key === 'Escape') {
|
|
879
|
+
if (state.searchQuery) {
|
|
880
|
+
state.searchQuery = '';
|
|
881
|
+
searchInput.value = '';
|
|
882
|
+
state.queryInfo = null;
|
|
883
|
+
loadPrompts();
|
|
884
|
+
} else {
|
|
885
|
+
WidgetManager.close('prompt-explorer');
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
setTimeout(() => searchInput.focus(), 100);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// Clear button
|
|
893
|
+
const clearBtn = state.container.querySelector('.pe-search-clear');
|
|
894
|
+
clearBtn?.addEventListener('click', () => {
|
|
895
|
+
state.searchQuery = '';
|
|
896
|
+
state.queryInfo = null;
|
|
897
|
+
if (searchInput) searchInput.value = '';
|
|
898
|
+
loadPrompts();
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
// Hints toggle button
|
|
902
|
+
state.container.querySelector('.pe-hints-toggle')?.addEventListener('click', () => {
|
|
903
|
+
state.showHints = !state.showHints;
|
|
904
|
+
// Re-render search area only
|
|
905
|
+
const searchArea = state.container.querySelector('.pe-search-area');
|
|
906
|
+
if (searchArea) {
|
|
907
|
+
searchArea.outerHTML = renderSearchBar();
|
|
908
|
+
attachSearchListeners(); // Re-attach after re-render
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
// Project filter toggle
|
|
913
|
+
state.container.querySelector('.pe-project-checkbox')?.addEventListener('change', (e) => {
|
|
914
|
+
state.currentProjectOnly = e.target.checked;
|
|
915
|
+
localStorage.setItem('pe-current-project-only', state.currentProjectOnly);
|
|
916
|
+
loadPrompts();
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
// Quick filter buttons
|
|
920
|
+
state.container.querySelectorAll('.pe-quick-filter').forEach(btn => {
|
|
921
|
+
btn.addEventListener('click', () => {
|
|
922
|
+
const query = btn.dataset.query;
|
|
923
|
+
state.searchQuery = query;
|
|
924
|
+
if (searchInput) searchInput.value = query;
|
|
925
|
+
loadPrompts();
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
// Filter chip removal
|
|
930
|
+
state.container.querySelectorAll('.pe-filter-remove').forEach(btn => {
|
|
931
|
+
btn.addEventListener('click', (e) => {
|
|
932
|
+
e.stopPropagation();
|
|
933
|
+
const filterLabel = btn.dataset.filter;
|
|
934
|
+
// Remove this filter from the query
|
|
935
|
+
removeFilterFromQuery(filterLabel);
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
// Clicking a syntax hint inserts it into search
|
|
940
|
+
state.container.querySelectorAll('.pe-hint-syntax').forEach(code => {
|
|
941
|
+
code.addEventListener('click', () => {
|
|
942
|
+
const syntax = code.textContent;
|
|
943
|
+
// Append to current query
|
|
944
|
+
const current = state.searchQuery ? state.searchQuery + ' ' : '';
|
|
945
|
+
state.searchQuery = current + syntax;
|
|
946
|
+
if (searchInput) {
|
|
947
|
+
searchInput.value = state.searchQuery;
|
|
948
|
+
searchInput.focus();
|
|
949
|
+
}
|
|
950
|
+
state.showHints = false;
|
|
951
|
+
loadPrompts();
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* Remove a specific filter from the query string
|
|
958
|
+
*/
|
|
959
|
+
function removeFilterFromQuery(filterLabel) {
|
|
960
|
+
if (!state.searchQuery) return;
|
|
961
|
+
|
|
962
|
+
let query = state.searchQuery;
|
|
963
|
+
|
|
964
|
+
// Handle quoted phrases
|
|
965
|
+
if (filterLabel.startsWith('"') && filterLabel.endsWith('"')) {
|
|
966
|
+
query = query.replace(filterLabel, '');
|
|
967
|
+
}
|
|
968
|
+
// Handle exclusions
|
|
969
|
+
else if (filterLabel.startsWith('-')) {
|
|
970
|
+
query = query.replace(filterLabel, '');
|
|
971
|
+
}
|
|
972
|
+
// Handle field filters (project:, in:, after:, etc.)
|
|
973
|
+
else if (filterLabel.includes(':')) {
|
|
974
|
+
const pattern = new RegExp(filterLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\s*', 'gi');
|
|
975
|
+
query = query.replace(pattern, '');
|
|
976
|
+
}
|
|
977
|
+
// Handle special keywords (long:, short:, today:, week:)
|
|
978
|
+
else if (['long (>500 chars)', 'short (<100 chars)', 'today', 'yesterday', 'this week'].includes(filterLabel.toLowerCase())) {
|
|
979
|
+
const keywordMap = {
|
|
980
|
+
'long (>500 chars)': 'long:',
|
|
981
|
+
'short (<100 chars)': 'short:',
|
|
982
|
+
'today': 'today:',
|
|
983
|
+
'yesterday': 'yesterday:',
|
|
984
|
+
'this week': 'week:',
|
|
985
|
+
};
|
|
986
|
+
const keyword = keywordMap[filterLabel.toLowerCase()] || filterLabel;
|
|
987
|
+
query = query.replace(new RegExp(keyword + '\\s*', 'gi'), '');
|
|
988
|
+
}
|
|
989
|
+
// Handle regular terms
|
|
990
|
+
else {
|
|
991
|
+
query = query.replace(new RegExp('\\b' + filterLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\b\\s*', 'gi'), '');
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// Clean up extra spaces
|
|
995
|
+
query = query.replace(/\s+/g, ' ').trim();
|
|
996
|
+
|
|
997
|
+
state.searchQuery = query;
|
|
998
|
+
const searchInput = state.container?.querySelector('.pe-search-input');
|
|
999
|
+
if (searchInput) searchInput.value = query;
|
|
1000
|
+
loadPrompts();
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
async function toggleFavorite(prompt, btn) {
|
|
1004
|
+
const card = btn.closest('.pe-card');
|
|
1005
|
+
const wasActive = btn.classList.contains('active');
|
|
1006
|
+
|
|
1007
|
+
// Optimistic UI update
|
|
1008
|
+
btn.classList.toggle('active');
|
|
1009
|
+
card?.classList.toggle('is-favorite');
|
|
1010
|
+
|
|
1011
|
+
// Call API
|
|
1012
|
+
const newState = await PromptFavorites.toggleFavorite(prompt.id, prompt.content);
|
|
1013
|
+
|
|
1014
|
+
// Update local state
|
|
1015
|
+
prompt.is_favorite = newState;
|
|
1016
|
+
|
|
1017
|
+
// Revert UI if API failed (state mismatch)
|
|
1018
|
+
if (newState === wasActive) {
|
|
1019
|
+
btn.classList.toggle('active');
|
|
1020
|
+
card?.classList.toggle('is-favorite');
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function attachCardListeners() {
|
|
1025
|
+
if (!state.container) return;
|
|
1026
|
+
|
|
1027
|
+
// Card actions
|
|
1028
|
+
state.container.querySelectorAll('.pe-card').forEach(card => {
|
|
1029
|
+
const promptId = card.dataset.id;
|
|
1030
|
+
const prompt = state.prompts.find(p => p.id === promptId);
|
|
1031
|
+
if (!prompt) return;
|
|
1032
|
+
|
|
1033
|
+
// Double-click to insert
|
|
1034
|
+
card.addEventListener('dblclick', (e) => {
|
|
1035
|
+
if (!e.target.closest('.pe-btn') && !e.target.closest('.pe-btn-favorite')) {
|
|
1036
|
+
insertPrompt(prompt);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
// Favorite button (header)
|
|
1041
|
+
const favBtn = card.querySelector('.pe-btn-favorite');
|
|
1042
|
+
if (favBtn) {
|
|
1043
|
+
favBtn.addEventListener('click', (e) => {
|
|
1044
|
+
e.stopPropagation();
|
|
1045
|
+
toggleFavorite(prompt, favBtn);
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Action buttons
|
|
1050
|
+
card.querySelectorAll('.pe-btn').forEach(btn => {
|
|
1051
|
+
btn.addEventListener('click', (e) => {
|
|
1052
|
+
e.stopPropagation();
|
|
1053
|
+
const action = btn.dataset.action;
|
|
1054
|
+
switch (action) {
|
|
1055
|
+
case 'copy': copyPrompt(prompt, btn); break;
|
|
1056
|
+
case 'insert': insertPrompt(prompt); break;
|
|
1057
|
+
case 'run-new': runInNewSession(prompt); break;
|
|
1058
|
+
case 'session': openSession(prompt); break;
|
|
1059
|
+
case 'expand': toggleExpand(promptId); break;
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1067
|
+
// WIDGET REGISTRATION
|
|
1068
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1069
|
+
|
|
1070
|
+
export function registerPromptExplorerWidget() {
|
|
1071
|
+
WidgetManager.register('prompt-explorer', {
|
|
1072
|
+
title: S.widgets.titles.prompt_history,
|
|
1073
|
+
icon: 'clock',
|
|
1074
|
+
type: 'floating',
|
|
1075
|
+
scope: 'global',
|
|
1076
|
+
defaultWidth: 650,
|
|
1077
|
+
defaultHeight: 550,
|
|
1078
|
+
|
|
1079
|
+
headerActions: [
|
|
1080
|
+
{
|
|
1081
|
+
icon: 'refresh',
|
|
1082
|
+
title: S.widgets.header_actions.refresh,
|
|
1083
|
+
onClick: () => state.view === 'drafts' ? loadDrafts() : loadPrompts()
|
|
1084
|
+
}
|
|
1085
|
+
],
|
|
1086
|
+
|
|
1087
|
+
render(container, ctx) {
|
|
1088
|
+
state.container = container;
|
|
1089
|
+
container.classList.add('prompt-explorer-widget');
|
|
1090
|
+
if (state.view === 'drafts') loadDrafts(); else loadPrompts();
|
|
1091
|
+
},
|
|
1092
|
+
|
|
1093
|
+
onOpen() {
|
|
1094
|
+
state.expandedId = null;
|
|
1095
|
+
state.armedDeleteId = null;
|
|
1096
|
+
state.armedClearAll = false;
|
|
1097
|
+
if (state.view === 'drafts') loadDrafts(); else loadPrompts();
|
|
1098
|
+
// Focus search input after render (history view only)
|
|
1099
|
+
requestAnimationFrame(() => {
|
|
1100
|
+
if (state.view !== 'drafts') {
|
|
1101
|
+
state.container?.querySelector('.pe-search-input')?.focus();
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
},
|
|
1105
|
+
|
|
1106
|
+
onClose() {
|
|
1107
|
+
// Focus chat input when closing
|
|
1108
|
+
document.querySelector('#message-input')?.focus();
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
debug.log('[PromptExplorer] Widget registered');
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
export const PromptExplorerWidget = {
|
|
1116
|
+
open: () => WidgetManager.open('prompt-explorer'),
|
|
1117
|
+
close: () => WidgetManager.close('prompt-explorer'),
|
|
1118
|
+
toggle: () => WidgetManager.toggle('prompt-explorer'),
|
|
1119
|
+
};
|