@jeiemgi/cckit 0.1.8 → 0.2.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.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bash
2
+ # next.sh — "what can I pick up right now?" The everyday-dev helper (Effort 75 · #79).
3
+ #
4
+ # Surfaces the unblocked set (wave 0 of the plan machine) and the single recommended next issue with
5
+ # the one command to start it. This is the daily-loop counterpart to the copilot: the copilot fans a
6
+ # whole wave out to subagents; `cckit next` is for a human (or agent) picking up one issue by hand.
7
+ #
8
+ # cckit next the unblocked issues + the top one's start command
9
+ # cckit next --effort <N> scope to effort #N's sub-issues
10
+ # cckit next --llm the unblocked set as TOON rows {number,ctx,title}
11
+ #
12
+ # Requires gh + jq (via the plan machine). bash 3.2 / zsh compatible.
13
+
14
+ NEXT_REPO="${NEXT_REPO:-${KIT_REPO:-}}"
15
+
16
+ next_issue() {
17
+ command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || { echo "next: needs gh + jq" >&2; return 1; }
18
+ local repo="$NEXT_REPO" out="${CCKIT_OUTPUT:-human}" effort="" planargs=()
19
+ while [ "$#" -gt 0 ]; do
20
+ case "$1" in
21
+ --llm|--output=json) out="json"; shift ;;
22
+ --effort) effort="$2"; planargs+=(--effort "$2"); shift 2 ;;
23
+ --effort=*) effort="${1#*=}"; planargs+=(--effort "${1#*=}"); shift ;;
24
+ -h|--help) sed -n '10,13p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; return 0 ;;
25
+ *) echo "next: unknown arg '$1'" >&2; return 2 ;;
26
+ esac
27
+ done
28
+ [ -n "$repo" ] || { echo "next: no repo (set KIT_REPO / NEXT_REPO)" >&2; return 1; }
29
+
30
+ local here; here="$(dirname "${BASH_SOURCE[0]}")"
31
+ # shellcheck source=/dev/null
32
+ . "$here/plan-machine.sh"
33
+ local rows wave0
34
+ rows="$(CCKIT_OUTPUT=tsv plan_machine "${planargs[@]+"${planargs[@]}"}" 2>/dev/null)"
35
+ wave0="$(printf '%s\n' "$rows" | awk -F'\t' '$1==0')"
36
+ if [ -z "$wave0" ]; then
37
+ [ "$out" = "json" ] && echo "[]" || echo "next: nothing unblocked — the board is blocked or empty."
38
+ return 0
39
+ fi
40
+
41
+ if [ "$out" = "json" ]; then
42
+ local json
43
+ json="$(printf '%s\n' "$wave0" | awk -F'\t' '{
44
+ t=$6; sub(/^\[Effort( [0-9]+)?\] [0-9]+ · ?/,"",t); sub(/^\[[A-Za-z]+\] /,"",t)
45
+ print $3"\t"$4"\t"t
46
+ }' \
47
+ | jq -R -s '[ split("\n")[] | select(length>0) | split("\t")
48
+ | {number:(.[0]|tonumber), ctx:.[1], title:.[2]} ]')"
49
+ # shellcheck source=/dev/null
50
+ . "$here/toon.sh"
51
+ printf '%s' "$json" | toon_encode
52
+ return 0
53
+ fi
54
+
55
+ # human: the unblocked table + the top issue's start command, through the rendering seam.
56
+ # shellcheck source=/dev/null
57
+ . "$here/render.sh"
58
+ local top topnum toptitle
59
+ top="$(printf '%s\n' "$wave0" | head -1)"
60
+ topnum="$(printf '%s' "$top" | cut -f3)"
61
+ toptitle="$(printf '%s' "$top" | cut -f6 | sed -E 's/^\[Effort( [0-9]+)?\] [0-9]+ · ?//; s/^\[[A-Za-z]+\] //')"
62
+ {
63
+ printf '# Next up — %s%s\n\n' "$repo" "$([ -n "$effort" ] && echo " · effort #$effort")"
64
+ printf '## Unblocked now\n\n'
65
+ printf '| # | ctx | issue |\n|---|-----|-------|\n'
66
+ printf '%s\n' "$wave0" | awk -F'\t' '{
67
+ t=$6; sub(/^\[Effort( [0-9]+)?\] [0-9]+ · ?/,"",t); sub(/^\[[A-Za-z]+\] /,"",t)
68
+ printf "| #%s | %s | %s |\n", $3, $4, t
69
+ }'
70
+ printf '\n## Pick up #%s — %s\n\n' "$topnum" "$toptitle"
71
+ printf 'Start it in an isolated worktree + branch:\n\n'
72
+ printf '```\ncckit start %s\n```\n\n' "$topnum"
73
+ printf 'Or fan the whole unblocked wave out to subagents with `cckit copilot%s`.\n' "$([ -n "$effort" ] && echo " --effort $effort")"
74
+ } | cckit_render
75
+ }
@@ -0,0 +1,72 @@
1
+ #!/bin/sh
2
+ # plan-machine-test.sh — self-test for plan-machine.sh pure helpers under bash AND zsh.
3
+ # Network-free: covers the wave layering, session/file packer, and file-hint parser only
4
+ # (the gh-calling plan_machine orchestration is not exercised).
5
+ # Run: bash scripts/lib/plan-machine-test.sh
6
+
7
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
8
+ TAB=$(printf '\t')
9
+
10
+ if [ -n "${PM_TEST_INNER:-}" ]; then
11
+ . "$dir/plan-machine.sh"
12
+ fail=0
13
+ eq() { # <label> <got> <want>
14
+ if [ "$2" != "$3" ]; then echo "FAIL($PM_TEST_INNER): $1 -> '[$2]', want '[$3]'"; fail=1; fi
15
+ }
16
+
17
+ # _pm_weight
18
+ eq "weight S" "$(_pm_weight S)" "1"
19
+ eq "weight XL" "$(_pm_weight XL)" "8"
20
+ eq "weight ?" "$(_pm_weight '')" "2"
21
+
22
+ # pm_waves: linear chain 3<-2<-1 (1 blocks 2 blocks 3) -> waves 0,1,2.
23
+ chain="$(printf '1\t\n2\t1\n3\t2\n' | pm_waves)"
24
+ eq "chain wave of 1" "$(printf '%s\n' "$chain" | awk -F"$TAB" '$1==1{print $2}')" "0"
25
+ eq "chain wave of 2" "$(printf '%s\n' "$chain" | awk -F"$TAB" '$1==2{print $2}')" "1"
26
+ eq "chain wave of 3" "$(printf '%s\n' "$chain" | awk -F"$TAB" '$1==3{print $2}')" "2"
27
+
28
+ # pm_waves: diamond 1 -> {2,3} -> 4. 2 and 3 share wave 1; 4 in wave 2.
29
+ dia="$(printf '1\t\n2\t1\n3\t1\n4\t2,3\n' | pm_waves)"
30
+ eq "diamond 2==3 wave" \
31
+ "$(printf '%s\n' "$dia" | awk -F"$TAB" '$1==2{print $2}')$(printf '%s\n' "$dia" | awk -F"$TAB" '$1==3{print $2}')" "11"
32
+ eq "diamond wave of 4" "$(printf '%s\n' "$dia" | awk -F"$TAB" '$1==4{print $2}')" "2"
33
+
34
+ # pm_waves: out-of-set blocker (99 absent) is ignored -> node 5 still wave 0.
35
+ oos="$(printf '5\t99\n' | pm_waves)"
36
+ eq "out-of-set blocker ignored" "$(printf '%s\n' "$oos" | awk -F"$TAB" '$1==5{print $2}')" "0"
37
+
38
+ # pm_waves: cycle (1<-2, 2<-1) must terminate, both land in the final wave (no hang, no drop).
39
+ cyc="$(printf '1\t2\n2\t1\n' | pm_waves | wc -l | tr -d ' ')"
40
+ eq "cycle emits both rows" "$cyc" "2"
41
+
42
+ # pm_batches: budget 4, three M(=2) issues with no file hints -> 2,2 then overflow -> batches 0,0,1.
43
+ pk="$(printf '1\tM\t\n2\tM\t\n3\tM\t\n' | pm_batches 4)"
44
+ eq "pack 1 batch0" "$(printf '%s\n' "$pk" | awk -F"$TAB" '$1==1{print $2}')" "0"
45
+ eq "pack 2 batch0" "$(printf '%s\n' "$pk" | awk -F"$TAB" '$1==2{print $2}')" "0"
46
+ eq "pack 3 batch1" "$(printf '%s\n' "$pk" | awk -F"$TAB" '$1==3{print $2}')" "1"
47
+
48
+ # pm_batches: file overlap forces a new batch even under budget.
49
+ fo="$(printf '1\tS\ta.sh\n2\tS\ta.sh\n' | pm_batches 8)"
50
+ eq "overlap splits batch" "$(printf '%s\n' "$fo" | awk -F"$TAB" '$1==2{print $2}')" "1"
51
+ # disjoint files stay in one batch under budget.
52
+ dj="$(printf '1\tS\ta.sh\n2\tS\tb.sh\n' | pm_batches 8)"
53
+ eq "disjoint same batch" "$(printf '%s\n' "$dj" | awk -F"$TAB" '$1==2{print $2}')" "0"
54
+
55
+ # _pm_files: pulls a Files:/Touches: line, normalizes separators.
56
+ eq "files hint comma" "$(_pm_files 'intro
57
+ Files: a.sh, b.sh
58
+ tail')" "a.sh b.sh"
59
+ eq "touches hint" "$(_pm_files 'Touches: x/y.ts')" "x/y.ts"
60
+ eq "no hint" "$(_pm_files 'just prose, no files')" ""
61
+
62
+ if [ "$fail" -eq 0 ]; then echo "PASS($PM_TEST_INNER): plan-machine helpers"; fi
63
+ exit "$fail"
64
+ fi
65
+
66
+ # Outer: re-run under each available shell.
67
+ rc=0
68
+ for sh in bash zsh; do
69
+ command -v "$sh" >/dev/null 2>&1 || continue
70
+ PM_TEST_INNER="$sh" "$sh" "$0" || rc=1
71
+ done
72
+ exit "$rc"
@@ -0,0 +1,260 @@
1
+ #!/usr/bin/env bash
2
+ # plan-machine.sh — the wave plan: turn the board into a deps-ordered, file-disjoint, session-fit
3
+ # execution plan the copilot fans out over (Effort 75 · #76).
4
+ #
5
+ # `cckit plan` reads the open board (or one effort's sub-issues), resolves the native GitHub
6
+ # `blocked_by` edges, and layers the issues into WAVES: wave 0 is everything unblocked, wave N is
7
+ # everything whose blockers all landed in earlier waves. Every issue in a wave is independent of the
8
+ # others in that wave, so a wave is exactly "what N agents can run in parallel right now". Within a
9
+ # wave we pack issues into BATCHES under a session ctx budget, starting a new batch when the budget
10
+ # would overflow or two issues declare overlapping files (so parallel subagents don't collide).
11
+ #
12
+ # cckit plan human wave plan for the open board
13
+ # cckit plan --llm TOON wave plan (uniform rows: wave,batch,number,ctx,blockers,title)
14
+ # cckit plan --effort <N> plan only effort #N's sub-issues
15
+ # cckit plan --milestone <M> filter to milestone M
16
+ # cckit plan --cap <N> session ctx budget per batch (default KIT_SESSION_BUDGET or 4)
17
+ #
18
+ # ctx weights: S=1 · M=2 · L=4 · XL=8. File hints: a "Files:"/"Touches:" line in the issue body
19
+ # (comma/space-separated paths) drives intra-wave disjointness; absent → ctx budget alone batches.
20
+ #
21
+ # Requires: gh, jq. bash 3.2 (no associative arrays — parallel indexed arrays + linear scan; N small).
22
+
23
+ PLAN_REPO="${PLAN_REPO:-${KIT_REPO:-}}"
24
+
25
+ _pm_weight() { case "$1" in S) echo 1 ;; M) echo 2 ;; L) echo 4 ;; XL) echo 8 ;; *) echo 2 ;; esac; }
26
+
27
+ # pm_waves — pure layered topo-sort. stdin: lines "num<TAB>csvBlockers"; stdout: "num<TAB>wave".
28
+ # Only blockers present in the input set constrain layering (out-of-set/closed blockers are the
29
+ # caller's concern). Cycle-safe: any leftover after no-progress lands in a final wave.
30
+ pm_waves() {
31
+ # dual-shell arrays: ksh_arrays gives zsh 0-based indexing + bash-style subscripting.
32
+ [ -n "${ZSH_VERSION:-}" ] && setopt local_options ksh_arrays sh_word_split 2>/dev/null
33
+ local -a N=() B=() W=()
34
+ local num blk
35
+ while IFS="$(printf '\t')" read -r num blk; do
36
+ [ -n "$num" ] || continue
37
+ N[${#N[@]}]="$num"; B[${#B[@]}]="$blk"; W[${#W[@]}]="-1"
38
+ done
39
+ local n="${#N[@]}" w=0 remaining="${#N[@]}" progress=1 i j b bl ok
40
+ [ "$remaining" -gt 0 ] || return 0
41
+ while [ "$remaining" -gt 0 ] && [ "$progress" -eq 1 ]; do
42
+ progress=0
43
+ local -a ready=()
44
+ i=0
45
+ while [ "$i" -lt "$n" ]; do
46
+ if [ "${W[$i]}" = "-1" ]; then
47
+ ok=1; bl="${B[$i]}"
48
+ for b in ${bl//,/ }; do
49
+ j=0
50
+ while [ "$j" -lt "$n" ]; do
51
+ if [ "${N[$j]}" = "$b" ] && [ "${W[$j]}" = "-1" ]; then ok=0; fi
52
+ j=$((j + 1))
53
+ done
54
+ done
55
+ [ "$ok" = "1" ] && ready[${#ready[@]}]="$i"
56
+ fi
57
+ i=$((i + 1))
58
+ done
59
+ if [ "${#ready[@]}" -gt 0 ]; then
60
+ for i in "${ready[@]}"; do W[$i]="$w"; done
61
+ remaining=$((remaining - ${#ready[@]})); w=$((w + 1)); progress=1
62
+ fi
63
+ done
64
+ i=0
65
+ while [ "$i" -lt "$n" ]; do [ "${W[$i]}" = "-1" ] && W[$i]="$w"; i=$((i + 1)); done
66
+ i=0
67
+ while [ "$i" -lt "$n" ]; do printf '%s\t%s\n' "${N[$i]}" "${W[$i]}"; i=$((i + 1)); done
68
+ }
69
+
70
+ # pm_batches — pure session-fit + file-disjoint packer for ONE wave (already deps-independent).
71
+ # stdin: lines "num<TAB>ctx<TAB>spaceSepFiles"; stdout: "num<TAB>batch". Budget = $1 (default 4).
72
+ # New batch when load+weight would overflow the budget OR the issue's files intersect the batch.
73
+ pm_batches() {
74
+ [ -n "${ZSH_VERSION:-}" ] && setopt local_options ksh_arrays sh_word_split 2>/dev/null
75
+ local budget="${1:-4}"
76
+ local -a N=() C=() F=()
77
+ local num ctx files
78
+ while IFS="$(printf '\t')" read -r num ctx files; do
79
+ [ -n "$num" ] || continue
80
+ N[${#N[@]}]="$num"; C[${#C[@]}]="$ctx"; F[${#F[@]}]="$files"
81
+ done
82
+ local n="${#N[@]}" batch=0 load=0 batchfiles=" " i w f ff need
83
+ i=0
84
+ while [ "$i" -lt "$n" ]; do
85
+ w="$(_pm_weight "${C[$i]}")"
86
+ need=0
87
+ [ $((load + w)) -gt "$budget" ] && need=1
88
+ ff="${F[$i]}"
89
+ for f in $ff; do
90
+ case "$batchfiles" in *" $f "*) need=1 ;; esac
91
+ done
92
+ if [ "$need" = "1" ] && [ "$load" -gt 0 ]; then
93
+ batch=$((batch + 1)); load=0; batchfiles=" "
94
+ fi
95
+ load=$((load + w))
96
+ for f in $ff; do batchfiles="$batchfiles$f "; done
97
+ printf '%s\t%s\n' "${N[$i]}" "$batch"
98
+ i=$((i + 1))
99
+ done
100
+ }
101
+
102
+ # _pm_files — pull a "Files:" / "Touches:" hint line from an issue body; emit space-separated paths.
103
+ _pm_files() {
104
+ printf '%s' "$1" | grep -ioE '^[[:space:]]*(Files|Touches):[[:space:]]*.*' 2>/dev/null \
105
+ | head -1 | sed -E 's/^[[:space:]]*(Files|Touches):[[:space:]]*//I; s/[,]+/ /g' \
106
+ | tr -s ' ' | sed 's/^ //; s/ $//'
107
+ }
108
+
109
+ plan_machine() {
110
+ command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || { echo "plan: needs gh + jq" >&2; return 1; }
111
+ # output mode: the dispatcher strips --llm and exports CCKIT_OUTPUT=json, so honor that env first;
112
+ # --llm/--output=json are kept for direct lib calls / tests.
113
+ local repo="$PLAN_REPO" budget="${KIT_SESSION_BUDGET:-4}" out="${CCKIT_OUTPUT:-human}" effort="" ms=""
114
+ while [ "$#" -gt 0 ]; do
115
+ case "$1" in
116
+ --llm|--output=json) out="json"; shift ;;
117
+ --effort) effort="$2"; shift 2 ;;
118
+ --effort=*) effort="${1#*=}"; shift ;;
119
+ --milestone) ms="$2"; shift 2 ;;
120
+ --milestone=*) ms="${1#*=}"; shift ;;
121
+ --cap) budget="$2"; shift 2 ;;
122
+ --cap=*) budget="${1#*=}"; shift ;;
123
+ -h|--help) sed -n '14,21p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; return 0 ;;
124
+ *) echo "plan: unknown arg '$1'" >&2; return 2 ;;
125
+ esac
126
+ done
127
+ [ -n "$repo" ] || { echo "plan: no repo (set KIT_REPO / PLAN_REPO)" >&2; return 1; }
128
+ case "$budget" in ''|*[!0-9]*) echo "plan: --cap needs a number (got '$budget')" >&2; return 2 ;; esac
129
+
130
+ # 1. the issue set: an effort's sub-issues, or the open board.
131
+ local raw
132
+ if [ -n "$effort" ]; then
133
+ raw="$(gh api "repos/$repo/issues/$effort/sub_issues" --paginate \
134
+ --jq '.[] | select(.state=="open") | [(.number|tostring), .title, .body] | @tsv' 2>/dev/null)" \
135
+ || { echo "plan: failed to read sub-issues of #$effort" >&2; return 1; }
136
+ else
137
+ local mjq='.[]'
138
+ [ -n "$ms" ] && mjq=".[] | select((.milestone.title // \"\") == \"$ms\")"
139
+ raw="$(gh issue list --repo "$repo" --state open --limit 200 --json number,title,body,milestone \
140
+ --jq "$mjq | [(.number|tostring), .title, .body] | @tsv" 2>/dev/null)" \
141
+ || { echo "plan: gh query failed (check gh auth)" >&2; return 1; }
142
+ fi
143
+ [ -n "$raw" ] || { [ "$out" = "json" ] && echo "[]" || echo "plan: no open issues to plan"; return 0; }
144
+
145
+ # 2. parallel arrays + per-issue ctx label, file hint, and OPEN blocked_by edges.
146
+ local -a nums=() titles=() ctxs=() files=() blkall=()
147
+ local n t b body lab
148
+ while IFS="$(printf '\t')" read -r n t body; do
149
+ [ -n "$n" ] || continue
150
+ nums+=("$n"); titles+=("$t")
151
+ lab="$(gh issue view "$n" --repo "$repo" --json labels \
152
+ --jq '[.labels[].name|select(startswith("ctx:"))|ltrimstr("ctx:")]|first // "M"' 2>/dev/null)"
153
+ ctxs+=("${lab:-M}")
154
+ files+=("$(_pm_files "$body")")
155
+ # only OPEN blockers gate execution; closed ones are already satisfied.
156
+ b="$(gh api "repos/$repo/issues/$n/dependencies/blocked_by" \
157
+ --jq '[.[]|select(.state=="open")|.number]|join(",")' 2>/dev/null)"
158
+ blkall+=("$b")
159
+ done <<EOF
160
+ $raw
161
+ EOF
162
+
163
+ # 3. split blockers into in-set (gate the wave layering) vs external-open (issue can't start yet).
164
+ local -a inset=() ext=()
165
+ local i j bb keepin keepext present
166
+ for i in "${!nums[@]}"; do
167
+ keepin=""; keepext=""
168
+ for bb in ${blkall[$i]//,/ }; do
169
+ present=0
170
+ for j in "${!nums[@]}"; do [ "${nums[$j]}" = "$bb" ] && present=1; done
171
+ if [ "$present" = "1" ]; then keepin="$keepin,$bb"; else keepext="$keepext,$bb"; fi
172
+ done
173
+ inset+=("${keepin#,}"); ext+=("${keepext#,}")
174
+ done
175
+
176
+ # 4. layer into waves (in-set deps only).
177
+ local wavetsv waves
178
+ wavetsv="$(for i in "${!nums[@]}"; do printf '%s\t%s\n' "${nums[$i]}" "${inset[$i]}"; done | pm_waves)"
179
+ # map number -> wave (linear; N small)
180
+ _wave_of() { printf '%s' "$wavetsv" | awk -F'\t' -v k="$1" '$1==k{print $2; exit}'; }
181
+ waves="$(printf '%s' "$wavetsv" | awk -F'\t' '{print $2}' | sort -n | uniq)"
182
+
183
+ # 5. within each wave, pack into batches (ctx budget + file overlap), then emit.
184
+ emit_rows() { # writes "wave<TAB>batch<TAB>number<TAB>ctx<TAB>blockers<TAB>title"
185
+ local wv batchtsv num bt
186
+ for wv in $waves; do
187
+ # gather this wave's issues as "num<TAB>ctx<TAB>files" in array order
188
+ batchtsv="$(for i in "${!nums[@]}"; do
189
+ [ "$(_wave_of "${nums[$i]}")" = "$wv" ] || continue
190
+ printf '%s\t%s\t%s\n' "${nums[$i]}" "${ctxs[$i]}" "${files[$i]}"
191
+ done | pm_batches "$budget")"
192
+ while IFS="$(printf '\t')" read -r num bt; do
193
+ [ -n "$num" ] || continue
194
+ for i in "${!nums[@]}"; do
195
+ if [ "${nums[$i]}" = "$num" ]; then
196
+ printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$wv" "$bt" "$num" "${ctxs[$i]}" "${inset[$i]}" "${titles[$i]}"
197
+ fi
198
+ done
199
+ done <<EOF2
200
+ $batchtsv
201
+ EOF2
202
+ done
203
+ }
204
+
205
+ local here; here="$(dirname "${BASH_SOURCE[0]}")"
206
+
207
+ # raw rows (wave<TAB>batch<TAB>number<TAB>ctx<TAB>blockers<TAB>title) — the copilot driver (#78)
208
+ # consumes this; not a public output mode.
209
+ if [ "$out" = "tsv" ]; then emit_rows; return 0; fi
210
+
211
+ if [ "$out" = "json" ]; then
212
+ # TOON-encode a uniform row array (wave,batch,number,ctx,blockers,title) for the copilot.
213
+ local json
214
+ json="$(emit_rows | jq -R -s '
215
+ [ split("\n")[] | select(length>0) | split("\t")
216
+ | {wave:(.[0]|tonumber), batch:(.[1]|tonumber), number:(.[2]|tonumber),
217
+ ctx:.[3], blockers:.[4], title:.[5]} ]')"
218
+ # route through the TOON encoder (uniform array -> tabular; falls back to JSON under the gate).
219
+ # shellcheck source=/dev/null
220
+ . "$here/toon.sh"
221
+ printf '%s' "$json" | toon_encode
222
+ return 0
223
+ fi
224
+
225
+ # human render: emit MARKDOWN (a table per wave) and route it through the rendering seam (#82) —
226
+ # rich via glow in a TTY, verbatim markdown otherwise (renders natively in Claude Code, pipe-safe).
227
+ # awk -F'\t' is used so the empty blockers field never collapses the columns.
228
+ # shellcheck source=/dev/null
229
+ . "$here/render.sh"
230
+ {
231
+ printf '# cckit plan — %s\n\n' "$repo"
232
+ printf '_session budget %s · ctx S=1 M=2 L=4 XL=8 · each wave runs in parallel_\n' "$budget"
233
+ emit_rows | awk -F'\t' '
234
+ BEGIN { lw="" }
235
+ {
236
+ wv=$1; bt=$2; num=$3; ctx=$4; blk=$5; title=$6
237
+ if (wv != lw) {
238
+ printf "\n## Wave %s\n\n", wv
239
+ print "| # | ctx | batch | issue | after |"
240
+ print "|---|-----|-------|-------|-------|"
241
+ lw=wv
242
+ }
243
+ sub(/^\[Effort( [0-9]+)?\] [0-9]+ · ?/, "", title)
244
+ sub(/^\[[A-Za-z]+\] /, "", title)
245
+ dep="—"
246
+ if (blk != "") { gsub(/,/, ", #", blk); dep="#" blk }
247
+ printf "| #%s | %s | %s | %s | %s |\n", num, ctx, bt, title, dep
248
+ }'
249
+ # externally-blocked issues never enter a wave — surface them so they aren't silently dropped.
250
+ local anyext=0
251
+ for i in "${!nums[@]}"; do [ -n "${ext[$i]}" ] && anyext=1; done
252
+ if [ "$anyext" = "1" ]; then
253
+ printf '\n## Blocked (open blockers outside this set — not scheduled)\n\n'
254
+ for i in "${!nums[@]}"; do
255
+ [ -n "${ext[$i]}" ] && printf -- '- #%s waits on #%s\n' "${nums[$i]}" "${ext[$i]//,/, #}"
256
+ done
257
+ fi
258
+ printf '\n'
259
+ } | cckit_render
260
+ }
@@ -0,0 +1,40 @@
1
+ #!/bin/sh
2
+ # render-test.sh — self-test for render.sh under bash AND zsh.
3
+ # Network-free, TTY-free: covers width clamping, the markdown table composers, and the pipe-safety
4
+ # guarantee (non-TTY in == verbatim out). Run: bash scripts/lib/render-test.sh
5
+
6
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
7
+
8
+ if [ -n "${RND_TEST_INNER:-}" ]; then
9
+ . "$dir/ui.sh"
10
+ . "$dir/render.sh"
11
+ fail=0
12
+ eq() { if [ "$2" != "$3" ]; then echo "FAIL($RND_TEST_INNER): $1 -> '[$2]', want '[$3]'"; fail=1; fi; }
13
+
14
+ # render_width — clamp to [40,120].
15
+ eq "width clamps high" "$(COLUMNS=999 render_width)" "120"
16
+ eq "width clamps low" "$(COLUMNS=5 render_width)" "40"
17
+ eq "width passes mid" "$(COLUMNS=90 render_width)" "90"
18
+ eq "width junk -> safe" "$( (COLUMNS=abc; unset TERM; render_width) | grep -qE '^[0-9]+$' && echo ok)" "ok"
19
+
20
+ # table composers.
21
+ eq "table row" "$(render_table_row '#76' 'M' 'plan')" "| #76 | M | plan |"
22
+ eq "table sep" "$(render_table_sep 3)" "| --- | --- | --- |"
23
+ eq "h1" "$(render_h1 'Title')" "# Title"
24
+
25
+ # pipe-safety: not a TTY here, so cckit_render must pass markdown through byte-for-byte.
26
+ md="$(printf '# H\n\n| a | b |\n')"
27
+ eq "render verbatim when piped" "$(printf '%s' "$md" | cckit_render)" "$md"
28
+ # explicit CCKIT_NO_GLOW also forces verbatim.
29
+ eq "render verbatim NO_GLOW" "$(printf '%s' "$md" | CCKIT_NO_GLOW=1 cckit_render)" "$md"
30
+
31
+ if [ "$fail" -eq 0 ]; then echo "PASS($RND_TEST_INNER): render seam"; fi
32
+ exit "$fail"
33
+ fi
34
+
35
+ rc=0
36
+ for sh in bash zsh; do
37
+ command -v "$sh" >/dev/null 2>&1 || continue
38
+ RND_TEST_INNER="$sh" "$sh" "$0" || rc=1
39
+ done
40
+ exit "$rc"
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+ # render.sh — the rendering seam: cckit's value-add for output (Effort 75 · #82, completes #9).
3
+ #
4
+ # cckit emits MARKDOWN. Two readers consume it:
5
+ # - Claude Code (and any agent transcript): markdown renders natively — tables, headings, code —
6
+ # so structured markdown IS the value-add. We just make sure verbs emit clean markdown.
7
+ # - A human terminal: `glow` renders that same markdown richly when stdout is a TTY; without glow,
8
+ # or when piped, the markdown passes through verbatim (still perfectly readable, still pipe-safe).
9
+ #
10
+ # One seam, every verb opts in: compose markdown with the helpers, pipe through `cckit_render`.
11
+ #
12
+ # cckit_render stdin markdown -> glow (TTY + glow) else verbatim (pipe-safe, always plain
13
+ # when not a terminal so machine consumers never see escape codes).
14
+ # render_h1 <text> a top sigil heading line.
15
+ # render_table_row … one markdown table row from N cells.
16
+ # render_rule a markdown horizontal rule.
17
+ #
18
+ # Depends on ui.sh (ui_tty). glow is optional; never required.
19
+
20
+ # render_width — target wrap width: COLUMNS if sane, else `tput cols`, else 100; clamped to [40,120]
21
+ # so rendered output fits a docs column / normal terminal and never sprawls.
22
+ render_width() {
23
+ local w="${COLUMNS:-}"
24
+ case "$w" in ''|*[!0-9]*) w="$(tput cols 2>/dev/null || echo 100)" ;; esac
25
+ case "$w" in ''|*[!0-9]*) w=100 ;; esac
26
+ [ "$w" -lt 40 ] && w=40
27
+ [ "$w" -gt 120 ] && w=120
28
+ printf '%s' "$w"
29
+ }
30
+
31
+ # cckit_render — render markdown from stdin. Rich via glow only when interactive; otherwise verbatim.
32
+ # CCKIT_NO_GLOW=1 forces verbatim (tests, demos, when the caller wants raw markdown).
33
+ cckit_render() {
34
+ if [ -z "${CCKIT_NO_GLOW:-}" ] && command -v ui_tty >/dev/null 2>&1 && ui_tty \
35
+ && command -v glow >/dev/null 2>&1; then
36
+ glow -w "$(render_width)" - 2>/dev/null || cat
37
+ else
38
+ cat
39
+ fi
40
+ }
41
+
42
+ render_h1() { printf '# %s\n' "$1"; }
43
+ render_rule() { printf '\n---\n'; }
44
+
45
+ # render_table_row <cell> [cell …] — a single markdown table row: | a | b | c |
46
+ render_table_row() {
47
+ local out="|"
48
+ for cell in "$@"; do out="$out $cell |"; done
49
+ printf '%s\n' "$out"
50
+ }
51
+
52
+ # render_table_sep <n> — the header separator row for an n-column markdown table.
53
+ render_table_sep() {
54
+ local n="$1" out="|" i=1
55
+ while [ "$i" -le "$n" ]; do out="$out --- |"; i=$((i + 1)); done
56
+ printf '%s\n' "$out"
57
+ }
@@ -0,0 +1,135 @@
1
+ ---
2
+ name: docs-writer
3
+ description: >
4
+ Write and edit end-user documentation in the house voice: kind but robust, ADHD-oriented and
5
+ scannable, ZERO analogies, beginner-inclusive but expert-skippable. Encodes the page template
6
+ (title → one-line description → self-explanatory left-to-right diagram → body → next-section
7
+ buttons) and the diagram discipline (interactive, left-to-right, self-explanatory, never
8
+ repetitive). Use it to keep every docs page readable by people with low software knowledge
9
+ without watering down the substance.
10
+ when_to_use: >
11
+ When writing or editing any documentation page meant for humans — guides, getting-started,
12
+ concept pages, how-to pages, reference intros. Use it before drafting (to lay out the page) and
13
+ after drafting (to run the checklist). Not for code comments, commit messages, or PR bodies.
14
+ metadata:
15
+ version: 1.0.0
16
+ ---
17
+
18
+ # docs-writer — the house voice for human documentation
19
+
20
+ Documentation here is read by people with low software knowledge. It must still be correct and
21
+ complete for experts. The whole skill is one promise: **a beginner can follow the flow, and an
22
+ expert can skip to the part they need — on the same page.**
23
+
24
+ You write the page so both happen at once.
25
+
26
+ ## The reader
27
+
28
+ - The lowest-baseline reader has barely used a terminal. Write so they are never lost.
29
+ - The expert reader knows git, PRs, and agents. Write so they can skip past the basics in seconds.
30
+ - Both read the same page. You do not fork the docs by skill level — you **structure** the page so
31
+ the basic material is clearly marked and easy to scroll past.
32
+
33
+ ## Voice rules (non-negotiable)
34
+
35
+ 1. **No analogies. Ever.** Do not say "think of it like…", "it's basically a…", "imagine a…".
36
+ Explain the actual thing in plain words. If a sentence starts to compare the topic to something
37
+ else, delete it and describe the topic directly.
38
+ 2. **Kind but robust.** Warm, plain, encouraging — and still precise. Kindness is short sentences
39
+ and no jargon-dumping, not vagueness. Never sacrifice a correct detail to sound friendly.
40
+ 3. **Not "so technical."** Use the plain word over the insider word. When a technical term is
41
+ unavoidable, define it in one short clause the first time it appears, then use it freely.
42
+ 4. **ADHD-oriented.** One idea per paragraph. Short paragraphs (1–3 sentences). Front-load the
43
+ point — the first words of every paragraph, bullet, and heading carry the meaning. Generous
44
+ headings so the page is skimmable. No walls of text.
45
+ 5. **Lead with the verb / the outcome.** "Open a pull request to…" beats "In order to be able to
46
+ open a pull request, you will…". Cut "in order to", "simply", "just", "basically", "of course".
47
+ 6. **Show, don't promise.** Prefer a real command, a real screenshot, a real diagram over a
48
+ paragraph describing one.
49
+
50
+ ## The page template
51
+
52
+ Every page follows this order, top to bottom:
53
+
54
+ 1. **Title** — the name of the thing or the task. Plain. No cleverness.
55
+ 2. **One-line description** — a single sentence under the title saying what this page lets the
56
+ reader do or understand. This is the whole page in one breath.
57
+ 3. **Self-explanatory diagram** — a left-to-right diagram of the flow, placed high on the page,
58
+ that a reader could understand with the title alone. See *Diagram discipline* below. If the
59
+ page has no flow worth drawing, skip this — do not force a diagram.
60
+ 4. **The body** — the rest of the docs: concepts, steps, the how and the why, and inline
61
+ **links to learn** more (definitions, deeper pages, external references). This is where the
62
+ beginner-only material lives, clearly headed so experts scroll past it.
63
+ 5. **Next-section buttons** — at the bottom, one or two clear buttons to the next step(s) in the
64
+ journey. Never leave the reader at a dead end.
65
+
66
+ Hold the order. Title, then the one-liner, then the picture, then the words, then the way out.
67
+
68
+ ### Skeleton
69
+
70
+ ```mdx
71
+ # <Plain title>
72
+
73
+ <One sentence: what you can do or understand after this page.>
74
+
75
+ <FlowDiagram .../> {/* left-to-right, self-explanatory, only if there's a flow */}
76
+
77
+ ## <First concept — front-loaded heading>
78
+ <Short paragraph. One idea. Plain words. A [link to learn](…) where useful.>
79
+
80
+ ## <Steps, if this is a how-to>
81
+ <Steps component: 1, 2, 3 — one action each.>
82
+
83
+ > [!NOTE]
84
+ > <Beginner aside: a basic point experts can skip, clearly marked.>
85
+
86
+ ---
87
+ <Next-section buttons: → Next step · → Related concept>
88
+ ```
89
+
90
+ ## Diagram discipline
91
+
92
+ - **Interactive, left-to-right.** Diagrams are interactive (React Flow / SVG) and flow left to
93
+ right, following how the reader reads.
94
+ - **Self-explanatory.** A diagram must make sense from the page title alone — labels are plain
95
+ words, the arrows tell the story, no legend required to grasp the shape.
96
+ - **Diagram the flow, not the prose.** Draw a flow when seeing it is faster than reading it:
97
+ sequences, branches, parallel work, lifecycles. Do not draw a diagram that just restates a
98
+ sentence.
99
+ - **Never repetitive.** If two pages share a flow, draw it once on the most relevant page and link
100
+ to it from the other. The same diagram should not appear twice.
101
+ - **Pair with steps, don't duplicate them.** The diagram shows the shape; a Steps list gives the
102
+ exact actions. They complement each other — they do not repeat each other word for word.
103
+
104
+ ## Scannability mechanics
105
+
106
+ - Headings every few paragraphs. A reader scanning only the headings should still get the gist.
107
+ - Bold the **lead word** of a bullet when the bullets are a list of distinct things.
108
+ - Lists over prose for anything enumerable (steps, options, requirements).
109
+ - Callouts for the things that interrupt: a NOTE for "good to know", a CAUTION for "this can bite
110
+ you", a TIP for a shortcut. Use them sparingly so they keep their weight.
111
+ - Code and commands in code blocks, never inline-buried in a paragraph.
112
+ - One screen, one idea: if a section runs long, it is probably two sections.
113
+
114
+ ## Beginner-inclusive, expert-skippable
115
+
116
+ - Put the absolute-basics content (what a terminal is, how to run a command, what a branch is) in
117
+ its own clearly-headed section or aside, so an expert sees the heading and scrolls past in one
118
+ motion.
119
+ - Never make the expert read the basics to reach the substance. Never make the beginner hunt for
120
+ the basics because they were assumed away.
121
+ - Mark the entry point. If a section is "start here for total beginners", say so in the heading.
122
+
123
+ ## Before you finish — checklist
124
+
125
+ - [ ] Title is plain; the one-line description says what the page delivers.
126
+ - [ ] If there's a flow, a left-to-right self-explanatory diagram sits near the top — and it is
127
+ not a redrawn paragraph.
128
+ - [ ] **Zero analogies.** Re-read every sentence that compares the topic to anything else; rewrite
129
+ it to describe the topic directly.
130
+ - [ ] Every technical term is defined the first time, in one clause.
131
+ - [ ] Paragraphs are short and front-loaded; the page is skimmable by headings alone.
132
+ - [ ] Beginner-only material is clearly headed so experts can skip it.
133
+ - [ ] No "simply", "just", "basically", "in order to", "of course".
134
+ - [ ] Next-section buttons at the bottom — no dead end.
135
+ - [ ] A reader with low software knowledge could follow the flow start to finish.