#pragma once #include #include // Device memory cache stored in claude_mem Flash partition // Uses raw flash read/write with simple header + JSON format class MemoryCache { public: static MemoryCache& GetInstance(); // Load cached data from Flash on boot bool Load(); // Save current data to Flash bool Save(); std::string GetProfileText() const { return profile_text_; } std::string GetChildName() const { return child_name_; } int GetInteractionCount() const { return interaction_count_; } void SetProfileText(const std::string& text) { profile_text_ = text; } void SetChildName(const std::string& name) { child_name_ = name; } void SetInteractionCount(int count) { interaction_count_ = count; } // Update from server's memory_sync JSON object, then save to Flash void UpdateFromServerSync(const cJSON* memory_sync); bool HasData() const { return !child_name_.empty() || !profile_text_.empty(); } private: MemoryCache() = default; std::string profile_text_; std::string child_name_; int interaction_count_ = 0; static constexpr uint32_t kMagic = 0x424F524C; // "BORL" static constexpr const char* kPartitionLabel = "claude_mem"; };