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,879 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Welcome Search - Shadow Git powered session discovery.
|
|
3
|
+
|
|
4
|
+
Replaces the dumb AI search with intelligent queries against shadow git commit data.
|
|
5
|
+
Parses natural language queries and structured queries into git commands.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
searcher = WelcomeSearcher(project_paths)
|
|
9
|
+
results = await searcher.search("auth bug fix from last week")
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import json
|
|
14
|
+
import logging
|
|
15
|
+
import re
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Optional
|
|
20
|
+
|
|
21
|
+
from painapple_code.paths import (
|
|
22
|
+
DATA_HOME,
|
|
23
|
+
get_project_display_name,
|
|
24
|
+
get_shadow_git_dir,
|
|
25
|
+
get_sessions_dir,
|
|
26
|
+
list_projects,
|
|
27
|
+
)
|
|
28
|
+
from painapple_code.shadow_git import parse_yaml_frontmatter
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger("painapple-code.welcome-search")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
34
|
+
# Query Parsing
|
|
35
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class ParsedQuery:
|
|
39
|
+
"""Structured representation of a search query."""
|
|
40
|
+
raw: str
|
|
41
|
+
keywords: list[str] = field(default_factory=list)
|
|
42
|
+
tags: list[str] = field(default_factory=list)
|
|
43
|
+
files: list[str] = field(default_factory=list)
|
|
44
|
+
code_pattern: Optional[str] = None
|
|
45
|
+
project_filter: Optional[str] = None
|
|
46
|
+
time_filter: Optional[str] = None # git --since format
|
|
47
|
+
time_until: Optional[str] = None # git --until format
|
|
48
|
+
model_filter: Optional[str] = None
|
|
49
|
+
intent: str = "search" # search or task
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# Time expressions to git date format
|
|
53
|
+
TIME_EXPRESSIONS = {
|
|
54
|
+
"today": ("today", None),
|
|
55
|
+
"yesterday": ("yesterday", "today"),
|
|
56
|
+
"this week": ("1 week ago", None),
|
|
57
|
+
"last week": ("2 weeks ago", "1 week ago"),
|
|
58
|
+
"this month": ("1 month ago", None),
|
|
59
|
+
"last month": ("2 months ago", "1 month ago"),
|
|
60
|
+
"recently": ("3 days ago", None),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def parse_query(query: str) -> ParsedQuery:
|
|
65
|
+
"""
|
|
66
|
+
Parse a natural language or structured query.
|
|
67
|
+
|
|
68
|
+
Supports:
|
|
69
|
+
- Natural: "that session where I fixed auth"
|
|
70
|
+
- Tags: "#bugfix #api"
|
|
71
|
+
- Files: "files:server.py"
|
|
72
|
+
- Code: "code:handleAuth"
|
|
73
|
+
- Time: "yesterday", "last week"
|
|
74
|
+
- Project: "in:ai-sysop"
|
|
75
|
+
- Model: "with:opus"
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
query: Raw query string
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
ParsedQuery with extracted components
|
|
82
|
+
"""
|
|
83
|
+
parsed = ParsedQuery(raw=query)
|
|
84
|
+
remaining = query.lower()
|
|
85
|
+
|
|
86
|
+
# Detect task intent (user wants to do something, not just search)
|
|
87
|
+
task_words = ["help me", "i want to", "let's", "add", "fix", "implement", "create"]
|
|
88
|
+
|
|
89
|
+
if any(w in remaining for w in task_words):
|
|
90
|
+
parsed.intent = "task"
|
|
91
|
+
|
|
92
|
+
# Extract tags (#bugfix, #auth, etc.)
|
|
93
|
+
tag_pattern = r'#(\w+)'
|
|
94
|
+
tags = re.findall(tag_pattern, query)
|
|
95
|
+
parsed.tags = [f"#{t}" for t in tags]
|
|
96
|
+
remaining = re.sub(tag_pattern, '', remaining)
|
|
97
|
+
|
|
98
|
+
# Extract file filters (files:path or file:path)
|
|
99
|
+
file_pattern = r'files?:(\S+)'
|
|
100
|
+
files = re.findall(file_pattern, query, re.IGNORECASE)
|
|
101
|
+
parsed.files = files
|
|
102
|
+
remaining = re.sub(file_pattern, '', remaining, flags=re.IGNORECASE)
|
|
103
|
+
|
|
104
|
+
# Extract code pattern (code:pattern)
|
|
105
|
+
code_pattern = r'code:(\S+)'
|
|
106
|
+
code_match = re.search(code_pattern, query, re.IGNORECASE)
|
|
107
|
+
if code_match:
|
|
108
|
+
parsed.code_pattern = code_match.group(1)
|
|
109
|
+
remaining = re.sub(code_pattern, '', remaining, flags=re.IGNORECASE)
|
|
110
|
+
|
|
111
|
+
# Extract project filter (in:project)
|
|
112
|
+
project_pattern = r'in:(\S+)'
|
|
113
|
+
project_match = re.search(project_pattern, query, re.IGNORECASE)
|
|
114
|
+
if project_match:
|
|
115
|
+
parsed.project_filter = project_match.group(1)
|
|
116
|
+
remaining = re.sub(project_pattern, '', remaining, flags=re.IGNORECASE)
|
|
117
|
+
|
|
118
|
+
# Extract model filter (with:opus, with:haiku)
|
|
119
|
+
model_pattern = r'with:(opus|sonnet|haiku)'
|
|
120
|
+
model_match = re.search(model_pattern, query, re.IGNORECASE)
|
|
121
|
+
if model_match:
|
|
122
|
+
parsed.model_filter = model_match.group(1).lower()
|
|
123
|
+
remaining = re.sub(model_pattern, '', remaining, flags=re.IGNORECASE)
|
|
124
|
+
|
|
125
|
+
# Extract time expressions
|
|
126
|
+
for expr, (since, until) in TIME_EXPRESSIONS.items():
|
|
127
|
+
if expr in remaining:
|
|
128
|
+
parsed.time_filter = since
|
|
129
|
+
parsed.time_until = until
|
|
130
|
+
remaining = remaining.replace(expr, '')
|
|
131
|
+
break
|
|
132
|
+
|
|
133
|
+
# Also check for "from last week", "since yesterday" patterns
|
|
134
|
+
if "last week" in remaining:
|
|
135
|
+
parsed.time_filter = "1 week ago"
|
|
136
|
+
remaining = remaining.replace("last week", "")
|
|
137
|
+
elif "last month" in remaining:
|
|
138
|
+
parsed.time_filter = "1 month ago"
|
|
139
|
+
remaining = remaining.replace("last month", "")
|
|
140
|
+
|
|
141
|
+
# Clean up common filler words
|
|
142
|
+
filler_words = [
|
|
143
|
+
"that", "session", "where", "i", "the", "a", "an", "on", "in",
|
|
144
|
+
"from", "with", "was", "did", "worked", "fixed", "about", "for",
|
|
145
|
+
"show", "me", "find", "search"
|
|
146
|
+
]
|
|
147
|
+
words = remaining.split()
|
|
148
|
+
keywords = [w.strip() for w in words if w.strip() and w not in filler_words]
|
|
149
|
+
|
|
150
|
+
# Remove punctuation from keywords
|
|
151
|
+
keywords = [re.sub(r'[^\w]', '', k) for k in keywords]
|
|
152
|
+
keywords = [k for k in keywords if k and len(k) > 1]
|
|
153
|
+
|
|
154
|
+
parsed.keywords = keywords
|
|
155
|
+
|
|
156
|
+
return parsed
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
160
|
+
# Session Result
|
|
161
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
162
|
+
|
|
163
|
+
@dataclass
|
|
164
|
+
class SessionResult:
|
|
165
|
+
"""Enriched session search result."""
|
|
166
|
+
session_id: str
|
|
167
|
+
project: str
|
|
168
|
+
project_path: str
|
|
169
|
+
|
|
170
|
+
# From meta.json
|
|
171
|
+
name: Optional[str] = None
|
|
172
|
+
created_at: Optional[str] = None
|
|
173
|
+
last_activity: Optional[str] = None
|
|
174
|
+
message_count: int = 0
|
|
175
|
+
total_cost: float = 0.0
|
|
176
|
+
|
|
177
|
+
# Fork relationship
|
|
178
|
+
forked_from: Optional[dict] = None # {store_id, provider_session_id}
|
|
179
|
+
is_comment_thread: bool = False
|
|
180
|
+
|
|
181
|
+
# From shadow git commits
|
|
182
|
+
summary: Optional[str] = None
|
|
183
|
+
tags: list[str] = field(default_factory=list)
|
|
184
|
+
files_changed: list[str] = field(default_factory=list)
|
|
185
|
+
journey_snippet: Optional[str] = None
|
|
186
|
+
key_decisions: list[str] = field(default_factory=list)
|
|
187
|
+
|
|
188
|
+
# Shadow stats
|
|
189
|
+
turn_count: int = 0
|
|
190
|
+
tools_summary: dict = field(default_factory=dict)
|
|
191
|
+
|
|
192
|
+
# Fallback when no summary yet
|
|
193
|
+
first_prompt: Optional[str] = None
|
|
194
|
+
|
|
195
|
+
# Search relevance
|
|
196
|
+
match_score: float = 0.0
|
|
197
|
+
match_reasons: list[str] = field(default_factory=list)
|
|
198
|
+
|
|
199
|
+
def to_dict(self) -> dict:
|
|
200
|
+
return {
|
|
201
|
+
"session_id": self.session_id,
|
|
202
|
+
"project": self.project,
|
|
203
|
+
"project_path": self.project_path,
|
|
204
|
+
"name": self.name,
|
|
205
|
+
"created_at": self.created_at,
|
|
206
|
+
"last_activity": self.last_activity,
|
|
207
|
+
"message_count": self.message_count,
|
|
208
|
+
"total_cost": self.total_cost,
|
|
209
|
+
"forked_from": self.forked_from,
|
|
210
|
+
"is_comment_thread": self.is_comment_thread,
|
|
211
|
+
"summary": self.summary,
|
|
212
|
+
"tags": self.tags,
|
|
213
|
+
"files_changed": self.files_changed[:10], # Limit
|
|
214
|
+
"journey_snippet": self.journey_snippet,
|
|
215
|
+
"key_decisions": self.key_decisions[:3],
|
|
216
|
+
"turn_count": self.turn_count,
|
|
217
|
+
"tools_summary": self.tools_summary,
|
|
218
|
+
"first_prompt": self.first_prompt,
|
|
219
|
+
"match_score": self.match_score,
|
|
220
|
+
"match_reasons": self.match_reasons,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
225
|
+
# Welcome Searcher
|
|
226
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
227
|
+
|
|
228
|
+
class WelcomeSearcher:
|
|
229
|
+
"""
|
|
230
|
+
Smart session search using shadow git archaeology.
|
|
231
|
+
|
|
232
|
+
Replaces the dumb AI search that sent summaries to Claude.
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
def __init__(self):
|
|
236
|
+
"""Initialize searcher."""
|
|
237
|
+
self.data_dir = DATA_HOME
|
|
238
|
+
|
|
239
|
+
@staticmethod
|
|
240
|
+
def _read_first_prompt(sessions_dir: Path, session_id: str) -> Optional[str]:
|
|
241
|
+
"""Read the first user prompt from messages.jsonl (truncated to 200 chars)."""
|
|
242
|
+
messages_file = sessions_dir / session_id / "messages.jsonl"
|
|
243
|
+
if not messages_file.exists():
|
|
244
|
+
return None
|
|
245
|
+
try:
|
|
246
|
+
with open(messages_file, encoding="utf-8") as f:
|
|
247
|
+
for line in f:
|
|
248
|
+
line = line.strip()
|
|
249
|
+
if not line:
|
|
250
|
+
continue
|
|
251
|
+
msg = json.loads(line)
|
|
252
|
+
if msg.get("role") == "user":
|
|
253
|
+
content = msg.get("content", "")
|
|
254
|
+
if isinstance(content, str) and content:
|
|
255
|
+
return content[:200]
|
|
256
|
+
break
|
|
257
|
+
except Exception:
|
|
258
|
+
pass
|
|
259
|
+
return None
|
|
260
|
+
|
|
261
|
+
async def search(
|
|
262
|
+
self,
|
|
263
|
+
query: str,
|
|
264
|
+
limit: int = 10
|
|
265
|
+
) -> dict:
|
|
266
|
+
"""
|
|
267
|
+
Search sessions using shadow git data.
|
|
268
|
+
|
|
269
|
+
Args:
|
|
270
|
+
query: Natural language or structured query
|
|
271
|
+
limit: Maximum results to return
|
|
272
|
+
|
|
273
|
+
Returns:
|
|
274
|
+
Dict with results, parsed query, suggestions
|
|
275
|
+
"""
|
|
276
|
+
# Parse the query
|
|
277
|
+
parsed = parse_query(query)
|
|
278
|
+
|
|
279
|
+
logger.info(f"Searching: {query}")
|
|
280
|
+
logger.debug(f"Parsed: keywords={parsed.keywords}, tags={parsed.tags}, "
|
|
281
|
+
f"time={parsed.time_filter}, files={parsed.files}")
|
|
282
|
+
|
|
283
|
+
# Get all projects
|
|
284
|
+
projects = list_projects()
|
|
285
|
+
|
|
286
|
+
if parsed.project_filter:
|
|
287
|
+
# Filter to matching project
|
|
288
|
+
projects = [
|
|
289
|
+
p for p in projects
|
|
290
|
+
if parsed.project_filter.lower() in p["path"].lower()
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
# Search each project's shadow git
|
|
294
|
+
all_results = []
|
|
295
|
+
|
|
296
|
+
for project in projects:
|
|
297
|
+
project_path = project["path"]
|
|
298
|
+
project_hash = project["hash"]
|
|
299
|
+
|
|
300
|
+
try:
|
|
301
|
+
results = await self._search_project(
|
|
302
|
+
project_path, project_hash, parsed
|
|
303
|
+
)
|
|
304
|
+
all_results.extend(results)
|
|
305
|
+
except Exception as e:
|
|
306
|
+
logger.warning(f"Error searching {project_path}: {e}")
|
|
307
|
+
|
|
308
|
+
# Rank results
|
|
309
|
+
ranked = self._rank_results(all_results, parsed)
|
|
310
|
+
|
|
311
|
+
# Limit
|
|
312
|
+
results = ranked[:limit]
|
|
313
|
+
|
|
314
|
+
# Generate suggestions
|
|
315
|
+
suggestions = self._generate_suggestions(parsed, results)
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
"query": query,
|
|
319
|
+
"parsed": {
|
|
320
|
+
"keywords": parsed.keywords,
|
|
321
|
+
"tags": parsed.tags,
|
|
322
|
+
"files": parsed.files,
|
|
323
|
+
"code_pattern": parsed.code_pattern,
|
|
324
|
+
"time_filter": parsed.time_filter,
|
|
325
|
+
"project_filter": parsed.project_filter,
|
|
326
|
+
"intent": parsed.intent,
|
|
327
|
+
},
|
|
328
|
+
"results": [r.to_dict() for r in results],
|
|
329
|
+
"total_found": len(all_results),
|
|
330
|
+
"suggestions": suggestions,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async def _search_project(
|
|
334
|
+
self,
|
|
335
|
+
project_path: str,
|
|
336
|
+
project_hash: str,
|
|
337
|
+
parsed: ParsedQuery
|
|
338
|
+
) -> list[SessionResult]:
|
|
339
|
+
"""Search a single project's shadow git."""
|
|
340
|
+
|
|
341
|
+
shadow_dir = get_shadow_git_dir(project_path)
|
|
342
|
+
sessions_dir = get_sessions_dir(project_path)
|
|
343
|
+
|
|
344
|
+
if not shadow_dir.exists():
|
|
345
|
+
# No shadow git - fall back to session metadata only
|
|
346
|
+
return await self._search_sessions_only(
|
|
347
|
+
project_path, project_hash, sessions_dir, parsed
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
# Build git log command
|
|
351
|
+
cmd = [
|
|
352
|
+
"git",
|
|
353
|
+
f"--git-dir={shadow_dir}",
|
|
354
|
+
f"--work-tree={project_path}",
|
|
355
|
+
"log",
|
|
356
|
+
"--format=%H|%s|%ai|%B§END§",
|
|
357
|
+
"-n", "200", # Search last 200 commits
|
|
358
|
+
]
|
|
359
|
+
|
|
360
|
+
# Add grep filters for tags
|
|
361
|
+
if parsed.tags:
|
|
362
|
+
for tag in parsed.tags:
|
|
363
|
+
cmd.extend(["--grep", tag])
|
|
364
|
+
cmd.append("--all-match")
|
|
365
|
+
|
|
366
|
+
# Add grep filters for keywords (match any)
|
|
367
|
+
if parsed.keywords:
|
|
368
|
+
for kw in parsed.keywords:
|
|
369
|
+
cmd.extend(["--grep", kw])
|
|
370
|
+
|
|
371
|
+
# Add time filters
|
|
372
|
+
if parsed.time_filter:
|
|
373
|
+
cmd.extend(["--since", parsed.time_filter])
|
|
374
|
+
if parsed.time_until:
|
|
375
|
+
cmd.extend(["--until", parsed.time_until])
|
|
376
|
+
|
|
377
|
+
# Add file filters
|
|
378
|
+
if parsed.files:
|
|
379
|
+
cmd.append("--")
|
|
380
|
+
for f in parsed.files:
|
|
381
|
+
cmd.append(f"*{f}*")
|
|
382
|
+
|
|
383
|
+
try:
|
|
384
|
+
proc = await asyncio.create_subprocess_exec(
|
|
385
|
+
*cmd,
|
|
386
|
+
stdout=asyncio.subprocess.PIPE,
|
|
387
|
+
stderr=asyncio.subprocess.PIPE,
|
|
388
|
+
cwd=project_path
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
stdout, stderr = await proc.communicate()
|
|
392
|
+
|
|
393
|
+
if proc.returncode != 0:
|
|
394
|
+
logger.debug(f"Git log returned {proc.returncode}: {stderr.decode()[:100]}")
|
|
395
|
+
return []
|
|
396
|
+
|
|
397
|
+
output = stdout.decode()
|
|
398
|
+
|
|
399
|
+
except Exception as e:
|
|
400
|
+
logger.warning(f"Git command failed: {e}")
|
|
401
|
+
return []
|
|
402
|
+
|
|
403
|
+
# Parse commits and group by session
|
|
404
|
+
shadow_results = self._parse_commits_to_sessions(
|
|
405
|
+
output, project_path, project_hash, sessions_dir, parsed
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
# Also include sessions from the session store that have NO shadow git
|
|
409
|
+
# commits yet (e.g., fresh sessions before first turn completes).
|
|
410
|
+
# Only do this for browse queries (no keywords/tags/files) to avoid
|
|
411
|
+
# polluting search results with empty sessions.
|
|
412
|
+
if not parsed.keywords and not parsed.tags and not parsed.files:
|
|
413
|
+
shadow_session_ids = {r.session_id for r in shadow_results}
|
|
414
|
+
orphan_results = await self._search_sessions_only(
|
|
415
|
+
project_path, project_hash, sessions_dir, parsed
|
|
416
|
+
)
|
|
417
|
+
for orphan in orphan_results:
|
|
418
|
+
if orphan.session_id not in shadow_session_ids:
|
|
419
|
+
shadow_results.append(orphan)
|
|
420
|
+
|
|
421
|
+
return shadow_results
|
|
422
|
+
|
|
423
|
+
async def _search_sessions_only(
|
|
424
|
+
self,
|
|
425
|
+
project_path: str,
|
|
426
|
+
project_hash: str,
|
|
427
|
+
sessions_dir: Path,
|
|
428
|
+
parsed: ParsedQuery
|
|
429
|
+
) -> list[SessionResult]:
|
|
430
|
+
"""Fallback search using only session metadata (no shadow git)."""
|
|
431
|
+
|
|
432
|
+
results = []
|
|
433
|
+
|
|
434
|
+
if not sessions_dir.exists():
|
|
435
|
+
return results
|
|
436
|
+
|
|
437
|
+
project_name = get_project_display_name(project_path)
|
|
438
|
+
|
|
439
|
+
for session_dir in sessions_dir.iterdir():
|
|
440
|
+
if not session_dir.is_dir():
|
|
441
|
+
continue
|
|
442
|
+
|
|
443
|
+
meta_file = session_dir / "meta.json"
|
|
444
|
+
if not meta_file.exists():
|
|
445
|
+
continue
|
|
446
|
+
|
|
447
|
+
try:
|
|
448
|
+
meta = json.loads(meta_file.read_text(encoding="utf-8"))
|
|
449
|
+
|
|
450
|
+
# Check if matches query
|
|
451
|
+
name = meta.get("name", "")
|
|
452
|
+
|
|
453
|
+
score = 0.0
|
|
454
|
+
reasons = []
|
|
455
|
+
|
|
456
|
+
for kw in parsed.keywords:
|
|
457
|
+
if kw.lower() in name.lower():
|
|
458
|
+
score += 0.5
|
|
459
|
+
reasons.append(f"Name contains '{kw}'")
|
|
460
|
+
|
|
461
|
+
if not parsed.keywords or score > 0:
|
|
462
|
+
first_prompt = self._read_first_prompt(sessions_dir, session_dir.name)
|
|
463
|
+
result = SessionResult(
|
|
464
|
+
session_id=session_dir.name,
|
|
465
|
+
project=project_name,
|
|
466
|
+
project_path=project_path,
|
|
467
|
+
name=name,
|
|
468
|
+
created_at=meta.get("created_at"),
|
|
469
|
+
last_activity=meta.get("last_activity"),
|
|
470
|
+
message_count=meta.get("message_count", 0),
|
|
471
|
+
total_cost=meta.get("total_cost", 0.0),
|
|
472
|
+
forked_from=meta.get("forked_from"),
|
|
473
|
+
is_comment_thread=meta.get("isCommentThread", False),
|
|
474
|
+
first_prompt=first_prompt,
|
|
475
|
+
match_score=score,
|
|
476
|
+
match_reasons=reasons,
|
|
477
|
+
)
|
|
478
|
+
results.append(result)
|
|
479
|
+
|
|
480
|
+
except Exception as e:
|
|
481
|
+
logger.debug(f"Failed to parse session {session_dir.name}: {e}")
|
|
482
|
+
|
|
483
|
+
return results
|
|
484
|
+
|
|
485
|
+
def _parse_commits_to_sessions(
|
|
486
|
+
self,
|
|
487
|
+
git_output: str,
|
|
488
|
+
project_path: str,
|
|
489
|
+
project_hash: str,
|
|
490
|
+
sessions_dir: Path,
|
|
491
|
+
parsed: ParsedQuery
|
|
492
|
+
) -> list[SessionResult]:
|
|
493
|
+
"""Parse git log output and group commits by session."""
|
|
494
|
+
|
|
495
|
+
# Split by our delimiter
|
|
496
|
+
commit_blocks = git_output.split("§END§")
|
|
497
|
+
|
|
498
|
+
# Group by session
|
|
499
|
+
session_commits: dict[str, list[dict]] = {}
|
|
500
|
+
|
|
501
|
+
for block in commit_blocks:
|
|
502
|
+
block = block.strip()
|
|
503
|
+
if not block:
|
|
504
|
+
continue
|
|
505
|
+
|
|
506
|
+
# Parse: hash|subject|date|body
|
|
507
|
+
try:
|
|
508
|
+
first_line, _, body = block.partition('\n')
|
|
509
|
+
parts = first_line.split('|', 3)
|
|
510
|
+
if len(parts) < 3:
|
|
511
|
+
continue
|
|
512
|
+
|
|
513
|
+
commit_hash = parts[0]
|
|
514
|
+
subject = parts[1]
|
|
515
|
+
date = parts[2]
|
|
516
|
+
full_body = body.strip() if len(parts) > 3 else ""
|
|
517
|
+
|
|
518
|
+
# The subject line contains embedded YAML frontmatter
|
|
519
|
+
# Format: "--- session: ABC123 turn: 1 timestamp: ... tags: [#tag1, #tag2] ..."
|
|
520
|
+
# OR: "[ABC123] Turn 1: message"
|
|
521
|
+
|
|
522
|
+
# Try to extract session ID from YAML-style subject
|
|
523
|
+
session_match = re.search(r'session:\s*([A-Za-z0-9_-]+)', subject)
|
|
524
|
+
if not session_match:
|
|
525
|
+
# Fallback: try [session_id] format
|
|
526
|
+
session_match = re.match(r'\[([A-Za-z0-9_-]+)', subject)
|
|
527
|
+
|
|
528
|
+
if not session_match:
|
|
529
|
+
continue
|
|
530
|
+
|
|
531
|
+
session_id_prefix = session_match.group(1)
|
|
532
|
+
|
|
533
|
+
# Parse embedded YAML data from subject line
|
|
534
|
+
# Extract key fields directly since they're on one line
|
|
535
|
+
yaml_data = {}
|
|
536
|
+
|
|
537
|
+
# Extract tags: [#tag1, #tag2, ...]
|
|
538
|
+
tags_match = re.search(r'tags:\s*\[(.*?)\]', subject)
|
|
539
|
+
if tags_match:
|
|
540
|
+
tags_str = tags_match.group(1)
|
|
541
|
+
yaml_data['tags'] = [t.strip() for t in tags_str.split(',') if t.strip()]
|
|
542
|
+
|
|
543
|
+
# Extract files: [file1, file2, ...]
|
|
544
|
+
files_match = re.search(r'files:\s*\[(.*?)\]', subject)
|
|
545
|
+
if files_match:
|
|
546
|
+
files_str = files_match.group(1)
|
|
547
|
+
yaml_data['files'] = [f.strip() for f in files_str.split(',') if f.strip()]
|
|
548
|
+
|
|
549
|
+
# Extract summary from subject (comes after ---)
|
|
550
|
+
summary_match = re.search(r'summary:\s*"([^"]*)"', subject)
|
|
551
|
+
if summary_match:
|
|
552
|
+
yaml_data['summary'] = summary_match.group(1)
|
|
553
|
+
|
|
554
|
+
# If there's a body, also try to parse YAML frontmatter from it
|
|
555
|
+
if full_body:
|
|
556
|
+
body_yaml = parse_yaml_frontmatter(full_body)
|
|
557
|
+
# Merge, preferring body data
|
|
558
|
+
for k, v in body_yaml.items():
|
|
559
|
+
if v: # Only use non-empty values
|
|
560
|
+
yaml_data[k] = v
|
|
561
|
+
|
|
562
|
+
commit_data = {
|
|
563
|
+
"hash": commit_hash,
|
|
564
|
+
"subject": subject,
|
|
565
|
+
"date": date,
|
|
566
|
+
"body": full_body,
|
|
567
|
+
"yaml": yaml_data,
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
# Find full session ID
|
|
571
|
+
full_session_id = None
|
|
572
|
+
if sessions_dir.exists():
|
|
573
|
+
for sd in sessions_dir.iterdir():
|
|
574
|
+
if sd.name.startswith(session_id_prefix):
|
|
575
|
+
full_session_id = sd.name
|
|
576
|
+
break
|
|
577
|
+
|
|
578
|
+
if not full_session_id:
|
|
579
|
+
full_session_id = session_id_prefix
|
|
580
|
+
|
|
581
|
+
if full_session_id not in session_commits:
|
|
582
|
+
session_commits[full_session_id] = []
|
|
583
|
+
session_commits[full_session_id].append(commit_data)
|
|
584
|
+
|
|
585
|
+
except Exception as e:
|
|
586
|
+
logger.debug(f"Failed to parse commit block: {e}")
|
|
587
|
+
|
|
588
|
+
# Convert to SessionResult objects
|
|
589
|
+
results = []
|
|
590
|
+
project_name = get_project_display_name(project_path)
|
|
591
|
+
|
|
592
|
+
for session_id, commits in session_commits.items():
|
|
593
|
+
# Get latest commit for summary
|
|
594
|
+
latest = commits[0] if commits else {}
|
|
595
|
+
yaml_data = latest.get("yaml", {})
|
|
596
|
+
|
|
597
|
+
# Extract tags from all commits
|
|
598
|
+
all_tags = set()
|
|
599
|
+
all_files = set()
|
|
600
|
+
journey_entries = []
|
|
601
|
+
decisions = []
|
|
602
|
+
|
|
603
|
+
for c in commits:
|
|
604
|
+
c_yaml = c.get("yaml", {})
|
|
605
|
+
|
|
606
|
+
if c_yaml.get("tags"):
|
|
607
|
+
all_tags.update(c_yaml["tags"])
|
|
608
|
+
if c_yaml.get("files"):
|
|
609
|
+
all_files.update(c_yaml["files"])
|
|
610
|
+
if c_yaml.get("journey"):
|
|
611
|
+
for j in c_yaml["journey"]:
|
|
612
|
+
if j.get("summary"):
|
|
613
|
+
journey_entries.append(j["summary"])
|
|
614
|
+
|
|
615
|
+
# Extract summary from body
|
|
616
|
+
summary = yaml_data.get("summary") or self._extract_section(latest.get("body", ""), "Summary")
|
|
617
|
+
|
|
618
|
+
# Load session metadata for enrichment
|
|
619
|
+
meta = {}
|
|
620
|
+
meta_file = sessions_dir / session_id / "meta.json"
|
|
621
|
+
if meta_file.exists():
|
|
622
|
+
try:
|
|
623
|
+
meta = json.loads(meta_file.read_text(encoding="utf-8"))
|
|
624
|
+
except Exception:
|
|
625
|
+
pass
|
|
626
|
+
|
|
627
|
+
shadow_meta = meta.get("shadow", {})
|
|
628
|
+
|
|
629
|
+
# Calculate match score
|
|
630
|
+
score, reasons = self._calculate_match_score(
|
|
631
|
+
parsed,
|
|
632
|
+
summary or "",
|
|
633
|
+
list(all_tags),
|
|
634
|
+
list(all_files),
|
|
635
|
+
journey_entries,
|
|
636
|
+
meta.get("name", "")
|
|
637
|
+
)
|
|
638
|
+
|
|
639
|
+
first_prompt = self._read_first_prompt(sessions_dir, session_id) if not summary else None
|
|
640
|
+
|
|
641
|
+
result = SessionResult(
|
|
642
|
+
session_id=session_id,
|
|
643
|
+
project=project_name,
|
|
644
|
+
project_path=project_path,
|
|
645
|
+
name=meta.get("name"),
|
|
646
|
+
created_at=meta.get("created_at"),
|
|
647
|
+
last_activity=meta.get("last_activity"),
|
|
648
|
+
message_count=meta.get("message_count", 0),
|
|
649
|
+
total_cost=meta.get("total_cost", 0.0),
|
|
650
|
+
forked_from=meta.get("forked_from"),
|
|
651
|
+
is_comment_thread=meta.get("isCommentThread", False),
|
|
652
|
+
summary=summary,
|
|
653
|
+
first_prompt=first_prompt,
|
|
654
|
+
tags=list(all_tags)[:10],
|
|
655
|
+
files_changed=list(all_files)[:15],
|
|
656
|
+
journey_snippet=journey_entries[-1] if journey_entries else None,
|
|
657
|
+
turn_count=shadow_meta.get("turn_count", len(commits)),
|
|
658
|
+
tools_summary=shadow_meta.get("tools_summary", {}),
|
|
659
|
+
match_score=score,
|
|
660
|
+
match_reasons=reasons,
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
results.append(result)
|
|
664
|
+
|
|
665
|
+
return results
|
|
666
|
+
|
|
667
|
+
def _extract_section(self, body: str, section: str) -> Optional[str]:
|
|
668
|
+
"""Extract a section from commit body (## Section)."""
|
|
669
|
+
pattern = rf'## {section}\s*\n(.*?)(?:\n##|\n---|\Z)'
|
|
670
|
+
match = re.search(pattern, body, re.DOTALL | re.IGNORECASE)
|
|
671
|
+
if match:
|
|
672
|
+
content = match.group(1).strip()
|
|
673
|
+
# Get first non-empty line
|
|
674
|
+
for line in content.split('\n'):
|
|
675
|
+
line = line.strip()
|
|
676
|
+
if line and not line.startswith('-') and not line.startswith('*'):
|
|
677
|
+
return line[:200]
|
|
678
|
+
return None
|
|
679
|
+
|
|
680
|
+
def _calculate_match_score(
|
|
681
|
+
self,
|
|
682
|
+
parsed: ParsedQuery,
|
|
683
|
+
summary: str,
|
|
684
|
+
tags: list[str],
|
|
685
|
+
files: list[str],
|
|
686
|
+
journey: list[str],
|
|
687
|
+
name: str
|
|
688
|
+
) -> tuple[float, list[str]]:
|
|
689
|
+
"""Calculate relevance score and reasons."""
|
|
690
|
+
|
|
691
|
+
score = 0.0
|
|
692
|
+
reasons = []
|
|
693
|
+
|
|
694
|
+
summary_lower = summary.lower()
|
|
695
|
+
name_lower = name.lower()
|
|
696
|
+
journey_text = " ".join(journey).lower()
|
|
697
|
+
|
|
698
|
+
# Tag matches (high weight)
|
|
699
|
+
for tag in parsed.tags:
|
|
700
|
+
if tag in tags:
|
|
701
|
+
score += 1.0
|
|
702
|
+
reasons.append(f"Has {tag} tag")
|
|
703
|
+
|
|
704
|
+
# Keyword matches in summary
|
|
705
|
+
for kw in parsed.keywords:
|
|
706
|
+
kw_lower = kw.lower()
|
|
707
|
+
if kw_lower in summary_lower:
|
|
708
|
+
score += 0.8
|
|
709
|
+
reasons.append(f"Summary mentions '{kw}'")
|
|
710
|
+
elif kw_lower in name_lower:
|
|
711
|
+
score += 0.6
|
|
712
|
+
reasons.append(f"Name contains '{kw}'")
|
|
713
|
+
elif kw_lower in journey_text:
|
|
714
|
+
score += 0.4
|
|
715
|
+
reasons.append(f"Journey mentions '{kw}'")
|
|
716
|
+
|
|
717
|
+
# File matches
|
|
718
|
+
for f in parsed.files:
|
|
719
|
+
f_lower = f.lower()
|
|
720
|
+
for file in files:
|
|
721
|
+
if f_lower in file.lower():
|
|
722
|
+
score += 0.7
|
|
723
|
+
reasons.append(f"Modified {file}")
|
|
724
|
+
break
|
|
725
|
+
|
|
726
|
+
# Recency bonus (if no time filter, boost recent)
|
|
727
|
+
if not parsed.time_filter:
|
|
728
|
+
score += 0.1 # Small boost, actual ranking uses last_activity
|
|
729
|
+
|
|
730
|
+
return score, reasons
|
|
731
|
+
|
|
732
|
+
def _rank_results(
|
|
733
|
+
self,
|
|
734
|
+
results: list[SessionResult],
|
|
735
|
+
parsed: ParsedQuery
|
|
736
|
+
) -> list[SessionResult]:
|
|
737
|
+
"""Rank results by relevance and recency."""
|
|
738
|
+
|
|
739
|
+
def sort_key(r: SessionResult):
|
|
740
|
+
# Primary: match score (higher is better)
|
|
741
|
+
# Secondary: recency (more recent is better)
|
|
742
|
+
recency = 0.0
|
|
743
|
+
if r.last_activity:
|
|
744
|
+
try:
|
|
745
|
+
dt = datetime.fromisoformat(r.last_activity.replace('Z', '+00:00'))
|
|
746
|
+
days_ago = (datetime.now(dt.tzinfo) - dt).days
|
|
747
|
+
recency = max(0, 30 - days_ago) / 30 # 0-1 based on last 30 days
|
|
748
|
+
except Exception:
|
|
749
|
+
pass
|
|
750
|
+
|
|
751
|
+
# If explicit query, prioritize match score
|
|
752
|
+
# If browsing (no query), prioritize recency
|
|
753
|
+
if parsed.keywords or parsed.tags:
|
|
754
|
+
return (r.match_score * 2 + recency, recency)
|
|
755
|
+
else:
|
|
756
|
+
return (recency * 2 + r.match_score, r.match_score)
|
|
757
|
+
|
|
758
|
+
return sorted(results, key=sort_key, reverse=True)
|
|
759
|
+
|
|
760
|
+
def _generate_suggestions(
|
|
761
|
+
self,
|
|
762
|
+
parsed: ParsedQuery,
|
|
763
|
+
results: list[SessionResult]
|
|
764
|
+
) -> list[str]:
|
|
765
|
+
"""Generate helpful search suggestions."""
|
|
766
|
+
|
|
767
|
+
suggestions = []
|
|
768
|
+
|
|
769
|
+
# If no results, suggest alternatives
|
|
770
|
+
if not results:
|
|
771
|
+
if parsed.tags:
|
|
772
|
+
suggestions.append(f"Try searching without tags: {' '.join(parsed.keywords)}")
|
|
773
|
+
if parsed.time_filter:
|
|
774
|
+
suggestions.append("Try 'this month' for a wider time range")
|
|
775
|
+
if not parsed.keywords:
|
|
776
|
+
suggestions.append("Try adding keywords like 'auth', 'bug', 'feature'")
|
|
777
|
+
|
|
778
|
+
# Suggest related queries based on results
|
|
779
|
+
if results:
|
|
780
|
+
# Collect common tags from results
|
|
781
|
+
all_tags = set()
|
|
782
|
+
for r in results[:5]:
|
|
783
|
+
all_tags.update(r.tags)
|
|
784
|
+
|
|
785
|
+
# Suggest unexplored tags
|
|
786
|
+
searched_tags = set(parsed.tags)
|
|
787
|
+
new_tags = all_tags - searched_tags
|
|
788
|
+
if new_tags:
|
|
789
|
+
tag = list(new_tags)[0]
|
|
790
|
+
suggestions.append(f"Try: '{parsed.raw} {tag}'")
|
|
791
|
+
|
|
792
|
+
# General suggestions
|
|
793
|
+
if not parsed.time_filter:
|
|
794
|
+
suggestions.append("Add 'yesterday' or 'last week' to filter by time")
|
|
795
|
+
|
|
796
|
+
return suggestions[:3]
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
800
|
+
# Session summaries (lightweight map for the quick-switcher drill-in)
|
|
801
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
802
|
+
|
|
803
|
+
async def get_session_summaries(project_path: str, max_commits: int = 5000) -> dict[str, str]:
|
|
804
|
+
"""
|
|
805
|
+
Map session_id → latest AI summary, parsed from shadow-git commit subjects.
|
|
806
|
+
|
|
807
|
+
Much lighter than WelcomeSearcher: one `git log --format=%s` (subjects
|
|
808
|
+
only, no bodies), simple regex extraction, newest commit per session wins.
|
|
809
|
+
Sessions older than `max_commits` shadow commits simply get no summary —
|
|
810
|
+
callers treat the summary as optional enrichment. Subjects-only log is
|
|
811
|
+
~30ms per 1000 commits, so the 5000 cap bounds the worst case at ~150ms.
|
|
812
|
+
"""
|
|
813
|
+
shadow_dir = get_shadow_git_dir(project_path)
|
|
814
|
+
if not shadow_dir.exists():
|
|
815
|
+
return {}
|
|
816
|
+
|
|
817
|
+
cmd = [
|
|
818
|
+
"git", f"--git-dir={shadow_dir}",
|
|
819
|
+
"log", "--format=%s", "-n", str(max_commits),
|
|
820
|
+
]
|
|
821
|
+
try:
|
|
822
|
+
proc = await asyncio.create_subprocess_exec(
|
|
823
|
+
*cmd,
|
|
824
|
+
stdout=asyncio.subprocess.PIPE,
|
|
825
|
+
stderr=asyncio.subprocess.PIPE,
|
|
826
|
+
)
|
|
827
|
+
stdout, _ = await proc.communicate()
|
|
828
|
+
if proc.returncode != 0:
|
|
829
|
+
return {}
|
|
830
|
+
except Exception as e:
|
|
831
|
+
logger.debug(f"Session summary scan failed for {project_path}: {e}")
|
|
832
|
+
return {}
|
|
833
|
+
|
|
834
|
+
summaries: dict[str, str] = {}
|
|
835
|
+
for subject in stdout.decode(errors="replace").splitlines():
|
|
836
|
+
sid_match = re.search(r'session:\s*([A-Za-z0-9_-]+)', subject)
|
|
837
|
+
if not sid_match:
|
|
838
|
+
continue
|
|
839
|
+
sid = sid_match.group(1)
|
|
840
|
+
if sid in summaries:
|
|
841
|
+
continue # newest-first log — first hit is the latest summary
|
|
842
|
+
# The turn-level summary is the LAST `summary: "…"` in the subject
|
|
843
|
+
# (earlier ones belong to embedded journey entries).
|
|
844
|
+
found = re.findall(r'summary:\s*"([^"]*)"', subject)
|
|
845
|
+
if found and found[-1]:
|
|
846
|
+
summaries[sid] = found[-1]
|
|
847
|
+
return summaries
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
851
|
+
# Recent Sessions (for welcome screen)
|
|
852
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
853
|
+
|
|
854
|
+
async def get_recent_sessions(limit: int = 10) -> list[dict]:
|
|
855
|
+
"""
|
|
856
|
+
Get recent sessions with enriched shadow git data.
|
|
857
|
+
|
|
858
|
+
This powers the welcome screen's session list with rich metadata.
|
|
859
|
+
"""
|
|
860
|
+
searcher = WelcomeSearcher()
|
|
861
|
+
|
|
862
|
+
# Empty query = get all, sorted by recency
|
|
863
|
+
result = await searcher.search("", limit=limit)
|
|
864
|
+
|
|
865
|
+
return result["results"]
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
869
|
+
# Singleton
|
|
870
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
871
|
+
|
|
872
|
+
_searcher: Optional[WelcomeSearcher] = None
|
|
873
|
+
|
|
874
|
+
def get_welcome_searcher() -> WelcomeSearcher:
|
|
875
|
+
"""Get or create the welcome searcher singleton."""
|
|
876
|
+
global _searcher
|
|
877
|
+
if _searcher is None:
|
|
878
|
+
_searcher = WelcomeSearcher()
|
|
879
|
+
return _searcher
|