@qqq123456789/codex-doctor 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -7,7 +7,8 @@ English | [中文](README.md)
7
7
  > **Every topic guide is available in English** — the map below links straight to the English versions; each one cross-links back to the Chinese original.
8
8
 
9
9
  [![CI](https://github.com/qlw088697-ui/codex-troubleshooting/actions/workflows/ci.yml/badge.svg)](https://github.com/qlw088697-ui/codex-troubleshooting/actions/workflows/ci.yml)
10
- [![Latest release](https://img.shields.io/github/v/release/qlw088697-ui/codex-troubleshooting?label=release)](https://github.com/qlw088697-ui/codex-troubleshooting/releases)
10
+ [![npm](https://img.shields.io/npm/v/@qqq123456789/codex-doctor)](https://www.npmjs.com/package/@qqq123456789/codex-doctor)
11
+ [![Latest release](https://img.shields.io/npm/v/@qqq123456789/codex-doctor?label=release)](https://www.npmjs.com/package/@qqq123456789/codex-doctor)
11
12
  [![Latest Codex](https://img.shields.io/github/v/release/openai/codex?label=latest%20codex)](docs/releases.md)
12
13
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
13
14
  [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux%20%7C%20WSL-lightgrey)](docs/06-sandbox-windows.md)
package/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
  > A Chinese-first troubleshooting & maintenance guide for OpenAI Codex CLI.
8
8
 
9
9
  [![CI](https://github.com/qlw088697-ui/codex-troubleshooting/actions/workflows/ci.yml/badge.svg)](https://github.com/qlw088697-ui/codex-troubleshooting/actions/workflows/ci.yml)
10
+ [![npm](https://img.shields.io/npm/v/@qqq123456789/codex-doctor)](https://www.npmjs.com/package/@qqq123456789/codex-doctor)
10
11
  [![Latest release](https://img.shields.io/github/v/release/qlw088697-ui/codex-troubleshooting?label=release)](https://github.com/qlw088697-ui/codex-troubleshooting/releases)
11
12
  [![Latest Codex](https://img.shields.io/github/v/release/openai/codex?label=latest%20codex)](docs/releases.md)
12
13
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqq123456789/codex-doctor",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Codex CLI 维护与排障工具:环境自检、会话/日志归档、配置与凭据备份恢复、版本追踪(零依赖)",
5
5
  "type": "module",
6
6
  "bin": {
package/tool/checks.mjs CHANGED
@@ -179,6 +179,29 @@ export async function collectChecks({ network = true } = {}) {
179
179
  'docs/02-login-auth.md'
180
180
  );
181
181
 
182
+ // 4b. 登录态有效期(解码 auth.json 中 id_token 的 exp 声明,不输出任何敏感内容)
183
+ if (exists(auth)) {
184
+ try {
185
+ const j = JSON.parse(fs.readFileSync(auth, 'utf8'));
186
+ const idToken = j?.tokens?.id_token;
187
+ if (typeof idToken === 'string' && idToken.split('.').length >= 2) {
188
+ const payload = JSON.parse(Buffer.from(idToken.split('.')[1], 'base64url').toString('utf8'));
189
+ if (typeof payload?.exp === 'number') {
190
+ const days = Math.floor((payload.exp * 1000 - Date.now()) / 86400e3);
191
+ if (days < 0) {
192
+ add('auth-expiry', 'warn', `登录态已过期 ${-days} 天——重新 codex login 即可`, 'docs/02-login-auth.md');
193
+ } else if (days <= 7) {
194
+ add('auth-expiry', 'warn', `登录态将于 ${days} 天内过期——建议尽快 codex login 刷新`, 'docs/02-login-auth.md');
195
+ } else {
196
+ add('auth-expiry', 'ok', `登录态剩余约 ${days} 天`);
197
+ }
198
+ }
199
+ }
200
+ } catch {
201
+ /* auth.json 结构不符或解析失败则静默跳过 */
202
+ }
203
+ }
204
+
182
205
  // 5. 环境变量
183
206
  if (process.env.OPENAI_API_KEY) add('env-key', 'ok', 'OPENAI_API_KEY 已设置(值不显示)');
184
207
  else add('env-key', 'info', 'OPENAI_API_KEY 未设置(ChatGPT 登录方式无需设置)');
package/tool/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { collectChecks, summarize, renderHuman } from './checks.mjs';
4
4
  import { cleanTarget } from './clean.mjs';
5
5
  import { backupConfig, restoreBackup, resetAuth, listVersions, listArchives, deleteArchive, checkUpdate } from './ops.mjs';
6
6
 
7
- const VERSION = '0.2.0';
7
+ const VERSION = '0.3.1';
8
8
 
9
9
  const HELP = `codex-doctor v${VERSION} — Codex CLI 维护与排障工具(零依赖)
10
10
 
package/tool/ops.mjs CHANGED
@@ -159,20 +159,21 @@ function compareSemver(a, b) {
159
159
  }
160
160
 
161
161
  export async function checkUpdate(currentVersion) {
162
- const headers = { Accept: 'application/vnd.github+json', 'User-Agent': 'codex-doctor-cli' };
163
- if (process.env.GH_TOKEN) headers.Authorization = `Bearer ${process.env.GH_TOKEN}`;
164
- const res = await fetch('https://api.github.com/repos/qlw088697-ui/codex-troubleshooting/releases/latest', { headers });
165
- if (!res.ok) throw new Error(`GitHub API HTTP ${res.status}`);
162
+ // npm registry 上的包版本对比(仓库 GitHub release 版本号与本工具版本号不同步)
163
+ // 注意:缩略 Accept 头配 /latest 端点会返回 406,故请求完整 packument 读 dist-tags
164
+ const res = await fetch('https://registry.npmjs.org/@qqq123456789%2Fcodex-doctor', {
165
+ headers: { Accept: 'application/vnd.npm.install-v1+json', 'User-Agent': 'codex-doctor-cli' },
166
+ });
167
+ if (!res.ok) throw new Error(`npm registry HTTP ${res.status}`);
166
168
  const r = await res.json();
167
- const tag = r.tag_name || '';
168
- const latest = tag.replace(/^v/, '');
169
+ const latest = r['dist-tags']?.latest || '';
169
170
  const newer = latest ? compareSemver(currentVersion, latest) < 0 : false;
170
171
  return {
171
172
  lines: [
172
173
  `当前工具版本: ${currentVersion}`,
173
- `仓库最新发布: ${tag}(${(r.published_at || '').slice(0, 10)})`,
174
+ `npm 最新版本: ${latest}`,
174
175
  newer
175
- ? 'npx 直跑始终使用最新代码,无需操作;本地克隆请 git pull 后重跑。'
176
+ ? 'npx 直跑始终使用最新代码,无需操作;全局安装用户请执行 npm install -g @qqq123456789/codex-doctor@latest'
176
177
  : '已是最新版本。',
177
178
  ],
178
179
  };