@jeiemgi/cckit 0.2.0 → 0.3.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 (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +21 -8
  3. package/README.md +63 -5
  4. package/bin/cckit +37 -16
  5. package/cckit.config.json +1 -1
  6. package/commands/kit-doctor.md +3 -1
  7. package/kit.config.schema.json +24 -0
  8. package/package.json +1 -1
  9. package/scripts/annotate-setup.sh +7 -2
  10. package/scripts/capture-project-ids.sh +23 -10
  11. package/scripts/init.sh +22 -4
  12. package/scripts/kit-doctor.sh +185 -7
  13. package/scripts/kit-version-check-test.sh +36 -0
  14. package/scripts/kit-version-check.sh +19 -4
  15. package/scripts/knowledge-lint.sh +4 -1
  16. package/scripts/lib/board-view-test.sh +54 -0
  17. package/scripts/lib/board-view.sh +80 -0
  18. package/scripts/lib/captain-test.sh +18 -0
  19. package/scripts/lib/captain.sh +92 -5
  20. package/scripts/lib/config-path-test.sh +47 -0
  21. package/scripts/lib/config-path.sh +29 -0
  22. package/scripts/lib/copilot.sh +9 -9
  23. package/scripts/lib/effort-metrics-test.sh +57 -0
  24. package/scripts/lib/effort-metrics.sh +19 -5
  25. package/scripts/lib/effort-ops-test.sh +51 -2
  26. package/scripts/lib/effort-ops.sh +314 -49
  27. package/scripts/lib/effort-parity-test.sh +128 -0
  28. package/scripts/lib/effort-slug-test.sh +87 -0
  29. package/scripts/lib/effort-slug.sh +104 -0
  30. package/scripts/lib/effort.sh +34 -0
  31. package/scripts/lib/gh-project-test.sh +95 -0
  32. package/scripts/lib/gh-project.sh +22 -7
  33. package/scripts/lib/git-remote-test.sh +57 -0
  34. package/scripts/lib/git-remote.sh +21 -0
  35. package/scripts/lib/kit-config-test.sh +37 -0
  36. package/scripts/lib/kit-config.sh +33 -13
  37. package/scripts/lib/kit-events.sh +5 -3
  38. package/scripts/lib/kit-gc-test.sh +88 -0
  39. package/scripts/lib/kit-gc.sh +136 -19
  40. package/scripts/lib/kit-local.sh +8 -1
  41. package/scripts/lib/next.sh +3 -3
  42. package/scripts/lib/plan-next-test.sh +87 -0
  43. package/scripts/lib/plan-next.sh +212 -0
  44. package/scripts/lib/project-scan.sh +7 -1
  45. package/scripts/lib/worktree-start.sh +12 -3
  46. package/scripts/lib/zsh-safety-test.sh +73 -0
  47. package/scripts/portable-test.sh +62 -20
  48. package/scripts/setup-labels.sh +13 -2
  49. package/scripts/showcase.sh +13 -4
  50. package/scripts/status-test.sh +63 -0
  51. package/scripts/status.sh +12 -4
  52. package/scripts/task-sync.sh +79 -10
  53. package/skills/kit-autopilot/SKILL.md +5 -0
  54. package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
  55. package/skills/kit-effort-new/SKILL.md +39 -111
  56. package/skills/kit-effort-pr/SKILL.md +6 -2
  57. package/skills/kit-next/SKILL.md +4 -0
  58. package/skills/kit-plan-next/SKILL.md +82 -0
  59. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  60. package/templates/rules/effort-model.md +26 -6
  61. package/templates/rules/mempalace.md +1 -0
  62. package/templates/rules/plan-next.md +58 -0
@@ -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)"
@@ -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"