@sassywares/skills 0.12.1 → 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 (29) hide show
  1. package/CONCEPTS.md +28 -15
  2. package/README.md +41 -34
  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 +6 -6
  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 +23 -0
  15. package/skills/sassy-setup/references/config.md +62 -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 +127 -51
  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
@@ -11,6 +11,9 @@
11
11
  # detect.sh --branch [--policy P] resolve the branch decision for this run
12
12
  # detect.sh [--root DIR] --check compare the existing config, and the
13
13
  # vendored pin, to reality
14
+ # detect.sh [--root DIR] --worktree-script MODE
15
+ # print the absolute path of the create or
16
+ # remove script a run executes
14
17
  #
15
18
  # --policy takes infer|current|new: the skill-level token. infer (the default)
16
19
  # defers to commit.branch in the config, and new is the fallback when the config
@@ -19,6 +22,11 @@
19
22
  # new name can match a base_map family (release/*) and retarget the PR.
20
23
  # --goal SLUG resolves the goal hooks for one goal slug, the same way --head does
21
24
  # for a branch; the slug keys hooks.goal, not a branch.
25
+ # --worktree-script MODE asks one question: which path does a run execute? The
26
+ # config's worktrees.create|remove when it names an executable file, else the
27
+ # built-in .sassywares/worktree/<mode>. A declared path that is gone warns on
28
+ # stderr and falls back; an absent key falls back silently. It never writes and
29
+ # never creates a directory, so it answers even before setup has installed one.
22
30
  set -euo pipefail
23
31
 
24
32
  ROOT_ARG=""
@@ -26,6 +34,7 @@ HEAD_ARG=""
26
34
  GOAL_ARG=""
27
35
  POLICY_ARG=""
28
36
  NAME_ARG=""
37
+ WT_SCRIPT=""
29
38
  CHECK=0
30
39
  BRANCH=0
31
40
 
@@ -41,9 +50,11 @@ while (( $# )); do
41
50
  --policy=*) POLICY_ARG="${1#*=}" ;;
42
51
  --name) shift; [[ $# -ge 1 ]] || { echo "missing BRANCH after --name" >&2; exit 2; }; NAME_ARG="$1" ;;
43
52
  --name=*) NAME_ARG="${1#*=}" ;;
53
+ --worktree-script) shift; [[ $# -ge 1 ]] || { echo "missing MODE after --worktree-script" >&2; exit 2; }; WT_SCRIPT="$1" ;;
54
+ --worktree-script=*) WT_SCRIPT="${1#*=}" ;;
44
55
  --branch) BRANCH=1 ;;
45
56
  --check) CHECK=1 ;;
46
- -h|--help) sed -n '2,21p' "${BASH_SOURCE[0]}" | sed 's|^# \{0,1\}||'; exit 0 ;;
57
+ -h|--help) sed -n '2,/^set -euo pipefail/p' "${BASH_SOURCE[0]}" | sed '$d' | sed 's|^# \{0,1\}||'; exit 0 ;;
47
58
  *) echo "unknown argument: $1" >&2; exit 2 ;;
48
59
  esac
49
60
  shift
@@ -60,6 +71,10 @@ START="${ROOT_ARG:-$PWD}"
60
71
  # --head is read by --check and by --branch; standalone it would print the
61
72
  # proposal and drop itself silently.
62
73
  (( CHECK || BRANCH )) || [[ -z "$HEAD_ARG" ]] || { echo "--head is read with --check or --branch; run them together" >&2; exit 2; }
74
+ # --worktree-script prints one path and returns before either mode, so without
75
+ # this guard `--check --worktree-script create` would silently skip the check.
76
+ [[ -z "$WT_SCRIPT" ]] || (( ! CHECK && ! BRANCH )) \
77
+ || { echo "--worktree-script is a mode of its own; run it apart from --check and --branch" >&2; exit 2; }
63
78
  # Absolute, or the walk-up loop below re-reads "." forever.
64
79
  START="$(cd "$START" && pwd -P)"
65
80
 
@@ -316,7 +331,6 @@ hook_points() {
316
331
  case "$1" in
317
332
  pr) printf '%s' "before_create after_create before_merge after_merge" ;;
318
333
  push) printf '%s' "after_push" ;;
319
- worktree) printf '%s' "after_create before_remove" ;;
320
334
  goal) printf '%s' "before_slice after_close" ;;
321
335
  esac
322
336
  }
@@ -398,6 +412,60 @@ pick_artifact() {
398
412
  if path_exists "$candidate"; then printf '%s' "$candidate"; else printf '%s' "$fallback"; fi
399
413
  }
400
414
 
415
+ # wt_script_reason VALUE — succeeds with the reason when a `worktrees.create|remove`
416
+ # value has the wrong shape, fails when it is usable. One path, relative to the
417
+ # project, no arguments: the script is the lifecycle, so a command line here would
418
+ # define a second place it lives. `--check` and `--worktree-script` share this one
419
+ # predicate, so a value cannot pass one mode and fail the other over the same
420
+ # question.
421
+ wt_script_reason() {
422
+ local v="$1"
423
+ case "$v" in
424
+ *[[:space:]]*) printf 'takes one path, no arguments — move the arguments into the script'; return 0 ;;
425
+ /*|~*) printf 'is not a path relative to the project root'; return 0 ;;
426
+ esac
427
+ escapes_root "$v" && { printf 'walks outside the project'; return 0; }
428
+ return 1
429
+ }
430
+
431
+ # --- Worktree script path --------------------------------------------------
432
+ # One question, one answer: which absolute path does a run execute for
433
+ # `worktrees.create` or `worktrees.remove`? A declared path that is gone is a
434
+ # degradation, not an error (D3): warn on stderr naming the key and the missing
435
+ # file, then hand back the built-in. Never writes, never creates a directory, and
436
+ # answers even when the built-in folder has not been installed yet.
437
+ if [[ -n "$WT_SCRIPT" ]]; then
438
+ case "$WT_SCRIPT" in
439
+ create|remove) ;;
440
+ *) echo "unknown --worktree-script: $WT_SCRIPT (expected create or remove)" >&2; exit 2 ;;
441
+ esac
442
+ [[ -n "$CONFIG" ]] || { echo "no .sassywares/config.yaml found — run sassy-setup" >&2; exit 1; }
443
+ # The config's folder is the project root, not the .sassywares folder holding
444
+ # the file: declared paths are relative to the project, like every other key.
445
+ builtin="$ROOT/.sassywares/worktree/$WT_SCRIPT"
446
+ declared="$(yflat "worktrees${US}${WT_SCRIPT}" 2>/dev/null || true)"
447
+ if [[ -z "$declared" ]]; then
448
+ printf '%s\n' "$builtin"
449
+ exit 0
450
+ fi
451
+ # A wrong shape is the same degradation as a missing file: warn with the reason
452
+ # `--check` gives, then hand back the built-in.
453
+ if reason="$(wt_script_reason "$declared")"; then
454
+ echo "warning: worktrees.$WT_SCRIPT: '$declared' $reason — using the built-in .sassywares/worktree/$WT_SCRIPT" >&2
455
+ printf '%s\n' "$builtin"
456
+ exit 0
457
+ fi
458
+ declared_path="$ROOT/${declared#./}"
459
+ if [[ -f "$declared_path" && -x "$declared_path" ]]; then
460
+ # Physical path, so the identity a run inherits never disagrees over /tmp.
461
+ printf '%s\n' "$(cd "$(dirname "$declared_path")" && pwd -P)/$(basename "$declared_path")"
462
+ exit 0
463
+ fi
464
+ echo "warning: worktrees.$WT_SCRIPT names '$declared' but $declared_path is missing or not executable — using the built-in .sassywares/worktree/$WT_SCRIPT" >&2
465
+ printf '%s\n' "$builtin"
466
+ exit 0
467
+ fi
468
+
401
469
  PLANS="$(pick_artifact docs/plans docs/plans)"
402
470
  SOLUTIONS="$(pick_artifact docs/solutions docs/solutions)"
403
471
  HANDBOOKS="$(pick_artifact docs/handbooks docs/handbooks)"
@@ -483,6 +551,7 @@ if (( CHECK )); then
483
551
  # and the run silently falls back to a default the project never chose. The
484
552
  # whitelist is the schema in references/config.md; every key there has a
485
553
  # validator of its own below, so anything landing here is unknown.
554
+ lost_hooks_reported=0
486
555
  while IFS=$'\t' read -r kpath kvalue; do
487
556
  [[ -n "$kpath" ]] || continue
488
557
  key="${kpath//$US/.}"
@@ -497,13 +566,25 @@ if (( CHECK )); then
497
566
  pr.babysit|pr.merge|pr.delete_branch) ;;
498
567
  dogfood.enabled|dogfood.recipe|dogfood.reports|dogfood.timeout) ;;
499
568
  worktrees.enabled|worktrees.dir) ;;
500
- up|down)
501
- # Top-level stack life cycle; see references/config.md. A list or a block
502
- # parses, but the scripts read one command word and its args.
569
+ worktrees.create|worktrees.remove)
570
+ # A single path, no arguments: the script is the lifecycle, so a command
571
+ # line here would define a second place it lives.
503
572
  case "$kvalue" in
504
- \[*|\{*)
505
- bad "$key is a list or block — write one line: $key: <script> <args…> or $key: <skill> <args…>" ;;
573
+ \[*|\{*) bad "$key is a list or block — write one path: $key: scripts/worktrees/${key##*.}" ;;
506
574
  esac ;;
575
+ up|down)
576
+ # Removed with the project-script lifecycle (D3/D11): a run stops and
577
+ # starts through the project's own create/remove, not a key. A soft
578
+ # warning would let a project believe its stack still stops.
579
+ bad "$key is gone — the lifecycle moved into worktrees.create and worktrees.remove. Delete the '$key:' line from .sassywares/config.yaml" ;;
580
+ hooks.worktree|hooks.worktree.*)
581
+ # Same migration: what a worktree needed to prepare or tear down is now
582
+ # inside the project's scripts, which the suite runs instead. One block
583
+ # is one fix, so report it once however many points it lists.
584
+ if (( ! lost_hooks_reported )); then
585
+ bad "hooks.worktree is gone — the lifecycle moved into worktrees.create and worktrees.remove, and those scripts replace it. Delete the 'worktree:' block under hooks in .sassywares/config.yaml"
586
+ lost_hooks_reported=1
587
+ fi ;;
507
588
  worktrees.ports)
508
589
  # Deleted from the schema. The one line that fixes it is the line itself.
509
590
  bad "worktrees.ports is gone — delete the 'ports:' line under worktrees in .sassywares/config.yaml" ;;
@@ -676,7 +757,7 @@ if (( CHECK )); then
676
757
  if [[ -n "$(yflat "hooks${US}pr${US}before_create")" ]]; then
677
758
  bad "hooks.pr.<point> is now nested by head branch — write hooks.pr.\"*\".<point>"
678
759
  fi
679
- for kind in pr push worktree goal; do
760
+ for kind in pr push goal; do
680
761
  while IFS= read -r pat; do
681
762
  [[ -n "$pat" ]] || continue
682
763
  case "$pat" in
@@ -701,14 +782,15 @@ if (( CHECK )); then
701
782
  done
702
783
 
703
784
  # `hooks.<kind>.<head-or-slug>.<point>` is the only shape. hooks.pr has four
704
- # points, hooks.push one, hooks.worktree two, hooks.goal two; any other point
705
- # name is a step that never fires.
785
+ # points, hooks.push one, hooks.goal two; any other point name is a step that
786
+ # never fires. hooks.worktree is reported where the accepted keys are, once.
706
787
  while IFS=$'\t' read -r depth hpath; do
707
788
  [[ -n "$depth" ]] || continue
708
789
  kind="${hpath#hooks$US}"; kind="${kind%%$US*}"
709
790
  case "$kind" in
710
- pr|push|worktree|goal) ;;
711
- *) bad "hooks kind '$kind' is not one of pr|push|worktree|goal"; continue ;;
791
+ pr|push|goal) ;;
792
+ worktree) continue ;;
793
+ *) bad "hooks kind '$kind' is not one of pr|push|goal"; continue ;;
712
794
  esac
713
795
  if [[ "$depth" != "4" ]]; then
714
796
  bad "hooks entry '${hpath//$US/.}' is not key -> point -> list"
@@ -728,7 +810,7 @@ if (( CHECK )); then
728
810
  if [[ "$TOPOLOGY" == "repo" ]]; then
729
811
  note " base for '$HEAD_ARG': $(base_for_head "$HEAD_ARG")"
730
812
  fi
731
- for kind in pr push worktree; do
813
+ for kind in pr push; do
732
814
  for point in $(hook_points "$kind"); do
733
815
  resolved="$(hooks_for_head_point "$HEAD_ARG" "$point" "$kind")"
734
816
  note " head '$HEAD_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
@@ -815,14 +897,9 @@ if (( CHECK )); then
815
897
  esac
816
898
  fi
817
899
 
818
- # An absent pair is a deliberate answer, not a missing setup step: say it so
819
- # `check` and `init` agree, and never propose a command here.
820
- if [[ -z "$(yflat up 2>/dev/null || true)" && -z "$(yflat down 2>/dev/null || true)" ]]; then
821
- note " no lifecycle — no top-level up/down keys"
822
- fi
823
-
824
- # Worktrees: a switch and one mechanical setting. Creating, addressing, and
825
- # refusing all belong to the scripts, so this validates only what a run reads.
900
+ # Worktrees: a switch, one mechanical setting, and the project's own lifecycle
901
+ # scripts. Creating, addressing, and refusing all belong to the scripts, so this
902
+ # validates only what a run reads.
826
903
  wt_on="$(block_value worktrees enabled || true)"
827
904
  case "$wt_on" in
828
905
  "") ;;
@@ -830,6 +907,26 @@ if (( CHECK )); then
830
907
  *) bad "worktrees.enabled '$wt_on' must be true|false" ;;
831
908
  esac
832
909
 
910
+ # worktrees.create/remove name the project's own lifecycle scripts. A declared
911
+ # path that is missing or not executable degrades to the built-in with a
912
+ # warning at run time (D3), so it is a note here, never drift.
913
+ for mode in create remove; do
914
+ declared="$(yflat "worktrees${US}${mode}" 2>/dev/null || true)"
915
+ [[ -n "$declared" ]] || continue
916
+ if reason="$(wt_script_reason "$declared")"; then
917
+ bad "worktrees.$mode: '$declared' $reason"
918
+ elif [[ -f "$ROOT/${declared#./}" && -x "$ROOT/${declared#./}" ]]; then
919
+ note " worktrees.$mode: ${declared#./}"
920
+ # A declared script is the project's file, so its contents are never drift.
921
+ # Without the header the run cannot tell whether it honors the WT_* contract.
922
+ if ! grep -q '^# sassywares:scaffold' "$ROOT/${declared#./}" 2>/dev/null; then
923
+ note " worktrees.$mode: ${declared#./} carries no sassywares:scaffold header — the run cannot tell whether it prints the WT_* block"
924
+ fi
925
+ else
926
+ note " worktrees.$mode '${declared#./}' is missing or not executable — the built-in .sassywares/worktree/$mode is used instead"
927
+ fi
928
+ done
929
+
833
930
  # The mechanics are suite-owned and read-only (D4/D5), so `--check` proves the
834
931
  # installed set byte for byte against the folder this skill ships, using the
835
932
  # skills-lock folder hash. A version header cannot: it is hand-maintained, so
@@ -842,7 +939,7 @@ if (( CHECK )); then
842
939
  "node not found — .sassywares/worktree is unverified (the skills CLI needs node)" \
843
940
  --installed "$ROOT/.sassywares/worktree" \
844
941
  --shipped "$ASSET_WORKTREE"
845
- for helper in create list remove prune; do
942
+ for helper in create list remove; do
846
943
  [[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
847
944
  || bad "missing or not executable: .sassywares/worktree/$helper"
848
945
  done
@@ -863,16 +960,6 @@ if (( CHECK )); then
863
960
  bad "worktrees.enabled but .sassywares/worktree/_lib.sh is missing — re-run setup"
864
961
  fi
865
962
 
866
- # A declared worktree hook is how a project prepares a checkout, so say
867
- # that it resolved — silence reads as "nothing is configured".
868
- for point in after_create before_remove; do
869
- declared="$(yflat "hooks${US}worktree${US}*${US}${point}" 2>/dev/null || true)"
870
- while IFS= read -r entry; do
871
- [[ -n "$entry" ]] || continue
872
- note " hooks.worktree.\"*\".$point: ${entry%% *}"
873
- done < <(list_items "$declared")
874
- done
875
-
876
963
  # A checkout must live outside the working tree — inside it, `git clean
877
964
  # -xdf` deletes uncommitted work and every scanner that ignores .gitignore
878
965
  # crawls a second copy of the source. And a worktree parked on a configured
@@ -1398,23 +1485,6 @@ cat <<'EOF'
1398
1485
  # push: # commit.branch: current only; keyed by the pushed branch
1399
1486
  # "*":
1400
1487
  # after_push: []
1401
- # worktree: # worktrees only; keyed by the checkout's branch
1402
- # "*":
1403
- # after_create: [] # derive .env, seed the database, copy the session in
1404
- # before_remove: [] # drop the database, shut the device
1405
-
1406
- # --- Lifecycle ------------------------------------------------------------
1407
- # How this project's stack starts and stops. Top level, not under worktrees:
1408
- # each key names exactly ONE thing, `<script> <args…>` or `<skill> <args…>`.
1409
- # up: run in the foreground and stop it with SIGTERM, so it must reap its
1410
- # children — a detached or daemonizing up outlives the call and holds the
1411
- # checkout. down: terminate what up started, then exit.
1412
- # A down: naming a skill makes `remove` print `require-hook <name>` and exit 3,
1413
- # because a shell script cannot dispatch a skill. Absent means no lifecycle:
1414
- # nothing is inferred and no command is invented. Ports are the project's — the
1415
- # suite derives none, so two checkouts running the same app collide.
1416
- # up: bin/up # or a declared command: just dev
1417
- # down: bin/down # or: just down
1418
1488
  EOF
1419
1489
  cat <<'EOF'
1420
1490
 
@@ -1423,8 +1493,10 @@ cat <<'EOF'
1423
1493
  # namespace, so two runs never fight over one working tree. enabled: true lets a
1424
1494
  # run offer one instead of working here — the run asks, and stays here unless the
1425
1495
  # answer is yes. It needs commit.branch: new, because `current` never cuts a
1426
- # branch. The scripts in .sassywares/worktree/ own the mechanics; nothing else
1427
- # reads these values.
1496
+ # branch. The built-in scripts in .sassywares/worktree/ own the git mechanics;
1497
+ # create: and remove: name this project's own scripts, which wrap them for
1498
+ # whatever a checkout needs and are what a run executes. Nothing else reads
1499
+ # these values.
1428
1500
  #
1429
1501
  # Repo topology only: a workspace root has no repo to cut a checkout from, and a
1430
1502
  # `none` folder has no git at all. A checkout is addressed by the project's own
@@ -1434,6 +1506,10 @@ worktrees:
1434
1506
  EOF
1435
1507
  kv enabled false 34 '# true = a run may offer its own checkout'
1436
1508
  kv dir '~/.sassywares/worktrees' 34 '# parent of the per-repo folder; ~ is allowed'
1509
+ cat <<'EOF'
1510
+ # create: scripts/worktrees/create # this project's own; runs before and after git
1511
+ # remove: scripts/worktrees/remove # this project's own; stop, then dispose
1512
+ EOF
1437
1513
  cat <<'EOF'
1438
1514
 
1439
1515
  # --- Dogfood --------------------------------------------------------------
@@ -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