@jeiemgi/cckit 0.11.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 (121) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +45 -41
  3. package/README.md +39 -29
  4. package/bin/cckit +111 -70
  5. package/cckit.config.json +1 -1
  6. package/package.json +1 -1
  7. package/scripts/advisor-test.sh +55 -0
  8. package/scripts/autopilot.sh +4 -4
  9. package/scripts/capture-project-ids.sh +16 -0
  10. package/scripts/check.sh +6 -0
  11. package/scripts/content-skills-test.sh +1 -1
  12. package/scripts/copilot-loop-test.sh +8 -8
  13. package/scripts/force-push-fence-test.sh +44 -0
  14. package/scripts/force-push-fence.baseline +1 -0
  15. package/scripts/force-push-fence.sh +51 -0
  16. package/scripts/init.sh +2 -2
  17. package/scripts/instruction-budget-baseline.txt +1 -1
  18. package/scripts/kit-doctor-test.sh +5 -0
  19. package/scripts/kit-doctor.sh +96 -2
  20. package/scripts/lib/agent-resolve-test.sh +2 -0
  21. package/scripts/lib/agent-resolve.sh +3 -2
  22. package/scripts/lib/board-view.sh +3 -3
  23. package/scripts/lib/captain.sh +1 -1
  24. package/scripts/lib/copilot-test.sh +4 -4
  25. package/scripts/lib/copilot.sh +13 -13
  26. package/scripts/lib/effort-close-subs-test.sh +96 -0
  27. package/scripts/lib/effort-dispatch-test.sh +2 -2
  28. package/scripts/lib/effort-ops-test.sh +98 -9
  29. package/scripts/lib/effort-ops.sh +390 -63
  30. package/scripts/lib/effort-parity-test.sh +37 -31
  31. package/scripts/lib/effort-plan.sh +3 -3
  32. package/scripts/lib/effort-review-test.sh +107 -0
  33. package/scripts/lib/effort-review.sh +93 -0
  34. package/scripts/lib/effort-slug-test.sh +4 -0
  35. package/scripts/lib/effort-slug.sh +5 -4
  36. package/scripts/lib/effort.sh +47 -74
  37. package/scripts/lib/forge-github.sh +18 -7
  38. package/scripts/lib/gh-board-add-test.sh +118 -0
  39. package/scripts/lib/gh-project-test.sh +115 -0
  40. package/scripts/lib/gh-project.sh +128 -6
  41. package/scripts/lib/gh-rest-test.sh +12 -8
  42. package/scripts/lib/gh-rest.sh +189 -15
  43. package/scripts/lib/git-core-test.sh +2 -2
  44. package/scripts/lib/grill-record-test.sh +49 -0
  45. package/scripts/lib/grill-record.sh +88 -0
  46. package/scripts/lib/handoff.sh +1 -1
  47. package/scripts/lib/kit-brief-test.sh +29 -0
  48. package/scripts/lib/kit-brief.sh +91 -6
  49. package/scripts/lib/kit-lib-test.sh +1 -1
  50. package/scripts/lib/kit-lib.sh +7 -7
  51. package/scripts/lib/kit-msg.sh +3 -3
  52. package/scripts/lib/kit-status.sh +1 -1
  53. package/scripts/lib/kit-task-ops-test.sh +17 -0
  54. package/scripts/lib/kit-task-ops.sh +73 -22
  55. package/scripts/lib/kto-task-new-test.sh +18 -0
  56. package/scripts/lib/kto-task-pr-merge-test.sh +44 -0
  57. package/scripts/lib/kto-task-pr-test.sh +3 -3
  58. package/scripts/lib/light-task.sh +16 -1
  59. package/scripts/lib/loose-issues.sh +65 -0
  60. package/scripts/lib/naming-test.sh +112 -0
  61. package/scripts/lib/naming-verbs-test.sh +126 -0
  62. package/scripts/lib/naming.sh +172 -0
  63. package/scripts/lib/next-test.sh +1 -1
  64. package/scripts/lib/next.sh +6 -6
  65. package/scripts/lib/plan-machine.sh +9 -9
  66. package/scripts/lib/plan-next.sh +4 -4
  67. package/scripts/lib/qa-lane.sh +1 -1
  68. package/scripts/lib/spec-lint-test.sh +63 -0
  69. package/scripts/lib/spec-lint.sh +95 -0
  70. package/scripts/lib/sprint-test.sh +96 -0
  71. package/scripts/lib/sprint.sh +216 -0
  72. package/scripts/lib/stage-receipt-test.sh +132 -0
  73. package/scripts/lib/stage-receipt.sh +184 -5
  74. package/scripts/lib/test-forge-shim.sh +2 -1
  75. package/scripts/lib/verbs.sh +1 -1
  76. package/scripts/lib/verbs.tsv +17 -15
  77. package/scripts/lib/worker-brief-test.sh +1 -1
  78. package/scripts/lib/worker-brief.sh +1 -1
  79. package/scripts/lib/worktree-start.sh +42 -1
  80. package/scripts/loose-issues-test.sh +102 -0
  81. package/scripts/loose-issues.baseline +5 -0
  82. package/scripts/night-grant.sh +1 -1
  83. package/scripts/portable-test.sh +1 -1
  84. package/scripts/status-test.sh +1 -1
  85. package/scripts/status.sh +4 -4
  86. package/scripts/task-sync-test.sh +34 -0
  87. package/scripts/task-sync.sh +81 -1
  88. package/scripts/terms-check.sh +1 -1
  89. package/scripts/verbs-ratchet-test.sh +6 -1
  90. package/scripts/verbs-test.sh +4 -4
  91. package/scripts/verbs.baseline +1 -1
  92. package/skills/kit-add/SKILL.md +1 -1
  93. package/skills/kit-advisor/SKILL.md +75 -0
  94. package/skills/kit-advisor/references/close.md +53 -0
  95. package/skills/kit-advisor/references/grill.md +69 -0
  96. package/skills/kit-advisor/references/orchestrate.md +56 -0
  97. package/skills/kit-advisor/references/plan.md +64 -0
  98. package/skills/kit-advisor/references/review.md +47 -0
  99. package/skills/kit-advisor/references/step-report.md +61 -0
  100. package/skills/kit-autopilot/SKILL.md +1 -1
  101. package/skills/kit-cleanup/SKILL.md +2 -2
  102. package/skills/kit-effort-close/SKILL.md +16 -8
  103. package/skills/kit-effort-new/SKILL.md +11 -8
  104. package/skills/kit-effort-pr/SKILL.md +7 -7
  105. package/skills/kit-next/SKILL.md +7 -7
  106. package/skills/kit-plan-next/SKILL.md +10 -11
  107. package/skills/kit-status/SKILL.md +5 -5
  108. package/skills/kit-task-pr-auto/SKILL.md +1 -1
  109. package/skills/kit-task-pr-merge/SKILL.md +3 -3
  110. package/skills/kit-task-sync/SKILL.md +2 -0
  111. package/skills/routing.yaml +5 -0
  112. package/templates/hooks/kit-mail-check.sh.tmpl +1 -1
  113. package/templates/instructions.md.tmpl +3 -3
  114. package/templates/rules/authoring.md +7 -3
  115. package/templates/rules/delegation-brief.md +4 -0
  116. package/templates/rules/effort-model.md +34 -31
  117. package/templates/rules/gate-and-review.md +1 -1
  118. package/templates/rules/merge-safety.md +9 -7
  119. package/templates/rules/naming-and-ids.md +20 -24
  120. package/templates/rules/plan-next.md +5 -5
  121. package/templates/skills/campaign/SKILL.md +2 -2
@@ -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
@@ -30,13 +30,65 @@ if [ -f "$SCRIPT_DIR/lib/gh-log.sh" ]; then
30
30
  fi
31
31
  type gh_log >/dev/null 2>&1 || gh_log() { :; }
32
32
 
33
- # The transport switch (#396): Projects v2 is GraphQL-only, so in rest mode (a cloud session) every
34
- # 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.
35
43
  if ! type cckit_board_skipped >/dev/null 2>&1 && [ -f "$SCRIPT_DIR/lib/gh-rest.sh" ]; then
36
44
  # shellcheck source=gh-rest.sh
37
45
  . "$SCRIPT_DIR/lib/gh-rest.sh"
38
46
  fi
39
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
+ }
40
92
 
41
93
  # Worktree-durable location for the captured project IDs (#532). The legacy
42
94
  # scripts/.project-ids.env is gitignored + untracked, so it is ABSENT in every worktree —
@@ -59,6 +111,9 @@ load_project_ids() {
59
111
  cp "$PROJECT_ENV_LEGACY" "$PROJECT_ENV" 2>/dev/null || PROJECT_ENV="$PROJECT_ENV_LEGACY"
60
112
  fi
61
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
62
117
  echo "✗ project IDs not found ($PROJECT_ENV). Run: ./scripts/capture-project-ids.sh first." >&2
63
118
  return 1
64
119
  fi
@@ -66,9 +121,43 @@ load_project_ids() {
66
121
  source "$PROJECT_ENV"
67
122
  }
68
123
 
69
- # 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).
70
150
  project_add_item() {
71
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; }
72
161
  gh_log graphql mutation "project_add_item" "gh-project"
73
162
  forge_rest graphql \
74
163
  -f query='mutation($project:ID!, $content:ID!) {
@@ -81,6 +170,9 @@ project_add_item() {
81
170
  # Set a single-select field. Args: <item_id> <field_id> <option_id>
82
171
  project_set_single_select() {
83
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
84
176
  gh_log graphql mutation "project_set_single_select" "gh-project"
85
177
  forge_rest graphql \
86
178
  -f query='mutation($project:ID!, $item:ID!, $field:ID!, $option:String!) {
@@ -89,12 +181,32 @@ project_set_single_select() {
89
181
  value:{ singleSelectOptionId:$option }
90
182
  }){ projectV2Item { id } }
91
183
  }' \
92
- -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
93
202
  }
94
203
 
95
204
  # Set a text field. Args: <item_id> <field_id> <text>
96
205
  project_set_text() {
97
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
98
210
  gh_log graphql mutation "project_set_text" "gh-project"
99
211
  forge_rest graphql \
100
212
  -f query='mutation($project:ID!, $item:ID!, $field:ID!, $text:String!) {
@@ -102,7 +214,7 @@ project_set_text() {
102
214
  projectId:$project, itemId:$item, fieldId:$field, value:{ text:$text }
103
215
  }){ projectV2Item { id } }
104
216
  }' \
105
- -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
106
218
  }
107
219
 
108
220
  # Resolve an option ID from a human name.
@@ -215,9 +327,18 @@ project_find_item_by_issue() {
215
327
  name="${repo##*/}"
216
328
  # Guard: an empty repo/number is the silent-failure trap — surface it, don't no-op.
217
329
  if [[ -z "$owner" || -z "$name" || -z "$pnum" ]]; then
330
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 0; fi
218
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
219
332
  return 1
220
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
221
342
  gh_log graphql query "project_find_item_by_issue:cheap" "gh-project"
222
343
  # The cheap query: issue.projectItems(first:20), each node carrying its project number.
223
344
  # No pagination, no board scan — O(1) per issue.
@@ -243,6 +364,7 @@ project_find_item_by_issue() {
243
364
  # before starting an issue so it can warn on a collision (another session already In Progress). #124.
244
365
  project_issue_status() {
245
366
  cckit_board_skipped && return 0
367
+ if cckit_graphql_off; then cckit_board_graphql_notice; return 0; fi
246
368
  local issue_num="$1" pnum="${2:-$(_ghp_resolve_pnum)}" repo owner name resp
247
369
  repo="$(_ghp_resolve_repo)"; owner="${repo%%/*}"; name="${repo##*/}"
248
370
  [ -n "$owner" ] && [ -n "$name" ] && [ -n "$pnum" ] || return 1
@@ -2,8 +2,8 @@
2
2
  # shellcheck shell=bash
3
3
  # gh-rest-test.sh — the lifecycle verbs over the forge (E537.3; #396 before it). cckit pr, merge,
4
4
  # close, new, effort new, effort pr and effort close send only REST requests on repos/… endpoints —
5
- # never a gh subcommand, never GraphQL — and in a cloud session every board step is skipped with
6
- # one notice. Hermetic: the shared forge shim (test-forge-shim.sh) answers like the REST API over a
5
+ # never a gh subcommand, never GraphQL — and in a cloud session with no board named (KIT_OWNER,
6
+ # KIT_PROJECT_NUMBER) every board step is skipped with one notice. Hermetic: the shared forge shim (test-forge-shim.sh) answers like the REST API over a
7
7
  # curl stand-in and logs `METHOD path {json}`; a throwaway repo and a bare remote.
8
8
  # Run: bash scripts/lib/gh-rest-test.sh
9
9
  # errors: strict — a test runner: rc 1 on any failed assertion
@@ -95,7 +95,7 @@ unset _CCKIT_BOARD_NOTICE_DONE; kto_task_pr 42 "Did the thing." >"$tmp/out" 2>"$
95
95
  t "pr: rc 0 over REST" "$rc" "0"
96
96
  rest_only "$GH_LOG" "pr: only REST calls"
97
97
  tc "$GH_LOG" '^GET repos/o/r/issues/42 ' "pr: reads the issue over REST"
98
- tc "$GH_LOG" '^POST repos/o/r/pulls \{"title":"fix: Fix the thing","head":"fix/42-the-thing","base":"develop"' "pr: opens the PR with POST pulls"
98
+ tc "$GH_LOG" '^POST repos/o/r/pulls \{"title":"fix: Fix the thing \[#42\]","head":"fix/42-the-thing","base":"develop"' "pr: opens the PR with POST pulls"
99
99
  tc "$GH_LOG" '^PATCH repos/o/r/issues/7 \{"labels":\["kind:fix","role:tech-lead"\],"assignees":\["me"\],"milestone":3\}' "pr: labels, assignee and milestone in one PATCH"
100
100
  tc "$tmp/out" 'https://github.com/o/r/pull/7' "pr: prints the PR url"
101
101
  t "pr: the board notice is printed once" "$(grep -c 'board step skipped' "$tmp/err")" "1"
@@ -191,15 +191,18 @@ t "no gh subcommand ran in the task verbs" "$(grep -c '^GH-SUBCOMMAND'
191
191
  . "$LIB/effort-ops.sh"
192
192
  GH_TITLE="[Effort] 99 · demo effort"; GH_LABELS='[{"name":"role:tech-lead"},{"name":"kind:task"}]'
193
193
  export KIT_BASE_BRANCH="main"
194
+ # The parent body effort close re-reads (E546.5): a Spec, so the close goes past its check. JSON-escaped.
195
+ export GH_BODY='## Goal\nship it\n\n## Spec\n- it ships'
196
+
194
197
 
195
198
  # cckit effort new
196
199
  : > "$GH_LOG"
197
- unset _CCKIT_BOARD_NOTICE_DONE; parent="$(effort_new --flow Core "demo effort" "first sub" "second sub" 2>"$tmp/err")"; rc=$?
200
+ unset _CCKIT_BOARD_NOTICE_DONE; parent="$(effort_new --flow Core --spec "it ships" "demo effort" "first sub" "second sub" 2>"$tmp/err")"; rc=$?
198
201
  t "effort new: rc 0 over REST" "$rc" "0"
199
202
  rest_only "$GH_LOG" "effort new: only REST calls"
200
203
  tc "$GH_LOG" '^POST repos/o/r/labels \{"name":"effort",' "effort new: ensures labels over REST"
201
- tc "$GH_LOG" "^POST repos/o/r/issues \{\"title\":\"\[Effort\] · \[Core\] demo effort\".*\"labels\":\[\"effort\"" "effort new: POST issues for the parent"
202
- tc "$GH_LOG" "^PATCH repos/o/r/issues/$parent \{\"title\":\"\[Effort\] $parent · \[Core\] demo effort\"\}$" "effort new: renames the parent with its number"
204
+ tc "$GH_LOG" "^POST repos/o/r/issues \{\"title\":\"demo effort\".*\"labels\":\[\"effort\"" "effort new: POST issues for the parent"
205
+ tc "$GH_LOG" "^PATCH repos/o/r/issues/$parent \{\"title\":\"\[E$parent\] demo effort\"\}$" "effort new: renames the parent with its number"
203
206
  tc "$GH_LOG" "^POST repos/o/r/issues/$parent/labels \{\"labels\":\[\"slug:demo-effort\"\]\}$" "effort new: adds the slug label"
204
207
  t "effort new: parent + 2 subs created" "$(grep -c '^POST repos/o/r/issues ' "$GH_LOG")" "3"
205
208
  t "effort new: 2 sub-issues linked" "$(grep -c 'sub_issues' "$GH_LOG")" "2"
@@ -215,7 +218,7 @@ echo work > file.txt; git add file.txt; git commit -q -m "feat: do the thing (#1
215
218
  unset _CCKIT_BOARD_NOTICE_DONE; effort_pr 99 --summary "SUMMARY" >"$tmp/out" 2>"$tmp/err"; rc=$?
216
219
  t "effort pr: rc 0 over REST" "$rc" "0"
217
220
  rest_only "$GH_LOG" "effort pr: only REST calls"
218
- tc "$GH_LOG" '^POST repos/o/r/pulls \{"title":"feat: demo effort \[#99\]","head":"effort/99-demo","base":"main"' "effort pr: POST pulls effort/99 → main"
221
+ tc "$GH_LOG" '^POST repos/o/r/pulls \{"title":"feat: demo effort \[E99\]","head":"effort/99-demo","base":"main"' "effort pr: POST pulls effort/99 → main"
219
222
  tc "$GH_LOG" '^PATCH repos/o/r/issues/7 \{"labels":\["role:tech-lead","kind:task".*"milestone":3' "effort pr: inherits labels + milestone"
220
223
  t "effort pr: the board notice is printed once" "$(grep -c 'board step skipped' "$tmp/err")" "1"
221
224
 
@@ -225,7 +228,8 @@ cd "$tmp/work" || exit 1
225
228
  t "effort close: rc 0 over REST" "$rc" "0"
226
229
  rest_only "$GH_LOG" "effort close: only REST calls"
227
230
  tc "$GH_LOG" '^PUT repos/o/r/pulls/9/merge \{"merge_method":"squash"\}$' "effort close: squash-merges over REST"
228
- tc "$GH_LOG" '^PATCH repos/o/r/issues/101 \{"state":"closed","state_reason":"completed"\}$' "effort close: closes sub #101"
231
+ # #565: the shim's subs are already closed, so close keeps their close reason (no second PATCH)
232
+ t "effort close: does not re-close an already-closed sub" "$(grep -c '^PATCH repos/o/r/issues/101 ' "$GH_LOG")" "0"
229
233
  tc "$GH_LOG" '^PATCH repos/o/r/issues/99 \{"state":"closed","state_reason":"completed"\}$' "effort close: closes the parent"
230
234
  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
231
235
  t "effort close: the board notice is printed once" "$(printf '%s\n' "$close_out" | grep -c 'board step skipped')" "1"
@@ -7,13 +7,17 @@
7
7
  # (GraphQL) transport of #396 is gone, so `cckit_gh_rest` is always true and `CCKIT_GH_TRANSPORT`
8
8
  # does nothing but warn once. What still depends on where cckit runs is GraphQL itself: a cloud
9
9
  # agent session reaches GitHub through a proxy that refuses it (403), and Projects v2 is GraphQL-only,
10
- # so board steps are skipped there with ONE notice line (exit 0, never a failure). They are skipped
11
- # the same way when the forge provider is `none`.
10
+ # so the board moves over the Projects v2 REST endpoints first (E546.7, gh_rest_board_* below) and
11
+ # GraphQL is only the fallback; where GraphQL is unavailable too, a board step that REST could not
12
+ # serve is skipped with ONE notice line (exit 0, never a failure). With the forge provider `none`
13
+ # every board step is skipped the same way.
12
14
  #
13
15
  # cckit_gh_rest rc 0 (kept for callers; REST is the only transport)
14
16
  # cckit_gh_transport echo rest
15
- # cckit_board_skipped rc 0 iff board steps are skipped (prints the notice once):
16
- # CLAUDE_CODE_REMOTE=true, CCKIT_GRAPHQL=0, or no forge
17
+ # cckit_board_skipped rc 0 iff board steps are skipped (prints the notice once): no
18
+ # forge, or GraphQL off with KIT_OWNER/KIT_PROJECT_NUMBER unset
19
+ # cckit_graphql_off rc 0 iff GraphQL is unavailable: CLAUDE_CODE_REMOTE=true or CCKIT_GRAPHQL=0
20
+ # cckit_board_graphql_notice the GraphQL-unavailable board notice, once per process
17
21
  # gh_rest_closing_refs stdin: a PR body → the issue #s it closes (pure)
18
22
  # gh_rest_issue_json <repo> <n> {number,title,body,state,labels[{name}],milestone{title,number}}
19
23
  # gh_rest_issue_state <repo> <n> OPEN | CLOSED
@@ -42,8 +46,18 @@
42
46
  # gh_rest_issue_closing_prs <repo> <n> merged PRs that close <n> by keyword (timeline)
43
47
  # gh_rest_wave_rows <repo> <parent> "sub|STATE|pr|merge-sha|pr-title" per sub (wave close)
44
48
  #
45
- # Not reachable in the cloud: Projects v2 (skipped), and remote branch deletion (the proxy rejects
46
- # DELETE git/refs) — callers keep the branch and say so.
49
+ # gh_rest_board_base <owner-type> <owner> <number> orgs/<o>/projectsV2/<n> | users/<o>/projectsV2/<n>
50
+ # gh_rest_board_project <base> {id,node_id,number,title}
51
+ # gh_rest_board_fields <base> [{id,node_id,name,data_type,options[{id,name}],iterations[{id,title,start_date}]}]
52
+ # gh_rest_board_ids_env <base> the scripts/.project-ids.env lines, read over REST
53
+ # gh_rest_board_find_item <base> <Issue|PullRequest> <repo> <n> "<item id>:<item node id>", empty when not on the board
54
+ # gh_rest_board_find_issue_item <base> <repo> <n> the same, for an issue
55
+ # gh_rest_board_add_item <base> <Issue|PullRequest> <repo> <n> "<item id>:<item node id>"
56
+ # gh_rest_board_set_field <base> <item id> <field id|node id> <single_select|iteration|text> <value>
57
+ # (board rc: 0 ok · 3 REST cannot serve it, the caller may fall back to GraphQL · 1 any other error)
58
+ #
59
+ # Not reachable in the cloud: GraphQL (so the board's GraphQL fallback), and remote branch deletion
60
+ # (the proxy rejects DELETE git/refs) — callers keep the branch and say so.
47
61
  # bash 3.2 + zsh compatible. Requires jq.
48
62
  # errors: mixed — creates, closes and merges propagate; labels/milestone/assignee are best-effort
49
63
  _ghr_self="${BASH_SOURCE[0]:-$0}"
@@ -74,18 +88,33 @@ cckit_gh_transport() { cckit_gh_rest; printf 'rest'; }
74
88
  # rc 0 in a cloud agent session, where the proxy also rejects remote branch deletion (#396).
75
89
  cckit_in_cloud() { [ "${CLAUDE_CODE_REMOTE:-}" = "true" ]; }
76
90
 
77
- # rc 0 when board steps (Projects v2, GraphQL-only) are skipped: a cloud session, CCKIT_GRAPHQL=0,
78
- # or no forge. Prints the notice at most once per process.
79
- cckit_board_skipped() {
80
- local why=""
81
- if [ "${CLAUDE_CODE_REMOTE:-}" = "true" ] || [ "${CCKIT_GRAPHQL:-1}" = "0" ]; then why="$CCKIT_BOARD_SKIP_NOTICE"
82
- elif command -v forge_available >/dev/null 2>&1 && ! forge_available; then why="$CCKIT_BOARD_SKIP_NOTICE_NOFORGE"
83
- else return 1; fi
91
+ # rc 0 when GraphQL is unavailable: a cloud session (the proxy answers 403) or CCKIT_GRAPHQL=0.
92
+ # The board still moves over REST there; only its GraphQL fallback is gone.
93
+ cckit_graphql_off() { [ "${CLAUDE_CODE_REMOTE:-}" = "true" ] || [ "${CCKIT_GRAPHQL:-1}" = "0" ]; }
94
+
95
+ _cckit_board_notice() {
84
96
  if [ -z "${_CCKIT_BOARD_NOTICE_DONE:-}" ]; then
85
- printf '%s\n' "$why" >&2
97
+ printf '%s\n' "$1" >&2
86
98
  _CCKIT_BOARD_NOTICE_DONE=1
87
99
  fi
88
- return 0
100
+ }
101
+
102
+ # The notice for a board step REST could not serve where GraphQL is unavailable. Once per process.
103
+ cckit_board_graphql_notice() { _cckit_board_notice "$CCKIT_BOARD_SKIP_NOTICE"; }
104
+
105
+ # rc 0 when board steps are skipped outright: no forge is configured, or GraphQL is unavailable and
106
+ # REST cannot name the board (KIT_OWNER or KIT_PROJECT_NUMBER unset). Prints the notice at most once
107
+ # per process. A cloud session with both set is not a skip: the board moves over REST (E546.7).
108
+ cckit_board_skipped() {
109
+ if command -v forge_available >/dev/null 2>&1 && ! forge_available; then
110
+ _cckit_board_notice "$CCKIT_BOARD_SKIP_NOTICE_NOFORGE"
111
+ return 0
112
+ fi
113
+ if cckit_graphql_off && { [ -z "${KIT_OWNER:-}" ] || [ -z "${KIT_PROJECT_NUMBER:-}" ]; }; then
114
+ _cckit_board_notice "$CCKIT_BOARD_SKIP_NOTICE"
115
+ return 0
116
+ fi
117
+ return 1
89
118
  }
90
119
 
91
120
  # --- pure ----------------------------------------------------------------------------------------
@@ -351,3 +380,148 @@ EOF
351
380
  printf '%s|%s|%s|%s|%s\n' "$sub" "$state" "$pr" "$oid" "$title"
352
381
  done
353
382
  }
383
+
384
+ # --- Projects v2 board over REST (E546.7) --------------------------------------------------------
385
+ # GitHub's REST endpoints for Projects v2, as documented (read 2026-11-24):
386
+ # https://docs.github.com/en/rest/projects/projects GET {orgs/<org>|users/<user>}/projectsV2/<number>
387
+ # https://docs.github.com/en/rest/projects/fields GET …/projectsV2/<number>/fields
388
+ # https://docs.github.com/en/rest/projects/items GET|POST …/projectsV2/<number>/items
389
+ # PATCH …/projectsV2/<number>/items/<item_id>
390
+ # The docs send `X-GitHub-Api-Version: 2026-03-10` (CCKIT_BOARD_API_VERSION overrides it).
391
+ # add an item POST {"type":"Issue"|"PullRequest","owner":"<o>","repo":"<r>","number":<n>} → 201, the item
392
+ # set a field PATCH {"fields":[{"id":<field id, integer>,"value":<string|number|null>}]} → 200, the item;
393
+ # a single-select value is the option id, an iteration value the iteration id (strings)
394
+ # Field and item ids are integers in REST and node ids (`node_id`) in GraphQL; option and iteration ids
395
+ # are strings. A REST item travels as "<id>:<node_id>" so a GraphQL fallback still has its node id.
396
+ # The user-owned endpoints do not accept GitHub App tokens.
397
+ CCKIT_BOARD_API_VERSION_DEFAULT="2026-03-10"
398
+
399
+ # _ghr_board <endpoint> [flags…] — one board call. rc 0 with the output; rc 3 when REST cannot serve
400
+ # it (HTTP 404, 410, 415 or 501, a transport failure, or an answer the --jq filter rejects), with
401
+ # nothing printed; rc 1 on any other HTTP error, the API's message on stderr.
402
+ _ghr_board() {
403
+ local err out rc=0 code
404
+ err="$(mktemp)" || return 1
405
+ out="$(_ghr_api "$@" -H "X-GitHub-Api-Version: ${CCKIT_BOARD_API_VERSION:-$CCKIT_BOARD_API_VERSION_DEFAULT}" 2>"$err")" || rc=$?
406
+ if [ "$rc" = 0 ]; then
407
+ rm -f "$err"
408
+ [ -n "$out" ] && printf '%s\n' "$out"
409
+ return 0
410
+ fi
411
+ code="$(sed -nE 's/.*GitHub answered ([0-9]{3}) .*/\1/p' "$err" | sed -n 1p)"
412
+ case "$code" in
413
+ ''|404|410|415|501) rm -f "$err"; return 3 ;;
414
+ esac
415
+ cat "$err" >&2; rm -f "$err"
416
+ return 1
417
+ }
418
+
419
+ # gh_rest_board_base <owner-type> <owner> <number> — the endpoint prefix; rc 3 with an owner or
420
+ # number missing or malformed.
421
+ gh_rest_board_base() {
422
+ local otype="${1:-user}" owner="${2:-}" num="${3:-}"
423
+ case "$owner" in ''|*[!A-Za-z0-9-]*) return 3 ;; esac
424
+ case "$num" in ''|*[!0-9]*) return 3 ;; esac
425
+ case "$otype" in
426
+ org|organization) printf 'orgs/%s/projectsV2/%s' "$owner" "$num" ;;
427
+ *) printf 'users/%s/projectsV2/%s' "$owner" "$num" ;;
428
+ esac
429
+ }
430
+
431
+ gh_rest_board_project() {
432
+ _ghr_board "$1" --jq 'if (.node_id | type) == "string" then {id, node_id, number, title} | tojson else error("no project") end'
433
+ }
434
+
435
+ gh_rest_board_fields() {
436
+ _ghr_board "$1/fields" -X GET -f per_page=100 --jq '
437
+ if type != "array" then error("not a field list") else
438
+ [.[] | {id, node_id, name, data_type,
439
+ options: [(.options // [])[] | {id, name: (.name.raw? // .name)}],
440
+ iterations: [((.configuration.iterations // [])[]) | {id, title: (.title.raw? // .title), start_date}]}]
441
+ | tojson end'
442
+ }
443
+
444
+ # gh_rest_board_ids_env <base> — the lines capture-project-ids.sh writes, over REST: PROJECT_ID (the
445
+ # project node id), <FIELD>_FIELD_ID (the field node id, which the GraphQL fallback needs too),
446
+ # <FIELD>_FIELD_NUM (the REST field id), <FIELD>_OPT_<OPTION> and <FIELD>_ITER_<TITLE>. Names are
447
+ # upper-cased, spaces and hyphens become underscores, anything else outside [A-Z0-9_] is dropped.
448
+ gh_rest_board_ids_env() {
449
+ local proj fields
450
+ proj="$(gh_rest_board_project "$1")" || return $?
451
+ fields="$(gh_rest_board_fields "$1")" || return $?
452
+ printf 'PROJECT_ID=%s\n' "$(printf '%s' "$proj" | jq -r .node_id)"
453
+ printf '%s' "$fields" | jq -r '
454
+ def n: ascii_upcase | gsub("[ -]"; "_") | gsub("[^A-Z0-9_]"; "");
455
+ .[] | select(.name != null) | (.name | n) as $f | select($f != "")
456
+ | "\($f)_FIELD_ID=\(.node_id // .id)", "\($f)_FIELD_NUM=\(.id)",
457
+ (.options[] | (.name | n) as $o | select($o != "") | "\($f)_OPT_\($o)=\(.id)"),
458
+ (.iterations[] | (.title | n) as $t | select($t != "") | "\($f)_ITER_\($t)=\(.id)")'
459
+ }
460
+
461
+ # gh_rest_board_find_item <base> <Issue|PullRequest> <repo> <n> — the issue's or PR's card on the
462
+ # board, as "<id>:<node_id>"; empty (rc 0) when it is not on it. REST has no content-side lookup, so
463
+ # this reads the board's items, 100 a page.
464
+ gh_rest_board_find_item() {
465
+ local base="$1" type="$2" repo="$3" n="$4" out
466
+ case "$type" in Issue|PullRequest) ;; *) return 3 ;; esac
467
+ case "$n" in ''|*[!0-9]*) return 3 ;; esac
468
+ case "$repo" in */*) ;; *) return 3 ;; esac
469
+ case "$repo" in *[!A-Za-z0-9._/-]*) return 3 ;; esac
470
+ out="$(_ghr_board "$base/items" -X GET -f per_page=100 --paginate --jq "
471
+ if type != \"array\" then error(\"not an item list\") else .[] end
472
+ | select(.content_type == \"$type\")
473
+ | select((.content.number // -1) == $n)
474
+ | select(((.content.repository.full_name // \"$repo\") | ascii_downcase) == (\"$repo\" | ascii_downcase))
475
+ | \"\(.id):\(.node_id // \"\")\"")" || return $?
476
+ printf '%s\n' "$out" | sed '/^$/d' | sed -n 1p
477
+ }
478
+
479
+ # gh_rest_board_find_issue_item <base> <repo> <n> — gh_rest_board_find_item for an issue.
480
+ gh_rest_board_find_issue_item() { gh_rest_board_find_item "$1" Issue "$2" "$3"; }
481
+
482
+ # gh_rest_board_add_item <base> <Issue|PullRequest> <repo> <n> — add an issue or PR; prints
483
+ # "<id>:<node_id>" of the new (or existing) item. REST answers 422 "Content already exists in this
484
+ # project" when the item is already on the board, where GraphQL's addProjectV2ItemById returned the
485
+ # existing item. A board with GitHub's auto-add workflow puts every new issue and PR on the board
486
+ # within seconds, so the 422 is the common case there (#590): the existing card is read back instead.
487
+ # rc 3 when it cannot be read, so the GraphQL fallback (idempotent) decides.
488
+ gh_rest_board_add_item() {
489
+ local base="$1" type="$2" repo="$3" n="$4" err out rc=0
490
+ case "$type" in Issue|PullRequest) ;; *) return 3 ;; esac
491
+ case "$n" in ''|*[!0-9]*) return 3 ;; esac
492
+ case "$repo" in */*) ;; *) return 3 ;; esac
493
+ err="$(mktemp)" || return 1
494
+ out="$(_ghr_board "$base/items" -X POST -f "type=$type" -f "owner=${repo%%/*}" -f "repo=${repo##*/}" -F "number=$n" \
495
+ --jq 'if (.id | type) == "number" then "\(.id):\(.node_id // "")" else error("no item id") end' 2>"$err")" || rc=$?
496
+ if [ "$rc" = 1 ] && grep -q 'GitHub answered 422 .*already exists' "$err"; then
497
+ rm -f "$err"
498
+ out="$(gh_rest_board_find_item "$base" "$type" "$repo" "$n" 2>/dev/null)" || return 3
499
+ [ -n "$out" ] || return 3
500
+ printf '%s\n' "$out"
501
+ return 0
502
+ fi
503
+ cat "$err" >&2; rm -f "$err"
504
+ [ "$rc" = 0 ] || return "$rc"
505
+ [ -n "$out" ] && printf '%s\n' "$out"
506
+ return 0
507
+ }
508
+
509
+ # gh_rest_board_set_field <base> <item id> <field> <kind> <value> — set one field of one item.
510
+ # <field> is the REST field id or its node id (the captured <FIELD>_FIELD_ID); <kind> is
511
+ # single_select (value = an option id), iteration (an iteration id) or text. The field is read
512
+ # first: a field, option or iteration REST does not list is rc 3, so the GraphQL fallback decides.
513
+ gh_rest_board_set_field() {
514
+ local base="$1" item="$2" field="$3" kind="$4" value="$5" fields fnum body
515
+ case "$item" in ''|*[!0-9]*) return 3 ;; esac
516
+ fields="$(gh_rest_board_fields "$base")" || return $?
517
+ fnum="$(printf '%s' "$fields" | jq -r --arg f "$field" --arg k "$kind" --arg v "$value" '
518
+ [.[] | select((.id | tostring) == $f or .node_id == $f)
519
+ | select(if $k == "single_select" then any(.options[]; .id == $v)
520
+ elif $k == "iteration" then any(.iterations[]; .id == $v)
521
+ else .data_type == "text" end)
522
+ | .id][0] // empty')"
523
+ case "$fnum" in ''|*[!0-9]*) return 3 ;; esac
524
+ body="$(jq -cn --argjson f "$fnum" --arg v "$value" '{fields: [{id: $f, value: $v}]}')"
525
+ printf '%s' "$body" | _ghr_board "$base/items/$item" -X PATCH --input - \
526
+ --jq 'if (.id | type) == "number" then .id else error("no item") end' >/dev/null
527
+ }
@@ -73,7 +73,7 @@ t "start with no slug: issue-<N>" "$(printf '%s' "$out2" | cut -d'|'
73
73
  echo two > "$wt/tracked.txt"
74
74
  out="$(cd "$wt" && kto_task_pr 7 "fix: do the thing" 2>"$tmp/err")"; rc=$?
75
75
  t "pr without a forge: rc 0" "$rc" "0"
76
- t "pr: the change is committed" "$(git -C "$wt" log -1 --format=%s)" "fix: do the thing"
76
+ t "pr: the change is committed" "$(git -C "$wt" log -1 --format=%s)" "fix: do the thing [#7]"
77
77
  t "pr: the branch is pushed" "$(git ls-remote --heads origin task/7-the-thing | wc -l | tr -d ' ')" "1"
78
78
  tc "$tmp/err" '^cckit pr: no forge — issue #7 is not read and the pull request is not opened' "pr: the one line says what it skipped"
79
79
  t "pr: says the pull request is to be opened by hand (origin is not on GitHub)" \
@@ -87,7 +87,7 @@ t "no compare page for a local origin" "$(forge_compare_url develop fix/1
87
87
  out="$(cd "$wt" && kto_task_pr_merge 2>"$tmp/err")"; rc=$?
88
88
  t "merge without a forge: rc 0" "$rc" "0"
89
89
  tc "$tmp/err" '^cckit merge: no forge — the branch lands on develop through git; no pull request is merged and no issue is closed' "merge: the one line says what it skipped"
90
- t "merge: develop on origin carries the squash commit" "$(git -C "$tmp/work" log -1 --format=%s origin/develop)" "fix: do the thing"
90
+ t "merge: develop on origin carries the squash commit" "$(git -C "$tmp/work" log -1 --format=%s origin/develop)" "fix: do the thing [#7]"
91
91
  t "merge: one commit landed (a squash)" "$(git -C "$tmp/work" rev-list --count origin/develop)" "2"
92
92
  t "merge: the worktree is removed" "$([ -d "$wt" ] && echo present || echo gone)" "gone"
93
93
  t "merge: the local branch is deleted" "$(git -C "$tmp/work" branch --list task/7-the-thing | wc -l | tr -d ' ')" "0"
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env bash
2
+ # grill-record-test.sh — the `## Grilling` record check (scripts/lib/grill-record.sh, E547.2): an
3
+ # accept/reject table, the reasons it prints, and grill_record_section. Hermetic, no network.
4
+ # errors: strict — a test runner: rc 1 on any failed assertion
5
+ set -u
6
+ LIB="$(cd "$(dirname "$0")" && pwd)"
7
+ fail=0
8
+ # shellcheck source=/dev/null
9
+ . "$LIB/grill-record.sh"
10
+
11
+ t() { if [ "$2" = "$3" ]; then echo "ok $1"; else echo "FAIL $1"; echo " got: [$2]"; echo " want: [$3]"; fail=1; fi; }
12
+ acc() { if grill_record_lint "$2" >/dev/null 2>&1; then echo "ok accepts: $1"; else echo "FAIL should accept: $1"; grill_record_lint "$2"; fail=1; fi; }
13
+ rej() { if grill_record_lint "$2" >/dev/null 2>&1; then echo "FAIL should reject: $1"; fail=1; else echo "ok rejects: $1"; fi; }
14
+ nl='
15
+ '
16
+ rec="Grilled: the maintainer, 2026-11-24, in session.${nl}1. One sprint is one week.${nl}2. Waves run inside a sprint.${nl}3. The advisor writes no code."
17
+
18
+ # --- accept ---
19
+ acc "three numbered decisions" "$rec"
20
+ acc "paren-numbered decisions" "Grilled: the owner, 2026-11-24.${nl}1) a${nl}2) b${nl}3) c"
21
+ acc "continuation lines indented" "$rec${nl} because it keeps the review weekly"
22
+ acc "a comment link holds them" "Grilled: the owner, 2026-11-24.${nl}Decisions: https://github.com/o/r/issues/12#issuecomment-345"
23
+ acc "an assumed record" "Grilled: the agent (assumed), 2026-11-24.${nl}1. a${nl}2. b${nl}3. c"
24
+ acc "a waiver" "waived: a one-line rename, nothing to decide"
25
+ acc "leading blank lines and CRLF" "${nl}${nl}Grilled: the owner, 2026-11-24.$(printf '\r')${nl}1. a${nl}2. b${nl}3. c"
26
+
27
+ # --- reject ---
28
+ rej "an empty record" ""
29
+ rej "no Grilled line" "2026-11-24${nl}1. a${nl}2. b${nl}3. c"
30
+ rej "Grilled names nobody" "Grilled:${nl}2026-11-24${nl}1. a${nl}2. b${nl}3. c"
31
+ rej "no date" "Grilled: the owner.${nl}1. a${nl}2. b${nl}3. c"
32
+ rej "two decisions" "Grilled: the owner, 2026-11-24.${nl}1. a${nl}2. b"
33
+ rej "indented items do not count" "Grilled: the owner, 2026-11-24.${nl} 1. a${nl} 2. b${nl} 3. c"
34
+ rej "an issue link is not a record" "Grilled: the owner, 2026-11-24.${nl}See https://github.com/o/r/issues/12"
35
+ rej "a waiver with no reason" "waived:"
36
+ rej "a waiver among other lines" "waived: x${nl}1. a"
37
+
38
+ # --- the reasons name what is missing ---
39
+ err="$(grill_record_lint "Grilled: the owner.${nl}1. a" 2>&1 >/dev/null)"
40
+ case "$err" in *"no YYYY-MM-DD date"*) echo "ok reason: missing date" ;; *) echo "FAIL reason: missing date — got: $err"; fail=1 ;; esac
41
+ case "$err" in *"1 decision(s)"*) echo "ok reason: counts the decisions" ;; *) echo "FAIL reason: decision count — got: $err"; fail=1 ;; esac
42
+ grill_record_lint >/dev/null 2>&1; t "no argument is a usage error" "$?" "2"
43
+ printf '%s\n' "$rec" | grill_record_lint - >/dev/null 2>&1; t "reads stdin with -" "$?" "0"
44
+
45
+ # --- the section builder ---
46
+ t "section: heading, blank, text, blank edges cut" \
47
+ "$(grill_record_section "${nl}${nl}waived: rename${nl}${nl}")" "## Grilling${nl}${nl}waived: rename"
48
+
49
+ exit "$fail"