feat(profiler/behave_shell): G.8 emotional_valence.frustration_venting

Binary read of ctx.obscenity_hits (G.0 lexical counter):
* detected — obscenity_hits ≥ 1
* none     — zero hits

Skip below FRUST_VENT_MIN_TYPED_CHARS (30). Confidence hard-capped at
0.5: 0.40 when detected, 0.50 only when cleanly absent over ≥ 200
typed letters, 0.30 otherwise.
This commit is contained in:
2026-05-08 16:37:29 -04:00
parent 40a283a7ec
commit 79f253c969
3 changed files with 89 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ from decnet.profiler.behave_shell._features.cognitive import (
)
from decnet.profiler.behave_shell._features.emotional_valence import (
arousal,
frustration_venting,
stress_response,
valence,
)
@@ -99,4 +100,5 @@ FEATURES: tuple[FeatureFn, ...] = (
valence,
arousal,
stress_response,
frustration_venting,
)

View File

@@ -26,6 +26,8 @@ from decnet.profiler.behave_shell._thresholds import (
AROUSAL_FAST_IAT_S,
AROUSAL_MIN_IATS,
EMOTIONAL_VALENCE_CONFIDENCE_CAP,
FRUST_VENT_FULL_CONFIDENCE_MIN,
FRUST_VENT_MIN_TYPED_CHARS,
STRESS_DISTRESS_RATIO_MIN,
STRESS_EUSTRESS_RATIO_MIN,
STRESS_MIN_ERRORED_WITH_IATS,
@@ -186,3 +188,36 @@ def stress_response(ctx: SessionContext) -> Iterator[Observation]:
value=value,
confidence=_cap_soft(raw),
)
def frustration_venting(ctx: SessionContext) -> Iterator[Observation]:
"""Emit ``emotional_valence.frustration_venting`` ∈ {none, detected}.
Pure read of ``ctx.obscenity_hits`` (G.0 lexical counter):
* ``detected`` — ``obscenity_hits ≥ 1``.
* ``none`` — zero hits.
Skip emission below ``FRUST_VENT_MIN_TYPED_CHARS`` (30) typed
letters — too thin to call cleanly absent. Confidence hard-capped
at 0.50; 0.40 when ``detected``; 0.50 only when ``none`` AND
typed_letter_count ≥ ``FRUST_VENT_FULL_CONFIDENCE_MIN`` (200);
0.30 otherwise.
"""
if ctx.typed_letter_count < FRUST_VENT_MIN_TYPED_CHARS:
return
if ctx.obscenity_hits >= 1:
value = "detected"
raw = 0.40
else:
value = "none"
if ctx.typed_letter_count >= FRUST_VENT_FULL_CONFIDENCE_MIN:
raw = 0.50
else:
raw = 0.30
yield make_observation(
ctx,
primitive="emotional_valence.frustration_venting",
value=value,
confidence=_cap_soft(raw),
)

View File

@@ -0,0 +1,52 @@
"""Step G.8: ``emotional_valence.frustration_venting`` ∈ {none, detected}.
Hard 0.5 confidence cap.
"""
from __future__ import annotations
from decnet.profiler.behave_shell import extract_session
from decnet.profiler.behave_shell._parse import AsciinemaEvent
PRIMITIVE = "emotional_valence.frustration_venting"
def _of(observations: list, primitive: str):
obs = [o for o in observations if o.primitive == primitive]
assert len(obs) == 1, f"expected exactly one {primitive}, got {len(obs)}"
return obs[0]
def _typed(text: str, t0: float = 0.0, dt: float = 0.05) -> list[AsciinemaEvent]:
return [(t0 + i * dt, "i", c) for i, c in enumerate(text)]
def test_too_little_text_no_emission() -> None:
out = list(extract_session(_typed("hi"), sid="g8-thin"))
assert [o for o in out if o.primitive == PRIMITIVE] == []
def test_detected_when_obscenity_present() -> None:
text = "hostname date hostname date oh fuck this is broken really "
obs = _of(list(extract_session(_typed(text), sid="g8-yes")), PRIMITIVE)
assert obs.value == "detected"
assert obs.confidence == 0.40
def test_none_when_clean() -> None:
text = "hostname date hostname date hostname date hostname date "
obs = _of(list(extract_session(_typed(text), sid="g8-no")), PRIMITIVE)
assert obs.value == "none"
def test_high_confidence_when_long_clean() -> None:
text = "hostname date " * 30
obs = _of(list(extract_session(_typed(text), sid="g8-long")), PRIMITIVE)
assert obs.value == "none"
assert obs.confidence == 0.50
def test_cap_never_exceeded() -> None:
text = "fuck shit damn " * 30
obs = _of(list(extract_session(_typed(text), sid="g8-cap")), PRIMITIVE)
assert obs.confidence <= 0.50