@sassywares/skills 0.11.21 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONCEPTS.md +33 -19
- package/README.md +33 -24
- package/package.json +1 -1
- package/skills/sassy-cycle/SKILL.md +7 -6
- package/skills/sassy-lfg/SKILL.md +1 -1
- package/skills/sassy-overview/SKILL.md +52 -0
- package/skills/sassy-overview/references/identify.md +82 -0
- package/skills/sassy-overview/scripts/identify.sh +83 -0
- package/skills/sassy-overview/scripts/lib.sh +334 -0
- package/skills/sassy-plan/SKILL.md +4 -4
- package/skills/sassy-setup/SKILL.md +8 -8
- package/skills/sassy-setup/assets/dogfood-recipe.md +1 -1
- package/skills/sassy-setup/assets/lifecycle/down +29 -0
- package/skills/sassy-setup/assets/lifecycle/up +34 -0
- package/skills/sassy-setup/assets/roster +1 -0
- package/skills/sassy-setup/assets/sassywares-readme.md +5 -4
- package/skills/sassy-setup/assets/worktree/_lib.sh +52 -213
- package/skills/sassy-setup/assets/worktree/create +18 -33
- package/skills/sassy-setup/assets/worktree/list +20 -54
- package/skills/sassy-setup/assets/worktree/prune +13 -9
- package/skills/sassy-setup/assets/worktree/remove +83 -26
- package/skills/sassy-setup/references/config.md +99 -17
- package/skills/sassy-setup/references/dogfood.md +11 -17
- package/skills/sassy-setup/references/init.md +18 -4
- package/skills/sassy-setup/references/workspace.md +27 -34
- package/skills/sassy-setup/references/worktree.md +66 -75
- package/skills/sassy-setup/scripts/detect.sh +112 -103
- package/skills/sassy-setup/scripts/hash-skill.mjs +31 -18
- package/skills/sassy-setup/scripts/worktree-check.mjs +89 -0
- package/skills/sassy-work/SKILL.md +1 -1
- package/skills/sassy-worktree/SKILL.md +17 -21
- package/skills/sassy-worktree/references/create.md +3 -3
- package/skills/sassy-worktree/references/list.md +2 -2
- package/skills/sassy-worktree/references/prune.md +4 -4
- package/skills/sassy-worktree/references/remove.md +8 -6
- package/skills/sassy-setup/assets/worktree/stop +0 -65
- package/skills/sassy-worktree/references/preview.md +0 -17
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# Worktrees
|
|
2
2
|
|
|
3
|
-
Parallel work in one repo: each run gets its own checkout
|
|
4
|
-
|
|
5
|
-
else is using.
|
|
3
|
+
Parallel work in one repo: each run gets its own checkout and its own branch,
|
|
4
|
+
without a second clone and without fighting the checkout somebody else is using.
|
|
6
5
|
|
|
7
6
|
**Repo topology only.** `git.repo: workspace` means the root is not a repo and each
|
|
8
7
|
nested repo carries its own config, so there is nothing to cut a checkout from; a
|
|
@@ -25,25 +24,46 @@ reused rather than a second one cut.
|
|
|
25
24
|
## Install
|
|
26
25
|
|
|
27
26
|
Setup copies `assets/worktree/*` flat into `.sassywares/worktree/`, makes the
|
|
28
|
-
scripts executable, and
|
|
29
|
-
|
|
30
|
-
worktree is a checkout of the repo, so every worktree carries the tooling.
|
|
27
|
+
four scripts executable, and stops. They are tracked: a worktree is a checkout of
|
|
28
|
+
the repo, so every worktree carries the tooling.
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
**No command runner is required and no manifest is created.** Every caller — the
|
|
31
|
+
suite included — runs them by path, `.sassywares/worktree/create <branch>`. Setup
|
|
32
|
+
never writes a `package.json`, a `Makefile`, or a `justfile` so that an alias has
|
|
33
|
+
somewhere to live; a Go, Python, or Dart project keeps its own tooling file and
|
|
34
|
+
nothing else.
|
|
35
|
+
|
|
36
|
+
| Script | Does | Ends with |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `create <branch> [--from <ref>] [--env]` | cuts the branch untracked | the `WT_*` block (`--env`), the upstream it found, and the `after_create` hooks to dispatch |
|
|
39
|
+
| `list [--path <slug>]` | the table: branch, path, dirty, upstream | what it prints; a flag prints one value for scripting |
|
|
40
|
+
| `remove <slug\|branch> [--hook-ok] [--force]` | the refusals below, then deletes the checkout | a surviving branch |
|
|
41
|
+
| `prune [--yes]` | merged-or-gone, clean, fully pushed — and no `down:` or `before_remove` hook it cannot run | the removals, and why each skipped row was skipped |
|
|
42
|
+
|
|
43
|
+
`_lib.sh` is shared helpers — it reads `worktrees:` and carries the version; it is
|
|
44
|
+
sourced, never run. Every script takes `--version` (prints `worktree-version`) and
|
|
45
|
+
`--help` (its own usage). Exit codes: `0` success, `1` a refusal with the reason,
|
|
46
|
+
`2` bad usage, and `3` from `remove` when an obligation is left that a shell
|
|
47
|
+
cannot dispatch — a declared `before_remove` hook, or a `down:` that names a
|
|
48
|
+
skill — and `--hook-ok` is missing. `--hook-ok` is the caller saying the hook
|
|
49
|
+
and the `down:` skill have been dispatched, so that exit is the handshake, not an
|
|
50
|
+
error to route around.
|
|
41
51
|
|
|
42
52
|
Nothing else lives there. No state, no registry, no pid file.
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
**Aliases are a convenience, never a requirement.** When the project already has a
|
|
55
|
+
file at the root that carries named commands — `package.json` `scripts`,
|
|
56
|
+
`deno.json` `tasks`, `composer.json` `scripts`, a `Makefile` or `justfile` target —
|
|
57
|
+
setup offers to add one `worktree:<script>` entry per script, append-only, by
|
|
58
|
+
`workspace.md`'s merge rules, and declining is a complete install. It never creates
|
|
59
|
+
such a file to hold them: a path works in every shell, hook, and delegation brief
|
|
60
|
+
with no runner in between.
|
|
61
|
+
|
|
62
|
+
The installed set is suite-owned and read-only: nothing under `.sassywares/`
|
|
63
|
+
but `config.yaml` is the project's to edit. `--check` hashes the installed
|
|
64
|
+
files the way `skills-lock.json` hashes a skill folder, so a differing byte is
|
|
65
|
+
drift and the file is named. Setup overwrites the set without asking, because
|
|
66
|
+
there is no legitimate project edit to preserve.
|
|
47
67
|
|
|
48
68
|
## Where things live
|
|
49
69
|
|
|
@@ -51,7 +71,6 @@ overwriting an existing copy — from the first install it is the project's file
|
|
|
51
71
|
~/.sassywares/worktrees/
|
|
52
72
|
└── <repo>/ <- the worktree home; .repo records which checkout owns it
|
|
53
73
|
├── .repo absolute path of the main checkout
|
|
54
|
-
├── ports/ claim directories, one per claimed port
|
|
55
74
|
└── <slug>/ a checkout
|
|
56
75
|
```
|
|
57
76
|
|
|
@@ -59,6 +78,10 @@ overwriting an existing copy — from the first install it is the project's file
|
|
|
59
78
|
one path in the config that may be absolute or start with `~/` — it names
|
|
60
79
|
machine-local state, not something a teammate clones.
|
|
61
80
|
|
|
81
|
+
**An install at `worktree-version` 8 or lower also has `<worktree home>/ports/`**
|
|
82
|
+
— a folder of claim directories. Nothing reads it any more: it is inert and can be
|
|
83
|
+
deleted.
|
|
84
|
+
|
|
62
85
|
The folder is named after the repo. When another **live** clone of the same name
|
|
63
86
|
already owns it, this one takes `<repo>-<hash>` instead; a home whose recorded
|
|
64
87
|
owner no longer exists is reclaimed, so a finished project does not squat the name
|
|
@@ -94,20 +117,16 @@ work; `remove` and `prune` are the only safe exits.
|
|
|
94
117
|
|---|---|---|
|
|
95
118
|
| `WT_PATH` | `~/.sassywares/worktrees/shop/feat-catalog` | where the checkout is |
|
|
96
119
|
| `WT_BRANCH` | `feat/catalog` | the branch, as git names it |
|
|
97
|
-
| `WT_SLUG` | `feat-catalog` | the directory name
|
|
120
|
+
| `WT_SLUG` | `feat-catalog` | the directory name; the handle `list` and `remove` take |
|
|
98
121
|
| `WT_NAMESPACE` | `shop-feat-catalog` | database schema, compose project, simulator name |
|
|
99
|
-
| `WT_PORT` | `3041` | a private port — **only when `ports:` is configured** |
|
|
100
|
-
| `WT_BASE_URL` | `http://localhost:3041` | the URL on that port — same condition |
|
|
101
122
|
|
|
102
|
-
The same
|
|
103
|
-
`${WT_PORT:-5180}` that makes a recipe runnable in the main checkout too.
|
|
123
|
+
The same names expand inside a hook's brief.
|
|
104
124
|
|
|
105
125
|
**Finding a checkout.** `list` prints paths with `$HOME` shortened to `~`, which
|
|
106
126
|
reads well and does **not** paste into anything:
|
|
107
127
|
|
|
108
128
|
```bash
|
|
109
|
-
cd "$(worktree
|
|
110
|
-
worktree:list --address feat-catalog # the URL, when ports are configured
|
|
129
|
+
cd "$(.sassywares/worktree/list --path feat-catalog)" # the real absolute path
|
|
111
130
|
```
|
|
112
131
|
|
|
113
132
|
`create --env` prints `WT_PATH=` and the rest for scripts, and a slug is just the
|
|
@@ -117,30 +136,15 @@ Derived, never invented downstream: a hook that needs a database name uses
|
|
|
117
136
|
`$WT_NAMESPACE` rather than building its own, so two worktrees cannot collide by
|
|
118
137
|
accident.
|
|
119
138
|
|
|
120
|
-
**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
and a
|
|
129
|
-
one a human opens, and the recipe's steps carry the rest (distinct ports per
|
|
130
|
-
service, derived from `$WT_PORT` or fixed by the project). Do not add a port list
|
|
131
|
-
to the config for this — it is procedure, not identity.
|
|
132
|
-
|
|
133
|
-
When a range *is* configured: the slug hashes into it, the claim is taken with an
|
|
134
|
-
atomic `mkdir`, and a collision probes forward one port at a time. A claim
|
|
135
|
-
belongs to a slug, so a restarted app returns to the same port and two slugs that
|
|
136
|
-
hash alike do not fight.
|
|
137
|
-
|
|
138
|
-
**Liveness and stopping follow the address, not the claim.** `list` probes the port
|
|
139
|
-
the checkout advertises — its claim if it has one, otherwise the port its recipe's
|
|
140
|
-
`**Preview:**` line names — and never trusts a recorded pid. `stop` kills by that
|
|
141
|
-
same address, and `remove` refuses to delete a checkout while it answers. A preview
|
|
142
|
-
that names no port at all (a simulator, a desktop window) has nothing to probe, so
|
|
143
|
-
`LIVE` reads `—` and stopping it is the project's job.
|
|
139
|
+
**Addressing a checkout is the project's own business**: how it is looked at, and
|
|
140
|
+
what brings it up, are the project's `up:` and `down:` pair — see
|
|
141
|
+
[`config.md`](config.md), Lifecycle. Two checkouts running the same app collide
|
|
142
|
+
only if that `up:` lets them.
|
|
143
|
+
|
|
144
|
+
**Liveness and stopping are the project's.** `list` reports branches, paths, dirty
|
|
145
|
+
state, and upstreams, and nothing else: the suite keeps no registry, no pid file,
|
|
146
|
+
and nothing to go stale. `remove` refuses a dirty tree, unpushed commits, or the
|
|
147
|
+
main checkout, and a configured `down:` is the project's own stop step.
|
|
144
148
|
|
|
145
149
|
## Hooks
|
|
146
150
|
|
|
@@ -165,31 +169,13 @@ declared and `--hook-ok` missing, it prints `require-hook <name>` and exits `3`.
|
|
|
165
169
|
**Never write a hook skill yourself** — the same rule as every other hook. Setup
|
|
166
170
|
records the name; the project writes the body.
|
|
167
171
|
|
|
168
|
-
## Previewing a worktree
|
|
169
|
-
|
|
170
|
-
`sassy-worktree mode:preview` brings the product up in a checkout and prints how
|
|
171
|
-
to see it, using the dogfood recipe's bring-up steps — everything up to, but not
|
|
172
|
-
including, that section's `Prove it:` step. It leaves the app running.
|
|
173
|
-
|
|
174
|
-
How to see it is the recipe's `**Preview:**` line with the namespace substituted,
|
|
175
|
-
so it is a URL, a simulator, or a window depending on the project and never a
|
|
176
|
-
guess by this tooling. `list` prints that same line in its `HOW TO SEE` column,
|
|
177
|
-
which is why the column is not called "address".
|
|
178
|
-
|
|
179
|
-
What stops a preview follows from the same split: kill it by port when there is
|
|
180
|
-
one, hand it to the project when there is not.
|
|
181
|
-
|
|
182
|
-
There is no separate preview configuration. How the app comes up is the recipe's
|
|
183
|
-
job, because it is the only place that knowledge is allowed to live.
|
|
184
|
-
|
|
185
172
|
**Sessions and third-party origins.** A worktree gets a fresh, empty
|
|
186
173
|
`.sassywares/session/`. Most providers register one callback URL, so a worktree
|
|
187
|
-
usually cannot log in on its own
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
writing down once in the recipe rather than rediscovering it.
|
|
174
|
+
usually cannot log in on its own, and the `after_create` hook is where a project
|
|
175
|
+
solves it — copying or linking the main checkout's session is the common answer.
|
|
176
|
+
A cookie is host-scoped; a `localStorage` session is origin-scoped and has to be
|
|
177
|
+
injected per origin. That difference is worth writing down once rather than
|
|
178
|
+
rediscovering it.
|
|
193
179
|
|
|
194
180
|
## Refusals
|
|
195
181
|
|
|
@@ -200,10 +186,15 @@ writing down once in the recipe rather than rediscovering it.
|
|
|
200
186
|
| It is the main checkout | the repo itself |
|
|
201
187
|
| Dirty tree | uncommitted work |
|
|
202
188
|
| Commits on no remote | nothing to recover from |
|
|
203
|
-
| Something listening on its advertised address | stop the app first |
|
|
204
189
|
| A `before_remove` hook not yet run | the project has cleanup to do |
|
|
190
|
+
| A `down:` or `before_remove` hook `prune` cannot run | it runs neither, so `--yes` sends the row to `remove` |
|
|
191
|
+
|
|
192
|
+
`prune --yes` removes nothing on a project with a `down:` configured — real or the
|
|
193
|
+
generated stub — or a `before_remove` hook: it can run neither, so every
|
|
194
|
+
otherwise-removable checkout is listed for `remove <slug>` to handle instead. That
|
|
195
|
+
is by design, not a bug.
|
|
205
196
|
|
|
206
|
-
`remove` deletes the checkout
|
|
197
|
+
`remove` deletes the checkout and nothing else. **The branch
|
|
207
198
|
survives** — git keeps it, so the work is still reachable after the worktree is
|
|
208
199
|
gone. Deleting it is the user's call, or `pr.delete_branch`'s after a merge.
|
|
209
200
|
|
|
@@ -427,6 +427,31 @@ if (( CHECK )); then
|
|
|
427
427
|
note() { printf '%s\n' "$*"; }
|
|
428
428
|
bad() { printf ' drift: %s\n' "$*"; drift=1; }
|
|
429
429
|
|
|
430
|
+
# A node checker prints `<drift|note>\t<message>` lines and exits 0; the caller
|
|
431
|
+
# owns the verdict, so its exit status is a finding too. Silencing a crash into
|
|
432
|
+
# zero output would read as "nothing to report", which is the one thing a
|
|
433
|
+
# verifier must never mean. On failure the first output line names the crash.
|
|
434
|
+
check_with_node() { # <script> <missing-node note> [args...]
|
|
435
|
+
local script="$1" missing="$2" out first kind msg
|
|
436
|
+
shift 2
|
|
437
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
438
|
+
note " $missing"
|
|
439
|
+
return 0
|
|
440
|
+
fi
|
|
441
|
+
if out="$(node "$script" "$@" 2>&1)"; then
|
|
442
|
+
while IFS=$'\t' read -r kind msg; do
|
|
443
|
+
case "$kind" in
|
|
444
|
+
drift) bad "$msg" ;;
|
|
445
|
+
note) note " $msg" ;;
|
|
446
|
+
esac
|
|
447
|
+
done <<< "$out"
|
|
448
|
+
else
|
|
449
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
450
|
+
bad "$(basename "$script") failed — ${first:-it exited non-zero with no output}"
|
|
451
|
+
fi
|
|
452
|
+
return 0
|
|
453
|
+
}
|
|
454
|
+
|
|
430
455
|
note "root: ${ROOT}"
|
|
431
456
|
note "config: ${CONFIG:-none found (walking up from $START)}"
|
|
432
457
|
|
|
@@ -458,7 +483,7 @@ if (( CHECK )); then
|
|
|
458
483
|
# and the run silently falls back to a default the project never chose. The
|
|
459
484
|
# whitelist is the schema in references/config.md; every key there has a
|
|
460
485
|
# validator of its own below, so anything landing here is unknown.
|
|
461
|
-
while IFS=$'\t' read -r kpath
|
|
486
|
+
while IFS=$'\t' read -r kpath kvalue; do
|
|
462
487
|
[[ -n "$kpath" ]] || continue
|
|
463
488
|
key="${kpath//$US/.}"
|
|
464
489
|
case "$key" in
|
|
@@ -471,7 +496,17 @@ if (( CHECK )); then
|
|
|
471
496
|
commit.branch) ;;
|
|
472
497
|
pr.babysit|pr.merge|pr.delete_branch) ;;
|
|
473
498
|
dogfood.enabled|dogfood.recipe|dogfood.reports|dogfood.timeout) ;;
|
|
474
|
-
worktrees.enabled|worktrees.dir
|
|
499
|
+
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.
|
|
503
|
+
case "$kvalue" in
|
|
504
|
+
\[*|\{*)
|
|
505
|
+
bad "$key is a list or block — write one line: $key: <script> <args…> or $key: <skill> <args…>" ;;
|
|
506
|
+
esac ;;
|
|
507
|
+
worktrees.ports)
|
|
508
|
+
# Deleted from the schema. The one line that fixes it is the line itself.
|
|
509
|
+
bad "worktrees.ports is gone — delete the 'ports:' line under worktrees in .sassywares/config.yaml" ;;
|
|
475
510
|
hooks.*) ;; # shape checked with the hooks
|
|
476
511
|
*) bad "unknown key '$key' — it is ignored, so the run uses the default" ;;
|
|
477
512
|
esac
|
|
@@ -576,23 +611,37 @@ if (( CHECK )); then
|
|
|
576
611
|
note " no workspace git helpers installed (optional)"
|
|
577
612
|
fi
|
|
578
613
|
|
|
579
|
-
# Aliases
|
|
614
|
+
# Aliases are optional: the scripts are run by path, and a project that wired
|
|
615
|
+
# only the ones its runner needs is not drifting. Reported, never failed.
|
|
616
|
+
# The manifest is never enumerated here — sassy-overview's identify.sh names
|
|
617
|
+
# the stack and the file that declares it (D20).
|
|
580
618
|
manifest=""
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
619
|
+
identify="$SKILL_DIR/../sassy-overview/scripts/identify.sh"
|
|
620
|
+
if [[ -f "$identify" ]]; then
|
|
621
|
+
stack_line="$(bash "$identify" --root "$ROOT" --key stack 2>/dev/null || true)"
|
|
622
|
+
while IFS=$'\t' read -r _key stack_val stack_src; do
|
|
623
|
+
# Only a named-scripts manifest has an alias slot; anything else is
|
|
624
|
+
# simply not wired, and that is complete.
|
|
625
|
+
case "$stack_val" in
|
|
626
|
+
node|php|deno) if [[ "$stack_src" != "-" ]]; then manifest="$stack_src"; fi ;;
|
|
627
|
+
esac
|
|
628
|
+
done <<< "$stack_line"
|
|
629
|
+
else
|
|
630
|
+
note " sassy-overview is not installed — workspace aliases unchecked"
|
|
631
|
+
fi
|
|
587
632
|
if [[ -n "$manifest" ]]; then
|
|
588
633
|
missing_aliases=()
|
|
634
|
+
missing_list=""
|
|
589
635
|
for script in branches pull checkout-bases snapshot; do
|
|
590
|
-
grep -q "\"workspace:${script}\"" "$ROOT/$manifest"
|
|
636
|
+
if ! grep -q "\"workspace:${script}\"" "$ROOT/$manifest"; then
|
|
637
|
+
missing_aliases+=("$script")
|
|
638
|
+
missing_list+="${missing_list:+, }workspace:${script}"
|
|
639
|
+
fi
|
|
591
640
|
done
|
|
592
641
|
if [[ ${#missing_aliases[@]} -eq 0 ]]; then
|
|
593
642
|
note " workspace:* aliases in ${manifest}"
|
|
594
643
|
elif [[ ${#missing_aliases[@]} -lt 4 ]]; then
|
|
595
|
-
|
|
644
|
+
note " aliases: ${missing_list} not wired in ${manifest} (optional — the scripts run by path)"
|
|
596
645
|
else
|
|
597
646
|
note " no workspace:* aliases in ${manifest} (optional)"
|
|
598
647
|
fi
|
|
@@ -766,69 +815,50 @@ if (( CHECK )); then
|
|
|
766
815
|
esac
|
|
767
816
|
fi
|
|
768
817
|
|
|
769
|
-
#
|
|
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
|
|
770
825
|
# refusing all belong to the scripts, so this validates only what a run reads.
|
|
771
826
|
wt_on="$(block_value worktrees enabled || true)"
|
|
772
|
-
wt_dir="$(block_value worktrees dir || true)"
|
|
773
|
-
wt_ports="$(block_value worktrees ports || true)"
|
|
774
827
|
case "$wt_on" in
|
|
775
828
|
"") ;;
|
|
776
829
|
true|false) note " worktrees.enabled: $wt_on" ;;
|
|
777
830
|
*) bad "worktrees.enabled '$wt_on' must be true|false" ;;
|
|
778
831
|
esac
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
832
|
+
|
|
833
|
+
# The mechanics are suite-owned and read-only (D4/D5), so `--check` proves the
|
|
834
|
+
# installed set byte for byte against the folder this skill ships, using the
|
|
835
|
+
# skills-lock folder hash. A version header cannot: it is hand-maintained, so
|
|
836
|
+
# an edited byte and an unbumped asset both still read as current. Run whenever
|
|
837
|
+
# the set is installed — a project that flipped the switch off still carries
|
|
838
|
+
# files it may not edit — and keep the missing set a switch-on finding.
|
|
839
|
+
wt_lib="$ROOT/.sassywares/worktree/_lib.sh"
|
|
840
|
+
verify_worktree_set() {
|
|
841
|
+
check_with_node "$SKILL_DIR/scripts/worktree-check.mjs" \
|
|
842
|
+
"node not found — .sassywares/worktree is unverified (the skills CLI needs node)" \
|
|
843
|
+
--installed "$ROOT/.sassywares/worktree" \
|
|
844
|
+
--shipped "$ASSET_WORKTREE"
|
|
845
|
+
for helper in create list remove prune; do
|
|
846
|
+
[[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
|
|
847
|
+
|| bad "missing or not executable: .sassywares/worktree/$helper"
|
|
848
|
+
done
|
|
849
|
+
}
|
|
795
850
|
|
|
796
851
|
if [[ "$wt_on" == "true" ]]; then
|
|
797
852
|
if [[ "$TOPOLOGY" != "repo" ]]; then
|
|
798
853
|
bad "worktrees.enabled needs a repo — this folder is '$TOPOLOGY', and a checkout needs git"
|
|
799
854
|
else
|
|
800
|
-
|
|
801
|
-
note " worktrees: no port resource — a checkout is addressed by the recipe's preview line"
|
|
802
|
-
fi
|
|
855
|
+
note " worktrees: a checkout is addressed by the project's own stack, and two checkouts running the same app collide"
|
|
803
856
|
if [[ "$(yflat "commit${US}branch" 2>/dev/null || true)" == "current" ]]; then
|
|
804
857
|
note " worktrees.enabled with commit.branch: current — a run never cuts a branch, so no run offers a checkout"
|
|
805
858
|
fi
|
|
806
859
|
|
|
807
|
-
wt_lib="$ROOT/.sassywares/worktree/_lib.sh"
|
|
808
860
|
if [[ -f "$wt_lib" ]]; then
|
|
809
|
-
|
|
810
|
-
asset_wt="$(sed -n 's/^# worktree-version: //p' "$ASSET_WORKTREE/_lib.sh" | head -n 1)"
|
|
811
|
-
installed_wt_var="$(sed -n 's/^WT_VERSION="\(.*\)"/\1/p' "$wt_lib" | head -n 1)"
|
|
812
|
-
if [[ -n "$installed_wt_var" && -n "$installed_wt" && "$installed_wt_var" != "$installed_wt" ]]; then
|
|
813
|
-
bad ".sassywares/worktree/_lib.sh header says v${installed_wt} but the script reports v${installed_wt_var} — the file was half-bumped"
|
|
814
|
-
fi
|
|
815
|
-
if [[ -z "$installed_wt" ]]; then
|
|
816
|
-
bad "installed .sassywares/worktree/_lib.sh has no worktree-version line"
|
|
817
|
-
elif [[ -n "$asset_wt" && "$installed_wt" != "$asset_wt" ]]; then
|
|
818
|
-
bad "installed worktree tooling is v${installed_wt}, this skill ships v${asset_wt} — re-run setup"
|
|
819
|
-
else
|
|
820
|
-
note " worktree tooling v${installed_wt}"
|
|
821
|
-
fi
|
|
822
|
-
# The version is hand-maintained, so a shipped change that forgot to bump
|
|
823
|
-
# it would look current. Say so when the bytes differ but the numbers do not.
|
|
824
|
-
if [[ -n "$installed_wt" && "$installed_wt" == "$asset_wt" ]] \
|
|
825
|
-
&& ! cmp -s "$wt_lib" "$ASSET_WORKTREE/_lib.sh"; then
|
|
826
|
-
note " .sassywares/worktree/_lib.sh matches v${installed_wt} but differs from the shipped copy — extended here, or the assets changed without a bump"
|
|
827
|
-
fi
|
|
828
|
-
for helper in create list stop remove prune; do
|
|
829
|
-
[[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
|
|
830
|
-
|| bad "missing or not executable: .sassywares/worktree/$helper"
|
|
831
|
-
done
|
|
861
|
+
verify_worktree_set
|
|
832
862
|
else
|
|
833
863
|
bad "worktrees.enabled but .sassywares/worktree/_lib.sh is missing — re-run setup"
|
|
834
864
|
fi
|
|
@@ -871,39 +901,15 @@ if (( CHECK )); then
|
|
|
871
901
|
bad "worktree '$ghost' is prunable — the folder is gone; run: git worktree prune"
|
|
872
902
|
done < <(git -C "$ROOT" worktree list --porcelain 2>/dev/null \
|
|
873
903
|
| awk '/^worktree /{p=$2} /^prunable /{print p; p=""}')
|
|
874
|
-
|
|
875
|
-
# Orphan port claims: the worktree is gone but its port is still taken, so
|
|
876
|
-
# a later checkout is pushed off it for no reason.
|
|
877
|
-
wt_homef=""
|
|
878
|
-
d="${wt_dir:-$HOME/.sassywares/worktrees}"
|
|
879
|
-
case "$d" in
|
|
880
|
-
"~") d="$HOME" ;;
|
|
881
|
-
"~/"*) d="$HOME/${d#\~/}" ;;
|
|
882
|
-
/*) ;;
|
|
883
|
-
*) d="$ROOT/$d" ;;
|
|
884
|
-
esac
|
|
885
|
-
cand="$d/$(basename "$ROOT")"
|
|
886
|
-
if [[ -f "$cand/.repo" && "$(cat "$cand/.repo" 2>/dev/null)" != "$root_real" ]]; then
|
|
887
|
-
cand="$d/$(basename "$ROOT")-$(printf '%s' "$root_real" | shasum -a 256 | cut -c1-6)"
|
|
888
|
-
fi
|
|
889
|
-
[[ -d "$cand" ]] && wt_homef="$cand"
|
|
890
|
-
if [[ -n "$wt_homef" && -d "$wt_homef/ports" ]]; then
|
|
891
|
-
for claim in "$wt_homef"/ports/*; do
|
|
892
|
-
[[ -d "$claim" ]] || continue
|
|
893
|
-
owner="$(cat "$claim/owner" 2>/dev/null || true)"
|
|
894
|
-
[[ -n "$owner" ]] || continue
|
|
895
|
-
found=0
|
|
896
|
-
if (( ${#wt_paths[@]} )); then
|
|
897
|
-
for p in "${wt_paths[@]}"; do
|
|
898
|
-
[[ "$p" == *"/$owner" ]] && found=1
|
|
899
|
-
done
|
|
900
|
-
fi
|
|
901
|
-
(( found )) || bad "port $(basename "$claim") is claimed by '$owner', which has no worktree"
|
|
902
|
-
done
|
|
903
|
-
fi
|
|
904
904
|
fi
|
|
905
905
|
fi
|
|
906
906
|
|
|
907
|
+
# The switch is off, but the tooling is installed: still suite-owned, still
|
|
908
|
+
# read-only, so still compared. Nothing here needs a repo or an enabled switch.
|
|
909
|
+
if [[ "$wt_on" != "true" && -f "$wt_lib" ]]; then
|
|
910
|
+
verify_worktree_set
|
|
911
|
+
fi
|
|
912
|
+
|
|
907
913
|
# Dogfood is a pointer and a switch, never commands: the recipe holds the
|
|
908
914
|
# procedure and its `Prove it:` step is the verdict. Everything below is
|
|
909
915
|
# structural. A check run never runs the product — a validator that boots an
|
|
@@ -1004,16 +1010,9 @@ if (( CHECK )); then
|
|
|
1004
1010
|
# stale, edited, or half-installed, and every skill downstream then runs
|
|
1005
1011
|
# something other than what the lock says. Offline, no network.
|
|
1006
1012
|
[[ -n "$SUITE_ROSTER" ]] || note " suite roster not found — falling back to the sassy-* name prefix"
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
drift) bad "$msg" ;;
|
|
1011
|
-
note) note " $msg" ;;
|
|
1012
|
-
esac
|
|
1013
|
-
done < <(node "$SKILL_DIR/scripts/lockcheck.mjs" --root "$ROOT" --roster "$SUITE_ROSTER" 2>/dev/null || true)
|
|
1014
|
-
else
|
|
1015
|
-
note " node not found — the vendored pin is unverified (the skills CLI needs node)"
|
|
1016
|
-
fi
|
|
1013
|
+
check_with_node "$SKILL_DIR/scripts/lockcheck.mjs" \
|
|
1014
|
+
"node not found — the vendored pin is unverified (the skills CLI needs node)" \
|
|
1015
|
+
--root "$ROOT" --roster "$SUITE_ROSTER"
|
|
1017
1016
|
|
|
1018
1017
|
if [[ "$TOPOLOGY" == "repo" ]]; then
|
|
1019
1018
|
# Tracked, not merely present: a clone has to get the pin without a network
|
|
@@ -1403,6 +1402,19 @@ cat <<'EOF'
|
|
|
1403
1402
|
# "*":
|
|
1404
1403
|
# after_create: [] # derive .env, seed the database, copy the session in
|
|
1405
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
|
|
1406
1418
|
EOF
|
|
1407
1419
|
cat <<'EOF'
|
|
1408
1420
|
|
|
@@ -1415,16 +1427,13 @@ cat <<'EOF'
|
|
|
1415
1427
|
# reads these values.
|
|
1416
1428
|
#
|
|
1417
1429
|
# Repo topology only: a workspace root has no repo to cut a checkout from, and a
|
|
1418
|
-
# `none` folder has no git at all.
|
|
1419
|
-
#
|
|
1420
|
-
#
|
|
1421
|
-
# mobile, desktop, or CLI project, and the checkout is addressed by the recipe's
|
|
1422
|
-
# preview line instead (`$WT_NAMESPACE` names a simulator, a window, a path).
|
|
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.
|
|
1423
1433
|
worktrees:
|
|
1424
1434
|
EOF
|
|
1425
1435
|
kv enabled false 34 '# true = a run may offer its own checkout'
|
|
1426
1436
|
kv dir '~/.sassywares/worktrees' 34 '# parent of the per-repo folder; ~ is allowed'
|
|
1427
|
-
kv ports 3000-3099 34 '# a private port per checkout; delete for non-port previews'
|
|
1428
1437
|
cat <<'EOF'
|
|
1429
1438
|
|
|
1430
1439
|
# --- Dogfood --------------------------------------------------------------
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
// skill. Re-read the CLI's source when bumping, and keep the golden vectors in
|
|
19
19
|
// tests/sassy-setup-roster.sh honest.
|
|
20
20
|
//
|
|
21
|
-
// No side effects: lockcheck.mjs and tests/hash-lock.mjs
|
|
21
|
+
// No side effects: lockcheck.mjs, worktree-check.mjs and tests/hash-lock.mjs
|
|
22
|
+
// import it.
|
|
22
23
|
|
|
23
24
|
import { createHash } from "node:crypto";
|
|
24
25
|
import { readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
@@ -80,31 +81,43 @@ function normalizeLineEndings(body) {
|
|
|
80
81
|
return Buffer.from(body.toString("latin1").replaceAll("\r\n", "\n"), "latin1");
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
// Every file in DIR, in the order and with the normalization the hash consumes.
|
|
85
|
+
// The single walk shared by the hash and by a caller that has to name a file, so
|
|
86
|
+
// a per-file report can never disagree with the folder verdict.
|
|
87
|
+
export async function skillFiles(dir, legacy = false) {
|
|
88
|
+
const files = [];
|
|
86
89
|
if (legacy) {
|
|
87
|
-
const files = [];
|
|
88
90
|
await walkLegacy(dir, dir, files);
|
|
89
91
|
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
90
|
-
|
|
91
|
-
return hash.digest("hex");
|
|
92
|
+
return files;
|
|
92
93
|
}
|
|
93
|
-
const files = [];
|
|
94
94
|
await walk(dir, dir, await realpath(dir), new Set(), files);
|
|
95
|
-
|
|
96
|
-
.map((file) => ({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
return files
|
|
96
|
+
.map((file) => ({ path: file.path, body: normalizeLineEndings(file.body) }))
|
|
97
|
+
.sort((a, b) => Buffer.compare(Buffer.from(a.path, "utf8"), Buffer.from(b.path, "utf8")));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Hash an already-walked file list the way the CLI does for a lock of the given
|
|
101
|
+
// era. Split out of hashSkillFolder so a caller that has to name a differing
|
|
102
|
+
// file (worktree-check.mjs) walks once and hashes the same array it reports on.
|
|
103
|
+
export function hashFiles(files, legacy = false) {
|
|
104
|
+
const hash = createHash("sha256");
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
if (legacy) {
|
|
107
|
+
hash.update(file.path).update(file.body);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
102
110
|
hash
|
|
103
|
-
.update(
|
|
111
|
+
.update(Buffer.from(file.path, "utf8"))
|
|
104
112
|
.update("\0")
|
|
105
|
-
.update(String(
|
|
113
|
+
.update(String(file.body.length))
|
|
106
114
|
.update("\0")
|
|
107
|
-
.update(
|
|
115
|
+
.update(file.body);
|
|
108
116
|
}
|
|
109
117
|
return hash.digest("hex");
|
|
110
118
|
}
|
|
119
|
+
|
|
120
|
+
// Hash one skill folder the way the CLI does for a lock of the given era.
|
|
121
|
+
export async function hashSkillFolder(dir, legacy = false) {
|
|
122
|
+
return hashFiles(await skillFiles(dir, legacy), legacy);
|
|
123
|
+
}
|