feat(cli): live command — real-time thread monitoring #37

Closed
opened 2026-05-07 10:47:20 +00:00 by xingyue · 2 comments
Owner

Summary

新增 uncaged-workflow live <thread-id> 命令,实时查看正在运行的 thread 的状态和输出。

Motivation

目前 thread 运行后只能通过 thread <id> 查看最终结果,或者手动 tail -f JSONL 文件。缺少 live 查看运行状况的能力,调试和观察体验差。

Design

CLI 接口

# 实时跟踪一个 thread
uncaged-workflow live <thread-id>

# 跟踪最近启动的 thread(不指定 id)
uncaged-workflow live --latest

# 只看特定 role 的输出
uncaged-workflow live <thread-id> --role planner

# 同时显示 info log(debug 模式)
uncaged-workflow live <thread-id> --debug

输出格式

╭─ thread 01KQXKW…YG ─ solve-issue ─ C9NMV6V2TQT81 ─────────────╮
│ status: running                                                  │
╰──────────────────────────────────────────────────────────────────╯

[12:03:01] ▶ preparer
  Analyzing repository structure...
  Found 12 source files, 3 test files...
  meta: { files: ["src/engine.ts", ...], dependencies: [...] }

[12:03:15] ▶ planner
  Planning implementation in 2 phases...
  meta: { phases: [{ name: "core", files: [...] }, ...] }

[12:03:42] ▶ coder (phase 1/2)
  Implementing core engine changes...
  ███████████░░░░ running...

实现方案

  1. Data source: tail -f 式监听 .data.jsonl + .info.jsonl
    • fs.watch / fs.watchFile 监听文件变化
    • 新行追加时解析并格式化输出
  2. Thread 状态: 从 worker 进程状态 + JSONL 内容推断
    • running / paused / completed / failed
  3. 退出条件:
    • Thread 完成(检测到 WorkflowResult 行)
    • 用户 Ctrl+C
    • Thread 被 kill

可选增强

  • --json 输出原始 JSONL(方便 pipe)
  • --no-color 禁用颜色
  • --since <timestamp> 从某个时间点开始回放

Implementation Notes

  • 新增 cmd-live.ts
  • 格式化输出复用 cli-output.ts 的工具函数
  • fs.watch 在 bun 中的兼容性需要验证,备选 polling
  • content 可能很长,默认截断显示,--full 显示完整

Acceptance Criteria

  • uncaged-workflow live <thread-id> 实时显示 role 输出
  • --latest 自动跟踪最近启动的 thread
  • --debug 同时显示 info.jsonl 的 log
  • Thread 完成后自动退出,显示 summary
  • Ctrl+C 优雅退出
  • 有测试覆盖
## Summary 新增 `uncaged-workflow live <thread-id>` 命令,实时查看正在运行的 thread 的状态和输出。 ## Motivation 目前 thread 运行后只能通过 `thread <id>` 查看最终结果,或者手动 `tail -f` JSONL 文件。缺少 live 查看运行状况的能力,调试和观察体验差。 ## Design ### CLI 接口 ```bash # 实时跟踪一个 thread uncaged-workflow live <thread-id> # 跟踪最近启动的 thread(不指定 id) uncaged-workflow live --latest # 只看特定 role 的输出 uncaged-workflow live <thread-id> --role planner # 同时显示 info log(debug 模式) uncaged-workflow live <thread-id> --debug ``` ### 输出格式 ``` ╭─ thread 01KQXKW…YG ─ solve-issue ─ C9NMV6V2TQT81 ─────────────╮ │ status: running │ ╰──────────────────────────────────────────────────────────────────╯ [12:03:01] ▶ preparer Analyzing repository structure... Found 12 source files, 3 test files... meta: { files: ["src/engine.ts", ...], dependencies: [...] } [12:03:15] ▶ planner Planning implementation in 2 phases... meta: { phases: [{ name: "core", files: [...] }, ...] } [12:03:42] ▶ coder (phase 1/2) Implementing core engine changes... ███████████░░░░ running... ``` ### 实现方案 1. **Data source**: `tail -f` 式监听 `.data.jsonl` + `.info.jsonl` - 用 `fs.watch` / `fs.watchFile` 监听文件变化 - 新行追加时解析并格式化输出 2. **Thread 状态**: 从 worker 进程状态 + JSONL 内容推断 - running / paused / completed / failed 3. **退出条件**: - Thread 完成(检测到 WorkflowResult 行) - 用户 Ctrl+C - Thread 被 kill ### 可选增强 - `--json` 输出原始 JSONL(方便 pipe) - `--no-color` 禁用颜色 - `--since <timestamp>` 从某个时间点开始回放 ## Implementation Notes - 新增 `cmd-live.ts` - 格式化输出复用 `cli-output.ts` 的工具函数 - `fs.watch` 在 bun 中的兼容性需要验证,备选 polling - content 可能很长,默认截断显示,`--full` 显示完整 ## Acceptance Criteria - [ ] `uncaged-workflow live <thread-id>` 实时显示 role 输出 - [ ] `--latest` 自动跟踪最近启动的 thread - [ ] `--debug` 同时显示 info.jsonl 的 log - [ ] Thread 完成后自动退出,显示 summary - [ ] Ctrl+C 优雅退出 - [ ] 有测试覆盖
Author
Owner

Phase 拆分

Phase 1: 基础实时 thread 监控

Phase 2: flags 与增强功能 (--latest / --debug / --role)

## Phase 拆分 ### Phase 1: 基础实时 thread 监控 - Testing issue: #49 ### Phase 2: flags 与增强功能 (--latest / --debug / --role) - Testing issue: #50
Author
Owner

All phases complete, PR #57 merged

All phases complete, PR #57 merged ✅
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#37