claude-brain 0.9.3 → 0.13.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 (66) hide show
  1. package/VERSION +1 -1
  2. package/assets/CLAUDE.md +9 -1
  3. package/package.json +1 -1
  4. package/src/automation/phase12-manager.ts +456 -0
  5. package/src/automation/project-detector.ts +13 -0
  6. package/src/automation/repo-scanner.ts +205 -0
  7. package/src/cli/bin.ts +30 -0
  8. package/src/cli/commands/git-hook.ts +189 -0
  9. package/src/cli/commands/hooks.ts +8 -9
  10. package/src/cli/commands/init.ts +98 -0
  11. package/src/cli/commands/serve.ts +7 -20
  12. package/src/cli/commands/update.ts +3 -3
  13. package/src/config/defaults.ts +4 -1
  14. package/src/config/schema.ts +27 -7
  15. package/src/hooks/brain-hook.ts +8 -6
  16. package/src/hooks/capture.ts +9 -2
  17. package/src/hooks/git-capture.ts +94 -0
  18. package/src/hooks/git-hook-installer.ts +197 -0
  19. package/src/hooks/index.ts +1 -0
  20. package/src/hooks/session-tracker.ts +79 -3
  21. package/src/hooks/types.ts +1 -1
  22. package/src/intelligence/index.ts +24 -0
  23. package/src/knowledge/graph/builder.ts +26 -0
  24. package/src/memory/chroma/store.ts +18 -2
  25. package/src/memory/episodic/manager.ts +17 -0
  26. package/src/memory/index.ts +48 -18
  27. package/src/phase12/index.ts +3 -454
  28. package/src/routing/intent-classifier.ts +107 -9
  29. package/src/routing/response-filter.ts +50 -17
  30. package/src/routing/router.ts +472 -224
  31. package/src/routing/search-engine.ts +464 -0
  32. package/src/routing/types.ts +84 -0
  33. package/src/server/handlers/call-tool.ts +4 -49
  34. package/src/server/handlers/tools/analyze-decision-evolution.ts +1 -1
  35. package/src/server/handlers/tools/detect-trends.ts +1 -1
  36. package/src/server/handlers/tools/find-cross-project-patterns.ts +1 -1
  37. package/src/server/handlers/tools/get-decision-timeline.ts +2 -2
  38. package/src/server/handlers/tools/get-recommendations.ts +1 -1
  39. package/src/server/handlers/tools/index.ts +5 -7
  40. package/src/server/handlers/tools/what-if-analysis.ts +1 -1
  41. package/src/server/providers/resources.ts +195 -0
  42. package/src/server/services.ts +81 -6
  43. package/src/tools/schemas.ts +7 -329
  44. package/src/utils/phase12-helper.ts +2 -2
  45. package/src/utils/timing.ts +47 -0
  46. package/src/vault/writer.ts +22 -2
  47. /package/src/{cross-project → intelligence/cross-project}/affinity.ts +0 -0
  48. /package/src/{cross-project → intelligence/cross-project}/generalizer.ts +0 -0
  49. /package/src/{cross-project → intelligence/cross-project}/index.ts +0 -0
  50. /package/src/{cross-project → intelligence/cross-project}/transfer.ts +0 -0
  51. /package/src/{optimization → intelligence/optimization}/index.ts +0 -0
  52. /package/src/{optimization → intelligence/optimization}/precompute.ts +0 -0
  53. /package/src/{optimization → intelligence/optimization}/semantic-cache.ts +0 -0
  54. /package/src/{prediction → intelligence/prediction}/context-anticipator.ts +0 -0
  55. /package/src/{prediction → intelligence/prediction}/decision-predictor.ts +0 -0
  56. /package/src/{prediction → intelligence/prediction}/index.ts +0 -0
  57. /package/src/{prediction → intelligence/prediction}/recommender.ts +0 -0
  58. /package/src/{reasoning → intelligence/reasoning}/chain-retrieval.ts +0 -0
  59. /package/src/{reasoning → intelligence/reasoning}/counterfactual.ts +0 -0
  60. /package/src/{reasoning → intelligence/reasoning}/index.ts +0 -0
  61. /package/src/{reasoning → intelligence/reasoning}/synthesizer.ts +0 -0
  62. /package/src/{temporal → intelligence/temporal}/evolution.ts +0 -0
  63. /package/src/{temporal → intelligence/temporal}/index.ts +0 -0
  64. /package/src/{temporal → intelligence/temporal}/query-processor.ts +0 -0
  65. /package/src/{temporal → intelligence/temporal}/timeline.ts +0 -0
  66. /package/src/{temporal → intelligence/temporal}/trends.ts +0 -0
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * Brain Response Filter
3
- * Phase 16: Filters noise, deduplicates, ranks, and synthesizes results
4
- * from the unified brain() tool
3
+ * Phase 16 + Phase 19: Filters noise, deduplicates, ranks, and synthesizes results
4
+ *
5
+ * Phase 19 changes:
6
+ * - D2: Lower word overlap threshold 0.85 → 0.75, add ID-based and prefix-based dedup
7
+ * - D3: Split INFRA_NOISE into strong (1 hit = filter) and weak (2+ hits = filter)
5
8
  */
6
9
 
7
10
  export interface FilterableResult {
@@ -32,13 +35,19 @@ export interface TierResults {
32
35
  }
33
36
 
34
37
  export class ResponseFilter {
35
- // Infrastructure noise terms strip from non-claude-brain projects
36
- private readonly INFRA_NOISE = [
38
+ // D3: Strong noise — 1 hit is enough to filter (very specific internal terms)
39
+ private readonly STRONG_NOISE = [
40
+ 'mcp-server', 'model-context-protocol', 'embedding-service', 'vector-database',
41
+ 'mcp tool', 'tool handler', 'precompute engine', 'knowledge graph builder',
42
+ 'semantic cache', 'bun:test'
43
+ ]
44
+
45
+ // D3: Weak noise — need 2+ hits to filter (terms that could appear in legitimate decisions)
46
+ private readonly WEAK_NOISE = [
37
47
  'chromadb', 'chroma', 'minisearch', 'compromise', 'better-sqlite3',
38
- 'pino', 'hono', 'bun:test', 'zod', 'mcp-server', 'claude-brain',
39
- 'model-context-protocol', 'embedding-service', 'vector-database',
40
- 'mcp tool', 'tool handler', 'phase 12', 'phase 13', 'phase 14', 'phase 15',
41
- 'semantic cache', 'precompute engine', 'knowledge graph builder'
48
+ 'pino', 'hono', 'zod', 'claude-brain',
49
+ 'phase 12', 'phase 13', 'phase 14', 'phase 15', 'phase 16',
50
+ 'phase 17', 'phase 18', 'phase 19'
42
51
  ]
43
52
 
44
53
  /**
@@ -52,7 +61,7 @@ export class ResponseFilter {
52
61
  filtered = filtered.filter(r => !this.isInfrastructureNoise(r.content))
53
62
  }
54
63
 
55
- // 2. Remove near-duplicates (>85% word overlap, keep higher score)
64
+ // 2. Remove near-duplicates (Phase 19 D2: improved dedup)
56
65
  filtered = this.deduplicateResults(filtered)
57
66
 
58
67
  // 3. Apply dynamic threshold (at least 70% of median similarity)
@@ -134,32 +143,56 @@ export class ResponseFilter {
134
143
  }
135
144
 
136
145
  /**
137
- * Check if content is infrastructure/internal noise
146
+ * D3: Check if content is infrastructure/internal noise
147
+ * Strong noise: 1 hit filters
148
+ * Weak noise: 2+ hits filters
138
149
  */
139
150
  private isInfrastructureNoise(content: string): boolean {
140
151
  const lower = content.toLowerCase()
141
- let noiseHits = 0
142
152
 
143
- for (const term of this.INFRA_NOISE) {
153
+ // Strong noise: a single hit is enough
154
+ for (const term of this.STRONG_NOISE) {
144
155
  if (lower.includes(term)) {
145
- noiseHits++
156
+ return true
146
157
  }
147
158
  }
148
159
 
149
- // If more than 2 infrastructure terms appear, it's likely noise
150
- return noiseHits >= 2
160
+ // Weak noise: need 2+ hits
161
+ let weakHits = 0
162
+ for (const term of this.WEAK_NOISE) {
163
+ if (lower.includes(term)) {
164
+ weakHits++
165
+ }
166
+ }
167
+ return weakHits >= 2
151
168
  }
152
169
 
153
170
  /**
154
- * Remove near-duplicate results (>85% word overlap)
171
+ * D2: Improved deduplication
172
+ * - ID-based dedup (if metadata has an ID)
173
+ * - Prefix-based dedup (first 100 chars match)
174
+ * - Word overlap dedup (lowered from 0.85 to 0.75)
155
175
  */
156
176
  private deduplicateResults(results: FilterableResult[]): FilterableResult[] {
157
177
  const kept: FilterableResult[] = []
178
+ const seenIds = new Set<string>()
179
+ const seenPrefixes = new Set<string>()
158
180
 
159
181
  for (const result of results) {
182
+ // ID-based dedup
183
+ const id = (result.metadata as any)?.id || (result.metadata as any)?.decision_id
184
+ if (id && seenIds.has(id)) continue
185
+ if (id) seenIds.add(id)
186
+
187
+ // Prefix-based dedup (first 100 chars, normalized)
188
+ const prefix = result.content.slice(0, 100).toLowerCase().replace(/\s+/g, ' ').trim()
189
+ if (prefix.length > 20 && seenPrefixes.has(prefix)) continue
190
+ if (prefix.length > 20) seenPrefixes.add(prefix)
191
+
192
+ // Word overlap dedup (D2: lowered to 0.75)
160
193
  const isDuplicate = kept.some(existing => {
161
194
  const overlap = this.calculateWordOverlap(existing.content, result.content)
162
- return overlap > 0.85
195
+ return overlap > 0.75
163
196
  })
164
197
 
165
198
  if (!isDuplicate) {