How mach4-braai/hum works
Purpose and executables
Hum is a local-first ambient-audio system for work-session lifecycle events. hum is the user/client CLI; humd is the long-running daemon that owns session state and audio output. Clients are tool-agnostic and communicate with the daemon through a local Unix-socket JSON protocol.
• cmd/hum/main.go
• cmd/humd/main.go
• cmd/humd/daemon.go
CLI client and process control
The hum command parses lifecycle, status, audio-control, theme, setup, diagnostics, and version commands; it connects to the daemon, sends protocol requests, and renders human or JSON output. It also includes daemon-management behavior such as starting/stopping and supervisor integration rather than embedding audio in the CLI.
• cmd/hum/client.go
• cmd/hum/start.go
• cmd/hum/supervisor.go
Daemon orchestration and ownership
humd wires configuration, socket transport, session registry, harmony allocation, theme loading, renderer/audio lifecycle, logging, and shutdown. This is the authoritative process for mutable session and output state; clients issue requests rather than directly manipulating audio.
• cmd/humd/daemon.go
• cmd/humd/logging.go
• cmd/humd/main.go
Local transport and wire boundary
The transport layer hosts the daemon endpoint and handles platform-specific socket behavior; the protocol package defines framing, requests, payloads, responses, and codec validation. This boundary permits any integration that can write line-delimited JSON, while keeping the daemon local. POSIX runtime directories/sockets are permission-restricted; Windows support is best-effort with differing socket security and signal behavior.
• internal/transport/transport.go
• internal/transport/unix.go
• internal/protocol/protocol.go
• internal/protocol/codec.go
Session lifecycle and harmony decisions
A registry manages live sessions and their lifecycle transitions: start creates sustained voices; completion/failure trigger distinct musical phrases before removal; cancellation stops without cadence; updates carry progress/metadata. The harmony engine allocates pitches from configured key/scale so simultaneous active sessions form chords.
• internal/session/registry.go
• internal/session/session.go
• internal/harmony/engine.go
• internal/harmony/allocator.go
Rendering and audio pipeline
Daemon events become renderer operations, with a renderer abstraction allowing implementations such as no-op output. The audio implementation synthesizes oscillators and phrases, mixes concurrent voices, and applies format/output behavior. Themes define the soundscape parameters used by this chain and can be swapped at runtime.
• internal/renderer/renderer.go
• internal/audio/renderer.go
• internal/audio/mixer.go
• internal/theme/theme.go
Configuration, deployment, and platform runtime
Configuration is loaded/resolved from configured locations and persisted for initialization/theme selection. Runtime paths centralize home, logs, runtime directory, and socket placement. Primary supported audio environments are macOS (AudioToolbox via pure Go) and Linux (ALSA, requiring headers/C toolchain); user-level service deployment is supplied for systemd and Homebrew packages provide macOS service operation.
• internal/config/load.go
• internal/config/resolve.go
• internal/paths/paths.go
• contrib/systemd/humd.service
Main entry points: daemon.go Daemon orchestrator · registry.go Session registry · transport.go Local socket endpoint · client.go CLI protocol client
Components 16
Client control
- hum CLI · Tool-agnostic client for lifecycle and control commands.
cmd/hum/main.go - CLI protocol client · Sends daemon requests and renders human or JSON responses.
cmd/hum/client.go - Daemon process control · Starts, stops, and integrates humd with supervisors.
cmd/hum/supervisor.go
Daemon core
- humd daemon · Authoritative owner of mutable sessions and audio output.
cmd/humd/main.go - Daemon orchestrator · Wires transport, state, themes, rendering, and shutdown.
cmd/humd/daemon.go - Local socket endpoint · Hosts the local daemon endpoint with platform-specific behavior.
internal/transport/transport.go - JSON wire protocol · Defines line-delimited JSON requests, responses, framing, and validation.
internal/protocol/protocol.go - Session registry · Tracks live sessions and completion, failure, cancellation, and update transitions.
internal/session/registry.go - Harmony allocator · Selects key/scale pitches so active sessions form chords.
internal/harmony/allocator.go
Audio pipeline
- Renderer abstraction · Converts daemon events into output operations and permits no-op output.
internal/renderer/renderer.go - Audio renderer · Synthesizes sustained voices and lifecycle phrases.
internal/audio/renderer.go - Concurrent voice mixer · Mixes simultaneous oscillator voices for output.
internal/audio/mixer.go - Themes · Defines runtime-swappable soundscape parameters.
internal/theme/theme.go
Runtime & deployment
- Configuration · Loads persisted initialization and theme-selection settings.
internal/config/load.go - Runtime paths · Centralizes home, logs, runtime directory, and socket locations.
internal/paths/paths.go - systemd user service · Supplies Linux user-level humd deployment.
contrib/systemd/humd.service
Connections 20
- hum CLI → CLI protocol client: invokes
- hum CLI → Daemon process control: manages daemon
- CLI protocol client → JSON wire protocol: encodes requests
- CLI protocol client → Local socket endpoint: connects locally
- Daemon process control → humd daemon: starts/stops
- humd daemon → Daemon orchestrator: runs
- Daemon orchestrator → Local socket endpoint: hosts
- Local socket endpoint → JSON wire protocol: decodes/encodes
- JSON wire protocol → Session registry: lifecycle requests
- Daemon orchestrator → Session registry: owns
- Session registry → Harmony allocator: allocates active pitches
- Session registry → Renderer abstraction: emits lifecycle events
- Daemon orchestrator → Themes: loads and swaps
- Themes → Renderer abstraction: sound parameters
- Renderer abstraction → Audio renderer: audio implementation
- Audio renderer → Concurrent voice mixer: produces voices
- Daemon orchestrator → Configuration: loads settings
- Configuration → Runtime paths: resolves locations
- Runtime paths → Local socket endpoint: socket location
- systemd user service → humd daemon: runs as user service