audrey 0.14.0 → 0.16.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 -21
- package/README.md +808 -681
- package/mcp-server/config.js +76 -76
- package/mcp-server/index.js +728 -437
- package/package.json +76 -77
- package/src/adaptive.js +53 -53
- package/src/affect.js +64 -64
- package/src/audrey.js +604 -570
- package/src/causal.js +95 -95
- package/src/confidence.js +120 -120
- package/src/consolidate.js +265 -242
- package/src/context.js +15 -15
- package/src/db.js +37 -0
- package/src/decay.js +84 -84
- package/src/embedding.js +256 -256
- package/src/export.js +67 -61
- package/src/forget.js +111 -111
- package/src/import.js +245 -123
- package/src/index.js +27 -20
- package/src/interference.js +51 -51
- package/src/introspect.js +48 -48
- package/src/llm.js +246 -240
- package/src/migrate.js +58 -58
- package/src/prompts.js +223 -223
- package/src/recall.js +352 -329
- package/src/rollback.js +42 -42
- package/src/ulid.js +18 -18
- package/src/utils.js +38 -38
- package/src/validate.js +172 -172
package/src/decay.js
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { computeConfidence, DEFAULT_HALF_LIVES, salienceModifier } from './confidence.js';
|
|
2
|
-
import { interferenceModifier } from './interference.js';
|
|
3
|
-
import { daysBetween } from './utils.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {import('better-sqlite3').Database} db
|
|
7
|
-
* @param {{ dormantThreshold?: number }} [options]
|
|
8
|
-
* @returns {{ totalEvaluated: number, transitionedToDormant: number, timestamp: string }}
|
|
9
|
-
*/
|
|
10
|
-
export function applyDecay(db, { dormantThreshold = 0.1, halfLives } = {}) {
|
|
11
|
-
const now = new Date();
|
|
12
|
-
let totalEvaluated = 0;
|
|
13
|
-
let transitionedToDormant = 0;
|
|
14
|
-
|
|
15
|
-
const semantics = db.prepare(`
|
|
16
|
-
SELECT id, supporting_count, contradicting_count, created_at,
|
|
17
|
-
last_reinforced_at, retrieval_count, interference_count, salience
|
|
18
|
-
FROM semantics WHERE state = 'active'
|
|
19
|
-
`).all();
|
|
20
|
-
|
|
21
|
-
const markDormantSem = db.prepare('UPDATE semantics SET state = ? WHERE id = ?');
|
|
22
|
-
|
|
23
|
-
for (const sem of semantics) {
|
|
24
|
-
totalEvaluated++;
|
|
25
|
-
const ageDays = daysBetween(sem.created_at, now);
|
|
26
|
-
const daysSinceRetrieval = sem.last_reinforced_at
|
|
27
|
-
? daysBetween(sem.last_reinforced_at, now)
|
|
28
|
-
: ageDays;
|
|
29
|
-
|
|
30
|
-
let confidence = computeConfidence({
|
|
31
|
-
sourceType: 'tool-result',
|
|
32
|
-
supportingCount: sem.supporting_count || 0,
|
|
33
|
-
contradictingCount: sem.contradicting_count || 0,
|
|
34
|
-
ageDays,
|
|
35
|
-
halfLifeDays: halfLives?.semantic ?? DEFAULT_HALF_LIVES.semantic,
|
|
36
|
-
retrievalCount: sem.retrieval_count || 0,
|
|
37
|
-
daysSinceRetrieval,
|
|
38
|
-
});
|
|
39
|
-
confidence *= interferenceModifier(sem.interference_count || 0);
|
|
40
|
-
confidence *= salienceModifier(sem.salience ?? 0.5);
|
|
41
|
-
confidence = Math.max(0, Math.min(1, confidence));
|
|
42
|
-
|
|
43
|
-
if (confidence < dormantThreshold) {
|
|
44
|
-
markDormantSem.run('dormant', sem.id);
|
|
45
|
-
transitionedToDormant++;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const procedures = db.prepare(`
|
|
50
|
-
SELECT id, success_count, failure_count, created_at,
|
|
51
|
-
last_reinforced_at, retrieval_count, interference_count, salience
|
|
52
|
-
FROM procedures WHERE state = 'active'
|
|
53
|
-
`).all();
|
|
54
|
-
|
|
55
|
-
const markDormantProc = db.prepare('UPDATE procedures SET state = ? WHERE id = ?');
|
|
56
|
-
|
|
57
|
-
for (const proc of procedures) {
|
|
58
|
-
totalEvaluated++;
|
|
59
|
-
const ageDays = daysBetween(proc.created_at, now);
|
|
60
|
-
const daysSinceRetrieval = proc.last_reinforced_at
|
|
61
|
-
? daysBetween(proc.last_reinforced_at, now)
|
|
62
|
-
: ageDays;
|
|
63
|
-
|
|
64
|
-
let confidence = computeConfidence({
|
|
65
|
-
sourceType: 'tool-result',
|
|
66
|
-
supportingCount: proc.success_count || 0,
|
|
67
|
-
contradictingCount: proc.failure_count || 0,
|
|
68
|
-
ageDays,
|
|
69
|
-
halfLifeDays: halfLives?.procedural ?? DEFAULT_HALF_LIVES.procedural,
|
|
70
|
-
retrievalCount: proc.retrieval_count || 0,
|
|
71
|
-
daysSinceRetrieval,
|
|
72
|
-
});
|
|
73
|
-
confidence *= interferenceModifier(proc.interference_count || 0);
|
|
74
|
-
confidence *= salienceModifier(proc.salience ?? 0.5);
|
|
75
|
-
confidence = Math.max(0, Math.min(1, confidence));
|
|
76
|
-
|
|
77
|
-
if (confidence < dormantThreshold) {
|
|
78
|
-
markDormantProc.run('dormant', proc.id);
|
|
79
|
-
transitionedToDormant++;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return { totalEvaluated, transitionedToDormant, timestamp: now.toISOString() };
|
|
84
|
-
}
|
|
1
|
+
import { computeConfidence, DEFAULT_HALF_LIVES, salienceModifier } from './confidence.js';
|
|
2
|
+
import { interferenceModifier } from './interference.js';
|
|
3
|
+
import { daysBetween } from './utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('better-sqlite3').Database} db
|
|
7
|
+
* @param {{ dormantThreshold?: number }} [options]
|
|
8
|
+
* @returns {{ totalEvaluated: number, transitionedToDormant: number, timestamp: string }}
|
|
9
|
+
*/
|
|
10
|
+
export function applyDecay(db, { dormantThreshold = 0.1, halfLives } = {}) {
|
|
11
|
+
const now = new Date();
|
|
12
|
+
let totalEvaluated = 0;
|
|
13
|
+
let transitionedToDormant = 0;
|
|
14
|
+
|
|
15
|
+
const semantics = db.prepare(`
|
|
16
|
+
SELECT id, supporting_count, contradicting_count, created_at,
|
|
17
|
+
last_reinforced_at, retrieval_count, interference_count, salience
|
|
18
|
+
FROM semantics WHERE state = 'active'
|
|
19
|
+
`).all();
|
|
20
|
+
|
|
21
|
+
const markDormantSem = db.prepare('UPDATE semantics SET state = ? WHERE id = ?');
|
|
22
|
+
|
|
23
|
+
for (const sem of semantics) {
|
|
24
|
+
totalEvaluated++;
|
|
25
|
+
const ageDays = daysBetween(sem.created_at, now);
|
|
26
|
+
const daysSinceRetrieval = sem.last_reinforced_at
|
|
27
|
+
? daysBetween(sem.last_reinforced_at, now)
|
|
28
|
+
: ageDays;
|
|
29
|
+
|
|
30
|
+
let confidence = computeConfidence({
|
|
31
|
+
sourceType: 'tool-result',
|
|
32
|
+
supportingCount: sem.supporting_count || 0,
|
|
33
|
+
contradictingCount: sem.contradicting_count || 0,
|
|
34
|
+
ageDays,
|
|
35
|
+
halfLifeDays: halfLives?.semantic ?? DEFAULT_HALF_LIVES.semantic,
|
|
36
|
+
retrievalCount: sem.retrieval_count || 0,
|
|
37
|
+
daysSinceRetrieval,
|
|
38
|
+
});
|
|
39
|
+
confidence *= interferenceModifier(sem.interference_count || 0);
|
|
40
|
+
confidence *= salienceModifier(sem.salience ?? 0.5);
|
|
41
|
+
confidence = Math.max(0, Math.min(1, confidence));
|
|
42
|
+
|
|
43
|
+
if (confidence < dormantThreshold) {
|
|
44
|
+
markDormantSem.run('dormant', sem.id);
|
|
45
|
+
transitionedToDormant++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const procedures = db.prepare(`
|
|
50
|
+
SELECT id, success_count, failure_count, created_at,
|
|
51
|
+
last_reinforced_at, retrieval_count, interference_count, salience
|
|
52
|
+
FROM procedures WHERE state = 'active'
|
|
53
|
+
`).all();
|
|
54
|
+
|
|
55
|
+
const markDormantProc = db.prepare('UPDATE procedures SET state = ? WHERE id = ?');
|
|
56
|
+
|
|
57
|
+
for (const proc of procedures) {
|
|
58
|
+
totalEvaluated++;
|
|
59
|
+
const ageDays = daysBetween(proc.created_at, now);
|
|
60
|
+
const daysSinceRetrieval = proc.last_reinforced_at
|
|
61
|
+
? daysBetween(proc.last_reinforced_at, now)
|
|
62
|
+
: ageDays;
|
|
63
|
+
|
|
64
|
+
let confidence = computeConfidence({
|
|
65
|
+
sourceType: 'tool-result',
|
|
66
|
+
supportingCount: proc.success_count || 0,
|
|
67
|
+
contradictingCount: proc.failure_count || 0,
|
|
68
|
+
ageDays,
|
|
69
|
+
halfLifeDays: halfLives?.procedural ?? DEFAULT_HALF_LIVES.procedural,
|
|
70
|
+
retrievalCount: proc.retrieval_count || 0,
|
|
71
|
+
daysSinceRetrieval,
|
|
72
|
+
});
|
|
73
|
+
confidence *= interferenceModifier(proc.interference_count || 0);
|
|
74
|
+
confidence *= salienceModifier(proc.salience ?? 0.5);
|
|
75
|
+
confidence = Math.max(0, Math.min(1, confidence));
|
|
76
|
+
|
|
77
|
+
if (confidence < dormantThreshold) {
|
|
78
|
+
markDormantProc.run('dormant', proc.id);
|
|
79
|
+
transitionedToDormant++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { totalEvaluated, transitionedToDormant, timestamp: now.toISOString() };
|
|
84
|
+
}
|