@jeiemgi/cckit 0.8.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 +505 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +189 -20
- 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/guard-raw-git-ops-test.sh +8 -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 +188 -35
- package/scripts/lib/effort-ops-test.sh +217 -7
- package/scripts/lib/effort-ops.sh +281 -49
- 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-slug.sh +16 -2
- package/scripts/lib/effort.sh +67 -12
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +37 -16
- package/scripts/lib/gh-rest-test.sh +330 -0
- package/scripts/lib/gh-rest.sh +304 -0
- 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 +244 -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 +362 -89
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
- 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/test-env-test.sh +3 -3
- package/scripts/lib/test-env.sh +7 -4
- 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 +93 -9
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +169 -32
- 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 +27 -14
- 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,12 +17,13 @@
|
|
|
17
17
|
# kto_labels_role <labels-csv> echo the role slug from a labels CSV (role:<slug>)
|
|
18
18
|
# kto_labels_kind <labels-csv> echo the kind slug from a labels CSV (kind:<slug>)
|
|
19
19
|
# kto_compose_pr_body <num> <summary> <role-slug> echo a PR body from the template
|
|
20
|
+
# kto_pr_body_style echo content|code (pr.bodyStyle, #418)
|
|
20
21
|
# kto_compose_issue_body <user-body> <plan> <blocked> <role-slug> echo an issue body
|
|
21
22
|
# kto_closing_issue_numbers <pr-num> echo the issue #s a merged PR closes
|
|
22
|
-
# kto_task_pr <num> <summary> [commit-msg]
|
|
23
|
-
# kto_task_pr_merge [pr-num]
|
|
23
|
+
# kto_task_pr <num> <summary> [commit-msg] [--base <branch>] commit+push+open PR (board → In Review)
|
|
24
|
+
# kto_task_pr_merge [pr-num] [--squash|--merge|--rebase] merge (squash default) + close issues + GC + update the PR base; refuses an effort/* head
|
|
24
25
|
# kto_task_new <title> <role> <kind> <prio> [ms] [plan] [blocked] <body> create issue + board fields (ms may be empty)
|
|
25
|
-
# kto_task_close <num> <summary> [pr-num]
|
|
26
|
+
# kto_task_close <num> <summary> [pr-num] [--reason R] [--duplicate-of N] [--superseded-by N] close + reason + board → Done
|
|
26
27
|
# errors: mixed — git/gh ops propagate; board + label side effects are best-effort
|
|
27
28
|
|
|
28
29
|
# --- repo resolution -----------------------------------------------------------------------------
|
|
@@ -37,19 +38,48 @@ if [[ -z "${KIT_REPO:-}" ]]; then
|
|
|
37
38
|
unset _kto_root
|
|
38
39
|
fi
|
|
39
40
|
|
|
41
|
+
# The GitHub transport switch (#396): in rest mode every gh call below is `gh api repos/…`.
|
|
42
|
+
if ! type cckit_gh_rest >/dev/null 2>&1; then
|
|
43
|
+
if [ -n "${BASH_SOURCE:-}" ]; then _kto_self="${BASH_SOURCE[0]}"
|
|
44
|
+
elif [ -n "${ZSH_VERSION:-}" ]; then eval '_kto_self="${(%):-%x}"'
|
|
45
|
+
else _kto_self="$0"; fi
|
|
46
|
+
_kto_self="$(cd "$(dirname "$_kto_self")" 2>/dev/null && pwd)/gh-rest.sh"
|
|
47
|
+
# shellcheck source=gh-rest.sh
|
|
48
|
+
[ -f "$_kto_self" ] && . "$_kto_self"
|
|
49
|
+
unset _kto_self
|
|
50
|
+
fi
|
|
51
|
+
type cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
|
|
52
|
+
|
|
53
|
+
# The kind vocabulary (kinds.sh): kto_pr_title takes the commit type from kit_kind_commit_type.
|
|
54
|
+
if ! type kit_kind_commit_type >/dev/null 2>&1; then
|
|
55
|
+
if [ -n "${BASH_SOURCE:-}" ]; then _kto_self="${BASH_SOURCE[0]}"
|
|
56
|
+
elif [ -n "${ZSH_VERSION:-}" ]; then eval '_kto_self="${(%):-%x}"'
|
|
57
|
+
else _kto_self="$0"; fi
|
|
58
|
+
_kto_self="$(cd "$(dirname "$_kto_self")" 2>/dev/null && pwd)/kinds.sh"
|
|
59
|
+
# shellcheck source=kinds.sh
|
|
60
|
+
[ -f "$_kto_self" ] && . "$_kto_self"
|
|
61
|
+
unset _kto_self
|
|
62
|
+
fi
|
|
63
|
+
type cckit_board_skipped >/dev/null 2>&1 || cckit_board_skipped() { return 1; }
|
|
64
|
+
|
|
40
65
|
kto_repo() {
|
|
41
66
|
printf '%s' "${KIT_TASK_REPO:-${KIT_REPO:-}}"
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
# The base branch a PR targets / pr-merge returns to (portable: KIT_BASE_BRANCH, default develop).
|
|
70
|
+
# Args: [override] — a non-empty override wins over the configured base (#391: `cckit pr --base`).
|
|
45
71
|
kto_base_branch() {
|
|
72
|
+
if [[ -n "${1:-}" ]]; then printf '%s' "$1"; return 0; fi
|
|
46
73
|
printf '%s' "${KIT_BASE_BRANCH:-main}"
|
|
47
74
|
}
|
|
48
75
|
|
|
49
76
|
# True (rc 0) iff board updates should run. Off when KIT_PROJECTS_V2 is explicitly "false" — keeps
|
|
50
77
|
# the op portable to a project with no Projects v2 board (the plugin's KIT_PROJECTS_V2 toggle).
|
|
78
|
+
# In rest mode (#396) the board is GraphQL-only: skipped with one notice, never a failure.
|
|
51
79
|
kto_board_enabled() {
|
|
52
|
-
[[ "${KIT_PROJECTS_V2:-true}" != "false" ]]
|
|
80
|
+
[[ "${KIT_PROJECTS_V2:-true}" != "false" ]] || return 1
|
|
81
|
+
cckit_board_skipped && return 1
|
|
82
|
+
return 0
|
|
53
83
|
}
|
|
54
84
|
|
|
55
85
|
# --- pure parsers (network-free; covered by the self-test) ---------------------------------------
|
|
@@ -57,17 +87,17 @@ kto_board_enabled() {
|
|
|
57
87
|
# Parse the issue number from a `<kind>/<N>-<slug>` branch (e.g. feat/173-x -> 173). Empty if none.
|
|
58
88
|
kto_branch_issue_number() {
|
|
59
89
|
local branch="${1:-$(git rev-parse --abbrev-ref HEAD 2>/dev/null)}"
|
|
60
|
-
printf '%s' "$branch" | grep -oE '/[0-9]+-' |
|
|
90
|
+
printf '%s' "$branch" | grep -oE '/[0-9]+-' | sed -n 1p | tr -d '/-'
|
|
61
91
|
}
|
|
62
92
|
|
|
63
93
|
# Echo the role slug from a comma-separated labels list (role:<slug>). Empty if absent.
|
|
64
94
|
kto_labels_role() {
|
|
65
|
-
printf '%s' "$1" | tr ',' '\n' | grep '^role:' |
|
|
95
|
+
printf '%s' "$1" | tr ',' '\n' | grep '^role:' | sed -n 1p | cut -d: -f2
|
|
66
96
|
}
|
|
67
97
|
|
|
68
98
|
# Echo the kind slug from a comma-separated labels list (kind:<slug>). Empty if absent.
|
|
69
99
|
kto_labels_kind() {
|
|
70
|
-
printf '%s' "$1" | tr ',' '\n' | grep '^kind:' |
|
|
100
|
+
printf '%s' "$1" | tr ',' '\n' | grep '^kind:' | sed -n 1p | cut -d: -f2
|
|
71
101
|
}
|
|
72
102
|
|
|
73
103
|
# Compose the PR title as a Conventional Commit subject. Because PRs are squash-merged, this title
|
|
@@ -98,17 +128,18 @@ kto_pr_title() {
|
|
|
98
128
|
fi
|
|
99
129
|
# 2) Derive the type from the kind:/bug label.
|
|
100
130
|
kind="$(kto_labels_kind "$labels")"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
131
|
+
# The kind -> type map is kinds.sh's (kit_kind_commit_type): a content kind (post, campaign,
|
|
132
|
+
# brand, research) titles as `docs`, kind:task and anything unknown as `feat`.
|
|
133
|
+
if command -v kit_kind_commit_type >/dev/null 2>&1; then
|
|
134
|
+
ctype="$(kit_kind_commit_type "$kind")"
|
|
135
|
+
else
|
|
136
|
+
case "$kind" in
|
|
137
|
+
feat|chore|docs|ci|test|perf|refactor) ctype="$kind" ;;
|
|
138
|
+
fix|bug) ctype=fix ;;
|
|
139
|
+
post|campaign|brand|research) ctype=docs ;;
|
|
140
|
+
*) ctype=feat ;;
|
|
141
|
+
esac
|
|
142
|
+
fi
|
|
112
143
|
case ",$labels," in *,bug,*) ctype=fix ;; esac # a plain `bug` label → fix
|
|
113
144
|
# 3) Strip "[Effort N] M · " (the "· " consumed here as a literal — byte-wise match is portable
|
|
114
145
|
# across BSD/GNU sed + locales; a negated class over the multibyte middot is not) and then a
|
|
@@ -121,14 +152,67 @@ kto_pr_title() {
|
|
|
121
152
|
printf '%s: %s' "$ctype" "$desc"
|
|
122
153
|
}
|
|
123
154
|
|
|
155
|
+
# kto_pr_body_style — `content` or `code`: which wording a generated PR body uses (#418).
|
|
156
|
+
# pr.bodyStyle in the config (KIT_PR_BODY_STYLE); anything but `content` is `code`. The content and
|
|
157
|
+
# marketing profiles set `content`. Shared by `cckit pr`, `cckit effort pr` and `cckit task finish`.
|
|
158
|
+
kto_pr_body_style() {
|
|
159
|
+
if [ "${KIT_PR_BODY_STYLE:-code}" = "content" ]; then printf 'content'; else printf 'code'; fi
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
# kto_content_review_checklist — the review checklist of a content-style PR body, one item per
|
|
163
|
+
# line. The same four lines in every body the kit writes for content work.
|
|
164
|
+
kto_content_review_checklist() {
|
|
165
|
+
printf '%s\n' \
|
|
166
|
+
'- [ ] Read the draft from start to finish' \
|
|
167
|
+
'- [ ] Facts, names, numbers and links are checked' \
|
|
168
|
+
'- [ ] The voice matches the brand guide' \
|
|
169
|
+
'- [ ] Only the files for this piece changed'
|
|
170
|
+
}
|
|
171
|
+
|
|
124
172
|
# Compose a PR body from the kit-task-pr template. Args: <num> <summary> <role-slug> [issue-title]
|
|
125
173
|
# pr.orchestratorSection = true (KIT_PR_ORCHESTRATOR_SECTION) prepends a 2-line
|
|
126
174
|
# `## For the orchestrator` section: the issue id + title, then what to review.
|
|
175
|
+
# pr.bodyStyle = content swaps the code wording (diff, reproduced manually) for draft-and-review
|
|
176
|
+
# wording; `Closes #N`, the summary and the signature are the same in both.
|
|
127
177
|
kto_compose_pr_body() {
|
|
128
|
-
local num="$1" summary="$2" role="$3" title="${4:-}" sig=""
|
|
178
|
+
local num="$1" summary="$2" role="$3" title="${4:-}" sig="" style
|
|
179
|
+
style="$(kto_pr_body_style)"
|
|
129
180
|
if type role_signature >/dev/null 2>&1; then sig="$(role_signature "$role")"; fi
|
|
130
181
|
if [ "${KIT_PR_ORCHESTRATOR_SECTION:-false}" = "true" ]; then
|
|
131
|
-
|
|
182
|
+
if [ "$style" = "content" ]; then
|
|
183
|
+
printf '## For the orchestrator\n\n#%s%s\nReview: the summary below and the changed files.\n\n' "$num" "${title:+ · $title}"
|
|
184
|
+
else
|
|
185
|
+
printf '## For the orchestrator\n\n#%s%s\nReview: the summary below and the diff.\n\n' "$num" "${title:+ · $title}"
|
|
186
|
+
fi
|
|
187
|
+
fi
|
|
188
|
+
if [ "$style" = "content" ]; then
|
|
189
|
+
cat <<EOF
|
|
190
|
+
## Closes
|
|
191
|
+
|
|
192
|
+
Closes #$num
|
|
193
|
+
|
|
194
|
+
## Summary
|
|
195
|
+
|
|
196
|
+
$summary
|
|
197
|
+
|
|
198
|
+
## Review
|
|
199
|
+
|
|
200
|
+
$(kto_content_review_checklist)
|
|
201
|
+
|
|
202
|
+
## Notes for the reviewer
|
|
203
|
+
|
|
204
|
+
—
|
|
205
|
+
|
|
206
|
+
## Not in this piece
|
|
207
|
+
|
|
208
|
+
—
|
|
209
|
+
|
|
210
|
+
$sig
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
<sub>· \`claude-kit\` · kit-task-pr</sub>
|
|
214
|
+
EOF
|
|
215
|
+
return 0
|
|
132
216
|
fi
|
|
133
217
|
cat <<EOF
|
|
134
218
|
## Closes
|
|
@@ -178,6 +262,7 @@ kto_compose_issue_body() {
|
|
|
178
262
|
kto_closing_issue_numbers() {
|
|
179
263
|
local pr="$1" repo issues body
|
|
180
264
|
repo="$(kto_repo)"
|
|
265
|
+
if cckit_gh_rest; then gh_rest_pr_closing_issues "$repo" "$pr"; return 0; fi
|
|
181
266
|
issues=$(gh pr view "$pr" --repo "$repo" --json closingIssuesReferences \
|
|
182
267
|
--jq '.closingIssuesReferences[].number' 2>/dev/null)
|
|
183
268
|
if [[ -z "$issues" ]]; then
|
|
@@ -192,21 +277,50 @@ kto_closing_issue_numbers() {
|
|
|
192
277
|
# --- the four ops (network; not exercised by the self-test) --------------------------------------
|
|
193
278
|
|
|
194
279
|
# Map a role slug to the board's Role single-select option id (uses gh-project's role_option_id,
|
|
195
|
-
# which takes a display name — translate slug -> display via role_display).
|
|
280
|
+
# which takes a display name — translate slug -> display via role_display). A slug role_display
|
|
281
|
+
# does not list is passed as-is (#378): role_option_id normalizes it to the same ROLE_OPT_<NAME>.
|
|
196
282
|
_kto_role_option_for_slug() {
|
|
197
283
|
local slug="$1" disp=""
|
|
284
|
+
[[ -z "$slug" ]] && return 0
|
|
198
285
|
if type role_display >/dev/null 2>&1; then disp="$(role_display "$slug")"; fi
|
|
199
|
-
[[ -z "$disp" ]] &&
|
|
286
|
+
[[ -z "$disp" ]] && disp="$slug"
|
|
200
287
|
if type role_option_id >/dev/null 2>&1; then role_option_id "$disp"; fi
|
|
201
288
|
}
|
|
202
289
|
|
|
203
290
|
# kit task pr — commit current changes (role identity in a Co-authored-by TRAILER, never the
|
|
204
291
|
# author field — Vercel rejects unknown author emails), push, open the PR with the issue's
|
|
205
292
|
# labels/milestone, add it to the board In Review, and move the issue to In Review.
|
|
206
|
-
# Args: <issue-num> <summary> [commit-msg]
|
|
293
|
+
# Args: <issue-num> <summary> [commit-msg] [--base <branch>]
|
|
294
|
+
#
|
|
295
|
+
# --base (#391) targets a branch other than the configured base — a release PR develop -> main.
|
|
296
|
+
# load_kit_config re-exports KIT_BASE_BRANCH from the config, so an env override cannot do this.
|
|
297
|
+
# The flag is parsed out before the positionals are read, anywhere on the line, and a missing value
|
|
298
|
+
# returns 2 before the commit and the push. The target is exported to the push as KIT_PR_BASE (set
|
|
299
|
+
# with or without the flag), so a project's git pre-push hook can compare against the branch the PR
|
|
300
|
+
# targets (#360).
|
|
207
301
|
kto_task_pr() {
|
|
208
302
|
# Default-safe reads: callers (scripts/kit) may run under `set -u`.
|
|
209
|
-
local num="
|
|
303
|
+
local num="" summary="" commit_msg="" base_override="" _pos=0
|
|
304
|
+
while [ "$#" -gt 0 ]; do
|
|
305
|
+
case "$1" in
|
|
306
|
+
--base)
|
|
307
|
+
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
|
|
308
|
+
echo "✗ kto_task_pr: --base needs a branch — usage: cckit pr <issue> \"<summary>\" [--base <branch>]" >&2; return 2
|
|
309
|
+
fi
|
|
310
|
+
base_override="$2"; shift 2 ;;
|
|
311
|
+
--base=*)
|
|
312
|
+
base_override="${1#--base=}"
|
|
313
|
+
if [ -z "$base_override" ]; then
|
|
314
|
+
echo "✗ kto_task_pr: --base needs a branch — usage: cckit pr <issue> \"<summary>\" [--base <branch>]" >&2; return 2
|
|
315
|
+
fi
|
|
316
|
+
shift ;;
|
|
317
|
+
*)
|
|
318
|
+
_pos=$((_pos + 1))
|
|
319
|
+
case "$_pos" in 1) num="$1" ;; 2) summary="$1" ;; 3) commit_msg="$1" ;; esac
|
|
320
|
+
shift ;;
|
|
321
|
+
esac
|
|
322
|
+
done
|
|
323
|
+
local base; base="$(kto_base_branch "$base_override")"
|
|
210
324
|
local repo branch meta title labels milestone role author="" url pr_num pr_node item role_opt issue_item
|
|
211
325
|
repo="$(kto_repo)"
|
|
212
326
|
branch="$(git rev-parse --abbrev-ref HEAD)"
|
|
@@ -215,7 +329,8 @@ kto_task_pr() {
|
|
|
215
329
|
[[ -n "$num" ]] || { echo "✗ kto_task_pr: branch '$branch' doesn't match <kind>/<N>-<slug> and no issue number passed" >&2; return 1; }
|
|
216
330
|
[[ -n "$summary" ]] || { echo "✗ kto_task_pr: a Summary is required (never invent one)" >&2; return 1; }
|
|
217
331
|
|
|
218
|
-
meta=$(
|
|
332
|
+
if cckit_gh_rest; then meta=$(gh_rest_issue_json "$repo" "$num") || return 1
|
|
333
|
+
else meta=$(gh issue view "$num" --repo "$repo" --json title,labels,milestone) || return 1; fi
|
|
219
334
|
title=$(printf '%s' "$meta" | jq -r .title)
|
|
220
335
|
labels=$(printf '%s' "$meta" | jq -r '[.labels[].name] | join(",")')
|
|
221
336
|
milestone=$(printf '%s' "$meta" | jq -r '.milestone.title // ""')
|
|
@@ -240,15 +355,20 @@ kto_task_pr() {
|
|
|
240
355
|
fi
|
|
241
356
|
fi
|
|
242
357
|
|
|
243
|
-
git push -u origin "$branch" || return 1
|
|
358
|
+
KIT_PR_BASE="$base" git push -u origin "$branch" || return 1
|
|
244
359
|
|
|
360
|
+
if cckit_gh_rest; then
|
|
361
|
+
url=$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" \
|
|
362
|
+
"$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" "$labels" "$milestone") || return 1
|
|
363
|
+
else
|
|
245
364
|
url=$(gh pr create --repo "$repo" \
|
|
246
|
-
--base "$
|
|
365
|
+
--base "$base" --head "$branch" \
|
|
247
366
|
--title "$pr_title" \
|
|
248
367
|
--body "$(kto_compose_pr_body "$num" "$summary" "$role" "$title")" \
|
|
249
368
|
--label "$labels" \
|
|
250
369
|
${milestone:+--milestone "$milestone"} \
|
|
251
370
|
--assignee "@me") || return 1
|
|
371
|
+
fi
|
|
252
372
|
echo "✓ $url"
|
|
253
373
|
|
|
254
374
|
# Board: add the PR (In Review) + move the issue to In Review. Best-effort — never fail the op.
|
|
@@ -269,13 +389,32 @@ kto_task_pr() {
|
|
|
269
389
|
fi
|
|
270
390
|
}
|
|
271
391
|
|
|
272
|
-
# kit task pr-merge —
|
|
273
|
-
#
|
|
274
|
-
#
|
|
275
|
-
# Args: [pr-num] (defaults to the open PR for the current branch)
|
|
392
|
+
# kit task pr-merge — merge a PR (squash by default; --merge or --rebase), rebase-fix conflicts onto
|
|
393
|
+
# the PR's base first, close its linked issues (GitHub native auto-close only fires on the default
|
|
394
|
+
# branch), then clean up the PR's head branch + worktree and bring the PR's base up to date.
|
|
395
|
+
# Args: [<pr-num>] [--squash|--merge|--rebase] (the PR defaults to the open PR for the current branch)
|
|
396
|
+
#
|
|
397
|
+
# The PR's base and head come from GitHub, never from the current checkout (#376): the base may be an
|
|
398
|
+
# effort/<N> branch, and a sub PR merged from the effort worktree must not GC the effort branch.
|
|
276
399
|
kto_task_pr_merge() {
|
|
277
|
-
local input_pr="
|
|
278
|
-
|
|
400
|
+
local input_pr="" method="squash" a
|
|
401
|
+
for a in "$@"; do
|
|
402
|
+
case "$a" in
|
|
403
|
+
--squash) method="squash" ;;
|
|
404
|
+
--merge) method="merge" ;;
|
|
405
|
+
--rebase) method="rebase" ;;
|
|
406
|
+
-*) echo "✗ kto_task_pr_merge: unknown flag '$a' — usage: cckit merge [<pr>] [--squash|--merge|--rebase]" >&2; return 2 ;;
|
|
407
|
+
*)
|
|
408
|
+
# Refuse anything but a PR number (#366). `gh pr merge --help` exits 0, so a flag taken as
|
|
409
|
+
# the number used to "merge", then run the cleanup on the base branch.
|
|
410
|
+
if [[ -n "$input_pr" || ! "$a" =~ ^#?[0-9]+$ ]]; then
|
|
411
|
+
echo "✗ kto_task_pr_merge: '$a' is not a PR number — usage: cckit merge [<pr>] [--squash|--merge|--rebase]" >&2; return 2
|
|
412
|
+
fi
|
|
413
|
+
input_pr="${a#\#}" ;;
|
|
414
|
+
esac
|
|
415
|
+
done
|
|
416
|
+
|
|
417
|
+
local repo branch base pr_num meta merge_state pr_base head issues n state wt main_wt base_wt common effort_n
|
|
279
418
|
repo="$(kto_repo)"
|
|
280
419
|
base="$(kto_base_branch)"
|
|
281
420
|
branch="$(git rev-parse --abbrev-ref HEAD)"
|
|
@@ -284,91 +423,162 @@ kto_task_pr_merge() {
|
|
|
284
423
|
echo "✗ Working tree is dirty — commit or stash changes first" >&2; return 1
|
|
285
424
|
fi
|
|
286
425
|
|
|
287
|
-
|
|
288
|
-
# used to "merge", then run the cleanup below on the base branch (#366).
|
|
289
|
-
if [[ -n "$input_pr" && ! "$input_pr" =~ ^#?[0-9]+$ ]]; then
|
|
290
|
-
echo "✗ kto_task_pr_merge: '$input_pr' is not a PR number — usage: cckit merge [<pr>]" >&2; return 2
|
|
291
|
-
fi
|
|
292
|
-
pr_num="${input_pr#\#}"
|
|
426
|
+
pr_num="$input_pr"
|
|
293
427
|
if [[ -z "$pr_num" ]]; then
|
|
294
|
-
pr_num=$(
|
|
428
|
+
if cckit_gh_rest; then pr_num=$(gh_rest_pr_for_head "$repo" "$branch")
|
|
429
|
+
else pr_num=$(gh pr list --repo "$repo" --head "$branch" --state open --json number --jq '.[0].number // empty'); fi
|
|
295
430
|
[[ -z "$pr_num" ]] && { echo "✗ No open PR found for branch $branch" >&2; return 1; }
|
|
296
431
|
fi
|
|
297
|
-
echo "→ PR #$pr_num on branch $branch"
|
|
298
432
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
merge_state=$(printf '%s' "$
|
|
302
|
-
|
|
433
|
+
if cckit_gh_rest; then meta=$(gh_rest_pr_json "$repo" "$pr_num") || return 1
|
|
434
|
+
else meta=$(gh pr view "$pr_num" --repo "$repo" --json mergeable,mergeStateStatus,baseRefName,headRefName) || return 1; fi
|
|
435
|
+
merge_state=$(printf '%s' "$meta" | jq -r '.mergeable // ""')
|
|
436
|
+
pr_base=$(printf '%s' "$meta" | jq -r '.baseRefName // empty'); pr_base="${pr_base:-$base}"
|
|
437
|
+
head=$(printf '%s' "$meta" | jq -r '.headRefName // empty'); head="${head:-$branch}"
|
|
438
|
+
echo "→ PR #$pr_num: $head → $pr_base ($method)"
|
|
439
|
+
echo " mergeable=$merge_state status=$(printf '%s' "$meta" | jq -r '.mergeStateStatus // ""')"
|
|
440
|
+
|
|
441
|
+
# An effort's PR merges with `cckit effort close` (#379): that op snapshots each sub-issue's diff
|
|
442
|
+
# before the squash destroys the per-sub commits. Refused before the rebase and the merge, so a
|
|
443
|
+
# refusal writes nothing. KIT_FORCE=1 merges anyway.
|
|
444
|
+
if [[ "$head" == effort/* ]]; then
|
|
445
|
+
effort_n="${head#effort/}"; effort_n="${effort_n%%-*}"
|
|
446
|
+
if [[ "${KIT_FORCE:-0}" == "1" ]]; then
|
|
447
|
+
echo "⚠ KIT_FORCE=1: merging effort branch $head with cckit merge — no per-sub trace snapshot is taken (cckit effort close $effort_n takes it)" >&2
|
|
448
|
+
else
|
|
449
|
+
echo "✗ PR #$pr_num is an effort branch ($head) — merge it with: cckit effort close $effort_n" >&2
|
|
450
|
+
echo " cckit merge would skip the per-sub trace snapshot effort close takes before the squash. KIT_FORCE=1 merges anyway." >&2
|
|
451
|
+
return 1
|
|
452
|
+
fi
|
|
453
|
+
fi
|
|
454
|
+
|
|
455
|
+
# Branches that are never rebased, force-pushed or deleted here: the repo base, the PR's base
|
|
456
|
+
# (it may be an effort branch), and the release branches (#366).
|
|
457
|
+
_kto_protected() { case "$1" in "$base"|"$pr_base"|main|master|develop|HEAD) return 0 ;; esac; return 1; }
|
|
303
458
|
|
|
304
459
|
if [[ "$merge_state" == "CONFLICTING" ]]; then
|
|
305
|
-
|
|
306
|
-
echo "✗ PR #$pr_num conflicts — rebase
|
|
307
|
-
|
|
308
|
-
echo "→ Conflicts detected — rebasing onto $
|
|
309
|
-
git fetch origin "$
|
|
310
|
-
if git rebase "origin/$
|
|
311
|
-
git push --force-with-lease origin "$
|
|
460
|
+
if [[ "$branch" != "$head" ]] || _kto_protected "$branch"; then
|
|
461
|
+
echo "✗ PR #$pr_num conflicts — rebase $head onto $pr_base from its own worktree (not from $branch)" >&2; return 1
|
|
462
|
+
fi
|
|
463
|
+
echo "→ Conflicts detected — rebasing onto $pr_base..."
|
|
464
|
+
git fetch origin "$pr_base"
|
|
465
|
+
if git rebase "origin/$pr_base"; then
|
|
466
|
+
git push --force-with-lease origin "$head"
|
|
312
467
|
echo "✓ Rebased and pushed — re-checking mergeability..."
|
|
313
468
|
else
|
|
314
|
-
echo "✗ Rebase had conflicts that need manual resolution — resolve, then run
|
|
469
|
+
echo "✗ Rebase had conflicts that need manual resolution — resolve, then run cckit merge again" >&2
|
|
315
470
|
git rebase --abort 2>/dev/null || true
|
|
316
471
|
return 1
|
|
317
472
|
fi
|
|
318
473
|
fi
|
|
319
474
|
|
|
320
|
-
if
|
|
475
|
+
if cckit_gh_rest; then
|
|
476
|
+
if ! gh_rest_pr_merge "$repo" "$pr_num" "$method" 2>&1; then
|
|
477
|
+
echo "✗ Merge failed — check PR status: https://github.com/$repo/pull/$pr_num" >&2
|
|
478
|
+
return 1
|
|
479
|
+
fi
|
|
480
|
+
elif ! gh pr merge "$pr_num" --repo "$repo" "--$method" 2>&1; then
|
|
321
481
|
echo "✗ Merge failed — check PR status: https://github.com/$repo/pull/$pr_num" >&2
|
|
322
482
|
return 1
|
|
323
483
|
fi
|
|
324
|
-
echo "✓ PR #$pr_num merged"
|
|
484
|
+
echo "✓ PR #$pr_num merged ($method)"
|
|
325
485
|
|
|
326
486
|
# Close linked issues (replaces issue-close-on-merge.yml; native auto-close only fires on main).
|
|
327
487
|
issues="$(kto_closing_issue_numbers "$pr_num")"
|
|
328
|
-
for n in $issues
|
|
329
|
-
|
|
330
|
-
|
|
488
|
+
# Read line by line on fd 3, not `for n in $issues` (#379): word-splitting follows the caller's
|
|
489
|
+
# IFS, and a NUL-polluted IFS passed "1020\n1021" to gh as one issue number.
|
|
490
|
+
while IFS= read -r n <&3; do
|
|
491
|
+
[[ "$n" =~ ^[0-9]+$ ]] || continue
|
|
492
|
+
if cckit_gh_rest; then state=$(gh_rest_issue_state "$repo" "$n" 2>/dev/null)
|
|
493
|
+
else state=$(gh issue view "$n" --repo "$repo" --json state --jq .state 2>/dev/null); fi
|
|
494
|
+
if [[ "$state" == "OPEN" ]] && cckit_gh_rest; then
|
|
495
|
+
gh_rest_issue_close "$repo" "$n" completed \
|
|
496
|
+
"Closed automatically on merge of #$pr_num to $pr_base (cckit merge; GitHub native auto-close only fires on the default branch)." \
|
|
497
|
+
&& echo "✓ Closed issue #$n"
|
|
498
|
+
elif [[ "$state" == "OPEN" ]]; then
|
|
331
499
|
gh issue close "$n" --repo "$repo" \
|
|
332
|
-
--comment "Closed automatically on merge of #$pr_num to $
|
|
500
|
+
--comment "Closed automatically on merge of #$pr_num to $pr_base (cckit merge; GitHub native auto-close only fires on the default branch)." \
|
|
333
501
|
&& echo "✓ Closed issue #$n"
|
|
334
502
|
elif [[ -n "$state" ]]; then
|
|
335
503
|
echo " issue #$n already $state — skipped"
|
|
336
504
|
fi
|
|
337
|
-
done
|
|
505
|
+
done 3<<EOF
|
|
506
|
+
$issues
|
|
507
|
+
EOF
|
|
338
508
|
|
|
339
|
-
#
|
|
340
|
-
#
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
local common
|
|
344
|
-
wt=$(git worktree list --porcelain | awk -v b="refs/heads/$branch" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
|
|
509
|
+
# Clean up FROM the main checkout (#371): run from the PR's own worktree, removing it deletes our
|
|
510
|
+
# cwd. Main checkout = parent of the shared git dir; fall back to the first `worktree list` entry.
|
|
511
|
+
wt=$(git worktree list --porcelain | awk -v b="refs/heads/$head" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
|
|
512
|
+
base_wt=$(git worktree list --porcelain | awk -v b="refs/heads/$pr_base" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
|
|
345
513
|
common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
|
|
346
514
|
main_wt=""
|
|
347
515
|
[[ -n "$common" && "$(basename "$common")" == ".git" ]] && main_wt="$(dirname "$common")"
|
|
348
|
-
[[ -n "$main_wt" ]] || main_wt=$(git worktree list --porcelain | awk '/^worktree /{print $2;
|
|
516
|
+
[[ -n "$main_wt" ]] || main_wt=$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')
|
|
349
517
|
cd "$main_wt" || { echo "✗ cannot reach the main checkout $main_wt for cleanup" >&2; return 1; }
|
|
350
|
-
git -C "$main_wt" checkout "$base" 2>/dev/null || true
|
|
351
|
-
git -C "$main_wt" pull origin "$base" 2>/dev/null || true
|
|
352
518
|
|
|
353
|
-
if [[ -n "$wt" && "$wt" != "$main_wt" ]]; then
|
|
519
|
+
if [[ -n "$wt" && "$wt" != "$main_wt" ]] && ! _kto_protected "$head"; then
|
|
354
520
|
git -C "$main_wt" worktree remove "$wt" --force && echo "✓ Removed worktree $wt"
|
|
355
521
|
fi
|
|
356
|
-
# Never delete the base (or a release) branch: merging a PR from the hub leaves $branch = base.
|
|
357
522
|
# -D, not -d: a squash merge leaves the branch "not fully merged" by ancestry.
|
|
358
|
-
|
|
359
|
-
"$
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
523
|
+
if _kto_protected "$head"; then
|
|
524
|
+
echo " ($head is protected — no branch cleanup)"
|
|
525
|
+
else
|
|
526
|
+
git -C "$main_wt" branch -D "$head" 2>/dev/null && echo "✓ Deleted local branch $head"
|
|
527
|
+
if cckit_gh_rest; then
|
|
528
|
+
# The cloud proxy rejects branch deletion (#396): keep it and say so.
|
|
529
|
+
echo " (remote branch $head kept — branch deletion is unavailable here; delete it on GitHub)"
|
|
530
|
+
else
|
|
531
|
+
git -C "$main_wt" push origin --delete "$head" 2>/dev/null && echo "✓ Deleted remote branch $head" || echo " (remote branch already gone)"
|
|
532
|
+
fi
|
|
533
|
+
fi
|
|
365
534
|
git -C "$main_wt" worktree prune
|
|
366
|
-
|
|
535
|
+
|
|
536
|
+
# Bring the PR's base up to date where it lives. The repo base: the main checkout switches to it and
|
|
537
|
+
# pulls. An effort/<N> base is checked out in its own worktree (git allows one checkout per branch),
|
|
538
|
+
# so that worktree fast-forwards; with no worktree, the local ref is fast-forwarded by fetch.
|
|
539
|
+
if [[ "$pr_base" == "$base" ]]; then
|
|
540
|
+
git -C "$main_wt" checkout "$pr_base" 2>/dev/null || true
|
|
541
|
+
git -C "$main_wt" pull --ff-only origin "$pr_base" 2>/dev/null || true
|
|
542
|
+
echo "✓ On $pr_base in $main_wt, up to date — merged branch + worktree cleaned"
|
|
543
|
+
elif [[ -n "$base_wt" ]]; then
|
|
544
|
+
git -C "$base_wt" pull --ff-only origin "$pr_base" 2>/dev/null || true
|
|
545
|
+
echo "✓ $pr_base updated in $base_wt — continue there (merged branch + worktree cleaned)"
|
|
546
|
+
else
|
|
547
|
+
git -C "$main_wt" fetch origin "$pr_base:$pr_base" 2>/dev/null || git -C "$main_wt" fetch origin "$pr_base" 2>/dev/null || true
|
|
548
|
+
echo "✓ $pr_base fetched (no worktree has it checked out) — merged branch + worktree cleaned"
|
|
549
|
+
fi
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
# _kto_existing_labels <repo> <comma-labels> — the subset of <comma-labels> the repo has, comma-joined
|
|
553
|
+
# on stdout; each one it lacks is named in a warning on stderr (#387). `gh issue create --label`
|
|
554
|
+
# aborts on an unknown label before any issue exists, and the REST endpoint creates the label
|
|
555
|
+
# instead, so both transports are filtered here: the issue is filed, no label is invented. Names
|
|
556
|
+
# match case-insensitively, as GitHub's do. A label list that cannot be read filters nothing.
|
|
557
|
+
_kto_existing_labels() {
|
|
558
|
+
local repo="$1" want="$2" have l keep=""
|
|
559
|
+
if cckit_gh_rest; then
|
|
560
|
+
have="$(gh_rest_label_names "$repo")" || { printf '%s' "$want"; return 0; }
|
|
561
|
+
else
|
|
562
|
+
have="$(gh label list --repo "$repo" --limit 1000 --json name --jq '.[].name' 2>/dev/null)" \
|
|
563
|
+
|| { printf '%s' "$want"; return 0; }
|
|
564
|
+
fi
|
|
565
|
+
while IFS= read -r l; do
|
|
566
|
+
[[ -n "$l" ]] || continue
|
|
567
|
+
if grep -qixF -- "$l" <<<"$have"; then
|
|
568
|
+
keep="${keep:+$keep,}$l"
|
|
569
|
+
else
|
|
570
|
+
echo "⚠ label '$l' not found in $repo — issue created without it (scripts/setup-labels.sh provisions the kit's labels)" >&2
|
|
571
|
+
fi
|
|
572
|
+
done <<EOF
|
|
573
|
+
$(printf '%s\n' "$want" | tr ',' '\n')
|
|
574
|
+
EOF
|
|
575
|
+
printf '%s' "$keep"
|
|
367
576
|
}
|
|
368
577
|
|
|
369
578
|
# kit task new — create a GitHub issue with labels + milestone, add it to the board, set Role +
|
|
370
579
|
# Status(Todo) + Plan Link. Inputs are passed (the caller does the AskUserQuestion). No invented
|
|
371
|
-
# values
|
|
580
|
+
# values: a label the repo does not have is dropped with a warning, never created, and the issue is
|
|
581
|
+
# still filed (#387). Non-zero only when the issue itself was not created.
|
|
372
582
|
# Args: <title> <role-display-or-slug> <kind> <priority> [milestone|""] [plan-link] [blocked-by] <body>
|
|
373
583
|
kto_task_new() {
|
|
374
584
|
local title="${1:-}" role="${2:-}" kind="${3:-}" prio="${4:-}" milestone="${5:-}" plan="${6:-}" blocked="${7:-}" body_user="${8:-}"
|
|
@@ -382,10 +592,15 @@ kto_task_new() {
|
|
|
382
592
|
role_slug="$(printf '%s' "$role" | tr 'A-Z ' 'a-z-')"
|
|
383
593
|
labels="kind:${kind},priority:${prio},role:${role_slug}"
|
|
384
594
|
body="$(kto_compose_issue_body "$body_user" "$plan" "$blocked" "$role_slug")"
|
|
595
|
+
labels="$(_kto_existing_labels "$repo" "$labels")"
|
|
385
596
|
|
|
597
|
+
if cckit_gh_rest; then
|
|
598
|
+
url=$(gh_rest_issue_create "$repo" "$title" "$body" "$labels" "$milestone") || return 1
|
|
599
|
+
else
|
|
386
600
|
url=$(gh issue create --repo "$repo" \
|
|
387
601
|
--title "$title" --body "$body" \
|
|
388
|
-
|
|
602
|
+
${labels:+--label} ${labels:+"$labels"} ${milestone:+--milestone "$milestone"} --assignee "@me") || return 1
|
|
603
|
+
fi
|
|
389
604
|
num=$(basename "$url")
|
|
390
605
|
echo "✓ $url"
|
|
391
606
|
|
|
@@ -407,16 +622,62 @@ kto_task_new() {
|
|
|
407
622
|
printf '%s' "$num"
|
|
408
623
|
}
|
|
409
624
|
|
|
410
|
-
# kit task close — set the board Status to Done and close the issue
|
|
411
|
-
# Plan-badge flip stays in the skill (it edits a repo file → needs a worktree/PR).
|
|
625
|
+
# kit task close — set the board Status to Done and close the issue with a summary comment and a
|
|
626
|
+
# close reason (#377). Plan-badge flip stays in the skill (it edits a repo file → needs a worktree/PR).
|
|
627
|
+
# Args: <num> <summary> [pr-num] [--reason completed|not-planned|duplicate] [--duplicate-of <N>]
|
|
628
|
+
# [--superseded-by <N>]
|
|
629
|
+
# --duplicate-of N GitHub state_reason duplicate, linked to #N (implies --reason duplicate)
|
|
630
|
+
# --superseded-by N state_reason not planned + "Superseded by #N" in the comment
|
|
631
|
+
# The summary may be omitted with --duplicate-of / --superseded-by: it defaults to "Duplicate of #N."
|
|
632
|
+
# / "Superseded by #N.". Flags may come anywhere; the closed set is the close-reason vocabulary.
|
|
412
633
|
kto_task_close() {
|
|
413
|
-
local num="
|
|
414
|
-
|
|
415
|
-
|
|
634
|
+
local num="" summary="" reason="" dup="" sup="" a pos=0
|
|
635
|
+
while [[ $# -gt 0 ]]; do
|
|
636
|
+
a="$1"
|
|
637
|
+
case "$a" in
|
|
638
|
+
--reason) reason="${2:-}"; shift 2 ;;
|
|
639
|
+
--reason=*) reason="${a#--reason=}"; shift ;;
|
|
640
|
+
--duplicate-of) dup="${2:-}"; shift 2 ;;
|
|
641
|
+
--superseded-by) sup="${2:-}"; shift 2 ;;
|
|
642
|
+
-*) echo "✗ kto_task_close: unknown flag '$a' — usage: cckit close <issue> [\"<summary>\"] [--reason completed|not-planned|duplicate] [--duplicate-of N] [--superseded-by N]" >&2; return 2 ;;
|
|
643
|
+
*)
|
|
644
|
+
pos=$((pos+1))
|
|
645
|
+
case "$pos" in 1) num="$a" ;; 2) summary="$a" ;; *) : ;; esac # 3rd positional = legacy pr-num
|
|
646
|
+
shift ;;
|
|
647
|
+
esac
|
|
648
|
+
done
|
|
649
|
+
dup="${dup#\#}"; sup="${sup#\#}"
|
|
416
650
|
[[ -n "$num" ]] || { echo "✗ kto_task_close: issue number required" >&2; return 1; }
|
|
651
|
+
[[ -z "$dup" || "$dup" =~ ^[0-9]+$ ]] || { echo "✗ kto_task_close: --duplicate-of needs an issue number" >&2; return 2; }
|
|
652
|
+
[[ -z "$sup" || "$sup" =~ ^[0-9]+$ ]] || { echo "✗ kto_task_close: --superseded-by needs an issue number" >&2; return 2; }
|
|
653
|
+
[[ -n "$dup" && -n "$sup" ]] && { echo "✗ kto_task_close: --duplicate-of and --superseded-by are exclusive" >&2; return 2; }
|
|
654
|
+
|
|
655
|
+
# The close-reason set (completed · not planned · duplicate · superseded) → GitHub's state_reason.
|
|
656
|
+
local gh_reason
|
|
657
|
+
case "$reason" in
|
|
658
|
+
""|completed) gh_reason="completed" ;;
|
|
659
|
+
not-planned|"not planned"|not_planned) gh_reason="not planned" ;;
|
|
660
|
+
duplicate) gh_reason="duplicate" ;;
|
|
661
|
+
*) echo "✗ kto_task_close: --reason must be completed, not-planned or duplicate (got '$reason')" >&2; return 2 ;;
|
|
662
|
+
esac
|
|
663
|
+
if [[ -n "$dup" ]]; then
|
|
664
|
+
[[ -z "$reason" || "$gh_reason" == "duplicate" ]] || { echo "✗ kto_task_close: --duplicate-of implies --reason duplicate" >&2; return 2; }
|
|
665
|
+
gh_reason="duplicate"; summary="${summary:-Duplicate of #$dup.}"
|
|
666
|
+
fi
|
|
667
|
+
if [[ -n "$sup" ]]; then
|
|
668
|
+
[[ -z "$reason" || "$gh_reason" == "not planned" ]] || { echo "✗ kto_task_close: --superseded-by implies --reason not-planned" >&2; return 2; }
|
|
669
|
+
gh_reason="not planned"
|
|
670
|
+
if [[ -z "$summary" ]]; then summary="Superseded by #$sup."
|
|
671
|
+
else case "$summary" in *"#$sup"*) : ;; *) summary="$summary"$'\n\n'"Superseded by #$sup." ;; esac
|
|
672
|
+
fi
|
|
673
|
+
fi
|
|
674
|
+
[[ "$gh_reason" == "duplicate" && -z "$dup" ]] && { echo "✗ kto_task_close: --reason duplicate needs --duplicate-of <N>" >&2; return 2; }
|
|
417
675
|
[[ -n "$summary" ]] || { echo "✗ kto_task_close: a summary is required" >&2; return 1; }
|
|
418
676
|
|
|
419
|
-
|
|
677
|
+
local repo issue_json state item
|
|
678
|
+
repo="$(kto_repo)"
|
|
679
|
+
if cckit_gh_rest; then issue_json=$(gh_rest_issue_json "$repo" "$num") || return 1
|
|
680
|
+
else issue_json=$(gh issue view "$num" --repo "$repo" --json state,projectItems) || return 1; fi
|
|
420
681
|
state=$(printf '%s' "$issue_json" | jq -r .state)
|
|
421
682
|
|
|
422
683
|
if kto_board_enabled && type load_project_ids >/dev/null 2>&1 && load_project_ids 2>/dev/null; then
|
|
@@ -426,8 +687,20 @@ kto_task_close() {
|
|
|
426
687
|
echo "✓ Board Status → Done for #$num" || true
|
|
427
688
|
fi
|
|
428
689
|
|
|
429
|
-
if [[ "$state" == "OPEN" ]]; then
|
|
430
|
-
|
|
690
|
+
if [[ "$state" == "OPEN" ]] && cckit_gh_rest; then
|
|
691
|
+
# REST has no duplicate link (#396): state_reason duplicate, and the comment names the original.
|
|
692
|
+
if [[ -n "$dup" ]]; then
|
|
693
|
+
case "$summary" in *"#$dup"*) : ;; *) summary="$summary"$'\n\n'"Duplicate of #$dup." ;; esac
|
|
694
|
+
fi
|
|
695
|
+
gh_rest_issue_close "$repo" "$num" "$gh_reason" "$summary" || return 1
|
|
696
|
+
echo "✓ Closed issue #$num ($gh_reason${dup:+ of #$dup}${sup:+, superseded by #$sup})"
|
|
697
|
+
elif [[ "$state" == "OPEN" ]]; then
|
|
698
|
+
if [[ -n "$dup" ]]; then
|
|
699
|
+
gh issue close "$num" --repo "$repo" --duplicate-of "$dup" --comment "$summary" || return 1
|
|
700
|
+
else
|
|
701
|
+
gh issue close "$num" --repo "$repo" --reason "$gh_reason" --comment "$summary" || return 1
|
|
702
|
+
fi
|
|
703
|
+
echo "✓ Closed issue #$num ($gh_reason${dup:+ of #$dup}${sup:+, superseded by #$sup})"
|
|
431
704
|
else
|
|
432
705
|
echo " issue #$num already $state — board status updated only"
|
|
433
706
|
fi
|