mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
Implement two-stage content codec: truncate oversized agent messages (48KB head + 12KB tail + marker, idempotent, never user messages) and compress message content JSON ≥256 bytes via zstd with fallback. - contentCodec.ts: new codec with truncation and compression routines - messages.ts: wire codec into addMessage (truncate+compress), copyMessageToSession (lossless), toStoredMessage (decode both formats) - index.ts: schema version 15→16 with no-op migration (enforces schema match on downgrade, no DDL change) - codexDesktop.ts: pass content through idempotent truncation for canonical comparison in transcript-import - cleanup-sessions.ts: decode compressed rows, replace full-scan with per-session batched scan (LIMIT 50) stopping at first user message - compact-db.ts: new offline compactor that retroactively applies truncate+compress+VACUUM to existing DBs; guards against schema version mismatch, symlink aliasing, and handles re-runs - Tests: contentCodec round-trip + truncation + idempotence + legacy decode; messages integration (compressed/truncated round-trip); migration tests updated to version 16 - README.md: document codec and both maintenance scripts Measured on 2.26GB production DB: 2159MB→768MB (-64%) in 12s, 748k messages intact, integrity verified.