Repository navigation
feat: codex takeover, history sync, and embedded web UI - #73
Conversation
LX666-666
commented
Aug 9, 2026
- Add codex-takeover module to intercept and redirect codex traffic
- Add codex-history for persistent conversation history sync
- Add codex-provider for active provider capture
- Add content-encoding helpers for transparent body decoding
- Replace monolithic src/web.ts with modular src/web/ (api/client/page/styles)
- Refactor upstream-proxy: cleaner CONNECT handling, per-URL config
- Update responses/server/cli/config to wire new modules
- Add 6 new test files covering codex, web routing, content encoding
- Add codex-takeover module to intercept and redirect codex traffic - Add codex-history for persistent conversation history sync - Add codex-provider for active provider capture - Add content-encoding helpers for transparent body decoding - Replace monolithic src/web.ts with modular src/web/ (api/client/page/styles) - Refactor upstream-proxy: cleaner CONNECT handling, per-URL config - Update responses/server/cli/config to wire new modules - Add 6 new test files covering codex, web routing, content encoding Co-Authored-By: AtomCode (GLM-5.2) <noreply@atomgit.com>
Review:「无法使用工具」根因 —— text-protocol 下
|
Codex code_mode tools (shell_command/apply_patch, declared via additional_tools) come back from upstream as custom_tool_call output items, not function_call. In text-protocol mode (auto-enabled for Codex by PR#73), the compress loop's realtime yield gate suppressed ALL non-meta events to buffer output_text for compress-trigger scanning. custom_tool_call items were neither captured (only function_call is) nor re-emitted at end-of-turn (only output_text is) — so every code_mode tool call was silently dropped, and Codex received only text. This is the root cause of the reported '无法使用工具'. Fix: tag custom_tool_call events with noBuffer so they bypass the text-protocol suppression and stream to the client in realtime (the same behavior that already works in non-text-protocol mode). output_text is still buffered for trigger scanning. Also count custom_tool_call items in [acp-diag] so code_mode usage is visible (allCalls is function_call only). Note: NOT tested against a live Codex session. Validated via: - npm run typecheck (clean) - npm test (202 pass, incl. new regression test that fails on the unpatched code and passes with this fix) Conflict note: touches only src/compress-loop-responses.ts (PR#73-only file, not modified by master), so it will not conflict with the responses.ts/server.ts merge conflicts that PR#73 currently has with master.
已实现修复:
|
| 文件 | 结果 |
|---|---|
README.md / README.zh-CN.md / package.json |
✅ 自动合并 |
src/responses.ts |
❌ 6 处冲突 |
src/server.ts |
❌ 2 处冲突 |
性质上可解,但需人工 + 测试:冲突是 PR#73 的 layout-based 输入重建(ResponsesProjection.layout / patchResponsesInput)与 master #71 的 reasoning 压缩(droppedReasoning / shouldDropAllReasoning)在同一区域交织,两者功能正交,合的时候要同时保留 layout 字段和 droppedReasoning 字段。responses.ts line 340-417 那块最大(~77 行),需要仔细手解。建议由 PR 作者 rebase 到最新 master 后解冲突,并跑一遍 reasoning 相关测试(tests/bili-message-roundtrip.test.ts 是 master 新加的)。
好消息:本次修 custom_tool_call 的改动只在 compress-loop-responses.ts,这个文件 master 没动过,所以不会和 master 冲突,可以干净地 cherry-pick 到解完冲突后的分支上。
建议的落地顺序
- PR 作者把 PR#73 rebase 到 master,手解
responses.ts/server.ts冲突(保留 layout + droppedReasoning 两套)。 - Cherry-pick
ed4d4c4(或直接 mergefix/codex-custom-tool-call-text-protocol,它基于97190f5,应该能干净合入)。 - 实机跑一次 Codex,确认
[acp-diag] ... customToolCalls=N在调用工具时 >0、且工具能真正执行。
Ported master's reasoning-through-compression (ranxianglei#71) and count_tokens (ranxianglei#72) features onto PR#73's layout-based patching architecture: responses.ts: - Removed 'reasoning' from OPAQUE_ITEM_TYPES (master: reasoning is conversation history, routed through compression, not preserved verbatim) - Added droppedReasoning counter + shouldDropAllReasoning() escape hatch (ACP_REASONING_KEEP=none) - Added 'reasoning' case to responsesToCore switch: creates a tracked BiliMessage (contentType 'reasoning', rawResponsesItem carried) so the kernel hides it once its turn is summarized; dropped reasoning uses 'continue' to skip layout.push so it is fully removed - Added reasoning re-emit to coreToResponses (assistant contentType 'reasoning' -> push raw verbatim) - patchOriginalItem needs no change: reasoning items are preserved via slot.original when their turn is live, dropped (nextById miss) when compressed -- correct by construction server.ts: - Added countTokens detection (isCountTokensRequest) + prepareCountTokens (read-only processTurn mirror so count_tokens reports post-compression count; ACP_COUNT_TOKENS_PASSTHROUGH=1 escape hatch) - Merged prepare ternary: countTokens -> anthropic -> openai -> responsesCompact -> responses Validation: typecheck clean, 216 tests pass (incl. 9 reasoning + 3 count_tokens + custom_tool_call fix), build ok.
readProviders previously read only the inline config.providers entries without normalizeUrlKey or merging the external ACP_PROVIDERS file, so the web UI could show a different route set than the running proxy actually used. Delegate to loadRoutes() (already used by the /reload endpoint) so display == runtime.
- responses.ts: route opaque call items (computer_call, file_search_call, web_search_call, image_generation_call, code_interpreter_call, mcp_call) through compression via contentType 'reasoning' with 'responses-call' kind. Track custom_tool_call/custom_tool_call_output fully (port master). Lift developer/system messages out of layout into systemParts (avoid duplication when re-injecting as developer message). - server.ts: include systemParts (base instructions) in the injected developer message alongside the compress prompt; restore base instructions even when compress injection is disabled. Strip previous_response_id and top-level instructions (lifted into developer message). - tests: update codex-official + proxy-responses-review for new behavior (instructions lifted into developer message; custom_tool_call tracked).
…viders Custom Codex providers routinely omit requires_openai_auth and supports_websockets (they are optional in Codex's native config). The strict validation threw an error for any custom provider missing them, surfacing a confusing warning on the web config page even though the provider was fully functional. Default both fields to false for custom providers (matching Codex's own behavior: custom providers don't use OAuth and don't support websockets). The builtin 'openai' provider still uses its documented defaults. Tighten boolField to require a boolean fallback so the resolved fields are always typed boolean.
Code Review: PR #73 — codex takeover / history sync / embedded web UI
总体方向很好: 🔴 阻塞合并(critical / high)1.
|
…URL proxy UI - routing: rename 'Codex 路由' → '客户端接入'; Codex is one client card alongside Claude Code / Gemini CLI / MITM placeholders (each with setup instructions). Generic lead text covers both integration methods. - upstream: default proxy mode 'direct' (was 'auto' which silently picked up system HTTP_PROXY env — risky for a proxy tool). Relabel modes: 直连(默认) / 手动代理 / 自动(跟随系统). - upstream: add '按 URL 覆盖' structured table — edit per-Provider upstream proxy inline (empty = inherit global). No longer buried in raw JSON. - settings: relabel '高级设置', clarify it's for raw providers JSON (adding providers, model context windows, etc).
Web 端设计评审(补充:交互 / 架构 / UX 层面)
架构设计1. 后端路由无抽象 —— 30+ 端点全靠
|
…b client
- codex-history.ts: indirect specifier so esbuild cannot rewrite the
dynamic import('node:sqlite') into __require('sqlite'), which fails
to resolve at runtime. Node 22.5+ resolves the native import directly.
- web/client.ts: remove byId() calls for route-codex-switch,
upstream-global-mode, upstream-provider-override — these elements were
removed during the routing/upstream restructure but their JS setters
remained, causing 'Cannot set properties of null' on page load.
测试质量评审(PR #73)
✅ 做得好的(已逐一核对)
❌ 覆盖空白 —— 正好对着本 PR 新代码的 bug
最关键的是前两个: writeFileSync(statePath, "{garbage");
assert.doesNotThrow(() => getCodexTakeoverStatus(files)); // 而非 throw这个测试 ~15 行,能顺带把 bug #1 暴露出来。
|
勘误:bug 评审中 pre-existing 项的归属说明我第一条评论(bug 评审)里,部分缺陷其实是 master 既存的(PRP #73 未引入,只是重构了周边),现已拆分成独立 issue 追踪,不 block 本 PR:
本 PR 范围内(代码是 PR 新增/改动,建议 PR 内修)的仍是:
依据: 测试评审见上一条评论,也已按此边界区分。 |
…efault Routing page restructured per README: - Category A (API-key clients, /bili/ prefix): OpenCode, Codex (API key), Pi, Claude Code (API key), Generic (Cursor/Aider/Continue). Each card shows the full prefixed URL with a copy button. - Category B (subscription/login clients): Codex Route takeover (existing), Claude Code (MITM), ZCode (MITM). Shows proxy + CA cert setup. - Removed Gemini CLI card (not in README supported list). - Generic copy-btn handler for all static-URL cards. - config.ts: upstream proxyMode default changed from 'auto' to 'direct' (bili is itself a proxy; should not chain through system HTTP_PROXY by default).
…eload Review feedback from ranxianglei (PR#73 comments ranxianglei#3-ranxianglei#4): 1. [ranxianglei#9 critical] Restore Responses session-identity fallback chain (responses.ts): header → body.session_id → metadata.session_id → previous_response_id → content-fingerprint(hashId). The previous generated-randomUUID() broke compression for headerless clients (Pi, plain OpenAI SDK) — every request got a new session so compression state never accumulated. 2. [ranxianglei#1+ranxianglei#2 critical] parseState robustness (codex-takeover.ts): corrupted state file now returns undefined (treat as stale/recoverable) instead of throwing, which would leave Codex CLI unusable. Added sectionPrefixLength type validation (non-negative number) to prevent NaN slicing that could wipe the entire config.toml. 3. [Comment#4 ranxianglei#2] PUT /__bili/config onChanged now also refreshes routes (server.ts): previously only proxy fields were refreshed, so pure API callers (non-Web-UI) had to also POST /reload for provider config to take effect. Now PUT guarantees save-then-apply in one call. 4. Fix misleading context-window hint on routing page (page.ts).
…UT-reload, affinityToken Addresses test-quality review (PR#73 comment #5234982438): - codex-takeover: corrupted state file degrades to disabled (not throw) - codex-takeover: non-numeric sectionPrefixLength rejected (not wipe config) - web-routing: PUT providers takes effect without separate /reload - proxy-session-id: affinityToken test name now matches assertion (was 'does NOT embed API key' but only checked passthrough)