Last updated: 2026-03-15
Runtime projection of any Maggie object into a CUE value. No syntax changes, no compiler work — pure primitive method on Object.
asCueValuebuilds a CUE struct from the receiver's ivar names and slot values- Uses existing
AllInstVarNames()/GetSlot(i)+cueExportValuemachinery CueValue>>matchesObject:— unify a CUE template against an object's projection, return true unless bottom- Enables tuplespace matching via CUE unification (structural, range-aware, composable) instead of Linda-style equality templates
Depends on: existing CueContext / CueValue wrappers (already NaN-boxed)
Optional CUE schema field on Class, compiled once at class definition time.
- New
cueSchema *cue.Valuefield onClassstruct .magsyntax:schema: '{x: number, y: number}'in class definition- Slot assignment validates against cached schema via
FillPath+Err() - Opt-in per class (nil schema = no validation, zero cost)
- Required CUE fields = hard constraints; default-value fields = soft/preferred
- Maps to Kaleidoscope's constraint hierarchy insight: required vs. preferential
Design considerations:
- Compile schema once at class load, cache on Class — no per-write CUE parse cost
- Recompile only on class redefinition
SetSlotValidatingpath behind a flag so unschema'd classes pay nothing- Subclass schemas must unify with superclass schema (tightening only, never loosening)
- Parser/compiler changes needed for
schema:clause in class definitions
CUE constraints as guards on method applicability.
- Optional
CueGuard *cue.ValueonCompiledMethod - At dispatch: project receiver via
asCueValue, unify with guard, skip method if bottom - Multiple methods with same selector disambiguated by guard specificity
.magsyntax:method: describe [cue: '{speed: >100}'] ^'fast'
Design considerations:
- VTable surgery: method lookup must try guards in specificity order
- Guard compilation happens once at method compile time
- Performance: guard checks add cost per dispatch — consider caching projection per message send
- Interaction with traits: trait methods with guards should compose via unification
- Parser changes for
[cue: ...]annotation syntax
Detailed implementation plan: docs/plans/2026-03-04-distributed-maggie-implementation-plan.md
What's done:
- Content hashing (SHA-256, De Bruijn indexed, golden files)
- Chunk types (method, class, module) with CBOR wire format
- Disk cache (git-style content-addressed storage in
.maggie/cache/) - Sync service RPCs: Announce, Transfer, Serve, Ping, Resolve, List
- CLI:
mag sync push|pull|status|list|diff|show - Rehydration pipeline (topological sort, namespace-aware, hash-verified)
- Peer reputation tracking with auto-ban on hash mismatches
- Capability policy (allow/deny lists on server)
Items that would harden the existing code distribution before moving to node protocol:
- Automatic cache loading on startup — currently only loaded explicitly during
sync pull - Rehydration in main compile flow —
RehydrateFromStoreonly called after pull, not during normal project load - Capability metadata on chunks —
Chunk.Capabilitiesfield exists but never populated - Peer management CLI — no
mag peersubcommand to inspect/manage reputation or ban list - Reputation persistence — peer trust data lost between sessions
- Import preservation for pulled code — synced code only works with FQN, not unqualified imports
The bridge from "distribute code" to "distribute execution."
- Node identity —
.maggie/node.key, node IDs, authentication - Value serialization —
vm/dist/serial.gowithSerializeValue/DeserializeValuefor cross-VM message passing - Symbol table negotiation — selector/symbol table sync between VMs (each VM has its own table)
- Inter-VM messaging —
SendMessageRPC for arbitrary message delivery between processes on different nodes - Remote process spawning —
forkOn: nodeRefprimitive, process runs on remote VM - Code-on-demand — automatic
sync pullwhen deserializing an object whose class is unknown locally - Distributed GC — lease-based reference lifecycle for cross-VM references
- Health checking — periodic ping + failure detection + process migration
Higher-level abstractions built on top of node protocol.
- Location-transparent proxies — remote references that forward messages via
SendMessageRPC; leverages existingbecome:forwarding pointer system - Supervisor trees — supervision hierarchy spanning nodes, Erlang-style restart strategies
- Cluster membership — gossip protocol or mDNS for node discovery
- Capability enforcement at runtime — tie
forkRestricted:mechanism to distributed capability policy
Detailed plan: docs/plans/2026-03-15-tuplespace-implementation-plan.md
- CUE Subsumption —
CueValue>>subsumes:/subsumedBy:for entailment checking - Local TupleSpace — Linda-style
in:/out:/read:with CUE unification matching and goroutine-based blocking - Linear Logic Extensions — tuple modes (linear/affine/persistent), atomic multi-take (⊗), choice (⊕), lease/expiry
- Constraint Store (CCP) — monotonic CUE-backed store with
tell:/ask:/suspend, concurrent constraint programming semantics - Agent Orchestration Patterns — application-layer Maggie code: Agent class, task/result protocols, fan-out/fan-in/pipeline/auction/blackboard/consensus patterns
- Distributed Tuplespace — depends on node protocol; partitioned tuples, CRDT-like constraint store replication
CUE Layer 1 (done)
│
├──→ CUE Layer 2 (schema on class)
│ │
│ └──→ CUE Layer 3 (method guards)
│
├──→ CUE Subsumption (now)
│ │
│ └──→ Local TupleSpace
│ │
│ ├──→ Linear Logic Extensions
│ │
│ └──→ Constraint Store (CCP)
│ │
│ └──→ Agent Orchestration (app layer)
│
├──→ Distribution Gaps (polish)
│ │
│ └──→ Node Protocol
│ │
│ ├──→ Distributed Programming Model
│ │
│ └──→ Distributed TupleSpace
The local tuplespace track (subsumption → tuplespace → linear extensions / constraint store) is independent of the distribution track. Agent orchestration can begin as soon as the local tuplespace exists. Distribution comes later.