@softspark/ai-toolkit 1.0.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 (327) hide show
  1. package/AGENTS.md +412 -0
  2. package/CHANGELOG.md +68 -0
  3. package/LICENSE +21 -0
  4. package/README.md +632 -0
  5. package/action.yml +53 -0
  6. package/app/.claude-plugin/plugin.json +44 -0
  7. package/app/ARCHITECTURE.md +306 -0
  8. package/app/CLAUDE.md.template +23 -0
  9. package/app/agents/ai-engineer.md +128 -0
  10. package/app/agents/backend-specialist.md +193 -0
  11. package/app/agents/business-intelligence.md +54 -0
  12. package/app/agents/chaos-monkey.md +67 -0
  13. package/app/agents/chief-of-staff.md +51 -0
  14. package/app/agents/code-archaeologist.md +127 -0
  15. package/app/agents/code-reviewer.md +184 -0
  16. package/app/agents/command-expert.md +131 -0
  17. package/app/agents/data-analyst.md +205 -0
  18. package/app/agents/data-scientist.md +151 -0
  19. package/app/agents/database-architect.md +317 -0
  20. package/app/agents/debugger.md +238 -0
  21. package/app/agents/devops-implementer.md +194 -0
  22. package/app/agents/documenter.md +364 -0
  23. package/app/agents/explorer-agent.md +145 -0
  24. package/app/agents/fact-checker.md +172 -0
  25. package/app/agents/frontend-specialist.md +209 -0
  26. package/app/agents/game-developer.md +216 -0
  27. package/app/agents/incident-responder.md +226 -0
  28. package/app/agents/infrastructure-architect.md +127 -0
  29. package/app/agents/infrastructure-validator.md +247 -0
  30. package/app/agents/llm-ops-engineer.md +237 -0
  31. package/app/agents/mcp-expert.md +228 -0
  32. package/app/agents/mcp-server-architect.md +195 -0
  33. package/app/agents/mcp-testing-engineer.md +292 -0
  34. package/app/agents/meta-architect.md +58 -0
  35. package/app/agents/ml-engineer.md +136 -0
  36. package/app/agents/mobile-developer.md +190 -0
  37. package/app/agents/night-watchman.md +55 -0
  38. package/app/agents/nlp-engineer.md +154 -0
  39. package/app/agents/orchestrator.md +437 -0
  40. package/app/agents/performance-optimizer.md +254 -0
  41. package/app/agents/predictive-analyst.md +57 -0
  42. package/app/agents/product-manager.md +194 -0
  43. package/app/agents/project-planner.md +287 -0
  44. package/app/agents/prompt-engineer.md +103 -0
  45. package/app/agents/qa-automation-engineer.md +182 -0
  46. package/app/agents/rag-engineer.md +201 -0
  47. package/app/agents/research-synthesizer.md +138 -0
  48. package/app/agents/search-specialist.md +101 -0
  49. package/app/agents/security-architect.md +62 -0
  50. package/app/agents/security-auditor.md +293 -0
  51. package/app/agents/seo-specialist.md +111 -0
  52. package/app/agents/system-governor.md +57 -0
  53. package/app/agents/tech-lead.md +62 -0
  54. package/app/agents/technical-researcher.md +103 -0
  55. package/app/agents/test-engineer.md +264 -0
  56. package/app/constitution.md +38 -0
  57. package/app/hooks/_profile-check.sh +11 -0
  58. package/app/hooks/guard-destructive.sh +74 -0
  59. package/app/hooks/guard-path.sh +73 -0
  60. package/app/hooks/post-tool-use.sh +35 -0
  61. package/app/hooks/pre-compact.sh +31 -0
  62. package/app/hooks/quality-check.sh +22 -0
  63. package/app/hooks/quality-gate.sh +49 -0
  64. package/app/hooks/save-session.sh +24 -0
  65. package/app/hooks/session-end.sh +37 -0
  66. package/app/hooks/session-start.sh +29 -0
  67. package/app/hooks/subagent-start.sh +16 -0
  68. package/app/hooks/subagent-stop.sh +16 -0
  69. package/app/hooks/track-usage.sh +50 -0
  70. package/app/hooks/user-prompt-submit.sh +25 -0
  71. package/app/hooks.json +178 -0
  72. package/app/mcp-defaults.json +23 -0
  73. package/app/output-styles/golden-rules.md +43 -0
  74. package/app/plugins/README.md +19 -0
  75. package/app/plugins/csharp-pack/README.md +11 -0
  76. package/app/plugins/csharp-pack/plugin.json +18 -0
  77. package/app/plugins/enterprise-pack/README.md +16 -0
  78. package/app/plugins/enterprise-pack/hooks/output-style.sh +6 -0
  79. package/app/plugins/enterprise-pack/hooks/status-line.sh +8 -0
  80. package/app/plugins/enterprise-pack/plugin.json +24 -0
  81. package/app/plugins/frontend-pack/README.md +14 -0
  82. package/app/plugins/frontend-pack/plugin.json +22 -0
  83. package/app/plugins/java-pack/README.md +11 -0
  84. package/app/plugins/java-pack/plugin.json +18 -0
  85. package/app/plugins/kotlin-pack/README.md +11 -0
  86. package/app/plugins/kotlin-pack/plugin.json +18 -0
  87. package/app/plugins/memory-pack/README.md +24 -0
  88. package/app/plugins/memory-pack/hooks/observation-capture.sh +67 -0
  89. package/app/plugins/memory-pack/hooks/session-summary.sh +71 -0
  90. package/app/plugins/memory-pack/plugin.json +22 -0
  91. package/app/plugins/memory-pack/scripts/init_db.py +81 -0
  92. package/app/plugins/memory-pack/scripts/strip_private.py +22 -0
  93. package/app/plugins/memory-pack/skills/mem-search/SKILL.md +70 -0
  94. package/app/plugins/research-pack/README.md +14 -0
  95. package/app/plugins/research-pack/plugin.json +22 -0
  96. package/app/plugins/ruby-pack/README.md +11 -0
  97. package/app/plugins/ruby-pack/plugin.json +18 -0
  98. package/app/plugins/rust-pack/README.md +11 -0
  99. package/app/plugins/rust-pack/plugin.json +18 -0
  100. package/app/plugins/security-pack/README.md +15 -0
  101. package/app/plugins/security-pack/plugin.json +23 -0
  102. package/app/plugins/swift-pack/README.md +11 -0
  103. package/app/plugins/swift-pack/plugin.json +18 -0
  104. package/app/rules/claude-toolkit-rules.md +21 -0
  105. package/app/rules/git-conventions.md +5 -0
  106. package/app/rules/quality-gates.md +10 -0
  107. package/app/skills/_lib/__init__.py +1 -0
  108. package/app/skills/_lib/detect_utils.py +150 -0
  109. package/app/skills/agent-creator/SKILL.md +82 -0
  110. package/app/skills/analyze/SKILL.md +92 -0
  111. package/app/skills/analyze/scripts/complexity.py +165 -0
  112. package/app/skills/api-patterns/SKILL.md +305 -0
  113. package/app/skills/app-builder/SKILL.md +187 -0
  114. package/app/skills/architecture-audit/SKILL.md +141 -0
  115. package/app/skills/architecture-decision/SKILL.md +55 -0
  116. package/app/skills/architecture-decision/templates/adr-template.md +36 -0
  117. package/app/skills/biz-scan/SKILL.md +30 -0
  118. package/app/skills/briefing/SKILL.md +27 -0
  119. package/app/skills/build/SKILL.md +97 -0
  120. package/app/skills/build/scripts/detect-build.py +151 -0
  121. package/app/skills/chaos/SKILL.md +32 -0
  122. package/app/skills/ci/SKILL.md +77 -0
  123. package/app/skills/ci/scripts/ci-detect.py +135 -0
  124. package/app/skills/ci/templates/github-actions-node.yml +38 -0
  125. package/app/skills/ci/templates/github-actions-python.yml +42 -0
  126. package/app/skills/ci-cd-patterns/SKILL.md +299 -0
  127. package/app/skills/clean-code/SKILL.md +110 -0
  128. package/app/skills/clean-code/reference/dart.md +18 -0
  129. package/app/skills/clean-code/reference/go.md +23 -0
  130. package/app/skills/clean-code/reference/php.md +32 -0
  131. package/app/skills/clean-code/reference/python.md +180 -0
  132. package/app/skills/clean-code/reference/typescript.md +26 -0
  133. package/app/skills/command-creator/SKILL.md +83 -0
  134. package/app/skills/commit/SKILL.md +98 -0
  135. package/app/skills/commit/scripts/pre-commit-check.py +87 -0
  136. package/app/skills/commit/templates/conventional-commit.md +52 -0
  137. package/app/skills/csharp-patterns/SKILL.md +450 -0
  138. package/app/skills/database-patterns/SKILL.md +297 -0
  139. package/app/skills/debug/SKILL.md +154 -0
  140. package/app/skills/debug/scripts/error-parser.py +187 -0
  141. package/app/skills/debugging-tactics/SKILL.md +136 -0
  142. package/app/skills/deploy/SKILL.md +130 -0
  143. package/app/skills/deploy/scripts/pre_deploy_check.py +171 -0
  144. package/app/skills/deploy/templates/deployment-checklist.md +31 -0
  145. package/app/skills/design-an-interface/SKILL.md +105 -0
  146. package/app/skills/design-engineering/SKILL.md +260 -0
  147. package/app/skills/docker-devops/SKILL.md +303 -0
  148. package/app/skills/docs/SKILL.md +145 -0
  149. package/app/skills/docs/scripts/doc-inventory.py +176 -0
  150. package/app/skills/docs/templates/adr-template.md +36 -0
  151. package/app/skills/docs/templates/readme-template.md +67 -0
  152. package/app/skills/documentation-standards/SKILL.md +191 -0
  153. package/app/skills/ecommerce-patterns/SKILL.md +209 -0
  154. package/app/skills/evaluate/SKILL.md +132 -0
  155. package/app/skills/evolve/SKILL.md +27 -0
  156. package/app/skills/explain/SKILL.md +54 -0
  157. package/app/skills/explain/scripts/dependency-graph.py +215 -0
  158. package/app/skills/explore/SKILL.md +112 -0
  159. package/app/skills/explore/scripts/visualize.py +117 -0
  160. package/app/skills/fix/SKILL.md +78 -0
  161. package/app/skills/fix/scripts/error-classifier.py +191 -0
  162. package/app/skills/flutter-patterns/SKILL.md +254 -0
  163. package/app/skills/git-mastery/SKILL.md +70 -0
  164. package/app/skills/grill-me/SKILL.md +38 -0
  165. package/app/skills/health/SKILL.md +91 -0
  166. package/app/skills/health/scripts/health_check.py +162 -0
  167. package/app/skills/hive-mind/SKILL.md +56 -0
  168. package/app/skills/hook-creator/SKILL.md +107 -0
  169. package/app/skills/index/SKILL.md +74 -0
  170. package/app/skills/instinct-review/SKILL.md +77 -0
  171. package/app/skills/java-patterns/SKILL.md +442 -0
  172. package/app/skills/kotlin-patterns/SKILL.md +446 -0
  173. package/app/skills/lint/SKILL.md +103 -0
  174. package/app/skills/lint/scripts/detect-linters.py +112 -0
  175. package/app/skills/mcp-patterns/SKILL.md +270 -0
  176. package/app/skills/mem-search/SKILL.md +70 -0
  177. package/app/skills/migrate/SKILL.md +90 -0
  178. package/app/skills/migrate/scripts/migration-status.py +195 -0
  179. package/app/skills/migration-patterns/SKILL.md +260 -0
  180. package/app/skills/night-watch/SKILL.md +28 -0
  181. package/app/skills/observability-patterns/SKILL.md +203 -0
  182. package/app/skills/onboard/SKILL.md +76 -0
  183. package/app/skills/orchestrate/SKILL.md +86 -0
  184. package/app/skills/panic/SKILL.md +30 -0
  185. package/app/skills/performance-profiling/SKILL.md +59 -0
  186. package/app/skills/plan/SKILL.md +110 -0
  187. package/app/skills/plan/templates/plan-template.md +40 -0
  188. package/app/skills/plan-writing/SKILL.md +201 -0
  189. package/app/skills/plugin-creator/SKILL.md +78 -0
  190. package/app/skills/pr/SKILL.md +129 -0
  191. package/app/skills/pr/scripts/pr-summary.py +175 -0
  192. package/app/skills/prd-to-issues/SKILL.md +108 -0
  193. package/app/skills/prd-to-plan/SKILL.md +120 -0
  194. package/app/skills/predict/SKILL.md +30 -0
  195. package/app/skills/qa-session/SKILL.md +110 -0
  196. package/app/skills/rag-patterns/SKILL.md +203 -0
  197. package/app/skills/refactor/SKILL.md +124 -0
  198. package/app/skills/refactor/scripts/refactor-scan.py +210 -0
  199. package/app/skills/refactor-plan/SKILL.md +112 -0
  200. package/app/skills/repeat/SKILL.md +149 -0
  201. package/app/skills/research-mastery/SKILL.md +56 -0
  202. package/app/skills/review/SKILL.md +141 -0
  203. package/app/skills/review/scripts/diff-analyzer.py +170 -0
  204. package/app/skills/rollback/SKILL.md +87 -0
  205. package/app/skills/rollback/scripts/rollback_info.py +149 -0
  206. package/app/skills/ruby-patterns/SKILL.md +454 -0
  207. package/app/skills/rust-patterns/SKILL.md +446 -0
  208. package/app/skills/search/SKILL.md +64 -0
  209. package/app/skills/security-patterns/SKILL.md +91 -0
  210. package/app/skills/security-patterns/reference/authentication.md +37 -0
  211. package/app/skills/security-patterns/reference/authorization.md +22 -0
  212. package/app/skills/security-patterns/reference/input-validation.md +30 -0
  213. package/app/skills/security-patterns/reference/oauth-csrf-audit.md +131 -0
  214. package/app/skills/skill-creator/SKILL.md +154 -0
  215. package/app/skills/skill-creator/templates/dashboard/index.html +130 -0
  216. package/app/skills/skill-creator/templates/reasoning-engine/assets/example.json +12 -0
  217. package/app/skills/skill-creator/templates/reasoning-engine/search.py +110 -0
  218. package/app/skills/subagent-development/SKILL.md +225 -0
  219. package/app/skills/subagent-development/reference/code-quality-reviewer-prompt.md +145 -0
  220. package/app/skills/subagent-development/reference/implementer-prompt.md +118 -0
  221. package/app/skills/subagent-development/reference/spec-reviewer-prompt.md +100 -0
  222. package/app/skills/swarm/SKILL.md +81 -0
  223. package/app/skills/swift-patterns/SKILL.md +500 -0
  224. package/app/skills/tdd/SKILL.md +174 -0
  225. package/app/skills/tdd/reference/deep-modules.md +32 -0
  226. package/app/skills/tdd/reference/interface-design.md +32 -0
  227. package/app/skills/tdd/reference/mocking.md +52 -0
  228. package/app/skills/tdd/reference/refactoring.md +10 -0
  229. package/app/skills/tdd/reference/tests.md +59 -0
  230. package/app/skills/teams/SKILL.md +101 -0
  231. package/app/skills/test/SKILL.md +107 -0
  232. package/app/skills/test/scripts/detect-runner.py +113 -0
  233. package/app/skills/testing-patterns/SKILL.md +73 -0
  234. package/app/skills/testing-patterns/reference/flutter-testing.md +33 -0
  235. package/app/skills/testing-patterns/reference/go-testing.md +52 -0
  236. package/app/skills/testing-patterns/reference/php-phpunit.md +39 -0
  237. package/app/skills/testing-patterns/reference/python-pytest.md +228 -0
  238. package/app/skills/testing-patterns/reference/typescript-vitest.md +50 -0
  239. package/app/skills/triage-issue/SKILL.md +120 -0
  240. package/app/skills/typescript-patterns/SKILL.md +256 -0
  241. package/app/skills/ubiquitous-language/SKILL.md +74 -0
  242. package/app/skills/verification-before-completion/SKILL.md +108 -0
  243. package/app/skills/workflow/SKILL.md +250 -0
  244. package/app/skills/write-a-prd/SKILL.md +129 -0
  245. package/app/skills/write-a-prd/reference/visual-companion.md +78 -0
  246. package/app/skills/write-a-prd/scripts/frame-template.html +111 -0
  247. package/app/skills/write-a-prd/scripts/visual-server.cjs +79 -0
  248. package/app/templates/skill/generator/SKILL.md.template +40 -0
  249. package/app/templates/skill/knowledge/SKILL.md.template +52 -0
  250. package/app/templates/skill/linter/SKILL.md.template +34 -0
  251. package/app/templates/skill/reviewer/SKILL.md.template +51 -0
  252. package/app/templates/skill/workflow/SKILL.md.template +49 -0
  253. package/benchmarks/README.md +111 -0
  254. package/benchmarks/ecosystem-dashboard.json +148 -0
  255. package/benchmarks/ecosystem-harvest.json +148 -0
  256. package/benchmarks/results.json +38 -0
  257. package/benchmarks/run.py +351 -0
  258. package/bin/ai-toolkit.js +345 -0
  259. package/kb/best-practices/README.md +11 -0
  260. package/kb/howto/README.md +11 -0
  261. package/kb/procedures/maintenance-sop.md +306 -0
  262. package/kb/reference/agents-catalog.md +124 -0
  263. package/kb/reference/anti-pattern-registry-format.md +221 -0
  264. package/kb/reference/architecture-overview.md +232 -0
  265. package/kb/reference/benchmark-config.md +62 -0
  266. package/kb/reference/ci-integration.md +66 -0
  267. package/kb/reference/claude-ecosystem-benchmark-snapshot.md +80 -0
  268. package/kb/reference/claude-ecosystem-expansion-foundations.md +102 -0
  269. package/kb/reference/commands-catalog.md +21 -0
  270. package/kb/reference/distribution-model.md +63 -0
  271. package/kb/reference/global-install-model.md +56 -0
  272. package/kb/reference/hierarchical-override-pattern.md +200 -0
  273. package/kb/reference/hooks-catalog.md +306 -0
  274. package/kb/reference/integrations.md +88 -0
  275. package/kb/reference/language-packs.md +52 -0
  276. package/kb/reference/merge-friendly-install-model.md +58 -0
  277. package/kb/reference/plugin-pack-conventions.md +151 -0
  278. package/kb/reference/quick-wins-implementation-summary.md +70 -0
  279. package/kb/reference/skill-templates.md +50 -0
  280. package/kb/reference/skills-catalog.md +215 -0
  281. package/kb/reference/skills-unification.md +57 -0
  282. package/kb/reference/stats.md +69 -0
  283. package/kb/reference/sync.md +76 -0
  284. package/kb/troubleshooting/README.md +11 -0
  285. package/llms-full.txt +3068 -0
  286. package/llms.txt +39 -0
  287. package/package.json +75 -0
  288. package/scripts/_common.py +160 -0
  289. package/scripts/add_rule.py +50 -0
  290. package/scripts/benchmark_config.py +127 -0
  291. package/scripts/benchmark_ecosystem.py +288 -0
  292. package/scripts/check_deps.py +260 -0
  293. package/scripts/create_skill.py +118 -0
  294. package/scripts/doctor.py +504 -0
  295. package/scripts/eject.py +113 -0
  296. package/scripts/emission.py +256 -0
  297. package/scripts/evaluate_skills.py +260 -0
  298. package/scripts/frontmatter.py +58 -0
  299. package/scripts/generate_agents_md.py +91 -0
  300. package/scripts/generate_aider_conf.py +51 -0
  301. package/scripts/generate_cline.py +35 -0
  302. package/scripts/generate_copilot.py +30 -0
  303. package/scripts/generate_cursor_rules.py +35 -0
  304. package/scripts/generate_gemini.py +28 -0
  305. package/scripts/generate_llms_txt.py +164 -0
  306. package/scripts/generate_roo_modes.py +80 -0
  307. package/scripts/generate_windsurf.py +35 -0
  308. package/scripts/generator_base.py +140 -0
  309. package/scripts/harvest_ecosystem.py +50 -0
  310. package/scripts/inject_rule_cli.py +101 -0
  311. package/scripts/inject_section_cli.py +47 -0
  312. package/scripts/injection.py +180 -0
  313. package/scripts/install.py +236 -0
  314. package/scripts/install_git_hooks.py +71 -0
  315. package/scripts/install_steps/__init__.py +5 -0
  316. package/scripts/install_steps/ai_tools.py +261 -0
  317. package/scripts/install_steps/hooks.py +90 -0
  318. package/scripts/install_steps/markers.py +79 -0
  319. package/scripts/install_steps/symlinks.py +87 -0
  320. package/scripts/merge-hooks.py +192 -0
  321. package/scripts/plugin.py +642 -0
  322. package/scripts/plugin_schema.py +138 -0
  323. package/scripts/remove_rule.py +58 -0
  324. package/scripts/stats.py +81 -0
  325. package/scripts/sync.py +215 -0
  326. package/scripts/uninstall.py +292 -0
  327. package/scripts/validate.py +700 -0
@@ -0,0 +1,203 @@
1
+ ---
2
+ name: rag-patterns
3
+ description: "Loaded when user asks about RAG systems, embeddings, or vector search"
4
+ effort: medium
5
+ user-invocable: false
6
+ ---
7
+
8
+ # RAG Patterns Skill
9
+
10
+ ## Core Patterns
11
+
12
+ ### 1. Hybrid Search
13
+ Combine dense (vector) and sparse (BM25) retrieval with RRF fusion:
14
+
15
+ ```python
16
+ # RAG-MCP hybrid search
17
+ result = await hybrid_search_kb(
18
+ query="rate limiting configuration",
19
+ service="nginx",
20
+ limit=10
21
+ )
22
+ ```
23
+
24
+ ### 2. Corrective RAG (CRAG)
25
+ Self-correcting retrieval with relevance validation:
26
+
27
+ ```python
28
+ result = await crag_search(
29
+ query="fuzzy query",
30
+ relevance_threshold=0.4,
31
+ max_retries=2
32
+ )
33
+
34
+ # Or via smart_query
35
+ result = await smart_query(query="...", use_crag=True)
36
+ ```
37
+
38
+ ### 3. HyDE (Hypothetical Document Embeddings)
39
+ Generate hypothetical answers for better retrieval on conceptual queries:
40
+
41
+ ```python
42
+ result = await smart_query(
43
+ query="conceptual question about design patterns",
44
+ use_hyde=True
45
+ )
46
+ ```
47
+
48
+ ### 4. Multi-hop Retrieval
49
+ Complex queries requiring multiple retrieval steps:
50
+
51
+ ```python
52
+ result = await multi_hop_search(
53
+ query="Compare nginx with varnish for Magento cache",
54
+ max_hops=3
55
+ )
56
+
57
+ # Or via smart_query
58
+ result = await smart_query(query="compare A vs B", use_multi_hop=True)
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Indexing Best Practices
64
+
65
+ | Aspect | Recommendation |
66
+ |--------|----------------|
67
+ | Chunk size | 512-1024 tokens |
68
+ | Overlap | 10-20% of chunk |
69
+ | Structure | Preserve headers, sections |
70
+ | Metadata | Include title, path, date, category, tags |
71
+ | Frontmatter | YAML with standardized fields |
72
+
73
+ ### Frontmatter Template
74
+ ```yaml
75
+ ---
76
+ title: "Document Title"
77
+ service: {project-name}
78
+ category: reference|howto|procedures|troubleshooting|decisions|best-practices
79
+ tags: [tag1, tag2, tag3]
80
+ last_updated: "YYYY-MM-DD"
81
+ ---
82
+ ```
83
+
84
+ ---
85
+
86
+ ## MCP Tools Reference (v5.5.0)
87
+
88
+ | Tool | Use Case | Speed |
89
+ |------|----------|-------|
90
+ | `smart_query` ⭐ | Default for 90% of queries | 2-4s |
91
+ | `hybrid_search_kb` | Raw vector + text search | <1s |
92
+ | `get_document` | Full document content | <1s |
93
+ | `crag_search` | Vague/fuzzy queries | 1-3s |
94
+ | `multi_hop_search` | Complex reasoning | 20-30s |
95
+
96
+ ### Tool Selection Guide
97
+
98
+ ```python
99
+ # Default - auto-routing
100
+ smart_query("specific technical question")
101
+
102
+ # Vague query - self-correcting
103
+ crag_search("jak to skonfigurować")
104
+
105
+ # Complex comparison
106
+ multi_hop_search("nginx vs varnish performance comparison")
107
+
108
+ # Known document
109
+ get_document(path="kb/reference/architecture.md")
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Quality Metrics
115
+
116
+ | Metric | Description | Target |
117
+ |--------|-------------|--------|
118
+ | Faithfulness | Answer based on context | >70% |
119
+ | Relevancy | Answer addresses question | >70% |
120
+ | Context Precision | Found context is accurate | >60% |
121
+ | Latency (p95) | Response time | <2s |
122
+ | Precision@k | Relevant results in top-k | >80% |
123
+
124
+ ---
125
+
126
+ ## Retrieval Optimization
127
+
128
+ ### Reranking
129
+ ```python
130
+ # Retrieve more, rerank to top-k
131
+ initial_results = await hybrid_search_kb(query, limit=20)
132
+ reranked = rerank_results(initial_results, query)
133
+ final_results = reranked[:5]
134
+ ```
135
+
136
+ ### Context Window Management
137
+ - Place critical info at start/end (serial position effect)
138
+ - Summarize long documents before insertion
139
+ - Use tiered context: critical → supporting → background
140
+
141
+ ### Query Enhancement
142
+ - Query expansion with synonyms
143
+ - Query decomposition for complex questions
144
+ - Entity extraction for filtering
145
+
146
+ ---
147
+
148
+ ## Anti-Patterns
149
+
150
+ ❌ **Don't**:
151
+ - Skip reranking for final results
152
+ - Use very large chunks (>2000 tokens)
153
+ - Ignore metadata in retrieval
154
+ - Trust LLM output without citation
155
+ - Use `latest` for model versions
156
+
157
+ ✅ **Do**:
158
+ - Use top-k=20 → rerank → top-5
159
+ - Chunk semantically (by section)
160
+ - Enrich metadata at indexing time
161
+ - Require source attribution in answers
162
+ - Pin model versions for reproducibility
163
+
164
+ ---
165
+
166
+ ## RAG System Implementation
167
+
168
+ ### Key Files (Typical Structure)
169
+ ```
170
+ scripts/
171
+ ├── search_core.py # Core search
172
+ ├── query_enhancements.py # HyDE, query expansion
173
+ ├── corrective_rag.py # CRAG
174
+ ├── multi_hop.py # Multi-hop
175
+ ├── unified_indexer.py # Indexing
176
+ └── rag_evaluator.py # Evaluation
177
+ ```
178
+
179
+ ### Running RAG Commands
180
+
181
+ **Direct execution:**
182
+ ```bash
183
+ # Index KB
184
+ make index
185
+
186
+ # Evaluate RAG
187
+ python scripts/evaluate_rag.py
188
+
189
+ # Detect gaps
190
+ python scripts/knowledge_gaps.py --detect
191
+ ```
192
+
193
+ **Docker execution (if containerized):**
194
+ ```bash
195
+ # Index KB
196
+ docker exec {app-container} make index
197
+
198
+ # Evaluate RAG
199
+ docker exec {api-container} python3 scripts/evaluate_rag.py
200
+
201
+ # Detect gaps
202
+ docker exec {api-container} python3 scripts/knowledge_gaps.py --detect
203
+ ```
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: refactor
3
+ description: "Refactor code for quality and maintainability"
4
+ user-invocable: true
5
+ effort: high
6
+ argument-hint: "[target and goal]"
7
+ agent: code-reviewer
8
+ context: fork
9
+ allowed-tools: Read, Edit, Grep, Glob, Bash
10
+ ---
11
+
12
+ # Refactor Code
13
+
14
+ $ARGUMENTS
15
+
16
+ Plan and execute code refactoring.
17
+
18
+ ## Usage
19
+
20
+ ```
21
+ /refactor [target] [--pattern=<pattern>]
22
+ ```
23
+
24
+ ## What This Command Does
25
+
26
+ 1. **Analyzes** target code
27
+ 2. **Identifies** refactoring opportunities
28
+ 3. **Plans** refactoring steps
29
+ 4. **Executes** with user approval
30
+
31
+ ## Refactoring Patterns
32
+
33
+ | Pattern | Description |
34
+ |---------|-------------|
35
+ | `extract-function` | Extract code block to function |
36
+ | `extract-component` | Extract UI component |
37
+ | `rename` | Rename symbol across codebase |
38
+ | `move` | Move code to better location |
39
+ | `inline` | Inline unnecessary abstraction |
40
+ | `simplify` | Simplify complex logic |
41
+
42
+ ## Safety Rules
43
+
44
+ - Run tests before refactoring
45
+ - Make atomic commits
46
+ - Preserve behavior (no feature changes)
47
+ - Run tests after each step
48
+ - Don't mix refactoring with features
49
+
50
+ ## Output Format
51
+
52
+ ```markdown
53
+ ## Refactoring Plan: [Target]
54
+
55
+ ### Current State
56
+ - **Location**: [file:line]
57
+ - **Issues**: [what's wrong]
58
+
59
+ ### Proposed Changes
60
+ 1. [Change 1]
61
+ 2. [Change 2]
62
+
63
+ ### Impact Analysis
64
+ - **Files affected**: [count]
65
+ - **Risk level**: [Low/Medium/High]
66
+
67
+ ### Test Coverage
68
+ - [x] Unit tests exist
69
+ - [ ] Integration tests needed
70
+
71
+ ### Rollback
72
+ ```
73
+ git revert [commit]
74
+ ```
75
+ ```
76
+
77
+ ## Approval Required
78
+
79
+ Before executing:
80
+ - [ ] Plan reviewed
81
+ - [ ] Tests passing
82
+ - [ ] Backup created
83
+
84
+ ## READ BEFORE WRITE
85
+
86
+ This command analyzes and plans first.
87
+ Execution requires explicit approval.
88
+
89
+ ## MANDATORY: Documentation Update
90
+
91
+ After refactoring, update documentation:
92
+
93
+ ### Required Updates
94
+ | Change Type | Update |
95
+ |-------------|--------|
96
+ | API changes | API documentation |
97
+ | Architecture | architecture note if significant |
98
+ | Patterns | Best practices docs |
99
+ | Breaking changes | Migration guide |
100
+
101
+ ### Post-Refactoring Checklist
102
+ - [ ] Tests still pass
103
+ - [ ] No behavior changes
104
+ - [ ] **Documentation updated if interfaces changed**
105
+ - [ ] Code comments updated
106
+
107
+ ## Automated Smell Detection
108
+
109
+ Run the bundled script to find refactoring opportunities:
110
+
111
+ ```bash
112
+ python3 ${CLAUDE_SKILL_DIR}/scripts/refactor-scan.py src/
113
+ ```
114
+
115
+ ## Parallel Refactoring (complex cases)
116
+
117
+ If the scan reports >5 smells across multiple files, use Agent Teams:
118
+
119
+ ```
120
+ Create an agent team for refactoring:
121
+ - Teammate 1 (code-reviewer): "Plan the refactoring strategy for [identified smells]. Document what to change and why." Use Opus. READ-ONLY.
122
+ - Teammate 2 (backend-specialist): "Implement the refactoring changes identified by the reviewer." Use Opus.
123
+ Teammate 1 completes first, then Teammate 2 acts on the plan.
124
+ ```
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env python3
2
+ """Detect code smells deterministically: long functions, deep nesting, large files."""
3
+
4
+ import json
5
+ import os
6
+ import re
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ IGNORE_DIRS = {'.git', 'node_modules', '__pycache__', '.venv', 'venv', 'dist', 'build', '.next', 'vendor', '.cache'}
11
+
12
+ SOURCE_EXTS = {'.py', '.ts', '.js', '.tsx', '.jsx', '.go', '.php', '.dart'}
13
+
14
+ THRESHOLDS = {
15
+ 'long_function_lines': 50,
16
+ 'deep_nesting_levels': 4,
17
+ 'large_file_lines': 300,
18
+ 'many_functions': 15,
19
+ }
20
+
21
+ FUNC_PATTERNS = {
22
+ '.py': re.compile(r'^(\s*)def\s+(\w+)\s*\('),
23
+ '.js': re.compile(r'^(\s*)(?:(?:async\s+)?function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\()'),
24
+ '.jsx': re.compile(r'^(\s*)(?:(?:async\s+)?function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\()'),
25
+ '.ts': re.compile(r'^(\s*)(?:(?:async\s+)?function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\()'),
26
+ '.tsx': re.compile(r'^(\s*)(?:(?:async\s+)?function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\()'),
27
+ '.go': re.compile(r'^(\s*)func\s+(?:\([^)]*\)\s+)?(\w+)\s*\('),
28
+ '.php': re.compile(r'^(\s*)(?:public|private|protected|static|\s)*function\s+(\w+)'),
29
+ '.dart': re.compile(r'^(\s*)(?:\w+\s+)?(\w+)\s*\([^)]*\)\s*(?:async\s*)?\{'),
30
+ }
31
+
32
+
33
+ def find_source_files(root: str) -> list:
34
+ result = []
35
+ for dirpath, dirnames, filenames in os.walk(root):
36
+ dirnames[:] = [d for d in dirnames if d not in IGNORE_DIRS]
37
+ for fn in filenames:
38
+ if Path(fn).suffix in SOURCE_EXTS:
39
+ result.append(os.path.join(dirpath, fn))
40
+ return result
41
+
42
+
43
+ def measure_nesting(line: str, ext: str) -> int:
44
+ """Measure nesting depth from indentation."""
45
+ if not line.strip():
46
+ return 0
47
+ if ext == '.py':
48
+ # Python: 4 spaces = 1 level
49
+ spaces = len(line) - len(line.lstrip())
50
+ return spaces // 4
51
+ else:
52
+ # Brace languages: count { minus } up to this point is complex,
53
+ # so use indentation heuristic (2 or 4 spaces = 1 level)
54
+ spaces = len(line) - len(line.lstrip())
55
+ tab_count = line.count('\t')
56
+ if tab_count > 0:
57
+ return tab_count
58
+ indent_size = 2 if spaces % 2 == 0 and spaces % 4 != 0 else 4
59
+ return spaces // indent_size
60
+
61
+
62
+ def analyze_file(filepath: str, project_root: str) -> dict:
63
+ ext = Path(filepath).suffix
64
+ rel_path = os.path.relpath(filepath, project_root)
65
+ smells = []
66
+
67
+ try:
68
+ with open(filepath, 'r', errors='replace') as f:
69
+ lines = f.readlines()
70
+ except OSError:
71
+ return {"file": rel_path, "smells": [], "functions": 0}
72
+
73
+ total_lines = len(lines)
74
+ func_pattern = FUNC_PATTERNS.get(ext)
75
+ if not func_pattern:
76
+ return {"file": rel_path, "smells": [], "functions": 0}
77
+
78
+ # Find function boundaries
79
+ functions = []
80
+ for i, line in enumerate(lines):
81
+ m = func_pattern.match(line)
82
+ if m:
83
+ name = next((g for g in m.groups()[1:] if g is not None), 'anonymous')
84
+ indent = len(m.group(1).expandtabs(4))
85
+ functions.append({"name": name, "start": i + 1, "indent": indent})
86
+
87
+ # Calculate function lengths
88
+ for idx, func in enumerate(functions):
89
+ if idx + 1 < len(functions):
90
+ end = functions[idx + 1]["start"] - 1
91
+ else:
92
+ end = total_lines
93
+ func["length"] = end - func["start"] + 1
94
+
95
+ # Detect max nesting per function
96
+ for func in functions:
97
+ start_idx = func["start"] - 1
98
+ end_idx = start_idx + func["length"]
99
+ max_depth = 0
100
+ for i in range(start_idx, min(end_idx, total_lines)):
101
+ depth = measure_nesting(lines[i], ext)
102
+ # Relative nesting: subtract function's own indent level
103
+ relative_depth = depth - (func["indent"] // 4) - 1
104
+ if relative_depth > max_depth:
105
+ max_depth = relative_depth
106
+ func["max_nesting"] = max(max_depth, 0)
107
+
108
+ # Flag smells
109
+ for func in functions:
110
+ if func["length"] > THRESHOLDS['long_function_lines']:
111
+ smells.append({
112
+ "type": "long_function",
113
+ "severity": "high" if func["length"] > 100 else "medium",
114
+ "file": rel_path,
115
+ "function": func["name"],
116
+ "line": func["start"],
117
+ "detail": f"{func['length']} lines (threshold: {THRESHOLDS['long_function_lines']})",
118
+ })
119
+ if func["max_nesting"] > THRESHOLDS['deep_nesting_levels']:
120
+ smells.append({
121
+ "type": "deep_nesting",
122
+ "severity": "high" if func["max_nesting"] > 6 else "medium",
123
+ "file": rel_path,
124
+ "function": func["name"],
125
+ "line": func["start"],
126
+ "detail": f"depth {func['max_nesting']} (threshold: {THRESHOLDS['deep_nesting_levels']})",
127
+ })
128
+
129
+ if total_lines > THRESHOLDS['large_file_lines']:
130
+ smells.append({
131
+ "type": "large_file",
132
+ "severity": "high" if total_lines > 600 else "medium",
133
+ "file": rel_path,
134
+ "function": None,
135
+ "line": None,
136
+ "detail": f"{total_lines} lines (threshold: {THRESHOLDS['large_file_lines']})",
137
+ })
138
+
139
+ if len(functions) > THRESHOLDS['many_functions']:
140
+ smells.append({
141
+ "type": "too_many_functions",
142
+ "severity": "medium",
143
+ "file": rel_path,
144
+ "function": None,
145
+ "line": None,
146
+ "detail": f"{len(functions)} functions (threshold: {THRESHOLDS['many_functions']}, possible God class)",
147
+ })
148
+
149
+ return {"file": rel_path, "smells": smells, "functions": len(functions)}
150
+
151
+
152
+ def main():
153
+ if len(sys.argv) < 2:
154
+ print(json.dumps({"error": "Usage: refactor-scan.py <file_or_directory>"}))
155
+ sys.exit(1)
156
+
157
+ target = os.path.abspath(sys.argv[1])
158
+ if not os.path.exists(target):
159
+ print(json.dumps({"error": f"Path not found: {target}"}))
160
+ sys.exit(1)
161
+
162
+ # Determine project root
163
+ project_root = target if os.path.isdir(target) else os.path.dirname(target)
164
+ check = project_root
165
+ for _ in range(10):
166
+ if os.path.isdir(os.path.join(check, '.git')):
167
+ project_root = check
168
+ break
169
+ parent = os.path.dirname(check)
170
+ if parent == check:
171
+ break
172
+ check = parent
173
+
174
+ files = [target] if os.path.isfile(target) else find_source_files(target)
175
+
176
+ all_smells = []
177
+ files_scanned = 0
178
+
179
+ for fp in files:
180
+ result = analyze_file(fp, project_root)
181
+ files_scanned += 1
182
+ all_smells.extend(result["smells"])
183
+
184
+ # Sort by severity (high first)
185
+ severity_order = {"high": 0, "medium": 1, "low": 2}
186
+ all_smells.sort(key=lambda s: severity_order.get(s["severity"], 99))
187
+
188
+ # Generate recommendation
189
+ if not all_smells:
190
+ recommendation = "No code smells detected. Codebase looks clean."
191
+ elif len(all_smells) <= 3:
192
+ recommendation = "Minor issues found. Address them in your next refactoring pass."
193
+ elif len(all_smells) <= 10:
194
+ recommendation = "Several code smells detected. Prioritize high-severity items."
195
+ else:
196
+ recommendation = "Significant technical debt detected. Consider a dedicated refactoring sprint."
197
+
198
+ output = {
199
+ "target": os.path.relpath(target, project_root),
200
+ "smells": all_smells,
201
+ "files_scanned": files_scanned,
202
+ "total_smells": len(all_smells),
203
+ "recommendation": recommendation,
204
+ }
205
+
206
+ print(json.dumps(output, indent=2))
207
+
208
+
209
+ if __name__ == '__main__':
210
+ main()
@@ -0,0 +1,112 @@
1
+ ---
2
+ name: refactor-plan
3
+ description: "Create a detailed refactor plan with tiny commits via user interview, then file as a GitHub issue RFC. Use when user wants to plan a refactor, create a refactoring RFC, or break a refactor into safe incremental steps."
4
+ user-invocable: true
5
+ effort: high
6
+ argument-hint: "[area or module to refactor]"
7
+ allowed-tools: Read, Grep, Glob, Bash, Agent
8
+ ---
9
+
10
+ # Refactor Plan
11
+
12
+ $ARGUMENTS
13
+
14
+ Create a detailed refactor plan with tiny commits via user interview, filed as a GitHub issue.
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ /refactor-plan [area or module to refactor]
20
+ ```
21
+
22
+ ## What This Command Does
23
+
24
+ 1. **Gathers** detailed problem description from user
25
+ 2. **Explores** the codebase to verify assertions
26
+ 3. **Presents** alternative approaches (>=3 options)
27
+ 4. **Interviews** about implementation details
28
+ 5. **Checks** test coverage of affected area
29
+ 6. **Breaks** into tiny commits (Martin Fowler: each step keeps codebase working)
30
+ 7. **Files** as GitHub issue via `gh issue create`
31
+
32
+ ## Process
33
+
34
+ ### 1. Gather Problem
35
+
36
+ Ask for detailed description of:
37
+ - The problem they want to solve
38
+ - Potential ideas for solutions
39
+
40
+ ### 2. Explore Codebase
41
+
42
+ Use Agent (subagent_type=Explore) to verify assertions and understand current state.
43
+
44
+ ### 3. Present Alternatives
45
+
46
+ Present >=3 alternative approaches. Discuss trade-offs.
47
+
48
+ ### 4. Interview
49
+
50
+ Detailed interview about chosen approach. Hammer out exact scope — what changes, what doesn't.
51
+
52
+ ### 5. Check Test Coverage
53
+
54
+ Explore existing test coverage for the affected area. If insufficient, ask about testing plans.
55
+
56
+ ### 6. Break into Tiny Commits
57
+
58
+ Each commit:
59
+ - Leaves the codebase in a working state
60
+ - Is the smallest possible step
61
+ - Can be reviewed independently
62
+
63
+ ### 7. File GitHub Issue
64
+
65
+ Use `gh issue create` with template below. Share URL immediately.
66
+
67
+ ## Issue Template
68
+
69
+ <refactor-plan-template>
70
+
71
+ ## Problem Statement
72
+
73
+ The problem from the developer's perspective.
74
+
75
+ ## Solution
76
+
77
+ The solution from the developer's perspective.
78
+
79
+ ## Commits
80
+
81
+ Detailed plan in plain English, broken into the tiniest commits possible. Each commit leaves the codebase working.
82
+
83
+ ## Decision Document
84
+
85
+ Implementation decisions made:
86
+ - Modules to build/modify
87
+ - Interface changes
88
+ - Architectural decisions
89
+ - Schema changes
90
+ - API contracts
91
+
92
+ Do NOT include file paths or code snippets — they go stale.
93
+
94
+ ## Testing Decisions
95
+
96
+ - What makes a good test (external behavior, not implementation details)
97
+ - Which modules to test
98
+ - Prior art for tests in the codebase
99
+
100
+ ## Out of Scope
101
+
102
+ What is explicitly NOT part of this refactor.
103
+
104
+ </refactor-plan-template>
105
+
106
+ ## Rules
107
+
108
+ - Present >=3 alternatives before committing to an approach
109
+ - Tiny commits — each step keeps codebase working
110
+ - No file paths or code snippets in the issue (durability)
111
+ - File immediately via `gh issue create` — don't ask for review
112
+ - Interview thoroughly before planning