@sassywares/skills 0.17.1 → 0.17.3

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 (36) hide show
  1. package/README.md +28 -6
  2. package/package.json +1 -1
  3. package/skills/sassy-babysit/SKILL.md +2 -2
  4. package/skills/sassy-dogfood/SKILL.md +11 -8
  5. package/skills/sassy-dogfood/references/check.md +5 -3
  6. package/skills/sassy-dogfood/references/discover.md +23 -12
  7. package/skills/sassy-dogfood/references/run.md +91 -17
  8. package/skills/sassy-setup/SKILL.md +5 -5
  9. package/skills/sassy-setup/assets/dogfood-recipe.md +19 -5
  10. package/skills/sassy-setup/references/anchors.md +1 -1
  11. package/skills/sassy-setup/references/branching.md +1 -1
  12. package/skills/sassy-setup/references/check.md +1 -1
  13. package/skills/sassy-setup/references/config.md +66 -14
  14. package/skills/sassy-setup/references/dogfood.md +181 -40
  15. package/skills/sassy-setup/references/harness.md +1 -1
  16. package/skills/sassy-setup/references/init.md +6 -4
  17. package/skills/sassy-setup/references/plan-resolution.md +1 -1
  18. package/skills/sassy-setup/references/scaffold-header.md +9 -2
  19. package/skills/sassy-setup/references/workspace.md +63 -1
  20. package/skills/sassy-setup/references/worktree.md +1 -1
  21. package/skills/sassy-setup/scripts/detect.sh +49 -1982
  22. package/skills/sassy-setup/scripts/hash-skill.mjs +1 -1
  23. package/skills/sassy-setup/scripts/lib/agents-md.sh +513 -0
  24. package/skills/sassy-setup/scripts/lib/branch.sh +200 -0
  25. package/skills/sassy-setup/scripts/lib/check.sh +940 -0
  26. package/skills/sassy-setup/scripts/lib/common.sh +128 -0
  27. package/skills/sassy-setup/scripts/lib/proposal.sh +248 -0
  28. package/skills/sassy-setup/scripts/lib/sync.sh +43 -0
  29. package/skills/sassy-setup/scripts/lib/worktree.sh +57 -0
  30. package/skills/sassy-setup/scripts/lib/yaml.sh +273 -0
  31. package/skills/sassy-setup/scripts/lockcheck.mjs +1 -1
  32. package/skills/sassy-setup/scripts/worktree-check.mjs +1 -1
  33. package/skills/sassy-ship/SKILL.md +4 -4
  34. package/skills/sassy-ship/references/brief.md +1 -1
  35. package/skills/sassy-ship/references/plan.md +1 -1
  36. package/skills/sassy-ship/references/slice.md +1 -1
@@ -0,0 +1,940 @@
1
+ # generated_by: sassy-setup@0.17.3
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 run directory is named YYYYMMDD-HHMMSS: fixed-width, so a lexical sort is
11
+ # chronological. Older runs may carry a legacy `-<label>` suffix; its first 15
12
+ # characters are still the clock id, so the same sort holds and it counts as one
13
+ # run. A new run never writes a label. The reports root holds runs directly
14
+ # (reports/<run-id>); once a workspace run files per repo (reports/<repo>/<run-id>)
15
+ # the level below the root is a bucket, told apart from a run by its name alone.
16
+ # Counting per bucket is the rule either way, so the nesting is a new writer, not
17
+ # a new count.
18
+ is_run_id() {
19
+ local n="$1"
20
+ [[ "$n" =~ ^[0-9]{8}-[0-9]{6}(-[A-Za-z0-9][A-Za-z0-9._-]*)?$ ]]
21
+ }
22
+ dogfood_run_counts() { # <reports-root> -> "<bucket>\t<count>", one per bucket
23
+ local root="$1" d c n cn
24
+ [[ -d "$root" ]] || return 0
25
+ # A `*/` glob only matches directories, and an unmatched one stays literal
26
+ # and fails is_run_id, so neither loop needs a guard of its own.
27
+ for d in "$root"/*/; do
28
+ n="$(basename "$d")"
29
+ if is_run_id "$n"; then
30
+ # `.` is the flat root bucket: a leading empty field would be swallowed
31
+ # by `read`'s IFS whitespace handling, and a sentinel keeps the two
32
+ # layouts on one code path.
33
+ printf '.\t%s\n' "$n"
34
+ else
35
+ for c in "$d"*/; do
36
+ cn="$(basename "$c")"
37
+ is_run_id "$cn" && printf '%s\t%s\n' "$n" "$cn"
38
+ done
39
+ fi
40
+ done | awk -F'\t' '{seen[$1]++} END {for (b in seen) printf "%s\t%d\n", b, seen[b]}' | sort
41
+ }
42
+
43
+ # A node checker prints `<drift|note>\t<message>` lines and exits 0; the caller
44
+ # owns the verdict, so its exit status is a finding too. Silencing a crash into
45
+ # zero output would read as "nothing to report", which is the one thing a
46
+ # verifier must never mean. On failure the first output line names the crash.
47
+ check_with_node() { # <script> <missing-node note> [args...]
48
+ local script="$1" missing="$2" out first kind msg
49
+ shift 2
50
+ if ! command -v node >/dev/null 2>&1; then
51
+ note " $missing"
52
+ return 0
53
+ fi
54
+ if out="$(node "$script" "$@" 2>&1)"; then
55
+ while IFS=$'\t' read -r kind msg; do
56
+ case "$kind" in
57
+ drift) bad "$msg" ;;
58
+ note) note " $msg" ;;
59
+ esac
60
+ done <<< "$out"
61
+ else
62
+ first="$(printf '%s\n' "$out" | head -n 1)"
63
+ bad "$(basename "$script") failed — ${first:-it exited non-zero with no output}"
64
+ fi
65
+ return 0
66
+ }
67
+
68
+ note "root: ${ROOT}"
69
+ note "config: ${CONFIG:-none found (walking up from $START)}"
70
+
71
+ if [[ -z "$CONFIG" ]]; then
72
+ bad "no .sassywares/config.yaml found — run sassy-setup"
73
+ exit 1
74
+ fi
75
+
76
+ configured_repo="$(config_value repo 2>/dev/null || true)"
77
+ if [[ -z "$configured_repo" ]]; then
78
+ bad "git.repo is unset"
79
+ elif [[ "$TOPOLOGY" == "repo" ]]; then
80
+ # The tree is a repo: the configured value must name one of its remotes.
81
+ case "$configured_repo" in
82
+ workspace|none) bad "git.repo is '$configured_repo' but this folder is a git repo" ;;
83
+ *) git -C "$ROOT" remote 2>/dev/null | grep -qx "$configured_repo" \
84
+ || bad "git.repo '$configured_repo' is not a remote of this repo" ;;
85
+ esac
86
+ else
87
+ # Not a repo: `workspace` and `none` are both legal, and which one is a
88
+ # human policy call the tree cannot verify.
89
+ case "$configured_repo" in
90
+ workspace|none) note " not a repo; '$configured_repo' accepted" ;;
91
+ *) bad "git.repo is '$configured_repo' but this folder is not a git repo" ;;
92
+ esac
93
+ fi
94
+
95
+ # A typo'd key is the quietest failure in the file: it parses, it is ignored,
96
+ # and the run silently falls back to a default the project never chose. The
97
+ # whitelist is the schema in references/config.md; every key there has a
98
+ # validator of its own below, so anything landing here is unknown.
99
+ lost_hooks_reported=0
100
+ while IFS=$'\t' read -r kpath kvalue; do
101
+ [[ -n "$kpath" ]] || continue
102
+ key="${kpath//$US/.}"
103
+ case "$key" in
104
+ artifacts.plans|artifacts.solutions|artifacts.handbooks|artifacts.concepts|artifacts.strategy) ;;
105
+ knowledge.read|knowledge.write) ;;
106
+ git.repo|git.remote|git.mirror_branch) ;;
107
+ git.default_branch) ;; # has its own message below
108
+ git.base_map.*) ;;
109
+ repos.*) ;;
110
+ commit.branch) ;;
111
+ pr.babysit|pr.merge|pr.delete_branch) ;;
112
+ dogfood.enabled|dogfood.recipe|dogfood.reports|dogfood.timeout|dogfood.keep) ;;
113
+ dogfood.recipes|dogfood.recipes.*) ;; # the map's shape is checked below
114
+ worktrees.enabled|worktrees.dir) ;;
115
+ worktrees.create|worktrees.remove)
116
+ # A single path, no arguments: the script is the lifecycle, so a command
117
+ # line here would define a second place it lives.
118
+ case "$kvalue" in
119
+ \[*|\{*) bad "$key is a list or block — write one path: $key: scripts/worktrees/${key##*.}" ;;
120
+ esac ;;
121
+ up|down)
122
+ # Removed with the project-script lifecycle (D3/D11): a run stops and
123
+ # starts through the project's own create/remove, not a key. A soft
124
+ # warning would let a project believe its stack still stops.
125
+ bad "$key is gone — the lifecycle moved into worktrees.create and worktrees.remove. Delete the '$key:' line from .sassywares/config.yaml" ;;
126
+ hooks.worktree|hooks.worktree.*)
127
+ # Same migration: what a worktree needed to prepare or tear down is now
128
+ # inside the project's scripts, which the suite runs instead. One block
129
+ # is one fix, so report it once however many points it lists.
130
+ if (( ! lost_hooks_reported )); then
131
+ 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"
132
+ lost_hooks_reported=1
133
+ fi ;;
134
+ worktrees.ports)
135
+ # Deleted from the schema. The one line that fixes it is the line itself.
136
+ bad "worktrees.ports is gone — delete the 'ports:' line under worktrees in .sassywares/config.yaml" ;;
137
+ hooks.*) ;; # shape checked with the hooks
138
+ *) bad "unknown key '$key' — it is ignored, so the run uses the default" ;;
139
+ esac
140
+ done < <(yaml_flat "$CONFIG")
141
+
142
+ if [[ -n "$(yflat "git${US}default_branch")" ]]; then
143
+ if [[ "$TOPOLOGY" == "workspace" ]]; then
144
+ bad "git.default_branch is gone — the mirror's branch is git.mirror_branch"
145
+ else
146
+ bad "git.default_branch is gone — use git.base_map with a \"*\" entry"
147
+ fi
148
+ fi
149
+
150
+ if [[ "$TOPOLOGY" == "repo" ]]; then
151
+ if [[ -n "$(yflat "git${US}remote")" ]]; then
152
+ bad "git.remote is workspace-only — a repo config names its remote in git.repo"
153
+ fi
154
+ if [[ -n "$(yflat "git${US}mirror_branch")" ]]; then
155
+ bad "git.mirror_branch is workspace-only — a repo routes branches in git.base_map"
156
+ fi
157
+ if [[ -z "$(yflat "git${US}base_map${US}*")" ]]; then
158
+ bad "git.base_map has no \"*\" entry — it is the base for ordinary work"
159
+ else
160
+ while IFS= read -r pat; do
161
+ [[ -n "$pat" ]] || continue
162
+ case "$pat" in
163
+ "*") ;;
164
+ *"*") [[ "${pat%\*}" != *"*" ]] || bad "base_map key '$pat': only one trailing * is allowed" ;;
165
+ esac
166
+ 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)
167
+ head_ref="${HEAD_ARG:-$(git -C "$ROOT" branch --show-current 2>/dev/null || true)}"
168
+ if [[ -n "$head_ref" ]]; then
169
+ # the --head readout below prints this line; avoid printing it twice
170
+ [[ -n "$HEAD_ARG" ]] || note " base for '${head_ref}': $(base_for_head "$head_ref")"
171
+ cur="$head_ref"; hops=0
172
+ while [[ -n "$cur" ]] && (( hops < 8 )); do
173
+ next="$(yflat "git${US}base_map${US}${cur}")"
174
+ [[ -z "$next" ]] && break
175
+ cur="$next"; hops=$((hops + 1))
176
+ if [[ "$cur" == "$head_ref" ]]; then
177
+ bad "git.base_map cycles through '$head_ref'"; break
178
+ fi
179
+ done
180
+ else
181
+ note " detached HEAD — pass --head <branch> to see the resolved base"
182
+ fi
183
+ fi
184
+ fi
185
+
186
+ # `repos` is the workspace inventory. In a repo config it is a dead map, and
187
+ # a reader would trust it over the base_map that actually applies.
188
+ if [[ "$configured_repo" != "workspace" ]]; then
189
+ while IFS= read -r rname; do
190
+ [[ -n "$rname" ]] || continue
191
+ bad "repos.$rname is workspace-only — git.repo is '${configured_repo:-unset}'"
192
+ done < <(repo_names | sort -u)
193
+ fi
194
+
195
+ if [[ "$TOPOLOGY" == "workspace" ]]; then
196
+ [[ -n "$MIRROR_REMOTE" ]] || bad "git.remote is required when git.repo is workspace"
197
+ installed="$ROOT/.sassywares/workspace/snapshot"
198
+ if [[ -x "$installed" ]]; then
199
+ installed_v="$(sed -n 's/^# snapshot-version: //p' "$installed" | head -n 1)"
200
+ asset_v="$(sed -n 's/^# snapshot-version: //p' "$ASSET_SNAPSHOT" | head -n 1)"
201
+ if [[ -z "$installed_v" ]]; then
202
+ bad "installed .sassywares/workspace/snapshot has no version line"
203
+ elif [[ "$installed_v" != "$asset_v" ]]; then
204
+ bad "installed snapshot is v${installed_v}, this skill ships v${asset_v} — re-run setup"
205
+ else
206
+ note " snapshot v${installed_v}"
207
+ fi
208
+ else
209
+ bad "missing .sassywares/workspace/snapshot"
210
+ fi
211
+
212
+ # The git helpers are optional as a set, but a half-installed or stale set is
213
+ # drift: they read `repos:` from this config, so a version skew means the
214
+ # project is running a reader written for a different map.
215
+ installed_lib="$ROOT/.sassywares/workspace/_lib.sh"
216
+ if [[ -f "$installed_lib" ]]; then
217
+ lib_v="$(sed -n 's/^# workspace-git-version: //p' "$installed_lib" | head -n 1)"
218
+ asset_lib_v="$(sed -n 's/^# workspace-git-version: //p' "$ASSET_WORKSPACE/_lib.sh" | head -n 1)"
219
+ lib_var="$(sed -n 's/^WORKSPACE_GIT_VERSION="\(.*\)"/\1/p' "$installed_lib" | head -n 1)"
220
+ if [[ -n "$lib_var" && -n "$lib_v" && "$lib_var" != "$lib_v" ]]; then
221
+ bad ".sassywares/workspace/_lib.sh header says v${lib_v} but the script reports v${lib_var} — the file was half-bumped"
222
+ fi
223
+ if [[ -z "$lib_v" ]]; then
224
+ bad "installed .sassywares/workspace/_lib.sh has no workspace-git-version line"
225
+ elif [[ -n "$asset_lib_v" && "$lib_v" != "$asset_lib_v" ]]; then
226
+ bad "installed workspace git helpers are v${lib_v}, this skill ships v${asset_lib_v} — re-run setup"
227
+ else
228
+ note " workspace-git v${lib_v}"
229
+ fi
230
+ for helper in branches pull checkout-bases; do
231
+ if [[ ! -x "$ROOT/.sassywares/workspace/$helper" ]]; then
232
+ bad "missing or not executable: .sassywares/workspace/$helper"
233
+ fi
234
+ done
235
+ else
236
+ note " no workspace git helpers installed (optional)"
237
+ fi
238
+
239
+ # Aliases are optional: the scripts are run by path, and a project that wired
240
+ # only the ones its runner needs is not drifting. Reported, never failed.
241
+ # The manifest is never enumerated here — sassy-overview's identify.sh names
242
+ # the stack and the file that declares it (D20).
243
+ manifest=""
244
+ identify="$SKILL_DIR/../sassy-overview/scripts/identify.sh"
245
+ if [[ -f "$identify" ]]; then
246
+ stack_line="$(bash "$identify" --root "$ROOT" --key stack 2>/dev/null || true)"
247
+ while IFS=$'\t' read -r _key stack_val stack_src; do
248
+ # Only a named-scripts manifest has an alias slot; anything else is
249
+ # simply not wired, and that is complete.
250
+ case "$stack_val" in
251
+ node|php|deno) if [[ "$stack_src" != "-" ]]; then manifest="$stack_src"; fi ;;
252
+ esac
253
+ done <<< "$stack_line"
254
+ else
255
+ note " sassy-overview is not installed — workspace aliases unchecked"
256
+ fi
257
+ if [[ -n "$manifest" ]]; then
258
+ missing_aliases=()
259
+ missing_list=""
260
+ for script in branches pull checkout-bases snapshot; do
261
+ if ! grep -q "\"workspace:${script}\"" "$ROOT/$manifest"; then
262
+ missing_aliases+=("$script")
263
+ missing_list+="${missing_list:+, }workspace:${script}"
264
+ fi
265
+ done
266
+ if [[ ${#missing_aliases[@]} -eq 0 ]]; then
267
+ note " workspace:* aliases in ${manifest}"
268
+ elif [[ ${#missing_aliases[@]} -lt 4 ]]; then
269
+ note " aliases: ${missing_list} not wired in ${manifest} (optional — the scripts run by path)"
270
+ else
271
+ note " no workspace:* aliases in ${manifest} (optional)"
272
+ fi
273
+ fi
274
+ while IFS= read -r name; do
275
+ [[ -n "$name" ]] || continue
276
+ base="$(detect_base "$ROOT/$name")"
277
+ listed="$(block_value repos "$name" || true)"
278
+ # A nested repo's own config is authoritative; `repos` is the inventory and
279
+ # the fallback for repos that have none.
280
+ nested="$ROOT/$name/.sassywares/config.yaml"
281
+ nested_base=""
282
+ [[ -f "$nested" ]] && nested_base="$(yflat_in "$nested" "git${US}base_map${US}*")"
283
+
284
+ if [[ -n "$nested_base" ]]; then
285
+ if [[ -n "$listed" && "$listed" != "$nested_base" ]]; then
286
+ bad "repos.$name is '$listed' but $name/.sassywares/config.yaml maps \"*\" to '$nested_base' — the nested config wins; fix or drop the repos entry"
287
+ elif [[ -z "$listed" ]]; then
288
+ note " $name: base '$nested_base' from its own config (no repos entry needed)"
289
+ else
290
+ note " $name: base '$nested_base' (agrees with its own config)"
291
+ fi
292
+ elif [[ -z "$listed" ]]; then
293
+ bad "repos has no entry for '$name' and $name carries no config (remote default: ${base:-unknown})"
294
+ elif [[ -n "$base" && "$listed" != "$base" ]]; then
295
+ note " repos.$name '$listed' overrides the remote default '$base' — expected for an integration branch"
296
+ fi
297
+ done < <(nested_repos)
298
+ fi
299
+
300
+ # Hooks: head-scoped, so `staging` means "the PR is from staging".
301
+ if [[ -n "$(yflat "hooks${US}pr${US}before_create")" ]]; then
302
+ bad "hooks.pr.<point> is now nested by head branch — write hooks.pr.\"*\".<point>"
303
+ fi
304
+ for kind in pr push goal; do
305
+ while IFS= read -r pat; do
306
+ [[ -n "$pat" ]] || continue
307
+ case "$pat" in
308
+ "*") ;;
309
+ *"*") [[ "${pat%\*}" != *"*" ]] || bad "hook pattern '$pat': only one trailing * is allowed" ;;
310
+ esac
311
+ for point in $(hook_points "$kind"); do
312
+ val="$(yflat "hooks${US}${kind}${US}${pat}${US}${point}")"
313
+ [[ -n "$val" ]] || continue
314
+ while IFS= read -r entry; do
315
+ [[ -n "$entry" ]] || continue
316
+ name="${entry%% *}"
317
+ if is_suite_skill "$name"; then
318
+ bad "hooks.$kind.$pat.$point: '$name' is one of our skills — hooks are project skills only"
319
+ else
320
+ hook_skill_path "$name" >/dev/null 2>&1 \
321
+ || bad "hooks.$kind.$pat.$point: '$name' not found at .agents/skills/$name/SKILL.md"
322
+ fi
323
+ done < <(list_items "$val")
324
+ done
325
+ done < <(hook_patterns "$kind")
326
+ done
327
+
328
+ # `hooks.<kind>.<head-or-slug>.<point>` is the only shape. hooks.pr has four
329
+ # points, hooks.push one, hooks.goal two; any other point name is a step that
330
+ # never fires. hooks.worktree is reported where the accepted keys are, once.
331
+ while IFS=$'\t' read -r depth hpath; do
332
+ [[ -n "$depth" ]] || continue
333
+ kind="${hpath#hooks$US}"; kind="${kind%%$US*}"
334
+ case "$kind" in
335
+ pr|push|goal) ;;
336
+ worktree) continue ;;
337
+ *) bad "hooks kind '$kind' is not one of pr|push|goal"; continue ;;
338
+ esac
339
+ if [[ "$depth" != "4" ]]; then
340
+ bad "hooks entry '${hpath//$US/.}' is not key -> point -> list"
341
+ continue
342
+ fi
343
+ point="${hpath##*$US}"
344
+ points="$(hook_points "$kind")"
345
+ case " $points " in
346
+ *" $point "*) ;;
347
+ *) bad "hooks.$kind point '$point' is not one of ${points// /|}" ;;
348
+ esac
349
+ done < <(yaml_flat "$CONFIG" \
350
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n>=2 && a[1]=="hooks") print n "\t" $1}')
351
+
352
+ # Resolve for one head, so nobody has to merge maps in their head.
353
+ if [[ -n "$HEAD_ARG" ]]; then
354
+ if [[ "$TOPOLOGY" == "repo" ]]; then
355
+ note " base for '$HEAD_ARG': $(base_for_head "$HEAD_ARG")"
356
+ fi
357
+ for kind in pr push; do
358
+ for point in $(hook_points "$kind"); do
359
+ resolved="$(hooks_for_head_point "$HEAD_ARG" "$point" "$kind")"
360
+ note " head '$HEAD_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
361
+ done
362
+ done
363
+ fi
364
+
365
+ # Goal hooks are keyed by goal slug, not a branch, so they resolve on their own.
366
+ if [[ -n "$GOAL_ARG" ]]; then
367
+ for point in $(hook_points goal); do
368
+ resolved="$(hooks_for_head_point "$GOAL_ARG" "$point" goal)"
369
+ note " goal '$GOAL_ARG' → $point: $( [[ -n "$resolved" ]] && printf '%s' "$resolved" || printf 'none' )"
370
+ done
371
+ fi
372
+
373
+ # artifacts is the one block that fails closed everywhere it is read, so a
374
+ # bad value here is drift, not a note: a typo must not write docs outside the
375
+ # project. Existence is not drift — the directory is created on first write.
376
+ for key in plans solutions handbooks concepts strategy; do
377
+ val="$(block_value artifacts "$key" || true)"
378
+ [[ -n "$val" ]] || continue
379
+ case "$val" in
380
+ /*|~*) bad "artifacts.$key '$val' is not relative to the config" ;;
381
+ .|./) bad "artifacts.$key is the project root itself" ;;
382
+ *)
383
+ if escapes_root "$val"; then
384
+ bad "artifacts.$key '$val' walks outside the project"
385
+ elif [[ "$val" == */ ]] && [[ "$key" == concepts || "$key" == strategy ]]; then
386
+ bad "artifacts.$key '$val' is a directory — $key is one file (default docs/$key.md)"
387
+ elif path_exists "$val"; then
388
+ note " artifacts.$key: $val (exists)"
389
+ else
390
+ note " artifacts.$key: $val (created on first write)"
391
+ fi
392
+ ;;
393
+ esac
394
+ done
395
+
396
+ # knowledge.read fails soft at read time by design, which is exactly why a
397
+ # broken value has to be visible here: nothing else will ever complain.
398
+ while IFS= read -r kline; do
399
+ [[ -n "$kline" ]] || continue
400
+ bad "knowledge.read must be an inline list — write read: [docs/solutions, docs/concepts.md]"
401
+ done < <(sed -n '/^knowledge:/,/^[a-z]/p' "$CONFIG" | grep -E '^[[:space:]]*-[[:space:]]' || true)
402
+ readv="$(yflat "knowledge${US}read" || true)"
403
+ while IFS= read -r kpath; do
404
+ [[ -n "$kpath" ]] || continue
405
+ case "$kpath" in
406
+ /*|~*) bad "knowledge.read '$kpath' is not a path relative to the config" ;;
407
+ *) if escapes_root "$kpath"; then
408
+ bad "knowledge.read '$kpath' walks outside the project"
409
+ elif ! path_exists "$kpath"; then
410
+ note " knowledge.read '$kpath' does not exist — skipped, not fatal"
411
+ fi ;;
412
+ esac
413
+ done < <(list_items "$readv")
414
+ val="$(yflat "knowledge${US}write" || true)"
415
+ if [[ -n "$val" ]]; then
416
+ case "$val" in
417
+ true|false) note " knowledge.write: $val" ;;
418
+ *) bad "knowledge.write '$val' must be true|false" ;;
419
+ esac
420
+ fi
421
+
422
+ # pr.* answers a policy question, so a value that is neither boolean is a
423
+ # policy nobody decided. Bare on/off are YAML 1.1 booleans and parse
424
+ # inconsistently across readers.
425
+ for key in babysit merge delete_branch; do
426
+ val="$(block_value pr "$key" || true)"
427
+ [[ -n "$val" ]] || continue
428
+ case "$val" in
429
+ true|false) note " pr.$key: $val" ;;
430
+ *) bad "pr.$key '$val' must be true|false, never on/off" ;;
431
+ esac
432
+ done
433
+
434
+ # commit.branch steers whether a run may touch a base branch, so an invalid
435
+ # value is reported rather than silently ignored.
436
+ val="$(yflat "commit${US}branch" 2>/dev/null || true)"
437
+ if [[ -n "$val" ]]; then
438
+ case "$val" in
439
+ current|new) note " commit.branch: $val" ;;
440
+ *) bad "commit.branch '$val' is not current|new" ;;
441
+ esac
442
+ fi
443
+
444
+ # Worktrees: a switch, one mechanical setting, and the project's own lifecycle
445
+ # scripts. Creating, addressing, and refusing all belong to the scripts, so this
446
+ # validates only what a run reads.
447
+ wt_on="$(block_value worktrees enabled || true)"
448
+ case "$wt_on" in
449
+ "") ;;
450
+ true|false) note " worktrees.enabled: $wt_on" ;;
451
+ *) bad "worktrees.enabled '$wt_on' must be true|false" ;;
452
+ esac
453
+
454
+ # worktrees.create/remove name the project's own lifecycle scripts. A declared
455
+ # path that is missing or not executable degrades to the built-in with a
456
+ # warning at run time (D3), so it is a note here, never drift.
457
+ for mode in create remove; do
458
+ declared="$(yflat "worktrees${US}${mode}" 2>/dev/null || true)"
459
+ [[ -n "$declared" ]] || continue
460
+ if reason="$(wt_script_reason "$declared")"; then
461
+ bad "worktrees.$mode: '$declared' $reason"
462
+ elif [[ -f "$ROOT/${declared#./}" && -x "$ROOT/${declared#./}" ]]; then
463
+ note " worktrees.$mode: ${declared#./}"
464
+ # A declared script is the project's file, so its contents are never drift.
465
+ # Without the header the run cannot tell whether it honors the WT_* contract.
466
+ if ! grep -q '^# sassywares:scaffold' "$ROOT/${declared#./}" 2>/dev/null; then
467
+ note " worktrees.$mode: ${declared#./} carries no sassywares:scaffold header — the run cannot tell whether it prints the WT_* block"
468
+ fi
469
+ else
470
+ note " worktrees.$mode '${declared#./}' is missing or not executable — the built-in .sassywares/worktree/$mode is used instead"
471
+ fi
472
+ done
473
+
474
+ # The mechanics are suite-owned and read-only (D4/D5), so `--check` proves the
475
+ # installed set byte for byte against the folder this skill ships, using the
476
+ # skills-lock folder hash. A version header cannot: it is hand-maintained, so
477
+ # an edited byte and an unbumped asset both still read as current. Run whenever
478
+ # the set is installed — a project that flipped the switch off still carries
479
+ # files it may not edit — and keep the missing set a switch-on finding.
480
+ wt_lib="$ROOT/.sassywares/worktree/_lib.sh"
481
+ verify_worktree_set() {
482
+ check_with_node "$SKILL_DIR/scripts/worktree-check.mjs" \
483
+ "node not found — .sassywares/worktree is unverified (the skills CLI needs node)" \
484
+ --installed "$ROOT/.sassywares/worktree" \
485
+ --shipped "$ASSET_WORKTREE"
486
+ for helper in create list remove; do
487
+ [[ -x "$ROOT/.sassywares/worktree/$helper" ]] \
488
+ || bad "missing or not executable: .sassywares/worktree/$helper"
489
+ done
490
+ }
491
+
492
+ if [[ "$wt_on" == "true" ]]; then
493
+ if [[ "$TOPOLOGY" != "repo" ]]; then
494
+ bad "worktrees.enabled needs a repo — this folder is '$TOPOLOGY', and a checkout needs git"
495
+ else
496
+ note " worktrees: a checkout is addressed by the project's own stack, and two checkouts running the same app collide"
497
+ if [[ "$(yflat "commit${US}branch" 2>/dev/null || true)" == "current" ]]; then
498
+ note " worktrees.enabled with commit.branch: current — a run never cuts a branch, so no run offers a checkout"
499
+ fi
500
+
501
+ if [[ -f "$wt_lib" ]]; then
502
+ verify_worktree_set
503
+ else
504
+ bad "worktrees.enabled but .sassywares/worktree/_lib.sh is missing — re-run setup"
505
+ fi
506
+
507
+ # A checkout must live outside the working tree — inside it, `git clean
508
+ # -xdf` deletes uncommitted work and every scanner that ignores .gitignore
509
+ # crawls a second copy of the source. And a worktree parked on a configured
510
+ # base is a run that will commit onto a shared branch unobserved.
511
+ root_real="$(cd "$ROOT" && pwd -P)"
512
+ BASE_VALUES="$(yaml_flat "$CONFIG" \
513
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n==3 && a[1]=="git" && a[2]=="base_map") print $2}' \
514
+ | tr '\n' ' ')"
515
+ wt_paths=()
516
+ while IFS=$'\t' read -r wpath wbranch; do
517
+ [[ -n "$wpath" ]] || continue
518
+ wt_paths+=("$wpath")
519
+ [[ "$wpath" == "$root_real" ]] && continue # the main checkout
520
+ case "$wpath" in
521
+ "$root_real"/*) bad "worktree '$wpath' is inside the working tree — move worktrees.dir outside it" ;;
522
+ esac
523
+ case " $BASE_VALUES " in
524
+ *" $wbranch "*) bad "a worktree holds '$wbranch', which base_map names as a base" ;;
525
+ esac
526
+ done < <(git -C "$ROOT" worktree list --porcelain 2>/dev/null \
527
+ | awk '/^worktree /{p=$2} /^branch /{b=$2; sub(/^refs\/heads\//,"",b); print p "\t" b; p=""} /^detached/{print p "\t(detached)"; p=""}')
528
+
529
+ # A registration whose folder is gone is a ghost `list` still believes in.
530
+ while IFS= read -r ghost; do
531
+ [[ -n "$ghost" ]] || continue
532
+ bad "worktree '$ghost' is prunable — the folder is gone; run: git worktree prune"
533
+ done < <(git -C "$ROOT" worktree list --porcelain 2>/dev/null \
534
+ | awk '/^worktree /{p=$2} /^prunable /{print p; p=""}')
535
+ fi
536
+ fi
537
+
538
+ # The switch is off, but the tooling is installed: still suite-owned, still
539
+ # read-only, so still compared. Nothing here needs a repo or an enabled switch.
540
+ if [[ "$wt_on" != "true" && -f "$wt_lib" ]]; then
541
+ verify_worktree_set
542
+ fi
543
+
544
+ # Dogfood is a pointer and a switch, never commands: the recipe holds the
545
+ # procedure and its `Prove it:` step is the verdict. Everything below is
546
+ # structural. A check run never runs the product — a validator that boots an
547
+ # app is a validator nobody runs.
548
+ # The recipe is the project's own document, so it lives in docs/ with the other
549
+ # documents the project edits; .sassywares/ is suite-owned state and never holds
550
+ # project-editable content.
551
+ dg_recipe_default="docs/dogfood.md"
552
+ dg_recipe_legacy=".sassywares/dogfood/recipe.md"
553
+ dg_enabled="$(block_value dogfood enabled || true)"
554
+ dg_recipe="$(block_value dogfood recipe || true)"
555
+ # The repos a workspace inventories — the key set `dogfood.recipes` is keyed by.
556
+ dg_repo_set=" $(repo_names | tr '\n' ' ')"
557
+ # Whether the workspace has already declared the per-repo map. Read here, before
558
+ # any path check, because a leftover legacy file is judged by it: once the map is
559
+ # written the split is user-directed and under way, which is D18's own
560
+ # intermediate state, not a migration that has not started.
561
+ dg_map_declared=0
562
+ if yaml_flat "$CONFIG" 2>/dev/null | grep -q "^dogfood${US}recipes${US}"; then
563
+ dg_map_declared=1
564
+ fi
565
+
566
+ # The shape tail both path checks share: relative to the config, never the
567
+ # root itself, never outside the project. One line on stdout, or nothing.
568
+ dg_path_tail() { # <label> <value>
569
+ local label="$1" v="$2"
570
+ case "$v" in
571
+ /*|~*) printf "%s '%s' is not relative to the config\n" "$label" "$v"; return 0 ;;
572
+ .|./) printf '%s is the project root itself\n' "$label"; return 0 ;;
573
+ esac
574
+ escapes_root "$v" && printf "%s '%s' walks outside the project\n" "$label" "$v"
575
+ return 0
576
+ }
577
+ # A recipe file that exists: its structural lint, its secret-shaped scan, and
578
+ # the path note. The map's values and the single recipe differ only by label.
579
+ dg_recipe_file() { # <path> <label>
580
+ local path="$1" label="$2" msg line0
581
+ while IFS= read -r msg; do
582
+ [[ -n "$msg" ]] || continue
583
+ bad "$label $msg"
584
+ done < <(recipe_lint "$ROOT/$path")
585
+ while IFS= read -r line0; do
586
+ [[ -n "$line0" ]] || continue
587
+ bad "$label has a secret-shaped string at line $line0 — env var names only, never a value"
588
+ 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/$path" 2>/dev/null | cut -d: -f1)
589
+ note " $label: $path"
590
+ }
591
+
592
+ # The map a workspace must write, built once from repos: so both the combined
593
+ # `recipe:` stop and the pre-P1 legacy-file stop name the same files.
594
+ dg_split_map=""
595
+ dg_split_repos=""
596
+ if [[ "$configured_repo" == "workspace" ]]; then
597
+ for r in $dg_repo_set; do
598
+ dg_split_map="$dg_split_map${dg_split_map:+, }$r: docs/dogfood/$r.md"
599
+ dg_split_repos="$dg_split_repos${dg_split_repos:+, }$r"
600
+ done
601
+ if [[ -z "$dg_split_map" ]]; then
602
+ dg_split_map="<repo>: docs/dogfood/<repo>.md"
603
+ dg_split_repos="<repo>"
604
+ fi
605
+ fi
606
+ dg_split=0
607
+ if [[ "$configured_repo" == "workspace" && -n "$dg_recipe" ]]; then
608
+ # D14/D18: a workspace declares one recipe per repo, keyed by `repos:`, so an
609
+ # agent dogfooding one repo never has to read every other repo's procedure.
610
+ # One combined recipe is the shape the rule replaces, and it is a stop rather
611
+ # than a working fallback — that fallback is how a combined recipe sat in a
612
+ # workspace for a week. The project owns the file, so the finding names the
613
+ # split and the map to write, in prose: a printed `cp` can target its own
614
+ # source (`recipe: docs/dogfood/fe.md`) or overwrite a file the user already
615
+ # finished, and an `rm` would delete a project-owned document. The suite
616
+ # never moves or deletes it.
617
+ dg_split="dogfood.recipe is '$dg_recipe', one combined procedure — a workspace declares one recipe per repo, at docs/dogfood/<repo>.md, as a 'recipes:' map under dogfood: keyed by repos:. Dogfooding is stopped until it is split: create one file per repo ($dg_split_repos) under docs/dogfood/ and carry over only that repo's sections; '$dg_recipe' stays where it is until you decide every section is distributed, and no command here copies or deletes it. Then replace 'recipe: $dg_recipe' with 'recipes:' in .sassywares/config.yaml — $dg_split_map"
618
+ if [[ "$dg_enabled" == "true" ]]; then
619
+ bad "$dg_split"
620
+ else
621
+ note " $dg_split"
622
+ fi
623
+ # The single-recipe path below is a repo-topology form: nothing else here
624
+ # lints the combined file or claims the per-repo map is missing — the split
625
+ # already says what to write, and nine "no entry for" notes under it would
626
+ # bury the one finding that matters.
627
+ dg_recipe=""
628
+ dg_split=1
629
+ elif [[ "$dg_recipe" == "$dg_recipe_legacy" ]] || { [[ -z "$dg_recipe" ]] && [[ -f "$ROOT/$dg_recipe_legacy" ]]; }; then
630
+ # A recipe still at the old path is a migration, and the project owns the file:
631
+ # the suite never moves it. In a repo topology the finding is the exact move; in
632
+ # a workspace that move would put the combined procedure at the single-repo path,
633
+ # which is the shape P4 replaces — so the workspace form names the per-repo split
634
+ # and prints no command at all, because nothing here copies or deletes a
635
+ # project-owned document. With dogfood on it is a hard stop — a run would keep
636
+ # reading a file the rule no longer calls the recipe, and a planner would write
637
+ # Auto rows against it — while a disabled block is only told, because nothing
638
+ # reads the file and refusing a project that never dogfoods would fail its own
639
+ # close-out selfcheck.
640
+ if [[ "$configured_repo" == "workspace" ]]; then
641
+ dg_legacy_split="the recipe is a project document now, and a workspace keeps one recipe per repo at docs/dogfood/<repo>.md, declared as a 'recipes:' map under dogfood: keyed by repos:. Dogfooding is stopped until it is split: create one file per repo ($dg_split_repos) under docs/dogfood/ and carry over only that repo's sections — you decide which sections belong to which repo; '$dg_recipe_legacy' stays where it is until you decide every section is distributed, and no command here copies or deletes it. Then write 'recipes:' in .sassywares/config.yaml — $dg_split_map"
642
+ # Two states, never one: with no map yet this is the migration stop, but with
643
+ # `recipes:` already written the split is under way and a leftover file is the
644
+ # same note the default path gets — a stop here could only be cleared by
645
+ # deleting a project-owned file the message tells the reader to keep, so a
646
+ # close-out would be impossible mid-migration.
647
+ if (( dg_map_declared )); then
648
+ note " dogfood.recipe is still '$dg_recipe_legacy' beside the 'recipes:' map — the split may not be finished. Keep it until every section is distributed, then delete it yourself: it is no longer the recipe, and nothing here reads or deletes it."
649
+ elif [[ "$dg_enabled" == "true" ]]; then
650
+ bad "dogfood.recipe is still '$dg_recipe_legacy' — $dg_legacy_split"
651
+ else
652
+ note " dogfood.recipe is at the old path '$dg_recipe_legacy' — $dg_legacy_split. dogfood.enabled is false, so nothing reads it; it is split before dogfood is turned on."
653
+ fi
654
+ # Like the combined-recipe stop above: the split already says what to write,
655
+ # so the per-repo missing-entry notes stay out of its way.
656
+ dg_split=1
657
+ else
658
+ dg_move="mkdir -p docs && git mv $dg_recipe_legacy $dg_recipe_default"
659
+ if [[ "$dg_enabled" == "true" ]]; then
660
+ bad "dogfood.recipe is still '$dg_recipe_legacy' — the recipe is a project document now, at '$dg_recipe_default'. Dogfooding is stopped until it moves: $dg_move, then set 'recipe: $dg_recipe_default' under dogfood: in .sassywares/config.yaml"
661
+ else
662
+ note " dogfood.recipe is at the old path '$dg_recipe_legacy' — the recipe lives at '$dg_recipe_default' now. dogfood.enabled is false, so nothing reads it; it moves before dogfood is turned on: $dg_move, then set 'recipe: $dg_recipe_default' under dogfood: in .sassywares/config.yaml"
663
+ fi
664
+ fi
665
+ # The old file is not the recipe any more, so nothing below lints it or claims
666
+ # the configured path is a missing recipe: there is exactly one thing to do.
667
+ dg_recipe=""
668
+ elif [[ "$configured_repo" != "workspace" && -z "$dg_recipe" ]] && { [[ "$dg_enabled" == "true" ]] || [[ -f "$ROOT/$dg_recipe_default" ]]; }; then
669
+ # The default path applies even when the key is absent: the scripts use it, so
670
+ # --check must lint what they will actually read. Only for a project that has
671
+ # dogfood on, or a recipe already sitting at the default, to avoid noise.
672
+ dg_recipe="$dg_recipe_default"
673
+ fi
674
+ dg_reports="$(block_value dogfood reports || true)"
675
+ dg_timeout="$(block_value dogfood timeout || true)"
676
+ dg_keep_raw="$(block_value dogfood keep || true)"
677
+ case "$dg_enabled" in
678
+ "") ;;
679
+ true|false) note " dogfood.enabled: $dg_enabled" ;;
680
+ *) bad "dogfood.enabled '$dg_enabled' must be true|false" ;;
681
+ esac
682
+ for dkey in recipe reports; do
683
+ case "$dkey" in
684
+ recipe) dpath="$dg_recipe" ;;
685
+ *) dpath="$dg_reports" ;;
686
+ esac
687
+ [[ -n "$dpath" ]] || continue
688
+ dg_tail="$(dg_path_tail "dogfood.$dkey" "$dpath")"
689
+ [[ -n "$dg_tail" ]] && bad "$dg_tail"
690
+ done
691
+ # One recipe per repo, in one map at the root: never a per-repo config, and
692
+ # never a second place the dogfood keys live. A value is a path inside the
693
+ # project (the same shape recipe and reports are held to) or `false`, which
694
+ # records a repo that is deliberately not dogfooded — turning a repo off by
695
+ # deleting its entry would erase the only record of what dogfooding it means.
696
+ # A key outside `repos:` is a hard error (it names no repo), while a repo
697
+ # absent from the map is only named: most repos in a workspace are never
698
+ # dogfooded, and that is a decision, not drift.
699
+ dg_recipes_root="$(yflat "dogfood${US}recipes" 2>/dev/null || true)"
700
+ dg_recipes_declared=0
701
+ dg_mapped=" "
702
+ # The repos a green run can prune: those whose entry is a procedure.
703
+ dg_live=" "
704
+ if [[ "$configured_repo" != "workspace" ]]; then
705
+ # The map is workspace-only. In a repo config it is a dead block, and a
706
+ # reader would trust it over the single `recipe:` that actually applies.
707
+ if [[ -n "$dg_recipes_root" ]] || yaml_flat "$CONFIG" | grep -q "^dogfood${US}recipes${US}"; then
708
+ bad "dogfood.recipes is workspace-only — git.repo is '${configured_repo:-unset}', so a repo declares one 'recipe:'"
709
+ fi
710
+ elif [[ -n "$dg_recipes_root" ]]; then
711
+ bad "dogfood.recipes '$dg_recipes_root' is one value — write a map keyed by repo: recipes: with '<repo>: docs/dogfood/<repo>.md' per repo, or '<repo>: false' for a repo that is deliberately not dogfooded"
712
+ else
713
+ while IFS=$'\t' read -r rpath rval; do
714
+ [[ -n "$rpath" ]] || continue
715
+ dg_recipes_declared=1
716
+ rkey="${rpath#dogfood${US}recipes${US}}"
717
+ # Mapped is recorded before the value is judged: a block or a malformed
718
+ # value still names the repo, so the one mistake is one finding and the
719
+ # missing-entry note does not tell the reader to add what they just wrote.
720
+ dg_mapped="$dg_mapped${rkey%%$US*} "
721
+ # Recorded before the value is fully judged, like `mapped`: a malformed path
722
+ # is drift on its own line, and silence here would hide an over-quota bucket
723
+ # behind a finding about the same entry.
724
+ case "$rval" in
725
+ false|true|yes|no|on|off|"") ;;
726
+ *) dg_live="$dg_live${rkey%%$US*} " ;;
727
+ esac
728
+ if [[ "$rkey" == *"$US"* ]]; then
729
+ bad "dogfood.recipes.${rkey//$US/.} is a nested block — each repo maps to one file: '${rkey%%$US*}: docs/dogfood/${rkey%%$US*}.md', or false"
730
+ continue
731
+ fi
732
+ case "$dg_repo_set" in
733
+ *" $rkey "*) ;;
734
+ *) bad "dogfood.recipes.$rkey is not a repo — repos: does not list '$rkey', and the map is keyed by the repo folder"; continue ;;
735
+ esac
736
+ # Shape first, and independently of `enabled`: an absolute path, a list,
737
+ # or an empty value is malformed whether dogfood runs or not. Only a
738
+ # missing file is a state a disabled block may leave for the first run.
739
+ case "$rval" in
740
+ false) note " dogfood.recipes.$rkey: false (deliberately not dogfooded)" ;;
741
+ true|yes|no|on|off) bad "dogfood.recipes.$rkey '$rval' must be a path or false, never on/off" ;;
742
+ "") bad "dogfood.recipes.$rkey '$rval' must be a path or false, never empty — a repo maps to docs/dogfood/$rkey.md, or false when it is deliberately not dogfooded" ;;
743
+ \[* ) bad "dogfood.recipes.$rkey '$rval' must be a path or false, never a list — a repo maps to one file: docs/dogfood/$rkey.md" ;;
744
+ /*|~*|.|./)
745
+ bad "$(dg_path_tail "dogfood.recipes.$rkey" "$rval")" ;;
746
+ *) if escapes_root "$rval"; then
747
+ bad "$(dg_path_tail "dogfood.recipes.$rkey" "$rval")"
748
+ elif [[ "$rval" != "docs/dogfood/$rkey.md" ]]; then
749
+ bad "dogfood.recipes.$rkey '$rval' is not this repo's recipe — a workspace keeps each repo's procedure at 'docs/dogfood/$rkey.md'; move it there and set '$rkey: docs/dogfood/$rkey.md'"
750
+ elif [[ ! -f "$ROOT/$rval" ]]; then
751
+ if [[ "$dg_enabled" == "true" ]]; then
752
+ bad "dogfood.recipes.$rkey '$rval' does not exist — run sassy-dogfood mode:discover"
753
+ else
754
+ note " dogfood.recipes.$rkey: $rval (written by the first sassy-dogfood run)"
755
+ fi
756
+ else
757
+ dg_recipe_file "$rval" "dogfood.recipes.$rkey"
758
+ fi ;;
759
+ esac
760
+ done < <(yaml_flat "$CONFIG" \
761
+ | awk -F'\t' -v us="$US" '{n=split($1,a,us); if (n>=3 && a[1]=="dogfood" && a[2]=="recipes") print $1 "\t" $2}')
762
+
763
+ # A repo with no recipe needs none — most are never dogfooded — so an
764
+ # omission is a note, never drift. `false` is the entry that says the
765
+ # decision was made, which is why a repo that carries one is not named.
766
+ if (( dg_recipes_declared )) || [[ "$dg_split" -eq 0 && "$dg_enabled" == "true" ]]; then
767
+ for rname in $dg_repo_set; do
768
+ case "$dg_mapped" in *" $rname "*) continue ;; esac
769
+ note " dogfood.recipes has no entry for '$rname' — it is not dogfooded; add '$rname: docs/dogfood/$rname.md' under recipes:, or '$rname: false' if that is deliberate"
770
+ done
771
+ fi
772
+ fi
773
+
774
+ # A half-migrated workspace: the map exists but the combined file the split
775
+ # replaces is still on disk, so the split may not have finished. One note and
776
+ # the reader decides — the check never deletes a project-owned document.
777
+ if [[ "$configured_repo" == "workspace" ]] && (( dg_recipes_declared )) && [[ -f "$ROOT/$dg_recipe_default" ]]; then
778
+ note " docs/dogfood.md still exists beside the 'recipes:' map — the split may not be finished; keep it until every section is distributed, then delete it yourself"
779
+ fi
780
+
781
+ if [[ -n "$dg_timeout" ]]; then
782
+ case "$dg_timeout" in
783
+ *[!0-9]*) bad "dogfood.timeout '$dg_timeout' is not a positive integer" ;;
784
+ 0) bad "dogfood.timeout is 0 — a procedure that can never finish" ;;
785
+ *) note " dogfood.timeout: ${dg_timeout}s" ;;
786
+ esac
787
+ fi
788
+ # Retention is a cap on run history, so zero is not a value: a run would prune
789
+ # every report it just wrote, including the one on disk. One predicate, shared
790
+ # with the sync's leaf_ok, because `*[!0-9]*` would accept `010` and `(( ))`
791
+ # would then read it as octal.
792
+ dg_keep="${dg_keep_raw:-10}"
793
+ dg_keep_ok=1
794
+ if [[ "$dg_keep" =~ ^[1-9][0-9]*$ ]]; then
795
+ [[ -z "$dg_keep_raw" ]] || note " dogfood.keep: $dg_keep runs"
796
+ else
797
+ bad "dogfood.keep '$dg_keep' is not an integer >= 1"
798
+ dg_keep_ok=0
799
+ fi
800
+
801
+ # Run history is not config drift: an over-quota reports directory is a note and
802
+ # the check still exits 0. Failing it would let a week of runs block a close-out,
803
+ # and the next green run is what prunes — this check only listens and reports.
804
+ if (( dg_keep_ok )); then
805
+ while IFS=$'\t' read -r dg_bucket dg_count; do
806
+ [[ -n "$dg_count" ]] || continue
807
+ (( dg_count > dg_keep )) || continue
808
+ # A bucket under a repo this workspace does not dogfood is frozen history:
809
+ # no run will ever prune it, so counting it would be one permanent note on
810
+ # every check. The prune there is the user's, by hand.
811
+ #
812
+ # `.` is the flat-root sentinel, so it and an empty bucket name the root
813
+ # reports path, not a repo below it — and in a workspace that legacy flat
814
+ # bucket is a half-migrated layout to move into `reports/<repo>/`, not a
815
+ # bucket any run maintains, so it stays loud instead of being skipped with
816
+ # a repo that is not dogfooded.
817
+ dg_suffix=""
818
+ [[ -z "$dg_bucket" || "$dg_bucket" == "." ]] || dg_suffix="/$dg_bucket"
819
+ if [[ "$configured_repo" == "workspace" && -n "$dg_suffix" ]]; then
820
+ case "$dg_live" in *" $dg_bucket "*) ;; *) continue ;; esac
821
+ fi
822
+ note " dogfood.reports${dg_suffix} holds $dg_count runs — more than dogfood.keep ($dg_keep); a completed green run prunes the oldest, or prune by hand"
823
+ done < <(dogfood_run_counts "$ROOT/${dg_reports:-.sassywares/dogfood/reports}")
824
+ fi
825
+
826
+ # Reports are logs and screenshots. A project that drops the ignore line
827
+ # commits them, and nobody notices until the history is heavy. Probed with a
828
+ # child path: `/reports/` names a directory, so git only matches it when the
829
+ # probe goes through the directory — and the directory may not exist yet.
830
+ if [[ "$TOPOLOGY" == "repo" && -n "$dg_reports" ]]; then
831
+ if git -C "$ROOT" check-ignore -q -- "$dg_reports/run.log" 2>/dev/null; then
832
+ note " dogfood.reports is gitignored"
833
+ else
834
+ bad "dogfood.reports '$dg_reports' is not gitignored — a run's logs and screenshots would be committed"
835
+ fi
836
+ fi
837
+
838
+ # A committed session is a credential leak, not merely a heavy history. Only
839
+ # checked once the folder exists, so a project that never uses one is silent.
840
+ if [[ "$TOPOLOGY" == "repo" && -d "$ROOT/.sassywares/session" ]]; then
841
+ if git -C "$ROOT" check-ignore -q -- ".sassywares/session/probe" 2>/dev/null; then
842
+ note " .sassywares/session is gitignored"
843
+ else
844
+ bad ".sassywares/session is not gitignored — a session artifact must never be committed"
845
+ fi
846
+ fi
847
+
848
+ if [[ -n "$dg_recipe" ]]; then
849
+ if [[ ! -f "$ROOT/$dg_recipe" ]]; then
850
+ if [[ "$dg_enabled" == "true" ]]; then
851
+ # Enabled with no procedure is the one state that lies: a planner would
852
+ # write Auto rows against a check that does not exist.
853
+ bad "dogfood.recipe '$dg_recipe' does not exist — run sassy-dogfood mode:discover"
854
+ else
855
+ note " dogfood.recipe: $dg_recipe (written by the first sassy-dogfood run)"
856
+ fi
857
+ else
858
+ dg_recipe_file "$dg_recipe" dogfood.recipe
859
+ fi
860
+ fi
861
+
862
+ # Hooks that cannot fire are a note, not drift: the config is legal, the step
863
+ # just never runs. hooks.push needs `current` in a single remote repo.
864
+ if [[ "$val" == "current" ]]; then
865
+ if hooks_declared pr; then
866
+ note " hooks.pr entries are declared but commit.branch is current — no PR, so they never run"
867
+ fi
868
+ if hooks_declared push && [[ "$configured_repo" == "workspace" || "$configured_repo" == "none" ]]; then
869
+ note " hooks.push entries are declared but git.repo is '$configured_repo' — they never run"
870
+ fi
871
+ elif hooks_declared push; then
872
+ note " hooks.push entries are declared but commit.branch is not current — they never run"
873
+ fi
874
+
875
+ # The pin. A config can match the tree perfectly while the vendored suite is
876
+ # stale, edited, or half-installed, and every skill downstream then runs
877
+ # something other than what the lock says. Offline, no network.
878
+ [[ -n "$SUITE_ROSTER" ]] || note " suite roster not found — falling back to the sassy-* name prefix"
879
+ check_with_node "$SKILL_DIR/scripts/lockcheck.mjs" \
880
+ "node not found — the vendored pin is unverified (the skills CLI needs node)" \
881
+ --root "$ROOT" --roster "$SUITE_ROSTER"
882
+
883
+ if [[ "$TOPOLOGY" == "repo" ]]; then
884
+ # Tracked, not merely present: a clone has to get the pin without a network
885
+ # call, so an untracked lock is a setup that does not travel.
886
+ # Only a project-scope install has a lock; a user-scope one has nothing here.
887
+ if [[ -n "$(git -C "$ROOT" ls-files -- skills-lock.json 2>/dev/null)" ]]; then
888
+ note " skills-lock.json is tracked"
889
+ elif [[ -f "$ROOT/skills-lock.json" ]]; then
890
+ note " skills-lock.json is not tracked yet — the setup commit carries it"
891
+ fi
892
+ if [[ -e "$ROOT/.claude/skills" ]] && ! git -C "$ROOT" check-ignore -q -- .claude/skills 2>/dev/null; then
893
+ note " .claude/skills is not gitignored — install-time links may get committed"
894
+ fi
895
+ fi
896
+
897
+ # A config can match the tree and still be behind the template: whole blocks,
898
+ # comment layers, and examples a later version added are missing, so the next
899
+ # reader gets a thinner file than the one sassy-setup documents. It is a note,
900
+ # never drift — every value the file declares is valid — and the sync only adds
901
+ # what is missing, so this is the one passing check worth reading.
902
+ template=""
903
+ if template="$(merged_config)"; then
904
+ if [[ "$template" != "$(cat "$CONFIG")" ]]; then
905
+ note " template: --sync --write would $(sync_phrase "$template") (values the check accepts stay) — run: bash $SELF --root $ROOT --sync --write"
906
+ fi
907
+ fi
908
+
909
+ # The routing block: AGENTS.md is what an agent reads before any skill is
910
+ # invoked. A missing or stale block is a note, never drift — the config is
911
+ # complete without it, and --sync --write is the updater.
912
+ shipped_agents="$(agents_md_shipped_version)"
913
+ case "$(agents_md_plan)" in
914
+ create)
915
+ note " agents-md: AGENTS.md is missing — --sync --write would create it with routing block v${shipped_agents}" ;;
916
+ append)
917
+ note " agents-md: AGENTS.md has no routing block — --sync --write would append v${shipped_agents}" ;;
918
+ replace)
919
+ agents_v="$(agents_md_version "$ROOT/AGENTS.md")"
920
+ if [[ "$agents_v" == "$shipped_agents" ]]; then
921
+ note " agents-md: routing block v${agents_v} differs from this skill's copy — --sync --write replaces it in place"
922
+ else
923
+ note " agents-md: routing block is v${agents_v}, this skill ships v${shipped_agents} — --sync --write replaces it in place"
924
+ fi ;;
925
+ current)
926
+ note " agents-md: routing block v${shipped_agents}" ;;
927
+ newer)
928
+ note " agents-md: routing block is v$(agents_md_version "$ROOT/AGENTS.md"), newer than this skill ships (v${shipped_agents}) — left alone" ;;
929
+ unterminated)
930
+ note " agents-md: AGENTS.md has an opening sassywares:skills marker with no matching closing marker — fix it by hand" ;;
931
+ mismatch)
932
+ note " agents-md: AGENTS.md routing block markers disagree on the version — fix it by hand" ;;
933
+ *)
934
+ note " agents-md: routing-block asset not found — AGENTS.md unchecked" ;;
935
+ esac
936
+
937
+ if (( drift )); then exit 1; fi
938
+ note " config matches the tree"
939
+ exit 0
940
+ }