Skip to content

feat: enforce parent-child hierarchy rules in validation #23

@mindsocket

Description

@mindsocket

Problem

Currently, the schema validation only checks individual node properties, not parent-child relationships. This means invalid hierarchies like:

  • Solutions with solution parents (should require opportunity parents)
  • Experiments with opportunity parents (should require solution parents)

These pass schema validation because the schema only checks that is a valid wikilink, not what type of node it references.

Context

The strict_ost schema (#15) defines a canonical 4-level hierarchy:

  • outcome → no parent (root level)
  • opportunity → parent must be outcome
  • solution → parent must be opportunity
  • experiment → parent must be solution

The schema currently cannot enforce these constraints because JSON Schema validates individual objects, not relationships between objects.

Proposed Solution

Add a post-schema validation step that:

  1. Builds a type index (title → type mapping) for all nodes
  2. For each node with a parent:
    • Resolve the parent reference (using existing logic)
    • Check if the parent's type is valid for the child's type
  3. Report hierarchy violations as validation errors

This would be similar to the existing dangling reference check, but with type-aware validation.

Implementation Notes

  • The hierarchy rules should be defined in the schema's ._metadata object (already exists for strict_ost)
  • Should work with both readSpaceDirectory and readSpaceOnAPage
  • Rules should be per-schema (general.json allows more flexibility, strict_ost is rigid)
  • Could be integrated into the existing validate command

Acceptance Criteria

  • Hierarchy rules are defined in schema metadata
  • Validation command reports parent-child type violations
  • Works for both directory and on-a-page formats
  • clear error messages (e.g., "solution 'Simplify signup' has parent 'Another solution' but must have an opportunity parent")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions