@jeiemgi/cckit 0.5.0 → 0.7.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 (144) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +34 -3
  3. package/README.md +95 -6
  4. package/bin/cckit +90 -3
  5. package/cckit.config.json +7 -2
  6. package/kit.config.schema.json +26 -1
  7. package/package.json +1 -1
  8. package/profiles/automation.json +2 -1
  9. package/profiles/content.json +2 -1
  10. package/profiles/minimal.json +2 -1
  11. package/profiles/research.json +2 -1
  12. package/profiles/software.json +2 -1
  13. package/scripts/benchmark/benchmark-test.sh +83 -0
  14. package/scripts/benchmark/gate.sh +55 -0
  15. package/scripts/benchmark/lib/bench-common.sh +70 -0
  16. package/scripts/benchmark/lib/model.sh +116 -0
  17. package/scripts/benchmark/report.sh +105 -0
  18. package/scripts/benchmark/run-quality.sh +102 -0
  19. package/scripts/benchmark/run.sh +166 -0
  20. package/scripts/benchmark/stop-check.sh +83 -0
  21. package/scripts/commitlint-test.sh +58 -0
  22. package/scripts/init.sh +57 -1
  23. package/scripts/kit-self-update.sh +55 -0
  24. package/scripts/lib/board-view-test.sh +1 -0
  25. package/scripts/lib/board-view.sh +1 -0
  26. package/scripts/lib/captain-test.sh +62 -0
  27. package/scripts/lib/captain.sh +105 -17
  28. package/scripts/lib/cckit-output.sh +1 -0
  29. package/scripts/lib/commitlint.sh +54 -0
  30. package/scripts/lib/config-path-test.sh +1 -0
  31. package/scripts/lib/config-path.sh +1 -0
  32. package/scripts/lib/copilot-test.sh +1 -0
  33. package/scripts/lib/copilot.sh +1 -0
  34. package/scripts/lib/effort-dispatch-test.sh +10 -0
  35. package/scripts/lib/effort-flows-test.sh +1 -0
  36. package/scripts/lib/effort-metrics-test.sh +1 -0
  37. package/scripts/lib/effort-metrics.sh +1 -0
  38. package/scripts/lib/effort-ops-test.sh +360 -0
  39. package/scripts/lib/effort-ops.sh +372 -16
  40. package/scripts/lib/effort-parity-test.sh +1 -0
  41. package/scripts/lib/effort-plan.sh +1 -0
  42. package/scripts/lib/effort-slug-test.sh +32 -0
  43. package/scripts/lib/effort-slug.sh +72 -8
  44. package/scripts/lib/effort.sh +1 -0
  45. package/scripts/lib/engine-adapter.sh +1 -0
  46. package/scripts/lib/errors-header-test.sh +86 -0
  47. package/scripts/lib/gh-log.sh +1 -0
  48. package/scripts/lib/gh-project-test.sh +1 -0
  49. package/scripts/lib/gh-project.sh +1 -0
  50. package/scripts/lib/git-remote-test.sh +1 -0
  51. package/scripts/lib/git-remote.sh +1 -0
  52. package/scripts/lib/handoff.sh +23 -2
  53. package/scripts/lib/kit-brief-test.sh +292 -0
  54. package/scripts/lib/kit-brief.sh +376 -0
  55. package/scripts/lib/kit-cli-test.sh +1 -0
  56. package/scripts/lib/kit-cli.sh +1 -0
  57. package/scripts/lib/kit-config-resolve.sh +1 -0
  58. package/scripts/lib/kit-config-test.sh +14 -0
  59. package/scripts/lib/kit-config.sh +7 -0
  60. package/scripts/lib/kit-engine-test.sh +1 -0
  61. package/scripts/lib/kit-events.sh +1 -0
  62. package/scripts/lib/kit-gc-test.sh +125 -0
  63. package/scripts/lib/kit-gc.sh +193 -5
  64. package/scripts/lib/kit-interview-test.sh +1 -0
  65. package/scripts/lib/kit-interview.sh +1 -0
  66. package/scripts/lib/kit-lib-test.sh +226 -0
  67. package/scripts/lib/kit-lib.sh +308 -0
  68. package/scripts/lib/kit-local.sh +1 -0
  69. package/scripts/lib/kit-manifest.sh +1 -0
  70. package/scripts/lib/kit-mode-test.sh +1 -0
  71. package/scripts/lib/kit-mode.sh +1 -0
  72. package/scripts/lib/kit-msg-test.sh +1 -0
  73. package/scripts/lib/kit-msg.sh +1 -0
  74. package/scripts/lib/kit-operate.sh +1 -0
  75. package/scripts/lib/kit-profile-test.sh +1 -0
  76. package/scripts/lib/kit-profile.sh +1 -0
  77. package/scripts/lib/kit-state-test.sh +89 -0
  78. package/scripts/lib/kit-state.sh +61 -0
  79. package/scripts/lib/kit-status-test.sh +233 -0
  80. package/scripts/lib/kit-status.sh +415 -0
  81. package/scripts/lib/kit-task-ops-test.sh +22 -0
  82. package/scripts/lib/kit-task-ops.sh +51 -2
  83. package/scripts/lib/next.sh +1 -0
  84. package/scripts/lib/plan-machine-test.sh +54 -0
  85. package/scripts/lib/plan-machine.sh +86 -25
  86. package/scripts/lib/plan-next-test.sh +1 -0
  87. package/scripts/lib/plan-next.sh +1 -0
  88. package/scripts/lib/pr-evidence-test.sh +259 -0
  89. package/scripts/lib/pr-evidence.sh +220 -35
  90. package/scripts/lib/project-scan.sh +1 -0
  91. package/scripts/lib/react-detect.sh +1 -0
  92. package/scripts/lib/render-test.sh +1 -0
  93. package/scripts/lib/render.sh +1 -0
  94. package/scripts/lib/role-identity.sh +1 -0
  95. package/scripts/lib/secret-guard.sh +21 -1
  96. package/scripts/lib/toon.sh +1 -0
  97. package/scripts/lib/ui.sh +1 -0
  98. package/scripts/lib/version-bump-test.sh +1 -0
  99. package/scripts/lib/version-bump.sh +1 -0
  100. package/scripts/lib/worktree-bootstrap-test.sh +220 -0
  101. package/scripts/lib/worktree-issue-test.sh +15 -1
  102. package/scripts/lib/worktree-issue.sh +23 -8
  103. package/scripts/lib/worktree-start.sh +191 -7
  104. package/scripts/lib/zsh-safety-test.sh +10 -0
  105. package/scripts/orchestrate.sh +8 -1
  106. package/scripts/portable-test.sh +13 -2
  107. package/scripts/self-install-test.sh +282 -0
  108. package/scripts/setup-labels.sh +1 -0
  109. package/scripts/status.sh +68 -40
  110. package/scripts/task-sync.sh +13 -0
  111. package/scripts/ux-a11y-scan.sh +96 -0
  112. package/scripts/ux-ds-audit.sh +146 -0
  113. package/scripts/ux-graph-scan.sh +188 -0
  114. package/skills/kit-autopilot/SKILL.md +6 -1
  115. package/skills/kit-cleanup/SKILL.md +83 -0
  116. package/skills/kit-effort-close/SKILL.md +3 -0
  117. package/skills/kit-effort-new/SKILL.md +7 -0
  118. package/skills/kit-effort-start/SKILL.md +39 -4
  119. package/skills/kit-gc/SKILL.md +19 -0
  120. package/skills/kit-next/SKILL.md +5 -0
  121. package/skills/kit-status/SKILL.md +92 -0
  122. package/skills/kit-task-start/SKILL.md +7 -1
  123. package/skills/kit-ux-audit/SKILL.md +241 -0
  124. package/skills/kit-ux-audit/references/a11y.md +79 -0
  125. package/skills/kit-ux-audit/references/consistency.md +106 -0
  126. package/skills/kit-ux-audit/references/graph-model.md +92 -0
  127. package/skills/kit-ux-audit/references/heuristics.md +157 -0
  128. package/skills/kit-ux-audit/references/report.md +172 -0
  129. package/templates/agents/ux.md +89 -0
  130. package/templates/benchmarks/SCHEMA.md +75 -0
  131. package/templates/benchmarks/abstain.jsonl +8 -0
  132. package/templates/benchmarks/adversarial.jsonl +8 -0
  133. package/templates/benchmarks/benchmark.config.json +14 -0
  134. package/templates/benchmarks/quality.jsonl +8 -0
  135. package/templates/benchmarks/retrieval.jsonl +7 -0
  136. package/templates/rules/branch-naming.md +20 -1
  137. package/templates/rules/communication-style.md +8 -0
  138. package/templates/rules/delegation-brief.md +38 -4
  139. package/templates/rules/effort-model.md +47 -4
  140. package/templates/rules/naming-and-ids.md +199 -0
  141. package/templates/rules/task-management.md +1 -1
  142. package/templates/settings/settings.json.tmpl +9 -0
  143. package/templates/skills/concrete/SKILL.md +117 -0
  144. package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ # benchmark/stop-check.sh — the Stop=Both predicate for objective autopilot mode.
3
+ #
4
+ # cckit autopilot objective mode drives a capped `/loop --until '<check>'` that grows + hardens the
5
+ # benchmark sets each round. This is that `<check>`: it exits 0 (loop is done) ONLY when BOTH
6
+ # conditions hold at once —
7
+ # (A) SIZE: the suite has reached its record-count target (config target.minRecords), AND
8
+ # (B) CLEAN: the no-mistakes gate (gate.sh) has passed target.cleanRounds rounds in a row.
9
+ #
10
+ # It runs the gate itself and tracks the clean streak in benchmarks/.stop-state.json, so the loop
11
+ # can't stop on a round that grew the suite but broke it. A broken round resets the streak to 0.
12
+ #
13
+ # Usage: benchmark/stop-check.sh [--dir <benchmarks>] [--min N] [--rounds K] [--json]
14
+ # Exit 0 = stop (both met); non-zero = keep looping.
15
+ set -uo pipefail
16
+
17
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
18
+ # shellcheck source=/dev/null
19
+ . "$SCRIPT_DIR/lib/bench-common.sh"
20
+
21
+ JSON=0; MIN=""; ROUNDS=""
22
+ DIRFLAG=()
23
+ while [ "$#" -gt 0 ]; do
24
+ case "$1" in
25
+ --dir) BENCH_DIR="$2"; export BENCH_DIR; DIRFLAG=(--dir "$2"); shift 2 ;;
26
+ --dir=*) BENCH_DIR="${1#*=}"; export BENCH_DIR; DIRFLAG=(--dir "${1#*=}"); shift ;;
27
+ --min) MIN="$2"; shift 2 ;;
28
+ --min=*) MIN="${1#*=}"; shift ;;
29
+ --rounds) ROUNDS="$2"; shift 2 ;;
30
+ --rounds=*) ROUNDS="${1#*=}"; shift ;;
31
+ --json|--llm) JSON=1; shift ;;
32
+ -h|--help) sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
33
+ *) echo "stop-check.sh: unknown arg '$1'" >&2; exit 2 ;;
34
+ esac
35
+ done
36
+
37
+ command -v jq >/dev/null 2>&1 || { echo "stop-check.sh: jq is required" >&2; exit 2; }
38
+
39
+ DIR="$(bench_dir)"
40
+ CFG="$(bench_config)"
41
+ STATE="$DIR/.stop-state.json"
42
+
43
+ # Targets: flags win, else config, else conservative defaults.
44
+ [ -n "$MIN" ] || MIN="$( [ -n "$CFG" ] && jq -r '.target.minRecords // empty' "$CFG" 2>/dev/null)"
45
+ [ -n "$ROUNDS" ] || ROUNDS="$([ -n "$CFG" ] && jq -r '.target.cleanRounds // empty' "$CFG" 2>/dev/null)"
46
+ [ -n "$MIN" ] || MIN=12
47
+ [ -n "$ROUNDS" ] || ROUNDS=2
48
+
49
+ # (A) SIZE — total records across every set (dry-count via run.sh gives retrieval/abstain; add
50
+ # quality). Reuse the runners' --dry --json totals so the count matches exactly what ships.
51
+ ret_n="$(bash "$SCRIPT_DIR/run.sh" --dry --json "${DIRFLAG[@]+"${DIRFLAG[@]}"}" 2>/dev/null | jq -r '.total // 0')"
52
+ qual_n="$(bash "$SCRIPT_DIR/run-quality.sh" --dry --json "${DIRFLAG[@]+"${DIRFLAG[@]}"}" 2>/dev/null | jq -r '.count // 0')"
53
+ [ -n "$ret_n" ] || ret_n=0
54
+ [ -n "$qual_n" ] || qual_n=0
55
+ TOTAL=$((ret_n + qual_n))
56
+ size_ok=0; [ "$TOTAL" -ge "$MIN" ] && size_ok=1
57
+
58
+ # (B) CLEAN — run the gate this round; update the streak.
59
+ streak=0
60
+ [ -f "$STATE" ] && streak="$(jq -r '.clean_streak // 0' "$STATE" 2>/dev/null || echo 0)"
61
+ if bash "$SCRIPT_DIR/gate.sh" "${DIRFLAG[@]+"${DIRFLAG[@]}"}" >/dev/null 2>&1; then
62
+ streak=$((streak + 1))
63
+ else
64
+ streak=0 # a broken round resets the streak — cannot stop on it
65
+ fi
66
+ jq -n --argjson s "$streak" '{clean_streak:$s}' > "$STATE" 2>/dev/null || true
67
+ clean_ok=0; [ "$streak" -ge "$ROUNDS" ] && clean_ok=1
68
+
69
+ STOP=0; [ "$size_ok" -eq 1 ] && [ "$clean_ok" -eq 1 ] && STOP=1
70
+
71
+ if [ "$JSON" -eq 1 ]; then
72
+ jq -n --argjson total "$TOTAL" --argjson min "$MIN" --argjson streak "$streak" \
73
+ --argjson rounds "$ROUNDS" --argjson size "$size_ok" --argjson clean "$clean_ok" \
74
+ --argjson stop "$STOP" \
75
+ '{records:$total, min:$min, size_ok:($size==1), clean_streak:$streak, rounds:$rounds, clean_ok:($clean==1), stop:($stop==1)}'
76
+ else
77
+ printf 'stop-check: records %s/%s (%s) · clean streak %s/%s (%s) -> %s\n' \
78
+ "$TOTAL" "$MIN" "$([ "$size_ok" -eq 1 ] && echo met || echo below)" \
79
+ "$streak" "$ROUNDS" "$([ "$clean_ok" -eq 1 ] && echo met || echo short)" \
80
+ "$([ "$STOP" -eq 1 ] && echo STOP || echo CONTINUE)"
81
+ fi
82
+
83
+ [ "$STOP" -eq 1 ] && exit 0 || exit 1
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ # commitlint-test.sh — the PR-title Conventional Commits gate (scripts/lib/commitlint.sh).
3
+ # Hermetic, no network. Discovered by scripts/test.sh, folded into scripts/check.sh + CI.
4
+ set -u
5
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6
+ fail=0
7
+ # shellcheck source=/dev/null
8
+ . "$ROOT/scripts/lib/commitlint.sh"
9
+
10
+ ok() { if commitlint_check "$1" >/dev/null 2>&1; then echo "ok: accept '$1'"; else echo "FAIL: should ACCEPT '$1'"; fail=1; fi; }
11
+ bad() { if commitlint_check "$1" >/dev/null 2>&1; then echo "FAIL: should REJECT '$1'"; fail=1; else echo "ok: reject '$1'"; fi; }
12
+
13
+ # --- valid subjects (every version-bump level + non-functional types) ---
14
+ ok "feat: add a thing"
15
+ ok "fix: correct a bug"
16
+ ok "feat(orchestrate): headless launch"
17
+ ok "fix(config): base feature work on develop"
18
+ ok "feat!: drop the old flag"
19
+ ok "feat(api)!: rename the export"
20
+ ok "perf: speed up the scan"
21
+ ok "refactor: extract a helper"
22
+ ok "revert: undo the change"
23
+ ok "docs: update releasing.mdx"
24
+ ok "chore: bump deps"
25
+ ok "chore(main): release 1.2.3" # release-please's own Release PR title
26
+ ok "ci: pin the runner"
27
+ ok "build: adjust the bundle"
28
+ ok "style: reformat"
29
+ ok "test: add coverage"
30
+ ok "fix(scope-with-dash): ok"
31
+ ok "feat(docs-site): scoped slash allowed"
32
+
33
+ # --- invalid subjects ---
34
+ bad "add a thing" # no type
35
+ bad "Feat: capitalized type" # type must be lowercase
36
+ bad "feat add a thing" # missing colon
37
+ bad "feat:no space after colon" # missing space
38
+ bad "feat: " # empty description
39
+ bad "feat:" # empty description, no space
40
+ bad "wip: not a conventional type" # unknown type
41
+ bad "feature: not the short form" # unknown type
42
+ bad "feat(): empty scope" # scope cannot be empty
43
+ bad "" # empty subject
44
+
45
+ # --- CLI form works and mirrors the function ---
46
+ if bash "$ROOT/scripts/lib/commitlint.sh" "feat: via cli" >/dev/null 2>&1; then
47
+ echo "ok: CLI accepts a valid subject"
48
+ else
49
+ echo "FAIL: CLI should accept a valid subject"; fail=1
50
+ fi
51
+ if bash "$ROOT/scripts/lib/commitlint.sh" "nope" >/dev/null 2>&1; then
52
+ echo "FAIL: CLI should reject an invalid subject"; fail=1
53
+ else
54
+ echo "ok: CLI rejects an invalid subject"
55
+ fi
56
+
57
+ [ "$fail" -eq 0 ] && echo "ALL OK (commitlint)" || echo "commitlint: FAILURES"
58
+ exit "$fail"
package/scripts/init.sh CHANGED
@@ -367,6 +367,33 @@ if [[ -z "$GH_OWNER" ]]; then GH_OWNER="$(gh api user --jq .login 2>/dev/null ||
367
367
  [[ -z "$REPO" && -n "$GH_OWNER" ]] && REPO="$GH_OWNER/$SLUG"
368
368
  [[ -z "$REPO" ]] && REPO="$SLUG"
369
369
 
370
+ # ---- base branch ---------------------------------------------------------
371
+ # Rules that name the integration branch are TEMPLATED on it ({{BASE_BRANCH}}), so a project that
372
+ # integrates on `develop` does not scaffold a rule telling agents to branch from `main` (#283).
373
+ # Resolved the same way the rest of the kit resolves it (kit-config.sh: baseBranch -> integrationBranch
374
+ # -> flow -> "main"), then WRITTEN into the generated config below — a rendered rule that disagrees
375
+ # with KIT_BASE_BRANCH is the bug this parameterization exists to remove.
376
+ # 1. KIT_BASE_BRANCH from the environment (an explicit caller override)
377
+ # 2. the project's existing config, found by kit_config_path (re-init / --upgrade keeps the
378
+ # project's choice) — the ONE resolver, so this honors $KIT_CONFIG and finds a config in an
379
+ # ancestor directory. Hand-checking two TARGET-local filenames skipped both.
380
+ # 3. the repo's actual GitHub default branch (same source as REPO/GH_OWNER above)
381
+ # 4. "main"
382
+ # Unconditional, not `[[ -z ${BASE_BRANCH:-} ]]`: KIT_BASE_BRANCH is the DOCUMENTED override, and
383
+ # BASE_BRANCH is an internal name this script exports for `emit` — an inherited BASE_BRANCH from a
384
+ # caller's environment must not silently outrank it.
385
+ BASE_BRANCH="${KIT_BASE_BRANCH:-}"
386
+ if [[ -z "$BASE_BRANCH" ]]; then
387
+ # shellcheck source=/dev/null
388
+ . "$KIT_ROOT/scripts/lib/config-path.sh"
389
+ _bb_cfg="$(kit_config_path "$TARGET" 2>/dev/null || true)"
390
+ if [[ -n "$_bb_cfg" && -f "$_bb_cfg" ]]; then
391
+ BASE_BRANCH="$(jq -r '.github.baseBranch // .github.integrationBranch // .github.flow // empty' "$_bb_cfg" 2>/dev/null || true)"
392
+ fi
393
+ fi
394
+ [[ -z "$BASE_BRANCH" ]] && BASE_BRANCH="$(cd "$TARGET" 2>/dev/null && gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || true)"
395
+ [[ -z "$BASE_BRANCH" ]] && BASE_BRANCH="main"
396
+
370
397
  # profile defaults
371
398
  [[ -z "$PLANS_FORMAT" ]] && PLANS_FORMAT="$(jq -r '.defaults.plans_format' "$PROFILE_FILE")"
372
399
  [[ -z "$MEMORY" ]] && MEMORY="$(jq -r '.defaults.memory' "$PROFILE_FILE")"
@@ -465,6 +492,7 @@ done
465
492
  # ---- export vars for substitution ---------------------------------------
466
493
  export PROJECT_NAME="$NAME" PROJECT_SLUG="$SLUG" OWNER_NAME="$OWNER_NAME" COMMS_LANG="$LANG_PREF"
467
494
  export PROFILE GH_REPO="$REPO" GH_OWNER="$GH_OWNER" PROJECT_NUMBER PROJECT_BOARD_TITLE="$NAME"
495
+ export BASE_BRANCH
468
496
  export PLANS_DIR PLANS_FORMAT KNOWLEDGE_DIR="knowledge" WING="$SLUG" CLAUDE_PROJECT_SLUG
469
497
  export MILESTONES_HUMAN ROLES_HUMAN AGENT_TABLE SKILL_TABLE
470
498
  export KIT_FLAGS_ON="$FLAGS_ON"
@@ -538,6 +566,7 @@ if [[ $DRY_RUN -eq 1 ]]; then
538
566
  echo " Profile : $PROFILE"
539
567
  echo " Project : $NAME ($SLUG)"
540
568
  echo " Repo : $REPO"
569
+ echo " Base : $BASE_BRANCH (rules that name the integration branch render this)"
541
570
  echo " Board : $([[ "$PROJECTS_V2" == "true" ]] && echo "Projects v2 #$PROJECT_NUMBER" || echo "off (gh issues only)")"
542
571
  echo " Memory : $MEMORY_BOOL Plans: $PLANS_FORMAT Lang: $LANG_PREF"
543
572
  echo " Spec Kit: $SPECKIT_ON Pre-push gate: $PREPUSH_ENABLED Local model: $LOCAL_ON kitVersion: $PLUGIN_VERSION"
@@ -603,6 +632,7 @@ jq -n \
603
632
  --arg name "$NAME" --arg slug "$SLUG" --arg owner "$OWNER_NAME" --arg lang "$LANG_PREF" --arg path "$TARGET" \
604
633
  --arg profile "$PROFILE" --argjson roles "$ROLES_JSON" \
605
634
  --arg repo "$REPO" --arg ghowner "$GH_OWNER" \
635
+ --arg base "$BASE_BRANCH" \
606
636
  --argjson pv2 "$PROJECTS_V2" --argjson pnum "$PNUM_JSON" --arg ptitle "$NAME" \
607
637
  --argjson milestones "$MS_JSON" \
608
638
  --arg pfmt "$PLANS_FORMAT" --arg pdir "$PLANS_DIR" \
@@ -613,7 +643,7 @@ jq -n \
613
643
  '{kitVersion:$kitver,
614
644
  project:{name:$name,slug:$slug,owner:$owner,language:$lang,path:$path},
615
645
  profile:$profile, roles:$roles,
616
- github:{repo:$repo,owner:$ghowner,projectsV2:$pv2,projectNumber:$pnum,projectTitle:$ptitle},
646
+ github:{repo:$repo,owner:$ghowner,baseBranch:$base,projectsV2:$pv2,projectNumber:$pnum,projectTitle:$ptitle},
617
647
  milestones:$milestones,
618
648
  plans:{format:$pfmt,dir:$pdir},
619
649
  knowledge:{dir:"knowledge"},
@@ -722,6 +752,24 @@ for sc in setup-labels.sh setup-milestones.sh capture-project-ids.sh task-sync.s
722
752
  done
723
753
  echo " + scripts/ (libs + setup + task-sync + version-check + knowledge-lint)"
724
754
 
755
+ # ---- benchmark harness (generic machinery; kit-owned) + example dataset ----
756
+ # The harness measures how well THIS project's own canonical docs can be found + used by a cold
757
+ # agent (retrieval / adversarial / abstain / quality tiers). Machinery is kit-owned (refreshed on
758
+ # upgrade); the datasets under benchmarks/ are the project's own — we scaffold an EXAMPLE set +
759
+ # schema only, and safe_write preserves it on upgrade so growth is never clobbered.
760
+ for bs in run.sh run-quality.sh report.sh gate.sh stop-check.sh benchmark-test.sh; do
761
+ safe_copy "$KIT_ROOT/scripts/benchmark/$bs" "$TARGET/scripts/benchmark/$bs" exec
762
+ done
763
+ safe_copy "$KIT_ROOT/scripts/benchmark/lib/model.sh" "$TARGET/scripts/benchmark/lib/model.sh"
764
+ safe_copy "$KIT_ROOT/scripts/benchmark/lib/bench-common.sh" "$TARGET/scripts/benchmark/lib/bench-common.sh"
765
+ echo " + scripts/benchmark/ (doc-retrieval benchmark harness — see benchmarks/SCHEMA.md)"
766
+
767
+ mkdir -p "$TARGET/benchmarks"
768
+ for bf in SCHEMA.md benchmark.config.json retrieval.jsonl adversarial.jsonl abstain.jsonl quality.jsonl .gitignore; do
769
+ safe_write "$KIT_ROOT/templates/benchmarks/$bf" "$TARGET/benchmarks/$bf"
770
+ done
771
+ echo " + benchmarks/ (example dataset + schema — grow your own; run: scripts/benchmark/report.sh)"
772
+
725
773
  # ---- knowledge base (governed dir: INDEX manifest; upgrade-safe) ---------
726
774
  mkdir -p "$TARGET/knowledge"
727
775
  safe_write "$KIT_ROOT/templates/knowledge-INDEX.md.tmpl" "$TARGET/knowledge/INDEX.md"
@@ -735,6 +783,14 @@ safe_write "$KIT_ROOT/templates/lib/kit-sigil.sh.tmpl" "$TARGET/.claude/lib/kit-
735
783
  chmod +x "$TARGET/.claude/lib/kit-sigil.sh" 2>/dev/null || true
736
784
  echo " + .claude/lib/kit-sigil.sh"
737
785
 
786
+ # ---- settings.json (versioned — travels to worktrees + collaborators) ---
787
+ # Unlike settings.local.json (gitignored, per-checkout), this one is CHECKED IN so the
788
+ # captain's pre-authorized wave-merge (gh pr merge under an approved plan) works in every
789
+ # worktree and for every collaborator without re-prompting. safe_write = preserve-if-exists.
790
+ mkdir -p "$TARGET/.claude"
791
+ safe_write "$KIT_ROOT/templates/settings/settings.json.tmpl" "$TARGET/.claude/settings.json"
792
+ echo " + .claude/settings.json (versioned captain merge permission)"
793
+
738
794
  # ---- settings.local.json (+ hooks, additive) ----------------------------
739
795
  mkdir -p "$TARGET/.claude"
740
796
  safe_write "$KIT_ROOT/templates/settings/settings.local.json.tmpl" "$TARGET/.claude/settings.local.json"
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+ # cckit — self-update the checkout this cckit runs from.
3
+ #
4
+ # A symlink install (cckit on PATH -> <checkout>/bin, plugin -> <checkout>) means "update"
5
+ # is just a fast-forward pull of the checkout. This script does that pull, safely:
6
+ # - resolves its OWN checkout root (works from any caller: hook, cron, by hand)
7
+ # - throttled: at most one network hit per THROTTLE window (stamp file), so a
8
+ # SessionStart hook can call it on every session for free
9
+ # - --ff-only on the checkout's CURRENT branch: never creates merges, never touches
10
+ # a diverged/dirty state -- worst case it silently does nothing
11
+ # - always exits 0: an update failure must never break a session start
12
+ #
13
+ # Usage: kit-self-update.sh [--force] [--quiet]
14
+ # --force ignore the throttle stamp
15
+ # --quiet suppress the "updated" notice
16
+ set -uo pipefail
17
+
18
+ FORCE=0; QUIET=0
19
+ while [[ $# -gt 0 ]]; do
20
+ case "$1" in
21
+ --force) FORCE=1; shift ;;
22
+ --quiet) QUIET=1; shift ;;
23
+ *) shift ;;
24
+ esac
25
+ done
26
+
27
+ # Resolve the checkout root from this script's real location (scripts/ -> root).
28
+ SELF_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
29
+ ROOT="$(cd -- "$SELF_DIR/.." >/dev/null 2>&1 && pwd)"
30
+ [[ -n "$ROOT" ]] || exit 0
31
+ git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
32
+
33
+ # Throttle: one pull per window (default 4h). Stamp lives in the user cache dir.
34
+ THROTTLE="${CCKIT_SELF_UPDATE_THROTTLE:-14400}"
35
+ STAMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cckit"
36
+ STAMP="$STAMP_DIR/self-update.stamp"
37
+ if [[ $FORCE -eq 0 && -f "$STAMP" ]]; then
38
+ now=$(date +%s)
39
+ last=$(stat -f %m "$STAMP" 2>/dev/null || stat -c %Y "$STAMP" 2>/dev/null || echo 0)
40
+ (( now - last < THROTTLE )) && exit 0
41
+ fi
42
+ mkdir -p "$STAMP_DIR" 2>/dev/null && touch "$STAMP" 2>/dev/null
43
+
44
+ before="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null)"
45
+ # ff-only pull of the current branch; short timeouts so a dead network can't hang a hook.
46
+ GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=5 \
47
+ git -C "$ROOT" pull --ff-only --quiet 2>/dev/null || exit 0
48
+ after="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null)"
49
+
50
+ if [[ $QUIET -eq 0 && -n "$before" && -n "$after" && "$before" != "$after" ]]; then
51
+ ver=""
52
+ command -v jq >/dev/null 2>&1 && ver="$(jq -r '.version // empty' "$ROOT/.claude-plugin/plugin.json" 2>/dev/null)"
53
+ echo "cckit self-updated: $before -> $after${ver:+ (v$ver)}"
54
+ fi
55
+ exit 0
@@ -3,6 +3,7 @@
3
3
  # board-view-test.sh — covers the pure board-view render helpers (#122): the merge-ordered open-PR
4
4
  # queue, the stale flag, the not-on-board flag, and Project Status lookup. Hermetic: canned JSON,
5
5
  # no gh. Run: bash scripts/lib/board-view-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
7
  set -u
7
8
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8
9
  LIB="$ROOT/scripts/lib"
@@ -4,6 +4,7 @@
4
4
  # and emits markdown/text; none call gh, so they are unit-testable with canned fixtures (#122).
5
5
  # Ported from the host project's board view: a merge-ordered open-PR queue, a stale-issue flag, a
6
6
  # not-on-board flag, and Project Status per issue. bash 3.2 + zsh safe. Requires jq.
7
+ # errors: pure — JSON in, text out; no gh, no network
7
8
 
8
9
  # board_merge_queue <prs-json> — render the open-PR merge queue as a markdown table. <prs-json> is
9
10
  # `gh pr list --json number,title,labels,isDraft,headRefName,reviewDecision,mergeable` output.
@@ -3,6 +3,7 @@
3
3
  # Network-free: covers cap_checks_summary / cap_classify / cap_action and the branch parser only
4
4
  # (the gh-driven captain_gate/pass/loop are not exercised).
5
5
  # Run: bash scripts/lib/captain-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
7
 
7
8
  dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
8
9
 
@@ -31,6 +32,31 @@ if [ -n "${CAP_TEST_INNER:-}" ]; then
31
32
  # failing checks must not be hidden even when mergeable says MERGEABLE.
32
33
  eq "fail beats mergeable" "$(cap_classify MERGEABLE CLEAN FAIL)" "CHECKS_FAILING"
33
34
 
35
+ # cap_classify + KIT_CAPTAIN_REQUIRE_CHECKS — an EMPTY rollup (NONE) is an ABSENCE of evidence, not
36
+ # a pass. Default OFF, so the four cases below are the whole contract.
37
+ #
38
+ # 1. OFF (unset AND explicit 0) — behaviour is UNCHANGED. This is the regression assertion: an
39
+ # empty rollup still reads CLEAN, exactly as before, so no existing repo's captain moves.
40
+ eq "require unset: NONE still CLEAN" "$(KIT_CAPTAIN_REQUIRE_CHECKS= cap_classify MERGEABLE CLEAN NONE)" "CLEAN"
41
+ eq "require 0: NONE still CLEAN" "$(KIT_CAPTAIN_REQUIRE_CHECKS=0 cap_classify MERGEABLE CLEAN NONE)" "CLEAN"
42
+ eq "require 0: unstable NONE CLEAN" "$(KIT_CAPTAIN_REQUIRE_CHECKS=0 cap_classify MERGEABLE UNSTABLE NONE)" "CLEAN"
43
+ # 2. ON — the empty rollup gets its own verdict, distinct from FAILING and PENDING.
44
+ eq "require 1: NONE is missing" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE CLEAN NONE)" "CHECKS_MISSING"
45
+ eq "require true: NONE is missing" "$(KIT_CAPTAIN_REQUIRE_CHECKS=true cap_classify MERGEABLE CLEAN NONE)" "CHECKS_MISSING"
46
+ eq "require 1: unstable NONE missing" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE UNSTABLE NONE)" "CHECKS_MISSING"
47
+ # 3. A real rollup is untouched either way — the setting only speaks about the empty case.
48
+ eq "require 1: PASS still CLEAN" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE CLEAN PASS)" "CLEAN"
49
+ eq "require 1: FAIL unaffected" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE UNSTABLE FAIL)" "CHECKS_FAILING"
50
+ eq "require 1: PENDING unaffected" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE UNSTABLE PENDING)" "CHECKS_PENDING"
51
+ eq "require 0: FAIL unaffected" "$(KIT_CAPTAIN_REQUIRE_CHECKS=0 cap_classify MERGEABLE UNSTABLE FAIL)" "CHECKS_FAILING"
52
+ eq "require 0: PENDING unaffected" "$(KIT_CAPTAIN_REQUIRE_CHECKS=0 cap_classify MERGEABLE UNSTABLE PENDING)" "CHECKS_PENDING"
53
+ # 4. Only the would-be-CLEAN verdict can change — draft/conflict/blocked keep their own answers
54
+ # even with the requirement on, so the rest of the vocabulary provably does not move.
55
+ eq "require 1: draft still draft" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify MERGEABLE DRAFT NONE)" "DRAFT"
56
+ eq "require 1: conflict still conf" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify CONFLICTING BLOCKED NONE)" "CONFLICTING"
57
+ eq "require 1: dirty still conflict" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify UNKNOWN DIRTY NONE)" "CONFLICTING"
58
+ eq "require 1: blocked still blocked" "$(KIT_CAPTAIN_REQUIRE_CHECKS=1 cap_classify UNKNOWN BLOCKED NONE)" "BLOCKED"
59
+
34
60
  # cap_action — verdict -> action.
35
61
  eq "act clean" "$(cap_action CLEAN)" "merge"
36
62
  eq "act conflicting" "$(cap_action CONFLICTING)" "rebase"
@@ -39,6 +65,8 @@ if [ -n "${CAP_TEST_INNER:-}" ]; then
39
65
  eq "act draft" "$(cap_action DRAFT)" "wait"
40
66
  eq "act held" "$(cap_action HELD)" "hold"
41
67
  eq "act blocked" "$(cap_action BLOCKED)" "skip"
68
+ # the whole point: an unobserved gate must never resolve to merge.
69
+ eq "act missing" "$(cap_action CHECKS_MISSING)" "verify"
42
70
 
43
71
  # cap_policy_floor — floors that block an unattended auto-merge (default ON). Non-empty = held.
44
72
  nl="$(printf '\n')"
@@ -57,6 +85,40 @@ if [ -n "${CAP_TEST_INNER:-}" ]; then
57
85
  # a disabling override lets even a workflow file through (config/CLI can opt out).
58
86
  eq "floor: KIT_CAPTAIN_FLOORS=0 disables" "$(KIT_CAPTAIN_FLOORS=0 cap_policy_floor ".github/workflows/ci.yml" "hold")" ""
59
87
 
88
+ # _cap_load_policy_config — the config bridge for requireChecks, and ENV WINNING over config
89
+ # (same rule as KIT_CAPTAIN_FLOORS). Subshelled so the exports never leak into later assertions.
90
+ if command -v jq >/dev/null 2>&1; then
91
+ bridge() {
92
+ ( KIT_CONFIG="$1"; KIT_CAPTAIN_REQUIRE_CHECKS="$2"
93
+ KIT_CAPTAIN_FLOORS=; KIT_CAPTAIN_EXTRA_GLOBS=
94
+ _cap_load_policy_config
95
+ printf '%s' "${KIT_CAPTAIN_REQUIRE_CHECKS:-unset}" )
96
+ }
97
+ cfgon="$(mktemp)"; printf '{"captain":{"mergePolicy":{"requireChecks":true}}}' > "$cfgon"
98
+ cfgoff="$(mktemp)"; printf '{"captain":{"mergePolicy":{"requireChecks":false}}}' > "$cfgoff"
99
+ cfgnone="$(mktemp)"; printf '{"project":{"name":"x"}}' > "$cfgnone"
100
+ eq "bridge: config true -> 1" "$(bridge "$cfgon" "")" "1"
101
+ eq "bridge: config false -> 0" "$(bridge "$cfgoff" "")" "0"
102
+ eq "bridge: key absent -> unset" "$(bridge "$cfgnone" "")" "unset"
103
+ eq "bridge: env 0 beats config" "$(bridge "$cfgon" "0")" "0"
104
+ eq "bridge: env 1 beats config" "$(bridge "$cfgoff" "1")" "1"
105
+ rm -f "$cfgon" "$cfgoff" "$cfgnone"
106
+
107
+ # _cap_cfg_bool must distinguish "set to false" from "not set". jq's `//` does NOT — it treats a
108
+ # literal false as absent — which is why `captain.mergePolicy.floors:false` was documented but
109
+ # inert until this helper replaced it. Locking that here so the opt-out cannot silently rot again.
110
+ cfgf="$(mktemp)"; printf '{"captain":{"mergePolicy":{"floors":false}}}' > "$cfgf"
111
+ eq "cfg_bool: false is not absent" "$(_cap_cfg_bool "$cfgf" floors)" "false"
112
+ eq "cfg_bool: absent is empty" "$(_cap_cfg_bool "$cfgf" requireChecks)" ""
113
+ floorbridge() {
114
+ ( KIT_CONFIG="$1"; KIT_CAPTAIN_FLOORS="$2"; KIT_CAPTAIN_EXTRA_GLOBS=; KIT_CAPTAIN_REQUIRE_CHECKS=
115
+ _cap_load_policy_config; printf '%s' "${KIT_CAPTAIN_FLOORS:-unset}" )
116
+ }
117
+ eq "bridge: floors:false -> 0" "$(floorbridge "$cfgf" "")" "0"
118
+ eq "bridge: env 1 beats floors cfg" "$(floorbridge "$cfgf" "1")" "1"
119
+ rm -f "$cfgf"
120
+ fi
121
+
60
122
  # _cap_issue_of_branch — pull the issue number out of a flow branch.
61
123
  eq "branch task" "$(_cap_issue_of_branch 'task/47-admin-clerk')" "47"
62
124
  eq "branch fix" "$(_cap_issue_of_branch 'fix/9-roadmap')" "9"
@@ -3,10 +3,10 @@
3
3
  # next unblocked wave, and checkpoint so the loop can stop and resume (Effort 75 · #77).
4
4
  #
5
5
  # Autopilot has two halves. `orchestrate`/`autopilot` LAUNCH the per-issue flows; the captain CLOSES
6
- # them — it inspects each PR, decides (CLEAN / CONFLICTING / CHECKS_FAILING / CHECKS_PENDING / DRAFT /
7
- # BLOCKED), merges what is ready, and lets the freshly-merged issues unblock the next wave. This is
8
- # the half that used to be left to the driving agent; now it is a script the agent (or `cckit watch`)
9
- # runs in a loop.
6
+ # them — it inspects each PR, decides (CLEAN / CONFLICTING / CHECKS_FAILING / CHECKS_PENDING /
7
+ # CHECKS_MISSING / DRAFT / BLOCKED), merges what is ready, and lets the freshly-merged issues unblock
8
+ # the next wave. This is the half that used to be left to the driving agent; now it is a script the
9
+ # agent (or `cckit watch`) runs in a loop.
10
10
  #
11
11
  # cckit watch one pass: gate every open PR, report (no merge) — safe default
12
12
  # cckit watch --merge gate + squash-merge the CLEAN PRs, then show the next wave
@@ -16,8 +16,28 @@
16
16
  #
17
17
  # Gate decision is three pure helpers (cap_checks_summary / cap_classify / cap_action) so the policy
18
18
  # is unit-tested without the network. Requires gh + jq. bash 3.2 / zsh compatible.
19
+ # errors: mixed — cap_* are pure; captain_gate/captain_pass propagate a gh failure
19
20
 
20
21
  CAPTAIN_REPO="${CAPTAIN_REPO:-${KIT_REPO:-}}"
22
+
23
+ # State lives in the shared .cckit/ (kit-state.sh), never CWD-relative: the captain gates the whole
24
+ # repo, so its record must be the same file from the primary checkout and from every worktree.
25
+ # Locate the sibling portably — BASH_SOURCE is bash-only and empty in zsh (#313).
26
+ if [ -n "${BASH_SOURCE:-}" ]; then
27
+ _cap_self="$BASH_SOURCE"
28
+ elif [ -n "${ZSH_VERSION:-}" ]; then
29
+ eval '_cap_self="${(%):-%x}"'
30
+ else
31
+ _cap_self="$0"
32
+ fi
33
+ if [ -f "$(dirname "$_cap_self")/kit-state.sh" ]; then
34
+ # shellcheck source=kit-state.sh
35
+ . "$(dirname "$_cap_self")/kit-state.sh"
36
+ fi
37
+ unset _cap_self
38
+ if [ -z "${CAPTAIN_STATE:-}" ] && command -v kit_state_file >/dev/null 2>&1; then
39
+ CAPTAIN_STATE="$(kit_state_file captain.state)"
40
+ fi
21
41
  CAPTAIN_STATE="${CAPTAIN_STATE:-.cckit/captain.state}"
22
42
 
23
43
  # cap_checks_summary — collapse a gh statusCheckRollup JSON array (stdin) to one token:
@@ -35,8 +55,22 @@ cap_checks_summary() {
35
55
 
36
56
  # cap_classify <mergeable> <mergeStateStatus> <checksSummary> — pure verdict for one PR.
37
57
  # mergeable: MERGEABLE|CONFLICTING|UNKNOWN · mss: CLEAN|DIRTY|DRAFT|BLOCKED|BEHIND|UNSTABLE|…
58
+ #
59
+ # CHECKS_MISSING — "the exit criteria could not be observed". An EMPTY statusCheckRollup collapses to
60
+ # NONE, and NONE is not a pass: it is the ABSENCE of evidence. Read as green it means a repo with no
61
+ # CI is auto-mergeable by construction, which is how an unattended captain lands a change nothing
62
+ # ever verified. When evidence is REQUIRED (KIT_CAPTAIN_REQUIRE_CHECKS=1, or
63
+ # captain.mergePolicy.requireChecks:true in the kit config — env wins) that case becomes its own
64
+ # verdict, distinct from CHECKS_FAILING (something ran and went red) and CHECKS_PENDING (something is
65
+ # still running), and its action is `verify`, never `merge`.
66
+ #
67
+ # DEFAULT OFF. Requiring evidence in every repo would turn a legitimate no-CI, human-reviewed
68
+ # workflow into a captain that silently merges nothing and reports steady state, so the default keeps
69
+ # today's behaviour and `captain_pass` instead PRINTS the assumption it is making (see the "green was
70
+ # assumed" advisory) with the key that closes it. The narrow guard below is deliberate: only the
71
+ # verdict that would have been CLEAN can change, so nothing else in the vocabulary moves.
38
72
  cap_classify() {
39
- local mergeable="$1" mss="$2" checks="$3"
73
+ local mergeable="$1" mss="$2" checks="$3" require
40
74
  case "$mss" in DRAFT) echo DRAFT; return 0 ;; esac
41
75
  case "$mergeable" in CONFLICTING) echo CONFLICTING; return 0 ;; esac
42
76
  case "$mss" in DIRTY) echo CONFLICTING; return 0 ;; esac
@@ -44,22 +78,32 @@ cap_classify() {
44
78
  FAIL) echo CHECKS_FAILING; return 0 ;;
45
79
  PENDING) echo CHECKS_PENDING; return 0 ;;
46
80
  esac
81
+ # Literal case patterns only (a variable in a case pattern matches literally under zsh).
82
+ case "${KIT_CAPTAIN_REQUIRE_CHECKS:-0}" in 1|true|yes|on) require=1 ;; *) require=0 ;; esac
47
83
  case "$mergeable" in
48
84
  MERGEABLE)
49
85
  # passing or no required checks, and not draft/dirty/conflicting -> ready.
50
- case "$mss" in CLEAN|UNSTABLE|HAS_HOOKS|"") echo CLEAN; return 0 ;; esac
86
+ case "$mss" in
87
+ CLEAN|UNSTABLE|HAS_HOOKS|"")
88
+ if [ "$require" = "1" ] && [ "$checks" = "NONE" ]; then echo CHECKS_MISSING; return 0; fi
89
+ echo CLEAN; return 0 ;;
90
+ esac
51
91
  echo BLOCKED; return 0 ;;
52
92
  esac
53
93
  echo BLOCKED
54
94
  }
55
95
 
56
96
  # cap_action <state> — the action the captain takes for a verdict.
97
+ # CHECKS_MISSING -> `verify`, not `wait` (nothing is coming — no check exists to finish) and not
98
+ # `hold` (that is the policy-floor action, reported as "policy floor: <reason>"). Someone must go
99
+ # produce or point at the evidence.
57
100
  cap_action() {
58
101
  case "$1" in
59
102
  CLEAN) echo merge ;;
60
103
  CONFLICTING) echo rebase ;;
61
104
  CHECKS_FAILING) echo fix ;;
62
105
  CHECKS_PENDING) echo wait ;;
106
+ CHECKS_MISSING) echo verify ;;
63
107
  DRAFT) echo wait ;;
64
108
  HELD) echo hold ;;
65
109
  *) echo skip ;;
@@ -77,6 +121,12 @@ cap_action() {
77
121
  # Disable entirely with KIT_CAPTAIN_FLOORS=0 (or captain.mergePolicy.floors:false in config). Extend
78
122
  # the protected set with KIT_CAPTAIN_EXTRA_GLOBS (space-separated case-globs). Draft state is honored
79
123
  # separately by cap_classify (DRAFT -> wait). Pure — no gh; unit-tested. bash 3.2 / zsh safe.
124
+ #
125
+ # A floor is about WHAT THE PR TOUCHES, so it needs the file list and labels and it downgrades a
126
+ # would-be merge to HELD. Missing check evidence is about WHAT IS KNOWN about the PR — decidable from
127
+ # the rollup token alone — so it is a cap_classify verdict (CHECKS_MISSING) instead. Keeping them
128
+ # apart keeps both reasons legible: "a human must sign off on this path" is not the same finding as
129
+ # "nothing ever verified this", and HELD's report line names a floor that would not exist.
80
130
  cap_policy_floor() {
81
131
  local files="$1" labels="$2" f g extra hit
82
132
  [ "${KIT_CAPTAIN_FLOORS:-1}" = "0" ] && return 0
@@ -117,23 +167,40 @@ EOF
117
167
  return 0
118
168
  }
119
169
 
170
+ # _cap_cfg_bool <cfg> <key> — echo "true"/"false" for captain.mergePolicy.<key>, or NOTHING when the
171
+ # key is absent. Deliberately NOT `// empty`: jq's `//` treats a literal `false` as absent, so
172
+ # `.foo // empty` silently swallows an explicit opt-out — which is exactly how
173
+ # `captain.mergePolicy.floors:false` came to be documented but inert. `has()` distinguishes
174
+ # "set to false" from "not set", which is the whole distinction a tri-state override needs.
175
+ _cap_cfg_bool() {
176
+ jq -r --arg k "$2" '
177
+ .captain.mergePolicy
178
+ | if type == "object" and has($k) and (.[$k] | type == "boolean")
179
+ then (.[$k] | tostring) else empty end' "$1" 2>/dev/null
180
+ }
181
+
120
182
  # _cap_load_policy_config — bridge captain.mergePolicy from the kit config into the env the pure
121
- # floor helper reads, so a project can override the floors declaratively. Env always wins (a value
122
- # already set is left untouched). Best-effort: no config / no jq -> defaults (floors ON).
183
+ # helpers read, so a project can set the merge policy declaratively. Env always wins (a value already
184
+ # set is left untouched). Best-effort: no config / no jq -> defaults (floors ON, requireChecks OFF).
123
185
  _cap_load_policy_config() {
124
186
  command -v jq >/dev/null 2>&1 || return 0
125
187
  local cfg="${KIT_CONFIG:-}"
126
188
  [ -n "$cfg" ] || { [ -f cckit.config.json ] && cfg=cckit.config.json || cfg=.claude/kit.config.json; }
127
189
  [ -f "$cfg" ] || return 0
128
190
  if [ -z "${KIT_CAPTAIN_FLOORS:-}" ]; then
129
- case "$(jq -r '.captain.mergePolicy.floors // empty' "$cfg" 2>/dev/null)" in
191
+ case "$(_cap_cfg_bool "$cfg" floors)" in
130
192
  false) KIT_CAPTAIN_FLOORS=0 ;; true) KIT_CAPTAIN_FLOORS=1 ;;
131
193
  esac
132
194
  fi
133
195
  if [ -z "${KIT_CAPTAIN_EXTRA_GLOBS:-}" ]; then
134
196
  KIT_CAPTAIN_EXTRA_GLOBS="$(jq -r '(.captain.mergePolicy.protectedGlobs // []) | join(" ")' "$cfg" 2>/dev/null || echo "")"
135
197
  fi
136
- export KIT_CAPTAIN_FLOORS KIT_CAPTAIN_EXTRA_GLOBS
198
+ if [ -z "${KIT_CAPTAIN_REQUIRE_CHECKS:-}" ]; then
199
+ case "$(_cap_cfg_bool "$cfg" requireChecks)" in
200
+ true) KIT_CAPTAIN_REQUIRE_CHECKS=1 ;; false) KIT_CAPTAIN_REQUIRE_CHECKS=0 ;;
201
+ esac
202
+ fi
203
+ export KIT_CAPTAIN_FLOORS KIT_CAPTAIN_EXTRA_GLOBS KIT_CAPTAIN_REQUIRE_CHECKS
137
204
  }
138
205
 
139
206
  # _cap_issue_of_branch <branch> — issue number a flow branch encodes (task/47-x, fix/9-y, effort/12-z).
@@ -142,9 +209,10 @@ _cap_issue_of_branch() {
142
209
  }
143
210
 
144
211
  # captain_gate <pr#> — fetch + classify one PR. Echoes
145
- # "pr<TAB>issue<TAB>state<TAB>action<TAB>title<TAB>reason". A CLEAN PR that trips a policy floor
146
- # (cap_policy_floor) is downgraded to HELD/hold so the captain never auto-merges it; `reason` carries
147
- # the floor that tripped (empty otherwise).
212
+ # "pr<TAB>issue<TAB>state<TAB>action<TAB>title<TAB>reason<TAB>checks". A CLEAN PR that trips a policy
213
+ # floor (cap_policy_floor) is downgraded to HELD/hold so the captain never auto-merges it; `reason`
214
+ # carries the floor that tripped (empty otherwise). `checks` is the raw rollup token (FAIL/PENDING/
215
+ # PASS/NONE) — REPORTED, not re-decided, so captain_pass can say when a merge rests on NONE.
148
216
  captain_gate() {
149
217
  local repo="$CAPTAIN_REPO" pr="$1" j mergeable mss checks issue state action title branch files labels reason
150
218
  j="$(gh pr view "$pr" --repo "$repo" --json number,title,headRefName,mergeable,mergeStateStatus,statusCheckRollup,files,labels 2>/dev/null)" \
@@ -165,7 +233,7 @@ captain_gate() {
165
233
  reason="$(cap_policy_floor "$files" "$labels")"
166
234
  [ -n "$reason" ] && { state="HELD"; action="hold"; }
167
235
  fi
168
- printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$pr" "${issue:-—}" "$state" "$action" "$title" "$reason"
236
+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$pr" "${issue:-—}" "$state" "$action" "$title" "$reason" "$checks"
169
237
  }
170
238
 
171
239
  # _cap_open_prs [effort] — open PR numbers, optionally only those whose branch-issue is a sub of <effort>.
@@ -203,11 +271,15 @@ captain_pass() {
203
271
  CAPTAIN_MERGED=0
204
272
  _cap_load_policy_config # bridge captain.mergePolicy from config into the floor env (env wins)
205
273
 
206
- local prs pr row state action issue title reason merged_any=0
274
+ local prs pr row state action issue title reason checks merged_any=0 unproven=0
207
275
  prs="$(_cap_open_prs "$effort")"
208
276
  [ -n "$prs" ] || { echo "captain: no open PRs in scope"; return 0; }
209
277
 
210
- : > "$CAPTAIN_STATE" 2>/dev/null || true
278
+ # The braces matter: redirections are processed left to right, so `: > "$f" 2>/dev/null` attempts
279
+ # the redirect BEFORE the suppression applies and the shell reports the failure anyway. Wrapping
280
+ # the whole group is what actually silences it. Ensure the dir first so it normally succeeds.
281
+ command -v kit_state_ensure >/dev/null 2>&1 && kit_state_ensure || true
282
+ { : > "$CAPTAIN_STATE"; } 2>/dev/null || true
211
283
  echo "captain: gating $(printf '%s\n' "$prs" | grep -c .) open PR(s)$( [ -n "$effort" ] && echo " for effort #$effort")"
212
284
  for pr in $prs; do
213
285
  row="$(captain_gate "$pr")" || continue
@@ -216,7 +288,11 @@ captain_pass() {
216
288
  issue="$(printf '%s' "$row" | cut -f2)"
217
289
  title="$(printf '%s' "$row" | cut -f5)"
218
290
  reason="$(printf '%s' "$row" | cut -f6)"
219
- printf '%s\t%s\n' "$pr" "$state" >> "$CAPTAIN_STATE" 2>/dev/null || true
291
+ checks="$(printf '%s' "$row" | cut -f7)"
292
+ { printf '%s\t%s\n' "$pr" "$state" >> "$CAPTAIN_STATE"; } 2>/dev/null || true
293
+ # A merge resting on an EMPTY rollup: green was assumed, never observed. Counted here and named
294
+ # once at the end of the pass, so the assumption is on screen even with the requirement OFF.
295
+ if [ "$action" = "merge" ] && [ "$checks" = "NONE" ]; then unproven=$((unproven + 1)); fi
220
296
  if [ "$action" = "merge" ] && [ "$do_merge" = "1" ] && [ "$dry" = "0" ]; then
221
297
  if gh pr merge "$pr" --repo "$repo" --squash --delete-branch >/dev/null 2>&1; then
222
298
  printf ' PR #%-4s %-14s MERGED (#%s %s)\n' "$pr" "$state" "$issue" "$title"
@@ -233,6 +309,18 @@ captain_pass() {
233
309
  done
234
310
  CAPTAIN_MERGED="$merged_any"
235
311
 
312
+ # Say the assumption out loud. `requireChecks` is default-off, so this advisory is what keeps it
313
+ # from being a safety feature nobody knows about: it fires at exactly the moment the risk is real
314
+ # (a PR the captain will merge whose rollup was EMPTY), names the key that closes it, and
315
+ # self-silences once the key is on — those PRs then read CHECKS_MISSING, so `unproven` stays 0.
316
+ if [ "$unproven" -gt 0 ]; then
317
+ printf 'captain: %s PR(s) read CLEAN with NO checks observed (empty rollup) — %s\n' \
318
+ "$unproven" "green was ASSUMED, not proved."
319
+ printf ' require evidence instead: captain.mergePolicy.requireChecks:true in your kit\n'
320
+ printf ' config (or KIT_CAPTAIN_REQUIRE_CHECKS=1). Those PRs then read CHECKS_MISSING\n'
321
+ printf ' -> verify, and the captain will not merge them.\n'
322
+ fi
323
+
236
324
  # advance: after merges, the newly-unblocked work shows up as the next wave.
237
325
  if [ "$merged_any" -gt 0 ]; then
238
326
  echo "captain: merged $merged_any — next unblocked wave:"