@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,991 @@
1
+ #!/usr/bin/env bash
2
+ # kit-doctor — onboarding preflight: deps + brew bootstrap + gh auth/scopes + SSH guided
3
+ #
4
+ # Usage:
5
+ # lib/verbs/kit-doctor.sh # detect + report; in a terminal, ASK before installing.
6
+ # # With no terminal and no --fix: report only, nothing is
7
+ # # installed and no file is written
8
+ # lib/verbs/kit-doctor.sh --fix # install missing deps without asking (alias: --yes, -y)
9
+ # lib/verbs/kit-doctor.sh --dry-run # report only — no installs, no auth changes
10
+ # lib/verbs/kit-doctor.sh --no-install # check and auth only — skip package installs
11
+ # lib/verbs/kit-doctor.sh --dismiss-local # silence the "local layer down" session notice
12
+ # # until the next x.y kit update
13
+ # lib/verbs/kit-doctor.sh --agents # only the selected agent runtimes (claude / codex):
14
+ # # present or absent; exit 1 if one is absent. No network.
15
+ # lib/verbs/kit-doctor.sh --loose # only the loose-issue count + the list (#N title): open
16
+ # # issues that are no effort, no sub-issue, not in Backlog
17
+ # lib/verbs/kit-doctor.sh --loose --ratchet [--baseline=FILE]
18
+ # # exit 1 when the count rose above the baseline
19
+ # # (default lib/core/loose-issues.baseline); 2 = not judged
20
+ #
21
+ # Tiers:
22
+ # Tier 0 Homebrew (macOS bootstrap — requires sudo password)
23
+ # Tier 1 git, gh, jq, perl — hard deps, auto-install via brew
24
+ # Tier 2 node + pnpm, vercel, turbo — project-specific, auto-install if applicable
25
+ # Agents the runtime binary of each adapter the project selected (`adapters` in the config),
26
+ # plus whether the Codex hooks are registered in .codex/hooks.json when codex is selected
27
+ # Integr. one row per descriptor in kit/integrations/ that is on (its config key, or on by default
28
+ # with the key absent — a missing default-on tool is reported, not failed) — installed by the
29
+ # shared runner (lib/core/integration-install.sh), only with recorded consent
30
+ # Local mlx_lm.server auto-start (when .local.enabled)
31
+ # Auth gh auth status + scope:project, git config name/email
32
+ # SSH optional guided flow (ed25519, pbcopy, link to github settings)
33
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (lib/forge/gh-rest.sh).
34
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
35
+ # shellcheck source=/dev/null
36
+ . "$(cd "$(dirname "$0")/.." && pwd)/forge/gh-rest.sh"
37
+ fi
38
+
39
+ set -euo pipefail
40
+
41
+ # Own directory — so we can find sibling scripts (kit-export-project.sh) regardless of cwd.
42
+ _export_dir_doctor="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
43
+
44
+ # ---- flags ------------------------------------------------------------------
45
+ DRY_RUN=0; NO_INSTALL=0; DISMISS_LOCAL=0; ASSUME_YES=0; AGENTS_ONLY=0
46
+ LOOSE_ONLY=0; LOOSE_RATCHET=0; LOOSE_BASELINE=""
47
+ INSTALL_APPROVED=0 # 1 = the operator said yes to installs in THIS run (--fix/--yes, or the prompt)
48
+ for _a in "$@"; do
49
+ case "$_a" in
50
+ --dry-run) DRY_RUN=1 ;;
51
+ --no-install) NO_INSTALL=1 ;;
52
+ --fix|--yes|-y) ASSUME_YES=1; INSTALL_APPROVED=1 ;;
53
+ --dismiss-local) DISMISS_LOCAL=1 ;;
54
+ --agents) AGENTS_ONLY=1 ;;
55
+ --loose) LOOSE_ONLY=1 ;;
56
+ --ratchet) LOOSE_ONLY=1; LOOSE_RATCHET=1 ;;
57
+ --baseline=*) LOOSE_BASELINE="${_a#--baseline=}" ;;
58
+ -h|--help)
59
+ sed -n '2,20p' "$0" | grep '^#' | sed 's/^# \?//'
60
+ exit 0 ;;
61
+ esac
62
+ done
63
+
64
+ # ---- --dismiss-local: record the dismiss and exit (no preflight run) ---------
65
+ # Writes .local.dismissed = current kitVersion to kit.config.json; the SessionStart
66
+ # notice stays silent until the kit's x.y core moves past it (issue #313).
67
+ if [[ $DISMISS_LOCAL -eq 1 ]]; then
68
+ command -v kit_config_path >/dev/null 2>&1 || . "$(dirname "$0")/../core/config-path.sh"
69
+ _kitcfg="$(kit_config_path "${TARGET:-$PWD}" 2>/dev/null || true)"
70
+ [[ -n "$_kitcfg" ]] || _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
71
+ if ! command -v jq >/dev/null 2>&1 || [[ ! -f "$_kitcfg" ]]; then
72
+ echo "kit-doctor: cannot dismiss — need jq + $_kitcfg" >&2
73
+ exit 1
74
+ fi
75
+ _kv="$(jq -r '.kitVersion // "0.0.0"' "$_kitcfg")"
76
+ _tmp="$(mktemp)"
77
+ jq --arg v "$_kv" '.local.dismissed = $v' "$_kitcfg" > "$_tmp" && mv "$_tmp" "$_kitcfg"
78
+ echo "local layer notice dismissed (kit $_kv) — reappears on the next x.y kit update"
79
+ echo "re-enable earlier: remove .local.dismissed from .claude/kit.config.json"
80
+ exit 0
81
+ fi
82
+
83
+ # ---- color/unicode detection (matches kit-sigil.sh pattern) -----------------
84
+ _loc="${LC_ALL:-${LC_CTYPE:-${LANG:-}}}"
85
+ if [ "${KIT_ASCII:-}" = "1" ]; then KIT_UNICODE=0
86
+ elif grep -qiE 'utf-?8' <<<"$_loc"; then KIT_UNICODE=1
87
+ else KIT_UNICODE=0; fi
88
+
89
+ if [ "${FORCE_COLOR:-}" = "1" ]; then KIT_COLOR=1
90
+ elif [ -t 1 ] && [ -z "${NO_COLOR+x}" ]; then KIT_COLOR=1
91
+ else KIT_COLOR=0; fi
92
+
93
+ if [ "$KIT_COLOR" = 1 ]; then
94
+ C_AZAFRAN=$'\033[38;2;201;122;44m'
95
+ C_SUCCESS=$'\033[38;2;21;128;61m'
96
+ C_FAIL=$'\033[38;2;192;50;43m'
97
+ C_WARN=$'\033[38;2;180;83;9m'
98
+ C_DIM=$'\033[2m'
99
+ C_BOLD=$'\033[1m'
100
+ C_RESET=$'\033[0m'
101
+ else
102
+ C_AZAFRAN=''; C_SUCCESS=''; C_FAIL=''; C_WARN=''; C_DIM=''; C_BOLD=''; C_RESET=''
103
+ fi
104
+
105
+ if [ "$KIT_UNICODE" = 1 ]; then
106
+ MARK_OK="${C_SUCCESS}✓${C_RESET}"
107
+ MARK_FAIL="${C_FAIL}✗${C_RESET}"
108
+ MARK_WARN="${C_WARN}!${C_RESET}"
109
+ MARK_SKIP="${C_DIM}-${C_RESET}"
110
+ MARK_SEED="${C_AZAFRAN}⡶${C_RESET}"
111
+ else
112
+ MARK_OK="ok"; MARK_FAIL="FAIL"; MARK_WARN="warn"; MARK_SKIP="-"; MARK_SEED="o"
113
+ fi
114
+
115
+ # ---- install consent --------------------------------------------------------
116
+ # The doctor can install missing dependencies for you (Homebrew, gh, jq, node, …). When a HUMAN runs
117
+ # it in a terminal, ASK first — install only if approved. A non-interactive caller that wants
118
+ # installs passes --fix/--yes (init.sh's preflight does). A run with no terminal and no --fix has
119
+ # nobody to ask, so it is report-only: no package install, no `pnpm install`, no seeded or refreshed
120
+ # file, no server start (#448 — it used to run `pnpm install` in whatever directory it was called
121
+ # from). --dry-run / --no-install already skip installs entirely. MAY_INSTALL is the one gate every
122
+ # install or write below reads.
123
+ if [[ $DRY_RUN -eq 0 && $NO_INSTALL -eq 0 && $ASSUME_YES -eq 0 && $AGENTS_ONLY -eq 0 && $LOOSE_ONLY -eq 0 && -t 0 ]]; then
124
+ printf '\n %s%scckit doctor can install anything missing for you%s (via Homebrew, corepack, etc.).\n' "$C_BOLD" "" "$C_RESET"
125
+ printf ' It will show each thing as it goes. Nothing is installed if you decline.\n\n'
126
+ printf ' Install missing dependencies? [Y/n] '
127
+ read -r _reply || _reply=""
128
+ case "$_reply" in
129
+ [nN]|[nN][oO])
130
+ NO_INSTALL=1
131
+ printf '\n %s report-only — listing what is missing and how to install it (no changes made).\n' "$MARK_SKIP" ;;
132
+ *) INSTALL_APPROVED=1 ;; # default (Enter / y) → proceed with installs
133
+ esac
134
+ fi
135
+ MAY_INSTALL=0; UNAPPROVED=0
136
+ if [[ $DRY_RUN -eq 0 && $NO_INSTALL -eq 0 ]]; then
137
+ if [[ $INSTALL_APPROVED -eq 1 ]]; then MAY_INSTALL=1; else UNAPPROVED=1; fi
138
+ fi
139
+
140
+ # ---- report accumulators ----------------------------------------------------
141
+ CHECKS_OK=0; CHECKS_FAIL=0; CHECKS_WARN=0
142
+ ACTIONS_TAKEN=() # things the doctor installed/fixed
143
+ ACTIONS_NEEDED=() # things the user must do manually
144
+
145
+ row() { # <mark> <label> <detail>
146
+ printf ' %-3s %-28s %s\n' "$1" "$2" "${3:-}"
147
+ }
148
+
149
+ # ---- macOS detection --------------------------------------------------------
150
+ IS_MACOS=0
151
+ [[ "$(uname -s 2>/dev/null)" == "Darwin" ]] && IS_MACOS=1
152
+
153
+ # ---- helpers ----------------------------------------------------------------
154
+ has_cmd() { command -v "$1" >/dev/null 2>&1; }
155
+
156
+ # brew_install <pkg> [<cmd-to-check>] — install via brew unless dry-run/no-install
157
+ # Returns 0 if the command is now available, 1 if not.
158
+ brew_install() {
159
+ local pkg="$1" cmd="${2:-$1}"
160
+ if [[ $MAY_INSTALL -eq 0 ]]; then
161
+ return 1
162
+ fi
163
+ if ! has_cmd brew; then return 1; fi
164
+ brew install "$pkg" >/dev/null 2>&1 && has_cmd "$cmd"
165
+ }
166
+
167
+ # ---- agent runtimes (E257.3) ------------------------------------------------
168
+ # One row per adapter the project SELECTED (`adapters` in its config; a config without the key means
169
+ # claude). An adapter whose CLI is not on PATH is installed but cannot run, so it is a warning and a
170
+ # manual action — the doctor never installs an agent CLI. Sets AGENTS_ABSENT to the count.
171
+ AGENTS_ABSENT=0
172
+ doctor_agents() {
173
+ local _d _sel _name _state _ver _tab
174
+ _d="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
175
+ command -v kit_config_path >/dev/null 2>&1 || . "$_d/../core/config-path.sh"
176
+ command -v adapter_runtime_report >/dev/null 2>&1 || . "$_d/../core/adapter-select.sh"
177
+ _tab="$(printf '\t')"
178
+ if ! _sel="$(adapter_project_list "${TARGET:-$PWD}" 2>/dev/null)"; then
179
+ row "$MARK_FAIL" "adapters" "the config's 'adapters' value is invalid (expected claude and/or codex)"
180
+ CHECKS_FAIL=$((CHECKS_FAIL + 1)); AGENTS_ABSENT=$((AGENTS_ABSENT + 1))
181
+ return 0
182
+ fi
183
+ while IFS="$_tab" read -r _name _state _ver; do
184
+ [[ -n "$_name" ]] || continue
185
+ if [[ "$_state" == "present" ]]; then
186
+ row "$MARK_OK" "$_name" "$_ver"
187
+ CHECKS_OK=$((CHECKS_OK + 1))
188
+ else
189
+ row "$MARK_WARN" "$_name" "absent — the $_name adapter is selected but its CLI is not on PATH"
190
+ CHECKS_WARN=$((CHECKS_WARN + 1)); AGENTS_ABSENT=$((AGENTS_ABSENT + 1))
191
+ ACTIONS_NEEDED+=("Install the $_name CLI (the project selects the $_name adapter)")
192
+ fi
193
+ done <<EOF_AGENTS
194
+ $(adapter_runtime_report "$_sel")
195
+ EOF_AGENTS
196
+ # Codex runs a project's hooks from .codex/hooks.json, and only after the user trusted them. The
197
+ # registration is checkable; the trust is Codex's own per-machine state and is not readable here,
198
+ # so a registered row says so instead of claiming the hooks run (E257.5).
199
+ if adapter_has "$_sel" codex; then
200
+ local _root
201
+ command -v codex_hooks_registered >/dev/null 2>&1 || . "$_d/../core/codex-hooks.sh"
202
+ _root="$(git -C "${TARGET:-$PWD}" rev-parse --show-toplevel 2>/dev/null)"
203
+ [[ -n "$_root" ]] || _root="${TARGET:-$PWD}"
204
+ if codex_hooks_registered "$_root/.codex/hooks.json" guard-base-branch-commit.sh \
205
+ && codex_hooks_registered "$_root/.codex/hooks.json" kit-mail-check.sh; then
206
+ row "$MARK_OK" "codex hooks" "registered in .codex/hooks.json — Codex runs them once trusted (/hooks in Codex; trust is not readable from here)"
207
+ CHECKS_OK=$((CHECKS_OK + 1))
208
+ else
209
+ row "$MARK_WARN" "codex hooks" "not registered in .codex/hooks.json — the commit guard and session mail do not run in Codex"
210
+ CHECKS_WARN=$((CHECKS_WARN + 1))
211
+ ACTIONS_NEEDED+=("Run cckit init --upgrade to register the Codex hooks in .codex/hooks.json")
212
+ fi
213
+ fi
214
+ }
215
+
216
+ # ---- --agents: only the runtime rows, then exit (no installs, no network) ----
217
+ if [[ $AGENTS_ONLY -eq 1 ]]; then
218
+ printf ' %s%sAgent runtimes%s\n' "$C_BOLD" "" "$C_RESET"
219
+ doctor_agents
220
+ [[ $AGENTS_ABSENT -eq 0 ]] || exit 1
221
+ exit 0
222
+ fi
223
+
224
+ # ---- loose issues (E546.2) ---------------------------------------------------
225
+ # A loose issue is open, not a pull request, not an effort, not a sub-issue, and not on the board
226
+ # with Status = Backlog (lib/core/loose-issues.sh). One row with the count; `list` adds one
227
+ # `#N title` line per issue. Sets LOOSE_STATE (read | skipped | failed) and LOOSE_COUNT. Read-only.
228
+ LOOSE_STATE=skipped; LOOSE_COUNT=""
229
+ doctor_loose() {
230
+ local _want_list="${1:-}" _cfg _repo _out _n _why
231
+ command -v loose_issues_list >/dev/null 2>&1 || . "$_export_dir_doctor/../core/loose-issues.sh"
232
+ _cfg="$(kit_config_path "${TARGET:-$PWD}" 2>/dev/null || true)"
233
+ if ! forge_available; then
234
+ row "$MARK_SKIP" "loose issues" "skipped — no forge, so the open issues cannot be read (export GH_TOKEN=<token>)"
235
+ return 0
236
+ fi
237
+ if ! _repo="$(loose_repo "$_cfg")"; then
238
+ row "$MARK_SKIP" "loose issues" "skipped — no repository (set github.repo, or add a GitHub origin remote)"
239
+ return 0
240
+ fi
241
+ if ! _out="$(loose_issues_list "$_repo" "$_cfg" 2>/dev/null)"; then
242
+ row "$MARK_FAIL" "loose issues" "could not read the open issues of $_repo"
243
+ CHECKS_FAIL=$((CHECKS_FAIL + 1)); LOOSE_STATE=failed
244
+ return 0
245
+ fi
246
+ _n="$(printf '%s' "$_out" | grep -c . || true)"
247
+ LOOSE_STATE=read; LOOSE_COUNT="$_n"
248
+ if loose_board_on "$_cfg"; then
249
+ _why="open issues that are no effort, no sub-issue, and not in Backlog on the board"
250
+ else
251
+ _why="the board is off (projectsV2 false), so no issue can carry the Backlog marker and every standalone issue counts"
252
+ fi
253
+ if [[ "$_n" -eq 0 ]]; then
254
+ row "$MARK_OK" "loose issues" "0 in $_repo — $_why"
255
+ CHECKS_OK=$((CHECKS_OK + 1))
256
+ else
257
+ row "$MARK_WARN" "loose issues" "$_n in $_repo — $_why. List them: cckit doctor --loose"
258
+ CHECKS_WARN=$((CHECKS_WARN + 1))
259
+ fi
260
+ if [[ "$_want_list" == list && -n "$_out" ]]; then
261
+ printf '%s\n' "$_out" | while IFS="$(printf '\t')" read -r _ln _lt; do
262
+ printf ' #%s %s\n' "$_ln" "$_lt"
263
+ done
264
+ fi
265
+ return 0
266
+ }
267
+
268
+ # ---- --loose [--ratchet]: only the loose-issue rows, then exit (no installs) -----
269
+ # --ratchet compares the count with the baseline file: exit 1 when it rose, 2 when it could not be
270
+ # judged (no forge, no repository, a failed read, no baseline). Not part of lib/core/check.sh: the
271
+ # gate stays offline. Run it by hand or in a job that has a token: cckit doctor --loose --ratchet
272
+ if [[ $LOOSE_ONLY -eq 1 ]]; then
273
+ printf ' %s%sLoose issues%s\n' "$C_BOLD" "" "$C_RESET"
274
+ doctor_loose list
275
+ if [[ $LOOSE_RATCHET -eq 1 ]]; then
276
+ if [[ -z "$LOOSE_BASELINE" ]]; then
277
+ _lroot="$(git -C "${TARGET:-$PWD}" rev-parse --show-toplevel 2>/dev/null || printf '%s' "${TARGET:-$PWD}")"
278
+ LOOSE_BASELINE="$_lroot/scripts/loose-issues.baseline"
279
+ fi
280
+ if [[ "$LOOSE_STATE" != read ]]; then
281
+ row "$MARK_FAIL" "loose ratchet" "not judged — the count was not read"
282
+ exit 2
283
+ fi
284
+ _lbase="$(loose_baseline_read "$LOOSE_BASELINE" || true)"
285
+ if [[ -z "$_lbase" ]]; then
286
+ row "$MARK_FAIL" "loose ratchet" "not judged — no number in $LOOSE_BASELINE"
287
+ exit 2
288
+ fi
289
+ if [[ "$LOOSE_COUNT" -gt "$_lbase" ]]; then
290
+ row "$MARK_FAIL" "loose ratchet" "$LOOSE_COUNT loose > baseline $_lbase — put each new one under an effort, as a sub-issue, or in Backlog"
291
+ exit 1
292
+ elif [[ "$LOOSE_COUNT" -lt "$_lbase" ]]; then
293
+ row "$MARK_OK" "loose ratchet" "$LOOSE_COUNT loose < baseline $_lbase — lower the number in $LOOSE_BASELINE to $LOOSE_COUNT"
294
+ else
295
+ row "$MARK_OK" "loose ratchet" "$LOOSE_COUNT loose = baseline $_lbase"
296
+ fi
297
+ exit 0
298
+ fi
299
+ [[ "$LOOSE_STATE" == failed ]] && exit 1
300
+ exit 0
301
+ fi
302
+
303
+ # ============================================================================
304
+ # BANNER
305
+ # ============================================================================
306
+ printf '\n'
307
+ printf ' %s%s%s kit-doctor\n' "$MARK_SEED" "$C_BOLD" " / claude-kit${C_RESET}"
308
+ printf ' %s\n' "${C_DIM}onboarding preflight${C_RESET}${DRY_RUN:+${C_WARN} [dry-run]${C_RESET}}${NO_INSTALL:+${C_DIM} [no-install]${C_RESET}}"
309
+ [[ $UNAPPROVED -eq 1 && $AGENTS_ONLY -eq 0 ]] && printf ' %s report-only — no terminal and no --fix, so nothing is installed and no file is written. To install: cckit doctor --fix\n' "$MARK_SKIP"
310
+ printf '\n'
311
+
312
+ # ============================================================================
313
+ # TIER 0 — Homebrew bootstrap (macOS only)
314
+ # ============================================================================
315
+ printf ' %s%sTier 0 — bootstrap%s\n' "$C_BOLD" "" "$C_RESET"
316
+
317
+ if [[ $IS_MACOS -eq 0 ]]; then
318
+ row "$MARK_SKIP" "Homebrew" "not macOS — skipping"
319
+ elif has_cmd brew; then
320
+ row "$MARK_OK" "Homebrew" "$(brew --version 2>/dev/null | sed -n 1p)"
321
+ CHECKS_OK=$((CHECKS_OK + 1))
322
+ else
323
+ if [[ $MAY_INSTALL -eq 0 ]]; then
324
+ row "$MARK_FAIL" "Homebrew" "missing — install: https://brew.sh"
325
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
326
+ ACTIONS_NEEDED+=("Install Homebrew: https://brew.sh")
327
+ else
328
+ printf '\n'
329
+ printf ' %s Homebrew not found — running the official installer (will ask for sudo password)...\n' "$MARK_WARN"
330
+ printf ' %sInstaller URL: https://brew.sh%s\n\n' "$C_DIM" "$C_RESET"
331
+ if /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; then
332
+ # Add brew to PATH for the rest of this session (Apple Silicon path)
333
+ [[ -f /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)" 2>/dev/null || true
334
+ [[ -f /usr/local/bin/brew ]] && eval "$(/usr/local/bin/brew shellenv)" 2>/dev/null || true
335
+ row "$MARK_OK" "Homebrew" "installed $(brew --version 2>/dev/null | sed -n 1p)"
336
+ CHECKS_OK=$((CHECKS_OK + 1))
337
+ ACTIONS_TAKEN+=("Installed Homebrew")
338
+ else
339
+ row "$MARK_FAIL" "Homebrew" "install failed — see https://brew.sh"
340
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
341
+ ACTIONS_NEEDED+=("Manually install Homebrew: https://brew.sh")
342
+ fi
343
+ fi
344
+ fi
345
+ printf '\n'
346
+
347
+ # ============================================================================
348
+ # TIER 1 — hard deps
349
+ # ============================================================================
350
+ printf ' %s%sTier 1 — hard deps%s\n' "$C_BOLD" "" "$C_RESET"
351
+
352
+ # ---- git -------------------------------------------------------------------
353
+ if has_cmd git; then
354
+ _gitver="$(git --version 2>/dev/null | awk '{print $3}')"
355
+ row "$MARK_OK" "git" "$_gitver"
356
+ CHECKS_OK=$((CHECKS_OK + 1))
357
+ elif brew_install git; then
358
+ row "$MARK_OK" "git" "installed $(git --version 2>/dev/null | awk '{print $3}')"
359
+ CHECKS_OK=$((CHECKS_OK + 1))
360
+ ACTIONS_TAKEN+=("Installed git via brew")
361
+ else
362
+ row "$MARK_FAIL" "git" "missing — brew install git"
363
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
364
+ ACTIONS_NEEDED+=("Install git: brew install git")
365
+ fi
366
+
367
+ # ---- gh (OPTIONAL: the interactive way to get a token; the forge itself is REST over curl) ----
368
+ GH_OK=0
369
+ if forge_cli_present; then
370
+ _ghver="$(forge_cli_version)"
371
+ row "$MARK_OK" "gh (optional)" "${_ghver:-present} — its token is used when GH_TOKEN is unset"
372
+ CHECKS_OK=$((CHECKS_OK + 1))
373
+ GH_OK=1
374
+ else
375
+ row "$MARK_SKIP" "gh (optional)" "not installed — a GH_TOKEN works without it; install it for an interactive sign-in"
376
+ fi
377
+
378
+ # ---- jq -------------------------------------------------------------------
379
+ if has_cmd jq; then
380
+ row "$MARK_OK" "jq" "$(jq --version 2>/dev/null)"
381
+ CHECKS_OK=$((CHECKS_OK + 1))
382
+ elif brew_install jq; then
383
+ row "$MARK_OK" "jq" "installed $(jq --version 2>/dev/null)"
384
+ CHECKS_OK=$((CHECKS_OK + 1))
385
+ ACTIONS_TAKEN+=("Installed jq via brew")
386
+ else
387
+ row "$MARK_FAIL" "jq" "missing — brew install jq"
388
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
389
+ ACTIONS_NEEDED+=("Install jq: brew install jq")
390
+ fi
391
+
392
+ # ---- curl (the forge is REST over curl) -------------------------------------
393
+ if has_cmd curl; then
394
+ row "$MARK_OK" "curl" "$(curl --version 2>/dev/null | sed -n 1p | awk '{print $2}')"
395
+ CHECKS_OK=$((CHECKS_OK + 1))
396
+ elif brew_install curl; then
397
+ row "$MARK_OK" "curl" "installed"
398
+ CHECKS_OK=$((CHECKS_OK + 1))
399
+ ACTIONS_TAKEN+=("Installed curl via brew")
400
+ else
401
+ row "$MARK_FAIL" "curl" "missing — brew install curl (every GitHub call is REST over curl)"
402
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
403
+ ACTIONS_NEEDED+=("Install curl: brew install curl")
404
+ fi
405
+
406
+ # ---- perl -----------------------------------------------------------------
407
+ if has_cmd perl; then
408
+ row "$MARK_OK" "perl" "$(perl --version 2>/dev/null | sed -n 1,2p | tail -1 | tr -d '()' | awk '{print $2}')"
409
+ CHECKS_OK=$((CHECKS_OK + 1))
410
+ elif brew_install perl; then
411
+ row "$MARK_OK" "perl" "installed"
412
+ CHECKS_OK=$((CHECKS_OK + 1))
413
+ ACTIONS_TAKEN+=("Installed perl via brew")
414
+ else
415
+ row "$MARK_FAIL" "perl" "missing — brew install perl"
416
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
417
+ ACTIONS_NEEDED+=("Install perl: brew install perl")
418
+ fi
419
+ printf '\n'
420
+
421
+ # ============================================================================
422
+ # TIER 2 — project deps (context-aware)
423
+ # ============================================================================
424
+ printf ' %s%sTier 2 — project deps%s\n' "$C_BOLD" "" "$C_RESET"
425
+
426
+ # ---- node + pnpm (check package.json for pinned version) -------------------
427
+ _pkg_json="${TARGET:-$PWD}/package.json"
428
+ _pkg_mgr=""
429
+ [[ -f "$_pkg_json" ]] && _pkg_mgr="$(jq -r '.packageManager // ""' "$_pkg_json" 2>/dev/null || true)"
430
+
431
+ if has_cmd node; then
432
+ row "$MARK_OK" "node" "$(node --version 2>/dev/null)"
433
+ CHECKS_OK=$((CHECKS_OK + 1))
434
+ elif brew_install node; then
435
+ row "$MARK_OK" "node" "installed $(node --version 2>/dev/null)"
436
+ CHECKS_OK=$((CHECKS_OK + 1))
437
+ ACTIONS_TAKEN+=("Installed node via brew")
438
+ else
439
+ row "$MARK_FAIL" "node" "missing — brew install node"
440
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
441
+ ACTIONS_NEEDED+=("Install node: brew install node")
442
+ fi
443
+
444
+ if has_cmd pnpm; then
445
+ row "$MARK_OK" "pnpm" "$(pnpm --version 2>/dev/null)"
446
+ CHECKS_OK=$((CHECKS_OK + 1))
447
+ elif [[ -n "$_pkg_mgr" && "$_pkg_mgr" == pnpm* ]]; then
448
+ # Pinned in package.json — enable via corepack
449
+ if has_cmd corepack || has_cmd node; then
450
+ if [[ $MAY_INSTALL -eq 1 ]]; then
451
+ corepack enable pnpm 2>/dev/null && \
452
+ corepack prepare "$_pkg_mgr" --activate 2>/dev/null && \
453
+ ACTIONS_TAKEN+=("Enabled pnpm via corepack ($_pkg_mgr)") || true
454
+ fi
455
+ if has_cmd pnpm; then
456
+ row "$MARK_OK" "pnpm" "$(pnpm --version 2>/dev/null) (via corepack)"
457
+ CHECKS_OK=$((CHECKS_OK + 1))
458
+ else
459
+ row "$MARK_FAIL" "pnpm" "missing — corepack enable pnpm"
460
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
461
+ ACTIONS_NEEDED+=("Enable pnpm: corepack enable pnpm && corepack prepare $_pkg_mgr --activate")
462
+ fi
463
+ else
464
+ row "$MARK_FAIL" "pnpm" "missing — npm install -g pnpm"
465
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
466
+ ACTIONS_NEEDED+=("Install pnpm: npm install -g pnpm")
467
+ fi
468
+ elif brew_install pnpm; then
469
+ row "$MARK_OK" "pnpm" "installed $(pnpm --version 2>/dev/null)"
470
+ CHECKS_OK=$((CHECKS_OK + 1))
471
+ ACTIONS_TAKEN+=("Installed pnpm via brew")
472
+ else
473
+ row "$MARK_WARN" "pnpm" "not found (needed for turbo monorepo)"
474
+ CHECKS_WARN=$((CHECKS_WARN + 1))
475
+ ACTIONS_NEEDED+=("Install pnpm: brew install pnpm")
476
+ fi
477
+
478
+ # ---- node_modules (check if pnpm install needed) ----------------------------
479
+ _nm="${TARGET:-$PWD}/node_modules"
480
+ if [[ -d "$_nm" ]]; then
481
+ row "$MARK_OK" "node_modules" "present"
482
+ CHECKS_OK=$((CHECKS_OK + 1))
483
+ elif [[ -f "$_pkg_json" ]]; then
484
+ if [[ $MAY_INSTALL -eq 1 ]] && has_cmd pnpm; then
485
+ printf '\n %s node_modules missing — running pnpm install...\n' "$MARK_WARN"
486
+ if pnpm install --frozen-lockfile 2>/dev/null || pnpm install; then
487
+ row "$MARK_OK" "node_modules" "installed via pnpm install"
488
+ CHECKS_OK=$((CHECKS_OK + 1))
489
+ ACTIONS_TAKEN+=("Ran pnpm install")
490
+ else
491
+ row "$MARK_FAIL" "node_modules" "pnpm install failed — run manually"
492
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
493
+ ACTIONS_NEEDED+=("Run pnpm install")
494
+ fi
495
+ else
496
+ row "$MARK_WARN" "node_modules" "missing — run pnpm install"
497
+ CHECKS_WARN=$((CHECKS_WARN + 1))
498
+ ACTIONS_NEEDED+=("Run pnpm install")
499
+ fi
500
+ else
501
+ row "$MARK_SKIP" "node_modules" "no package.json found — skipping"
502
+ fi
503
+
504
+ # ---- vercel (only if .vercel/ linked or VERCEL env) -------------------------
505
+ _has_vercel_link=0
506
+ [[ -d "${TARGET:-$PWD}/.vercel" ]] && _has_vercel_link=1
507
+
508
+ if [[ $_has_vercel_link -eq 1 ]] || [[ -n "${VERCEL:-}" ]]; then
509
+ if has_cmd vercel; then
510
+ row "$MARK_OK" "vercel" "$(vercel --version 2>/dev/null | sed -n 1p)"
511
+ CHECKS_OK=$((CHECKS_OK + 1))
512
+ elif brew_install vercel vercel; then
513
+ row "$MARK_OK" "vercel" "installed $(vercel --version 2>/dev/null | sed -n 1p)"
514
+ CHECKS_OK=$((CHECKS_OK + 1))
515
+ ACTIONS_TAKEN+=("Installed vercel CLI via brew")
516
+ elif [[ $MAY_INSTALL -eq 1 ]] && has_cmd npm; then
517
+ npm install -g vercel >/dev/null 2>&1 && \
518
+ ACTIONS_TAKEN+=("Installed vercel CLI via npm") || true
519
+ if has_cmd vercel; then
520
+ row "$MARK_OK" "vercel" "installed $(vercel --version 2>/dev/null | sed -n 1p)"
521
+ CHECKS_OK=$((CHECKS_OK + 1))
522
+ else
523
+ row "$MARK_FAIL" "vercel" "missing — npm install -g vercel"
524
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
525
+ ACTIONS_NEEDED+=("Install vercel: npm install -g vercel")
526
+ fi
527
+ else
528
+ row "$MARK_FAIL" "vercel" "missing — npm install -g vercel"
529
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
530
+ ACTIONS_NEEDED+=("Install vercel: npm install -g vercel")
531
+ fi
532
+ else
533
+ row "$MARK_SKIP" "vercel" "no .vercel/ project link — skipping"
534
+ fi
535
+
536
+ # turbo + playwright: dev deps only — never global; check node_modules
537
+ if [[ -d "$_nm" ]]; then
538
+ if [[ -x "$_nm/.bin/turbo" ]]; then
539
+ row "$MARK_OK" "turbo" "dev dep present"
540
+ CHECKS_OK=$((CHECKS_OK + 1))
541
+ else
542
+ row "$MARK_SKIP" "turbo" "not in node_modules (run pnpm install)"
543
+ fi
544
+ if [[ -x "$_nm/.bin/playwright" ]]; then
545
+ row "$MARK_OK" "playwright" "dev dep present"
546
+ CHECKS_OK=$((CHECKS_OK + 1))
547
+ else
548
+ row "$MARK_SKIP" "playwright" "not in node_modules (run pnpm install)"
549
+ fi
550
+ fi
551
+ printf '\n'
552
+
553
+ # ============================================================================
554
+ # AGENT RUNTIMES — the CLI of each selected adapter
555
+ # ============================================================================
556
+ printf ' %s%sAgent runtimes%s\n' "$C_BOLD" "" "$C_RESET"
557
+ doctor_agents
558
+ printf '\n'
559
+
560
+ # ============================================================================
561
+ # INTEGRATIONS (opt-in — one row per descriptor in kit/integrations/ the project switched on)
562
+ # ============================================================================
563
+ # An optional third-party tool is DATA: kit/integrations/<id>.json names its config key, its detect
564
+ # command and its install candidates in order. This loop holds no tool's recipe. For every
565
+ # descriptor whose config key is on it asks the shared runner (lib/integration-install.sh) and
566
+ # turns the runner's one status line into a row. Silent when the project switched nothing on.
567
+ #
568
+ # The runner installs only with consent recorded in .cckit/consent (`install:<id>`). The operator
569
+ # saying yes to installs in THIS run — --fix/--yes, or the terminal prompt above — is that consent,
570
+ # and is recorded here, so init's `--yes` preflight keeps installing. A run nobody approved (no
571
+ # TTY, no --fix) reports the tool missing and installs nothing. --dry-run / --no-install run the
572
+ # runner under KIT_DRY_RUN: it plans, and neither installs nor records anything.
573
+ command -v kit_config_path >/dev/null 2>&1 || . "$(dirname "$0")/../core/config-path.sh"
574
+ _kitcfg="$(kit_config_path "${TARGET:-$PWD}" 2>/dev/null || true)"
575
+ [[ -n "$_kitcfg" ]] || _kitcfg="${TARGET:-$PWD}/.claude/kit.config.json"
576
+
577
+ # doctor_integration <descriptor> — one row for one enabled integration.
578
+ doctor_integration() {
579
+ local f="$1" id label recipe st bin after also
580
+ id="$(jq -r '.id' "$f")"; label="$(jq -r '.label' "$f")"
581
+ recipe="$(jq -r '.install[0].run' "$f")"
582
+ if integration_detect "$f" "$_ig_target"; then
583
+ bin="$(integration_bin "$f" || true)"
584
+ row "$MARK_OK" "$label" "installed${bin:+ ($bin)}"
585
+ CHECKS_OK=$((CHECKS_OK + 1))
586
+ return 0
587
+ fi
588
+ if ! integration_applies "$f" "$_ig_target"; then
589
+ row "$MARK_SKIP" "$label" "needs $(integration_applies_needs "$f") — skipping install"
590
+ return 0
591
+ fi
592
+ # On by default and never chosen by this project: its callers fall back without the tool, so a
593
+ # missing one is reported, does not fail the run, and is NOT installed — a yes to installs covers
594
+ # what the project switched on. `cckit add <id>` writes the key, and then the rows below apply.
595
+ if integration_default_on "$f" && ! integration_explicit "$f" "$_kitcfg"; then
596
+ row "$MARK_SKIP" "$label" "not installed — on by default, falls back without it. By hand: $recipe (or 'cckit add $id', then 'cckit doctor --fix')"
597
+ return 0
598
+ fi
599
+ if [[ $DRY_RUN -eq 1 || $NO_INSTALL -eq 1 ]]; then
600
+ st="$(KIT_DRY_RUN=1 integration_install "$f" "$_ig_target" 2>/dev/null || true)"
601
+ else
602
+ if [[ $INSTALL_APPROVED -eq 1 ]]; then integration_consent_record "$id" "$_ig_target" || true; fi
603
+ st="$(integration_install "$f" "$_ig_target" || true)"
604
+ fi
605
+ case "$st" in
606
+ present|installed\ *)
607
+ bin="$(integration_bin "$f" || true)"
608
+ if [[ "$st" == present ]]; then
609
+ row "$MARK_OK" "$label" "installed${bin:+ ($bin)}"
610
+ else
611
+ after="$(jq -r '.afterInstall // ""' "$f")"
612
+ # What the installer writes besides the file `detect` checks (descriptor: alsoWrites).
613
+ also="$(jq -r '(.alsoWrites // []) | join(", ")' "$f")"
614
+ row "$MARK_OK" "$label" "installed via ${st#installed }${bin:+ ($bin)}${also:+ — it also wrote: $also}"
615
+ ACTIONS_TAKEN+=("Installed $label via ${st#installed }${also:+ — it also wrote: $also}${after:+ — $after}")
616
+ fi
617
+ CHECKS_OK=$((CHECKS_OK + 1)) ;;
618
+ dry-run)
619
+ row "$MARK_FAIL" "$label" "missing — $recipe"
620
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
621
+ ACTIONS_NEEDED+=("Install $label: $recipe") ;;
622
+ no-consent)
623
+ row "$MARK_FAIL" "$label" "missing — nothing installs without your yes: cckit doctor --fix"
624
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
625
+ ACTIONS_NEEDED+=("Install $label: cckit doctor --fix (or by hand: $recipe)") ;;
626
+ *)
627
+ row "$MARK_FAIL" "$label" "install failed — $recipe"
628
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
629
+ ACTIONS_NEEDED+=("Install $label: $recipe") ;;
630
+ esac
631
+ }
632
+
633
+ _ig_target="${TARGET:-$PWD}"
634
+ if has_cmd jq && [[ -f "$_kitcfg" ]]; then
635
+ # shellcheck source=/dev/null
636
+ . "$_export_dir_doctor/../core/integration-install.sh"
637
+ _ig_shown=0
638
+ for _ig_id in $(integrations_list); do
639
+ _ig_f="$(integration_file "$_ig_id")" || continue
640
+ integration_enabled "$_ig_f" "$_kitcfg" || continue
641
+ if [[ $_ig_shown -eq 0 ]]; then
642
+ printf ' %s%sIntegrations (optional tools that are on in this project)%s\n' "$C_BOLD" "" "$C_RESET"
643
+ _ig_shown=1
644
+ fi
645
+ doctor_integration "$_ig_f"
646
+ done
647
+ if [[ $_ig_shown -eq 1 ]]; then printf '\n'; fi
648
+ fi
649
+
650
+ # ============================================================================
651
+ # PAGE-DESIGN SKILL (only checked when tasks.design is true)
652
+ # ============================================================================
653
+ # `tasks.design: true` makes every task of the project a page task, and a page task tells the agent
654
+ # to load cckit's `page-design` skill. The key alone installs nothing: a project already at the
655
+ # installed version gets no file from `cckit init --upgrade`. One row per selected adapter says
656
+ # whether the skill is in its skills folder, and a missing one names the command that copies it.
657
+ if has_cmd jq && [[ -f "$_kitcfg" ]] && [[ "$(jq -r '.tasks.design // false' "$_kitcfg" 2>/dev/null)" == "true" ]]; then
658
+ command -v adapter_list_from_config >/dev/null 2>&1 || . "$_export_dir_doctor/../core/adapter-select.sh"
659
+ printf ' %s%sPage tasks (tasks.design is on)%s\n' "$C_BOLD" "" "$C_RESET"
660
+ _pd_root="$(dirname "$_kitcfg")"
661
+ [[ "$(basename "$_pd_root")" == ".claude" ]] && _pd_root="$(dirname "$_pd_root")"
662
+ for _pd_a in $(adapter_list_from_config "$_kitcfg" 2>/dev/null || echo claude); do
663
+ _pd_dir="$(adapter_dir "$_pd_a")/skills/page-design"
664
+ if [[ -f "$_pd_root/$_pd_dir/SKILL.md" ]]; then
665
+ row "$MARK_OK" "page-design skill" "$_pd_dir"
666
+ CHECKS_OK=$((CHECKS_OK + 1))
667
+ else
668
+ row "$MARK_FAIL" "page-design skill" "missing from $_pd_dir — run: cckit add page-design"
669
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
670
+ ACTIONS_NEEDED+=("Add the page-design skill ($_pd_dir): cckit add page-design")
671
+ fi
672
+ done
673
+ printf '\n'
674
+ fi
675
+
676
+ # ============================================================================
677
+ # LOCAL MODEL LAYER (opt-in — only checked when .local.enabled is true)
678
+ # ============================================================================
679
+ # Same gating principle as vercel: silence when the project didn't opt in. The runtime itself is
680
+ # an integration (kit/integrations/mlx-lm.json) and was handled by the loop above; this section is the
681
+ # part that is not an install — the server. When the runtime is present but the server is down,
682
+ # the doctor starts it in background + health-checks the port. --dry-run stays 100% read-only: it
683
+ # reports what it would do and starts nothing.
684
+ _local_on="false"
685
+ [[ -f "$_kitcfg" ]] && _local_on="$(jq -r '.local.enabled // false' "$_kitcfg" 2>/dev/null || echo false)"
686
+ if [[ "$_local_on" == "true" ]]; then
687
+ printf ' %s%sLocal model layer (mlx_lm.server)%s\n' "$C_BOLD" "" "$C_RESET"
688
+ _lport="$(jq -r '.local.port // 8080' "$_kitcfg" 2>/dev/null || echo 8080)"
689
+ _lmodel="$(jq -r '.local.model // "mlx-community/Qwen3-8B-4bit"' "$_kitcfg" 2>/dev/null || echo "mlx-community/Qwen3-8B-4bit")"
690
+
691
+ # Apple silicon — MLX requirement (the descriptor's appliesWhen.platform gates the install)
692
+ if [[ $IS_MACOS -eq 1 && "$(uname -m 2>/dev/null)" == "arm64" ]]; then
693
+ row "$MARK_OK" "apple silicon" "$(sysctl -n machdep.cpu.brand_string 2>/dev/null || echo arm64)"
694
+ CHECKS_OK=$((CHECKS_OK + 1))
695
+ else
696
+ row "$MARK_WARN" "apple silicon" "MLX needs an Apple silicon Mac — local layer will stay dormant here"
697
+ CHECKS_WARN=$((CHECKS_WARN + 1))
698
+ fi
699
+
700
+ # the server binary — resolved through the descriptor, so ~/.local/bin is searched too
701
+ _mlx_bin="$(integration_bin "$(integration_file mlx-lm 2>/dev/null || true)" 2>/dev/null || true)"
702
+
703
+ # server alive on the configured port — auto-start when down + installed
704
+ _lurl="http://127.0.0.1:${_lport}/v1/models"
705
+ if curl -sf -m 1 "$_lurl" >/dev/null 2>&1; then
706
+ row "$MARK_OK" "server" "alive @ :${_lport} (${_lmodel##*/}) — NL chores run at \$0"
707
+ CHECKS_OK=$((CHECKS_OK + 1))
708
+ elif [[ -z "$_mlx_bin" ]]; then
709
+ row "$MARK_WARN" "server" "not running — install mlx-lm first, then re-run kit-doctor"
710
+ CHECKS_WARN=$((CHECKS_WARN + 1))
711
+ ACTIONS_NEEDED+=("Start the local model server: mlx_lm.server --model ${_lmodel} --port ${_lport}")
712
+ elif [[ $DRY_RUN -eq 1 || $UNAPPROVED -eq 1 ]]; then
713
+ row "$MARK_WARN" "server" "not running — would start mlx_lm.server in background (first run downloads ~4.5 GB)"
714
+ CHECKS_WARN=$((CHECKS_WARN + 1))
715
+ ACTIONS_NEEDED+=("Start the local model server: mlx_lm.server --model ${_lmodel} --port ${_lport}")
716
+ else
717
+ _llog="$HOME/.claude/kit-local-server.log"
718
+ mkdir -p "$HOME/.claude" 2>/dev/null || _llog="${TMPDIR:-/tmp}/kit-local-server.log"
719
+ # first-run warning: model not in the HF cache yet → server stays "loading" for a while
720
+ _hfdir="$HOME/.cache/huggingface/hub/models--${_lmodel//\//--}"
721
+ [[ -d "$_hfdir" ]] || printf ' %s first run: the model downloads now (~4.5 GB) — the server may take several minutes to come up\n' "$MARK_WARN"
722
+ printf ' %s server down — starting mlx_lm.server in background (log: %s)...\n' "$MARK_WARN" "$_llog"
723
+ nohup "$_mlx_bin" --model "$_lmodel" --port "$_lport" >>"$_llog" 2>&1 &
724
+ _mlx_pid=$!
725
+ _lup=0
726
+ for _i in $(seq 1 30); do
727
+ if curl -sf -m 1 "$_lurl" >/dev/null 2>&1; then _lup=1; break; fi
728
+ kill -0 "$_mlx_pid" 2>/dev/null || break
729
+ sleep 1
730
+ done
731
+ if [[ $_lup -eq 1 ]]; then
732
+ row "$MARK_OK" "server" "started @ :${_lport} (${_lmodel##*/}) — NL chores run at \$0"
733
+ CHECKS_OK=$((CHECKS_OK + 1))
734
+ ACTIONS_TAKEN+=("Started mlx_lm.server @ :${_lport} (pid $_mlx_pid)")
735
+ elif kill -0 "$_mlx_pid" 2>/dev/null; then
736
+ row "$MARK_WARN" "server" "starting (pid $_mlx_pid) — model still downloading/loading; check: curl :${_lport}/v1/models"
737
+ CHECKS_WARN=$((CHECKS_WARN + 1))
738
+ ACTIONS_TAKEN+=("Started mlx_lm.server (pid $_mlx_pid) — still loading, log: $_llog")
739
+ else
740
+ row "$MARK_FAIL" "server" "failed to start — see $_llog"
741
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
742
+ ACTIONS_NEEDED+=("Start the local model server manually: mlx_lm.server --model ${_lmodel} --port ${_lport} (log: $_llog)")
743
+ fi
744
+ fi
745
+ printf '\n'
746
+ fi
747
+
748
+ # ============================================================================
749
+ # AUTH + CONFIG
750
+ # ============================================================================
751
+ printf ' %s%sAuth + config%s\n' "$C_BOLD" "" "$C_RESET"
752
+
753
+ # ---- the forge (GitHub through a token) --------------------------------------
754
+ # forge.provider: github when a token resolves (GH_TOKEN, GITHUB_TOKEN, or gh's), else none. With
755
+ # none every verb that needs GitHub refuses by name and the git steps still run (lib/forge/forge.sh).
756
+ GH_AUTHED=0
757
+ _fprov="$(forge_provider 2>/dev/null || echo none)"
758
+ if [[ "$_fprov" == "none" ]]; then
759
+ if [[ $DRY_RUN -eq 0 && $MAY_INSTALL -eq 1 ]] && forge_cli_present; then
760
+ printf '\n %s no GitHub token — launching gh auth login (device flow)...\n\n' "$MARK_WARN"
761
+ if forge_login; then
762
+ unset _FORGE_LOADED; _fprov="$(forge_provider 2>/dev/null || echo none)"
763
+ ACTIONS_TAKEN+=("Signed in to GitHub through gh auth login")
764
+ fi
765
+ fi
766
+ fi
767
+ if [[ "$_fprov" == "none" ]]; then
768
+ row "$MARK_WARN" "forge" "none — git-only. Issues, pull requests and labels are unavailable until a token is set: export GH_TOKEN=<token>, or gh auth login"
769
+ CHECKS_WARN=$((CHECKS_WARN + 1))
770
+ ACTIONS_NEEDED+=("Sign in to GitHub: export GH_TOKEN=<token> (or: gh auth login)")
771
+ else
772
+ _ghuser="$(gh_rest_user_login 2>/dev/null || true)"
773
+ if [[ -n "$_ghuser" ]]; then
774
+ row "$MARK_OK" "forge" "github — signed in as @$_ghuser"
775
+ CHECKS_OK=$((CHECKS_OK + 1))
776
+ GH_AUTHED=1
777
+ else
778
+ row "$MARK_FAIL" "forge" "github — the token does not work (GH_TOKEN, GITHUB_TOKEN, or gh's). Re-issue it, or gh auth login"
779
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
780
+ ACTIONS_NEEDED+=("Fix the GitHub token: export GH_TOKEN=<token>, or gh auth login")
781
+ fi
782
+ fi
783
+
784
+ # ---- token scope: project (Projects v2 silently fails without it) ------------
785
+ GH_SCOPE_PROJECT=0
786
+ _pv2="false"; [[ -f "$_kitcfg" ]] && _pv2="$(jq -r '.github.projectsV2 // false' "$_kitcfg" 2>/dev/null || echo false)"
787
+ if [[ $GH_AUTHED -eq 1 && "$_pv2" == "true" ]]; then
788
+ _token_scopes="$(forge_token_scopes 2>/dev/null || true)"
789
+ if grep -qi 'project' <<<"$_token_scopes"; then
790
+ row "$MARK_OK" "token scope:project" "present"
791
+ CHECKS_OK=$((CHECKS_OK + 1))
792
+ GH_SCOPE_PROJECT=1
793
+ elif [[ -z "$_token_scopes" ]]; then
794
+ row "$MARK_SKIP" "token scope:project" "a fine-grained token lists no scopes — give it Projects access if the board stays empty"
795
+ elif [[ $DRY_RUN -eq 1 || $MAY_INSTALL -eq 0 ]] || ! forge_cli_present; then
796
+ row "$MARK_FAIL" "token scope:project" "missing — gh auth refresh -s project (or re-issue the token with it)"
797
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
798
+ ACTIONS_NEEDED+=("Add scope: gh auth refresh -s project")
799
+ else
800
+ printf '\n %s scope "project" missing — running gh auth refresh (will open browser)...\n\n' "$MARK_WARN"
801
+ if forge_login_scope project; then
802
+ row "$MARK_OK" "token scope:project" "added"
803
+ CHECKS_OK=$((CHECKS_OK + 1))
804
+ GH_SCOPE_PROJECT=1
805
+ ACTIONS_TAKEN+=("Added the project scope through gh auth refresh")
806
+ else
807
+ row "$MARK_FAIL" "token scope:project" "refresh failed — gh auth refresh -s project"
808
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
809
+ ACTIONS_NEEDED+=("Add scope: gh auth refresh -s project")
810
+ fi
811
+ fi
812
+ elif [[ $GH_AUTHED -eq 1 ]]; then
813
+ row "$MARK_SKIP" "token scope:project" "Projects v2 is off — not needed"
814
+ fi
815
+
816
+ # ---- git config user.name + user.email -------------------------------------
817
+ _git_name="$(git config --global user.name 2>/dev/null || true)"
818
+ if [[ -n "$_git_name" ]]; then
819
+ row "$MARK_OK" "git user.name" "$_git_name"
820
+ CHECKS_OK=$((CHECKS_OK + 1))
821
+ else
822
+ row "$MARK_FAIL" "git user.name" "not set — git config --global user.name \"Your Name\""
823
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
824
+ ACTIONS_NEEDED+=("Set git identity: git config --global user.name \"Your Name\"")
825
+ fi
826
+
827
+ _git_email="$(git config --global user.email 2>/dev/null || true)"
828
+ if [[ -n "$_git_email" ]]; then
829
+ row "$MARK_OK" "git user.email" "$_git_email"
830
+ CHECKS_OK=$((CHECKS_OK + 1))
831
+ else
832
+ row "$MARK_FAIL" "git user.email" "not set — git config --global user.email \"you@example.com\""
833
+ CHECKS_FAIL=$((CHECKS_FAIL + 1))
834
+ ACTIONS_NEEDED+=("Set git email: git config --global user.email \"you@example.com\"")
835
+ fi
836
+
837
+ # ---- base branch vs GitHub default -----------------------------------------
838
+ # `Closes #N` auto-close only fires when a PR merges into the repo's DEFAULT branch. If this
839
+ # project integrates on a non-default branch (github.baseBranch, e.g. develop) that mismatch
840
+ # silently leaves issues open on native/UI merges. cckit's own `pr-merge` closes them explicitly,
841
+ # but the misalignment still bites anyone who merges from the GitHub UI — so surface it.
842
+ if [[ $GH_AUTHED -eq 1 ]] && [[ -f "$_kitcfg" ]]; then
843
+ _cfg_repo="$(jq -r '.github.repo // empty' "$_kitcfg" 2>/dev/null || true)"
844
+ # Same fallback chain as load_kit_config (#117) so the warning judges the branch cckit actually
845
+ # integrates on: baseBranch -> integrationBranch -> flow -> "main".
846
+ _cfg_base="$(jq -r '.github.baseBranch // .github.integrationBranch // .github.flow // "main"' "$_kitcfg" 2>/dev/null || echo main)"
847
+ if [[ -n "$_cfg_repo" ]]; then
848
+ _gh_default="$(gh_rest_repo_default_branch "$_cfg_repo" 2>/dev/null || true)"
849
+ if [[ -z "$_gh_default" ]]; then
850
+ row "$MARK_SKIP" "base branch" "couldn't read GitHub default for $_cfg_repo — skipped"
851
+ elif [[ "$_cfg_base" == "$_gh_default" ]]; then
852
+ row "$MARK_OK" "base branch" "$_cfg_base = GitHub default"
853
+ CHECKS_OK=$((CHECKS_OK + 1))
854
+ else
855
+ row "$MARK_WARN" "base branch" "baseBranch '$_cfg_base' ≠ GitHub default '$_gh_default' — 'Closes #N' won't auto-close on GitHub-UI merges"
856
+ CHECKS_WARN=$((CHECKS_WARN + 1))
857
+ ACTIONS_NEEDED+=("Align base branch: make '$_cfg_base' the default branch of $_cfg_repo on GitHub (or set github.baseBranch to '$_gh_default'). Note: 'cckit merge' already closes linked issues explicitly.")
858
+ fi
859
+ fi
860
+ fi
861
+ # ---- loose issues: the count only (the list is cckit doctor --loose) --------
862
+ if [[ $GH_AUTHED -eq 1 || "$_fprov" == "none" ]]; then
863
+ doctor_loose
864
+ else
865
+ row "$MARK_SKIP" "loose issues" "skipped — the token does not work, so the open issues cannot be read"
866
+ fi
867
+ printf '\n'
868
+
869
+ # ============================================================================
870
+ # SSH (optional guided flow)
871
+ # ============================================================================
872
+ printf ' %s%sSSH (optional — HTTPS with the token is the default)%s\n' "$C_BOLD" "" "$C_RESET"
873
+
874
+ _ssh_result=0
875
+ grep -q "successfully authenticated" <<<"$(ssh -T git@github.com -o ConnectTimeout=5 -o BatchMode=yes 2>&1)" && _ssh_result=1 || true
876
+
877
+ if [[ $_ssh_result -eq 1 ]]; then
878
+ row "$MARK_OK" "SSH to github.com" "key already accepted"
879
+ CHECKS_OK=$((CHECKS_OK + 1))
880
+ else
881
+ row "$MARK_SKIP" "SSH to github.com" "no key — HTTPS with the token is used by default"
882
+
883
+ # Show guided SSH setup only if user explicitly wants SSH
884
+ if [[ "${KIT_DOCTOR_SSH:-}" == "1" && $DRY_RUN -eq 0 ]]; then
885
+ _ssh_key="$HOME/.ssh/id_ed25519_kit"
886
+ if [[ ! -f "$_ssh_key" ]]; then
887
+ printf '\n Generating ed25519 SSH key at %s...\n' "$_ssh_key"
888
+ ssh-keygen -t ed25519 -f "$_ssh_key" -C "claude-kit onboarding" -N "" 2>/dev/null
889
+ ACTIONS_TAKEN+=("Generated SSH key $_ssh_key")
890
+ fi
891
+ if has_cmd pbcopy; then
892
+ pbcopy < "${_ssh_key}.pub"
893
+ printf ' Public key copied to clipboard.\n'
894
+ else
895
+ cat "${_ssh_key}.pub"
896
+ fi
897
+ printf '\n Paste the public key at: https://github.com/settings/ssh/new\n'
898
+ ACTIONS_NEEDED+=("Add SSH public key: https://github.com/settings/ssh/new")
899
+ else
900
+ printf ' %sTip: set KIT_DOCTOR_SSH=1 and re-run to generate an ed25519 key.%s\n' "$C_DIM" "$C_RESET"
901
+ fi
902
+ fi
903
+ printf '\n'
904
+
905
+ # ============================================================================
906
+ # SURFACE PORTABILITY (connection test — terminal / Cowork / claude.ai, #376)
907
+ # ============================================================================
908
+ # A kit project should run on all three Claude surfaces with no hand edits. Terminal + Cowork read
909
+ # CLAUDE.md + .claude/ natively; claude.ai needs the kit-export-project transform. This test asks
910
+ # the same question kit-export-project --verify does: is the PORTABLE surface self-sufficient — does
911
+ # every file CLAUDE.md leans on carry tier-A (portable) semantics, not a tier-B CLI-only shim that
912
+ # would silently no-op off-terminal? Read-only; gated on a kit project (CLAUDE.md present).
913
+ _kit_target="${TARGET:-$PWD}"
914
+ _export_script="$_export_dir_doctor/kit-export-project.sh"
915
+ if [[ -f "$_kit_target/CLAUDE.md" && -f "$_export_script" ]]; then
916
+ printf ' %s%sSurface portability (terminal / Cowork / claude.ai)%s\n' "$C_BOLD" "" "$C_RESET"
917
+ if ( cd "$_kit_target" && bash "$_export_script" --verify ) >/dev/null 2>&1; then
918
+ row "$MARK_OK" "portable surface" "tier-A self-sufficient — runs in terminal/Cowork/claude.ai unchanged"
919
+ CHECKS_OK=$((CHECKS_OK + 1))
920
+ else
921
+ row "$MARK_WARN" "portable surface" "defect(s) — run: kit-export-project.sh --verify"
922
+ CHECKS_WARN=$((CHECKS_WARN + 1))
923
+ ACTIONS_NEEDED+=("Inspect portability: lib/verbs/kit-export-project.sh --verify (then export for claude.ai with no args)")
924
+ fi
925
+ printf '\n'
926
+ fi
927
+
928
+ # ============================================================================
929
+ # INSTRUCTION FILES (resident context budget, #357)
930
+ # ============================================================================
931
+ # CLAUDE.md and every .claude/rules/*.md without a `paths:` frontmatter load into every session;
932
+ # Claude Code warns at startup once they pass 150k characters combined. Show the number and the
933
+ # three largest files here so it is seen before that warning is. Read-only, and the same
934
+ # measurement the gate uses (instruction-budget-lint.sh --summary). Absent when the project has no
935
+ # instruction files.
936
+ _budget_lint="$_export_dir_doctor/../core/instruction-budget-lint.sh"
937
+ if [[ -f "$_budget_lint" ]]; then
938
+ _budget_line="$(INSTRUCTION_BUDGET_ROOT="$_kit_target" bash "$_budget_lint" --summary 2>/dev/null || true)"
939
+ if [[ -n "$_budget_line" ]]; then
940
+ printf ' %s%sInstruction files (loaded into every session)%s\n' "$C_BOLD" "" "$C_RESET"
941
+ _budget_resident="$(printf '%s' "$_budget_line" | awk '{print $3}')"
942
+ _budget_limit="$(printf '%s' "$_budget_line" | awk '{print $5}')"
943
+ if [[ "$_budget_resident" =~ ^[0-9]+$ && "$_budget_limit" =~ ^[0-9]+$ && "$_budget_resident" -gt "$_budget_limit" ]]; then
944
+ row "$MARK_WARN" "resident budget" "$_budget_line"
945
+ CHECKS_WARN=$((CHECKS_WARN + 1))
946
+ ACTIONS_NEEDED+=("Trim resident instruction files: lib/core/instruction-budget-lint.sh --report (scope a rule with paths:, or split it into a short rule + a knowledge doc)")
947
+ else
948
+ row "$MARK_OK" "resident budget" "$_budget_line"
949
+ CHECKS_OK=$((CHECKS_OK + 1))
950
+ fi
951
+ printf '\n'
952
+ fi
953
+ fi
954
+
955
+ # ============================================================================
956
+ # SUMMARY
957
+ # ============================================================================
958
+ printf ' %s%sSummary%s\n' "$C_BOLD" "" "$C_RESET"
959
+ printf ' %-4s %s checked ok\n' "" "$CHECKS_OK"
960
+ [[ $CHECKS_WARN -gt 0 ]] && printf ' %-4s %s warnings\n' "" "$CHECKS_WARN"
961
+ [[ $CHECKS_FAIL -gt 0 ]] && printf ' %-4s %s failed\n' "" "$CHECKS_FAIL"
962
+
963
+ if [[ ${#ACTIONS_TAKEN[@]} -gt 0 ]]; then
964
+ printf '\n %s%sInstalled / fixed:%s\n' "$C_BOLD" "" "$C_RESET"
965
+ for _a in "${ACTIONS_TAKEN[@]}"; do
966
+ printf ' %s %s\n' "$MARK_OK" "$_a"
967
+ done
968
+ fi
969
+
970
+ if [[ ${#ACTIONS_NEEDED[@]} -gt 0 ]]; then
971
+ printf '\n %s%sAction required:%s\n' "$C_BOLD" "" "$C_RESET"
972
+ for _a in "${ACTIONS_NEEDED[@]}"; do
973
+ printf ' %s %s\n' "$MARK_FAIL" "$_a"
974
+ done
975
+ fi
976
+ printf '\n'
977
+
978
+ # ---- onboarding / docs pointer ---------------------------------------------
979
+ # Show the local onboarding app ONLY when something actually answers on it —
980
+ # otherwise point at the public docs. (Previously this always printed
981
+ # http://localhost:3001/onboarding even when nothing served that port.)
982
+ _admin_url="${CCKIT_ADMIN_URL:-http://localhost:3001}"
983
+ if has_cmd curl && curl -fsS --max-time 1 "$_admin_url/onboarding" >/dev/null 2>&1; then
984
+ printf ' %sOnboarding guide (web): %s/onboarding%s\n' "$C_DIM" "$_admin_url" "$C_RESET"
985
+ else
986
+ printf ' %sDocs & quick start: %shttps://cckit.dev%s\n' "$C_DIM" "" "$C_RESET"
987
+ fi
988
+ printf '\n'
989
+
990
+ # Exit non-zero when critical checks failed
991
+ [[ $CHECKS_FAIL -gt 0 ]] && exit 1 || exit 0