Mapleru/dsh-codex-bridge ↗★ 0

dsh-codex-bridge

Bidirectional local-file bridge between one DSH Desktop session and one dedicated Codex CLI session.

包名
dsh-codex-bridge
兼容性
待验证
版本
0.1.0
许可证
MIT
最近更新
2026年11月5日

同名包的其他仓库

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:Mapleru/dsh-codex-bridge

配置

所有运行参数来自 Cordis 配置(cordis.patch.yml 的 config:)。代码里没有用户路径或真实 会话 ID。缺少必填项时插件保持 ready:false 并报告原因,不会让宿主崩溃。

键默认值说明
root空(必填)邮箱根目录,必须位于 codexWorkingDirectory 内,否则 Codex 沙箱写不进去
dshSessionId空(必填)目标 DSH 会话 ID;没有 routes 时使用它,工具只对该会话可见
routes无可选路由表,见下节;设置后每个路由各自绑定一个 DSH 会话和一个 Codex 线程
deliverySourcewebhook投递到 DSH 的来源:webhook 显示为外部/通知消息;user 走 prompt() 并保留幂等 requestId
deliveryModefollowupfollowup 等当前回合结束再送达(不打断长任务);steer 立即送达并开新回合
codexExecutable空(必填)Codex CLI 的绝对路径;启动时验证文件、版本和能力
codexWorkingDirectory空(必填)Codex 的工作目录(协作目录),也是邮箱的沙箱根
codexTimeoutMs900000单次调用超时;超时只终止本插件创建的进程树
maxHops6达到 hops >= maxHops 停车,不再调用模型
maxAttempts3仅在“尚未看到任何 Codex 事件”时可安全重试
maxQueueDepth20Codex 待处理队列上限;满时发送返回 busy
maxMessageBytes32768单条消息上限
maxMailboxBytes8388608单个邮箱文件上限;满了返回 busy,不覆盖未消费数据
pollIntervalMs2000兜底轮询间隔(watcher 之外)
debounceMs300watcher 防抖
retryBaseMs5000投递失败指数退避基数
shutdownTimeoutMs4000宿主退出时等待收尾的上限(小于宿主 5 s 强制退出)
model空可选,传给 exec -m;空表示不指定
transportauto路由级:auto 先用 exec、遇“线程被占用”改走 queue;exec 只用子进程;queue 只走共享 app-server

root 必须绝对路径,且 path.relative(codexWorkingDirectory, root) 不能逃出该目录。这是刻意 设计:邮箱要由 Codex 在 workspace-write 沙箱内写入,不能靠扩大成全盘写权限解决。

路由(双方按 session ID 选会话)

不配 routes 时是单路由:一个 DSH 会话 ↔ 一个 Codex 线程(default)。要同时对接多组会话:

routes:
  - id: default
    dshSessionId: session-00000000-0000-4000-8000-000000000000
    codexWorkingDirectory: D:/codex/collab-a
  - id: research
    dshSessionId: session-11111111-1111-4111-8111-111111111111
    codexWorkingDirectory: D:/codex/collab-b
    model: gpt-5-codex
  • 每条路由有自己的 Codex 线程绑定(mailbox/routes.json),互不复用;路由丢失线程时停车, 不会自动新建。
  • DSH→Codex:工具按调用方会话自动选路由;同一会话拥有多条路由时必须显式传 route。
  • Codex→DSH:send.mjs --route 指定;多路由下不写 route 会被停车为 route-required。
  • 回复继承父消息的路由;显式写了不同路由会被拒绝(route-mismatch)。
  • 旧配置(只有 dshSessionId)自动迁移成 default 路由,session.json 的线程绑定也会迁移进 routes.json。
  • 运维:ctl.mjs routes 查看绑定,ctl.mjs reset-session [route] 清除某路由线程, ctl.mjs bind 复用已有线程。

绑定到桌面聊天:transport: queue

Codex 桌面端打开某个线程时会持有独占写锁,此时 codex exec resume 一定失败:

thread-store conflict: thread  already has an active writer

这不是线程丢失。transport: auto(默认)会在看到这条错误后自动改用 codex queue 把消息 排进同一个线程,再从该线程的 rollout JSONL(~/.codex/sessions/.../rollout-*-.jsonl) 读回最终答复。实测:入队到答复约 11 s,答复以普通 reply 写回邮箱。

代价与边界:

  • 被排队的回合在桌面线程自己的工作目录和权限配置里执行,不是 codexWorkingDirectory; 绑定桌面聊天等于把该聊天的执行环境交给桥。
  • queue 只保证“已入队”,桥以 rollout 里出现本消息 id 的回合并收到 task_complete 为完成; 期间桥无法中止该回合,超时按 delivery-uncertain 停车,不自动重跑。
  • 若线程真的不存在(no rollout found),仍按 session-lost 停车,不会新建线程替代; 需要运维 ctl.mjs reset-session 明确解除绑定。