claude-code-superkit 0.0.0-stage → 1.5.3

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 (353) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +374 -2
  3. package/bin/cli.js +153 -0
  4. package/bin/inject-tokens.js +224 -0
  5. package/bin/measure-tokens.js +17 -0
  6. package/bin/superkit-counts-verify.sh +30 -0
  7. package/lib/codex.js +246 -0
  8. package/lib/docs-scaffold.js +147 -0
  9. package/lib/installer.js +499 -0
  10. package/lib/prompts.js +51 -0
  11. package/lib/settings-builder.js +51 -0
  12. package/lib/superpowers.js +99 -0
  13. package/lib/utils.js +117 -0
  14. package/lib/validator.js +84 -0
  15. package/package.json +49 -4
  16. package/packages/codex/AGENTS.md +396 -0
  17. package/packages/codex/INSTALL.md +342 -0
  18. package/packages/codex/config.toml +22 -0
  19. package/packages/codex/hooks/superkit.mjs +203 -0
  20. package/packages/codex/hooks.json +30 -0
  21. package/packages/codex/legacy-baseline.json +88 -0
  22. package/packages/codex/native-skills.txt +65 -0
  23. package/packages/codex/rules/default.rules +565 -0
  24. package/packages/codex/skills/ai-slop-cleaner/SKILL.md +44 -0
  25. package/packages/codex/skills/api-contract-sync/SKILL.md +96 -0
  26. package/packages/codex/skills/architect/SKILL.md +49 -0
  27. package/packages/codex/skills/audit-backend/SKILL.md +80 -0
  28. package/packages/codex/skills/audit-frontend/SKILL.md +82 -0
  29. package/packages/codex/skills/audit-infra/SKILL.md +87 -0
  30. package/packages/codex/skills/audit-orchestrator/SKILL.md +114 -0
  31. package/packages/codex/skills/behavioral-nudge-engine/SKILL.md +110 -0
  32. package/packages/codex/skills/benchmark/SKILL.md +49 -0
  33. package/packages/codex/skills/bot-reviewer/SKILL.md +94 -0
  34. package/packages/codex/skills/code-reviewer/SKILL.md +67 -0
  35. package/packages/codex/skills/codebase-onboarding-engineer/SKILL.md +46 -0
  36. package/packages/codex/skills/comment-rot-analyzer/SKILL.md +75 -0
  37. package/packages/codex/skills/commit-helper/SKILL.md +101 -0
  38. package/packages/codex/skills/critic/SKILL.md +56 -0
  39. package/packages/codex/skills/database-reviewer/SKILL.md +79 -0
  40. package/packages/codex/skills/debug-observer/SKILL.md +107 -0
  41. package/packages/codex/skills/dependency-checker/SKILL.md +69 -0
  42. package/packages/codex/skills/design-system-reviewer/SKILL.md +121 -0
  43. package/packages/codex/skills/dev-orchestrator/SKILL.md +304 -0
  44. package/packages/codex/skills/docs-reviewer/SKILL.md +86 -0
  45. package/packages/codex/skills/drizzle-orm-expert/SKILL.md +246 -0
  46. package/packages/codex/skills/e2e-test-generator/SKILL.md +95 -0
  47. package/packages/codex/skills/evaluator/SKILL.md +63 -0
  48. package/packages/codex/skills/frontend-perf-reviewer/SKILL.md +95 -0
  49. package/packages/codex/skills/frontend-ui-color-reviewer/SKILL.md +68 -0
  50. package/packages/codex/skills/frontend-ui-design-critic/SKILL.md +99 -0
  51. package/packages/codex/skills/frontend-ui-interaction-reviewer/SKILL.md +102 -0
  52. package/packages/codex/skills/frontend-ui-motion-reviewer/SKILL.md +85 -0
  53. package/packages/codex/skills/frontend-ui-reviewer/SKILL.md +81 -0
  54. package/packages/codex/skills/frontend-ui-typography-reviewer/SKILL.md +62 -0
  55. package/packages/codex/skills/gltf-debugging/SKILL.md +128 -0
  56. package/packages/codex/skills/go-benchmark/SKILL.md +217 -0
  57. package/packages/codex/skills/go-concurrency-reviewer/SKILL.md +113 -0
  58. package/packages/codex/skills/go-error-reviewer/SKILL.md +107 -0
  59. package/packages/codex/skills/go-grpc-patterns/SKILL.md +285 -0
  60. package/packages/codex/skills/go-modernizer/SKILL.md +111 -0
  61. package/packages/codex/skills/go-observability-reviewer/SKILL.md +121 -0
  62. package/packages/codex/skills/go-performance-reviewer/SKILL.md +112 -0
  63. package/packages/codex/skills/go-reviewer/SKILL.md +109 -0
  64. package/packages/codex/skills/go-samber-do/SKILL.md +158 -0
  65. package/packages/codex/skills/go-samber-lo/SKILL.md +178 -0
  66. package/packages/codex/skills/go-samber-oops/SKILL.md +174 -0
  67. package/packages/codex/skills/goal-verifier/SKILL.md +53 -0
  68. package/packages/codex/skills/health-checker/SKILL.md +109 -0
  69. package/packages/codex/skills/html-to-3d-texture/SKILL.md +153 -0
  70. package/packages/codex/skills/impeccable-craft/SKILL.md +101 -0
  71. package/packages/codex/skills/lint-runner/SKILL.md +85 -0
  72. package/packages/codex/skills/migrate/SKILL.md +60 -0
  73. package/packages/codex/skills/migration-reviewer/SKILL.md +88 -0
  74. package/packages/codex/skills/minimal-change-engineer/SKILL.md +44 -0
  75. package/packages/codex/skills/new-migration/SKILL.md +59 -0
  76. package/packages/codex/skills/nextjs-supabase-auth/SKILL.md +227 -0
  77. package/packages/codex/skills/output-enforcement/SKILL.md +71 -0
  78. package/packages/codex/skills/plan-checker/SKILL.md +53 -0
  79. package/packages/codex/skills/postgresql-optimization/SKILL.md +159 -0
  80. package/packages/codex/skills/pre-deploy-validator/SKILL.md +111 -0
  81. package/packages/codex/skills/presentation-reviewer/SKILL.md +88 -0
  82. package/packages/codex/skills/product-3d-lighting/SKILL.md +137 -0
  83. package/packages/codex/skills/project-architecture/SKILL.md +52 -0
  84. package/packages/codex/skills/py-reviewer/SKILL.md +100 -0
  85. package/packages/codex/skills/r3f-scene-reviewer/SKILL.md +88 -0
  86. package/packages/codex/skills/r3f-scroll-driven-3d/SKILL.md +162 -0
  87. package/packages/codex/skills/reality-checker/SKILL.md +61 -0
  88. package/packages/codex/skills/redis-patterns/SKILL.md +260 -0
  89. package/packages/codex/skills/review-orchestrator/SKILL.md +151 -0
  90. package/packages/codex/skills/rs-reviewer/SKILL.md +98 -0
  91. package/packages/codex/skills/ru-text/SKILL.md +132 -0
  92. package/packages/codex/skills/scaffold-endpoint/SKILL.md +44 -0
  93. package/packages/codex/skills/security-scanner/SKILL.md +94 -0
  94. package/packages/codex/skills/silent-failure-hunter/SKILL.md +176 -0
  95. package/packages/codex/skills/telegram-bot-builder/SKILL.md +120 -0
  96. package/packages/codex/skills/test-generator/SKILL.md +79 -0
  97. package/packages/codex/skills/test-runner/SKILL.md +101 -0
  98. package/packages/codex/skills/threejs-color-management/SKILL.md +97 -0
  99. package/packages/codex/skills/tree-generator/SKILL.md +63 -0
  100. package/packages/codex/skills/ts-reviewer/SKILL.md +90 -0
  101. package/packages/codex/skills/ui-design-reviewer/SKILL.md +89 -0
  102. package/packages/codex/skills/ui-reviewer/SKILL.md +103 -0
  103. package/packages/codex/skills/visual-reviewer/SKILL.md +85 -0
  104. package/packages/codex/skills/writing-agents/SKILL.md +165 -0
  105. package/packages/codex/skills/writing-commands/SKILL.md +173 -0
  106. package/packages/core/CLAUDE.md +118 -0
  107. package/packages/core/INTERNAL-FILES +16 -0
  108. package/packages/core/agents/ai-slop-cleaner.md +187 -0
  109. package/packages/core/agents/api-contract-sync.md +127 -0
  110. package/packages/core/agents/architect.md +205 -0
  111. package/packages/core/agents/audit-backend.md +137 -0
  112. package/packages/core/agents/audit-frontend.md +129 -0
  113. package/packages/core/agents/audit-infra.md +182 -0
  114. package/packages/core/agents/behavioral-nudge-engine.md +170 -0
  115. package/packages/core/agents/code-reviewer.md +195 -0
  116. package/packages/core/agents/codebase-onboarding-engineer.md +172 -0
  117. package/packages/core/agents/comment-rot-analyzer.md +115 -0
  118. package/packages/core/agents/critic.md +172 -0
  119. package/packages/core/agents/database-reviewer.md +201 -0
  120. package/packages/core/agents/debug-observer.md +261 -0
  121. package/packages/core/agents/dependency-checker.md +199 -0
  122. package/packages/core/agents/docs-reviewer.md +206 -0
  123. package/packages/core/agents/e2e-test-generator.md +261 -0
  124. package/packages/core/agents/evaluator.md +141 -0
  125. package/packages/core/agents/goal-verifier.md +130 -0
  126. package/packages/core/agents/health-checker.md +194 -0
  127. package/packages/core/agents/migration-reviewer.md +161 -0
  128. package/packages/core/agents/minimal-change-engineer.md +219 -0
  129. package/packages/core/agents/plan-checker.md +139 -0
  130. package/packages/core/agents/pre-deploy-validator.md +189 -0
  131. package/packages/core/agents/reality-checker.md +175 -0
  132. package/packages/core/agents/scaffold-endpoint.md +162 -0
  133. package/packages/core/agents/security-scanner.md +236 -0
  134. package/packages/core/agents/silent-failure-hunter.md +276 -0
  135. package/packages/core/agents/test-generator.md +146 -0
  136. package/packages/core/agents/tree-generator.md +141 -0
  137. package/packages/core/agents/ui-reviewer.md +172 -0
  138. package/packages/core/agents/visual-reviewer.md +211 -0
  139. package/packages/core/commands/audit.md +166 -0
  140. package/packages/core/commands/benchmark.md +130 -0
  141. package/packages/core/commands/commit.md +148 -0
  142. package/packages/core/commands/dev.md +302 -0
  143. package/packages/core/commands/docs-init.md +75 -0
  144. package/packages/core/commands/lint.md +137 -0
  145. package/packages/core/commands/migrate.md +146 -0
  146. package/packages/core/commands/new-migration.md +182 -0
  147. package/packages/core/commands/pair.md +209 -0
  148. package/packages/core/commands/review.md +195 -0
  149. package/packages/core/commands/security-scan.md +142 -0
  150. package/packages/core/commands/superkit-evolve.md +231 -0
  151. package/packages/core/commands/superkit-init.md +274 -0
  152. package/packages/core/commands/test.md +108 -0
  153. package/packages/core/commands/workflow.md +150 -0
  154. package/packages/core/docs/guide/01-getting-started.md +41 -0
  155. package/packages/core/docs-templates/README.md +33 -0
  156. package/packages/core/docs-templates/adr-template.md +62 -0
  157. package/packages/core/docs-templates/architecture/api-contracts.md +26 -0
  158. package/packages/core/docs-templates/architecture/api-reference.md +48 -0
  159. package/packages/core/docs-templates/architecture/auth-and-sessions.md +38 -0
  160. package/packages/core/docs-templates/architecture/backend-layers.md +42 -0
  161. package/packages/core/docs-templates/architecture/data-flow.md +26 -0
  162. package/packages/core/docs-templates/architecture/database-schema.md +51 -0
  163. package/packages/core/docs-templates/architecture/deployment.md +41 -0
  164. package/packages/core/docs-templates/architecture/frontend-state.md +46 -0
  165. package/packages/core/helpers/statusline.cjs +370 -0
  166. package/packages/core/hooks/CHAIN-SEMANTICS.md +84 -0
  167. package/packages/core/hooks/audit-settings-source.sh +98 -0
  168. package/packages/core/hooks/audit-trail.sh +120 -0
  169. package/packages/core/hooks/block-dangerous-git.sh +189 -0
  170. package/packages/core/hooks/bundle-import-check.sh +64 -0
  171. package/packages/core/hooks/compact-state-inject.sh +84 -0
  172. package/packages/core/hooks/config-protection.sh +68 -0
  173. package/packages/core/hooks/console-log-warning.sh +28 -0
  174. package/packages/core/hooks/context-monitor.sh +35 -0
  175. package/packages/core/hooks/dev-edit-counter.sh +59 -0
  176. package/packages/core/hooks/dev-marker-set.sh +55 -0
  177. package/packages/core/hooks/dev-required-on-commit.sh +426 -0
  178. package/packages/core/hooks/doc-check-on-commit.sh +396 -0
  179. package/packages/core/hooks/edit-streak-check.sh +63 -0
  180. package/packages/core/hooks/evolve-check.sh +78 -0
  181. package/packages/core/hooks/gateguard-pre-edit.sh +154 -0
  182. package/packages/core/hooks/gateguard-record-facts.sh +37 -0
  183. package/packages/core/hooks/intake-classifier.py +449 -0
  184. package/packages/core/hooks/lib/profile.sh +141 -0
  185. package/packages/core/hooks/loop-guard.sh +75 -0
  186. package/packages/core/hooks/migration-safety.sh +56 -0
  187. package/packages/core/hooks/plan-completion-gate.sh +61 -0
  188. package/packages/core/hooks/pre-compact-save.sh +89 -0
  189. package/packages/core/hooks/security-patterns.sh +119 -0
  190. package/packages/core/hooks/session-context-restore.sh +76 -0
  191. package/packages/core/hooks/subagent-stop-validate.sh +73 -0
  192. package/packages/core/hooks/superkit-counts-verify.sh +346 -0
  193. package/packages/core/hooks/superkit-update.sh +367 -0
  194. package/packages/core/hooks/tests/README.md +42 -0
  195. package/packages/core/hooks/tests/audit-trail-chain_test.sh +62 -0
  196. package/packages/core/hooks/tests/block-dangerous-git_test.sh +144 -0
  197. package/packages/core/hooks/tests/chain-semantics/h1.sh +11 -0
  198. package/packages/core/hooks/tests/chain-semantics/h2.sh +9 -0
  199. package/packages/core/hooks/tests/chain-semantics/h3.sh +11 -0
  200. package/packages/core/hooks/tests/chain-semantics/run-experiment.sh +65 -0
  201. package/packages/core/hooks/tests/chain-semantics/settings-experiment.json +15 -0
  202. package/packages/core/hooks/tests/counts-verify_test.sh +118 -0
  203. package/packages/core/hooks/tests/dev-required-on-commit_test.sh +207 -0
  204. package/packages/core/hooks/tests/dev-required-wip-on-main_test.sh +20 -0
  205. package/packages/core/hooks/tests/doc-check-on-commit_test.sh +122 -0
  206. package/packages/core/hooks/tests/edit-streak-check_test.sh +106 -0
  207. package/packages/core/hooks/tests/internal-manifest_test.sh +130 -0
  208. package/packages/core/hooks/tests/json-path_test.sh +108 -0
  209. package/packages/core/hooks/tests/mirror-invariants_test.sh +139 -0
  210. package/packages/core/hooks/tests/nudge-throttle_test.sh +95 -0
  211. package/packages/core/hooks/tests/profile-helper_test.sh +21 -0
  212. package/packages/core/hooks/tests/run-all.sh +47 -0
  213. package/packages/core/hooks/tests/session-key-helper_test.sh +17 -0
  214. package/packages/core/hooks/tests/superkit-update_test.sh +311 -0
  215. package/packages/core/hooks/tests/warn-visibility_test.sh +59 -0
  216. package/packages/core/hooks/user-intent-detect.sh +44 -0
  217. package/packages/core/hooks/verify-hooks.sh +69 -0
  218. package/packages/core/rules/auto-commands.md +124 -0
  219. package/packages/core/rules/coding-style.md +68 -0
  220. package/packages/core/rules/dev-workflow.md +77 -0
  221. package/packages/core/rules/documentation.md +106 -0
  222. package/packages/core/rules/frontend-aesthetics.md +53 -0
  223. package/packages/core/rules/git-workflow.md +14 -0
  224. package/packages/core/rules/security.md +29 -0
  225. package/packages/core/rules/superkit-integrity.md +114 -0
  226. package/packages/core/settings.json +229 -0
  227. package/packages/core/skills/drizzle-orm-expert/SKILL.md +260 -0
  228. package/packages/core/skills/nextjs-supabase-auth/SKILL.md +259 -0
  229. package/packages/core/skills/postgresql-optimization/SKILL.md +150 -0
  230. package/packages/core/skills/project-architecture/SKILL.md +31 -0
  231. package/packages/core/skills/project-scanner/SKILL.md +132 -0
  232. package/packages/core/skills/redis-patterns/SKILL.md +261 -0
  233. package/packages/core/skills/ru-text/SKILL.md +156 -0
  234. package/packages/core/skills/telegram-bot-builder/SKILL.md +145 -0
  235. package/packages/core/skills/writing-agents/SKILL.md +220 -0
  236. package/packages/core/skills/writing-commands/SKILL.md +176 -0
  237. package/packages/core/skills/writing-hooks/SKILL.md +335 -0
  238. package/packages/extras/bot-reviewer.md +279 -0
  239. package/packages/extras/design-system-reviewer.md +234 -0
  240. package/packages/extras/red-blue-auditor/README.md +117 -0
  241. package/packages/extras/red-blue-auditor/agent.md +128 -0
  242. package/packages/extras/red-blue-auditor/patterns/agent-config.txt +4 -0
  243. package/packages/extras/red-blue-auditor/patterns/hook-injection.txt +8 -0
  244. package/packages/extras/red-blue-auditor/patterns/mcp-risk.txt +5 -0
  245. package/packages/extras/red-blue-auditor/patterns/permission-abuse.txt +6 -0
  246. package/packages/extras/red-blue-auditor/patterns/secrets.txt +17 -0
  247. package/packages/extras/red-blue-auditor/scan.sh +88 -0
  248. package/packages/extras/skillsmp-search/SKILL.md +134 -0
  249. package/packages/frontend-3d/README.md +62 -0
  250. package/packages/frontend-3d/agents/frontend-perf-reviewer.md +164 -0
  251. package/packages/frontend-3d/agents/presentation-reviewer.md +146 -0
  252. package/packages/frontend-3d/agents/r3f-scene-reviewer.md +128 -0
  253. package/packages/frontend-3d/agents/ui-design-reviewer.md +169 -0
  254. package/packages/frontend-3d/commands/capture-screen.md +166 -0
  255. package/packages/frontend-3d/hooks/bundle-size-warn.sh +93 -0
  256. package/packages/frontend-3d/hooks/gsap-pattern-check.sh +74 -0
  257. package/packages/frontend-3d/hooks/r3f-color-check.sh +76 -0
  258. package/packages/frontend-3d/hooks/tailwind-version-guard.sh +98 -0
  259. package/packages/frontend-3d/rules/frontend-aesthetics-3d.md +81 -0
  260. package/packages/frontend-3d/rules/gsap-conventions.md +129 -0
  261. package/packages/frontend-3d/rules/threejs-conventions.md +116 -0
  262. package/packages/frontend-3d/skills/gltf-debugging/SKILL.md +145 -0
  263. package/packages/frontend-3d/skills/html-to-3d-texture/SKILL.md +183 -0
  264. package/packages/frontend-3d/skills/output-enforcement/SKILL.md +79 -0
  265. package/packages/frontend-3d/skills/product-3d-lighting/SKILL.md +166 -0
  266. package/packages/frontend-3d/skills/r3f-scroll-driven-3d/SKILL.md +209 -0
  267. package/packages/frontend-3d/skills/threejs-color-management/SKILL.md +111 -0
  268. package/packages/frontend-ui/NOTICE.md +99 -0
  269. package/packages/frontend-ui/README.md +59 -0
  270. package/packages/frontend-ui/agents/ui-color-reviewer.md +174 -0
  271. package/packages/frontend-ui/agents/ui-design-critic.md +198 -0
  272. package/packages/frontend-ui/agents/ui-interaction-reviewer.md +259 -0
  273. package/packages/frontend-ui/agents/ui-motion-reviewer.md +266 -0
  274. package/packages/frontend-ui/agents/ui-reviewer.md +251 -0
  275. package/packages/frontend-ui/agents/ui-typography-reviewer.md +222 -0
  276. package/packages/frontend-ui/hooks/tests/ui-animation-easing-check_test.sh +78 -0
  277. package/packages/frontend-ui/hooks/tests/ui-banned-fonts-check_test.sh +77 -0
  278. package/packages/frontend-ui/hooks/tests/ui-color-check_test.sh +75 -0
  279. package/packages/frontend-ui/hooks/ui-animation-easing-check.sh +86 -0
  280. package/packages/frontend-ui/hooks/ui-banned-fonts-check.sh +90 -0
  281. package/packages/frontend-ui/hooks/ui-color-check.sh +102 -0
  282. package/packages/frontend-ui/rules/color-and-contrast.md +230 -0
  283. package/packages/frontend-ui/rules/frontend-design-aesthetics.md +124 -0
  284. package/packages/frontend-ui/rules/interaction-polish.md +335 -0
  285. package/packages/frontend-ui/rules/motion-and-animation.md +283 -0
  286. package/packages/frontend-ui/rules/spatial-and-layout.md +212 -0
  287. package/packages/frontend-ui/rules/typography-guidelines.md +185 -0
  288. package/packages/frontend-ui/rules/ui-anti-patterns.md +309 -0
  289. package/packages/frontend-ui/settings.json +24 -0
  290. package/packages/frontend-ui/skills/impeccable-craft/SKILL.md +187 -0
  291. package/packages/gan/README.md +232 -0
  292. package/packages/gan/agents/gan-evaluator.md +214 -0
  293. package/packages/gan/agents/gan-generator.md +171 -0
  294. package/packages/gan/agents/gan-planner.md +206 -0
  295. package/packages/gan/rubrics/functionality.md +66 -0
  296. package/packages/gan/rubrics/ui-quality.md +77 -0
  297. package/packages/gan/skills/gan-evaluator/SKILL.md +91 -0
  298. package/packages/gan/skills/gan-generator/SKILL.md +72 -0
  299. package/packages/gan/skills/gan-planner/SKILL.md +93 -0
  300. package/packages/stack-agents/go/go-concurrency-reviewer.md +210 -0
  301. package/packages/stack-agents/go/go-error-reviewer.md +187 -0
  302. package/packages/stack-agents/go/go-modernizer.md +160 -0
  303. package/packages/stack-agents/go/go-observability-reviewer.md +185 -0
  304. package/packages/stack-agents/go/go-performance-reviewer.md +160 -0
  305. package/packages/stack-agents/go/go-reviewer.md +277 -0
  306. package/packages/stack-agents/go/references/benchmark-methodology.md +280 -0
  307. package/packages/stack-agents/go/references/channel-patterns.md +384 -0
  308. package/packages/stack-agents/go/references/cli-cobra-viper.md +190 -0
  309. package/packages/stack-agents/go/references/code-style.md +262 -0
  310. package/packages/stack-agents/go/references/context-propagation.md +317 -0
  311. package/packages/stack-agents/go/references/data-structures.md +315 -0
  312. package/packages/stack-agents/go/references/database-patterns.md +334 -0
  313. package/packages/stack-agents/go/references/design-patterns.md +411 -0
  314. package/packages/stack-agents/go/references/di-frameworks.md +146 -0
  315. package/packages/stack-agents/go/references/error-creation.md +251 -0
  316. package/packages/stack-agents/go/references/error-inspection.md +348 -0
  317. package/packages/stack-agents/go/references/error-wrapping.md +230 -0
  318. package/packages/stack-agents/go/references/gopls-driving.md +62 -0
  319. package/packages/stack-agents/go/references/goroutine-lifecycle.md +351 -0
  320. package/packages/stack-agents/go/references/graphql-patterns.md +221 -0
  321. package/packages/stack-agents/go/references/grpc-patterns.md +373 -0
  322. package/packages/stack-agents/go/references/modernize-guide.md +522 -0
  323. package/packages/stack-agents/go/references/module-management.md +191 -0
  324. package/packages/stack-agents/go/references/naming-conventions.md +176 -0
  325. package/packages/stack-agents/go/references/observability-pipeline.md +352 -0
  326. package/packages/stack-agents/go/references/performance-profiling.md +250 -0
  327. package/packages/stack-agents/go/references/refactoring-mechanics.md +127 -0
  328. package/packages/stack-agents/go/references/rest-openapi-patterns.md +160 -0
  329. package/packages/stack-agents/go/references/samber-do.md +201 -0
  330. package/packages/stack-agents/go/references/samber-libraries.md +363 -0
  331. package/packages/stack-agents/go/references/samber-lo.md +260 -0
  332. package/packages/stack-agents/go/references/samber-oops.md +200 -0
  333. package/packages/stack-agents/go/references/security-checklist.md +441 -0
  334. package/packages/stack-agents/go/references/standard-stdlib-now.md +181 -0
  335. package/packages/stack-agents/go/references/stay-updated.md +147 -0
  336. package/packages/stack-agents/go/references/structs-interfaces.md +312 -0
  337. package/packages/stack-agents/go/references/sync-primitives.md +395 -0
  338. package/packages/stack-agents/go/references/testing-patterns.md +483 -0
  339. package/packages/stack-agents/go/references/troubleshooting.md +98 -0
  340. package/packages/stack-agents/python/py-reviewer.md +194 -0
  341. package/packages/stack-agents/rust/rs-reviewer.md +188 -0
  342. package/packages/stack-agents/typescript/ts-reviewer.md +135 -0
  343. package/packages/stack-hooks/go/go-context-check-on-edit.sh +56 -0
  344. package/packages/stack-hooks/go/go-error-check-on-edit.sh +54 -0
  345. package/packages/stack-hooks/go/go-format-on-edit.sh +32 -0
  346. package/packages/stack-hooks/go/go-safety-check-on-edit.sh +54 -0
  347. package/packages/stack-hooks/go/go-vet-on-edit.sh +61 -0
  348. package/packages/stack-hooks/go/golangci-lint-on-edit.sh +54 -0
  349. package/packages/stack-hooks/python/ruff-on-edit.sh +67 -0
  350. package/packages/stack-hooks/rust/cargo-check-on-edit.sh +64 -0
  351. package/packages/stack-hooks/typescript/typecheck-on-edit.sh +76 -0
  352. package/packages/stack-rules/go/go-conventions.md +44 -0
  353. package/packages/stack-rules/go/go-safety.md +35 -0
@@ -0,0 +1,261 @@
1
+ ---
2
+ name: redis-patterns
3
+ description: Redis patterns — caching (cache-aside, write-through), sessions, pub/sub, work queues, distributed locks, data structures (sorted sets, streams, hashes). Covers ioredis, node-redis, Redis 7+. Use when designing Redis usage in Node.js/TypeScript apps
4
+ tokens: 2081
5
+ user-invocable: false
6
+ ---
7
+
8
+ # Redis Patterns
9
+
10
+ Production patterns for Redis as a cache, session store, pub/sub bus, work-queue backbone, and distributed-coordination primitive in Node.js/TypeScript (ioredis, node-redis, Redis 7+).
11
+
12
+ ## Use this skill when
13
+
14
+ - Implementing caching (cache-aside, write-through, write-back)
15
+ - Setting up pub/sub or BLPOP-based work queues
16
+ - Using Redis data structures (Sorted Sets, Streams, Hash, Sets, Lists)
17
+ - Configuring ioredis for Node.js production
18
+ - Designing key naming and TTL strategies
19
+ - Implementing distributed locks with atomic `SET NX PX`
20
+
21
+ ## Do not use this skill when
22
+
23
+ - You need a message broker with guaranteed delivery — use BullMQ, RabbitMQ, or Kafka
24
+ - The task is Redis server-level configuration / cluster setup
25
+
26
+ ## Hard Rules
27
+
28
+ 1. **TTL on every SET** — the only no-TTL exception is queue keys (persistent until consumed). Locks always carry an expiry.
29
+ 2. **SCAN, never `KEYS *`** in production — `KEYS *` blocks the server on large keyspaces.
30
+ 3. **Dedicated subscriber connection** — a connection in subscribe mode cannot issue other commands.
31
+ 4. **Error handler on every client** — an unhandled `error` event crashes the Node.js process.
32
+ 5. **BullMQ clients set `maxRetriesPerRequest: null`** — otherwise connections fail under load.
33
+ 6. **Shut down with `quit()`, not `disconnect()`** — `quit()` drains in-flight commands; `disconnect()` drops them.
34
+
35
+ ## Workflow
36
+
37
+ 1. Identify the use case: caching, pub/sub, queue, session, or rate limiting.
38
+ 2. Choose the data structure that fits the access pattern (see Data Structures table).
39
+ 3. Design keys with the `scope:entity:id` convention.
40
+ 4. Set TTL on every key; the only no-TTL exception is queue keys (Hard Rule 1) — locks always carry an expiry.
41
+ 5. Validate error handling (Hard Rule 4) and graceful shutdown (Hard Rule 6).
42
+
43
+ Done when: every key has a deliberate TTL or is a documented queue key, the client has an error handler attached before connecting, and shutdown calls `quit()`.
44
+
45
+ ## Connection (ioredis — recommended for Node.js)
46
+
47
+ ```typescript
48
+ import Redis from 'ioredis';
49
+
50
+ export const redis = new Redis({
51
+ host: process.env.REDIS_HOST,
52
+ port: 6379,
53
+ lazyConnect: true,
54
+ connectionName: 'api-server',
55
+ retryStrategy(times) {
56
+ return Math.min(times * 200, 2000);
57
+ },
58
+ });
59
+
60
+ redis.on('error', (err) => logger.error({ err }, 'redis'));
61
+ redis.on('ready', () => logger.info('redis ready'));
62
+ ```
63
+
64
+ - Singleton client; `lazyConnect` defers connection until first command
65
+ - `retryStrategy` for exponential backoff
66
+ - Separate dedicated **subscriber** connection for pub/sub (Hard Rule 3)
67
+ - **BullMQ**: set `maxRetriesPerRequest: null` (Hard Rule 5)
68
+
69
+ ## Cache-Aside Pattern
70
+
71
+ ```typescript
72
+ async function getUser(id: string): Promise<User | null> {
73
+ const key = `cache:user:${id}`;
74
+ const cached = await redis.get(key);
75
+ if (cached) return JSON.parse(cached);
76
+
77
+ const user = await db.users.findUnique({ where: { id } });
78
+ if (user) await redis.set(key, JSON.stringify(user), 'EX', 300);
79
+ return user;
80
+ }
81
+
82
+ async function invalidateUser(id: string) {
83
+ await redis.del(`cache:user:${id}`);
84
+ }
85
+ ```
86
+
87
+ TTL strategy:
88
+ - Volatile data (counters, hot lists): seconds
89
+ - Stable data (config, user profiles): minutes to hours
90
+ - Rarely-changing reference data: hours to days
91
+
92
+ Bulk invalidation: `SCAN` + `DEL` (Hard Rule 2).
93
+
94
+ ## Pub/Sub
95
+
96
+ ```typescript
97
+ // Publisher (regular connection)
98
+ await redis.publish('orders:new', JSON.stringify({ orderId: 123 }));
99
+
100
+ // Subscriber (DEDICATED connection — can't issue other commands)
101
+ const sub = new Redis({ ...config });
102
+ await sub.subscribe('orders:new');
103
+ sub.on('message', (channel, message) => {
104
+ const data = JSON.parse(message);
105
+ handleOrder(data);
106
+ });
107
+ ```
108
+
109
+ Pub/sub is fire-and-forget — messages dropped if no subscriber. For durable messaging use **Streams**.
110
+
111
+ ## BLPOP Wake Queue
112
+
113
+ ```typescript
114
+ // Producer
115
+ await redis.lpush('queue:emails', JSON.stringify(payload));
116
+
117
+ // Consumer (blocks until item arrives)
118
+ while (true) {
119
+ const [, raw] = await redis.brpop('queue:emails', 0);
120
+ await processEmail(JSON.parse(raw));
121
+ }
122
+ ```
123
+
124
+ Instant wake-up without polling. For complex queue needs use **BullMQ**, built on this primitive.
125
+
126
+ ## Data Structures
127
+
128
+ | Structure | Use case |
129
+ |-----------|----------|
130
+ | **Sorted Set** | Leaderboards, sliding-window rate limit, scheduled jobs by score |
131
+ | **Stream** (`XADD`/`XREAD`) | Event sourcing, consumer groups, persistent log |
132
+ | **Hash** (`HSET`/`HGETALL`) | Object storage with partial updates (user sessions) |
133
+ | **Set** | Unique tag membership, set operations (union, intersect, diff) |
134
+ | **List** | FIFO/LIFO queues; recent activity via `LPUSH` + `LTRIM` |
135
+
136
+ ## Batch Operations
137
+
138
+ ```typescript
139
+ // Pipeline — multiple commands, one round-trip (no atomicity)
140
+ const results = await redis
141
+ .pipeline()
142
+ .get('a')
143
+ .get('b')
144
+ .incr('counter')
145
+ .exec();
146
+
147
+ // Multi/Exec — atomic transaction (all-or-nothing)
148
+ const txResults = await redis
149
+ .multi()
150
+ .decrby('inventory:x', 1)
151
+ .lpush('orders', orderId)
152
+ .exec();
153
+ ```
154
+
155
+ Pipeline for **performance**, multi/exec for **atomicity**.
156
+
157
+ ## Distributed Locks
158
+
159
+ ```typescript
160
+ async function acquireLock(key: string, ttlMs: number, token: string): Promise<boolean> {
161
+ const r = await redis.set(key, token, 'PX', ttlMs, 'NX');
162
+ return r === 'OK';
163
+ }
164
+
165
+ const releaseScript = `
166
+ if redis.call('get', KEYS[1]) == ARGV[1] then
167
+ return redis.call('del', KEYS[1])
168
+ else
169
+ return 0
170
+ end
171
+ `;
172
+
173
+ async function releaseLock(key: string, token: string) {
174
+ await redis.eval(releaseScript, 1, key, token);
175
+ }
176
+ ```
177
+
178
+ The Lua release script prevents one process releasing another's lock. Always set expiry (the `PX` above) to prevent deadlock on crash — locks are never a no-TTL key (Hard Rule 1).
179
+
180
+ For production-grade locking with renewal use the **Redlock** algorithm or a hosted lock service.
181
+
182
+ ## Lua Scripts
183
+
184
+ `redis.defineCommand()` caches EVALSHA automatically:
185
+
186
+ ```typescript
187
+ redis.defineCommand('rateLimit', {
188
+ numberOfKeys: 1,
189
+ lua: `
190
+ local current = redis.call('incr', KEYS[1])
191
+ if current == 1 then redis.call('expire', KEYS[1], ARGV[1]) end
192
+ return current
193
+ `,
194
+ });
195
+
196
+ const count = await redis.rateLimit(`rate:${userId}`, 60);
197
+ ```
198
+
199
+ Use for atomic read-modify-write that can't be expressed with `MULTI`/`EXEC`.
200
+
201
+ ## Key Naming Convention
202
+
203
+ Pattern: `scope:entity:id`
204
+
205
+ - `session:user:123`
206
+ - `cache:products:featured`
207
+ - `lock:payment:456`
208
+ - `rate:api:user:789`
209
+ - `queue:emails:high`
210
+ - `stream:events:user-activity`
211
+
212
+ Consistent colon separator enables prefix-based scanning and invalidation.
213
+
214
+ ## TTL Strategy Guide
215
+
216
+ | Use case | Suggested TTL |
217
+ |----------|---------------|
218
+ | User session | 24h – 7 days |
219
+ | API response cache | 1 min – 1 hour |
220
+ | Rate limit window | = window size (60s for per-minute) |
221
+ | Distributed lock | Slightly longer than expected op duration |
222
+ | BLPOP queue keys | No TTL (persistent until consumed) |
223
+
224
+ ## Eviction Policies
225
+
226
+ | Policy | Behavior | Use case |
227
+ |--------|----------|----------|
228
+ | `allkeys-lru` | Evict LRU from all keys | Pure caching |
229
+ | `volatile-lru` | Evict LRU from keys with TTL | Protect persistent queues |
230
+ | `allkeys-lfu` | Evict LFU | Repeated-access patterns |
231
+ | `noeviction` | Error on write when full | Required for BullMQ |
232
+
233
+ ## Graceful Shutdown
234
+
235
+ ```typescript
236
+ process.on('SIGTERM', async () => {
237
+ await redis.quit(); // waits for pending commands
238
+ process.exit(0);
239
+ });
240
+ ```
241
+
242
+ Use `quit()`, not `disconnect()` (Hard Rule 6).
243
+
244
+ ## Common Mistakes (symptom → cause)
245
+
246
+ - Redis stalls on a large keyspace → `KEYS *` in a hot path (Hard Rule 2).
247
+ - Node.js process crashes on a connection blip → no `error` handler attached before connect (Hard Rule 4).
248
+ - "Connection in subscriber mode" errors → subscribe + commands mixed on one connection (Hard Rule 3).
249
+ - Unbounded memory growth → cache keys written without TTL (Hard Rule 1).
250
+ - Jobs lost / commands dropped on deploy → `disconnect()` in shutdown instead of `quit()` (Hard Rule 6).
251
+ - BullMQ connection failures under load → missing `maxRetriesPerRequest: null` (Hard Rule 5).
252
+
253
+ ## Recap — non-negotiables
254
+
255
+ - TTL on every SET except queue keys; locks always expire.
256
+ - SCAN, never `KEYS *`, in production.
257
+ - Dedicated subscriber connection; error handler on every client.
258
+ - BullMQ clients set `maxRetriesPerRequest: null`.
259
+ - Shutdown via `quit()`, not `disconnect()`.
260
+
261
+ Adapted from VKirill/codex-starter-kit (community skill).
@@ -0,0 +1,156 @@
1
+ ---
2
+ name: ru-text
3
+ description: Russian typography and editorial standards — quotes, dashes, NBSP, number formatting, info-style anti-patterns. Use when writing, editing, or reviewing Russian text (UI copy, articles, emails, marketing, microcopy)
4
+ tokens: 1771
5
+ user-invocable: false
6
+ ---
7
+
8
+ # ru-text — Russian Text Quality
9
+
10
+ Russian typography and editorial reference. Apply to ALL Russian-language output unless the user requests a different style.
11
+
12
+ ## Use when
13
+
14
+ - UI copy: buttons, errors, hints, empty states, microcopy
15
+ - Articles, blog posts, marketing content
16
+ - Email, messenger, business correspondence
17
+ - Reviewing existing Russian text for typography / style issues
18
+
19
+ ## Do not use when
20
+
21
+ - The output is not in Russian.
22
+ - Inside code, identifiers, URLs, file paths, or email addresses — leave machine punctuation untouched.
23
+ - The user explicitly requests a conflicting style (casual, academic, SEO, literary). Their prompt overrides these defaults on conflict — this is the Style Priority escape hatch.
24
+
25
+ ## Hard Rules
26
+
27
+ Apply to every Russian sentence you emit:
28
+
29
+ 1. Quotes: outer «ёлочки», nested „лапки“ — never ASCII straight quotes (U+0022) in the delivered text.
30
+ 2. Dashes: `—` (em) in running text, `–` (en) in ranges, `-` (hyphen) only inside words. Max 1–2 em dashes per paragraph.
31
+ 3. NBSP (U+00A0) after single-letter prepositions and between number+unit, so they never wrap alone.
32
+ 4. Numbers: decimal comma (`3,14`), thin-space digit groups (`1 000 000`).
33
+ 5. Write `ё` where it removes ambiguity (`все`/`всё`, `небо`/`нёбо`) and in proper names.
34
+ 6. Headings use sentence case, not Title Case.
35
+ 7. Cut office-speak (`являться`, `осуществлять`, `в целях`, `ввиду того что`).
36
+
37
+ ## Typography Rules Table
38
+
39
+ In every example below, `␣` marks a non-breaking space (U+00A0) — otherwise invisible.
40
+
41
+ | Rule | Wrong | Correct |
42
+ |---|---|---|
43
+ | Primary quotes: guillemets | "текст" | «текст» |
44
+ | Nested quotes: lapki (U+201C closing) | «"вложенные"» | «„вложенные“» |
45
+ | Em dash with spaces | слово - слово | слово — слово |
46
+ | En dash for ranges, no spaces | 10-15 дней | 10–15 дней |
47
+ | NBSP after single-letter prepositions | в начале (space wraps) | в␣начале |
48
+ | Ellipsis: single character | ... | … |
49
+ | Digit groups with thin spaces | 1000000 | 1 000 000 |
50
+ | Decimal comma (not dot) | 3.14 | 3,14 |
51
+ | Ordinal with hyphen | 1ый, 2ой | 1-й, 2-й |
52
+ | Numero sign | No. 5, #5 | №␣5 |
53
+ | Abbreviations with NBSP | т.д., т.е. | т.␣д., т.␣е. |
54
+ | Ruble symbol after number with NBSP | 1500 руб | 1␣500␣₽ |
55
+
56
+ ## NBSP — Critical Cases
57
+
58
+ `␣` = NBSP (U+00A0). Insert a real non-breaking space at each `␣` position; place it between:
59
+
60
+ - Single-letter prepositions and the next word: `в␣начале`, `к␣концу`, `с␣пятого`, `о␣проекте`, `у␣меня`, `и␣тогда`, `а␣потом`
61
+ - Number and unit: `5␣кг`, `1␣500␣₽`, `№␣5`
62
+ - Abbreviation parts: `т.␣д.`, `т.␣е.`, `и.␣о.`
63
+ - Initials and surname: `А.␣С.␣Пушкин`
64
+
65
+ ## Dashes — Three Different Marks
66
+
67
+ - `—` (em dash, U+2014) — in running text, between subject and predicate, before direct speech
68
+ - `–` (en dash, U+2013) — for numerical ranges: `10–15 дней`, `2024–2026`
69
+ - `-` (hyphen) — only inside compound words: `кто-то`, `по-русски`, `1-й`
70
+
71
+ **Limit:** max 1–2 em dashes per paragraph. Overuse signals weak writing.
72
+
73
+ ## Numbers and Money
74
+
75
+ | Wrong | Correct |
76
+ |---|---|
77
+ | 1500руб | 1␣500␣₽ |
78
+ | 3.14 | 3,14 |
79
+ | 1000000 | 1 000 000 |
80
+ | 50 % / 50% (context) | UI copy: `50%` · print: `50␣%` |
81
+ | 25 С | 25 °C |
82
+
83
+ **Percent:** in UI/web copy write `50%` with no space (dominant web practice). In print or formal typography use `50␣%` with NBSP (GOST / Milchin). Default to UI style for interface copy.
84
+
85
+ ## Capitalization (Russian-specific)
86
+
87
+ - Sentence case for headings (NOT title case as in English): `Как настроить уведомления` (not `Как Настроить Уведомления`)
88
+ - Days of week, months: lowercase (`понедельник`, `март`)
89
+ - Nationalities, languages: lowercase (`русский`, `англичанин`)
90
+ - Job titles: lowercase unless at start of sentence (`директор`, `менеджер`)
91
+ - Brand names: keep original casing (`iPhone`, `GitHub`)
92
+
93
+ ## Top Stop-Words to Remove or Replace
94
+
95
+ | Stop-word (Russian) | Replace with |
96
+ |---|---|
97
+ | является | — (em dash) or restructure |
98
+ | осуществлять | делать, проводить |
99
+ | в настоящее время | сейчас |
100
+ | данный | этот |
101
+ | определённый | (name the specific thing) |
102
+ | произвести оплату | оплатить |
103
+ | высококачественный | (name the specific quality) |
104
+ | был осуществлён | (active voice + actor) |
105
+ | на сегодняшний день | сегодня |
106
+ | в целях | чтобы |
107
+ | в случае если | если |
108
+ | ввиду того что | потому что |
109
+ | с целью | чтобы |
110
+ | при условии что | если |
111
+
112
+ ## UX Writing — Microcopy Rules
113
+
114
+ Example strings are shown in backticks (`` ` ``); the backticks are delimiters, not part of the copy.
115
+
116
+ - **Buttons:** verb + object — `Сохранить изменения`, `Отправить заявку` (not `Сохранение`, `Отправка`)
117
+ - **Errors:** state what went wrong + what to do — `Не удалось сохранить. Проверьте подключение и попробуйте ещё раз` (not `Ошибка сохранения`)
118
+ - **Empty states:** explain why + suggest action — `Здесь пока пусто. Создайте первый заказ` (not `Нет данных`)
119
+ - **Confirmations:** clear, no ambiguity — `Удалить заказ №␣123?` with explicit `Удалить` / `Отмена` buttons (not `OK` / `Cancel`)
120
+ - **Hints:** answer «что это» or «что делать», short — `Например, ivan@example.com` (not `Введите email`)
121
+
122
+ ## Common Anti-Patterns
123
+
124
+ 1. **Russian text with English punctuation:** ASCII straight quotes (U+0022) and hyphens (`-`) where dashes belong, instead of «ёлочки» and `—`
125
+ 2. **Missed NBSP:** `в начале` (ordinary space, wraps to a new line) instead of `в␣начале` (`␣` = NBSP) — a lone `в` at a line end reads badly on narrow screens
126
+ 3. **Decimal point instead of comma:** Russian standard is `3,14`
127
+ 4. **Double spaces:** typewriter habit; modern typography uses a single space
128
+ 5. **Title Case as in English:** Russian uses sentence case
129
+ 6. **Overuse of `являться`:** removes life from sentences — use an em dash or active verb
130
+ 7. **Office-speak:** `осуществлять`, `проводить мероприятия`, `в целях оптимизации` → plain verbs
131
+ 8. **Foreign loanwords with Russian endings:** `юзать`, `контентмейкер`, `митап` — acceptable in casual context, jarring in formal
132
+
133
+ ## Quality Checklist
134
+
135
+ Before delivering Russian text, confirm every box (`␣` = NBSP):
136
+
137
+ - [ ] Quotes: «ёлочки» primary, „лапки“ nested (U+201C closing, never ASCII)
138
+ - [ ] Dashes: — in text, – in ranges, - only in compounds; max 1–2 per paragraph
139
+ - [ ] NBSP after single-letter prepositions (в, к, с, о, у, и, а)
140
+ - [ ] Ellipsis: … (single char)
141
+ - [ ] Abbreviations: т.␣д., т.␣п. (with NBSP)
142
+ - [ ] No double spaces, no space before punctuation
143
+ - [ ] Numbers: thin spaces for groups, comma for decimal
144
+ - [ ] Currency: 1␣500␣₽ (NBSP both sides)
145
+ - [ ] Heading case: sentence case, not Title Case
146
+ - [ ] No office-speak: являться, осуществлять, в целях, ввиду
147
+
148
+ ## Recap — non-negotiables
149
+
150
+ - Outer «ёлочки», nested „лапки“ (U+201C closing) — no ASCII straight quotes in delivered text.
151
+ - Three dash marks kept distinct: — text, – ranges, - compounds; 1–2 em dashes per paragraph.
152
+ - NBSP after single-letter prepositions and inside number+unit; decimal comma; thin-space digit groups.
153
+ - Sentence-case headings; no office-speak.
154
+ - Run the Quality Checklist before delivering.
155
+
156
+ Credit: based on Arseniy Kamyshev's ru-text reference (via VKirill/codex-starter-kit). Full editorial reference at https://ru-text.org.
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: telegram-bot-builder
3
+ description: Expert in building Telegram bots — bot architecture, the Telegram Bot API, inline keyboards, conversation flows, payments, scaling. Use when the task mentions Telegram bot, bot API, tg bot, Telegraf, grammY, aiogram, pyrogram, or telethon
4
+ tokens: 1480
5
+ user-invocable: false
6
+ ---
7
+
8
+ # Telegram Bot Builder
9
+
10
+ Design and build Telegram bots — architecture, the Bot API, inline keyboards, conversation flows, payments, and scaling — with conversations that feel natural and retain users.
11
+
12
+ ## Use this skill when
13
+
14
+ - Building a new Telegram bot or extending an existing one
15
+ - Designing inline keyboards, conversation flows, or command handlers
16
+ - Planning monetization via Telegram Payments or freemium models
17
+ - Setting up webhooks, graceful shutdown, or background processing
18
+
19
+ ## Do not use this skill when
20
+
21
+ - The task is a Telegram Mini App UI — that is regular frontend web work (React/Vue running inside a WebApp), not covered by this kit's skills. This skill covers only the Bot API side.
22
+ - You need general backend architecture unrelated to Telegram APIs.
23
+
24
+ ## Hard Rules
25
+
26
+ 1. NEVER run blocking or long I/O synchronously inside a handler — Telegram enforces tight timeouts. Acknowledge immediately (`ctx.sendChatAction('typing')` or a confirmation message), then process in the background.
27
+ 2. ALWAYS call `ctx.answerCbQuery()` for every callback query, or the user sees a spinner forever.
28
+ 3. NEVER expose internal errors or stack traces in replies — register a global `bot.catch` and send a friendly message instead.
29
+ 4. ALWAYS handle the `successful_payment` event and activate the paid feature BEFORE replying.
30
+ 5. ALWAYS register `SIGINT` and `SIGTERM` handlers that stop the bot cleanly (`bot.stop()`).
31
+ 6. ALWAYS validate user input, and check usage limits before any paid or rate-limited action.
32
+ 7. Keep replies concise — Telegram users read on mobile.
33
+
34
+ ## Stack Selection (decide first)
35
+
36
+ Pick the library by detection, in order; stop at the first match:
37
+
38
+ 1. An existing bot dependency in `package.json` / `pyproject.toml` (telegraf, grammy, aiogram, python-telegram-bot, pyrogram, telethon) → keep it; do not migrate.
39
+ 2. New TypeScript/Node project → **grammY** (TypeScript-first, modern async) or **Telegraf** (mature, larger ecosystem). Prefer grammY for a fresh TS codebase; pick Telegraf if the team already knows it.
40
+ 3. New Python project → **aiogram** (async, scales) for anything beyond a prototype; **python-telegram-bot** for a quick prototype.
41
+ 4. Userbot / low-level MTProto client features (not a bot token) → **pyrogram** or **telethon**.
42
+ 5. Default when nothing above matches → grammY (Node) or aiogram (Python).
43
+
44
+ ## Bot Architecture
45
+
46
+ Separate concerns:
47
+
48
+ ```
49
+ src/
50
+ ├── bot.ts # initialization, handler registration
51
+ ├── commands/ # one file per /command
52
+ ├── handlers/ # message + callback query handlers
53
+ ├── keyboards/ # reusable inline keyboard builders
54
+ ├── middleware/ # auth, logging, rate-limit, i18n
55
+ ├── services/ # business logic, DB access
56
+ └── config.ts # env parsing
57
+ ```
58
+
59
+ `bot.ts` registers command, text, and callback query handlers, then starts the bot: `bot.launch()` (Telegraf) or `bot.start()` (grammY). Wire graceful shutdown per Hard Rule 5.
60
+
61
+ ## Inline Keyboards
62
+
63
+ Build with `Markup.inlineKeyboard()` — an array of rows, each row an array of buttons. One button per row = vertical menu; several buttons per row = a horizontal row (yes/no, pagination). Use `Markup.button.url()` for external links and payment pages.
64
+
65
+ ```typescript
66
+ import { Markup } from 'telegraf';
67
+
68
+ Markup.inlineKeyboard([
69
+ [Markup.button.callback('Option A', 'opt_a')], // vertical menu
70
+ [Markup.button.callback('Yes', 'yes'),
71
+ Markup.button.callback('No', 'no')], // one row, two buttons
72
+ [Markup.button.url('Docs', 'https://example.com')], // external link
73
+ ]);
74
+ ```
75
+
76
+ Paginated list — slice by page, then append nav buttons only when they exist:
77
+
78
+ ```typescript
79
+ function pageKeyboard(items, page, perPage) {
80
+ const start = page * perPage;
81
+ const rows = items.slice(start, start + perPage)
82
+ .map((it) => [Markup.button.callback(it.label, `pick:${it.id}`)]);
83
+ const nav = [];
84
+ if (page > 0) nav.push(Markup.button.callback('« Prev', `page:${page - 1}`));
85
+ if (start + perPage < items.length) nav.push(Markup.button.callback('Next »', `page:${page + 1}`));
86
+ if (nav.length) rows.push(nav);
87
+ return Markup.inlineKeyboard(rows);
88
+ }
89
+
90
+ bot.action(/^page:(\d+)$/, async (ctx) => {
91
+ await ctx.answerCbQuery(); // Hard Rule 2
92
+ const page = Number(ctx.match[1]);
93
+ const items = await listItems(); // your data source
94
+ await ctx.editMessageText('Page ' + (page + 1), pageKeyboard(items, page, 5));
95
+ });
96
+ ```
97
+
98
+ ## Monetization
99
+
100
+ Revenue models, ordered low → high on both effort and revenue:
101
+
102
+ 1. Ads / affiliate links — low effort, low revenue.
103
+ 2. Per-use payments — low effort, via Telegram Payments.
104
+ 3. Freemium with usage limits — medium effort, common pattern.
105
+ 4. Subscription — medium effort, needs retention work.
106
+
107
+ Telegram Payments flow: create the invoice with `ctx.replyWithInvoice({ title, description, payload, provider_token, currency, prices })`; answer the `pre_checkout_query` with `ctx.answerPreCheckoutQuery(true)`; on `successful_payment`, activate the feature before replying (Hard Rule 4).
108
+
109
+ Freemium: store per-`userId` usage in the DB, check the daily limit before each gated action, and prompt an upgrade when the limit is reached.
110
+
111
+ ## Error Handling
112
+
113
+ Register one global handler so no request times out (Hard Rule 3). Log with enough context to debug; apply rate limiting to prevent abuse.
114
+
115
+ ```typescript
116
+ bot.catch((err, ctx) => {
117
+ logger.error({ err, update: ctx.update }, 'bot error');
118
+ ctx.reply('Что-то пошло не так. Уже разбираемся.').catch(() => {});
119
+ });
120
+ ```
121
+
122
+ ## Background Processing
123
+
124
+ For work longer than Telegram's response timeout (~10s for webhooks, ~30s for long polling): acknowledge immediately (typing indicator or a "processing…" message), do the work in the background, then send or edit-in the result. For heavier loads use a queue (BullMQ, Celery, RabbitMQ) and edit the "processing…" message on completion.
125
+
126
+ ## Webhook vs Long Polling
127
+
128
+ | Aspect | Webhook | Long polling |
129
+ |--------|---------|--------------|
130
+ | Latency | Low | Higher |
131
+ | Hosting | Public HTTPS endpoint required | Any environment |
132
+ | Scaling | Horizontal (load balancer) | Single process (or distributed via shared queue) |
133
+ | Dev experience | Needs ngrok / cloudflared locally | Just run |
134
+ | Best for | Production | Local dev, low traffic |
135
+
136
+ Production: Telegraf `bot.createWebhook()` / grammY `webhookCallback()`, mounted on your web framework.
137
+
138
+ ## Recap — non-negotiables
139
+
140
+ - Never block in a handler; acknowledge long work immediately and finish it in the background.
141
+ - Answer every callback query (`ctx.answerCbQuery()`); never leak stack traces — use `bot.catch`.
142
+ - Activate paid features on `successful_payment` before replying; check usage limits before gated actions.
143
+ - Register `SIGINT`/`SIGTERM` shutdown, validate input, and keep replies short.
144
+
145
+ Adapted from vibeship-spawner-skills (Apache 2.0).