refactor(usage): OpenCode usage comes from provider-opencode #17577
t3/usage-transcript-readers fromrefs/pull/17577/head·merged by juliusmarminge View on GitHubThe OpenCode usage reader and its OPENCODE_DATA_DIR/XDG root resolution lived in apps/server.
They move into provider-opencode as a scan reader on OpenCodeDriver.usage. UsageService runs scan readers generically and fills in a source's volume id from its directory when a reader leaves it out. Tests move with the code.
🤖 Generated with Claude Code (Claude Opus 5.5, Claude Code harness)
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This is primarily a behavior-preserving refactor that relocates OpenCode usage scanning into its provider package and adds generic scan plumbing. The new test file also adds a file-level static-analysis suppression directive, requiring human review.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).0d411e3. Prior analysis still applies.No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
1d3ba86e-6648-4465-97a6-8dfd3ffc9294
📥 Commits
Reviewing files that changed from the base of the PR and between a97390980eac1a5d21ed9ec0191c44c7e77879f1 and 0d411e3eb0a265e1b93ed95a942311ef37169fad.
📒 Files selected for processing (2)
apps/server/src/usage/UsageService.tspackages/provider-core/src/server/usage.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough#
OpenCode usage history is now read through a provider scan reader registered as a built-in usage driver. UsageService runs built-in scan readers alongside its other usage sources. The scan result contract allows readers to omit a volume ID.
Changes#
OpenCode usage scanning
Layer / File(s) Summary OpenCode scan reader and contract
packages/provider-core/src/server/usage.ts,packages/provider-opencode/src/server/usage.ts,packages/provider-opencode/src/server/usage.test.ts,apps/server/src/usage/usageTranscriptReader.test.tsThe scan contract makes volumeIdoptional. The OpenCode reader resolves and deduplicates data roots, scans them, and reports missing or partially readable history. Tests for SQLite and legacy JSON history are now in the OpenCode package; the corresponding test was removed from the server transcript-reader suite.Register OpenCode scan reader
packages/provider-opencode/src/server/driver.ts,apps/server/src/provider/builtInDrivers.tsOpenCodeDriverexposesopenCodeUsageReaderand is included in the built-in usage driver list.Run scan readers during usage collection
apps/server/src/usage/UsageService.tsUsageService selects built-in scan readers, supplies configured instances and scan cutoffs, normalizes returned sources, and includes them in collection. The dedicated OpenCode collection path was removed. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Sequence Diagram(s)#
sequenceDiagram participant UsageService participant OpenCodeDriver participant openCodeUsageReader participant FileSystem UsageService->>OpenCodeDriver: select built-in scan reader UsageService->>openCodeUsageReader: provide instances and scan cutoffs openCodeUsageReader->>FileSystem: resolve roots and read usage history FileSystem-->>openCodeUsageReader: history results openCodeUsageReader-->>UsageService: scanned sources and statusSuggested reviewers:
t3dotgg
Merge Risk: ⚪ Minimal · up to
0d411No actionable OpenCode usage regression was established; this PR is mergeable after normal checks.
Pre-merge checks |
3 | 1❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Description check The description explains the code movement and generic scan-reader change, but it omits the required Problem, Scope and approval, and Verification sections. It provides no test results or statement of… Add the required Problem, Change, Scope and approval, and Verification sections. Include the problem and expected behavior, issue or maintainer approval details, focused tests with observed results, and any checks that were not run. ✅ Passed checks (3 passed)
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the main change: moving OpenCode usage handling into provider-opencode. It is concise and specific.
Full details: Description check
Explanation
The description explains the code movement and generic scan-reader change, but it omits the required Problem, Scope and approval, and Verification sections. It provides no test results or statement of unchecked items.
- Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
- Commit to this branch
- Create a new PR
📝 Generate docstrings
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged this23957c7
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
0d411e3· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.