feat(scripts): add agent-worktree CLI skeleton with help and dispatch (ref #83)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-05-12 09:51:38 +02:00
parent a67c4c6b6e
commit 33768c7854
2 changed files with 79 additions and 0 deletions

60
scripts/agent-worktree.sh Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
# scripts/agent-worktree.sh
# Multi-agent worktree workflow helper.
# See docs/superpowers/specs/2026-05-12-multi-agent-worktree-workflow-design.md
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=lib/agent-worktree-lib.sh
source "$SCRIPT_DIR/lib/agent-worktree-lib.sh"
WORKTREE_ROOT="${WORKTREE_ROOT:-$HOME/CyberMindStudio/secubox-deb-worktrees}"
GH_BIN="${GH_BIN:-gh}"
GIT_BIN="${GIT_BIN:-git}"
usage() {
cat <<'USAGE'
agent-worktree.sh — multi-agent worktree workflow helper
Usage:
agent-worktree.sh start --issue <N> [--dry-run] [--verbose]
agent-worktree.sh list [--verbose]
agent-worktree.sh sync [<N>]
agent-worktree.sh finish [--dry-run]
agent-worktree.sh clean <N> [--force]
agent-worktree.sh --help
Environment:
WORKTREE_ROOT override worktree root (default: ~/CyberMindStudio/secubox-deb-worktrees)
GH_BIN, GIT_BIN override CLI binaries (used by tests)
Exit codes:
0 success
1 generic / usage
2 precondition (issue missing, gh not authed, etc.)
3 bad state (dirty tree, conflict, non-merged PR)
4 network / remote error
USAGE
}
cmd_start() { echo "start: not implemented" >&2 ; return 1; }
cmd_list() { echo "list: not implemented" >&2 ; return 1; }
cmd_sync() { echo "sync: not implemented" >&2 ; return 1; }
cmd_finish() { echo "finish: not implemented" >&2; return 1; }
cmd_clean() { echo "clean: not implemented" >&2 ; return 1; }
main() {
local sub="${1:-}"
shift || true
case "$sub" in
-h|--help|help|"") usage ; return 0 ;;
start) cmd_start "$@" ;;
list) cmd_list "$@" ;;
sync) cmd_sync "$@" ;;
finish) cmd_finish "$@" ;;
clean) cmd_clean "$@" ;;
*) echo "unknown sub-command: $sub" >&2 ; usage >&2 ; return 1 ;;
esac
}
main "$@"

View File

@ -101,6 +101,25 @@ test_prefix_first_match_wins() {
assert_eq "fix/" "$(prefix_from_labels 'bug,documentation')" "first match"
}
test_script_help_exits_zero() {
local out
out=$(bash "$SCRIPT" --help 2>&1)
assert_eq "0" "$?" "help exit"
assert_contains "$out" "agent-worktree.sh"
assert_contains "$out" "start"
assert_contains "$out" "list"
assert_contains "$out" "sync"
assert_contains "$out" "finish"
assert_contains "$out" "clean"
}
test_script_unknown_subcommand_exits_1() {
local out rc
out=$(bash "$SCRIPT" wibble 2>&1) ; rc=$?
if [[ $rc -ne 1 ]]; then echo "expected rc=1, got $rc; out=$out" >&2; return 1; fi
assert_contains "$out" "unknown"
}
# Auto-discover and run
mapfile -t tests < <(declare -F | awk '{print $3}' | grep '^test_')
for t in "${tests[@]}"; do run_test "$t"; done