Repository navigation
Description
Land the open-core data plane for ADR-037's organizational-by-default / opt-in-restriction access model, so a future nodespaced-pro RLS layer can enforce it. Per ADR-028 this issue covers only inert, local-first data and ops: a Core-protected boolean restrictedToMembers on the collection schema, a permission value (admin/modify/readOnly, default modify) on member_of edges, and the ops the UI needs to toggle restriction and manage person members with permission levels.
PersonNode the type is owned by #133 — this issue depends on it for the person-only membership check and does not re-specify it. No PersonNode instance is seeded locally (nothing reads it in the free/local journey); the first PersonNode is created at Pro sync-onboarding (create + name + bind), a pro/frontend flow.
Out of scope (private nodespace-sync / nodespace-cloud): RLS enforcement (user_can_access_node/user_can_write_node, nearest-boundary recursive CTE, break-inheritance, person-only filter), the atomic auto-admin bootstrap on restrict, the Last-Admin Invariant trigger, auth_identities/JWT bind, all cloud DDL (nodes.id TEXT, collection_members VIEW, REPLICA IDENTITY FULL), and PersonNode instantiation/naming. Core lands the data they read.
Greenfield (per CLAUDE.md): no migration code. The modify read-default covers legacy member_of edges; absent restrictedToMembers = false. Reset is acceptable.
Dependencies
- Implement PersonNodeBehavior #133 (PersonNode type) — hard prerequisite for Task C2 (person-only membership) and the member-list ops. PersonNode schema + behavior live there, not here.
What core must land (the wire contract pro reads)
Two things on the wire, plus the person keyspace (#133) the edges point at:
properties.restrictedToMembers: boolon collection nodesproperties.permission: "admin" | "modify" | "readOnly"on personmember_ofedges
Task A — restrictedToMembers core property on collection
No dependency. Ship first.
- Add a
restrictedToMembersSchemaField(boolean,protection: Core, defaultfalse, not required) to thecollectionSchemaNodeinpackages/core/src/models/core_schemas.rs(entry ~L285, currentlyfields: vec![]). - In
CollectionNodeBehavior::validate(packages/core/src/behaviors/mod.rs~L1424), reject a non-booleanrestrictedToMembers(mirror TaskNodeBehavior type-check ~L671). Absent/null → treated asfalse. - Verify
SchemaProtectionLevel::Coreactually blocks writes at the persistence boundary (not just advisory/UI-hidden) for arbitraryupdate_nodecallers — if advisory today, add a hard reject in the behavior + ensure the protection path runs on every collection update. (See Risk 1.) - Tests: absent→valid(false);
true/false→valid;"true"/number→InvalidProperties.
Task B — permission value on member_of edges
No dependency; inert until persons exist.
- Extend
SqliteStore::add_to_collection(packages/core/src/db/sqlite_store.rs~L2887) to accept optionalpermissionand write it into the edgepropertiesJSON alongsideorder(additive, no DDL — edgepropertiesalready exists ~L2934). - Add
set_member_permission(member_id, collection_id, permission)updatingproperties->>'permission'. - Define a
Permissionenum (Admin/Modify/ReadOnly) serializing toadmin/modify/readOnly; reads default tomodifywhen absent. - Validate the enum at the ops boundary; reject unknown strings.
- Tests: each level round-trips; absent→
modify; unknown rejected; permission update.
Task C — Ops: set restriction, add person members, set permission, list members
Depends on Task B + #133 (person type).
-
set_collection_restriction(collection_id, bool)incollection_ops.rs— plain property write, no auto-admin grant (that is the pro bootstrap, deliberately omitted). -
add_person_to_collection(person_id, collection_id, permission)— validatesout_nodeisnode_type='person'(person-only, ADR-037 §4); defaultmodify. -
set_member_permission(...)wrapping Task B. - Extend
get_collection_members/_recursive(collection_ops.rs~L164/L180; queriessqlite_store.rs~L2991/L3084) to surface each member'spermission(defaultmodify). - Tests: non-person rejected; person at each level; permission change; list returns levels.
Suggested sequence: A ∥ B → (B + #133) → C.
Risks / open decisions (core side)
- Protection vs. fail-open RLS (highest risk). The pro RLS is open-by-default: any non-boolean
restrictedToMembersreads as not restricted (soft-open). Core MUST guarantee the field is only ever a boolean — confirmSchemaProtectionLevel::Coreblocks writes at persistence, not just UI. Treat a non-boolean write as a bug, not a soft-open. - Auto-admin bootstrap is purely pro (ADR-037 §6). Keep
set_collection_restrictiona dumb property write — no local admin grant. Local restriction is inert (no RLS locally); document this. Do not add a "convenience" local bootstrap — it would create a second, divergent path. - No local PersonNode instance. Decided: nothing reads a PersonNode in the free/local journey, so none is seeded (no inert placeholder). The person-only membership check in Task C simply has nothing to point at locally until Pro onboarding creates the first PersonNode — which is correct (a single-user local graph has no members).
- No migration/reset code —
modifyread-default + absent-=false cover legacy; reset is fine.
A separate, deferrable Pro-onboarding issue (pro/frontend) covers PersonNode instantiation + name prompt + Supabase identity bind at the start of the sync journey, plus the always-visible gated "Restrict to members" upgrade CTA (tier-aware via the existing WatchSyncStatus capability probe). Neither has a core backend dependency beyond the property/type existing.
Breakdown produced via senior-architect-reviewer against ADR-037 + the merged cloud-sync.md, grounded in current nodespace-core source. Revised: PersonNode type consolidated into #133; no local placeholder; instantiation deferred to Pro onboarding.
Activity
#1372: restrictedToMembers Core field on the collection schema (ADR-0…
#1372: restrictedToMembers Core field on the collection schema (ADR-0…