wyrm-mcp 3.2.0 → 3.3.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.
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Wyrm Intelligence Layer — Ground Truths & Reasoning Scaffolds.
3
+ *
4
+ * Ground Truths: authoritative, versioned project facts that AI models must
5
+ * treat as absolute rather than inferring from context. Eliminates hallucination
6
+ * of stack/architecture/constraint decisions.
7
+ *
8
+ * Reasoning Scaffolds: structured thinking templates for specific task types.
9
+ * Injected into AI context to force step-by-step reasoning on complex tasks —
10
+ * approximating Opus-level structured reasoning in smaller models.
11
+ *
12
+ * @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
13
+ * @license Proprietary - See LICENSE file for details.
14
+ */
15
+ import type Database from 'better-sqlite3';
16
+ export type TruthCategory = 'tech_stack' | 'architecture' | 'constraint' | 'decision' | 'contact' | 'other';
17
+ export interface GroundTruth {
18
+ id: number;
19
+ project_id: number;
20
+ category: TruthCategory;
21
+ key: string;
22
+ value: string;
23
+ rationale: string | null;
24
+ source: string | null;
25
+ is_current: number;
26
+ supersedes_id: number | null;
27
+ confidence: number;
28
+ last_verified_at: string;
29
+ created_at: string;
30
+ updated_at: string;
31
+ }
32
+ export interface SetTruthOptions {
33
+ category: TruthCategory;
34
+ key: string;
35
+ value: string;
36
+ rationale?: string;
37
+ source?: string;
38
+ confidence?: number;
39
+ }
40
+ export declare class GroundTruths {
41
+ private db;
42
+ constructor(db: Database.Database);
43
+ /**
44
+ * Upsert a ground truth for a project. If a current truth with the same key exists,
45
+ * it is superseded and a new current row is inserted (versioned history preserved).
46
+ */
47
+ set(projectId: number, opts: SetTruthOptions): GroundTruth;
48
+ /** Get all current ground truths for a project, optionally filtered by category. */
49
+ getCurrent(projectId: number, category?: TruthCategory): GroundTruth[];
50
+ /** Get the full history for a specific key. */
51
+ getHistory(projectId: number, category: TruthCategory, key: string): GroundTruth[];
52
+ /** Delete the current ground truth for a key (soft delete via is_current=0). */
53
+ revoke(projectId: number, category: TruthCategory, key: string): boolean;
54
+ /**
55
+ * Format current ground truths as a "Project Facts" block for context injection.
56
+ * Applies a character budget to avoid crowding out task-specific context.
57
+ */
58
+ formatForContext(projectId: number, budgetChars?: number): string;
59
+ getStats(projectId: number): {
60
+ current: number;
61
+ superseded: number;
62
+ byCategory: Record<string, number>;
63
+ };
64
+ }
65
+ export interface ReasoningScaffold {
66
+ id: number;
67
+ project_id: number | null;
68
+ problem_type: string;
69
+ description: string | null;
70
+ when_to_use: string | null;
71
+ steps: string;
72
+ verification_steps: string | null;
73
+ do_not_apply_if: string | null;
74
+ tags: string | null;
75
+ usage_count: number;
76
+ success_count: number;
77
+ confidence: number;
78
+ created_at: string;
79
+ updated_at: string;
80
+ }
81
+ export interface SaveScaffoldOptions {
82
+ problemType: string;
83
+ description?: string;
84
+ whenToUse?: string;
85
+ steps: string[];
86
+ verificationSteps?: string[];
87
+ doNotApplyIf?: string[];
88
+ tags?: string[];
89
+ projectId?: number;
90
+ }
91
+ export interface ScaffoldMatch {
92
+ scaffold: ReasoningScaffold;
93
+ matchScore: number;
94
+ }
95
+ export declare class ReasoningScaffolds {
96
+ private db;
97
+ constructor(db: Database.Database);
98
+ save(opts: SaveScaffoldOptions): ReasoningScaffold;
99
+ get(id: number): ReasoningScaffold | null;
100
+ /**
101
+ * Find the best matching scaffold for a given task description.
102
+ * Uses FTS for candidates, then applies confidence weighting.
103
+ * Returns null if no confident match found.
104
+ */
105
+ findBest(task: string, projectId?: number, minConfidence?: number): ScaffoldMatch | null;
106
+ private fallbackSearch;
107
+ recordOutcome(id: number, success: boolean): void;
108
+ list(projectId?: number, limit?: number): ReasoningScaffold[];
109
+ delete(id: number): boolean;
110
+ /**
111
+ * Format a scaffold as a structured context block.
112
+ * Returns a plain checklist (not XML/CoT prompting) for model injection.
113
+ */
114
+ formatForContext(match: ScaffoldMatch, budgetChars?: number): string;
115
+ }
116
+ //# sourceMappingURL=intellig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,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AAOD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAEzC,IAAI,CAAC,IAAI,EAAE,mBAAmB,GAAG,iBAAiB;IAkBlD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAIzC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,aAAa,SAA0B,GAAG,aAAa,GAAG,IAAI;IAwCzG,OAAO,CAAC,cAAc;IAoBtB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAejD,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,iBAAiB,EAAE;IAazD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,aAAa,EAAE,WAAW,SAAwB,GAAG,MAAM;CAkCpF"}
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Wyrm Intelligence Layer — Ground Truths & Reasoning Scaffolds.
3
+ *
4
+ * Ground Truths: authoritative, versioned project facts that AI models must
5
+ * treat as absolute rather than inferring from context. Eliminates hallucination
6
+ * of stack/architecture/constraint decisions.
7
+ *
8
+ * Reasoning Scaffolds: structured thinking templates for specific task types.
9
+ * Injected into AI context to force step-by-step reasoning on complex tasks —
10
+ * approximating Opus-level structured reasoning in smaller models.
11
+ *
12
+ * @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
13
+ * @license Proprietary - See LICENSE file for details.
14
+ */
15
+ /** Max chars for the ground truths block in context_build */
16
+ const TRUTHS_BUDGET_CHARS = 1200;
17
+ export class GroundTruths {
18
+ db;
19
+ constructor(db) {
20
+ this.db = db;
21
+ }
22
+ /**
23
+ * Upsert a ground truth for a project. If a current truth with the same key exists,
24
+ * it is superseded and a new current row is inserted (versioned history preserved).
25
+ */
26
+ set(projectId, opts) {
27
+ const setTruth = this.db.transaction(() => {
28
+ // Find current truth for this key
29
+ const existing = this.db.prepare(`
30
+ SELECT * FROM ground_truths
31
+ WHERE project_id = ? AND category = ? AND key = ? AND is_current = 1
32
+ ORDER BY id DESC LIMIT 1
33
+ `).get(projectId, opts.category, opts.key);
34
+ // Mark the existing one as superseded
35
+ if (existing) {
36
+ this.db.prepare(`UPDATE ground_truths SET is_current = 0, updated_at = datetime('now') WHERE id = ?`).run(existing.id);
37
+ }
38
+ // Insert new current row
39
+ const result = this.db.prepare(`
40
+ INSERT INTO ground_truths (project_id, category, key, value, rationale, source, confidence, supersedes_id)
41
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
42
+ `).run(projectId, opts.category, opts.key.trim(), opts.value.trim(), opts.rationale?.trim() ?? null, opts.source?.trim() ?? null, opts.confidence ?? 1.0, existing?.id ?? null);
43
+ return this.db.prepare('SELECT * FROM ground_truths WHERE id = ?').get(result.lastInsertRowid);
44
+ });
45
+ return setTruth();
46
+ }
47
+ /** Get all current ground truths for a project, optionally filtered by category. */
48
+ getCurrent(projectId, category) {
49
+ if (category) {
50
+ return this.db.prepare(`
51
+ SELECT * FROM ground_truths
52
+ WHERE project_id = ? AND category = ? AND is_current = 1
53
+ ORDER BY category, key
54
+ `).all(projectId, category);
55
+ }
56
+ return this.db.prepare(`
57
+ SELECT * FROM ground_truths
58
+ WHERE project_id = ? AND is_current = 1
59
+ ORDER BY category, key
60
+ `).all(projectId);
61
+ }
62
+ /** Get the full history for a specific key. */
63
+ getHistory(projectId, category, key) {
64
+ return this.db.prepare(`
65
+ SELECT * FROM ground_truths
66
+ WHERE project_id = ? AND category = ? AND key = ?
67
+ ORDER BY id DESC
68
+ `).all(projectId, category, key);
69
+ }
70
+ /** Delete the current ground truth for a key (soft delete via is_current=0). */
71
+ revoke(projectId, category, key) {
72
+ const result = this.db.prepare(`
73
+ UPDATE ground_truths SET is_current = 0, updated_at = datetime('now')
74
+ WHERE project_id = ? AND category = ? AND key = ? AND is_current = 1
75
+ `).run(projectId, category, key);
76
+ return result.changes > 0;
77
+ }
78
+ /**
79
+ * Format current ground truths as a "Project Facts" block for context injection.
80
+ * Applies a character budget to avoid crowding out task-specific context.
81
+ */
82
+ formatForContext(projectId, budgetChars = TRUTHS_BUDGET_CHARS) {
83
+ const truths = this.getCurrent(projectId);
84
+ if (truths.length === 0)
85
+ return '';
86
+ const CATEGORY_LABELS = {
87
+ tech_stack: '🛠️ Tech Stack',
88
+ architecture: '🏗️ Architecture',
89
+ constraint: '🚧 Constraints',
90
+ decision: '📋 Decisions',
91
+ contact: '👤 Contacts',
92
+ other: '📌 Other Facts',
93
+ };
94
+ // Group by category
95
+ const byCategory = new Map();
96
+ for (const t of truths) {
97
+ const existing = byCategory.get(t.category) ?? [];
98
+ existing.push(t);
99
+ byCategory.set(t.category, existing);
100
+ }
101
+ let text = '### 📚 Project Ground Truths _(treat as authoritative — do not infer or contradict)_\n';
102
+ let chars = text.length;
103
+ for (const [category, items] of byCategory) {
104
+ const label = CATEGORY_LABELS[category] ?? category;
105
+ const header = `**${label}:**\n`;
106
+ if (chars + header.length > budgetChars)
107
+ break;
108
+ text += header;
109
+ chars += header.length;
110
+ for (const t of items) {
111
+ const line = `- **${t.key}:** ${t.value}${t.rationale ? ` _(${t.rationale})_` : ''}\n`;
112
+ if (chars + line.length > budgetChars)
113
+ break;
114
+ text += line;
115
+ chars += line.length;
116
+ }
117
+ }
118
+ const truncNote = chars >= budgetChars ? '\n_(truncated — use wyrm_truth_get for full list)_\n' : '';
119
+ return text + truncNote;
120
+ }
121
+ getStats(projectId) {
122
+ const current = this.db.prepare('SELECT COUNT(*) as n FROM ground_truths WHERE project_id = ? AND is_current = 1').get(projectId).n;
123
+ const superseded = this.db.prepare('SELECT COUNT(*) as n FROM ground_truths WHERE project_id = ? AND is_current = 0').get(projectId).n;
124
+ const catRows = this.db.prepare(`
125
+ SELECT category, COUNT(*) as cnt FROM ground_truths
126
+ WHERE project_id = ? AND is_current = 1 GROUP BY category
127
+ `).all(projectId);
128
+ const byCategory = {};
129
+ for (const r of catRows)
130
+ byCategory[r.category] = r.cnt;
131
+ return { current, superseded, byCategory };
132
+ }
133
+ }
134
+ /** Minimum FTS match confidence before injecting a scaffold */
135
+ const MIN_SCAFFOLD_CONFIDENCE = 0.3;
136
+ /** Max chars for scaffold block in context_build */
137
+ const SCAFFOLD_BUDGET_CHARS = 1500;
138
+ export class ReasoningScaffolds {
139
+ db;
140
+ constructor(db) {
141
+ this.db = db;
142
+ }
143
+ save(opts) {
144
+ const result = this.db.prepare(`
145
+ INSERT INTO reasoning_scaffolds
146
+ (project_id, problem_type, description, when_to_use, steps, verification_steps, do_not_apply_if, tags)
147
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
148
+ `).run(opts.projectId ?? null, opts.problemType.trim(), opts.description?.trim() ?? null, opts.whenToUse?.trim() ?? null, JSON.stringify(opts.steps), opts.verificationSteps ? JSON.stringify(opts.verificationSteps) : null, opts.doNotApplyIf ? JSON.stringify(opts.doNotApplyIf) : null, opts.tags?.join(',') ?? null);
149
+ return this.get(result.lastInsertRowid);
150
+ }
151
+ get(id) {
152
+ return this.db.prepare('SELECT * FROM reasoning_scaffolds WHERE id = ?').get(id) ?? null;
153
+ }
154
+ /**
155
+ * Find the best matching scaffold for a given task description.
156
+ * Uses FTS for candidates, then applies confidence weighting.
157
+ * Returns null if no confident match found.
158
+ */
159
+ findBest(task, projectId, minConfidence = MIN_SCAFFOLD_CONFIDENCE) {
160
+ const sanitized = task.replace(/['"*]/g, ' ').trim();
161
+ if (!sanitized)
162
+ return null;
163
+ const projectClause = projectId
164
+ ? 'AND (s.project_id = ? OR s.project_id IS NULL)'
165
+ : 'AND s.project_id IS NULL';
166
+ const params = [sanitized];
167
+ if (projectId)
168
+ params.push(projectId);
169
+ params.push(10);
170
+ let candidates = [];
171
+ try {
172
+ candidates = this.db.prepare(`
173
+ SELECT s.* FROM reasoning_scaffolds s
174
+ JOIN scaffolds_fts fts ON s.id = fts.rowid
175
+ WHERE fts MATCH ?
176
+ ${projectClause}
177
+ ORDER BY rank, s.confidence DESC
178
+ LIMIT ?
179
+ `).all(...params);
180
+ }
181
+ catch {
182
+ // FTS failed — fall back to keyword matching
183
+ candidates = this.fallbackSearch(task, projectId, 5);
184
+ }
185
+ if (candidates.length === 0)
186
+ return null;
187
+ // Score the best candidate
188
+ const best = candidates[0];
189
+ // Adjust score: FTS rank (position 0 = best) × stored confidence
190
+ const positionScore = candidates.length > 1 ? 0.7 : 1.0; // more confident if unambiguous
191
+ const matchScore = positionScore * best.confidence;
192
+ if (matchScore < minConfidence)
193
+ return null;
194
+ return { scaffold: best, matchScore };
195
+ }
196
+ fallbackSearch(task, projectId, limit = 5) {
197
+ const words = task.toLowerCase().split(/\s+/).filter(w => w.length > 3);
198
+ if (!words.length)
199
+ return [];
200
+ const likeOr = words.slice(0, 3).map(() => 'LOWER(problem_type) LIKE ? OR LOWER(tags) LIKE ?').join(' OR ');
201
+ const likeParams = words.slice(0, 3).flatMap(w => [`%${w}%`, `%${w}%`]);
202
+ const projectClause = projectId ? 'AND (project_id = ? OR project_id IS NULL)' : 'AND project_id IS NULL';
203
+ const params = [...likeParams];
204
+ if (projectId)
205
+ params.push(projectId);
206
+ params.push(limit);
207
+ return this.db.prepare(`
208
+ SELECT * FROM reasoning_scaffolds
209
+ WHERE (${likeOr}) ${projectClause}
210
+ ORDER BY confidence DESC
211
+ LIMIT ?
212
+ `).all(...params);
213
+ }
214
+ recordOutcome(id, success) {
215
+ const col = success ? 'success_count' : 'usage_count';
216
+ this.db.prepare(`
217
+ UPDATE reasoning_scaffolds SET
218
+ usage_count = usage_count + 1,
219
+ ${col} = ${col} + 1,
220
+ confidence = CASE
221
+ WHEN ? THEN MIN(1.0, confidence + 0.03)
222
+ ELSE MAX(0.1, confidence - 0.08)
223
+ END,
224
+ updated_at = datetime('now')
225
+ WHERE id = ?
226
+ `).run(success ? 1 : 0, id);
227
+ }
228
+ list(projectId, limit = 20) {
229
+ const projectClause = projectId ? 'WHERE project_id = ? OR project_id IS NULL' : 'WHERE project_id IS NULL';
230
+ const params = [];
231
+ if (projectId)
232
+ params.push(projectId);
233
+ params.push(limit);
234
+ return this.db.prepare(`
235
+ SELECT * FROM reasoning_scaffolds ${projectClause}
236
+ ORDER BY confidence DESC, usage_count DESC
237
+ LIMIT ?
238
+ `).all(...params);
239
+ }
240
+ delete(id) {
241
+ return this.db.prepare('DELETE FROM reasoning_scaffolds WHERE id = ?').run(id).changes > 0;
242
+ }
243
+ /**
244
+ * Format a scaffold as a structured context block.
245
+ * Returns a plain checklist (not XML/CoT prompting) for model injection.
246
+ */
247
+ formatForContext(match, budgetChars = SCAFFOLD_BUDGET_CHARS) {
248
+ const s = match.scaffold;
249
+ const steps = JSON.parse(s.steps || '[]');
250
+ const verifySteps = s.verification_steps ? JSON.parse(s.verification_steps) : [];
251
+ const dontApply = s.do_not_apply_if ? JSON.parse(s.do_not_apply_if) : [];
252
+ let text = `### 🧭 Reasoning Scaffold: "${s.problem_type}" _(confidence: ${(match.matchScore * 100).toFixed(0)}%)_\n`;
253
+ if (s.when_to_use) {
254
+ text += `**When to use:** ${s.when_to_use}\n`;
255
+ }
256
+ if (dontApply.length) {
257
+ text += `**Do NOT apply if:** ${dontApply.join(' · ')}\n`;
258
+ }
259
+ text += `\n**Execution steps:**\n`;
260
+ for (let i = 0; i < steps.length; i++) {
261
+ const line = `${i + 1}. ${steps[i]}\n`;
262
+ if (text.length + line.length > budgetChars)
263
+ break;
264
+ text += line;
265
+ }
266
+ if (verifySteps.length && text.length + 100 < budgetChars) {
267
+ text += `\n**Before finishing, verify:**\n`;
268
+ for (const v of verifySteps) {
269
+ const line = `- [ ] ${v}\n`;
270
+ if (text.length + line.length > budgetChars)
271
+ break;
272
+ text += line;
273
+ }
274
+ }
275
+ return text;
276
+ }
277
+ }
278
+ //# sourceMappingURL=intelligence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intelligence.js","sourceRoot":"","sources":["../src/intelligence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiCH,6DAA6D;AAC7D,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAM,OAAO,YAAY;IACH;IAApB,YAAoB,EAAqB;QAArB,OAAE,GAAF,EAAE,CAAmB;IAAG,CAAC;IAE7C;;;OAGG;IACH,GAAG,CAAC,SAAiB,EAAE,IAAqB;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;YACxC,kCAAkC;YAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;;;;OAIhC,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAA4B,CAAC;YAEtE,sCAAsC;YACtC,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,EAAE,CAAC,OAAO,CACb,oFAAoF,CACrF,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACrB,CAAC;YAED,yBAAyB;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;;;OAG9B,CAAC,CAAC,GAAG,CACJ,SAAS,EACT,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EACf,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACjB,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,IAAI,EAC9B,IAAI,CAAC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,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;YACvC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,WAAW;gBAAE,MAAM;YACnD,IAAI,IAAI,IAAI,CAAC;QACf,CAAC;QAED,IAAI,WAAW,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,WAAW,EAAE,CAAC;YAC1D,IAAI,IAAI,mCAAmC,CAAC;YAC5C,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;gBAC5B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;gBAC5B,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,WAAW;oBAAE,MAAM;gBACnD,IAAI,IAAI,IAAI,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Wyrm Knowledge Graph — Entity & Relationship Management
3
+ *
4
+ * @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
5
+ * @license Proprietary - See LICENSE file for details.
6
+ *
7
+ * Manual-first knowledge graph with provenance tracking:
8
+ * - Named entities with types and metadata
9
+ * - Typed, directed relationships between entities
10
+ * - Aliases for deduplication
11
+ * - Graph traversal via recursive CTEs (neighborhood, paths)
12
+ * - FTS5 search on entity names
13
+ */
14
+ import type Database from 'better-sqlite3';
15
+ export interface Entity {
16
+ id: number;
17
+ project_id: number;
18
+ name: string;
19
+ type: string;
20
+ metadata: string | null;
21
+ created_by: string;
22
+ created_at: string;
23
+ updated_at: string;
24
+ }
25
+ export interface Relationship {
26
+ id: number;
27
+ project_id: number;
28
+ source_entity_id: number;
29
+ target_entity_id: number;
30
+ relationship_type: string;
31
+ weight: number;
32
+ confidence: number;
33
+ source_memory: string | null;
34
+ extraction_method: string;
35
+ metadata: string | null;
36
+ created_by: string;
37
+ created_at: string;
38
+ }
39
+ export interface GraphNode {
40
+ id: number;
41
+ name: string;
42
+ type: string;
43
+ metadata: string | null;
44
+ depth: number;
45
+ }
46
+ export interface GraphEdge {
47
+ source_id: number;
48
+ source_name: string;
49
+ target_id: number;
50
+ target_name: string;
51
+ relationship_type: string;
52
+ weight: number;
53
+ }
54
+ export interface GraphNeighborhood {
55
+ nodes: GraphNode[];
56
+ edges: GraphEdge[];
57
+ }
58
+ /**
59
+ * Knowledge graph operations backed by SQLite.
60
+ */
61
+ export declare class KnowledgeGraph {
62
+ private db;
63
+ constructor(db: Database.Database);
64
+ addEntity(projectId: number, name: string, type: string, metadata?: string, createdBy?: string): Entity;
65
+ getEntity(id: number): Entity | null;
66
+ findEntity(projectId: number, name: string, type?: string): Entity | null;
67
+ updateEntity(id: number, updates: {
68
+ name?: string;
69
+ type?: string;
70
+ metadata?: string;
71
+ }): Entity | null;
72
+ deleteEntity(id: number): boolean;
73
+ listEntities(projectId: number, options?: {
74
+ type?: string;
75
+ limit?: number;
76
+ offset?: number;
77
+ }): Entity[];
78
+ searchEntities(projectId: number, query: string, limit?: number): Entity[];
79
+ addAlias(entityId: number, alias: string): void;
80
+ getAliases(entityId: number): string[];
81
+ findByAlias(projectId: number, alias: string): Entity | null;
82
+ addRelationship(projectId: number, sourceId: number, targetId: number, type: string, options?: {
83
+ weight?: number;
84
+ confidence?: number;
85
+ sourceMemory?: string;
86
+ extractionMethod?: string;
87
+ metadata?: string;
88
+ createdBy?: string;
89
+ }): Relationship;
90
+ getRelationships(entityId: number, direction?: 'outgoing' | 'incoming' | 'both'): Relationship[];
91
+ deleteRelationship(id: number): boolean;
92
+ /**
93
+ * Get neighborhood — all nodes within N hops of a given entity.
94
+ * Uses recursive CTE with cycle detection.
95
+ */
96
+ getNeighborhood(entityId: number, maxDepth?: number): GraphNeighborhood;
97
+ /**
98
+ * Find path between two entities using BFS with cycle detection.
99
+ * Returns the shortest path as a list of entity IDs, or null if no path exists.
100
+ */
101
+ findPath(sourceId: number, targetId: number, maxDepth?: number): number[] | null;
102
+ /**
103
+ * Merge two entities: moves all relationships and aliases from source to target,
104
+ * adds source name as alias on target, then deletes source.
105
+ */
106
+ mergeEntities(sourceId: number, targetId: number): Entity | null;
107
+ getStats(projectId: number): {
108
+ entities: number;
109
+ relationships: number;
110
+ entityTypes: Record<string, number>;
111
+ };
112
+ }
113
+ //# sourceMappingURL=knowledge-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-graph.d.ts","sourceRoot":"","sources":["../src/knowledge-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,U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