@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
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env bash
2
- # orchestrate.sh - run N issue flows as live tmux panes, each an agent in its own worktree.
2
+ # orchestrate.sh - run N issue flows as live terminal panes, each an agent in its own worktree.
3
3
  #
4
4
  # For each issue: create an isolated worktree + branch off the configured base branch
5
- # (cckit.config.json: github.repo + github.baseBranch), then open a tmux session with one tiled
6
- # pane per flow running the agent command. Branches must be file-disjoint - the flows edit in
7
- # parallel, so disjointness is the caller's responsibility.
5
+ # (cckit.config.json: github.repo + github.baseBranch), then open a tmux session or Herdr workspace
6
+ # with one pane per flow running the agent command. Branches must be file-disjoint - the flows edit
7
+ # in parallel, so disjointness is the caller's responsibility.
8
8
  #
9
9
  # Agent-agnostic: the per-pane command defaults to `claude` but is overridable, so cckit drives any
10
10
  # CLI agent that takes a prompt as its first argument.
11
- # --agent <cmd> / CCKIT_AGENT=<cmd>
11
+ # --agent <cmd> / CCKIT_AGENT=<cmd> the CLI directly (profile-free path)
12
+ # --profile <name> / CCKIT_PROFILE=<name> a declared agent profile: its kind + its argv
13
+ # --runtime <tmux|herdr> / CCKIT_RUNTIME=<runtime>
12
14
  #
13
15
  # Hardening:
14
16
  # --dry-run resolve + print the launch plan; create no worktrees, start no panes
@@ -21,6 +23,7 @@
21
23
  # cckit orchestrate <issueA> <issueB> [<issueC> ...]
22
24
  # cckit orchestrate --dry-run 6 7 8
23
25
  # cckit orchestrate --cap 3 --agent codex 2 3 6 9
26
+ # cckit orchestrate --runtime herdr --agent codex 2 3 6 9
24
27
  # cckit orchestrate --no-seed 6 7 # don't auto-prompt each agent
25
28
  # cckit orchestrate --force 7 # launch even if blocked_by an open issue
26
29
  # cckit orchestrate --session=sweep 1 2 # custom tmux session name
@@ -34,6 +37,10 @@ FORCE=0
34
37
  DETACH=0
35
38
  CAP=4
36
39
  AGENT="${CCKIT_AGENT:-claude}"
40
+ RUNTIME="${CCKIT_RUNTIME:-tmux}"
41
+ PROFILE="${CCKIT_PROFILE:-}"
42
+ AGENT_ARGS_NL=""
43
+ AGENT_EXPLICIT=0
37
44
  ISSUES=()
38
45
 
39
46
  usage() { sed -n '2,28p' "$0" | sed 's/^# \{0,1\}//'; }
@@ -46,8 +53,12 @@ while [ "$#" -gt 0 ]; do
46
53
  --detach) DETACH=1; shift ;;
47
54
  --cap) CAP="$2"; shift 2 ;;
48
55
  --cap=*) CAP="${1#*=}"; shift ;;
49
- --agent) AGENT="$2"; shift 2 ;;
50
- --agent=*) AGENT="${1#*=}"; shift ;;
56
+ --agent) AGENT="$2"; AGENT_EXPLICIT=1; shift 2 ;;
57
+ --agent=*) AGENT="${1#*=}"; AGENT_EXPLICIT=1; shift ;;
58
+ --profile) PROFILE="$2"; shift 2 ;;
59
+ --profile=*) PROFILE="${1#*=}"; shift ;;
60
+ --runtime) RUNTIME="$2"; shift 2 ;;
61
+ --runtime=*) RUNTIME="${1#*=}"; shift ;;
51
62
  --session=*) SESSION="${1#*=}"; shift ;;
52
63
  -h|--help) usage; exit 0 ;;
53
64
  [0-9]*) ISSUES+=("$1"); shift ;;
@@ -56,11 +67,54 @@ while [ "$#" -gt 0 ]; do
56
67
  done
57
68
 
58
69
  [ "${#ISSUES[@]}" -ge 1 ] || { echo "orchestrate: pass at least one issue number" >&2; usage; exit 2; }
59
- case "$CAP" in ''|*[!0-9]*) echo "orchestrate: --cap needs a number (got '$CAP')" >&2; exit 2 ;; esac
70
+ case "$CAP" in ''|*[!0-9]*) echo "orchestrate: --cap needs a positive number (got '$CAP')" >&2; exit 2 ;; esac
71
+ [ "$CAP" -gt 0 ] || { echo "orchestrate: --cap must be greater than zero" >&2; exit 2; }
60
72
 
61
73
  # Resolve the main worktree root + load config (repo + base branch drive everything).
62
74
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
63
75
  ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # cckit INSTALL root — for sourcing libs (works on brew/npm installs)
76
+ # shellcheck source=/dev/null
77
+ source "$ROOT/scripts/lib/orchestration-runtime.sh"
78
+
79
+ # Agent profiles (#320). A profile supplies the agent KIND and its extra argv; cckit never names a
80
+ # model, so whatever model flag the project wants lives in the profile's `args`. Resolution runs
81
+ # BEFORE the preflight so an unknown or stage-barred profile is refused with everything else — no
82
+ # worktree, no pane. `--agent` remains the direct, profile-free path and wins when given.
83
+ if [ "$AGENT_EXPLICIT" -eq 0 ]; then
84
+ # shellcheck source=/dev/null
85
+ source "$ROOT/scripts/lib/config-path.sh" 2>/dev/null || true
86
+ # shellcheck source=/dev/null
87
+ source "$ROOT/scripts/lib/agent-resolve.sh" 2>/dev/null || true
88
+ _oc_cfg=""
89
+ command -v kit_config_path >/dev/null 2>&1 && _oc_cfg="$(kit_config_path 2>/dev/null || true)"
90
+ if [ -n "$_oc_cfg" ] && [ -f "$_oc_cfg" ] && command -v ap_resolve >/dev/null 2>&1; then
91
+ # No issue labels here: this is the run-wide profile. Per-issue `agent:` labels select a
92
+ # profile per entry, which the launch loop cannot express yet (it takes one kind for the run).
93
+ # rc 2 is a REFUSAL (unknown profile, barred stage) and must stop before any worktree. rc 4 is
94
+ # "this project declares no profiles", which is the normal state of every project that has not
95
+ # opted in — it falls through to --agent's default rather than breaking plain orchestration.
96
+ _oc_rc=0
97
+ _oc_prof="$(ap_resolve "$_oc_cfg" build "$PROFILE" '' '')" || _oc_rc=$?
98
+ case "$_oc_rc" in
99
+ 0) : ;;
100
+ 4) if [ -n "$PROFILE" ]; then
101
+ echo "orchestrate: --profile '$PROFILE' given but no agent profiles are declared" >&2; exit 2
102
+ fi
103
+ _oc_prof="" ;;
104
+ *) exit "$_oc_rc" ;;
105
+ esac
106
+ if [ -n "$_oc_prof" ]; then
107
+ AGENT="$(ap_profile_field "$_oc_cfg" "$_oc_prof" kind)"
108
+ AGENT_ARGS_NL="$(ap_profile_args "$_oc_cfg" "$_oc_prof")"
109
+ echo "orchestrate: profile '$_oc_prof' (tier $(ap_profile_tier "$_oc_cfg" "$_oc_prof"), kind $AGENT)"
110
+ fi
111
+ elif [ -n "$PROFILE" ]; then
112
+ echo "orchestrate: --profile '$PROFILE' given but no kit config declares agents.profiles" >&2
113
+ exit 2
114
+ fi
115
+ fi
116
+
117
+ or_runtime_preflight "$RUNTIME" "$AGENT" "$DRYRUN"
64
118
  # The git-repo guard validates the INVOKING project ($PWD), not cckit's install dir; wt_start and
65
119
  # load_kit_config below resolve the project + its config from the invoking directory.
66
120
  git -C "$PWD" rev-parse --show-toplevel >/dev/null 2>&1 || { echo "orchestrate: not in a git repo" >&2; exit 1; }
@@ -71,16 +125,19 @@ REPO="$KIT_REPO"
71
125
  # blocked_by gate: echo the OPEN blocker numbers of an issue (native GitHub dependency edge).
72
126
  open_blockers() {
73
127
  local n="$1" b st blk
74
- blk="$(gh api "repos/$REPO/issues/$n/dependencies/blocked_by" --jq '.[].number' 2>/dev/null || true)"
128
+ blk="$(gh api "repos/$REPO/issues/$n/dependencies/blocked_by" --jq '.[].number')" || {
129
+ echo "orchestrate: could not read blockers for #$n" >&2; return 1;
130
+ }
75
131
  for b in $blk; do
76
132
  st="$(gh issue view "$b" --repo "$REPO" --json state --jq .state 2>/dev/null || echo OPEN)"
77
133
  [ "$st" = "OPEN" ] && printf '%s ' "$b"
78
134
  done
135
+ return 0
79
136
  }
80
137
 
81
138
  # Partition the requested issues into eligible / blocked / (later) queued.
82
139
  ELIGIBLE=()
83
- echo "orchestrate: repo $REPO (base ${KIT_BASE_BRANCH:-main}), cap $CAP, agent '$AGENT'"
140
+ echo "orchestrate: repo $REPO (base ${KIT_BASE_BRANCH:-main}), cap $CAP, runtime '$RUNTIME', agent '$AGENT'"
84
141
  for num in "${ISSUES[@]}"; do
85
142
  blockers="$(open_blockers "$num")"
86
143
  if [ -n "$blockers" ] && [ "$FORCE" -eq 0 ]; then
@@ -108,21 +165,28 @@ if [ "$DRYRUN" -eq 1 ]; then
108
165
  exit 0
109
166
  fi
110
167
 
111
- command -v tmux >/dev/null || { echo "orchestrate: tmux not installed (brew install tmux)" >&2; exit 1; }
112
- command -v "$AGENT" >/dev/null || { echo "orchestrate: agent '$AGENT' not on PATH" >&2; exit 1; }
113
-
114
168
  # shellcheck source=/dev/null
115
169
  source "$ROOT/scripts/lib/worktree-start.sh"
116
170
 
117
171
  # Headless seed: the agent runs with NO human present - it must never ask, decide autonomously,
118
172
  # gauge difficulty + apply proportional effort, and close no-op issues itself. cckit verbs only.
173
+ #
174
+ # The framing and the receipt contract live in worker-brief.sh (#321), not here, because they are
175
+ # the two parts that must survive truncation and a budget is the resolved profile's to set.
176
+ # shellcheck source=/dev/null
177
+ source "$ROOT/scripts/lib/worker-brief.sh"
178
+ SEED_BUDGET=""
179
+ [ -n "${_oc_cfg:-}" ] && [ -n "${_oc_prof:-}" ] && SEED_BUDGET="$(wb_profile_budget "$_oc_cfg" "$_oc_prof")"
180
+
119
181
  seed_for() {
120
- local num="$1" branch="$2"
121
- printf '%s' "You are running HEADLESS inside a cckit orchestration: there is NO human to answer \
122
- questions, so NEVER ask - decide autonomously and proceed. Gauge the task difficulty and apply \
123
- proportional effort. Worktree + branch $branch for issue #$num are ready. Run: gh issue view $num, \
124
- implement it, run bash scripts/check.sh until green, then open the PR with: cckit pr $num \"<summary>\". \
125
- If it is a no-op (nothing to change), comment why and run: cckit close $num \"<reason>\". Do not wait for input."
182
+ local num="$1" branch="$2" wt="${3:-$PWD}" brief
183
+ brief="$(cd "$wt" && "$ROOT/bin/cckit" brief "$num" 2>/dev/null)" || brief=""
184
+ if [ -z "$brief" ]; then
185
+ # Nested single quotes would terminate the format string and make printf recycle it over the
186
+ # stray words as arguments, so the fallback names the command without quoting it.
187
+ brief="$(printf 'The generated cckit brief was unavailable. Read only issue #%s with: gh issue view %s\n' "$num" "$num")"
188
+ fi
189
+ printf '%s\n' "$brief" | wb_compose "$num" "$branch" "$SEED_BUDGET" || true
126
190
  }
127
191
 
128
192
  ENTRIES=()
@@ -131,6 +195,44 @@ for num in "${LAUNCH[@]}"; do
131
195
  ENTRIES+=("$entry")
132
196
  done
133
197
 
198
+ # ── one writer per branch (#323) ────────────────────────────────────────────────────────────────
199
+ # wt_start hands back the branch each flow will push. A second wave launched onto a branch a live
200
+ # worker is already writing is the corruption rules/branch-naming.md describes, and git does not
201
+ # catch it: git refuses one branch in two WORKTREES, which says nothing about two agent processes
202
+ # driving the branch cckit just handed them. Claim the lease before a single pane starts, and
203
+ # release every claim if any one of them is contested — a half-launched wave is worse than none.
204
+ # shellcheck source=/dev/null
205
+ source "$ROOT/scripts/lib/branch-owner.sh"
206
+ BO_OWNER="orchestrate:$SESSION:$$"
207
+ CLAIMED=()
208
+ _bo_release_all() {
209
+ local c
210
+ for c in ${CLAIMED+"${CLAIMED[@]}"}; do bo_release "$c" "$BO_OWNER" >/dev/null 2>&1 || true; done
211
+ }
212
+ for entry in "${ENTRIES[@]}"; do
213
+ rest="${entry#*|}"; branch="${rest%%|*}"; num="${rest##*|}"
214
+ # Empty pid: orchestrate exits while the panes keep writing, so the lease must not be tied to
215
+ # this process. The worktree is the liveness signal (branch-owner.sh explains the argument).
216
+ if ! bo_claim "$branch" "$BO_OWNER" "${entry%%|*}" ""; then
217
+ echo "orchestrate: #$num — another writer already owns $branch; not launching this wave" >&2
218
+ _bo_release_all
219
+ exit 1
220
+ fi
221
+ CLAIMED+=("$branch")
222
+ done
223
+ # The lease outlives this process on purpose: the pane keeps writing after orchestrate returns, and
224
+ # the ledger reclaims it on positive evidence (the worktree is gone, or the pid died on this host).
225
+
226
+ if [ "$RUNTIME" = "herdr" ]; then
227
+ or_herdr_launch "$SESSION" "$AGENT" "$SEED" "$DETACH" "${KIT_PROJECT_SLUG:-project}" "$AGENT_ARGS_NL" "${ENTRIES[@]}"
228
+ exit $?
229
+ fi
230
+
231
+ # The profile's argv on the tmux path. Herdr got it as an argv array above; tmux types a command
232
+ # LINE into the pane's shell, so the quoting lives in or_tmux_agent_cmd beside the Herdr launcher —
233
+ # both runtimes answer the same question and neither may drop the args the resolution line promised.
234
+ AGENT_CMD="$(or_tmux_agent_cmd "$AGENT" "$AGENT_ARGS_NL")"
235
+
134
236
  tmux kill-session -t "$SESSION" 2>/dev/null || true
135
237
  first=1
136
238
  for entry in "${ENTRIES[@]}"; do
@@ -149,11 +251,11 @@ for entry in "${ENTRIES[@]}"; do
149
251
  # parsed by the pane's shell. Double-quoting collided with the seed's own quotes and
150
252
  # dumped `<summary>` onto zsh as a redirection ("no such file or directory: summary"),
151
253
  # so the agent never launched. Escape any single quotes for safe single-quote wrapping.
152
- seed="$(seed_for "$num" "$branch")"
254
+ seed="$(seed_for "$num" "$branch" "$wt")"
153
255
  esc=${seed//\'/\'\\\'\'}
154
- tmux send-keys -t "$pane" "$AGENT '$esc'" C-m
256
+ tmux send-keys -t "$pane" "$AGENT_CMD '$esc'" C-m
155
257
  else
156
- tmux send-keys -t "$pane" "$AGENT" C-m
258
+ tmux send-keys -t "$pane" "$AGENT_CMD" C-m
157
259
  fi
158
260
  done
159
261
  tmux select-layout -t "$SESSION:flows" tiled >/dev/null
@@ -8,6 +8,9 @@
8
8
  # Hermetic: stubs `gh` (no network/auth). Run: bash scripts/portable-test.sh
9
9
  set -u
10
10
  ROOT="$(cd "$(dirname "$0")/.." && pwd)"
11
+ # Sealed from the caller's KIT_*/CCKIT_*/EFFORT_* (#369): this suite builds its own fixture.
12
+ # shellcheck source=/dev/null
13
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
11
14
  CCKIT="$ROOT/bin/cckit"
12
15
  fail=0
13
16
  t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
@@ -91,11 +94,29 @@ yes "gc resolves the invoking repo" "$(cat "$GH_REPO_LOG")" "$FIX_REPO"
91
94
  no "brief never resolves cckit's own repo from a foreign checkout" "$(cat "$GH_REPO_LOG")" "$OWN_REPO"
92
95
  yes "brief resolves the invoking repo" "$(cat "$GH_REPO_LOG")" "$FIX_REPO"
93
96
 
97
+ # `receipt` makes no gh call, so the --repo log cannot judge it — but it WRITES, and writing into
98
+ # cckit's own .cckit/ from someone else's checkout is the same leak in a different resource. The
99
+ # state dir is derived from --git-common-dir, so a foreign repo must get its own.
100
+ if command -v jq >/dev/null 2>&1; then
101
+ ( cd "$fix" && PATH="$stub:$PATH" "$CCKIT" receipt 1 --stage build >/dev/null 2>&1 <<'EOF'
102
+ outcome: pr-open
103
+ url: https://example/1
104
+ gate: pass
105
+ blocker: none
106
+ next stage: review
107
+ EOF
108
+ )
109
+ yes "receipt writes into the INVOKING repo's state dir" \
110
+ "$([ -f "$fix/.cckit/receipts/1-build-1.json" ] && echo yes || echo no)" "yes"
111
+ no "receipt leaves nothing in cckit's own state dir" \
112
+ "$(ls "$ROOT/.cckit/receipts" 2>/dev/null | grep -c '^1-build-1\.json$' || true)" "1"
113
+ fi
114
+
94
115
  # ── BY CONSTRUCTION: every verb in `cckit commands` is classified (exercised or explicitly skipped) ─
95
116
  # A new verb that is neither exercised nor listed here fails the harness — forcing a coverage
96
117
  # decision. SKIP holds verbs that mutate, need args, read stdin, are interactive, or act on the
97
118
  # install itself (not the invoking project's board) — deliberately not driven here.
98
- SKIP="adopt autopilot bench brief close commands completions contribute copilot debug digest effort encode-context handoff help init install migrate msg orchestrate pr release render resume start ui update version watch"
119
+ SKIP="adopt autopilot bench brief close commands completions contribute copilot debug digest effort encode-context handoff help init install merge migrate msg new orchestrate pr receipt release render resume start ui update version watch"
99
120
  classified() { case " $EXERCISE $SKIP " in *" $1 "*) return 0 ;; *) return 1 ;; esac; }
100
121
  for v in $("$CCKIT" commands); do
101
122
  classified "$v" || { echo "FAIL: verb '$v' is unclassified — add it to EXERCISE (read-only, assert no own-repo leak) or SKIP in portable-test.sh"; fail=1; }
@@ -0,0 +1,28 @@
1
+ # review-lint-baseline.txt — generated by scripts/review-lint.sh --update
2
+ # Pre-existing hits, GRANDFATHERED per file: they may stay, but may never grow, and a
3
+ # file not listed here must have zero hits. Fix a file and re-run --update to tighten.
4
+ #
5
+ # <RULE>\t<path>\t<count> (TAB-separated: a path may contain a space)
6
+ refs-word-splitting scripts/lib/effort-ops-test.sh 1
7
+ fence-missing-language .claude/rules/branch-naming.md 1
8
+ fence-missing-language .claude/rules/effort-model.md 1
9
+ fence-missing-language .claude/skills/karpathy-guidelines/SKILL.md 1
10
+ fence-missing-language CONTRIBUTING.md 1
11
+ fence-missing-language README.md 1
12
+ fence-missing-language skills/kit-autopilot/SKILL.md 2
13
+ fence-missing-language skills/kit-dev/SKILL.md 1
14
+ fence-missing-language skills/kit-next/SKILL.md 3
15
+ fence-missing-language skills/kit-plan-next/SKILL.md 2
16
+ fence-missing-language skills/kit-task-sync/SKILL.md 1
17
+ fence-missing-language skills/kit-ux-audit/references/graph-model.md 2
18
+ fence-missing-language skills/kit-ux-audit/references/heuristics.md 1
19
+ fence-missing-language templates/agents/security.md 1
20
+ fence-missing-language templates/agents/ux.md 1
21
+ fence-missing-language templates/rules/branch-naming.md 1
22
+ fence-missing-language templates/rules/effort-model.md 1
23
+ fence-missing-language templates/rules/plan-next.md 1
24
+ fence-missing-language templates/rules/plan-output-format.md 1
25
+ fence-missing-language templates/skills/copywriting/references/copy-frameworks.md 5
26
+ fence-missing-language templates/skills/feature-build-refine/SKILL.md 2
27
+ fence-missing-language templates/skills/karpathy-guidelines/SKILL.md 1
28
+ fence-missing-language templates/skills/speckit/SKILL.md 2
@@ -0,0 +1,271 @@
1
+ #!/usr/bin/env bash
2
+ # review-lint-test.sh — behavioral test for the codified-review-findings gate.
3
+ # Builds a throwaway repo with its own rule table and asserts the engine contract: scope/exclude
4
+ # selection, code_only and ignore filtering, both rule kinds (regex + stateful awk), and the
5
+ # per-file ratchet (new hit fails, baselined hit passes, growth fails).
6
+ set -uo pipefail
7
+
8
+ ENGINE="$(cd "$(dirname "$0")" && pwd)/review-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/lib" "$TMP/docs"
16
+ cp "$ENGINE" "$TMP/scripts/"
17
+
18
+ ( cd "$TMP" && git init -q . && git config user.email t@t && git config user.name t ) >/dev/null 2>&1
19
+
20
+ # Capture rather than pipe: `run | grep -q` lets grep exit early, kills `run` with SIGPIPE, and
21
+ # under `set -o pipefail` reports the pipeline as failed even on a successful match.
22
+ run() { ( cd "$TMP" && bash scripts/review-lint.sh "$@" 2>&1 ); }
23
+ run_out=""; run_rc=0
24
+ capture() { run_out="$(run "$@")"; run_rc=$?; }
25
+ track() { ( cd "$TMP" && git add -A . >/dev/null 2>&1 ); }
26
+
27
+ cat > "$TMP/scripts/review-rules.conf" <<'CONF'
28
+ [T001]
29
+ title: no bare TODO markers
30
+ why: test rule
31
+ scope: lib/*
32
+ exclude: *-test.sh
33
+ code_only: true
34
+ ignore: ALLOWED
35
+ pattern: TODO
36
+ source: test
37
+
38
+ [T002]
39
+ title: fenced block needs a language
40
+ why: test rule
41
+ kind: awk
42
+ scope: docs/*
43
+ 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=""}}
44
+ source: test
45
+ CONF
46
+
47
+ # --- 1. clean tree passes ----------------------------------------------------
48
+ echo 'echo hi' > "$TMP/lib/clean.sh"; track
49
+ capture
50
+ [ "$run_rc" -eq 0 ] && pass "clean tree passes" || fail "clean tree passes (rc=$run_rc: $run_out)"
51
+
52
+ # --- 2. scope: a hit OUTSIDE the rule's scope is ignored ---------------------
53
+ echo 'x=1 # TODO' > "$TMP/scripts/out-of-scope.sh"; track
54
+ capture
55
+ [ "$run_rc" -eq 0 ] && pass "out-of-scope file ignored" || fail "out-of-scope file ignored"
56
+
57
+ # --- 3. a real in-scope hit fails -------------------------------------------
58
+ echo 'x=1 TODO' > "$TMP/lib/bad.sh"; track
59
+ capture
60
+ if [ "$run_rc" -ne 0 ] && printf '%s' "$run_out" | grep -q 'T001.*lib/bad.sh'; then
61
+ pass "in-scope hit fails"
62
+ else
63
+ fail "in-scope hit fails (rc=$run_rc: $run_out)"
64
+ fi
65
+
66
+ # --- 4. exclude: same content in an excluded file is ignored ----------------
67
+ rm "$TMP/lib/bad.sh"; echo 'x=1 TODO' > "$TMP/lib/thing-test.sh"; track
68
+ capture
69
+ [ "$run_rc" -eq 0 ] && pass "exclude pattern honored" || fail "exclude pattern honored ($run_out)"
70
+
71
+ # --- 5. code_only: a FULL-LINE comment is not a hit -------------------------
72
+ rm "$TMP/lib/thing-test.sh"; printf ' # TODO later\n' > "$TMP/lib/c.sh"; track
73
+ capture
74
+ [ "$run_rc" -eq 0 ] && pass "code_only skips full-line comments" || fail "code_only skips full-line comments ($run_out)"
75
+
76
+ # --- 6. ignore: a line matching the ignore ERE is not a hit -----------------
77
+ printf 'x=1 TODO ALLOWED\n' > "$TMP/lib/c.sh"; track
78
+ capture
79
+ [ "$run_rc" -eq 0 ] && pass "ignore pattern honored" || fail "ignore pattern honored ($run_out)"
80
+
81
+ # --- 7. awk kind: OPENING bare fence is a hit, closing fence is not ---------
82
+ rm "$TMP/lib/c.sh"
83
+ printf 'intro\n```\ncode\n```\n' > "$TMP/docs/a.md"; track
84
+ n="$(run --rule T002 | grep -c 'docs/a.md:' || true)"
85
+ [ "$n" -eq 1 ] && pass "awk rule counts opening fence only (got $n)" \
86
+ || fail "awk rule counts opening fence only (expected 1, got $n)"
87
+
88
+ # --- 8. awk kind: a LABELLED fence is clean --------------------------------
89
+ printf 'intro\n```bash\ncode\n```\n' > "$TMP/docs/a.md"; track
90
+ capture
91
+ [ "$run_rc" -eq 0 ] && pass "labelled fence is clean" || fail "labelled fence is clean ($run_out)"
92
+
93
+ # --- 9. awk state resets per file (no parity bleed across files) ------------
94
+ printf 'a\n```sh\nx\n```\n' > "$TMP/docs/a.md"
95
+ printf 'b\n```sh\ny\n```\n' > "$TMP/docs/b.md"; track
96
+ capture
97
+ [ "$run_rc" -eq 0 ] && pass "awk state resets per file" || fail "awk state resets per file ($run_out)"
98
+
99
+ # --- 10. baseline grandfathers an existing hit ------------------------------
100
+ printf 'a\n```\nx\n```\n' > "$TMP/docs/a.md"; track
101
+ run --update >/dev/null 2>&1
102
+ capture
103
+ [ "$run_rc" -eq 0 ] && pass "baselined hit is grandfathered" || fail "baselined hit is grandfathered ($run_out)"
104
+
105
+ # --- 11. ...but growth in that same file fails ------------------------------
106
+ printf 'a\n```\nx\n```\n\n```\ny\n```\n' > "$TMP/docs/a.md"; track
107
+ capture
108
+ if [ "$run_rc" -ne 0 ] && printf '%s' "$run_out" | grep -q 'grew to'; then
109
+ pass "growth past baseline fails"
110
+ else
111
+ fail "growth past baseline fails (rc=$run_rc: $run_out)"
112
+ fi
113
+
114
+ # --- 12. a NEW file with a hit fails even while another is baselined --------
115
+ printf 'a\n```\nx\n```\n' > "$TMP/docs/a.md"
116
+ printf 'c\n```\nz\n```\n' > "$TMP/docs/c.md"; track
117
+ capture
118
+ if [ "$run_rc" -ne 0 ] && printf '%s' "$run_out" | grep -q 'docs/c.md'; then
119
+ pass "new offending file fails despite baseline"
120
+ else
121
+ fail "new offending file fails despite baseline (rc=$run_rc: $run_out)"
122
+ fi
123
+
124
+ # --- 13. untracked files are invisible (git ls-files is the source) --------
125
+ rm "$TMP/docs/c.md"; track
126
+ printf 'u\n```\nz\n```\n' > "$TMP/docs/untracked.md" # deliberately NOT added
127
+ capture
128
+ [ "$run_rc" -eq 0 ] && pass "untracked files are not scanned" || fail "untracked files are not scanned ($run_out)"
129
+
130
+ # --- 14. the rule table never matches itself -------------------------------
131
+ # review-rules.conf quotes the patterns it describes, so scanning it makes every rule self-match.
132
+ # Own temp repo: this must assert on WHICH paths are reported, not on the exit code.
133
+ TMP3="$(mktemp -d)"; mkdir -p "$TMP3/scripts" "$TMP3/lib"
134
+ cp "$ENGINE" "$TMP3/scripts/"
135
+ ( cd "$TMP3" && git init -q . ) >/dev/null 2>&1
136
+ cat > "$TMP3/scripts/review-rules.conf" <<'CONF'
137
+ [selfmatch]
138
+ title: no SENTINEL_TOKEN
139
+ why: the word SENTINEL_TOKEN appears in this very table
140
+ scope: scripts/*, lib/*
141
+ pattern: SENTINEL_TOKEN
142
+ source: test
143
+ CONF
144
+ echo 'x=SENTINEL_TOKEN' > "$TMP3/lib/real.sh"
145
+ out3="$( cd "$TMP3" && bash scripts/review-lint.sh 2>&1 )"
146
+ if printf '%s' "$out3" | grep -q 'review-rules.conf'; then
147
+ fail "rule table is not linted against itself (self-matched: $out3)"
148
+ elif printf '%s' "$out3" | grep -q 'lib/real.sh'; then
149
+ pass "rule table is skipped while real files still match"
150
+ else
151
+ fail "rule table is not linted against itself (real hit missed: $out3)"
152
+ fi
153
+ rm -rf "$TMP3"
154
+
155
+ # --- 15. untracked-but-present files are scanned when NOTHING is tracked ---
156
+ # A freshly scaffolded project has files on disk and an empty index; the gate must still see them.
157
+ TMP2="$(mktemp -d)"; mkdir -p "$TMP2/scripts" "$TMP2/docs"
158
+ cp "$ENGINE" "$TMP2/scripts/"; cp "$TMP/scripts/review-rules.conf" "$TMP2/scripts/"
159
+ ( cd "$TMP2" && git init -q . ) >/dev/null 2>&1
160
+ printf 'a\n```\nx\n```\n' > "$TMP2/docs/a.md" # never `git add`ed
161
+ out2="$( cd "$TMP2" && bash scripts/review-lint.sh 2>&1 )"; rc2=$?
162
+ if [ "$rc2" -ne 0 ] && printf '%s' "$out2" | grep -q 'docs/a.md'; then
163
+ pass "scans on-disk files when the index is empty"
164
+ else
165
+ fail "scans on-disk files when the index is empty (rc=$rc2: $out2)"
166
+ fi
167
+ rm -rf "$TMP2"
168
+
169
+ # --- 16. a path containing a space keeps its own baseline row --------------
170
+ # `uniq -c | awk '{ print $2, $1 }'` keeps only the first whitespace token, so `docs/my file.md`
171
+ # is recorded as `docs/my` — and a second file sharing that prefix lands on the SAME row, so its
172
+ # hits are compared against the first file's count and pass unnoticed.
173
+ TMP4="$(mktemp -d)"; mkdir -p "$TMP4/scripts" "$TMP4/docs"
174
+ cp "$ENGINE" "$TMP4/scripts/"; cp "$TMP/scripts/review-rules.conf" "$TMP4/scripts/"
175
+ ( cd "$TMP4" && git init -q . && git config user.email t@t && git config user.name t ) >/dev/null 2>&1
176
+ printf '```\nx\n```\n' > "$TMP4/docs/my file.md" # 1 bare opener
177
+ printf '```\ny\n```\nz\n```\nw\n```\n' > "$TMP4/docs/my other.md" # 2 bare openers
178
+ ( cd "$TMP4" && git add -A . ) >/dev/null 2>&1
179
+ ( cd "$TMP4" && bash scripts/review-lint.sh --update ) >/dev/null 2>&1
180
+ bl="$TMP4/scripts/review-lint-baseline.txt"
181
+ rows="$(grep -c 'docs/my' "$bl" 2>/dev/null | tr -d ' ')"
182
+ if [ "$rows" = 2 ] \
183
+ && grep -q "$(printf 'docs/my file.md\t1')" "$bl" \
184
+ && grep -q "$(printf 'docs/my other.md\t2')" "$bl"; then
185
+ pass "a path with a space keeps its own row and count"
186
+ else
187
+ fail "a path with a space keeps its own row and count (rows=$rows: $(grep 'docs/my' "$bl" | tr '\t' '|' | tr '\n' ' '))"
188
+ fi
189
+ # ...and the gate reads those rows back, so both files stay grandfathered.
190
+ out4="$( cd "$TMP4" && bash scripts/review-lint.sh 2>&1 )"; rc4=$?
191
+ [ "$rc4" -eq 0 ] && pass "both spaced paths are grandfathered" \
192
+ || fail "both spaced paths are grandfathered (rc=$rc4: $out4)"
193
+
194
+ # --- 17. a space-separated baseline from an older kit is still readable -----
195
+ # Rows are written TAB-separated now. Refusing to read the old format would report every
196
+ # grandfathered file as a new hit and turn the gate red the moment a project upgrades.
197
+ printf '# legacy\nT002 docs/legacy.md 1\n' > "$TMP4/scripts/review-lint-baseline.txt"
198
+ rm -f "$TMP4/docs/my file.md" "$TMP4/docs/my other.md"
199
+ printf '```\nx\n```\n' > "$TMP4/docs/legacy.md"
200
+ ( cd "$TMP4" && git add -A . ) >/dev/null 2>&1
201
+ out5="$( cd "$TMP4" && bash scripts/review-lint.sh 2>&1 )"; rc5=$?
202
+ [ "$rc5" -eq 0 ] && pass "a space-separated legacy baseline is honored" \
203
+ || fail "a space-separated legacy baseline is honored (rc=$rc5: $out5)"
204
+ rm -rf "$TMP4"
205
+
206
+ # --- 18. a 4-backtick outer fence does not invert parity for the rest -------
207
+ # `/^```/` matches ```` too: the counter increments but the line never satisfies $0=="```", so it
208
+ # is never reported AND `n` stays odd — every later CLOSING fence is then flagged as a bare opener.
209
+ TMP5="$(mktemp -d)"; mkdir -p "$TMP5/scripts" "$TMP5/docs"
210
+ cp "$ENGINE" "$TMP5/scripts/"; cp "$TMP/scripts/review-rules.conf" "$TMP5/scripts/"
211
+ ( cd "$TMP5" && git init -q . && git config user.email t@t && git config user.name t ) >/dev/null 2>&1
212
+ printf '````md\n```sh\necho hi\n```\n````\n\n```sh\necho ok\n```\n' > "$TMP5/docs/nested.md"
213
+ ( cd "$TMP5" && git add -A . ) >/dev/null 2>&1
214
+ out6="$( cd "$TMP5" && bash scripts/review-lint.sh 2>&1 )"; rc6=$?
215
+ [ "$rc6" -eq 0 ] && pass "a 4-backtick outer fence leaves later fences clean" \
216
+ || fail "a 4-backtick outer fence leaves later fences clean (rc=$rc6: $out6)"
217
+ # A genuinely bare ~~~ fence is still caught — the rule sees tilde fences at all now.
218
+ printf '~~~\nx\n~~~\n' > "$TMP5/docs/tilde.md"
219
+ ( cd "$TMP5" && git add -A . ) >/dev/null 2>&1
220
+ out7="$( cd "$TMP5" && bash scripts/review-lint.sh 2>&1 )"; rc7=$?
221
+ if [ "$rc7" -ne 0 ] && printf '%s' "$out7" | grep -q 'docs/tilde.md'; then
222
+ pass "a bare ~~~ fence is caught"
223
+ else
224
+ fail "a bare ~~~ fence is caught (rc=$rc7: $out7)"
225
+ fi
226
+ rm -rf "$TMP5"
227
+
228
+ # --- 19. KIT_LINT_WALK seeds from disk even when the index is NOT empty -----
229
+ # The scaffold case init.sh actually hits: a repo that already has commits, with the kit's files
230
+ # freshly written and untracked. Without the walk the baseline comes out empty and the gate goes
231
+ # red on the user's first commit of the scaffold.
232
+ TMP6="$(mktemp -d)"; mkdir -p "$TMP6/scripts" "$TMP6/docs"
233
+ cp "$ENGINE" "$TMP6/scripts/"; cp "$TMP/scripts/review-rules.conf" "$TMP6/scripts/"
234
+ ( cd "$TMP6" && git init -q . && git config user.email t@t && git config user.name t ) >/dev/null 2>&1
235
+ echo readme > "$TMP6/README.md"
236
+ ( cd "$TMP6" && git add README.md && git commit -qm init ) >/dev/null 2>&1
237
+ printf '```\nx\n```\n' > "$TMP6/docs/scaffolded.md" # written by the scaffold, still untracked
238
+ ( cd "$TMP6" && KIT_LINT_WALK=1 bash scripts/review-lint.sh --update ) >/dev/null 2>&1
239
+ if grep -q 'docs/scaffolded.md' "$TMP6/scripts/review-lint-baseline.txt" 2>/dev/null; then
240
+ pass "KIT_LINT_WALK seeds untracked scaffold files"
241
+ else
242
+ fail "KIT_LINT_WALK seeds untracked scaffold files ($(cat "$TMP6/scripts/review-lint-baseline.txt" 2>&1))"
243
+ fi
244
+ ( cd "$TMP6" && git add -A . ) >/dev/null 2>&1
245
+ out8="$( cd "$TMP6" && bash scripts/review-lint.sh 2>&1 )"; rc8=$?
246
+ [ "$rc8" -eq 0 ] && pass "the seeded scaffold is green once committed" \
247
+ || fail "the seeded scaffold is green once committed (rc=$rc8: $out8)"
248
+ # Without the walk the seed is empty — the defect this guards against.
249
+ rm -f "$TMP6/scripts/review-lint-baseline.txt"
250
+ printf '```\ny\n```\n' > "$TMP6/docs/second.md"
251
+ ( cd "$TMP6" && bash scripts/review-lint.sh --update ) >/dev/null 2>&1
252
+ if grep -q 'docs/second.md' "$TMP6/scripts/review-lint-baseline.txt" 2>/dev/null; then
253
+ fail "an unwalked seed must not see untracked files"
254
+ else
255
+ pass "an unwalked seed sees only tracked files"
256
+ fi
257
+ rm -rf "$TMP6"
258
+
259
+ # --- 20. --baseline-path is the one place the filename is spelled ----------
260
+ out9="$(run --baseline-path)"
261
+ [ "$out9" = "scripts/review-lint-baseline.txt" ] \
262
+ && pass "--baseline-path reports the baseline" \
263
+ || fail "--baseline-path reports the baseline (got '$out9')"
264
+
265
+ # --- 21. missing rule table is a no-op, not a failure ----------------------
266
+ rm "$TMP/scripts/review-rules.conf"
267
+ capture
268
+ [ "$run_rc" -eq 0 ] && pass "missing rule table is a no-op" || fail "missing rule table is a no-op"
269
+
270
+ [ "$fails" -eq 0 ] && echo "ok review-lint-test passed" || echo "FAIL review-lint-test"
271
+ exit "$fails"