@soleri/core 8.1.0 → 9.0.1

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 (143) hide show
  1. package/dist/brain/brain.d.ts +1 -8
  2. package/dist/brain/brain.d.ts.map +1 -1
  3. package/dist/brain/brain.js +5 -134
  4. package/dist/brain/brain.js.map +1 -1
  5. package/dist/cognee/client.d.ts +5 -0
  6. package/dist/cognee/client.d.ts.map +1 -1
  7. package/dist/cognee/client.js +83 -16
  8. package/dist/cognee/client.js.map +1 -1
  9. package/dist/cognee/sync-manager.d.ts +67 -8
  10. package/dist/cognee/sync-manager.d.ts.map +1 -1
  11. package/dist/cognee/sync-manager.js +129 -32
  12. package/dist/cognee/sync-manager.js.map +1 -1
  13. package/dist/cognee/types.d.ts +16 -0
  14. package/dist/cognee/types.d.ts.map +1 -1
  15. package/dist/context/context-engine.d.ts +2 -5
  16. package/dist/context/context-engine.d.ts.map +1 -1
  17. package/dist/context/context-engine.js +4 -31
  18. package/dist/context/context-engine.js.map +1 -1
  19. package/dist/curator/curator.d.ts +2 -5
  20. package/dist/curator/curator.d.ts.map +1 -1
  21. package/dist/curator/curator.js +4 -23
  22. package/dist/curator/curator.js.map +1 -1
  23. package/dist/engine/bin/soleri-engine.js +6 -5
  24. package/dist/engine/bin/soleri-engine.js.map +1 -1
  25. package/dist/engine/core-ops.d.ts.map +1 -1
  26. package/dist/engine/core-ops.js +11 -6
  27. package/dist/engine/core-ops.js.map +1 -1
  28. package/dist/engine/module-manifest.d.ts +1 -1
  29. package/dist/engine/module-manifest.d.ts.map +1 -1
  30. package/dist/engine/module-manifest.js +1 -7
  31. package/dist/engine/module-manifest.js.map +1 -1
  32. package/dist/engine/register-engine.d.ts.map +1 -1
  33. package/dist/engine/register-engine.js +0 -7
  34. package/dist/engine/register-engine.js.map +1 -1
  35. package/dist/index.d.ts +5 -5
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +3 -4
  38. package/dist/index.js.map +1 -1
  39. package/dist/intelligence/types.d.ts +7 -0
  40. package/dist/intelligence/types.d.ts.map +1 -1
  41. package/dist/persona/defaults.d.ts +16 -0
  42. package/dist/persona/defaults.d.ts.map +1 -0
  43. package/dist/persona/defaults.js +78 -0
  44. package/dist/persona/defaults.js.map +1 -0
  45. package/dist/persona/index.d.ts +5 -0
  46. package/dist/persona/index.d.ts.map +1 -0
  47. package/dist/persona/index.js +4 -0
  48. package/dist/persona/index.js.map +1 -0
  49. package/dist/persona/loader.d.ts +11 -0
  50. package/dist/persona/loader.d.ts.map +1 -0
  51. package/dist/persona/loader.js +45 -0
  52. package/dist/persona/loader.js.map +1 -0
  53. package/dist/persona/prompt-generator.d.ts +13 -0
  54. package/dist/persona/prompt-generator.d.ts.map +1 -0
  55. package/dist/persona/prompt-generator.js +89 -0
  56. package/dist/persona/prompt-generator.js.map +1 -0
  57. package/dist/persona/types.d.ts +56 -0
  58. package/dist/persona/types.d.ts.map +1 -0
  59. package/dist/persona/types.js +9 -0
  60. package/dist/persona/types.js.map +1 -0
  61. package/dist/plugins/types.d.ts +13 -13
  62. package/dist/runtime/admin-extra-ops.d.ts.map +1 -1
  63. package/dist/runtime/admin-extra-ops.js +5 -27
  64. package/dist/runtime/admin-extra-ops.js.map +1 -1
  65. package/dist/runtime/admin-ops.d.ts.map +1 -1
  66. package/dist/runtime/admin-ops.js +5 -37
  67. package/dist/runtime/admin-ops.js.map +1 -1
  68. package/dist/runtime/capture-ops.d.ts.map +1 -1
  69. package/dist/runtime/capture-ops.js +32 -16
  70. package/dist/runtime/capture-ops.js.map +1 -1
  71. package/dist/runtime/cognee-sync-ops.d.ts +2 -2
  72. package/dist/runtime/cognee-sync-ops.d.ts.map +1 -1
  73. package/dist/runtime/cognee-sync-ops.js +45 -7
  74. package/dist/runtime/cognee-sync-ops.js.map +1 -1
  75. package/dist/runtime/facades/index.d.ts +1 -1
  76. package/dist/runtime/facades/index.d.ts.map +1 -1
  77. package/dist/runtime/facades/index.js +1 -10
  78. package/dist/runtime/facades/index.js.map +1 -1
  79. package/dist/runtime/runtime.d.ts.map +1 -1
  80. package/dist/runtime/runtime.js +14 -53
  81. package/dist/runtime/runtime.js.map +1 -1
  82. package/dist/runtime/types.d.ts +6 -8
  83. package/dist/runtime/types.d.ts.map +1 -1
  84. package/dist/runtime/vault-linking-ops.d.ts.map +1 -1
  85. package/dist/runtime/vault-linking-ops.js +40 -0
  86. package/dist/runtime/vault-linking-ops.js.map +1 -1
  87. package/dist/runtime/vault-sharing-ops.d.ts.map +1 -1
  88. package/dist/runtime/vault-sharing-ops.js +53 -3
  89. package/dist/runtime/vault-sharing-ops.js.map +1 -1
  90. package/dist/vault/linking.d.ts +37 -0
  91. package/dist/vault/linking.d.ts.map +1 -1
  92. package/dist/vault/linking.js +73 -0
  93. package/dist/vault/linking.js.map +1 -1
  94. package/dist/vault/vault.d.ts +0 -2
  95. package/dist/vault/vault.d.ts.map +1 -1
  96. package/dist/vault/vault.js +0 -13
  97. package/dist/vault/vault.js.map +1 -1
  98. package/package.json +1 -1
  99. package/src/__tests__/admin-extra-ops.test.ts +0 -3
  100. package/src/__tests__/admin-ops.test.ts +1 -5
  101. package/src/__tests__/brain.test.ts +1 -225
  102. package/src/__tests__/context-engine.test.ts +1 -6
  103. package/src/__tests__/core-ops.test.ts +1 -8
  104. package/src/__tests__/curator-extra-ops.test.ts +0 -2
  105. package/src/__tests__/curator-pipeline-e2e.test.ts +3 -28
  106. package/src/__tests__/feature-flags.test.ts +0 -1
  107. package/src/__tests__/health-registry.test.ts +18 -18
  108. package/src/__tests__/replayable-stream.test.ts +3 -3
  109. package/src/brain/brain.ts +4 -157
  110. package/src/context/context-engine.ts +3 -31
  111. package/src/curator/curator.ts +5 -28
  112. package/src/engine/bin/soleri-engine.ts +6 -5
  113. package/src/engine/core-ops.ts +11 -6
  114. package/src/engine/module-manifest.ts +1 -7
  115. package/src/engine/register-engine.ts +0 -7
  116. package/src/index.ts +20 -16
  117. package/src/intelligence/types.ts +8 -0
  118. package/src/persona/defaults.ts +96 -0
  119. package/src/persona/index.ts +9 -0
  120. package/src/persona/loader.ts +50 -0
  121. package/src/persona/prompt-generator.ts +109 -0
  122. package/src/persona/types.ts +72 -0
  123. package/src/runtime/admin-extra-ops.ts +5 -28
  124. package/src/runtime/admin-ops.ts +5 -38
  125. package/src/runtime/capture-ops.ts +33 -14
  126. package/src/runtime/facades/index.ts +1 -11
  127. package/src/runtime/runtime.ts +14 -54
  128. package/src/runtime/types.ts +6 -8
  129. package/src/runtime/vault-linking-ops.ts +41 -0
  130. package/src/runtime/vault-sharing-ops.ts +63 -4
  131. package/src/vault/linking.ts +94 -0
  132. package/src/vault/vault.ts +0 -14
  133. package/src/__tests__/cognee-client-gaps.test.ts +0 -474
  134. package/src/__tests__/cognee-client.test.ts +0 -524
  135. package/src/__tests__/cognee-hybrid-search.test.ts +0 -492
  136. package/src/__tests__/cognee-integration.test.ts +0 -80
  137. package/src/__tests__/cognee-sync-manager-deep.test.ts +0 -654
  138. package/src/__tests__/cognee-sync-manager.test.ts +0 -104
  139. package/src/cognee/client.ts +0 -370
  140. package/src/cognee/sync-manager.ts +0 -389
  141. package/src/cognee/types.ts +0 -62
  142. package/src/runtime/cognee-sync-ops.ts +0 -63
  143. package/src/runtime/facades/cognee-facade.ts +0 -164
@@ -1,389 +0,0 @@
1
- /**
2
- * CogneeSyncManager — queued, resilient sync between the Vault SQLite DB and Cognee.
3
- *
4
- * Maintains a persistent queue (`cognee_sync_queue`) so that ingestions, updates,
5
- * and deletions survive process restarts. Drain is idempotent and retry-safe.
6
- * Health-flip detection auto-drains when Cognee comes back online.
7
- *
8
- * Ported from Salvador MCP's battle-tested cognee-sync module.
9
- */
10
-
11
- import { createHash } from 'node:crypto';
12
- import type { PersistenceProvider } from '../persistence/types.js';
13
- import type { CogneeClient } from './client.js';
14
- import type { IntelligenceEntry } from '../intelligence/types.js';
15
-
16
- // ─── Types ──────────────────────────────────────────────────────────
17
-
18
- export type SyncOp = 'ingest' | 'update' | 'delete';
19
- export type SyncStatus = 'pending' | 'processing' | 'completed' | 'failed';
20
-
21
- export interface SyncQueueItem {
22
- id: number;
23
- op: SyncOp;
24
- entryId: string;
25
- dataset: string;
26
- contentHash: string | null;
27
- status: SyncStatus;
28
- attempts: number;
29
- error: string | null;
30
- createdAt: number;
31
- processedAt: number | null;
32
- }
33
-
34
- export interface SyncManagerStats {
35
- pending: number;
36
- processing: number;
37
- completed: number;
38
- failed: number;
39
- queueSize: number;
40
- lastDrainAt: number | null;
41
- }
42
-
43
- // ─── Constants ──────────────────────────────────────────────────────
44
-
45
- const MAX_BATCH = 10;
46
- const MAX_RETRIES = 3;
47
-
48
- // ─── CogneeSyncManager ─────────────────────────────────────────────
49
-
50
- export class CogneeSyncManager {
51
- private db: PersistenceProvider;
52
- private cognee: CogneeClient;
53
- private dataset: string;
54
- private lastDrainAt: number | null = null;
55
- private drainTimer: ReturnType<typeof setInterval> | null = null;
56
- private wasAvailable: boolean = false;
57
-
58
- constructor(db: PersistenceProvider, cognee: CogneeClient, dataset: string) {
59
- this.db = db;
60
- this.cognee = cognee;
61
- this.dataset = dataset;
62
- this.initSchema();
63
- this.wasAvailable = cognee.isAvailable;
64
- }
65
-
66
- // ─── Schema ────────────────────────────────────────────────────
67
-
68
- private initSchema(): void {
69
- this.db.execSql(`
70
- CREATE TABLE IF NOT EXISTS cognee_sync_queue (
71
- id INTEGER PRIMARY KEY AUTOINCREMENT,
72
- op TEXT NOT NULL,
73
- entry_id TEXT NOT NULL,
74
- dataset TEXT NOT NULL,
75
- content_hash TEXT,
76
- status TEXT NOT NULL DEFAULT 'pending',
77
- attempts INTEGER NOT NULL DEFAULT 0,
78
- error TEXT,
79
- created_at INTEGER NOT NULL DEFAULT (unixepoch()),
80
- processed_at INTEGER
81
- )
82
- `);
83
-
84
- // Add cognee_ingested_hash column to entries table for reconciliation.
85
- // ALTER TABLE ... ADD COLUMN is a no-op error when the column already exists.
86
- try {
87
- this.db.run('ALTER TABLE entries ADD COLUMN cognee_ingested_hash TEXT');
88
- } catch {
89
- // Column already exists — expected on subsequent runs.
90
- }
91
- }
92
-
93
- // ─── Content hashing ──────────────────────────────────────────
94
-
95
- /**
96
- * SHA-256 of the serialized entry fields, truncated to 16 hex characters.
97
- * Deterministic for identical content — used to detect drift.
98
- */
99
- static contentHash(entry: IntelligenceEntry): string {
100
- const payload = JSON.stringify({
101
- id: entry.id,
102
- type: entry.type,
103
- domain: entry.domain,
104
- title: entry.title,
105
- severity: entry.severity,
106
- description: entry.description,
107
- context: entry.context ?? null,
108
- example: entry.example ?? null,
109
- counterExample: entry.counterExample ?? null,
110
- why: entry.why ?? null,
111
- tags: entry.tags,
112
- appliesTo: entry.appliesTo ?? [],
113
- });
114
- return createHash('sha256').update(payload).digest('hex').slice(0, 16);
115
- }
116
-
117
- // ─── Enqueue ──────────────────────────────────────────────────
118
-
119
- /**
120
- * Add an operation to the sync queue.
121
- *
122
- * @param op The operation type (ingest | update | delete).
123
- * @param entryId The vault entry ID.
124
- * @param entry Optional entry for hash computation. If omitted, hash is null.
125
- */
126
- enqueue(op: SyncOp, entryId: string, entry?: IntelligenceEntry): void {
127
- const contentHash = entry ? CogneeSyncManager.contentHash(entry) : null;
128
- this.db.run(
129
- `INSERT INTO cognee_sync_queue (op, entry_id, dataset, content_hash)
130
- VALUES (@op, @entryId, @dataset, @contentHash)`,
131
- {
132
- op,
133
- entryId,
134
- dataset: this.dataset,
135
- contentHash,
136
- },
137
- );
138
- }
139
-
140
- // ─── Drain ────────────────────────────────────────────────────
141
-
142
- /**
143
- * Process up to MAX_BATCH pending items from the queue.
144
- * Returns the number of items successfully processed.
145
- *
146
- * If Cognee is not available, returns 0 without touching the queue.
147
- */
148
- async drain(): Promise<number> {
149
- if (!this.cognee.isAvailable) return 0;
150
-
151
- // Claim a batch: move pending → processing
152
- const items = this.db.all<Record<string, unknown>>(
153
- `SELECT * FROM cognee_sync_queue
154
- WHERE status = 'pending' AND dataset = @dataset
155
- ORDER BY created_at ASC
156
- LIMIT @limit`,
157
- { dataset: this.dataset, limit: MAX_BATCH },
158
- );
159
-
160
- if (items.length === 0) return 0;
161
-
162
- let processed = 0;
163
-
164
- for (const raw of items) {
165
- const item = rowToQueueItem(raw);
166
-
167
- // Mark as processing
168
- this.db.run(
169
- `UPDATE cognee_sync_queue SET status = 'processing', attempts = attempts + 1 WHERE id = @id`,
170
- { id: item.id },
171
- );
172
-
173
- try {
174
- if (item.op === 'ingest' || item.op === 'update') {
175
- const entry = this.readEntry(item.entryId);
176
- if (!entry) {
177
- // Entry was deleted from vault before we could sync — mark completed
178
- this.markCompleted(item.id);
179
- processed++;
180
- continue;
181
- }
182
-
183
- const result = await this.cognee.addEntries([entry]);
184
- if (result.added === 0) {
185
- throw new Error('Cognee addEntries returned 0 added');
186
- }
187
-
188
- // Update the ingested hash on the entries table
189
- const hash = CogneeSyncManager.contentHash(entry);
190
- this.db.run(`UPDATE entries SET cognee_ingested_hash = @hash WHERE id = @id`, {
191
- hash,
192
- id: item.entryId,
193
- });
194
-
195
- this.markCompleted(item.id);
196
- processed++;
197
- } else if (item.op === 'delete') {
198
- // deleteEntries may not exist yet — graceful degradation
199
- const client = this.cognee as unknown as Record<string, unknown>;
200
- if (typeof client.deleteEntries === 'function') {
201
- await (client.deleteEntries as (ids: string[]) => Promise<unknown>)([item.entryId]);
202
- }
203
- // Clear the ingested hash (entry may already be gone from entries table)
204
- this.db.run(`UPDATE entries SET cognee_ingested_hash = NULL WHERE id = @id`, {
205
- id: item.entryId,
206
- });
207
- this.markCompleted(item.id);
208
- processed++;
209
- }
210
- } catch (err) {
211
- const errorMsg = err instanceof Error ? err.message : String(err);
212
- const attempts = item.attempts + 1; // Already incremented above
213
- if (attempts >= MAX_RETRIES) {
214
- this.db.run(
215
- `UPDATE cognee_sync_queue SET status = 'failed', error = @error, processed_at = unixepoch() WHERE id = @id`,
216
- { id: item.id, error: errorMsg },
217
- );
218
- } else {
219
- // Back to pending for retry
220
- this.db.run(
221
- `UPDATE cognee_sync_queue SET status = 'pending', error = @error WHERE id = @id`,
222
- { id: item.id, error: errorMsg },
223
- );
224
- }
225
- }
226
- }
227
-
228
- this.lastDrainAt = Math.floor(Date.now() / 1000);
229
- return processed;
230
- }
231
-
232
- // ─── Reconciliation ───────────────────────────────────────────
233
-
234
- /**
235
- * Find entries whose cognee_ingested_hash is NULL or doesn't match the
236
- * current content hash. Enqueue dirty entries for re-ingestion.
237
- *
238
- * Returns the number of entries enqueued.
239
- */
240
- reconcile(): number {
241
- // Get all entries that either have never been ingested or whose content changed
242
- const rows = this.db.all<Record<string, unknown>>(
243
- `SELECT * FROM entries WHERE cognee_ingested_hash IS NULL
244
- UNION ALL
245
- SELECT * FROM entries WHERE cognee_ingested_hash IS NOT NULL`,
246
- );
247
-
248
- let enqueued = 0;
249
-
250
- for (const raw of rows) {
251
- const entry = this.rowToEntry(raw);
252
- const currentHash = CogneeSyncManager.contentHash(entry);
253
- const ingestedHash = raw.cognee_ingested_hash as string | null;
254
-
255
- if (ingestedHash === currentHash) continue;
256
-
257
- // Determine op: null hash means never ingested, mismatched means update
258
- const op: SyncOp = ingestedHash === null ? 'ingest' : 'update';
259
-
260
- // Avoid duplicate pending items for the same entry
261
- const existing = this.db.get<{ id: number }>(
262
- `SELECT id FROM cognee_sync_queue
263
- WHERE entry_id = @entryId AND dataset = @dataset AND status = 'pending'`,
264
- { entryId: entry.id, dataset: this.dataset },
265
- );
266
-
267
- if (!existing) {
268
- this.enqueue(op, entry.id, entry);
269
- enqueued++;
270
- }
271
- }
272
-
273
- return enqueued;
274
- }
275
-
276
- // ─── Stats ────────────────────────────────────────────────────
277
-
278
- getStats(): SyncManagerStats {
279
- const countByStatus = (status: SyncStatus): number => {
280
- const row = this.db.get<{ count: number }>(
281
- `SELECT COUNT(*) as count FROM cognee_sync_queue WHERE status = @status AND dataset = @dataset`,
282
- { status, dataset: this.dataset },
283
- );
284
- return row?.count ?? 0;
285
- };
286
-
287
- const pending = countByStatus('pending');
288
- const processing = countByStatus('processing');
289
- const completed = countByStatus('completed');
290
- const failed = countByStatus('failed');
291
-
292
- return {
293
- pending,
294
- processing,
295
- completed,
296
- failed,
297
- queueSize: pending + processing,
298
- lastDrainAt: this.lastDrainAt,
299
- };
300
- }
301
-
302
- // ─── Health-flip detection ────────────────────────────────────
303
-
304
- /**
305
- * Detects an unavailable-to-available transition on the Cognee client.
306
- * When Cognee comes back online, automatically triggers a drain.
307
- *
308
- * Call this periodically (e.g. after each health check).
309
- */
310
- async checkHealthFlip(): Promise<void> {
311
- const nowAvailable = this.cognee.isAvailable;
312
- if (nowAvailable && !this.wasAvailable) {
313
- // Cognee just came back online — drain the queue
314
- await this.drain();
315
- }
316
- this.wasAvailable = nowAvailable;
317
- }
318
-
319
- // ─── Cleanup ──────────────────────────────────────────────────
320
-
321
- /**
322
- * Clear any periodic drain timer.
323
- */
324
- close(): void {
325
- if (this.drainTimer) {
326
- clearInterval(this.drainTimer);
327
- this.drainTimer = null;
328
- }
329
- }
330
-
331
- // ─── Private helpers ──────────────────────────────────────────
332
-
333
- private markCompleted(id: number): void {
334
- this.db.run(
335
- `UPDATE cognee_sync_queue SET status = 'completed', processed_at = unixepoch() WHERE id = @id`,
336
- { id },
337
- );
338
- }
339
-
340
- /**
341
- * Read an entry from the entries table by ID.
342
- * Returns null if the entry doesn't exist.
343
- */
344
- private readEntry(id: string): IntelligenceEntry | null {
345
- const row = this.db.get<Record<string, unknown>>('SELECT * FROM entries WHERE id = @id', {
346
- id,
347
- });
348
- return row ? this.rowToEntry(row) : null;
349
- }
350
-
351
- /**
352
- * Convert a raw DB row into an IntelligenceEntry.
353
- */
354
- private rowToEntry(row: Record<string, unknown>): IntelligenceEntry {
355
- return {
356
- id: row.id as string,
357
- type: row.type as IntelligenceEntry['type'],
358
- domain: row.domain as string,
359
- title: row.title as string,
360
- severity: row.severity as IntelligenceEntry['severity'],
361
- description: row.description as string,
362
- context: (row.context as string) ?? undefined,
363
- example: (row.example as string) ?? undefined,
364
- counterExample: (row.counter_example as string) ?? undefined,
365
- why: (row.why as string) ?? undefined,
366
- tags: JSON.parse((row.tags as string) || '[]'),
367
- appliesTo: JSON.parse((row.applies_to as string) || '[]'),
368
- validFrom: (row.valid_from as number) ?? undefined,
369
- validUntil: (row.valid_until as number) ?? undefined,
370
- };
371
- }
372
- }
373
-
374
- // ─── Module-level helpers ─────────────────────────────────────────
375
-
376
- function rowToQueueItem(row: Record<string, unknown>): SyncQueueItem {
377
- return {
378
- id: row.id as number,
379
- op: row.op as SyncOp,
380
- entryId: row.entry_id as string,
381
- dataset: row.dataset as string,
382
- contentHash: (row.content_hash as string) ?? null,
383
- status: row.status as SyncStatus,
384
- attempts: row.attempts as number,
385
- error: (row.error as string) ?? null,
386
- createdAt: row.created_at as number,
387
- processedAt: (row.processed_at as number) ?? null,
388
- };
389
- }
@@ -1,62 +0,0 @@
1
- // ─── Cognee Integration Types ──────────────────────────────────────
2
-
3
- export interface CogneeConfig {
4
- /** Base URL of the Cognee API (default: http://localhost:8000) */
5
- baseUrl: string;
6
- /** Dataset name for this agent's vault entries */
7
- dataset: string;
8
- /** Bearer token for Cognee API authentication (auto-acquired if not set) */
9
- apiToken?: string;
10
- /** Service account email for auto-login (default: soleri-agent@cognee.dev) */
11
- serviceEmail?: string;
12
- /** Service account password for auto-login */
13
- servicePassword?: string;
14
- /** Default request timeout in milliseconds (default: 30000) */
15
- timeoutMs: number;
16
- /** Search timeout in milliseconds — Ollama cold start can take 90s (default: 120000) */
17
- searchTimeoutMs: number;
18
- /** Health check timeout in milliseconds (default: 5000) */
19
- healthTimeoutMs: number;
20
- /** Health check cache TTL in milliseconds (default: 60000) */
21
- healthCacheTtlMs: number;
22
- /** Cognify debounce window in milliseconds (default: 30000) */
23
- cognifyDebounceMs: number;
24
- }
25
-
26
- export interface CogneeSearchResult {
27
- /** Vault entry ID (cross-reference key) */
28
- id: string;
29
- /** Relevance score (0–1). Position-based when Cognee omits scores. */
30
- score: number;
31
- /** Text content from Cognee */
32
- text: string;
33
- /** Cognee search type that produced this result */
34
- searchType: CogneeSearchType;
35
- }
36
-
37
- export type CogneeSearchType =
38
- | 'SUMMARIES'
39
- | 'CHUNKS'
40
- | 'RAG_COMPLETION'
41
- | 'TRIPLET_COMPLETION'
42
- | 'GRAPH_COMPLETION'
43
- | 'GRAPH_SUMMARY_COMPLETION'
44
- | 'NATURAL_LANGUAGE'
45
- | 'GRAPH_COMPLETION_COT'
46
- | 'FEELING_LUCKY'
47
- | 'CHUNKS_LEXICAL';
48
-
49
- export interface CogneeStatus {
50
- available: boolean;
51
- url: string;
52
- latencyMs: number;
53
- error?: string;
54
- }
55
-
56
- export interface CogneeAddResult {
57
- added: number;
58
- }
59
-
60
- export interface CogneeCognifyResult {
61
- status: string;
62
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * Cognee sync operations — 3 ops for queue visibility and control.
3
- */
4
-
5
- import { z } from 'zod';
6
- import type { OpDefinition } from '../facades/types.js';
7
- import type { CogneeSyncManager } from '../cognee/sync-manager.js';
8
-
9
- /**
10
- * Create the 3 cognee-sync operations.
11
- *
12
- * The sync manager is optional — when null, all ops return a graceful error.
13
- */
14
- export function createCogneeSyncOps(syncManager: CogneeSyncManager | null): OpDefinition[] {
15
- return [
16
- // ─── Status ──────────────────────────────────────────────────
17
- {
18
- name: 'cognee_sync_status',
19
- description:
20
- 'Get current cognee sync queue stats — pending, processing, completed, failed counts.',
21
- auth: 'read',
22
- schema: z.object({}),
23
- handler: async () => {
24
- if (!syncManager) {
25
- return { error: 'Sync manager not configured' };
26
- }
27
- return syncManager.getStats();
28
- },
29
- },
30
-
31
- // ─── Drain ───────────────────────────────────────────────────
32
- {
33
- name: 'cognee_sync_drain',
34
- description:
35
- 'Process pending items in the cognee sync queue. Returns count of processed items and updated stats.',
36
- auth: 'write',
37
- schema: z.object({}),
38
- handler: async () => {
39
- if (!syncManager) {
40
- return { error: 'Sync manager not configured' };
41
- }
42
- const processed = await syncManager.drain();
43
- return { processed, stats: syncManager.getStats() };
44
- },
45
- },
46
-
47
- // ─── Reconcile ───────────────────────────────────────────────
48
- {
49
- name: 'cognee_sync_reconcile',
50
- description:
51
- 'Find vault entries with stale or missing cognee ingestion and enqueue them for sync.',
52
- auth: 'write',
53
- schema: z.object({}),
54
- handler: async () => {
55
- if (!syncManager) {
56
- return { error: 'Sync manager not configured' };
57
- }
58
- const enqueued = syncManager.reconcile();
59
- return { enqueued, stats: syncManager.getStats() };
60
- },
61
- },
62
- ];
63
- }
@@ -1,164 +0,0 @@
1
- /**
2
- * Cognee facade — knowledge graph ops.
3
- * Cognee search, sync, export, graph stats.
4
- */
5
-
6
- import { z } from 'zod';
7
- import type { OpDefinition } from '../../facades/types.js';
8
- import type { IntelligenceEntry } from '../../intelligence/types.js';
9
- import type { AgentRuntime } from '../types.js';
10
- import type { CogneeSearchType } from '../../cognee/types.js';
11
- import { createCogneeSyncOps } from '../cognee-sync-ops.js';
12
-
13
- export function createCogneeFacadeOps(runtime: AgentRuntime): OpDefinition[] {
14
- // Only called when runtime.cognee is non-null (guarded in createSemanticFacades)
15
- const cognee = runtime.cognee!;
16
- const { vault, syncManager } = runtime;
17
-
18
- return [
19
- // ─── Cognee (inline from core-ops.ts) ───────────────────────
20
- {
21
- name: 'cognee_status',
22
- description:
23
- 'Cognee vector search health — availability, URL, latency. Checks the Cognee API endpoint.',
24
- auth: 'read',
25
- handler: async () => {
26
- return cognee.healthCheck();
27
- },
28
- },
29
- {
30
- name: 'cognee_search',
31
- description:
32
- 'Vector similarity search via Cognee. Complements TF-IDF vault search with semantic understanding.',
33
- auth: 'read',
34
- schema: z.object({
35
- query: z.string(),
36
- searchType: z
37
- .enum([
38
- 'SUMMARIES',
39
- 'CHUNKS',
40
- 'RAG_COMPLETION',
41
- 'TRIPLET_COMPLETION',
42
- 'GRAPH_COMPLETION',
43
- 'GRAPH_SUMMARY_COMPLETION',
44
- 'NATURAL_LANGUAGE',
45
- 'GRAPH_COMPLETION_COT',
46
- 'FEELING_LUCKY',
47
- 'CHUNKS_LEXICAL',
48
- ])
49
- .optional()
50
- .describe('Cognee search type. Default CHUNKS (pure vector similarity).'),
51
- limit: z.number().optional(),
52
- }),
53
- handler: async (params) => {
54
- return cognee.search(params.query as string, {
55
- searchType: params.searchType as CogneeSearchType | undefined,
56
- limit: (params.limit as number) ?? 10,
57
- });
58
- },
59
- },
60
- {
61
- name: 'cognee_add',
62
- description:
63
- 'Ingest vault entries into Cognee for vector indexing. Auto-schedules cognify after ingest.',
64
- auth: 'write',
65
- schema: z.object({
66
- entryIds: z.array(z.string()).describe('Vault entry IDs to ingest into Cognee.'),
67
- }),
68
- handler: async (params) => {
69
- const ids = params.entryIds as string[];
70
- const entries = ids
71
- .map((id) => vault.get(id))
72
- .filter((e): e is IntelligenceEntry => e !== null && e !== undefined);
73
- if (entries.length === 0) return { added: 0, error: 'No matching vault entries found' };
74
- return cognee.addEntries(entries);
75
- },
76
- },
77
- {
78
- name: 'cognee_cognify',
79
- description:
80
- 'Trigger Cognee knowledge graph processing on the vault dataset. Usually auto-scheduled after add.',
81
- auth: 'write',
82
- handler: async () => {
83
- return cognee.cognify();
84
- },
85
- },
86
- {
87
- name: 'cognee_config',
88
- description: 'Get current Cognee client configuration and cached health status.',
89
- auth: 'read',
90
- handler: async () => {
91
- return { config: cognee.getConfig(), cachedStatus: cognee.getStatus() };
92
- },
93
- },
94
- // ─── Cognee Graph ────────────────────────────────────────────
95
- {
96
- name: 'cognee_get_node',
97
- description: 'Get a specific Cognee graph node by UUID with all properties and connections.',
98
- auth: 'read',
99
- schema: z.object({
100
- nodeId: z.string().describe('UUID of the graph node'),
101
- }),
102
- handler: async (params) => {
103
- try {
104
- const results = await cognee.search(params.nodeId as string, {
105
- searchType: 'GRAPH_COMPLETION' as CogneeSearchType,
106
- limit: 1,
107
- });
108
- if (!results || (Array.isArray(results) && results.length === 0)) {
109
- return { found: false, nodeId: params.nodeId };
110
- }
111
- return {
112
- found: true,
113
- nodeId: params.nodeId,
114
- node: Array.isArray(results) ? results[0] : results,
115
- };
116
- } catch (err) {
117
- return { error: (err as Error).message };
118
- }
119
- },
120
- },
121
- {
122
- name: 'cognee_graph_stats',
123
- description:
124
- 'Cognee graph statistics — availability, endpoint, latency from last health check.',
125
- auth: 'read',
126
- handler: async () => {
127
- try {
128
- const status = cognee.getStatus();
129
- const health = await cognee.healthCheck();
130
- return {
131
- available: status?.available ?? false,
132
- url: status?.url ?? cognee.getConfig().baseUrl,
133
- latencyMs: status?.latencyMs ?? health.latencyMs ?? null,
134
- error: status?.error ?? health.error ?? null,
135
- };
136
- } catch (err) {
137
- return { error: (err as Error).message };
138
- }
139
- },
140
- },
141
- {
142
- name: 'cognee_export_status',
143
- description: 'Check Cognee dataset and processing status — availability, pending operations.',
144
- auth: 'read',
145
- handler: async () => {
146
- try {
147
- const status = cognee.getStatus();
148
- const config = cognee.getConfig();
149
- return {
150
- available: status?.available ?? false,
151
- dataset: config.dataset ?? 'default',
152
- pendingCognify: false,
153
- url: status?.url ?? config.baseUrl,
154
- };
155
- } catch (err) {
156
- return { error: (err as Error).message };
157
- }
158
- },
159
- },
160
-
161
- // ─── Satellite ops ───────────────────────────────────────────
162
- ...createCogneeSyncOps(syncManager),
163
- ];
164
- }