Skip to content

feat(remote): Codex 移动端远程控制 M1(Telegram Bot Channel + CDP 驱动)#496

Open
Cmochance wants to merge 10 commits into
mainfrom
worktree-feat+moc-249-codex-remote-control
Open

feat(remote): Codex 移动端远程控制 M1(Telegram Bot Channel + CDP 驱动)#496
Cmochance wants to merge 10 commits into
mainfrom
worktree-feat+moc-249-codex-remote-control

Conversation

@Cmochance

Copy link
Copy Markdown
Owner

不依赖 GPT 账号、用手机远程驱动本地 Codex。transfer Rust 端跑一个 Telegram bot(纯 HTTPS long-poll,无 relay / 公网回调,绕开 Codex renderer CSP):授权用户在手机 Telegram 给 bot 发消息 → 经 CDP 把 prompt 灌进 Codex 输入框(ProseMirror)、提交、读流式输出回编到 Telegram 消息。手机端 = 已有的 Telegram app。

借鉴智谱 ZCode v3.1.0 的 Bot Channel 设计(命令文法、按用户绑定、流式回复),不移植其代码。可行性已端到端 spike 实证。

改动

  • src-tauri/src/codex_remote/{driver,telegram,mod}.rs:CodexDriver(CDP 驱动 Codex 发对话/读输出)+ Telegram 客户端 + daemon(白名单鉴权、命令 /new /stop /status /help、流式回复)
  • 复用 codex_theme_injector 的 CDP 原语 + codex_quota_injector 的 daemon 骨架
  • should_attach_debug_portcodexRemoteControlEnabled;settings UI(开关 + Bot Token + 白名单,中英 i18n);README 中英
  • 8 个单测;默认关

用户影响

设置 → 「移动端远程控制(Telegram)」填 Bot Token + 授权白名单即可用。⚠️ 远程控制等同远程操作本机,只授权本人、保管好 token。需经本应用启动 Codex,改开关后重启 Codex 生效。M1 为对话问答式(工具/命令批准仍需桌面确认,批准转发手机为后续阶段);Windows MSIX 不支持。

详细设计 / spike 实证 / 分阶段计划见 Linear MOC-249。

Refs MOC-249

🤖 Generated with Claude Code

不依赖 GPT 账号、用手机远程驱动本地 Codex:transfer Rust 端跑一个 Telegram bot
(纯 HTTPS long-poll,无 relay/公网回调,绕开 renderer CSP),授权用户发消息 →
经 CDP 把 prompt 灌进 Codex 输入框(ProseMirror)、提交、读流式输出回编到 Telegram。

- src-tauri/src/codex_remote/{driver,telegram,mod}.rs:CodexDriver(CDP 驱动)+
  Telegram 客户端 + daemon(白名单鉴权 / 命令 /new /stop /status /help / 流式回复)
- 复用 codex_theme_injector 的 CDP 原语 + codex_quota_injector 的 daemon 骨架
- should_attach_debug_port 加 codexRemoteControlEnabled;settings UI(开关+token+白名单,中英 i18n)
- 借鉴 zcode v3.1.0 Bot Channel 设计(不移植代码);默认关;Windows MSIX 不支持

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 460d2e1b6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/driver.rs Outdated
- driver::set_input 改全选替换(不再追加)+ 校验入框文本==目标(空白不敏感),
  防残留草稿与远程指令一起被提交执行非预期文本
- daemon offset 移进外层 loop 按 bot 会话重置:换 token 后不再复用旧 bot 的 offset
  导致新 bot 消息被跳过

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5958cbde90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/telegram.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
- telegram::call 错误用 reqwest Error::without_url 剥掉含 /bot<token>/ 的 URL,
  防 token 经日志/用户消息泄露(P1)
- /new 取 TURN_LOCK try_lock:轮次进行中拒绝,避免并发新建把活动对话从 run_turn
  下面换掉;/status /stop 仍 bypass(P2)

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c7c0ec422

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs Outdated
H1 的「无文本」早退会在 Codex 本地轮次仍在跑(submitting==true)时 return 放锁,
下一条 prompt 即可驱动同一页面、破坏 one-turn-at-a-time。改为:无文本/编辑失败只
提示一次、继续持锁轮询,直到 Codex 空闲 / CDP 不可达 / MAX_POLLS 才释放;完成判定
去掉「必须有文本」(纯工具轮无文本也算结束)。稳定性按观察内容算、与编辑成败解耦。

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e6b06f793

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/driver.rs Outdated
- 完成判定的 drift 分支改用当前 snap.submitting.is_none()(不再用 sticky flag),
  避免早期读到一次 None 后即使后续 Some(true) 仍在跑也误判完成提前放锁
- JS_STOP 按钮回退仅在 isSubmitting===true 时点(该钮空闲时是发送钮,点了会把草稿
  当新一轮提交);空闲返 none,daemon 报「当前没有进行中的轮次」

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86b6e7ab0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs
- 初始 snapshot 已 submitting==true(桌面端在跑)→ 拒绝注入,不覆盖草稿/停掉桌面轮次
- 占位消息发送失败不再 return(submit 已起跑):msg_id 置 None,无流式但持锁轮询到空闲
- drift 完成判定要求非空内容:fiber 全漂移时刚提交还在 thinking 的轮次不再 ~7s 误判完成
- 会话启动先 drain 积压(offset=-1):不再把关闭期/未授权时发的指令在启用后重放执行

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b14bda2b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs
- 初始 drain 失败退避重试(最多 6 次),始终失败则不进 live loop、回外层重建,
  绝不以 offset=0 进 loop 重放积压
- 完成判定改用 data-local-conversation-final-assistant 标记(final_ready)作 idle 证据,
  替代纯 stable-text 的 drift 路径:isSubmitting 漂移读不到时不再凭"内容稳定"误判完成
  提前放锁(codex-e2e-test skill 实证该标记更可靠)
- 循环超时退出后取末张快照,仍 submitting==true 则 driver::stop() 中止再释放锁
- 顺带把 driver 的回复提取升级为 final-assistant 优先 + 排除 composer(更干净)

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a33008db1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs
Comment thread src-tauri/src/codex_remote/driver.rs
… P2)

- JS_SNAPSHOT 的 final-assistant 标记必须用 compareDocumentPosition 确认在最新用户气泡
  之后才算本轮 finalReady,否则 Codex 残留的上一轮旧最终答案会让新 prompt 仍在 thinking
  时秒判完成 + 回旧答案 + 提前放锁(同 bug 一并修 codex-e2e-test skill driver)
- daemon long-poll 返回后、spawn handler 前重查 enabled()+token:25s 窗口内用户关开关/
  换 token 时丢弃这批旧会话 update,不再驱动 Codex

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3daca36806

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs
Comment thread src-tauri/src/codex_remote/mod.rs
- 只接受 Telegram private chat(加 Chat.type):bot 被拉进群/超级群/频道时群内消息
  静默忽略,不驱动 Codex(防群内滥用);kind 缺失按私聊放行
- run_turn 取到 TURN_LOCK 后重查 enabled():排队等锁期间(前轮可能数分钟)用户关掉
  远程控制则取消本次,不再驱动

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb1f7022ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
Comment thread src-tauri/src/codex_remote/mod.rs Outdated
- P1:鉴权只认稳定数字 user id,不再按 username(可改/被夺取会让新持有者获本机控制
  权);白名单残留 @username 项不再生效;UI/README/未授权回复同步改为「数字 id」
- P2:run_turn 传 sender_id,取 TURN_LOCK 后重查 enabled()+发起者仍在白名单,排队期间
  被移出/关开关则取消本次
- P2:完成判定 submitting==false 需长稳(8 轮)+ 非空文本佐证(streaming 期 isSubmitting
  会误读 false),final-assistant 标记仍为主判据

Refs MOC-249

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21a25a81f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/codex_remote/mod.rs
Comment thread src-tauri/src/codex_remote/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant