fix(opencode): probe XDG path on Windows for session storage#1026
fix(opencode): probe XDG path on Windows for session storage#1026pedramamini wants to merge 1 commit into
Conversation
OpenCode v1.2+ on Windows actually stores its SQLite database and JSON files under %USERPROFILE%\.local\share\opencode (XDG-style), not %APPDATA%\opencode. Maestro's hard-coded %APPDATA% probe meant Windows users saw empty Session History even when `opencode session list` worked. Resolve the data dir by checking each candidate (XDG_DATA_HOME -> ~/.local/share/opencode -> %APPDATA%\opencode on Windows) and picking the first that exists, so both current and legacy installs are found. Closes #1025
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR updates OpenCode storage path discovery to search across XDG, Linux home, and Windows APPDATA directories. Instead of checking a single hardcoded location, it now builds an ordered list of candidates and returns the first existing directory, with a deterministic fallback for new installations or database initialization. ChangesMulti-platform OpenCode storage discovery
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes OpenCode session discovery on Windows by replacing the hard-coded single path with a candidate-list probe that respects
Confidence Score: 3/5Safe to merge for the primary use case, but the JSON-storage fallback path can silently miss legacy sessions in mixed-install environments where both an XDG directory and an APPDATA directory coexist. The fix correctly resolves the reported Windows XDG path issue for the primary SQLite flow. However, the JSON fallback uses a weaker probe (directory existence vs. file existence), meaning legacy pre-v1.2 sessions stored in APPDATA could be invisible when both directories exist. src/main/storage/opencode-session-storage.ts — specifically the getOpenCodeStorageDir/getOpenCodeDataDir interaction and the fallback return path in getOpenCodeDbPath. Important Files Changed
|
| function getOpenCodeDbPath(): string { | ||
| return path.join(getOpenCodeDataDir(), 'opencode.db'); | ||
| for (const candidate of getOpenCodeDataDirCandidates()) { | ||
| const dbPath = path.join(candidate, 'opencode.db'); | ||
| if (fsSync.existsSync(dbPath)) { | ||
| return dbPath; | ||
| } | ||
| } | ||
| return path.join(getOpenCodeDataDirCandidates()[0], 'opencode.db'); | ||
| } |
There was a problem hiding this comment.
getOpenCodeDbPath() calls getOpenCodeDataDirCandidates() twice: once for the loop and once again in the fallback return. The second call is redundant — the candidates are already known from the first iteration. Cache the result to avoid the duplicate work.
| function getOpenCodeDbPath(): string { | |
| return path.join(getOpenCodeDataDir(), 'opencode.db'); | |
| for (const candidate of getOpenCodeDataDirCandidates()) { | |
| const dbPath = path.join(candidate, 'opencode.db'); | |
| if (fsSync.existsSync(dbPath)) { | |
| return dbPath; | |
| } | |
| } | |
| return path.join(getOpenCodeDataDirCandidates()[0], 'opencode.db'); | |
| } | |
| function getOpenCodeDbPath(): string { | |
| const candidates = getOpenCodeDataDirCandidates(); | |
| for (const candidate of candidates) { | |
| const dbPath = path.join(candidate, 'opencode.db'); | |
| if (fsSync.existsSync(dbPath)) { | |
| return dbPath; | |
| } | |
| } | |
| return path.join(candidates[0], 'opencode.db'); | |
| } |
Summary
%USERPROFILE%\.local\share\opencode(XDG-style), not%APPDATA%\opencode. As a result, Maestro's OpenCode session history was empty on Windows even whenopencode session listreturned sessions.getOpenCodeDataDir()now resolves through a candidate list (XDG_DATA_HOME→~/.local/share/opencode→%APPDATA%\opencodeon Windows) and picks the first that exists, so both current and legacy installs are discovered.getOpenCodeDbPath()performs the same probe so the SQLite reader hits the correct file regardless of which candidate dir holds it.Closes #1025
Test plan
opencode session list.%APPDATA%\opencode\storageJSON layout exists, confirm sessions still appear (fallback path).maestro-cli list sessions <opencode-agent-id> --jsonreturns the expectedtotalCounton each platform above.Summary by CodeRabbit