@sassywares/skills 0.12.0 → 0.13.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 (39) hide show
  1. package/CONCEPTS.md +32 -19
  2. package/README.md +50 -43
  3. package/package.json +1 -1
  4. package/skills/sassy-goal/SKILL.md +5 -5
  5. package/skills/sassy-goal/references/close.md +4 -4
  6. package/skills/sassy-goal/references/goal-format.md +27 -4
  7. package/skills/sassy-goal/references/next.md +2 -1
  8. package/skills/sassy-goal/references/write.md +2 -2
  9. package/skills/sassy-lfg/SKILL.md +1 -1
  10. package/skills/sassy-overview/SKILL.md +2 -2
  11. package/skills/sassy-overview/references/identify.md +1 -1
  12. package/skills/sassy-plan/SKILL.md +5 -5
  13. package/skills/sassy-plan/references/plan-format.md +34 -6
  14. package/skills/sassy-setup/SKILL.md +6 -6
  15. package/skills/sassy-setup/assets/templates/worktrees-create +52 -0
  16. package/skills/sassy-setup/assets/templates/worktrees-remove +51 -0
  17. package/skills/sassy-setup/assets/worktree/_lib.sh +22 -55
  18. package/skills/sassy-setup/assets/worktree/create +21 -28
  19. package/skills/sassy-setup/assets/worktree/list +52 -11
  20. package/skills/sassy-setup/assets/worktree/remove +10 -83
  21. package/skills/sassy-setup/references/branching.md +9 -5
  22. package/skills/sassy-setup/references/check.md +23 -0
  23. package/skills/sassy-setup/references/config.md +68 -107
  24. package/skills/sassy-setup/references/dogfood.md +3 -3
  25. package/skills/sassy-setup/references/init.md +18 -16
  26. package/skills/sassy-setup/references/scaffold-header.md +63 -0
  27. package/skills/sassy-setup/references/worktree.md +135 -86
  28. package/skills/sassy-setup/scripts/detect.sh +127 -51
  29. package/skills/sassy-setup/scripts/worktree-check.mjs +32 -1
  30. package/skills/sassy-ship/SKILL.md +1 -1
  31. package/skills/sassy-work/SKILL.md +1 -1
  32. package/skills/sassy-worktree/SKILL.md +9 -12
  33. package/skills/sassy-worktree/references/create.md +10 -3
  34. package/skills/sassy-worktree/references/list.md +4 -2
  35. package/skills/sassy-worktree/references/remove.md +30 -6
  36. package/skills/sassy-setup/assets/lifecycle/down +0 -29
  37. package/skills/sassy-setup/assets/lifecycle/up +0 -34
  38. package/skills/sassy-setup/assets/worktree/prune +0 -93
  39. package/skills/sassy-worktree/references/prune.md +0 -13
@@ -2,6 +2,30 @@
2
2
 
3
3
  Read this before writing the plan file.
4
4
 
5
+ ## The file name
6
+
7
+ The filename is the plan's identity: `<artifacts.plans>/<type>-<slug>.md` for a standalone plan, whose `<type>-` prefix matches the frontmatter `type`; a goal slice is `<NN>-<slice-slug>.md`, and its slug carries no type.
8
+
9
+ - **`type`** is one of `feat fix chore refactor docs test perf ci build` — the Conventional Commit type the work will ship as — and a standalone plan's filename prefix must equal the frontmatter `type`.
10
+ - **`slug`** is lowercase ASCII kebab, 2–3 words (ceiling 5), naming the thing that changes, never the activity: `worktree-cut`, not `cutting-the-worktree-half`.
11
+ - **No date, no `-plan` suffix, no phase numbers.** The date is frontmatter, because a filename must survive a revision, and a rename breaks every reference to it (`sassy-work <plan>`, hook briefs, `goal.md`'s Plan links).
12
+ - **Never overwrite another plan.** Two concurrent plans on the same object take a qualifier (`-phase-two`), never a timestamp.
13
+ - **A caller passing `out:<path>` owns the name.** Slice plans stay `NN-<slice-slug>.md`, and the caller's path wins over every rule here.
14
+
15
+ ## The frontmatter
16
+
17
+ Keys, in this order: `type`, `created`, and `updated` are required; `qa` is optional.
18
+
19
+ - **`type`** — matches the filename prefix and names the commit type the work will ship as. For a standalone plan the prefix must equal it; for a slice plan it equals the parent `goal.md`'s `type`, which the caller passes.
20
+ - **`created`** — `YYYY-MM-DD`, the day the plan was first written; never changes.
21
+ - **`updated`** — `YYYY-MM-DD`; a revision sets it to today in the same edit, and every executor that writes a phase status or a QA row result bumps it too.
22
+
23
+ **`qa`** is a gate switch, not a record of mode. Write `qa: off` only when the user asked for a plan with no QA gates at all, which also means no QA tables anywhere in the file; omit the key otherwise, and the QA gate is on. Never write `on`, `auto`, or `manual`. A check's mode lives only in the row `Mode` column, where rows freely mix `Auto` and `Manual`.
24
+
25
+ Slice plans add `goal` (relative path to the parent `goal.md`) and `slice` (the slice ID, e.g. `S1`).
26
+
27
+ The H1 title stays: frontmatter does not render on GitHub, so the heading is what a reader sees.
28
+
5
29
  ## No open questions
6
30
 
7
31
  The plan has no open-questions section. Every branch the interview found is a decision, a deferred item, or an assumption — copy the ledger as it stood at the confirmed read-back. If you find an open branch while writing, stop and ask it before the file lands.
@@ -48,16 +72,18 @@ On doubt, `Manual`. A false `Auto` pass is unrecoverable; a `Manual` row is mere
48
72
 
49
73
  QA is a completion gate, not a separate track: a phase turns `Done` only when the code is approved and every QA row for that phase passes. `Manual` rows belong to the user, and the agent records what it hears. `Auto` rows are settled by a `sassy-dogfood` run and its report, never by an opinion.
50
74
 
51
- The user may ask in plain language to omit QA tables for this plan, in which case omit the tables and the `**QA:**` line entirely.
75
+ The user may ask in plain language for a plan with no QA gates, in which case omit every `#### QA — P<NN>` subsection and set `qa: off` in the frontmatter. An executor runs a QA gate unless that key says `off`.
52
76
 
53
77
  ## Plan file format
54
78
 
55
79
  ```markdown
56
- # <Plan title>
80
+ ---
81
+ type: feat
82
+ created: YYYY-MM-DD
83
+ updated: YYYY-MM-DD
84
+ ---
57
85
 
58
- **QA:** auto
59
-
60
- (`auto` when at least one row in the plan is `Auto`, `manual` when none is. It is the source of truth for executors, so it never disagrees with the tables.)
86
+ # <Plan title>
61
87
 
62
88
  ## Intent
63
89
  One short paragraph: what we are building and why.
@@ -124,4 +150,6 @@ Omit empty layers. Do not put the next goal's work here. The `**Review:**` line
124
150
  …
125
151
  ```
126
152
 
127
- Every phase has at least one QA row. Status values there are `Pending` | `Done` | `Blocked`: a `Manual` row is `Done` once the user ran that check and confirmed it passed, an `Auto` row is `Done` once a dogfood run passed and its run id is in `Notes`, `Blocked` carries a note saying what failed, and anything unreported stays `Pending`. The `**QA:**` line near the title is the source of truth for executors.
153
+ `qa: off` is added to the frontmatter only for a gate-free plan.
154
+
155
+ Every phase has at least one QA row. Status values there are `Pending` | `Done` | `Blocked`: a `Manual` row is `Done` once the user ran that check and confirmed it passed, an `Auto` row is `Done` once a dogfood run passed and its run id is in `Notes`, `Blocked` carries a note saying what failed, and anything unreported stays `Pending`. The frontmatter's `qa: off` is the only thing that removes the gate for executors; its absence leaves the gate on.
@@ -35,7 +35,7 @@ A check run never edits the config and never rewrites the tree. Its only possibl
35
35
 
36
36
  ## Steps 7–9 — shared by both modes
37
37
 
38
- 7. **Verify.** Run `scripts/detect.sh --root <path> --check`. It validates the config against the tree — topology and remotes, `base_map` shape and cycles, `repos` against each nested repo, hooks, artifacts paths, `knowledge`, `pr.*` booleans, `commit.branch`, the `worktrees` block, the top-level `up`/`down` pair (accepted there, and a stray nested `up.*`/`down.*` is an unknown key), the `dogfood` block, any unknown key, and in `workspace` mode the installed snapshot's version — plus, for a project-scope install, the pin: every suite-skill folder in `.agents/skills` (a name in the suite's roster, `assets/roster` in sassy-setup, not any `sassy-` prefix) hashed against `skills-lock.json`, the lock's coverage both ways, and whether git carries the lock. A user-scope install has no pin here; the check notes the scope it found. Report every `drift:` line verbatim, or that the config matches the tree. Drift blocks step 8.
38
+ 7. **Verify.** Run `scripts/detect.sh --root <path> --check`. It validates the config against the tree — topology and remotes, `base_map` shape and cycles, `repos` against each nested repo, hooks, artifacts paths, `knowledge`, `pr.*` booleans, `commit.branch`, the `worktrees` block, the removed legacy keys `up`, `down`, and `hooks.worktree` (a named error each), the `dogfood` block, any unknown key, and in `workspace` mode the installed snapshot's version — plus, for a project-scope install, the pin: every suite-skill folder in `.agents/skills` (a name in the suite's roster, `assets/roster` in sassy-setup, not any `sassy-` prefix) hashed against `skills-lock.json`, the lock's coverage both ways, and whether git carries the lock. A user-scope install has no pin here; the check notes the scope it found. Report every `drift:` line verbatim, or that the config matches the tree. Drift blocks step 8.
39
39
 
40
40
  The `worktrees` half checks what a run would read: the switch, that the tooling is installed with the shipped bytes, that no checkout sits inside the working tree, and that none holds a branch `base_map` names as a base.
41
41
 
@@ -45,7 +45,7 @@ A check run never edits the config and never rewrites the tree. Its only possibl
45
45
 
46
46
  8. **Commit what setup owns.** `repo` topology only, and only when step 7 is clean. The file list is exactly what setup wrote or found unwritten:
47
47
 
48
- `.sassywares/config.yaml`, `.sassywares/README.md`, `.sassywares/dogfood/recipe.md` and `.sassywares/.gitignore` when step 4 created them, the `up`/`down` stubs step 4 wrote (only those two named scripts — never their directory), `.sassywares/worktree/*` when step 6 installed the tooling, the runner file when the user accepted aliases in it, `.agents/skills/sassy-*` and `skills-lock.json` when the suite is in project scope, the project-scope agent files when step 5 copied them, and a root `.gitignore` when step 5 created one. Named files only — never `git add -A`, never `git add .`. The reports directory is never in this list: it is gitignored, and nothing setup writes lives there.
48
+ `.sassywares/config.yaml`, `.sassywares/README.md`, `.sassywares/dogfood/recipe.md` and `.sassywares/.gitignore` when step 4 created them, the two project scripts step 6 scaffolded at `<home>/worktrees/create` and `<home>/worktrees/remove` (only those two named files — never their directory), `.sassywares/worktree/*` when step 6 installed the tooling, the runner file when the user accepted aliases in it, `.agents/skills/sassy-*` and `skills-lock.json` when the suite is in project scope, the project-scope agent files when step 5 copied them, and a root `.gitignore` when step 5 created one. Named files only — never `git add -A`, never `git add .`. The reports directory is never in this list: it is gitignored, and nothing setup writes lives there.
49
49
 
50
50
  Dispatch `sassy-commit` with that list and `branch:current`. The token is explicit, not this skill's default: wiring is a one-time bootstrap commit, and cutting a branch would leave the project configured but uncommitted until someone ships it. Name the branch it landed on, base branch included.
51
51
 
@@ -54,7 +54,7 @@ A check run never edits the config and never rewrites the tree. Its only possibl
54
54
  - **`workspace`** — nothing to commit: the root is not a repo, and `references/workspace.md` forbids running the snapshot here. Say the root config and the pin land with the project's next snapshot.
55
55
  - **`none`** — nothing to commit, deliberately.
56
56
 
57
- 9. **Report.** The config path, the topology, the resolved artifact and knowledge paths, the lifecycle — the two values `up` and `down` name, or one line saying the project declares **no lifecycle** because the keys are absent, with no suggestion attached — whether agent QA is **off** — one line saying every QA row stays a human's, with no suggestion attached — or on, and then whether the recipe is ready or still a skeleton until `sassy-dogfood mode:discover` runs, where the skills are installed (scope) and where the agents are (scope and harness), or why either is not, the commit (hash and branch) or why there is none, and in `workspace` mode what was installed, with versions (`snapshot vN`, `workspace-git vN`), and where the `worktree:*` / `workspace:*` aliases went, or that none were wired because the project has no command-building file to put them in — naming the scripts' path instead, since that is how they are run either way. Remind: `/reload` so the harness rescans. Close with what is left over — at most dirt setup deliberately did not commit — and nothing else: a clean setup leaves the user good to go.
57
+ 9. **Report.** The config path, the topology, the resolved artifact and knowledge paths, the lifecycle — the two paths `worktrees.create` and `worktrees.remove` name, or one line saying the built-in is used because the keys are absent, with no suggestion attached — whether agent QA is **off** — one line saying every QA row stays a human's, with no suggestion attached — or on, and then whether the recipe is ready or still a skeleton until `sassy-dogfood mode:discover` runs, where the skills are installed (scope) and where the agents are (scope and harness), or why either is not, the commit (hash and branch) or why there is none, and in `workspace` mode what was installed, with versions (`snapshot vN`, `workspace-git vN`), and where the `worktree:*` / `workspace:*` aliases went, or that none were wired because the project has no command-building file to put them in — naming the scripts' path instead, since that is how they are run either way. Remind: `/reload` so the harness rescans. Close with what is left over — at most dirt setup deliberately did not commit — and nothing else: a clean setup leaves the user good to go.
58
58
 
59
59
  ## Hard rules — every mode
60
60
 
@@ -62,10 +62,10 @@ A check run never edits the config and never rewrites the tree. Its only possibl
62
62
  |------|-------------|
63
63
  | No `git init` | Setup never turns a folder into a repo, and never does remote or ref surgery. The step 8 commit is its only git write. |
64
64
  | Verify before commit | A config that fails `--check` is reported, never committed. |
65
- | Commit only what setup owns | The config, the setup README, the `up`/`down` stubs step 4 wrote, the vendored `sassy-*` folders and `skills-lock.json` (project scope), the project-scope agent files, and a `.gitignore` setup created. Never a file the user wrote or the repo already had, unless they name it. |
65
+ | Commit only what setup owns | The config, the setup README, the two project scripts step 6 scaffolded, the vendored `sassy-*` folders and `skills-lock.json` (project scope), the project-scope agent files, and a `.gitignore` setup created. Never a file the user wrote or the repo already had, unless they name it. |
66
66
  | No silent overwrite | An existing config or an existing `.sassywares/workspace/snapshot` is shown and asked about, never replaced blind. |
67
- | Write boundary | Only `.sassywares/` (the config, the setup README, the dogfood scaffold, and the worktree tooling), the two `up`/`down` stubs step 4 wrote at their probed path, the skills and agent files step 5 installed in the scope the user chose, `skills-lock.json` (project scope), `.sassywares/.gitignore` with its two lines, and at most one root `.gitignore` line that step 5 created. Never `package.json` outside step 6's `worktree:*` and `workspace:*` aliases, never a root `.gitignore` in a workspace. Workspace git helpers land in `.sassywares/workspace/`, never in a project's `bin/`. |
68
- | Install the tooling, never use it | Setup copies `.sassywares/worktree/` and offers the aliases. It never creates a checkout, never runs a script, and never starts or stops the project's stack — `up` is the project's or the user's, and `down` runs only from `remove`. |
67
+ | Write boundary | Only `.sassywares/` (the config, the setup README, the dogfood scaffold, and the worktree tooling), the two project scripts step 6 scaffolded at `<home>/worktrees/create` and `<home>/worktrees/remove` (new files only — never the whole `worktrees/` folder), the skills and agent files step 5 installed in the scope the user chose, `skills-lock.json` (project scope), `.sassywares/.gitignore` with its two lines, and at most one root `.gitignore` line that step 5 created. Never `package.json` outside step 6's `worktree:*` and `workspace:*` aliases, never a root `.gitignore` in a workspace. Workspace git helpers land in `.sassywares/workspace/`, never in a project's `bin/`. |
68
+ | Install the tooling, never use it | Setup copies `.sassywares/worktree/` and offers the aliases. It never creates a checkout, never runs a script, and never starts or stops the project's stack — that is the project's own `create`/`remove` script's job. |
69
69
  | Skills come from upstream | Install with `npx skills add`, `-g` for user scope; never hand-copy skill files or maintain the links yourself. |
70
70
  | Agents come from sassy-agents | Only the running harness's folder, as-is: linked by `install.sh` (user scope) or copied verbatim (project scope). Never edit, merge, or overwrite a differing agent file without asking. |
71
71
  | Never edit the manifest | No dependencies, no `postinstall`, no `skills:*` scripts. Step 6's `worktree:*` and `workspace:*` aliases may be added, and only into a file that already carries named commands: appended or corrected, never removed, nothing else in the file touched, and **never a manifest created to hold them**. A project with no such file gets no aliases and loses nothing — the scripts are run by path. Setup installs the suite; the user or project decides how it updates. |
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+ # sassywares:scaffold v1 skill=sassy-setup version=<version> date=<YYYY-MM-DD>
3
+ #
4
+ # worktrees/create — this project's own "prepare a checkout" step.
5
+ #
6
+ # Contract: called as `<home>/worktrees/create <branch> [--from <ref>]`, with the
7
+ # same arguments the toolbox takes. It must exit 0 and print the four WT_* lines
8
+ # on stdout — WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE — with all narration on
9
+ # stderr. A run that exits 0 without them is reported as "checkout is real but
10
+ # unprepared".
11
+ #
12
+ # This file now belongs to the project. Setup wrote it once and never rewrites it:
13
+ # edit it freely. Nothing below the suite call runs until you add it.
14
+ set -euo pipefail
15
+
16
+ # The suite scripts resolve from the project root, whatever <home> is called.
17
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
18
+
19
+ # --help and --version belong to the toolbox, not to this wrapper: pass them
20
+ # through before the identity capture below would treat their output as one.
21
+ case "${1:-}" in
22
+ -h|--help|--version) exec "$ROOT/.sassywares/worktree/create" "$@" ;;
23
+ esac
24
+
25
+ # --- before the checkout exists (before git) --------------------------------
26
+ # Anything that has to exist before the checkout does goes here. Add only what
27
+ # this project really needs, then delete the examples you did not use. They are
28
+ # comments on purpose — setup writes no code here, because it cannot verify one.
29
+ #
30
+ # - claim a namespace or pre-create a resource the new checkout will attach to.
31
+ # - reserve a name or a slot from the project's own registry before git uses it.
32
+ # ---------------------------------------------------------------------------
33
+
34
+ # The toolbox cuts the checkout and prints the identity block. Capture it, echo it
35
+ # unchanged for the caller, then evaluate it so this script — and everything you
36
+ # add below — sees WT_PATH, WT_BRANCH, WT_SLUG, and WT_NAMESPACE.
37
+ block="$("$ROOT/.sassywares/worktree/create" "$@")"
38
+ printf '%s\n' "$block"
39
+ eval "$block"
40
+
41
+ # --- after the checkout exists (after git) ---------------------------------
42
+ # Everything a checkout needs beyond git goes here: the checkout exists and the
43
+ # WT_* names are set. Add only what this project really needs, then delete the
44
+ # examples you did not use. They are comments on purpose — setup writes no code
45
+ # here, because it cannot verify one.
46
+ #
47
+ # - install dependencies into $WT_PATH (the project's package manager).
48
+ # - derive a per-worktree .env from $WT_NAMESPACE, e.g.
49
+ # tool env --namespace "$WT_NAMESPACE" > "$WT_PATH/.env".
50
+ # - seed a database named from $WT_NAMESPACE, e.g. createdb "$WT_NAMESPACE".
51
+ # - create a preview deployment named from $WT_NAMESPACE.
52
+ # --------------------------------------------------------------------------
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ # sassywares:scaffold v1 skill=sassy-setup version=<version> date=<YYYY-MM-DD>
3
+ #
4
+ # worktrees/remove — this project's own "tear a checkout down" step.
5
+ #
6
+ # Contract: called as `<home>/worktrees/remove <slug|branch> [--force]`, with the
7
+ # same arguments the toolbox takes. It must exit 0 once the checkout is gone.
8
+ #
9
+ # This file now belongs to the project. Setup wrote it once and never rewrites it:
10
+ # edit it freely. The two slots below are inert comments until you add to them.
11
+ set -euo pipefail
12
+
13
+ # The suite scripts resolve from the project root, whatever <home> is called.
14
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
15
+
16
+ # --help and --version belong to the toolbox, not to this wrapper: pass them
17
+ # through before the identity capture below would treat their output as one.
18
+ case "${1:-}" in
19
+ -h|--help|--version) exec "$ROOT/.sassywares/worktree/remove" "$@" ;;
20
+ esac
21
+
22
+ target="${1:-}"
23
+ [ -n "$target" ] || { printf 'Usage: %s <slug|branch> [--force]\n' "${BASH_SOURCE[0]}" >&2; exit 2; }
24
+
25
+ # The identity of the checkout this run is about to delete. Asking the toolbox —
26
+ # rather than rebuilding a slug here — means these are the names `create` minted.
27
+ # Capture only: nothing consumes remove's stdout, so this block is not echoed.
28
+ # Capture before evaluating, so a failed lookup aborts under set -e instead of
29
+ # deleting a tree with the variables unset.
30
+ block="$("$ROOT/.sassywares/worktree/list" --env "$target")"
31
+ eval "$block"
32
+
33
+ # --- stop, while the checkout still exists ---------------------------------
34
+ # Whatever the checkout is running has to stop before the tree goes: the folder is
35
+ # about to be deleted, and a process holding it is what makes a removal half-fail.
36
+ # Add only what this project starts per checkout.
37
+ #
38
+ # - stop the stack in $WT_PATH (e.g. a compose down run in "$WT_PATH").
39
+ # - shut the simulator or device named from $WT_NAMESPACE.
40
+ # ---------------------------------------------------------------------------
41
+
42
+ "$ROOT/.sassywares/worktree/remove" "$@"
43
+
44
+ # --- dispose, after the tree is gone ---------------------------------------
45
+ # The checkout is deleted, the branch survives, and WT_NAMESPACE is still set — the
46
+ # derived name is all that is needed to drop what was created for it.
47
+ #
48
+ # - drop the database derived from $WT_NAMESPACE, e.g. dropdb "$WT_NAMESPACE".
49
+ # - delete the preview deployment named from $WT_NAMESPACE.
50
+ # - shut the simulator started for $WT_NAMESPACE.
51
+ # ---------------------------------------------------------------------------
@@ -1,35 +1,29 @@
1
1
  #!/usr/bin/env bash
2
- # Shared helpers for the worktree scripts: create, list, remove, prune.
2
+ # Shared helpers for the worktree scripts: create, list, remove.
3
3
  #
4
4
  # Installed next to those scripts by sassy-setup. Suite-owned and read-only, so
5
5
  # every project runs the same mechanics. Three rules worth keeping:
6
6
  #
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.
7
+ # 1. One config source. The worktree home and the on/off switch live under
8
+ # `worktrees:` in .sassywares/config.yaml; a stack's own start and stop steps
9
+ # belong to the project's scripts, not to a key here. Never grow a second
10
+ # source.
11
11
  # 2. Identity is derived here once — never built by hand downstream.
12
12
  # 3. Everything resolves against the MAIN checkout, so running any of these
13
13
  # from inside a worktree behaves identically.
14
14
  #
15
- # worktree-version: 12
15
+ # worktree-version: 13
16
16
 
17
17
  set -euo pipefail
18
18
 
19
- WT_VERSION="12"
20
- WT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ # shellcheck disable=SC2034 # read by every script that sources this file
20
+ WT_VERSION="13"
21
21
 
22
22
  log() { printf '%s\n' "$*"; }
23
23
  ok() { printf ' %-9s %s\n' "$1" "$2"; }
24
24
  warn() { printf ' %-9s %s\n' "!" "$*" >&2; }
25
25
  die() { printf ' ✗ %s\n' "$*" >&2; exit 1; }
26
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
- }
33
27
 
34
28
  # The nearest config, walking up from the cwd — used only to explain a refusal
35
29
  # when there is no repo to work in at all.
@@ -111,47 +105,7 @@ wt_cfg() {
111
105
 
112
106
  wt_enabled() { [ "$(wt_cfg enabled false)" = "true" ]; }
113
107
 
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
-
138
- # A list value (`[a b]`) split one per line.
139
- wt_list_items() {
140
- printf '%s' "$1" | sed -e 's/^\[//' -e 's/\]$//' | tr ',' '\n' \
141
- | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//; s/^"//; s/"$//' | grep -v '^$' || true
142
- }
143
-
144
108
  # --- identity -------------------------------------------------------------
145
- # The first match wins, so `hooks.worktree."*"` applies when no branch matches.
146
- wt_hook() { # $1 point (after_create|before_remove), $2 branch — one entry per line
147
- local point="$1" branch="$2" v=""
148
- v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}${branch}${WLIB_US}${point}")"
149
- if [ -z "$v" ]; then
150
- v="$(wt_get "hooks${WLIB_US}worktree${WLIB_US}*${WLIB_US}${point}")"
151
- fi
152
- wt_list_items "$v"
153
- }
154
-
155
109
  wt_slug() { printf '%s' "$1" | sed -E 's#[/ ]+#-#g; s#[^A-Za-z0-9._-]#-#g'; }
156
110
 
157
111
  # A name safe for a database, a compose project, or a simulator: lowercase,
@@ -162,12 +116,25 @@ wt_namespace() {
162
116
  | sed -E 's#[^a-z0-9]+#-#g; s#^-+##; s#-+$##'
163
117
  }
164
118
 
119
+ # wt_print_env PATH BRANCH SLUG — the four `WT_*` lines a caller evaluates. One
120
+ # formatter: `create` mints an identity and `list --env` hands one back, so the
121
+ # two cannot drift apart. Nothing else goes on stdout when this runs.
122
+ wt_print_env() {
123
+ # %q keeps a space in the path or a backtick in the branch from being read as
124
+ # shell syntax when a caller evaluates the block. Simple values are unchanged.
125
+ printf 'WT_PATH=%q\nWT_BRANCH=%q\nWT_SLUG=%q\nWT_NAMESPACE=%q\n' \
126
+ "$1" "$2" "$3" "$(wt_namespace "$3")"
127
+ }
128
+
165
129
  # The directory holding every worktree of this repo: one folder per checkout,
166
130
  # under a home that survives a reboot. A second clone of the same project gets a
167
131
  # suffixed folder instead of sharing this one.
168
132
  wt_home() {
169
133
  local dir base cand parent owner
170
134
  dir="$(wt_cfg dir "$HOME/.sassywares/worktrees")"
135
+ # The patterns are literal (case does not expand a tilde), so the strip below
136
+ # removes the two characters the user wrote, not a home directory.
137
+ # shellcheck disable=SC2088
171
138
  case "$dir" in
172
139
  "~") dir="$HOME" ;;
173
140
  "~/"*) dir="$HOME/${dir#\~/}" ;;
@@ -224,7 +191,7 @@ wt_find() { # $1 slug or branch -> path<TAB>branch, or nothing
224
191
 
225
192
  # A checkout is ours when it lives under this repo's worktree home AND carries
226
193
  # the wiring. Anything else — another tool's worktree, or one cut before setup
227
- # was committed — is not managed here: we do not list it, prune it, or delete it.
194
+ # was committed — is not managed here: we do not list it or delete it.
228
195
  wt_managed() { # $1 path
229
196
  case "$1" in
230
197
  "$(wt_home)"/*) [ -f "$1/.sassywares/config.yaml" ] ;;
@@ -4,7 +4,11 @@
4
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
- # Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
7
+ # Streams: stdout carries only the four WT_* identity lines, once, at the end of
8
+ # a successful run; every human line goes to stderr. A caller can eval stdout
9
+ # while a person still reads the narration.
10
+ #
11
+ # Usage: .sassywares/worktree/create <branch> [--from <start-point>]
8
12
  # .sassywares/worktree/create --version
9
13
  set -euo pipefail
10
14
 
@@ -12,31 +16,33 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
16
  # shellcheck source=./_lib.sh
13
17
  source "$SCRIPT_DIR/_lib.sh"
14
18
 
19
+ # stdout belongs to the identity, so every human line here goes to stderr. The
20
+ # shared `ok` is stdout-oriented; shadow it rather than fork the format.
21
+ ok() { printf ' %-9s %s\n' "$1" "$2" >&2; }
22
+
15
23
  usage() {
16
24
  cat <<'EOF'
17
- Usage: .sassywares/worktree/create <branch> [--from <start-point>] [--env]
25
+ Usage: .sassywares/worktree/create <branch> [--from <start-point>]
18
26
 
19
- Create (or find) the worktree for <branch> and print the namespace a run
20
- inherits: WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE.
27
+ Create (or find) the worktree for <branch>. stdout carries the identity a run
28
+ inherits — WT_PATH, WT_BRANCH, WT_SLUG, WT_NAMESPACE, one per line — and nothing
29
+ else; the narration goes to stderr.
21
30
 
22
31
  --from <ref> where a new branch is cut from (default HEAD). A caller that has
23
32
  already resolved the base passes it; this script never guesses.
24
- --env print only `WT_*=<value>` lines, for eval.
25
33
  EOF
26
34
  }
27
35
 
28
36
  branch=""
29
37
  from="HEAD"
30
- env_only=0
31
38
  while [ $# -gt 0 ]; do
32
39
  case "$1" in
33
40
  -h|--help) usage; exit 0 ;;
34
41
  --version) printf '%s\n' "$WT_VERSION"; exit 0 ;;
35
- --env) env_only=1 ;;
36
- --from) shift; from="${1:-}"; [ -n "$from" ] || die "--from needs a start point" ;;
37
- --from=*) from="${1#*=}" ;;
38
- -*) die "unknown flag: $1 (try --help)" ;;
39
- *) [ -z "$branch" ] || die "one branch at a time"; branch="$1" ;;
42
+ --from) shift; from="${1:-}"; [ -n "$from" ] || { usage >&2; exit 2; } ;;
43
+ --from=*) from="${1#*=}"; [ -n "$from" ] || { usage >&2; exit 2; } ;;
44
+ -*) printf ' ✗ unknown flag: %s (try --help)\n' "$1" >&2; usage >&2; exit 2 ;;
45
+ *) [ -z "$branch" ] || { usage >&2; exit 2; }; branch="$1" ;;
40
46
  esac
41
47
  shift
42
48
  done
@@ -51,10 +57,6 @@ path="$(wt_path "$slug")"
51
57
  show() { # $1 path
52
58
  local ns
53
59
  ns="$(wt_namespace "$slug")"
54
- if [ "$env_only" -eq 1 ]; then
55
- printf 'WT_PATH=%s\nWT_BRANCH=%s\nWT_SLUG=%s\nWT_NAMESPACE=%s\n' "$1" "$branch" "$slug" "$ns"
56
- return 0
57
- fi
58
60
  ok worktree "$1"
59
61
  ok branch "$branch"
60
62
  # Say the tracking out loud. A branch cut from a remote-tracking ref used to
@@ -68,19 +70,10 @@ show() { # $1 path
68
70
  || warn upstream "this branch tracks '$up', not '$branch' — a plain 'git push' lands there"
69
71
  ok namespace "$ns"
70
72
  # A branch cut from a ref that predates setup has no config and no tooling, so
71
- # this checkout is not managed here: `list` skips it, `prune` leaves it alone.
73
+ # this checkout is not managed here: `list` skips it and never offers it.
72
74
  [ -f "$1/.sassywares/config.yaml" ] \
73
- || ok unmanaged "this branch has no .sassywares/config.yaml — cut from a ref that predates setup; list and prune will skip it"
74
- local hooks n
75
- hooks="$(wt_hook after_create "$branch")"
76
- if [ -z "$hooks" ]; then
77
- ok hook "hooks.worktree.after_create — none declared"
78
- else
79
- while IFS= read -r n; do
80
- [ -n "$n" ] || continue
81
- ok hook "after_create → $n (dispatch it, with WT_* above)"
82
- done <<<"$hooks"
83
- fi
75
+ || ok unmanaged "this branch has no .sassywares/config.yaml — cut from a ref that predates setup; list will skip it"
76
+ wt_print_env "$1" "$branch" "$slug"
84
77
  }
85
78
 
86
79
  # Already in a worktree of ours: show it and stop. This is the second call in a
@@ -96,7 +89,7 @@ if [ -n "$existing" ]; then
96
89
  fi
97
90
 
98
91
  if [ -e "$path" ]; then
99
- die "'$path' exists but no worktree is registered for '$branch' — inspect it, then prune"
92
+ die "'$path' exists but no worktree is registered for '$branch' — inspect it, then delete it"
100
93
  fi
101
94
 
102
95
  home="$(wt_home)"
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env bash
2
- # Show every worktree of this repo: branch, path, whether its tree is dirty, and
3
- # the upstream it tracks.
2
+ # Show every worktree of this repo: branch, path, whether its tree is dirty, the
3
+ # upstream it tracks, and whether its work is merged there.
4
4
  #
5
- # Usage: .sassywares/worktree/list [--path <slug>] [--version]
5
+ # Read-only: nothing here creates, edits, or deletes a checkout.
6
+ #
7
+ # Usage: .sassywares/worktree/list [--path <slug>] [--env <slug|branch>] [--version]
6
8
  set -euo pipefail
7
9
 
8
10
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -11,26 +13,33 @@ source "$SCRIPT_DIR/_lib.sh"
11
13
 
12
14
  usage() {
13
15
  cat <<'EOF'
14
- Usage: .sassywares/worktree/list [--path <slug>]
16
+ Usage: .sassywares/worktree/list [--path <slug>] [--env <slug|branch>]
15
17
 
16
- Print every worktree with its branch, path, dirty state, and upstream.
18
+ Print every worktree with its branch, path, dirty state, upstream, and state
19
+ (merged / gone / unmerged).
17
20
 
18
- --path <slug> print only the path of one worktree (for cd "$(...)")
21
+ --path <slug> print only the path of one worktree (for cd "$(...)")
22
+ --env <slug|branch> print only the four WT_* identity lines of one worktree
19
23
  EOF
20
24
  }
21
25
 
22
26
  want=""
27
+ env_target=""
23
28
  while [ $# -gt 0 ]; do
24
29
  case "$1" in
25
30
  -h|--help) usage; exit 0 ;;
26
31
  --version) printf '%s\n' "$WT_VERSION"; exit 0 ;;
27
- --path) shift; want="${1:-}"; [ -n "$want" ] || die "path needs a slug" ;;
28
- -*) die "unknown flag: $1 (try --help)" ;;
29
- *) die "unexpected argument: $1 (try --help)" ;;
32
+ --path) shift; want="${1:-}"; [ -n "$want" ] || { usage >&2; exit 2; } ;;
33
+ --env) shift; env_target="${1:-}"; [ -n "$env_target" ] || { usage >&2; exit 2; } ;;
34
+ --env=*) env_target="${1#*=}"; [ -n "$env_target" ] || { usage >&2; exit 2; } ;;
35
+ -*) usage >&2; exit 2 ;;
36
+ *) usage >&2; exit 2 ;;
30
37
  esac
31
38
  shift
32
39
  done
33
40
 
41
+ [ -z "$env_target" ] || [ -z "$want" ] || { usage >&2; exit 2; }
42
+
34
43
  need_git
35
44
 
36
45
  if [ -n "$want" ]; then
@@ -41,7 +50,35 @@ if [ -n "$want" ]; then
41
50
  exit 0
42
51
  fi
43
52
 
44
- printf ' %-34s %-50s %-6s %s\n' "BRANCH" "WORKTREE" "DIRTY" "UPSTREAM"
53
+ if [ -n "$env_target" ]; then
54
+ # An identity handed back, so it goes to exactly one checkout. Collect every
55
+ # match instead of taking the first: two branches can slug to the same name
56
+ # (`feat/x` and `feat-x`), and a silent first pick would hand a caller another
57
+ # branch's checkout.
58
+ count=0
59
+ found=""
60
+ names=""
61
+ while IFS=$'\t' read -r p b; do
62
+ [ -n "$p" ] || continue
63
+ if [ "$b" != "$env_target" ] && [ "$(wt_slug "$b")" != "$env_target" ]; then
64
+ continue
65
+ fi
66
+ count=$(( count + 1 ))
67
+ found="$p"$'\t'"$b"
68
+ names="${names:+$names, }$b"
69
+ done < <(wt_all)
70
+ [ "$count" -gt 0 ] || die "no worktree for '$env_target' (try: list)"
71
+ [ "$count" -eq 1 ] || die "'$env_target' matches $count worktrees ($names) — pass the branch name of exactly one"
72
+ p="${found%%$'\t'*}"
73
+ b="${found##*$'\t'}"
74
+ wt_is_main "$p" && die "the main checkout is not a worktree"
75
+ wt_managed "$p" \
76
+ || die "'$env_target' is not managed here — it is outside the worktree home, or it was cut before the wiring"
77
+ wt_print_env "$p" "$b" "$(wt_slug "$b")"
78
+ exit 0
79
+ fi
80
+
81
+ printf ' %-34s %-50s %-6s %-24s %s\n' "BRANCH" "WORKTREE" "DIRTY" "UPSTREAM" "STATE"
45
82
  count=0
46
83
  unmanaged=0
47
84
  while IFS=$'\t' read -r p b; do
@@ -49,16 +86,20 @@ while IFS=$'\t' read -r p b; do
49
86
  count=$(( count + 1 ))
50
87
  shown="${p/#$HOME/~}"
51
88
  label="$b"
89
+ state="—"
52
90
  if wt_is_main "$p"; then
53
91
  label="$b (main checkout)"
54
92
  elif ! wt_managed "$p"; then
55
93
  # No git calls for a checkout that is not ours: it is counted, never listed.
56
94
  unmanaged=$(( unmanaged + 1 ))
57
95
  continue
96
+ else
97
+ # Only a managed checkout is ever removable, so only one gets a state.
98
+ state="$(wt_upstream_state "$p")"
58
99
  fi
59
100
  if wt_dirty "$p"; then dirty="yes"; else dirty="no"; fi
60
101
  up="$(wt_upstream "$p")"
61
- printf ' %-34s %-50s %-6s %s\n' "$(short_path "$label" 34)" "$(short_path "$shown" 50)" "$dirty" "${up:-—}"
102
+ printf ' %-34s %-50s %-6s %-24s %s\n' "$(short_path "$label" 34)" "$(short_path "$shown" 50)" "$dirty" "${up:-—}" "$state"
62
103
  done < <(wt_all)
63
104
 
64
105
  [ "$count" -gt 0 ] || log " no checkouts found — is this a git repository?"