Repository navigation
Description
Overview
Schema nodes (node_type = 'schema') currently store their human-readable description as a flat string in properties.description. This has two problems:
-
Descriptions are not semantically searchable.
SchemaNodeBehaviordoes not overrideget_embeddable_content, so a schema embeds by itscontent(the name, e.g. "Invoice") alone. The description sitting inpropertiesis ignored by the embedding pipeline. A semantic search for "billing" or "track money owed" cannot find an existing "Invoice" schema — which leads to duplicate near-synonym entity types (e.g.invoiceandbillingcreated as two separate schemas). -
Descriptions cannot be rich. A single
properties.descriptionstring cannot hold structured markdown (headers, lists, code blocks, etc.). NodeSpace models all rich content as a node subtree ("everything is a node"); schema descriptions should follow the same model.
This refactor moves the description out of properties and represents it as a child node subtree of the schema node — authored as full markdown (headers, lists, text, code blocks, …), exactly like any other rich document in NodeSpace. The existing embedding-aggregation machinery (Issue #1018) then folds the whole subtree into the schema's embedding, making schemas semantically discoverable by meaning.
Problem Statement
SchemaNode.description: Stringis parsed fromproperties.description(packages/core/src/models/schema_node.rs).SchemaNodeBehaviorhascan_have_children() == falseand noget_aggregated_content, so schemas are leaf nodes embedded by name only (packages/core/src/behaviors/mod.rs).- The semantic schema retrieval that injects "relevant entity types" into the agent prompt (
packages/core/src/ops/context_ops.rs,semantic_search_nodes_of_type("schema", ...), threshold 0.4) is therefore ineffective — there is no descriptive text in the schema embedding to match against. - Net effect during the A/B test Gemma 4 12B (Q4_K_M) vs E4B for the local ai-chat agent #1329 model trial: the agent cannot reliably tell whether a matching schema already exists before calling
create_schema, so it recreates types and produces near-duplicates.
Proposed Solution
Represent the schema description as a child node subtree (single source of truth — remove properties.description).
-
Behavior (
packages/core/src/behaviors/mod.rs,SchemaNodeBehavior):can_have_children()->true.- Implement
get_aggregated_content()to recursively aggregate child content (reuse the existingaggregate_children_contenthelper used bytext/headerbehaviors). The traversal already recurses through headers/lists/text, so a full markdown subtree is folded into the schema's embedding.
-
Model (
packages/core/src/models/schema_node.rs):- Remove
descriptionfrom thepropertiesround-trip.SchemaNodeno longer carries the description as a plainStringfield (the description is a node subtree fetched on demand, not an inline property).
- Remove
-
Schema creation (
packages/core/src/schema/mod.rs,handle_create_schema):- Stop writing
properties.description. - After creating the schema node, parse the supplied description markdown into a node subtree (via the existing markdown -> nodes pipeline, e.g.
prepare_nodes_from_template/create_nodes_from_markdown) and attach it as children of the schema node.
- Stop writing
-
Schema update (
handle_update_schema/update_schemapath inpackages/core/src/schema/mod.rs):- Editing the description edits the child subtree, not a property.
-
Tool outputs / API:
CreateSchemaOutput/UpdateSchemaOutputand any gRPC/JSON surface that currently returnsdescriptionmust source it from the child subtree (rendered to markdown) instead ofproperties.description.
-
Frontend (
packages/desktop-app):- Wherever the schema description is read/displayed (e.g.
schema-plugin-loader), source it from the child subtree rather thanproperties.description.
- Wherever the schema description is read/displayed (e.g.
-
Backfill / migration:
- One-time migration: for every existing schema node lacking a description subtree, create one from its current
properties.description(treat the existing string as markdown), then re-embed the schema. Applies to seeded core schemas and any user schemas in existing databases.
- One-time migration: for every existing schema node lacking a description subtree, create one from its current
-
Embedding:
- No embedding-service change required — Phase 2 aggregation (
get_aggregated_content) is already invoked by the embedding service after Phase 1; enabling it onSchemaNodeBehavioris sufficient.
- No embedding-service change required — Phase 2 aggregation (
Acceptance Criteria
-
SchemaNodeBehavior::can_have_children()returnstrueandget_aggregated_content()aggregates the full description subtree. -
create_schemastores the description as a markdown node subtree (headers/lists/text/etc.) under the schema node, not inproperties.description. -
update_schemaedits the description subtree. -
properties.descriptionis no longer written or read anywhere for schema nodes (single source of truth). - Tool outputs, gRPC/JSON surfaces, and the desktop UI read the description from the subtree.
- A schema's embedding includes its description text; a semantic search over
node_type='schema'for a synonym (e.g. "billing" -> existing "Invoice" schema) returns the existing schema above threshold. - Migration backfills description subtrees for all existing schemas (including seeded core schemas) and re-embeds them.
- All existing schema tests updated; new tests cover subtree aggregation into the embedding and the synonym-search behavior.
- Code passes
bun run quality:fix. - Tests pass (
bun run test:all).
Technical Specifications
Reference Files
- Schema behavior:
packages/core/src/behaviors/mod.rs—SchemaNodeBehavior(currentlycan_have_children() == false, noget_aggregated_content). Pattern to copy:TextNodeBehavior::get_aggregated_content+aggregate_children_content. - Schema model:
packages/core/src/models/schema_node.rs—SchemaNodestruct;descriptionparsed fromproperties(around theget("description")call). - Schema ops:
packages/core/src/schema/mod.rs—handle_create_schema(writesproperties.description), update path, and theCreateSchemaOutput/ output serialization that returnsdescription. - Prompt context:
packages/core/src/ops/context_ops.rs—build_workspace_context/format_for_prompt(semantic schema retrieval that becomes effective once schemas embed richly). - Markdown -> nodes pipeline: existing
create_nodes_from_markdown/prepare_nodes_from_templatefor building the subtree. - Frontend:
packages/desktop-app/src— schema description display (schema-plugin-loader).
Implementation Notes
- The aggregation traversal (
aggregate_children_content,MAX_AGGREGATION_DEPTH = 20) already recurses through child types thatcan_have_children(), so a full markdown subtree (headers containing lists/text) is captured. - Keep schema validation (field rules, title_template token checks) unchanged — only the description storage changes.
Related Issues
- Refactor embedding service to use NodeBehavior via NodeService for content extraction #1018 (child-content embedding aggregation — the mechanism reused here)
- A/B test Gemma 4 12B (Q4_K_M) vs E4B for the local ai-chat agent #1329 (model A/B trial — surfaced the duplicate-schema problem that motivated this)
- Remove entity type injection from system prompt in favor of on-demand schema discovery #1284 (removed ENTITY TYPES prompt injection in favor of on-demand schema discovery — this refactor makes that discovery semantically reliable)
Non-Goals
- Changing schema field/relationship storage (fields stay in
properties). - Changing the embedding model or the semantic-search threshold tuning.
Activity
malibio commentedon Jun 6, 2026
Design note: reuse the existing root-node subtree mechanism
Schema nodes should be treated as ordinary root nodes with a body — no description-specific storage or fetch logic.
get_subtree_data(node_id)/ markdown-render path (packages/core/src/markdown/mod.rs, also used byget_node(format=markdown)andsearch_ops). Any root node can already be fetched with its full children tree and rendered to markdown; schema descriptions are just that same body. Callers that previously readSchemaNode.descriptionshould fetch+render the subtree instead.get_aggregated_contentwalks the same subtree (Issue Refactor embedding service to use NodeBehavior via NodeService for content extraction #1018), so name + full description body are embedded together.Net: schemas become consistent with prompt nodes and skill nodes (root + children body). The
SchemaNode.description: Stringinline field is removed rather than re-pointed at a property — there is no second source of truth.malibio commentedon Jun 6, 2026
Frontend baseline: 134 passed (3844 tests)
Address code review findings for #1351 schema description subtree
Store schema descriptions as a node subtree (markdown) instead of pro…