@jeiemgi/cckit 0.9.0 → 0.10.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 +169 -21
- package/README.md +491 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +182 -17
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +13 -5
- package/commands/kit-export-project.md +0 -2
- package/commands/kit-export-training.md +6 -9
- package/commands/kit-init.md +43 -13
- package/commands/kit-routines.md +1 -1
- package/commands/kit-update.md +11 -6
- package/databases/supabase/guide.html +106 -0
- package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
- package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
- package/databases/supabase.json +70 -0
- package/integrations/emil-design-eng.json +41 -0
- package/integrations/graft.json +81 -0
- package/integrations/impeccable.json +42 -0
- package/integrations/integration.schema.json +215 -0
- package/integrations/lavish.json +43 -0
- package/integrations/mempalace.json +28 -0
- package/integrations/mlx-lm.json +32 -0
- package/integrations/web-design-guidelines.json +42 -0
- package/kit.config.schema.json +183 -5
- package/package.json +4 -1
- package/profiles/automation.json +7 -1
- package/profiles/content.json +10 -2
- package/profiles/marketing.json +57 -0
- package/profiles/minimal.json +7 -1
- package/profiles/research.json +7 -1
- package/profiles/software.json +7 -1
- package/recipes/nextjs-shadcn.json +49 -0
- package/scripts/agent-skills-external.txt +45 -0
- package/scripts/agent-skills-lint-test.sh +131 -0
- package/scripts/agent-skills-lint.sh +115 -0
- package/scripts/agent-template-lint-test.sh +42 -0
- package/scripts/agent-template-lint.sh +58 -0
- package/scripts/annotate-setup.sh +1 -1
- package/scripts/autopilot-run-test.sh +338 -0
- package/scripts/autopilot-run.sh +448 -0
- package/scripts/autopilot-test.sh +8 -0
- package/scripts/autopilot.sh +10 -1
- package/scripts/benchmark/benchmark-test.sh +85 -0
- package/scripts/benchmark/checkpoint-test.sh +314 -0
- package/scripts/benchmark/checkpoint.sh +408 -0
- package/scripts/benchmark/lib/model.sh +31 -6
- package/scripts/benchmark/report.sh +17 -2
- package/scripts/benchmark/run-quality.sh +36 -10
- package/scripts/benchmark/verb-timings-test.sh +124 -0
- package/scripts/benchmark/verb-timings.sh +149 -0
- package/scripts/check.sh +29 -19
- package/scripts/content-skills-test.sh +144 -0
- package/scripts/copilot-loop-test.sh +25 -0
- package/scripts/database-supabase-test.sh +121 -0
- package/scripts/docs-marketing-words-test.sh +73 -0
- package/scripts/docs-record-tables-test.sh +72 -0
- package/scripts/hook-adapter-test.sh +193 -0
- package/scripts/init-content-test.sh +225 -0
- package/scripts/init-guided-test.sh +474 -0
- package/scripts/init-recipes-test.sh +104 -0
- package/scripts/init-upgrade-test.sh +341 -2
- package/scripts/init.sh +746 -95
- package/scripts/instruction-budget-baseline.txt +8 -0
- package/scripts/instruction-budget-lint-test.sh +166 -0
- package/scripts/instruction-budget-lint.sh +219 -0
- package/scripts/integrations-check-test.sh +200 -0
- package/scripts/integrations-check.sh +157 -0
- package/scripts/kit-add-test.sh +214 -0
- package/scripts/kit-add.sh +305 -5
- package/scripts/kit-adopt-test.sh +16 -0
- package/scripts/kit-adopt.sh +3 -2
- package/scripts/kit-digest.sh +2 -2
- package/scripts/kit-doctor-test.sh +293 -0
- package/scripts/kit-doctor.sh +272 -140
- package/scripts/kit-export-project-test.sh +3 -3
- package/scripts/kit-remove-test.sh +19 -0
- package/scripts/kit-routines.sh +2 -2
- package/scripts/kit-self-update.sh +1 -1
- package/scripts/kit-version-check-test.sh +4 -0
- package/scripts/kit-version-check.sh +4 -2
- package/scripts/knowledge-lint.sh +4 -4
- package/scripts/leak-fence-test.sh +89 -0
- package/scripts/lib/adapter-select-test.sh +136 -0
- package/scripts/lib/adapter-select.sh +158 -0
- package/scripts/lib/agent-def-test.sh +69 -0
- package/scripts/lib/agent-def.sh +106 -0
- package/scripts/lib/agent-launch-test.sh +212 -0
- package/scripts/lib/agent-launch.sh +335 -0
- package/scripts/lib/board-view-test.sh +11 -0
- package/scripts/lib/board-view.sh +42 -26
- package/scripts/lib/branch-owner-test.sh +26 -0
- package/scripts/lib/branch-owner.sh +16 -9
- package/scripts/lib/captain-test.sh +105 -0
- package/scripts/lib/captain.sh +87 -8
- package/scripts/lib/codex-hooks-test.sh +100 -0
- package/scripts/lib/codex-hooks.sh +69 -0
- package/scripts/lib/commitlint.sh +1 -1
- package/scripts/lib/content-kinds-gc-test.sh +88 -0
- package/scripts/lib/copilot-test.sh +70 -4
- package/scripts/lib/copilot.sh +66 -14
- package/scripts/lib/effort-dispatch-test.sh +3 -3
- package/scripts/lib/effort-metrics-test.sh +178 -1
- package/scripts/lib/effort-metrics.sh +175 -35
- package/scripts/lib/effort-ops-test.sh +205 -7
- package/scripts/lib/effort-ops.sh +198 -43
- package/scripts/lib/effort-parity-test.sh +49 -13
- package/scripts/lib/effort-plan-test.sh +337 -0
- package/scripts/lib/effort-plan.sh +200 -23
- package/scripts/lib/effort.sh +56 -11
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +23 -16
- package/scripts/lib/gh-rest-test.sh +32 -3
- package/scripts/lib/gh-rest.sh +17 -2
- package/scripts/lib/hook-refresh.sh +1 -1
- package/scripts/lib/init-github.sh +412 -0
- package/scripts/lib/init-guide.sh +630 -0
- package/scripts/lib/integration-install-test.sh +343 -0
- package/scripts/lib/integration-install.sh +257 -0
- package/scripts/lib/integrations-test.sh +366 -0
- package/scripts/lib/integrations.sh +244 -0
- package/scripts/lib/kinds-test.sh +125 -0
- package/scripts/lib/kinds.sh +66 -0
- package/scripts/lib/kit-brief-test.sh +22 -3
- package/scripts/lib/kit-brief.sh +45 -5
- package/scripts/lib/kit-config-resolve.sh +2 -2
- package/scripts/lib/kit-config-test.sh +64 -1
- package/scripts/lib/kit-config.sh +37 -1
- package/scripts/lib/kit-events.sh +7 -0
- package/scripts/lib/kit-gc-test.sh +173 -1
- package/scripts/lib/kit-gc.sh +226 -37
- package/scripts/lib/kit-hotfix.sh +216 -0
- package/scripts/lib/kit-interview-test.sh +93 -0
- package/scripts/lib/kit-interview.sh +117 -8
- package/scripts/lib/kit-lib-test.sh +1 -1
- package/scripts/lib/kit-lib.sh +3 -3
- package/scripts/lib/kit-local.sh +2 -2
- package/scripts/lib/kit-manifest.sh +33 -1
- package/scripts/lib/kit-profile-test.sh +3 -3
- package/scripts/lib/kit-status-test.sh +112 -4
- package/scripts/lib/kit-status.sh +246 -16
- package/scripts/lib/kit-task-ops-test.sh +37 -0
- package/scripts/lib/kit-task-ops.sh +175 -31
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +1 -1
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
- package/scripts/lib/kto-task-pr-test.sh +70 -0
- package/scripts/lib/leak-fence.sh +89 -0
- package/scripts/lib/light-task-run-test.sh +255 -0
- package/scripts/lib/light-task-test.sh +309 -0
- package/scripts/lib/light-task.sh +706 -0
- package/scripts/lib/next-test.sh +99 -0
- package/scripts/lib/next.sh +9 -3
- package/scripts/lib/orchestration-runtime-test.sh +72 -0
- package/scripts/lib/orchestration-runtime.sh +57 -5
- package/scripts/lib/plan-machine-test.sh +15 -2
- package/scripts/lib/plan-machine.sh +20 -7
- package/scripts/lib/plan-next-test.sh +1 -1
- package/scripts/lib/plan-next.sh +4 -4
- package/scripts/lib/pr-evidence-test.sh +3 -3
- package/scripts/lib/pr-evidence.sh +1 -1
- package/scripts/lib/qa-lane-test.sh +626 -0
- package/scripts/lib/qa-lane.sh +1357 -0
- package/scripts/lib/qa-lanes-test.sh +175 -0
- package/scripts/lib/react-detect.sh +1 -1
- package/scripts/lib/render-test.sh +1 -1
- package/scripts/lib/review-page-test.sh +318 -0
- package/scripts/lib/review-page.sh +369 -0
- package/scripts/lib/review-stage-test.sh +62 -11
- package/scripts/lib/review-stage.sh +42 -60
- package/scripts/lib/role-identity-test.sh +65 -0
- package/scripts/lib/role-identity.sh +25 -2
- package/scripts/lib/secret-guard.sh +3 -3
- package/scripts/lib/session-registry-test.sh +111 -0
- package/scripts/lib/session-registry.sh +233 -0
- package/scripts/lib/stage-receipt-test.sh +14 -1
- package/scripts/lib/stage-receipt.sh +13 -8
- package/scripts/lib/task-source-file.sh +309 -0
- package/scripts/lib/task-source.sh +130 -0
- package/scripts/lib/upgrade-report-test.sh +120 -0
- package/scripts/lib/upgrade-report.sh +138 -0
- package/scripts/lib/version-bump.sh +3 -3
- package/scripts/lib/wave-result-test.sh +80 -0
- package/scripts/lib/wave-result.sh +127 -0
- package/scripts/lib/worker-brief-test.sh +5 -0
- package/scripts/lib/worker-brief.sh +2 -2
- package/scripts/lib/worktree-issue-test.sh +30 -1
- package/scripts/lib/worktree-issue.sh +82 -12
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +153 -31
- package/scripts/lib/zsh-safety-test.sh +19 -3
- package/scripts/marketing-walkthrough-test.sh +152 -0
- package/scripts/night-grant-test.sh +37 -0
- package/scripts/night-grant.sh +448 -0
- package/scripts/night-run-test.sh +8 -0
- package/scripts/night-run.mjs +275 -0
- package/scripts/night-run.test.mjs +324 -0
- package/scripts/orchestrate-test.sh +190 -0
- package/scripts/orchestrate.sh +79 -8
- package/scripts/portable-test.sh +11 -2
- package/scripts/publish.sh +28 -3
- package/scripts/review-lint-test.sh +7 -7
- package/scripts/review-lint.sh +2 -2
- package/scripts/review-rules.conf +8 -0
- package/scripts/rule-recipes-test.sh +96 -0
- package/scripts/self-install-test.sh +39 -9
- package/scripts/setup-labels.sh +18 -1
- package/scripts/setup-milestones.sh +1 -1
- package/scripts/showcase.sh +1 -1
- package/scripts/skill-frontmatter-lint-test.sh +4 -4
- package/scripts/skill-frontmatter-lint.sh +1 -1
- package/scripts/status-test.sh +113 -2
- package/scripts/status.sh +16 -3
- package/scripts/task-sync-test.sh +154 -0
- package/scripts/task-sync.sh +243 -32
- package/scripts/test-runner-test.sh +158 -0
- package/scripts/test.sh +131 -23
- package/scripts/update-path-test.sh +279 -0
- package/scripts/ux-ds-audit.sh +1 -1
- package/scripts/ux-graph-scan.sh +6 -6
- package/scripts/wave-worker.sh +54 -0
- package/skills/kit-add/SKILL.md +77 -0
- package/skills/kit-autopilot/SKILL.md +123 -12
- package/skills/kit-cleanup/SKILL.md +5 -2
- package/skills/kit-contribute/SKILL.md +4 -4
- package/skills/kit-docs-writer/SKILL.md +16 -6
- package/skills/kit-effort-close/SKILL.md +17 -8
- package/skills/kit-effort-new/SKILL.md +15 -9
- package/skills/kit-effort-pr/SKILL.md +15 -7
- package/skills/kit-effort-start/SKILL.md +5 -2
- package/skills/kit-gc/SKILL.md +5 -2
- package/skills/kit-next/SKILL.md +5 -1
- package/skills/kit-onboard/SKILL.md +3 -3
- package/skills/kit-page/SKILL.md +93 -0
- package/skills/kit-plan-next/SKILL.md +8 -4
- package/skills/kit-security-sweep/SKILL.md +1 -3
- package/skills/kit-ship/SKILL.md +2 -3
- package/skills/kit-status/SKILL.md +35 -4
- package/skills/kit-task-new/SKILL.md +3 -3
- package/skills/kit-task-pr/SKILL.md +7 -2
- package/skills/kit-task-pr-merge/SKILL.md +7 -2
- package/skills/kit-task-start/SKILL.md +7 -7
- package/skills/kit-task-sync/SKILL.md +19 -3
- package/skills/kit-ux-audit/SKILL.md +3 -2
- package/templates/agents/auto-dev.md +5 -4
- package/templates/agents/backend.md +1 -1
- package/templates/agents/designer.md +2 -0
- package/templates/agents/devops.md +1 -1
- package/templates/agents/editor.md +9 -1
- package/templates/agents/frontend.md +1 -1
- package/templates/agents/local-delegate.md +1 -1
- package/templates/agents/pm.md +5 -5
- package/templates/agents/tech-lead.md +1 -1
- package/templates/benchmarks/SCHEMA.md +9 -3
- package/templates/codex/hooks.json.tmpl +89 -0
- package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
- package/templates/hooks/mempal_followup.sh.tmpl +2 -2
- package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
- package/templates/hooks/prepush_gate.sh.tmpl +4 -2
- package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
- package/templates/instructions.md.tmpl +174 -0
- package/templates/kit.config.json.tmpl +3 -3
- package/templates/knowledge-INDEX.md.tmpl +1 -1
- package/templates/lib/kit-sigil.sh.tmpl +1 -1
- package/templates/rules/authoring.md +106 -0
- package/templates/rules/branch-naming.md +40 -4
- package/templates/rules/code-retrieval.md +63 -0
- package/templates/rules/delegation-brief.md +0 -3
- package/templates/rules/design-routing.md +3 -3
- package/templates/rules/effort-model.md +14 -10
- package/templates/rules/gate-and-review.md +94 -0
- package/templates/rules/issue-lifecycle.md +88 -0
- package/templates/rules/knowledge-base.md +1 -1
- package/templates/rules/mempalace.md +1 -1
- package/templates/rules/merge-safety.md +108 -0
- package/templates/rules/naming-and-ids.md +23 -17
- package/templates/rules/plain-language.md +59 -0
- package/templates/rules/plan-next.md +9 -11
- package/templates/rules/react-annotate.md +6 -0
- package/templates/rules/review-pages.md +49 -0
- package/templates/rules/risk-tiered-review.md +13 -4
- package/templates/rules/shared-checkout.md +106 -0
- package/templates/rules/skill-gaps.md +2 -7
- package/templates/rules/task-management.md +13 -1
- package/templates/skills/brand-voice/SKILL.md +91 -0
- package/templates/skills/brand-voice/references/voice-template.md +61 -0
- package/templates/skills/campaign/SKILL.md +123 -0
- package/templates/skills/campaign/references/plan-template.md +55 -0
- package/templates/skills/concrete/SKILL.md +2 -2
- package/templates/skills/copywriting/SKILL.md +8 -1
- package/templates/skills/feature-build-refine/SKILL.md +2 -4
- package/templates/skills/morning-briefing/SKILL.md +2 -2
- package/templates/skills/page-design/SKILL.md +145 -0
- package/templates/skills/page-design/add.json +5 -0
- package/templates/skills/page-design/references/design-file-template.md +40 -0
- package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
- package/templates/skills/page-design/references/minimum-rules.md +42 -0
- package/templates/skills/speckit/SKILL.md +4 -5
- package/templates/skills/supabase-patterns/SKILL.md +1 -1
- package/commands/kit-add.md +0 -42
- package/templates/CLAUDE.md.tmpl +0 -106
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
# RECORDED under the git-common-dir, so uniqueness is by construction and an issue keeps its
|
|
18
18
|
# slot for as long as its worktree lives.
|
|
19
19
|
#
|
|
20
|
+
# 4. A LOCK THAT DID NOT EXCLUDE (#449). The ledger lock was `mkdir`. The `mkdir` of uutils
|
|
21
|
+
# coreutils 0.10.0 (Ubuntu 26.04, GitHub's `ubuntu-latest`) exits 0 for the loser of a race, so
|
|
22
|
+
# two allocations ran together and took the same slot: 4 of 70 runs of this file on that
|
|
23
|
+
# runner, 52 of 100 runs of section 6 in an Ubuntu 26.04 container. Section 7 races the
|
|
24
|
+
# primitive itself.
|
|
25
|
+
#
|
|
20
26
|
# The bar: N worktrees over arbitrary issue numbers, in either config layout, produce N disjoint
|
|
21
27
|
# port sets — and re-running for a live issue never renumbers it.
|
|
22
28
|
#
|
|
@@ -85,6 +91,20 @@ wt_assign_ports "$W" 7 "$P" >/dev/null 2>&1
|
|
|
85
91
|
after="$(ports_of "$W" | tr '\n' ' ')"
|
|
86
92
|
[ "$before" = "$after" ] && ok || bad "re-run renumbered a live lane: '$before' -> '$after'"
|
|
87
93
|
|
|
94
|
+
# ── 4b. the public readers agree with the allocation (#295) ───────────────────────────────────
|
|
95
|
+
# The QA lane derives its ports from wt_port_slot + wt_port_stride. If either disagreed with what
|
|
96
|
+
# wt_assign_ports wrote, a lane's stack would boot off the worktree's own port block.
|
|
97
|
+
slot7="$(wt_port_slot "$P" 7 "$W" 2>/dev/null)"
|
|
98
|
+
stride7="$(wt_port_stride "$P/cckit.config.json")"
|
|
99
|
+
[ "$stride7" = 10 ] && ok || bad "wt_port_stride default: got '$stride7', want 10"
|
|
100
|
+
first7="$(ports_of "$W" | sed -n 1p)"
|
|
101
|
+
[ "$first7" = "$(( 3001 + slot7 * stride7 ))" ] && ok || bad "wt_port_slot disagrees with the assigned port: slot '$slot7' stride '$stride7' port '$first7'"
|
|
102
|
+
[ "$(wt_port_slot "$P" 7 "$W" 2>/dev/null)" = "$slot7" ] && ok || bad "wt_port_slot renumbered a live issue"
|
|
103
|
+
printf '%s' '{"worktree":{"devPortStride":25}}' > "$TMP/stride.json"
|
|
104
|
+
[ "$(wt_port_stride "$TMP/stride.json")" = 25 ] && ok || bad "wt_port_stride ignored worktree.devPortStride"
|
|
105
|
+
printf '%s' '{"worktree":{"devPortStride":"wide"}}' > "$TMP/stride.json"
|
|
106
|
+
[ "$(wt_port_stride "$TMP/stride.json")" = 10 ] && ok || bad "wt_port_stride accepted a non-integer stride"
|
|
107
|
+
|
|
88
108
|
# ── 5. a freed slot is reclaimed, not leaked ──────────────────────────────────────────────────
|
|
89
109
|
slots="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
|
|
90
110
|
case "$slots" in /*) : ;; *) slots="$(cd "$P" && cd "$slots" && pwd)" ;; esac
|
|
@@ -119,7 +139,7 @@ for num in $RACE_NUMS; do
|
|
|
119
139
|
while [ "$(lines_in "$barrier")" -lt "$RACE_N" ] && [ "$waited" -lt 50 ]; do
|
|
120
140
|
sleep 0.1; waited=$(( waited + 1 ))
|
|
121
141
|
done
|
|
122
|
-
wt_assign_ports "$W" "$num" "$P" >/dev/null 2
|
|
142
|
+
wt_assign_ports "$W" "$num" "$P" >/dev/null 2>"$P/.err.$num"
|
|
123
143
|
) &
|
|
124
144
|
pids="$pids $!"
|
|
125
145
|
done
|
|
@@ -134,13 +154,46 @@ race_uniq="$(printf '%s' "$race" | sort -u | grep -c .)"
|
|
|
134
154
|
[ "$race_total" = 24 ] && ok || bad "parallel: expected 24 ports over 8 concurrent worktrees, got $race_total"
|
|
135
155
|
if [ "$race_total" = "$race_uniq" ]; then ok; else
|
|
136
156
|
bad "parallel port collision: $race_total ports but only $race_uniq distinct ($(printf '%s' "$race" | sort | uniq -d | tr '\n' ' '))"
|
|
157
|
+
# The evidence, not only the verdict: what the ledger recorded and what the allocator said on
|
|
158
|
+
# stderr (a lock that timed out warns there). Without these a collision cannot be traced (#449).
|
|
159
|
+
echo " ledger:"; sed 's/^/ /' "$P/.git/kit-portslots.tsv" 2>&1
|
|
160
|
+
echo " allocator stderr:"; cat "$P"/.err.* 2>/dev/null | grep -v ' PORT=' | sed 's/^/ /'
|
|
137
161
|
fi
|
|
138
162
|
|
|
139
|
-
# The lock is released on the way out — a leftover lock
|
|
140
|
-
#
|
|
163
|
+
# The lock is released on the way out — a leftover lock wedges every later start until the
|
|
164
|
+
# one-minute abandonment window elapses.
|
|
141
165
|
race_gcd="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
|
|
142
166
|
case "$race_gcd" in /*) : ;; *) race_gcd="$(cd "$P" && cd "$race_gcd" && pwd)" ;; esac
|
|
143
|
-
[ ! -
|
|
167
|
+
[ ! -e "$race_gcd/kit-portslots.tsv.lock" ] && ok || bad "the port-slot lock was left behind after allocation"
|
|
168
|
+
|
|
169
|
+
# ── 7. the lock primitive excludes: of N simultaneous attempts exactly one wins (#449) ────────
|
|
170
|
+
# Section 6 only fails when two allocations happen to overlap. This one asks the primitive
|
|
171
|
+
# directly: eight processes make ONE attempt each on the same lock, released together by a start
|
|
172
|
+
# file, and the winners are counted. A primitive that checks and then creates (uutils `mkdir`)
|
|
173
|
+
# reports several winners in most rounds, so 25 rounds do not pass by luck.
|
|
174
|
+
LOCK_ROUNDS=25; lock_bad=0; lock_detail=""
|
|
175
|
+
L="$TMP/prim.lock"; go="$TMP/prim.go"; won="$TMP/prim.won"
|
|
176
|
+
r=0
|
|
177
|
+
while [ "$r" -lt "$LOCK_ROUNDS" ]; do
|
|
178
|
+
r=$((r+1)); rm -rf "$L" "$go"; : > "$won"; pids=""
|
|
179
|
+
for k in 1 2 3 4 5 6 7 8; do
|
|
180
|
+
(
|
|
181
|
+
waited=0
|
|
182
|
+
while [ ! -e "$go" ] && [ "$waited" -lt 20000 ]; do waited=$((waited+1)); done # spin: a sleep would spread the attempts out
|
|
183
|
+
_wt_lock_try "$L" && echo "$k" >> "$won"
|
|
184
|
+
) &
|
|
185
|
+
pids="$pids $!"
|
|
186
|
+
done
|
|
187
|
+
: > "$go"
|
|
188
|
+
for pid in $pids; do wait "$pid"; done
|
|
189
|
+
winners="$(lines_in "$won")"
|
|
190
|
+
[ "$winners" = 1 ] || { lock_bad=$((lock_bad+1)); lock_detail="$lock_detail $winners"; }
|
|
191
|
+
done
|
|
192
|
+
[ "$lock_bad" = 0 ] && ok || bad "the lock primitive let $lock_bad of $LOCK_ROUNDS rounds end without exactly one winner (winners per bad round:$lock_detail)"
|
|
193
|
+
_wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left the lock in place"
|
|
194
|
+
# A cckit from before #449 leaves a lock DIRECTORY at the same path: it must still block.
|
|
195
|
+
mkdir "$L"; if _wt_lock_try "$L"; then bad "a lock directory from an older cckit did not block"; else ok; fi
|
|
196
|
+
_wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left an older lock directory in place"
|
|
144
197
|
|
|
145
198
|
echo "worktree-ports-test: $n assertion(s), $([ "$fail" = 0 ] && echo "all passed" || echo "FAILURES")"
|
|
146
199
|
exit "$fail"
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# worktree-start-test.sh — wt_start sees live session claims (#384).
|
|
3
|
+
#
|
|
4
|
+
# The bug: a second `cckit start <N>` from another session got "reusing worktree" and rc 0, so two
|
|
5
|
+
# agents wrote one tree. The bar: a LIVE claim by another session refuses the start before any
|
|
6
|
+
# fetch, branch or worktree; `--force` / KIT_FORCE=1 proceeds; a dead session's claim is reaped;
|
|
7
|
+
# the claimant's own re-run stays a no-op; `cckit claims` lists and writes nothing.
|
|
8
|
+
#
|
|
9
|
+
# Hermetic: a throwaway repo with a local bare origin, a stubbed `gh` (no network, no auth) and a
|
|
10
|
+
# stubbed `zoxide` (so no temp path lands in the developer's jump database). A "session" is a
|
|
11
|
+
# background `sleep` whose pid is handed to wt_start through KIT_SESSION_PID.
|
|
12
|
+
#
|
|
13
|
+
# Run: bash scripts/lib/worktree-start-test.sh
|
|
14
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
15
|
+
set -u
|
|
16
|
+
LIB="$(cd "$(dirname "$0")" && pwd)"
|
|
17
|
+
ROOT="$(cd "$LIB/../.." && pwd)"
|
|
18
|
+
# shellcheck source=/dev/null
|
|
19
|
+
. "$LIB/test-env.sh" && test_env_seal
|
|
20
|
+
command -v jq >/dev/null 2>&1 || { echo "worktree-start-test: jq required" >&2; exit 1; }
|
|
21
|
+
|
|
22
|
+
fail=0
|
|
23
|
+
t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
24
|
+
has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
|
|
25
|
+
|
|
26
|
+
tmp="$(cd "$(mktemp -d 2>/dev/null || mktemp -d -t wst)" && pwd -P)"
|
|
27
|
+
SESS_A=""; SESS_B=""
|
|
28
|
+
cleanup() {
|
|
29
|
+
[ -n "$SESS_A" ] && kill "$SESS_A" 2>/dev/null
|
|
30
|
+
[ -n "$SESS_B" ] && kill "$SESS_B" 2>/dev/null
|
|
31
|
+
rm -rf "$tmp"
|
|
32
|
+
}
|
|
33
|
+
trap cleanup EXIT INT TERM
|
|
34
|
+
|
|
35
|
+
# ── fixture: stubs, a bare origin with `main`, and a clone to start worktrees from ─────────────
|
|
36
|
+
mkdir -p "$tmp/bin"
|
|
37
|
+
cat > "$tmp/bin/gh" <<'SH'
|
|
38
|
+
#!/usr/bin/env bash
|
|
39
|
+
# Every call is logged, so a test can assert a refusal made NO GitHub read.
|
|
40
|
+
printf '%s\n' "$*" >> "${GH_CALL_LOG:-/dev/null}"
|
|
41
|
+
case "$*" in
|
|
42
|
+
*"issue view"*) echo '{"title":"Claimed thing","labels":[{"name":"kind:task"}]}' ;;
|
|
43
|
+
*graphql*) echo '{"data":{}}' ;;
|
|
44
|
+
*) echo '[]' ;;
|
|
45
|
+
esac
|
|
46
|
+
SH
|
|
47
|
+
printf '#!/bin/sh\nexit 0\n' > "$tmp/bin/zoxide"
|
|
48
|
+
chmod +x "$tmp/bin/gh" "$tmp/bin/zoxide"
|
|
49
|
+
PATH="$tmp/bin:$PATH"; export PATH
|
|
50
|
+
export GH_CALL_LOG="$tmp/gh.calls"; : > "$GH_CALL_LOG"
|
|
51
|
+
|
|
52
|
+
git init -q --bare "$tmp/origin.git"
|
|
53
|
+
git init -q "$tmp/repo"
|
|
54
|
+
(
|
|
55
|
+
cd "$tmp/repo" || exit 1
|
|
56
|
+
git config user.email t@example.invalid; git config user.name t; git config commit.gpgsign false
|
|
57
|
+
git checkout -q -b main
|
|
58
|
+
printf '{ "kitVersion":"9.9.9", "project":{"name":"fx","slug":"fx"},\n "github":{"repo":"octo/fx","owner":"octo","baseBranch":"main","projectsV2":false} }\n' > cckit.config.json
|
|
59
|
+
git add cckit.config.json && git commit -q -m init
|
|
60
|
+
git remote add origin "$tmp/origin.git" && git push -q origin main
|
|
61
|
+
) || { echo "FAIL: fixture repo setup"; exit 1; }
|
|
62
|
+
REPO="$tmp/repo"
|
|
63
|
+
REG="$REPO/.git/kit-sessions"
|
|
64
|
+
|
|
65
|
+
export WT_START_REPO="octo/fx" KIT_BASE_BRANCH="main" KIT_WT_INSTALL=0
|
|
66
|
+
# shellcheck source=/dev/null
|
|
67
|
+
. "$LIB/worktree-start.sh"
|
|
68
|
+
|
|
69
|
+
sleep 600 & SESS_A=$!
|
|
70
|
+
sleep 600 & SESS_B=$!
|
|
71
|
+
|
|
72
|
+
# start_as <session-pid> <args…> — wt_start from the main checkout, as that session.
|
|
73
|
+
start_as() { local sp="$1"; shift; ( cd "$REPO" && KIT_SESSION_PID="$sp" wt_start "$@" ); }
|
|
74
|
+
branches() { git -C "$REPO" for-each-ref --format='%(refname:short)' refs/heads | sort | tr '\n' ' '; }
|
|
75
|
+
worktrees() { git -C "$REPO" worktree list --porcelain | grep -c '^worktree '; }
|
|
76
|
+
|
|
77
|
+
# ── 1. first start: creates the worktree and writes the claim ──────────────────────────────────
|
|
78
|
+
out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
|
|
79
|
+
t "first start succeeds" "$rc" "0"
|
|
80
|
+
WT7="$REPO/.claude/worktrees/task+7-claimed-thing"
|
|
81
|
+
t "first start prints path|branch|issue" "$out" "$WT7|task/7-claimed-thing|7"
|
|
82
|
+
t "claim file written" "$([ -f "$REG/issue-7.json" ] && echo yes || echo no)" "yes"
|
|
83
|
+
t "claim records the session pid" "$(jq -r .pid "$REG/issue-7.json" 2>/dev/null)" "$SESS_A"
|
|
84
|
+
t "claim records the worktree" "$(jq -r .worktree "$REG/issue-7.json" 2>/dev/null)" "$WT7"
|
|
85
|
+
t "claim records the branch" "$(jq -r .branch "$REG/issue-7.json" 2>/dev/null)" "task/7-claimed-thing"
|
|
86
|
+
t "claim records the issue" "$(jq -r .issue "$REG/issue-7.json" 2>/dev/null)" "7"
|
|
87
|
+
t "claim records a start time" "$(jq -r '.started | type' "$REG/issue-7.json" 2>/dev/null)" "number"
|
|
88
|
+
|
|
89
|
+
# ── 6. the EXISTING reader sees the claim (it reads .pid + .cwd, skips cache-*) ────────────────
|
|
90
|
+
_wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns sees the wt_start claim" "$?" "0"
|
|
91
|
+
_wt_session_owns "$REPO" "$REPO/.claude/worktrees/task+8-nope"; t "_wt_session_owns is false for an unclaimed path" "$?" "1"
|
|
92
|
+
|
|
93
|
+
# ── 1. a second session is refused — and nothing is created, nothing is fetched or read ────────
|
|
94
|
+
# A second issue number makes "no new worktree, no new branch" observable: 7 already has both, so
|
|
95
|
+
# the refusal case that proves it is a claim on an issue whose worktree does NOT exist yet.
|
|
96
|
+
mkdir -p "$REG"
|
|
97
|
+
jq -n --argjson pid "$SESS_A" --arg host "$(hostname)" --arg wt "$REPO/.claude/worktrees/task+9-claimed-thing" \
|
|
98
|
+
--argjson started "$(date +%s)" \
|
|
99
|
+
'{issue:9, branch:"task/9-claimed-thing", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' \
|
|
100
|
+
> "$REG/issue-9.json"
|
|
101
|
+
b_before="$(branches)"; w_before="$(worktrees)"; : > "$GH_CALL_LOG"
|
|
102
|
+
fetch_before="$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)"
|
|
103
|
+
err="$(start_as "$SESS_B" 9 2>&1 >/dev/null)"; rc=$?
|
|
104
|
+
t "second session on a claimed issue is refused (rc 1)" "$rc" "1"
|
|
105
|
+
has "refusal names the claimant pid" "$err" "pid $SESS_A"
|
|
106
|
+
has "refusal names the escape hatch" "$err" "--force"
|
|
107
|
+
t "refusal creates no branch" "$(branches)" "$b_before"
|
|
108
|
+
t "refusal creates no worktree" "$(worktrees)" "$w_before"
|
|
109
|
+
t "refusal creates no worktree dir" "$([ -e "$REPO/.claude/worktrees/task+9-claimed-thing" ] && echo yes || echo no)" "no"
|
|
110
|
+
t "refusal makes no gh call (it runs before the issue read)" "$(wc -l < "$GH_CALL_LOG" | tr -d ' ')" "0"
|
|
111
|
+
t "refusal runs before the fetch (FETCH_HEAD untouched)" \
|
|
112
|
+
"$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)" "$fetch_before"
|
|
113
|
+
t "refusal leaves the claim with its owner" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_A"
|
|
114
|
+
|
|
115
|
+
# The same refusal on the issue that already has a worktree: no "reusing worktree" success.
|
|
116
|
+
out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
|
|
117
|
+
t "second session on a claimed, existing worktree is refused" "$rc" "1"
|
|
118
|
+
t "refused start prints no worktree line" "$out" ""
|
|
119
|
+
|
|
120
|
+
# ── 2. --force and KIT_FORCE=1 proceed ─────────────────────────────────────────────────────────
|
|
121
|
+
out="$(start_as "$SESS_B" --force 9 2>/dev/null)"; rc=$?
|
|
122
|
+
t "--force starts a claimed issue" "$rc" "0"
|
|
123
|
+
t "--force is not taken for the issue number" "$out" "$REPO/.claude/worktrees/task+9-claimed-thing|task/9-claimed-thing|9"
|
|
124
|
+
t "--force takes the claim over" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_B"
|
|
125
|
+
out="$(start_as "$SESS_B" 7 --force 2>/dev/null)"; rc=$?
|
|
126
|
+
t "--force after the issue number also works" "$rc" "0"
|
|
127
|
+
t "claim 7 now belongs to the forcing session" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
|
|
128
|
+
out="$( cd "$REPO" && KIT_FORCE=1 KIT_SESSION_PID="$SESS_A" wt_start 7 2>/dev/null )"; rc=$?
|
|
129
|
+
t "KIT_FORCE=1 starts a claimed issue" "$rc" "0"
|
|
130
|
+
t "KIT_FORCE=1 takes the claim over" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_A"
|
|
131
|
+
err="$(start_as "$SESS_A" --bogus 7 2>&1 >/dev/null)"; rc=$?
|
|
132
|
+
t "an unknown flag is refused, not read as the issue" "$rc" "1"
|
|
133
|
+
|
|
134
|
+
# ── 4. the claimant's own re-run is a no-op success ────────────────────────────────────────────
|
|
135
|
+
before="$(cat "$REG/issue-7.json")"
|
|
136
|
+
out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
|
|
137
|
+
t "re-run by the claiming session succeeds" "$rc" "0"
|
|
138
|
+
t "re-run by the claiming session leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
|
|
139
|
+
# From inside the claim's own worktree, as a session with a DIFFERENT pid (an agent's fresh shell).
|
|
140
|
+
out="$( cd "$WT7" && KIT_SESSION_PID="$SESS_B" wt_start 7 2>/dev/null )"; rc=$?
|
|
141
|
+
t "re-run from the claim's own worktree succeeds" "$rc" "0"
|
|
142
|
+
t "re-run from the claim's own worktree prints the same line" "$out" "$WT7|task/7-claimed-thing|7"
|
|
143
|
+
t "re-run from the claim's own worktree leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
|
|
144
|
+
t "re-run added no worktree" "$(worktrees)" "3"
|
|
145
|
+
|
|
146
|
+
# ── 5. `cckit claims` lists the live claims and writes nothing ─────────────────────────────────
|
|
147
|
+
snap() { ( cd "$REG" && ls -la . && cat issue-*.json ) 2>/dev/null; }
|
|
148
|
+
before="$(snap)"
|
|
149
|
+
human="$( cd "$REPO" && "$ROOT/bin/cckit" claims 2>/dev/null )"; rc=$?
|
|
150
|
+
t "cckit claims exits 0" "$rc" "0"
|
|
151
|
+
has "cckit claims lists issue 7" "$human" "#7"
|
|
152
|
+
has "cckit claims lists the branch" "$human" "task/7-claimed-thing"
|
|
153
|
+
json="$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null )"
|
|
154
|
+
t "cckit claims --llm is a JSON array of both live claims" "$(printf '%s' "$json" | jq -c '[.[].issue]' 2>/dev/null)" "[7,9]"
|
|
155
|
+
t "cckit claims --llm carries the pid" "$(printf '%s' "$json" | jq -r '.[0].pid' 2>/dev/null)" "$SESS_A"
|
|
156
|
+
t "cckit claims works from inside a worktree" "$( cd "$WT7" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[7,9]"
|
|
157
|
+
t "cckit claims writes nothing" "$(snap)" "$before"
|
|
158
|
+
|
|
159
|
+
# ── 3. a dead session's claim is reaped and the start proceeds ─────────────────────────────────
|
|
160
|
+
kill "$SESS_A" 2>/dev/null; wait "$SESS_A" 2>/dev/null; DEAD="$SESS_A"; SESS_A=""
|
|
161
|
+
before="$(snap)"
|
|
162
|
+
t "cckit claims hides a dead session's claim" "$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[9]"
|
|
163
|
+
t "cckit claims does not reap it (read-only)" "$(snap)" "$before"
|
|
164
|
+
_wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns is false once the session died" "$?" "1"
|
|
165
|
+
out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
|
|
166
|
+
t "start over a dead session's claim proceeds" "$rc" "0"
|
|
167
|
+
t "the dead claim was replaced by the new session's" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
|
|
168
|
+
t "the dead pid is gone from the registry" "$(grep -l "\"pid\": *$DEAD\b" "$REG"/issue-*.json 2>/dev/null | wc -l | tr -d ' ')" "0"
|
|
169
|
+
|
|
170
|
+
# A claim whose worktree was removed (the PR merged, cleanup ran) is dead even with a live pid,
|
|
171
|
+
# once it is older than the grace that covers the claim→`worktree add` window.
|
|
172
|
+
jq -n --argjson pid "$SESS_B" --arg host "$(hostname)" --arg wt "$tmp/gone" --argjson started "$(( $(date +%s) - 4000 ))" \
|
|
173
|
+
'{issue:11, branch:"task/11-x", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' > "$REG/issue-11.json"
|
|
174
|
+
start_as "$$" 11 >/dev/null 2>&1; rc=$?
|
|
175
|
+
t "a claim whose worktree is long gone does not block" "$rc" "0"
|
|
176
|
+
|
|
177
|
+
# ── a failed start does not leave a claim behind ───────────────────────────────────────────────
|
|
178
|
+
# `git worktree add -B` fails when the branch is checked out in the main checkout.
|
|
179
|
+
git -C "$REPO" checkout -q -b task/12-claimed-thing
|
|
180
|
+
start_as "$SESS_B" 12 >/dev/null 2>&1; rc=$?
|
|
181
|
+
t "a start whose worktree add fails returns 1" "$rc" "1"
|
|
182
|
+
t "…and releases the claim it had just taken" "$([ -e "$REG/issue-12.json" ] && echo yes || echo no)" "no"
|
|
183
|
+
git -C "$REPO" checkout -q main
|
|
184
|
+
|
|
185
|
+
# ── 7. the CLI reports the ISSUE, not the flag ─────────────────────────────────────────────────
|
|
186
|
+
json="$( cd "$REPO" && KIT_SESSION_PID="$$" "$ROOT/bin/cckit" start --force 9 --llm 2>/dev/null )"
|
|
187
|
+
t "cckit start --force N --llm reports issue N" "$(printf '%s' "$json" | jq -r '.issue' 2>/dev/null)" "9"
|
|
188
|
+
t "cckit start --force N --llm is ok" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "true"
|
|
189
|
+
json="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 --llm 2>/dev/null )"; rc=$?
|
|
190
|
+
t "cckit start on a claimed issue exits 1" "$rc" "1"
|
|
191
|
+
t "cckit start on a claimed issue reports ok:false" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "false"
|
|
192
|
+
err="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 2>&1 >/dev/null )"; rc=$?
|
|
193
|
+
t "cckit start (human mode) on a claimed issue exits 1" "$rc" "1"
|
|
194
|
+
has "cckit start (human mode) prints the refusal" "$err" "refused: a live session already claims this issue"
|
|
195
|
+
|
|
196
|
+
[ "$fail" -eq 0 ] && echo "ALL OK (worktree-start)" || echo "worktree-start: FAILURES"
|
|
197
|
+
exit "$fail"
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
# Family 1 of kit-engine-boundary.md (rule #1/#2): one bash home for the op, consumed by the
|
|
5
5
|
# kit-task-start skill, scripts/orchestrate.sh, and `kit task start`. No second implementation.
|
|
6
6
|
#
|
|
7
|
-
# wt_start <issue-number> [slug-override]
|
|
7
|
+
# wt_start [--force] <issue-number> [slug-override]
|
|
8
|
+
# Refuses (rc 1, before any fetch / branch / worktree) when another LIVE session already holds
|
|
9
|
+
# the issue's claim in <git-common-dir>/kit-sessions (session-registry.sh). `--force` or
|
|
10
|
+
# KIT_FORCE=1 starts anyway and takes the claim over.
|
|
8
11
|
# stdout: "<worktree-path>|<branch>|<issue-number>" (one line, machine-readable)
|
|
9
12
|
# stderr: human progress
|
|
10
13
|
# returns: 0 on success (created or reused), 1 on failure
|
|
@@ -21,6 +24,31 @@ if ! command -v cckit_gh_rest >/dev/null 2>&1; then
|
|
|
21
24
|
fi
|
|
22
25
|
command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
|
|
23
26
|
|
|
27
|
+
# The claims registry (#384). Guarded: a project scaffolded before session-registry.sh shipped has
|
|
28
|
+
# worktree-start.sh without it, and there wt_start runs with no claim check rather than failing.
|
|
29
|
+
if ! command -v sreg_claim >/dev/null 2>&1; then
|
|
30
|
+
_sr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/session-registry.sh"
|
|
31
|
+
# shellcheck source=/dev/null
|
|
32
|
+
[ -f "$_sr_lib" ] && . "$_sr_lib"
|
|
33
|
+
unset _sr_lib
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# The closed kind: vocabulary (kinds.sh). The issue's `kind:` label becomes the branch prefix, so it
|
|
37
|
+
# is mapped through the set: a label outside it (kind:bug, kind:docs, a typo) would otherwise produce
|
|
38
|
+
# a branch the hygiene hook rejects as non-conventional.
|
|
39
|
+
if ! command -v kit_kind_branch >/dev/null 2>&1; then
|
|
40
|
+
_wtk_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/kinds.sh"
|
|
41
|
+
# shellcheck source=/dev/null
|
|
42
|
+
[ -f "$_wtk_lib" ] && . "$_wtk_lib"
|
|
43
|
+
unset _wtk_lib
|
|
44
|
+
fi
|
|
45
|
+
# _wt_kind_prefix <kind> — the branch prefix for a kind label value. With kinds.sh loaded: the value
|
|
46
|
+
# itself when it is in the closed set, else `task` plus a warning on stderr. Without kinds.sh (a
|
|
47
|
+
# project scaffolded before it shipped) the value passes through unchanged, as it always did.
|
|
48
|
+
_wt_kind_prefix() {
|
|
49
|
+
if command -v kit_kind_branch >/dev/null 2>&1; then kit_kind_branch "${1:-}"; else printf '%s\n' "${1:-task}"; fi
|
|
50
|
+
}
|
|
51
|
+
|
|
24
52
|
WT_START_REPO="${WT_START_REPO:-${KIT_REPO:-}}"
|
|
25
53
|
|
|
26
54
|
# _wt_set_port <app-env-file> <port> <issue-num> — append a per-worktree dev PORT to an app's
|
|
@@ -31,7 +59,8 @@ WT_START_REPO="${WT_START_REPO:-${KIT_REPO:-}}"
|
|
|
31
59
|
# file. A script like `next dev -p ${PORT:-3003}` is expanded by the npm-script shell, which never
|
|
32
60
|
# reads .env.local, so the value is INERT for it and every worktree falls back to the same default.
|
|
33
61
|
# cckit therefore does not RELY on it: everything cckit launches itself passes the port explicitly
|
|
34
|
-
# (scripts/lib/qa-lane.sh
|
|
62
|
+
# (scripts/lib/qa-lane.sh exports each port env var the project declared in `qa.ports`, set to that
|
|
63
|
+
# lane's port, into the command it launches). Treat the .env.local write as
|
|
35
64
|
# a convenience for apps that do read it — and if you start a dev server by hand in a worktree,
|
|
36
65
|
# check which port you actually got.
|
|
37
66
|
_wt_set_port() {
|
|
@@ -55,6 +84,16 @@ _wt_set_port() {
|
|
|
55
84
|
# State lives beside the event log under the git-common-dir, so it is worktree-durable and shared by
|
|
56
85
|
# every checkout. Each line: <issue>\t<slot>\t<worktree-path>. A slot whose worktree is gone is
|
|
57
86
|
# reclaimed on the next call, which is what keeps the 40 slots from leaking away over a long project.
|
|
87
|
+
# _wt_num_hash <key> — <key> itself when it is a number, else a number derived from it. The slot
|
|
88
|
+
# ledger is keyed by issue number; a light task (#450) is keyed by its id (`t3f9a`), and the hashed
|
|
89
|
+
# fallbacks below do arithmetic on the key.
|
|
90
|
+
_wt_num_hash() {
|
|
91
|
+
case "$1" in
|
|
92
|
+
''|*[!0-9]*) printf '%s' "$1" | cksum | cut -d' ' -f1 ;;
|
|
93
|
+
*) printf '%s' "$1" ;;
|
|
94
|
+
esac
|
|
95
|
+
}
|
|
96
|
+
|
|
58
97
|
_wt_slots_file() {
|
|
59
98
|
local gcd
|
|
60
99
|
gcd="$(git -C "${1:-.}" rev-parse --git-common-dir 2>/dev/null)" || return 1
|
|
@@ -68,34 +107,46 @@ _wt_slots_file() {
|
|
|
68
107
|
# very defect the slot ledger exists to remove. The reclaim rewrite races worse than the append:
|
|
69
108
|
# it `mv`s a snapshot over the ledger, silently dropping any row another process added in between.
|
|
70
109
|
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
110
|
+
# The lock primitive is the shell's own noclobber redirection: `set -C; : > file` opens with
|
|
111
|
+
# O_CREAT|O_EXCL, which the kernel makes exclusive, and no external tool is involved. A stock macOS
|
|
112
|
+
# has no flock(1) and this file targets bash 3.2.
|
|
113
|
+
#
|
|
114
|
+
# It was `mkdir` until #449. `mkdir` is exclusive only when the binary makes ONE mkdir(2) call and
|
|
115
|
+
# reports its EEXIST. uutils coreutils 0.10.0 (the `mkdir` of Ubuntu 26.04, and of GitHub's
|
|
116
|
+
# `ubuntu-latest` runner) calls statx first and exits 0 for the loser of a race: 8 processes running
|
|
117
|
+
# `mkdir <same path>` at once all "succeeded" in 183 of 200 rounds. Two `cckit start` runs then held
|
|
118
|
+
# this lock together and were given the same slot.
|
|
74
119
|
_WT_LOCK_WAIT="${_WT_LOCK_WAIT:-10}" # seconds to wait for a held lock before giving up
|
|
75
120
|
|
|
76
|
-
#
|
|
121
|
+
# _wt_lock_try <lockfile> — ONE attempt: 0 when this call created the lock, 1 when it exists. The
|
|
122
|
+
# subshell keeps noclobber out of the caller's shell. Never replace this with an external command
|
|
123
|
+
# without racing it first (scripts/lib/worktree-ports-test.sh section 7 does).
|
|
124
|
+
_wt_lock_try() { ( set -C; : > "$1" ) 2>/dev/null; }
|
|
125
|
+
|
|
126
|
+
# _wt_lock <lockfile> — 0 when the lock is held, 1 when it is not. A caller that fails to lock
|
|
77
127
|
# proceeds ANYWAY: an unserialized allocation can collide, but a `cckit start` that refuses to run
|
|
78
128
|
# cannot be worked around. Degrade, don't block.
|
|
79
129
|
#
|
|
80
|
-
# A lock
|
|
130
|
+
# A lock older than a minute is treated as abandoned and broken, so a process killed
|
|
81
131
|
# mid-allocation cannot wedge every future start. The age floor is well above _WT_LOCK_WAIT, so a
|
|
82
|
-
# slow-but-live holder is never stolen from.
|
|
132
|
+
# slow-but-live holder is never stolen from. `rm -rf` because a cckit from before #449 leaves a
|
|
133
|
+
# lock DIRECTORY at the same path; either kind blocks the other, so mixed versions still exclude.
|
|
83
134
|
_wt_lock() {
|
|
84
135
|
local d="$1" tries=0 max
|
|
85
136
|
max=$(( _WT_LOCK_WAIT * 10 ))
|
|
86
137
|
while [[ "$tries" -lt "$max" ]]; do
|
|
87
|
-
|
|
138
|
+
_wt_lock_try "$d" && return 0
|
|
88
139
|
sleep 0.1 2>/dev/null || sleep 1
|
|
89
140
|
tries=$(( tries + 1 ))
|
|
90
141
|
done
|
|
91
142
|
if [[ -n "$(find "$d" -maxdepth 0 -mmin +1 2>/dev/null)" ]]; then
|
|
92
143
|
rm -rf "$d" 2>/dev/null
|
|
93
|
-
|
|
144
|
+
_wt_lock_try "$d" && { echo "warn: broke an abandoned port-slot lock ($d)" >&2; return 0; }
|
|
94
145
|
fi
|
|
95
146
|
return 1
|
|
96
147
|
}
|
|
97
148
|
|
|
98
|
-
_wt_unlock() {
|
|
149
|
+
_wt_unlock() { rm -rf "$1" 2>/dev/null; }
|
|
99
150
|
|
|
100
151
|
# _wt_slot_alloc <ledger> <issue-num> <worktree> — the ledger transaction: reclaim dead rows,
|
|
101
152
|
# return the issue's existing allocation if it has one, else take the lowest free slot and append
|
|
@@ -125,7 +176,7 @@ _wt_slot_alloc() {
|
|
|
125
176
|
i=$(( i + 1 ))
|
|
126
177
|
done
|
|
127
178
|
echo "[#$num] warn: all 40 dev-port slots are held — falling back to a hashed port (collisions possible); run cckit gc" >&2
|
|
128
|
-
printf '%s' $(( num % 40 ))
|
|
179
|
+
printf '%s' $(( $(_wt_num_hash "$num") % 40 ))
|
|
129
180
|
}
|
|
130
181
|
|
|
131
182
|
# _wt_slot_for <root> <issue-num> <worktree> — echo this issue's slot (0-39), allocating on first
|
|
@@ -134,8 +185,10 @@ _wt_slot_alloc() {
|
|
|
134
185
|
# a warning) only when every slot is genuinely held.
|
|
135
186
|
_wt_slot_for() {
|
|
136
187
|
local root="$1" num="$2" wt="$3" f lock out locked=0
|
|
137
|
-
f="$(_wt_slots_file "$root")" || { printf '%s' $(( num % 40 )); return 0; }
|
|
138
|
-
|
|
188
|
+
f="$(_wt_slots_file "$root")" || { printf '%s' $(( $(_wt_num_hash "$num") % 40 )); return 0; }
|
|
189
|
+
# `>>`, not `>`: this line runs BEFORE the lock, so a truncating create could empty a ledger that
|
|
190
|
+
# another process created and wrote to between the test and the redirection.
|
|
191
|
+
[[ -f "$f" ]] || : >> "$f" 2>/dev/null || { printf '%s' $(( $(_wt_num_hash "$num") % 40 )); return 0; }
|
|
139
192
|
|
|
140
193
|
lock="$f.lock"
|
|
141
194
|
if _wt_lock "$lock"; then locked=1; else
|
|
@@ -146,6 +199,22 @@ _wt_slot_for() {
|
|
|
146
199
|
printf '%s' "$out"
|
|
147
200
|
}
|
|
148
201
|
|
|
202
|
+
# wt_port_slot <root> <issue-num> <worktree> — the PUBLIC reader of the slot ledger: echo the slot
|
|
203
|
+
# (0-39) this issue holds, allocating one on first call. Same row `cckit start` uses, so a caller
|
|
204
|
+
# that launches something for an issue's worktree (the QA lane, qa-lane.sh) lands on the port block
|
|
205
|
+
# that worktree already owns instead of deriving a second one.
|
|
206
|
+
wt_port_slot() { _wt_slot_for "$1" "$2" "$3"; }
|
|
207
|
+
|
|
208
|
+
# wt_port_stride <config-file> — the distance between one slot's port block and the next:
|
|
209
|
+
# `worktree.devPortStride`, default 10. One reader, so wt_assign_ports and the QA lane cannot
|
|
210
|
+
# disagree about where the next block starts.
|
|
211
|
+
wt_port_stride() {
|
|
212
|
+
local stride=""
|
|
213
|
+
stride="$(jq -r '.worktree.devPortStride // empty' "${1:-}" 2>/dev/null)"
|
|
214
|
+
[[ "$stride" =~ ^[0-9]+$ && "$stride" -gt 0 ]] || stride=10
|
|
215
|
+
printf '%s' "$stride"
|
|
216
|
+
}
|
|
217
|
+
|
|
149
218
|
wt_assign_ports() {
|
|
150
219
|
# `apppath`, not `path`: under zsh `path` is tied to PATH (special array); a bare `path` local
|
|
151
220
|
# would clobber the command search path on assignment. A namespaced name is inert.
|
|
@@ -168,8 +237,7 @@ wt_assign_ports() {
|
|
|
168
237
|
# different worktrees. Real example (bases 3001/3003/3004, n=3): worktree offset k+1's admin port
|
|
169
238
|
# (3004+3k) IS worktree offset k's api port. Configurable as `worktree.devPortStride`; the default
|
|
170
239
|
# leaves room for up to 10 services per project.
|
|
171
|
-
stride="$(
|
|
172
|
-
[[ "$stride" =~ ^[0-9]+$ && "$stride" -gt 0 ]] || stride=10
|
|
240
|
+
stride="$(wt_port_stride "$cfg")"
|
|
173
241
|
|
|
174
242
|
# The invariant that keeps blocks disjoint: every base must sit inside ONE stride-wide window.
|
|
175
243
|
# Warn rather than fail — the ports still work, they just stop being collision-proof, and a
|
|
@@ -180,7 +248,7 @@ wt_assign_ports() {
|
|
|
180
248
|
fi
|
|
181
249
|
|
|
182
250
|
offset="$(_wt_slot_for "$root" "$num" "$wt")"
|
|
183
|
-
[[ "$offset" =~ ^[0-9]+$ ]] || offset=$(( num % 40 ))
|
|
251
|
+
[[ "$offset" =~ ^[0-9]+$ ]] || offset=$(( $(_wt_num_hash "$num") % 40 ))
|
|
184
252
|
i=0
|
|
185
253
|
while [[ "$i" -lt "$n" ]]; do
|
|
186
254
|
apppath="$(jq -r ".[$i].path // empty" <<<"$ports")"
|
|
@@ -216,7 +284,7 @@ _wt_json_has() {
|
|
|
216
284
|
if command -v jq >/dev/null 2>&1; then
|
|
217
285
|
jq -e "$filter" "$file" >/dev/null 2>&1
|
|
218
286
|
else
|
|
219
|
-
tr -d ' \n\t' < "$file" 2>/dev/null
|
|
287
|
+
grep -qE "$re" <<<"$(tr -d ' \n\t' < "$file" 2>/dev/null)"
|
|
220
288
|
fi
|
|
221
289
|
}
|
|
222
290
|
|
|
@@ -423,7 +491,7 @@ wt_bootstrap() {
|
|
|
423
491
|
# • no LIVE session owns it (kit-sessions registry: no live pid sitting in that dir)
|
|
424
492
|
|
|
425
493
|
# _wt_mtime <path> — file mtime as epoch seconds (BSD stat, then GNU stat). Picks the oldest tree.
|
|
426
|
-
_wt_mtime() { stat -
|
|
494
|
+
_wt_mtime() { stat -c %Y "$1" 2>/dev/null || stat -f %m "$1" 2>/dev/null; }
|
|
427
495
|
|
|
428
496
|
# _wt_list <root> — emit one "<path>\t<branch-or-->\t<locked:0|1>" line per worktree (porcelain).
|
|
429
497
|
_wt_list() {
|
|
@@ -457,7 +525,8 @@ _wt_is_clean() {
|
|
|
457
525
|
}
|
|
458
526
|
|
|
459
527
|
# _wt_session_owns <root> <path> — true when a LIVE Claude session sits in <path> (or a subdir),
|
|
460
|
-
# per the kit-sessions registry (.git/kit-sessions/*.json
|
|
528
|
+
# per the kit-sessions registry (.git/kit-sessions/*.json — wt_start writes one claim per issue
|
|
529
|
+
# through session-registry.sh, with `cwd` set to the worktree). A dead
|
|
461
530
|
# pid is not an owner. No registry → no known live owner (returns false).
|
|
462
531
|
_wt_session_owns() {
|
|
463
532
|
local root="$1" wt_path="$2" common reg f opid ocwd
|
|
@@ -500,7 +569,7 @@ _wt_pool_find() {
|
|
|
500
569
|
# mutates). Shows branch / merged-into-develop? / clean? / live-session? / overall reusable?.
|
|
501
570
|
wt_pool_status() {
|
|
502
571
|
local root wtdir wt_path branch locked merged clean owned reusable any=0
|
|
503
|
-
root="$(git worktree list --porcelain | awk '/^worktree /{print $2;
|
|
572
|
+
root="$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')"
|
|
504
573
|
[[ -n "$root" ]] || { echo "wt_pool_status: not in a git repo" >&2; return 1; }
|
|
505
574
|
wtdir="$root/.claude/worktrees/"
|
|
506
575
|
git -C "$root" fetch origin "${KIT_BASE_BRANCH:-main}" --quiet 2>/dev/null || true
|
|
@@ -522,15 +591,46 @@ wt_pool_status() {
|
|
|
522
591
|
[[ "$any" == "1" ]] || echo "(no pooled worktrees under $wtdir)"
|
|
523
592
|
}
|
|
524
593
|
|
|
594
|
+
# _wt_claim_desc <tsv-row> — one human line for a claim row from sreg_issue_claim.
|
|
595
|
+
_wt_claim_desc() {
|
|
596
|
+
local c_issue c_branch c_wt c_pid c_host c_started
|
|
597
|
+
IFS=$'\t' read -r c_issue c_branch c_wt c_pid c_host c_started <<EOF
|
|
598
|
+
$1
|
|
599
|
+
EOF
|
|
600
|
+
printf 'pid %s on %s, worktree %s' "$c_pid" "$c_host" "$c_wt"
|
|
601
|
+
}
|
|
602
|
+
|
|
525
603
|
wt_start() {
|
|
526
|
-
local num="
|
|
604
|
+
local num="" slug_override="" root meta title kind slug branch wt reused cand
|
|
605
|
+
local force="${KIT_FORCE:-0}" _arg _claim _claimed="" _crc
|
|
606
|
+
for _arg in "$@"; do
|
|
607
|
+
case "$_arg" in
|
|
608
|
+
--force) force=1 ;;
|
|
609
|
+
-*) echo "wt_start: unknown flag '$_arg' (usage: start [--force] <issue> [slug])" >&2; return 1 ;;
|
|
610
|
+
*) if [[ -z "$num" ]]; then num="$_arg"; elif [[ -z "$slug_override" ]]; then slug_override="$_arg"; fi ;;
|
|
611
|
+
esac
|
|
612
|
+
done
|
|
527
613
|
[[ -n "$num" ]] || { echo "wt_start: issue number required" >&2; return 1; }
|
|
528
614
|
|
|
529
|
-
root="$(git worktree list --porcelain | awk '/^worktree /{print $2;
|
|
615
|
+
root="$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')"
|
|
530
616
|
[[ -n "$root" ]] || { echo "wt_start: not in a git repo" >&2; return 1; }
|
|
531
617
|
|
|
532
|
-
#
|
|
533
|
-
#
|
|
618
|
+
# Claim check (#384) — BEFORE the issue read, the fetch and `git worktree add`, so a refusal
|
|
619
|
+
# makes no network call, no branch and no worktree. A claim this session already holds (same
|
|
620
|
+
# session pid, or the caller stands inside the claimed worktree) is not a collision: re-running
|
|
621
|
+
# start stays the no-op it always was.
|
|
622
|
+
if command -v sreg_issue_claim >/dev/null 2>&1 && _claim="$(sreg_issue_claim "$root" "$num")" \
|
|
623
|
+
&& ! sreg_claim_mine "$root" "$num"; then
|
|
624
|
+
if [[ "$force" != "1" ]]; then
|
|
625
|
+
echo "[#$num] refused: a live session already claims this issue — $(_wt_claim_desc "$_claim")" >&2
|
|
626
|
+
echo "[#$num] see 'cckit claims'; 'cckit start --force $num' (or KIT_FORCE=1) starts anyway and takes the claim." >&2
|
|
627
|
+
return 1
|
|
628
|
+
fi
|
|
629
|
+
echo "[#$num] ⚠ --force: taking over the claim of a live session — $(_wt_claim_desc "$_claim")" >&2
|
|
630
|
+
fi
|
|
631
|
+
|
|
632
|
+
# The board helpers load lazily, further down: Status is otherwise set server-side by built-in
|
|
633
|
+
# automations (Item closed→Done, PR merged→Done), and In Progress is the one write wt_start owns.
|
|
534
634
|
|
|
535
635
|
if cckit_gh_rest; then
|
|
536
636
|
meta="$(gh_rest_issue_json "$WT_START_REPO" "$num" 2>/dev/null)" || { echo "[#$num] issue not found" >&2; return 1; }
|
|
@@ -540,6 +640,7 @@ wt_start() {
|
|
|
540
640
|
fi
|
|
541
641
|
title="$(echo "$meta" | jq -r '.title')"
|
|
542
642
|
kind="$(echo "$meta" | jq -r '([.labels[].name | select(startswith("kind:"))][0] // "kind:task") | sub("^kind:";"")')"
|
|
643
|
+
kind="$(_wt_kind_prefix "$kind")"
|
|
543
644
|
if [[ -n "$slug_override" ]]; then
|
|
544
645
|
slug="$slug_override"
|
|
545
646
|
else
|
|
@@ -552,8 +653,26 @@ wt_start() {
|
|
|
552
653
|
branch="$kind/$num-$slug"
|
|
553
654
|
wt="$root/.claude/worktrees/${kind}+${num}-${slug}"
|
|
554
655
|
|
|
656
|
+
# Take the claim now that the worktree path is known, still before the fetch. rc 3 = another
|
|
657
|
+
# session claimed the issue between the check above and here. An unwritable registry only warns:
|
|
658
|
+
# the registry is a guard, not a precondition for working.
|
|
659
|
+
if command -v sreg_claim >/dev/null 2>&1; then
|
|
660
|
+
# _claimed marks a claim THIS call writes (none before, or one taken over by force), so a
|
|
661
|
+
# failed `worktree add` below releases only that — never a claim the session already held.
|
|
662
|
+
sreg_claim_mine "$root" "$num" || _claimed="1"
|
|
663
|
+
# `&& … ||` so a caller running under `set -e` (bin/cckit) reaches the refusal message.
|
|
664
|
+
sreg_claim "$root" "$num" "$branch" "$wt" "$force" && _crc=0 || _crc=$?
|
|
665
|
+
if [[ "$_crc" -eq 3 ]]; then
|
|
666
|
+
echo "[#$num] refused: another session claimed this issue just now — see 'cckit claims'." >&2
|
|
667
|
+
return 1
|
|
668
|
+
elif [[ "$_crc" -ne 0 ]]; then
|
|
669
|
+
_claimed=""
|
|
670
|
+
echo "[#$num] ⚠ could not record the session claim; continuing without one." >&2
|
|
671
|
+
fi
|
|
672
|
+
fi
|
|
673
|
+
|
|
555
674
|
git -C "$root" fetch origin "${KIT_BASE_BRANCH:-main}" --quiet
|
|
556
|
-
if
|
|
675
|
+
if grep -q "/${kind}+${num}-${slug}$" <<<"$(git -C "$root" worktree list --porcelain)"; then
|
|
557
676
|
echo "[#$num] reusing worktree $wt" >&2
|
|
558
677
|
else
|
|
559
678
|
reused=""
|
|
@@ -575,7 +694,8 @@ wt_start() {
|
|
|
575
694
|
fi
|
|
576
695
|
if [[ -z "$reused" ]]; then
|
|
577
696
|
git -C "$root" worktree add -B "$branch" "$wt" origin/${KIT_BASE_BRANCH:-main} >/dev/null 2>&1 \
|
|
578
|
-
|| {
|
|
697
|
+
|| { if [[ -n "$_claimed" ]]; then sreg_release "$root" "$num" 2>/dev/null || true; fi
|
|
698
|
+
echo "[#$num] worktree add failed (branch $branch may exist elsewhere)" >&2; return 1; }
|
|
579
699
|
echo "[#$num] created worktree $wt (branch $branch)" >&2
|
|
580
700
|
fi
|
|
581
701
|
fi
|
|
@@ -595,12 +715,14 @@ wt_start() {
|
|
|
595
715
|
command -v cckit_board_skipped >/dev/null 2>&1 && cckit_board_skipped
|
|
596
716
|
elif source "$root/scripts/lib/gh-project.sh" 2>/dev/null; then
|
|
597
717
|
[[ -n "${STATUS_FIELD_ID:-}" ]] || load_project_ids >/dev/null 2>&1 || true
|
|
598
|
-
#
|
|
599
|
-
#
|
|
718
|
+
# Board precheck (#124, #384): an issue ALREADY In Progress or In Review may belong to someone
|
|
719
|
+
# the local claims registry cannot see (a teammate's machine). Warn only — wt_start writes In
|
|
720
|
+
# Progress itself and nothing resets it when a session dies, so refusing on board Status would
|
|
721
|
+
# lock out every restart after a crash. The refusal is the live claim, checked at the top.
|
|
600
722
|
if command -v project_issue_status >/dev/null 2>&1; then
|
|
601
723
|
local _prev_status; _prev_status="$(project_issue_status "$num" 2>/dev/null || true)"
|
|
602
|
-
[[ "$_prev_status" == "In Progress" ]] \
|
|
603
|
-
&& echo "[#$num] ⚠ already
|
|
724
|
+
[[ "$_prev_status" == "In Progress" || "$_prev_status" == "In Review" ]] \
|
|
725
|
+
&& echo "[#$num] ⚠ already $_prev_status on the board — another session may own this issue; continuing." >&2
|
|
604
726
|
fi
|
|
605
727
|
item="$(project_find_item_by_issue "$num" 2>/dev/null)"
|
|
606
728
|
if [[ -z "$item" ]]; then
|