@jeiemgi/cckit 0.5.0 → 0.7.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 (144) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +34 -3
  3. package/README.md +95 -6
  4. package/bin/cckit +90 -3
  5. package/cckit.config.json +7 -2
  6. package/kit.config.schema.json +26 -1
  7. package/package.json +1 -1
  8. package/profiles/automation.json +2 -1
  9. package/profiles/content.json +2 -1
  10. package/profiles/minimal.json +2 -1
  11. package/profiles/research.json +2 -1
  12. package/profiles/software.json +2 -1
  13. package/scripts/benchmark/benchmark-test.sh +83 -0
  14. package/scripts/benchmark/gate.sh +55 -0
  15. package/scripts/benchmark/lib/bench-common.sh +70 -0
  16. package/scripts/benchmark/lib/model.sh +116 -0
  17. package/scripts/benchmark/report.sh +105 -0
  18. package/scripts/benchmark/run-quality.sh +102 -0
  19. package/scripts/benchmark/run.sh +166 -0
  20. package/scripts/benchmark/stop-check.sh +83 -0
  21. package/scripts/commitlint-test.sh +58 -0
  22. package/scripts/init.sh +57 -1
  23. package/scripts/kit-self-update.sh +55 -0
  24. package/scripts/lib/board-view-test.sh +1 -0
  25. package/scripts/lib/board-view.sh +1 -0
  26. package/scripts/lib/captain-test.sh +62 -0
  27. package/scripts/lib/captain.sh +105 -17
  28. package/scripts/lib/cckit-output.sh +1 -0
  29. package/scripts/lib/commitlint.sh +54 -0
  30. package/scripts/lib/config-path-test.sh +1 -0
  31. package/scripts/lib/config-path.sh +1 -0
  32. package/scripts/lib/copilot-test.sh +1 -0
  33. package/scripts/lib/copilot.sh +1 -0
  34. package/scripts/lib/effort-dispatch-test.sh +10 -0
  35. package/scripts/lib/effort-flows-test.sh +1 -0
  36. package/scripts/lib/effort-metrics-test.sh +1 -0
  37. package/scripts/lib/effort-metrics.sh +1 -0
  38. package/scripts/lib/effort-ops-test.sh +360 -0
  39. package/scripts/lib/effort-ops.sh +372 -16
  40. package/scripts/lib/effort-parity-test.sh +1 -0
  41. package/scripts/lib/effort-plan.sh +1 -0
  42. package/scripts/lib/effort-slug-test.sh +32 -0
  43. package/scripts/lib/effort-slug.sh +72 -8
  44. package/scripts/lib/effort.sh +1 -0
  45. package/scripts/lib/engine-adapter.sh +1 -0
  46. package/scripts/lib/errors-header-test.sh +86 -0
  47. package/scripts/lib/gh-log.sh +1 -0
  48. package/scripts/lib/gh-project-test.sh +1 -0
  49. package/scripts/lib/gh-project.sh +1 -0
  50. package/scripts/lib/git-remote-test.sh +1 -0
  51. package/scripts/lib/git-remote.sh +1 -0
  52. package/scripts/lib/handoff.sh +23 -2
  53. package/scripts/lib/kit-brief-test.sh +292 -0
  54. package/scripts/lib/kit-brief.sh +376 -0
  55. package/scripts/lib/kit-cli-test.sh +1 -0
  56. package/scripts/lib/kit-cli.sh +1 -0
  57. package/scripts/lib/kit-config-resolve.sh +1 -0
  58. package/scripts/lib/kit-config-test.sh +14 -0
  59. package/scripts/lib/kit-config.sh +7 -0
  60. package/scripts/lib/kit-engine-test.sh +1 -0
  61. package/scripts/lib/kit-events.sh +1 -0
  62. package/scripts/lib/kit-gc-test.sh +125 -0
  63. package/scripts/lib/kit-gc.sh +193 -5
  64. package/scripts/lib/kit-interview-test.sh +1 -0
  65. package/scripts/lib/kit-interview.sh +1 -0
  66. package/scripts/lib/kit-lib-test.sh +226 -0
  67. package/scripts/lib/kit-lib.sh +308 -0
  68. package/scripts/lib/kit-local.sh +1 -0
  69. package/scripts/lib/kit-manifest.sh +1 -0
  70. package/scripts/lib/kit-mode-test.sh +1 -0
  71. package/scripts/lib/kit-mode.sh +1 -0
  72. package/scripts/lib/kit-msg-test.sh +1 -0
  73. package/scripts/lib/kit-msg.sh +1 -0
  74. package/scripts/lib/kit-operate.sh +1 -0
  75. package/scripts/lib/kit-profile-test.sh +1 -0
  76. package/scripts/lib/kit-profile.sh +1 -0
  77. package/scripts/lib/kit-state-test.sh +89 -0
  78. package/scripts/lib/kit-state.sh +61 -0
  79. package/scripts/lib/kit-status-test.sh +233 -0
  80. package/scripts/lib/kit-status.sh +415 -0
  81. package/scripts/lib/kit-task-ops-test.sh +22 -0
  82. package/scripts/lib/kit-task-ops.sh +51 -2
  83. package/scripts/lib/next.sh +1 -0
  84. package/scripts/lib/plan-machine-test.sh +54 -0
  85. package/scripts/lib/plan-machine.sh +86 -25
  86. package/scripts/lib/plan-next-test.sh +1 -0
  87. package/scripts/lib/plan-next.sh +1 -0
  88. package/scripts/lib/pr-evidence-test.sh +259 -0
  89. package/scripts/lib/pr-evidence.sh +220 -35
  90. package/scripts/lib/project-scan.sh +1 -0
  91. package/scripts/lib/react-detect.sh +1 -0
  92. package/scripts/lib/render-test.sh +1 -0
  93. package/scripts/lib/render.sh +1 -0
  94. package/scripts/lib/role-identity.sh +1 -0
  95. package/scripts/lib/secret-guard.sh +21 -1
  96. package/scripts/lib/toon.sh +1 -0
  97. package/scripts/lib/ui.sh +1 -0
  98. package/scripts/lib/version-bump-test.sh +1 -0
  99. package/scripts/lib/version-bump.sh +1 -0
  100. package/scripts/lib/worktree-bootstrap-test.sh +220 -0
  101. package/scripts/lib/worktree-issue-test.sh +15 -1
  102. package/scripts/lib/worktree-issue.sh +23 -8
  103. package/scripts/lib/worktree-start.sh +191 -7
  104. package/scripts/lib/zsh-safety-test.sh +10 -0
  105. package/scripts/orchestrate.sh +8 -1
  106. package/scripts/portable-test.sh +13 -2
  107. package/scripts/self-install-test.sh +282 -0
  108. package/scripts/setup-labels.sh +1 -0
  109. package/scripts/status.sh +68 -40
  110. package/scripts/task-sync.sh +13 -0
  111. package/scripts/ux-a11y-scan.sh +96 -0
  112. package/scripts/ux-ds-audit.sh +146 -0
  113. package/scripts/ux-graph-scan.sh +188 -0
  114. package/skills/kit-autopilot/SKILL.md +6 -1
  115. package/skills/kit-cleanup/SKILL.md +83 -0
  116. package/skills/kit-effort-close/SKILL.md +3 -0
  117. package/skills/kit-effort-new/SKILL.md +7 -0
  118. package/skills/kit-effort-start/SKILL.md +39 -4
  119. package/skills/kit-gc/SKILL.md +19 -0
  120. package/skills/kit-next/SKILL.md +5 -0
  121. package/skills/kit-status/SKILL.md +92 -0
  122. package/skills/kit-task-start/SKILL.md +7 -1
  123. package/skills/kit-ux-audit/SKILL.md +241 -0
  124. package/skills/kit-ux-audit/references/a11y.md +79 -0
  125. package/skills/kit-ux-audit/references/consistency.md +106 -0
  126. package/skills/kit-ux-audit/references/graph-model.md +92 -0
  127. package/skills/kit-ux-audit/references/heuristics.md +157 -0
  128. package/skills/kit-ux-audit/references/report.md +172 -0
  129. package/templates/agents/ux.md +89 -0
  130. package/templates/benchmarks/SCHEMA.md +75 -0
  131. package/templates/benchmarks/abstain.jsonl +8 -0
  132. package/templates/benchmarks/adversarial.jsonl +8 -0
  133. package/templates/benchmarks/benchmark.config.json +14 -0
  134. package/templates/benchmarks/quality.jsonl +8 -0
  135. package/templates/benchmarks/retrieval.jsonl +7 -0
  136. package/templates/rules/branch-naming.md +20 -1
  137. package/templates/rules/communication-style.md +8 -0
  138. package/templates/rules/delegation-brief.md +38 -4
  139. package/templates/rules/effort-model.md +47 -4
  140. package/templates/rules/naming-and-ids.md +199 -0
  141. package/templates/rules/task-management.md +1 -1
  142. package/templates/settings/settings.json.tmpl +9 -0
  143. package/templates/skills/concrete/SKILL.md +117 -0
  144. package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
@@ -3,6 +3,7 @@
3
3
  # When CCKIT_OUTPUT=json (set by the --llm / --output=json flag), verbs emit a single JSON
4
4
  # object on stdout so any agent can parse the result; otherwise they print human-readable text.
5
5
  # Dependency-light: jq when present (correct escaping), a pure-bash fallback otherwise.
6
+ # errors: pure — jq when present, pure-bash fallback; cannot fail
6
7
 
7
8
  # cckit_is_json - true when the caller asked for machine-readable output.
8
9
  cckit_is_json() { [ "${CCKIT_OUTPUT:-human}" = "json" ]; }
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env bash
2
+ # commitlint.sh — validate a subject line against Conventional Commits. ONE implementation,
3
+ # shared by the PR-title gate (.github/workflows/commitlint.yml) and the local test suite.
4
+ #
5
+ # Why this exists: PRs are squash-merged (`gh pr merge --squash`), so the PR *title* becomes the
6
+ # single commit on the base branch that release-please reads to compute the next version. A
7
+ # non-conventional title makes release-please classify the change as "other" and silently
8
+ # under-bump (or skip the release) — so every PR title MUST be a Conventional Commit subject.
9
+ #
10
+ # commitlint.sh "<subject>" exit 0 = valid, 1 = invalid (with guidance on stderr)
11
+ # source commitlint.sh && commitlint_check "<subject>" same, as a function
12
+ #
13
+ # The accepted types are commitlint's config-conventional set, a superset of the types
14
+ # scripts/lib/version-bump.sh acts on (feat -> minor; fix/perf/refactor/revert -> patch;
15
+ # feat!/BREAKING CHANGE -> major; the rest -> no release). Keeping the two in step means a title
16
+ # that passes here is one release-please can always classify.
17
+ # errors: strict — a validator: rc 1 on an invalid subject
18
+
19
+ # Conventional Commit subject: type(scope)!: description
20
+ # type — one of the known types below
21
+ # (scope) — optional, e.g. (orchestrate), (main)
22
+ # ! — optional breaking-change marker
23
+ # : SPACE — required separator
24
+ # description — required, non-empty
25
+ _CL_TYPES='build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test'
26
+ _CL_RE="^(${_CL_TYPES})(\([a-z0-9][a-z0-9._/-]*\))?(!)?: .+"
27
+
28
+ commitlint_check() {
29
+ local subject="${1-}"
30
+ if [ -z "$subject" ]; then
31
+ printf 'commitlint: empty subject — nothing to validate\n' >&2
32
+ return 1
33
+ fi
34
+ if printf '%s' "$subject" | grep -qE "$_CL_RE"; then
35
+ return 0
36
+ fi
37
+ {
38
+ printf 'commitlint: not a Conventional Commit subject:\n'
39
+ printf ' %s\n\n' "$subject"
40
+ printf 'Expected: type(scope)!: summary\n'
41
+ printf ' type one of: %s\n' "$(printf '%s' "$_CL_TYPES" | tr '|' ' ')"
42
+ printf ' scope optional, e.g. feat(orchestrate): ...\n'
43
+ printf ' ! optional breaking-change marker, e.g. feat!: ...\n'
44
+ printf ' : then a space, then a non-empty summary\n\n'
45
+ printf 'Why it matters: this subject is the squash-merge commit release-please reads to pick\n'
46
+ printf 'the next version. A non-conventional subject under-bumps the release silently.\n'
47
+ } >&2
48
+ return 1
49
+ }
50
+
51
+ # Run as a CLI when executed directly (not when sourced).
52
+ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
53
+ commitlint_check "${1-}"
54
+ fi
@@ -3,6 +3,7 @@
3
3
  # config-path-test.sh — covers the ONE shared config-path resolver (#69): kit_config_find (pure walk)
4
4
  # and kit_config_path (KIT_CONFIG wins, else walk). Every kit entrypoint discovers the project config
5
5
  # through these. Hermetic: throwaway dirs. Run: bash scripts/lib/config-path-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
7
  set -u
7
8
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8
9
  LIB="$ROOT/scripts/lib"
@@ -10,6 +10,7 @@
10
10
  # kit_config_find <startdir> walk startdir -> / for a project config; prints path (rc 0) or rc 1.
11
11
  # Ignores KIT_CONFIG — a pure "is <dir> under a kit project?" answer.
12
12
  # kit_config_path [startdir] KIT_CONFIG wins, else kit_config_find; prints path (rc 0) or rc 1.
13
+ # errors: pure — dependency-free path resolution
13
14
 
14
15
  kit_config_find() {
15
16
  local d="${1:-$PWD}"
@@ -2,6 +2,7 @@
2
2
  # copilot-test.sh — self-test for copilot.sh pure helper under bash AND zsh.
3
3
  # Network-free: covers the subagent seed composer only (the gh/plan-driven copilot_brief is not
4
4
  # exercised). Run: bash scripts/lib/copilot-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
5
6
 
6
7
  dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
7
8
 
@@ -13,6 +13,7 @@
13
13
  # cckit wave --llm the fan-out as TOON rows (wave,number,ctx,prompt) for an agent
14
14
  #
15
15
  # Requires: gh, jq (via the plan machine). bash 3.2 / zsh compatible.
16
+ # errors: strict — refuses to emit a brief without gh + jq
16
17
 
17
18
  COPILOT_REPO="${COPILOT_REPO:-${KIT_REPO:-}}"
18
19
 
@@ -6,6 +6,7 @@
6
6
  # origin/main on a non-main-based repo (and the KIT_PROJECTS_V2 board guard never fired via the CLI).
7
7
  # Static contract test over bin/cckit: extract the branch block, assert load_kit_config comes first.
8
8
  # Run: bash scripts/lib/effort-dispatch-test.sh
9
+ # errors: strict — a test runner: rc 1 on any failed assertion
9
10
  set -u
10
11
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
11
12
  BIN="$ROOT/bin/cckit"
@@ -21,5 +22,14 @@ lib_ln="$(printf '%s\n' "$blk" | grep -n 'source "\$LIB/effort\.sh"' | head -1 |
21
22
  t "effort) loads the project config" "$([ -n "$cfg_ln" ] && echo yes)" "yes"
22
23
  t "config load precedes the effort libs" "$([ -n "$cfg_ln" ] && [ -n "$lib_ln" ] && [ "$cfg_ln" -lt "$lib_ln" ] && echo yes)" "yes"
23
24
 
25
+ # #243: every effort subcommand the usage header advertises must actually dispatch, `chain` included
26
+ # — a docs/code drift guard (a subcommand documented but not wired falls through to the usage line).
27
+ usage_subs="$(grep -oE '^# cckit effort <[a-z|]+>' "$BIN" | head -1 | sed -E 's/.*<//; s/>//; s/\|/ /g')"
28
+ t "usage header lists the effort subcommands" "$usage_subs" "new chain start pr close plan"
29
+ for s in $usage_subs; do
30
+ t "effort) dispatches '$s'" \
31
+ "$(printf '%s\n' "$blk" | grep -cE "^ ${s}\)" | tr -d ' ')" "1"
32
+ done
33
+
24
34
  [ "$fail" -eq 0 ] && echo "ALL OK"
25
35
  exit "$fail"
@@ -5,6 +5,7 @@
5
5
  # explicit EFFORT_FLOWS env var (wins) -> effort.flows[] in the project config -> built-in default.
6
6
  # Hermetic: throwaway configs pointed at via KIT_CONFIG (no network, no gh).
7
7
  # Run: bash scripts/lib/effort-flows-test.sh
8
+ # errors: strict — a test runner: rc 1 on any failed assertion
8
9
  set -u
9
10
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
10
11
  LIB="$ROOT/scripts/lib"
@@ -5,6 +5,7 @@
5
5
  # effort's build WINDOW [start,end] — the window recovers sessions logged before the branch field
6
6
  # existed or from a detached/worktree checkout. Hermetic: a throwaway repo + a stubbed usage log +
7
7
  # stubbed transcripts under a temp HOME. Run: bash scripts/lib/effort-metrics-test.sh
8
+ # errors: strict — a test runner: rc 1 on any failed assertion
8
9
  set -u
9
10
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
10
11
  LIB="$ROOT/scripts/lib"
@@ -12,6 +12,7 @@
12
12
  #
13
13
  # Cost = metered API; retroactively $ is computed from current Opus-4.8 list price (no per-call bill
14
14
  # access here) → cost_source="list-price". bash 3.2 compatible. Requires: git, jq.
15
+ # errors: best-effort — local telemetry must never break the op it measures
15
16
 
16
17
  # Opus 4.8 list price, USD per 1M tokens (correct as of 2026-06; update when prices change).
17
18
  _EM_PRICE_IN=5.00; _EM_PRICE_OUT=25.00; _EM_PRICE_CACHE_READ=0.50; _EM_PRICE_CACHE_WRITE=6.25
@@ -2,6 +2,7 @@
2
2
  # shellcheck shell=bash
3
3
  # effort-ops-test.sh — covers the effort lifecycle ops (#48). Hermetic: stubs gh (no network/auth)
4
4
  # and uses a throwaway git repo with a bare remote. Run: bash scripts/lib/effort-ops-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
5
6
  set -u
6
7
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
7
8
  LIB="$ROOT/scripts/lib"
@@ -186,5 +187,364 @@ tc "$BOARD_LOG" 'ITEM-301 SF1 OPT_DONE' "wave close sets board Done for sub #301
186
187
  tc "$BOARD_LOG" 'ITEM-302 SF1 OPT_DONE' "wave close sets board Done for sub #302"
187
188
  case "$close_out" in *"kit-sync"*".claude/skills/demo.md"*) echo "ok: wave drift check reads the merged PR diffs" ;; *) echo "FAIL: no kit-sync warning in wave close output"; fail=1 ;; esac
188
189
 
190
+ # ── #243 · _eff_relations_add — the ONE `Depends on` formatter (pure: no gh, no network) ──────────
191
+ rel_body="$(printf '## Verification\nV\n')"
192
+ rel1="$(_eff_relations_add "$rel_body" 5)"
193
+ t "relations_add appends a ## Relations section" "$rel1" "$(printf '## Verification\nV\n\n## Relations\n- Depends on #5')"
194
+ t "relations_add is idempotent (same line twice)" "$(_eff_relations_add "$rel1" 5)" "$rel1"
195
+ t "relations_add appends into an existing section" "$(_eff_relations_add "$rel1" 9)" \
196
+ "$(printf '## Verification\nV\n\n## Relations\n- Depends on #5\n- Depends on #9')"
197
+ t "relations_add on an empty body has no leading blank" "$(_eff_relations_add "" 5)" \
198
+ "$(printf '## Relations\n- Depends on #5')"
199
+ # a ## Relations section in the MIDDLE of a body keeps its place; the line lands at the section end
200
+ t "relations_add respects a mid-body section" \
201
+ "$(_eff_relations_add "$(printf '## Relations\n- Depends on #1\n\n## Verification\nV\n')" 2)" \
202
+ "$(printf '## Relations\n- Depends on #1\n- Depends on #2\n\n## Verification\nV')"
203
+
204
+ # ── #243 · effort_new --depends-on emits a WELL-FORMED Relations block ────────────────────────────
205
+ # It used to be built inline with `$( … )`, which eats trailing newlines — the section shipped as the
206
+ # single mangled line `## Relations- Depends on #4- Depends on #9`. Both now go through the formatter.
207
+ : > "$GH_LOG"; printf '0' > "$GH_N"
208
+ effort_new --depends-on "#4,9" "depends on effort" >/dev/null 2>&1
209
+ tc "$GH_LOG" '^## Relations$' "--depends-on writes ## Relations on its own line"
210
+ tc "$GH_LOG" '^- Depends on #4$' "--depends-on writes the first dep on its own line"
211
+ tc "$GH_LOG" '^- Depends on #9( |$)' "--depends-on writes the second dep on its own line"
212
+ t "--depends-on does not mangle the heading" "$(grep -c '## Relations-' "$GH_LOG")" "0"
213
+
214
+ # ── #243 · effort_chain — a linear blocked_by chain, idempotent, cycle-refusing ────────────────────
215
+ # Its own gh stub (prepended to PATH) with real STATE: which issues exist, the blocked_by edge set,
216
+ # and per-issue bodies — so the edges and the body lines can be asserted, not just the call log.
217
+ cstub="$tmp/cbin"; mkdir -p "$cstub"
218
+ export CH_DIR="$tmp/chain"; mkdir -p "$CH_DIR"
219
+ export CH_LOG="$CH_DIR/gh.log" CH_EDGES="$CH_DIR/edges" CH_EXISTS="$CH_DIR/exists"
220
+ printf '501\n502\n503\n504\n601\n' > "$CH_EXISTS" # #999 deliberately absent
221
+ : > "$CH_EDGES"; : > "$CH_LOG"
222
+ for n in 501 502 503 504; do printf '## Goal\ng%s\n\n## Verification\nv\n' "$n" > "$CH_DIR/body.$n"; done
223
+ cat > "$cstub/gh" <<'SH'
224
+ #!/usr/bin/env bash
225
+ # stub gh with state. DB id of issue N is 900000+N (the dependencies API takes the blocker's db id).
226
+ echo "$*" | tr '\n' ' ' >> "$CH_LOG"; echo >> "$CH_LOG"
227
+ _n() { printf '%s' "$1" | sed -nE 's#.*issues/([0-9]+).*#\1#p'; }
228
+ case "$1" in
229
+ issue)
230
+ case "$2" in
231
+ view) cat "$CH_DIR/body.$3" 2>/dev/null; exit 0 ;;
232
+ edit) n="$3"; shift 3
233
+ # CH_FAIL_EDIT=<n> makes the edit fail for that issue — a POST-validation failure, the
234
+ # only way to reach effort_chain's rc=1 path (pre-flight refusals never write at all).
235
+ [ -n "${CH_FAIL_EDIT:-}" ] && [ "$n" = "$CH_FAIL_EDIT" ] && exit 1
236
+ while [ $# -gt 0 ]; do
237
+ [ "$1" = "--body" ] && { printf '%s' "$2" > "$CH_DIR/body.$n"; break; }
238
+ shift
239
+ done
240
+ exit 0 ;;
241
+ *) exit 0 ;;
242
+ esac ;;
243
+ api)
244
+ case "$*" in
245
+ *"--method POST"*"/dependencies/blocked_by"*)
246
+ n="$(_n "$*")"; bid="$(printf '%s' "$*" | sed -nE 's#.*issue_id=([0-9]+).*#\1#p')"
247
+ b=$((bid - 900000))
248
+ grep -qx "$n $b" "$CH_EDGES" && exit 1 # GitHub rejects a duplicate edge
249
+ echo "$n $b" >> "$CH_EDGES"; exit 0 ;;
250
+ *"/dependencies/blocked_by"*)
251
+ awk -v k="$(_n "$*")" '$1==k{print $2}' "$CH_EDGES"; exit 0 ;;
252
+ *".id"*) n="$(_n "$*")"; echo $((900000 + n)); exit 0 ;;
253
+ *".number"*) n="$(_n "$*")"; grep -qx "$n" "$CH_EXISTS" || exit 1; echo "$n"; exit 0 ;;
254
+ *) exit 0 ;;
255
+ esac ;;
256
+ *) exit 0 ;;
257
+ esac
258
+ SH
259
+ chmod +x "$cstub/gh"
260
+ export PATH="$cstub:$PATH"
261
+ edges() { sort "$CH_EDGES" | tr '\n' ';'; }
262
+
263
+ # happy path: 502 blocked_by 501, 503 blocked_by 502, each body records its predecessor
264
+ : > "$CH_LOG"
265
+ effort_chain 501 502 503 >/dev/null 2>&1; rc=$?
266
+ t "chain happy path returns 0" "$rc" "0"
267
+ t "chain sets both blocked_by edges" "$(edges)" "502 501;503 502;"
268
+ tc "$CH_DIR/body.502" '^- Depends on #501$' "chain records 'Depends on #501' in #502"
269
+ tc "$CH_DIR/body.503" '^- Depends on #502$' "chain records 'Depends on #502' in #503"
270
+ tc "$CH_DIR/body.502" '^## Relations$' "chain adds a ## Relations section"
271
+ t "chain leaves the head issue's body alone" "$(grep -c 'Depends on' "$CH_DIR/body.501")" "0"
272
+
273
+ # idempotency: a second identical run writes NOTHING — no POST, no body edit, no duplicate line
274
+ : > "$CH_LOG"
275
+ effort_chain 501 502 503 >/dev/null 2>&1; rc=$?
276
+ t "chain re-run returns 0" "$rc" "0"
277
+ t "chain re-run sets no new edge" "$(edges)" "502 501;503 502;"
278
+ t "chain re-run POSTs no dependency" "$(grep -c 'method POST' "$CH_LOG")" "0"
279
+ t "chain re-run edits no body" "$(grep -c 'issue edit' "$CH_LOG")" "0"
280
+ t "chain re-run leaves ONE Depends on line" "$(grep -c 'Depends on #501' "$CH_DIR/body.502")" "1"
281
+ # a `#`-prefixed number is the same issue
282
+ : > "$CH_LOG"
283
+ effort_chain '#501' '#502' >/dev/null 2>&1
284
+ t "chain accepts #-prefixed numbers" "$(grep -c 'method POST' "$CH_LOG")" "0"
285
+
286
+ # arity: fewer than two numbers is a usage error and writes nothing
287
+ : > "$CH_LOG"
288
+ effort_chain 501 >/dev/null 2>&1 && rc=0 || rc=1
289
+ t "chain refuses a single issue (rc 1)" "$rc" "1"
290
+ effort_chain >/dev/null 2>&1 && rc=0 || rc=1
291
+ t "chain refuses zero issues (rc 1)" "$rc" "1"
292
+ t "chain arity refusal writes nothing" "$(grep -cE 'method POST|issue edit' "$CH_LOG")" "0"
293
+
294
+ # a non-numeric argument is rejected up front
295
+ : > "$CH_LOG"
296
+ effort_chain 501 not-a-number >/dev/null 2>&1 && rc=0 || rc=1
297
+ t "chain refuses a non-numeric arg (rc 1)" "$rc" "1"
298
+ t "chain non-numeric refusal writes nothing" "$(grep -cE 'method POST|issue edit' "$CH_LOG")" "0"
299
+
300
+ # a nonexistent issue aborts the WHOLE chain — the earlier, valid link is not written either
301
+ : > "$CH_LOG"
302
+ effort_chain 504 999 >/dev/null 2>&1 && rc=0 || rc=1
303
+ t "chain refuses a nonexistent issue (rc 1)" "$rc" "1"
304
+ t "chain missing-issue refusal writes nothing" "$(grep -cE 'method POST|issue edit' "$CH_LOG")" "0"
305
+ t "chain missing-issue refusal adds no edge" "$(edges)" "502 501;503 502;"
306
+
307
+ # a repeated number is a cycle (`chain 1 2 1`) — refused whole
308
+ : > "$CH_LOG"
309
+ effort_chain 504 501 504 >/dev/null 2>&1 && rc=0 || rc=1
310
+ t "chain refuses a repeated number (rc 1)" "$rc" "1"
311
+ t "chain repeat refusal writes nothing" "$(grep -cE 'method POST|issue edit' "$CH_LOG")" "0"
312
+
313
+ # a cycle through edges GitHub ALREADY holds: 503 → 502 → 501 exists, so 501 blocked_by 503 loops
314
+ : > "$CH_LOG"
315
+ effort_chain 503 501 >/dev/null 2>&1 && rc=0 || rc=1
316
+ t "chain refuses a transitive cycle (rc 1)" "$rc" "1"
317
+ t "chain cycle refusal writes nothing" "$(grep -cE 'method POST|issue edit' "$CH_LOG")" "0"
318
+ t "chain cycle refusal adds no edge" "$(edges)" "502 501;503 502;"
319
+
320
+ # an issue already blocked by something ELSE keeps that blocker — chain only ever ADDS its edge
321
+ echo "504 601" >> "$CH_EDGES"
322
+ : > "$CH_LOG"
323
+ effort_chain 501 504 >/dev/null 2>&1; rc=$?
324
+ t "chain wires an already-blocked issue (rc 0)" "$rc" "0"
325
+ t "chain preserves the pre-existing blocker" "$(edges)" "502 501;503 502;504 501;504 601;"
326
+ tc "$CH_DIR/body.504" '^- Depends on #501$' "chain records its own dep on an already-blocked issue"
327
+
328
+ # The summary banner must agree with rc. A ✓ over a nonzero exit reports a chain that is not fully
329
+ # wired, so the failure is invisible to anything reading stderr rather than $?.
330
+ : > "$CH_LOG"
331
+ out="$(effort_chain 501 502 2>&1)"; rc=$?
332
+ t "chain banner: rc 0 on a clean run" "$rc" "0"
333
+ case "$out" in *"✓ chain"*) t "chain banner: ✓ on success" ok ok ;; *) t "chain banner: ✓ on success" "$out" "✓ chain" ;; esac
334
+
335
+ # A POST-validation failure: #601 exists and passes pre-flight, but its body edit fails. This is the
336
+ # only path that reaches rc=1 with writes already attempted — every pre-flight refusal returns early.
337
+ : > "$CH_LOG"
338
+ out="$(CH_FAIL_EDIT=601 effort_chain 502 601 2>&1)"; rc=$?
339
+ t "chain returns rc 1 when a body edit fails" "$rc" "1"
340
+ case "$out" in
341
+ *"✓ chain"*) t "chain banner: no ✓ when a link failed" "$out" "(no '✓ chain')" ;;
342
+ *"✗ chain"*) t "chain banner: ✗ when a link failed" "ok" "ok" ;;
343
+ *) t "chain banner: ✗ when a link failed" "$out" "✗ chain" ;;
344
+ esac
345
+
346
+ # ── #244 · effort_start enforces a WIP limit ──────────────────────────────────────────────────────
347
+ # In progress = an `effort/<N>-<slug>` ref exists (local head OR remote-tracking) — the same scan the
348
+ # slug resolver uses. Its own throwaway repo + bare remote so the branch inventory is exactly what
349
+ # each case sets up, and its own gh log so "a refusal writes NOTHING" can be asserted against zero
350
+ # gh calls as well as zero refs.
351
+ wtmp="$tmp/wip"; mkdir -p "$wtmp"
352
+ ( cd "$wtmp" && git init -q --bare remote.git )
353
+ ( cd "$wtmp" && git clone -q remote.git work \
354
+ && cd work && git -c user.email=t@t -c user.name=t commit -q --allow-empty -m init \
355
+ && git push -q origin HEAD:main )
356
+ cd "$wtmp/work" || exit 1
357
+ unset EFFORT_WIP_LIMIT KIT_EFFORT_WIP_LIMIT KIT_FORCE 2>/dev/null || true
358
+ # `gh` on PATH here is the chain stub, which logs to $CH_LOG — that is the log a refusal must leave
359
+ # empty, so the "writes nothing" assertions read it rather than $GH_LOG.
360
+
361
+ wip_started() { git show-ref --verify --quiet "refs/heads/effort/$1" && echo yes || echo no; }
362
+ wip_reset() { git checkout -q main 2>/dev/null; \
363
+ for b in $(git for-each-ref --format='%(refname:short)' 'refs/heads/effort/*'); do
364
+ git worktree remove --force ".claude/worktrees/effort+${b#effort/}" >/dev/null 2>&1
365
+ git branch -D "$b" >/dev/null 2>&1
366
+ done; git worktree prune >/dev/null 2>&1; }
367
+
368
+ # 1. under the limit → starts. Nothing in progress, default limit 2.
369
+ effort_start 701 one >/dev/null 2>&1; rc=$?
370
+ t "wip: under the limit starts (rc 0)" "$rc" "0"
371
+ t "wip: under the limit created the branch" "$(wip_started 701-one)" "yes"
372
+
373
+ # 2. the SECOND effort still starts (1 < 2) — the limit is a ceiling, not a one-at-a-time rule.
374
+ effort_start 702 two >/dev/null 2>&1; rc=$?
375
+ t "wip: the second effort starts (rc 0)" "$rc" "0"
376
+
377
+ # 3. AT the limit (2 in progress, limit 2) → refuse. A third would make three.
378
+ : > "$CH_LOG"
379
+ out="$(effort_start 703 three 2>&1)"; rc=$?
380
+ t "wip: at the limit refuses (rc 1)" "$rc" "1"
381
+ case "$out" in *"WIP limit is 2"*) echo "ok: refusal names the limit" ;; *) echo "FAIL: refusal did not name the limit: $out"; fail=1 ;; esac
382
+ case "$out" in *"one #701"*) echo "ok: refusal lists what is in progress" ;; *) echo "FAIL: refusal did not list #701: $out"; fail=1 ;; esac
383
+ case "$out" in *"--force"*) echo "ok: refusal says how to override" ;; *) echo "FAIL: refusal did not mention --force: $out"; fail=1 ;; esac
384
+ case "$out" in *"effort.wipLimit"*) echo "ok: refusal names the config key" ;; *) echo "FAIL: refusal did not name effort.wipLimit: $out"; fail=1 ;; esac
385
+ # …and the refusal WRITES nothing: no branch, no worktree dir, no board change.
386
+ t "wip: refusal created no branch" "$(wip_started 703-three)" "no"
387
+ t "wip: refusal created no worktree" "$(ls -d .claude/worktrees/effort+703-three 2>/dev/null | wc -l | tr -d ' ')" "0"
388
+ # For a NUMERIC argument the refusal also makes no gh call — the number is passed through, so no
389
+ # resolution happens. This is NOT the guarantee for a <slug> argument (see the next assertion), and
390
+ # the docs claim only "no branch, no worktree, no board change" (#244 review).
391
+ t "wip: a numeric-arg refusal made no gh call" "$(grep -c . "$CH_LOG" | tr -d ' ')" "0"
392
+ # A SLUG argument is resolved BEFORE the gate, and the resolver falls through to `gh issue list`
393
+ # when no branch matches — so a refusal on that path can read from GitHub. Asserted on the resolver
394
+ # itself, which is the mechanism the narrowed doc claim refers to.
395
+ : > "$CH_LOG"
396
+ effort_slug_resolve no-such-effort-anywhere >/dev/null 2>&1 || true
397
+ t "wip: resolving a slug with no branch DOES call gh" \
398
+ "$(grep -c 'issue list' "$CH_LOG" | tr -d ' ')" "2"
399
+
400
+ # 4. --force starts anyway (and says so).
401
+ out="$(effort_start --force 703 three 2>&1)"; rc=$?
402
+ t "wip: --force starts anyway (rc 0)" "$rc" "0"
403
+ t "wip: --force created the branch" "$(wip_started 703-three)" "yes"
404
+ case "$out" in *"anyway"*) echo "ok: --force announces the override" ;; *) echo "FAIL: --force said nothing: $out"; fail=1 ;; esac
405
+
406
+ # 5. ABOVE the limit (3 in progress, limit 2) still refuses.
407
+ effort_start 704 four >/dev/null 2>&1; rc=$?
408
+ t "wip: above the limit refuses (rc 1)" "$rc" "1"
409
+ t "wip: above the limit created no branch" "$(wip_started 704-four)" "no"
410
+
411
+ # 6. KIT_FORCE=1 — the same escape hatch effort_close uses — starts anyway.
412
+ KIT_FORCE=1 effort_start 704 four >/dev/null 2>&1; rc=$?
413
+ t "wip: KIT_FORCE=1 starts anyway (rc 0)" "$rc" "0"
414
+ t "wip: KIT_FORCE=1 created the branch" "$(wip_started 704-four)" "yes"
415
+
416
+ # 7. re-running start on an ALREADY in-progress effort is never gated — it adds no WIP, so
417
+ # `effort start` stays safe to re-run even when the set is at or over the limit.
418
+ out="$(effort_start 701 one 2>&1)"; rc=$?
419
+ t "wip: re-starting an in-progress effort is allowed (rc 0)" "$rc" "0"
420
+ case "$out" in *"WIP limit"*) echo "FAIL: re-start hit the WIP gate: $out"; fail=1 ;; *) echo "ok: re-start bypasses the gate" ;; esac
421
+
422
+ # 8. a REMOTE-only effort branch counts as in progress (another machine owns it).
423
+ wip_reset
424
+ git push -q origin main:refs/heads/effort/705-remote-only
425
+ git fetch -q origin
426
+ t "wip: only a remote effort ref is present" "$(effort_wip_rows | tr '\t' '-' | tr '\n' ' ')" "705-remote-only "
427
+ EFFORT_WIP_LIMIT=1 effort_start 706 local-one >/dev/null 2>&1; rc=$?
428
+ t "wip: a remote-only effort branch counts toward the limit (rc 1)" "$rc" "1"
429
+ git push -q origin :refs/heads/effort/705-remote-only; git fetch -q --prune origin
430
+
431
+ # ── #244 review · the cached refs/remotes is wrong in BOTH directions ─────────────────────────────
432
+ # effort_wip_rows reads origin with `git ls-remote`, not refs/remotes, because the cache under- and
433
+ # over-counts and a gate is wrong with either. Both directions are reproduced here against the real
434
+ # bare remote, with the local cache deliberately left un-fetched / un-pruned.
435
+
436
+ # 8a. OVER-count: a branch DELETED on origin lingers in refs/remotes until a prune. The stale ref
437
+ # must not block a start. The delete is written into the bare remote rather than pushed from
438
+ # here as `origin :ref` — a delete-push updates THIS clone's tracking ref, which would hide the
439
+ # staleness under test. Writing the remote is the "another machine deleted it" case.
440
+ wip_reset
441
+ git push -q origin main:refs/heads/effort/720-stale
442
+ git fetch -q origin # cache it
443
+ git --git-dir="$wtmp/remote.git" update-ref -d refs/heads/effort/720-stale
444
+ t "wip: the deleted branch is still in the local cache" \
445
+ "$(git for-each-ref --format='%(refname:short)' refs/remotes 2>/dev/null | grep -c 'effort/720-stale' | tr -d ' ')" "1"
446
+ t "wip: a stale remote-tracking ref is NOT counted" \
447
+ "$(effort_wip_rows | grep -c '^720' | tr -d ' ')" "0"
448
+ EFFORT_WIP_LIMIT=1 effort_start 721 not-blocked >/dev/null 2>&1; rc=$?
449
+ t "wip: a stale ref does not block a start (rc 0)" "$rc" "0"
450
+ t "wip: the unblocked start created its branch" "$(wip_started 721-not-blocked)" "yes"
451
+ git fetch -q --prune origin
452
+
453
+ # 8b. UNDER-count: a branch pushed to origin since the last fetch is absent from refs/remotes — and
454
+ # effort_start's own fetch is base-only, so it would never appear. It must still be counted.
455
+ # `git update-ref` inside the bare remote is the "another machine pushed" case with no fetch.
456
+ wip_reset
457
+ git --git-dir="$wtmp/remote.git" update-ref refs/heads/effort/722-unfetched \
458
+ "$(git rev-parse origin/main)"
459
+ t "wip: the new branch is absent from the local cache" \
460
+ "$(git for-each-ref --format='%(refname:short)' refs/remotes 2>/dev/null | grep -c 'effort/722-unfetched' | tr -d ' ')" "0"
461
+ t "wip: an unfetched origin branch IS counted" \
462
+ "$(effort_wip_rows | grep -c '^722' | tr -d ' ')" "1"
463
+ out="$(EFFORT_WIP_LIMIT=1 effort_start 723 blocked-by-unfetched 2>&1)"; rc=$?
464
+ t "wip: an unfetched origin branch blocks a start (rc 1)" "$rc" "1"
465
+ t "wip: that refusal created no branch" "$(wip_started 723-blocked-by-unfetched)" "no"
466
+ case "$out" in *"722"*) echo "ok: the refusal names the unfetched effort" ;; *) echo "FAIL: refusal did not name #722: $out"; fail=1 ;; esac
467
+
468
+ # 8c. EFFORT_WIP_REMOTE=0 opts out of the origin query and counts the cache — so with the same
469
+ # un-fetched origin branch the count goes back to the old approximation (absent), which is
470
+ # exactly what "deterministic offline mode" means.
471
+ t "wip: EFFORT_WIP_REMOTE=0 skips the origin query" \
472
+ "$(EFFORT_WIP_REMOTE=0 effort_wip_rows | grep -c '^722' | tr -d ' ')" "0"
473
+ EFFORT_WIP_REMOTE=0 EFFORT_WIP_LIMIT=1 effort_start 724 optout >/dev/null 2>&1; rc=$?
474
+ t "wip: EFFORT_WIP_REMOTE=0 starts under the cached count (rc 0)" "$rc" "0"
475
+ wip_reset
476
+ git --git-dir="$wtmp/remote.git" update-ref -d refs/heads/effort/722-unfetched
477
+
478
+ # 8d. an UNREACHABLE origin must not fail the start: the count falls back to the cached refs, warns
479
+ # once on stderr, and the gate proceeds. A gate that hard-fails offline is worse than one that
480
+ # miscounts.
481
+ wip_reset
482
+ git remote set-url origin "$wtmp/nope-does-not-exist.git"
483
+ rows_out="$(effort_wip_rows 2>&1 >/dev/null)"
484
+ case "$rows_out" in *"may be stale"*) echo "ok: an unreachable origin warns" ;; *) echo "FAIL: no staleness warning: $rows_out"; fail=1 ;; esac
485
+ out="$(effort_start 725 offline 2>&1)"; rc=$?
486
+ t "wip: an unreachable origin still starts the effort (rc 0)" "$rc" "0"
487
+ t "wip: the offline start created its branch" "$(wip_started 725-offline)" "yes"
488
+ git remote set-url origin "$wtmp/remote.git"
489
+ wip_reset
490
+
491
+ # 9. limit 0 freezes new efforts entirely (nothing in progress, and still a refusal).
492
+ wip_reset
493
+ EFFORT_WIP_LIMIT=0 effort_start 707 frozen >/dev/null 2>&1; rc=$?
494
+ t "wip: limit 0 refuses with nothing in progress (rc 1)" "$rc" "1"
495
+ t "wip: limit 0 created no branch" "$(wip_started 707-frozen)" "no"
496
+ EFFORT_WIP_LIMIT=0 effort_start --force 707 frozen >/dev/null 2>&1; rc=$?
497
+ t "wip: limit 0 is still overridable (rc 0)" "$rc" "0"
498
+
499
+ # 10. a misconfigured limit is IGNORED with a warning and the built-in default (2) is used —
500
+ # a typo must neither disable the gate nor wedge the verb.
501
+ wip_reset
502
+ out="$(EFFORT_WIP_LIMIT=lots effort_start 708 typo 2>&1)"; rc=$?
503
+ t "wip: a non-numeric limit still starts under the default (rc 0)" "$rc" "0"
504
+ case "$out" in *"must be a non-negative integer"*) echo "ok: a bad limit warns" ;; *) echo "FAIL: no warning for a bad limit: $out"; fail=1 ;; esac
505
+ out="$(EFFORT_WIP_LIMIT=-1 effort_start 709 negative 2>&1)"; rc=$?
506
+ t "wip: a negative limit falls back to the default too (rc 0)" "$rc" "0"
507
+ # two are now in progress under the fallback default of 2 → the next one is refused
508
+ EFFORT_WIP_LIMIT=lots effort_start 710 third >/dev/null 2>&1; rc=$?
509
+ t "wip: the fallback default is really 2 (rc 1)" "$rc" "1"
510
+
511
+ # 11. the limit is read from `effort.wipLimit` in the project config when no env var is set…
512
+ wip_reset
513
+ mkdir -p .claude
514
+ printf '{"effort":{"wipLimit":1}}\n' > .claude/kit.config.json
515
+ effort_start 711 from-config >/dev/null 2>&1
516
+ out="$(effort_start 712 from-config-two 2>&1)"; rc=$?
517
+ t "wip: effort.wipLimit=1 refuses the second effort (rc 1)" "$rc" "1"
518
+ case "$out" in *"WIP limit is 1"*) echo "ok: the configured limit is the one enforced" ;; *) echo "FAIL: config limit not used: $out"; fail=1 ;; esac
519
+ # …and EFFORT_WIP_LIMIT wins over it, per invocation.
520
+ EFFORT_WIP_LIMIT=3 effort_start 712 from-config-two >/dev/null 2>&1; rc=$?
521
+ t "wip: EFFORT_WIP_LIMIT overrides the config (rc 0)" "$rc" "0"
522
+ # KIT_EFFORT_WIP_LIMIT (what load_kit_config exports) is read when EFFORT_WIP_LIMIT is unset.
523
+ wip_reset
524
+ out="$(KIT_EFFORT_WIP_LIMIT=0 effort_start 713 kitenv 2>&1)"; rc=$?
525
+ t "wip: KIT_EFFORT_WIP_LIMIT is honoured (rc 1)" "$rc" "1"
526
+ rm -f .claude/kit.config.json
527
+
528
+ # 12. effort_wip_rows counts each effort ONCE even when local + remote refs both carry it.
529
+ wip_reset
530
+ effort_start 714 dedup >/dev/null 2>&1
531
+ git push -q origin effort/714-dedup; git fetch -q origin
532
+ t "wip: local + remote refs count as one effort" "$(effort_wip_rows | wc -l | tr -d ' ')" "1"
533
+ git push -q origin :refs/heads/effort/714-dedup >/dev/null 2>&1; git fetch -q --prune origin
534
+ wip_reset
535
+
536
+ # 13. an unknown flag is rejected before anything happens.
537
+ : > "$CH_LOG"
538
+ effort_start --nope 715 x >/dev/null 2>&1; rc=$?
539
+ t "wip: an unknown flag is rejected (rc 1)" "$rc" "1"
540
+ t "wip: an unknown flag writes nothing" "$(grep -c . "$CH_LOG" | tr -d ' ')" "0"
541
+
542
+ # 14. scope: the gate is an EFFORT gate. `cckit start <issue>` (wt_start, worktree-start.sh) has no
543
+ # WIP limit — a static guard so widening the scope can't happen by accident.
544
+ t "wip: the plain-task start path is not gated" \
545
+ "$(grep -c '_eff_wip_gate\|effort_wip_rows' "$LIB/worktree-start.sh" | tr -d ' ')" "0"
546
+
547
+ cd "$tmp/work" || exit 1
548
+
189
549
  [ "$fail" -eq 0 ] && echo "ALL OK (effort-ops)" || echo "effort-ops: FAILURES"
190
550
  exit "$fail"