Repository navigation
Strongly-Typed Node Structs with Direct Spoke Table Deserialization - #685
Conversation
…ttern (closes #673) ## Summary - Refactored TaskNode to use strongly-typed fields instead of wrapping Node - Created new SchemaNode struct for strongly-typed schema access - Added single-query pattern using record links (spoke.node.* for hub fields) - Added get_task_node() and get_schema_node() methods to SurrealStore and NodeService ## Changes **TaskNode (refactored):** - Direct fields: id, content, version, created_at, modified_at, status, priority, due_date, assignee - TaskStatus enum now derives Serialize/Deserialize with snake_case - Builder pattern updated for DateTime<Utc> due_date - from_node() and into_node() for backward compatibility **SchemaNode (new):** - Combines hub fields with spoke-specific fields (is_core, schema_version, description, fields) - get_enum_values(), can_delete_field(), can_modify_field() delegate to SchemaDefinition - from_node(), into_node(), into_definition() for compatibility **Single-Query Pattern:** - SurrealStore.get_task_node() - spoke fields + hub via node.* record link - SurrealStore.get_schema_node() - same pattern for schemas - Documented in surrealdb-schema-design.md as Option 3 (Recommended) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Completed in This Session - [x] Phase 4: Updated MCP handlers to return strongly-typed JSON responses - Added `node_to_typed_value()` and `nodes_to_typed_values()` helper functions - Updated `handle_get_node()` to convert task/schema nodes to typed structs - Updated `handle_query_nodes()` to convert node lists to typed values - Updated `handle_get_nodes_batch()` to convert nodes to typed values - [x] Updated serialization to use camelCase for JSON consistency - Changed TaskNode and SchemaNode from snake_case to camelCase - Matches Node struct convention for consistent API - [x] Added comprehensive tests for typed responses - 4 new tests verifying TaskNode/SchemaNode/Node response formats - All 41 MCP handler tests passing - [x] Fixed tests to match camelCase JSON format - Updated task_node_test.rs serde tests - Updated schema_node.rs serde tests ## Remaining Work - [ ] Phase 5: Behavior integration - TaskNodeBehavior should validate TaskNode directly - [ ] Phase 6: Fix get_node() to use FETCH data for single query efficiency ## Current State - Files modified: - packages/core/src/mcp/handlers/nodes.rs (typed conversion helpers) - packages/core/src/mcp/handlers/nodes_test.rs (+4 typed response tests) - packages/core/src/models/task_node.rs (camelCase serialization) - packages/core/src/models/schema_node.rs (camelCase serialization) - packages/core/src/models/task_node_test.rs (fixed serde tests) - Tests status: All 548 tests passing, no clippy warnings - Known issues: None - current functionality working ## Context for Next Session MCP handlers now return strongly-typed TaskNode/SchemaNode for task/schema types, providing direct field access (status, priority, isCore) instead of nesting in properties. Simple types (text, header) continue to use generic Node. The key remaining work is Phase 5 (behavior validation) and Phase 6 (single-query efficiency using FETCH data). ## Acceptance Criteria Status From issue #673: - [x] TaskNode struct with direct fields (id, content, status, priority, etc.) - [x] SchemaNode struct with direct fields (id, content, isCore, fields, etc.) - [x] get_task_node() method in NodeService (single-query) - [x] get_schema_node() method in NodeService (single-query) - [x] MCP handlers return typed structs (Phase 4 ✅) - [ ] Behavior integration (Phase 5) - [ ] get_node() efficiency fix (Phase 6) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Phase 5: Behavior Integration - Add `validate_task_node()` to TaskNodeBehavior for strongly-typed validation - Add `validate_schema_node()` to SchemaNodeBehavior for strongly-typed validation - Update `validate()` methods to convert Node → typed struct internally - Priority validation now checks 1-4 range (type-safe i32 field) - Fallback to property validation if typed conversion fails (backward compat) ## Phase 6: Documentation (Deferred Implementation) - Document FETCH data limitation in get_node() (blocked by Issue #511) - SurrealDB Thing type cannot deserialize to serde_json::Value - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency with spoke table types ## TaskNode::from_node() Improvements - Handle both nested (properties.task.*) and flat (properties.*) formats - Support string priority conversion ("high" → 2, "low" → 4, etc.) - Consistent with Issue #397 type-namespaced properties ## New Tests - test_task_node_behavior_validate_task_node: Priority range validation - test_schema_node_behavior_validate_schema_node: Content validation - test_task_node_from_node_nested_format: Nested property extraction - test_task_node_from_node_flat_format: Backward compatibility - test_task_node_from_node_string_priority: String→int conversion - Updated test_task_node_behavior_validation with range tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…re comments Issue #511 (SurrealDB Schema Refactor) is closed and its architecture is now the established pattern. Updated comments to reflect current state: - Simplified SurrealNode.data field documentation - Removed "FETCH data limitation" explanation (no longer relevant) - Updated get_node() comment to describe the 2-query pattern as intentional - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency The hub-spoke architecture with strongly-typed methods is the solution, not a workaround for a blocking issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Changed from 2 sequential queries to 1 multi-statement query: - Hub query: SELECT * FROM node:`id` - Task spoke: SELECT * OMIT id, node FROM task:`id` - Schema spoke: SELECT * OMIT id, node FROM schema:`id` All 3 statements execute in a single database round-trip. The spoke queries return empty results for non-matching types, and we merge based on node_type. Benefits: - Single network round-trip instead of 2 sequential queries - Simpler code with clearer intent - Same correctness - OMIT excludes Thing-typed fields that can't deserialize For compile-time type safety with strongly-typed returns, use: - get_task_node(id) → TaskNode - get_schema_node(id) → SchemaNode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Instead of hardcoding spoke table types, get_node() now uses the hub's
`data` field to determine if a spoke exists:
```sql
LET $hub = (SELECT * FROM node:`{id}`)[0];
LET $spoke = IF $hub.data != NONE THEN
(SELECT * OMIT id, node FROM $hub.data)[0]
ELSE
NONE
END;
RETURN { hub: $hub, spoke: $spoke };
```
Benefits:
- Single round-trip query
- Automatically works for any node type (core or user-defined)
- No hardcoded type list in get_node()
- Prepares for user-defined custom node types with spoke tables
Note: TYPES_WITH_SPOKE_TABLES constant still used elsewhere (create, update,
type switching). Full removal requires schema-driven type system refactor.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
## Changes - Remove LET/IF/RETURN single-query pattern from get_node() - Use simple two-query approach: hub first, then spoke if needed - Remove unused HubSpokeResult struct ## Rationale For embedded SurrealDB (RocksDB), the second query is an in-process call with ~microsecond overhead. The two-query approach: 1. **Scales automatically** - No code changes needed for new spoke types 2. **More maintainable** - No IF/ELSE chain enumerating all types 3. **Same performance** - In-process calls are negligible Single-query alternatives were investigated but rejected: - `FETCH data` fails because Thing types can't deserialize to serde_json::Value - `LET/IF/RETURN` requires enumerating all spoke types in the query For compile-time type safety, use get_task_node() or get_schema_node() which already use single-query spoke-first pattern. Closes #673 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review: PR #685 - Strongly-Typed Node Structs with Direct Spoke Table DeserializationReview Type: Initial Review Executive SummaryThis PR implements strongly-typed node structs (TaskNode, SchemaNode) that deserialize directly from spoke tables, eliminating the intermediate JSON properties step. The architectural approach is sound and aligns with the issue requirements. However, there is one critical regression that must be addressed before merging. Requirements Validation (Issue #673)
FindingsCritical Issues🔴 [Critical/Blocker] Test Regression: sibling_queue test failsLocation: `packages/core/src/operations/sibling_queue.rs:420` The test `test_reorder_with_retry_max_retries_exceeded` passes on `main` but fails on this branch. Error: Root Cause Analysis: The `get_node()` refactoring in `surreal_store.rs` changed how node data is retrieved. The new two-query approach may have altered timing characteristics or error propagation behavior, causing a race condition in the OCC (Optimistic Concurrency Control) test to manifest differently. The test expects either `Ok(_)` or `Err(NodeServiceError::VersionConflict { .. })`, but receives a different error type: `QueryFailed` wrapped error. Impact: This is a regression that could affect concurrent update scenarios in production. Recommendation:
Suggested Improvements🟡 [Improvement] Duplicated helper functions between modulesLocation:
Both modules define identical `default_version()` helper functions. Consider consolidating into a shared utility. Engineering Principle: DRY (Don't Repeat Yourself) - reduces maintenance burden. 🟡 [Improvement] Inconsistent assignee field extractionLocation: `packages/core/src/models/task_node.rs:243-247` ```rust While backward compatibility is good, consider documenting which field name is canonical. The struct field is `assignee`, but `from_node` prefers `assignee_id`, and `into_node` writes `assignee`. This could lead to confusion. Recommendation: Add a comment explaining the backward-compat behavior and consider normalizing to a single field name during serialization/deserialization. 🟡 [Improvement] Manual JSON parsing in get_node() is error-proneLocation: `packages/core/src/db/surreal_store.rs:1231-1306` The new `get_node()` implementation manually parses JSON values (created_at, modified_at, etc.) with fallbacks: ```rust Concern: Silent fallback to `Utc::now()` on parse failure could mask data corruption issues. This differs from the previous `SurrealNode` deserialization which would surface errors. Recommendation: Consider logging warnings when fallbacks are used, or document why silent fallbacks are acceptable for this use case. NitpicksNit: `packages/core/src/behaviors/mod.rs:499`The `validate_task_node` docstring example uses `build()` but doesn't show the import path for TaskStatus, which could confuse readers unfamiliar with the crate structure. Nit: `packages/core/src/mcp/handlers/nodes.rs:23-40`The `node_to_typed_value` helper is well-structured. Consider adding a comment explaining why it converts via `from_node` rather than using the pre-existing typed retrieval methods (`get_task_node`, etc.) - this appears intentional for efficiency when the Node is already loaded. Architectural AssessmentStrengths
Design Decision AcknowledgmentThe two-query approach for generic `get_node()` is well-justified in the commit message and issue:
This trade-off prioritizes maintainability (no hardcoded type enumeration) over micro-optimization. Final Recommendation❌ REQUEST CHANGES This PR introduces valuable architectural improvements that align with the strongly-typed design goals. However, the test regression must be resolved before merge:
Once the test regression is resolved and all tests pass, this PR is ready to merge. 🤖 Generated with Claude Code |
- Add warning logs for missing/invalid timestamps in get_node() to help diagnose potential data corruption (surreal_store.rs) - Document the assignee field backward compatibility behavior in TaskNode::from_node() to explain why both field names are supported - Add implementation note to node_to_typed_value() explaining why from_node() is used instead of typed retrieval methods Reviewer suggestions addressed: - [Important] Silent fallbacks now log warnings for timestamps - [Important] Assignee field inconsistency documented - [Nit] node_to_typed_value helper now explains design decision Skipped (with justification): - [Important] Duplicated default_version() helpers - These are trivial one-line serde default functions. Consolidating would require adding public exports and changing serde attribute paths across files for minimal DRY benefit. The maintenance cost exceeds the value. - [Nit] validate_task_node docstring import path - Minimal value, the example code is clear enough without full import paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback AddressedSummary
Changes Made
Verification
Skipped Recommendations (Justification)Duplicated
🤖 Generated with Claude Code |
TaskStatus enum now supports user-defined values via User(String) variant,
aligning with the schema system's core_values/user_values model.
Changes:
- Add User(String) variant to TaskStatus for schema-extended statuses
- Remove Copy trait (User variant contains String)
- Add is_core() and is_user_defined() helper methods
- Implement custom Serialize/Deserialize for string-based storage
- Update from_str to accept any value (core or user-defined)
- Update tests to reflect new behavior
This ensures strongly-typed nodes don't block schema extensibility:
- Core statuses (open, in_progress, done, cancelled) get compile-time safety
- User-extended statuses are stored as User("blocked"), User("review"), etc.
- Runtime validation against schema still applies via validate_node_against_schema
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Additional Change: User-Defined Task Status SupportAdded support for user-defined task statuses via schema extensibility. What Changed
pub enum TaskStatus {
Open, // Core
InProgress, // Core
Done, // Core
Cancelled, // Core
User(String), // User-defined (e.g., "blocked", "review")
}WhyThe original implementation used a closed enum that would reject any status not in the predefined list. This blocked the schema system's How It Works
Tests
🤖 Generated with Claude Code |
) Updated all node-returning endpoints to use strongly-typed structs (TaskNode, SchemaNode) via node_to_typed_value() helper, matching the MCP handler implementation. Tauri commands updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - get_nodes_by_root_id() -> returns Vec<typed Value> - query_nodes_simple() -> returns Vec<typed Value> - mention_autocomplete() -> returns Vec<typed Value> Dev-proxy (HTTP adapter) updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - query_nodes() -> returns Vec<typed Value> This completes the Issue #673 requirement to integrate typed structs throughout the entire stack (MCP handlers, behaviors, Tauri commands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Tauri & Dev-Proxy Integration Complete (Issue #673)Per the issue requirements, typed node structs are now integrated throughout the entire stack: Updated Entry Points
Tauri Commands Updated
Dev-Proxy (HTTP Adapter) Updated
How It WorksBoth layers now use
This ensures frontends receive properly structured JSON:
🤖 Generated with Claude Code |
Code Review: PR #685 - Re-ReviewReview Type: Re-Review Previous Review Summary
All blocking issues have been resolved. The skipped items have valid justification. New Changes AssessmentCommit:
|
| Acceptance Criterion | Status |
|---|---|
| TaskNode struct with strongly-typed fields | ✅ PASS |
| SchemaNode struct with strongly-typed fields | ✅ PASS |
| Single-query pattern using spoke table with hub record link | ✅ PASS |
get_task_node() method returning TaskNode directly |
✅ PASS |
get_schema_node() method returning SchemaNode directly |
✅ PASS |
Existing get_node() preserved for generic/unknown types |
✅ PASS |
| Update architecture documentation | ✅ PASS |
| MCP handlers return typed structs for task/schema types | ✅ PASS |
| TaskNodeBehavior validates TaskNode directly | ✅ PASS |
| All existing tests pass | ✅ PASS (537 tests) |
| Code passes quality:fix | ✅ PASS (cargo clippy clean) |
| Tests pass (cargo test --lib) | ✅ PASS |
| Tauri commands return typed structs | ✅ NEW - PASS |
| Dev-proxy returns typed JSON | ✅ NEW - PASS |
All acceptance criteria met.
Test Verification
test result: ok. 537 passed; 0 failed; 16 ignored; 0 measured; 0 filtered out
cargo clippy -- -D warnings: Clean (no warnings)
cargo check (Tauri): Success
Final Recommendation
✅ APPROVE
This PR is ready to merge. All previous blocking issues have been addressed:
- Test regression resolved - sibling_queue test passes consistently
- Review feedback addressed - Logging, documentation, and comments added
- New features well-designed - User-defined task statuses integrate cleanly
- Full stack integration complete - Tauri and dev-proxy return typed responses
- All tests passing - 537 tests, clean clippy
The code duplication in node_to_typed_value across three locations is noted as minor tech debt but is not blocking given the straightforward logic and different error type requirements at each layer.
🤖 Generated with Claude Code
Removes code duplication by creating a single canonical implementation of node_to_typed_value in nodespace_core::models, which all entry points (MCP handlers, Tauri commands, dev-proxy) now delegate to. Changes: - Add node_to_typed_value() and nodes_to_typed_values() to models/mod.rs - Simplify MCP handlers to delegate with MCPError mapping - Simplify Tauri commands to delegate with CommandError mapping - Simplify dev-proxy to delegate with ApiError mapping This reduces 86 lines to 64 and ensures consistent behavior across all API surfaces (Issue #673). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Duplication AddressedConsolidated Changes
Impact
Commit: ba6529a |
Resolved conflicts between PR #692 (schema simplification) and PR #685 (strongly-typed node structs): Architecture decisions (per user requirements): - Keep flat struct pattern for direct spoke table deserialization (performance) - Single-query pattern (one DB call, not two) - EnumValue struct with labels from PR #692 - Comprehensive schema validation in SchemaNodeBehavior Conflict resolutions: - schema_node.rs: Flat struct with direct deserialization + EnumValue support - behaviors/mod.rs: Combined validation from both PRs - surreal_store.rs: Kept single-query pattern, removed duplicate two-query functions - node_service.rs: Documentation cleanup - task_node.rs: Fixed imports, removed conflicting custom Serialize impl - MCP handlers: Fixed imports, removed SchemaService - Tauri commands: Fixed imports - dev-proxy.rs: Fixed models import 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…685) * Implement strongly-typed TaskNode and SchemaNode with single-query pattern (closes #673) ## Summary - Refactored TaskNode to use strongly-typed fields instead of wrapping Node - Created new SchemaNode struct for strongly-typed schema access - Added single-query pattern using record links (spoke.node.* for hub fields) - Added get_task_node() and get_schema_node() methods to SurrealStore and NodeService ## Changes **TaskNode (refactored):** - Direct fields: id, content, version, created_at, modified_at, status, priority, due_date, assignee - TaskStatus enum now derives Serialize/Deserialize with snake_case - Builder pattern updated for DateTime<Utc> due_date - from_node() and into_node() for backward compatibility **SchemaNode (new):** - Combines hub fields with spoke-specific fields (is_core, schema_version, description, fields) - get_enum_values(), can_delete_field(), can_modify_field() delegate to SchemaDefinition - from_node(), into_node(), into_definition() for compatibility **Single-Query Pattern:** - SurrealStore.get_task_node() - spoke fields + hub via node.* record link - SurrealStore.get_schema_node() - same pattern for schemas - Documented in surrealdb-schema-design.md as Option 3 (Recommended) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Phase 4 complete - MCP handlers return typed structs ## Completed in This Session - [x] Phase 4: Updated MCP handlers to return strongly-typed JSON responses - Added `node_to_typed_value()` and `nodes_to_typed_values()` helper functions - Updated `handle_get_node()` to convert task/schema nodes to typed structs - Updated `handle_query_nodes()` to convert node lists to typed values - Updated `handle_get_nodes_batch()` to convert nodes to typed values - [x] Updated serialization to use camelCase for JSON consistency - Changed TaskNode and SchemaNode from snake_case to camelCase - Matches Node struct convention for consistent API - [x] Added comprehensive tests for typed responses - 4 new tests verifying TaskNode/SchemaNode/Node response formats - All 41 MCP handler tests passing - [x] Fixed tests to match camelCase JSON format - Updated task_node_test.rs serde tests - Updated schema_node.rs serde tests ## Remaining Work - [ ] Phase 5: Behavior integration - TaskNodeBehavior should validate TaskNode directly - [ ] Phase 6: Fix get_node() to use FETCH data for single query efficiency ## Current State - Files modified: - packages/core/src/mcp/handlers/nodes.rs (typed conversion helpers) - packages/core/src/mcp/handlers/nodes_test.rs (+4 typed response tests) - packages/core/src/models/task_node.rs (camelCase serialization) - packages/core/src/models/schema_node.rs (camelCase serialization) - packages/core/src/models/task_node_test.rs (fixed serde tests) - Tests status: All 548 tests passing, no clippy warnings - Known issues: None - current functionality working ## Context for Next Session MCP handlers now return strongly-typed TaskNode/SchemaNode for task/schema types, providing direct field access (status, priority, isCore) instead of nesting in properties. Simple types (text, header) continue to use generic Node. The key remaining work is Phase 5 (behavior validation) and Phase 6 (single-query efficiency using FETCH data). ## Acceptance Criteria Status From issue #673: - [x] TaskNode struct with direct fields (id, content, status, priority, etc.) - [x] SchemaNode struct with direct fields (id, content, isCore, fields, etc.) - [x] get_task_node() method in NodeService (single-query) - [x] get_schema_node() method in NodeService (single-query) - [x] MCP handlers return typed structs (Phase 4 ✅) - [ ] Behavior integration (Phase 5) - [ ] get_node() efficiency fix (Phase 6) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement strongly-typed behavior validation (Issue #673 Phases 5-6) ## Phase 5: Behavior Integration - Add `validate_task_node()` to TaskNodeBehavior for strongly-typed validation - Add `validate_schema_node()` to SchemaNodeBehavior for strongly-typed validation - Update `validate()` methods to convert Node → typed struct internally - Priority validation now checks 1-4 range (type-safe i32 field) - Fallback to property validation if typed conversion fails (backward compat) ## Phase 6: Documentation (Deferred Implementation) - Document FETCH data limitation in get_node() (blocked by Issue #511) - SurrealDB Thing type cannot deserialize to serde_json::Value - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency with spoke table types ## TaskNode::from_node() Improvements - Handle both nested (properties.task.*) and flat (properties.*) formats - Support string priority conversion ("high" → 2, "low" → 4, etc.) - Consistent with Issue #397 type-namespaced properties ## New Tests - test_task_node_behavior_validate_task_node: Priority range validation - test_schema_node_behavior_validate_schema_node: Content validation - test_task_node_from_node_nested_format: Nested property extraction - test_task_node_from_node_flat_format: Backward compatibility - test_task_node_from_node_string_priority: String→int conversion - Updated test_task_node_behavior_validation with range tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Remove outdated Issue #511 references from hub-spoke architecture comments Issue #511 (SurrealDB Schema Refactor) is closed and its architecture is now the established pattern. Updated comments to reflect current state: - Simplified SurrealNode.data field documentation - Removed "FETCH data limitation" explanation (no longer relevant) - Updated get_node() comment to describe the 2-query pattern as intentional - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency The hub-spoke architecture with strongly-typed methods is the solution, not a workaround for a blocking issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Optimize get_node() to single round-trip query (Issue #673 Phase 6) Changed from 2 sequential queries to 1 multi-statement query: - Hub query: SELECT * FROM node:`id` - Task spoke: SELECT * OMIT id, node FROM task:`id` - Schema spoke: SELECT * OMIT id, node FROM schema:`id` All 3 statements execute in a single database round-trip. The spoke queries return empty results for non-matching types, and we merge based on node_type. Benefits: - Single network round-trip instead of 2 sequential queries - Simpler code with clearer intent - Same correctness - OMIT excludes Thing-typed fields that can't deserialize For compile-time type safety with strongly-typed returns, use: - get_task_node(id) → TaskNode - get_schema_node(id) → SchemaNode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor get_node() to use dynamic spoke detection via data field Instead of hardcoding spoke table types, get_node() now uses the hub's `data` field to determine if a spoke exists: ```sql LET $hub = (SELECT * FROM node:`{id}`)[0]; LET $spoke = IF $hub.data != NONE THEN (SELECT * OMIT id, node FROM $hub.data)[0] ELSE NONE END; RETURN { hub: $hub, spoke: $spoke }; ``` Benefits: - Single round-trip query - Automatically works for any node type (core or user-defined) - No hardcoded type list in get_node() - Prepares for user-defined custom node types with spoke tables Note: TYPES_WITH_SPOKE_TABLES constant still used elsewhere (create, update, type switching). Full removal requires schema-driven type system refactor. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Simplify get_node() to two-query approach for maintainability ## Changes - Remove LET/IF/RETURN single-query pattern from get_node() - Use simple two-query approach: hub first, then spoke if needed - Remove unused HubSpokeResult struct ## Rationale For embedded SurrealDB (RocksDB), the second query is an in-process call with ~microsecond overhead. The two-query approach: 1. **Scales automatically** - No code changes needed for new spoke types 2. **More maintainable** - No IF/ELSE chain enumerating all types 3. **Same performance** - In-process calls are negligible Single-query alternatives were investigated but rejected: - `FETCH data` fails because Thing types can't deserialize to serde_json::Value - `LET/IF/RETURN` requires enumerating all spoke types in the query For compile-time type safety, use get_task_node() or get_schema_node() which already use single-query spoke-first pattern. Closes #673 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback from PR #685 - Add warning logs for missing/invalid timestamps in get_node() to help diagnose potential data corruption (surreal_store.rs) - Document the assignee field backward compatibility behavior in TaskNode::from_node() to explain why both field names are supported - Add implementation note to node_to_typed_value() explaining why from_node() is used instead of typed retrieval methods Reviewer suggestions addressed: - [Important] Silent fallbacks now log warnings for timestamps - [Important] Assignee field inconsistency documented - [Nit] node_to_typed_value helper now explains design decision Skipped (with justification): - [Important] Duplicated default_version() helpers - These are trivial one-line serde default functions. Consolidating would require adding public exports and changing serde attribute paths across files for minimal DRY benefit. The maintenance cost exceeds the value. - [Nit] validate_task_node docstring import path - Minimal value, the example code is clear enough without full import paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Support user-defined task statuses via schema extensibility TaskStatus enum now supports user-defined values via User(String) variant, aligning with the schema system's core_values/user_values model. Changes: - Add User(String) variant to TaskStatus for schema-extended statuses - Remove Copy trait (User variant contains String) - Add is_core() and is_user_defined() helper methods - Implement custom Serialize/Deserialize for string-based storage - Update from_str to accept any value (core or user-defined) - Update tests to reflect new behavior This ensures strongly-typed nodes don't block schema extensibility: - Core statuses (open, in_progress, done, cancelled) get compile-time safety - User-extended statuses are stored as User("blocked"), User("review"), etc. - Runtime validation against schema still applies via validate_node_against_schema 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Integrate typed node structs in Tauri commands and dev-proxy (Issue #673) Updated all node-returning endpoints to use strongly-typed structs (TaskNode, SchemaNode) via node_to_typed_value() helper, matching the MCP handler implementation. Tauri commands updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - get_nodes_by_root_id() -> returns Vec<typed Value> - query_nodes_simple() -> returns Vec<typed Value> - mention_autocomplete() -> returns Vec<typed Value> Dev-proxy (HTTP adapter) updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - query_nodes() -> returns Vec<typed Value> This completes the Issue #673 requirement to integrate typed structs throughout the entire stack (MCP handlers, behaviors, Tauri commands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Consolidate node_to_typed_value into canonical implementation Removes code duplication by creating a single canonical implementation of node_to_typed_value in nodespace_core::models, which all entry points (MCP handlers, Tauri commands, dev-proxy) now delegate to. Changes: - Add node_to_typed_value() and nodes_to_typed_values() to models/mod.rs - Simplify MCP handlers to delegate with MCPError mapping - Simplify Tauri commands to delegate with CommandError mapping - Simplify dev-proxy to delegate with ApiError mapping This reduces 86 lines to 64 and ensures consistent behavior across all API surfaces (Issue #673). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…685) * Implement strongly-typed TaskNode and SchemaNode with single-query pattern (closes #673) ## Summary - Refactored TaskNode to use strongly-typed fields instead of wrapping Node - Created new SchemaNode struct for strongly-typed schema access - Added single-query pattern using record links (spoke.node.* for hub fields) - Added get_task_node() and get_schema_node() methods to SurrealStore and NodeService ## Changes **TaskNode (refactored):** - Direct fields: id, content, version, created_at, modified_at, status, priority, due_date, assignee - TaskStatus enum now derives Serialize/Deserialize with snake_case - Builder pattern updated for DateTime<Utc> due_date - from_node() and into_node() for backward compatibility **SchemaNode (new):** - Combines hub fields with spoke-specific fields (is_core, schema_version, description, fields) - get_enum_values(), can_delete_field(), can_modify_field() delegate to SchemaDefinition - from_node(), into_node(), into_definition() for compatibility **Single-Query Pattern:** - SurrealStore.get_task_node() - spoke fields + hub via node.* record link - SurrealStore.get_schema_node() - same pattern for schemas - Documented in surrealdb-schema-design.md as Option 3 (Recommended) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Phase 4 complete - MCP handlers return typed structs ## Completed in This Session - [x] Phase 4: Updated MCP handlers to return strongly-typed JSON responses - Added `node_to_typed_value()` and `nodes_to_typed_values()` helper functions - Updated `handle_get_node()` to convert task/schema nodes to typed structs - Updated `handle_query_nodes()` to convert node lists to typed values - Updated `handle_get_nodes_batch()` to convert nodes to typed values - [x] Updated serialization to use camelCase for JSON consistency - Changed TaskNode and SchemaNode from snake_case to camelCase - Matches Node struct convention for consistent API - [x] Added comprehensive tests for typed responses - 4 new tests verifying TaskNode/SchemaNode/Node response formats - All 41 MCP handler tests passing - [x] Fixed tests to match camelCase JSON format - Updated task_node_test.rs serde tests - Updated schema_node.rs serde tests ## Remaining Work - [ ] Phase 5: Behavior integration - TaskNodeBehavior should validate TaskNode directly - [ ] Phase 6: Fix get_node() to use FETCH data for single query efficiency ## Current State - Files modified: - packages/core/src/mcp/handlers/nodes.rs (typed conversion helpers) - packages/core/src/mcp/handlers/nodes_test.rs (+4 typed response tests) - packages/core/src/models/task_node.rs (camelCase serialization) - packages/core/src/models/schema_node.rs (camelCase serialization) - packages/core/src/models/task_node_test.rs (fixed serde tests) - Tests status: All 548 tests passing, no clippy warnings - Known issues: None - current functionality working ## Context for Next Session MCP handlers now return strongly-typed TaskNode/SchemaNode for task/schema types, providing direct field access (status, priority, isCore) instead of nesting in properties. Simple types (text, header) continue to use generic Node. The key remaining work is Phase 5 (behavior validation) and Phase 6 (single-query efficiency using FETCH data). ## Acceptance Criteria Status From issue #673: - [x] TaskNode struct with direct fields (id, content, status, priority, etc.) - [x] SchemaNode struct with direct fields (id, content, isCore, fields, etc.) - [x] get_task_node() method in NodeService (single-query) - [x] get_schema_node() method in NodeService (single-query) - [x] MCP handlers return typed structs (Phase 4 ✅) - [ ] Behavior integration (Phase 5) - [ ] get_node() efficiency fix (Phase 6) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement strongly-typed behavior validation (Issue #673 Phases 5-6) ## Phase 5: Behavior Integration - Add `validate_task_node()` to TaskNodeBehavior for strongly-typed validation - Add `validate_schema_node()` to SchemaNodeBehavior for strongly-typed validation - Update `validate()` methods to convert Node → typed struct internally - Priority validation now checks 1-4 range (type-safe i32 field) - Fallback to property validation if typed conversion fails (backward compat) ## Phase 6: Documentation (Deferred Implementation) - Document FETCH data limitation in get_node() (blocked by Issue #511) - SurrealDB Thing type cannot deserialize to serde_json::Value - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency with spoke table types ## TaskNode::from_node() Improvements - Handle both nested (properties.task.*) and flat (properties.*) formats - Support string priority conversion ("high" → 2, "low" → 4, etc.) - Consistent with Issue #397 type-namespaced properties ## New Tests - test_task_node_behavior_validate_task_node: Priority range validation - test_schema_node_behavior_validate_schema_node: Content validation - test_task_node_from_node_nested_format: Nested property extraction - test_task_node_from_node_flat_format: Backward compatibility - test_task_node_from_node_string_priority: String→int conversion - Updated test_task_node_behavior_validation with range tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Remove outdated Issue #511 references from hub-spoke architecture comments Issue #511 (SurrealDB Schema Refactor) is closed and its architecture is now the established pattern. Updated comments to reflect current state: - Simplified SurrealNode.data field documentation - Removed "FETCH data limitation" explanation (no longer relevant) - Updated get_node() comment to describe the 2-query pattern as intentional - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency The hub-spoke architecture with strongly-typed methods is the solution, not a workaround for a blocking issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Optimize get_node() to single round-trip query (Issue #673 Phase 6) Changed from 2 sequential queries to 1 multi-statement query: - Hub query: SELECT * FROM node:`id` - Task spoke: SELECT * OMIT id, node FROM task:`id` - Schema spoke: SELECT * OMIT id, node FROM schema:`id` All 3 statements execute in a single database round-trip. The spoke queries return empty results for non-matching types, and we merge based on node_type. Benefits: - Single network round-trip instead of 2 sequential queries - Simpler code with clearer intent - Same correctness - OMIT excludes Thing-typed fields that can't deserialize For compile-time type safety with strongly-typed returns, use: - get_task_node(id) → TaskNode - get_schema_node(id) → SchemaNode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor get_node() to use dynamic spoke detection via data field Instead of hardcoding spoke table types, get_node() now uses the hub's `data` field to determine if a spoke exists: ```sql LET $hub = (SELECT * FROM node:`{id}`)[0]; LET $spoke = IF $hub.data != NONE THEN (SELECT * OMIT id, node FROM $hub.data)[0] ELSE NONE END; RETURN { hub: $hub, spoke: $spoke }; ``` Benefits: - Single round-trip query - Automatically works for any node type (core or user-defined) - No hardcoded type list in get_node() - Prepares for user-defined custom node types with spoke tables Note: TYPES_WITH_SPOKE_TABLES constant still used elsewhere (create, update, type switching). Full removal requires schema-driven type system refactor. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Simplify get_node() to two-query approach for maintainability ## Changes - Remove LET/IF/RETURN single-query pattern from get_node() - Use simple two-query approach: hub first, then spoke if needed - Remove unused HubSpokeResult struct ## Rationale For embedded SurrealDB (RocksDB), the second query is an in-process call with ~microsecond overhead. The two-query approach: 1. **Scales automatically** - No code changes needed for new spoke types 2. **More maintainable** - No IF/ELSE chain enumerating all types 3. **Same performance** - In-process calls are negligible Single-query alternatives were investigated but rejected: - `FETCH data` fails because Thing types can't deserialize to serde_json::Value - `LET/IF/RETURN` requires enumerating all spoke types in the query For compile-time type safety, use get_task_node() or get_schema_node() which already use single-query spoke-first pattern. Closes #673 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback from PR #685 - Add warning logs for missing/invalid timestamps in get_node() to help diagnose potential data corruption (surreal_store.rs) - Document the assignee field backward compatibility behavior in TaskNode::from_node() to explain why both field names are supported - Add implementation note to node_to_typed_value() explaining why from_node() is used instead of typed retrieval methods Reviewer suggestions addressed: - [Important] Silent fallbacks now log warnings for timestamps - [Important] Assignee field inconsistency documented - [Nit] node_to_typed_value helper now explains design decision Skipped (with justification): - [Important] Duplicated default_version() helpers - These are trivial one-line serde default functions. Consolidating would require adding public exports and changing serde attribute paths across files for minimal DRY benefit. The maintenance cost exceeds the value. - [Nit] validate_task_node docstring import path - Minimal value, the example code is clear enough without full import paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Support user-defined task statuses via schema extensibility TaskStatus enum now supports user-defined values via User(String) variant, aligning with the schema system's core_values/user_values model. Changes: - Add User(String) variant to TaskStatus for schema-extended statuses - Remove Copy trait (User variant contains String) - Add is_core() and is_user_defined() helper methods - Implement custom Serialize/Deserialize for string-based storage - Update from_str to accept any value (core or user-defined) - Update tests to reflect new behavior This ensures strongly-typed nodes don't block schema extensibility: - Core statuses (open, in_progress, done, cancelled) get compile-time safety - User-extended statuses are stored as User("blocked"), User("review"), etc. - Runtime validation against schema still applies via validate_node_against_schema 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Integrate typed node structs in Tauri commands and dev-proxy (Issue #673) Updated all node-returning endpoints to use strongly-typed structs (TaskNode, SchemaNode) via node_to_typed_value() helper, matching the MCP handler implementation. Tauri commands updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - get_nodes_by_root_id() -> returns Vec<typed Value> - query_nodes_simple() -> returns Vec<typed Value> - mention_autocomplete() -> returns Vec<typed Value> Dev-proxy (HTTP adapter) updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - query_nodes() -> returns Vec<typed Value> This completes the Issue #673 requirement to integrate typed structs throughout the entire stack (MCP handlers, behaviors, Tauri commands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Consolidate node_to_typed_value into canonical implementation Removes code duplication by creating a single canonical implementation of node_to_typed_value in nodespace_core::models, which all entry points (MCP handlers, Tauri commands, dev-proxy) now delegate to. Changes: - Add node_to_typed_value() and nodes_to_typed_values() to models/mod.rs - Simplify MCP handlers to delegate with MCPError mapping - Simplify Tauri commands to delegate with CommandError mapping - Simplify dev-proxy to delegate with ApiError mapping This reduces 86 lines to 64 and ensures consistent behavior across all API surfaces (Issue #673). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…685) * Implement strongly-typed TaskNode and SchemaNode with single-query pattern (closes #673) ## Summary - Refactored TaskNode to use strongly-typed fields instead of wrapping Node - Created new SchemaNode struct for strongly-typed schema access - Added single-query pattern using record links (spoke.node.* for hub fields) - Added get_task_node() and get_schema_node() methods to SurrealStore and NodeService ## Changes **TaskNode (refactored):** - Direct fields: id, content, version, created_at, modified_at, status, priority, due_date, assignee - TaskStatus enum now derives Serialize/Deserialize with snake_case - Builder pattern updated for DateTime<Utc> due_date - from_node() and into_node() for backward compatibility **SchemaNode (new):** - Combines hub fields with spoke-specific fields (is_core, schema_version, description, fields) - get_enum_values(), can_delete_field(), can_modify_field() delegate to SchemaDefinition - from_node(), into_node(), into_definition() for compatibility **Single-Query Pattern:** - SurrealStore.get_task_node() - spoke fields + hub via node.* record link - SurrealStore.get_schema_node() - same pattern for schemas - Documented in surrealdb-schema-design.md as Option 3 (Recommended) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * WIP: Phase 4 complete - MCP handlers return typed structs ## Completed in This Session - [x] Phase 4: Updated MCP handlers to return strongly-typed JSON responses - Added `node_to_typed_value()` and `nodes_to_typed_values()` helper functions - Updated `handle_get_node()` to convert task/schema nodes to typed structs - Updated `handle_query_nodes()` to convert node lists to typed values - Updated `handle_get_nodes_batch()` to convert nodes to typed values - [x] Updated serialization to use camelCase for JSON consistency - Changed TaskNode and SchemaNode from snake_case to camelCase - Matches Node struct convention for consistent API - [x] Added comprehensive tests for typed responses - 4 new tests verifying TaskNode/SchemaNode/Node response formats - All 41 MCP handler tests passing - [x] Fixed tests to match camelCase JSON format - Updated task_node_test.rs serde tests - Updated schema_node.rs serde tests ## Remaining Work - [ ] Phase 5: Behavior integration - TaskNodeBehavior should validate TaskNode directly - [ ] Phase 6: Fix get_node() to use FETCH data for single query efficiency ## Current State - Files modified: - packages/core/src/mcp/handlers/nodes.rs (typed conversion helpers) - packages/core/src/mcp/handlers/nodes_test.rs (+4 typed response tests) - packages/core/src/models/task_node.rs (camelCase serialization) - packages/core/src/models/schema_node.rs (camelCase serialization) - packages/core/src/models/task_node_test.rs (fixed serde tests) - Tests status: All 548 tests passing, no clippy warnings - Known issues: None - current functionality working ## Context for Next Session MCP handlers now return strongly-typed TaskNode/SchemaNode for task/schema types, providing direct field access (status, priority, isCore) instead of nesting in properties. Simple types (text, header) continue to use generic Node. The key remaining work is Phase 5 (behavior validation) and Phase 6 (single-query efficiency using FETCH data). ## Acceptance Criteria Status From issue #673: - [x] TaskNode struct with direct fields (id, content, status, priority, etc.) - [x] SchemaNode struct with direct fields (id, content, isCore, fields, etc.) - [x] get_task_node() method in NodeService (single-query) - [x] get_schema_node() method in NodeService (single-query) - [x] MCP handlers return typed structs (Phase 4 ✅) - [ ] Behavior integration (Phase 5) - [ ] get_node() efficiency fix (Phase 6) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement strongly-typed behavior validation (Issue #673 Phases 5-6) ## Phase 5: Behavior Integration - Add `validate_task_node()` to TaskNodeBehavior for strongly-typed validation - Add `validate_schema_node()` to SchemaNodeBehavior for strongly-typed validation - Update `validate()` methods to convert Node → typed struct internally - Priority validation now checks 1-4 range (type-safe i32 field) - Fallback to property validation if typed conversion fails (backward compat) ## Phase 6: Documentation (Deferred Implementation) - Document FETCH data limitation in get_node() (blocked by Issue #511) - SurrealDB Thing type cannot deserialize to serde_json::Value - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency with spoke table types ## TaskNode::from_node() Improvements - Handle both nested (properties.task.*) and flat (properties.*) formats - Support string priority conversion ("high" → 2, "low" → 4, etc.) - Consistent with Issue #397 type-namespaced properties ## New Tests - test_task_node_behavior_validate_task_node: Priority range validation - test_schema_node_behavior_validate_schema_node: Content validation - test_task_node_from_node_nested_format: Nested property extraction - test_task_node_from_node_flat_format: Backward compatibility - test_task_node_from_node_string_priority: String→int conversion - Updated test_task_node_behavior_validation with range tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Remove outdated Issue #511 references from hub-spoke architecture comments Issue #511 (SurrealDB Schema Refactor) is closed and its architecture is now the established pattern. Updated comments to reflect current state: - Simplified SurrealNode.data field documentation - Removed "FETCH data limitation" explanation (no longer relevant) - Updated get_node() comment to describe the 2-query pattern as intentional - Recommend strongly-typed methods (get_task_node, get_schema_node) for single-query efficiency The hub-spoke architecture with strongly-typed methods is the solution, not a workaround for a blocking issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Optimize get_node() to single round-trip query (Issue #673 Phase 6) Changed from 2 sequential queries to 1 multi-statement query: - Hub query: SELECT * FROM node:`id` - Task spoke: SELECT * OMIT id, node FROM task:`id` - Schema spoke: SELECT * OMIT id, node FROM schema:`id` All 3 statements execute in a single database round-trip. The spoke queries return empty results for non-matching types, and we merge based on node_type. Benefits: - Single network round-trip instead of 2 sequential queries - Simpler code with clearer intent - Same correctness - OMIT excludes Thing-typed fields that can't deserialize For compile-time type safety with strongly-typed returns, use: - get_task_node(id) → TaskNode - get_schema_node(id) → SchemaNode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Refactor get_node() to use dynamic spoke detection via data field Instead of hardcoding spoke table types, get_node() now uses the hub's `data` field to determine if a spoke exists: ```sql LET $hub = (SELECT * FROM node:`{id}`)[0]; LET $spoke = IF $hub.data != NONE THEN (SELECT * OMIT id, node FROM $hub.data)[0] ELSE NONE END; RETURN { hub: $hub, spoke: $spoke }; ``` Benefits: - Single round-trip query - Automatically works for any node type (core or user-defined) - No hardcoded type list in get_node() - Prepares for user-defined custom node types with spoke tables Note: TYPES_WITH_SPOKE_TABLES constant still used elsewhere (create, update, type switching). Full removal requires schema-driven type system refactor. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Simplify get_node() to two-query approach for maintainability ## Changes - Remove LET/IF/RETURN single-query pattern from get_node() - Use simple two-query approach: hub first, then spoke if needed - Remove unused HubSpokeResult struct ## Rationale For embedded SurrealDB (RocksDB), the second query is an in-process call with ~microsecond overhead. The two-query approach: 1. **Scales automatically** - No code changes needed for new spoke types 2. **More maintainable** - No IF/ELSE chain enumerating all types 3. **Same performance** - In-process calls are negligible Single-query alternatives were investigated but rejected: - `FETCH data` fails because Thing types can't deserialize to serde_json::Value - `LET/IF/RETURN` requires enumerating all spoke types in the query For compile-time type safety, use get_task_node() or get_schema_node() which already use single-query spoke-first pattern. Closes #673 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address code review feedback from PR #685 - Add warning logs for missing/invalid timestamps in get_node() to help diagnose potential data corruption (surreal_store.rs) - Document the assignee field backward compatibility behavior in TaskNode::from_node() to explain why both field names are supported - Add implementation note to node_to_typed_value() explaining why from_node() is used instead of typed retrieval methods Reviewer suggestions addressed: - [Important] Silent fallbacks now log warnings for timestamps - [Important] Assignee field inconsistency documented - [Nit] node_to_typed_value helper now explains design decision Skipped (with justification): - [Important] Duplicated default_version() helpers - These are trivial one-line serde default functions. Consolidating would require adding public exports and changing serde attribute paths across files for minimal DRY benefit. The maintenance cost exceeds the value. - [Nit] validate_task_node docstring import path - Minimal value, the example code is clear enough without full import paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Support user-defined task statuses via schema extensibility TaskStatus enum now supports user-defined values via User(String) variant, aligning with the schema system's core_values/user_values model. Changes: - Add User(String) variant to TaskStatus for schema-extended statuses - Remove Copy trait (User variant contains String) - Add is_core() and is_user_defined() helper methods - Implement custom Serialize/Deserialize for string-based storage - Update from_str to accept any value (core or user-defined) - Update tests to reflect new behavior This ensures strongly-typed nodes don't block schema extensibility: - Core statuses (open, in_progress, done, cancelled) get compile-time safety - User-extended statuses are stored as User("blocked"), User("review"), etc. - Runtime validation against schema still applies via validate_node_against_schema 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Integrate typed node structs in Tauri commands and dev-proxy (Issue #673) Updated all node-returning endpoints to use strongly-typed structs (TaskNode, SchemaNode) via node_to_typed_value() helper, matching the MCP handler implementation. Tauri commands updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - get_nodes_by_root_id() -> returns Vec<typed Value> - query_nodes_simple() -> returns Vec<typed Value> - mention_autocomplete() -> returns Vec<typed Value> Dev-proxy (HTTP adapter) updated: - get_node() -> returns typed Value - update_node() -> returns typed Value - get_children() -> returns Vec<typed Value> - query_nodes() -> returns Vec<typed Value> This completes the Issue #673 requirement to integrate typed structs throughout the entire stack (MCP handlers, behaviors, Tauri commands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Consolidate node_to_typed_value into canonical implementation Removes code duplication by creating a single canonical implementation of node_to_typed_value in nodespace_core::models, which all entry points (MCP handlers, Tauri commands, dev-proxy) now delegate to. Changes: - Add node_to_typed_value() and nodes_to_typed_values() to models/mod.rs - Simplify MCP handlers to delegate with MCPError mapping - Simplify Tauri commands to delegate with CommandError mapping - Simplify dev-proxy to delegate with ApiError mapping This reduces 86 lines to 64 and ensures consistent behavior across all API surfaces (Issue #673). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #673