|
| 1 | +# 任务:no-reply 模式下返回 sessionID 和 messageID |
| 2 | + |
| 3 | +## 问题描述 |
| 4 | + |
| 5 | +当前使用 `oho message add --no-reply` 发送消息时: |
| 6 | +1. 服务器不等待 AI 响应,返回空响应 |
| 7 | +2. CLI 只打印 "消息已发送",**不输出 sessionID 和 messageID** |
| 8 | +3. 用户无法追踪任务状态,交互体验差 |
| 9 | + |
| 10 | +## 需求 |
| 11 | + |
| 12 | +优化 `--no-reply` 模式的交互体验,确保执行后至少能获得: |
| 13 | +- ✅ **sessionID**(从命令行参数已知) |
| 14 | +- ✅ **messageID**(用户提供的或服务器生成的) |
| 15 | +- ✅ **执行状态确认** |
| 16 | + |
| 17 | +## 实现方案 |
| 18 | + |
| 19 | +### 方案 A:CLI 端优化(优先实施) |
| 20 | + |
| 21 | +修改 `/mnt/d/fe/opencode_cli/oho/cmd/message/message.go` 的 `addCmd`: |
| 22 | + |
| 23 | +```go |
| 24 | +// 当前代码(问题) |
| 25 | +if len(resp) == 0 { |
| 26 | + fmt.Println("消息已发送") |
| 27 | + return nil |
| 28 | +} |
| 29 | + |
| 30 | +// 优化后 |
| 31 | +if len(resp) == 0 { |
| 32 | + // no-reply 模式,服务器返回空响应 |
| 33 | + fmt.Println("消息已发送 (no-reply 模式)") |
| 34 | + fmt.Printf(" Session ID: %s\n", sessionID) |
| 35 | + if messageID != "" { |
| 36 | + fmt.Printf(" Message ID: %s\n", messageID) |
| 37 | + } else { |
| 38 | + fmt.Println(" Message ID: (服务器生成,可通过 session 消息列表查询)") |
| 39 | + } |
| 40 | + fmt.Println("\n提示:使用 oho message list -s <session> 查看消息状态") |
| 41 | + return nil |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### 方案 B:服务器端优化(可选,增强版) |
| 46 | + |
| 47 | +修改 OpenCode Server 的 `/session/:id/message` 接口: |
| 48 | +- 当 `noReply=true` 时,立即返回已创建的消息对象 |
| 49 | +- 返回字段:`{ id, sessionId, role: "user", createdAt, parts: [...] }` |
| 50 | +- 不等待 AI 响应,但确认消息已入队 |
| 51 | + |
| 52 | +## 验收标准 |
| 53 | + |
| 54 | +1. ✅ 执行 `oho message add -s xxx "消息" --no-reply` 后,输出包含: |
| 55 | + - Session ID |
| 56 | + - Message ID(如果提供了 `--message` 参数) |
| 57 | + - 状态确认信息 |
| 58 | + |
| 59 | +2. ✅ 输出格式清晰,便于脚本解析(支持 `--json` 模式) |
| 60 | + |
| 61 | +3. ✅ 不影响正常模式(无 `--no-reply`)的行为 |
| 62 | + |
| 63 | +## 相关文件 |
| 64 | + |
| 65 | +- `/mnt/d/fe/opencode_cli/oho/cmd/message/message.go` - 主要修改位置 |
| 66 | +- `/mnt/d/fe/opencode_cli/oho/internal/types/types.go` - 类型定义(可能需要新增响应类型) |
| 67 | + |
| 68 | +## 测试用例 |
| 69 | + |
| 70 | +```bash |
| 71 | +# 测试 1: 无 messageID |
| 72 | +oho message add -s test123 "测试消息" --no-reply |
| 73 | +# 期望输出:Session ID: test123 |
| 74 | + |
| 75 | +# 测试 2: 有 messageID |
| 76 | +oho message add -s test123 "测试消息" --no-reply --message my-task-001 |
| 77 | +# 期望输出:Session ID: test123, Message ID: my-task-001 |
| 78 | + |
| 79 | +# 测试 3: JSON 模式 |
| 80 | +oho message add -s test123 "测试消息" --no-reply --json |
| 81 | +# 期望输出:{"sessionId":"test123","messageId":"...","status":"queued"} |
| 82 | +``` |
| 83 | + |
| 84 | +## 优先级 |
| 85 | + |
| 86 | +- P0: CLI 端优化(方案 A)- 立即实施 |
| 87 | +- P1: 服务器端优化(方案 B)- 后续增强 |
0 commit comments