feat(profiler/behave_shell): emit environmental.numpad_usage

Sliding-window scan over single-char digit input events. A run of
NUMPAD_RUN_MIN (4) consecutive digit events whose pairwise IATs are
all ≤ NUMPAD_FAST_IAT_S (50ms) → detected. Otherwise → not_detected.
Skips below NUMPAD_MIN_TYPED_CHARS (50) typed chars. Confidence cap
0.50 per the registry's weak-signal flag.
This commit is contained in:
2026-05-04 00:40:42 -04:00
parent cd7c7ea5a2
commit c8166a6071
4 changed files with 121 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ from decnet.profiler.behave_shell._features.cognitive import (
from decnet.profiler.behave_shell._features.environmental import (
keyboard_layout,
locale,
numpad_usage,
shell_type,
terminal_multiplexer,
)
@@ -77,4 +78,5 @@ FEATURES: tuple[FeatureFn, ...] = (
terminal_multiplexer,
locale,
keyboard_layout,
numpad_usage,
)

View File

@@ -9,6 +9,7 @@ Step F.1: ``environmental.shell_type``.
Step F.2: ``environmental.terminal_multiplexer``.
Step F.3: ``environmental.locale``.
Step F.4: ``environmental.keyboard_layout``.
Step F.5: ``environmental.numpad_usage``.
"""
from __future__ import annotations
@@ -30,6 +31,10 @@ from decnet.profiler.behave_shell._thresholds import (
LAYOUT_QWERTZ_Z_MIN,
LAYOUT_TOP_ENG_BIGRAMS,
LOCALE_MIN_VALUE_LENGTH,
NUMPAD_FAST_IAT_S,
NUMPAD_MIN_TYPED_CHARS,
NUMPAD_RUN_MIN,
PASTE_MIN_CHARS_PER_EVENT,
SHELL_TYPE_MIN_PROMPTS,
)
@@ -297,3 +302,51 @@ def keyboard_layout(ctx: SessionContext) -> Iterator[Observation]:
value=value,
confidence=confidence,
)
def numpad_usage(ctx: SessionContext) -> Iterator[Observation]:
"""Emit ``environmental.numpad_usage`` ∈ {detected, not_detected}.
A digit run is ``NUMPAD_RUN_MIN`` (4) consecutive single-character
digit input events whose pairwise IATs are all
≤ ``NUMPAD_FAST_IAT_S`` (50ms). Numpad muscle memory produces
faster digit cadence than touch-typing the top row.
Skip emission below ``NUMPAD_MIN_TYPED_CHARS`` (50) typed chars —
no honest signal in a tiny session. Confidence cap 0.50 (registry
flags as weak signal).
"""
if not ctx.commands:
return
digit_events: list[float] = []
typed_count = 0
for t, _kind, data in ctx.input_events:
if len(data) >= PASTE_MIN_CHARS_PER_EVENT:
continue
typed_count += len(data)
if len(data) == 1 and data.isdigit():
digit_events.append(t)
if typed_count < NUMPAD_MIN_TYPED_CHARS:
return
detected = False
if len(digit_events) >= NUMPAD_RUN_MIN:
# Sliding window: any contiguous run of NUMPAD_RUN_MIN digit
# events whose internal IATs are ALL fast → numpad.
for i in range(len(digit_events) - NUMPAD_RUN_MIN + 1):
window_iats = [
digit_events[i + j + 1] - digit_events[i + j]
for j in range(NUMPAD_RUN_MIN - 1)
]
if all(x <= NUMPAD_FAST_IAT_S for x in window_iats):
detected = True
break
yield make_observation(
ctx,
primitive="environmental.numpad_usage",
value="detected" if detected else "not_detected",
confidence=0.50,
)

View File

@@ -263,6 +263,15 @@ LAYOUT_QWERTZ_Z_MIN: float = 0.030 # high `z` rate (German content / QWERTZ
LAYOUT_QWERTZ_Y_MAX: float = 0.010 # AND `y` swap signature
LAYOUT_QWERTY_ENG_MIN: float = 0.080 # English-bigram saturation floor
# ── environmental.numpad_usage (Step F.5) ──────────────────────────────────
# A digit run = NUMPAD_RUN_MIN consecutive single-char digit events
# whose pairwise IATs are all ≤ NUMPAD_FAST_IAT_S. Numpad muscle memory
# produces faster digit IATs than touch-typing on the top row.
NUMPAD_FAST_IAT_S: float = 0.050
NUMPAD_RUN_MIN: int = 4
# Below this many typed chars total, skip emission (no honest signal).
NUMPAD_MIN_TYPED_CHARS: int = 50
# ── motor.keystroke_cadence (Step B.1) ──────────────────────────────────────
# Typing bursts split at gaps > IKI_THINK_MAX_S so think-pauses between
# commands don't inflate the within-burst CV. Mirrors the prototype's