feat(codex): codex setup auto-upgrade — version check, network detection, offline guidance#55
Merged
Merged
Conversation
…dex setup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…esolved version on fresh install Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Codex sandbox guidance Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…offline Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… to accept semver pre-release - export compareVersions and strip pre-release/build metadata before numeric comparison so '3.7.3' vs '3.8.0-rc.1' correctly returns -1 - remove '$' anchor from fetchLatestPublishedVersion regex so pre-release versions from the npm registry are accepted instead of silently falling back to VERSION - add 6 unit tests covering the fixed cases Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Warnings JSON field, remove dead null guard Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… accurate version in success message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…DESTRUCTIVE_LOCAL - check-credentials.js: replace tryKeychainDescribe (auth keychain describe --json) with tryKeychainGet (auth keychain get --json, inspects present===true) so a fresh-install machine with no stored token is no longer falsely reported as authenticated - capabilities.ts: reclassify 'reset' from ACTION_LOCAL to DESTRUCTIVE_LOCAL since it permanently removes credentials, config, audit logs, quota data, history, and caches Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…with present field
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.
Current situation
switchbot codex setupinstalls@switchbot/openapi-cliglobally but never checks whether an existing install is outdated. Users running a stale global install would silently skip the upgrade step with just "already installed", leaving them on an old version.Additionally, Codex workspaces are offline by default — no network check existed, so setup would hit multiple sequential timeouts and emit confusing raw npm errors with no guidance on how to fix it.
Proposed solution
Auto-upgrade via npm registry check
fetchLatestPublishedVersionqueriesnpm view @switchbot/openapi-cli version(8 s timeout) to get the true latest from the registryVERSION(the running binary) when offline — correct when invoked vianpxsinceVERSION == latestcompareVersionsdoes a numeric semver comparison (pre-release segments stripped); upgrades automatically if installed version is behindnpm list -gto report an accurate "upgraded X → Y" messageNetwork detection step (
check-network)npm pingwarnoutcome with the exact~/.codex/config.tomlfix and skipsinstall-switchbot-cliautomatically (avoids ~13 s of serial timeouts)hasWarnings: truewhen any step warnsPlugin docs for Codex sandbox
packages/codex-plugin/skills/switchbot/references/codex-network.md— explains the three network operations required and gives the exact config snippetSKILL.mdgains a## Network requirementssection pointing to that referenceCode review fixes (from post-implementation review)
compareVersions: strips pre-release/build metadata before numeric comparison (3.8.0-rc.1no longer causes NaN)fetchLatestPublishedVersionregex: removed$anchor so pre-release versions from the registry are acceptedrunRepairicon renderer: addedwarn → chalk.yellow('⚠')arm (was falling through to red ✗)as … | null | undefinedcast onregisterCodexPluginAuto()call sitesRelease Notes
codex setupnow:~/.codex/config.tomlfix before wasting time on network callsNo breaking changes. The step count increases from 5 to 6 (
check-networkinserted as step 2, skippable).Testing
tests/commands/codex.test.ts(was 30), all passingcompareVersionscovering pre-release edge casesReviewer nudge
Start with
src/commands/codex.ts:fetchLatestPublishedVersion+compareVersions(~line 20–50) — version check logicsetupStepCheckNetwork(~line 380) — new network probe stepsetupStepInstallGlobalPackage(~line 440) — rewritten install/upgrade logicrunSetup(~line 515) —networkOfflineflag + auto-skip wiringThen
packages/codex-plugin/skills/switchbot/references/codex-network.mdfor the user-facing guidance.