feat: 新增 --watch <session> 入口(四运行时),替代 scripts/watch.sh - #80
Open
lloydzhou wants to merge 1 commit into
Open
Conversation
- Bash/Go/Rust/C 主程序新增 --watch 参数:实时跟踪 session 的 events.jsonl
- 参数支持 events.jsonl 路径 | session 目录 | session_id(projects 下递归查找)
- 初始渲染最后 10 行已有事件,之后 follow 新增事件直到 Ctrl+C
- 渲染复用 replay 的事件→display 映射(bash 复用 event_replay.awk 管线;
go/rust/c 抽出行级渲染函数与 resume replay 共用)
- --output-format stream-json 下透传原始事件行
- 不需要 API key、不创建 session(watch 短路在 validate_config 之前)
- 找不到 session → stderr 报错 + 退出码 1(四端一致)
- bash 端用 tail -f | 逐行有限 awk 管道 | display_stream:
tail -f 自带最后 10 行上下文;read 按 \n 交付完整行(避开半行);
每行一次有限 awk 调用(与 resume replay 同一管线),进程退出即 flush,
规避 awk stdout 接管道时的块缓冲(gawk/mawk 不自动 flush)
- 删除 scripts/watch.sh(单 session 场景由 --watch 替代,多 session tmux 场景放弃)
- tests/test.sh 新增 Test 52:不存在 session 退出码 1、初始渲染、follow 新增事件
- README/README.en/CHANGELOG 同步
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
主程序新增
--watch <session>入口(Bash/Go/Rust/C 四运行时一致实现):实时跟踪某个 session 的events.jsonl,把新增事件送入与--resumereplay 相同的 display 渲染管线。替代scripts/watch.sh的单 session 场景。行为定义(四端一致)
agent --watch <session>,参数支持三种形式(对齐原 watch.sh resolve_session):events.jsonl文件路径/events.jsonl)$BASH_AGENT_HOME/.bash-agent/projects下递归查找同名目录)--output-format stream-json下直接透传原始事件行(跳过 display 渲染)validate_config/ API key 校验之前各运行时实现
src/agent.sh:agent_watch_session单函数仅 10 行,tail -f+ 逐行有限 awk 管道(与 resume replay 同一event_replay.awk管线)+display_streamgo/cmd/goagent/main.go:replayEvents循环体抽为renderEventLine复用;新增resolveWatchFile/completeLines/runWatch(500ms 轮询)rust/src/agent.rs:display_replay_event抽为自由函数replay_event_build/replay_parse_line供 replay 与 watch 共用;main.rs加参数解析与短路(500ms 轮询)c/agent.c:agent_replay_events循环体抽为agent_render_event_line复用;新增watch_resolve/agent_watch_session(500ms 轮询);cagent.c加参数解析与短路关键设计说明
tail -f | awk | display_stream一条管道:awk 的 stdout 接管道时是 stdio 块缓冲(攒满 4KB 才 flush),tail -f没有 EOF → awk 不退出 → 事件攒批才显示(macOS 自带 BWK awk 会在阻塞读 stdin 前 flush,掩盖了该问题;gawk/mawk 无此行为)。改为tail -f | while read逐行喂有限 awk 管道:每次调用进程退出即 flush,所有 awk 实现行为一致;read按\n交付完整行,天然避开写入中的半行;tail -f自带"最后 10 行"上下文。测试
tests/test.sh新增 Test 52(三用例):不存在 session 退出码 1 + stderr;human 模式渲染已有事件;追加新事件后 follow 输出--watch同一真实 session 输出一致;bash 端验证 session_id 解析、最后 10 行截断、follow 实时性、stream-json 透传移除
scripts/watch.sh删除:单 session 场景由--watch替代;多 session tmux 分屏场景一并放弃