Skip to content

Commit c5d4292

Browse files
committed
bootstrap repository
0 parents  commit c5d4292

1 file changed

Lines changed: 195 additions & 0 deletions

File tree

README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# codex-viewer
2+
3+
`codex-viewer` 是一个面向 Codex CLI 的 Web 可视化工具。它一边在浏览器里代理执行 `codex`,一边实时捕获和展示请求、响应、上下文、多轮工具调用、token 消耗与终端输出。
4+
5+
适合这几类场景:
6+
7+
- 想在浏览器里使用接近终端的 Codex 输入体验
8+
- 想看清 Codex 到模型层的真实 request / response 结构
9+
- 想排查多轮 tool call、continuation request、token usage 的执行链路
10+
- 想把 Codex CLI 包装成一个可直接分发给团队使用的 npm 工具
11+
12+
## 功能概览
13+
14+
- 浏览器中直接发起 Codex 任务,支持多轮上下文持久化
15+
- 直连代理拦截 Codex 与模型上游之间的 HTTP / SSE / WebSocket 数据
16+
- 实时查看 request、response、protocol chain、timeline、terminal
17+
- 单独查看工具调用与工具响应,并追踪 continuation request
18+
- JSON 可视化查看,支持树形折叠、格式化代码视图、复制与下载
19+
- 支持图片与文件附件
20+
- 自动处理非 ASCII 工作目录,必要时镜像到 `/tmp`
21+
22+
## 界面预览
23+
24+
### 1. Codex 输入工作区
25+
26+
![Codex input workspace](./docs/screenshots/codex-input.svg)
27+
28+
### 2. 请求可视化面板
29+
30+
![Request visualization](./docs/screenshots/request-visualization.svg)
31+
32+
### 3. JSON 结构查看
33+
34+
![JSON viewer](./docs/screenshots/json-viewer.svg)
35+
36+
## 安装
37+
38+
### 全局安装
39+
40+
```bash
41+
npm install -g codex-viewer
42+
```
43+
44+
安装完成后可直接运行:
45+
46+
```bash
47+
codex-viewer --port 3789
48+
```
49+
50+
### 免安装快速运行
51+
52+
```bash
53+
npx codex-viewer --port 3789
54+
```
55+
56+
## 前置条件
57+
58+
在启动 `codex-viewer` 之前,请确认:
59+
60+
- 已安装 Node.js `18+`
61+
- 已安装可执行的 `codex` CLI
62+
- `codex` 已完成登录或具备可用的 API / CLI 认证环境
63+
64+
如果你的 `codex` 不在系统 PATH 中,可以通过 `--codex-bin` 指定路径。
65+
66+
## 启动方式
67+
68+
最常用的启动命令:
69+
70+
```bash
71+
codex-viewer --port 3789
72+
```
73+
74+
然后打开:
75+
76+
```text
77+
http://127.0.0.1:3789
78+
```
79+
80+
你之前本地用的这条命令依然可用:
81+
82+
```bash
83+
node bin/codex-viewer.js --port 3789
84+
```
85+
86+
## 常用参数
87+
88+
```bash
89+
codex-viewer \
90+
--port 3789 \
91+
--host 127.0.0.1 \
92+
--cd /path/to/workspace \
93+
--codex-bin codex \
94+
--proxy-port 0
95+
```
96+
97+
主要参数说明:
98+
99+
- `--port`:Web 服务端口,默认 `3789`
100+
- `--host`:监听地址,默认 `127.0.0.1`
101+
- `--cd`:默认工作目录
102+
- `--codex-bin`:Codex CLI 路径,默认 `codex`
103+
- `--proxy-port`:本地直连代理端口,默认 `0`,表示自动分配空闲端口
104+
- `--max-events`:前端保留的结构化事件数量
105+
- `--proxy-max-body`:单个 HTTP 请求/响应允许捕获的最大 body 大小
106+
- `--proxy-max-ws`:单个 WebSocket frame 允许捕获的最大大小
107+
- `--proxy-max-json`:允许解析的最大 JSON 体大小
108+
109+
## 使用流程
110+
111+
1. 启动 `codex-viewer`
112+
2. 在浏览器中进入输入页
113+
3. 选择工作目录、模型,必要时添加图片或文件
114+
4. 在输入框中直接输入任务并发送
115+
5.`request visualization` 中查看:
116+
- 原始 request
117+
- 最终 response
118+
- tool call / tool response
119+
- continuation request
120+
- protocol chain
121+
- terminal 输出
122+
123+
## 这个工具拦截了什么
124+
125+
`codex-viewer` 会在本地启动一层直连代理,把 Codex 的模型请求先导到本地,再转发到上游接口。这样可以捕获:
126+
127+
- session request
128+
- model request
129+
- model response
130+
- tool call
131+
- tool response
132+
- continuation request
133+
- usage / token 统计
134+
- 错误事件
135+
- 终端输出流
136+
137+
对于 JSON 请求体,会额外提取核心结构,包括:
138+
139+
- `messages`
140+
- `input`
141+
- `instructions`
142+
- `tool` 上下文
143+
- `usage`
144+
145+
## 工作区镜像
146+
147+
在某些环境下,Codex CLI 无法直接从包含中文或其他非 ASCII 字符的路径运行。
148+
`codex-viewer` 会检测这类情况,并支持自动镜像到 `/tmp/codex-viewer-mirrors/...` 后再运行。
149+
150+
## 本地开发
151+
152+
```bash
153+
npm install
154+
npm test
155+
node bin/codex-viewer.js --port 3789
156+
```
157+
158+
如果你只想检查最终发布包内容:
159+
160+
```bash
161+
npm run pack:check
162+
```
163+
164+
## 发布到 npm
165+
166+
项目已经准备成可直接发布的 npm CLI 包。正式发布前,建议按下面顺序执行:
167+
168+
```bash
169+
npm login
170+
npm whoami
171+
npm run pack:check
172+
npm publish --access public
173+
```
174+
175+
如果 `codex-viewer` 这个 unscoped 包名已被占用,建议改成组织作用域,例如:
176+
177+
```bash
178+
@your-scope/codex-viewer
179+
```
180+
181+
对应安装命令会变成:
182+
183+
```bash
184+
npm install -g @your-scope/codex-viewer
185+
```
186+
187+
## 建议在发布前再补一项
188+
189+
如果你希望 npm 包页面中的 README 截图也稳定显示,建议在 `package.json` 里补上实际 GitHub 仓库地址:
190+
191+
- `repository`
192+
- `homepage`
193+
- `bugs`
194+
195+
这样 npm 页面能更稳定地解析 README 中的图片与跳转链接。

0 commit comments

Comments
 (0)