Repository navigation
fix: OpenCode sessions missing on Windows (#10332) + Pi Shift+Enter submits after tool (#9703) - #10511
fix: OpenCode sessions missing on Windows (#10332) + Pi Shift+Enter submits after tool (#9703)#10511itisvincent wants to merge 2 commits into
Conversation
…i CSI-u Shift+Enter OpenCode stores its SQLite DB at ~/.local/share/opencode/opencode on every platform, including Windows. The OpenCode usage scanner's getXdgDataHome() returned %LOCALAPPDATA% on Windows, so it looked under %LOCALAPPDATA%/opencode (which does not exist), never ran the SQLite session scanner, and OpenCode sessions were missing from Agent Session History. Resolve the data directory to ~/.local/share/opencode on all platforms (XDG_DATA_HOME still wins when set). Exports a pure resolveOpenCodeDataDirectory() so the Windows path is regression-tested without writing to the real home dir. (stablyai#10332) Pi enables the Kitty keyboard protocol at startup and decodes CSI-u, but TUI_AGENT_CONFIG['pi'] never set windowsShiftEnterEncoding, so on Windows Shift+Enter fell back to the flaky live-KKP-flag path: it inserted a newline after start/refocus but submitted the message after a tool ran a subprocess (which reset the KKP flags). Set windowsShiftEnterEncoding: 'csi-u' for pi, mirroring the Droid fix, so the trusted CSI-u route is used reliably. (stablyai#9703) Co-authored-by: Vincent <[email protected]>
📝 WalkthroughWalkthroughThe change updates OpenCode data-directory resolution to use 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/opencode-usage/scanner.test.ts (1)
25-40: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winCover the
OPENCODE_DBoverride in regression tests.These tests cover XDG precedence and the fallback directory, but not the required
OPENCODE_DBoverride. Add a scanner-level case asserting that an explicit database path still takes precedence over the derived directory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 50549d2d-0e0c-4e26-974a-72929c670e8c
📒 Files selected for processing (4)
src/main/opencode-usage/scanner.test.tssrc/main/opencode-usage/scanner.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.tssrc/shared/tui-agent-config.ts
The previous regression test called a newly exported pure resolver with an injected env/homeDir, so on any non-Windows CI host it passed against the buggy code too: main's %LOCALAPPDATA% branch sits behind `process.platform === 'win32'`, which the test never stubbed. It failed on main only with "resolveOpenCodeDataDirectory is not a function". Drive `listOpenCodeDatabases` with `process.platform` stubbed to win32 and a real DB on disk instead, so the test fails on main for the actual reason (scans %LOCALAPPDATA%, finds nothing). That removes the need for the exported options-injection API, so `getOpenCodeDataDirectory` goes back to a 4-line function. Also covers the OPENCODE_DB override per review feedback. Co-authored-by: Orca <[email protected]>
|
Splitting out the Shift+Enter half (#9703) into a clean, rebased PR since the OpenCode Windows-data-dir half (#10332) landed independently in #10362 and this PR now conflicts on The Pi CSI-u Shift+Enter fix is now here: #11769 (rebased onto current |
|
Closing as superseded — the linked issue(s) for this PR were fixed by another change that has already been merged.
Superseding merge: #11769, #10362 Thank you for the contribution! If anything remains unaddressed, please open a new issue or PR against current |
Summary
Two independent Windows bugs, one line of behavior change each.
1. OpenCode sessions missing from Agent Session History on Windows (#10332). OpenCode resolves its data directory through
xdg-basediron every platform, so on Windows its SQLite DB lands at~/.local/share/opencode/opencode.db— not under%LOCALAPPDATA%. This is a known, still-open quirk on OpenCode's side (sst/opencode#8235 — "Config and Data directories follow the Linux XDG standard even on windows"). Orca'sgetOpenCodeDataDirectory()had aprocess.platform === 'win32'branch pointing at%LOCALAPPDATA%\opencode, which never exists. Thereaddirthrew, thecatchswallowed it,listOpenCodeDatabases()returned[], and the OpenCode SQLite scanner was never invoked — so every other agent showed up and only OpenCode was missing. Fix: drop the Windows branch, keeping theXDG_DATA_HOMEoverride.2. Pi Shift+Enter submits instead of inserting a newline after a tool call (#9703).
TUI_AGENT_CONFIG['pi']never setwindowsShiftEnterEncoding, so on Windows Pi could only reach CSI-u via the live-KKP-flag path. Pi pushes the Kitty keyboard protocol once at startup and never re-pushes; when a tool spawns a subprocess that emits a reset sequence (RIS / DECSTR / alt-screen swap), the tracker's flags drop to 0, Orca falls back toEsc+CR, and Pi reads that as a plain Enter → submit. It self-heals on the next pane refocus, which is exactly the reported "works at start, breaks after a tool, fixed by clicking the pane" pattern. Fix: setwindowsShiftEnterEncoding: 'csi-u'forpi, mirroring the existing Droid (#7668) and Grok (#8385) fixes, so the trusted route no longer depends on KKP-flag churn.ELI5
Orca was looking for OpenCode's history file in the wrong folder on Windows, so the Agents panel always showed an empty list for OpenCode even though the history was there — we now look in the folder OpenCode actually uses. Separately, when chatting with the Pi agent on Windows, pressing Shift+Enter to add a new line would accidentally send the message instead, but only right after Pi used a tool. Orca now tells Pi's keypresses apart reliably, so Shift+Enter always just adds a new line.
Proof of fix
Fix A — OpenCode Windows path (#10332)
The regression test drives the real entry point (
listOpenCodeDatabases) withprocess.platformstubbed towin32, a temp$HOME,%LOCALAPPDATA%populated, and a realopencode.dbon disk at the XDG location.With
src/main/opencode-usage/scanner.tschecked out fromorigin/main:With the fix applied:
Verified on a real Windows 11 box (
win32 x64, Node v24.18.0), running both resolution strategies side by side against a seeded DB:An independent directory listing on that same box confirms
C:\Users\neil\.local\share\is a real, populated location (it already holdsclaudeanddevex), while a recursive search foropencode.dbunder%LOCALAPPDATA%and%APPDATA%returns nothing.Confirmed on a real Windows 11 box (win32 x64) — the premise is not inferred from the upstream issue, it is observed on disk:
OpenCode's data directory is present at the XDG path and absent from both
%LOCALAPPDATA%and%APPDATA%— exactly the directorymainwas reading, which is whyreaddirthrew and the scanner silently returned[]. (opencode.dbitself is absent on that box because OpenCode has not been run there; the directory location is the claim under test.)Fix B — Pi Shift+Enter (#9703)
With
src/shared/tui-agent-config.tschecked out fromorigin/main:With the fix applied:
Proof of no regressions
No user-visible behavior changes beyond the two fixes. Justification:
process.platform === 'win32'branch. macOS and Linux never entered it, so their resolved path is byte-identical. TheXDG_DATA_HOMEandOPENCODE_DBoverrides are unchanged and both are now covered by tests (theOPENCODE_DBcase was added per review feedback). The only behavior that changes is on Windows, where the scanned directory moves from a path that never exists to the one that does.TUI_AGENT_CONFIG. I diffed the file againstorigin/main: the only changed lines are inside thepientry (a trailing comma, a comment, and the new key). Claude, Codex, OpenCode, Cursor, Gemini, Grok, Droid and every other agent config are byte-unchanged. Plain Enter is untouched — it is handled by a different branch ofterminal-shortcut-policy.tsthat never consults this config, and the Shift+Enter branch is the only reader. A new test pins that trusted agents without an override (gemini, cursor, codex) still resolve toalt-enter.Compatibility
isWindowsTerminalHost()at the call site interminal-shortcut-policy.ts, and an existing test already pins that off-Windows panes require active KKP negotiation regardless of the configured encoding. All paths usepath.join; no separator is hardcoded. Note thatlistOpenCodeDatabasesusesreaddirplus a filename regex rather than a glob library, so there is no forward-slash-in-pattern hazard.session-scanner-opencode-sources.ts, which already used~/.local/share/opencodefor WSL homes and is untouched by this PR. This change only affects the local-host lookup, which now agrees with the WSL logic instead of contradicting it.path.joinin a scan that already hits the filesystem. Fix B is a record property read, and the call site is lazy —getWindowsShiftEnterEncodingis only invoked on Shift+Enter, never on ordinary keystrokes (an existing test asserts this).Screenshots
No visual change.
Testing
pnpm lint(npx oxlinton the changed files)pnpm typecheck(config/tsconfig.node.json+config/tsconfig.tc.web.json)pnpm test— ran the affected suites rather than the full 30+ min suite:src/main/opencode-usage/,src/main/ai-vault/, and the fourterminal-panesuites covering Shift+Enter (766 tests, all passing)pnpm buildAI Review Report
Reviewed for correctness, cross-platform behavior, SSH/remote impact, performance, and regression surface.
The review flagged one real defect in the original patch, which is fixed here. The first version of the Fix A regression test exported a new pure resolver
resolveOpenCodeDataDirectory({ env, homeDir })and asserted against injected values. That test was vacuous: main's bug lives behindprocess.platform === 'win32', which the test never stubbed, so on any non-Windows CI host main's own logic satisfies the same assertion. Transplanting main's resolver verbatim and running the assertion against it confirmed it returns the expected value on macOS/Linux. Onorigin/mainthe test failed only withTypeError: resolveOpenCodeDataDirectory is not a function— i.e. it was detecting a missing symbol, not a wrong path, and would have kept passing if someone reintroduced the%LOCALAPPDATA%branch. Replaced it with a test that drives the reallistOpenCodeDatabasesentry point withprocess.platformstubbed towin32and a real DB on disk; it now fails on main for the correct reason (see Proof of fix). That also made the exported options-injection API unnecessary, sogetOpenCodeDataDirectoryis back to a 4-line private function and the production diff shrank.Cross-platform compatibility was checked explicitly for macOS, Linux, and Windows, covering path separators, drive letters, the glob-vs-
readdirdistinction, shortcut byte protocols, and the Windows-host gating of the Shift+Enter encoding — see Compatibility above for the per-platform findings. The review also confirmed neither bug is already fixed onmain, and that the Fix B config change touches only thepientry.Security Audit
No new attack surface. No command execution, no network calls, no IPC surface, no auth or secret handling, no dependency changes.
homedir()or the pre-existingXDG_DATA_HOMEoverride, and the filename filter remains an anchored regex (/^opencode(?:-[A-Za-z0-9_.-]+)?\.db$/) applied toreaddirentry names, so it cannot traverse outside the data directory. Reads stay wrapped in the existingtry/catch.\x1b[13;2u) and is only reachable via trusted foreground process evidence. Hook- and OSC-derived status remain excluded from routing authority, so PTY output still cannot forge it — the existing test covering that is unchanged and passing.No follow-up security work needed.
Notes
src/main/opencode-usage/vssrc/shared/) with no shared code, no shared test file, and no interaction. Splitting would add review overhead without reducing risk; each fix has its own separately-labelled failing-on-main proof above, so either can be reverted alone.listOpenCodeDatabases()still swallowsreaddirerrors and returns[], so a genuinely unreadable or missing data directory remains silent in the UI. That is what made [Bug]: OpenCode sessions missing from Agent Session History on Windows —getXdgDataHome()returns%LOCALAPPDATA%instead of~/.local/share#10332 hard to diagnose in the first place. Surfacing anAiVaultScanIssuethere is a worthwhile follow-up but is deliberately out of scope for a targeted bugfix.windowsShiftEnterEncodingrelies on live KKP flags that tool subprocesses can reset — still applies to the remaining agents. Making the KKP tracker resilient to reset sequences, or re-pushing KKP on focus return, would fix the whole class rather than one agent at a time; that is a larger change and a good follow-up.Closes #10332
Closes #9703
Original patch by @itisvincent.