@getanima/core 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 +182 -0
- package/SPEC.md +475 -0
- package/dist/anima.d.ts +104 -0
- package/dist/anima.d.ts.map +1 -0
- package/dist/anima.js +246 -0
- package/dist/anima.js.map +1 -0
- package/dist/identity.d.ts +50 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +209 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +81 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +356 -0
- package/dist/memory.js.map +1 -0
- package/dist/reflection.d.ts +33 -0
- package/dist/reflection.d.ts.map +1 -0
- package/dist/reflection.js +90 -0
- package/dist/reflection.js.map +1 -0
- package/dist/types.d.ts +148 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +57 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +152 -0
- package/dist/utils.js.map +1 -0
- package/package.json +50 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anima — Identity and memory infrastructure for AI agents.
|
|
4
|
+
*
|
|
5
|
+
* Give your AI agent a soul — not just a system prompt.
|
|
6
|
+
*
|
|
7
|
+
* @module @getanima/core
|
|
8
|
+
* @see https://getanima.dev
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ReflectionEngine = exports.IdentityManager = exports.MemoryEngine = exports.Anima = void 0;
|
|
12
|
+
var anima_1 = require("./anima");
|
|
13
|
+
Object.defineProperty(exports, "Anima", { enumerable: true, get: function () { return anima_1.Anima; } });
|
|
14
|
+
var memory_1 = require("./memory");
|
|
15
|
+
Object.defineProperty(exports, "MemoryEngine", { enumerable: true, get: function () { return memory_1.MemoryEngine; } });
|
|
16
|
+
var identity_1 = require("./identity");
|
|
17
|
+
Object.defineProperty(exports, "IdentityManager", { enumerable: true, get: function () { return identity_1.IdentityManager; } });
|
|
18
|
+
var reflection_1 = require("./reflection");
|
|
19
|
+
Object.defineProperty(exports, "ReflectionEngine", { enumerable: true, get: function () { return reflection_1.ReflectionEngine; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AACxB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA"}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Engine — storage, retrieval, consolidation, and decay.
|
|
3
|
+
*
|
|
4
|
+
* File-based. Markdown-native. Zero external dependencies.
|
|
5
|
+
*
|
|
6
|
+
* Storage layout:
|
|
7
|
+
* {storagePath}/
|
|
8
|
+
* SOUL.md — immutable identity
|
|
9
|
+
* NOW.md — lifeboat (20-line emergency context)
|
|
10
|
+
* MEMORY.md — curated long-term memory
|
|
11
|
+
* identity.json — structured identity data
|
|
12
|
+
* memory/
|
|
13
|
+
* YYYY-MM-DD.md — daily logs
|
|
14
|
+
* memories.json — structured memory index
|
|
15
|
+
* opinions/
|
|
16
|
+
* opinions.json — opinion tracker
|
|
17
|
+
*/
|
|
18
|
+
import type { Memory, MemoryType, ImportanceLevel, Checkpoint, DecayConfig, Opinion } from './types';
|
|
19
|
+
export declare class MemoryEngine {
|
|
20
|
+
private storagePath;
|
|
21
|
+
private memoryDir;
|
|
22
|
+
private decayConfig;
|
|
23
|
+
private memories;
|
|
24
|
+
private opinions;
|
|
25
|
+
private sessionId;
|
|
26
|
+
constructor(storagePath: string, sessionId: string, decayConfig?: Partial<DecayConfig>);
|
|
27
|
+
/** Store a new memory. Writes to daily log AND structured index. */
|
|
28
|
+
remember(input: {
|
|
29
|
+
content: string;
|
|
30
|
+
type?: MemoryType;
|
|
31
|
+
importance?: ImportanceLevel;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
emotionalWeight?: number;
|
|
34
|
+
}): Promise<Memory>;
|
|
35
|
+
/** Search memories by keyword matching. Returns ranked results. */
|
|
36
|
+
recall(query: string, limit?: number): Promise<Memory[]>;
|
|
37
|
+
/** Update the NOW.md lifeboat — call every 2 significant actions */
|
|
38
|
+
updateLifeboat(checkpoint: Checkpoint): Promise<void>;
|
|
39
|
+
/** Read the current lifeboat */
|
|
40
|
+
readLifeboat(): Promise<string | null>;
|
|
41
|
+
/** Read today's daily log */
|
|
42
|
+
readDailyLog(date?: string): Promise<string | null>;
|
|
43
|
+
/** Read yesterday's daily log */
|
|
44
|
+
readYesterdayLog(): Promise<string | null>;
|
|
45
|
+
/** Read MEMORY.md (curated long-term memory) */
|
|
46
|
+
readLongTerm(): Promise<string | null>;
|
|
47
|
+
/** Append to MEMORY.md */
|
|
48
|
+
writeLongTerm(content: string): Promise<void>;
|
|
49
|
+
/** Run decay on all memories. Call during reflection/sleep. */
|
|
50
|
+
runDecay(): Promise<{
|
|
51
|
+
decayed: number;
|
|
52
|
+
archived: number;
|
|
53
|
+
kept: number;
|
|
54
|
+
}>;
|
|
55
|
+
/** Record or update an opinion */
|
|
56
|
+
opine(input: {
|
|
57
|
+
topic: string;
|
|
58
|
+
opinion: string;
|
|
59
|
+
confidence: number;
|
|
60
|
+
}): Promise<Opinion>;
|
|
61
|
+
/** Get all opinions */
|
|
62
|
+
getOpinions(): Promise<Opinion[]>;
|
|
63
|
+
/** Emergency flush — call before context compression */
|
|
64
|
+
emergencyFlush(context: {
|
|
65
|
+
activeTask?: string;
|
|
66
|
+
criticalState?: string;
|
|
67
|
+
unsavedMemories?: string[];
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
/** Get all memories (for boot context) */
|
|
70
|
+
getRecentMemories(hours?: number): Promise<Memory[]>;
|
|
71
|
+
/** Get all memories */
|
|
72
|
+
getAllMemories(): Promise<Memory[]>;
|
|
73
|
+
private loadIndex;
|
|
74
|
+
private saveIndex;
|
|
75
|
+
private loadOpinions;
|
|
76
|
+
private saveOpinions;
|
|
77
|
+
private estimateNovelty;
|
|
78
|
+
private estimateContinuity;
|
|
79
|
+
private estimateEffort;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAc,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAUjH,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAAS;gBAEd,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC;IAStF,oEAAoE;IAC9D,QAAQ,CAAC,KAAK,EAAE;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,UAAU,CAAC,EAAE,eAAe,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,eAAe,CAAC,EAAE,MA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IA6BjB,0CAA0C;IACpC,iBAAiB,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ9D,uBAAuB;IACjB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAK3B,SAAS;YAWT,SAAS;YAOT,YAAY;YAWZ,YAAY;IAO1B,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,cAAc;CAOvB"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory Engine — storage, retrieval, consolidation, and decay.
|
|
4
|
+
*
|
|
5
|
+
* File-based. Markdown-native. Zero external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* Storage layout:
|
|
8
|
+
* {storagePath}/
|
|
9
|
+
* SOUL.md — immutable identity
|
|
10
|
+
* NOW.md — lifeboat (20-line emergency context)
|
|
11
|
+
* MEMORY.md — curated long-term memory
|
|
12
|
+
* identity.json — structured identity data
|
|
13
|
+
* memory/
|
|
14
|
+
* YYYY-MM-DD.md — daily logs
|
|
15
|
+
* memories.json — structured memory index
|
|
16
|
+
* opinions/
|
|
17
|
+
* opinions.json — opinion tracker
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.MemoryEngine = void 0;
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
|
+
const path_1 = require("path");
|
|
23
|
+
const DEFAULT_DECAY = {
|
|
24
|
+
procedural: 0.0003,
|
|
25
|
+
semantic: 0.001,
|
|
26
|
+
episodic: 0.003,
|
|
27
|
+
};
|
|
28
|
+
class MemoryEngine {
|
|
29
|
+
storagePath;
|
|
30
|
+
memoryDir;
|
|
31
|
+
decayConfig;
|
|
32
|
+
memories = [];
|
|
33
|
+
opinions = [];
|
|
34
|
+
sessionId;
|
|
35
|
+
constructor(storagePath, sessionId, decayConfig) {
|
|
36
|
+
this.storagePath = storagePath;
|
|
37
|
+
this.memoryDir = (0, path_1.join)(storagePath, 'memory');
|
|
38
|
+
this.sessionId = sessionId;
|
|
39
|
+
this.decayConfig = { ...DEFAULT_DECAY, ...decayConfig };
|
|
40
|
+
}
|
|
41
|
+
// ============ CORE: Remember ============
|
|
42
|
+
/** Store a new memory. Writes to daily log AND structured index. */
|
|
43
|
+
async remember(input) {
|
|
44
|
+
const memory = {
|
|
45
|
+
id: (0, utils_1.uid)(),
|
|
46
|
+
type: input.type || 'event',
|
|
47
|
+
content: input.content,
|
|
48
|
+
importance: input.importance || 'medium',
|
|
49
|
+
tier: 'hot',
|
|
50
|
+
tags: input.tags || [],
|
|
51
|
+
timestamp: (0, utils_1.now)(),
|
|
52
|
+
sessionId: this.sessionId,
|
|
53
|
+
salienceScore: undefined,
|
|
54
|
+
emotionalWeight: input.emotionalWeight || 0,
|
|
55
|
+
accessCount: 0,
|
|
56
|
+
crossDomainAccess: false,
|
|
57
|
+
decayScore: 0,
|
|
58
|
+
};
|
|
59
|
+
// Score salience
|
|
60
|
+
memory.salienceScore = (0, utils_1.calculateSalience)({
|
|
61
|
+
novelty: this.estimateNovelty(memory),
|
|
62
|
+
retention: 0, // new memory, no retention yet
|
|
63
|
+
momentum: 1, // just created = max momentum
|
|
64
|
+
continuity: this.estimateContinuity(memory),
|
|
65
|
+
effort: this.estimateEffort(memory),
|
|
66
|
+
});
|
|
67
|
+
// Promote to critical tier if needed
|
|
68
|
+
if (memory.importance === 'critical' || (memory.salienceScore && memory.salienceScore > 0.8)) {
|
|
69
|
+
memory.tier = 'hot';
|
|
70
|
+
}
|
|
71
|
+
// Write to daily log (markdown, human-readable)
|
|
72
|
+
const dailyPath = (0, path_1.join)(this.memoryDir, `${(0, utils_1.dateKey)()}.md`);
|
|
73
|
+
await (0, utils_1.appendFileSafe)(dailyPath, (0, utils_1.memoryToMarkdown)(memory));
|
|
74
|
+
// Write to structured index
|
|
75
|
+
this.memories.push(memory);
|
|
76
|
+
await this.saveIndex();
|
|
77
|
+
return memory;
|
|
78
|
+
}
|
|
79
|
+
// ============ CORE: Recall ============
|
|
80
|
+
/** Search memories by keyword matching. Returns ranked results. */
|
|
81
|
+
async recall(query, limit = 10) {
|
|
82
|
+
await this.loadIndex();
|
|
83
|
+
const queryLower = query.toLowerCase();
|
|
84
|
+
const queryWords = queryLower.split(/\s+/);
|
|
85
|
+
const scored = this.memories
|
|
86
|
+
.map(memory => {
|
|
87
|
+
const contentLower = memory.content.toLowerCase();
|
|
88
|
+
const tagsLower = memory.tags.map(t => t.toLowerCase());
|
|
89
|
+
// Simple relevance: word match count + tag match
|
|
90
|
+
let wordMatchScore = 0;
|
|
91
|
+
for (const word of queryWords) {
|
|
92
|
+
if (contentLower.includes(word))
|
|
93
|
+
wordMatchScore += 1;
|
|
94
|
+
if (tagsLower.some(t => t.includes(word)))
|
|
95
|
+
wordMatchScore += 2;
|
|
96
|
+
}
|
|
97
|
+
// No word matches = not relevant, skip entirely
|
|
98
|
+
if (wordMatchScore === 0)
|
|
99
|
+
return { memory, score: 0 };
|
|
100
|
+
let score = wordMatchScore;
|
|
101
|
+
// Boost by importance (only if words matched)
|
|
102
|
+
const importanceBoost = { low: 0, medium: 0.5, high: 1, critical: 2 };
|
|
103
|
+
score += importanceBoost[memory.importance] || 0;
|
|
104
|
+
// Boost by recency (memories from today score higher)
|
|
105
|
+
const ageMs = Date.now() - new Date(memory.timestamp).getTime();
|
|
106
|
+
const ageHours = ageMs / (1000 * 60 * 60);
|
|
107
|
+
if (ageHours < 24)
|
|
108
|
+
score += 1;
|
|
109
|
+
if (ageHours < 1)
|
|
110
|
+
score += 2;
|
|
111
|
+
// Boost by salience
|
|
112
|
+
score += (memory.salienceScore || 0) * 2;
|
|
113
|
+
// Track access
|
|
114
|
+
memory.accessCount = (memory.accessCount || 0) + 1;
|
|
115
|
+
return { memory, score };
|
|
116
|
+
})
|
|
117
|
+
.filter(({ score }) => score > 0)
|
|
118
|
+
.sort((a, b) => b.score - a.score)
|
|
119
|
+
.slice(0, limit);
|
|
120
|
+
// Save updated access counts
|
|
121
|
+
if (scored.length > 0) {
|
|
122
|
+
await this.saveIndex();
|
|
123
|
+
}
|
|
124
|
+
return scored.map(({ memory }) => memory);
|
|
125
|
+
}
|
|
126
|
+
// ============ CORE: Lifeboat (NOW.md) ============
|
|
127
|
+
/** Update the NOW.md lifeboat — call every 2 significant actions */
|
|
128
|
+
async updateLifeboat(checkpoint) {
|
|
129
|
+
const content = `# NOW.md — Lifeboat
|
|
130
|
+
*If you wake up with zero context, read this first.*
|
|
131
|
+
*Updated: ${checkpoint.updatedAt}*
|
|
132
|
+
|
|
133
|
+
## Active Task
|
|
134
|
+
${checkpoint.activeTask}
|
|
135
|
+
|
|
136
|
+
## Status
|
|
137
|
+
${checkpoint.status}
|
|
138
|
+
|
|
139
|
+
## Resume Point
|
|
140
|
+
${checkpoint.resumePoint}
|
|
141
|
+
|
|
142
|
+
${checkpoint.openThreads?.length ? `## Open Threads\n${checkpoint.openThreads.map(t => `- ${t}`).join('\n')}` : ''}
|
|
143
|
+
|
|
144
|
+
${checkpoint.keyContext?.length ? `## Key Context\n${checkpoint.keyContext.map(c => `- ${c}`).join('\n')}` : ''}
|
|
145
|
+
|
|
146
|
+
${checkpoint.emergency ? '⚠️ **EMERGENCY FLAG SET** — Something critical was happening when this was saved.' : ''}
|
|
147
|
+
`;
|
|
148
|
+
await (0, utils_1.writeFileSafe)((0, path_1.join)(this.storagePath, 'NOW.md'), content);
|
|
149
|
+
}
|
|
150
|
+
/** Read the current lifeboat */
|
|
151
|
+
async readLifeboat() {
|
|
152
|
+
return (0, utils_1.readFileSafe)((0, path_1.join)(this.storagePath, 'NOW.md'));
|
|
153
|
+
}
|
|
154
|
+
// ============ CORE: Daily Log ============
|
|
155
|
+
/** Read today's daily log */
|
|
156
|
+
async readDailyLog(date) {
|
|
157
|
+
const key = date || (0, utils_1.dateKey)();
|
|
158
|
+
return (0, utils_1.readFileSafe)((0, path_1.join)(this.memoryDir, `${key}.md`));
|
|
159
|
+
}
|
|
160
|
+
/** Read yesterday's daily log */
|
|
161
|
+
async readYesterdayLog() {
|
|
162
|
+
return (0, utils_1.readFileSafe)((0, path_1.join)(this.memoryDir, `${(0, utils_1.yesterdayKey)()}.md`));
|
|
163
|
+
}
|
|
164
|
+
// ============ CORE: Long-term Memory ============
|
|
165
|
+
/** Read MEMORY.md (curated long-term memory) */
|
|
166
|
+
async readLongTerm() {
|
|
167
|
+
return (0, utils_1.readFileSafe)((0, path_1.join)(this.storagePath, 'MEMORY.md'));
|
|
168
|
+
}
|
|
169
|
+
/** Append to MEMORY.md */
|
|
170
|
+
async writeLongTerm(content) {
|
|
171
|
+
await (0, utils_1.appendFileSafe)((0, path_1.join)(this.storagePath, 'MEMORY.md'), '\n' + content + '\n');
|
|
172
|
+
}
|
|
173
|
+
// ============ MEMORY DECAY ============
|
|
174
|
+
/** Run decay on all memories. Call during reflection/sleep. */
|
|
175
|
+
async runDecay() {
|
|
176
|
+
await this.loadIndex();
|
|
177
|
+
let decayed = 0;
|
|
178
|
+
let archived = 0;
|
|
179
|
+
let kept = 0;
|
|
180
|
+
for (const memory of this.memories) {
|
|
181
|
+
const ageMs = Date.now() - new Date(memory.timestamp).getTime();
|
|
182
|
+
const ageHours = ageMs / (1000 * 60 * 60);
|
|
183
|
+
memory.decayScore = (0, utils_1.calculateDecay)({
|
|
184
|
+
type: memory.type,
|
|
185
|
+
ageHours,
|
|
186
|
+
accessCount: memory.accessCount || 0,
|
|
187
|
+
emotionalWeight: memory.emotionalWeight || 0,
|
|
188
|
+
decayRates: this.decayConfig,
|
|
189
|
+
});
|
|
190
|
+
// Recalculate salience with updated decay
|
|
191
|
+
memory.salienceScore = (0, utils_1.calculateSalience)({
|
|
192
|
+
novelty: this.estimateNovelty(memory),
|
|
193
|
+
retention: Math.min(1, (memory.accessCount || 0) * 0.2),
|
|
194
|
+
momentum: Math.max(0, 1 - (ageHours / 168)), // decays over a week
|
|
195
|
+
continuity: this.estimateContinuity(memory),
|
|
196
|
+
effort: this.estimateEffort(memory),
|
|
197
|
+
});
|
|
198
|
+
// Apply tier transitions
|
|
199
|
+
if (memory.salienceScore < 0.2 && memory.importance !== 'critical') {
|
|
200
|
+
if (memory.tier !== 'archived') {
|
|
201
|
+
memory.tier = 'archived';
|
|
202
|
+
archived++;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
decayed++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (memory.salienceScore < 0.5) {
|
|
209
|
+
memory.tier = 'cold';
|
|
210
|
+
kept++;
|
|
211
|
+
}
|
|
212
|
+
else if (memory.salienceScore < 0.7) {
|
|
213
|
+
memory.tier = 'warm';
|
|
214
|
+
kept++;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
memory.tier = 'hot';
|
|
218
|
+
kept++;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Remove fully decayed memories (archived + salience near 0)
|
|
222
|
+
this.memories = this.memories.filter(m => m.tier !== 'archived' || m.salienceScore > 0.05 || m.importance === 'critical');
|
|
223
|
+
await this.saveIndex();
|
|
224
|
+
return { decayed, archived, kept };
|
|
225
|
+
}
|
|
226
|
+
// ============ OPINIONS ============
|
|
227
|
+
/** Record or update an opinion */
|
|
228
|
+
async opine(input) {
|
|
229
|
+
await this.loadOpinions();
|
|
230
|
+
const existing = this.opinions.find(o => o.topic.toLowerCase() === input.topic.toLowerCase());
|
|
231
|
+
if (existing) {
|
|
232
|
+
// Track opinion evolution
|
|
233
|
+
existing.previousOpinions.push({
|
|
234
|
+
opinion: existing.current,
|
|
235
|
+
confidence: existing.confidence,
|
|
236
|
+
date: existing.updatedAt,
|
|
237
|
+
reasonForChange: `Updated to: ${input.opinion}`,
|
|
238
|
+
});
|
|
239
|
+
existing.current = input.opinion;
|
|
240
|
+
existing.confidence = input.confidence;
|
|
241
|
+
existing.updatedAt = (0, utils_1.now)();
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const newOpinion = {
|
|
245
|
+
id: (0, utils_1.uid)(),
|
|
246
|
+
topic: input.topic,
|
|
247
|
+
current: input.opinion,
|
|
248
|
+
confidence: input.confidence,
|
|
249
|
+
formedAt: (0, utils_1.now)(),
|
|
250
|
+
updatedAt: (0, utils_1.now)(),
|
|
251
|
+
previousOpinions: [],
|
|
252
|
+
};
|
|
253
|
+
this.opinions.push(newOpinion);
|
|
254
|
+
}
|
|
255
|
+
await this.saveOpinions();
|
|
256
|
+
return existing || this.opinions[this.opinions.length - 1];
|
|
257
|
+
}
|
|
258
|
+
/** Get all opinions */
|
|
259
|
+
async getOpinions() {
|
|
260
|
+
await this.loadOpinions();
|
|
261
|
+
return [...this.opinions];
|
|
262
|
+
}
|
|
263
|
+
// ============ PRE-COMPACTION HOOK ============
|
|
264
|
+
/** Emergency flush — call before context compression */
|
|
265
|
+
async emergencyFlush(context) {
|
|
266
|
+
// Save lifeboat
|
|
267
|
+
await this.updateLifeboat({
|
|
268
|
+
activeTask: context.activeTask || 'Unknown — emergency flush triggered',
|
|
269
|
+
status: 'in-progress',
|
|
270
|
+
resumePoint: 'Resumed from emergency flush',
|
|
271
|
+
keyContext: context.unsavedMemories || [],
|
|
272
|
+
emergency: true,
|
|
273
|
+
updatedAt: (0, utils_1.now)(),
|
|
274
|
+
});
|
|
275
|
+
// Save any unsaved memories
|
|
276
|
+
if (context.unsavedMemories) {
|
|
277
|
+
for (const content of context.unsavedMemories) {
|
|
278
|
+
await this.remember({
|
|
279
|
+
content: `[EMERGENCY FLUSH] ${content}`,
|
|
280
|
+
type: 'event',
|
|
281
|
+
importance: 'high',
|
|
282
|
+
tags: ['emergency-flush', 'pre-compaction'],
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// Force save index
|
|
287
|
+
await this.saveIndex();
|
|
288
|
+
}
|
|
289
|
+
// ============ INTERNAL ============
|
|
290
|
+
/** Get all memories (for boot context) */
|
|
291
|
+
async getRecentMemories(hours = 48) {
|
|
292
|
+
await this.loadIndex();
|
|
293
|
+
const cutoff = Date.now() - (hours * 60 * 60 * 1000);
|
|
294
|
+
return this.memories
|
|
295
|
+
.filter(m => new Date(m.timestamp).getTime() > cutoff)
|
|
296
|
+
.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
297
|
+
}
|
|
298
|
+
/** Get all memories */
|
|
299
|
+
async getAllMemories() {
|
|
300
|
+
await this.loadIndex();
|
|
301
|
+
return [...this.memories];
|
|
302
|
+
}
|
|
303
|
+
async loadIndex() {
|
|
304
|
+
const raw = await (0, utils_1.readFileSafe)((0, path_1.join)(this.memoryDir, 'memories.json'));
|
|
305
|
+
if (raw) {
|
|
306
|
+
try {
|
|
307
|
+
this.memories = JSON.parse(raw);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
this.memories = [];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async saveIndex() {
|
|
315
|
+
await (0, utils_1.writeFileSafe)((0, path_1.join)(this.memoryDir, 'memories.json'), JSON.stringify(this.memories, null, 2));
|
|
316
|
+
}
|
|
317
|
+
async loadOpinions() {
|
|
318
|
+
const raw = await (0, utils_1.readFileSafe)((0, path_1.join)(this.storagePath, 'opinions', 'opinions.json'));
|
|
319
|
+
if (raw) {
|
|
320
|
+
try {
|
|
321
|
+
this.opinions = JSON.parse(raw);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
this.opinions = [];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async saveOpinions() {
|
|
329
|
+
await (0, utils_1.writeFileSafe)((0, path_1.join)(this.storagePath, 'opinions', 'opinions.json'), JSON.stringify(this.opinions, null, 2));
|
|
330
|
+
}
|
|
331
|
+
estimateNovelty(memory) {
|
|
332
|
+
// Simple heuristic: longer content = potentially more novel
|
|
333
|
+
const lengthScore = Math.min(1, memory.content.length / 500);
|
|
334
|
+
// Critical/emotional = more novel
|
|
335
|
+
const importanceBoost = memory.importance === 'critical' ? 0.3 : 0;
|
|
336
|
+
const emotionalBoost = (memory.emotionalWeight || 0) * 0.2;
|
|
337
|
+
return Math.min(1, lengthScore + importanceBoost + emotionalBoost);
|
|
338
|
+
}
|
|
339
|
+
estimateContinuity(memory) {
|
|
340
|
+
// How connected is this to other memories?
|
|
341
|
+
// Simple: check tag overlap
|
|
342
|
+
if (memory.tags.length === 0)
|
|
343
|
+
return 0.1;
|
|
344
|
+
const taggedMemories = this.memories.filter(m => m.id !== memory.id && m.tags.some(t => memory.tags.includes(t)));
|
|
345
|
+
return Math.min(1, taggedMemories.length * 0.2);
|
|
346
|
+
}
|
|
347
|
+
estimateEffort(memory) {
|
|
348
|
+
// How costly is this memory to reconstruct?
|
|
349
|
+
// Simple: longer = more effort, more tags = less effort (better indexed)
|
|
350
|
+
const lengthCost = Math.min(0.5, memory.content.length / 1000);
|
|
351
|
+
const tagBenefit = Math.min(0.3, memory.tags.length * 0.1);
|
|
352
|
+
return Math.max(0, lengthCost - tagBenefit);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
exports.MemoryEngine = MemoryEngine;
|
|
356
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAGH,mCAAuK;AACvK,+BAA4B;AAE5B,MAAM,aAAa,GAAgB;IACjC,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;CAChB,CAAC;AAEF,MAAa,YAAY;IACf,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,WAAW,CAAc;IACzB,QAAQ,GAAa,EAAE,CAAC;IACxB,QAAQ,GAAc,EAAE,CAAC;IACzB,SAAS,CAAS;IAE1B,YAAY,WAAmB,EAAE,SAAiB,EAAE,WAA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, memory promotion.
|
|
3
|
+
*
|
|
4
|
+
* This runs during explicit reflection periods (end of session, scheduled reviews).
|
|
5
|
+
* Never during task execution — that's a core principle.
|
|
6
|
+
*/
|
|
7
|
+
import type { Memory } from './types';
|
|
8
|
+
import { MemoryEngine } from './memory';
|
|
9
|
+
import { IdentityManager } from './identity';
|
|
10
|
+
export declare class ReflectionEngine {
|
|
11
|
+
private storagePath;
|
|
12
|
+
private memory;
|
|
13
|
+
private identity;
|
|
14
|
+
constructor(storagePath: string, memory: MemoryEngine, identity: IdentityManager);
|
|
15
|
+
/**
|
|
16
|
+
* Promote important daily memories to MEMORY.md (long-term).
|
|
17
|
+
* Call during reflection periods.
|
|
18
|
+
*/
|
|
19
|
+
promoteToDurable(memories: Memory[]): Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Generate a daily review summary.
|
|
22
|
+
* Distills the day's events into key takeaways.
|
|
23
|
+
*/
|
|
24
|
+
generateDailyReview(): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Check for memory conflicts — when different sessions have contradictory beliefs.
|
|
27
|
+
*/
|
|
28
|
+
detectConflicts(): Promise<Array<{
|
|
29
|
+
topic: string;
|
|
30
|
+
memories: Memory[];
|
|
31
|
+
}>>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=reflection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection.d.ts","sourceRoot":"","sources":["../src/reflection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAA2B,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe;IAMhF;;;OAGG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB3D;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAiC5C;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CAmB/E"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reflection Engine — self-assessment, growth tracking, memory promotion.
|
|
4
|
+
*
|
|
5
|
+
* This runs during explicit reflection periods (end of session, scheduled reviews).
|
|
6
|
+
* Never during task execution — that's a core principle.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ReflectionEngine = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
class ReflectionEngine {
|
|
12
|
+
storagePath;
|
|
13
|
+
memory;
|
|
14
|
+
identity;
|
|
15
|
+
constructor(storagePath, memory, identity) {
|
|
16
|
+
this.storagePath = storagePath;
|
|
17
|
+
this.memory = memory;
|
|
18
|
+
this.identity = identity;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Promote important daily memories to MEMORY.md (long-term).
|
|
22
|
+
* Call during reflection periods.
|
|
23
|
+
*/
|
|
24
|
+
async promoteToDurable(memories) {
|
|
25
|
+
const highValue = memories.filter(m => m.importance === 'critical' ||
|
|
26
|
+
m.importance === 'high' ||
|
|
27
|
+
(m.salienceScore && m.salienceScore > 0.6) ||
|
|
28
|
+
(m.emotionalWeight && m.emotionalWeight > 0.5));
|
|
29
|
+
if (highValue.length === 0)
|
|
30
|
+
return 0;
|
|
31
|
+
const entries = highValue.map(m => `- **[${m.type}]** ${m.content} *(${m.timestamp})*`).join('\n');
|
|
32
|
+
const section = `\n## ${(0, utils_1.dateKey)()} — Promoted Memories\n${entries}\n`;
|
|
33
|
+
await this.memory.writeLongTerm(section);
|
|
34
|
+
return highValue.length;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate a daily review summary.
|
|
38
|
+
* Distills the day's events into key takeaways.
|
|
39
|
+
*/
|
|
40
|
+
async generateDailyReview() {
|
|
41
|
+
const allMemories = await this.memory.getAllMemories();
|
|
42
|
+
const today = (0, utils_1.dateKey)();
|
|
43
|
+
const todayMemories = allMemories.filter(m => m.timestamp.startsWith(today));
|
|
44
|
+
const byType = {};
|
|
45
|
+
const highImportance = [];
|
|
46
|
+
const lessons = [];
|
|
47
|
+
for (const m of todayMemories) {
|
|
48
|
+
byType[m.type] = (byType[m.type] || 0) + 1;
|
|
49
|
+
if (m.importance === 'high' || m.importance === 'critical') {
|
|
50
|
+
highImportance.push(m.content);
|
|
51
|
+
}
|
|
52
|
+
if (m.type === 'lesson' || m.type === 'insight') {
|
|
53
|
+
lessons.push(m.content);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const review = [
|
|
57
|
+
`# Daily Review — ${today}`,
|
|
58
|
+
'',
|
|
59
|
+
`## Summary`,
|
|
60
|
+
`Total memories: ${todayMemories.length}`,
|
|
61
|
+
`By type: ${Object.entries(byType).map(([k, v]) => `${k}(${v})`).join(', ')}`,
|
|
62
|
+
'',
|
|
63
|
+
highImportance.length > 0 ? `## Important Events\n${highImportance.map(e => `- ${e}`).join('\n')}` : '',
|
|
64
|
+
lessons.length > 0 ? `## Lessons & Insights\n${lessons.map(l => `- ${l}`).join('\n')}` : '',
|
|
65
|
+
].filter(Boolean).join('\n');
|
|
66
|
+
return review;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check for memory conflicts — when different sessions have contradictory beliefs.
|
|
70
|
+
*/
|
|
71
|
+
async detectConflicts() {
|
|
72
|
+
const opinions = await this.memory.getOpinions();
|
|
73
|
+
const conflicts = [];
|
|
74
|
+
for (const opinion of opinions) {
|
|
75
|
+
if (opinion.previousOpinions.length > 0) {
|
|
76
|
+
// This opinion has changed — potential conflict
|
|
77
|
+
const relatedMemories = await this.memory.recall(opinion.topic, 5);
|
|
78
|
+
if (relatedMemories.length > 1) {
|
|
79
|
+
conflicts.push({
|
|
80
|
+
topic: opinion.topic,
|
|
81
|
+
memories: relatedMemories,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return conflicts;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.ReflectionEngine = ReflectionEngine;
|
|
90
|
+
//# sourceMappingURL=reflection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection.js","sourceRoot":"","sources":["../src/reflection.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAKH,mCAAoE;AAGpE,MAAa,gBAAgB;IACnB,WAAW,CAAS;IACpB,MAAM,CAAe;IACrB,QAAQ,CAAkB;IAElC,YAAY,WAAmB,EAAE,MAAoB,EAAE,QAAyB;QAC9E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,gBAAgB,CAAC,QAAkB;QACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CACpC,CAAC,CAAC,UAAU,KAAK,UAAU;YAC3B,CAAC,CAAC,UAAU,KAAK,MAAM;YACvB,CAAC,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,aAAa,GAAG,GAAG,CAAC;YAC1C,CAAC,CAAC,CAAC,eAAe,IAAI,CAAC,CAAC,eAAe,GAAG,GAAG,CAAC,CAC/C,CAAC;QAEF,IAAI,S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