Skip to content

QueryNode Behavior and Core Type Definitions #439

Closed

Description

@malibio

Overview

Implement QueryNode as a first-class node type following NodeSpace's current architecture. QueryNode stores query definitions using hub-and-spoke pattern: plain text description in hub (node.content), structured query fields in spoke table.

Architecture References

Problem Statement

NodeSpace needs a way to create, store, and execute queries that filter/search nodes. QueryNodes can be created by AI chat (primary use case) or manually via slash command for testing/development. QueryNode must integrate with the hub-and-spoke SurrealDB architecture using record links and graph edges for relationships.

Implementation Summary

Hub-and-Spoke Storage Pattern

Following TaskNode/SchemaNode pattern:

  • Hub (node.content): Plain text description (e.g., "All open high-priority tasks")
  • Spoke (query table): Structured query fields (filters, sorting, limit, metadata)
  • NOT JSON in content - complex data lives in spoke fields

Core Components Implemented

  1. QueryNodeBehavior (packages/core/src/behaviors/mod.rs) - Validation, embedding exclusion
  2. Query Schema (packages/core/src/models/core_schemas.rs) - 8 fields with indexing
  3. TypeScript Types (packages/desktop-app/src/lib/types/query.ts) - QueryNode, QueryFilter interfaces
  4. Plugin Definition (packages/desktop-app/src/lib/plugins/core-plugins.ts) - Includes /query slash command
  5. Icon Registration (packages/desktop-app/src/lib/design/icons/registry.ts) - Circle with filter symbol
  6. Component (packages/desktop-app/src/lib/components/query-node.svelte) - With "open" button navigation

Slash Command

/query slash command added for manual testing and user-initiated queries:

  • Enables development/testing before full MCP integration
  • Provides value for users who want to manually create saved queries
  • Creates query node with empty content template
  • Command shortcut: 'q'

Acceptance Criteria

  • QueryNodeBehavior implemented and registered in packages/core/src/behaviors/mod.rs
  • Query schema added to get_core_schemas() in packages/core/src/models/core_schemas.rs
  • TypeScript types defined in packages/desktop-app/src/lib/types/query.ts
  • Plugin defined in packages/desktop-app/src/lib/plugins/core-plugins.ts
  • /query slash command registered for manual query creation
  • Icon registered in packages/desktop-app/src/lib/design/icons/registry.ts
  • Hub stores plain text description, spoke stores structured fields
  • Spoke table auto-generated with indexed fields (target_type, generated_by, generator_context)
  • "Open" button for navigation to query viewer
  • Backend tests for behavior validation
  • Frontend tests for plugin registration
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Design Notes

Query vs View Separation:
QueryNode stores ONLY the query definition (what nodes to find). View type and configuration are specified at render time via QueryPreferencesService (#443), enabling:

  • Different users to view same query differently
  • Same query embedded multiple times with different views
  • Future inline embeds: \![[nodespace://query-123|view=table]]

AI Query Ownership:
AI-generated queries use graph edges for hierarchical organization:

  • has_child edge from chat → query establishes parent-child relationship
  • Cascade delete: delete chat → automatically deletes query via edge cleanup
  • Query attribution tracked in query.generated_by field
  • Context tracking via query.generator_context (parent chat ID)

Hybrid Storage Benefits:

  • Spoke table: Fast indexed queries ("show all task queries", "show AI queries")
  • Hub content: Plain text description for semantic search and display
  • Record links: Type-safe references, automatic join optimization
  • Graph edges: Natural parent-child representation, recursive queries

Testing Requirements

  • Backend: Behavior validation tests (valid/invalid patterns)
  • Backend: Schema field definitions correct
  • Frontend: Plugin registration and slash command
  • Frontend: Icon renders correctly
  • Integration: Node can be created via slash command
  • Integration: Node persists and loads from database

Non-Goals

Activity

  1. malibio commented on Dec 2, 2025

    @malibio
    CollaboratorAuthor

    Starting implementation of QueryNode (Issue #439).

    Test Baseline:

    • Frontend: 728 tests passed
    • Rust: All tests passed

    Implementation approach:
    Following TaskNode and SchemaNode patterns for hub-and-spoke architecture with auto-generated spoke table.

  2. self-assigned this
    on Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions