@jeiemgi/cckit 0.7.1 → 0.9.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.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +15 -4
- package/README.md +25 -3
- package/bin/cckit +91 -8
- package/cckit.config.json +1 -1
- package/kit.config.schema.json +43 -2
- package/package.json +1 -1
- package/scripts/autopilot-test.sh +68 -0
- package/scripts/autopilot.sh +16 -10
- package/scripts/check.sh +14 -1
- package/scripts/copilot-loop-test.sh +3 -0
- package/scripts/guard-raw-git-ops-test.sh +73 -0
- package/scripts/init.sh +68 -8
- package/scripts/lib/agent-profile-test.sh +151 -0
- package/scripts/lib/agent-profile.sh +195 -0
- package/scripts/lib/agent-resolve-test.sh +156 -0
- package/scripts/lib/agent-resolve.sh +177 -0
- package/scripts/lib/branch-owner-test.sh +99 -0
- package/scripts/lib/branch-owner.sh +194 -0
- package/scripts/lib/captain-test.sh +86 -0
- package/scripts/lib/captain.sh +142 -7
- package/scripts/lib/contribute-root-test.sh +40 -0
- package/scripts/lib/contribute-root.sh +22 -0
- package/scripts/lib/effort-metrics.sh +14 -1
- package/scripts/lib/effort-ops-test.sh +54 -2
- package/scripts/lib/effort-ops.sh +243 -23
- package/scripts/lib/effort-parity-test.sh +5 -3
- package/scripts/lib/effort-slug.sh +16 -2
- package/scripts/lib/effort.sh +49 -15
- package/scripts/lib/gh-project.sh +14 -0
- package/scripts/lib/gh-rest-test.sh +301 -0
- package/scripts/lib/gh-rest.sh +289 -0
- package/scripts/lib/hook-refresh-test.sh +65 -0
- package/scripts/lib/hook-refresh.sh +62 -0
- package/scripts/lib/kit-config.sh +6 -0
- package/scripts/lib/kit-gc-test.sh +178 -1
- package/scripts/lib/kit-gc.sh +251 -55
- package/scripts/lib/kit-task-ops-test.sh +15 -0
- package/scripts/lib/kit-task-ops.sh +231 -58
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +129 -0
- package/scripts/lib/kto-task-pr-test.sh +59 -0
- package/scripts/lib/orchestration-runtime-test.sh +142 -0
- package/scripts/lib/orchestration-runtime.sh +171 -0
- package/scripts/lib/review-stage-test.sh +241 -0
- package/scripts/lib/review-stage.sh +259 -0
- package/scripts/lib/stage-receipt-test.sh +252 -0
- package/scripts/lib/stage-receipt.sh +442 -0
- package/scripts/lib/test-env-test.sh +25 -0
- package/scripts/lib/test-env.sh +33 -0
- package/scripts/lib/worker-brief-test.sh +120 -0
- package/scripts/lib/worker-brief.sh +185 -0
- package/scripts/lib/worktree-issue.sh +14 -0
- package/scripts/lib/worktree-ports-test.sh +146 -0
- package/scripts/lib/worktree-start.sh +153 -8
- package/scripts/lib/zsh-safety-test.sh +67 -0
- package/scripts/orchestrate.sh +124 -22
- package/scripts/portable-test.sh +22 -1
- package/scripts/review-lint-baseline.txt +28 -0
- package/scripts/review-lint-test.sh +271 -0
- package/scripts/review-lint.sh +259 -0
- package/scripts/review-rules.conf +55 -0
- package/scripts/setup-labels.sh +21 -1
- package/scripts/skill-frontmatter-baseline.txt +24 -0
- package/scripts/skill-frontmatter-lint-test.sh +156 -0
- package/scripts/skill-frontmatter-lint.sh +182 -0
- package/scripts/task-sync.sh +8 -0
- package/scripts/test.sh +10 -1
- package/skills/kit-autopilot/SKILL.md +13 -1
- package/skills/kit-cleanup/SKILL.md +5 -3
- package/skills/kit-contribute/SKILL.md +6 -5
- package/skills/kit-effort-close/SKILL.md +8 -3
- package/skills/kit-effort-pr/SKILL.md +16 -95
- package/skills/kit-gc/SKILL.md +15 -10
- package/skills/kit-security-sweep/SKILL.md +4 -6
- package/skills/kit-ship/SKILL.md +1 -1
- package/skills/kit-task-pr/SKILL.md +2 -0
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +193 -0
- package/templates/rules/branch-naming.md +6 -0
- package/templates/rules/effort-model.md +3 -0
- package/templates/rules/naming-and-ids.md +4 -1
- package/templates/settings/settings.json.tmpl +4 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# kto-task-pr-merge-test.sh — kto_task_pr_merge never acts on the base branch (#366), cleans up from
|
|
3
|
+
# the PR's own worktree (#371), and merges by squash, merge commit or rebase into develop or an
|
|
4
|
+
# effort branch (#376).
|
|
5
|
+
# A flag taken as the PR number used to "merge" (gh pr merge --help exits 0) and then run the branch
|
|
6
|
+
# cleanup on the base branch; a conflicting PR merged from the hub would rebase + force-push it.
|
|
7
|
+
# Hermetic: stubbed gh, throwaway repo + bare remote. Run: bash scripts/lib/kto-task-pr-merge-test.sh
|
|
8
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
9
|
+
set -u
|
|
10
|
+
LIB="$(cd "$(dirname "$0")" && pwd)"
|
|
11
|
+
ROOT="$(cd "$LIB/../.." && pwd)"
|
|
12
|
+
fail=0
|
|
13
|
+
t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
14
|
+
command -v jq >/dev/null 2>&1 || { echo "kto-task-pr-merge-test: jq required" >&2; exit 1; }
|
|
15
|
+
|
|
16
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
17
|
+
export GH_LOG="$tmp/gh.log" GH_MERGEABLE="MERGEABLE" GH_BASE="develop" GH_HEAD=""; : > "$GH_LOG"
|
|
18
|
+
mkdir -p "$tmp/bin"
|
|
19
|
+
cat > "$tmp/bin/gh" <<'SH'
|
|
20
|
+
#!/usr/bin/env bash
|
|
21
|
+
echo "$*" >> "$GH_LOG"
|
|
22
|
+
case "$1 $2" in
|
|
23
|
+
"pr view") printf '{"mergeable":"%s","mergeStateStatus":"CLEAN","baseRefName":"%s","headRefName":"%s"}\n' \
|
|
24
|
+
"$GH_MERGEABLE" "${GH_BASE:-develop}" "${GH_HEAD:-}" ;;
|
|
25
|
+
*) exit 0 ;;
|
|
26
|
+
esac
|
|
27
|
+
SH
|
|
28
|
+
chmod +x "$tmp/bin/gh"
|
|
29
|
+
export PATH="$tmp/bin:$PATH" KIT_REPO="o/r" KIT_BASE_BRANCH="develop" KIT_PROJECTS_V2="false"
|
|
30
|
+
unset KIT_CONFIG
|
|
31
|
+
|
|
32
|
+
git init -q --bare "$tmp/remote.git"
|
|
33
|
+
git clone -q "$tmp/remote.git" "$tmp/work" 2>/dev/null
|
|
34
|
+
cd "$tmp/work" || exit 1
|
|
35
|
+
git config user.email t@t; git config user.name t
|
|
36
|
+
git checkout -q -b develop; git commit -q --allow-empty -m init; git push -q origin develop
|
|
37
|
+
|
|
38
|
+
# shellcheck source=/dev/null
|
|
39
|
+
. "$LIB/kit-task-ops.sh"
|
|
40
|
+
|
|
41
|
+
kto_task_pr_merge --help >/dev/null 2>&1; rc=$?
|
|
42
|
+
t "a flag is refused as a PR number (rc 2)" "$rc" "2"
|
|
43
|
+
t "nothing was merged on a refused flag" "$(grep -c 'pr merge' "$GH_LOG")" "0"
|
|
44
|
+
t "the dispatcher answers --help with usage" "$("$ROOT/bin/cckit" merge --help | cut -c1-18)" "cckit merge [<pr>]"
|
|
45
|
+
# #376: a bad flag, or a second PR number, is refused with usage and merges nothing
|
|
46
|
+
kto_task_pr_merge 7 --fast >/dev/null 2>"$tmp/errf"; rc=$?
|
|
47
|
+
t "an unknown flag is refused (rc 2)" "$rc" "2"
|
|
48
|
+
t "the refusal prints the usage" "$(grep -c 'usage: cckit merge \[<pr>\] \[--squash|--merge|--rebase\]' "$tmp/errf")" "1"
|
|
49
|
+
kto_task_pr_merge 7 8 >/dev/null 2>&1; rc=$?
|
|
50
|
+
t "two PR numbers are refused (rc 2)" "$rc" "2"
|
|
51
|
+
t "nothing was merged on a refused flag" "$(grep -c 'pr merge' "$GH_LOG")" "0"
|
|
52
|
+
|
|
53
|
+
: > "$GH_LOG"; GH_HEAD="fix/7-x"
|
|
54
|
+
kto_task_pr_merge 7 >/dev/null 2>&1
|
|
55
|
+
t "a numeric PR merges" "$(grep -c 'pr merge 7' "$GH_LOG")" "1"
|
|
56
|
+
t "the default method is still squash" "$(grep -c 'pr merge 7 --repo o/r --squash' "$GH_LOG")" "1"
|
|
57
|
+
# #376: --merge (a merge commit) and --rebase reach gh unchanged
|
|
58
|
+
: > "$GH_LOG"; GH_HEAD="fix/10-x"
|
|
59
|
+
kto_task_pr_merge 10 --merge >/dev/null 2>&1; rc=$?
|
|
60
|
+
t "--merge succeeds" "$rc" "0"
|
|
61
|
+
t "--merge asks GitHub for a merge commit" "$(grep -c 'pr merge 10 --repo o/r --merge' "$GH_LOG")" "1"
|
|
62
|
+
: > "$GH_LOG"; GH_HEAD="fix/13-x"
|
|
63
|
+
kto_task_pr_merge --rebase 13 >/dev/null 2>&1; rc=$?
|
|
64
|
+
t "--rebase succeeds (flag before the number)" "$rc" "0"
|
|
65
|
+
t "--rebase asks GitHub for a rebase merge" "$(grep -c 'pr merge 13 --repo o/r --rebase' "$GH_LOG")" "1"
|
|
66
|
+
t "merging from the base branch keeps it" "$(git branch --list develop | tr -d ' *')" "develop"
|
|
67
|
+
t "and keeps it on origin" "$(git ls-remote --heads origin develop | wc -l | tr -d ' ')" "1"
|
|
68
|
+
|
|
69
|
+
: > "$GH_LOG"; GH_MERGEABLE="CONFLICTING"; GH_HEAD="fix/8-x"
|
|
70
|
+
before="$(git rev-parse develop)"
|
|
71
|
+
kto_task_pr_merge 8 >/dev/null 2>&1; rc=$?
|
|
72
|
+
t "a conflicting PR from the base branch is refused" "$rc" "1"
|
|
73
|
+
t "the base branch was not rebased" "$(git rev-parse develop)" "$before"
|
|
74
|
+
t "nothing was merged on a conflict refusal" "$(grep -c 'pr merge' "$GH_LOG")" "0"
|
|
75
|
+
|
|
76
|
+
# ── #371: merged from the PR's OWN worktree, the cleanup still finishes ─────────────────────────
|
|
77
|
+
: > "$GH_LOG"; GH_MERGEABLE="MERGEABLE"; GH_HEAD="fix/9-x"
|
|
78
|
+
wt="$tmp/work/.claude/worktrees/fix+9-x"
|
|
79
|
+
git worktree add -q -b fix/9-x "$wt" develop
|
|
80
|
+
git -C "$wt" commit -q --allow-empty -m "the fix"
|
|
81
|
+
git -C "$wt" push -q origin fix/9-x
|
|
82
|
+
( cd "$wt" && kto_task_pr_merge 9 ) >/dev/null 2>"$tmp/err9"; rc=$?
|
|
83
|
+
t "merge from inside its worktree exits 0" "$rc" "0"
|
|
84
|
+
t "the PR was merged" "$(grep -c 'pr merge 9' "$GH_LOG")" "1"
|
|
85
|
+
t "its worktree is removed" "$([ -d "$wt" ] && echo present || echo gone)" "gone"
|
|
86
|
+
t "its local branch is deleted" "$(git branch --list fix/9-x | wc -l | tr -d ' ')" "0"
|
|
87
|
+
t "its remote branch is deleted" "$(git ls-remote --heads origin fix/9-x | wc -l | tr -d ' ')" "0"
|
|
88
|
+
t "no 'Unable to read current working directory'" "$(grep -c 'current working directory' "$tmp/err9")" "0"
|
|
89
|
+
t "the base branch survives" "$(git branch --list develop | tr -d ' *')" "develop"
|
|
90
|
+
|
|
91
|
+
# ── #376: a sub PR whose base is an effort branch ────────────────────────────────────────────────
|
|
92
|
+
git checkout -q develop
|
|
93
|
+
ewt="$tmp/work/.claude/worktrees/effort+5-e"
|
|
94
|
+
git worktree add -q -b effort/5-e "$ewt" develop
|
|
95
|
+
git -C "$ewt" commit -q --allow-empty -m "effort start"; git -C "$ewt" push -q origin effort/5-e
|
|
96
|
+
swt="$tmp/work/.claude/worktrees/sub+5a-x"
|
|
97
|
+
git worktree add -q -b sub/5a-x "$swt" effort/5-e
|
|
98
|
+
git -C "$swt" commit -q --allow-empty -m "sub a"; git -C "$swt" push -q origin sub/5a-x
|
|
99
|
+
# what GitHub's merge does to the effort branch: a new commit on origin/effort/5-e
|
|
100
|
+
git clone -q "$tmp/remote.git" "$tmp/gh-side" 2>/dev/null
|
|
101
|
+
git -C "$tmp/gh-side" checkout -q effort/5-e
|
|
102
|
+
git -C "$tmp/gh-side" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "Merge pull request #11"
|
|
103
|
+
git -C "$tmp/gh-side" push -q origin effort/5-e
|
|
104
|
+
|
|
105
|
+
: > "$GH_LOG"; GH_BASE="effort/5-e"; GH_HEAD="sub/5a-x"
|
|
106
|
+
( cd "$swt" && kto_task_pr_merge 11 --merge ) >/dev/null 2>&1; rc=$?
|
|
107
|
+
t "a sub PR into an effort branch merges (rc 0)" "$rc" "0"
|
|
108
|
+
t "with a merge commit" "$(grep -c 'pr merge 11 --repo o/r --merge' "$GH_LOG")" "1"
|
|
109
|
+
t "the sub worktree is removed" "$([ -d "$swt" ] && echo present || echo gone)" "gone"
|
|
110
|
+
t "the sub branch is deleted" "$(git branch --list sub/5a-x | wc -l | tr -d ' ')" "0"
|
|
111
|
+
t "the effort branch survives" "$(git branch --list effort/5-e | tr -d ' *+')" "effort/5-e"
|
|
112
|
+
t "the effort worktree survives" "$([ -d "$ewt" ] && echo present || echo gone)" "present"
|
|
113
|
+
t "the effort worktree is pulled to the merge" "$(git -C "$ewt" rev-parse HEAD)" "$(git -C "$tmp/gh-side" rev-parse HEAD)"
|
|
114
|
+
t "the main checkout stays on develop" "$(git rev-parse --abbrev-ref HEAD)" "develop"
|
|
115
|
+
|
|
116
|
+
# Run from the EFFORT worktree with a sub PR number: the current branch is the PR's base, and it
|
|
117
|
+
# must never be treated as the branch to clean up (before #376 this deleted effort/5-e).
|
|
118
|
+
git branch -q sub/5b-y effort/5-e; git push -q origin sub/5b-y
|
|
119
|
+
: > "$GH_LOG"; GH_HEAD="sub/5b-y"
|
|
120
|
+
( cd "$ewt" && kto_task_pr_merge 12 ) >/dev/null 2>&1; rc=$?
|
|
121
|
+
t "merging a sub PR from the effort worktree: rc 0" "$rc" "0"
|
|
122
|
+
t "the effort branch still survives" "$(git branch --list effort/5-e | tr -d ' *+')" "effort/5-e"
|
|
123
|
+
t "the effort worktree still survives" "$([ -d "$ewt" ] && echo present || echo gone)" "present"
|
|
124
|
+
t "the sub branch (not the cwd branch) is deleted" "$(git branch --list sub/5b-y | wc -l | tr -d ' ')" "0"
|
|
125
|
+
t "and on origin" "$(git ls-remote --heads origin sub/5b-y | wc -l | tr -d ' ')" "0"
|
|
126
|
+
t "effort/5-e is still on origin" "$(git ls-remote --heads origin effort/5-e | wc -l | tr -d ' ')" "1"
|
|
127
|
+
|
|
128
|
+
[ "$fail" -eq 0 ] && echo "kto-task-pr-merge: all passed" || echo "kto-task-pr-merge: FAILURES"
|
|
129
|
+
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"
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# orchestration-runtime.sh — terminal-runtime adapters for cckit orchestrate.
|
|
3
|
+
#
|
|
4
|
+
# cckit owns the work: issue selection, worktrees, branches, pull requests. A runtime owns only the
|
|
5
|
+
# terminal the agent runs in. Everything here is that second half — validate the runtime name,
|
|
6
|
+
# refuse an agent kind the runtime cannot start, and build the Herdr topology (workspace → tab →
|
|
7
|
+
# pane → agent) that tmux gets for free from `tmux new-session`.
|
|
8
|
+
# errors: strict — an invalid runtime, an unsupported agent kind, a missing binary or a failed
|
|
9
|
+
# herdr call propagates its rc; the caller must not create worktrees after a non-zero preflight.
|
|
10
|
+
# shellcheck shell=bash
|
|
11
|
+
|
|
12
|
+
or_runtime_validate() {
|
|
13
|
+
case "${1:-}" in
|
|
14
|
+
tmux|herdr) return 0 ;;
|
|
15
|
+
*) echo "orchestrate: --runtime must be tmux or herdr (got '${1:-}')" >&2; return 2 ;;
|
|
16
|
+
esac
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# The kinds Herdr can start. Read from the INSTALLED binary rather than a copy kept here: a
|
|
20
|
+
# hand-written list drifts silently against the runtime, and it already had — it carried `letta`,
|
|
21
|
+
# which herdr 0.9.0 does not support, so `--agent letta` passed preflight and then failed at
|
|
22
|
+
# `agent start`, after the worktree existed. The fallback list is only for when herdr is absent
|
|
23
|
+
# (a dry run) or its help output changes shape; it is deliberately the 0.9.0 set.
|
|
24
|
+
_OR_HERDR_KINDS_FALLBACK="pi claude codex gemini cursor devin agy cline omp mastracode opencode copilot kimi kiro droid amp grok hermes kilo qodercli qwen maki muse"
|
|
25
|
+
_OR_HERDR_KINDS=""
|
|
26
|
+
|
|
27
|
+
or_herdr_kinds() {
|
|
28
|
+
[ -n "$_OR_HERDR_KINDS" ] && { printf '%s\n' "$_OR_HERDR_KINDS"; return 0; }
|
|
29
|
+
local live=""
|
|
30
|
+
if command -v herdr >/dev/null 2>&1; then
|
|
31
|
+
live="$(herdr agent start --help 2>&1 \
|
|
32
|
+
| tr -d '\n' \
|
|
33
|
+
| sed -n 's/.*\[possible values:\([^]]*\)\].*/\1/p' \
|
|
34
|
+
| tr -d ' ' | tr ',' ' ')"
|
|
35
|
+
fi
|
|
36
|
+
case "$live" in
|
|
37
|
+
*claude*) _OR_HERDR_KINDS="$live" ;; # sanity: a parse that lost `claude` is a bad parse
|
|
38
|
+
*) _OR_HERDR_KINDS="$_OR_HERDR_KINDS_FALLBACK" ;;
|
|
39
|
+
esac
|
|
40
|
+
printf '%s\n' "$_OR_HERDR_KINDS"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
or_herdr_kind_supported() {
|
|
44
|
+
local want="${1:-}" k
|
|
45
|
+
[ -n "$want" ] || return 1
|
|
46
|
+
for k in $(or_herdr_kinds); do
|
|
47
|
+
[ "$k" = "$want" ] && return 0
|
|
48
|
+
done
|
|
49
|
+
return 1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
or_runtime_preflight() {
|
|
53
|
+
local runtime="$1" agent="$2" dryrun="${3:-0}"
|
|
54
|
+
or_runtime_validate "$runtime" || return $?
|
|
55
|
+
|
|
56
|
+
if [ "$runtime" = "herdr" ] && ! or_herdr_kind_supported "$agent"; then
|
|
57
|
+
echo "orchestrate: Herdr needs a supported agent kind, not '$agent'" >&2
|
|
58
|
+
echo " supported here: $(or_herdr_kinds)" >&2
|
|
59
|
+
return 2
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
[ "$dryrun" -eq 1 ] && return 0
|
|
63
|
+
command -v "$runtime" >/dev/null 2>&1 || {
|
|
64
|
+
case "$runtime" in
|
|
65
|
+
tmux) echo "orchestrate: tmux not installed (brew install tmux)" >&2 ;;
|
|
66
|
+
herdr) echo "orchestrate: Herdr not installed (see https://herdr.dev/install)" >&2 ;;
|
|
67
|
+
esac
|
|
68
|
+
return 1
|
|
69
|
+
}
|
|
70
|
+
command -v "$agent" >/dev/null 2>&1 || {
|
|
71
|
+
echo "orchestrate: agent '$agent' not on PATH" >&2
|
|
72
|
+
return 1
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
or_herdr_agent_name() {
|
|
77
|
+
local project="$1" issue="$2" base room
|
|
78
|
+
base="cckit-${project:-project}"
|
|
79
|
+
base="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9_-' '-')"
|
|
80
|
+
base="${base#-}"
|
|
81
|
+
[ -n "$base" ] || base="cckit-project"
|
|
82
|
+
case "$base" in [a-z]*) ;; *) base="cckit-$base" ;; esac
|
|
83
|
+
room=$((31 - ${#issue}))
|
|
84
|
+
[ "$room" -gt 0 ] || room=1
|
|
85
|
+
printf '%.*s-%s' "$room" "$base" "$issue"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# or_tmux_agent_cmd <kind> <agent-args-nl> — echo the command LINE tmux types into a pane.
|
|
89
|
+
#
|
|
90
|
+
# The two runtimes receive a profile's argv differently, and the difference is the whole reason this
|
|
91
|
+
# exists. Herdr takes an argv array and never meets a shell; tmux `send-keys` writes a command line
|
|
92
|
+
# INTO the pane's shell, so every argument must be single-quoted here or that shell re-splits it.
|
|
93
|
+
#
|
|
94
|
+
# Skipping this dropped a profile's args on the DEFAULT runtime while orchestrate still printed the
|
|
95
|
+
# resolved profile — a profile selecting a model ran on the CLI's default model with no warning.
|
|
96
|
+
or_tmux_agent_cmd() {
|
|
97
|
+
local kind="${1:-}" args_nl="${2:-}" cmd="${1:-}" a esc
|
|
98
|
+
[ -n "$args_nl" ] || { printf '%s\n' "$kind"; return 0; }
|
|
99
|
+
while IFS= read -r a; do
|
|
100
|
+
[ -n "$a" ] || continue
|
|
101
|
+
# Escape in its OWN assignment, not inline in the concatenation: the `'\''` idiom needs one
|
|
102
|
+
# level of quoting and doing it inside a double-quoted string silently adds another. The
|
|
103
|
+
# seed prompt a few lines down in orchestrate.sh uses this exact two-step form for the same
|
|
104
|
+
# reason — it was arrived at by a bug, not by taste.
|
|
105
|
+
esc=${a//\'/\'\\\'\'}
|
|
106
|
+
cmd="$cmd '$esc'"
|
|
107
|
+
done <<EOF
|
|
108
|
+
$args_nl
|
|
109
|
+
EOF
|
|
110
|
+
printf '%s\n' "$cmd"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# or_herdr_launch <session> <kind> <seed?> <detach?> <project> <agent-args-nl> <entry>...
|
|
114
|
+
#
|
|
115
|
+
# <agent-args-nl> is the profile's extra CLI argv, ONE PER LINE (empty for none). They are handed to
|
|
116
|
+
# `herdr agent start ... -- <args>`, which is Herdr's documented passthrough to the agent process.
|
|
117
|
+
# One-per-line, then rebuilt into an array, so an argument containing spaces stays one argument —
|
|
118
|
+
# a flat string would be re-split by the shell and silently change what the agent was asked to do.
|
|
119
|
+
or_herdr_launch() {
|
|
120
|
+
local session="$1" agent="$2" seed_enabled="$3" detach="$4" project="$5" args_nl="${6:-}"
|
|
121
|
+
shift 6
|
|
122
|
+
local entries=("$@") first entry wt rest branch num created workspace pane tab name seed
|
|
123
|
+
local aargs=() _a
|
|
124
|
+
if [ -n "$args_nl" ]; then
|
|
125
|
+
while IFS= read -r _a; do [ -n "$_a" ] && aargs+=("$_a"); done <<EOF
|
|
126
|
+
$args_nl
|
|
127
|
+
EOF
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
first=1
|
|
131
|
+
workspace=""
|
|
132
|
+
for entry in "${entries[@]}"; do
|
|
133
|
+
wt="${entry%%|*}"; rest="${entry#*|}"; branch="${rest%%|*}"; num="${rest##*|}"
|
|
134
|
+
if [ "$first" -eq 1 ]; then
|
|
135
|
+
created="$(herdr workspace create --cwd "$wt" --label "cckit:${project:-project}:$session" --no-focus)" || return $?
|
|
136
|
+
workspace="$(printf '%s\n' "$created" | jq -r '.result.workspace.workspace_id // empty')"
|
|
137
|
+
pane="$(printf '%s\n' "$created" | jq -r '.result.root_pane.pane_id // empty')"
|
|
138
|
+
[ -n "$workspace" ] && [ -n "$pane" ] || {
|
|
139
|
+
echo "orchestrate: Herdr workspace response did not include workspace and pane IDs" >&2
|
|
140
|
+
return 1
|
|
141
|
+
}
|
|
142
|
+
first=0
|
|
143
|
+
else
|
|
144
|
+
tab="$(herdr tab create --workspace "$workspace" --cwd "$wt" --label "issue-$num" --no-focus)" || return $?
|
|
145
|
+
pane="$(printf '%s\n' "$tab" | jq -r '.result.root_pane.pane_id // empty')"
|
|
146
|
+
[ -n "$pane" ] || {
|
|
147
|
+
echo "orchestrate: Herdr tab response did not include a pane ID for issue #$num" >&2
|
|
148
|
+
return 1
|
|
149
|
+
}
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
name="$(or_herdr_agent_name "$project" "$num")"
|
|
153
|
+
if [ "${#aargs[@]}" -gt 0 ]; then
|
|
154
|
+
herdr agent start "$name" --kind "$agent" --pane "$pane" -- "${aargs[@]}" >/dev/null || return $?
|
|
155
|
+
else
|
|
156
|
+
herdr agent start "$name" --kind "$agent" --pane "$pane" >/dev/null || return $?
|
|
157
|
+
fi
|
|
158
|
+
if [ "$seed_enabled" -eq 1 ]; then
|
|
159
|
+
seed="$(seed_for "$num" "$branch" "$wt")"
|
|
160
|
+
herdr agent prompt "$name" "$seed" >/dev/null || return $?
|
|
161
|
+
fi
|
|
162
|
+
echo " #$num Herdr agent '$name' in $wt"
|
|
163
|
+
done
|
|
164
|
+
|
|
165
|
+
if [ "$detach" -eq 1 ]; then
|
|
166
|
+
echo "orchestrate: Herdr workspace '$workspace' built. Open: herdr workspace focus $workspace && herdr"
|
|
167
|
+
else
|
|
168
|
+
herdr workspace focus "$workspace" >/dev/null
|
|
169
|
+
exec herdr
|
|
170
|
+
fi
|
|
171
|
+
}
|