@nandoblanco/opencode-local-search 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +9 -7
- package/dist/gui-experimental.cjs +1 -1
- package/package.json +2 -1
- package/src/gui.css +46 -0
- package/src/gui.tsx +98 -22
- package/src/rpc.ts +6 -0
- package/src/search.ts +156 -63
- package/src/server.ts +7 -0
- package/src/sort.ts +5 -0
- package/src/tui.ts +56 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.2.0 (2026-11-17)
|
|
4
|
+
|
|
5
|
+
- Renamed OpenCode Desktop sidebar label (`vertical-tabs-search`), panel tab title, and dialog title from `Search sessions` to `Search` and stripped any trailing shortcut badge from the left sidebar button (`src/gui.tsx`).
|
|
6
|
+
- Added a centered loading spinner overlay (`.ols-loading-center` / `.ols-loading-pill`) inside the search results split view (`src/gui.tsx`, `src/gui.css`) and reduced search input debounce to 16ms.
|
|
7
|
+
- Accelerated session search (`src/search.ts`, `src/server.ts`) with incremental SQLite `session_v2` delta indexing (`time_updated > cachedMaxUpdated`), skipping redundant V1 fallback table scans when V2 sessions exist, and prewarming the index on server plugin startup.
|
|
8
|
+
- Added session sort modes (`updated`, `relevance`, `newest`, `oldest`, `title`, `context`, `tokens`) via `src/sort.ts` with interactive sort controls in `/search` TUI (`src/tui.ts`) and OpenCode Desktop (`src/gui.tsx`).
|
|
9
|
+
- Included `archived`, `contextTokens`, and `totalTokens` session metadata in RPC and server search responses (`src/rpc.ts`, `src/server.ts`).
|
|
10
|
+
|
|
11
|
+
## 1.1.0 (2026-11-12)
|
|
12
|
+
|
|
13
|
+
- Added OpenCode Desktop Session Search (`src/gui.tsx`, `src/gui.css`, `dist/gui-experimental.cjs`, and `SearchRpc` in `src/rpc.ts`) with a persistent side panel (`Ctrl+Shift+F` to open/focus, `Ctrl+Alt+F` to toggle), fallback dialog when no session is active, and routing from OpenCode Desktop's built-in titlebar, vertical-tabs, Home session search, and Search sessions dialog.
|
|
14
|
+
- Updated `cli.js` and `src/server.ts` to register `SearchRpc.query` for shared SQLite session search across TUI and Desktop.
|
|
15
|
+
|
|
16
|
+
## 1.0.2 (2026-10-28)
|
|
17
|
+
|
|
18
|
+
- Refined the `/search` OpenTUI modal layout (`src/tui.ts`) with a bordered filter bar and split-pane session and message snippet cards.
|
|
19
|
+
|
|
20
|
+
## 1.0.1 (2026-10-26)
|
|
21
|
+
|
|
22
|
+
- Scoped npm package as `@nandoblanco/opencode-local-search` with public `publishConfig` and normalized `bin` and `repository` fields.
|
|
23
|
+
- Hardened regex ReDoS guards in `parseQuery`, enforced inline filters during fuzzy fallback matching in `src/search.ts`, bounded the in-memory index cache, and cleaned up transcript auto-scroll timers in `src/tui.ts`.
|
|
24
|
+
|
|
25
|
+
## 1.0.0 (2026-10-25)
|
|
26
|
+
|
|
27
|
+
- Initial release of `opencode-local-search` for OpenCode.
|
|
28
|
+
- Added zero-token local SQLite session indexing (`bun:sqlite` and `node:sqlite`) supporting both OpenCode V2 (`session_v2`, `session_message`) and V1 (`session`, `message`, `part`) schemas.
|
|
29
|
+
- Added multi-term session-level AND ranking, exact phrase matching, regex (`/pattern/i` and `re:`), bounded Levenshtein fuzzy search (`~term`), inline filter tokens (`role:`, `date:`, `file:`, `tool:`, `scope:`), one-command CLI installer (`cli.js`), and the `/search` split-pane TUI modal (`src/tui.ts`) with auto-scroll to matched messages.
|
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
## OpenCode Desktop Support
|
|
8
8
|
|
|
9
|
-
**Replaces OpenCode Desktop's built-in session search.** The titlebar, vertical-tabs, Home session search, and built-in Search sessions dialog route into this plugin's
|
|
9
|
+
**Replaces OpenCode Desktop's built-in session search.** The titlebar, vertical-tabs (`Search`), Home session search, and built-in Search sessions dialog route into this plugin's `Search` interface.
|
|
10
10
|
|
|
11
|
-
**Now available in OpenCode Desktop as well as the TUI.** Search local conversation history in a persistent
|
|
11
|
+
**Now available in OpenCode Desktop as well as the TUI.** Search local conversation history in a persistent `Search` side panel, sort sessions by recency, relevance, creation time, title, context size, or total tokens, preview matching messages and file/tool details, and open matching sessions without a model turn. Press `Ctrl+Shift+F` to open or focus the panel, or `Ctrl+Alt+F` to toggle it. When no session is active, search opens in a fallback dialog.
|
|
12
12
|
|
|
13
13
|
**In the CLI/TUI, search is an additional tool rather than a replacement.** Open it with `/search` or the command palette. The built-in `/sessions` picker remains available.
|
|
14
14
|
|
|
@@ -34,11 +34,12 @@ This project started as a small local CLI script wired to a custom `/search` com
|
|
|
34
34
|
| Local-first, zero-token execution | Queries your local OpenCode SQLite database directly inside the TUI with zero LLM token usage, zero server tools, and zero cloud dependencies |
|
|
35
35
|
| Zero external npm dependencies | Uses the SQLite driver built into OpenCode's runtime (`bun:sqlite` or `node:sqlite`) and a built-in bounded Levenshtein matcher, requiring no native C++ addons |
|
|
36
36
|
| Dual-schema support (OpenCode V2 + V1) | Automatically detects and indexes both the OpenCode V2 schema (`session_v2` and `session_message`) and the V1 schema (`session`, `message`, and `part`) |
|
|
37
|
-
| Interactive `/search` TUI modal | Wide (`80%` default, configurable via `dialogWidth`) split-pane popup with colored filter pills (`^p` scope, `^g` role, `^t` date, `^r` mode, `^l` refresh), live session list on the left, and highlighted message/tool/file snippet cards on the right |
|
|
37
|
+
| Interactive `/search` TUI modal | Wide (`80%` default, configurable via `dialogWidth`) split-pane popup with colored filter pills (`^p` scope, `^g` role, `^t` date, `^r` mode, `^o` sort, `^l` refresh), live session list on the left, and highlighted message/tool/file snippet cards on the right |
|
|
38
38
|
| Session-level multi-term AND ranking | Searching `auth cookie` finds sessions where both terms appear anywhere across the session title, user prompts, assistant replies, tool calls, or file paths, ranking single-message co-occurrences higher |
|
|
39
|
+
| Multi-mode session sorting | Sort results by `Recently updated`, `Relevance`, `Newest created`, `Oldest created`, `Title A-Z`, `Latest context size`, or `Total tokens used` (`src/sort.ts`) |
|
|
39
40
|
| Typo-tolerant fuzzy & regex search | Supports `"exact phrase"`, `/regex/i` (`re:`), explicit `~fuzzy` terms, and automatic bounded Levenshtein fallback when a multi-word query has a typo |
|
|
40
41
|
| Auto-scroll to matched message | Pressing `Enter` (or clicking any snippet card in the preview pane) opens the session and automatically scrolls the transcript to the exact matched message |
|
|
41
|
-
| OpenCode Desktop search | Persistent
|
|
42
|
+
| OpenCode Desktop search | Persistent `Search` side panel backed by `SearchRpc.query`, with a fallback dialog when no session is active, centered loading spinner, scope/query/sort controls, snippets, and session navigation |
|
|
42
43
|
|
|
43
44
|
## Installation
|
|
44
45
|
|
|
@@ -103,9 +104,9 @@ For development, use Node.js 26.4 or newer to meet the OpenTUI dependency's decl
|
|
|
103
104
|
|
|
104
105
|
### OpenCode Desktop
|
|
105
106
|
|
|
106
|
-
Run `/search [query]` or press `Ctrl+Shift+F` (`Cmd+Shift+F` on macOS) to open and focus the persistent
|
|
107
|
+
Run `/search [query]` or press `Ctrl+Shift+F` (`Cmd+Shift+F` on macOS) to open and focus the persistent `Search` side panel. `Ctrl+Alt+F` (`Cmd+Option+F`) toggles it. Without an active session, these commands open a dialog. The plugin also intercepts the built-in titlebar, vertical-tab (`Search`), and home-session search entry points.
|
|
107
108
|
|
|
108
|
-
Desktop requests use a
|
|
109
|
+
Desktop requests use a 16 ms debounce, a centered loading spinner overlay, and a sequence counter to discard stale responses. They call `SearchRpc.query` on the server, which prewarms the SQLite session index on startup and returns up to 60 session results with message snippets, token/context metadata, and file/tool details. The TUI continues to query SQLite locally. Exact-message scrolling in the TUI uses the render-tree traversal described below; Desktop uses its own session navigation path.
|
|
109
110
|
|
|
110
111
|
## TUI Query Syntax (`/search`)
|
|
111
112
|
|
|
@@ -137,6 +138,7 @@ Type filters inline in the search bar or toggle them with keyboard shortcuts and
|
|
|
137
138
|
| `Ctrl+G` | Cycle role filter pill (`all` -> `user` -> `assistant` -> `shell`) |
|
|
138
139
|
| `Ctrl+T` | Cycle date filter pill (`all` -> `today` -> `yesterday` -> `7d` -> `30d`) |
|
|
139
140
|
| `Ctrl+R` | Cycle search mode pill (`smart` -> `fuzzy` -> `regex`) |
|
|
141
|
+
| `Ctrl+O` | Cycle session sort order (`updated` -> `relevance` -> `newest` -> `oldest` -> `title` -> `context` -> `tokens`) |
|
|
140
142
|
| `Ctrl+L` | Force refresh the SQLite session index |
|
|
141
143
|
| `Esc` | Close popup |
|
|
142
144
|
|
|
@@ -154,7 +156,7 @@ Type filters inline in the search bar or toggle them with keyboard shortcuts and
|
|
|
154
156
|
4. `~/.local/share/opencode/opencode.db` (macOS, Linux, Windows)
|
|
155
157
|
5. `%LOCALAPPDATA%/opencode/opencode.db` (Windows fallback)
|
|
156
158
|
|
|
157
|
-
Once loaded, `loadSessionIndex()`
|
|
159
|
+
Once loaded, `loadSessionIndex()` keeps the parsed `SessionIndex` in memory (`INDEX_TTL_MS = 2000`) and performs incremental SQLite delta updates (`WHERE time_updated > cachedMaxUpdated`) so only newly modified sessions are re-read from `session_v2` and `session_message`. Typing in the search bar filters in sub-millisecond time (`Ctrl+L` or Desktop `Refresh` forces a full re-index).
|
|
158
160
|
|
|
159
161
|
### 2. Dual-Schema Indexing (OpenCode V2 + V1 Fallback)
|
|
160
162
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("solid-js/web"),t=require("@opencode/plugin/gui"),n=require("solid-js");var r=`.ols-root{--ols-bg-surface:var(--v2-background-bg-layer-01,#141417);--ols-bg-subtle:var(--v2-background-bg-base,#0e0e11);--ols-bg-elevated:var(--v2-background-bg-layer-02,#1c1c21);--ols-bg-pill:var(--v2-background-bg-layer-03,#25252c);--ols-bg-hover:var(--v2-overlay-simple-overlay-hover,#ffffff0d);--ols-bg-pressed:var(--v2-overlay-simple-overlay-pressed,#ffffff17);--ols-border:var(--v2-border-border-muted,#ffffff14);--ols-border-strong:var(--v2-border-border-strong,#ffffff24);--ols-focus:var(--v2-border-border-focus,#3b82f6);--ols-text:var(--v2-text-text-base,#ededf0);--ols-text-muted:var(--v2-text-text-muted,#9ca3af);--ols-text-faint:var(--v2-text-text-faint,#6b7280);--ols-danger:var(--v2-state-fg-danger,#ef4444);--ols-mark-bg:#f59e0b38;--ols-mark-fg:var(--v2-text-text-base,#fde68a);box-sizing:border-box;width:100%;height:100%;min-height:0;color:var(--ols-text);font-family:var(--font-family-text,-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);letter-spacing:-.04px;-webkit-user-select:none;user-select:none;flex-direction:column;font-size:13px;font-weight:440;line-height:1.45;display:flex;overflow:hidden}.ols-root[data-scheme=light]{--ols-bg-surface:var(--v2-background-bg-layer-01,#fff);--ols-bg-subtle:var(--v2-background-bg-base,#f6f6f8);--ols-bg-elevated:var(--v2-background-bg-layer-02,#f0f0f3);--ols-bg-pill:var(--v2-background-bg-layer-03,#e6e6eb);--ols-bg-hover:var(--v2-overlay-simple-overlay-hover,#0000000b);--ols-bg-pressed:var(--v2-overlay-simple-overlay-pressed,#00000014);--ols-border:var(--v2-border-border-muted,#00000014);--ols-border-strong:var(--v2-border-border-strong,#00000024);--ols-text:var(--v2-text-text-base,#161618);--ols-text-muted:var(--v2-text-text-muted,#5c606a);--ols-text-faint:var(--v2-text-text-faint,#8c909a);--ols-mark-bg:#f59e0b47;--ols-mark-fg:#78350f}.ols-root *,.ols-root :before,.ols-root :after{box-sizing:border-box}.ols-root--modal{border-top:1px solid var(--ols-border);border-bottom:1px solid var(--ols-border);flex:1;height:min(64vh,480px);max-height:100%;overflow:hidden}.ols-root--panel{height:100%;min-height:360px}.ols-header{border-bottom:1px solid var(--ols-border);flex-direction:column;flex-shrink:0;gap:8px;padding:10px 16px;display:flex}.ols-root--panel .ols-header{padding:10px 12px}.ols-input-wrap{width:100%;display:flex}.ols-input-wrap [data-component=text-input-v2]{flex:1;width:100%}.ols-controls-bar{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px;display:flex}.ols-controls-left{flex-wrap:wrap;align-items:center;gap:6px;min-width:0;display:flex}.ols-controls-right{flex-shrink:0;align-items:center;gap:6px;margin-inline-start:auto;display:flex}.ols-segment{background:var(--ols-bg-elevated);box-shadow:inset 0 0 0 1px var(--ols-border);border-radius:6px;align-items:center;padding:2px;display:inline-flex}.ols-segment-btn{height:20px;color:var(--ols-text-muted);letter-spacing:-.04px;cursor:pointer;background:0 0;border:0;border-radius:4px;align-items:center;gap:5px;padding:0 8px;font-family:inherit;font-size:12px;font-weight:440;transition:background-color 85ms ease-out,color 85ms ease-out;display:inline-flex}.ols-segment-btn:hover{color:var(--ols-text)}.ols-segment-btn:focus-visible{outline:2px solid var(--ols-focus);outline-offset:1px}.ols-segment-btn--active{background:var(--ols-bg-surface);color:var(--ols-text);box-shadow:var(--v2-elevation-button-neutral,0 1px 2px #00000029);font-weight:530}.ols-active-pill{background:var(--ols-bg-pill);height:22px;color:var(--ols-text);cursor:pointer;border:0;border-radius:4px;align-items:center;gap:4px;padding:0 6px 0 8px;font-family:inherit;font-size:12px;font-weight:440;transition:background-color 85ms ease-out;display:inline-flex}.ols-active-pill:hover{background:var(--ols-bg-pressed)}.ols-active-pill:focus-visible{outline:2px solid var(--ols-focus);outline-offset:1px}.ols-error-pill{height:22px;color:var(--ols-danger);background:#ef44441f;border-radius:4px;align-items:center;padding:0 8px;font-size:12px;font-weight:530;display:inline-flex}.ols-status-count{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;align-items:center;font-size:12px;display:inline-flex}.ols-split{flex:1;grid-template-columns:minmax(260px,38%) minmax(0,1fr);min-height:0;display:grid;overflow:hidden}.ols-root--panel .ols-split{grid-template-rows:minmax(170px,44%) minmax(0,1fr);grid-template-columns:1fr}.ols-column{flex-direction:column;min-width:0;min-height:0;display:flex;overflow:hidden}.ols-column--list{border-right:1px solid var(--ols-border);background:var(--ols-bg-subtle)}.ols-root--panel .ols-column--list{border-right:0;border-bottom:1px solid var(--ols-border)}.ols-column--detail{background:var(--ols-bg-surface)}.ols-list-scroll,.ols-detail-scroll{flex:1;min-height:0;overflow:hidden auto}.ols-list-scroll{flex-direction:column;gap:2px;padding:6px;display:flex}.ols-row{width:100%;color:var(--ols-text);text-align:left;cursor:pointer;background:0 0;border:0;border-radius:6px;flex-direction:column;gap:3px;padding:8px 10px;font-family:inherit;transition:background-color 65ms ease-out;display:flex}.ols-row:hover{background:var(--ols-bg-hover)}.ols-row:focus-visible{outline:2px solid var(--ols-focus);outline-offset:-2px}.ols-row--selected,.ols-row--selected:hover{background:var(--ols-bg-pressed)}.ols-row-top{justify-content:space-between;align-items:baseline;gap:8px;min-width:0;display:flex}.ols-row-title{color:var(--ols-text);white-space:nowrap;text-overflow:ellipsis;flex:1;min-width:0;font-size:13px;font-weight:530;overflow:hidden}.ols-row-time{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;flex-shrink:0;font-size:11px}.ols-row-snippet{color:var(--ols-text-muted);-webkit-line-clamp:2;overflow-wrap:anywhere;-webkit-box-orient:vertical;font-size:12px;line-height:1.38;display:-webkit-box;overflow:hidden}.ols-row-meta{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;white-space:nowrap;align-items:center;gap:6px;margin-top:2px;font-size:11px;display:flex;overflow:hidden}.ols-row-hit-badge{background:var(--ols-bg-pill);height:16px;color:var(--ols-text-muted);letter-spacing:.01em;border-radius:3px;align-items:center;padding:0 5px;font-size:10px;font-weight:530;display:inline-flex}.ols-row-folder{color:var(--ols-text-muted);text-overflow:ellipsis;overflow:hidden}.ols-detail-header{border-bottom:1px solid var(--ols-border);flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;padding:12px 16px;display:flex}.ols-detail-heading{flex-direction:column;flex:1;gap:2px;min-width:0;display:flex}.ols-detail-title{color:var(--ols-text);white-space:nowrap;text-overflow:ellipsis;font-size:14px;font-weight:530;overflow:hidden}.ols-detail-meta{color:var(--ols-text-faint);white-space:nowrap;text-overflow:ellipsis;align-items:center;gap:6px;font-size:12px;display:flex;overflow:hidden}.ols-detail-actions{flex-shrink:0;align-items:center;gap:6px;display:flex}.ols-quick-bar{border-bottom:1px solid var(--ols-border);background:var(--ols-bg-subtle);flex-wrap:wrap;flex-shrink:0;align-items:center;gap:6px;padding:7px 16px;display:flex}.ols-quick-label{color:var(--ols-text-faint);font-size:11px}.ols-quick-chip{background:var(--ols-bg-elevated);height:20px;box-shadow:inset 0 0 0 1px var(--ols-border);color:var(--ols-text-muted);font-family:var(--font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);cursor:pointer;border:0;border-radius:4px;align-items:center;padding:0 7px;font-size:11px;transition:background-color 65ms ease-out,color 65ms ease-out;display:inline-flex}.ols-quick-chip:hover{background:var(--ols-bg-hover);color:var(--ols-text)}.ols-timeline{divide-y:1px solid var(--ols-border);flex-direction:column;display:flex}.ols-turn{border-bottom:1px solid var(--ols-border);cursor:pointer;flex-direction:column;gap:4px;padding:12px 16px;transition:background-color 65ms ease-out;display:flex}.ols-turn:hover{background:var(--ols-bg-hover)}.ols-turn--selected{background:var(--ols-bg-pressed)}.ols-turn-header{align-items:center;gap:6px;font-size:12px;display:flex}.ols-turn-author{color:var(--ols-text);font-weight:530}.ols-turn-author--user{color:var(--ols-text)}.ols-turn-author--assistant{color:var(--ols-text-muted)}.ols-turn-author--shell{color:var(--v2-state-fg-warning,#f59e0b)}.ols-turn-chip{background:var(--ols-bg-pill);height:16px;color:var(--ols-text-muted);font-family:var(--font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);border-radius:3px;align-items:center;padding:0 5px;font-size:10px;display:inline-flex}.ols-turn-time{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;margin-inline-start:auto;font-size:11px}.ols-turn-body{color:var(--ols-text-muted);white-space:pre-wrap;overflow-wrap:anywhere;-webkit-user-select:text;user-select:text;font-size:13px;line-height:1.5}.ols-mark{background:var(--ols-mark-bg);color:var(--ols-mark-fg);border-radius:2px;padding:0 2px;font-weight:530}.ols-empty{text-align:center;flex-direction:column;flex:1;justify-content:center;align-items:center;gap:4px;padding:36px 20px;display:flex}.ols-empty-title{color:var(--ols-text);font-size:13px;font-weight:530}.ols-empty-sub{color:var(--ols-text-faint);max-width:280px;font-size:12px}.ols-inline-link{color:var(--ols-text);font:inherit;text-underline-offset:2px;cursor:pointer;background:0 0;border:0;padding:0;font-weight:530;text-decoration:underline}.ols-dialog-footer{justify-content:space-between;align-items:center;gap:12px;width:100%;display:flex}.ols-dialog-shortcuts{flex-wrap:wrap;align-items:center;gap:14px;display:flex}.ols-shortcut-item{color:var(--ols-text-faint);align-items:center;gap:5px;font-size:12px;display:inline-flex}@media (width<=720px){.ols-split{grid-template-rows:minmax(160px,42%) minmax(0,1fr);grid-template-columns:1fr}.ols-column--list{border-right:0;border-bottom:1px solid var(--ols-border)}}[data-component=home-session-search],[data-component=home-session-search] label,[data-component=home-session-search] input{cursor:pointer}#home-session-search-results{display:none}`,i={id:`opencode-local-search`,methods:{query:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{query:{type:`string`},scope:{type:`string`,enum:[`all`,`project`]},currentDirectory:{type:`string`},role:{type:`string`,enum:[`all`,`user`,`assistant`,`shell`]},datePreset:{type:`string`,enum:[`all`,`today`,`yesterday`,`7d`,`30d`]},mode:{type:`string`,enum:[`smart`,`fuzzy`,`regex`]},limit:{type:`number`},forceReload:{type:`boolean`}},required:[`query`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,additionalProperties:!0}}},events:{}},a=(0,e.template)(`<mark class=ols-mark>`),o=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset search mode"><span>`),s=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset role filter"><span>`),c=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset time filter"><span>`),l=(0,e.template)(`<div class=ols-split><div><div class=ols-list-scroll></div></div><div>`),u=(0,e.template)(`<div><div class=ols-header><div class=ols-input-wrap></div><div class=ols-controls-bar><div class=ols-controls-left><div class=ols-segment role=group aria-label="Search scope"><button type=button><span></span></button><button type=button><span>All workspaces</span></button></div></div><div class=ols-controls-right><span class=ols-status-count>`),d=(0,e.template)(`<span class=ols-error-pill>`),f=(0,e.template)(`<div class=ols-empty><div class=ols-empty-title>Unable to search sessions</div><div class=ols-empty-sub>`),ee=(0,e.template)(`<button type=button class=ols-inline-link>All workspaces`),te=(0,e.template)(`<div class=ols-empty><div class=ols-empty-title>No matching sessions</div><div class=ols-empty-sub>`),ne=(0,e.template)(`<div class=ols-row-snippet>`),re=(0,e.template)(`<span class=ols-row-hit-badge>`),ie=(0,e.template)(`<span class=ols-row-folder>`),ae=(0,e.template)(`<button type=button><div class=ols-row-top><span class=ols-row-title></span><span class=ols-row-time></span></div><div class=ols-row-meta><span> messages`),oe=(0,e.template)(`<div class=ols-empty><div class=ols-empty-sub>Select a session to inspect conversation matches.`),se=(0,e.template)(`<div class=ols-detail-header><div class=ols-detail-heading><div class=ols-detail-title></div><div class=ols-detail-meta><span></span><span>·</span><span></span></div></div><div class=ols-detail-actions>`),ce=(0,e.template)(`<div class=ols-quick-bar><span class=ols-quick-label>Try:</span><button type=button class=ols-quick-chip>role:user</button><button type=button class=ols-quick-chip>tool:shell</button><button type=button class=ols-quick-chip>in:title</button><button type=button class=ols-quick-chip>since:7d`),p=(0,e.template)(`<div class=ols-timeline>`),le=(0,e.template)(`<div class=ols-detail-scroll>`),ue=(0,e.template)(`<span class=ols-turn-chip>`),de=(0,e.template)(`<div class=ols-turn><div class=ols-turn-header><span></span><span class=ols-turn-time></span></div><div class=ols-turn-body>`),fe=(0,e.template)(`<span class=ols-turn-chip>file`),pe=(0,e.template)(`<span class=ols-turn-chip>~`),me=(0,e.template)(`<div><div class=ols-turn-header><span></span><span class=ols-turn-time></span></div><div class=ols-turn-body>`),m=[`all`,`user`,`assistant`,`shell`],h=[`all`,`today`,`yesterday`,`7d`,`30d`],g=[`smart`,`fuzzy`,`regex`],he={all:`Any time`,today:`Today`,yesterday:`Yesterday`,"7d":`Last 7 days`,"30d":`Last 30 days`},ge={smart:`Smart`,fuzzy:`Fuzzy`,regex:`Regex`},_={all:`All roles`,user:`User`,assistant:`Assistant`,shell:`Shell`};function v(e,t=Date.now()){if(!e||e<=0)return``;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=new Date(e);return`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,`0`)}-${String(o.getDate()).padStart(2,`0`)}`}function _e(e){if(!e)return`unknown`;let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)} ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function y(e){if(!e)return`Global`;let t=e.replace(/\\/g,`/`).split(`/`).filter(Boolean);return t.length<=2?t.join(`/`):`${t.slice(-2).join(`/`)}`}function b(e,t,n,r){if(!e)return[{text:``,match:!1}];if(n)try{let t=r?.includes(`g`)?r:`${r??`i`}g`,i=new RegExp(n,t),a=[],o=0,s,c=0;for(;(s=i.exec(e))!==null&&c++<40;)s[0].length===0?i.lastIndex++:(s.index>o&&a.push({text:e.slice(o,s.index),match:!1}),a.push({text:s[0],match:!0}),o=s.index+s[0].length);return o<e.length&&a.push({text:e.slice(o),match:!1}),a.length>0?a:[{text:e,match:!1}]}catch{return[{text:e,match:!1}]}let i=t.map(e=>e.trim().toLowerCase()).filter(e=>e.length>0).sort((e,t)=>t.length-e.length);if(i.length===0)return[{text:e,match:!1}];let a=e.toLowerCase(),o=[],s=0;for(;s<e.length;){let t=-1,n=0;for(let e of i){let r=a.indexOf(e,s);r!==-1&&(t===-1||r<t)&&(t=r,n=e.length)}if(t===-1){o.push({text:e.slice(s),match:!1});break}t>s&&o.push({text:e.slice(s,t),match:!1}),o.push({text:e.slice(t,t+n),match:!0}),s=t+n}return o.length>0?o:[{text:e,match:!1}]}function x(t){let r=(0,n.createMemo)(()=>b(t.text,t.terms,t.regexPattern,t.regexFlags));return(0,e.createComponent)(n.For,{get each(){return r()},children:t=>t.match?(()=>{var n=a();return(0,e.insert)(n,()=>t.text),n})():t.text})}function S(e){let t=e.sessions.current();if(t?.server?.id)return t.server.id;let n=e.servers.list();for(let t of n)if(e.servers.get(t)?.builtin)return t;return n[0]??`sidecar`}function C(e){return e===`user`?`You`:e===`assistant`?`Assistant`:e===`shell`?`Command`:e===`title`?`Title`:e}var[w,T]=(0,n.createSignal)(``);function E(t){let r=t.ctx.ui,[a,b]=(0,n.createSignal)(t.initialQuery??``),[T,E]=(0,n.createSignal)(t.ctx.sessions.current()?.directory?`project`:`all`),[D,O]=(0,n.createSignal)(`all`),[k,A]=(0,n.createSignal)(`all`),[j,M]=(0,n.createSignal)(`smart`),[N,P]=(0,n.createSignal)(0),[F,I]=(0,n.createSignal)(0),[L,R]=(0,n.createSignal)(`sessions`),[ve,z]=(0,n.createSignal)(!0),[ye,B]=(0,n.createSignal)(!1),[V,H]=(0,n.createSignal)(null),[be,xe]=(0,n.createSignal)(0),[U,Se]=(0,n.createSignal)([]),[W,Ce]=(0,n.createSignal)(null);(0,n.createEffect)(()=>{let e=w();e&&b(e)});let G=0,K,q=(0,n.createMemo)(()=>t.ctx.sessions.current()?.directory??``),we=(0,n.createMemo)(()=>t.ctx.appearance.mode());async function J(e=!1){let n=++G;e&&B(!0),z(!0),H(null);try{let r=await(t.ctx.sessions.current()?.server?.client??t.ctx.servers.get(S(t.ctx))?.client??t.ctx.client).rpc(i).query({query:a(),scope:T(),currentDirectory:q(),role:D(),datePreset:k(),mode:j(),limit:60,forceReload:e});if(n!==G)return;xe(r.totalSessions),Se(r.results),Ce(r.parsed),P(e=>Math.max(0,Math.min(e,Math.max(0,r.results.length-1)))),I(0),e&&t.ctx.toast.show({variant:`success`,title:`Refreshed ${r.totalSessions} sessions`})}catch(e){if(n!==G)return;H(e instanceof Error?e.message:`Failed to query session index`)}finally{n===G&&(z(!1),B(!1))}}(0,n.createEffect)(()=>{a(),T(),D(),k(),j(),q(),K&&clearTimeout(K),K=setTimeout(()=>{J(!1)},35)}),(0,n.onCleanup)(()=>{K&&clearTimeout(K)});let Y=(0,n.createMemo)(()=>U()[N()]??U()[0]),X=(0,n.createMemo)(()=>{let e=W(),t=e?[...e.terms,...e.fuzzyTerms]:[],n=Y()?.matches[F()]?.matchedTerm;return n&&!t.includes(n)&&t.push(n),t}),Z=(0,n.createMemo)(()=>{let e=0;return D()!==`all`&&e++,k()!==`all`&&e++,j()!==`smart`&&e++,e}),Te=(0,n.createMemo)(()=>[{type:`group`,label:`Search Mode`,items:g.map(e=>({label:ge[e],icon:j()===e?`check-small`:void 0,onSelect:()=>{M(e),P(0)}}))},{type:`separator`},{type:`group`,label:`Message Role`,items:m.map(e=>({label:_[e],icon:D()===e?`check-small`:void 0,onSelect:()=>{O(e),P(0)}}))},{type:`separator`},{type:`group`,label:`Time Range`,items:h.map(e=>({label:he[e],icon:k()===e?`check-small`:void 0,onSelect:()=>{A(e),P(0)}}))},{type:`separator`},{label:`Reset filters`,disabled:Z()===0,onSelect:()=>{M(`smart`),O(`all`),A(`all`),P(0)}}]);function Ee(){E(e=>e===`project`?`all`:`project`),P(0)}function De(){O(e=>m[(m.indexOf(e)+1)%m.length]??`all`),P(0)}function Oe(){A(e=>h[(h.indexOf(e)+1)%h.length]??`all`),P(0)}function ke(){M(e=>g[(g.indexOf(e)+1)%g.length]??`smart`),P(0)}function Q(e){if(!e)return;let n=S(t.ctx);t.ctx.tabs.open({server:n,id:e.id},{focus:!0}),t.onClose?.()}async function Ae(e){e&&(await t.ctx.system.copy(e.id),t.ctx.toast.show({variant:`success`,title:`Copied session ID`,description:e.id}))}function $(e){let t=a().trim();b(t?`${t} ${e}`:e)}function je(e){if((e.ctrlKey||e.altKey)&&!e.shiftKey){let t=e.key.toLowerCase();if(t===`p`){e.preventDefault(),Ee();return}if(t===`g`){e.preventDefault(),De();return}if(t===`t`){e.preventDefault(),Oe();return}if(t===`r`){e.preventDefault(),ke();return}if(t===`l`){e.preventDefault(),J(!0);return}}if(e.key===`Tab`){e.preventDefault(),R(e=>e===`sessions`?`matches`:`sessions`);return}let t=U().length,n=Y()?.matches.length??0;e.key===`ArrowDown`?(e.preventDefault(),L()===`matches`&&n>0?I(e=>Math.min(n-1,e+1)):t>0&&(P(e=>Math.min(t-1,e+1)),I(0))):e.key===`ArrowUp`?(e.preventDefault(),L()===`matches`&&n>0?I(e=>Math.max(0,e-1)):t>0&&(P(e=>Math.max(0,e-1)),I(0))):e.key===`PageDown`?(e.preventDefault(),t>0&&(P(e=>Math.min(t-1,e+8)),I(0))):e.key===`PageUp`?(e.preventDefault(),t>0&&(P(e=>Math.max(0,e-8)),I(0))):e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q(Y()))}return(()=>{var i=u(),m=i.firstChild.firstChild,h=m.nextSibling.firstChild,g=h.firstChild.firstChild,S=g.firstChild,w=g.nextSibling,z=h.nextSibling,B=z.firstChild;return i.$$keydown=je,(0,e.insert)(m,(0,e.createComponent)(r.TextInput,{type:`search`,size:`large`,label:`Search session history`,get value(){return a()},onInput:e=>{b(e),P(0),I(0)},onSubmit:()=>Q(Y()),placeholder:`Search conversations, "exact phrase", fuzzy~, /regex/i, role:user, tool:shell...`,get invalid(){return!!W()?.regexError},autofocus:!0})),g.$$click=()=>{E(`project`),P(0)},(0,e.insert)(g,(0,e.createComponent)(r.Icon,{name:`folder`,size:`small`}),S),(0,e.insert)(S,(()=>{var t=(0,e.memo)(()=>!!q());return()=>t()?y(q()):`Project`})()),w.$$click=()=>{E(`all`),P(0)},(0,e.insert)(h,(0,e.createComponent)(r.Menu,{get label(){return(0,e.memo)(()=>Z()>0)()?`Filters (${Z()})`:`Filters`},icon:`sliders`,trigger:`button`,get items(){return Te()}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return j()!==`smart`},get children(){var t=o(),n=t.firstChild;return t.$$click=()=>M(`smart`),(0,e.insert)(n,()=>ge[j()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return D()!==`all`},get children(){var t=s(),n=t.firstChild;return t.$$click=()=>O(`all`),(0,e.insert)(n,()=>_[D()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return k()!==`all`},get children(){var t=c(),n=t.firstChild;return t.$$click=()=>A(`all`),(0,e.insert)(n,()=>he[k()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return W()?.regexError},children:t=>(()=>{var n=d();return(0,e.insert)(n,t),n})()}),null),(0,e.insert)(B,(0,e.createComponent)(n.Show,{get when(){return!ve()},get fallback(){return(0,e.createComponent)(r.Loader,{size:`small`})},get children(){return[(0,e.memo)(()=>U().length),` of `,(0,e.memo)(()=>be()),` sessions`]}})),(0,e.insert)(z,(0,e.createComponent)(r.Tooltip,{value:`Refresh index`,keys:[`Ctrl`,`L`],get children(){return(0,e.createComponent)(r.IconButton,{icon:`refresh`,label:`Refresh index`,variant:`ghost`,size:`small`,get busy(){return ye()},onClick:()=>void J(!0)})}}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return V()},children:t=>(()=>{var n=f(),r=n.firstChild.nextSibling;return(0,e.insert)(r,t),n})()}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return!V()},get children(){var i=l(),o=i.firstChild,s=o.firstChild,c=o.nextSibling;return o.$$click=()=>R(`sessions`),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return U().length>0},get fallback(){return(()=>{var t=te(),r=t.firstChild.nextSibling;return(0,e.insert)(r,(0,e.createComponent)(n.Show,{get when(){return T()===`project`},fallback:`Try Fuzzy mode or fewer search terms.`,get children(){return[`No hits in this workspace. Switch to`,` `,(()=>{var e=ee();return e.$$click=Ee,e})(),` `,`to search everywhere.`]}})),t})()},get children(){return(0,e.createComponent)(n.For,{get each(){return U()},children:(t,r)=>{let i=()=>r()===N();return(()=>{var o=ae(),s=o.firstChild,c=s.firstChild,l=c.nextSibling,u=s.nextSibling,d=u.firstChild,f=d.firstChild;return o.$$dblclick=()=>Q(t),o.$$click=()=>{P(r()),I(0),R(`sessions`)},(0,e.insert)(c,(0,e.createComponent)(x,{get text(){return t.title||`Untitled session`},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),(0,e.insert)(l,()=>v(t.timeUpdated)),(0,e.insert)(o,(0,e.createComponent)(n.Show,{get when(){return t.bestSnippet},get children(){var n=ne();return(0,e.insert)(n,(0,e.createComponent)(x,{get text(){return t.bestSnippet},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),n}}),u),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return a().trim().length>0},get children(){var n=re();return(0,e.insert)(n,()=>t.matchBadge),n}}),d),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>T()===`all`)()&&t.directory},get children(){var n=ie();return(0,e.insert)(n,()=>y(t.directory)),n}}),d),(0,e.insert)(d,()=>t.entryCount,f),(0,e.effect)(()=>(0,e.className)(o,`ols-row ${i()?`ols-row--selected`:``}`)),o})()}})}})),c.$$click=()=>R(`matches`),(0,e.insert)(c,(0,e.createComponent)(n.Show,{get when(){return Y()},get fallback(){return oe()},children:i=>[(()=>{var t=se(),n=t.firstChild,a=n.firstChild,o=a.nextSibling.firstChild,s=o.nextSibling.nextSibling,c=n.nextSibling;return(0,e.insert)(a,()=>i().title),(0,e.insert)(o,()=>i().directory||`Global`),(0,e.insert)(s,()=>_e(i().timeUpdated)),(0,e.insert)(c,(0,e.createComponent)(r.Tooltip,{value:`Copy session ID`,get children(){return(0,e.createComponent)(r.IconButton,{icon:`copy`,label:`Copy session ID`,variant:`ghost`,size:`small`,onClick:()=>void Ae(i())})}}),null),(0,e.insert)(c,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,icon:`square-arrow-top-right`,onClick:()=>Q(i()),children:`Open`}),null),t})(),(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>a().trim().length===0)()&&t.variant===`modal`},get children(){var e=ce(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.nextSibling;return t.$$click=()=>$(`role:user`),n.$$click=()=>$(`tool:shell`),r.$$click=()=>$(`in:title`),i.$$click=()=>$(`since:7d`),e}}),(()=>{var t=le();return(0,e.insert)(t,(0,e.createComponent)(n.Show,{get when(){return i().matches.length>0},get fallback(){return(()=>{var t=p();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return i().recentEntries},children:t=>(()=>{var r=de(),a=r.firstChild,o=a.firstChild,s=o.nextSibling,c=a.nextSibling;return r.$$click=()=>Q(i()),(0,e.insert)(o,()=>C(t.role)),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return t.toolName},get children(){var n=ue();return(0,e.insert)(n,()=>t.toolName),n}}),s),(0,e.insert)(s,()=>v(t.timeCreated)),(0,e.insert)(c,()=>t.text),(0,e.effect)(()=>(0,e.className)(o,`ols-turn-author ols-turn-author--${t.role}`)),r})()})),t})()},get children(){var t=p();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return i().matches},children:(t,r)=>{let a=()=>L()===`matches`&&r()===F();return(()=>{var o=me(),s=o.firstChild,c=s.firstChild,l=c.nextSibling,u=s.nextSibling;return o.$$dblclick=()=>Q(i()),o.$$click=()=>{R(`matches`),I(r())},(0,e.insert)(c,()=>C(t.role)),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>t.kind===`tool`)()&&t.toolName},get children(){var n=ue();return(0,e.insert)(n,()=>t.toolName),n}}),l),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return t.kind===`filepath`},get children(){return fe()}}),l),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return t.kind===`fuzzy`},get children(){var n=pe();return n.firstChild,(0,e.insert)(n,()=>t.matchedTerm,null),n}}),l),(0,e.insert)(l,()=>v(t.timeCreated)),(0,e.insert)(u,(0,e.createComponent)(x,{get text(){return t.snippet},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),(0,e.effect)(n=>{var r=`ols-turn ${a()?`ols-turn--selected`:``}`,i=`ols-turn-author ols-turn-author--${t.role}`;return r!==n.e&&(0,e.className)(o,n.e=r),i!==n.t&&(0,e.className)(c,n.t=i),n},{e:void 0,t:void 0}),o})()}})),t}})),t})()]})),(0,e.effect)(t=>{var n=`ols-column ols-column--list ${L()===`sessions`?`ols-column--active`:``}`,r=`ols-column ols-column--detail ${L()===`matches`?`ols-column--active`:``}`;return n!==t.e&&(0,e.className)(o,t.e=n),r!==t.t&&(0,e.className)(c,t.t=r),t},{e:void 0,t:void 0}),i}}),null),(0,e.effect)(n=>{var r=`ols-root ols-root--${t.variant}`,a=we(),o=`ols-segment-btn ${T()===`project`?`ols-segment-btn--active`:``}`,s=q()?`Current project (${q()})`:`Current project`,c=`ols-segment-btn ${T()===`all`?`ols-segment-btn--active`:``}`;return r!==n.e&&(0,e.className)(i,n.e=r),a!==n.t&&(0,e.setAttribute)(i,`data-scheme`,n.t=a),o!==n.a&&(0,e.className)(g,n.a=o),s!==n.o&&(0,e.setAttribute)(g,`title`,n.o=s),c!==n.i&&(0,e.className)(w,n.i=c),n},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}var D=t.Plugin.define({i18n:{en:{"search.title":`Search Sessions`,"search.command":`Search session history...`,"search.panel":`Session Search`}},setup(i){let a=i.ui;i.add(t.Style,r);let o;function s(t=``){T(t);let r=i.sessions.current();if(r){o?.close();try{i.layout.open(`${i.id}:search`,r)}catch{}}else{if(o)return;o=i.dialogs.open(r=>((0,n.onCleanup)(()=>{o=void 0}),(0,e.createComponent)(a.Dialog,{title:`Search Sessions`,size:`x-large`,get children(){return(0,e.createComponent)(E,{ctx:i,variant:`modal`,initialQuery:t,get onClose(){return r.close}})}})))}}if(i.add(t.Command,()=>({id:`search`,title:`Search session history...`,description:`Full-text, fuzzy, regex, tool, and file search across all session conversations`,keywords:`find history messages conversation regex fuzzy search grep`,group:`Session`,section:`session`,bind:`mod+shift+f`,slash:{name:`search`,arguments:!0},featured:!0,run(e){s(typeof e==`string`?e:``)}})),i.add(t.Command,()=>({id:`search-panel`,title:`Toggle session search panel`,description:`Open or close the Session Search side panel`,keywords:`panel sidebar search history`,group:`Session`,section:`session`,bind:`mod+alt+f`,run(){let e=i.sessions.current();e?i.layout.toggle(`${i.id}:search`,e):s(``)}})),typeof document<`u`){let e=e=>{let t=e.closest(`button`);if(!t||t.closest(`.ols-root`))return!1;if(t.getAttribute(`data-action`)===`vertical-tabs-search`)return!0;if(!t.closest(`[data-slot="titlebar-v2"]`)||t.closest(`[data-titlebar-plugin-item]`))return!1;if((t.getAttribute(`aria-label`)??``).toLowerCase().includes(`search`))return!0;let n=t.querySelector(`svg[data-slot="icon-svg"] use`);return(n?.getAttribute(`href`)??n?.getAttribute(`xlink:href`)??``).includes(`magnifying-glass`)},t=t=>{let n=t.target;if(!(n instanceof Element))return;if(e(n)){t.preventDefault(),t.stopPropagation(),s(``);return}let r=n.closest(`[data-component="home-session-search"]`);if(r){t.preventDefault(),t.stopPropagation();let e=r.querySelector(`input`),n=e instanceof HTMLInputElement?e.value:``;e instanceof HTMLElement&&e.blur(),s(n)}},r=e=>{let t=e.target;if(!(t instanceof Element)||!t.closest(`[data-component="home-session-search"]`))return;let n=t instanceof HTMLInputElement?t.value:``;t instanceof HTMLElement&&t.blur(),s(n)};document.addEventListener(`click`,t,!0),document.addEventListener(`focusin`,r,!0);let i=new WeakSet,a=new MutationObserver(()=>{let e=document.querySelector(`.command-palette input[placeholder="Search sessions"], .command-palette-dialog input[placeholder="Search sessions..."]`);if(e&&!i.has(e)){i.add(e);let t=e.value||``;e.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,code:`Escape`,bubbles:!0,cancelable:!0})),s(t)}});document.body&&a.observe(document.body,{childList:!0,subtree:!0}),(0,n.onCleanup)(()=>{document.removeEventListener(`click`,t,!0),document.removeEventListener(`focusin`,r,!0),a.disconnect()})}let c={id:`search`,get title(){return i.t(`search.panel`)},closable:`compact`};i.add(t.Panel,{id:`search`,region:`side`,list:e=>e.open.includes(`search`)?[c]:[],render:()=>(0,e.createComponent)(E,{ctx:i,variant:`panel`})}),i.add(t.MenuItem,()=>{let e=i.sessions.current();return{menu:`session.panel`,id:`search`,title:`Session Search`,description:`Search conversation history`,icon:`magnifying-glass`,keybind:`${i.id}.search-panel`,opened:!!e&&i.layout.state(`${i.id}:search`,e)!==`closed`,run:()=>{let e=i.sessions.current();e?i.layout.open(`${i.id}:search`,e):s(``)}}})}});(0,e.delegateEvents)([`keydown`,`click`,`dblclick`]),exports.default=D;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require("solid-js/web"),t=require("@opencode/plugin/gui"),n=require("solid-js");var r=`.ols-root{--ols-bg-surface:var(--v2-background-bg-layer-01,#141417);--ols-bg-subtle:var(--v2-background-bg-base,#0e0e11);--ols-bg-elevated:var(--v2-background-bg-layer-02,#1c1c21);--ols-bg-pill:var(--v2-background-bg-layer-03,#25252c);--ols-bg-hover:var(--v2-overlay-simple-overlay-hover,#ffffff0d);--ols-bg-pressed:var(--v2-overlay-simple-overlay-pressed,#ffffff17);--ols-border:var(--v2-border-border-muted,#ffffff14);--ols-border-strong:var(--v2-border-border-strong,#ffffff24);--ols-focus:var(--v2-border-border-focus,#3b82f6);--ols-text:var(--v2-text-text-base,#ededf0);--ols-text-muted:var(--v2-text-text-muted,#9ca3af);--ols-text-faint:var(--v2-text-text-faint,#6b7280);--ols-danger:var(--v2-state-fg-danger,#ef4444);--ols-mark-bg:#f59e0b38;--ols-mark-fg:var(--v2-text-text-base,#fde68a);box-sizing:border-box;width:100%;height:100%;min-height:0;color:var(--ols-text);font-family:var(--font-family-text,-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);letter-spacing:-.04px;-webkit-user-select:none;user-select:none;flex-direction:column;font-size:13px;font-weight:440;line-height:1.45;display:flex;overflow:hidden}.ols-root[data-scheme=light]{--ols-bg-surface:var(--v2-background-bg-layer-01,#fff);--ols-bg-subtle:var(--v2-background-bg-base,#f6f6f8);--ols-bg-elevated:var(--v2-background-bg-layer-02,#f0f0f3);--ols-bg-pill:var(--v2-background-bg-layer-03,#e6e6eb);--ols-bg-hover:var(--v2-overlay-simple-overlay-hover,#0000000b);--ols-bg-pressed:var(--v2-overlay-simple-overlay-pressed,#00000014);--ols-border:var(--v2-border-border-muted,#00000014);--ols-border-strong:var(--v2-border-border-strong,#00000024);--ols-text:var(--v2-text-text-base,#161618);--ols-text-muted:var(--v2-text-text-muted,#5c606a);--ols-text-faint:var(--v2-text-text-faint,#8c909a);--ols-mark-bg:#f59e0b47;--ols-mark-fg:#78350f}.ols-root *,.ols-root :before,.ols-root :after{box-sizing:border-box}.ols-root--modal{border-top:1px solid var(--ols-border);border-bottom:1px solid var(--ols-border);flex:1;height:min(64vh,480px);max-height:100%;overflow:hidden}.ols-root--panel{height:100%;min-height:360px}.ols-header{border-bottom:1px solid var(--ols-border);flex-direction:column;flex-shrink:0;gap:8px;padding:10px 16px;display:flex}.ols-root--panel .ols-header{padding:10px 12px}.ols-input-wrap{width:100%;display:flex}.ols-input-wrap [data-component=text-input-v2]{flex:1;width:100%}.ols-controls-bar{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px;display:flex}.ols-controls-left{flex-wrap:wrap;align-items:center;gap:6px;min-width:0;display:flex}.ols-controls-right{flex-shrink:0;align-items:center;gap:6px;margin-inline-start:auto;display:flex}.ols-segment{background:var(--ols-bg-elevated);box-shadow:inset 0 0 0 1px var(--ols-border);border-radius:6px;align-items:center;padding:2px;display:inline-flex}.ols-segment-btn{height:20px;color:var(--ols-text-muted);letter-spacing:-.04px;cursor:pointer;background:0 0;border:0;border-radius:4px;align-items:center;gap:5px;padding:0 8px;font-family:inherit;font-size:12px;font-weight:440;transition:background-color 85ms ease-out,color 85ms ease-out;display:inline-flex}.ols-segment-btn:hover{color:var(--ols-text)}.ols-segment-btn:focus-visible{outline:2px solid var(--ols-focus);outline-offset:1px}.ols-segment-btn--active{background:var(--ols-bg-surface);color:var(--ols-text);box-shadow:var(--v2-elevation-button-neutral,0 1px 2px #00000029);font-weight:530}.ols-active-pill{background:var(--ols-bg-pill);height:22px;color:var(--ols-text);cursor:pointer;border:0;border-radius:4px;align-items:center;gap:4px;padding:0 6px 0 8px;font-family:inherit;font-size:12px;font-weight:440;transition:background-color 85ms ease-out;display:inline-flex}.ols-active-pill:hover{background:var(--ols-bg-pressed)}.ols-active-pill:focus-visible{outline:2px solid var(--ols-focus);outline-offset:1px}.ols-error-pill{height:22px;color:var(--ols-danger);background:#ef44441f;border-radius:4px;align-items:center;padding:0 8px;font-size:12px;font-weight:530;display:inline-flex}.ols-status-count{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;align-items:center;font-size:12px;display:inline-flex}.ols-split{flex:1;grid-template-columns:minmax(260px,38%) minmax(0,1fr);min-height:0;display:grid;position:relative;overflow:hidden}.ols-loading-center{z-index:20;-webkit-backdrop-filter:blur(1.5px);backdrop-filter:blur(1.5px);pointer-events:none;background:#0e0e116b;justify-content:center;align-items:center;display:flex;position:absolute;inset:0}.ols-root[data-scheme=light] .ols-loading-center{background:#f6f6f885}.ols-loading-pill{background:var(--ols-bg-elevated);border:1px solid var(--ols-border-strong);color:var(--ols-text);border-radius:999px;align-items:center;gap:8px;padding:8px 14px;font-size:12px;font-weight:530;display:inline-flex;box-shadow:0 4px 16px #00000047}.ols-spinner{border:2px solid var(--ols-border-strong);border-top-color:var(--ols-focus);border-radius:50%;width:14px;height:14px;animation:.65s linear infinite ols-spin}@keyframes ols-spin{to{transform:rotate(360deg)}}.ols-root--panel .ols-split{grid-template-rows:minmax(170px,44%) minmax(0,1fr);grid-template-columns:1fr}.ols-column{flex-direction:column;min-width:0;min-height:0;display:flex;overflow:hidden}.ols-column--list{border-right:1px solid var(--ols-border);background:var(--ols-bg-subtle)}.ols-root--panel .ols-column--list{border-right:0;border-bottom:1px solid var(--ols-border)}.ols-column--detail{background:var(--ols-bg-surface)}.ols-list-scroll,.ols-detail-scroll{flex:1;min-height:0;overflow:hidden auto}.ols-list-scroll{flex-direction:column;gap:2px;padding:6px;display:flex}.ols-row{width:100%;color:var(--ols-text);text-align:left;cursor:pointer;background:0 0;border:0;border-radius:6px;flex-direction:column;gap:3px;padding:8px 10px;font-family:inherit;transition:background-color 65ms ease-out;display:flex}.ols-row:hover{background:var(--ols-bg-hover)}.ols-row:focus-visible{outline:2px solid var(--ols-focus);outline-offset:-2px}.ols-row--selected,.ols-row--selected:hover{background:var(--ols-bg-pressed)}.ols-row-top{justify-content:space-between;align-items:baseline;gap:8px;min-width:0;display:flex}.ols-row-title{color:var(--ols-text);white-space:nowrap;text-overflow:ellipsis;flex:1;min-width:0;font-size:13px;font-weight:530;overflow:hidden}.ols-row-time{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;flex-shrink:0;font-size:11px}.ols-row-snippet{color:var(--ols-text-muted);-webkit-line-clamp:2;overflow-wrap:anywhere;-webkit-box-orient:vertical;font-size:12px;line-height:1.38;display:-webkit-box;overflow:hidden}.ols-row-meta{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;white-space:nowrap;align-items:center;gap:6px;margin-top:2px;font-size:11px;display:flex;overflow:hidden}.ols-row-hit-badge{background:var(--ols-bg-pill);height:16px;color:var(--ols-text-muted);letter-spacing:.01em;border-radius:3px;align-items:center;padding:0 5px;font-size:10px;font-weight:530;display:inline-flex}.ols-row-folder{color:var(--ols-text-muted);text-overflow:ellipsis;overflow:hidden}.ols-detail-header{border-bottom:1px solid var(--ols-border);flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;padding:12px 16px;display:flex}.ols-detail-heading{flex-direction:column;flex:1;gap:2px;min-width:0;display:flex}.ols-detail-title{color:var(--ols-text);white-space:nowrap;text-overflow:ellipsis;font-size:14px;font-weight:530;overflow:hidden}.ols-detail-meta{color:var(--ols-text-faint);white-space:nowrap;text-overflow:ellipsis;align-items:center;gap:6px;font-size:12px;display:flex;overflow:hidden}.ols-detail-actions{flex-shrink:0;align-items:center;gap:6px;display:flex}.ols-quick-bar{border-bottom:1px solid var(--ols-border);background:var(--ols-bg-subtle);flex-wrap:wrap;flex-shrink:0;align-items:center;gap:6px;padding:7px 16px;display:flex}.ols-quick-label{color:var(--ols-text-faint);font-size:11px}.ols-quick-chip{background:var(--ols-bg-elevated);height:20px;box-shadow:inset 0 0 0 1px var(--ols-border);color:var(--ols-text-muted);font-family:var(--font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);cursor:pointer;border:0;border-radius:4px;align-items:center;padding:0 7px;font-size:11px;transition:background-color 65ms ease-out,color 65ms ease-out;display:inline-flex}.ols-quick-chip:hover{background:var(--ols-bg-hover);color:var(--ols-text)}.ols-timeline{divide-y:1px solid var(--ols-border);flex-direction:column;display:flex}.ols-turn{border-bottom:1px solid var(--ols-border);cursor:pointer;flex-direction:column;gap:4px;padding:12px 16px;transition:background-color 65ms ease-out;display:flex}.ols-turn:hover{background:var(--ols-bg-hover)}.ols-turn--selected{background:var(--ols-bg-pressed)}.ols-turn-header{align-items:center;gap:6px;font-size:12px;display:flex}.ols-turn-author{color:var(--ols-text);font-weight:530}.ols-turn-author--user{color:var(--ols-text)}.ols-turn-author--assistant{color:var(--ols-text-muted)}.ols-turn-author--shell{color:var(--v2-state-fg-warning,#f59e0b)}.ols-turn-chip{background:var(--ols-bg-pill);height:16px;color:var(--ols-text-muted);font-family:var(--font-family-mono,ui-monospace, SFMono-Regular, Consolas, monospace);border-radius:3px;align-items:center;padding:0 5px;font-size:10px;display:inline-flex}.ols-turn-time{color:var(--ols-text-faint);font-variant-numeric:tabular-nums;margin-inline-start:auto;font-size:11px}.ols-turn-body{color:var(--ols-text-muted);white-space:pre-wrap;overflow-wrap:anywhere;-webkit-user-select:text;user-select:text;font-size:13px;line-height:1.5}.ols-mark{background:var(--ols-mark-bg);color:var(--ols-mark-fg);border-radius:2px;padding:0 2px;font-weight:530}.ols-empty{text-align:center;flex-direction:column;flex:1;justify-content:center;align-items:center;gap:4px;padding:36px 20px;display:flex}.ols-empty-title{color:var(--ols-text);font-size:13px;font-weight:530}.ols-empty-sub{color:var(--ols-text-faint);max-width:280px;font-size:12px}.ols-inline-link{color:var(--ols-text);font:inherit;text-underline-offset:2px;cursor:pointer;background:0 0;border:0;padding:0;font-weight:530;text-decoration:underline}.ols-dialog-footer{justify-content:space-between;align-items:center;gap:12px;width:100%;display:flex}.ols-dialog-shortcuts{flex-wrap:wrap;align-items:center;gap:14px;display:flex}.ols-shortcut-item{color:var(--ols-text-faint);align-items:center;gap:5px;font-size:12px;display:inline-flex}@media (width<=720px){.ols-split{grid-template-rows:minmax(160px,42%) minmax(0,1fr);grid-template-columns:1fr}.ols-column--list{border-right:0;border-bottom:1px solid var(--ols-border)}}[data-component=home-session-search],[data-component=home-session-search] label,[data-component=home-session-search] input{cursor:pointer}#home-session-search-results{display:none}`,i={id:`opencode-local-search`,methods:{query:{input:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,properties:{query:{type:`string`},sort:{type:`string`,enum:[`updated`,`relevance`,`newest`,`oldest`,`title`,`context`,`tokens`]},scope:{type:`string`,enum:[`all`,`project`]},currentDirectory:{type:`string`},role:{type:`string`,enum:[`all`,`user`,`assistant`,`shell`]},datePreset:{type:`string`,enum:[`all`,`today`,`yesterday`,`7d`,`30d`]},mode:{type:`string`,enum:[`smart`,`fuzzy`,`regex`]},limit:{type:`number`},forceReload:{type:`boolean`}},required:[`query`],additionalProperties:!1},output:{$schema:`https://json-schema.org/draft/2020-12/schema`,type:`object`,additionalProperties:!0}}},events:{}},a={updated:`Recently updated`,relevance:`Relevance`,newest:`Newest created`,oldest:`Oldest created`,title:`Title A–Z`,context:`Latest context size`,tokens:`Total tokens used`},o=(0,e.template)(`<mark class=ols-mark>`),s=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset search mode"><span>`),c=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset role filter"><span>`),l=(0,e.template)(`<button type=button class=ols-active-pill title="Click to reset time filter"><span>`),u=(0,e.template)(`<div class=ols-loading-center role=status aria-live=polite><div class=ols-loading-pill><span class=ols-spinner aria-hidden=true></span><span>Searching...`),d=(0,e.template)(`<div class=ols-split><div><div class=ols-list-scroll></div></div><div>`),f=(0,e.template)(`<div><div class=ols-header><div class=ols-input-wrap></div><div class=ols-controls-bar><div class=ols-controls-left><div class=ols-segment role=group aria-label="Search scope"><button type=button><span></span></button><button type=button><span>All workspaces</span></button></div></div><div class=ols-controls-right><span class=ols-status-count>`),ee=(0,e.template)(`<span class=ols-error-pill>`),te=(0,e.template)(`<div class=ols-empty><div class=ols-empty-title>Unable to search sessions</div><div class=ols-empty-sub>`),ne=(0,e.template)(`<button type=button class=ols-inline-link>All workspaces`),re=(0,e.template)(`<div class=ols-empty><div class=ols-empty-title>No matching sessions</div><div class=ols-empty-sub>`),ie=(0,e.template)(`<div class=ols-row-snippet>`),ae=(0,e.template)(`<span class=ols-row-hit-badge>Archived`),oe=(0,e.template)(`<span>: `),se=(0,e.template)(`<span class=ols-row-hit-badge>`),ce=(0,e.template)(`<span class=ols-row-folder>`),le=(0,e.template)(`<button type=button><div class=ols-row-top><span class=ols-row-title></span><span class=ols-row-time></span></div><div class=ols-row-meta><span> messages`),ue=(0,e.template)(`<div class=ols-empty><div class=ols-empty-sub>Select a session to inspect conversation matches.`),de=(0,e.template)(`<span>Archived`),fe=(0,e.template)(`<div class=ols-detail-header><div class=ols-detail-heading><div class=ols-detail-title></div><div class=ols-detail-meta><span></span><span>·</span><span></span></div></div><div class=ols-detail-actions>`),pe=(0,e.template)(`<div class=ols-quick-bar><span class=ols-quick-label>Try:</span><button type=button class=ols-quick-chip>role:user</button><button type=button class=ols-quick-chip>tool:shell</button><button type=button class=ols-quick-chip>in:title</button><button type=button class=ols-quick-chip>since:7d`),p=(0,e.template)(`<div class=ols-timeline>`),me=(0,e.template)(`<div class=ols-detail-scroll>`),he=(0,e.template)(`<span class=ols-turn-chip>`),ge=(0,e.template)(`<div class=ols-turn><div class=ols-turn-header><span></span><span class=ols-turn-time></span></div><div class=ols-turn-body>`),_e=(0,e.template)(`<span class=ols-turn-chip>file`),ve=(0,e.template)(`<span class=ols-turn-chip>~`),ye=(0,e.template)(`<div><div class=ols-turn-header><span></span><span class=ols-turn-time></span></div><div class=ols-turn-body>`),m=[`all`,`user`,`assistant`,`shell`],h=[`all`,`today`,`yesterday`,`7d`,`30d`],g=[`smart`,`fuzzy`,`regex`],_={all:`Any time`,today:`Today`,yesterday:`Yesterday`,"7d":`Last 7 days`,"30d":`Last 30 days`},be={smart:`Smart`,fuzzy:`Fuzzy`,regex:`Regex`},xe={all:`All roles`,user:`User`,assistant:`Assistant`,shell:`Shell`};function v(e,t=Date.now()){if(!e||e<=0)return``;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=new Date(e);return`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,`0`)}-${String(o.getDate()).padStart(2,`0`)}`}function Se(e){if(!e)return`unknown`;let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)} ${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`}function Ce(e){if(!e)return`Global`;let t=e.replace(/\\/g,`/`).split(`/`).filter(Boolean);return t.length<=2?t.join(`/`):`${t.slice(-2).join(`/`)}`}function y(e,t,n,r){if(!e)return[{text:``,match:!1}];if(n)try{let t=r?.includes(`g`)?r:`${r??`i`}g`,i=new RegExp(n,t),a=[],o=0,s,c=0;for(;(s=i.exec(e))!==null&&c++<40;)s[0].length===0?i.lastIndex++:(s.index>o&&a.push({text:e.slice(o,s.index),match:!1}),a.push({text:s[0],match:!0}),o=s.index+s[0].length);return o<e.length&&a.push({text:e.slice(o),match:!1}),a.length>0?a:[{text:e,match:!1}]}catch{return[{text:e,match:!1}]}let i=t.map(e=>e.trim().toLowerCase()).filter(e=>e.length>0).sort((e,t)=>t.length-e.length);if(i.length===0)return[{text:e,match:!1}];let a=e.toLowerCase(),o=[],s=0;for(;s<e.length;){let t=-1,n=0;for(let e of i){let r=a.indexOf(e,s);r!==-1&&(t===-1||r<t)&&(t=r,n=e.length)}if(t===-1){o.push({text:e.slice(s),match:!1});break}t>s&&o.push({text:e.slice(s,t),match:!1}),o.push({text:e.slice(t,t+n),match:!0}),s=t+n}return o.length>0?o:[{text:e,match:!1}]}function b(t){let r=(0,n.createMemo)(()=>y(t.text,t.terms,t.regexPattern,t.regexFlags));return(0,e.createComponent)(n.For,{get each(){return r()},children:t=>t.match?(()=>{var n=o();return(0,e.insert)(n,()=>t.text),n})():t.text})}function x(e){let t=e.sessions.current();if(t?.server?.id)return t.server.id;let n=e.servers.list();for(let t of n)if(e.servers.get(t)?.builtin)return t;return n[0]??`sidecar`}function S(e){return e===`user`?`You`:e===`assistant`?`Assistant`:e===`shell`?`Command`:e===`title`?`Title`:e}var[C,w]=(0,n.createSignal)(``);function T(t){let r=t.ctx.ui,[o,y]=(0,n.createSignal)(t.initialQuery??``),[w,T]=(0,n.createSignal)(t.ctx.sessions.current()?.directory?`project`:`all`),[E,D]=(0,n.createSignal)(`all`),[O,k]=(0,n.createSignal)(`all`),[A,j]=(0,n.createSignal)(`smart`),[M,we]=(0,n.createSignal)(`updated`),[N,P]=(0,n.createSignal)(!1),[F,I]=(0,n.createSignal)(0),[L,R]=(0,n.createSignal)(0),[z,B]=(0,n.createSignal)(`sessions`),[V,H]=(0,n.createSignal)(!0),[Te,Ee]=(0,n.createSignal)(!1),[De,Oe]=(0,n.createSignal)(null),[ke,Ae]=(0,n.createSignal)(0),[U,je]=(0,n.createSignal)([]),[W,Me]=(0,n.createSignal)(null);(0,n.createEffect)(()=>{let e=C();e&&y(e)});let G=0,K,q=(0,n.createMemo)(()=>t.ctx.sessions.current()?.directory??``),Ne=(0,n.createMemo)(()=>t.ctx.appearance.mode());async function J(e=!1){let n=++G;e&&Ee(!0),H(!0),Oe(null);try{let r=await(t.ctx.sessions.current()?.server?.client??t.ctx.servers.get(x(t.ctx))?.client??t.ctx.client).rpc(i).query({query:o(),scope:w(),currentDirectory:q(),role:E(),datePreset:O(),mode:A(),sort:M(),limit:60,forceReload:e});if(n!==G)return;Ae(r.totalSessions),je(r.results),Me(r.parsed),I(e=>Math.max(0,Math.min(e,Math.max(0,r.results.length-1)))),R(0),e&&t.ctx.toast.show({variant:`success`,title:`Refreshed ${r.totalSessions} sessions`})}catch(e){if(n!==G)return;Oe(e instanceof Error?e.message:`Failed to query session index`)}finally{n===G&&(H(!1),Ee(!1))}}(0,n.createEffect)(()=>{o(),w(),E(),O(),A(),M(),q(),K&&clearTimeout(K),K=setTimeout(()=>{J(!1)},16)}),(0,n.onCleanup)(()=>{K&&clearTimeout(K)});let Y=(0,n.createMemo)(()=>U()[F()]??U()[0]),X=(0,n.createMemo)(()=>{let e=W(),t=e?[...e.terms,...e.fuzzyTerms]:[],n=Y()?.matches[L()]?.matchedTerm;return n&&!t.includes(n)&&t.push(n),t}),Z=(0,n.createMemo)(()=>{let e=0;return E()!==`all`&&e++,O()!==`all`&&e++,A()!==`smart`&&e++,e}),Pe=(0,n.createMemo)(()=>[{type:`group`,label:`Search Mode`,items:g.map(e=>({label:be[e],icon:A()===e?`check-small`:void 0,onSelect:()=>{j(e),I(0)}}))},{type:`separator`},{type:`group`,label:`Message Role`,items:m.map(e=>({label:xe[e],icon:E()===e?`check-small`:void 0,onSelect:()=>{D(e),I(0)}}))},{type:`separator`},{type:`group`,label:`Time Range`,items:h.map(e=>({label:_[e],icon:O()===e?`check-small`:void 0,onSelect:()=>{k(e),I(0)}}))},{type:`separator`},{label:`Reset filters`,disabled:Z()===0,onSelect:()=>{j(`smart`),D(`all`),k(`all`),I(0)}}]);function Fe(){T(e=>e===`project`?`all`:`project`),I(0)}function Ie(){D(e=>m[(m.indexOf(e)+1)%m.length]??`all`),I(0)}function Le(){k(e=>h[(h.indexOf(e)+1)%h.length]??`all`),I(0)}function Re(){j(e=>g[(g.indexOf(e)+1)%g.length]??`smart`),I(0)}function Q(e){if(!e)return;let n=x(t.ctx);t.ctx.tabs.open({server:n,id:e.id},{focus:!0}),t.onClose?.()}async function ze(e){e&&(await t.ctx.system.copy(e.id),t.ctx.toast.show({variant:`success`,title:`Copied session ID`,description:e.id}))}async function Be(e){if(!N()){P(!0);try{await(t.ctx.sessions.current()?.server?.client??t.ctx.servers.get(x(t.ctx))?.client??t.ctx.client).session.update({sessionID:e.id,archived:!1}),await J(!0)}catch(e){t.ctx.toast.show({variant:`error`,title:`Unable to unarchive session`,description:e instanceof Error?e.message:String(e)})}finally{P(!1)}}}function $(e){let t=o().trim();y(t?`${t} ${e}`:e)}function Ve(e){if((e.ctrlKey||e.altKey)&&!e.shiftKey){let t=e.key.toLowerCase();if(t===`p`){e.preventDefault(),Fe();return}if(t===`g`){e.preventDefault(),Ie();return}if(t===`t`){e.preventDefault(),Le();return}if(t===`r`){e.preventDefault(),Re();return}if(t===`l`){e.preventDefault(),J(!0);return}}if(e.key===`Tab`){e.preventDefault(),B(e=>e===`sessions`?`matches`:`sessions`);return}let t=U().length,n=Y()?.matches.length??0;e.key===`ArrowDown`?(e.preventDefault(),z()===`matches`&&n>0?R(e=>Math.min(n-1,e+1)):t>0&&(I(e=>Math.min(t-1,e+1)),R(0))):e.key===`ArrowUp`?(e.preventDefault(),z()===`matches`&&n>0?R(e=>Math.max(0,e-1)):t>0&&(I(e=>Math.max(0,e-1)),R(0))):e.key===`PageDown`?(e.preventDefault(),t>0&&(I(e=>Math.min(t-1,e+8)),R(0))):e.key===`PageUp`?(e.preventDefault(),t>0&&(I(e=>Math.max(0,e-8)),R(0))):e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q(Y()))}return(()=>{var i=f(),m=i.firstChild.firstChild,h=m.nextSibling.firstChild,g=h.firstChild.firstChild,x=g.firstChild,C=g.nextSibling,P=h.nextSibling,H=P.firstChild;return i.$$keydown=Ve,(0,e.insert)(m,(0,e.createComponent)(r.TextInput,{type:`search`,size:`large`,label:`Search session history`,get value(){return o()},onInput:e=>{y(e),I(0),R(0)},onSubmit:()=>Q(Y()),placeholder:`Search conversations, "exact phrase", fuzzy~, /regex/i, role:user, tool:shell...`,get invalid(){return!!W()?.regexError},autofocus:!0})),g.$$click=()=>{T(`project`),I(0)},(0,e.insert)(g,(0,e.createComponent)(r.Icon,{name:`folder`,size:`small`}),x),(0,e.insert)(x,(()=>{var t=(0,e.memo)(()=>!!q());return()=>t()?Ce(q()):`Project`})()),C.$$click=()=>{T(`all`),I(0)},(0,e.insert)(h,(0,e.createComponent)(r.Menu,{get label(){return`Sort: ${a[M()]}`},trigger:`button`,get items(){return Object.entries(a).map(([e,t])=>({label:t,icon:M()===e?`check-small`:void 0,onSelect:()=>{we(e),I(0)}}))}}),null),(0,e.insert)(h,(0,e.createComponent)(r.Menu,{get label(){return(0,e.memo)(()=>Z()>0)()?`Filters (${Z()})`:`Filters`},icon:`sliders`,trigger:`button`,get items(){return Pe()}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return A()!==`smart`},get children(){var t=s(),n=t.firstChild;return t.$$click=()=>j(`smart`),(0,e.insert)(n,()=>be[A()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return E()!==`all`},get children(){var t=c(),n=t.firstChild;return t.$$click=()=>D(`all`),(0,e.insert)(n,()=>xe[E()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return O()!==`all`},get children(){var t=l(),n=t.firstChild;return t.$$click=()=>k(`all`),(0,e.insert)(n,()=>_[O()]),(0,e.insert)(t,(0,e.createComponent)(r.Icon,{name:`close-small`,size:`small`}),null),t}}),null),(0,e.insert)(h,(0,e.createComponent)(n.Show,{get when(){return W()?.regexError},children:t=>(()=>{var n=ee();return(0,e.insert)(n,t),n})()}),null),(0,e.insert)(H,(0,e.createComponent)(n.Show,{get when(){return!V()},get fallback(){return(0,e.createComponent)(r.Loader,{size:`small`})},get children(){return[(0,e.memo)(()=>U().length),` of `,(0,e.memo)(()=>ke()),` sessions`]}})),(0,e.insert)(P,(0,e.createComponent)(r.Tooltip,{value:`Refresh index`,keys:[`Ctrl`,`L`],get children(){return(0,e.createComponent)(r.IconButton,{icon:`refresh`,label:`Refresh index`,variant:`ghost`,size:`small`,get busy(){return Te()},onClick:()=>void J(!0)})}}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return De()},children:t=>(()=>{var n=te(),r=n.firstChild.nextSibling;return(0,e.insert)(r,t),n})()}),null),(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return!De()},get children(){var i=d(),a=i.firstChild,s=a.firstChild,c=a.nextSibling;return(0,e.insert)(i,(0,e.createComponent)(n.Show,{get when(){return V()},get children(){return u()}}),a),a.$$click=()=>B(`sessions`),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return U().length>0},get fallback(){return(0,e.createComponent)(n.Show,{get when(){return!V()},get children(){var t=re(),r=t.firstChild.nextSibling;return(0,e.insert)(r,(0,e.createComponent)(n.Show,{get when(){return w()===`project`},fallback:`Try Fuzzy mode or fewer search terms.`,get children(){return[`No hits in this workspace. Switch to`,` `,(()=>{var e=ne();return e.$$click=Fe,e})(),` `,`to search everywhere.`]}})),t}})},get children(){return(0,e.createComponent)(n.For,{get each(){return U()},children:(t,r)=>{let i=()=>r()===F();return(()=>{var a=le(),s=a.firstChild,c=s.firstChild,l=c.nextSibling,u=s.nextSibling,d=u.firstChild,f=d.firstChild;return a.$$dblclick=()=>Q(t),a.$$click=()=>{I(r()),R(0),B(`sessions`)},(0,e.insert)(c,(0,e.createComponent)(b,{get text(){return t.title||`Untitled session`},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),(0,e.insert)(l,()=>v(t.timeUpdated)),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return t.bestSnippet},get children(){var n=ie();return(0,e.insert)(n,(0,e.createComponent)(b,{get text(){return t.bestSnippet},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),n}}),u),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return t.archived},get children(){return ae()}}),d),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return M()===`context`||M()===`tokens`},get children(){var n=oe(),r=n.firstChild;return(0,e.insert)(n,()=>M()===`context`?`Context`:`Total`,r),(0,e.insert)(n,()=>(M()===`context`?t.contextTokens:t.totalTokens)?.toLocaleString()??`Not recorded`,null),n}}),d),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return o().trim().length>0},get children(){var n=se();return(0,e.insert)(n,()=>t.matchBadge),n}}),d),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>w()===`all`)()&&t.directory},get children(){var n=ce();return(0,e.insert)(n,()=>Ce(t.directory)),n}}),d),(0,e.insert)(d,()=>t.entryCount,f),(0,e.effect)(()=>(0,e.className)(a,`ols-row ${i()?`ols-row--selected`:``}`)),a})()}})}})),c.$$click=()=>B(`matches`),(0,e.insert)(c,(0,e.createComponent)(n.Show,{get when(){return Y()},get fallback(){return ue()},children:i=>[(()=>{var t=fe(),a=t.firstChild,o=a.firstChild,s=o.nextSibling,c=s.firstChild,l=c.nextSibling.nextSibling,u=a.nextSibling;return(0,e.insert)(o,()=>i().title),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return i().archived},get children(){return de()}}),c),(0,e.insert)(c,()=>i().directory||`Global`),(0,e.insert)(l,()=>Se(i().timeUpdated)),(0,e.insert)(u,(0,e.createComponent)(n.Show,{get when(){return i().archived},get children(){return(0,e.createComponent)(r.Button,{size:`small`,get busy(){return N()},onClick:()=>void Be(i()),children:`Unarchive`})}}),null),(0,e.insert)(u,(0,e.createComponent)(r.Tooltip,{value:`Copy session ID`,get children(){return(0,e.createComponent)(r.IconButton,{icon:`copy`,label:`Copy session ID`,variant:`ghost`,size:`small`,onClick:()=>void ze(i())})}}),null),(0,e.insert)(u,(0,e.createComponent)(r.Button,{variant:`contrast`,size:`small`,icon:`square-arrow-top-right`,onClick:()=>Q(i()),children:`Open`}),null),t})(),(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>o().trim().length===0)()&&t.variant===`modal`},get children(){var e=pe(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.nextSibling;return t.$$click=()=>$(`role:user`),n.$$click=()=>$(`tool:shell`),r.$$click=()=>$(`in:title`),i.$$click=()=>$(`since:7d`),e}}),(()=>{var t=me();return(0,e.insert)(t,(0,e.createComponent)(n.Show,{get when(){return i().matches.length>0},get fallback(){return(()=>{var t=p();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return i().recentEntries},children:t=>(()=>{var r=ge(),a=r.firstChild,o=a.firstChild,s=o.nextSibling,c=a.nextSibling;return r.$$click=()=>Q(i()),(0,e.insert)(o,()=>S(t.role)),(0,e.insert)(a,(0,e.createComponent)(n.Show,{get when(){return t.toolName},get children(){var n=he();return(0,e.insert)(n,()=>t.toolName),n}}),s),(0,e.insert)(s,()=>v(t.timeCreated)),(0,e.insert)(c,()=>t.text),(0,e.effect)(()=>(0,e.className)(o,`ols-turn-author ols-turn-author--${t.role}`)),r})()})),t})()},get children(){var t=p();return(0,e.insert)(t,(0,e.createComponent)(n.For,{get each(){return i().matches},children:(t,r)=>{let a=()=>z()===`matches`&&r()===L();return(()=>{var o=ye(),s=o.firstChild,c=s.firstChild,l=c.nextSibling,u=s.nextSibling;return o.$$dblclick=()=>Q(i()),o.$$click=()=>{B(`matches`),R(r())},(0,e.insert)(c,()=>S(t.role)),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return(0,e.memo)(()=>t.kind===`tool`)()&&t.toolName},get children(){var n=he();return(0,e.insert)(n,()=>t.toolName),n}}),l),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return t.kind===`filepath`},get children(){return _e()}}),l),(0,e.insert)(s,(0,e.createComponent)(n.Show,{get when(){return t.kind===`fuzzy`},get children(){var n=ve();return n.firstChild,(0,e.insert)(n,()=>t.matchedTerm,null),n}}),l),(0,e.insert)(l,()=>v(t.timeCreated)),(0,e.insert)(u,(0,e.createComponent)(b,{get text(){return t.snippet},get terms(){return X()},get regexPattern(){return W()?.regexPattern},get regexFlags(){return W()?.regexFlags}})),(0,e.effect)(n=>{var r=`ols-turn ${a()?`ols-turn--selected`:``}`,i=`ols-turn-author ols-turn-author--${t.role}`;return r!==n.e&&(0,e.className)(o,n.e=r),i!==n.t&&(0,e.className)(c,n.t=i),n},{e:void 0,t:void 0}),o})()}})),t}})),t})()]})),(0,e.effect)(t=>{var n=`ols-column ols-column--list ${z()===`sessions`?`ols-column--active`:``}`,r=`ols-column ols-column--detail ${z()===`matches`?`ols-column--active`:``}`;return n!==t.e&&(0,e.className)(a,t.e=n),r!==t.t&&(0,e.className)(c,t.t=r),t},{e:void 0,t:void 0}),i}}),null),(0,e.effect)(n=>{var r=`ols-root ols-root--${t.variant}`,a=Ne(),o=`ols-segment-btn ${w()===`project`?`ols-segment-btn--active`:``}`,s=q()?`Current project (${q()})`:`Current project`,c=`ols-segment-btn ${w()===`all`?`ols-segment-btn--active`:``}`;return r!==n.e&&(0,e.className)(i,n.e=r),a!==n.t&&(0,e.setAttribute)(i,`data-scheme`,n.t=a),o!==n.a&&(0,e.className)(g,n.a=o),s!==n.o&&(0,e.setAttribute)(g,`title`,n.o=s),c!==n.i&&(0,e.className)(C,n.i=c),n},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}var E=t.Plugin.define({i18n:{en:{"search.title":`Search`,"search.command":`Search session history...`,"search.panel":`Search`}},setup(i){let a=i.ui;i.add(t.Style,r);let o;function s(t=``){w(t);let r=i.sessions.current();if(r){o?.close();try{i.layout.open(`${i.id}:search`,r)}catch{}}else{if(o)return;o=i.dialogs.open(r=>((0,n.onCleanup)(()=>{o=void 0}),(0,e.createComponent)(a.Dialog,{title:`Search`,size:`x-large`,get children(){return(0,e.createComponent)(T,{ctx:i,variant:`modal`,initialQuery:t,get onClose(){return r.close}})}})))}}if(i.add(t.Command,()=>({id:`search`,title:`Search session history...`,description:`Full-text, fuzzy, regex, tool, and file search across all session conversations`,keywords:`find history messages conversation regex fuzzy search grep`,group:`Session`,section:`session`,bind:`mod+shift+f`,slash:{name:`search`,arguments:!0},featured:!0,run(e){s(typeof e==`string`?e:``)}})),i.add(t.Command,()=>({id:`search-panel`,title:`Toggle session search panel`,description:`Open or close the Session Search side panel`,keywords:`panel sidebar search history`,group:`Session`,section:`session`,bind:`mod+alt+f`,run(){let e=i.sessions.current();e?i.layout.toggle(`${i.id}:search`,e):s(``)}})),typeof document<`u`){let e=e=>{let t=e.closest(`button`);if(!t||t.closest(`.ols-root`))return!1;if(t.getAttribute(`data-action`)===`vertical-tabs-search`)return!0;if(!t.closest(`[data-slot="titlebar-v2"]`)||t.closest(`[data-titlebar-plugin-item]`))return!1;if((t.getAttribute(`aria-label`)??``).toLowerCase().includes(`search`))return!0;let n=t.querySelector(`svg[data-slot="icon-svg"] use`);return(n?.getAttribute(`href`)??n?.getAttribute(`xlink:href`)??``).includes(`magnifying-glass`)},t=t=>{let n=t.target;if(!(n instanceof Element))return;if(e(n)){t.preventDefault(),t.stopPropagation(),s(``);return}let r=n.closest(`[data-component="home-session-search"]`);if(r){t.preventDefault(),t.stopPropagation();let e=r.querySelector(`input`),n=e instanceof HTMLInputElement?e.value:``;e instanceof HTMLElement&&e.blur(),s(n)}},r=e=>{let t=e.target;if(!(t instanceof Element)||!t.closest(`[data-component="home-session-search"]`))return;let n=t instanceof HTMLInputElement?t.value:``;t instanceof HTMLElement&&t.blur(),s(n)};document.addEventListener(`click`,t,!0),document.addEventListener(`focusin`,r,!0);let i=()=>{let e=document.querySelectorAll(`button[data-action="vertical-tabs-search"]`);for(let t of e){for(let e of t.querySelectorAll(`span`))(e.textContent?.trim().toLowerCase()??``)===`search sessions`?(e.textContent=`Search`,e.classList.add(`whitespace-nowrap`)):(e.classList.contains(`ms-auto`)||e.querySelector(`bdi, kbd`))&&e.remove();t.getAttribute(`aria-label`)?.toLowerCase()===`search sessions`&&t.setAttribute(`aria-label`,`Search`),t.getAttribute(`title`)?.toLowerCase()===`search sessions`&&t.setAttribute(`title`,`Search`)}};i(),setTimeout(i,50);let a=new WeakSet,o=new MutationObserver(()=>{i();let e=document.querySelector(`.command-palette input[placeholder="Search sessions"], .command-palette-dialog input[placeholder="Search sessions..."]`);if(e&&!a.has(e)){a.add(e);let t=e.value||``;e.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,code:`Escape`,bubbles:!0,cancelable:!0})),s(t)}});document.body&&o.observe(document.body,{childList:!0,subtree:!0}),(0,n.onCleanup)(()=>{document.removeEventListener(`click`,t,!0),document.removeEventListener(`focusin`,r,!0),o.disconnect()})}let c={id:`search`,get title(){return i.t(`search.panel`)},closable:`compact`};i.add(t.Panel,{id:`search`,region:`side`,list:e=>e.open.includes(`search`)?[c]:[],render:()=>(0,e.createComponent)(T,{ctx:i,variant:`panel`})}),i.add(t.MenuItem,()=>{let e=i.sessions.current();return{menu:`session.panel`,id:`search`,title:`Search`,description:`Search conversation history`,icon:`magnifying-glass`,keybind:`${i.id}.search-panel`,opened:!!e&&i.layout.state(`${i.id}:search`,e)!==`closed`,run:()=>{let e=i.sessions.current();e?i.layout.open(`${i.id}:search`,e):s(``)}}})}});(0,e.delegateEvents)([`keydown`,`click`,`dblclick`]),exports.default=E;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nandoblanco/opencode-local-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"dist/*.cjs",
|
|
26
26
|
"assets/screenshot.png",
|
|
27
27
|
"README.md",
|
|
28
|
+
"CHANGELOG.md",
|
|
28
29
|
"LICENSE"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
package/src/gui.css
CHANGED
|
@@ -211,6 +211,7 @@
|
|
|
211
211
|
|
|
212
212
|
/* Split layout */
|
|
213
213
|
.ols-split {
|
|
214
|
+
position: relative;
|
|
214
215
|
display: grid;
|
|
215
216
|
grid-template-columns: minmax(260px, 38%) minmax(0, 1fr);
|
|
216
217
|
flex: 1;
|
|
@@ -218,6 +219,51 @@
|
|
|
218
219
|
overflow: hidden;
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
.ols-loading-center {
|
|
223
|
+
position: absolute;
|
|
224
|
+
inset: 0;
|
|
225
|
+
z-index: 20;
|
|
226
|
+
display: flex;
|
|
227
|
+
align-items: center;
|
|
228
|
+
justify-content: center;
|
|
229
|
+
background: rgba(14, 14, 17, 0.42);
|
|
230
|
+
backdrop-filter: blur(1.5px);
|
|
231
|
+
pointer-events: none;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.ols-root[data-scheme="light"] .ols-loading-center {
|
|
235
|
+
background: rgba(246, 246, 248, 0.52);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.ols-loading-pill {
|
|
239
|
+
display: inline-flex;
|
|
240
|
+
align-items: center;
|
|
241
|
+
gap: 8px;
|
|
242
|
+
padding: 8px 14px;
|
|
243
|
+
border-radius: 999px;
|
|
244
|
+
background: var(--ols-bg-elevated);
|
|
245
|
+
border: 1px solid var(--ols-border-strong);
|
|
246
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
|
|
247
|
+
color: var(--ols-text);
|
|
248
|
+
font-size: 12px;
|
|
249
|
+
font-weight: 530;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.ols-spinner {
|
|
253
|
+
width: 14px;
|
|
254
|
+
height: 14px;
|
|
255
|
+
border-radius: 50%;
|
|
256
|
+
border: 2px solid var(--ols-border-strong);
|
|
257
|
+
border-top-color: var(--ols-focus);
|
|
258
|
+
animation: ols-spin 0.65s linear infinite;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@keyframes ols-spin {
|
|
262
|
+
to {
|
|
263
|
+
transform: rotate(360deg);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
221
267
|
.ols-root--panel .ols-split {
|
|
222
268
|
grid-template-columns: 1fr;
|
|
223
269
|
grid-template-rows: minmax(170px, 44%) minmax(0, 1fr);
|
package/src/gui.tsx
CHANGED
|
@@ -27,7 +27,9 @@ import type {
|
|
|
27
27
|
RoleFilter,
|
|
28
28
|
ScopeFilter,
|
|
29
29
|
SearchMode,
|
|
30
|
+
SearchSort,
|
|
30
31
|
} from "./search.ts"
|
|
32
|
+
import { SEARCH_SORT_LABELS } from "./sort.ts"
|
|
31
33
|
|
|
32
34
|
const ROLE_ORDER: RoleFilter[] = ["all", "user", "assistant", "shell"]
|
|
33
35
|
const DATE_ORDER: DatePreset[] = ["all", "today", "yesterday", "7d", "30d"]
|
|
@@ -231,6 +233,8 @@ function SearchSurface(props: {
|
|
|
231
233
|
const [role, setRole] = createSignal<RoleFilter>("all")
|
|
232
234
|
const [datePreset, setDatePreset] = createSignal<DatePreset>("all")
|
|
233
235
|
const [mode, setMode] = createSignal<SearchMode>("smart")
|
|
236
|
+
const [sort, setSort] = createSignal<SearchSort>("updated")
|
|
237
|
+
const [restoring, setRestoring] = createSignal(false)
|
|
234
238
|
const [selectedIndex, setSelectedIndex] = createSignal(0)
|
|
235
239
|
const [selectedMatchIdx, setSelectedMatchIdx] = createSignal(0)
|
|
236
240
|
const [activePane, setActivePane] = createSignal<"sessions" | "matches">(
|
|
@@ -278,6 +282,7 @@ function SearchSurface(props: {
|
|
|
278
282
|
role: role(),
|
|
279
283
|
datePreset: datePreset(),
|
|
280
284
|
mode: mode(),
|
|
285
|
+
sort: sort(),
|
|
281
286
|
limit: 60,
|
|
282
287
|
forceReload,
|
|
283
288
|
})
|
|
@@ -314,12 +319,13 @@ function SearchSurface(props: {
|
|
|
314
319
|
void role()
|
|
315
320
|
void datePreset()
|
|
316
321
|
void mode()
|
|
322
|
+
void sort()
|
|
317
323
|
void currentDirectory()
|
|
318
324
|
|
|
319
325
|
if (debounceTimer) clearTimeout(debounceTimer)
|
|
320
326
|
debounceTimer = setTimeout(() => {
|
|
321
327
|
void runQuery(false)
|
|
322
|
-
},
|
|
328
|
+
}, 16)
|
|
323
329
|
})
|
|
324
330
|
|
|
325
331
|
onCleanup(() => {
|
|
@@ -444,6 +450,21 @@ function SearchSurface(props: {
|
|
|
444
450
|
})
|
|
445
451
|
}
|
|
446
452
|
|
|
453
|
+
async function unarchiveSession(session: RpcSessionMatch) {
|
|
454
|
+
if (restoring()) return
|
|
455
|
+
setRestoring(true)
|
|
456
|
+
try {
|
|
457
|
+
const client = props.ctx.sessions.current()?.server?.client ??
|
|
458
|
+
props.ctx.servers.get(resolveServerId(props.ctx))?.client ?? props.ctx.client
|
|
459
|
+
await client.session.update({ sessionID: session.id, archived: false })
|
|
460
|
+
await runQuery(true)
|
|
461
|
+
} catch (err) {
|
|
462
|
+
props.ctx.toast.show({ variant: "error", title: "Unable to unarchive session", description: err instanceof Error ? err.message : String(err) })
|
|
463
|
+
} finally {
|
|
464
|
+
setRestoring(false)
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
447
468
|
function appendSyntaxToken(token: string) {
|
|
448
469
|
const cur = query().trim()
|
|
449
470
|
setQuery(cur ? `${cur} ${token}` : token)
|
|
@@ -598,6 +619,16 @@ function SearchSurface(props: {
|
|
|
598
619
|
</button>
|
|
599
620
|
</div>
|
|
600
621
|
|
|
622
|
+
<ui.Menu
|
|
623
|
+
label={`Sort: ${SEARCH_SORT_LABELS[sort()]}`}
|
|
624
|
+
trigger="button"
|
|
625
|
+
items={(Object.entries(SEARCH_SORT_LABELS) as [SearchSort, string][]).map(([value, label]) => ({
|
|
626
|
+
label,
|
|
627
|
+
icon: sort() === value ? "check-small" : undefined,
|
|
628
|
+
onSelect: () => { setSort(value); setSelectedIndex(0) },
|
|
629
|
+
}))}
|
|
630
|
+
/>
|
|
631
|
+
|
|
601
632
|
<ui.Menu
|
|
602
633
|
label={
|
|
603
634
|
activeFilterCount() > 0
|
|
@@ -682,6 +713,14 @@ function SearchSurface(props: {
|
|
|
682
713
|
|
|
683
714
|
<Show when={!errorMsg()}>
|
|
684
715
|
<div class="ols-split">
|
|
716
|
+
<Show when={loading()}>
|
|
717
|
+
<div class="ols-loading-center" role="status" aria-live="polite">
|
|
718
|
+
<div class="ols-loading-pill">
|
|
719
|
+
<span class="ols-spinner" aria-hidden="true" />
|
|
720
|
+
<span>Searching...</span>
|
|
721
|
+
</div>
|
|
722
|
+
</div>
|
|
723
|
+
</Show>
|
|
685
724
|
<div
|
|
686
725
|
class={`ols-column ols-column--list ${
|
|
687
726
|
activePane() === "sessions" ? "ols-column--active" : ""
|
|
@@ -692,25 +731,27 @@ function SearchSurface(props: {
|
|
|
692
731
|
<Show
|
|
693
732
|
when={results().length > 0}
|
|
694
733
|
fallback={
|
|
695
|
-
<
|
|
696
|
-
<div class="ols-empty
|
|
697
|
-
|
|
698
|
-
<
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
No hits in this workspace. Switch to{" "}
|
|
703
|
-
<button
|
|
704
|
-
type="button"
|
|
705
|
-
class="ols-inline-link"
|
|
706
|
-
onClick={toggleScope}
|
|
734
|
+
<Show when={!loading()}>
|
|
735
|
+
<div class="ols-empty">
|
|
736
|
+
<div class="ols-empty-title">No matching sessions</div>
|
|
737
|
+
<div class="ols-empty-sub">
|
|
738
|
+
<Show
|
|
739
|
+
when={scope() === "project"}
|
|
740
|
+
fallback="Try Fuzzy mode or fewer search terms."
|
|
707
741
|
>
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
742
|
+
No hits in this workspace. Switch to{" "}
|
|
743
|
+
<button
|
|
744
|
+
type="button"
|
|
745
|
+
class="ols-inline-link"
|
|
746
|
+
onClick={toggleScope}
|
|
747
|
+
>
|
|
748
|
+
All workspaces
|
|
749
|
+
</button>{" "}
|
|
750
|
+
to search everywhere.
|
|
751
|
+
</Show>
|
|
752
|
+
</div>
|
|
712
753
|
</div>
|
|
713
|
-
</
|
|
754
|
+
</Show>
|
|
714
755
|
}
|
|
715
756
|
>
|
|
716
757
|
<For each={results()}>
|
|
@@ -755,6 +796,10 @@ function SearchSurface(props: {
|
|
|
755
796
|
</Show>
|
|
756
797
|
|
|
757
798
|
<div class="ols-row-meta">
|
|
799
|
+
<Show when={item.archived}><span class="ols-row-hit-badge">Archived</span></Show>
|
|
800
|
+
<Show when={sort() === "context" || sort() === "tokens"}>
|
|
801
|
+
<span>{sort() === "context" ? "Context" : "Total"}: {(sort() === "context" ? item.contextTokens : item.totalTokens)?.toLocaleString() ?? "Not recorded"}</span>
|
|
802
|
+
</Show>
|
|
758
803
|
<Show when={query().trim().length > 0}>
|
|
759
804
|
<span class="ols-row-hit-badge">
|
|
760
805
|
{item.matchBadge}
|
|
@@ -797,6 +842,7 @@ function SearchSurface(props: {
|
|
|
797
842
|
<div class="ols-detail-heading">
|
|
798
843
|
<div class="ols-detail-title">{session().title}</div>
|
|
799
844
|
<div class="ols-detail-meta">
|
|
845
|
+
<Show when={session().archived}><span>Archived</span></Show>
|
|
800
846
|
<span>{session().directory || "Global"}</span>
|
|
801
847
|
<span>·</span>
|
|
802
848
|
<span>{formatDateFull(session().timeUpdated)}</span>
|
|
@@ -804,6 +850,9 @@ function SearchSurface(props: {
|
|
|
804
850
|
</div>
|
|
805
851
|
|
|
806
852
|
<div class="ols-detail-actions">
|
|
853
|
+
<Show when={session().archived}>
|
|
854
|
+
<ui.Button size="small" busy={restoring()} onClick={() => void unarchiveSession(session())}>Unarchive</ui.Button>
|
|
855
|
+
</Show>
|
|
807
856
|
<ui.Tooltip value="Copy session ID">
|
|
808
857
|
<ui.IconButton
|
|
809
858
|
icon="copy"
|
|
@@ -964,9 +1013,9 @@ function SearchSurface(props: {
|
|
|
964
1013
|
export default Plugin.define({
|
|
965
1014
|
i18n: {
|
|
966
1015
|
en: {
|
|
967
|
-
"search.title": "Search
|
|
1016
|
+
"search.title": "Search",
|
|
968
1017
|
"search.command": "Search session history...",
|
|
969
|
-
"search.panel": "
|
|
1018
|
+
"search.panel": "Search",
|
|
970
1019
|
},
|
|
971
1020
|
},
|
|
972
1021
|
setup(ctx) {
|
|
@@ -984,7 +1033,7 @@ export default Plugin.define({
|
|
|
984
1033
|
searchFallbackDialog = ctx.dialogs.open((dialog) => {
|
|
985
1034
|
onCleanup(() => { searchFallbackDialog = undefined })
|
|
986
1035
|
return (
|
|
987
|
-
<ui.Dialog title="Search
|
|
1036
|
+
<ui.Dialog title="Search" size="x-large">
|
|
988
1037
|
<SearchSurface ctx={ctx} variant="modal" initialQuery={initialQuery} onClose={dialog.close} />
|
|
989
1038
|
</ui.Dialog>
|
|
990
1039
|
)
|
|
@@ -1105,8 +1154,35 @@ export default Plugin.define({
|
|
|
1105
1154
|
document.addEventListener("click", handleCaptureClick, true)
|
|
1106
1155
|
document.addEventListener("focusin", handleCaptureFocusIn, true)
|
|
1107
1156
|
|
|
1157
|
+
const syncBuiltinSearchButtonLabel = () => {
|
|
1158
|
+
const buttons = document.querySelectorAll<HTMLButtonElement>(
|
|
1159
|
+
'button[data-action="vertical-tabs-search"]',
|
|
1160
|
+
)
|
|
1161
|
+
for (const btn of buttons) {
|
|
1162
|
+
for (const span of btn.querySelectorAll("span")) {
|
|
1163
|
+
const txt = span.textContent?.trim().toLowerCase() ?? ""
|
|
1164
|
+
if (txt === "search sessions") {
|
|
1165
|
+
span.textContent = "Search"
|
|
1166
|
+
span.classList.add("whitespace-nowrap")
|
|
1167
|
+
} else if (span.classList.contains("ms-auto") || span.querySelector("bdi, kbd")) {
|
|
1168
|
+
span.remove()
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
if (btn.getAttribute("aria-label")?.toLowerCase() === "search sessions") {
|
|
1172
|
+
btn.setAttribute("aria-label", "Search")
|
|
1173
|
+
}
|
|
1174
|
+
if (btn.getAttribute("title")?.toLowerCase() === "search sessions") {
|
|
1175
|
+
btn.setAttribute("title", "Search")
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
syncBuiltinSearchButtonLabel()
|
|
1181
|
+
setTimeout(syncBuiltinSearchButtonLabel, 50)
|
|
1182
|
+
|
|
1108
1183
|
const redirectedInputs = new WeakSet<HTMLInputElement>()
|
|
1109
1184
|
const observer = new MutationObserver(() => {
|
|
1185
|
+
syncBuiltinSearchButtonLabel()
|
|
1110
1186
|
const builtinInput = document.querySelector<HTMLInputElement>(
|
|
1111
1187
|
'.command-palette input[placeholder="Search sessions"], .command-palette-dialog input[placeholder="Search sessions..."]',
|
|
1112
1188
|
)
|
|
@@ -1153,7 +1229,7 @@ export default Plugin.define({
|
|
|
1153
1229
|
return {
|
|
1154
1230
|
menu: "session.panel",
|
|
1155
1231
|
id: "search",
|
|
1156
|
-
title: "
|
|
1232
|
+
title: "Search",
|
|
1157
1233
|
description: "Search conversation history",
|
|
1158
1234
|
icon: "magnifying-glass",
|
|
1159
1235
|
keybind: `${ctx.id}.search-panel`,
|
package/src/rpc.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
ScopeFilter,
|
|
6
6
|
SearchEntryMatch,
|
|
7
7
|
SearchMode,
|
|
8
|
+
SearchSort,
|
|
8
9
|
} from "./search.ts"
|
|
9
10
|
|
|
10
11
|
export interface RpcPreviewEntry {
|
|
@@ -25,6 +26,9 @@ export interface RpcSessionMatch {
|
|
|
25
26
|
directoryNorm: string
|
|
26
27
|
timeCreated: number
|
|
27
28
|
timeUpdated: number
|
|
29
|
+
archived?: boolean
|
|
30
|
+
contextTokens?: number
|
|
31
|
+
totalTokens?: number
|
|
28
32
|
tools: string[]
|
|
29
33
|
files: string[]
|
|
30
34
|
entryCount: number
|
|
@@ -55,6 +59,7 @@ export interface RpcParsedQueryInfo {
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
export interface SearchQueryInput {
|
|
62
|
+
sort?: SearchSort
|
|
58
63
|
query: string
|
|
59
64
|
scope?: ScopeFilter
|
|
60
65
|
currentDirectory?: string
|
|
@@ -77,6 +82,7 @@ const searchInputSchema = {
|
|
|
77
82
|
type: "object",
|
|
78
83
|
properties: {
|
|
79
84
|
query: { type: "string" },
|
|
85
|
+
sort: { type: "string", enum: ["updated", "relevance", "newest", "oldest", "title", "context", "tokens"] },
|
|
80
86
|
scope: { type: "string", enum: ["all", "project"] },
|
|
81
87
|
currentDirectory: { type: "string" },
|
|
82
88
|
role: { type: "string", enum: ["all", "user", "assistant", "shell"] },
|
package/src/search.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type SearchMode = "smart" | "fuzzy" | "regex";
|
|
|
8
8
|
export type RoleFilter = "all" | "user" | "assistant" | "shell";
|
|
9
9
|
export type ScopeFilter = "all" | "project";
|
|
10
10
|
export type DatePreset = "all" | "today" | "yesterday" | "7d" | "30d";
|
|
11
|
+
import type { SearchSort } from "./sort.ts";
|
|
12
|
+
export { SEARCH_SORT_LABELS, type SearchSort } from "./sort.ts";
|
|
11
13
|
|
|
12
14
|
export interface SearchEntry {
|
|
13
15
|
id: string;
|
|
@@ -29,6 +31,9 @@ export interface IndexedSession {
|
|
|
29
31
|
directoryNorm: string;
|
|
30
32
|
timeCreated: number;
|
|
31
33
|
timeUpdated: number;
|
|
34
|
+
archived?: boolean;
|
|
35
|
+
contextTokens?: number;
|
|
36
|
+
totalTokens?: number;
|
|
32
37
|
tools: string[];
|
|
33
38
|
files: string[];
|
|
34
39
|
entries: SearchEntry[];
|
|
@@ -63,6 +68,7 @@ export interface SearchSessionMatch {
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
export interface SearchOptions {
|
|
71
|
+
sort?: SearchSort;
|
|
66
72
|
scope?: ScopeFilter;
|
|
67
73
|
currentDirectory?: string;
|
|
68
74
|
role?: RoleFilter;
|
|
@@ -92,9 +98,13 @@ interface SqliteRowsDriver {
|
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
let cachedIndex: SessionIndex | null = null;
|
|
101
|
+
let cachedSessionsMap: Map<string, IndexedSession> | null = null;
|
|
102
|
+
let cachedSessionFiles: Map<string, Set<string>> | null = null;
|
|
103
|
+
let cachedSessionTools: Map<string, Set<string>> | null = null;
|
|
104
|
+
let cachedMaxUpdated = 0;
|
|
95
105
|
let cachedIndexEvictTimer: ReturnType<typeof setTimeout> | null = null;
|
|
96
|
-
const INDEX_TTL_MS =
|
|
97
|
-
const INDEX_IDLE_EVICT_MS =
|
|
106
|
+
const INDEX_TTL_MS = 2000; // Fast in-memory hit window before incremental check
|
|
107
|
+
const INDEX_IDLE_EVICT_MS = 30 * 60_000; // Keep warm index in memory for 30m idle
|
|
98
108
|
const MAX_INDEXED_TEXT_CHARS = 4000;
|
|
99
109
|
|
|
100
110
|
function capIndexedText(text: string): string {
|
|
@@ -107,6 +117,10 @@ function scheduleIndexIdleEviction(): void {
|
|
|
107
117
|
}
|
|
108
118
|
cachedIndexEvictTimer = setTimeout(() => {
|
|
109
119
|
cachedIndex = null;
|
|
120
|
+
cachedSessionsMap = null;
|
|
121
|
+
cachedSessionFiles = null;
|
|
122
|
+
cachedSessionTools = null;
|
|
123
|
+
cachedMaxUpdated = 0;
|
|
110
124
|
cachedIndexEvictTimer = null;
|
|
111
125
|
}, INDEX_IDLE_EVICT_MS);
|
|
112
126
|
cachedIndexEvictTimer.unref?.();
|
|
@@ -240,16 +254,30 @@ function stringifyToolInput(input: unknown): string {
|
|
|
240
254
|
export async function loadSessionIndex(force = false, customDbPath?: string): Promise<SessionIndex> {
|
|
241
255
|
const dbPath = resolveDbPath(customDbPath);
|
|
242
256
|
if (!force && cachedIndex && cachedIndex.dbPath === dbPath && Date.now() - cachedIndex.loadedAt < INDEX_TTL_MS) {
|
|
257
|
+
scheduleIndexIdleEviction();
|
|
243
258
|
return cachedIndex;
|
|
244
259
|
}
|
|
245
260
|
if (!existsSync(dbPath)) {
|
|
246
261
|
return { dbPath, loadedAt: Date.now(), sessions: [] };
|
|
247
262
|
}
|
|
248
263
|
|
|
264
|
+
const canIncremental =
|
|
265
|
+
!force &&
|
|
266
|
+
cachedIndex !== null &&
|
|
267
|
+
cachedIndex.dbPath === dbPath &&
|
|
268
|
+
cachedSessionsMap !== null &&
|
|
269
|
+
cachedSessionFiles !== null &&
|
|
270
|
+
cachedSessionTools !== null;
|
|
271
|
+
|
|
272
|
+
if (!canIncremental) {
|
|
273
|
+
cachedMaxUpdated = 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
249
276
|
const db = await openReadOnlyDb(dbPath);
|
|
250
|
-
const sessionsMap = new Map<string, IndexedSession>();
|
|
251
|
-
const sessionFiles = new Map<string, Set<string>>();
|
|
252
|
-
const sessionTools = new Map<string, Set<string>>();
|
|
277
|
+
const sessionsMap = canIncremental ? cachedSessionsMap! : new Map<string, IndexedSession>();
|
|
278
|
+
const sessionFiles = canIncremental ? cachedSessionFiles! : new Map<string, Set<string>>();
|
|
279
|
+
const sessionTools = canIncremental ? cachedSessionTools! : new Map<string, Set<string>>();
|
|
280
|
+
const changedIds: string[] = [];
|
|
253
281
|
|
|
254
282
|
try {
|
|
255
283
|
const tables = new Set(
|
|
@@ -268,21 +296,35 @@ export async function loadSessionIndex(force = false, customDbPath?: string): Pr
|
|
|
268
296
|
: v2Cols.has("workspace_directory")
|
|
269
297
|
? "COALESCE(workspace_directory, root_directory, '')"
|
|
270
298
|
: "''";
|
|
271
|
-
const
|
|
299
|
+
const archiveExpr = v2Cols.has("time_archived") ? "time_archived" : "NULL";
|
|
300
|
+
|
|
301
|
+
const v2Sessions = canIncremental
|
|
302
|
+
? db.all(
|
|
303
|
+
`SELECT id, title, ${dirExpr} AS directory, time_created, time_updated, ${archiveExpr} AS time_archived
|
|
304
|
+
FROM session_v2
|
|
305
|
+
WHERE time_updated > ?
|
|
306
|
+
ORDER BY time_updated DESC`,
|
|
307
|
+
cachedMaxUpdated
|
|
308
|
+
)
|
|
309
|
+
: db.all(`
|
|
310
|
+
SELECT id, title, ${dirExpr} AS directory, time_created, time_updated, ${archiveExpr} AS time_archived
|
|
311
|
+
FROM session_v2
|
|
312
|
+
ORDER BY time_updated DESC
|
|
313
|
+
`);
|
|
272
314
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
LIMIT 800
|
|
279
|
-
`);
|
|
315
|
+
if (canIncremental && v2Sessions.length === 0) {
|
|
316
|
+
cachedIndex!.loadedAt = Date.now();
|
|
317
|
+
scheduleIndexIdleEviction();
|
|
318
|
+
return cachedIndex!;
|
|
319
|
+
}
|
|
280
320
|
|
|
281
321
|
for (const row of v2Sessions) {
|
|
282
322
|
const id = String(row.id || "");
|
|
283
323
|
if (!id) continue;
|
|
284
324
|
const title = String(row.title || "(untitled session)");
|
|
285
325
|
const directory = String(row.directory || "");
|
|
326
|
+
const timeUpdated = Number(row.time_updated || 0);
|
|
327
|
+
if (timeUpdated > cachedMaxUpdated) cachedMaxUpdated = timeUpdated;
|
|
286
328
|
sessionsMap.set(id, {
|
|
287
329
|
id,
|
|
288
330
|
title,
|
|
@@ -290,43 +332,75 @@ export async function loadSessionIndex(force = false, customDbPath?: string): Pr
|
|
|
290
332
|
directory,
|
|
291
333
|
directoryNorm: normalizePath(directory),
|
|
292
334
|
timeCreated: Number(row.time_created || 0),
|
|
293
|
-
timeUpdated
|
|
335
|
+
timeUpdated,
|
|
336
|
+
archived: row.time_archived != null,
|
|
294
337
|
tools: [],
|
|
295
338
|
files: [],
|
|
296
339
|
entries: [],
|
|
297
340
|
});
|
|
298
341
|
sessionFiles.set(id, new Set());
|
|
299
342
|
sessionTools.set(id, new Set());
|
|
343
|
+
changedIds.push(id);
|
|
300
344
|
}
|
|
301
345
|
|
|
302
346
|
if (tables.has("session_message") && sessionsMap.size > 0) {
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
347
|
+
const targetIds = canIncremental ? changedIds : null;
|
|
348
|
+
const idFilterSql =
|
|
349
|
+
targetIds && targetIds.length > 0
|
|
350
|
+
? ` AND session_id IN (${targetIds.map(() => "?").join(",")})`
|
|
351
|
+
: "";
|
|
352
|
+
const idJoinFilterSql =
|
|
353
|
+
targetIds && targetIds.length > 0
|
|
354
|
+
? ` AND m.session_id IN (${targetIds.map(() => "?").join(",")})`
|
|
355
|
+
: "";
|
|
356
|
+
const idParams = targetIds && targetIds.length > 0 ? targetIds : [];
|
|
357
|
+
|
|
358
|
+
const msgWhere = `WHERE m.type IN ('user', 'assistant', 'shell')${idJoinFilterSql}`;
|
|
359
|
+
// Usage is read across assistant messages for loaded/updated sessions.
|
|
360
|
+
const usageRows = db.all(
|
|
361
|
+
`SELECT session_id, time_created, id, json_extract(data, '$.tokens') AS tokens
|
|
362
|
+
FROM session_message
|
|
363
|
+
WHERE type = 'assistant' AND json_valid(data)
|
|
364
|
+
AND json_type(data, '$.tokens') = 'object'${idFilterSql}
|
|
365
|
+
ORDER BY time_created ASC, id ASC`,
|
|
366
|
+
...idParams
|
|
367
|
+
);
|
|
368
|
+
for (const row of usageRows) {
|
|
369
|
+
const session = sessionsMap.get(String(row.session_id));
|
|
370
|
+
if (!session) continue;
|
|
371
|
+
const tokens = JSON.parse(String(row.tokens)) as {
|
|
372
|
+
input: number; output: number; reasoning: number; cache: { read: number; write: number };
|
|
373
|
+
};
|
|
374
|
+
const input = tokens.input + tokens.cache.read + tokens.cache.write;
|
|
375
|
+
session.contextTokens = input;
|
|
376
|
+
session.totalTokens = (session.totalTokens ?? 0) + input + tokens.output + tokens.reasoning;
|
|
377
|
+
}
|
|
306
378
|
let v2Messages: Record<string, unknown>[];
|
|
307
379
|
try {
|
|
308
|
-
v2Messages = db.all(
|
|
309
|
-
SELECT id, session_id, type, time_created, data
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
380
|
+
v2Messages = db.all(
|
|
381
|
+
`SELECT id, session_id, type, time_created, data
|
|
382
|
+
FROM (
|
|
383
|
+
SELECT m.id, m.session_id, m.type, m.time_created, m.data,
|
|
384
|
+
ROW_NUMBER() OVER (PARTITION BY m.session_id ORDER BY m.time_created DESC) AS rn
|
|
385
|
+
FROM session_message m
|
|
386
|
+
JOIN session_v2 s ON s.id = m.session_id
|
|
387
|
+
${msgWhere}
|
|
388
|
+
)
|
|
389
|
+
WHERE rn <= 250
|
|
390
|
+
ORDER BY time_created DESC
|
|
391
|
+
LIMIT 30000`,
|
|
392
|
+
...idParams
|
|
393
|
+
);
|
|
321
394
|
} catch {
|
|
322
|
-
v2Messages = db.all(
|
|
323
|
-
SELECT m.id, m.session_id, m.type, m.time_created, m.data
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
395
|
+
v2Messages = db.all(
|
|
396
|
+
`SELECT m.id, m.session_id, m.type, m.time_created, m.data
|
|
397
|
+
FROM session_message m
|
|
398
|
+
JOIN session_v2 s ON s.id = m.session_id
|
|
399
|
+
${msgWhere}
|
|
400
|
+
ORDER BY m.time_created DESC
|
|
401
|
+
LIMIT 18000`,
|
|
402
|
+
...idParams
|
|
403
|
+
);
|
|
330
404
|
}
|
|
331
405
|
|
|
332
406
|
for (const row of v2Messages) {
|
|
@@ -468,14 +542,16 @@ export async function loadSessionIndex(force = false, customDbPath?: string): Pr
|
|
|
468
542
|
}
|
|
469
543
|
|
|
470
544
|
// 2. OpenCode V1 Fallback Schema (session + message + part)
|
|
471
|
-
if (tables.has("session") && tables.has("message") && tables.has("part")) {
|
|
545
|
+
if (!canIncremental && tables.has("session") && tables.has("message") && tables.has("part")) {
|
|
546
|
+
const v1Cols = new Set(db.all("PRAGMA table_info(session)").map((col) => String(col.name || "")));
|
|
547
|
+
const v1ArchiveExpr = v1Cols.has("time_archived") ? "time_archived" : "NULL";
|
|
472
548
|
const v1Sessions = db.all(`
|
|
473
|
-
SELECT id, title, directory, time_created, time_updated
|
|
549
|
+
SELECT id, title, directory, time_created, time_updated, ${v1ArchiveExpr} AS time_archived
|
|
474
550
|
FROM session
|
|
475
551
|
ORDER BY time_updated DESC
|
|
476
|
-
LIMIT 500
|
|
477
552
|
`);
|
|
478
553
|
|
|
554
|
+
let v1AddedCount = 0;
|
|
479
555
|
for (const row of v1Sessions) {
|
|
480
556
|
const id = String(row.id || "");
|
|
481
557
|
if (!id || sessionsMap.has(id)) continue;
|
|
@@ -489,38 +565,42 @@ export async function loadSessionIndex(force = false, customDbPath?: string): Pr
|
|
|
489
565
|
directoryNorm: normalizePath(directory),
|
|
490
566
|
timeCreated: Number(row.time_created || 0),
|
|
491
567
|
timeUpdated: Number(row.time_updated || 0),
|
|
568
|
+
archived: row.time_archived != null,
|
|
492
569
|
tools: [],
|
|
493
570
|
files: [],
|
|
494
571
|
entries: [],
|
|
495
572
|
});
|
|
496
573
|
sessionFiles.set(id, new Set());
|
|
497
574
|
sessionTools.set(id, new Set());
|
|
575
|
+
v1AddedCount++;
|
|
498
576
|
}
|
|
499
577
|
|
|
500
|
-
let v1Parts: Record<string, unknown>[];
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
578
|
+
let v1Parts: Record<string, unknown>[] = [];
|
|
579
|
+
if (v1AddedCount > 0) {
|
|
580
|
+
try {
|
|
581
|
+
v1Parts = db.all(`
|
|
582
|
+
SELECT id, message_id, session_id, time_created, part_data, role
|
|
583
|
+
FROM (
|
|
584
|
+
SELECT p.id, p.message_id, p.session_id, p.time_created, p.data AS part_data,
|
|
585
|
+
json_extract(m.data, '$.role') AS role,
|
|
586
|
+
ROW_NUMBER() OVER (PARTITION BY p.session_id ORDER BY p.time_created DESC) AS rn
|
|
587
|
+
FROM part p
|
|
588
|
+
JOIN message m ON m.id = p.message_id
|
|
589
|
+
)
|
|
590
|
+
WHERE rn <= 250
|
|
591
|
+
ORDER BY time_created DESC
|
|
592
|
+
LIMIT 25000
|
|
593
|
+
`);
|
|
594
|
+
} catch {
|
|
595
|
+
v1Parts = db.all(`
|
|
505
596
|
SELECT p.id, p.message_id, p.session_id, p.time_created, p.data AS part_data,
|
|
506
|
-
json_extract(m.data, '$.role') AS role
|
|
507
|
-
ROW_NUMBER() OVER (PARTITION BY p.session_id ORDER BY p.time_created DESC) AS rn
|
|
597
|
+
json_extract(m.data, '$.role') AS role
|
|
508
598
|
FROM part p
|
|
509
599
|
JOIN message m ON m.id = p.message_id
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
`);
|
|
515
|
-
} catch {
|
|
516
|
-
v1Parts = db.all(`
|
|
517
|
-
SELECT p.id, p.message_id, p.session_id, p.time_created, p.data AS part_data,
|
|
518
|
-
json_extract(m.data, '$.role') AS role
|
|
519
|
-
FROM part p
|
|
520
|
-
JOIN message m ON m.id = p.message_id
|
|
521
|
-
ORDER BY p.time_created DESC
|
|
522
|
-
LIMIT 12000
|
|
523
|
-
`);
|
|
600
|
+
ORDER BY p.time_created DESC
|
|
601
|
+
LIMIT 12000
|
|
602
|
+
`);
|
|
603
|
+
}
|
|
524
604
|
}
|
|
525
605
|
|
|
526
606
|
for (const row of v1Parts) {
|
|
@@ -602,6 +682,9 @@ export async function loadSessionIndex(force = false, customDbPath?: string): Pr
|
|
|
602
682
|
}
|
|
603
683
|
|
|
604
684
|
const sessions = [...sessionsMap.values()].sort((a, b) => b.timeUpdated - a.timeUpdated);
|
|
685
|
+
cachedSessionsMap = sessionsMap;
|
|
686
|
+
cachedSessionFiles = sessionFiles;
|
|
687
|
+
cachedSessionTools = sessionTools;
|
|
605
688
|
cachedIndex = {
|
|
606
689
|
dbPath,
|
|
607
690
|
loadedAt: Date.now(),
|
|
@@ -1272,6 +1355,16 @@ export function searchSessionIndex(
|
|
|
1272
1355
|
});
|
|
1273
1356
|
}
|
|
1274
1357
|
|
|
1275
|
-
|
|
1358
|
+
const sort = options.sort ?? "updated";
|
|
1359
|
+
results.sort((a, b) => {
|
|
1360
|
+
let difference = 0;
|
|
1361
|
+
if (sort === "relevance") difference = b.score - a.score;
|
|
1362
|
+
if (sort === "newest") difference = b.session.timeCreated - a.session.timeCreated;
|
|
1363
|
+
if (sort === "oldest") difference = a.session.timeCreated - b.session.timeCreated;
|
|
1364
|
+
if (sort === "title") difference = a.session.title.localeCompare(b.session.title);
|
|
1365
|
+
if (sort === "context") difference = (b.session.contextTokens ?? -1) - (a.session.contextTokens ?? -1);
|
|
1366
|
+
if (sort === "tokens") difference = (b.session.totalTokens ?? -1) - (a.session.totalTokens ?? -1);
|
|
1367
|
+
return difference || b.session.timeUpdated - a.session.timeUpdated || a.session.id.localeCompare(b.session.id);
|
|
1368
|
+
});
|
|
1276
1369
|
return results.slice(0, limit);
|
|
1277
1370
|
}
|
package/src/server.ts
CHANGED
|
@@ -31,6 +31,7 @@ export async function executeSearchQuery(
|
|
|
31
31
|
datePreset,
|
|
32
32
|
})
|
|
33
33
|
const matches = searchSessionIndex(index, query, {
|
|
34
|
+
sort: input.sort,
|
|
34
35
|
scope,
|
|
35
36
|
currentDirectory,
|
|
36
37
|
role,
|
|
@@ -46,6 +47,9 @@ export async function executeSearchQuery(
|
|
|
46
47
|
directoryNorm: m.session.directoryNorm,
|
|
47
48
|
timeCreated: m.session.timeCreated,
|
|
48
49
|
timeUpdated: m.session.timeUpdated,
|
|
50
|
+
archived: m.session.archived,
|
|
51
|
+
contextTokens: m.session.contextTokens,
|
|
52
|
+
totalTokens: m.session.totalTokens,
|
|
49
53
|
tools: m.session.tools.slice(0, 12),
|
|
50
54
|
files: m.session.files.slice(0, 16),
|
|
51
55
|
entryCount: m.session.entries.length,
|
|
@@ -102,6 +106,9 @@ const server: Plugin.Definition = {
|
|
|
102
106
|
},
|
|
103
107
|
})
|
|
104
108
|
}
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
void loadSessionIndex(false).catch(() => {})
|
|
111
|
+
}, 50).unref?.()
|
|
105
112
|
},
|
|
106
113
|
}
|
|
107
114
|
|
package/src/sort.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type SearchSort = "updated" | "relevance" | "newest" | "oldest" | "title" | "context" | "tokens";
|
|
2
|
+
export const SEARCH_SORT_LABELS: Record<SearchSort, string> = {
|
|
3
|
+
updated: "Recently updated", relevance: "Relevance", newest: "Newest created",
|
|
4
|
+
oldest: "Oldest created", title: "Title A–Z", context: "Latest context size", tokens: "Total tokens used",
|
|
5
|
+
};
|
package/src/tui.ts
CHANGED
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
type SearchSessionMatch,
|
|
33
33
|
searchSessionIndex,
|
|
34
34
|
type SessionIndex,
|
|
35
|
+
type SearchSort,
|
|
36
|
+
SEARCH_SORT_LABELS,
|
|
35
37
|
} from "./search.ts";
|
|
36
38
|
|
|
37
39
|
function splitHighlightedText(
|
|
@@ -133,6 +135,8 @@ function createTuiRenderer() {
|
|
|
133
135
|
const [role, setRole] = createSignal<RoleFilter>("all");
|
|
134
136
|
const [datePreset, setDatePreset] = createSignal<DatePreset>("all");
|
|
135
137
|
const [mode, setMode] = createSignal<SearchMode>("smart");
|
|
138
|
+
const [sort, setSort] = createSignal<SearchSort>("updated");
|
|
139
|
+
const [restoring, setRestoring] = createSignal(false);
|
|
136
140
|
const [focusPane, setFocusPane] = createSignal<"search" | "list" | "preview">("search");
|
|
137
141
|
const [selectedIndex, setSelectedIndex] = createSignal(0);
|
|
138
142
|
const [selectedSnippetIndex, setSelectedSnippetIndex] = createSignal(0);
|
|
@@ -242,6 +246,7 @@ function createTuiRenderer() {
|
|
|
242
246
|
const idx = indexData();
|
|
243
247
|
if (!idx.sessions.length) return [];
|
|
244
248
|
return searchSessionIndex(idx, query(), {
|
|
249
|
+
sort: sort(),
|
|
245
250
|
scope: scope(),
|
|
246
251
|
currentDirectory: props.currentDirectory,
|
|
247
252
|
role: role(),
|
|
@@ -257,6 +262,7 @@ function createTuiRenderer() {
|
|
|
257
262
|
role();
|
|
258
263
|
datePreset();
|
|
259
264
|
mode();
|
|
265
|
+
sort();
|
|
260
266
|
setSelectedIndex(0);
|
|
261
267
|
setSelectedSnippetIndex(0);
|
|
262
268
|
queueMicrotask(() => listScrollRef?.scrollTo?.(0));
|
|
@@ -310,6 +316,25 @@ function createTuiRenderer() {
|
|
|
310
316
|
setMode((prev: SearchMode) => MODE_CYCLE[(MODE_CYCLE.indexOf(prev) + 1) % MODE_CYCLE.length]);
|
|
311
317
|
};
|
|
312
318
|
|
|
319
|
+
const cycleSort = () => {
|
|
320
|
+
const sorts = Object.keys(SEARCH_SORT_LABELS) as SearchSort[];
|
|
321
|
+
setSort((prev) => sorts[(sorts.indexOf(prev) + 1) % sorts.length]);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const unarchiveSelected = async () => {
|
|
325
|
+
const session = selectedMatch()?.session;
|
|
326
|
+
if (!session?.archived || restoring()) return;
|
|
327
|
+
setRestoring(true);
|
|
328
|
+
try {
|
|
329
|
+
await props.context.client.session.update({ sessionID: session.id, archived: false });
|
|
330
|
+
await reloadIndex(true);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
333
|
+
} finally {
|
|
334
|
+
setRestoring(false);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
313
338
|
const openSelected = (explicitHit?: SearchSessionMatch["matches"][number]) => {
|
|
314
339
|
const current = selectedMatch();
|
|
315
340
|
if (!current) return;
|
|
@@ -396,6 +421,18 @@ function createTuiRenderer() {
|
|
|
396
421
|
toggleScope();
|
|
397
422
|
return;
|
|
398
423
|
}
|
|
424
|
+
if (event.ctrl && name === "s") {
|
|
425
|
+
event.preventDefault();
|
|
426
|
+
event.stopPropagation();
|
|
427
|
+
cycleSort();
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (event.ctrl && event.shift && name === "a") {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
event.stopPropagation();
|
|
433
|
+
void unarchiveSelected();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
399
436
|
if (event.ctrl && name === "g") {
|
|
400
437
|
event.preventDefault();
|
|
401
438
|
event.stopPropagation();
|
|
@@ -721,6 +758,23 @@ function createTuiRenderer() {
|
|
|
721
758
|
active: () => parsedQuery().effectiveMode !== "smart",
|
|
722
759
|
onClick: cycleMode,
|
|
723
760
|
}),
|
|
761
|
+
Pill({
|
|
762
|
+
label: () => `sort:${SEARCH_SORT_LABELS[sort()]}`,
|
|
763
|
+
shortcut: "^s",
|
|
764
|
+
active: () => sort() !== "updated",
|
|
765
|
+
onClick: cycleSort,
|
|
766
|
+
}),
|
|
767
|
+
createComponent(Show, {
|
|
768
|
+
get when() { return selectedMatch()?.session.archived; },
|
|
769
|
+
get children() {
|
|
770
|
+
return Pill({
|
|
771
|
+
label: () => restoring() ? "Restoring..." : "Unarchive",
|
|
772
|
+
shortcut: "^shift+a",
|
|
773
|
+
active: () => true,
|
|
774
|
+
onClick: () => void unarchiveSelected(),
|
|
775
|
+
});
|
|
776
|
+
},
|
|
777
|
+
}),
|
|
724
778
|
createComponent(Show, {
|
|
725
779
|
get when() {
|
|
726
780
|
return Boolean(parsedQuery().fileFilter);
|
|
@@ -898,7 +952,7 @@ function createTuiRenderer() {
|
|
|
898
952
|
isSelected() ? TextAttributes.BOLD : undefined,
|
|
899
953
|
},
|
|
900
954
|
() =>
|
|
901
|
-
`${isSelected() ? "▸ " : " "}${item.session.title}`
|
|
955
|
+
`${isSelected() ? "▸ " : " "}${item.session.archived ? "[Archived] " : ""}${item.session.title}`
|
|
902
956
|
),
|
|
903
957
|
el(
|
|
904
958
|
"text",
|
|
@@ -911,7 +965,7 @@ function createTuiRenderer() {
|
|
|
911
965
|
: theme().text.action.primary.base,
|
|
912
966
|
},
|
|
913
967
|
() =>
|
|
914
|
-
` [${item.matchBadge}] ${formatRelativeTime(item.session.timeUpdated)}`
|
|
968
|
+
` [${item.matchBadge}] ${formatRelativeTime(item.session.timeUpdated)}${sort() === "context" ? ` · context: ${item.session.contextTokens?.toLocaleString() ?? "not recorded"}` : sort() === "tokens" ? ` · total: ${item.session.totalTokens?.toLocaleString() ?? "not recorded"}` : ""}`
|
|
915
969
|
)
|
|
916
970
|
),
|
|
917
971
|
el(
|