@soleri/core 8.0.0 → 9.0.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/brain/brain.d.ts +1 -8
- package/dist/brain/brain.d.ts.map +1 -1
- package/dist/brain/brain.js +5 -134
- package/dist/brain/brain.js.map +1 -1
- package/dist/brain/knowledge-synthesizer.d.ts.map +1 -1
- package/dist/brain/knowledge-synthesizer.js +0 -2
- package/dist/brain/knowledge-synthesizer.js.map +1 -1
- package/dist/cognee/client.d.ts +5 -0
- package/dist/cognee/client.d.ts.map +1 -1
- package/dist/cognee/client.js +83 -16
- package/dist/cognee/client.js.map +1 -1
- package/dist/cognee/sync-manager.d.ts +67 -8
- package/dist/cognee/sync-manager.d.ts.map +1 -1
- package/dist/cognee/sync-manager.js +129 -32
- package/dist/cognee/sync-manager.js.map +1 -1
- package/dist/cognee/types.d.ts +16 -0
- package/dist/cognee/types.d.ts.map +1 -1
- package/dist/context/context-engine.d.ts +2 -5
- package/dist/context/context-engine.d.ts.map +1 -1
- package/dist/context/context-engine.js +4 -31
- package/dist/context/context-engine.js.map +1 -1
- package/dist/curator/classifier.d.ts.map +1 -1
- package/dist/curator/classifier.js +0 -2
- package/dist/curator/classifier.js.map +1 -1
- package/dist/curator/curator.d.ts +2 -5
- package/dist/curator/curator.d.ts.map +1 -1
- package/dist/curator/curator.js +4 -23
- package/dist/curator/curator.js.map +1 -1
- package/dist/curator/quality-gate.d.ts.map +1 -1
- package/dist/curator/quality-gate.js +0 -2
- package/dist/curator/quality-gate.js.map +1 -1
- package/dist/domain-packs/index.d.ts +0 -3
- package/dist/domain-packs/index.d.ts.map +1 -1
- package/dist/domain-packs/index.js +0 -3
- package/dist/domain-packs/index.js.map +1 -1
- package/dist/domain-packs/loader.d.ts.map +1 -1
- package/dist/domain-packs/loader.js +20 -4
- package/dist/domain-packs/loader.js.map +1 -1
- package/dist/domain-packs/pack-runtime.d.ts +5 -5
- package/dist/domain-packs/pack-runtime.d.ts.map +1 -1
- package/dist/domain-packs/pack-runtime.js +2 -2
- package/dist/domain-packs/pack-runtime.js.map +1 -1
- package/dist/domain-packs/types.d.ts +8 -2
- package/dist/domain-packs/types.d.ts.map +1 -1
- package/dist/domain-packs/types.js.map +1 -1
- package/dist/engine/bin/soleri-engine.js +18 -7
- package/dist/engine/bin/soleri-engine.js.map +1 -1
- package/dist/engine/core-ops.d.ts.map +1 -1
- package/dist/engine/core-ops.js +11 -6
- package/dist/engine/core-ops.js.map +1 -1
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +1 -0
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/module-manifest.d.ts +28 -0
- package/dist/engine/module-manifest.d.ts.map +1 -0
- package/dist/engine/module-manifest.js +85 -0
- package/dist/engine/module-manifest.js.map +1 -0
- package/dist/engine/register-engine.d.ts +19 -0
- package/dist/engine/register-engine.d.ts.map +1 -1
- package/dist/engine/register-engine.js +15 -9
- package/dist/engine/register-engine.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/intake/content-classifier.d.ts.map +1 -1
- package/dist/intake/content-classifier.js +0 -2
- package/dist/intake/content-classifier.js.map +1 -1
- package/dist/intelligence/types.d.ts +7 -0
- package/dist/intelligence/types.d.ts.map +1 -1
- package/dist/llm/llm-client.d.ts.map +1 -1
- package/dist/llm/llm-client.js +8 -4
- package/dist/llm/llm-client.js.map +1 -1
- package/dist/llm/oauth-discovery.d.ts +0 -8
- package/dist/llm/oauth-discovery.d.ts.map +1 -1
- package/dist/llm/oauth-discovery.js +0 -19
- package/dist/llm/oauth-discovery.js.map +1 -1
- package/dist/llm/types.d.ts +4 -2
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/packs/pack-installer.d.ts +2 -1
- package/dist/packs/pack-installer.d.ts.map +1 -1
- package/dist/packs/pack-installer.js +10 -1
- package/dist/packs/pack-installer.js.map +1 -1
- package/dist/persistence/index.d.ts +0 -1
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +0 -1
- package/dist/persistence/index.js.map +1 -1
- package/dist/persistence/types.d.ts +2 -6
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/persona/defaults.d.ts +16 -0
- package/dist/persona/defaults.d.ts.map +1 -0
- package/dist/persona/defaults.js +78 -0
- package/dist/persona/defaults.js.map +1 -0
- package/dist/persona/index.d.ts +5 -0
- package/dist/persona/index.d.ts.map +1 -0
- package/dist/persona/index.js +4 -0
- package/dist/persona/index.js.map +1 -0
- package/dist/persona/loader.d.ts +11 -0
- package/dist/persona/loader.d.ts.map +1 -0
- package/dist/persona/loader.js +45 -0
- package/dist/persona/loader.js.map +1 -0
- package/dist/persona/prompt-generator.d.ts +13 -0
- package/dist/persona/prompt-generator.d.ts.map +1 -0
- package/dist/persona/prompt-generator.js +89 -0
- package/dist/persona/prompt-generator.js.map +1 -0
- package/dist/persona/types.d.ts +56 -0
- package/dist/persona/types.d.ts.map +1 -0
- package/dist/persona/types.js +9 -0
- package/dist/persona/types.js.map +1 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin-registry.d.ts +4 -0
- package/dist/plugins/plugin-registry.d.ts.map +1 -1
- package/dist/plugins/plugin-registry.js +4 -0
- package/dist/plugins/plugin-registry.js.map +1 -1
- package/dist/plugins/types.d.ts +36 -31
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +6 -3
- package/dist/plugins/types.js.map +1 -1
- package/dist/runtime/admin-extra-ops.d.ts.map +1 -1
- package/dist/runtime/admin-extra-ops.js +5 -27
- package/dist/runtime/admin-extra-ops.js.map +1 -1
- package/dist/runtime/admin-ops.d.ts.map +1 -1
- package/dist/runtime/admin-ops.js +5 -37
- package/dist/runtime/admin-ops.js.map +1 -1
- package/dist/runtime/capture-ops.d.ts.map +1 -1
- package/dist/runtime/capture-ops.js +32 -16
- package/dist/runtime/capture-ops.js.map +1 -1
- package/dist/runtime/claude-md-helpers.d.ts +0 -9
- package/dist/runtime/claude-md-helpers.d.ts.map +1 -1
- package/dist/runtime/claude-md-helpers.js +1 -14
- package/dist/runtime/claude-md-helpers.js.map +1 -1
- package/dist/runtime/cognee-sync-ops.d.ts +2 -2
- package/dist/runtime/cognee-sync-ops.d.ts.map +1 -1
- package/dist/runtime/cognee-sync-ops.js +45 -7
- package/dist/runtime/cognee-sync-ops.js.map +1 -1
- package/dist/runtime/facades/admin-facade.d.ts.map +1 -1
- package/dist/runtime/facades/admin-facade.js +1 -2
- package/dist/runtime/facades/admin-facade.js.map +1 -1
- package/dist/runtime/facades/index.d.ts +1 -1
- package/dist/runtime/facades/index.d.ts.map +1 -1
- package/dist/runtime/facades/index.js +1 -10
- package/dist/runtime/facades/index.js.map +1 -1
- package/dist/runtime/pack-ops.d.ts +3 -0
- package/dist/runtime/pack-ops.d.ts.map +1 -1
- package/dist/runtime/pack-ops.js +18 -1
- package/dist/runtime/pack-ops.js.map +1 -1
- package/dist/runtime/plugin-ops.d.ts.map +1 -1
- package/dist/runtime/plugin-ops.js +3 -0
- package/dist/runtime/plugin-ops.js.map +1 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +14 -53
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/session-briefing.d.ts.map +1 -1
- package/dist/runtime/session-briefing.js +14 -0
- package/dist/runtime/session-briefing.js.map +1 -1
- package/dist/runtime/types.d.ts +6 -8
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/vault-linking-ops.d.ts.map +1 -1
- package/dist/runtime/vault-linking-ops.js +42 -4
- package/dist/runtime/vault-linking-ops.js.map +1 -1
- package/dist/runtime/vault-sharing-ops.d.ts.map +1 -1
- package/dist/runtime/vault-sharing-ops.js +53 -3
- package/dist/runtime/vault-sharing-ops.js.map +1 -1
- package/dist/vault/linking.d.ts +37 -0
- package/dist/vault/linking.d.ts.map +1 -1
- package/dist/vault/linking.js +73 -0
- package/dist/vault/linking.js.map +1 -1
- package/dist/vault/vault.d.ts +9 -2
- package/dist/vault/vault.d.ts.map +1 -1
- package/dist/vault/vault.js +21 -12
- package/dist/vault/vault.js.map +1 -1
- package/package.json +6 -4
- package/src/__tests__/curator-pipeline-e2e.test.ts +187 -0
- package/src/__tests__/module-manifest-drift.test.ts +59 -0
- package/src/brain/brain.ts +4 -157
- package/src/brain/knowledge-synthesizer.ts +0 -2
- package/src/context/context-engine.ts +3 -31
- package/src/curator/classifier.ts +0 -2
- package/src/curator/curator.ts +5 -28
- package/src/curator/quality-gate.ts +0 -2
- package/src/domain-packs/index.ts +0 -6
- package/src/domain-packs/loader.ts +25 -5
- package/src/domain-packs/pack-runtime.ts +6 -6
- package/src/domain-packs/types.ts +8 -2
- package/src/engine/bin/soleri-engine.ts +23 -7
- package/src/engine/core-ops.ts +11 -6
- package/src/engine/index.ts +2 -0
- package/src/engine/module-manifest.ts +99 -0
- package/src/engine/register-engine.ts +21 -9
- package/src/index.ts +20 -17
- package/src/intake/content-classifier.ts +0 -2
- package/src/intelligence/types.ts +8 -0
- package/src/llm/llm-client.ts +12 -6
- package/src/llm/oauth-discovery.ts +0 -18
- package/src/llm/types.ts +4 -2
- package/src/packs/pack-installer.ts +16 -1
- package/src/persistence/index.ts +0 -1
- package/src/persistence/types.ts +2 -6
- package/src/persona/defaults.ts +96 -0
- package/src/persona/index.ts +9 -0
- package/src/persona/loader.ts +50 -0
- package/src/persona/prompt-generator.ts +109 -0
- package/src/persona/types.ts +72 -0
- package/src/plugins/index.ts +4 -0
- package/src/plugins/plugin-registry.ts +6 -1
- package/src/plugins/types.ts +10 -5
- package/src/runtime/admin-extra-ops.ts +5 -28
- package/src/runtime/admin-ops.ts +5 -38
- package/src/runtime/capture-ops.ts +33 -14
- package/src/runtime/claude-md-helpers.ts +1 -19
- package/src/runtime/facades/admin-facade.ts +1 -2
- package/src/runtime/facades/index.ts +1 -11
- package/src/runtime/pack-ops.ts +26 -1
- package/src/runtime/plugin-ops.ts +3 -0
- package/src/runtime/runtime.ts +14 -54
- package/src/runtime/session-briefing.ts +14 -0
- package/src/runtime/types.ts +6 -8
- package/src/runtime/vault-linking-ops.ts +43 -4
- package/src/runtime/vault-sharing-ops.ts +63 -4
- package/src/vault/linking.ts +94 -0
- package/src/vault/vault.ts +24 -12
- package/src/__tests__/cognee-client-gaps.test.ts +0 -474
- package/src/__tests__/cognee-client.test.ts +0 -524
- package/src/__tests__/cognee-hybrid-search.test.ts +0 -492
- package/src/__tests__/cognee-integration.test.ts +0 -80
- package/src/__tests__/cognee-sync-manager-deep.test.ts +0 -654
- package/src/__tests__/cognee-sync-manager.test.ts +0 -104
- package/src/__tests__/postgres-provider.test.ts +0 -116
- package/src/cognee/client.ts +0 -370
- package/src/cognee/sync-manager.ts +0 -389
- package/src/cognee/types.ts +0 -62
- package/src/health/doctor-checks.ts +0 -115
- package/src/persistence/postgres-provider.ts +0 -310
- package/src/runtime/cognee-sync-ops.ts +0 -63
- 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
|
-
}
|
package/src/cognee/types.ts
DELETED
|
@@ -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,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Doctor Checks — 8 specialized health checks for comprehensive diagnostics.
|
|
3
|
-
*
|
|
4
|
-
* Each check validates a subsystem and reports pass/warn/fail.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { HealthRegistry } from './health-registry.js';
|
|
8
|
-
import type { AgentRuntime } from '../runtime/types.js';
|
|
9
|
-
|
|
10
|
-
export interface DoctorCheckResult {
|
|
11
|
-
check: string;
|
|
12
|
-
status: 'pass' | 'warn' | 'fail';
|
|
13
|
-
message: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function runDoctorChecks(runtime: AgentRuntime): DoctorCheckResult[] {
|
|
17
|
-
const results: DoctorCheckResult[] = [];
|
|
18
|
-
|
|
19
|
-
// 1. Config
|
|
20
|
-
try {
|
|
21
|
-
const id = runtime.config.agentId;
|
|
22
|
-
results.push({
|
|
23
|
-
check: 'config',
|
|
24
|
-
status: id ? 'pass' : 'fail',
|
|
25
|
-
message: id ? `Agent "${id}" configured` : 'No agent ID',
|
|
26
|
-
});
|
|
27
|
-
} catch (e) {
|
|
28
|
-
results.push({ check: 'config', status: 'fail', message: (e as Error).message });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 2. Database
|
|
32
|
-
try {
|
|
33
|
-
runtime.vault.getProvider().get<{ v: number }>('PRAGMA user_version');
|
|
34
|
-
results.push({ check: 'database', status: 'pass', message: 'SQLite healthy' });
|
|
35
|
-
} catch (e) {
|
|
36
|
-
results.push({ check: 'database', status: 'fail', message: (e as Error).message });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// 3. Vault
|
|
40
|
-
try {
|
|
41
|
-
const stats = runtime.vault.stats();
|
|
42
|
-
results.push({
|
|
43
|
-
check: 'vault',
|
|
44
|
-
status: stats.totalEntries > 0 ? 'pass' : 'warn',
|
|
45
|
-
message: stats.totalEntries > 0 ? `${stats.totalEntries} entries` : 'Vault empty',
|
|
46
|
-
});
|
|
47
|
-
} catch (e) {
|
|
48
|
-
results.push({ check: 'vault', status: 'fail', message: (e as Error).message });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 4. LLM
|
|
52
|
-
try {
|
|
53
|
-
const pool = runtime.keyPool;
|
|
54
|
-
const total = (pool.openai?.getActiveKey() ? 1 : 0) + (pool.anthropic?.getActiveKey() ? 1 : 0);
|
|
55
|
-
results.push({
|
|
56
|
-
check: 'llm',
|
|
57
|
-
status: total > 0 ? 'pass' : 'warn',
|
|
58
|
-
message: total > 0 ? `${total} provider(s) available` : 'No API keys — LLM features disabled',
|
|
59
|
-
});
|
|
60
|
-
} catch {
|
|
61
|
-
results.push({ check: 'llm', status: 'warn', message: 'LLM check failed' });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 5. Auth
|
|
65
|
-
results.push({
|
|
66
|
-
check: 'auth',
|
|
67
|
-
status: 'pass',
|
|
68
|
-
message: `Mode: ${runtime.authPolicy.mode}`,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// 6. Plugins
|
|
72
|
-
try {
|
|
73
|
-
const count = runtime.pluginRegistry.list().length;
|
|
74
|
-
results.push({ check: 'plugins', status: 'pass', message: `${count} plugin(s)` });
|
|
75
|
-
} catch {
|
|
76
|
-
results.push({ check: 'plugins', status: 'warn', message: 'Plugin check failed' });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 7. Embeddings (Cognee)
|
|
80
|
-
try {
|
|
81
|
-
const available = runtime.cognee?.isAvailable ?? false;
|
|
82
|
-
results.push({
|
|
83
|
-
check: 'embeddings',
|
|
84
|
-
status: available ? 'pass' : 'warn',
|
|
85
|
-
message: available ? 'Cognee available' : 'Cognee not available — vector search disabled',
|
|
86
|
-
});
|
|
87
|
-
} catch {
|
|
88
|
-
results.push({ check: 'embeddings', status: 'warn', message: 'Embedding check failed' });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 8. Security
|
|
92
|
-
results.push({
|
|
93
|
-
check: 'security',
|
|
94
|
-
status: runtime.authPolicy.mode === 'permissive' ? 'warn' : 'pass',
|
|
95
|
-
message:
|
|
96
|
-
runtime.authPolicy.mode === 'permissive'
|
|
97
|
-
? 'Permissive mode — all ops allowed'
|
|
98
|
-
: `Enforcement: ${runtime.authPolicy.mode}`,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return results;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function registerDoctorChecks(health: HealthRegistry, runtime: AgentRuntime): void {
|
|
105
|
-
const results = runDoctorChecks(runtime);
|
|
106
|
-
for (const r of results) {
|
|
107
|
-
health.register(
|
|
108
|
-
r.check,
|
|
109
|
-
r.status === 'pass' ? 'healthy' : r.status === 'warn' ? 'degraded' : 'down',
|
|
110
|
-
);
|
|
111
|
-
if (r.status !== 'pass') {
|
|
112
|
-
health.update(r.check, r.status === 'warn' ? 'degraded' : 'down', r.message);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|