@jeiemgi/cckit 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (549) hide show
  1. package/.claude-plugin/plugin.json +4 -2
  2. package/AGENTS.md +22 -238
  3. package/README.md +66 -56
  4. package/SECURITY.md +4 -4
  5. package/bin/PROMPTS.md +12 -0
  6. package/bin/cckit +181 -140
  7. package/cckit.config.json +1 -1
  8. package/kit/PROMPTS.md +14 -0
  9. package/{commands → kit/commands}/kit-doctor.md +3 -4
  10. package/{commands → kit/commands}/kit-export-project.md +1 -1
  11. package/{commands → kit/commands}/kit-init.md +8 -20
  12. package/{commands → kit/commands}/kit-routines.md +1 -1
  13. package/{commands → kit/commands}/kit-update.md +3 -3
  14. package/kit/completions/cckit.bash +9 -0
  15. package/{databases → kit/databases}/supabase.json +1 -1
  16. package/{integrations → kit/integrations}/integration.schema.json +3 -3
  17. package/kit/interview/global.json +54 -0
  18. package/kit/interview/project.json +133 -0
  19. package/kit/modules/qa.json +63 -0
  20. package/kit/modules/software.json +48 -0
  21. package/{profiles → kit/profiles}/automation.json +1 -3
  22. package/{profiles → kit/profiles}/content.json +0 -2
  23. package/{profiles → kit/profiles}/marketing.json +0 -2
  24. package/{profiles → kit/profiles}/minimal.json +1 -3
  25. package/{profiles → kit/profiles}/research.json +1 -3
  26. package/{profiles → kit/profiles}/software.json +0 -2
  27. package/kit/routines/catalogue.json +84 -0
  28. package/{skills → kit/skills}/kit-add/SKILL.md +4 -4
  29. package/kit/skills/kit-advisor/SKILL.md +75 -0
  30. package/kit/skills/kit-advisor/references/close.md +53 -0
  31. package/kit/skills/kit-advisor/references/grill.md +69 -0
  32. package/kit/skills/kit-advisor/references/orchestrate.md +56 -0
  33. package/kit/skills/kit-advisor/references/plan.md +64 -0
  34. package/kit/skills/kit-advisor/references/review.md +47 -0
  35. package/kit/skills/kit-advisor/references/step-report.md +61 -0
  36. package/{skills → kit/skills}/kit-annotate/SKILL.md +2 -4
  37. package/{skills → kit/skills}/kit-autopilot/SKILL.md +7 -7
  38. package/{skills → kit/skills}/kit-cleanup/SKILL.md +4 -4
  39. package/{skills → kit/skills}/kit-contribute/SKILL.md +8 -12
  40. package/{skills → kit/skills}/kit-customize/SKILL.md +5 -8
  41. package/{skills → kit/skills}/kit-dev/SKILL.md +1 -1
  42. package/{skills → kit/skills}/kit-digest/SKILL.md +3 -3
  43. package/{skills → kit/skills}/kit-effort-close/SKILL.md +20 -12
  44. package/{skills → kit/skills}/kit-effort-new/SKILL.md +17 -14
  45. package/{skills → kit/skills}/kit-effort-pr/SKILL.md +7 -7
  46. package/{skills → kit/skills}/kit-effort-start/SKILL.md +3 -3
  47. package/{skills → kit/skills}/kit-gc/SKILL.md +3 -3
  48. package/{skills → kit/skills}/kit-next/SKILL.md +7 -7
  49. package/{skills → kit/skills}/kit-page/SKILL.md +1 -1
  50. package/{skills → kit/skills}/kit-plan-next/SKILL.md +10 -11
  51. package/{skills → kit/skills}/kit-status/SKILL.md +6 -6
  52. package/{skills → kit/skills}/kit-task-close/SKILL.md +5 -5
  53. package/{skills → kit/skills}/kit-task-new/SKILL.md +5 -5
  54. package/{skills → kit/skills}/kit-task-pr/SKILL.md +5 -5
  55. package/{skills → kit/skills}/kit-task-pr-auto/SKILL.md +1 -1
  56. package/{skills → kit/skills}/kit-task-pr-merge/SKILL.md +10 -10
  57. package/{skills → kit/skills}/kit-task-start/SKILL.md +1 -1
  58. package/{skills → kit/skills}/kit-task-sync/SKILL.md +5 -3
  59. package/{skills → kit/skills}/kit-ux-audit/SKILL.md +16 -35
  60. package/{skills → kit/skills}/kit-ux-audit/references/graph-model.md +7 -26
  61. package/{skills → kit/skills}/kit-ux-audit/references/report.md +2 -3
  62. package/{skills → kit/skills}/routing.yaml +6 -1
  63. package/kit/statusline/kit-statusline.sh +82 -0
  64. package/{templates → kit/templates}/agents/analyst.md +0 -11
  65. package/{templates → kit/templates}/agents/auto-dev.md +0 -13
  66. package/{templates → kit/templates}/agents/backend.md +0 -11
  67. package/{templates → kit/templates}/agents/designer.md +0 -11
  68. package/{templates → kit/templates}/agents/devops.md +0 -11
  69. package/{templates → kit/templates}/agents/editor.md +0 -11
  70. package/{templates → kit/templates}/agents/frontend.md +0 -11
  71. package/{templates → kit/templates}/agents/generalist.md +0 -11
  72. package/{templates → kit/templates}/agents/local-delegate.md +0 -13
  73. package/{templates → kit/templates}/agents/n8n.md +0 -11
  74. package/{templates → kit/templates}/agents/pm.md +0 -11
  75. package/{templates → kit/templates}/agents/qa.md +0 -11
  76. package/{templates → kit/templates}/agents/researcher.md +0 -11
  77. package/{templates → kit/templates}/agents/security.md +0 -11
  78. package/{templates → kit/templates}/agents/tech-lead.md +0 -11
  79. package/{templates → kit/templates}/agents/ux.md +3 -14
  80. package/{templates → kit/templates}/hooks/kit-mail-check.sh.tmpl +1 -1
  81. package/{templates → kit/templates}/instructions.md.tmpl +4 -21
  82. package/{templates → kit/templates}/kit.config.json.tmpl +0 -6
  83. package/{templates → kit/templates}/rules/authoring.md +7 -3
  84. package/{templates → kit/templates}/rules/branch-naming.md +3 -2
  85. package/{templates → kit/templates}/rules/delegation-brief.md +4 -0
  86. package/{templates → kit/templates}/rules/effort-model.md +34 -31
  87. package/{templates → kit/templates}/rules/gate-and-review.md +1 -1
  88. package/{templates → kit/templates}/rules/merge-safety.md +12 -9
  89. package/{templates → kit/templates}/rules/naming-and-ids.md +20 -24
  90. package/{templates → kit/templates}/rules/plan-next.md +5 -5
  91. package/{templates → kit/templates}/rules/react-annotate.md +0 -8
  92. package/{templates → kit/templates}/skills/campaign/SKILL.md +2 -2
  93. package/kit.config.schema.json +11 -11
  94. package/lib/PROMPTS.md +14 -0
  95. package/{scripts/lib → lib/core}/adapter-select-test.sh +7 -7
  96. package/lib/core/advisor-test.sh +55 -0
  97. package/{scripts/lib → lib/core}/agent-def-test.sh +1 -1
  98. package/{scripts/lib → lib/core}/agent-def.sh +2 -2
  99. package/{scripts/lib → lib/core}/agent-launch-test.sh +3 -3
  100. package/{scripts/lib → lib/core}/agent-profile-test.sh +2 -2
  101. package/{scripts/lib → lib/core}/agent-resolve-test.sh +4 -2
  102. package/{scripts/lib → lib/core}/agent-resolve.sh +5 -4
  103. package/{scripts → lib/core}/agent-skills-external.txt +3 -3
  104. package/{scripts → lib/core}/agent-skills-lint-test.sh +17 -17
  105. package/lib/core/agent-skills-lint.sh +115 -0
  106. package/{scripts → lib/core}/agent-template-lint-test.sh +7 -7
  107. package/lib/core/agent-template-lint.sh +58 -0
  108. package/{scripts/lib → lib/core}/board-view-test.sh +3 -3
  109. package/lib/core/board-view.sh +97 -0
  110. package/{scripts/lib → lib/core}/branch-owner-test.sh +3 -3
  111. package/lib/core/branch-owner.sh +201 -0
  112. package/lib/core/check.sh +125 -0
  113. package/{scripts/lib → lib/core}/codex-hooks-test.sh +3 -3
  114. package/{scripts → lib/core}/commitlint-test.sh +6 -6
  115. package/lib/core/commitlint.sh +54 -0
  116. package/{scripts/config-path-test.sh → lib/core/config-path-scan-test.sh} +2 -2
  117. package/{scripts/lib → lib/core}/config-path-test.sh +3 -3
  118. package/lib/core/config-path.sh +30 -0
  119. package/{scripts → lib/core}/content-skills-test.sh +17 -17
  120. package/{scripts → lib/core}/docs-marketing-words-test.sh +2 -2
  121. package/{scripts → lib/core}/docs-record-tables-test.sh +2 -2
  122. package/{scripts/lib → lib/core}/effort-metrics-test.sh +6 -6
  123. package/lib/core/effort-metrics.sh +591 -0
  124. package/{scripts/lib → lib/core}/effort-slug-test.sh +8 -4
  125. package/{scripts/lib → lib/core}/effort-slug.sh +8 -7
  126. package/lib/core/effort.sh +339 -0
  127. package/{scripts/lib → lib/core}/errors-header-test.sh +19 -9
  128. package/lib/core/errors-header.exempt +49 -0
  129. package/{scripts → lib/core}/exec-targets-test.sh +3 -3
  130. package/lib/core/feature-map.sh +76 -0
  131. package/lib/core/force-push-fence-test.sh +44 -0
  132. package/lib/core/force-push-fence.baseline +1 -0
  133. package/lib/core/force-push-fence.sh +51 -0
  134. package/{scripts → lib/core}/forge-fence-test.sh +13 -13
  135. package/{scripts → lib/core}/forge-fence.sh +14 -14
  136. package/{scripts → lib/core}/forge-report-test.sh +5 -5
  137. package/{scripts → lib/core}/forge-report.sh +18 -14
  138. package/{scripts/lib → lib/core}/git-core-test.sh +7 -7
  139. package/{scripts/lib → lib/core}/git-remote-test.sh +3 -3
  140. package/{scripts → lib/core}/guard-raw-git-ops-test.sh +4 -4
  141. package/{scripts → lib/core}/hook-adapter-test.sh +5 -5
  142. package/{scripts/lib → lib/core}/hook-refresh-test.sh +5 -5
  143. package/{scripts → lib/core}/instruction-budget-baseline.txt +2 -2
  144. package/lib/core/instruction-budget-lint.sh +238 -0
  145. package/{scripts/lib → lib/core}/integration-install-test.sh +12 -12
  146. package/lib/core/integration-install.sh +257 -0
  147. package/{scripts/lib → lib/core}/integrations-test.sh +38 -45
  148. package/lib/core/integrations.sh +244 -0
  149. package/{scripts/lib → lib/core}/kinds-test.sh +5 -5
  150. package/lib/core/kinds.sh +66 -0
  151. package/{scripts/lib → lib/core}/kit-cli-test.sh +1 -1
  152. package/{scripts/lib → lib/core}/kit-cli.sh +1 -1
  153. package/{scripts/lib → lib/core}/kit-config-resolve.sh +2 -2
  154. package/{scripts/lib → lib/core}/kit-config-test.sh +11 -11
  155. package/lib/core/kit-config.sh +164 -0
  156. package/{scripts/lib → lib/core}/kit-engine-test.sh +1 -1
  157. package/lib/core/kit-events.sh +72 -0
  158. package/lib/core/kit-local.sh +87 -0
  159. package/{scripts/lib → lib/core}/kit-manifest.sh +1 -1
  160. package/{scripts/lib → lib/core}/kit-mode-test.sh +1 -1
  161. package/{scripts/lib → lib/core}/kit-mode.sh +3 -3
  162. package/{scripts/lib → lib/core}/kit-operate.sh +1 -1
  163. package/{scripts/lib → lib/core}/kit-profile-test.sh +1 -1
  164. package/{scripts/lib → lib/core}/kit-profile.sh +2 -2
  165. package/{scripts/lib → lib/core}/kit-state-test.sh +1 -1
  166. package/lib/core/knowledge-lint.sh +106 -0
  167. package/lib/core/layout-fence-test.sh +35 -0
  168. package/lib/core/layout-fence.allow +15 -0
  169. package/lib/core/layout-fence.baseline +4 -0
  170. package/lib/core/layout-fence.sh +50 -0
  171. package/{scripts → lib/core}/leak-fence-test.sh +10 -10
  172. package/{scripts/lib → lib/core}/leak-fence.sh +1 -1
  173. package/lib/core/loose-issues-test.sh +102 -0
  174. package/lib/core/loose-issues.baseline +5 -0
  175. package/lib/core/loose-issues.sh +65 -0
  176. package/{scripts → lib/core}/marketing-walkthrough-test.sh +7 -7
  177. package/lib/core/naming-test.sh +112 -0
  178. package/lib/core/naming-verbs-test.sh +126 -0
  179. package/lib/core/naming.sh +172 -0
  180. package/{scripts/lib → lib/core}/orchestration-runtime-test.sh +4 -4
  181. package/{scripts → lib/core}/portable-test.sh +11 -7
  182. package/{scripts/lib → lib/core}/pr-evidence-test.sh +5 -5
  183. package/lib/core/pr-evidence.sh +361 -0
  184. package/{scripts/lib → lib/core}/qa-lane-test.sh +7 -7
  185. package/{scripts/lib → lib/core}/qa-lane.sh +4 -4
  186. package/{scripts/lib → lib/core}/qa-lanes-test.sh +5 -5
  187. package/lib/core/react-detect.sh +79 -0
  188. package/{scripts/lib → lib/core}/render-test.sh +1 -1
  189. package/lib/core/resident-context-test.sh +42 -0
  190. package/lib/core/resident-context.baseline +1 -0
  191. package/lib/core/resident-context.sh +56 -0
  192. package/lib/core/review-lint-baseline.txt +28 -0
  193. package/lib/core/review-lint.sh +266 -0
  194. package/{scripts → lib/core}/review-rules.conf +1 -1
  195. package/{scripts/lib → lib/core}/review-stage-test.sh +2 -2
  196. package/{scripts/lib → lib/core}/role-identity-test.sh +3 -3
  197. package/lib/core/role-identity.sh +71 -0
  198. package/{scripts → lib/core}/rule-recipes-test.sh +5 -5
  199. package/lib/core/secret-guard.sh +116 -0
  200. package/{scripts → lib/core}/self-install-test.sh +15 -16
  201. package/{scripts/lib → lib/core}/session-registry-test.sh +1 -1
  202. package/lib/core/session-registry.sh +233 -0
  203. package/{scripts → lib/core}/skill-frontmatter-baseline.txt +1 -1
  204. package/lib/core/skill-frontmatter-lint.sh +189 -0
  205. package/lib/core/spec-lint-test.sh +63 -0
  206. package/lib/core/spec-lint.sh +95 -0
  207. package/{scripts/lib → lib/core}/stage-receipt-test.sh +136 -4
  208. package/{scripts/lib → lib/core}/stage-receipt.sh +186 -7
  209. package/{scripts → lib/core}/terms-check-test.sh +6 -6
  210. package/lib/core/terms-check.sh +244 -0
  211. package/{scripts/lib → lib/core}/test-env-test.sh +2 -2
  212. package/{scripts/lib → lib/core}/test-env.sh +1 -1
  213. package/{scripts → lib/core}/test-runner-test.sh +11 -11
  214. package/{scripts → lib/core}/test.sh +12 -12
  215. package/{scripts → lib/core}/update-path-test.sh +3 -3
  216. package/{scripts → lib/core}/verbs-gen.sh +9 -9
  217. package/{scripts → lib/core}/verbs-help-test.sh +4 -4
  218. package/{scripts → lib/core}/verbs-ratchet-test.sh +24 -19
  219. package/{scripts → lib/core}/verbs-ratchet.sh +8 -8
  220. package/{scripts → lib/core}/verbs-test.sh +23 -23
  221. package/lib/core/verbs.baseline +5 -0
  222. package/{scripts/lib → lib/core}/verbs.sh +3 -3
  223. package/{scripts/lib → lib/core}/verbs.tsv +22 -20
  224. package/{scripts/lib → lib/core}/version-bump-test.sh +29 -8
  225. package/{scripts/lib → lib/core}/version-bump.sh +15 -2
  226. package/{scripts/lib → lib/core}/wave-result-test.sh +2 -2
  227. package/{scripts/lib → lib/core}/wave-result.sh +1 -1
  228. package/{scripts/lib → lib/core}/worker-brief-test.sh +4 -4
  229. package/{scripts/lib → lib/core}/worker-brief.sh +1 -1
  230. package/{scripts/lib → lib/core}/worktree-bootstrap-test.sh +1 -1
  231. package/{scripts/lib → lib/core}/worktree-issue-test.sh +2 -2
  232. package/lib/core/worktree-issue.sh +172 -0
  233. package/{scripts/lib → lib/core}/worktree-ports-test.sh +1 -1
  234. package/{scripts/lib → lib/core}/worktree-start-test.sh +2 -2
  235. package/lib/core/worktree-start.sh +790 -0
  236. package/{scripts/lib → lib/core}/zsh-safety-test.sh +11 -11
  237. package/{scripts/lib → lib/forge}/forge-github.sh +18 -7
  238. package/{scripts/lib → lib/forge}/forge-test.sh +4 -4
  239. package/{scripts/lib → lib/forge}/forge.sh +1 -1
  240. package/lib/forge/gh-board-add-test.sh +118 -0
  241. package/lib/forge/gh-log.sh +59 -0
  242. package/lib/forge/gh-project-test.sh +251 -0
  243. package/lib/forge/gh-project.sh +379 -0
  244. package/{scripts/lib → lib/forge}/gh-rest-test.sh +17 -13
  245. package/{scripts/lib → lib/forge}/gh-rest.sh +190 -16
  246. package/{scripts/lib → lib/forge}/init-github.sh +18 -8
  247. package/{scripts/lib → lib/forge}/test-forge-shim.sh +2 -1
  248. package/lib/verbs/PROMPTS.md +146 -0
  249. package/lib/verbs/annotate-setup.sh +149 -0
  250. package/{scripts → lib/verbs}/autopilot-run-test.sh +9 -9
  251. package/{scripts → lib/verbs}/autopilot-run.sh +9 -9
  252. package/{scripts → lib/verbs}/autopilot-test.sh +7 -6
  253. package/{scripts → lib/verbs}/autopilot.sh +7 -7
  254. package/{scripts/lib → lib/verbs}/captain-test.sh +1 -1
  255. package/{scripts/lib → lib/verbs}/captain.sh +8 -8
  256. package/lib/verbs/capture-project-ids.sh +99 -0
  257. package/{scripts/lib → lib/verbs}/content-kinds-gc-test.sh +7 -7
  258. package/{scripts/lib → lib/verbs}/contribute-root-test.sh +4 -4
  259. package/{scripts/lib → lib/verbs}/contribute-root.sh +1 -1
  260. package/{scripts → lib/verbs}/contribute.sh +8 -8
  261. package/{scripts → lib/verbs}/copilot-loop-test.sh +12 -12
  262. package/{scripts/lib → lib/verbs}/copilot-test.sh +15 -14
  263. package/{scripts/lib → lib/verbs}/copilot.sh +19 -19
  264. package/{scripts → lib/verbs}/database-supabase-test.sh +6 -6
  265. package/lib/verbs/effort-close-subs-test.sh +96 -0
  266. package/{scripts/lib → lib/verbs}/effort-dispatch-test.sh +5 -5
  267. package/{scripts/lib → lib/verbs}/effort-flows-test.sh +5 -5
  268. package/{scripts/lib → lib/verbs}/effort-ops-test.sh +111 -22
  269. package/lib/verbs/effort-ops.sh +1571 -0
  270. package/{scripts/lib → lib/verbs}/effort-parity-test.sh +47 -41
  271. package/{scripts/lib → lib/verbs}/effort-plan-test.sh +7 -7
  272. package/lib/verbs/effort-plan.sh +289 -0
  273. package/lib/verbs/effort-review-test.sh +107 -0
  274. package/lib/verbs/effort-review.sh +93 -0
  275. package/lib/verbs/grill-record-test.sh +49 -0
  276. package/lib/verbs/grill-record.sh +88 -0
  277. package/{scripts/lib → lib/verbs}/handoff.sh +3 -3
  278. package/{scripts → lib/verbs}/init-content-test.sh +14 -14
  279. package/{scripts/lib → lib/verbs}/init-guide.sh +6 -6
  280. package/{scripts → lib/verbs}/init-guided-test.sh +9 -9
  281. package/{scripts → lib/verbs}/init-recipes-test.sh +7 -7
  282. package/{scripts → lib/verbs}/init-upgrade-test.sh +9 -10
  283. package/lib/verbs/init.sh +1598 -0
  284. package/{scripts → lib/verbs}/install-test.sh +5 -5
  285. package/lib/verbs/install.sh +31 -0
  286. package/{scripts → lib/verbs}/integrations-check-test.sh +9 -9
  287. package/lib/verbs/integrations-check.sh +157 -0
  288. package/{scripts → lib/verbs}/kit-add-test.sh +8 -8
  289. package/lib/verbs/kit-add.sh +415 -0
  290. package/{scripts → lib/verbs}/kit-adopt-test.sh +4 -4
  291. package/{scripts → lib/verbs}/kit-adopt.sh +6 -6
  292. package/{scripts/lib → lib/verbs}/kit-brief-test.sh +44 -15
  293. package/{scripts/lib → lib/verbs}/kit-brief.sh +101 -16
  294. package/lib/verbs/kit-bump-version.sh +79 -0
  295. package/lib/verbs/kit-digest.sh +126 -0
  296. package/{scripts → lib/verbs}/kit-doctor-test.sh +57 -32
  297. package/lib/verbs/kit-doctor.sh +991 -0
  298. package/{scripts → lib/verbs}/kit-export-project-test.sh +4 -4
  299. package/lib/verbs/kit-export-project.sh +245 -0
  300. package/{scripts → lib/verbs}/kit-export-training-test.sh +3 -3
  301. package/lib/verbs/kit-export-training.sh +175 -0
  302. package/{scripts/lib → lib/verbs}/kit-gc-test.sh +5 -5
  303. package/lib/verbs/kit-gc.sh +804 -0
  304. package/{scripts/lib → lib/verbs}/kit-hotfix.sh +3 -3
  305. package/{scripts/lib → lib/verbs}/kit-interview-test.sh +2 -2
  306. package/lib/verbs/kit-interview.sh +319 -0
  307. package/{scripts/lib → lib/verbs}/kit-lib-test.sh +2 -2
  308. package/{scripts/lib → lib/verbs}/kit-lib.sh +10 -10
  309. package/{scripts → lib/verbs}/kit-migrate-test.sh +4 -4
  310. package/{scripts → lib/verbs}/kit-migrate.sh +5 -5
  311. package/{scripts/lib → lib/verbs}/kit-msg-test.sh +2 -2
  312. package/{scripts/lib → lib/verbs}/kit-msg.sh +5 -5
  313. package/{scripts → lib/verbs}/kit-onboard-test.sh +2 -3
  314. package/lib/verbs/kit-onboard.sh +69 -0
  315. package/{scripts → lib/verbs}/kit-promote-test.sh +4 -4
  316. package/{scripts → lib/verbs}/kit-promote.sh +4 -4
  317. package/{scripts → lib/verbs}/kit-remove-test.sh +4 -4
  318. package/{scripts → lib/verbs}/kit-remove.sh +5 -5
  319. package/lib/verbs/kit-routines.sh +322 -0
  320. package/lib/verbs/kit-self-update.sh +55 -0
  321. package/{scripts/lib → lib/verbs}/kit-status-test.sh +2 -2
  322. package/lib/verbs/kit-status.sh +650 -0
  323. package/{scripts/lib → lib/verbs}/kit-task-ops-test.sh +25 -2
  324. package/lib/verbs/kit-task-ops.sh +793 -0
  325. package/{scripts → lib/verbs}/kit-version-check-test.sh +3 -3
  326. package/lib/verbs/kit-version-check.sh +121 -0
  327. package/{scripts → lib/verbs}/kit-wire-test.sh +6 -6
  328. package/{scripts → lib/verbs}/kit-wire.sh +8 -8
  329. package/{scripts/lib → lib/verbs}/kto-hotfix-test.sh +3 -3
  330. package/{scripts/lib → lib/verbs}/kto-task-close-test.sh +2 -2
  331. package/{scripts/lib → lib/verbs}/kto-task-new-test.sh +20 -2
  332. package/{scripts/lib → lib/verbs}/kto-task-pr-merge-test.sh +46 -2
  333. package/{scripts/lib → lib/verbs}/kto-task-pr-test.sh +6 -6
  334. package/{scripts/lib → lib/verbs}/light-task-run-test.sh +4 -4
  335. package/{scripts/lib → lib/verbs}/light-task-test.sh +9 -9
  336. package/{scripts/lib → lib/verbs}/light-task.sh +26 -11
  337. package/{scripts/lib → lib/verbs}/next-test.sh +3 -3
  338. package/{scripts/lib → lib/verbs}/next.sh +10 -10
  339. package/{scripts → lib/verbs}/night-grant-test.sh +4 -4
  340. package/lib/verbs/night-grant.sh +454 -0
  341. package/{scripts → lib/verbs}/night-run-test.sh +3 -3
  342. package/{scripts → lib/verbs}/night-run.mjs +2 -2
  343. package/{scripts → lib/verbs}/orchestrate-test.sh +5 -5
  344. package/{scripts → lib/verbs}/orchestrate.sh +15 -15
  345. package/{scripts/lib → lib/verbs}/plan-machine-test.sh +1 -1
  346. package/{scripts/lib → lib/verbs}/plan-machine.sh +13 -13
  347. package/{scripts/lib → lib/verbs}/plan-next-test.sh +1 -1
  348. package/lib/verbs/plan-next.sh +213 -0
  349. package/{scripts → lib/verbs}/publish.sh +10 -10
  350. package/{scripts/lib → lib/verbs}/review-page-test.sh +4 -4
  351. package/lib/verbs/review-page.sh +375 -0
  352. package/lib/verbs/setup-labels.sh +96 -0
  353. package/lib/verbs/setup-milestones.sh +34 -0
  354. package/{scripts → lib/verbs}/showcase.sh +2 -2
  355. package/lib/verbs/sprint-test.sh +96 -0
  356. package/lib/verbs/sprint.sh +216 -0
  357. package/{scripts → lib/verbs}/status-test.sh +8 -8
  358. package/{scripts → lib/verbs}/status.sh +16 -16
  359. package/{scripts → lib/verbs}/task-sync-test.sh +40 -6
  360. package/lib/verbs/task-sync.sh +462 -0
  361. package/{scripts/lib → lib/verbs}/upgrade-report-test.sh +4 -4
  362. package/lib/verbs/ux-a11y-scan.sh +96 -0
  363. package/lib/verbs/ux-ds-audit.sh +146 -0
  364. package/lib/verbs/ux-graph-scan.sh +188 -0
  365. package/{scripts → lib/verbs}/wave-worker.sh +2 -2
  366. package/lib/verbs/web-install.sh +22 -0
  367. package/package.json +3 -10
  368. package/scripts/PROMPTS.md +13 -0
  369. package/scripts/agent-skills-lint.sh +12 -113
  370. package/scripts/agent-template-lint.sh +12 -56
  371. package/scripts/annotate-setup.sh +11 -151
  372. package/scripts/benchmark/checkpoint-test.sh +1 -1
  373. package/scripts/benchmark/checkpoint.sh +1 -1
  374. package/scripts/benchmark/gate.sh +2 -2
  375. package/scripts/benchmark/lib/bench-common.sh +1 -1
  376. package/scripts/capture-project-ids.sh +12 -70
  377. package/scripts/check.sh +12 -106
  378. package/scripts/force-push-fence.sh +14 -0
  379. package/scripts/init.sh +13 -1637
  380. package/scripts/install.sh +12 -29
  381. package/scripts/instruction-budget-lint.sh +13 -218
  382. package/scripts/integrations-check.sh +12 -155
  383. package/scripts/kit-add.sh +12 -413
  384. package/scripts/kit-bump-version.sh +13 -78
  385. package/scripts/kit-digest.sh +13 -125
  386. package/scripts/kit-doctor.sh +13 -971
  387. package/scripts/kit-export-project.sh +12 -243
  388. package/scripts/kit-export-training.sh +12 -173
  389. package/scripts/kit-onboard.sh +12 -67
  390. package/scripts/kit-routines.sh +12 -320
  391. package/scripts/kit-self-update.sh +12 -53
  392. package/scripts/kit-version-check.sh +12 -106
  393. package/scripts/knowledge-lint.sh +13 -98
  394. package/scripts/lib/board-view.sh +13 -96
  395. package/scripts/lib/branch-owner.sh +12 -199
  396. package/scripts/lib/commitlint.sh +12 -52
  397. package/scripts/lib/config-path.sh +13 -29
  398. package/scripts/lib/effort-metrics.sh +12 -589
  399. package/scripts/lib/effort-ops.sh +13 -1243
  400. package/scripts/lib/effort-plan.sh +12 -287
  401. package/scripts/lib/effort.sh +13 -365
  402. package/scripts/lib/gh-log.sh +14 -59
  403. package/scripts/lib/gh-project.sh +13 -254
  404. package/scripts/lib/grill-record.sh +14 -0
  405. package/scripts/lib/integration-install.sh +12 -255
  406. package/scripts/lib/integrations.sh +12 -242
  407. package/scripts/lib/kinds.sh +13 -65
  408. package/scripts/lib/kit-config.sh +12 -165
  409. package/scripts/lib/kit-events.sh +13 -71
  410. package/scripts/lib/kit-gc.sh +12 -802
  411. package/scripts/lib/kit-interview.sh +11 -316
  412. package/scripts/lib/kit-local.sh +12 -85
  413. package/scripts/lib/kit-status.sh +12 -648
  414. package/scripts/lib/kit-task-ops.sh +13 -738
  415. package/scripts/lib/naming.sh +14 -0
  416. package/scripts/lib/plan-next.sh +13 -212
  417. package/scripts/lib/pr-evidence.sh +12 -359
  418. package/scripts/lib/react-detect.sh +12 -77
  419. package/scripts/lib/review-page.sh +11 -372
  420. package/scripts/lib/role-identity.sh +13 -70
  421. package/scripts/lib/secret-guard.sh +12 -114
  422. package/scripts/lib/session-registry.sh +13 -232
  423. package/scripts/lib/spec-lint.sh +14 -0
  424. package/scripts/lib/worktree-issue.sh +12 -170
  425. package/scripts/lib/worktree-start.sh +13 -748
  426. package/scripts/night-grant.sh +12 -452
  427. package/scripts/review-lint.sh +13 -258
  428. package/scripts/setup-labels.sh +11 -82
  429. package/scripts/setup-milestones.sh +12 -21
  430. package/scripts/skill-frontmatter-lint.sh +13 -181
  431. package/scripts/task-sync.sh +13 -370
  432. package/scripts/terms-check.sh +13 -241
  433. package/scripts/ux-a11y-scan.sh +13 -95
  434. package/scripts/ux-ds-audit.sh +12 -144
  435. package/scripts/ux-graph-scan.sh +12 -186
  436. package/scripts/web-install.sh +16 -20
  437. package/docs/kit-annotate/01-explainer.html +0 -225
  438. package/docs/kit-annotate/02-implementation-plan.html +0 -196
  439. package/docs/media/.onboarding-capture.cast +0 -5
  440. package/docs/media/README.md +0 -43
  441. package/docs/media/build-demo.sh +0 -63
  442. package/docs/media/build-kit-init.sh +0 -51
  443. package/docs/media/build-onboarding.sh +0 -51
  444. package/docs/media/kit-dry-run.cast +0 -107
  445. package/docs/media/kit-dry-run.gif +0 -0
  446. package/docs/media/kit-init.cast +0 -56
  447. package/docs/media/kit-init.gif +0 -0
  448. package/docs/media/kit-onboarding.cast +0 -148
  449. package/docs/media/kit-onboarding.gif +0 -0
  450. package/integrations/mempalace.json +0 -28
  451. package/scripts/lib/gh-project-test.sh +0 -135
  452. package/scripts/review-lint-baseline.txt +0 -28
  453. package/scripts/verbs.baseline +0 -5
  454. package/templates/hooks/mempal_followup.sh.tmpl +0 -97
  455. package/templates/hooks/mempal_precompact.sh.tmpl +0 -4
  456. package/templates/hooks/mempal_save.sh.tmpl +0 -4
  457. package/templates/hooks/mempal_session_start.sh.tmpl +0 -42
  458. package/templates/rules/mempalace.md +0 -111
  459. /package/{commands → kit/commands}/kit-docs.md +0 -0
  460. /package/{commands → kit/commands}/kit-export-training.md +0 -0
  461. /package/{databases → kit/databases}/supabase/guide.html +0 -0
  462. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/client.ts +0 -0
  463. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/server.ts +0 -0
  464. /package/{githooks → kit/githooks}/pre-commit +0 -0
  465. /package/{integrations → kit/integrations}/emil-design-eng.json +0 -0
  466. /package/{integrations → kit/integrations}/graft.json +0 -0
  467. /package/{integrations → kit/integrations}/impeccable.json +0 -0
  468. /package/{integrations → kit/integrations}/lavish.json +0 -0
  469. /package/{integrations → kit/integrations}/mlx-lm.json +0 -0
  470. /package/{integrations → kit/integrations}/web-design-guidelines.json +0 -0
  471. /package/{recipes → kit/recipes}/nextjs-shadcn.json +0 -0
  472. /package/{skills → kit/skills}/kit-docs-writer/SKILL.md +0 -0
  473. /package/{skills → kit/skills}/kit-onboard/SKILL.md +0 -0
  474. /package/{skills → kit/skills}/kit-security-sweep/SKILL.md +0 -0
  475. /package/{skills → kit/skills}/kit-ship/SKILL.md +0 -0
  476. /package/{skills → kit/skills}/kit-ux-audit/references/a11y.md +0 -0
  477. /package/{skills → kit/skills}/kit-ux-audit/references/consistency.md +0 -0
  478. /package/{skills → kit/skills}/kit-ux-audit/references/heuristics.md +0 -0
  479. /package/{templates → kit/templates}/benchmarks/SCHEMA.md +0 -0
  480. /package/{templates → kit/templates}/benchmarks/abstain.jsonl +0 -0
  481. /package/{templates → kit/templates}/benchmarks/adversarial.jsonl +0 -0
  482. /package/{templates → kit/templates}/benchmarks/benchmark.config.json +0 -0
  483. /package/{templates → kit/templates}/benchmarks/quality.jsonl +0 -0
  484. /package/{templates → kit/templates}/benchmarks/retrieval.jsonl +0 -0
  485. /package/{templates → kit/templates}/codex/hooks.json.tmpl +0 -0
  486. /package/{templates → kit/templates}/hooks/guard-base-branch-commit.sh.tmpl +0 -0
  487. /package/{templates → kit/templates}/hooks/guard-raw-git-ops.sh.tmpl +0 -0
  488. /package/{templates → kit/templates}/hooks/kit-local-status.sh.tmpl +0 -0
  489. /package/{templates → kit/templates}/hooks/kit_version_check.sh.tmpl +0 -0
  490. /package/{templates → kit/templates}/hooks/prepush_gate.sh.tmpl +0 -0
  491. /package/{templates → kit/templates}/hooks/repo-hygiene.sh.tmpl +0 -0
  492. /package/{templates → kit/templates}/knowledge-INDEX.md.tmpl +0 -0
  493. /package/{templates → kit/templates}/lib/kit-sigil.sh.tmpl +0 -0
  494. /package/{templates → kit/templates}/rules/code-retrieval.md +0 -0
  495. /package/{templates → kit/templates}/rules/communication-style.md +0 -0
  496. /package/{templates → kit/templates}/rules/design-routing.md +0 -0
  497. /package/{templates → kit/templates}/rules/issue-lifecycle.md +0 -0
  498. /package/{templates → kit/templates}/rules/knowledge-base.md +0 -0
  499. /package/{templates → kit/templates}/rules/plain-language.md +0 -0
  500. /package/{templates → kit/templates}/rules/plan-output-format.md +0 -0
  501. /package/{templates → kit/templates}/rules/review-pages.md +0 -0
  502. /package/{templates → kit/templates}/rules/risk-tiered-review.md +0 -0
  503. /package/{templates → kit/templates}/rules/shared-checkout.md +0 -0
  504. /package/{templates → kit/templates}/rules/skill-gaps.md +0 -0
  505. /package/{templates → kit/templates}/rules/task-management.md +0 -0
  506. /package/{templates → kit/templates}/settings/settings.json.tmpl +0 -0
  507. /package/{templates → kit/templates}/settings/settings.local.json.tmpl +0 -0
  508. /package/{templates → kit/templates}/skills/NAMESPACED +0 -0
  509. /package/{templates → kit/templates}/skills/brand-voice/SKILL.md +0 -0
  510. /package/{templates → kit/templates}/skills/brand-voice/references/voice-template.md +0 -0
  511. /package/{templates → kit/templates}/skills/campaign/references/plan-template.md +0 -0
  512. /package/{templates → kit/templates}/skills/concrete/SKILL.md +0 -0
  513. /package/{templates → kit/templates}/skills/copywriting/SKILL.md +0 -0
  514. /package/{templates → kit/templates}/skills/copywriting/references/copy-frameworks.md +0 -0
  515. /package/{templates → kit/templates}/skills/copywriting/references/natural-transitions.md +0 -0
  516. /package/{templates → kit/templates}/skills/feature-build-refine/SKILL.md +0 -0
  517. /package/{templates → kit/templates}/skills/karpathy-guidelines/SKILL.md +0 -0
  518. /package/{templates → kit/templates}/skills/morning-briefing/SKILL.md +0 -0
  519. /package/{templates → kit/templates}/skills/page-design/SKILL.md +0 -0
  520. /package/{templates → kit/templates}/skills/page-design/add.json +0 -0
  521. /package/{templates → kit/templates}/skills/page-design/references/design-file-template.md +0 -0
  522. /package/{templates → kit/templates}/skills/page-design/references/generic-page-patterns.md +0 -0
  523. /package/{templates → kit/templates}/skills/page-design/references/minimum-rules.md +0 -0
  524. /package/{templates → kit/templates}/skills/speckit/SKILL.md +0 -0
  525. /package/{templates → kit/templates}/skills/supabase-patterns/SKILL.md +0 -0
  526. /package/{scripts/lib → lib/core}/adapter-select.sh +0 -0
  527. /package/{scripts/lib → lib/core}/agent-launch.sh +0 -0
  528. /package/{scripts/lib → lib/core}/agent-profile.sh +0 -0
  529. /package/{scripts/lib → lib/core}/cckit-output.sh +0 -0
  530. /package/{scripts/lib → lib/core}/codex-hooks.sh +0 -0
  531. /package/{scripts → lib/core}/forge-fence.baseline +0 -0
  532. /package/{scripts/lib → lib/core}/git-remote.sh +0 -0
  533. /package/{scripts/lib → lib/core}/hook-refresh.sh +0 -0
  534. /package/{scripts → lib/core}/instruction-budget-lint-test.sh +0 -0
  535. /package/{scripts/lib → lib/core}/kit-state.sh +0 -0
  536. /package/{scripts/lib → lib/core}/orchestration-runtime.sh +0 -0
  537. /package/{scripts/lib → lib/core}/project-scan.sh +0 -0
  538. /package/{scripts/lib → lib/core}/render.sh +0 -0
  539. /package/{scripts → lib/core}/review-lint-test.sh +0 -0
  540. /package/{scripts/lib → lib/core}/review-stage.sh +0 -0
  541. /package/{scripts → lib/core}/skill-frontmatter-lint-test.sh +0 -0
  542. /package/{scripts/lib → lib/core}/task-source-file.sh +0 -0
  543. /package/{scripts/lib → lib/core}/task-source.sh +0 -0
  544. /package/{scripts/lib → lib/core}/toon.sh +0 -0
  545. /package/{scripts/lib → lib/core}/ui.sh +0 -0
  546. /package/{scripts/lib → lib/forge}/forge-none.sh +0 -0
  547. /package/{scripts → lib/verbs}/debug.sh +0 -0
  548. /package/{scripts → lib/verbs}/night-run.test.mjs +0 -0
  549. /package/{scripts/lib → lib/verbs}/upgrade-report.sh +0 -0
@@ -0,0 +1,804 @@
1
+ #!/usr/bin/env bash
2
+ # kit-gc.sh — the canonical "garbage-collect the repo" git-mechanic (#373 / #419 extraction).
3
+ #
4
+ # Plugin mirror of the canonical lib/verbs/kit-gc.sh (#370 self-contained). Same op, one home.
5
+ # Family 1 of kit-engine-boundary.md (rule #1/#2): ONE bash home for the gc op, consumed by the
6
+ # kit-gc skill, `kit gc`, and the kit-ui Run cockpit (#816 — it shells `scripts/kit gc`). No second
7
+ # implementation. This extracts the read-only ANALYSIS — branch/worktree/stash classification with
8
+ # the issue-open protection — out of the skill so a UI can run a REAL verb (not just preview text).
9
+ #
10
+ # The DESTRUCTIVE prune stays interactive (the skill / a human drives the confirmed deletes); a
11
+ # headless surface only ever runs the analysis. That split is deliberate: `kit_gc_analyze` is safe
12
+ # to run anywhere, anytime (it writes nothing), so the cockpit can flip its `gc` verb to runnable.
13
+ #
14
+ # kit_gc_analyze print the classification table (read-only). rc 0 always.
15
+ # kit_gc_has_prunable rc 0 if anything is SAFE or LANDED to delete (for a UI badge / nudge).
16
+ # kit_gc_prune [--yes] [--only <regex>] delete the SAFE + LANDED rows (dry-run without --yes).
17
+ # kit_gc_cleanup [--yes] the guided sweep: plan every bucket, then act on SAFE + LANDED + ZOMBIE.
18
+ #
19
+ # Verdicts: PROTECTED (issue open) · SAFE (own PR merged) · ACTIVE (own PR open / base) · LANDED (no
20
+ # PR of its own, work already on base — #388: effort subs, agent isolation worktrees) · ORPHAN ·
21
+ # UNKNOWN (a gh read FAILED, so the verdict could not be determined — #330; never deletable).
22
+ # A DETACHED worktree has no branch to classify, so it gets its own row (#390): LANDED when it is
23
+ # clean and its HEAD is already on the base branch or `main`, ORPHAN otherwise.
24
+ #
25
+ # Requires: git; gh (degrades to "unknown" issue/PR state without it); lib/core/worktree-issue.sh.
26
+ # Portable: bash 3.2+ AND zsh.
27
+ # errors: mixed — kit_gc_analyze is read-only and forgiving; the prune path propagates
28
+
29
+ # The GitHub transport switch (#396): rest mode routes the gh calls below through gh-rest.sh.
30
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (lib/forge/gh-rest.sh).
31
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
32
+ # shellcheck source=/dev/null
33
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/.." && pwd)/forge/gh-rest.sh"
34
+ fi
35
+
36
+ if ! command -v cckit_gh_rest >/dev/null 2>&1; then
37
+ _ghr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/.." 2>/dev/null && pwd)/forge/gh-rest.sh"
38
+ # shellcheck source=/dev/null
39
+ [ -f "$_ghr_lib" ] && . "$_ghr_lib"
40
+ unset _ghr_lib
41
+ fi
42
+ command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
43
+
44
+ KIT_GC_REPO="${KIT_GC_REPO:-${KIT_REPO:-}}"
45
+
46
+ _kit_gc_root() { git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit {print $2; hit=1}'; }
47
+
48
+ # This file's own directory, resolved ONCE at load time — the only point where both shells agree.
49
+ # `BASH_SOURCE` is bash-only; inside a zsh *function* it is unset and `$0` is the function name, so
50
+ # the old per-call resolution fell back to `$0`="zsh", worktree-issue.sh was never sourced,
51
+ # `wt_protected_reason` stayed undefined, and every call site's `2>/dev/null || true` turned the
52
+ # resulting "command not found" into an empty reason — i.e. an open issue's branch classified as
53
+ # SAFE to delete. At FILE scope zsh sets `$0` to the sourced file's path, so one expansion covers
54
+ # bash (source or direct exec) and zsh (interactive or not) with no shell-specific syntax. Prompt
55
+ # expansion (`${(%):-%x}`) is deliberately avoided: it is zsh-only, needs `eval` to stay parseable
56
+ # under bash, and is unreliable in an INTERACTIVE zsh — the kit's own shell.
57
+ #
58
+ # `cd`'s own stdout is discarded, not just its stderr: an interactive zsh ECHOES the new directory
59
+ # (tilde-abbreviated) after a `cd`, so the bare `$(cd … && pwd)` idiom captured TWO lines and the
60
+ # resulting path never existed. `pwd` still writes to the substitution.
61
+ _KIT_GC_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
62
+
63
+ # Source worktree-issue.sh (wt_issue_number / wt_protected_reason) from the lib dir we live in.
64
+ _kit_gc_load_deps() {
65
+ command -v wt_protected_reason >/dev/null 2>&1 && return 0
66
+ # shellcheck source=/dev/null
67
+ [ -n "${_KIT_GC_LIB_DIR:-}" ] && [ -f "$_KIT_GC_LIB_DIR/../core/worktree-issue.sh" ] \
68
+ && . "$_KIT_GC_LIB_DIR/../core/worktree-issue.sh"
69
+ command -v wt_protected_reason >/dev/null 2>&1
70
+ }
71
+
72
+ # Fail LOUD if the protection helper could not be loaded. Without it every issue-open check
73
+ # silently returns empty and gc would offer to delete in-progress work — a wrong "safe" is far
74
+ # worse than a refusal, so callers must not proceed on a degraded analysis.
75
+ _kit_gc_require_deps() {
76
+ _kit_gc_load_deps || : # never let a load failure abort a `set -e` caller before the FATAL prints
77
+ command -v wt_protected_reason >/dev/null 2>&1 && return 0
78
+ echo "kit-gc: FATAL — worktree-issue.sh not loaded; issue-open protection is unavailable." >&2
79
+ echo "kit-gc: refusing to classify branches: everything would look SAFE to delete." >&2
80
+ return 1
81
+ }
82
+
83
+ # _kit_gc_pr_index [repo] — echo one "<headRefName>\tPR#<num> <STATE>" line per PR in ONE gh call, so
84
+ # branch classification is a local lookup instead of a per-branch `gh pr list --head` — an N+1 that
85
+ # scaled badly exactly when gc matters most (many stale branches). #124.
86
+ #
87
+ # A FAILED read is not an empty list (#330): an empty index means "this repo has no PRs", and every
88
+ # branch then reads as having none. So a failure warns on stderr and emits ONE sentinel line,
89
+ # `?<TAB>UNKNOWN` — `?` cannot be a branch name (git refuses it), so no lookup ever matches it — and
90
+ # _kit_gc_classify answers UNKNOWN instead of ORPHAN/LANDED for a branch it finds no PR for. rc 0
91
+ # always: kit-status.sh calls this in a bare assignment under `set -e`.
92
+ _kit_gc_pr_index() {
93
+ local repo="${1:-$KIT_GC_REPO}" out
94
+ out="$(forge_rest "repos/$repo/pulls" -X GET -f state=all -f per_page=100 --paginate \
95
+ --jq '.[] | "\(.head.ref)\tPR#\(.number) \(if .merged_at then "MERGED" else (.state | ascii_upcase) end)"' 2>/dev/null)" \
96
+ || { _kit_gc_pr_index_failed; return 0; }
97
+ [ -n "$out" ] && printf '%s\n' "$out"
98
+ return 0
99
+ }
100
+
101
+ _kit_gc_pr_index_failed() {
102
+ echo "kit-gc: could not read the PR list from GitHub — a branch whose PR is not known is reported UNKNOWN and kept" >&2
103
+ printf '?\tUNKNOWN\n'
104
+ }
105
+
106
+ # _kit_gc_pr_index_unknown <index> — rc 0 when <index> carries the failed-read sentinel.
107
+ _kit_gc_pr_index_unknown() {
108
+ grep -q "^?$(printf '\t')UNKNOWN\$" <<<"$1"
109
+ }
110
+
111
+ # _kit_gc_pr_for <index> <branch> — first PR line matching <branch> as head (mirrors the old `.[0]`).
112
+ _kit_gc_pr_for() {
113
+ printf '%s\n' "$1" | awk -F'\t' -v want="$2" '$1==want && !hit {print $2; hit=1}'
114
+ }
115
+
116
+ # _kit_gc_base_ref — the ref the LANDED checks compare against: `origin/<base>` when that
117
+ # remote-tracking ref exists (the merge target), else the local base branch (a repo with no origin,
118
+ # e.g. a test fixture). Empty when neither exists — then nothing can be LANDED.
119
+ _kit_gc_base_ref() {
120
+ local base="${KIT_BASE_BRANCH:-main}"
121
+ if git show-ref --verify --quiet "refs/remotes/origin/$base" 2>/dev/null; then printf 'origin/%s' "$base"
122
+ elif git show-ref --verify --quiet "refs/heads/$base" 2>/dev/null; then printf '%s' "$base"
123
+ fi
124
+ }
125
+
126
+ # _kit_gc_landed_reason <branch> <pr_index> [repo] — echo why <branch>'s work is already on the base
127
+ # branch, or nothing when it is not. The rows #388 is about: a branch with NO PR of its own whose work
128
+ # reached base through someone else's PR — an effort's `sub/<N><letter>` (merged into effort/<N>, then
129
+ # squash-merged), an `effort/<N>` whose remote ref is gone, a Claude Code Agent-tool isolation
130
+ # worktree (`worktree-agent-<hash>`, merged into the task branch that had the PR). `git cherry` and
131
+ # `--is-ancestor` cannot see through a squash (it rewrites the patch ids), so two checks, either of
132
+ # which suffices:
133
+ # (a) content — every file the branch changed since its merge base with base now has the same
134
+ # content on base (`git diff --quiet <base> <branch> -- <those files>`): the branch holds no
135
+ # change base lacks, whatever path it took there. A branch with no change at all beyond its
136
+ # merge base (or an ancestor of base) is landed trivially.
137
+ # (b) lineage — the name (`sub/<N>…`, `effort/<N>…`, any `<kind>/<N>-…`) or a `[#N]` in one of its
138
+ # commit subjects names an issue that is CLOSED and whose PR is MERGED: either a head
139
+ # `<kind>/<N>-…` in the PR index, or — when the PR has scrolled out of that 200-PR window — a
140
+ # PR the issue itself reports as having closed it (_kit_gc_issue_merged_pr, cached per issue).
141
+ # Covers a sub whose files base has since changed further, and an agent branch whose `[#N]`
142
+ # names the effort parent while the PR was the effort's.
143
+ # A branch failing both stays ORPHAN. Never called for a branch with a PR of its own.
144
+ _kit_gc_landed_reason() {
145
+ local b="$1" pr_index="$2" repo="${3:-$KIT_GC_REPO}" base_ref mb files shape="" n state pr
146
+ base_ref="$(_kit_gc_base_ref)"; [ -n "$base_ref" ] || return 0
147
+ case "$b" in worktree-agent-*) shape="agent worktree; " ;; esac
148
+ # (a) content
149
+ if git merge-base --is-ancestor "$b" "$base_ref" 2>/dev/null; then
150
+ printf '%sancestor of %s' "$shape" "$base_ref"; return 0
151
+ fi
152
+ mb="$(git merge-base "$base_ref" "$b" 2>/dev/null)"
153
+ if [ -n "$mb" ]; then
154
+ files="$(git diff --name-only "$mb" "$b" 2>/dev/null)"
155
+ if [ -z "$files" ]; then
156
+ printf '%sno change beyond %s' "$shape" "$base_ref"; return 0
157
+ fi
158
+ # NUL-delimited so a path with spaces survives; xargs exits non-zero if any batch differs.
159
+ if git diff --name-only -z "$mb" "$b" 2>/dev/null | xargs -0 git diff --quiet "$base_ref" "$b" -- 2>/dev/null; then
160
+ printf '%scontent on %s' "$shape" "$base_ref"; return 0
161
+ fi
162
+ fi
163
+ # (b) lineage
164
+ n="$(wt_issue_number "$b")"
165
+ # `[#N]` is the kit's token; `(#N)` is GitHub's own trailing ref (what a squash puts on a PR
166
+ # commit, and what a sub-issue's commit subject carried on a consuming repo's effort). Both name issues.
167
+ [ -n "$n" ] || n="$(git log --format=%s "$base_ref..$b" 2>/dev/null | grep -oE '[[(]#[0-9]+[])]' | sed -n 1p | tr -dc '0-9')"
168
+ [ -n "$n" ] || return 0
169
+ state="$(wt_issue_state "$n" "$repo")"
170
+ [ "$state" = closed ] || return 0
171
+ if grep -qE "^[a-z]+/${n}-[^ ]* PR#[0-9]+ MERGED\$" <<<"$pr_index"; then
172
+ printf '%sissue #%s closed, its PR merged' "$shape" "$n"
173
+ elif pr="$(_kit_gc_issue_merged_pr "$n" "$repo")" && [ -n "$pr" ]; then
174
+ # The index is a 200-PR window; on a repo with hundreds of merged PRs the effort PR that closed
175
+ # #N has scrolled out of it (measured on a consuming repo: the closing PR sat at position 254). The issue itself
176
+ # knows which PR closed it, and that lookup is exact and not window-bound. A sub-issue closes
177
+ # through `effort close`, not a PR, so the answer may come from its parent: "M via P".
178
+ case "$pr" in
179
+ *" via "*) printf '%sissue #%s closed, parent #%s closed by merged PR#%s' "$shape" "$n" "${pr#* via }" "${pr%% *}" ;;
180
+ *) printf '%sissue #%s closed by merged PR#%s' "$shape" "$n" "$pr" ;;
181
+ esac
182
+ fi
183
+ }
184
+
185
+ # Per-run cache for _kit_gc_issue_merged_pr. A file, not a shell variable: the lookup runs inside
186
+ # `$(...)` and `| while read` subshells, where a variable written is lost on return, while `$$` is
187
+ # the top shell's PID in every subshell of one verb run. kit_gc_analyze / kit_gc_prune reset it on
188
+ # entry so a result never outlives the run that made it (an issue closed since would read stale).
189
+ _KIT_GC_CACHE_DIR="${TMPDIR:-/tmp}/kit-gc-cache-$$"
190
+ _kit_gc_cache_reset() { rm -rf "$_KIT_GC_CACHE_DIR" 2>/dev/null; mkdir -p "$_KIT_GC_CACHE_DIR" 2>/dev/null || true; }
191
+
192
+ # _kit_gc_issue_merged_pr <issue> [repo] [depth] — echo the number of a MERGED PR that closed
193
+ # <issue>, or nothing. Reads the issue's `closedByPullRequestsReferences` (exact, not bound to the
194
+ # 200-PR index window) and confirms the state of each candidate. When nothing closed <issue> — a
195
+ # sub-issue closes through `effort close`, not a PR — climb ONCE to its parent (the sub-issues API;
196
+ # 404 = no parent) and answer `<M> via <P>` when the parent was closed by merged PR M. Cached per
197
+ # issue number for the run: an effort's subs and agent branches all name the same N, and 21
198
+ # branches must not mean 21 gh round trips. A negative answer is cached too. rc 0 with empty output
199
+ # when nothing merged closed it or its parent (measured: an effort closed NOT_PLANNED, no PR, no
200
+ # parent — a true ORPHAN).
201
+ _kit_gc_issue_merged_pr() {
202
+ local n="$1" repo="${2:-$KIT_GC_REPO}" depth="${3:-0}" cache="" cand result="" parent
203
+ [ -n "$n" ] || return 0
204
+ forge_available || { forge_note_none gc "merged pull requests cannot be read; a branch whose issue state is unknown is kept, never deleted"; return 0; }
205
+ [ -d "$_KIT_GC_CACHE_DIR" ] && cache="$_KIT_GC_CACHE_DIR/issue-$n"
206
+ if [ -n "$cache" ] && [ -f "$cache" ]; then cat "$cache"; return 0; fi
207
+ while IFS= read -r cand; do
208
+ [ -n "$cand" ] || continue
209
+ case "$cand" in *[!0-9]*) continue ;; esac
210
+ # The candidate came from a merged cross-reference that closes <n> (gh_rest_issue_closing_prs).
211
+ result="$cand"; break
212
+ done <<EOF
213
+ $(gh_rest_issue_closing_prs "$repo" "$n" 2>/dev/null || true)
214
+ EOF
215
+ if [ -z "$result" ] && [ "$depth" -eq 0 ]; then
216
+ parent="$(forge_rest "repos/$repo/issues/$n/parent" --jq .number 2>/dev/null || true)"
217
+ case "$parent" in ''|*[!0-9]*) parent="" ;; esac
218
+ if [ -n "$parent" ]; then
219
+ result="$(_kit_gc_issue_merged_pr "$parent" "$repo" 1)"
220
+ [ -n "$result" ] && result="${result%% *} via $parent"
221
+ fi
222
+ fi
223
+ [ -n "$cache" ] && printf '%s' "$result" > "$cache" 2>/dev/null
224
+ printf '%s' "$result"
225
+ }
226
+
227
+ # _kit_gc_classify <branch> <pr_index> [repo] — the ONE verdict for a branch, exactly as
228
+ # kit_gc_analyze prints it after `-> `. kit_gc_prune acts on this same function, so the plan a human
229
+ # approved and the delete that follows can never disagree (Family 1, the failure mode #219 was about).
230
+ # Order: base branch > PROTECTED (issue open, or light task open) > UNKNOWN (issue or light-task
231
+ # state read failed) > SAFE (own PR
232
+ # merged) > ACTIVE (own PR open) > a CLOSED-unmerged PR verbatim > UNKNOWN (PR list read failed) >
233
+ # LANDED (no PR, work on base) > ORPHAN.
234
+ #
235
+ # The two UNKNOWN rungs are #330. A failed issue-state read sits ABOVE SAFE and LANDED because the
236
+ # issue may be open: with gh failing, an open issue's branch with no commits beyond base used to
237
+ # lose PROTECTED and be classified LANDED by the content check, which needs no gh at all — and
238
+ # LANDED is deletable. A failed PR-list read sits above LANDED/ORPHAN because "found no PR" is not
239
+ # "has no PR" when the list never arrived. Neither string says "no PR", and neither is deletable
240
+ # (_kit_gc_prune_why answers nothing for it).
241
+ _kit_gc_classify() {
242
+ local b="$1" pr_index="$2" repo="${3:-$KIT_GC_REPO}" pr n state="" landed
243
+ case "$b" in "${KIT_BASE_BRANCH:-main}"|develop|main) echo "ACTIVE (base branch)"; return 0 ;; esac
244
+ pr="$(_kit_gc_pr_for "$pr_index" "$b")"
245
+ # The same read wt_protected_reason makes, kept as a state so `unknown` is not flattened to "".
246
+ n="$(wt_issue_number "$b" 2>/dev/null || true)"
247
+ [ -n "$n" ] && state="$(wt_issue_state "$n" "$repo" 2>/dev/null || true)"
248
+ # A light task's branch (`light/<id>-<slug>`, #450) names no issue; its task source answers. A
249
+ # copy of worktree-issue.sh that predates wt_task_id leaves both empty, as before.
250
+ local tid="" tstate=""
251
+ if command -v wt_task_id >/dev/null 2>&1; then tid="$(wt_task_id "$b" 2>/dev/null || true)"; fi
252
+ [ -n "$tid" ] && tstate="$(wt_task_state "$tid" "$b" 2>/dev/null || true)"
253
+ if [ "$state" = open ]; then
254
+ echo "PROTECTED: issue #$n still OPEN"
255
+ elif [ "$tstate" = open ]; then
256
+ echo "PROTECTED: light task $tid still OPEN"
257
+ elif [ "$state" = unknown ]; then
258
+ echo "UNKNOWN (could not determine — the state read for issue #$n failed; kept, never auto-deleted)"
259
+ elif [ "$tstate" = unknown ]; then
260
+ echo "UNKNOWN (could not determine — the state read for light task $tid failed; kept, never auto-deleted)"
261
+ elif grep -q 'MERGED' <<<"$pr"; then
262
+ echo "SAFE (${pr}, issue closed/absent — verify level with remote before delete)"
263
+ elif grep -q 'OPEN' <<<"$pr"; then
264
+ echo "ACTIVE (${pr})"
265
+ elif [ -n "$pr" ]; then
266
+ echo "$pr"
267
+ elif _kit_gc_pr_index_unknown "$pr_index"; then
268
+ echo "UNKNOWN (could not determine — the PR list read failed; kept, never auto-deleted)"
269
+ else
270
+ landed="$(_kit_gc_landed_reason "$b" "$pr_index" "$repo")"
271
+ if [ -n "$landed" ]; then echo "LANDED ($landed)"
272
+ else echo "ORPHAN (no PR — surface, never auto-delete)"; fi
273
+ fi
274
+ }
275
+
276
+ # _kit_gc_detached_verdict <worktree-path> <head-sha> — the ONE verdict for a live worktree whose HEAD
277
+ # is detached (#390), exactly as kit_gc_analyze prints it after `-> `. It has no branch, so none of
278
+ # the branch checks apply (no name to carry an issue number, no PR head to look up):
279
+ # LANDED the tree is clean AND HEAD is an ancestor of the base ref or of `main` — every commit it
280
+ # can reach is already there and no file differs, so removing it loses nothing. The shape
281
+ # an agent tool leaves behind when the `claude/*` branch it made the worktree for is gone,
282
+ # and a temp worktree a review built at a base commit.
283
+ # ORPHAN anything else: uncommitted changes, a status that cannot be read, or a HEAD that is on
284
+ # neither ref. A commit made on a detached HEAD is on no branch, so the worktree is the
285
+ # only handle on it — never deleted, surfaced by path.
286
+ # An ignored file does not make the tree dirty (same rule as the branch worktrees above).
287
+ _kit_gc_detached_verdict() {
288
+ local wtpath="$1" sha="$2" ref dirt
289
+ dirt="$(git -C "$wtpath" status --porcelain 2>/dev/null)" \
290
+ || { echo "ORPHAN (detached, status unreadable — surface, never auto-delete)"; return 0; }
291
+ if [ -n "$dirt" ]; then
292
+ echo "ORPHAN (detached, uncommitted changes — surface, never auto-delete)"; return 0
293
+ fi
294
+ for ref in "$(_kit_gc_base_ref)" origin/main main; do
295
+ [ -n "$ref" ] || continue
296
+ git rev-parse --verify --quiet "${ref}^{commit}" >/dev/null 2>&1 || continue
297
+ if git merge-base --is-ancestor "$sha" "$ref" 2>/dev/null; then
298
+ echo "LANDED (detached; ancestor of $ref)"; return 0
299
+ fi
300
+ done
301
+ echo "ORPHAN (detached, HEAD on neither the base branch nor main — surface, never auto-delete)"
302
+ }
303
+
304
+ # _kit_gc_detached_rows — echo "<path>\t<head-sha>\t<verdict>" for each LIVE linked worktree whose
305
+ # HEAD is detached. The first porcelain record is the main checkout (or a bare repo): it cannot be
306
+ # removed as a worktree, so it is never a row. A detached worktree whose directory is gone is a
307
+ # ZOMBIE and belongs to _kit_gc_zombies, not here. `substr`, not `$2`: a path may hold a space.
308
+ # Writes NOTHING. analyze, prune, cleanup and `cckit status` all read this one list.
309
+ _kit_gc_detached_rows() {
310
+ local wtpath sha
311
+ git worktree list --porcelain 2>/dev/null \
312
+ | awk '/^worktree / { n++; w = substr($0, 10); h = ""; next }
313
+ /^HEAD / { h = substr($0, 6); next }
314
+ /^detached$/ { if (n > 1) print w "\t" h }' \
315
+ | while IFS="$(printf '\t')" read -r wtpath sha; do
316
+ [ -n "$wtpath" ] && [ -d "$wtpath" ] || continue
317
+ printf '%s\t%s\t%s\n' "$wtpath" "$sha" "$(_kit_gc_detached_verdict "$wtpath" "$sha")"
318
+ done
319
+ }
320
+
321
+ # kit_gc_analyze — read-only classification of worktrees, branches, and stashes. Writes NOTHING.
322
+ # Each row is tagged PROTECTED / SAFE / ACTIVE / LANDED / ORPHAN / UNKNOWN so a human or UI can
323
+ # decide what to prune.
324
+ kit_gc_analyze() {
325
+ _kit_gc_require_deps || return 1
326
+ _kit_gc_cache_reset
327
+ # Without a forge no issue or pull request state can be read: every issue branch is UNKNOWN and
328
+ # kept. Said once here, since the per-branch reads below are quiet.
329
+ forge_available || forge_note_none gc "issue and pull request states cannot be read; every issue branch is UNKNOWN and kept, never deleted"
330
+ # `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so a bare `path` local
331
+ # here would clobber the command search path on assignment. A namespaced name is inert.
332
+ local repo="$KIT_GC_REPO" b ref wtpath reason
333
+ git fetch origin --prune --quiet 2>/dev/null || true
334
+
335
+ echo "# worktrees"
336
+ git worktree list --porcelain 2>/dev/null \
337
+ | awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
338
+ | while read -r wtpath ref; do
339
+ b="${ref#refs/heads/}"
340
+ reason="$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)"
341
+ if [ -n "$reason" ]; then echo " $wtpath [$b] -> PROTECTED: $reason"
342
+ else echo " $wtpath [$b] -> prunable if PR merged"; fi
343
+ done
344
+ # Detached worktrees: no `branch` line, so the loop above never sees them (#390).
345
+ local dsha dverdict
346
+ while IFS="$(printf '\t')" read -r wtpath dsha dverdict; do
347
+ [ -n "$wtpath" ] || continue
348
+ echo " $wtpath [detached@$(printf '%.12s' "$dsha")] -> $dverdict"
349
+ done <<EOF
350
+ $(_kit_gc_detached_rows)
351
+ EOF
352
+
353
+ echo "# branches"
354
+ # All PRs in ONE call, indexed locally by head branch (#124). while-read (NOT `for b in $(...)`) so
355
+ # branch iteration survives a NUL-polluted IFS.
356
+ local pr_index; pr_index="$(_kit_gc_pr_index "$repo")"
357
+ git branch --format='%(refname:short)' 2>/dev/null | while IFS= read -r b; do
358
+ [ -n "$b" ] || continue
359
+ echo " $b -> $(_kit_gc_classify "$b" "$pr_index" "$repo")"
360
+ done
361
+
362
+ echo "# stashes"
363
+ git stash list 2>/dev/null | sed 's/^/ /' || true
364
+
365
+ echo "# zombies (worktree dir gone, admin metadata lingers)"
366
+ local zname zbranch zstaged found=0
367
+ while IFS="$(printf '\t')" read -r zname zbranch zstaged; do
368
+ [ -n "$zname" ] || continue
369
+ found=1
370
+ if [ "$zstaged" = yes ] && _kit_gc_zombie_detached "$zbranch"; then
371
+ echo " $zname [$zbranch] -> ZOMBIE with STAGED work, detached — kept, never pruned (no branch to recover onto; recover by hand)"
372
+ elif [ "$zstaged" = yes ]; then
373
+ echo " $zname [$zbranch] -> ZOMBIE with STAGED work — recover-before-prune (gc --prune --yes recovers it to a commit)"
374
+ else
375
+ echo " $zname [$zbranch] -> ZOMBIE (no staged delta) — prunable"
376
+ fi
377
+ done <<EOF
378
+ $(_kit_gc_zombies)
379
+ EOF
380
+ [ "$found" -eq 1 ] || echo " (none)"
381
+ }
382
+
383
+ # kit_gc_has_prunable — rc 0 if at least one row is deletable: a branch that is SAFE (its own PR
384
+ # merged) or LANDED (no PR of its own, work already on base), or a LANDED detached worktree.
385
+ kit_gc_has_prunable() {
386
+ grep -qE '> (SAFE|LANDED) ' <<<"$(kit_gc_analyze 2>/dev/null)"
387
+ }
388
+
389
+ # _kit_gc_zombies — echo "<name>\t<branch>\t<staged:yes|no>" for each ZOMBIE worktree: its working
390
+ # dir is gone but its admin metadata (<git-common-dir>/worktrees/<name>/) lingers. staged=yes when
391
+ # the admin index holds a tree that differs from the branch tip (staged-but-uncommitted work that
392
+ # `git worktree prune` would orphan). A DETACHED zombie (its admin HEAD is a raw commit id, not a
393
+ # `ref:`) is compared to THAT commit's tree and labelled `detached@<sha12>` (#390): comparing it to
394
+ # an empty branch tip called every clean one "staged". Writes NOTHING. bash 3.2.
395
+ _kit_gc_zombies() {
396
+ local common wdir name gitdir wtpath branch tree tip tiptree staged dsha
397
+ common="$(git rev-parse --git-common-dir 2>/dev/null)" || return 0
398
+ case "$common" in /*) : ;; *) common="$(cd "$common" 2>/dev/null && pwd)" || return 0 ;; esac
399
+ [ -d "$common/worktrees" ] || return 0
400
+ for wdir in "$common"/worktrees/*/; do
401
+ [ -d "$wdir" ] || continue
402
+ gitdir="$(cat "$wdir/gitdir" 2>/dev/null)"; wtpath="${gitdir%/.git}"
403
+ # A zombie: the recorded working-tree path is set but no longer exists on disk.
404
+ [ -n "$wtpath" ] && [ ! -e "$wtpath" ] || continue
405
+ name="$(basename "$wdir")"
406
+ branch="$(sed -n 's#^ref: refs/heads/##p' "$wdir/HEAD" 2>/dev/null)"
407
+ tree=""; [ -f "$wdir/index" ] && tree="$(GIT_INDEX_FILE="$wdir/index" git write-tree 2>/dev/null)"
408
+ dsha=""; [ -n "$branch" ] || dsha="$(_kit_gc_zombie_head_sha "$wdir")"
409
+ if [ -n "$dsha" ]; then
410
+ tip="$(git rev-parse --verify --quiet "${dsha}^{commit}" 2>/dev/null)"
411
+ branch="detached@$(printf '%.12s' "$dsha")"
412
+ else
413
+ tip="$(git rev-parse --verify --quiet "refs/heads/${branch}" 2>/dev/null)"
414
+ fi
415
+ tiptree=""; [ -n "$tip" ] && tiptree="$(git rev-parse --verify --quiet "${tip}^{tree}" 2>/dev/null)"
416
+ if [ -n "$tree" ] && [ "$tree" != "$tiptree" ]; then staged=yes; else staged=no; fi
417
+ printf '%s\t%s\t%s\n' "$name" "${branch:-?}" "$staged"
418
+ done
419
+ }
420
+
421
+ # _kit_gc_zombie_head_sha <admin-dir> — echo the commit id a worktree's admin HEAD holds when it is
422
+ # DETACHED (a bare 40- or 64-hex line), nothing when HEAD is a `ref:`.
423
+ _kit_gc_zombie_head_sha() {
424
+ sed -n '1p' "$1/HEAD" 2>/dev/null | grep -E '^[0-9a-f]{40}([0-9a-f]{24})?$' || true
425
+ }
426
+
427
+ # _kit_gc_zombie_detached <label> — rc 0 when a _kit_gc_zombies branch column names a detached HEAD.
428
+ _kit_gc_zombie_detached() {
429
+ case "$1" in detached@*) return 0 ;; *) return 1 ;; esac
430
+ }
431
+
432
+ # kit_gc_recover_zombies <yes> — the recover-before-prune mechanic (#111). For each ZOMBIE worktree
433
+ # holding staged-but-uncommitted work, recover that delta to its branch via plumbing BEFORE any
434
+ # prune: GIT_INDEX_FILE=<admin>/index git write-tree -> git commit-tree -p <tip> -> update-ref. With
435
+ # <yes>=1 it performs the recovery + sweeps that zombie's stale locks; otherwise it reports what it
436
+ # WOULD recover (dry-run). Never prunes; that stays with the caller (gated on --yes). bash 3.2.
437
+ #
438
+ # A DETACHED zombie (#390) has no branch to commit onto. With no staged delta beyond its HEAD's tree
439
+ # it is skipped like any clean zombie and the caller's prune drops it. With one, the admin index is
440
+ # the only blob->path map and there is nowhere to recover it, so under <yes>=1 the admin dir is
441
+ # LOCKED (git's own `locked` file, which `git worktree prune` honors) — the caller's prune then
442
+ # leaves that one entry in place while it drops the rest. Before this, the message said "leaving it
443
+ # for manual recovery" and the prune that followed deleted the index anyway.
444
+ kit_gc_recover_zombies() {
445
+ local yes="${1:-0}" common wdir name gitdir wtpath branch tree tip tiptree newc msg dsha
446
+ common="$(git rev-parse --git-common-dir 2>/dev/null)" || return 0
447
+ case "$common" in /*) : ;; *) common="$(cd "$common" 2>/dev/null && pwd)" || return 0 ;; esac
448
+ [ -d "$common/worktrees" ] || return 0
449
+ for wdir in "$common"/worktrees/*/; do
450
+ [ -d "$wdir" ] || continue
451
+ gitdir="$(cat "$wdir/gitdir" 2>/dev/null)"; wtpath="${gitdir%/.git}"
452
+ [ -n "$wtpath" ] && [ ! -e "$wtpath" ] || continue # only dead worktrees
453
+ name="$(basename "$wdir")"
454
+ branch="$(sed -n 's#^ref: refs/heads/##p' "$wdir/HEAD" 2>/dev/null)"
455
+ [ -f "$wdir/index" ] || continue
456
+ tree="$(GIT_INDEX_FILE="$wdir/index" git write-tree 2>/dev/null)" || continue
457
+ [ -n "$tree" ] || continue
458
+ dsha=""; [ -n "$branch" ] || dsha="$(_kit_gc_zombie_head_sha "$wdir")"
459
+ if [ -n "$dsha" ]; then tip="$(git rev-parse --verify --quiet "${dsha}^{commit}" 2>/dev/null)"
460
+ else tip="$(git rev-parse --verify --quiet "refs/heads/${branch}" 2>/dev/null)"; fi
461
+ tiptree=""; [ -n "$tip" ] && tiptree="$(git rev-parse --verify --quiet "${tip}^{tree}" 2>/dev/null)"
462
+ # No staged delta beyond the tip → nothing to recover; the zombie is safe to prune as-is.
463
+ [ "$tree" = "$tiptree" ] && continue
464
+ if [ -z "$branch" ]; then
465
+ if [ "$yes" -ne 1 ]; then
466
+ echo " would KEEP zombie worktree $name — detached with staged work (staged tree $tree), no branch to recover onto" >&2
467
+ continue
468
+ fi
469
+ [ -e "$wdir/locked" ] \
470
+ || printf '%s\n' "kit gc: detached zombie holds staged work (tree $tree) — recover before pruning" > "$wdir/locked" 2>/dev/null
471
+ if [ -e "$wdir/locked" ]; then
472
+ echo " KEPT zombie worktree $name — detached with staged work, locked so the prune skips it. Recover: git branch <name> \$(git commit-tree $tree${tip:+ -p $tip} -m recovered); then rm '${wdir%/}/locked' && git worktree prune" >&2
473
+ else
474
+ echo " gc: could not lock detached zombie $name — its staged work (tree $tree) is NOT protected from the prune" >&2
475
+ fi
476
+ continue
477
+ fi
478
+ if [ "$yes" -ne 1 ]; then
479
+ echo " would RECOVER staged work from zombie worktree $name -> a commit on $branch (staged tree $tree)" >&2
480
+ continue
481
+ fi
482
+ msg="kit gc: recovered staged work from zombie worktree $name (recover-before-prune)"
483
+ newc="$(printf '%s\n' "$msg" | GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-kit-gc}" GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-kit-gc@localhost}" GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-kit-gc}" GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-kit-gc@localhost}" git commit-tree "$tree" ${tip:+-p "$tip"} 2>/dev/null)"
484
+ if [ -n "$newc" ]; then
485
+ # Compare-and-swap on the tip so a concurrent update is never clobbered.
486
+ if git update-ref "refs/heads/$branch" "$newc" ${tip:+"$tip"} 2>/dev/null; then
487
+ echo " RECOVERED staged work from zombie $name -> commit ${newc%% *} on $branch" >&2
488
+ else
489
+ echo " gc: could not update refs/heads/$branch (moved concurrently?) — zombie $name left intact" >&2
490
+ fi
491
+ fi
492
+ # Stale-lock sweep — safe only because this worktree is provably dead.
493
+ rm -f "$wdir/index.lock" "$wdir/HEAD.lock" 2>/dev/null || true
494
+ done
495
+ }
496
+
497
+ # _kit_gc_has_unpushed <branch> — rc 0 when the LOCAL branch holds commits its remote does not, i.e.
498
+ # deleting it locally would destroy the only copy. A missing remote ref is NOT unpushed work: the
499
+ # branch's PR merged, so the commits reached the base branch and the remote was deleted at merge.
500
+ # `git branch -D` is a force delete, so this is the guard that makes it safe (kit-gc SKILL: "verify a
501
+ # branch is level with its remote before deleting — an 'ahead' branch may hold orphan work").
502
+ _kit_gc_has_unpushed() {
503
+ local b="$1"
504
+ git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || return 1
505
+ [ "$(git rev-list --count "origin/$b..$b" 2>/dev/null || echo 1)" != "0" ]
506
+ }
507
+
508
+ # _kit_gc_remote_ahead <branch> — rc 0 when the REMOTE holds commits the local branch does not.
509
+ # Containment in one direction is not equality: `origin/<b>..<b>` = 0 only proves local ⊆ remote, so
510
+ # a remote-ahead branch would otherwise pass the level check and lose remote-only history on delete.
511
+ # Remote deletion requires BOTH directions empty.
512
+ _kit_gc_remote_ahead() {
513
+ local b="$1"
514
+ git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || return 1
515
+ [ "$(git rev-list --count "$b..origin/$b" 2>/dev/null || echo 1)" != "0" ]
516
+ }
517
+
518
+ # _kit_gc_only_match <regex> <branch> — rc 0 when <regex> is empty or <branch> matches it (ERE).
519
+ _kit_gc_only_match() {
520
+ [ -n "$1" ] || return 0
521
+ grep -qE -- "$1" <<<"$2"
522
+ }
523
+
524
+ # _kit_gc_prune_why <verdict> — echo the reason a prune row prints, or nothing when the verdict is
525
+ # not a deletable one. SAFE (own PR merged) and LANDED (no PR, work on base — #388) are the only two;
526
+ # UNKNOWN (#330, a failed gh read) falls through with every other kept verdict.
527
+ _kit_gc_prune_why() {
528
+ case "$1" in
529
+ SAFE*) echo "PR MERGED" ;;
530
+ LANDED*) echo "$1" ;;
531
+ *) : ;;
532
+ esac
533
+ }
534
+
535
+ # kit_gc_prune [--yes] [--only <regex>] - remove worktrees + local branches whose PR is MERGED (the
536
+ # SAFE rows) or whose work is already on base with no PR of their own (the LANDED rows, #388).
537
+ # A detached worktree rated LANDED (#390) goes the same way; one rated ORPHAN never does.
538
+ # DRY-RUN by default (lists what it WOULD remove); --yes performs the deletions. Never touches a
539
+ # PROTECTED/ACTIVE/ORPHAN branch, and never a DIRTY worktree (recover-before-prune): a worktree with
540
+ # staged/unstaged/untracked changes is skipped with a warning, not destroyed. The remote branch is
541
+ # already deleted at merge time (gh pr merge --delete-branch); this cleans up the local side.
542
+ # `--only <regex>` restricts both loops to branches matching the ERE (effort_close passes
543
+ # `^sub/<N>[a-z]-` to collect an effort's subs; a regex, not a glob — zsh does not expand a glob
544
+ # held in a variable inside `case`, bash does, and this file is sourced by both); the zombie pass is skipped under --only, since it
545
+ # is not scoped to a branch — that stays with a full `gc --prune` / `cleanup`.
546
+ kit_gc_prune() {
547
+ _kit_gc_require_deps || return 1
548
+ _kit_gc_cache_reset
549
+ # `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so assigning to a bare
550
+ # `path` local would clobber the command search path. A namespaced name is inert.
551
+ local repo="$KIT_GC_REPO" yes=0 wtpath ref b pr_index verdict why only=""
552
+ while [ $# -gt 0 ]; do
553
+ case "$1" in
554
+ --yes|-y) yes=1 ;;
555
+ --only) only="${2:-}"; shift ;;
556
+ --only=*) only="${1#--only=}" ;;
557
+ esac
558
+ shift
559
+ done
560
+
561
+ # All PRs in ONE call, indexed by head branch (#124) — shared by both loops below instead of a
562
+ # per-branch `gh pr list --head` (the N+1 that scaled badly with many stale branches).
563
+ pr_index="$(_kit_gc_pr_index "$repo")"
564
+
565
+ # Worktrees first - a branch's worktree must be removed before the branch can be deleted. The
566
+ # verdict comes from the ONE classifier (_kit_gc_classify), the same function analyze prints.
567
+ git worktree list --porcelain 2>/dev/null \
568
+ | awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
569
+ | while read -r wtpath ref; do
570
+ b="${ref#refs/heads/}"
571
+ [ -n "$b" ] || continue
572
+ _kit_gc_only_match "$only" "$b" || continue
573
+ verdict="$(_kit_gc_classify "$b" "$pr_index" "$repo")"
574
+ why="$(_kit_gc_prune_why "$verdict")"; [ -n "$why" ] || continue
575
+ if [ -n "$(git -C "$wtpath" status --porcelain 2>/dev/null)" ]; then
576
+ echo " SKIP dirty worktree $wtpath [$b] - commit/recover before pruning" >&2; continue
577
+ fi
578
+ if [ "$yes" -eq 1 ]; then
579
+ git worktree remove --force "$wtpath" 2>/dev/null && echo " removed worktree $wtpath [$b] ($why)"
580
+ else
581
+ echo " would remove worktree $wtpath [$b] ($why)"
582
+ fi
583
+ done
584
+
585
+ # Detached worktrees (#390): only the LANDED ones, by the same verdict analyze printed. No
586
+ # `--force`: the verdict already required a clean tree, so a refusal here means it changed since
587
+ # (or is locked) and the worktree is left exactly as it is. Not branch-scoped, so skipped under
588
+ # --only like the zombie pass below.
589
+ if [ -z "$only" ]; then
590
+ local dsha dlabel
591
+ while IFS="$(printf '\t')" read -r wtpath dsha verdict; do
592
+ [ -n "$wtpath" ] || continue
593
+ why="$(_kit_gc_prune_why "$verdict")"; [ -n "$why" ] || continue
594
+ dlabel="detached@$(printf '%.12s' "$dsha")"
595
+ if [ "$yes" -ne 1 ]; then
596
+ echo " would remove worktree $wtpath [$dlabel] ($why)"
597
+ elif git worktree remove "$wtpath" 2>/dev/null; then
598
+ echo " removed worktree $wtpath [$dlabel] ($why)"
599
+ else
600
+ echo " SKIP worktree $wtpath [$dlabel] - git refused to remove it (locked, or changed since the plan)" >&2
601
+ fi
602
+ done <<EOF
603
+ $(_kit_gc_detached_rows)
604
+ EOF
605
+ fi
606
+
607
+ # recover-before-prune (#111): a zombie worktree (working dir gone, admin metadata lingers) may
608
+ # hold staged-but-uncommitted work in its admin index — the ONLY blob->path map. `git worktree
609
+ # prune` deletes that index, orphaning the blobs for a later `git gc` to reap — real data loss in a
610
+ # documented incident. Recover any staged delta to its branch FIRST, and gate the prune sweep
611
+ # behind --yes so it NEVER runs in a dry-run (the previous unconditional prune was the hazard).
612
+ if [ -z "$only" ]; then
613
+ kit_gc_recover_zombies "$yes"
614
+ [ "$yes" -eq 1 ] && { git worktree prune 2>/dev/null || true; }
615
+ fi
616
+
617
+ # Then local branches whose PR merged, or whose work landed (worktree now gone). while-read (NOT
618
+ # `for b in $(...)`) so branch iteration survives a NUL-polluted IFS (#124).
619
+ git branch --format='%(refname:short)' 2>/dev/null | while IFS= read -r b; do
620
+ [ -n "$b" ] || continue
621
+ _kit_gc_only_match "$only" "$b" || continue
622
+ verdict="$(_kit_gc_classify "$b" "$pr_index" "$repo")"
623
+ why="$(_kit_gc_prune_why "$verdict")"; [ -n "$why" ] || continue
624
+ # A merged PR (or landed content) is not on its own sufficient: the local ref may carry commits
625
+ # that were never pushed, and `git branch -D` would be their last rites.
626
+ if _kit_gc_has_unpushed "$b"; then
627
+ echo " SKIP $b — ahead of origin/$b (unpushed commits); recover before pruning" >&2; continue
628
+ fi
629
+ if [ "$yes" -eq 1 ]; then
630
+ git branch -D "$b" >/dev/null 2>&1 && echo " deleted local branch $b ($why)"
631
+ else
632
+ echo " would delete local branch $b ($why)"
633
+ fi
634
+ done
635
+ [ "$yes" -eq 1 ] && echo "gc prune: done" || echo "gc prune: DRY RUN - pass --yes to delete"
636
+ }
637
+
638
+ # _kit_gc_names <analysis> <section> <verdict-regex> — echo one bare name per matching row inside a
639
+ # `# <section>` block of a kit_gc_analyze dump. The analysis is the SINGLE classifier (Family 1):
640
+ # cleanup reads its verdicts rather than re-deriving them, so the two can never disagree about what
641
+ # is safe to delete — the failure mode #219 was about.
642
+ _kit_gc_names() {
643
+ printf '%s\n' "$1" | awk -v sect="$2" -v want="$3" '
644
+ /^# / { in_s = ($0 == "# " sect); next }
645
+ !in_s { next }
646
+ $0 ~ want { sub(/^ /, ""); sub(/ ->.*/, ""); print }
647
+ '
648
+ }
649
+
650
+ # kit_gc_cleanup [--yes] — the ONE guided destructive sweep over the gc analysis.
651
+ #
652
+ # PLAN FIRST, always: print every bucket with its counts and names, then execute only the SAFE rows,
653
+ # and only with --yes. Without --yes nothing is written — the plan IS the output. Every row the plan
654
+ # omits is a deletion the user did not get to veto, so the plan must name EVERYTHING --yes can touch:
655
+ # worktrees as well as branches.
656
+ #
657
+ # What --yes deletes: SAFE and LANDED worktrees and local branches (via kit_gc_prune, which also runs
658
+ # the recover-before-prune zombie pass) — SAFE = its own PR merged, LANDED = no PR of its own but its
659
+ # work is already on base (#388: effort subs, agent isolation worktrees) — and the REMOTE ref of such
660
+ # a branch when it is exactly level with it. What it NEVER deletes: an ORPHAN branch (local commits
661
+ # not on the base remote), a PROTECTED branch (its issue is still open), or a stash. Those three are
662
+ # irreversible or hold the only copy of work, so they are surfaced BY NAME for a human and left
663
+ # exactly where they are.
664
+ #
665
+ # NOTE: the underlying kit_gc_analyze refreshes remote-tracking refs (`git fetch --prune`) so the
666
+ # classification is not made against a stale view of the remote. That is the only write a plan-only
667
+ # run performs, and it touches no branch, worktree, stash, or commit of yours.
668
+ kit_gc_cleanup() {
669
+ _kit_gc_require_deps || return 1
670
+ local repo="$KIT_GC_REPO" yes=0 a out b n_safe n_orphan n_prot n_stash n_wt rc=0 n_rfail=0
671
+ local zname zbranch zstaged
672
+ local safe_list landed_list orphan_list prot_list stash_list wt_list zomb_list level_ok n_zomb n_landed
673
+ local unknown_list n_unknown
674
+ local det_rows det_wt det_orphan wtpath dsha dverdict n_zkept
675
+ for a in "$@"; do case "$a" in --yes|-y) yes=1 ;; esac; done
676
+
677
+ out="$(kit_gc_analyze)" || return 1
678
+ safe_list="$(_kit_gc_names "$out" branches ' -> SAFE ')"
679
+ # LANDED rows keep their reason (`name (reason)`) so the plan says WHY each one may go (#388).
680
+ landed_list="$(printf '%s\n' "$out" | awk '
681
+ /^# / { in_s = ($0 == "# branches"); next }
682
+ in_s && / -> LANDED / { sub(/^ /, ""); sub(/ -> LANDED /, " "); print }')"
683
+ orphan_list="$(_kit_gc_names "$out" branches ' -> ORPHAN')"
684
+ prot_list="$(_kit_gc_names "$out" branches ' -> PROTECTED:')"
685
+ unknown_list="$(_kit_gc_names "$out" branches ' -> UNKNOWN ')"
686
+ stash_list="$(printf '%s\n' "$out" | awk '/^# /{in_s=($0=="# stashes"); next} in_s && NF' | sed 's/^ //')"
687
+
688
+ # Worktrees kit_gc_prune would remove: the ones whose branch is itself SAFE or LANDED (the same
689
+ # verdicts prune acts on). Derived from those lists so the two cannot diverge.
690
+ wt_list="$(git worktree list --porcelain 2>/dev/null \
691
+ | awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
692
+ | while read -r wtpath ref; do
693
+ b="${ref#refs/heads/}"
694
+ grep -qxF "$b" <<<"$safe_list" \
695
+ || grep -qxF "$b" <<<"$(printf '%s\n' "$landed_list" | sed 's/ (.*//')" || continue
696
+ if [ -n "$(git -C "$wtpath" status --porcelain 2>/dev/null)" ]; then
697
+ echo "$wtpath [$b] (DIRTY — will be skipped, not destroyed)"
698
+ else
699
+ echo "$wtpath [$b]"
700
+ fi
701
+ done)"
702
+
703
+ # Detached worktrees (#390) have no branch, so neither list above carries them. The LANDED ones
704
+ # join the worktrees --yes removes; the ORPHAN ones join the kept rows, named by path. Same helper
705
+ # as the analyze report and the prune pass, so the three cannot diverge.
706
+ det_rows="$(_kit_gc_detached_rows)"
707
+ det_wt="$(printf '%s\n' "$det_rows" | while IFS="$(printf '\t')" read -r wtpath dsha dverdict; do
708
+ case "$dverdict" in LANDED*) echo "$wtpath [detached@$(printf '%.12s' "$dsha")] ${dverdict#LANDED }" ;; *) : ;; esac
709
+ done)"
710
+ det_orphan="$(printf '%s\n' "$det_rows" | while IFS="$(printf '\t')" read -r wtpath dsha dverdict; do
711
+ case "$dverdict" in ORPHAN*) echo "$wtpath [detached@$(printf '%.12s' "$dsha")] ${dverdict#ORPHAN }" ;; *) : ;; esac
712
+ done)"
713
+ [ -n "$det_wt" ] && wt_list="$(printf '%s\n%s' "$wt_list" "$det_wt" | grep . || true)"
714
+ [ -n "$det_orphan" ] && orphan_list="$(printf '%s\n%s' "$orphan_list" "$det_orphan" | grep . || true)"
715
+
716
+ # ZOMBIE worktrees (dir gone, admin metadata lingers). kit_gc_prune --yes acts on these two ways
717
+ # — kit_gc_recover_zombies commits any staged delta to the branch, then `git worktree prune`
718
+ # drops the metadata — so the plan MUST name them or --yes would touch a row nobody approved
719
+ # (#227 review). Same helper as the analyze report, so the two cannot diverge.
720
+ zomb_list="$(while IFS="$(printf '\t')" read -r zname zbranch zstaged; do
721
+ [ -n "$zname" ] || continue
722
+ if [ "$zstaged" = yes ] && _kit_gc_zombie_detached "$zbranch"; then
723
+ echo "$zname [$zbranch] (STAGED work, detached — kept, not pruned: no branch to recover onto)"
724
+ elif [ "$zstaged" = yes ]; then
725
+ echo "$zname [$zbranch] (STAGED work — recovered to a commit on $zbranch, then metadata pruned)"
726
+ else
727
+ echo "$zname [$zbranch] (no staged delta — metadata pruned)"
728
+ fi
729
+ done <<ZEOF
730
+ $(_kit_gc_zombies)
731
+ ZEOF
732
+ )"
733
+
734
+ n_safe="$(printf '%s' "$safe_list" | grep -c . || true)"
735
+ n_landed="$(printf '%s' "$landed_list" | grep -c . || true)"
736
+ n_orphan="$(printf '%s' "$orphan_list" | grep -c . || true)"
737
+ n_prot="$(printf '%s' "$prot_list" | grep -c . || true)"
738
+ n_unknown="$(printf '%s' "$unknown_list" | grep -c . || true)"
739
+ n_stash="$(printf '%s' "$stash_list" | grep -c . || true)"
740
+ n_wt="$(printf '%s' "$wt_list" | grep -c . || true)"
741
+ n_zomb="$(printf '%s' "$zomb_list" | grep -c . || true)"
742
+ n_zkept="$(printf '%s' "$zomb_list" | grep -c 'kept, not pruned' || true)"
743
+
744
+ echo "# cleanup plan"
745
+ printf ' SAFE branches %3s merged PR, issue closed/absent\n' "$n_safe"
746
+ printf '%s\n' "$safe_list" | grep . | sed 's/^/ /' || true
747
+ printf ' SAFE worktrees %3s removed with their branch (SAFE or LANDED)\n' "$n_wt"
748
+ printf '%s\n' "$wt_list" | grep . | sed 's/^/ /' || true
749
+ printf ' ZOMBIE worktrees %3s staged work recovered to its branch, then metadata pruned\n' "$n_zomb"
750
+ printf '%s\n' "$zomb_list" | grep . | sed 's/^/ /' || true
751
+ printf ' LANDED branches %3s no PR of its own, work already on the base branch\n' "$n_landed"
752
+ printf '%s\n' "$landed_list" | grep . | sed 's/^/ /' || true
753
+ printf ' ORPHAN kept %3s commits not on the base remote — never auto-deleted\n' "$n_orphan"
754
+ printf '%s\n' "$orphan_list" | grep . | sed 's/^/ /' || true
755
+ printf ' PROTECTED kept %3s issue still OPEN\n' "$n_prot"
756
+ printf '%s\n' "$prot_list" | grep . | sed 's/^/ /' || true
757
+ printf ' UNKNOWN kept %3s a GitHub read failed — could not determine, rerun when GitHub answers\n' "$n_unknown"
758
+ printf '%s\n' "$unknown_list" | grep . | sed 's/^/ /' || true
759
+ printf ' stashes kept %3s irreversible — drop by hand after reading each diff\n' "$n_stash"
760
+ printf '%s\n' "$stash_list" | grep . | sed 's/^/ /' || true
761
+
762
+ if [ "$yes" -ne 1 ]; then
763
+ echo "cleanup: PLAN ONLY — nothing deleted. Pass --yes to delete the SAFE and LANDED rows and prune the ZOMBIE rows."
764
+ return 0
765
+ fi
766
+ [ "$n_safe" -eq 0 ] && [ "$n_landed" -eq 0 ] && [ "$n_wt" -eq 0 ] && [ "$n_zomb" -eq 0 ] \
767
+ && { echo "cleanup: nothing SAFE or LANDED to delete."; return 0; }
768
+
769
+ # Which SAFE / LANDED branches may have their REMOTE deleted — decided BEFORE the local prune,
770
+ # because once the local ref is gone there is nothing left to compare. Requires exact equality in
771
+ # BOTH directions: local ⊆ remote alone would let a remote-ahead branch lose remote-only history.
772
+ level_ok=""
773
+ while IFS= read -r b; do
774
+ [ -n "$b" ] || continue
775
+ git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || continue
776
+ _kit_gc_has_unpushed "$b" && { echo " SKIP remote $b — local is ahead of origin/$b" >&2; continue; }
777
+ _kit_gc_remote_ahead "$b" && { echo " SKIP remote $b — origin/$b is ahead of local" >&2; continue; }
778
+ level_ok="$level_ok$b
779
+ "
780
+ done <<EOF
781
+ $safe_list
782
+ $(printf '%s\n' "$landed_list" | sed 's/ (.*//')
783
+ EOF
784
+
785
+ kit_gc_prune --yes || rc=1
786
+
787
+ # Remote side last: only branches proven exactly level above, so nothing unpushed or remote-only
788
+ # is dropped. A failed delete is reported AND counted (this loop is heredoc-fed, not piped, so it
789
+ # runs in the current shell and the counter survives), never retried blindly.
790
+ while IFS= read -r b; do
791
+ [ -n "$b" ] || continue
792
+ if git push origin --delete "$b" >/dev/null 2>&1; then
793
+ echo " deleted remote branch $b"
794
+ else
795
+ echo " SKIP remote $b — delete failed (protected ref or already gone)" >&2
796
+ n_rfail=$((n_rfail + 1)); rc=1
797
+ fi
798
+ done <<EOF
799
+ $level_ok
800
+ EOF
801
+ printf ' remote deletes failed %3s\n' "$n_rfail"
802
+ echo "cleanup: done — $n_safe safe + $n_landed landed deleted / $((n_zomb - n_zkept)) zombie pruned / $n_orphan orphan / $n_prot protected / $n_unknown unknown / $n_stash stash left untouched."
803
+ return "$rc"
804
+ }