-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-layout.sh
More file actions
executable file
·628 lines (541 loc) · 18.9 KB
/
Copy pathdev-layout.sh
File metadata and controls
executable file
·628 lines (541 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
#!/usr/bin/env bash
# Herdr dev layout: sticky agent pane (left 50%) + review/explorer/terminal tabs.
# shellcheck disable=SC2016
set -euo pipefail
HERDR="${HERDR_BIN_PATH:-herdr}"
STATE_VERSION=1
TABS=(review explorer terminal)
_plugin_root() {
if [[ -n "${HERDR_PLUGIN_ROOT:-}" ]]; then
printf '%s' "$HERDR_PLUGIN_ROOT"
else
cd "$(dirname "${BASH_SOURCE[0]}")" && pwd
fi
}
# shellcheck source=/dev/null
source "$(_plugin_root)/config-reader.sh"
_state_dir() {
if [[ -n "${HERDR_PLUGIN_STATE_DIR:-}" ]]; then
printf '%s' "$HERDR_PLUGIN_STATE_DIR"
return 0
fi
printf '%s' "${XDG_STATE_HOME:-${HOME}/.local/state}/herdr/plugins/agentic-dev.dev-layout"
}
_state_path() {
local workspace_id="$1"
mkdir -p "$(_state_dir)"
printf '%s/%s.json' "$(_state_dir)" "$workspace_id"
}
_agent_cmd() {
if declare -F agentic_dev_agent_command >/dev/null 2>&1; then
agentic_dev_agent_command
else
printf '%s' "agent"
fi
}
_editor() {
if declare -F agentic_dev_layout_editor >/dev/null 2>&1; then
agentic_dev_layout_editor
else
printf '%s' "${EDITOR:-nvim}"
fi
}
_herdr_json() {
"$HERDR" "$@" 2>/dev/null
}
_jq() {
jq -r "$@"
}
_tool_command() {
local tab="$1"
local editor
editor="$(_editor)"
case "$tab" in
review) printf '%s' "tuicr; exec bash -li" ;;
explorer) printf '%s' "${editor} .; exec bash -li" ;;
terminal) printf '%s' "clear; exec bash -li" ;;
*) return 1 ;;
esac
}
_focused_workspace_id() {
_herdr_json workspace list \
| _jq '.result.workspaces[] | select(.focused == true) | .workspace_id' \
| head -1
}
_workspace_id_by_label() {
local label="$1"
_herdr_json workspace list \
| _jq --arg label "$label" '.result.workspaces[] | select(.label == $label) | .workspace_id' \
| head -1
}
_workspace_id_by_cwd() {
local cwd="$1"
local ws_id pane_cwd
while IFS= read -r ws_id; do
[[ -n "$ws_id" ]] || continue
pane_cwd="$(_herdr_json pane list --workspace "$ws_id" \
| _jq '.result.panes[0].cwd // empty' \
| head -1)"
if [[ "$pane_cwd" == "$cwd" ]]; then
printf '%s' "$ws_id"
return 0
fi
done < <(_herdr_json workspace list | _jq '.result.workspaces[].workspace_id')
return 1
}
_pane_exists() {
local pane_id="$1"
[[ -n "$pane_id" ]] || return 1
_herdr_json pane get "$pane_id" >/dev/null 2>&1
}
# Serialize layout mutations per workspace. Concurrent create/apply (e.g. worktrunk
# post-start + wtc/dev attach) otherwise race and open duplicate agent panes.
_layout_lock_acquire() {
local workspace_id="$1"
local lockfile
mkdir -p "$(_state_dir)"
lockfile="$(_state_dir)/${workspace_id}.lock"
exec 9>"$lockfile"
flock 9
}
_layout_lock_release() {
flock -u 9 2>/dev/null || true
exec 9>&- 2>/dev/null || true
}
_extra_panes_on_tab() {
local workspace_id="$1" tab_id="$2" tool_pane="$3"
_herdr_json pane list --workspace "$workspace_id" \
| _jq --arg tab "$tab_id" --arg tool "$tool_pane" \
'.result.panes[] | select(.tab_id == $tab and .pane_id != $tool) | .pane_id'
}
_close_orphan_agent_panes() {
local workspace_id="$1" tab_id="$2" tool_pane="$3" keep_pane="${4:-}"
local pane_id
while IFS= read -r pane_id; do
[[ -n "$pane_id" ]] || continue
[[ "$pane_id" == "$keep_pane" ]] && continue
_herdr_json pane close "$pane_id" >/dev/null 2>&1 || true
done < <(_extra_panes_on_tab "$workspace_id" "$tab_id" "$tool_pane")
}
_state_quarantine() {
local workspace_id="$1" path="$2"
local quarantine_dir target
quarantine_dir="$(_state_dir)/quarantine"
mkdir -p "$quarantine_dir"
target="$(mktemp "$quarantine_dir/$workspace_id.json.XXXXXX")"
if ! mv "$path" "$target"; then
rm -f "$target"
return 1
fi
printf 'dev-layout: quarantined invalid state: %s\n' "$target" >&2
}
_state_probe() {
local workspace_id="$1"
local path filename_workspace_id
path="$(_state_path "$workspace_id")"
[[ -f "$path" ]] || return 1
filename_workspace_id="${path##*/}"
filename_workspace_id="${filename_workspace_id%.json}"
if jq -e \
--arg workspace_id "$filename_workspace_id" \
--argjson version "$STATE_VERSION" \
'type == "object"
and (.version | type == "number")
and .version == $version
and (.workspace_id | type == "string")
and .workspace_id == $workspace_id
and (.label | type == "string")
and (.workdir | type == "string")
and (.agent_pane_id | type == "string")
and (.active_tab | type == "string")
and (.tabs | type == "object")' \
"$path" >/dev/null 2>&1; then
cat "$path"
return 0
fi
if ! _state_quarantine "$filename_workspace_id" "$path"; then
printf 'dev-layout: unable to quarantine invalid state; removing active record: %s\n' "$path" >&2
rm -f "$path"
fi
return 1
}
_state_load() {
_state_probe "$1"
}
_state_save() {
local workspace_id="$1"
local json="$2"
printf '%s' "$json" > "$(_state_path "$workspace_id")"
}
_state_delete() {
local workspace_id="$1"
rm -f "$(_state_path "$workspace_id")"
}
_state_init() {
local workspace_id="$1" label="$2" workdir="$3"
jq -n \
--arg workspace_id "$workspace_id" \
--arg label "$label" \
--arg workdir "$workdir" \
--argjson version "$STATE_VERSION" \
'{
workspace_id: $workspace_id,
label: $label,
workdir: $workdir,
version: $version,
agent_pane_id: "",
active_tab: "review",
tabs: {}
}'
}
_state_set_tab() {
local state="$1" tab="$2" tab_id="$3" tool_pane_id="$4"
printf '%s' "$state" | jq \
--arg tab "$tab" \
--arg tab_id "$tab_id" \
--arg tool_pane_id "$tool_pane_id" \
'.tabs[$tab] = {tab_id: $tab_id, tool_pane_id: $tool_pane_id}'
}
_state_get_tab_id() {
local state="$1" tab="$2"
printf '%s' "$state" | _jq --arg tab "$tab" '.tabs[$tab].tab_id // empty'
}
_state_get_tool_pane() {
local state="$1" tab="$2"
printf '%s' "$state" | _jq --arg tab "$tab" '.tabs[$tab].tool_pane_id // empty'
}
_ensure_workspace() {
local label="$1" workdir="$2"
local workspace_id
workspace_id="$(_workspace_id_by_label "$label")"
if [[ -z "$workspace_id" ]]; then
workspace_id="$(_workspace_id_by_cwd "$workdir" 2>/dev/null || true)"
fi
if [[ -n "$workspace_id" ]]; then
_herdr_json workspace rename "$workspace_id" "$label" >/dev/null || true
_herdr_json workspace focus "$workspace_id" >/dev/null
printf '%s' "$workspace_id"
return 0
fi
workspace_id="$(_herdr_json workspace create --cwd "$workdir" --label "$label" --focus \
| _jq '.result.workspace.workspace_id')"
printf '%s' "$workspace_id"
}
_ensure_tab() {
local workspace_id="$1" tab="$2" workdir="$3" state="$4"
local tab_id tool_pane_id existing
tab_id="$(_state_get_tab_id "$state" "$tab")"
if [[ -n "$tab_id" ]]; then
tool_pane_id="$(_state_get_tool_pane "$state" "$tab")"
if _pane_exists "$tool_pane_id"; then
printf '%s\t%s' "$tab_id" "$tool_pane_id"
return 0
fi
fi
existing="$(_herdr_json tab list --workspace "$workspace_id" \
| _jq --arg tab "$tab" '.result.tabs[] | select(.label == $tab) | .tab_id' \
| head -1)"
if [[ -n "$existing" ]]; then
tool_pane_id="$(_herdr_json pane list --workspace "$workspace_id" \
| _jq --arg tab "$existing" '.result.panes[] | select(.tab_id == $tab) | .pane_id' \
| head -1)"
if _pane_exists "$tool_pane_id"; then
printf '%s\t%s' "$existing" "$tool_pane_id"
return 0
fi
fi
local create_json tool_cmd
tool_cmd="$(_tool_command "$tab")"
create_json="$(_herdr_json tab create --workspace "$workspace_id" --cwd "$workdir" --label "$tab" --no-focus)"
tab_id="$(printf '%s' "$create_json" | _jq '.result.tab.tab_id')"
tool_pane_id="$(printf '%s' "$create_json" | _jq '.result.root_pane.pane_id')"
_herdr_json pane run "$tool_pane_id" "bash -li -c $(printf '%q' "$tool_cmd")" >/dev/null || true
printf '%s\t%s' "$tab_id" "$tool_pane_id"
}
_ensure_agent_pane() {
local workspace_id="$1" workdir="$2" state="$3" tab="$4"
local agent_pane tool_pane tab_id existing
tab_id="$(_state_get_tab_id "$state" "$tab")"
tool_pane="$(_state_get_tool_pane "$state" "$tab")"
[[ -n "$tab_id" && -n "$tool_pane" ]] || return 1
agent_pane="$(printf '%s' "$state" | _jq '.agent_pane_id // empty')"
if _pane_exists "$agent_pane"; then
_close_orphan_agent_panes "$workspace_id" "$tab_id" "$tool_pane" "$agent_pane"
printf '%s' "$agent_pane"
return 0
fi
# Reclaim a leftover split from a raced create before opening another.
existing="$(_extra_panes_on_tab "$workspace_id" "$tab_id" "$tool_pane" | head -1)"
if [[ -n "$existing" ]] && _pane_exists "$existing"; then
_close_orphan_agent_panes "$workspace_id" "$tab_id" "$tool_pane" "$existing"
printf '%s' "$existing"
return 0
fi
_herdr_json tab focus "$tab_id" >/dev/null
agent_pane="$(_herdr_json pane split "$tool_pane" --direction right --ratio 0.5 --cwd "$workdir" --no-focus \
| _jq '.result.pane.pane_id')"
_herdr_json pane swap --source-pane "$agent_pane" --target-pane "$tool_pane" >/dev/null 2>&1 || true
_herdr_json pane run "$agent_pane" "$(_agent_cmd)" >/dev/null || true
printf '%s' "$agent_pane"
}
_attach_agent_to_tab() {
local state="$1" tab="$2"
local agent_pane tab_id tool_pane agent_tab
agent_pane="$(printf '%s' "$state" | _jq '.agent_pane_id // empty')"
tab_id="$(_state_get_tab_id "$state" "$tab")"
tool_pane="$(_state_get_tool_pane "$state" "$tab")"
[[ -n "$agent_pane" && -n "$tab_id" && -n "$tool_pane" ]] || return 0
_pane_exists "$agent_pane" || return 0
_pane_exists "$tool_pane" || return 0
agent_tab="$(_herdr_json pane get "$agent_pane" | _jq '.result.pane.tab_id // .result.tab_id // empty' 2>/dev/null || \
_herdr_json pane list | _jq --arg p "$agent_pane" '.result.panes[] | select(.pane_id == $p) | .tab_id')"
if [[ "$agent_tab" == "$tab_id" ]]; then
return 0
fi
_herdr_json pane move "$agent_pane" --tab "$tab_id" --split right --ratio 0.5 --target-pane "$tool_pane" --no-focus >/dev/null
_herdr_json pane swap --source-pane "$agent_pane" --target-pane "$tool_pane" >/dev/null 2>&1 || true
}
_layout_ensure() {
local label="${WT_HERDR_LABEL:-}" workdir="${WT_HERDR_WORKDIR:-}"
local workspace_id state tab tab_id tool_pane agent_pane line
if [[ -z "$label" || -z "$workdir" ]]; then
workspace_id="${HERDR_WORKSPACE_ID:-$(_focused_workspace_id)}"
[[ -n "$workspace_id" ]] || { echo "dev-layout: no workspace context" >&2; exit 1; }
state="$(_state_load "$workspace_id" 2>/dev/null || true)"
if [[ -n "$state" ]]; then
label="$(printf '%s' "$state" | _jq '.label')"
workdir="$(printf '%s' "$state" | _jq '.workdir')"
else
label="$(_herdr_json workspace get "$workspace_id" | _jq '.result.workspace.label // empty')"
workdir="$(_herdr_json pane list --workspace "$workspace_id" \
| _jq '.result.panes[0].cwd // empty' | head -1)"
workdir="${workdir:-$PWD}"
label="${label:-$workdir}"
fi
fi
workspace_id="$(_ensure_workspace "$label" "$workdir")"
_layout_lock_acquire "$workspace_id"
# shellcheck disable=SC2064
trap '_layout_lock_release' RETURN
state="$(_state_load "$workspace_id" 2>/dev/null || _state_init "$workspace_id" "$label" "$workdir")"
state="$(printf '%s' "$state" | jq --arg wid "$workspace_id" --arg label "$label" --arg workdir "$workdir" \
'.workspace_id = $wid | .label = $label | .workdir = $workdir')"
if [[ -z "$(_state_get_tab_id "$state" "review")" ]]; then
local root_tab root_pane
root_tab="$(_herdr_json workspace get "$workspace_id" | _jq '.result.workspace.active_tab_id // empty')"
root_pane="$(_herdr_json pane list --workspace "$workspace_id" \
| _jq '.result.panes[0].pane_id // empty' | head -1)"
if [[ -n "$root_tab" && -n "$root_pane" ]]; then
_herdr_json tab rename "$root_tab" review >/dev/null 2>&1 || true
_herdr_json pane run "$root_pane" "bash -li -c $(printf '%q' "$(_tool_command review)")" >/dev/null || true
state="$(_state_set_tab "$state" review "$root_tab" "$root_pane")"
fi
fi
for tab in "${TABS[@]}"; do
if [[ "$tab" == "review" && -n "$(_state_get_tab_id "$state" "review")" ]]; then
continue
fi
line="$(_ensure_tab "$workspace_id" "$tab" "$workdir" "$state")"
tab_id="${line%%$'\t'*}"
tool_pane="${line#*$'\t'}"
state="$(_state_set_tab "$state" "$tab" "$tab_id" "$tool_pane")"
done
agent_pane="$(_ensure_agent_pane "$workspace_id" "$workdir" "$state" "review")"
state="$(printf '%s' "$state" | jq --arg agent "$agent_pane" '.agent_pane_id = $agent')"
_state_save "$workspace_id" "$state"
printf '%s' "$state"
}
_dev_workspace_id() {
if [[ -n "${HERDR_WORKSPACE_ID:-}" ]]; then
printf '%s' "$HERDR_WORKSPACE_ID"
return 0
fi
_focused_workspace_id
}
_dev_state() {
local workspace_id
workspace_id="$(_dev_workspace_id)"
[[ -n "$workspace_id" ]] || return 1
_state_probe "$workspace_id"
}
_select_tab() {
local tab="$1"
local state workspace_id tab_id
state="$(_dev_state)" || return 0
workspace_id="$(printf '%s' "$state" | _jq '.workspace_id')"
tab_id="$(_state_get_tab_id "$state" "$tab")"
[[ -n "$tab_id" ]] || return 0
_attach_agent_to_tab "$state" "$tab"
_herdr_json tab focus "$tab_id" >/dev/null
if [[ "$tab" != "agent" ]]; then
_herdr_json pane focus --direction right >/dev/null 2>&1 || true
fi
state="$(printf '%s' "$state" | jq --arg tab "$tab" '.active_tab = $tab')"
_state_save "$workspace_id" "$state"
}
_focus_agent() {
local state workspace_id tab agent_pane tab_id
state="$(_dev_state)" || return 0
workspace_id="$(printf '%s' "$state" | _jq '.workspace_id')"
tab="$(printf '%s' "$state" | _jq '.active_tab // "review"')"
agent_pane="$(printf '%s' "$state" | _jq '.agent_pane_id // empty')"
tab_id="$(_state_get_tab_id "$state" "$tab")"
if ! _pane_exists "$agent_pane"; then
local workdir
workdir="$(printf '%s' "$state" | _jq '.workdir')"
agent_pane="$(_ensure_agent_pane "$workspace_id" "$workdir" "$state" "$tab" 2>/dev/null || true)"
if [[ -n "$agent_pane" ]]; then
state="$(printf '%s' "$state" | jq --arg agent "$agent_pane" '.agent_pane_id = $agent')"
_state_save "$workspace_id" "$state"
fi
else
_attach_agent_to_tab "$state" "$tab"
fi
[[ -z "$tab_id" ]] || _herdr_json tab focus "$tab_id" >/dev/null
if _pane_exists "$agent_pane"; then
_herdr_json agent focus "$agent_pane" >/dev/null 2>&1 \
|| _herdr_json pane focus --direction left >/dev/null 2>&1 \
|| true
fi
}
_select_tab_index() {
local index="$1" semantic="$2"
local workspace_id tab_id
if _dev_state >/dev/null 2>&1; then
_select_tab "$semantic"
return 0
fi
workspace_id="$(_dev_workspace_id)"
[[ -n "$workspace_id" ]] || return 0
tab_id="$(_herdr_json tab list --workspace "$workspace_id" \
| _jq --argjson index "$index" '.result.tabs[$index].tab_id // empty')"
[[ -n "$tab_id" ]] || return 0
_herdr_json tab focus "$tab_id" >/dev/null
}
_workspace_is_live() {
local workspace_id="$1"
local list_json found
list_json="$(_herdr_json workspace list)" || return 2
found="$(printf '%s' "$list_json" | _jq --arg id "$workspace_id" \
'.result.workspaces[]? | select(.workspace_id == $id) | .workspace_id' \
| head -1)" || return 2
[[ -n "$found" ]]
}
_reconcile_live_state() {
local state="$1"
local agent_pane tab tool_pane next
next="$state"
agent_pane="$(printf '%s' "$next" | _jq '.agent_pane_id // empty')"
if [[ -n "$agent_pane" ]] && ! _pane_exists "$agent_pane"; then
next="$(printf '%s' "$next" | jq '.agent_pane_id = ""')"
fi
for tab in "${TABS[@]}"; do
tool_pane="$(_state_get_tool_pane "$next" "$tab")"
if [[ -n "$tool_pane" ]] && ! _pane_exists "$tool_pane"; then
next="$(printf '%s' "$next" | jq --arg tab "$tab" \
'if (.tabs[$tab] | type) == "object" then .tabs[$tab].tool_pane_id = "" else . end')"
fi
done
printf '%s' "$next"
}
_on_startup() {
local state_dir path workspace_id state reconciled live_status
state_dir="$(_state_dir)"
[[ -d "$state_dir" ]] || return 0
shopt -s nullglob
for path in "$state_dir"/*.json; do
[[ -f "$path" ]] || continue
workspace_id="${path##*/}"
workspace_id="${workspace_id%.json}"
state="$(_state_probe "$workspace_id" 2>/dev/null || true)"
[[ -n "$state" ]] || continue
live_status=0
_workspace_is_live "$workspace_id" || live_status=$?
if [[ "$live_status" -eq 1 ]]; then
_state_delete "$workspace_id"
continue
fi
if [[ "$live_status" -ne 0 ]]; then
# Workspace list failed: preserve state rather than delete.
continue
fi
reconciled="$(_reconcile_live_state "$state")"
if [[ "$reconciled" != "$state" ]]; then
_state_save "$workspace_id" "$reconciled"
fi
done
shopt -u nullglob
}
_on_pane_exited() {
local pane_id="${1:-}"
local workspace_id state agent_pane
[[ -n "$pane_id" ]] || return 0
for path in "$(_state_dir)"/*.json; do
[[ -f "$path" ]] || continue
state="$(cat "$path")"
agent_pane="$(printf '%s' "$state" | _jq '.agent_pane_id // empty')"
if [[ "$agent_pane" == "$pane_id" ]]; then
workspace_id="$(printf '%s' "$state" | _jq '.workspace_id')"
state="$(printf '%s' "$state" | jq '.agent_pane_id = ""')"
_state_save "$workspace_id" "$state"
fi
done
}
_on_workspace_closed() {
local workspace_id="${1:-}"
[[ -n "$workspace_id" ]] || return 0
_state_delete "$workspace_id"
}
_resolve_context() {
if [[ -n "${WT_HERDR_LABEL:-}" && -n "${WT_HERDR_WORKDIR:-}" ]]; then
return 0
fi
if [[ -n "${HERDR_WORKSPACE_ID:-}" ]]; then
return 0
fi
local focused
focused="$(_focused_workspace_id)"
[[ -n "$focused" ]] && export HERDR_WORKSPACE_ID="$focused"
}
main() {
local cmd="${1:-}"
[[ -n "$cmd" ]] || cmd="${HERDR_PLUGIN_ACTION_ID:-}"
[[ -n "$cmd" ]] || cmd="${HERDR_PLUGIN_EVENT:-}"
case "$cmd" in
create|apply)
_resolve_context
_layout_ensure >/dev/null
_select_tab review
;;
startup)
_on_startup
;;
focus_agent)
_resolve_context
_focus_agent
;;
select_review) _resolve_context; _select_tab review ;;
select_explorer) _resolve_context; _select_tab explorer ;;
select_terminal) _resolve_context; _select_tab terminal ;;
alt_review) _resolve_context; _select_tab_index 0 review ;;
alt_explorer) _resolve_context; _select_tab_index 1 explorer ;;
alt_terminal) _resolve_context; _select_tab_index 2 terminal ;;
event_pane_exited|pane.exited)
local pane_id
pane_id="$(printf '%s' "${HERDR_PLUGIN_EVENT_JSON:-{}}" | _jq '.pane_id // .pane.pane_id // empty' 2>/dev/null || true)"
_on_pane_exited "$pane_id"
;;
event_workspace_closed|workspace.closed)
local workspace_id
workspace_id="$(printf '%s' "${HERDR_PLUGIN_EVENT_JSON:-{}}" | _jq '.workspace_id // .workspace.workspace_id // empty' 2>/dev/null || true)"
_on_workspace_closed "$workspace_id"
;;
*)
echo "dev-layout: unknown command '$cmd'" >&2
exit 1
;;
esac
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi