@jeiemgi/cckit 0.10.0 → 0.12.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 (193) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +136 -127
  3. package/README.md +66 -43
  4. package/bin/cckit +151 -181
  5. package/cckit.config.json +1 -4
  6. package/package.json +1 -1
  7. package/scripts/advisor-test.sh +55 -0
  8. package/scripts/autopilot-run-test.sh +20 -12
  9. package/scripts/autopilot-run.sh +9 -1
  10. package/scripts/autopilot-test.sh +29 -13
  11. package/scripts/autopilot.sh +4 -4
  12. package/scripts/benchmark/verb-timings-test.sh +4 -0
  13. package/scripts/benchmark/verb-timings.sh +16 -5
  14. package/scripts/capture-project-ids.sh +23 -1
  15. package/scripts/check.sh +25 -0
  16. package/scripts/content-skills-test.sh +1 -1
  17. package/scripts/contribute.sh +8 -3
  18. package/scripts/copilot-loop-test.sh +66 -81
  19. package/scripts/exec-targets-test.sh +20 -0
  20. package/scripts/force-push-fence-test.sh +44 -0
  21. package/scripts/force-push-fence.baseline +1 -0
  22. package/scripts/force-push-fence.sh +51 -0
  23. package/scripts/forge-fence-test.sh +69 -0
  24. package/scripts/forge-fence.baseline +2 -0
  25. package/scripts/forge-fence.sh +76 -0
  26. package/scripts/forge-report-test.sh +100 -0
  27. package/scripts/forge-report.sh +176 -0
  28. package/scripts/init-guided-test.sh +94 -82
  29. package/scripts/init.sh +12 -7
  30. package/scripts/install-test.sh +26 -0
  31. package/scripts/install.sh +7 -0
  32. package/scripts/instruction-budget-baseline.txt +1 -1
  33. package/scripts/kit-doctor-test.sh +60 -12
  34. package/scripts/kit-doctor.sh +170 -77
  35. package/scripts/lib/agent-resolve-test.sh +2 -0
  36. package/scripts/lib/agent-resolve.sh +15 -8
  37. package/scripts/lib/board-view.sh +3 -3
  38. package/scripts/lib/captain.sh +37 -8
  39. package/scripts/lib/content-kinds-gc-test.sh +22 -21
  40. package/scripts/lib/copilot-test.sh +20 -11
  41. package/scripts/lib/copilot.sh +19 -13
  42. package/scripts/lib/effort-close-subs-test.sh +96 -0
  43. package/scripts/lib/effort-dispatch-test.sh +5 -3
  44. package/scripts/lib/effort-metrics-test.sh +7 -12
  45. package/scripts/lib/effort-metrics.sh +17 -46
  46. package/scripts/lib/effort-ops-test.sh +261 -167
  47. package/scripts/lib/effort-ops.sh +449 -171
  48. package/scripts/lib/effort-parity-test.sh +57 -62
  49. package/scripts/lib/effort-plan-test.sh +56 -54
  50. package/scripts/lib/effort-plan.sh +14 -7
  51. package/scripts/lib/effort-review-test.sh +107 -0
  52. package/scripts/lib/effort-review.sh +93 -0
  53. package/scripts/lib/effort-slug-test.sh +34 -14
  54. package/scripts/lib/effort-slug.sh +13 -13
  55. package/scripts/lib/effort.sh +58 -80
  56. package/scripts/lib/forge-github.sh +260 -0
  57. package/scripts/lib/forge-none.sh +24 -0
  58. package/scripts/lib/forge-test.sh +186 -0
  59. package/scripts/lib/forge.sh +133 -0
  60. package/scripts/lib/gh-board-add-test.sh +118 -0
  61. package/scripts/lib/gh-project-test.sh +151 -31
  62. package/scripts/lib/gh-project.sh +139 -11
  63. package/scripts/lib/gh-rest-test.sh +63 -118
  64. package/scripts/lib/gh-rest.sh +275 -52
  65. package/scripts/lib/git-core-test.sh +128 -0
  66. package/scripts/lib/grill-record-test.sh +49 -0
  67. package/scripts/lib/grill-record.sh +88 -0
  68. package/scripts/lib/handoff.sh +1 -1
  69. package/scripts/lib/init-github.sh +38 -13
  70. package/scripts/lib/kinds-test.sh +13 -16
  71. package/scripts/lib/kit-brief-test.sh +51 -10
  72. package/scripts/lib/kit-brief.sh +103 -18
  73. package/scripts/lib/kit-gc-test.sh +90 -109
  74. package/scripts/lib/kit-gc.sh +19 -22
  75. package/scripts/lib/kit-hotfix.sh +18 -16
  76. package/scripts/lib/kit-interview.sh +6 -0
  77. package/scripts/lib/kit-lib-test.sh +1 -1
  78. package/scripts/lib/kit-lib.sh +7 -7
  79. package/scripts/lib/kit-msg.sh +3 -3
  80. package/scripts/lib/kit-status.sh +19 -14
  81. package/scripts/lib/kit-task-ops-test.sh +20 -1
  82. package/scripts/lib/kit-task-ops.sh +177 -94
  83. package/scripts/lib/kto-hotfix-test.sh +53 -58
  84. package/scripts/lib/kto-task-close-test.sh +28 -27
  85. package/scripts/lib/kto-task-new-test.sh +55 -48
  86. package/scripts/lib/kto-task-pr-merge-test.sh +77 -41
  87. package/scripts/lib/kto-task-pr-test.sh +30 -34
  88. package/scripts/lib/light-task-run-test.sh +19 -15
  89. package/scripts/lib/light-task-test.sh +34 -29
  90. package/scripts/lib/light-task.sh +24 -13
  91. package/scripts/lib/loose-issues.sh +65 -0
  92. package/scripts/lib/naming-test.sh +112 -0
  93. package/scripts/lib/naming-verbs-test.sh +126 -0
  94. package/scripts/lib/naming.sh +172 -0
  95. package/scripts/lib/next-test.sh +27 -22
  96. package/scripts/lib/next.sh +13 -7
  97. package/scripts/lib/orchestration-runtime-test.sh +11 -8
  98. package/scripts/lib/plan-machine.sh +22 -16
  99. package/scripts/lib/plan-next.sh +4 -4
  100. package/scripts/lib/pr-evidence-test.sh +63 -74
  101. package/scripts/lib/pr-evidence.sh +15 -12
  102. package/scripts/lib/qa-lane-test.sh +59 -27
  103. package/scripts/lib/qa-lane.sh +14 -6
  104. package/scripts/lib/review-page-test.sh +34 -25
  105. package/scripts/lib/review-page.sh +10 -4
  106. package/scripts/lib/spec-lint-test.sh +63 -0
  107. package/scripts/lib/spec-lint.sh +95 -0
  108. package/scripts/lib/sprint-test.sh +96 -0
  109. package/scripts/lib/sprint.sh +216 -0
  110. package/scripts/lib/stage-receipt-test.sh +169 -19
  111. package/scripts/lib/stage-receipt.sh +195 -10
  112. package/scripts/lib/test-forge-shim.sh +115 -0
  113. package/scripts/lib/verbs.sh +105 -0
  114. package/scripts/lib/verbs.tsv +92 -0
  115. package/scripts/lib/version-bump-test.sh +20 -0
  116. package/scripts/lib/version-bump.sh +4 -2
  117. package/scripts/lib/worker-brief-test.sh +1 -1
  118. package/scripts/lib/worker-brief.sh +1 -1
  119. package/scripts/lib/worktree-issue-test.sh +24 -19
  120. package/scripts/lib/worktree-issue.sh +10 -10
  121. package/scripts/lib/worktree-start-test.sh +13 -16
  122. package/scripts/lib/worktree-start.sh +57 -7
  123. package/scripts/loose-issues-test.sh +102 -0
  124. package/scripts/loose-issues.baseline +5 -0
  125. package/scripts/marketing-walkthrough-test.sh +25 -30
  126. package/scripts/night-grant.sh +14 -8
  127. package/scripts/night-run.mjs +1 -1
  128. package/scripts/orchestrate-test.sh +27 -31
  129. package/scripts/orchestrate.sh +9 -3
  130. package/scripts/portable-test.sh +37 -36
  131. package/scripts/publish.sh +9 -3
  132. package/scripts/setup-labels.sh +23 -12
  133. package/scripts/setup-milestones.sh +8 -2
  134. package/scripts/status-test.sh +39 -33
  135. package/scripts/status.sh +12 -6
  136. package/scripts/task-sync-test.sh +75 -32
  137. package/scripts/task-sync.sh +97 -6
  138. package/scripts/terms-check-test.sh +191 -0
  139. package/scripts/terms-check.sh +242 -0
  140. package/scripts/verbs-gen.sh +43 -0
  141. package/scripts/verbs-help-test.sh +61 -0
  142. package/scripts/verbs-ratchet-test.sh +69 -0
  143. package/scripts/verbs-ratchet.sh +34 -0
  144. package/scripts/verbs-test.sh +120 -0
  145. package/scripts/verbs.baseline +5 -0
  146. package/skills/kit-add/SKILL.md +2 -1
  147. package/skills/kit-advisor/SKILL.md +75 -0
  148. package/skills/kit-advisor/references/close.md +53 -0
  149. package/skills/kit-advisor/references/grill.md +69 -0
  150. package/skills/kit-advisor/references/orchestrate.md +56 -0
  151. package/skills/kit-advisor/references/plan.md +64 -0
  152. package/skills/kit-advisor/references/review.md +47 -0
  153. package/skills/kit-advisor/references/step-report.md +61 -0
  154. package/skills/kit-annotate/SKILL.md +1 -0
  155. package/skills/kit-autopilot/SKILL.md +2 -1
  156. package/skills/kit-cleanup/SKILL.md +3 -2
  157. package/skills/kit-contribute/SKILL.md +1 -0
  158. package/skills/kit-customize/SKILL.md +1 -0
  159. package/skills/kit-dev/SKILL.md +1 -0
  160. package/skills/kit-digest/SKILL.md +1 -0
  161. package/skills/kit-docs-writer/SKILL.md +4 -3
  162. package/skills/kit-effort-close/SKILL.md +18 -9
  163. package/skills/kit-effort-new/SKILL.md +12 -8
  164. package/skills/kit-effort-pr/SKILL.md +8 -7
  165. package/skills/kit-effort-start/SKILL.md +1 -0
  166. package/skills/kit-gc/SKILL.md +1 -0
  167. package/skills/kit-next/SKILL.md +8 -7
  168. package/skills/kit-onboard/SKILL.md +1 -0
  169. package/skills/kit-page/SKILL.md +1 -0
  170. package/skills/kit-plan-next/SKILL.md +11 -11
  171. package/skills/kit-security-sweep/SKILL.md +1 -0
  172. package/skills/kit-ship/SKILL.md +1 -0
  173. package/skills/kit-status/SKILL.md +6 -5
  174. package/skills/kit-task-close/SKILL.md +1 -0
  175. package/skills/kit-task-new/SKILL.md +1 -0
  176. package/skills/kit-task-pr/SKILL.md +1 -0
  177. package/skills/kit-task-pr-auto/SKILL.md +2 -1
  178. package/skills/kit-task-pr-merge/SKILL.md +4 -3
  179. package/skills/kit-task-start/SKILL.md +1 -0
  180. package/skills/kit-task-sync/SKILL.md +3 -0
  181. package/skills/kit-ux-audit/SKILL.md +1 -0
  182. package/skills/routing.yaml +124 -0
  183. package/templates/hooks/kit-mail-check.sh.tmpl +1 -1
  184. package/templates/instructions.md.tmpl +3 -3
  185. package/templates/rules/authoring.md +7 -3
  186. package/templates/rules/delegation-brief.md +4 -0
  187. package/templates/rules/effort-model.md +34 -31
  188. package/templates/rules/gate-and-review.md +1 -1
  189. package/templates/rules/merge-safety.md +9 -7
  190. package/templates/rules/naming-and-ids.md +20 -24
  191. package/templates/rules/plan-next.md +5 -5
  192. package/templates/skills/campaign/SKILL.md +2 -2
  193. package/scripts/lib/engine-adapter.sh +0 -93
@@ -32,6 +32,12 @@
32
32
  # effort sub whose commits were merged into a pushed effort branch has no upstream of its own, yet
33
33
  # its work is safely on the remote and is not undone. A branch that merely trails its upstream is
34
34
  # not undone work either, and is deliberately absent. best-effort: without git, no rows.
35
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
36
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
37
+ # shellcheck source=/dev/null
38
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
39
+ fi
40
+
35
41
  status_local_rows() {
36
42
  local base="${1:-${KIT_BASE_BRANCH:-main}}" wtpath ref b up ahead n effort
37
43
  command -v git >/dev/null 2>&1 || return 0
@@ -162,7 +168,7 @@ status_prs_classify() {
162
168
  elif ($ai == 1 and (($p.ai_review // false) | not)) then "ai-review"
163
169
  elif (($p.approvals // 0) == 0) then "review"
164
170
  else "ready" end) as $v |
165
- (if $v == "conflict" then "merge state is CONFLICTING — rebase onto the base"
171
+ (if $v == "conflict" then "merge state is CONFLICTING — merge the base into the branch"
166
172
  elif $v == "checks" then "a required check is failing"
167
173
  elif $v == "draft" then "still a draft"
168
174
  elif $v == "wait" then (if ($p.mergeable // "") == "UNKNOWN" and ($p.checks // "NONE") != "PENDING"
@@ -179,20 +185,20 @@ status_prs_classify() {
179
185
  }
180
186
 
181
187
  # status_prs_fetch — echo the shaped JSON array status_prs_classify expects, for the repo in
182
- # $KIT_REPO. ONE `gh api graphql` call: open PRs with their reviews, review threads and the head
188
+ # $KIT_REPO. ONE `forge_rest graphql` call: open PRs with their reviews, review threads and the head
183
189
  # commit's check rollup, collapsed to the four scalars the classifier reads.
184
190
  #
185
191
  # It always PRINTS a valid JSON array, but the rc distinguishes the two cases a caller must not
186
192
  # conflate: rc 0 means the query ran (`[]` = genuinely no open PRs), rc 1 means it could not run
187
- # (no gh, no jq, no auth, no network) and `[]` means "unknown", not "none". Reporting an empty
193
+ # (no forge, no jq, no auth, no network) and `[]` means "unknown", not "none". Reporting an empty
188
194
  # bucket for an unreachable API is the failure this whole report exists to avoid.
189
195
  status_prs_fetch() {
190
196
  local repo="${1:-${KIT_REPO:-}}" owner name raw
191
- command -v gh >/dev/null 2>&1 || { echo '[]'; return 1; }
197
+ forge_available || { echo '[]'; return 1; }
192
198
  command -v jq >/dev/null 2>&1 || { echo '[]'; return 1; }
193
199
  case "$repo" in */*) owner="${repo%%/*}"; name="${repo##*/}" ;; *) echo '[]'; return 1 ;; esac
194
200
 
195
- raw="$(gh api graphql -f owner="$owner" -f name="$name" -f query='
201
+ raw="$(forge_rest graphql -f owner="$owner" -f name="$name" -f query='
196
202
  query($owner:String!,$name:String!){
197
203
  repository(owner:$owner,name:$name){
198
204
  pullRequests(states:OPEN, first:30, orderBy:{field:UPDATED_AT,direction:DESC}){
@@ -280,7 +286,7 @@ status_cleanup_counts() {
280
286
  prot="$(printf '%s\n' "$out" | grep -c -- '> PROTECTED:' || true)"
281
287
  unknown="$(printf '%s\n' "$out" | grep -c -- '> UNKNOWN ' || true)"
282
288
  fi
283
- if command -v git >/dev/null 2>&1 && command -v gh >/dev/null 2>&1; then
289
+ if command -v git >/dev/null 2>&1 && forge_available; then
284
290
  local base="${KIT_BASE_BRANCH:-main}" idx
285
291
  # ONE PR query, reusing gc's index (#124) instead of a `gh pr list --head` per branch — an N+1
286
292
  # that scales badly exactly when this count matters, i.e. with many stale branches. And
@@ -290,9 +296,8 @@ status_cleanup_counts() {
290
296
  # 2>/dev/null: a failed read already shows as `unknown` rows from kit_gc_analyze above.
291
297
  idx="$(_kit_gc_pr_index "${KIT_GC_REPO:-${KIT_REPO:-}}" 2>/dev/null || true)"
292
298
  else
293
- idx="$(gh pr list --repo "${KIT_REPO:-}" --state all --limit 200 \
294
- --json number,state,headRefName \
295
- --jq '.[] | "\(.headRefName)\tPR#\(.number) \(.state)"' 2>/dev/null || true)"
299
+ idx="$(forge_rest "repos/${KIT_REPO:-}/pulls" -X GET -f state=all -f per_page=100 --paginate \
300
+ --jq '.[] | "\(.head.ref)\tPR#\(.number) \(if .merged_at then "MERGED" else (.state | ascii_upcase) end)"' 2>/dev/null || true)"
296
301
  fi
297
302
  while IFS= read -r r; do
298
303
  [ -n "$r" ] || continue
@@ -346,7 +351,7 @@ status_next_efforts_md() {
346
351
  echo ""
347
352
  rows="$(status_next_efforts_rows "${1:-}")" || ne_rc=$?
348
353
  if [ "$ne_rc" -ne 0 ]; then
349
- echo "_Could not read the open efforts (gh or jq absent, unauthenticated, or offline). This is NOT"
354
+ echo "_Could not read the open efforts (no forge or jq, unauthenticated, or offline). This is NOT"
350
355
  echo "the same as having none._"
351
356
  elif [ -z "$rows" ]; then
352
357
  echo "_No open issue carries the \`effort\` label, so there is no effort to order."
@@ -500,14 +505,14 @@ EOF
500
505
  echo ""
501
506
  echo "## 2 · PRs waiting on a human"
502
507
  echo ""
503
- if command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
508
+ if forge_available && command -v jq >/dev/null 2>&1; then
504
509
  local pr_rc=0
505
510
  prs="$(status_prs_fetch)" || pr_rc=$?
506
511
  ai="$(status_ai_expected "$root" "$prs")"
507
512
  prrows="$(printf '%s' "$prs" | status_prs_classify "$ai")"
508
513
  if [ "$pr_rc" -ne 0 ]; then
509
- echo "_Could not read the open PRs (gh unavailable, unauthenticated, or offline). This is NOT"
510
- echo "the same as having none — re-run once \`gh auth status\` is clean._"
514
+ echo "_Could not read the open PRs (the forge is unreachable, the token invalid, or offline). This is NOT"
515
+ echo "the same as having none — re-run once \`cckit doctor\` shows the forge signed in._"
511
516
  elif [ -n "$prrows" ]; then
512
517
  echo "| PR | what it needs | title |"
513
518
  echo "| --- | --- | --- |"
@@ -570,7 +575,7 @@ status_buckets_json() {
570
575
  command -v jq >/dev/null 2>&1 || {
571
576
  printf '%s\n' '{"error":"jq is required for --llm output","deps":{"jq":false}}'; return 1; }
572
577
  local pr_rc=0 has_gh=false has_git=false
573
- command -v gh >/dev/null 2>&1 && has_gh=true
578
+ forge_available && has_gh=true # deps.gh: a forge is available (the key name is kept for readers)
574
579
  command -v git >/dev/null 2>&1 && has_git=true
575
580
  rows="$(status_local_rows "$base")"
576
581
  local wt_rows; wt_rows="$(status_worktree_rows)"
@@ -31,7 +31,9 @@ if [ -n "${KTO_TEST_INNER:-}" ]; then
31
31
  eq "base override" "$(KIT_BASE_BRANCH=main; kto_base_branch)" "main"
32
32
  eq "base explicit wins" "$(KIT_BASE_BRANCH=develop; kto_base_branch release)" "release"
33
33
  eq "base explicit empty" "$(KIT_BASE_BRANCH=develop; kto_base_branch '')" "develop"
34
- if ( unset KIT_PROJECTS_V2; kto_board_enabled ); then eq "board default on" "on" "on"; else eq "board default on" "off" "on"; fi
34
+ # The board is on by default — given a forge (it is GraphQL on GitHub): with none it is skipped.
35
+ if ( unset KIT_PROJECTS_V2; CCKIT_FORGE=github kto_board_enabled ); then eq "board default on" "on" "on"; else eq "board default on" "off" "on"; fi
36
+ if ( unset KIT_PROJECTS_V2; CCKIT_FORGE=none kto_board_enabled 2>/dev/null ); then eq "board off with no forge" "on" "off"; else eq "board off with no forge" "off" "off"; fi
35
37
  ( KIT_PROJECTS_V2=false; if kto_board_enabled; then exit 0; else exit 1; fi ) \
36
38
  && eq "board off" "on" "off" || eq "board off" "off" "off"
37
39
 
@@ -69,6 +71,23 @@ if [ -n "${KTO_TEST_INNER:-}" ]; then
69
71
  eq "titleStyle issue-title → the issue title verbatim" \
70
72
  "$(KIT_PR_TITLE_STYLE=issue-title kto_pr_title '[Effort 182] 1 · Enforce it' 'ci: x' 'kind:task')" \
71
73
  "[Effort 182] 1 · Enforce it"
74
+ # The trailing token (E546.1), when the issue number is given
75
+ eq "standalone issue → [#N]" \
76
+ "$(kto_pr_title 'mail hook goes silent' '' 'bug' 209)" \
77
+ "fix: mail hook goes silent [#209]"
78
+ eq "new sub title → [E<n>.<s>]" \
79
+ "$(kto_pr_title '[E546.1] One naming convention' '' 'kind:feat' 567)" \
80
+ "feat: One naming convention [E546.1]"
81
+ eq "legacy sub title → [E<n>.<s>]" \
82
+ "$(kto_pr_title '[Effort 182] 2 · Publish to npm' 'ci: publish via OIDC' 'kind:task' 184)" \
83
+ "ci: publish via OIDC [E182.2]"
84
+ eq "a summary that carries a token keeps it" \
85
+ "$(kto_pr_title 'x' 'fix(start): keep it [#12]' 'kind:task' 12)" \
86
+ "fix(start): keep it [#12]"
87
+ eq "issue-title style appends nothing" \
88
+ "$(KIT_PR_TITLE_STYLE=issue-title kto_pr_title 'Enforce it' '' 'kind:task' 12)" \
89
+ "Enforce it"
90
+ if naming_title_lint pr "$(kto_pr_title '[E546.1] One naming convention' '' 'kind:feat' 567)" 2>/dev/null; then :; else eq "generated PR title passes the naming lint" "no" "yes"; fi
72
91
  eq "titleStyle conventional (explicit) → derive" \
73
92
  "$(KIT_PR_TITLE_STYLE=conventional kto_pr_title 'mail hook goes silent' '' 'bug')" \
74
93
  "fix: mail hook goes silent"
@@ -22,13 +22,19 @@
22
22
  # kto_closing_issue_numbers <pr-num> echo the issue #s a merged PR closes
23
23
  # kto_task_pr <num> <summary> [commit-msg] [--base <branch>] commit+push+open PR (board → In Review)
24
24
  # kto_task_pr_merge [pr-num] [--squash|--merge|--rebase] merge (squash default) + close issues + GC + update the PR base; refuses an effort/* head
25
- # kto_task_new <title> <role> <kind> <prio> [ms] [plan] [blocked] <body> create issue + board fields (ms may be empty)
25
+ # kto_task_new <title> <role> <kind> <prio> [ms] [plan] [blocked] <body> lint the title, create issue + board fields (ms may be empty)
26
26
  # kto_task_close <num> <summary> [pr-num] [--reason R] [--duplicate-of N] [--superseded-by N] close + reason + board → Done
27
27
  # errors: mixed — git/gh ops propagate; board + label side effects are best-effort
28
28
 
29
29
  # --- repo resolution -----------------------------------------------------------------------------
30
30
  # Resolve the repo slug from KIT_REPO (kit-config) when available, else the kit's home repo. A
31
31
  # caller may export KIT_TASK_REPO to override.
32
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
33
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
34
+ # shellcheck source=/dev/null
35
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
36
+ fi
37
+
32
38
  if [[ -z "${KIT_REPO:-}" ]]; then
33
39
  _kto_root="$(git rev-parse --show-toplevel 2>/dev/null || true)"
34
40
  if [[ -n "$_kto_root" && -f "$_kto_root/scripts/lib/kit-config.sh" ]]; then
@@ -38,7 +44,7 @@ if [[ -z "${KIT_REPO:-}" ]]; then
38
44
  unset _kto_root
39
45
  fi
40
46
 
41
- # The GitHub transport switch (#396): in rest mode every gh call below is `gh api repos/…`.
47
+ # The GitHub transport switch (#396): in rest mode every gh call below is `forge_rest repos/…`.
42
48
  if ! type cckit_gh_rest >/dev/null 2>&1; then
43
49
  if [ -n "${BASH_SOURCE:-}" ]; then _kto_self="${BASH_SOURCE[0]}"
44
50
  elif [ -n "${ZSH_VERSION:-}" ]; then eval '_kto_self="${(%):-%x}"'
@@ -62,6 +68,18 @@ if ! type kit_kind_commit_type >/dev/null 2>&1; then
62
68
  fi
63
69
  type cckit_board_skipped >/dev/null 2>&1 || cckit_board_skipped() { return 1; }
64
70
 
71
+ # The one title convention (naming.sh, E546.1): kto_task_new lints the issue title and kto_task_pr
72
+ # the PR title before any forge write; kto_pr_title strips issue prefixes and appends the token.
73
+ if ! type naming_title_lint >/dev/null 2>&1; then
74
+ if [ -n "${BASH_SOURCE:-}" ]; then _kto_self="${BASH_SOURCE[0]}"
75
+ elif [ -n "${ZSH_VERSION:-}" ]; then eval '_kto_self="${(%):-%x}"'
76
+ else _kto_self="$0"; fi
77
+ _kto_self="$(cd "$(dirname "$_kto_self")" 2>/dev/null && pwd)/naming.sh"
78
+ # shellcheck source=naming.sh
79
+ [ -f "$_kto_self" ] && . "$_kto_self"
80
+ unset _kto_self
81
+ fi
82
+
65
83
  kto_repo() {
66
84
  printf '%s' "${KIT_TASK_REPO:-${KIT_REPO:-}}"
67
85
  }
@@ -103,13 +121,34 @@ kto_labels_kind() {
103
121
  # Compose the PR title as a Conventional Commit subject. Because PRs are squash-merged, this title
104
122
  # becomes the single commit release-please reads to pick the next version — a non-conventional title
105
123
  # under-bumps silently, and the commitlint gate (.github/workflows/commitlint.yml) now rejects it.
106
- # Args: <raw-issue-title> <summary> <labels-csv>
124
+ # Args: <raw-issue-title> <summary> <labels-csv> [<issue-num>]
107
125
  # 1. An author <summary> that is ALREADY a conventional subject wins — the author knows the change's
108
126
  # true type (e.g. a kind:task that is really a fix). Validated by the shared commitlint.sh.
109
127
  # 2. Otherwise derive the type from the kind:/bug label (kind:task, the default, → feat) and strip
110
- # the "[Effort N] M · " / leading "[Tag] " noise from the issue title.
128
+ # the issue title's prefix, new ([E<n>.<s>] ) or legacy ([Effort N] M · ), and a leading [Tag].
129
+ # 3. With <issue-num>, the title ends in the work's token (rules/naming-and-ids.md) unless it
130
+ # already does: [E<n>.<s>] when the issue is a sub, [E<n>] when it is an effort, else [#<num>].
111
131
  # Network-free (covered by the self-test). Output always passes commitlint_check.
112
132
  kto_pr_title() {
133
+ local raw="${1:-}" summary="${2:-}" labels="${3:-}" num="${4:-}" t
134
+ t="$(_kto_pr_title_subject "$raw" "$summary" "$labels")" || return 1
135
+ if [ -n "$num" ] && [ "${KIT_PR_TITLE_STYLE:-conventional}" != "issue-title" ]; then
136
+ t="$(_kto_pr_title_token "$t" "$raw" "$num")"
137
+ fi
138
+ printf '%s' "$t"
139
+ }
140
+
141
+ # _kto_pr_title_token <title> <raw-issue-title> <num> — <title> with the work's trailing token.
142
+ _kto_pr_title_token() {
143
+ local t="$1" raw="$2" num="${3#\#}" tok=""
144
+ if grep -qE '\[(E[0-9]+(\.[0-9]+)?|#[0-9]+|share-[0-9]+)\][[:space:]]*$' <<<"$t"; then printf '%s' "$t"; return 0; fi
145
+ if type naming_title_token >/dev/null 2>&1; then tok="$(naming_title_token "$raw" 2>/dev/null || true)"; fi
146
+ [ -n "$tok" ] || tok="#$num"
147
+ printf '%s [%s]' "$t" "$tok"
148
+ }
149
+
150
+ # _kto_pr_title_subject <raw-issue-title> <summary> <labels-csv> — steps 1 and 2 of kto_pr_title.
151
+ _kto_pr_title_subject() {
113
152
  local raw="${1:-}" summary="${2:-}" labels="${3:-}" kind ctype desc
114
153
  # pr.titleStyle = issue-title (KIT_PR_TITLE_STYLE): the PR title IS the issue title, verbatim — for
115
154
  # repos whose convention is "PR title = exact issue title" and that run no commitlint gate.
@@ -122,10 +161,15 @@ kto_pr_title() {
122
161
  local _cl; _cl="$(git rev-parse --show-toplevel 2>/dev/null)/scripts/lib/commitlint.sh"
123
162
  [ -f "$_cl" ] && . "$_cl" 2>/dev/null || true
124
163
  fi
125
- # 1) Prefer an author-provided conventional summary.
164
+ # 1) Prefer an author-provided conventional summary. Without commitlint.sh (a project that is not
165
+ # cckit), the shape alone decides: `type(scope)!: subject`.
126
166
  if [ -n "$summary" ] && type commitlint_check >/dev/null 2>&1 && commitlint_check "$summary" >/dev/null 2>&1; then
127
167
  printf '%s' "$summary"; return 0
128
168
  fi
169
+ if [ -n "$summary" ] && ! type commitlint_check >/dev/null 2>&1 \
170
+ && grep -qE '^[a-z]+(\([^)]*\))?!?: [^[:space:]]' <<<"$summary"; then
171
+ printf '%s' "$summary"; return 0
172
+ fi
129
173
  # 2) Derive the type from the kind:/bug label.
130
174
  kind="$(kto_labels_kind "$labels")"
131
175
  # The kind -> type map is kinds.sh's (kit_kind_commit_type): a content kind (post, campaign,
@@ -141,14 +185,18 @@ kto_pr_title() {
141
185
  esac
142
186
  fi
143
187
  case ",$labels," in *,bug,*) ctype=fix ;; esac # a plain `bug` label → fix
144
- # 3) Strip "[Effort N] M · " (the "· " consumed here as a literal — byte-wise match is portable
145
- # across BSD/GNU sed + locales; a negated class over the multibyte middot is not) and then a
146
- # leading "[Tag] " (e.g. [Core]). Order matters: eat the separator before the next tag's "[".
188
+ # 3) Strip "[E<n>.<s>] " / "[E<n>] " and the legacy "[Effort N] M · " (the "· " consumed here as
189
+ # a literal — byte-wise match is portable across BSD/GNU sed + locales; a negated class over the
190
+ # multibyte middot is not), then a leading "[Tag] " (e.g. [Core]). Order matters: eat the
191
+ # separator before the next tag's "[".
147
192
  desc="$(printf '%s' "$raw" | sed -E \
193
+ -e 's/^\[E[0-9]+(\.[0-9]+)?\] +//' \
148
194
  -e 's/^\[Effort[^]]*\] +[0-9]+ +· +//' \
149
195
  -e 's/^\[[^]]+\] +//' \
150
196
  -e 's/^[[:space:]]+//')"
151
197
  [ -n "$desc" ] || desc="$raw"
198
+ # No issue title (no forge read it): the summary is the subject.
199
+ [ -n "$desc" ] || desc="$(printf '%s' "$summary" | sed -E 's/^[a-z]+(\([^)]*\))?!?: //')"
152
200
  printf '%s: %s' "$ctype" "$desc"
153
201
  }
154
202
 
@@ -262,16 +310,7 @@ kto_compose_issue_body() {
262
310
  kto_closing_issue_numbers() {
263
311
  local pr="$1" repo issues body
264
312
  repo="$(kto_repo)"
265
- if cckit_gh_rest; then gh_rest_pr_closing_issues "$repo" "$pr"; return 0; fi
266
- issues=$(gh pr view "$pr" --repo "$repo" --json closingIssuesReferences \
267
- --jq '.closingIssuesReferences[].number' 2>/dev/null)
268
- if [[ -z "$issues" ]]; then
269
- body=$(gh pr view "$pr" --repo "$repo" --json body --jq .body 2>/dev/null)
270
- issues=$(printf '%s\n' "$body" \
271
- | grep -ioE '(close[sd]?|fix(e[sd])?|resolve[sd]?) +#[0-9]+' \
272
- | grep -oE '[0-9]+' | sort -u)
273
- fi
274
- printf '%s' "$issues"
313
+ gh_rest_pr_closing_issues "$repo" "$pr"; return 0
275
314
  }
276
315
 
277
316
  # --- the four ops (network; not exercised by the self-test) --------------------------------------
@@ -329,14 +368,25 @@ kto_task_pr() {
329
368
  [[ -n "$num" ]] || { echo "✗ kto_task_pr: branch '$branch' doesn't match <kind>/<N>-<slug> and no issue number passed" >&2; return 1; }
330
369
  [[ -n "$summary" ]] || { echo "✗ kto_task_pr: a Summary is required (never invent one)" >&2; return 1; }
331
370
 
332
- if cckit_gh_rest; then meta=$(gh_rest_issue_json "$repo" "$num") || return 1
333
- else meta=$(gh issue view "$num" --repo "$repo" --json title,labels,milestone) || return 1; fi
334
- title=$(printf '%s' "$meta" | jq -r .title)
335
- labels=$(printf '%s' "$meta" | jq -r '[.labels[].name] | join(",")')
336
- milestone=$(printf '%s' "$meta" | jq -r '.milestone.title // ""')
371
+ if forge_available; then
372
+ meta=$(gh_rest_issue_json "$repo" "$num") || return 1
373
+ title=$(printf '%s' "$meta" | jq -r .title)
374
+ labels=$(printf '%s' "$meta" | jq -r '[.labels[].name] | join(",")')
375
+ milestone=$(printf '%s' "$meta" | jq -r '.milestone.title // ""')
376
+ else
377
+ # The git steps run: commit and push. The issue is not read and the pull request is not opened;
378
+ # the compare page is printed when origin is on GitHub.
379
+ forge_note_none pr "issue #$num is not read and the pull request is not opened; the branch is committed and pushed"
380
+ title=""; labels=""; milestone=""
381
+ fi
337
382
  role="$(kto_labels_role "$labels")"
338
383
  # Conventional Commit PR title (squash-merge commit release-please reads + the commitlint gate).
339
- local pr_title; pr_title="$(kto_pr_title "$title" "$summary" "$labels")"
384
+ local pr_title; pr_title="$(kto_pr_title "$title" "$summary" "$labels" "$num")"
385
+ # The naming rule (E546.1) before the commit, the push or the PR: a Conventional Commit subject
386
+ # ending in the work's token. Refused here, nothing is written.
387
+ if type naming_title_lint >/dev/null 2>&1; then
388
+ naming_title_lint pr "$pr_title" || { echo "✗ kto_task_pr: the PR title breaks the naming rule — pass a summary of the form 'type(scope): subject'" >&2; return 1; }
389
+ fi
340
390
  [[ -z "$commit_msg" ]] && commit_msg="$pr_title"
341
391
 
342
392
  # TRACKED changes only: `git add -A` would sweep an untracked .env.local (copied into every worktree)
@@ -357,26 +407,22 @@ kto_task_pr() {
357
407
 
358
408
  KIT_PR_BASE="$base" git push -u origin "$branch" || return 1
359
409
 
360
- if cckit_gh_rest; then
361
- url=$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" \
362
- "$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" "$labels" "$milestone") || return 1
363
- else
364
- url=$(gh pr create --repo "$repo" \
365
- --base "$base" --head "$branch" \
366
- --title "$pr_title" \
367
- --body "$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" \
368
- --label "$labels" \
369
- ${milestone:+--milestone "$milestone"} \
370
- --assignee "@me") || return 1
410
+ if ! forge_available; then
411
+ local cmp; cmp="$(forge_compare_url "$base" "$branch" 2>/dev/null || true)"
412
+ if [[ -n "$cmp" ]]; then echo "✓ pushed $branch → open the pull request: $cmp"
413
+ else echo "✓ pushed $branch (no forge: open the pull request on your forge, $branch → $base)"; fi
414
+ return 0
371
415
  fi
416
+ url=$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" \
417
+ "$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" "$labels" "$milestone") || return 1
372
418
  echo "✓ $url"
373
419
 
374
420
  # Board: add the PR (In Review) + move the issue to In Review. Best-effort — never fail the op.
375
421
  if kto_board_enabled && type load_project_ids >/dev/null 2>&1 && load_project_ids 2>/dev/null; then
376
422
  pr_num="$(basename "$url")"
377
- pr_node=$(gh api "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)
423
+ pr_node=$(forge_rest "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)
378
424
  if [[ -n "$pr_node" ]]; then
379
- item=$(project_add_item "$pr_node" 2>/dev/null || true)
425
+ item=$(project_add_item "$pr_node" "$repo" "$pr_num" PullRequest 2>/dev/null || true)
380
426
  if [[ -n "$item" ]]; then
381
427
  role_opt="$(_kto_role_option_for_slug "$role")"
382
428
  [[ -n "$role_opt" ]] && project_set_single_select "$item" "$ROLE_FIELD_ID" "$role_opt" 2>/dev/null || true
@@ -389,7 +435,7 @@ kto_task_pr() {
389
435
  fi
390
436
  }
391
437
 
392
- # kit task pr-merge — merge a PR (squash by default; --merge or --rebase), rebase-fix conflicts onto
438
+ # kit task pr-merge — merge a PR (squash by default; --merge or --rebase), merge-fix conflicts from
393
439
  # the PR's base first, close its linked issues (GitHub native auto-close only fires on the default
394
440
  # branch), then clean up the PR's head branch + worktree and bring the PR's base up to date.
395
441
  # Args: [<pr-num>] [--squash|--merge|--rebase] (the PR defaults to the open PR for the current branch)
@@ -423,15 +469,19 @@ kto_task_pr_merge() {
423
469
  echo "✗ Working tree is dirty — commit or stash changes first" >&2; return 1
424
470
  fi
425
471
 
472
+ if ! forge_available; then
473
+ [[ -z "$input_pr" ]] || { echo "✗ cckit merge: no forge — a pull request number cannot be read; run it from the branch's worktree with no argument" >&2; return 1; }
474
+ _kto_local_merge "$branch" "$base" "$method"
475
+ return $?
476
+ fi
477
+
426
478
  pr_num="$input_pr"
427
479
  if [[ -z "$pr_num" ]]; then
428
- if cckit_gh_rest; then pr_num=$(gh_rest_pr_for_head "$repo" "$branch")
429
- else pr_num=$(gh pr list --repo "$repo" --head "$branch" --state open --json number --jq '.[0].number // empty'); fi
480
+ pr_num=$(gh_rest_pr_for_head "$repo" "$branch")
430
481
  [[ -z "$pr_num" ]] && { echo "✗ No open PR found for branch $branch" >&2; return 1; }
431
482
  fi
432
483
 
433
- if cckit_gh_rest; then meta=$(gh_rest_pr_json "$repo" "$pr_num") || return 1
434
- else meta=$(gh pr view "$pr_num" --repo "$repo" --json mergeable,mergeStateStatus,baseRefName,headRefName) || return 1; fi
484
+ meta=$(gh_rest_pr_json "$repo" "$pr_num") || return 1
435
485
  merge_state=$(printf '%s' "$meta" | jq -r '.mergeable // ""')
436
486
  pr_base=$(printf '%s' "$meta" | jq -r '.baseRefName // empty'); pr_base="${pr_base:-$base}"
437
487
  head=$(printf '%s' "$meta" | jq -r '.headRefName // empty'); head="${head:-$branch}"
@@ -452,32 +502,28 @@ kto_task_pr_merge() {
452
502
  fi
453
503
  fi
454
504
 
455
- # Branches that are never rebased, force-pushed or deleted here: the repo base, the PR's base
456
- # (it may be an effort branch), and the release branches (#366).
505
+ # Branches that are never merged into, pushed to or deleted here: the repo base, the PR's base
506
+ # (it may be an effort branch), and the release branches (#366). A pushed branch is brought onto
507
+ # its base by merge, never by rebase, so no push here needs --force (#592).
457
508
  _kto_protected() { case "$1" in "$base"|"$pr_base"|main|master|develop|HEAD) return 0 ;; esac; return 1; }
458
509
 
459
510
  if [[ "$merge_state" == "CONFLICTING" ]]; then
460
511
  if [[ "$branch" != "$head" ]] || _kto_protected "$branch"; then
461
- echo "✗ PR #$pr_num conflicts — rebase $head onto $pr_base from its own worktree (not from $branch)" >&2; return 1
512
+ echo "✗ PR #$pr_num conflicts — merge origin/$pr_base into $head from its own worktree (not from $branch)" >&2; return 1
462
513
  fi
463
- echo "→ Conflicts detected — rebasing onto $pr_base..."
514
+ echo "→ Conflicts detected — merging origin/$pr_base into $head..."
464
515
  git fetch origin "$pr_base"
465
- if git rebase "origin/$pr_base"; then
466
- git push --force-with-lease origin "$head"
467
- echo "✓ Rebased and pushed — re-checking mergeability..."
516
+ if git merge --no-edit "origin/$pr_base"; then
517
+ git push origin "$head"
518
+ echo "✓ Merged $pr_base in and pushed — re-checking mergeability..."
468
519
  else
469
- echo "✗ Rebase had conflicts that need manual resolution — resolve, then run cckit merge again" >&2
470
- git rebase --abort 2>/dev/null || true
520
+ echo "✗ Merge had conflicts that need manual resolution — from this branch's worktree run: git merge origin/$pr_base, resolve, commit, push, then run cckit merge again" >&2
521
+ git merge --abort 2>/dev/null || true
471
522
  return 1
472
523
  fi
473
524
  fi
474
525
 
475
- if cckit_gh_rest; then
476
- if ! gh_rest_pr_merge "$repo" "$pr_num" "$method" 2>&1; then
477
- echo "✗ Merge failed — check PR status: https://github.com/$repo/pull/$pr_num" >&2
478
- return 1
479
- fi
480
- elif ! gh pr merge "$pr_num" --repo "$repo" "--$method" 2>&1; then
526
+ if ! gh_rest_pr_merge "$repo" "$pr_num" "$method" 2>&1; then
481
527
  echo "✗ Merge failed — check PR status: https://github.com/$repo/pull/$pr_num" >&2
482
528
  return 1
483
529
  fi
@@ -489,16 +535,11 @@ kto_task_pr_merge() {
489
535
  # IFS, and a NUL-polluted IFS passed "1020\n1021" to gh as one issue number.
490
536
  while IFS= read -r n <&3; do
491
537
  [[ "$n" =~ ^[0-9]+$ ]] || continue
492
- if cckit_gh_rest; then state=$(gh_rest_issue_state "$repo" "$n" 2>/dev/null)
493
- else state=$(gh issue view "$n" --repo "$repo" --json state --jq .state 2>/dev/null); fi
494
- if [[ "$state" == "OPEN" ]] && cckit_gh_rest; then
538
+ state=$(gh_rest_issue_state "$repo" "$n" 2>/dev/null)
539
+ if [[ "$state" == "OPEN" ]]; then
495
540
  gh_rest_issue_close "$repo" "$n" completed \
496
541
  "Closed automatically on merge of #$pr_num to $pr_base (cckit merge; GitHub native auto-close only fires on the default branch)." \
497
542
  && echo "✓ Closed issue #$n"
498
- elif [[ "$state" == "OPEN" ]]; then
499
- gh issue close "$n" --repo "$repo" \
500
- --comment "Closed automatically on merge of #$pr_num to $pr_base (cckit merge; GitHub native auto-close only fires on the default branch)." \
501
- && echo "✓ Closed issue #$n"
502
543
  elif [[ -n "$state" ]]; then
503
544
  echo " issue #$n already $state — skipped"
504
545
  fi
@@ -506,6 +547,57 @@ kto_task_pr_merge() {
506
547
  $issues
507
548
  EOF
508
549
 
550
+ _kto_merge_cleanup "$head" "$pr_base" "$base"
551
+ }
552
+
553
+ # _kto_local_merge <branch> <base> <squash|merge|rebase> — the forge-less merge (E537.4): the
554
+ # branch lands on the base through git alone. From the main checkout: fetch the base, fast-forward
555
+ # it, merge the branch (a squash commit titled after the branch's last commit; --merge keeps the
556
+ # commits under a merge commit; --rebase replays the branch first and fast-forwards), push the base.
557
+ # Then the usual cleanup. Linked issues are not closed: that needs a forge, and the note says so.
558
+ _kto_local_merge() {
559
+ local head="$1" base="$2" method="$3" main_wt common subject rc=0
560
+ forge_note_none merge "the branch lands on $base through git; no pull request is merged and no issue is closed"
561
+ if [[ "$head" == effort/* ]]; then
562
+ echo "✗ $head is an effort branch — merge it with: cckit effort close ${head#effort/}" >&2; return 1
563
+ fi
564
+ case "$head" in "$base"|main|master|develop|HEAD) echo "✗ cckit merge: run it from the branch to merge, not from $head" >&2; return 1 ;; esac
565
+ common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
566
+ main_wt=""
567
+ [[ -n "$common" && "$(basename "$common")" == ".git" ]] && main_wt="$(dirname "$common")"
568
+ [[ -n "$main_wt" ]] || main_wt=$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')
569
+ if [[ -n "$(git -C "$main_wt" status --porcelain --untracked-files=no)" ]]; then
570
+ echo "✗ cckit merge: the main checkout $main_wt has uncommitted changes — commit or discard them first" >&2; return 1
571
+ fi
572
+ git -C "$main_wt" fetch -q origin "$base" 2>/dev/null || true
573
+ git -C "$main_wt" checkout -q "$base" 2>/dev/null || { echo "✗ cckit merge: cannot check out $base in $main_wt" >&2; return 1; }
574
+ git -C "$main_wt" merge -q --ff-only "origin/$base" 2>/dev/null || true
575
+ subject="$(git log -1 --format=%s "$head")"
576
+ case "$method" in
577
+ squash)
578
+ git -C "$main_wt" merge -q --squash "$head" >/dev/null 2>&1 || rc=1
579
+ [[ $rc -eq 0 ]] && { git -C "$main_wt" commit -q -m "$subject" >/dev/null 2>&1 || rc=1; } ;;
580
+ merge)
581
+ git -C "$main_wt" merge -q --no-ff -m "Merge branch '$head' into $base" "$head" >/dev/null 2>&1 || rc=1 ;;
582
+ rebase)
583
+ git -C "$(git rev-parse --show-toplevel)" rebase -q "$base" >/dev/null 2>&1 || rc=1
584
+ [[ $rc -eq 0 ]] && { git -C "$main_wt" merge -q --ff-only "$head" >/dev/null 2>&1 || rc=1; } ;;
585
+ esac
586
+ if [[ $rc -ne 0 ]]; then
587
+ git -C "$main_wt" merge --abort >/dev/null 2>&1 || git -C "$main_wt" reset -q --hard "origin/$base" >/dev/null 2>&1 || true
588
+ echo "✗ cckit merge: $head does not merge cleanly onto $base — rebase it onto origin/$base in its worktree and rerun" >&2
589
+ return 1
590
+ fi
591
+ git -C "$main_wt" push -q origin "$base" 2>/dev/null || { echo "✗ cckit merge: merged locally on $base but the push to origin failed — push $base yourself" >&2; return 1; }
592
+ echo "✓ $head merged into $base ($method) and pushed"
593
+ _kto_merge_cleanup "$head" "$base" "$base"
594
+ }
595
+
596
+ # _kto_merge_cleanup <head> <pr-base> <base> — remove the merged branch's worktree and branches,
597
+ # then bring the PR's base up to date where it lives. Shared by the forge and the git-only merge.
598
+ _kto_merge_cleanup() {
599
+ local head="$1" pr_base="$2" base="$3" wt base_wt common main_wt
600
+ _kto_protected() { case "$1" in "$base"|"$pr_base"|main|master|develop|HEAD) return 0 ;; esac; return 1; }
509
601
  # Clean up FROM the main checkout (#371): run from the PR's own worktree, removing it deletes our
510
602
  # cwd. Main checkout = parent of the shared git dir; fall back to the first `worktree list` entry.
511
603
  wt=$(git worktree list --porcelain | awk -v b="refs/heads/$head" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
@@ -524,7 +616,7 @@ EOF
524
616
  echo " ($head is protected — no branch cleanup)"
525
617
  else
526
618
  git -C "$main_wt" branch -D "$head" 2>/dev/null && echo "✓ Deleted local branch $head"
527
- if cckit_gh_rest; then
619
+ if cckit_in_cloud; then
528
620
  # The cloud proxy rejects branch deletion (#396): keep it and say so.
529
621
  echo " (remote branch $head kept — branch deletion is unavailable here; delete it on GitHub)"
530
622
  else
@@ -556,12 +648,7 @@ EOF
556
648
  # match case-insensitively, as GitHub's do. A label list that cannot be read filters nothing.
557
649
  _kto_existing_labels() {
558
650
  local repo="$1" want="$2" have l keep=""
559
- if cckit_gh_rest; then
560
- have="$(gh_rest_label_names "$repo")" || { printf '%s' "$want"; return 0; }
561
- else
562
- have="$(gh label list --repo "$repo" --limit 1000 --json name --jq '.[].name' 2>/dev/null)" \
563
- || { printf '%s' "$want"; return 0; }
564
- fi
651
+ have="$(gh_rest_label_names "$repo")" || { printf '%s' "$want"; return 0; }
565
652
  while IFS= read -r l; do
566
653
  [[ -n "$l" ]] || continue
567
654
  if grep -qixF -- "$l" <<<"$have"; then
@@ -576,45 +663,49 @@ EOF
576
663
  }
577
664
 
578
665
  # kit task new — create a GitHub issue with labels + milestone, add it to the board, set Role +
579
- # Status(Todo) + Plan Link. Inputs are passed (the caller does the AskUserQuestion). No invented
666
+ # Status (Backlog when no milestone is named and the board has that option, else Todo) + Plan Link. Inputs are passed (the caller does the AskUserQuestion). No invented
580
667
  # values: a label the repo does not have is dropped with a warning, never created, and the issue is
581
668
  # still filed (#387). Non-zero only when the issue itself was not created.
582
669
  # Args: <title> <role-display-or-slug> <kind> <priority> [milestone|""] [plan-link] [blocked-by] <body>
583
670
  kto_task_new() {
584
671
  local title="${1:-}" role="${2:-}" kind="${3:-}" prio="${4:-}" milestone="${5:-}" plan="${6:-}" blocked="${7:-}" body_user="${8:-}"
585
- local repo role_slug labels body url num node item role_opt
672
+ local repo role_slug labels body url num node item role_opt status_opt
586
673
  repo="$(kto_repo)"
587
674
  # Milestone is optional: a repo with no milestones (cckit itself) must still be able to file an
588
675
  # issue through the verb, or agents fall back to raw `gh issue create` and the board drops it.
589
676
  [[ -n "$title" && -n "$role" && -n "$kind" && -n "$prio" ]] || {
590
677
  echo "✗ kto_task_new: title, role, kind, priority are required" >&2; return 1; }
591
678
 
679
+ # The naming rule (E546.1): a standalone issue is a plain outcome of at most six words, no prefix.
680
+ # Checked before any forge read or write; multi-part work is `cckit effort new`.
681
+ if type naming_title_lint >/dev/null 2>&1; then
682
+ naming_title_lint issue "$title" || { echo "✗ kto_task_new: fix the title and retry — nothing was filed" >&2; return 1; }
683
+ fi
684
+
592
685
  role_slug="$(printf '%s' "$role" | tr 'A-Z ' 'a-z-')"
593
686
  labels="kind:${kind},priority:${prio},role:${role_slug}"
594
687
  body="$(kto_compose_issue_body "$body_user" "$plan" "$blocked" "$role_slug")"
595
688
  labels="$(_kto_existing_labels "$repo" "$labels")"
596
689
 
597
- if cckit_gh_rest; then
598
- url=$(gh_rest_issue_create "$repo" "$title" "$body" "$labels" "$milestone") || return 1
599
- else
600
- url=$(gh issue create --repo "$repo" \
601
- --title "$title" --body "$body" \
602
- ${labels:+--label} ${labels:+"$labels"} ${milestone:+--milestone "$milestone"} --assignee "@me") || return 1
603
- fi
690
+ url=$(gh_rest_issue_create "$repo" "$title" "$body" "$labels" "$milestone") || return 1
604
691
  num=$(basename "$url")
605
692
  echo "✓ $url"
606
693
 
607
694
  if kto_board_enabled && type load_project_ids >/dev/null 2>&1 && load_project_ids 2>/dev/null; then
608
- node=$(gh api "repos/$repo/issues/$num" --jq .node_id 2>/dev/null)
695
+ node=$(forge_rest "repos/$repo/issues/$num" --jq .node_id 2>/dev/null)
609
696
  item=""
610
- [[ -n "$node" ]] && item=$(project_add_item "$node" 2>/dev/null || true)
697
+ [[ -n "$node" ]] && item=$(project_add_item "$node" "$repo" "$num" Issue 2>/dev/null || true)
611
698
  # Loud, not silent: an issue missing from the board is the failure this verb exists to prevent.
612
699
  [[ -z "$item" ]] && echo "⚠ #$num was created but NOT added to the board — add it by hand" >&2
613
700
  if [[ -n "$node" ]]; then
614
701
  if [[ -n "$item" ]]; then
615
702
  role_opt="$(_kto_role_option_for_slug "$role_slug")"
616
703
  [[ -n "$role_opt" ]] && project_set_single_select "$item" "$ROLE_FIELD_ID" "$role_opt" 2>/dev/null || true
617
- [[ -n "${STATUS_OPT_TODO:-}" ]] && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_TODO" 2>/dev/null || true
704
+ # No sprint (milestone) named: the issue waits in the Backlog column, so it is not loose
705
+ # (E546.2). A board without a Backlog option keeps Todo.
706
+ status_opt="${STATUS_OPT_TODO:-}"
707
+ [[ -z "$milestone" && -n "${STATUS_OPT_BACKLOG:-}" ]] && status_opt="$STATUS_OPT_BACKLOG"
708
+ [[ -n "$status_opt" ]] && project_set_single_select "$item" "$STATUS_FIELD_ID" "$status_opt" 2>/dev/null || true
618
709
  [[ -n "$plan" && -n "${PLAN_LINK_FIELD_ID:-}" ]] && project_set_text "$item" "$PLAN_LINK_FIELD_ID" "$plan" 2>/dev/null || true
619
710
  fi
620
711
  fi
@@ -676,8 +767,7 @@ kto_task_close() {
676
767
 
677
768
  local repo issue_json state item
678
769
  repo="$(kto_repo)"
679
- if cckit_gh_rest; then issue_json=$(gh_rest_issue_json "$repo" "$num") || return 1
680
- else issue_json=$(gh issue view "$num" --repo "$repo" --json state,projectItems) || return 1; fi
770
+ issue_json=$(gh_rest_issue_json "$repo" "$num") || return 1
681
771
  state=$(printf '%s' "$issue_json" | jq -r .state)
682
772
 
683
773
  if kto_board_enabled && type load_project_ids >/dev/null 2>&1 && load_project_ids 2>/dev/null; then
@@ -687,20 +777,13 @@ kto_task_close() {
687
777
  echo "✓ Board Status → Done for #$num" || true
688
778
  fi
689
779
 
690
- if [[ "$state" == "OPEN" ]] && cckit_gh_rest; then
691
- # REST has no duplicate link (#396): state_reason duplicate, and the comment names the original.
780
+ if [[ "$state" == "OPEN" ]]; then
781
+ # REST has no duplicate link: state_reason duplicate, and the comment names the original.
692
782
  if [[ -n "$dup" ]]; then
693
783
  case "$summary" in *"#$dup"*) : ;; *) summary="$summary"$'\n\n'"Duplicate of #$dup." ;; esac
694
784
  fi
695
785
  gh_rest_issue_close "$repo" "$num" "$gh_reason" "$summary" || return 1
696
786
  echo "✓ Closed issue #$num ($gh_reason${dup:+ of #$dup}${sup:+, superseded by #$sup})"
697
- elif [[ "$state" == "OPEN" ]]; then
698
- if [[ -n "$dup" ]]; then
699
- gh issue close "$num" --repo "$repo" --duplicate-of "$dup" --comment "$summary" || return 1
700
- else
701
- gh issue close "$num" --repo "$repo" --reason "$gh_reason" --comment "$summary" || return 1
702
- fi
703
- echo "✓ Closed issue #$num ($gh_reason${dup:+ of #$dup}${sup:+, superseded by #$sup})"
704
787
  else
705
788
  echo " issue #$num already $state — board status updated only"
706
789
  fi