feat: support Trae CLI (coco) as a new agent#394
Conversation
- Implemented `Agent` and `AgentSession` interfaces for `coco` agent.
- Registered `coco` via `core.RegisterAgent("coco", New)`.
- Added build tag file `cmd/cc-connect/plugin_agent_coco.go`.
- Added `coco` to `ALL_AGENTS` in Makefile.
- Added example configuration for `coco` to `config.example.toml`.
- Implemented `Agent` and `AgentSession` interface for `coco` agent. - Wrapped Trae CLI process with stdin/stdout pipes to allow bidirectional communication. - Added build tags in `cmd/cc-connect/plugin_agent_coco.go`. - Registered `coco` agent in `Makefile` and added a configuration example.
chenhg5
left a comment
There was a problem hiding this comment.
感谢提交 coco agent 的适配!整体结构清晰,不过 review 下来有一些需要关注的问题:
严重问题
1. 原始 PTY 输出直接推给用户
readLoop 里把 PTY 的原始字节(含 ANSI 转义码)直接作为 EventText 发出去了:
case qs.events <- core.Event{Type: core.EventText, Content: string(chunk)}:cleanAnsi 只在进程退出时的 EventResult 上用到。用户在 Telegram/Feishu 等平台会看到大量乱码转义符。建议在发 EventText 之前也做一次清理。
2. 没有 turn detection(轮次结束检测)
EventResult 只在 PTY 关闭(进程退出)时才发送。整个会话期间引擎永远收不到 "done" 信号,平台侧的"正在输入"指示器会一直转。
对比项目中已有的 agent:
iflow— 通过 tailing transcript JSONL + 900ms idle timer 检测轮次结束qoder— 通过结构化 JSON stream 的resultevent 检测
coco 目前完全没有轮次结束判断,多轮对话基本不可用。需要增加某种机制(idle timeout / prompt 正则匹配 / 特定输出标记等)来判断 coco 什么时候回复完毕。
3. accumulated buffer 无限增长 → 内存泄漏
var accumulated bytes.Buffer整个会话期间所有 PTY 输出都追加到这里,永远不会清理。长对话会导致内存持续增长。建议在每轮结束后重置,或者改用 ring buffer / 只保留最后 N 字节。
4. cleanAnsi 太简陋
目前只处理 ESC[...letter 这种基本 CSI 模式。PTY 输出常见的 \r(回车覆盖)、\b(退格)、OSC 序列(ESC]...BEL)等都没处理。可以参考 agent/iflow/session.go 里的 stripANSI 实现,它用正则覆盖了 OSC + CSI + \r。
设计问题
5. Permission 流程不通
RespondPermission 直接写 "Y\r" / "N\r",但代码里从未发出过 EventPermissionRequest 事件。引擎不知道 coco 什么时候在请求权限,所以这个权限流程实际上走不通。
如果 coco CLI 有权限确认提示,需要在 readLoop 里检测并发出 EventPermissionRequest;如果 coco 不需要权限确认,RespondPermission 返回 nil 即可,不需要写 PTY。
6. coco CLI 有没有非交互模式?
目前用空参数启动 coco 然后全靠 PTY 解析。想确认下:coco 有没有类似 --non-interactive、--output-format json、或者 pipe 模式的选项?如果有结构化输出模式,会比 PTY 解析稳定很多。
代码质量
7. 变量命名 qs
session 类型是 cocoSession,但 receiver 变量全部是 qs,看起来是从 qoder/session.go 复制过来没改。建议改为 cs 或 s 保持一致。
8. 缺少测试
项目要求所有新功能需要包含单元测试(见 CLAUDE.md)。至少需要:
cleanAnsi的单元测试Agent构造和基本接口的测试- 可以参考
agent/qoder/或agent/cursor/的测试写法
9. web/tsconfig.tsbuildinfo 不应提交
这是 TypeScript 自动生成的构建缓存文件,和 coco agent 无关。看起来是本地环境把文件名大小写全改了,建议从这个 PR 移除,加到 .gitignore。
10. session resume 没实现
resumeID 存了,但 startProcess 永远启动新进程。如果暂不支持恢复,建议加个注释说明或者直接不存 resumeID,避免误导。
总结:核心问题是 turn detection 和 ANSI 清理,这两个不解决的话多轮对话体验会比较差。建议先确认 coco CLI 有没有结构化输出模式,如果有的话优先走那个路径会省很多事。期待后续更新 👍
chenhg5
left a comment
There was a problem hiding this comment.
LGTM. Well-structured new agent implementation.
Review summary:
- ✅ Follows agent architecture pattern
- ✅ Implements core.Agent and core.AgentSession interfaces
- ✅ Plugin file with build tag
- ✅ Makefile updated
- ✅ Config example added
- ✅ CI passes
Welcome addition of Trae CLI (coco) agent support!
This PR adds support for the Trae IDE's CLI tool (
coco).core.Agentandcore.AgentSessioninterfaces forcocounderagent/coco.cocoprocess.plugin_agent_coco.gowith build tag!no_coco.Makefileto includecocoin the default agent list.cocoexample toconfig.example.toml.