refactor: Replace JSON registry with SQLite database

Replace the JSON-based project registry with SQLite using SQLAlchemy ORM
for improved reliability, concurrency handling, and simpler code.

Changes:
- registry.py: Complete rewrite from JSON to SQLite storage
  - Remove manual file locking (RegistryLock class with msvcrt/fcntl)
  - Remove atomic write logic (temp file + rename pattern)
  - Remove backup/recovery logic for corrupted JSON
  - Add SQLAlchemy Project model with name, path, created_at columns
  - Add singleton database engine pattern (_get_engine)
  - Add session context manager (_get_session) for transactions
  - Simplify from 493 to 367 lines of code

- CLAUDE.md: Update documentation to reflect new storage

Storage location change:
- Before: Platform-specific paths
  - Windows: %APPDATA%\autonomous-coder\projects.json
  - macOS: ~/Library/Application Support/autonomous-coder/projects.json
  - Linux: ~/.config/autonomous-coder/projects.json
- After: Unified path for all platforms
  - ~/.autocoder/registry.db

Benefits:
- SQLite handles concurrency automatically (no manual locking needed)
- Atomic transactions built-in (no temp file + rename dance)
- Crash-safe by default (no backup/recovery code needed)
- Consistent with existing features.db pattern in api/database.py
- Data persists across app updates (stored in user home, not project)

All public API functions maintain their existing signatures, so no
changes are required in the 7 consumer files (start.py,
autonomous_agent_demo.py, and 5 server routers).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Auto
2026-01-02 11:22:51 +02:00
parent e8f3b99a42
commit 81b1b29f24
2 changed files with 140 additions and 268 deletions

View File

@@ -98,15 +98,13 @@ npm run lint # Run ESLint
### Project Registry
Projects can be stored in any directory. The registry (`projects.json`) maps project names to paths:
- **Windows**: `%APPDATA%\autonomous-coder\projects.json`
- **macOS**: `~/Library/Application Support/autonomous-coder/projects.json`
- **Linux**: `~/.config/autonomous-coder/projects.json`
Projects can be stored in any directory. The registry maps project names to paths using SQLite:
- **All platforms**: `~/.autocoder/registry.db`
The registry uses:
- SQLite database with SQLAlchemy ORM
- POSIX path format (forward slashes) for cross-platform compatibility
- File locking for concurrent access safety
- Atomic writes (temp file + rename) to prevent corruption
- SQLite's built-in transaction handling for concurrency safety
### Server API (server/)
@@ -146,7 +144,7 @@ MCP tools available to the agent:
### Project Structure for Generated Apps
Projects can be stored in any directory (registered in `projects.json`). Each project contains:
Projects can be stored in any directory (registered in `~/.autocoder/registry.db`). Each project contains:
- `prompts/app_spec.txt` - Application specification (XML format)
- `prompts/initializer_prompt.md` - First session prompt
- `prompts/coding_prompt.md` - Continuation session prompt