#include "HyperTwistSkills/HyperTwistSkillTypes.h"

namespace HyperTwistSkillTypesInternal
{
	bool AreAllStringsPopulated(const TArray<FString>& Values)
	{
		for (const FString& Value : Values)
		{
			if (Value.IsEmpty())
			{
				return false;
			}
		}

		return true;
	}

	template <typename ItemType>
	bool AreAllItemsStructurallyValid(const TArray<ItemType>& Values)
	{
		for (const ItemType& Value : Values)
		{
			if (!Value.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}

	bool IsImplementedPermissiveWrapperSkillId(const FString& SkillId)
	{
		return SkillId == TEXT("skill/review-architecture")
			|| SkillId == TEXT("skill/memory-resume-briefing")
			|| SkillId == TEXT("skill/provider-routing-inspector");
	}
}

bool FHyperTwistSkillManifestEntry::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| Version.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Family == EHyperTwistSkillFamily::None
		|| Status == EHyperTwistSkillStatus::None
		|| !bOptionalAssistive
		|| !bInstalledWhenDisabled
		|| !bInertWhenDisabled
		|| CommandBindings.Num() == 0
		|| PermissionScopes.Num() == 0
		|| !Provenance.IsStructurallyValid())
	{
		return false;
	}

	return HyperTwistSkillTypesInternal::AreAllItemsStructurallyValid(CommandBindings)
		&& HyperTwistSkillTypesInternal::AreAllItemsStructurallyValid(PermissionScopes);
}

bool FHyperTwistSkillCommandProvenanceState::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| BoundFeatureId.IsEmpty()
		|| InvocationPattern.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| ProducerIdentity.IsEmpty()
		|| CustodyClass.IsEmpty()
		|| PermissionScopeIds.Num() == 0
		|| ProducedArtifactKinds.Num() == 0
		|| !bCommandBindingDeclared
		|| !bServiceBindingVisible)
	{
		return false;
	}

	return HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(ProducedArtifactKinds);
}

bool FHyperTwistSkillAnalyzerWrapperOutput::IsStructurallyValid() const
{
	if (WrapperOutputId.IsEmpty()
		|| SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| OutputKindId.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| ArtifactKind.IsEmpty()
		|| PermissionScopeIds.Num() == 0
		|| !bLiveWrapper
		|| !bStableInvocationPattern
		|| !bStructuredOutput
		|| !bDerivedAssistiveOnly)
	{
		return false;
	}

	return HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds);
}

bool FHyperTwistSkillExtractionSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| StructuredFieldIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| StructuredFieldCount != StructuredFieldIds.Num()
		|| !bReadsAuthoritativeSourceSurfaces
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bStructuredExtractionOnly
		|| !bAvoidsBrowserDiagnosticsWidening
		|| !bAvoidsDesignTranslationWidening
		|| bExtractsDocumentation == bExtractsDesignSpecs)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(StructuredFieldIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	return Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillExtractionState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeSourceSurfaces
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bStructuredExtractionRemainsBounded
		|| !bNoBrowserDiagnosticsWidening
		|| !bNoDesignTranslationWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedDocsExtractionSkillCount = 0;
	int32 ComputedDesignSpecExtractionSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeSourceSurfaces = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedStructuredExtractionBounded = true;
	bool bComputedNoBrowserDiagnosticsWidening = true;
	bool bComputedNoDesignTranslationWidening = true;

	for (const FHyperTwistSkillExtractionSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedDocsExtractionSkillCount += Skill.bExtractsDocumentation ? 1 : 0;
		ComputedDesignSpecExtractionSkillCount += Skill.bExtractsDesignSpecs ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedStructuredExtractionBounded &= Skill.bStructuredExtractionOnly;
		bComputedNoBrowserDiagnosticsWidening &= Skill.bAvoidsBrowserDiagnosticsWidening;
		bComputedNoDesignTranslationWidening &= Skill.bAvoidsDesignTranslationWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeSourceSurfaces &=
				Skill.bReadsAuthoritativeSourceSurfaces;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& DocsExtractionSkillCount == ComputedDocsExtractionSkillCount
		&& DesignSpecExtractionSkillCount == ComputedDesignSpecExtractionSkillCount
		&& bEveryLiveSkillReadsAuthoritativeSourceSurfaces
			== bComputedEveryLiveSkillReadsAuthoritativeSourceSurfaces
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bStructuredExtractionRemainsBounded == bComputedStructuredExtractionBounded
		&& bNoBrowserDiagnosticsWidening == bComputedNoBrowserDiagnosticsWidening
		&& bNoDesignTranslationWidening == bComputedNoDesignTranslationWidening;
}

bool FHyperTwistSkillBrowserDiagnosticSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredExtractionSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredExtractionSkillCount != RequiredExtractionSkillIds.Num()
		|| !bReadsAuthoritativeBrowserAndDocSurfaces
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToDiagnosticsOnly
		|| !bRequiresExtractionSubstrate
		|| !bAvoidsDesignTranslationWidening
		|| bCapturesBrowserTrace == bPerformsBrowserApiDiscovery)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredExtractionSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	return Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillBrowserDiagnosticsState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeBrowserAndDocSurfaces
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bDiagnosticsRemainBounded
		|| !bEverySkillRequiresExtractionSubstrate
		|| !bNoDesignTranslationWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedBrowserTraceCaptureSkillCount = 0;
	int32 ComputedBrowserApiDiscoverySkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeBrowserAndDocSurfaces = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedDiagnosticsRemainBounded = true;
	bool bComputedEverySkillRequiresExtractionSubstrate = true;
	bool bComputedNoDesignTranslationWidening = true;

	for (const FHyperTwistSkillBrowserDiagnosticSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedBrowserTraceCaptureSkillCount += Skill.bCapturesBrowserTrace ? 1 : 0;
		ComputedBrowserApiDiscoverySkillCount += Skill.bPerformsBrowserApiDiscovery ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedDiagnosticsRemainBounded &= Skill.bBoundedToDiagnosticsOnly;
		bComputedEverySkillRequiresExtractionSubstrate &= Skill.bRequiresExtractionSubstrate;
		bComputedNoDesignTranslationWidening &= Skill.bAvoidsDesignTranslationWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeBrowserAndDocSurfaces &=
				Skill.bReadsAuthoritativeBrowserAndDocSurfaces;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& BrowserTraceCaptureSkillCount == ComputedBrowserTraceCaptureSkillCount
		&& BrowserApiDiscoverySkillCount == ComputedBrowserApiDiscoverySkillCount
		&& bEveryLiveSkillReadsAuthoritativeBrowserAndDocSurfaces
			== bComputedEveryLiveSkillReadsAuthoritativeBrowserAndDocSurfaces
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bDiagnosticsRemainBounded == bComputedDiagnosticsRemainBounded
		&& bEverySkillRequiresExtractionSubstrate
			== bComputedEverySkillRequiresExtractionSubstrate
		&& bNoDesignTranslationWidening == bComputedNoDesignTranslationWidening;
}

bool FHyperTwistSkillDesignShellSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredExtractionSkillIds.Num() == 0
		|| RequiredBrowserDiagnosticSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredExtractionSkillCount != RequiredExtractionSkillIds.Num()
		|| RequiredBrowserDiagnosticSkillCount != RequiredBrowserDiagnosticSkillIds.Num()
		|| !bReadsAuthoritativeDocsBrowserAndDesignSurfaces
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToDesignShellOnly
		|| !bRequiresExtractionSubstrate
		|| !bRequiresBrowserDiagnosticsSubstrate
		|| !bAvoidsGenericBrowserShellWidening
		|| bTranslatesDesignShell == bTranslatesInteractionContract)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredExtractionSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredBrowserDiagnosticSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	return Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillDesignShellState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeDocsBrowserAndDesignSurfaces
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bDesignShellTranslationRemainsBounded
		|| !bEverySkillRequiresExtractionSubstrate
		|| !bEverySkillRequiresBrowserDiagnosticsSubstrate
		|| !bNoGenericBrowserShellWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedDesignShellTranslationSkillCount = 0;
	int32 ComputedInteractionContractTranslationSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeDocsBrowserAndDesignSurfaces = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedDesignShellTranslationRemainsBounded = true;
	bool bComputedEverySkillRequiresExtractionSubstrate = true;
	bool bComputedEverySkillRequiresBrowserDiagnosticsSubstrate = true;
	bool bComputedNoGenericBrowserShellWidening = true;

	for (const FHyperTwistSkillDesignShellSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedDesignShellTranslationSkillCount += Skill.bTranslatesDesignShell ? 1 : 0;
		ComputedInteractionContractTranslationSkillCount +=
			Skill.bTranslatesInteractionContract ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedDesignShellTranslationRemainsBounded &= Skill.bBoundedToDesignShellOnly;
		bComputedEverySkillRequiresExtractionSubstrate &= Skill.bRequiresExtractionSubstrate;
		bComputedEverySkillRequiresBrowserDiagnosticsSubstrate &=
			Skill.bRequiresBrowserDiagnosticsSubstrate;
		bComputedNoGenericBrowserShellWidening &=
			Skill.bAvoidsGenericBrowserShellWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeDocsBrowserAndDesignSurfaces &=
				Skill.bReadsAuthoritativeDocsBrowserAndDesignSurfaces;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& DesignShellTranslationSkillCount == ComputedDesignShellTranslationSkillCount
		&& InteractionContractTranslationSkillCount
			== ComputedInteractionContractTranslationSkillCount
		&& bEveryLiveSkillReadsAuthoritativeDocsBrowserAndDesignSurfaces
			== bComputedEveryLiveSkillReadsAuthoritativeDocsBrowserAndDesignSurfaces
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bDesignShellTranslationRemainsBounded
			== bComputedDesignShellTranslationRemainsBounded
		&& bEverySkillRequiresExtractionSubstrate
			== bComputedEverySkillRequiresExtractionSubstrate
		&& bEverySkillRequiresBrowserDiagnosticsSubstrate
			== bComputedEverySkillRequiresBrowserDiagnosticsSubstrate
		&& bNoGenericBrowserShellWidening == bComputedNoGenericBrowserShellWidening;
}

bool FHyperTwistSkillRegistryState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| Entries.Num() == 0
		|| SkillCount != Entries.Num()
		|| !bAllSkillsOptionalAssistive
		|| !bDisabledSkillsRemainInstalled
		|| !bDisabledSkillsAreInert
		|| !bNoAdHocMetadataRequired)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedEnabledByDefaultCount = 0;
	bool bComputedAllOptionalAssistive = true;
	bool bComputedDisabledRemainInstalled = true;
	bool bComputedDisabledAreInert = true;

	for (const FHyperTwistSkillManifestEntry& Entry : Entries)
	{
		if (!Entry.IsStructurallyValid() || SeenSkillIds.Contains(Entry.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Entry.SkillId);
		ComputedEnabledByDefaultCount += Entry.bEnabledByDefault ? 1 : 0;
		bComputedAllOptionalAssistive &= Entry.bOptionalAssistive;
		bComputedDisabledRemainInstalled &= Entry.bInstalledWhenDisabled;
		bComputedDisabledAreInert &= Entry.bInertWhenDisabled;
	}

	if (EnabledByDefaultCount != ComputedEnabledByDefaultCount
		|| DisabledByDefaultCount != (Entries.Num() - ComputedEnabledByDefaultCount)
		|| bAllSkillsOptionalAssistive != bComputedAllOptionalAssistive
		|| bDisabledSkillsRemainInstalled != bComputedDisabledRemainInstalled
		|| bDisabledSkillsAreInert != bComputedDisabledAreInert)
	{
		return false;
	}

	TArray<EHyperTwistSkillStatus> SeenStatuses;
	for (const FHyperTwistSkillStatusCount& StatusCount : StatusCounts)
	{
		if (!StatusCount.IsStructurallyValid() || SeenStatuses.Contains(StatusCount.Status))
		{
			return false;
		}

		int32 ComputedCount = 0;
		for (const FHyperTwistSkillManifestEntry& Entry : Entries)
		{
			ComputedCount += Entry.Status == StatusCount.Status ? 1 : 0;
		}

		if (ComputedCount != StatusCount.Count)
		{
			return false;
		}

		SeenStatuses.Add(StatusCount.Status);
	}

	TArray<EHyperTwistSkillFamily> SeenFamilies;
	for (const FHyperTwistSkillFamilyCount& FamilyCount : FamilyCounts)
	{
		if (!FamilyCount.IsStructurallyValid() || SeenFamilies.Contains(FamilyCount.Family))
		{
			return false;
		}

		int32 ComputedCount = 0;
		for (const FHyperTwistSkillManifestEntry& Entry : Entries)
		{
			ComputedCount += Entry.Family == FamilyCount.Family ? 1 : 0;
		}

		if (ComputedCount != FamilyCount.Count)
		{
			return false;
		}

		SeenFamilies.Add(FamilyCount.Family);
	}

	return true;
}

bool FHyperTwistSkillControlState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| ControlProfileId.IsEmpty()
		|| !MasterSwitch.IsStructurallyValid()
		|| SkillStates.Num() == 0
		|| SkillCount != SkillStates.Num()
		|| EffectiveDisabledSkillCount != (SkillCount - EffectiveEnabledSkillCount)
		|| HiddenSkillCount != (SkillCount - VisibleSkillCount)
		|| !bCoreProductWorksWithAllSkillsOff
		|| !bNoPromptBabysittingToDisable
		|| !bAllInstalledSkillsRemainReenableable)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedEnabledCount = 0;
	int32 ComputedVisibleCount = 0;
	bool bComputedNoBabysitting = true;
	bool bComputedReenableable = true;
	for (const FHyperTwistSkillControlStateEntry& SkillState : SkillStates)
	{
		if (!SkillState.IsStructurallyValid() || SeenSkillIds.Contains(SkillState.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(SkillState.SkillId);
		ComputedEnabledCount += SkillState.bEffectiveEnabled ? 1 : 0;
		ComputedVisibleCount += SkillState.bEffectiveVisible ? 1 : 0;
		bComputedNoBabysitting &= SkillState.bDurableSettingExposed;
		bComputedReenableable &= SkillState.bInstalled && SkillState.bInertWhenDisabled;
	}

	if (ComputedEnabledCount != EffectiveEnabledSkillCount
		|| ComputedVisibleCount != VisibleSkillCount
		|| bComputedNoBabysitting != bNoPromptBabysittingToDisable
		|| bComputedReenableable != bAllInstalledSkillsRemainReenableable)
	{
		return false;
	}

	TArray<FString> SeenGroupIds;
	for (const FHyperTwistSkillVisibilityGroupState& Group : VisibilityGroups)
	{
		if (!Group.IsStructurallyValid() || SeenGroupIds.Contains(Group.GroupId))
		{
			return false;
		}

		int32 ComputedGroupVisibleCount = 0;
		int32 ComputedGroupHiddenCount = 0;
		for (const FString& SkillId : Group.SkillIds)
		{
			const FHyperTwistSkillControlStateEntry* SkillState = SkillStates.FindByPredicate(
				[&SkillId](const FHyperTwistSkillControlStateEntry& Entry)
				{
					return Entry.SkillId == SkillId;
				}
			);
			if (SkillState == nullptr
				|| SkillState->Family != Group.Family
				|| SkillState->VisibilityGroupId != Group.GroupId)
			{
				return false;
			}

			ComputedGroupVisibleCount += SkillState->bEffectiveVisible ? 1 : 0;
			ComputedGroupHiddenCount += SkillState->bEffectiveVisible ? 0 : 1;
		}

		if (ComputedGroupVisibleCount != Group.VisibleSkillCount
			|| ComputedGroupHiddenCount != Group.HiddenSkillCount)
		{
			return false;
		}

		SeenGroupIds.Add(Group.GroupId);
	}

	return true;
}

bool FHyperTwistSkillInvocationRecord::IsStructurallyValid() const
{
	if (InvocationId.IsEmpty()
		|| SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| SessionId.IsEmpty()
		|| RunId.IsEmpty()
		|| StartedAtUtc.IsEmpty()
		|| CompletedAtUtc.IsEmpty()
		|| Outcome == EHyperTwistSkillInvocationOutcome::None
		|| WarningState.IsEmpty()
		|| !CommandProvenance.IsStructurallyValid()
		|| !bInvocationTraceable
		|| !bOutcomeRecorded
		|| !HyperTwistSkillTypesInternal::AreAllItemsStructurallyValid(ProducedArtifacts))
	{
		return false;
	}

	switch (Outcome)
	{
	case EHyperTwistSkillInvocationOutcome::Succeeded:
		if (FailureReason.Len() > 0
			|| CancelReason.Len() > 0
			|| ProducedArtifacts.Num() == 0
			|| !bOutputBecameProductTruth
			|| !bOutputTraceable)
		{
			return false;
		}
		break;

	case EHyperTwistSkillInvocationOutcome::Failed:
		if (FailureReason.IsEmpty()
			|| CancelReason.Len() > 0
			|| ProducedArtifacts.Num() != 0
			|| bOutputBecameProductTruth)
		{
			return false;
		}
		break;

	case EHyperTwistSkillInvocationOutcome::Cancelled:
		if (CancelReason.IsEmpty()
			|| FailureReason.Len() > 0
			|| ProducedArtifacts.Num() != 0
			|| bOutputBecameProductTruth)
		{
			return false;
		}
		break;

	default:
		return false;
	}

	return !bOutputBecameProductTruth || bOutputTraceable;
}

bool FHyperTwistSkillAuditLedgerState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| ControlProfileId.IsEmpty()
		|| LedgerId.IsEmpty()
		|| InvocationCount != InvocationRecords.Num()
		|| EnabledSkillCount < 0
		|| InvocationCount < 0
		|| SuccessfulInvocationCount < 0
		|| FailedInvocationCount < 0
		|| CancelledInvocationCount < 0
		|| TraceableInvocationCount < 0
		|| ProductTruthOutputCount < 0
		|| TraceableProductTruthOutputCount < 0
		|| !bNoUntraceableProductTruth
		|| !bCommandServiceProvenanceVisible)
	{
		return false;
	}

	TArray<FString> SeenInvocationIds;
	int32 ComputedSuccessCount = 0;
	int32 ComputedFailureCount = 0;
	int32 ComputedCancelCount = 0;
	int32 ComputedTraceableInvocationCount = 0;
	int32 ComputedProductTruthCount = 0;
	int32 ComputedTraceableProductTruthCount = 0;
	bool bComputedCommandProvenanceVisible = true;
	for (const FHyperTwistSkillInvocationRecord& Record : InvocationRecords)
	{
		if (!Record.IsStructurallyValid() || SeenInvocationIds.Contains(Record.InvocationId))
		{
			return false;
		}

		SeenInvocationIds.Add(Record.InvocationId);
		ComputedTraceableInvocationCount += Record.bInvocationTraceable ? 1 : 0;
		ComputedProductTruthCount += Record.bOutputBecameProductTruth ? 1 : 0;
		ComputedTraceableProductTruthCount +=
			(Record.bOutputBecameProductTruth && Record.bOutputTraceable) ? 1 : 0;
		bComputedCommandProvenanceVisible &= Record.CommandProvenance.bCommandBindingDeclared
			&& Record.CommandProvenance.bServiceBindingVisible;

		switch (Record.Outcome)
		{
		case EHyperTwistSkillInvocationOutcome::Succeeded:
			ComputedSuccessCount += 1;
			break;

		case EHyperTwistSkillInvocationOutcome::Failed:
			ComputedFailureCount += 1;
			break;

		case EHyperTwistSkillInvocationOutcome::Cancelled:
			ComputedCancelCount += 1;
			break;

		default:
			return false;
		}
	}

	return SuccessfulInvocationCount == ComputedSuccessCount
		&& FailedInvocationCount == ComputedFailureCount
		&& CancelledInvocationCount == ComputedCancelCount
		&& TraceableInvocationCount == ComputedTraceableInvocationCount
		&& ProductTruthOutputCount == ComputedProductTruthCount
		&& TraceableProductTruthOutputCount == ComputedTraceableProductTruthCount
		&& bNoUntraceableProductTruth
			== (ComputedProductTruthCount == ComputedTraceableProductTruthCount)
		&& bFailureRecordingSupported
		&& bCancelRecordingSupported
		&& bCommandServiceProvenanceVisible == bComputedCommandProvenanceVisible;
}

bool FHyperTwistSkillValidationContractCase::IsStructurallyValid() const
{
	if (CaseId.IsEmpty()
		|| SkillId.IsEmpty()
		|| Kind == EHyperTwistSkillValidationContractKind::None
		|| ExecutionMode == EHyperTwistSkillValidationExecutionMode::None
		|| ExpectedCommandSurfaceId.IsEmpty()
		|| ExpectedServiceBindingId.IsEmpty()
		|| RequiredTemplateSectionIds.Num() == 0
		|| ExpectedArtifactKinds.Num() == 0)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredTemplateSectionIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(ExpectedArtifactKinds))
	{
		return false;
	}

	const bool bLiveMode =
		ExecutionMode == EHyperTwistSkillValidationExecutionMode::LiveContract;
	if (bLiveMode && !bUsesAuditLedgerEvidence)
	{
		return false;
	}

	return true;
}

bool FHyperTwistSkillAuthoringHarnessState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| AuditLedgerId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| TemplateSections.Num() == 0
		|| Examples.Num() == 0
		|| ValidationCases.Num() == 0
		|| SkillCount <= 0
		|| ExampleCount != Examples.Num()
		|| ValidationCaseCount != ValidationCases.Num()
		|| SkillsWithSmokeContractCount < 0
		|| SkillsWithEvalContractCount < 0
		|| !bNewSkillsCanBeAddedWithoutInventingStructure
		|| !bEverySkillHasSmokeContract
		|| !bEverySkillHasEvalContract
		|| !bExamplesGroundedInFirstPartyRegistry
		|| !bValidationHarnessUsesAuditLedgerWhenLive)
	{
		return false;
	}

	TArray<FString> SeenSectionIds;
	for (const FHyperTwistSkillAuthoringTemplateSection& Section : TemplateSections)
	{
		if (!Section.IsStructurallyValid() || SeenSectionIds.Contains(Section.SectionId))
		{
			return false;
		}

		SeenSectionIds.Add(Section.SectionId);
	}

	TArray<FString> SeenExampleIds;
	TArray<FString> ExampleSkillIds;
	bool bComputedExamplesGroundedInRegistry = true;
	for (const FHyperTwistSkillAuthoringExampleState& Example : Examples)
	{
		if (!Example.IsStructurallyValid() || SeenExampleIds.Contains(Example.ExampleId))
		{
			return false;
		}

		for (const FString& SectionId : Example.TemplateSectionIds)
		{
			if (!SeenSectionIds.Contains(SectionId))
			{
				return false;
			}
		}

		SeenExampleIds.Add(Example.ExampleId);
		ExampleSkillIds.Add(Example.SkillId);
		bComputedExamplesGroundedInRegistry &= Example.bGroundedInRegistry;
	}

	TArray<FString> SeenCaseIds;
	TArray<FString> SkillsWithSmokeContract;
	TArray<FString> SkillsWithEvalContract;
	bool bComputedValidationUsesAuditLedgerWhenLive = true;
	for (const FHyperTwistSkillValidationContractCase& ValidationCase : ValidationCases)
	{
		if (!ValidationCase.IsStructurallyValid() || SeenCaseIds.Contains(ValidationCase.CaseId))
		{
			return false;
		}

		if (!ExampleSkillIds.Contains(ValidationCase.SkillId))
		{
			return false;
		}

		for (const FString& SectionId : ValidationCase.RequiredTemplateSectionIds)
		{
			if (!SeenSectionIds.Contains(SectionId))
			{
				return false;
			}
		}

		if (ValidationCase.Kind == EHyperTwistSkillValidationContractKind::Smoke)
		{
			SkillsWithSmokeContract.AddUnique(ValidationCase.SkillId);
		}
		else if (ValidationCase.Kind == EHyperTwistSkillValidationContractKind::Eval)
		{
			SkillsWithEvalContract.AddUnique(ValidationCase.SkillId);
		}

		bComputedValidationUsesAuditLedgerWhenLive &=
			ValidationCase.ExecutionMode != EHyperTwistSkillValidationExecutionMode::LiveContract
			|| ValidationCase.bUsesAuditLedgerEvidence;

		SeenCaseIds.Add(ValidationCase.CaseId);
	}

	return SkillsWithSmokeContractCount == SkillsWithSmokeContract.Num()
		&& SkillsWithEvalContractCount == SkillsWithEvalContract.Num()
		&& SkillsWithSmokeContractCount == SkillCount
		&& SkillsWithEvalContractCount == SkillCount
		&& bExamplesGroundedInFirstPartyRegistry == bComputedExamplesGroundedInRegistry
		&& bValidationHarnessUsesAuditLedgerWhenLive
			== bComputedValidationUsesAuditLedgerWhenLive;
}

bool FHyperTwistSkillWorkflowReviewSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredExtractionSkillIds.Num() == 0
		|| RequiredWorkflowMemorySkillIds.Num() == 0
		|| RequiredDesignShellSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredExtractionSkillCount != RequiredExtractionSkillIds.Num()
		|| RequiredWorkflowMemorySkillCount != RequiredWorkflowMemorySkillIds.Num()
		|| RequiredDesignShellSkillCount != RequiredDesignShellSkillIds.Num()
		|| !bReadsAuthoritativeWorkflowAndReviewSurfaces
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToWorkflowReviewOnly
		|| !bRequiresExtractionSubstrate
		|| !bRequiresWorkflowMemorySubstrate
		|| !bRequiresDesignShellSubstrate
		|| !bAvoidsImplementationReviewDelegationWidening
		|| !bAvoidsPlanSynthesisWidening)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredExtractionSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredWorkflowMemorySkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredDesignShellSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 ReviewModeCount =
		(bReviewsProposal ? 1 : 0) + (bReviewsDiff ? 1 : 0) + (bWrapsBoundedWorkflow ? 1 : 0);
	return ReviewModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillWorkflowReviewState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeWorkflowAndReviewSurfaces
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bWorkflowReviewRemainsBounded
		|| !bEverySkillRequiresExtractionSubstrate
		|| !bEverySkillRequiresWorkflowMemorySubstrate
		|| !bEverySkillRequiresDesignShellSubstrate
		|| !bNoImplementationReviewDelegationWidening
		|| !bNoPlanSynthesisWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedProposalReviewSkillCount = 0;
	int32 ComputedDiffReviewSkillCount = 0;
	int32 ComputedBoundedWorkflowWrapperSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeWorkflowAndReviewSurfaces = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedWorkflowReviewRemainsBounded = true;
	bool bComputedEverySkillRequiresExtractionSubstrate = true;
	bool bComputedEverySkillRequiresWorkflowMemorySubstrate = true;
	bool bComputedEverySkillRequiresDesignShellSubstrate = true;
	bool bComputedNoImplementationReviewDelegationWidening = true;
	bool bComputedNoPlanSynthesisWidening = true;

	for (const FHyperTwistSkillWorkflowReviewSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedProposalReviewSkillCount += Skill.bReviewsProposal ? 1 : 0;
		ComputedDiffReviewSkillCount += Skill.bReviewsDiff ? 1 : 0;
		ComputedBoundedWorkflowWrapperSkillCount += Skill.bWrapsBoundedWorkflow ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedWorkflowReviewRemainsBounded &= Skill.bBoundedToWorkflowReviewOnly;
		bComputedEverySkillRequiresExtractionSubstrate &= Skill.bRequiresExtractionSubstrate;
		bComputedEverySkillRequiresWorkflowMemorySubstrate &=
			Skill.bRequiresWorkflowMemorySubstrate;
		bComputedEverySkillRequiresDesignShellSubstrate &=
			Skill.bRequiresDesignShellSubstrate;
		bComputedNoImplementationReviewDelegationWidening &=
			Skill.bAvoidsImplementationReviewDelegationWidening;
		bComputedNoPlanSynthesisWidening &= Skill.bAvoidsPlanSynthesisWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeWorkflowAndReviewSurfaces &=
				Skill.bReadsAuthoritativeWorkflowAndReviewSurfaces;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& ProposalReviewSkillCount == ComputedProposalReviewSkillCount
		&& DiffReviewSkillCount == ComputedDiffReviewSkillCount
		&& BoundedWorkflowWrapperSkillCount == ComputedBoundedWorkflowWrapperSkillCount
		&& bEveryLiveSkillReadsAuthoritativeWorkflowAndReviewSurfaces
			== bComputedEveryLiveSkillReadsAuthoritativeWorkflowAndReviewSurfaces
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bWorkflowReviewRemainsBounded == bComputedWorkflowReviewRemainsBounded
		&& bEverySkillRequiresExtractionSubstrate
			== bComputedEverySkillRequiresExtractionSubstrate
		&& bEverySkillRequiresWorkflowMemorySubstrate
			== bComputedEverySkillRequiresWorkflowMemorySubstrate
		&& bEverySkillRequiresDesignShellSubstrate
			== bComputedEverySkillRequiresDesignShellSubstrate
		&& bNoImplementationReviewDelegationWidening
			== bComputedNoImplementationReviewDelegationWidening
		&& bNoPlanSynthesisWidening == bComputedNoPlanSynthesisWidening;
}

bool FHyperTwistSkillImplementationDelegationSpec::IsStructurallyValid() const
{
	if (SpecId.IsEmpty()
		|| SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| InputArtifactKinds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| RequiredWorkflowReviewSkillIds.Num() == 0
		|| RequiredWorkflowReviewSkillCount != RequiredWorkflowReviewSkillIds.Num()
		|| RequiredDesignShellSkillIds.Num() == 0
		|| RequiredDesignShellSkillCount != RequiredDesignShellSkillIds.Num()
		|| SpecStepIds.Num() == 0
		|| SafetyRuleIds.Num() == 0
		|| !bUsesFirstPartyTermsOnly
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bRequiresProvenanceLedger
		|| !bBoundedToImplementationReviewAndDelegationOnly
		|| !bAvoidsPlanSynthesisWidening
		|| !bAvoidsAutonomousExecutionClaims
		|| !bReadyForFutureWrapperBinding)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(InputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredWorkflowReviewSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredDesignShellSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SpecStepIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SafetyRuleIds))
	{
		return false;
	}

	const int32 SpecModeCount =
		(bCoversImplementationReview ? 1 : 0) + (bDefinesBoundedDelegationSpec ? 1 : 0);
	return SpecModeCount == 1;
}

bool FHyperTwistSkillImplementationDelegationState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Specs.Num() == 0
		|| SkillCount <= 0
		|| SpecCount != Specs.Num()
		|| StepCount <= 0
		|| SafetyRuleCount <= 0
		|| !bEverySpecUsesFirstPartyTerms
		|| !bEverySpecPreservesOptionalAssistiveOffState
		|| !bEverySpecRequiresProvenanceLedger
		|| !bEverySpecRemainsBounded
		|| !bEverySpecRequiresWorkflowReviewSubstrate
		|| !bEverySpecRequiresDesignShellSubstrate
		|| !bNoPlanSynthesisWidening
		|| !bNoAutonomousExecutionClaims
		|| !bEverySpecReadyForFutureWrapperBinding)
	{
		return false;
	}

	TArray<FString> SeenSpecIds;
	TArray<FString> SeenSkillIds;
	TArray<FString> SeenStepIds;
	TArray<FString> SeenSafetyRuleIds;
	int32 ComputedImplementationReviewSpecCount = 0;
	int32 ComputedDelegationSpecCount = 0;
	bool bComputedFirstPartyTerms = true;
	bool bComputedPreservesOffState = true;
	bool bComputedRequiresProvenanceLedger = true;
	bool bComputedRemainsBounded = true;
	bool bComputedRequiresWorkflowReview = true;
	bool bComputedRequiresDesignShell = true;
	bool bComputedNoPlanSynthesisWidening = true;
	bool bComputedNoAutonomousExecutionClaims = true;
	bool bComputedReadyForFutureWrapperBinding = true;

	for (const FHyperTwistSkillImplementationDelegationSpec& Spec : Specs)
	{
		if (!Spec.IsStructurallyValid() || SeenSpecIds.Contains(Spec.SpecId))
		{
			return false;
		}

		SeenSpecIds.Add(Spec.SpecId);
		SeenSkillIds.AddUnique(Spec.SkillId);
		ComputedImplementationReviewSpecCount += Spec.bCoversImplementationReview ? 1 : 0;
		ComputedDelegationSpecCount += Spec.bDefinesBoundedDelegationSpec ? 1 : 0;
		bComputedFirstPartyTerms &= Spec.bUsesFirstPartyTermsOnly;
		bComputedPreservesOffState &= Spec.bPreservesOptionalAssistiveOffState;
		bComputedRequiresProvenanceLedger &= Spec.bRequiresProvenanceLedger;
		bComputedRemainsBounded &= Spec.bBoundedToImplementationReviewAndDelegationOnly;
		bComputedRequiresWorkflowReview &= Spec.RequiredWorkflowReviewSkillIds.Num() > 0;
		bComputedRequiresDesignShell &= Spec.RequiredDesignShellSkillIds.Num() > 0;
		bComputedNoPlanSynthesisWidening &= Spec.bAvoidsPlanSynthesisWidening;
		bComputedNoAutonomousExecutionClaims &= Spec.bAvoidsAutonomousExecutionClaims;
		bComputedReadyForFutureWrapperBinding &= Spec.bReadyForFutureWrapperBinding;

		for (const FString& StepId : Spec.SpecStepIds)
		{
			SeenStepIds.AddUnique(StepId);
		}

		for (const FString& SafetyRuleId : Spec.SafetyRuleIds)
		{
			SeenSafetyRuleIds.AddUnique(SafetyRuleId);
		}
	}

	return SkillCount == SeenSkillIds.Num()
		&& StepCount == SeenStepIds.Num()
		&& SafetyRuleCount == SeenSafetyRuleIds.Num()
		&& ImplementationReviewSpecCount == ComputedImplementationReviewSpecCount
		&& DelegationSpecCount == ComputedDelegationSpecCount
		&& bEverySpecUsesFirstPartyTerms == bComputedFirstPartyTerms
		&& bEverySpecPreservesOptionalAssistiveOffState == bComputedPreservesOffState
		&& bEverySpecRequiresProvenanceLedger == bComputedRequiresProvenanceLedger
		&& bEverySpecRemainsBounded == bComputedRemainsBounded
		&& bEverySpecRequiresWorkflowReviewSubstrate == bComputedRequiresWorkflowReview
		&& bEverySpecRequiresDesignShellSubstrate == bComputedRequiresDesignShell
		&& bNoPlanSynthesisWidening == bComputedNoPlanSynthesisWidening
		&& bNoAutonomousExecutionClaims == bComputedNoAutonomousExecutionClaims
		&& bEverySpecReadyForFutureWrapperBinding == bComputedReadyForFutureWrapperBinding;
}

bool FHyperTwistSkillPlanOrchestrationSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredImplementationDelegationSkillIds.Num() == 0
		|| RequiredWorkflowMemorySkillIds.Num() == 0
		|| RequiredWorkflowReviewSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredImplementationDelegationSkillCount
			!= RequiredImplementationDelegationSkillIds.Num()
		|| RequiredWorkflowMemorySkillCount != RequiredWorkflowMemorySkillIds.Num()
		|| RequiredWorkflowReviewSkillCount != RequiredWorkflowReviewSkillIds.Num()
		|| !bReadsAuthoritativeWorkflowImplementationAndMemorySurfaces
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToPlanOrchestrationOnly
		|| !bRequiresImplementationDelegationSubstrate
		|| !bRequiresWorkflowMemorySubstrate
		|| !bRequiresWorkflowReviewSubstrate
		|| !bAvoidsProviderWidening
		|| !bAvoidsDomainSkillPackWidening
		|| !bAvoidsAutonomousExecutionClaims)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredImplementationDelegationSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredWorkflowMemorySkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredWorkflowReviewSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 OrchestrationModeCount =
		(bSynthesizesBoundedPlan ? 1 : 0) + (bChainsBoundedWorkflow ? 1 : 0);
	return OrchestrationModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillPlanOrchestrationState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeWorkflowImplementationAndMemorySurfaces
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bPlanOrchestrationRemainsBounded
		|| !bEverySkillRequiresImplementationDelegationSubstrate
		|| !bEverySkillRequiresWorkflowMemorySubstrate
		|| !bEverySkillRequiresWorkflowReviewSubstrate
		|| !bNoProviderWidening
		|| !bNoDomainSkillPackWidening
		|| !bNoAutonomousExecutionClaims)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedPlanSynthesisSkillCount = 0;
	int32 ComputedWorkflowChainingSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeWorkflowImplementationAndMemorySurfaces =
		true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedPlanOrchestrationRemainsBounded = true;
	bool bComputedEverySkillRequiresImplementationDelegationSubstrate = true;
	bool bComputedEverySkillRequiresWorkflowMemorySubstrate = true;
	bool bComputedEverySkillRequiresWorkflowReviewSubstrate = true;
	bool bComputedNoProviderWidening = true;
	bool bComputedNoDomainSkillPackWidening = true;
	bool bComputedNoAutonomousExecutionClaims = true;

	for (const FHyperTwistSkillPlanOrchestrationSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedPlanSynthesisSkillCount += Skill.bSynthesizesBoundedPlan ? 1 : 0;
		ComputedWorkflowChainingSkillCount += Skill.bChainsBoundedWorkflow ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedPlanOrchestrationRemainsBounded &= Skill.bBoundedToPlanOrchestrationOnly;
		bComputedEverySkillRequiresImplementationDelegationSubstrate &=
			Skill.bRequiresImplementationDelegationSubstrate;
		bComputedEverySkillRequiresWorkflowMemorySubstrate &=
			Skill.bRequiresWorkflowMemorySubstrate;
		bComputedEverySkillRequiresWorkflowReviewSubstrate &=
			Skill.bRequiresWorkflowReviewSubstrate;
		bComputedNoProviderWidening &= Skill.bAvoidsProviderWidening;
		bComputedNoDomainSkillPackWidening &= Skill.bAvoidsDomainSkillPackWidening;
		bComputedNoAutonomousExecutionClaims &= Skill.bAvoidsAutonomousExecutionClaims;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeWorkflowImplementationAndMemorySurfaces &=
				Skill.bReadsAuthoritativeWorkflowImplementationAndMemorySurfaces;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& PlanSynthesisSkillCount == ComputedPlanSynthesisSkillCount
		&& WorkflowChainingSkillCount == ComputedWorkflowChainingSkillCount
		&& bEveryLiveSkillReadsAuthoritativeWorkflowImplementationAndMemorySurfaces
			== bComputedEveryLiveSkillReadsAuthoritativeWorkflowImplementationAndMemorySurfaces
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bPlanOrchestrationRemainsBounded == bComputedPlanOrchestrationRemainsBounded
		&& bEverySkillRequiresImplementationDelegationSubstrate
			== bComputedEverySkillRequiresImplementationDelegationSubstrate
		&& bEverySkillRequiresWorkflowMemorySubstrate
			== bComputedEverySkillRequiresWorkflowMemorySubstrate
		&& bEverySkillRequiresWorkflowReviewSubstrate
			== bComputedEverySkillRequiresWorkflowReviewSubstrate
		&& bNoProviderWidening == bComputedNoProviderWidening
		&& bNoDomainSkillPackWidening == bComputedNoDomainSkillPackWidening
		&& bNoAutonomousExecutionClaims == bComputedNoAutonomousExecutionClaims;
}

bool FHyperTwistSkillProviderProfileRoutingSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredAnalyzerWrapperSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredAnalyzerWrapperSkillCount != RequiredAnalyzerWrapperSkillIds.Num()
		|| !bReadsAuthoritativeProviderNeutralState
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToProviderProfileRoutingOnly
		|| !bRequiresAnalyzerWrapperSubstrate
		|| !bRequiresProviderSessionConfigState
		|| !bRequiresProviderServiceHealthState
		|| !bPreservesOpenAiCompatibleCustomEndpointFirstClass
		|| !bPreservesUserLabeledByokProfiles
		|| !bPreservesProviderNeutrality
		|| !bAvoidsProviderSpecificOverlayWidening)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredAnalyzerWrapperSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 ProviderModeCount =
		(bInspectsProviderProfile ? 1 : 0)
		+ (bSetsUpByokProfile ? 1 : 0)
		+ (bDiagnosesRouting ? 1 : 0);
	return ProviderModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillProviderProfileRoutingState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeProviderNeutralState
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bProviderProfileRoutingRemainsBounded
		|| !bEverySkillRequiresAnalyzerWrapperSubstrate
		|| !bEverySkillRequiresProviderSessionConfigState
		|| !bEverySkillRequiresProviderServiceHealthState
		|| !bOpenAiCompatibleCustomEndpointsRemainFirstClass
		|| !bUserLabeledByokProfilesRemainSupported
		|| !bProviderNeutralityRemainsPreserved
		|| !bNoProviderSpecificOverlayWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedProviderProfileInspectionSkillCount = 0;
	int32 ComputedByokProfileSetupSkillCount = 0;
	int32 ComputedRoutingDiagnosticSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeProviderNeutralState = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedProviderProfileRoutingRemainsBounded = true;
	bool bComputedEverySkillRequiresAnalyzerWrapperSubstrate = true;
	bool bComputedEverySkillRequiresProviderSessionConfigState = true;
	bool bComputedEverySkillRequiresProviderServiceHealthState = true;
	bool bComputedOpenAiCompatibleCustomEndpointsRemainFirstClass = true;
	bool bComputedUserLabeledByokProfilesRemainSupported = true;
	bool bComputedProviderNeutralityRemainsPreserved = true;
	bool bComputedNoProviderSpecificOverlayWidening = true;

	for (const FHyperTwistSkillProviderProfileRoutingSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedProviderProfileInspectionSkillCount += Skill.bInspectsProviderProfile ? 1 : 0;
		ComputedByokProfileSetupSkillCount += Skill.bSetsUpByokProfile ? 1 : 0;
		ComputedRoutingDiagnosticSkillCount += Skill.bDiagnosesRouting ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedProviderProfileRoutingRemainsBounded &=
			Skill.bBoundedToProviderProfileRoutingOnly;
		bComputedEverySkillRequiresAnalyzerWrapperSubstrate &=
			Skill.bRequiresAnalyzerWrapperSubstrate;
		bComputedEverySkillRequiresProviderSessionConfigState &=
			Skill.bRequiresProviderSessionConfigState;
		bComputedEverySkillRequiresProviderServiceHealthState &=
			Skill.bRequiresProviderServiceHealthState;
		bComputedOpenAiCompatibleCustomEndpointsRemainFirstClass &=
			Skill.bPreservesOpenAiCompatibleCustomEndpointFirstClass;
		bComputedUserLabeledByokProfilesRemainSupported &=
			Skill.bPreservesUserLabeledByokProfiles;
		bComputedProviderNeutralityRemainsPreserved &=
			Skill.bPreservesProviderNeutrality;
		bComputedNoProviderSpecificOverlayWidening &=
			Skill.bAvoidsProviderSpecificOverlayWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeProviderNeutralState &=
				Skill.bReadsAuthoritativeProviderNeutralState;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& ProviderProfileInspectionSkillCount == ComputedProviderProfileInspectionSkillCount
		&& ByokProfileSetupSkillCount == ComputedByokProfileSetupSkillCount
		&& RoutingDiagnosticSkillCount == ComputedRoutingDiagnosticSkillCount
		&& bEveryLiveSkillReadsAuthoritativeProviderNeutralState
			== bComputedEveryLiveSkillReadsAuthoritativeProviderNeutralState
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bProviderProfileRoutingRemainsBounded
			== bComputedProviderProfileRoutingRemainsBounded
		&& bEverySkillRequiresAnalyzerWrapperSubstrate
			== bComputedEverySkillRequiresAnalyzerWrapperSubstrate
		&& bEverySkillRequiresProviderSessionConfigState
			== bComputedEverySkillRequiresProviderSessionConfigState
		&& bEverySkillRequiresProviderServiceHealthState
			== bComputedEverySkillRequiresProviderServiceHealthState
		&& bOpenAiCompatibleCustomEndpointsRemainFirstClass
			== bComputedOpenAiCompatibleCustomEndpointsRemainFirstClass
		&& bUserLabeledByokProfilesRemainSupported
			== bComputedUserLabeledByokProfilesRemainSupported
		&& bProviderNeutralityRemainsPreserved
			== bComputedProviderNeutralityRemainsPreserved
		&& bNoProviderSpecificOverlayWidening == bComputedNoProviderSpecificOverlayWidening;
}

bool FHyperTwistSkillProviderUsageOperationsAuditSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredProviderProfileRoutingSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredProviderProfileRoutingSkillCount
			!= RequiredProviderProfileRoutingSkillIds.Num()
		|| !bReadsNormalizedFirstPartyState
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToUsageOperationsAuditOnly
		|| !bRequiresProviderProfileRoutingSubstrate
		|| !bRequiresUsageCostAccountingState
		|| !bRequiresRouteAndServiceHealthState
		|| !bPreservesNormalizedFirstPartyAccountingOwnership
		|| !bAvoidsSettlementExecutionWidening
		|| !bAvoidsProviderPortalWidening)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredProviderProfileRoutingSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 AuditModeCount =
		(bAuditsUsage ? 1 : 0)
		+ (bInspectsTopology ? 1 : 0)
		+ (bDiagnosesRouteService ? 1 : 0);
	return AuditModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillProviderUsageOperationsAuditState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsNormalizedFirstPartyState
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bUsageOperationsAuditRemainsBounded
		|| !bEverySkillRequiresProviderProfileRoutingSubstrate
		|| !bEverySkillRequiresUsageCostAccountingState
		|| !bEverySkillRequiresRouteAndServiceHealthState
		|| !bNormalizedFirstPartyAccountingOwnershipPreserved
		|| !bNoSettlementExecutionWidening
		|| !bNoProviderPortalWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedUsageAuditSkillCount = 0;
	int32 ComputedTopologyInspectionSkillCount = 0;
	int32 ComputedRouteServiceDiagnosticSkillCount = 0;
	bool bComputedEveryLiveSkillReadsNormalizedFirstPartyState = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedUsageOperationsAuditRemainsBounded = true;
	bool bComputedEverySkillRequiresProviderProfileRoutingSubstrate = true;
	bool bComputedEverySkillRequiresUsageCostAccountingState = true;
	bool bComputedEverySkillRequiresRouteAndServiceHealthState = true;
	bool bComputedNormalizedFirstPartyAccountingOwnershipPreserved = true;
	bool bComputedNoSettlementExecutionWidening = true;
	bool bComputedNoProviderPortalWidening = true;

	for (const FHyperTwistSkillProviderUsageOperationsAuditSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedUsageAuditSkillCount += Skill.bAuditsUsage ? 1 : 0;
		ComputedTopologyInspectionSkillCount += Skill.bInspectsTopology ? 1 : 0;
		ComputedRouteServiceDiagnosticSkillCount += Skill.bDiagnosesRouteService ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedUsageOperationsAuditRemainsBounded &=
			Skill.bBoundedToUsageOperationsAuditOnly;
		bComputedEverySkillRequiresProviderProfileRoutingSubstrate &=
			Skill.bRequiresProviderProfileRoutingSubstrate;
		bComputedEverySkillRequiresUsageCostAccountingState &=
			Skill.bRequiresUsageCostAccountingState;
		bComputedEverySkillRequiresRouteAndServiceHealthState &=
			Skill.bRequiresRouteAndServiceHealthState;
		bComputedNormalizedFirstPartyAccountingOwnershipPreserved &=
			Skill.bPreservesNormalizedFirstPartyAccountingOwnership;
		bComputedNoSettlementExecutionWidening &= Skill.bAvoidsSettlementExecutionWidening;
		bComputedNoProviderPortalWidening &= Skill.bAvoidsProviderPortalWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsNormalizedFirstPartyState &=
				Skill.bReadsNormalizedFirstPartyState;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& UsageAuditSkillCount == ComputedUsageAuditSkillCount
		&& TopologyInspectionSkillCount == ComputedTopologyInspectionSkillCount
		&& RouteServiceDiagnosticSkillCount == ComputedRouteServiceDiagnosticSkillCount
		&& bEveryLiveSkillReadsNormalizedFirstPartyState
			== bComputedEveryLiveSkillReadsNormalizedFirstPartyState
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bUsageOperationsAuditRemainsBounded
			== bComputedUsageOperationsAuditRemainsBounded
		&& bEverySkillRequiresProviderProfileRoutingSubstrate
			== bComputedEverySkillRequiresProviderProfileRoutingSubstrate
		&& bEverySkillRequiresUsageCostAccountingState
			== bComputedEverySkillRequiresUsageCostAccountingState
		&& bEverySkillRequiresRouteAndServiceHealthState
			== bComputedEverySkillRequiresRouteAndServiceHealthState
		&& bNormalizedFirstPartyAccountingOwnershipPreserved
			== bComputedNormalizedFirstPartyAccountingOwnershipPreserved
		&& bNoSettlementExecutionWidening == bComputedNoSettlementExecutionWidening
		&& bNoProviderPortalWidening == bComputedNoProviderPortalWidening;
}

bool FHyperTwistSkillDomainPackFrameworkSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredPlanOrchestrationSkillIds.Num() == 0
		|| RequiredProviderUsageAuditSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredPlanOrchestrationSkillCount
			!= RequiredPlanOrchestrationSkillIds.Num()
		|| RequiredProviderUsageAuditSkillCount
			!= RequiredProviderUsageAuditSkillIds.Num()
		|| !bReadsAuthoritativeSkillAndFrameworkState
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToDomainPackFrameworkOnly
		|| !bRequiresPlanOrchestrationSubstrate
		|| !bRequiresProviderUsageOperationsAuditSubstrate
		|| !bPreservesPlaceholderDomainPackDeferral
		|| !bAvoidsRetainedDomainPackClaims
		|| !bAvoidsCreativeMediaWidening)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredPlanOrchestrationSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredProviderUsageAuditSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 FrameworkModeCount =
		(bSpecifiesPackagingRules ? 1 : 0)
		+ (bSpecifiesEnableDisableGrouping ? 1 : 0);
	return FrameworkModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillDomainPackFrameworkState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeSkillAndFrameworkState
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bDomainPackFrameworkRemainsBounded
		|| !bEverySkillRequiresPlanOrchestrationSubstrate
		|| !bEverySkillRequiresProviderUsageOperationsAuditSubstrate
		|| !bPlaceholderDomainPackDeferralRemainsPreserved
		|| !bNoRetainedDomainPackClaims
		|| !bNoCreativeMediaWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedPackagingRuleSkillCount = 0;
	int32 ComputedEnableDisableGroupingSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeSkillAndFrameworkState = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedDomainPackFrameworkRemainsBounded = true;
	bool bComputedEverySkillRequiresPlanOrchestrationSubstrate = true;
	bool bComputedEverySkillRequiresProviderUsageOperationsAuditSubstrate = true;
	bool bComputedPlaceholderDomainPackDeferralRemainsPreserved = true;
	bool bComputedNoRetainedDomainPackClaims = true;
	bool bComputedNoCreativeMediaWidening = true;

	for (const FHyperTwistSkillDomainPackFrameworkSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedPackagingRuleSkillCount += Skill.bSpecifiesPackagingRules ? 1 : 0;
		ComputedEnableDisableGroupingSkillCount +=
			Skill.bSpecifiesEnableDisableGrouping ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedDomainPackFrameworkRemainsBounded &=
			Skill.bBoundedToDomainPackFrameworkOnly;
		bComputedEverySkillRequiresPlanOrchestrationSubstrate &=
			Skill.bRequiresPlanOrchestrationSubstrate;
		bComputedEverySkillRequiresProviderUsageOperationsAuditSubstrate &=
			Skill.bRequiresProviderUsageOperationsAuditSubstrate;
		bComputedPlaceholderDomainPackDeferralRemainsPreserved &=
			Skill.bPreservesPlaceholderDomainPackDeferral;
		bComputedNoRetainedDomainPackClaims &=
			Skill.bAvoidsRetainedDomainPackClaims;
		bComputedNoCreativeMediaWidening &=
			Skill.bAvoidsCreativeMediaWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeSkillAndFrameworkState &=
				Skill.bReadsAuthoritativeSkillAndFrameworkState;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& PackagingRuleSkillCount == ComputedPackagingRuleSkillCount
		&& EnableDisableGroupingSkillCount
			== ComputedEnableDisableGroupingSkillCount
		&& bEveryLiveSkillReadsAuthoritativeSkillAndFrameworkState
			== bComputedEveryLiveSkillReadsAuthoritativeSkillAndFrameworkState
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bDomainPackFrameworkRemainsBounded
			== bComputedDomainPackFrameworkRemainsBounded
		&& bEverySkillRequiresPlanOrchestrationSubstrate
			== bComputedEverySkillRequiresPlanOrchestrationSubstrate
		&& bEverySkillRequiresProviderUsageOperationsAuditSubstrate
			== bComputedEverySkillRequiresProviderUsageOperationsAuditSubstrate
		&& bPlaceholderDomainPackDeferralRemainsPreserved
			== bComputedPlaceholderDomainPackDeferralRemainsPreserved
		&& bNoRetainedDomainPackClaims == bComputedNoRetainedDomainPackClaims
		&& bNoCreativeMediaWidening == bComputedNoCreativeMediaWidening;
}

bool FHyperTwistSkillRetainedDomainPackSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredDomainPackFrameworkSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredDomainPackFrameworkSkillCount
			!= RequiredDomainPackFrameworkSkillIds.Num()
		|| !bReadsAuthoritativeFirstPartyDomainState
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToRetainedDomainPackOnly
		|| !bRequiresDomainPackFrameworkSubstrate
		|| !bPreservesFirstPartyRetainedPackGrounding
		|| !bPreservesUnlandedPackDeferral
		|| !bAvoidsCreativeAdjunctWidening)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredDomainPackFrameworkSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 PackModeCount =
		(bReadsTrainingReplayState ? 1 : 0)
		+ (bReadsCurriculumContentState ? 1 : 0)
		+ (bReadsMediaExportState ? 1 : 0);
	return PackModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillRetainedDomainPackState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeFirstPartyDomainState
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bRetainedDomainPackLayerRemainsBounded
		|| !bEverySkillRequiresDomainPackFrameworkSubstrate
		|| !bRetainedPackClaimsRemainFirstPartyGrounded
		|| !bUnlandedPackDeferralRemainsPreserved
		|| !bNoCreativeAdjunctWidening)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedTrainingReplayPackSkillCount = 0;
	int32 ComputedCurriculumContentPackSkillCount = 0;
	int32 ComputedMediaExportPackSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeFirstPartyDomainState = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedRetainedDomainPackLayerRemainsBounded = true;
	bool bComputedEverySkillRequiresDomainPackFrameworkSubstrate = true;
	bool bComputedRetainedPackClaimsRemainFirstPartyGrounded = true;
	bool bComputedUnlandedPackDeferralRemainsPreserved = true;
	bool bComputedNoCreativeAdjunctWidening = true;

	for (const FHyperTwistSkillRetainedDomainPackSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedTrainingReplayPackSkillCount +=
			Skill.bReadsTrainingReplayState ? 1 : 0;
		ComputedCurriculumContentPackSkillCount +=
			Skill.bReadsCurriculumContentState ? 1 : 0;
		ComputedMediaExportPackSkillCount +=
			Skill.bReadsMediaExportState ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedRetainedDomainPackLayerRemainsBounded &=
			Skill.bBoundedToRetainedDomainPackOnly;
		bComputedEverySkillRequiresDomainPackFrameworkSubstrate &=
			Skill.bRequiresDomainPackFrameworkSubstrate;
		bComputedRetainedPackClaimsRemainFirstPartyGrounded &=
			Skill.bPreservesFirstPartyRetainedPackGrounding;
		bComputedUnlandedPackDeferralRemainsPreserved &=
			Skill.bPreservesUnlandedPackDeferral;
		bComputedNoCreativeAdjunctWidening &=
			Skill.bAvoidsCreativeAdjunctWidening;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeFirstPartyDomainState &=
				Skill.bReadsAuthoritativeFirstPartyDomainState;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& TrainingReplayPackSkillCount
			== ComputedTrainingReplayPackSkillCount
		&& CurriculumContentPackSkillCount
			== ComputedCurriculumContentPackSkillCount
		&& MediaExportPackSkillCount == ComputedMediaExportPackSkillCount
		&& bEveryLiveSkillReadsAuthoritativeFirstPartyDomainState
			== bComputedEveryLiveSkillReadsAuthoritativeFirstPartyDomainState
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bRetainedDomainPackLayerRemainsBounded
			== bComputedRetainedDomainPackLayerRemainsBounded
		&& bEverySkillRequiresDomainPackFrameworkSubstrate
			== bComputedEverySkillRequiresDomainPackFrameworkSubstrate
		&& bRetainedPackClaimsRemainFirstPartyGrounded
			== bComputedRetainedPackClaimsRemainFirstPartyGrounded
		&& bUnlandedPackDeferralRemainsPreserved
			== bComputedUnlandedPackDeferralRemainsPreserved
		&& bNoCreativeAdjunctWidening
			== bComputedNoCreativeAdjunctWidening;
}

bool FHyperTwistSkillCreativeMediaPackSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| SourceSurfaceIds.Num() == 0
		|| RequiredRetainedDomainPackSkillIds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| SourceSurfaceCount != SourceSurfaceIds.Num()
		|| RequiredRetainedDomainPackSkillCount
			!= RequiredRetainedDomainPackSkillIds.Num()
		|| !bReadsAuthoritativeFirstPartyCreativeMediaState
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bBoundedToCreativeMediaPackOnly
		|| !bRequiresRetainedDomainPackSubstrate
		|| !bCreativeMediaAdjunctOnly
		|| !bAvoidsCoreRuntimePromotion
		|| !bBoundarySensitiveLicensingRemainsExplicit)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(SourceSurfaceIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredRetainedDomainPackSkillIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	const int32 PackModeCount =
		(bReadsReplayExplainerState ? 1 : 0)
		+ (bReadsMediaParserState ? 1 : 0)
		+ (bReadsSharedFixtureState ? 1 : 0);
	return PackModeCount == 1
		&& Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillCreativeMediaPackState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeFirstPartyCreativeMediaState
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bCreativeMediaPackLayerRemainsBounded
		|| !bEverySkillRequiresRetainedDomainPackSubstrate
		|| !bCreativeMediaAdjunctsRemainOptional
		|| !bNoCoreRuntimePromotion
		|| !bBoundarySensitiveLicensingRemainsExplicit)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedReplayExplainerPackSkillCount = 0;
	int32 ComputedMediaParserPackSkillCount = 0;
	int32 ComputedSharedFixturePackSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeFirstPartyCreativeMediaState =
		true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedCreativeMediaPackLayerRemainsBounded = true;
	bool bComputedEverySkillRequiresRetainedDomainPackSubstrate = true;
	bool bComputedCreativeMediaAdjunctsRemainOptional = true;
	bool bComputedNoCoreRuntimePromotion = true;
	bool bComputedBoundarySensitiveLicensingRemainsExplicit = true;

	for (const FHyperTwistSkillCreativeMediaPackSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedReplayExplainerPackSkillCount +=
			Skill.bReadsReplayExplainerState ? 1 : 0;
		ComputedMediaParserPackSkillCount +=
			Skill.bReadsMediaParserState ? 1 : 0;
		ComputedSharedFixturePackSkillCount +=
			Skill.bReadsSharedFixtureState ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedCreativeMediaPackLayerRemainsBounded &=
			Skill.bBoundedToCreativeMediaPackOnly;
		bComputedEverySkillRequiresRetainedDomainPackSubstrate &=
			Skill.bRequiresRetainedDomainPackSubstrate;
		bComputedCreativeMediaAdjunctsRemainOptional &=
			Skill.bCreativeMediaAdjunctOnly;
		bComputedNoCoreRuntimePromotion &= Skill.bAvoidsCoreRuntimePromotion;
		bComputedBoundarySensitiveLicensingRemainsExplicit &=
			Skill.bBoundarySensitiveLicensingRemainsExplicit;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeFirstPartyCreativeMediaState &=
				Skill.bReadsAuthoritativeFirstPartyCreativeMediaState;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& ReplayExplainerPackSkillCount
			== ComputedReplayExplainerPackSkillCount
		&& MediaParserPackSkillCount == ComputedMediaParserPackSkillCount
		&& SharedFixturePackSkillCount == ComputedSharedFixturePackSkillCount
		&& bEveryLiveSkillReadsAuthoritativeFirstPartyCreativeMediaState
			== bComputedEveryLiveSkillReadsAuthoritativeFirstPartyCreativeMediaState
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bCreativeMediaPackLayerRemainsBounded
			== bComputedCreativeMediaPackLayerRemainsBounded
		&& bEverySkillRequiresRetainedDomainPackSubstrate
			== bComputedEverySkillRequiresRetainedDomainPackSubstrate
		&& bCreativeMediaAdjunctsRemainOptional
			== bComputedCreativeMediaAdjunctsRemainOptional
		&& bNoCoreRuntimePromotion == bComputedNoCoreRuntimePromotion
		&& bBoundarySensitiveLicensingRemainsExplicit
			== bComputedBoundarySensitiveLicensingRemainsExplicit;
}

bool FHyperTwistSkillAnalyzerWrapperState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Outputs.Num() == 0
		|| SkillCount <= 0
		|| OutputCount != Outputs.Num()
		|| ArchitectureScanCount < 0
		|| PolicyScanCount < 0
		|| RouteInspectionCount < 0
		|| WatchAndRecheckCount < 0
		|| !bEveryWrapperMapsToStableInvocationPattern
		|| !bEveryWrapperEmitsStructuredOutput
		|| !bOnlyImplementedPermissiveWrappersIncluded)
	{
		return false;
	}

	TArray<FString> SeenOutputIds;
	TArray<FString> SeenSkillIds;
	int32 ComputedArchitectureScanCount = 0;
	int32 ComputedPolicyScanCount = 0;
	int32 ComputedRouteInspectionCount = 0;
	int32 ComputedWatchAndRecheckCount = 0;
	bool bComputedStableInvocationPattern = true;
	bool bComputedStructuredOutput = true;
	bool bComputedOnlyImplementedPermissiveWrappersIncluded = true;

	for (const FHyperTwistSkillAnalyzerWrapperOutput& Output : Outputs)
	{
		if (!Output.IsStructurallyValid() || SeenOutputIds.Contains(Output.WrapperOutputId))
		{
			return false;
		}

		SeenOutputIds.Add(Output.WrapperOutputId);
		SeenSkillIds.AddUnique(Output.SkillId);
		bComputedStableInvocationPattern &= Output.bStableInvocationPattern;
		bComputedStructuredOutput &= Output.bStructuredOutput;
		bComputedOnlyImplementedPermissiveWrappersIncluded &=
			HyperTwistSkillTypesInternal::IsImplementedPermissiveWrapperSkillId(Output.SkillId);

		if (Output.OutputKindId == TEXT("wrapper-output/architecture-scan"))
		{
			ComputedArchitectureScanCount += 1;
		}
		else if (Output.OutputKindId == TEXT("wrapper-output/policy-scan"))
		{
			ComputedPolicyScanCount += 1;
		}
		else if (Output.OutputKindId == TEXT("wrapper-output/route-inspection"))
		{
			ComputedRouteInspectionCount += 1;
		}
		else if (Output.OutputKindId == TEXT("wrapper-output/watch-and-recheck"))
		{
			ComputedWatchAndRecheckCount += 1;
		}
		else
		{
			return false;
		}
	}

	return SkillCount == SeenSkillIds.Num()
		&& ArchitectureScanCount == ComputedArchitectureScanCount
		&& PolicyScanCount == ComputedPolicyScanCount
		&& RouteInspectionCount == ComputedRouteInspectionCount
		&& WatchAndRecheckCount == ComputedWatchAndRecheckCount
		&& bEveryWrapperMapsToStableInvocationPattern == bComputedStableInvocationPattern
		&& bEveryWrapperEmitsStructuredOutput == bComputedStructuredOutput
		&& bOnlyImplementedPermissiveWrappersIncluded
			== bComputedOnlyImplementedPermissiveWrappersIncluded;
}

bool FHyperTwistSkillCleanRoomCommandContractSpec::IsStructurallyValid() const
{
	if (SpecId.IsEmpty()
		|| SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| InvocationPattern.IsEmpty()
		|| ArtifactKind.IsEmpty()
		|| PermissionScopeIds.Num() == 0
		|| RequiredTemplateSectionIds.Num() == 0
		|| SafetyRuleIds.Num() == 0
		|| SmokeExecutionMode != EHyperTwistSkillValidationExecutionMode::DeclarationOnly
		|| EvalExecutionMode
			!= EHyperTwistSkillValidationExecutionMode::DeferredUntilCleanRoomSkillSpec
		|| !bUsesFirstPartyTermsOnly
		|| !bAvoidsDonorWording
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bRequiresProvenanceLedger
		|| !bNoProductTruthMutation
		|| !bFutureWrapperMayBindWithoutContractRewrite)
	{
		return false;
	}

	return HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredTemplateSectionIds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(SafetyRuleIds);
}

bool FHyperTwistSkillCleanRoomCommandContractState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Specs.Num() == 0
		|| SkillCount <= 0
		|| SpecCount != Specs.Num()
		|| SafetyRuleCount <= 0
		|| !bEverySpecUsesFirstPartyTerms
		|| !bEverySpecAvoidsDonorWording
		|| !bEverySpecPreservesOptionalAssistiveOffState
		|| !bEverySpecRestrictsToDerivedAssistiveOutput
		|| !bEverySpecRequiresProvenanceLedger
		|| !bEverySpecAvoidsProductTruthMutation
		|| !bEverySpecMayBindFutureWrapperWithoutContractRewrite
		|| !bEverySpecHasAuthoringHarnessCoverage
		|| !bEverySpecDefersEvalUntilCleanRoomSkillSpec)
	{
		return false;
	}

	TArray<FString> SeenSpecIds;
	TArray<FString> SeenSkillIds;
	TArray<FString> SeenSafetyRuleIds;
	bool bComputedFirstPartyTerms = true;
	bool bComputedAvoidsDonorWording = true;
	bool bComputedPreservesOffState = true;
	bool bComputedDerivedAssistiveOnly = true;
	bool bComputedRequiresProvenanceLedger = true;
	bool bComputedAvoidsProductTruthMutation = true;
	bool bComputedMayBindWithoutRewrite = true;
	bool bComputedHasHarnessCoverage = true;
	bool bComputedDefersEvalUntilSkillSpec = true;

	for (const FHyperTwistSkillCleanRoomCommandContractSpec& Spec : Specs)
	{
		if (!Spec.IsStructurallyValid() || SeenSpecIds.Contains(Spec.SpecId))
		{
			return false;
		}

		SeenSpecIds.Add(Spec.SpecId);
		SeenSkillIds.AddUnique(Spec.SkillId);
		bComputedFirstPartyTerms &= Spec.bUsesFirstPartyTermsOnly;
		bComputedAvoidsDonorWording &= Spec.bAvoidsDonorWording;
		bComputedPreservesOffState &= Spec.bPreservesOptionalAssistiveOffState;
		bComputedDerivedAssistiveOnly &= Spec.bDerivedAssistiveOnly;
		bComputedRequiresProvenanceLedger &= Spec.bRequiresProvenanceLedger;
		bComputedAvoidsProductTruthMutation &= Spec.bNoProductTruthMutation;
		bComputedMayBindWithoutRewrite &= Spec.bFutureWrapperMayBindWithoutContractRewrite;
		bComputedHasHarnessCoverage &= Spec.RequiredTemplateSectionIds.Num() > 0;
		bComputedDefersEvalUntilSkillSpec &=
			Spec.EvalExecutionMode
			== EHyperTwistSkillValidationExecutionMode::DeferredUntilCleanRoomSkillSpec;

		for (const FString& SafetyRuleId : Spec.SafetyRuleIds)
		{
			SeenSafetyRuleIds.AddUnique(SafetyRuleId);
		}
	}

	return SkillCount == SeenSkillIds.Num()
		&& SafetyRuleCount == SeenSafetyRuleIds.Num()
		&& bEverySpecUsesFirstPartyTerms == bComputedFirstPartyTerms
		&& bEverySpecAvoidsDonorWording == bComputedAvoidsDonorWording
		&& bEverySpecPreservesOptionalAssistiveOffState == bComputedPreservesOffState
		&& bEverySpecRestrictsToDerivedAssistiveOutput == bComputedDerivedAssistiveOnly
		&& bEverySpecRequiresProvenanceLedger == bComputedRequiresProvenanceLedger
		&& bEverySpecAvoidsProductTruthMutation == bComputedAvoidsProductTruthMutation
		&& bEverySpecMayBindFutureWrapperWithoutContractRewrite == bComputedMayBindWithoutRewrite
		&& bEverySpecHasAuthoringHarnessCoverage == bComputedHasHarnessCoverage
		&& bEverySpecDefersEvalUntilCleanRoomSkillSpec == bComputedDefersEvalUntilSkillSpec;
}

bool FHyperTwistSkillCleanRoomSkillSpec::IsStructurallyValid() const
{
	if (SkillSpecId.IsEmpty()
		|| SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandContractSpecId.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| InputStateKinds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| SpecStepIds.Num() == 0
		|| SafetyRuleIds.Num() == 0
		|| RequiredTemplateSectionIds.Num() == 0
		|| SmokeExecutionMode != EHyperTwistSkillValidationExecutionMode::DeclarationOnly
		|| EvalExecutionMode != EHyperTwistSkillValidationExecutionMode::DeclarationOnly
		|| !bUsesFirstPartyTermsOnly
		|| !bAvoidsDonorWording
		|| !bSpecReadyForFutureImplementation
		|| !bNotLiveImplementationYet
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bRequiresProvenanceLedger
		|| !bNoProductTruthMutation)
	{
		return false;
	}

	return HyperTwistSkillTypesInternal::AreAllStringsPopulated(InputStateKinds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(SpecStepIds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(SafetyRuleIds)
		&& HyperTwistSkillTypesInternal::AreAllStringsPopulated(RequiredTemplateSectionIds);
}

bool FHyperTwistSkillCleanRoomSkillSpecState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Specs.Num() == 0
		|| SkillCount <= 0
		|| SpecCount != Specs.Num()
		|| StepCount <= 0
		|| SafetyRuleCount <= 0
		|| !bEverySpecUsesFirstPartyTerms
		|| !bEverySpecAvoidsDonorWording
		|| !bEverySpecBindsToCommandContractState
		|| !bEverySpecReadyForFutureImplementation
		|| !bNoSpecClaimsLiveImplementation
		|| !bEverySpecPreservesOptionalAssistiveOffState
		|| !bEverySpecRestrictsToDerivedAssistiveOutput
		|| !bEverySpecRequiresProvenanceLedger
		|| !bEverySpecAvoidsProductTruthMutation
		|| !bEverySpecHasAuthoringHarnessCoverage
		|| !bEverySpecUsesDeclarationOnlyValidation)
	{
		return false;
	}

	TArray<FString> SeenSpecIds;
	TArray<FString> SeenSkillIds;
	TArray<FString> SeenStepIds;
	TArray<FString> SeenSafetyRuleIds;
	bool bComputedFirstPartyTerms = true;
	bool bComputedAvoidsDonorWording = true;
	bool bComputedBindsToCommandContractState = true;
	bool bComputedReadyForFutureImplementation = true;
	bool bComputedNoLiveImplementation = true;
	bool bComputedPreservesOffState = true;
	bool bComputedDerivedAssistiveOnly = true;
	bool bComputedRequiresProvenanceLedger = true;
	bool bComputedAvoidsProductTruthMutation = true;
	bool bComputedHasHarnessCoverage = true;
	bool bComputedUsesDeclarationOnlyValidation = true;

	for (const FHyperTwistSkillCleanRoomSkillSpec& Spec : Specs)
	{
		if (!Spec.IsStructurallyValid() || SeenSpecIds.Contains(Spec.SkillSpecId))
		{
			return false;
		}

		SeenSpecIds.Add(Spec.SkillSpecId);
		SeenSkillIds.AddUnique(Spec.SkillId);
		bComputedFirstPartyTerms &= Spec.bUsesFirstPartyTermsOnly;
		bComputedAvoidsDonorWording &= Spec.bAvoidsDonorWording;
		bComputedBindsToCommandContractState &= !Spec.CommandContractSpecId.IsEmpty();
		bComputedReadyForFutureImplementation &= Spec.bSpecReadyForFutureImplementation;
		bComputedNoLiveImplementation &= Spec.bNotLiveImplementationYet;
		bComputedPreservesOffState &= Spec.bPreservesOptionalAssistiveOffState;
		bComputedDerivedAssistiveOnly &= Spec.bDerivedAssistiveOnly;
		bComputedRequiresProvenanceLedger &= Spec.bRequiresProvenanceLedger;
		bComputedAvoidsProductTruthMutation &= Spec.bNoProductTruthMutation;
		bComputedHasHarnessCoverage &= Spec.RequiredTemplateSectionIds.Num() > 0;
		bComputedUsesDeclarationOnlyValidation &=
			Spec.SmokeExecutionMode == EHyperTwistSkillValidationExecutionMode::DeclarationOnly
			&& Spec.EvalExecutionMode == EHyperTwistSkillValidationExecutionMode::DeclarationOnly;

		for (const FString& StepId : Spec.SpecStepIds)
		{
			SeenStepIds.AddUnique(StepId);
		}

		for (const FString& SafetyRuleId : Spec.SafetyRuleIds)
		{
			SeenSafetyRuleIds.AddUnique(SafetyRuleId);
		}
	}

	return SkillCount == SeenSkillIds.Num()
		&& StepCount == SeenStepIds.Num()
		&& SafetyRuleCount == SeenSafetyRuleIds.Num()
		&& bEverySpecUsesFirstPartyTerms == bComputedFirstPartyTerms
		&& bEverySpecAvoidsDonorWording == bComputedAvoidsDonorWording
		&& bEverySpecBindsToCommandContractState == bComputedBindsToCommandContractState
		&& bEverySpecReadyForFutureImplementation == bComputedReadyForFutureImplementation
		&& bNoSpecClaimsLiveImplementation == bComputedNoLiveImplementation
		&& bEverySpecPreservesOptionalAssistiveOffState == bComputedPreservesOffState
		&& bEverySpecRestrictsToDerivedAssistiveOutput == bComputedDerivedAssistiveOnly
		&& bEverySpecRequiresProvenanceLedger == bComputedRequiresProvenanceLedger
		&& bEverySpecAvoidsProductTruthMutation == bComputedAvoidsProductTruthMutation
		&& bEverySpecHasAuthoringHarnessCoverage == bComputedHasHarnessCoverage
		&& bEverySpecUsesDeclarationOnlyValidation == bComputedUsesDeclarationOnlyValidation;
}

bool FHyperTwistSkillContinuityResumeSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| InputStateKinds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| AvailableItemCount < 0
		|| BlockingItemCount < 0
		|| !bReadsAuthoritativeStores
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(InputStateKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	if (Status == EHyperTwistSkillStatus::ImplementedNow)
	{
		return bLiveSkill && bAvailableNow && !bRequiresOwnerActivation;
	}

	if (Status == EHyperTwistSkillStatus::CommandContractPending)
	{
		return !bLiveSkill && !bAvailableNow && bRequiresOwnerActivation;
	}

	return false;
}

bool FHyperTwistSkillContinuityResumeState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeStores
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bNoSkillClaimsActiveUserNoteCaptureWithoutOwnerActivation)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedPendingSkillCount = 0;
	int32 ComputedResumeSessionSkillCount = 0;
	int32 ComputedSearchHistorySkillCount = 0;
	int32 ComputedCaptureNoteSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeStores = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedCaptureNoteGuard = false;

	for (const FHyperTwistSkillContinuityResumeSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedPendingSkillCount +=
			Skill.Status == EHyperTwistSkillStatus::CommandContractPending ? 1 : 0;
		ComputedResumeSessionSkillCount +=
			Skill.SkillId == TEXT("skill/resume-session") ? 1 : 0;
		ComputedSearchHistorySkillCount +=
			Skill.SkillId == TEXT("skill/search-history") ? 1 : 0;
		ComputedCaptureNoteSkillCount +=
			Skill.SkillId == TEXT("skill/capture-note") ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeStores &= Skill.bReadsAuthoritativeStores;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}

		if (Skill.SkillId == TEXT("skill/capture-note"))
		{
			bComputedCaptureNoteGuard =
				!Skill.bLiveSkill && !Skill.bAvailableNow && Skill.bRequiresOwnerActivation;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& PendingSkillCount == ComputedPendingSkillCount
		&& ResumeSessionSkillCount == ComputedResumeSessionSkillCount
		&& SearchHistorySkillCount == ComputedSearchHistorySkillCount
		&& CaptureNoteSkillCount == ComputedCaptureNoteSkillCount
		&& bEveryLiveSkillReadsAuthoritativeStores
			== bComputedEveryLiveSkillReadsAuthoritativeStores
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bNoSkillClaimsActiveUserNoteCaptureWithoutOwnerActivation
			== bComputedCaptureNoteGuard;
}

bool FHyperTwistSkillRecallCompactViewSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| InputStateKinds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| AvailableItemCount < 0
		|| LinkedSourceCount <= 0
		|| !bReadsAuthoritativeStores
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bLinkedToAuthoritativeSources)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(InputStateKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	return Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillRecallCompactViewState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeStores
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bCompactViewsRemainOptionalAndLinkedToAuthoritativeSources)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedRecallMemorySkillCount = 0;
	int32 ComputedGenerateCompactViewSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeStores = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedCompactViewGuard = false;

	for (const FHyperTwistSkillRecallCompactViewSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedRecallMemorySkillCount += Skill.SkillId == TEXT("skill/recall-memory") ? 1 : 0;
		ComputedGenerateCompactViewSkillCount +=
			Skill.SkillId == TEXT("skill/generate-compact-view") ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeStores &= Skill.bReadsAuthoritativeStores;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}

		if (Skill.SkillId == TEXT("skill/generate-compact-view"))
		{
			bComputedCompactViewGuard =
				Skill.bOptionalCompactView && Skill.bLinkedToAuthoritativeSources;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& RecallMemorySkillCount == ComputedRecallMemorySkillCount
		&& GenerateCompactViewSkillCount == ComputedGenerateCompactViewSkillCount
		&& bEveryLiveSkillReadsAuthoritativeStores
			== bComputedEveryLiveSkillReadsAuthoritativeStores
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bCompactViewsRemainOptionalAndLinkedToAuthoritativeSources
			== bComputedCompactViewGuard;
}

bool FHyperTwistSkillWorkflowMemoryCaptureSkill::IsStructurallyValid() const
{
	if (SkillId.IsEmpty()
		|| DisplayLabel.IsEmpty()
		|| CommandSurfaceId.IsEmpty()
		|| ServiceBindingId.IsEmpty()
		|| OwnerLaneId.IsEmpty()
		|| OwnerFeatureId.IsEmpty()
		|| Status == EHyperTwistSkillStatus::None
		|| PermissionScopeIds.Num() == 0
		|| InputStateKinds.Num() == 0
		|| OutputArtifactKinds.Num() == 0
		|| PreviewHeadlines.Num() == 0
		|| AvailableItemCount <= 0
		|| LinkedWorkflowEntityCount <= 0
		|| BlockingItemCount < 0
		|| !bReadsAuthoritativeStores
		|| !bPreservesOptionalAssistiveOffState
		|| !bDerivedAssistiveOnly
		|| !bHasValidationHarnessCoverage
		|| !bAvoidsUserAuthoredNoteCapture
		|| !bAvoidsOpaqueSummaryCollapse)
	{
		return false;
	}

	if (!HyperTwistSkillTypesInternal::AreAllStringsPopulated(PermissionScopeIds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(InputStateKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(OutputArtifactKinds)
		|| !HyperTwistSkillTypesInternal::AreAllStringsPopulated(PreviewHeadlines))
	{
		return false;
	}

	return Status == EHyperTwistSkillStatus::ImplementedNow
		&& bLiveSkill
		&& bAvailableNow
		&& !bRequiresOwnerActivation;
}

bool FHyperTwistSkillWorkflowMemoryCaptureState::IsStructurallyValid() const
{
	if (RegistryId.IsEmpty()
		|| ManifestVersion.IsEmpty()
		|| ReferenceUtc.IsEmpty()
		|| CommandSurfaceRootId.IsEmpty()
		|| TemplateVersion.IsEmpty()
		|| Skills.Num() == 0
		|| SkillCount != Skills.Num()
		|| !bEveryLiveSkillReadsAuthoritativeStores
		|| !bEverySkillPreservesOptionalAssistiveOffState
		|| !bEveryLiveSkillHasValidationHarnessCoverage
		|| !bWorkflowMemoryRemainsSeparateFromUserAuthoredNotes
		|| !bWorkflowMemoryDoesNotCollapseIntoOpaqueSummaries)
	{
		return false;
	}

	TArray<FString> SeenSkillIds;
	int32 ComputedLiveSkillCount = 0;
	int32 ComputedAvailableNowCount = 0;
	int32 ComputedCaptureSessionTemplateSkillCount = 0;
	int32 ComputedCaptureFollowUpRoutineSkillCount = 0;
	bool bComputedEveryLiveSkillReadsAuthoritativeStores = true;
	bool bComputedEverySkillPreservesOptionalAssistiveOffState = true;
	bool bComputedEveryLiveSkillHasValidationHarnessCoverage = true;
	bool bComputedUserNoteSeparation = true;
	bool bComputedOpaqueSummaryGuard = true;

	for (const FHyperTwistSkillWorkflowMemoryCaptureSkill& Skill : Skills)
	{
		if (!Skill.IsStructurallyValid() || SeenSkillIds.Contains(Skill.SkillId))
		{
			return false;
		}

		SeenSkillIds.Add(Skill.SkillId);
		ComputedLiveSkillCount += Skill.bLiveSkill ? 1 : 0;
		ComputedAvailableNowCount += Skill.bAvailableNow ? 1 : 0;
		ComputedCaptureSessionTemplateSkillCount +=
			Skill.SkillId == TEXT("skill/capture-session-template") ? 1 : 0;
		ComputedCaptureFollowUpRoutineSkillCount +=
			Skill.SkillId == TEXT("skill/capture-follow-up-routine") ? 1 : 0;
		bComputedEverySkillPreservesOptionalAssistiveOffState &=
			Skill.bPreservesOptionalAssistiveOffState;
		bComputedUserNoteSeparation &= Skill.bAvoidsUserAuthoredNoteCapture;
		bComputedOpaqueSummaryGuard &= Skill.bAvoidsOpaqueSummaryCollapse;

		if (Skill.bLiveSkill)
		{
			bComputedEveryLiveSkillReadsAuthoritativeStores &= Skill.bReadsAuthoritativeStores;
			bComputedEveryLiveSkillHasValidationHarnessCoverage &=
				Skill.bHasValidationHarnessCoverage;
		}
	}

	return LiveSkillCount == ComputedLiveSkillCount
		&& AvailableNowCount == ComputedAvailableNowCount
		&& CaptureSessionTemplateSkillCount == ComputedCaptureSessionTemplateSkillCount
		&& CaptureFollowUpRoutineSkillCount == ComputedCaptureFollowUpRoutineSkillCount
		&& bEveryLiveSkillReadsAuthoritativeStores
			== bComputedEveryLiveSkillReadsAuthoritativeStores
		&& bEverySkillPreservesOptionalAssistiveOffState
			== bComputedEverySkillPreservesOptionalAssistiveOffState
		&& bEveryLiveSkillHasValidationHarnessCoverage
			== bComputedEveryLiveSkillHasValidationHarnessCoverage
		&& bWorkflowMemoryRemainsSeparateFromUserAuthoredNotes
			== bComputedUserNoteSeparation
		&& bWorkflowMemoryDoesNotCollapseIntoOpaqueSummaries
			== bComputedOpaqueSummaryGuard;
}
