opencode-sessions-explorer 0.1.1 → 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.
- package/CHANGELOG.md +8 -0
- package/README.md +30 -4
- package/docs/README.md +45 -0
- package/docs/getting-started.md +96 -0
- package/docs/guides/cost-and-usage-analysis.md +75 -0
- package/docs/guides/export-and-maintenance.md +85 -0
- package/docs/guides/manage-archived-sessions.md +70 -0
- package/docs/guides/recall-and-navigation.md +90 -0
- package/docs/guides/search-and-grep.md +87 -0
- package/docs/install.md +140 -0
- package/docs/maintainers/development.md +140 -0
- package/docs/maintainers/docs-writing.md +86 -0
- package/docs/maintainers/release.md +72 -0
- package/docs/maintainers/triage.md +55 -0
- package/docs/reference/architecture.md +112 -0
- package/docs/reference/configuration.md +115 -0
- package/docs/reference/response-format.md +120 -0
- package/docs/reference/search-surfaces.md +106 -0
- package/docs/reference/tools.md +151 -0
- package/docs/support/troubleshooting.md +230 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.2] - 2026-06-13
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Clarified installation, source-dev, and first-run docs, including plugin
|
|
14
|
+
registration troubleshooting, platform-specific database paths, and export/index
|
|
15
|
+
setup; shipped `docs/` in the npm package so README guide links resolve for
|
|
16
|
+
package consumers.
|
|
17
|
+
|
|
10
18
|
## [0.1.1] - 2026-06-13
|
|
11
19
|
|
|
12
20
|
### Changed
|
package/README.md
CHANGED
|
@@ -27,14 +27,14 @@ Unarchive session ses_… so I can open it again.
|
|
|
27
27
|
|
|
28
28
|
| Area | Support | Notes |
|
|
29
29
|
| --- | --- | --- |
|
|
30
|
-
| OpenCode | Plugin host | Loads the plugin and owns the source database |
|
|
31
|
-
| Bun | `>= 1.0` | Runtime; the plugin uses `bun:sqlite` (OpenCode ships Bun) |
|
|
30
|
+
| OpenCode | Plugin host compatible with `@opencode-ai/plugin >= 1.15.0` | Loads the plugin and owns the source database |
|
|
31
|
+
| Bun | `>= 1.0` | Runtime; the plugin uses `bun:sqlite` (OpenCode ships Bun), which should include SQLite `json1`; `check-deps` / `db-stats` verify it |
|
|
32
32
|
| `ck` | `>= 0.7`, optional | Only `search-text` / `grep-session` need it; the other 16 tools work without it |
|
|
33
33
|
| OS | macOS / Linux | Windows paths resolve via `%LOCALAPPDATA%` |
|
|
34
34
|
|
|
35
35
|
## Quick Start
|
|
36
36
|
|
|
37
|
-
1. Add the plugin and grant access to the OpenCode data directory
|
|
37
|
+
1. Add the plugin and grant access to the OpenCode data directory:
|
|
38
38
|
|
|
39
39
|
```jsonc
|
|
40
40
|
// ~/.config/opencode/opencode.json
|
|
@@ -49,12 +49,38 @@ Unarchive session ses_… so I can open it again.
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
The `external_directory` snippet covers the common macOS/Linux default path. If
|
|
53
|
+
`$XDG_DATA_HOME`, Windows `%LOCALAPPDATA%`, or
|
|
54
|
+
`OPENCODE_SESSIONS_EXPLORER_DB` points elsewhere, allow the actual containing
|
|
55
|
+
directory and restart OpenCode. Some existing global configs use
|
|
56
|
+
`external_directory: "allow"`; that also permits access, but the scoped path rule
|
|
57
|
+
above is preferred for normal users.
|
|
58
|
+
|
|
52
59
|
1. **Quit and restart OpenCode.** All 18 tools auto-register. OpenCode auto-installs
|
|
53
60
|
npm plugins with Bun on startup, so there is no separate `npm install` step.
|
|
54
|
-
1.
|
|
61
|
+
1. Run the health probe once. Warnings for the missing export tree, missing `ck`, or
|
|
62
|
+
missing `ck` index are okay at this stage:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
bunx opencode-sessions-explorer-check-deps
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
1. Materialize the search export once:
|
|
55
69
|
|
|
56
70
|
```bash
|
|
57
71
|
bunx opencode-sessions-explorer-bulk-export
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
1. (Optional) Build the `ck` index from the export root, not the repo root:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cd ~/.local/share/opencode-sessions-explorer
|
|
78
|
+
ck --index . # run in the export root, not the repo root
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
1. Run the health probe again to confirm the export and optional index state:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
58
84
|
bunx opencode-sessions-explorer-check-deps
|
|
59
85
|
```
|
|
60
86
|
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Documentation
|
|
2
|
+
|
|
3
|
+
This documentation is organized by intent so you can find the shortest path from
|
|
4
|
+
a question about your OpenCode session history to the tool or command that answers it.
|
|
5
|
+
|
|
6
|
+
## How To Navigate This Docs Set
|
|
7
|
+
|
|
8
|
+
- Start pages help with install and the first successful query.
|
|
9
|
+
- Guides explain workflows and decision points across the 18 tools and 3 CLIs.
|
|
10
|
+
- Reference pages define stable tools, options, search surfaces, and response shapes.
|
|
11
|
+
- Support pages diagnose failures.
|
|
12
|
+
- Maintainer pages describe contributor and release operations.
|
|
13
|
+
|
|
14
|
+
## Start Here
|
|
15
|
+
|
|
16
|
+
- [Getting Started](getting-started.md): prerequisites, setup, and first successful query.
|
|
17
|
+
- [Install](install.md): plugin registration, version pinning, and from-source setup.
|
|
18
|
+
|
|
19
|
+
## Find By Task
|
|
20
|
+
|
|
21
|
+
| If You Need To... | Read |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| Install the plugin and run a first query | [getting-started.md](getting-started.md), [install.md](install.md) |
|
|
24
|
+
| Recall a session and drill into its content | [guides/recall-and-navigation.md](guides/recall-and-navigation.md) |
|
|
25
|
+
| Search across your whole session history | [guides/search-and-grep.md](guides/search-and-grep.md) |
|
|
26
|
+
| Grep inside one known session | [guides/search-and-grep.md](guides/search-and-grep.md) |
|
|
27
|
+
| Analyze cost and usage | [guides/cost-and-usage-analysis.md](guides/cost-and-usage-analysis.md) |
|
|
28
|
+
| Export and maintain the search tree | [guides/export-and-maintenance.md](guides/export-and-maintenance.md) |
|
|
29
|
+
| Recover an archived session | [guides/manage-archived-sessions.md](guides/manage-archived-sessions.md) |
|
|
30
|
+
| Read the full tool reference | [reference/tools.md](reference/tools.md) |
|
|
31
|
+
| Configure paths, env vars, and behavior | [reference/configuration.md](reference/configuration.md) |
|
|
32
|
+
| Understand the response/envelope format | [reference/response-format.md](reference/response-format.md) |
|
|
33
|
+
| Understand the architecture | [reference/architecture.md](reference/architecture.md) |
|
|
34
|
+
| Diagnose an environment or workflow failure | [support/troubleshooting.md](support/troubleshooting.md) |
|
|
35
|
+
|
|
36
|
+
## Maintainers
|
|
37
|
+
|
|
38
|
+
- [Development Guide](maintainers/development.md)
|
|
39
|
+
- [Release Guide](maintainers/release.md)
|
|
40
|
+
- [Triage Guide](maintainers/triage.md)
|
|
41
|
+
- [Docs Writing Standard](maintainers/docs-writing.md)
|
|
42
|
+
|
|
43
|
+
## Roadmap
|
|
44
|
+
|
|
45
|
+
- [Changelog](../CHANGELOG.md)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Get from a fresh install to a first successful query against your OpenCode session
|
|
6
|
+
history, then branch into the right workflow guide.
|
|
7
|
+
|
|
8
|
+
## Prerequisites
|
|
9
|
+
|
|
10
|
+
| Area | Requirement |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| OpenCode | A working OpenCode install that has run at least once (it owns the source database) and a plugin host compatible with `@opencode-ai/plugin >= 1.15.0` |
|
|
13
|
+
| Bun | `>= 1.0` runtime; the plugin uses `bun:sqlite`, which should include SQLite `json1`. OpenCode ships Bun, so a standalone install is only needed to run the bundled CLIs directly. `check-deps` / `db-stats` verify it. |
|
|
14
|
+
| `ck` (optional) | [`ck`](https://github.com/BeaconBay/ck) `>= 0.7`, required only by `search-text` and `grep-session`; the other 16 tools work without it |
|
|
15
|
+
|
|
16
|
+
## Steps
|
|
17
|
+
|
|
18
|
+
1. Register the plugin and grant access to the OpenCode data directory in
|
|
19
|
+
`~/.config/opencode/opencode.json`:
|
|
20
|
+
|
|
21
|
+
```jsonc
|
|
22
|
+
{
|
|
23
|
+
"$schema": "https://opencode.ai/config.json",
|
|
24
|
+
"plugin": ["opencode-sessions-explorer"],
|
|
25
|
+
"permission": {
|
|
26
|
+
"external_directory": {
|
|
27
|
+
"~/.local/share/opencode/**": "allow"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The `external_directory` allow rule is required because the OpenCode database
|
|
34
|
+
lives outside your project workspace. This snippet covers the common macOS/Linux
|
|
35
|
+
default path. If `$XDG_DATA_HOME`, Windows `%LOCALAPPDATA%`, or
|
|
36
|
+
`OPENCODE_SESSIONS_EXPLORER_DB` points elsewhere, allow the actual containing
|
|
37
|
+
directory and restart OpenCode. Some global configs use
|
|
38
|
+
`external_directory: "allow"`; that also permits access, but the scoped path rule
|
|
39
|
+
is preferred for normal users.
|
|
40
|
+
|
|
41
|
+
1. Quit and restart OpenCode. It auto-installs npm plugins with Bun on startup, so
|
|
42
|
+
there is no separate `npm install` step, and all 18 tools auto-register.
|
|
43
|
+
|
|
44
|
+
1. Run the install health probe before exporting. Warnings for a missing export
|
|
45
|
+
tree, missing `ck`, or missing `ck` index are expected on a fresh install:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
bunx opencode-sessions-explorer-check-deps
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
1. Materialize the searchable export tree once so content search has data to scan:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
bunx opencode-sessions-explorer-bulk-export
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
1. (Optional) Build the semantic index to enable `mode:'sem'` and `mode:'hybrid'`
|
|
58
|
+
search. This is a slow, one-time pass. Run it in the export root, not in the
|
|
59
|
+
repository checkout:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cd ~/.local/share/opencode-sessions-explorer
|
|
63
|
+
ck --index . # run in the export root, not the repo root
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
1. Run the install health probe again and confirm there are no hard failures:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bunx opencode-sessions-explorer-check-deps
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Validate
|
|
73
|
+
|
|
74
|
+
1. Read the final `check-deps` output. It reports database reachability, schema and
|
|
75
|
+
drift, SQLite `json1`, `busy_timeout`, export tree, channel views, `ck` CLI,
|
|
76
|
+
`ck` index, and tool-output directory status. Exit code `0` means all green, `1`
|
|
77
|
+
means optional pieces are missing, and `2` means the plugin cannot work yet.
|
|
78
|
+
|
|
79
|
+
1. In OpenCode, ask an orientation question such as "what session am I in?" — the
|
|
80
|
+
model routes to `current-session` and returns this session's id, agent, model,
|
|
81
|
+
directory, and useful paths.
|
|
82
|
+
|
|
83
|
+
## Next Steps
|
|
84
|
+
|
|
85
|
+
- Recall and navigation: [guides/recall-and-navigation.md](guides/recall-and-navigation.md)
|
|
86
|
+
- Search and grep: [guides/search-and-grep.md](guides/search-and-grep.md)
|
|
87
|
+
- Cost and usage analysis: [guides/cost-and-usage-analysis.md](guides/cost-and-usage-analysis.md)
|
|
88
|
+
- Export and maintenance: [guides/export-and-maintenance.md](guides/export-and-maintenance.md)
|
|
89
|
+
- Manage archived sessions: [guides/manage-archived-sessions.md](guides/manage-archived-sessions.md)
|
|
90
|
+
|
|
91
|
+
## Related Docs
|
|
92
|
+
|
|
93
|
+
- [Install](install.md)
|
|
94
|
+
- [Tool reference](reference/tools.md)
|
|
95
|
+
- [Configuration reference](reference/configuration.md)
|
|
96
|
+
- [Troubleshooting](support/troubleshooting.md)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Cost And Usage Analysis Guide
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Quantify OpenCode spend and token usage across your session history, and surface
|
|
6
|
+
recurring failures and repeated prompts.
|
|
7
|
+
|
|
8
|
+
## Mental Model
|
|
9
|
+
|
|
10
|
+
All four tools aggregate the `session` and `part` tables directly — no export tree
|
|
11
|
+
or `ck` index required. Pick the tool by the shape of the answer you want:
|
|
12
|
+
|
|
13
|
+
- **Spend by dimension** — `cost-by-project` groups by project, directory, agent, or
|
|
14
|
+
model.
|
|
15
|
+
- **Spend over time** — `cost-by-period` buckets the same data by day, week, or month.
|
|
16
|
+
- **Failure signal** — `list-tool-failures` aggregates errored tool calls.
|
|
17
|
+
- **Repetition signal** — `list-repeated-prompts` clusters sessions by their first
|
|
18
|
+
user prompt.
|
|
19
|
+
|
|
20
|
+
### The `cost_known` Flag
|
|
21
|
+
|
|
22
|
+
Sessions created before OpenCode's `session_usage` migration store `cost = 0` even
|
|
23
|
+
though they were not actually free. `cost-by-project` reports `cost_known: false` for
|
|
24
|
+
any group whose sessions are all pre-migration, and `cost-by-period` hides
|
|
25
|
+
zero-valued buckets unless you pass `include_zero_buckets: true`. Treat a zero with
|
|
26
|
+
`cost_known: false` as "unknown", not "$0".
|
|
27
|
+
|
|
28
|
+
## Controls
|
|
29
|
+
|
|
30
|
+
| Tool | Use It For | Key Args |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| `cost-by-project` | "Spend by project / agent / model", "which directory burned the most tokens" | `group_by` (`project_id`/`directory`/`agent`/`model`), `since_ms`/`until_ms`, `archived`, `min_cost`, `min_tokens`, `top` |
|
|
33
|
+
| `cost-by-period` | "Daily/weekly/monthly spend", "cost trend over time" | `bucket` (`day`/`week`/`month`), `since_ms`/`until_ms`, `project_id`, `agent`, `tz_offset_min`, `min_cost`, `include_zero_buckets`, `max_buckets` |
|
|
34
|
+
| `list-tool-failures` | "Which tool fails most", "what errors keep recurring", "sessions with the most failures" | `group_by` (`tool`/`error`/`session`), `tool`, `error_like`, `since_ms`/`until_ms`, `archived`, `limit`, `error_prefix_chars` |
|
|
35
|
+
| `list-repeated-prompts` | "Have I asked this before", "my most repeated prompts" | `min_count`, `prefix_chars`, `since_ms`/`until_ms`, `archived`, `limit`, `sample_per_group` |
|
|
36
|
+
|
|
37
|
+
## Recommended Flow
|
|
38
|
+
|
|
39
|
+
1. Start broad with a spend breakdown by project:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{ "group_by": "project_id", "top": 20 }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
1. Compare models or agents by switching `group_by`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{ "group_by": "model" }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
1. Look at the trend over time, shifting bucket boundaries to your local day if
|
|
52
|
+
needed (`tz_offset_min` is positive when ahead of UTC):
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{ "bucket": "day", "tz_offset_min": 120 }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
1. Find what breaks most often, then expand a group with `search-tool-calls`:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{ "group_by": "tool", "limit": 20 }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
1. Detect duplicated work by clustering opening prompts:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{ "min_count": 3, "prefix_chars": 80 }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Related Docs
|
|
71
|
+
|
|
72
|
+
- [Recall and navigation](recall-and-navigation.md)
|
|
73
|
+
- [Search and grep](search-and-grep.md)
|
|
74
|
+
- [Tool reference](../reference/tools.md)
|
|
75
|
+
- [Response format](../reference/response-format.md)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Export And Maintenance Guide
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Understand the searchable export tree that content search depends on, and keep it
|
|
6
|
+
healthy with the bundled command-line tools.
|
|
7
|
+
|
|
8
|
+
## Mental Model
|
|
9
|
+
|
|
10
|
+
Content search does not run against the database directly. The plugin maintains a
|
|
11
|
+
four-layer pipeline:
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
SQLite DB (read-only source of truth)
|
|
15
|
+
-> filesystem export tree (~/.local/share/opencode-sessions-explorer; by-session + by-channel)
|
|
16
|
+
-> ck index (.ck/, BM25 + embeddings; optional)
|
|
17
|
+
-> enriched response (re-fetches session/part metadata from SQLite per hit)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The export tree materializes each searchable part as a small text file under
|
|
21
|
+
`by-session/<ses_…>/` plus curated `by-channel/` views (such as conversation and
|
|
22
|
+
session-summary). `ck` searches these files; the plugin then re-reads session and
|
|
23
|
+
part metadata from SQLite to enrich each hit. The export root is overridable via
|
|
24
|
+
`OPENCODE_SESSIONS_EXPLORER_EXPORT_ROOT`.
|
|
25
|
+
|
|
26
|
+
### Auto-Sync
|
|
27
|
+
|
|
28
|
+
`search-text` and `grep-session` delta-sync new parts into the export tree before
|
|
29
|
+
each call (a few-second best-effort budget), so day-to-day search stays current
|
|
30
|
+
without manual steps. The CLIs below are for the initial backfill and occasional
|
|
31
|
+
maintenance.
|
|
32
|
+
|
|
33
|
+
## Controls
|
|
34
|
+
|
|
35
|
+
| Command / Tool | Use It For | Notes |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| `opencode-sessions-explorer-bulk-export` | Build or resume the export tree | Idempotent and resumable via `.last_sync`; `--reset` starts from scratch and rebuilds curated `by-channel/` views; `--root <path>` targets a non-default export root |
|
|
38
|
+
| `opencode-sessions-explorer-dedupe-export` | Remove duplicate part files from an older cursor-migration bug | Dry-run by default (reports only); pass `--apply` to actually delete, keeping the lowest-seq file per part |
|
|
39
|
+
| `opencode-sessions-explorer-check-deps` | Probe install health | Checks DB, schema/drift, SQLite `json1`, `busy_timeout`, export tree, channel views, `ck` CLI, `ck` index, and tool-output dir; `--json` for machine output; exit codes `0` ok, `1` soft warning, `2` hard fail |
|
|
40
|
+
| `db-stats` (tool) | Inspect database health from inside OpenCode | Returns migration head, table counts, json1 status, `busy_timeout`, and schema-drift warnings |
|
|
41
|
+
|
|
42
|
+
## Recommended Flow
|
|
43
|
+
|
|
44
|
+
1. Run the one-time backfill so search has content to scan:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bunx opencode-sessions-explorer-bulk-export
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
1. If curated channel views are reported as partial (for example by
|
|
51
|
+
`check-deps`), rebuild them once:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
bunx opencode-sessions-explorer-bulk-export --reset
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
1. (Optional) Build the semantic index to unlock `sem` and `hybrid` search modes.
|
|
58
|
+
This is slow and only needs to run once. Run `ck --index .` from the export root,
|
|
59
|
+
not from the repository checkout:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cd ~/.local/share/opencode-sessions-explorer
|
|
63
|
+
ck --index . # run in the export root, not the repo root
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
1. Verify everything is wired up, and re-run after any OpenCode upgrade:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bunx opencode-sessions-explorer-check-deps
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
1. If an older export shows duplicate part files, preview then apply a cleanup:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bunx opencode-sessions-explorer-dedupe-export
|
|
76
|
+
bunx opencode-sessions-explorer-dedupe-export --apply
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Related Docs
|
|
80
|
+
|
|
81
|
+
- [Search and grep](search-and-grep.md)
|
|
82
|
+
- [Architecture](../reference/architecture.md)
|
|
83
|
+
- [Search surfaces](../reference/search-surfaces.md)
|
|
84
|
+
- [Configuration reference](../reference/configuration.md)
|
|
85
|
+
- [Troubleshooting](../support/troubleshooting.md)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Manage Archived Sessions Guide
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Restore a previously archived OpenCode session so it can be opened and prompted
|
|
6
|
+
again, using the one tool in this plugin that writes to the database.
|
|
7
|
+
|
|
8
|
+
## Mental Model
|
|
9
|
+
|
|
10
|
+
`unarchive-session` is the only write surface in an otherwise read-only plugin. It
|
|
11
|
+
does two things in a single isolated write:
|
|
12
|
+
|
|
13
|
+
1. **Clears `time_archived`** so the session is no longer marked archived.
|
|
14
|
+
2. **Refreshes `time_updated`** so the session resurfaces at the top of OpenCode's
|
|
15
|
+
recency-ordered list.
|
|
16
|
+
|
|
17
|
+
The `time_updated` bump is required, not cosmetic. OpenCode loads sessions ordered
|
|
18
|
+
by `time_updated DESC` with a default limit of ~100 per directory. Clearing
|
|
19
|
+
`time_archived` alone leaves a long-archived session buried below that window, so the
|
|
20
|
+
app still fails to retrieve it with "Unable to retrieve session". Refreshing
|
|
21
|
+
`time_updated` is also the intuitive meaning of "restore". Because it always
|
|
22
|
+
restores to a usable state, the tool also resurfaces an already-active-but-buried
|
|
23
|
+
session and is idempotent in effect (active and at the top).
|
|
24
|
+
|
|
25
|
+
### Why A Direct Database Write Is Required
|
|
26
|
+
|
|
27
|
+
OpenCode exposes no archive/unarchive endpoint that can clear the flag: the HTTP
|
|
28
|
+
`UpdatePayload` types `time.archived` as a finite number and the handler ignores
|
|
29
|
+
`undefined`, so a clear cannot be sent over the wire. The `opencode session` CLI
|
|
30
|
+
only offers list and delete. A direct database write is therefore the only
|
|
31
|
+
mechanism. Reads still go through the shared read-only handle; the write goes through
|
|
32
|
+
a separate, short-lived read-write connection used only by this tool.
|
|
33
|
+
|
|
34
|
+
## Controls
|
|
35
|
+
|
|
36
|
+
| Tool | Use It For | Key Args |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `unarchive-session` | "Unarchive `ses_…`", "restore an archived session so I can continue it" | `session_id` (must be an existing session; returns `NOT_FOUND` otherwise) |
|
|
39
|
+
| `list-sessions` / `search-sessions-meta` | Find archived sessions to restore | `archived: 'only'` |
|
|
40
|
+
|
|
41
|
+
## Recommended Flow
|
|
42
|
+
|
|
43
|
+
1. Find the archived session you want back:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{ "archived": "only", "limit": 20 }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
1. Restore it by id:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{ "session_id": "ses_XYZ" }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The response reports `was_archived`, the new `now_active` and `resurfaced`
|
|
56
|
+
state, the session `directory`, and before/after `time_updated` values.
|
|
57
|
+
|
|
58
|
+
1. Make the restored session visible in the app. Because the write happens outside
|
|
59
|
+
OpenCode, it emits no `session.updated` event:
|
|
60
|
+
|
|
61
|
+
1. Reload or restart the OpenCode window.
|
|
62
|
+
1. Open OpenCode in the session's own `directory` — it is restored under that
|
|
63
|
+
directory and now sorts to the top of the recency-ordered list.
|
|
64
|
+
|
|
65
|
+
## Related Docs
|
|
66
|
+
|
|
67
|
+
- [Recall and navigation](recall-and-navigation.md)
|
|
68
|
+
- [Tool reference](../reference/tools.md)
|
|
69
|
+
- [Architecture](../reference/architecture.md)
|
|
70
|
+
- [Security policy](../../.github/SECURITY.md)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Recall And Navigation Guide
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Find a past OpenCode session, understand what it contains, and drill from a
|
|
6
|
+
high-level overview down to a single message or part — including the parent/child
|
|
7
|
+
chains created by subagent dispatch.
|
|
8
|
+
|
|
9
|
+
## Mental Model
|
|
10
|
+
|
|
11
|
+
Orient first, then drill down; walk the tree to follow subagent and
|
|
12
|
+
pair-execution chains.
|
|
13
|
+
|
|
14
|
+
- **Orient.** `current-session` tells the assistant which session it is running in
|
|
15
|
+
(id, agent, model, directory, counts, and useful filesystem paths). It is the
|
|
16
|
+
natural first call because the model has no native way to know its own session id.
|
|
17
|
+
- **Find and browse.** `list-sessions` and `search-sessions-meta` locate sessions by
|
|
18
|
+
recency or structured metadata (agent, directory, title, cost, tokens). Neither
|
|
19
|
+
returns message bodies.
|
|
20
|
+
- **Overview.** `get-session` returns one session's metadata and aggregate counts;
|
|
21
|
+
`session-summary` returns a human-readable overview (first/last prompt, top files
|
|
22
|
+
touched, top tools, errors, duration, cost).
|
|
23
|
+
- **Reconstruct.** `session-timeline` returns a chronological event stream (one
|
|
24
|
+
short line per part) without raw bodies.
|
|
25
|
+
- **Drill into detail.** `get-message` fetches one turn and its parts (bodies
|
|
26
|
+
capped); `get-part` fetches a single part and can dereference externalized
|
|
27
|
+
tool-output files.
|
|
28
|
+
- **Trace relationships.** `session-genealogy` walks the `parent_id` chain up to
|
|
29
|
+
ancestors and down to descendants — the graph that subagent dispatches create.
|
|
30
|
+
|
|
31
|
+
## Entry Points
|
|
32
|
+
|
|
33
|
+
| Tool | Answers | Key Args |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `current-session` | "What session am I in?", "where am I?", self-orientation | `detail` (`compact`/`full`), `include_suggestions` |
|
|
36
|
+
| `list-sessions` | "List my recent sessions", "sessions from last week", "sessions using agent X" | `limit`, `cursor`, `project_id`, `agent`, `model_id`, `directory_prefix`, `archived`, `since_ms`/`until_ms`, `title_like` |
|
|
37
|
+
| `search-sessions-meta` | "Sessions costing more than $5", "sessions with > 100K input tokens", "most expensive session" | `title_like`, `directory_like`, `project_id`, `agent`, `model_id`, `min_cost`, `min_tokens_input`, `since_ms`/`until_ms`, `archived` |
|
|
38
|
+
| `get-session` | "Metadata for `ses_X`", "how many messages/parts in `ses_Y`", "who is the parent of `ses_X`" | `session_id` |
|
|
39
|
+
| `session-summary` | "Summarize `ses_X`", "what files did I touch", "what tools did I use" | `session_id`, `max_prompt_bytes` |
|
|
40
|
+
| `session-timeline` | "Walk `ses_X` step by step", "show only the tool calls in order" | `session_id`, `types`, `granularity`, `from_ts`/`until_ts`, `limit`, `cursor` |
|
|
41
|
+
| `get-message` | "Fetch message `msg_X` with its parts" | `message_id`, `include_part_data`, `part_types`, `max_part_bytes` |
|
|
42
|
+
| `get-part` | "Show part `prt_X`", "dereference the externalized output of `prt_Z`" | `part_id`, `max_bytes`, `dereference_output_path` |
|
|
43
|
+
| `session-genealogy` | "Parent chain of `ses_X`", "what subagents did `ses_Y` spawn" | `session_id`, `direction` (`ancestors`/`descendants`/`both`), `max_depth`, `include_archived` |
|
|
44
|
+
|
|
45
|
+
## Recommended Flow
|
|
46
|
+
|
|
47
|
+
1. Start with `current-session` to capture your own `session_id` and context.
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "detail": "full" }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
1. If you do not yet know the session, narrow with `list-sessions` (recency) or
|
|
54
|
+
`search-sessions-meta` (cost/token/title thresholds).
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{ "agent": "build", "since_ms": 1717200000000, "limit": 20 }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
1. Get the gist with `session-summary`, or raw counts with `get-session`.
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{ "session_id": "ses_XYZ", "max_prompt_bytes": 2048 }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
1. Reconstruct the flow with `session-timeline`, filtering `types` to keep it tight.
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{ "session_id": "ses_XYZ", "types": ["tool", "patch"], "limit": 100 }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
1. Expand a specific event with `get-message` (whole turn) or `get-part` (one part).
|
|
73
|
+
For tool output that was externalized to a file, set `dereference_output_path`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{ "part_id": "prt_ABC", "dereference_output_path": true }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
1. Trace dispatch chains with `session-genealogy` when a session spawned subagents.
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{ "session_id": "ses_XYZ", "direction": "both", "max_depth": 5 }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Related Docs
|
|
86
|
+
|
|
87
|
+
- [Search and grep](search-and-grep.md)
|
|
88
|
+
- [Tool reference](../reference/tools.md)
|
|
89
|
+
- [Response format](../reference/response-format.md)
|
|
90
|
+
- [Getting Started](../getting-started.md)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Search And Grep Guide
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Search across the bodies of your entire OpenCode session history, grep inside one
|
|
6
|
+
known session, and audit individual tool invocations by name, status, or substring.
|
|
7
|
+
|
|
8
|
+
## Default Behavior
|
|
9
|
+
|
|
10
|
+
- `search-text` is the canonical "where in my history did X happen?" tool. Its
|
|
11
|
+
default surface is `recall`: session-first, channel-aware, and evidence-limited,
|
|
12
|
+
searching high-signal conversation and session-summary views before raw replay.
|
|
13
|
+
- The default `mode` is `regex` (a drop-in grep that needs no index and always
|
|
14
|
+
works). `lex` adds BM25 phrase search (auto-builds a Tantivy index), while `sem`
|
|
15
|
+
and `hybrid` add semantic embeddings.
|
|
16
|
+
- The default `role` is `any`. Natural-language questions like "where did I mention
|
|
17
|
+
X" or "have I discussed Y" ask about appearances anywhere in the corpus — only set
|
|
18
|
+
`role:'user'` when the question is explicitly about prompts you authored.
|
|
19
|
+
- For unscoped recall, results default to one row per matching session
|
|
20
|
+
(`group_by_session`); scoped, single-session searches default to flat per-part hits.
|
|
21
|
+
- Snippets redact common secret shapes by default. Pass `redact:false` only for
|
|
22
|
+
local forensics.
|
|
23
|
+
|
|
24
|
+
### The `ck` Dependency
|
|
25
|
+
|
|
26
|
+
`search-text` and `grep-session` shell out to the optional [`ck`](https://github.com/BeaconBay/ck)
|
|
27
|
+
CLI over the filesystem export tree. If `ck` is not installed, both return
|
|
28
|
+
`CK_NOT_FOUND` cleanly; the other 16 tools keep working without it. Semantic modes
|
|
29
|
+
additionally require a one-time `ck --index .` inside the export root — without it,
|
|
30
|
+
`sem`/`hybrid` fall back to `regex` with a warning. See
|
|
31
|
+
[search surfaces](../reference/search-surfaces.md) for the surface/channel model.
|
|
32
|
+
|
|
33
|
+
## Controls
|
|
34
|
+
|
|
35
|
+
| Tool | Use It For | Key Args |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| `search-text` | Cross-session content search across all bodies (prompts, responses, tool I/O, reasoning, patches) | `q`, `mode` (`regex`/`lex`/`sem`/`hybrid`), `surface`, `channels`, `group_by_session`, `role`, `session_ids`, `project_id`, `agent`, `since_ms`/`until_ms`, `archived`, `limit`, `redact` |
|
|
38
|
+
| `grep-session` | Fast regex/lex grep inside one known session | `session_id`, `pattern`, `surface`, `channels`, `mode` (`regex`/`lex`), `fixed_string`, `case_sensitive`, `whole_word`, `context_lines`, `limit`, `redact` |
|
|
39
|
+
| `search-tool-calls` | Find tool invocations by name, status, or input/output/error substring | `tool` (exact or `LIKE` wildcard), `status`, `input_like`, `output_like`, `error_like`, `session_id`, `project_id`, `since_ms`/`until_ms`, `archived`, `limit`, `cursor` |
|
|
40
|
+
|
|
41
|
+
## Recommended Flow
|
|
42
|
+
|
|
43
|
+
1. For a broad recall question, start with `search-text` and let the default
|
|
44
|
+
`recall` surface curate results:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{ "q": "export codec", "limit": 20 }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
1. Speed up cross-session search by pre-filtering scope. Unscoped full-corpus search
|
|
51
|
+
can take 10-30 seconds; scoped searches return in under a second:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{ "q": "retry backoff", "project_id": "global", "since_ms": 1717200000000 }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
1. For exhaustive raw replay over tool output, reasoning, and patches, switch the
|
|
58
|
+
surface:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{ "q": "SQLITE_BUSY", "surface": "forensics" }
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
1. Once you know the session, grep inside it with `grep-session` (faster, narrower):
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{ "session_id": "ses_XYZ", "pattern": "TODO", "context_lines": 2 }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
1. To audit commands rather than prose, use `search-tool-calls` — for example every
|
|
71
|
+
failed `read`, or every Jira MCP call via a `LIKE` wildcard:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{ "tool": "read", "status": "error", "limit": 20 }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{ "tool": "mcp-atlassian_jira_%", "limit": 20 }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Related Docs
|
|
82
|
+
|
|
83
|
+
- [Search surfaces](../reference/search-surfaces.md)
|
|
84
|
+
- [Recall and navigation](recall-and-navigation.md)
|
|
85
|
+
- [Export and maintenance](export-and-maintenance.md)
|
|
86
|
+
- [Tool reference](../reference/tools.md)
|
|
87
|
+
- [Troubleshooting](../support/troubleshooting.md)
|