This directory contains comprehensive documentation for the Atrophy Electron application - a companion agent system with voice interaction, persistent memory, and autonomous background processes.
- Auto Telegram Chat ID Management - Agents automatically detect group membership changes
- Org/Agent Management UI - Full CRUD for organizations and agents in Settings
- Session Suspension - Deferrals now suspend (not end) sessions for later resumption
| # | File | Bug | Fix |
|---|---|---|---|
| 1 | switchboard.ts |
TOCTOU race on MCP queue | Atomic rename-then-restore |
| 2 | tts.ts |
Unhandled WriteStream error | Added error listener + reject path |
| 3 | scheduler.ts |
Stale closure in delay | Re-evaluate delay from job.nextRun |
| 4 | scheduler.ts |
Disabled job rescheduled | Added disabled guard |
| 5 | inference.ts |
Dead process ref leak | Clean up _allProcesses |
| 6 | memory.ts + app.ts |
FD accumulation | Added closeForPath() |
scripts/agents/shared/credentials.py- Shared credential loadingdocs/specs/decisions/2026-03-26-auto-telegram-chat-id-management.mddocs/specs/decisions/2026-03-26-bug-scan-and-avatar-investigation.md
docs/codebase/
├── README.md # This file - architecture overview
├── FILE_INDEX.md # Complete file index with status
├── files/ # Detailed file-by-file documentation
│ ├── src/
│ │ ├── main/ # Main process modules
│ │ │ ├── index.md # Entry point
│ │ │ ├── bootstrap.md # Hot bundle loader
│ │ │ ├── app.md # Main process implementation
│ │ │ ├── config.md # Configuration system
│ │ │ ├── memory.md # SQLite data layer
│ │ │ ├── inference.md # Claude CLI streaming
│ │ │ ├── tts.md # Text-to-speech
│ │ │ ├── stt.md # Speech-to-text
│ │ │ └── ... # (50+ module docs)
│ │ │ ├── ipc/ # IPC handlers
│ │ │ ├── channels/ # Channel system
│ │ │ └── jobs/ # Background jobs
│ │ ├── preload/ # Preload scripts
│ │ └── renderer/ # Svelte components & stores
│ ├── db/ # Database schema
│ └── mcp/ # MCP servers
└── archive/ # Legacy overview documents
Atrophy is an Electron/TypeScript companion agent system. It uses the Claude CLI for inference (streaming JSON output via subprocess), maintains persistent memory in SQLite via better-sqlite3, speaks with synthesised voice, and runs autonomous background processes via macOS launchd. The UI is built with Svelte 5 (runes mode).
| Layer | Choice |
|---|---|
| Runtime | Electron 34+ |
| Language | TypeScript 5.x (strict mode) |
| UI Framework | Svelte 5 (runes mode) |
| Build System | Vite + electron-vite |
| Package Manager | pnpm |
| Database | better-sqlite3 (synchronous, WAL mode) |
| Embeddings | @xenova/transformers (WASM, all-MiniLM-L6-v2, 384-dim) |
| Distribution | electron-builder + electron-updater |
┌─────────────────────────────────────────────────────────────────┐
│ Atrophy Architecture │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ Renderer │◀───▶│ Preload │◀───▶│ Main Process │ │
│ │ (Svelte 5) │ IPC │ Bridge │ IPC │ (Node.js) │ │
│ └─────────────┘ └─────────────┘ └────────┬────────┘ │
│ │ │
│ ┌───────────────────────────────┼──────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ Claude CLI │ │ SQLite DB │ │
│ │ (inference) │ │ (memory) │ │
│ └───────────────┘ └───────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ ElevenLabs │ │ Embeddings │ │
│ │ (TTS) │ │ (WASM) │ │
│ └───────────────┘ └───────────────┘ │
└─────────────────────────────────────────────────────────────────┘
The system is agent-aware. Switching agents changes the entire identity - all paths, configuration, database, voice settings, and personality are scoped per-agent.
Two root paths:
BUNDLE_ROOT- where the code lives (process.resourcesPathwhen packaged, project root in dev)USER_DATA(~/.atrophy/) - runtime state, memory DBs, generated avatar content, user config
Agent directory structure:
agents/<name>/ # In BUNDLE_ROOT (repo)
prompts/
system_prompt.md # personality and behavioral instructions
soul.md # core identity document
heartbeat.md # outreach evaluation checklist
data/
agent.json # manifest: display name, voice config
~/.atrophy/agents/<name>/ # In USER_DATA (runtime)
data/
memory.db # per-agent SQLite database
.emotional_state.json
.user_status.json
avatar/
loops/ # generated loop segments
ambient_loop.mp4 # master ambient loop
index.md- Main process entry pointbootstrap.md- Hot bundle loaderapp.md- Main process implementation
config.md- Three-tier configuration systemlogger.md- Leveled loggingsession.md- Session lifecyclestatus.md- User presence trackinginstall.md- Login item management
memory.md- SQLite three-layer memoryvector-search.md- Hybrid vector + keyword searchembeddings.md- Transformers.js WASM embeddingsqueue.md- Thread-safe message queue
inference.md- Claude CLI streamingcontext.md- Context assemblyprompts.md- Four-tier prompt resolutionopening.md- Opening line generationartifact-parser.md- Inline artifact extraction
agency.md- Pattern detection for contextthinking.md- Effort classificationsentinel.md- Coherence monitoring
inner-life.md- Emotional state engine
tts.md- Text-to-speechstt.md- Speech-to-textaudio.md- Audio bridgewake-word.md- Wake word detectioncall.md- Voice call modevoice-agent.md- Hybrid voice agent
agent-manager.md- Agent discoverycreate-agent.md- Agent scaffolding
handlers.md- IPC orchestratorconfig.md- Configuration handlersagents.md- Agent managementinference.md- Inference handlersaudio.md- Audio handlerssystem.md- System handlerstelegram.md- Telegram handlers
mcp-registry.md- MCP server registryswitchboard.md- Message switchboard
bundle-updater.md- Hot bundle downloaderupdater.md- DMG auto-updateravatar-downloader.md- Avatar assets
- bootstrap.ts - Detect hot bundle, load app.js
- ensureUserData() - Create directory structure
- getConfig() - Load configuration singleton
- initDb() - Open SQLite database
- registerIpcHandlers() - Register IPC handlers
- registerAudioHandlers() - Register audio IPC
- registerWakeWordHandlers() - Register wake word IPC
- setPlaybackCallbacks() - Wire TTS callbacks
- Resume last active agent - Load previous agent
- Start background timers - Sentinel, queue poller, deferral watcher
- Create window - Show GUI or start server mode
Environment variables → ~/.atrophy/config.json → agent.json → defaults
Pre-built bundles from GitHub Releases enable OTA updates without DMG reinstall.
Each agent has separate database, config, prompts, and state files.
Audio capture in renderer (browser APIs), processing in main process (native binaries).
Turns are written immediately; embeddings computed asynchronously in background.
FILE_INDEX.md- Complete file index with documentation statusarchive/- Legacy overview documents