Skip to content

feat(refresh): use Lambda /refresh endpoint before gh fallback (v0.13.3) - #68

Merged
minarc merged 1 commit into
mainfrom
feat/refresh-token-client
May 19, 2026
Merged

minarc merged 1 commit into
mainfrom
feat/refresh-token-client

Conversation

@minarc

@minarc minarc commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Re-opens #66 (auto-closed when parent stack #67 merged). Same content; base is now `main`.

Pairs with skillmeter-extension-activation#24 — the Lambda `/refresh` endpoint this client calls. Safe to ship before Lambda lands: 404/410/error falls back silently to gh `/activate`.

Summary

License refresh no longer hard-depends on the GitHub CLI. The plugin POSTs the expired JWT to the Lambda's `/refresh` endpoint first; gh silent activation is the safety net for users whose 7-day sliding window has elapsed or whose environment hasn't deployed `/refresh` yet.

Before: every refresh required `gh auth token` + GitHub `/user` + `/user/orgs`. gh-less users effectively couldn't refresh.

After: refresh hits Lambda `/refresh` directly (server checks signature + sliding window + DB org status, no GitHub round-trip). gh-less users keep working as long as they're inside the sliding window.

Files

  • `scripts/lib/license-activation.js` — adds `getRefreshUrl()` and `refreshExpiredJwt(jwt, deviceId)`. 410/404/network/parse → null (caller falls back). 200 → writes rotated token to credstore atomically.
  • `scripts/logger.js` — `tryRefreshLicense` tries `refreshExpiredJwt` first, falls back to `trySilentGhActivate` on null.
  • `plugin.json` — bumped to 0.13.3.

Deploy-order safety

Lambda `/refresh` may not be reachable in every environment yet. 404 from the client is silently absorbed into the gh fallback path so there's no observable regression during rollout.

Test plan

  • Module load — all 3 modules `require` cleanly.
  • URL derivation — `getRefreshUrl()` correctly derives from prod default, dev env override, and custom localhost (no `/activate` suffix).
  • Hook smoke — `session_start.js` loads `v0.13.3` banner, exits 0.
  • End-to-end against dev once Lambda + infra route land.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Version bumped to v0.13.3
  • New Features

    • Added license token refresh capability with automatic fallback to GitHub-based activation when refresh is unavailable

Review Change Stack

License refresh no longer hard-depends on the GitHub CLI. The plugin now
POSTs the expired JWT to the Lambda's /refresh endpoint first; gh-cli
silent activation is the safety net for users whose sliding-refresh
window has elapsed (Lambda returns 410) or whose environment hasn't
deployed /refresh yet (404).

Behavior:
  Before: every refresh required `gh auth token` + GitHub /user + /user/orgs
          → gh-less users effectively couldn't refresh
  After:  refresh hits Lambda /refresh directly (server checks signature +
          sliding window + DB org status, no GitHub roundtrip)
          → gh-less users keep working as long as they're inside the 7-day
            sliding window from their last full /activate

Files:
  lib/license-activation.js
    + getRefreshUrl() — derives from getActivateUrl, preserves host config
    + refreshExpiredJwt(jwt, deviceId) — POSTs to /refresh, returns new JWT
      or null. On null, the caller's silent-gh fallback runs.
    · 410/404/network/parse errors all return null (caller falls back).
    · On 200, writes the new JWT to credstore atomically.

  logger.js
    · tryRefreshLicense tries refreshExpiredJwt first, falls back to
      trySilentGhActivate on null result.
    · Existing signed_out / no-deviceId early returns preserved.

Deploy-order-safe: Lambda /refresh endpoint may not be reachable in every
environment yet. 404 from the client is silently absorbed into the gh
fallback path so there's no visible regression during rollout.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f64b9c56-4087-453b-8f97-50b2f33668c5

📥 Commits

Reviewing files that changed from the base of the PR and between 2efa0bc and aca52fa.

📒 Files selected for processing (3)
  • skillmeter/.claude-plugin/plugin.json
  • skillmeter/scripts/lib/license-activation.js
  • skillmeter/scripts/logger.js

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

This PR adds JWT token refresh capability to the license activation system. It introduces a new /refresh endpoint utility and refresh function in license-activation.js, then integrates them into the logger's license-refresh flow to attempt token rotation before falling back to GitHub activation. The plugin version is also bumped to 0.13.3.

Changes

License JWT Token Refresh with Fallback

Layer / File(s) Summary
JWT refresh endpoint helper and function
skillmeter/scripts/lib/license-activation.js
getRefreshUrl() derives a /refresh endpoint URL from the existing activation URL; refreshExpiredJwt(jwt, deviceId) POSTs the JWT as a Bearer token and device_id JSON body to the refresh endpoint, handling network failures and HTTP status codes (410/404 return null), and on success writes the refreshed token to credstore and returns it.
Logger integration with JWT-first refresh strategy
skillmeter/scripts/logger.js
tryRefreshLicense now imports and calls refreshExpiredJwt first when a current token exists; if it succeeds, the refreshed token is returned immediately, otherwise falls back to trySilentGhActivate for GitHub-based activation. Comment block updated to document the refresh-before-fallback behavior.
Plugin version bump
skillmeter/.claude-plugin/plugin.json
Version incremented from 0.13.2 to 0.13.3.

Sequence Diagram

sequenceDiagram
  participant Logger as Logger.tryRefreshLicense
  participant RefreshJWT as refreshExpiredJwt
  participant RefreshEndpoint as /refresh endpoint
  participant Credstore as Credstore
  participant GhActivate as trySilentGhActivate

  Logger->>RefreshJWT: refreshExpiredJwt(current_jwt, deviceId)
  RefreshJWT->>RefreshEndpoint: POST with Bearer token & device_id
  alt Success (200 OK, valid token)
    RefreshEndpoint-->>RefreshJWT: new_jwt
    RefreshJWT->>Credstore: write new_jwt
    RefreshJWT-->>Logger: return new_jwt
  else 410 Expiry or 404 Missing
    RefreshEndpoint-->>RefreshJWT: error response
    RefreshJWT-->>Logger: return null
    Logger->>GhActivate: fallback to GitHub activation
  else Other non-OK status
    RefreshEndpoint-->>RefreshJWT: error response
    RefreshJWT-->>Logger: return null
    Logger->>GhActivate: fallback to GitHub activation
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jhunlee-dev

Poem

🐰 A token that ages, now spins round with grace,
/refresh before falling back—giving trust its new place.
Credstore holds steady, the fallback stands tall,
And when slides expire, refresh rolls for all! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/refresh-token-client

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.21.0)

OpenGrep fatal error (exit code 2):
┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m
[00.42][ERROR]: Error: exception Glob.Lexer.Syntax_error("malformed glob pattern: missing ']'")
Raised at Glob__Lexer.syntax_error in file "libs/glob/Lexer.mll", line 8, characters 2-26
Called from Glob__Lexer.__ocaml_lex_token_rec in file "libs/glob/Lexer.mll", line 29, characters 26-53
Cal


Comment @coderabbitai help to get the list of available commands and usage tips.

@minarc
minarc merged commit cd002c5 into main May 19, 2026
1 check was pending
@minarc
minarc deleted the feat/refresh-token-client branch May 19, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant