Repository navigation
Closed
Labels
Description
Implement Namespace Enforcement for User-Defined Properties
Problem
Without namespace enforcement, user-defined properties can conflict with future core properties, leading to breaking changes when NodeSpace adds new core features.
Collision Scenarios
Scenario 1: Property Name Collision
Year 2025: User adds custom property
{
"node_type": "task",
"properties": {
"estimatedHours": "8 hours" // User-defined (string type)
}
}
Year 2026: NodeSpace v2.0 adds core property
{
"properties": {
"estimatedHours": null // Core property (number type)
}
}
💥 Collision: Type mismatch, data loss risk
Scenario 2: Type Collision
User creates custom "project" node type with different schema
→ NodeSpace later adds ProjectNodeBehavior as core type
→ 500 existing user nodes now fail validation
Solution
Enforce namespace prefixes for all user-defined properties to guarantee zero collision risk with future core features.
Required Namespaces
| Prefix | Purpose | Example |
|---|---|---|
custom: |
Personal custom properties | custom:estimatedHours, custom:tags |
org: |
Organization-specific | org:departmentCode, org:budget |
plugin: |
Plugin-provided | plugin:jira:issueId, plugin:github:prUrl |
Core Property Rules
- Core properties: No prefix (
status,priority,due_date) - User properties: MUST have prefix (
custom:estimatedHours) - Future-proof: Simple names reserved for core expansion
Implementation Tasks
Phase 1: Validation Enforcement
- Add namespace validation to
SchemaService::add_field() - Reject user fields without namespace prefix
- Reject core fields with namespace prefix
- Add validation tests
Files to modify:
packages/core/src/services/schema_service.rs
Validation logic:
pub fn add_field(&self, schema_name: &str, field: SchemaField) -> Result<()> {
if field.protection == ProtectionLevel::Core {
if field.name.contains(':') {
return Err(ServiceError::InvalidFieldName(
"Core properties cannot use namespace prefix".to_string()
));
}
} else {
// User/plugin fields must have prefix
let valid_prefixes = ["custom:", "org:", "plugin:"];
let has_valid_prefix = valid_prefixes.iter()
.any(|prefix| field.name.starts_with(prefix));
if !has_valid_prefix {
return Err(ServiceError::InvalidFieldName(
format!(
"User properties must use namespace prefix.\n\
Examples: 'custom:{}', 'org:{}', 'plugin:name:{}'\n\
This prevents conflicts with future core properties.",
field.name, field.name, field.name
)
));
}
}
// ... proceed
}Phase 2: MCP Tool Updates
- Update
add_schema_fieldMCP tool with validation - Update tool schema to document namespace requirement
- Add error messages with examples
Files to modify:
packages/core/src/mcp/handlers/schema.rs
Phase 3: Frontend UI Updates (Future)
- Schema editor UI enforces prefix selection
- Dropdown for namespace prefix choice
- Inline help text explaining namespaces
Files to modify:
packages/desktop-app/src/lib/components/schema-editor.svelte(future)
Phase 4: Migration for Existing Data
- Add migration check on app startup
- Detect non-namespaced user properties
- Auto-rename with
custom:prefix - Create backup before migration
- Show user notification of renamed properties
Files to modify:
packages/core/src/services/schema_service.rs(migration logic)packages/desktop-app/src/lib/services/schema-migration-ui.ts(UI)
Phase 5: Documentation
- Update schema management guide with namespace rules
- Update node behavior system docs with hybrid architecture
- Add migration guide for existing users (if needed)
- Update API documentation
Acceptance Criteria
- SchemaService rejects user fields without namespace prefix
- SchemaService rejects core fields with namespace prefix
- MCP tools enforce namespace validation
- Clear error messages guide users to correct format
- Documentation updated with namespace guidelines
- Migration strategy tested for existing data
- Unit tests cover all validation cases
Benefits
- Zero Collision Risk: Future core properties will never conflict with user data
- Clear Ownership: Easy to distinguish core vs user properties
- Plugin Safety: Each plugin has isolated namespace
- Future-Proof: NodeSpace can evolve without breaking user schemas
Technical Notes
Testing Strategy
#[test]
fn test_namespace_enforcement() {
let service = SchemaService::new();
// ✅ Core field without prefix - should succeed
let core_field = SchemaField {
name: "status".to_string(),
protection: ProtectionLevel::Core,
// ...
};
assert!(service.add_field("task", core_field).is_ok());
// ❌ User field without prefix - should fail
let invalid_user_field = SchemaField {
name: "estimatedHours".to_string(),
protection: ProtectionLevel::User,
// ...
};
assert!(service.add_field("task", invalid_user_field).is_err());
// ✅ User field with prefix - should succeed
let valid_user_field = SchemaField {
name: "custom:estimatedHours".to_string(),
protection: ProtectionLevel::User,
// ...
};
assert!(service.add_field("task", valid_user_field).is_ok());
// ❌ Core field with prefix - should fail
let invalid_core_field = SchemaField {
name: "custom:status".to_string(),
protection: ProtectionLevel::Core,
// ...
};
assert!(service.add_field("task", invalid_core_field).is_err());
}Priority
High - Implement before users create many custom schemas to avoid difficult migrations later.
Related Issues
- Implement Schema Management Service with Migration Infrastructure #106 - Schema Management System (implemented)
- Replace hardcoded behavior validation with schema-driven validation #392 - Replace hardcoded behavior validation with schema-driven validation
- Implement Schema-Driven Property UI for Node Viewers #193 - Schema-Driven Property UI (implemented)
Activity
docs: Document hybrid architecture and namespace enforcement strategy
feat: Implement namespace enforcement for user-defined properties (Is…
Implement Namespace Enforcement for User-Defined Properties (#401)
Add namespace prefix enforcement for user schema fields (Issue #690, #…
Simplify Schema Architecture: Remove SchemaDefinition and SchemaServi…
docs: Document hybrid architecture and namespace enforcement strategy
Implement Namespace Enforcement for User-Defined Properties (#401)
Simplify Schema Architecture: Remove SchemaDefinition and SchemaServi…
docs: Document hybrid architecture and namespace enforcement strategy
Implement Namespace Enforcement for User-Defined Properties (#401)
Simplify Schema Architecture: Remove SchemaDefinition and SchemaServi…
Implement Namespace Enforcement for User-Defined Properties (#401)
Simplify Schema Architecture: Remove SchemaDefinition and SchemaServi…