BEHAVE-EXTRACTOR.md Phase A Step 2. The first primitive — picked
first because it has the highest discriminative value (HUMAN vs
everyone) and the simplest implementation (paste-event ratio over
total inputs).
* _features/motor.py:input_modality(ctx) emits one Observation
per session in {typed, pasted, mixed} with confidence 0.75 / 0.70.
* _features/_emit.py centralises the make_observation helper so
every feature module gets the same Window/source/evidence_ref
boilerplate without copy-paste.
* Thresholds inherited from the prototype's calibration history
(MODALITY_PASTED_MIN=0.40, MODALITY_TYPED_MAX=0.05).
* Zero-input session skips emission — registry doesn't admit
"unknown" here.
Tests: pure-typed → typed, pure-pasted → pasted, mixed → mixed,
output-only session → no observation, full envelope round-trip.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""``motor.*`` feature functions.
|
|
|
|
Step 2: ``motor.input_modality`` — typed / pasted / mixed.
|
|
Step 3: ``motor.paste_burst_rate`` — none / occasional / habitual.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Iterator
|
|
|
|
from decnet_behave_core.spec.envelope import Observation
|
|
|
|
from decnet.profiler.behave_shell._ctx import SessionContext
|
|
from decnet.profiler.behave_shell._features._emit import make_observation
|
|
from decnet.profiler.behave_shell._thresholds import (
|
|
MODALITY_PASTED_MIN,
|
|
MODALITY_TYPED_MAX,
|
|
)
|
|
|
|
|
|
def input_modality(ctx: SessionContext) -> Iterator[Observation]:
|
|
"""Emit ``motor.input_modality`` ∈ {typed, pasted, mixed}.
|
|
|
|
Ratio of paste-class events to total inputs. Empty input → skip
|
|
emission entirely (the registry doesn't admit ``unknown`` here
|
|
and fabricating ``typed`` for a zero-input session is dishonest).
|
|
"""
|
|
n = len(ctx.input_events)
|
|
if n == 0:
|
|
return
|
|
ratio = ctx.paste_event_count / n
|
|
if ratio >= MODALITY_PASTED_MIN:
|
|
modality = "pasted"
|
|
confidence = 0.75
|
|
elif ratio <= MODALITY_TYPED_MAX:
|
|
modality = "typed"
|
|
confidence = 0.75
|
|
else:
|
|
modality = "mixed"
|
|
confidence = 0.70
|
|
yield make_observation(
|
|
ctx,
|
|
primitive="motor.input_modality",
|
|
value=modality,
|
|
confidence=confidence,
|
|
)
|