claude-brain 0.5.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/VERSION +1 -1
  2. package/assets/CLAUDE-unified.md +11 -0
  3. package/package.json +2 -1
  4. package/packs/backend/node.json +173 -0
  5. package/packs/core/javascript.json +176 -0
  6. package/packs/core/typescript.json +222 -0
  7. package/packs/frontend/react.json +254 -0
  8. package/packs/meta/testing.json +172 -0
  9. package/src/cli/bin.ts +14 -0
  10. package/src/cli/commands/chroma.ts +53 -17
  11. package/src/cli/commands/hooks.ts +214 -0
  12. package/src/cli/commands/pack.ts +197 -0
  13. package/src/cli/commands/serve.ts +34 -0
  14. package/src/config/defaults.ts +1 -1
  15. package/src/config/schema.ts +85 -2
  16. package/src/hooks/brain-hook.ts +110 -0
  17. package/src/hooks/capture.ts +161 -0
  18. package/src/hooks/deduplicator.ts +72 -0
  19. package/src/hooks/index.ts +19 -0
  20. package/src/hooks/installer.ts +181 -0
  21. package/src/hooks/passive-classifier.ts +366 -0
  22. package/src/hooks/queue.ts +122 -0
  23. package/src/hooks/session-tracker.ts +199 -0
  24. package/src/hooks/types.ts +47 -0
  25. package/src/memory/chroma/client.ts +1 -1
  26. package/src/memory/chroma/index.ts +1 -1
  27. package/src/memory/chroma/store.ts +29 -9
  28. package/src/memory/index.ts +1 -0
  29. package/src/memory/store.ts +1 -0
  30. package/src/packs/index.ts +9 -0
  31. package/src/packs/loader.ts +134 -0
  32. package/src/packs/manager.ts +204 -0
  33. package/src/packs/ranker.ts +78 -0
  34. package/src/packs/types.ts +81 -0
  35. package/src/routing/entity-extractor.ts +410 -0
  36. package/src/routing/intent-classifier.ts +229 -0
  37. package/src/routing/response-filter.ts +221 -0
  38. package/src/routing/router.ts +671 -0
  39. package/src/server/handlers/call-tool.ts +7 -0
  40. package/src/server/handlers/list-tools.ts +22 -5
  41. package/src/server/handlers/tools/brain.ts +85 -0
  42. package/src/server/handlers/tools/init-project.ts +47 -0
  43. package/src/server/handlers/tools/schemas.ts +12 -0
  44. package/src/server/http-api.ts +188 -0
  45. package/src/tools/registry.ts +9 -0
  46. package/src/tools/schemas.ts +33 -1
@@ -0,0 +1,254 @@
1
+ {
2
+ "id": "frontend/react",
3
+ "name": "React Patterns & Pitfalls",
4
+ "version": "1.0.0",
5
+ "stack": ["react", "next.js", "remix", "gatsby"],
6
+ "description": "Hooks pitfalls, state management decisions, performance optimization, and component patterns",
7
+ "author": "claude-brain",
8
+ "entries": [
9
+ {
10
+ "type": "common-issue",
11
+ "category": "Hooks",
12
+ "title": "Avoid infinite loops with useEffect dependencies",
13
+ "content": "Objects, arrays, and functions created during render are new references each time. Including them in useEffect deps causes infinite re-renders. Use useMemo/useCallback to stabilize references, or restructure to use primitive deps.",
14
+ "confidence": 0.95,
15
+ "tags": ["react", "hooks", "useEffect", "performance"]
16
+ },
17
+ {
18
+ "type": "anti-pattern",
19
+ "category": "Hooks",
20
+ "title": "Don't use useEffect for derived state",
21
+ "content": "Don't use useEffect to sync state derived from other state or props. Calculate it during render instead. useEffect for derived state adds unnecessary re-renders and complexity.",
22
+ "confidence": 0.95,
23
+ "tags": ["react", "hooks", "useEffect", "state"],
24
+ "example": "// Bad: useEffect(() => setFullName(first + last), [first, last])\n// Good: const fullName = first + ' ' + last"
25
+ },
26
+ {
27
+ "type": "best-practice",
28
+ "category": "State Management",
29
+ "title": "Lift state up only as far as needed",
30
+ "content": "Keep state as close to where it's used as possible. Only lift state to a common parent when multiple siblings need it. Over-lifting state to the top causes unnecessary re-renders.",
31
+ "confidence": 0.9,
32
+ "tags": ["react", "state", "architecture"]
33
+ },
34
+ {
35
+ "type": "pattern",
36
+ "category": "State Management",
37
+ "title": "Use useReducer for complex state logic",
38
+ "content": "When state updates depend on previous state or involve multiple related values, useReducer provides clearer intent and easier testing than multiple useState calls.",
39
+ "confidence": 0.85,
40
+ "tags": ["react", "hooks", "useReducer", "state"]
41
+ },
42
+ {
43
+ "type": "common-issue",
44
+ "category": "Hooks",
45
+ "title": "Stale closures in event handlers and effects",
46
+ "content": "Event handlers and effects capture the state/props from the render they were created in. Use refs for values that need to be always-current in callbacks, or ensure proper dependency arrays.",
47
+ "confidence": 0.9,
48
+ "tags": ["react", "hooks", "closures", "stale-state"]
49
+ },
50
+ {
51
+ "type": "best-practice",
52
+ "category": "Performance",
53
+ "title": "Use React.memo sparingly and with profiling",
54
+ "content": "React.memo prevents re-renders when props haven't changed, but adds comparison overhead. Only use it when profiling shows a component re-renders frequently with the same props.",
55
+ "confidence": 0.9,
56
+ "tags": ["react", "performance", "memo"]
57
+ },
58
+ {
59
+ "type": "best-practice",
60
+ "category": "Performance",
61
+ "title": "Use key prop correctly for list rendering",
62
+ "content": "Always use stable, unique keys for list items. Never use array index as key if the list can be reordered, filtered, or items inserted. Bad keys cause incorrect DOM reuse and state bugs.",
63
+ "confidence": 0.95,
64
+ "tags": ["react", "performance", "keys", "lists"]
65
+ },
66
+ {
67
+ "type": "pattern",
68
+ "category": "Components",
69
+ "title": "Composition over prop drilling",
70
+ "content": "Use component composition (children, render props, compound components) to avoid passing props through multiple intermediate layers. This keeps components focused and reduces coupling.",
71
+ "confidence": 0.9,
72
+ "tags": ["react", "composition", "patterns"]
73
+ },
74
+ {
75
+ "type": "anti-pattern",
76
+ "category": "Components",
77
+ "title": "Avoid defining components inside other components",
78
+ "content": "Never define a component inside another component's render. This creates a new component type each render, causing full unmount/remount and losing all state. Define components at module scope.",
79
+ "confidence": 0.95,
80
+ "tags": ["react", "components", "performance"]
81
+ },
82
+ {
83
+ "type": "best-practice",
84
+ "category": "Hooks",
85
+ "title": "Extract custom hooks for reusable logic",
86
+ "content": "Extract shared stateful logic into custom hooks (useXyz). Custom hooks compose well, are independently testable, and keep components focused on rendering.",
87
+ "confidence": 0.9,
88
+ "tags": ["react", "hooks", "custom-hooks", "reuse"]
89
+ },
90
+ {
91
+ "type": "common-issue",
92
+ "category": "Hooks",
93
+ "title": "Follow the Rules of Hooks",
94
+ "content": "Hooks must be called at the top level (not inside conditions, loops, or nested functions) and only from React function components or custom hooks. Violating this causes incorrect hook state association.",
95
+ "confidence": 0.95,
96
+ "tags": ["react", "hooks", "rules"]
97
+ },
98
+ {
99
+ "type": "pattern",
100
+ "category": "Data Fetching",
101
+ "title": "Use a data fetching library over raw useEffect",
102
+ "content": "Use React Query (TanStack Query), SWR, or your framework's data fetching solution instead of raw useEffect + fetch. These handle caching, deduplication, race conditions, and background refetching.",
103
+ "confidence": 0.9,
104
+ "tags": ["react", "data-fetching", "react-query", "swr"]
105
+ },
106
+ {
107
+ "type": "anti-pattern",
108
+ "category": "State Management",
109
+ "title": "Avoid mirroring props in state",
110
+ "content": "Don't copy props into state with useState. The state won't update when props change unless you add a useEffect to sync them. Use props directly, or derive values during render.",
111
+ "confidence": 0.9,
112
+ "tags": ["react", "state", "props", "anti-pattern"]
113
+ },
114
+ {
115
+ "type": "best-practice",
116
+ "category": "Performance",
117
+ "title": "Lazy load routes and heavy components",
118
+ "content": "Use React.lazy() and Suspense for code splitting. Lazy load routes and heavy components (charts, editors, modals) to reduce initial bundle size and improve time-to-interactive.",
119
+ "confidence": 0.9,
120
+ "tags": ["react", "performance", "lazy-loading", "code-splitting"]
121
+ },
122
+ {
123
+ "type": "pattern",
124
+ "category": "Error Handling",
125
+ "title": "Use Error Boundaries for resilient UI",
126
+ "content": "Wrap sections of your UI with Error Boundaries to catch rendering errors and show fallback UI instead of crashing the entire app. Place boundaries at route level and around risky components.",
127
+ "confidence": 0.9,
128
+ "tags": ["react", "error-handling", "error-boundary"]
129
+ },
130
+ {
131
+ "type": "best-practice",
132
+ "category": "Hooks",
133
+ "title": "Use useCallback for stable event handlers",
134
+ "content": "Wrap event handler functions in useCallback when passing them to memoized children or using them in effect dependency arrays. This prevents unnecessary re-renders of child components.",
135
+ "confidence": 0.85,
136
+ "tags": ["react", "hooks", "useCallback", "performance"]
137
+ },
138
+ {
139
+ "type": "common-issue",
140
+ "category": "State Management",
141
+ "title": "Batching state updates",
142
+ "content": "React 18+ automatically batches state updates in event handlers, timeouts, promises, and native events. Multiple setState calls in one function only trigger one re-render.",
143
+ "confidence": 0.85,
144
+ "tags": ["react", "state", "batching", "react-18"]
145
+ },
146
+ {
147
+ "type": "anti-pattern",
148
+ "category": "State Management",
149
+ "title": "Avoid excessive global state",
150
+ "content": "Don't put everything in global state (Redux/Context). Server data belongs in a cache layer (React Query). UI state should be local. Only truly global state (auth, theme) needs a global store.",
151
+ "confidence": 0.9,
152
+ "tags": ["react", "state", "redux", "context"]
153
+ },
154
+ {
155
+ "type": "best-practice",
156
+ "category": "Components",
157
+ "title": "Keep components small and focused",
158
+ "content": "Each component should do one thing well. If a component file exceeds 200 lines, it likely handles too many concerns. Extract sub-components, custom hooks, or utility functions.",
159
+ "confidence": 0.85,
160
+ "tags": ["react", "components", "architecture"]
161
+ },
162
+ {
163
+ "type": "pattern",
164
+ "category": "Forms",
165
+ "title": "Use controlled components for forms",
166
+ "content": "Prefer controlled components (state-driven) for forms. Use a form library (React Hook Form, Formik) for complex forms with validation, arrays, and dynamic fields.",
167
+ "confidence": 0.85,
168
+ "tags": ["react", "forms", "controlled-components"]
169
+ },
170
+ {
171
+ "type": "best-practice",
172
+ "category": "Accessibility",
173
+ "title": "Use semantic HTML and ARIA attributes",
174
+ "content": "Use semantic HTML elements (button, nav, main, article) over generic divs. Add ARIA labels for interactive elements. Ensure keyboard navigation works for all interactive components.",
175
+ "confidence": 0.9,
176
+ "tags": ["react", "accessibility", "a11y", "html"]
177
+ },
178
+ {
179
+ "type": "common-issue",
180
+ "category": "Hooks",
181
+ "title": "Clean up effects to prevent memory leaks",
182
+ "content": "Always return a cleanup function from useEffect when subscribing to events, setting up intervals, or creating observers. Forgetting cleanup causes memory leaks and stale callbacks.",
183
+ "confidence": 0.9,
184
+ "tags": ["react", "hooks", "useEffect", "cleanup"],
185
+ "example": "useEffect(() => { const id = setInterval(fn, 1000); return () => clearInterval(id); }, [])"
186
+ },
187
+ {
188
+ "type": "pattern",
189
+ "category": "Performance",
190
+ "title": "Virtualize long lists",
191
+ "content": "For lists with hundreds or thousands of items, use virtualization (react-window, react-virtuoso, TanStack Virtual) to render only visible items. This dramatically improves scroll performance.",
192
+ "confidence": 0.9,
193
+ "tags": ["react", "performance", "virtualization", "lists"]
194
+ },
195
+ {
196
+ "type": "best-practice",
197
+ "category": "State Management",
198
+ "title": "Use server state libraries for API data",
199
+ "content": "Treat server data as a cache, not as state. Libraries like TanStack Query manage caching, invalidation, background updates, and optimistic updates. This removes most useState/useEffect for data fetching.",
200
+ "confidence": 0.9,
201
+ "tags": ["react", "state", "server-state", "caching"]
202
+ },
203
+ {
204
+ "type": "anti-pattern",
205
+ "category": "Hooks",
206
+ "title": "Avoid useEffect as an event handler",
207
+ "content": "Don't use useEffect to respond to user events (clicks, form submissions). Handle events directly in event handlers. useEffect is for synchronizing with external systems, not for responding to events.",
208
+ "confidence": 0.9,
209
+ "tags": ["react", "hooks", "useEffect", "events"]
210
+ },
211
+ {
212
+ "type": "pattern",
213
+ "category": "Components",
214
+ "title": "Use compound components for flexible APIs",
215
+ "content": "For complex UI components (tabs, dropdowns, accordions), use the compound component pattern with React Context. This gives consumers flexible control over rendering while keeping logic encapsulated.",
216
+ "confidence": 0.85,
217
+ "tags": ["react", "components", "compound-components", "patterns"],
218
+ "example": "<Tabs>\n <Tabs.List>\n <Tabs.Tab>One</Tabs.Tab>\n </Tabs.List>\n <Tabs.Panel>Content</Tabs.Panel>\n</Tabs>"
219
+ },
220
+ {
221
+ "type": "best-practice",
222
+ "category": "TypeScript",
223
+ "title": "Type component props with interfaces",
224
+ "content": "Define component props as interfaces or types. Use React.FC sparingly (it adds implicit children). Prefer explicit prop typing with destructuring in the function signature.",
225
+ "confidence": 0.85,
226
+ "tags": ["react", "typescript", "props", "typing"],
227
+ "example": "interface ButtonProps { label: string; onClick: () => void }\nfunction Button({ label, onClick }: ButtonProps) { ... }"
228
+ },
229
+ {
230
+ "type": "common-issue",
231
+ "category": "Performance",
232
+ "title": "Avoid creating new objects in JSX props",
233
+ "content": "Inline objects and arrays in JSX (`style={{ color: 'red' }}`, `data={[1,2,3]}`) create new references each render. Move static values outside the component or use useMemo for dynamic ones.",
234
+ "confidence": 0.85,
235
+ "tags": ["react", "performance", "rendering"]
236
+ },
237
+ {
238
+ "type": "best-practice",
239
+ "category": "Testing",
240
+ "title": "Test behavior, not implementation",
241
+ "content": "Test what the user sees and interacts with, not component internals. Use React Testing Library to query by role, text, and labels. Avoid testing state values or implementation details directly.",
242
+ "confidence": 0.9,
243
+ "tags": ["react", "testing", "react-testing-library"]
244
+ },
245
+ {
246
+ "type": "pattern",
247
+ "category": "Hooks",
248
+ "title": "Use useId for accessibility IDs",
249
+ "content": "Use React.useId() to generate stable, unique IDs for accessibility attributes (htmlFor, aria-describedby). This works correctly with server-side rendering unlike random ID generation.",
250
+ "confidence": 0.8,
251
+ "tags": ["react", "hooks", "accessibility", "ssr"]
252
+ }
253
+ ]
254
+ }
@@ -0,0 +1,172 @@
1
+ {
2
+ "id": "meta/testing",
3
+ "name": "Testing Best Practices",
4
+ "version": "1.0.0",
5
+ "stack": ["jest", "vitest", "mocha", "bun:test", "testing"],
6
+ "description": "Test pyramid, mocking strategies, anti-patterns, arrange-act-assert, and testing philosophy",
7
+ "author": "claude-brain",
8
+ "entries": [
9
+ {
10
+ "type": "best-practice",
11
+ "category": "Test Structure",
12
+ "title": "Follow Arrange-Act-Assert pattern",
13
+ "content": "Structure every test in three clear phases: Arrange (set up data and dependencies), Act (call the code under test), Assert (verify the result). This makes tests readable and consistent.",
14
+ "confidence": 0.95,
15
+ "tags": ["testing", "aaa", "structure"]
16
+ },
17
+ {
18
+ "type": "best-practice",
19
+ "category": "Test Strategy",
20
+ "title": "Follow the testing pyramid",
21
+ "content": "Write many fast unit tests, fewer integration tests, and minimal E2E tests. Unit tests catch logic bugs cheaply. Integration tests verify component interaction. E2E tests validate critical user journeys.",
22
+ "confidence": 0.95,
23
+ "tags": ["testing", "pyramid", "strategy"]
24
+ },
25
+ {
26
+ "type": "anti-pattern",
27
+ "category": "Test Design",
28
+ "title": "Avoid testing implementation details",
29
+ "content": "Test behavior and outcomes, not internal implementation. Tests that verify private methods, internal state, or specific function calls break when refactoring even if behavior is unchanged.",
30
+ "confidence": 0.95,
31
+ "tags": ["testing", "behavior", "anti-pattern"]
32
+ },
33
+ {
34
+ "type": "best-practice",
35
+ "category": "Test Design",
36
+ "title": "Each test should test one thing",
37
+ "content": "Keep tests focused on a single behavior or scenario. Multiple assertions are fine if they verify aspects of the same behavior. Avoid testing multiple unrelated behaviors in one test.",
38
+ "confidence": 0.9,
39
+ "tags": ["testing", "single-responsibility", "design"]
40
+ },
41
+ {
42
+ "type": "common-issue",
43
+ "category": "Mocking",
44
+ "title": "Don't over-mock",
45
+ "content": "Only mock external dependencies (APIs, databases, file system). Don't mock the code under test or internal modules. Over-mocking makes tests pass even when the real code is broken.",
46
+ "confidence": 0.9,
47
+ "tags": ["testing", "mocking", "integration"]
48
+ },
49
+ {
50
+ "type": "pattern",
51
+ "category": "Mocking",
52
+ "title": "Use dependency injection for mockable code",
53
+ "content": "Pass dependencies as parameters instead of importing them directly. This makes functions testable without module-level mocking, which is fragile and order-dependent.",
54
+ "confidence": 0.9,
55
+ "tags": ["testing", "mocking", "dependency-injection"]
56
+ },
57
+ {
58
+ "type": "best-practice",
59
+ "category": "Test Design",
60
+ "title": "Write descriptive test names",
61
+ "content": "Test names should describe the scenario and expected outcome: 'should return 404 when user does not exist' is better than 'test getUser'. Good names serve as documentation.",
62
+ "confidence": 0.9,
63
+ "tags": ["testing", "naming", "documentation"]
64
+ },
65
+ {
66
+ "type": "anti-pattern",
67
+ "category": "Test Design",
68
+ "title": "Avoid test interdependence",
69
+ "content": "Each test must be independent and able to run in isolation. Never rely on test execution order or shared mutable state between tests. Use beforeEach to reset state.",
70
+ "confidence": 0.95,
71
+ "tags": ["testing", "isolation", "anti-pattern"]
72
+ },
73
+ {
74
+ "type": "common-issue",
75
+ "category": "Async Testing",
76
+ "title": "Always await async assertions",
77
+ "content": "Forgetting to await async operations in tests causes false positives — the test passes before assertions run. Always return or await promises, and use the test framework's async utilities.",
78
+ "confidence": 0.9,
79
+ "tags": ["testing", "async", "promises"]
80
+ },
81
+ {
82
+ "type": "pattern",
83
+ "category": "Test Data",
84
+ "title": "Use factories for test data",
85
+ "content": "Create factory functions that generate test data with sensible defaults and overrides. This reduces boilerplate, keeps tests focused on what's relevant, and makes it easy to create variations.",
86
+ "confidence": 0.85,
87
+ "tags": ["testing", "data", "factories"],
88
+ "example": "function createUser(overrides = {}) { return { name: 'Test', email: 'test@test.com', ...overrides } }"
89
+ },
90
+ {
91
+ "type": "best-practice",
92
+ "category": "Test Maintenance",
93
+ "title": "Keep tests fast",
94
+ "content": "Fast tests get run often. Avoid real network calls, file I/O, and sleeps in unit tests. Use in-memory alternatives and mock external services. A slow test suite leads to developers skipping tests.",
95
+ "confidence": 0.9,
96
+ "tags": ["testing", "performance", "speed"]
97
+ },
98
+ {
99
+ "type": "anti-pattern",
100
+ "category": "Test Design",
101
+ "title": "Avoid snapshot overuse",
102
+ "content": "Snapshot tests are easy to write but hard to maintain. Large snapshots are never reviewed when updated. Use snapshots sparingly for stable output (serialized data, error messages), not for entire component trees.",
103
+ "confidence": 0.85,
104
+ "tags": ["testing", "snapshots", "anti-pattern"]
105
+ },
106
+ {
107
+ "type": "pattern",
108
+ "category": "Error Testing",
109
+ "title": "Test error cases and edge cases",
110
+ "content": "Don't only test the happy path. Test invalid input, empty data, null values, boundary conditions, and error responses. Error handling code has bugs too — verify it works correctly.",
111
+ "confidence": 0.9,
112
+ "tags": ["testing", "error-cases", "edge-cases"]
113
+ },
114
+ {
115
+ "type": "best-practice",
116
+ "category": "Test Strategy",
117
+ "title": "Use integration tests for API endpoints",
118
+ "content": "Test API endpoints with real HTTP requests against the actual server (with mocked external services). This verifies routing, middleware, validation, and response formatting together.",
119
+ "confidence": 0.85,
120
+ "tags": ["testing", "integration", "api"]
121
+ },
122
+ {
123
+ "type": "common-issue",
124
+ "category": "Mocking",
125
+ "title": "Reset mocks between tests",
126
+ "content": "Always clear mock state between tests using beforeEach, afterEach, or the framework's auto-clear feature. Leftover mock state from previous tests causes intermittent failures.",
127
+ "confidence": 0.9,
128
+ "tags": ["testing", "mocking", "cleanup"]
129
+ },
130
+ {
131
+ "type": "anti-pattern",
132
+ "category": "Test Design",
133
+ "title": "Avoid conditional logic in tests",
134
+ "content": "Tests should not contain if/else, loops, or try/catch. Each test should follow a straight-line path. If you need different scenarios, write separate tests for each.",
135
+ "confidence": 0.9,
136
+ "tags": ["testing", "simplicity", "anti-pattern"]
137
+ },
138
+ {
139
+ "type": "best-practice",
140
+ "category": "Coverage",
141
+ "title": "Use coverage as a guide, not a goal",
142
+ "content": "Code coverage measures lines executed, not quality of assertions. 100% coverage with weak assertions is worse than 80% coverage with thorough behavior tests. Focus on testing critical paths well.",
143
+ "confidence": 0.9,
144
+ "tags": ["testing", "coverage", "quality"]
145
+ },
146
+ {
147
+ "type": "pattern",
148
+ "category": "Test Organization",
149
+ "title": "Group tests by behavior with describe blocks",
150
+ "content": "Use nested describe blocks to group related tests: by function/method, then by scenario. This creates readable test output and makes it easy to find and run specific test groups.",
151
+ "confidence": 0.85,
152
+ "tags": ["testing", "organization", "describe"],
153
+ "example": "describe('UserService', () => {\n describe('createUser', () => {\n it('should create with valid data', ...)\n it('should reject duplicate email', ...)\n })\n})"
154
+ },
155
+ {
156
+ "type": "best-practice",
157
+ "category": "Test Design",
158
+ "title": "Assert on the most specific thing",
159
+ "content": "Use the most specific assertion available. `toBe(3)` is better than `toBeGreaterThan(0)`. `toEqual({name: 'test'})` is better than `toBeTruthy()`. Specific assertions catch bugs that general ones miss.",
160
+ "confidence": 0.85,
161
+ "tags": ["testing", "assertions", "specificity"]
162
+ },
163
+ {
164
+ "type": "common-issue",
165
+ "category": "Flaky Tests",
166
+ "title": "Eliminate time-dependent tests",
167
+ "content": "Tests that depend on wall clock time, setTimeout delays, or Date.now() are inherently flaky. Use fake timers (jest.useFakeTimers, vi.useFakeTimers) to control time in tests.",
168
+ "confidence": 0.9,
169
+ "tags": ["testing", "flaky", "timers"]
170
+ }
171
+ ]
172
+ }
package/src/cli/bin.ts CHANGED
@@ -33,6 +33,8 @@ function printHelp() {
33
33
  ['uninstall', 'Remove MCP server from Claude Code'],
34
34
  ['update', 'Update package and refresh CLAUDE.md'],
35
35
  ['chroma', 'Manage ChromaDB server (start/stop/status)'],
36
+ ['hooks', 'Manage passive learning hooks (install/uninstall/status)'],
37
+ ['pack', 'Manage knowledge packs (list/status/reload)'],
36
38
  ['health', 'Run health checks'],
37
39
  ['diagnose', 'Run diagnostics'],
38
40
  ['version', 'Show version'],
@@ -116,6 +118,18 @@ async function main() {
116
118
  break
117
119
  }
118
120
 
121
+ case 'hooks': {
122
+ const { runHooks } = await import('./commands/hooks')
123
+ await runHooks()
124
+ break
125
+ }
126
+
127
+ case 'pack': {
128
+ const { runPack } = await import('./commands/pack')
129
+ await runPack()
130
+ break
131
+ }
132
+
119
133
  case 'health': {
120
134
  const { runHealthCheck } = await import('@/health')
121
135
  await runHealthCheck()
@@ -29,25 +29,53 @@ function getChromaDataPath(): string {
29
29
  * Find the chroma binary - checks PATH first, then common pip install locations
30
30
  */
31
31
  function findChromaBinary(): string | null {
32
+ const isWindows = process.platform === 'win32'
33
+ const chromaName = isWindows ? 'chroma.exe' : 'chroma'
34
+
32
35
  // Try bare 'chroma' first (on PATH)
33
36
  try {
34
37
  execSync('chroma --version', { stdio: 'pipe', timeout: 5000 })
35
38
  return 'chroma'
36
39
  } catch {}
37
40
 
38
- // Search common pip install locations
39
41
  const { homedir } = require('os')
40
42
  const home = homedir()
41
- const candidates = [
42
- join(home, 'Library', 'Python', '3.9', 'bin', 'chroma'),
43
- join(home, 'Library', 'Python', '3.10', 'bin', 'chroma'),
44
- join(home, 'Library', 'Python', '3.11', 'bin', 'chroma'),
45
- join(home, 'Library', 'Python', '3.12', 'bin', 'chroma'),
46
- join(home, 'Library', 'Python', '3.13', 'bin', 'chroma'),
47
- join(home, '.local', 'bin', 'chroma'),
48
- '/usr/local/bin/chroma',
49
- '/opt/homebrew/bin/chroma',
50
- ]
43
+
44
+ // Platform-specific search paths
45
+ const candidates: string[] = isWindows
46
+ ? [
47
+ // Windows pip install locations
48
+ join(home, 'AppData', 'Local', 'Programs', 'Python', 'Python39', 'Scripts', chromaName),
49
+ join(home, 'AppData', 'Local', 'Programs', 'Python', 'Python310', 'Scripts', chromaName),
50
+ join(home, 'AppData', 'Local', 'Programs', 'Python', 'Python311', 'Scripts', chromaName),
51
+ join(home, 'AppData', 'Local', 'Programs', 'Python', 'Python312', 'Scripts', chromaName),
52
+ join(home, 'AppData', 'Local', 'Programs', 'Python', 'Python313', 'Scripts', chromaName),
53
+ // Windows user pip install (pip install --user)
54
+ join(home, 'AppData', 'Roaming', 'Python', 'Python39', 'Scripts', chromaName),
55
+ join(home, 'AppData', 'Roaming', 'Python', 'Python310', 'Scripts', chromaName),
56
+ join(home, 'AppData', 'Roaming', 'Python', 'Python311', 'Scripts', chromaName),
57
+ join(home, 'AppData', 'Roaming', 'Python', 'Python312', 'Scripts', chromaName),
58
+ join(home, 'AppData', 'Roaming', 'Python', 'Python313', 'Scripts', chromaName),
59
+ // Scoop / Chocolatey / winget
60
+ join(home, 'scoop', 'shims', chromaName),
61
+ 'C:\\Python39\\Scripts\\' + chromaName,
62
+ 'C:\\Python310\\Scripts\\' + chromaName,
63
+ 'C:\\Python311\\Scripts\\' + chromaName,
64
+ 'C:\\Python312\\Scripts\\' + chromaName,
65
+ 'C:\\Python313\\Scripts\\' + chromaName,
66
+ ]
67
+ : [
68
+ // macOS pip install locations
69
+ join(home, 'Library', 'Python', '3.9', 'bin', chromaName),
70
+ join(home, 'Library', 'Python', '3.10', 'bin', chromaName),
71
+ join(home, 'Library', 'Python', '3.11', 'bin', chromaName),
72
+ join(home, 'Library', 'Python', '3.12', 'bin', chromaName),
73
+ join(home, 'Library', 'Python', '3.13', 'bin', chromaName),
74
+ // Linux pip install locations
75
+ join(home, '.local', 'bin', chromaName),
76
+ '/usr/local/bin/' + chromaName,
77
+ '/opt/homebrew/bin/' + chromaName,
78
+ ]
51
79
 
52
80
  for (const candidate of candidates) {
53
81
  try {
@@ -58,15 +86,23 @@ function findChromaBinary(): string | null {
58
86
  } catch {}
59
87
  }
60
88
 
61
- // Try finding via python -m site
89
+ // Try finding via python -m site (works on all platforms)
90
+ const pythonCmd = isWindows ? 'python' : 'python3'
62
91
  try {
63
- const sitePackages = execSync('python3 -c "import site; print(site.getusersitepackages())"', {
92
+ const sitePackages = execSync(`${pythonCmd} -c "import site; print(site.getusersitepackages())"`, {
64
93
  encoding: 'utf-8', stdio: 'pipe', timeout: 5000
65
94
  }).trim()
66
- // User site-packages is like /Users/x/Library/Python/3.9/lib/python/site-packages
67
- // The bin is at the same level as lib
68
- const binDir = sitePackages.replace(/\/lib\/.*/, '/bin')
69
- const chromaPath = join(binDir, 'chroma')
95
+
96
+ let binDir: string
97
+ if (isWindows) {
98
+ // Windows: C:\Users\x\AppData\Roaming\Python\Python311\site-packages Scripts
99
+ binDir = sitePackages.replace(/[\\\/]site-packages$/, '\\Scripts')
100
+ } else {
101
+ // Unix: /Users/x/Library/Python/3.9/lib/python/site-packages → bin
102
+ binDir = sitePackages.replace(/\/lib\/.*/, '/bin')
103
+ }
104
+
105
+ const chromaPath = join(binDir, chromaName)
70
106
  if (existsSync(chromaPath)) {
71
107
  execSync(`"${chromaPath}" --version`, { stdio: 'pipe', timeout: 5000 })
72
108
  return chromaPath