diff --git a/content/storage-bridge.js b/content/storage-bridge.js index 3a2d130..ae3f9cf 100644 --- a/content/storage-bridge.js +++ b/content/storage-bridge.js @@ -10,7 +10,8 @@ function fetchRemote() {return authHeaders().then(function(h){return fetch(BU+"/ function putRemote(s) {return authHeaders().then(function(h){return fetch(BU+"/"+"memory/state",{method:"PUT",headers:h,body:JSON.stringify(s)})}).then(function(r){if(!r.ok)throw new Error("PUT "+r.status);return r.json()}).then(function(j){return j&&j.ok})}; function newer(a,b) {return (a&&a.updatedAt?a.updatedAt:"") >= (b&&b.updatedAt?b.updatedAt:"")}; -function sync() {return Promise.all([loadLocal(),fetchRemote().catch(function(){return null})]).then(function(arr){var loc=arr[0],rem=arr[1];if(!rem)return loc;if(newer(loc,rem)){putRemote(loc).catch(function(){});return loc};return saveLocal(rem).then(function(){return rem})})}; +function isEmpty(s) {return !s || ((s.memories ? Object.keys(s.memories).length : 0) + (s.skills ? s.skills.length : 0) === 0)}; +function sync() {return Promise.all([loadLocal(),fetchRemote().catch(function(){return null})]).then(function(arr){var loc=arr[0],rem=arr[1];if(!rem)return loc;var le=isEmpty(loc),re=isEmpty(rem);if(le!==re){if(le){return saveLocal(rem).then(function(){return rem})}putRemote(loc).catch(function(){});return loc};if(newer(loc,rem)){putRemote(loc).catch(function(){});return loc};return saveLocal(rem).then(function(){return rem})})}; function getState() {return sync()}; function putState(s) {var v={version:1,updatedAt:new Date().toISOString(),memories:s.memories||{},skills:s.skills||[]};return saveLocal(v).then(function(){return putRemote(v).catch(function(){return false})}).then(function(){return v})}; diff --git a/memory/state.json b/memory/state.json index 24cba57..46d879c 100644 --- a/memory/state.json +++ b/memory/state.json @@ -1,6 +1,6 @@ { "version": 1, - "updatedAt": "2026-10-31T02:11:46.453Z", + "updatedAt": "2026-10-31T03:11:08.923Z", "memories": {}, "skills": [] } \ No newline at end of file