@humanu/orchestra 0.5.42 → 0.5.49

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humanu/orchestra",
3
- "version": "0.5.42",
3
+ "version": "0.5.49",
4
4
  "description": "AI-powered Git worktree and tmux session manager with modern TUI",
5
5
  "keywords": [
6
6
  "git",
@@ -737,8 +737,13 @@ tmux_session_preview() {
737
737
  else
738
738
  echo "<<<IDLE:false>>>"
739
739
  fi
740
-
741
- echo "$txt"
740
+
741
+ # If no content after processing, show placeholder
742
+ if [[ -z "$txt" ]]; then
743
+ echo "(session active, no visible output)"
744
+ else
745
+ echo "$txt"
746
+ fi
742
747
  }
743
748
 
744
749
  # --------------------------- Advanced Operations ----------------------------
@@ -146,24 +146,31 @@ copy_env_files() {
146
146
 
147
147
  if [[ "$trimmed" == "/" ]]; then
148
148
  local found_root=0
149
- for env_file in "$base"/.env*; do
149
+ while IFS= read -r -d '' env_file; do
150
150
  [[ -f "$env_file" ]] || continue
151
- mkdir -p "$target_root"
151
+ local rel_path="${env_file#$base/}"
152
+ if [[ "$rel_path" == "$env_file" ]]; then
153
+ rel_path="$(basename "$env_file")"
154
+ fi
155
+ local dest_path="$target_root/$rel_path"
156
+ mkdir -p "$(dirname "$dest_path")"
152
157
  local err_msg
153
- err_msg="$(cp "$env_file" "$target_root/$(basename "$env_file")" 2>&1)"
158
+ err_msg="$(cp "$env_file" "$dest_path" 2>&1)"
154
159
  if [[ $? -eq 0 ]]; then
155
160
  (( overall_copied++ ))
156
161
  location_copied=1
157
162
  found_root=1
158
- (( quiet != 1 )) && echo " ✅ Copied $(basename "$env_file") from $base/"
159
- copy_env_log "INFO" "Copied $(basename "$env_file") from $base/"
163
+ (( quiet != 1 )) && echo " ✅ Copied $rel_path from $base/"
164
+ copy_env_log "INFO" "Copied $rel_path from $base/"
160
165
  else
161
166
  (( overall_failed++ ))
162
167
  (( location_failed++ ))
163
- (( quiet != 1 )) && echo " ❌ Failed to copy $(basename "$env_file") from $base/"
164
- copy_env_log "ERROR" "Failed to copy $(basename "$env_file") from $base/: ${err_msg:-unknown error}"
168
+ (( quiet != 1 )) && echo " ❌ Failed to copy $rel_path from $base/"
169
+ copy_env_log "ERROR" "Failed to copy $rel_path from $base/: ${err_msg:-unknown error}"
165
170
  fi
166
- done
171
+ done < <(find "$base" \
172
+ \( -path "$target_root" -o -path "$target_root/*" -o -path "$base/.git" -o -path "$base/.git/*" -o -path "$base/worktrees" -o -path "$base/worktrees/*" \) -prune -o \
173
+ -type f -name '.env*' -print0 2>/dev/null)
167
174
  if [[ $found_root -eq 1 ]]; then
168
175
  break
169
176
  fi
@@ -56,7 +56,8 @@ fi
56
56
  "git/list_worktrees.sh" \
57
57
  "git/checkout_worktree.sh" \
58
58
  "git/status.sh" \
59
- "env/copy_env_command.sh"
59
+ "env/copy_env_command.sh" \
60
+ "tmux/new_session_command.sh"
60
61
  do
61
62
  if [[ -f "$COMMANDS_DIR/$command_file" ]]; then
62
63
  # shellcheck source=/dev/null
@@ -138,13 +139,19 @@ usage() {
138
139
  echo " status [git status args] Show current worktree + git status"
139
140
  echo " update, --update Check for available updates"
140
141
  echo ""
142
+ echo "Tmux flags:"
143
+ echo " --branch <branch> Branch name for tmux session worktree"
144
+ echo " --new-tmux Create a new tmux session for the branch"
145
+ echo " --cmd <command> Command to run inside the new session"
146
+ echo ""
141
147
  echo "Examples:"
142
148
  echo " $(basename "$0") # interactive picker (tmux session management)"
143
149
  echo " $(basename "$0") ls # list worktrees only"
144
150
  echo " $(basename "$0") ch -b feat/x # create and switch to worktree"
151
+ echo " $(basename "$0") --branch main --new-tmux --cmd \"git status\""
145
152
  echo " $(basename "$0") update # check for available updates"
146
153
  echo ""
147
- echo "Note: tmux session management is only available via the interactive menu (no args)."
154
+ echo "Note: tmux session management is available via flags or the interactive menu."
148
155
  }
149
156
 
150
157
 
@@ -184,6 +191,49 @@ if [ $# -eq 0 ]; then
184
191
  exit 0
185
192
  fi
186
193
 
194
+ new_tmux=false
195
+ tmux_branch=""
196
+ tmux_cmd=""
197
+ while [[ $# -gt 0 ]]; do
198
+ case "$1" in
199
+ --branch|-b)
200
+ [[ $# -lt 2 ]] && { err "--branch requires a value"; exit 1; }
201
+ tmux_branch="$2"
202
+ shift 2
203
+ ;;
204
+ --cmd|-c)
205
+ [[ $# -lt 2 ]] && { err "--cmd requires a value"; exit 1; }
206
+ tmux_cmd="$2"
207
+ shift 2
208
+ ;;
209
+ --new-tmux)
210
+ new_tmux=true
211
+ shift
212
+ ;;
213
+ --)
214
+ shift
215
+ break
216
+ ;;
217
+ *)
218
+ break
219
+ ;;
220
+ esac
221
+ done
222
+
223
+ if $new_tmux; then
224
+ if [[ -z "$tmux_branch" || -z "$tmux_cmd" ]]; then
225
+ err "Usage: $(basename "$0") --branch <branch> --new-tmux --cmd \"<command>\""
226
+ exit 1
227
+ fi
228
+ cmd_new_tmux_session_with_command "$tmux_branch" "$tmux_cmd"
229
+ exit $?
230
+ fi
231
+
232
+ if [[ -n "$tmux_branch" || -n "$tmux_cmd" ]]; then
233
+ err "--branch/--cmd require --new-tmux"
234
+ exit 1
235
+ fi
236
+
187
237
  COMMAND="$1"; shift || true
188
238
  case "$COMMAND" in
189
239
  b|create|add) cmd_create_worktree "$@" ;;
@@ -73,24 +73,31 @@ copy_env_files() {
73
73
 
74
74
  if [[ "$trimmed" == "/" ]]; then
75
75
  local found_root=0
76
- for env_file in "$base"/.env*; do
76
+ while IFS= read -r -d '' env_file; do
77
77
  [[ -f "$env_file" ]] || continue
78
- mkdir -p "$target_root"
78
+ local rel_path="${env_file#$base/}"
79
+ if [[ "$rel_path" == "$env_file" ]]; then
80
+ rel_path="$(basename "$env_file")"
81
+ fi
82
+ local dest_path="$target_root/$rel_path"
83
+ mkdir -p "$(dirname "$dest_path")"
79
84
  local err_msg
80
- err_msg="$(cp "$env_file" "$target_root/$(basename "$env_file")" 2>&1)"
85
+ err_msg="$(cp "$env_file" "$dest_path" 2>&1)"
81
86
  if [[ $? -eq 0 ]]; then
82
87
  (( overall_copied++ ))
83
88
  location_copied=1
84
89
  found_root=1
85
- (( quiet != 1 )) && echo " ✅ Copied $(basename "$env_file") from $base/"
86
- copy_env_log "INFO" "Copied $(basename "$env_file") from $base/"
90
+ (( quiet != 1 )) && echo " ✅ Copied $rel_path from $base/"
91
+ copy_env_log "INFO" "Copied $rel_path from $base/"
87
92
  else
88
93
  (( overall_failed++ ))
89
94
  (( location_failed++ ))
90
- (( quiet != 1 )) && echo " ❌ Failed to copy $(basename "$env_file") from $base/"
91
- copy_env_log "ERROR" "Failed to copy $(basename "$env_file") from $base/: ${err_msg:-unknown error}"
95
+ (( quiet != 1 )) && echo " ❌ Failed to copy $rel_path from $base/"
96
+ copy_env_log "ERROR" "Failed to copy $rel_path from $base/: ${err_msg:-unknown error}"
92
97
  fi
93
- done
98
+ done < <(find "$base" \
99
+ \( -path "$target_root" -o -path "$target_root/*" -o -path "$base/.git" -o -path "$base/.git/*" -o -path "$base/worktrees" -o -path "$base/worktrees/*" \) -prune -o \
100
+ -type f -name '.env*' -print0 2>/dev/null)
94
101
  if [[ $found_root -eq 1 ]]; then
95
102
  break
96
103
  fi
@@ -1,22 +1,10 @@
1
1
  # shellcheck shell=bash
2
2
 
3
3
  gwr_get_current_worktree_title() {
4
- local branch=""
5
4
  local worktree=""
6
5
 
7
- if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
8
- branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")"
9
- if [[ -n "$branch" && "$branch" != "HEAD" ]]; then
10
- worktree="$branch"
11
- else
12
- worktree="$(git rev-parse --short HEAD 2>/dev/null || echo "")"
13
- fi
14
- fi
15
-
16
- if [[ -z "$worktree" ]]; then
17
- worktree="$(pwd -P)"
18
- worktree="$(basename "$worktree")"
19
- fi
6
+ worktree="$(pwd -P)"
7
+ worktree="$(basename "$worktree")"
20
8
 
21
9
  worktree="${worktree//\//-}"
22
10
  worktree="${worktree// /-}"
@@ -25,5 +13,5 @@ gwr_get_current_worktree_title() {
25
13
  worktree="unknown"
26
14
  fi
27
15
 
28
- printf 'orchestra [orchestra/%s]' "$worktree"
16
+ printf 'orchestra: /%s' "$worktree"
29
17
  }
@@ -0,0 +1,54 @@
1
+ # shellcheck shell=bash
2
+
3
+ cmd_new_tmux_session_with_command() {
4
+ local branch_name="$1"
5
+ local command_line="$2"
6
+
7
+ local root; root="$(git_require_repo_root)" || return 1
8
+ local shared_root; shared_root="$(git_shared_root 2>/dev/null)"
9
+ [[ -z "$shared_root" ]] && shared_root="$root"
10
+ local source_root; source_root="$(git_current_path)"
11
+
12
+ if ! tmux_available; then
13
+ err "tmux not installed"
14
+ return 1
15
+ fi
16
+
17
+ if [[ -z "$branch_name" ]]; then
18
+ err "Branch name required"
19
+ return 1
20
+ fi
21
+
22
+ if [[ -z "${command_line// }" ]]; then
23
+ err "Command required"
24
+ return 1
25
+ fi
26
+
27
+ local wt=""
28
+ if git_branch_exists "$branch_name"; then
29
+ wt="$(git_branch_to_worktree_path "$branch_name")"
30
+ if [[ -z "$wt" ]]; then
31
+ info "🌳 Creating worktree for existing branch '$branch_name'..."
32
+ wt="$(git_ensure_worktree_for_branch "$branch_name")"
33
+ copy_env_files "$source_root" "$wt" "$shared_root"
34
+ fi
35
+ else
36
+ err "Branch '$branch_name' does not exist"
37
+ return 1
38
+ fi
39
+
40
+ if [[ -z "$wt" ]]; then
41
+ err "Worktree not found for branch '$branch_name'"
42
+ return 1
43
+ fi
44
+
45
+ local session=""
46
+ session="$(tmux_ensure_session "$branch_name" "" "$wt")" || return 1
47
+ if [[ -z "$session" ]]; then
48
+ err "Failed to create tmux session"
49
+ return 1
50
+ fi
51
+
52
+ tmux_send_keys "$session" "$command_line" || return 1
53
+ tmux_attach_session "$session"
54
+ }