Skip to content

feat: notify when a newer version is available - #333

Merged
tibo-openai merged 9 commits into
openai:mainfrom
benny123tw:feat/support-outdated-alert
Apr 19, 2025
Merged

tibo-openai merged 9 commits into
openai:mainfrom
benny123tw:feat/support-outdated-alert

Conversation

@benny123tw

Copy link
Copy Markdown
Contributor

Summary
This change introduces a new startup check that notifies users if a newer @openai/codex version is available. To avoid spamming, it writes a small state file recording the last check time and will only re‑check once every 24 hours.

What’s Changed

  • New file src/utils/check-updates.ts
    • Runs npm outdated --global @openai/codex
    • Reads/writes codex-state.json under CONFIG_DIR
    • Limits checks to once per day (UPDATE_CHECK_FREQUENCY = 24h)
    • Uses boxen for a styled alert and which to locate the npm binary
  • Hooked into src/cli.tsx entrypoint:
    import { checkForUpdates } from "./utils/check-updates";
    // …
    // after loading config
    await checkForUpdates().catch();
  • Dependencies
    • Added boxen@^8.0.1, which@^5.0.0, @types/which@^3.0.4
  • Tests
    • Vitest suite under tests/check-updates.test.ts
    • Snapshot in __snapshots__/check-updates.test.ts.snap

Motivation
Addresses issue #244. Users running a stale global install will now see a friendly reminder—at most once per day—to upgrade and enjoy the latest features.

Test Plan

  • getNPMCommandPath() resolves npm correctly
  • checkOutdated() parses npm outdated JSON
  • State file prevents repeat alerts within 24h
  • Boxen snapshot matches expected output
  • No console output when state indicates a recent check

Related Issue
try resolves #244

Preview
Prompt a pnpm‑style alert when outdated
outdated‑alert

Let me know if you’d tweak any of the messaging, throttle frequency, placement in the startup flow, or anything else.

@github-actions

github-actions Bot commented Apr 18, 2025 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@benny123tw

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@benny123tw

Copy link
Copy Markdown
Contributor Author

recheck

github-actions Bot added a commit that referenced this pull request Apr 18, 2025
@maheshrijal

Copy link
Copy Markdown
Contributor

I'm just thinking out loud.. but does it make sense to download the update in background and ask user to reload the app?

@benny123tw

Copy link
Copy Markdown
Contributor Author

I'm just thinking out loud.. but does it make sense to download the update in background and ask user to reload the app?

I’d personally lean toward keeping updates manual. Feels more in line with typical CLI behavior. Just my take!

@tibo-openai

Copy link
Copy Markdown
Collaborator

This is a great change and very well structured. Agreed with keeping things without auto update for now, especially as it's still early days and updates might introduce breaking changes.


const UPDATE_CHECK_FREQUENCY = 1000 * 60 * 60 * 24; // 1 day

export async function getNPMCommandPath(): Promise<string | undefined> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add support for #282

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I’ll need a bit of time to look into it. I’ll follow up once I have a better understanding

npmCommandPath: string,
): Promise<UpdateCheckInfo | undefined> {
return new Promise((resolve, _reject) => {
// TODO: support local installation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a little bit more information here with some ideas for implementation or why this is important to support.

@benny123tw benny123tw Apr 18, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in e3a04e9. Since users might install Codex locally, I think we should check the project-level install first, then global as a fallback.

Comment thread codex-cli/src/utils/check-updates.ts Outdated
}
cp.execFile(commandPath, args, options, (_error, stdout) => {
try {
// TODO parse from package.json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the limitations related to not parsing package.json

@benny123tw benny123tw Apr 18, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a comment on tsconfig.json#L14 mentioned that ESM doesn't yet support JSON modules, so I added a TODO there.

"resolveJsonModule": false, // ESM doesn't yet support JSON modules.

That said, when building the TypeScript code, I found that importing package.json actually works. The bundler transforms the JSON import into a CommonJS-style require(...), and then wraps it with __toESM(...) so it behaves correctly in an ESM context. Here's an example from the build output:

const { name: packageName } = await Promise.resolve().then(() => __toESM(require_package2(), 1));

While JSON modules are no longer experimental in Node.js 23.1.0+, we’re still using Node.js 22, so native support isn’t available yet — but the build behavior makes this approach work just fine.

Implemented in 2d9b707

Comment thread codex-cli/src/utils/check-updates.ts Outdated
import { join } from "node:path";
import which from "which";

interface State {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you scope this to update state only, similar for the file name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check — are you suggesting moving the state logic into a separate file, or just to keep this PR focused on state only?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting to not call this State, but UpdateState and have the file name also be named after what it is storing (update state) and not generically be about state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've renamed State to UpdateState, and updated the file name to update-state.json to reflect its purpose more clearly in 396691b

@tibo-openai

Copy link
Copy Markdown
Collaborator

Please resolve the merge conflicts and I will then merge. This is looking good after the changes, ty!

@tibo-openai

Copy link
Copy Markdown
Collaborator

Resolved, merging. Thank you for this great change!

@tibo-openai
tibo-openai merged commit d61da89 into openai:main Apr 19, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 19, 2025
@benny123tw
benny123tw deleted the feat/support-outdated-alert branch April 19, 2025 02:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Version Out of Date Alert

3 participants