@jeiemgi/cckit 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +21 -8
  3. package/README.md +119 -20
  4. package/bin/cckit +42 -16
  5. package/cckit.config.json +1 -1
  6. package/commands/kit-doctor.md +3 -1
  7. package/commands/kit-update.md +9 -4
  8. package/kit.config.schema.json +25 -0
  9. package/package.json +1 -1
  10. package/scripts/annotate-setup.sh +7 -2
  11. package/scripts/capture-project-ids.sh +23 -10
  12. package/scripts/init-upgrade-test.sh +35 -1
  13. package/scripts/init.sh +43 -7
  14. package/scripts/kit-doctor.sh +185 -7
  15. package/scripts/kit-version-check-test.sh +36 -0
  16. package/scripts/kit-version-check.sh +19 -4
  17. package/scripts/kit-wire.sh +4 -1
  18. package/scripts/knowledge-lint.sh +4 -1
  19. package/scripts/lib/board-view-test.sh +54 -0
  20. package/scripts/lib/board-view.sh +80 -0
  21. package/scripts/lib/captain-test.sh +18 -0
  22. package/scripts/lib/captain.sh +92 -5
  23. package/scripts/lib/config-path-test.sh +47 -0
  24. package/scripts/lib/config-path.sh +29 -0
  25. package/scripts/lib/copilot.sh +9 -9
  26. package/scripts/lib/effort-dispatch-test.sh +25 -0
  27. package/scripts/lib/effort-flows-test.sh +55 -0
  28. package/scripts/lib/effort-metrics-test.sh +57 -0
  29. package/scripts/lib/effort-metrics.sh +19 -5
  30. package/scripts/lib/effort-ops-test.sh +110 -3
  31. package/scripts/lib/effort-ops.sh +480 -50
  32. package/scripts/lib/effort-parity-test.sh +128 -0
  33. package/scripts/lib/effort-slug-test.sh +87 -0
  34. package/scripts/lib/effort-slug.sh +104 -0
  35. package/scripts/lib/effort.sh +91 -1
  36. package/scripts/lib/gh-project-test.sh +95 -0
  37. package/scripts/lib/gh-project.sh +22 -7
  38. package/scripts/lib/git-remote-test.sh +57 -0
  39. package/scripts/lib/git-remote.sh +21 -0
  40. package/scripts/lib/kit-config-test.sh +37 -0
  41. package/scripts/lib/kit-config.sh +38 -13
  42. package/scripts/lib/kit-engine-test.sh +9 -0
  43. package/scripts/lib/kit-events.sh +5 -3
  44. package/scripts/lib/kit-gc-test.sh +88 -0
  45. package/scripts/lib/kit-gc.sh +136 -19
  46. package/scripts/lib/kit-local.sh +8 -1
  47. package/scripts/lib/kit-operate.sh +17 -2
  48. package/scripts/lib/next.sh +3 -3
  49. package/scripts/lib/plan-next-test.sh +87 -0
  50. package/scripts/lib/plan-next.sh +212 -0
  51. package/scripts/lib/project-scan.sh +7 -1
  52. package/scripts/lib/worktree-start.sh +12 -3
  53. package/scripts/lib/zsh-safety-test.sh +73 -0
  54. package/scripts/portable-test.sh +62 -20
  55. package/scripts/setup-labels.sh +13 -2
  56. package/scripts/showcase.sh +13 -4
  57. package/scripts/status-test.sh +63 -0
  58. package/scripts/status.sh +12 -4
  59. package/scripts/task-sync.sh +79 -10
  60. package/skills/kit-autopilot/SKILL.md +5 -0
  61. package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
  62. package/skills/kit-effort-close/SKILL.md +52 -104
  63. package/skills/kit-effort-new/SKILL.md +40 -112
  64. package/skills/kit-effort-pr/SKILL.md +6 -2
  65. package/skills/kit-effort-start/SKILL.md +44 -46
  66. package/skills/kit-next/SKILL.md +4 -0
  67. package/skills/kit-plan-next/SKILL.md +82 -0
  68. package/skills/kit-task-start/SKILL.md +44 -55
  69. package/templates/CLAUDE.md.tmpl +1 -1
  70. package/templates/agents/auto-dev.md +1 -1
  71. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  72. package/templates/rules/effort-model.md +43 -6
  73. package/templates/rules/mempalace.md +1 -0
  74. package/templates/rules/plan-next.md +58 -0
  75. package/templates/rules/task-management.md +1 -1
package/scripts/init.sh CHANGED
@@ -230,8 +230,9 @@ _INIT_SKIP_PREFLIGHT=0
230
230
  for _ia in "$@"; do [[ "$_ia" == "--upgrade" || "$_ia" == "--dry-run" ]] && _INIT_SKIP_PREFLIGHT=1; done
231
231
 
232
232
  if [[ $_INIT_SKIP_PREFLIGHT -eq 0 && -x "$_DOCTOR" ]]; then
233
- # Pass --no-install if init itself was called with --no-install equivalent
234
- bash "$_DOCTOR" || {
233
+ # --yes: init's preflight installs Tier-1 deps non-interactively (no approval prompt here; the
234
+ # user already opted into setup by running init). A human running `cckit doctor` directly is asked.
235
+ bash "$_DOCTOR" --yes || {
235
236
  echo "" >&2
236
237
  echo "x kit-doctor reported unresolved issues — fix them and re-run /kit-init." >&2
237
238
  exit 1
@@ -307,7 +308,9 @@ if [[ $UPGRADE -eq 1 ]]; then
307
308
  [[ -z "$MEMORY" ]] && MEMORY="$(jq -r 'if .memory.enabled then "on" else "off" end' "$UP_CFG")"
308
309
  [[ -z "$SPECKIT" ]] && SPECKIT="$(jq -r 'if (.specKit.enabled // false) then "on" else "off" end' "$UP_CFG")"
309
310
  [[ -z "$LOCAL_LAYER" ]] && LOCAL_LAYER="$(jq -r 'if (.local.enabled // false) then "on" else "off" end' "$UP_CFG")"
310
- [[ -z "$PLANS_FORMAT" ]] && PLANS_FORMAT="$(jq -r '.plans.format // ""' "$UP_CFG")"
311
+ # A config with NO plans key at all deliberately runs without plan files — upgrade must not
312
+ # resurrect the profile default (and with it the plans rule + config block) (#149).
313
+ [[ -z "$PLANS_FORMAT" ]] && PLANS_FORMAT="$(jq -r 'if has("plans") then (.plans.format // "") else "none" end' "$UP_CFG")"
311
314
  [[ "$LANG_PREF" == "English" ]] && LANG_PREF="$(jq -r '.project.language // "English"' "$UP_CFG")"
312
315
  # Skill-name prefix: projects that namespace their kit skills (e.g. "kit-task-close") set
313
316
  # `skillPrefix` so upgrade scaffolds namespaced templates to the matching name instead of
@@ -349,8 +352,13 @@ PROFILE_FILE="$KIT_ROOT/profiles/$PROFILE.json"
349
352
  mkdir -p "$TARGET"
350
353
  TARGET="$(cd "$TARGET" && pwd)"
351
354
  BASENAME="$(basename "$TARGET")"
352
- [[ -z "$NAME" ]] && NAME="$BASENAME"
353
- [[ -z "$SLUG" ]] && SLUG="$(echo "$BASENAME" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-|-$//g')"
355
+ # Prefer the ACTUAL repo name from the git remote — the local directory is often cloned/renamed to a
356
+ # different name — and only fall back to the directory basename (#73).
357
+ # shellcheck source=/dev/null
358
+ . "$KIT_ROOT/scripts/lib/git-remote.sh"
359
+ NAME_SRC="$(git_remote_repo_name "$TARGET" 2>/dev/null || true)"; NAME_SRC="${NAME_SRC:-$BASENAME}"
360
+ [[ -z "$NAME" ]] && NAME="$NAME_SRC"
361
+ [[ -z "$SLUG" ]] && SLUG="$(echo "$NAME_SRC" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-|-$//g')"
354
362
  if [[ -z "$GH_OWNER" ]]; then GH_OWNER="$(gh api user --jq .login 2>/dev/null || echo "")"; fi
355
363
  [[ -z "$OWNER_NAME" ]] && OWNER_NAME="${GH_OWNER:-owner}"
356
364
  # Prefer the project's ACTUAL GitHub remote over an <owner>/<dir-basename> guess — the local
@@ -561,6 +569,7 @@ if [[ $DRY_RUN -eq 1 ]]; then
561
569
  echo " knowledge/INDEX.md (knowledge-base manifest — rules/knowledge-base.md)"
562
570
  echo " .claude/lib/kit-sigil.sh (claude-kit attribution sigil helper, sourced by task-* footers)"
563
571
  [[ "$MEMORY_BOOL" == "true" ]] && echo " .claude/hooks/mempal_session_start.sh + mempal_save.sh + mempal_precompact.sh + mempal_followup.sh (SessionStart / Stop / PreCompact / SessionEnd)"
572
+ [[ "$MEMORY_BOOL" == "true" ]] && echo " .claude/mempal-identity.$SLUG.txt (per-wing wake-up header — edit the Stack line)"
564
573
  [[ "$PREPUSH_ENABLED" == "true" ]] && echo " .claude/hooks/prepush_gate.sh (PreToolUse Bash gate: $PREPUSH_CMD)"
565
574
  [[ "$LOCAL_ON" == "true" ]] && echo " .claude/hooks/kit-local-status.sh (SessionStart: announce local model layer when alive)"
566
575
  echo ""
@@ -614,8 +623,16 @@ jq -n \
614
623
  memory:{enabled:$mem,provider:"mempalace",wing:$wing,claudeProjectSlug:$cps}}' \
615
624
  > "$KITCFG.kit-new"
616
625
  if [[ $UPGRADE -eq 1 && -f "$KITCFG" ]]; then
617
- # deep-merge: existing values win (preserve user choices), new keys added, version bumped.
618
- jq -s --arg kitver "$PLUGIN_VERSION" '.[0] * .[1] | .kitVersion = $kitver' "$KITCFG.kit-new" "$KITCFG" \
626
+ # deep-merge: existing values win (preserve user choices), new REQUIRED keys added, version
627
+ # bumped. FEATURE blocks (plans/specKit/prePush/local/memory) are additive only when the
628
+ # project's config ALREADY has them — a missing feature key is a deliberate absence, and an
629
+ # upgrade must never inject profile defaults over it (#149).
630
+ jq -s --arg kitver "$PLUGIN_VERSION" '
631
+ .[1] as $have
632
+ | (.[0] | with_entries(.key as $k | select(
633
+ (["plans","specKit","prePush","local","memory"] | index($k)) == null
634
+ or ($have | has($k))))) as $tmpl
635
+ | $tmpl * $have | .kitVersion = $kitver' "$KITCFG.kit-new" "$KITCFG" \
619
636
  > "$KITCFG.merged" && mv "$KITCFG.merged" "$KITCFG"
620
637
  rm -f "$KITCFG.kit-new"
621
638
  # Existing values win in the merge — but an EXPLICIT --local flag is a user decision now,
@@ -732,6 +749,17 @@ if [[ "$MEMORY_BOOL" == "true" && $UPGRADE -eq 0 ]]; then
732
749
  emit "$KIT_ROOT/templates/hooks/mempal_precompact.sh.tmpl" "$TARGET/.claude/hooks/mempal_precompact.sh"
733
750
  emit "$KIT_ROOT/templates/hooks/mempal_followup.sh.tmpl" "$TARGET/.claude/hooks/mempal_followup.sh"
734
751
  chmod +x "$TARGET/.claude/hooks/mempal_session_start.sh" "$TARGET/.claude/hooks/mempal_save.sh" "$TARGET/.claude/hooks/mempal_precompact.sh" "$TARGET/.claude/hooks/mempal_followup.sh"
752
+ # Per-wing wake-up header — without it, `mempalace wake-up` shows the single global
753
+ # ~/.mempalace/identity.txt for every wing (the session-start hook swaps this in). See
754
+ # templates/rules/mempalace.md; `cckit doctor` re-seeds it if it goes missing.
755
+ _mpid="$TARGET/.claude/mempal-identity.$SLUG.txt"
756
+ if [[ ! -e "$_mpid" ]]; then
757
+ {
758
+ printf 'Project: %s (wing: %s)\n' "$NAME" "$SLUG"
759
+ [[ -n "$OWNER_NAME" ]] && printf 'Owner: %s\n' "$OWNER_NAME"
760
+ printf 'Stack: (describe this project — this header shows on every session wake-up)\n'
761
+ } > "$_mpid"
762
+ fi
735
763
  merge_settings --arg start "$TARGET/.claude/hooks/mempal_session_start.sh" --arg save "$TARGET/.claude/hooks/mempal_save.sh" --arg pre "$TARGET/.claude/hooks/mempal_precompact.sh" --arg fup "$TARGET/.claude/hooks/mempal_followup.sh" \
736
764
  '.hooks.SessionStart = [{matcher:"",hooks:[{type:"command",command:$start,timeout:30}]}]
737
765
  | .hooks.Stop = [{matcher:"",hooks:[{type:"command",command:$save,timeout:30}]}]
@@ -797,9 +825,17 @@ echo " + .claude/settings.local.json${HOOK_NOTE:+ (}${HOOK_NOTE# + }${HOOK_NOTE
797
825
  # Runs on BOTH scaffold and --upgrade so every update re-wires (fixes the class of bug where
798
826
  # /kit-update refreshed files but never re-ran the wiring → statusline/settings drifted). #369
799
827
  if [[ -f "$KIT_ROOT/scripts/kit-wire.sh" ]]; then
828
+ # On --upgrade an EXISTING .claude/statusline.sh follows the same contract as safe_write: the
829
+ # conffiles guard in kit-operate keeps a customized (or untracked) shim; only a shim the kit
830
+ # provably owns intact is refreshed (#149).
831
+ _SHIM="$TARGET/.claude/statusline.sh"
832
+ _shim_before=""; [[ -f "$_SHIM" ]] && _shim_before="$(cat "$_SHIM" 2>/dev/null)"
800
833
  if ( cd "$TARGET" && CLAUDE_PLUGIN_ROOT="$KIT_ROOT" KIT_ASSUME_YES=1 bash "$KIT_ROOT/scripts/kit-wire.sh" >/dev/null 2>&1 ); then
801
834
  echo " + wired: statusline shim + settings.statusLine (kit-wire)"
802
835
  fi
836
+ if [[ $UPGRADE -eq 1 && -n "$_shim_before" && "$_shim_before" == "$(cat "$_SHIM" 2>/dev/null)" ]]; then
837
+ UPGRADE_PRESERVED+=(".claude/statusline.sh")
838
+ fi
803
839
  fi
804
840
 
805
841
  # ---- summary -------------------------------------------------------------
@@ -2,7 +2,8 @@
2
2
  # kit-doctor — onboarding preflight: deps + brew bootstrap + gh auth/scopes + SSH guided
3
3
  #
4
4
  # Usage:
5
- # scripts/kit-doctor.sh # detect + auto-install + report
5
+ # scripts/kit-doctor.sh # detect + report; in a terminal, ASK before installing
6
+ # scripts/kit-doctor.sh --fix # install missing deps without asking (alias: --yes, -y)
6
7
  # scripts/kit-doctor.sh --dry-run # report only — no installs, no auth changes
7
8
  # scripts/kit-doctor.sh --no-install # check and auth only — skip package installs
8
9
  # scripts/kit-doctor.sh --dismiss-local # silence the "local layer down" session notice
@@ -21,14 +22,15 @@ set -euo pipefail
21
22
  _export_dir_doctor="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
22
23
 
23
24
  # ---- flags ------------------------------------------------------------------
24
- DRY_RUN=0; NO_INSTALL=0; DISMISS_LOCAL=0
25
+ DRY_RUN=0; NO_INSTALL=0; DISMISS_LOCAL=0; ASSUME_YES=0
25
26
  for _a in "$@"; do
26
27
  case "$_a" in
27
28
  --dry-run) DRY_RUN=1 ;;
28
29
  --no-install) NO_INSTALL=1 ;;
30
+ --fix|--yes|-y) ASSUME_YES=1 ;;
29
31
  --dismiss-local) DISMISS_LOCAL=1 ;;
30
32
  -h|--help)
31
- sed -n '2,12p' "$0" | grep '^#' | sed 's/^# \?//'
33
+ sed -n '2,13p' "$0" | grep '^#' | sed 's/^# \?//'
32
34
  exit 0 ;;
33
35
  esac
34
36
  done
@@ -37,7 +39,9 @@ done
37
39
  # Writes .local.dismissed = current kitVersion to kit.config.json; the SessionStart
38
40
  # notice stays silent until the kit's x.y core moves past it (issue #313).
39
41
  if [[ $DISMISS_LOCAL -eq 1 ]]; then
40
- _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
42
+ command -v kit_config_path >/dev/null 2>&1 || . "$(dirname "$0")/lib/config-path.sh"
43
+ _kitcfg="$(kit_config_path "${TARGET:-$PWD}" 2>/dev/null || true)"
44
+ [[ -n "$_kitcfg" ]] || _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
41
45
  if ! command -v jq >/dev/null 2>&1 || [[ ! -f "$_kitcfg" ]]; then
42
46
  echo "kit-doctor: cannot dismiss — need jq + $_kitcfg" >&2
43
47
  exit 1
@@ -82,6 +86,24 @@ else
82
86
  MARK_OK="ok"; MARK_FAIL="FAIL"; MARK_WARN="warn"; MARK_SKIP="-"; MARK_SEED="o"
83
87
  fi
84
88
 
89
+ # ---- install consent --------------------------------------------------------
90
+ # The doctor can install missing dependencies for you (Homebrew, gh, jq, node, …). When a HUMAN runs
91
+ # it in a terminal, ASK first — install only if approved. Non-interactive callers (init.sh preflight,
92
+ # hooks) pass --fix/--yes or simply have no TTY, so automation keeps its current auto-install behavior
93
+ # and never blocks on a prompt. --dry-run / --no-install already skip installs entirely.
94
+ if [[ $DRY_RUN -eq 0 && $NO_INSTALL -eq 0 && $ASSUME_YES -eq 0 && -t 0 ]]; then
95
+ printf '\n %s%scckit doctor can install anything missing for you%s (via Homebrew, corepack, etc.).\n' "$C_BOLD" "" "$C_RESET"
96
+ printf ' It will show each thing as it goes. Nothing is installed if you decline.\n\n'
97
+ printf ' Install missing dependencies? [Y/n] '
98
+ read -r _reply || _reply=""
99
+ case "$_reply" in
100
+ [nN]|[nN][oO])
101
+ NO_INSTALL=1
102
+ printf '\n %s report-only — listing what is missing and how to install it (no changes made).\n' "$MARK_SKIP" ;;
103
+ *) : ;; # default (Enter / y) → proceed with installs
104
+ esac
105
+ fi
106
+
85
107
  # ---- report accumulators ----------------------------------------------------
86
108
  CHECKS_OK=0; CHECKS_FAIL=0; CHECKS_WARN=0
87
109
  ACTIONS_TAKEN=() # things the doctor installed/fixed
@@ -374,7 +396,9 @@ printf '\n'
374
396
  # pipx; NEVER suggest plain pip. When mlx-lm is present but the server is down,
375
397
  # the doctor starts it in background + health-checks the port. --dry-run stays
376
398
  # 100% read-only: it reports what it would do, installs and starts nothing.
377
- _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
399
+ command -v kit_config_path >/dev/null 2>&1 || . "$(dirname "$0")/lib/config-path.sh"
400
+ _kitcfg="$(kit_config_path "${TARGET:-$PWD}" 2>/dev/null || true)"
401
+ [[ -n "$_kitcfg" ]] || _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
378
402
  _local_on="false"
379
403
  [[ -f "$_kitcfg" ]] && _local_on="$(jq -r '.local.enabled // false' "$_kitcfg" 2>/dev/null || echo false)"
380
404
  if [[ "$_local_on" == "true" ]]; then
@@ -482,6 +506,128 @@ if [[ "$_local_on" == "true" ]]; then
482
506
  printf '\n'
483
507
  fi
484
508
 
509
+ # ============================================================================
510
+ # MEMORY LAYER (MemPalace) — opt-in — only checked when .memory.enabled is true
511
+ # ============================================================================
512
+ # Same gating principle as the local model layer: silent unless the project opted
513
+ # into memory at init. Three things to verify:
514
+ # 1. the `mempalace` CLI is installed — the SessionStart/Stop/… hooks no-op without it.
515
+ # 2. a per-wing identity header exists. `mempalace wake-up` scopes the L1 *body* to the
516
+ # wing, but reads its L0 identity *header* from the single global ~/.mempalace/identity.txt
517
+ # (mempalace layers.py Layer0), so every wing shows the same — usually wrong — header
518
+ # unless .claude/mempal-identity.<wing>.txt is present. --fix seeds a starter from kit.config.
519
+ # 3. the session-start hook is current — older hooks just ran `wake-up --wing` and could not
520
+ # apply the per-wing header from (2). --fix re-emits the hook from the kit template.
521
+ _mem_on="false"
522
+ [[ -f "$_kitcfg" ]] && _mem_on="$(jq -r '.memory.enabled // false' "$_kitcfg" 2>/dev/null || echo false)"
523
+ if [[ "$_mem_on" == "true" ]]; then
524
+ printf ' %s%sMemory (MemPalace)%s\n' "$C_BOLD" "" "$C_RESET"
525
+ _mwing="$(jq -r '.memory.wing // .project.slug // ""' "$_kitcfg" 2>/dev/null || echo "")"
526
+ [[ -z "$_mwing" || "$_mwing" == "null" ]] && _mwing="$(basename "${TARGET:-$PWD}")"
527
+
528
+ # 1. mempalace CLI — install it (guarded) when memory is on but the CLI is missing; the
529
+ # SessionStart/Stop/… hooks are silent no-ops without it. MemPalace is a Python CLI
530
+ # (github.com/MemPalace/mempalace); install into an isolated tool venv via pipx (fallback uv).
531
+ # Installs obey the same consent guard as every other dep: skipped under --dry-run/--no-install
532
+ # or when the operator declined the install prompt.
533
+ _mp_find() { # pipx/uv drop the bin in ~/.local/bin, which may not be on PATH yet this session
534
+ if has_cmd mempalace; then command -v mempalace
535
+ elif [[ -x "$HOME/.local/bin/mempalace" ]]; then echo "$HOME/.local/bin/mempalace"
536
+ fi
537
+ return 0
538
+ }
539
+ _mp_bin="$(_mp_find)"
540
+ if [[ -n "$_mp_bin" ]]; then
541
+ _mv="$("$_mp_bin" --version 2>/dev/null | head -1)"; [[ -n "$_mv" ]] || _mv="installed"
542
+ row "$MARK_OK" "mempalace CLI" "$_mv"
543
+ CHECKS_OK=$((CHECKS_OK + 1))
544
+ elif [[ $DRY_RUN -eq 1 || $NO_INSTALL -eq 1 ]]; then
545
+ row "$MARK_FAIL" "mempalace CLI" "missing — pipx install mempalace"
546
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
547
+ ACTIONS_NEEDED+=("Install MemPalace: pipx install mempalace (then: mempalace mcp)")
548
+ else
549
+ # ensure an installer: pipx preferred (brew-installable), uv as fallback. NEVER plain pip.
550
+ if ! has_cmd pipx && ! has_cmd uv; then
551
+ brew_install pipx pipx && ACTIONS_TAKEN+=("Installed pipx via brew") || true
552
+ fi
553
+ if has_cmd pipx; then
554
+ printf ' %s mempalace missing — installing via pipx (isolated venv)...\n' "$MARK_WARN"
555
+ pipx install mempalace >/dev/null 2>&1 || true
556
+ _mp_installer="pipx"
557
+ elif has_cmd uv; then
558
+ printf ' %s mempalace missing — installing via uv tool install (isolated venv)...\n' "$MARK_WARN"
559
+ uv tool install mempalace >/dev/null 2>&1 || true
560
+ _mp_installer="uv tool install"
561
+ fi
562
+ _mp_bin="$(_mp_find)"
563
+ if [[ -n "$_mp_bin" ]]; then
564
+ _mv="$("$_mp_bin" --version 2>/dev/null | head -1)"; [[ -n "$_mv" ]] || _mv="installed"
565
+ row "$MARK_OK" "mempalace CLI" "$_mv (via ${_mp_installer:-pipx})"
566
+ CHECKS_OK=$((CHECKS_OK + 1))
567
+ ACTIONS_TAKEN+=("Installed MemPalace via ${_mp_installer:-pipx} — run 'mempalace mcp' to wire the MCP server")
568
+ else
569
+ row "$MARK_FAIL" "mempalace CLI" "install failed — install pipx, then: pipx install mempalace"
570
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
571
+ ACTIONS_NEEDED+=("Install MemPalace: pipx install mempalace (then: mempalace mcp)")
572
+ fi
573
+ fi
574
+
575
+ # 2. per-wing identity header — the fix for the global-header bug
576
+ _idfile="${TARGET:-$PWD}/.claude/mempal-identity.${_mwing}.txt"
577
+ _idfile_generic="${TARGET:-$PWD}/.claude/mempal-identity.txt"
578
+ if [[ -s "$_idfile" ]] || [[ -s "$_idfile_generic" ]]; then
579
+ _present="$_idfile"; [[ -s "$_idfile" ]] || _present="$_idfile_generic"
580
+ row "$MARK_OK" "identity header" "wing-scoped (${_present#${TARGET:-$PWD}/})"
581
+ CHECKS_OK=$((CHECKS_OK + 1))
582
+ elif [[ $DRY_RUN -eq 0 && $NO_INSTALL -eq 0 ]]; then
583
+ # Seed a starter header from kit.config so this wing stops inheriting the global identity.
584
+ _owner="$(jq -r '.project.owner // ""' "$_kitcfg" 2>/dev/null || echo "")"
585
+ _pname="$(jq -r '.project.name // ""' "$_kitcfg" 2>/dev/null || echo "")"
586
+ [[ -z "$_pname" || "$_pname" == "null" ]] && _pname="$_mwing"
587
+ {
588
+ printf 'Project: %s (wing: %s)\n' "$_pname" "$_mwing"
589
+ [[ -n "$_owner" && "$_owner" != "null" ]] && printf 'Owner: %s\n' "$_owner"
590
+ printf 'Stack: (describe this project — this header shows on every session wake-up)\n'
591
+ } > "$_idfile"
592
+ row "$MARK_OK" "identity header" "seeded .claude/mempal-identity.${_mwing}.txt — edit the Stack line"
593
+ ACTIONS_TAKEN+=("Seeded per-wing MemPalace header .claude/mempal-identity.${_mwing}.txt (edit it to taste)")
594
+ CHECKS_OK=$((CHECKS_OK + 1))
595
+ else
596
+ row "$MARK_WARN" "identity header" "missing — wake-up shows the global ~/.mempalace/identity.txt for every wing"
597
+ CHECKS_WARN=$((CHECKS_WARN + 1))
598
+ ACTIONS_NEEDED+=("Create .claude/mempal-identity.${_mwing}.txt so this wing has its own wake-up header (or run: cckit doctor --fix)")
599
+ fi
600
+
601
+ # 3. session-start hook freshness — the `mempal-identity` marker means the hook
602
+ # knows how to swap in the per-wing header (2). Older hooks lack it.
603
+ _hook="${TARGET:-$PWD}/.claude/hooks/mempal_session_start.sh"
604
+ _kit_root="$(dirname "$_export_dir_doctor")"
605
+ _hook_tmpl="$_kit_root/templates/hooks/mempal_session_start.sh.tmpl"
606
+ if [[ ! -f "$_hook" ]]; then
607
+ : # no hook installed — the CLI row already covers a non-functioning memory layer
608
+ elif grep -q 'mempal-identity' "$_hook" 2>/dev/null; then
609
+ row "$MARK_OK" "session-start hook" "current — applies the per-wing header"
610
+ CHECKS_OK=$((CHECKS_OK + 1))
611
+ elif [[ $DRY_RUN -eq 0 && $NO_INSTALL -eq 0 && -f "$_hook_tmpl" ]]; then
612
+ # Re-emit from the template (only {{WING}} to substitute; no IF blocks in this hook).
613
+ if sed "s|{{WING}}|${_mwing}|g" "$_hook_tmpl" > "$_hook"; then
614
+ chmod +x "$_hook"
615
+ row "$MARK_OK" "session-start hook" "refreshed — now applies the per-wing header"
616
+ ACTIONS_TAKEN+=("Refreshed .claude/hooks/mempal_session_start.sh (now swaps in the per-wing header)")
617
+ CHECKS_OK=$((CHECKS_OK + 1))
618
+ else
619
+ row "$MARK_WARN" "session-start hook" "stale — refresh failed; re-run: cckit init --upgrade"
620
+ CHECKS_WARN=$((CHECKS_WARN + 1))
621
+ ACTIONS_NEEDED+=("Refresh the session-start hook manually: cckit init --upgrade")
622
+ fi
623
+ else
624
+ row "$MARK_WARN" "session-start hook" "stale — ignores the per-wing header (runs wake-up --wing only)"
625
+ CHECKS_WARN=$((CHECKS_WARN + 1))
626
+ ACTIONS_NEEDED+=("Refresh the session-start hook: cckit doctor --fix (or cckit init --upgrade)")
627
+ fi
628
+ printf '\n'
629
+ fi
630
+
485
631
  # ============================================================================
486
632
  # AUTH + CONFIG
487
633
  # ============================================================================
@@ -570,6 +716,31 @@ else
570
716
  CHECKS_FAIL=$((CHECKS_FAIL + 1))
571
717
  ACTIONS_NEEDED+=("Set git email: git config --global user.email \"you@example.com\"")
572
718
  fi
719
+
720
+ # ---- base branch vs GitHub default -----------------------------------------
721
+ # `Closes #N` auto-close only fires when a PR merges into the repo's DEFAULT branch. If this
722
+ # project integrates on a non-default branch (github.baseBranch, e.g. develop) that mismatch
723
+ # silently leaves issues open on native/UI merges. cckit's own `pr-merge` closes them explicitly,
724
+ # but the misalignment still bites anyone who merges from the GitHub UI — so surface it.
725
+ if [[ $GH_AUTHED -eq 1 ]] && has_cmd gh && [[ -f "$_kitcfg" ]]; then
726
+ _cfg_repo="$(jq -r '.github.repo // empty' "$_kitcfg" 2>/dev/null || true)"
727
+ # Same fallback chain as load_kit_config (#117) so the warning judges the branch cckit actually
728
+ # integrates on: baseBranch -> integrationBranch -> flow -> "main".
729
+ _cfg_base="$(jq -r '.github.baseBranch // .github.integrationBranch // .github.flow // "main"' "$_kitcfg" 2>/dev/null || echo main)"
730
+ if [[ -n "$_cfg_repo" ]]; then
731
+ _gh_default="$(gh repo view "$_cfg_repo" --json defaultBranchRef --jq '.defaultBranchRef.name' 2>/dev/null || true)"
732
+ if [[ -z "$_gh_default" ]]; then
733
+ row "$MARK_SKIP" "base branch" "couldn't read GitHub default for $_cfg_repo — skipped"
734
+ elif [[ "$_cfg_base" == "$_gh_default" ]]; then
735
+ row "$MARK_OK" "base branch" "$_cfg_base = GitHub default"
736
+ CHECKS_OK=$((CHECKS_OK + 1))
737
+ else
738
+ row "$MARK_WARN" "base branch" "baseBranch '$_cfg_base' ≠ GitHub default '$_gh_default' — 'Closes #N' won't auto-close on GitHub-UI merges"
739
+ CHECKS_WARN=$((CHECKS_WARN + 1))
740
+ ACTIONS_NEEDED+=("Align base branch: 'gh repo edit $_cfg_repo --default-branch $_cfg_base' (or set github.baseBranch to '$_gh_default'). Note: 'cckit pr-merge' already closes linked issues explicitly.")
741
+ fi
742
+ fi
743
+ fi
573
744
  printf '\n'
574
745
 
575
746
  # ============================================================================
@@ -654,9 +825,16 @@ if [[ ${#ACTIONS_NEEDED[@]} -gt 0 ]]; then
654
825
  fi
655
826
  printf '\n'
656
827
 
657
- # ---- onboarding page -------------------------------------------------------
828
+ # ---- onboarding / docs pointer ---------------------------------------------
829
+ # Show the local onboarding app ONLY when something actually answers on it —
830
+ # otherwise point at the public docs. (Previously this always printed
831
+ # http://localhost:3001/onboarding even when nothing served that port.)
658
832
  _admin_url="${CCKIT_ADMIN_URL:-http://localhost:3001}"
659
- printf ' %sOnboarding guide (web): %s/onboarding%s\n' "$C_DIM" "$_admin_url" "$C_RESET"
833
+ if has_cmd curl && curl -fsS --max-time 1 "$_admin_url/onboarding" >/dev/null 2>&1; then
834
+ printf ' %sOnboarding guide (web): %s/onboarding%s\n' "$C_DIM" "$_admin_url" "$C_RESET"
835
+ else
836
+ printf ' %sDocs & quick start: %shttps://cckit.vercel.app%s\n' "$C_DIM" "" "$C_RESET"
837
+ fi
660
838
  printf '\n'
661
839
 
662
840
  # Exit non-zero when critical checks failed
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kit-version-check-test.sh — covers `cckit update` self-version resolution (#124). The check must
4
+ # resolve the RUNNING install's plugin.json from the script's own dir (it ships at <install>/scripts/)
5
+ # — not only via a ~/.claude/plugins glob that matched claude-kit* and never a cckit install, so
6
+ # `cckit update` silently no-op'd. Hermetic: a throwaway target config; CLAUDE_PLUGIN_ROOT unset so
7
+ # only the self-resolution can find the version. Run: bash scripts/kit-version-check-test.sh
8
+ set -u
9
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
10
+ SCRIPT="$ROOT/scripts/kit-version-check.sh"
11
+ fail=0
12
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
13
+ command -v jq >/dev/null 2>&1 || { echo "kit-version-check-test: jq required — skipping"; exit 0; }
14
+
15
+ INSTALLED="$(jq -r '.version // "0.0.0"' "$ROOT/.claude-plugin/plugin.json" 2>/dev/null || echo 0.0.0)"
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+
18
+ # A project recorded BEHIND the installed cckit → the check must self-resolve the install version and
19
+ # signal "behind" (exit 10), instead of exiting 0 because a plugin-dir glob found nothing.
20
+ printf '{"kitVersion":"0.0.1"}' > "$tmp/cckit.config.json"
21
+ out="$(env -u CLAUDE_PLUGIN_ROOT bash "$SCRIPT" --target "$tmp" 2>&1)"; rc=$?
22
+ t "behind project → exit 10 (self-resolved, not a silent no-op)" "$rc" "10"
23
+ case "$out" in *"$INSTALLED"*) echo "ok: notice names the resolved install version ($INSTALLED)" ;; *) echo "FAIL: notice lacks install version: $out"; fail=1 ;; esac
24
+
25
+ # A project recorded AT the installed version → up to date (exit 0), still self-resolved.
26
+ printf '{"kitVersion":"%s"}' "$INSTALLED" > "$tmp/cckit.config.json"
27
+ env -u CLAUDE_PLUGIN_ROOT bash "$SCRIPT" --target "$tmp" >/dev/null 2>&1
28
+ t "at-version project → exit 0 (up to date)" "$?" "0"
29
+
30
+ # No config at the target → safe no-op (exit 0), never an error.
31
+ rm -f "$tmp/cckit.config.json"
32
+ env -u CLAUDE_PLUGIN_ROOT bash "$SCRIPT" --target "$tmp" >/dev/null 2>&1
33
+ t "no config → safe no-op (exit 0)" "$?" "0"
34
+
35
+ [ "$fail" -eq 0 ] && echo "ALL OK (kit-version-check)" || echo "kit-version-check: FAILURES"
36
+ exit "$fail"
@@ -17,14 +17,29 @@ while [[ $# -gt 0 ]]; do
17
17
  done
18
18
 
19
19
  command -v jq >/dev/null 2>&1 || exit 0
20
- cfg="$TARGET/cckit.config.json"; [[ -f "$cfg" ]] || cfg="$TARGET/.claude/kit.config.json"
21
- [[ -f "$cfg" ]] || exit 0
20
+ # Resolve the target project's config via the ONE shared resolver (config-path.sh, #69).
21
+ # shellcheck source=/dev/null
22
+ . "$(dirname "$0")/lib/config-path.sh"
23
+ cfg="$(kit_config_find "$TARGET" 2>/dev/null || true)"
24
+ [[ -n "$cfg" && -f "$cfg" ]] || exit 0
22
25
 
23
- # Locate the installed plugin's plugin.json: explicit root → env → best-effort glob.
26
+ # Locate the installed cckit's plugin.json. Order (first hit wins):
27
+ # 1. explicit --plugin-root / CLAUDE_PLUGIN_ROOT
28
+ # 2. THIS script's own install root — kit-version-check.sh ships at <install>/scripts/, so
29
+ # <install>/.claude-plugin/plugin.json is the version of the cckit that is actually running.
30
+ # This is the reliable self-resolution for a Homebrew/symlink/`cckit update` install, which the
31
+ # plugin-dir glob below never matched (it only looked for claude-kit* under ~/.claude/plugins).
32
+ # 3. best-effort glob over installed plugins — cckit* first, then legacy claude-kit*.
24
33
  pj=""
25
34
  [[ -n "$PLUGIN_ROOT" && -f "$PLUGIN_ROOT/.claude-plugin/plugin.json" ]] && pj="$PLUGIN_ROOT/.claude-plugin/plugin.json"
26
35
  if [[ -z "$pj" ]]; then
27
- pj="$(ls -t "$HOME"/.claude/plugins/*/claude-kit*/.claude-plugin/plugin.json \
36
+ _self_dir="$(cd -- "$(dirname -- "$0")" >/dev/null 2>&1 && pwd)"
37
+ [[ -n "$_self_dir" && -f "$_self_dir/../.claude-plugin/plugin.json" ]] && pj="$_self_dir/../.claude-plugin/plugin.json"
38
+ fi
39
+ if [[ -z "$pj" ]]; then
40
+ pj="$(ls -t "$HOME"/.claude/plugins/*/cckit*/.claude-plugin/plugin.json \
41
+ "$HOME"/.claude/plugins/*/*/cckit*/.claude-plugin/plugin.json \
42
+ "$HOME"/.claude/plugins/*/claude-kit*/.claude-plugin/plugin.json \
28
43
  "$HOME"/.claude/plugins/*/*/claude-kit*/.claude-plugin/plugin.json \
29
44
  "$HOME"/.claude/plugins/*/*/claude-kit*/*/.claude-plugin/plugin.json \
30
45
  "$HOME"/.claude/plugins/*/*/*/claude-kit*/.claude-plugin/plugin.json 2>/dev/null | head -1 || true)"
@@ -92,7 +92,10 @@ kit_wire() {
92
92
  _kit_op_say "kit-wire: plugin root = $proot"
93
93
  mkdir -p .claude
94
94
  # 1. statusline shim (tier B — CLI only). kit_op_write_content runs the conffiles machine.
95
- _kit_shim_content | kit_op_write_content "$shim" B wire || return 1
95
+ # rc 10 = kept: a customized/untracked existing shim is PRESERVED (#149) — wiring continues;
96
+ # only a real error aborts. A project that repointed its shim keeps it across updates.
97
+ _kit_shim_content | kit_op_write_content "$shim" B wire
98
+ case $? in 0|10) ;; *) return 1;; esac
96
99
  [ -f "$shim" ] && [ -z "${KIT_DRY_RUN:-}" ] && chmod +x "$shim"
97
100
  # 2. settings statusLine -> shim
98
101
  _kit_wire_settings || true
@@ -15,7 +15,10 @@ ok() { echo "ok $1"; }
15
15
 
16
16
  # ---- config (tolerant: defaults if config/lib absent) ----------------------
17
17
  KNOWLEDGE_DIR="knowledge"; PLANS_DIR=""; PLANS_FORMAT=""
18
- if [[ -f scripts/lib/kit-config.sh && ( -f .claude/kit.config.json || -f cckit.config.json ) ]]; then
18
+ # ONE shared config discovery (config-path.sh, #69) — recognizes KIT_CONFIG, a root cckit.config.json,
19
+ # or a .claude/kit.config.json (walk up), instead of a CWD-only inline check.
20
+ . scripts/lib/config-path.sh 2>/dev/null || true
21
+ if [[ -f scripts/lib/kit-config.sh ]] && kit_config_path >/dev/null 2>&1; then
19
22
  source scripts/lib/kit-config.sh
20
23
  load_kit_config >/dev/null 2>&1 || true
21
24
  KNOWLEDGE_DIR="${KIT_KNOWLEDGE_DIR:-knowledge}"
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # board-view-test.sh — covers the pure board-view render helpers (#122): the merge-ordered open-PR
4
+ # queue, the stale flag, the not-on-board flag, and Project Status lookup. Hermetic: canned JSON,
5
+ # no gh. Run: bash scripts/lib/board-view-test.sh
6
+ set -u
7
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8
+ LIB="$ROOT/scripts/lib"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> output lacks '$3'"; fail=1 ;; esac; }
12
+ command -v jq >/dev/null 2>&1 || { echo "board-view-test: jq required — skipping"; exit 0; }
13
+
14
+ # shellcheck source=/dev/null
15
+ source "$LIB/board-view.sh"
16
+
17
+ # ── merge queue ordering: ready(1) → draft(2) → blocked(3); within a tier risk:low first, size asc ─
18
+ PRS='[
19
+ {"number":10,"title":"blocked one","labels":[{"name":"risk:low"},{"name":"size:S"},{"name":"blocked"}],"isDraft":false,"headRefName":"feat/10","reviewDecision":"APPROVED","mergeable":"MERGEABLE"},
20
+ {"number":11,"title":"draft one","labels":[{"name":"risk:low"},{"name":"size:XS"}],"isDraft":true,"headRefName":"feat/11","reviewDecision":null,"mergeable":"MERGEABLE"},
21
+ {"number":12,"title":"ready high risk","labels":[{"name":"risk:high"},{"name":"size:S"}],"isDraft":false,"headRefName":"claude/12","reviewDecision":"APPROVED","mergeable":"MERGEABLE"},
22
+ {"number":13,"title":"ready low risk L","labels":[{"name":"risk:low"},{"name":"size:L"}],"isDraft":false,"headRefName":"feat/13","reviewDecision":"APPROVED","mergeable":"MERGEABLE"},
23
+ {"number":14,"title":"ready low risk S","labels":[{"name":"risk:low"},{"name":"size:S"}],"isDraft":false,"headRefName":"feat/14","reviewDecision":"APPROVED","mergeable":"MERGEABLE"}
24
+ ]'
25
+ MQ="$(board_merge_queue "$PRS")"
26
+ order="$(printf '%s' "$MQ" | grep -oE '#1[0-4]' | tr '\n' ' ')"
27
+ t "merge queue orders ready(risk asc,size asc) → draft → blocked" "$order" "#14 #13 #12 #11 #10 "
28
+ has "ready PR marked ● ready" "$MQ" "● ready"
29
+ has "draft PR marked · draft" "$MQ" "· draft"
30
+ has "blocked PR marked ▪ blocked" "$MQ" "▪ blocked"
31
+ has "agent branch flagged ● agent" "$MQ" "● agent"
32
+
33
+ # empty PR set renders the no-open-PRs row, not an error.
34
+ has "empty merge queue renders a friendly row" "$(board_merge_queue '[]')" "no open PRs ✓"
35
+
36
+ # ── stale flag: > N days no activity, most-stale first ──────────────────────────────────────────
37
+ NOW="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
38
+ OLD20="$(date -u -v-20d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '20 days ago' +%Y-%m-%dT%H:%M:%SZ)"
39
+ OLD40="$(date -u -v-40d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '40 days ago' +%Y-%m-%dT%H:%M:%SZ)"
40
+ ISS="[{\"number\":1,\"updatedAt\":\"$OLD20\"},{\"number\":2,\"updatedAt\":\"$NOW\"},{\"number\":3,\"updatedAt\":\"$OLD40\"}]"
41
+ sl="$(board_stale_list "$ISS" 14)"
42
+ t "stale list picks the >14d issues, most-stale first" "${sl%% *}" "#3(40d)"
43
+ has "stale list includes the 20d issue" "$sl" "#1(20d)"
44
+ case "$sl" in *"#2"*) echo "FAIL: fresh issue wrongly flagged stale"; fail=1 ;; *) echo "ok: fresh issue not flagged stale" ;; esac
45
+ t "no stale issues yields empty (caller renders none)" "$(board_stale_list "[{\"number\":9,\"updatedAt\":\"$NOW\"}]" 14)" ""
46
+
47
+ # ── not-on-board + status lookup ────────────────────────────────────────────────────────────────
48
+ t "not_on_board lists issues absent from the board map" "$(board_not_on_board '[{"number":1},{"number":2},{"number":3}]' '{"1":"Todo","3":"Done"}')" "#2"
49
+ t "not_on_board empty when all issues are on the board" "$(board_not_on_board '[{"number":1}]' '{"1":"Todo"}')" ""
50
+ t "status_for returns the board status" "$(board_status_for 3 '{"1":"Todo","3":"Done"}')" "Done"
51
+ t "status_for returns — for an off-board issue" "$(board_status_for 9 '{"1":"Todo"}')" "—"
52
+
53
+ [ "$fail" -eq 0 ] && echo "ALL OK (board-view)" || echo "board-view: FAILURES"
54
+ exit "$fail"
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # board-view.sh — pure render helpers for the read-only board view (`cckit sync`). Each takes JSON
4
+ # and emits markdown/text; none call gh, so they are unit-testable with canned fixtures (#122).
5
+ # Ported from the host project's board view: a merge-ordered open-PR queue, a stale-issue flag, a
6
+ # not-on-board flag, and Project Status per issue. bash 3.2 + zsh safe. Requires jq.
7
+
8
+ # board_merge_queue <prs-json> — render the open-PR merge queue as a markdown table. <prs-json> is
9
+ # `gh pr list --json number,title,labels,isDraft,headRefName,reviewDecision,mergeable` output.
10
+ # Ordering answers "in what order do I merge?": ready(1) -> draft(2) -> blocked(3); within a tier,
11
+ # risk:low first, then smaller size, then issue number. Risk/size come from risk:/size: labels; a
12
+ # `blocked` label marks blocked. An agent branch (agent|claude|auto/*) or an agent:auto label flags a
13
+ # row as bot-authored so a human checks it before starting overlapping work.
14
+ board_merge_queue() {
15
+ local prs="${1:-[]}" rows tab; tab="$(printf '\t')"
16
+ rows="$(printf '%s' "$prs" | jq -r '
17
+ def lbl($p): (($p.labels // []) | map(.name));
18
+ def risk($l): ($l | map(select(startswith("risk:"))) | first // "risk:med" | ltrimstr("risk:"));
19
+ def size($l): ($l | map(select(startswith("size:"))) | first // "" | ltrimstr("size:"));
20
+ def riskRank($r): if $r=="low" then 0 elif $r=="med" then 1 else 2 end;
21
+ def sizeRank($s): ({"XS":0,"S":1,"M":2,"L":3,"XL":4}[$s] // 2);
22
+ map( . as $p | lbl($p) as $l
23
+ | (risk($l)) as $risk | (size($l)) as $size
24
+ | (any($l[]; . == "blocked")) as $blocked
25
+ | (((($p.headRefName // "") | test("^(agent|claude|auto)/")) or (any($l[]; . == "agent:auto")))) as $agent
26
+ | (if $blocked then 3 elif ($p.isDraft // false) then 2 else 1 end) as $ready
27
+ | { n:$p.number, title:$p.title, risk:$risk,
28
+ size:(if $size=="" then "—" else $size end),
29
+ blocked:$blocked, draft:($p.isDraft // false), agent:$agent,
30
+ conflict:($p.mergeable == "CONFLICTING"), approved:($p.reviewDecision == "APPROVED"),
31
+ ready:$ready, rr:riskRank($risk), sr:sizeRank($size) } )
32
+ | sort_by(.ready, .rr, .sr, .n)
33
+ | .[]
34
+ | [ ("#" + (.n|tostring)), .risk, .size,
35
+ (if .blocked then "▪ blocked" elif .draft then "· draft" elif .conflict then "◆ conflict"
36
+ elif .approved then "● ready" else "· needs review" end),
37
+ (if .agent then "● agent" else "·" end),
38
+ (if (.title|length) > 48 then (.title[0:48] + "…") else .title end) ] | @tsv')"
39
+ printf '### Merge Queue (open PRs — merge top-down)\n'
40
+ printf '| PR | Risk | Size | State | Who | Title |\n|---|---|---|---|---|---|\n'
41
+ if [ -z "$rows" ]; then
42
+ printf '| — | | | no open PRs ✓ | | |\n'
43
+ else
44
+ while IFS="$tab" read -r pr risk size state who title; do
45
+ [ -z "$pr" ] && continue
46
+ printf '| %s | %s | %s | %s | %s | %s |\n' "$pr" "$risk" "$size" "$state" "$who" "$title"
47
+ done <<EOF
48
+ $rows
49
+ EOF
50
+ fi
51
+ printf '\n_Order: ready → draft → blocked; within that, risk:low first, then smaller size. ● agent = a bot branch — check it before starting overlapping work._\n'
52
+ }
53
+
54
+ # board_stale_list <issues-json> [days] — space-joined "#N(Dd)" tokens for open issues untouched for
55
+ # more than [days] (default 14), most-stale first. Empty when none. <issues-json> is
56
+ # `gh issue list --json number,updatedAt`. The caller renders the "none ✓" fallback.
57
+ board_stale_list() {
58
+ local issues="${1:-[]}" days="${2:-14}" now
59
+ now="$(date -u +%s 2>/dev/null || echo 0)"
60
+ printf '%s' "$issues" | jq -r --argjson now "$now" --argjson d "$days" '
61
+ [ .[]
62
+ | (($now - ((.updatedAt // "1970-01-01T00:00:00Z") | fromdateiso8601)) / 86400 | floor) as $age
63
+ | select($age > $d) | {n:.number, age:$age} ]
64
+ | sort_by(-.age) | map("#\(.n)(\(.age)d)") | join(" ")'
65
+ }
66
+
67
+ # board_not_on_board <issues-json> <status-map-json> — space-joined "#N" for open issues that have
68
+ # NO Project Status (absent from the board map), so an adopter sees which issues never got added to
69
+ # the board. <status-map-json> is {"<number>":"<status>", …}. Empty when all issues are on the board.
70
+ board_not_on_board() {
71
+ local issues="${1:-[]}" map="${2:-{\}}"
72
+ printf '%s' "$issues" | jq -r --argjson m "$map" '
73
+ [ .[] | select(($m[(.number|tostring)] // null) == null) | "#\(.number)" ] | join(" ")'
74
+ }
75
+
76
+ # board_status_for <number> <status-map-json> — echo the issue's Project Status, or "—" when the
77
+ # issue is not on the board (or the board is off). Used to annotate each issue row with its Status.
78
+ board_status_for() {
79
+ printf '%s' "${2:-{\}}" | jq -r --arg n "$1" '.[$n] // "—"'
80
+ }
@@ -37,8 +37,26 @@ if [ -n "${CAP_TEST_INNER:-}" ]; then
37
37
  eq "act failing" "$(cap_action CHECKS_FAILING)" "fix"
38
38
  eq "act pending" "$(cap_action CHECKS_PENDING)" "wait"
39
39
  eq "act draft" "$(cap_action DRAFT)" "wait"
40
+ eq "act held" "$(cap_action HELD)" "hold"
40
41
  eq "act blocked" "$(cap_action BLOCKED)" "skip"
41
42
 
43
+ # cap_policy_floor — floors that block an unattended auto-merge (default ON). Non-empty = held.
44
+ nl="$(printf '\n')"
45
+ eq "floor: clean PR merges" "$(KIT_CAPTAIN_FLOORS= KIT_CAPTAIN_EXTRA_GLOBS= cap_policy_floor "src/app.ts${nl}README.md" "")" ""
46
+ neq() { if [ -z "$2" ]; then echo "FAIL($CAP_TEST_INNER): $1 -> empty, want non-empty"; fail=1; fi; }
47
+ neq "floor: workflow file held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor ".github/workflows/ci.yml" "")"
48
+ neq "floor: pnpm-lock held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "pnpm-lock.yaml" "")"
49
+ neq "floor: package.json held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "apps/web/package.json" "")"
50
+ neq "floor: workspace yaml held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "pnpm-workspace.yaml" "")"
51
+ neq "floor: turbo.json held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "turbo.json" "")"
52
+ neq "floor: pem held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "certs/server.pem" "")"
53
+ neq "floor: dotenv held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor ".env.production" "")"
54
+ neq "floor: secrets path held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "config/secrets/db.yml" "")"
55
+ neq "floor: hold label held" "$(KIT_CAPTAIN_FLOORS= cap_policy_floor "src/app.ts" "priority:p1 hold")"
56
+ neq "floor: extra glob held" "$(KIT_CAPTAIN_FLOORS= KIT_CAPTAIN_EXTRA_GLOBS='migrations/*' cap_policy_floor "migrations/001.sql" "")"
57
+ # a disabling override lets even a workflow file through (config/CLI can opt out).
58
+ eq "floor: KIT_CAPTAIN_FLOORS=0 disables" "$(KIT_CAPTAIN_FLOORS=0 cap_policy_floor ".github/workflows/ci.yml" "hold")" ""
59
+
42
60
  # _cap_issue_of_branch — pull the issue number out of a flow branch.
43
61
  eq "branch task" "$(_cap_issue_of_branch 'task/47-admin-clerk')" "47"
44
62
  eq "branch fix" "$(_cap_issue_of_branch 'fix/9-roadmap')" "9"