Commit Graph
1 Commits
Author SHA1 Message Date
weishu 05ba050eb8 feat(hub): add message content codec for storage optimization
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.
2026-08-02 13:21:32 +08:00