opencode-db-search 1.0.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/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # opencode-db-search
2
+
3
+ > Where did my session go?
4
+
5
+ A CLI tool for searching and inspecting [OpenCode](https://github.com/sst/opencode) sessions directly from the SQLite database -- without the filters, lookback windows, or project scoping that can hide them in the TUI.
6
+
7
+ ## The problem
8
+
9
+ OpenCode's session list applies several invisible filters:
10
+
11
+ - **30-day lookback** -- sessions older than 30 days disappear from the TUI
12
+ - **Project scoping** -- only sessions matching the current git repo are shown
13
+ - **Fork filtering** -- subagent/fork sessions are hidden by default
14
+ - **Channel isolation** -- dev builds (`opencode-local.db`) and release builds (`opencode.db`) use separate databases
15
+
16
+ When a session goes missing, there's no built-in way to find it. This tool queries the raw SQLite database with no filters, so you can always find any session.
17
+
18
+ ## Install
19
+
20
+ Requires [Bun](https://bun.sh) v1.0+.
21
+
22
+ ```sh
23
+ # From npm
24
+ bun install -g opencode-db-search
25
+
26
+ # From GitHub
27
+ bun install -g github:rmk40/opencode-db-search
28
+
29
+ # From a local clone
30
+ git clone https://github.com/rmk40/opencode-db-search && cd opencode-db-search && bun link
31
+ ```
32
+
33
+ If `~/.bun/bin` is not on your PATH, add it:
34
+
35
+ ```sh
36
+ export PATH="$HOME/.bun/bin:$PATH"
37
+ ```
38
+
39
+ ## Quick start
40
+
41
+ ```sh
42
+ # What databases exist?
43
+ opencode-db-search dbs
44
+
45
+ # List all sessions across all projects
46
+ opencode-db-search sessions --all
47
+
48
+ # Search for a session by keyword
49
+ opencode-db-search search "refactor auth"
50
+
51
+ # Why isn't -c picking my session?
52
+ opencode-db-search latest
53
+
54
+ # Get full details on a session
55
+ opencode-db-search inspect ses_abc123...
56
+
57
+ # Open a session in OpenCode
58
+ opencode-db-search load ses_abc123...
59
+ ```
60
+
61
+ ## Example output
62
+
63
+ ```
64
+ $ opencode-db-search sessions --all --limit 5
65
+ ┌──────────────────────────┬───────────────────────────┬──────────────────────────┬──────────┬──────┐
66
+ │ ID │ Title │ Directory │ Updated │ Msgs │
67
+ ├──────────────────────────┼───────────────────────────┼──────────────────────────┼──────────┼──────┤
68
+ │ ses_27b4926f3ffe9q475j… │ Refactor auth middleware │ /home/user/projects/app │ just now │ 142 │
69
+ │ ses_2be0ef954ffeImu3vl… │ Fix pagination bug │ /home/user/projects/api │ 1h ago │ 1050 │
70
+ │ ses_2957fa195ffemZs3FU… │ Add dark mode │ /home/user/projects/web │ 3h ago │ 64 │
71
+ │ ses_2c40c9050ffeYUwQ75… │ Deploy pipeline │ /home/user/infra │ 2d ago │ 737 │
72
+ │ ses_1b632aafa8931d2e61… │ Initial setup │ /home/user/projects/app │ 12d ago │ 79 │
73
+ └──────────────────────────┴───────────────────────────┴──────────────────────────┴──────────┴──────┘
74
+ 5 session(s)
75
+ ```
76
+
77
+ ```
78
+ $ opencode-db-search latest
79
+ Project
80
+ ID 4b0ea68d7af9a6031a7ffda7ad66e0cb83315750
81
+ Source inferred from cwd
82
+
83
+ TUI mode (-c)
84
+ Session ses_27b4926f3ffe9q475jVn131I3j
85
+ Title Refactor auth middleware
86
+ Updated 2026-04-13 03:40:18
87
+ Directory /home/user/projects/app
88
+
89
+ Headless mode (run -c)
90
+ Same as TUI mode
91
+
92
+ Root sessions 12
93
+ Outside 30d window 3
94
+ ```
95
+
96
+ ## Commands
97
+
98
+ | Command | Description |
99
+ | ---------------- | --------------------------------------------------------- |
100
+ | `dbs` | List available database files with size, age, and channel |
101
+ | `projects` | List all projects with session counts |
102
+ | `sessions` | List sessions with filtering by project, date, status |
103
+ | `messages <id>` | Show messages in a session |
104
+ | `parts <id>` | Show message parts (text, tool calls, reasoning) |
105
+ | `search <query>` | Full-text search across titles and content |
106
+ | `inspect <id>` | Detailed session info: stats, tokens, cost, todos |
107
+ | `latest` | Debug why `-c` picks (or doesn't pick) a session |
108
+ | `load <id>` | Open a session directly in OpenCode |
109
+
110
+ Every command supports `--json` for machine-readable output.
111
+
112
+ ## Key flags
113
+
114
+ ```sh
115
+ # Show sessions from all projects, not just current
116
+ opencode-db-search sessions --all
117
+
118
+ # Include archived and fork sessions
119
+ opencode-db-search sessions --archived --forks
120
+
121
+ # Filter by date range
122
+ opencode-db-search sessions --since 2024-01-01 --before 2024-02-01
123
+
124
+ # Use a specific database file
125
+ opencode-db-search sessions --db ~/.local/share/opencode/opencode-local.db
126
+
127
+ # Search only titles, or only content
128
+ opencode-db-search search "query" --scope title
129
+ opencode-db-search search "query" --scope content
130
+
131
+ # Preview what load would do
132
+ opencode-db-search load ses_abc123 --dry-run
133
+ ```
134
+
135
+ ## How it finds the database
136
+
137
+ 1. `--db <path>` flag (explicit)
138
+ 2. `$OPENCODE_DB` environment variable
139
+ 3. `--channel <name>` flag (`local` -> `opencode-local.db`, etc.)
140
+ 4. Auto-detect: most recently modified `opencode*.db` in `~/.local/share/opencode/`
141
+
142
+ ## How it scopes to your project
143
+
144
+ By default, `sessions` and `latest` filter to the current project, inferred from:
145
+
146
+ 1. Cached ID in `.git/opencode` (matches OpenCode's own logic)
147
+ 2. Git root commit hash
148
+ 3. Falls back to `"global"` outside git repos
149
+
150
+ Use `--all` to see everything, or `--project <id>` to target a specific project.
151
+
152
+ ## License
153
+
154
+ MIT