MCPcopy
hub / github.com/garrytan/gstack / mergeDreamIntoState

Function mergeDreamIntoState

bin/gstack-gbrain-sync.ts:1451–1457  ·  view source on GitHub ↗

* Persist the dream stage result with read-modify-write semantics. * * Dream runs AFTER the sync lock releases, so a sibling worktree may have * written newer state in the meantime. Overwriting the whole file with our * pre-dream snapshot + dream result would clobber that sibling's sync. Instead

(dream: StageResult)

Source from the content-addressed store, hash-verified

1449 * merge is what prevents the clobber.)
1450 */
1451function mergeDreamIntoState(dream: StageResult): void {
1452 const fresh = loadSyncState();
1453 const others = (fresh.last_stages || []).filter((s) => s.name !== "dream");
1454 fresh.last_stages = [...others, dream];
1455 fresh.last_sync = new Date().toISOString();
1456 saveSyncState(fresh);
1457}
1458
1459// ── Output ─────────────────────────────────────────────────────────────────
1460

Callers 1

mainFunction · 0.85

Calls 2

loadSyncStateFunction · 0.85
saveSyncStateFunction · 0.85

Tested by

no test coverage detected