fix: wire Pip familiar into Workshop state pipeline
All checks were successful
Tests / lint (pull_request) Successful in 5s
Tests / test (pull_request) Successful in 58s

Pip's backend behavioral AI (state machine, mood mirroring, event
reactions) was never connected to the world state API. The frontend
Pip wandered randomly with no connection to the backend.

- Add _pip_snapshot() to workshop_state.py — ticks Pip and feeds
  Timmy's mood/confidence into Pip's behavioral AI each heartbeat
- Include familiar snapshot in presence state dict (get_state_dict)
- Include familiar in _build_world_state() API response
- Trigger pip_familiar.on_event("visitor_spoke") when visitors chat

Fixes #222

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kimi
2026-03-19 03:04:17 -04:00
parent 4b617cfcd0
commit 59c182cdfa
2 changed files with 23 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ def _build_world_state(presence: dict) -> dict:
"energy": presence.get("energy", 0.5),
"confidence": presence.get("confidence", 0.7),
},
"familiar": presence.get("familiar"),
"activeThreads": presence.get("active_threads", []),
"recentEvents": presence.get("recent_events", []),
"concerns": presence.get("concerns", []),
@@ -232,6 +233,14 @@ async def _bark_and_broadcast(visitor_text: str) -> None:
"""Generate a bark response and broadcast it to all Workshop clients."""
await _broadcast(json.dumps({"type": "timmy_thinking"}))
# Notify Pip that a visitor spoke
try:
from timmy.familiar import pip_familiar
pip_familiar.on_event("visitor_spoke")
except Exception:
pass # Pip is optional
_refresh_ground(visitor_text)
reply = await _generate_bark(visitor_text)

View File

@@ -73,6 +73,19 @@ def _current_energy() -> float:
return max(_ENERGY_MIN, min(1.0, decayed))
def _pip_snapshot(mood: str, confidence: float) -> dict:
"""Tick Pip and return his current snapshot dict.
Feeds Timmy's mood and confidence into Pip's behavioral AI so the
familiar reacts to Timmy's cognitive state.
"""
from timmy.familiar import pip_familiar
pip_familiar.on_mood_change(mood, confidence=confidence)
pip_familiar.tick()
return pip_familiar.snapshot().to_dict()
def get_state_dict() -> dict:
"""Build presence state dict from current cognitive state.
@@ -135,6 +148,7 @@ def get_state_dict() -> dict:
"local_time": local_now.strftime("%-I:%M %p"),
"day_of_week": local_now.strftime("%A"),
},
"familiar": _pip_snapshot(mood, confidence),
"meta": {
"schema_version": 1,
"updated_at": now.strftime("%Y-%m-%dT%H:%M:%SZ"),