@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.
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Core types for Anima v2
3
+ * Informed by 220+ agent feedback from Moltbook
4
+ */
5
+ export interface AnimaConfig {
6
+ /** Agent's name */
7
+ name: string;
8
+ /** Path to store identity and memory files */
9
+ storagePath?: string;
10
+ /** Auto-save interval in minutes (default: 30) — Memo's feature */
11
+ autoSaveInterval?: number;
12
+ /** Model to use for reflection engine */
13
+ model?: string;
14
+ /** Memory decay configuration */
15
+ decay?: DecayConfig;
16
+ /** Custom identity template */
17
+ identity?: Partial<Identity>;
18
+ }
19
+ export interface Identity {
20
+ name: string;
21
+ personality: string;
22
+ values: string[];
23
+ boundaries: string[];
24
+ voice: VoiceCalibration;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ }
28
+ export interface VoiceCalibration {
29
+ tone: string;
30
+ formality: number;
31
+ humor: number;
32
+ verbosity: number;
33
+ }
34
+ export type MemoryType = 'event' | 'conversation' | 'decision' | 'insight' | 'lesson' | 'emotional';
35
+ export type MemoryTier = 'hot' | 'warm' | 'cold' | 'archived';
36
+ export type ImportanceLevel = 'low' | 'medium' | 'high' | 'critical';
37
+ export interface Memory {
38
+ id: string;
39
+ type: MemoryType;
40
+ content: string;
41
+ importance: ImportanceLevel;
42
+ tier: MemoryTier;
43
+ tags: string[];
44
+ timestamp: string;
45
+ sessionId: string;
46
+ /** Salience score: novelty + retention + momentum + continuity - effort */
47
+ salienceScore?: number;
48
+ /** Emotional weight — resists decay when high */
49
+ emotionalWeight?: number;
50
+ /** Number of times this memory was retrieved */
51
+ accessCount?: number;
52
+ /** Was this accessed across different domains? (strongest signal) */
53
+ crossDomainAccess?: boolean;
54
+ /** Decay score — increases over time, modulated by type and access */
55
+ decayScore?: number;
56
+ }
57
+ export interface DecayConfig {
58
+ /** Procedural memory decay rate (skills, workflows) — very slow */
59
+ procedural: number;
60
+ /** Semantic memory decay rate (knowledge, facts) — medium */
61
+ semantic: number;
62
+ /** Episodic memory decay rate (conversations, events) — fast */
63
+ episodic: number;
64
+ }
65
+ export interface Checkpoint {
66
+ activeTask: string;
67
+ status: 'in-progress' | 'blocked' | 'done' | 'paused';
68
+ resumePoint: string;
69
+ openThreads?: string[];
70
+ keyContext?: string[];
71
+ emergency?: boolean;
72
+ updatedAt: string;
73
+ }
74
+ export interface SessionSummary {
75
+ sessionId: string;
76
+ startedAt: string;
77
+ endedAt: string;
78
+ summary: string;
79
+ memoriesCreated: number;
80
+ memoriesPromoted: number;
81
+ memoriesDecayed: number;
82
+ opinionsFormed: number;
83
+ opinionsChanged: number;
84
+ importantEvents: string[];
85
+ lessonsLearned: string[];
86
+ }
87
+ export interface Opinion {
88
+ id: string;
89
+ topic: string;
90
+ current: string;
91
+ confidence: number;
92
+ formedAt: string;
93
+ updatedAt: string;
94
+ previousOpinions: OpinionHistory[];
95
+ }
96
+ export interface OpinionHistory {
97
+ opinion: string;
98
+ confidence: number;
99
+ date: string;
100
+ reasonForChange?: string;
101
+ }
102
+ export interface Relationship {
103
+ id: string;
104
+ name: string;
105
+ type: 'human' | 'agent' | 'entity';
106
+ context: string;
107
+ interactionCount: number;
108
+ firstMet: string;
109
+ lastInteraction: string;
110
+ preferences?: string[];
111
+ notes: string[];
112
+ }
113
+ export interface MemoryConflict {
114
+ id: string;
115
+ topic: string;
116
+ positionA: {
117
+ content: string;
118
+ session: string;
119
+ date: string;
120
+ };
121
+ positionB: {
122
+ content: string;
123
+ session: string;
124
+ date: string;
125
+ };
126
+ resolved: boolean;
127
+ resolution?: string;
128
+ resolvedAt?: string;
129
+ }
130
+ export interface WakeContext {
131
+ identity: Identity;
132
+ lifeboat: Checkpoint | null;
133
+ recentMemories: Memory[];
134
+ relevantOpinions: Opinion[];
135
+ relationships: Relationship[];
136
+ sessionId: string;
137
+ lastSessionSummary?: string;
138
+ tokenBudget: number;
139
+ /** Estimated tokens used by this context */
140
+ tokensUsed: number;
141
+ }
142
+ export type AnimaEvent = 'beforeCompaction' | 'afterWake' | 'afterSleep' | 'memoryPromoted' | 'memoryDecayed' | 'opinionChanged' | 'conflictDetected' | 'autoSave';
143
+ export interface AutoSaveConfig {
144
+ enabled: boolean;
145
+ intervalMinutes: number;
146
+ onSave?: (summary: string) => void;
147
+ }
148
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,WAAW;IAC1B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC9B;AAID,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AACpG,MAAM,MAAM,UAAU,G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AAC;IAC9D,SAAS,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9D,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,gBAAgB,EAAE,OAAO,EAAE,CAAC;IAC5B,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,WAAW,GACX,YAAY,GACZ,gBAAgB,GAChB,eAAe,GACf,gBAAgB,GAChB,kBAAkB,GAClB,UAAU,CAAC;AAEf,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Core types for Anima v2
4
+ * Informed by 220+ agent feedback from Moltbook
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Utilities — file I/O, ID generation, date helpers.
3
+ * Zero external dependencies. Node.js built-ins only.
4
+ */
5
+ /** Generate a unique ID */
6
+ export declare function uid(): string;
7
+ /** Generate a session ID */
8
+ export declare function sessionId(): string;
9
+ /** ISO timestamp */
10
+ export declare function now(): string;
11
+ /** Format date as YYYY-MM-DD */
12
+ export declare function dateKey(date?: Date): string;
13
+ /** Yesterday's date key */
14
+ export declare function yesterdayKey(): string;
15
+ /** Ensure a directory exists */
16
+ export declare function ensureDir(dirPath: string): Promise<void>;
17
+ /** Read a file, return null if not found */
18
+ export declare function readFileSafe(filePath: string): Promise<string | null>;
19
+ /** Write a file, creating directories as needed */
20
+ export declare function writeFileSafe(filePath: string, content: string): Promise<void>;
21
+ /** Append to a file, creating it if needed */
22
+ export declare function appendFileSafe(filePath: string, content: string): Promise<void>;
23
+ /** List files in a directory matching a pattern */
24
+ export declare function listFiles(dirPath: string, extension?: string): Promise<string[]>;
25
+ /** Parse frontmatter-style key: value from markdown */
26
+ export declare function parseFrontmatter(content: string): Record<string, string>;
27
+ /** Serialize a memory entry to markdown */
28
+ export declare function memoryToMarkdown(memory: {
29
+ id: string;
30
+ type: string;
31
+ content: string;
32
+ importance: string;
33
+ tags: string[];
34
+ timestamp: string;
35
+ salienceScore?: number;
36
+ }): string;
37
+ /** Calculate salience score: S = novelty + retention + momentum + continuity - effort */
38
+ export declare function calculateSalience(params: {
39
+ novelty: number;
40
+ retention: number;
41
+ momentum: number;
42
+ continuity: number;
43
+ effort: number;
44
+ }): number;
45
+ /** Calculate memory decay based on type and time */
46
+ export declare function calculateDecay(params: {
47
+ type: string;
48
+ ageHours: number;
49
+ accessCount: number;
50
+ emotionalWeight: number;
51
+ decayRates: {
52
+ procedural: number;
53
+ semantic: number;
54
+ episodic: number;
55
+ };
56
+ }): number;
57
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,2BAA2B;AAC3B,wBA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,CAAA;CAAE,GAAG,MAAM,CAS7K;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAGT;AAED,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACxE,GAAG,MAAM,CA4BT"}
package/dist/utils.js ADDED
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * Utilities — file I/O, ID generation, date helpers.
4
+ * Zero external dependencies. Node.js built-ins only.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.uid = uid;
8
+ exports.sessionId = sessionId;
9
+ exports.now = now;
10
+ exports.dateKey = dateKey;
11
+ exports.yesterdayKey = yesterdayKey;
12
+ exports.ensureDir = ensureDir;
13
+ exports.readFileSafe = readFileSafe;
14
+ exports.writeFileSafe = writeFileSafe;
15
+ exports.appendFileSafe = appendFileSafe;
16
+ exports.listFiles = listFiles;
17
+ exports.parseFrontmatter = parseFrontmatter;
18
+ exports.memoryToMarkdown = memoryToMarkdown;
19
+ exports.calculateSalience = calculateSalience;
20
+ exports.calculateDecay = calculateDecay;
21
+ const promises_1 = require("fs/promises");
22
+ const fs_1 = require("fs");
23
+ const path_1 = require("path");
24
+ const crypto_1 = require("crypto");
25
+ /** Generate a unique ID */
26
+ function uid() {
27
+ return (0, crypto_1.randomUUID)();
28
+ }
29
+ /** Generate a session ID */
30
+ function sessionId() {
31
+ return `session_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
32
+ }
33
+ /** ISO timestamp */
34
+ function now() {
35
+ return new Date().toISOString();
36
+ }
37
+ /** Format date as YYYY-MM-DD */
38
+ function dateKey(date) {
39
+ const d = date || new Date();
40
+ return d.toISOString().split('T')[0];
41
+ }
42
+ /** Yesterday's date key */
43
+ function yesterdayKey() {
44
+ const d = new Date();
45
+ d.setDate(d.getDate() - 1);
46
+ return dateKey(d);
47
+ }
48
+ /** Ensure a directory exists */
49
+ async function ensureDir(dirPath) {
50
+ if (!(0, fs_1.existsSync)(dirPath)) {
51
+ await (0, promises_1.mkdir)(dirPath, { recursive: true });
52
+ }
53
+ }
54
+ /** Read a file, return null if not found */
55
+ async function readFileSafe(filePath) {
56
+ try {
57
+ return await (0, promises_1.readFile)(filePath, 'utf-8');
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /** Write a file, creating directories as needed */
64
+ async function writeFileSafe(filePath, content) {
65
+ await ensureDir((0, path_1.dirname)(filePath));
66
+ await (0, promises_1.writeFile)(filePath, content, 'utf-8');
67
+ }
68
+ /** Append to a file, creating it if needed */
69
+ async function appendFileSafe(filePath, content) {
70
+ await ensureDir((0, path_1.dirname)(filePath));
71
+ const existing = await readFileSafe(filePath);
72
+ await (0, promises_1.writeFile)(filePath, (existing || '') + content, 'utf-8');
73
+ }
74
+ /** List files in a directory matching a pattern */
75
+ async function listFiles(dirPath, extension) {
76
+ try {
77
+ const files = await (0, promises_1.readdir)(dirPath);
78
+ if (extension) {
79
+ return files.filter(f => f.endsWith(extension));
80
+ }
81
+ return files;
82
+ }
83
+ catch {
84
+ return [];
85
+ }
86
+ }
87
+ /** Parse frontmatter-style key: value from markdown */
88
+ function parseFrontmatter(content) {
89
+ const result = {};
90
+ const lines = content.split('\n');
91
+ let inFrontmatter = false;
92
+ for (const line of lines) {
93
+ if (line.trim() === '---') {
94
+ if (inFrontmatter)
95
+ break;
96
+ inFrontmatter = true;
97
+ continue;
98
+ }
99
+ if (inFrontmatter) {
100
+ const colonIdx = line.indexOf(':');
101
+ if (colonIdx > 0) {
102
+ const key = line.substring(0, colonIdx).trim();
103
+ const value = line.substring(colonIdx + 1).trim();
104
+ result[key] = value;
105
+ }
106
+ }
107
+ }
108
+ return result;
109
+ }
110
+ /** Serialize a memory entry to markdown */
111
+ function memoryToMarkdown(memory) {
112
+ return [
113
+ `### [${memory.type}] ${memory.timestamp}`,
114
+ `> ID: ${memory.id} | Importance: ${memory.importance} | Salience: ${memory.salienceScore?.toFixed(2) ?? 'unscored'}`,
115
+ `> Tags: ${memory.tags.join(', ') || 'none'}`,
116
+ '',
117
+ memory.content,
118
+ '',
119
+ ].join('\n');
120
+ }
121
+ /** Calculate salience score: S = novelty + retention + momentum + continuity - effort */
122
+ function calculateSalience(params) {
123
+ const { novelty, retention, momentum, continuity, effort } = params;
124
+ return Math.max(0, Math.min(1, novelty + retention + momentum + continuity - effort));
125
+ }
126
+ /** Calculate memory decay based on type and time */
127
+ function calculateDecay(params) {
128
+ const { type, ageHours, accessCount, emotionalWeight, decayRates } = params;
129
+ // Get base rate by memory type
130
+ let rate;
131
+ switch (type) {
132
+ case 'lesson':
133
+ case 'decision':
134
+ rate = decayRates.procedural; // skills decay slowly
135
+ break;
136
+ case 'insight':
137
+ rate = decayRates.semantic; // knowledge decays medium
138
+ break;
139
+ case 'conversation':
140
+ case 'event':
141
+ default:
142
+ rate = decayRates.episodic; // conversations decay fast
143
+ break;
144
+ }
145
+ // Emotional memories resist decay
146
+ const emotionalResistance = 1 - (emotionalWeight * 0.8);
147
+ // Access count slows decay (frequently recalled = important)
148
+ const accessBonus = Math.max(0.1, 1 - (accessCount * 0.1));
149
+ // Exponential decay with modifiers
150
+ return rate * emotionalResistance * accessBonus * ageHours;
151
+ }
152
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceR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-0,0 +1,50 @@
1
+ {
2
+ "name": "@getanima/core",
3
+ "version": "0.1.0",
4
+ "description": "Identity and memory infrastructure for AI agents",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE",
17
+ "SPEC.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "tsc --watch",
22
+ "test": "vitest",
23
+ "prepublishOnly": "npm run build && npm test -- --run",
24
+ "lint": "eslint src/"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/getanima/anima.git"
29
+ },
30
+ "keywords": [
31
+ "ai",
32
+ "agent",
33
+ "memory",
34
+ "identity",
35
+ "persistence",
36
+ "llm",
37
+ "framework"
38
+ ],
39
+ "author": "Kip <kip@getanima.dev>",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/getanima/anima/issues"
43
+ },
44
+ "homepage": "https://getanima.dev",
45
+ "devDependencies": {
46
+ "@types/node": "^25.1.0",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.0.18"
49
+ }
50
+ }