@jeiemgi/cckit 0.7.1 → 0.8.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 (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +15 -4
  3. package/README.md +11 -3
  4. package/bin/cckit +86 -7
  5. package/cckit.config.json +1 -1
  6. package/kit.config.schema.json +43 -2
  7. package/package.json +1 -1
  8. package/scripts/autopilot-test.sh +68 -0
  9. package/scripts/autopilot.sh +16 -10
  10. package/scripts/check.sh +14 -1
  11. package/scripts/copilot-loop-test.sh +3 -0
  12. package/scripts/guard-raw-git-ops-test.sh +65 -0
  13. package/scripts/init.sh +68 -8
  14. package/scripts/lib/agent-profile-test.sh +151 -0
  15. package/scripts/lib/agent-profile.sh +195 -0
  16. package/scripts/lib/agent-resolve-test.sh +156 -0
  17. package/scripts/lib/agent-resolve.sh +177 -0
  18. package/scripts/lib/branch-owner-test.sh +99 -0
  19. package/scripts/lib/branch-owner.sh +194 -0
  20. package/scripts/lib/captain-test.sh +86 -0
  21. package/scripts/lib/captain.sh +142 -7
  22. package/scripts/lib/contribute-root-test.sh +40 -0
  23. package/scripts/lib/contribute-root.sh +22 -0
  24. package/scripts/lib/effort-ops-test.sh +42 -2
  25. package/scripts/lib/effort-ops.sh +157 -14
  26. package/scripts/lib/effort-parity-test.sh +5 -3
  27. package/scripts/lib/effort.sh +38 -14
  28. package/scripts/lib/hook-refresh-test.sh +65 -0
  29. package/scripts/lib/hook-refresh.sh +62 -0
  30. package/scripts/lib/kit-config.sh +6 -0
  31. package/scripts/lib/kit-gc-test.sh +178 -1
  32. package/scripts/lib/kit-gc.sh +233 -55
  33. package/scripts/lib/kit-task-ops-test.sh +15 -0
  34. package/scripts/lib/kit-task-ops.sh +65 -21
  35. package/scripts/lib/kto-task-pr-merge-test.sh +72 -0
  36. package/scripts/lib/kto-task-pr-test.sh +59 -0
  37. package/scripts/lib/orchestration-runtime-test.sh +142 -0
  38. package/scripts/lib/orchestration-runtime.sh +171 -0
  39. package/scripts/lib/review-stage-test.sh +241 -0
  40. package/scripts/lib/review-stage.sh +259 -0
  41. package/scripts/lib/stage-receipt-test.sh +252 -0
  42. package/scripts/lib/stage-receipt.sh +442 -0
  43. package/scripts/lib/test-env-test.sh +25 -0
  44. package/scripts/lib/test-env.sh +30 -0
  45. package/scripts/lib/worker-brief-test.sh +120 -0
  46. package/scripts/lib/worker-brief.sh +185 -0
  47. package/scripts/lib/worktree-ports-test.sh +146 -0
  48. package/scripts/lib/worktree-start.sh +137 -7
  49. package/scripts/lib/zsh-safety-test.sh +67 -0
  50. package/scripts/orchestrate.sh +124 -22
  51. package/scripts/portable-test.sh +22 -1
  52. package/scripts/review-lint-baseline.txt +28 -0
  53. package/scripts/review-lint-test.sh +271 -0
  54. package/scripts/review-lint.sh +259 -0
  55. package/scripts/review-rules.conf +55 -0
  56. package/scripts/setup-labels.sh +21 -1
  57. package/scripts/skill-frontmatter-baseline.txt +24 -0
  58. package/scripts/skill-frontmatter-lint-test.sh +156 -0
  59. package/scripts/skill-frontmatter-lint.sh +182 -0
  60. package/scripts/task-sync.sh +8 -0
  61. package/scripts/test.sh +10 -1
  62. package/skills/kit-autopilot/SKILL.md +13 -1
  63. package/skills/kit-cleanup/SKILL.md +5 -3
  64. package/skills/kit-contribute/SKILL.md +6 -5
  65. package/skills/kit-effort-close/SKILL.md +8 -3
  66. package/skills/kit-effort-pr/SKILL.md +16 -95
  67. package/skills/kit-gc/SKILL.md +15 -10
  68. package/skills/kit-security-sweep/SKILL.md +4 -6
  69. package/skills/kit-ship/SKILL.md +1 -1
  70. package/skills/kit-task-pr/SKILL.md +2 -0
  71. package/templates/hooks/guard-raw-git-ops.sh.tmpl +180 -0
  72. package/templates/rules/branch-naming.md +6 -0
  73. package/templates/rules/effort-model.md +3 -0
  74. package/templates/rules/naming-and-ids.md +4 -1
  75. package/templates/settings/settings.json.tmpl +4 -2
@@ -55,10 +55,25 @@ if [ -n "${KTO_TEST_INNER:-}" ]; then
55
55
  eq "conventional summary wins over derivation" \
56
56
  "$(kto_pr_title '[Effort 182] 2 · Publish to npm' 'ci: publish via OIDC' 'kind:task')" \
57
57
  "ci: publish via OIDC"
58
+ eq "titleStyle issue-title → the issue title verbatim" \
59
+ "$(KIT_PR_TITLE_STYLE=issue-title kto_pr_title '[Effort 182] 1 · Enforce it' 'ci: x' 'kind:task')" \
60
+ "[Effort 182] 1 · Enforce it"
61
+ eq "titleStyle conventional (explicit) → derive" \
62
+ "$(KIT_PR_TITLE_STYLE=conventional kto_pr_title 'mail hook goes silent' '' 'bug')" \
63
+ "fix: mail hook goes silent"
58
64
  eq "non-conventional summary ignored → derive" \
59
65
  "$(kto_pr_title 'Benchmark harness' 'ported a harness' 'kind:feat')" \
60
66
  "feat: Benchmark harness"
61
67
 
68
+ # pr.orchestratorSection: off by default, a 2-line section first when on
69
+ ob="$(kto_compose_pr_body 42 'S.' 'tech-lead' 'Fix the thing')"
70
+ case "$ob" in *"For the orchestrator"*) echo "FAIL($KTO_TEST_INNER): orchestrator section present by default"; fail=1 ;; *) ;; esac
71
+ ob="$(KIT_PR_ORCHESTRATOR_SECTION=true kto_compose_pr_body 42 'S.' 'tech-lead' 'Fix the thing')"
72
+ eq "orchestrator section opens the body" "$(printf '%s\n' "$ob" | sed -n 1p)" "## For the orchestrator"
73
+ eq "orchestrator line 1 = id + title" "$(printf '%s\n' "$ob" | sed -n 3p)" "#42 · Fix the thing"
74
+ eq "orchestrator line 2 = what to review" "$(printf '%s\n' "$ob" | sed -n 4p)" "Review: the summary below and the diff."
75
+ case "$ob" in *"Closes #42"*) ;; *) echo "FAIL($KTO_TEST_INNER): Closes line lost with the section on"; fail=1 ;; esac
76
+
62
77
  # kto_compose_pr_body must carry Closes #N and the Summary
63
78
  body="$(kto_compose_pr_body 42 'Did the thing.' 'tech-lead')"
64
79
  case "$body" in *"Closes #42"*) ;; *) echo "FAIL($KTO_TEST_INNER): pr body missing Closes #42"; fail=1 ;; esac
@@ -21,7 +21,7 @@
21
21
  # kto_closing_issue_numbers <pr-num> echo the issue #s a merged PR closes
22
22
  # kto_task_pr <num> <summary> [commit-msg] commit+push+open PR (board → In Review)
23
23
  # kto_task_pr_merge [pr-num] squash-merge + close issues + switch develop + GC
24
- # kto_task_new <title> <role> <kind> <prio> <ms> [plan] [blocked] <body> create issue + board fields
24
+ # kto_task_new <title> <role> <kind> <prio> [ms] [plan] [blocked] <body> create issue + board fields (ms may be empty)
25
25
  # kto_task_close <num> <summary> [pr-num] close issue + board → Done
26
26
  # errors: mixed — git/gh ops propagate; board + label side effects are best-effort
27
27
 
@@ -81,6 +81,11 @@ kto_labels_kind() {
81
81
  # Network-free (covered by the self-test). Output always passes commitlint_check.
82
82
  kto_pr_title() {
83
83
  local raw="${1:-}" summary="${2:-}" labels="${3:-}" kind ctype desc
84
+ # pr.titleStyle = issue-title (KIT_PR_TITLE_STYLE): the PR title IS the issue title, verbatim — for
85
+ # repos whose convention is "PR title = exact issue title" and that run no commitlint gate.
86
+ if [ "${KIT_PR_TITLE_STYLE:-conventional}" = "issue-title" ] && [ -n "$raw" ]; then
87
+ printf '%s' "$raw"; return 0
88
+ fi
84
89
  # Reuse the ONE commit-lint implementation. bin/cckit sources it; if a bare caller hasn't, pull it
85
90
  # from the repo (kto_task_pr always runs in-repo). Degrades gracefully if it can't be found.
86
91
  if ! type commitlint_check >/dev/null 2>&1; then
@@ -116,10 +121,15 @@ kto_pr_title() {
116
121
  printf '%s: %s' "$ctype" "$desc"
117
122
  }
118
123
 
119
- # Compose a PR body from the kit-task-pr template. Args: <num> <summary> <role-slug>
124
+ # Compose a PR body from the kit-task-pr template. Args: <num> <summary> <role-slug> [issue-title]
125
+ # pr.orchestratorSection = true (KIT_PR_ORCHESTRATOR_SECTION) prepends a 2-line
126
+ # `## For the orchestrator` section: the issue id + title, then what to review.
120
127
  kto_compose_pr_body() {
121
- local num="$1" summary="$2" role="$3" sig=""
128
+ local num="$1" summary="$2" role="$3" title="${4:-}" sig=""
122
129
  if type role_signature >/dev/null 2>&1; then sig="$(role_signature "$role")"; fi
130
+ if [ "${KIT_PR_ORCHESTRATOR_SECTION:-false}" = "true" ]; then
131
+ printf '## For the orchestrator\n\n#%s%s\nReview: the summary below and the diff.\n\n' "$num" "${title:+ · $title}"
132
+ fi
123
133
  cat <<EOF
124
134
  ## Closes
125
135
 
@@ -197,7 +207,7 @@ _kto_role_option_for_slug() {
197
207
  kto_task_pr() {
198
208
  # Default-safe reads: callers (scripts/kit) may run under `set -u`.
199
209
  local num="${1:-}" summary="${2:-}" commit_msg="${3:-}"
200
- local repo branch meta title labels milestone role author url pr_num pr_node item role_opt issue_item
210
+ local repo branch meta title labels milestone role author="" url pr_num pr_node item role_opt issue_item
201
211
  repo="$(kto_repo)"
202
212
  branch="$(git rev-parse --abbrev-ref HEAD)"
203
213
 
@@ -214,8 +224,14 @@ kto_task_pr() {
214
224
  local pr_title; pr_title="$(kto_pr_title "$title" "$summary" "$labels")"
215
225
  [[ -z "$commit_msg" ]] && commit_msg="$pr_title"
216
226
 
217
- if [[ -n "$(git status --porcelain)" ]]; then
218
- git add -A
227
+ # TRACKED changes only: `git add -A` would sweep an untracked .env.local (copied into every worktree)
228
+ # into the PR. Untracked files are listed, never committed — `git add` them yourself if they belong.
229
+ if [[ -n "$(git ls-files --others --exclude-standard 2>/dev/null)" ]]; then
230
+ echo "kto_task_pr: untracked files NOT committed (git add them first if they belong):" >&2
231
+ git ls-files --others --exclude-standard 2>/dev/null | sed 's/^/ /' >&2
232
+ fi
233
+ if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
234
+ git add -u
219
235
  if type role_git_author >/dev/null 2>&1; then author="$(role_git_author "$role")"; fi
220
236
  if [[ -n "$author" ]]; then
221
237
  git commit -m "$commit_msg" -m "Co-authored-by: ${author%%|*} <${author##*|}>"
@@ -229,7 +245,7 @@ kto_task_pr() {
229
245
  url=$(gh pr create --repo "$repo" \
230
246
  --base "$(kto_base_branch)" --head "$branch" \
231
247
  --title "$pr_title" \
232
- --body "$(kto_compose_pr_body "$num" "$summary" "$role")" \
248
+ --body "$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" \
233
249
  --label "$labels" \
234
250
  ${milestone:+--milestone "$milestone"} \
235
251
  --assignee "@me") || return 1
@@ -268,7 +284,12 @@ kto_task_pr_merge() {
268
284
  echo "✗ Working tree is dirty — commit or stash changes first" >&2; return 1
269
285
  fi
270
286
 
271
- pr_num="$input_pr"
287
+ # Refuse anything but a PR number. `gh pr merge --help` exits 0, so a flag taken as the number
288
+ # used to "merge", then run the cleanup below on the base branch (#366).
289
+ if [[ -n "$input_pr" && ! "$input_pr" =~ ^#?[0-9]+$ ]]; then
290
+ echo "✗ kto_task_pr_merge: '$input_pr' is not a PR number — usage: cckit merge [<pr>]" >&2; return 2
291
+ fi
292
+ pr_num="${input_pr#\#}"
272
293
  if [[ -z "$pr_num" ]]; then
273
294
  pr_num=$(gh pr list --repo "$repo" --head "$branch" --state open --json number --jq '.[0].number // empty')
274
295
  [[ -z "$pr_num" ]] && { echo "✗ No open PR found for branch $branch" >&2; return 1; }
@@ -281,6 +302,9 @@ kto_task_pr_merge() {
281
302
  echo " mergeable=$merge_state status=$(printf '%s' "$mergeable" | jq -r .status)"
282
303
 
283
304
  if [[ "$merge_state" == "CONFLICTING" ]]; then
305
+ case "$branch" in "$base"|main|master|develop|HEAD)
306
+ echo "✗ PR #$pr_num conflicts — rebase it from its own worktree (never rebase $branch here)" >&2; return 1 ;;
307
+ esac
284
308
  echo "→ Conflicts detected — rebasing onto $base..."
285
309
  git fetch origin "$base"
286
310
  if git rebase "origin/$base"; then
@@ -312,31 +336,48 @@ kto_task_pr_merge() {
312
336
  fi
313
337
  done
314
338
 
315
- # Locate the branch's worktree + the main worktree, switch develop + pull, clean up.
339
+ # Locate the branch's worktree + the main checkout, then clean up FROM the main checkout (#371).
340
+ # Run from the PR's own worktree, removing that worktree deleted our cwd, and every git call after
341
+ # it died with "Unable to read current working directory" — leaving the local branch behind. The
342
+ # main checkout = the parent of the shared git dir; fall back to the first `worktree list` entry.
343
+ local common
316
344
  wt=$(git worktree list --porcelain | awk -v b="refs/heads/$branch" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
317
- main_wt=$(git worktree list --porcelain | awk '/^worktree /{print $2; exit}')
318
- git -C "$main_wt" checkout "$base" 2>/dev/null || git checkout "$base"
319
- git -C "$main_wt" pull origin "$base" 2>/dev/null || git pull origin "$base"
345
+ common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
346
+ main_wt=""
347
+ [[ -n "$common" && "$(basename "$common")" == ".git" ]] && main_wt="$(dirname "$common")"
348
+ [[ -n "$main_wt" ]] || main_wt=$(git worktree list --porcelain | awk '/^worktree /{print $2; exit}')
349
+ cd "$main_wt" || { echo "✗ cannot reach the main checkout $main_wt for cleanup" >&2; return 1; }
350
+ git -C "$main_wt" checkout "$base" 2>/dev/null || true
351
+ git -C "$main_wt" pull origin "$base" 2>/dev/null || true
320
352
 
321
353
  if [[ -n "$wt" && "$wt" != "$main_wt" ]]; then
322
- git worktree remove "$wt" --force && echo "✓ Removed worktree $wt"
354
+ git -C "$main_wt" worktree remove "$wt" --force && echo "✓ Removed worktree $wt"
323
355
  fi
324
- git branch -D "$branch" 2>/dev/null && echo "✓ Deleted local branch $branch"
325
- git push origin --delete "$branch" 2>/dev/null && echo "✓ Deleted remote branch $branch" || echo " (remote branch already gone)"
326
- git worktree prune
356
+ # Never delete the base (or a release) branch: merging a PR from the hub leaves $branch = base.
357
+ # -D, not -d: a squash merge leaves the branch "not fully merged" by ancestry.
358
+ case "$branch" in
359
+ "$base"|main|master|develop|HEAD)
360
+ echo " (on $branch — no branch cleanup; run cckit merge from the PR's worktree to GC it)" ;;
361
+ *)
362
+ git -C "$main_wt" branch -D "$branch" 2>/dev/null && echo "✓ Deleted local branch $branch"
363
+ git -C "$main_wt" push origin --delete "$branch" 2>/dev/null && echo "✓ Deleted remote branch $branch" || echo " (remote branch already gone)" ;;
364
+ esac
365
+ git -C "$main_wt" worktree prune
327
366
  echo "✓ On $base, up to date — merged branch + worktree cleaned"
328
367
  }
329
368
 
330
369
  # kit task new — create a GitHub issue with labels + milestone, add it to the board, set Role +
331
370
  # Status(Todo) + Plan Link. Inputs are passed (the caller does the AskUserQuestion). No invented
332
371
  # values; fails loudly on an unknown label family upstream (the caller validates the closed sets).
333
- # Args: <title> <role-display-or-slug> <kind> <priority> <milestone> [plan-link] [blocked-by] <body>
372
+ # Args: <title> <role-display-or-slug> <kind> <priority> [milestone|""] [plan-link] [blocked-by] <body>
334
373
  kto_task_new() {
335
374
  local title="${1:-}" role="${2:-}" kind="${3:-}" prio="${4:-}" milestone="${5:-}" plan="${6:-}" blocked="${7:-}" body_user="${8:-}"
336
375
  local repo role_slug labels body url num node item role_opt
337
376
  repo="$(kto_repo)"
338
- [[ -n "$title" && -n "$role" && -n "$kind" && -n "$prio" && -n "$milestone" ]] || {
339
- echo "✗ kto_task_new: title, role, kind, priority, milestone are required" >&2; return 1; }
377
+ # Milestone is optional: a repo with no milestones (cckit itself) must still be able to file an
378
+ # issue through the verb, or agents fall back to raw `gh issue create` and the board drops it.
379
+ [[ -n "$title" && -n "$role" && -n "$kind" && -n "$prio" ]] || {
380
+ echo "✗ kto_task_new: title, role, kind, priority are required" >&2; return 1; }
340
381
 
341
382
  role_slug="$(printf '%s' "$role" | tr 'A-Z ' 'a-z-')"
342
383
  labels="kind:${kind},priority:${prio},role:${role_slug}"
@@ -344,14 +385,17 @@ kto_task_new() {
344
385
 
345
386
  url=$(gh issue create --repo "$repo" \
346
387
  --title "$title" --body "$body" \
347
- --label "$labels" --milestone "$milestone" --assignee "@me") || return 1
388
+ --label "$labels" ${milestone:+--milestone "$milestone"} --assignee "@me") || return 1
348
389
  num=$(basename "$url")
349
390
  echo "✓ $url"
350
391
 
351
392
  if kto_board_enabled && type load_project_ids >/dev/null 2>&1 && load_project_ids 2>/dev/null; then
352
393
  node=$(gh api "repos/$repo/issues/$num" --jq .node_id 2>/dev/null)
394
+ item=""
395
+ [[ -n "$node" ]] && item=$(project_add_item "$node" 2>/dev/null || true)
396
+ # Loud, not silent: an issue missing from the board is the failure this verb exists to prevent.
397
+ [[ -z "$item" ]] && echo "⚠ #$num was created but NOT added to the board — add it by hand" >&2
353
398
  if [[ -n "$node" ]]; then
354
- item=$(project_add_item "$node" 2>/dev/null || true)
355
399
  if [[ -n "$item" ]]; then
356
400
  role_opt="$(_kto_role_option_for_slug "$role_slug")"
357
401
  [[ -n "$role_opt" ]] && project_set_single_select "$item" "$ROLE_FIELD_ID" "$role_opt" 2>/dev/null || true
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ # kto-task-pr-merge-test.sh — kto_task_pr_merge never acts on the base branch (#366).
3
+ # A flag taken as the PR number used to "merge" (gh pr merge --help exits 0) and then run the branch
4
+ # cleanup on the base branch; a conflicting PR merged from the hub would rebase + force-push it.
5
+ # Hermetic: stubbed gh, throwaway repo + bare remote. Run: bash scripts/lib/kto-task-pr-merge-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
7
+ set -u
8
+ LIB="$(cd "$(dirname "$0")" && pwd)"
9
+ ROOT="$(cd "$LIB/../.." && pwd)"
10
+ fail=0
11
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
12
+ command -v jq >/dev/null 2>&1 || { echo "kto-task-pr-merge-test: jq required" >&2; exit 1; }
13
+
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+ export GH_LOG="$tmp/gh.log" GH_MERGEABLE="MERGEABLE"; : > "$GH_LOG"
16
+ mkdir -p "$tmp/bin"
17
+ cat > "$tmp/bin/gh" <<'SH'
18
+ #!/usr/bin/env bash
19
+ echo "$*" >> "$GH_LOG"
20
+ case "$1 $2" in
21
+ "pr view") echo "{\"mergeable\":\"$GH_MERGEABLE\",\"status\":\"CLEAN\"}" ;;
22
+ *) exit 0 ;;
23
+ esac
24
+ SH
25
+ chmod +x "$tmp/bin/gh"
26
+ export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" KIT_BASE_BRANCH="develop" KIT_PROJECTS_V2="false"
27
+ unset KIT_CONFIG
28
+
29
+ git init -q --bare "$tmp/remote.git"
30
+ git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
31
+ cd "$tmp/work" || exit 1
32
+ git config user.email t@t; git config user.name t
33
+ git checkout -q -b develop; git commit -q --allow-empty -m init; git push -q origin develop
34
+
35
+ # shellcheck source=/dev/null
36
+ . "$LIB/kit-task-ops.sh"
37
+
38
+ kto_task_pr_merge --help >/dev/null 2>&1; rc=$?
39
+ t "a flag is refused as a PR number (rc 2)" "$rc" "2"
40
+ t "nothing was merged on a refused flag" "$(grep -c 'pr merge' "$GH_LOG")" "0"
41
+ t "the dispatcher answers --help with usage" "$("$ROOT/bin/cckit" merge --help | cut -c1-18)" "cckit merge [<pr>]"
42
+
43
+ : > "$GH_LOG"
44
+ kto_task_pr_merge 7 >/dev/null 2>&1
45
+ t "a numeric PR merges" "$(grep -c 'pr merge 7' "$GH_LOG")" "1"
46
+ t "merging from the base branch keeps it" "$(git branch --list develop | tr -d ' *')" "develop"
47
+ t "and keeps it on origin" "$(git ls-remote --heads origin develop | wc -l | tr -d ' ')" "1"
48
+
49
+ : > "$GH_LOG"; GH_MERGEABLE="CONFLICTING"
50
+ before="$(git rev-parse develop)"
51
+ kto_task_pr_merge 8 >/dev/null 2>&1; rc=$?
52
+ t "a conflicting PR from the base branch is refused" "$rc" "1"
53
+ t "the base branch was not rebased" "$(git rev-parse develop)" "$before"
54
+ t "nothing was merged on a conflict refusal" "$(grep -c 'pr merge' "$GH_LOG")" "0"
55
+
56
+ # ── #371: merged from the PR's OWN worktree, the cleanup still finishes ─────────────────────────
57
+ : > "$GH_LOG"; GH_MERGEABLE="MERGEABLE"
58
+ wt="$tmp/work/.claude/worktrees/fix+9-x"
59
+ git worktree add -q -b fix/9-x "$wt" develop
60
+ git -C "$wt" commit -q --allow-empty -m "the fix"
61
+ git -C "$wt" push -q origin fix/9-x
62
+ ( cd "$wt" && kto_task_pr_merge 9 ) >/dev/null 2>"$tmp/err9"; rc=$?
63
+ t "merge from inside its worktree exits 0" "$rc" "0"
64
+ t "the PR was merged" "$(grep -c 'pr merge 9' "$GH_LOG")" "1"
65
+ t "its worktree is removed" "$([ -d "$wt" ] && echo present || echo gone)" "gone"
66
+ t "its local branch is deleted" "$(git branch --list fix/9-x | wc -l | tr -d ' ')" "0"
67
+ t "its remote branch is deleted" "$(git ls-remote --heads origin fix/9-x | wc -l | tr -d ' ')" "0"
68
+ t "no 'Unable to read current working directory'" "$(grep -c 'current working directory' "$tmp/err9")" "0"
69
+ t "the base branch survives" "$(git branch --list develop | tr -d ' *')" "develop"
70
+
71
+ [ "$fail" -eq 0 ] && echo "kto-task-pr-merge: all passed" || echo "kto-task-pr-merge: FAILURES"
72
+ exit "$fail"
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # kto-task-pr-test.sh — kto_task_pr end to end against a stubbed gh and a bare remote (#361):
3
+ # it commits tracked changes only (never an untracked .env.local), and it honours
4
+ # pr.titleStyle + pr.orchestratorSection when it opens the PR.
5
+ # Run: bash scripts/lib/kto-task-pr-test.sh
6
+ # errors: strict — a test runner: rc 1 on any failed assertion
7
+ set -u
8
+ LIB="$(cd "$(dirname "$0")" && pwd)"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ tc() { if grep -qE "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in gh log)"; fail=1; fi; }
12
+ command -v jq >/dev/null 2>&1 || { echo "kto-task-pr-test: jq required" >&2; exit 1; }
13
+
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+ export GH_LOG="$tmp/gh.log"; : > "$GH_LOG"
16
+ mkdir -p "$tmp/bin"
17
+ cat > "$tmp/bin/gh" <<'SH'
18
+ #!/usr/bin/env bash
19
+ echo "$*" >> "$GH_LOG"
20
+ case "$1 $2" in
21
+ "issue view") echo '{"title":"Fix the thing","labels":[{"name":"kind:fix"},{"name":"role:tech-lead"}],"milestone":null}' ;;
22
+ "pr create") echo "https://github.com/o/r/pull/7" ;;
23
+ *) exit 0 ;;
24
+ esac
25
+ SH
26
+ chmod +x "$tmp/bin/gh"
27
+ export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" KIT_BASE_BRANCH="main" KIT_PROJECTS_V2="false"
28
+ unset KIT_CONFIG
29
+
30
+ git init -q --bare "$tmp/remote.git"
31
+ git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
32
+ cd "$tmp/work" || exit 1
33
+ git config user.email t@t; git config user.name t
34
+ echo one > tracked.txt; git add tracked.txt; git commit -q -m init; git push -q origin HEAD:main
35
+ git checkout -q -b fix/42-the-thing
36
+ echo two > tracked.txt # a tracked change: must be committed
37
+ echo SECRET=x > .env.local # untracked, not ignored: must NOT be committed
38
+
39
+ # shellcheck source=/dev/null
40
+ . "$LIB/kit-task-ops.sh"
41
+ KIT_PR_TITLE_STYLE=issue-title KIT_PR_ORCHESTRATOR_SECTION=true \
42
+ kto_task_pr 42 "Did the thing." >/dev/null 2>"$tmp/err"
43
+ t "kto_task_pr succeeds under set -u" "$?" "0"
44
+
45
+ t "the tracked change is committed" "$(git show --name-only --format= HEAD)" "tracked.txt"
46
+ t "the untracked .env.local is not" "$(git ls-files .env.local)" ""
47
+ t ".env.local is still on disk" "$(cat .env.local)" "SECRET=x"
48
+ grep -q '.env.local' "$tmp/err" && echo "ok: the untracked file is reported" || { echo "FAIL: untracked file not reported"; fail=1; }
49
+ tc "$GH_LOG" 'pr create .*--title Fix the thing( |$)' "issue-title: the PR title is the issue title"
50
+ tc "$GH_LOG" '[-]-body ## For the orchestrator$' "orchestratorSection: the body opens with the section"
51
+ tc "$GH_LOG" '^#42 · Fix the thing$' "orchestratorSection: id + title line"
52
+
53
+ : > "$GH_LOG"; git checkout -q -b fix/43-other
54
+ KIT_PR_TITLE_STYLE=conventional kto_task_pr 43 "Other." >/dev/null 2>&1
55
+ tc "$GH_LOG" 'pr create .*--title fix: Fix the thing' "conventional (default): a Conventional Commits title"
56
+ grep -q 'For the orchestrator' "$GH_LOG" && { echo "FAIL: section present with the switch off"; fail=1; } || echo "ok: no section with the switch off"
57
+
58
+ [ "$fail" -eq 0 ] && echo "kto-task-pr: all passed" || echo "kto-task-pr: FAILURES"
59
+ exit "$fail"
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env bash
2
+ # orchestration-runtime-test.sh — Herdr runtime contract for cckit orchestrate (#317).
3
+ # errors: strict — a test runner: rc 1 on any failed assertion
4
+ # shellcheck shell=bash
5
+ set -u
6
+
7
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
8
+ # Sealed from the caller's KIT_*/CCKIT_*/EFFORT_* (#369): this suite builds its own fixture.
9
+ # shellcheck source=/dev/null
10
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
11
+ # shellcheck source=/dev/null
12
+ source "$ROOT/scripts/lib/orchestration-runtime.sh"
13
+
14
+ fail=0
15
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
16
+ yes() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
17
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> found '$3' in [$2]"; fail=1 ;; *) echo "ok: $1" ;; esac; }
18
+
19
+ or_runtime_validate tmux >/dev/null 2>&1; t "tmux runtime is accepted" "$?" "0"
20
+ or_runtime_validate herdr >/dev/null 2>&1; t "Herdr runtime is accepted" "$?" "0"
21
+ or_runtime_validate screen >/dev/null 2>&1; t "unknown runtime is rejected" "$?" "2"
22
+ or_herdr_kind_supported codex; t "Codex is a supported Herdr kind" "$?" "0"
23
+ or_herdr_kind_supported custom-agent; t "arbitrary commands are rejected by Herdr" "$?" "1"
24
+
25
+ name="$(or_herdr_agent_name 'My Very Long Project Name That Exceeds The Limit' 317)"
26
+ t "Herdr agent name stays within 32 characters" "${#name}" "32"
27
+ t "Herdr agent name preserves the issue suffix" "${name##*-}" "317"
28
+ case "$name" in [a-z][a-z0-9_-]*) name_ok=yes ;; *) name_ok=no ;; esac
29
+ t "Herdr agent name uses the accepted character set" "$name_ok" "yes"
30
+
31
+ stub="$(mktemp -d)"
32
+ export HERDR_TEST_LOG="$stub/herdr.log"
33
+ : > "$HERDR_TEST_LOG"
34
+ cat > "$stub/herdr" <<'SH'
35
+ #!/usr/bin/env bash
36
+ domain="$1"
37
+ {
38
+ printf '%s' "$1"; shift
39
+ for arg in "$@"; do printf '|%s' "$arg"; done
40
+ printf '\n'
41
+ } >> "$HERDR_TEST_LOG"
42
+ case "$1" in
43
+ create)
44
+ case "$domain" in
45
+ workspace) echo '{"result":{"workspace":{"workspace_id":"w1"},"root_pane":{"pane_id":"w1:p1"}}}' ;;
46
+ tab) echo '{"result":{"root_pane":{"pane_id":"w1:p2"}}}' ;;
47
+ esac
48
+ ;;
49
+ *) echo '{"result":{}}' ;;
50
+ esac
51
+ SH
52
+ cat > "$stub/codex" <<'SH'
53
+ #!/usr/bin/env bash
54
+ exit 0
55
+ SH
56
+ cat > "$stub/gh" <<'SH'
57
+ #!/usr/bin/env bash
58
+ case "${1:-}" in
59
+ api) exit 0 ;;
60
+ *) echo '[]' ;;
61
+ esac
62
+ SH
63
+ chmod +x "$stub/herdr" "$stub/codex" "$stub/gh"
64
+
65
+ seed_for() { printf 'seed issue %s on %s in %s' "$1" "$2" "$3"; }
66
+ old_path="$PATH"
67
+ PATH="$stub:$PATH"
68
+ out="$(or_herdr_launch sweep codex 1 1 demo "" "/tmp/wt1|task/41-one|41" "/tmp/wt2|task/42-two|42")"
69
+ log="$(cat "$HERDR_TEST_LOG")"
70
+ yes "Herdr creates one orchestration workspace" "$log" "workspace|create|--cwd|/tmp/wt1|--label|cckit:demo:sweep|--no-focus"
71
+ yes "Herdr starts the first issue agent" "$log" "agent|start|cckit-demo-41|--kind|codex|--pane|w1:p1"
72
+ yes "Herdr creates a tab rooted in the second worktree" "$log" "tab|create|--workspace|w1|--cwd|/tmp/wt2|--label|issue-42|--no-focus"
73
+ yes "Herdr sends the existing headless seed" "$log" "agent|prompt|cckit-demo-41|seed issue 41 on task/41-one in /tmp/wt1"
74
+ yes "detached launch prints a reopen command" "$out" "herdr workspace focus w1 && herdr"
75
+
76
+ : > "$HERDR_TEST_LOG"
77
+ or_herdr_launch sweep codex 0 1 demo "" "/tmp/wt1|task/41-one|41" >/dev/null
78
+ no "--no-seed starts the agent without prompting" "$(cat "$HERDR_TEST_LOG")" "agent|prompt"
79
+
80
+ # ── the supported-kind list comes from the INSTALLED binary, not a copy kept in cckit ───────────
81
+ # A hand-written list drifts: it carried `letta`, which herdr 0.9.0 rejects, so the kind passed
82
+ # preflight and failed later — after the worktree existed, which is exactly what preflight exists
83
+ # to prevent.
84
+ or_herdr_kind_supported claude; t "a kind herdr supports is accepted" "$?" "0"
85
+ or_herdr_kind_supported letta; t "a kind herdr does NOT support is rejected" "$?" "1"
86
+ or_herdr_kind_supported ''; t "an empty kind is rejected" "$?" "1"
87
+ yes "the refusal lists the kinds actually supported" "$(or_runtime_preflight herdr letta 1 2>&1)" "supported here:"
88
+
89
+ # ── a profile's argv reaches the agent through Herdr's `--` passthrough ─────────────────────────
90
+ : > "$HERDR_TEST_LOG"
91
+ or_herdr_launch sweep codex 0 1 demo "$(printf -- '--model\nsome model')" "/tmp/wt1|task/41-one|41" >/dev/null
92
+ yes "profile args are passed after herdr's --" "$(cat "$HERDR_TEST_LOG")" "--kind|codex|--pane|w1:p1|--|--model|some model"
93
+ # One-per-line then rebuilt as an array: an argument containing a space must stay ONE argument.
94
+ no "a space-bearing arg is not split into two" "$(cat "$HERDR_TEST_LOG")" "|some|model"
95
+
96
+ : > "$HERDR_TEST_LOG"
97
+ or_herdr_launch sweep codex 0 1 demo "" "/tmp/wt1|task/41-one|41" >/dev/null
98
+ no "no profile args means no trailing -- separator" "$(cat "$HERDR_TEST_LOG")" "--pane|w1:p1|--"
99
+
100
+ # ── the SAME argv reaches the agent on the tmux path, which is the DEFAULT runtime ─────────────
101
+ # This had no test, and that is why it shipped broken: the argv was threaded to or_herdr_launch and
102
+ # nowhere else, so a profile's `args` were dropped on the runtime almost everyone runs.
103
+ t "no args is the bare command" "$(or_tmux_agent_cmd claude '')" "claude"
104
+ t "args are quoted onto the command line" \
105
+ "$(or_tmux_agent_cmd claude "$(printf -- '--model\nsome model')")" "claude '--model' 'some model'"
106
+ # Assert the ROUND TRIP, not the literal: what matters is the argv the pane's shell ends up with,
107
+ # and an eval is the only thing that proves it. Comparing the quoted string to an expected literal
108
+ # is how a doubly-escaped `'\''` passes a test and still breaks the pane.
109
+ argv() { eval "printf '[%s]' $(or_tmux_agent_cmd claude "$1")"; }
110
+ t "the pane shell sees one arg per declared arg" \
111
+ "$(argv "$(printf -- '--model\nsome model')")" "[claude][--model][some model]"
112
+ t "a single quote survives instead of terminating the quoting" \
113
+ "$(argv "$(printf -- "it's odd")")" "[claude][it's odd]"
114
+
115
+ PATH="/usr/bin:/bin"
116
+ missing="$(or_runtime_preflight herdr codex 0 2>&1)"; rc=$?
117
+ t "missing Herdr fails before worktree creation" "$rc" "1"
118
+ yes "missing Herdr names the dependency" "$missing" "Herdr not installed"
119
+ PATH="$old_path"
120
+
121
+ dry="$(cd "$ROOT" && PATH="$stub:$PATH" "$ROOT/bin/cckit" orchestrate --runtime herdr --agent codex --dry-run 41 2>&1)"
122
+ yes "orchestrate accepts the Herdr runtime flag" "$dry" "runtime 'herdr', agent 'codex'"
123
+ yes "Herdr dry-run creates no runtime state" "$dry" "no worktrees created, no panes started"
124
+
125
+ auto="$(cd "$ROOT" && PATH="$stub:$PATH" "$ROOT/bin/cckit" autopilot --runtime herdr --agent codex --dry-run 41 2>&1)"
126
+ yes "autopilot passes the runtime to orchestrate" "$auto" "runtime 'herdr', agent 'codex'"
127
+
128
+ # autopilot forwards an explicit allow-list, so a flag orchestrate grew is rejected until it is
129
+ # added here too — `--profile` was, and the unattended driver is where a profile matters most.
130
+ prof="$(cd "$ROOT" && PATH="$stub:$PATH" "$ROOT/bin/cckit" autopilot --profile build --dry-run 41 2>&1)"
131
+ no "autopilot forwards --profile instead of rejecting it" "$prof" "unknown arg '--profile'"
132
+ # Forwarding is proven by WHO refuses. cckit's own config declares no profiles, so the resolver
133
+ # must be the one to say so — a message from agent-profile means the flag reached orchestrate.
134
+ yes "--profile reaches the resolver, not autopilot's arg parser" "$prof" "agent-profile: no profile named 'build'"
135
+ yes "autopilot lists --profile in its help" \
136
+ "$(cd "$ROOT" && "$ROOT/bin/cckit" autopilot --help 2>&1)" "--profile build"
137
+ no "autopilot help stops before the script body" \
138
+ "$(cd "$ROOT" && "$ROOT/bin/cckit" autopilot --help 2>&1)" "set -euo pipefail"
139
+
140
+ rm -rf "$stub"
141
+ [ "$fail" -eq 0 ] && echo "ALL OK" || echo "orchestration runtime: FAILURES"
142
+ exit "$fail"