@bitkyc08/opencodex 2.5.7-preview.20260627 → 2.6.0

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.
Files changed (51) hide show
  1. package/README.ko.md +17 -6
  2. package/README.md +19 -7
  3. package/README.zh-CN.md +12 -3
  4. package/assets/architecture.png +0 -0
  5. package/assets/banner.png +0 -0
  6. package/assets/codex-app-picker.png +0 -0
  7. package/bin/ocx.mjs +88 -2
  8. package/bin/package-main.mjs +9 -0
  9. package/gui/dist/assets/index-BS4X1QDi.js +9 -0
  10. package/gui/dist/assets/{index-CKqUwc02.css → index-BwvDb198.css} +1 -1
  11. package/gui/dist/index.html +2 -2
  12. package/package.json +20 -6
  13. package/src/adapters/anthropic.ts +16 -5
  14. package/src/adapters/google.ts +9 -2
  15. package/src/adapters/openai-chat.ts +13 -5
  16. package/src/bun-runtime.ts +22 -1
  17. package/src/cli-help.ts +111 -0
  18. package/src/cli-status.ts +164 -0
  19. package/src/cli.ts +77 -186
  20. package/src/codex-account-store.ts +47 -8
  21. package/src/codex-auth-api.ts +111 -54
  22. package/src/codex-auth-collision.ts +5 -0
  23. package/src/codex-catalog.ts +24 -12
  24. package/src/codex-history-provider.ts +29 -13
  25. package/src/codex-inject.ts +46 -29
  26. package/src/codex-journal.ts +77 -13
  27. package/src/codex-quota.ts +11 -3
  28. package/src/codex-routing.ts +14 -4
  29. package/src/codex-shim.ts +71 -24
  30. package/src/codex-websocket-registry.ts +20 -4
  31. package/src/config.ts +138 -4
  32. package/src/init.ts +7 -2
  33. package/src/oauth/callback-server.ts +22 -15
  34. package/src/oauth/index.ts +18 -4
  35. package/src/oauth/login-cli.ts +8 -1
  36. package/src/oauth/store.ts +2 -1
  37. package/src/process-control.ts +36 -0
  38. package/src/provider-label.ts +8 -0
  39. package/src/responses/parser.ts +18 -1
  40. package/src/router.ts +61 -5
  41. package/src/server.ts +878 -94
  42. package/src/service-secrets.ts +6 -0
  43. package/src/service.ts +293 -28
  44. package/src/types.ts +26 -1
  45. package/src/update.ts +16 -9
  46. package/src/usage-debug.ts +65 -0
  47. package/src/usage-log.ts +62 -0
  48. package/src/usage-summary.ts +0 -0
  49. package/src/ws-bridge.ts +2 -2
  50. package/gui/README.md +0 -73
  51. package/gui/dist/assets/index-DqGb2K_u.js +0 -9
package/README.ko.md CHANGED
@@ -34,7 +34,7 @@ Codex CLI / App / SDK ──/v1/responses──▶ opencodex ──▶ Any provi
34
34
 
35
35
  ```bash
36
36
  # 설치 (Bun 런타임이 자동으로 번들됩니다 — Node 18+ 만 있으면 됩니다)
37
- npm install -g @bitkyc08/opencodex # 또는: bun install -g @bitkyc08/opencodex
37
+ npm install -g @bitkyc08/opencodex
38
38
 
39
39
  # 대화형 설정 (config 작성 + Codex 주입 + 자동 시작 shim 설치 선택)
40
40
  ocx init
@@ -134,7 +134,7 @@ ocx logout <provider> # 저장된 로그인 정보 삭제
134
134
  ocx gui # 웹 대시보드 열기
135
135
  ocx codex-shim install # codex 실행 시 `ocx ensure` 실행
136
136
  ocx service <install|start|stop|status|uninstall> # 백그라운드 서비스 (launchd/systemd/schtasks)
137
- ocx update # opencodex 최신 버전으로 업데이트
137
+ ocx update [--tag preview] # opencodex 업데이트; preview 설치는 @preview 유지
138
138
  ```
139
139
 
140
140
  ### 자동 시작: service vs shim
@@ -143,7 +143,7 @@ opencodex에는 프록시를 자동 시작하는 두 가지 방법이 있습니
143
143
 
144
144
  | | `ocx service install` | `ocx codex-shim install` |
145
145
  |---|---|---|
146
- | **방식** | OS 서비스 관리자 (launchd / systemd / schtasks) | `codex` 바이너리를 래퍼 스크립트로 교체 |
146
+ | **방식** | OS 서비스 관리자 (launchd / systemd / schtasks) | `codex` 스크립트 런처를 래핑하며 실제 `codex.exe`는 건드리지 않음 |
147
147
  | **시점** | 로그인 후 항상 실행 | 온디맨드 — `codex` 실행 시 `ocx ensure` 실행 |
148
148
  | **재시작** | 크래시 시 자동 재시작 | `codex` 호출마다 한 번 시작 |
149
149
  | **Codex 업데이트** | 영향 없음 | `ocx codex-shim install` 또는 `ocx update` 시 복구 |
@@ -155,11 +155,11 @@ shim 자동 시작은 기본으로 켜져 있으며 GUI 대시보드에서 끌
155
155
 
156
156
  ### 삭제
157
157
 
158
- npm/bun 패키지를 지우기 전에 로컬 상태를 먼저 정리하세요:
158
+ npm 패키지를 지우기 전에 로컬 상태를 먼저 정리하세요:
159
159
 
160
160
  ```bash
161
161
  ocx uninstall
162
- npm uninstall -g @bitkyc08/opencodex # 또는: bun remove -g @bitkyc08/opencodex
162
+ npm uninstall -g @bitkyc08/opencodex
163
163
  ```
164
164
 
165
165
  `ocx uninstall`은 프록시 중지, 설치된 service 제거, Codex shim 제거, Codex config/catalog/history
@@ -219,7 +219,8 @@ export OPENCODEX_API_AUTH_TOKEN="your-secret-token"
219
219
  ocx start
220
220
  ```
221
221
 
222
- 비루프백 바인딩 시 이 환경 변수가 없으면 프록시 시작이 거부됩니다.
222
+ 비루프백 바인딩 시 이 환경 변수가 없으면 프록시 시작이 거부됩니다. LAN 접근용 백그라운드
223
+ 서비스를 설치할 때도 같은 셸에서 이 변수를 먼저 설정한 뒤 `ocx service install`을 실행해야 합니다.
223
224
  클라이언트(스크립트, 원격 머신)는 모든 요청에 토큰을 포함해야 합니다:
224
225
 
225
226
  ```
@@ -247,6 +248,16 @@ bun run dev # dev 모드로 프록시 시작
247
248
  bun x tsc --noEmit # 타입 체크
248
249
  ```
249
250
 
251
+ `bun run dev`는 프록시 API(`/healthz`, `/v1/responses`, `/api/*`)만 시작합니다. 패키징된
252
+ 대시보드 `/`를 함께 서빙하지 않습니다. 대시보드는 설치된 `ocx gui`를 쓰거나, 프론트엔드를
253
+ 수정할 때는 별도로 실행하세요:
254
+
255
+ ```bash
256
+ cd gui
257
+ bun install
258
+ bun dev
259
+ ```
260
+
250
261
  **[기여하기](https://lidge-jun.github.io/opencodex/ko/contributing/)** 를 참고하세요.
251
262
 
252
263
  ## 면책 조항
package/README.md CHANGED
@@ -58,7 +58,7 @@ Requires [Node](https://nodejs.org) 18+. The Bun runtime is bundled automaticall
58
58
 
59
59
  ```bash
60
60
  # Install (bundles the Bun runtime automatically — only Node 18+ required)
61
- npm install -g @bitkyc08/opencodex # or: bun install -g @bitkyc08/opencodex
61
+ npm install -g @bitkyc08/opencodex
62
62
 
63
63
  # Interactive setup (writes config, injects into Codex, and offers autostart shim install)
64
64
  ocx init
@@ -197,7 +197,7 @@ ocx login <xai|anthropic|kimi> # OAuth login
197
197
  ocx logout <provider> # remove a stored login
198
198
  ocx gui # open the web dashboard
199
199
  ocx service <install|start|stop|status|uninstall> # background service (launchd/systemd/schtasks)
200
- ocx update # update opencodex to the latest published version
200
+ ocx update [--tag preview] # update opencodex; preview installs stay on @preview
201
201
  ```
202
202
 
203
203
  ### Autostart: service vs shim
@@ -206,7 +206,7 @@ opencodex has two ways to auto-start the proxy:
206
206
 
207
207
  | | `ocx service install` | `ocx codex-shim install` |
208
208
  |---|---|---|
209
- | **How** | OS service manager (launchd / systemd / schtasks) | Replaces the `codex` binary with a wrapper script |
209
+ | **How** | OS service manager (launchd / systemd / schtasks) | Wraps script launchers for `codex`; real `codex.exe` is left untouched |
210
210
  | **When** | Always running after login | On-demand — runs `ocx ensure` when `codex` is launched |
211
211
  | **Restart** | Auto-restarts on crash | Starts once per `codex` invocation |
212
212
  | **Codex updates** | Unaffected | Repairs on next `ocx codex-shim install` or `ocx update` |
@@ -219,11 +219,11 @@ automatically picks another free local port and updates Codex to use it.
219
219
 
220
220
  ### Uninstall
221
221
 
222
- Before removing the npm/bun package, clean up local state:
222
+ Before removing the npm package, clean up local state:
223
223
 
224
224
  ```bash
225
225
  ocx uninstall
226
- npm uninstall -g @bitkyc08/opencodex # or: bun remove -g @bitkyc08/opencodex
226
+ npm uninstall -g @bitkyc08/opencodex
227
227
  ```
228
228
 
229
229
  `ocx uninstall` stops the proxy, removes any installed service, removes the Codex shim, restores
@@ -302,7 +302,9 @@ export OPENCODEX_API_AUTH_TOKEN="your-secret-token"
302
302
  ocx start
303
303
  ```
304
304
 
305
- The proxy refuses to start without this variable when binding beyond loopback.
305
+ The proxy refuses to start without this variable when binding beyond loopback. If you install a
306
+ background service for LAN access, export the same variable before `ocx service install` so the
307
+ service manager receives it.
306
308
  Clients (scripts, remote machines) must include the token in every request:
307
309
 
308
310
  ```
@@ -338,10 +340,20 @@ Maintainer source-of-truth notes live under [`structure/`](./structure). Histori
338
340
  git clone https://github.com/lidge-jun/opencodex.git
339
341
  cd opencodex
340
342
  bun install
341
- bun run dev # start the proxy in dev mode
343
+ bun run dev:proxy # start the proxy API in dev mode
344
+ bun run dev:gui # start the dashboard dev server in another terminal
342
345
  bun x tsc --noEmit # typecheck
343
346
  ```
344
347
 
348
+ `bun run dev` remains an alias for `bun run dev:proxy` for compatibility. In a source checkout,
349
+ the proxy API exposes `/healthz`, `/v1/responses`, and `/api/*`; `GET /` serves the packaged
350
+ dashboard only after `bun run build:gui` has produced `gui/dist`. While hacking on the dashboard,
351
+ run the frontend separately:
352
+
353
+ ```bash
354
+ bun run dev:gui
355
+ ```
356
+
345
357
  See **[Contributing](https://lidge-jun.github.io/opencodex/contributing/)**.
346
358
 
347
359
  ## Disclaimer
package/README.zh-CN.md CHANGED
@@ -33,7 +33,7 @@ Codex CLI / App / SDK ──/v1/responses──▶ opencodex ──▶ Any provi
33
33
 
34
34
  ```bash
35
35
  # 安装(自动打包 Bun 运行时 —— 只需 Node 18+)
36
- npm install -g @bitkyc08/opencodex # 或者: bun install -g @bitkyc08/opencodex
36
+ npm install -g @bitkyc08/opencodex
37
37
 
38
38
  # 交互式初始化(写入配置 + 注入 Codex)
39
39
  ocx init
@@ -126,7 +126,7 @@ ocx logout <provider> # 移除已保存的登录
126
126
  ocx gui # 打开 Web 仪表盘
127
127
  ocx codex-shim install # 运行 codex 时自动启动代理
128
128
  ocx service <install|start|stop|status|uninstall> # 后台服务(launchd/systemd/schtasks)
129
- ocx update # 更新到最新版
129
+ ocx update [--tag preview] # 更新 opencodex;preview 安装保持 @preview
130
130
  ```
131
131
 
132
132
  ### 自动启动:service vs shim
@@ -135,7 +135,7 @@ opencodex 提供两种自动启动代理的方式:
135
135
 
136
136
  | | `ocx service install` | `ocx codex-shim install` |
137
137
  |---|---|---|
138
- | **方式** | OS 服务管理器(launchd / systemd / schtasks) | `codex` 二进制替换为包装脚本 |
138
+ | **方式** | OS 服务管理器(launchd / systemd / schtasks) | 包装 `codex` 脚本启动器;不会改动真实 `codex.exe` |
139
139
  | **时机** | 登录后始终运行 | 按需 — 仅在运行 `codex` 时启动 |
140
140
  | **重启** | 崩溃后自动重启 | 每次调用 `codex` 时启动一次 |
141
141
  | **Codex 更新** | 不受影响 | 下次运行 `ocx codex-shim install` 或 `ocx update` 时修复 |
@@ -209,6 +209,15 @@ bun run dev # 以开发模式启动代理
209
209
  bun x tsc --noEmit # 类型检查
210
210
  ```
211
211
 
212
+ `bun run dev` 只启动代理 API(`/healthz`、`/v1/responses`、`/api/*`)。它不会同时在 `/`
213
+ 提供打包后的仪表盘。要打开仪表盘,请使用已安装的 `ocx gui`;如果要开发前端,请单独运行:
214
+
215
+ ```bash
216
+ cd gui
217
+ bun install
218
+ bun dev
219
+ ```
220
+
212
221
  参阅 **[贡献指南](https://lidge-jun.github.io/opencodex/zh-cn/contributing/)**。
213
222
 
214
223
  ## 免责声明
Binary file
Binary file
Binary file
package/bin/ocx.mjs CHANGED
@@ -10,14 +10,96 @@
10
10
  */
11
11
  import { spawnSync } from "node:child_process";
12
12
  import { createRequire } from "node:module";
13
- import { existsSync, statSync } from "node:fs";
14
- import { dirname, join } from "node:path";
13
+ import { existsSync, readFileSync, statSync } from "node:fs";
14
+ import { homedir } from "node:os";
15
+ import { dirname, join, resolve } from "node:path";
15
16
  import { fileURLToPath } from "node:url";
16
17
 
18
+ const PKG = "@bitkyc08/opencodex";
17
19
  const require = createRequire(import.meta.url);
18
20
  const here = dirname(fileURLToPath(import.meta.url));
19
21
  const cliPath = join(here, "..", "src", "cli.ts");
20
22
 
23
+ function isNodeModulesInstall() {
24
+ return here.split(/[\\/]/).includes("node_modules");
25
+ }
26
+
27
+ function isBunGlobalInstall() {
28
+ return /[\\/]\.bun[\\/]/.test(here);
29
+ }
30
+
31
+ function npmBin() {
32
+ return process.platform === "win32" ? "npm.cmd" : "npm";
33
+ }
34
+
35
+ function currentPackageVersion() {
36
+ try {
37
+ return JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")).version ?? "?";
38
+ } catch {
39
+ return "?";
40
+ }
41
+ }
42
+
43
+ function updateTag(currentVersion) {
44
+ const tagIndex = process.argv.indexOf("--tag");
45
+ if (tagIndex !== -1 && process.argv[tagIndex + 1]) return process.argv[tagIndex + 1];
46
+ return String(currentVersion).includes("-preview.") ? "preview" : "latest";
47
+ }
48
+
49
+ function configDir() {
50
+ return resolve(process.env.OPENCODEX_HOME?.trim() || join(homedir(), ".opencodex"));
51
+ }
52
+
53
+ function shouldRepairCodexShim() {
54
+ return existsSync(join(configDir(), "codex-shim.json"));
55
+ }
56
+
57
+ function repairCodexShimIfNeeded() {
58
+ if (!shouldRepairCodexShim()) return;
59
+ const launcher = fileURLToPath(import.meta.url);
60
+ const res = spawnSync(process.execPath, [launcher, "codex-shim", "install"], {
61
+ stdio: "inherit",
62
+ windowsHide: true,
63
+ });
64
+ if (res.status !== 0) {
65
+ console.warn(`opencodex: Codex shim repair failed (${res.status ?? "unknown exit"}). Try: ocx codex-shim install`);
66
+ }
67
+ }
68
+
69
+ function runNpmSelfUpdate() {
70
+ const current = currentPackageVersion();
71
+ const tag = updateTag(current);
72
+ const npm = npmBin();
73
+ const latestResult = spawnSync(npm, ["view", `${PKG}@${tag}`, "version"], {
74
+ encoding: "utf8",
75
+ timeout: 12000,
76
+ windowsHide: true,
77
+ });
78
+ const latest = latestResult.status === 0 ? latestResult.stdout.trim() : "";
79
+
80
+ console.log(`opencodex v${current} (installed via npm, tag ${tag})`);
81
+ if (latest && latest === current) {
82
+ console.log(`Already on the latest ${tag} version (v${latest}).`);
83
+ process.exit(0);
84
+ }
85
+
86
+ console.log(`Updating${latest ? ` to v${latest}` : ""}...\n$ ${npm} install -g ${PKG}@${tag}`);
87
+ const res = spawnSync(npm, ["install", "-g", `${PKG}@${tag}`], {
88
+ stdio: "inherit",
89
+ timeout: 180000,
90
+ windowsHide: true,
91
+ });
92
+ if (res.status === 0) {
93
+ console.log(`\nUpdated${latest ? ` to v${latest}` : ""}.`);
94
+ repairCodexShimIfNeeded();
95
+ console.log("Restart the proxy: ocx stop && ocx start");
96
+ console.log("If a background service is installed, refresh its baked path: ocx service install");
97
+ process.exit(0);
98
+ }
99
+ console.error(`\nUpdate failed (${npm} exit ${res.status ?? "?"}). Try manually: ${npm} install -g ${PKG}@${tag}`);
100
+ process.exit(1);
101
+ }
102
+
21
103
  function bunBinDir() {
22
104
  // Resolve the `bun` dependency's directory without hardcoding the platform
23
105
  // package — npm's os/cpu/libc resolution already picked the right @oven/bun-*.
@@ -73,6 +155,10 @@ function resolveBun() {
73
155
  return bin;
74
156
  }
75
157
 
158
+ if (process.argv[2] === "update" && isNodeModulesInstall() && !isBunGlobalInstall()) {
159
+ runNpmSelfUpdate();
160
+ }
161
+
76
162
  const bun = resolveBun();
77
163
  const res = spawnSync(bun, [cliPath, ...process.argv.slice(2)], { stdio: "inherit" });
78
164
  if (res.error) {
@@ -0,0 +1,9 @@
1
+ export const packageName = "@bitkyc08/opencodex";
2
+ export const cliCommand = "ocx";
3
+
4
+ export async function loadBunApi() {
5
+ if (typeof Bun === "undefined") {
6
+ throw new Error("The opencodex programmatic API requires the Bun runtime. Use `ocx` for the CLI entrypoint.");
7
+ }
8
+ return import("../src/index.ts");
9
+ }