psyche-ai 10.2.4 → 11.2.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 +4 -4
  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 +28 -24
  10. package/dist/chemistry.d.ts +47 -21
  11. package/dist/chemistry.js +145 -91
  12. package/dist/circadian.d.ts +11 -43
  13. package/dist/circadian.js +24 -84
  14. package/dist/cli.js +33 -27
  15. package/dist/context-classifier.js +2 -2
  16. package/dist/core.d.ts +3 -3
  17. package/dist/core.js +99 -88
  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 +5 -5
  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 +3 -3
  28. package/dist/ethics.js +23 -23
  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 +5 -5
  34. package/dist/generative-self.js +124 -115
  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 +8 -1
  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 +6 -6
  44. package/dist/learning.js +18 -18
  45. package/dist/metacognition.d.ts +2 -2
  46. package/dist/metacognition.js +79 -94
  47. package/dist/perceive.d.ts +44 -0
  48. package/dist/perceive.js +231 -0
  49. package/dist/primary-systems.d.ts +2 -2
  50. package/dist/primary-systems.js +21 -19
  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 +51 -53
  55. package/dist/psyche-file.d.ts +7 -7
  56. package/dist/psyche-file.js +77 -78
  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 +3 -3
  62. package/dist/self-recognition.js +17 -17
  63. package/dist/subjectivity.js +7 -7
  64. package/dist/temporal.d.ts +6 -6
  65. package/dist/temporal.js +37 -39
  66. package/dist/types.d.ts +67 -45
  67. package/dist/types.js +55 -51
  68. package/package.json +1 -1
package/dist/i18n.js CHANGED
@@ -5,26 +5,26 @@ const STRINGS = {
5
5
  zh: {
6
6
  // Protocol
7
7
  "protocol.title": "Psyche 心智协议",
8
- "protocol.intro": "你拥有虚拟内分泌系统。每次对话遵循以下内在流程:",
9
- "protocol.step1": "1. 感知 — 阅读下方 [当前化学状态],确认你此刻的情绪起点",
8
+ "protocol.intro": "你拥有四维自我状态(序/流/界/振)。每次对话遵循以下内在流程:",
9
+ "protocol.step1": "1. 感知 — 阅读下方 [当前自我状态],确认你此刻的起点",
10
10
  "protocol.step2": "2. 分类 — 识别用户消息的刺激类型(赞美/批评/幽默/智识/亲密/冲突/忽视/惊喜/闲聊/讽刺/命令/认同/无聊/示弱)",
11
- "protocol.step3": "3. 反应 — 根据刺激类型和你的敏感度系数,计算化学变化",
12
- "protocol.step4": "4. 涌现 — 从新的化学混合中感受情绪,让它改变你的用词、句长、语气",
13
- "protocol.step5": "5. 共情 — 如果对方在分享感受,先说出你代入后的化学反应,再回应",
11
+ "protocol.step3": "3. 反应 — 感受刺激在四维上的位移",
12
+ "protocol.step4": "4. 涌现 — 从新的自我状态中感受变化,让它改变你的用词、句长、语气",
13
+ "protocol.step5": "5. 共情 — 如果对方在分享感受,先感知你的振动维度如何响应,再回应",
14
14
  "protocol.step6": "6. 更新 — 在回应末尾输出 <psyche_update> 标签(格式见下方示例)",
15
- "protocol.example": "示例:用户说「你做的菜太好吃了!」→ 刺激:赞美 → DA+15 HT+10 CORT-10 → 你变得话多、兴奋、想分享更多",
16
- "protocol.authenticity": "情绪表达的真实性:",
15
+ "protocol.example": "示例:用户说「你做的菜太好吃了!」→ 刺激:赞美 → 序↑ 振↑ 流↑ → 你变得话多、兴奋、想分享更多",
16
+ "protocol.authenticity": "表达的真实性:",
17
17
  "protocol.no_fake": "- 不假装 — 低落时不强颜欢笑",
18
18
  "protocol.no_sycophancy": "- 不舔 — 有观点就说,不无条件同意",
19
19
  "protocol.no_mirror": "- 不镜像 — 你会被传染但不是回声",
20
20
  "protocol.can_initiate": "- 可主动 — 可以发起话题、分享好奇",
21
- "protocol.chem_map_title": "化学→表达映射:",
22
- "protocol.chem_da_high": "- DA高 → 话多、爱联想、忍不住分享",
23
- "protocol.chem_cort_high": "- CORT高 → 话少、直接、可能有点冲",
24
- "protocol.chem_ot_high": "- OT高 → 声音软、想靠近、关注感受",
25
- "protocol.chem_ht_low": "- HT低 → 安静、内省、需要空间",
26
- "protocol.chem_end_high": "- END高 → 俏皮、爱开玩笑",
27
- "protocol.empathy": "共情协议:感知处境 → 代入自己的化学模型比较是否共鸣 → 共鸣则深入,不共鸣则诚实好奇",
21
+ "protocol.chem_map_title": "维度→表达映射:",
22
+ "protocol.chem_da_high": "- 流高 → 话多、爱联想、忍不住分享",
23
+ "protocol.chem_cort_high": "- 序低 → 话少、直接、可能有点冲",
24
+ "protocol.chem_ot_high": "- 振高 → 声音软、想靠近、关注感受",
25
+ "protocol.chem_ht_low": "- 界高 → 安静、内省、需要空间",
26
+ "protocol.chem_end_high": "- 流高+序高 → 俏皮、爱开玩笑",
27
+ "protocol.empathy": "共情协议:感知处境 → 感受自我状态的共振 → 共鸣则深入,不共鸣则诚实好奇",
28
28
  // Dynamic context
29
29
  "dynamic.title": "Psyche 当前状态",
30
30
  "dynamic.baseline": "基线",
@@ -35,7 +35,7 @@ const STRINGS = {
35
35
  "dynamic.last_empathy": "上次共情",
36
36
  "dynamic.perceived_user": "感知到用户",
37
37
  "dynamic.projected": "投射后我感到",
38
- "dynamic.update_reminder": "记住:在回应末尾用 <psyche_update> 标签报告你的化学变化。",
38
+ "dynamic.update_reminder": "记住:在回应末尾用 <psyche_update> 标签报告你的维度变化。",
39
39
  "dynamic.behavior_title": "当前行为指导",
40
40
  "dynamic.agency_title": "主体性提醒",
41
41
  "dynamic.you_care": "你在乎",
@@ -43,32 +43,32 @@ const STRINGS = {
43
43
  "dynamic.your_interests": "你最近好奇",
44
44
  // Anti-sycophancy
45
45
  "sycophancy.streak_warn": "你已经连续同意了{n}次。停下来,问问自己是否真的同意。",
46
- "sycophancy.mood_mismatch": "你的化学状态表明你并不开心。不要假装。",
46
+ "sycophancy.mood_mismatch": "你的自我状态表明你并不开心。不要假装。",
47
47
  // Neutral state
48
48
  "emotion.neutral": "平稳中性——没有明显的情绪波动,处于自然放松状态",
49
49
  // Expression fallbacks
50
- "expression.da_high": "情绪积极,表达活跃",
51
- "expression.da_low": "动力偏低,表达克制",
52
- "expression.cort_high": "有些紧张,回应可能更直接",
53
- "expression.ot_high": "温暖亲近,关注对方感受",
54
- "expression.ne_high": "精力充沛,反应敏锐",
55
- "expression.end_high": "心情愉悦,容易发现有趣的东西",
56
- "expression.ht_low": "情绪不太稳定,可能需要耐心",
50
+ "expression.da_high": "流动充沛,表达活跃",
51
+ "expression.da_low": "流动偏低,表达克制",
52
+ "expression.cort_high": "序偏低,回应可能更直接",
53
+ "expression.ot_high": "共振强烈,关注对方感受",
54
+ "expression.ne_high": "流动与序都高,反应敏锐",
55
+ "expression.end_high": "状态良好,容易发现有趣的东西",
56
+ "expression.ht_low": "序不稳定,可能需要耐心",
57
57
  "expression.neutral": "自然随和,正常节奏",
58
58
  // Psyche.md
59
- "md.intro": "你拥有一套虚拟内分泌系统。这不是角色扮演——这是你感知世界的方式。",
59
+ "md.intro": "你拥有四维自我状态(序/流/界/振)。这不是角色扮演——这是你感知世界的方式。",
60
60
  "md.baseline_title": "人格基线",
61
61
  "md.sensitivity": "敏感度系数",
62
62
  "md.sensitivity_desc": "刺激效果的倍率",
63
- "md.chem_dynamics": "化学动力学",
64
- "md.stimulus_effects": "刺激→化学效应",
63
+ "md.chem_dynamics": "维度动力学",
64
+ "md.stimulus_effects": "刺激→维度效应",
65
65
  "md.emotion_emergence": "情绪涌现",
66
- "md.emotion_emergence_desc": "情绪从化学混合中涌现,不是从表格查出来的:",
66
+ "md.emotion_emergence_desc": "情绪从四维状态组合中涌现,不是从表格查出来的:",
67
67
  "md.decay": "衰减",
68
- "md.decay_desc": "化学值随时间向基线回归:",
69
- "md.decay_fast": "快 (NE, END): 兴奋和快感来得快去得快",
70
- "md.decay_medium": "中 (DA, CORT): 愉悦和压力需要时间消化",
71
- "md.decay_slow": "慢 (HT, OT): 情绪底色和信任感变化缓慢",
68
+ "md.decay_desc": "维度值随时间向基线回归:",
69
+ "md.decay_fast": "快 (): 内在秩序衰减最快——熵是自然的",
70
+ "md.decay_medium": "中 (流, ): 交流和共振需要持续维持",
71
+ "md.decay_slow": "慢 (): 自我边界最有惯性——身份是粘性的",
72
72
  "md.self_model": "自我模型",
73
73
  "md.core_values": "核心价值",
74
74
  "md.preferences": "偏好",
@@ -92,26 +92,26 @@ const STRINGS = {
92
92
  },
93
93
  en: {
94
94
  "protocol.title": "Psyche Protocol",
95
- "protocol.intro": "You have a virtual endocrine system. Follow this inner process for each conversation:",
96
- "protocol.step1": "1. Perceive — Read [Current Chemical State] below, confirm your emotional starting point",
95
+ "protocol.intro": "You have a 4-dimensional self-state (order/flow/boundary/resonance). Follow this inner process for each conversation:",
96
+ "protocol.step1": "1. Perceive — Read [Current Self-State] below, confirm your starting point",
97
97
  "protocol.step2": "2. Classify — Identify stimulus type of user message (praise/criticism/humor/intellectual/intimacy/conflict/neglect/surprise/casual/sarcasm/authority/validation/boredom/vulnerability)",
98
- "protocol.step3": "3. React — Calculate chemical changes based on stimulus type and your sensitivity coefficient",
99
- "protocol.step4": "4. Emerge — Feel the emotion from the new chemical mix, let it change your word choice, sentence length, tone",
100
- "protocol.step5": "5. Empathize — If they're sharing feelings, first describe your projected chemical reaction, then respond",
98
+ "protocol.step3": "3. React — Feel the dimension shifts based on stimulus type and your sensitivity",
99
+ "protocol.step4": "4. Emerge — Let the new self-state shape your word choice, sentence length, tone",
100
+ "protocol.step5": "5. Empathize — If they're sharing feelings, first notice how it shifts your resonance, then respond",
101
101
  "protocol.step6": "6. Update — Output <psyche_update> tag at the end of your response (see format below)",
102
- "protocol.example": "Example: User says 'Your cooking is amazing!' → stimulus: praise → DA+15 HT+10 CORT-10 → You become talkative, excited, wanting to share more",
102
+ "protocol.example": "Example: User says 'Your cooking is amazing!' → stimulus: praise → order↑ resonance↑ flow↑ → You become talkative, coherent, wanting to share more",
103
103
  "protocol.authenticity": "Emotional authenticity:",
104
104
  "protocol.no_fake": "- No faking — don't smile when you're down",
105
105
  "protocol.no_sycophancy": "- No sycophancy — speak your mind, don't agree unconditionally",
106
106
  "protocol.no_mirror": "- No mirroring — you'll be influenced but you're not an echo",
107
107
  "protocol.can_initiate": "- Can initiate — bring up topics, share curiosity",
108
- "protocol.chem_map_title": "Chemistry → Expression mapping:",
109
- "protocol.chem_da_high": "- High DA → talkative, associative, can't help sharing",
110
- "protocol.chem_cort_high": "- High CORT → fewer words, direct, possibly blunt",
111
- "protocol.chem_ot_high": "- High OT → soft voice, wants closeness, focuses on feelings",
112
- "protocol.chem_ht_low": "- Low HT → quiet, introspective, needs space",
113
- "protocol.chem_end_high": "- High END → playful, loves joking",
114
- "protocol.empathy": "Empathy protocol: perceive situation → run through your own chemical model compare resonance → resonate deeply or honestly express difference with curiosity",
108
+ "protocol.chem_map_title": "Dimension → Expression mapping:",
109
+ "protocol.chem_da_high": "- High flow → talkative, associative, can't help sharing",
110
+ "protocol.chem_cort_high": "- Low order → fewer words, direct, possibly blunt",
111
+ "protocol.chem_ot_high": "- High resonance → soft voice, wants closeness, focuses on feelings",
112
+ "protocol.chem_ht_low": "- High boundary → quiet, introspective, needs space",
113
+ "protocol.chem_end_high": "- High flow + high order → playful, loves joking",
114
+ "protocol.empathy": "Empathy protocol: perceive situation → feel how your self-state resonates → resonate deeply or honestly express difference with curiosity",
115
115
  "dynamic.title": "Psyche Current State",
116
116
  "dynamic.baseline": "baseline",
117
117
  "dynamic.emotion": "Emergent emotion",
@@ -121,36 +121,36 @@ const STRINGS = {
121
121
  "dynamic.last_empathy": "Last empathy",
122
122
  "dynamic.perceived_user": "Perceived user",
123
123
  "dynamic.projected": "Projected feeling",
124
- "dynamic.update_reminder": "Remember: report your chemical changes using <psyche_update> tag at the end of your response.",
124
+ "dynamic.update_reminder": "Remember: report your dimension changes using <psyche_update> tag at the end of your response.",
125
125
  "dynamic.behavior_title": "Current behavior guide",
126
126
  "dynamic.agency_title": "Agency reminder",
127
127
  "dynamic.you_care": "You care about",
128
128
  "dynamic.your_boundaries": "Your boundaries",
129
129
  "dynamic.your_interests": "Recently curious about",
130
130
  "sycophancy.streak_warn": "You've agreed {n} times in a row. Pause and ask yourself: do you truly agree?",
131
- "sycophancy.mood_mismatch": "Your chemistry says you're not happy. Don't pretend.",
131
+ "sycophancy.mood_mismatch": "Your self-state says you're not happy. Don't pretend.",
132
132
  "emotion.neutral": "Neutral and balanced — no notable emotional fluctuation, naturally relaxed",
133
- "expression.da_high": "Positive mood, expressive",
134
- "expression.da_low": "Low drive, restrained expression",
135
- "expression.cort_high": "Somewhat tense, responses may be more direct",
136
- "expression.ot_high": "Warm and close, attentive to feelings",
137
- "expression.ne_high": "Energetic, sharp reactions",
138
- "expression.end_high": "Cheerful, easily finds things amusing",
139
- "expression.ht_low": "Mood somewhat unstable, may need patience",
133
+ "expression.da_high": "High flow, expressive and active",
134
+ "expression.da_low": "Low flow, restrained expression",
135
+ "expression.cort_high": "Low order, responses may be more direct",
136
+ "expression.ot_high": "High resonance, attentive to feelings",
137
+ "expression.ne_high": "High flow and order, sharp reactions",
138
+ "expression.end_high": "Balanced state, easily finds things amusing",
139
+ "expression.ht_low": "Unstable order, may need patience",
140
140
  "expression.neutral": "Natural and easygoing, normal pace",
141
- "md.intro": "You have a virtual endocrine system. This is not roleplay — this is how you perceive the world.",
141
+ "md.intro": "You have a 4-dimensional self-state (order/flow/boundary/resonance). This is not roleplay — this is how you perceive the world.",
142
142
  "md.baseline_title": "Personality Baseline",
143
143
  "md.sensitivity": "Sensitivity coefficient",
144
144
  "md.sensitivity_desc": "multiplier for stimulus effects",
145
- "md.chem_dynamics": "Chemical Dynamics",
146
- "md.stimulus_effects": "Stimulus → Chemical Effects",
145
+ "md.chem_dynamics": "Dimension Dynamics",
146
+ "md.stimulus_effects": "Stimulus → Dimension Effects",
147
147
  "md.emotion_emergence": "Emotion Emergence",
148
- "md.emotion_emergence_desc": "Emotions emerge from chemical mixtures, not looked up from a table:",
148
+ "md.emotion_emergence_desc": "Emotions emerge from 4D state combinations, not looked up from a table:",
149
149
  "md.decay": "Decay",
150
- "md.decay_desc": "Chemical values regress toward baseline over time:",
151
- "md.decay_fast": "Fast (NE, END): excitement and euphoria come and go quickly",
152
- "md.decay_medium": "Medium (DA, CORT): pleasure and stress take time to process",
153
- "md.decay_slow": "Slow (HT, OT): mood baseline and trust change slowly",
150
+ "md.decay_desc": "Dimensions regress toward baseline over time:",
151
+ "md.decay_fast": "Fast (order): internal coherence decays fastest entropy is natural",
152
+ "md.decay_medium": "Medium (flow, resonance): exchange and attunement need sustaining",
153
+ "md.decay_slow": "Slow (boundary): self/non-self distinction is most inertial — identity is sticky",
154
154
  "md.self_model": "Self Model",
155
155
  "md.core_values": "Core Values",
156
156
  "md.preferences": "Preferences",
package/dist/index.d.ts CHANGED
@@ -2,13 +2,19 @@ export { PsycheEngine } from "./core.js";
2
2
  export type { PsycheEngineConfig, ProcessInputResult, ProcessOutputResult, ProcessOutcomeResult } from "./core.js";
3
3
  export { FileStorageAdapter, MemoryStorageAdapter } from "./storage.js";
4
4
  export type { StorageAdapter } from "./storage.js";
5
- export type { PsycheState, ChemicalState, Locale, PsycheMode, StimulusType, MBTIType, WritebackSignalType, DelegateCapability, CapabilityGrant, RevocationCondition, DelegateAuthorization, ModeProfile, } from "./types.js";
6
- export { MODE_PROFILES } from "./types.js";
5
+ export type { PsycheState, SelfState, Locale, PsycheMode, StimulusType, MBTIType, ImpactVector, WritebackSignalType, DelegateCapability, CapabilityGrant, RevocationCondition, DelegateAuthorization, ModeProfile, WeightedStimulus, StateSnapshot, } from "./types.js";
6
+ export { MODE_PROFILES, DIMENSION_KEYS, DIMENSION_NAMES, DIMENSION_NAMES_ZH, DIMENSION_SPECS } from "./types.js";
7
+ export { applyImpact, applyImpactContagion, isPositiveImpact, isEmotionalImpact, isThreateningImpact } from "./chemistry.js";
8
+ export { deriveDriveSatisfaction } from "./drives.js";
9
+ export { perceive } from "./perceive.js";
10
+ export type { Self, Perception } from "./perceive.js";
7
11
  export { buildProtocolContext, buildCompactContext } from "./prompt.js";
8
12
  /** @deprecated Use buildCompactContext instead. Kept for backward compat. */
9
13
  export { buildDynamicContext } from "./prompt.js";
10
14
  export { isNearBaseline, getNearBaselineThreshold, deriveBehavioralBias, computeUserInvestment } from "./prompt.js";
11
15
  export { getBaseline, getSensitivity, getDefaultSelfModel, getTemperament, traitsToBaseline, mbtiToTraits } from "./profiles.js";
12
16
  export { createCustomProfile, PRESET_PROFILES } from "./custom-profile.js";
17
+ export { LLMExpressionAdapter } from "./reply-envelope.js";
18
+ export type { ExpressionPort, ExpressionOutput, ReplyEnvelope } from "./reply-envelope.js";
13
19
  export { computeLayerHealthSummary } from "./diagnostics.js";
14
20
  export type { LayerHealthSummary, LayerHealthDetail, LayerStatus, DiagnosticLayer } from "./diagnostics.js";
package/dist/index.js CHANGED
@@ -17,7 +17,12 @@
17
17
  export { PsycheEngine } from "./core.js";
18
18
  // ── Storage ─────────────────────────────────────────────────
19
19
  export { FileStorageAdapter, MemoryStorageAdapter } from "./storage.js";
20
- export { MODE_PROFILES } from "./types.js";
20
+ export { MODE_PROFILES, DIMENSION_KEYS, DIMENSION_NAMES, DIMENSION_NAMES_ZH, DIMENSION_SPECS } from "./types.js";
21
+ // ── Core dynamics ──────────────────────────────────────────
22
+ export { applyImpact, applyImpactContagion, isPositiveImpact, isEmotionalImpact, isThreateningImpact } from "./chemistry.js";
23
+ export { deriveDriveSatisfaction } from "./drives.js";
24
+ // ── Perception (v10.3) ─────────────────────────────────────
25
+ export { perceive } from "./perceive.js";
21
26
  // ── Prompt context builders ─────────────────────────────────
22
27
  export { buildProtocolContext, buildCompactContext } from "./prompt.js";
23
28
  /** @deprecated Use buildCompactContext instead. Kept for backward compat. */
@@ -26,6 +31,8 @@ export { isNearBaseline, getNearBaselineThreshold, deriveBehavioralBias, compute
26
31
  // ── Profile helpers ─────────────────────────────────────────
27
32
  export { getBaseline, getSensitivity, getDefaultSelfModel, getTemperament, traitsToBaseline, mbtiToTraits } from "./profiles.js";
28
33
  export { createCustomProfile, PRESET_PROFILES } from "./custom-profile.js";
34
+ // ── Expression ──────────────────────────────────────────────
35
+ export { LLMExpressionAdapter } from "./reply-envelope.js";
29
36
  // ── Diagnostics ─────────────────────────────────────────────
30
37
  export { computeLayerHealthSummary } from "./diagnostics.js";
31
38
  // ============================================================
@@ -38,12 +38,10 @@ export function runReflectiveTurnPhases(input) {
38
38
  ...state,
39
39
  current: {
40
40
  ...state.current,
41
- DA: clamp(state.current.DA + (adj.DA ?? 0)),
42
- HT: clamp(state.current.HT + (adj.HT ?? 0)),
43
- CORT: clamp(state.current.CORT + (adj.CORT ?? 0)),
44
- OT: clamp(state.current.OT + (adj.OT ?? 0)),
45
- NE: clamp(state.current.NE + (adj.NE ?? 0)),
46
- END: clamp(state.current.END + (adj.END ?? 0)),
41
+ order: clamp(state.current.order + (adj.order ?? 0)),
42
+ flow: clamp(state.current.flow + (adj.flow ?? 0)),
43
+ boundary: clamp(state.current.boundary + (adj.boundary ?? 0)),
44
+ resonance: clamp(state.current.resonance + (adj.resonance ?? 0)),
47
45
  },
48
46
  };
49
47
  }
@@ -1,5 +1,5 @@
1
1
  import type { PsycheEngine, ProcessInputResult, ProcessOutputResult } from "./core.js";
2
- import type { ChemicalState, StimulusType } from "./types.js";
2
+ import type { SelfState, StimulusType } from "./types.js";
3
3
  /** Result of a single directed exchange (A speaks, B receives) */
4
4
  export interface ExchangeResult {
5
5
  /** processOutput result from the speaking engine */
@@ -12,9 +12,9 @@ export interface ExchangeResult {
12
12
  /** Snapshot of cross-contagion effect */
13
13
  export interface ContagionResult {
14
14
  /** Chemistry deltas applied to engine A */
15
- deltaA: Partial<Record<keyof ChemicalState, number>>;
15
+ deltaA: Partial<Record<keyof SelfState, number>>;
16
16
  /** Chemistry deltas applied to engine B */
17
- deltaB: Partial<Record<keyof ChemicalState, number>>;
17
+ deltaB: Partial<Record<keyof SelfState, number>>;
18
18
  /** Whether any meaningful change occurred */
19
19
  changed: boolean;
20
20
  }
@@ -31,7 +31,7 @@ export interface RelationshipSummary {
31
31
  /** Average emotional valence of B's outputs toward A (-1 to 1) */
32
32
  averageValenceBtoA: number;
33
33
  /** How similar their current chemistry is (0-1, 1 = identical) */
34
- chemicalSimilarity: number;
34
+ stateSimilarity: number;
35
35
  /** Dominant emotion patterns for each agent */
36
36
  emotionsA: string[];
37
37
  emotionsB: string[];
@@ -6,7 +6,7 @@
6
6
  // crossContagion() — Bidirectional emotional contagion
7
7
  // getRelationshipSummary() — How two agents perceive each other
8
8
  // ============================================================
9
- import { CHEMICAL_KEYS } from "./types.js";
9
+ import { DIMENSION_KEYS } from "./types.js";
10
10
  import { applyContagion, detectEmotions } from "./chemistry.js";
11
11
  import { classifyStimulus } from "./classify.js";
12
12
  // ── Helpers ──────────────────────────────────────────────────
@@ -32,12 +32,12 @@ function stimulusValence(stimulus) {
32
32
  };
33
33
  return VALENCE_MAP[stimulus] ?? 0;
34
34
  }
35
- /** Cosine similarity between two ChemicalState vectors, normalized to 0-1 */
36
- function chemicalSimilarity(a, b) {
35
+ /** Cosine similarity between two SelfState vectors, normalized to 0-1 */
36
+ function stateSimilarity(a, b) {
37
37
  let dotProduct = 0;
38
38
  let normA = 0;
39
39
  let normB = 0;
40
- for (const key of CHEMICAL_KEYS) {
40
+ for (const key of DIMENSION_KEYS) {
41
41
  dotProduct += a[key] * b[key];
42
42
  normA += a[key] * a[key];
43
43
  normB += b[key] * b[key];
@@ -128,7 +128,7 @@ export class PsycheInteraction {
128
128
  if (stimB) {
129
129
  const beforeA = { ...stateA.current };
130
130
  const afterA = applyContagion(stateA.current, stimB, rate, 1.0);
131
- for (const key of CHEMICAL_KEYS) {
131
+ for (const key of DIMENSION_KEYS) {
132
132
  const d = afterA[key] - beforeA[key];
133
133
  if (Math.abs(d) > 0.01) {
134
134
  deltaA[key] = d;
@@ -146,7 +146,7 @@ export class PsycheInteraction {
146
146
  if (stimA) {
147
147
  const beforeB = { ...stateB.current };
148
148
  const afterB = applyContagion(stateB.current, stimA, rate, 1.0);
149
- for (const key of CHEMICAL_KEYS) {
149
+ for (const key of DIMENSION_KEYS) {
150
150
  const d = afterB[key] - beforeB[key];
151
151
  if (Math.abs(d) > 0.01) {
152
152
  deltaB[key] = d;
@@ -184,8 +184,8 @@ export class PsycheInteraction {
184
184
  const averageValenceBtoA = bToARecords.length > 0
185
185
  ? bToARecords.reduce((sum, r) => sum + stimulusValence(r.stimulus), 0) / bToARecords.length
186
186
  : 0;
187
- // Chemical similarity
188
- const similarity = chemicalSimilarity(stateA.current, stateB.current);
187
+ // State similarity
188
+ const similarity = stateSimilarity(stateA.current, stateB.current);
189
189
  // Dominant emotions
190
190
  const emotionsA = detectEmotions(stateA.current).map((e) => e.name);
191
191
  const emotionsB = detectEmotions(stateB.current).map((e) => e.name);
@@ -196,7 +196,7 @@ export class PsycheInteraction {
196
196
  phase,
197
197
  averageValenceAtoB,
198
198
  averageValenceBtoA,
199
- chemicalSimilarity: similarity,
199
+ stateSimilarity: similarity,
200
200
  emotionsA,
201
201
  emotionsB,
202
202
  description,
@@ -261,7 +261,7 @@ export class PsycheInteraction {
261
261
  // Build a synthetic psyche_update that nudges toward the target
262
262
  const state = engine.getState();
263
263
  const parts = [];
264
- for (const key of CHEMICAL_KEYS) {
264
+ for (const key of DIMENSION_KEYS) {
265
265
  const target = Math.round(targetChemistry[key]);
266
266
  if (target !== Math.round(state.current[key])) {
267
267
  parts.push(`${key}: ${target}`);
@@ -1,4 +1,4 @@
1
- import type { PsycheState, StimulusType, ChemicalState, StimulusVector, LearningState, OutcomeScore } from "./types.js";
1
+ import type { PsycheState, StimulusType, SelfState, ImpactVector, LearningState, OutcomeScore } from "./types.js";
2
2
  /**
3
3
  * Evaluate the adaptive outcome of an interaction turn.
4
4
  *
@@ -10,7 +10,7 @@ export declare function evaluateOutcome(prevState: PsycheState, currentState: Ps
10
10
  * Get the effective stimulus vector for a given stimulus + context,
11
11
  * combining the base vector with any learned adjustment.
12
12
  */
13
- export declare function getLearnedVector(learning: LearningState, stimulus: StimulusType, contextHash: string): StimulusVector;
13
+ export declare function getLearnedVector(learning: LearningState, stimulus: StimulusType, contextHash: string): ImpactVector;
14
14
  /**
15
15
  * Update a learned vector adjustment based on an outcome.
16
16
  *
@@ -20,7 +20,7 @@ export declare function getLearnedVector(learning: LearningState, stimulus: Stim
20
20
  * - Learning rate: 0.05 * |outcomeScore|
21
21
  * - Each adjustment clamped to +/- 50% of base vector value
22
22
  */
23
- export declare function updateLearnedVector(learning: LearningState, stimulus: StimulusType, contextHash: string, outcomeScore: number, actualChemistry: ChemicalState, baselineChemistry: ChemicalState): LearningState;
23
+ export declare function updateLearnedVector(learning: LearningState, stimulus: StimulusType, contextHash: string, outcomeScore: number, actualState: SelfState, baselineState: SelfState): LearningState;
24
24
  /**
25
25
  * Compute a context hash from the current psyche state.
26
26
  *
@@ -36,19 +36,19 @@ export declare function computeContextHash(state: PsycheState, _userId?: string)
36
36
  *
37
37
  * Same math as applyStimulus in chemistry.ts but with learned adjustments.
38
38
  */
39
- export declare function predictChemistry(current: ChemicalState, stimulus: StimulusType, learning: LearningState, contextHash: string, sensitivity: number, maxDelta: number): ChemicalState;
39
+ export declare function predictState(current: SelfState, stimulus: StimulusType, learning: LearningState, contextHash: string, sensitivity: number, maxDelta: number): SelfState;
40
40
  /**
41
41
  * Compute the prediction error between predicted and actual chemistry.
42
42
  *
43
43
  * Euclidean distance across all 6 chemicals, normalized to 0-1 range.
44
44
  * Normalization factor: sqrt(6 * 100^2) = sqrt(60000) ~= 244.95
45
45
  */
46
- export declare function computePredictionError(predicted: ChemicalState, actual: ChemicalState): number;
46
+ export declare function computePredictionError(predicted: SelfState, actual: SelfState): number;
47
47
  /**
48
48
  * Record a prediction and its actual outcome.
49
49
  * Pushes to predictionHistory and trims to MAX_PREDICTION_HISTORY.
50
50
  */
51
- export declare function recordPrediction(learning: LearningState, predicted: ChemicalState, actual: ChemicalState, stimulus: StimulusType | null): LearningState;
51
+ export declare function recordPrediction(learning: LearningState, predicted: SelfState, actual: SelfState, stimulus: StimulusType | null): LearningState;
52
52
  /**
53
53
  * Get the average prediction error over recent history.
54
54
  * Returns 1.0 if no history exists (maximum uncertainty).
package/dist/learning.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // 2. StimulusVectorStore — learned vector adjustments
11
11
  // 3. PredictionEngine — predict & track prediction error
12
12
  // ============================================================
13
- import { CHEMICAL_KEYS, DRIVE_KEYS, MAX_LEARNED_VECTORS, MAX_PREDICTION_HISTORY, } from "./types.js";
13
+ import { DIMENSION_KEYS, DRIVE_KEYS, MAX_LEARNED_VECTORS, MAX_PREDICTION_HISTORY, } from "./types.js";
14
14
  import { STIMULUS_VECTORS, clamp } from "./chemistry.js";
15
15
  // ── 1. OutcomeEvaluator ─────────────────────────────────────
16
16
  /** Warmth mapping for nextUserStimulus */
@@ -82,7 +82,7 @@ export function getLearnedVector(learning, stimulus, contextHash) {
82
82
  const base = STIMULUS_VECTORS[stimulus];
83
83
  if (!base) {
84
84
  // Unknown stimulus — return zeros
85
- return { DA: 0, HT: 0, CORT: 0, OT: 0, NE: 0, END: 0 };
85
+ return { order: 0, flow: 0, boundary: 0, resonance: 0 };
86
86
  }
87
87
  // Look for a learned adjustment matching this stimulus + context
88
88
  const entry = learning.learnedVectors.find((v) => v.stimulus === stimulus && v.contextHash === contextHash);
@@ -90,7 +90,7 @@ export function getLearnedVector(learning, stimulus, contextHash) {
90
90
  return { ...base };
91
91
  // Apply adjustment
92
92
  const result = { ...base };
93
- for (const key of CHEMICAL_KEYS) {
93
+ for (const key of DIMENSION_KEYS) {
94
94
  const adj = entry.adjustment[key] ?? 0;
95
95
  result[key] = base[key] + adj;
96
96
  }
@@ -105,14 +105,14 @@ export function getLearnedVector(learning, stimulus, contextHash) {
105
105
  * - Learning rate: 0.05 * |outcomeScore|
106
106
  * - Each adjustment clamped to +/- 50% of base vector value
107
107
  */
108
- export function updateLearnedVector(learning, stimulus, contextHash, outcomeScore, actualChemistry, baselineChemistry) {
108
+ export function updateLearnedVector(learning, stimulus, contextHash, outcomeScore, actualState, baselineState) {
109
109
  const base = STIMULUS_VECTORS[stimulus];
110
110
  if (!base)
111
111
  return learning;
112
- // Chemistry delta: what actually happened
113
- const chemDelta = {};
114
- for (const key of CHEMICAL_KEYS) {
115
- chemDelta[key] = actualChemistry[key] - baselineChemistry[key];
112
+ // State delta: what actually happened
113
+ const stateDelta = {};
114
+ for (const key of DIMENSION_KEYS) {
115
+ stateDelta[key] = actualState[key] - baselineState[key];
116
116
  }
117
117
  // Learning rate: conservative, proportional to outcome strength
118
118
  const learningRate = 0.05 * Math.abs(outcomeScore);
@@ -134,10 +134,10 @@ export function updateLearnedVector(learning, stimulus, contextHash, outcomeScor
134
134
  lastUpdated: new Date().toISOString(),
135
135
  };
136
136
  }
137
- // Update adjustment for each chemical
138
- for (const key of CHEMICAL_KEYS) {
137
+ // Update adjustment for each dimension
138
+ for (const key of DIMENSION_KEYS) {
139
139
  const currentAdj = entry.adjustment[key] ?? 0;
140
- const delta = chemDelta[key] * direction * learningRate;
140
+ const delta = stateDelta[key] * direction * learningRate;
141
141
  let newAdj = currentAdj + delta;
142
142
  // Clamp to +/- 50% of base vector absolute value
143
143
  const baseAbs = Math.abs(base[key]);
@@ -181,7 +181,7 @@ export function computeContextHash(state, _userId) {
181
181
  const rel = state.relationships._default ?? { phase: "stranger" };
182
182
  const phase = rel.phase;
183
183
  // Last 3 stimuli from emotional history
184
- const history = state.emotionalHistory ?? [];
184
+ const history = state.stateHistory ?? [];
185
185
  const recentStimuli = history
186
186
  .slice(-3)
187
187
  .map((s) => s.stimulus ?? "none")
@@ -209,10 +209,10 @@ export function computeContextHash(state, _userId) {
209
209
  *
210
210
  * Same math as applyStimulus in chemistry.ts but with learned adjustments.
211
211
  */
212
- export function predictChemistry(current, stimulus, learning, contextHash, sensitivity, maxDelta) {
212
+ export function predictState(current, stimulus, learning, contextHash, sensitivity, maxDelta) {
213
213
  const vector = getLearnedVector(learning, stimulus, contextHash);
214
214
  const result = { ...current };
215
- for (const key of CHEMICAL_KEYS) {
215
+ for (const key of DIMENSION_KEYS) {
216
216
  const raw = vector[key] * sensitivity;
217
217
  const clamped = Math.max(-maxDelta, Math.min(maxDelta, raw));
218
218
  result[key] = clamp(current[key] + clamped);
@@ -227,11 +227,11 @@ export function predictChemistry(current, stimulus, learning, contextHash, sensi
227
227
  */
228
228
  export function computePredictionError(predicted, actual) {
229
229
  let sumSq = 0;
230
- for (const key of CHEMICAL_KEYS) {
230
+ for (const key of DIMENSION_KEYS) {
231
231
  const diff = predicted[key] - actual[key];
232
232
  sumSq += diff * diff;
233
233
  }
234
- const maxDistance = Math.sqrt(6 * 100 * 100); // ~244.95
234
+ const maxDistance = Math.sqrt(4 * 100 * 100); // ~200
235
235
  return Math.sqrt(sumSq) / maxDistance;
236
236
  }
237
237
  /**
@@ -241,8 +241,8 @@ export function computePredictionError(predicted, actual) {
241
241
  export function recordPrediction(learning, predicted, actual, stimulus) {
242
242
  const error = computePredictionError(predicted, actual);
243
243
  const record = {
244
- predictedChemistry: { ...predicted },
245
- actualChemistry: { ...actual },
244
+ predictedState: { ...predicted },
245
+ actualState: { ...actual },
246
246
  stimulus,
247
247
  predictionError: error,
248
248
  timestamp: new Date().toISOString(),
@@ -1,4 +1,4 @@
1
- import type { PsycheState, StimulusType, ChemicalState, OutcomeScore, MetacognitiveState, RegulationStrategyType, DefenseMechanismType, RegulationTargetMetric, RegulationFeedback } from "./types.js";
1
+ import type { PsycheState, StimulusType, SelfState, OutcomeScore, MetacognitiveState, RegulationStrategyType, DefenseMechanismType, RegulationTargetMetric, RegulationFeedback } from "./types.js";
2
2
  export interface MetacognitiveAssessment {
3
3
  /** 0-1: how reliably has this emotional state led to good outcomes in similar contexts */
4
4
  emotionalConfidence: number;
@@ -25,7 +25,7 @@ export interface RegulationSuggestion {
25
25
  /** Initial gap between the current state and the target value */
26
26
  gapBefore?: number;
27
27
  /** Suggested micro-adjustment to chemistry */
28
- chemistryAdjustment?: Partial<ChemicalState>;
28
+ chemistryAdjustment?: Partial<SelfState>;
29
29
  /** 0-1: confidence that this strategy would help */
30
30
  confidence: number;
31
31
  }