@clawdactual/chitin 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/LICENSE +21 -0
- package/README.md +318 -0
- package/dist/carapace/client.d.ts +41 -0
- package/dist/carapace/client.d.ts.map +1 -0
- package/dist/carapace/client.js +62 -0
- package/dist/carapace/client.js.map +1 -0
- package/dist/carapace/config.d.ts +9 -0
- package/dist/carapace/config.d.ts.map +1 -0
- package/dist/carapace/config.js +24 -0
- package/dist/carapace/config.js.map +1 -0
- package/dist/carapace/index.d.ts +5 -0
- package/dist/carapace/index.d.ts.map +1 -0
- package/dist/carapace/index.js +3 -0
- package/dist/carapace/index.js.map +1 -0
- package/dist/carapace/mapper.d.ts +71 -0
- package/dist/carapace/mapper.d.ts.map +1 -0
- package/dist/carapace/mapper.js +83 -0
- package/dist/carapace/mapper.js.map +1 -0
- package/dist/db/embeddings.d.ts +12 -0
- package/dist/db/embeddings.d.ts.map +1 -0
- package/dist/db/embeddings.js +58 -0
- package/dist/db/embeddings.js.map +1 -0
- package/dist/db/history.d.ts +52 -0
- package/dist/db/history.d.ts.map +1 -0
- package/dist/db/history.js +99 -0
- package/dist/db/history.js.map +1 -0
- package/dist/db/repository.d.ts +64 -0
- package/dist/db/repository.d.ts.map +1 -0
- package/dist/db/repository.js +298 -0
- package/dist/db/repository.js.map +1 -0
- package/dist/db/schema.d.ts +5 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +68 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/engine/conflicts.d.ts +52 -0
- package/dist/engine/conflicts.d.ts.map +1 -0
- package/dist/engine/conflicts.js +232 -0
- package/dist/engine/conflicts.js.map +1 -0
- package/dist/engine/context-detect.d.ts +17 -0
- package/dist/engine/context-detect.d.ts.map +1 -0
- package/dist/engine/context-detect.js +132 -0
- package/dist/engine/context-detect.js.map +1 -0
- package/dist/engine/marshal.d.ts +19 -0
- package/dist/engine/marshal.d.ts.map +1 -0
- package/dist/engine/marshal.js +74 -0
- package/dist/engine/marshal.js.map +1 -0
- package/dist/engine/retrieve.d.ts +36 -0
- package/dist/engine/retrieve.d.ts.map +1 -0
- package/dist/engine/retrieve.js +45 -0
- package/dist/engine/retrieve.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +769 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
- package/seed.json +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapper.js","sourceRoot":"","sources":["../../src/carapace/mapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuCH,uEAAuE;AACvE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AAE/E,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAgB,EAChB,UAAoC,EAAE;IAEtC,MAAM,MAAM,GAAyB;QACnC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC;IAEF,IAAI,OAAO,CAAC,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAC5D,IAAI,OAAO,CAAC,OAAO;QAAE,MAAM,CAAC,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAC5D,IAAI,OAAO,CAAC,WAAW;QAAE,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAElE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CA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CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACnF,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;IACxF,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;IAE/D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NearestResult {
|
|
2
|
+
insightId: string;
|
|
3
|
+
similarity: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class EmbeddingStore {
|
|
6
|
+
upsert(insightId: string, embedding: Float32Array): void;
|
|
7
|
+
get(insightId: string): Float32Array | null;
|
|
8
|
+
cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
9
|
+
findNearest(query: Float32Array, maxResults: number): NearestResult[];
|
|
10
|
+
findMissingEmbeddings(): string[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=embeddings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.d.ts","sourceRoot":"","sources":["../../src/db/embeddings.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,cAAc;IACzB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,GAAG,IAAI;IAWxD,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAU3C,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM;IAoB1D,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,EAAE;IAsBrE,qBAAqB,IAAI,MAAM,EAAE;CAUlC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getDatabase } from './schema.js';
|
|
2
|
+
export class EmbeddingStore {
|
|
3
|
+
upsert(insightId, embedding) {
|
|
4
|
+
const db = getDatabase();
|
|
5
|
+
const buffer = Buffer.from(embedding.buffer, embedding.byteOffset, embedding.byteLength);
|
|
6
|
+
db.prepare(`
|
|
7
|
+
INSERT INTO insight_embeddings (insight_id, embedding)
|
|
8
|
+
VALUES (?, ?)
|
|
9
|
+
ON CONFLICT(insight_id) DO UPDATE SET embedding = excluded.embedding
|
|
10
|
+
`).run(insightId, buffer);
|
|
11
|
+
}
|
|
12
|
+
get(insightId) {
|
|
13
|
+
const db = getDatabase();
|
|
14
|
+
const row = db.prepare('SELECT embedding FROM insight_embeddings WHERE insight_id = ?').get(insightId);
|
|
15
|
+
if (!row)
|
|
16
|
+
return null;
|
|
17
|
+
return new Float32Array(row.embedding.buffer, row.embedding.byteOffset, row.embedding.byteLength / 4);
|
|
18
|
+
}
|
|
19
|
+
cosineSimilarity(a, b) {
|
|
20
|
+
if (a.length !== b.length) {
|
|
21
|
+
throw new Error(`Vector dimension mismatch: ${a.length} vs ${b.length}`);
|
|
22
|
+
}
|
|
23
|
+
let dot = 0;
|
|
24
|
+
let normA = 0;
|
|
25
|
+
let normB = 0;
|
|
26
|
+
for (let i = 0; i < a.length; i++) {
|
|
27
|
+
dot += a[i] * b[i];
|
|
28
|
+
normA += a[i] * a[i];
|
|
29
|
+
normB += b[i] * b[i];
|
|
30
|
+
}
|
|
31
|
+
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
32
|
+
if (denom === 0)
|
|
33
|
+
return 0;
|
|
34
|
+
return dot / denom;
|
|
35
|
+
}
|
|
36
|
+
findNearest(query, maxResults) {
|
|
37
|
+
const db = getDatabase();
|
|
38
|
+
const rows = db.prepare('SELECT insight_id, embedding FROM insight_embeddings').all();
|
|
39
|
+
const scored = [];
|
|
40
|
+
for (const row of rows) {
|
|
41
|
+
const embedding = new Float32Array(row.embedding.buffer, row.embedding.byteOffset, row.embedding.byteLength / 4);
|
|
42
|
+
const similarity = this.cosineSimilarity(query, embedding);
|
|
43
|
+
scored.push({ insightId: row.insight_id, similarity });
|
|
44
|
+
}
|
|
45
|
+
scored.sort((a, b) => b.similarity - a.similarity);
|
|
46
|
+
return scored.slice(0, maxResults);
|
|
47
|
+
}
|
|
48
|
+
findMissingEmbeddings() {
|
|
49
|
+
const db = getDatabase();
|
|
50
|
+
const rows = db.prepare(`
|
|
51
|
+
SELECT i.id FROM insights i
|
|
52
|
+
LEFT JOIN insight_embeddings e ON i.id = e.insight_id
|
|
53
|
+
WHERE e.insight_id IS NULL
|
|
54
|
+
`).all();
|
|
55
|
+
return rows.map(r => r.id);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=embeddings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.js","sourceRoot":"","sources":["../../src/db/embeddings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,SAAiB,EAAE,SAAuB;QAC/C,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;QAEzF,EAAE,CAAC,OAAO,CAAC;;;;KAIV,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,GAAG,CAAC,SAAiB;QACnB,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CACpB,+DAA+D,CAChE,CAAC,GAAG,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AE,CAAC,OAAO,CACrB,sDAAsD,CACvD,CAAC,GAAG,EAAiD,CAAC;QAEvD,MAAM,MAAM,GAAoB,EAAE,CAAC;QAEnC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,SAAS,GAAG,IAAI,YAAY,CAChC,GAAG,CAAC,SAAS,CAAC,MAAM,EACpB,GAAG,CAAC,SAAS,CAAC,UAAU,EACxB,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAC7B,CAAC;YACF,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAC3D,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;QACnD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,qBAAqB;QACnB,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC;;;;KAIvB,CAAC,CAAC,GAAG,EAAsB,CAAC;QAE7B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Insight } from '../types.js';
|
|
2
|
+
export interface HistoryEntry {
|
|
3
|
+
id: number;
|
|
4
|
+
insightId: string;
|
|
5
|
+
field: string;
|
|
6
|
+
oldValue: string | null;
|
|
7
|
+
newValue: string | null;
|
|
8
|
+
changeType: 'create' | 'update' | 'reinforce' | 'merge';
|
|
9
|
+
changedAt: string;
|
|
10
|
+
source: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface HistoryOptions {
|
|
13
|
+
limit?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ChangelogOptions {
|
|
16
|
+
limit?: number;
|
|
17
|
+
days?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class InsightHistory {
|
|
20
|
+
/**
|
|
21
|
+
* Record an insight creation.
|
|
22
|
+
*/
|
|
23
|
+
recordCreate(insight: Insight): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record field-level changes from an update.
|
|
26
|
+
* @param changes - Map of field name to { old, new } string values
|
|
27
|
+
*/
|
|
28
|
+
recordUpdate(insightId: string, changes: Record<string, {
|
|
29
|
+
old: string;
|
|
30
|
+
new: string;
|
|
31
|
+
}>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Record a reinforcement event (confidence change).
|
|
34
|
+
*/
|
|
35
|
+
recordReinforce(insightId: string, oldConfidence: number, newConfidence: number, newCount: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Record field changes from a merge operation.
|
|
38
|
+
*/
|
|
39
|
+
recordMerge(targetId: string, sourceId: string, changes: Record<string, {
|
|
40
|
+
old: string;
|
|
41
|
+
new: string;
|
|
42
|
+
}>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get the history for a specific insight, in chronological order.
|
|
45
|
+
*/
|
|
46
|
+
getHistory(insightId: string, options?: HistoryOptions): HistoryEntry[];
|
|
47
|
+
/**
|
|
48
|
+
* Get recent changes across all insights, most recent first.
|
|
49
|
+
*/
|
|
50
|
+
getChangelog(options?: ChangelogOptions): HistoryEntry[];
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/db/history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,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EAAE;CAsBzD"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getDatabase } from './schema.js';
|
|
2
|
+
function rowToEntry(row) {
|
|
3
|
+
return {
|
|
4
|
+
id: row.id,
|
|
5
|
+
insightId: row.insight_id,
|
|
6
|
+
field: row.field,
|
|
7
|
+
oldValue: row.old_value,
|
|
8
|
+
newValue: row.new_value,
|
|
9
|
+
changeType: row.change_type,
|
|
10
|
+
changedAt: row.changed_at,
|
|
11
|
+
source: row.source,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export class InsightHistory {
|
|
15
|
+
/**
|
|
16
|
+
* Record an insight creation.
|
|
17
|
+
*/
|
|
18
|
+
recordCreate(insight) {
|
|
19
|
+
const db = getDatabase();
|
|
20
|
+
db.prepare(`
|
|
21
|
+
INSERT INTO insight_history (insight_id, field, old_value, new_value, change_type, source)
|
|
22
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
23
|
+
`).run(insight.id, '*', null, insight.claim, 'create', null);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Record field-level changes from an update.
|
|
27
|
+
* @param changes - Map of field name to { old, new } string values
|
|
28
|
+
*/
|
|
29
|
+
recordUpdate(insightId, changes) {
|
|
30
|
+
const db = getDatabase();
|
|
31
|
+
const stmt = db.prepare(`
|
|
32
|
+
INSERT INTO insight_history (insight_id, field, old_value, new_value, change_type, source)
|
|
33
|
+
VALUES (?, ?, ?, ?, 'update', ?)
|
|
34
|
+
`);
|
|
35
|
+
for (const [field, { old: oldVal, new: newVal }] of Object.entries(changes)) {
|
|
36
|
+
stmt.run(insightId, field, oldVal, newVal, null);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Record a reinforcement event (confidence change).
|
|
41
|
+
*/
|
|
42
|
+
recordReinforce(insightId, oldConfidence, newConfidence, newCount) {
|
|
43
|
+
const db = getDatabase();
|
|
44
|
+
db.prepare(`
|
|
45
|
+
INSERT INTO insight_history (insight_id, field, old_value, new_value, change_type, source)
|
|
46
|
+
VALUES (?, ?, ?, ?, 'reinforce', ?)
|
|
47
|
+
`).run(insightId, 'confidence', String(oldConfidence), String(newConfidence), `reinforce:${newCount}`);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record field changes from a merge operation.
|
|
51
|
+
*/
|
|
52
|
+
recordMerge(targetId, sourceId, changes) {
|
|
53
|
+
const db = getDatabase();
|
|
54
|
+
const stmt = db.prepare(`
|
|
55
|
+
INSERT INTO insight_history (insight_id, field, old_value, new_value, change_type, source)
|
|
56
|
+
VALUES (?, ?, ?, ?, 'merge', ?)
|
|
57
|
+
`);
|
|
58
|
+
const source = `merge:${sourceId}`;
|
|
59
|
+
for (const [field, { old: oldVal, new: newVal }] of Object.entries(changes)) {
|
|
60
|
+
stmt.run(targetId, field, oldVal, newVal, source);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the history for a specific insight, in chronological order.
|
|
65
|
+
*/
|
|
66
|
+
getHistory(insightId, options) {
|
|
67
|
+
const db = getDatabase();
|
|
68
|
+
const limit = options?.limit ? `LIMIT ${options.limit}` : '';
|
|
69
|
+
const rows = db.prepare(`
|
|
70
|
+
SELECT * FROM insight_history
|
|
71
|
+
WHERE insight_id = ?
|
|
72
|
+
ORDER BY changed_at ASC, id ASC
|
|
73
|
+
${limit}
|
|
74
|
+
`).all(insightId);
|
|
75
|
+
return rows.map(rowToEntry);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get recent changes across all insights, most recent first.
|
|
79
|
+
*/
|
|
80
|
+
getChangelog(options) {
|
|
81
|
+
const db = getDatabase();
|
|
82
|
+
const conditions = [];
|
|
83
|
+
const params = [];
|
|
84
|
+
if (options?.days) {
|
|
85
|
+
conditions.push(`changed_at >= datetime('now', ?)`);
|
|
86
|
+
params.push(`-${options.days} days`);
|
|
87
|
+
}
|
|
88
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
89
|
+
const limit = options?.limit ? `LIMIT ${options.limit}` : 'LIMIT 50';
|
|
90
|
+
const rows = db.prepare(`
|
|
91
|
+
SELECT * FROM insight_history
|
|
92
|
+
${where}
|
|
93
|
+
ORDER BY changed_at DESC, id DESC
|
|
94
|
+
${limit}
|
|
95
|
+
`).all(...params);
|
|
96
|
+
return rows.map(rowToEntry);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/db/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAkC1C,SAAS,UAAU,CAAC,GAAe;IACjC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,QAAQ,EAAE,GAAG,CAAC,SAAS;QACvB,QAAQ,EAAE,GAAG,CAAC,SAAS;QACvB,UAAU,EAAE,GAAG,CAAC,WAAyC;QACzD,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,MAAM,EAAE,GAAG,CAAC,MAAM;KACnB,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,cAAc;IACzB;;OAEG;IACH,YAAY,CAAC,OAAgB;QAC3B,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,EAAE,CAAC,OAAO,CAAC;;;KAGV,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,SAAiB,EAAE,OAAqD;QACnF,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO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AAK,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC;;;;QAIpB,KAAK;KACR,CAAC,CAAC,GAAG,CAAC,SAAS,CAAiB,CAAC;QAElC,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,OAA0B;QACrC,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QACzB,MAAM,UAAU,GAAa,EAAE,CAAC;QAChC,MAAM,MAAM,GAAc,EAAE,CAAC;QAE7B,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;YAClB,UAAU,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;YACpD,MAAM,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;QAErE,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC;;QAEpB,KAAK;;QAEL,KAAK;KACR,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAiB,CAAC;QAElC,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Insight, ContributeInput, ContributeResult, UpdateInput, InsightType } from '../types.js';
|
|
2
|
+
export interface SimilarResult {
|
|
3
|
+
insight: Insight;
|
|
4
|
+
similarity: number;
|
|
5
|
+
}
|
|
6
|
+
export interface MergeOptions {
|
|
7
|
+
claim?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ListOptions {
|
|
10
|
+
types?: InsightType[];
|
|
11
|
+
tags?: string[];
|
|
12
|
+
minConfidence?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface InsightStats {
|
|
15
|
+
total: number;
|
|
16
|
+
byType: Record<InsightType, number>;
|
|
17
|
+
averageConfidence: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class InsightRepository {
|
|
20
|
+
private history;
|
|
21
|
+
contribute(input: ContributeInput): Insight;
|
|
22
|
+
/**
|
|
23
|
+
* Contribute with conflict detection. Checks for contradictions before writing.
|
|
24
|
+
* Returns the new insight plus any detected conflicts.
|
|
25
|
+
*
|
|
26
|
+
* If `force` is false and conflicts are found, the insight is STILL written
|
|
27
|
+
* (caller decides what to do with conflict info). Use this for CLI interactive mode.
|
|
28
|
+
*/
|
|
29
|
+
contributeWithCheck(input: ContributeInput, options?: {
|
|
30
|
+
force?: boolean;
|
|
31
|
+
}): ContributeResult;
|
|
32
|
+
get(id: string): Insight | null;
|
|
33
|
+
update(id: string, input: UpdateInput): Insight;
|
|
34
|
+
archive(id: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Confidence adjustment rate per reinforcement.
|
|
37
|
+
* Each reinforce nudges confidence up by this fraction of the remaining gap to 1.0:
|
|
38
|
+
* newConfidence = confidence + (1.0 - confidence) * CONFIDENCE_ADJUSTMENT_RATE
|
|
39
|
+
* At 0.05, a 0.8 → 0.81 → 0.8195 → ... asymptotically approaching 1.0.
|
|
40
|
+
*/
|
|
41
|
+
static readonly CONFIDENCE_ADJUSTMENT_RATE = 0.05;
|
|
42
|
+
reinforce(id: string): Insight;
|
|
43
|
+
/**
|
|
44
|
+
* Find insights with similar claims using word-level Jaccard similarity.
|
|
45
|
+
* Returns results sorted by similarity descending.
|
|
46
|
+
*/
|
|
47
|
+
findSimilar(claim: string, minSimilarity?: number, excludeId?: string): SimilarResult[];
|
|
48
|
+
/**
|
|
49
|
+
* Merge source insight into target. Target survives with combined data:
|
|
50
|
+
* - confidence: max of both
|
|
51
|
+
* - tags: union (deduplicated)
|
|
52
|
+
* - reinforcementCount: sum of both
|
|
53
|
+
* - reasoning: concatenated if both exist
|
|
54
|
+
* - claim: target's claim unless overridden
|
|
55
|
+
*
|
|
56
|
+
* Source is deleted after merge.
|
|
57
|
+
*/
|
|
58
|
+
merge(sourceId: string, targetId: string, options?: MergeOptions): Insight;
|
|
59
|
+
private tokenize;
|
|
60
|
+
private jaccardSimilarity;
|
|
61
|
+
list(options?: ListOptions): Insight[];
|
|
62
|
+
stats(): InsightStats;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/db/repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAiB,MAAM,aAAa,CAAC;AAsCvH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACpC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAwB;IAEvC,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO;IAyB3C;;;;;;OAMG;IACH,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,gBAAgB;IAM5F,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAM/B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO;IAyD/C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKzB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,0BAA0B,QAAQ;IAElD,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IA8B9B;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,SAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE;IAsBpF;;;;;;;;;OASG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO;IAmE9E,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,iBAAiB;IAYzB,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,EAAE;IA6BtC,KAAK,IAAI,YAAY;CA8BtB"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { getDatabase } from './schema.js';
|
|
3
|
+
import { detectConflicts } from '../engine/conflicts.js';
|
|
4
|
+
import { InsightHistory } from './history.js';
|
|
5
|
+
function rowToInsight(row) {
|
|
6
|
+
return {
|
|
7
|
+
id: row.id,
|
|
8
|
+
type: row.type,
|
|
9
|
+
claim: row.claim,
|
|
10
|
+
reasoning: row.reasoning ?? undefined,
|
|
11
|
+
context: row.context ?? undefined,
|
|
12
|
+
limitations: row.limitations ?? undefined,
|
|
13
|
+
confidence: row.confidence,
|
|
14
|
+
tags: JSON.parse(row.tags),
|
|
15
|
+
source: row.source ?? undefined,
|
|
16
|
+
createdAt: row.created_at,
|
|
17
|
+
updatedAt: row.updated_at,
|
|
18
|
+
reinforcementCount: row.reinforcement_count,
|
|
19
|
+
lastRetrievedAt: row.last_retrieved_at ?? undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export class InsightRepository {
|
|
23
|
+
history = new InsightHistory();
|
|
24
|
+
contribute(input) {
|
|
25
|
+
const db = getDatabase();
|
|
26
|
+
const id = crypto.randomUUID();
|
|
27
|
+
const tags = JSON.stringify(input.tags ?? []);
|
|
28
|
+
db.prepare(`
|
|
29
|
+
INSERT INTO insights (id, type, claim, reasoning, context, limitations, confidence, tags, source)
|
|
30
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
31
|
+
`).run(id, input.type, input.claim, input.reasoning ?? null, input.context ?? null, input.limitations ?? null, input.confidence, tags, input.source ?? null);
|
|
32
|
+
const insight = this.get(id);
|
|
33
|
+
this.history.recordCreate(insight);
|
|
34
|
+
return insight;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Contribute with conflict detection. Checks for contradictions before writing.
|
|
38
|
+
* Returns the new insight plus any detected conflicts.
|
|
39
|
+
*
|
|
40
|
+
* If `force` is false and conflicts are found, the insight is STILL written
|
|
41
|
+
* (caller decides what to do with conflict info). Use this for CLI interactive mode.
|
|
42
|
+
*/
|
|
43
|
+
contributeWithCheck(input, options) {
|
|
44
|
+
const conflicts = options?.force ? [] : detectConflicts(this, input);
|
|
45
|
+
const insight = this.contribute(input);
|
|
46
|
+
return { insight, conflicts };
|
|
47
|
+
}
|
|
48
|
+
get(id) {
|
|
49
|
+
const db = getDatabase();
|
|
50
|
+
const row = db.prepare('SELECT * FROM insights WHERE id = ?').get(id);
|
|
51
|
+
return row ? rowToInsight(row) : null;
|
|
52
|
+
}
|
|
53
|
+
update(id, input) {
|
|
54
|
+
const db = getDatabase();
|
|
55
|
+
const existing = this.get(id);
|
|
56
|
+
if (!existing) {
|
|
57
|
+
throw new Error(`Insight not found: ${id}`);
|
|
58
|
+
}
|
|
59
|
+
const fields = [];
|
|
60
|
+
const values = [];
|
|
61
|
+
const changes = {};
|
|
62
|
+
if (input.claim !== undefined) {
|
|
63
|
+
fields.push('claim = ?');
|
|
64
|
+
values.push(input.claim);
|
|
65
|
+
if (input.claim !== existing.claim)
|
|
66
|
+
changes.claim = { old: existing.claim, new: input.claim };
|
|
67
|
+
}
|
|
68
|
+
if (input.reasoning !== undefined) {
|
|
69
|
+
fields.push('reasoning = ?');
|
|
70
|
+
values.push(input.reasoning);
|
|
71
|
+
if (input.reasoning !== (existing.reasoning ?? ''))
|
|
72
|
+
changes.reasoning = { old: existing.reasoning ?? '', new: input.reasoning };
|
|
73
|
+
}
|
|
74
|
+
if (input.context !== undefined) {
|
|
75
|
+
fields.push('context = ?');
|
|
76
|
+
values.push(input.context);
|
|
77
|
+
if (input.context !== (existing.context ?? ''))
|
|
78
|
+
changes.context = { old: existing.context ?? '', new: input.context };
|
|
79
|
+
}
|
|
80
|
+
if (input.limitations !== undefined) {
|
|
81
|
+
fields.push('limitations = ?');
|
|
82
|
+
values.push(input.limitations);
|
|
83
|
+
if (input.limitations !== (existing.limitations ?? ''))
|
|
84
|
+
changes.limitations = { old: existing.limitations ?? '', new: input.limitations };
|
|
85
|
+
}
|
|
86
|
+
if (input.confidence !== undefined) {
|
|
87
|
+
fields.push('confidence = ?');
|
|
88
|
+
values.push(input.confidence);
|
|
89
|
+
if (input.confidence !== existing.confidence)
|
|
90
|
+
changes.confidence = { old: String(existing.confidence), new: String(input.confidence) };
|
|
91
|
+
}
|
|
92
|
+
if (input.tags !== undefined) {
|
|
93
|
+
fields.push('tags = ?');
|
|
94
|
+
values.push(JSON.stringify(input.tags));
|
|
95
|
+
const oldTags = JSON.stringify(existing.tags);
|
|
96
|
+
const newTags = JSON.stringify(input.tags);
|
|
97
|
+
if (oldTags !== newTags)
|
|
98
|
+
changes.tags = { old: oldTags, new: newTags };
|
|
99
|
+
}
|
|
100
|
+
if (input.source !== undefined) {
|
|
101
|
+
fields.push('source = ?');
|
|
102
|
+
values.push(input.source);
|
|
103
|
+
if (input.source !== (existing.source ?? ''))
|
|
104
|
+
changes.source = { old: existing.source ?? '', new: input.source };
|
|
105
|
+
}
|
|
106
|
+
if (fields.length === 0)
|
|
107
|
+
return existing;
|
|
108
|
+
fields.push("updated_at = datetime('now')");
|
|
109
|
+
values.push(id);
|
|
110
|
+
db.prepare(`UPDATE insights SET ${fields.join(', ')} WHERE id = ?`).run(...values);
|
|
111
|
+
// Record history
|
|
112
|
+
if (Object.keys(changes).length > 0) {
|
|
113
|
+
this.history.recordUpdate(id, changes);
|
|
114
|
+
}
|
|
115
|
+
return this.get(id);
|
|
116
|
+
}
|
|
117
|
+
archive(id) {
|
|
118
|
+
const db = getDatabase();
|
|
119
|
+
db.prepare('DELETE FROM insights WHERE id = ?').run(id);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Confidence adjustment rate per reinforcement.
|
|
123
|
+
* Each reinforce nudges confidence up by this fraction of the remaining gap to 1.0:
|
|
124
|
+
* newConfidence = confidence + (1.0 - confidence) * CONFIDENCE_ADJUSTMENT_RATE
|
|
125
|
+
* At 0.05, a 0.8 → 0.81 → 0.8195 → ... asymptotically approaching 1.0.
|
|
126
|
+
*/
|
|
127
|
+
static CONFIDENCE_ADJUSTMENT_RATE = 0.05;
|
|
128
|
+
reinforce(id) {
|
|
129
|
+
const db = getDatabase();
|
|
130
|
+
const existing = this.get(id);
|
|
131
|
+
if (!existing) {
|
|
132
|
+
throw new Error(`Insight not found: ${id}`);
|
|
133
|
+
}
|
|
134
|
+
// Nudge confidence toward 1.0
|
|
135
|
+
const oldConfidence = existing.confidence;
|
|
136
|
+
const newConfidence = Math.min(1.0, oldConfidence + (1.0 - oldConfidence) * InsightRepository.CONFIDENCE_ADJUSTMENT_RATE);
|
|
137
|
+
const newCount = existing.reinforcementCount + 1;
|
|
138
|
+
db.prepare(`
|
|
139
|
+
UPDATE insights
|
|
140
|
+
SET reinforcement_count = reinforcement_count + 1,
|
|
141
|
+
confidence = ?,
|
|
142
|
+
last_retrieved_at = datetime('now'),
|
|
143
|
+
updated_at = datetime('now')
|
|
144
|
+
WHERE id = ?
|
|
145
|
+
`).run(newConfidence, id);
|
|
146
|
+
// Record history
|
|
147
|
+
this.history.recordReinforce(id, oldConfidence, newConfidence, newCount);
|
|
148
|
+
return this.get(id);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Find insights with similar claims using word-level Jaccard similarity.
|
|
152
|
+
* Returns results sorted by similarity descending.
|
|
153
|
+
*/
|
|
154
|
+
findSimilar(claim, minSimilarity = 0.2, excludeId) {
|
|
155
|
+
const queryWords = this.tokenize(claim);
|
|
156
|
+
if (queryWords.size === 0)
|
|
157
|
+
return [];
|
|
158
|
+
const allInsights = this.list();
|
|
159
|
+
const results = [];
|
|
160
|
+
for (const insight of allInsights) {
|
|
161
|
+
if (excludeId && insight.id === excludeId)
|
|
162
|
+
continue;
|
|
163
|
+
const insightWords = this.tokenize(insight.claim);
|
|
164
|
+
const similarity = this.jaccardSimilarity(queryWords, insightWords);
|
|
165
|
+
if (similarity >= minSimilarity) {
|
|
166
|
+
results.push({ insight, similarity });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
results.sort((a, b) => b.similarity - a.similarity);
|
|
170
|
+
return results;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Merge source insight into target. Target survives with combined data:
|
|
174
|
+
* - confidence: max of both
|
|
175
|
+
* - tags: union (deduplicated)
|
|
176
|
+
* - reinforcementCount: sum of both
|
|
177
|
+
* - reasoning: concatenated if both exist
|
|
178
|
+
* - claim: target's claim unless overridden
|
|
179
|
+
*
|
|
180
|
+
* Source is deleted after merge.
|
|
181
|
+
*/
|
|
182
|
+
merge(sourceId, targetId, options = {}) {
|
|
183
|
+
if (sourceId === targetId) {
|
|
184
|
+
throw new Error('Cannot merge an insight with itself');
|
|
185
|
+
}
|
|
186
|
+
const source = this.get(sourceId);
|
|
187
|
+
if (!source) {
|
|
188
|
+
throw new Error(`Source insight not found: ${sourceId}`);
|
|
189
|
+
}
|
|
190
|
+
const target = this.get(targetId);
|
|
191
|
+
if (!target) {
|
|
192
|
+
throw new Error(`Target insight not found: ${targetId}`);
|
|
193
|
+
}
|
|
194
|
+
// Combine fields
|
|
195
|
+
const mergedConfidence = Math.max(source.confidence, target.confidence);
|
|
196
|
+
const mergedTags = [...new Set([...target.tags, ...source.tags])];
|
|
197
|
+
const mergedReinforcement = target.reinforcementCount + source.reinforcementCount;
|
|
198
|
+
let mergedReasoning = target.reasoning;
|
|
199
|
+
if (source.reasoning) {
|
|
200
|
+
mergedReasoning = mergedReasoning
|
|
201
|
+
? `${mergedReasoning}; ${source.reasoning}`
|
|
202
|
+
: source.reasoning;
|
|
203
|
+
}
|
|
204
|
+
const mergedClaim = options.claim ?? target.claim;
|
|
205
|
+
// Update target
|
|
206
|
+
const db = getDatabase();
|
|
207
|
+
db.prepare(`
|
|
208
|
+
UPDATE insights
|
|
209
|
+
SET claim = ?,
|
|
210
|
+
confidence = ?,
|
|
211
|
+
tags = ?,
|
|
212
|
+
reinforcement_count = ?,
|
|
213
|
+
reasoning = ?,
|
|
214
|
+
updated_at = datetime('now')
|
|
215
|
+
WHERE id = ?
|
|
216
|
+
`).run(mergedClaim, mergedConfidence, JSON.stringify(mergedTags), mergedReinforcement, mergedReasoning ?? null, targetId);
|
|
217
|
+
// Record history for changed fields
|
|
218
|
+
const mergeChanges = {};
|
|
219
|
+
if (mergedClaim !== target.claim)
|
|
220
|
+
mergeChanges.claim = { old: target.claim, new: mergedClaim };
|
|
221
|
+
if (mergedConfidence !== target.confidence)
|
|
222
|
+
mergeChanges.confidence = { old: String(target.confidence), new: String(mergedConfidence) };
|
|
223
|
+
if (JSON.stringify(mergedTags) !== JSON.stringify(target.tags))
|
|
224
|
+
mergeChanges.tags = { old: JSON.stringify(target.tags), new: JSON.stringify(mergedTags) };
|
|
225
|
+
if (mergedReinforcement !== target.reinforcementCount)
|
|
226
|
+
mergeChanges.reinforcement_count = { old: String(target.reinforcementCount), new: String(mergedReinforcement) };
|
|
227
|
+
if (mergedReasoning !== target.reasoning)
|
|
228
|
+
mergeChanges.reasoning = { old: target.reasoning ?? '', new: mergedReasoning ?? '' };
|
|
229
|
+
if (Object.keys(mergeChanges).length > 0) {
|
|
230
|
+
this.history.recordMerge(targetId, sourceId, mergeChanges);
|
|
231
|
+
}
|
|
232
|
+
// Delete source
|
|
233
|
+
this.archive(sourceId);
|
|
234
|
+
return this.get(targetId);
|
|
235
|
+
}
|
|
236
|
+
tokenize(text) {
|
|
237
|
+
return new Set(text.toLowerCase()
|
|
238
|
+
.split(/\W+/)
|
|
239
|
+
.filter(w => w.length > 2) // skip tiny words like "a", "on", "is"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
jaccardSimilarity(a, b) {
|
|
243
|
+
if (a.size === 0 && b.size === 0)
|
|
244
|
+
return 0;
|
|
245
|
+
let intersection = 0;
|
|
246
|
+
for (const word of a) {
|
|
247
|
+
if (b.has(word))
|
|
248
|
+
intersection++;
|
|
249
|
+
}
|
|
250
|
+
const union = a.size + b.size - intersection;
|
|
251
|
+
return union === 0 ? 0 : intersection / union;
|
|
252
|
+
}
|
|
253
|
+
list(options) {
|
|
254
|
+
const db = getDatabase();
|
|
255
|
+
const conditions = [];
|
|
256
|
+
const params = [];
|
|
257
|
+
if (options?.types && options.types.length > 0) {
|
|
258
|
+
const placeholders = options.types.map(() => '?').join(', ');
|
|
259
|
+
conditions.push(`type IN (${placeholders})`);
|
|
260
|
+
params.push(...options.types);
|
|
261
|
+
}
|
|
262
|
+
if (options?.minConfidence !== undefined) {
|
|
263
|
+
conditions.push('confidence >= ?');
|
|
264
|
+
params.push(options.minConfidence);
|
|
265
|
+
}
|
|
266
|
+
if (options?.tags && options.tags.length > 0) {
|
|
267
|
+
// Match any insight whose tags JSON array contains any of the requested tags
|
|
268
|
+
const tagConditions = options.tags.map(() => "tags LIKE ?");
|
|
269
|
+
conditions.push(`(${tagConditions.join(' OR ')})`);
|
|
270
|
+
params.push(...options.tags.map(t => `%"${t}"%`));
|
|
271
|
+
}
|
|
272
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
273
|
+
const rows = db.prepare(`SELECT * FROM insights ${where} ORDER BY created_at DESC`).all(...params);
|
|
274
|
+
return rows.map(rowToInsight);
|
|
275
|
+
}
|
|
276
|
+
stats() {
|
|
277
|
+
const db = getDatabase();
|
|
278
|
+
const total = db.prepare('SELECT COUNT(*) as count FROM insights').get().count;
|
|
279
|
+
const typeCounts = db.prepare('SELECT type, COUNT(*) as count FROM insights GROUP BY type').all();
|
|
280
|
+
const byType = {
|
|
281
|
+
behavioral: 0,
|
|
282
|
+
personality: 0,
|
|
283
|
+
relational: 0,
|
|
284
|
+
principle: 0,
|
|
285
|
+
skill: 0,
|
|
286
|
+
};
|
|
287
|
+
for (const row of typeCounts) {
|
|
288
|
+
byType[row.type] = row.count;
|
|
289
|
+
}
|
|
290
|
+
const avgRow = db.prepare('SELECT AVG(confidence) as avg FROM insights').get();
|
|
291
|
+
return {
|
|
292
|
+
total,
|
|
293
|
+
byType: byType,
|
|
294
|
+
averageConfidence: avgRow.avg ?? 0,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/db/repository.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAkB9C,SAAS,Y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