Skip to content

Commit 16671b1

Browse files
authored
fix(sleep): add Windows AppData support for default OpenCode database discovery (#56) (#230)
1 parent 9c776fc commit 16671b1

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎docs/reference/cli.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ login, or contact a model provider. Source selection remains explicit:
223223
`--source auto` keeps Codex-then-Claude precedence and does not select OpenCode.
224224

225225
The database path is selected from `--opencode-db` or the `opencode_db` config
226-
key, then `OPENCODE_DB`, then
227-
`${XDG_DATA_HOME:-~/.local/share}/opencode/opencode.db`. A relative
226+
key, then `OPENCODE_DB`, then `%LOCALAPPDATA%\opencode\opencode.db` or `%APPDATA%\opencode\opencode.db` on Windows or
227+
`${XDG_DATA_HOME:-~/.local/share}/opencode/opencode.db` on POSIX. A relative
228228
`OPENCODE_DB` value is resolved below OpenCode's data directory;
229229
`OPENCODE_DB=:memory:` has no persistent history to harvest.
230230

‎plugins/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Common implemented flags include:
145145
| `--pi-home PATH` | `~/.pi` | select the parent directory containing `agent/sessions` |
146146
| `--pi-path PATH` | auto-detect `pi` | select the Pi coding-agent CLI executable |
147147
| `--opencode-path PATH` | `SKILLOPT_SLEEP_OPENCODE_PATH`, then `opencode` on `PATH`/`PATHEXT` | select the OpenCode CLI executable |
148-
| `--opencode-db PATH` | `OPENCODE_DB`, then `${XDG_DATA_HOME:-~/.local/share}/opencode/opencode.db` | select the OpenCode SQLite history database |
148+
| `--opencode-db PATH` | `OPENCODE_DB`, `%LOCALAPPDATA%`/`%APPDATA%` (Windows), or `${XDG_DATA_HOME:-~/.local/share}/opencode/opencode.db` | select the OpenCode SQLite history database |
149149
| `--project PATH` | current directory | select the project and invoked harvest scope |
150150
| `--scope invoked\|all` | `invoked` | limit transcript harvesting |
151151
| `--target-skill-path PATH` | managed skill | select a specific `SKILL.md` to stage/adopt |

‎skillopt_sleep/harvest_opencode.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import re
1515
import sqlite3
16+
import sys
1617
from datetime import datetime, timezone
1718
from typing import Any, Iterable, List, Optional
1819
from urllib.request import pathname2url
@@ -48,6 +49,9 @@ def default_opencode_db() -> str:
4849
data_home = os.environ.get("XDG_DATA_HOME", "")
4950
if data_home:
5051
data_dir = os.path.abspath(os.path.expanduser(data_home))
52+
elif sys.platform == "win32" and (os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA")):
53+
win_appdata = os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or ""
54+
data_dir = os.path.abspath(os.path.expanduser(win_appdata))
5155
else:
5256
data_dir = os.path.join(os.path.expanduser("~"), ".local", "share")
5357
opencode_data = os.path.join(data_dir, "opencode")

‎tests/test_harvest_opencode.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import os
88
import sqlite3
9+
import sys
910
from collections.abc import Iterable
1011
from datetime import datetime, timezone
1112
from pathlib import Path
@@ -913,10 +914,23 @@ def test_default_database_honors_xdg_and_opencode_db(monkeypatch, tmp_path: Path
913914
assert default_opencode_db() == ""
914915

915916

917+
def test_default_database_honors_windows_appdata(monkeypatch, tmp_path: Path) -> None:
918+
local_app_data = tmp_path / "LocalAppData"
919+
monkeypatch.delenv("XDG_DATA_HOME", raising=False)
920+
monkeypatch.delenv("OPENCODE_DB", raising=False)
921+
monkeypatch.setattr(sys, "platform", "win32")
922+
monkeypatch.setenv("LOCALAPPDATA", str(local_app_data))
923+
monkeypatch.delenv("APPDATA", raising=False)
924+
925+
assert default_opencode_db() == os.path.abspath(local_app_data / "opencode" / "opencode.db")
926+
927+
916928
def test_default_database_falls_back_to_home_local_share(monkeypatch, tmp_path: Path) -> None:
917929
home = tmp_path / "home"
918930
monkeypatch.delenv("XDG_DATA_HOME", raising=False)
919931
monkeypatch.delenv("OPENCODE_DB", raising=False)
932+
monkeypatch.delenv("LOCALAPPDATA", raising=False)
933+
monkeypatch.delenv("APPDATA", raising=False)
920934
monkeypatch.setenv("HOME", str(home))
921935
monkeypatch.setenv("USERPROFILE", str(home))
922936

0 commit comments

Comments
 (0)