Share resource history interpretation across working and acknowledged scans

This commit is contained in:
2026-11-10 01:50:14 +08:00
parent fb997f23a8
commit c087d32e84
4 changed files with 86 additions and 45 deletions
+4 -3
View File
@@ -2,13 +2,14 @@ import {importNeedsSeal} from './imports.ts';
import type {Id,Registry} from '../canvas-core/types.ts';
import {fault,readMap,readSet,freeze} from '../canvas-core/values.ts';
import type {EngineSnapshot,RuntimeState} from './contracts.ts';
import {resourcePins} from './resources.ts';
import {createResourcePinScan} from './resources.ts';
/** Complete local-byte protection for one project scope; no DOM/viewport filtering. */
export function resourceRetentionPins(snapshot:EngineSnapshot,registry:Registry,displays:ReadonlyMap<Id,number>=new Map(),temporary:ReadonlyMap<Id,readonly Id[]>=new Map()) {
const {runtime}=snapshot;
const current=resourcePins(snapshot,runtime.ledger,registry,runtime.resourcePins);
const base=resourcePins({...snapshot,document:runtime.acknowledged},runtime.ledger,registry,new Map());
const scan=createResourcePinScan(snapshot.history,runtime.ledger,registry);
const current=scan(snapshot.document,runtime.resourcePins);
const base=scan(runtime.acknowledged);
const pins=new Map<Id,Set<string>>();
const add=(id:Id,owner:string)=>{let owners=pins.get(id);if(!owners){owners=new Set();pins.set(id,owners);}owners.add(owner);};
for(const [id,owners]of current.pins)for(const owner of owners)add(id,owner);