This document contains engineering & contributor facing details intentionally kept out of the end‑user README.md (optimized for the VS Code Marketplace).
- Clone & install deps
git clone https://github.com/Fail-Safe/CopilotPremiumUsageMonitor.git
cd CopilotPremiumUsageMonitor
npm install- Build once (or use watch):
npm run vscode:prepublishornpm run compilefor watch. - Press F5 in VS Code (launches an Extension Development Host). The extension activates on
onStartupFinished. - Use the command palette to run: "Copilot Premium Usage Monitor: Open".
Tips:
- When iterating UI in the webview, you can close/reopen via the command palette to force a fresh HTML load.
- Status bar changes react to configuration events; for manual forcing use tests or tweak a setting.
To create consistent Marketplace screenshots, two helper commands are included (developer convenience):
-
Copilot Premium Usage Monitor: Prepare Screenshot State (Normal)- Seeds a plan (Copilot Pro+), 131/1500 included usage, and $2/$10 budget.
- Opens the panel and refreshes the status bar for a clean capture.
-
Copilot Premium Usage Monitor: Prepare Screenshot State (Error)- Posts a network error to the panel and sets an error icon in the status bar.
Tips for capturing:
- Hide unrelated status bar items via the status bar gear menu for a clean UI.
- Keep OS/UI scale at 100% where possible to preserve crisp bar glyphs.
- You can adjust colors with
useThemeStatusColorif you want fixed green/yellow/red styling in screenshots.
| Command | Purpose |
|---|---|
npm run compile |
TypeScript watch build |
npm test |
Unit + extension integration tests (no full coverage instrumentation) |
npm run test:coverage |
Unit test coverage (extension host not instrumented) |
npm run test:coverage:full |
Full instrumentation: unit + extension activation with combined coverage merge |
npm run clean |
Remove build + coverage artifacts (safe) |
npm run clean:full |
Deep clean (also uses git clean -fdX) – removes ignored/untracked build artifacts |
npm run package |
Build a VSIX (no publish) |
npm run release |
Build & publish (requires VSCE_PAT) |
All test commands transpile TypeScript first (vscode:prepublish) unless already built.
Location: src/test/
| Area | Path | Notes |
|---|---|---|
| VS Code activation/integration | src/test/suite/*.test.ts |
Uses @vscode/test-electron. Exercises command registration, webview message routing, status bar coloring. |
| Node unit tests | src/test/unit/*.test.ts |
Run via Node test runner (node --test). Focus on formatting helpers. |
| Harness | src/test/runTests.ts |
Wrapper enabling optional coverage instrumentation & environment control. |
| Mode | Command | What it Instruments |
|---|---|---|
| Unit only | npm run test:coverage |
Node unit tests (c8) – no extension host instrumentation |
| Full merge | npm run test:coverage:full |
Instruments compiled JS, runs unit + activation tests, merges host + unit coverage, updates badge |
The badge JSON consumed by README uses scripts/coverage-badge.mjs.
The repository CI enforces a coverage gate (nyc) configured in package.json aiming for high confidence across metrics; local npm run test:coverage:full generates the merged coverage report and coverage/lcov.info suitable for CI upload.
| Variable | Purpose | Used In |
|---|---|---|
CPUM_TEST_ENABLE_LOG_BUFFER |
Captures OutputChannel lines into an in‑memory buffer for assertions | Tests & runtime guard in extension.ts |
CPUM_TEST_FORCE_ORG_ERROR |
Forces an org listing error path | Org error test |
CPUM_COVERAGE_DIR |
Directory where extension host writes instrumentation JSON (extension + runTests) | Coverage merge scripts |
Set via the activateWithEnv helper in tests or shell before running coverage commands.
npm run lint (ESLint + TypeScript). Add rules sparingly; keep signal high. Run before large PRs.
Artifacts removed by clean script:
out/(compiled JS)coverage/,.nyc_output/,.node_coverage/.tsbuildinfo
The scripts/clean-artifacts.sh script centralizes safe removal of transient artifacts. It is referenced by the npm scripts above so local and CI workflows remain consistent.
If you add new transient directories (e.g., dist/ or reports/), update both .gitignore and this script.
This repo provides a GitHub Actions workflow (Release) that can be triggered manually (workflow_dispatch):
- Go to Actions → Release → Run workflow.
- Choose a bump type: patch | minor | major | prepatch | preminor | premajor | prerelease | auto.
- auto: derives bump from commit messages since last tag (BREAKING CHANGE/! => major, feat => minor, else patch).
- (Optional) Provide preid (default: beta) for pre* / prerelease bumps.
- Workflow enforces a clean working tree (no uncommitted changes) before proceeding.
- Steps: bump version + CHANGELOG, commit, tag, build, run activation test (collect coverage), generate coverage badge + release notes (includes CI & coverage shields), package VSIX, create GitHub Release.
- Optional Marketplace publish runs only if a VSCE_PAT secret is configured.
To enable the publish step, create a Visual Studio Marketplace Personal Access Token with publish scope and add it as a repository secret named VSCE_PAT (Settings → Secrets and variables → Actions → New repository secret). Omit the secret to skip publishing (useful for dry runs).
- Open an issue for feature proposals – align on scope before coding.
- Keep PRs small & cohesive (one feature or fix + tests).
- Include tests for new logic (status bar behaviors, config interactions, error flows). Prefer deterministic test env variables.
- Avoid introducing runtime dependencies unless clearly justified (evaluate size, maintenance, security). Octokit &
vscode-nlsintentionally kept minimal. - Internationalization: wrap user‑facing strings in
nls.loadMessageBundle()usage patterns when new UI text is added. - Security / Privacy: never add telemetry or external network endpoints; only GitHub API calls are allowed.
Release workflow supports an auto bump deriving semantic version from commit messages:
| Trigger | Result |
|---|---|
Commit body / footer contains BREAKING CHANGE: or ! after type (e.g. feat!:) |
major |
feat: conventional commit type |
minor |
| Anything else | patch |
Follow standard Conventional Commits where practical (e.g., feat:, fix:, docs:, refactor:).
- Use Copilot Premium Usage Monitor: Show Logs to view OutputChannel.
- Toggle
copilotPremiumUsageMonitor.showLogOnErrorto auto open log on first failure. - For status bar color debugging modify thresholds & observe immediate refresh events.
- For webview messaging issues, add temporary log lines in
_dispatch(ensure removal before commit).
src/lib/tokenState.ts centralizes timing heuristics (secure assume window, legacy retain & suppress windows) to avoid scattered boolean races. Tests in src/test/unit/tokenState.residualHint.test.ts and integration suites cover migration + residual plaintext hint windows. When adjusting timings, update constants there and adapt any hardcoded waits in integration tests referencing those windows.
Potential future improvements (open issues & PR discussion first):
| Idea | Notes |
|---|---|
| Org spend estimation | If GitHub exposes an org cost endpoint for Copilot Premium Request SKU. |
| Export usage data | Panel action to copy current summarized metrics. |
| More granular refresh | Separate intervals or manual-only mode. |
| Status bar hover mini‑chart | Sparkline of recent percent snapshots (local only). |
MIT (see root LICENSE).
Coverage is parsed from coverage/lcov.info during the release job. A dynamic JSON badge is generated locally and an approximate static shields.io badge is embedded in the release body along with CI status. (A persistent README badge can be added later if desired.)