fix: OpenCode SQLite 토큰 사용량 파싱 지원 - #22
Merged
kobenlys merged 10 commits intoSep 3, 2026
Merged
Conversation
release: 2026.7.1-BETA — Linux auto-sync 지원 및 config·에러 견고화
release: 2026.7.2-BETA — update-check -BETA 감지 수정
release: develop → main (2026.8.1)
docs: 이슈 템플릿 main 반영
Contributor
PR 감사합니다
검토 결과 전달드립니다. AS-IS : Tokenphage → OpenCode(App) → opencode.db OpenCode의 상태(오작동, 삭제, 등)에 따라 Tokenphage sync 동작에 #20 db조회 방식 참고 해당 지점
그 외 코드컨밴션 및 테스트코드 작성된 부분은 좋습니다 LGTM |
kobenlys
reviewed
Aug 10, 2026
|
|
||
| test('parseOpencodeRows_모델또는날짜가없는행은제외', () => { | ||
| const entries = parseOpencodeRows([ | ||
| { time_created: TS_MS, model: null, output: 999 }, |
Contributor
There was a problem hiding this comment.
USAGE_QUERY가 SELECT하는 별칭은 7개입니다 (src/parsers/opencode.js:12-18).
date, model, input, output, reasoning, cache_read, cache_write
time_created: TS_MS는 운영환경에서 조회될 수 없는 값입니다
테스트 의도와 코드는 좋으니 운영에서 사용되는 데이터 형식으로 변경해주시면 좋을것같습니다 LGTM
docs: 배지 예시를 마크다운 스니펫으로 교체하고 grass 테마 추가
opencode.db(SQLite)를 외부 App 호출 없이 직접 읽기 위해 필요하다. 동일 목적으로 SQLite를 조회하는 #20과 버전(^11.10.0)을 맞춘다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y47Mk5FmHKctpTjcFZ45Ar
리뷰 반영. `opencode` CLI를 execFile로 호출해 사용량을 받아오던 경로를 걷어내고 opencode.db를 read-only로 직접 조회한다(TOKENPHAGE#20 DB 조회 방식과 정렬). AS-IS : Tokenphage -> OpenCode(App) -> opencode.db TO-BE : Tokenphage -> opencode.db - parseOpencodeDatabase(dbPath)로 조회 대상 경로를 명시적으로 받는다. parser.js는 후보 디렉터리에서 처음 찾은 opencode.db 하나만 읽는다(first-wins). - OpenCode 상태가 sync를 막지 않도록 실패를 격리한다. parseAll이 파서들을 Promise.all로 묶기 때문에 여기서 throw하면 claude/codex 결과까지 버려진다. 어떤 실패도 예외를 올리지 않고 빈 목록을 반환한다. - 경고는 조치가 필요한 경우로 한정한다. 파일 없음·빈 DB(삭제 후 잔존)는 집계할 기록이 없을 뿐이므로 조용히 넘어가고, 파일이 남아 있는데 읽기가 실패했거나(손상·권한) message/part 테이블만 없으면(스키마 변경) 알린다. - tokens가 객체인 step-finish part만 집계하도록 WHERE 조건을 좁혔다. JSON null tokens가 json_type에서 'null'을 돌려줘 0 레코드로 새던 문제를 막는다. - CLI stub 대신 실제 SQLite fixture로 테스트를 재작성하고, console.warn을 가로채 경고 발생 여부까지 단언한다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y47Mk5FmHKctpTjcFZ45Ar
haazz
force-pushed
the
feature/opencode-sqlite-storage
branch
from
August 25, 2026 23:17
5f9b0bc to
775f5c9
Compare
리뷰 반영. USAGE_QUERY는 date·model·input·output·reasoning·cache_read· cache_write 7개 별칭만 SELECT하는데, time_created를 받는 경로가 코드와 테스트에 남아 있어 운영에서 나올 수 없는 데이터 형식을 다루고 있었다. - entryOfRow에서 localDateOf(row.time_created) fallback을 없앤다. 쿼리가 time_created를 내보내지 않으므로 이 분기는 항상 undefined를 받는 죽은 경로였고, 의도(날짜를 못 만들면 제외)를 재시도처럼 읽히게 만들었다. date는 strftime 결과라 'YYYY-MM-DD' 아니면 NULL이므로 그것만 검사한다. - parseOpencodeRows 제외 테스트의 행을 운영 형식(date 별칭)으로 바꾼다. - m.time_created가 NULL이면 strftime이 NULL을 돌려주는 실제 동작을 SQLite fixture 테스트로 고정한다. 위 제외 규칙이 쿼리 결과와 맞물려 동작하는지를 stub이 아니라 실제 DB로 검증한다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014feReoHMBpj1XPiPHgHQfM
haazz
force-pushed
the
feature/opencode-sqlite-storage
branch
from
August 26, 2026 23:06
2fc1393 to
ad07270
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🏷️ 작업 유형
📋 변경 사항
storage/message,storage/partJSON 대신opencode.db에 저장하는 변경을 반영했습니다.opencode.db가 있으면 외부 App(opencodeCLI) 호출 없이better-sqlite3로 read-only 직접 조회합니다. (feat: Hermes Agent 토큰 사용량 집계 지원 #20 DB 조회 방식과 정렬)tokenphage sync동작에 영향을 주지 않습니다.#21
🔁 리뷰 반영 (2차)
AS-IS : Tokenphage → OpenCode(App) → opencode.db
TO-BE : Tokenphage → opencode.db
src/parsers/opencode.js의execFile('opencode', ['db', ...])경로를 제거했습니다.parseOpencodeDatabase(dbPath)로 조회 대상 경로를 명시적으로 받습니다.src/parser.js는 후보 디렉터리에서 처음 찾은opencode.db하나만 읽습니다(first-wins).tokens가 객체인step-finishpart만 집계하도록 WHERE 조건을 좁혔습니다 (JSONnulltokens가 0 레코드로 새던 문제 제거).CLI stub 대신 실제 SQLite fixture로 DB 경로 테스트를 재작성했습니다.
실패 격리:
parseAll이Promise.all로 파서들을 묶기 때문에 OpenCode 조회가 throw하면 claude/codex 결과까지 버려지고 sync 전체가 실패합니다. 어떤 실패도 예외를 올리지 않고 빈 목록을 반환하도록 격리했습니다 (feat: Hermes Agent 토큰 사용량 집계 지원 #20parseHermesSessions와 동일 계약).경고는 조치가 필요한 경우에만: OpenCode를 쓰지 않는 사용자가 노이즈를 보지 않도록 좁혔습니다.
parseAll이 glob으로 찾았을 때만 DB를 읽으므로 애초에 호출되지 않습니다message/part만 없음 (스키마 변경)✅ 테스트
npm test: 184개 테스트 통과npm run test:coverage: 커버리지 기준 통과 (src/parsers/opencode.js100% lines / 100% functions)git diff --check: 통과XDG_DATA_HOME에 4가지 상태(파일 없음 / 빈 DB / 손상 / 스키마 변경)의opencode.db를 두고parseAll실행 → 전 케이스에서 Claude 레코드는 정상 집계되고, 경고는 손상·스키마 변경 2건에서만 출력됨