@jeiemgi/cckit 0.6.1 → 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 (114) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +34 -3
  3. package/README.md +86 -5
  4. package/bin/cckit +72 -3
  5. package/cckit.config.json +6 -1
  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/init.sh +31 -1
  14. package/scripts/lib/board-view-test.sh +1 -0
  15. package/scripts/lib/board-view.sh +1 -0
  16. package/scripts/lib/captain-test.sh +62 -0
  17. package/scripts/lib/captain.sh +105 -17
  18. package/scripts/lib/cckit-output.sh +1 -0
  19. package/scripts/lib/commitlint.sh +1 -0
  20. package/scripts/lib/config-path-test.sh +1 -0
  21. package/scripts/lib/config-path.sh +1 -0
  22. package/scripts/lib/copilot-test.sh +1 -0
  23. package/scripts/lib/copilot.sh +1 -0
  24. package/scripts/lib/effort-dispatch-test.sh +10 -0
  25. package/scripts/lib/effort-flows-test.sh +1 -0
  26. package/scripts/lib/effort-metrics-test.sh +1 -0
  27. package/scripts/lib/effort-metrics.sh +1 -0
  28. package/scripts/lib/effort-ops-test.sh +360 -0
  29. package/scripts/lib/effort-ops.sh +372 -16
  30. package/scripts/lib/effort-parity-test.sh +1 -0
  31. package/scripts/lib/effort-plan.sh +1 -0
  32. package/scripts/lib/effort-slug-test.sh +32 -0
  33. package/scripts/lib/effort-slug.sh +72 -8
  34. package/scripts/lib/effort.sh +1 -0
  35. package/scripts/lib/engine-adapter.sh +1 -0
  36. package/scripts/lib/errors-header-test.sh +86 -0
  37. package/scripts/lib/gh-log.sh +1 -0
  38. package/scripts/lib/gh-project-test.sh +1 -0
  39. package/scripts/lib/gh-project.sh +1 -0
  40. package/scripts/lib/git-remote-test.sh +1 -0
  41. package/scripts/lib/git-remote.sh +1 -0
  42. package/scripts/lib/handoff.sh +23 -2
  43. package/scripts/lib/kit-brief-test.sh +292 -0
  44. package/scripts/lib/kit-brief.sh +376 -0
  45. package/scripts/lib/kit-cli-test.sh +1 -0
  46. package/scripts/lib/kit-cli.sh +1 -0
  47. package/scripts/lib/kit-config-resolve.sh +1 -0
  48. package/scripts/lib/kit-config-test.sh +14 -0
  49. package/scripts/lib/kit-config.sh +7 -0
  50. package/scripts/lib/kit-engine-test.sh +1 -0
  51. package/scripts/lib/kit-events.sh +1 -0
  52. package/scripts/lib/kit-gc-test.sh +125 -0
  53. package/scripts/lib/kit-gc.sh +193 -5
  54. package/scripts/lib/kit-interview-test.sh +1 -0
  55. package/scripts/lib/kit-interview.sh +1 -0
  56. package/scripts/lib/kit-lib-test.sh +226 -0
  57. package/scripts/lib/kit-lib.sh +308 -0
  58. package/scripts/lib/kit-local.sh +1 -0
  59. package/scripts/lib/kit-manifest.sh +1 -0
  60. package/scripts/lib/kit-mode-test.sh +1 -0
  61. package/scripts/lib/kit-mode.sh +1 -0
  62. package/scripts/lib/kit-msg-test.sh +1 -0
  63. package/scripts/lib/kit-msg.sh +1 -0
  64. package/scripts/lib/kit-operate.sh +1 -0
  65. package/scripts/lib/kit-profile-test.sh +1 -0
  66. package/scripts/lib/kit-profile.sh +1 -0
  67. package/scripts/lib/kit-state-test.sh +89 -0
  68. package/scripts/lib/kit-state.sh +61 -0
  69. package/scripts/lib/kit-status-test.sh +233 -0
  70. package/scripts/lib/kit-status.sh +415 -0
  71. package/scripts/lib/kit-task-ops-test.sh +1 -0
  72. package/scripts/lib/kit-task-ops.sh +1 -0
  73. package/scripts/lib/next.sh +1 -0
  74. package/scripts/lib/plan-machine-test.sh +54 -0
  75. package/scripts/lib/plan-machine.sh +86 -25
  76. package/scripts/lib/plan-next-test.sh +1 -0
  77. package/scripts/lib/plan-next.sh +1 -0
  78. package/scripts/lib/pr-evidence-test.sh +259 -0
  79. package/scripts/lib/pr-evidence.sh +220 -35
  80. package/scripts/lib/project-scan.sh +1 -0
  81. package/scripts/lib/react-detect.sh +1 -0
  82. package/scripts/lib/render-test.sh +1 -0
  83. package/scripts/lib/render.sh +1 -0
  84. package/scripts/lib/role-identity.sh +1 -0
  85. package/scripts/lib/secret-guard.sh +21 -1
  86. package/scripts/lib/toon.sh +1 -0
  87. package/scripts/lib/ui.sh +1 -0
  88. package/scripts/lib/version-bump-test.sh +1 -0
  89. package/scripts/lib/version-bump.sh +1 -0
  90. package/scripts/lib/worktree-bootstrap-test.sh +220 -0
  91. package/scripts/lib/worktree-issue-test.sh +15 -1
  92. package/scripts/lib/worktree-issue.sh +23 -8
  93. package/scripts/lib/worktree-start.sh +191 -7
  94. package/scripts/lib/zsh-safety-test.sh +10 -0
  95. package/scripts/portable-test.sh +13 -2
  96. package/scripts/self-install-test.sh +282 -0
  97. package/scripts/setup-labels.sh +1 -0
  98. package/scripts/status.sh +25 -10
  99. package/skills/kit-cleanup/SKILL.md +83 -0
  100. package/skills/kit-effort-close/SKILL.md +3 -0
  101. package/skills/kit-effort-new/SKILL.md +7 -0
  102. package/skills/kit-effort-start/SKILL.md +39 -4
  103. package/skills/kit-gc/SKILL.md +19 -0
  104. package/skills/kit-next/SKILL.md +5 -0
  105. package/skills/kit-status/SKILL.md +92 -0
  106. package/skills/kit-task-start/SKILL.md +7 -1
  107. package/templates/rules/branch-naming.md +20 -1
  108. package/templates/rules/communication-style.md +8 -0
  109. package/templates/rules/delegation-brief.md +38 -4
  110. package/templates/rules/effort-model.md +47 -4
  111. package/templates/rules/naming-and-ids.md +199 -0
  112. package/templates/rules/task-management.md +1 -1
  113. package/templates/skills/concrete/SKILL.md +117 -0
  114. package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # errors-header-test.sh — enforce the `# errors:` header on every scripts/lib helper (#223).
4
+ #
5
+ # The header says whether a helper propagates a failure or swallows it. Both are correct designs,
6
+ # but the difference used to live only in prose, so a caller that mixed a strict helper with a
7
+ # best-effort one silently inherited the weaker behavior — and nothing could assert otherwise.
8
+ # This test is what makes the header a rule instead of a habit: a new lib file without one, or with
9
+ # a value outside the vocabulary, fails here. Run: bash scripts/lib/errors-header-test.sh
10
+ # errors: strict — a test runner: rc 1 on any failed assertion
11
+ set -u
12
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
13
+ LIB="$ROOT/scripts/lib"
14
+ fail=0
15
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
16
+
17
+ # The vocabulary. Adding a fifth value is a deliberate change — update this list and the docs table.
18
+ VOCAB="pure strict best-effort mixed"
19
+
20
+ in_vocab() {
21
+ local v="$1" x
22
+ for x in $VOCAB; do [ "$v" = "$x" ] && return 0; done
23
+ return 1
24
+ }
25
+
26
+ # errors_header <file> — the declared value, or empty when the file has no header line.
27
+ errors_header() {
28
+ # Bounded to the LEADING comment block, matching kit_lib_errors (_kl_header): the shebang and
29
+ # blanks skipped, comments taken up to the first line of code. A later `# errors:` line in the
30
+ # body is not the file's declaration. A fixed line window would be wrong — two libs carry headers
31
+ # that run past 25 lines.
32
+ awk 'NR==1 && /^#!/ {next} /^[[:space:]]*#/ {print; next} /^[[:space:]]*$/ {next} {exit}' "$1" | sed -n 's/^# errors:[[:space:]]*\([a-z-]*\).*/\1/p' | head -1
33
+ }
34
+
35
+ # ── 1. every lib file declares one, and it is in the vocabulary ────────────────────────────────
36
+ missing=0 bad=0 n=0
37
+ for f in "$LIB"/*.sh; do
38
+ n=$((n + 1))
39
+ v="$(errors_header "$f")"
40
+ if [ -z "$v" ]; then
41
+ echo "FAIL: no '# errors:' header -> $(basename "$f")"
42
+ missing=$((missing + 1)); fail=1
43
+ elif ! in_vocab "$v"; then
44
+ echo "FAIL: '$v' is not in the vocabulary ($VOCAB) -> $(basename "$f")"
45
+ bad=$((bad + 1)); fail=1
46
+ fi
47
+ done
48
+ [ "$n" -gt 0 ] || { echo "FAIL: found no lib files to check"; fail=1; }
49
+ t "every lib file has a header" "$missing" "0"
50
+ t "every value is in the vocabulary" "$bad" "0"
51
+
52
+ # ── 2. the header carries a reason, not just a value ───────────────────────────────────────────
53
+ # A bare "# errors: mixed" tells a reader nothing about WHICH half is which, which is the whole
54
+ # point for a mixed file. Require the em-dash reason.
55
+ noreason=0
56
+ for f in "$LIB"/*.sh; do
57
+ # `[^[:space:]]` after the dash, not `.+`: `.+` is satisfied by trailing spaces, so a header
58
+ # ending "— " would count as carrying a reason while telling a reader nothing.
59
+ grep -qE '^# errors: (pure|strict|best-effort|mixed) —[[:space:]]*[^[:space:]]' "$f" || {
60
+ echo "FAIL: header has no reason after the em dash -> $(basename "$f")"
61
+ noreason=$((noreason + 1)); fail=1
62
+ }
63
+ done
64
+ t "every header carries a reason" "$noreason" "0"
65
+
66
+ # ── 3. the parser itself, on fixtures (pure; no repo files) ────────────────────────────────────
67
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
68
+ printf '#!/usr/bin/env bash\n# x.sh — a thing.\n# errors: best-effort — warns and returns 0\nx() { :; }\n' > "$tmp/a.sh"
69
+ printf '#!/usr/bin/env bash\n# y.sh — a thing.\ny() { :; }\n' > "$tmp/b.sh"
70
+ t "parses a declared value" "$(errors_header "$tmp/a.sh")" "best-effort"
71
+ t "empty when undeclared" "$(errors_header "$tmp/b.sh")" ""
72
+ if in_vocab "best-effort"; then t "vocabulary accepts best-effort" "yes" "yes"; else t "vocabulary accepts best-effort" "no" "yes"; fi
73
+ if in_vocab "silent"; then t "vocabulary rejects an unknown value" "accepted" "rejected"; else t "vocabulary rejects an unknown value" "rejected" "rejected"; fi
74
+
75
+ # ── 4. a strict file must not claim to be pure ─────────────────────────────────────────────────
76
+ # Cheap consistency check: a file declaring `pure` should not carry a `set -e`, which only matters
77
+ # when the file shells out to something that can fail.
78
+ liars=0
79
+ for f in "$LIB"/*.sh; do
80
+ [ "$(errors_header "$f")" = "pure" ] || continue
81
+ grep -qE '^set -[a-z]*e' "$f" && { echo "FAIL: declares pure but sets -e -> $(basename "$f")"; liars=$((liars + 1)); fail=1; }
82
+ done
83
+ t "no pure file sets -e" "$liars" "0"
84
+
85
+ if [ "$fail" -eq 0 ]; then echo "errors-header-test: OK ($n lib files)"; else echo "errors-header-test: FAILED"; fi
86
+ exit "$fail"
@@ -12,6 +12,7 @@
12
12
  # Log: one JSON line per call appended to <git-common-dir>/gh-requests.jsonl
13
13
  # {ts, kind:"graphql|rest", op:"query|mutation|GET|POST|…", label, points, surface, pid}
14
14
  # Disable with KIT_GH_LOG=0. Never fails a caller (logging is best-effort).
15
+ # errors: best-effort — logging never fails a caller
15
16
 
16
17
  GH_LOG_FILE="${GH_LOG_FILE:-$(git rev-parse --git-common-dir 2>/dev/null)/gh-requests.jsonl}"
17
18
 
@@ -6,6 +6,7 @@
6
6
  # Covered: _ghp_owner_root resolution, kit-config exporting KIT_PROJECT_OWNER_TYPE, and
7
7
  # capture-project-ids.sh selecting the matching root end-to-end (stubbed gh — no network).
8
8
  # Run: bash scripts/lib/gh-project-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
  LIB="$ROOT/scripts/lib"
@@ -2,6 +2,7 @@
2
2
  # Helpers for GitHub Projects v2 via gh CLI + GraphQL.
3
3
  # Source after kit-config.sh: source scripts/lib/gh-project.sh; load_project_ids
4
4
  # Requires scripts/.project-ids.env — populate via scripts/capture-project-ids.sh.
5
+ # errors: strict — a failed GraphQL call propagates; the board is not guessed
5
6
 
6
7
  # Locate scripts/ portably when sourced (#313): BASH_SOURCE is bash-only — empty in
7
8
  # zsh, where dirname "" resolved to CWD and the env was sought in the wrong dir.
@@ -4,6 +4,7 @@
4
4
  # NAME / slug / wing come from the ACTUAL repo name (not a cloned/renamed directory basename). Also
5
5
  # checks the host-agnostic URL parsing (ssh, https, GHE/GitLab). Hermetic: a throwaway git repo with
6
6
  # a fake remote. Run: bash scripts/lib/git-remote-test.sh
7
+ # errors: strict — a test runner: rc 1 on any failed assertion
7
8
  set -u
8
9
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
9
10
  LIB="$ROOT/scripts/lib"
@@ -8,6 +8,7 @@
8
8
  # git_remote_slug [dir] -> "owner/repo" from origin (rc 1 + empty when no remote)
9
9
  # git_remote_repo_name [dir] -> "repo"
10
10
  # git_remote_owner [dir] -> "owner"
11
+ # errors: strict — rc 1 + empty when there is no remote
11
12
 
12
13
  git_remote_slug() {
13
14
  local dir="${1:-$PWD}" url
@@ -3,9 +3,30 @@
3
3
  # "resume here" note; the next session (bare `cckit`) prints it so the operator or agent picks up
4
4
  # exactly where the last one left off. The note is LOCAL (.cckit/handoff.md, gitignored) - it is
5
5
  # session state, not a repo artifact.
6
+ # errors: best-effort — session state, not a repo artifact
6
7
 
7
- _handoff_root() { git rev-parse --show-toplevel 2>/dev/null || pwd; }
8
- _handoff_file() { printf '%s/.cckit/handoff.md' "$(_handoff_root)"; }
8
+ # The note must be the SAME file from the primary checkout and from every worktree. It used to
9
+ # resolve via `git rev-parse --show-toplevel`, which returns the WORKTREE's root inside a worktree —
10
+ # so a handoff written from the main checkout was invisible from every worktree (and vice versa),
11
+ # silently, with `cckit` reporting "no resume-here handoff saved". kit-state.sh resolves the one
12
+ # shared .cckit/ via --git-common-dir instead.
13
+ if [ -n "${BASH_SOURCE:-}" ]; then
14
+ _ho_self="$BASH_SOURCE"
15
+ elif [ -n "${ZSH_VERSION:-}" ]; then
16
+ eval '_ho_self="${(%):-%x}"'
17
+ else
18
+ _ho_self="$0"
19
+ fi
20
+ if [ -f "$(dirname "$_ho_self")/kit-state.sh" ]; then
21
+ # shellcheck source=kit-state.sh
22
+ . "$(dirname "$_ho_self")/kit-state.sh"
23
+ fi
24
+ unset _ho_self
25
+
26
+ _handoff_file() {
27
+ if command -v kit_state_file >/dev/null 2>&1; then kit_state_file handoff.md
28
+ else printf '%s/.cckit/handoff.md' "$(git rev-parse --show-toplevel 2>/dev/null || pwd)"; fi
29
+ }
9
30
 
10
31
  # handoff_write [text] - save the resume note from "$*" or, if none, stdin.
11
32
  handoff_write() {
@@ -0,0 +1,292 @@
1
+ #!/bin/sh
2
+ # kit-brief-test.sh — self-test for kit-brief.sh, the delegation-brief generator (Effort 220 · #221).
3
+ # Network-free and repo-free: the text parsers run against fixture strings, and the git-dependent
4
+ # lookups (seed freshness, worktree association, basename resolution) run against a throwaway repo
5
+ # with a fabricated `origin/` ref — so nothing here depends on what this checkout looks like today.
6
+ # Every assertion runs under bash AND zsh, because the verb is sourced by a dispatcher that may be
7
+ # either and the parsers use parameter expansion that the two shells disagree about.
8
+ # Run: bash scripts/lib/kit-brief-test.sh
9
+ # errors: strict — a test runner: rc 1 on any failed assertion
10
+
11
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
12
+
13
+ if [ -n "${KB_TEST_INNER:-}" ]; then
14
+ fail=0
15
+ eq() { if [ "$2" = "$3" ]; then :; else echo "FAIL($KB_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
16
+ has() { case "$2" in *"$3"*) : ;; *) echo "FAIL($KB_TEST_INNER): $1 -> '$2' lacks '$3'"; fail=1 ;; esac; }
17
+ no() { case "$2" in *"$3"*) echo "FAIL($KB_TEST_INNER): $1 -> '$2' should not contain '$3'"; fail=1 ;; *) : ;; esac; }
18
+
19
+ # shellcheck source=/dev/null
20
+ . "$dir/kit-brief.sh"
21
+
22
+ # ── kit_brief_section ────────────────────────────────────────────────────────────────────────
23
+ body='## Goal
24
+
25
+ why this exists
26
+
27
+ ## For agents
28
+
29
+ build order matters
30
+
31
+ - `scripts/lib/a.sh`
32
+
33
+ ## Verification
34
+
35
+ green'
36
+ sec="$(printf '%s\n' "$body" | kit_brief_section "For agents")"
37
+ has "section body" "$sec" "build order matters"
38
+ has "section keeps its list" "$sec" 'scripts/lib/a.sh'
39
+ no "section stops at the next heading" "$sec" "green"
40
+ no "section excludes its own heading" "$sec" "## For agents"
41
+ # the trim runs at both ends, so a lifted section drops in without a stray gap
42
+ eq "section trims leading blank" "$(printf '%s\n' "$sec" | head -1)" "build order matters"
43
+ eq "section trims trailing blank" "$(printf '%s\n' "$sec" | tail -1)" '- `scripts/lib/a.sh`'
44
+ eq "absent section is empty" "$(printf '%s\n' "$body" | kit_brief_section "Nope")" ""
45
+ # heading match is case-insensitive but not a prefix match
46
+ has "section matches case-insensitively" \
47
+ "$(printf '%s\n' "$body" | kit_brief_section "for agents")" "build order matters"
48
+
49
+ # ── kit_brief_files ──────────────────────────────────────────────────────────────────────────
50
+ text='Edit `scripts/lib/captain.sh` and captain-test.sh, plus docs/ and README.md.
51
+ Files: scripts/lib/kit-brief.sh, bin/cckit, docs-site/src/content/docs/cli-reference.mdx
52
+ See https://example.com/thing.md for context. Ignore prose words like errors: and mixed.'
53
+ f="$(printf '%s\n' "$text" | kit_brief_files)"
54
+ has "path from backticks" "$f" "scripts/lib/captain.sh"
55
+ has "bare basename token" "$f" "captain-test.sh"
56
+ has "directory token" "$f" "docs/"
57
+ has "path from a Files: line" "$f" "scripts/lib/kit-brief.sh"
58
+ has "mdx path" "$f" "docs-site/src/content/docs/cli-reference.mdx"
59
+ has "extensionless is kept when it is a real path token" "$f" "bin/cckit"
60
+ no "URL is not a path" "$f" "https"
61
+ no "prose word is not a path" "$f" "mixed"
62
+ eq "list is deduped + sorted" "$(printf '%s\n' "$f" | sort -u | wc -l | tr -d ' ')" \
63
+ "$(printf '%s\n' "$f" | wc -l | tr -d ' ')"
64
+
65
+ # ── kit_brief_sourced ────────────────────────────────────────────────────────────────────────
66
+ tmp="$(mktemp -d)"
67
+ cat > "$tmp/consumer.sh" <<'EOF'
68
+ #!/usr/bin/env bash
69
+ source "$LIB/kit-config.sh" && load_kit_config
70
+ . "$LIB/gh-project.sh"
71
+ source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-lib.sh"
72
+ echo "not a source line: lib/decoy.sh"
73
+ EOF
74
+ srcd="$(kit_brief_sourced "$tmp/consumer.sh")"
75
+ has "finds a source'd helper" "$srcd" "kit-config.sh"
76
+ has "finds a dot-source'd helper" "$srcd" "gh-project.sh"
77
+ has "finds a plugin-root helper" "$srcd" "kit-lib.sh"
78
+ no "ignores a non-source mention" "$srcd" "decoy.sh"
79
+ eq "missing file is skipped, not fatal" "$(kit_brief_sourced "$tmp/nope.sh")" ""
80
+
81
+ # ── kit_brief_gotchas ────────────────────────────────────────────────────────────────────────
82
+ mkdir -p "$tmp/proj/.claude/rules" "$tmp/proj/templates/rules"
83
+ cat > "$tmp/proj/templates/rules/delegation-brief.md" <<'EOF'
84
+ # Delegation brief
85
+ ## Standing gotchas
86
+ - template gotcha
87
+ ## Gate commands
88
+ - not a gotcha
89
+ EOF
90
+ eq "falls back to the kit template" \
91
+ "$(kit_brief_gotchas "$tmp/proj" | head -1)" "- template gotcha"
92
+ cat > "$tmp/proj/.claude/rules/delegation-brief.md" <<'EOF'
93
+ # Delegation brief
94
+ ## Standing gotchas
95
+
96
+ - project gotcha
97
+
98
+ ## Gate commands
99
+ - not a gotcha
100
+ EOF
101
+ g="$(kit_brief_gotchas "$tmp/proj")"
102
+ eq "project rule wins over the template" "$(printf '%s\n' "$g" | head -1)" "- project gotcha"
103
+ no "gotchas stop at the next heading" "$g" "not a gotcha"
104
+ eq "no rule file yields nothing" "$(kit_brief_gotchas "$tmp/empty-root")" ""
105
+
106
+ # ── kit_brief_durable_prose (#283) ───────────────────────────────────────────────────────────
107
+ # The concrete mandate has to reach the GENERATED brief: an agent applies a skill only when it is
108
+ # told to, so a mandate that lives only in communication-style.md never fires.
109
+ mkdir -p "$tmp/dp/.claude/rules"
110
+ cat > "$tmp/dp/.claude/rules/delegation-brief.md" <<'EOF'
111
+ # Delegation brief
112
+ ## Standing gotchas
113
+ - a gotcha
114
+ ## Durable prose — the concrete pass
115
+ - apply the `concrete` catalogue before writing
116
+ - O13 unverifiable claim / O14 undecided decision
117
+ ## Gate commands
118
+ - not durable prose
119
+ EOF
120
+ dp="$(kit_brief_durable_prose "$tmp/dp")"
121
+ has "durable prose names the skill" "$dp" 'concrete'
122
+ has "durable prose carries O13/O14" "$dp" "O13"
123
+ no "durable prose stops at the next heading" "$dp" "not durable prose"
124
+ no "durable prose is not the gotchas block" "$dp" "a gotcha"
125
+ eq "absent durable-prose section is empty" \
126
+ "$(kit_brief_durable_prose "$tmp/proj")" ""
127
+ eq "no rule file yields no durable prose" "$(kit_brief_durable_prose "$tmp/empty-root")" ""
128
+
129
+ # The kit's OWN template must carry the section, or every project scaffolds a brief without it.
130
+ ktpl="$dir/../../templates/rules/delegation-brief.md"
131
+ if [ -f "$ktpl" ]; then
132
+ tpl_prose="$(awk '/^##[[:space:]]/ { in_s = ($0 ~ /[Dd]urable prose/) ? 1 : 0; next } in_s' "$ktpl")"
133
+ has "kit template has a Durable prose section" "$tpl_prose" 'concrete'
134
+ has "kit template names O13" "$tpl_prose" "O13"
135
+ has "kit template names O14" "$tpl_prose" "O14"
136
+ has "kit template forbids cutting by length" "$tpl_prose" "never by length"
137
+ has "kit template cross-refs communication-style" "$tpl_prose" "communication-style.md"
138
+ else
139
+ echo " (templates/rules/delegation-brief.md absent — skipping the kit-template assertions)"
140
+ fi
141
+
142
+ # ── git-dependent lookups, against a throwaway repo ──────────────────────────────────────────
143
+ if command -v git >/dev/null 2>&1; then
144
+ repo="$tmp/r"; mkdir -p "$repo"
145
+ ( cd "$repo" && git init -q . \
146
+ && git config user.email t@t && git config user.name t \
147
+ && mkdir -p scripts/lib && echo base > scripts/lib/only-here.sh \
148
+ && echo dup > scripts/lib/dup.sh && mkdir -p other && echo dup > other/dup.sh \
149
+ && git add -A && git commit -q -m init ) >/dev/null 2>&1
150
+
151
+ # kit_brief_resolve — a bare basename must resolve to its tracked path, not read as "new"
152
+ r="$(cd "$repo" && kit_brief_resolve "only-here.sh" "$repo")"
153
+ eq "bare basename resolves to its path" "${r%% *}" "scripts/lib/only-here.sh"
154
+ eq "resolved basename is marked here" "${r##* }" "here"
155
+ r="$(cd "$repo" && kit_brief_resolve "scripts/lib/only-here.sh" "$repo")"
156
+ eq "literal existing path is here" "${r##* }" "here"
157
+ r="$(cd "$repo" && kit_brief_resolve "scripts/lib/not-yet.sh" "$repo")"
158
+ eq "literal missing path is new" "${r##* }" "new"
159
+ r="$(cd "$repo" && kit_brief_resolve "dup.sh" "$repo")"
160
+ case "${r##* }" in
161
+ ambiguous*) : ;;
162
+ *) echo "FAIL($KB_TEST_INNER): a basename matching two tracked files must be ambiguous -> '$r'"; fail=1 ;;
163
+ esac
164
+
165
+ # kit_brief_seed — fresh vs stale vs unknown, against a fabricated origin ref
166
+ ( cd "$repo" \
167
+ && git branch -q feat/1-fresh \
168
+ && git update-ref refs/remotes/origin/trunk "$(git rev-parse HEAD)" \
169
+ && echo more >> scripts/lib/only-here.sh && git add -A && git commit -q -m second \
170
+ && git update-ref refs/remotes/origin/trunk "$(git rev-parse HEAD)" ) >/dev/null 2>&1
171
+ # feat/1-fresh was cut BEFORE the second commit, so origin/trunk is no longer an ancestor of it
172
+ eq "a branch behind origin is STALE" \
173
+ "$(cd "$repo" && kit_brief_seed feat/1-fresh trunk | cut -d' ' -f1)" "stale"
174
+ ( cd "$repo" && git branch -q feat/2-current ) >/dev/null 2>&1
175
+ eq "a branch cut from the tip is FRESH" \
176
+ "$(cd "$repo" && kit_brief_seed feat/2-current trunk | cut -d' ' -f1)" "fresh"
177
+ eq "an unknown base is reported, not guessed" \
178
+ "$(cd "$repo" && kit_brief_seed feat/2-current no-such-base)" "unknown"
179
+ eq "an absent branch is reported, not guessed" \
180
+ "$(cd "$repo" && kit_brief_seed no-such-branch trunk)" "unknown"
181
+ # the seed check must name a real tip so a reader can verify it
182
+ has "fresh names the base tip" \
183
+ "$(cd "$repo" && kit_brief_seed feat/2-current trunk)" \
184
+ "$(cd "$repo" && git rev-parse --short origin/trunk)"
185
+
186
+ # kit_brief_worktree — the association comes from wt_issue_number, the same rule gc uses
187
+ if [ -f "$dir/worktree-issue.sh" ]; then
188
+ # shellcheck source=/dev/null
189
+ . "$dir/worktree-issue.sh"
190
+ ( cd "$repo" && git worktree add -q "$tmp/wt-7" -b task/7-thing ) >/dev/null 2>&1
191
+ w="$(cd "$repo" && kit_brief_worktree 7)"
192
+ has "finds the worktree for an issue" "$w" "task/7-thing"
193
+ eq "an issue with no worktree yields nothing" "$(cd "$repo" && kit_brief_worktree 999)" ""
194
+ else
195
+ echo " (worktree-issue.sh absent — skipping the worktree-association assertions)"
196
+ fi
197
+ else
198
+ echo " (git absent — skipping the git-dependent assertions)"
199
+ fi
200
+
201
+ # ── _kb_rows + the helpers-table cap ─────────────────────────────────────────────────────────
202
+ # _kb_rows needs the catalog from kit-lib.sh; skip cleanly where that helper is absent.
203
+ if [ -f "$dir/kit-lib.sh" ]; then
204
+ # shellcheck source=/dev/null
205
+ . "$dir/kit-lib.sh"
206
+ libfix="$tmp/lib"; mkdir -p "$libfix"
207
+ i=1
208
+ while [ "$i" -le 4 ]; do
209
+ cat > "$libfix/h$i.sh" <<EOF
210
+ #!/usr/bin/env bash
211
+ # h$i.sh — helper number $i.
212
+ # errors: pure
213
+ pub_$i() { :; }
214
+ EOF
215
+ i=$((i + 1))
216
+ done
217
+ rows="$(_kb_rows "$libfix" "$(printf 'h2.sh
218
+ h4.sh
219
+ ')")"
220
+ eq "_kb_rows returns one row per requested helper" \
221
+ "$(printf '%s\n' "$rows" | grep -c . | tr -d ' ')" "2"
222
+ has "_kb_rows renders the purpose" "$rows" "helper number 2"
223
+ has "_kb_rows renders the contract" "$rows" "pure"
224
+ no "_kb_rows omits helpers nobody asked for" "$rows" "h1.sh"
225
+ eq "_kb_rows with an empty set is empty" "$(_kb_rows "$libfix" "")" ""
226
+ eq "_kb_rows ignores a name that is not in the catalog" \
227
+ "$(_kb_rows "$libfix" "nope.sh")" ""
228
+ else
229
+ echo " (kit-lib.sh absent — skipping the helpers-table assertions)"
230
+ fi
231
+
232
+ # ── the helpers-table overflow count (#230 review) ───────────────────────────────────────────
233
+ # `grep -c` on empty input PRINTS 0 and exits 1, so a `|| echo 0` fallback yields "0\n0" and the
234
+ # arithmetic that consumes it dies — the same bug class as the #142 board-counter regression.
235
+ # An empty sourced set is the case that triggers it, so pin the arithmetic on empty input.
236
+ if [ -f "$dir/kit-lib.sh" ]; then
237
+ n_over_probe="$(( $(printf '' | grep -c . || true) - $(printf '' | grep -c . || true) ))"
238
+ eq "an empty count stays a single integer" "$n_over_probe" "0"
239
+ fi
240
+
241
+ # ── the whole brief renders under `set -eu` (#283) ───────────────────────────────────────────
242
+ # `bin/cckit` runs `set -eu`, and a while loop's rc is its LAST iteration's: an issue whose file
243
+ # list ended in a non-file token (`templates/skills/` — the parser keeps directory tokens) made
244
+ # the sourced-helpers assignment rc 1 and killed the brief mid-render. Every section after the
245
+ # helpers table — standing gotchas, the durable-prose mandate — was silently absent. gh is stubbed
246
+ # so this stays network-free; jq and git are real, because the verb requires both.
247
+ if command -v git >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 && [ -f "$dir/kit-lib.sh" ]; then
248
+ ghstub="$tmp/ghbin"; mkdir -p "$ghstub"
249
+ cat > "$ghstub/gh" <<'EOF'
250
+ #!/bin/sh
251
+ # stub: only `gh issue view … --json …` is used by kit_brief.
252
+ printf '%s' '{"title":"t","state":"OPEN","labels":[],"body":"Files: scripts/lib/only-here.sh, templates/skills/"}'
253
+ EOF
254
+ chmod +x "$ghstub/gh"
255
+ mkdir -p "$repo/.claude/rules"
256
+ cat > "$repo/.claude/rules/delegation-brief.md" <<'EOF'
257
+ # Delegation brief
258
+ ## Standing gotchas
259
+ - fixture gotcha
260
+ ## Durable prose — the concrete pass
261
+ - apply the `concrete` catalogue before writing
262
+ EOF
263
+ # A subshell, not `sh -c`: kit_brief is a function in THIS shell, and `set -eu` has to apply
264
+ # to it exactly as `bin/cckit` applies it. And NO trailing `|| true` — bash suppresses errexit
265
+ # for a command that is part of a `||` list, and the suppression reaches into the subshell, so
266
+ # a `|| true` here would make these assertions pass against the very bug they pin.
267
+ brief_out="$(cd "$repo" && export PATH="$ghstub:$PATH" && ( set -eu; kit_brief 5 ) 2>&1)"
268
+ has "the brief reaches the helpers table" "$brief_out" "## Helpers you already have"
269
+ has "the brief reaches the standing gotchas" "$brief_out" "fixture gotcha"
270
+ has "the brief reaches the durable-prose mandate" "$brief_out" 'concrete'
271
+ else
272
+ echo " (git, jq or kit-lib.sh absent — skipping the full-render assertions)"
273
+ fi
274
+
275
+ # ── the verb's argument contract (no gh call: it must reject before reaching for the network) ──
276
+ out="$(kit_brief 2>&1)"; rc=$?
277
+ eq "no argument is rc 2" "$rc" "2"
278
+ has "no argument prints usage" "$out" "usage: cckit brief"
279
+ out="$(kit_brief --llm 2>&1)"; rc=$?
280
+ eq "a flag without an issue is rc 2" "$rc" "2"
281
+
282
+ rm -rf "$tmp"
283
+ if [ "$fail" -eq 0 ]; then echo "PASS($KB_TEST_INNER): kit-brief parsers + real-state lookups"; fi
284
+ exit "$fail"
285
+ fi
286
+
287
+ rc=0
288
+ for sh in bash zsh; do
289
+ command -v "$sh" >/dev/null 2>&1 || continue
290
+ KB_TEST_INNER="$sh" "$sh" "$0" || rc=1
291
+ done
292
+ exit "$rc"