-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.sh
More file actions
executable file
·526 lines (456 loc) · 18.3 KB
/
validate.sh
File metadata and controls
executable file
·526 lines (456 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
#!/usr/bin/env bash
#
# Structural validation for the ai-agent-dev-workflow ecosystem.
# Checks files, links, JSON, phases, agents, leaks, and cross-references.
#
# Usage: ./validate.sh
# Exit code: 0 = all checks pass, 1 = failures found
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
PASS=0
FAIL=0
ERRORS=()
pass() {
PASS=$((PASS + 1))
printf " \033[32mPASS\033[0m %s\n" "$1"
}
fail() {
FAIL=$((FAIL + 1))
ERRORS+=("$1")
printf " \033[31mFAIL\033[0m %s\n" "$1"
}
section() {
printf "\n\033[1m%s\033[0m\n" "$1"
}
# ─────────────────────────────────────────────
section "1. Required files exist"
# ─────────────────────────────────────────────
required_files=(
".claude-plugin/plugin.json"
"LICENSE"
"README.md"
"sync.sh"
# TDD skill
"skills/tdd/SKILL.md"
"skills/tdd/PROJECT.md"
"skills/tdd/references/chunk-template.md"
"skills/tdd/references/tracker-schema.md"
"skills/tdd/references/quality-checklist.md"
# Spec skill
"skills/spec/SKILL.md"
"skills/spec/PROJECT.md"
"skills/spec/references/spec-template.md"
"skills/spec/references/clarification-taxonomy.md"
"skills/spec/references/validation-checklist.md"
# Agents
"agents/review-plan.md"
"agents/review-impl.md"
)
for f in "${required_files[@]}"; do
if [[ -f "$f" ]]; then
pass "$f exists"
else
fail "$f is missing"
fi
done
# ─────────────────────────────────────────────
section "2. Internal markdown links resolve"
# ─────────────────────────────────────────────
check_links_in() {
local file="$1"
local dir
dir="$(dirname "$file")"
local targets
targets="$(sed -n 's/.*\[.*\](\([^)]*\.md[^)]*\)).*/\1/p' "$file" 2>/dev/null || true)"
if [[ -z "$targets" ]]; then
return
fi
while IFS= read -r target; do
# Skip external links
[[ "$target" == http* ]] && continue
# Strip any anchor (#section)
target="${target%%#*}"
local resolved="$dir/$target"
if [[ -f "$resolved" ]]; then
pass "$file -> $target"
else
fail "$file -> $target (not found: $resolved)"
fi
done <<< "$targets"
}
check_links_in "README.md"
check_links_in "skills/tdd/SKILL.md"
check_links_in "skills/spec/SKILL.md"
check_links_in "skills/tdd/references/chunk-template.md"
check_links_in "skills/tdd/references/tracker-schema.md"
check_links_in "skills/tdd/references/quality-checklist.md"
check_links_in "skills/spec/references/spec-template.md"
check_links_in "skills/spec/references/clarification-taxonomy.md"
check_links_in "skills/spec/references/validation-checklist.md"
# ─────────────────────────────────────────────
section "3. JSON validity"
# ─────────────────────────────────────────────
# plugin.json
if python3 -m json.tool .claude-plugin/plugin.json > /dev/null 2>&1; then
pass "plugin.json is valid JSON"
else
fail "plugin.json is invalid JSON"
fi
# JSON blocks in markdown files
validate_json_blocks() {
local file="$1"
local block_num=0
local in_json=false
local json_buf=""
while IFS= read -r line; do
if [[ "$line" == '```json' ]]; then
in_json=true
json_buf=""
block_num=$((block_num + 1))
continue
fi
if [[ "$line" == '```' ]] && $in_json; then
in_json=false
if echo "$json_buf" | python3 -m json.tool > /dev/null 2>&1; then
pass "$file JSON block #$block_num is valid"
else
fail "$file JSON block #$block_num is invalid JSON"
fi
continue
fi
if $in_json; then
json_buf+="$line"$'\n'
fi
done < "$file"
}
validate_json_blocks "skills/tdd/references/tracker-schema.md"
validate_json_blocks "skills/tdd/references/chunk-template.md"
# ─────────────────────────────────────────────
section "4. plugin.json has required fields"
# ─────────────────────────────────────────────
for field in name description author; do
if python3 -c "import json; d=json.load(open('.claude-plugin/plugin.json')); assert '$field' in d" 2>/dev/null; then
pass "plugin.json has '$field' field"
else
fail "plugin.json missing '$field' field"
fi
done
# Check skills array
skill_count="$(python3 -c "import json; d=json.load(open('.claude-plugin/plugin.json')); print(len(d.get('skills',[])))" 2>/dev/null || echo 0)"
if [[ "$skill_count" -ge 2 ]]; then
pass "plugin.json has $skill_count skills"
else
fail "plugin.json has $skill_count skills (expected >= 2)"
fi
# ─────────────────────────────────────────────
section "5. TDD SKILL.md phases are sequential (1-6)"
# ─────────────────────────────────────────────
tdd_skill="skills/tdd/SKILL.md"
phase_count="$(grep -cE '^## Phase [0-9]+:' "$tdd_skill" || true)"
if [[ "$phase_count" -eq 6 ]]; then
pass "TDD SKILL.md has $phase_count phases"
else
fail "TDD SKILL.md has $phase_count phases (expected 6)"
fi
expected=1
phase_nums="$(grep -E '^## Phase [0-9]+:' "$tdd_skill" | sed 's/^## Phase //' | sed 's/:.*//' || true)"
while IFS= read -r num; do
[[ -z "$num" ]] && continue
if [[ "$num" -eq "$expected" ]]; then
pass "TDD Phase $num is sequential"
else
fail "TDD Phase $num out of order (expected $expected)"
fi
expected=$((expected + 1))
done <<< "$phase_nums"
# ─────────────────────────────────────────────
section "6. Spec SKILL.md phases are sequential (1-5)"
# ─────────────────────────────────────────────
spec_skill="skills/spec/SKILL.md"
phase_count="$(grep -cE '^## Phase [0-9]+:' "$spec_skill" || true)"
if [[ "$phase_count" -eq 5 ]]; then
pass "Spec SKILL.md has $phase_count phases"
else
fail "Spec SKILL.md has $phase_count phases (expected 5)"
fi
expected=1
phase_nums="$(grep -E '^## Phase [0-9]+:' "$spec_skill" | sed 's/^## Phase //' | sed 's/:.*//' || true)"
while IFS= read -r num; do
[[ -z "$num" ]] && continue
if [[ "$num" -eq "$expected" ]]; then
pass "Spec Phase $num is sequential"
else
fail "Spec Phase $num out of order (expected $expected)"
fi
expected=$((expected + 1))
done <<< "$phase_nums"
# ─────────────────────────────────────────────
section "7. Quality checklist has exactly 8 points"
# ─────────────────────────────────────────────
checklist="skills/tdd/references/quality-checklist.md"
checklist_count="$(grep -cE '^## [0-9]+\.' "$checklist" || true)"
if [[ "$checklist_count" -eq 8 ]]; then
pass "quality-checklist.md has $checklist_count points"
else
fail "quality-checklist.md has $checklist_count points (expected 8)"
fi
expected=1
checklist_nums="$(grep -E '^## [0-9]+\.' "$checklist" | sed 's/^## //' | sed 's/\..*//' || true)"
while IFS= read -r num; do
[[ -z "$num" ]] && continue
if [[ "$num" -eq "$expected" ]]; then
pass "Checklist point $num is sequential"
else
fail "Checklist point $num out of order (expected $expected)"
fi
expected=$((expected + 1))
done <<< "$checklist_nums"
# ─────────────────────────────────────────────
section "8. TDD SKILL.md 8-point summaries match checklist"
# ─────────────────────────────────────────────
# Phase 6 Quick Reference lists criteria 1-7 in bold; Phase 2.5 delegates
# to the review-plan agent (criteria listed in the agent, not inline).
# Check: each criterion appears at least once (Phase 6 Quick Reference).
phase6_names=(
"Completeness"
"Correctness"
"Gaps (Functional)"
"Standards"
"Regression"
"Robustness"
"Gaps (Architectural)"
"Blindspots"
)
for name in "${phase6_names[@]}"; do
count="$(grep -c "\*\*$name\*\*" "$tdd_skill" || true)"
if [[ "$count" -ge 1 ]]; then
pass "\"$name\" in Phase 6 Quick Reference"
else
fail "\"$name\" not found in TDD SKILL.md"
fi
done
# Phase 2.5 is an artifact-triggered gate that delegates to review-plan agent.
# Verify the gate structure exists.
if grep -q "GATE.*tracker.*triggers" "$tdd_skill"; then
pass "Phase 2.5 has artifact-triggered gate"
else
fail "Phase 2.5 missing artifact-triggered gate pattern"
fi
if grep -q "plan_review" "$tdd_skill"; then
pass "SKILL.md references plan_review tracker field"
else
fail "SKILL.md missing plan_review tracker field reference"
fi
# ─────────────────────────────────────────────
section "9. Lessons learned are sequentially numbered"
# ─────────────────────────────────────────────
check_lessons() {
local file="$1"
local label="$2"
local lesson_nums=()
local in_lessons=false
while IFS= read -r line; do
if [[ "$line" == "## Lessons Learned"* ]]; then
in_lessons=true
continue
fi
if $in_lessons && [[ "$line" == "---" || "$line" == "## "* ]]; then
break
fi
if $in_lessons; then
num=""
if echo "$line" | grep -qE '^[0-9]+\. \*\*'; then
num="$(echo "$line" | sed 's/\..*//')"
fi
if [[ -n "$num" ]]; then
lesson_nums+=("$num")
fi
fi
done < "$file"
local count=${#lesson_nums[@]}
if [[ "$count" -gt 0 ]]; then
pass "$label: found $count lessons"
else
fail "$label: no lessons found"
fi
local expected=1
for num in "${lesson_nums[@]}"; do
if [[ "$num" -eq "$expected" ]]; then
pass "$label: lesson $num is sequential"
else
fail "$label: lesson $num out of order (expected $expected)"
fi
expected=$((expected + 1))
done
}
check_lessons "$tdd_skill" "TDD"
check_lessons "$spec_skill" "Spec"
# ─────────────────────────────────────────────
section "10. PROJECT.md templates have required sections"
# ─────────────────────────────────────────────
tdd_sections=(
"Build & Test Commands"
"Architecture Patterns"
"Standards to Verify"
"Blindspots to Check"
"Commit Conventions"
"Documentation Location"
)
for section_name in "${tdd_sections[@]}"; do
if grep -q "$section_name" "skills/tdd/PROJECT.md"; then
pass "TDD PROJECT.md has \"$section_name\""
else
fail "TDD PROJECT.md missing \"$section_name\""
fi
done
spec_sections=(
"Domain Context"
"Architecture Overview"
"Domain-Specific Concerns"
"Quality Standards"
"Commit Conventions"
)
for section_name in "${spec_sections[@]}"; do
if grep -q "$section_name" "skills/spec/PROJECT.md"; then
pass "Spec PROJECT.md has \"$section_name\""
else
fail "Spec PROJECT.md missing \"$section_name\""
fi
done
# ─────────────────────────────────────────────
section "11. No project-specific leaks in core files"
# ─────────────────────────────────────────────
core_files=(
"skills/tdd/SKILL.md"
"skills/spec/SKILL.md"
"skills/tdd/references/chunk-template.md"
"skills/tdd/references/tracker-schema.md"
"skills/tdd/references/quality-checklist.md"
"skills/spec/references/spec-template.md"
"skills/spec/references/clarification-taxonomy.md"
"skills/spec/references/validation-checklist.md"
"agents/review-plan.md"
"agents/review-impl.md"
)
leaked_terms=("SapClient" "fetchFn" "vitest" "npx tsc" "CSRF" "Zod" "gradlew" "Hilt" "Room" "Jetpack" "AndroidManifest")
leak_found=false
for file in "${core_files[@]}"; do
for term in "${leaked_terms[@]}"; do
if grep -qi "$term" "$file" 2>/dev/null; then
fail "$file contains project-specific term \"$term\""
leak_found=true
fi
done
done
if ! $leak_found; then
pass "No project-specific terms in core files"
fi
# ─────────────────────────────────────────────
section "12. Agent frontmatter is valid"
# ─────────────────────────────────────────────
for agent in agents/*.md; do
basename="$(basename "$agent")"
for field in name description tools model; do
if grep -q "^${field}:" "$agent"; then
pass "$basename has '$field' field"
else
fail "$basename missing '$field' field"
fi
done
done
# ─────────────────────────────────────────────
section "13. TDD SKILL.md references review agents"
# ─────────────────────────────────────────────
if grep -q "review-plan" "$tdd_skill"; then
pass "TDD SKILL.md references review-plan agent"
else
fail "TDD SKILL.md does not reference review-plan agent"
fi
if grep -q "review-impl" "$tdd_skill"; then
pass "TDD SKILL.md references review-impl agent"
else
fail "TDD SKILL.md does not reference review-impl agent"
fi
# ─────────────────────────────────────────────
section "14. SKILL.md frontmatter follows spec"
# ─────────────────────────────────────────────
check_skill_frontmatter() {
local file="$1"
local label="$2"
if grep -q '^name:' "$file"; then
local skill_name
skill_name="$(sed -n 's/^name:[[:space:]]*//p' "$file" | head -1 | tr -d ' ')"
pass "$label has 'name' field: $skill_name"
if echo "$skill_name" | grep -qE '^[a-z0-9]([a-z0-9-]*[a-z0-9])?$'; then
pass "$label name format is valid"
else
fail "$label name '$skill_name' should be lowercase letters, numbers, and hyphens"
fi
else
fail "$label missing 'name' field"
fi
if grep -q '^description:' "$file"; then
pass "$label has 'description' field"
else
fail "$label missing 'description' field"
fi
if grep -q '\$ARGUMENTS' "$file"; then
pass "$label uses \$ARGUMENTS placeholder"
else
fail "$label missing \$ARGUMENTS (user input won't reach the process)"
fi
}
check_skill_frontmatter "$tdd_skill" "TDD SKILL.md"
check_skill_frontmatter "$spec_skill" "Spec SKILL.md"
# ─────────────────────────────────────────────
section "15. SKILL.md files are under 500 lines"
# ─────────────────────────────────────────────
for skill_file in "$tdd_skill" "$spec_skill"; do
label="$(basename "$(dirname "$skill_file")")"
lines="$(wc -l < "$skill_file")"
if [[ "$lines" -le 510 ]]; then
pass "$label SKILL.md is $lines lines (limit: 510)"
else
fail "$label SKILL.md is $lines lines (recommended limit: 510)"
fi
done
# ─────────────────────────────────────────────
section "16. Example project configs are valid"
# ─────────────────────────────────────────────
for config in skills/tdd/project-configs/*.md; do
basename="$(basename "$config")"
for section_name in "${tdd_sections[@]}"; do
if grep -q "$section_name" "$config"; then
pass "tdd/$basename has \"$section_name\""
else
fail "tdd/$basename missing \"$section_name\""
fi
done
done
for config in skills/spec/project-configs/*.md; do
basename="$(basename "$config")"
for section_name in "${spec_sections[@]}"; do
if grep -q "$section_name" "$config"; then
pass "spec/$basename has \"$section_name\""
else
fail "spec/$basename missing \"$section_name\""
fi
done
done
# ─────────────────────────────────────────────
# Summary
# ─────────────────────────────────────────────
printf "\n\033[1m━━━ Results ━━━\033[0m\n"
printf " \033[32m%d passed\033[0m\n" "$PASS"
if [[ "$FAIL" -gt 0 ]]; then
printf " \033[31m%d failed\033[0m\n" "$FAIL"
printf "\n\033[31mFailures:\033[0m\n"
for err in "${ERRORS[@]}"; do
printf " - %s\n" "$err"
done
exit 1
else
printf " \033[32m0 failed\033[0m\n"
printf "\n\033[32mAll checks passed.\033[0m\n"
exit 0
fi