Skip to content

Add the core node type registry, shared envelope, closed schemas and extends-aware rules #3439

Closed

Description

@malibio

Overview

Build the foundation of ADR-086: a CoreNodeType registry, a shared NodeEnvelope, closed core schemas, abstract types, and rules that follow the extends chain instead of comparing node_type with a literal. Every other node-type issue builds on this one.

Problem Statement

  • No single list of types. The seeded schemas (packages/core/src/models/core_schemas.rs), the behaviour registry (packages/core/src/behaviors/mod.rs), the frontend plugins (packages/desktop-app/src/lib/plugins/core-plugins.ts) and the docs each list a different set. play and checkbox have no behaviour; tool has no schema.
  • Schemas don't constrain. Validation checks only declared fields, so any other key is stored, and nested item_fields are never checked.
  • Subtypes escape their base type's rules. Behaviour lookup, embedding, the title rule, the collection/schema root triggers (packages/core/src/db/schema.rs), partial indexes, the @ picker and the wire conversion (node_to_typed_value in packages/nodespace-types/src/convert.rs) compare node_type with a literal. issue extends task is validated and embedded as an unknown custom type, and a pro-collection escapes the root-only rule.
  • The envelope differs per layer. The TS Node has no lifecycleStatus; typed wire structs drop mentions, and some drop title.
  • No abstract types. ai-chat and tool must become abstract bases (ADR-088, ADR-086 §12), and nothing can express "never created directly".
  • Field types. SchemaField.type accepts both string and text.

Proposed Solution

  1. NodeEnvelope in nodespace-types (ADR-086 §2): id, node_type, content, title, version, created_at, modified_at, lifecycle_status (always serialized), properties, mentions, mentioned_in. The generic Node and every typed struct embed it; TypeScript's NodeEnvelope is the base interface.
  2. CoreNodeType registry (ADR-086 §3): one variant per core type, core subtype and abstract base. Each records its category, its parent, whether it is abstract, its content role, structural rules (the slot is filled by the ADR-089 issue), participation rules (the slot is filled by the participation issue), title rules, and its typed struct. Add the registry tests listed in §3.
  3. Chain-aware rules (ADR-086 §5). Rules resolve through the registry or the extends chain, and a subtype behaviour composes with its base's (it adds, never replaces). Remove every literal node_type comparison that applies a type's rule.
  4. Type-ancestry table maintained from schema extends edges in the same transaction as the schema write, so SQL triggers and indexes can apply base-type rules to subtypes.
  5. Abstract types (ADR-086 §6): a schema flag; create and retype into an abstract type are refused in the service; queries for an abstract type return its subtypes.
  6. Closed core schemas (ADR-086 §7). A key in a core type's bucket must be declared, be a namespaced extension field (custom:/org:/plugin:), or start with _. fields/item_fields are validated recursively. Every core behaviour has a schema and vice versa (give tool a schema and play/checkbox behaviours).
  7. Typed-client rejection. The generic update_node from typed clients (Tauri app-lib, dev-proxy) rejects a patch naming a core type's declared field; the CLI's and agent's flat update keeps working through the same validated pipeline.
  8. One field-type vocabulary (ADR-086 §7a): SchemaField.type is a closed enum; text, not string.

No migration: change the shape and reset the database.

Architecture Impact

Implements decisions/086-core-node-types-defined-once-typed-by-category.md §2, §3, §5, §6, §7 and §7a (nodespace-docs). It touches ADR-078 (extends buckets), ADR-082 §2.1 (a behaviour for a core type is rejected; extension subtypes stay open) and ADR-089 (structural rules use the ancestry table). Docs are already committed; keep components/node-types.md in step.

Acceptance Criteria

  • NodeEnvelope exists in nodespace-types; Node and every typed node struct embed it; lifecycle_status is always serialized
  • CoreNodeType covers every core type, core subtype and abstract base, and its registry tests pass: seeded schemas == registry (except schema); behaviour ⇔ schema; primitive ⇔ no fields; exhaustive matching in node_to_typed_value, promoted fields and typed-update dispatch; frontend plugins ⊆ registry
  • Rule resolution follows the extends chain: a user subtype of task is validated and embedded as a task; a subtype of collection is root-only (tests)
  • No literal node_type comparison applies a type's rule in Rust, SQL or TypeScript (a grep-style test or lint enforces it)
  • The type-ancestry table is maintained transactionally with schema writes (test: add and remove extends)
  • Creating or retyping into an abstract type is refused on every surface (test)
  • An undeclared key in a core bucket is rejected; a custom: key and a _ key are accepted; nested item_fields are validated (tests)
  • A typed client's generic update naming a core field is rejected; the CLI's node update --property on the same field succeeds through the pipeline (tests)
  • SchemaField.type is a closed enum; string is rejected
  • Follows development/node-type-sequence.md; the node-types.md sheets updated in the same PR
  • bun run test:changed passes; bun run quality:fix clean
  • The create path rejects a provided id that isn't a UUID, except the three named forms: date (YYYY-MM-DD), schema (the type name) and database-settings-singleton (ADR-086 §10); test per form plus a rejected slug

Technical Specifications

Reference Files

  • packages/nodespace-types/src/lib.rs, node.rs, convert.rs, schema.rs
  • packages/core/src/models/core_schemas.rs, packages/core/src/models/mod.rs
  • packages/core/src/behaviors/mod.rs (NodeBehaviorRegistry)
  • packages/core/src/db/schema.rs (DDL, the root triggers, partial indexes)
  • packages/core/src/services/node_service/crud.rs (rebucket_and_validate, create/update validation)
  • packages/core/src/db/sqlite_store/search.rs (literal type list)
  • packages/desktop-app/app-lib/src/commands/nodes.rs, packages/dev-tools/src/dev-proxy.ts (typed clients)
  • packages/desktop-app/src/lib/types/node.ts, packages/desktop-app/src/lib/plugins/core-plugins.ts

Dependencies

  • None. This is the first of the ADR-086 issues.

Related Issues

Non-Goals

  • Generating TypeScript (separate issue)
  • Structural rules and participation rules themselves (separate issues; this one provides the registry slots and the ancestry table)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions