@jeiemgi/cckit 0.9.0 → 0.10.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.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +169 -21
- package/README.md +491 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +182 -17
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +13 -5
- package/commands/kit-export-project.md +0 -2
- package/commands/kit-export-training.md +6 -9
- package/commands/kit-init.md +43 -13
- package/commands/kit-routines.md +1 -1
- package/commands/kit-update.md +11 -6
- package/databases/supabase/guide.html +106 -0
- package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
- package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
- package/databases/supabase.json +70 -0
- package/integrations/emil-design-eng.json +41 -0
- package/integrations/graft.json +81 -0
- package/integrations/impeccable.json +42 -0
- package/integrations/integration.schema.json +215 -0
- package/integrations/lavish.json +43 -0
- package/integrations/mempalace.json +28 -0
- package/integrations/mlx-lm.json +32 -0
- package/integrations/web-design-guidelines.json +42 -0
- package/kit.config.schema.json +183 -5
- package/package.json +4 -1
- package/profiles/automation.json +7 -1
- package/profiles/content.json +10 -2
- package/profiles/marketing.json +57 -0
- package/profiles/minimal.json +7 -1
- package/profiles/research.json +7 -1
- package/profiles/software.json +7 -1
- package/recipes/nextjs-shadcn.json +49 -0
- package/scripts/agent-skills-external.txt +45 -0
- package/scripts/agent-skills-lint-test.sh +131 -0
- package/scripts/agent-skills-lint.sh +115 -0
- package/scripts/agent-template-lint-test.sh +42 -0
- package/scripts/agent-template-lint.sh +58 -0
- package/scripts/annotate-setup.sh +1 -1
- package/scripts/autopilot-run-test.sh +338 -0
- package/scripts/autopilot-run.sh +448 -0
- package/scripts/autopilot-test.sh +8 -0
- package/scripts/autopilot.sh +10 -1
- package/scripts/benchmark/benchmark-test.sh +85 -0
- package/scripts/benchmark/checkpoint-test.sh +314 -0
- package/scripts/benchmark/checkpoint.sh +408 -0
- package/scripts/benchmark/lib/model.sh +31 -6
- package/scripts/benchmark/report.sh +17 -2
- package/scripts/benchmark/run-quality.sh +36 -10
- package/scripts/benchmark/verb-timings-test.sh +124 -0
- package/scripts/benchmark/verb-timings.sh +149 -0
- package/scripts/check.sh +29 -19
- package/scripts/content-skills-test.sh +144 -0
- package/scripts/copilot-loop-test.sh +25 -0
- package/scripts/database-supabase-test.sh +121 -0
- package/scripts/docs-marketing-words-test.sh +73 -0
- package/scripts/docs-record-tables-test.sh +72 -0
- package/scripts/hook-adapter-test.sh +193 -0
- package/scripts/init-content-test.sh +225 -0
- package/scripts/init-guided-test.sh +474 -0
- package/scripts/init-recipes-test.sh +104 -0
- package/scripts/init-upgrade-test.sh +341 -2
- package/scripts/init.sh +746 -95
- package/scripts/instruction-budget-baseline.txt +8 -0
- package/scripts/instruction-budget-lint-test.sh +166 -0
- package/scripts/instruction-budget-lint.sh +219 -0
- package/scripts/integrations-check-test.sh +200 -0
- package/scripts/integrations-check.sh +157 -0
- package/scripts/kit-add-test.sh +214 -0
- package/scripts/kit-add.sh +305 -5
- package/scripts/kit-adopt-test.sh +16 -0
- package/scripts/kit-adopt.sh +3 -2
- package/scripts/kit-digest.sh +2 -2
- package/scripts/kit-doctor-test.sh +293 -0
- package/scripts/kit-doctor.sh +272 -140
- package/scripts/kit-export-project-test.sh +3 -3
- package/scripts/kit-remove-test.sh +19 -0
- package/scripts/kit-routines.sh +2 -2
- package/scripts/kit-self-update.sh +1 -1
- package/scripts/kit-version-check-test.sh +4 -0
- package/scripts/kit-version-check.sh +4 -2
- package/scripts/knowledge-lint.sh +4 -4
- package/scripts/leak-fence-test.sh +89 -0
- package/scripts/lib/adapter-select-test.sh +136 -0
- package/scripts/lib/adapter-select.sh +158 -0
- package/scripts/lib/agent-def-test.sh +69 -0
- package/scripts/lib/agent-def.sh +106 -0
- package/scripts/lib/agent-launch-test.sh +212 -0
- package/scripts/lib/agent-launch.sh +335 -0
- package/scripts/lib/board-view-test.sh +11 -0
- package/scripts/lib/board-view.sh +42 -26
- package/scripts/lib/branch-owner-test.sh +26 -0
- package/scripts/lib/branch-owner.sh +16 -9
- package/scripts/lib/captain-test.sh +105 -0
- package/scripts/lib/captain.sh +87 -8
- package/scripts/lib/codex-hooks-test.sh +100 -0
- package/scripts/lib/codex-hooks.sh +69 -0
- package/scripts/lib/commitlint.sh +1 -1
- package/scripts/lib/content-kinds-gc-test.sh +88 -0
- package/scripts/lib/copilot-test.sh +70 -4
- package/scripts/lib/copilot.sh +66 -14
- package/scripts/lib/effort-dispatch-test.sh +3 -3
- package/scripts/lib/effort-metrics-test.sh +178 -1
- package/scripts/lib/effort-metrics.sh +175 -35
- package/scripts/lib/effort-ops-test.sh +205 -7
- package/scripts/lib/effort-ops.sh +198 -43
- package/scripts/lib/effort-parity-test.sh +49 -13
- package/scripts/lib/effort-plan-test.sh +337 -0
- package/scripts/lib/effort-plan.sh +200 -23
- package/scripts/lib/effort.sh +56 -11
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +23 -16
- package/scripts/lib/gh-rest-test.sh +32 -3
- package/scripts/lib/gh-rest.sh +17 -2
- package/scripts/lib/hook-refresh.sh +1 -1
- package/scripts/lib/init-github.sh +412 -0
- package/scripts/lib/init-guide.sh +630 -0
- package/scripts/lib/integration-install-test.sh +343 -0
- package/scripts/lib/integration-install.sh +257 -0
- package/scripts/lib/integrations-test.sh +366 -0
- package/scripts/lib/integrations.sh +244 -0
- package/scripts/lib/kinds-test.sh +125 -0
- package/scripts/lib/kinds.sh +66 -0
- package/scripts/lib/kit-brief-test.sh +22 -3
- package/scripts/lib/kit-brief.sh +45 -5
- package/scripts/lib/kit-config-resolve.sh +2 -2
- package/scripts/lib/kit-config-test.sh +64 -1
- package/scripts/lib/kit-config.sh +37 -1
- package/scripts/lib/kit-events.sh +7 -0
- package/scripts/lib/kit-gc-test.sh +173 -1
- package/scripts/lib/kit-gc.sh +226 -37
- package/scripts/lib/kit-hotfix.sh +216 -0
- package/scripts/lib/kit-interview-test.sh +93 -0
- package/scripts/lib/kit-interview.sh +117 -8
- package/scripts/lib/kit-lib-test.sh +1 -1
- package/scripts/lib/kit-lib.sh +3 -3
- package/scripts/lib/kit-local.sh +2 -2
- package/scripts/lib/kit-manifest.sh +33 -1
- package/scripts/lib/kit-profile-test.sh +3 -3
- package/scripts/lib/kit-status-test.sh +112 -4
- package/scripts/lib/kit-status.sh +246 -16
- package/scripts/lib/kit-task-ops-test.sh +37 -0
- package/scripts/lib/kit-task-ops.sh +175 -31
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +1 -1
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
- package/scripts/lib/kto-task-pr-test.sh +70 -0
- package/scripts/lib/leak-fence.sh +89 -0
- package/scripts/lib/light-task-run-test.sh +255 -0
- package/scripts/lib/light-task-test.sh +309 -0
- package/scripts/lib/light-task.sh +706 -0
- package/scripts/lib/next-test.sh +99 -0
- package/scripts/lib/next.sh +9 -3
- package/scripts/lib/orchestration-runtime-test.sh +72 -0
- package/scripts/lib/orchestration-runtime.sh +57 -5
- package/scripts/lib/plan-machine-test.sh +15 -2
- package/scripts/lib/plan-machine.sh +20 -7
- package/scripts/lib/plan-next-test.sh +1 -1
- package/scripts/lib/plan-next.sh +4 -4
- package/scripts/lib/pr-evidence-test.sh +3 -3
- package/scripts/lib/pr-evidence.sh +1 -1
- package/scripts/lib/qa-lane-test.sh +626 -0
- package/scripts/lib/qa-lane.sh +1357 -0
- package/scripts/lib/qa-lanes-test.sh +175 -0
- package/scripts/lib/react-detect.sh +1 -1
- package/scripts/lib/render-test.sh +1 -1
- package/scripts/lib/review-page-test.sh +318 -0
- package/scripts/lib/review-page.sh +369 -0
- package/scripts/lib/review-stage-test.sh +62 -11
- package/scripts/lib/review-stage.sh +42 -60
- package/scripts/lib/role-identity-test.sh +65 -0
- package/scripts/lib/role-identity.sh +25 -2
- package/scripts/lib/secret-guard.sh +3 -3
- package/scripts/lib/session-registry-test.sh +111 -0
- package/scripts/lib/session-registry.sh +233 -0
- package/scripts/lib/stage-receipt-test.sh +14 -1
- package/scripts/lib/stage-receipt.sh +13 -8
- package/scripts/lib/task-source-file.sh +309 -0
- package/scripts/lib/task-source.sh +130 -0
- package/scripts/lib/upgrade-report-test.sh +120 -0
- package/scripts/lib/upgrade-report.sh +138 -0
- package/scripts/lib/version-bump.sh +3 -3
- package/scripts/lib/wave-result-test.sh +80 -0
- package/scripts/lib/wave-result.sh +127 -0
- package/scripts/lib/worker-brief-test.sh +5 -0
- package/scripts/lib/worker-brief.sh +2 -2
- package/scripts/lib/worktree-issue-test.sh +30 -1
- package/scripts/lib/worktree-issue.sh +82 -12
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +153 -31
- package/scripts/lib/zsh-safety-test.sh +19 -3
- package/scripts/marketing-walkthrough-test.sh +152 -0
- package/scripts/night-grant-test.sh +37 -0
- package/scripts/night-grant.sh +448 -0
- package/scripts/night-run-test.sh +8 -0
- package/scripts/night-run.mjs +275 -0
- package/scripts/night-run.test.mjs +324 -0
- package/scripts/orchestrate-test.sh +190 -0
- package/scripts/orchestrate.sh +79 -8
- package/scripts/portable-test.sh +11 -2
- package/scripts/publish.sh +28 -3
- package/scripts/review-lint-test.sh +7 -7
- package/scripts/review-lint.sh +2 -2
- package/scripts/review-rules.conf +8 -0
- package/scripts/rule-recipes-test.sh +96 -0
- package/scripts/self-install-test.sh +39 -9
- package/scripts/setup-labels.sh +18 -1
- package/scripts/setup-milestones.sh +1 -1
- package/scripts/showcase.sh +1 -1
- package/scripts/skill-frontmatter-lint-test.sh +4 -4
- package/scripts/skill-frontmatter-lint.sh +1 -1
- package/scripts/status-test.sh +113 -2
- package/scripts/status.sh +16 -3
- package/scripts/task-sync-test.sh +154 -0
- package/scripts/task-sync.sh +243 -32
- package/scripts/test-runner-test.sh +158 -0
- package/scripts/test.sh +131 -23
- package/scripts/update-path-test.sh +279 -0
- package/scripts/ux-ds-audit.sh +1 -1
- package/scripts/ux-graph-scan.sh +6 -6
- package/scripts/wave-worker.sh +54 -0
- package/skills/kit-add/SKILL.md +77 -0
- package/skills/kit-autopilot/SKILL.md +123 -12
- package/skills/kit-cleanup/SKILL.md +5 -2
- package/skills/kit-contribute/SKILL.md +4 -4
- package/skills/kit-docs-writer/SKILL.md +16 -6
- package/skills/kit-effort-close/SKILL.md +17 -8
- package/skills/kit-effort-new/SKILL.md +15 -9
- package/skills/kit-effort-pr/SKILL.md +15 -7
- package/skills/kit-effort-start/SKILL.md +5 -2
- package/skills/kit-gc/SKILL.md +5 -2
- package/skills/kit-next/SKILL.md +5 -1
- package/skills/kit-onboard/SKILL.md +3 -3
- package/skills/kit-page/SKILL.md +93 -0
- package/skills/kit-plan-next/SKILL.md +8 -4
- package/skills/kit-security-sweep/SKILL.md +1 -3
- package/skills/kit-ship/SKILL.md +2 -3
- package/skills/kit-status/SKILL.md +35 -4
- package/skills/kit-task-new/SKILL.md +3 -3
- package/skills/kit-task-pr/SKILL.md +7 -2
- package/skills/kit-task-pr-merge/SKILL.md +7 -2
- package/skills/kit-task-start/SKILL.md +7 -7
- package/skills/kit-task-sync/SKILL.md +19 -3
- package/skills/kit-ux-audit/SKILL.md +3 -2
- package/templates/agents/auto-dev.md +5 -4
- package/templates/agents/backend.md +1 -1
- package/templates/agents/designer.md +2 -0
- package/templates/agents/devops.md +1 -1
- package/templates/agents/editor.md +9 -1
- package/templates/agents/frontend.md +1 -1
- package/templates/agents/local-delegate.md +1 -1
- package/templates/agents/pm.md +5 -5
- package/templates/agents/tech-lead.md +1 -1
- package/templates/benchmarks/SCHEMA.md +9 -3
- package/templates/codex/hooks.json.tmpl +89 -0
- package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
- package/templates/hooks/mempal_followup.sh.tmpl +2 -2
- package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
- package/templates/hooks/prepush_gate.sh.tmpl +4 -2
- package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
- package/templates/instructions.md.tmpl +174 -0
- package/templates/kit.config.json.tmpl +3 -3
- package/templates/knowledge-INDEX.md.tmpl +1 -1
- package/templates/lib/kit-sigil.sh.tmpl +1 -1
- package/templates/rules/authoring.md +106 -0
- package/templates/rules/branch-naming.md +40 -4
- package/templates/rules/code-retrieval.md +63 -0
- package/templates/rules/delegation-brief.md +0 -3
- package/templates/rules/design-routing.md +3 -3
- package/templates/rules/effort-model.md +14 -10
- package/templates/rules/gate-and-review.md +94 -0
- package/templates/rules/issue-lifecycle.md +88 -0
- package/templates/rules/knowledge-base.md +1 -1
- package/templates/rules/mempalace.md +1 -1
- package/templates/rules/merge-safety.md +108 -0
- package/templates/rules/naming-and-ids.md +23 -17
- package/templates/rules/plain-language.md +59 -0
- package/templates/rules/plan-next.md +9 -11
- package/templates/rules/react-annotate.md +6 -0
- package/templates/rules/review-pages.md +49 -0
- package/templates/rules/risk-tiered-review.md +13 -4
- package/templates/rules/shared-checkout.md +106 -0
- package/templates/rules/skill-gaps.md +2 -7
- package/templates/rules/task-management.md +13 -1
- package/templates/skills/brand-voice/SKILL.md +91 -0
- package/templates/skills/brand-voice/references/voice-template.md +61 -0
- package/templates/skills/campaign/SKILL.md +123 -0
- package/templates/skills/campaign/references/plan-template.md +55 -0
- package/templates/skills/concrete/SKILL.md +2 -2
- package/templates/skills/copywriting/SKILL.md +8 -1
- package/templates/skills/feature-build-refine/SKILL.md +2 -4
- package/templates/skills/morning-briefing/SKILL.md +2 -2
- package/templates/skills/page-design/SKILL.md +145 -0
- package/templates/skills/page-design/add.json +5 -0
- package/templates/skills/page-design/references/design-file-template.md +40 -0
- package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
- package/templates/skills/page-design/references/minimum-rules.md +42 -0
- package/templates/skills/speckit/SKILL.md +4 -5
- package/templates/skills/supabase-patterns/SKILL.md +1 -1
- package/commands/kit-add.md +0 -42
- package/templates/CLAUDE.md.tmpl +0 -106
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# instruction-budget-baseline.txt — generated by scripts/instruction-budget-lint.sh --update
|
|
2
|
+
# Instruction files over 200 lines, and the resident total while it is over 150000 bytes.
|
|
3
|
+
# These are GRANDFATHERED: allowed to stay, but may never grow. Shrink them, scope a rule with
|
|
4
|
+
# `paths:`, or split it into a short rule + a knowledge doc, then re-run --update to tighten.
|
|
5
|
+
#
|
|
6
|
+
# <path> <lines> | @resident <bytes>
|
|
7
|
+
.claude/rules/effort-model.md 209
|
|
8
|
+
.claude/rules/naming-and-ids.md 208
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# instruction-budget-lint-test.sh — behavioral test for the instruction-file budget ratchet (#357).
|
|
3
|
+
# Builds a throwaway project in a temp ROOT and asserts the transitions that matter: a `paths:` rule
|
|
4
|
+
# leaves the resident sum, a new over-long file fails, a baselined file may sit still but not grow,
|
|
5
|
+
# the resident total ratchets the same way, and a project with no instruction files is a no-op.
|
|
6
|
+
set -uo pipefail
|
|
7
|
+
|
|
8
|
+
LINT="$(cd "$(dirname "$0")" && pwd)/instruction-budget-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"
|
|
16
|
+
cp "$LINT" "$TMP/scripts/"
|
|
17
|
+
|
|
18
|
+
# Capture rather than pipe: `run | grep -q` lets grep exit early and SIGPIPE the lint, which
|
|
19
|
+
# pipefail then reports as a failure on a successful match.
|
|
20
|
+
run() { ( cd "$TMP" && bash scripts/instruction-budget-lint.sh "$@" 2>&1 ); }
|
|
21
|
+
run_out=""; run_rc=0
|
|
22
|
+
capture() { run_out="$(run "$@")"; run_rc=$?; }
|
|
23
|
+
has() { case "$run_out" in *"$1"*) return 0 ;; *) return 1 ;; esac; }
|
|
24
|
+
|
|
25
|
+
# mk_rule <name> <lines> [paths-glob] — a rule of exactly <lines> lines, each line 10 bytes.
|
|
26
|
+
mk_rule() {
|
|
27
|
+
local name="$1" lines="$2" glob="${3:-}" i=0
|
|
28
|
+
mkdir -p "$TMP/.claude/rules"
|
|
29
|
+
{
|
|
30
|
+
if [ -n "$glob" ]; then
|
|
31
|
+
printf -- '---\npaths:\n - "%s"\n---\n' "$glob"
|
|
32
|
+
i=4
|
|
33
|
+
fi
|
|
34
|
+
while [ "$i" -lt "$lines" ]; do echo "123456789"; i=$(( i + 1 )); done
|
|
35
|
+
} > "$TMP/.claude/rules/$name.md"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# --- (d) no CLAUDE.md and no rules dir: exits 0, and --summary prints nothing ------------------
|
|
39
|
+
capture
|
|
40
|
+
if [ "$run_rc" -eq 0 ] && has "nothing to lint"; then pass "no instruction files exits 0"
|
|
41
|
+
else fail "no instruction files exits 0 (rc $run_rc: $run_out)"; fi
|
|
42
|
+
capture --summary
|
|
43
|
+
if [ "$run_rc" -eq 0 ] && [ -z "$run_out" ]; then pass "--summary is empty with nothing to measure"
|
|
44
|
+
else fail "--summary is empty with nothing to measure (rc $run_rc: $run_out)"; fi
|
|
45
|
+
|
|
46
|
+
# --- --baseline-path names the file init.sh seeds ---------------------------------------------
|
|
47
|
+
capture --baseline-path
|
|
48
|
+
[ "$run_out" = "scripts/instruction-budget-baseline.txt" ] && pass "--baseline-path prints the baseline path" \
|
|
49
|
+
|| fail "--baseline-path prints the baseline path (got $run_out)"
|
|
50
|
+
|
|
51
|
+
# --- a lean project passes with no baseline ---------------------------------------------------
|
|
52
|
+
printf '%s\n' "# project" "one line" > "$TMP/CLAUDE.md" # 10 + 9 = 19 bytes
|
|
53
|
+
mk_rule always 10 # 100 bytes
|
|
54
|
+
capture
|
|
55
|
+
[ "$run_rc" -eq 0 ] && pass "a lean project passes with no baseline" \
|
|
56
|
+
|| fail "a lean project passes with no baseline ($run_out)"
|
|
57
|
+
|
|
58
|
+
# --- (a) a rule with `paths:` frontmatter is excluded from the resident sum -------------------
|
|
59
|
+
capture --summary
|
|
60
|
+
has "instruction files: 119 of 150000 bytes resident" && pass "resident sum is CLAUDE.md + unscoped rules (119)" \
|
|
61
|
+
|| fail "resident sum is CLAUDE.md + unscoped rules (got: $run_out)"
|
|
62
|
+
mk_rule scoped 50 'src/**/*.tsx'
|
|
63
|
+
capture --summary
|
|
64
|
+
has "instruction files: 119 of 150000 bytes resident" && pass "a paths: rule is excluded from the resident sum" \
|
|
65
|
+
|| fail "a paths: rule is excluded from the resident sum (got: $run_out)"
|
|
66
|
+
capture --report
|
|
67
|
+
if has "resident total: 119 of 150000 bytes" && has "path-scoped: " && has "in 1 file(s)"; then
|
|
68
|
+
pass "--report prints the resident total and the path-scoped cost"
|
|
69
|
+
else fail "--report prints the resident total and the path-scoped cost (got: $run_out)"; fi
|
|
70
|
+
|
|
71
|
+
# A `paths:` line in the BODY is not frontmatter and must not hide a rule from the sum.
|
|
72
|
+
printf '%s\n' "# body" "paths: not frontmatter" > "$TMP/.claude/rules/body.md" # 7 + 23 = 30
|
|
73
|
+
capture --summary
|
|
74
|
+
has "instruction files: 149 of" && pass "paths: outside frontmatter does not scope a rule" \
|
|
75
|
+
|| fail "paths: outside frontmatter does not scope a rule (got: $run_out)"
|
|
76
|
+
rm -f "$TMP/.claude/rules/body.md"
|
|
77
|
+
|
|
78
|
+
# --- --summary names the three largest resident files, largest first --------------------------
|
|
79
|
+
mk_rule mid 30; mk_rule big 40; mk_rule small 2
|
|
80
|
+
capture --summary
|
|
81
|
+
case "$run_out" in
|
|
82
|
+
*"largest: .claude/rules/big.md (400), .claude/rules/mid.md (300), .claude/rules/always.md (100)") \
|
|
83
|
+
pass "--summary lists the three largest resident files" ;;
|
|
84
|
+
*) fail "--summary lists the three largest resident files (got: $run_out)" ;;
|
|
85
|
+
esac
|
|
86
|
+
capture --report
|
|
87
|
+
has "largest resident: .claude/rules/big.md (400)" && pass "--report lists the largest files" \
|
|
88
|
+
|| fail "--report lists the largest files (got: $run_out)"
|
|
89
|
+
rm -f "$TMP/.claude/rules/mid.md" "$TMP/.claude/rules/big.md" "$TMP/.claude/rules/small.md"
|
|
90
|
+
|
|
91
|
+
# --- (c) a NEW file over 200 lines fails ------------------------------------------------------
|
|
92
|
+
mk_rule long 201
|
|
93
|
+
capture
|
|
94
|
+
if [ "$run_rc" -ne 0 ] && has "long.md: 201 lines, over the 200-line limit"; then
|
|
95
|
+
pass "a new file over 200 lines is rejected"
|
|
96
|
+
else fail "a new file over 200 lines is rejected (rc $run_rc: $run_out)"; fi
|
|
97
|
+
|
|
98
|
+
# A path-scoped file is held to the line limit too: once loaded it costs the same.
|
|
99
|
+
mk_rule scopedlong 230 'docs/**'
|
|
100
|
+
capture
|
|
101
|
+
has "scopedlong.md: 230 lines" && pass "a path-scoped file over 200 lines is rejected too" \
|
|
102
|
+
|| fail "a path-scoped file over 200 lines is rejected too ($run_out)"
|
|
103
|
+
rm -f "$TMP/.claude/rules/scopedlong.md"
|
|
104
|
+
|
|
105
|
+
# --- baselining grandfathers it ---------------------------------------------------------------
|
|
106
|
+
run --update >/dev/null
|
|
107
|
+
grep -q '^\.claude/rules/long\.md 201$' "$TMP/scripts/instruction-budget-baseline.txt" \
|
|
108
|
+
&& pass "--update records the file and its line count" \
|
|
109
|
+
|| fail "--update records the file and its line count ($(cat "$TMP/scripts/instruction-budget-baseline.txt"))"
|
|
110
|
+
capture
|
|
111
|
+
[ "$run_rc" -eq 0 ] && pass "a baselined file that sits still passes" \
|
|
112
|
+
|| fail "a baselined file that sits still passes ($run_out)"
|
|
113
|
+
|
|
114
|
+
# --- (b) growing a baselined file fails -------------------------------------------------------
|
|
115
|
+
mk_rule long 205
|
|
116
|
+
capture
|
|
117
|
+
if [ "$run_rc" -ne 0 ] && has "long.md: grew to 205 lines (baseline 201)"; then
|
|
118
|
+
pass "growing a baselined file is rejected"
|
|
119
|
+
else fail "growing a baselined file is rejected (rc $run_rc: $run_out)"; fi
|
|
120
|
+
|
|
121
|
+
# --- shrinking under the limit passes and nudges ----------------------------------------------
|
|
122
|
+
mk_rule long 150
|
|
123
|
+
capture
|
|
124
|
+
if [ "$run_rc" -eq 0 ] && has "run --update to drop it from the baseline"; then
|
|
125
|
+
pass "a shrunk file passes and nudges a re-baseline"
|
|
126
|
+
else fail "a shrunk file passes and nudges a re-baseline (rc $run_rc: $run_out)"; fi
|
|
127
|
+
run --update >/dev/null
|
|
128
|
+
|
|
129
|
+
# --- the resident total ratchets against the limit --------------------------------------------
|
|
130
|
+
# KIT_INSTRUCTION_BUDGET shrinks the limit so the fixture stays small: resident is 19 + 100 + 1500.
|
|
131
|
+
runb() { ( cd "$TMP" && KIT_INSTRUCTION_BUDGET=1000 bash scripts/instruction-budget-lint.sh "$@" 2>&1 ); }
|
|
132
|
+
run_out="$(runb)"; run_rc=$?
|
|
133
|
+
if [ "$run_rc" -ne 0 ] && has "total 1619 bytes, over the 1000-byte limit"; then
|
|
134
|
+
pass "a resident total over the limit is rejected"
|
|
135
|
+
else fail "a resident total over the limit is rejected (rc $run_rc: $run_out)"; fi
|
|
136
|
+
runb --update >/dev/null
|
|
137
|
+
grep -q '^@resident 1619$' "$TMP/scripts/instruction-budget-baseline.txt" \
|
|
138
|
+
&& pass "--update records the over-limit resident total" \
|
|
139
|
+
|| fail "--update records the over-limit resident total"
|
|
140
|
+
run_out="$(runb)"; run_rc=$?
|
|
141
|
+
[ "$run_rc" -eq 0 ] && pass "a baselined resident total that sits still passes" \
|
|
142
|
+
|| fail "a baselined resident total that sits still passes ($run_out)"
|
|
143
|
+
mk_rule extra 5
|
|
144
|
+
run_out="$(runb)"; run_rc=$?
|
|
145
|
+
if [ "$run_rc" -ne 0 ] && has "grew to 1669 bytes (baseline 1619"; then
|
|
146
|
+
pass "growing a baselined resident total is rejected"
|
|
147
|
+
else fail "growing a baselined resident total is rejected (rc $run_rc: $run_out)"; fi
|
|
148
|
+
# Scoping the new rule takes it back out of the resident set, which is the fix the lint asks for.
|
|
149
|
+
mk_rule extra 5 'app/**'
|
|
150
|
+
run_out="$(runb)"; run_rc=$?
|
|
151
|
+
[ "$run_rc" -eq 0 ] && pass "scoping the new rule with paths: clears the growth" \
|
|
152
|
+
|| fail "scoping the new rule with paths: clears the growth ($run_out)"
|
|
153
|
+
|
|
154
|
+
# --- INSTRUCTION_BUDGET_ROOT measures another directory (how status + doctor call it) ---------
|
|
155
|
+
other="$TMP/other"; mkdir -p "$other"
|
|
156
|
+
printf '%s\n' "12345" > "$other/CLAUDE.md"
|
|
157
|
+
got="$(INSTRUCTION_BUDGET_ROOT="$other" bash "$LINT" --summary 2>&1)"
|
|
158
|
+
case "$got" in
|
|
159
|
+
"instruction files: 6 of 150000 bytes resident (0%); largest: CLAUDE.md (6)") \
|
|
160
|
+
pass "INSTRUCTION_BUDGET_ROOT points the lint at another project" ;;
|
|
161
|
+
*) fail "INSTRUCTION_BUDGET_ROOT points the lint at another project (got: $got)" ;;
|
|
162
|
+
esac
|
|
163
|
+
|
|
164
|
+
echo
|
|
165
|
+
[ "$fails" -eq 0 ] && echo "PASS instruction-budget-lint" || echo "FAILED instruction-budget-lint"
|
|
166
|
+
exit "$fails"
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# instruction-budget-lint.sh — context-budget guardrail for instruction files (kit-owned).
|
|
3
|
+
#
|
|
4
|
+
# WHY: Claude Code loads every CLAUDE.md, and every `.claude/rules/*.md` that has no `paths:`
|
|
5
|
+
# frontmatter, into EVERY session whatever the task. It warns at startup once those files add up
|
|
6
|
+
# past a combined 150k characters; over the limit they still load, and adherence drops. A project
|
|
7
|
+
# grows rules one decision at a time, so the resident set drifts upward with no single commit to
|
|
8
|
+
# blame. skill-frontmatter-lint.sh ratchets the skill LISTING; this is the same drift one level up.
|
|
9
|
+
#
|
|
10
|
+
# WHAT: splits the instruction files into two sets and enforces a RATCHET, not a hard cap.
|
|
11
|
+
#
|
|
12
|
+
# resident CLAUDE.md, CLAUDE.local.md, .claude/CLAUDE.md, and every rule with no `paths:` key
|
|
13
|
+
# path-scoped a rule whose frontmatter declares `paths:` — loaded only once a matching file is read
|
|
14
|
+
#
|
|
15
|
+
# - the resident total may not exceed BUDGET bytes (150000), and
|
|
16
|
+
# - no single instruction file, resident or scoped, may exceed MAX_LINES lines (200).
|
|
17
|
+
#
|
|
18
|
+
# Today's offenders are recorded in a baseline and allowed to stay; nothing may grow past its
|
|
19
|
+
# recorded size and nothing NEW may land over a limit.
|
|
20
|
+
#
|
|
21
|
+
# scripts/instruction-budget-lint.sh lint against the baseline (the gate)
|
|
22
|
+
# scripts/instruction-budget-lint.sh --report every file's cost, both sets; never fails
|
|
23
|
+
# scripts/instruction-budget-lint.sh --summary one line: resident total + three largest
|
|
24
|
+
# scripts/instruction-budget-lint.sh --update rewrite the baseline from current sizes
|
|
25
|
+
# scripts/instruction-budget-lint.sh --baseline-path print the baseline path (init.sh asks for it)
|
|
26
|
+
#
|
|
27
|
+
# Baseline: scripts/instruction-budget-baseline.txt
|
|
28
|
+
# "<path> <lines>" a file over MAX_LINES, grandfathered at that line count
|
|
29
|
+
# "@resident <bytes>" the resident total, present only while it is over BUDGET
|
|
30
|
+
#
|
|
31
|
+
# LIMITS, stated so the number is not over-trusted:
|
|
32
|
+
# - `@path` imports inside a CLAUDE.md are not followed; an imported file is not counted.
|
|
33
|
+
# - CLAUDE.md files in subdirectories and in ~/.claude load too and are not counted — this lint
|
|
34
|
+
# measures what the repo root commits.
|
|
35
|
+
# - `paths:` is detected as a top-level frontmatter key. Its globs are not evaluated.
|
|
36
|
+
#
|
|
37
|
+
# INSTRUCTION_BUDGET_ROOT measures another directory (`cckit status` / `cckit doctor` point the
|
|
38
|
+
# kit's copy at the project they are run in). bash 3.2 compatible.
|
|
39
|
+
set -uo pipefail
|
|
40
|
+
|
|
41
|
+
# Bytes, not characters — same reason as skill-frontmatter-lint.sh: a count that changes with the
|
|
42
|
+
# locale makes a ratchet fire on files nobody touched. Bytes are >= characters, so measuring bytes
|
|
43
|
+
# against a character limit errs toward warning early, never late.
|
|
44
|
+
LC_ALL=C
|
|
45
|
+
export LC_ALL
|
|
46
|
+
|
|
47
|
+
ROOT="${INSTRUCTION_BUDGET_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"
|
|
48
|
+
cd "$ROOT" || { echo "instruction-budget-lint: cannot enter $ROOT" >&2; exit 1; }
|
|
49
|
+
|
|
50
|
+
BASELINE="scripts/instruction-budget-baseline.txt"
|
|
51
|
+
BUDGET="${KIT_INSTRUCTION_BUDGET:-150000}"
|
|
52
|
+
MAX_LINES="${KIT_INSTRUCTION_MAX_LINES:-200}"
|
|
53
|
+
TAB="$(printf '\t')"
|
|
54
|
+
|
|
55
|
+
FAIL=0
|
|
56
|
+
err() { echo "x $1"; FAIL=1; }
|
|
57
|
+
ok() { echo "ok $1"; }
|
|
58
|
+
note() { echo " $1"; }
|
|
59
|
+
|
|
60
|
+
MODE="${1:-lint}"
|
|
61
|
+
|
|
62
|
+
# The one place the baseline filename is spelled; init.sh asks rather than reconstructing it.
|
|
63
|
+
if [ "$MODE" = "--baseline-path" ]; then
|
|
64
|
+
printf '%s\n' "$BASELINE"
|
|
65
|
+
exit 0
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
# has_paths <file> — rc 0 when the file opens with a frontmatter block that has a top-level
|
|
69
|
+
# `paths:` key. Only a block that starts on line 1 counts: Claude Code reads no other.
|
|
70
|
+
has_paths() {
|
|
71
|
+
awk '
|
|
72
|
+
{ sub(/\r$/, "") }
|
|
73
|
+
NR == 1 { if ($0 != "---") exit; next }
|
|
74
|
+
$0 == "---" { exit }
|
|
75
|
+
/^paths[ \t]*:/ { found = 1; exit }
|
|
76
|
+
END { exit found ? 0 : 1 }
|
|
77
|
+
' "$1"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
baseline_for() { # <key> → the recorded number, or empty
|
|
81
|
+
[ -f "$BASELINE" ] || { echo ""; return; }
|
|
82
|
+
grep -v '^[[:space:]]*#' "$BASELINE" 2>/dev/null \
|
|
83
|
+
| awk -v k="$1" '{ n = $NF; sub(/[ \t]+[0-9]+[ \t]*$/, ""); if ($0 == k && !hit) { print n; hit = 1 } }'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# ---- collect ----------------------------------------------------------------
|
|
87
|
+
rows="" # "<bytes>\t<lines>\t<resident|scoped>\t<path>" per line
|
|
88
|
+
resident=0; scoped=0; n_resident=0; n_scoped=0; count=0
|
|
89
|
+
add_file() {
|
|
90
|
+
local f="$1" kind="$2" b l
|
|
91
|
+
b="$(wc -c < "$f" | tr -d ' ')"
|
|
92
|
+
l="$(wc -l < "$f" | tr -d ' ')"
|
|
93
|
+
rows="${rows}${b}${TAB}${l}${TAB}${kind}${TAB}${f}
|
|
94
|
+
"
|
|
95
|
+
count=$(( count + 1 ))
|
|
96
|
+
if [ "$kind" = resident ]; then
|
|
97
|
+
resident=$(( resident + b )); n_resident=$(( n_resident + 1 ))
|
|
98
|
+
else
|
|
99
|
+
scoped=$(( scoped + b )); n_scoped=$(( n_scoped + 1 ))
|
|
100
|
+
fi
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for f in CLAUDE.md CLAUDE.local.md .claude/CLAUDE.md; do
|
|
104
|
+
[ -f "$f" ] && add_file "$f" resident
|
|
105
|
+
done
|
|
106
|
+
if [ -d .claude/rules ]; then
|
|
107
|
+
while IFS= read -r f; do
|
|
108
|
+
[ -n "$f" ] || continue
|
|
109
|
+
if has_paths "$f"; then add_file "$f" scoped; else add_file "$f" resident; fi
|
|
110
|
+
done < <(find .claude/rules -type f -name '*.md' 2>/dev/null | sort)
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
pct=0
|
|
114
|
+
[ "$BUDGET" -gt 0 ] && pct=$(( resident * 100 / BUDGET ))
|
|
115
|
+
|
|
116
|
+
# largest_three — "a (n), b (n), c (n)" over the resident set, the files a trim would start with.
|
|
117
|
+
largest_three() {
|
|
118
|
+
printf '%s' "$rows" | awk -F'\t' '$3 == "resident"' | sort -t"$TAB" -k1,1nr | sed -n 1,3p \
|
|
119
|
+
| awk -F'\t' '{ printf "%s%s (%s)", (NR > 1 ? ", " : ""), $4, $1 }'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# ---- --summary --------------------------------------------------------------
|
|
123
|
+
# One line for `cckit status` and `cckit doctor`. Prints nothing when there is nothing to measure,
|
|
124
|
+
# so a caller can omit the line instead of reporting a zero that reads as a measurement.
|
|
125
|
+
if [ "$MODE" = "--summary" ]; then
|
|
126
|
+
[ "$count" -gt 0 ] || exit 0
|
|
127
|
+
printf 'instruction files: %s of %s bytes resident (%s%%); largest: %s\n' \
|
|
128
|
+
"$resident" "$BUDGET" "$pct" "$(largest_three)"
|
|
129
|
+
exit 0
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
if [ "$count" -eq 0 ]; then
|
|
133
|
+
echo "instruction-budget-lint: no CLAUDE.md and no .claude/rules/ — nothing to lint"
|
|
134
|
+
exit 0
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# ---- --report ---------------------------------------------------------------
|
|
138
|
+
if [ "$MODE" = "--report" ]; then
|
|
139
|
+
for kind in resident scoped; do
|
|
140
|
+
if [ "$kind" = resident ]; then
|
|
141
|
+
echo "resident — loaded into every session"
|
|
142
|
+
else
|
|
143
|
+
echo
|
|
144
|
+
echo "path-scoped — loaded when a file matching \`paths:\` is read"
|
|
145
|
+
fi
|
|
146
|
+
printf '%8s %6s %s\n' bytes lines file
|
|
147
|
+
printf '%s' "$rows" | awk -F'\t' -v k="$kind" '$3 == k' | sort -t"$TAB" -k1,1nr \
|
|
148
|
+
| while IFS="$TAB" read -r b l _k f; do
|
|
149
|
+
flag=""; [ "$l" -gt "$MAX_LINES" ] && flag=" <- over ${MAX_LINES} lines"
|
|
150
|
+
printf '%8s %6s %s%s\n' "$b" "$l" "$f" "$flag"
|
|
151
|
+
done
|
|
152
|
+
done
|
|
153
|
+
echo
|
|
154
|
+
flag=""; [ "$resident" -gt "$BUDGET" ] && flag=" <- over the limit"
|
|
155
|
+
echo "resident total: ${resident} of ${BUDGET} bytes (${pct}%), ${n_resident} file(s)${flag}"
|
|
156
|
+
echo "path-scoped: ${scoped} bytes in ${n_scoped} file(s) — what those rules would add to every session without \`paths:\`"
|
|
157
|
+
echo "largest resident: $(largest_three)"
|
|
158
|
+
exit 0
|
|
159
|
+
fi
|
|
160
|
+
|
|
161
|
+
# ---- --update ---------------------------------------------------------------
|
|
162
|
+
if [ "$MODE" = "--update" ]; then
|
|
163
|
+
mkdir -p "$(dirname "$BASELINE")"
|
|
164
|
+
{
|
|
165
|
+
echo "# instruction-budget-baseline.txt — generated by scripts/instruction-budget-lint.sh --update"
|
|
166
|
+
echo "# Instruction files over ${MAX_LINES} lines, and the resident total while it is over ${BUDGET} bytes."
|
|
167
|
+
echo "# These are GRANDFATHERED: allowed to stay, but may never grow. Shrink them, scope a rule with"
|
|
168
|
+
echo "# \`paths:\`, or split it into a short rule + a knowledge doc, then re-run --update to tighten."
|
|
169
|
+
echo "#"
|
|
170
|
+
echo "# <path> <lines> | @resident <bytes>"
|
|
171
|
+
[ "$resident" -gt "$BUDGET" ] && echo "@resident $resident"
|
|
172
|
+
printf '%s' "$rows" | sort -t"$TAB" -k4,4 | while IFS="$TAB" read -r _b l _k f; do
|
|
173
|
+
[ "$l" -gt "$MAX_LINES" ] && printf '%s %s\n' "$f" "$l"
|
|
174
|
+
done
|
|
175
|
+
} > "$BASELINE"
|
|
176
|
+
echo "ok wrote $BASELINE ($(grep -cv '^[[:space:]]*#' "$BASELINE") grandfathered)"
|
|
177
|
+
exit 0
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
# ---- lint (the gate) --------------------------------------------------------
|
|
181
|
+
over=0
|
|
182
|
+
base="$(baseline_for @resident)"
|
|
183
|
+
if [ "$resident" -gt "$BUDGET" ]; then
|
|
184
|
+
over=$(( over + 1 ))
|
|
185
|
+
if [ -z "$base" ]; then
|
|
186
|
+
err "resident instruction files total ${resident} bytes, over the ${BUDGET}-byte limit"
|
|
187
|
+
note "every byte loads into EVERY session. Give a rule that covers one kind of file a \`paths:\`"
|
|
188
|
+
note "frontmatter, or split a long rule into a short resident half + a knowledge doc."
|
|
189
|
+
note "see what costs most: scripts/instruction-budget-lint.sh --report"
|
|
190
|
+
elif [ "$resident" -gt "$base" ]; then
|
|
191
|
+
err "resident instruction files grew to ${resident} bytes (baseline ${base}, limit ${BUDGET})"
|
|
192
|
+
note "trim back to ${base} or below, or re-baseline deliberately with --update"
|
|
193
|
+
fi
|
|
194
|
+
elif [ -n "$base" ]; then
|
|
195
|
+
note "resident total is now under the limit (${resident}) — run --update to drop @resident from the baseline"
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
while IFS="$TAB" read -r _b l _k f; do
|
|
199
|
+
[ -n "$f" ] || continue
|
|
200
|
+
base="$(baseline_for "$f")"
|
|
201
|
+
if [ "$l" -le "$MAX_LINES" ]; then
|
|
202
|
+
[ -n "$base" ] && note "$f is now ${l} lines — run --update to drop it from the baseline"
|
|
203
|
+
continue
|
|
204
|
+
fi
|
|
205
|
+
over=$(( over + 1 ))
|
|
206
|
+
if [ -z "$base" ]; then
|
|
207
|
+
err "$f: ${l} lines, over the ${MAX_LINES}-line limit for one instruction file"
|
|
208
|
+
note "split it (a short rule that points at a knowledge doc), or accept it deliberately with:"
|
|
209
|
+
note "scripts/instruction-budget-lint.sh --update"
|
|
210
|
+
elif [ "$l" -gt "$base" ]; then
|
|
211
|
+
err "$f: grew to ${l} lines (baseline ${base}) — an over-long instruction file may not grow"
|
|
212
|
+
note "trim it back to ${base} or below, or re-baseline deliberately with --update"
|
|
213
|
+
fi
|
|
214
|
+
done < <(printf '%s' "$rows" | sort -t"$TAB" -k4,4)
|
|
215
|
+
|
|
216
|
+
if [ "$FAIL" -eq 0 ]; then
|
|
217
|
+
ok "instruction files within budget (${resident} of ${BUDGET} bytes resident in ${n_resident} file(s), ${n_scoped} path-scoped; $over grandfathered)"
|
|
218
|
+
fi
|
|
219
|
+
exit "$FAIL"
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# integrations-check-test.sh — covers the monthly recipe check (E303.8):
|
|
4
|
+
# scripts/integrations-check.sh and the shape of .github/workflows/integrations-check.yml. The
|
|
5
|
+
# workflow cannot run before it is merged (`schedule` and `workflow_dispatch` are read from the
|
|
6
|
+
# default branch), so the logic lives in the script and is tested here.
|
|
7
|
+
#
|
|
8
|
+
# Hermetic: every descriptor is a fixture in a throwaway registry whose commands are plain shell
|
|
9
|
+
# writing into a throwaway HOME. The schema's `manager` enum is closed, so fixtures name `npm`, and
|
|
10
|
+
# a no-op `npm` stub leads PATH: the runner only asks whether the manager exists, then runs the
|
|
11
|
+
# descriptor's own command. No shipped descriptor is installed and no package manager runs.
|
|
12
|
+
# Run: bash scripts/integrations-check-test.sh
|
|
13
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
14
|
+
set -u
|
|
15
|
+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
16
|
+
# shellcheck source=/dev/null
|
|
17
|
+
. "$ROOT/scripts/lib/test-env.sh" && test_env_seal
|
|
18
|
+
CHECK="$ROOT/scripts/integrations-check.sh"
|
|
19
|
+
WF="$ROOT/.github/workflows/integrations-check.yml"
|
|
20
|
+
fail=0
|
|
21
|
+
rc() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '$2' want '$3'"; fail=1; fi; }
|
|
22
|
+
has() { if grep -qF -- "$3" <<<"$2"; then echo "ok: $1"; else echo "FAIL: $1 -> '$3' not in: $2"; fail=1; fi; }
|
|
23
|
+
hasnt() { if grep -qF -- "$3" <<<"$2"; then echo "FAIL: $1 -> '$3' found in: $2"; fail=1; else echo "ok: $1"; fi; }
|
|
24
|
+
|
|
25
|
+
command -v jq >/dev/null 2>&1 || { echo "integrations-check-test: jq absent — skipping (dependency-light gate)"; exit 0; }
|
|
26
|
+
|
|
27
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
28
|
+
tmp="$(cd "$tmp" && pwd -P)"
|
|
29
|
+
export HOME="$tmp/home"; mkdir -p "$HOME"
|
|
30
|
+
fx="$tmp/integrations"; mkdir -p "$fx"
|
|
31
|
+
cp "$ROOT/integrations/integration.schema.json" "$fx/"
|
|
32
|
+
export KIT_INTEGRATIONS_DIR="$fx"
|
|
33
|
+
mkdir -p "$tmp/stubs"; printf '#!/bin/sh\nexit 0\n' > "$tmp/stubs/npm"; chmod +x "$tmp/stubs/npm"
|
|
34
|
+
export PATH="$tmp/stubs:$PATH"
|
|
35
|
+
# A platform this machine is not, from the schema's closed `os` enum.
|
|
36
|
+
other_os="Linux"; [ "$(uname -s)" = "Linux" ] && other_os="Darwin"
|
|
37
|
+
|
|
38
|
+
# fixture <id> <install-command> <verify-command> [extra top-level JSON members]
|
|
39
|
+
# The tool is a script at ~/.local/bin/<id>-bin: off PATH, where the runner looks for it.
|
|
40
|
+
fixture() {
|
|
41
|
+
cat > "$fx/$1.json" <<JSON
|
|
42
|
+
{
|
|
43
|
+
"id": "$1",
|
|
44
|
+
"label": "$1",
|
|
45
|
+
"summary": "A tool that exists only in this test.",
|
|
46
|
+
"config": { "key": "fixtureKind.provider", "value": "$1" },
|
|
47
|
+
"detect": { "run": "$1-bin --version" },
|
|
48
|
+
"install": [ { "manager": "npm", "run": "$2" } ],
|
|
49
|
+
"verify": { "run": "$3" },
|
|
50
|
+
${4:-}
|
|
51
|
+
"docs": "https://example.com/$1",
|
|
52
|
+
"attribution": { "author": "Nobody", "homepage": "https://example.com/$1", "affiliated": false, "notice": "A test fixture." }
|
|
53
|
+
}
|
|
54
|
+
JSON
|
|
55
|
+
}
|
|
56
|
+
# The install command a working recipe uses: drop an executable that exits 0.
|
|
57
|
+
good_install() { printf "mkdir -p \$HOME/.local/bin && printf '#!/bin/sh\\\\nexit 0\\\\n' > \$HOME/.local/bin/%s-bin && chmod +x \$HOME/.local/bin/%s-bin" "$1" "$1"; }
|
|
58
|
+
reset() { rm -rf "$HOME/.local" "$fx"/*.json; cp "$ROOT/integrations/integration.schema.json" "$fx/"; }
|
|
59
|
+
|
|
60
|
+
# ── a healthy descriptor ───────────────────────────────────────────────────────────────────────
|
|
61
|
+
fixture healthy "$(good_install healthy)" "healthy-bin --version"
|
|
62
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
63
|
+
rc "healthy: exit 0" "$r" 0
|
|
64
|
+
has "healthy: validate reported" "$out" "ok healthy: validate"
|
|
65
|
+
has "healthy: install reported with its manager" "$out" "ok healthy: install: npm"
|
|
66
|
+
has "healthy: detect reported" "$out" "ok healthy: detect: healthy-bin --version"
|
|
67
|
+
has "healthy: verify reported" "$out" "ok healthy: verify: healthy-bin --version"
|
|
68
|
+
has "healthy: count line" "$out" "integrations-check: 1 checked, 0 failed, 0 skipped"
|
|
69
|
+
hasnt "healthy: no FAIL line" "$out" "FAIL"
|
|
70
|
+
|
|
71
|
+
# The tool is now on the machine: a second run says the install recipe went unexercised.
|
|
72
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
73
|
+
rc "already present: exit 0" "$r" 0
|
|
74
|
+
has "already present: says the install recipe was not exercised" "$out" "skip healthy: install: already on this machine"
|
|
75
|
+
has "already present: verify still runs" "$out" "ok healthy: verify"
|
|
76
|
+
|
|
77
|
+
# ── an install command broken on purpose ───────────────────────────────────────────────────────
|
|
78
|
+
reset
|
|
79
|
+
fixture healthy "$(good_install healthy)" "healthy-bin --version"
|
|
80
|
+
fixture broken-install "exit 3" "broken-install-bin --version"
|
|
81
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
82
|
+
rc "broken install: exit non-zero" "$r" 1
|
|
83
|
+
has "broken install: names the descriptor and the step" "$out" "FAIL broken-install: install:"
|
|
84
|
+
has "broken install: carries the runner's evidence" "$out" "integration broken-install: npm failed"
|
|
85
|
+
has "broken install: the healthy descriptor beside it still passes" "$out" "ok healthy: verify"
|
|
86
|
+
has "broken install: count line" "$out" "integrations-check: 2 checked, 1 failed, 0 skipped"
|
|
87
|
+
hasnt "broken install: later steps do not run" "$out" "broken-install: verify"
|
|
88
|
+
|
|
89
|
+
# An installer that exits 0 and installs nothing is the same failure, not a pass.
|
|
90
|
+
reset
|
|
91
|
+
fixture lying-install "true" "lying-install-bin --version"
|
|
92
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
93
|
+
rc "lying install: exit non-zero" "$r" 1
|
|
94
|
+
has "lying install: named at the install step" "$out" "FAIL lying-install: install:"
|
|
95
|
+
|
|
96
|
+
# ── verify broken, install fine ────────────────────────────────────────────────────────────────
|
|
97
|
+
reset
|
|
98
|
+
fixture broken-verify "$(good_install broken-verify)" "echo flag-was-renamed >&2; exit 2"
|
|
99
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
100
|
+
rc "broken verify: exit non-zero" "$r" 1
|
|
101
|
+
has "broken verify: install passed first" "$out" "ok broken-verify: install: npm"
|
|
102
|
+
has "broken verify: names the descriptor and the step" "$out" "FAIL broken-verify: verify:"
|
|
103
|
+
has "broken verify: carries the command's output" "$out" "flag-was-renamed"
|
|
104
|
+
|
|
105
|
+
# ── wire ───────────────────────────────────────────────────────────────────────────────────────
|
|
106
|
+
reset
|
|
107
|
+
fixture wired "$(good_install wired)" "wired-bin --version" \
|
|
108
|
+
'"wire": { "run": "touch wired-here", "declined": { "--": "ends the flags, so the next one is a file name", "also-wired": "a second file" } },'
|
|
109
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
110
|
+
rc "wire: exit 0" "$r" 0
|
|
111
|
+
has "wire: reported with the declined flags rendered" "$out" "ok wired: wire: touch wired-here -- also-wired"
|
|
112
|
+
r=0; { [ -e "$ROOT/wired-here" ] || [ -e "$PWD/wired-here" ]; } && r=1
|
|
113
|
+
rc "wire: ran in the scratch repo, not here" "$r" 0
|
|
114
|
+
|
|
115
|
+
reset
|
|
116
|
+
fixture broken-wire "$(good_install broken-wire)" "broken-wire-bin --version" '"wire": { "run": "exit 4" },'
|
|
117
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
118
|
+
rc "broken wire: exit non-zero" "$r" 1
|
|
119
|
+
has "broken wire: names the descriptor and the step" "$out" "FAIL broken-wire: wire:"
|
|
120
|
+
|
|
121
|
+
# ── a descriptor that fails the schema ─────────────────────────────────────────────────────────
|
|
122
|
+
reset
|
|
123
|
+
printf '{ "id": "bad-shape", "label": "x" }\n' > "$fx/bad-shape.json"
|
|
124
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
125
|
+
rc "invalid descriptor: exit non-zero" "$r" 1
|
|
126
|
+
has "invalid descriptor: named at the validate step" "$out" "FAIL bad-shape: validate:"
|
|
127
|
+
has "invalid descriptor: names the missing field" "$out" "detect: required field is missing"
|
|
128
|
+
|
|
129
|
+
# ── platform: a mismatch is a skip, never a failure ────────────────────────────────────────────
|
|
130
|
+
reset
|
|
131
|
+
fixture other-machine "exit 3" "false" "\"appliesWhen\": { \"platform\": { \"os\": \"$other_os\" } },"
|
|
132
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
133
|
+
rc "platform mismatch: exit 0" "$r" 0
|
|
134
|
+
has "platform mismatch: skipped, with what it needs" "$out" "skip other-machine: platform: needs a $other_os machine"
|
|
135
|
+
has "platform mismatch: counted as skipped" "$out" "1 checked, 0 failed, 1 skipped"
|
|
136
|
+
|
|
137
|
+
# An extension predicate judges a repo, and no repo is under test: the recipe still runs.
|
|
138
|
+
reset
|
|
139
|
+
fixture needs-ext "$(good_install needs-ext)" "needs-ext-bin --version" '"appliesWhen": { "anyExtension": [".zzz"] },'
|
|
140
|
+
out="$(bash "$CHECK" --yes 2>/dev/null)"; r=$?
|
|
141
|
+
rc "extension predicate: exit 0" "$r" 0
|
|
142
|
+
has "extension predicate: the recipe ran" "$out" "ok needs-ext: install: npm"
|
|
143
|
+
|
|
144
|
+
# ── without --yes nothing installs ─────────────────────────────────────────────────────────────
|
|
145
|
+
reset
|
|
146
|
+
fixture healthy "$(good_install healthy)" "healthy-bin --version"
|
|
147
|
+
fixture broken-install "exit 3" "broken-install-bin --version"
|
|
148
|
+
out="$(bash "$CHECK" 2>/dev/null)"; r=$?
|
|
149
|
+
rc "plan only: exit 0 even beside a broken recipe" "$r" 0
|
|
150
|
+
has "plan only: prints the candidate" "$out" "1. exit 3"
|
|
151
|
+
has "plan only: says how to run it" "$out" "skip healthy: install: plan only — pass --yes to run it"
|
|
152
|
+
r=0; [ -e "$HOME/.local/bin/healthy-bin" ] && r=1
|
|
153
|
+
rc "plan only: nothing was installed" "$r" 0
|
|
154
|
+
|
|
155
|
+
# ── arguments ──────────────────────────────────────────────────────────────────────────────────
|
|
156
|
+
out="$(bash "$CHECK" --yes healthy 2>/dev/null)"; r=$?
|
|
157
|
+
rc "one id: exit 0, the broken descriptor is not run" "$r" 0
|
|
158
|
+
has "one id: only that descriptor is counted" "$out" "integrations-check: 1 checked, 0 failed, 0 skipped"
|
|
159
|
+
out="$(bash "$CHECK" --yes no-such-tool 2>/dev/null)"; r=$?
|
|
160
|
+
rc "unknown id: exit non-zero" "$r" 1
|
|
161
|
+
has "unknown id: named" "$out" "FAIL no-such-tool: validate: no descriptor with that id"
|
|
162
|
+
bash "$CHECK" --bogus >/dev/null 2>&1; rc "unknown flag: usage error" "$?" 2
|
|
163
|
+
|
|
164
|
+
# An inherited state dir must not receive this run's consent.
|
|
165
|
+
reset
|
|
166
|
+
fixture healthy "$(good_install healthy)" "healthy-bin --version"
|
|
167
|
+
KIT_STATE_DIR="$tmp/real-project-state" bash "$CHECK" --yes >/dev/null 2>&1
|
|
168
|
+
r=0; [ -e "$tmp/real-project-state" ] && r=1
|
|
169
|
+
rc "consent: never written to an inherited KIT_STATE_DIR" "$r" 0
|
|
170
|
+
|
|
171
|
+
# ── every shipped descriptor has what the check runs ───────────────────────────────────────────
|
|
172
|
+
unset KIT_INTEGRATIONS_DIR
|
|
173
|
+
for f in "$ROOT"/integrations/*.json; do
|
|
174
|
+
[ "$(basename "$f")" = "integration.schema.json" ] && continue
|
|
175
|
+
jq -e '(.detect.run | type == "string") and (.verify.run | type == "string") and (.install | length > 0)' "$f" >/dev/null 2>&1
|
|
176
|
+
rc "shipped $(basename "$f" .json): has detect, install and verify commands" "$?" 0
|
|
177
|
+
done
|
|
178
|
+
out="$(HOME="$tmp/home" bash "$CHECK" 2>/dev/null)"; r=$?
|
|
179
|
+
rc "shipped descriptors: the plan-only run exits 0" "$r" 0
|
|
180
|
+
hasnt "shipped descriptors: none fails validation" "$out" "FAIL"
|
|
181
|
+
|
|
182
|
+
# ── the workflow ───────────────────────────────────────────────────────────────────────────────
|
|
183
|
+
wf="$(cat "$WF" 2>/dev/null)"
|
|
184
|
+
has "workflow: schedule trigger" "$wf" "schedule:"
|
|
185
|
+
grep -qE '^[[:space:]]*- cron: "[0-9]+ [0-9]+ [0-9]+ \* \*"' <<<"$wf"; rc "workflow: the cron is monthly (fixed day of month, every month)" "$?" 0
|
|
186
|
+
has "workflow: manual trigger" "$wf" "workflow_dispatch:"
|
|
187
|
+
has "workflow: may write issues" "$wf" "issues: write"
|
|
188
|
+
has "workflow: an arm64 macOS runner for mlx-lm" "$wf" "macos-15"
|
|
189
|
+
has "workflow: runs the check for real" "$wf" "bash scripts/integrations-check.sh --yes"
|
|
190
|
+
has "workflow: the issue step runs only on failure" "$wf" "if: failure()"
|
|
191
|
+
has "workflow: opens an issue" "$wf" "gh issue create"
|
|
192
|
+
if command -v ruby >/dev/null 2>&1; then
|
|
193
|
+
ruby -ryaml -e 'y = YAML.load_file(ARGV[0]); t = y["on"] || y[true]; exit(t.key?("schedule") && t.key?("workflow_dispatch") && y["permissions"]["issues"] == "write" && y["jobs"]["check"]["strategy"]["matrix"]["os"].include?("macos-15") ? 0 : 1)' "$WF" 2>/dev/null
|
|
194
|
+
rc "workflow: the YAML parses and holds the triggers, permission and runner" "$?" 0
|
|
195
|
+
else
|
|
196
|
+
echo "ok: workflow YAML parse — ruby absent, skipped"
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
if [ "$fail" -eq 0 ]; then echo "PASS integrations-check-test"; else echo "FAIL integrations-check-test"; fi
|
|
200
|
+
exit "$fail"
|