psyche-ai 10.2.4 → 11.3.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.
Files changed (68) hide show
  1. package/README.md +49 -60
  2. package/dist/adapters/claude-sdk.d.ts +5 -5
  3. package/dist/adapters/claude-sdk.js +34 -32
  4. package/dist/adapters/mcp.js +7 -7
  5. package/dist/adapters/openclaw.js +12 -14
  6. package/dist/attachment.d.ts +3 -13
  7. package/dist/attachment.js +36 -88
  8. package/dist/autonomic.d.ts +4 -4
  9. package/dist/autonomic.js +29 -25
  10. package/dist/chemistry.d.ts +47 -21
  11. package/dist/chemistry.js +149 -95
  12. package/dist/circadian.d.ts +11 -43
  13. package/dist/circadian.js +24 -84
  14. package/dist/cli.js +36 -30
  15. package/dist/context-classifier.js +2 -2
  16. package/dist/core.d.ts +3 -3
  17. package/dist/core.js +102 -91
  18. package/dist/custom-profile.d.ts +20 -20
  19. package/dist/custom-profile.js +12 -12
  20. package/dist/decision-bias.d.ts +7 -8
  21. package/dist/decision-bias.js +74 -74
  22. package/dist/demo.js +7 -16
  23. package/dist/diagnostics.d.ts +6 -6
  24. package/dist/diagnostics.js +22 -22
  25. package/dist/drives.d.ts +15 -47
  26. package/dist/drives.js +98 -196
  27. package/dist/ethics.d.ts +4 -4
  28. package/dist/ethics.js +26 -26
  29. package/dist/experience.d.ts +34 -0
  30. package/dist/experience.js +200 -0
  31. package/dist/experiential-field.d.ts +19 -14
  32. package/dist/experiential-field.js +110 -100
  33. package/dist/generative-self.d.ts +7 -7
  34. package/dist/generative-self.js +128 -119
  35. package/dist/guards.d.ts +4 -4
  36. package/dist/guards.js +7 -7
  37. package/dist/i18n.js +61 -61
  38. package/dist/index.d.ts +8 -2
  39. package/dist/index.js +10 -3
  40. package/dist/input-turn.js +4 -6
  41. package/dist/interaction.d.ts +4 -4
  42. package/dist/interaction.js +10 -10
  43. package/dist/learning.d.ts +8 -8
  44. package/dist/learning.js +20 -20
  45. package/dist/metacognition.d.ts +2 -2
  46. package/dist/metacognition.js +81 -96
  47. package/dist/perceive.d.ts +44 -0
  48. package/dist/perceive.js +231 -0
  49. package/dist/primary-systems.d.ts +3 -3
  50. package/dist/primary-systems.js +22 -20
  51. package/dist/profiles.d.ts +5 -13
  52. package/dist/profiles.js +33 -51
  53. package/dist/prompt.d.ts +2 -2
  54. package/dist/prompt.js +57 -59
  55. package/dist/psyche-file.d.ts +10 -10
  56. package/dist/psyche-file.js +80 -81
  57. package/dist/relation-dynamics.d.ts +4 -0
  58. package/dist/relation-dynamics.js +1 -1
  59. package/dist/reply-envelope.d.ts +25 -1
  60. package/dist/reply-envelope.js +26 -11
  61. package/dist/self-recognition.d.ts +6 -6
  62. package/dist/self-recognition.js +20 -20
  63. package/dist/subjectivity.js +7 -7
  64. package/dist/temporal.d.ts +9 -9
  65. package/dist/temporal.js +40 -42
  66. package/dist/types.d.ts +67 -45
  67. package/dist/types.js +55 -51
  68. package/package.json +1 -1
@@ -1,14 +1,5 @@
1
1
  // ============================================================
2
- // Attachment Dynamics — Bowlby-inspired attachment formation
3
- //
4
- // Models relationship attachment through interaction patterns:
5
- // 1. AttachmentModel — style classification + strength tracking
6
- // 2. SeparationAnxiety — absence effects on chemistry
7
- // 3. ReunionEffect — return effects on chemistry
8
- //
9
- // Attachment style emerges from interaction history, not from
10
- // configuration. Consistent positive interaction → secure.
11
- // Inconsistency → anxious. Rejection/neglect → avoidant.
2
+ // Attachment Dynamics — v11: effects in 4D self-state
12
3
  // ============================================================
13
4
  // ── Defaults ─────────────────────────────────────────────────
14
5
  export const DEFAULT_ATTACHMENT = {
@@ -30,51 +21,32 @@ const NEGATIVE_STIMULI = new Set([
30
21
  const REJECTION_STIMULI = new Set([
31
22
  "neglect", "authority", "boredom",
32
23
  ]);
33
- // EMA smoothing factor: weight given to new observation
34
24
  const EMA_ALPHA = 0.15;
35
25
  // ── 1. AttachmentModel ──────────────────────────────────────
36
- /**
37
- * Determine attachment style from scores.
38
- */
39
26
  function determineStyle(securityScore, anxietyScore, avoidanceScore) {
40
- // Disorganized: both anxiety and avoidance elevated
41
- if (anxietyScore > 50 && avoidanceScore > 50) {
27
+ if (anxietyScore > 50 && avoidanceScore > 50)
42
28
  return "disorganized";
43
- }
44
- // Anxious: high anxiety
45
- if (anxietyScore > 60) {
29
+ if (anxietyScore > 60)
46
30
  return "anxious";
47
- }
48
- // Avoidant: high avoidance
49
- if (avoidanceScore > 60) {
31
+ if (avoidanceScore > 60)
50
32
  return "avoidant";
51
- }
52
- // Secure: high security, low anxiety, low avoidance
53
- if (securityScore > 60 && anxietyScore < 40 && avoidanceScore < 40) {
33
+ if (securityScore > 60 && anxietyScore < 40 && avoidanceScore < 40)
54
34
  return "secure";
55
- }
56
- // Default to current trajectory — mild insecurity stays secure
57
35
  if (securityScore >= 50)
58
36
  return "secure";
59
37
  if (anxietyScore > avoidanceScore)
60
38
  return "anxious";
61
39
  return "avoidant";
62
40
  }
63
- /**
64
- * Update attachment based on interaction outcome.
65
- */
66
41
  export function updateAttachment(attachment, stimulus, outcomeScore) {
67
42
  const result = { ...attachment };
68
- // Strength increases slowly with interaction count
69
43
  result.interactionCount = attachment.interactionCount + 1;
70
44
  result.strength = Math.min(100, attachment.strength + 1);
71
45
  result.lastInteractionAt = new Date().toISOString();
72
46
  if (stimulus === null) {
73
- // No stimulus — just update count/strength, reclassify
74
47
  result.style = determineStyle(result.securityScore, result.anxietyScore, result.avoidanceScore);
75
48
  return result;
76
49
  }
77
- // SecurityScore: EMA with positive/negative stimuli
78
50
  const isPositive = POSITIVE_STIMULI.has(stimulus);
79
51
  const isNegative = NEGATIVE_STIMULI.has(stimulus);
80
52
  if (isPositive) {
@@ -85,107 +57,88 @@ export function updateAttachment(attachment, stimulus, outcomeScore) {
85
57
  const target = Math.max(0, result.securityScore - 5);
86
58
  result.securityScore = result.securityScore * (1 - EMA_ALPHA) + target * EMA_ALPHA;
87
59
  }
88
- // AnxietyScore: increases with inconsistency (rapid alternation between positive and negative)
89
- // We detect inconsistency by checking if outcomeScore diverges from the security trend
90
60
  const expectedDirection = result.securityScore > 50 ? 1 : -1;
91
61
  const actualDirection = outcomeScore >= 0 ? 1 : -1;
92
62
  const isInconsistent = expectedDirection !== actualDirection;
93
63
  if (isInconsistent) {
94
- // Inconsistency → anxiety rises
95
64
  const anxietyTarget = Math.min(100, result.anxietyScore + 8);
96
65
  result.anxietyScore = result.anxietyScore * (1 - EMA_ALPHA) + anxietyTarget * EMA_ALPHA;
97
66
  }
98
67
  else {
99
- // Consistency → anxiety decreases
100
68
  const anxietyTarget = Math.max(0, result.anxietyScore - 3);
101
69
  result.anxietyScore = result.anxietyScore * (1 - EMA_ALPHA) + anxietyTarget * EMA_ALPHA;
102
70
  }
103
- // AvoidanceScore: increases with rejection/neglect stimuli
104
71
  if (REJECTION_STIMULI.has(stimulus)) {
105
72
  const avoidTarget = Math.min(100, result.avoidanceScore + 6);
106
73
  result.avoidanceScore = result.avoidanceScore * (1 - EMA_ALPHA) + avoidTarget * EMA_ALPHA;
107
74
  }
108
75
  else if (isPositive) {
109
- // Positive interactions reduce avoidance
110
76
  const avoidTarget = Math.max(0, result.avoidanceScore - 3);
111
77
  result.avoidanceScore = result.avoidanceScore * (1 - EMA_ALPHA) + avoidTarget * EMA_ALPHA;
112
78
  }
113
- // Clamp all scores
114
79
  result.securityScore = Math.max(0, Math.min(100, result.securityScore));
115
80
  result.anxietyScore = Math.max(0, Math.min(100, result.anxietyScore));
116
81
  result.avoidanceScore = Math.max(0, Math.min(100, result.avoidanceScore));
117
- // Determine style
118
82
  result.style = determineStyle(result.securityScore, result.anxietyScore, result.avoidanceScore);
119
83
  return result;
120
84
  }
121
- // ── 2. SeparationAnxiety ────────────────────────────────────
122
- /**
123
- * Compute chemistry effects of absence based on attachment.
124
- * Called when time since last interaction is significant.
125
- */
85
+ // ── 2. SeparationEffect (4D) ────────────────────────────────
126
86
  export function computeSeparationEffect(attachment, minutesSinceLastInteraction) {
127
- // No effect for short absence or weak attachment
128
87
  if (minutesSinceLastInteraction < 60 || attachment.strength < 20) {
129
88
  return null;
130
89
  }
131
90
  const hours = minutesSinceLastInteraction / 60;
132
- // Intensity scales with attachment strength and time (logarithmic growth, capped at 1)
133
91
  const baseIntensity = (attachment.strength / 100) * Math.min(1, Math.log2(hours + 1) / 5);
134
92
  switch (attachment.style) {
135
93
  case "secure": {
136
- // Mild longing after 24h
137
94
  if (hours < 24)
138
95
  return null;
139
96
  const intensity = baseIntensity * 0.5;
140
97
  return {
141
- chemistryDelta: {
142
- OT: -5 * intensity,
143
- DA: -3 * intensity,
98
+ stateDelta: {
99
+ resonance: -5 * intensity,
100
+ order: -3 * intensity,
144
101
  },
145
102
  description: "gentle longing from sustained absence",
146
103
  intensity: Math.min(1, intensity),
147
104
  };
148
105
  }
149
106
  case "anxious": {
150
- // Distress after 4h, grows with time
151
107
  if (hours < 4)
152
108
  return null;
153
109
  const intensity = baseIntensity * 1.5;
154
- // OT oscillation: represented as net negative with anxiety
155
110
  return {
156
- chemistryDelta: {
157
- CORT: 10 * intensity,
158
- OT: -5 * intensity,
159
- NE: 8 * intensity,
160
- DA: -3 * intensity,
111
+ stateDelta: {
112
+ resonance: -8 * intensity,
113
+ order: -10 * intensity,
114
+ boundary: -5 * intensity,
115
+ flow: +5 * intensity,
161
116
  },
162
117
  description: "anxious distress from absence — fear of abandonment",
163
118
  intensity: Math.min(1, intensity),
164
119
  };
165
120
  }
166
121
  case "avoidant": {
167
- // Relief initially, discomfort after 48h
168
122
  if (hours < 48)
169
123
  return null;
170
124
  const intensity = baseIntensity * 0.4;
171
125
  return {
172
- chemistryDelta: {
173
- OT: -3 * intensity,
126
+ stateDelta: {
127
+ resonance: -3 * intensity,
174
128
  },
175
129
  description: "subtle discomfort surfacing through avoidant defense",
176
130
  intensity: Math.min(1, intensity),
177
131
  };
178
132
  }
179
133
  case "disorganized": {
180
- // Conflicting signals
181
134
  if (hours < 4)
182
135
  return null;
183
136
  const intensity = baseIntensity * 1.0;
184
137
  return {
185
- chemistryDelta: {
186
- CORT: 5 * intensity,
187
- OT: 5 * intensity,
188
- NE: 3 * intensity,
138
+ stateDelta: {
139
+ resonance: +5 * intensity,
140
+ order: -5 * intensity,
141
+ flow: +3 * intensity,
189
142
  },
190
143
  description: "conflicting signals — wanting closeness and fearing it",
191
144
  intensity: Math.min(1, intensity),
@@ -193,48 +146,43 @@ export function computeSeparationEffect(attachment, minutesSinceLastInteraction)
193
146
  }
194
147
  }
195
148
  }
196
- // ── 3. ReunionEffect ────────────────────────────────────────
197
- /**
198
- * Compute chemistry effects when reuniting after absence.
199
- */
149
+ // ── 3. ReunionEffect (4D) ───────────────────────────────────
200
150
  export function computeReunionEffect(attachment, minutesSinceLastInteraction) {
201
- // No effect for short absence or weak attachment
202
151
  if (minutesSinceLastInteraction < 60 || attachment.strength < 20) {
203
152
  return null;
204
153
  }
205
154
  const hours = minutesSinceLastInteraction / 60;
206
- // Scale with time (logarithmic) and attachment strength
207
155
  const scale = (attachment.strength / 100) * Math.min(1, Math.log2(hours + 1) / 5);
208
156
  switch (attachment.style) {
209
157
  case "secure": {
210
- // Warm reunion
158
+ // Warm reunion: resonance↑, order↑
211
159
  return {
212
- OT: 8 * scale,
213
- DA: 5 * scale,
214
- END: 3 * scale,
160
+ resonance: 8 * scale,
161
+ order: 5 * scale,
162
+ flow: 3 * scale,
215
163
  };
216
164
  }
217
165
  case "anxious": {
218
- // Intense but short-lived relief (CORT still elevated)
166
+ // Intense relief but order still shaky
219
167
  return {
220
- OT: 15 * scale,
221
- DA: 10 * scale,
222
- CORT: 5 * scale,
168
+ resonance: 15 * scale,
169
+ flow: 8 * scale,
170
+ order: -3 * scale,
223
171
  };
224
172
  }
225
173
  case "avoidant": {
226
- // Cautious re-engagement
174
+ // Cautious: boundary stays high, mild flow increase
227
175
  return {
228
- OT: 3 * scale,
229
- NE: 5 * scale,
176
+ boundary: 3 * scale,
177
+ flow: 5 * scale,
230
178
  };
231
179
  }
232
180
  case "disorganized": {
233
- // Mixed signals
181
+ // Mixed
234
182
  return {
235
- OT: 5 * scale,
236
- CORT: 5 * scale,
237
- NE: 5 * scale,
183
+ resonance: 5 * scale,
184
+ order: -3 * scale,
185
+ flow: 5 * scale,
238
186
  };
239
187
  }
240
188
  }
@@ -1,4 +1,4 @@
1
- import type { ChemicalState, InnateDrives, Locale, EnergyBudgets } from "./types.js";
1
+ import type { SelfState, InnateDrives, Locale, EnergyBudgets } from "./types.js";
2
2
  export type AutonomicState = "ventral-vagal" | "sympathetic" | "dorsal-vagal";
3
3
  export interface AutonomicResult {
4
4
  state: AutonomicState;
@@ -17,7 +17,7 @@ export interface AutonomicTransition {
17
17
  * Compute the raw autonomic state from chemistry and drives.
18
18
  * No transition inertia — returns the "target" state.
19
19
  */
20
- export declare function computeAutonomicState(chemistry: ChemicalState, drives: InnateDrives): AutonomicState;
20
+ export declare function computeAutonomicState(state: SelfState, drives: InnateDrives): AutonomicState;
21
21
  /**
22
22
  * Gate emotions based on autonomic state.
23
23
  * - Ventral vagal: all emotions pass through
@@ -44,7 +44,7 @@ export declare function describeAutonomicState(state: AutonomicState, locale: Lo
44
44
  * This is a natural extension of autonomic state: you can't deeply reflect
45
45
  * when your nervous system is in fight/flight/freeze mode.
46
46
  */
47
- export declare function computeProcessingDepth(autonomicState: AutonomicState, chemistry: ChemicalState, baseline: ChemicalState, energyBudgets?: EnergyBudgets): {
47
+ export declare function computeProcessingDepth(autonomicState: AutonomicState, current: SelfState, baseline: SelfState, energyBudgets?: EnergyBudgets): {
48
48
  depth: number;
49
49
  skippedStages: string[];
50
50
  };
@@ -56,4 +56,4 @@ export declare function computeProcessingDepth(autonomicState: AutonomicState, c
56
56
  *
57
57
  * Includes P10 processing depth (dual-process cognitive gating).
58
58
  */
59
- export declare function computeAutonomicResult(chemistry: ChemicalState, drives: InnateDrives, previousState: AutonomicState | null, minutesSinceLastUpdate: number, locale?: Locale, baseline?: ChemicalState, energyBudgets?: EnergyBudgets): AutonomicResult;
59
+ export declare function computeAutonomicResult(current: SelfState, drives: InnateDrives, previousState: AutonomicState | null, minutesSinceLastUpdate: number, locale?: Locale, baseline?: SelfState, energyBudgets?: EnergyBudgets): AutonomicResult;
package/dist/autonomic.js CHANGED
@@ -2,12 +2,13 @@
2
2
  // Autonomic Nervous System — Polyvagal Theory Implementation
3
3
  // ============================================================
4
4
  //
5
- // Maps chemical state + innate drives to autonomic nervous system
5
+ // Maps self-state dimensions + innate drives to autonomic nervous system
6
6
  // states based on Stephen Porges' Polyvagal Theory:
7
7
  //
8
8
  // - Ventral vagal: social engagement, safety (default)
9
9
  // - Sympathetic: fight/flight mobilization
10
10
  // - Dorsal vagal: freeze/shutdown/collapse
11
+ import { DIMENSION_KEYS } from "./types.js";
11
12
  // ── i18n Strings ─────────────────────────────────────────────
12
13
  const AUTONOMIC_STRINGS = {
13
14
  zh: {
@@ -65,32 +66,36 @@ const DORSAL_ALLOWED = new Set([
65
66
  * Compute the raw autonomic state from chemistry and drives.
66
67
  * No transition inertia — returns the "target" state.
67
68
  */
68
- export function computeAutonomicState(chemistry, drives) {
69
- const { CORT, NE, DA } = chemistry;
69
+ export function computeAutonomicState(state, drives) {
70
+ const { order, flow, boundary } = state;
70
71
  const { survival, safety, connection } = drives;
72
+ // Inverse order = stress (low order = high entropy/distress)
73
+ const stress = 100 - order;
74
+ // Flow maps to arousal/activation
75
+ const arousal = flow;
71
76
  // Count drives that are critically low (< 20)
72
77
  const lowDriveCount = [survival, safety, connection, drives.esteem, drives.curiosity]
73
78
  .filter((d) => d < 20).length;
74
79
  // ── Dorsal vagal check (freeze/shutdown) ──
75
80
  // Very high stress + low arousal + low motivation = collapse
76
- if (CORT >= 80 && NE <= 25 && DA <= 20) {
81
+ if (stress >= 80 && arousal <= 25 && flow <= 20) {
77
82
  return "dorsal-vagal";
78
83
  }
79
- // Multiple critically low drives with depleted chemistry
80
- if (lowDriveCount >= 3 && CORT >= 70 && (NE <= 30 || DA <= 20)) {
84
+ // Multiple critically low drives with depleted state
85
+ if (lowDriveCount >= 3 && stress >= 70 && (arousal <= 30 || flow <= 20)) {
81
86
  return "dorsal-vagal";
82
87
  }
83
88
  // ── Sympathetic check (fight/flight) ──
84
89
  // High stress + high arousal
85
- if (CORT >= 65 && NE >= 65) {
90
+ if (stress >= 65 && arousal >= 65) {
86
91
  return "sympathetic";
87
92
  }
88
- // Either axis extreme: one chemical dominating can still trigger mobilization
89
- if (CORT + NE >= 140 && CORT >= 50 && NE >= 50) {
93
+ // Either axis extreme: one dimension dominating can still trigger mobilization
94
+ if (stress + arousal >= 140 && stress >= 50 && arousal >= 50) {
90
95
  return "sympathetic";
91
96
  }
92
97
  // Very low survival or safety drive with elevated stress
93
- if ((survival < 20 || safety < 20) && CORT >= 55 && NE >= 55) {
98
+ if ((survival < 20 || safety < 20) && stress >= 55 && arousal >= 55) {
94
99
  return "sympathetic";
95
100
  }
96
101
  // ── Default: Ventral vagal (social engagement/safety) ──
@@ -135,30 +140,29 @@ export function describeAutonomicState(state, locale) {
135
140
  * This is a natural extension of autonomic state: you can't deeply reflect
136
141
  * when your nervous system is in fight/flight/freeze mode.
137
142
  */
138
- export function computeProcessingDepth(autonomicState, chemistry, baseline, energyBudgets) {
139
- const { CORT } = chemistry;
140
- // Chemical deviation from baseline (0-1)
143
+ export function computeProcessingDepth(autonomicState, current, baseline, energyBudgets) {
144
+ const stress = 100 - current.order;
145
+ // State deviation from baseline (0-1)
141
146
  let totalDeviation = 0;
142
- const keys = ["DA", "HT", "CORT", "OT", "NE", "END"];
143
- for (const k of keys) {
144
- totalDeviation += Math.abs(chemistry[k] - baseline[k]);
147
+ for (const k of DIMENSION_KEYS) {
148
+ totalDeviation += Math.abs(current[k] - baseline[k]);
145
149
  }
146
- const chemDeviation = Math.min(1, totalDeviation / 600);
150
+ const stateDeviation = Math.min(1, totalDeviation / 400);
147
151
  // Base depth from autonomic state
148
152
  let baseDepth;
149
153
  if (autonomicState === "dorsal-vagal") {
150
154
  baseDepth = 0;
151
155
  }
152
156
  else if (autonomicState === "sympathetic") {
153
- // Higher CORT in sympathetic = less cognitive resource
154
- baseDepth = CORT >= 60 ? 0.15 : 0.35;
157
+ // Higher stress in sympathetic = less cognitive resource
158
+ baseDepth = stress >= 60 ? 0.15 : 0.35;
155
159
  }
156
160
  else {
157
161
  // ventral-vagal: safe, most cognitive resource available
158
162
  baseDepth = 0.85;
159
163
  }
160
- // Chemical deviation reduces depth (strong emotions = less reflection)
161
- let depth = Math.max(0, Math.min(1, baseDepth * (1 - chemDeviation * 0.5)));
164
+ // State deviation reduces depth (strong shifts = less reflection)
165
+ let depth = Math.max(0, Math.min(1, baseDepth * (1 - stateDeviation * 0.5)));
162
166
  // v9: Low attention energy further reduces processing depth
163
167
  if (energyBudgets && energyBudgets.attention < 30) {
164
168
  const attentionPenalty = (30 - energyBudgets.attention) / 30 * 0.3;
@@ -186,12 +190,12 @@ export function computeProcessingDepth(autonomicState, chemistry, baseline, ener
186
190
  *
187
191
  * Includes P10 processing depth (dual-process cognitive gating).
188
192
  */
189
- export function computeAutonomicResult(chemistry, drives, previousState, minutesSinceLastUpdate, locale = "zh", baseline, energyBudgets) {
190
- const targetState = computeAutonomicState(chemistry, drives);
191
- const effectiveBaseline = baseline ?? { DA: 50, HT: 50, CORT: 50, OT: 50, NE: 50, END: 50 };
193
+ export function computeAutonomicResult(current, drives, previousState, minutesSinceLastUpdate, locale = "zh", baseline, energyBudgets) {
194
+ const targetState = computeAutonomicState(current, drives);
195
+ const effectiveBaseline = baseline ?? { order: 50, flow: 50, boundary: 50, resonance: 50 };
192
196
  // Helper to build full result with processing depth
193
197
  const buildResult = (state, transitionProgress) => {
194
- const { depth, skippedStages } = computeProcessingDepth(state, chemistry, effectiveBaseline, energyBudgets);
198
+ const { depth, skippedStages } = computeProcessingDepth(state, current, effectiveBaseline, energyBudgets);
195
199
  return {
196
200
  state,
197
201
  transitionProgress,
@@ -1,41 +1,67 @@
1
- import { type ChemicalState, type StimulusType, type StimulusVector, type EmotionPattern, type Locale } from "./types.js";
2
- export declare const STIMULUS_VECTORS: Record<StimulusType, StimulusVector>;
1
+ import { type SelfState, type StimulusType, type ImpactVector, type EmotionPattern, type Locale } from "./types.js";
2
+ export declare const STIMULUS_VECTORS: Record<StimulusType, ImpactVector>;
3
3
  export declare const EMOTION_PATTERNS: EmotionPattern[];
4
4
  /** Clamp a value to [0, 100] */
5
5
  export declare function clamp(v: number): number;
6
6
  /**
7
7
  * Apply time-based decay: pull current values toward baseline.
8
8
  *
9
- * decayed = baseline + (current - baseline) * factor^(minutes/60)
9
+ * Each dimension decays at its own rate (order fastest, boundary slowest).
10
+ * decayRateModifiers alter speed per dimension (>1 = slower, <1 = faster).
10
11
  */
11
- export declare function applyDecay(current: ChemicalState, baseline: ChemicalState, minutesElapsed: number, decayRateModifiers?: Partial<Record<keyof ChemicalState, number>>): ChemicalState;
12
+ export declare function applyDecay(current: SelfState, baseline: SelfState, minutesElapsed: number, decayRateModifiers?: Partial<Record<keyof SelfState, number>>): SelfState;
12
13
  /**
13
- * Apply a stimulus to the current state.
14
- * Respects emotional inertia (maxDelta) and personality sensitivity.
15
- * Logs a warning for unknown stimulus types.
14
+ * Mutual influence between dimensions.
15
+ *
16
+ * Dimensions are not independent they affect each other:
17
+ * - Collapsing order drags boundary down (incoherent self loses distinction)
18
+ * - High flow raises order (engagement creates coherence)
19
+ * - High resonance stabilizes boundary (attunement reinforces self)
20
+ * - Low boundary amplifies order loss (dissolution spiral)
21
+ */
22
+ export declare function applyMutualInfluence(state: SelfState, baseline: SelfState): SelfState;
23
+ /**
24
+ * Apply an impact vector to the current state.
25
+ * Core substrate-independent function — operates on 4D vectors, not labels.
26
+ * Respects inertia (maxDelta), sensitivity, and habituation.
16
27
  */
17
- export declare function applyStimulus(current: ChemicalState, stimulus: StimulusType, sensitivity: number, maxDelta: number, logger?: {
28
+ export declare function applyImpact(current: SelfState, vector: ImpactVector, sensitivity: number, maxDelta: number, recentSameCount?: number): SelfState;
29
+ /**
30
+ * Apply a labeled stimulus to the current state.
31
+ * Perception-layer convenience — looks up the ImpactVector from STIMULUS_VECTORS.
32
+ */
33
+ export declare function applyStimulus(current: SelfState, stimulus: StimulusType, sensitivity: number, maxDelta: number, logger?: {
18
34
  warn: (msg: string) => void;
19
- }, recentSameCount?: number): ChemicalState;
35
+ }, recentSameCount?: number): SelfState;
36
+ /**
37
+ * Apply emotional contagion from a labeled stimulus.
38
+ */
39
+ export declare function applyContagion(agentState: SelfState, detectedUserEmotion: StimulusType, contagionRate: number, sensitivity: number): SelfState;
20
40
  /**
21
- * Apply emotional contagion: the detected user emotion partially
22
- * influences the agent's chemistry.
41
+ * Apply contagion from a raw impact vector.
42
+ * Core substrate-independent function.
23
43
  */
24
- export declare function applyContagion(agentState: ChemicalState, detectedUserEmotion: StimulusType, contagionRate: number, sensitivity: number): ChemicalState;
44
+ export declare function applyImpactContagion(agentState: SelfState, vector: ImpactVector, contagionRate: number, sensitivity: number): SelfState;
45
+ /** True if the net impact across all dimensions is positive. */
46
+ export declare function isPositiveImpact(v: ImpactVector): boolean;
47
+ /** True if the impact has significant resonance magnitude. */
48
+ export declare function isEmotionalImpact(v: ImpactVector): boolean;
49
+ /** True if the impact threatens self-coherence (order or boundary). */
50
+ export declare function isThreateningImpact(v: ImpactVector): boolean;
25
51
  /**
26
- * Detect the dominant emergent emotion(s) from the current chemistry.
27
- * Returns all matching patterns.
52
+ * Detect emergent emotion patterns from the current self-state.
53
+ * Returns all matching patterns — emotions emerge, they are not designed.
28
54
  */
29
- export declare function detectEmotions(current: ChemicalState): EmotionPattern[];
55
+ export declare function detectEmotions(current: SelfState): EmotionPattern[];
30
56
  /**
31
- * Generate a human-readable emotion summary from chemistry.
57
+ * Human-readable emotion summary from self-state.
32
58
  */
33
- export declare function describeEmotionalState(current: ChemicalState, locale?: Locale): string;
59
+ export declare function describeEmotionalState(current: SelfState, locale?: Locale): string;
34
60
  /**
35
- * Generate concise expression guidance from the current chemistry.
61
+ * Concise expression guidance from self-state.
36
62
  */
37
- export declare function getExpressionHint(current: ChemicalState, locale?: Locale): string;
63
+ export declare function getExpressionHint(current: SelfState, locale?: Locale): string;
38
64
  /**
39
- * Get behavior guide for the current emotional state.
65
+ * Behavior guide for the current emergent emotional state.
40
66
  */
41
- export declare function getBehaviorGuide(current: ChemicalState, locale?: Locale): string | null;
67
+ export declare function getBehaviorGuide(current: SelfState, locale?: Locale): string | null;