feat: per-profile Go usage tracking for multi-account setups — fixes #63#75
Merged
Merged
Conversation
…file isolation usageProfile.ts: profile registry, key fingerprint, rename/delete helpers. goUsageTracker.ts: storageKeySuffix constructor param for namespaced storage; migrateFromSingleton() to copy legacy data into first profile. Unit tests: 20 tests.
- Replace singleton goUsageTracker with Map<fingerprint, GoUsageTracker> - ensureProfileSync() called during provider resolution to pre-register profiles at startup; also called during request recording - Model IDs now include key fingerprint so two entries with same vendor don't collide in apiKeysByModelId (fixes issue ltmoerdani#63) - Active profile auto-switches to the most recently used model - Status bar shows active profile label in multi-profile mode - QuickPick lists all profiles with switch support - SVG title shows active profile name
CHANGELOG.md: unreleased section for per-profile usage tracking. README.md: 'Multiple Go accounts' section under Usage Tracking. package.json: renameActiveProfile and deleteProfile commands.
Per-profile trackers have namespaced storage (storageKeySuffix set) and should not read the shared opencode.db — it has no key column, so reading it would mix quota data from all accounts, causing the 5-hour rolling usage to accumulate across profiles instead of resetting. Now getSummary() and setManualSpentTargets() skip SQLite when the tracker is namespaced, falling back to in-memory tracked entries. Reported by @taojunnan during PR ltmoerdani#75 testing.
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.
feat: per-profile Go usage tracking for multi-account setups — fixes #63
Goal
Allow users with multiple OpenCode Go subscriptions (e.g. work + personal)
to use separate Go accounts in the same VS Code window without the usage
panel mixing their data.
Commits
feat(usage): add usageProfile module and storageKeySuffix— profileregistry, key fingerprint, rename/delete helpers, storage isolation per
profile, migration from legacy singleton. (3 files, +270 lines)
feat(usage): multi-profile wiring in extension.ts— tracker map,profile creation during provider resolution, fingerprint in model IDs
to prevent key collisions, auto-switch, QuickPick with full profile
list, SVG title with profile name. (1 file, +285 lines)
feat(docs): update docs and package.json— CHANGELOG, README with"Multiple Go accounts" section, new commands. (3 files, +41 lines)
What was implemented
label. Deterministic fingerprint (first 8 + last 8 key chars). Persisted
in globalState.
namespaced keys. Legacy data is migrated into Profile 1 on first use.
the status bar to open the QuickPick — every profile is listed, active
one is checked, others are clickable switches.
when 2+ profiles exist (accuracy trade-off documented in README).
Testing
95/95 unit tests pass. Tested with two OpenCode Go accounts. Profile
creation, auto-switch, QuickPick switch, rename, and delete all verified.