@jeiemgi/cckit 0.1.8 → 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 (68) 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 +77 -12
  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/copilot-loop-test.sh +162 -0
  12. package/scripts/init.sh +22 -4
  13. package/scripts/kit-doctor.sh +185 -7
  14. package/scripts/kit-version-check-test.sh +36 -0
  15. package/scripts/kit-version-check.sh +19 -4
  16. package/scripts/knowledge-lint.sh +4 -1
  17. package/scripts/lib/board-view-test.sh +54 -0
  18. package/scripts/lib/board-view.sh +80 -0
  19. package/scripts/lib/captain-test.sh +76 -0
  20. package/scripts/lib/captain.sh +268 -0
  21. package/scripts/lib/config-path-test.sh +47 -0
  22. package/scripts/lib/config-path.sh +29 -0
  23. package/scripts/lib/copilot-test.sh +30 -0
  24. package/scripts/lib/copilot.sh +101 -0
  25. package/scripts/lib/effort-metrics-test.sh +57 -0
  26. package/scripts/lib/effort-metrics.sh +19 -5
  27. package/scripts/lib/effort-ops-test.sh +51 -2
  28. package/scripts/lib/effort-ops.sh +314 -49
  29. package/scripts/lib/effort-parity-test.sh +128 -0
  30. package/scripts/lib/effort-slug-test.sh +87 -0
  31. package/scripts/lib/effort-slug.sh +104 -0
  32. package/scripts/lib/effort.sh +34 -0
  33. package/scripts/lib/gh-project-test.sh +95 -0
  34. package/scripts/lib/gh-project.sh +22 -7
  35. package/scripts/lib/git-remote-test.sh +57 -0
  36. package/scripts/lib/git-remote.sh +21 -0
  37. package/scripts/lib/kit-config-test.sh +37 -0
  38. package/scripts/lib/kit-config.sh +33 -13
  39. package/scripts/lib/kit-events.sh +5 -3
  40. package/scripts/lib/kit-gc-test.sh +88 -0
  41. package/scripts/lib/kit-gc.sh +136 -19
  42. package/scripts/lib/kit-local.sh +8 -1
  43. package/scripts/lib/next.sh +75 -0
  44. package/scripts/lib/plan-machine-test.sh +72 -0
  45. package/scripts/lib/plan-machine.sh +260 -0
  46. package/scripts/lib/plan-next-test.sh +87 -0
  47. package/scripts/lib/plan-next.sh +212 -0
  48. package/scripts/lib/project-scan.sh +7 -1
  49. package/scripts/lib/render-test.sh +40 -0
  50. package/scripts/lib/render.sh +57 -0
  51. package/scripts/lib/worktree-start.sh +12 -3
  52. package/scripts/lib/zsh-safety-test.sh +73 -0
  53. package/scripts/portable-test.sh +62 -20
  54. package/scripts/setup-labels.sh +13 -2
  55. package/scripts/showcase.sh +13 -4
  56. package/scripts/status-test.sh +63 -0
  57. package/scripts/status.sh +12 -4
  58. package/scripts/task-sync.sh +79 -10
  59. package/skills/kit-autopilot/SKILL.md +5 -0
  60. package/skills/kit-docs-writer/SKILL.md +135 -0
  61. package/skills/kit-effort-new/SKILL.md +39 -111
  62. package/skills/kit-effort-pr/SKILL.md +6 -2
  63. package/skills/kit-next/SKILL.md +58 -0
  64. package/skills/kit-plan-next/SKILL.md +82 -0
  65. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  66. package/templates/rules/effort-model.md +26 -6
  67. package/templates/rules/mempalace.md +1 -0
  68. package/templates/rules/plan-next.md +58 -0
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # effort-parity-test.sh — effort #98: the verb (`cckit effort new`) and the skill (/kit-effort-new)
4
+ # create structurally IDENTICAL efforts because both call the one shared core `effort_new`. This test
5
+ # drives that core with the full skill-shaped inputs and asserts the parity contract:
6
+ # - the four body sections are FILLED (no `<!--` template placeholder left)
7
+ # - the ctx/kind/priority/role/flow label set is applied to the parent
8
+ # - sub-issues carry kind/priority/role labels and are native-linked
9
+ # - every sub title is linted UP FRONT (a bad sub name aborts before anything is created)
10
+ # Hermetic: stubs gh (no network/auth). Run: bash scripts/lib/effort-parity-test.sh
11
+ set -u
12
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
13
+ LIB="$ROOT/scripts/lib"
14
+ fail=0
15
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
16
+ tc() { if grep -qE "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in gh log)"; fail=1; fi; }
17
+ tn() { if grep -qE "$2" "$1"; then echo "FAIL: $3 (unexpected /$2/ in gh log)"; fail=1; else echo "ok: $3"; fi; }
18
+ command -v jq >/dev/null 2>&1 || { echo "effort-parity-test: jq required" >&2; exit 1; }
19
+
20
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
21
+ export GH_LOG="$tmp/gh.log"; export GH_N="$tmp/n"; : > "$GH_LOG"
22
+
23
+ # Stub gh: log every call as ONE physical line (newlines in the multi-line --body flattened to spaces
24
+ # so a single-line grep can see --label, which follows --body), return canned output.
25
+ stub="$tmp/bin"; mkdir -p "$stub"
26
+ cat > "$stub/gh" <<'SH'
27
+ #!/usr/bin/env bash
28
+ echo "$*" | tr '\n' ' ' >> "$GH_LOG"; echo >> "$GH_LOG"
29
+ case "$1 $2" in
30
+ "issue create") n=$(( $(cat "$GH_N" 2>/dev/null || echo 0) + 1 )); echo "$n" > "$GH_N"
31
+ echo "https://github.com/o/r/issues/$n" ;;
32
+ "issue edit") exit 0 ;;
33
+ "api "*|"api")
34
+ case "$*" in
35
+ *"--method POST"*"/sub_issues"*) exit 0 ;;
36
+ *".id"*) echo "55501" ;;
37
+ *) exit 0 ;;
38
+ esac ;;
39
+ *) exit 0 ;;
40
+ esac
41
+ SH
42
+ chmod +x "$stub/gh"
43
+ export PATH="$stub:$PATH"
44
+ export KIT_REPO="o/r" EFFORT_REPO="o/r" KIT_BASE_BRANCH="main" KIT_PROJECTS_V2="false"
45
+ # shellcheck source=/dev/null
46
+ source "$LIB/effort.sh" 2>/dev/null
47
+ # shellcheck source=/dev/null
48
+ source "$LIB/effort-metrics.sh" 2>/dev/null # effort_ctx_bucket — so ctx is sized, not the fallback
49
+ # shellcheck source=/dev/null
50
+ source "$LIB/effort-ops.sh"
51
+
52
+ # ── Full skill-shaped inputs through the shared core ─────────────────────────────────────────────
53
+ : > "$GH_LOG"
54
+ parent="$(effort_new \
55
+ --flow Core --role tech-lead --priority p2 \
56
+ --goal "Close the parity gap between the verb and the skill." \
57
+ --scope "1. share core | 2. verb fills body | 3. skill delegates" \
58
+ --for-agents "scripts/lib/effort-ops.sh and skills/kit-effort-new/SKILL.md" \
59
+ --verification "the verb and skill produce identical issues" \
60
+ "demo parity effort" "share core :: factor the logic" "fill the body :: verb wiring")"
61
+
62
+ t "core returns the parent number" "$parent" "1"
63
+ t "core creates parent + 2 subs (3 issues)" "$(grep -c 'issue create' "$GH_LOG")" "3"
64
+ t "core links 2 native sub-issues" "$(grep -c 'method POST .*sub_issues' "$GH_LOG")" "2"
65
+
66
+ # Body is FILLED — every section heading present AND the placeholder comments are gone.
67
+ tc "$GH_LOG" 'Close the parity gap between the verb' "body fills ## Goal"
68
+ tc "$GH_LOG" '1\. share core \| 2\. verb fills body' "body fills ## Scope"
69
+ tc "$GH_LOG" 'scripts/lib/effort-ops\.sh and skills' "body fills ## For agents"
70
+ tc "$GH_LOG" 'the verb and skill produce identical' "body fills ## Verification"
71
+ tn "$GH_LOG" '<!--' "no template placeholder left in a filled body"
72
+
73
+ # Label set on the parent: ctx + kind + priority + role + flow (flow lowercased).
74
+ tc "$GH_LOG" 'issue create .*--label ctx:[SMLX]+,kind:task,priority:p2,role:tech-lead,flow:core' \
75
+ "parent carries ctx/kind/priority/role/flow labels"
76
+ # Flow tag on the composed title.
77
+ tc "$GH_LOG" 'issue edit 1 .*--title \[Effort\] 1 · \[Core\] demo parity effort' \
78
+ "parent title carries the [Core] flow tag + injected number"
79
+ # Sub labels: kind/priority/role (no ctx/flow on subs — those are parent-level).
80
+ tc "$GH_LOG" 'issue create .*--title \[Effort 1\] 1 · share core.*--label kind:task,priority:p2,role:tech-lead' \
81
+ "sub #1 carries kind/priority/role labels + a proper [Effort N] M title"
82
+
83
+ # ── A bad sub title aborts the whole op BEFORE anything is created (parity contract) ─────────────
84
+ : > "$GH_LOG"; printf '0' > "$GH_N"
85
+ effort_new --role tech-lead --goal G --scope S --for-agents A --verification V \
86
+ "clean parent name" "refactor the whole wiring layer thing now" >/dev/null 2>&1 && rc=0 || rc=1
87
+ t "core rejects a bad sub title" "$rc" "1"
88
+ t "core creates nothing on a bad sub title" "$(grep -c 'issue create' "$GH_LOG")" "0"
89
+
90
+ # ── A bare verb-style call (no body flags) still yields the 4-section scaffold ───────────────────
91
+ : > "$GH_LOG"; printf '0' > "$GH_N"
92
+ effort_new "minimal effort name" >/dev/null 2>&1
93
+ tc "$GH_LOG" '## Goal' "bare call still emits ## Goal"
94
+ tc "$GH_LOG" '## Verification' "bare call still emits ## Verification"
95
+ tc "$GH_LOG" '<!--' "bare call leaves the template placeholders (nothing to fill)"
96
+
97
+ # ── #121: the ONE shared effort-PR title composer + the mandatory-[#N] check ─────────────────────
98
+ t "effort_pr_title composes [#N] name" "$(effort_pr_title 115 'adoption hardening')" "[#115] adoption hardening"
99
+ t "effort_pr_title with a role prefix" "$(effort_pr_title 115 'adoption hardening' 'Tech Lead')" "[Tech Lead] [#115] adoption hardening"
100
+ t "effort_pr_title peels an [Effort] prefix" "$(effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening')" "[#115] [Core] adoption hardening"
101
+ t "effort_pr_title tolerates a #-prefixed num" "$(effort_pr_title '#42' 'x')" "[#42] x"
102
+ effort_pr_title_check "[Tech Lead] [#115] adoption hardening" 115; t "check accepts a title carrying [#N]" "$?" "0"
103
+ effort_pr_title_check "[Effort] 115 · adoption hardening" 115 2>/dev/null; t "check refuses a title lacking [#N]" "$?" "1"
104
+ effort_pr_title_check "[#7] anything" 2>/dev/null; t "check accepts any [#N] when no num given" "$?" "0"
105
+
106
+ # ── #121: --par applies a par:<value> label on the parent; bad values are rejected up front ───────
107
+ : > "$GH_LOG"; printf '0' > "$GH_N"
108
+ effort_new --flow Core --par wide "parallel wide effort" "a :: x" "b :: y" >/dev/null 2>&1
109
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,par:wide' "--par wide adds a par:wide label to the parent"
110
+ tc "$GH_LOG" 'label create par:wide' "--par creates the par:wide label idempotently"
111
+ : > "$GH_LOG"; printf '0' > "$GH_N"
112
+ effort_new --par 3 "parallel three effort" >/dev/null 2>&1
113
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,par:3' "--par 3 adds a par:3 label"
114
+ : > "$GH_LOG"; printf '0' > "$GH_N"
115
+ effort_new --par nonsense "bad par effort" >/dev/null 2>&1 && rc=0 || rc=1
116
+ t "--par rejects a non seq/wide/int value" "$rc" "1"
117
+ t "--par creates nothing on a bad value" "$(grep -c 'issue create' "$GH_LOG")" "0"
118
+
119
+ # ── #121: flags are position-INDEPENDENT — trailing --flow/--role no longer become junk sub-issues ─
120
+ : > "$GH_LOG"; printf '0' > "$GH_N"
121
+ effort_new "flags after title effort" "real sub :: desc" --flow Docs --role docs >/dev/null 2>&1
122
+ t "trailing flags do NOT create junk subs (parent + 1 real sub)" "$(grep -c 'issue create' "$GH_LOG")" "2"
123
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,flow:docs' "trailing --flow is honored (flow:docs label)"
124
+ tc "$GH_LOG" 'issue create .*--title \[Effort 1\] 1 · real sub' "the one real sub is created from the positional"
125
+ tn "$GH_LOG" 'issue create .*--title \[Effort 1\] [0-9]+ · --flow' "no '--flow' junk sub-issue created"
126
+
127
+ [ "$fail" -eq 0 ] && echo "ALL OK (effort-parity)" || echo "effort-parity: FAILURES"
128
+ exit "$fail"
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # effort-slug-test.sh — covers the effort slug layer (#93/#94/#96): slug derivation (doubling fix),
4
+ # `slug #N` display, and effort_slug_resolve (number passthrough, branch match, ambiguity, no-match,
5
+ # slug:<slug> label vs title-derived precedence). Hermetic: a throwaway git repo with effort/* branches
6
+ # + a stubbed gh (no network/auth). Run: bash scripts/lib/effort-slug-test.sh
7
+ set -u
8
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
9
+ LIB="$ROOT/scripts/lib"
10
+ fail=0
11
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
12
+ rc() { # <label> <expected-rc> ; reads the just-run command's rc from $?
13
+ if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '$2' want '$3'"; fail=1; fi; }
14
+ command -v git >/dev/null 2>&1 || { echo "effort-slug-test: git required" >&2; exit 1; }
15
+
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+
18
+ # Stub gh so the issue-based fallback is deterministic (label lookup + title-derived).
19
+ stub="$tmp/bin"; mkdir -p "$stub"
20
+ cat > "$stub/gh" <<'SH'
21
+ #!/usr/bin/env bash
22
+ # issue list --label slug:explicit-handle → #207 ; title search → #205 "[Effort] 205 · [Core] Title Only Effort"
23
+ case "$*" in
24
+ *"--label slug:explicit-handle"*) echo "207" ;;
25
+ *"--label slug:"*) : ;; # unknown label → no match
26
+ *"in:title"*) printf '205\t[Effort] 205 · [Core] Title Only Effort\n' ;;
27
+ *) : ;;
28
+ esac
29
+ SH
30
+ chmod +x "$stub/gh"
31
+ export PATH="$stub:$PATH"
32
+ export EFFORT_REPO="o/r" KIT_REPO="o/r"
33
+
34
+ # shellcheck source=/dev/null
35
+ source "$LIB/effort-slug.sh"
36
+
37
+ # ── slug derivation (the #93 doubling fix) ─────────────────────────────────────────────────────
38
+ t "_eff_title_slug peels prefix + flow (parent)" \
39
+ "$(_eff_title_slug '[Effort] 93 · [Core] Slug handles for efforts')" "slug-handles-for-efforts"
40
+ t "_eff_title_slug peels prefix + flow (sub)" \
41
+ "$(_eff_title_slug '[Effort 93] 2 · [UI] Accept slug in commands')" "accept-slug-in-commands"
42
+ t "_eff_title_slug without a flow tag" \
43
+ "$(_eff_title_slug '[Effort] 12 · plain outcome name')" "plain-outcome-name"
44
+ t "_eff_slug lowercases + dashes arbitrary text" \
45
+ "$(_eff_slug 'Some Mixed CASE!!')" "some-mixed-case"
46
+
47
+ # ── display ────────────────────────────────────────────────────────────────────────────────────
48
+ t "effort_display renders slug #N" "$(effort_display 93 slug-handles)" "slug-handles #93"
49
+ t "effort_display without a slug" "$(effort_display 93)" "#93"
50
+
51
+ # ── effort_slug_resolve: number passthrough (canonical key, never re-mapped) ───────────────────
52
+ t "resolve passes a pure number through" "$(effort_slug_resolve 93)" "93"
53
+ effort_slug_resolve "" >/dev/null 2>&1; rc "resolve rejects empty input (rc 2)" "$?" "2"
54
+
55
+ # ── effort_slug_resolve: branch matching (local + remote effort/* refs) ────────────────────────
56
+ ( cd "$tmp" && git init -q --bare remote.git )
57
+ git clone -q "$tmp/remote.git" "$tmp/work"
58
+ cd "$tmp/work" || exit 1
59
+ git -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
60
+ git push -q origin HEAD:main
61
+ git branch effort/101-resolve-slug
62
+ git branch effort/102-accept-slug
63
+ git push -q origin effort/101-resolve-slug effort/102-accept-slug
64
+ # remote-only branch (delete the local ref so only refs/remotes/origin/… carries it)
65
+ git branch -D effort/102-accept-slug >/dev/null 2>&1
66
+
67
+ t "resolve a local branch slug" "$(effort_slug_resolve resolve-slug)" "101"
68
+ t "resolve a remote-only slug" "$(effort_slug_resolve accept-slug)" "102"
69
+
70
+ # ── ambiguity: two efforts share a slug → structured error, nonzero rc, no guess ───────────────
71
+ git branch effort/103-resolve-slug
72
+ out="$(effort_slug_resolve resolve-slug 2>&1)"; r=$?
73
+ rc "ambiguous slug returns nonzero rc" "$r" "1"
74
+ case "$out" in *ambiguous*) echo "ok: ambiguous slug explains itself" ;; *) echo "FAIL: ambiguous message: $out"; fail=1 ;; esac
75
+ git branch -D effort/103-resolve-slug >/dev/null 2>&1
76
+
77
+ # ── gh fallback: slug:<slug> label wins; title-derived used when no branch/label matches ───────
78
+ t "resolve via slug label (no branch)" "$(effort_slug_resolve explicit-handle)" "207"
79
+ t "resolve via title-derived (no branch)" "$(effort_slug_resolve title-only-effort)" "205"
80
+
81
+ # ── no match anywhere → nonzero rc ─────────────────────────────────────────────────────────────
82
+ out="$(effort_slug_resolve nope-not-here 2>&1)"; r=$?
83
+ rc "unknown slug returns nonzero rc" "$r" "1"
84
+ case "$out" in *"no effort matches"*) echo "ok: unknown slug explains itself" ;; *) echo "FAIL: no-match message: $out"; fail=1 ;; esac
85
+
86
+ [ "$fail" -eq 0 ] && echo "ALL OK (effort-slug)" || echo "effort-slug: FAILURES"
87
+ exit "$fail"
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # effort-slug.sh — the effort *slug* layer (Effort #93). The GitHub issue NUMBER stays the canonical
4
+ # key; the slug is a DERIVED human handle that already lives in the branch name `effort/<N>-<slug>`.
5
+ # This file surfaces that handle: derive a slug from a title, render efforts as `slug #N`, and resolve
6
+ # a slug (or a number) back to the canonical effort number so commands can take either.
7
+ #
8
+ # Functions:
9
+ # _eff_slug <text> a short branch-safe slug (mirrors wt_start; shared with effort-ops)
10
+ # _eff_title_slug <effort title> slug derived from an effort title — peels the structural prefix
11
+ # ("[Effort] N · " / "[Effort N] M · ") and any leading [Flow] tag so
12
+ # the number/flow are NOT duplicated into the slug (#93 doubling fix)
13
+ # effort_display <N> [slug] render an effort as "slug #N" (or "#N" when no slug is known)
14
+ # effort_slug_resolve <slug|N> resolve a slug OR a number to the canonical effort number.
15
+ # pure-digits → passthrough; otherwise match effort/* branches
16
+ # (local + remote), then slug:<slug> labels, then open effort titles.
17
+ # no match → rc 1; ambiguous → rc 1; bad input → rc 2.
18
+ #
19
+ # Number stays canonical: a pure-digits argument is always treated as a number and passed through
20
+ # unchanged, so every existing `<N>` call keeps working. bash 3.2 compatible. Requires: git; gh (only
21
+ # for the issue-based fallback when no local/remote branch matches).
22
+
23
+ # Repo for the gh fallback — resolved from the same env effort.sh/kit-config populate.
24
+ _eff_slug_repo() { printf '%s' "${EFFORT_REPO:-${KIT_REPO:-}}"; }
25
+
26
+ # <text> → a short branch-safe slug (lowercase, [a-z0-9-], ≤40 chars). Mirrors wt_start / effort-ops.
27
+ _eff_slug() {
28
+ printf '%s' "$1" | sed -E 's/^\[[^]]+\][[:space:]]*//' | tr '[:upper:]' '[:lower:]' \
29
+ | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g' | cut -c1-40
30
+ }
31
+
32
+ # <effort title> → the human slug. Peels the structural prefix and one optional leading [Flow] tag
33
+ # BEFORE slugifying, so `[Effort] 93 · [Core] Slug handles` → `slug-handles` (not `93-core-slug-handles`,
34
+ # the cosmetic doubling that produced branches like `effort/98-98-core-…`). See #93 / sub #96.
35
+ _eff_title_slug() {
36
+ local t="$1"
37
+ # structural prefix: "[Effort] N · " (parent) or "[Effort N] M · " (sub)
38
+ t="$(printf '%s' "$t" | sed -E 's/^\[Effort( [0-9]+)?\] [0-9]+ ·? ?//')"
39
+ # one optional leading [Flow] tag
40
+ t="$(printf '%s' "$t" | sed -E 's/^\[[A-Za-z]+\][[:space:]]*//')"
41
+ _eff_slug "$t"
42
+ }
43
+
44
+ # <N> [slug] → "slug #N" for human output (the canonical handle is the number; the slug is the label).
45
+ effort_display() {
46
+ local n="$1" s="${2:-}"
47
+ if [ -n "$s" ]; then printf '%s #%s' "$s" "$n"; else printf '#%s' "$n"; fi
48
+ }
49
+
50
+ # effort_slug_resolve <slug|N> → echo the canonical effort number on stdout (rc 0).
51
+ # - pure digits → passthrough (number stays canonical; never re-mapped).
52
+ # - otherwise normalize and match, in order: effort/* branches (local + remote), then (via gh)
53
+ # slug:<slug> labels, then title-derived slugs of open `[Effort]` issues.
54
+ # - no match → rc 1; >1 distinct match → rc 1 (ambiguous, never a wrong guess); empty/unusable → rc 2.
55
+ effort_slug_resolve() {
56
+ local input="${1:-}"
57
+ [ -n "$input" ] || { echo "effort_slug_resolve: <slug|N> required" >&2; return 2; }
58
+ case "$input" in
59
+ *[!0-9]*) : ;; # contains a non-digit → treat as a slug
60
+ *) printf '%s\n' "$input"; return 0 ;; # all digits → canonical number, passthrough
61
+ esac
62
+
63
+ local norm; norm="$(_eff_slug "$input")"
64
+ [ -n "$norm" ] || { echo "effort_slug_resolve: '$input' is not a usable slug" >&2; return 2; }
65
+
66
+ local matches="" ref n s
67
+ # 1. branches (local refs/heads + remote refs/remotes): effort/<N>-<slug>
68
+ while IFS= read -r ref; do
69
+ [ -n "$ref" ] || continue
70
+ n="$(printf '%s' "$ref" | sed -nE 's#^(.*/)?effort/([0-9]+)-(.*)$#\2#p')"
71
+ s="$(printf '%s' "$ref" | sed -nE 's#^(.*/)?effort/([0-9]+)-(.*)$#\3#p')"
72
+ [ -n "$n" ] || continue
73
+ [ "$s" = "$norm" ] && matches="$matches$n"$'\n'
74
+ done < <(git for-each-ref --format='%(refname:short)' refs/heads refs/remotes 2>/dev/null \
75
+ | grep -E '(^|/)effort/[0-9]+-' )
76
+ matches="$(printf '%s' "$matches" | grep -E '^[0-9]+$' | sort -un)"
77
+
78
+ # 2. gh fallback (only when no branch matched): slug:<slug> label first, then open effort titles.
79
+ if [ -z "$matches" ] && command -v gh >/dev/null 2>&1; then
80
+ local repo; repo="$(_eff_slug_repo)"
81
+ if [ -n "$repo" ]; then
82
+ matches="$(gh issue list --repo "$repo" --state open --label "slug:$norm" \
83
+ --json number -q '.[].number' 2>/dev/null | grep -E '^[0-9]+$' | sort -un)"
84
+ if [ -z "$matches" ]; then
85
+ local in it
86
+ matches="$(gh issue list --repo "$repo" --state open --search '[Effort] in:title' --limit 200 \
87
+ --json number,title -q '.[] | "\(.number)\t\(.title)"' 2>/dev/null \
88
+ | while IFS="$(printf '\t')" read -r in it; do
89
+ [ "$(_eff_title_slug "$it")" = "$norm" ] && printf '%s\n' "$in"
90
+ done | grep -E '^[0-9]+$' | sort -un)"
91
+ fi
92
+ fi
93
+ fi
94
+
95
+ local count; count="$(printf '%s\n' "$matches" | grep -cE '^[0-9]+$')"
96
+ if [ "$count" -eq 0 ]; then
97
+ echo "effort_slug_resolve: no effort matches slug '$norm' (looked in effort/* branches, slug:* labels, open effort titles)" >&2
98
+ return 1
99
+ elif [ "$count" -gt 1 ]; then
100
+ echo "effort_slug_resolve: slug '$norm' is ambiguous — matches efforts $(printf '%s' "$matches" | tr '\n' ' ')— pass the number" >&2
101
+ return 1
102
+ fi
103
+ printf '%s\n' "$matches"
104
+ }
@@ -106,6 +106,40 @@ effort_snapshot_subs() {
106
106
  printf '%s' "$dir"
107
107
  }
108
108
 
109
+ # ── Effort PR title — ONE composer shared by the verb + the skill (#121) ────────────────────────
110
+ # `cckit effort pr` (the verb) and /kit-effort-pr (the skill) previously composed different PR
111
+ # titles; they now both call effort_pr_title so an effort PR is titled identically no matter who
112
+ # opens it. The MANDATORY element is the [#N] effort id — a PR title without it is a review blocker
113
+ # (effort-model.md), enforced by effort_pr_title_check.
114
+ #
115
+ # effort_pr_title <num> <name> [role_display] — compose the canonical title:
116
+ # effort_pr_title 115 "adoption hardening" -> "[#115] adoption hardening"
117
+ # effort_pr_title 115 "adoption hardening" "Tech Lead" -> "[Tech Lead] [#115] adoption hardening"
118
+ # A full parent title ("[Effort] 115 · [Core] adoption hardening") is accepted too — the
119
+ # "[Effort] N · " prefix is peeled so the id is never duplicated.
120
+ effort_pr_title() {
121
+ local num="${1:-}" name="${2:-}" role="${3:-}"
122
+ num="${num#\#}"
123
+ name="$(printf '%s' "$name" | sed -E 's/^\[Effort\] [0-9]+ · ?//')"
124
+ [ -n "$name" ] || name="effort"
125
+ if [ -n "$role" ]; then printf '[%s] [#%s] %s' "$role" "$num" "$name"
126
+ else printf '[#%s] %s' "$num" "$name"; fi
127
+ }
128
+
129
+ # effort_pr_title_check <title> [num] — rc 0 iff <title> carries the effort id token [#N] (the exact
130
+ # [#num] when given, else any [#digits]). Prints the reason + rc 1 when it doesn't, so both the verb
131
+ # and the skill can refuse to open a PR whose title lacks the effort id.
132
+ effort_pr_title_check() {
133
+ local title="${1:-}" num="${2:-}"
134
+ if [ -n "$num" ]; then
135
+ num="${num#\#}"
136
+ case "$title" in *"[#$num]"*) return 0 ;; esac
137
+ echo "effort_pr_title_check: PR title lacks the [#$num] effort id: '$title'" >&2; return 1
138
+ fi
139
+ printf '%s' "$title" | grep -qE '\[#[0-9]+\]' && return 0
140
+ echo "effort_pr_title_check: PR title lacks a [#N] effort id: '$title'" >&2; return 1
141
+ }
142
+
109
143
  # ── Effort-title rule — concise, jargon-free, flow-tagged ──────────────────────────────────────────
110
144
  # The board must say what an effort delivers and which FLOW it belongs to. So the `<Name>` part of an
111
145
  # effort/sub title is a short plain-language outcome with an optional leading `[Flow]` tag from a
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # gh-project-test.sh — covers the board owner-type resolution adoption needs (#118). A Projects v2
4
+ # board can live under a USER login or an ORGANIZATION login, and each needs a different GraphQL root
5
+ # (user(login:) vs organization(login:)). A user-only query silently returns null for an org board.
6
+ # Covered: _ghp_owner_root resolution, kit-config exporting KIT_PROJECT_OWNER_TYPE, and
7
+ # capture-project-ids.sh selecting the matching root end-to-end (stubbed gh — no network).
8
+ # Run: bash scripts/lib/gh-project-test.sh
9
+ set -u
10
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
11
+ LIB="$ROOT/scripts/lib"
12
+ fail=0
13
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
14
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '$2' lacks '$3'"; fail=1 ;; esac; }
15
+ command -v jq >/dev/null 2>&1 || { echo "gh-project-test: jq required — skipping"; exit 0; }
16
+
17
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
18
+
19
+ # ── _ghp_owner_root resolves from KIT_PROJECT_OWNER_TYPE ───────────────────────────────────────
20
+ # shellcheck source=/dev/null
21
+ ( KIT_PROJECT_OWNER_TYPE=organization; source "$LIB/gh-project.sh"; [ "$(_ghp_owner_root)" = organization ] ) \
22
+ && echo "ok: owner_root=organization for org type" || { echo "FAIL: org owner_root"; fail=1; }
23
+ ( KIT_PROJECT_OWNER_TYPE=org; source "$LIB/gh-project.sh"; [ "$(_ghp_owner_root)" = organization ] ) \
24
+ && echo "ok: owner_root=organization for 'org' shorthand" || { echo "FAIL: org shorthand"; fail=1; }
25
+ ( unset KIT_PROJECT_OWNER_TYPE; KIT_CONFIG=/nonexistent; source "$LIB/gh-project.sh"; [ "$(_ghp_owner_root)" = user ] ) \
26
+ && echo "ok: owner_root=user by default" || { echo "FAIL: default user owner_root"; fail=1; }
27
+
28
+ # ── kit-config exports KIT_PROJECT_OWNER_TYPE from config ──────────────────────────────────────
29
+ printf '%s' '{"github":{"projectOwnerType":"organization"}}' > "$tmp/org.json"
30
+ got="$(KIT_CONFIG="$tmp/org.json" bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; printf '%s' \"\$KIT_PROJECT_OWNER_TYPE\"")"
31
+ t "kit-config exports owner type from config" "$got" "organization"
32
+ printf '%s' '{"github":{}}' > "$tmp/none.json"
33
+ got="$(KIT_CONFIG="$tmp/none.json" bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; printf '%s' \"\$KIT_PROJECT_OWNER_TYPE\"")"
34
+ t "kit-config defaults owner type to user" "$got" "user"
35
+
36
+ # ── capture-project-ids.sh selects the matching GraphQL root (stubbed gh) ───────────────────────
37
+ # Isolated scripts dir: a copy of the script + a symlink to the real lib, so $0-relative sourcing +
38
+ # OUT path stay inside tmp. A stub gh detects the query root and returns matching-shaped JSON.
39
+ mkdir -p "$tmp/scripts" "$tmp/bin"
40
+ cp "$ROOT/scripts/capture-project-ids.sh" "$tmp/scripts/"
41
+ ln -s "$LIB" "$tmp/scripts/lib"
42
+ cat > "$tmp/bin/gh" <<'SH'
43
+ #!/usr/bin/env bash
44
+ # Record the query, then emit JSON under whichever root the query selected.
45
+ q=""; for a in "$@"; do case "$a" in query=*) q="${a#query=}" ;; esac; done
46
+ printf '%s\n' "$q" >> "$GH_QUERY_LOG"
47
+ if printf '%s' "$q" | grep -q 'organization(login'; then root=organization; else root=user; fi
48
+ cat <<JSON
49
+ {"data":{"$root":{"projectV2":{"id":"PVT_org123","fields":{"nodes":[
50
+ {"__typename":"ProjectV2SingleSelectField","id":"F_status","name":"Status","options":[{"id":"O_todo","name":"Todo"}]},
51
+ {"__typename":"ProjectV2FieldCommon","id":"F_plan","name":"Plan Link"}
52
+ ]}}}}}
53
+ JSON
54
+ SH
55
+ chmod +x "$tmp/bin/gh"
56
+
57
+ run_capture() { # <owner-type>
58
+ printf '%s' "{\"github\":{\"projectsV2\":true,\"owner\":\"acme\",\"projectNumber\":3,\"projectOwnerType\":\"$1\"}}" > "$tmp/cfg.json"
59
+ : > "$tmp/qlog"
60
+ GH_QUERY_LOG="$tmp/qlog" KIT_CONFIG="$tmp/cfg.json" PATH="$tmp/bin:$PATH" \
61
+ bash "$tmp/scripts/capture-project-ids.sh" >/dev/null 2>&1
62
+ }
63
+
64
+ run_capture organization
65
+ rc=$?
66
+ t "capture rc 0 (org board)" "$rc" "0"
67
+ has "capture uses organization root for an org board" "$(cat "$tmp/qlog")" "organization(login"
68
+ [ -f "$tmp/scripts/.project-ids.env" ] && has "org capture wrote PROJECT_ID" "$(cat "$tmp/scripts/.project-ids.env")" "PROJECT_ID=PVT_org123" || { echo "FAIL: no env written (org)"; fail=1; }
69
+ has "org capture wrote a field id" "$(cat "$tmp/scripts/.project-ids.env" 2>/dev/null)" "STATUS_FIELD_ID=F_status"
70
+ rm -f "$tmp/scripts/.project-ids.env"
71
+
72
+ run_capture user
73
+ has "capture uses user root for a user board" "$(cat "$tmp/qlog")" "user(login"
74
+
75
+ # ── project_issue_status: read an issue's board Status via the cheap issue.projectItems query (#124) ─
76
+ mkdir -p "$tmp/bin2"
77
+ cat > "$tmp/bin2/gh" <<'SH'
78
+ #!/usr/bin/env bash
79
+ # The issue.projectItems Status query: issue is "In Progress" on project #3 (and Todo on some other).
80
+ cat <<'JSON'
81
+ {"data":{"repository":{"issue":{"projectItems":{"nodes":[
82
+ {"project":{"number":7},"fieldValueByName":{"name":"Todo"}},
83
+ {"project":{"number":3},"fieldValueByName":{"name":"In Progress"}}
84
+ ]}}}}}
85
+ JSON
86
+ SH
87
+ chmod +x "$tmp/bin2/gh"
88
+ st="$(PATH="$tmp/bin2:$PATH" KIT_REPO="acme/app" KIT_PROJECT_NUMBER=3 bash -c "source '$LIB/gh-project.sh'; project_issue_status 42")"
89
+ t "project_issue_status returns the board Status for our project" "$st" "In Progress"
90
+ # unresolved repo/number -> non-zero, no guess.
91
+ PATH="$tmp/bin2:$PATH" KIT_REPO="" KIT_PROJECT_NUMBER="" bash -c "source '$LIB/gh-project.sh'; project_issue_status 42" >/dev/null 2>&1
92
+ t "project_issue_status fails (rc 1) with unresolved repo/number" "$?" "1"
93
+
94
+ [ "$fail" -eq 0 ] && echo "ALL OK (gh-project)" || echo "gh-project: FAILURES"
95
+ exit "$fail"
@@ -139,10 +139,10 @@ _ghp_resolve_pnum() {
139
139
  }
140
140
 
141
141
  # Resolve the project OWNER TYPE — "organization" or "user" (default "user").
142
- # The board moved from a user project (jeiemgi #2) to an org project
143
- # (tuempresadigital #3). An org-owned board is what lets a single issue see its
144
- # own card via the CHEAP issue.projectItems lookup (project_find_item_by_issue),
142
+ # A board can live under a user login OR an organization login. An org-owned board is what lets a
143
+ # single issue see its own card via the CHEAP issue.projectItems lookup (project_find_item_by_issue),
145
144
  # so every board GraphQL query must branch on this: organization(login:) vs user(login:).
145
+ # Prefers the exported KIT_PROJECT_OWNER_TYPE (set by kit-config from github.projectOwnerType).
146
146
  _ghp_resolve_owner_type() {
147
147
  [[ -n "${KIT_PROJECT_OWNER_TYPE:-}" ]] && { printf '%s' "$KIT_PROJECT_OWNER_TYPE"; return 0; }
148
148
  local cfg="${KIT_CONFIG:-$SCRIPT_DIR/../.claude/kit.config.json}" t=""
@@ -176,10 +176,9 @@ _ghp_resolve_repo() {
176
176
  # Prints the item node ID on stdout, or nothing if the issue genuinely isn't on the board.
177
177
  #
178
178
  # Instead of paginating the WHOLE board (the old 330+-item loop), this asks the ISSUE for its
179
- # own project cards (issue.projectItems) and filters by project number. This works ONLY because
180
- # the board is now ORG-owned (tuempresadigital #3) — an org project surfaces issue.projectItems
181
- # cheaply; the move from the user board (#2) is the whole reason this finder no longer paginates.
182
- # An issue belongs to few projects, so first:20 covers it without a loop.
179
+ # own project cards (issue.projectItems) and filters by project number. issue.projectItems surfaces
180
+ # an issue's cards cheaply (O(1) per issue) whether the board is user- or org-owned, so this finder
181
+ # never paginates. An issue belongs to few projects, so first:20 covers it without a loop.
183
182
  project_find_item_by_issue() {
184
183
  local issue_num="$1"
185
184
  local pnum="${2:-$(_ghp_resolve_pnum)}"
@@ -210,3 +209,19 @@ project_find_item_by_issue() {
210
209
  '.data.repository.issue.projectItems.nodes[] | select(.project.number==$n) | .id' 2>/dev/null | head -1)
211
210
  echo "$item_id"
212
211
  }
212
+
213
+ # project_issue_status <issue_number> [<project_number>] — echo an issue's Project Status field value
214
+ # on OUR board ("Todo" / "In Progress" / "Done" / …), or empty when the issue isn't on the board.
215
+ # The cheap issue.projectItems lookup, same as project_find_item_by_issue. A claim precheck reads this
216
+ # before starting an issue so it can warn on a collision (another session already In Progress). #124.
217
+ project_issue_status() {
218
+ local issue_num="$1" pnum="${2:-$(_ghp_resolve_pnum)}" repo owner name resp
219
+ repo="$(_ghp_resolve_repo)"; owner="${repo%%/*}"; name="${repo##*/}"
220
+ [ -n "$owner" ] && [ -n "$name" ] && [ -n "$pnum" ] || return 1
221
+ resp="$(gh api graphql \
222
+ -f query='query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){issue(number:$n){projectItems(first:20){nodes{project{number} fieldValueByName(name:"Status"){...on ProjectV2ItemFieldSingleSelectValue{name}}}}}}}' \
223
+ -F o="$owner" -F r="$name" -F n="$issue_num" 2>/dev/null)" || return 1
224
+ printf '%s' "$resp" | jq -r --argjson n "$pnum" \
225
+ '.data.repository.issue.projectItems.nodes[]? | select(.project.number==$n) | .fieldValueByName.name // empty' \
226
+ 2>/dev/null | head -1
227
+ }
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # git-remote-test.sh — covers deriving the project's repo identity from the git remote (#73), so
4
+ # NAME / slug / wing come from the ACTUAL repo name (not a cloned/renamed directory basename). Also
5
+ # checks the host-agnostic URL parsing (ssh, https, GHE/GitLab). Hermetic: a throwaway git repo with
6
+ # a fake remote. Run: bash scripts/lib/git-remote-test.sh
7
+ set -u
8
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
9
+ LIB="$ROOT/scripts/lib"
10
+ fail=0
11
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
12
+ rc() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '$2' want '$3'"; fail=1; fi; }
13
+ command -v git >/dev/null 2>&1 || { echo "git-remote-test: git required" >&2; exit 1; }
14
+
15
+ # shellcheck source=/dev/null
16
+ . "$LIB/git-remote.sh"
17
+
18
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
19
+ cd "$tmp"; git init -q proj-dir-renamed; cd proj-dir-renamed # dir name != repo name on purpose
20
+
21
+ # no remote yet -> rc 1, empty (so callers fall back to the basename)
22
+ out="$(git_remote_slug 2>/dev/null)"; r=$?
23
+ rc "no remote -> rc 1" "$r" "1"
24
+ t "no remote -> empty" "$out" ""
25
+
26
+ set_remote() { git remote remove origin 2>/dev/null; git remote add origin "$1"; }
27
+
28
+ # ssh form
29
+ set_remote "git@github.com:acme/actual-repo.git"
30
+ t "ssh: slug" "$(git_remote_slug)" "acme/actual-repo"
31
+ t "ssh: repo name" "$(git_remote_repo_name)" "actual-repo"
32
+ t "ssh: owner" "$(git_remote_owner)" "acme"
33
+
34
+ # https form with .git
35
+ set_remote "https://github.com/acme/actual-repo.git"
36
+ t "https: slug" "$(git_remote_slug)" "acme/actual-repo"
37
+ t "https: repo name" "$(git_remote_repo_name)" "actual-repo"
38
+
39
+ # https without .git
40
+ set_remote "https://github.com/acme/actual-repo"
41
+ t "https no .git: repo name" "$(git_remote_repo_name)" "actual-repo"
42
+
43
+ # a non-GitHub host (GitLab) still parses (host-agnostic)
44
+ set_remote "git@gitlab.example.com:group/my-service.git"
45
+ t "GHE/GitLab: owner" "$(git_remote_owner)" "group"
46
+ t "GHE/GitLab: repo name" "$(git_remote_repo_name)" "my-service"
47
+
48
+ # ssh:// scheme form
49
+ set_remote "ssh://git@github.com/acme/another.git"
50
+ t "ssh:// scheme: repo name" "$(git_remote_repo_name)" "another"
51
+
52
+ # The whole point: repo name comes from the remote, NOT the (renamed) directory basename.
53
+ t "repo name != directory basename" "$(git_remote_repo_name)" "another"
54
+ [ "$(basename "$PWD")" = "proj-dir-renamed" ] && echo "ok: directory basename is indeed different" || { echo "FAIL: dir basename"; fail=1; }
55
+
56
+ [ "$fail" -eq 0 ] && echo "ALL OK (git-remote)" || echo "git-remote: FAILURES"
57
+ exit "$fail"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # git-remote.sh — derive the project's repo identity from its git remote (#73). The local directory
4
+ # is often cloned/renamed to something other than the repo name, so NAME / slug / wing should come
5
+ # from the ACTUAL remote repo name; the directory basename is only the LAST resort. Pure git + sed —
6
+ # no gh, no network, host-agnostic (github.com, GHE, GitLab, ssh/https). bash 3.2 + zsh compatible.
7
+ #
8
+ # git_remote_slug [dir] -> "owner/repo" from origin (rc 1 + empty when no remote)
9
+ # git_remote_repo_name [dir] -> "repo"
10
+ # git_remote_owner [dir] -> "owner"
11
+
12
+ git_remote_slug() {
13
+ local dir="${1:-$PWD}" url
14
+ url="$(git -C "$dir" remote get-url origin 2>/dev/null || true)"
15
+ [ -n "$url" ] || return 1
16
+ # Strip any scheme/host prefix (git@host:, ssh://git@host/, https://host/) and the trailing .git.
17
+ printf '%s' "$url" | sed -E 's#^[a-z]+://[^/]+/##; s#^git@[^:]+:##; s#\.git$##; s#/$##'
18
+ }
19
+
20
+ git_remote_repo_name() { local s; s="$(git_remote_slug "${1:-$PWD}")" || return 1; printf '%s' "${s##*/}"; }
21
+ git_remote_owner() { local s; s="$(git_remote_slug "${1:-$PWD}")" || return 1; printf '%s' "${s%%/*}"; }
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kit-config-test.sh — covers load_kit_config resolution that adoption depends on. Today: the
4
+ # integration-branch fallback chain (#117) — a host project that names its integration branch under
5
+ # an alternate key (integrationBranch / flow) must still resolve, not silently fall back to "main".
6
+ # Hermetic: throwaway config files pointed at via KIT_CONFIG. Run: bash scripts/lib/kit-config-test.sh
7
+ set -u
8
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
9
+ LIB="$ROOT/scripts/lib"
10
+ fail=0
11
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
12
+ command -v jq >/dev/null 2>&1 || { echo "kit-config-test: jq required — skipping"; exit 0; }
13
+
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+
16
+ # base_branch_for <json> — resolve KIT_BASE_BRANCH for a given github config, hermetically.
17
+ base_branch_for() {
18
+ local json="$1" d; d="$(mktemp -d "$tmp/cfg.XXXXXX")"
19
+ printf '%s' "$json" > "$d/cckit.config.json"
20
+ KIT_CONFIG="$d/cckit.config.json" bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; printf '%s' \"\$KIT_BASE_BRANCH\""
21
+ }
22
+
23
+ # baseBranch is canonical and wins over the alternate keys.
24
+ t "baseBranch wins" \
25
+ "$(base_branch_for '{"github":{"baseBranch":"develop","integrationBranch":"x","flow":"y"}}')" "develop"
26
+ # integrationBranch is honored when baseBranch is absent (older/alternate host config).
27
+ t "integrationBranch fallback" \
28
+ "$(base_branch_for '{"github":{"integrationBranch":"integration","flow":"y"}}')" "integration"
29
+ # flow is the last named fallback before the default.
30
+ t "flow fallback" \
31
+ "$(base_branch_for '{"github":{"flow":"trunk"}}')" "trunk"
32
+ # nothing set -> "main", the safe default.
33
+ t "default main when unset" \
34
+ "$(base_branch_for '{"github":{}}')" "main"
35
+
36
+ [ "$fail" -eq 0 ] && echo "ALL OK (kit-config)" || echo "kit-config: FAILURES"
37
+ exit "$fail"