How ahmadhassan-bted/b works
Purpose and Entry Point
B is a Python/PyQt6 desktop companion that observes desktop context, accepts typed or spoken input, runs LLM reasoning, and renders speech, text, emotion, and movement in a transparent overlay. Startup is main.py, which composes modules, registers global hotkeys, and drives the 60 FPS application tick.
Event-Driven Core
core/bus.py is the architectural boundary between subsystems: modules publish and subscribe through a thread-safe Qt signal-based EventBus rather than calling one another directly. main.py owns process lifecycle and bus wiring. Core control flow is perception/input → bus → cognition/state → bus → visual/audio/motion outputs.
Perception and Context Acquisition
Active application changes originate from sensors/window_tracker.py. vision/semantic.py extracts structured UI context via UI Automation and quality/cooldown logic. When semantic extraction is unavailable, vision/mss_capture.py captures the screen and uses OCR as a fallback. These stages emit context events rather than exposing platform-specific APIs to the brain.
User Input and Work Modes
ui/input_box.py provides typed interaction; audio/ears.py provides microphone transcription using Faster-Whisper with voice activity detection. brain/work_mode.py defines the focused/proactive work-mode behavior activated by global hotkey. Input is normalized into bus events consumed by cognition, keeping UI and audio capture independent from reasoning.
Cognition, State, and Autonomy
brain/llm.py is the CognitiveEngine: it combines context/history, invokes either Groq cloud inference or local llama-cpp, and parses streamed output. brain/context.py manages contextual state, while brain/soul.py owns emotional/conversation state and sentence-ready stream buffering. brain/autonomy_loop.py schedules unsolicited thoughts only when timing and context quality permit. Cognition publishes speech, expression, and movement requests; it does not directly render or play them.
Expression and Overlay Runtime
ui/overlay.py hosts the transparent, click-through desktop presentation. ui/face.py renders the animated face, ui/chat.py displays spoken text, and physics/kinematics.py translates movement requests into eased/Bezier motion. These are Qt-driven, 60 FPS output consumers coordinated through events and state transitions.
Audio and External Dependencies
audio/speaker.py turns generated sentences into Piper ONNX speech and applies Pedalboard DSP effects; packaged voice assets are voices/b_voice.onnx and voices/b_voice.onnx.json. External services/runtime boundaries include Groq API credentials from .env, optional local GGUF/llama-cpp inference, Windows UI Automation/Win32 hooks, Tesseract OCR, MSS screen capture, Faster-Whisper, and PyQt6. Primary target is Windows 10/11, with experimental Linux/macOS support.
Main entry points: bus.py Event bus · llm.py Cognitive engine · overlay.py Transparent overlay · semantic.py Semantic UI extraction
Components 19
Application Runtime
- Application entry · Composes modules, registers hotkeys, and drives the 60 FPS tick.
main.py - Event bus · Thread-safe boundary between subsystems.
core/bus.py
Perception & Input
- Window tracker
sensors/window_tracker.py - Semantic UI extraction
vision/semantic.py - OCR fallback capture
vision/mss_capture.py - Typed input
ui/input_box.py - Voice transcription · Faster-Whisper transcription with voice activity detection.
audio/ears.py
Cognition & State
- Work mode · Focused and proactive behavior activated by global hotkey.
brain/work_mode.py - Context state
brain/context.py - Emotion & conversation state · Buffers sentence-ready streamed output.
brain/soul.py - Cognitive engine · Combines context and history, streams inference, and emits output requests.
brain/llm.py - Autonomy loop · Schedules unsolicited thoughts when timing and context quality allow.
brain/autonomy_loop.py - LLM providers · Cloud Groq inference or optional local GGUF runtime.
Overlay Outputs
- Transparent overlay · Click-through desktop overlay runtime.
ui/overlay.py - Animated face
ui/face.py - Speech text display
ui/chat.py - Motion engine · Applies eased and Bezier motion.
physics/kinematics.py - Speech synthesis · Piper ONNX voice synthesis with Pedalboard DSP.
audio/speaker.py - Packaged voice assets
voices/b_voice.onnx
Connections 23
- Application entry → Event bus: wires lifecycle
- Application entry → Transparent overlay: drives 60 FPS tick
- Window tracker → Semantic UI extraction: active app changes
- Semantic UI extraction → OCR fallback capture: fallback when unavailable
- Semantic UI extraction → Event bus: structured context
- OCR fallback capture → Event bus: OCR context
- Typed input → Event bus: typed input
- Voice transcription → Event bus: transcribed input
- Event bus → Work mode: hotkey and input events
- Event bus → Context state: context events
- Event bus → Cognitive engine: normalized input
- Context state → Cognitive engine: current context
- Emotion & conversation state → Cognitive engine: conversation and emotion
- Autonomy loop → Cognitive engine: proactive prompts
- Cognitive engine → LLM providers: streaming inference
- Cognitive engine → Event bus: speech, expression, movement
- Event bus → Emotion & conversation state: stream and state events
- Event bus → Transparent overlay: presentation events
- Transparent overlay → Animated face: renders expression
- Transparent overlay → Speech text display: renders spoken text
- Event bus → Motion engine: movement requests
- Event bus → Speech synthesis: sentence-ready speech
- Speech synthesis → Packaged voice assets: loads voice model