@sassywares/skills 0.11.22 → 0.12.0

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.
Files changed (35) hide show
  1. package/CONCEPTS.md +32 -18
  2. package/README.md +33 -24
  3. package/package.json +1 -1
  4. package/skills/sassy-lfg/SKILL.md +1 -1
  5. package/skills/sassy-overview/SKILL.md +52 -0
  6. package/skills/sassy-overview/references/identify.md +82 -0
  7. package/skills/sassy-overview/scripts/identify.sh +83 -0
  8. package/skills/sassy-overview/scripts/lib.sh +334 -0
  9. package/skills/sassy-setup/SKILL.md +8 -8
  10. package/skills/sassy-setup/assets/dogfood-recipe.md +1 -1
  11. package/skills/sassy-setup/assets/lifecycle/down +29 -0
  12. package/skills/sassy-setup/assets/lifecycle/up +34 -0
  13. package/skills/sassy-setup/assets/roster +1 -0
  14. package/skills/sassy-setup/assets/sassywares-readme.md +5 -4
  15. package/skills/sassy-setup/assets/worktree/_lib.sh +52 -213
  16. package/skills/sassy-setup/assets/worktree/create +18 -33
  17. package/skills/sassy-setup/assets/worktree/list +20 -54
  18. package/skills/sassy-setup/assets/worktree/prune +13 -9
  19. package/skills/sassy-setup/assets/worktree/remove +83 -26
  20. package/skills/sassy-setup/references/config.md +99 -17
  21. package/skills/sassy-setup/references/dogfood.md +11 -17
  22. package/skills/sassy-setup/references/init.md +18 -4
  23. package/skills/sassy-setup/references/workspace.md +27 -34
  24. package/skills/sassy-setup/references/worktree.md +66 -75
  25. package/skills/sassy-setup/scripts/detect.sh +112 -103
  26. package/skills/sassy-setup/scripts/hash-skill.mjs +31 -18
  27. package/skills/sassy-setup/scripts/worktree-check.mjs +89 -0
  28. package/skills/sassy-work/SKILL.md +1 -1
  29. package/skills/sassy-worktree/SKILL.md +17 -21
  30. package/skills/sassy-worktree/references/create.md +3 -3
  31. package/skills/sassy-worktree/references/list.md +2 -2
  32. package/skills/sassy-worktree/references/prune.md +4 -4
  33. package/skills/sassy-worktree/references/remove.md +8 -6
  34. package/skills/sassy-setup/assets/worktree/stop +0 -65
  35. package/skills/sassy-worktree/references/preview.md +0 -17
@@ -1,27 +1,35 @@
1
1
  #!/usr/bin/env bash
2
- # Shared helpers for the worktree scripts: create, list, stop, remove, prune.
2
+ # Shared helpers for the worktree scripts: create, list, remove, prune.
3
3
  #
4
- # Installed next to those scripts by sassy-setup, and owned by this project from
5
- # then on — extend it here rather than forking a copy. Three rules worth keeping:
4
+ # Installed next to those scripts by sassy-setup. Suite-owned and read-only, so
5
+ # every project runs the same mechanics. Three rules worth keeping:
6
6
  #
7
- # 1. The worktree home, the port range, and the on/off switch come from
8
- # `worktrees:` in .sassywares/config.yaml. Never grow a second source.
9
- # 2. A port is claimed, never assumed. The claim directory is the lock.
7
+ # 1. Two config sources, each with exactly one owner. The worktree home and the
8
+ # on/off switch live under `worktrees:` in .sassywares/config.yaml; the stack
9
+ # life cycle is the top-level `down:`/`up:`. Never duplicate either one into
10
+ # the other block, and never grow a third source.
11
+ # 2. Identity is derived here once — never built by hand downstream.
10
12
  # 3. Everything resolves against the MAIN checkout, so running any of these
11
13
  # from inside a worktree behaves identically.
12
14
  #
13
- # worktree-version: 8
15
+ # worktree-version: 12
14
16
 
15
17
  set -euo pipefail
16
18
 
17
- WT_VERSION="8"
19
+ WT_VERSION="12"
18
20
  WT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
21
 
20
22
  log() { printf '%s\n' "$*"; }
21
23
  ok() { printf ' %-9s %s\n' "$1" "$2"; }
22
- warn() { printf ' %-9s %s\n' "!" "$2" >&2; }
24
+ warn() { printf ' %-9s %s\n' "!" "$*" >&2; }
23
25
  die() { printf ' ✗ %s\n' "$*" >&2; exit 1; }
24
26
  hint() { printf ' %-9s %s\n' "→" "$*"; }
27
+ # The exit-3 handshake: something the script cannot dispatch is still owed, and
28
+ # the caller has to run it before re-invoking with --hook-ok.
29
+ require_dispatch() {
30
+ hint "$1" >&2
31
+ exit 3
32
+ }
25
33
 
26
34
  # The nearest config, walking up from the cwd — used only to explain a refusal
27
35
  # when there is no repo to work in at all.
@@ -88,15 +96,45 @@ wt_flat() {
88
96
  }' "${1:-${CONFIG:-/dev/null}}" 2>/dev/null
89
97
  }
90
98
 
99
+ # wt_get PATH — the value of one flattened config path, or empty. The one lookup
100
+ # every reader uses, so a nested map has exactly one interpretation.
101
+ wt_get() {
102
+ wt_flat | awk -F'\t' -v p="$1" '$1 == p { print $2; exit }'
103
+ }
104
+
91
105
  # wt_cfg KEY DEFAULT — a dotted path under the `worktrees:` block.
92
106
  wt_cfg() {
93
107
  local v
94
- v="$(wt_flat | awk -F'\t' -v p="worktrees${WLIB_US}$1" '$1 == p { print $2; exit }')"
108
+ v="$(wt_get "worktrees${WLIB_US}$1")"
95
109
  printf '%s' "${v:-$2}"
96
110
  }
97
111
 
98
112
  wt_enabled() { [ "$(wt_cfg enabled false)" = "true" ]; }
99
113
 
114
+ # wt_down — the top-level `down:` entry, exactly as written, or empty when the
115
+ # project declares no lifecycle. Top-level by design (never under `worktrees:`).
116
+ wt_down() { wt_get down; }
117
+
118
+ # wt_resolve VALUE CHECKOUT — how to run one top-level life-cycle value, as
119
+ # `<run|skill|missing|none><TAB><command><TAB><args…>`. `run` means the command
120
+ # exists — a path in the checkout, an absolute path, or a word on PATH — so a
121
+ # shell script can execute it; `skill` means nothing on disk claims the word, so
122
+ # only an agent can dispatch it; `missing` means the value is path-shaped but no
123
+ # such executable exists; `none` means the value is empty. Args are command
124
+ # words, not patterns: callers disable globbing before expanding them.
125
+ wt_resolve() {
126
+ local value="${1:-}" checkout="${2:-}" cmd="" args="" how=skill
127
+ [ -n "$value" ] || { printf 'none\t\t'; return 0; }
128
+ cmd="${value%% *}"
129
+ case "$value" in *" "*) args="${value#* }" ;; esac
130
+ case "$cmd" in
131
+ /*) if [ -f "$cmd" ] && [ -x "$cmd" ]; then how=run; else how=missing; fi ;;
132
+ */*) if [ -f "$checkout/$cmd" ] && [ -x "$checkout/$cmd" ]; then how=run; else how=missing; fi ;;
133
+ *) command -v "$cmd" >/dev/null 2>&1 && how=run ;;
134
+ esac
135
+ printf '%s\t%s\t%s' "$how" "$cmd" "$args"
136
+ }
137
+
100
138
  # A list value (`[a b]`) split one per line.
101
139
  wt_list_items() {
102
140
  printf '%s' "$1" | sed -e 's/^\[//' -e 's/\]$//' | tr ',' '\n' \
@@ -107,9 +145,9 @@ wt_list_items() {
107
145
  # The first match wins, so `hooks.worktree."*"` applies when no branch matches.
108
146
  wt_hook() { # $1 point (after_create|before_remove), $2 branch — one entry per line
109
147
  local point="$1" branch="$2" v=""
110
- v="$(wt_flat | awk -F'\t' -v b="$branch" -v p="hooks${WLIB_US}worktree${WLIB_US}${branch}${WLIB_US}${point}" '$1 == p { print $2; exit }')"
148
+ v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}${branch}${WLIB_US}${point}")"
111
149
  if [ -z "$v" ]; then
112
- v="$(wt_flat | awk -F'\t' -v p="hooks${WLIB_US}worktree${WLIB_US}*${WLIB_US}${point}" '$1 == p { print $2; exit }')"
150
+ v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}*${WLIB_US}${point}")"
113
151
  fi
114
152
  wt_list_items "$v"
115
153
  }
@@ -137,7 +175,7 @@ wt_home() {
137
175
  *) dir="$MAIN/$dir" ;;
138
176
  esac
139
177
  # Resolve through the parent, so /tmp and /private/tmp never disagree and the
140
- # paths match what `git worktree list` reports.
178
+ # paths match what `git worktree list` prints.
141
179
  parent="$(dirname "$dir")"
142
180
  [ -d "$parent" ] && dir="$(cd "$parent" && pwd -P)/$(basename "$dir")"
143
181
  base="$(basename "$MAIN")"
@@ -155,43 +193,7 @@ wt_home() {
155
193
 
156
194
  wt_path() { printf '%s/%s' "$(wt_home)" "$1"; }
157
195
 
158
- # --- resources ------------------------------------------------------------
159
- # A port is one resource a checkout may need, not the definition of a preview. A
160
- # mobile app claims a simulator, a desktop app nothing, and both are legitimate:
161
- # when `worktrees.ports` is absent nothing is derived and nothing is claimed.
162
- wt_has_ports() { [ -n "$(wt_cfg ports '')" ]; }
163
-
164
- wt_range() {
165
- local r lo hi
166
- r="$(wt_cfg ports '')"
167
- [ -n "$r" ] || return 0
168
- case "$r" in
169
- *-*) lo="${r%%-*}"; hi="${r##*-}" ;;
170
- *) lo="$r"; hi="$r" ;;
171
- esac
172
- case "$lo$hi" in *[!0-9]*) die "worktrees.ports '$r' is not <from>-<to>" ;; esac
173
- [ "$lo" -le "$hi" ] || die "worktrees.ports '$r' has an empty range"
174
- printf '%s %s' "$lo" "$hi"
175
- }
176
-
177
- # tcp_up PORT — 0 when something accepts a connection on loopback.
178
- # Liveness is observed, never read from a state file: a killed preview leaves no
179
- # trace to go stale. The probe runs in a subshell so a successful connect cannot
180
- # leave a descriptor (or a fatal `exec`) behind in the caller.
181
- tcp_up() {
182
- local port="$1"
183
- # IPv4, then IPv6: a dev server that binds `[::1]` only is up, and an IPv4-only
184
- # probe reads it as down — which would make `LIVE` lie and `remove`'s
185
- # live-preview refusal unreachable.
186
- if (exec 3<>"/dev/tcp/127.0.0.1/$port") >/dev/null 2>&1; then return 0; fi
187
- if (exec 3<>"/dev/tcp/::1/$port") >/dev/null 2>&1; then return 0; fi
188
- # Last resort for a listener /dev/tcp cannot reach.
189
- if command -v lsof >/dev/null 2>&1 && lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1; then
190
- return 0
191
- fi
192
- return 1
193
- }
194
-
196
+ # --- display --------------------------------------------------------------
195
197
  # short_path PATH WIDTH — keep the tail of a long path, because the tail holds the
196
198
  # slug and the start is always the same worktree home.
197
199
  short_path() {
@@ -199,64 +201,6 @@ short_path() {
199
201
  if [ "${#s}" -gt "$w" ]; then printf '…%s' "${s: -$(( w - 1 ))}"; else printf '%s' "$s"; fi
200
202
  }
201
203
 
202
- wt_claim_dir() { printf '%s/ports/%s' "$(wt_home)" "$1"; }
203
-
204
- # wt_owner PORT — the slug that claimed a port, or empty.
205
- wt_owner() {
206
- local f
207
- f="$(wt_claim_dir "$1")/owner"
208
- [ -f "$f" ] && cat "$f" 2>/dev/null || true
209
- }
210
-
211
- # wt_claim SLUG — print the port this slug owns, claiming one when needed.
212
- # Deterministic first (a restarted preview comes back on the same port), then a
213
- # linear probe so two slugs that hash alike do not fight.
214
- # wt_port_for SLUG — the port this slug uses: an existing claim, else the derived
215
- # one probed forward past claims held by others. Read-only, so `list` may call it.
216
- wt_port_for() {
217
- local slug="$1" lo hi span i port owner hex d
218
- wt_has_ports || return 0
219
- read -r lo hi <<<"$(wt_range)"
220
- for d in "$(wt_home)/ports"/*; do
221
- [ -d "$d" ] || continue
222
- if [ "$(cat "$d/owner" 2>/dev/null)" = "$slug" ]; then
223
- basename "$d"
224
- return 0
225
- fi
226
- done
227
- span=$(( hi - lo + 1 ))
228
- hex="$(printf '%s' "$slug" | shasum -a 256 | cut -c1-8)"
229
- i=$(( 16#$hex % span ))
230
- port=$(( lo + i ))
231
- while :; do
232
- owner="$(wt_owner "$port")"
233
- if [ -z "$owner" ] || [ "$owner" = "$slug" ]; then
234
- printf '%s' "$port"
235
- return 0
236
- fi
237
- port=$(( port + 1 ))
238
- [ "$port" -gt "$hi" ] && port=$lo
239
- i=$(( i + 1 ))
240
- [ "$i" -gt "$span" ] && die "no free port in $(wt_range | sed 's/ /-/')"
241
- done
242
- }
243
-
244
- # wt_claim SLUG — claim and print the port, writing the lock directory.
245
- wt_claim() {
246
- local slug="$1" port
247
- port="$(wt_port_for "$slug")"
248
- mkdir -p "$(wt_claim_dir "$port")"
249
- printf '%s' "$slug" > "$(wt_claim_dir "$port")/owner"
250
- printf '%s' "$port"
251
- }
252
-
253
- wt_release() { # $1 port, $2 slug
254
- local d
255
- d="$(wt_claim_dir "$1")"
256
- [ "$(wt_owner "$1")" = "$2" ] && rm -rf "$d"
257
- return 0
258
- }
259
-
260
204
  # --- checkouts ------------------------------------------------------------
261
205
  # Emits one record per worktree: path<TAB>branch.
262
206
  wt_all() {
@@ -340,108 +284,3 @@ wt_upstream_state() { # merged | gone | unmerged
340
284
  printf 'unmerged'
341
285
  fi
342
286
  }
343
-
344
- # wt_subst LINE NAME VALUE — expand `$NAME`, `${NAME}` and `${NAME:-default}` for
345
- # one variable. No name here is a prefix of another, so a plain replace is exact.
346
- wt_subst() {
347
- local line="$1" name="$2" val="$3"
348
- if [ -n "$val" ]; then
349
- printf '%s' "$line" \
350
- | sed -e "s|\${$name:-[^}]*}|$val|g" -e "s|\${$name}|$val|g" -e "s|\$$name|$val|g"
351
- else
352
- printf '%s' "$line" \
353
- | sed -e "s|\${$name:-\([^}]*\)}|\1|g" -e "s|\${$name}||g" -e "s|\$$name||g"
354
- fi
355
- }
356
-
357
- # _wt_preview_block RECIPE [SECTION] — the `**Preview:**` block, joined to one line.
358
- # With no section it reads only what sits *before* the first `## ` heading, so a
359
- # nested recipe's first app cannot masquerade as the file-level address.
360
- _wt_preview_block() {
361
- awk -v want="${2:-}" '
362
- /^## / {
363
- if (want == "") exit
364
- s = $0; sub(/^## +/, "", s); split(s, pr, /[ \t]+/); cur = pr[1]; inb = 0; next
365
- }
366
- want != "" && cur != want { next }
367
- /^\*\*Preview:\*\*/ { sub(/^\*\*Preview:\*\*[[:space:]]*/, ""); buf = $0; inb = 1; next }
368
- inb && /^[[:space:]]*$/ { inb = 0; next }
369
- inb && /^\*\*/ { inb = 0; next }
370
- inb { buf = buf " " $0 }
371
- END { printf "%s", buf }
372
- ' "$1" | sed -E 's/[[:space:]]+/ /g; s/[[:space:]]+$//'
373
- }
374
-
375
- # wt_preview SLUG [SECTION] — how to see this checkout, substituted.
376
- # A section's own line wins when one is asked for; otherwise the file-level line is
377
- # the checkout's address. With no file-level line and exactly one section, that
378
- # section is the answer; with several, nothing is returned rather than guessing which
379
- # app a checkout is serving.
380
- wt_preview() {
381
- local slug="$1" sect="${2:-}" recipe line="" cand count sl port base
382
- recipe="$(wt_flat | awk -F'\t' -v p="dogfood${WLIB_US}recipe" '$1 == p { print $2; exit }')"
383
- recipe="${recipe:-.sassywares/dogfood/recipe.md}"
384
- case "$recipe" in /*) ;; *) recipe="$MAIN/$recipe" ;; esac
385
- [ -f "$recipe" ] || return 0
386
- if [ -n "$sect" ]; then line="$(_wt_preview_block "$recipe" "$sect")"; fi
387
- if [ -z "$line" ]; then line="$(_wt_preview_block "$recipe" "")"; fi
388
- if [ -z "$line" ]; then
389
- # Fall back to the single section that *declares* an address. Counting sections
390
- # would fail on a recipe with one app and one uncovered surface, which is a
391
- # perfectly ordinary shape: only the app has somewhere to look.
392
- count=0; cand=""
393
- while IFS= read -r sl; do
394
- [ -n "$sl" ] || continue
395
- cand="$(_wt_preview_block "$recipe" "$sl")"
396
- [ -n "$cand" ] || continue
397
- count=$((count + 1))
398
- line="$cand"
399
- done < <(sed -n 's/^## \([^ ]*\).*/\1/p' "$recipe")
400
- [ "$count" -eq 1 ] || line=""
401
- fi
402
- [ -n "$line" ] || return 0
403
- port=""
404
- if wt_has_ports; then
405
- port="$(wt_port_for "$slug")"
406
- base="http://localhost:$port"
407
- fi
408
- line="$(wt_subst "$line" WT_SLUG "$slug")"
409
- line="$(wt_subst "$line" WT_NAMESPACE "$(wt_namespace "$slug")")"
410
- line="$(wt_subst "$line" WT_PATH "$(wt_path "$slug")")"
411
- line="$(wt_subst "$line" WT_PORT "$port")"
412
- line="$(wt_subst "$line" WT_BASE_URL "$base")"
413
- printf '%s' "$line"
414
- }
415
-
416
- # wt_preview_port SLUG — the port the preview line advertises, if it names one.
417
- # A project with no `worktrees.ports` still has an address; this is how the tools
418
- # find it without assuming a browser or a claim.
419
- wt_preview_port() {
420
- local line
421
- line="$(wt_preview "$1")"
422
- [ -n "$line" ] || return 0
423
- printf '%s' "$line" \
424
- | grep -oE '(localhost|127\.0\.0\.1):[0-9]+' | head -n 1 | grep -oE '[0-9]+$'
425
- }
426
-
427
- # wt_live_port SLUG — where to probe this checkout: its claim if it has one, else
428
- # the port its preview advertises. Empty means "nothing to probe here".
429
- wt_live_port() {
430
- local slug="$1" p
431
- if wt_has_ports; then
432
- p="$(wt_port_for "$slug")"
433
- [ -n "$p" ] && { printf '%s' "$p"; return 0; }
434
- fi
435
- wt_preview_port "$slug"
436
- }
437
-
438
- # Newest dogfood verdict for a checkout, as `status class` — or empty.
439
- wt_verdict() {
440
- local dir="$1/.sassywares/dogfood/reports" newest s c
441
- [ -d "$dir" ] || return 0
442
- newest="$(ls -1t "$dir" 2>/dev/null | head -n 1)"
443
- [ -n "$newest" ] || return 0
444
- s="$(sed -n 's/^\*\*status:\*\* //p' "$dir/$newest/summary.md" 2>/dev/null | head -n 1)"
445
- c="$(sed -n 's/^\*\*class:\*\* //p' "$dir/$newest/summary.md" 2>/dev/null | head -n 1)"
446
- printf '%s%s' "${s:-unknown}" "$( [ -n "$c" ] && printf ' %s' "$c" )"
447
- }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- # Add a worktree for one branch and claim its port.
2
+ # Add a worktree for one branch.
3
3
  #
4
- # Idempotent: a branch already in a worktree of ours is reported, not recreated,
4
+ # Idempotent: a branch already in a worktree of ours is shown, not recreated,
5
5
  # and nobody else's checkout holding it is a stop rather than a clobber.
6
6
  #
7
7
  # Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
@@ -16,9 +16,8 @@ usage() {
16
16
  cat <<'EOF'
17
17
  Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
18
18
 
19
- Create (or report) the worktree for <branch>, claim its port, and print the
20
- namespace a run inherits: WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE, WT_PORT,
21
- WT_BASE_URL.
19
+ Create (or find) the worktree for <branch> and print the namespace a run
20
+ inherits: WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE.
22
21
 
23
22
  --from <ref> where a new branch is cut from (default HEAD). A caller that has
24
23
  already resolved the base passes it; this script never guesses.
@@ -49,46 +48,31 @@ wt_enabled || die "worktrees are off here — set worktrees.enabled: true in .sa
49
48
  slug="$(wt_slug "$branch")"
50
49
  path="$(wt_path "$slug")"
51
50
 
52
- report() { # $1 path, $2 branch
53
- local port="" addr="" ns
51
+ show() { # $1 path
52
+ local ns
54
53
  ns="$(wt_namespace "$slug")"
55
- # A port is a resource this project asked for, not a property of a checkout.
56
- if wt_has_ports; then
57
- port="$(wt_claim "$slug")"
58
- addr="http://localhost:$port"
59
- fi
60
54
  if [ "$env_only" -eq 1 ]; then
61
- printf 'WT_PATH=%s\nWT_BRANCH=%s\nWT_SLUG=%s\nWT_NAMESPACE=%s\n' "$1" "$2" "$slug" "$ns"
62
- [ -n "$port" ] && printf 'WT_PORT=%s\nWT_BASE_URL=%s\n' "$port" "$addr"
55
+ printf 'WT_PATH=%s\nWT_BRANCH=%s\nWT_SLUG=%s\nWT_NAMESPACE=%s\n' "$1" "$branch" "$slug" "$ns"
63
56
  return 0
64
57
  fi
65
58
  ok worktree "$1"
66
- ok branch "$2"
59
+ ok branch "$branch"
67
60
  # Say the tracking out loud. A branch cut from a remote-tracking ref used to
68
61
  # inherit it as its upstream, so a plain push aimed at the base; and a branch
69
62
  # that tracks something other than its own name is the state that made that
70
- # invisible. `create` never sets a base — it reports what it found.
63
+ # invisible. `create` never sets a base — it shows what it found.
71
64
  local up
72
65
  up="$(wt_upstream "$1")"
73
66
  ok upstream "${up:-none}"
74
- [ -z "$up" ] || [ "${up#*/}" = "$2" ] \
75
- || warn upstream "this branch tracks '$up', not '$2' — a plain 'git push' lands there"
67
+ [ -z "$up" ] || [ "${up#*/}" = "$branch" ] \
68
+ || warn upstream "this branch tracks '$up', not '$branch' — a plain 'git push' lands there"
76
69
  ok namespace "$ns"
77
- if [ -n "$port" ]; then
78
- ok port "$port"
79
- ok address "$addr"
80
- else
81
- ok port "none — worktrees.ports is unset, so this checkout holds no port"
82
- fi
83
- local preview
84
- preview="$(wt_preview "$slug")"
85
- [ -n "$preview" ] && ok preview "$preview"
86
70
  # A branch cut from a ref that predates setup has no config and no tooling, so
87
71
  # this checkout is not managed here: `list` skips it, `prune` leaves it alone.
88
72
  [ -f "$1/.sassywares/config.yaml" ] \
89
73
  || ok unmanaged "this branch has no .sassywares/config.yaml — cut from a ref that predates setup; list and prune will skip it"
90
74
  local hooks n
91
- hooks="$(wt_hook after_create "$2")"
75
+ hooks="$(wt_hook after_create "$branch")"
92
76
  if [ -z "$hooks" ]; then
93
77
  ok hook "hooks.worktree.after_create — none declared"
94
78
  else
@@ -99,7 +83,7 @@ report() { # $1 path, $2 branch
99
83
  fi
100
84
  }
101
85
 
102
- # Already in a worktree of ours: report and stop. This is the second call in a
86
+ # Already in a worktree of ours: show it and stop. This is the second call in a
103
87
  # resumed run, and it must not fail.
104
88
  existing="$(wt_find "$branch" || true)"
105
89
  if [ -n "$existing" ]; then
@@ -107,7 +91,7 @@ if [ -n "$existing" ]; then
107
91
  if wt_is_main "$epath"; then
108
92
  die "'$branch' is checked out in the main checkout — leave it, or switch the main checkout first"
109
93
  fi
110
- report "$epath" "$branch"
94
+ show "$epath"
111
95
  exit 0
112
96
  fi
113
97
 
@@ -115,8 +99,9 @@ if [ -e "$path" ]; then
115
99
  die "'$path' exists but no worktree is registered for '$branch' — inspect it, then prune"
116
100
  fi
117
101
 
118
- (umask 077; mkdir -p "$(wt_home)/ports")
119
- printf '%s\n' "$MAIN" > "$(wt_home)/.repo"
102
+ home="$(wt_home)"
103
+ (umask 077; mkdir -p "$home")
104
+ printf '%s\n' "$MAIN" > "$home/.repo"
120
105
 
121
106
  if git show-ref --verify --quiet "refs/heads/$branch"; then
122
107
  git worktree add --quiet "$path" "$branch"
@@ -127,4 +112,4 @@ else
127
112
  git worktree add --quiet --no-track -b "$branch" "$path" "$from"
128
113
  fi
129
114
 
130
- report "$path" "$branch"
115
+ show "$path"
@@ -1,11 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Show every worktree of this repo: branch, path, address, whether anything is
3
- # listening there, and the last dogfood verdict.
2
+ # Show every worktree of this repo: branch, path, whether its tree is dirty, and
3
+ # the upstream it tracks.
4
4
  #
5
- # Liveness is probed, never read from a pid file — a killed preview leaves no
6
- # stale entry to believe.
7
- #
8
- # Usage: .sassywares/worktree/list [--address <slug>] [--path <slug>] [--version]
5
+ # Usage: .sassywares/worktree/list [--path <slug>] [--version]
9
6
  set -euo pipefail
10
7
 
11
8
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -14,21 +11,20 @@ source "$SCRIPT_DIR/_lib.sh"
14
11
 
15
12
  usage() {
16
13
  cat <<'EOF'
17
- Usage: .sassywares/worktree/list [--address <slug>] [--path <slug>]
14
+ Usage: .sassywares/worktree/list [--path <slug>]
18
15
 
19
- Print every worktree with its address and last verdict.
16
+ Print every worktree with its branch, path, dirty state, and upstream.
20
17
 
21
- --address <slug> print only the base URL of one worktree
22
- --path <slug> print only the path of one worktree (for cd "$(...)")
18
+ --path <slug> print only the path of one worktree (for cd "$(...)")
23
19
  EOF
24
20
  }
25
21
 
26
- want="" kind=""
22
+ want=""
27
23
  while [ $# -gt 0 ]; do
28
24
  case "$1" in
29
25
  -h|--help) usage; exit 0 ;;
30
26
  --version) printf '%s\n' "$WT_VERSION"; exit 0 ;;
31
- --address|--path|--preview) kind="${1#--}"; shift; want="${1:-}"; [ -n "$want" ] || die "$kind needs a slug" ;;
27
+ --path) shift; want="${1:-}"; [ -n "$want" ] || die "path needs a slug" ;;
32
28
  -*) die "unknown flag: $1 (try --help)" ;;
33
29
  *) die "unexpected argument: $1 (try --help)" ;;
34
30
  esac
@@ -37,62 +33,32 @@ done
37
33
 
38
34
  need_git
39
35
 
40
- one() { # $1 path, $2 branch
41
- local p="$1" b="$2" slug port line
42
- slug="$(wt_slug "$b")"
43
- if wt_is_main "$p"; then
44
- die "the main checkout is not a worktree — read the recipe's preview line for its address"
45
- fi
46
- case "$kind" in
47
- path) printf '%s\n' "$p" ;;
48
- address)
49
- # A claimed port, or the one the recipe's preview line advertises.
50
- port="$(wt_live_port "$slug")"
51
- [ -n "$port" ] || die "no address here — worktrees.ports is unset and the preview line names no port; try --preview"
52
- printf 'http://localhost:%s\n' "$port"
53
- ;;
54
- preview)
55
- line="$(wt_preview "$slug")"
56
- [ -n "$line" ] || die "no preview line for '$slug' — add one to dogfood.recipe"
57
- printf '%s\n' "$line"
58
- ;;
59
- esac
60
- }
61
-
62
- if [ -n "$kind" ]; then
36
+ if [ -n "$want" ]; then
63
37
  rec="$(wt_require_managed "$want")"
64
- one "${rec%%$'\t'*}" "${rec##*$'\t'}"
38
+ path="${rec%%$'\t'*}"
39
+ wt_is_main "$path" && die "the main checkout is not a worktree"
40
+ printf '%s\n' "$path"
65
41
  exit 0
66
42
  fi
67
43
 
68
- printf ' %-34s %-50s %-40s %-5s %s\n' "BRANCH" "WORKTREE" "HOW TO SEE" "LIVE" "LAST RUN"
44
+ printf ' %-34s %-50s %-6s %s\n' "BRANCH" "WORKTREE" "DIRTY" "UPSTREAM"
69
45
  count=0
70
46
  unmanaged=0
71
47
  while IFS=$'\t' read -r p b; do
72
48
  [ -n "$p" ] || continue
73
49
  count=$(( count + 1 ))
74
- slug="$(wt_slug "$b")"
75
50
  shown="${p/#$HOME/~}"
51
+ label="$b"
76
52
  if wt_is_main "$p"; then
77
- printf ' %-34s %-50s %-40.40s %-5s %s\n' "$(short_path "$b (main checkout)" 34)" "$(short_path "$shown" 50)" "—" "—" "—"
78
- continue
79
- fi
80
- if ! wt_managed "$p"; then
53
+ label="$b (main checkout)"
54
+ elif ! wt_managed "$p"; then
55
+ # No git calls for a checkout that is not ours: it is counted, never listed.
81
56
  unmanaged=$(( unmanaged + 1 ))
82
57
  continue
83
58
  fi
84
- # The address is whatever the project says it is: a URL, a simulator, a window.
85
- line="$(wt_preview "$slug")"
86
- port="$(wt_live_port "$slug")"
87
- [ -n "$line" ] || line=""
88
- if [ -z "$line" ] && [ -n "$port" ]; then line="http://localhost:$port"; fi
89
- if [ -n "$port" ]; then
90
- if tcp_up "$port"; then live="up"; else live="down"; fi
91
- else
92
- live="—"
93
- fi
94
- last="$(wt_verdict "$p")"
95
- printf ' %-34s %-50s %-40.40s %-5s %s\n' "$(short_path "$b" 34)" "$(short_path "$shown" 50)" "${line:-—}" "$live" "${last:-—}"
59
+ if wt_dirty "$p"; then dirty="yes"; else dirty="no"; fi
60
+ up="$(wt_upstream "$p")"
61
+ printf ' %-34s %-50s %-6s %s\n' "$(short_path "$label" 34)" "$(short_path "$shown" 50)" "$dirty" "${up:-—}"
96
62
  done < <(wt_all)
97
63
 
98
64
  [ "$count" -gt 0 ] || log " no checkouts found — is this a git repository?"
@@ -3,8 +3,8 @@
3
3
  # you approve. This is the mode that keeps the worktree home from becoming tens
4
4
  # of gigabytes.
5
5
  #
6
- # Only merged-or-gone branches that are clean, fully pushed, and not running are
7
- # ever candidates. Nothing is removed without --yes.
6
+ # Only merged-or-gone branches that are clean and fully pushed are ever
7
+ # candidates. Nothing is removed without --yes.
8
8
  #
9
9
  # Usage: .sassywares/worktree/prune [--yes] [--version]
10
10
  set -euo pipefail
@@ -18,7 +18,8 @@ usage() {
18
18
  Usage: .sassywares/worktree/prune [--yes]
19
19
 
20
20
  Show every worktree that is merged into its upstream (or whose upstream is gone)
21
- and safe to remove, then — with --yes — remove those and release their ports.
21
+ and safe to remove, then — with --yes — remove those whose tree is clean and
22
+ fully pushed.
22
23
  EOF
23
24
  }
24
25
 
@@ -36,6 +37,11 @@ done
36
37
 
37
38
  need_git
38
39
 
40
+ # A declared life cycle means the stack is the project's to stop. There is no
41
+ # liveness probe here: `remove` is what runs `down:`, so prune sends the user there
42
+ # rather than pulling a directory out from under a running process.
43
+ down="$(wt_down)"
44
+
39
45
  printf ' %-32s %-9s %-6s %-9s %s\n' "BRANCH" "UPSTREAM" "DIRTY" "UNPUSHED" "ACTION"
40
46
  n_candidates=0
41
47
  n_removed=0
@@ -48,9 +54,6 @@ while IFS=$'\t' read -r p b; do
48
54
  state="$(wt_upstream_state "$p")"
49
55
  if wt_dirty "$p"; then dirty="yes"; else dirty="no"; fi
50
56
  unpushed="$(wt_unpushed "$p")"
51
- port="$(wt_live_port "$slug")"
52
- live="no"
53
- [ -n "$port" ] && tcp_up "$port" && live="yes"
54
57
 
55
58
  action=""
56
59
  if [ "$state" = "unmerged" ]; then
@@ -59,8 +62,6 @@ while IFS=$'\t' read -r p b; do
59
62
  action="skipped — dirty"
60
63
  elif [ "$unpushed" != "0" ]; then
61
64
  action="skipped — $unpushed unpushed"
62
- elif [ "$live" = "yes" ]; then
63
- action="skipped — running${port:+ on :$port}"
64
65
  else
65
66
  action="removable"
66
67
  n_candidates=$(( n_candidates + 1 ))
@@ -74,8 +75,11 @@ while IFS=$'\t' read -r p b; do
74
75
  warn skipped "$b has a before_remove hook — run remove <$slug> so it runs"
75
76
  continue
76
77
  fi
78
+ if [ -n "$down" ]; then
79
+ warn skipped "$b has a down: life cycle — real, or the generated stub (exit 78); run remove <$slug> so it is handled"
80
+ continue
81
+ fi
77
82
  git worktree remove "$p" || continue
78
- [ -n "$port" ] && wt_release "$port" "$slug"
79
83
  n_removed=$(( n_removed + 1 ))
80
84
  fi
81
85
  done < <(wt_all)