xtrm-tools 2.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 (447) hide show
  1. package/CHANGELOG.md +496 -0
  2. package/README.md +762 -0
  3. package/cli/dist/index.cjs +55245 -0
  4. package/cli/dist/index.cjs.map +1 -0
  5. package/cli/dist/index.d.cts +2 -0
  6. package/cli/package.json +43 -0
  7. package/config/.env.example +40 -0
  8. package/config/hooks.json +36 -0
  9. package/config/mcp_servers.json +46 -0
  10. package/config/mcp_servers_optional.json +53 -0
  11. package/config/settings.json +70 -0
  12. package/hooks/README.md +156 -0
  13. package/hooks/__pycache__/agent_context.cpython-314.pyc +0 -0
  14. package/hooks/agent_context.py +105 -0
  15. package/hooks/gitnexus/gitnexus-hook.cjs +133 -0
  16. package/hooks/serena-workflow-reminder.py +74 -0
  17. package/hooks/skill-discovery.py +90 -0
  18. package/hooks/skill-suggestion.py +112 -0
  19. package/hooks/test_agent_context.py +112 -0
  20. package/hooks/type-safety-enforcement.py +107 -0
  21. package/package.json +48 -0
  22. package/project-skills/main-guard/.claude/hooks/main-guard.cjs +188 -0
  23. package/project-skills/main-guard/.claude/settings.json +16 -0
  24. package/project-skills/main-guard/.claude/skills/using-main-guard/SKILL.md +135 -0
  25. package/project-skills/main-guard/README.md +163 -0
  26. package/project-skills/py-quality-gate/.claude/hooks/quality-check.py +311 -0
  27. package/project-skills/py-quality-gate/.claude/settings.json +16 -0
  28. package/project-skills/py-quality-gate/.claude/skills/using-py-quality-gate/SKILL.md +112 -0
  29. package/project-skills/py-quality-gate/README.md +147 -0
  30. package/project-skills/service-skills-set/.claude/git-hooks/__pycache__/doc_reminder.cpython-314.pyc +0 -0
  31. package/project-skills/service-skills-set/.claude/git-hooks/__pycache__/skill_staleness.cpython-314.pyc +0 -0
  32. package/project-skills/service-skills-set/.claude/git-hooks/doc_reminder.py +67 -0
  33. package/project-skills/service-skills-set/.claude/git-hooks/skill_staleness.py +194 -0
  34. package/project-skills/service-skills-set/.claude/service-registry.json +4 -0
  35. package/project-skills/service-skills-set/.claude/settings.json +37 -0
  36. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/SKILL.md +433 -0
  37. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/references/script_quality_standards.md +412 -0
  38. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/references/service_skill_system_guide.md +264 -0
  39. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/scripts/bootstrap.py +308 -0
  40. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/scripts/deep_dive.py +304 -0
  41. package/project-skills/service-skills-set/.claude/skills/creating-service-skills/scripts/scaffolder.py +482 -0
  42. package/project-skills/service-skills-set/.claude/skills/scoping-service-skills/SKILL.md +231 -0
  43. package/project-skills/service-skills-set/.claude/skills/scoping-service-skills/scripts/scope.py +74 -0
  44. package/project-skills/service-skills-set/.claude/skills/updating-service-skills/SKILL.md +136 -0
  45. package/project-skills/service-skills-set/.claude/skills/updating-service-skills/scripts/__pycache__/drift_detector.cpython-314.pyc +0 -0
  46. package/project-skills/service-skills-set/.claude/skills/updating-service-skills/scripts/drift_detector.py +222 -0
  47. package/project-skills/service-skills-set/.claude/skills/using-service-skills/SKILL.md +108 -0
  48. package/project-skills/service-skills-set/.claude/skills/using-service-skills/scripts/__pycache__/cataloger.cpython-314.pyc +0 -0
  49. package/project-skills/service-skills-set/.claude/skills/using-service-skills/scripts/__pycache__/skill_activator.cpython-314.pyc +0 -0
  50. package/project-skills/service-skills-set/.claude/skills/using-service-skills/scripts/cataloger.py +74 -0
  51. package/project-skills/service-skills-set/.claude/skills/using-service-skills/scripts/skill_activator.py +152 -0
  52. package/project-skills/service-skills-set/README.md +93 -0
  53. package/project-skills/service-skills-set/__pycache__/install-service-skills.cpython-314.pyc +0 -0
  54. package/project-skills/service-skills-set/install-service-skills.py +163 -0
  55. package/project-skills/service-skills-set/service-skills-readme.md +236 -0
  56. package/project-skills/tdd-guard/.claude/settings.json +38 -0
  57. package/project-skills/tdd-guard/.claude/skills/using-tdd-guard/SKILL.md +74 -0
  58. package/project-skills/tdd-guard/CLAUDE.md +98 -0
  59. package/project-skills/tdd-guard/CONTRIBUTING.md +38 -0
  60. package/project-skills/tdd-guard/DEVELOPMENT.md +127 -0
  61. package/project-skills/tdd-guard/LICENSE +21 -0
  62. package/project-skills/tdd-guard/README.md +396 -0
  63. package/project-skills/tdd-guard/docs/adr/001-claude-session-subdirectory.md +52 -0
  64. package/project-skills/tdd-guard/docs/adr/002-secure-claude-binary-path.md +56 -0
  65. package/project-skills/tdd-guard/docs/adr/003-remove-configurable-data-directory.md +56 -0
  66. package/project-skills/tdd-guard/docs/adr/004-monorepo-architecture.md +64 -0
  67. package/project-skills/tdd-guard/docs/adr/005-claude-project-dir-support.md +55 -0
  68. package/project-skills/tdd-guard/docs/adr/006-phpunit-separate-repository.md +93 -0
  69. package/project-skills/tdd-guard/docs/adr/007-golangci-lint-path-support.md +83 -0
  70. package/project-skills/tdd-guard/docs/adr/008-storybook-reporter-design.md +182 -0
  71. package/project-skills/tdd-guard/docs/assets/tdd-guard-demo-screenshot.gif +0 -0
  72. package/project-skills/tdd-guard/docs/config-migration.md +143 -0
  73. package/project-skills/tdd-guard/docs/configuration.md +137 -0
  74. package/project-skills/tdd-guard/docs/custom-instructions.md +43 -0
  75. package/project-skills/tdd-guard/docs/enforcement.md +46 -0
  76. package/project-skills/tdd-guard/docs/ignore-patterns.md +81 -0
  77. package/project-skills/tdd-guard/docs/linting.md +109 -0
  78. package/project-skills/tdd-guard/docs/quick-commands.md +52 -0
  79. package/project-skills/tdd-guard/docs/session-management.md +75 -0
  80. package/project-skills/tdd-guard/docs/storybook-vitest-addon.md +120 -0
  81. package/project-skills/tdd-guard/docs/validation-model.md +63 -0
  82. package/project-skills/tdd-guard/eslint.config.mjs +140 -0
  83. package/project-skills/tdd-guard/package-lock.json +16937 -0
  84. package/project-skills/tdd-guard/package.json +102 -0
  85. package/project-skills/tdd-guard/reporters/go/README.md +67 -0
  86. package/project-skills/tdd-guard/reporters/go/cmd/tdd-guard-go/main.go +127 -0
  87. package/project-skills/tdd-guard/reporters/go/cmd/tdd-guard-go/main_test.go +280 -0
  88. package/project-skills/tdd-guard/reporters/go/go.mod +3 -0
  89. package/project-skills/tdd-guard/reporters/go/go.sum +0 -0
  90. package/project-skills/tdd-guard/reporters/go/internal/formatter/formatter.go +126 -0
  91. package/project-skills/tdd-guard/reporters/go/internal/formatter/formatter_test.go +264 -0
  92. package/project-skills/tdd-guard/reporters/go/internal/io/tee_reader.go +26 -0
  93. package/project-skills/tdd-guard/reporters/go/internal/io/tee_reader_test.go +37 -0
  94. package/project-skills/tdd-guard/reporters/go/internal/parser/mixed_reader.go +94 -0
  95. package/project-skills/tdd-guard/reporters/go/internal/parser/mixed_reader_test.go +198 -0
  96. package/project-skills/tdd-guard/reporters/go/internal/parser/parser.go +245 -0
  97. package/project-skills/tdd-guard/reporters/go/internal/parser/parser_test.go +547 -0
  98. package/project-skills/tdd-guard/reporters/go/internal/storage/storage.go +35 -0
  99. package/project-skills/tdd-guard/reporters/go/internal/storage/storage_test.go +113 -0
  100. package/project-skills/tdd-guard/reporters/go/internal/transformer/transformer.go +103 -0
  101. package/project-skills/tdd-guard/reporters/go/internal/transformer/transformer_test.go +303 -0
  102. package/project-skills/tdd-guard/reporters/jest/README.md +102 -0
  103. package/project-skills/tdd-guard/reporters/jest/package.json +38 -0
  104. package/project-skills/tdd-guard/reporters/phpunit/.php-cs-fixer.php +28 -0
  105. package/project-skills/tdd-guard/reporters/phpunit/README.md +97 -0
  106. package/project-skills/tdd-guard/reporters/phpunit/SYNC_README.md +29 -0
  107. package/project-skills/tdd-guard/reporters/phpunit/composer.json +55 -0
  108. package/project-skills/tdd-guard/reporters/phpunit/phpunit.xml.dist +19 -0
  109. package/project-skills/tdd-guard/reporters/phpunit/psalm.xml +44 -0
  110. package/project-skills/tdd-guard/reporters/phpunit/src/Event/ErroredTestSubscriber.php +28 -0
  111. package/project-skills/tdd-guard/reporters/phpunit/src/Event/FailedTestSubscriber.php +28 -0
  112. package/project-skills/tdd-guard/reporters/phpunit/src/Event/IncompleteTestSubscriber.php +28 -0
  113. package/project-skills/tdd-guard/reporters/phpunit/src/Event/PassedTestSubscriber.php +27 -0
  114. package/project-skills/tdd-guard/reporters/phpunit/src/Event/SkippedTestSubscriber.php +28 -0
  115. package/project-skills/tdd-guard/reporters/phpunit/src/Event/TestRunnerFinishedSubscriber.php +24 -0
  116. package/project-skills/tdd-guard/reporters/phpunit/src/PathValidator.php +88 -0
  117. package/project-skills/tdd-guard/reporters/phpunit/src/Storage.php +26 -0
  118. package/project-skills/tdd-guard/reporters/phpunit/src/TddGuardExtension.php +33 -0
  119. package/project-skills/tdd-guard/reporters/phpunit/src/TddGuardListener.php +158 -0
  120. package/project-skills/tdd-guard/reporters/phpunit/src/TddGuardSubscriber.php +35 -0
  121. package/project-skills/tdd-guard/reporters/phpunit/src/TestResultCollector.php +105 -0
  122. package/project-skills/tdd-guard/reporters/phpunit/tests/PathValidatorTest.php +74 -0
  123. package/project-skills/tdd-guard/reporters/phpunit/tests/TddGuardExtensionFailedTest.php +241 -0
  124. package/project-skills/tdd-guard/reporters/phpunit/tests/TddGuardExtensionTest.php +84 -0
  125. package/project-skills/tdd-guard/reporters/phpunit/tests/TddGuardStorageLocationTest.php +71 -0
  126. package/project-skills/tdd-guard/reporters/pytest/README.md +77 -0
  127. package/project-skills/tdd-guard/reporters/pytest/pyproject.toml +43 -0
  128. package/project-skills/tdd-guard/reporters/pytest/pytest.ini.example +7 -0
  129. package/project-skills/tdd-guard/reporters/pytest/tdd_guard_pytest/__init__.py +1 -0
  130. package/project-skills/tdd-guard/reporters/pytest/tdd_guard_pytest/pytest_reporter.py +134 -0
  131. package/project-skills/tdd-guard/reporters/pytest/tests/__init__.py +1 -0
  132. package/project-skills/tdd-guard/reporters/pytest/tests/conftest.py +3 -0
  133. package/project-skills/tdd-guard/reporters/pytest/tests/helpers.py +293 -0
  134. package/project-skills/tdd-guard/reporters/pytest/tests/test_config_option.py +38 -0
  135. package/project-skills/tdd-guard/reporters/pytest/tests/test_path_validation.py +59 -0
  136. package/project-skills/tdd-guard/reporters/pytest/tests/test_plugin_config.py +32 -0
  137. package/project-skills/tdd-guard/reporters/pytest/tests/test_project_root.py +296 -0
  138. package/project-skills/tdd-guard/reporters/pytest/tests/test_pytest_reporter.py +137 -0
  139. package/project-skills/tdd-guard/reporters/rspec/Gemfile +3 -0
  140. package/project-skills/tdd-guard/reporters/rust/Cargo.lock +458 -0
  141. package/project-skills/tdd-guard/reporters/rust/Cargo.toml +33 -0
  142. package/project-skills/tdd-guard/reporters/rust/Makefile.example +95 -0
  143. package/project-skills/tdd-guard/reporters/rust/README.md +88 -0
  144. package/project-skills/tdd-guard/reporters/rust/src/error_parser.rs +309 -0
  145. package/project-skills/tdd-guard/reporters/rust/src/main.rs +464 -0
  146. package/project-skills/tdd-guard/reporters/rust/src/parser.rs +225 -0
  147. package/project-skills/tdd-guard/reporters/rust/src/transformer.rs +409 -0
  148. package/project-skills/tdd-guard/reporters/storybook/README.md +108 -0
  149. package/project-skills/tdd-guard/reporters/storybook/package-lock.json +9482 -0
  150. package/project-skills/tdd-guard/reporters/storybook/package.json +43 -0
  151. package/project-skills/tdd-guard/reporters/storybook/src/StorybookReporter.test-data.ts +22 -0
  152. package/project-skills/tdd-guard/reporters/storybook/src/StorybookReporter.test.ts +190 -0
  153. package/project-skills/tdd-guard/reporters/storybook/src/StorybookReporter.ts +88 -0
  154. package/project-skills/tdd-guard/reporters/storybook/src/index.ts +12 -0
  155. package/project-skills/tdd-guard/reporters/storybook/src/types.ts +37 -0
  156. package/project-skills/tdd-guard/reporters/storybook/tsconfig.json +11 -0
  157. package/project-skills/tdd-guard/reporters/test/artifacts/go/failing/go.mod +3 -0
  158. package/project-skills/tdd-guard/reporters/test/artifacts/go/failing/single_failing_test.go +13 -0
  159. package/project-skills/tdd-guard/reporters/test/artifacts/go/import/go.mod +3 -0
  160. package/project-skills/tdd-guard/reporters/test/artifacts/go/import/single_import_error_test.go +17 -0
  161. package/project-skills/tdd-guard/reporters/test/artifacts/go/passing/go.mod +3 -0
  162. package/project-skills/tdd-guard/reporters/test/artifacts/go/passing/single_passing_test.go +13 -0
  163. package/project-skills/tdd-guard/reporters/test/artifacts/jest/single-failing.test.js +5 -0
  164. package/project-skills/tdd-guard/reporters/test/artifacts/jest/single-import-error.test.js +8 -0
  165. package/project-skills/tdd-guard/reporters/test/artifacts/jest/single-passing.test.js +5 -0
  166. package/project-skills/tdd-guard/reporters/test/artifacts/phpunit/SingleFailingTest.php +11 -0
  167. package/project-skills/tdd-guard/reporters/test/artifacts/phpunit/SingleImportErrorTest.php +14 -0
  168. package/project-skills/tdd-guard/reporters/test/artifacts/phpunit/SinglePassingTest.php +11 -0
  169. package/project-skills/tdd-guard/reporters/test/artifacts/pytest/test_single_failing.py +3 -0
  170. package/project-skills/tdd-guard/reporters/test/artifacts/pytest/test_single_import_error.py +6 -0
  171. package/project-skills/tdd-guard/reporters/test/artifacts/pytest/test_single_passing.py +3 -0
  172. package/project-skills/tdd-guard/reporters/test/artifacts/rust/failing/Cargo.lock +7 -0
  173. package/project-skills/tdd-guard/reporters/test/artifacts/rust/failing/Cargo.toml +4 -0
  174. package/project-skills/tdd-guard/reporters/test/artifacts/rust/failing/src/lib.rs +14 -0
  175. package/project-skills/tdd-guard/reporters/test/artifacts/rust/import/Cargo.lock +7 -0
  176. package/project-skills/tdd-guard/reporters/test/artifacts/rust/import/Cargo.toml +4 -0
  177. package/project-skills/tdd-guard/reporters/test/artifacts/rust/import/src/lib.rs +13 -0
  178. package/project-skills/tdd-guard/reporters/test/artifacts/rust/passing/Cargo.lock +7 -0
  179. package/project-skills/tdd-guard/reporters/test/artifacts/rust/passing/Cargo.toml +4 -0
  180. package/project-skills/tdd-guard/reporters/test/artifacts/rust/passing/src/lib.rs +14 -0
  181. package/project-skills/tdd-guard/reporters/test/artifacts/storybook/Calculator.js +4 -0
  182. package/project-skills/tdd-guard/reporters/test/artifacts/storybook/single-failing.stories.js +15 -0
  183. package/project-skills/tdd-guard/reporters/test/artifacts/storybook/single-import-error.stories.js +14 -0
  184. package/project-skills/tdd-guard/reporters/test/artifacts/storybook/single-passing.stories.js +15 -0
  185. package/project-skills/tdd-guard/reporters/test/artifacts/vitest/single-failing.test.js +7 -0
  186. package/project-skills/tdd-guard/reporters/test/artifacts/vitest/single-import-error.test.js +9 -0
  187. package/project-skills/tdd-guard/reporters/test/artifacts/vitest/single-passing.test.js +7 -0
  188. package/project-skills/tdd-guard/reporters/test/factories/go.ts +59 -0
  189. package/project-skills/tdd-guard/reporters/test/factories/helpers.ts +48 -0
  190. package/project-skills/tdd-guard/reporters/test/factories/index.ts +7 -0
  191. package/project-skills/tdd-guard/reporters/test/factories/jest.ts +51 -0
  192. package/project-skills/tdd-guard/reporters/test/factories/phpunit.ts +63 -0
  193. package/project-skills/tdd-guard/reporters/test/factories/pytest.ts +41 -0
  194. package/project-skills/tdd-guard/reporters/test/factories/rust.ts +158 -0
  195. package/project-skills/tdd-guard/reporters/test/factories/storybook.ts +198 -0
  196. package/project-skills/tdd-guard/reporters/test/factories/vitest.ts +51 -0
  197. package/project-skills/tdd-guard/reporters/test/reporters.integration.test.ts +735 -0
  198. package/project-skills/tdd-guard/reporters/test/types.ts +28 -0
  199. package/project-skills/tdd-guard/reporters/vitest/README.md +64 -0
  200. package/project-skills/tdd-guard/reporters/vitest/package.json +35 -0
  201. package/project-skills/tdd-guard/src/cli/buildContext.test.ts +200 -0
  202. package/project-skills/tdd-guard/src/cli/buildContext.ts +48 -0
  203. package/project-skills/tdd-guard/src/cli/tdd-guard.test.ts +159 -0
  204. package/project-skills/tdd-guard/src/cli/tdd-guard.ts +48 -0
  205. package/project-skills/tdd-guard/src/config/Config.test.ts +538 -0
  206. package/project-skills/tdd-guard/src/config/Config.ts +172 -0
  207. package/project-skills/tdd-guard/src/contracts/schemas/guardSchemas.test.ts +58 -0
  208. package/project-skills/tdd-guard/src/contracts/schemas/guardSchemas.ts +8 -0
  209. package/project-skills/tdd-guard/src/contracts/schemas/lintSchemas.test.ts +347 -0
  210. package/project-skills/tdd-guard/src/contracts/schemas/lintSchemas.ts +61 -0
  211. package/project-skills/tdd-guard/src/contracts/schemas/pytestSchemas.test.ts +24 -0
  212. package/project-skills/tdd-guard/src/contracts/schemas/pytestSchemas.ts +7 -0
  213. package/project-skills/tdd-guard/src/contracts/schemas/reporterSchemas.test.ts +377 -0
  214. package/project-skills/tdd-guard/src/contracts/schemas/reporterSchemas.ts +75 -0
  215. package/project-skills/tdd-guard/src/contracts/schemas/toolSchemas.test.ts +563 -0
  216. package/project-skills/tdd-guard/src/contracts/schemas/toolSchemas.ts +140 -0
  217. package/project-skills/tdd-guard/src/contracts/types/ClientType.ts +1 -0
  218. package/project-skills/tdd-guard/src/contracts/types/ConfigOptions.ts +12 -0
  219. package/project-skills/tdd-guard/src/contracts/types/Context.ts +16 -0
  220. package/project-skills/tdd-guard/src/contracts/types/ModelClient.ts +3 -0
  221. package/project-skills/tdd-guard/src/contracts/types/ValidationResult.ts +6 -0
  222. package/project-skills/tdd-guard/src/guard/GuardManager.test.ts +336 -0
  223. package/project-skills/tdd-guard/src/guard/GuardManager.ts +83 -0
  224. package/project-skills/tdd-guard/src/hooks/HookEvents.test.ts +107 -0
  225. package/project-skills/tdd-guard/src/hooks/HookEvents.ts +39 -0
  226. package/project-skills/tdd-guard/src/hooks/fileTypeDetection.ts +16 -0
  227. package/project-skills/tdd-guard/src/hooks/postToolLint.test.ts +327 -0
  228. package/project-skills/tdd-guard/src/hooks/postToolLint.ts +165 -0
  229. package/project-skills/tdd-guard/src/hooks/processHookData.test.ts +465 -0
  230. package/project-skills/tdd-guard/src/hooks/processHookData.ts +203 -0
  231. package/project-skills/tdd-guard/src/hooks/sessionHandler.test.ts +136 -0
  232. package/project-skills/tdd-guard/src/hooks/sessionHandler.ts +31 -0
  233. package/project-skills/tdd-guard/src/hooks/userPromptHandler.test.ts +131 -0
  234. package/project-skills/tdd-guard/src/hooks/userPromptHandler.ts +55 -0
  235. package/project-skills/tdd-guard/src/index.ts +19 -0
  236. package/project-skills/tdd-guard/src/linters/Linter.ts +5 -0
  237. package/project-skills/tdd-guard/src/linters/eslint/ESLint.test.ts +183 -0
  238. package/project-skills/tdd-guard/src/linters/eslint/ESLint.ts +82 -0
  239. package/project-skills/tdd-guard/src/linters/golangci/GolangciLint.test.ts +170 -0
  240. package/project-skills/tdd-guard/src/linters/golangci/GolangciLint.ts +148 -0
  241. package/project-skills/tdd-guard/src/processors/index.ts +1 -0
  242. package/project-skills/tdd-guard/src/processors/lintProcessor.ts +77 -0
  243. package/project-skills/tdd-guard/src/processors/testResults/TestResultsProcessor.test.ts +303 -0
  244. package/project-skills/tdd-guard/src/processors/testResults/TestResultsProcessor.ts +255 -0
  245. package/project-skills/tdd-guard/src/providers/LinterProvider.test.ts +43 -0
  246. package/project-skills/tdd-guard/src/providers/LinterProvider.ts +20 -0
  247. package/project-skills/tdd-guard/src/providers/ModelClientProvider.test.ts +68 -0
  248. package/project-skills/tdd-guard/src/providers/ModelClientProvider.ts +22 -0
  249. package/project-skills/tdd-guard/src/storage/FileStorage.test.ts +76 -0
  250. package/project-skills/tdd-guard/src/storage/FileStorage.ts +108 -0
  251. package/project-skills/tdd-guard/src/storage/MemoryStorage.ts +57 -0
  252. package/project-skills/tdd-guard/src/storage/Storage.test.ts +227 -0
  253. package/project-skills/tdd-guard/src/storage/Storage.ts +17 -0
  254. package/project-skills/tdd-guard/src/validation/context/context.test.ts +364 -0
  255. package/project-skills/tdd-guard/src/validation/context/context.ts +155 -0
  256. package/project-skills/tdd-guard/src/validation/models/AnthropicApi.test.ts +171 -0
  257. package/project-skills/tdd-guard/src/validation/models/AnthropicApi.ts +49 -0
  258. package/project-skills/tdd-guard/src/validation/models/ClaudeAgentSdk.test.ts +167 -0
  259. package/project-skills/tdd-guard/src/validation/models/ClaudeAgentSdk.ts +54 -0
  260. package/project-skills/tdd-guard/src/validation/models/ClaudeCli.test.ts +239 -0
  261. package/project-skills/tdd-guard/src/validation/models/ClaudeCli.ts +57 -0
  262. package/project-skills/tdd-guard/src/validation/prompts/file-types.ts +52 -0
  263. package/project-skills/tdd-guard/src/validation/prompts/operations/edit.ts +58 -0
  264. package/project-skills/tdd-guard/src/validation/prompts/operations/multi-edit.ts +54 -0
  265. package/project-skills/tdd-guard/src/validation/prompts/operations/write.ts +54 -0
  266. package/project-skills/tdd-guard/src/validation/prompts/response.ts +40 -0
  267. package/project-skills/tdd-guard/src/validation/prompts/rules.ts +51 -0
  268. package/project-skills/tdd-guard/src/validation/prompts/system-prompt.ts +10 -0
  269. package/project-skills/tdd-guard/src/validation/prompts/tools/lint-results.ts +15 -0
  270. package/project-skills/tdd-guard/src/validation/prompts/tools/test-output.ts +14 -0
  271. package/project-skills/tdd-guard/src/validation/prompts/tools/todos.ts +9 -0
  272. package/project-skills/tdd-guard/src/validation/validator.test.ts +268 -0
  273. package/project-skills/tdd-guard/src/validation/validator.ts +159 -0
  274. package/project-skills/tdd-guard/test/artifacts/go/.golangci.yml +6 -0
  275. package/project-skills/tdd-guard/test/artifacts/go/with-issues/file-with-issues.go +12 -0
  276. package/project-skills/tdd-guard/test/artifacts/go/with-issues/go.mod +3 -0
  277. package/project-skills/tdd-guard/test/artifacts/go/without-issues/file-without-issues.go +7 -0
  278. package/project-skills/tdd-guard/test/artifacts/go/without-issues/go.mod +3 -0
  279. package/project-skills/tdd-guard/test/artifacts/javascript/eslint.config.js +20 -0
  280. package/project-skills/tdd-guard/test/artifacts/javascript/file-with-issues.js +12 -0
  281. package/project-skills/tdd-guard/test/artifacts/javascript/file-without-issues.js +10 -0
  282. package/project-skills/tdd-guard/test/hooks/fileTypeDetection.test.ts +26 -0
  283. package/project-skills/tdd-guard/test/hooks/processHookData.fileType.test.ts +46 -0
  284. package/project-skills/tdd-guard/test/hooks/processHookData.python.test.ts +68 -0
  285. package/project-skills/tdd-guard/test/integration/test-context.test.ts +66 -0
  286. package/project-skills/tdd-guard/test/integration/validator.core.test.ts +96 -0
  287. package/project-skills/tdd-guard/test/integration/validator.scenarios.test.ts +497 -0
  288. package/project-skills/tdd-guard/test/utils/assertions.ts +29 -0
  289. package/project-skills/tdd-guard/test/utils/factories/contextFactory.ts +30 -0
  290. package/project-skills/tdd-guard/test/utils/factories/editFactory.ts +82 -0
  291. package/project-skills/tdd-guard/test/utils/factories/helpers.test.ts +46 -0
  292. package/project-skills/tdd-guard/test/utils/factories/helpers.ts +46 -0
  293. package/project-skills/tdd-guard/test/utils/factories/lintFactory.ts +352 -0
  294. package/project-skills/tdd-guard/test/utils/factories/modelClientProviderFactory.ts +21 -0
  295. package/project-skills/tdd-guard/test/utils/factories/multiEditFactory.ts +79 -0
  296. package/project-skills/tdd-guard/test/utils/factories/operations.ts +57 -0
  297. package/project-skills/tdd-guard/test/utils/factories/reporterFactory.ts +55 -0
  298. package/project-skills/tdd-guard/test/utils/factories/scenarios/index.ts +22 -0
  299. package/project-skills/tdd-guard/test/utils/factories/scenarios/languages/python.ts +745 -0
  300. package/project-skills/tdd-guard/test/utils/factories/scenarios/languages/typescript.ts +767 -0
  301. package/project-skills/tdd-guard/test/utils/factories/scenarios/types.ts +77 -0
  302. package/project-skills/tdd-guard/test/utils/factories/scenarios/utils.ts +15 -0
  303. package/project-skills/tdd-guard/test/utils/factories/sessionStartFactory.ts +36 -0
  304. package/project-skills/tdd-guard/test/utils/factories/testDefaults.ts +90 -0
  305. package/project-skills/tdd-guard/test/utils/factories/testResultsFactory.ts +234 -0
  306. package/project-skills/tdd-guard/test/utils/factories/todoFactory.ts +99 -0
  307. package/project-skills/tdd-guard/test/utils/factories/userPromptSubmitFactory.ts +39 -0
  308. package/project-skills/tdd-guard/test/utils/factories/writeFactory.ts +70 -0
  309. package/project-skills/tdd-guard/test/utils/index.ts +131 -0
  310. package/project-skills/tdd-guard/tsconfig.build.json +16 -0
  311. package/project-skills/tdd-guard/tsconfig.eslint.json +17 -0
  312. package/project-skills/tdd-guard/tsconfig.json +32 -0
  313. package/project-skills/tdd-guard/tsconfig.node.json +10 -0
  314. package/project-skills/tdd-guard/vitest.config.ts +85 -0
  315. package/project-skills/ts-quality-gate/.claude/hooks/hook-config.json +66 -0
  316. package/project-skills/ts-quality-gate/.claude/hooks/quality-check.cjs +1251 -0
  317. package/project-skills/ts-quality-gate/.claude/settings.json +16 -0
  318. package/project-skills/ts-quality-gate/.claude/skills/using-ts-quality-gate/SKILL.md +81 -0
  319. package/project-skills/ts-quality-gate/README.md +115 -0
  320. package/skills/README.txt +31 -0
  321. package/skills/clean-code/SKILL.md +201 -0
  322. package/skills/delegating/SKILL.md +196 -0
  323. package/skills/delegating/config.yaml +210 -0
  324. package/skills/delegating/references/orchestration-protocols.md +41 -0
  325. package/skills/docker-expert/SKILL.md +409 -0
  326. package/skills/documenting/CHANGELOG.md +23 -0
  327. package/skills/documenting/README.md +148 -0
  328. package/skills/documenting/SKILL.md +113 -0
  329. package/skills/documenting/examples/example_pattern.md +70 -0
  330. package/skills/documenting/examples/example_reference.md +70 -0
  331. package/skills/documenting/examples/example_ssot_analytics.md +64 -0
  332. package/skills/documenting/examples/example_workflow.md +141 -0
  333. package/skills/documenting/references/changelog-format.md +97 -0
  334. package/skills/documenting/references/metadata-schema.md +136 -0
  335. package/skills/documenting/references/taxonomy.md +81 -0
  336. package/skills/documenting/references/versioning-rules.md +78 -0
  337. package/skills/documenting/scripts/__pycache__/drift_detector.cpython-314.pyc +0 -0
  338. package/skills/documenting/scripts/__pycache__/orchestrator.cpython-314.pyc +0 -0
  339. package/skills/documenting/scripts/__pycache__/validate_metadata.cpython-314.pyc +0 -0
  340. package/skills/documenting/scripts/bump_version.sh +60 -0
  341. package/skills/documenting/scripts/changelog/__init__.py +0 -0
  342. package/skills/documenting/scripts/changelog/__pycache__/__init__.cpython-314.pyc +0 -0
  343. package/skills/documenting/scripts/changelog/__pycache__/add_entry.cpython-314.pyc +0 -0
  344. package/skills/documenting/scripts/changelog/__pycache__/bump_release.cpython-314.pyc +0 -0
  345. package/skills/documenting/scripts/changelog/__pycache__/validate_changelog.cpython-314.pyc +0 -0
  346. package/skills/documenting/scripts/changelog/add_entry.py +216 -0
  347. package/skills/documenting/scripts/changelog/bump_release.py +117 -0
  348. package/skills/documenting/scripts/changelog/init_changelog.py +54 -0
  349. package/skills/documenting/scripts/changelog/validate_changelog.py +128 -0
  350. package/skills/documenting/scripts/drift_detector.py +266 -0
  351. package/skills/documenting/scripts/generate_template.py +311 -0
  352. package/skills/documenting/scripts/list_by_category.sh +84 -0
  353. package/skills/documenting/scripts/orchestrator.py +255 -0
  354. package/skills/documenting/scripts/validate_metadata.py +242 -0
  355. package/skills/documenting/templates/CHANGELOG.md.template +13 -0
  356. package/skills/documenting/tests/__pycache__/test_changelog.cpython-314-pytest-9.0.2.pyc +0 -0
  357. package/skills/documenting/tests/__pycache__/test_drift_detector.cpython-314-pytest-9.0.2.pyc +0 -0
  358. package/skills/documenting/tests/__pycache__/test_orchestrator.cpython-314-pytest-9.0.2.pyc +0 -0
  359. package/skills/documenting/tests/__pycache__/test_validate_metadata.cpython-314-pytest-9.0.2.pyc +0 -0
  360. package/skills/documenting/tests/integration_test.sh +70 -0
  361. package/skills/documenting/tests/test_changelog.py +201 -0
  362. package/skills/documenting/tests/test_drift_detector.py +80 -0
  363. package/skills/documenting/tests/test_orchestrator.py +52 -0
  364. package/skills/documenting/tests/test_validate_metadata.py +64 -0
  365. package/skills/find-skills/SKILL.md +133 -0
  366. package/skills/gitnexus-debugging/SKILL.md +85 -0
  367. package/skills/gitnexus-exploring/SKILL.md +75 -0
  368. package/skills/gitnexus-impact-analysis/SKILL.md +94 -0
  369. package/skills/gitnexus-refactoring/SKILL.md +113 -0
  370. package/skills/hook-development/SKILL.md +797 -0
  371. package/skills/hook-development/examples/load-context.sh +55 -0
  372. package/skills/hook-development/examples/quality-check.js +1168 -0
  373. package/skills/hook-development/examples/validate-bash.sh +43 -0
  374. package/skills/hook-development/examples/validate-write.sh +38 -0
  375. package/skills/hook-development/references/advanced.md +527 -0
  376. package/skills/hook-development/references/migration.md +369 -0
  377. package/skills/hook-development/references/patterns.md +412 -0
  378. package/skills/hook-development/scripts/README.md +164 -0
  379. package/skills/hook-development/scripts/hook-linter.sh +153 -0
  380. package/skills/hook-development/scripts/test-hook.sh +252 -0
  381. package/skills/hook-development/scripts/validate-hook-schema.sh +159 -0
  382. package/skills/obsidian-cli/SKILL.md +106 -0
  383. package/skills/orchestrating-agents/SKILL.md +135 -0
  384. package/skills/orchestrating-agents/config.yaml +45 -0
  385. package/skills/orchestrating-agents/references/agent-context-integration.md +37 -0
  386. package/skills/orchestrating-agents/references/examples.md +45 -0
  387. package/skills/orchestrating-agents/references/handover-protocol.md +31 -0
  388. package/skills/orchestrating-agents/references/workflows.md +42 -0
  389. package/skills/orchestrating-agents/scripts/detect_neighbors.py +23 -0
  390. package/skills/prompt-improving/README.md +162 -0
  391. package/skills/prompt-improving/SKILL.md +74 -0
  392. package/skills/prompt-improving/references/analysis_commands.md +24 -0
  393. package/skills/prompt-improving/references/chain_of_thought.md +24 -0
  394. package/skills/prompt-improving/references/mcp_definitions.md +20 -0
  395. package/skills/prompt-improving/references/multishot.md +23 -0
  396. package/skills/prompt-improving/references/xml_core.md +60 -0
  397. package/skills/python-testing/SKILL.md +815 -0
  398. package/skills/senior-backend/SKILL.md +209 -0
  399. package/skills/senior-backend/references/api_design_patterns.md +103 -0
  400. package/skills/senior-backend/references/backend_security_practices.md +103 -0
  401. package/skills/senior-backend/references/database_optimization_guide.md +103 -0
  402. package/skills/senior-backend/scripts/api_load_tester.py +114 -0
  403. package/skills/senior-backend/scripts/api_scaffolder.py +114 -0
  404. package/skills/senior-backend/scripts/database_migration_tool.py +114 -0
  405. package/skills/senior-data-scientist/SKILL.md +226 -0
  406. package/skills/senior-data-scientist/references/experiment_design_frameworks.md +80 -0
  407. package/skills/senior-data-scientist/references/feature_engineering_patterns.md +80 -0
  408. package/skills/senior-data-scientist/references/statistical_methods_advanced.md +80 -0
  409. package/skills/senior-data-scientist/scripts/experiment_designer.py +100 -0
  410. package/skills/senior-data-scientist/scripts/feature_engineering_pipeline.py +100 -0
  411. package/skills/senior-data-scientist/scripts/model_evaluation_suite.py +100 -0
  412. package/skills/senior-devops/SKILL.md +209 -0
  413. package/skills/senior-devops/references/cicd_pipeline_guide.md +103 -0
  414. package/skills/senior-devops/references/deployment_strategies.md +103 -0
  415. package/skills/senior-devops/references/infrastructure_as_code.md +103 -0
  416. package/skills/senior-devops/scripts/deployment_manager.py +114 -0
  417. package/skills/senior-devops/scripts/pipeline_generator.py +114 -0
  418. package/skills/senior-devops/scripts/terraform_scaffolder.py +114 -0
  419. package/skills/senior-security/SKILL.md +209 -0
  420. package/skills/senior-security/references/cryptography_implementation.md +103 -0
  421. package/skills/senior-security/references/penetration_testing_guide.md +103 -0
  422. package/skills/senior-security/references/security_architecture_patterns.md +103 -0
  423. package/skills/senior-security/scripts/pentest_automator.py +114 -0
  424. package/skills/senior-security/scripts/security_auditor.py +114 -0
  425. package/skills/senior-security/scripts/threat_modeler.py +114 -0
  426. package/skills/skill-creator/LICENSE.txt +202 -0
  427. package/skills/skill-creator/SKILL.md +479 -0
  428. package/skills/skill-creator/agents/analyzer.md +274 -0
  429. package/skills/skill-creator/agents/comparator.md +202 -0
  430. package/skills/skill-creator/agents/grader.md +223 -0
  431. package/skills/skill-creator/assets/eval_review.html +146 -0
  432. package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  433. package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  434. package/skills/skill-creator/references/schemas.md +430 -0
  435. package/skills/skill-creator/scripts/__init__.py +0 -0
  436. package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  437. package/skills/skill-creator/scripts/generate_report.py +326 -0
  438. package/skills/skill-creator/scripts/improve_description.py +248 -0
  439. package/skills/skill-creator/scripts/package_skill.py +136 -0
  440. package/skills/skill-creator/scripts/quick_validate.py +103 -0
  441. package/skills/skill-creator/scripts/run_eval.py +310 -0
  442. package/skills/skill-creator/scripts/run_loop.py +332 -0
  443. package/skills/skill-creator/scripts/utils.py +47 -0
  444. package/skills/using-TDD/SKILL.md +410 -0
  445. package/skills/using-serena-lsp/README.md +8 -0
  446. package/skills/using-serena-lsp/REFERENCE.md +194 -0
  447. package/skills/using-serena-lsp/SKILL.md +82 -0
@@ -0,0 +1,1168 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * React App Quality Check Hook
4
+ * Optimized for React applications with sensible defaults
5
+ *
6
+ * EXIT CODES:
7
+ * 0 - Success (all checks passed)
8
+ * 1 - General error (missing dependencies, etc.)
9
+ * 2 - Quality issues found - ALL must be fixed (blocking)
10
+ */
11
+
12
+ const fs = require('fs').promises;
13
+ const path = require('path');
14
+ const crypto = require('crypto');
15
+
16
+ /**
17
+ * Get project root using CLAUDE_PROJECT_DIR environment variable
18
+ * @returns {string} Project root directory
19
+ */
20
+ function getProjectRoot() {
21
+ return process.env.CLAUDE_PROJECT_DIR || process.cwd();
22
+ }
23
+
24
+ const projectRoot = getProjectRoot();
25
+
26
+ /**
27
+ * Intelligent TypeScript Config Cache with checksum validation
28
+ * Handles multiple tsconfig files and maps files to appropriate configs
29
+ */
30
+ class TypeScriptConfigCache {
31
+ /**
32
+ * Creates a new TypeScript config cache instance.
33
+ * Loads existing cache or initializes empty cache.
34
+ */
35
+ constructor() {
36
+ // Store cache in the hook's directory for isolation
37
+ this.cacheFile = path.join(__dirname, 'tsconfig-cache.json');
38
+ this.cache = { hashes: {}, mappings: {} };
39
+ this.loadCache();
40
+ }
41
+
42
+ /**
43
+ * Get config hash for cache validation
44
+ * @param {string} configPath - Path to tsconfig file
45
+ * @returns {string} SHA256 hash of config content
46
+ */
47
+ getConfigHash(configPath) {
48
+ try {
49
+ const content = require('fs').readFileSync(configPath, 'utf8');
50
+ return crypto.createHash('sha256').update(content).digest('hex');
51
+ } catch (e) {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Find all tsconfig files in project
58
+ * @returns {string[]} Array of tsconfig file paths
59
+ */
60
+ findTsConfigFiles() {
61
+ const configs = [];
62
+ try {
63
+ // Try to use glob if available, fallback to manual search
64
+ const globSync = require('glob').sync;
65
+ return globSync('tsconfig*.json', { cwd: projectRoot }).map((file) =>
66
+ path.join(projectRoot, file)
67
+ );
68
+ } catch (e) {
69
+ // Fallback: manually check common config files
70
+ const commonConfigs = [
71
+ 'tsconfig.json',
72
+ 'tsconfig.webview.json',
73
+ 'tsconfig.test.json',
74
+ 'tsconfig.node.json',
75
+ ];
76
+
77
+ for (const config of commonConfigs) {
78
+ const configPath = path.join(projectRoot, config);
79
+ if (require('fs').existsSync(configPath)) {
80
+ configs.push(configPath);
81
+ }
82
+ }
83
+ return configs;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Check if cache is valid by comparing config hashes
89
+ * @returns {boolean} True if cache is valid
90
+ */
91
+ isValid() {
92
+ const configFiles = this.findTsConfigFiles();
93
+
94
+ // Check if we have the same number of configs
95
+ if (Object.keys(this.cache.hashes).length !== configFiles.length) {
96
+ return false;
97
+ }
98
+
99
+ // Check each config hash
100
+ for (const configPath of configFiles) {
101
+ const currentHash = this.getConfigHash(configPath);
102
+ if (currentHash !== this.cache.hashes[configPath]) {
103
+ return false;
104
+ }
105
+ }
106
+
107
+ return true;
108
+ }
109
+
110
+ /**
111
+ * Rebuild cache by parsing all configs and creating file mappings
112
+ */
113
+ rebuild() {
114
+ this.cache = { hashes: {}, mappings: {} };
115
+
116
+ // Process configs in priority order (most specific first)
117
+ const configPriority = [
118
+ 'tsconfig.webview.json', // Most specific
119
+ 'tsconfig.test.json', // Test-specific
120
+ 'tsconfig.json', // Base config
121
+ ];
122
+
123
+ configPriority.forEach((configName) => {
124
+ const configPath = path.join(projectRoot, configName);
125
+ if (!require('fs').existsSync(configPath)) {
126
+ return;
127
+ }
128
+
129
+ // Store hash for validation
130
+ this.cache.hashes[configPath] = this.getConfigHash(configPath);
131
+
132
+ try {
133
+ const configContent = require('fs').readFileSync(configPath, 'utf8');
134
+ const config = JSON.parse(configContent);
135
+
136
+ // Build file pattern mappings
137
+ if (config.include) {
138
+ config.include.forEach((pattern) => {
139
+ // Only set if not already mapped by a more specific config
140
+ if (!this.cache.mappings[pattern]) {
141
+ this.cache.mappings[pattern] = {
142
+ configPath,
143
+ excludes: config.exclude || [],
144
+ };
145
+ }
146
+ });
147
+ }
148
+ } catch (e) {
149
+ // Skip invalid configs
150
+ }
151
+ });
152
+
153
+ this.saveCache();
154
+ }
155
+
156
+ /**
157
+ * Load cache from disk
158
+ */
159
+ loadCache() {
160
+ try {
161
+ const cacheContent = require('fs').readFileSync(this.cacheFile, 'utf8');
162
+ this.cache = JSON.parse(cacheContent);
163
+ } catch (e) {
164
+ // Cache doesn't exist or is invalid, will rebuild
165
+ this.cache = { hashes: {}, mappings: {} };
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Save cache to disk
171
+ */
172
+ saveCache() {
173
+ try {
174
+ // Save cache directly in hook directory (directory already exists)
175
+ require('fs').writeFileSync(this.cacheFile, JSON.stringify(this.cache, null, 2));
176
+ } catch (e) {
177
+ // Ignore cache save errors
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Get appropriate tsconfig for a file
183
+ * @param {string} filePath - File path to check
184
+ * @returns {string} Path to appropriate tsconfig file
185
+ */
186
+ getTsConfigForFile(filePath) {
187
+ // Ensure cache is valid
188
+ if (!this.isValid()) {
189
+ this.rebuild();
190
+ }
191
+
192
+ const relativePath = path.relative(projectRoot, filePath);
193
+
194
+ // Check cached mappings first - these are from actual tsconfig includes
195
+ // Sort patterns by specificity to match most specific first
196
+ const sortedMappings = Object.entries(this.cache.mappings).sort(([a], [b]) => {
197
+ // More specific patterns first
198
+ const aSpecificity = a.split('/').length + (a.includes('**') ? 0 : 10);
199
+ const bSpecificity = b.split('/').length + (b.includes('**') ? 0 : 10);
200
+ return bSpecificity - aSpecificity;
201
+ });
202
+
203
+ for (const [pattern, mapping] of sortedMappings) {
204
+ // Handle both old format (string) and new format (object with excludes)
205
+ const configPath = typeof mapping === 'string' ? mapping : mapping.configPath;
206
+ const excludes = typeof mapping === 'string' ? [] : mapping.excludes;
207
+
208
+ if (this.matchesPattern(relativePath, pattern)) {
209
+ // Check if file is excluded
210
+ let isExcluded = false;
211
+ for (const exclude of excludes) {
212
+ if (this.matchesPattern(relativePath, exclude)) {
213
+ isExcluded = true;
214
+ break;
215
+ }
216
+ }
217
+
218
+ if (!isExcluded) {
219
+ return configPath;
220
+ }
221
+ }
222
+ }
223
+
224
+ // Fast heuristics for common cases not in cache
225
+ // Webview files
226
+ if (relativePath.includes('src/webview/') || relativePath.includes('/webview/')) {
227
+ const webviewConfig = path.join(projectRoot, 'tsconfig.webview.json');
228
+ if (require('fs').existsSync(webviewConfig)) {
229
+ return webviewConfig;
230
+ }
231
+ }
232
+
233
+ // Test files
234
+ if (
235
+ relativePath.includes('/test/') ||
236
+ relativePath.includes('.test.') ||
237
+ relativePath.includes('.spec.')
238
+ ) {
239
+ const testConfig = path.join(projectRoot, 'tsconfig.test.json');
240
+ if (require('fs').existsSync(testConfig)) {
241
+ return testConfig;
242
+ }
243
+ }
244
+
245
+ // Default fallback
246
+ return path.join(projectRoot, 'tsconfig.json');
247
+ }
248
+
249
+ /**
250
+ * Simple pattern matching for file paths
251
+ * @param {string} filePath - File path to test
252
+ * @param {string} pattern - Glob-like pattern
253
+ * @returns {boolean} True if file matches pattern
254
+ */
255
+ matchesPattern(filePath, pattern) {
256
+ // Simple pattern matching - convert glob to regex
257
+ // Handle the common patterns specially
258
+ if (pattern.endsWith('/**/*')) {
259
+ // For patterns like src/webview/**/* or src/protocol/**/*
260
+ // Match any file under that directory
261
+ const baseDir = pattern.slice(0, -5); // Remove /**/*
262
+ return filePath.startsWith(baseDir);
263
+ }
264
+
265
+ // For other patterns, use regex conversion
266
+ let regexPattern = pattern
267
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape regex special chars
268
+ .replace(/\*\*/g, '🌟') // Temporary placeholder for **
269
+ .replace(/\*/g, '[^/]*') // * matches anything except /
270
+ .replace(/🌟/g, '.*') // ** matches anything including /
271
+ .replace(/\?/g, '.'); // ? matches single character
272
+
273
+ const regex = new RegExp(`^${regexPattern}$`);
274
+ const result = regex.test(filePath);
275
+
276
+ return result;
277
+ }
278
+ }
279
+
280
+ // Global config cache instance
281
+ const tsConfigCache = new TypeScriptConfigCache();
282
+
283
+ // ANSI color codes
284
+ const colors = {
285
+ red: '\x1b[0;31m',
286
+ green: '\x1b[0;32m',
287
+ yellow: '\x1b[0;33m',
288
+ blue: '\x1b[0;34m',
289
+ cyan: '\x1b[0;36m',
290
+ reset: '\x1b[0m',
291
+ };
292
+
293
+ /**
294
+ * Load configuration from JSON file with environment variable overrides
295
+ * @returns {Object} Configuration object
296
+ */
297
+ function loadConfig() {
298
+ let fileConfig = {};
299
+
300
+ // Try to load hook-config.json
301
+ try {
302
+ const configPath = path.join(__dirname, 'hook-config.json');
303
+ if (require('fs').existsSync(configPath)) {
304
+ fileConfig = JSON.parse(require('fs').readFileSync(configPath, 'utf8'));
305
+ }
306
+ } catch (e) {
307
+ // Config file not found or invalid, use defaults
308
+ }
309
+
310
+ // Build config with file settings as base, env vars as overrides
311
+ return {
312
+ // TypeScript settings
313
+ typescriptEnabled:
314
+ process.env.CLAUDE_HOOKS_TYPESCRIPT_ENABLED !== undefined
315
+ ? process.env.CLAUDE_HOOKS_TYPESCRIPT_ENABLED !== 'false'
316
+ : (fileConfig.typescript?.enabled ?? true),
317
+
318
+ showDependencyErrors:
319
+ process.env.CLAUDE_HOOKS_SHOW_DEPENDENCY_ERRORS !== undefined
320
+ ? process.env.CLAUDE_HOOKS_SHOW_DEPENDENCY_ERRORS === 'true'
321
+ : (fileConfig.typescript?.showDependencyErrors ?? false),
322
+
323
+ // ESLint settings
324
+ eslintEnabled:
325
+ process.env.CLAUDE_HOOKS_ESLINT_ENABLED !== undefined
326
+ ? process.env.CLAUDE_HOOKS_ESLINT_ENABLED !== 'false'
327
+ : (fileConfig.eslint?.enabled ?? true),
328
+
329
+ eslintAutofix:
330
+ process.env.CLAUDE_HOOKS_ESLINT_AUTOFIX !== undefined
331
+ ? process.env.CLAUDE_HOOKS_ESLINT_AUTOFIX === 'true'
332
+ : (fileConfig.eslint?.autofix ?? false),
333
+
334
+ // Prettier settings
335
+ prettierEnabled:
336
+ process.env.CLAUDE_HOOKS_PRETTIER_ENABLED !== undefined
337
+ ? process.env.CLAUDE_HOOKS_PRETTIER_ENABLED !== 'false'
338
+ : (fileConfig.prettier?.enabled ?? true),
339
+
340
+ prettierAutofix:
341
+ process.env.CLAUDE_HOOKS_PRETTIER_AUTOFIX !== undefined
342
+ ? process.env.CLAUDE_HOOKS_PRETTIER_AUTOFIX === 'true'
343
+ : (fileConfig.prettier?.autofix ?? false),
344
+
345
+ // General settings
346
+ autofixSilent:
347
+ process.env.CLAUDE_HOOKS_AUTOFIX_SILENT !== undefined
348
+ ? process.env.CLAUDE_HOOKS_AUTOFIX_SILENT === 'true'
349
+ : (fileConfig.general?.autofixSilent ?? false),
350
+
351
+ debug:
352
+ process.env.CLAUDE_HOOKS_DEBUG !== undefined
353
+ ? process.env.CLAUDE_HOOKS_DEBUG === 'true'
354
+ : (fileConfig.general?.debug ?? false),
355
+
356
+ // Ignore patterns
357
+ ignorePatterns: fileConfig.ignore?.patterns || [],
358
+
359
+ // Store the full config for rule access
360
+ _fileConfig: fileConfig,
361
+ };
362
+ }
363
+
364
+ /**
365
+ * Hook Configuration
366
+ *
367
+ * Configuration is loaded from (in order of precedence):
368
+ * 1. Environment variables (highest priority)
369
+ * 2. .claude/hooks/config.json file
370
+ * 3. Built-in defaults
371
+ */
372
+ const config = loadConfig();
373
+
374
+ // Logging functions - define before using
375
+ const log = {
376
+ info: (msg) => console.error(`${colors.blue}[INFO]${colors.reset} ${msg}`),
377
+ error: (msg) => console.error(`${colors.red}[ERROR]${colors.reset} ${msg}`),
378
+ success: (msg) => console.error(`${colors.green}[OK]${colors.reset} ${msg}`),
379
+ warning: (msg) => console.error(`${colors.yellow}[WARN]${colors.reset} ${msg}`),
380
+ debug: (msg) => {
381
+ if (config.debug) {
382
+ console.error(`${colors.cyan}[DEBUG]${colors.reset} ${msg}`);
383
+ }
384
+ },
385
+ };
386
+
387
+ // Note: errors and autofixes are tracked per QualityChecker instance
388
+
389
+ // Try to load modules, but make them optional
390
+ let ESLint, prettier, ts;
391
+
392
+ try {
393
+ ({ ESLint } = require(path.join(projectRoot, 'node_modules', 'eslint')));
394
+ } catch (e) {
395
+ log.debug('ESLint not found in project - will skip ESLint checks');
396
+ }
397
+
398
+ try {
399
+ prettier = require(path.join(projectRoot, 'node_modules', 'prettier'));
400
+ } catch (e) {
401
+ log.debug('Prettier not found in project - will skip Prettier checks');
402
+ }
403
+
404
+ try {
405
+ ts = require(path.join(projectRoot, 'node_modules', 'typescript'));
406
+ } catch (e) {
407
+ log.debug('TypeScript not found in project - will skip TypeScript checks');
408
+ }
409
+
410
+ /**
411
+ * Quality checker for a single file.
412
+ * Runs TypeScript, ESLint, and Prettier checks with optional auto-fixing.
413
+ */
414
+ class QualityChecker {
415
+ /**
416
+ * Creates a new QualityChecker instance.
417
+ * @param {string} filePath - Path to file to check
418
+ */
419
+ constructor(filePath) {
420
+ this.filePath = filePath;
421
+ this.fileType = this.detectFileType(filePath);
422
+ this.errors = [];
423
+ this.autofixes = [];
424
+ }
425
+
426
+ /**
427
+ * Detect file type from path
428
+ * @param {string} filePath - File path
429
+ * @returns {string} File type
430
+ */
431
+ detectFileType(filePath) {
432
+ if (/\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filePath)) {
433
+ return 'test';
434
+ }
435
+ if (/\/store\/|\/slices\/|\/reducers\//.test(filePath)) {
436
+ return 'redux';
437
+ }
438
+ if (/\/components\/.*\.(tsx|jsx)$/.test(filePath)) {
439
+ return 'component';
440
+ }
441
+ if (/\.(ts|tsx)$/.test(filePath)) {
442
+ return 'typescript';
443
+ }
444
+ if (/\.(js|jsx)$/.test(filePath)) {
445
+ return 'javascript';
446
+ }
447
+ return 'unknown';
448
+ }
449
+
450
+ /**
451
+ * Run all quality checks
452
+ * @returns {Promise<{errors: string[], autofixes: string[]}>} Check results
453
+ */
454
+ async checkAll() {
455
+ // This should never happen now since we filter out non-source files earlier,
456
+ // but keeping for consistency with shell version
457
+ if (this.fileType === 'unknown') {
458
+ log.info('Unknown file type, skipping detailed checks');
459
+ return { errors: [], autofixes: [] };
460
+ }
461
+
462
+ // Run all checks in parallel for speed
463
+ const checkPromises = [];
464
+
465
+ if (config.typescriptEnabled) {
466
+ checkPromises.push(this.checkTypeScript());
467
+ }
468
+
469
+ if (config.eslintEnabled) {
470
+ checkPromises.push(this.checkESLint());
471
+ }
472
+
473
+ if (config.prettierEnabled) {
474
+ checkPromises.push(this.checkPrettier());
475
+ }
476
+
477
+ checkPromises.push(this.checkCommonIssues());
478
+
479
+ await Promise.all(checkPromises);
480
+
481
+ // Check for related tests (not critical, so separate)
482
+ await this.suggestRelatedTests();
483
+
484
+ return {
485
+ errors: this.errors,
486
+ autofixes: this.autofixes,
487
+ };
488
+ }
489
+
490
+ /**
491
+ * Get file dependencies by parsing imports
492
+ * @param {string} filePath - File to analyze
493
+ * @returns {string[]} Array of file paths including dependencies
494
+ */
495
+ getFileDependencies(filePath) {
496
+ const dependencies = new Set([filePath]);
497
+
498
+ try {
499
+ const content = require('fs').readFileSync(filePath, 'utf8');
500
+ const importRegex = /import\s+.*?\s+from\s+['"]([^'"]+)['"]/g;
501
+ let match;
502
+
503
+ while ((match = importRegex.exec(content)) !== null) {
504
+ const importPath = match[1];
505
+
506
+ // Only include relative imports (project files)
507
+ if (importPath.startsWith('.')) {
508
+ const resolvedPath = this.resolveImportPath(filePath, importPath);
509
+ if (resolvedPath && require('fs').existsSync(resolvedPath)) {
510
+ dependencies.add(resolvedPath);
511
+ }
512
+ }
513
+ }
514
+ } catch (e) {
515
+ // If we can't parse imports, just use the original file
516
+ log.debug(`Could not parse imports for ${filePath}: ${e.message}`);
517
+ }
518
+
519
+ return Array.from(dependencies);
520
+ }
521
+
522
+ /**
523
+ * Resolve relative import path to absolute path
524
+ * @param {string} fromFile - File doing the import
525
+ * @param {string} importPath - Relative import path
526
+ * @returns {string|null} Absolute file path or null if not found
527
+ */
528
+ resolveImportPath(fromFile, importPath) {
529
+ const dir = path.dirname(fromFile);
530
+ const resolved = path.resolve(dir, importPath);
531
+
532
+ // Try common extensions
533
+ const extensions = ['.ts', '.tsx', '.js', '.jsx'];
534
+ for (const ext of extensions) {
535
+ const fullPath = resolved + ext;
536
+ if (require('fs').existsSync(fullPath)) {
537
+ return fullPath;
538
+ }
539
+ }
540
+
541
+ // Try index files
542
+ for (const ext of extensions) {
543
+ const indexPath = path.join(resolved, 'index' + ext);
544
+ if (require('fs').existsSync(indexPath)) {
545
+ return indexPath;
546
+ }
547
+ }
548
+
549
+ return null;
550
+ }
551
+
552
+ /**
553
+ * Check TypeScript compilation
554
+ * @returns {Promise<void>}
555
+ */
556
+ async checkTypeScript() {
557
+ if (!config.typescriptEnabled || !ts) {
558
+ return;
559
+ }
560
+
561
+ // Skip TypeScript checking for JavaScript files in hook directories
562
+ if (this.filePath.endsWith('.js') && this.filePath.includes('.claude/hooks/')) {
563
+ log.debug('Skipping TypeScript check for JavaScript hook file');
564
+ return;
565
+ }
566
+
567
+ log.info('Running TypeScript compilation check...');
568
+
569
+ try {
570
+ // Get intelligent config for this file
571
+ const configPath = tsConfigCache.getTsConfigForFile(this.filePath);
572
+
573
+ if (!require('fs').existsSync(configPath)) {
574
+ log.debug(`No TypeScript config found: ${configPath}`);
575
+ return;
576
+ }
577
+
578
+ log.debug(
579
+ `Using TypeScript config: ${path.basename(configPath)} for ${path.relative(projectRoot, this.filePath)}`
580
+ );
581
+
582
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
583
+ const parsedConfig = ts.parseJsonConfigFileContent(
584
+ configFile.config,
585
+ ts.sys,
586
+ path.dirname(configPath)
587
+ );
588
+
589
+ // Only check the edited file, not its dependencies
590
+ // Dependencies will be type-checked with their own appropriate configs
591
+ log.debug(`TypeScript checking edited file only`);
592
+
593
+ // Create program with just the edited file
594
+ const program = ts.createProgram([this.filePath], parsedConfig.options);
595
+ const diagnostics = ts.getPreEmitDiagnostics(program);
596
+
597
+ // Group diagnostics by file
598
+ const diagnosticsByFile = new Map();
599
+ diagnostics.forEach((d) => {
600
+ if (d.file) {
601
+ const fileName = d.file.fileName;
602
+ if (!diagnosticsByFile.has(fileName)) {
603
+ diagnosticsByFile.set(fileName, []);
604
+ }
605
+ diagnosticsByFile.get(fileName).push(d);
606
+ }
607
+ });
608
+
609
+ // Report edited file first
610
+ const editedFileDiagnostics = diagnosticsByFile.get(this.filePath) || [];
611
+ if (editedFileDiagnostics.length > 0) {
612
+ this.errors.push(`TypeScript errors in edited file (using ${path.basename(configPath)})`);
613
+ editedFileDiagnostics.forEach((diagnostic) => {
614
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
615
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(
616
+ diagnostic.start
617
+ );
618
+ console.error(
619
+ ` ❌ ${diagnostic.file.fileName}:${line + 1}:${character + 1} - ${message}`
620
+ );
621
+ });
622
+ }
623
+
624
+ // Report dependencies separately (as warnings, not errors) - only if enabled
625
+ if (config.showDependencyErrors) {
626
+ let hasDepErrors = false;
627
+ diagnosticsByFile.forEach((diags, fileName) => {
628
+ if (fileName !== this.filePath) {
629
+ if (!hasDepErrors) {
630
+ console.error('\n[DEPENDENCY ERRORS] Files imported by your edited file:');
631
+ hasDepErrors = true;
632
+ }
633
+ console.error(` ⚠️ ${fileName}:`);
634
+ diags.forEach((diagnostic) => {
635
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
636
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(
637
+ diagnostic.start
638
+ );
639
+ console.error(` Line ${line + 1}:${character + 1} - ${message}`);
640
+ });
641
+ }
642
+ });
643
+ }
644
+
645
+ if (diagnostics.length === 0) {
646
+ log.success('TypeScript compilation passed');
647
+ }
648
+ } catch (error) {
649
+ log.debug(`TypeScript check error: ${error.message}`);
650
+ }
651
+ }
652
+
653
+ /**
654
+ * Check ESLint rules
655
+ * @returns {Promise<void>}
656
+ */
657
+ async checkESLint() {
658
+ if (!config.eslintEnabled || !ESLint) {
659
+ return;
660
+ }
661
+
662
+ log.info('Running ESLint...');
663
+
664
+ try {
665
+ const eslint = new ESLint({
666
+ fix: config.eslintAutofix,
667
+ cwd: projectRoot,
668
+ });
669
+
670
+ const results = await eslint.lintFiles([this.filePath]);
671
+ const result = results[0];
672
+
673
+ if (result.errorCount > 0 || result.warningCount > 0) {
674
+ if (config.eslintAutofix) {
675
+ log.warning('ESLint issues found, attempting auto-fix...');
676
+
677
+ // Write the fixed output
678
+ if (result.output) {
679
+ await fs.writeFile(this.filePath, result.output);
680
+
681
+ // Re-lint to see if issues remain
682
+ const resultsAfterFix = await eslint.lintFiles([this.filePath]);
683
+ const resultAfterFix = resultsAfterFix[0];
684
+
685
+ if (resultAfterFix.errorCount === 0 && resultAfterFix.warningCount === 0) {
686
+ log.success('ESLint auto-fixed all issues!');
687
+ if (config.autofixSilent) {
688
+ this.autofixes.push('ESLint auto-fixed formatting/style issues');
689
+ } else {
690
+ this.errors.push('ESLint issues were auto-fixed - verify the changes');
691
+ }
692
+ } else {
693
+ this.errors.push(
694
+ `ESLint found issues that couldn't be auto-fixed in ${this.filePath}`
695
+ );
696
+ const formatter = await eslint.loadFormatter('stylish');
697
+ const output = formatter.format(resultsAfterFix);
698
+ console.error(output);
699
+ }
700
+ } else {
701
+ this.errors.push(`ESLint found issues in ${this.filePath}`);
702
+ const formatter = await eslint.loadFormatter('stylish');
703
+ const output = formatter.format(results);
704
+ console.error(output);
705
+ }
706
+ } else {
707
+ this.errors.push(`ESLint found issues in ${this.filePath}`);
708
+ const formatter = await eslint.loadFormatter('stylish');
709
+ const output = formatter.format(results);
710
+ console.error(output);
711
+ }
712
+ } else {
713
+ log.success('ESLint passed');
714
+ }
715
+ } catch (error) {
716
+ log.debug(`ESLint check error: ${error.message}`);
717
+ }
718
+ }
719
+
720
+ /**
721
+ * Check Prettier formatting
722
+ * @returns {Promise<void>}
723
+ */
724
+ async checkPrettier() {
725
+ if (!config.prettierEnabled || !prettier) {
726
+ return;
727
+ }
728
+
729
+ log.info('Running Prettier check...');
730
+
731
+ try {
732
+ const fileContent = await fs.readFile(this.filePath, 'utf8');
733
+ const prettierConfig = await prettier.resolveConfig(this.filePath);
734
+
735
+ const isFormatted = await prettier.check(fileContent, {
736
+ ...prettierConfig,
737
+ filepath: this.filePath,
738
+ });
739
+
740
+ if (!isFormatted) {
741
+ if (config.prettierAutofix) {
742
+ log.warning('Prettier formatting issues found, auto-fixing...');
743
+
744
+ const formatted = await prettier.format(fileContent, {
745
+ ...prettierConfig,
746
+ filepath: this.filePath,
747
+ });
748
+
749
+ await fs.writeFile(this.filePath, formatted);
750
+ log.success('Prettier auto-formatted the file!');
751
+
752
+ if (config.autofixSilent) {
753
+ this.autofixes.push('Prettier auto-formatted the file');
754
+ } else {
755
+ this.errors.push('Prettier formatting was auto-fixed - verify the changes');
756
+ }
757
+ } else {
758
+ this.errors.push(`Prettier formatting issues in ${this.filePath}`);
759
+ console.error('Run prettier --write to fix');
760
+ }
761
+ } else {
762
+ log.success('Prettier formatting correct');
763
+ }
764
+ } catch (error) {
765
+ log.debug(`Prettier check error: ${error.message}`);
766
+ }
767
+ }
768
+
769
+ /**
770
+ * Check for common code issues
771
+ * @returns {Promise<void>}
772
+ */
773
+ async checkCommonIssues() {
774
+ log.info('Checking for common issues...');
775
+
776
+ try {
777
+ const content = await fs.readFile(this.filePath, 'utf8');
778
+ const lines = content.split('\n');
779
+ let foundIssues = false;
780
+
781
+ // Check for 'as any' in TypeScript files
782
+ const asAnyRule = config._fileConfig.rules?.asAny || {};
783
+ if (
784
+ (this.fileType === 'typescript' || this.fileType === 'component') &&
785
+ asAnyRule.enabled !== false
786
+ ) {
787
+ lines.forEach((line, index) => {
788
+ if (line.includes('as any')) {
789
+ const severity = asAnyRule.severity || 'error';
790
+ const message =
791
+ asAnyRule.message || 'Prefer proper types or "as unknown" for type assertions';
792
+
793
+ if (severity === 'error') {
794
+ this.errors.push(`Found 'as any' usage in ${this.filePath} - ${message}`);
795
+ console.error(` Line ${index + 1}: ${line.trim()}`);
796
+ foundIssues = true;
797
+ } else {
798
+ // Warning level - just warn, don't block
799
+ log.warning(`'as any' usage at line ${index + 1}: ${message}`);
800
+ }
801
+ }
802
+ });
803
+ }
804
+
805
+ // Check for console statements based on React app rules
806
+ const consoleRule = config._fileConfig.rules?.console || {};
807
+ let allowConsole = false;
808
+
809
+ // Check if console is allowed in this file
810
+ if (consoleRule.enabled === false) {
811
+ allowConsole = true;
812
+ } else {
813
+ // Check allowed paths
814
+ const allowedPaths = consoleRule.allowIn?.paths || [];
815
+ if (allowedPaths.some((path) => this.filePath.includes(path))) {
816
+ allowConsole = true;
817
+ }
818
+
819
+ // Check allowed file types
820
+ const allowedFileTypes = consoleRule.allowIn?.fileTypes || [];
821
+ if (allowedFileTypes.includes(this.fileType)) {
822
+ allowConsole = true;
823
+ }
824
+
825
+ // Check allowed patterns
826
+ const allowedPatterns = consoleRule.allowIn?.patterns || [];
827
+ const fileName = path.basename(this.filePath);
828
+ if (
829
+ allowedPatterns.some((pattern) => {
830
+ const regex = new RegExp(pattern.replace(/\*/g, '.*'));
831
+ return regex.test(fileName);
832
+ })
833
+ ) {
834
+ allowConsole = true;
835
+ }
836
+ }
837
+
838
+ // For React apps, console is generally allowed but shows as info
839
+ if (!allowConsole && consoleRule.enabled !== false) {
840
+ lines.forEach((line, index) => {
841
+ if (/console\./.test(line)) {
842
+ const severity = consoleRule.severity || 'info';
843
+ const message = consoleRule.message || 'Consider using a logging library';
844
+
845
+ if (severity === 'error') {
846
+ this.errors.push(`Found console statements in ${this.filePath} - ${message}`);
847
+ console.error(` Line ${index + 1}: ${line.trim()}`);
848
+ foundIssues = true;
849
+ } else {
850
+ // Info level - just warn, don't block
851
+ log.warning(`Console usage at line ${index + 1}: ${message}`);
852
+ }
853
+ }
854
+ });
855
+ }
856
+
857
+ // Check for TODO/FIXME comments
858
+ lines.forEach((line, index) => {
859
+ if (/TODO|FIXME/.test(line)) {
860
+ log.warning(`Found TODO/FIXME comment at line ${index + 1}`);
861
+ }
862
+ });
863
+
864
+ if (!foundIssues) {
865
+ log.success('No common issues found');
866
+ }
867
+ } catch (error) {
868
+ log.debug(`Common issues check error: ${error.message}`);
869
+ }
870
+ }
871
+
872
+ /**
873
+ * Suggest related test files
874
+ * @returns {Promise<void>}
875
+ */
876
+ async suggestRelatedTests() {
877
+ // Skip for test files
878
+ if (this.fileType === 'test') {
879
+ return;
880
+ }
881
+
882
+ const baseName = this.filePath.replace(/\.[^.]+$/, '');
883
+ const testExtensions = ['test.ts', 'test.tsx', 'spec.ts', 'spec.tsx'];
884
+ let hasTests = false;
885
+
886
+ for (const ext of testExtensions) {
887
+ try {
888
+ await fs.access(`${baseName}.${ext}`);
889
+ hasTests = true;
890
+ log.warning(`💡 Related test found: ${path.basename(baseName)}.${ext}`);
891
+ log.warning(' Consider running the tests to ensure nothing broke');
892
+ break;
893
+ } catch {
894
+ // File doesn't exist, continue
895
+ }
896
+ }
897
+
898
+ if (!hasTests) {
899
+ // Check __tests__ directory
900
+ const dir = path.dirname(this.filePath);
901
+ const fileName = path.basename(this.filePath);
902
+ const baseFileName = fileName.replace(/\.[^.]+$/, '');
903
+
904
+ for (const ext of testExtensions) {
905
+ try {
906
+ await fs.access(path.join(dir, '__tests__', `${baseFileName}.${ext}`));
907
+ hasTests = true;
908
+ log.warning(`💡 Related test found: __tests__/${baseFileName}.${ext}`);
909
+ log.warning(' Consider running the tests to ensure nothing broke');
910
+ break;
911
+ } catch {
912
+ // File doesn't exist, continue
913
+ }
914
+ }
915
+ }
916
+
917
+ if (!hasTests) {
918
+ log.warning(`💡 No test file found for ${path.basename(this.filePath)}`);
919
+ log.warning(' Consider adding tests for better code quality');
920
+ }
921
+
922
+ // Special reminders for specific file types
923
+ if (/\/state\/slices\//.test(this.filePath)) {
924
+ log.warning('💡 Redux state file! Consider testing state updates');
925
+ } else if (/\/components\//.test(this.filePath)) {
926
+ log.warning('💡 Component file! Consider testing UI behavior');
927
+ } else if (/\/services\//.test(this.filePath)) {
928
+ log.warning('💡 Service file! Consider testing business logic');
929
+ }
930
+ }
931
+ }
932
+
933
+ /**
934
+ * Parse JSON input from stdin
935
+ * @returns {Promise<Object>} Parsed JSON object
936
+ */
937
+ async function parseJsonInput() {
938
+ let inputData = '';
939
+
940
+ // Read from stdin
941
+ for await (const chunk of process.stdin) {
942
+ inputData += chunk;
943
+ }
944
+
945
+ if (!inputData.trim()) {
946
+ log.warning('No JSON input provided. This hook expects JSON input from Claude Code.');
947
+ log.info(
948
+ 'For testing, provide JSON like: echo \'{"tool_name":"Edit","tool_input":{"file_path":"/path/to/file.ts"}}\' | node hook.js'
949
+ );
950
+ console.error(`\n${colors.yellow}👉 Hook executed but no input to process.${colors.reset}`);
951
+ process.exit(0);
952
+ }
953
+
954
+ try {
955
+ return JSON.parse(inputData);
956
+ } catch (error) {
957
+ log.error(`Failed to parse JSON input: ${error.message}`);
958
+ log.debug(`Input was: ${inputData}`);
959
+ process.exit(1);
960
+ }
961
+ }
962
+
963
+ /**
964
+ * Extract file path from tool input
965
+ * @param {Object} input - Tool input object
966
+ * @returns {string|null} File path or null
967
+ */
968
+ function extractFilePath(input) {
969
+ const { tool_input } = input;
970
+ if (!tool_input) {
971
+ return null;
972
+ }
973
+
974
+ return tool_input.file_path || tool_input.path || tool_input.notebook_path || null;
975
+ }
976
+
977
+ /**
978
+ * Check if file exists
979
+ * @param {string} filePath - Path to check
980
+ * @returns {Promise<boolean>} True if exists
981
+ */
982
+ async function fileExists(filePath) {
983
+ try {
984
+ await fs.access(filePath);
985
+ return true;
986
+ } catch {
987
+ return false;
988
+ }
989
+ }
990
+
991
+ /**
992
+ * Check if file is a source file
993
+ * @param {string} filePath - Path to check
994
+ * @returns {boolean} True if source file
995
+ */
996
+ function isSourceFile(filePath) {
997
+ return /\.(ts|tsx|js|jsx)$/.test(filePath);
998
+ }
999
+
1000
+ /**
1001
+ * Print summary of errors and autofixes
1002
+ * @param {string[]} errors - List of errors
1003
+ * @param {string[]} autofixes - List of autofixes
1004
+ */
1005
+ function printSummary(errors, autofixes) {
1006
+ // Show auto-fixes if any
1007
+ if (autofixes.length > 0) {
1008
+ console.error(`\n${colors.blue}═══ Auto-fixes Applied ═══${colors.reset}`);
1009
+ autofixes.forEach((fix) => {
1010
+ console.error(`${colors.green}✨${colors.reset} ${fix}`);
1011
+ });
1012
+ console.error(
1013
+ `${colors.green}Automatically fixed ${autofixes.length} issue(s) for you!${colors.reset}`
1014
+ );
1015
+ }
1016
+
1017
+ // Show errors if any
1018
+ if (errors.length > 0) {
1019
+ console.error(`\n${colors.blue}═══ Quality Check Summary ═══${colors.reset}`);
1020
+ errors.forEach((error) => {
1021
+ console.error(`${colors.red}❌${colors.reset} ${error}`);
1022
+ });
1023
+
1024
+ console.error(
1025
+ `\n${colors.red}Found ${errors.length} issue(s) that MUST be fixed!${colors.reset}`
1026
+ );
1027
+ console.error(`${colors.red}════════════════════════════════════════════${colors.reset}`);
1028
+ console.error(`${colors.red}❌ ALL ISSUES ARE BLOCKING ❌${colors.reset}`);
1029
+ console.error(`${colors.red}════════════════════════════════════════════${colors.reset}`);
1030
+ console.error(`${colors.red}Fix EVERYTHING above until all checks are ✅ GREEN${colors.reset}`);
1031
+ }
1032
+ }
1033
+
1034
+ /**
1035
+ * Main entry point
1036
+ * @returns {Promise<void>}
1037
+ */
1038
+ async function main() {
1039
+ // Show header with version
1040
+ const hookVersion = config._fileConfig.version || '1.0.0';
1041
+ console.error('');
1042
+ console.error(`⚛️ React App Quality Check v${hookVersion} - Starting...`);
1043
+ console.error('────────────────────────────────────────────');
1044
+
1045
+ // Debug: show loaded configuration
1046
+ log.debug(`Loaded config: ${JSON.stringify(config, null, 2)}`);
1047
+
1048
+ // Parse input
1049
+ const input = await parseJsonInput();
1050
+ const filePath = extractFilePath(input);
1051
+
1052
+ if (!filePath) {
1053
+ log.warning('No file path found in JSON input. Tool might not be file-related.');
1054
+ log.debug(`JSON input was: ${JSON.stringify(input)}`);
1055
+ console.error(
1056
+ `\n${colors.yellow}👉 No file to check - tool may not be file-related.${colors.reset}`
1057
+ );
1058
+ process.exit(0);
1059
+ }
1060
+
1061
+ // Check if file exists
1062
+ if (!(await fileExists(filePath))) {
1063
+ log.info(`File does not exist: ${filePath} (may have been deleted)`);
1064
+ console.error(`\n${colors.yellow}👉 File skipped - doesn't exist.${colors.reset}`);
1065
+ process.exit(0);
1066
+ }
1067
+
1068
+ // For non-source files, exit successfully without checks (matching shell behavior)
1069
+ if (!isSourceFile(filePath)) {
1070
+ log.info(`Skipping non-source file: ${filePath}`);
1071
+ console.error(`\n${colors.yellow}👉 File skipped - not a source file.${colors.reset}`);
1072
+ console.error(
1073
+ `\n${colors.green}✅ No checks needed for ${path.basename(filePath)}${colors.reset}`
1074
+ );
1075
+ process.exit(0);
1076
+ }
1077
+
1078
+ // Update header with file name
1079
+ console.error('');
1080
+ console.error(`🔍 Validating: ${path.basename(filePath)}`);
1081
+ console.error('────────────────────────────────────────────');
1082
+ log.info(`Checking: ${filePath}`);
1083
+
1084
+ // Run quality checks
1085
+ const checker = new QualityChecker(filePath);
1086
+ const { errors, autofixes } = await checker.checkAll();
1087
+
1088
+ // Print summary
1089
+ printSummary(errors, autofixes);
1090
+
1091
+ // Separate edited file errors from other issues
1092
+ const editedFileErrors = errors.filter(
1093
+ (e) =>
1094
+ e.includes('edited file') ||
1095
+ e.includes('ESLint found issues') ||
1096
+ e.includes('Prettier formatting issues') ||
1097
+ e.includes('console statements') ||
1098
+ e.includes("'as any' usage") ||
1099
+ e.includes('were auto-fixed')
1100
+ );
1101
+
1102
+ const dependencyWarnings = errors.filter((e) => !editedFileErrors.includes(e));
1103
+
1104
+ // Exit with appropriate code
1105
+ if (editedFileErrors.length > 0) {
1106
+ // Critical - blocks immediately
1107
+ console.error(`\n${colors.red}🛑 FAILED - Fix issues in your edited file! 🛑${colors.reset}`);
1108
+ console.error(`${colors.cyan}💡 CLAUDE.md CHECK:${colors.reset}`);
1109
+ console.error(
1110
+ `${colors.cyan} → What CLAUDE.md pattern would have prevented this?${colors.reset}`
1111
+ );
1112
+ console.error(`${colors.cyan} → Are you following JSDoc batching strategy?${colors.reset}`);
1113
+ console.error(`${colors.yellow}📋 NEXT STEPS:${colors.reset}`);
1114
+ console.error(`${colors.yellow} 1. Fix the issues listed above${colors.reset}`);
1115
+ console.error(`${colors.yellow} 2. The hook will run again automatically${colors.reset}`);
1116
+ console.error(
1117
+ `${colors.yellow} 3. Continue with your original task once all checks pass${colors.reset}`
1118
+ );
1119
+ process.exit(2);
1120
+ } else if (dependencyWarnings.length > 0) {
1121
+ // Warning - shows but doesn't block
1122
+ console.error(`\n${colors.yellow}⚠️ WARNING - Dependency issues found${colors.reset}`);
1123
+ console.error(
1124
+ `${colors.yellow}These won't block your progress but should be addressed${colors.reset}`
1125
+ );
1126
+ console.error(
1127
+ `\n${colors.green}✅ Quality check passed for ${path.basename(filePath)}${colors.reset}`
1128
+ );
1129
+
1130
+ if (autofixes.length > 0 && config.autofixSilent) {
1131
+ console.error(
1132
+ `\n${colors.yellow}👉 File quality verified. Auto-fixes applied. Continue with your task.${colors.reset}`
1133
+ );
1134
+ } else {
1135
+ console.error(
1136
+ `\n${colors.yellow}👉 File quality verified. Continue with your task.${colors.reset}`
1137
+ );
1138
+ }
1139
+ process.exit(0); // Don't block on dependency issues
1140
+ } else {
1141
+ console.error(
1142
+ `\n${colors.green}✅ Quality check passed for ${path.basename(filePath)}${colors.reset}`
1143
+ );
1144
+
1145
+ if (autofixes.length > 0 && config.autofixSilent) {
1146
+ console.error(
1147
+ `\n${colors.yellow}👉 File quality verified. Auto-fixes applied. Continue with your task.${colors.reset}`
1148
+ );
1149
+ } else {
1150
+ console.error(
1151
+ `\n${colors.yellow}👉 File quality verified. Continue with your task.${colors.reset}`
1152
+ );
1153
+ }
1154
+ process.exit(0);
1155
+ }
1156
+ }
1157
+
1158
+ // Handle errors
1159
+ process.on('unhandledRejection', (error) => {
1160
+ log.error(`Unhandled error: ${error.message}`);
1161
+ process.exit(1);
1162
+ });
1163
+
1164
+ // Run main
1165
+ main().catch((error) => {
1166
+ log.error(`Fatal error: ${error.message}`);
1167
+ process.exit(1);
1168
+ });