Skip to content

fix(coco): 修复 CoCo 消息无法自动提交 - #25

Merged
deepcoldy merged 1 commit into
deepcoldy:masterfrom
ZBCccc:fix/coco-submit-autocommit
May 20, 2026
Merged

deepcoldy merged 1 commit into
deepcoldy:masterfrom
ZBCccc:fix/coco-submit-autocommit

Conversation

@ZBCccc

@ZBCccc ZBCccc commented May 20, 2026

Copy link
Copy Markdown

背景

排查 CoCo / Trae CLI 在 botmux tmux 模式下的多行输入提交链路时,发现 CoCo 提交确认依赖两处行为:

  1. CoCo 的全局 history.jsonl 路径是平台相关的:macOS 写入 ~/Library/Caches/coco/history.jsonl,Linux 写入 ~/.cache/coco/history.jsonl。此前 adapter 只按 Linux 路径读取,macOS 下会误读不到真实提交历史,影响提交确认、retry/failure 判断。
  2. CoCo 在 tmux 模式下通过 pasteText() 注入多行内容。为了让 CoCo / Ink 更可靠地识别 paste 边界,tmux paste-buffer 需要带上 -p,在应用启用 bracketed paste 时插入 paste 边界控制码。

改动

  • src/adapters/cli/coco.ts
    • CoCo history path 改为平台相关:macOS 使用 ~/Library/Caches/coco/history.jsonl,其他平台保持 ~/.cache/coco/history.jsonl。
    • 更新注释,避免继续写死 Linux 路径。
  • src/adapters/backend/tmux-backend.ts
    • pasteText() 的 tmux paste-buffer 增加 -p,在应用启用 bracketed paste 时插入 paste 边界控制码。
  • test/write-input.test.ts
    • 测试 helper 使用与 adapter 一致的平台相关 CoCo history path。
    • 保留 CoCo retry/failure 回归用例,避免 macOS 下误走 fresh-install shortcut 而掩盖提交失败。

验证

  • pnpm exec tsc --noEmit ✅
  • pnpm vitest run test/write-input.test.ts ✅ 68 tests
  • pnpm vitest run test/tmux-backend-input.test.ts ✅ 12 tests
  • git diff --check ✅

备注:本机 Node 为 v20.20.2,pnpm 会提示项目期望 node >=22,但上述验证命令均已通过。

1. tmux-backend pasteText 添加 -p 标志强制 bracketed-paste 标记
2. coco.ts HISTORY_PATH 适配 macOS ~/Library/Caches 路径
@ZBCccc
ZBCccc requested a review from deepcoldy as a code owner May 20, 2026 11:15
Copilot AI review requested due to automatic review settings May 20, 2026 11:15

Copilot AI 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.

Pull request overview

This PR aims to fix CoCo/Trae CLI “multiline input can’t auto-submit” in botmux tmux mode by (1) using the correct CoCo history.jsonl path per platform (macOS vs Linux) for submit verification, and (2) making tmux paste operations reliably delimited via bracketed-paste markers.

Changes:

  • Update CoCo submit-verification history path to be platform-specific (macOS ~/Library/Caches/..., otherwise ~/.cache/...).
  • Add -p to tmux paste-buffer in pasteText() to request bracketed-paste markers when supported/enabled.
  • Align the write-input test helper to use the same platform-specific CoCo history path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/write-input.test.ts Test helper now uses platform-specific CoCo history path and updates related comments.
src/adapters/cli/coco.ts CoCo adapter now reads platform-specific history.jsonl; updates verification comment accordingly.
src/adapters/backend/tmux-backend.ts pasteText() now passes -p to tmux paste-buffer and updates bracketed-paste documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 271 to 286
@@ -280,7 +282,7 @@ export class TmuxBackend implements SessionBackend {
timeout: 5000,
env: tmuxEnv(),
});
execFileSync('tmux', ['paste-buffer', '-t', this.cmdTarget, '-d'], {
execFileSync('tmux', ['paste-buffer', '-t', this.cmdTarget, '-d', '-p'], {
stdio: 'ignore',
@deepcoldy

Copy link
Copy Markdown
Owner

感谢 @ZBCccc 的修复!🙏

Review 结论(在隔离 worktree 上验证):

  • coco.ts 平台相关 history.jsonl 路径 ✅ 正确,与 coco-transcript.ts 既有约定一致;
  • tmux-backend.ts 的 paste-buffer -p ✅ 正确——-p 仅在应用启用 bracketed paste 时插入边界码(man tmux 确认是条件性的),对其它仅 CoCo 之外不调用 pasteText() 的 CLI 无回归;
  • 测试同步更新到平台相关路径 ✅,避免 macOS 下误走 fresh-install shortcut。
  • 验证:tsc --noEmit 通过,write-input + tmux-backend-input 共 80 tests 全绿。

本 PR 是完整版(含测试),与 #25 重复的 #23 将作为 superseded 关闭。合并后会再补一个小重构把 CoCo 缓存根路径抽成共享 helper。

@deepcoldy
deepcoldy merged commit 2ed0c94 into deepcoldy:master May 20, 2026
3 of 4 checks passed
deepcoldy added a commit that referenced this pull request May 20, 2026
review nit:原注释写 'paste-buffer -d 自动 wraps',正是导致 PR #25 改错
backend 的误解来源。改成准确描述 -p 的作用。
ZBCccc pushed a commit to ZBCccc/botmux that referenced this pull request May 21, 2026
PR deepcoldy#25 的 -p 加到了 TmuxBackend.pasteText,但运行时所有会话走的都是
TmuxPipeBackend(见 selectSessionBackend),其 pasteText 仍是无 -p 的
paste-buffer -d。没有 -p tmux 不会包 bracketed-paste 标记,CoCo/Ink 把
内容当成连续输入 burst,结尾 Enter 被吞成软换行,消息卡在输入框未提交;
下一条消息的 paste 才把上一条顶出去提交 —— 表现为'每次回复上一条'。

- TmuxPipeBackend.pasteText 的 paste-buffer 补 -p(对齐 TmuxBackend)
- tmux-pipe-backend.test 增加 -p 断言作为回归护栏(旧测试 mock 掉了
  pasteText,从未跑到真实 tmux flag,所以 PR deepcoldy#25 的错位没被拦住)
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.

3 participants