@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
@@ -11,6 +11,12 @@
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
17
+ # detect.sh [--root DIR] --sync [--write]
18
+ # merge the existing config onto the template
19
+ # and print it (or write it with --write)
14
20
  #
15
21
  # --policy takes infer|current|new: the skill-level token. infer (the default)
16
22
  # defers to commit.branch in the config, and new is the fallback when the config
@@ -19,6 +25,18 @@
19
25
  # new name can match a base_map family (release/*) and retarget the PR.
20
26
  # --goal SLUG resolves the goal hooks for one goal slug, the same way --head does
21
27
  # for a branch; the slug keys hooks.goal, not a branch.
28
+ # --worktree-script MODE asks one question: which path does a run execute? The
29
+ # config's worktrees.create|remove when it names an executable file, else the
30
+ # built-in .sassywares/worktree/<mode>. A declared path that is gone warns on
31
+ # stderr and falls back; an absent key falls back silently. It never writes and
32
+ # never creates a directory, so it answers even before setup has installed one.
33
+ # --sync is the one mode that writes. It starts from the same proposal the
34
+ # default mode prints, then keeps every line the current file declares and
35
+ # --check accepts — value and same-line trailing comment, byte for byte — and
36
+ # takes every block, key, comment layer, and example the file lacks from the
37
+ # proposal. A malformed value is not accepted, so it comes from the proposal,
38
+ # exactly as --check judges it. A dry run prints the merged file and writes
39
+ # nothing.
22
40
  set -euo pipefail
23
41
 
24
42
  ROOT_ARG=""
@@ -26,8 +44,11 @@ HEAD_ARG=""
26
44
  GOAL_ARG=""
27
45
  POLICY_ARG=""
28
46
  NAME_ARG=""
47
+ WT_SCRIPT=""
29
48
  CHECK=0
30
49
  BRANCH=0
50
+ SYNC=0
51
+ SINGLE=0
31
52
 
32
53
  while (( $# )); do
33
54
  case "$1" in
@@ -41,9 +62,13 @@ while (( $# )); do
41
62
  --policy=*) POLICY_ARG="${1#*=}" ;;
42
63
  --name) shift; [[ $# -ge 1 ]] || { echo "missing BRANCH after --name" >&2; exit 2; }; NAME_ARG="$1" ;;
43
64
  --name=*) NAME_ARG="${1#*=}" ;;
65
+ --worktree-script) shift; [[ $# -ge 1 ]] || { echo "missing MODE after --worktree-script" >&2; exit 2; }; WT_SCRIPT="$1" ;;
66
+ --worktree-script=*) WT_SCRIPT="${1#*=}" ;;
44
67
  --branch) BRANCH=1 ;;
45
68
  --check) CHECK=1 ;;
46
- -h|--help) sed -n '2,21p' "${BASH_SOURCE[0]}" | sed 's|^# \{0,1\}||'; exit 0 ;;
69
+ --sync) SYNC=1 ;;
70
+ --write) SINGLE=1 ;;
71
+ -h|--help) sed -n '2,/^set -euo pipefail/p' "${BASH_SOURCE[0]}" | sed '$d' | sed 's|^# \{0,1\}||'; exit 0 ;;
47
72
  *) echo "unknown argument: $1" >&2; exit 2 ;;
48
73
  esac
49
74
  shift
@@ -54,12 +79,23 @@ START="${ROOT_ARG:-$PWD}"
54
79
  # --branch prints a decision; --check validates a config. One at a time, or the
55
80
  # second is silently ignored.
56
81
  (( BRANCH && CHECK )) && { echo "--branch and --check are separate modes; run them one at a time" >&2; exit 2; }
82
+ # --sync computes the proposal too, so the default print, --check, and --branch
83
+ # would each silently drop it.
84
+ (( ! SYNC )) || (( ! CHECK && ! BRANCH )) \
85
+ || { echo "--sync is a mode of its own; run it apart from --check and --branch" >&2; exit 2; }
86
+ # --write is read by --sync. Alone it would print the proposal and drop itself.
87
+ (( ! SINGLE )) || (( SYNC )) \
88
+ || { echo "--write is read with --sync; run them together" >&2; exit 2; }
57
89
  # --goal resolves hooks inside --check. Anywhere else the flag would print the
58
90
  # proposal and drop itself silently.
59
91
  (( CHECK )) || [[ -z "$GOAL_ARG" ]] || { echo "--goal is read with --check; run them together" >&2; exit 2; }
60
92
  # --head is read by --check and by --branch; standalone it would print the
61
93
  # proposal and drop itself silently.
62
94
  (( CHECK || BRANCH )) || [[ -z "$HEAD_ARG" ]] || { echo "--head is read with --check or --branch; run them together" >&2; exit 2; }
95
+ # --worktree-script prints one path and returns before either mode, so without
96
+ # this guard `--check --worktree-script create` would silently skip the check.
97
+ [[ -z "$WT_SCRIPT" ]] || (( ! CHECK && ! BRANCH && ! SYNC )) \
98
+ || { echo "--worktree-script is a mode of its own; run it apart from --check, --branch, and --sync" >&2; exit 2; }
63
99
  # Absolute, or the walk-up loop below re-reads "." forever.
64
100
  START="$(cd "$START" && pwd -P)"
65
101
 
@@ -316,7 +352,6 @@ hook_points() {
316
352
  case "$1" in
317
353
  pr) printf '%s' "before_create after_create before_merge after_merge" ;;
318
354
  push) printf '%s' "after_push" ;;
319
- worktree) printf '%s' "after_create before_remove" ;;
320
355
  goal) printf '%s' "before_slice after_close" ;;
321
356
  esac
322
357
  }
@@ -398,6 +433,60 @@ pick_artifact() {
398
433
  if path_exists "$candidate"; then printf '%s' "$candidate"; else printf '%s' "$fallback"; fi
399
434
  }
400
435
 
436
+ # wt_script_reason VALUE — succeeds with the reason when a `worktrees.create|remove`
437
+ # value has the wrong shape, fails when it is usable. One path, relative to the
438
+ # project, no arguments: the script is the lifecycle, so a command line here would
439
+ # define a second place it lives. `--check` and `--worktree-script` share this one
440
+ # predicate, so a value cannot pass one mode and fail the other over the same
441
+ # question.
442
+ wt_script_reason() {
443
+ local v="$1"
444
+ case "$v" in
445
+ *[[:space:]]*) printf 'takes one path, no arguments — move the arguments into the script'; return 0 ;;
446
+ /*|~*) printf 'is not a path relative to the project root'; return 0 ;;
447
+ esac
448
+ escapes_root "$v" && { printf 'walks outside the project'; return 0; }
449
+ return 1
450
+ }
451
+
452
+ # --- Worktree script path --------------------------------------------------
453
+ # One question, one answer: which absolute path does a run execute for
454
+ # `worktrees.create` or `worktrees.remove`? A declared path that is gone is a
455
+ # degradation, not an error (D3): warn on stderr naming the key and the missing
456
+ # file, then hand back the built-in. Never writes, never creates a directory, and
457
+ # answers even when the built-in folder has not been installed yet.
458
+ if [[ -n "$WT_SCRIPT" ]]; then
459
+ case "$WT_SCRIPT" in
460
+ create|remove) ;;
461
+ *) echo "unknown --worktree-script: $WT_SCRIPT (expected create or remove)" >&2; exit 2 ;;
462
+ esac
463
+ [[ -n "$CONFIG" ]] || { echo "no .sassywares/config.yaml found — run sassy-setup" >&2; exit 1; }
464
+ # The config's folder is the project root, not the .sassywares folder holding
465
+ # the file: declared paths are relative to the project, like every other key.
466
+ builtin="$ROOT/.sassywares/worktree/$WT_SCRIPT"
467
+ declared="$(yflat "worktrees${US}${WT_SCRIPT}" 2>/dev/null || true)"
468
+ if [[ -z "$declared" ]]; then
469
+ printf '%s\n' "$builtin"
470
+ exit 0
471
+ fi
472
+ # A wrong shape is the same degradation as a missing file: warn with the reason
473
+ # `--check` gives, then hand back the built-in.
474
+ if reason="$(wt_script_reason "$declared")"; then
475
+ echo "warning: worktrees.$WT_SCRIPT: '$declared' $reason — using the built-in .sassywares/worktree/$WT_SCRIPT" >&2
476
+ printf '%s\n' "$builtin"
477
+ exit 0
478
+ fi
479
+ declared_path="$ROOT/${declared#./}"
480
+ if [[ -f "$declared_path" && -x "$declared_path" ]]; then
481
+ # Physical path, so the identity a run inherits never disagrees over /tmp.
482
+ printf '%s\n' "$(cd "$(dirname "$declared_path")" && pwd -P)/$(basename "$declared_path")"
483
+ exit 0
484
+ fi
485
+ echo "warning: worktrees.$WT_SCRIPT names '$declared' but $declared_path is missing or not executable — using the built-in .sassywares/worktree/$WT_SCRIPT" >&2
486
+ printf '%s\n' "$builtin"
487
+ exit 0
488
+ fi
489
+
401
490
  PLANS="$(pick_artifact docs/plans docs/plans)"
402
491
  SOLUTIONS="$(pick_artifact docs/solutions docs/solutions)"
403
492
  HANDBOOKS="$(pick_artifact docs/handbooks docs/handbooks)"
@@ -412,8 +501,10 @@ case "$TOPOLOGY" in
412
501
  repo)
413
502
  REPO_NAME="$(remote_name "$ROOT")"
414
503
  REPO_NAME="${REPO_NAME:-origin}"
415
- # A check run reads the base from the config; probing costs a network call.
416
- (( CHECK )) || DEFAULT_BRANCH="$(detect_base "$ROOT")"
504
+ # A check or sync run reads the base from the config; probing costs a
505
+ # network call. A sync keeps the file's base when it has a valid one and
506
+ # leaves the placeholder when it does not, for a human to confirm.
507
+ (( CHECK || SYNC )) || DEFAULT_BRANCH="$(detect_base "$ROOT")"
417
508
  ;;
418
509
  workspace)
419
510
  MIRROR_REMOTE="$(config_value remote 2>/dev/null || true)"
@@ -422,6 +513,529 @@ case "$TOPOLOGY" in
422
513
  ;;
423
514
  esac
424
515
 
516
+ # --- Template merge -------------------------------------------------------
517
+ # --sync starts from the proposal the default mode prints (emit_proposal) and
518
+ # merges the existing file onto it: a leaf the file declares and this check
519
+ # accepts keeps its line — value and same-line trailing comment — exactly as
520
+ # written, and every block, key, comment layer, and example the file lacks comes
521
+ # from the proposal. A value --check reports as drift is not accepted, so it is
522
+ # replaced by the proposal's, the same judgement --check makes.
523
+ #
524
+ # "Value --check accepts" is one predicate, leaf_ok, over the schema in
525
+ # references/config.md. It deliberately validates only the value, never its
526
+ # context: a `worktrees.enabled: true` with no tooling installed is a valid value
527
+ # in a wrong state, so the sync keeps it and the check keeps reporting it.
528
+ leaf_ok() { # PATH VALUE — PATH joined with US, value comment- and quote-stripped
529
+ local path="$1" v="$2" key kind rest pat point entry name
530
+ key="${path//$US/.}"
531
+ case "$key" in
532
+ artifacts.plans|artifacts.solutions|artifacts.handbooks|artifacts.concepts)
533
+ case "$v" in ""|/*|~*|.|./) return 1 ;; esac
534
+ escapes_root "$v" && return 1
535
+ [[ "$key" == "artifacts.concepts" && "$v" == */ ]] && return 1
536
+ return 0 ;;
537
+ knowledge.read)
538
+ case "$v" in \[*\]) ;; *) return 1 ;; esac
539
+ while IFS= read -r entry; do
540
+ [[ -n "$entry" ]] || continue
541
+ case "$entry" in /*|~*) return 1 ;; esac
542
+ escapes_root "$entry" && return 1
543
+ done < <(list_items "$v")
544
+ return 0 ;;
545
+ knowledge.write|pr.babysit|pr.merge|pr.delete_branch|dogfood.enabled|worktrees.enabled)
546
+ [[ "$v" == "true" || "$v" == "false" ]] ;;
547
+ git.repo)
548
+ if [[ "$TOPOLOGY" == "repo" ]]; then
549
+ case "$v" in ""|workspace|none) return 1 ;; esac
550
+ git -C "$ROOT" remote 2>/dev/null | grep -qx "$v"
551
+ else
552
+ [[ "$v" == "workspace" || "$v" == "none" ]]
553
+ fi ;;
554
+ git.remote|git.mirror_branch)
555
+ [[ "$TOPOLOGY" != "repo" && -n "$v" ]] ;;
556
+ git.base_map.*)
557
+ pat="${key#git.base_map.}"
558
+ case "$pat" in
559
+ *"*") [[ "$pat" == "*" || ( -n "${pat%\*}" && "${pat%\*}" != *"*" ) ]] || return 1 ;;
560
+ esac
561
+ return 0 ;;
562
+ repos.*)
563
+ [[ "$TOPOLOGY" != "repo" ]] ;;
564
+ commit.branch)
565
+ [[ "$v" == "current" || "$v" == "new" ]] ;;
566
+ dogfood.timeout)
567
+ [[ "$v" =~ ^[1-9][0-9]*$ ]] ;;
568
+ dogfood.recipe|dogfood.reports)
569
+ case "$v" in ""|/*|~*|.|./) return 1 ;; esac
570
+ escapes_root "$v" && return 1
571
+ return 0 ;;
572
+ worktrees.dir)
573
+ [[ -n "$v" ]] ;;
574
+ worktrees.create|worktrees.remove)
575
+ ! wt_script_reason "$v" >/dev/null ;;
576
+ hooks.*)
577
+ kind="${key#hooks.}"; kind="${kind%%.*}"
578
+ case "$kind" in pr|push|goal) ;; *) return 1 ;; esac
579
+ rest="${key#hooks.}"; rest="${rest#*.}"
580
+ point="${rest##*.}"
581
+ pat="${rest%.*}"
582
+ case " $(hook_points "$kind") " in *" $point "*) ;; *) return 1 ;; esac
583
+ case "$pat" in
584
+ *"*") [[ "$pat" == "*" || ( -n "${pat%\*}" && "${pat%\*}" != *"*" ) ]] || return 1 ;;
585
+ esac
586
+ while IFS= read -r entry; do
587
+ [[ -n "$entry" ]] || continue
588
+ name="${entry%% *}"
589
+ is_suite_skill "$name" && return 1
590
+ hook_skill_path "$name" >/dev/null 2>&1 || return 1
591
+ done < <(list_items "$v")
592
+ return 0 ;;
593
+ *)
594
+ return 1 ;;
595
+ esac
596
+ }
597
+
598
+ # One parser, two readers: the flat path stack is the same shape yaml_flat
599
+ # builds, so a line can be matched to the current file and to the proposal.
600
+ LEAF_AWK='function trim(s) { sub(/^[ \t]+/, "", s); sub(/[ \t]+$/, "", s); return s }
601
+ function ind(s, m) { m = match(s, /^ */); return m ? RLENGTH : 0 }
602
+ {
603
+ raw = $0
604
+ body0 = trim(raw)
605
+ if (body0 == "" || substr(body0, 1, 1) == "#") next
606
+ line = raw; sub(/#.*$/, "", line)
607
+ d = ind(line); body = trim(line)
608
+ if (body ~ /:$/) {
609
+ k = body; sub(/:$/, "", k); gsub(/"/, "", k)
610
+ while (sp > 0 && sd[sp] >= d) sp--
611
+ sd[++sp] = d; sk[sp] = k
612
+ next
613
+ }
614
+ k = body; sub(/:.*/, "", k); gsub(/"/, "", k)
615
+ while (sp > 0 && sd[sp] >= d) sp--
616
+ p = ""
617
+ for (i = 1; i <= sp; i++) p = p (p == "" ? "" : us) sk[i]
618
+ print p (p == "" ? "" : us) k "\t" raw
619
+ }'
620
+
621
+ # The merge. Records are `kind <TAB> depth <TAB> path <TAB> raw`; a commented
622
+ # example is a record too, with the depth its `#` markers would have if removed
623
+ # (the hash characters themselves add no depth, the spaces after them do), so
624
+ # `# push:` under `hooks:` is known to be the posited `hooks.push` block. When the
625
+ # file declares a valid leaf under such an example, the example is replaced by
626
+ # the file's own active block, verbatim — the one case where a commented example
627
+ # in the proposal is not an example for this project.
628
+ MERGE_AWK='function trim(s) { sub(/^[ \t]+/, "", s); sub(/[ \t]+$/, "", s); return s }
629
+ function ind(s, m) { m = match(s, /^ */); return m ? RLENGTH : 0 }
630
+ function joinall( p, i) { p = ""; for (i = 1; i <= sp; i++) p = p (p == "" ? "" : us) sk[i]; return p }
631
+ function dopop(d) { while (sp > 0 && sd[sp] >= d) sp-- }
632
+ function outf(r, p) { o++; oraw[o] = r; okind[o] = ""; opath[o] = p }
633
+ function outfk(r, d, p) { o++; oraw[o] = r; okind[o] = "key"; odepth[o] = d; opath[o] = p }
634
+ function outfl(r, d, p) { o++; oraw[o] = r; okind[o] = "leaf"; odepth[o] = d; opath[o] = p }
635
+ function under_accepted(P, a) {
636
+ for (a = 1; a <= na; a++) if (index(aorder[a], P us) == 1) return 1
637
+ return 0
638
+ }
639
+ function emit_acc(P, d) { o++; oraw[o] = acc[P]; okind[o] = "leaf"; odepth[o] = d; opath[o] = P; emitted[P] = 1 }
640
+ function emit_block(P, i, j, e, a) {
641
+ b0 = 0
642
+ for (i = 1; i <= cn; i++) if (ckind[i] == "key" && cpath[i] == P) { b0 = i; break }
643
+ if (b0 == 0) { warn[++nw] = P; return }
644
+ e = b0
645
+ for (j = b0 + 1; j <= cn; j++) {
646
+ if (ckind[j] == "blank") continue
647
+ if (cdepth[j] > cdepth[b0]) { e = j; continue }
648
+ break
649
+ }
650
+ for (j = b0; j <= e; j++) {
651
+ if (ckind[j] == "key") outfk(crawl[j], cdepth[j], cpath[j])
652
+ else if (ckind[j] == "leaf") outfl(crawl[j], cdepth[j], cpath[j])
653
+ else outf(crawl[j])
654
+ }
655
+ for (a = 1; a <= na; a++) if (index(aorder[a], P us) == 1) emitted[aorder[a]] = 1
656
+ emitted[P] = 1
657
+ }
658
+ BEGIN { cn = 0; pn = 0; na = 0; sp = 0; o = 0; nw = 0 }
659
+ FILENAME == accf {
660
+ if ($2 != "") { acc[$1] = $2; aorder[++na] = $1 }
661
+ next
662
+ }
663
+ FILENAME == curf {
664
+ raw = $0
665
+ body0 = trim(raw)
666
+ if (body0 == "") { ckind[++cn] = "blank"; crawl[cn] = raw; next }
667
+ if (substr(body0, 1, 1) == "#") { ckind[++cn] = "comment"; crawl[cn] = raw; next }
668
+ line = raw; sub(/#.*$/, "", line)
669
+ d = ind(line); body = trim(line)
670
+ if (body ~ /:$/) {
671
+ k = body; sub(/:$/, "", k); gsub(/"/, "", k)
672
+ dopop(d); sd[++sp] = d; sk[sp] = k
673
+ ckind[++cn] = "key"; cdepth[cn] = d; cpath[cn] = joinall(); crawl[cn] = raw
674
+ } else {
675
+ k = body; sub(/:.*/, "", k); gsub(/"/, "", k)
676
+ dopop(d); p = joinall()
677
+ ckind[++cn] = "leaf"; cdepth[cn] = d; cpath[cn] = p (p == "" ? "" : us) k; crawl[cn] = raw
678
+ }
679
+ next
680
+ }
681
+ FILENAME == propf {
682
+ raw = $0
683
+ body0 = trim(raw)
684
+ if (body0 == "") { pkind[++pn] = "blank"; pdepth[pn] = 0; ppath[pn] = ""; praw[pn] = raw; next }
685
+ if (substr(body0, 1, 1) == "#") {
686
+ rest = body0
687
+ while (substr(rest, 1, 1) == "#") rest = substr(rest, 2)
688
+ m = match(rest, /^ */); spc = m ? RLENGTH : 0
689
+ rest = substr(rest, spc + 1)
690
+ # A commented example sits at its `#` column, and its content starts two
691
+ # columns later ("# "); the spaces after the marker encode the depth of a
692
+ # child, so subtracting the marker leaves the line the example stands for.
693
+ ed = ind(raw) + (spc > 0 ? spc - 1 : 0)
694
+ if (rest ~ /^[^ \t:]+:/) {
695
+ k = rest; sub(/:.*/, "", k); gsub(/"/, "", k)
696
+ v = rest; sub(/^[^:]*:/, "", v); sub(/#.*/, "", v); v = trim(v)
697
+ dopop(ed)
698
+ if (v == "") {
699
+ sd[++sp] = ed; sk[sp] = k
700
+ pkind[++pn] = "example_key"; pdepth[pn] = ed; ppath[pn] = joinall(); praw[pn] = raw
701
+ } else {
702
+ p = joinall()
703
+ pkind[++pn] = "example_leaf"; pdepth[pn] = ed
704
+ ppath[pn] = p (p == "" ? "" : us) k; praw[pn] = raw
705
+ }
706
+ } else {
707
+ pkind[++pn] = "comment"; pdepth[pn] = 0; ppath[pn] = ""; praw[pn] = raw
708
+ }
709
+ next
710
+ }
711
+ line = raw; sub(/#.*$/, "", line)
712
+ d = ind(line); body = trim(line)
713
+ if (body ~ /:$/) {
714
+ k = body; sub(/:$/, "", k); gsub(/"/, "", k)
715
+ dopop(d); sd[++sp] = d; sk[sp] = k
716
+ pkind[++pn] = "key"; pdepth[pn] = d; ppath[pn] = joinall(); praw[pn] = raw
717
+ } else {
718
+ k = body; sub(/:.*/, "", k); gsub(/"/, "", k)
719
+ dopop(d); p = joinall()
720
+ pkind[++pn] = "leaf"; pdepth[pn] = d
721
+ ppath[pn] = p (p == "" ? "" : us) k; praw[pn] = raw
722
+ }
723
+ next
724
+ }
725
+ END {
726
+ i = 1
727
+ while (i <= pn) {
728
+ if (pkind[i] == "blank" || pkind[i] == "comment") { outf(praw[i]); i++; continue }
729
+ if (pkind[i] == "example_key") {
730
+ j = i + 1
731
+ while (j <= pn && (pkind[j] == "example_key" || pkind[j] == "example_leaf") && pdepth[j] > pdepth[i]) j++
732
+ if (under_accepted(ppath[i])) {
733
+ emit_block(ppath[i])
734
+ } else {
735
+ for (m = i; m < j; m++) outf(praw[m])
736
+ }
737
+ i = j; continue
738
+ }
739
+ if (pkind[i] == "example_leaf") {
740
+ if (ppath[i] in acc) emit_acc(ppath[i], pdepth[i]); else outf(praw[i])
741
+ i++; continue
742
+ }
743
+ if (pkind[i] == "leaf") {
744
+ if (ppath[i] in acc) emit_acc(ppath[i], pdepth[i]); else outfl(praw[i], pdepth[i], ppath[i])
745
+ i++; continue
746
+ }
747
+ outfk(praw[i], pdepth[i], ppath[i])
748
+ i++
749
+ }
750
+ # An accepted leaf the proposal has no slot for — an extra base_map rung, a
751
+ # hand-written head — is inserted under its own block, after the last line
752
+ # of that block. Dropping it would be the one thing the sync must never do:
753
+ # change a value the check accepts.
754
+ for (a = 1; a <= na; a++) {
755
+ P = aorder[a]
756
+ if (P in emitted) continue
757
+ par = P; sub(us "[^" us "]*$", "", par)
758
+ if (par == P) { warn[++nw] = P; continue }
759
+ b0 = 0; bd = -1
760
+ for (m = 1; m <= o; m++) if (okind[m] == "key" && opath[m] == par) { b0 = m; bd = odepth[m] }
761
+ if (b0 == 0) { warn[++nw] = P; continue }
762
+ last = b0
763
+ for (m = b0 + 1; m <= o; m++) {
764
+ if (okind[m] == "blank") continue
765
+ if (odepth[m] <= bd) break
766
+ last = m
767
+ }
768
+ insn[last]++
769
+ insraw[last, insn[last]] = acc[P]
770
+ }
771
+ for (m = 1; m <= o; m++) {
772
+ print oraw[m]
773
+ for (q = 1; q <= insn[m]; q++) print insraw[m, q]
774
+ }
775
+ for (m = 1; m <= nw; m++) print "sync: no slot for " warn[m] > "/dev/stderr"
776
+ }'
777
+
778
+ leaf_lines() { # FILE -> `path<TAB>raw line` for every active leaf
779
+ awk -v us="$US" "$LEAF_AWK" "$1"
780
+ }
781
+
782
+ accepted_table() { # -> `path<TAB>raw line` for every leaf --check accepts today
783
+ local path raw value
784
+ leaf_lines "$CONFIG" | while IFS=$'\t' read -r path raw; do
785
+ [[ -n "$path" ]] || continue
786
+ value="$(printf '%s' "$raw" \
787
+ | sed -E 's/^[[:space:]]*[^:]*:[[:space:]]*//; s/[[:space:]]+#.*$//; s/[[:space:]]+$//')"
788
+ value="${value#\"}"; value="${value%\"}"
789
+ if leaf_ok "$path" "$value"; then printf '%s\t%s\n' "$path" "$raw"; fi
790
+ done
791
+ }
792
+
793
+ merged_config() { # the current file merged onto the proposal, on stdout
794
+ local prop acc
795
+ prop="$(mktemp "${TMPDIR:-/tmp}/sassy-sync-proposal.XXXXXX")"
796
+ acc="$(mktemp "${TMPDIR:-/tmp}/sassy-sync-accepted.XXXXXX")"
797
+ emit_proposal > "$prop"
798
+ accepted_table > "$acc"
799
+ awk -F'\t' -v us="$US" -v accf="$acc" -v curf="$CONFIG" -v propf="$prop" \
800
+ "$MERGE_AWK" "$acc" "$CONFIG" "$prop"
801
+ rm -f "$prop" "$acc"
802
+ }
803
+
804
+ sync_phrase() { # MERGED -> what --sync --write would do, for the check's note
805
+ local merged="$1" cur_paths merged_paths acc_paths added="" replaced="" p raw out
806
+ cur_paths="$(leaf_lines "$CONFIG" | cut -f1)"
807
+ merged_paths="$(printf '%s\n' "$merged" | leaf_lines /dev/stdin | cut -f1)"
808
+ acc_paths="$(accepted_table | cut -f1)"
809
+ added="$(comm -13 <(printf '%s\n' "$cur_paths" | sort -u) <(printf '%s\n' "$merged_paths" | sort -u) 2>/dev/null \
810
+ | cut -d"$US" -f1 | sort -u | grep -v '^$' | paste -sd, - | sed 's/,/, /g' || true)"
811
+ while IFS=$'\t' read -r p raw; do
812
+ [[ -n "$p" ]] || continue
813
+ grep -qxF "$p" <<< "$acc_paths" && continue
814
+ grep -qxF "$p" <<< "$merged_paths" || continue
815
+ replaced="${replaced:+$replaced, }${p//$US/.}"
816
+ done < <(leaf_lines "$CONFIG")
817
+ if [[ -z "$added" && -z "$replaced" ]]; then printf 'refresh the comments'; return; fi
818
+ out=""
819
+ [[ -n "$added" ]] && out="add $added"
820
+ [[ -n "$replaced" ]] && out="${out:+$out; }replace $replaced (not valid today)"
821
+ printf '%s and refresh the comments' "$out"
822
+ }
823
+
824
+ # --- Emit a proposal -------------------------------------------------------
825
+ # One function, two callers: the default mode prints it, and --sync/--check
826
+ # merge onto it. Everything it reads (PLANS, REPO_NAME, TOPOLOGY, DEFAULT_BRANCH,
827
+ # MIRROR_*) is computed above, before either caller runs.
828
+ emit_proposal() {
829
+ # Every key carries its meaning and its allowed values. The file is the
830
+ # documentation a teammate reads, so the comments are part of the output, not
831
+ # decoration to be stripped.
832
+
833
+ # kv KEY VALUE WIDTH COMMENT [INDENT] — prints "key: value" padded so comments
834
+ # align. WIDTH 0 means no padding.
835
+ kv() {
836
+ local indent="${5:- }" line
837
+ line="$indent$1: $2"
838
+ if [[ -n "${4:-}" && "${3:-0}" != "0" ]]; then
839
+ printf '%-*s%s\n' "$3" "$line" "$4"
840
+ elif [[ -n "${4:-}" ]]; then
841
+ printf '%s %s\n' "$line" "$4"
842
+ else
843
+ printf '%s\n' "$line"
844
+ fi
845
+ }
846
+
847
+ cat <<EOF
848
+ # Sassy Skills project config — written by sassy-setup.
849
+ # Every key is optional: delete a line to fall back to the documented default.
850
+ # Guide: https://github.com/sassywares/sassy-skills/blob/main/skills/sassy-setup/references/config.md
851
+
852
+ # --- Artifacts ------------------------------------------------------------
853
+ # Where sassy writes its documents. Paths are relative to this file's folder.
854
+ artifacts:
855
+ EOF
856
+ kv plans "$PLANS" 34 '# sassy-plan writes plans here'
857
+ kv solutions "$SOLUTIONS" 34 '# sassy-compound writes learnings here'
858
+ kv handbooks "$HANDBOOKS" 34 '# sassy-handbook writes handovers here'
859
+ kv concepts "$CONCEPTS" 34 '# the glossary sassy-compound maintains (a file)'
860
+ cat <<EOF
861
+
862
+ # --- Knowledge ------------------------------------------------------------
863
+ # read: folders and files searched for prior learnings before planning or
864
+ # debugging. Any paths; one that does not exist is skipped, not fatal.
865
+ # write: true | false — false means this project takes no learnings.
866
+ knowledge:
867
+ EOF
868
+ kv read "[$SOLUTIONS, $CONCEPTS]" 0
869
+ kv write true 34 '# true | false'
870
+
871
+ case "$TOPOLOGY" in
872
+ repo)
873
+ cat <<EOF
874
+
875
+ # --- Git ------------------------------------------------------------------
876
+ # repo: a remote name (this folder is the repo) | workspace (repos live below,
877
+ # this folder is not a repo) | none (no git anywhere here).
878
+ # base_map: the base for a HEAD branch, so a PR targets the right rung.
879
+ # "*" is ordinary work; add a rung for a branch that releases elsewhere.
880
+ git:
881
+ EOF
882
+ kv repo "$REPO_NAME" 0
883
+ printf ' base_map:\n'
884
+ if [[ -n "$DEFAULT_BRANCH" ]]; then
885
+ printf ' "*": %s # probed — confirm this is where ordinary work branches from\n' "$DEFAULT_BRANCH"
886
+ else
887
+ printf ' "*": %s # base for ordinary work; never guessed\n' "<confirm by hand>"
888
+ fi
889
+ printf ' # staging: main # uncomment when a branch releases somewhere else\n'
890
+ printf ' # release/*: main # a family of heads, longest prefix wins\n'
891
+ cat <<'EOF'
892
+ # remote: owner/backup # workspace only: the snapshot mirror
893
+ # mirror_branch: main # workspace only: the mirror's branch
894
+
895
+ # workspace only: each nested repo folder -> the base its PRs target
896
+ # repos:
897
+ # fe: dev
898
+ EOF
899
+ ;;
900
+ workspace)
901
+ cat <<EOF
902
+
903
+ # --- Git ------------------------------------------------------------------
904
+ # repo: workspace means repos live below and this folder is not a repo.
905
+ # remote: the snapshot mirror (GitHub owner/name or URL), required here.
906
+ # mirror_branch: the branch the mirror pushes to. Not a PR base — nested repos
907
+ # carry their own, and a workspace has no branches of its own.
908
+ git:
909
+ EOF
910
+ kv repo workspace 0
911
+ kv remote "${MIRROR_REMOTE:-<set the snapshot mirror, owner/name or URL>}" 0
912
+ kv mirror_branch "$MIRROR_BRANCH" 0
913
+ cat <<'EOF'
914
+
915
+ # --- Repos ----------------------------------------------------------------
916
+ # Every nested repo -> the base its PRs target. A touched repo missing here is
917
+ # a question, never a default.
918
+ repos:
919
+ EOF
920
+ any=0
921
+ while IFS= read -r name; do
922
+ [[ -n "$name" ]] || continue
923
+ base="$(detect_base "$ROOT/$name")"
924
+ if [[ -n "$base" ]]; then
925
+ kv "$name" "$base" 34 '# probed — confirm the PR base'
926
+ else
927
+ kv "$name" "<confirm>" 34 '# base unknown; confirm by hand'
928
+ fi
929
+ any=1
930
+ done < <(nested_repos)
931
+ (( any )) || printf ' # no nested repos found\n'
932
+ ;;
933
+ *)
934
+ cat <<EOF
935
+
936
+ # --- Git ------------------------------------------------------------------
937
+ # repo: none means this folder is deliberately outside git: commit, PR, and
938
+ # babysit refuse here, and work still leaves its changes on disk.
939
+ git:
940
+ EOF
941
+ kv repo none 0
942
+ ;;
943
+ esac
944
+
945
+ cat <<'EOF'
946
+
947
+ # --- Commit ---------------------------------------------------------------
948
+ # current: commit on the checked-out branch, even on a base branch, then push
949
+ # it to its upstream. No PR: pr.* and hooks.pr are ignored; hooks.push runs.
950
+ # new: never commit on a base branch — sassy-work, sassy-lfg, and sassy-debug
951
+ # cut a branch at the start of the run and stay on it.
952
+ commit:
953
+ EOF
954
+ kv branch new 34 '# current | new'
955
+ cat <<'EOF'
956
+
957
+ # --- Pull requests --------------------------------------------------------
958
+ pr:
959
+ EOF
960
+ kv babysit true 24 '# true | false — babysit the PR this run opened'
961
+ kv merge false 24 '# true = merge every babysat PR here'
962
+ kv delete_branch false 24 '# true | false — delete the head branch once merged'
963
+ cat <<'EOF'
964
+
965
+ # --- Hooks ----------------------------------------------------------------
966
+ # Project steps injected into the PR pipeline, after a push under
967
+ # commit.branch: current, across a worktree's life, or around a goal. Keyed by
968
+ # the branch — the branch the PR comes from, never the one it targets — or by the
969
+ # goal slug for hooks.goal. `"*"` is the default; a name overrides per point, and
970
+ # `release/*` matches a family. Each entry is `<skill> <args…>`, resolved at
971
+ # .agents/skills/<name>/SKILL.md; args are passed to the skill verbatim. Declared
972
+ # order, one worker each, missing skill fails closed.
973
+ hooks:
974
+ pr:
975
+ "*":
976
+ EOF
977
+ kv before_create '[]' 30 '# after the commit, before the PR opens' ' '
978
+ kv after_create '[]' 30 '# the PR was just created' ' '
979
+ kv before_merge '[]' 30 '# this run is about to merge' ' '
980
+ kv after_merge '[]' 30 '# this run observed the merge' ' '
981
+ cat <<'EOF'
982
+ # staging: # per-point override for one head branch
983
+ # before_create: []
984
+ # release/*: # a family of heads
985
+ # after_merge: [notify mode:auto]
986
+ goal: # keyed by the goal slug (the folder under artifacts.plans)
987
+ "*":
988
+ EOF
989
+ kv before_slice '[]' 30 '# sassy-goal mode:next: after the previous slice merges' ' '
990
+ kv after_close '[]' 30 '# sassy-goal mode:close: after the status is persisted' ' '
991
+ cat <<'EOF'
992
+ # migration-v2: # one goal, by slug
993
+ # before_slice: [db-migrate mode:auto]
994
+ # push: # commit.branch: current only; keyed by the pushed branch
995
+ # "*":
996
+ # after_push: []
997
+ EOF
998
+ cat <<'EOF'
999
+
1000
+ # --- Worktrees ------------------------------------------------------------
1001
+ # Parallel work in one repo: a checkout per branch, each with its own derived
1002
+ # namespace, so two runs never fight over one working tree. enabled: true lets a
1003
+ # run offer one instead of working here — the run asks, and stays here unless the
1004
+ # answer is yes. It needs commit.branch: new, because `current` never cuts a
1005
+ # branch. The built-in scripts in .sassywares/worktree/ own the git mechanics;
1006
+ # create: and remove: name this project's own scripts, which wrap them for
1007
+ # whatever a checkout needs and are what a run executes. Nothing else reads
1008
+ # these values.
1009
+ #
1010
+ # Repo topology only: a workspace root has no repo to cut a checkout from, and a
1011
+ # `none` folder has no git at all. A checkout is addressed by the project's own
1012
+ # stack, not by the suite: a port is the project's business, and this block
1013
+ # carries no range.
1014
+ worktrees:
1015
+ EOF
1016
+ kv enabled false 34 '# true = a run may offer its own checkout'
1017
+ kv dir '~/.sassywares/worktrees' 34 '# parent of the per-repo folder; ~ is allowed'
1018
+ cat <<'EOF'
1019
+ # create: scripts/worktrees/create # this project's own; runs before and after git
1020
+ # remove: scripts/worktrees/remove # this project's own; stop, then dispose
1021
+ EOF
1022
+ cat <<'EOF'
1023
+
1024
+ # --- Dogfood --------------------------------------------------------------
1025
+ # Agent QA: a stored procedure that proves a change works in the running
1026
+ # product. This block only points at it — commands live in the recipe, because
1027
+ # a copy here would duplicate the manifest and could not express step order.
1028
+ # The recipe ends each section in a `Prove it:` step whose exit code is the
1029
+ # verdict. enabled: true lets a plan write Mode: Auto QA rows, but only for a
1030
+ # section that actually has one.
1031
+ dogfood:
1032
+ EOF
1033
+ kv enabled false 42 '# true = plan writes Auto QA rows; false = all Manual'
1034
+ kv recipe .sassywares/dogfood/recipe.md 42 '# the procedure; sassy-dogfood writes it'
1035
+ kv reports .sassywares/dogfood/reports 42 '# run output; must stay gitignored'
1036
+ kv timeout 900 42 '# seconds for the whole procedure'
1037
+ }
1038
+
425
1039
  if (( CHECK )); then
426
1040
  drift=0
427
1041
  note() { printf '%s\n' "$*"; }
@@ -483,6 +1097,7 @@ if (( CHECK )); then
483
1097
  # and the run silently falls back to a default the project never chose. The
484
1098
  # whitelist is the schema in references/config.md; every key there has a
485
1099
  # validator of its own below, so anything landing here is unknown.
1100
+ lost_hooks_reported=0
486
1101
  while IFS=$'\t' read -r kpath kvalue; do
487
1102
  [[ -n "$kpath" ]] || continue
488
1103
  key="${kpath//$US/.}"
@@ -497,13 +1112,25 @@ if (( CHECK )); then
497
1112
  pr.babysit|pr.merge|pr.delete_branch) ;;
498
1113
  dogfood.enabled|dogfood.recipe|dogfood.reports|dogfood.timeout) ;;
499
1114
  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.
1115
+ worktrees.create|worktrees.remove)
1116
+ # A single path, no arguments: the script is the lifecycle, so a command
1117
+ # line here would define a second place it lives.
503
1118
  case "$kvalue" in
504
- \[*|\{*)
505
- bad "$key is a list or block — write one line: $key: <script> <args…> or $key: <skill> <args…>" ;;
1119
+ \[*|\{*) bad "$key is a list or block — write one path: $key: scripts/worktrees/${key##*.}" ;;
506
1120
  esac ;;
1121
+ up|down)
1122
+ # Removed with the project-script lifecycle (D3/D11): a run stops and
1123
+ # starts through the project's own create/remove, not a key. A soft
1124
+ # warning would let a project believe its stack still stops.
1125
+ bad "$key is gone — the lifecycle moved into worktrees.create and worktrees.remove. Delete the '$key:' line from .sassywares/config.yaml" ;;
1126
+ hooks.worktree|hooks.worktree.*)
1127
+ # Same migration: what a worktree needed to prepare or tear down is now
1128
+ # inside the project's scripts, which the suite runs instead. One block
1129
+ # is one fix, so report it once however many points it lists.
1130
+ if (( ! lost_hooks_reported )); then
1131
+ 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"
1132
+ lost_hooks_reported=1
1133
+ fi ;;
507
1134
  worktrees.ports)
508
1135
  # Deleted from the schema. The one line that fixes it is the line itself.
509
1136
  bad "worktrees.ports is gone — delete the 'ports:' line under worktrees in .sassywares/config.yaml" ;;
@@ -676,7 +1303,7 @@ if (( CHECK )); then
676
1303
  if [[ -n "$(yflat "hooks${US}pr${US}before_create")" ]]; then
677
1304
  bad "hooks.pr.<point> is now nested by head branch — write hooks.pr.\"*\".<point>"
678
1305
  fi
679
- for kind in pr push worktree goal; do
1306
+ for kind in pr push goal; do
680
1307
  while IFS= read -r pat; do
681
1308
  [[ -n "$pat" ]] || continue
682
1309
  case "$pat" in
@@ -701,14 +1328,15 @@ if (( CHECK )); then
701
1328
  done
702
1329
 
703
1330
  # `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.
1331
+ # points, hooks.push one, hooks.goal two; any other point name is a step that
1332
+ # never fires. hooks.worktree is reported where the accepted keys are, once.
706
1333
  while IFS=$'\t' read -r depth hpath; do
707
1334
  [[ -n "$depth" ]] || continue
708
1335
  kind="${hpath#hooks$US}"; kind="${kind%%$US*}"
709
1336
  case "$kind" in
710
- pr|push|worktree|goal) ;;
711
- *) bad "hooks kind '$kind' is not one of pr|push|worktree|goal"; continue ;;
1337
+ pr|push|goal) ;;
1338
+ worktree) continue ;;
1339
+ *) bad "hooks kind '$kind' is not one of pr|push|goal"; continue ;;
712
1340
  esac
713
1341
  if [[ "$depth" != "4" ]]; then
714
1342
  bad "hooks entry '${hpath//$US/.}' is not key -> point -> list"
@@ -728,7 +1356,7 @@ if (( CHECK )); then
728
1356
  if [[ "$TOPOLOGY" == "repo" ]]; then
729
1357
  note " base for '$HEAD_ARG': $(base_for_head "$HEAD_ARG")"
730
1358
  fi
731
- for kind in pr push worktree; do
1359
+ for kind in pr push; do
732
1360
  for point in $(hook_points "$kind"); do
733
1361
  resolved="$(hooks_for_head_point "$HEAD_ARG" "$point" "$kind")"
734
1362
  note " head '$HEAD_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
@@ -815,14 +1443,9 @@ if (( CHECK )); then
815
1443
  esac
816
1444
  fi
817
1445
 
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.
1446
+ # Worktrees: a switch, one mechanical setting, and the project's own lifecycle
1447
+ # scripts. Creating, addressing, and refusing all belong to the scripts, so this
1448
+ # validates only what a run reads.
826
1449
  wt_on="$(block_value worktrees enabled || true)"
827
1450
  case "$wt_on" in
828
1451
  "") ;;
@@ -830,6 +1453,26 @@ if (( CHECK )); then
830
1453
  *) bad "worktrees.enabled '$wt_on' must be true|false" ;;
831
1454
  esac
832
1455
 
1456
+ # worktrees.create/remove name the project's own lifecycle scripts. A declared
1457
+ # path that is missing or not executable degrades to the built-in with a
1458
+ # warning at run time (D3), so it is a note here, never drift.
1459
+ for mode in create remove; do
1460
+ declared="$(yflat "worktrees${US}${mode}" 2>/dev/null || true)"
1461
+ [[ -n "$declared" ]] || continue
1462
+ if reason="$(wt_script_reason "$declared")"; then
1463
+ bad "worktrees.$mode: '$declared' $reason"
1464
+ elif [[ -f "$ROOT/${declared#./}" && -x "$ROOT/${declared#./}" ]]; then
1465
+ note " worktrees.$mode: ${declared#./}"
1466
+ # A declared script is the project's file, so its contents are never drift.
1467
+ # Without the header the run cannot tell whether it honors the WT_* contract.
1468
+ if ! grep -q '^# sassywares:scaffold' "$ROOT/${declared#./}" 2>/dev/null; then
1469
+ note " worktrees.$mode: ${declared#./} carries no sassywares:scaffold header — the run cannot tell whether it prints the WT_* block"
1470
+ fi
1471
+ else
1472
+ note " worktrees.$mode '${declared#./}' is missing or not executable — the built-in .sassywares/worktree/$mode is used instead"
1473
+ fi
1474
+ done
1475
+
833
1476
  # The mechanics are suite-owned and read-only (D4/D5), so `--check` proves the
834
1477
  # installed set byte for byte against the folder this skill ships, using the
835
1478
  # skills-lock folder hash. A version header cannot: it is hand-maintained, so
@@ -842,7 +1485,7 @@ if (( CHECK )); then
842
1485
  "node not found — .sassywares/worktree is unverified (the skills CLI needs node)" \
843
1486
  --installed "$ROOT/.sassywares/worktree" \
844
1487
  --shipped "$ASSET_WORKTREE"
845
- for helper in create list remove prune; do
1488
+ for helper in create list remove; do
846
1489
  [[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
847
1490
  || bad "missing or not executable: .sassywares/worktree/$helper"
848
1491
  done
@@ -863,16 +1506,6 @@ if (( CHECK )); then
863
1506
  bad "worktrees.enabled but .sassywares/worktree/_lib.sh is missing — re-run setup"
864
1507
  fi
865
1508
 
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
1509
  # A checkout must live outside the working tree — inside it, `git clean
877
1510
  # -xdf` deletes uncommitted work and every scanner that ignores .gitignore
878
1511
  # crawls a second copy of the source. And a worktree parked on a configured
@@ -1028,6 +1661,18 @@ if (( CHECK )); then
1028
1661
  fi
1029
1662
  fi
1030
1663
 
1664
+ # A config can match the tree and still be behind the template: whole blocks,
1665
+ # comment layers, and examples a later version added are missing, so the next
1666
+ # reader gets a thinner file than the one sassy-setup documents. It is a note,
1667
+ # never drift — every value the file declares is valid — and the sync only adds
1668
+ # what is missing, so this is the one passing check worth reading.
1669
+ template=""
1670
+ if template="$(merged_config)"; then
1671
+ if [[ "$template" != "$(cat "$CONFIG")" ]]; then
1672
+ note " template: --sync --write would $(sync_phrase "$template") (values the check accepts stay) — run: bash ${BASH_SOURCE[0]} --root $ROOT --sync --write"
1673
+ fi
1674
+ fi
1675
+
1031
1676
  if (( drift )); then exit 1; fi
1032
1677
  note " config matches the tree"
1033
1678
  exit 0
@@ -1229,223 +1874,36 @@ if (( BRANCH )); then
1229
1874
  exit 0
1230
1875
  fi
1231
1876
 
1232
- # --- Emit a proposal -------------------------------------------------------
1233
- # Every key carries its meaning and its allowed values. The file is the
1234
- # documentation a teammate reads, so the comments are part of the output, not
1235
- # decoration to be stripped.
1236
-
1237
- # kv KEY VALUE WIDTH COMMENT [INDENT] — prints "key: value" padded so comments
1238
- # align. WIDTH 0 means no padding.
1239
- kv() {
1240
- local indent="${5:- }" line
1241
- line="$indent$1: $2"
1242
- if [[ -n "${4:-}" && "${3:-0}" != "0" ]]; then
1243
- printf '%-*s%s\n' "$3" "$line" "$4"
1244
- elif [[ -n "${4:-}" ]]; then
1245
- printf '%s %s\n' "$line" "$4"
1877
+ # --- Template sync ---------------------------------------------------------
1878
+ # The one mode that writes. It computes the same proposal the default mode
1879
+ # prints, merges the current file onto it (see --sync at the top), and either
1880
+ # prints the result (dry run, the default) or writes it with --write. The file is
1881
+ # left untouched when the merge is identical, so a second run is a no-op that
1882
+ # says so.
1883
+ if (( SYNC )); then
1884
+ [[ -n "$CONFIG" ]] || { echo "no .sassywares/config.yaml found — run sassy-setup" >&2; exit 1; }
1885
+ merged="$(merged_config)"
1886
+ current="$(cat "$CONFIG")"
1887
+ if [[ "$merged" == "$current" ]]; then
1888
+ (( SINGLE )) || printf '%s\n' "$merged"
1889
+ echo "sync: $CONFIG is already current" >&2
1890
+ exit 0
1891
+ fi
1892
+ before="$(mktemp "${TMPDIR:-/tmp}/sassy-sync-before.XXXXXX")"
1893
+ after="$(mktemp "${TMPDIR:-/tmp}/sassy-sync-after.XXXXXX")"
1894
+ printf '%s\n' "$current" > "$before"
1895
+ printf '%s\n' "$merged" > "$after"
1896
+ changed="$(diff -u "$before" "$after" 2>/dev/null | awk '/^\+[^+]|^-[^-]/{n++} END{print n+0}' || true)"
1897
+ rm -f "$before" "$after"
1898
+ if (( SINGLE )); then
1899
+ printf '%s\n' "$merged" > "$CONFIG"
1900
+ echo "sync: wrote $CONFIG ($changed line(s) changed)" >&2
1246
1901
  else
1247
- printf '%s\n' "$line"
1902
+ printf '%s\n' "$merged"
1903
+ echo "sync: $CONFIG would change ($changed line(s)) — nothing written; rerun with --sync --write" >&2
1248
1904
  fi
1249
- }
1250
-
1251
- cat <<EOF
1252
- # Sassy Skills project config — written by sassy-setup.
1253
- # Every key is optional: delete a line to fall back to the documented default.
1254
- # Guide: https://github.com/sassywares/sassy-skills/blob/main/skills/sassy-setup/references/config.md
1255
-
1256
- # --- Artifacts ------------------------------------------------------------
1257
- # Where sassy writes its documents. Paths are relative to this file's folder.
1258
- artifacts:
1259
- EOF
1260
- kv plans "$PLANS" 34 '# sassy-plan writes plans here'
1261
- kv solutions "$SOLUTIONS" 34 '# sassy-compound writes learnings here'
1262
- kv handbooks "$HANDBOOKS" 34 '# sassy-handbook writes handovers here'
1263
- kv concepts "$CONCEPTS" 34 '# the glossary sassy-compound maintains (a file)'
1264
- cat <<EOF
1265
-
1266
- # --- Knowledge ------------------------------------------------------------
1267
- # read: folders and files searched for prior learnings before planning or
1268
- # debugging. Any paths; one that does not exist is skipped, not fatal.
1269
- # write: true | false — false means this project takes no learnings.
1270
- knowledge:
1271
- EOF
1272
- kv read "[$SOLUTIONS, $CONCEPTS]" 0
1273
- kv write true 34 '# true | false'
1274
-
1275
- case "$TOPOLOGY" in
1276
- repo)
1277
- cat <<EOF
1278
-
1279
- # --- Git ------------------------------------------------------------------
1280
- # repo: a remote name (this folder is the repo) | workspace (repos live below,
1281
- # this folder is not a repo) | none (no git anywhere here).
1282
- # base_map: the base for a HEAD branch, so a PR targets the right rung.
1283
- # "*" is ordinary work; add a rung for a branch that releases elsewhere.
1284
- git:
1285
- EOF
1286
- kv repo "$REPO_NAME" 0
1287
- printf ' base_map:\n'
1288
- if [[ -n "$DEFAULT_BRANCH" ]]; then
1289
- printf ' "*": %s # probed — confirm this is where ordinary work branches from\n' "$DEFAULT_BRANCH"
1290
- else
1291
- printf ' "*": %s # base for ordinary work; never guessed\n' "<confirm by hand>"
1292
- fi
1293
- printf ' # staging: main # uncomment when a branch releases somewhere else\n'
1294
- printf ' # release/*: main # a family of heads, longest prefix wins\n'
1295
- cat <<'EOF'
1296
- # remote: owner/backup # workspace only: the snapshot mirror
1297
- # mirror_branch: main # workspace only: the mirror's branch
1298
-
1299
- # workspace only: each nested repo folder -> the base its PRs target
1300
- # repos:
1301
- # fe: dev
1302
- EOF
1303
- ;;
1304
- workspace)
1305
- cat <<EOF
1306
-
1307
- # --- Git ------------------------------------------------------------------
1308
- # repo: workspace means repos live below and this folder is not a repo.
1309
- # remote: the snapshot mirror (GitHub owner/name or URL), required here.
1310
- # mirror_branch: the branch the mirror pushes to. Not a PR base — nested repos
1311
- # carry their own, and a workspace has no branches of its own.
1312
- git:
1313
- EOF
1314
- kv repo workspace 0
1315
- kv remote "${MIRROR_REMOTE:-<set the snapshot mirror, owner/name or URL>}" 0
1316
- kv mirror_branch "$MIRROR_BRANCH" 0
1317
- cat <<'EOF'
1318
-
1319
- # --- Repos ----------------------------------------------------------------
1320
- # Every nested repo -> the base its PRs target. A touched repo missing here is
1321
- # a question, never a default.
1322
- repos:
1323
- EOF
1324
- any=0
1325
- while IFS= read -r name; do
1326
- [[ -n "$name" ]] || continue
1327
- base="$(detect_base "$ROOT/$name")"
1328
- if [[ -n "$base" ]]; then
1329
- kv "$name" "$base" 34 '# probed — confirm the PR base'
1330
- else
1331
- kv "$name" "<confirm>" 34 '# base unknown; confirm by hand'
1332
- fi
1333
- any=1
1334
- done < <(nested_repos)
1335
- (( any )) || printf ' # no nested repos found\n'
1336
- ;;
1337
- *)
1338
- cat <<EOF
1339
-
1340
- # --- Git ------------------------------------------------------------------
1341
- # repo: none means this folder is deliberately outside git: commit, PR, and
1342
- # babysit refuse here, and work still leaves its changes on disk.
1343
- git:
1344
- EOF
1345
- kv repo none 0
1346
- ;;
1347
- esac
1348
-
1349
- cat <<'EOF'
1350
-
1351
- # --- Commit ---------------------------------------------------------------
1352
- # current: commit on the checked-out branch, even on a base branch, then push
1353
- # it to its upstream. No PR: pr.* and hooks.pr are ignored; hooks.push runs.
1354
- # new: never commit on a base branch — sassy-work, sassy-lfg, and sassy-debug
1355
- # cut a branch at the start of the run and stay on it.
1356
- commit:
1357
- EOF
1358
- kv branch new 34 '# current | new'
1359
- cat <<'EOF'
1360
-
1361
- # --- Pull requests --------------------------------------------------------
1362
- pr:
1363
- EOF
1364
- kv babysit true 24 '# true | false — babysit the PR this run opened'
1365
- kv merge false 24 '# true = merge every babysat PR here'
1366
- kv delete_branch false 24 '# true | false — delete the head branch once merged'
1367
- cat <<'EOF'
1368
-
1369
- # --- Hooks ----------------------------------------------------------------
1370
- # Project steps injected into the PR pipeline, after a push under
1371
- # commit.branch: current, across a worktree's life, or around a goal. Keyed by
1372
- # the branch — the branch the PR comes from, never the one it targets — or by the
1373
- # goal slug for hooks.goal. `"*"` is the default; a name overrides per point, and
1374
- # `release/*` matches a family. Each entry is `<skill> <args…>`, resolved at
1375
- # .agents/skills/<name>/SKILL.md; args are passed to the skill verbatim. Declared
1376
- # order, one worker each, missing skill fails closed.
1377
- hooks:
1378
- pr:
1379
- "*":
1380
- EOF
1381
- kv before_create '[]' 30 '# after the commit, before the PR opens' ' '
1382
- kv after_create '[]' 30 '# the PR was just created' ' '
1383
- kv before_merge '[]' 30 '# this run is about to merge' ' '
1384
- kv after_merge '[]' 30 '# this run observed the merge' ' '
1385
- cat <<'EOF'
1386
- # staging: # per-point override for one head branch
1387
- # before_create: []
1388
- # release/*: # a family of heads
1389
- # after_merge: [notify mode:auto]
1390
- goal: # keyed by the goal slug (the folder under artifacts.plans)
1391
- "*":
1392
- EOF
1393
- kv before_slice '[]' 30 '# sassy-goal mode:next: after the previous slice merges' ' '
1394
- kv after_close '[]' 30 '# sassy-goal mode:close: after the status is persisted' ' '
1395
- cat <<'EOF'
1396
- # migration-v2: # one goal, by slug
1397
- # before_slice: [db-migrate mode:auto]
1398
- # push: # commit.branch: current only; keyed by the pushed branch
1399
- # "*":
1400
- # 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
- EOF
1419
- cat <<'EOF'
1905
+ exit 0
1906
+ fi
1420
1907
 
1421
- # --- Worktrees ------------------------------------------------------------
1422
- # Parallel work in one repo: a checkout per branch, each with its own derived
1423
- # namespace, so two runs never fight over one working tree. enabled: true lets a
1424
- # run offer one instead of working here — the run asks, and stays here unless the
1425
- # 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.
1428
- #
1429
- # Repo topology only: a workspace root has no repo to cut a checkout from, and a
1430
- # `none` folder has no git at all. A checkout is addressed by the project's own
1431
- # stack, not by the suite: a port is the project's business, and this block
1432
- # carries no range.
1433
- worktrees:
1434
- EOF
1435
- kv enabled false 34 '# true = a run may offer its own checkout'
1436
- kv dir '~/.sassywares/worktrees' 34 '# parent of the per-repo folder; ~ is allowed'
1437
- cat <<'EOF'
1908
+ emit_proposal
1438
1909
 
1439
- # --- Dogfood --------------------------------------------------------------
1440
- # Agent QA: a stored procedure that proves a change works in the running
1441
- # product. This block only points at it — commands live in the recipe, because
1442
- # a copy here would duplicate the manifest and could not express step order.
1443
- # The recipe ends each section in a `Prove it:` step whose exit code is the
1444
- # verdict. enabled: true lets a plan write Mode: Auto QA rows, but only for a
1445
- # section that actually has one.
1446
- dogfood:
1447
- EOF
1448
- kv enabled false 42 '# true = plan writes Auto QA rows; false = all Manual'
1449
- kv recipe .sassywares/dogfood/recipe.md 42 '# the procedure; sassy-dogfood writes it'
1450
- kv reports .sassywares/dogfood/reports 42 '# run output; must stay gitignored'
1451
- kv timeout 900 42 '# seconds for the whole procedure'