contextdevkit 1.8.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 (345) hide show
  1. package/CHANGELOG.md +592 -0
  2. package/LICENSE +21 -0
  3. package/README.md +401 -0
  4. package/docs/AGENT-PACKAGE-FORMAT.md +140 -0
  5. package/docs/ARCHITECTURE.md +258 -0
  6. package/docs/CHANGELOG.md +559 -0
  7. package/docs/CUSTOMIZING.md +211 -0
  8. package/docs/LEVELS.md +151 -0
  9. package/docs/ROADMAP.md +385 -0
  10. package/docs/SQUAD-PIPELINE-FORMAT.md +258 -0
  11. package/docs/SQUADS/agent-forge.md +65 -0
  12. package/docs/SQUADS/design-team.md +161 -0
  13. package/docs/token-economy-plan.md +135 -0
  14. package/install.mjs +273 -0
  15. package/instrucoes.md +274 -0
  16. package/package.json +46 -0
  17. package/templates/CLAUDE.md.tpl +133 -0
  18. package/templates/claude/agents/_TEMPLATE.md +52 -0
  19. package/templates/claude/agents/accessibility.md +36 -0
  20. package/templates/claude/agents/agent-architect.md +37 -0
  21. package/templates/claude/agents/architect.md +39 -0
  22. package/templates/claude/agents/code-reviewer.md +43 -0
  23. package/templates/claude/agents/code-security.md +59 -0
  24. package/templates/claude/agents/context-keeper.md +40 -0
  25. package/templates/claude/agents/devops.md +40 -0
  26. package/templates/claude/agents/eval-designer.md +40 -0
  27. package/templates/claude/agents/forge-orchestrator.md +42 -0
  28. package/templates/claude/agents/governance-officer.md +45 -0
  29. package/templates/claude/agents/growth.md +92 -0
  30. package/templates/claude/agents/infra-security.md +53 -0
  31. package/templates/claude/agents/landing-architect.md +154 -0
  32. package/templates/claude/agents/model-router.md +34 -0
  33. package/templates/claude/agents/packager.md +38 -0
  34. package/templates/claude/agents/privacy-lgpd.md +64 -0
  35. package/templates/claude/agents/product-owner.md +51 -0
  36. package/templates/claude/agents/prompt-engineer.md +33 -0
  37. package/templates/claude/agents/qa-e2e.md +52 -0
  38. package/templates/claude/agents/qa-fuzzer.md +24 -0
  39. package/templates/claude/agents/qa-integration.md +21 -0
  40. package/templates/claude/agents/qa-orchestrator.md +40 -0
  41. package/templates/claude/agents/qa-perf.md +40 -0
  42. package/templates/claude/agents/qa-unit.md +39 -0
  43. package/templates/claude/agents/rag-designer.md +54 -0
  44. package/templates/claude/agents/retention.md +85 -0
  45. package/templates/claude/agents/security.md +48 -0
  46. package/templates/claude/agents/seo-specialist.md +106 -0
  47. package/templates/claude/agents/test-engineer.md +48 -0
  48. package/templates/claude/agents/tool-designer.md +32 -0
  49. package/templates/claude/agents/ui-designer.md +37 -0
  50. package/templates/claude/agents/ux-designer.md +38 -0
  51. package/templates/claude/commands/README.md +95 -0
  52. package/templates/claude/commands/advise.md +80 -0
  53. package/templates/claude/commands/audit/analyze-code-ia-practices.md +75 -0
  54. package/templates/claude/commands/audit/audit.md +35 -0
  55. package/templates/claude/commands/audit/contract-check.md +21 -0
  56. package/templates/claude/commands/audit/deep-analysis.md +48 -0
  57. package/templates/claude/commands/audit/deps-audit.md +49 -0
  58. package/templates/claude/commands/audit/security-setup.md +35 -0
  59. package/templates/claude/commands/audit/seo-audit.md +63 -0
  60. package/templates/claude/commands/audit/tech-debt-sweep.md +35 -0
  61. package/templates/claude/commands/bug-hunt.md +42 -0
  62. package/templates/claude/commands/claude-md.md +36 -0
  63. package/templates/claude/commands/close-version.md +25 -0
  64. package/templates/claude/commands/context-refresh.md +19 -0
  65. package/templates/claude/commands/context-stats.md +15 -0
  66. package/templates/claude/commands/dashboard.md +66 -0
  67. package/templates/claude/commands/distill-apply.md +19 -0
  68. package/templates/claude/commands/distill-sessions.md +26 -0
  69. package/templates/claude/commands/fleet.md +47 -0
  70. package/templates/claude/commands/forge/forge-audit.md +16 -0
  71. package/templates/claude/commands/forge/forge-budget.md +16 -0
  72. package/templates/claude/commands/forge/forge-deprecate.md +16 -0
  73. package/templates/claude/commands/forge/forge-doctor.md +17 -0
  74. package/templates/claude/commands/forge/forge-eval.md +16 -0
  75. package/templates/claude/commands/forge/forge-fallback-test.md +17 -0
  76. package/templates/claude/commands/forge/forge-killswitch.md +17 -0
  77. package/templates/claude/commands/forge/forge-list.md +17 -0
  78. package/templates/claude/commands/forge/forge-new.md +41 -0
  79. package/templates/claude/commands/forge/forge-policy.md +16 -0
  80. package/templates/claude/commands/forge/forge-redteam.md +17 -0
  81. package/templates/claude/commands/forge/forge-refresh-matrix.md +20 -0
  82. package/templates/claude/commands/forge/forge-route.md +17 -0
  83. package/templates/claude/commands/forge/forge-show.md +16 -0
  84. package/templates/claude/commands/landing-page.md +71 -0
  85. package/templates/claude/commands/log-session.md +59 -0
  86. package/templates/claude/commands/media-gen.md +93 -0
  87. package/templates/claude/commands/new-adr.md +30 -0
  88. package/templates/claude/commands/pipeline/dev-start.md +64 -0
  89. package/templates/claude/commands/pipeline/pipeline.md +36 -0
  90. package/templates/claude/commands/pipeline/resume.md +70 -0
  91. package/templates/claude/commands/pipeline/retro.md +34 -0
  92. package/templates/claude/commands/pipeline/runs.md +63 -0
  93. package/templates/claude/commands/pipeline/ship.md +54 -0
  94. package/templates/claude/commands/pipeline/workflow.md +85 -0
  95. package/templates/claude/commands/playbook.md +27 -0
  96. package/templates/claude/commands/predictions-review.md +28 -0
  97. package/templates/claude/commands/qa/qa-signoff.md +24 -0
  98. package/templates/claude/commands/qa/scaffold-tests.md +27 -0
  99. package/templates/claude/commands/qa/test-plan.md +26 -0
  100. package/templates/claude/commands/qa/visual-test.md +42 -0
  101. package/templates/claude/commands/roadmap.md +48 -0
  102. package/templates/claude/commands/setup/aidevtool-from0.md +104 -0
  103. package/templates/claude/commands/setup/context-config.md +25 -0
  104. package/templates/claude/commands/setup/context-doctor.md +21 -0
  105. package/templates/claude/commands/setup/context-level.md +17 -0
  106. package/templates/claude/commands/setup/setupcontextdevkit.md +121 -0
  107. package/templates/claude/commands/simulate-impact.md +32 -0
  108. package/templates/claude/commands/squad.md +44 -0
  109. package/templates/claude/commands/state.md +21 -0
  110. package/templates/claude/commands/token-report.md +29 -0
  111. package/templates/claude/commands/tune-agents.md +35 -0
  112. package/templates/claude/commands/vcs/claim.md +18 -0
  113. package/templates/claude/commands/vcs/git.md +83 -0
  114. package/templates/claude/commands/vcs/release.md +15 -0
  115. package/templates/claude/commands/vcs/worktree-new.md +18 -0
  116. package/templates/claude/commands/watch.md +47 -0
  117. package/templates/contextkit/.env.example +36 -0
  118. package/templates/contextkit/CLAUDE.child.md.tpl +38 -0
  119. package/templates/contextkit/README.md +74 -0
  120. package/templates/contextkit/behaviors-examples.md +183 -0
  121. package/templates/contextkit/behaviors.md +116 -0
  122. package/templates/contextkit/best-practices.md +323 -0
  123. package/templates/contextkit/config.json +66 -0
  124. package/templates/contextkit/detectors/README.md +45 -0
  125. package/templates/contextkit/detectors/example-detector.mjs.example +25 -0
  126. package/templates/contextkit/instrucoes.md +114 -0
  127. package/templates/contextkit/memory/GLOSSARY.md +13 -0
  128. package/templates/contextkit/memory/SESSIONS.md +9 -0
  129. package/templates/contextkit/memory/WORKSPACE.md +7 -0
  130. package/templates/contextkit/memory/business-rules/_TEMPLATE.md +33 -0
  131. package/templates/contextkit/memory/decisions/0000-record-architecture-decisions.md +34 -0
  132. package/templates/contextkit/memory/decisions/_TEMPLATE.md +25 -0
  133. package/templates/contextkit/memory/predictions/.gitkeep +0 -0
  134. package/templates/contextkit/memory/roadmap.md +28 -0
  135. package/templates/contextkit/memory/sessions/.gitkeep +0 -0
  136. package/templates/contextkit/memory/workflows/.gitkeep +0 -0
  137. package/templates/contextkit/pipeline/backlog/.gitkeep +0 -0
  138. package/templates/contextkit/pipeline/conclusion/.gitkeep +0 -0
  139. package/templates/contextkit/pipeline/devpipeline.md +9 -0
  140. package/templates/contextkit/pipeline/testing/.gitkeep +0 -0
  141. package/templates/contextkit/pipeline/working/.gitkeep +0 -0
  142. package/templates/contextkit/review-protocol.md +214 -0
  143. package/templates/contextkit/runtime/config/defaults.mjs +215 -0
  144. package/templates/contextkit/runtime/config/levels.mjs +42 -0
  145. package/templates/contextkit/runtime/config/load.mjs +105 -0
  146. package/templates/contextkit/runtime/config/paths.mjs +92 -0
  147. package/templates/contextkit/runtime/config/presets.mjs +47 -0
  148. package/templates/contextkit/runtime/config/schema.mjs +88 -0
  149. package/templates/contextkit/runtime/config/settings-compose.mjs +55 -0
  150. package/templates/contextkit/runtime/git-hooks/commit-msg.mjs +55 -0
  151. package/templates/contextkit/runtime/git-hooks/pre-commit.mjs +47 -0
  152. package/templates/contextkit/runtime/git-hooks/pre-push.mjs +102 -0
  153. package/templates/contextkit/runtime/hooks/boot-context-readers.mjs +111 -0
  154. package/templates/contextkit/runtime/hooks/boot-signals.mjs +135 -0
  155. package/templates/contextkit/runtime/hooks/check-registration.mjs +228 -0
  156. package/templates/contextkit/runtime/hooks/concurrency-guard.mjs +110 -0
  157. package/templates/contextkit/runtime/hooks/ledger.mjs +231 -0
  158. package/templates/contextkit/runtime/hooks/md-extract.mjs +65 -0
  159. package/templates/contextkit/runtime/hooks/path-classification.mjs +62 -0
  160. package/templates/contextkit/runtime/hooks/safe-io.mjs +84 -0
  161. package/templates/contextkit/runtime/hooks/session-digest-core.mjs +85 -0
  162. package/templates/contextkit/runtime/hooks/session-start.mjs +248 -0
  163. package/templates/contextkit/runtime/hooks/simulate-gate.mjs +108 -0
  164. package/templates/contextkit/runtime/hooks/track-edits.mjs +154 -0
  165. package/templates/contextkit/runtime/providers/media/_adapter.mjs +120 -0
  166. package/templates/contextkit/runtime/providers/media/nano-banana.mjs +110 -0
  167. package/templates/contextkit/runtime/providers/media/veo.mjs +162 -0
  168. package/templates/contextkit/runtime/providers/review/_adapter.mjs +71 -0
  169. package/templates/contextkit/runtime/providers/review/detect.mjs +115 -0
  170. package/templates/contextkit/runtime/providers/review/gh.mjs +103 -0
  171. package/templates/contextkit/runtime/state/state-io.mjs +172 -0
  172. package/templates/contextkit/runtime/statusline.mjs +51 -0
  173. package/templates/contextkit/squads/README.md +115 -0
  174. package/templates/contextkit/squads/_BRIEFING.md.tpl +27 -0
  175. package/templates/contextkit/squads/agent-forge/README.md +69 -0
  176. package/templates/contextkit/squads/agent-forge/ROADMAP.md +108 -0
  177. package/templates/contextkit/squads/agent-forge/best-practices.md +89 -0
  178. package/templates/contextkit/squads/agent-forge/cli/forge-admin.mjs +132 -0
  179. package/templates/contextkit/squads/agent-forge/cli/forge-eval-cli.mjs +163 -0
  180. package/templates/contextkit/squads/agent-forge/cli/forge-new.mjs +97 -0
  181. package/templates/contextkit/squads/agent-forge/cli/forge-ops.mjs +177 -0
  182. package/templates/contextkit/squads/agent-forge/lib/architect.mjs +112 -0
  183. package/templates/contextkit/squads/agent-forge/lib/eval-designer.mjs +133 -0
  184. package/templates/contextkit/squads/agent-forge/lib/eval-runner.mjs +167 -0
  185. package/templates/contextkit/squads/agent-forge/lib/governance-officer.mjs +178 -0
  186. package/templates/contextkit/squads/agent-forge/lib/package-ops.mjs +101 -0
  187. package/templates/contextkit/squads/agent-forge/lib/packager.mjs +219 -0
  188. package/templates/contextkit/squads/agent-forge/lib/prompt-gen.mjs +122 -0
  189. package/templates/contextkit/squads/agent-forge/lib/rag-designer.mjs +102 -0
  190. package/templates/contextkit/squads/agent-forge/lib/router.mjs +165 -0
  191. package/templates/contextkit/squads/agent-forge/lib/tool-gen.mjs +113 -0
  192. package/templates/contextkit/squads/agent-forge/lib/yaml.mjs +47 -0
  193. package/templates/contextkit/squads/agent-forge/pipeline.yaml +65 -0
  194. package/templates/contextkit/squads/agent-forge/router/capability-matrix.json +112 -0
  195. package/templates/contextkit/squads/agent-forge/router/decision-rules.json +120 -0
  196. package/templates/contextkit/squads/agent-forge/templates/agent-package/.agentforgerc +12 -0
  197. package/templates/contextkit/squads/agent-forge/templates/agent-package/CHANGELOG.md +13 -0
  198. package/templates/contextkit/squads/agent-forge/templates/agent-package/LICENSE +5 -0
  199. package/templates/contextkit/squads/agent-forge/templates/agent-package/README.md +39 -0
  200. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/go/README.md +10 -0
  201. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/go/agent.go +14 -0
  202. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/go/go.mod +3 -0
  203. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/node/README.md +11 -0
  204. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/node/index.js +53 -0
  205. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/node/package.json +9 -0
  206. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/python/README.md +10 -0
  207. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/python/agent.py +16 -0
  208. package/templates/contextkit/squads/agent-forge/templates/agent-package/adapters/python/pyproject.toml +10 -0
  209. package/templates/contextkit/squads/agent-forge/templates/agent-package/evals/golden.jsonl +1 -0
  210. package/templates/contextkit/squads/agent-forge/templates/agent-package/evals/red-team.jsonl +3 -0
  211. package/templates/contextkit/squads/agent-forge/templates/agent-package/evals/rubric.yaml +14 -0
  212. package/templates/contextkit/squads/agent-forge/templates/agent-package/evals/run-eval.md +17 -0
  213. package/templates/contextkit/squads/agent-forge/templates/agent-package/evals/thresholds.yaml +18 -0
  214. package/templates/contextkit/squads/agent-forge/templates/agent-package/examples/basic.node.md +17 -0
  215. package/templates/contextkit/squads/agent-forge/templates/agent-package/examples/with-fallback.node.md +24 -0
  216. package/templates/contextkit/squads/agent-forge/templates/agent-package/examples/with-rag.python.md +20 -0
  217. package/templates/contextkit/squads/agent-forge/templates/agent-package/governance/audit.schema.json +23 -0
  218. package/templates/contextkit/squads/agent-forge/templates/agent-package/governance/compliance.policy.yaml +43 -0
  219. package/templates/contextkit/squads/agent-forge/templates/agent-package/governance/cost.policy.yaml +36 -0
  220. package/templates/contextkit/squads/agent-forge/templates/agent-package/governance/fallback-chain.yaml +16 -0
  221. package/templates/contextkit/squads/agent-forge/templates/agent-package/governance/quality.policy.yaml +43 -0
  222. package/templates/contextkit/squads/agent-forge/templates/agent-package/manifest.yaml +91 -0
  223. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.anthropic.md +19 -0
  224. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.canonical.md +25 -0
  225. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.deepseek.md +21 -0
  226. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.google.md +19 -0
  227. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.ollama.md +21 -0
  228. package/templates/contextkit/squads/agent-forge/templates/agent-package/prompts/system.openai.md +20 -0
  229. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/config.yaml +17 -0
  230. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/index/.gitkeep +3 -0
  231. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/ingestion/chunker.config.yaml +6 -0
  232. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/ingestion/sources.yaml +8 -0
  233. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/retrieval/query-template.md +16 -0
  234. package/templates/contextkit/squads/agent-forge/templates/agent-package/rag/retrieval/rerank.config.yaml +6 -0
  235. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/adapters/anthropic.tools.json +11 -0
  236. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/adapters/deepseek.tools.json +14 -0
  237. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/adapters/google.tools.json +11 -0
  238. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/adapters/ollama.tools.json +14 -0
  239. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/adapters/openai.tools.json +14 -0
  240. package/templates/contextkit/squads/agent-forge/templates/agent-package/tools/schemas.canonical.json +25 -0
  241. package/templates/contextkit/starters/tanstack/README.md +86 -0
  242. package/templates/contextkit/starters/tanstack/index.html +12 -0
  243. package/templates/contextkit/starters/tanstack/package.json +25 -0
  244. package/templates/contextkit/starters/tanstack/src/main.tsx +40 -0
  245. package/templates/contextkit/starters/tanstack/src/router.tsx +12 -0
  246. package/templates/contextkit/starters/tanstack/src/routes/__root.tsx +10 -0
  247. package/templates/contextkit/starters/tanstack/src/routes/index.tsx +17 -0
  248. package/templates/contextkit/starters/tanstack/tsconfig.json +19 -0
  249. package/templates/contextkit/starters/tanstack/vite.config.ts +10 -0
  250. package/templates/contextkit/tools/scripts/adr-digest-core.mjs +42 -0
  251. package/templates/contextkit/tools/scripts/adr-digest.mjs +78 -0
  252. package/templates/contextkit/tools/scripts/agent-tuning.mjs +74 -0
  253. package/templates/contextkit/tools/scripts/aiso-audit.mjs +174 -0
  254. package/templates/contextkit/tools/scripts/audit-shared.mjs +129 -0
  255. package/templates/contextkit/tools/scripts/claim.mjs +133 -0
  256. package/templates/contextkit/tools/scripts/claude-md.mjs +123 -0
  257. package/templates/contextkit/tools/scripts/clean-drive.mjs +78 -0
  258. package/templates/contextkit/tools/scripts/context-config.mjs +111 -0
  259. package/templates/contextkit/tools/scripts/context-level.mjs +98 -0
  260. package/templates/contextkit/tools/scripts/context-pack.mjs +120 -0
  261. package/templates/contextkit/tools/scripts/contract-scan.mjs +186 -0
  262. package/templates/contextkit/tools/scripts/dashboard-data.mjs +198 -0
  263. package/templates/contextkit/tools/scripts/dashboard-html.mjs +215 -0
  264. package/templates/contextkit/tools/scripts/dashboard-server.mjs +129 -0
  265. package/templates/contextkit/tools/scripts/dashboard.mjs +107 -0
  266. package/templates/contextkit/tools/scripts/deep-analysis.mjs +62 -0
  267. package/templates/contextkit/tools/scripts/deps-audit.mjs +201 -0
  268. package/templates/contextkit/tools/scripts/detect-stack.mjs +164 -0
  269. package/templates/contextkit/tools/scripts/distill-detect.mjs +90 -0
  270. package/templates/contextkit/tools/scripts/doctor.mjs +165 -0
  271. package/templates/contextkit/tools/scripts/fleet.mjs +170 -0
  272. package/templates/contextkit/tools/scripts/generate-context.mjs +142 -0
  273. package/templates/contextkit/tools/scripts/gh-alerts.mjs +117 -0
  274. package/templates/contextkit/tools/scripts/git.mjs +97 -0
  275. package/templates/contextkit/tools/scripts/home.mjs +106 -0
  276. package/templates/contextkit/tools/scripts/mark-simulation.mjs +78 -0
  277. package/templates/contextkit/tools/scripts/media-gen.mjs +154 -0
  278. package/templates/contextkit/tools/scripts/pipeline-board.mjs +74 -0
  279. package/templates/contextkit/tools/scripts/pipeline-prioritize.mjs +68 -0
  280. package/templates/contextkit/tools/scripts/pipeline-session.mjs +99 -0
  281. package/templates/contextkit/tools/scripts/pipeline-validate.mjs +136 -0
  282. package/templates/contextkit/tools/scripts/pipeline.mjs +302 -0
  283. package/templates/contextkit/tools/scripts/playbook.mjs +123 -0
  284. package/templates/contextkit/tools/scripts/predictions-review.mjs +113 -0
  285. package/templates/contextkit/tools/scripts/release.mjs +60 -0
  286. package/templates/contextkit/tools/scripts/resume.mjs +114 -0
  287. package/templates/contextkit/tools/scripts/roadmap.mjs +86 -0
  288. package/templates/contextkit/tools/scripts/runs.mjs +116 -0
  289. package/templates/contextkit/tools/scripts/seo-audit.mjs +150 -0
  290. package/templates/contextkit/tools/scripts/session-digest.mjs +89 -0
  291. package/templates/contextkit/tools/scripts/session-reindex.mjs +91 -0
  292. package/templates/contextkit/tools/scripts/setup-complete.mjs +69 -0
  293. package/templates/contextkit/tools/scripts/squad-meta.mjs +23 -0
  294. package/templates/contextkit/tools/scripts/squad-pipeline-condition.mjs +192 -0
  295. package/templates/contextkit/tools/scripts/squad-pipeline.mjs +301 -0
  296. package/templates/contextkit/tools/scripts/squad.mjs +80 -0
  297. package/templates/contextkit/tools/scripts/stats.mjs +138 -0
  298. package/templates/contextkit/tools/scripts/sync-check.mjs +235 -0
  299. package/templates/contextkit/tools/scripts/tech-debt-detectors.mjs +76 -0
  300. package/templates/contextkit/tools/scripts/tech-debt-scan.mjs +164 -0
  301. package/templates/contextkit/tools/scripts/token-report.mjs +153 -0
  302. package/templates/contextkit/tools/scripts/visual-test.mjs +132 -0
  303. package/templates/contextkit/tools/scripts/watch.mjs +106 -0
  304. package/templates/contextkit/tools/scripts/workflow.mjs +136 -0
  305. package/templates/contextkit/tools/scripts/workspace-sync.mjs +220 -0
  306. package/templates/contextkit/tools/scripts/worktree-new.mjs +50 -0
  307. package/templates/contextkit/workflows/L1-static-loading.md +59 -0
  308. package/templates/contextkit/workflows/L2-session-ledger.md +86 -0
  309. package/templates/contextkit/workflows/L3-multi-session.md +80 -0
  310. package/templates/contextkit/workflows/L4-squads.md +68 -0
  311. package/templates/contextkit/workflows/L5-proactive.md +88 -0
  312. package/templates/contextkit/workflows/README.md +47 -0
  313. package/templates/contextkit/workflows/playbooks/distillation-cycle.md +74 -0
  314. package/templates/contextkit/workflows/playbooks/landing-page.md +197 -0
  315. package/templates/contextkit/workflows/playbooks/security-batch.md +68 -0
  316. package/templates/contextkit/workflows/playbooks/seo-aiso.md +288 -0
  317. package/templates/contextkit/workflows/playbooks/simulate-impact.md +83 -0
  318. package/templates/contextkit/workflows/playbooks/tanstack.md +164 -0
  319. package/templates/contextkit/workflows/playbooks/tech-debt-sweep.md +77 -0
  320. package/templates/docs/CHANGELOG.md.tpl +11 -0
  321. package/templates/gitattributes +3 -0
  322. package/templates/github/ISSUE_TEMPLATE/bug_report.md +30 -0
  323. package/templates/github/ISSUE_TEMPLATE/feature_request.md +22 -0
  324. package/templates/github/PULL_REQUEST_TEMPLATE.md +27 -0
  325. package/templates/github/dependabot.yml +27 -0
  326. package/templates/github/workflows/quality.yml +36 -0
  327. package/templates/github/workflows/security.yml +54 -0
  328. package/tools/install/cli.mjs +62 -0
  329. package/tools/install/fs.mjs +56 -0
  330. package/tools/install/git.mjs +114 -0
  331. package/tools/install/project.mjs +51 -0
  332. package/tools/install/uninstall.mjs +54 -0
  333. package/tools/integration-test-compozy.mjs +88 -0
  334. package/tools/integration-test-guards.mjs +269 -0
  335. package/tools/integration-test-tooling-agent-forge.mjs +189 -0
  336. package/tools/integration-test-tooling-pipeline.mjs +164 -0
  337. package/tools/integration-test-tooling.mjs +172 -0
  338. package/tools/integration-test.mjs +228 -0
  339. package/tools/it-helpers.mjs +60 -0
  340. package/tools/selfcheck-agent-forge-ops.mjs +107 -0
  341. package/tools/selfcheck-agent-forge.mjs +304 -0
  342. package/tools/selfcheck-config.mjs +80 -0
  343. package/tools/selfcheck-runtime.mjs +135 -0
  344. package/tools/selfcheck-source.mjs +326 -0
  345. package/tools/selfcheck.mjs +268 -0
@@ -0,0 +1,65 @@
1
+ # agent-forge — the factory squad
2
+
3
+ > Public reference for the optional L4+ squad that forges portable, multi-provider
4
+ > **Agent Packages (APF v1)** for projects *outside* the kit. The kit gains an
5
+ > agent-that-builds-agents whose output ships independently — zero ContextDevKit
6
+ > dependency at consume time.
7
+
8
+ ## When to enable
9
+
10
+ Add `agent-forge` when a project's purpose includes shipping production AI
11
+ agents (chatbots, extractors, RAG, classifiers, etc.) as standalone artefacts —
12
+ typically `project_type: ai-product`. Stays inert otherwise.
13
+
14
+ ## Approval + constraints
15
+
16
+ - **[ADR-0012](../../contextkit/memory/decisions/0012-agent-forge-squad-for-portable-agent-packages.md)** — 7 binding constraints (portable zero-dep output, hot path stays zero-dep, reuse `squadOf`, no phantom prerequisite, **eval-as-authority**, owned matrix freshness, mandatory tests).
17
+ - **[ADR-0013](../../contextkit/memory/decisions/0013-agent-forge-yaml-via-optional-dynamic-import.md)** — YAML strategy: optional `yaml` dep behind a dynamic import (the `zod` precedent).
18
+
19
+ ## Pipeline
20
+
21
+ ```
22
+ /forge-new
23
+ → agent-architect (interview → blueprint)
24
+ → model-router (capability-matrix × decision-rules → primary/fallback/cheap/premium + rationale)
25
+ → prompt-engineer (canonical → Anthropic+OpenAI+Gemini+DeepSeek+Ollama)
26
+ → tool-designer (canonical JSON Schema → 5 provider adapters)
27
+ → eval-designer (golden + red-team + rubric + thresholds)
28
+ → governance-officer (three pillars + fallback chain; refuses under-configured)
29
+ → packager (assembles APF, stamps provenance, writes 5 prompts + 5 tool adapters)
30
+ → eval gate (optional `runEval` → stamps `eval_passed_at` only on PASS)
31
+ ```
32
+
33
+ ## Maintenance commands (Fase 4)
34
+
35
+ | Command | What it does |
36
+ | --- | --- |
37
+ | `/forge-list` | Every package + version + routed primary + eval-stamp status |
38
+ | `/forge-show <agent>` | Manifest + provenance + last eval timestamp |
39
+ | `/forge-doctor` | Integrity check; fails on missing files or `{{TOKEN}}` placeholders |
40
+ | `/forge-policy <agent>` | Resolved cost / compliance / quality + fallback chain |
41
+ | `/forge-budget` | Aggregate monthly target + hard cap |
42
+ | `/forge-audit <agent>` | Audit-log tally (ok / refused / error / killed / fallbacks / cost) |
43
+ | `/forge-eval <agent>` | Re-run golden + red-team |
44
+ | `/forge-redteam <agent>` | Red-team only |
45
+ | `/forge-route <agent>` | Re-run router, diff vs current manifest |
46
+ | `/forge-fallback-test <agent>` | Chaos: primary 503 on first call |
47
+ | `/forge-refresh-matrix` | Stamp `updated`; model adds require an ADR |
48
+ | `/forge-killswitch <agent> <on\|off>` | Toggle quality kill switch (atomic) |
49
+ | `/forge-deprecate <agent>` | Stamp `metadata.deprecated_at`; recommend an ADR |
50
+
51
+ Read `/context-stats` for the aggregate Forge Stats section.
52
+
53
+ ## Where each piece lives
54
+
55
+ - **Squad source** — [`templates/contextkit/squads/agent-forge/`](../../templates/contextkit/squads/agent-forge/)
56
+ - **Status map** — [`ROADMAP.md`](../../templates/contextkit/squads/agent-forge/ROADMAP.md) (the section-by-section blueprint coverage)
57
+ - **Best-practices bar** — [`best-practices.md`](../../templates/contextkit/squads/agent-forge/best-practices.md)
58
+ - **APF v1 template** — [`templates/contextkit/squads/agent-forge/templates/agent-package/`](../../templates/contextkit/squads/agent-forge/templates/agent-package/) (45 files)
59
+ - **APF format reference** — [`docs/AGENT-PACKAGE-FORMAT.md`](AGENT-PACKAGE-FORMAT.md)
60
+
61
+ ## Boundary
62
+
63
+ This squad's *clients* are external projects, not Claude Code. Every other squad
64
+ in the kit (devteam / qa-team / security-team / …) services the developer; this
65
+ one services *the developer's product*.
@@ -0,0 +1,161 @@
1
+ # Squad — design-team
2
+
3
+ The kit's "make it usable, make it beautiful, make it findable" squad. Five
4
+ specialists, each sharp and narrow. Activated at **Level 4+**.
5
+
6
+ ## When to invoke each
7
+
8
+ | Specialist | When to use | Refuses |
9
+ |---|---|---|
10
+ | **`ux-designer`** | Designing or critiquing a flow / screen / interaction. User journeys, friction maps, empty/loading/error states, IA. | Clever-over-clear, decoration that costs friction, designing only happy paths |
11
+ | **`ui-designer`** | Layout, spacing, type scale, colour roles, components, responsive behaviour, design tokens. | One-off styles, hard-coded raw hex colours in components, inventing patterns when the system has one |
12
+ | **`accessibility`** | WCAG 2.1 AA verification — keyboard nav, screen-reader semantics, contrast ratios, focus management, ARIA. | Adding ARIA when semantic HTML already does the job; mouse-only interactions |
13
+ | **`seo-specialist`** *(v1.7)* | Public-facing surfaces where indexability matters — SEO (Google + Bing) and AISO (LLM answer engines). | Plain client-rendered SPAs on public routes, JS-rendered cited content, prerender hacks, missing `llms.txt` / FAQ schema |
14
+ | **`landing-architect`** *(v1.7)* | Landing-page or marketing-site structural decisions — rendering posture, fold map, conversion levers, package picks. | Cookie-cutter "Lovable / v0 / Tailwind UI" pattern; `Inter` / Heroicons / three-tier pricing / testimonial slider as defaults |
15
+
16
+ ## How they pair
17
+
18
+ ```text
19
+ Brief: "design a landing page for our pricing change"
20
+
21
+ /landing-page → landing-architect
22
+
23
+ ├──→ seo-specialist (mandatory gate — indexability first)
24
+ ├──→ ui-designer (tokens + visual layout)
25
+ ├──→ ux-designer (user flow through the page)
26
+ ├──→ accessibility (pre-merge WCAG AA)
27
+ └──→ /media-gen (hero imagery instead of stock)
28
+ ```
29
+
30
+ The **order matters**. `landing-architect` decides the rendering posture and
31
+ fold map first; `seo-specialist` verifies indexability *before* visual work
32
+ lands; only then do `ui-designer` and `ux-designer` shape the screen.
33
+
34
+ ## `landing-architect` — the structural decision-maker *(new in v1.7)*
35
+
36
+ Authority: [ADR-0023](../../contextkit/memory/decisions/0023-landing-page-and-conversion-posture.md)
37
+ + [`landing-page.md`](../../templates/contextkit/workflows/playbooks/landing-page.md) playbook.
38
+
39
+ ### Posture
40
+
41
+ Anti-Lovable / anti-cookie-cutter is the load-bearing principle. The current
42
+ generation of AI-generated landing pages has a uniform look (gradient hero,
43
+ three feature cards, three-tier pricing, testimonial slider, FAQ accordion)
44
+ that a savvy visitor recognises in 3 seconds. Recognition reads as
45
+ "AI-built" → "low effort" → conversion cost.
46
+
47
+ ### The three decisions (in this order)
48
+
49
+ 1. **Rendering posture** — SSG (Astro recommended), SSR (Next App Router /
50
+ Nuxt / Remix / SvelteKit), or carve-out via project ADR. Plain Vite +
51
+ React for a public landing page is a refusal; propose Astro.
52
+ 2. **Fold map** — count from the playbook's table:
53
+ - **min 3** (hero · proof · CTA) — utility / one-feature pages
54
+ - **ideal 5–7** — SaaS, marketing pages
55
+ - **max 9** — high-ticket B2B; beyond falls off a cliff
56
+ - Per-fold rule: **one message · one action · one proof**.
57
+ 3. **Package picks** — framework, styling, animation, typography, icons,
58
+ forms, analytics, experimentation, imagery. From the dated rec table
59
+ in the playbook; refuse `Inter` / Heroicons / GA4 / Material UI as
60
+ *defaults*.
61
+
62
+ ### Output shape
63
+
64
+ Every `/landing-page` response is structured exactly:
65
+
66
+ 1. Indexability decision (SSG / SSR / carve-out + framework + rationale)
67
+ 2. Fold map (each: `<fold-name> · <message> · <action> · <proof>`)
68
+ 3. Anti-Lovable map (smells refused + substitute for each)
69
+ 4. Stack (one-line rationale per category)
70
+ 5. Performance budget (LCP < 2.5 s · INP < 200 ms · CLS < 0.1 · JS < 100 kB)
71
+ 6. Next-step delegations (which agent for what input)
72
+
73
+ **No code.** The plan is the deliverable.
74
+
75
+ ## `seo-specialist` — the indexability + discoverability gate *(new in v1.7)*
76
+
77
+ Authority: [ADR-0025](../../contextkit/memory/decisions/0025-seo-and-aiso-posture.md)
78
+ + [`seo-aiso.md`](../../templates/contextkit/workflows/playbooks/seo-aiso.md) playbook.
79
+
80
+ ### Two index spaces, two rule sets
81
+
82
+ A public page is judged by **two crawler classes simultaneously**, and most
83
+ projects optimise the first while ignoring the second.
84
+
85
+ | Index | Crawlers | Rewards | Kills |
86
+ |---|---|---|---|
87
+ | **Classical SEO** | Googlebot, Bingbot, DuckDuckBot | Server-rendered HTML, semantic tags, canonical URLs, sitemap, Core Web Vitals, JSON-LD entities | Empty `<div id="root"></div>`, JS-rendered titles, missing `<meta description>`, CLS > 0.1 |
88
+ | **AISO** (AI Search Optimization) | GPTBot, ClaudeBot, PerplexityBot, Google-Extended, OAI-SearchBot | `llms.txt`, FAQ schema, scannable Q&A headings, semantic HTML5, recency stamps, author schema | Div-soup, JS-rendered content, no FAQ schema, no `llms.txt`, robots.txt blocking AI crawlers |
89
+
90
+ ### Operational principles
91
+
92
+ - **Audit-first.** Runs `seo-audit.mjs` + `aiso-audit.mjs` before any opinion.
93
+ - **Refuse-on-unindexable for landing surfaces.** Plain SPA on public routes
94
+ is a refusal — proposes SSG / SSR.
95
+ - **Refuse JS-tricks.** Prerender services, dynamic-rendering middleware —
96
+ brittle, propose-correct-rendering-mode-up-front instead.
97
+ - **AISO is not optional for marketing sites.** `llms.txt` + FAQ schema +
98
+ semantic HTML5 = the 80/20.
99
+ - **Propose, don't auto-rewrite.** Findings are the deliverable.
100
+ - **Respect project-local ADRs** that carve out indexability (internal admin
101
+ tools, etc).
102
+
103
+ ### Audits available
104
+
105
+ ```bash
106
+ # Classical SEO — 8 codes, exit 1 on critical (SPA_ENTRYPOINT)
107
+ node contextkit/tools/scripts/seo-audit.mjs # human-readable table
108
+ node contextkit/tools/scripts/seo-audit.mjs --json # machine-readable
109
+
110
+ # AISO — 8 codes
111
+ node contextkit/tools/scripts/aiso-audit.mjs # human-readable table
112
+ node contextkit/tools/scripts/aiso-audit.mjs --json # machine-readable
113
+
114
+ # Or the slash command runs both and summarises:
115
+ /seo-audit
116
+ ```
117
+
118
+ | SEO codes | AISO codes |
119
+ |---|---|
120
+ | `SPA_ENTRYPOINT` (critical), `MISSING_TITLE` (high), `MISSING_DESCRIPTION` (high), `MULTIPLE_H1` (high), `MISSING_CANONICAL` (medium), `MISSING_ALT` (medium), `MISSING_SITEMAP` (high), `MISSING_ROBOTS` (medium) | `MISSING_LLMS_TXT` (high), `MISSING_FAQ_SCHEMA` (high), `MISSING_ORG_SCHEMA` (medium), `DIV_SOUP` (medium), `JS_RENDERED_CONTENT` (high), `MISSING_AUTHOR_SCHEMA` (low), `MISSING_DATE_STAMP` (low), `BLOCKS_AI_CRAWLERS` (high) |
121
+
122
+ ## `ui-designer` — the system voice
123
+
124
+ Owns layout, spacing, type scale, colour roles, components, responsive
125
+ behaviour, and visual consistency via **design tokens** (`:root { --color-primary: ... }`).
126
+ Refuses one-off styles. Pairs with the chosen styling system (Tailwind +
127
+ tokens being the kit's recommended default).
128
+
129
+ ## `ux-designer` — the user-flow voice
130
+
131
+ Owns user journeys, IA, interaction design, and the *unhappy paths* (empty,
132
+ loading, error, partial, offline, first-run). Designs the flow backward
133
+ from the job-to-be-done; resists clever-over-clear.
134
+
135
+ ## `accessibility` — the WCAG 2.1 AA floor
136
+
137
+ Owns keyboard navigation, screen-reader semantics, contrast ratios, focus
138
+ management, ARIA hygiene. Refuses ARIA-when-semantic-HTML-already-does-the-job.
139
+ Mandatory before any landing-page or marketing surface merges.
140
+
141
+ ## Growing the squad
142
+
143
+ To add a specialist (e.g. `motion-designer` for advanced interaction):
144
+
145
+ 1. Copy `templates/claude/agents/_TEMPLATE.md`.
146
+ 2. Fill in `name` + `description` (the routing signal — Claude picks an
147
+ agent by matching the description).
148
+ 3. Add posture / principles / anti-patterns / self-audit / delegate-to.
149
+ 4. Add a selfcheck assertion in `tools/selfcheck-source.mjs`.
150
+ 5. Document in this file under "When to invoke each".
151
+
152
+ A vague "helps with everything" agent defeats routing. Keep it **sharp and
153
+ narrow** — see `seo-specialist.md` and `landing-architect.md` as references.
154
+
155
+ ## Related
156
+
157
+ - [`docs/SQUADS/agent-forge.md`](agent-forge.md) — the L6+ squad that *builds*
158
+ Agent Packages portable across hosts.
159
+ - Playbook [`landing-page.md`](../../templates/contextkit/workflows/playbooks/landing-page.md)
160
+ + [`seo-aiso.md`](../../templates/contextkit/workflows/playbooks/seo-aiso.md).
161
+ - [`docs/CUSTOMIZING.md`](../CUSTOMIZING.md) — adding agents to any squad.
@@ -0,0 +1,135 @@
1
+ # Token-Economy & Agility Plan
2
+
3
+ > A plan to reduce token consumption **and** increase agility in ContextDevKit, by
4
+ > moving deterministic extraction out of the AI and into zero-dep scripts.
5
+ > Companion to [ADR-0027](../contextkit/memory/decisions/0027-token-economy-digest-layer.md)
6
+ > and the ROADMAP section *"Token economy: the digest layer"*.
7
+ > Authored 2026-06-03.
8
+
9
+ ## 1. The principle
10
+
11
+ In this kit, **tokens are spent when the AI (Claude) reads files and reasons over
12
+ them.** Every line of raw markdown the AI ingests is input tokens. The cheapest token
13
+ is the one never read. So the lever is simple:
14
+
15
+ > **Pre-digest deterministically in a script; let the AI reason over the compact
16
+ > output.** Scripts are free (they don't consume model tokens); the AI's context is
17
+ > the scarce resource.
18
+
19
+ The kit already lives by this — ~40 of 65 commands delegate heavy work to a `.mjs`
20
+ script. This plan finishes the job for the cluster that still makes the AI ingest
21
+ **full raw artifacts**.
22
+
23
+ ## 2. Where the tokens go (the audit)
24
+
25
+ A pass over `templates/claude/commands/` (65 files) + the boot hook found three cost
26
+ shapes:
27
+
28
+ | Shape | Where | Why it's expensive |
29
+ | --- | --- | --- |
30
+ | **Read N raw session logs** | `/distill-sessions`, `/retro`, `/tune-agents` | last ~10 logs = 1,100–1,300 lines (~13–16K tok) **before any reasoning** |
31
+ | **Overlapping multi-file reads** | `/dev-start`, `/state`, `/ship` | each re-reads latest session + `[Unreleased]` + `CLAUDE.md` rules (+ADRs); also 3–5 sequential round-trips |
32
+ | **ADR discovery** | many flows ("read the relevant ADR") | 26 ADRs × ~110 lines; finding the right one by reading 3–5 ≈ 10–13K tok |
33
+ | **Boot banner** | `session-start.mjs` (every session) | injects 60 raw lines of the last session, **every session**, from turn 1 |
34
+
35
+ Already efficient (no action): `/audit`, `/deep-analysis`, `/deps-audit`,
36
+ `/contract-check`, `/dashboard`, `/stats`, `/pipeline`, `/token-report`, the forge/
37
+ vcs/setup families — all script-backed.
38
+
39
+ ## 3. The fix (four pieces, one shared library)
40
+
41
+ Per ADR-0027 — each piece has a concrete existing consumer (Rule 9), reuses one
42
+ single-source extractor (Rule 4), stays zero-dep (Rule 1), and degrades to raw on any
43
+ parse miss (Rule 2/8):
44
+
45
+ 1. **`lib/digest/`** — pure shared extractor (session log → compact record; ADR →
46
+ `{number,title,status,decision1line}`). Used by the boot hook **and** the scripts.
47
+ 2. **`session-digest.mjs`** — session logs → ~12–18 line digest (`--last N`/`--id`/
48
+ `--json`). Rewires `/distill-sessions`, `/retro`, `/tune-agents`.
49
+ 3. **`adr-digest.mjs`** — ~26-line ADR catalog + `--search`. Wires into `/ship`,
50
+ `/dev-start`, `/new-adr`, `/deep-analysis`.
51
+ 4. **`context-pack.mjs`** — one bounded "start of work" bundle. Collapses
52
+ `/dev-start`/`/state`/`/ship` pre-reads into one call.
53
+ 5. **Boot rewire** — 60 raw lines → ~12-line digest, with raw-truncated fallback.
54
+
55
+ ## 4. Estimated token savings
56
+
57
+ **Assumptions (stated honestly):** ~12 input tokens per dense markdown line; figures
58
+ are **input/ingest** tokens (reasoning + output unaffected); prompt caching already
59
+ discounts re-reads inside a warm window, so the *realized* saving is largest on cold
60
+ and **cross-session** reads — the digest shrinks the bytes regardless. Frequencies are
61
+ for a single active project in a week; scale per your cadence. These are
62
+ **order-of-magnitude estimates**, provable after the fact with `/token-report --json`.
63
+
64
+ | Command / surface | Raw ingest today | With digest | Saved / run | ~Freq/wk | Weekly |
65
+ | --- | ---: | ---: | ---: | ---: | ---: |
66
+ | `/distill-sessions` | ~1,200 ln ≈ 14K | ~150 ln ≈ 1.8K | **~12K** | 2 | ~24K |
67
+ | `/retro` | ~1,300 ln ≈ 15K | ~250 ln ≈ 3K | **~12K** | 1 | ~12K |
68
+ | `/tune-agents` | ~1,100 ln ≈ 13K | ~200 ln ≈ 2.5K | **~10K** | 1 | ~10K |
69
+ | `/dev-start` (step 2) | ~160 ln ≈ 2K | ~55 ln ≈ 0.7K | **~1.3K** | 15 | ~20K |
70
+ | `/state` | ~150 ln ≈ 1.8K | ~50 ln ≈ 0.6K | **~1.2K** | 10 | ~12K |
71
+ | `/ship` pre-read + ADRs | ~350 ln ≈ 4.5K | ~80 ln ≈ 1K | **~3.5K** | 4 | ~14K |
72
+ | ADR discovery (ad hoc) | ~330 ln ≈ 4K | ~136 ln ≈ 1.7K | **~2.3K** | 15 | ~35K |
73
+ | **Boot banner** (per session) | 60 ln ≈ 0.7K | 12 ln ≈ 0.15K | **~0.55K** | 35 | ~19K |
74
+ | | | | | **Total** | **~145K/wk** |
75
+
76
+ **Headline: ~120–200K input tokens/week** on an active project (the range covers
77
+ caching and cadence variance), order **~0.5–0.8M/month**. Two clear leaders:
78
+ - **Biggest single-run wins:** the periodic L5/L6 commands (`/distill-sessions`,
79
+ `/retro`, `/tune-agents`) — ~10–14K each, because they ingest ~10 raw logs.
80
+ - **Highest-frequency win:** the **boot digest** — small per session (~0.55K) but
81
+ paid by *every* session from turn 1.
82
+
83
+ ## 5. The agility dividend (beyond tokens)
84
+
85
+ Token count isn't the only cost — **round-trips and determinism** matter too:
86
+
87
+ - **Fewer round-trips → lower latency.** `/dev-start` step 2 is 3–4 sequential
88
+ `Read` calls today (each a turn). `context-pack.mjs` makes it **one** call. Same for
89
+ `/state` and `/ship`'s pre-read.
90
+ - **Deterministic briefings.** Extraction is regex/structure, not an AI summary — the
91
+ session *starts from the same context every time*, no run-to-run drift in what the
92
+ AI saw. Reproducible inputs → reproducible behaviour.
93
+ - **Leaner from turn 1.** The boot digest means *every* session begins with a tighter
94
+ context window, leaving more headroom before compaction kicks in.
95
+
96
+ ## 6. Rollout — smallest blast radius first, measure around it
97
+
98
+ Sequenced so each slice ships independently, with a test (Rule 3) and a re-measure:
99
+
100
+ - **Phase 0 — Baseline (measure first).** Capture `node contextkit/tools/scripts/token-report.mjs
101
+ --json` now, and note the `cache_read` share. You can't prove a saving you didn't
102
+ baseline. *(No code.)*
103
+ - **Phase 1 — Biggest single-run wins.** Build `lib/digest/` + `session-digest.mjs` +
104
+ selfcheck; rewire `/distill-sessions` and `/retro`. Highest tokens-per-run, lowest
105
+ risk (these commands are periodic, off the hot path).
106
+ - **Phase 2 — Highest-frequency win + start pack.** Rewire the boot hook to the shared
107
+ digester (with raw fallback) and ship `context-pack.mjs`; wire `/dev-start` + `/state`.
108
+ Touches the hot path → guarded by the fallback + an integration test that the boot
109
+ banner never empties.
110
+ - **Phase 3 — ADR discovery.** Ship `adr-digest.mjs`; wire `/ship`, `/new-adr`
111
+ (dup-decision check), `/deep-analysis`, `/tune-agents`.
112
+ - **Phase 4 — Re-measure & close the loop.** Re-run `/token-report`, compare actual vs
113
+ the §4 estimate, and file the predicted-vs-actual delta (the kit's predictions-review
114
+ culture). Feed any surprise into the next reducer (follow-ups in ADR-0027).
115
+
116
+ ## 7. Guardrails (don't regress the invariants)
117
+
118
+ - **Zero-dep, zero new hook** — plain scripts + one pure shared module; boot reuses the
119
+ existing hot path. (Rule 1)
120
+ - **Never break, never empty** — a digest miss falls back to the current raw-truncated
121
+ output; the boot banner can degrade but never blocks or shows nothing. (Rule 2/8)
122
+ - **Single-source** — one extractor module, used by boot *and* the scripts; no second
123
+ copy of the parser. (Rule 4)
124
+ - **Every slice ships with a test** — `selfcheck`/`integration-test` assertions,
125
+ including one that fails if the canonical session-log headings drift out of sync
126
+ with the parser. (Rule 3)
127
+ - **Deterministic, not lossy** — digests extract structure; they never let the AI
128
+ "summarize and forget". The full artifacts stay on disk, one `Read` away.
129
+
130
+ ## 8. Out of scope (deferred, per Rule 9)
131
+
132
+ Per-command/agent token attribution in `/token-report`; a DevPipeline board digest for
133
+ `/pipeline`; a general "summarize any file" digester (unsafe — only the structured
134
+ artifacts qualify); an mtime-keyed digest cache (only if extraction cost ever shows up
135
+ in a profile).
package/install.mjs ADDED
@@ -0,0 +1,273 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ContextDevKit installer — entry point + orchestration.
4
+ *
5
+ * Bootstraps the AI-assisted development platform into ANY project (greenfield
6
+ * or existing, any stack). Idempotent: re-run it to change level or pull engine
7
+ * updates. It never clobbers your own content (CLAUDE.md, memory, config
8
+ * overrides); it only overwrites the kit's own engine code and slash commands.
9
+ *
10
+ * The mechanics live in focused modules under `tools/install/` (cli, fs,
11
+ * project, git, uninstall); this file just wires the steps together.
12
+ * Run `node install.mjs --help` for usage and the full flag list.
13
+ *
14
+ * Cohesion note (line budget): this file is intentionally a single linear
15
+ * orchestrator — the ordered install steps (settings → engine → commands →
16
+ * agents → memory seeds → GitHub → git hooks → config) share one `target` +
17
+ * `report` and must run in sequence. Splitting the sequence into more modules
18
+ * would scatter the one thing this file exists to express (the install order)
19
+ * and add indirection without reducing real complexity. The heavy lifting is
20
+ * already delegated to `tools/install/*`; what remains is the recipe.
21
+ */
22
+ import { existsSync } from 'node:fs';
23
+ import { dirname, resolve, join } from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+ import { createInterface } from 'node:readline/promises';
26
+ import { composeSettings } from './templates/contextkit/runtime/config/settings-compose.mjs';
27
+ import { applyPreset, listPresets } from './templates/contextkit/runtime/config/presets.mjs';
28
+ import { ensureDir, read, writeIfMissing, overwrite, copyTree, copyTreeIfMissing, render } from './tools/install/fs.mjs';
29
+ import { detectStack, requireBasename, looksGreenfield } from './tools/install/project.mjs';
30
+ import { installGitHooks, patchGitignore, patchGitattributes } from './tools/install/git.mjs';
31
+ import { uninstall } from './tools/install/uninstall.mjs';
32
+ import { isValidLevel } from './templates/contextkit/runtime/config/levels.mjs';
33
+ import { parseArgs, HELP, prompt, LEVEL_LABELS } from './tools/install/cli.mjs';
34
+
35
+ const KIT_ROOT = dirname(fileURLToPath(import.meta.url));
36
+ const TPL = resolve(KIT_ROOT, 'templates');
37
+
38
+ async function kitVersion() {
39
+ try {
40
+ return JSON.parse(await read(join(KIT_ROOT, 'package.json'))).version ?? '0.0.0';
41
+ } catch {
42
+ return '0.0.0';
43
+ }
44
+ }
45
+
46
+ async function main() {
47
+ const args = parseArgs(process.argv.slice(2));
48
+
49
+ if (args.help) {
50
+ console.log(HELP);
51
+ return;
52
+ }
53
+ if (args.version) {
54
+ console.log(`contextdevkit ${await kitVersion()}`);
55
+ return;
56
+ }
57
+
58
+ const target = resolve(args.target || process.cwd());
59
+ await ensureDir(target);
60
+
61
+ if (args.uninstall) {
62
+ await uninstall(target, args.purge);
63
+ return;
64
+ }
65
+
66
+ const interactive = !args.yes && process.stdout.isTTY;
67
+ let level = Number.isInteger(args.level) ? args.level : undefined;
68
+ let name = args.name;
69
+ let mode = args.mode;
70
+
71
+ if (interactive) {
72
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
73
+ console.log('\n🌀 ContextDevKit installer\n');
74
+ console.log(`Target: ${target}\n`);
75
+ if (!name) name = await prompt(rl, 'Project name', requireBasename(target));
76
+ if (!mode) {
77
+ const auto = looksGreenfield(target) ? 'greenfield' : 'existing';
78
+ mode = await prompt(rl, 'Mode (greenfield/existing)', auto);
79
+ }
80
+ if (!level) {
81
+ console.log('\nLevels:');
82
+ for (const [k, v] of Object.entries(LEVEL_LABELS)) console.log(` ${k}. ${v}`);
83
+ level = Number(await prompt(rl, '\nStart at level', String(mode === 'greenfield' ? 3 : 7)));
84
+ }
85
+ rl.close();
86
+ }
87
+
88
+ // Recommended starting level by project type: L3 for greenfield, L7 for a project
89
+ // that already has code (full toolkit; gates stay inert until configured). [ADR-0009]
90
+ const effMode = mode === 'greenfield' || mode === 'existing' ? mode : looksGreenfield(target) ? 'greenfield' : 'existing';
91
+ const recommended = effMode === 'greenfield' ? 3 : 7;
92
+
93
+ // Safe re-run / update: if no explicit --level, preserve the project's current
94
+ // level (read from config) instead of silently downgrading to the default.
95
+ if (!isValidLevel(level)) {
96
+ try {
97
+ const existingCfg = JSON.parse(await read(join(target, 'contextkit', 'config.json')));
98
+ if (Number.isInteger(existingCfg.level)) level = existingCfg.level;
99
+ } catch {
100
+ /* no config yet */
101
+ }
102
+ }
103
+ level = isValidLevel(level) ? level : recommended;
104
+ name = name || requireBasename(target);
105
+ mode = effMode;
106
+
107
+ const report = [];
108
+
109
+ // 1. settings.json (always — this is the wiring).
110
+ const settingsPath = join(target, '.claude', 'settings.json');
111
+ let existingSettings = null;
112
+ if (existsSync(settingsPath)) {
113
+ try {
114
+ existingSettings = JSON.parse(await read(settingsPath));
115
+ } catch {
116
+ report.push('⚠️ existing .claude/settings.json was malformed — recreated');
117
+ }
118
+ }
119
+ await overwrite(settingsPath, JSON.stringify(composeSettings(existingSettings, level), null, 2) + '\n');
120
+ report.push(`✓ .claude/settings.json wired for L${level}`);
121
+
122
+ if (args.rewire) {
123
+ console.log(report.join('\n'));
124
+ console.log(`\n✅ Rewired to Level ${level}. Restart Claude Code to load the new hooks.`);
125
+ return;
126
+ }
127
+
128
+ // 2. Engine: always overwrite (kit code; updates should propagate).
129
+ await copyTree(join(TPL, 'contextkit', 'runtime'), join(target, 'contextkit', 'runtime'));
130
+ await copyTree(join(TPL, 'contextkit', 'tools'), join(target, 'contextkit', 'tools'));
131
+ report.push('✓ engine installed (contextkit/runtime, contextkit/tools)');
132
+
133
+ // 3. Slash commands: always overwrite.
134
+ await copyTree(join(TPL, 'claude', 'commands'), join(target, '.claude', 'commands'));
135
+ report.push('✓ slash commands installed (.claude/commands)');
136
+
137
+ // 4. Agents + L4+ squads: only at L >= 4.
138
+ if (level >= 4) {
139
+ await copyTree(join(TPL, 'claude', 'agents'), join(target, '.claude', 'agents'));
140
+ report.push('✓ agent archetypes installed (.claude/agents)');
141
+ // agent-forge factory squad: engine code + matrix + APF templates (ADR-0012).
142
+ // Always overwrite — engine kit code, not user-editable.
143
+ await copyTree(join(TPL, 'contextkit', 'squads', 'agent-forge'), join(target, 'contextkit', 'squads', 'agent-forge'));
144
+ report.push('✓ agent-forge squad installed (contextkit/squads/agent-forge)');
145
+ }
146
+
147
+ // 5. Memory seeds: write only if missing. `.env.example` is seeded here so the
148
+ // user's edits survive re-install (ADR-0024 — media-gen credentials template).
149
+ for (const rel of ['memory/SESSIONS.md', 'memory/WORKSPACE.md', 'memory/GLOSSARY.md', 'memory/roadmap.md', 'memory/decisions/_TEMPLATE.md', 'memory/decisions/0000-record-architecture-decisions.md', 'memory/business-rules/_TEMPLATE.md', 'memory/predictions/.gitkeep', 'memory/sessions/.gitkeep', 'README.md', 'instrucoes.md', 'best-practices.md', 'behaviors.md', 'behaviors-examples.md', 'CLAUDE.child.md.tpl', 'squads/README.md', 'squads/_BRIEFING.md.tpl', '.env.example']) {
150
+ const src = join(TPL, 'contextkit', rel);
151
+ if (!existsSync(src)) continue;
152
+ const wrote = await writeIfMissing(join(target, 'contextkit', rel), await read(src), args.force);
153
+ if (wrote) report.push(`✓ seeded contextkit/${rel}`);
154
+ }
155
+ // Ensure memory dirs exist even if a packager stripped the .gitkeep seed.
156
+ await ensureDir(join(target, 'contextkit', 'memory', 'sessions'));
157
+ await ensureDir(join(target, 'contextkit', 'memory', 'decisions'));
158
+ await ensureDir(join(target, 'contextkit', 'memory', 'business-rules'));
159
+ await ensureDir(join(target, 'contextkit', 'memory', 'predictions'));
160
+ // DevPipeline scaffolding (write-if-missing so existing tasks survive re-install).
161
+ const pipeCount = await copyTreeIfMissing(join(TPL, 'contextkit', 'pipeline'), join(target, 'contextkit', 'pipeline'));
162
+ if (pipeCount > 0) report.push(`✓ seeded contextkit/pipeline (${pipeCount} file(s))`);
163
+ for (const s of ['backlog', 'testing', 'conclusion']) await ensureDir(join(target, 'contextkit', 'pipeline', s));
164
+ // Workflow guides (L1–L6) + reusable playbooks (write-if-missing so customizations survive).
165
+ const wfCount = await copyTreeIfMissing(join(TPL, 'contextkit', 'workflows'), join(target, 'contextkit', 'workflows'));
166
+ if (wfCount > 0) report.push(`✓ seeded contextkit/workflows (${wfCount} file(s))`);
167
+ // Pluggable-detector seed (README + inert example) so the extension point is discoverable.
168
+ const detCount = await copyTreeIfMissing(join(TPL, 'contextkit', 'detectors'), join(target, 'contextkit', 'detectors'));
169
+ if (detCount > 0) report.push(`✓ seeded contextkit/detectors (${detCount} file(s))`);
170
+ // Curated-stack starters (always overwrite — pure templates, no user edits expected here;
171
+ // /aidevtool-from0 copies them OUT of contextkit/starters/ into the project root, not in-place).
172
+ await copyTree(join(TPL, 'contextkit', 'starters'), join(target, 'contextkit', 'starters'));
173
+ report.push('✓ curated-stack starters installed (contextkit/starters)');
174
+
175
+ // 6. config.json: create with level + first-run flag, or update level
176
+ // (preserving an already-completed setup so re-installs don't re-trigger).
177
+ const cfgPath = join(target, 'contextkit', 'config.json');
178
+ const preset = args.preset && listPresets().includes(args.preset) ? args.preset : null;
179
+ if (args.preset && !preset) report.push(`⚠️ unknown --preset "${args.preset}" (have: ${listPresets().join(', ')}) — ignored`);
180
+ if (existsSync(cfgPath)) {
181
+ try {
182
+ let cfg = JSON.parse(await read(cfgPath));
183
+ cfg.level = level;
184
+ if (cfg.setup?.completed !== true) cfg.setup = { completed: false, installedAt: new Date().toISOString() };
185
+ if (preset) cfg = applyPreset(cfg, preset);
186
+ await overwrite(cfgPath, JSON.stringify(cfg, null, 2) + '\n');
187
+ report.push(`✓ updated contextkit/config.json level → ${level}${preset ? ` (+preset ${preset})` : ''}`);
188
+ } catch {
189
+ /* leave malformed file for the user */
190
+ }
191
+ } else {
192
+ let cfg = JSON.parse(await read(join(TPL, 'contextkit', 'config.json')));
193
+ cfg.level = level;
194
+ cfg.setup = { completed: false, installedAt: new Date().toISOString() };
195
+ if (preset) cfg = applyPreset(cfg, preset);
196
+ await overwrite(cfgPath, JSON.stringify(cfg, null, 2) + '\n');
197
+ report.push(`✓ created contextkit/config.json (level ${level}, first-run pending${preset ? `, preset ${preset}` : ''})`);
198
+ }
199
+
200
+ // 7. CLAUDE.md: render if missing; else drop a side file to merge.
201
+ // On --update we NEVER touch CLAUDE.md (it's user-owned content).
202
+ const claudePath = join(target, 'CLAUDE.md');
203
+ if (args.update && existsSync(claudePath)) {
204
+ /* update: leave the user's CLAUDE.md untouched */
205
+ } else {
206
+ const claudeTpl = await read(join(TPL, 'CLAUDE.md.tpl'));
207
+ const claudeOut = render(claudeTpl, {
208
+ PROJECT_NAME: name,
209
+ DATE: new Date().toISOString().slice(0, 10),
210
+ LEVEL: String(level),
211
+ MODE: mode,
212
+ STACK_NOTES: mode === 'existing' ? await detectStack(target) : 'Greenfield — define the stack as the first architectural decision (`/new-adr`).',
213
+ });
214
+ if (!existsSync(claudePath) || args.force) {
215
+ await overwrite(claudePath, claudeOut);
216
+ report.push('✓ CLAUDE.md created');
217
+ } else {
218
+ await overwrite(join(target, 'CLAUDE.contextdevkit.md'), claudeOut);
219
+ report.push('⚠️ CLAUDE.md exists — wrote CLAUDE.contextdevkit.md to merge by hand');
220
+ }
221
+ }
222
+
223
+ // 8. CHANGELOG: render if missing.
224
+ const changelogPath = join(target, 'docs', 'CHANGELOG.md');
225
+ if (!existsSync(changelogPath)) {
226
+ const clTpl = await read(join(TPL, 'docs', 'CHANGELOG.md.tpl'));
227
+ await overwrite(changelogPath, render(clTpl, { PROJECT_NAME: name, DATE: new Date().toISOString().slice(0, 10) }));
228
+ report.push('✓ docs/CHANGELOG.md created');
229
+ }
230
+
231
+ // 9. .gitignore + .gitattributes + GitHub templates + git hooks.
232
+ if (await patchGitignore(target)) report.push('✓ .gitignore patched');
233
+ if (await patchGitattributes(target, TPL)) report.push('✓ .gitattributes patched (LF for engine scripts)');
234
+ const ghCount = await copyTreeIfMissing(join(TPL, 'github'), join(target, '.github'));
235
+ if (ghCount > 0) report.push(`✓ ${ghCount} GitHub template(s) added to .github/`);
236
+ if (level >= 3) {
237
+ const gitHooks = await installGitHooks(target);
238
+ if (gitHooks.installed) {
239
+ report.push('✓ git hooks installed (pre-commit, commit-msg, pre-push)');
240
+ if (gitHooks.backedUp.length) report.push(` ↳ backed up your existing ${gitHooks.backedUp.join(', ')} hook(s) → *.bak`);
241
+ } else report.push('ℹ️ no .git found — run `git init` then re-run to install git hooks');
242
+ }
243
+ // Version-control hint: suggest connecting a remote if there isn't one.
244
+ if (!existsSync(join(target, '.git')) || !(await read(join(target, '.git', 'config')).catch(() => '')).includes('[remote "origin"]')) {
245
+ report.push('ℹ️ no git remote — run /git setup-remote to connect GitHub/GitLab/other (+ CLI)');
246
+ }
247
+
248
+ // ── summary ──
249
+ console.log('\n' + report.join('\n'));
250
+ if (args.update) {
251
+ console.log(`\n✅ ContextDevKit UPDATED to v${await kitVersion()} (Level ${level} preserved) in ${target}`);
252
+ console.log(' Refreshed: engine + slash commands + hook wiring. Untouched: CLAUDE.md, config,');
253
+ console.log(' memory (ADRs/sessions/roadmap), pipeline tasks, scoped module CLAUDE.md files.');
254
+ console.log(' Restart Claude Code to load the refreshed hooks.');
255
+ console.log('');
256
+ return;
257
+ }
258
+ console.log(`\n✅ ContextDevKit installed at Level ${level} into ${target}`);
259
+ console.log('\nNext steps:');
260
+ console.log(' 1. Open the project in Claude Code (it reads .claude/ + CLAUDE.md).');
261
+ console.log(' 2. Approve the hooks on first run (one-time per hook).');
262
+ console.log(' 3. ⭐ Run /setupcontextdevkit — it fits the kit to THIS project');
263
+ console.log(' (detects stack, tunes config, fills CLAUDE.md, flags risks).');
264
+ console.log(' The first-run trigger will remind you automatically.');
265
+ console.log(' 4. Then work normally. /log-session at the end.');
266
+ if (level < 5) console.log(` 5. Level up later: /context-level ${Math.min(level + 1, 5)}`);
267
+ console.log('');
268
+ }
269
+
270
+ main().catch((err) => {
271
+ console.error('\n❌ ContextDevKit install failed:', err?.stack || err);
272
+ process.exit(1);
273
+ });