mixle.substrate.spaces module¶
Team-scoped substrate views with explicit publishing.
The substrate tags every item with an access scope (“local”, a team id, or a shared scope like
“public”), but the raw store filters on ONE scope at a time. A team’s real visibility is a union: its
own items PLUS whatever has been shared into a common scope, and never another team’s private items.
Space is that view. Construct one for a team and it answers retrieve / all over exactly
the team’s visible set, so two teams querying the same substrate see different, correctly-isolated
knowledge.
Sharing is explicit: nothing crosses a scope boundary until someone calls
publish(). Publishing re-scopes an item into a shared scope and records
who published it and from where.
- visible_scopes(team, *, shared=(PUBLIC,))[source]
The scopes a team may read: its own id plus the shared scopes (never another team’s private one).
- publish(substrate, ids, *, to=PUBLIC, by=None, from_scope=None)[source]
Share items into a common scope.
Re-scopes each item in
idstotoand recordspublished_by/published_fromin its provenance. Returns the ids actually published (missing ids are skipped).from_scope, if given, guards that only items currently in that scope are published (an ACL check the caller can enforce).
- version_of(item)[source]
The share version of an item (0 if never published) – a monotonic counter bumped by each publish.
- history(substrate, item_id)[source]
The full publish history of an item: every version with who shared it, from where, to where.
- merge_versions(substrate, keep_id, other_id, *, by=None, prefer='latest')[source]
Reconcile two versions of the same knowledge into one, keeping full lineage (no silent loss, P2).
Merges
other_idintokeep_id: unions tags and links, keeps the text/payload of whichever has the higher version (prefer="latest") or ofkeep(prefer="keep"), bumps the surviving item’s version, records BOTH parents in the history, and removes the merged-away item. Returns the surviving id, or None if either is missing. Two teams that independently edited a shared item can be reconciled without either edit vanishing unrecorded.
- class Space(substrate, team, *, shared=(PUBLIC,))[source]
Bases:
objectA team’s scoped view over a shared substrate: its own items plus what has been shared to it.
- all(*, kind=None)[source]
Every visible item (optionally of one kind) – never another team’s private knowledge.
- add(*, scope=None, **kw)[source]
Add an item to this team’s own scope by default (pass
scope=PUBLICto share immediately).
- retrieve(query, *, k=8, **kw)[source]
Retrieve over exactly the team’s visible set (own scope ∪ shared), with cross-kind diversity.