Skip to content

feat(gateway): prefer the hub's auth.json when present - #40

Merged
quickbeard merged 1 commit into
mainfrom
hub-auth-fallback
Jul 11, 2026
Merged

quickbeard merged 1 commit into
mainfrom
hub-auth-fallback

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

The CoDev Hub moved its auth file to ~/.codev-hub/auth.json with no fallback to the old shared ~/.codev/auth.json, so the "one shared SSO session" contract between codev and codevhub was broken: a hub login no longer made the configure flow silent.

All three configure triggers (first-run gate, codev configure, the /configure command) funnel through silentSso()/login() into the authFilePath()/forceLoginPath() helpers, so the fix lives in one place:

  • New authDir() resolver in packages/codev-gateway/src/auth-file.ts: when ~/.codev-hub/auth.json exists, both the auth file and the force-login sentinel resolve into ~/.codev-hub; otherwise fall back to ~/.codev exactly as today. Keyed on the file, not the dir, mirroring the hub's own fresh-install check (unrelated code creates the dir).
  • Reads and writes follow the resolved path: a silent refresh may rotate the refresh_token, so persisting it anywhere but the hub's file would strand the hub on a dead session. The file shapes are field-for-field identical (hub src/lib/auth.ts AuthFileContents), and the read-merge-write pattern preserves hub-only fields like skillhub_cookie.
State on disk Configure flow behavior
~/.codev-hub/auth.json exists Reuse/refresh the hub session (silent login if valid); api_key/model/gateway config written into the hub file; honors ~/.codev-hub/force-login
No hub file Today's flow against ~/.codev/auth.json
Both exist Hub file wins

Test bug fixed along the way

Bun's os.homedir() ignores runtime HOME changes (Node respects them), so the existing suite's HOME = tempDir override silently read and wrote the real ~/.codev/auth.json on every bun test run. Home is now resolved per call via OPENCODE_TEST_HOME (the existing core/global.ts convention) and the tests set that instead. If you've run this package's tests locally, your ~/.codev/auth.json likely contains fixtures (api_key: "sk-3") — delete it and re-run codev configure.

Testing

  • bun test from packages/codev-gateway: 14 pass, 0 fail (two new tests: path resolution incl. dir-without-file fallback; reading a hub session and merging api_key back into the hub file without creating ~/.codev/auth.json)
  • bun typecheck clean
  • Not verified live: the browser SSO round-trip riding a real hub session

🤖 Generated with Claude Code

The CoDev Hub moved its auth file to ~/.codev-hub/auth.json with no
fallback to the old shared ~/.codev/auth.json, breaking the shared-
session contract. Resolve the auth dir per call: when the hub's
auth.json exists, read AND write there (a silent refresh may rotate
the refresh_token, so persisting it elsewhere would strand the hub on
a dead session); otherwise fall back to ~/.codev as before. The
force-login sentinel follows the same resolution.

Also fixes a test bug: Bun's os.homedir() ignores runtime HOME
changes, so the suite's HOME override silently read and wrote the
real ~/.codev/auth.json. Home is now resolved per call via
OPENCODE_TEST_HOME (core Global convention) and the tests set that
instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@quickbeard
quickbeard merged commit 4f50dc0 into main Jul 11, 2026
3 of 5 checks passed
@quickbeard
quickbeard deleted the hub-auth-fallback branch July 11, 2026 01:57
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