From 79f253c969bbe07d76001742e2fbc7cbd7319282 Mon Sep 17 00:00:00 2001 From: anti Date: Fri, 8 May 2026 16:37:29 -0400 Subject: [PATCH] feat(profiler/behave_shell): G.8 emotional_valence.frustration_venting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../behave_shell/_features/__init__.py | 2 + .../_features/emotional_valence.py | 35 +++++++++++++ ...t_emotional_valence_frustration_venting.py | 52 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tests/profiler/behave_shell/test_emotional_valence_frustration_venting.py diff --git a/decnet/profiler/behave_shell/_features/__init__.py b/decnet/profiler/behave_shell/_features/__init__.py index 1f9d8e24..b0231ef2 100644 --- a/decnet/profiler/behave_shell/_features/__init__.py +++ b/decnet/profiler/behave_shell/_features/__init__.py @@ -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, ) diff --git a/decnet/profiler/behave_shell/_features/emotional_valence.py b/decnet/profiler/behave_shell/_features/emotional_valence.py index 10fe8c9f..c2c715fc 100644 --- a/decnet/profiler/behave_shell/_features/emotional_valence.py +++ b/decnet/profiler/behave_shell/_features/emotional_valence.py @@ -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), + ) diff --git a/tests/profiler/behave_shell/test_emotional_valence_frustration_venting.py b/tests/profiler/behave_shell/test_emotional_valence_frustration_venting.py new file mode 100644 index 00000000..b72ddb8c --- /dev/null +++ b/tests/profiler/behave_shell/test_emotional_valence_frustration_venting.py @@ -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