@jeiemgi/cckit 0.8.0 → 0.10.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 (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,330 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # gh-rest-test.sh — the lifecycle verbs work without GraphQL (#396). In rest mode, cckit pr, merge,
4
+ # close, new, effort new, effort pr and effort close send only `gh api repos/…` calls — never
5
+ # `gh api graphql`, `gh pr …` or `gh issue …` — and every board step is skipped with one notice.
6
+ # The default transport is unchanged. Hermetic: a stubbed gh that answers like the REST API (it
7
+ # applies --jq with the real jq), a throwaway repo and a bare remote.
8
+ # Run: bash scripts/lib/gh-rest-test.sh
9
+ # errors: strict — a test runner: rc 1 on any failed assertion
10
+ set -u
11
+ LIB="$(cd "$(dirname "$0")" && pwd)"
12
+ # shellcheck source=/dev/null
13
+ . "$LIB/test-env.sh" && test_env_seal
14
+ unset CLAUDE_CODE_REMOTE CCKIT_GH_TRANSPORT
15
+ fail=0
16
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
17
+ tc() { if grep -qE -- "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in $1)"; fail=1; fi; }
18
+ command -v jq >/dev/null 2>&1 || { echo "gh-rest-test: jq required" >&2; exit 1; }
19
+ command -v git >/dev/null 2>&1 || { echo "gh-rest-test: git required" >&2; exit 1; }
20
+
21
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
22
+ export GH_LOG="$tmp/gh.log" GH_N="$tmp/n" GH_CLOSED="" GH_HEAD="fix/9-x" GH_BASE="develop" GH_MERGEABLE="true"
23
+ export GH_TITLE="Fix the thing" GH_LABELS='[{"name":"kind:fix"},{"name":"role:tech-lead"}]'
24
+ export GH_REPO_LABELS='[{"name":"kind:task"},{"name":"priority:p2"},{"name":"role:tech-lead"}]'
25
+ : > "$GH_LOG"
26
+
27
+ # rest_only <log> <label> — every gh call in <log> is `gh api` on a repos/ endpoint; none is graphql,
28
+ # `gh pr …` or `gh issue …`. (The stub logs one call per line: newlines in a body become \036.)
29
+ rest_only() {
30
+ local bad
31
+ bad="$(grep -vE '^api (-[^ ]+ [^ ]+ )*repos/' "$1" | sed -n 1,3p)"
32
+ if [ -n "$bad" ]; then echo "FAIL: $2 — non-REST gh calls: $bad"; fail=1; else echo "ok: $2"; fi
33
+ if grep -q graphql "$1"; then echo "FAIL: $2 — a graphql call was made"; fail=1; fi
34
+ }
35
+
36
+ mkdir -p "$tmp/bin"
37
+ cat > "$tmp/bin/gh" <<'SH'
38
+ #!/usr/bin/env bash
39
+ # A REST-shaped gh: logs every call; `gh api <endpoint>` answers a fixture, through --jq when given.
40
+ { printf '%s' "$*" | tr '\n' '\036'; echo; } >> "$GH_LOG"
41
+ if [ "$1" != api ]; then # the default (graphql) transport's subcommands
42
+ case "$1 $2" in
43
+ "issue view") printf '{"state":"OPEN","title":"%s","labels":%s,"milestone":{"title":"M1"},"body":"","projectItems":[]}\n' "$GH_TITLE" "$GH_LABELS" ;;
44
+ "issue create") echo "https://github.com/o/r/issues/50" ;;
45
+ "pr create") echo "https://github.com/o/r/pull/7" ;;
46
+ "pr view") printf '{"mergeable":"MERGEABLE","mergeStateStatus":"CLEAN","baseRefName":"%s","headRefName":"%s"}\n' "$GH_BASE" "$GH_HEAD" ;;
47
+ esac
48
+ exit 0
49
+ fi
50
+ shift; ep="$1"; shift
51
+ method=""; jqx=""; fields=""; accept=""
52
+ while [ $# -gt 0 ]; do
53
+ case "$1" in
54
+ -X|--method) method="$2"; shift 2 ;;
55
+ --jq|-q) jqx="$2"; shift 2 ;;
56
+ -f|-F|--raw-field|--field) fields=1; shift 2 ;;
57
+ -H|--header) accept="$2"; shift 2 ;;
58
+ *) shift ;;
59
+ esac
60
+ done
61
+ [ -n "$method" ] || { [ -n "$fields" ] && method=POST || method=GET; }
62
+ # GH_FAIL_EP=<glob>: that endpoint fails the way real gh does — the error JSON on stdout (--jq is
63
+ # not applied), a message on stderr, rc 1.
64
+ case "$ep" in ${GH_FAIL_EP:-//never//})
65
+ printf '{"message":"Not Found","documentation_url":"https://docs.github.com/rest","status":"404"}'
66
+ echo "gh: Not Found (HTTP 404)" >&2; exit 1 ;;
67
+ esac
68
+ next() { n=$(( $(cat "$GH_N" 2>/dev/null || echo 49) + 1 )); echo "$n" > "$GH_N"; echo "$n"; }
69
+ state_of() { case " $GH_CLOSED " in *" $1 "*) echo closed ;; *) echo open ;; esac; }
70
+ json='{}'
71
+ case "$method $ep" in
72
+ "GET repos/o/r/labels") json="$GH_REPO_LABELS" ;;
73
+ "GET repos/o/r/milestones") json='[{"number":2,"title":"M0"},{"number":3,"title":"M1"}]' ;;
74
+ "POST repos/o/r/issues") n="$(next)"; json="{\"number\":$n,\"html_url\":\"https://github.com/o/r/issues/$n\",\"user\":{\"login\":\"me\"}}" ;;
75
+ "GET repos/o/r/issues") json='[{"number":99,"title":"[Effort] 99 · demo effort"},{"number":5,"title":"PR","pull_request":{}}]' ;;
76
+ "GET repos/o/r/issues/"*/sub_issues) json='[{"number":101,"state":"closed"},{"number":102,"state":"closed"}]' ;;
77
+ "GET repos/o/r/issues/"*/timeline)
78
+ sub="${ep#repos/o/r/issues/}"; sub="${sub%/timeline}"
79
+ json="[{\"event\":\"cross-referenced\",\"source\":{\"issue\":{\"number\":6$sub,\"body\":\"mentions #$sub\",\"repository_url\":\"https://api.github.com/repos/o/r\",\"pull_request\":{\"merged_at\":\"2026-01-01\"}}}},
80
+ {\"event\":\"cross-referenced\",\"source\":{\"issue\":{\"number\":5$sub,\"body\":\"Closes #$sub\",\"repository_url\":\"https://api.github.com/repos/o/r\",\"pull_request\":{\"merged_at\":\"2026-01-01\"}}}}]" ;;
81
+ "GET repos/o/r/issues/"*)
82
+ n="${ep##*/}"
83
+ json="{\"number\":$n,\"title\":\"$GH_TITLE\",\"state\":\"$(state_of "$n")\",\"body\":\"## Goal\\nship it\",\"labels\":$GH_LABELS,\"milestone\":{\"number\":3,\"title\":\"M1\"},\"user\":{\"login\":\"me\"}}" ;;
84
+ "POST repos/o/r/pulls") json='{"number":7,"html_url":"https://github.com/o/r/pull/7","user":{"login":"me"}}' ;;
85
+ "GET repos/o/r/pulls") json="[{\"number\":9,\"head\":{\"ref\":\"$GH_HEAD\"},\"state\":\"open\",\"merged_at\":null}]" ;;
86
+ "GET repos/o/r/pulls/"*)
87
+ n="${ep##*/}"
88
+ case "$accept" in *diff*) printf 'diff --git a/src/app.ts b/src/app.ts\n+app\n'; exit 0 ;; esac
89
+ json="{\"number\":$n,\"title\":\"feat: sub $n\",\"mergeable\":$GH_MERGEABLE,\"mergeable_state\":\"clean\",\"base\":{\"ref\":\"$GH_BASE\"},\"head\":{\"ref\":\"$GH_HEAD\"},\"body\":\"Closes #42\\nFixes #43\\nsee #44\",\"state\":\"open\",\"merged_at\":null,\"merge_commit_sha\":\"abc1234def\"}" ;;
90
+ "PUT repos/o/r/pulls/"*/merge) json='{"merged":true}' ;;
91
+ esac
92
+ if [ -n "$jqx" ]; then printf '%s' "$json" | jq -r -c "$jqx"; else printf '%s\n' "$json"; fi
93
+ SH
94
+ chmod +x "$tmp/bin/gh"
95
+ export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" EFFORT_REPO="o/r" KIT_BASE_BRANCH="develop" KIT_WT_INSTALL=0
96
+ unset KIT_CONFIG
97
+
98
+ # shellcheck source=/dev/null
99
+ . "$LIB/gh-rest.sh"
100
+
101
+ # ── the chooser ───────────────────────────────────────────────────────────────────────────────────
102
+ t "default transport is graphql" "$(cckit_gh_transport)" "graphql"
103
+ t "a cloud session defaults to rest" "$(CLAUDE_CODE_REMOTE=true cckit_gh_transport)" "rest"
104
+ t "CCKIT_GH_TRANSPORT=graphql wins in the cloud" "$(CLAUDE_CODE_REMOTE=true CCKIT_GH_TRANSPORT=graphql cckit_gh_transport)" "graphql"
105
+ t "CCKIT_GH_TRANSPORT=rest forces rest locally" "$(CCKIT_GH_TRANSPORT=rest cckit_gh_transport)" "rest"
106
+ t "an unknown value falls to the default" "$(CCKIT_GH_TRANSPORT=soap cckit_gh_transport 2>/dev/null)" "graphql"
107
+ tc <(CCKIT_GH_TRANSPORT=soap cckit_gh_transport 2>&1 >/dev/null) "must be rest or graphql" "an unknown value warns"
108
+
109
+ # ── pure helpers ──────────────────────────────────────────────────────────────────────────────────
110
+ t "closing refs are read from a PR body" \
111
+ "$(printf 'Closes #42\nfixes #43 and resolves #7\nsee #44\nCloses #42\n' | gh_rest_closing_refs | tr '\n' ' ')" "7 42 43 "
112
+
113
+ # The PR read carries what `cckit hotfix <pr>` needs (#360): the title, and a merge commit only once
114
+ # MERGED — the fixture PR is open, and its merge_commit_sha is GitHub's test merge, not a real one.
115
+ t "pr json carries the title" "$(gh_rest_pr_json o/r 9 | jq -r .title)" "feat: sub 9"
116
+ t "an open PR has no merge commit" "$(gh_rest_pr_json o/r 9 | jq -r '.mergeCommit.oid // "none"')" "none"
117
+
118
+ # ── board steps in rest mode ──────────────────────────────────────────────────────────────────────
119
+ : > "$GH_LOG"
120
+ out="$(CCKIT_GH_TRANSPORT=rest bash -c '
121
+ . "$1/gh-project.sh"
122
+ load_project_ids; echo "rc=$?"
123
+ project_add_item NODE; echo "rc=$?"
124
+ project_set_single_select I F O; echo "rc=$?"
125
+ project_set_text I F T; echo "rc=$?"
126
+ project_find_item_by_issue 5; echo "rc=$?"
127
+ project_issue_status 5; echo "rc=$?"' _ "$LIB" 2>"$tmp/board.err")"
128
+ t "every board function returns 0 in rest mode" "$(printf '%s' "$out" | grep -c '^rc=0$')" "6"
129
+ t "the board functions print nothing on stdout" "$(printf '%s' "$out" | grep -vc '^rc=')" "0"
130
+ t "the notice is printed once" "$(grep -c 'board step skipped' "$tmp/board.err")" "1"
131
+ tc "$tmp/board.err" "^cckit: board step skipped \(GraphQL unavailable; the project's built-in workflows move the card\)$" "the notice wording"
132
+ t "no gh call is made for the board" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
133
+
134
+ # ── the task verbs ────────────────────────────────────────────────────────────────────────────────
135
+ git init -q --bare "$tmp/remote.git"
136
+ git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
137
+ cd "$tmp/work" || exit 1
138
+ git config user.email t@t; git config user.name t
139
+ git checkout -q -b develop; git commit -q --allow-empty -m init; git push -q origin develop
140
+ # shellcheck source=/dev/null
141
+ . "$LIB/gh-project.sh"
142
+ # shellcheck source=/dev/null
143
+ . "$LIB/kit-task-ops.sh"
144
+ export KIT_PROJECTS_V2=true CCKIT_GH_TRANSPORT=rest
145
+
146
+ # cckit pr
147
+ git checkout -q -b fix/42-the-thing
148
+ echo x > a.txt; git add a.txt; git commit -q -m wip
149
+ : > "$GH_LOG"
150
+ unset _CCKIT_BOARD_NOTICE_DONE; kto_task_pr 42 "Did the thing." >"$tmp/out" 2>"$tmp/err"; rc=$?
151
+ t "pr: rc 0 over REST" "$rc" "0"
152
+ rest_only "$GH_LOG" "pr: only REST calls"
153
+ tc "$GH_LOG" '^api repos/o/r/issues/42 ' "pr: reads the issue over REST"
154
+ tc "$GH_LOG" '^api repos/o/r/pulls -X POST .*-f title=fix: Fix the thing -f head=fix/42-the-thing -f base=develop' "pr: opens the PR with POST pulls"
155
+ tc "$GH_LOG" '^api repos/o/r/issues/7 -X PATCH -f labels\[\]=kind:fix -f labels\[\]=role:tech-lead -f assignees\[\]=me -F milestone=3' "pr: labels, assignee and milestone in one PATCH"
156
+ tc "$tmp/out" 'https://github.com/o/r/pull/7' "pr: prints the PR url"
157
+ t "pr: the board notice is printed once" "$(grep -c 'board step skipped' "$tmp/err")" "1"
158
+
159
+ : > "$GH_LOG"
160
+ kto_task_pr 42 "Did the thing." --base main >/dev/null 2>&1; rc=$?
161
+ t "pr --base: rc 0 over REST" "$rc" "0"
162
+ tc "$GH_LOG" '^api repos/o/r/pulls -X POST .*-f head=fix/42-the-thing -f base=main' "pr --base: the explicit base is sent in POST pulls"
163
+
164
+ # cckit new
165
+ : > "$GH_LOG"
166
+ unset _CCKIT_BOARD_NOTICE_DONE; num="$(kto_task_new "Add a thing" tech-lead task p2 M1 "" "" "Body." 2>"$tmp/err" | tail -1)"; rc=$?
167
+ t "new: rc 0 over REST" "$rc" "0"
168
+ rest_only "$GH_LOG" "new: only REST calls"
169
+ tc "$GH_LOG" '^api repos/o/r/issues -X POST -f title=Add a thing .*-f labels\[\]=kind:task -f labels\[\]=priority:p2 -f labels\[\]=role:tech-lead -F milestone=3' "new: POST issues with labels and the milestone number"
170
+ tc "$GH_LOG" "^api repos/o/r/issues/$num/assignees -X POST -f assignees\[\]=me" "new: assigns the issue to its author"
171
+ t "new: echoes the new number" "$num" "50"
172
+ t "new: no 'NOT added to the board' warning" "$(grep -c 'NOT added' "$tmp/err")" "0"
173
+ t "new: the board notice is printed once" "$(grep -c 'board step skipped' "$tmp/err")" "1"
174
+
175
+ # cckit new, a label the repo does not have (#387): a warning, the issue is still created, and the
176
+ # label is not sent — POST issues would create it.
177
+ : > "$GH_LOG"
178
+ unset _CCKIT_BOARD_NOTICE_DONE; kto_task_new "Add a thing" tech-lead feat p2 "" "" "" "Body." >"$tmp/out" 2>"$tmp/err"; rc=$?
179
+ t "new, missing label: rc 0 over REST" "$rc" "0"
180
+ rest_only "$GH_LOG" "new, missing label: only REST calls"
181
+ tc "$GH_LOG" '^api repos/o/r/labels -X GET ' "new, missing label: reads the repo's labels over REST"
182
+ tc "$GH_LOG" '^api repos/o/r/issues -X POST -f title=Add a thing .*-f labels\[\]=priority:p2 -f labels\[\]=role:tech-lead --jq' "new, missing label: POST issues with the existing labels only"
183
+ t "new, missing label: kind:feat is not sent" "$(grep -c 'kind:feat' "$GH_LOG")" "0"
184
+ tc "$tmp/out" '^✓ https://github.com/o/r/issues/[0-9]+$' "new, missing label: prints the issue url"
185
+ tc "$tmp/err" "label 'kind:feat' not found" "new, missing label: the warning names kind:feat"
186
+ # The label list cannot be read: every label is sent, as before.
187
+ : > "$GH_LOG"
188
+ GH_FAIL_EP="repos/o/r/labels" kto_task_new "Add a thing" tech-lead feat p2 "" "" "" "Body." >"$tmp/out" 2>"$tmp/err"; rc=$?
189
+ t "new, unreadable label list: rc 0" "$rc" "0"
190
+ tc "$GH_LOG" '^api repos/o/r/issues -X POST .*-f labels\[\]=kind:feat -f labels\[\]=priority:p2 -f labels\[\]=role:tech-lead' "new, unreadable label list: every label is sent"
191
+
192
+ # cckit close
193
+ : > "$GH_LOG"
194
+ unset _CCKIT_BOARD_NOTICE_DONE; kto_task_close 5 "Shipped." >/dev/null 2>"$tmp/err"; rc=$?
195
+ t "close: rc 0 over REST" "$rc" "0"
196
+ rest_only "$GH_LOG" "close: only REST calls"
197
+ tc "$GH_LOG" '^api repos/o/r/issues/5/comments -X POST -f body=Shipped\.$' "close: posts the summary"
198
+ tc "$GH_LOG" '^api repos/o/r/issues/5 -X PATCH -f state=closed -f state_reason=completed$' "close: state_reason completed"
199
+ : > "$GH_LOG"
200
+ kto_task_close 6 "Not worth it." --reason not-planned >/dev/null 2>&1
201
+ tc "$GH_LOG" '^api repos/o/r/issues/6 -X PATCH -f state=closed -f state_reason=not_planned$' "close: not-planned maps to not_planned"
202
+ : > "$GH_LOG"
203
+ kto_task_close 7 "Same work." --duplicate-of 4 >/dev/null 2>&1
204
+ tc "$GH_LOG" '^api repos/o/r/issues/7 -X PATCH -f state=closed -f state_reason=duplicate$' "close: duplicate maps to state_reason duplicate"
205
+ tc "$GH_LOG" 'issues/7/comments -X POST -f body=Same work\..*Duplicate of #4\.$' "close: the comment links the original"
206
+ : > "$GH_LOG"; GH_CLOSED="8"
207
+ kto_task_close 8 "x" >/dev/null 2>&1; rc=$?
208
+ t "close: an already-closed issue is fine" "$rc" "0"
209
+ t "close: it is not closed again" "$(grep -c 'PATCH' "$GH_LOG")" "0"
210
+ GH_CLOSED=""
211
+
212
+ # cckit merge — from the PR's worktree, as in the default-mode suite
213
+ git checkout -q develop
214
+ wt="$tmp/work/.claude/worktrees/fix+9-x"
215
+ git worktree add -q -b fix/9-x "$wt" develop
216
+ git -C "$wt" commit -q --allow-empty -m "the fix"
217
+ git -C "$wt" push -q origin fix/9-x
218
+ : > "$GH_LOG"; GH_CLOSED="43"
219
+ unset _CCKIT_BOARD_NOTICE_DONE; ( cd "$wt" && kto_task_pr_merge ) >"$tmp/out" 2>"$tmp/err"; rc=$?
220
+ t "merge: rc 0 over REST" "$rc" "0"
221
+ rest_only "$GH_LOG" "merge: only REST calls"
222
+ tc "$GH_LOG" '^api repos/o/r/pulls -X GET -f head=o:fix/9-x -f state=open' "merge: finds the open PR for the branch"
223
+ tc "$GH_LOG" '^api repos/o/r/pulls/9/merge -X PUT -f merge_method=squash$' "merge: squash-merges with PUT pulls/9/merge"
224
+ tc "$GH_LOG" '^api repos/o/r/issues/42 -X PATCH -f state=closed -f state_reason=completed$' "merge: closes the linked open issue"
225
+ t "merge: an already-closed linked issue is left" "$(grep -c 'issues/43 -X PATCH' "$GH_LOG")" "0"
226
+ t "merge: a bare mention is not a closing ref" "$(grep -c 'issues/44' "$GH_LOG")" "0"
227
+ t "merge: the worktree is removed" "$([ -d "$wt" ] && echo present || echo gone)" "gone"
228
+ t "merge: the local branch is deleted" "$(git branch --list fix/9-x | wc -l | tr -d ' ')" "0"
229
+ t "merge: the remote branch is kept" "$(git ls-remote --heads origin fix/9-x | wc -l | tr -d ' ')" "1"
230
+ tc "$tmp/out" 'remote branch fix/9-x kept' "merge: says why the remote branch stays"
231
+ : > "$GH_LOG"; GH_HEAD="fix/10-x"
232
+ kto_task_pr_merge 10 --rebase >/dev/null 2>&1
233
+ tc "$GH_LOG" '^api repos/o/r/pulls/10/merge -X PUT -f merge_method=rebase$' "merge: --rebase reaches merge_method"
234
+ : > "$GH_LOG"; GH_MERGEABLE="false"; GH_HEAD="fix/11-x"
235
+ kto_task_pr_merge 11 >/dev/null 2>&1; rc=$?
236
+ t "merge: a conflicting PR from the base is refused" "$rc" "1"
237
+ t "merge: nothing merged on a conflict" "$(grep -c '/merge' "$GH_LOG")" "0"
238
+ GH_MERGEABLE="true"; GH_CLOSED=""; GH_HEAD="fix/9-x"
239
+
240
+ # ── the default transport is unchanged ────────────────────────────────────────────────────────────
241
+ : > "$GH_LOG"
242
+ CLAUDE_CODE_REMOTE=true CCKIT_GH_TRANSPORT=graphql KIT_PROJECTS_V2=false kto_task_close 12 "Done." >/dev/null 2>&1
243
+ tc "$GH_LOG" '^issue close 12 --repo o/r --reason completed --comment Done\.$' "graphql: close still uses gh issue close"
244
+ t "graphql: no REST close" "$(grep -c '^api ' "$GH_LOG")" "0"
245
+
246
+ # ── the effort verbs ──────────────────────────────────────────────────────────────────────────────
247
+ # shellcheck source=/dev/null
248
+ . "$LIB/effort.sh" 2>/dev/null
249
+ # shellcheck source=/dev/null
250
+ . "$LIB/effort-ops.sh"
251
+ GH_TITLE="[Effort] 99 · demo effort"; GH_LABELS='[{"name":"role:tech-lead"},{"name":"kind:task"}]'
252
+ export KIT_BASE_BRANCH="main"
253
+
254
+ # cckit effort new
255
+ : > "$GH_LOG"
256
+ unset _CCKIT_BOARD_NOTICE_DONE; parent="$(effort_new --flow Core "demo effort" "first sub" "second sub" 2>"$tmp/err")"; rc=$?
257
+ t "effort new: rc 0 over REST" "$rc" "0"
258
+ rest_only "$GH_LOG" "effort new: only REST calls"
259
+ tc "$GH_LOG" '^api repos/o/r/labels -X POST -f name=effort ' "effort new: ensures labels over REST"
260
+ tc "$GH_LOG" "^api repos/o/r/issues -X POST -f title=\[Effort\] · \[Core\] demo effort .*-f labels\[\]=effort" "effort new: POST issues for the parent"
261
+ tc "$GH_LOG" "^api repos/o/r/issues/$parent -X PATCH -f title=\[Effort\] $parent · \[Core\] demo effort$" "effort new: renames the parent with its number"
262
+ tc "$GH_LOG" "^api repos/o/r/issues/$parent/labels -X POST -f labels\[\]=slug:demo-effort$" "effort new: adds the slug label"
263
+ t "effort new: parent + 2 subs created" "$(grep -c '^api repos/o/r/issues -X POST' "$GH_LOG")" "3"
264
+ t "effort new: 2 sub-issues linked" "$(grep -c 'sub_issues' "$GH_LOG")" "2"
265
+
266
+ # cckit effort pr + effort close
267
+ git checkout -q -b main; git push -q origin main
268
+ cd "$tmp/work" || exit 1
269
+ effort_start 99 demo >/dev/null 2>&1
270
+ ewt="$tmp/work/.claude/worktrees/effort+99-demo"
271
+ cd "$ewt" || exit 1
272
+ echo work > file.txt; git add file.txt; git commit -q -m "feat: do the thing (#101)"
273
+ : > "$GH_LOG"
274
+ unset _CCKIT_BOARD_NOTICE_DONE; effort_pr 99 --summary "SUMMARY" >"$tmp/out" 2>"$tmp/err"; rc=$?
275
+ t "effort pr: rc 0 over REST" "$rc" "0"
276
+ rest_only "$GH_LOG" "effort pr: only REST calls"
277
+ tc "$GH_LOG" '^api repos/o/r/pulls -X POST -f title=feat: demo effort \[#99\] .*-f head=effort/99-demo -f base=main' "effort pr: POST pulls effort/99 → main"
278
+ tc "$GH_LOG" '^api repos/o/r/issues/7 -X PATCH -f labels\[\]=role:tech-lead -f labels\[\]=kind:task .*-F milestone=3' "effort pr: inherits labels + milestone"
279
+ t "effort pr: the board notice is printed once" "$(grep -c 'board step skipped' "$tmp/err")" "1"
280
+
281
+ : > "$GH_LOG"; GH_HEAD="effort/99-demo"; GH_BASE="main"
282
+ unset _CCKIT_BOARD_NOTICE_DONE; close_out="$(effort_close 99 2>&1)"; rc=$?
283
+ cd "$tmp/work" || exit 1
284
+ t "effort close: rc 0 over REST" "$rc" "0"
285
+ rest_only "$GH_LOG" "effort close: only REST calls"
286
+ tc "$GH_LOG" '^api repos/o/r/pulls/9/merge -X PUT -f merge_method=squash$' "effort close: squash-merges over REST"
287
+ tc "$GH_LOG" '^api repos/o/r/issues/101 -X PATCH -f state=closed -f state_reason=completed$' "effort close: closes sub #101"
288
+ tc "$GH_LOG" '^api repos/o/r/issues/99 -X PATCH -f state=closed -f state_reason=completed$' "effort close: closes the parent"
289
+ case "$close_out" in *"remote branch effort/99-demo kept"*) echo "ok: effort close: says why the remote branch stays" ;; *) echo "FAIL: effort close: no remote-branch notice: $close_out"; fail=1 ;; esac
290
+ t "effort close: the board notice is printed once" "$(printf '%s\n' "$close_out" | grep -c 'board step skipped')" "1"
291
+ t "effort close: the local branch is deleted" "$(git branch --list effort/99-demo | wc -l | tr -d ' ')" "0"
292
+
293
+ # wave-style close: no effort branch, the subs shipped as their own merged PRs
294
+ : > "$GH_LOG"
295
+ unset _CCKIT_BOARD_NOTICE_DONE; close_out="$(effort_close 77 2>&1)"; rc=$?
296
+ t "wave close: rc 0 over REST" "$rc" "0"
297
+ rest_only "$GH_LOG" "wave close: only REST calls"
298
+ tc "$GH_LOG" '^api repos/o/r/issues/101/timeline ' "wave close: finds the closing PR in the sub's timeline"
299
+ tc "$GH_LOG" '^api repos/o/r/pulls/5101 -H Accept: application/vnd.github.v3.diff$' "wave close: snapshots the closing PR's diff (not the mention)"
300
+ tc "$GH_LOG" '^api repos/o/r/issues/77 -X PATCH -f state=closed -f state_reason=completed$' "wave close: closes the parent"
301
+ t "wave close: rows match the graphql shape" \
302
+ "$(gh_rest_wave_rows o/r 77 | sed -n 1p)" "101|CLOSED|5101|abc1234def|feat: sub 5101"
303
+
304
+ # ── a failed REST read is no data, never the error body ───────────────────────────────────────────
305
+ export GH_FAIL_EP="repos/o/r/issues/404"
306
+ t "failed read: issue state is empty" "$(gh_rest_issue_state o/r 404 2>/dev/null)" ""
307
+ gh_rest_issue_state o/r 404 >/dev/null 2>&1; rc=$?
308
+ t "failed read: issue state returns non-zero" "$rc" "1"
309
+ t "failed read: issue json is empty" "$(gh_rest_issue_json o/r 404 2>/dev/null)" ""
310
+ export GH_FAIL_EP="repos/o/r/issues/404/timeline"
311
+ t "failed read: closing PRs are empty" "$(gh_rest_issue_closing_prs o/r 404 2>/dev/null)" ""
312
+ export GH_FAIL_EP="repos/o/r/pulls"
313
+ t "failed read: no PR for the head" "$(gh_rest_pr_for_head o/r fix/1-x 2>/dev/null)" ""
314
+ export GH_FAIL_EP="repos/o/r/issues/*/sub_issues"
315
+ t "failed read: no sub-issue numbers" "$(gh_rest_sub_issue_numbers o/r 1 2>/dev/null)" ""
316
+ export GH_FAIL_EP="repos/o/r/issues/102/timeline"
317
+ t "failed read: a sub whose timeline fails has no PR" \
318
+ "$(gh_rest_wave_rows o/r 77 2>/dev/null | sed -n 2p)" "102|CLOSED|||"
319
+ : > "$GH_LOG"
320
+ effort_close 77 >/dev/null 2>&1; rc=$?
321
+ t "failed read: wave close refuses" "$rc" "1"
322
+ t "failed read: wave close leaves the parent open" "$(grep -c 'issues/77 -X PATCH' "$GH_LOG")" "0"
323
+ export GH_FAIL_EP="repos/o/r/issues/88"
324
+ effort_start 88 >/dev/null 2>&1
325
+ t "failed read: effort start falls back to the effort slug" \
326
+ "$(git branch --list 'effort/88-*' | tr -d ' *+')" "effort/88-effort"
327
+ unset GH_FAIL_EP
328
+
329
+ [ "$fail" -eq 0 ] && echo "gh-rest: all passed" || echo "gh-rest: FAILURES"
330
+ exit "$fail"
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # gh-rest.sh — the GitHub transport switch and the REST forms of the lifecycle calls (#396).
4
+ #
5
+ # Cloud agent sessions reach GitHub through a proxy that refuses every GraphQL request (403), and
6
+ # `gh pr …` / `gh issue …` are GraphQL underneath. REST calls to the attached repo still work. So the
7
+ # lifecycle verbs (pr, merge, close, new, effort new|pr|close) pick a transport here:
8
+ #
9
+ # CCKIT_GH_TRANSPORT=rest|graphql forces it
10
+ # CLAUDE_CODE_REMOTE=true defaults it to rest (a cloud session)
11
+ # otherwise graphql — the gh subcommands, unchanged
12
+ #
13
+ # In rest mode every call is `gh api repos/<owner>/<repo>/…`, endpoint first. Projects v2 is
14
+ # GraphQL-only, so board steps are skipped with ONE notice line (exit 0, never a failure).
15
+ #
16
+ # cckit_gh_rest rc 0 iff the transport is rest
17
+ # cckit_gh_transport echo rest|graphql
18
+ # cckit_board_skipped rc 0 iff board steps are skipped (prints the notice once)
19
+ # gh_rest_closing_refs stdin: a PR body → the issue #s it closes (pure)
20
+ # gh_rest_issue_json <repo> <n> {number,title,body,state,labels[{name}],milestone{title,number}}
21
+ # gh_rest_issue_state <repo> <n> OPEN | CLOSED
22
+ # gh_rest_issue_create <repo> <title> <body> <labels-csv> [milestone-title] [assign 1|0] → html_url
23
+ # gh_rest_issue_close <repo> <n> <completed|not_planned|duplicate> [comment]
24
+ # gh_rest_issue_edit_title <repo> <n> <title>
25
+ # gh_rest_issue_set_body <repo> <n> <body>
26
+ # gh_rest_issue_add_labels <repo> <n> <labels-csv>
27
+ # gh_rest_label_create <repo> <name> <color> <description> (idempotent)
28
+ # gh_rest_milestone_number <repo> <title>
29
+ # gh_rest_pr_create <repo> <base> <head> <title> <body> <labels-csv> [milestone-title] → html_url
30
+ # gh_rest_pr_for_head <repo> <branch> the open PR number for a head branch
31
+ # gh_rest_pr_json <repo> <pr> {mergeable,mergeStateStatus,baseRefName,headRefName,body,title,mergeCommit,state}
32
+ # gh_rest_pr_commit_subjects <repo> <pr> one subject line per PR commit, oldest first
33
+ # gh_rest_pr_merge <repo> <pr> <squash|merge|rebase>
34
+ # gh_rest_pr_closing_issues <repo> <pr>
35
+ # gh_rest_pr_diff <repo> <pr>
36
+ # gh_rest_sub_issue_numbers <repo> <n>
37
+ # gh_rest_issue_numbers_by_label <repo> <label> open issues only
38
+ # gh_rest_open_issue_titles <repo> "<n>\t<title>" for every open issue
39
+ # gh_rest_issue_closing_prs <repo> <n> merged PRs that close <n> by keyword (timeline)
40
+ # gh_rest_wave_rows <repo> <parent> "sub|STATE|pr|merge-sha|pr-title" per sub (wave close)
41
+ #
42
+ # Not reachable over REST in the cloud: Projects v2 (skipped), and remote branch deletion (the proxy
43
+ # rejects DELETE git/refs) — callers keep the branch and say so.
44
+ # bash 3.2 + zsh compatible. Requires gh, jq.
45
+ # errors: mixed — creates, closes and merges propagate; labels/milestone/assignee are best-effort
46
+
47
+ CCKIT_BOARD_SKIP_NOTICE="cckit: board step skipped (GraphQL unavailable; the project's built-in workflows move the card)"
48
+
49
+ # rc 0 iff the transport is rest. An unknown CCKIT_GH_TRANSPORT warns once and falls to the default.
50
+ cckit_gh_rest() {
51
+ case "${CCKIT_GH_TRANSPORT:-}" in
52
+ rest) return 0 ;;
53
+ graphql) return 1 ;;
54
+ '') : ;;
55
+ *)
56
+ if [ -z "${_CCKIT_TRANSPORT_WARNED:-}" ]; then
57
+ printf "cckit: CCKIT_GH_TRANSPORT must be rest or graphql (got '%s') — using the default\n" \
58
+ "$CCKIT_GH_TRANSPORT" >&2
59
+ _CCKIT_TRANSPORT_WARNED=1
60
+ fi ;;
61
+ esac
62
+ [ "${CLAUDE_CODE_REMOTE:-}" = "true" ]
63
+ }
64
+
65
+ cckit_gh_transport() {
66
+ if cckit_gh_rest; then printf 'rest'; else printf 'graphql'; fi
67
+ }
68
+
69
+ # rc 0 when board steps are skipped (rest mode). Prints the notice at most once per process.
70
+ cckit_board_skipped() {
71
+ cckit_gh_rest || return 1
72
+ if [ -z "${_CCKIT_BOARD_NOTICE_DONE:-}" ]; then
73
+ printf '%s\n' "$CCKIT_BOARD_SKIP_NOTICE" >&2
74
+ _CCKIT_BOARD_NOTICE_DONE=1
75
+ fi
76
+ return 0
77
+ }
78
+
79
+ # --- pure ----------------------------------------------------------------------------------------
80
+
81
+ # A PR body on stdin → the issue numbers it closes, one per line, sorted. REST has no
82
+ # closingIssuesReferences, so the keywords are read from the body (the same regex the graphql path
83
+ # falls back to).
84
+ gh_rest_closing_refs() {
85
+ grep -ioE '(close[sd]?|fix(e[sd])?|resolve[sd]?) +#[0-9]+' | grep -oE '[0-9]+' | sort -un
86
+ }
87
+
88
+ # Split a comma list into `-f <key>[]=<item>` args on stdout, one arg per line (callers read them
89
+ # back with a while loop: no word splitting, so a label with a space survives).
90
+ _ghr_array_args() {
91
+ local key="$1" item
92
+ printf '%s\n' "$2" | tr ',' '\n' | while IFS= read -r item; do
93
+ item="$(printf '%s' "$item" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
94
+ [ -n "$item" ] && printf -- '-f\n%s[]=%s\n' "$key" "$item"
95
+ done
96
+ }
97
+
98
+ # `gh api …` for a read. On failure gh prints the error JSON to stdout and skips --jq, so the output
99
+ # is kept only on rc 0: a failed read is no data (rc 1), never an error body taken as a value.
100
+ _ghr_read() {
101
+ local out
102
+ out="$(gh api "$@")" || return 1
103
+ [ -n "$out" ] && printf '%s\n' "$out"
104
+ return 0
105
+ }
106
+
107
+ # --- issues --------------------------------------------------------------------------------------
108
+
109
+ gh_rest_issue_json() {
110
+ _ghr_read "repos/$1/issues/$2" --jq '{number, title, body: (.body // ""), state: (.state | ascii_upcase),
111
+ labels: [.labels[]? | {name}],
112
+ milestone: (if .milestone then {title: .milestone.title, number: .milestone.number} else null end)}'
113
+ }
114
+
115
+ gh_rest_issue_state() {
116
+ _ghr_read "repos/$1/issues/$2" --jq '.state | ascii_upcase'
117
+ }
118
+
119
+ gh_rest_milestone_number() {
120
+ local tab n t; tab="$(printf '\t')"
121
+ _ghr_read "repos/$1/milestones" -X GET -f state=all -f per_page=100 \
122
+ --jq '.[] | "\(.number)\t\(.title)"' 2>/dev/null \
123
+ | while IFS="$tab" read -r n t; do [ "$t" = "$2" ] && { printf '%s' "$n"; break; }; done
124
+ }
125
+
126
+ # Create an issue with labels + milestone, then assign it to its author (the REST form of
127
+ # `gh issue create --assignee @me`: the token's own login is the author). <assign> 0 skips that.
128
+ # Echoes the html_url.
129
+ gh_rest_issue_create() {
130
+ local repo="$1" title="$2" body="$3" labels="${4:-}" ms="${5:-}" assign="${6:-1}" msnum="" out num url login a
131
+ local tab; tab="$(printf '\t')"
132
+ set -- -f "title=$title" -f "body=$body"
133
+ while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
134
+ $(_ghr_array_args labels "$labels")
135
+ EOF
136
+ if [ -n "$ms" ]; then
137
+ msnum="$(gh_rest_milestone_number "$repo" "$ms")"
138
+ if [ -n "$msnum" ]; then set -- "$@" -F "milestone=$msnum"
139
+ else echo "cckit: milestone '$ms' not found in $repo — issue created without it" >&2; fi
140
+ fi
141
+ out="$(gh api "repos/$repo/issues" -X POST "$@" \
142
+ --jq '"\(.number)\t\(.html_url)\t\(.user.login // "")"')" || return 1
143
+ IFS="$tab" read -r num url login <<EOF
144
+ $out
145
+ EOF
146
+ [ -n "$num" ] || return 1
147
+ if [ "$assign" = 1 ] && [ -n "$login" ]; then
148
+ gh api "repos/$repo/issues/$num/assignees" -X POST -f "assignees[]=$login" >/dev/null 2>&1 \
149
+ || echo "cckit: #$num created but not assigned to $login" >&2
150
+ fi
151
+ printf '%s\n' "$url"
152
+ }
153
+
154
+ # Close with a GitHub state_reason (completed | not_planned | duplicate); the comment goes first,
155
+ # as `gh issue close --comment` does.
156
+ gh_rest_issue_close() {
157
+ local repo="$1" n="$2" reason="${3:-completed}" comment="${4:-}"
158
+ reason="$(printf '%s' "$reason" | tr ' -' '__')"
159
+ if [ -n "$comment" ]; then
160
+ gh api "repos/$repo/issues/$n/comments" -X POST -f "body=$comment" >/dev/null || return 1
161
+ fi
162
+ gh api "repos/$repo/issues/$n" -X PATCH -f state=closed -f "state_reason=$reason" >/dev/null
163
+ }
164
+
165
+ gh_rest_issue_edit_title() {
166
+ gh api "repos/$1/issues/$2" -X PATCH -f "title=$3" >/dev/null
167
+ }
168
+
169
+ gh_rest_issue_set_body() {
170
+ gh api "repos/$1/issues/$2" -X PATCH -f "body=$3" >/dev/null
171
+ }
172
+
173
+ gh_rest_issue_add_labels() {
174
+ local repo="$1" n="$2" labels="${3:-}" a
175
+ set --
176
+ while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
177
+ $(_ghr_array_args labels "$labels")
178
+ EOF
179
+ [ $# -gt 0 ] || return 0
180
+ gh api "repos/$repo/issues/$n/labels" -X POST "$@" >/dev/null
181
+ }
182
+
183
+ # Idempotent: an existing label answers 422, which is fine.
184
+ gh_rest_label_create() {
185
+ gh api "repos/$1/labels" -X POST -f "name=$2" -f "color=$3" -f "description=$4" >/dev/null 2>&1 || true
186
+ }
187
+
188
+ # Every label name in the repo, one per line. rc 1 when the list cannot be read.
189
+ gh_rest_label_names() {
190
+ _ghr_read "repos/$1/labels" -X GET -f per_page=100 --paginate --jq '.[].name'
191
+ }
192
+
193
+ gh_rest_sub_issue_numbers() {
194
+ _ghr_read "repos/$1/issues/$2/sub_issues" -X GET -f per_page=100 --jq '.[].number'
195
+ }
196
+
197
+ gh_rest_issue_numbers_by_label() {
198
+ _ghr_read "repos/$1/issues" -X GET -f state=open -f "labels=$2" -f per_page=100 \
199
+ --jq '.[] | select(.pull_request | not) | .number'
200
+ }
201
+
202
+ gh_rest_open_issue_titles() {
203
+ _ghr_read "repos/$1/issues" -X GET -f state=open -f per_page=100 --paginate \
204
+ --jq '.[] | select(.pull_request | not) | "\(.number)\t\(.title)"'
205
+ }
206
+
207
+ # --- pull requests -------------------------------------------------------------------------------
208
+
209
+ # Open a PR, then set labels, milestone and assignee (its author — `--assignee @me`) in one PATCH.
210
+ # The PR is the failure that matters; the decoration is best-effort and says so. Echoes the html_url.
211
+ gh_rest_pr_create() {
212
+ local repo="$1" base="$2" head="$3" title="$4" body="$5" labels="${6:-}" ms="${7:-}" msnum out num url login a
213
+ local tab; tab="$(printf '\t')"
214
+ out="$(gh api "repos/$repo/pulls" -X POST -f "title=$title" -f "head=$head" -f "base=$base" -f "body=$body" \
215
+ --jq '"\(.number)\t\(.html_url)\t\(.user.login // "")"')" || return 1
216
+ IFS="$tab" read -r num url login <<EOF
217
+ $out
218
+ EOF
219
+ [ -n "$num" ] || return 1
220
+ set --
221
+ while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
222
+ $(_ghr_array_args labels "$labels")
223
+ EOF
224
+ [ -n "$login" ] && set -- "$@" -f "assignees[]=$login"
225
+ if [ -n "$ms" ]; then
226
+ msnum="$(gh_rest_milestone_number "$repo" "$ms")"
227
+ if [ -n "$msnum" ]; then set -- "$@" -F "milestone=$msnum"
228
+ else echo "cckit: milestone '$ms' not found in $repo — PR opened without it" >&2; fi
229
+ fi
230
+ if [ $# -gt 0 ]; then
231
+ gh api "repos/$repo/issues/$num" -X PATCH "$@" >/dev/null 2>&1 \
232
+ || echo "cckit: PR #$num opened, but its labels/milestone/assignee were not set" >&2
233
+ fi
234
+ printf '%s\n' "$url"
235
+ }
236
+
237
+ gh_rest_pr_for_head() {
238
+ _ghr_read "repos/$1/pulls" -X GET -f "head=${1%%/*}:$2" -f state=open --jq '.[0].number // empty'
239
+ }
240
+
241
+ # The fields the merge path reads, in the graphql vocabulary: mergeable MERGEABLE|CONFLICTING|UNKNOWN
242
+ # (REST true|false|null — null while GitHub computes it), mergeStateStatus = REST mergeable_state.
243
+ # mergeCommit is {oid} only once MERGED: REST fills merge_commit_sha on an open PR too, with the
244
+ # test-merge commit, which is not a commit anyone merged (#360).
245
+ gh_rest_pr_json() {
246
+ _ghr_read "repos/$1/pulls/$2" --jq '{
247
+ mergeable: (if .mergeable == true then "MERGEABLE" elif .mergeable == false then "CONFLICTING" else "UNKNOWN" end),
248
+ mergeStateStatus: ((.mergeable_state // "unknown") | ascii_upcase),
249
+ baseRefName: .base.ref, headRefName: .head.ref, body: (.body // ""),
250
+ title: (.title // ""),
251
+ mergeCommit: (if .merged_at then {oid: .merge_commit_sha} else null end),
252
+ state: (if .merged_at then "MERGED" else (.state | ascii_upcase) end)}'
253
+ }
254
+
255
+ gh_rest_pr_commit_subjects() {
256
+ _ghr_read "repos/$1/pulls/$2/commits" -X GET -f per_page=100 --paginate \
257
+ --jq '.[].commit.message | split("\n")[0]'
258
+ }
259
+
260
+ gh_rest_pr_merge() {
261
+ gh api "repos/$1/pulls/$2/merge" -X PUT -f "merge_method=${3:-squash}" >/dev/null
262
+ }
263
+
264
+ gh_rest_pr_closing_issues() {
265
+ _ghr_read "repos/$1/pulls/$2" --jq '.body // ""' 2>/dev/null | gh_rest_closing_refs
266
+ }
267
+
268
+ gh_rest_pr_diff() {
269
+ _ghr_read "repos/$1/pulls/$2" -H 'Accept: application/vnd.github.v3.diff'
270
+ }
271
+
272
+ # The merged PRs that close issue <n> (graphql: closedByPullRequestsReferences, merged only). REST has
273
+ # no such link, so: the PRs in <n>'s timeline that cross-reference it, are merged, live in this repo,
274
+ # and close it by keyword. One number per line, timeline order.
275
+ gh_rest_issue_closing_prs() {
276
+ local repo="$1" n="$2"
277
+ _ghr_read "repos/$repo/issues/$n/timeline" -X GET -f per_page=100 --jq "
278
+ .[] | select(.event == \"cross-referenced\") | .source.issue // empty
279
+ | select(.pull_request.merged_at != null)
280
+ | select((.repository_url // \"\") | endswith(\"/repos/$repo\"))
281
+ | select((.body // \"\") | test(\"(?i)(close[sd]?|fix(e[sd])?|resolve[sd]?) +#$n([^0-9]|\$)\"))
282
+ | .number"
283
+ }
284
+
285
+ # The wave close's per-sub read (graphql: subIssues + closedByPullRequestsReferences): each sub from
286
+ # sub_issues, its first merged closing PR, then that PR's merge commit and title. A failed read leaves
287
+ # the field empty, so the close refuses (fails closed, as the graphql path does).
288
+ gh_rest_wave_rows() {
289
+ local repo="$1" parent="$2" tab sub state pr oid title
290
+ tab="$(printf '\t')"
291
+ _ghr_read "repos/$repo/issues/$parent/sub_issues" -X GET -f per_page=100 \
292
+ --jq '.[] | "\(.number)\t\(.state | ascii_upcase)"' 2>/dev/null \
293
+ | while IFS="$tab" read -r sub state; do
294
+ [ -n "$sub" ] || continue
295
+ oid="" title=""
296
+ pr="$(gh_rest_issue_closing_prs "$repo" "$sub" 2>/dev/null | sed -n 1p)"
297
+ if [ -n "$pr" ]; then
298
+ IFS="$tab" read -r oid title <<EOF
299
+ $(_ghr_read "repos/$repo/pulls/$pr" --jq '"\(.merge_commit_sha // "")\t\(.title // "")"' 2>/dev/null)
300
+ EOF
301
+ fi
302
+ printf '%s|%s|%s|%s|%s\n' "$sub" "$state" "$pr" "$oid" "$title"
303
+ done
304
+ }