@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,96 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # sprint-test.sh — `cckit effort sprint` (scripts/lib/sprint.sh, #570): the week arithmetic, and the
4
+ # milestone open / list / close over the forge shim (test-forge-shim.sh). Hermetic, no network.
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
+ set -u
7
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8
+ # shellcheck source=/dev/null
9
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
10
+ LIB="$ROOT/scripts/lib"
11
+ fail=0
12
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
13
+ tc() { if grep -qE "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in $1)"; fail=1; fi; }
14
+ tn() { if grep -qE "$2" "$1"; then echo "FAIL: $3 (found /$2/)"; fail=1; else echo "ok: $3"; fi; }
15
+ command -v jq >/dev/null 2>&1 || { echo "sprint-test: jq required" >&2; exit 1; }
16
+
17
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
18
+ export GH_LOG="$tmp/gh.log"; : > "$GH_LOG"
19
+ stub="$tmp/bin"
20
+ # shellcheck source=/dev/null
21
+ . "$LIB/test-forge-shim.sh"; forge_shim_install "$stub"
22
+ export PATH="$stub:$PATH" GH_TOKEN=test-token CCKIT_FORGE=github KIT_REPO=o/r
23
+ # The milestones and the sprint's issues, per test (MS_JSON / MS_ISSUES).
24
+ export GH_FIXTURE="$tmp/fixture.sh"
25
+ cat > "$GH_FIXTURE" <<'SH'
26
+ case "$method $ep" in
27
+ "GET repos/o/r/milestones") out="${MS_JSON:-[]}" ;;
28
+ "POST repos/o/r/milestones") out='{"number":12}' ;;
29
+ "PATCH repos/o/r/milestones/"*) out='{}' ;;
30
+ "GET repos/o/r/issues") case "$path" in *milestone=*) out="${MS_ISSUES:-[]}" ;; esac ;;
31
+ esac
32
+ SH
33
+ # shellcheck source=/dev/null
34
+ . "$LIB/sprint.sh"
35
+
36
+ # ── the week: ISO week name, Monday to Monday ─────────────────────────────────────────────────
37
+ t "a Tuesday names its ISO week" "$(sprint_name 2026-11-24)" "2026-W48"
38
+ t "a Sunday is still that week" "$(sprint_name 2026-11-29)" "2026-W48"
39
+ t "the next Monday starts the next one" "$(sprint_name 2026-11-30)" "2026-W49"
40
+ t "Jan 1st 2027 (a Friday) is 2026-W53" "$(sprint_name 2027-01-01)" "2026-W53"
41
+ t "bounds: Monday to the next Monday" "$(sprint_bounds 2026-11-24)" "$(printf '2026-11-23\t2026-11-30')"
42
+ t "bounds of a Monday start on it" "$(sprint_bounds 2026-11-30)" "$(printf '2026-11-30\t2026-12-07')"
43
+ t "bounds across a month" "$(sprint_bounds 2026-12-31)" "$(printf '2026-12-28\t2027-01-04')"
44
+ sprint_name 2026-13-45 >/dev/null 2>&1; t "a bad day is a usage error" "$?" "2"
45
+ sprint_name "next week" >/dev/null 2>&1; t "prose is a usage error" "$?" "2"
46
+ t "no date means today" "$(sprint_name)" "$(date '+%G-W%V')"
47
+
48
+ # ── open: create, keep, update the goal ───────────────────────────────────────────────────────
49
+ : > "$GH_LOG"
50
+ out="$(MS_JSON='[{"number":3,"title":"v1"}]' sprint_open --goal "ship the advisor" --date 2026-11-25 2>/dev/null)"
51
+ t "open prints the sprint name" "$out" "2026-W48"
52
+ tc "$GH_LOG" '^POST repos/o/r/milestones \{"title":"2026-W48","description":"Sprint goal: ship the advisor\\n\\nMonday 2026-11-23 to Monday 2026-11-30\.","due_on":"2026-11-30T00:00:00Z"\}' \
53
+ "open creates the milestone: title, goal, due the closing Monday"
54
+ : > "$GH_LOG"
55
+ MS_JSON='[{"number":12,"title":"2026-W48","state":"open"}]' sprint_open --date 2026-11-25 >/dev/null 2>&1
56
+ tn "$GH_LOG" '^(POST|PATCH) ' "open keeps an existing sprint and writes nothing"
57
+ : > "$GH_LOG"
58
+ MS_JSON='[{"number":12,"title":"2026-W48","state":"open"}]' sprint_open --goal "new goal" --date 2026-11-25 >/dev/null 2>&1
59
+ tc "$GH_LOG" '^PATCH repos/o/r/milestones/12 \{"description":"Sprint goal: new goal' "open --goal updates the goal of an existing sprint"
60
+ sprint_open --bogus >/dev/null 2>&1; t "open: an unknown flag is a usage error" "$?" "2"
61
+
62
+ # ── list: only sprint milestones ──────────────────────────────────────────────────────────────
63
+ out="$(MS_JSON='[{"title":"v1","state":"open","open_issues":1,"closed_issues":0},{"title":"2026-W48","state":"open","open_issues":2,"closed_issues":5,"due_on":"2026-11-30T00:00:00Z"}]' sprint_list)"
64
+ t "list: a header and the sprint rows only" "$out" "$(printf 'sprint\tstate\topen\tclosed\tdue\n2026-W48\topen\t2\t5\t2026-11-30')"
65
+ out="$(MS_JSON='[]' sprint_list)"
66
+ case "$out" in *"no open sprint"*"effort sprint open"*) echo "ok: list with none says how to open one" ;; *) echo "FAIL: empty list: $out"; fail=1 ;; esac
67
+
68
+ # ── close: the review + retrospective page, then the milestone ─────────────────────────────────
69
+ export MS_JSON='[{"number":12,"title":"2026-W48","state":"open","description":"Sprint goal: ship the advisor\n\nMonday 2026-11-23 to Monday 2026-11-30."}]'
70
+ export MS_ISSUES='[{"number":579,"title":"Advisor skill","state":"closed"},{"number":580,"title":"Grill stage","state":"closed"},{"number":586,"title":"Release","state":"open"},{"number":9,"title":"a PR","state":"closed","pull_request":{}}]'
71
+ : > "$GH_LOG"
72
+ page="$(sprint_close 2026-W48 --dry-run 2>/dev/null)"
73
+ case "$page" in *"## Sprint goal"*"ship the advisor"*"### Done (2)"*"#579 Advisor skill"*"### Carried over (1)"*"#586 Release"*"## Retrospective"*) echo "ok: close --dry-run prints goal, done, carried over and the retro" ;; *) echo "FAIL: dry-run page: $page"; fail=1 ;; esac
74
+ case "$page" in *"a PR"*) echo "FAIL: a pull request was listed as sprint work"; fail=1 ;; *) echo "ok: pull requests are not sprint items" ;; esac
75
+ tn "$GH_LOG" '^PATCH ' "close --dry-run closes nothing"
76
+ : > "$GH_LOG"
77
+ printf 'Shown: the advisor routing five stages.\n' > "$tmp/review.md"
78
+ path="$(sprint_close 2026-W48 --review-file "$tmp/review.md" --retro "Keep one commit per sub." --out "$tmp/out/sprint.md" 2>/dev/null)"; rc=$?
79
+ t "close succeeds" "$rc" "0"
80
+ t "close prints the page path" "$path" "$tmp/out/sprint.md"
81
+ tc "$tmp/out/sprint.md" '^Shown: the advisor routing five stages\.$' "close puts the review text on the page"
82
+ tc "$tmp/out/sprint.md" '^Keep one commit per sub\.$' "close puts the retrospective text on the page"
83
+ tc "$GH_LOG" '^PATCH repos/o/r/milestones/12 \{"state":"closed","description":"Sprint goal: ship the advisor.*## Review\\n2 done, 1 carried over\. Review and retrospective: sprint\.md"\}' \
84
+ "close closes the milestone and appends the one-line review"
85
+ sprint_close 2026-W99x >/dev/null 2>&1; t "close: a bad sprint name is a usage error" "$?" "2"
86
+ MS_JSON='[]' sprint_close 2026-W40 >/dev/null 2>&1; t "close: no such sprint is rc 1" "$?" "1"
87
+
88
+ # ── without a forge: the week still works, the milestone verbs refuse ─────────────────────────
89
+ t "name runs with no forge" "$(CCKIT_FORGE=none GH_TOKEN='' sprint_name 2026-11-24)" "2026-W48"
90
+ CCKIT_FORGE=none GH_TOKEN='' sprint_open >/dev/null 2>&1; t "open refuses with no forge" "$?" "1"
91
+
92
+ # ── the dispatcher ────────────────────────────────────────────────────────────────────────────
93
+ t "cckit effort sprint name" "$(bash "$ROOT/bin/cckit" effort sprint name 2026-11-24 2>/dev/null)" "2026-W48"
94
+ bash "$ROOT/bin/cckit" effort sprint bogus >/dev/null 2>&1; t "an unknown sprint sub-verb is rc 2" "$?" "2"
95
+
96
+ exit "$fail"
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # sprint.sh — `cckit effort sprint`: one week of work, Monday to Monday, as a forge milestone (#570,
4
+ # E547). The milestone's title is the ISO week (`2026-W48`), its description the sprint goal, its
5
+ # due date the Monday the sprint ends. The issues on it are the sprint backlog; waves run inside it.
6
+ # A sub-verb of `effort`, not a top-level verb: the verb count may only go down (scripts/verbs.baseline).
7
+ #
8
+ # sprint_name [YYYY-MM-DD] the sprint a day falls in (default today): 2026-W48
9
+ # sprint_bounds [YYYY-MM-DD] its Monday and the next Monday, tab-separated
10
+ # sprint_open [--goal G] [--date D] create the milestone; an existing one is kept (and its
11
+ # goal updated when --goal is given) — safe to re-run
12
+ # sprint_list [--all] the sprint milestones: title, state, open, closed, due
13
+ # sprint_close [<name>] [--review T|--review-file F] [--retro T|--retro-file F] [--out F] [--dry-run]
14
+ # write the sprint review + retrospective page, then close
15
+ # the milestone with a one-line review in its description
16
+ # sprint_cli <name|bounds|open|list|close> … the `cckit effort sprint` dispatcher
17
+ #
18
+ # Only `name` and `bounds` run on git alone; the rest read or write the forge (forge_rest).
19
+ # bash 3.2 compatible; GNU and BSD `date` both work.
20
+ # errors: mixed — name/bounds are pure; open/list/close propagate a forge failure (rc 1)
21
+
22
+ if ! command -v forge_rest >/dev/null 2>&1 && ! command -v gh_rest_issue_json >/dev/null 2>&1; then
23
+ # shellcheck source=/dev/null
24
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
25
+ fi
26
+
27
+ SPRINT_TITLE_RE='^[0-9]{4}-W[0-9]{2}$'
28
+
29
+ # _sprint_date <YYYY-MM-DD> <+%fmt> [<days to add>] — format a day, optionally shifted. GNU first,
30
+ # then BSD. rc 1 on a day neither understands.
31
+ _sprint_date() {
32
+ local d="$1" fmt="$2" add="${3:-0}" sign="+"
33
+ case "$add" in -*) sign="-"; add="${add#-}" ;; esac
34
+ case "$d" in [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) ;; *) return 1 ;; esac
35
+ date -d "$d $sign$add days" "$fmt" 2>/dev/null && return 0
36
+ date -j -v"$sign${add}d" -f '%Y-%m-%d' "$d" "$fmt" 2>/dev/null && return 0
37
+ return 1
38
+ }
39
+
40
+ _sprint_today() { date '+%Y-%m-%d'; }
41
+
42
+ sprint_bounds() {
43
+ local d="${1:-$(_sprint_today)}" dow start end
44
+ dow="$(_sprint_date "$d" '+%u')" || { echo "sprint: not a YYYY-MM-DD date: '$d'" >&2; return 2; }
45
+ start="$(_sprint_date "$d" '+%Y-%m-%d' "-$((dow - 1))")" || return 1
46
+ end="$(_sprint_date "$start" '+%Y-%m-%d' 7)" || return 1
47
+ printf '%s\t%s\n' "$start" "$end"
48
+ }
49
+
50
+ sprint_name() {
51
+ local d="${1:-$(_sprint_today)}"
52
+ _sprint_date "$d" '+%G-W%V' || { echo "sprint: not a YYYY-MM-DD date: '$d'" >&2; return 2; }
53
+ }
54
+
55
+ _sprint_repo() { printf '%s' "${KIT_REPO:-${EFFORT_REPO:-}}"; }
56
+ _sprint_need() {
57
+ forge_need "effort sprint" || return 1
58
+ command -v jq >/dev/null 2>&1 || { echo "effort sprint: jq is required" >&2; return 1; }
59
+ [ -n "$(_sprint_repo)" ] || { echo "effort sprint: no repository (github.repo unset)" >&2; return 1; }
60
+ }
61
+
62
+ # _sprint_milestone <title> — echo the milestone's JSON ({number,title,state,description,…}), or
63
+ # nothing when there is none. rc 1 when the read fails.
64
+ _sprint_milestone() {
65
+ forge_rest "repos/$(_sprint_repo)/milestones" -X GET -f state=all -f per_page=100 \
66
+ --jq ".[] | select(.title == \"$1\") | tojson" | sed -n 1p
67
+ }
68
+
69
+ _sprint_description() { # <goal> <start> <end>
70
+ printf 'Sprint goal: %s\n\nMonday %s to Monday %s.' "${1:-not set}" "$2" "$3"
71
+ }
72
+
73
+ sprint_open() {
74
+ local goal="" d="" name start end ms num desc
75
+ while [ $# -gt 0 ]; do
76
+ case "$1" in
77
+ --goal) goal="${2:-}"; shift 2 ;;
78
+ --date) d="${2:-}"; shift 2 ;;
79
+ *) echo "effort sprint open: unknown argument '$1'" >&2; return 2 ;;
80
+ esac
81
+ done
82
+ d="${d:-$(_sprint_today)}"
83
+ name="$(sprint_name "$d")" || return 2
84
+ IFS="$(printf '\t')" read -r start end <<EOF_B
85
+ $(sprint_bounds "$d")
86
+ EOF_B
87
+ _sprint_need || return 1
88
+ ms="$(_sprint_milestone "$name")" || { echo "effort sprint: could not read the milestones" >&2; return 1; }
89
+ desc="$(_sprint_description "$goal" "$start" "$end")"
90
+ if [ -n "$ms" ]; then
91
+ num="$(printf '%s' "$ms" | jq -r .number)"
92
+ if [ -n "$goal" ]; then
93
+ forge_rest "repos/$(_sprint_repo)/milestones/$num" -X PATCH -f "description=$desc" --silent \
94
+ || { echo "effort sprint: could not update the goal of $name" >&2; return 1; }
95
+ echo " ✓ sprint $name is open; goal updated" >&2
96
+ else
97
+ echo " ✓ sprint $name is already open (milestone $num)" >&2
98
+ fi
99
+ else
100
+ num="$(forge_rest "repos/$(_sprint_repo)/milestones" -X POST -f "title=$name" -f "description=$desc" \
101
+ -f "due_on=${end}T00:00:00Z" --jq .number)" || { echo "effort sprint: could not create $name" >&2; return 1; }
102
+ echo " ✓ sprint $name opened (milestone $num): Monday $start to Monday $end" >&2
103
+ fi
104
+ printf '%s\n' "$name"
105
+ }
106
+
107
+ sprint_list() {
108
+ local state=open
109
+ case "${1:-}" in --all) state=all ;; '') ;; *) echo "effort sprint list: unknown argument '$1'" >&2; return 2 ;; esac
110
+ _sprint_need || return 1
111
+ local rows
112
+ rows="$(forge_rest "repos/$(_sprint_repo)/milestones" -X GET -f "state=$state" -f per_page=100 \
113
+ --jq ".[] | select(.title | test(\"$SPRINT_TITLE_RE\")) | [.title, .state, (.open_issues|tostring), (.closed_issues|tostring), ((.due_on // \"-\") | .[0:10])] | @tsv")" \
114
+ || { echo "effort sprint: could not read the milestones" >&2; return 1; }
115
+ if [ -z "$rows" ]; then echo "no $state sprint — open one with: cckit effort sprint open --goal \"<goal>\""; return 0; fi
116
+ printf 'sprint\tstate\topen\tclosed\tdue\n%s\n' "$(printf '%s\n' "$rows" | sort)"
117
+ }
118
+
119
+ # _sprint_text <inline> <file> — the inline text, else the file's, else nothing.
120
+ _sprint_text() {
121
+ if [ -n "$1" ]; then printf '%s\n' "$1"; elif [ -n "$2" ]; then cat "$2"; fi
122
+ }
123
+
124
+ sprint_close() {
125
+ local name="" review="" review_f="" retro="" retro_f="" out="" dry=""
126
+ while [ $# -gt 0 ]; do
127
+ case "$1" in
128
+ --review) review="${2:-}"; shift 2 ;;
129
+ --review-file) review_f="${2:-}"; [ -r "$review_f" ] || { echo "effort sprint close: cannot read '$review_f'" >&2; return 2; }; shift 2 ;;
130
+ --retro) retro="${2:-}"; shift 2 ;;
131
+ --retro-file) retro_f="${2:-}"; [ -r "$retro_f" ] || { echo "effort sprint close: cannot read '$retro_f'" >&2; return 2; }; shift 2 ;;
132
+ --out) out="${2:-}"; shift 2 ;;
133
+ --dry-run) dry=1; shift ;;
134
+ -*) echo "effort sprint close: unknown flag '$1'" >&2; return 2 ;;
135
+ *) name="$1"; shift ;;
136
+ esac
137
+ done
138
+ name="${name:-$(sprint_name)}"
139
+ grep -qE "$SPRINT_TITLE_RE" <<<"$name" || { echo "effort sprint close: '$name' is not a sprint name (YYYY-Www)" >&2; return 2; }
140
+ _sprint_need || return 1
141
+ local ms num desc goal issues done_rows open_rows n_done n_open
142
+ ms="$(_sprint_milestone "$name")" || { echo "effort sprint: could not read the milestones" >&2; return 1; }
143
+ [ -n "$ms" ] || { echo "effort sprint close: no milestone named $name — nothing to close" >&2; return 1; }
144
+ num="$(printf '%s' "$ms" | jq -r .number)"
145
+ desc="$(printf '%s' "$ms" | jq -r '.description // ""')"
146
+ goal="$(printf '%s\n' "$desc" | sed -n 's/^Sprint goal:[[:space:]]*//p' | sed -n 1p)"
147
+ issues="$(forge_rest "repos/$(_sprint_repo)/issues" -X GET -f "milestone=$num" -f state=all -f per_page=100 \
148
+ --jq '[.[] | select(.pull_request | not) | {number, title, state}]')" || { echo "effort sprint: could not read the issues of $name" >&2; return 1; }
149
+ done_rows="$(printf '%s' "$issues" | jq -r '.[] | select(.state == "closed") | "- #\(.number) \(.title)"')"
150
+ open_rows="$(printf '%s' "$issues" | jq -r '.[] | select(.state != "closed") | "- #\(.number) \(.title)"')"
151
+ n_done="$(printf '%s' "$issues" | jq '[.[] | select(.state == "closed")] | length')"
152
+ n_open="$(printf '%s' "$issues" | jq '[.[] | select(.state != "closed")] | length')"
153
+
154
+ local page review_txt retro_txt
155
+ review_txt="$(_sprint_text "$review" "$review_f")"
156
+ retro_txt="$(_sprint_text "$retro" "$retro_f")"
157
+ page="$(cat <<EOF_PAGE
158
+ # Sprint $name · review and retrospective
159
+
160
+ ## Sprint goal
161
+ ${goal:-not set}
162
+
163
+ ## Sprint review
164
+ ${review_txt:-<!-- what was shown, what the owner said, what changes in the backlog -->}
165
+
166
+ ### Done ($n_done)
167
+ ${done_rows:-none}
168
+
169
+ ### Carried over ($n_open)
170
+ ${open_rows:-none}
171
+
172
+ ## Retrospective
173
+ ${retro_txt:-<!-- what went well · what to change · the one change the next sprint makes -->}
174
+ EOF_PAGE
175
+ )"
176
+ if [ -n "$dry" ]; then
177
+ printf '%s\n' "$page"
178
+ echo "effort sprint close: --dry-run — no file written, $name left open" >&2
179
+ return 0
180
+ fi
181
+ if [ -z "$out" ]; then
182
+ local root; root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
183
+ out="$root/.cckit/reports/$(date '+%Y-%m-%d')-sprint-$name.md"
184
+ fi
185
+ mkdir -p "$(dirname "$out")" || return 1
186
+ printf '%s\n' "$page" > "$out" || return 1
187
+ local line
188
+ line="$(printf '## Review\n%s done, %s carried over. Review and retrospective: %s' "$n_done" "$n_open" "$(basename "$out")")"
189
+ forge_rest "repos/$(_sprint_repo)/milestones/$num" -X PATCH -f state=closed -f "description=$desc
190
+
191
+ $line" --silent || { echo "effort sprint close: wrote $out but could not close milestone $num" >&2; return 1; }
192
+ echo " ✓ sprint $name closed: $n_done done, $n_open carried over" >&2
193
+ printf '%s\n' "$out"
194
+ }
195
+
196
+ sprint_cli() {
197
+ local sub="${1:-}"; shift || true
198
+ case "$sub" in
199
+ name) sprint_name "$@" ;;
200
+ bounds) sprint_bounds "$@" ;;
201
+ open) sprint_open "$@" ;;
202
+ list) sprint_list "$@" ;;
203
+ close) sprint_close "$@" ;;
204
+ ''|-h|--help)
205
+ cat <<'EOF_H'
206
+ cckit effort sprint name [YYYY-MM-DD] the sprint a day falls in (ISO week, Monday to Monday)
207
+ cckit effort sprint bounds [YYYY-MM-DD] its Monday and the next Monday
208
+ cckit effort sprint open [--goal G] [--date D] create the sprint milestone; re-running keeps it
209
+ cckit effort sprint list [--all] the sprint milestones with their open and closed counts
210
+ cckit effort sprint close [<YYYY-Www>] [--review T|--review-file F] [--retro T|--retro-file F] [--out F] [--dry-run]
211
+ write the review + retrospective page, close the milestone
212
+ EOF_H
213
+ [ -n "$sub" ] || return 2 ;;
214
+ *) echo "cckit effort sprint <name|bounds|open|list|close>" >&2; return 2 ;;
215
+ esac
216
+ }
@@ -10,9 +10,9 @@ command -v jq >/dev/null 2>&1 || { echo "stage-receipt-test: jq absent — skipp
10
10
  # Every receipt lands in a scratch dir, never the real .cckit/.
11
11
  KIT_STATE_DIR="$(mktemp -d)/state"; export KIT_STATE_DIR
12
12
 
13
- # The GitHub mirror (#333) is ON by default, and `gh` is authenticated on a developer machine — an
13
+ # The GitHub mirror (#333) is ON by default, and a forge token is usually at hand on a developer machine — an
14
14
  # unguarded `sr_cli` case here would post real comments to the real repo from the test suite. Off
15
- # for every case above; the mirror's own cases below stub `gh` and turn it back on explicitly.
15
+ # for every case above; the mirror's own cases below put the forge shim on PATH and turn it back on explicitly.
16
16
  CCKIT_RECEIPT_REMOTE=0; export CCKIT_RECEIPT_REMOTE
17
17
  # shellcheck source=/dev/null
18
18
  source "$ROOT/scripts/lib/stage-receipt.sh"
@@ -179,22 +179,28 @@ there="$(cd /tmp && KIT_STATE_DIR="$KIT_STATE_DIR" bash -c "source '$ROOT/script
179
179
  t "sr_dir is the same from another directory" "$there" "$here"
180
180
 
181
181
  # ── the GitHub mirror (#333) ───────────────────────────────────────────────────────────────────
182
- # `gh` is stubbed on PATH: it logs every invocation and serves a canned comment list, so the upsert
183
- # is exercised end to end with no network and no real repo touched.
182
+ # The forge shim (test-forge-shim.sh) stands in for GitHub: its curl logs every request as
183
+ # `METHOD path {json}` and a fixture serves the canned comment list from $GH_COMMENTS (one
184
+ # `<id><TAB><json body>` line per comment), so the upsert is exercised end to end with no network and
185
+ # no real repo touched. GH_RC=1 makes every request fail (502).
184
186
  ghtmp="$(mktemp -d)"; mkdir -p "$ghtmp/bin"
185
- export GH_LOG="$ghtmp/gh.log"; export GH_COMMENTS="$ghtmp/comments.txt"
187
+ # shellcheck source=/dev/null
188
+ . "$ROOT/scripts/lib/test-forge-shim.sh"; forge_shim_install "$ghtmp/bin"
189
+ export GH_LOG="$ghtmp/gh.log"; export GH_COMMENTS="$ghtmp/comments.txt"; export GH_FIXTURE="$ghtmp/fixture"
190
+ export GH_TOKEN=test-token CCKIT_FORGE=github SR_REPO=o/r
186
191
  : > "$GH_LOG"; : > "$GH_COMMENTS"
187
- cat > "$ghtmp/bin/gh" <<'SH'
188
- #!/usr/bin/env bash
189
- echo "$*" >> "$GH_LOG"
190
- case "$*" in
191
- *"issues/"*"/comments"*) cat "$GH_COMMENTS" ;; # the listing (--jq is applied by the real gh)
192
- *) : ;;
193
- esac
194
- exit "${GH_RC:-0}"
195
- SH
196
- chmod +x "$ghtmp/bin/gh"
192
+ cat > "$GH_FIXTURE" <<'FIX'
193
+ if [ "${GH_RC:-0}" != 0 ]; then code=502; out='{"message":"Server Error"}'
194
+ else
195
+ case "$method $ep" in
196
+ "GET repos/o/r/issues/"*"/comments")
197
+ out="$(jq -R 'split("\t") | {id: (.[0] | tonumber), body: (.[1] | fromjson)}' "$GH_COMMENTS" | jq -sc .)" ;;
198
+ "PATCH repos/o/r/issues/comments/"*) out="{\"id\":${ep##*/}}" ;;
199
+ esac
200
+ fi
201
+ FIX
197
202
  OLDPATH="$PATH"; PATH="$ghtmp/bin:$PATH"; export PATH
203
+ CREATE='^POST repos/o/r/issues/42/comments '
198
204
 
199
205
  # ── pure: the marker is the identity, and it is per ATTEMPT ────────────────────────────────────
200
206
  t "the marker keys on issue, stage and attempt" \
@@ -215,21 +221,31 @@ printf '%s\n' "$REPORT" | CCKIT_RECEIPT_REMOTE=0 sr_cli 42 --stage build --attem
215
221
  # ── a first mirror CREATES ─────────────────────────────────────────────────────────────────────
216
222
  CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 >/dev/null 2>&1
217
223
  t "a first mirror creates" "$SR_MIRROR_LAST_RESULT" "created"
218
- yes "and it commented on the issue" "$(cat "$GH_LOG")" "issue comment 42"
224
+ yes "and it commented on the issue" "$(cat "$GH_LOG")" "POST repos/o/r/issues/42/comments "
225
+ yes "the comment carries the marker" "$(cat "$GH_LOG")" "cckit:receipt key=42-build-1"
226
+ t "the lookup read the issue's comments over REST" "$(grep -c '^GET repos/o/r/issues/42/comments' "$GH_LOG")" "1"
219
227
 
220
228
  # ── the same attempt again EDITS the one comment, it does not append a second ──────────────────
221
229
  printf '%s\t%s\n' 777 '"<!-- cckit:receipt key=42-build-1 --> already here"' > "$GH_COMMENTS"
222
230
  : > "$GH_LOG"
223
231
  CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 >/dev/null 2>&1
224
232
  t "a second identical run edits" "$SR_MIRROR_LAST_RESULT" "updated"
225
- yes "and it PATCHed the existing comment" "$(cat "$GH_LOG")" "issues/comments/777"
226
- t "it did not also create one" "$(grep -c 'issue comment' "$GH_LOG" || true)" "0"
233
+ yes "and it PATCHed the existing comment" "$(cat "$GH_LOG")" "PATCH repos/o/r/issues/comments/777 "
234
+ t "it did not also create one" "$(grep -c "$CREATE" "$GH_LOG" || true)" "0"
227
235
 
228
236
  # ── a FAILED lookup must not post: a blind post is how a duplicate appears ─────────────────────
229
237
  : > "$GH_LOG"
230
238
  GH_RC=1 CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 >/dev/null 2>&1
231
239
  t "a failed lookup does not post" "$SR_MIRROR_LAST_RESULT" "lookup-failed"
232
- t "and nothing was created" "$(grep -c 'issue comment' "$GH_LOG" || true)" "0"
240
+ t "and nothing was created" "$(grep -c "$CREATE" "$GH_LOG" || true)" "0"
241
+
242
+ # ── no forge configured: the receipt stays local, the result says so, nothing is asked ─────────
243
+ : > "$GH_LOG"
244
+ ( unset _FORGE_LOADED; CCKIT_FORGE=none CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 >/dev/null 2>&1 ); t "no forge exits 0" "$?" "0"
245
+ noforge="$(unset _FORGE_LOADED; CCKIT_FORGE=none CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 2>&1 >/dev/null; printf '|%s' "$SR_MIRROR_LAST_RESULT")"
246
+ t "no forge is the recorded result" "${noforge##*|}" "no-forge"
247
+ yes "no forge says the receipt stayed local" "$noforge" "no forge is configured — receipt written locally only"
248
+ t "no forge makes no request" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
233
249
 
234
250
  # ── an unreachable GitHub still leaves the local file, and exits 0 ─────────────────────────────
235
251
  GH_RC=1 CCKIT_RECEIPT_REMOTE=1 sr_mirror 42 build 1 >/dev/null 2>&1
@@ -256,10 +272,144 @@ yes "the body carries its marker" "$body" "<!-- cckit:receipt key=42-build-1 -
256
272
  yes "the body names the stage" "$body" 'stage `build`'
257
273
  yes "the body embeds the JSON" "$body" '"outcome": "pr-open"'
258
274
 
275
+ t "no gh subcommand ran in the mirror cases" "$(grep -c '^GH-SUBCOMMAND' "$GH_LOG")" "0"
259
276
  PATH="$OLDPATH"; export PATH
277
+ unset GH_FIXTURE SR_REPO
260
278
  rm -rf "$ghtmp"
261
279
 
262
280
 
281
+ # ── the agent trail (#572): a step report becomes one short comment on its issue ───────────────
282
+ # The forge shim records every request with its JSON body. Synthetic leak words only: the real
283
+ # list is private and never appears in a test.
284
+ trtmp="$(mktemp -d)"; mkdir -p "$trtmp/bin"
285
+ forge_shim_install "$trtmp/bin"
286
+ export GH_LOG="$trtmp/gh.log" GH_COMMENTS="$trtmp/comments.txt" GH_FIXTURE="$trtmp/fixture"
287
+ export GH_TOKEN=test-token CCKIT_FORGE=github SR_REPO=o/r
288
+ printf 'zorblaxian\n# a comment line\nquuxcorp\n' > "$trtmp/leak-words"
289
+ CCKIT_LEAK_WORDS_FILE="$trtmp/leak-words"; export CCKIT_LEAK_WORDS_FILE; unset CCKIT_LEAK_WORDS
290
+ : > "$GH_LOG"; : > "$GH_COMMENTS"
291
+ cat > "$GH_FIXTURE" <<'FIX'
292
+ case "$method $ep" in
293
+ "GET repos/o/r/issues/"*"/comments")
294
+ out="$(jq -R 'split("\t") | {id: (.[0] | tonumber), body: (.[1] | fromjson)}' "$GH_COMMENTS" | jq -sc .)" ;;
295
+ "PATCH repos/o/r/issues/comments/"*) out="{\"id\":${ep##*/}}" ;;
296
+ esac
297
+ FIX
298
+ PATH="$trtmp/bin:$OLDPATH"; export PATH
299
+ # The suite keeps CCKIT_RECEIPT_REMOTE=0 so nothing else can post; the trail cases turn it on over
300
+ # the shim, and one case checks that off means not posted.
301
+ CCKIT_RECEIPT_REMOTE=1; export CCKIT_RECEIPT_REMOTE
302
+ TRAIL_POST='^POST repos/o/r/issues/77/comments '
303
+
304
+ REP="$trtmp/2026-11-24-1200-build-77.md"
305
+ cat > "$REP" <<'EOF'
306
+ # Build 77
307
+
308
+ ## Status
309
+ Built and gated; PR open.
310
+ Second status line.
311
+
312
+ ## Done
313
+ - one commit, see https://github.com/o/r/pull/12.
314
+ - the issue https://github.com/o/r/issues/77
315
+
316
+ ## Waiting for a yes
317
+ - merge the PR
318
+
319
+ ## Numbers
320
+ check.sh 120 passed
321
+
322
+ ## Next step
323
+ review
324
+ EOF
325
+
326
+ out="$(CCKIT_RECEIPT_REMOTE=0 sr_cli 77 --report "$REP" 2>&1)"
327
+ yes "CCKIT_RECEIPT_REMOTE=0 says the comment was not posted" "$out" "the comment was NOT posted to #77"
328
+ t "CCKIT_RECEIPT_REMOTE=0 makes no request" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
329
+
330
+ out="$(sr_cli 77 --report "$REP" 2>&1)"; rc=$?
331
+ t "a report posts with rc 0" "$rc" "0"
332
+ yes "the verb says it posted" "$out" "trail comment posted on #77"
333
+ posted="$(grep "$TRAIL_POST" "$GH_LOG")"
334
+ t "exactly one comment was posted" "$(printf '%s\n' "$posted" | grep -c .)" "1"
335
+ yes "the comment carries the Status head" "$posted" "Built and gated; PR open."
336
+ yes "the comment carries the PR URL, trailing dot dropped" "$posted" "- https://github.com/o/r/pull/12\\n"
337
+ yes "the comment carries the issue URL" "$posted" "https://github.com/o/r/issues/77"
338
+ yes "the comment carries the waiting items" "$posted" "- merge the PR"
339
+ yes "the comment names the report file" "$posted" 'Full report: `2026-11-24-1200-build-77.md`'
340
+ yes "the comment carries its trail marker" "$posted" "cckit:trail report=2026-11-24-1200-build-77.md"
341
+ case "$posted" in *"check.sh 120 passed"*) t "the Numbers section stays in the full report" "present" "absent" ;;
342
+ *) t "the Numbers section stays in the full report" "absent" "absent" ;; esac
343
+ case "$posted" in *"$trtmp"*) t "no absolute path reaches the comment" "present" "absent" ;;
344
+ *) t "no absolute path reaches the comment" "absent" "absent" ;; esac
345
+
346
+ # The same report again edits its comment instead of appending a second.
347
+ printf '%s\t%s\n' 901 '"<!-- cckit:trail report=2026-11-24-1200-build-77.md --> earlier"' > "$GH_COMMENTS"
348
+ : > "$GH_LOG"
349
+ yes "a second post of one report edits" "$(sr_cli 77 --report "$REP" 2>&1)" "updated"
350
+ yes "and it PATCHed the existing comment" "$(cat "$GH_LOG")" "PATCH repos/o/r/issues/comments/901 "
351
+ t "it did not also create one" "$(grep -c "$TRAIL_POST" "$GH_LOG" || true)" "0"
352
+ : > "$GH_COMMENTS"
353
+
354
+ # No waiting items reads "none".
355
+ NOW="$trtmp/no-wait.md"; printf '## Status\nAll done.\n\n## Done\n- x\n' > "$NOW"
356
+ yes "no Waiting section reads none" "$(sr_cli 77 --report "$NOW" --dry-run 2>/dev/null)" "$(printf '**Waiting for a yes**\nnone')"
357
+
358
+ # Truncation: a long report is cut to the cap, says so, and still names the file last.
359
+ LONG="$trtmp/long.md"
360
+ { printf '## Status\nlong one\n\n## Waiting for a yes\n'; i=0; while [ "$i" -lt 80 ]; do printf -- '- decision number %s needs an answer from the owner\n' "$i"; i=$((i+1)); done; } > "$LONG"
361
+ long="$(sr_cli 77 --report "$LONG" --dry-run 2>/dev/null)"
362
+ t "a long comment stays within the cap" "$([ "${#long}" -le 1500 ] && echo yes || echo "no (${#long})")" "yes"
363
+ yes "a cut comment says it was truncated" "$long" "Truncated to 1500 characters"
364
+ t "a cut comment's last line names the file" "$(printf '%s\n' "$long" | tail -n 1)" 'Full report: `long.md` (local, not on GitHub)'
365
+
366
+ # A leak-list word refuses the whole comment, posts nothing, and does not echo the word.
367
+ LEAK="$trtmp/leak.md"; printf '## Status\nShipped the QuuxCorp import.\n' > "$LEAK"
368
+ : > "$GH_LOG"
369
+ out="$(sr_cli 77 --report "$LEAK" 2>&1)"; rc=$?
370
+ t "a leak word is refused with rc 1" "$rc" "1"
371
+ yes "the refusal names the leak list" "$out" "private leak list"
372
+ case "$out" in *[Qq]uux[Cc]orp*) t "the refusal does not echo the word" "echoed" "hidden" ;;
373
+ *) t "the refusal does not echo the word" "hidden" "hidden" ;; esac
374
+ t "a refused comment posts nothing" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
375
+ sr_cli 77 --report "$LEAK" --dry-run >/dev/null 2>&1; t "dry run refuses a leak word too" "$?" "1"
376
+
377
+ # An absolute home path is refused the same way.
378
+ HOMEP="$trtmp/home.md"; printf '## Status\nlog at /Users/alice/work/log.txt\n' > "$HOMEP"
379
+ out="$(sr_cli 77 --report "$HOMEP" 2>&1)"; rc=$?
380
+ t "a home path is refused with rc 1" "$rc" "1"
381
+ yes "the refusal names the home path" "$out" "absolute home path"
382
+ t "a home-path comment posts nothing" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
383
+
384
+ # --dry-run prints and writes nothing.
385
+ : > "$GH_LOG"
386
+ dry="$(sr_cli 77 --report "$REP" --dry-run 2>/dev/null)"; rc=$?
387
+ t "dry run exits 0" "$rc" "0"
388
+ yes "dry run prints the comment" "$dry" "Built and gated; PR open."
389
+ t "dry run makes no request" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
390
+
391
+ # No forge: the comment is not posted, the verb says so and prints it.
392
+ : > "$GH_LOG"
393
+ out="$(unset _FORGE_LOADED; CCKIT_FORGE=none sr_cli 77 --report "$REP" 2>&1)"; rc=$?
394
+ t "no forge exits 0" "$rc" "0"
395
+ yes "no forge says the comment was not posted" "$out" "the comment was NOT posted to #77"
396
+ yes "no forge still prints the comment" "$out" "Built and gated; PR open."
397
+ t "no forge makes no request" "$(wc -l < "$GH_LOG" | tr -d ' ')" "0"
398
+
399
+ # Usage errors.
400
+ NOST="$trtmp/nostatus.md"; printf '## Done\n- x\n' > "$NOST"
401
+ sr_cli 77 --report "$NOST" --dry-run >/dev/null 2>&1; t "a report with no Status is refused" "$?" "2"
402
+ sr_cli 77 --report "$trtmp/missing.md" >/dev/null 2>&1; t "a missing report is refused" "$?" "2"
403
+ sr_cli 77 --report </dev/null >/dev/null 2>&1; t "--report with no file is refused" "$?" "2"
404
+ sr_cli 77 --stage build --dry-run </dev/null >/dev/null 2>&1; t "--dry-run without --report is refused" "$?" "2"
405
+ yes "the help names the trail mode" "$(sr_cli --help 2>&1)" "--report <file> [--dry-run]"
406
+
407
+ t "no gh subcommand ran in the trail cases" "$(grep -c '^GH-SUBCOMMAND' "$GH_LOG" || true)" "0"
408
+ PATH="$OLDPATH"; export PATH
409
+ unset GH_FIXTURE SR_REPO CCKIT_LEAK_WORDS_FILE
410
+ CCKIT_RECEIPT_REMOTE=0; export CCKIT_RECEIPT_REMOTE
411
+ rm -rf "$trtmp"
412
+
263
413
  rm -rf "$(dirname "$KIT_STATE_DIR")"
264
414
  [ "$fail" -eq 0 ] && echo "ALL OK" || echo "stage receipt: FAILURES"
265
415
  exit "$fail"