diff --git a/skills/auto-tmux/AGENTS.md b/skills/auto-tmux/AGENTS.md index f755de0..e305c42 100644 --- a/skills/auto-tmux/AGENTS.md +++ b/skills/auto-tmux/AGENTS.md @@ -19,6 +19,7 @@ skills/auto-tmux/ │ ├── swarm-archive.sh │ ├── swarm-board.sh │ ├── swarm-deps-graph.sh +│ ├── swarm-export.sh │ ├── swarm-assign.sh │ ├── swarm-health.sh │ ├── record-summary.sh @@ -53,6 +54,7 @@ skills/auto-tmux/ - `scripts/swarm-archive.sh` 是归档层,打包 brief、snapshot 和 swarm state 供复盘交接。 - `scripts/swarm-board.sh` 是看板层,将任务、依赖、锁和状态日志渲染为 Markdown。 - `scripts/swarm-deps-graph.sh` 是依赖可视化层,将 `deps.tsv` 渲染为 Mermaid 图。 +- `scripts/swarm-export.sh` 是机器可读导出层,将任务、依赖和锁导出为 JSONL。 - `scripts/swarm-assign.sh` 是分配建议层,将 ready task 轮询映射到 worker pane。 - `scripts/swarm-health.sh` 是健康检查层,汇总 tmux 和 swarm state 的只读报告包。 - `scripts/record-summary.sh` 是复盘摘要层,将 pane 录制日志整理为 Markdown。 @@ -69,4 +71,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/swarm-watch.sh`、`bash -n skills/auto-tmux/scripts/swarm-archive.sh`、`bash -n skills/auto-tmux/scripts/swarm-board.sh`、`bash -n skills/auto-tmux/scripts/swarm-deps-graph.sh`、`bash -n skills/auto-tmux/scripts/swarm-assign.sh`、`bash -n skills/auto-tmux/scripts/swarm-health.sh`、`bash -n skills/auto-tmux/scripts/record-summary.sh`、`bash -n skills/auto-tmux/scripts/completion.bash`、`bash -n skills/auto-tmux/scripts/safety-check.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/swarm-archive.sh`、`bash -n skills/auto-tmux/scripts/swarm-board.sh`、`bash -n skills/auto-tmux/scripts/swarm-deps-graph.sh`、`bash -n skills/auto-tmux/scripts/swarm-export.sh`、`bash -n skills/auto-tmux/scripts/swarm-assign.sh`、`bash -n skills/auto-tmux/scripts/swarm-health.sh`、`bash -n skills/auto-tmux/scripts/record-summary.sh`、`bash -n skills/auto-tmux/scripts/completion.bash`、`bash -n skills/auto-tmux/scripts/safety-check.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 b72daf1..a64df62 100644 --- a/skills/auto-tmux/README.md +++ b/skills/auto-tmux/README.md @@ -26,6 +26,7 @@ bash -n skills/auto-tmux/scripts/swarm-watch.sh bash -n skills/auto-tmux/scripts/swarm-archive.sh bash -n skills/auto-tmux/scripts/swarm-board.sh bash -n skills/auto-tmux/scripts/swarm-deps-graph.sh +bash -n skills/auto-tmux/scripts/swarm-export.sh bash -n skills/auto-tmux/scripts/swarm-assign.sh bash -n skills/auto-tmux/scripts/swarm-health.sh bash -n skills/auto-tmux/scripts/record-summary.sh diff --git a/skills/auto-tmux/SKILL.md b/skills/auto-tmux/SKILL.md index d13f3a6..7cf570b 100644 --- a/skills/auto-tmux/SKILL.md +++ b/skills/auto-tmux/SKILL.md @@ -40,6 +40,7 @@ bash -n skills/auto-tmux/scripts/swarm-watch.sh bash -n skills/auto-tmux/scripts/swarm-archive.sh bash -n skills/auto-tmux/scripts/swarm-board.sh bash -n skills/auto-tmux/scripts/swarm-deps-graph.sh +bash -n skills/auto-tmux/scripts/swarm-export.sh bash -n skills/auto-tmux/scripts/swarm-assign.sh bash -n skills/auto-tmux/scripts/swarm-health.sh bash -n skills/auto-tmux/scripts/record-summary.sh @@ -125,6 +126,7 @@ skills/auto-tmux/scripts/swarm-watch.sh --session ai-hub --swarm-dir /tmp/ai_swa skills/auto-tmux/scripts/swarm-archive.sh --session ai-hub --swarm-dir /tmp/ai_swarm --out /tmp/ai-hub-handoff.tar.gz skills/auto-tmux/scripts/swarm-board.sh --dir /tmp/ai_swarm --out /tmp/ai-swarm-board.md skills/auto-tmux/scripts/swarm-deps-graph.sh --dir /tmp/ai_swarm --out /tmp/ai-swarm-deps.md +skills/auto-tmux/scripts/swarm-export.sh --dir /tmp/ai_swarm --out /tmp/ai-swarm-export skills/auto-tmux/scripts/swarm-assign.sh --swarm-dir /tmp/ai_swarm --session ai-hub --out /tmp/ai-swarm-assign.md skills/auto-tmux/scripts/swarm-health.sh --session ai-hub --swarm-dir /tmp/ai_swarm --out /tmp/auto-tmux-health ``` @@ -273,6 +275,7 @@ skills/auto-tmux/scripts/swarm-dispatch.sh --role worker --target ::/dev/null || true - rm -rf "$SWARM_DIR" "$DEP_SWARM_DIR" "$SNAPSHOT_DIR" "$RECORD_DIR" "$RECORD_SUMMARY_FILE" "$BRIEF_DIR" "$WATCH_DIR" "$ARCHIVE_FILE" "$BOARD_FILE" "$DEPS_GRAPH_FILE" "$ASSIGN_FILE" "$HEALTH_DIR" "$DISPATCH_PROMPT" "$TASK_IMPORT_FILE" "$PASTE_FILE" + rm -rf "$SWARM_DIR" "$DEP_SWARM_DIR" "$SNAPSHOT_DIR" "$RECORD_DIR" "$RECORD_SUMMARY_FILE" "$BRIEF_DIR" "$WATCH_DIR" "$ARCHIVE_FILE" "$BOARD_FILE" "$DEPS_GRAPH_FILE" "$EXPORT_DIR" "$ASSIGN_FILE" "$HEALTH_DIR" "$DISPATCH_PROMPT" "$TASK_IMPORT_FILE" "$PASTE_FILE" } trap cleanup EXIT @@ -53,6 +55,7 @@ bash -n "$SWARM_WATCH" bash -n "$SWARM_ARCHIVE" bash -n "$SWARM_BOARD" bash -n "$SWARM_DEPS_GRAPH" +bash -n "$SWARM_EXPORT" bash -n "$SWARM_ASSIGN" bash -n "$SWARM_HEALTH" bash -n "$RECORD_SUMMARY" @@ -154,6 +157,10 @@ grep -q 'smoke-fail' "$BOARD_FILE" "$SWARM_DEPS_GRAPH" --dir "$SWARM_DIR" --out "$DEPS_GRAPH_FILE" >/tmp/auto-tmux-smoke-deps-graph.txt grep -q 'auto-tmux Swarm Dependency Graph' "$DEPS_GRAPH_FILE" grep -q 'task_dep_a --> task_dep_b' "$DEPS_GRAPH_FILE" +"$SWARM_EXPORT" --dir "$SWARM_DIR" --out "$EXPORT_DIR" >/tmp/auto-tmux-smoke-export.txt +grep -q '"type":"auto-tmux-swarm-export"' "$EXPORT_DIR/manifest.json" +grep -q '"id":"smoke-task"' "$EXPORT_DIR/tasks.jsonl" +grep -q '"task_id":"dep-b"' "$EXPORT_DIR/deps.jsonl" "$SWARM_ASSIGN" --swarm-dir "$SWARM_DIR" --session "$SESSION" --out "$ASSIGN_FILE" --limit 20 >/tmp/auto-tmux-smoke-assign.txt grep -q 'auto-tmux Swarm Assignment Suggestions' "$ASSIGN_FILE" grep -q 'swarm-dispatch.sh' "$ASSIGN_FILE" diff --git a/skills/auto-tmux/scripts/auto-tmux.sh b/skills/auto-tmux/scripts/auto-tmux.sh index f33218f..95ba2cb 100755 --- a/skills/auto-tmux/scripts/auto-tmux.sh +++ b/skills/auto-tmux/scripts/auto-tmux.sh @@ -153,7 +153,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 swarm-watch.sh swarm-archive.sh swarm-board.sh swarm-deps-graph.sh swarm-assign.sh swarm-health.sh record-summary.sh safety-check.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 swarm-archive.sh swarm-board.sh swarm-deps-graph.sh swarm-export.sh swarm-assign.sh swarm-health.sh record-summary.sh safety-check.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-export.sh b/skills/auto-tmux/scripts/swarm-export.sh new file mode 100755 index 0000000..944203a --- /dev/null +++ b/skills/auto-tmux/scripts/swarm-export.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +# swarm-export: export swarm state as machine-readable JSONL files. +set -euo pipefail + +usage() { + cat <<'EOF' +swarm-export: export auto-tmux swarm state as JSONL + +Usage: + swarm-export.sh [--dir DIR] [--out DIR] + +Defaults: + --dir AUTO_TMUX_SWARM_DIR or /tmp/ai_swarm + --out /tmp/auto-tmux-export-YYYYmmdd-HHMMSS + +Outputs: + tasks.jsonl + deps.jsonl + locks.jsonl + manifest.json + +This script is read-only. It does not mutate swarm state. +EOF +} + +die() { + printf 'error: %s\n' "$*" >&2 + exit 1 +} + +swarm_dir="${AUTO_TMUX_SWARM_DIR:-/tmp/ai_swarm}" +out_dir="/tmp/auto-tmux-export-$(date +%Y%m%d-%H%M%S)" + +while [[ $# -gt 0 ]]; do + case "$1" in + --dir|--swarm-dir) + swarm_dir="${2:-}" + shift 2 + ;; + --out) + out_dir="${2:-}" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + *) + die "unknown option: $1" + ;; + esac +done + +tasks_tsv="$swarm_dir/tasks.tsv" +deps_tsv="$swarm_dir/deps.tsv" +locks_dir="$swarm_dir/locks" +[[ -f "$tasks_tsv" ]] || die "tasks file not found: $tasks_tsv" +[[ -f "$deps_tsv" ]] || die "deps file not found: $deps_tsv" +mkdir -p "$out_dir" + +json_escape() { + printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\r/\\r/g' -e 's/\n/\\n/g' +} + +awk -F '\t' ' + function json(value) { + gsub(/\\/, "\\\\", value) + gsub(/"/, "\\\"", value) + gsub(/\r/, "\\r", value) + gsub(/\n/, "\\n", value) + return value + } + NR > 1 { + print "{\"id\":\"" json($1) "\",\"status\":\"" json($2) "\",\"owner\":\"" json($3) "\",\"text\":\"" json($4) "\",\"result\":\"" json($5) "\"}" + } +' "$tasks_tsv" > "$out_dir/tasks.jsonl" + +awk -F '\t' ' + function json(value) { + gsub(/\\/, "\\\\", value) + gsub(/"/, "\\\"", value) + return value + } + NR > 1 { + print "{\"task_id\":\"" json($1) "\",\"blocked_by\":\"" json($2) "\"}" + } +' "$deps_tsv" > "$out_dir/deps.jsonl" + +if [[ -d "$locks_dir" ]]; then + find "$locks_dir" -mindepth 1 -maxdepth 1 -type d -name '*.lock.d' -print | sort | while read -r path; do + name="$(basename "$path" .lock.d)" + owner="$(cat "$path/owner" 2>/dev/null || printf unknown)" + created_at="$(cat "$path/created_at" 2>/dev/null || printf unknown)" + printf '{"name":"%s","owner":"%s","created_at":"%s"}\n' \ + "$(json_escape "$name")" "$(json_escape "$owner")" "$(json_escape "$created_at")" + done > "$out_dir/locks.jsonl" +else + : > "$out_dir/locks.jsonl" +fi + +printf '{"type":"auto-tmux-swarm-export","created_at":"%s","swarm_dir":"%s","files":["tasks.jsonl","deps.jsonl","locks.jsonl"]}\n' \ + "$(date -Is)" "$(json_escape "$swarm_dir")" > "$out_dir/manifest.json" + +printf 'swarm export 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 9cf7a2d..0b01fe0 100755 --- a/skills/auto-tmux/scripts/validate-auto-tmux.sh +++ b/skills/auto-tmux/scripts/validate-auto-tmux.sh @@ -84,6 +84,7 @@ scripts=( "$script_dir/swarm-archive.sh" "$script_dir/swarm-board.sh" "$script_dir/swarm-deps-graph.sh" + "$script_dir/swarm-export.sh" "$script_dir/swarm-assign.sh" "$script_dir/swarm-health.sh" "$script_dir/record-summary.sh" @@ -108,6 +109,7 @@ run_gate "swarm-watch help" "$script_dir/swarm-watch.sh" --help run_gate "swarm-archive help" "$script_dir/swarm-archive.sh" --help run_gate "swarm-board help" "$script_dir/swarm-board.sh" --help run_gate "swarm-deps-graph help" "$script_dir/swarm-deps-graph.sh" --help +run_gate "swarm-export help" "$script_dir/swarm-export.sh" --help run_gate "swarm-assign help" "$script_dir/swarm-assign.sh" --help run_gate "swarm-health help" "$script_dir/swarm-health.sh" --help run_gate "record-summary help" "$script_dir/record-summary.sh" --help @@ -127,6 +129,7 @@ require_contains "$skill_dir/SKILL.md" "scripts/swarm-watch.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-archive.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-board.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-deps-graph.sh" +require_contains "$skill_dir/SKILL.md" "scripts/swarm-export.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-assign.sh" require_contains "$skill_dir/SKILL.md" "scripts/swarm-health.sh" require_contains "$skill_dir/SKILL.md" "scripts/record-summary.sh" @@ -143,6 +146,7 @@ require_contains "$script_dir/README.md" "swarm-watch.sh" require_contains "$script_dir/README.md" "swarm-archive.sh" require_contains "$script_dir/README.md" "swarm-board.sh" require_contains "$script_dir/README.md" "swarm-deps-graph.sh" +require_contains "$script_dir/README.md" "swarm-export.sh" require_contains "$script_dir/README.md" "swarm-assign.sh" require_contains "$script_dir/README.md" "swarm-health.sh" require_contains "$script_dir/README.md" "record-summary.sh" @@ -154,6 +158,7 @@ require_contains "$script_dir/AGENTS.md" "swarm-watch.sh" require_contains "$script_dir/AGENTS.md" "swarm-archive.sh" require_contains "$script_dir/AGENTS.md" "swarm-board.sh" require_contains "$script_dir/AGENTS.md" "swarm-deps-graph.sh" +require_contains "$script_dir/AGENTS.md" "swarm-export.sh" require_contains "$script_dir/AGENTS.md" "swarm-assign.sh" require_contains "$script_dir/AGENTS.md" "swarm-health.sh" require_contains "$script_dir/AGENTS.md" "record-summary.sh"