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.
- package/README.md +49 -60
- package/dist/adapters/claude-sdk.d.ts +5 -5
- package/dist/adapters/claude-sdk.js +34 -32
- package/dist/adapters/mcp.js +7 -7
- package/dist/adapters/openclaw.js +12 -14
- package/dist/attachment.d.ts +3 -13
- package/dist/attachment.js +36 -88
- package/dist/autonomic.d.ts +4 -4
- package/dist/autonomic.js +29 -25
- package/dist/chemistry.d.ts +47 -21
- package/dist/chemistry.js +149 -95
- package/dist/circadian.d.ts +11 -43
- package/dist/circadian.js +24 -84
- package/dist/cli.js +36 -30
- package/dist/context-classifier.js +2 -2
- package/dist/core.d.ts +3 -3
- package/dist/core.js +102 -91
- package/dist/custom-profile.d.ts +20 -20
- package/dist/custom-profile.js +12 -12
- package/dist/decision-bias.d.ts +7 -8
- package/dist/decision-bias.js +74 -74
- package/dist/demo.js +7 -16
- package/dist/diagnostics.d.ts +6 -6
- package/dist/diagnostics.js +22 -22
- package/dist/drives.d.ts +15 -47
- package/dist/drives.js +98 -196
- package/dist/ethics.d.ts +4 -4
- package/dist/ethics.js +26 -26
- package/dist/experience.d.ts +34 -0
- package/dist/experience.js +200 -0
- package/dist/experiential-field.d.ts +19 -14
- package/dist/experiential-field.js +110 -100
- package/dist/generative-self.d.ts +7 -7
- package/dist/generative-self.js +128 -119
- package/dist/guards.d.ts +4 -4
- package/dist/guards.js +7 -7
- package/dist/i18n.js +61 -61
- package/dist/index.d.ts +8 -2
- package/dist/index.js +10 -3
- package/dist/input-turn.js +4 -6
- package/dist/interaction.d.ts +4 -4
- package/dist/interaction.js +10 -10
- package/dist/learning.d.ts +8 -8
- package/dist/learning.js +20 -20
- package/dist/metacognition.d.ts +2 -2
- package/dist/metacognition.js +81 -96
- package/dist/perceive.d.ts +44 -0
- package/dist/perceive.js +231 -0
- package/dist/primary-systems.d.ts +3 -3
- package/dist/primary-systems.js +22 -20
- package/dist/profiles.d.ts +5 -13
- package/dist/profiles.js +33 -51
- package/dist/prompt.d.ts +2 -2
- package/dist/prompt.js +57 -59
- package/dist/psyche-file.d.ts +10 -10
- package/dist/psyche-file.js +80 -81
- package/dist/relation-dynamics.d.ts +4 -0
- package/dist/relation-dynamics.js +1 -1
- package/dist/reply-envelope.d.ts +25 -1
- package/dist/reply-envelope.js +26 -11
- package/dist/self-recognition.d.ts +6 -6
- package/dist/self-recognition.js +20 -20
- package/dist/subjectivity.js +7 -7
- package/dist/temporal.d.ts +9 -9
- package/dist/temporal.js +40 -42
- package/dist/types.d.ts +67 -45
- package/dist/types.js +55 -51
- package/package.json +1 -1
package/dist/attachment.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
// ============================================================
|
|
2
|
-
// Attachment Dynamics —
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
160
|
+
resonance: 8 * scale,
|
|
161
|
+
order: 5 * scale,
|
|
162
|
+
flow: 3 * scale,
|
|
215
163
|
};
|
|
216
164
|
}
|
|
217
165
|
case "anxious": {
|
|
218
|
-
// Intense but
|
|
166
|
+
// Intense relief but order still shaky
|
|
219
167
|
return {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
168
|
+
resonance: 15 * scale,
|
|
169
|
+
flow: 8 * scale,
|
|
170
|
+
order: -3 * scale,
|
|
223
171
|
};
|
|
224
172
|
}
|
|
225
173
|
case "avoidant": {
|
|
226
|
-
// Cautious
|
|
174
|
+
// Cautious: boundary stays high, mild flow increase
|
|
227
175
|
return {
|
|
228
|
-
|
|
229
|
-
|
|
176
|
+
boundary: 3 * scale,
|
|
177
|
+
flow: 5 * scale,
|
|
230
178
|
};
|
|
231
179
|
}
|
|
232
180
|
case "disorganized": {
|
|
233
|
-
// Mixed
|
|
181
|
+
// Mixed
|
|
234
182
|
return {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
183
|
+
resonance: 5 * scale,
|
|
184
|
+
order: -3 * scale,
|
|
185
|
+
flow: 5 * scale,
|
|
238
186
|
};
|
|
239
187
|
}
|
|
240
188
|
}
|
package/dist/autonomic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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(
|
|
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,
|
|
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(
|
|
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
|
|
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(
|
|
69
|
-
const {
|
|
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 (
|
|
81
|
+
if (stress >= 80 && arousal <= 25 && flow <= 20) {
|
|
77
82
|
return "dorsal-vagal";
|
|
78
83
|
}
|
|
79
|
-
// Multiple critically low drives with depleted
|
|
80
|
-
if (lowDriveCount >= 3 &&
|
|
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 (
|
|
90
|
+
if (stress >= 65 && arousal >= 65) {
|
|
86
91
|
return "sympathetic";
|
|
87
92
|
}
|
|
88
|
-
// Either axis extreme: one
|
|
89
|
-
if (
|
|
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) &&
|
|
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,
|
|
139
|
-
const
|
|
140
|
-
//
|
|
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
|
|
143
|
-
|
|
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
|
|
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
|
|
154
|
-
baseDepth =
|
|
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
|
-
//
|
|
161
|
-
let depth = Math.max(0, Math.min(1, baseDepth * (1 -
|
|
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(
|
|
190
|
-
const targetState = computeAutonomicState(
|
|
191
|
-
const effectiveBaseline = baseline ?? {
|
|
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,
|
|
198
|
+
const { depth, skippedStages } = computeProcessingDepth(state, current, effectiveBaseline, energyBudgets);
|
|
195
199
|
return {
|
|
196
200
|
state,
|
|
197
201
|
transitionProgress,
|
package/dist/chemistry.d.ts
CHANGED
|
@@ -1,41 +1,67 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const STIMULUS_VECTORS: Record<StimulusType,
|
|
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
|
-
*
|
|
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:
|
|
12
|
+
export declare function applyDecay(current: SelfState, baseline: SelfState, minutesElapsed: number, decayRateModifiers?: Partial<Record<keyof SelfState, number>>): SelfState;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
|
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):
|
|
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
|
|
22
|
-
*
|
|
41
|
+
* Apply contagion from a raw impact vector.
|
|
42
|
+
* Core substrate-independent function.
|
|
23
43
|
*/
|
|
24
|
-
export declare function
|
|
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
|
|
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:
|
|
55
|
+
export declare function detectEmotions(current: SelfState): EmotionPattern[];
|
|
30
56
|
/**
|
|
31
|
-
*
|
|
57
|
+
* Human-readable emotion summary from self-state.
|
|
32
58
|
*/
|
|
33
|
-
export declare function describeEmotionalState(current:
|
|
59
|
+
export declare function describeEmotionalState(current: SelfState, locale?: Locale): string;
|
|
34
60
|
/**
|
|
35
|
-
*
|
|
61
|
+
* Concise expression guidance from self-state.
|
|
36
62
|
*/
|
|
37
|
-
export declare function getExpressionHint(current:
|
|
63
|
+
export declare function getExpressionHint(current: SelfState, locale?: Locale): string;
|
|
38
64
|
/**
|
|
39
|
-
*
|
|
65
|
+
* Behavior guide for the current emergent emotional state.
|
|
40
66
|
*/
|
|
41
|
-
export declare function getBehaviorGuide(current:
|
|
67
|
+
export declare function getBehaviorGuide(current: SelfState, locale?: Locale): string | null;
|