Skip to content

Commit 99cbafc

Browse files
committed
build codex viewer direct proxy ui
1 parent c5d4292 commit 99cbafc

35 files changed

Lines changed: 18117 additions & 0 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.npm-cache
3+
.DS_Store
4+
npm-debug.log*
5+
coverage
6+
*.tgz
7+
.codex-viewer/mitm-ca/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bin/codex-viewer.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env node
2+
3+
import process from 'node:process';
4+
import path from 'node:path';
5+
import { Command } from 'commander';
6+
import { startServer } from '../src/live-server.js';
7+
8+
const program = new Command();
9+
10+
program
11+
.name('codex-viewer')
12+
.description('Direct-proxy web viewer for Codex CLI')
13+
.version('0.4.0');
14+
15+
program
16+
.option('-p, --port <port>', 'server port', '3789')
17+
.option('-H, --host <host>', 'server host', '127.0.0.1')
18+
.option('--codex-bin <path>', 'codex executable path', 'codex')
19+
.option('--max-events <n>', 'max buffered structured events', '3000')
20+
.option('--proxy-port <port>', 'direct proxy listen port (0 = random free port)', '0')
21+
.option('--proxy-max-body <bytes>', 'max captured body bytes per request/response', String(512 * 1024))
22+
.option('--proxy-max-ws <bytes>', 'max captured websocket frame bytes', String(128 * 1024))
23+
.option('--proxy-max-json <bytes>', 'max parsed json bytes per payload', String(256 * 1024))
24+
.option('-C, --cd <dir>', 'default working directory')
25+
.action(async (options) => {
26+
const port = Number.parseInt(options.port, 10);
27+
if (!Number.isFinite(port) || port <= 0) {
28+
throw new Error(`Invalid port: ${options.port}`);
29+
}
30+
31+
const host = String(options.host || '127.0.0.1');
32+
const workdir = options.cd ? path.resolve(String(options.cd)) : process.cwd();
33+
const maxEvents = Number.parseInt(String(options.maxEvents || '3000'), 10);
34+
if (!Number.isFinite(maxEvents) || maxEvents < 100) {
35+
throw new Error(`Invalid max-events: ${options.maxEvents}`);
36+
}
37+
38+
const proxyPort = Number.parseInt(String(options.proxyPort || '0'), 10);
39+
if (!Number.isFinite(proxyPort) || proxyPort < 0) {
40+
throw new Error(`Invalid proxy-port: ${options.proxyPort}`);
41+
}
42+
43+
const proxyMaxBodyBytes = Number.parseInt(String(options.proxyMaxBody || 512 * 1024), 10);
44+
if (!Number.isFinite(proxyMaxBodyBytes) || proxyMaxBodyBytes < 4096) {
45+
throw new Error(`Invalid proxy-max-body: ${options.proxyMaxBody}`);
46+
}
47+
48+
const proxyMaxWsBytes = Number.parseInt(String(options.proxyMaxWs || 128 * 1024), 10);
49+
if (!Number.isFinite(proxyMaxWsBytes) || proxyMaxWsBytes < 1024) {
50+
throw new Error(`Invalid proxy-max-ws: ${options.proxyMaxWs}`);
51+
}
52+
53+
const proxyMaxJsonBytes = Number.parseInt(String(options.proxyMaxJson || 256 * 1024), 10);
54+
if (!Number.isFinite(proxyMaxJsonBytes) || proxyMaxJsonBytes < 1024) {
55+
throw new Error(`Invalid proxy-max-json: ${options.proxyMaxJson}`);
56+
}
57+
58+
const service = await startServer({
59+
host,
60+
port,
61+
options: {
62+
codexBin: options.codexBin,
63+
workdir,
64+
maxEvents,
65+
proxy: true,
66+
proxyPort,
67+
proxyMaxBodyBytes,
68+
proxyMaxWsBytes,
69+
proxyMaxJsonBytes
70+
}
71+
});
72+
73+
console.log(`codex-viewer: http://${host}:${port}`);
74+
75+
await new Promise((resolve) => {
76+
let closed = false;
77+
78+
async function shutdown() {
79+
if (closed) {
80+
return;
81+
}
82+
83+
closed = true;
84+
service.stopRunner();
85+
service.closeSockets();
86+
await service.stopProxy?.();
87+
service.server.close(() => resolve());
88+
}
89+
90+
process.on('SIGINT', shutdown);
91+
process.on('SIGTERM', shutdown);
92+
});
93+
});
94+
95+
program.parseAsync(process.argv).catch((error) => {
96+
console.error(`codex-viewer error: ${error.message}`);
97+
process.exitCode = 1;
98+
});

docs/screenshots/codex-input.svg

Lines changed: 36 additions & 0 deletions
Loading

docs/screenshots/json-viewer.svg

Lines changed: 64 additions & 0 deletions
Loading
Lines changed: 54 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)