diff --git a/skills/auto-tmux/AGENTS.md b/skills/auto-tmux/AGENTS.md index de71cd7..ae463e0 100644 --- a/skills/auto-tmux/AGENTS.md +++ b/skills/auto-tmux/AGENTS.md @@ -15,6 +15,7 @@ skills/auto-tmux/ │ ├── auto-tmux.sh │ ├── swarm-state.sh │ ├── swarm-brief.sh +│ ├── swarm-watch.sh │ ├── render-swarm-prompt.sh │ ├── swarm-dispatch.sh │ ├── auto-tmux-smoke-test.sh @@ -40,6 +41,7 @@ skills/auto-tmux/ - `scripts/auto-tmux.sh` 是技能执行层,封装 topology/capture/send/scan/rescue/record/snapshot/hub/wait。 - `scripts/swarm-state.sh` 是蜂群协作状态层,管理任务、锁、状态日志和结果报告。 - `scripts/swarm-brief.sh` 是只读交接层,汇总 doctor/topology/scan/report 形成上下文快照。 +- `scripts/swarm-watch.sh` 是有限轮次巡检层,按间隔采集 pane 输出与 swarm report。 - `scripts/render-swarm-prompt.sh` 是提示词渲染层,生成 commander/worker/reviewer 协议文本。 - `scripts/swarm-dispatch.sh` 是提示词下发层,默认写文件,显式 `--send` 后才发送到 pane。 - `scripts/validate-auto-tmux.sh` 是技能专属质量门禁,覆盖脚本、文档索引和 smoke test。 @@ -51,4 +53,4 @@ skills/auto-tmux/ - 上游来源:`tools/external/.tmux` 与 `tools/external/tmux`。 - 下游使用:`SKILL.md` 和 `references/` 中的命令示例。 - 验证入口:`skills/auto-skill/scripts/validate-skill.sh skills/auto-tmux --strict`。 -- 脚本验证:`skills/auto-tmux/scripts/validate-auto-tmux.sh`、`bash -n skills/auto-tmux/scripts/auto-tmux.sh`、`bash -n skills/auto-tmux/scripts/swarm-state.sh`、`bash -n skills/auto-tmux/scripts/swarm-brief.sh`、`bash -n skills/auto-tmux/scripts/render-swarm-prompt.sh`、`bash -n skills/auto-tmux/scripts/swarm-dispatch.sh`、`skills/auto-tmux/scripts/auto-tmux-smoke-test.sh`。 +- 脚本验证:`skills/auto-tmux/scripts/validate-auto-tmux.sh`、`bash -n skills/auto-tmux/scripts/auto-tmux.sh`、`bash -n skills/auto-tmux/scripts/swarm-state.sh`、`bash -n skills/auto-tmux/scripts/swarm-brief.sh`、`bash -n skills/auto-tmux/scripts/swarm-watch.sh`、`bash -n skills/auto-tmux/scripts/render-swarm-prompt.sh`、`bash -n skills/auto-tmux/scripts/swarm-dispatch.sh`、`skills/auto-tmux/scripts/auto-tmux-smoke-test.sh`。 diff --git a/skills/auto-tmux/README.md b/skills/auto-tmux/README.md index 98893ed..ebeb0b4 100644 --- a/skills/auto-tmux/README.md +++ b/skills/auto-tmux/README.md @@ -22,6 +22,7 @@ bash -n skills/auto-tmux/scripts/auto-tmux.sh bash -n skills/auto-tmux/scripts/swarm-state.sh bash -n skills/auto-tmux/scripts/swarm-brief.sh +bash -n skills/auto-tmux/scripts/swarm-watch.sh bash -n skills/auto-tmux/scripts/render-swarm-prompt.sh bash -n skills/auto-tmux/scripts/swarm-dispatch.sh bash -n skills/auto-tmux/scripts/validate-auto-tmux.sh diff --git a/skills/auto-tmux/SKILL.md b/skills/auto-tmux/SKILL.md index 771157a..cc16341 100644 --- a/skills/auto-tmux/SKILL.md +++ b/skills/auto-tmux/SKILL.md @@ -36,6 +36,7 @@ description: "tmux 自动化操控:用 scripts/auto-tmux.sh 安全读取、发 bash -n skills/auto-tmux/scripts/auto-tmux.sh bash -n skills/auto-tmux/scripts/swarm-state.sh bash -n skills/auto-tmux/scripts/swarm-brief.sh +bash -n skills/auto-tmux/scripts/swarm-watch.sh bash -n skills/auto-tmux/scripts/render-swarm-prompt.sh bash -n skills/auto-tmux/scripts/swarm-dispatch.sh bash -n skills/auto-tmux/scripts/validate-auto-tmux.sh @@ -108,6 +109,7 @@ skills/auto-tmux/scripts/auto-tmux.sh broadcast --session ai-hub --text "pwd" -- ```bash skills/auto-tmux/scripts/auto-tmux.sh snapshot --session ai-hub --dir /tmp/auto-tmux-snapshot -n 120 skills/auto-tmux/scripts/swarm-brief.sh --session ai-hub --swarm-dir /tmp/ai_swarm --out /tmp/auto-tmux-brief +skills/auto-tmux/scripts/swarm-watch.sh --session ai-hub --swarm-dir /tmp/ai_swarm --iterations 3 --interval 10 ``` **远程救援:发现等待输入即发送 y** @@ -236,6 +238,7 @@ skills/auto-tmux/scripts/swarm-dispatch.sh --role worker --target ::/dev/null || true - rm -rf "$SWARM_DIR" "$SNAPSHOT_DIR" "$RECORD_DIR" "$BRIEF_DIR" "$DISPATCH_PROMPT" + rm -rf "$SWARM_DIR" "$SNAPSHOT_DIR" "$RECORD_DIR" "$BRIEF_DIR" "$WATCH_DIR" "$DISPATCH_PROMPT" } trap cleanup EXIT @@ -30,6 +32,7 @@ bash -n "$AUTO_TMUX" bash -n "$SWARM_STATE" bash -n "$RENDER_PROMPT" bash -n "$SWARM_BRIEF" +bash -n "$SWARM_WATCH" bash -n "$SWARM_DISPATCH" "$AUTO_TMUX" hub --session "$SESSION" --workers 1 --cmd bash @@ -67,6 +70,8 @@ grep -q 'BLOCKED' /tmp/auto-tmux-smoke-report.txt grep -q 'FAIL' /tmp/auto-tmux-smoke-report.txt "$SWARM_BRIEF" --session "$SESSION" --swarm-dir "$SWARM_DIR" --out "$BRIEF_DIR" -n 10 >/tmp/auto-tmux-smoke-brief.txt grep -q 'auto-tmux Swarm Brief' "$BRIEF_DIR/brief.md" +"$SWARM_WATCH" --session "$SESSION" --swarm-dir "$SWARM_DIR" --out "$WATCH_DIR" --iterations 1 --interval 0 -n 10 >/tmp/auto-tmux-smoke-watch.txt +grep -q 'auto-tmux Swarm Watch' "$WATCH_DIR/index.md" "$RENDER_PROMPT" commander --session "$SESSION" --swarm-dir "$SWARM_DIR" --task "smoke" >/tmp/auto-tmux-smoke-commander-prompt.md "$RENDER_PROMPT" worker --session "$SESSION" --target "$worker_target" --swarm-dir "$SWARM_DIR" --task "smoke" >/tmp/auto-tmux-smoke-worker-prompt.md "$SWARM_DISPATCH" --role worker --target "$worker_target" --session "$SESSION" --swarm-dir "$SWARM_DIR" --task "smoke" --out "$DISPATCH_PROMPT" >/tmp/auto-tmux-smoke-dispatch-render.txt diff --git a/skills/auto-tmux/scripts/auto-tmux.sh b/skills/auto-tmux/scripts/auto-tmux.sh index e6812ea..a00c18b 100755 --- a/skills/auto-tmux/scripts/auto-tmux.sh +++ b/skills/auto-tmux/scripts/auto-tmux.sh @@ -147,7 +147,7 @@ cmd_doctor() { status_line "WARN" "tmux server has no reachable session yet" fi - for script in auto-tmux.sh swarm-state.sh swarm-brief.sh render-swarm-prompt.sh swarm-dispatch.sh auto-tmux-smoke-test.sh validate-auto-tmux.sh; do + for script in auto-tmux.sh swarm-state.sh swarm-brief.sh swarm-watch.sh render-swarm-prompt.sh swarm-dispatch.sh auto-tmux-smoke-test.sh validate-auto-tmux.sh; do if [[ -x "$script_dir/$script" ]]; then status_line "OK" "script executable: $script" else diff --git a/skills/auto-tmux/scripts/swarm-watch.sh b/skills/auto-tmux/scripts/swarm-watch.sh new file mode 100755 index 0000000..8c7b9b3 --- /dev/null +++ b/skills/auto-tmux/scripts/swarm-watch.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +# Run finite read-only watch cycles for a tmux AI swarm session. +set -euo pipefail + +usage() { + cat <<'EOF' +swarm-watch: collect repeated read-only scan/report snapshots for a tmux AI swarm + +Usage: + swarm-watch.sh [--session NAME] [--swarm-dir DIR] [--out DIR] [--interval SEC] [--iterations N] [-n LINES] [--pattern REGEX] + +Examples: + swarm-watch.sh --session ai-hub --swarm-dir /tmp/ai_swarm --iterations 3 --interval 10 + swarm-watch.sh --session ai-hub --pattern "ERROR|Traceback|failed" --iterations 1 +EOF +} + +die() { + printf 'error: %s\n' "$*" >&2 + exit 1 +} + +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +auto_tmux="$script_dir/auto-tmux.sh" +swarm_state="$script_dir/swarm-state.sh" + +session="" +swarm_dir="${AUTO_TMUX_SWARM_DIR:-/tmp/ai_swarm}" +out_dir="/tmp/auto-tmux-watch-$(date +%Y%m%d-%H%M%S)" +interval=10 +iterations=3 +lines=80 +pattern="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --session) session="${2:-}"; shift 2 ;; + --swarm-dir) swarm_dir="${2:-}"; shift 2 ;; + --out) out_dir="${2:-}"; shift 2 ;; + --interval) interval="${2:-}"; shift 2 ;; + --iterations) iterations="${2:-}"; shift 2 ;; + -n|--lines) lines="${2:-}"; shift 2 ;; + --pattern) pattern="${2:-}"; shift 2 ;; + -h|--help) usage; exit 0 ;; + *) die "unknown option: $1" ;; + esac +done + +[[ "$iterations" =~ ^[0-9]+$ ]] || die "--iterations must be a positive integer" +[[ "$interval" =~ ^[0-9]+$ ]] || die "--interval must be a non-negative integer" +[[ "$lines" =~ ^[0-9]+$ ]] || die "--lines must be a positive integer" +(( iterations > 0 )) || die "--iterations must be > 0" + +mkdir -p "$out_dir" +index="$out_dir/index.md" + +{ + printf '# auto-tmux Swarm Watch\n\n' + printf '%s\n' "- created_at: \`$(date -Is)\`" + printf '%s\n' "- session: \`${session:-}\`" + printf '%s\n' "- swarm_dir: \`$swarm_dir\`" + printf '%s\n' "- iterations: \`$iterations\`" + printf '%s\n' "- interval: \`$interval\`" + printf '%s\n' "- lines_per_pane: \`$lines\`" + printf '%s\n\n' "- pattern: \`${pattern:-}\`" +} > "$index" + +scan_args=(scan -n "$lines") +if [[ -n "$session" ]]; then + scan_args+=(--session "$session") +fi +if [[ -n "$pattern" ]]; then + scan_args+=(--pattern "$pattern") +fi + +for ((i = 1; i <= iterations; i++)); do + stamp="$(date +%Y%m%d-%H%M%S)" + scan_file="$out_dir/${i}-${stamp}-scan.log" + report_file="$out_dir/${i}-${stamp}-report.md" + + printf 'watch iteration %s/%s\n' "$i" "$iterations" + "$auto_tmux" "${scan_args[@]}" > "$scan_file" 2>&1 || true + + if [[ -d "$swarm_dir" ]]; then + "$swarm_state" report --dir "$swarm_dir" > "$report_file" 2>&1 || true + else + printf 'swarm state dir not found: %s\n' "$swarm_dir" > "$report_file" + fi + + { + printf '## Iteration %s\n\n' "$i" + printf '%s\n' "- scan: [$(basename "$scan_file")](./$(basename "$scan_file"))" + printf '%s\n\n' "- report: [$(basename "$report_file")](./$(basename "$report_file"))" + } >> "$index" + + if (( i < iterations )); then + sleep "$interval" + fi +done + +printf 'watch written: %s\n' "$out_dir" diff --git a/skills/auto-tmux/scripts/validate-auto-tmux.sh b/skills/auto-tmux/scripts/validate-auto-tmux.sh index 77d943a..6e3923a 100755 --- a/skills/auto-tmux/scripts/validate-auto-tmux.sh +++ b/skills/auto-tmux/scripts/validate-auto-tmux.sh @@ -80,6 +80,7 @@ scripts=( "$script_dir/auto-tmux.sh" "$script_dir/swarm-state.sh" "$script_dir/swarm-brief.sh" + "$script_dir/swarm-watch.sh" "$script_dir/render-swarm-prompt.sh" "$script_dir/swarm-dispatch.sh" "$script_dir/auto-tmux-smoke-test.sh" @@ -93,18 +94,22 @@ done run_gate "auto-tmux help" "$script_dir/auto-tmux.sh" help run_gate "swarm-state help" "$script_dir/swarm-state.sh" help run_gate "swarm-brief help" "$script_dir/swarm-brief.sh" --help +run_gate "swarm-watch help" "$script_dir/swarm-watch.sh" --help run_gate "render-swarm-prompt help" "$script_dir/render-swarm-prompt.sh" --help run_gate "swarm-dispatch help" "$script_dir/swarm-dispatch.sh" --help require_contains "$skill_dir/SKILL.md" "scripts/validate-auto-tmux.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-brief.sh" +require_contains "$skill_dir/SKILL.md" "scripts/swarm-watch.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-dispatch.sh" require_contains "$skill_dir/references/index.md" "automation.md" require_contains "$skill_dir/references/README.md" "swarm-state.md" require_contains "$script_dir/README.md" "validate-auto-tmux.sh" require_contains "$script_dir/README.md" "swarm-dispatch.sh" +require_contains "$script_dir/README.md" "swarm-watch.sh" require_contains "$script_dir/AGENTS.md" "validate-auto-tmux.sh" require_contains "$script_dir/AGENTS.md" "swarm-dispatch.sh" +require_contains "$script_dir/AGENTS.md" "swarm-watch.sh" if [[ -x "$repo_root/skills/auto-skill/scripts/validate-skill.sh" ]]; then run_gate "auto-skill strict validation" "$repo_root/skills/auto-skill/scripts/validate-skill.sh" "$skill_dir" --strict