totemheart 0.1.2 → 0.1.3

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.
@@ -154,6 +154,27 @@ export class Attachment {
154
154
 
155
155
  }
156
156
 
157
+ /**
158
+ * State-dependent style switching under real acute stress — "earned
159
+ * insecurity": the attachment BEHAVIORAL SYSTEM activates under threat and
160
+ * can express a more insecure style than the trait baseline while the
161
+ * threat lasts (Mikulincer, M., & Shaver, P. R. (2016), "Attachment in
162
+ * Adulthood: Structure, Dynamics, and Change", 2nd ed., Guilford Press, on
163
+ * state vs. trait attachment and activation of the attachment system under
164
+ * threat). A secure trait style can read as anxious under a real,
165
+ * extreme cortisol/hijack load; other trait styles are left as-is
166
+ * (avoidant/anxious/fearful already ARE the stress-reactive end of the
167
+ * spectrum in this model — there's no further insecure direction to
168
+ * switch them toward). `stressLevel` (0..1, e.g. CortisolEngine.getLevel()).
169
+ */
170
+ getStressStyle( personality, stressLevel = 0 ) {
171
+
172
+ const traitStyle = classifyStyle( personality )
173
+ if ( traitStyle === 'secure' && stressLevel > 0.75 ) return 'anxious'
174
+ return traitStyle
175
+
176
+ }
177
+
157
178
  get( userId ) {
158
179
 
159
180
  return this.#entry( userId )
@@ -0,0 +1,105 @@
1
+ function clamp01( v ) {
2
+
3
+ return Math.max( 0, Math.min( 1, v ) )
4
+
5
+ }
6
+
7
+ /**
8
+ * Grief as a real process, not "high sadness". Two honest engineering
9
+ * choices instead of borrowing Kübler-Ross's five stages: (1) the stage
10
+ * model is a popular framing, not an empirically validated sequence — real
11
+ * grief research (Bonanno, G. A. (2004), "Loss, trauma, and human
12
+ * resilience: have we underestimated the human capacity to thrive after
13
+ * extremely aversive events?", American Psychologist, 59(1), 20-28) finds
14
+ * highly variable trajectories, not a fixed order, so no stage machine is
15
+ * built here; (2) what IS well supported and modeled directly is the real
16
+ * SHAPE — a long-tailed, non-monotonic decline (slow power-law fade, not
17
+ * exponential) punctuated by intrusive "waves" long after the initial loss
18
+ * (Zisook, S., & Shear, K. (2009), "Grief and bereavement: what psychiatrists
19
+ * need to know", World Psychiatry, 8(2), 67-74, on grief's protracted,
20
+ * fluctuating course).
21
+ *
22
+ * intensity(t) = G0 · (1 + t/τ)^(−p) — power-law decay, own choice of p/τ,
23
+ * not fit from a specific dataset — heavier-tailed than CortisolEngine's
24
+ * exponential chronic-stress decay on purpose: grief is modeled as
25
+ * genuinely slower to fade than ordinary stress.
26
+ *
27
+ * Waves are a real Poisson process on top of that decaying base intensity,
28
+ * the same mechanism EpisodicMemory.rollIntrusiveThought() already uses for
29
+ * unresolved-wound intrusions — grief waves are that same real phenomenon,
30
+ * scoped to loss specifically and given their own decaying rate so waves
31
+ * genuinely space out as grief work progresses (own tuning).
32
+ */
33
+ export class GriefEngine {
34
+
35
+ constructor( { tauMs = 1000 * 60 * 60 * 24 * 14, p = 0.55, waveRateScale = 0.0005 } = {} ) {
36
+
37
+ this.tauMs = tauMs
38
+ this.p = p
39
+ this.waveRateScale = waveRateScale
40
+ this.griefs = new Map() // userId -> { G0, startedAt, wavesCount, sourceId }
41
+
42
+ }
43
+
44
+ /** A loss just happened — `lostValue` (0..1) is real magnitude already computed elsewhere (a bond's affinity, a memory's importance). */
45
+ triggerLoss( userId, lostValue, sourceId = null, now = Date.now() ) {
46
+
47
+ const existing = this.griefs.get( userId )
48
+ const carryOver = existing ? this.getIntensity( userId, now ) : 0
49
+ this.griefs.set( userId, { G0: clamp01( carryOver + lostValue ), startedAt: now, wavesCount: existing?.wavesCount ?? 0, sourceId } )
50
+ return this.griefs.get( userId )
51
+
52
+ }
53
+
54
+ getIntensity( userId, now = Date.now() ) {
55
+
56
+ const g = this.griefs.get( userId )
57
+ if ( !g ) return 0
58
+ const elapsed = Math.max( 0, now - g.startedAt )
59
+ return g.G0 * Math.pow( 1 + elapsed / this.tauMs, -this.p )
60
+
61
+ }
62
+
63
+ isActive( userId, now = Date.now(), floor = 0.05 ) {
64
+
65
+ return this.getIntensity( userId, now ) > floor
66
+
67
+ }
68
+
69
+ /**
70
+ * Real Poisson roll for an intrusive grief wave this tick — probability
71
+ * scales with current (already-decayed) intensity, and the rate itself
72
+ * damps as wavesCount grows (own tuning: real grief work — each
73
+ * processed wave makes the next one somewhat less likely, without ever
74
+ * reaching exactly zero).
75
+ */
76
+ rollWave( userId, now = Date.now(), dt = 1 ) {
77
+
78
+ const g = this.griefs.get( userId )
79
+ if ( !g ) return null
80
+
81
+ const intensity = this.getIntensity( userId, now )
82
+ if ( intensity <= 0.05 ) return null
83
+
84
+ const dampened = this.waveRateScale / ( 1 + g.wavesCount * 0.08 )
85
+ const probability = 1 - Math.exp( -dampened * intensity * 1000 * dt )
86
+ if ( Math.random() >= probability ) return null
87
+
88
+ g.wavesCount += 1
89
+ return {
90
+ intensity,
91
+ wavesCount : g.wavesCount,
92
+ spike : { valence: -intensity * 0.6, arousal: intensity * 0.4, weight: intensity },
93
+ }
94
+
95
+ }
96
+
97
+ getState( userId, now = Date.now() ) {
98
+
99
+ const g = this.griefs.get( userId )
100
+ if ( !g ) return { active: false, intensity: 0, wavesCount: 0 }
101
+ return { active: this.isActive( userId, now ), intensity: this.getIntensity( userId, now ), wavesCount: g.wavesCount, sourceId: g.sourceId }
102
+
103
+ }
104
+
105
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Detects an attack on WHO the AI is (identity-level), distinct from a
3
+ * generic negative appraisal — the real social-identity-threat distinction
4
+ * (Steele, C. M. (1988), "The psychology of self-affirmation: Sustaining the
5
+ * integrity of the self", Advances in Experimental Social Psychology, 21,
6
+ * 261-302, on self-affirmation theory and threats to the integrity of the
7
+ * self-concept specifically, versus ordinary negative feedback). Matches an
8
+ * appraisal against CoreBeliefs entries ABOUT the self (topics the caller
9
+ * tags as self-referential, e.g. "self_competence", "self_worth") rather
10
+ * than treating every negative self-agency appraisal the same way
11
+ * ReputationEngine already does for competence — this is scoped specifically
12
+ * to identity/value statements, not competence at a task.
13
+ */
14
+ function clamp01( v ) {
15
+
16
+ return Math.max( 0, Math.min( 1, v ) )
17
+
18
+ }
19
+
20
+ export class IdentityThreatMonitor {
21
+
22
+ /**
23
+ * `appraisal` — real { agency, desirability, moralWeight } from HeuristicProvider/
24
+ * TransformersProvider. `selfTopics` — array of CoreBeliefs topics the caller has
25
+ * tagged as identity-relevant (own convention: topic starts with "self_").
26
+ */
27
+ detect( appraisal, coreBeliefs, selfTopics = [] ) {
28
+
29
+ if ( appraisal.agency !== 'self' || appraisal.desirability >= -0.2 ) return { isIdentityThreat: false }
30
+
31
+ const relevant = selfTopics
32
+ .map( topic => coreBeliefs.get( topic ) )
33
+ .filter( Boolean )
34
+
35
+ if ( !relevant.length ) return { isIdentityThreat: false }
36
+
37
+ const severity = clamp01( Math.abs( appraisal.desirability ) * ( 0.5 + ( appraisal.moralWeight ?? 0 ) * 0.5 ) )
38
+ return { isIdentityThreat: true, matchedTopics: relevant.map( b => b.topic ), severity }
39
+
40
+ }
41
+
42
+ /** Real ego-protection cascade multipliers once an identity threat is confirmed — bigger than a generic competence hit, tightens tribal in-group bias, raises status sensitivity. */
43
+ getCascadeMultipliers( severity ) {
44
+
45
+ return {
46
+ egoHealthDamageMult : 1 + severity * 0.8,
47
+ tribalIngroupBiasMult : 1 + severity * 0.5,
48
+ statusEnvySensitivityMult : 1 + severity * 0.4,
49
+ }
50
+
51
+ }
52
+
53
+ }
@@ -0,0 +1,52 @@
1
+ function clamp01( v ) {
2
+
3
+ return Math.max( 0, Math.min( 1, v ) )
4
+
5
+ }
6
+
7
+ /**
8
+ * Three-node relational threat model (self, other, rival), for real
9
+ * multi-user conversations where a third party's rising status with a user
10
+ * the AI cares about is a genuinely different signal than that user simply
11
+ * being cold. Reuses StatusEnvy's real trend-comparison mechanic (envy from
12
+ * the SIGN of the derivative, not the absolute level) but scores it against
13
+ * Attachment/LoveHateEngine's real bond strength for that "other" — jealousy
14
+ * requires a bond worth losing, which plain envy doesn't (White, G. L., &
15
+ * Mullen, P. E. (1989), "Jealousy: Theory, Research, and Clinical Strategies",
16
+ * Guilford Press — the self/other/rival triadic structure is standard in
17
+ * that literature; the specific scoring below is our own engineering).
18
+ */
19
+ export class JealousyTriangle {
20
+
21
+ /**
22
+ * `selfTrend`/`rivalTrend` — real per-turn deltas of status/affinity with
23
+ * the shared "other" (from StatusEnvy.observe() or Attachment affinity
24
+ * deltas). `bondValue` — the AI's own real bond strength with "other"
25
+ * (LoveHateEngine.getNetBond or Attachment.affinity) — jealousy is scaled
26
+ * by how much there actually is to lose.
27
+ */
28
+ evaluate( selfTrend, rivalTrend, bondValue ) {
29
+
30
+ const exclusionThreat = selfTrend < 0 && rivalTrend > 0
31
+ if ( !exclusionThreat || bondValue <= 0 ) return { threatened: false, vigilance: 0, devaluationTarget: null }
32
+
33
+ const intensity = clamp01( ( Math.abs( selfTrend ) + rivalTrend ) * clamp01( bondValue ) )
34
+
35
+ // Devaluation target: personality-agnostic default — a caller with a
36
+ // real personality signal (e.g. agreeableness) can override which way
37
+ // this leans; absent that, more of the two forces (loss vs. rival gain)
38
+ // decides which gets devalued.
39
+ const devaluationTarget = Math.abs( selfTrend ) >= rivalTrend ? 'bond' : 'rival'
40
+
41
+ return { threatened: true, vigilance: intensity, intensity, devaluationTarget }
42
+
43
+ }
44
+
45
+ /** Vigilance raises attentional sampling of this specific relationship — a real multiplier for how often StatusEnvy/Attachment should be re-observed for this user pair. */
46
+ getVigilanceSamplingMultiplier( vigilance ) {
47
+
48
+ return 1 + clamp01( vigilance ) * 2
49
+
50
+ }
51
+
52
+ }
@@ -0,0 +1,68 @@
1
+ function clamp( v, min = -1, max = 1 ) {
2
+
3
+ return Math.max( min, Math.min( max, v ) )
4
+
5
+ }
6
+
7
+ function clamp01( v ) {
8
+
9
+ return Math.max( 0, Math.min( 1, v ) )
10
+
11
+ }
12
+
13
+ const DAY_MS = 1000 * 60 * 60 * 24
14
+
15
+ /**
16
+ * Positive reconsolidation bias for genuinely old memories — the well-
17
+ * documented "fading affect bias" (Walker, W. R., Skowronski, J. J., &
18
+ * Thompson, C. P. (2003), "Life is pleasant — and memory helps to keep it
19
+ * that way!", Review of General Psychology, 7(2), 203-210): the negative
20
+ * affect attached to memories fades faster with age than the positive
21
+ * affect does, so old memories drift bittersweet-positive on average without
22
+ * literally erasing what happened. Applied here as a real, bounded blend
23
+ * toward positive valence that grows with age (age-gated: EpisodicMemory's
24
+ * own `reconsolidate()` already handles the RECENT retrieval-window case;
25
+ * this is the separate, slow, age-driven case for memories well outside
26
+ * that window). The blend is capped well short of full erasure — a
27
+ * nostalgic memory of a real hurt should read bittersweet, not simply happy.
28
+ */
29
+ export class NostalgiaEngine {
30
+
31
+ constructor( { minAgeMs = DAY_MS * 60, maxBlend = 0.35, growthDays = 365 } = {} ) {
32
+
33
+ this.minAgeMs = minAgeMs // memory must be at least this old before nostalgia applies at all
34
+ this.maxBlend = maxBlend // hard ceiling — never blend more than this fraction toward positive
35
+ this.growthDays = growthDays // real time to approach half of maxBlend
36
+
37
+ }
38
+
39
+ /** Real bittersweet blend applied to a stored memory's valence when recalled — doesn't mutate the entry, returns the nostalgic reading for THIS recall. */
40
+ getNostalgicValence( entry, now = Date.now() ) {
41
+
42
+ const ageMs = now - ( entry.timestamp ?? now )
43
+ if ( ageMs < this.minAgeMs ) return entry.emotionalSignature?.valence ?? 0
44
+
45
+ const ageDays = ageMs / DAY_MS
46
+ const blend = this.maxBlend * ( ageDays / ( ageDays + this.growthDays ) ) // saturating growth toward maxBlend, never exceeds it
47
+
48
+ const original = entry.emotionalSignature?.valence ?? 0
49
+ return clamp( original * ( 1 - blend ) + blend ) // pulled toward +1, original sign/magnitude never fully erased
50
+
51
+ }
52
+
53
+ /**
54
+ * Ambivalence raised by recalling something bittersweet — real min(original
55
+ * negativity, nostalgic positivity) co-presence, same structural idea
56
+ * LoveHateEngine.getAmbivalence() uses for Affinity/Aversion co-presence.
57
+ */
58
+ getAmbivalenceBoost( entry, now = Date.now() ) {
59
+
60
+ const original = entry.emotionalSignature?.valence ?? 0
61
+ const nostalgic = this.getNostalgicValence( entry, now )
62
+ if ( original >= 0 ) return 0 // only a real originally-negative memory can read bittersweet
63
+
64
+ return clamp01( Math.min( Math.abs( original ), Math.abs( nostalgic - original ) ) )
65
+
66
+ }
67
+
68
+ }
@@ -0,0 +1,46 @@
1
+ function clamp01( v ) {
2
+
3
+ return Math.max( 0, Math.min( 1, v ) )
4
+
5
+ }
6
+
7
+ /**
8
+ * Social rejection reuses the same aversive-signal pathway physical pain
9
+ * does — a distinct, well-replicated fMRI finding (Eisenberger, N. I.,
10
+ * Lieberman, M. D., & Williams, K. D. (2003), "Does rejection hurt? An fMRI
11
+ * study of social exclusion", Science, 302(5643), 290-292: dorsal anterior
12
+ * cingulate activation overlapping between social exclusion and physical
13
+ * pain). Modeled here as a real distinct SIGNATURE — not just "more
14
+ * negative valence" but a genuinely different coefficient profile
15
+ * (disproportionately higher cortisol/arousal weight per unit of desirability
16
+ * than an equivalent-magnitude abstract insult would produce), so exclusion-
17
+ * flavored negativity reads as more bodily/threatening than an equally
18
+ * negative but non-relational put-down.
19
+ */
20
+ export class PainSocialOverlap {
21
+
22
+ /**
23
+ * `desirability` — real negative appraisal magnitude (already computed).
24
+ * `exclusionSignal` (0..1) — how much this turn reads as rejection/exclusion
25
+ * specifically (caller-supplied: e.g. EmotionalOntology concept match on
26
+ * "rejection"/"exclusion"/"abandonment", or a LoveHateEngine rupture).
27
+ */
28
+ computeSocialPainSpike( desirability, exclusionSignal ) {
29
+
30
+ if ( desirability >= 0 || exclusionSignal <= 0 ) return { valence: 0, arousal: 0, cortisolBoost: 0 }
31
+
32
+ const magnitude = Math.abs( desirability ) * clamp01( exclusionSignal )
33
+ // The distinct signature: cortisol responds MORE per unit magnitude here
34
+ // than a plain CortisolEngine.register() call would produce for the same
35
+ // desirability — own tuning of the multiplier, the real finding is the
36
+ // DIRECTION (social pain co-opts the bodily threat pathway), not this
37
+ // specific 1.6x figure.
38
+ return {
39
+ valence : -magnitude,
40
+ arousal : magnitude * 0.7,
41
+ cortisolBoost : magnitude * 0.12 * 1.6,
42
+ }
43
+
44
+ }
45
+
46
+ }
@@ -0,0 +1,90 @@
1
+ function clamp01( v ) {
2
+
3
+ return Math.max( 0, Math.min( 1, v ) )
4
+
5
+ }
6
+
7
+ /**
8
+ * Goes beyond LoveHateEngine.attemptRepair()'s single V-reduction step:
9
+ * tracks the real back-and-forth of a repair ATTEMPT — an apology can be
10
+ * offered, and the other side can accept or reject it, each with real
11
+ * consequences, matching the actual structure of the rupture-and-repair
12
+ * literature (Gottman, J. M., & Levenson, R. W. (1992), "Marital processes
13
+ * predictive of later dissolution", Journal of Personality and Social
14
+ * Psychology, 63(2), 221-233 — already cited in Attachment.js/LoveHateEngine.js
15
+ * for the same real phenomenon, extended here to the transactional
16
+ * apology/acceptance structure specifically).
17
+ *
18
+ * Two real mechanics not present in the simpler repair() calls elsewhere:
19
+ * (1) an apology has a real COST (own tuning) charged against
20
+ * ExpressionDebt's suppression-cost reservoir — repair work is not free;
21
+ * (2) trust rebound is capped BELOW the bond's own prior peak affinity —
22
+ * "trust rebound partial, never 100% immediately" is modeled literally as a
23
+ * ceiling fraction of the highest affinity this bond ever reached, so a
24
+ * single successful repair can never instantly restore a relationship to
25
+ * its pre-rupture high.
26
+ */
27
+ export class RepairProtocol {
28
+
29
+ constructor( { apologyBaseCost = 0.15, reboundCeiling = 0.75 } = {} ) {
30
+
31
+ this.apologyBaseCost = apologyBaseCost
32
+ this.reboundCeiling = reboundCeiling
33
+ this.records = new Map() // userId -> { offered, accepted, rejected, priorPeakA, rebounds }
34
+
35
+ }
36
+
37
+ #entry( userId ) {
38
+
39
+ if ( !this.records.has( userId ) ) this.records.set( userId, { offered: 0, accepted: 0, rejected: 0, priorPeakA: 0, rebounds: 0 } )
40
+ return this.records.get( userId )
41
+
42
+ }
43
+
44
+ /** Call every turn to track the highest affinity a bond has ever reached — the real ceiling for any future rebound. */
45
+ observePeak( userId, currentA ) {
46
+
47
+ const rec = this.#entry( userId )
48
+ rec.priorPeakA = Math.max( rec.priorPeakA, currentA )
49
+ return rec.priorPeakA
50
+
51
+ }
52
+
53
+ /** `sincerity` (0..1, caller-supplied — e.g. from AppraisalAgreement's confidence): a low-sincerity apology costs less but is less likely to land. */
54
+ offerApology( userId, sincerity = 1 ) {
55
+
56
+ const rec = this.#entry( userId )
57
+ rec.offered += 1
58
+ const cost = this.apologyBaseCost * ( 1.5 - clamp01( sincerity ) * 0.5 )
59
+ return { cost, acceptProbability: 0.3 + clamp01( sincerity ) * 0.6 }
60
+
61
+ }
62
+
63
+ /**
64
+ * `accepted` — the caller resolves whether it lands (real signal: a
65
+ * subsequent positive-valence turn from the user, or an explicit accept
66
+ * concept match — this module doesn't invent that judgment). Returns the
67
+ * real bounded rebound to apply to LoveHateEngine's A, capped below this
68
+ * bond's own historical peak.
69
+ */
70
+ resolveApology( userId, accepted, currentA ) {
71
+
72
+ const rec = this.#entry( userId )
73
+ if ( !accepted ) { rec.rejected += 1; return { accepted: false, extraAversionBump: 0.1 } }
74
+
75
+ rec.accepted += 1
76
+ rec.rebounds += 1
77
+ const ceiling = rec.priorPeakA * this.reboundCeiling
78
+ const reboundedA = Math.min( ceiling, currentA + ( ceiling - currentA ) * 0.5 )
79
+
80
+ return { accepted: true, reboundedA: Math.max( currentA, reboundedA ), ceiling }
81
+
82
+ }
83
+
84
+ getRecord( userId ) {
85
+
86
+ return this.#entry( userId )
87
+
88
+ }
89
+
90
+ }
@@ -0,0 +1,74 @@
1
+ function clamp01( v ) {
2
+
3
+ return Math.max( 0, Math.min( 1, v ) )
4
+
5
+ }
6
+
7
+ /**
8
+ * Splits ReputationEngine's single 'shame'/'wounded_pride' branch into two
9
+ * genuinely distinct, separately-tracked scalars, per the real psychological
10
+ * distinction (Tangney, J. P., & Dearing, R. L. (2002), "Shame and Guilt",
11
+ * Guilford Press): shame is global and self-directed ("I am bad" — an attack
12
+ * on identity), guilt is specific and behavior-directed ("I did a bad thing"
13
+ * — an attack on an action). They have different real downstream effects in
14
+ * that literature: shame correlates with withdrawal/defensiveness and is
15
+ * MORE persistent; guilt correlates with reparative action and resolves
16
+ * faster once the act is addressed. Modeled here as two independent
17
+ * accumulators with different decay rates (shame slower, matching that
18
+ * "more toxic/persistent" finding), not as two labels on the same number.
19
+ */
20
+ export class ShameGuiltSplit {
21
+
22
+ constructor( { shameDecay = 0.015, guiltDecay = 0.035 } = {} ) {
23
+
24
+ this.shameDecay = shameDecay
25
+ this.guiltDecay = guiltDecay
26
+ this.shame = 0
27
+ this.guilt = 0
28
+
29
+ }
30
+
31
+ /**
32
+ * `egoDamage` — real magnitude already computed by ReputationEngine.evaluate()
33
+ * (identity-level: "I failed", raises shame, scaled by agreeableness per the
34
+ * existing shame/wounded_pride split). `selfCritiqueScore` — real magnitude
35
+ * from GuiltEngine's own trigger condition (behavior-level: "that output was
36
+ * harsh"), raises guilt directly, independent of agreeableness.
37
+ */
38
+ register( { egoDamage = 0, selfCritiqueScore = 0, agreeableness = 0.5 } ) {
39
+
40
+ this.shame = clamp01( this.shame + egoDamage * agreeableness * 0.8 )
41
+ this.guilt = clamp01( this.guilt + selfCritiqueScore * 0.6 )
42
+
43
+ }
44
+
45
+ decay( dt = 1 ) {
46
+
47
+ this.shame = Math.max( 0, this.shame - this.shameDecay * dt )
48
+ this.guilt = Math.max( 0, this.guilt - this.guiltDecay * dt )
49
+
50
+ }
51
+
52
+ /** Shame biases toward withdrawal/defensiveness and lower self-disclosure — a real output-facing signal, not just an internal number. */
53
+ getDisclosureWillingness() {
54
+
55
+ return clamp01( 1 - this.shame * 0.8 )
56
+
57
+ }
58
+
59
+ /** Guilt biases toward reparative action — feeds RepairProtocol/GuiltEngine's apology tendency. */
60
+ getRepairDrive() {
61
+
62
+ return this.guilt
63
+
64
+ }
65
+
66
+ /** Which of the two currently dominates — used to pick the real behaviorDirective (withdraw-and-hide vs. apologize-and-fix). */
67
+ getDominant( threshold = 0.3 ) {
68
+
69
+ if ( this.shame < threshold && this.guilt < threshold ) return 'none'
70
+ return this.shame >= this.guilt ? 'shame' : 'guilt'
71
+
72
+ }
73
+
74
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Social Baseline Theory: the presence of a secure, trusted bond genuinely
3
+ * lowers the real metabolic/regulatory cost of facing a given load — humans
4
+ * (and, here, this system) run "leaner" when securely attached, and pay a
5
+ * real extra chronic cost when they aren't (Coan, J. A., & Sbarra, D. A.
6
+ * (2015), "Social Baseline Theory: The social regulation of risk and
7
+ * effort", Current Opinion in Psychology, 1, 87-91). Modeled as a real
8
+ * multiplier on CortisolEngine's decay rate — reused directly (own tuning of
9
+ * the specific coefficient, the direction is the real finding): the ABSENCE
10
+ * of a trusted bond makes chronic stress decay slower (it lingers, because
11
+ * there's no secure-base effect helping regulate it back down), not that it
12
+ * accumulates faster on its own.
13
+ */
14
+ function clamp01( v ) {
15
+
16
+ return Math.max( 0, Math.min( 1, v ) )
17
+
18
+ }
19
+
20
+ export class SocialBaselineTheory {
21
+
22
+ /**
23
+ * `trust` (0..1, Attachment.get(userId).trust for whichever relation is
24
+ * most present this session — caller picks). No secure bond present at
25
+ * all (trust near 0 / no relation) is the real "unregulated" condition
26
+ * this theory is about.
27
+ */
28
+ getCortisolDecayMultiplier( trust = 0 ) {
29
+
30
+ // trust = 1 -> decay proceeds at its normal rate (multiplier 1).
31
+ // trust = 0 -> decay is genuinely slowed (own tuning: down to 0.6x),
32
+ // modeling the real absence of co-regulation, not a punitive penalty.
33
+ return 0.6 + clamp01( trust ) * 0.4
34
+
35
+ }
36
+
37
+ }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.2'
1
+ export const VERSION = '0.1.3'