@kybernesis/brain-core 0.1.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/dist/claude-call.d.ts +37 -0
- package/dist/claude-call.d.ts.map +1 -0
- package/dist/claude-call.js +55 -0
- package/dist/claude-call.js.map +1 -0
- package/dist/entity-graph.d.ts +79 -0
- package/dist/entity-graph.d.ts.map +1 -0
- package/dist/entity-graph.js +611 -0
- package/dist/entity-graph.js.map +1 -0
- package/dist/fact-contradiction.d.ts +25 -0
- package/dist/fact-contradiction.d.ts.map +1 -0
- package/dist/fact-contradiction.js +109 -0
- package/dist/fact-contradiction.js.map +1 -0
- package/dist/fact-extractor.d.ts +26 -0
- package/dist/fact-extractor.d.ts.map +1 -0
- package/dist/fact-extractor.js +98 -0
- package/dist/fact-extractor.js.map +1 -0
- package/dist/fact-retrieval.d.ts +51 -0
- package/dist/fact-retrieval.d.ts.map +1 -0
- package/dist/fact-retrieval.js +401 -0
- package/dist/fact-retrieval.js.map +1 -0
- package/dist/fact-store.d.ts +26 -0
- package/dist/fact-store.d.ts.map +1 -0
- package/dist/fact-store.js +181 -0
- package/dist/fact-store.js.map +1 -0
- package/dist/fact-temporal.d.ts +20 -0
- package/dist/fact-temporal.d.ts.map +1 -0
- package/dist/fact-temporal.js +79 -0
- package/dist/fact-temporal.js.map +1 -0
- package/dist/fts-sanitizer.d.ts +32 -0
- package/dist/fts-sanitizer.d.ts.map +1 -0
- package/dist/fts-sanitizer.js +61 -0
- package/dist/fts-sanitizer.js.map +1 -0
- package/dist/hybrid-search.d.ts +44 -0
- package/dist/hybrid-search.d.ts.map +1 -0
- package/dist/hybrid-search.js +410 -0
- package/dist/hybrid-search.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/ops.d.ts +28 -0
- package/dist/ops.d.ts.map +1 -0
- package/dist/ops.js +307 -0
- package/dist/ops.js.map +1 -0
- package/dist/queue.d.ts +13 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +28 -0
- package/dist/queue.js.map +1 -0
- package/dist/relationship-extractor.d.ts +38 -0
- package/dist/relationship-extractor.d.ts.map +1 -0
- package/dist/relationship-extractor.js +119 -0
- package/dist/relationship-extractor.js.map +1 -0
- package/dist/sleep/config.d.ts +47 -0
- package/dist/sleep/config.d.ts.map +1 -0
- package/dist/sleep/config.js +46 -0
- package/dist/sleep/config.js.map +1 -0
- package/dist/sleep/db.d.ts +16 -0
- package/dist/sleep/db.d.ts.map +1 -0
- package/dist/sleep/db.js +114 -0
- package/dist/sleep/db.js.map +1 -0
- package/dist/sleep/index.d.ts +69 -0
- package/dist/sleep/index.d.ts.map +1 -0
- package/dist/sleep/index.js +99 -0
- package/dist/sleep/index.js.map +1 -0
- package/dist/sleep/steps/consolidate.d.ts +19 -0
- package/dist/sleep/steps/consolidate.d.ts.map +1 -0
- package/dist/sleep/steps/consolidate.js +74 -0
- package/dist/sleep/steps/consolidate.js.map +1 -0
- package/dist/sleep/steps/decay.d.ts +19 -0
- package/dist/sleep/steps/decay.d.ts.map +1 -0
- package/dist/sleep/steps/decay.js +121 -0
- package/dist/sleep/steps/decay.js.map +1 -0
- package/dist/sleep/steps/entity-hygiene.d.ts +29 -0
- package/dist/sleep/steps/entity-hygiene.d.ts.map +1 -0
- package/dist/sleep/steps/entity-hygiene.js +452 -0
- package/dist/sleep/steps/entity-hygiene.js.map +1 -0
- package/dist/sleep/steps/link.d.ts +20 -0
- package/dist/sleep/steps/link.d.ts.map +1 -0
- package/dist/sleep/steps/link.js +216 -0
- package/dist/sleep/steps/link.js.map +1 -0
- package/dist/sleep/steps/observe.d.ts +17 -0
- package/dist/sleep/steps/observe.d.ts.map +1 -0
- package/dist/sleep/steps/observe.js +192 -0
- package/dist/sleep/steps/observe.js.map +1 -0
- package/dist/sleep/steps/profile.d.ts +15 -0
- package/dist/sleep/steps/profile.d.ts.map +1 -0
- package/dist/sleep/steps/profile.js +26 -0
- package/dist/sleep/steps/profile.js.map +1 -0
- package/dist/sleep/steps/reasoning.d.ts +19 -0
- package/dist/sleep/steps/reasoning.d.ts.map +1 -0
- package/dist/sleep/steps/reasoning.js +173 -0
- package/dist/sleep/steps/reasoning.js.map +1 -0
- package/dist/sleep/steps/summarize.d.ts +21 -0
- package/dist/sleep/steps/summarize.d.ts.map +1 -0
- package/dist/sleep/steps/summarize.js +206 -0
- package/dist/sleep/steps/summarize.js.map +1 -0
- package/dist/sleep/steps/tag.d.ts +16 -0
- package/dist/sleep/steps/tag.d.ts.map +1 -0
- package/dist/sleep/steps/tag.js +84 -0
- package/dist/sleep/steps/tag.js.map +1 -0
- package/dist/sleep/steps/tier.d.ts +18 -0
- package/dist/sleep/steps/tier.d.ts.map +1 -0
- package/dist/sleep/steps/tier.js +112 -0
- package/dist/sleep/steps/tier.js.map +1 -0
- package/dist/sleep/utils/checkpoint.d.ts +11 -0
- package/dist/sleep/utils/checkpoint.d.ts.map +1 -0
- package/dist/sleep/utils/checkpoint.js +26 -0
- package/dist/sleep/utils/checkpoint.js.map +1 -0
- package/dist/sleep/utils/jaccard.d.ts +7 -0
- package/dist/sleep/utils/jaccard.d.ts.map +1 -0
- package/dist/sleep/utils/jaccard.js +19 -0
- package/dist/sleep/utils/jaccard.js.map +1 -0
- package/dist/store-conversation.d.ts +29 -0
- package/dist/store-conversation.d.ts.map +1 -0
- package/dist/store-conversation.js +227 -0
- package/dist/store-conversation.js.map +1 -0
- package/dist/timeline.d.ts +50 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +389 -0
- package/dist/timeline.js.map +1 -0
- package/dist/user-profile.d.ts +30 -0
- package/dist/user-profile.d.ts.map +1 -0
- package/dist/user-profile.js +147 -0
- package/dist/user-profile.js.map +1 -0
- package/dist/vectors.d.ts +56 -0
- package/dist/vectors.d.ts.map +1 -0
- package/dist/vectors.js +132 -0
- package/dist/vectors.js.map +1 -0
- package/package.json +53 -0
package/dist/ops.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI output formatters — port of KAD's cli-formatters.ts (renamed ops.ts
|
|
3
|
+
* per CANONICAL.md §4). Output is byte-identical to what KAD renders.
|
|
4
|
+
* Wire contract for MCP skills — do NOT change output format.
|
|
5
|
+
*/
|
|
6
|
+
import { getDb } from '@kybernesis/brain-storage-sqlite';
|
|
7
|
+
import { getEntityContext, searchEntities, getEntityGraphStats, getMostMentionedEntities, getTypedRelationships, getEntityProfile, getOpenContradictions, getEntityInsights, } from './entity-graph.js';
|
|
8
|
+
import { formatRelationship } from './relationship-extractor.js';
|
|
9
|
+
import { getFactsForEntity } from './fact-store.js';
|
|
10
|
+
import { queryTimeline, getTimelineStats, getRecentActivity, getActivityOnDate, searchTimeline, } from './timeline.js';
|
|
11
|
+
import { hybridSearch } from './hybrid-search.js';
|
|
12
|
+
// ─── Recall ───────────────────────────────────────────────────────────────────
|
|
13
|
+
function extractEntityName(query) {
|
|
14
|
+
return query
|
|
15
|
+
.replace(/^(who is|what is|what do (i|you) know about|tell me about|recall)\s+/i, '')
|
|
16
|
+
.replace(/\?+$/, '')
|
|
17
|
+
.trim();
|
|
18
|
+
}
|
|
19
|
+
async function formatEntityContext(t, context) {
|
|
20
|
+
const { entity, mentions, relatedEntities } = context;
|
|
21
|
+
const lines = [];
|
|
22
|
+
lines.push(`# ${entity.name}`, '');
|
|
23
|
+
try {
|
|
24
|
+
const profile = await getEntityProfile(t, entity.id);
|
|
25
|
+
if (profile) {
|
|
26
|
+
lines.push(profile.profile, '');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch { /* non-critical */ }
|
|
30
|
+
lines.push(`Mentioned ${entity.mentionCount} times | First seen: ${new Date(entity.firstSeen).toLocaleDateString()} | Last seen: ${new Date(entity.lastSeen).toLocaleDateString()}`);
|
|
31
|
+
lines.push(`Type: ${entity.type}`);
|
|
32
|
+
if (entity.aliases.length > 0)
|
|
33
|
+
lines.push(`Also known as: ${entity.aliases.join(', ')}`);
|
|
34
|
+
try {
|
|
35
|
+
const facts = await getFactsForEntity(t, entity.name, { latestOnly: true, limit: 10 });
|
|
36
|
+
if (facts.length > 0) {
|
|
37
|
+
lines.push('', '## Known Facts');
|
|
38
|
+
for (const f of facts) {
|
|
39
|
+
const conf = f.confidence < 0.7 ? ` (${Math.round(f.confidence * 100)}%)` : '';
|
|
40
|
+
lines.push(`- ${f.content}${conf}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch { /* non-critical */ }
|
|
45
|
+
try {
|
|
46
|
+
const rels = await getTypedRelationships(t, entity.id);
|
|
47
|
+
if (rels.length > 0) {
|
|
48
|
+
lines.push('', '## Relationships');
|
|
49
|
+
for (const rel of rels) {
|
|
50
|
+
const verb = formatRelationship(rel.entity.name, rel.relationship, rel.direction);
|
|
51
|
+
const conf = rel.confidence >= 0.8 ? '' : ` (${Math.round(rel.confidence * 100)}% confident)`;
|
|
52
|
+
lines.push(`- ${entity.name} ${verb} ${rel.entity.name}${conf}`);
|
|
53
|
+
if (rel.rationale)
|
|
54
|
+
lines.push(` -- ${rel.rationale}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch { /* non-critical */ }
|
|
59
|
+
try {
|
|
60
|
+
const insights = await getEntityInsights(t, entity.id);
|
|
61
|
+
if (insights.length > 0) {
|
|
62
|
+
lines.push('', '## Insights');
|
|
63
|
+
for (const ins of insights.slice(0, 5)) {
|
|
64
|
+
const tag = ins.insightType === 'inference' ? 'inferred'
|
|
65
|
+
: ins.insightType === 'pattern' ? 'pattern'
|
|
66
|
+
: ins.insightType === 'quality' ? 'note' : 'insight';
|
|
67
|
+
lines.push(`- ${ins.insight} [${tag}]`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch { /* non-critical */ }
|
|
72
|
+
try {
|
|
73
|
+
const contradictions = await getOpenContradictions(t, entity.id);
|
|
74
|
+
if (contradictions.length > 0) {
|
|
75
|
+
lines.push('');
|
|
76
|
+
for (const c of contradictions) {
|
|
77
|
+
lines.push(`Note: I have conflicting info — "${c.factA}" vs "${c.factB}". Want to clarify which is correct?`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch { /* non-critical */ }
|
|
82
|
+
if (mentions.length > 0) {
|
|
83
|
+
lines.push('', '## Mentions');
|
|
84
|
+
for (const m of mentions.slice(0, 10)) {
|
|
85
|
+
const date = new Date(m.timestamp).toLocaleDateString();
|
|
86
|
+
lines.push(m.context ? `- [${date}] ${m.context}` : `- [${date}] Mentioned in conversation`);
|
|
87
|
+
}
|
|
88
|
+
if (mentions.length > 10)
|
|
89
|
+
lines.push(`- ... and ${mentions.length - 10} more mentions`);
|
|
90
|
+
}
|
|
91
|
+
if (relatedEntities.length > 0) {
|
|
92
|
+
lines.push('', '## Co-occurred With');
|
|
93
|
+
for (const rel of relatedEntities.slice(0, 10)) {
|
|
94
|
+
lines.push(`- ${rel.entity.name} (${rel.entity.type}) - appeared together ${rel.strength} time(s)`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return lines.join('\n');
|
|
98
|
+
}
|
|
99
|
+
async function getRelatedMemories(t, entityName) {
|
|
100
|
+
try {
|
|
101
|
+
const db = getDb(t, 'timeline');
|
|
102
|
+
let sleep = null;
|
|
103
|
+
try {
|
|
104
|
+
sleep = getDb(t, 'sleep');
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
const entityLower = entityName.toLowerCase();
|
|
110
|
+
const sourcePaths = db.prepare(`
|
|
111
|
+
SELECT DISTINCT source_path FROM timeline_events
|
|
112
|
+
WHERE LOWER(title) LIKE ? OR LOWER(tags_json) LIKE ? OR LOWER(entities_json) LIKE ?
|
|
113
|
+
LIMIT 20
|
|
114
|
+
`).all(`%${entityLower}%`, `%${entityLower}%`, `%${entityLower}%`);
|
|
115
|
+
if (sourcePaths.length === 0)
|
|
116
|
+
return [];
|
|
117
|
+
const relatedPaths = new Set();
|
|
118
|
+
for (const { source_path } of sourcePaths) {
|
|
119
|
+
try {
|
|
120
|
+
const edges = sleep.prepare(`
|
|
121
|
+
SELECT CASE WHEN from_path = ? THEN to_path ELSE from_path END as related_path,
|
|
122
|
+
confidence, shared_tags
|
|
123
|
+
FROM memory_edges
|
|
124
|
+
WHERE from_path = ? OR to_path = ?
|
|
125
|
+
ORDER BY confidence DESC LIMIT 3
|
|
126
|
+
`).all(source_path, source_path, source_path);
|
|
127
|
+
for (const edge of edges) {
|
|
128
|
+
if (!sourcePaths.some(s => s.source_path === edge.related_path)) {
|
|
129
|
+
relatedPaths.add(edge.related_path);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch { /* memory_edges may not exist */ }
|
|
134
|
+
}
|
|
135
|
+
if (relatedPaths.size === 0)
|
|
136
|
+
return [];
|
|
137
|
+
const lines = [];
|
|
138
|
+
for (const path of relatedPaths) {
|
|
139
|
+
const item = db.prepare('SELECT title, tier, timestamp FROM timeline_events WHERE source_path = ?')
|
|
140
|
+
.get(path);
|
|
141
|
+
if (item) {
|
|
142
|
+
const date = new Date(item.timestamp).toLocaleDateString();
|
|
143
|
+
lines.push(`- ${item.title} [${date}] (${item.tier})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lines;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function trackEntityAccess(t, entityId) {
|
|
153
|
+
try {
|
|
154
|
+
const db = getDb(t, 'entityGraph');
|
|
155
|
+
db.prepare(`
|
|
156
|
+
UPDATE entities SET access_count = access_count + 1, last_accessed = datetime('now') WHERE id = ?
|
|
157
|
+
`).run(entityId);
|
|
158
|
+
}
|
|
159
|
+
catch { /* non-critical */ }
|
|
160
|
+
}
|
|
161
|
+
export async function formatRecall(t, query) {
|
|
162
|
+
if (!query || !query.trim()) {
|
|
163
|
+
const stats = await getEntityGraphStats(t);
|
|
164
|
+
const top = await getMostMentionedEntities(t, { limit: 10 });
|
|
165
|
+
return formatStats(stats) + '\n\n' + formatTopEntities(top);
|
|
166
|
+
}
|
|
167
|
+
const entityName = extractEntityName(query);
|
|
168
|
+
const context = await getEntityContext(t, entityName);
|
|
169
|
+
if (context) {
|
|
170
|
+
const out = [await formatEntityContext(t, context)];
|
|
171
|
+
const related = await getRelatedMemories(t, entityName);
|
|
172
|
+
if (related.length > 0) {
|
|
173
|
+
out.push('', '## Connected Memories', ...related);
|
|
174
|
+
}
|
|
175
|
+
await trackEntityAccess(t, context.entity.id);
|
|
176
|
+
return out.join('\n');
|
|
177
|
+
}
|
|
178
|
+
const results = await searchEntities(t, entityName, { limit: 10 });
|
|
179
|
+
if (results.length === 1) {
|
|
180
|
+
const ctx = await getEntityContext(t, results[0].id);
|
|
181
|
+
if (ctx) {
|
|
182
|
+
const out = [await formatEntityContext(t, ctx)];
|
|
183
|
+
const related = await getRelatedMemories(t, results[0].name);
|
|
184
|
+
if (related.length > 0) {
|
|
185
|
+
out.push('', '## Connected Memories', ...related);
|
|
186
|
+
}
|
|
187
|
+
await trackEntityAccess(t, ctx.entity.id);
|
|
188
|
+
return out.join('\n');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (results.length > 0)
|
|
192
|
+
return formatSearchResults(results);
|
|
193
|
+
return `No information found about "${entityName}".\n\nThis entity has not been mentioned in any processed conversations yet.`;
|
|
194
|
+
}
|
|
195
|
+
function formatSearchResults(results) {
|
|
196
|
+
if (results.length === 0)
|
|
197
|
+
return 'No matching entities found.';
|
|
198
|
+
return ['# Search Results', '', ...results.map(e => `- ${e.name} (${e.type}) - ${e.mentionCount} mention(s)`)].join('\n');
|
|
199
|
+
}
|
|
200
|
+
function formatStats(stats) {
|
|
201
|
+
return [
|
|
202
|
+
'# Entity Graph Summary', '',
|
|
203
|
+
`Total entities tracked: ${stats.totalEntities}`,
|
|
204
|
+
`Total mentions recorded: ${stats.totalMentions}`,
|
|
205
|
+
`Entity relationships: ${stats.totalRelations}`, '',
|
|
206
|
+
'## By Type',
|
|
207
|
+
`- People: ${stats.byType.person}`,
|
|
208
|
+
`- Companies: ${stats.byType.company}`,
|
|
209
|
+
`- Projects: ${stats.byType.project}`,
|
|
210
|
+
`- Places: ${stats.byType.place}`,
|
|
211
|
+
`- Topics: ${stats.byType.topic}`,
|
|
212
|
+
].join('\n');
|
|
213
|
+
}
|
|
214
|
+
function formatTopEntities(entities) {
|
|
215
|
+
if (entities.length === 0)
|
|
216
|
+
return 'No entities recorded yet.';
|
|
217
|
+
return ['# Most Mentioned Entities', '', ...entities.map(e => `- ${e.name} (${e.type}) - ${e.mentionCount} mention(s)`)].join('\n');
|
|
218
|
+
}
|
|
219
|
+
// ─── Timeline ─────────────────────────────────────────────────────────────────
|
|
220
|
+
function getToday() { return new Date().toISOString().slice(0, 10); }
|
|
221
|
+
function getYesterday() {
|
|
222
|
+
const d = new Date();
|
|
223
|
+
d.setDate(d.getDate() - 1);
|
|
224
|
+
return d.toISOString().slice(0, 10);
|
|
225
|
+
}
|
|
226
|
+
function getWeekStart() {
|
|
227
|
+
const d = new Date();
|
|
228
|
+
const day = d.getDay();
|
|
229
|
+
const diff = d.getDate() - day + (day === 0 ? -6 : 1);
|
|
230
|
+
d.setDate(diff);
|
|
231
|
+
d.setHours(0, 0, 0, 0);
|
|
232
|
+
return d.toISOString();
|
|
233
|
+
}
|
|
234
|
+
function formatTimelineEvents(events, title) {
|
|
235
|
+
if (events.length === 0)
|
|
236
|
+
return `# ${title}\n\nNo events found.`;
|
|
237
|
+
const lines = [`# ${title}`, '', `${events.length} event(s)`, ''];
|
|
238
|
+
for (const event of events) {
|
|
239
|
+
const date = new Date(event.timestamp).toLocaleDateString();
|
|
240
|
+
const time = new Date(event.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
241
|
+
lines.push(`## [${event.type}] ${event.title}`);
|
|
242
|
+
const tier = event['tier'];
|
|
243
|
+
lines.push(`${date} ${time}${tier ? ` | tier: ${tier}` : ''}`);
|
|
244
|
+
if (event.summary)
|
|
245
|
+
lines.push(event.summary);
|
|
246
|
+
const ents = event['entities'] ?? [];
|
|
247
|
+
if (Array.isArray(ents) && ents.length > 0)
|
|
248
|
+
lines.push(`Entities: ${ents.join(', ')}`);
|
|
249
|
+
lines.push('');
|
|
250
|
+
}
|
|
251
|
+
return lines.join('\n');
|
|
252
|
+
}
|
|
253
|
+
function formatTimelineStats(stats) {
|
|
254
|
+
return [
|
|
255
|
+
'# Timeline Statistics', '',
|
|
256
|
+
`Total events: ${stats.totalEvents}`, '',
|
|
257
|
+
'## By Type',
|
|
258
|
+
...Object.entries(stats.byType).map(([k, v]) => `- ${k}: ${v}`),
|
|
259
|
+
].join('\n');
|
|
260
|
+
}
|
|
261
|
+
export async function formatTimelineRich(t, opts) {
|
|
262
|
+
if (opts.stats)
|
|
263
|
+
return formatTimelineStats(await getTimelineStats(t));
|
|
264
|
+
const limit = opts.limit ?? 20;
|
|
265
|
+
let events;
|
|
266
|
+
let title;
|
|
267
|
+
if (opts.today) {
|
|
268
|
+
events = await getActivityOnDate(t, getToday());
|
|
269
|
+
title = "Today's Activity";
|
|
270
|
+
}
|
|
271
|
+
else if (opts.yesterday) {
|
|
272
|
+
events = await getActivityOnDate(t, getYesterday());
|
|
273
|
+
title = "Yesterday's Activity";
|
|
274
|
+
}
|
|
275
|
+
else if (opts.week) {
|
|
276
|
+
events = await queryTimeline(t, { start: getWeekStart(), limit: 50 });
|
|
277
|
+
title = 'This Week';
|
|
278
|
+
}
|
|
279
|
+
else if (opts.search) {
|
|
280
|
+
events = await searchTimeline(t, opts.search, { limit, type: opts.type });
|
|
281
|
+
title = `Search: "${opts.search}"`;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
events = await getRecentActivity(t, limit);
|
|
285
|
+
title = 'Recent Activity';
|
|
286
|
+
}
|
|
287
|
+
return formatTimelineEvents(events, title);
|
|
288
|
+
}
|
|
289
|
+
export async function formatSearchRich(t, opts) {
|
|
290
|
+
const limit = opts.limit ?? 20;
|
|
291
|
+
const results = await hybridSearch(t, opts.q, { limit });
|
|
292
|
+
if (results.length === 0)
|
|
293
|
+
return `# Search\n\nNo matches for "${opts.q}".`;
|
|
294
|
+
const lines = [`# Search: "${opts.q}"`, '', `${results.length} result(s)`, ''];
|
|
295
|
+
for (const r of results) {
|
|
296
|
+
const date = r.timestamp ? new Date(r.timestamp).toLocaleDateString() : '';
|
|
297
|
+
const tier = r.tier ? ` | ${r.tier}` : '';
|
|
298
|
+
lines.push(`## ${r.title ?? '(untitled)'}${date ? ` — ${date}` : ''}${tier}`);
|
|
299
|
+
if (r.content)
|
|
300
|
+
lines.push(r.content.slice(0, 500));
|
|
301
|
+
if (r.source_path)
|
|
302
|
+
lines.push(`_${r.source_path}_`);
|
|
303
|
+
lines.push('');
|
|
304
|
+
}
|
|
305
|
+
return lines.join('\n');
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=ops.js.map
|
package/dist/ops.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.js","sourceRoot":"","sources":["../src/ops.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AACzD,OAAO,EACL,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,EAAE,wBAAwB,EAC/E,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAC9D,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EACL,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EACrE,c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,CAAC,CAAC,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,CAAC,OAAO;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,CAAC,WAAW;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC;QACpD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-tenant single-fiber write queue.
|
|
3
|
+
*
|
|
4
|
+
* Every brain write (timeline, fact, entity, sleep) is queued on the
|
|
5
|
+
* tenant's serial channel. better-sqlite3 + WAL is multi-reader-safe but
|
|
6
|
+
* single-writer — concurrent writes risk corruption. This queue makes the
|
|
7
|
+
* "daemon is the sole writer per tenant" invariant load-bearing in code.
|
|
8
|
+
*/
|
|
9
|
+
type Job<T> = () => Promise<T>;
|
|
10
|
+
export declare function enqueueWrite<T>(slug: string, job: Job<T>): Promise<T>;
|
|
11
|
+
export declare function queueDepth(slug: string): number;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,KAAK,GAAG,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;AAS/B,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAcrE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-tenant single-fiber write queue.
|
|
3
|
+
*
|
|
4
|
+
* Every brain write (timeline, fact, entity, sleep) is queued on the
|
|
5
|
+
* tenant's serial channel. better-sqlite3 + WAL is multi-reader-safe but
|
|
6
|
+
* single-writer — concurrent writes risk corruption. This queue makes the
|
|
7
|
+
* "daemon is the sole writer per tenant" invariant load-bearing in code.
|
|
8
|
+
*/
|
|
9
|
+
const queues = new Map();
|
|
10
|
+
export function enqueueWrite(slug, job) {
|
|
11
|
+
const state = queues.get(slug) ?? { tail: Promise.resolve(), depth: 0 };
|
|
12
|
+
state.depth += 1;
|
|
13
|
+
const run = state.tail.then(() => {
|
|
14
|
+
return job().catch((err) => {
|
|
15
|
+
console.warn('[brain-core/queue] write failed', { slug, err: String(err) });
|
|
16
|
+
throw err;
|
|
17
|
+
}).finally(() => {
|
|
18
|
+
state.depth -= 1;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
state.tail = run.catch(() => undefined);
|
|
22
|
+
queues.set(slug, state);
|
|
23
|
+
return run;
|
|
24
|
+
}
|
|
25
|
+
export function queueDepth(slug) {
|
|
26
|
+
return queues.get(slug)?.depth ?? 0;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;AAE7C,MAAM,UAAU,YAAY,CAAI,IAAY,EAAE,GAAW;IACvD,MAAM,KAAK,GAAe,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACpF,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;IACjB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;QAC/B,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACzB,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC5E,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACd,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,OAAO,GAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relationship extractor — port of KAD's relationship-extractor.ts.
|
|
3
|
+
*
|
|
4
|
+
* Uses Claude Haiku to extract typed relationships between entities
|
|
5
|
+
* from conversation text.
|
|
6
|
+
*/
|
|
7
|
+
import type { TenantContext, EntityType, RelationshipType } from '@kybernesis/brain-contracts';
|
|
8
|
+
export interface ExtractedRelationship {
|
|
9
|
+
source: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: EntityType;
|
|
12
|
+
};
|
|
13
|
+
target: {
|
|
14
|
+
name: string;
|
|
15
|
+
type: EntityType;
|
|
16
|
+
};
|
|
17
|
+
relationship: RelationshipType;
|
|
18
|
+
confidence: number;
|
|
19
|
+
rationale: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RelationshipExtractionResult {
|
|
22
|
+
entities: Array<{
|
|
23
|
+
name: string;
|
|
24
|
+
type: EntityType;
|
|
25
|
+
}>;
|
|
26
|
+
relationships: ExtractedRelationship[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract entities and typed relationships from conversation text.
|
|
30
|
+
* Uses Claude Haiku for fast, cost-effective extraction.
|
|
31
|
+
* `t` is accepted for signature parity with other brain-core modules.
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractRelationships(_t: TenantContext, text: string, options?: {
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
}): Promise<RelationshipExtractionResult>;
|
|
36
|
+
/** Format a relationship verb for display in recall output. */
|
|
37
|
+
export declare function formatRelationship(_entityName: string, relationship: RelationshipType, direction: 'outgoing' | 'incoming'): string;
|
|
38
|
+
//# sourceMappingURL=relationship-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationship-extractor.d.ts","sourceRoot":"","sources":["../src/relationship-extractor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/F,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;IAC3C,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;IAC3C,YAAY,EAAE,gBAAgB,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACpD,aAAa,EAAE,qBAAqB,EAAE,CAAC;CACxC;AAgED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAExC,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GACnC,OAAO,CAAC,4BAA4B,CAAC,CA+BvC;AAED,+DAA+D;AAC/D,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,gBAAgB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,GACjC,MAAM,CAoBR"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relationship extractor — port of KAD's relationship-extractor.ts.
|
|
3
|
+
*
|
|
4
|
+
* Uses Claude Haiku to extract typed relationships between entities
|
|
5
|
+
* from conversation text.
|
|
6
|
+
*/
|
|
7
|
+
import { callClaude } from './claude-call.js';
|
|
8
|
+
const EXTRACTION_PROMPT = `You are an entity relationship extractor. Analyze the conversation text and extract:
|
|
9
|
+
|
|
10
|
+
1. **Entities**: People, companies, projects, places, and topics mentioned
|
|
11
|
+
2. **Relationships**: Explicit relationships between entities
|
|
12
|
+
|
|
13
|
+
## Entity Types
|
|
14
|
+
- person: Individual people (e.g., "John", "Dr. Smith", "my brother")
|
|
15
|
+
- company: Companies, organizations (e.g., "Google", "Acme Corp", "the university")
|
|
16
|
+
- project: Specific named projects, products, or apps that someone is building or working on (e.g., "KyberBot", "Project Alpha", "the mobile app"). NOTE: Programming languages, frameworks, libraries, databases, and tools are NOT projects — classify them as topic instead.
|
|
17
|
+
- place: Locations (e.g., "New York", "the office", "Thailand")
|
|
18
|
+
- topic: Topics, concepts, technologies, tools, frameworks, programming languages (e.g., "AI", "funding", "TypeScript", "Docker", "React", "SQLite", "Express", "deployment")
|
|
19
|
+
|
|
20
|
+
## Relationship Types (only use these exact values)
|
|
21
|
+
- founded: Person founded company/project
|
|
22
|
+
- works_at: Person works at company
|
|
23
|
+
- invested_in: Person/company invested in company/project
|
|
24
|
+
- met_with: Person met with person
|
|
25
|
+
- created: Person created project
|
|
26
|
+
- manages: Person manages project/company
|
|
27
|
+
- partners_with: Company partners with company
|
|
28
|
+
- located_in: Company/project located in place
|
|
29
|
+
- discussed: Entities discussed together (topic-related)
|
|
30
|
+
- related_to: Generic relationship when specific type unclear
|
|
31
|
+
- reports_to: Person reports to person (management hierarchy)
|
|
32
|
+
- uses: Project/company uses a technology or tool (topic)
|
|
33
|
+
- depends_on: Project depends on another project or technology
|
|
34
|
+
- part_of: Entity is part of a larger entity (team part of company, module part of project)
|
|
35
|
+
|
|
36
|
+
## Rules
|
|
37
|
+
- Only extract relationships that are EXPLICITLY stated or strongly implied
|
|
38
|
+
- Do NOT create relationships just because entities appear together
|
|
39
|
+
- Do NOT extract shell commands (curl, bash, git), file paths (.claude/settings.json), error messages (BLOCKED, timeout), or infrastructure noise (sandbox, permissions, max turns limit) as entities
|
|
40
|
+
- The speaker is "user" unless otherwise specified
|
|
41
|
+
- Set confidence 0.8-0.95 for explicit statements, 0.5-0.7 for implied relationships
|
|
42
|
+
- Provide brief rationale explaining why you identified each relationship
|
|
43
|
+
|
|
44
|
+
Respond with JSON only:
|
|
45
|
+
{
|
|
46
|
+
"entities": [
|
|
47
|
+
{ "name": "John Smith", "type": "person" },
|
|
48
|
+
{ "name": "Acme Corp", "type": "company" }
|
|
49
|
+
],
|
|
50
|
+
"relationships": [
|
|
51
|
+
{
|
|
52
|
+
"source": { "name": "John Smith", "type": "person" },
|
|
53
|
+
"target": { "name": "Acme Corp", "type": "company" },
|
|
54
|
+
"relationship": "founded",
|
|
55
|
+
"confidence": 0.9,
|
|
56
|
+
"rationale": "Text explicitly states John founded Acme Corp"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
If no explicit relationships found, return empty relationships array but still list entities.`;
|
|
62
|
+
const VALID_ENTITY_TYPES = new Set(['person', 'company', 'project', 'place', 'topic']);
|
|
63
|
+
const VALID_RELATIONSHIP_TYPES = new Set([
|
|
64
|
+
'co-occurred', 'founded', 'works_at', 'invested_in', 'met_with', 'created',
|
|
65
|
+
'manages', 'partners_with', 'located_in', 'discussed', 'related_to',
|
|
66
|
+
'reports_to', 'uses', 'depends_on', 'part_of',
|
|
67
|
+
]);
|
|
68
|
+
/**
|
|
69
|
+
* Extract entities and typed relationships from conversation text.
|
|
70
|
+
* Uses Claude Haiku for fast, cost-effective extraction.
|
|
71
|
+
* `t` is accepted for signature parity with other brain-core modules.
|
|
72
|
+
*/
|
|
73
|
+
export async function extractRelationships(
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
+
_t, text, options = {}) {
|
|
76
|
+
const maxTokens = options.maxTokens ?? 4096;
|
|
77
|
+
try {
|
|
78
|
+
const truncated = text.length > 4000 ? text.slice(0, 4000) + '\n\n[Text truncated...]' : text;
|
|
79
|
+
const response = await callClaude(`Extract entities and relationships from this conversation:\n\n${truncated}`, { system: EXTRACTION_PROMPT, maxTokens });
|
|
80
|
+
if (!response)
|
|
81
|
+
return { entities: [], relationships: [] };
|
|
82
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
83
|
+
if (!jsonMatch)
|
|
84
|
+
return { entities: [], relationships: [] };
|
|
85
|
+
const raw = JSON.parse(jsonMatch[0]);
|
|
86
|
+
const entities = (raw.entities || []).filter((e) => e.name && e.type && VALID_ENTITY_TYPES.has(e.type));
|
|
87
|
+
const relationships = (raw.relationships || []).filter((r) => r.source?.name && r.source?.type &&
|
|
88
|
+
r.target?.name && r.target?.type &&
|
|
89
|
+
r.relationship && VALID_RELATIONSHIP_TYPES.has(r.relationship));
|
|
90
|
+
return { entities, relationships };
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.warn('[brain-core/relationship-extractor] extraction failed', { err: String(err) });
|
|
94
|
+
return { entities: [], relationships: [] };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Format a relationship verb for display in recall output. */
|
|
98
|
+
export function formatRelationship(_entityName, relationship, direction) {
|
|
99
|
+
const formats = {
|
|
100
|
+
founded: { outgoing: 'founded', incoming: 'was founded by' },
|
|
101
|
+
works_at: { outgoing: 'works at', incoming: 'employs' },
|
|
102
|
+
invested_in: { outgoing: 'invested in', incoming: 'received investment from' },
|
|
103
|
+
met_with: { outgoing: 'met with', incoming: 'met with' },
|
|
104
|
+
created: { outgoing: 'created', incoming: 'was created by' },
|
|
105
|
+
manages: { outgoing: 'manages', incoming: 'is managed by' },
|
|
106
|
+
partners_with: { outgoing: 'partners with', incoming: 'partners with' },
|
|
107
|
+
located_in: { outgoing: 'is located in', incoming: 'is location of' },
|
|
108
|
+
discussed: { outgoing: 'discussed', incoming: 'was discussed with' },
|
|
109
|
+
related_to: { outgoing: 'related to', incoming: 'related to' },
|
|
110
|
+
'co-occurred': { outgoing: 'mentioned with', incoming: 'mentioned with' },
|
|
111
|
+
reports_to: { outgoing: 'reports to', incoming: 'has report' },
|
|
112
|
+
uses: { outgoing: 'uses', incoming: 'is used by' },
|
|
113
|
+
depends_on: { outgoing: 'depends on', incoming: 'is dependency of' },
|
|
114
|
+
part_of: { outgoing: 'is part of', incoming: 'contains' },
|
|
115
|
+
};
|
|
116
|
+
const fmt = formats[relationship] ?? formats['related_to'];
|
|
117
|
+
return direction === 'outgoing' ? fmt.outgoing : fmt.incoming;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=relationship-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationship-extractor.js","sourceRoot":"","sources":["../src/relationship-extractor.ts"],"names":[],"m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AC,CAAC,GAAG,CAAC,QAAQ,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep config — port of KAD's sleep/config.ts (verbatim per ADR-0003).
|
|
3
|
+
* All constants are locked at parity (CANONICAL.md §2 "Sleep cadence + default config").
|
|
4
|
+
*/
|
|
5
|
+
export interface SleepConfig {
|
|
6
|
+
intervalMinutes: number;
|
|
7
|
+
initialDelayMinutes: number;
|
|
8
|
+
batchSize: number;
|
|
9
|
+
maxTagsPerRun: number;
|
|
10
|
+
maxLinksPerRun: number;
|
|
11
|
+
maxSummariesPerRun: number;
|
|
12
|
+
decayRatePerHour: number;
|
|
13
|
+
maxDecay: number;
|
|
14
|
+
minConfidenceForLink: number;
|
|
15
|
+
maxEdgesPerMemory: number;
|
|
16
|
+
hotPriorityThreshold: number;
|
|
17
|
+
warmPriorityThreshold: number;
|
|
18
|
+
hotDecayThreshold: number;
|
|
19
|
+
hotAccessDays: number;
|
|
20
|
+
warmAccessDays: number;
|
|
21
|
+
hotEdgeCount: number;
|
|
22
|
+
warmEdgeCount: number;
|
|
23
|
+
tagStaleDays: number;
|
|
24
|
+
hotWarmSummarySentences: number;
|
|
25
|
+
archiveSummarySentences: number;
|
|
26
|
+
enableTagging: boolean;
|
|
27
|
+
enableRewriting: boolean;
|
|
28
|
+
enableEntityHygiene: boolean;
|
|
29
|
+
maxMergesPerRun: number;
|
|
30
|
+
hygieneConfidenceThreshold: number;
|
|
31
|
+
pruneMinAgeDays: number;
|
|
32
|
+
enableConsolidation: boolean;
|
|
33
|
+
consolidationTitleThreshold: number;
|
|
34
|
+
repetitiveDecayMultiplier: number;
|
|
35
|
+
enableObservations: boolean;
|
|
36
|
+
maxObservationsPerRun: number;
|
|
37
|
+
enableFactExtraction: boolean;
|
|
38
|
+
maxFactsPerRun: number;
|
|
39
|
+
enableContradictionDetection: boolean;
|
|
40
|
+
maxContradictionChecksPerRun: number;
|
|
41
|
+
enableUserProfile: boolean;
|
|
42
|
+
profileRefreshMinutes: number;
|
|
43
|
+
enableReasoning: boolean;
|
|
44
|
+
maxReasoningPerRun: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_CONFIG: SleepConfig;
|
|
47
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/sleep/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAE5B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAE3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IAEjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAE1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IAEtB,YAAY,EAAE,MAAM,CAAC;IAErB,uBAAuB,EAAE,MAAM,CAAC;IAChC,uBAAuB,EAAE,MAAM,CAAC;IAEhC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IAEzB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,0BAA0B,EAAE,MAAM,CAAC;IACnC,eAAe,EAAE,MAAM,CAAC;IAExB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,2BAA2B,EAAE,MAAM,CAAC;IACpC,yBAAyB,EAAE,MAAM,CAAC;IAElC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAE9B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;IAEvB,4BAA4B,EAAE,OAAO,CAAC;IACtC,4BAA4B,EAAE,MAAM,CAAC;IAErC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;IAE9B,eAAe,EAAE,OAAO,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,cAAc,EAAE,WAsD5B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep config — port of KAD's sleep/config.ts (verbatim per ADR-0003).
|
|
3
|
+
* All constants are locked at parity (CANONICAL.md §2 "Sleep cadence + default config").
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_CONFIG = {
|
|
6
|
+
intervalMinutes: 60,
|
|
7
|
+
initialDelayMinutes: 5,
|
|
8
|
+
batchSize: 50,
|
|
9
|
+
maxTagsPerRun: 5,
|
|
10
|
+
maxLinksPerRun: 100,
|
|
11
|
+
maxSummariesPerRun: 5,
|
|
12
|
+
decayRatePerHour: 0.002,
|
|
13
|
+
maxDecay: 1.0,
|
|
14
|
+
minConfidenceForLink: 0.15,
|
|
15
|
+
maxEdgesPerMemory: 5,
|
|
16
|
+
hotPriorityThreshold: 0.65,
|
|
17
|
+
warmPriorityThreshold: 0.3,
|
|
18
|
+
hotDecayThreshold: 0.25,
|
|
19
|
+
hotAccessDays: 3,
|
|
20
|
+
warmAccessDays: 21,
|
|
21
|
+
hotEdgeCount: 6,
|
|
22
|
+
warmEdgeCount: 3,
|
|
23
|
+
tagStaleDays: 7,
|
|
24
|
+
hotWarmSummarySentences: 5,
|
|
25
|
+
archiveSummarySentences: 3,
|
|
26
|
+
enableTagging: true,
|
|
27
|
+
enableRewriting: false,
|
|
28
|
+
enableEntityHygiene: true,
|
|
29
|
+
maxMergesPerRun: 10,
|
|
30
|
+
hygieneConfidenceThreshold: 0.8,
|
|
31
|
+
pruneMinAgeDays: 30,
|
|
32
|
+
enableConsolidation: true,
|
|
33
|
+
consolidationTitleThreshold: 3,
|
|
34
|
+
repetitiveDecayMultiplier: 3.0,
|
|
35
|
+
enableObservations: true,
|
|
36
|
+
maxObservationsPerRun: 10,
|
|
37
|
+
enableFactExtraction: true,
|
|
38
|
+
maxFactsPerRun: 5,
|
|
39
|
+
enableContradictionDetection: true,
|
|
40
|
+
maxContradictionChecksPerRun: 5,
|
|
41
|
+
enableUserProfile: true,
|
|
42
|
+
profileRefreshMinutes: 60,
|
|
43
|
+
enableReasoning: true,
|
|
44
|
+
maxReasoningPerRun: 5,
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=config.js.map
|