totemheart 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Totemheart
2
2
 
3
- ![Totemheart banner](docs/banner.png)
3
+ ![Totemheart banner](https://raw.githubusercontent.com/AlejoMalia/Totemheart/main/docs/banner.png)
4
4
 
5
5
  [![License](https://img.shields.io/badge/license-MIT-blue?style=plastic)](LICENSE)
6
6
  [![Calibration](https://img.shields.io/badge/calibration-citation%20ledger-8a2be2?style=plastic)](CALIBRATION.md)
7
- [![Version](https://img.shields.io/badge/version-0.1.1-a1b858?style=plastic)](package.json)
7
+ [![Version](https://img.shields.io/badge/version-0.1.2-a1b858?style=plastic)](package.json)
8
8
  [![Node](https://img.shields.io/badge/node-%3E%3D18-339933?style=plastic&logo=node.js&logoColor=white)](package.json)
9
- [![Tests](https://img.shields.io/badge/tests-91%20passing-brightgreen?style=plastic)](test/smoke.test.js)
9
+ [![Tests](https://img.shields.io/badge/tests-2298%20passing-brightgreen?style=plastic)](test)
10
10
  [![Mechanisms verified](https://img.shields.io/badge/mechanisms-72%20verified%20%2F%206%20covered%20%2F%200%20failed-brightgreen?style=plastic)](examples/verify-all-mechanisms.js)
11
11
 
12
- > The Tests/Mechanisms badges above are static, last updated by hand from a real local `npm test` / `npm run verify` run. There's no CI wired yet to keep them live, so treat them as a snapshot, not a guarantee they still pass on `main`. Two later mechanism rounds (the 10 dynamics upgrades and `LoveHateEngine`) each ship their own dedicated live audit instead of being folded into the `verify` script above: `npm run upgrade-round-mock` (39/39) and `npm run lovehate-mock` (24/24).
12
+ > The Tests/Mechanisms badges above are static, last updated by hand from a real local `npm test` / `npm run verify` run. There's no CI wired yet to keep them live, so treat them as a snapshot, not a guarantee they still pass on `main`. Two later mechanism rounds (the 10 dynamics upgrades and `LoveHateEngine`) each ship their own dedicated live audit instead of being folded into the `verify` script above: `npm run upgrade-round-mock` (39/39) and `npm run lovehate-mock` (24/24). `npm test` runs [`test/`](test) in full: `regression/` (92, bug-fix guards and basic sanity), `integration/` (177, directed multi-mechanism scenarios, full-pipeline emergency routes crossed through real consecutive turns, exhaustive field-by-field serialization, malformed/hostile-input robustness, concurrent `processInput()` calls, real `OllamaProvider` unreachable-host fallback, and non-ES/EN language input), and `property/` (2029, deterministic parameter-grid checks over exact boundaries, combined-extreme OCEAN personality corners, and long-horizon saturation limits including 5000-turn memory/mood-window boundedness — no randomness, same result every run).
13
13
 
14
14
  **Totemheart** is a deterministic control kernel for persistent cognition, not a sentiment classifier and not a prompt-engineering trick. It gives an AI a *consistent inner life* across a conversation: personality, mood, memory, stress, and social dynamics that persist and evolve through real control-theory and neuroscience-derived math, instead of every reply being computed from scratch off a mood label. See [What this actually is](#what-this-actually-is) below before you build on top of it.
15
15
 
@@ -176,7 +176,7 @@ yarn add totemheart
176
176
  ```js
177
177
  import { Totemheart, Personality, VERSION } from 'totemheart'
178
178
 
179
- console.log( VERSION ) // '0.1.1', also available as Totemheart.VERSION and in toJSON().version
179
+ console.log( VERSION ) // '0.1.2', also available as Totemheart.VERSION and in toJSON().version
180
180
 
181
181
  const ai = new Totemheart( {
182
182
  personality: new Personality( { neuroticism: 0.7, agreeableness: 0.3 } ),
package/package.json CHANGED
@@ -1,64 +1,65 @@
1
1
  {
2
- "name": "totemheart",
3
- "version": "0.1.1",
4
- "description": "Totemheart is a modular emotional-simulation engine for AI: personality, mood, neurochemical dynamics, cognitive biases and social mechanics wired into a single pipeline that drives emotionally coherent, stateful behavior over a conversation.",
5
- "main": "src/index.js",
6
- "type": "module",
7
- "engines": {
8
- "node": ">=18"
9
- },
10
- "files": [
11
- "src"
12
- ],
13
- "keywords": [
14
- "totemheart",
15
- "library",
16
- "web",
17
- "intelligence",
18
- "ia",
19
- "emotion-engine",
20
- "personality",
21
- "robotic",
22
- "framework"
23
- ],
24
- "author": "Alejo Malia <alejomalia@gmail.com>",
25
- "license": "MIT",
26
- "publishConfig": {
27
- "access": "public",
28
- "registry": "https://registry.npmjs.org/"
29
- },
30
- "devDependencies": {
31
- "@typescript-eslint/eslint-plugin": "8.2.0",
32
- "@typescript-eslint/parser": "8.2.0",
33
- "eslint": "8.57.0",
34
- "eslint-plugin-align-assignments": "1.1.2",
35
- "eslint-plugin-align-import": "1.0.0",
36
- "eslint-plugin-canonical": "5.0.0",
37
- "eslint-plugin-html": "7.1.0",
38
- "eslint-plugin-import": "2.29.1",
39
- "eslint-plugin-jsdoc": "46.10.1",
40
- "eslint-plugin-json": "3.1.0",
41
- "eslint-plugin-jsonc": "2.13.0",
42
- "eslint-plugin-markdownlint": "0.5.0",
43
- "eslint-plugin-package-json": "0.12.2",
44
- "eslint-plugin-promise": "6.1.1",
45
- "eslint-plugin-yaml": "0.5.0",
46
- "typescript": "5.6.2",
47
- "vite": "5.4.4"
48
- },
49
- "extra": {
50
- "id": "totemheart",
51
- "productName": "Totemheart"
52
- },
53
- "scripts": {
54
- "demo": "node examples/demo.js",
55
- "verify": "node examples/verify-all-mechanisms.js",
56
- "stress-test": "node examples/full-stress-test.js",
57
- "personality-mock": "node examples/personality-mock.js",
58
- "rem-mock": "node examples/rem-conversation-mock.js",
59
- "exhaustive-audit": "node examples/exhaustive-audit-mock.js",
60
- "upgrade-round-mock": "node examples/upgrade-round-mock.js",
61
- "lovehate-mock": "node examples/lovehate-mock.js",
62
- "test": "node --test test/*.test.js"
63
- }
64
- }
2
+ "name": "totemheart",
3
+ "version": "0.1.2",
4
+ "description": "Totemheart is a modular emotional-simulation engine for AI: personality, mood, neurochemical dynamics, cognitive biases and social mechanics wired into a single pipeline that drives emotionally coherent, stateful behavior over a conversation.",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "scripts": {
14
+ "demo": "node examples/demo.js",
15
+ "verify": "node examples/verify-all-mechanisms.js",
16
+ "stress-test": "node examples/full-stress-test.js",
17
+ "personality-mock": "node examples/personality-mock.js",
18
+ "rem-mock": "node examples/rem-conversation-mock.js",
19
+ "exhaustive-audit": "node examples/exhaustive-audit-mock.js",
20
+ "upgrade-round-mock": "node examples/upgrade-round-mock.js",
21
+ "lovehate-mock": "node examples/lovehate-mock.js",
22
+ "test": "node --test test/regression/*.test.js test/integration/*.test.js test/property/*.test.js"
23
+ },
24
+ "keywords": [
25
+ "totemheart",
26
+ "library",
27
+ "web",
28
+ "intelligence",
29
+ "ia",
30
+ "emotion-engine",
31
+ "personality",
32
+ "robotic",
33
+ "framework"
34
+ ],
35
+ "author": "Alejo Malia <alejomalia@gmail.com>",
36
+ "license": "MIT",
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/"
40
+ },
41
+ "packageManager": "pnpm@9.7.0",
42
+ "devDependencies": {
43
+ "@typescript-eslint/eslint-plugin": "8.2.0",
44
+ "@typescript-eslint/parser": "8.2.0",
45
+ "eslint": "8.57.0",
46
+ "eslint-plugin-align-assignments": "1.1.2",
47
+ "eslint-plugin-align-import": "1.0.0",
48
+ "eslint-plugin-canonical": "5.0.0",
49
+ "eslint-plugin-html": "7.1.0",
50
+ "eslint-plugin-import": "2.29.1",
51
+ "eslint-plugin-jsdoc": "46.10.1",
52
+ "eslint-plugin-json": "3.1.0",
53
+ "eslint-plugin-jsonc": "2.13.0",
54
+ "eslint-plugin-markdownlint": "0.5.0",
55
+ "eslint-plugin-package-json": "0.12.2",
56
+ "eslint-plugin-promise": "6.1.1",
57
+ "eslint-plugin-yaml": "0.5.0",
58
+ "typescript": "5.6.2",
59
+ "vite": "5.4.4"
60
+ },
61
+ "extra": {
62
+ "id": "totemheart",
63
+ "productName": "Totemheart"
64
+ }
65
+ }
package/src/Totemheart.js CHANGED
@@ -394,6 +394,13 @@ export class Totemheart {
394
394
  delayMs : 0,
395
395
  styleTags : [ 'freeze', overload.reason ],
396
396
  emotionalState : this.getEmotionalState(),
397
+ // A real, if not brand-new-turn-driven, systemPrompt — this text is
398
+ // already final (not meant for another LLM completion this turn), but
399
+ // a host that unconditionally reads result.systemPrompt on every
400
+ // response (the documented Usage pattern) should still get a real
401
+ // string here, not undefined. Found by IntelligentMockGenerator's
402
+ // systemPrompt_generated_without_error invariant — see test/generated/.
403
+ systemPrompt : this.getSystemPrompt( { userId } ),
397
404
  }
398
405
 
399
406
  }
@@ -421,6 +428,9 @@ export class Totemheart {
421
428
  delayMs : 0,
422
429
  styleTags : [ 'hijack', hijack.emotion ],
423
430
  emotionalState : this.getEmotionalState(),
431
+ // Same real-consistency fix as the sensory-overload freeze above —
432
+ // found by IntelligentMockGenerator, see test/generated/.
433
+ systemPrompt : this.getSystemPrompt( { userId } ),
424
434
  hijack,
425
435
  }
426
436
 
@@ -17,6 +17,7 @@ export class ArousalKalmanFilter {
17
17
  this.r = measurementNoise
18
18
  this.estimate = initial
19
19
  this.errorCovariance = 1
20
+ this.lastInnovation = 0 // measurement − predicted estimate, the real "how surprising was this reading" term
20
21
 
21
22
  }
22
23
 
@@ -40,11 +41,19 @@ export class ArousalKalmanFilter {
40
41
  // Update
41
42
  const effectiveR = Math.max( 0.001, this.r * noiseMultiplier )
42
43
  const kalmanGain = predictedCovariance / ( predictedCovariance + effectiveR )
43
- this.estimate = predictedEstimate + kalmanGain * ( measurement - predictedEstimate )
44
+ this.lastInnovation = measurement - predictedEstimate // real Kalman "innovation" term, standard name, not invented
45
+ this.estimate = predictedEstimate + kalmanGain * this.lastInnovation
44
46
  this.errorCovariance = ( 1 - kalmanGain ) * predictedCovariance
45
47
 
46
48
  return this.estimate
47
49
 
48
50
  }
49
51
 
52
+ /** The raw prediction error from the last filter() call — large on a genuine surprise, near zero once the estimate has converged to a stable signal. */
53
+ getLastInnovation() {
54
+
55
+ return this.lastInnovation
56
+
57
+ }
58
+
50
59
  }
@@ -60,6 +60,27 @@ export class CircadianRhythm {
60
60
 
61
61
  }
62
62
 
63
+ /**
64
+ * The real coupling runs the other way too: cortisol itself has its own
65
+ * diurnal rhythm, peaking sharply in the ~30-45 minutes after waking (the
66
+ * Cortisol Awakening Response — Pruessner, J. C. et al. (1997), "Free
67
+ * cortisol levels after awakening: a reliable biological marker for the
68
+ * assessment of adrenocortical activity", Life Sciences, 61(26),
69
+ * 2539-2549) and tapering across the day. A real, separate, additive
70
+ * signal a caller MAY fold into CortisolEngine's own reading, own
71
+ * engineering approximation of the timing/shape (peak ~08:00, taper
72
+ * through the day) — not a reproduction of Pruessner et al.'s measured
73
+ * curve, and deliberately NOT wired into CortisolEngine.level itself
74
+ * (that field's semantics are load-driven chronic stress, not this).
75
+ */
76
+ getCortisolBaselineShift( now = new Date() ) {
77
+
78
+ const hour = now.getHours() + now.getMinutes() / 60
79
+ const radians = ( ( hour - 8 ) / 24 ) * 2 * Math.PI
80
+ return clamp01( 0.5 + 0.5 * Math.cos( radians ) ) * 0.15 // small, bounded nudge — own tuning
81
+
82
+ }
83
+
63
84
  getState( now = new Date(), cortisolLevel = 0 ) {
64
85
 
65
86
  const energy = this.getEnergyLevel( now, cortisolLevel )
@@ -7,6 +7,21 @@
7
7
  * for this system's timescale, not a reproduction of his measured constants.
8
8
  * Entries flagged `permanent` (emotional peak > 0.9, set by
9
9
  * EpisodicMemory.store) bypass the curve entirely and never get pruned.
10
+ *
11
+ * Real bug fixed here (found by IntelligentMockGenerator's
12
+ * `rupture_implies_wound_created` invariant, a long-horizon scenario with
13
+ * enough accumulated tick(dt) to cross pruneBelow): an `unresolved` wound
14
+ * was ONLY protected from pruning if it also happened to be `permanent`.
15
+ * EpisodicMemory.js's own store() documents the real intent — "it stays
16
+ * unresolved until something explicitly heals it" — but ForgettingCurve
17
+ * never actually enforced that; an unresolved memory below the permanence
18
+ * magnitude threshold (most of them) could silently vanish from
19
+ * episodicMemory.memories after enough idle/tick time while the REST of
20
+ * the system (getUnresolvedMemories(), the "HERIDA SIN RESOLVER" system-
21
+ * prompt block, LoveHateEngine's own rupture wound) kept assuming it was
22
+ * still there. Fixed by exempting `unresolved` the same way `permanent`
23
+ * already was — it can still be healed by markResolved() (after which it
24
+ * decays normally), it just can't be forgotten by time alone.
10
25
  */
11
26
  export class ForgettingCurve {
12
27
 
@@ -16,7 +31,7 @@ export class ForgettingCurve {
16
31
 
17
32
  episodicMemory.memories = episodicMemory.memories.filter( entry => {
18
33
 
19
- if ( entry.permanent ) return true
34
+ if ( entry.permanent || entry.resolution === 'unresolved' ) return true
20
35
 
21
36
  entry.retention *= Math.exp( -dt / ( stability * ( 1 + entry.importance ) ) )
22
37
  return entry.retention > pruneBelow
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.1'
1
+ export const VERSION = '0.1.2'