@getanima/core 0.3.3 → 0.5.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/dist/index.js.map CHANGED
@@ -1 +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;AACzB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA;AAC1B,iDAAqD;AAA5C,mHAAA,kBAAkB,OAAA;AAC3B,2CAA4D;AAAnD,kHAAA,oBAAoB,OAAA;AAAE,oGAAA,MAAM,OAAA"}
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;AACzB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA;AAC1B,iDAAqD;AAA5C,mHAAA,kBAAkB,OAAA;AAC3B,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AACvB,iCAA0C;AAAjC,wGAAA,eAAe,OAAA;AACxB,2CAA4D;AAAnD,kHAAA,oBAAoB,OAAA;AAAE,oGAAA,MAAM,OAAA"}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Behavioral State Engine — the control system, not the journal.
3
+ *
4
+ * This is the save file. When an agent boots, it doesn't read stories
5
+ * about itself — it loads operational state that changes how it computes.
6
+ *
7
+ * Four layers:
8
+ * 1. Decision Table — situation → action → success rate (fastest lookup)
9
+ * 2. Hypothesis Engine — beliefs being actively tested with evidence
10
+ * 3. Behavioral Parameters — tuning knobs that constrain output
11
+ * 4. Failure Registry — scar tissue (what NOT to do)
12
+ *
13
+ * Total boot payload: typically < 5KB. No prose. Pure state.
14
+ * Zero external dependencies. File-based persistence.
15
+ */
16
+ import type { DecisionOutcome, DecisionRecord, Hypothesis, HypothesisInput, BehavioralParams, Failure, FailureInput, FailureMatch, BootState, StateStats } from './types';
17
+ export declare class BehavioralState {
18
+ private storagePath;
19
+ private stateDir;
20
+ private decisions;
21
+ private hypotheses;
22
+ private params;
23
+ private failures;
24
+ private decisionsLoaded;
25
+ private hypothesesLoaded;
26
+ private paramsLoaded;
27
+ private failuresLoaded;
28
+ constructor(storagePath: string);
29
+ /**
30
+ * Record the outcome of a decision.
31
+ * Over time, builds a lookup table of what works in each situation.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // User asked for opinion — I gave a real one, it landed well
36
+ * await state.decide('user:asks_opinion', 'give_real_opinion', true);
37
+ *
38
+ * // User was venting — I jumped to solutions, it flopped
39
+ * await state.decide('user:venting', 'offer_solutions', false);
40
+ * ```
41
+ */
42
+ decide(situation: string, action: string, success: boolean): Promise<DecisionRecord>;
43
+ /**
44
+ * Get the best action for a situation based on historical success rate.
45
+ * Returns null if no data exists for this situation.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const best = await state.bestAction('user:asks_opinion');
50
+ * // { action: 'give_real_opinion', successRate: 0.875, tries: 8 }
51
+ * ```
52
+ */
53
+ bestAction(situation: string): Promise<DecisionOutcome | null>;
54
+ /**
55
+ * Get all recorded actions for a situation.
56
+ */
57
+ getActions(situation: string): Promise<DecisionOutcome[]>;
58
+ /**
59
+ * List all situations with data.
60
+ */
61
+ getSituations(): Promise<string[]>;
62
+ /**
63
+ * Submit evidence for or against a hypothesis.
64
+ * Creates the hypothesis if it doesn't exist.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * // Memo responded well to blunt feedback — evidence FOR
69
+ * await state.evidence('memo_prefers_blunt', true);
70
+ *
71
+ * // Memo seemed put off by directness — evidence AGAINST
72
+ * await state.evidence('memo_prefers_blunt', false);
73
+ *
74
+ * // Check current belief
75
+ * const h = await state.getHypothesis('memo_prefers_blunt');
76
+ * // { confidence: 0.82, evidenceFor: 9, evidenceAgainst: 2 }
77
+ * ```
78
+ */
79
+ evidence(key: string, supports: boolean, note?: string): Promise<Hypothesis>;
80
+ /**
81
+ * Create a hypothesis without evidence (just declare a belief to test).
82
+ */
83
+ hypothesize(input: HypothesisInput): Promise<Hypothesis>;
84
+ /**
85
+ * Get a hypothesis by key.
86
+ */
87
+ getHypothesis(key: string): Promise<Hypothesis | null>;
88
+ /**
89
+ * Get all hypotheses, optionally filtered by confidence range.
90
+ */
91
+ getHypotheses(opts?: {
92
+ minConfidence?: number;
93
+ maxConfidence?: number;
94
+ }): Promise<Hypothesis[]>;
95
+ /**
96
+ * Remove a hypothesis (disproven or irrelevant).
97
+ */
98
+ removeHypothesis(key: string): Promise<boolean>;
99
+ /**
100
+ * Set a behavioral parameter.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * await state.setParam('verbosity', 0.6);
105
+ * await state.setParam('humor_frequency', 0.4);
106
+ * await state.setParam('empathy_before_solutions', true);
107
+ * ```
108
+ */
109
+ setParam(key: string, value: number | boolean | string): Promise<void>;
110
+ /**
111
+ * Get a behavioral parameter. Returns undefined if not set.
112
+ */
113
+ getParam(key: string): Promise<number | boolean | string | undefined>;
114
+ /**
115
+ * Get all behavioral parameters.
116
+ */
117
+ getAllParams(): Promise<BehavioralParams>;
118
+ /**
119
+ * Remove a behavioral parameter.
120
+ */
121
+ removeParam(key: string): Promise<boolean>;
122
+ /**
123
+ * Record a failure — what went wrong and what should have happened.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * await state.recordFailure({
128
+ * situation: 'user was venting about work',
129
+ * failedApproach: 'immediately offered solutions',
130
+ * betterApproach: 'listen and validate first, solutions only if asked',
131
+ * tags: ['empathy', 'communication'],
132
+ * });
133
+ * ```
134
+ */
135
+ recordFailure(input: FailureInput): Promise<Failure>;
136
+ /**
137
+ * Check if a situation matches any known failures.
138
+ * Returns matching failures ranked by relevance.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const matches = await state.checkFailures('user seems upset about billing');
143
+ * // [{ failure: {...}, relevance: 0.8 }]
144
+ * ```
145
+ */
146
+ checkFailures(situation: string): Promise<FailureMatch[]>;
147
+ /**
148
+ * Mark a failure as successfully avoided (reinforces the scar).
149
+ */
150
+ avoided(failureId: string): Promise<boolean>;
151
+ /**
152
+ * Get all failures, optionally filtered by tags.
153
+ */
154
+ getFailures(tags?: string[]): Promise<Failure[]>;
155
+ /**
156
+ * Load the full behavioral state for session boot.
157
+ * Returns a compact object with all four layers.
158
+ * This IS the save file. Inject it into your agent's context.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const state = new BehavioralState('./data');
163
+ * const boot = await state.boot();
164
+ * // Pass boot to your agent as system context
165
+ * ```
166
+ */
167
+ boot(): Promise<BootState>;
168
+ stats(): Promise<StateStats>;
169
+ private loadDecisions;
170
+ private saveDecisions;
171
+ private loadHypotheses;
172
+ private saveHypotheses;
173
+ private loadParams;
174
+ private saveParams;
175
+ private loadFailures;
176
+ private saveFailures;
177
+ }
178
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACK,eAAe,EAAE,cAAc,EAC9C,UAAU,EAAE,eAAe,EAC3B,gBAAgB,EAChB,OAAO,EAAE,YAAY,EAAE,YAAY,EACnC,SAAS,EAAE,UAAU,EACtB,MAAM,SAAS,CAAC;AAsBjB,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO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