31#include <choc/containers/choc_Value.h>
39#include <unordered_map>
40#include <unordered_set>
66 using BypassValue = std::variant<bool, std::vector<std::string>>;
75 std::string_view property_path,
76 choc::value::Value
value,
77 std::string_view source = {});
103 std::vector<BatchEntry> entries,
104 std::string_view source = {});
109 std::string_view property_path);
153 std::optional<choc::value::Value>
154 lookup(std::string_view anchor_id, std::string_view property_path)
const;
159 std::string_view property_path)
const;
163 std::optional<BypassValue>
302 std::unordered_map<std::string, std::unordered_set<std::string>>
321 std::vector<DriftedTweak>
331 mutable std::mutex mtx_;
335 choc::value::Value
value;
339 std::unordered_map<std::string,
340 std::unordered_map<std::string, Entry>> tweaks_;
341 std::unordered_map<std::string, BypassValue> bypassed_;
344 std::unordered_set<std::string> locked_;
345 std::uint64_t next_sequence_ = 0;
350 bool auto_save_ =
false;
351 std::string auto_save_path_;
357 int auto_save_suspend_depth_ = 0;
360 std::string to_json_locked()
const;
361 DiskResult from_json_locked(std::string_view json);
362 DiskResult save_locked(std::string_view
path)
const;
366 void maybe_auto_save_unlocked()
const;
std::string auto_save_path() const
The path auto-save flushes to (empty if auto-save is off and no explicit path has ever been set).
void set_locked(std::string_view anchor_id, bool locked)
Set the lock state for an anchor.
std::vector< std::string > bypassed_anchors() const
Return every anchor id that currently has a bypass entry, regardless of whether it also has tweak rec...
DiskResult load_from_disk(std::string_view path={})
Replace the in-memory state with the contents of path.
void set_auto_save(bool enabled, std::string_view path={})
Enable / disable post-mutation auto-save.
bool auto_save_enabled() const
Whether auto-save is currently armed.
std::size_t remove_anchor(std::string_view anchor_id)
Remove all entries for an anchor.
std::vector< Record > list_tweaks() const
Return every record in the store's stable order.
std::vector< DriftedTweak > find_drifted(const std::vector< std::string > &live_anchors) const
Convenience overload taking a flat anchor list.
static const char * drift_reason_str(DriftReason reason)
Stringify a DriftReason for JSON / human output.
std::size_t apply_tweaks_batch(std::string_view anchor_id, std::vector< BatchEntry > entries, std::string_view source={})
Apply several tweaks under one anchor as a SINGLE atomic unit.
DriftReport diff(const DesignSnapshot &design) const
Classify every stored tweak against design.
std::size_t apply_tweak(std::string_view anchor_id, std::string_view property_path, choc::value::Value value, std::string_view source={})
Record an edit.
std::size_t count() const
Total number of (anchor, property) entries.
bool remove_tweak(std::string_view anchor_id, std::string_view property_path)
Remove a single (anchor_id, property_path) entry.
std::variant< bool, std::vector< std::string > > BypassValue
Bypass overlay value — matches the TS true | string[] shape.
Definition tweak_store.hpp:66
std::string to_json() const
Serialize the current state to a JSON string in the on-disk schema.
static std::string drift_report_to_json(const DriftReport &report)
Render a DriftReport as a JSON string (used by pulp tweaks diff --json and the protocol layer).
bool is_bypassed(std::string_view anchor_id, std::string_view property_path) const
Whether a specific (anchor_id, property_path) is currently bypassed (either whole-anchor or path-spec...
void clear_bypass(std::string_view anchor_id)
Convenience: clear the bypass for an anchor (equivalent to set_bypass(id, false)).
static std::string default_tweaks_path()
Resolve the default pulp-tweaks.json location:
void clear_lock(std::string_view anchor_id)
Convenience: clear the lock for an anchor (equivalent to set_locked(id, false)).
void clear()
Clear the entire table (tweaks + bypass overlay + lock set).
bool is_locked(std::string_view anchor_id) const
Whether anchor_id is currently locked.
std::optional< choc::value::Value > lookup(std::string_view anchor_id, std::string_view property_path) const
Look up a specific (anchor_id, property_path).
std::vector< DriftedTweak > find_drifted(const DesignSnapshot &design) const
Return only the orphaned + drifted tweaks for design — the subset the inspector drift drawer renders.
DriftReason
Why a tweak failed to apply cleanly.
Definition tweak_store.hpp:257
@ anchor_not_found
No live view carries this anchor_id.
Definition tweak_store.hpp:258
@ property_not_found
Anchor resolves but the design no longer exposes this property path.
Definition tweak_store.hpp:259
std::vector< std::string > locked_anchors() const
Return every anchor id that currently carries a lock, in unspecified order.
void set_bypass(std::string_view anchor_id, BypassValue value)
Set the bypass state for an anchor.
static constexpr int kSchemaVersion
On-disk schema version. Bumped if/when we ever break the format.
Definition tweak_store.hpp:187
DiskResult from_json(std::string_view json)
Replace state from an in-memory JSON string.
std::optional< BypassValue > bypass_for(std::string_view anchor_id) const
Current bypass state for an anchor.
DriftReport diff(const std::vector< std::string > &live_anchors) const
Convenience: classify against a flat anchor list (anchor-only matching — no property-level drift).
DiskResult save_to_disk(std::string_view path={}) const
Atomically write the current in-memory state to path.
@ path
Definition scene_node.hpp:93
Definition design_adherence.hpp:32
Definition agent_context.hpp:7
Definition host_transport_projector.hpp:8
@ value
the widget's primary value (Knob, Fader, RangeSlider, Toggle, ProgressBar)
Definition binding_diagnostics.hpp:19
One (property_path, value) pair within a batched apply.
Definition tweak_store.hpp:81
std::string property_path
Dotted path, e.g. "layout.left".
Definition tweak_store.hpp:82
choc::value::Value value
Definition tweak_store.hpp:83
A design snapshot the drift logic diffs tweaks against.
Definition tweak_store.hpp:300
std::unordered_set< std::string > anchors
Definition tweak_store.hpp:301
std::unordered_map< std::string, std::unordered_set< std::string > > properties
Definition tweak_store.hpp:303
Outcome of a disk operation.
Definition tweak_store.hpp:191
std::size_t bypass_count
Definition tweak_store.hpp:195
std::string path
Definition tweak_store.hpp:196
std::size_t tweak_count
Definition tweak_store.hpp:194
std::string error
Definition tweak_store.hpp:193
bool ok
Definition tweak_store.hpp:192
Three-way classification of every stored tweak against a design.
Definition tweak_store.hpp:277
bool has_drift() const
Definition tweak_store.hpp:285
std::vector< DriftedTweak > drifted
Anchor resolves, property gone.
Definition tweak_store.hpp:279
std::size_t total() const
Definition tweak_store.hpp:282
std::vector< Record > clean
Anchor + property both resolve.
Definition tweak_store.hpp:278
std::vector< DriftedTweak > orphaned
Anchor itself is gone.
Definition tweak_store.hpp:280
One drifted tweak — a stored edit that no longer maps cleanly to the current design.
Definition tweak_store.hpp:268
DriftReason reason
Definition tweak_store.hpp:273
std::string source
Definition tweak_store.hpp:272
std::string property_path
Definition tweak_store.hpp:270
std::string anchor_id
Definition tweak_store.hpp:269
choc::value::Value value
Definition tweak_store.hpp:271
A single tweak record returned by list_tweaks().
Definition tweak_store.hpp:56
std::string property_path
Definition tweak_store.hpp:58
std::string source
Definition tweak_store.hpp:60
choc::value::Value value
Definition tweak_store.hpp:59
std::string anchor_id
Definition tweak_store.hpp:57