fix(opencode): support OpenCode 2 session_message schema and credential table - #1186
arpankanwer wants to merge 1 commit into
Conversation
…al table
OpenCode 2 (1.18.x/beta) moved local storage:
- message table (role/providerID/modelID/tokens.total) -> session_message
table (type=assistant, model.providerID, model.id,
tokens.input/output/reasoning/cache.* without total)
- auth.json {"opencode-go":{"key":"sk-..."}} -> SQLite credential
table (integration_id='opencode-go', value JSON {"key":"sk-..."})
Previously OpenUsage queried only 'message' with old JSON paths and
only read auth.json, so on OpenCode 2 it showed
"Couldn't read OpenCode's local database" and no Go meters.
Fix:
- Scanner: UNION ALL message + session_message with coalesced JSON
paths (providerID, modelID, tokens) so either schema or both
during migration works. probe and data queries updated.
- AuthStore: try auth.json first, then fallback to credential table
across all opencode*.db files (opencode-go then generic sk-%),
injected via SQLiteAccessing for testability, backwards compatible.
Resolves robinebers#1124
Test: swift build, swift test --filter OpenCode (40 passed),
swift test full (1225 passed), manual sqlite verification on
~/.local/share/opencode/opencode.db (46716 union vs 24893 v1-only)
|
Thanks for your interest in contributing to OpenUsage! External pull requests must reference an open issue that:
Please discuss the change on an issue first, wait for a maintainer to approve and assign it to you, then reopen this pull request with |
|
@robinebers Thanks for assigning #1124! Could you please reopen #1186? Latest policy check is now passing, so it should stay open. I'll mark it Ready after. |
|
Superseded by #1243. This PR could not be reopened: GitHub blocks it while the head branch has been force-pushed after close ( Nothing to review here — please look at #1243 instead. |
Approved issue
Fixes #1124
TL;DR
OpenUsage failed on OpenCode 2 beta — "Couldn't read OpenCode's local database" and no Go meters — because the scanner still hit the v1
messagetable /auth.jsononly. This unions bothmessage+session_messagetables and falls back fromauth.jsonto the SQLitecredentialtable.What was happening
OpenCode 2 (1.18.x beta, current stable) changed local storage:
message(fieldsrole,providerID,modelID,tokens.total) →session_message(columnstype,seq,datawithtype='assistant', JSONmodel.providerID,model.id,tokens.input/output/reasoning/cache.*— nototal)~/.local/share/opencode/auth.json→ SQLitecredentialtable (integration_id='opencode-go',valueJSON{"key":"sk-..."})OpenUsage only queried
FROM messagewith$.role/$.providerID/$.tokens.totaland only readauth.json, so on a v2 DB every scan threwno such table: messageor returned empty, andgoAPIKey()returned nil.What this changes
OpenCodeUsageScanner:dataSQL/probeSQLnowUNION ALLboth tables with coalesced JSON pathsOpenCodeAuthStore: tryauth.jsonfirst, then fallback tocredentialtableTests
swift build → Build complete
swift test --filter OpenCode → 40 passed