AUDIO
Listen to this page
Chapters
Architecture
AI Agent & Tools pattern
The system core acts as an Agent; plugins serve as Tools the AI can invoke dynamically. Each plugin registers itself with a precise JSON description of its capabilities; the agent matches the request against the tools available to the current user and executes the chosen one.
Voice walk-through (the full pipeline):
- Client records audio in
.wav(16 kHz PCM) and posts it to the core. - STT — the core forwards the audio to a faster-whisper container, receives the transcribed text.
- Agent — the text is passed to the AI model (mock matcher, local or cloud LLM — see agent-and-language), which matches the request against available tools.
- Tool execution — the core calls the plugin's
execute(); the result is a{success, message?, data?, error?}object whosemessageis what the user hears. - TTS & response — piper synthesizes the answer; the client gets JSON + the response audio.
graph TD
Client[Flutter Client] -->|1. POST .wav| Core[holai Core Node.js]
Core -->|2. Transcribe| Whisper[Faster-Whisper]
Core -->|3. Agent| Agent[AI Agent Layer]
Agent -->|4. Tool| Plugins[Plugins Engine]
Plugins -->|execute| Tool[Specific Plugin]
Core -->|5. Synthesize| Piper[Piper TTS]
Core -->|6. JSON + .wav| Client
State, plugins and storage details continue below; the REST surface is in api, the admin UI in dashboard.
State lives in the database
Users, settings, env variables, the plugin on/off selection, the plugin lock
and the AUDIT LOG live in the SQLite database (holai.db) — table store
(one row per logical store, JSON value: users / settings / env /
plugin-state / plugins-lock) and table audit (extracted filter columns +
full event JSON, real SQL filtering). The store-interface classes
(SqlStore) are drop-in compatible with old JSON-file stores, so routes and
services are untouched.
holai.dbis the ONLY persistent state layer — no JSON fallback and no migration from legacy files: a missing store row is simply filled with the store's defaults at boot. The file lives in the data dir (data/holai.db,DB_PATHoverrides); a legacy root copy is moved on the next start.- Message/conversation history is INTENTIONALLY not persisted this way (voice answers are ephemeral audio); chat log retention belongs to the media store.
- Backup of the whole instance is the backup plugin
(plugins/backup): it ships a scheduled zip of the
db snapshot alone (format 2 — every plugin's state is inside the db as
ctx.sqlStorerows) to Google Drive (default)/FTP/S3 and restores it onto a fresh instance. Manually: copyholai.db(+ media dirs). Legacy format-1 zips that bundleddata/plugin-data/**still restore — the plugins re-import their JSON files into the db on first read. Deleting the db file effectively resets the household (users/settings/env/plugin selection return to defaults: default admin/admin, mock provider, no env keys).
Permissions & roles
Access control is split into two layers: who is asking (user roles) and what a plugin is allowed to do (permission scopes). Both are enforced by the core before any tool is executed.
User roles
| Role | Who | Capabilities |
|---|---|---|
admin |
Owner | Everything: plugin install/update/remove, env config, AI provider switching, user management |
user |
Family member | Invoke all plugins marked minRole: user, view device states |
guest |
Temporary | Only plugins with minRole: guest (lights, music); no history access, no sensitive tools |
kid |
Children | Whitelisted tools + time-based restrictions (quiet hours). The role gate only passes tools declared at kid level — the lowest tier, so guests and users pass too (lights, music, time/alarms); the per-user whitelist narrows further — locks, cameras, backups etc. stay unreachable |
Role resolution:
- Clients authenticate with a JWT (issued at login); the role is embedded in the token.
- For voice, an optional speaker-recognition step (voice embedding) maps the
audio to a household profile; with low confidence the request falls back
to the least-privileged role (
guest).
Permission scopes
Plugins declare what they need in manifest.json. The Agent only sees tools
the current user is allowed to call, and tool execution re-checks scopes at
execution time (defense in depth):
{
"name": "manage_light",
"permissions": {
"scopes": ["devices:lights:write"],
"minRole": "user"
}
}
Scope convention: <domain>:<resource>:<action> — e.g.
devices:lights:write, media:music:play, system:exec,
data:history:read, network:external (any outbound HTTP call from a
plugin).
Internal (core) operations use the same convention:
plugins:install / plugins:update / plugins:remove, env:write (values
are always masked in responses), settings:ai-provider.
Enforcement flow
voice/HTTP request → auth token / speaker ID → role
→ tool list filtered by role (the LLM only sees allowed tools)
→ agent picks tool → callTool()
→ permission check: role ≥ minRole AND scopes ⊆ user's granted scopes
→ execute → audit log (who, which tool, args, result, timestamp)
Every execution is written to the audit log, visible in the Admin Dashboard — so it is always possible to answer "which command turned off the lights at 3 AM".
Configuring rights & permissions (how-to)
All of it lives in the dashboard; nothing needs a config file.
| What | Where | Controls |
|---|---|---|
| Accounts & roles | Users | create users, pick the role (admin/user/guest/kid), set passwords |
| Per-user tool whitelist | Users → "allowed tools" | multiselect over the currently installed tools (toggle chips, saved as a comma-separated list, tuya, media_library); empty = everything the role allows. Filtered tools vanish from the LLM's tool list AND are refused at execution |
| AI permission modes | AI permissions | per user: always allow / ask each time / deny for external providers, tool control actions, single devices, single scenarios (see "AI permissions & consent" below); the "Always" button in the consent dialog writes the same store |
| Kids' quiet hours | Users → quiet hours toggle + start/end | during the window every tool call from the kid is refused (403, before any tool runs) |
| Plugin scopes | Marketplace at install | the plugin's declared scopes are shown and approved once per install/update; not per-user |
| Speaker identity | speaker's config.yaml (core.username/password) |
each speaker logs in AS a household user — a kid's room speaker logs in with the kid's account, so role, whitelist, quiet hours and consent all apply to it |
A practical kids setup:
- Create the child's account with role
kid(the kid's own login works on a phone/tablet app of their own). - Whitelist the tools the child may use — e.g.
tuyafor their room's lamp andmedia_libraryfor music. Note the two-layer restriction: akidfirst has to pass each tool'sminRole(only lights, music and time/alarms declare the lowestkidtier — which guests and users pass as well; locks, cameras, backups, scenarios, web actions stay unreachable for kids no matter what the whitelist says), and the whitelist then narrows what remains. - Turn on quiet hours (e.g. 21 → 7): at night the AI answers nothing but general questions — any tool call is refused with a clear message.
- Give the child a own speaker: point its
config.yamlat the core with the child's username/password. Voice requests from that speaker then run under the kid's role — the whitelist, quiet hours and the AI permission modes apply exactly as on their phone. A general-knowledge question still works at night (no tool, no provider needed when the local model answers), actuating the house does not. - Consent for the kid: an
ask-mode request raised by the kid is answered either by the kid's own app dialog or by any admin (the parent) — the parent's app lists pending requests of the whole home and can approve or deny them remotely. "Always allow" is thereby effectively a parental decision.
Everything the child does lands in the same audit log (user, tool, args, result) — including which external provider answered, when consent was asked, and who granted it.
Where changed code goes
Source layout highlights (the core is server/src/):
| Area | Files |
|---|---|
| HTTP entry + plugin UI serving | server/src/index.js |
| Plugin loading, route mounting, tool filtering | server/src/core/PluginManager.js |
| Staged plugin updates, npm marketplace | server/src/core/PluginUpdater.js |
| SQLite state + audit | server/src/core/sqlStore.js, server/src/core/audit.js |
| Voice pipeline routes | server/src/routes/voice.js, server/src/routes/chat.js |
| Agent + LLM providers | server/src/services/agent.js |
| Remote access tunnel | server/src/services/hubSession.js, hub/server.js |
| Machine auth for plugin→core calls | server/src/core/auth.js (JWT_SECRET) |
AI confinement & code integrity
A prompt-injected (or simply buggy) external AI must never be able to patch the holai code or reach the OS. The defense is layered:
- The agent surface is a closed tool list. The model can only emit
{tool, args}against manifests it was given, andcallToolre-validates every call: unknown parameters are rejected,enumfields (e.g. the light plugin'saction: on|off, the backup tool'saction: status|run) allow-list the values, string/number types are enforced (PluginManager.validateArgs). Free-form shell strings, file paths or code snippets are not part of any tool schema — there is no "run command" tool. Role, scopes and (for kids) quiet hours are re-checked at execution, not just in the tool list. - Destructive primitives are never agent tools. Code-level writes
(marketplace install, plugin restore, migrations) and process spawning
(esphome compile, backup CLI) live behind admin-scoped dashboard routes
only; the agent-facing backup tool can only
status/run. Plugin packages come from the marketplace the admin chose — an admin install is an explicit trust decision. - OS level (the Docker deployment). The core container runs with a
read-only root filesystem (
read_only: true,/tmpon a tmpfs):server/src,node_modulesanddashboard/distare physically unwritable at runtime — even a fully compromised process cannot modify the code; only the plugin bind mount, the data volume and/tmpare writable, and code capabilities are dropped (cap_drop: [ALL],no-new-privileges). A tampered plugin file is the only persistent code path left — review the plugins folder the same way you review the marketplace. - Bare metal. Run
npm startunder a dedicated non-admin OS user and deny that user write access (NTFS ACL / chmod) toserver/src,server/dashboardandnode_modules. The Node process then cannot patch its own code even if some layer is subverted.
Integrity is observable: every tool call, plugin install/restore and permission change lands in the audit log with the acting user.
AI permissions & consent
Separate from the code-integrity layer above: WHAT the AI may use on its own, per user. Three modes per subject — allow (runs freely), ask (every use waits for a confirmation: a dialog in the app, a spoken yes-no on the speaker; the default) and deny (the AI must not touch it). Subjects:
| kind | what |
|---|---|
provider |
an external AI service (openrouter, openai, anthropic) — queries must not leave the home without consent; local ollama/llamacpp never ask |
tool |
an agent tool's control actions (media play, vault write, scenario run …) — read-only actions never ask |
device |
one controllable device (tuya control per resolved device, manage_light rooms) |
scenario |
one user-defined scenario (an AI-triggered run) |
Mechanics: the gate (src/core/consent.js) checks the mode; on ask it
publishes a consent.request event and pauses the pipeline until the user
answers (POST /consent/respond, ~45 s timeout → denial). The Flutter
client shows the dialog (Allow once / Always / Deny); the speaker bridge
speaks the question and parses the spoken yes-no. "Always" upgrades the
subject's mode. Mode changes are admin-managed in the dashboard (AI
permissions page) and audited.
User-authored logic never asks: scenario auto-fires (event, condition,
schedule) and chained scenario steps run without the gate — the scenario
editor is the user's explicit will. Mechanically, the core marks every
plugin pseudouser call with ctx.aiCall = false (PluginManager) and the
gating plugins (tuya, manage_light, scenarios) skip ctx.confirm when it
is false — a chat/tool call from a real user still asks. So an external
AI cannot actuate a device directly without consent, and repeated consent
can be revoked by switching the mode to deny in the dashboard.
Last updated: November 2026