|
1 | 1 | # Codex Account Manager |
2 | 2 |
|
3 | | -Codex Account Manager is a SolidJS frontend with a Zig backend powered by [zig-webui](https://github.com/webui-dev/zig-webui). |
| 3 | +Codex Account Manager is a SolidJS + Zig app (via [zig-webui](https://github.com/webui-dev/zig-webui)) for managing multiple Codex accounts. |
| 4 | + |
| 5 | +It can switch the active `~/.codex/auth.json` on the fly, organize accounts by status, and show remaining usage per account. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Manage multiple Codex accounts in one place |
| 10 | +- Switch active account instantly |
| 11 | +- Credits/usage checks via ChatGPT token flow (`/backend-api/wham/usage`) |
| 12 | +- Account buckets: |
| 13 | + - active |
| 14 | + - depleted |
| 15 | + - frozen |
| 16 | +- Drag-and-drop reordering in desktop and web modes |
| 17 | +- Custom desktop title bar controls: |
| 18 | + - minimize |
| 19 | + - fullscreen toggle |
| 20 | + - close |
| 21 | + - double-click title bar to toggle fullscreen |
| 22 | +- Theme persistence (light/dark) |
| 23 | + |
| 24 | +## Tech Stack |
| 25 | + |
| 26 | +- Frontend: SolidJS (`frontend/src`) |
| 27 | +- Backend: Zig (`src`, `main.zig`) |
| 28 | +- Runtime bridge: `window.cm_rpc(...)` and `window.webui.call(...)` |
| 29 | +- Build pipeline: Zig orchestrates frontend typecheck + Vite builds (`build.zig`) |
4 | 30 |
|
5 | | -It manages multiple Codex accounts, switches active `~/.codex/auth.json` on the fly, and checks per-account credits. |
| 31 | +## Requirements |
| 32 | + |
| 33 | +- Zig `0.15+` |
| 34 | +- Node.js `20+` |
| 35 | +- `npm` |
| 36 | +- `curl` |
| 37 | +- `codex` CLI |
| 38 | + |
| 39 | +Linux desktop mode also requires GTK/WebKitGTK runtime libraries for WebView. |
| 40 | + |
| 41 | +## Dependency Matrix |
| 42 | + |
| 43 | +### Shared (all OS) |
| 44 | + |
| 45 | +| Type | Dependencies | |
| 46 | +|---|---| |
| 47 | +| Comptime (build-time) | Zig `0.15.2+`, Node.js `20+`, npm, frontend packages: `solid-js`, `vite`, `vite-plugin-solid`, `typescript` | |
| 48 | +| Runtime | `curl` in `PATH`, `codex` CLI in `PATH` | |
| 49 | +| Notes | `zig_webui` is vendored via `build.zig.zon` and built as a static Zig dependency (`enable_tls = false`) | |
| 50 | + |
| 51 | +### Linux |
6 | 52 |
|
7 | | -## Architecture |
| 53 | +| Type | Dependencies | |
| 54 | +|---|---| |
| 55 | +| Comptime (build-time) | Shared dependencies above; C compilation support via Zig toolchain | |
| 56 | +| Runtime (desktop mode `--desktop`) | `libgtk-3.so.0`, `libwebkit2gtk-4.1.so.0` (or `libwebkit2gtk-4.0.so.37`) and their distro-provided transitive libs | |
| 57 | +| Runtime (web mode `--web`) | A supported installed browser (default browser launch path) | |
| 58 | +| Notes | This project loads GTK/WebKit at runtime via `dlopen`, so missing desktop libs fail at runtime, not compile time | |
8 | 59 |
|
9 | | -- Frontend: SolidJS (`/home/a/projects/js/codex_manager/frontend/src`) |
10 | | -- Backend runtime: Zig + WebUI (`/home/a/projects/js/codex_manager/src`) |
11 | | -- Function bridge: |
12 | | - - `window.cm_rpc(...)` (provided by `/webui.js` in desktop and `--web` modes) |
| 60 | +### macOS |
13 | 61 |
|
14 | | -## Build System |
| 62 | +| Type | Dependencies | |
| 63 | +|---|---| |
| 64 | +| Comptime (build-time) | Shared dependencies above; Xcode Command Line Tools (clang + macOS SDK) for Objective-C/WebKit build path | |
| 65 | +| Runtime (desktop mode `--desktop`) | System frameworks: `Cocoa.framework`, `WebKit.framework` | |
| 66 | +| Runtime (web mode `--web`) | A default browser | |
| 67 | +| Notes | No GTK/WebKitGTK packages are required on macOS | |
15 | 68 |
|
16 | | -The Zig project is now root-level: |
| 69 | +### Windows |
17 | 70 |
|
18 | | -- `/home/a/projects/js/codex_manager/build.zig` |
19 | | -- `/home/a/projects/js/codex_manager/build.zig.zon` |
| 71 | +| Type | Dependencies | |
| 72 | +|---|---| |
| 73 | +| Comptime (build-time) | Shared dependencies above; C/C++ build support and Windows SDK link libs (`ws2_32`, `ole32`, and ABI-specific system libs) | |
| 74 | +| Runtime (desktop mode `--desktop`) | Microsoft Edge WebView2 Runtime | |
| 75 | +| Runtime (web mode `--web`) | A default browser | |
| 76 | +| Notes | WebView2 headers are vendored by the `webui` dependency; no separate header package is required | |
20 | 77 |
|
21 | | -### Commands |
| 78 | +## Development |
22 | 79 |
|
23 | | -Run app in dev mode: |
| 80 | +Run in default mode (web mode): |
24 | 81 |
|
25 | 82 | ```bash |
26 | 83 | zig build dev |
27 | 84 | ``` |
28 | 85 |
|
29 | | -Default dev mode runs browser-hosted WebUI (`--web` behavior). |
30 | | - |
31 | | -Run app in web mode: |
| 86 | +Run explicitly in web mode: |
32 | 87 |
|
33 | 88 | ```bash |
34 | 89 | zig build dev -- --web |
35 | 90 | ``` |
36 | 91 |
|
37 | | -Run desktop WebView mode explicitly: |
| 92 | +Run in desktop WebView mode: |
38 | 93 |
|
39 | 94 | ```bash |
40 | 95 | zig build dev -- --desktop |
41 | 96 | ``` |
42 | 97 |
|
43 | | -Build/install release binary: |
| 98 | +## Build and Install |
| 99 | + |
| 100 | +Build/install optimized binary: |
44 | 101 |
|
45 | 102 | ```bash |
46 | 103 | zig build install -Doptimize=ReleaseFast |
47 | 104 | ``` |
48 | 105 |
|
49 | | -Output binary: |
| 106 | +Binary output: |
50 | 107 |
|
51 | | -- Linux/macOS: `/home/a/projects/js/codex_manager/zig-out/bin/codex-manager` |
52 | | -- Windows: `/home/a/projects/js/codex_manager/zig-out/bin/codex-manager.exe` |
| 108 | +- Linux/macOS: `zig-out/bin/codex-manager` |
| 109 | +- Windows: `zig-out/bin/codex-manager.exe` |
53 | 110 |
|
54 | | -Run built binary in web mode: |
| 111 | +Run installed binary: |
55 | 112 |
|
56 | 113 | ```bash |
57 | 114 | ./zig-out/bin/codex-manager --web |
| 115 | +./zig-out/bin/codex-manager --desktop |
58 | 116 | ``` |
59 | 117 |
|
60 | | -Run built binary in desktop mode: |
| 118 | +## Testing |
| 119 | + |
| 120 | +Run backend Zig tests: |
61 | 121 |
|
62 | 122 | ```bash |
63 | | -./zig-out/bin/codex-manager --desktop |
| 123 | +zig build test |
64 | 124 | ``` |
65 | 125 |
|
66 | | -## Self-contained Binary |
| 126 | +## Storage |
67 | 127 |
|
68 | | -`zig build install` compiles a single binary with frontend assets embedded at compile time: |
69 | | -- web bundle: `frontend/dist-web/index.html` |
70 | | -- desktop bundle: `frontend/dist-desktop/index.html` |
| 128 | +- Managed accounts: app local data directory, file `accounts.json` |
| 129 | +- UI bootstrap cache: app local data directory, file `bootstrap-state.json` |
| 130 | +- Theme setting: app local data directory, file `ui-theme.txt` |
| 131 | +- Active Codex auth target: `~/.codex/auth.json` |
71 | 132 |
|
72 | | -The runtime does not depend on shipping any external `dist` folder. |
| 133 | +## Troubleshooting |
73 | 134 |
|
74 | | -## Requirements |
| 135 | +- `WebUI RPC unavailable in this session`: |
| 136 | + - Launch through the app (`zig build dev -- --web` or `zig build dev -- --desktop`) |
| 137 | + - Open the app URL from the printed `127.0.0.1` address |
| 138 | +- Desktop WebView crashes on Linux: |
| 139 | + - Ensure GTK/WebKitGTK packages are installed |
| 140 | + - Try web mode (`--web`) if your system WebView stack is unstable |
| 141 | +- Window buttons do nothing: |
| 142 | + - This can happen in plain browser mode |
| 143 | + - Use desktop mode for native window controls |
75 | 144 |
|
76 | | -- Node.js 20+ |
77 | | -- Zig 0.15+ |
78 | | -- `curl` in PATH |
79 | | -- `codex` CLI |
| 145 | +## Notes |
| 146 | + |
| 147 | +- Frontend bundles are built into two targets: |
| 148 | + - `dist-web` |
| 149 | + - `dist-desktop` |
| 150 | +- The executable is self-contained for app logic and embedded frontend assets. |
0 commit comments