mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Resolves #1989. When encryption at rest is enabled, `.swarm/memory.db` becomes an RFE1-magicked ciphertext blob rather than a SQLite database. The statusline-generator's "page count at offset 28" fallback read ciphertext bytes as a uint32 and rendered 3,367,093,602 patterns, which then cascaded into fake DDD 5/5 / 100% / intelligence 100% downstream. Three defense layers, all in `statusline-generator.ts` (the template that `ruflo init` writes to `.claude/helpers/statusline.cjs`): 1. **Magic-bytes check** -- compare the first 16 bytes against the literal "SQLite format 3\\0" before interpreting any subsequent bytes. Encrypted, empty, or non-SQLite files are skipped. 2. **Page-count sanity clamp** -- reject pageCount > 1,000,000 (~4GB DB). Catches future regressions or genuinely corrupt headers even on plaintext SQLite. 3. **Defensive consumer clamps** in `getV3Progress` and `getSystemMetrics` -- `Number.isFinite` + range check on `learning.patterns` before deriving domainsCompleted / intelligencePct. If any future regression in the reader returns a wild value, the downstream displays stay honest. Verified with a fake RFE1-headered `memory.db` matching the forensic bytes from the issue: Before: DDD Domains 5/5 / 100% / patterns=3367093.6k / 🧠 100% After: DDD Domains 0/5 / 0% / patterns=0 / 🧠 0% The `\\0` in the SQLite-magic string is intentional: the statusline-generator emits via a JS template literal, so the source-level `\\\\0` resolves to `\\0` in the generated .cjs which JS then parses as the null byte. Co-authored-by: Reuven <cohen@ruv-mac-mini.local>