@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
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # gh-board-add-test.sh — the board add when the item is already on the board (#590). A Projects v2
4
+ # board with GitHub's auto-add workflow puts every new issue and PR on the board within seconds of
5
+ # its creation, so the kit's REST add answers 422 "Content already exists in this project" — where
6
+ # GraphQL's addProjectV2ItemById returned the existing item. The add must read that card back, fall
7
+ # back to GraphQL when it cannot, and `cckit new` must then go on to set the card's fields.
8
+ # Hermetic: the shared forge shim (test-forge-shim.sh) over a curl stand-in; a throwaway repo.
9
+ # Run: bash scripts/lib/gh-board-add-test.sh
10
+ # errors: strict — a test runner: rc 1 on any failed assertion
11
+ set -u
12
+ LIB="$(cd "$(dirname "$0")" && pwd)"
13
+ # shellcheck source=/dev/null
14
+ . "$LIB/test-env.sh" && test_env_seal
15
+ unset CLAUDE_CODE_REMOTE CCKIT_GH_TRANSPORT CCKIT_GRAPHQL
16
+ fail=0
17
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
18
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '$2' lacks '$3'"; fail=1 ;; esac; }
19
+ command -v jq >/dev/null 2>&1 || { echo "gh-board-add-test: jq required — skipping"; exit 0; }
20
+ command -v git >/dev/null 2>&1 || { echo "gh-board-add-test: git required — skipping"; exit 0; }
21
+
22
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
23
+ # shellcheck source=/dev/null
24
+ . "$LIB/test-forge-shim.sh"; forge_shim_install "$tmp/bin"
25
+ export GH_TOKEN=test-token CCKIT_FORGE=github GH_LOG="$tmp/gh.log" GH_N="$tmp/n"
26
+
27
+ # Org board acme #3. POST items answers as GH_ADD_MODE says: exists = the documented 422 for content
28
+ # already on the board · forbidden = 403 · ok = 201 with a new item. GET items lists issue 42, PR 7
29
+ # and issue 50 (the number the shim gives the first created issue) unless GH_ITEMS_EMPTY=1.
30
+ cat > "$tmp/fixture.sh" <<'SH'
31
+ case "$method $ep" in
32
+ "GET orgs/acme/projectsV2/3")
33
+ out='{"id":11,"node_id":"PVT_rest","number":3,"title":"Board"}' ;;
34
+ "GET orgs/acme/projectsV2/3/fields")
35
+ out='[{"id":101,"node_id":"PVTSSF_status","name":"Status","data_type":"single_select","options":[{"id":"opt_todo","name":{"raw":"Todo","html":"Todo"}}]}]' ;;
36
+ "GET orgs/acme/projectsV2/3/items")
37
+ if [ "${GH_ITEMS_EMPTY:-0}" = 1 ]; then out='[]'; else
38
+ out='[{"id":502,"node_id":"PVTI_other","content_type":"Issue","content":{"number":42,"repository":{"full_name":"acme/other"}}},
39
+ {"id":501,"node_id":"PVTI_a","content_type":"Issue","content":{"number":42,"repository":{"full_name":"acme/app"}}},
40
+ {"id":503,"node_id":"PVTI_pr","content_type":"PullRequest","content":{"number":7,"repository":{"full_name":"acme/app"}}},
41
+ {"id":550,"node_id":"PVTI_new50","content_type":"Issue","content":{"number":50,"repository":{"full_name":"acme/app"}}}]'; fi ;;
42
+ "POST orgs/acme/projectsV2/3/items")
43
+ case "${GH_ADD_MODE:-exists}" in
44
+ exists) code=422; out='{"message":"Content already exists in this project","documentation_url":"https://docs.github.com/rest/projects/items#add-item-to-organization-owned-project","status":"422"}' ;;
45
+ forbidden) code=403; out='{"message":"Resource not accessible by integration","status":"403"}' ;;
46
+ *) code=201; out='{"id":777,"node_id":"PVTI_made","content_type":"Issue"}' ;;
47
+ esac ;;
48
+ "PATCH orgs/acme/projectsV2/3/items/"*)
49
+ out="{\"id\":${ep##*/},\"node_id\":\"PVTI_x\"}" ;;
50
+ esac
51
+ SH
52
+ export GH_FIXTURE="$tmp/fixture.sh"
53
+ export GH_GRAPHQL='{"data":{"addProjectV2ItemById":{"item":{"id":"PVTI_gql"}}}}'
54
+
55
+ add() { # <snippet> — run gh-project.sh functions against the org board, over the shim
56
+ : > "$GH_LOG"
57
+ PATH="$tmp/bin:$PATH" KIT_CONFIG=/nonexistent KIT_REPO=acme/app KIT_OWNER=acme KIT_PROJECT_NUMBER=3 \
58
+ KIT_PROJECT_OWNER_TYPE=organization PROJECT_ID=PVT_rest bash -c "source '$LIB/gh-project.sh'; $1" 2>"$tmp/add.err"
59
+ }
60
+
61
+ # ── the item is already on the board: REST 422 → the existing card ───────────────────────────────
62
+ got="$(add 'project_add_item I_42 acme/app 42 Issue')"
63
+ t "422 exists: prints the existing card as <id>:<node id>" "$got" "501:PVTI_a"
64
+ has "422 exists: the POST was tried first" "$(sed -n 1p "$GH_LOG")" "POST orgs/acme/projectsV2/3/items"
65
+ has "422 exists: then the board's items were read" "$(sed -n 2p "$GH_LOG")" "GET orgs/acme/projectsV2/3/items"
66
+ t "422 exists: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
67
+ t "422 exists: nothing on stderr" "$(cat "$tmp/add.err")" ""
68
+
69
+ got="$(add 'project_add_item PR_7 acme/app 7')"
70
+ t "422 exists, a PR: the PR's card, not an issue's" "$got" "503:PVTI_pr"
71
+
72
+ # ── 422 but the card cannot be read back: the idempotent GraphQL add decides ──────────────────────
73
+ got="$(add 'GH_ITEMS_EMPTY=1; export GH_ITEMS_EMPTY; project_add_item I_42 acme/app 42 Issue')"
74
+ t "422, card not listed: GraphQL's item" "$got" "PVTI_gql"
75
+ has "422, card not listed: GraphQL adds by the content node id" "$(cat "$GH_LOG")" '"content":"I_42"'
76
+ has "422, card not listed: one fallback note" "$(cat "$tmp/add.err")" "board add item: REST could not serve it, falling back to GraphQL"
77
+
78
+ # ── any other REST failure of the add: GraphQL too (an item missing from the board strands the rest)
79
+ got="$(add 'GH_ADD_MODE=forbidden; export GH_ADD_MODE; project_add_item I_42 acme/app 42 Issue')"
80
+ t "REST 403 on add: GraphQL's item" "$got" "PVTI_gql"
81
+ has "REST 403 on add: the API's answer is still reported" "$(cat "$tmp/add.err")" "GitHub answered 403"
82
+ t "REST 403 on add: one GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "1"
83
+
84
+ # A cloud session: no GraphQL, so the skip notice and rc 0, never a GraphQL call.
85
+ got="$(add 'GH_ADD_MODE=forbidden; export GH_ADD_MODE; CLAUDE_CODE_REMOTE=true; project_add_item I_42 acme/app 42 Issue; echo rc=$?')"
86
+ t "cloud, REST 403 on add: rc 0, no item" "$got" "rc=0"
87
+ t "cloud, REST 403 on add: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
88
+
89
+ # A fresh add still prints the new card.
90
+ got="$(add 'GH_ADD_MODE=ok; export GH_ADD_MODE; project_add_item I_42 acme/app 42 Issue')"
91
+ t "201: the new card" "$got" "777:PVTI_made"
92
+
93
+ # ── cckit new on an auto-add board: on the board, no warning, its Status set on the existing card ─
94
+ git init -q --bare "$tmp/remote.git"
95
+ git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
96
+ cd "$tmp/work" || exit 1
97
+ git config user.email t@t; git config user.name t
98
+ git checkout -q -b develop; git commit -q --allow-empty -m init; git push -q origin develop
99
+ export PATH="$tmp/bin:$PATH" KIT_CONFIG=/nonexistent KIT_REPO=acme/app KIT_OWNER=acme KIT_PROJECT_NUMBER=3 \
100
+ KIT_PROJECT_OWNER_TYPE=organization KIT_BASE_BRANCH=develop KIT_PROJECTS_V2=true KIT_WT_INSTALL=0
101
+ export GH_REPO_LABELS='[{"name":"kind:task"},{"name":"priority:p2"},{"name":"role:tech-lead"}]'
102
+ export PROJECT_ID=PVT_rest STATUS_FIELD_ID=PVTSSF_status STATUS_OPT_TODO=opt_todo
103
+ unset GH_ADD_MODE GH_ITEMS_EMPTY
104
+ # shellcheck source=/dev/null
105
+ . "$LIB/gh-project.sh"
106
+ # shellcheck source=/dev/null
107
+ . "$LIB/kit-task-ops.sh"
108
+ load_project_ids() { :; } # the ids are exported above; no captured file in the throwaway repo
109
+ : > "$GH_LOG"
110
+ num="$(kto_task_new "Add a thing" tech-lead task p2 "" "" "" "Body." 2>"$tmp/new.err" | tail -1)"
111
+ t "new: the new issue's number" "$num" "50"
112
+ t "new: no 'NOT added to the board' warning" "$(grep -c 'NOT added' "$tmp/new.err")" "0"
113
+ has "new: the board add was tried over REST" "$(cat "$GH_LOG")" 'POST orgs/acme/projectsV2/3/items {"type":"Issue","owner":"acme","repo":"app","number":50}'
114
+ has "new: the Status is set on the existing card" "$(cat "$GH_LOG")" 'PATCH orgs/acme/projectsV2/3/items/550 {"fields":[{"id":101,"value":"opt_todo"}]}'
115
+ t "new: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
116
+
117
+ [ "$fail" -eq 0 ] && echo "ALL OK (gh-board-add)" || echo "gh-board-add: FAILURES"
118
+ exit "$fail"
@@ -4,7 +4,7 @@
4
4
  # board can live under a USER login or an ORGANIZATION login, and each needs a different GraphQL root
5
5
  # (user(login:) vs organization(login:)). A user-only query silently returns null for an org board.
6
6
  # Covered: _ghp_owner_root resolution, kit-config exporting KIT_PROJECT_OWNER_TYPE, and
7
- # capture-project-ids.sh selecting the matching root end-to-end (stubbed gh — no network).
7
+ # capture-project-ids.sh selecting the matching root end-to-end (over the forge shim — no network).
8
8
  # Run: bash scripts/lib/gh-project-test.sh
9
9
  # errors: strict — a test runner: rc 1 on any failed assertion
10
10
  set -u
@@ -34,63 +34,68 @@ printf '%s' '{"github":{}}' > "$tmp/none.json"
34
34
  got="$(KIT_CONFIG="$tmp/none.json" bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; printf '%s' \"\$KIT_PROJECT_OWNER_TYPE\"")"
35
35
  t "kit-config defaults owner type to user" "$got" "user"
36
36
 
37
- # ── capture-project-ids.sh selects the matching GraphQL root (stubbed gh) ───────────────────────
37
+ # ── capture-project-ids.sh selects the matching GraphQL root (over the forge shim) ──────────────
38
38
  # Isolated scripts dir: a copy of the script + a symlink to the real lib, so $0-relative sourcing +
39
- # OUT path stay inside tmp. A stub gh detects the query root and returns matching-shaped JSON.
39
+ # OUT path stay inside tmp. The shim's curl logs every request — a GraphQL call is ONE
40
+ # `POST graphql {"query":…,"variables":{…}}` line — and a fixture reads the query root out of the
41
+ # body and answers JSON under that same root.
40
42
  mkdir -p "$tmp/scripts" "$tmp/bin"
41
43
  cp "$ROOT/scripts/capture-project-ids.sh" "$tmp/scripts/"
42
44
  ln -s "$LIB" "$tmp/scripts/lib"
43
- cat > "$tmp/bin/gh" <<'SH'
44
- #!/usr/bin/env bash
45
- # Record the query, then emit JSON under whichever root the query selected.
46
- q=""; for a in "$@"; do case "$a" in query=*) q="${a#query=}" ;; esac; done
47
- printf '%s\n' "$q" >> "$GH_QUERY_LOG"
48
- if grep -q 'organization(login' <<<"$q"; then root=organization; else root=user; fi
49
- cat <<JSON
50
- {"data":{"$root":{"projectV2":{"id":"PVT_org123","fields":{"nodes":[
51
- {"__typename":"ProjectV2SingleSelectField","id":"F_status","name":"Status","options":[{"id":"O_todo","name":"Todo"}]},
52
- {"__typename":"ProjectV2FieldCommon","id":"F_plan","name":"Plan Link"}
53
- ]}}}}}
54
- JSON
45
+ # shellcheck source=/dev/null
46
+ . "$LIB/test-forge-shim.sh"; forge_shim_install "$tmp/bin"
47
+ export GH_TOKEN=test-token CCKIT_FORGE=github GH_LOG="$tmp/gh.log"
48
+ cat > "$tmp/root-fixture.sh" <<'SH'
49
+ case "$method $ep" in "POST graphql")
50
+ q="$(printf '%s' "$body" | jq -r '.query // ""')"
51
+ case "$q" in *"organization(login"*) root=organization ;; *) root=user ;; esac
52
+ out="{\"data\":{\"$root\":{\"projectV2\":{\"id\":\"PVT_org123\",\"fields\":{\"nodes\":[
53
+ {\"__typename\":\"ProjectV2SingleSelectField\",\"id\":\"F_status\",\"name\":\"Status\",\"options\":[{\"id\":\"O_todo\",\"name\":\"Todo\"}]},
54
+ {\"__typename\":\"ProjectV2FieldCommon\",\"id\":\"F_plan\",\"name\":\"Plan Link\"}
55
+ ]}}}}}" ;;
56
+ esac
55
57
  SH
56
- chmod +x "$tmp/bin/gh"
57
58
 
58
59
  run_capture() { # <owner-type>
59
60
  printf '%s' "{\"github\":{\"projectsV2\":true,\"owner\":\"acme\",\"projectNumber\":3,\"projectOwnerType\":\"$1\"}}" > "$tmp/cfg.json"
60
- : > "$tmp/qlog"
61
- GH_QUERY_LOG="$tmp/qlog" KIT_CONFIG="$tmp/cfg.json" PATH="$tmp/bin:$PATH" \
61
+ : > "$GH_LOG"
62
+ GH_FIXTURE="$tmp/root-fixture.sh" KIT_CONFIG="$tmp/cfg.json" PATH="$tmp/bin:$PATH" \
62
63
  bash "$tmp/scripts/capture-project-ids.sh" >/dev/null 2>&1
63
64
  }
64
65
 
65
66
  run_capture organization
66
67
  rc=$?
67
68
  t "capture rc 0 (org board)" "$rc" "0"
68
- has "capture uses organization root for an org board" "$(cat "$tmp/qlog")" "organization(login"
69
+ has "capture uses organization root for an org board" "$(cat "$GH_LOG")" "organization(login"
70
+ t "capture is one GraphQL POST, no gh subcommand" "$(grep -c '^POST graphql ' "$GH_LOG"):$(grep -c '^GH-SUBCOMMAND' "$GH_LOG")" "1:0"
71
+ has "capture sends the login and the number as variables" "$(cat "$GH_LOG")" '"variables":{"login":"acme","number":3}'
69
72
  [ -f "$tmp/scripts/.project-ids.env" ] && has "org capture wrote PROJECT_ID" "$(cat "$tmp/scripts/.project-ids.env")" "PROJECT_ID=PVT_org123" || { echo "FAIL: no env written (org)"; fail=1; }
70
73
  has "org capture wrote a field id" "$(cat "$tmp/scripts/.project-ids.env" 2>/dev/null)" "STATUS_FIELD_ID=F_status"
71
74
  rm -f "$tmp/scripts/.project-ids.env"
72
75
 
73
76
  run_capture user
74
- has "capture uses user root for a user board" "$(cat "$tmp/qlog")" "user(login"
77
+ has "capture uses user root for a user board" "$(cat "$GH_LOG")" "user(login"
75
78
 
76
79
  # ── project_issue_status: read an issue's board Status via the cheap issue.projectItems query (#124) ─
77
- mkdir -p "$tmp/bin2"
78
- cat > "$tmp/bin2/gh" <<'SH'
79
- #!/usr/bin/env bash
80
80
  # The issue.projectItems Status query: issue is "In Progress" on project #3 (and Todo on some other).
81
- cat <<'JSON'
82
- {"data":{"repository":{"issue":{"projectItems":{"nodes":[
81
+ # GH_GRAPHQL is what the shim answers to every POST graphql.
82
+ export GH_GRAPHQL='{"data":{"repository":{"issue":{"projectItems":{"nodes":[
83
83
  {"project":{"number":7},"fieldValueByName":{"name":"Todo"}},
84
84
  {"project":{"number":3},"fieldValueByName":{"name":"In Progress"}}
85
- ]}}}}}
86
- JSON
87
- SH
88
- chmod +x "$tmp/bin2/gh"
89
- st="$(PATH="$tmp/bin2:$PATH" KIT_REPO="acme/app" KIT_PROJECT_NUMBER=3 bash -c "source '$LIB/gh-project.sh'; project_issue_status 42")"
85
+ ]}}}}}'
86
+ : > "$GH_LOG"
87
+ st="$(PATH="$tmp/bin:$PATH" KIT_REPO="acme/app" KIT_PROJECT_NUMBER=3 bash -c "source '$LIB/gh-project.sh'; project_issue_status 42")"
90
88
  t "project_issue_status returns the board Status for our project" "$st" "In Progress"
89
+ has "project_issue_status asks for issue 42 of acme/app" "$(cat "$GH_LOG")" '"variables":{"o":"acme","r":"app","n":42}'
91
90
  # unresolved repo/number -> non-zero, no guess.
92
- PATH="$tmp/bin2:$PATH" KIT_REPO="" KIT_PROJECT_NUMBER="" bash -c "source '$LIB/gh-project.sh'; project_issue_status 42" >/dev/null 2>&1
91
+ PATH="$tmp/bin:$PATH" KIT_REPO="" KIT_PROJECT_NUMBER="" bash -c "source '$LIB/gh-project.sh'; project_issue_status 42" >/dev/null 2>&1
93
92
  t "project_issue_status fails (rc 1) with unresolved repo/number" "$?" "1"
93
+ # no forge: every board step is skipped with the one notice, rc 0, and nothing is requested (#396)
94
+ : > "$GH_LOG"
95
+ out="$(PATH="$tmp/bin:$PATH" CCKIT_FORGE=none KIT_REPO="acme/app" KIT_PROJECT_NUMBER=3 bash -c "source '$LIB/gh-project.sh'; project_issue_status 42; echo rc=\$?" 2>"$tmp/noforge.err")"
96
+ t "no forge: project_issue_status is a quiet rc 0" "$out" "rc=0"
97
+ has "no forge: the board notice names the cause" "$(cat "$tmp/noforge.err")" "board step skipped (no forge is configured; see forge.provider)"
98
+ t "no forge: no request was made" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
94
99
 
95
100
  # ── role_option_id: any board Role option resolves, not a fixed list (#378) ─────────────────────
96
101
  # capture-project-ids.sh writes ROLE_OPT_<NAME> for every option the board has; the lookup reads
@@ -126,5 +131,120 @@ for rsh in bash zsh; do
126
131
  || echo "ok: [$rsh] role_option_id evaluates nothing from its argument"
127
132
  done
128
133
 
134
+ # ── the board over REST first, GraphQL as the fallback (E546.7) ────────────────────────────────
135
+ # A fixture answers the Projects v2 REST endpoints of org board acme #3 in the documented shapes
136
+ # (docs.github.com/en/rest/projects): integer field and item ids, node ids beside them, option and
137
+ # iteration ids as strings, option names as {raw, html}. GH_BOARD_PATCH_CODE makes the PATCH answer
138
+ # that HTTP code. No request leaves the shim.
139
+ cat > "$tmp/board-fixture.sh" <<'SH'
140
+ case "$method $ep" in
141
+ "GET orgs/acme/projectsV2/3")
142
+ out='{"id":11,"node_id":"PVT_rest","number":3,"title":"Board"}' ;;
143
+ "GET orgs/acme/projectsV2/3/fields")
144
+ out='[{"id":101,"node_id":"PVTSSF_status","name":"Status","data_type":"single_select","options":[{"id":"opt_todo","name":{"raw":"Todo","html":"Todo"}},{"id":"opt_done","name":{"raw":"Done","html":"Done"}}]},
145
+ {"id":102,"node_id":"PVTIF_iter","name":"Iteration","data_type":"iteration","configuration":{"iterations":[{"id":"it_1","title":{"raw":"Iteration 1","html":"Iteration 1"},"start_date":"2026-11-01","duration":14,"completed":false}]}},
146
+ {"id":103,"node_id":"PVTF_plan","name":"Plan Link","data_type":"text"}]' ;;
147
+ "GET orgs/acme/projectsV2/3/items")
148
+ out='[{"id":502,"node_id":"PVTI_other","content_type":"Issue","content":{"number":42,"repository":{"full_name":"acme/other"}}},
149
+ {"id":501,"node_id":"PVTI_a","content_type":"Issue","content":{"number":42,"repository":{"full_name":"acme/app"}}}]' ;;
150
+ "POST orgs/acme/projectsV2/3/items")
151
+ code=201; out='{"id":777,"node_id":"PVTI_new","content_type":"Issue"}' ;;
152
+ "PATCH orgs/acme/projectsV2/3/items/"*)
153
+ code="${GH_BOARD_PATCH_CODE:-200}"
154
+ if [ "$code" = 200 ]; then out="{\"id\":${ep##*/},\"node_id\":\"PVTI_a\"}"; else out='{"message":"Resource not accessible"}'; fi ;;
155
+ esac
156
+ SH
157
+ export GH_HDR_LOG="$tmp/hdr.log"
158
+ board() { # <snippet> — run gh-project.sh functions against the org board, over the shim
159
+ : > "$GH_LOG"; : > "$GH_HDR_LOG"
160
+ PATH="$tmp/bin:$PATH" GH_FIXTURE="$tmp/board-fixture.sh" KIT_CONFIG=/nonexistent \
161
+ KIT_REPO=acme/app KIT_OWNER=acme KIT_PROJECT_NUMBER=3 KIT_PROJECT_OWNER_TYPE=organization \
162
+ PROJECT_ID=PVT_rest bash -c "source '$LIB/gh-project.sh'; $1" 2>"$tmp/board.err"
163
+ }
164
+ export GH_GRAPHQL='{"data":{"repository":{"issue":{"projectItems":{"nodes":[{"id":"PVTI_gql","project":{"number":3}}]}}}}}'
165
+
166
+ got="$(board 'project_find_item_by_issue 42')"
167
+ t "REST find: the card of acme/app#42, as <id>:<node id>" "$got" "501:PVTI_a"
168
+ has "REST find: reads the board's items over REST" "$(cat "$GH_LOG")" "GET orgs/acme/projectsV2/3/items?per_page=100"
169
+ t "REST find: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
170
+ has "REST find: sends the documented API version" "$(cat "$GH_HDR_LOG")" "X-GitHub-Api-Version: 2026-03-10"
171
+ t "REST find: no fallback note" "$(grep -c 'falling back' "$tmp/board.err")" "0"
172
+
173
+ board 'project_set_single_select 501:PVTI_a PVTSSF_status opt_done; echo rc=$?' > "$tmp/out"
174
+ t "REST Status: rc 0" "$(cat "$tmp/out")" "rc=0"
175
+ has "REST Status: PATCH the item with the field's integer id and the option id" "$(cat "$GH_LOG")" \
176
+ 'PATCH orgs/acme/projectsV2/3/items/501 {"fields":[{"id":101,"value":"opt_done"}]}'
177
+ t "REST Status: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
178
+
179
+ board 'project_set_iteration 501:PVTI_a PVTIF_iter it_1' >/dev/null
180
+ has "REST Iteration: PATCH with the iteration id" "$(cat "$GH_LOG")" \
181
+ 'PATCH orgs/acme/projectsV2/3/items/501 {"fields":[{"id":102,"value":"it_1"}]}'
182
+ board 'project_set_text 501:PVTI_a PVTF_plan https://x/plan' >/dev/null
183
+ has "REST text: PATCH with the text" "$(cat "$GH_LOG")" \
184
+ 'PATCH orgs/acme/projectsV2/3/items/501 {"fields":[{"id":103,"value":"https://x/plan"}]}'
185
+
186
+ got="$(board 'project_add_item I_42 acme/app 42')"
187
+ t "REST add: prints the new item as <id>:<node id>" "$got" "777:PVTI_new"
188
+ has "REST add: POST items by owner, repo and number" "$(cat "$GH_LOG")" \
189
+ 'POST orgs/acme/projectsV2/3/items {"type":"Issue","owner":"acme","repo":"app","number":42}'
190
+ board 'project_add_item PR_7 acme/app 7' >/dev/null
191
+ has "REST add: a PR_ node id adds a PullRequest" "$(cat "$GH_LOG")" '"type":"PullRequest"'
192
+
193
+ got="$(board 'PROJECT_ENV=/nonexistent/ids.env; unset PROJECT_ID; load_project_ids; echo "$PROJECT_ID $STATUS_FIELD_ID $STATUS_FIELD_NUM $STATUS_OPT_DONE $ITERATION_ITER_ITERATION_1 $PLAN_LINK_FIELD_ID"')"
194
+ t "REST ids: load_project_ids reads the ids over REST with no captured file" "$got" \
195
+ "PVT_rest PVTSSF_status 101 opt_done it_1 PVTF_plan"
196
+ has "REST ids: says the ids came over REST" "$(cat "$tmp/board.err")" "board ids read over REST"
197
+
198
+ # An unknown option is not sent over REST: the GraphQL fallback decides.
199
+ board 'project_set_single_select 501:PVTI_a PVTSSF_status opt_missing' >/dev/null
200
+ t "REST Status: an option REST does not list is not PATCHed" "$(grep -c '^PATCH' "$GH_LOG")" "0"
201
+ has "REST Status: ... and goes to GraphQL" "$(cat "$GH_LOG")" '"option":"opt_missing"'
202
+
203
+ # The fallback: REST answers 404 → one note, then GraphQL with the node id.
204
+ export GH_FAIL_EP='orgs/*'
205
+ got="$(board 'project_find_item_by_issue 42')"
206
+ t "fallback find: GraphQL's item after a REST 404" "$got" "PVTI_gql"
207
+ has "fallback find: REST was tried first" "$(sed -n 1p "$GH_LOG")" "GET orgs/acme/projectsV2/3/items"
208
+ t "fallback find: then one GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "1"
209
+ t "fallback find: one stderr note" "$(grep -c 'board find item: REST could not serve it, falling back to GraphQL' "$tmp/board.err")" "1"
210
+ board 'project_set_single_select 501:PVTI_a PVTSSF_status opt_done; echo rc=$?' > "$tmp/out"
211
+ t "fallback Status: rc 0" "$(cat "$tmp/out")" "rc=0"
212
+ has "fallback Status: GraphQL gets the item's node id, not the REST id" "$(cat "$GH_LOG")" '"item":"PVTI_a"'
213
+ t "fallback Status: one note" "$(grep -c 'falling back to GraphQL' "$tmp/board.err")" "1"
214
+ got="$(board 'project_add_item I_42 acme/app 42')"
215
+ has "fallback add: GraphQL adds by the content node id" "$(cat "$GH_LOG")" '"content":"I_42"'
216
+ # A cloud session: REST failed and GraphQL is unavailable → the skip notice, rc 0, no GraphQL.
217
+ board 'CLAUDE_CODE_REMOTE=true; project_set_single_select 501:PVTI_a PVTSSF_status opt_done; echo rc=$?' > "$tmp/out"
218
+ t "cloud, REST 404: rc 0" "$(cat "$tmp/out")" "rc=0"
219
+ t "cloud, REST 404: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
220
+ has "cloud, REST 404: the skip notice" "$(cat "$tmp/board.err")" "board step skipped (GraphQL unavailable"
221
+ unset GH_FAIL_EP
222
+
223
+ # A cloud session where REST works: the card moves.
224
+ board 'CLAUDE_CODE_REMOTE=true; project_set_single_select 501:PVTI_a PVTSSF_status opt_done; echo rc=$?' > "$tmp/out"
225
+ t "cloud: Status moves over REST" "$(grep -c '^PATCH orgs/acme/projectsV2/3/items/501 ' "$GH_LOG"):$(grep -c '^POST graphql' "$GH_LOG")" "1:0"
226
+
227
+ # A hard REST error (403) is reported, not retried over GraphQL.
228
+ board 'GH_BOARD_PATCH_CODE=403; export GH_BOARD_PATCH_CODE; project_set_single_select 501:PVTI_a PVTSSF_status opt_done; echo rc=$?' > "$tmp/out"
229
+ t "REST 403: rc 1" "$(cat "$tmp/out")" "rc=1"
230
+ t "REST 403: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
231
+ has "REST 403: the API's answer on stderr" "$(cat "$tmp/board.err")" "GitHub answered 403"
232
+
233
+ # A GraphQL item handle (a node id) skips REST, which needs the integer id.
234
+ board 'project_set_single_select PVTI_gql PVTSSF_status opt_done' >/dev/null
235
+ t "node-id item: no REST PATCH" "$(grep -c '^PATCH' "$GH_LOG")" "0"
236
+ has "node-id item: GraphQL with the node id" "$(cat "$GH_LOG")" '"item":"PVTI_gql"'
237
+
238
+ # capture-project-ids.sh reads the board over REST and writes the same file.
239
+ printf '%s' '{"github":{"projectsV2":true,"owner":"acme","projectNumber":3,"projectOwnerType":"organization"}}' > "$tmp/cfg.json"
240
+ : > "$GH_LOG"
241
+ GH_FIXTURE="$tmp/board-fixture.sh" KIT_CONFIG="$tmp/cfg.json" PATH="$tmp/bin:$PATH" \
242
+ bash "$tmp/scripts/capture-project-ids.sh" >/dev/null 2>&1
243
+ t "REST capture: rc 0" "$?" "0"
244
+ t "REST capture: no GraphQL call" "$(grep -c '^POST graphql' "$GH_LOG")" "0"
245
+ has "REST capture: PROJECT_ID is the node id" "$(cat "$tmp/scripts/.project-ids.env" 2>/dev/null)" "PROJECT_ID=PVT_rest"
246
+ has "REST capture: the Status option" "$(cat "$tmp/scripts/.project-ids.env" 2>/dev/null)" "STATUS_OPT_DONE=opt_done"
247
+ unset GH_HDR_LOG
248
+
129
249
  [ "$fail" -eq 0 ] && echo "ALL OK (gh-project)" || echo "gh-project: FAILURES"
130
250
  exit "$fail"
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Helpers for GitHub Projects v2 via gh CLI + GraphQL.
2
+ # Helpers for GitHub Projects v2: REST first, GraphQL as the fallback (E546.7).
3
3
  # Source after kit-config.sh: source scripts/lib/gh-project.sh; load_project_ids
4
4
  # Requires scripts/.project-ids.env — populate via scripts/capture-project-ids.sh.
5
5
  # errors: strict — a failed GraphQL call propagates; the board is not guessed
@@ -7,6 +7,12 @@
7
7
  # Locate scripts/ portably when sourced (#313): BASH_SOURCE is bash-only — empty in
8
8
  # zsh, where dirname "" resolved to CWD and the env was sought in the wrong dir.
9
9
  # zsh exposes the sourced file via the %x prompt escape; eval keeps bash from parsing it.
10
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
11
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
12
+ # shellcheck source=/dev/null
13
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
14
+ fi
15
+
10
16
  if [ -n "${BASH_SOURCE:-}" ]; then
11
17
  _ghp_self="$BASH_SOURCE"
12
18
  elif [ -n "${ZSH_VERSION:-}" ]; then
@@ -24,13 +30,65 @@ if [ -f "$SCRIPT_DIR/lib/gh-log.sh" ]; then
24
30
  fi
25
31
  type gh_log >/dev/null 2>&1 || gh_log() { :; }
26
32
 
27
- # The transport switch (#396): Projects v2 is GraphQL-only, so in rest mode (a cloud session) every
28
- # board function below prints the one skip notice and returns 0 with no output.
33
+ # The board moves over REST first (E546.7): load_project_ids, project_add_item, project_find_item_by_issue,
34
+ # project_set_single_select, project_set_iteration and project_set_text call the Projects v2 REST
35
+ # endpoints (gh_rest_board_*, scripts/lib/gh-rest.sh) and fall back to GraphQL only when REST cannot
36
+ # serve the call (404, 410, 415, 501, a transport failure, an unexpected answer), with one stderr note.
37
+ # Where GraphQL is unavailable too (a cloud session, CCKIT_GRAPHQL=0) such a step prints the one skip
38
+ # notice and returns 0. With no forge every board function returns 0 at once (cckit_board_skipped).
39
+ # project_issue_status is GraphQL-only.
40
+ #
41
+ # Item ids: a REST item is "<id>:<node_id>" (the integer REST id, then the GraphQL node id); a GraphQL
42
+ # item is its node id. Every setter takes either: REST with the integer, GraphQL with the node id.
29
43
  if ! type cckit_board_skipped >/dev/null 2>&1 && [ -f "$SCRIPT_DIR/lib/gh-rest.sh" ]; then
30
44
  # shellcheck source=gh-rest.sh
31
45
  . "$SCRIPT_DIR/lib/gh-rest.sh"
32
46
  fi
33
47
  type cckit_board_skipped >/dev/null 2>&1 || cckit_board_skipped() { return 1; }
48
+ type cckit_graphql_off >/dev/null 2>&1 || cckit_graphql_off() { return 1; }
49
+ type cckit_board_graphql_notice >/dev/null 2>&1 || cckit_board_graphql_notice() { :; }
50
+
51
+ # _ghp_fallback <step> — REST could not serve <step>. rc 0: go on with GraphQL (one note printed);
52
+ # rc 1: GraphQL is unavailable here, the skip notice is printed once, the caller returns 0.
53
+ _ghp_fallback() {
54
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 1; fi
55
+ printf 'cckit: board %s: REST could not serve it, falling back to GraphQL\n' "$1" >&2
56
+ return 0
57
+ }
58
+
59
+ # The REST endpoint prefix of our board, or rc 3 when the owner or number is unresolved.
60
+ _ghp_rest_base() {
61
+ command -v gh_rest_board_base >/dev/null 2>&1 || return 3
62
+ gh_rest_board_base "$(_ghp_resolve_owner_type)" "$(_ghp_resolve_owner)" "$(_ghp_resolve_pnum)"
63
+ }
64
+
65
+ # An item handle's REST id ("<id>:<node>" or "<id>"), or rc 1; and its GraphQL node id, or empty.
66
+ _ghp_item_num() {
67
+ local n="${1%%:*}"
68
+ case "$n" in ''|*[!0-9]*) return 1 ;; esac
69
+ printf '%s' "$n"
70
+ }
71
+ _ghp_item_node() {
72
+ case "$1" in
73
+ *:*) printf '%s' "${1#*:}" ;;
74
+ *[!0-9]*) printf '%s' "$1" ;;
75
+ *) : ;;
76
+ esac
77
+ }
78
+
79
+ # _ghp_rest_set <kind> <item> <field> <value> — the REST half of a setter. rc 0 set · 1 a hard error
80
+ # · 3 go on with GraphQL (note printed) · 4 GraphQL unavailable (notice printed; return 0).
81
+ _ghp_rest_set() {
82
+ local kind="$1" item="$2" field="$3" value="$4" inum base rc=3
83
+ if inum="$(_ghp_item_num "$item")" && base="$(_ghp_rest_base)"; then
84
+ gh_log rest mutation "project_set_$kind" "gh-project"
85
+ rc=0; gh_rest_board_set_field "$base" "$inum" "$field" "$kind" "$value" || rc=$?
86
+ fi
87
+ case "$rc" in 0) return 0 ;; 3) ;; *) return 1 ;; esac
88
+ _ghp_fallback "set $kind" || return 4
89
+ [ -n "$(_ghp_item_node "$item")" ] || { echo "cckit: board item '$item' has no GraphQL node id" >&2; return 1; }
90
+ return 3
91
+ }
34
92
 
35
93
  # Worktree-durable location for the captured project IDs (#532). The legacy
36
94
  # scripts/.project-ids.env is gitignored + untracked, so it is ABSENT in every worktree —
@@ -53,6 +111,9 @@ load_project_ids() {
53
111
  cp "$PROJECT_ENV_LEGACY" "$PROJECT_ENV" 2>/dev/null || PROJECT_ENV="$PROJECT_ENV_LEGACY"
54
112
  fi
55
113
  if [[ ! -f "$PROJECT_ENV" ]]; then
114
+ # No captured file (a fresh clone, a cloud session): read the ids over REST into this shell.
115
+ _ghp_load_ids_rest && return 0
116
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 0; fi
56
117
  echo "✗ project IDs not found ($PROJECT_ENV). Run: ./scripts/capture-project-ids.sh first." >&2
57
118
  return 1
58
119
  fi
@@ -60,11 +121,45 @@ load_project_ids() {
60
121
  source "$PROJECT_ENV"
61
122
  }
62
123
 
63
- # Add an issue/PR (by node ID) to the project. Echoes the new item ID.
124
+ # _ghp_load_ids_rest — export the ids gh_rest_board_ids_env reads. Each line must be NAME=value with
125
+ # NAME in [A-Z0-9_] and an id-shaped value; nothing is evaluated. rc 1 when REST cannot read them.
126
+ _ghp_load_ids_rest() {
127
+ local base lines line k v
128
+ command -v gh_rest_board_ids_env >/dev/null 2>&1 || return 1
129
+ base="$(_ghp_rest_base)" || return 1
130
+ gh_log rest query "load_project_ids" "gh-project"
131
+ lines="$(gh_rest_board_ids_env "$base" 2>/dev/null)" || return 1
132
+ case "$lines" in PROJECT_ID=?*) ;; *) return 1 ;; esac
133
+ while IFS= read -r line; do
134
+ k="${line%%=*}"; v="${line#*=}"
135
+ case "$k" in ''|*[!A-Z0-9_]*) continue ;; esac
136
+ case "$v" in *[!A-Za-z0-9_=+/-]*) continue ;; esac
137
+ export "$k=$v"
138
+ done <<EOF
139
+ $lines
140
+ EOF
141
+ echo "cckit: board ids read over REST (no captured file; scripts/capture-project-ids.sh writes one)" >&2
142
+ return 0
143
+ }
144
+
145
+ # Add an issue/PR to the project. Echoes the new item ID.
146
+ # Args: <content node id> [<repo> <number> [Issue|PullRequest]]. REST adds by repo + number, so it
147
+ # runs when those are given (the type defaults from the node id: PR_… is a pull request); GraphQL
148
+ # adds by the node id. Unlike the setters, ANY REST failure falls back to GraphQL here: an item
149
+ # missing from the board strands every later board step, and addProjectV2ItemById is idempotent (#590).
64
150
  project_add_item() {
65
151
  cckit_board_skipped && return 0
152
+ local node="${1:-}" repo="${2:-}" num="${3:-}" type="${4:-}" base out rc=3
153
+ if [ -z "$type" ]; then case "$node" in PR_*) type=PullRequest ;; *) type=Issue ;; esac; fi
154
+ if [ -n "$repo" ] && [ -n "$num" ] && base="$(_ghp_rest_base)"; then
155
+ gh_log rest mutation "project_add_item" "gh-project"
156
+ rc=0; out="$(gh_rest_board_add_item "$base" "$type" "$repo" "$num")" || rc=$?
157
+ fi
158
+ case "$rc" in 0) [ -n "$out" ] && { printf '%s\n' "$out"; return 0; } ;; esac
159
+ _ghp_fallback "add item" || return 0
160
+ [ -n "$node" ] || { echo "cckit: project_add_item: no content node id for the GraphQL fallback" >&2; return 1; }
66
161
  gh_log graphql mutation "project_add_item" "gh-project"
67
- gh api graphql \
162
+ forge_rest graphql \
68
163
  -f query='mutation($project:ID!, $content:ID!) {
69
164
  addProjectV2ItemById(input:{projectId:$project, contentId:$content}){ item { id } }
70
165
  }' \
@@ -75,28 +170,51 @@ project_add_item() {
75
170
  # Set a single-select field. Args: <item_id> <field_id> <option_id>
76
171
  project_set_single_select() {
77
172
  cckit_board_skipped && return 0
173
+ local _rs=0
174
+ _ghp_rest_set single_select "$1" "$2" "$3" || _rs=$?
175
+ case "$_rs" in 0|4) return 0 ;; 1) return 1 ;; esac
78
176
  gh_log graphql mutation "project_set_single_select" "gh-project"
79
- gh api graphql \
177
+ forge_rest graphql \
80
178
  -f query='mutation($project:ID!, $item:ID!, $field:ID!, $option:String!) {
81
179
  updateProjectV2ItemFieldValue(input:{
82
180
  projectId:$project, itemId:$item, fieldId:$field,
83
181
  value:{ singleSelectOptionId:$option }
84
182
  }){ projectV2Item { id } }
85
183
  }' \
86
- -f project="$PROJECT_ID" -f item="$1" -f field="$2" -f option="$3" >/dev/null
184
+ -f project="$PROJECT_ID" -f item="$(_ghp_item_node "$1")" -f field="$2" -f option="$3" >/dev/null
185
+ }
186
+
187
+ # Set an iteration field. Args: <item_id> <field_id> <iteration_id>
188
+ project_set_iteration() {
189
+ cckit_board_skipped && return 0
190
+ local _rs=0
191
+ _ghp_rest_set iteration "$1" "$2" "$3" || _rs=$?
192
+ case "$_rs" in 0|4) return 0 ;; 1) return 1 ;; esac
193
+ gh_log graphql mutation "project_set_iteration" "gh-project"
194
+ forge_rest graphql \
195
+ -f query='mutation($project:ID!, $item:ID!, $field:ID!, $iteration:String!) {
196
+ updateProjectV2ItemFieldValue(input:{
197
+ projectId:$project, itemId:$item, fieldId:$field,
198
+ value:{ iterationId:$iteration }
199
+ }){ projectV2Item { id } }
200
+ }' \
201
+ -f project="$PROJECT_ID" -f item="$(_ghp_item_node "$1")" -f field="$2" -f iteration="$3" >/dev/null
87
202
  }
88
203
 
89
204
  # Set a text field. Args: <item_id> <field_id> <text>
90
205
  project_set_text() {
91
206
  cckit_board_skipped && return 0
207
+ local _rs=0
208
+ _ghp_rest_set text "$1" "$2" "$3" || _rs=$?
209
+ case "$_rs" in 0|4) return 0 ;; 1) return 1 ;; esac
92
210
  gh_log graphql mutation "project_set_text" "gh-project"
93
- gh api graphql \
211
+ forge_rest graphql \
94
212
  -f query='mutation($project:ID!, $item:ID!, $field:ID!, $text:String!) {
95
213
  updateProjectV2ItemFieldValue(input:{
96
214
  projectId:$project, itemId:$item, fieldId:$field, value:{ text:$text }
97
215
  }){ projectV2Item { id } }
98
216
  }' \
99
- -f project="$PROJECT_ID" -f item="$1" -f field="$2" -f text="$3" >/dev/null
217
+ -f project="$PROJECT_ID" -f item="$(_ghp_item_node "$1")" -f field="$2" -f text="$3" >/dev/null
100
218
  }
101
219
 
102
220
  # Resolve an option ID from a human name.
@@ -209,13 +327,22 @@ project_find_item_by_issue() {
209
327
  name="${repo##*/}"
210
328
  # Guard: an empty repo/number is the silent-failure trap — surface it, don't no-op.
211
329
  if [[ -z "$owner" || -z "$name" || -z "$pnum" ]]; then
330
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 0; fi
212
331
  echo "✗ project_find_item_by_issue: repo/project-number unresolved (KIT_REPO='${KIT_REPO:-}' repo='$repo' KIT_PROJECT_NUMBER='${KIT_PROJECT_NUMBER:-}'). Set .github.repo + .github.projectNumber in kit.config.json, or pass the number as arg 2." >&2
213
332
  return 1
214
333
  fi
334
+ # REST first: the board's items, read for this issue's card ("<id>:<node_id>").
335
+ local base rc=3
336
+ if base="$(gh_rest_board_base "$(_ghp_resolve_owner_type)" "$(_ghp_resolve_owner)" "$pnum" 2>/dev/null)"; then
337
+ gh_log rest query "project_find_item_by_issue" "gh-project"
338
+ rc=0; item_id="$(gh_rest_board_find_issue_item "$base" "$repo" "$issue_num")" || rc=$?
339
+ fi
340
+ case "$rc" in 0) [ -n "$item_id" ] && printf '%s\n' "$item_id"; return 0 ;; 3) ;; *) return 1 ;; esac
341
+ _ghp_fallback "find item" || return 0
215
342
  gh_log graphql query "project_find_item_by_issue:cheap" "gh-project"
216
343
  # The cheap query: issue.projectItems(first:20), each node carrying its project number.
217
344
  # No pagination, no board scan — O(1) per issue.
218
- resp=$(gh api graphql \
345
+ resp=$(forge_rest graphql \
219
346
  -f query='query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){issue(number:$n){projectItems(first:20){nodes{id project{number}}}}}}' \
220
347
  -F o="$owner" -F r="$name" -F n="$issue_num" 2>&1)
221
348
  # A GraphQL/transport error (or a null issue) must abort LOUDLY — never let it read as
@@ -237,10 +364,11 @@ project_find_item_by_issue() {
237
364
  # before starting an issue so it can warn on a collision (another session already In Progress). #124.
238
365
  project_issue_status() {
239
366
  cckit_board_skipped && return 0
367
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 0; fi
240
368
  local issue_num="$1" pnum="${2:-$(_ghp_resolve_pnum)}" repo owner name resp
241
369
  repo="$(_ghp_resolve_repo)"; owner="${repo%%/*}"; name="${repo##*/}"
242
370
  [ -n "$owner" ] && [ -n "$name" ] && [ -n "$pnum" ] || return 1
243
- resp="$(gh api graphql \
371
+ resp="$(forge_rest graphql \
244
372
  -f query='query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){issue(number:$n){projectItems(first:20){nodes{project{number} fieldValueByName(name:"Status"){...on ProjectV2ItemFieldSingleSelectValue{name}}}}}}}' \
245
373
  -F o="$owner" -F r="$name" -F n="$issue_num" 2>/dev/null)" || return 1
246
374
  printf '%s' "$resp" | jq -r --argjson n "$pnum" \