opencode-sessions-explorer 0.1.0 → 0.1.2

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.
@@ -0,0 +1,151 @@
1
+ # Tools Reference
2
+
3
+ ## Scope
4
+
5
+ This page is the complete catalog of the tools `opencode-sessions-explorer`
6
+ registers with the LLM. There are 18 tools: 17 are read-only and one
7
+ (`unarchive-session`) performs a single, deliberate write. Every tool is exposed
8
+ under the public key `opencode-sessions-explorer-<name>`; the short names below
9
+ (for example `get-session`) are used for brevity.
10
+
11
+ Tools are grouped by intent. The `Read/Write` column states whether the tool only
12
+ reads the OpenCode session database or mutates it. For the curated search surfaces
13
+ and channels that `search-text` and `grep-session` accept, see
14
+ [search-surfaces.md](search-surfaces.md). For the compact result shape that
15
+ list-shaped tools return, see [response-format.md](response-format.md).
16
+
17
+ ## Recall And Navigation
18
+
19
+ Find your bearings and pull conversation content by id.
20
+
21
+ | Tool | What It Does | Read/Write |
22
+ | --- | --- | --- |
23
+ | `current-session` | Identifies the session the assistant is currently running in: id, message id, agent, model, directory, worktree, parent, cost-so-far, message/part/tool-call counters, child sessions, and useful filesystem paths (database, export tree, this session's export dir + `meta.json`). Pass `detail:'full'` for counters, children, and paths. | Read |
24
+ | `get-session` | Fetches one session's metadata and aggregate counts by id (parts by type, tool-call status breakdown, immediate child session ids). Returns no message bodies. | Read |
25
+ | `session-summary` | One-call human-readable overview: metadata, first and last user prompt, top files touched, top tools used (with completed/error counts), error count, duration, and cost. | Read |
26
+ | `session-timeline` | Chronological event stream — one row per part with a short per-type summary and no raw bodies. Filter by part type and time window; cursor-paginated. | Read |
27
+ | `get-message` | Fetches one message and its parts by message id. Each part body is capped via `max_part_bytes` to keep the response bounded. | Read |
28
+ | `get-part` | Fetches one fully decoded part by id. Optionally dereferences an externalized tool-output file when `dereference_output_path:true` (path-guarded — see [configuration.md](configuration.md)). | Read |
29
+
30
+ ## Genealogy
31
+
32
+ Trace how sessions relate.
33
+
34
+ | Tool | What It Does | Read/Write |
35
+ | --- | --- | --- |
36
+ | `session-genealogy` | Walks the session parent/child tree to trace subagent dispatches and pair-execution chains. `direction` selects `ancestors` (up the `parent_id` chain), `descendants` (down to child sessions), or `both`. Depth-bounded by `max_depth`. | Read |
37
+
38
+ ## Browse And Filter
39
+
40
+ List and filter sessions by structured metadata. Both return metadata only — never
41
+ message bodies.
42
+
43
+ | Tool | What It Does | Read/Write |
44
+ | --- | --- | --- |
45
+ | `list-sessions` | Browses sessions newest-first with combinable structured filters: `project_id`, `agent`, `model_id`, `directory_prefix`, `archived`, `since_ms`/`until_ms`, and `title_like`. Cursor-paginated. | Read |
46
+ | `search-sessions-meta` | Filters sessions by structured metadata plus cost/token thresholds (`min_cost`, `min_tokens_input`) — the same envelope as `list-sessions` with spend filters added. | Read |
47
+
48
+ ## Content Search (ck-backed)
49
+
50
+ Search the bodies of sessions and the tool calls inside them. `search-text` and
51
+ `grep-session` shell out to the optional [`ck`](https://github.com/BeaconBay/ck)
52
+ CLI; if `ck` is absent they return `CK_NOT_FOUND` cleanly and the other tools keep
53
+ working. `search-tool-calls` queries the database directly and does not need `ck`.
54
+
55
+ | Tool | What It Does | Read/Write |
56
+ | --- | --- | --- |
57
+ | `search-text` | Full-text search across the bodies of all sessions (user prompts, assistant responses, tool input/output, reasoning, file references, patches, subtask prompts). Surface- and channel-aware; supports `regex`, `lex` (BM25), `sem`, and `hybrid` modes, a `role` filter, and `group_by_session` rollups. | Read |
58
+ | `grep-session` | grep/regex search inside one session's exported body content (fast; operates on that session's part files only). Supports `fixed_string`, `case_sensitive`, `whole_word`, and `context_lines`. | Read |
59
+ | `search-tool-calls` | Finds tool invocations across sessions, filtered by tool name (exact or `LIKE` wildcard), status, or substring on input/output/error. Returns capped snippets; cursor-paginated, newest-first. | Read |
60
+
61
+ ## Cost And Usage Analysis
62
+
63
+ Aggregate spend, tokens, failures, and prompt patterns.
64
+
65
+ | Tool | What It Does | Read/Write |
66
+ | --- | --- | --- |
67
+ | `cost-by-project` | Aggregates cost and token usage grouped by `project_id`, `directory`, `agent`, or `model`, sorted by cost. Surfaces a `cost_known` flag for groups whose sessions predate the usage-tracking migration. | Read |
68
+ | `cost-by-period` | Time-series cost and tokens bucketed by `day`, `week`, or `month`, newest-first. Supports `tz_offset_min` to shift bucket boundaries to a local day. | Read |
69
+ | `list-tool-failures` | Aggregates tool errors grouped by `tool`, `error` message prefix, or `session`, sorted by count. | Read |
70
+ | `list-repeated-prompts` | Clusters sessions by the normalized prefix of their first user prompt to surface "have I asked this before" patterns. | Read |
71
+
72
+ ## Health
73
+
74
+ | Tool | What It Does | Read/Write |
75
+ | --- | --- | --- |
76
+ | `db-stats` | Health and schema-drift probe for the OpenCode SQLite database: migration head, table counts (session/message/part), json1 status, `busy_timeout`, and drift warnings. | Read |
77
+
78
+ ## Write
79
+
80
+ The single mutation surface in the plugin.
81
+
82
+ | Tool | What It Does | Read/Write |
83
+ | --- | --- | --- |
84
+ | `unarchive-session` | Restores a previously archived session: clears `session.time_archived` **and** refreshes `session.time_updated` so the session resurfaces at the top of OpenCode's recency-ordered list. Returns `NOT_FOUND` only when the id does not exist. | **Write** |
85
+
86
+ The write is intentionally narrow: it runs through an isolated, short-lived
87
+ read-write connection while every other tool uses a read-only handle. The
88
+ `time_updated` refresh is required, not cosmetic — OpenCode loads sessions ordered
89
+ by `time_updated DESC` with a default limit per directory, so a long-archived
90
+ session would otherwise stay buried below that window and fail to open. See
91
+ [architecture.md](architecture.md) for the single-writer model.
92
+
93
+ ### CLI Executables
94
+
95
+ These ship as standalone commands (run with `bunx`) for materializing and
96
+ maintaining the search export and for verifying install health.
97
+
98
+ | Executable | What It Does |
99
+ | --- | --- |
100
+ | `opencode-sessions-explorer-bulk-export` | Materializes (and incrementally refreshes) the filesystem search export tree. `--reset` rebuilds from scratch; `--root <path>` targets a non-default export root. |
101
+ | `opencode-sessions-explorer-dedupe-export` | One-shot maintenance that removes duplicate part files (same part id, different sequence prefix). Dry-run by default; pass `--apply` to delete. |
102
+ | `opencode-sessions-explorer-check-deps` | Install health probe: database reachability, schema head and drift, SQLite `json1`, `busy_timeout`, export tree, channel views, `ck` CLI and index, and tool-output directory. `--json` emits machine-readable output. |
103
+
104
+ ## Examples
105
+
106
+ Identify the current session, then summarize it:
107
+
108
+ ```text
109
+ opencode-sessions-explorer-current-session # returns this session's id
110
+ opencode-sessions-explorer-session-summary { "session_id": "ses_…" }
111
+ ```
112
+
113
+ Find every failed `read` tool call in the last week:
114
+
115
+ ```text
116
+ opencode-sessions-explorer-search-tool-calls { "tool": "read", "status": "error", "since_ms": 1717200000000 }
117
+ ```
118
+
119
+ Search all sessions for a topic, rolled up per session:
120
+
121
+ ```text
122
+ opencode-sessions-explorer-search-text { "q": "retry backoff", "group_by_session": true }
123
+ ```
124
+
125
+ Fresh install health flow:
126
+
127
+ ```bash
128
+ bunx opencode-sessions-explorer-check-deps # warnings for missing export/ck are okay initially
129
+ bunx opencode-sessions-explorer-bulk-export
130
+ bunx opencode-sessions-explorer-check-deps
131
+ ```
132
+
133
+ Restore an archived session you located with `archived:'only'`:
134
+
135
+ ```text
136
+ opencode-sessions-explorer-list-sessions { "archived": "only" }
137
+ opencode-sessions-explorer-unarchive-session { "session_id": "ses_…" }
138
+ ```
139
+
140
+ ## Related Docs
141
+
142
+ - Configuration and environment overrides: [configuration.md](configuration.md)
143
+ - Search surfaces and channels: [search-surfaces.md](search-surfaces.md)
144
+ - Compact result format: [response-format.md](response-format.md)
145
+ - Four-layer architecture: [architecture.md](architecture.md)
146
+ - Recall and navigation workflow: [../guides/recall-and-navigation.md](../guides/recall-and-navigation.md)
147
+ - Search and grep workflow: [../guides/search-and-grep.md](../guides/search-and-grep.md)
148
+ - Cost and usage analysis workflow: [../guides/cost-and-usage-analysis.md](../guides/cost-and-usage-analysis.md)
149
+ - Export and maintenance workflow: [../guides/export-and-maintenance.md](../guides/export-and-maintenance.md)
150
+ - Managing archived sessions: [../guides/manage-archived-sessions.md](../guides/manage-archived-sessions.md)
151
+ - Troubleshooting: [../support/troubleshooting.md](../support/troubleshooting.md)
@@ -0,0 +1,230 @@
1
+ # Troubleshooting
2
+
3
+ ## How To Use This Page
4
+
5
+ Find the symptom that matches what you are seeing, run its quick checks, then apply
6
+ the fix. Each block is phrased the way the problem usually appears — an error code in
7
+ a tool response, an empty result, or a failed restore. Run the baseline checks below
8
+ first; they resolve or explain most issues on their own.
9
+
10
+ ## Baseline Checks
11
+
12
+ Two commands cover the health of every layer the plugin depends on.
13
+
14
+ 1. Probe the install end to end:
15
+
16
+ ```bash
17
+ bunx opencode-sessions-explorer-check-deps
18
+ ```
19
+
20
+ This reports database reachability, schema head and drift, SQLite `json1`,
21
+ `busy_timeout`, export tree presence, curated channel views, `ck` CLI, `ck`
22
+ index, and the tool-output directory. Add `--json` for machine-readable output.
23
+
24
+ 2. Probe the database from inside OpenCode with the `db-stats` tool. It returns the
25
+ migration head, table counts, json1 status, `busy_timeout`, and any schema-drift
26
+ warnings.
27
+
28
+ If both come back clean, the plugin core is healthy and the issue is likely scoped
29
+ to one tool or to the optional `ck` search path.
30
+
31
+ ## Plugin Tools Do Not Appear After Config Change
32
+
33
+ OpenCode starts, but the `opencode-sessions-explorer-*` tools are not available to
34
+ the model after editing config.
35
+
36
+ Quick checks:
37
+
38
+ - Confirm you edited the active OpenCode config path, usually
39
+ `~/.config/opencode/opencode.json`.
40
+ - Confirm the `plugin` array contains either the package spec
41
+ (`"opencode-sessions-explorer"` or a pinned version) or an absolute local path.
42
+ - Confirm you fully quit and restarted OpenCode; do not assume plugin hot reload.
43
+ - If using source TypeScript, confirm the path to `src/plugin.ts` exists.
44
+ - If using built JavaScript, confirm `bun run build` produced `dist/plugin.js`.
45
+ - Confirm `src/plugin.ts` exports only the plugin function; extra non-function
46
+ exports can make OpenCode reject the plugin entrypoint.
47
+
48
+ Fix:
49
+
50
+ - Correct the config, then fully restart OpenCode.
51
+ - For source checkouts, see the supported source TS and built JS options in
52
+ [install.md#from-source-dev](../install.md#from-source-dev).
53
+ - If a local source path still fails, run a local import check from the checkout:
54
+
55
+ ```bash
56
+ bun -e 'import("./src/plugin.ts").then((m) => { if (typeof m.default !== "function") throw new Error("default export is not a function") })'
57
+ ```
58
+
59
+ ## Search Returns CK_NOT_FOUND
60
+
61
+ `search-text` or `grep-session` returns the error code `CK_NOT_FOUND`.
62
+
63
+ Quick checks:
64
+
65
+ - Confirm whether `ck` is installed and on `PATH`: `ck --version`.
66
+ - Run `bunx opencode-sessions-explorer-check-deps` and look at the `ck` line.
67
+
68
+ Fix:
69
+
70
+ - Install [`ck`](https://github.com/BeaconBay/ck) (>= 0.7). If it is installed
71
+ outside `PATH`, point the plugin at it with
72
+ `OPENCODE_SESSIONS_EXPLORER_CK_BIN=/abs/path/to/ck`.
73
+ - `ck` is only needed for `search-text` and `grep-session`. The other 16 tools work
74
+ without it, so recall, browse, cost, and analysis tools remain available
75
+ meanwhile. See [configuration.md](../reference/configuration.md).
76
+
77
+ ## Database Not Found
78
+
79
+ A tool returns `DB_NOT_FOUND`, or `check-deps` fails the "OpenCode DB" line.
80
+
81
+ Quick checks:
82
+
83
+ - Confirm the database exists at the default path
84
+ (`~/.local/share/opencode/opencode.db` on common macOS/Linux installs).
85
+ - Confirm OpenCode has run at least once so the database has been created.
86
+
87
+ Fix:
88
+
89
+ - If the database lives elsewhere, set `OPENCODE_SESSIONS_EXPLORER_DB` to its
90
+ absolute path. If `$XDG_DATA_HOME` or Windows `%LOCALAPPDATA%` changes the data
91
+ root, use that actual path.
92
+ - If the path is correct but access is blocked, add the `external_directory`
93
+ permission rule (next block) and restart OpenCode.
94
+ - See [configuration.md](../reference/configuration.md) for the full override table.
95
+
96
+ ## Search Finds Nothing
97
+
98
+ A search returns zero hits for a term you expect to exist.
99
+
100
+ Quick checks:
101
+
102
+ - Confirm the export tree has been materialized at least once.
103
+ - Note whether the session you expect is very new — its parts may not be exported
104
+ yet.
105
+ - Confirm the term is not being narrowed away by `role`, `surface`, or a time/scope
106
+ filter.
107
+
108
+ Fix:
109
+
110
+ - Run the one-time export, then retry:
111
+
112
+ ```bash
113
+ bunx opencode-sessions-explorer-bulk-export
114
+ ```
115
+
116
+ - New parts are delta-synced automatically before each `search-text` /
117
+ `grep-session` call, so a missing recent part usually resolves on the next search.
118
+ - Widen the search: try `surface:'forensics'` (or `channels:['raw']`) to include raw
119
+ bodies, and confirm `role` is `any`. See
120
+ [search-surfaces.md](../reference/search-surfaces.md).
121
+
122
+ ## grep-session Returns INDEX_MISSING
123
+
124
+ `grep-session` returns `INDEX_MISSING`, usually with a message that the session is
125
+ not in the export tree.
126
+
127
+ Quick checks:
128
+
129
+ - Verify the `session_id` is correct with `get-session` or `list-sessions`.
130
+ - Confirm the export tree exists and includes that session under `by-session/`.
131
+ - If you requested a curated surface/channel, confirm channel views are complete in
132
+ `check-deps`.
133
+
134
+ Fix:
135
+
136
+ - Run the one-time export, then retry `grep-session`:
137
+
138
+ ```bash
139
+ bunx opencode-sessions-explorer-bulk-export
140
+ ```
141
+
142
+ - If the session is very new, retry after the tool's auto-sync has had a chance to
143
+ export recent parts.
144
+ - If channel views are partial or missing, rebuild them:
145
+
146
+ ```bash
147
+ bunx opencode-sessions-explorer-bulk-export --reset
148
+ ```
149
+
150
+ ## Permission Denied / external_directory
151
+
152
+ A tool cannot reach the database even though the path is correct, or OpenCode
153
+ reports an external-directory permission error.
154
+
155
+ Quick checks:
156
+
157
+ - Confirm the `external_directory` allow rule is present in your OpenCode config.
158
+ - Confirm you fully restarted OpenCode after editing the config.
159
+
160
+ Fix:
161
+
162
+ - Add the allow rule and restart OpenCode:
163
+
164
+ ```jsonc
165
+ // ~/.config/opencode/opencode.json
166
+ {
167
+ "permission": {
168
+ "external_directory": {
169
+ "~/.local/share/opencode/**": "allow"
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ - The database lives outside your project workspace, so this rule is required. The
176
+ default snippet covers the common macOS/Linux path. If `$XDG_DATA_HOME`, Windows
177
+ `%LOCALAPPDATA%`, or `OPENCODE_SESSIONS_EXPLORER_DB` points elsewhere, allow the
178
+ actual containing directory and restart. Some global configs use
179
+ `external_directory: "allow"`; that also permits access, but a scoped allow rule is
180
+ preferred for normal users. The change only takes effect after a full restart. See
181
+ [configuration.md](../reference/configuration.md).
182
+
183
+ ## Schema Drift Warnings
184
+
185
+ A tool returns `SCHEMA_DRIFT`, or `db-stats` / `check-deps` reports drift warnings.
186
+
187
+ Quick checks:
188
+
189
+ - Run `db-stats` and read `migrations_head` and `drift_warnings`.
190
+ - Run `bunx opencode-sessions-explorer-check-deps` and check the schema line.
191
+ - Note whether you recently upgraded OpenCode.
192
+
193
+ Fix:
194
+
195
+ - Drift warnings usually mean the installed OpenCode version moved the database
196
+ schema ahead of (or behind) what the plugin expects. Align the plugin version with
197
+ your OpenCode version.
198
+ - If the warning is soft, read tools still work; treat the warning as a prompt to
199
+ update. If `hard_drift` is reported, update the plugin before relying on affected
200
+ tools.
201
+
202
+ ## get-part Returns PATH_TRAVERSAL
203
+
204
+ `get-part` with `dereference_output_path:true` returns `PATH_TRAVERSAL`.
205
+
206
+ Quick checks:
207
+
208
+ - Confirm the part's externalized output path resolves inside the tool-output
209
+ directory.
210
+ - Confirm `OPENCODE_SESSIONS_EXPLORER_TOOL_OUTPUT_DIR`, if set, points at the
211
+ directory that actually holds the externalized files.
212
+
213
+ Fix:
214
+
215
+ - Dereference is deliberately whitelisted to the tool-output directory; any path
216
+ outside it (including a symlink that escapes the root) is rejected by design. This
217
+ is a guardrail, not a bug.
218
+ - If your externalized output lives in a non-default location, set
219
+ `OPENCODE_SESSIONS_EXPLORER_TOOL_OUTPUT_DIR` to that root and retry. See
220
+ [configuration.md](../reference/configuration.md) and the redaction/guard policy in
221
+ [SECURITY.md](../../.github/SECURITY.md).
222
+
223
+ ## Related Docs
224
+
225
+ - Tool catalog: [../reference/tools.md](../reference/tools.md)
226
+ - Configuration and environment overrides: [../reference/configuration.md](../reference/configuration.md)
227
+ - Search surfaces and channels: [../reference/search-surfaces.md](../reference/search-surfaces.md)
228
+ - Four-layer architecture: [../reference/architecture.md](../reference/architecture.md)
229
+ - Export and maintenance workflow: [../guides/export-and-maintenance.md](../guides/export-and-maintenance.md)
230
+ - Data exposure and redaction policy: [../../.github/SECURITY.md](../../.github/SECURITY.md)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "opencode-sessions-explorer",
4
- "version": "0.1.0",
5
- "description": "OpenCode plugin: access to every prior OpenCode session on this machine — recall, search/grep, and historical analysis via 18 LLM-discoverable tools (17 read-only plus one write, unarchive-session).",
4
+ "version": "0.1.2",
5
+ "description": "OpenCode plugin for recall and analysis of past OpenCode sessions: search, grep, and cost/usage insights across your session history via 18 LLM tools (17 read-only plus one write, unarchive-session).",
6
6
  "keywords": [
7
7
  "opencode",
8
8
  "opencode-plugin",
@@ -34,6 +34,7 @@
34
34
  "files": [
35
35
  "dist/",
36
36
  "types/",
37
+ "docs/",
37
38
  "README.md",
38
39
  "LICENSE",
39
40
  "CHANGELOG.md"
@@ -67,8 +68,8 @@
67
68
  "zod": "^4.0.0"
68
69
  },
69
70
  "devDependencies": {
70
- "@opencode-ai/plugin": "1.15.10",
71
+ "@opencode-ai/plugin": "1.17.4",
71
72
  "@types/bun": "latest",
72
- "typescript": "^5.4.0"
73
+ "typescript": "^6.0.3"
73
74
  }
74
75
  }