Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Atrophy Codebase Documentation

This directory contains comprehensive documentation for the Atrophy Electron application - a companion agent system with voice interaction, persistent memory, and autonomous background processes.

Recent Changes (2026-03-26)

Features

  • 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

Bug Fixes

# 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()

New Files

  • scripts/agents/shared/credentials.py - Shared credential loading
  • docs/specs/decisions/2026-03-26-auto-telegram-chat-id-management.md
  • docs/specs/decisions/2026-03-26-bug-scan-and-avatar-investigation.md

Documentation Structure

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

Architecture Overview

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).

Technology Stack

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

Core Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    Atrophy Architecture                          │
│                                                                   │
│  ┌─────────────┐     ┌─────────────┐     ┌─────────────────┐   │
│  │  Renderer   │◀───▶│   Preload   │◀───▶│  Main Process   │   │
│  │  (Svelte 5) │ IPC │   Bridge    │ IPC │  (Node.js)      │   │
│  └─────────────┘     └─────────────┘     └────────┬────────┘   │
│                                                    │             │
│                    ┌───────────────────────────────┼──────┐     │
│                    │                               │      │     │
│                    ▼                               ▼      ▼     │
│            ┌───────────────┐              ┌───────────────┐    │
│            │  Claude CLI   │              │  SQLite DB    │    │
│            │  (inference)  │              │  (memory)     │    │
│            └───────────────┘              └───────────────┘    │
│                    │                               │             │
│                    ▼                               ▼             │
│            ┌───────────────┐              ┌───────────────┐    │
│            │  ElevenLabs   │              │  Embeddings   │    │
│            │  (TTS)        │              │  (WASM)       │    │
│            └───────────────┘              └───────────────┘    │
└─────────────────────────────────────────────────────────────────┘

Agent System

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.resourcesPath when 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

Module Categories

Entry Points

Configuration & Foundation

Data Layer

Inference & Context

Behavioral Agency

Inner Life System

Voice Pipeline

Agent Management

IPC Handlers

Channels & MCP

Updates & Assets

Services & Analytics

Startup Sequence

  1. bootstrap.ts - Detect hot bundle, load app.js
  2. ensureUserData() - Create directory structure
  3. getConfig() - Load configuration singleton
  4. initDb() - Open SQLite database
  5. registerIpcHandlers() - Register IPC handlers
  6. registerAudioHandlers() - Register audio IPC
  7. registerWakeWordHandlers() - Register wake word IPC
  8. setPlaybackCallbacks() - Wire TTS callbacks
  9. Resume last active agent - Load previous agent
  10. Start background timers - Sentinel, queue poller, deferral watcher
  11. Create window - Show GUI or start server mode

Key Design Decisions

Three-Tier Configuration

Environment variables → ~/.atrophy/config.jsonagent.json → defaults

Hot Bundle Updates

Pre-built bundles from GitHub Releases enable OTA updates without DMG reinstall.

Per-Agent Isolation

Each agent has separate database, config, prompts, and state files.

Split Voice Pipeline

Audio capture in renderer (browser APIs), processing in main process (native binaries).

Fire-and-Forget Embedding

Turns are written immediately; embeddings computed asynchronously in background.

See Also