@sassywares/skills 0.17.1 → 0.17.2

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.
@@ -0,0 +1,673 @@
1
+ # generated_by: sassy-setup@0.17.2
2
+ # lib/check.sh — the --check mode: validate the config against the tree.
3
+ # Sourced by detect.sh. Never sets shell options; reads the paths it set.
4
+
5
+ mode_check() {
6
+ drift=0
7
+ note() { printf '%s\n' "$*"; }
8
+ bad() { printf ' drift: %s\n' "$*"; drift=1; }
9
+
10
+ # A node checker prints `<drift|note>\t<message>` lines and exits 0; the caller
11
+ # owns the verdict, so its exit status is a finding too. Silencing a crash into
12
+ # zero output would read as "nothing to report", which is the one thing a
13
+ # verifier must never mean. On failure the first output line names the crash.
14
+ check_with_node() { # <script> <missing-node note> [args...]
15
+ local script="$1" missing="$2" out first kind msg
16
+ shift 2
17
+ if ! command -v node >/dev/null 2>&1; then
18
+ note " $missing"
19
+ return 0
20
+ fi
21
+ if out="$(node "$script" "$@" 2>&1)"; then
22
+ while IFS=$'\t' read -r kind msg; do
23
+ case "$kind" in
24
+ drift) bad "$msg" ;;
25
+ note) note " $msg" ;;
26
+ esac
27
+ done <<< "$out"
28
+ else
29
+ first="$(printf '%s\n' "$out" | head -n 1)"
30
+ bad "$(basename "$script") failed — ${first:-it exited non-zero with no output}"
31
+ fi
32
+ return 0
33
+ }
34
+
35
+ note "root: ${ROOT}"
36
+ note "config: ${CONFIG:-none found (walking up from $START)}"
37
+
38
+ if [[ -z "$CONFIG" ]]; then
39
+ bad "no .sassywares/config.yaml found — run sassy-setup"
40
+ exit 1
41
+ fi
42
+
43
+ configured_repo="$(config_value repo 2>/dev/null || true)"
44
+ if [[ -z "$configured_repo" ]]; then
45
+ bad "git.repo is unset"
46
+ elif [[ "$TOPOLOGY" == "repo" ]]; then
47
+ # The tree is a repo: the configured value must name one of its remotes.
48
+ case "$configured_repo" in
49
+ workspace|none) bad "git.repo is '$configured_repo' but this folder is a git repo" ;;
50
+ *) git -C "$ROOT" remote 2>/dev/null | grep -qx "$configured_repo" \
51
+ || bad "git.repo '$configured_repo' is not a remote of this repo" ;;
52
+ esac
53
+ else
54
+ # Not a repo: `workspace` and `none` are both legal, and which one is a
55
+ # human policy call the tree cannot verify.
56
+ case "$configured_repo" in
57
+ workspace|none) note " not a repo; '$configured_repo' accepted" ;;
58
+ *) bad "git.repo is '$configured_repo' but this folder is not a git repo" ;;
59
+ esac
60
+ fi
61
+
62
+ # A typo'd key is the quietest failure in the file: it parses, it is ignored,
63
+ # and the run silently falls back to a default the project never chose. The
64
+ # whitelist is the schema in references/config.md; every key there has a
65
+ # validator of its own below, so anything landing here is unknown.
66
+ lost_hooks_reported=0
67
+ while IFS=$'\t' read -r kpath kvalue; do
68
+ [[ -n "$kpath" ]] || continue
69
+ key="${kpath//$US/.}"
70
+ case "$key" in
71
+ artifacts.plans|artifacts.solutions|artifacts.handbooks|artifacts.concepts|artifacts.strategy) ;;
72
+ knowledge.read|knowledge.write) ;;
73
+ git.repo|git.remote|git.mirror_branch) ;;
74
+ git.default_branch) ;; # has its own message below
75
+ git.base_map.*) ;;
76
+ repos.*) ;;
77
+ commit.branch) ;;
78
+ pr.babysit|pr.merge|pr.delete_branch) ;;
79
+ dogfood.enabled|dogfood.recipe|dogfood.reports|dogfood.timeout) ;;
80
+ worktrees.enabled|worktrees.dir) ;;
81
+ worktrees.create|worktrees.remove)
82
+ # A single path, no arguments: the script is the lifecycle, so a command
83
+ # line here would define a second place it lives.
84
+ case "$kvalue" in
85
+ \[*|\{*) bad "$key is a list or block — write one path: $key: scripts/worktrees/${key##*.}" ;;
86
+ esac ;;
87
+ up|down)
88
+ # Removed with the project-script lifecycle (D3/D11): a run stops and
89
+ # starts through the project's own create/remove, not a key. A soft
90
+ # warning would let a project believe its stack still stops.
91
+ bad "$key is gone — the lifecycle moved into worktrees.create and worktrees.remove. Delete the '$key:' line from .sassywares/config.yaml" ;;
92
+ hooks.worktree|hooks.worktree.*)
93
+ # Same migration: what a worktree needed to prepare or tear down is now
94
+ # inside the project's scripts, which the suite runs instead. One block
95
+ # is one fix, so report it once however many points it lists.
96
+ if (( ! lost_hooks_reported )); then
97
+ 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"
98
+ lost_hooks_reported=1
99
+ fi ;;
100
+ worktrees.ports)
101
+ # Deleted from the schema. The one line that fixes it is the line itself.
102
+ bad "worktrees.ports is gone — delete the 'ports:' line under worktrees in .sassywares/config.yaml" ;;
103
+ hooks.*) ;; # shape checked with the hooks
104
+ *) bad "unknown key '$key' — it is ignored, so the run uses the default" ;;
105
+ esac
106
+ done < <(yaml_flat "$CONFIG")
107
+
108
+ if [[ -n "$(yflat "git${US}default_branch")" ]]; then
109
+ if [[ "$TOPOLOGY" == "workspace" ]]; then
110
+ bad "git.default_branch is gone — the mirror's branch is git.mirror_branch"
111
+ else
112
+ bad "git.default_branch is gone — use git.base_map with a \"*\" entry"
113
+ fi
114
+ fi
115
+
116
+ if [[ "$TOPOLOGY" == "repo" ]]; then
117
+ if [[ -n "$(yflat "git${US}remote")" ]]; then
118
+ bad "git.remote is workspace-only — a repo config names its remote in git.repo"
119
+ fi
120
+ if [[ -n "$(yflat "git${US}mirror_branch")" ]]; then
121
+ bad "git.mirror_branch is workspace-only — a repo routes branches in git.base_map"
122
+ fi
123
+ if [[ -z "$(yflat "git${US}base_map${US}*")" ]]; then
124
+ bad "git.base_map has no \"*\" entry — it is the base for ordinary work"
125
+ else
126
+ while IFS= read -r pat; do
127
+ [[ -n "$pat" ]] || continue
128
+ case "$pat" in
129
+ "*") ;;
130
+ *"*") [[ "${pat%\*}" != *"*" ]] || bad "base_map key '$pat': only one trailing * is allowed" ;;
131
+ esac
132
+ done < <(yaml_flat "$CONFIG" | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n==3 && a[1]=="git" && a[2]=="base_map") print a[3]}' | sort -u)
133
+ head_ref="${HEAD_ARG:-$(git -C "$ROOT" branch --show-current 2>/dev/null || true)}"
134
+ if [[ -n "$head_ref" ]]; then
135
+ # the --head readout below prints this line; avoid printing it twice
136
+ [[ -n "$HEAD_ARG" ]] || note " base for '${head_ref}': $(base_for_head "$head_ref")"
137
+ cur="$head_ref"; hops=0
138
+ while [[ -n "$cur" ]] && (( hops < 8 )); do
139
+ next="$(yflat "git${US}base_map${US}${cur}")"
140
+ [[ -z "$next" ]] && break
141
+ cur="$next"; hops=$((hops + 1))
142
+ if [[ "$cur" == "$head_ref" ]]; then
143
+ bad "git.base_map cycles through '$head_ref'"; break
144
+ fi
145
+ done
146
+ else
147
+ note " detached HEAD — pass --head <branch> to see the resolved base"
148
+ fi
149
+ fi
150
+ fi
151
+
152
+ # `repos` is the workspace inventory. In a repo config it is a dead map, and
153
+ # a reader would trust it over the base_map that actually applies.
154
+ if [[ "$configured_repo" != "workspace" ]]; then
155
+ while IFS= read -r rname; do
156
+ [[ -n "$rname" ]] || continue
157
+ bad "repos.$rname is workspace-only — git.repo is '${configured_repo:-unset}'"
158
+ done < <(yaml_flat "$CONFIG" \
159
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n>=2 && a[1]=="repos") print a[2]}' \
160
+ | sort -u)
161
+ fi
162
+
163
+ if [[ "$TOPOLOGY" == "workspace" ]]; then
164
+ [[ -n "$MIRROR_REMOTE" ]] || bad "git.remote is required when git.repo is workspace"
165
+ installed="$ROOT/.sassywares/workspace/snapshot"
166
+ if [[ -x "$installed" ]]; then
167
+ installed_v="$(sed -n 's/^# snapshot-version: //p' "$installed" | head -n 1)"
168
+ asset_v="$(sed -n 's/^# snapshot-version: //p' "$ASSET_SNAPSHOT" | head -n 1)"
169
+ if [[ -z "$installed_v" ]]; then
170
+ bad "installed .sassywares/workspace/snapshot has no version line"
171
+ elif [[ "$installed_v" != "$asset_v" ]]; then
172
+ bad "installed snapshot is v${installed_v}, this skill ships v${asset_v} — re-run setup"
173
+ else
174
+ note " snapshot v${installed_v}"
175
+ fi
176
+ else
177
+ bad "missing .sassywares/workspace/snapshot"
178
+ fi
179
+
180
+ # The git helpers are optional as a set, but a half-installed or stale set is
181
+ # drift: they read `repos:` from this config, so a version skew means the
182
+ # project is running a reader written for a different map.
183
+ installed_lib="$ROOT/.sassywares/workspace/_lib.sh"
184
+ if [[ -f "$installed_lib" ]]; then
185
+ lib_v="$(sed -n 's/^# workspace-git-version: //p' "$installed_lib" | head -n 1)"
186
+ asset_lib_v="$(sed -n 's/^# workspace-git-version: //p' "$ASSET_WORKSPACE/_lib.sh" | head -n 1)"
187
+ lib_var="$(sed -n 's/^WORKSPACE_GIT_VERSION="\(.*\)"/\1/p' "$installed_lib" | head -n 1)"
188
+ if [[ -n "$lib_var" && -n "$lib_v" && "$lib_var" != "$lib_v" ]]; then
189
+ bad ".sassywares/workspace/_lib.sh header says v${lib_v} but the script reports v${lib_var} — the file was half-bumped"
190
+ fi
191
+ if [[ -z "$lib_v" ]]; then
192
+ bad "installed .sassywares/workspace/_lib.sh has no workspace-git-version line"
193
+ elif [[ -n "$asset_lib_v" && "$lib_v" != "$asset_lib_v" ]]; then
194
+ bad "installed workspace git helpers are v${lib_v}, this skill ships v${asset_lib_v} — re-run setup"
195
+ else
196
+ note " workspace-git v${lib_v}"
197
+ fi
198
+ for helper in branches pull checkout-bases; do
199
+ if [[ ! -x "$ROOT/.sassywares/workspace/$helper" ]]; then
200
+ bad "missing or not executable: .sassywares/workspace/$helper"
201
+ fi
202
+ done
203
+ else
204
+ note " no workspace git helpers installed (optional)"
205
+ fi
206
+
207
+ # Aliases are optional: the scripts are run by path, and a project that wired
208
+ # only the ones its runner needs is not drifting. Reported, never failed.
209
+ # The manifest is never enumerated here — sassy-overview's identify.sh names
210
+ # the stack and the file that declares it (D20).
211
+ manifest=""
212
+ identify="$SKILL_DIR/../sassy-overview/scripts/identify.sh"
213
+ if [[ -f "$identify" ]]; then
214
+ stack_line="$(bash "$identify" --root "$ROOT" --key stack 2>/dev/null || true)"
215
+ while IFS=$'\t' read -r _key stack_val stack_src; do
216
+ # Only a named-scripts manifest has an alias slot; anything else is
217
+ # simply not wired, and that is complete.
218
+ case "$stack_val" in
219
+ node|php|deno) if [[ "$stack_src" != "-" ]]; then manifest="$stack_src"; fi ;;
220
+ esac
221
+ done <<< "$stack_line"
222
+ else
223
+ note " sassy-overview is not installed — workspace aliases unchecked"
224
+ fi
225
+ if [[ -n "$manifest" ]]; then
226
+ missing_aliases=()
227
+ missing_list=""
228
+ for script in branches pull checkout-bases snapshot; do
229
+ if ! grep -q "\"workspace:${script}\"" "$ROOT/$manifest"; then
230
+ missing_aliases+=("$script")
231
+ missing_list+="${missing_list:+, }workspace:${script}"
232
+ fi
233
+ done
234
+ if [[ ${#missing_aliases[@]} -eq 0 ]]; then
235
+ note " workspace:* aliases in ${manifest}"
236
+ elif [[ ${#missing_aliases[@]} -lt 4 ]]; then
237
+ note " aliases: ${missing_list} not wired in ${manifest} (optional — the scripts run by path)"
238
+ else
239
+ note " no workspace:* aliases in ${manifest} (optional)"
240
+ fi
241
+ fi
242
+ while IFS= read -r name; do
243
+ [[ -n "$name" ]] || continue
244
+ base="$(detect_base "$ROOT/$name")"
245
+ listed="$(block_value repos "$name" || true)"
246
+ # A nested repo's own config is authoritative; `repos` is the inventory and
247
+ # the fallback for repos that have none.
248
+ nested="$ROOT/$name/.sassywares/config.yaml"
249
+ nested_base=""
250
+ [[ -f "$nested" ]] && nested_base="$(yflat_in "$nested" "git${US}base_map${US}*")"
251
+
252
+ if [[ -n "$nested_base" ]]; then
253
+ if [[ -n "$listed" && "$listed" != "$nested_base" ]]; then
254
+ bad "repos.$name is '$listed' but $name/.sassywares/config.yaml maps \"*\" to '$nested_base' — the nested config wins; fix or drop the repos entry"
255
+ elif [[ -z "$listed" ]]; then
256
+ note " $name: base '$nested_base' from its own config (no repos entry needed)"
257
+ else
258
+ note " $name: base '$nested_base' (agrees with its own config)"
259
+ fi
260
+ elif [[ -z "$listed" ]]; then
261
+ bad "repos has no entry for '$name' and $name carries no config (remote default: ${base:-unknown})"
262
+ elif [[ -n "$base" && "$listed" != "$base" ]]; then
263
+ note " repos.$name '$listed' overrides the remote default '$base' — expected for an integration branch"
264
+ fi
265
+ done < <(nested_repos)
266
+ fi
267
+
268
+ # Hooks: head-scoped, so `staging` means "the PR is from staging".
269
+ if [[ -n "$(yflat "hooks${US}pr${US}before_create")" ]]; then
270
+ bad "hooks.pr.<point> is now nested by head branch — write hooks.pr.\"*\".<point>"
271
+ fi
272
+ for kind in pr push goal; do
273
+ while IFS= read -r pat; do
274
+ [[ -n "$pat" ]] || continue
275
+ case "$pat" in
276
+ "*") ;;
277
+ *"*") [[ "${pat%\*}" != *"*" ]] || bad "hook pattern '$pat': only one trailing * is allowed" ;;
278
+ esac
279
+ for point in $(hook_points "$kind"); do
280
+ val="$(yflat "hooks${US}${kind}${US}${pat}${US}${point}")"
281
+ [[ -n "$val" ]] || continue
282
+ while IFS= read -r entry; do
283
+ [[ -n "$entry" ]] || continue
284
+ name="${entry%% *}"
285
+ if is_suite_skill "$name"; then
286
+ bad "hooks.$kind.$pat.$point: '$name' is one of our skills — hooks are project skills only"
287
+ else
288
+ hook_skill_path "$name" >/dev/null 2>&1 \
289
+ || bad "hooks.$kind.$pat.$point: '$name' not found at .agents/skills/$name/SKILL.md"
290
+ fi
291
+ done < <(list_items "$val")
292
+ done
293
+ done < <(hook_patterns "$kind")
294
+ done
295
+
296
+ # `hooks.<kind>.<head-or-slug>.<point>` is the only shape. hooks.pr has four
297
+ # points, hooks.push one, hooks.goal two; any other point name is a step that
298
+ # never fires. hooks.worktree is reported where the accepted keys are, once.
299
+ while IFS=$'\t' read -r depth hpath; do
300
+ [[ -n "$depth" ]] || continue
301
+ kind="${hpath#hooks$US}"; kind="${kind%%$US*}"
302
+ case "$kind" in
303
+ pr|push|goal) ;;
304
+ worktree) continue ;;
305
+ *) bad "hooks kind '$kind' is not one of pr|push|goal"; continue ;;
306
+ esac
307
+ if [[ "$depth" != "4" ]]; then
308
+ bad "hooks entry '${hpath//$US/.}' is not key -> point -> list"
309
+ continue
310
+ fi
311
+ point="${hpath##*$US}"
312
+ points="$(hook_points "$kind")"
313
+ case " $points " in
314
+ *" $point "*) ;;
315
+ *) bad "hooks.$kind point '$point' is not one of ${points// /|}" ;;
316
+ esac
317
+ done < <(yaml_flat "$CONFIG" \
318
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n>=2 && a[1]=="hooks") print n "\t" $1}')
319
+
320
+ # Resolve for one head, so nobody has to merge maps in their head.
321
+ if [[ -n "$HEAD_ARG" ]]; then
322
+ if [[ "$TOPOLOGY" == "repo" ]]; then
323
+ note " base for '$HEAD_ARG': $(base_for_head "$HEAD_ARG")"
324
+ fi
325
+ for kind in pr push; do
326
+ for point in $(hook_points "$kind"); do
327
+ resolved="$(hooks_for_head_point "$HEAD_ARG" "$point" "$kind")"
328
+ note " head '$HEAD_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
329
+ done
330
+ done
331
+ fi
332
+
333
+ # Goal hooks are keyed by goal slug, not a branch, so they resolve on their own.
334
+ if [[ -n "$GOAL_ARG" ]]; then
335
+ for point in $(hook_points goal); do
336
+ resolved="$(hooks_for_head_point "$GOAL_ARG" "$point" goal)"
337
+ note " goal '$GOAL_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
338
+ done
339
+ fi
340
+
341
+ # artifacts is the one block that fails closed everywhere it is read, so a
342
+ # bad value here is drift, not a note: a typo must not write docs outside the
343
+ # project. Existence is not drift — the directory is created on first write.
344
+ for key in plans solutions handbooks concepts strategy; do
345
+ val="$(block_value artifacts "$key" || true)"
346
+ [[ -n "$val" ]] || continue
347
+ case "$val" in
348
+ /*|~*) bad "artifacts.$key '$val' is not relative to the config" ;;
349
+ .|./) bad "artifacts.$key is the project root itself" ;;
350
+ *)
351
+ if escapes_root "$val"; then
352
+ bad "artifacts.$key '$val' walks outside the project"
353
+ elif [[ "$val" == */ ]] && [[ "$key" == concepts || "$key" == strategy ]]; then
354
+ bad "artifacts.$key '$val' is a directory — $key is one file (default docs/$key.md)"
355
+ elif path_exists "$val"; then
356
+ note " artifacts.$key: $val (exists)"
357
+ else
358
+ note " artifacts.$key: $val (created on first write)"
359
+ fi
360
+ ;;
361
+ esac
362
+ done
363
+
364
+ # knowledge.read fails soft at read time by design, which is exactly why a
365
+ # broken value has to be visible here: nothing else will ever complain.
366
+ while IFS= read -r kline; do
367
+ [[ -n "$kline" ]] || continue
368
+ bad "knowledge.read must be an inline list — write read: [docs/solutions, docs/concepts.md]"
369
+ done < <(sed -n '/^knowledge:/,/^[a-z]/p' "$CONFIG" | grep -E '^[[:space:]]*-[[:space:]]' || true)
370
+ readv="$(yflat "knowledge${US}read" || true)"
371
+ while IFS= read -r kpath; do
372
+ [[ -n "$kpath" ]] || continue
373
+ case "$kpath" in
374
+ /*|~*) bad "knowledge.read '$kpath' is not a path relative to the config" ;;
375
+ *) if escapes_root "$kpath"; then
376
+ bad "knowledge.read '$kpath' walks outside the project"
377
+ elif ! path_exists "$kpath"; then
378
+ note " knowledge.read '$kpath' does not exist — skipped, not fatal"
379
+ fi ;;
380
+ esac
381
+ done < <(list_items "$readv")
382
+ val="$(yflat "knowledge${US}write" || true)"
383
+ if [[ -n "$val" ]]; then
384
+ case "$val" in
385
+ true|false) note " knowledge.write: $val" ;;
386
+ *) bad "knowledge.write '$val' must be true|false" ;;
387
+ esac
388
+ fi
389
+
390
+ # pr.* answers a policy question, so a value that is neither boolean is a
391
+ # policy nobody decided. Bare on/off are YAML 1.1 booleans and parse
392
+ # inconsistently across readers.
393
+ for key in babysit merge delete_branch; do
394
+ val="$(block_value pr "$key" || true)"
395
+ [[ -n "$val" ]] || continue
396
+ case "$val" in
397
+ true|false) note " pr.$key: $val" ;;
398
+ *) bad "pr.$key '$val' must be true|false, never on/off" ;;
399
+ esac
400
+ done
401
+
402
+ # commit.branch steers whether a run may touch a base branch, so an invalid
403
+ # value is reported rather than silently ignored.
404
+ val="$(yflat "commit${US}branch" 2>/dev/null || true)"
405
+ if [[ -n "$val" ]]; then
406
+ case "$val" in
407
+ current|new) note " commit.branch: $val" ;;
408
+ *) bad "commit.branch '$val' is not current|new" ;;
409
+ esac
410
+ fi
411
+
412
+ # Worktrees: a switch, one mechanical setting, and the project's own lifecycle
413
+ # scripts. Creating, addressing, and refusing all belong to the scripts, so this
414
+ # validates only what a run reads.
415
+ wt_on="$(block_value worktrees enabled || true)"
416
+ case "$wt_on" in
417
+ "") ;;
418
+ true|false) note " worktrees.enabled: $wt_on" ;;
419
+ *) bad "worktrees.enabled '$wt_on' must be true|false" ;;
420
+ esac
421
+
422
+ # worktrees.create/remove name the project's own lifecycle scripts. A declared
423
+ # path that is missing or not executable degrades to the built-in with a
424
+ # warning at run time (D3), so it is a note here, never drift.
425
+ for mode in create remove; do
426
+ declared="$(yflat "worktrees${US}${mode}" 2>/dev/null || true)"
427
+ [[ -n "$declared" ]] || continue
428
+ if reason="$(wt_script_reason "$declared")"; then
429
+ bad "worktrees.$mode: '$declared' $reason"
430
+ elif [[ -f "$ROOT/${declared#./}" && -x "$ROOT/${declared#./}" ]]; then
431
+ note " worktrees.$mode: ${declared#./}"
432
+ # A declared script is the project's file, so its contents are never drift.
433
+ # Without the header the run cannot tell whether it honors the WT_* contract.
434
+ if ! grep -q '^# sassywares:scaffold' "$ROOT/${declared#./}" 2>/dev/null; then
435
+ note " worktrees.$mode: ${declared#./} carries no sassywares:scaffold header — the run cannot tell whether it prints the WT_* block"
436
+ fi
437
+ else
438
+ note " worktrees.$mode '${declared#./}' is missing or not executable — the built-in .sassywares/worktree/$mode is used instead"
439
+ fi
440
+ done
441
+
442
+ # The mechanics are suite-owned and read-only (D4/D5), so `--check` proves the
443
+ # installed set byte for byte against the folder this skill ships, using the
444
+ # skills-lock folder hash. A version header cannot: it is hand-maintained, so
445
+ # an edited byte and an unbumped asset both still read as current. Run whenever
446
+ # the set is installed — a project that flipped the switch off still carries
447
+ # files it may not edit — and keep the missing set a switch-on finding.
448
+ wt_lib="$ROOT/.sassywares/worktree/_lib.sh"
449
+ verify_worktree_set() {
450
+ check_with_node "$SKILL_DIR/scripts/worktree-check.mjs" \
451
+ "node not found — .sassywares/worktree is unverified (the skills CLI needs node)" \
452
+ --installed "$ROOT/.sassywares/worktree" \
453
+ --shipped "$ASSET_WORKTREE"
454
+ for helper in create list remove; do
455
+ [[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
456
+ || bad "missing or not executable: .sassywares/worktree/$helper"
457
+ done
458
+ }
459
+
460
+ if [[ "$wt_on" == "true" ]]; then
461
+ if [[ "$TOPOLOGY" != "repo" ]]; then
462
+ bad "worktrees.enabled needs a repo — this folder is '$TOPOLOGY', and a checkout needs git"
463
+ else
464
+ note " worktrees: a checkout is addressed by the project's own stack, and two checkouts running the same app collide"
465
+ if [[ "$(yflat "commit${US}branch" 2>/dev/null || true)" == "current" ]]; then
466
+ note " worktrees.enabled with commit.branch: current — a run never cuts a branch, so no run offers a checkout"
467
+ fi
468
+
469
+ if [[ -f "$wt_lib" ]]; then
470
+ verify_worktree_set
471
+ else
472
+ bad "worktrees.enabled but .sassywares/worktree/_lib.sh is missing — re-run setup"
473
+ fi
474
+
475
+ # A checkout must live outside the working tree — inside it, `git clean
476
+ # -xdf` deletes uncommitted work and every scanner that ignores .gitignore
477
+ # crawls a second copy of the source. And a worktree parked on a configured
478
+ # base is a run that will commit onto a shared branch unobserved.
479
+ root_real="$(cd "$ROOT" && pwd -P)"
480
+ BASE_VALUES="$(yaml_flat "$CONFIG" \
481
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n==3 && a[1]=="git" && a[2]=="base_map") print $2}' \
482
+ | tr '\n' ' ')"
483
+ wt_paths=()
484
+ while IFS=$'\t' read -r wpath wbranch; do
485
+ [[ -n "$wpath" ]] || continue
486
+ wt_paths+=("$wpath")
487
+ [[ "$wpath" == "$root_real" ]] && continue # the main checkout
488
+ case "$wpath" in
489
+ "$root_real"/*) bad "worktree '$wpath' is inside the working tree — move worktrees.dir outside it" ;;
490
+ esac
491
+ case " $BASE_VALUES " in
492
+ *" $wbranch "*) bad "a worktree holds '$wbranch', which base_map names as a base" ;;
493
+ esac
494
+ done < <(git -C "$ROOT" worktree list --porcelain 2>/dev/null \
495
+ | awk '/^worktree /{p=$2} /^branch /{b=$2; sub(/^refs\/heads\//,"",b); print p "\t" b; p=""} /^detached/{print p "\t(detached)"; p=""}')
496
+
497
+ # A registration whose folder is gone is a ghost `list` still believes in.
498
+ while IFS= read -r ghost; do
499
+ [[ -n "$ghost" ]] || continue
500
+ bad "worktree '$ghost' is prunable — the folder is gone; run: git worktree prune"
501
+ done < <(git -C "$ROOT" worktree list --porcelain 2>/dev/null \
502
+ | awk '/^worktree /{p=$2} /^prunable /{print p; p=""}')
503
+ fi
504
+ fi
505
+
506
+ # The switch is off, but the tooling is installed: still suite-owned, still
507
+ # read-only, so still compared. Nothing here needs a repo or an enabled switch.
508
+ if [[ "$wt_on" != "true" && -f "$wt_lib" ]]; then
509
+ verify_worktree_set
510
+ fi
511
+
512
+ # Dogfood is a pointer and a switch, never commands: the recipe holds the
513
+ # procedure and its `Prove it:` step is the verdict. Everything below is
514
+ # structural. A check run never runs the product — a validator that boots an
515
+ # app is a validator nobody runs.
516
+ dg_enabled="$(block_value dogfood enabled || true)"
517
+ dg_recipe="$(block_value dogfood recipe || true)"
518
+ # The default path applies even when the key is absent: the scripts use it, so
519
+ # --check must lint what they will actually read. Only for a project that has
520
+ # dogfood on, or a recipe already sitting at the default, to avoid noise.
521
+ if [[ -z "$dg_recipe" ]] && { [[ "$dg_enabled" == "true" ]] || [[ -f "$ROOT/.sassywares/dogfood/recipe.md" ]]; }; then
522
+ dg_recipe=".sassywares/dogfood/recipe.md"
523
+ fi
524
+ dg_reports="$(block_value dogfood reports || true)"
525
+ dg_timeout="$(block_value dogfood timeout || true)"
526
+ case "$dg_enabled" in
527
+ "") ;;
528
+ true|false) note " dogfood.enabled: $dg_enabled" ;;
529
+ *) bad "dogfood.enabled '$dg_enabled' must be true|false" ;;
530
+ esac
531
+ for dkey in recipe reports; do
532
+ case "$dkey" in
533
+ recipe) dpath="$dg_recipe" ;;
534
+ *) dpath="$dg_reports" ;;
535
+ esac
536
+ [[ -n "$dpath" ]] || continue
537
+ case "$dpath" in
538
+ /*|~*) bad "dogfood.$dkey '$dpath' is not relative to the config" ;;
539
+ .|./) bad "dogfood.$dkey is the project root itself" ;;
540
+ *) escapes_root "$dpath" && bad "dogfood.$dkey '$dpath' walks outside the project" ;;
541
+ esac
542
+ done
543
+ if [[ -n "$dg_timeout" ]]; then
544
+ case "$dg_timeout" in
545
+ *[!0-9]*) bad "dogfood.timeout '$dg_timeout' is not a positive integer" ;;
546
+ 0) bad "dogfood.timeout is 0 — a procedure that can never finish" ;;
547
+ *) note " dogfood.timeout: ${dg_timeout}s" ;;
548
+ esac
549
+ fi
550
+
551
+ # Reports are logs and screenshots. A project that drops the ignore line
552
+ # commits them, and nobody notices until the history is heavy. Probed with a
553
+ # child path: `/reports/` names a directory, so git only matches it when the
554
+ # probe goes through the directory — and the directory may not exist yet.
555
+ if [[ "$TOPOLOGY" == "repo" && -n "$dg_reports" ]]; then
556
+ if git -C "$ROOT" check-ignore -q -- "$dg_reports/run.log" 2>/dev/null; then
557
+ note " dogfood.reports is gitignored"
558
+ else
559
+ bad "dogfood.reports '$dg_reports' is not gitignored — a run's logs and screenshots would be committed"
560
+ fi
561
+ fi
562
+
563
+ # A committed session is a credential leak, not merely a heavy history. Only
564
+ # checked once the folder exists, so a project that never uses one is silent.
565
+ if [[ "$TOPOLOGY" == "repo" && -d "$ROOT/.sassywares/session" ]]; then
566
+ if git -C "$ROOT" check-ignore -q -- ".sassywares/session/probe" 2>/dev/null; then
567
+ note " .sassywares/session is gitignored"
568
+ else
569
+ bad ".sassywares/session is not gitignored — a session artifact must never be committed"
570
+ fi
571
+ fi
572
+
573
+ if [[ -n "$dg_recipe" ]]; then
574
+ if [[ ! -f "$ROOT/$dg_recipe" ]]; then
575
+ if [[ "$dg_enabled" == "true" ]]; then
576
+ # Enabled with no procedure is the one state that lies: a planner would
577
+ # write Auto rows against a check that does not exist.
578
+ bad "dogfood.recipe '$dg_recipe' does not exist — run sassy-dogfood mode:discover"
579
+ else
580
+ note " dogfood.recipe: $dg_recipe (written by the first sassy-dogfood run)"
581
+ fi
582
+ else
583
+ while IFS= read -r msg; do
584
+ [[ -n "$msg" ]] || continue
585
+ bad "dogfood.recipe $msg"
586
+ done < <(recipe_lint "$ROOT/$dg_recipe")
587
+ while IFS= read -r line0; do
588
+ [[ -n "$line0" ]] || continue
589
+ bad "dogfood.recipe has a secret-shaped string at line $line0 — env var names only, never a value"
590
+ done < <(grep -nE 'sk-[A-Za-z0-9_-]{16,}|ghp_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]{10,}' "$ROOT/$dg_recipe" 2>/dev/null | cut -d: -f1)
591
+ note " dogfood.recipe: $dg_recipe"
592
+ fi
593
+ fi
594
+
595
+ # Hooks that cannot fire are a note, not drift: the config is legal, the step
596
+ # just never runs. hooks.push needs `current` in a single remote repo.
597
+ if [[ "$val" == "current" ]]; then
598
+ if hooks_declared pr; then
599
+ note " hooks.pr entries are declared but commit.branch is current — no PR, so they never run"
600
+ fi
601
+ if hooks_declared push && [[ "$configured_repo" == "workspace" || "$configured_repo" == "none" ]]; then
602
+ note " hooks.push entries are declared but git.repo is '$configured_repo' — they never run"
603
+ fi
604
+ elif hooks_declared push; then
605
+ note " hooks.push entries are declared but commit.branch is not current — they never run"
606
+ fi
607
+
608
+ # The pin. A config can match the tree perfectly while the vendored suite is
609
+ # stale, edited, or half-installed, and every skill downstream then runs
610
+ # something other than what the lock says. Offline, no network.
611
+ [[ -n "$SUITE_ROSTER" ]] || note " suite roster not found — falling back to the sassy-* name prefix"
612
+ check_with_node "$SKILL_DIR/scripts/lockcheck.mjs" \
613
+ "node not found — the vendored pin is unverified (the skills CLI needs node)" \
614
+ --root "$ROOT" --roster "$SUITE_ROSTER"
615
+
616
+ if [[ "$TOPOLOGY" == "repo" ]]; then
617
+ # Tracked, not merely present: a clone has to get the pin without a network
618
+ # call, so an untracked lock is a setup that does not travel.
619
+ # Only a project-scope install has a lock; a user-scope one has nothing here.
620
+ if [[ -n "$(git -C "$ROOT" ls-files -- skills-lock.json 2>/dev/null)" ]]; then
621
+ note " skills-lock.json is tracked"
622
+ elif [[ -f "$ROOT/skills-lock.json" ]]; then
623
+ note " skills-lock.json is not tracked yet — the setup commit carries it"
624
+ fi
625
+ if [[ -e "$ROOT/.claude/skills" ]] && ! git -C "$ROOT" check-ignore -q -- .claude/skills 2>/dev/null; then
626
+ note " .claude/skills is not gitignored — install-time links may get committed"
627
+ fi
628
+ fi
629
+
630
+ # A config can match the tree and still be behind the template: whole blocks,
631
+ # comment layers, and examples a later version added are missing, so the next
632
+ # reader gets a thinner file than the one sassy-setup documents. It is a note,
633
+ # never drift — every value the file declares is valid — and the sync only adds
634
+ # what is missing, so this is the one passing check worth reading.
635
+ template=""
636
+ if template="$(merged_config)"; then
637
+ if [[ "$template" != "$(cat "$CONFIG")" ]]; then
638
+ note " template: --sync --write would $(sync_phrase "$template") (values the check accepts stay) — run: bash $SELF --root $ROOT --sync --write"
639
+ fi
640
+ fi
641
+
642
+ # The routing block: AGENTS.md is what an agent reads before any skill is
643
+ # invoked. A missing or stale block is a note, never drift — the config is
644
+ # complete without it, and --sync --write is the updater.
645
+ shipped_agents="$(agents_md_shipped_version)"
646
+ case "$(agents_md_plan)" in
647
+ create)
648
+ note " agents-md: AGENTS.md is missing — --sync --write would create it with routing block v${shipped_agents}" ;;
649
+ append)
650
+ note " agents-md: AGENTS.md has no routing block — --sync --write would append v${shipped_agents}" ;;
651
+ replace)
652
+ agents_v="$(agents_md_version "$ROOT/AGENTS.md")"
653
+ if [[ "$agents_v" == "$shipped_agents" ]]; then
654
+ note " agents-md: routing block v${agents_v} differs from this skill's copy — --sync --write replaces it in place"
655
+ else
656
+ note " agents-md: routing block is v${agents_v}, this skill ships v${shipped_agents} — --sync --write replaces it in place"
657
+ fi ;;
658
+ current)
659
+ note " agents-md: routing block v${shipped_agents}" ;;
660
+ newer)
661
+ note " agents-md: routing block is v$(agents_md_version "$ROOT/AGENTS.md"), newer than this skill ships (v${shipped_agents}) — left alone" ;;
662
+ unterminated)
663
+ note " agents-md: AGENTS.md has an opening sassywares:skills marker with no matching closing marker — fix it by hand" ;;
664
+ mismatch)
665
+ note " agents-md: AGENTS.md routing block markers disagree on the version — fix it by hand" ;;
666
+ *)
667
+ note " agents-md: routing-block asset not found — AGENTS.md unchecked" ;;
668
+ esac
669
+
670
+ if (( drift )); then exit 1; fi
671
+ note " config matches the tree"
672
+ exit 0
673
+ }