Repository navigation
Closed
Description
Overview
Implement ADR-089's declared structural rules. Each type declares what it may have as children and what parent it needs, and the database enforces both for every write path.
Problem Statement
- "Must be a root" is two hand-written triggers. It exists only for
collectionandschema, as SQL triggers inpackages/core/src/db/schema.rskeyed on literal type names, so apro-collectionescapes it. - "Must have a parent" doesn't exist. It's needed for
ai-chat-message. can_have_children()isn't enforced.NodeBehavior::can_have_children()(packages/core/src/behaviors/mod.rs) is read only by embedding aggregation, never on a write.canBeChildis never consumed. The frontend's flag (packages/desktop-app/src/lib/plugins/core-plugins.ts) has no reader.
Proposed Solution
- Two rules per type, declared in the schema and carried by the registry:
- children:
any(default) ·none·any_except [types] - parent:
any(default) ·must_be_root·must_have_parent_of [types]
A named type covers its subtypes, and a subtype may only tighten its base's rules.
- children:
- Enforcement:
- Every
has_childwrite (create with parent, move, bulk insert, seeding) checks both rules against the resolved type chains, using the type-ancestry table, in the same transaction. - Retyping re-checks both rules.
must_have_parent_ofis also checked on the create path, because the node row is written before its edge.
- Every
- Declarations (ADR-089 §4):
collection,schema,date:must_be_root.ai-chat-message:must_have_parent_of [ai-chat-native, ai-chat-acp],children: none.code-block,ordered-list,horizontal-line,table,query,tool,database-settings:children: none.- The
ai-chatbase:children: any. A non-message child of a chat is its own embedding root. - Everything else:
any/any.
- Replace the
collection/schemaroot triggers,can_have_children()(embedding aggregation asks thechildrenrule) and the frontend'scanBeChild/canHaveChildrenflags. - The UI respects the rules: indent, outdent and drag-and-drop aren't offered where a rule would refuse them.
Architecture Impact
Implements decisions/089-structural-rules-children-and-parent.md (nodespace-docs), which supersedes ADR-059 §2's enforcement mechanism (the rule stands). Uses ADR-086 §5's type-ancestry table.
Acceptance Criteria
- Schemas declare
childrenandparent, the registry carries them, and a subtype can't relax its base's rules (tests) - Every write path (create, move, bulk, seeding, generic relationship create, retype) refuses a violating
has_childedge (tests per path) - A
must_have_parent_oftype created without a qualifying parent is refused before anything is written (test) -
collection,schemaanddateare root-only, including subtypes of them (tests); the old triggers are removed - The leaf types refuse children (tests)
- A non-message child of a chat is embedded as its own root (test)
-
can_have_children()and the frontendcanBeChild/canHaveChildrenflags are gone; the UI's indent/outdent/drag follow the rules (frontend tests) - Follows
development/node-type-sequence.md; thenode-types.mdstructural-rule columns updated in the same PR -
bun run test:changedpasses;bun run quality:fixclean
Technical Specifications
Reference Files
packages/core/src/db/schema.rs(root triggers),packages/core/src/db/sqlite_store/relationships.rspackages/core/src/services/node_service/crud.rs,hierarchy.rs,bulk.rspackages/core/src/behaviors/mod.rs(can_have_children, embedding aggregation)packages/core/src/db/sqlite_store/embedding_roots.rspackages/core/src/models/core_schemas.rs,packages/nodespace-types/src/schema.rspackages/desktop-app/src/lib/plugins/core-plugins.ts,packages/desktop-app/src/lib/plugins/types.ts, and the outline indent/outdent handlers inbase-node-viewer.svelte
Dependencies
- Add the core node type registry, shared envelope, closed schemas and extends-aware rules #3439 (registry and type-ancestry table)
Non-Goals
- How the chat viewer shows non-message children (UI decision)
Activity
malibio commentedon Oct 1, 2026
Baseline — Frontend: 301 test files, 5558 tests passed
Declare and enforce children and parent rules per node type (closes #…
Declare and enforce children and parent rules per node type (closes #…
Declare and enforce children and parent rules per node type (closes #…
malibio commentedon Oct 1, 2026
Landed in #3475. One item from the proposed solution is not in it: the
ai-chat-messagedeclaration (must_have_parent_of [ai-chat-native, ai-chat-acp],children: none). That type is not in the registry yet; the rule mechanism is implemented and tested through user-defined types, and declaring it is a registry entry in the change that adds the message type (#3448).