@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# role-identity-test.sh — every role a shipped profile declares resolves to a display name, so the
|
|
3
|
+
# commit author, the PR signature and the board Role are never empty for it (#416).
|
|
4
|
+
# Runs the helpers under bash AND zsh. Hermetic: no network, no gh, no files written.
|
|
5
|
+
# Run: bash scripts/lib/role-identity-test.sh
|
|
6
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
7
|
+
|
|
8
|
+
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
9
|
+
root=$(CDPATH='' cd -- "$dir/../.." && pwd)
|
|
10
|
+
|
|
11
|
+
if [ -n "${ROLE_TEST_INNER:-}" ]; then
|
|
12
|
+
unset KIT_ROLES KIT_ROLE_EMAIL_DOMAIN KIT_AGENT_LABEL
|
|
13
|
+
. "$dir/role-identity.sh"
|
|
14
|
+
. "$dir/gh-project.sh"
|
|
15
|
+
fail=0
|
|
16
|
+
eq() { if [ "$2" != "$3" ]; then echo "FAIL($ROLE_TEST_INNER): $1 -> '[$2]', want '[$3]'"; fail=1; fi; }
|
|
17
|
+
|
|
18
|
+
eq "role_display editor" "$(role_display editor)" "Editor"
|
|
19
|
+
eq "role_display researcher" "$(role_display researcher)" "Researcher"
|
|
20
|
+
eq "role_display analyst" "$(role_display analyst)" "Analyst"
|
|
21
|
+
eq "role_display tech-lead (unchanged)" "$(role_display tech-lead)" "Tech Lead"
|
|
22
|
+
eq "role_display unknown is empty" "$(role_display nobody)" ""
|
|
23
|
+
eq "role_display blank is empty" "$(role_display "")" ""
|
|
24
|
+
|
|
25
|
+
eq "author editor" "$(role_git_author editor)" "Editor (agent)|editor@agents.local"
|
|
26
|
+
eq "signature researcher" "$(role_signature researcher)" "— Researcher · agent (acting via the maintainer account)"
|
|
27
|
+
eq "author unknown is empty" "$(role_git_author nobody)" ""
|
|
28
|
+
|
|
29
|
+
# A role only the project's config declares resolves through KIT_ROLES.
|
|
30
|
+
KIT_ROLES="PM
|
|
31
|
+
Brand Lead
|
|
32
|
+
Editor"
|
|
33
|
+
eq "config role resolves" "$(role_display brand-lead)" "Brand Lead"
|
|
34
|
+
eq "config role signs" "$(role_git_author brand-lead)" "Brand Lead (agent)|brand-lead@agents.local"
|
|
35
|
+
eq "a slug not in the config stays empty" "$(role_display growth)" ""
|
|
36
|
+
unset KIT_ROLES
|
|
37
|
+
|
|
38
|
+
# The board Role option: found for a captured option, by display name.
|
|
39
|
+
ROLE_OPT_EDITOR="opt-ed"; ROLE_OPT_RESEARCHER="opt-re"
|
|
40
|
+
eq "role_option_id Editor" "$(role_option_id "$(role_display editor)" 2>/dev/null)" "opt-ed"
|
|
41
|
+
eq "role_option_id Researcher" "$(role_option_id "$(role_display researcher)" 2>/dev/null)" "opt-re"
|
|
42
|
+
exit "$fail"
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
fail=0
|
|
46
|
+
for sh in bash zsh; do
|
|
47
|
+
command -v "$sh" >/dev/null 2>&1 || { echo "skip: $sh not installed"; continue; }
|
|
48
|
+
if ROLE_TEST_INNER="$sh" "$sh" "$0"; then echo "ok: role helpers under $sh"; else fail=1; fi
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
# Every role of every shipped profile has a display name equal to the profile's own spelling.
|
|
52
|
+
command -v jq >/dev/null 2>&1 || { echo "skip: jq missing — profile roles not checked"; exit "$fail"; }
|
|
53
|
+
. "$dir/role-identity.sh"
|
|
54
|
+
for f in "$root"/profiles/*.json; do
|
|
55
|
+
roles="$(jq -r '.roles[]' "$f")"
|
|
56
|
+
old_ifs="$IFS"; IFS='
|
|
57
|
+
'
|
|
58
|
+
for r in $roles; do
|
|
59
|
+
slug="$(printf '%s' "$r" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')"
|
|
60
|
+
got="$(role_display "$slug")"
|
|
61
|
+
if [ "$got" = "$r" ]; then echo "ok: $(basename "$f") role '$r'"; else echo "FAIL: $(basename "$f") role '$r' (slug $slug) -> '[$got]'"; fail=1; fi
|
|
62
|
+
done
|
|
63
|
+
IFS="$old_ifs"
|
|
64
|
+
done
|
|
65
|
+
exit "$fail"
|
|
@@ -11,12 +11,24 @@
|
|
|
11
11
|
# Tunables (env):
|
|
12
12
|
# KIT_ROLE_EMAIL_DOMAIN synthetic author-email domain (default: agents.local — not a real inbox)
|
|
13
13
|
# KIT_AGENT_LABEL suffix in the author/sig label (default: agent)
|
|
14
|
-
# errors: pure — maps a role slug to an author + signature
|
|
14
|
+
# errors: pure — maps a role slug to an author + signature; an unknown slug prints an empty line
|
|
15
15
|
KIT_ROLE_EMAIL_DOMAIN="${KIT_ROLE_EMAIL_DOMAIN:-agents.local}"
|
|
16
16
|
KIT_AGENT_LABEL="${KIT_AGENT_LABEL:-agent}"
|
|
17
17
|
|
|
18
18
|
# role_display <slug> -> human label (empty for unknown/blank)
|
|
19
|
+
# The fixed list covers every role a shipped profile declares. A slug outside it resolves through
|
|
20
|
+
# the project's own roles (KIT_ROLES, newline-delimited display names from `roles` in the config,
|
|
21
|
+
# exported by load_kit_config): "Brand Lead" answers for `brand-lead`. So a role a project adds to
|
|
22
|
+
# its config signs its commits and pull requests without a code change here (#416).
|
|
19
23
|
role_display() {
|
|
24
|
+
local _rd_role _rd_slug
|
|
25
|
+
case "$1" in
|
|
26
|
+
editor) echo "Editor"; return 0 ;;
|
|
27
|
+
researcher) echo "Researcher"; return 0 ;;
|
|
28
|
+
analyst) echo "Analyst"; return 0 ;;
|
|
29
|
+
automation) echo "Automation"; return 0 ;;
|
|
30
|
+
generalist) echo "Generalist"; return 0 ;;
|
|
31
|
+
esac
|
|
20
32
|
case "$1" in
|
|
21
33
|
designer) echo "Designer" ;;
|
|
22
34
|
devops) echo "DevOps" ;;
|
|
@@ -29,7 +41,18 @@ role_display() {
|
|
|
29
41
|
tech-lead) echo "Tech Lead" ;;
|
|
30
42
|
research) echo "Research" ;;
|
|
31
43
|
backend) echo "Backend" ;;
|
|
32
|
-
|
|
44
|
+
'') echo "" ;;
|
|
45
|
+
*)
|
|
46
|
+
# No pipe and no `<<<`: this file is sourced by bash 3.2 and zsh, and the loop must set the
|
|
47
|
+
# answer in this shell.
|
|
48
|
+
while IFS= read -r _rd_role; do
|
|
49
|
+
[ -n "$_rd_role" ] || continue
|
|
50
|
+
_rd_slug="$(printf '%s' "$_rd_role" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')"
|
|
51
|
+
if [ "$_rd_slug" = "$1" ]; then printf '%s\n' "$_rd_role"; return 0; fi
|
|
52
|
+
done <<_RD_EOF
|
|
53
|
+
${KIT_ROLES:-}
|
|
54
|
+
_RD_EOF
|
|
55
|
+
echo "" ;;
|
|
33
56
|
esac
|
|
34
57
|
}
|
|
35
58
|
|
|
@@ -82,7 +82,7 @@ secret_guard_scan() {
|
|
|
82
82
|
while IFS= read -r line; do
|
|
83
83
|
[ -z "$line" ] && continue
|
|
84
84
|
echo "x secret-guard: secret-like content: $line" >&2; findings=$((findings+1))
|
|
85
|
-
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -nIE "$pat" 2>/dev/null |
|
|
85
|
+
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -nIE "$pat" 2>/dev/null | sed -n 1,20p)
|
|
86
86
|
done < <(_sg_secret_patterns)
|
|
87
87
|
|
|
88
88
|
# (c) generic secret assignment (placeholders allowed)
|
|
@@ -90,7 +90,7 @@ secret_guard_scan() {
|
|
|
90
90
|
[ -z "$line" ] && continue
|
|
91
91
|
case "$line" in *YOUR_*|*example*|*EXAMPLE*|*placeholder*|*changeme*|*xxxx*|*redacted*|*'<'*|*'${'*) continue ;; esac
|
|
92
92
|
echo "x secret-guard: secret-like assignment: $line" >&2; findings=$((findings+1))
|
|
93
|
-
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -niIE "$_sg_assign_pattern" 2>/dev/null |
|
|
93
|
+
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -niIE "$_sg_assign_pattern" 2>/dev/null | sed -n 1,20p)
|
|
94
94
|
|
|
95
95
|
# (d) user-supplied privacy denylist (agnostic: YOU declare what is yours; file stays local)
|
|
96
96
|
# Resolve against the shared .cckit/, not the CWD: the denylist is the user's declaration of what
|
|
@@ -105,7 +105,7 @@ secret_guard_scan() {
|
|
|
105
105
|
while IFS= read -r line; do
|
|
106
106
|
[ -z "$line" ] && continue
|
|
107
107
|
echo "x secret-guard: private term '$term' present: $line" >&2; findings=$((findings+1))
|
|
108
|
-
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -nIF "$term" 2>/dev/null |
|
|
108
|
+
done < <(printf '%s\n' "${files[@]:-}" | tr '\n' '\0' | xargs -0 grep -nIF "$term" 2>/dev/null | sed -n 1,10p)
|
|
109
109
|
done < "$denylist"
|
|
110
110
|
fi
|
|
111
111
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# session-registry-test.sh — the claims registry contract (#384), under bash AND zsh.
|
|
3
|
+
#
|
|
4
|
+
# worktree-start-test.sh proves wt_start's behaviour end to end; this file pins the registry's own
|
|
5
|
+
# rules — which pid a claim records, what counts as dead, who may release — in both shells the lib
|
|
6
|
+
# is sourced from.
|
|
7
|
+
#
|
|
8
|
+
# Run: bash scripts/lib/session-registry-test.sh
|
|
9
|
+
# Without args: re-runs itself under every available shell. With SRT_INNER set: runs the assertions
|
|
10
|
+
# in the current interpreter.
|
|
11
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
12
|
+
|
|
13
|
+
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
14
|
+
|
|
15
|
+
if [ -n "${SRT_INNER:-}" ]; then
|
|
16
|
+
unset KIT_SESSION_PID KIT_FORCE SREG_GRACE
|
|
17
|
+
. "$dir/session-registry.sh"
|
|
18
|
+
fail=0
|
|
19
|
+
t() { if [ "$2" = "$3" ]; then :; else echo "FAIL($SRT_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
20
|
+
|
|
21
|
+
tmp=$(cd "$(mktemp -d 2>/dev/null || mktemp -d -t srt)" && pwd -P)
|
|
22
|
+
sleep 600 & A=$!
|
|
23
|
+
sleep 600 & B=$!
|
|
24
|
+
trap 'kill "$A" "$B" 2>/dev/null; rm -rf "$tmp"' EXIT INT TERM
|
|
25
|
+
git init -q "$tmp/repo"; R="$tmp/repo"; REG="$R/.git/kit-sessions"
|
|
26
|
+
mkdir -p "$tmp/wt"
|
|
27
|
+
|
|
28
|
+
# ── sreg_dir: the shared git dir, the same from a subdirectory ────────────────────────────
|
|
29
|
+
t "sreg_dir is under the git common dir" "$(sreg_dir "$R")" "$REG"
|
|
30
|
+
mkdir -p "$R/sub"; t "sreg_dir from a subdirectory" "$(sreg_dir "$R/sub")" "$REG"
|
|
31
|
+
sreg_dir "$tmp" >/dev/null 2>&1; t "sreg_dir outside a repo fails" "$?" "1"
|
|
32
|
+
|
|
33
|
+
# ── sreg_session_pid ──────────────────────────────────────────────────────────────────────
|
|
34
|
+
t "KIT_SESSION_PID overrides" "$(KIT_SESSION_PID=$A sreg_session_pid)" "$A"
|
|
35
|
+
auto=$(sreg_session_pid)
|
|
36
|
+
case "$auto" in ''|*[!0-9]*) t "auto session pid is numeric" "$auto" "<pid>" ;; esac
|
|
37
|
+
kill -0 "$auto" 2>/dev/null; t "auto session pid is a live process" "$?" "0"
|
|
38
|
+
# A throwaway `<shell> -c` between the session and the call must not become the session: the pid
|
|
39
|
+
# resolved one shell deeper is the same one. The intermediate shell is the interpreter under
|
|
40
|
+
# test, never `sh`: the lib is bash/zsh-only (`[[`), and `sh` is dash on the CI runner.
|
|
41
|
+
deeper=$("$SRT_INNER" -c ". '$dir/session-registry.sh'; sreg_session_pid")
|
|
42
|
+
t "an intermediate $SRT_INNER -c is skipped" "$deeper" "$auto"
|
|
43
|
+
|
|
44
|
+
# ── claim / mine / contested ──────────────────────────────────────────────────────────────
|
|
45
|
+
sreg_issue_claim "$R" 5 >/dev/null; t "no claim yet" "$?" "1"
|
|
46
|
+
sreg_claim "$R" abc b "$tmp/wt" >/dev/null 2>&1; t "a non-numeric issue is rejected" "$?" "1"
|
|
47
|
+
KIT_SESSION_PID=$A sreg_claim "$R" 5 task/5-x "$tmp/wt"; t "first claim" "$?" "0"
|
|
48
|
+
t "claim row" "$(sreg_issue_claim "$R" 5 | cut -f1-4)" "$(printf '5\ttask/5-x\t%s\t%s' "$tmp/wt" "$A")"
|
|
49
|
+
t "cwd mirrors the worktree for _wt_session_owns" "$(jq -r .cwd "$REG/issue-5.json")" "$tmp/wt"
|
|
50
|
+
( KIT_SESSION_PID=$A; export KIT_SESSION_PID; sreg_claim_mine "$R" 5 ); t "mine for the same session" "$?" "0"
|
|
51
|
+
( cd "$tmp" && KIT_SESSION_PID=$B sreg_claim_mine "$R" 5 ); t "not mine for another session" "$?" "1"
|
|
52
|
+
( cd "$tmp/wt" && KIT_SESSION_PID=$B sreg_claim_mine "$R" 5 ); t "mine from inside the claimed worktree" "$?" "0"
|
|
53
|
+
( cd "$tmp" && KIT_SESSION_PID=$B sreg_claim "$R" 5 task/5-x "$tmp/wt" ); t "contested claim returns 3" "$?" "3"
|
|
54
|
+
t "contested claim wrote nothing" "$(jq -r .pid "$REG/issue-5.json")" "$A"
|
|
55
|
+
( cd "$tmp" && KIT_SESSION_PID=$B sreg_release "$R" 5 ); t "another session cannot release" "$?" "1"
|
|
56
|
+
t "…and the claim is still there" "$([ -f "$REG/issue-5.json" ] && echo yes || echo no)" "yes"
|
|
57
|
+
( cd "$tmp" && KIT_SESSION_PID=$B sreg_claim "$R" 5 task/5-x "$tmp/wt" 1 ); t "forced claim returns 0" "$?" "0"
|
|
58
|
+
t "forced claim takes over" "$(jq -r .pid "$REG/issue-5.json")" "$B"
|
|
59
|
+
t "no temp file left behind" "$(ls -a "$REG" | grep -c '\.tmp$')" "0"
|
|
60
|
+
|
|
61
|
+
# ── list: read-only, sorted ───────────────────────────────────────────────────────────────
|
|
62
|
+
KIT_SESSION_PID=$A sreg_claim "$R" 12 task/12-y "$tmp/wt"
|
|
63
|
+
KIT_SESSION_PID=$A sreg_claim "$R" 3 task/3-z "$tmp/wt"
|
|
64
|
+
t "list is numerically sorted" "$(sreg_list "$R" | cut -f1 | tr '\n' ' ')" "3 5 12 "
|
|
65
|
+
t "list --json" "$(sreg_list "$R" --json | jq -c '[.[].issue]')" "[3,5,12]"
|
|
66
|
+
t "list --json on an empty registry is []" "$(sreg_list "$tmp/repo/sub/../../nowhere" --json 2>/dev/null)" "[]"
|
|
67
|
+
|
|
68
|
+
# ── liveness ──────────────────────────────────────────────────────────────────────────────
|
|
69
|
+
kill "$A" 2>/dev/null; wait "$A" 2>/dev/null
|
|
70
|
+
before=$(ls "$REG" | tr '\n' ' ')
|
|
71
|
+
t "list hides a dead session's claims" "$(sreg_list "$R" | cut -f1 | tr '\n' ' ')" "5 "
|
|
72
|
+
t "list deleted nothing" "$(ls "$REG" | tr '\n' ' ')" "$before"
|
|
73
|
+
sreg_reap "$R"
|
|
74
|
+
t "reap drops only the dead claims" "$(ls "$REG" | tr '\n' ' ')" "issue-5.json "
|
|
75
|
+
|
|
76
|
+
# pid reuse: a live pid whose start time is not the recorded one is a different process.
|
|
77
|
+
jq '.pstart = "Thu Jan 1 00:00:00 1970"' "$REG/issue-5.json" > "$REG/x" && mv "$REG/x" "$REG/issue-5.json"
|
|
78
|
+
sreg_issue_claim "$R" 5 >/dev/null; t "a reused pid does not hold the claim" "$?" "1"
|
|
79
|
+
t "…and that claim was reaped" "$([ -f "$REG/issue-5.json" ] && echo yes || echo no)" "no"
|
|
80
|
+
|
|
81
|
+
# Another host's claim: its pid means nothing here, so a dead-looking pid must NOT drop it.
|
|
82
|
+
now=$(date +%s)
|
|
83
|
+
printf '{"issue":20,"branch":"task/20-r","worktree":"%s","cwd":"%s","pid":%s,"host":"some-other-host","started":%s}\n' \
|
|
84
|
+
"$tmp/wt" "$tmp/wt" "$A" "$now" > "$REG/issue-20.json"
|
|
85
|
+
sreg_issue_claim "$R" 20 >/dev/null; t "a claim from another host survives a dead local pid" "$?" "0"
|
|
86
|
+
|
|
87
|
+
# Worktree gone: live inside the grace window (claim written before `git worktree add`), dead after.
|
|
88
|
+
printf '{"issue":21,"branch":"b","worktree":"%s","cwd":"%s","pid":%s,"host":"%s","started":%s}\n' \
|
|
89
|
+
"$tmp/gone" "$tmp/gone" "$B" "$(hostname)" "$now" > "$REG/issue-21.json"
|
|
90
|
+
sreg_issue_claim "$R" 21 >/dev/null; t "a fresh claim on a not-yet-created worktree is live" "$?" "0"
|
|
91
|
+
printf '{"issue":21,"branch":"b","worktree":"%s","cwd":"%s","pid":%s,"host":"%s","started":%s}\n' \
|
|
92
|
+
"$tmp/gone" "$tmp/gone" "$B" "$(hostname)" "$((now - 4000))" > "$REG/issue-21.json"
|
|
93
|
+
sreg_issue_claim "$R" 21 >/dev/null; t "an old claim on a missing worktree is dead" "$?" "1"
|
|
94
|
+
|
|
95
|
+
# Garbage in the directory is ignored, never fatal — the reader shares it with cache-* files.
|
|
96
|
+
echo 'not json' > "$REG/issue-30.json"; echo '{}' > "$REG/cache-x.json"
|
|
97
|
+
t "a corrupt claim file is skipped" "$(sreg_list "$R" | cut -f1 | tr '\n' ' ')" "20 "
|
|
98
|
+
|
|
99
|
+
[ "$fail" -eq 0 ] && echo "ok($SRT_INNER): session-registry"
|
|
100
|
+
exit "$fail"
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
rc=0; ran=0
|
|
104
|
+
for sh in bash zsh; do
|
|
105
|
+
command -v "$sh" >/dev/null 2>&1 || continue
|
|
106
|
+
ran=$((ran + 1))
|
|
107
|
+
SRT_INNER="$sh" "$sh" "$0" || rc=1
|
|
108
|
+
done
|
|
109
|
+
[ "$ran" -gt 0 ] || { echo "session-registry-test: no bash or zsh found" >&2; exit 1; }
|
|
110
|
+
[ "$rc" -eq 0 ] && echo "ALL OK (session-registry)"
|
|
111
|
+
exit "$rc"
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# session-registry.sh — which live session is working which issue (#384).
|
|
4
|
+
#
|
|
5
|
+
# `git worktree add` refuses one branch in two worktrees. It cannot see a session in ANOTHER
|
|
6
|
+
# checkout, or a second agent started on the same issue from the same checkout a moment later:
|
|
7
|
+
# both get a "reusing worktree" success and then write the same tree. This file is the record
|
|
8
|
+
# wt_start (worktree-start.sh) consults before it fetches or creates anything.
|
|
9
|
+
#
|
|
10
|
+
# One JSON file per claimed issue, under the shared git dir so every worktree reads the same set:
|
|
11
|
+
#
|
|
12
|
+
# <git-common-dir>/kit-sessions/issue-<N>.json
|
|
13
|
+
# {"issue":N,"branch":"…","worktree":"…","cwd":"…","pid":P,"pstart":"…","host":"…","started":EPOCH}
|
|
14
|
+
#
|
|
15
|
+
# `cwd` repeats `worktree` on purpose: `_wt_session_owns` (worktree-start.sh) already reads `.pid`
|
|
16
|
+
# and `.cwd` from every non-`cache-*` JSON file in this directory, so a claim written here also
|
|
17
|
+
# keeps the worktree pool from recycling a tree its session is still using.
|
|
18
|
+
#
|
|
19
|
+
# WHICH PID. Neither `cckit start`'s own pid nor the shell that ran it outlives the call when an
|
|
20
|
+
# agent runs each command in a fresh shell. The claim records the SESSION: `KIT_SESSION_PID` when
|
|
21
|
+
# set, else the nearest ancestor that is not a throwaway shell — the agent process, or the
|
|
22
|
+
# terminal's own login/tty shell for a person. See sreg_session_pid.
|
|
23
|
+
#
|
|
24
|
+
# LIVENESS drops a claim only on positive evidence its session is gone:
|
|
25
|
+
# • written on THIS host and the pid is dead, or alive with a different start time (pid reuse);
|
|
26
|
+
# • its worktree no longer exists and the claim is older than SREG_GRACE seconds (the grace covers
|
|
27
|
+
# the window between writing the claim and `git worktree add` creating the directory).
|
|
28
|
+
# A claim from another host is never dropped on a pid check — pids do not compare across hosts.
|
|
29
|
+
#
|
|
30
|
+
# sreg_dir <root> the registry directory (not created)
|
|
31
|
+
# sreg_session_pid the pid a claim written now would record
|
|
32
|
+
# sreg_issue_claim <root> <issue> reap a dead claim; print the live one as TSV, rc 1 if none
|
|
33
|
+
# sreg_claim_mine <root> <issue> rc 0 when the live claim is this session's own
|
|
34
|
+
# sreg_claim <root> <issue> <branch> <wt> [force] take the claim; rc 3 when another session holds it
|
|
35
|
+
# sreg_release <root> <issue> drop this session's own claim
|
|
36
|
+
# sreg_reap <root> drop every claim whose session is provably gone
|
|
37
|
+
# sreg_list <root> [--json] live claims; READ-ONLY, never reaps
|
|
38
|
+
#
|
|
39
|
+
# TSV row: <issue>\t<branch>\t<worktree>\t<pid>\t<host>\t<started-epoch>. No field is ever empty
|
|
40
|
+
# (`-` is the absent marker): tab is IFS whitespace, so an empty field would shift the rest.
|
|
41
|
+
#
|
|
42
|
+
# Requires: git, jq, ps. bash 3.2 compatible; runs under zsh (no glob held in a variable, no
|
|
43
|
+
# `status`/`path` variable names).
|
|
44
|
+
# errors: strict — a contested claim returns 3 and the caller must not start; an unwritable
|
|
45
|
+
# registry returns 1 and the caller decides whether to go on without a claim.
|
|
46
|
+
|
|
47
|
+
SREG_GRACE="${SREG_GRACE:-300}" # seconds a claim may name a worktree that does not exist yet
|
|
48
|
+
|
|
49
|
+
_sreg_now() { date +%s 2>/dev/null || echo 0; }
|
|
50
|
+
_sreg_host() { hostname 2>/dev/null || echo unknown; }
|
|
51
|
+
|
|
52
|
+
# _sreg_pstart <pid> — the process start time as ps prints it, or nothing. Compared verbatim, so it
|
|
53
|
+
# only has to be stable for one process on one host.
|
|
54
|
+
_sreg_pstart() { ps -o lstart= -p "$1" 2>/dev/null | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//'; }
|
|
55
|
+
|
|
56
|
+
sreg_dir() {
|
|
57
|
+
local common
|
|
58
|
+
common="$(git -C "${1:-.}" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 1
|
|
59
|
+
[ -n "$common" ] || return 1
|
|
60
|
+
printf '%s/kit-sessions' "$common"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_sreg_file() {
|
|
64
|
+
local d
|
|
65
|
+
[[ "${2:-}" =~ ^[1-9][0-9]*$ ]] || return 1
|
|
66
|
+
d="$(sreg_dir "$1")" || return 1
|
|
67
|
+
printf '%s/issue-%s.json' "$d" "$2"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# sreg_session_pid — the long-lived process this start belongs to.
|
|
71
|
+
# 1. KIT_SESSION_PID, when it is a pid — the explicit override (a harness that knows its own).
|
|
72
|
+
# 2. Walking up from this shell's parent: the first ancestor that is NOT a shell (the agent
|
|
73
|
+
# process), or a shell that is the terminal's own — a login shell (`-zsh`), or one whose
|
|
74
|
+
# parent does not share its controlling tty. Intermediate `sh -c` / script shells are skipped.
|
|
75
|
+
# 3. The last ancestor reached before pid 1, when nothing above matched.
|
|
76
|
+
sreg_session_pid() {
|
|
77
|
+
local cur="${PPID:-0}" comm base tty ptty parent hops=0
|
|
78
|
+
if [[ "${KIT_SESSION_PID:-}" =~ ^[1-9][0-9]*$ ]]; then printf '%s' "$KIT_SESSION_PID"; return 0; fi
|
|
79
|
+
[[ "$cur" =~ ^[1-9][0-9]*$ ]] || { printf '%s' "$$"; return 0; }
|
|
80
|
+
while [ "$hops" -lt 16 ]; do
|
|
81
|
+
hops=$((hops + 1))
|
|
82
|
+
comm="$(ps -o comm= -p "$cur" 2>/dev/null | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
|
83
|
+
[ -n "$comm" ] || break
|
|
84
|
+
parent="$(ps -o ppid= -p "$cur" 2>/dev/null | tr -d '[:space:]')"
|
|
85
|
+
case "$comm" in -*) break ;; esac
|
|
86
|
+
base="${comm##*/}"
|
|
87
|
+
case "$base" in
|
|
88
|
+
sh|bash|zsh|dash|ksh|fish|env|timeout|gtimeout|sudo|nohup|cckit|kit) ;;
|
|
89
|
+
*) break ;;
|
|
90
|
+
esac
|
|
91
|
+
[[ "$parent" =~ ^[0-9]+$ ]] && [ "$parent" -gt 1 ] || break
|
|
92
|
+
tty="$(ps -o tty= -p "$cur" 2>/dev/null | tr -d '[:space:]')"
|
|
93
|
+
ptty="$(ps -o tty= -p "$parent" 2>/dev/null | tr -d '[:space:]')"
|
|
94
|
+
case "$tty" in ''|'?'|'??') ;; *) [ "$tty" = "$ptty" ] || break ;; esac
|
|
95
|
+
cur="$parent"
|
|
96
|
+
done
|
|
97
|
+
printf '%s' "$cur"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# _sreg_row <file> — the claim as one TSV row plus a trailing <pstart> field, or rc 1 if unreadable.
|
|
101
|
+
_sreg_row() {
|
|
102
|
+
[ -f "$1" ] || return 1
|
|
103
|
+
jq -r '[(.issue // 0), (.branch // "" | if . == "" then "-" else . end),
|
|
104
|
+
(.worktree // "" | if . == "" then "-" else . end), (.pid // 0),
|
|
105
|
+
(.host // "" | if . == "" then "-" else . end), (.started // 0),
|
|
106
|
+
(.pstart // "" | if . == "" then "-" else . end)] | @tsv' "$1" 2>/dev/null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# _sreg_live <file> — rc 0 while the claim's session is not provably gone. Pure: deletes nothing.
|
|
110
|
+
_sreg_live() {
|
|
111
|
+
local row issue branch wt opid host started pstart now
|
|
112
|
+
row="$(_sreg_row "$1")" || return 1
|
|
113
|
+
[ -n "$row" ] || return 1
|
|
114
|
+
IFS=$'\t' read -r issue branch wt opid host started pstart <<EOF
|
|
115
|
+
$row
|
|
116
|
+
EOF
|
|
117
|
+
[[ "$issue" =~ ^[1-9][0-9]*$ ]] || return 1
|
|
118
|
+
if [ "$host" = "$(_sreg_host)" ]; then
|
|
119
|
+
[[ "$opid" =~ ^[1-9][0-9]*$ ]] || return 1
|
|
120
|
+
kill -0 "$opid" 2>/dev/null || return 1
|
|
121
|
+
if [ "$pstart" != "-" ] && [ "$(_sreg_pstart "$opid")" != "$pstart" ]; then return 1; fi
|
|
122
|
+
fi
|
|
123
|
+
if [ "$wt" != "-" ] && [ ! -d "$wt" ]; then
|
|
124
|
+
now="$(_sreg_now)"
|
|
125
|
+
[[ "$started" =~ ^[0-9]+$ ]] || started=0
|
|
126
|
+
[ $((now - started)) -le "$SREG_GRACE" ] || return 1
|
|
127
|
+
fi
|
|
128
|
+
return 0
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# _sreg_files <root> — every claim file, one absolute path per line.
|
|
132
|
+
_sreg_files() {
|
|
133
|
+
local d f
|
|
134
|
+
d="$(sreg_dir "$1")" || return 0
|
|
135
|
+
[ -d "$d" ] || return 0
|
|
136
|
+
ls "$d" 2>/dev/null | grep -E '^issue-[1-9][0-9]*\.json$' | while IFS= read -r f; do
|
|
137
|
+
printf '%s/%s\n' "$d" "$f"
|
|
138
|
+
done
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
# sreg_issue_claim <root> <issue> — print the live claim's TSV row (rc 0), or reap a dead one and
|
|
142
|
+
# return 1. This is the write-capable read wt_start uses; sreg_list is the read-only one.
|
|
143
|
+
sreg_issue_claim() {
|
|
144
|
+
local f row
|
|
145
|
+
f="$(_sreg_file "$1" "${2:-}")" || return 1
|
|
146
|
+
[ -f "$f" ] || return 1
|
|
147
|
+
if ! _sreg_live "$f"; then rm -f "$f" 2>/dev/null; return 1; fi
|
|
148
|
+
row="$(_sreg_row "$f")" || return 1
|
|
149
|
+
printf '%s\n' "${row% *}"
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# sreg_claim_mine <root> <issue> — the live claim belongs to this session: same host and session
|
|
153
|
+
# pid, or the caller is standing inside the claimed worktree (re-running start from the worktree
|
|
154
|
+
# the claim names is the claimant by construction, whatever shell it runs in).
|
|
155
|
+
sreg_claim_mine() {
|
|
156
|
+
local row issue branch wt opid host started here
|
|
157
|
+
row="$(sreg_issue_claim "$1" "${2:-}")" || return 1
|
|
158
|
+
IFS=$'\t' read -r issue branch wt opid host started <<EOF
|
|
159
|
+
$row
|
|
160
|
+
EOF
|
|
161
|
+
if [ "$host" = "$(_sreg_host)" ] && [ "$opid" = "$(sreg_session_pid)" ]; then return 0; fi
|
|
162
|
+
if [ "$wt" != "-" ] && [ -d "$wt" ]; then
|
|
163
|
+
here="$(pwd -P 2>/dev/null)"; wt="$(cd "$wt" 2>/dev/null && pwd -P)"
|
|
164
|
+
case "$here" in "$wt"|"$wt"/*) return 0 ;; esac
|
|
165
|
+
fi
|
|
166
|
+
return 1
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# sreg_claim <root> <issue> <branch> <worktree> [force] — take the claim for this session.
|
|
170
|
+
# rc 0 claimed (or already this session's — the existing record is left untouched)
|
|
171
|
+
# rc 3 another live session holds it and force is not 1 — nothing written
|
|
172
|
+
# rc 1 the registry could not be written
|
|
173
|
+
# The first writer wins by `ln`, which fails when the target exists — atomic without a lock.
|
|
174
|
+
sreg_claim() {
|
|
175
|
+
local root="$1" issue="${2:-}" branch="${3:-}" wt="${4:-}" force="${5:-0}" d f tmp spid
|
|
176
|
+
f="$(_sreg_file "$root" "$issue")" || return 1
|
|
177
|
+
d="${f%/*}"
|
|
178
|
+
mkdir -p "$d" 2>/dev/null || return 1
|
|
179
|
+
if sreg_issue_claim "$root" "$issue" >/dev/null; then
|
|
180
|
+
sreg_claim_mine "$root" "$issue" && return 0
|
|
181
|
+
[ "$force" = "1" ] || return 3
|
|
182
|
+
fi
|
|
183
|
+
spid="$(sreg_session_pid)"
|
|
184
|
+
tmp="$d/.issue-$issue.$$.tmp"
|
|
185
|
+
jq -n --argjson issue "$issue" --arg branch "$branch" --arg wt "$wt" --argjson pid "$spid" \
|
|
186
|
+
--arg pstart "$(_sreg_pstart "$spid")" --arg host "$(_sreg_host)" --argjson started "$(_sreg_now)" \
|
|
187
|
+
'{issue:$issue, branch:$branch, worktree:$wt, cwd:$wt, pid:$pid, pstart:$pstart, host:$host, started:$started}' \
|
|
188
|
+
> "$tmp" 2>/dev/null || { rm -f "$tmp" 2>/dev/null; return 1; }
|
|
189
|
+
if [ "$force" = "1" ]; then
|
|
190
|
+
mv -f "$tmp" "$f" 2>/dev/null || { rm -f "$tmp" 2>/dev/null; return 1; }
|
|
191
|
+
return 0
|
|
192
|
+
fi
|
|
193
|
+
if ln "$tmp" "$f" 2>/dev/null; then rm -f "$tmp" 2>/dev/null; return 0; fi
|
|
194
|
+
rm -f "$tmp" 2>/dev/null
|
|
195
|
+
# Lost the race to a claim written between the check and the link.
|
|
196
|
+
[ -f "$f" ] && return 3
|
|
197
|
+
return 1
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# sreg_release <root> <issue> — drop the claim, but only this session's own.
|
|
201
|
+
sreg_release() {
|
|
202
|
+
local f
|
|
203
|
+
f="$(_sreg_file "$1" "${2:-}")" || return 1
|
|
204
|
+
[ -f "$f" ] || return 0
|
|
205
|
+
sreg_claim_mine "$1" "$2" || return 1
|
|
206
|
+
rm -f "$f" 2>/dev/null
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
# sreg_reap <root> — drop every claim whose session is provably gone.
|
|
210
|
+
sreg_reap() {
|
|
211
|
+
local f
|
|
212
|
+
_sreg_files "$1" | while IFS= read -r f; do
|
|
213
|
+
_sreg_live "$f" || rm -f "$f" 2>/dev/null
|
|
214
|
+
done
|
|
215
|
+
return 0
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
# sreg_list <root> [--json] — the live claims. Read-only: a dead claim is skipped, never deleted.
|
|
219
|
+
# default: one TSV row per claim · --json: one JSON array of the claim records.
|
|
220
|
+
sreg_list() {
|
|
221
|
+
local root="${1:-.}" mode="${2:-}" f row
|
|
222
|
+
if [ "$mode" = "--json" ]; then
|
|
223
|
+
_sreg_files "$root" | while IFS= read -r f; do
|
|
224
|
+
_sreg_live "$f" && jq -c 'del(.pstart)' "$f" 2>/dev/null
|
|
225
|
+
done | jq -s -c 'sort_by(.issue)'
|
|
226
|
+
return 0
|
|
227
|
+
fi
|
|
228
|
+
_sreg_files "$root" | while IFS= read -r f; do
|
|
229
|
+
_sreg_live "$f" || continue
|
|
230
|
+
row="$(_sreg_row "$f")" || continue
|
|
231
|
+
printf '%s\n' "${row% *}"
|
|
232
|
+
done | sort -n
|
|
233
|
+
}
|
|
@@ -155,7 +155,20 @@ sr_cli 500 --stage deploy </dev/null >/dev/null 2>&1; t "an unknown stage is ref
|
|
|
155
155
|
sr_cli 500 </dev/null >/dev/null 2>&1; t "a missing --stage is refused" "$?" "2"
|
|
156
156
|
sr_cli abc --stage build </dev/null >/dev/null 2>&1; t "a non-numeric issue is refused" "$?" "2"
|
|
157
157
|
sr_cli 500 --stage build --nope x </dev/null >/dev/null 2>&1; t "an unknown flag is refused" "$?" "2"
|
|
158
|
-
|
|
158
|
+
printf 'outcome: pr-open\nurl: -\ngate: pass\nblocker: none\nnext stage: none\n' \
|
|
159
|
+
| sr_cli 501 --stage qa --no-remote >/dev/null 2>&1; t "qa is a stage a receipt can be recorded at" "$?" "0"
|
|
160
|
+
t "a qa receipt reads back by its stage" "$(sr_cli show 501 qa | jq -r '.stage')" "qa"
|
|
161
|
+
t "qa is a next stage a receipt may name" "$(sr_invalid_fields pr-open pass qa)" ""
|
|
162
|
+
# zsh aborts on a glob that matches nothing; the first receipt of a NEW stage for an issue is
|
|
163
|
+
# exactly that case once the receipts directory exists (#299 hit it recording a qa verdict).
|
|
164
|
+
if command -v zsh >/dev/null 2>&1; then
|
|
165
|
+
out="$(KIT_STATE_DIR="$KIT_STATE_DIR" zsh -c "source '$ROOT/scripts/lib/stage-receipt.sh'; sr_next_attempt 500 docs; sr_next_attempt 500 build; sr_list 777 | wc -l | tr -d ' '" 2>&1)"
|
|
166
|
+
t "zsh: attempts count with and without a matching receipt, and an empty list is empty" \
|
|
167
|
+
"$(printf '%s' "$out" | tr '\n' ' ')" "1 3 0"
|
|
168
|
+
else
|
|
169
|
+
echo "ok: zsh absent — skipping the zsh receipt pass (dependency-light gate)"
|
|
170
|
+
fi
|
|
171
|
+
yes "the verb help names the stages" "$(sr_cli --help 2>&1)" "build review design docs qa none"
|
|
159
172
|
|
|
160
173
|
# ── the receipts dir is shared, not per-worktree ───────────────────────────────────────────────
|
|
161
174
|
# kit_state_dir anchors a relative override to the repo's shared root, so standing somewhere else
|
|
@@ -44,7 +44,7 @@ command -v kit_state_dir >/dev/null 2>&1 || . "$_sr_dir/kit-state.sh"
|
|
|
44
44
|
# a value outside them is not a receipt with a typo — it is a routing decision nobody can make.
|
|
45
45
|
SR_OUTCOMES="merged pr-open closed-no-op blocked"
|
|
46
46
|
SR_GATES="pass fail"
|
|
47
|
-
SR_STAGES="build review design docs none"
|
|
47
|
+
SR_STAGES="build review design docs qa none"
|
|
48
48
|
|
|
49
49
|
_sr_need_jq() {
|
|
50
50
|
command -v jq >/dev/null 2>&1 || { echo "stage-receipt: jq is required to read and write receipts" >&2; return 3; }
|
|
@@ -76,12 +76,15 @@ sr_next_attempt() {
|
|
|
76
76
|
[ -n "$n" ] && [ -n "$stage" ] || { echo "sr_next_attempt: <issue> <stage> required" >&2; return 2; }
|
|
77
77
|
d="$(sr_dir)"
|
|
78
78
|
[ -d "$d" ] || { printf '1\n'; return 0; }
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
# Listed and filtered, not globbed: under zsh a glob that matches nothing is an ERROR (nomatch),
|
|
80
|
+
# so the first receipt of a stage in a directory that already held another stage's aborted.
|
|
81
|
+
while IFS= read -r f; do
|
|
82
|
+
[ -n "$f" ] || continue
|
|
81
83
|
a="${f##*-}"; a="${a%.json}"
|
|
82
|
-
case "$a" in ''|*[!0-9]*) continue ;; esac
|
|
83
84
|
[ "$a" -gt "$max" ] && max="$a"
|
|
84
|
-
done
|
|
85
|
+
done <<EOF
|
|
86
|
+
$(ls "$d" 2>/dev/null | grep -E "^$n-$stage-[0-9]+\.json\$")
|
|
87
|
+
EOF
|
|
85
88
|
printf '%s\n' "$(( max + 1 ))"
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -208,7 +211,9 @@ sr_list() {
|
|
|
208
211
|
_sr_need_jq || return $?
|
|
209
212
|
d="$(sr_dir)"
|
|
210
213
|
[ -d "$d" ] || return 0
|
|
211
|
-
for
|
|
214
|
+
# Listed and filtered for the same zsh reason as sr_next_attempt.
|
|
215
|
+
ls "$d" 2>/dev/null | grep -E "^${n:+$n-}.*\.json\$" | while IFS= read -r f; do
|
|
216
|
+
f="$d/$f"
|
|
212
217
|
[ -f "$f" ] || continue
|
|
213
218
|
jq -r '[(.issue|tostring), .stage, (.attempt|tostring),
|
|
214
219
|
(.outcome + (if ((.invalid // []) | length) > 0 then " (invalid: " + ((.invalid|join(","))) + ")" else "" end))]
|
|
@@ -262,7 +267,7 @@ cckit receipt <issue> --stage <stage> [--attempt <n>] [--profile <p>] [--tier <t
|
|
|
262
267
|
cckit receipt list [<issue>]
|
|
263
268
|
cckit receipt show <issue> <stage> [<attempt>]
|
|
264
269
|
|
|
265
|
-
Stages: build review design docs none
|
|
270
|
+
Stages: build review design docs qa none
|
|
266
271
|
Outcomes: merged pr-open closed-no-op blocked
|
|
267
272
|
|
|
268
273
|
The receipt is written locally AND mirrored as a comment on the issue. --no-remote (or
|
|
@@ -428,7 +433,7 @@ sr_mirror() {
|
|
|
428
433
|
|
|
429
434
|
ids="$(printf '%s\n' "$listing" | _sr_mirror_match_id "$marker")" || ids=""
|
|
430
435
|
if [ -n "$ids" ]; then
|
|
431
|
-
id="$(printf '%s\n' "$ids" |
|
|
436
|
+
id="$(printf '%s\n' "$ids" | sed -n 1p)"
|
|
432
437
|
if _sr_mirror_edit "$repo" "$id" "$body"; then
|
|
433
438
|
rm -f "$body"; SR_MIRROR_LAST_RESULT=updated; return 0
|
|
434
439
|
fi
|