@jeiemgi/cckit 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +15 -4
  3. package/README.md +11 -3
  4. package/bin/cckit +86 -7
  5. package/cckit.config.json +1 -1
  6. package/kit.config.schema.json +43 -2
  7. package/package.json +1 -1
  8. package/scripts/autopilot-test.sh +68 -0
  9. package/scripts/autopilot.sh +16 -10
  10. package/scripts/check.sh +14 -1
  11. package/scripts/copilot-loop-test.sh +3 -0
  12. package/scripts/guard-raw-git-ops-test.sh +65 -0
  13. package/scripts/init.sh +68 -8
  14. package/scripts/lib/agent-profile-test.sh +151 -0
  15. package/scripts/lib/agent-profile.sh +195 -0
  16. package/scripts/lib/agent-resolve-test.sh +156 -0
  17. package/scripts/lib/agent-resolve.sh +177 -0
  18. package/scripts/lib/branch-owner-test.sh +99 -0
  19. package/scripts/lib/branch-owner.sh +194 -0
  20. package/scripts/lib/captain-test.sh +86 -0
  21. package/scripts/lib/captain.sh +142 -7
  22. package/scripts/lib/contribute-root-test.sh +40 -0
  23. package/scripts/lib/contribute-root.sh +22 -0
  24. package/scripts/lib/effort-ops-test.sh +42 -2
  25. package/scripts/lib/effort-ops.sh +157 -14
  26. package/scripts/lib/effort-parity-test.sh +5 -3
  27. package/scripts/lib/effort.sh +38 -14
  28. package/scripts/lib/hook-refresh-test.sh +65 -0
  29. package/scripts/lib/hook-refresh.sh +62 -0
  30. package/scripts/lib/kit-config.sh +6 -0
  31. package/scripts/lib/kit-gc-test.sh +178 -1
  32. package/scripts/lib/kit-gc.sh +233 -55
  33. package/scripts/lib/kit-task-ops-test.sh +15 -0
  34. package/scripts/lib/kit-task-ops.sh +65 -21
  35. package/scripts/lib/kto-task-pr-merge-test.sh +72 -0
  36. package/scripts/lib/kto-task-pr-test.sh +59 -0
  37. package/scripts/lib/orchestration-runtime-test.sh +142 -0
  38. package/scripts/lib/orchestration-runtime.sh +171 -0
  39. package/scripts/lib/review-stage-test.sh +241 -0
  40. package/scripts/lib/review-stage.sh +259 -0
  41. package/scripts/lib/stage-receipt-test.sh +252 -0
  42. package/scripts/lib/stage-receipt.sh +442 -0
  43. package/scripts/lib/test-env-test.sh +25 -0
  44. package/scripts/lib/test-env.sh +30 -0
  45. package/scripts/lib/worker-brief-test.sh +120 -0
  46. package/scripts/lib/worker-brief.sh +185 -0
  47. package/scripts/lib/worktree-ports-test.sh +146 -0
  48. package/scripts/lib/worktree-start.sh +137 -7
  49. package/scripts/lib/zsh-safety-test.sh +67 -0
  50. package/scripts/orchestrate.sh +124 -22
  51. package/scripts/portable-test.sh +22 -1
  52. package/scripts/review-lint-baseline.txt +28 -0
  53. package/scripts/review-lint-test.sh +271 -0
  54. package/scripts/review-lint.sh +259 -0
  55. package/scripts/review-rules.conf +55 -0
  56. package/scripts/setup-labels.sh +21 -1
  57. package/scripts/skill-frontmatter-baseline.txt +24 -0
  58. package/scripts/skill-frontmatter-lint-test.sh +156 -0
  59. package/scripts/skill-frontmatter-lint.sh +182 -0
  60. package/scripts/task-sync.sh +8 -0
  61. package/scripts/test.sh +10 -1
  62. package/skills/kit-autopilot/SKILL.md +13 -1
  63. package/skills/kit-cleanup/SKILL.md +5 -3
  64. package/skills/kit-contribute/SKILL.md +6 -5
  65. package/skills/kit-effort-close/SKILL.md +8 -3
  66. package/skills/kit-effort-pr/SKILL.md +16 -95
  67. package/skills/kit-gc/SKILL.md +15 -10
  68. package/skills/kit-security-sweep/SKILL.md +4 -6
  69. package/skills/kit-ship/SKILL.md +1 -1
  70. package/skills/kit-task-pr/SKILL.md +2 -0
  71. package/templates/hooks/guard-raw-git-ops.sh.tmpl +180 -0
  72. package/templates/rules/branch-naming.md +6 -0
  73. package/templates/rules/effort-model.md +3 -0
  74. package/templates/rules/naming-and-ids.md +4 -1
  75. package/templates/settings/settings.json.tmpl +4 -2
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env bash
2
+ # review-lint.sh — codified review findings as a deterministic gate (kit-owned).
3
+ #
4
+ # WHY: an AI reviewer (CodeRabbit) finds the same classes of defect over and over, but its findings
5
+ # live in PR threads and die there. Anything MECHANICAL in that stream — a pattern that is wrong
6
+ # every time it appears, regardless of intent — belongs in a gate that runs in under a second and
7
+ # never forgets. This file is that gate; `review-rules.conf` is the rule table, one block per rule,
8
+ # each carrying the PR it was earned from.
9
+ #
10
+ # WHAT IT IS NOT: a replacement for review. Only the mechanical slice maps here. Findings that need
11
+ # intent — doc-vs-code drift, architectural contracts, "is this the right abstraction" — stay with
12
+ # the reviewer. Do not force those into regexes; a noisy gate is worse than no gate.
13
+ #
14
+ # scripts/review-lint.sh lint against the baseline (the gate)
15
+ # scripts/review-lint.sh --report every rule's current hit count; never fails
16
+ # scripts/review-lint.sh --rule <ID> show every hit for one rule, with context
17
+ # scripts/review-lint.sh --update re-baseline from current hits
18
+ #
19
+ # Baseline: scripts/review-lint-baseline.txt ("<RULE> <path> <count>"). Grandfathers today's hits
20
+ # per file so adding a rule never forces a repo-wide fix; only NEW or GROWN hits fail.
21
+ # bash 3.2 compatible (no associative arrays, no mapfile).
22
+ set -uo pipefail
23
+
24
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
25
+ cd "$ROOT"
26
+
27
+ RULES="scripts/review-rules.conf"
28
+ BASELINE="scripts/review-lint-baseline.txt"
29
+
30
+ FAIL=0
31
+ err() { echo "x $1"; FAIL=1; }
32
+ ok() { echo "ok $1"; }
33
+ note() { echo " $1"; }
34
+
35
+ [ -f "$RULES" ] || { echo "review-lint: no $RULES — nothing to enforce"; exit 0; }
36
+
37
+ # ---- rule table access ------------------------------------------------------
38
+ rule_ids() { awk '/^\[.+\]$/ { gsub(/^\[|\]$/, ""); print }' "$RULES"; }
39
+
40
+ # rule_field <id> <key> — value of one key inside one [id] block ("" if unset).
41
+ rule_field() {
42
+ awk -v id="$1" -v key="$2" '
43
+ /^\[.+\]$/ { cur = $0; gsub(/^\[|\]$/, "", cur); inblk = (cur == id); next }
44
+ !inblk { next }
45
+ index($0, key ":") == 1 { sub("^" key ":[ \t]*", ""); print; exit }
46
+ ' "$RULES"
47
+ }
48
+
49
+ # ---- file selection ---------------------------------------------------------
50
+ # Scope/exclude are comma-separated shell patterns matched with `case`, where `*` DOES cross `/`
51
+ # (case patterns are not pathname expansion). So `scripts/*` matches `scripts/lib/foo.sh`.
52
+ # Tracked files when there are any; otherwise a filesystem walk. The fallback matters for a
53
+ # freshly scaffolded project, where the kit has written files but nothing is staged yet -
54
+ # `git ls-files` is empty there, and without this the gate would silently scan nothing.
55
+ #
56
+ # KIT_LINT_WALK=1 forces the walk. Seeding a baseline needs it: init.sh scaffolds into a repo that
57
+ # usually ALREADY has commits, so `git ls-files` is non-empty and the just-written kit files are
58
+ # invisible to it. `--update` then grandfathers nothing, and the gate turns red the moment the user
59
+ # commits the scaffold - failing on templates the kit itself shipped. "Seed once so a fresh project
60
+ # starts green" only holds if the seed can see the whole tree, tracked or not.
61
+ list_files() {
62
+ local tracked
63
+ if [ "${KIT_LINT_WALK:-0}" != "1" ]; then
64
+ tracked="$(git ls-files 2>/dev/null)"
65
+ if [ -n "$tracked" ]; then printf '%s\n' "$tracked"; return 0; fi
66
+ fi
67
+ find . -type f \
68
+ -not -path './.git/*' -not -path '*/node_modules/*' \
69
+ -not -path './dist/*' -not -path './.cckit/*' 2>/dev/null | sed 's|^\./||'
70
+ }
71
+
72
+ files_for_rule() {
73
+ local scope exclude f keep pat
74
+ scope="$(rule_field "$1" scope)"
75
+ exclude="$(rule_field "$1" exclude)"
76
+ [ -n "$scope" ] || scope='*'
77
+ list_files | while IFS= read -r f; do
78
+ # Never lint the rule table or the baseline: both quote the very patterns they describe,
79
+ # so scanning them makes every rule match itself.
80
+ case "$f" in "$RULES"|"$BASELINE") continue ;; esac
81
+ keep=0
82
+ IFS=',' read -r -a _scopes <<< "$(printf '%s' "$scope" | tr -d ' ')"
83
+ for pat in "${_scopes[@]}"; do
84
+ [ -n "$pat" ] || continue
85
+ case "$f" in $pat) keep=1; break ;; esac
86
+ done
87
+ [ "$keep" -eq 1 ] || continue
88
+ if [ -n "$exclude" ]; then
89
+ IFS=',' read -r -a _excl <<< "$(printf '%s' "$exclude" | tr -d ' ')"
90
+ for pat in "${_excl[@]}"; do
91
+ [ -n "$pat" ] || continue
92
+ case "$f" in $pat) keep=0; break ;; esac
93
+ done
94
+ fi
95
+ [ "$keep" -eq 1 ] && printf '%s\n' "$f"
96
+ done
97
+ }
98
+
99
+ # ---- matching ---------------------------------------------------------------
100
+ # Emits "path:line:text" for every hit of one rule.
101
+ #
102
+ # code_only drops FULL-LINE comments only (first non-blank char is `#`). It deliberately does not
103
+ # strip trailing comments: in shell `#` is ambiguous (`${v#p}`, `$#`, `'#'`), so stripping it would
104
+ # corrupt real code lines. Use `ignore:` for the rest.
105
+ hits_for_rule() {
106
+ local id="$1" kind pattern prog ignore code_only flist
107
+ kind="$(rule_field "$id" kind)"
108
+ ignore="$(rule_field "$id" ignore)"
109
+ code_only="$(rule_field "$id" code_only)"
110
+
111
+ flist="$(files_for_rule "$id")"
112
+ [ -n "$flist" ] || return 0
113
+
114
+ # Two rule kinds. `regex` (the default) is a per-line grep — enough for most findings. `awk` is
115
+ # for rules that need STATE across lines, such as fence parity: a bare ``` is only a defect when
116
+ # it OPENS a block, and no per-line pattern can know that. An awk rule supplies a one-line program
117
+ # that prints FILENAME":"FNR":"$0 for each hit and resets its state on FNR==1.
118
+ if [ "$kind" = "awk" ]; then
119
+ prog="$(rule_field "$id" awk)"
120
+ [ -n "$prog" ] || return 0
121
+ printf '%s\n' "$flist" \
122
+ | tr '\n' '\0' \
123
+ | xargs -0 awk "$prog" 2>/dev/null
124
+ else
125
+ pattern="$(rule_field "$id" pattern)"
126
+ [ -n "$pattern" ] || return 0
127
+ printf '%s\n' "$flist" \
128
+ | tr '\n' '\0' \
129
+ | xargs -0 grep -nE -- "$pattern" /dev/null 2>/dev/null
130
+ fi \
131
+ | awk -v co="${code_only:-false}" -v ig="${ignore:-}" '
132
+ {
133
+ body = $0
134
+ sub(/^[^:]*:[0-9]+:/, "", body)
135
+ if (co == "true") { t = body; sub(/^[ \t]+/, "", t); if (substr(t, 1, 1) == "#") next }
136
+ if (ig != "" && body ~ ig) next
137
+ print
138
+ }
139
+ '
140
+ }
141
+
142
+ # count_by_file — read "path:line:text" hits on stdin, emit "<path><TAB><count>", path-sorted.
143
+ #
144
+ # The obvious `uniq -c | awk '{ print $2, $1 }'` keeps only the FIRST whitespace token of the path,
145
+ # so `docs/my file.md` is recorded as `docs/my`. Two offending files sharing that prefix then
146
+ # collapse onto one row and are both compared against a single baseline entry - the second file's
147
+ # hits pass unnoticed. Counting in awk, keyed on the whole path, and separating with a TAB (which
148
+ # cannot occur in the paths git reports) keeps the field boundary unambiguous for every reader.
149
+ count_by_file() {
150
+ awk -F: '{ c[$1]++ } END { for (p in c) printf "%s\t%s\n", p, c[p] }' | LC_ALL=C sort
151
+ }
152
+
153
+ # baseline_count <rule> <path> — the recorded count, 0 when absent.
154
+ #
155
+ # Reads BOTH layouts. Rows are written TAB-separated so a path with a space survives, but a project
156
+ # upgrading from an earlier kit still has a space-separated baseline on disk; refusing to read it
157
+ # would report every grandfathered file as a new hit and turn the gate red on upgrade.
158
+ baseline_count() {
159
+ [ -f "$BASELINE" ] || { echo 0; return; }
160
+ grep -v '^[[:space:]]*#' "$BASELINE" 2>/dev/null \
161
+ | awk -v r="$1" -v p="$2" '
162
+ { n = index($0, "\t") ? split($0, F, "\t") : split($0, F, " ") }
163
+ n >= 3 && F[1] == r && F[2] == p { print F[3]; found = 1; exit }
164
+ END { if (!found) print 0 }
165
+ '
166
+ }
167
+
168
+ MODE="${1:-lint}"
169
+ ARG="${2:-}"
170
+
171
+ # The one place the baseline filename is spelled, so init.sh's "seed once" guard cannot go looking
172
+ # for a name that does not exist.
173
+ if [ "$MODE" = "--baseline-path" ]; then
174
+ printf '%s\n' "$BASELINE"
175
+ exit 0
176
+ fi
177
+
178
+ # ---- --rule <ID> ------------------------------------------------------------
179
+ if [ "$MODE" = "--rule" ]; then
180
+ [ -n "$ARG" ] || { echo "usage: review-lint.sh --rule <ID>"; exit 2; }
181
+ rule_ids | grep -qx "$ARG" || { echo "x unknown rule '$ARG'"; exit 2; }
182
+ echo "[$ARG] $(rule_field "$ARG" title)"
183
+ echo " why: $(rule_field "$ARG" why)"
184
+ echo " source: $(rule_field "$ARG" source)"
185
+ echo
186
+ hits_for_rule "$ARG" | sed 's/^/ /'
187
+ echo
188
+ echo " $(hits_for_rule "$ARG" | grep -c . | tr -d ' ') hit(s)"
189
+ exit 0
190
+ fi
191
+
192
+ # ---- --report ---------------------------------------------------------------
193
+ if [ "$MODE" = "--report" ]; then
194
+ printf '%-26s %5s %s\n' RULE HITS TITLE
195
+ rule_ids | while IFS= read -r id; do
196
+ [ -n "$id" ] || continue
197
+ printf '%-26s %5s %s\n' "$id" "$(hits_for_rule "$id" | grep -c . | tr -d ' ')" "$(rule_field "$id" title)"
198
+ done
199
+ exit 0
200
+ fi
201
+
202
+ # ---- --update ---------------------------------------------------------------
203
+ if [ "$MODE" = "--update" ]; then
204
+ {
205
+ echo "# review-lint-baseline.txt — generated by scripts/review-lint.sh --update"
206
+ echo "# Pre-existing hits, GRANDFATHERED per file: they may stay, but may never grow, and a"
207
+ echo "# file not listed here must have zero hits. Fix a file and re-run --update to tighten."
208
+ echo "#"
209
+ echo "# <RULE>\t<path>\t<count> (TAB-separated: a path may contain a space)"
210
+ rule_ids | while IFS= read -r id; do
211
+ [ -n "$id" ] || continue
212
+ hits_for_rule "$id" | count_by_file \
213
+ | awk -v r="$id" -F"\t" '{ printf "%s\t%s\t%s\n", r, $1, $2 }'
214
+ done
215
+ } > "$BASELINE"
216
+ echo "ok wrote $BASELINE ($(grep -cv '^[[:space:]]*#' "$BASELINE" | tr -d ' ') grandfathered file(s))"
217
+ exit 0
218
+ fi
219
+
220
+ # ---- lint (the gate) --------------------------------------------------------
221
+ total=0
222
+ grandfathered=0
223
+ while IFS= read -r id; do
224
+ [ -n "$id" ] || continue
225
+ title="$(rule_field "$id" title)"
226
+ why="$(rule_field "$id" why)"
227
+ src="$(rule_field "$id" source)"
228
+
229
+ # Per-file counts for this rule, "<path><TAB><count>".
230
+ counts="$(hits_for_rule "$id" | count_by_file)"
231
+ [ -n "$counts" ] || continue
232
+
233
+ while IFS="$(printf '\t')" read -r path n; do
234
+ [ -n "$path" ] || continue
235
+ [ "$n" -ge 0 ] 2>/dev/null || continue
236
+ total=$(( total + n ))
237
+ base="$(baseline_count "$id" "$path")"
238
+ if [ "$n" -gt "$base" ]; then
239
+ if [ "$base" -eq 0 ]; then
240
+ err "[$id] $path: $n hit(s) — $title"
241
+ else
242
+ err "[$id] $path: grew to $n hit(s) (baseline $base) — $title"
243
+ fi
244
+ note "why: $why"
245
+ note "source: $src"
246
+ hits_for_rule "$id" | awk -F: -v p="$path" '$1 == p' | head -3 | sed 's/^/ /'
247
+ note "see all: scripts/review-lint.sh --rule $id"
248
+ else
249
+ grandfathered=$(( grandfathered + n ))
250
+ fi
251
+ done <<EOF
252
+ $counts
253
+ EOF
254
+ done < <(rule_ids)
255
+
256
+ if [ "$FAIL" -eq 0 ]; then
257
+ ok "review rules clean ($(rule_ids | grep -c . | tr -d ' ') rule(s), $grandfathered grandfathered hit(s))"
258
+ fi
259
+ exit "$FAIL"
@@ -0,0 +1,55 @@
1
+ # review-rules.conf — mechanical review findings, codified. Enforced by scripts/review-lint.sh.
2
+ #
3
+ # Each block is one rule mined from a real review thread. `source` is the provenance: the PR where
4
+ # a human or the AI reviewer caught this, so a rule can always be traced back to the defect that
5
+ # earned it. Adding a rule is a one-block append + `scripts/review-lint.sh --update`.
6
+ #
7
+ # Fields:
8
+ # kind `regex` (default) or `awk` for rules needing state across lines
9
+ # title one line, imperative — printed on failure
10
+ # why what actually breaks (not "best practice")
11
+ # scope comma-separated `case` patterns; `*` crosses `/` (so `scripts/*` is recursive)
12
+ # exclude same syntax, applied after scope
13
+ # pattern ERE passed to `grep -E` (kind: regex)
14
+ # awk one-line awk program printing FILENAME":"FNR":"$0 per hit (kind: awk)
15
+ # ignore optional ERE; a matching line is not a hit (use for output strings, fixtures)
16
+ # code_only true = skip full-line comments (trailing comments are NOT stripped; see review-lint.sh)
17
+ # source provenance
18
+ #
19
+ # ONLY mechanical rules belong here — patterns that are wrong every time they appear. Findings that
20
+ # need intent (doc-vs-code drift, architectural contracts) stay with the reviewer; forcing those
21
+ # into a regex produces noise, and a noisy gate trains people to ignore it.
22
+
23
+ [grep-c-zero-fallback]
24
+ title: do not use `grep -c ... || echo 0` as a zero-count fallback
25
+ why: `grep -c` PRINTS 0 and exits 1 on no match, so the fallback appends a second 0 and the command substitution yields "0\n0" — arithmetic and comparisons then break
26
+ scope: scripts/*, bin/*
27
+ code_only: true
28
+ pattern: grep -c[^|]*\|\|[[:space:]]*echo[[:space:]]+0
29
+ source: coderabbit PR#230 (scripts/lib/kit-brief.sh, "Fix both zero-count fallbacks")
30
+
31
+ [refs-word-splitting]
32
+ title: iterate refs and paths with `while IFS= read -r`, not `for x in $(...)`
33
+ why: unquoted command substitution word-splits on the ambient IFS, so refs or worktree paths containing spaces are silently dropped or split — a polluted IFS (including a NUL) breaks it further
34
+ scope: scripts/*, bin/*
35
+ code_only: true
36
+ pattern: for[[:space:]]+[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]+in[[:space:]]+\$\((git|gh)[[:space:]]
37
+ source: coderabbit PR#240 (scripts/lib/kit-status.sh, "Worktree paths that contain a space are dropped")
38
+
39
+ [local-masks-exit-status]
40
+ title: split `local x=$(cmd)` into `local x; x=$(cmd)` when the exit status matters
41
+ why: `local` is itself a command, so its exit status masks the command substitution's — `set -e` and `|| return` never fire (shellcheck SC2155)
42
+ scope: scripts/*, bin/*
43
+ code_only: true
44
+ pattern: ^[[:space:]]*local[[:space:]]+[a-zA-Z_][a-zA-Z0-9_]*=\$\(
45
+ source: coderabbit PR#240 / SC2155
46
+
47
+ [fence-missing-language]
48
+ title: give every fenced code block a language identifier
49
+ why: a bare ``` fence renders unhighlighted and breaks docs-site syntax highlighting and copy buttons (markdownlint MD040)
50
+ kind: awk
51
+ scope: *.md, *.mdx
52
+ exclude: docs-site/node_modules/*, CHANGELOG.md, .github/*
53
+ awk: FNR==1{inb=0;fence=""} match($0,/^[ \t]*(`{3,}|~{3,})/){m=substr($0,RSTART,RLENGTH);sub(/^[ \t]+/,"",m);rest=substr($0,RSTART+RLENGTH);sub(/^[ \t]+/,"",rest);sub(/[ \t]+$/,"",rest);if(!inb){inb=1;fence=m;if(rest=="")print FILENAME":"FNR":"$0}else if(substr(m,1,1)==substr(fence,1,1)&&length(m)>=length(fence)&&rest==""){inb=0;fence=""}}
54
+ note: tracks the OPENING fence's char and length. A parity counter (n%2) breaks on a 4-backtick outer fence - the normal way to show a fenced block inside a fenced block: it counts the ```` line but never reports it, leaving n odd so every later CLOSING fence is reported as a bare opener. ~~~ fences were invisible to it entirely.
55
+ source: coderabbit PR#276 (templates/rules/naming-and-ids.md, "Add language identifiers to the fenced code blocks")
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Create the ctx:/flow:/kind:/priority:/role: label families on the repo. Idempotent.
2
+ # Create the agent:/ctx:/flow:/kind:/priority:/role: label families on the repo. Idempotent.
3
3
  # Reads repo + roles from .claude/kit.config.json; the flow vocabulary from effort.sh (EFFORT_FLOWS).
4
4
  # These are exactly the labels `cckit effort new` / /kit-effort-new apply — provision them here so a
5
5
  # fresh repo can create a fully-labeled effort with no manual label creation. Run from project root.
@@ -14,6 +14,10 @@ ensure_label() { # name color description
14
14
  }
15
15
 
16
16
  echo "→ Labels on $KIT_REPO"
17
+ # The one label that marks a parent AS an effort, and the one `effort_plan` queries. It was read
18
+ # and never provisioned, so `cckit effort plan` found nothing on every repo.
19
+ echo "effort:"
20
+ ensure_label "effort" "5319e7" "An effort parent issue"
17
21
  echo "kinds:"
18
22
  for k in task plan adr scaffold spike; do ensure_label "kind:$k" "5319e7" "Kind: $k"; done
19
23
  echo "priorities:"
@@ -34,4 +38,20 @@ while IFS= read -r role; do
34
38
  slug=$(echo "$role" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
35
39
  ensure_label "role:$slug" "1d76db" "Role: $role"
36
40
  done <<< "$KIT_ROLES"
41
+
42
+ # agent:<profile> — which agent profile a piece of work runs under (#319). Driven by the profiles
43
+ # the project actually declares, so the family stays bounded by the config rather than growing one
44
+ # label per issue. A project with no `agents.profiles` gets no agent: labels, which is correct:
45
+ # nothing reads them until a profile exists to name.
46
+ echo "agents:"
47
+ _al_cfg=""
48
+ if command -v kit_config_path >/dev/null 2>&1; then _al_cfg="$(kit_config_path 2>/dev/null || true)"; fi
49
+ if [ -n "$_al_cfg" ] && [ -f "$_al_cfg" ] && command -v jq >/dev/null 2>&1; then
50
+ while IFS= read -r p; do
51
+ [ -z "$p" ] && continue
52
+ ensure_label "agent:$p" "5319e7" "Agent profile: $p"
53
+ done <<< "$(jq -r '(.agents.profiles // {}) | keys[]' "$_al_cfg" 2>/dev/null)"
54
+ else
55
+ echo " • no agents.profiles declared — skipping"
56
+ fi
37
57
  echo "✓ done"
@@ -0,0 +1,24 @@
1
+ # skill-frontmatter-baseline.txt — generated by scripts/skill-frontmatter-lint.sh --update
2
+ # Skills whose description+when_to_use exceed the 500-byte listing budget.
3
+ # These are GRANDFATHERED: allowed to stay, but may never grow. Shrink them and re-run
4
+ # --update to tighten the ratchet. A skill that drops under budget leaves this file.
5
+ #
6
+ # <skill> <bytes>
7
+ kit-ux-audit 2181
8
+ kit-status 2004
9
+ kit-docs-writer 780
10
+ kit-onboard 728
11
+ kit-effort-start 717
12
+ kit-autopilot 686
13
+ concrete 679
14
+ kit-plan-next 674
15
+ kit-effort-close 592
16
+ kit-effort-new 578
17
+ kit-security-sweep 560
18
+ kit-cleanup 560
19
+ kit-dev 544
20
+ kit-contribute 538
21
+ kit-next 535
22
+ kit-annotate 534
23
+ kit-effort-pr 534
24
+ kit-ship 520
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env bash
2
+ # skill-frontmatter-lint-test.sh — behavioral test for the skill frontmatter context-budget ratchet.
3
+ # Builds a throwaway skills/ tree in a temp ROOT and asserts the four transitions that matter:
4
+ # under budget passes, a new over-budget skill fails, a baselined skill may sit still but not grow,
5
+ # and a shrunk skill is reported as re-baselineable.
6
+ set -uo pipefail
7
+
8
+ LINT="$(cd "$(dirname "$0")" && pwd)/skill-frontmatter-lint.sh"
9
+ fails=0
10
+ pass() { echo "ok $1"; }
11
+ fail() { echo "FAIL $1"; fails=1; }
12
+
13
+ TMP="$(mktemp -d)"
14
+ trap 'rm -rf "$TMP"' EXIT
15
+ mkdir -p "$TMP/scripts" "$TMP/skills"
16
+ cp "$LINT" "$TMP/scripts/"
17
+
18
+ # Write skills/<name>/SKILL.md with a description of $2 chars and when_to_use of $3 chars.
19
+ mk_skill() {
20
+ local name="$1" dlen="$2" wlen="$3"
21
+ mkdir -p "$TMP/skills/$name"
22
+ {
23
+ echo "---"
24
+ echo "name: $name"
25
+ printf 'description: %s\n' "$(head -c "$dlen" < /dev/zero | tr '\0' 'd')"
26
+ [ "$wlen" -gt 0 ] && printf 'when_to_use: %s\n' "$(head -c "$wlen" < /dev/zero | tr '\0' 'w')"
27
+ echo "---"
28
+ echo
29
+ echo "body"
30
+ } > "$TMP/skills/$name/SKILL.md"
31
+ }
32
+
33
+ # Capture rather than pipe: `run | grep -q` would let grep exit early, kill `run` with SIGPIPE,
34
+ # and — under `set -o pipefail` — report the whole pipeline as failed even on a successful match.
35
+ run() { ( cd "$TMP" && bash scripts/skill-frontmatter-lint.sh "$@" 2>&1 ); }
36
+ run_out=""; run_rc=0
37
+ capture() { run_out="$(run "$@")"; run_rc=$?; }
38
+
39
+ # --- 1. a lean skill passes with no baseline at all -------------------------
40
+ mk_skill lean 100 80
41
+ run >/dev/null 2>&1 && pass "lean skill passes with no baseline" \
42
+ || fail "lean skill passes with no baseline"
43
+
44
+ # --- 2. measurement is correct across a block scalar ------------------------
45
+ # description 100 + when_to_use 80 = 180 total.
46
+ got="$(run --report | awk '$1=="lean" {print $4}')"
47
+ [ "$got" = "180" ] && pass "measures description+when_to_use (got $got)" \
48
+ || fail "measures description+when_to_use (expected 180, got $got)"
49
+
50
+ # --- 3. a NEW over-budget skill fails ---------------------------------------
51
+ mk_skill bloated 700 200
52
+ capture
53
+ if [ "$run_rc" -eq 0 ]; then
54
+ fail "new over-budget skill is rejected (exited 0)"
55
+ elif printf '%s' "$run_out" | grep -q "over the .*listing budget"; then
56
+ pass "new over-budget skill is rejected"
57
+ else
58
+ fail "new over-budget skill is rejected (wrong message: $run_out)"
59
+ fi
60
+
61
+ # --- 4. once baselined, the same skill is grandfathered ---------------------
62
+ run --update >/dev/null 2>&1
63
+ run >/dev/null 2>&1 && pass "baselined skill is grandfathered" \
64
+ || fail "baselined skill is grandfathered"
65
+
66
+ # --- 5. but it may not GROW -------------------------------------------------
67
+ mk_skill bloated 900 200
68
+ capture
69
+ if [ "$run_rc" -eq 0 ]; then
70
+ fail "growth past baseline is rejected (exited 0)"
71
+ elif printf '%s' "$run_out" | grep -q "always-resident context may not grow"; then
72
+ pass "growth past baseline is rejected"
73
+ else
74
+ fail "growth past baseline is rejected (wrong message: $run_out)"
75
+ fi
76
+
77
+ # --- 6. shrinking under budget passes and nudges a re-baseline -------------
78
+ mk_skill bloated 200 100
79
+ capture
80
+ if [ "$run_rc" -ne 0 ]; then
81
+ fail "shrunk skill passes and nudges --update (exited $run_rc)"
82
+ elif printf '%s' "$run_out" | grep -q "now under budget"; then
83
+ pass "shrunk skill passes and nudges --update"
84
+ else
85
+ fail "shrunk skill passes but no re-baseline nudge"
86
+ fi
87
+
88
+ # --- 7. the measurement does not move with the locale -----------------------
89
+ # `${#s}` counts CHARACTERS under a UTF-8 locale and BYTES under C/POSIX. With multibyte text in a
90
+ # description, a baseline generated under one locale fires the ratchet under the other — on skills
91
+ # nobody touched. The lint pins LC_ALL, so both runs must agree exactly.
92
+ rm -rf "$TMP/skills"; mkdir -p "$TMP/skills"; rm -f "$TMP/scripts/skill-frontmatter-baseline.txt"
93
+ mkdir -p "$TMP/skills/multibyte"
94
+ {
95
+ echo "---"
96
+ echo "name: multibyte"
97
+ printf 'description: %s — %s · %s\n' "$(head -c 200 < /dev/zero | tr '\0' 'd')" \
98
+ "$(head -c 200 < /dev/zero | tr '\0' 'e')" \
99
+ "$(head -c 200 < /dev/zero | tr '\0' 'f')"
100
+ echo "---"
101
+ echo
102
+ echo "body"
103
+ } > "$TMP/skills/multibyte/SKILL.md"
104
+ c_out="$( cd "$TMP" && LC_ALL=C bash scripts/skill-frontmatter-lint.sh --report 2>&1 )"
105
+ u_out="$( cd "$TMP" && LC_ALL=en_US.UTF-8 bash scripts/skill-frontmatter-lint.sh --report 2>&1 )"
106
+ [ "$c_out" = "$u_out" ] && pass "the count is identical under LC_ALL=C and UTF-8" \
107
+ || fail "the count moves with the locale:
108
+ C: $c_out
109
+ UTF8: $u_out"
110
+
111
+ # A baseline written under one locale must still pass the gate under the other.
112
+ ( cd "$TMP" && LC_ALL=en_US.UTF-8 bash scripts/skill-frontmatter-lint.sh --update ) >/dev/null 2>&1
113
+ lc_out="$( cd "$TMP" && LC_ALL=C bash scripts/skill-frontmatter-lint.sh 2>&1 )"; lc_rc=$?
114
+ [ "$lc_rc" -eq 0 ] && pass "a UTF-8 baseline passes under LC_ALL=C" \
115
+ || fail "a UTF-8 baseline passes under LC_ALL=C (rc=$lc_rc: $lc_out)"
116
+ rm -f "$TMP/scripts/skill-frontmatter-baseline.txt"
117
+
118
+ # --- 8. .claude/skills/ is linted too — the layout init.sh actually scaffolds
119
+ # Hard-coding `skills` made the shipped lint a permanent no-op in every consumer project.
120
+ rm -rf "$TMP/skills"
121
+ mkdir -p "$TMP/.claude/skills/scaffolded"
122
+ {
123
+ echo "---"
124
+ echo "name: scaffolded"
125
+ printf 'description: %s\n' "$(head -c 700 < /dev/zero | tr '\0' 'd')"
126
+ echo "---"
127
+ } > "$TMP/.claude/skills/scaffolded/SKILL.md"
128
+ capture
129
+ if [ "$run_rc" -ne 0 ] && printf '%s' "$run_out" | grep -q 'scaffolded'; then
130
+ pass ".claude/skills/ is linted"
131
+ else
132
+ fail ".claude/skills/ is linted (rc=$run_rc: $run_out)"
133
+ fi
134
+ rm -rf "$TMP/.claude"
135
+
136
+ # --- 9. --baseline-path is the one place the filename is spelled ------------
137
+ # init.sh used to reconstruct it as "<lint>-baseline.txt", which for THIS lint names a file that
138
+ # never exists — so its "seed once" guard never matched and every upgrade re-baselined silently.
139
+ bp_out="$( cd "$TMP" && bash scripts/skill-frontmatter-lint.sh --baseline-path 2>&1 )"
140
+ [ "$bp_out" = "scripts/skill-frontmatter-baseline.txt" ] \
141
+ && pass "--baseline-path reports the baseline" \
142
+ || fail "--baseline-path reports the baseline (got '$bp_out')"
143
+ # It answers even with no skills tree at all — init.sh asks before anything is scaffolded.
144
+ [ -d "$TMP/skills" ] && fail "fixture leaked a skills/ dir into the no-tree check"
145
+ bp2="$( cd "$TMP" && bash scripts/skill-frontmatter-lint.sh --baseline-path 2>&1 )"
146
+ [ "$bp2" = "scripts/skill-frontmatter-baseline.txt" ] \
147
+ && pass "--baseline-path answers with no skills tree" \
148
+ || fail "--baseline-path answers with no skills tree (got '$bp2')"
149
+
150
+ # --- 10. a repo with no skills tree is a no-op, not a failure ---------------
151
+ rm -rf "$TMP/skills"
152
+ run >/dev/null 2>&1 && pass "missing skills tree is a no-op" \
153
+ || fail "missing skills tree is a no-op"
154
+
155
+ [ "$fails" -eq 0 ] && echo "ok skill-frontmatter-lint-test passed" || echo "FAIL skill-frontmatter-lint-test"
156
+ exit "$fails"