@humanu/orchestra 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,148 @@
1
+ #!/bin/bash
2
+
3
+ ###############################################################################
4
+ # gw.sh – Git-Worktree helper main entry point
5
+ # ---------------------------------------------------------------------------
6
+ # This script prints a line like: cd "/abs/path" for your shell wrapper to eval
7
+ # so your interactive shell actually changes directories. See wrapper notes
8
+ # below. It routes commands to appropriate modules and offers an interactive
9
+ # picker when invoked with no args.
10
+ ###############################################################################
11
+
12
+ # Recommended wrapper (place in ~/.bash_profile or ~/.zshrc):
13
+ #
14
+ # gw () {
15
+ # local script="/absolute/path/to/gw.sh" # UPDATE THIS PATH
16
+ # local out
17
+ # out="$(command bash "$script" "$@")"
18
+ # local status=$?
19
+ # local cd_line
20
+ # cd_line="$(printf '%s\n' "$out" | grep -m1 '^cd \".*\"')"
21
+ # [[ -n $cd_line ]] && eval "$cd_line"
22
+ # printf '%s\n' "$out" | grep -v -F "$cd_line"
23
+ # return $status
24
+ # }
25
+
26
+ # --------------------------- Utilities --------------------------------------
27
+ set -o errexit
28
+ set -o pipefail
29
+ set -o nounset
30
+
31
+ # Don't exit on errors inside helper subshells we explicitly guard
32
+ # lastpipe not available on older macOS bash; ignore
33
+
34
+ err() { printf '❌ %s\n' "$*" 1>&2; }
35
+ info() { printf '%s\n' "$*"; }
36
+ debug() { :; }
37
+
38
+ have_cmd() { command -v "$1" >/dev/null 2>&1; }
39
+
40
+ # Legacy wrappers for backward compatibility - these now use git.sh API
41
+ repo_root() { git_repo_root; }
42
+ current_abs_path() { git_current_path; }
43
+ branch_to_slug() { git_branch_to_slug "$1"; }
44
+ worktree_path_to_branch() { git_worktree_path_to_branch "$1"; }
45
+ list_worktrees() { git_list_worktrees; }
46
+
47
+ # --------------------------- Module Loading ---------------------------------
48
+
49
+ # Source Git API module first (required by other modules)
50
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
51
+ if [[ -f "$SCRIPT_DIR/api/git.sh" ]]; then
52
+ source "$SCRIPT_DIR/api/git.sh"
53
+ else
54
+ err "api/git.sh not found in $SCRIPT_DIR"
55
+ exit 1
56
+ fi
57
+
58
+ # Source command-line operations
59
+ if [[ -f "$SCRIPT_DIR/commands.sh" ]]; then
60
+ source "$SCRIPT_DIR/commands.sh"
61
+ else
62
+ err "commands.sh not found in $SCRIPT_DIR"
63
+ exit 1
64
+ fi
65
+
66
+ # Source tmux API module
67
+ if [[ -f "$SCRIPT_DIR/api/tmux.sh" ]]; then
68
+ source "$SCRIPT_DIR/api/tmux.sh"
69
+ else
70
+ err "api/tmux.sh not found in $SCRIPT_DIR"
71
+ exit 1
72
+ fi
73
+
74
+ # Interactive functionality is provided by the Rust TUI (gw-tui)
75
+ # No longer sourcing interactive.sh - Rust TUI is the primary interface
76
+
77
+ # --------------------------- core features ----------------------------------
78
+
79
+ usage() {
80
+ echo "Usage: $(basename "$0") <command> [args]"
81
+ echo ""
82
+ echo "Git worktree helper - command-line manages worktrees, interactive manages tmux sessions."
83
+ echo ""
84
+ echo "Commands:"
85
+ echo " (no args) Interactive picker of worktrees + tmux sessions"
86
+ echo " b, create, add <branch> Create a new branch and its worktree"
87
+ echo " d, delete, rm <branch> Delete a worktree and its local branch"
88
+ echo " ls, list List worktrees only"
89
+ echo " ch, checkout -b <branch> Create <branch>, its worktree, and switch"
90
+ echo " ch, checkout <branch> Switch to the worktree of <branch>"
91
+ echo " copy-env <worktreename> Copy env files from current worktree to target"
92
+ echo " status [git status args] Show current worktree + git status"
93
+ echo ""
94
+ echo "Examples:"
95
+ echo " $(basename "$0") # interactive picker (tmux session management)"
96
+ echo " $(basename "$0") ls # list worktrees only"
97
+ echo " $(basename "$0") ch -b feat/x # create and switch to worktree"
98
+ echo ""
99
+ echo "Note: tmux session management is only available via the interactive menu (no args)."
100
+ }
101
+
102
+
103
+
104
+ # --------------------------- Main -------------------------------------------
105
+
106
+ if [ $# -eq 0 ]; then
107
+ # Interactive mode by default - prefer Rust TUI if available
108
+ if command -v gw-tui >/dev/null 2>&1; then
109
+ # Use Rust TUI if available
110
+ gw-tui --bridge-path "$SCRIPT_DIR/gw-bridge.sh"
111
+ elif [[ -f "$SCRIPT_DIR/gw-tui/target/release/gw-tui" ]]; then
112
+ # Use locally built Rust TUI
113
+ "$SCRIPT_DIR/gw-tui/target/release/gw-tui" --bridge-path "$SCRIPT_DIR/gw-bridge.sh"
114
+ elif [[ -f "$SCRIPT_DIR/gw-tui/target/debug/gw-tui" ]]; then
115
+ # Use debug build of Rust TUI
116
+ "$SCRIPT_DIR/gw-tui/target/debug/gw-tui" --bridge-path "$SCRIPT_DIR/gw-bridge.sh"
117
+ else
118
+ # No Rust TUI available - provide clear guidance
119
+ err "Interactive mode requires the Rust TUI (gw-tui)"
120
+ echo ""
121
+ echo "To build:"
122
+ echo " ./build.sh # Build Rust TUI binary"
123
+ echo ""
124
+ echo "Or build manually:"
125
+ echo " cd gw-tui && cargo build --release"
126
+ echo ""
127
+ echo "For command-line operations without interactive mode:"
128
+ echo " $0 ls # List worktrees"
129
+ echo " $0 ch <branch> # Switch to worktree"
130
+ echo " $0 help # Show all commands"
131
+ exit 1
132
+ fi
133
+ exit 0
134
+ fi
135
+
136
+ COMMAND="$1"; shift || true
137
+ case "$COMMAND" in
138
+ b|create|add) cmd_create_worktree "$@" ;;
139
+ d|delete|remove|rm) cmd_delete_worktree "$@" ;;
140
+ ls|list) cmd_list_worktrees ;;
141
+ ch|checkout) cmd_checkout_worktree "$@" ;;
142
+ status) cmd_status "$@" ;;
143
+ copy-env) cmd_copy_env "$@" ;;
144
+ help|-h|--help) usage ;;
145
+ *) err "Unknown command '$COMMAND'"; usage ;;
146
+ esac
147
+
148
+ exit 0
@@ -0,0 +1,171 @@
1
+ #!/bin/bash
2
+
3
+ ###############################################################################
4
+ # gwr.sh – Git-Worktree Rust TUI launcher
5
+ # ---------------------------------------------------------------------------
6
+ # This script launches the Rust TUI application for git worktree and tmux
7
+ # session management. It automatically detects the built binary location
8
+ # and passes through any command-line arguments.
9
+ ###############################################################################
10
+
11
+ # Recommended wrapper (place in ~/.bash_profile or ~/.zshrc):
12
+ #
13
+ # gwr () {
14
+ # local script="/absolute/path/to/gwr.sh" # UPDATE THIS PATH
15
+ # local out
16
+ # out="$(command bash "$script" "$@")"
17
+ # local status=$?
18
+ # local cd_line
19
+ # cd_line="$(printf '%s\n' "$out" | grep -m1 '^cd \".*\"')"
20
+ # [[ -n $cd_line ]] && eval "$cd_line"
21
+ # printf '%s\n' "$out" | grep -v -F "$cd_line"
22
+ # return $status
23
+ # }
24
+
25
+ set -o errexit
26
+ set -o pipefail
27
+ set -o nounset
28
+
29
+ # Colors for output
30
+ RED='\033[0;31m'
31
+ GREEN='\033[0;32m'
32
+ YELLOW='\033[1;33m'
33
+ BLUE='\033[0;34m'
34
+ NC='\033[0m' # No Color
35
+
36
+ info() { printf "${BLUE}[INFO]${NC} %s\n" "$*" >&2; }
37
+ success() { printf "${GREEN}[SUCCESS]${NC} %s\n" "$*" >&2; }
38
+ warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$*" >&2; }
39
+ error() { printf "${RED}[ERROR]${NC} %s\n" "$*" >&2; }
40
+
41
+ # Get script directory
42
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
43
+
44
+ # Function to find the gw-tui binary
45
+ find_gw_tui_binary() {
46
+ # Check environment variable first (for Homebrew installs)
47
+ if [[ -n "${GW_TUI_BIN:-}" && -x "$GW_TUI_BIN" ]]; then
48
+ echo "$GW_TUI_BIN"
49
+ return 0
50
+ fi
51
+
52
+ local binary_paths=(
53
+ "$SCRIPT_DIR/orchestra"
54
+ "$SCRIPT_DIR/gw-tui"
55
+ "$SCRIPT_DIR/gw-tui/target/release/gw-tui"
56
+ "$SCRIPT_DIR/gw-tui/target/debug/gw-tui"
57
+ "$(command -v gw-tui 2>/dev/null || true)"
58
+ )
59
+
60
+ for path in "${binary_paths[@]}"; do
61
+ if [[ -n "$path" && -x "$path" ]]; then
62
+ echo "$path"
63
+ return 0
64
+ fi
65
+ done
66
+
67
+ return 1
68
+ }
69
+
70
+ # Function to check if we're in a git repository
71
+ check_git_repo() {
72
+ if ! git rev-parse --git-dir >/dev/null 2>&1; then
73
+ error "Not a git repository or git command not found."
74
+ exit 1
75
+ fi
76
+ }
77
+
78
+ # Function to check if bridge script exists
79
+ check_bridge_script() {
80
+ local bridge_path="$SCRIPT_DIR/gw-bridge.sh"
81
+ if [[ ! -x "$bridge_path" ]]; then
82
+ error "gw-bridge.sh not found or not executable at: $bridge_path"
83
+ error "Please ensure the bridge script exists and is executable."
84
+ exit 1
85
+ fi
86
+ }
87
+
88
+ # Show usage information
89
+ show_usage() {
90
+ cat << EOF
91
+ gwr - Git Worktree Rust TUI
92
+
93
+ Usage: gwr [options]
94
+
95
+ A terminal user interface for managing git worktrees and tmux sessions.
96
+
97
+ Options:
98
+ -d, --debug Enable debug mode
99
+ -h, --help Show this help
100
+
101
+ Features:
102
+ • Interactive worktree and session management
103
+ • Visual tree display of worktrees and their tmux sessions
104
+ • Real-time session previews and git status
105
+ • Keyboard navigation with vim-like bindings
106
+ • Session creation, deletion, and renaming
107
+ • AI-powered session naming (when configured)
108
+
109
+ Navigation:
110
+ ↑/↓ Navigate items
111
+ Enter Select worktree or attach to session
112
+ s Auth menu (if enabled)
113
+ Space Expand/collapse worktree sessions
114
+ d Delete worktree or kill session
115
+ r Rename session (AI-powered)
116
+ c Create new worktree
117
+ o Configure Anthropic API key
118
+ Ctrl+R Refresh data
119
+ q/Esc Quit
120
+
121
+ Requirements:
122
+ • Git repository
123
+ • Rust TUI binary (built with build.sh)
124
+ • gw-bridge.sh script
125
+ • tmux (optional, for session management)
126
+
127
+ For the original shell-based interface, use: gw
128
+
129
+ Examples:
130
+ gwr # Launch interactive TUI
131
+ gwr --debug # Launch with debug information
132
+ gwr --help # Show this help
133
+
134
+ EOF
135
+ }
136
+
137
+ # Handle help flag early
138
+ if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
139
+ show_usage
140
+ exit 0
141
+ fi
142
+
143
+ # Check prerequisites
144
+ check_git_repo
145
+ check_bridge_script
146
+
147
+ # Find the binary
148
+ if ! BINARY_PATH=$(find_gw_tui_binary); then
149
+ error "gw-tui binary not found!"
150
+ error ""
151
+ error "Please build the Rust TUI first:"
152
+ error " ./build.sh"
153
+ error ""
154
+ error "Or install globally:"
155
+ error " ./build.sh --install"
156
+ error ""
157
+ error "Binary search paths:"
158
+ if [[ -n "${GW_TUI_BIN:-}" ]]; then
159
+ error " • $GW_TUI_BIN (from GW_TUI_BIN)"
160
+ fi
161
+ error " • $SCRIPT_DIR/gw-tui/target/release/gw-tui"
162
+ error " • $SCRIPT_DIR/gw-tui/target/debug/gw-tui"
163
+ error " • gw-tui (in PATH)"
164
+ exit 1
165
+ fi
166
+
167
+ # Get bridge script path
168
+ BRIDGE_PATH="$SCRIPT_DIR/gw-bridge.sh"
169
+
170
+ # Run the Rust TUI with bridge path and all arguments passed through
171
+ exec "$BINARY_PATH" --bridge-path "$BRIDGE_PATH" "$@"