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,86 @@
1
+ # Docs Writing Standard
2
+
3
+ ## Purpose
4
+
5
+ Define consistent structure, markdown style, and explanation patterns for
6
+ project docs.
7
+
8
+ ## Core Principles
9
+
10
+ - Lead with user outcome, then steps, then edge cases.
11
+ - One page should have one clear intent.
12
+ - Prefer short concrete statements over broad prose.
13
+ - Use stable terms (`search-text`, `unarchive-session`, `OPENCODE_SESSIONS_EXPLORER_DB`)
14
+ consistently.
15
+
16
+ ## Page Type Templates
17
+
18
+ ### Start Pages
19
+
20
+ Use sections in this order:
21
+
22
+ 1. `Purpose`
23
+ 1. `Prerequisites`
24
+ 1. `Setup` or `Steps`
25
+ 1. `Validate` (how to confirm success)
26
+ 1. `Next steps`
27
+
28
+ ### Guides
29
+
30
+ Use sections in this order:
31
+
32
+ 1. `Purpose`
33
+ 1. `Default behavior` or `Mental model`
34
+ 1. `Controls` or `Entry points`
35
+ 1. `Recommended flow`
36
+ 1. `Related docs`
37
+
38
+ ### Reference Pages
39
+
40
+ Use sections in this order:
41
+
42
+ 1. `Scope`
43
+ 1. `Definitions/Tables`
44
+ 1. `Examples`
45
+ 1. `Related docs`
46
+
47
+ ### Troubleshooting Pages
48
+
49
+ Use sections in this order:
50
+
51
+ 1. `How to use this page`
52
+ 1. `Baseline checks`
53
+ 1. Symptom blocks (`Quick checks`, `Fix`)
54
+ 1. `Related docs`
55
+
56
+ ## Markdown Conventions
57
+
58
+ - Keep headings concise and in Title Case.
59
+ - Use numbered lists (`1.` style) for procedures.
60
+ - Use tables for command/option/tool inventories.
61
+ - Wrap commands, paths, options, env vars, and tool names in backticks.
62
+ - Prefer fenced code blocks with language identifiers.
63
+ - End pages with a `Related Docs` section.
64
+
65
+ ## Explanation Pattern
66
+
67
+ Use this order for each important concept:
68
+
69
+ 1. What it is
70
+ 1. Why it matters
71
+ 1. How to use it
72
+ 1. How to validate it
73
+ 1. Where to go next
74
+
75
+ ## Link Policy
76
+
77
+ - Keep canonical maintainer pages under `docs/maintainers/`.
78
+ - Use relative links between docs and back to root files (`../../README.md`).
79
+ - Update the "Maintainer Docs" list in [`CONTRIBUTING.md`](../../CONTRIBUTING.md)
80
+ whenever docs paths or ownership change.
81
+
82
+ ## Related Docs
83
+
84
+ - [Development Guide](development.md)
85
+ - [Release Guide](release.md)
86
+ - [Triage Guide](triage.md)
@@ -0,0 +1,72 @@
1
+ # Release Guide
2
+
3
+ ## Purpose
4
+
5
+ Define repeatable steps to cut and publish a release of
6
+ `opencode-sessions-explorer` to npm and GitHub.
7
+
8
+ ## Versioning
9
+
10
+ Use [SemVer](https://semver.org/spec/v2.0.0.html):
11
+
12
+ - Major: breaking changes
13
+ - Minor: new features
14
+ - Patch: fixes and docs
15
+
16
+ ## Release Checklist
17
+
18
+ 1. Bump the version in `package.json` to the target `x.y.z`.
19
+ 1. Move the `## [Unreleased]` notes in `CHANGELOG.md` into a new
20
+ `## [x.y.z] - YYYY-MM-DD` section, and leave an empty `## [Unreleased]`
21
+ above it for the next cycle.
22
+ 1. Run the quality gates locally and confirm they pass:
23
+
24
+ ```bash
25
+ bun run typecheck
26
+ bun test
27
+ bun run build
28
+ ```
29
+
30
+ 1. Confirm the **CI** workflow (`.github/workflows/ci.yml`) is green on the
31
+ commit you intend to tag.
32
+ 1. Commit the version bump and changelog (for example
33
+ `chore(release): vX.Y.Z`).
34
+ 1. Create an annotated tag and push it:
35
+
36
+ ```bash
37
+ git tag -a vX.Y.Z -m "vX.Y.Z"
38
+ git push origin vX.Y.Z
39
+ ```
40
+
41
+ Pushing a `vX.Y.Z` tag triggers `.github/workflows/publish.yml`, which publishes
42
+ the package to npm with provenance and creates the GitHub Release from the
43
+ changelog entry.
44
+
45
+ ## Publish Bootstrap (first release only)
46
+
47
+ The publish workflow is configured for npm
48
+ [Trusted Publishing (OIDC)](https://docs.npmjs.com/trusted-publishers), which
49
+ needs the package to already exist on npm before OIDC can be linked. Bootstrap it
50
+ once:
51
+
52
+ 1. Create a short-lived **automation** npm token and add it to the repository as
53
+ the `NPM_TOKEN` secret.
54
+ 1. Cut the first release (`v0.1.0`) so `publish.yml` publishes the initial
55
+ version to npm using that token.
56
+ 1. In the npm package settings, configure **Trusted Publishing** for this repo's
57
+ `.github/workflows/publish.yml`.
58
+ 1. **Revoke** the `NPM_TOKEN` secret and the npm token. Subsequent releases
59
+ authenticate via OIDC with no long-lived secret.
60
+
61
+ ## Post-Release
62
+
63
+ - Verify the new version is live on
64
+ [npm](https://www.npmjs.com/package/opencode-sessions-explorer) and that the
65
+ GitHub Release was created.
66
+ - Monitor issues for regressions.
67
+ - Triage and label follow-up reports (see [Triage Guide](triage.md)).
68
+
69
+ ## Related Docs
70
+
71
+ - [Development Guide](development.md)
72
+ - [Triage Guide](triage.md)
@@ -0,0 +1,55 @@
1
+ # Triage Guide
2
+
3
+ ## Purpose
4
+
5
+ Define issue intake, labeling, and follow-up policy. The canonical label
6
+ definitions live in [`.github/labels.yml`](../../.github/labels.yml); this guide
7
+ documents how they are applied.
8
+
9
+ ## Intake Flow
10
+
11
+ 1. Confirm issue template quality (clear repro, version, environment).
12
+ 1. Reproduce the issue when possible.
13
+ 1. Apply labels for type, status, and scope.
14
+
15
+ ## Label Set
16
+
17
+ Issue type:
18
+
19
+ - `bug` — something is not working
20
+ - `enhancement` — new feature or request
21
+ - `documentation` — documentation updates
22
+ - `security` — security related issues
23
+ - `question` — further information requested
24
+
25
+ Contributor signals:
26
+
27
+ - `help wanted` — extra attention is needed
28
+ - `good first issue` — good for newcomers
29
+
30
+ Implementation focus:
31
+
32
+ - `tests` — test coverage or fixes
33
+ - `refactor` — refactoring or cleanup
34
+ - `chore` — maintenance tasks
35
+
36
+ Triage status:
37
+
38
+ - `triage/needs-info` — needs more information from the reporter
39
+ - `triage/confirmed` — repro confirmed by maintainers
40
+ - `triage/blocked` — blocked on an external dependency or upstream (e.g.
41
+ OpenCode or `ck`)
42
+ - `triage/duplicate` — duplicate of an existing issue
43
+ - `triage/wontfix` — will not be addressed
44
+
45
+ ## Follow-Up Policy
46
+
47
+ - Close `triage/needs-info` after 14 days without a response.
48
+ - For `triage/blocked`, document the blocker and a recheck date.
49
+ - Close `triage/duplicate` with a link to the canonical issue.
50
+ - Close `triage/wontfix` with a concise rationale and alternatives when possible.
51
+
52
+ ## Related Docs
53
+
54
+ - [Development Guide](development.md)
55
+ - [Release Guide](release.md)
@@ -0,0 +1,112 @@
1
+ # Architecture Reference
2
+
3
+ ## Scope
4
+
5
+ This page describes the four-layer pipeline that turns the OpenCode session
6
+ database into enriched, searchable tool responses, and the single-writer exception
7
+ to the otherwise read-only design. It is a conceptual reference; for the
8
+ contributor-facing build and code layout, see the
9
+ [Development Guide](../maintainers/development.md).
10
+
11
+ ## The Four Layers
12
+
13
+ ```
14
+ L1 SQLite DB (read-only source of truth)
15
+ | PRAGMA query_only = 1; opened readonly
16
+ v
17
+ L2 filesystem export tree (~/.local/share/opencode-sessions-explorer)
18
+ | by-session/<ses_id>/... + by-channel/<channel>/by-session/<ses_id>/...
19
+ | delta-synced before each search call
20
+ v
21
+ L3 ck index (.ck/, BM25 + embeddings; optional)
22
+ | incremental; built by the ck CLI
23
+ v
24
+ L4 enriched response
25
+ | re-fetches session/part metadata from SQLite per hit
26
+ v
27
+ { ok, data, meta, warnings } envelope
28
+ ```
29
+
30
+ ### L1 — SQLite Source Of Truth
31
+
32
+ The OpenCode database is the authoritative source. The shared handle opens it
33
+ read-only and sets `PRAGMA query_only = 1` as a belt-and-braces guard, so any
34
+ accidental write through that handle throws. The live OpenCode process may be
35
+ writing concurrently — the database runs in WAL mode and multiple readers plus a
36
+ writer is safe, with a `busy_timeout` covering rare lock collisions. All metadata,
37
+ counts, and message/part bodies ultimately come from here.
38
+
39
+ ### L2 — Filesystem Export Tree
40
+
41
+ Searchable content is materialized to a filesystem tree (default
42
+ `~/.local/share/opencode-sessions-explorer`, overridable via
43
+ `OPENCODE_SESSIONS_EXPLORER_EXPORT_ROOT`). It has two arms:
44
+
45
+ - `by-session/<ses_id>/` — the raw, lossless per-part export plus `meta.json`.
46
+ - `by-channel/<channel>/by-session/<ses_id>/` — curated channel views derived from
47
+ the raw parts (see [search-surfaces.md](search-surfaces.md)).
48
+
49
+ The tree is built once by `opencode-sessions-explorer-bulk-export` and then
50
+ delta-synced automatically before each `search-text` / `grep-session` call, so new
51
+ parts become searchable without a manual re-export. Sync is cursor-based on
52
+ `(time_updated, id)`, which also re-exports parts whose status mutated since the last
53
+ pass.
54
+
55
+ ### L3 — ck Index (Optional)
56
+
57
+ `search-text` and `grep-session` shell out to the [`ck`](https://github.com/BeaconBay/ck)
58
+ CLI, which walks the export tree. `ck` supports plain regex with no index, a BM25
59
+ full-text index, and semantic embeddings; the index lives under `.ck/` in the export
60
+ root and is incremental. `ck` is optional: when it is absent these two tools return
61
+ `CK_NOT_FOUND` cleanly and the other 16 tools are unaffected.
62
+
63
+ ### L4 — Enriched Response
64
+
65
+ Search hits from `ck` carry file paths, not domain objects. The final layer parses
66
+ the session and part ids out of each hit path and re-fetches fresh metadata from
67
+ SQLite (session title, agent, model, part type, message role) before returning
68
+ results. Every tool wraps its payload in a uniform `{ ok, data, meta, warnings }`
69
+ envelope; list-shaped data inside `data` uses the compact format described in
70
+ [response-format.md](response-format.md).
71
+
72
+ ## Single-Writer Exception
73
+
74
+ The plugin is read-only with exactly one sanctioned write: `unarchive-session`.
75
+ Reads never write through the shared read-only handle. The write goes through a
76
+ separate, short-lived read-write connection that performs a single statement —
77
+ `UPDATE session SET time_archived = NULL, time_updated = <now>` — and closes
78
+ immediately.
79
+
80
+ Both fields are updated deliberately. OpenCode loads sessions ordered by
81
+ `time_updated DESC` with a default limit per directory, so clearing `time_archived`
82
+ alone would leave a long-archived session buried below that window, and opening it
83
+ would fail with "Unable to retrieve session". Refreshing `time_updated` resurfaces
84
+ the session at the top of the list, which is also the intuitive meaning of
85
+ "restore". OpenCode exposes no HTTP or SDK endpoint that can *clear* the archived
86
+ flag, so the direct database write is the only mechanism.
87
+
88
+ ## Examples
89
+
90
+ Materialize the export tree (L2), then build the optional `ck` index (L3):
91
+
92
+ ```bash
93
+ bunx opencode-sessions-explorer-bulk-export
94
+ cd ~/.local/share/opencode-sessions-explorer
95
+ ck --index . # run in the export root, not the repository checkout
96
+ ```
97
+
98
+ Verify all four layers are healthy:
99
+
100
+ ```bash
101
+ bunx opencode-sessions-explorer-check-deps
102
+ ```
103
+
104
+ ## Related Docs
105
+
106
+ - Tool catalog: [tools.md](tools.md)
107
+ - Search surfaces and channels: [search-surfaces.md](search-surfaces.md)
108
+ - Compact result format: [response-format.md](response-format.md)
109
+ - Configuration and environment overrides: [configuration.md](configuration.md)
110
+ - Export and maintenance workflow: [../guides/export-and-maintenance.md](../guides/export-and-maintenance.md)
111
+ - Development Guide: [../maintainers/development.md](../maintainers/development.md)
112
+ - Troubleshooting: [../support/troubleshooting.md](../support/troubleshooting.md)
@@ -0,0 +1,115 @@
1
+ # Configuration Reference
2
+
3
+ ## Scope
4
+
5
+ This page documents how to configure `opencode-sessions-explorer`: the OpenCode
6
+ `permission` rule the plugin needs, the environment variables that override every
7
+ filesystem path, and the opt-in switch for running the test suite against real
8
+ session data.
9
+
10
+ The plugin has no settings object of its own — it is configured entirely through
11
+ OpenCode permissions and environment variables. All defaults work out of the box on
12
+ macOS and Linux; Windows paths resolve via `%LOCALAPPDATA%`.
13
+
14
+ ## Required Permission
15
+
16
+ The OpenCode session database lives outside your project workspace, so OpenCode
17
+ must be granted access to its data directory. Add an `external_directory` allow rule
18
+ to your OpenCode config and restart:
19
+
20
+ ```jsonc
21
+ // ~/.config/opencode/opencode.json
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
+ Without this rule the read-only database handle cannot open the file and tools fail
34
+ with `DB_NOT_FOUND` or a permission error. The change takes effect only after a full
35
+ OpenCode restart. See [Permission Denied / external_directory](../support/troubleshooting.md#permission-denied--external_directory)
36
+ if a tool still cannot reach the database after adding the rule.
37
+
38
+ The snippet above covers the common macOS/Linux default path. If `$XDG_DATA_HOME`,
39
+ Windows `%LOCALAPPDATA%`, or `OPENCODE_SESSIONS_EXPLORER_DB` points to another
40
+ database location, allow the actual directory that contains `opencode.db` and
41
+ restart OpenCode. Some existing global configs may set `external_directory: "allow"`;
42
+ that grants broad access and is useful for local power users, but the scoped path
43
+ rule is preferred for normal installs.
44
+
45
+ ## Runtime Compatibility
46
+
47
+ The plugin targets the OpenCode plugin host contract provided by
48
+ `@opencode-ai/plugin >= 1.15.0`. It runs on Bun and uses `bun:sqlite`, which should
49
+ include SQLite `json1`; the bundled health probes (`check-deps` CLI and `db-stats`
50
+ tool) verify `json1`, schema drift, and database runtime settings for the active
51
+ OpenCode database.
52
+
53
+ ## Environment Overrides
54
+
55
+ Every path the plugin uses is overridable through an environment variable. These are
56
+ the simplest way to point the plugin (or its tests) at non-default locations.
57
+
58
+ | Variable | Default | Purpose |
59
+ | --- | --- | --- |
60
+ | `OPENCODE_SESSIONS_EXPLORER_DB` | `$XDG_DATA_HOME/opencode/opencode.db` (macOS/Linux) or `%LOCALAPPDATA%\opencode\opencode.db` (Windows); falls back to `~/.local/share/opencode/opencode.db` | Absolute path to the OpenCode SQLite database the plugin reads. Set this when the database is not in the default OpenCode data directory. |
61
+ | `OPENCODE_SESSIONS_EXPLORER_EXPORT_ROOT` | `~/.local/share/opencode-sessions-explorer` | Directory where searchable session content is materialized (the `by-session` and `by-channel` export trees that `ck` indexes). |
62
+ | `OPENCODE_SESSIONS_EXPLORER_TOOL_OUTPUT_DIR` | `$XDG_DATA_HOME/opencode/tool-output` (macOS/Linux) or `%LOCALAPPDATA%\opencode\tool-output` (Windows); falls back to `~/.local/share/opencode/tool-output` | Whitelist root for `get-part` dereference. Only files resolving inside this root may be read when `dereference_output_path:true`; any other path is rejected with `PATH_TRAVERSAL`. |
63
+ | `OPENCODE_SESSIONS_EXPLORER_CK_BIN` | `ck` discovered on `PATH` | Absolute path to the `ck` binary. Set this when `ck` is installed outside `PATH`; only `search-text` and `grep-session` use it. |
64
+
65
+ ### `get-part` Dereference Guard
66
+
67
+ The `OPENCODE_SESSIONS_EXPLORER_TOOL_OUTPUT_DIR` whitelist is enforced before any
68
+ externalized tool output is read. Symlinks are resolved before the path is compared
69
+ to the root, so a symlink inside the whitelist that points outside it is also
70
+ rejected. This is why `get-part` returns `PATH_TRAVERSAL` for any path outside the
71
+ tool-output directory — see the troubleshooting page for the recovery steps.
72
+
73
+ ## Testing Override (Dev Only)
74
+
75
+ `bun test` is hermetic by default and runs against a synthetic fixture database. To
76
+ exercise the suite against real session data instead, opt in with:
77
+
78
+ ```bash
79
+ OPENCODE_SESSIONS_EXPLORER_LIVE=1 bun test
80
+ ```
81
+
82
+ Live runs read real `ses_`/`msg_`/`prt_` ids and minimum counts from your own
83
+ history, so failures there reflect local data rather than a regression. This switch
84
+ is for contributors only and has no effect on the plugin at runtime; see the
85
+ [Development Guide](../maintainers/development.md) for the full contributor loop.
86
+
87
+ ## Examples
88
+
89
+ Point the plugin at a database in a custom location:
90
+
91
+ ```bash
92
+ export OPENCODE_SESSIONS_EXPLORER_DB="/data/opencode/opencode.db"
93
+ ```
94
+
95
+ Materialize the search export to a dedicated disk:
96
+
97
+ ```bash
98
+ export OPENCODE_SESSIONS_EXPLORER_EXPORT_ROOT="/fast-ssd/opencode-search"
99
+ bunx opencode-sessions-explorer-bulk-export
100
+ ```
101
+
102
+ Use a `ck` binary that is not on `PATH`:
103
+
104
+ ```bash
105
+ export OPENCODE_SESSIONS_EXPLORER_CK_BIN="$HOME/.cargo/bin/ck"
106
+ ```
107
+
108
+ ## Related Docs
109
+
110
+ - Tool catalog: [tools.md](tools.md)
111
+ - Search surfaces and channels: [search-surfaces.md](search-surfaces.md)
112
+ - Four-layer architecture: [architecture.md](architecture.md)
113
+ - Data exposure and redaction policy: [../../.github/SECURITY.md](../../.github/SECURITY.md)
114
+ - Install walkthrough: [../install.md](../install.md)
115
+ - Troubleshooting: [../support/troubleshooting.md](../support/troubleshooting.md)
@@ -0,0 +1,120 @@
1
+ # Response Format Reference
2
+
3
+ ## Scope
4
+
5
+ This page documents the compact, lossless format that list-shaped tool results use.
6
+ Several tools return arrays of uniform records (sessions, events, tool calls, cost
7
+ groups, search hits). Serializing those as plain arrays-of-objects repeats every
8
+ JSON key on every row and re-serializes the same nested values (model, directory,
9
+ agent) again and again. To cut payload size without losing information, list results
10
+ are encoded as a columnar table with string interning.
11
+
12
+ Scalar, single-object responses (for example `get-session` or `db-stats`) are
13
+ returned as ordinary JSON objects and are **not** encoded this way.
14
+
15
+ ## The Table Shape
16
+
17
+ An encoded list result is an object with three keys:
18
+
19
+ ```json
20
+ {
21
+ "cols": ["id", "title", "agent", "model"],
22
+ "dict": {
23
+ "agent": ["build", "executor-gpt"],
24
+ "model": [{ "id": "claude-opus", "provider": "anthropic" }]
25
+ },
26
+ "rows": [
27
+ ["ses_a1", "Fix retry bug", 0, 0],
28
+ ["ses_b2", "Cost audit", 1, 0]
29
+ ]
30
+ }
31
+ ```
32
+
33
+ - `cols` — the column order; each row is an array of cells in this order.
34
+ - `dict` — interning tables for selected columns. A column listed here stores its
35
+ distinct values once; rows reference them by integer index. Columns absent from
36
+ `dict` store their literal value inline.
37
+ - `rows` — one array per record.
38
+
39
+ ## Decode Rule
40
+
41
+ There is a single decode rule:
42
+
43
+ > A cell in a column whose name is a key in `dict` is an integer index into
44
+ > `dict[col]`. Otherwise the cell is its literal value.
45
+
46
+ Decoding the example above yields:
47
+
48
+ ```json
49
+ [
50
+ { "id": "ses_a1", "title": "Fix retry bug", "agent": "build", "model": { "id": "claude-opus", "provider": "anthropic" } },
51
+ { "id": "ses_b2", "title": "Cost audit", "agent": "executor-gpt", "model": { "id": "claude-opus", "provider": "anthropic" } }
52
+ ]
53
+ ```
54
+
55
+ Note that both rows reuse the same `model` object (index `0`) instead of repeating
56
+ it — that is where the savings come from on large result sets.
57
+
58
+ ## Reference Decoder
59
+
60
+ The plugin ships the inverse function, `decodeTable()`, in
61
+ [`src/lib/table.ts`](../../src/lib/table.ts). It is used by the test suite and is
62
+ safe for consumers to copy. Two behaviors make migration painless:
63
+
64
+ - A plain array passed to `decodeTable()` is returned unchanged, so callers can
65
+ treat encoded and unencoded results uniformly.
66
+ - An out-of-range or non-integer cell in a `dict` column is passed through as its
67
+ literal value rather than throwing.
68
+
69
+ A minimal equivalent decoder:
70
+
71
+ ```ts
72
+ function decodeTable(t) {
73
+ if (t == null) return []
74
+ if (Array.isArray(t)) return t // already plain
75
+ const dict = t.dict ?? {}
76
+ return t.rows.map((row) => {
77
+ const o = {}
78
+ t.cols.forEach((c, i) => {
79
+ const v = row[i]
80
+ const d = dict[c]
81
+ o[c] = d && typeof v === "number" && v >= 0 && v < d.length ? d[v] : v
82
+ })
83
+ return o
84
+ })
85
+ }
86
+ ```
87
+
88
+ ## Examples
89
+
90
+ A `list-sessions` result interns the repetitive `agent`, `model`, `directory`, and
91
+ `project_id` columns:
92
+
93
+ ```json
94
+ {
95
+ "sessions": {
96
+ "cols": ["id", "title", "agent", "model", "directory", "cost"],
97
+ "dict": {
98
+ "agent": ["build"],
99
+ "model": [{ "id": "claude-opus" }],
100
+ "directory": ["/projects/app"],
101
+ "project_id": []
102
+ },
103
+ "rows": [
104
+ ["ses_a1", "Fix retry bug", 0, 0, 0, 0.42]
105
+ ]
106
+ },
107
+ "has_more": false
108
+ }
109
+ ```
110
+
111
+ Apply the decode rule to recover the records, then read `cost` (a literal column)
112
+ directly.
113
+
114
+ ## Related Docs
115
+
116
+ - Tool catalog: [tools.md](tools.md)
117
+ - Search surfaces and channels: [search-surfaces.md](search-surfaces.md)
118
+ - Four-layer architecture: [architecture.md](architecture.md)
119
+ - Configuration and environment overrides: [configuration.md](configuration.md)
120
+ - Troubleshooting: [../support/troubleshooting.md](../support/troubleshooting.md)
@@ -0,0 +1,106 @@
1
+ # Search Surfaces Reference
2
+
3
+ ## Scope
4
+
5
+ This page documents the retrieval presets (`surface`) and the underlying channels
6
+ that `search-text` and `grep-session` use to decide *what* exported content to
7
+ search. Raw session data always stays lossless in the database and export tree;
8
+ channels are derived search views that let default recall search high-signal content
9
+ first while preserving raw drill-down through part and message ids.
10
+
11
+ Both tools accept a `surface` argument and an optional `channels` override. If you
12
+ pass `channels` explicitly, it takes precedence over the surface-derived set.
13
+
14
+ ## Surfaces
15
+
16
+ A surface is a named preset that expands to a curated set of channels. The default
17
+ is `recall`.
18
+
19
+ | Surface | Channels Searched | Use For |
20
+ | --- | --- | --- |
21
+ | `recall` | `conversation`, `session-summary` | Default. Session-first, high-signal recall — "where did I mention X", "find sessions about Y". |
22
+ | `debug_trace` | `conversation`, `session-summary`, `tool-error`, `tool-input-summary` | Investigating failures and what led to them — errors, exceptions, stack traces, logs. |
23
+ | `tool_audit` | `tool-input-summary`, `tool-error` | Auditing tool usage — bash commands, tool calls, MCP calls, and their errors. |
24
+ | `code` | `conversation`, `session-summary`, `code-touch`, `patch-summary`, `tool-input-summary` | Tracing file and code changes — paths, diffs, edits, patches. |
25
+ | `forensics` | `raw` | Exhaustive replay over raw exported bodies, including full tool output and reasoning. Slowest; use when curated channels miss something. |
26
+
27
+ ### Surface Inference
28
+
29
+ When `surface` is left at its default (`recall`), the query text is inspected and
30
+ the surface may be auto-promoted:
31
+
32
+ - Error vocabulary (`error`, `exception`, `stack trace`, `failed`, `timeout`,
33
+ `logs`, `stderr`, `stdout`) promotes to `debug_trace`.
34
+ - Tool vocabulary (`tool calls`, `bash`, `command`, `grep`, `read tool`,
35
+ `edit tool`, `apply_patch`, `mcp`, …) promotes to `tool_audit`.
36
+ - Code vocabulary (`file`, `path`, `class`, `function`, `symbol`, `diff`, `patch`,
37
+ `edited`, `src/`, `.ts`, `.kt`, `.py`, …) promotes to `code`.
38
+
39
+ Passing an explicit non-`recall` surface disables inference and uses that surface
40
+ as-is.
41
+
42
+ ## Channels
43
+
44
+ Channels are the derived views the export tree materializes under
45
+ `by-channel/<channel>/by-session/<ses_id>/`. The raw, lossless export lives under
46
+ `by-session/<ses_id>/` and is reachable through the `raw` channel.
47
+
48
+ | Channel | Contents |
49
+ | --- | --- |
50
+ | `conversation` | User and assistant text, plus subtask prompts. |
51
+ | `session-summary` | Per-session synthesized summary: title, directory, first and last user prompt. |
52
+ | `tool-input-summary` | Compact summary of each tool invocation's inputs (command, paths, query, ids). |
53
+ | `tool-error` | Normalized error text from failed tool calls. |
54
+ | `code-touch` | File paths touched by file tools and patches. |
55
+ | `tool-output` | Raw output bodies produced by tool calls. |
56
+ | `patch-summary` | Files changed per patch, with hash and file count. |
57
+ | `reasoning` | Assistant reasoning text. |
58
+ | `file` | File-reference parts (filename, URL, source path). |
59
+ | `raw` | The full-fidelity per-session export, including every searchable body. Selected by the `forensics` surface. |
60
+
61
+ ## Grep Defaults
62
+
63
+ `grep-session` defaults to the same curated channels as the active surface
64
+ (`recall` → `conversation`, `session-summary`) when the curated channel export is
65
+ available. To search the raw exported bodies of a single session — including tool
66
+ output and reasoning — set `surface:'forensics'` or pass `channels:['raw']`.
67
+
68
+ If the curated channel export is only partial (not yet backfilled), both tools fall
69
+ back to the raw `by-session` export to avoid false negatives and add a warning;
70
+ running `opencode-sessions-explorer-bulk-export --reset` backfills the curated
71
+ channels. See [export-and-maintenance.md](../guides/export-and-maintenance.md).
72
+
73
+ ## Examples
74
+
75
+ Default recall search across all sessions:
76
+
77
+ ```text
78
+ opencode-sessions-explorer-search-text { "q": "rate limiting" }
79
+ ```
80
+
81
+ Force a raw forensic sweep with explicit channels:
82
+
83
+ ```text
84
+ opencode-sessions-explorer-search-text { "q": "AKIA", "surface": "forensics" }
85
+ ```
86
+
87
+ Grep one session's raw bodies (tool output included):
88
+
89
+ ```text
90
+ opencode-sessions-explorer-grep-session { "session_id": "ses_…", "pattern": "ETIMEDOUT", "channels": ["raw"] }
91
+ ```
92
+
93
+ Audit tool inputs and errors only:
94
+
95
+ ```text
96
+ opencode-sessions-explorer-search-text { "q": "git push", "surface": "tool_audit" }
97
+ ```
98
+
99
+ ## Related Docs
100
+
101
+ - Tool catalog: [tools.md](tools.md)
102
+ - Compact result format: [response-format.md](response-format.md)
103
+ - Four-layer architecture: [architecture.md](architecture.md)
104
+ - Search and grep workflow: [../guides/search-and-grep.md](../guides/search-and-grep.md)
105
+ - Export and maintenance workflow: [../guides/export-and-maintenance.md](../guides/export-and-maintenance.md)
106
+ - Troubleshooting: [../support/troubleshooting.md](../support/troubleshooting.md)