Commit Graph

3 Commits

Author SHA1 Message Date
ekko d0f1e7d1f2 Fix bridge compression history handling (#726)
* feat(bridge): refactor compression to use DB history and add structured logging

- Extract buildDbHistory() to share message loading between buildCompressedHistory and forceCompressBridgeHistory
- forceCompressBridgeHistory now reads from local DB instead of using Python-provided messages, ensuring consistency with api_server path
- Pass sessionId to compressor for snapshot-aware compression
- Add force_compress flag to bridge chat requests
- Add bridgeLogger structured logging for compression lifecycle
- Simplify schemas, session-sync, and providers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix bridge compression history handling

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-14 21:02:59 +08:00
ekko 969c7c0e1a feat: add robust LLM JSON parser and fix Group Chat schema (#388)
Add robust LLM JSON parsing utilities to handle unreliable model output:
- Parse tool arguments with tolerance for Python format (single quotes, trailing commas)
- Extract text from Anthropic-style content arrays in streaming events
- Normalize tool_result content to string format per Hermes spec
- Parse message.delta and run.completed output to avoid displaying JSON strings

Fix Group Chat database schema errors:
- Add id column as PRIMARY KEY to gc_room_agents and gc_room_members tables
- Change from composite primary keys to single-column id keys
- Update tests to match new schema structure

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 08:58:14 +08:00
ekko acf4e225e6 feat: rewrite database schema synchronization with automatic recovery (#379)
Complete rewrite of the Hermes SQLite database schema synchronization mechanism
with comprehensive error handling, automatic recovery, and full test coverage.

## Database Schema Synchronization
- **Unified sync mechanism**: Single `syncTable()` function handles all schema changes
- **Automatic column sync**: Adds missing columns and removes extra columns
- **Table rebuilding**: Automatically rebuilds tables when primary keys or types change
- **Data preservation**: Preserves data during schema changes when compatible
- **Index management**: Creates and removes indexes as needed

## Error Recovery & Reliability
- **Automatic backup**: Backs up corrupted database before recovery
- **Retry limiting**: Prevents infinite loops with retry limit
- **Duplicate prevention**: Avoids multiple backup files
- **Safe file operations**: Uses copy+delete instead of rename for safety

## Composite Primary Keys
- Fixed GC_ROOM_AGENTS and GC_ROOM_MEMBERS with proper composite primary keys
- Prevents duplicate entries while allowing same roomId with different agentId/userId

## Test Coverage
- **10 new integration tests** for schema synchronization (tests/server/schema-sync.test.ts)
- **3 updated tests** for Hermes schemas (tests/server/hermes-schemas.test.ts)
- All 327 tests passing (47 test files, 325 passed, 2 skipped)

## Bug Fixes
- Fixed module import issues (unified ES6 imports, removed mixed require())
- Fixed mock issues in sessions routes tests
- Fixed i18n coverage test to handle newly added keys
- Fixed profiles store test to match current implementation

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 19:48:46 +08:00