@sassywares/skills 0.12.1 → 0.13.1

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 (29) hide show
  1. package/CONCEPTS.md +32 -15
  2. package/README.md +43 -36
  3. package/package.json +1 -1
  4. package/skills/sassy-overview/SKILL.md +2 -2
  5. package/skills/sassy-overview/references/identify.md +1 -1
  6. package/skills/sassy-setup/SKILL.md +12 -7
  7. package/skills/sassy-setup/assets/templates/worktrees-create +52 -0
  8. package/skills/sassy-setup/assets/templates/worktrees-remove +51 -0
  9. package/skills/sassy-setup/assets/worktree/_lib.sh +22 -55
  10. package/skills/sassy-setup/assets/worktree/create +21 -28
  11. package/skills/sassy-setup/assets/worktree/list +52 -11
  12. package/skills/sassy-setup/assets/worktree/remove +10 -83
  13. package/skills/sassy-setup/references/branching.md +2 -2
  14. package/skills/sassy-setup/references/check.md +46 -2
  15. package/skills/sassy-setup/references/config.md +70 -100
  16. package/skills/sassy-setup/references/dogfood.md +3 -3
  17. package/skills/sassy-setup/references/init.md +18 -16
  18. package/skills/sassy-setup/references/scaffold-header.md +63 -0
  19. package/skills/sassy-setup/references/worktree.md +135 -86
  20. package/skills/sassy-setup/scripts/detect.sh +708 -250
  21. package/skills/sassy-setup/scripts/worktree-check.mjs +32 -1
  22. package/skills/sassy-worktree/SKILL.md +9 -12
  23. package/skills/sassy-worktree/references/create.md +10 -3
  24. package/skills/sassy-worktree/references/list.md +4 -2
  25. package/skills/sassy-worktree/references/remove.md +30 -6
  26. package/skills/sassy-setup/assets/lifecycle/down +0 -29
  27. package/skills/sassy-setup/assets/lifecycle/up +0 -34
  28. package/skills/sassy-setup/assets/worktree/prune +0 -93
  29. package/skills/sassy-worktree/references/prune.md +0 -13
@@ -10,11 +10,18 @@
10
10
  // asset folder's: setup installs it by copying that folder flat, so no separate
11
11
  // state file records it and no second hash definition exists.
12
12
  //
13
+ // The shipped set is four files — _lib.sh, create, list, remove. `prune` is
14
+ // gone. A v12 install is therefore stale by construction, and its hash cannot
15
+ // match: that is an upgrade, not tampering, so the version header earns its
16
+ // one job here — an older header is reported as a note and the caller proceeds
17
+ // to reinstall. An equal header whose hashes differ is still drift.
18
+ //
13
19
  // Usage: worktree-check.mjs --installed DIR --shipped DIR
14
20
  // Prints "<drift|note>\t<message>" per finding and always exits 0: the caller
15
21
  // owns the verdict and the formatting. Read-only, offline.
16
22
 
17
- import { existsSync } from "node:fs";
23
+ import { existsSync, readFileSync } from "node:fs";
24
+ import { join } from "node:path";
18
25
 
19
26
  import { hashFiles, skillFiles } from "./hash-skill.mjs";
20
27
 
@@ -50,6 +57,30 @@ if (!existsSync(installed)) {
50
57
  process.exit(0);
51
58
  }
52
59
 
60
+ // headerVersion DIR — the number on `# worktree-version: N` in DIR/_lib.sh, or
61
+ // null when there is no readable header. A header is never the verdict, but a
62
+ // lower one names an install built for a contract this skill no longer ships.
63
+ const headerVersion = (dir) => {
64
+ const file = join(dir, "_lib.sh");
65
+ if (!existsSync(file)) return null;
66
+ const match = readFileSync(file, "utf8").match(/^# worktree-version:\s*(\d+)\s*$/m);
67
+ return match ? Number(match[1]) : null;
68
+ };
69
+
70
+ const installedVersion = headerVersion(installed);
71
+ const shippedVersion = headerVersion(shipped);
72
+ if (
73
+ installedVersion !== null &&
74
+ shippedVersion !== null &&
75
+ installedVersion < shippedVersion
76
+ ) {
77
+ note(
78
+ `worktree tooling is v${installedVersion}; this skill ships v${shippedVersion} — an upgrade, not drift — re-run setup, then delete .sassywares/worktree/prune, which v${shippedVersion} no longer ships`,
79
+ );
80
+ console.log(lines.join("\n"));
81
+ process.exit(0);
82
+ }
83
+
53
84
  // Walk each side once: the hash is the verdict and the same arrays name which
54
85
  // bytes moved, so the per-file report cannot contradict the folder hash.
55
86
  const [installedFiles, shippedFiles] = await Promise.all([
@@ -5,16 +5,14 @@ description: >-
5
5
  worktree per branch, each with its own derived namespace, created and torn down
6
6
  safely. Use when asked for parallel work, a second checkout, or to see what a
7
7
  worktree looks like, and when a run offers one and the user accepts.
8
- argument-hint: "[slug] [mode:create|list|remove|prune]"
8
+ argument-hint: "[slug] [mode:list|create|remove]"
9
9
  ---
10
10
 
11
11
  # Sassy Worktree
12
12
 
13
13
  **Outcome:** a checkout per branch that a run or a human can use without touching the main one — created and removed without losing work — or a table saying what exists and what is safe to delete.
14
14
 
15
- **Config.** Resolve `.sassywares/config.yaml` (nearest, walking up) per the `sassy-setup` skill's `references/config.md`. `worktrees.enabled` decides whether a checkout is available at all — permission, never an instruction to take one; `dir` is read by the scripts, not by you. Precedence: explicit token > session instruction > config > skill default. Read the `sassy-setup` skill's `references/worktree.md` before the first mode: it owns the directory, refusal, and hook rules the scripts implement.
16
-
17
- **The scripts do the git.** `.sassywares/worktree/{create,list,remove,prune}` are installed by `sassy-setup` and own the mechanics: `git worktree`, the identity, the refusals. This skill never runs `git worktree` itself and never deletes a directory.
15
+ **Config.** Resolve `.sassywares/config.yaml` (nearest, walking up) per the `sassy-setup` skill's `references/config.md`. `worktrees.enabled` decides whether a checkout is available at all — permission, never an instruction to take one; `worktrees.dir` is read by the scripts, not by you; `worktrees.create` and `worktrees.remove` name the project's own prepare and teardown scripts. Precedence: explicit token > session instruction > config > skill default. Read the `sassy-setup` skill's `references/worktree.md` before the first mode: it owns the directory, the streams, the refusal, and the script-order rules the scripts implement, and its `references/config.md` Lifecycle owns the two keys' shape and degrade.
18
16
 
19
17
  **Harness.** Loading another skill, dispatching an agent, and any command you hand the user follow the `sassy-setup` skill's `references/harness.md`. Read it once per run, before the first of those.
20
18
 
@@ -22,30 +20,29 @@ argument-hint: "[slug] [mode:create|list|remove|prune]"
22
20
 
23
21
  | Mode | Load | It ends with |
24
22
  |---|---|---|
25
- | `list` (default) | `references/list.md` | the table of managed checkouts, as it prints |
26
- | `create` | `references/create.md` | a ready checkout and its hooks |
23
+ | `list` (default) | `references/list.md` | the table of managed checkouts, as it prints, with each row's state |
24
+ | `create` | `references/create.md` | a ready checkout and its identity, or one reported as real but unprepared |
27
25
  | `remove` | `references/remove.md` | a deleted checkout, a surviving branch |
28
- | `prune` | `references/prune.md` | the removed checkouts, and why each skipped row was skipped |
29
26
 
30
- Resolve the mode: an explicit `mode:` token wins. With none, it is `list` — the only mode that changes nothing; a request to add a checkout is `create`, to delete one is `remove`, and to sweep the safe ones is `prune`. Read the one reference for that mode **and only that one**.
27
+ Resolve the mode: an explicit `mode:` token wins. With none, it is `list` — the only mode that changes nothing; a request to add a checkout is `create`, to delete one is `remove`. Read the one reference for that mode **and only that one**.
31
28
 
32
29
  ## Hard rules — every mode
33
30
 
34
31
  | Rule | Requirement |
35
32
  |------|-------------|
33
+ | The project's scripts are the entry point | A create or remove step runs `<worktrees.create>` / `<worktrees.remove>` as `detect.sh --worktree-script` resolves them, never the toolbox directly. The resolver's degrade rule is `references/worktree.md`'s; the keys are `references/config.md`'s Lifecycle. |
36
34
  | The scripts do the git | Never run `git worktree`, never delete a checkout by hand. `.sassywares/worktree/*` owns all of it. |
37
35
  | Repo topology only | `git.repo: workspace` or `none` means no worktrees at all. Say so in one line and stop — never create a checkout inside a nested repo to work around it. |
38
36
  | Enabled is permission | `worktrees.enabled: true` lets a run *offer* a checkout. `create` runs on the user's yes, or on a human asking outright — never because the config allowed it. |
39
- | Ours only | A checkout is managed when it sits under `worktrees.dir` **and** carries `.sassywares/config.yaml`. Never list, prune, or remove one that is not — another tool made it, or it was cut before the wiring. `create` says so when that happens. |
37
+ | Ours only | A checkout is managed when it sits under `worktrees.dir` **and** carries `.sassywares/config.yaml`. Never list or remove one that is not — another tool made it, or it was cut before the wiring. `create` says so when that happens. |
40
38
  | Names come from the script | `WT_NAMESPACE` is derived once. Never build a database name, a compose project, or a device name by hand. |
41
- | Hooks are dispatched, not skipped | A declared `after_create` or `before_remove` runs, or a `down:` that names a skill. `remove` exits `3` rather than skipping it, and that is deliberate. |
39
+ | The identity is the contract | A create must exit `0` **and** print the four `WT_*` lines. Anything else is reported as "checkout is real but unprepared", never filled in from a guess. |
42
40
  | Never force on your behalf | `--force` skips the dirty and unpushed checks. Only the user's explicit instruction passes it. |
43
41
  | No judgement | This skill says what exists and what is safe to delete. Whether the work is correct is a different question, and not one it answers. |
44
- | No state of its own | The scripts keep no registry and no pid file. What exists is what `git worktree list` prints. |
45
42
  | The main checkout is read-only here | Read config from it, list from it, never work in it on a run's behalf. |
46
43
 
47
44
  ## What worktree is not
48
45
 
49
46
  Not a second clone: the checkouts share one object store and one branch lock, so two worktrees can never hold the same branch — which is the property that makes this safe and a `git clone` per agent unsafe.
50
47
 
51
- Not a runner. How the stack starts and stops belongs to the project, and this skill neither owns it nor guesses at it.
48
+ Not a runner. How the stack starts and stops belongs in the project's `create` and `remove` scripts, and this skill neither owns it nor guesses at it.
@@ -3,9 +3,16 @@
3
3
  Read the shared sections in `SKILL.md` first. This file is the create path only.
4
4
 
5
5
  1. **Resolve the branch and its start point first**, through the `sassy-setup` skill's `references/branching.md`, exactly as `sassy-work` does. A run that reaches here has already decided; the branch is not created twice. When a human asks for one by hand with no branch named, ask for the branch name — never derive one.
6
- 2. **Run `.sassywares/worktree/create <branch> --from <start-point>`** with the resolved start point. It is idempotent: an existing worktree for that branch is shown, a branch held by the main checkout is refused, and the same checkout comes back either way. On `--env` it prints the `WT_*` block alone.
7
- 3. **Dispatch the declared hooks.** The script prints one line per `hooks.worktree.after_create` entry; it cannot dispatch a skill, so you do. One `worker` each, in declared order: *load the project skill at `.agents/skills/<name>/SKILL.md` and follow it*, briefed with the `WT_*` block and the fact that the checkout now exists. A missing skill or a `blocked` result stops here — the checkout is real but unprepared, and saying so is the answer.
8
- 4. **Say** the path, branch, the namespace, the upstream it printed (`none` is normal), and the hooks that ran or that none are declared. If the caller is a run, tell it to work in `WT_PATH` from now on.
6
+ 2. **Resolve the project's create script**, then run it once:
7
+
8
+ ```bash
9
+ bash <sassy-setup skill>/scripts/detect.sh --root <project> --worktree-script create
10
+ <resolved-path> <branch> --from <start-point>
11
+ ```
12
+
13
+ An absent key uses the built-in silently; a declared value that is unusable — a missing or non-executable file, or a wrong-shape path — falls back to it with a warning naming the key and the file, and that is not an error. The script takes the same `--from` and the same refusals as the toolbox: `references/worktree.md`'s Refusals table is the list. It does all the project's prepare work around the git call.
14
+ 3. **Check the contract, not the narration.** stdout carries only the four `WT_*` lines; the human lines — including the upstream it found — are on stderr. A non-zero exit is a refusal or a failed prepare: report its message verbatim and stop. Exit `0` without a complete, four-line identity is the other failure: say **the checkout is real but unprepared**, show what was printed and the path the script named if any, and never invent the missing names or present the checkout as ready.
15
+ 4. **Say** the path, branch, the namespace, the upstream the script named (`none` is normal), and that the project's prepare step ran. If the caller is a run, tell it to work in `WT_PATH` from now on.
9
16
 
10
17
  | Rule | Requirement |
11
18
  |------|-------------|
@@ -2,10 +2,12 @@
2
2
 
3
3
  Read the shared sections in `SKILL.md` first. This file is the list path only. `list` is the default because it is the only mode that changes nothing.
4
4
 
5
- 1. Run `.sassywares/worktree/list` and present it as it prints — branch, worktree, dirty, upstream. Never summarise the table away: the columns are the answer.
5
+ 1. Run `.sassywares/worktree/list` and present it as it prints — branch, worktree, dirty, upstream, state. Never summarise the table away: the columns are the answer. A non-zero exit means the state cannot be read: report its message and stop; never guess a state.
6
6
  2. Paths in the table are shortened to `~`. `--path <slug>` prints the real absolute path, which is what you hand a user who wants to open the checkout in an editor.
7
7
  3. A row's upstream is what the branch tracks, or `—` when nothing. An empty upstream is normal for a branch cut here; an upstream that is not the branch's own name is worth pointing at.
8
- 4. Only managed checkouts appear. Anything else found under the worktrees directory is counted in a footer, never listed as if it were ours.
8
+ 4. **Read the state column.** The definitions live in the `sassy-setup` skill's `references/worktree.md`; say what the row shows instead of guessing.
9
+ 5. `--env <slug|branch>` prints the same four `WT_*` lines `create` printed, for scripting — `references/worktree.md` owns it. An ambiguous name — two branches can slug to one — is an error naming every match, never a first pick.
10
+ 6. Only managed checkouts appear. Anything else found under the worktrees directory is counted in a footer, never listed as if it were ours.
9
11
 
10
12
  | Rule | Requirement |
11
13
  |------|-------------|
@@ -2,14 +2,38 @@
2
2
 
3
3
  Read the shared sections in `SKILL.md` first. This file is the remove path only.
4
4
 
5
- 1. **Run `.sassywares/worktree/remove <slug>`.** It refuses first — dirty, unpushed, the main checkout — before it stops anything.
6
- 2. **Then, in this order:** a top-level `down:` naming a script is run by the script itself, in the checkout; a `down:` naming a skill is not, so it joins the hooks in the exit-3 handshake. That exit is the handshake, not an error to route around: it lists every obligation still owed in one round — that `down`, and every declared `hooks.worktree.before_remove` — so dispatch them all, one `worker` per hook briefed with the `WT_*` block and that the checkout is about to go (drop the derived database, shut the simulator), then re-run once with `--hook-ok`. That re-run skips a script `down` that already ran: it continues the same removal, so nothing is stopped twice. A `down:` whose value is path-shaped but has no executable in the checkout is a mistake, not a skill, and `remove` refuses naming both the value and the checkout.
5
+ 1. **Name one checkout.** A slug or a branch is enough; `remove` accepts both. For a request like "remove the merged ones", run `list` first, confirm once, then run `remove` for each checkout in turn — see the last section.
6
+ 2. **Resolve the project's remove script and run it once:**
7
7
 
8
- A generated stub exits `78` to mean **unimplemented**. `remove` warns loudly, names the `down:` key, and removes anyway; any other non-zero status aborts before the handshake. Drop the key if nothing needs stopping, or implement the stub.
9
- 3. **Say what survives.** `remove` deletes the checkout; the **branch stays**, so the work is still reachable. Naming that stops someone assuming the deletion took their commits with it.
10
- 4. **Give a refusal verbatim and stop.** Dirty tree, unpushed commits, the main checkout: each is a real reason, and `--force` is the user's call, never yours. On success say which path went.
8
+ ```bash
9
+ bash <sassy-setup skill>/scripts/detect.sh --root <project> --worktree-script remove
10
+ <resolved-path> <slug|branch>
11
+ ```
12
+
13
+ The project script owns the order in one run, and `references/worktree.md` owns
14
+ the steps and the slots. The skill runs that one command and does not sequence
15
+ the steps itself.
16
+ 3. **Give a refusal verbatim and stop.** The toolbox refuses before touching anything, and the project script passes that through:
17
+ - `not clean — <n> path(s) modified. Commit, discard, or --force.`
18
+ - `<n> commit(s) on '<branch>' are on no remote — push, or --force`
19
+ - `that is the main checkout — it cannot be removed`
20
+
21
+ Each is a real reason. `--force` is the user's call, never yours: it skips the dirty-tree and unpushed-commit checks **only**, never the main checkout. If a refusal leaves a checkout behind, that is the answer; never clear the objection yourself.
22
+
23
+ **A non-zero exit names the stage that failed.** The stop step failing means nothing is deleted. A toolbox refusal means nothing is deleted and the tree is intact. A dispose step failing **after** the tree is gone means the checkout is gone and the resources may survive: report what is left and what to run, and never recreate the tree.
24
+ 4. **Say what survives.** The checkout is gone; the **branch stays**, so the work is still reachable. Naming that stops someone assuming the deletion took their commits with it. Say which path went.
25
+
26
+ ## Removing several checkouts
27
+
28
+ There is no bulk flag. The plain-language path is the only path:
29
+
30
+ 1. Run `list` and show the table, states included.
31
+ 2. Confirm the set once, naming the `merged` rows the user picked.
32
+ 3. Run `remove <slug>` for each checkout, **sequentially**, one project-script run each.
33
+ 4. Report each result and the count at the end; `references/worktree.md` owns how the walk treats a refusal.
11
34
 
12
35
  | Rule | Requirement |
13
36
  |------|-------------|
14
37
  | The branch outlives the checkout | Say that the branch survived. A removal the user reads as a data loss is a removal that gets skipped next time. |
15
- | A refusal is information | Give dirty, unpushed, or main-checkout verbatim. Never route around `--hook-ok`, and never clear the objection yourself. |
38
+ | A refusal is information | Give dirty, unpushed, or main-checkout verbatim. Never clear the objection yourself and never invent a flag to get past it. |
39
+ | One script run per checkout | Never loop inside the project's script or add a bulk mode. The sequential walk is the design. |
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env bash
2
- # down — how this project's stack stops.
3
- #
4
- # sassy-setup wrote this stub and will never edit it again: replace the body below
5
- # with this project's real stop command. The suite reads the `down:` key in
6
- # .sassywares/config.yaml, not this file's name, so keep the two in step if you
7
- # rename the file.
8
- #
9
- # Unimplemented: this stub exits 78. Implement it, or delete the `down:` key if
10
- # nothing needs stopping.
11
- #
12
- # The contract:
13
- # * Terminate what `up` started, then exit: no daemon left behind, nothing else
14
- # still holding this checkout.
15
- # * Idempotent. A stack that is already down is not an error.
16
- # * It runs from inside the checkout, before the folder is deleted, after the
17
- # guards have passed — so a failure here aborts the removal rather than
18
- # leaving something running in a directory nobody owns. Until this stub is
19
- # real, that is what it does: it refuses, because how this project stops is
20
- # still unknown. Delete the `down:` key instead if nothing needs stopping.
21
- # * These are exported: WT_PATH (this checkout), WT_BRANCH, WT_SLUG, and
22
- # WT_NAMESPACE (the derived database / compose project / device name).
23
- set -euo pipefail
24
-
25
- printf 'down: not implemented yet — this project has not said how its stack stops.\n' >&2
26
- printf ' Read the contract at the top of %s, then replace this body.\n' "$0" >&2
27
- printf ' WT_PATH=%s\n WT_BRANCH=%s\n WT_SLUG=%s\n WT_NAMESPACE=%s\n' \
28
- "${WT_PATH:-<unset>}" "${WT_BRANCH:-<unset>}" "${WT_SLUG:-<unset>}" "${WT_NAMESPACE:-<unset>}" >&2
29
- exit 78
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env bash
2
- # up — how this project's stack starts.
3
- #
4
- # sassy-setup wrote this stub and will never edit it again: replace the body below
5
- # with this project's real start command. The suite reads the `up:` key in
6
- # .sassywares/config.yaml, not this file's name, so keep the two in step if you
7
- # rename the file.
8
- #
9
- # Unimplemented: this stub exits 78. Implement it, or delete the `up:` key if
10
- # nothing needs starting.
11
- #
12
- # The contract:
13
- # * Run in the FOREGROUND. This process owns the stack until it is stopped, so a
14
- # detached or daemonized app outlives the call and holds the checkout — which
15
- # is exactly what `down` then cannot kill.
16
- # * Stop on SIGTERM (and Ctrl-C) and reap the children you started before you
17
- # exit. `down` is the other half of the pair: it must terminate what this one
18
- # started, and it runs before a checkout is deleted.
19
- # * These are exported by whoever runs this, so a checkout stays distinct from
20
- # its siblings. Derive names from them, never build one by hand:
21
- # WT_PATH this checkout
22
- # WT_BRANCH the branch it holds
23
- # WT_SLUG the branch, filesystem-safe
24
- # WT_NAMESPACE the derived name for a database, a compose project, a device
25
- # * Ports are this project's business: the suite derives none, so two checkouts
26
- # running the same app collide on a fixed port. Hash WT_SLUG into one instead,
27
- # e.g. PORT=$(( 3000 + $(printf '%s' "$WT_SLUG" | cksum | cut -d' ' -f1) % 100 )).
28
- set -euo pipefail
29
-
30
- printf 'up: not implemented yet — nothing here starts this project.\n' >&2
31
- printf ' Read the contract at the top of %s, then replace this body.\n' "$0" >&2
32
- printf ' WT_PATH=%s\n WT_BRANCH=%s\n WT_SLUG=%s\n WT_NAMESPACE=%s\n' \
33
- "${WT_PATH:-<unset>}" "${WT_BRANCH:-<unset>}" "${WT_SLUG:-<unset>}" "${WT_NAMESPACE:-<unset>}" >&2
34
- exit 78
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env bash
2
- # List worktrees whose work is already safely on a remote, and remove the ones
3
- # you approve. This is the mode that keeps the worktree home from becoming tens
4
- # of gigabytes.
5
- #
6
- # Only merged-or-gone branches that are clean and fully pushed are ever
7
- # candidates. Nothing is removed without --yes.
8
- #
9
- # Usage: .sassywares/worktree/prune [--yes] [--version]
10
- set -euo pipefail
11
-
12
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
- # shellcheck source=./_lib.sh
14
- source "$SCRIPT_DIR/_lib.sh"
15
-
16
- usage() {
17
- cat <<'EOF'
18
- Usage: .sassywares/worktree/prune [--yes]
19
-
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 whose tree is clean and
22
- fully pushed.
23
- EOF
24
- }
25
-
26
- yes=0
27
- while [ $# -gt 0 ]; do
28
- case "$1" in
29
- -h|--help) usage; exit 0 ;;
30
- --version) printf '%s\n' "$WT_VERSION"; exit 0 ;;
31
- --yes) yes=1 ;;
32
- -*) die "unknown flag: $1 (try --help)" ;;
33
- *) die "unexpected argument: $1 (try --help)" ;;
34
- esac
35
- shift
36
- done
37
-
38
- need_git
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
-
45
- printf ' %-32s %-9s %-6s %-9s %s\n' "BRANCH" "UPSTREAM" "DIRTY" "UNPUSHED" "ACTION"
46
- n_candidates=0
47
- n_removed=0
48
- unmanaged=0
49
- while IFS=$'\t' read -r p b; do
50
- [ -n "$p" ] || continue
51
- wt_is_main "$p" && continue
52
- wt_managed "$p" || { unmanaged=$(( unmanaged + 1 )); continue; }
53
- slug="$(wt_slug "$b")"
54
- state="$(wt_upstream_state "$p")"
55
- if wt_dirty "$p"; then dirty="yes"; else dirty="no"; fi
56
- unpushed="$(wt_unpushed "$p")"
57
-
58
- action=""
59
- if [ "$state" = "unmerged" ]; then
60
- action="skipped — unmerged"
61
- elif [ "$dirty" = "yes" ]; then
62
- action="skipped — dirty"
63
- elif [ "$unpushed" != "0" ]; then
64
- action="skipped — $unpushed unpushed"
65
- else
66
- action="removable"
67
- n_candidates=$(( n_candidates + 1 ))
68
- fi
69
-
70
- printf ' %-32s %-9s %-6s %-9s %s\n' "$b" "$state" "$dirty" "$unpushed" "$action"
71
-
72
- if [ "$yes" -eq 1 ] && [ "$action" = "removable" ]; then
73
- hooks="$(wt_hook before_remove "$b")"
74
- if [ -n "$hooks" ]; then
75
- warn skipped "$b has a before_remove hook — run remove <$slug> so it runs"
76
- continue
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
82
- git worktree remove "$p" || continue
83
- n_removed=$(( n_removed + 1 ))
84
- fi
85
- done < <(wt_all)
86
-
87
- if [ "$yes" -eq 1 ]; then
88
- ok pruned "$n_removed removed, $(( n_candidates - n_removed )) left"
89
- elif [ "$n_candidates" -gt 0 ]; then
90
- hint "re-run with --yes to remove the $n_candidates removable worktree(s)"
91
- [ "$unmanaged" -gt 0 ] && hint "$unmanaged worktree(s) not managed here — left alone"
92
- [ "$n_candidates" -eq 0 ] && [ "$unmanaged" -eq 0 ] && ok pruned "nothing to remove"
93
- fi
@@ -1,13 +0,0 @@
1
- # Mode: prune — sweep the checkouts that are safe to delete
2
-
3
- Read the shared sections in `SKILL.md` first. This file is the prune path only.
4
-
5
- 1. Run `.sassywares/worktree/prune` with no flag and show the table.
6
- 2. Ask before removing. `--yes` removes only rows marked `removable`: merged into their upstream or whose upstream is gone, clean, fully pushed, and no `before_remove` hook or `down:` life cycle it would skip.
7
- 3. Rows with a declared hook or a `down:` are shown so the user can run `remove <slug>` instead and get the cleanup. Prune never skips either silently.
8
- 4. Give the counts — removed, left, and why each skipped row was skipped.
9
-
10
- | Rule | Requirement |
11
- |------|-------------|
12
- | Only `removable` rows | The script's marking is the safety proof. Never extend `--yes` to a row it left out, and never prune by hand. |
13
- | A skipped row says why | `unmerged`, `dirty`, `unpushed`, `hook`, or `down`: name it. A bare count leaves the user unable to tell a safe sweep from a stuck one. |