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.
- package/VERSION +1 -1
- package/assets/CLAUDE.md +9 -1
- package/package.json +1 -1
- package/src/automation/phase12-manager.ts +456 -0
- package/src/automation/project-detector.ts +13 -0
- package/src/automation/repo-scanner.ts +205 -0
- package/src/cli/bin.ts +30 -0
- package/src/cli/commands/git-hook.ts +189 -0
- package/src/cli/commands/hooks.ts +8 -9
- package/src/cli/commands/init.ts +98 -0
- package/src/cli/commands/serve.ts +7 -20
- package/src/cli/commands/update.ts +3 -3
- package/src/config/defaults.ts +4 -1
- package/src/config/schema.ts +27 -7
- package/src/hooks/brain-hook.ts +8 -6
- package/src/hooks/capture.ts +9 -2
- package/src/hooks/git-capture.ts +94 -0
- package/src/hooks/git-hook-installer.ts +197 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/session-tracker.ts +79 -3
- package/src/hooks/types.ts +1 -1
- package/src/intelligence/index.ts +24 -0
- package/src/knowledge/graph/builder.ts +26 -0
- package/src/memory/chroma/store.ts +18 -2
- package/src/memory/episodic/manager.ts +17 -0
- package/src/memory/index.ts +48 -18
- package/src/phase12/index.ts +3 -454
- package/src/routing/intent-classifier.ts +107 -9
- package/src/routing/response-filter.ts +50 -17
- package/src/routing/router.ts +472 -224
- package/src/routing/search-engine.ts +464 -0
- package/src/routing/types.ts +84 -0
- package/src/server/handlers/call-tool.ts +4 -49
- package/src/server/handlers/tools/analyze-decision-evolution.ts +1 -1
- package/src/server/handlers/tools/detect-trends.ts +1 -1
- package/src/server/handlers/tools/find-cross-project-patterns.ts +1 -1
- package/src/server/handlers/tools/get-decision-timeline.ts +2 -2
- package/src/server/handlers/tools/get-recommendations.ts +1 -1
- package/src/server/handlers/tools/index.ts +5 -7
- package/src/server/handlers/tools/what-if-analysis.ts +1 -1
- package/src/server/providers/resources.ts +195 -0
- package/src/server/services.ts +81 -6
- package/src/tools/schemas.ts +7 -329
- package/src/utils/phase12-helper.ts +2 -2
- package/src/utils/timing.ts +47 -0
- package/src/vault/writer.ts +22 -2
- /package/src/{cross-project → intelligence/cross-project}/affinity.ts +0 -0
- /package/src/{cross-project → intelligence/cross-project}/generalizer.ts +0 -0
- /package/src/{cross-project → intelligence/cross-project}/index.ts +0 -0
- /package/src/{cross-project → intelligence/cross-project}/transfer.ts +0 -0
- /package/src/{optimization → intelligence/optimization}/index.ts +0 -0
- /package/src/{optimization → intelligence/optimization}/precompute.ts +0 -0
- /package/src/{optimization → intelligence/optimization}/semantic-cache.ts +0 -0
- /package/src/{prediction → intelligence/prediction}/context-anticipator.ts +0 -0
- /package/src/{prediction → intelligence/prediction}/decision-predictor.ts +0 -0
- /package/src/{prediction → intelligence/prediction}/index.ts +0 -0
- /package/src/{prediction → intelligence/prediction}/recommender.ts +0 -0
- /package/src/{reasoning → intelligence/reasoning}/chain-retrieval.ts +0 -0
- /package/src/{reasoning → intelligence/reasoning}/counterfactual.ts +0 -0
- /package/src/{reasoning → intelligence/reasoning}/index.ts +0 -0
- /package/src/{reasoning → intelligence/reasoning}/synthesizer.ts +0 -0
- /package/src/{temporal → intelligence/temporal}/evolution.ts +0 -0
- /package/src/{temporal → intelligence/temporal}/index.ts +0 -0
- /package/src/{temporal → intelligence/temporal}/query-processor.ts +0 -0
- /package/src/{temporal → intelligence/temporal}/timeline.ts +0 -0
- /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
|
-
*
|
|
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
|
-
//
|
|
36
|
-
private readonly
|
|
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', '
|
|
39
|
-
'
|
|
40
|
-
'
|
|
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 (
|
|
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
|
-
|
|
153
|
+
// Strong noise: a single hit is enough
|
|
154
|
+
for (const term of this.STRONG_NOISE) {
|
|
144
155
|
if (lower.includes(term)) {
|
|
145
|
-
|
|
156
|
+
return true
|
|
146
157
|
}
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
//
|
|
150
|
-
|
|
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
|
-
*
|
|
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.
|
|
195
|
+
return overlap > 0.75
|
|
163
196
|
})
|
|
164
197
|
|
|
165
198
|
if (!isDuplicate) {
|