#include "HyperTwistTraining/HyperTwistTrainingLearnedSearchLibrary.h"

namespace HyperTwistTrainingLearnedSearchLibraryInternal
{
	const TCHAR* LearnedSearchLicense = TEXT("MIT");
	const TCHAR* LearnedSearchRepo = TEXT("yakupbilen/drl-rubiks-cube");

	FHyperTwistTrainingSourceAttribution MakeDirectDonorAttribution(
		const FString& TrackId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::DirectDonor;
		Attribution.SourceRepo = LearnedSearchRepo;
		Attribution.SourceLicense = LearnedSearchLicense;
		Attribution.SourceTrackId = TrackId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeFirstPartyAttribution(
		const FString& TrackId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceRepo = LearnedSearchRepo;
		Attribution.SourceLicense = LearnedSearchLicense;
		Attribution.SourceTrackId = TrackId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingLearnedSearchPackageReference MakePackageReference(
		const FString& PackageId,
		const FString& Label,
		const FString& ExportPath,
		const FString& OwnershipRole,
		const FString& LicensePosture,
		const FString& Summary,
		const TArray<FString>& RetainedSurfaceTags,
		const TArray<FString>& RequiredNoticeActions,
		const TArray<FString>& ExplicitExclusions,
		const FHyperTwistTrainingSourceAttribution& SourceAttribution
	)
	{
		FHyperTwistTrainingLearnedSearchPackageReference Reference;
		Reference.PackageId = PackageId;
		Reference.Label = Label;
		Reference.ExportPath = ExportPath;
		Reference.OwnershipRole = OwnershipRole;
		Reference.LicensePosture = LicensePosture;
		Reference.Summary = Summary;
		Reference.RetainedSurfaceTags = RetainedSurfaceTags;
		Reference.RequiredNoticeActions = RequiredNoticeActions;
		Reference.ExplicitExclusions = ExplicitExclusions;
		Reference.SourceAttribution = SourceAttribution;
		return Reference;
	}

	void AppendJoined(FString& OutText, const TArray<FString>& Values)
	{
		for (int32 Index = 0; Index < Values.Num(); ++Index)
		{
			if (Index > 0)
			{
				OutText.Append(TEXT(", "));
			}

			OutText.Append(Values[Index]);
		}
	}
}

FHyperTwistTrainingLearnedSearchReferenceBundle
UHyperTwistTrainingLearnedSearchLibrary::BuildBundledLearnedSearchReferenceBundle()
{
	using namespace HyperTwistTrainingLearnedSearchLibraryInternal;

	FHyperTwistTrainingLearnedSearchReferenceBundle Bundle;
	Bundle.ReferenceUtc = TEXT("2026-05-31T06:05:00Z");
	Bundle.PrimaryExperimentProfileContractId = TEXT("learned-search-experiment-profile");
	Bundle.PrimaryAdiGenerationBoundaryId = TEXT("learned-search-adi-generation-boundary");
	Bundle.PrimarySearchBenchmarkBoundaryId = TEXT("learned-search-search-benchmark-boundary");
	Bundle.PrimaryAttributionBoundaryId = TEXT("learned-search-attribution-boundary");
	Bundle.PrimarySequencePolicyContractId = TEXT("learned-search-sequence-policy-contract");
	Bundle.PrimarySearchBudgetBoundaryId = TEXT("learned-search-search-budget-boundary");
	Bundle.PrimaryNodeIdentityContractId = TEXT("learned-search-node-identity-contract");
	Bundle.PrimaryStateExpansionBoundaryId = TEXT("learned-search-state-expansion-boundary");
	Bundle.PrimaryFrontierScoringBoundaryId = TEXT("learned-search-frontier-scoring-boundary");
	Bundle.PrimarySolutionUnwindBoundaryId = TEXT("learned-search-solution-unwind-boundary");
	Bundle.PrimaryValueNetworkShapeBoundaryId = TEXT("learned-search-value-network-shape-boundary");
	Bundle.PrimaryGeneratorSyncBoundaryId = TEXT("learned-search-generator-sync-boundary");

	const TArray<FString> CommonNoticeActions =
	{
		TEXT("preserve the upstream MIT license text in third-party notices or equivalent release/legal materials"),
		TEXT("preserve the upstream copyright notice for Yakup Bilen")
	};

	Bundle.PackageReferences =
	{
		MakePackageReference(
			TEXT("package/yakupbilen-cube-state"),
			TEXT("cube/cube.py"),
			TEXT("./cube/cube.py"),
			TEXT("learned-search-state-benchmark-anchor"),
			TEXT("direct permissive donor benchmark"),
			TEXT("Compact `54`-sticker state encoding, direct move-transition tables, inverse-solution recovery, and anti-cancellation sequence cleanup for bounded first-party experimentation."),
			{
				TEXT("54-sticker state encoding"),
				TEXT("direct move-transition tables"),
				TEXT("inverse-solution recovery"),
				TEXT("anti-cancellation sequence cleanup")
			},
			CommonNoticeActions,
			{
				TEXT("live camera recognition ownership"),
				TEXT("committed-face reconstruction ownership"),
				TEXT("generalized solver backend ownership")
			},
			MakeDirectDonorAttribution(
				TEXT("yakupbilen/cube-state"),
				TEXT("Preserves the compact sticker-state transition benchmark without promoting it into HyperTwist live recognition, reconstruction, or generalized solver ownership.")
			)
		),
		MakePackageReference(
			TEXT("package/yakupbilen-adi-train-utils"),
			TEXT("train/train_utils.py"),
			TEXT("./train/train_utils.py"),
			TEXT("adi-generation-benchmark-anchor"),
			TEXT("direct permissive donor benchmark"),
			TEXT("ADI reverse-rollout generation, distance-bucket state sampling, and weighted target-preparation benchmark material for a narrow first-party experimentation lane."),
			{
				TEXT("ADI reverse rollout generation"),
				TEXT("distance-bucket sampling"),
				TEXT("weighted target preparation"),
				TEXT("scramble-depth batch composition")
			},
			CommonNoticeActions,
			{
				TEXT("live camera recognition ownership"),
				TEXT("broad model training platform ownership"),
				TEXT("generalized dataset shipping ownership")
			},
			MakeDirectDonorAttribution(
				TEXT("yakupbilen/adi-train-utils"),
				TEXT("Preserves the narrow ADI state-generation benchmark beneath a first-party HyperTwist experimentation profile without widening into generic training-platform ownership.")
			)
		),
		MakePackageReference(
			TEXT("package/yakupbilen-search"),
			TEXT("search/search.py"),
			TEXT("./search/search.py"),
			TEXT("neural-search-benchmark-anchor"),
			TEXT("direct permissive donor benchmark"),
			TEXT("Batched neural search experimentation, node-expansion ordering, and frontier ranking patterns for bounded offline benchmark use."),
			{
				TEXT("batched node expansion"),
				TEXT("network-scored frontier ranking"),
				TEXT("offline A* benchmark search"),
				TEXT("anti-cancellation successor pruning")
			},
			CommonNoticeActions,
			{
				TEXT("live solve explanation ownership"),
				TEXT("correctness/performance oracle ownership"),
				TEXT("browser shell ownership")
			},
			MakeDirectDonorAttribution(
				TEXT("yakupbilen/search"),
				TEXT("Preserves the offline neural search benchmark beneath first-party HyperTwist experimentation without turning it into the primary live explanation or solver-oracle owner.")
			)
		),
		MakePackageReference(
			TEXT("package/yakupbilen-modelpaper"),
			TEXT("networks/modelpaper.py"),
			TEXT("./networks/modelpaper.py"),
			TEXT("value-network-benchmark-anchor"),
			TEXT("direct permissive donor benchmark"),
			TEXT("Compact value-network benchmark architecture and batched state-evaluation posture for bounded offline experimentation."),
			{
				TEXT("small value-network inference"),
				TEXT("batched state evaluation"),
				TEXT("offline checkpoint research"),
				TEXT("neural benchmark scoring")
			},
			CommonNoticeActions,
			{
				TEXT("deployed inference service ownership"),
				TEXT("broad provider-backed model serving"),
				TEXT("voice or assistant platform ownership")
			},
			MakeDirectDonorAttribution(
				TEXT("yakupbilen/modelpaper"),
				TEXT("Preserves the compact value-network benchmark beneath a first-party experimentation lane without widening into deployed product-side ML service ownership.")
			)
		)
	};

	FHyperTwistTrainingLearnedSearchExperimentProfileContract ExperimentProfile;
	ExperimentProfile.ContractId = TEXT("learned-search-experiment-profile");
	ExperimentProfile.Title = TEXT("First-party learned heuristic search experimentation profile");
	ExperimentProfile.Summary = TEXT("First-party HyperTwist contract for `54`-sticker encoding, ADI batch generation, and offline neural frontier benchmark hooks above existing live recognition and solver-oracle owners.");
	ExperimentProfile.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-adi-train-utils"),
		TEXT("package/yakupbilen-search"),
		TEXT("package/yakupbilen-modelpaper")
	};
	ExperimentProfile.StateSurfaceTags =
	{
		TEXT("54-sticker state encoding"),
		TEXT("direct move-transition tables"),
		TEXT("inverse-solution recovery"),
		TEXT("anti-cancellation sequence cleanup")
	};
	ExperimentProfile.GenerationSurfaceTags =
	{
		TEXT("ADI reverse rollout generation"),
		TEXT("distance-labeled state batches"),
		TEXT("weighted target preparation"),
		TEXT("scramble-depth batch composition")
	};
	ExperimentProfile.SearchSurfaceTags =
	{
		TEXT("batched neural A* frontier scoring"),
		TEXT("offline benchmark replay"),
		TEXT("value-network evaluation hooks"),
		TEXT("oracle-comparison instrumentation")
	};
	ExperimentProfile.ExplicitExclusions =
	{
		TEXT("live camera recognition ownership"),
		TEXT("committed-face reconstruction ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("broad deployed ML platform ownership")
	};
	ExperimentProfile.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-experiment-profile"),
		TEXT("Reauthors a bounded first-party HyperTwist ML experimentation lane grounded in the retained yakupbilen benchmark without widening into live perception, reconstruction, or solver-oracle ownership.")
	);
	Bundle.ExperimentProfileContracts = {ExperimentProfile};

	FHyperTwistTrainingLearnedSearchAdiGenerationBoundary AdiBoundary;
	AdiBoundary.BoundaryId = TEXT("learned-search-adi-generation-boundary");
	AdiBoundary.Title = TEXT("ADI generation and target-preparation boundary");
	AdiBoundary.Summary = TEXT("First-party HyperTwist boundary for bounded ADI state generation, distance-bucket sampling, and target-preparation posture above the retained learned-search benchmark packages.");
	AdiBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-adi-train-utils")
	};
	AdiBoundary.GenerationSurfaceTags =
	{
		TEXT("ADI reverse rollout generation"),
		TEXT("goal-state seeded expansion"),
		TEXT("inverse-solution seeded scrambles"),
		TEXT("distance-labeled state batches")
	};
	AdiBoundary.TargetSurfaceTags =
	{
		TEXT("weighted target preparation"),
		TEXT("discount-aware target blending"),
		TEXT("batch supervision assembly"),
		TEXT("offline evaluation-only posture")
	};
	AdiBoundary.ProvenanceCaveats =
	{
		TEXT("offline experimentation only"),
		TEXT("generated states are not correctness oracle proof"),
		TEXT("no live camera or browser shell ownership")
	};
	AdiBoundary.ExplicitExclusions =
	{
		TEXT("live camera recognition ownership"),
		TEXT("committed-face reconstruction ownership"),
		TEXT("broad model training platform ownership"),
		TEXT("generalized dataset shipping ownership")
	};
	AdiBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-adi-boundary"),
		TEXT("Reauthors the bounded ADI generation and target-preparation seam above retained yakupbilen benchmark surfaces without turning the donor row into a generic training-data or product runtime owner.")
	);
	Bundle.AdiGenerationBoundaries = {AdiBoundary};

	FHyperTwistTrainingLearnedSearchSearchBenchmarkBoundary SearchBoundary;
	SearchBoundary.BoundaryId = TEXT("learned-search-search-benchmark-boundary");
	SearchBoundary.Title = TEXT("Offline neural search benchmark boundary");
	SearchBoundary.Summary = TEXT("First-party HyperTwist boundary for bounded neural frontier search benchmarking and small value-model comparison above the retained learned-search packages.");
	SearchBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-search"),
		TEXT("package/yakupbilen-modelpaper")
	};
	SearchBoundary.SearchSurfaceTags =
	{
		TEXT("batched node expansion"),
		TEXT("cost-plus-heuristic priority ranking"),
		TEXT("anti-cancellation successor pruning"),
		TEXT("goal-test solve extraction")
	};
	SearchBoundary.ModelSurfaceTags =
	{
		TEXT("small value-network inference"),
		TEXT("batched state evaluation"),
		TEXT("benchmark checkpoint posture"),
		TEXT("offline experiment scoring")
	};
	SearchBoundary.ProvenanceCaveats =
	{
		TEXT("brownan and efrantar remain correctness/performance oracle owners"),
		TEXT("qbr and rubix-cube-solver remain live recognition/reconstruction owners"),
		TEXT("research benchmark latency and accuracy remain non-authoritative")
	};
	SearchBoundary.ExplicitExclusions =
	{
		TEXT("correctness/performance oracle ownership"),
		TEXT("live solve explanation ownership"),
		TEXT("broad provider-backed model serving"),
		TEXT("browser or smart-device shell ownership")
	};
	SearchBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-search-boundary"),
		TEXT("Reauthors the bounded offline search benchmark seam above retained yakupbilen packages while keeping correctness, performance, explanation, and live shell ownership elsewhere in the stack.")
	);
	Bundle.SearchBenchmarkBoundaries = {SearchBoundary};

	FHyperTwistTrainingLearnedSearchAttributionBoundary AttributionBoundary;
	AttributionBoundary.BoundaryId = TEXT("learned-search-attribution-boundary");
	AttributionBoundary.Title = TEXT("Learned-search benchmark attribution boundary");
	AttributionBoundary.Summary = TEXT("First-party HyperTwist compliance boundary for using the yakupbilen learned-search stack as a retained permissive benchmark beneath a bounded first-party experimentation lane.");
	AttributionBoundary.AllowedUseTags =
	{
		TEXT("first-party reauthored experimentation lane"),
		TEXT("direct permissive benchmark reference"),
		TEXT("bounded offline search and ADI contract use")
	};
	AttributionBoundary.RequiredNoticeActions = CommonNoticeActions;
	AttributionBoundary.ProvenanceCaveats =
	{
		TEXT("yakupbilen remains a research benchmark rather than a camera/perception donor"),
		TEXT("qbr and rubix-cube-solver remain live recognition/reconstruction owners"),
		TEXT("brownan and efrantar remain solver-oracle owners")
	};
	AttributionBoundary.ExplicitExclusions =
	{
		TEXT("silent donor promotion"),
		TEXT("treating the benchmark as a live reconstruction owner"),
		TEXT("claiming deployed product-side ML serving landed")
	};
	AttributionBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-attribution-boundary"),
		TEXT("Records MIT provenance and packet bounds for the learned-search experimentation lane while keeping the donor row benchmark-grounded and non-authoritative for live product ownership.")
	);
	Bundle.AttributionBoundaries = {AttributionBoundary};

	FHyperTwistTrainingLearnedSearchSequencePolicyContract SequencePolicy;
	SequencePolicy.ContractId = TEXT("learned-search-sequence-policy-contract");
	SequencePolicy.Title = TEXT("Learned-search anti-cancellation sequence policy");
	SequencePolicy.Summary = TEXT("First-party HyperTwist contract for anti-cancellation scramble generation, solved-state inclusion posture, and weighting-policy selection above the retained ADI benchmark seam.");
	SequencePolicy.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-adi-train-utils")
	};
	SequencePolicy.SequenceSurfaceTags =
	{
		TEXT("inverse-pair suppression"),
		TEXT("triple-repeat suppression"),
		TEXT("scramble-depth sequence generation"),
		TEXT("shuffle-after-generation posture")
	};
	SequencePolicy.SamplingSurfaceTags =
	{
		TEXT("optional solved-state inclusion"),
		TEXT("distance-labeled sample distribution"),
		TEXT("scramble-batch repetition groups"),
		TEXT("solved-state append-before-shuffle posture")
	};
	SequencePolicy.WeightingSurfaceTags =
	{
		TEXT("learn-first-close weighting"),
		TEXT("lightweight depth weighting"),
		TEXT("depth-proportional weighting"),
		TEXT("offline batch-only supervision weighting")
	};
	SequencePolicy.ExplicitExclusions =
	{
		TEXT("live replay notation ownership"),
		TEXT("general scramble registry ownership"),
		TEXT("broad model training platform ownership"),
		TEXT("correctness/performance oracle ownership")
	};
	SequencePolicy.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-sequence-policy"),
		TEXT("Reauthors the narrow anti-cancellation sequence and weighting-policy seam above retained ADI benchmark surfaces without promoting it into HyperTwist live replay, scramble-registry, or solver-oracle ownership.")
	);
	Bundle.SequencePolicyContracts = {SequencePolicy};

	FHyperTwistTrainingLearnedSearchSearchBudgetBoundary SearchBudgetBoundary;
	SearchBudgetBoundary.BoundaryId = TEXT("learned-search-search-budget-boundary");
	SearchBudgetBoundary.Title = TEXT("Learned-search frontier budget boundary");
	SearchBudgetBoundary.Summary = TEXT("First-party HyperTwist boundary for bounded frontier-budget, time/iteration cap, and model-clone checkpoint posture above the retained offline search benchmark seam.");
	SearchBudgetBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-search"),
		TEXT("package/yakupbilen-modelpaper")
	};
	SearchBudgetBoundary.BudgetSurfaceTags =
	{
		TEXT("weighted frontier ranking"),
		TEXT("batch-size frontier cap"),
		TEXT("iteration-cap search mode"),
		TEXT("time-cap search mode")
	};
	SearchBudgetBoundary.FrontierSurfaceTags =
	{
		TEXT("goal-hit early exit"),
		TEXT("closed-node depth replacement"),
		TEXT("benchmark checkpoint clone posture"),
		TEXT("offline-only heuristic eval mode")
	};
	SearchBudgetBoundary.ProvenanceCaveats =
	{
		TEXT("frontier budgets remain benchmark-only and non-authoritative for live solve UX"),
		TEXT("model clone posture is a checkpoint benchmark rather than deployed service ownership"),
		TEXT("search budgets do not supersede retained solver-oracle owners")
	};
	SearchBudgetBoundary.ExplicitExclusions =
	{
		TEXT("live solve explanation ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("deployed model serving ownership"),
		TEXT("browser or smart-device shell ownership")
	};
	SearchBudgetBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-search-budget"),
		TEXT("Reauthors the narrow frontier-budget and checkpoint posture above retained search benchmark surfaces while keeping live solve UX, deployed serving, and oracle ownership elsewhere in the stack.")
	);
	Bundle.SearchBudgetBoundaries = {SearchBudgetBoundary};

	FHyperTwistTrainingLearnedSearchNodeIdentityContract NodeIdentityContract;
	NodeIdentityContract.ContractId = TEXT("learned-search-node-identity-contract");
	NodeIdentityContract.Title = TEXT("Learned-search node identity contract");
	NodeIdentityContract.Summary = TEXT("First-party HyperTwist contract for flattened-byte node hashing, parent-linked lineage, and depth-replacement posture above the retained offline search benchmark seam.");
	NodeIdentityContract.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-search")
	};
	NodeIdentityContract.IdentitySurfaceTags =
	{
		TEXT("flattened-byte node hash"),
		TEXT("array-equality identity check"),
		TEXT("closed-node dedupe posture"),
		TEXT("shallower-depth replacement policy")
	};
	NodeIdentityContract.LineageSurfaceTags =
	{
		TEXT("parent-linked lineage"),
		TEXT("move-index lineage"),
		TEXT("depth-tracked node state"),
		TEXT("solution-path unwind posture")
	};
	NodeIdentityContract.ExplicitExclusions =
	{
		TEXT("canonical replay ledger ownership"),
		TEXT("live solve-history ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("browser or smart-device shell ownership")
	};
	NodeIdentityContract.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-node-identity"),
		TEXT("Reauthors the narrow node identity and lineage seam above retained search benchmark surfaces without promoting it into HyperTwist canonical replay, solve-history, or oracle ownership.")
	);
	Bundle.NodeIdentityContracts = {NodeIdentityContract};

	FHyperTwistTrainingLearnedSearchStateExpansionBoundary StateExpansionBoundary;
	StateExpansionBoundary.BoundaryId = TEXT("learned-search-state-expansion-boundary");
	StateExpansionBoundary.Title = TEXT("Learned-search vectorized state-expansion boundary");
	StateExpansionBoundary.Summary = TEXT("First-party HyperTwist boundary for vectorized 12-way successor expansion, solved-state reward tagging, and stacked goal-scan posture above the retained offline search benchmark seam.");
	StateExpansionBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-search")
	};
	StateExpansionBoundary.ExpansionSurfaceTags =
	{
		TEXT("stacked state batching"),
		TEXT("12-way successor expansion"),
		TEXT("take-along-axis transition routing"),
		TEXT("vectorized reward scan")
	};
	StateExpansionBoundary.GoalSurfaceTags =
	{
		TEXT("solved-state goal tagging"),
		TEXT("goal-hit early return posture"),
		TEXT("per-successor reward flattening"),
		TEXT("offline-only expansion benchmark")
	};
	StateExpansionBoundary.ProvenanceCaveats =
	{
		TEXT("state expansion remains benchmark-only and non-authoritative for live reconstruction"),
		TEXT("goal tagging does not supersede retained solver-oracle owners"),
		TEXT("vectorized expansion is not a browser or camera shell claim")
	};
	StateExpansionBoundary.ExplicitExclusions =
	{
		TEXT("live camera recognition ownership"),
		TEXT("committed-face reconstruction ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("canonical replay verification ownership")
	};
	StateExpansionBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-state-expansion"),
		TEXT("Reauthors the narrow vectorized successor-expansion seam above retained search benchmark surfaces while keeping live reconstruction, replay, and oracle ownership elsewhere in the stack.")
	);
	Bundle.StateExpansionBoundaries = {StateExpansionBoundary};

	FHyperTwistTrainingLearnedSearchFrontierScoringBoundary FrontierScoringBoundary;
	FrontierScoringBoundary.BoundaryId = TEXT("learned-search-frontier-scoring-boundary");
	FrontierScoringBoundary.Title = TEXT("Learned-search frontier scoring boundary");
	FrontierScoringBoundary.Summary = TEXT("First-party HyperTwist boundary for batched frontier pop windows, weighted f-score ordering, categorical heuristic input shaping, and no-grad evaluation posture above the retained offline search benchmark seam.");
	FrontierScoringBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-search"),
		TEXT("package/yakupbilen-modelpaper")
	};
	FrontierScoringBoundary.FrontierSurfaceTags =
	{
		TEXT("open-list score ordering"),
		TEXT("batched frontier pop window"),
		TEXT("weighted f-score depth penalty"),
		TEXT("generated-node counter growth")
	};
	FrontierScoringBoundary.EvaluationSurfaceTags =
	{
		TEXT("one-hot categorical heuristic input"),
		TEXT("model eval gating"),
		TEXT("torch no-grad evaluation posture"),
		TEXT("per-node heuristic score assignment")
	};
	FrontierScoringBoundary.ProvenanceCaveats =
	{
		TEXT("frontier scoring remains benchmark-only and non-authoritative for live coaching"),
		TEXT("heuristic evaluation does not supersede retained solver-oracle owners"),
		TEXT("categorical heuristic input is not a live recognition preprocessing claim")
	};
	FrontierScoringBoundary.ExplicitExclusions =
	{
		TEXT("live solve explanation ownership"),
		TEXT("deployed model serving ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("browser or camera shell ownership")
	};
	FrontierScoringBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-frontier-scoring"),
		TEXT("Reauthors the narrow frontier scoring and batched heuristic-evaluation seam above retained search benchmark surfaces while keeping live coaching, deployed serving, and oracle ownership elsewhere in the stack.")
	);
	Bundle.FrontierScoringBoundaries = {FrontierScoringBoundary};

	FHyperTwistTrainingLearnedSearchSolutionUnwindBoundary SolutionUnwindBoundary;
	SolutionUnwindBoundary.BoundaryId = TEXT("learned-search-solution-unwind-boundary");
	SolutionUnwindBoundary.Title = TEXT("Learned-search solution unwind boundary");
	SolutionUnwindBoundary.Summary = TEXT("First-party HyperTwist boundary for solved-state short-circuit handling, parent-chain solution unwind, move-list normalization, and iteration or timeout result reporting above the retained offline search benchmark seam.");
	SolutionUnwindBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-cube-state"),
		TEXT("package/yakupbilen-search")
	};
	SolutionUnwindBoundary.RecoverySurfaceTags =
	{
		TEXT("solved-state short-circuit return"),
		TEXT("goal-index to parent-chain unwind"),
		TEXT("move-list reverse ordering"),
		TEXT("clear-seq normalization posture")
	};
	SolutionUnwindBoundary.TerminationSurfaceTags =
	{
		TEXT("iteration-bounded search mode"),
		TEXT("time-bounded search mode"),
		TEXT("iteration and generated-node reporting"),
		TEXT("goal-hit early completion posture")
	};
	SolutionUnwindBoundary.ProvenanceCaveats =
	{
		TEXT("solution unwind remains benchmark-only and non-authoritative for canonical replay"),
		TEXT("termination reporting does not supersede retained timer or stats owners"),
		TEXT("generated-node counts remain experiment telemetry rather than user-facing solve records")
	};
	SolutionUnwindBoundary.ExplicitExclusions =
	{
		TEXT("canonical replay ledger ownership"),
		TEXT("competition stats ownership"),
		TEXT("live timer ownership"),
		TEXT("solve-history explanation ownership")
	};
	SolutionUnwindBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-solution-unwind"),
		TEXT("Reauthors the narrow solution unwind and termination-reporting seam above retained search benchmark surfaces while keeping replay, timer, and solve-history ownership elsewhere in the stack.")
	);
	Bundle.SolutionUnwindBoundaries = {SolutionUnwindBoundary};

	FHyperTwistTrainingLearnedSearchValueNetworkShapeBoundary ValueNetworkShapeBoundary;
	ValueNetworkShapeBoundary.BoundaryId = TEXT("learned-search-value-network-shape-boundary");
	ValueNetworkShapeBoundary.Title = TEXT("Learned-search value-network shape boundary");
	ValueNetworkShapeBoundary.Summary = TEXT("First-party HyperTwist boundary for compact flattened-input value-network shape, linear-stack depth, and initialization posture above the retained offline learned-search benchmark seam.");
	ValueNetworkShapeBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-modelpaper")
	};
	ValueNetworkShapeBoundary.ArchitectureSurfaceTags =
	{
		TEXT("flattened input reshape"),
		TEXT("4096-2048-512 linear stack"),
		TEXT("relu activation ladder"),
		TEXT("single-value scalar head")
	};
	ValueNetworkShapeBoundary.InitializationSurfaceTags =
	{
		TEXT("xavier-normal weight init"),
		TEXT("zero-bias init posture"),
		TEXT("input-size keyed network shape"),
		TEXT("state-dict clone-compatible layout")
	};
	ValueNetworkShapeBoundary.ProvenanceCaveats =
	{
		TEXT("value-network shape remains benchmark-only and non-authoritative for deployed serving"),
		TEXT("model architecture does not supersede retained solver-oracle owners"),
		TEXT("flattened input shape is not a live perception preprocessing claim")
	};
	ValueNetworkShapeBoundary.ExplicitExclusions =
	{
		TEXT("deployed model serving ownership"),
		TEXT("broad training-platform ownership"),
		TEXT("correctness/performance oracle ownership"),
		TEXT("live recognition preprocessing ownership")
	};
	ValueNetworkShapeBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-value-network-shape"),
		TEXT("Reauthors the narrow value-network shape and initialization seam above retained model benchmark surfaces while keeping deployed serving, training-platform, and oracle ownership elsewhere in the stack.")
	);
	Bundle.ValueNetworkShapeBoundaries = {ValueNetworkShapeBoundary};

	FHyperTwistTrainingLearnedSearchGeneratorSyncBoundary GeneratorSyncBoundary;
	GeneratorSyncBoundary.BoundaryId = TEXT("learned-search-generator-sync-boundary");
	GeneratorSyncBoundary.Title = TEXT("Learned-search generator sync boundary");
	GeneratorSyncBoundary.Summary = TEXT("First-party HyperTwist boundary for tau-weighted generator refresh, parameter copy posture, and device-aware sync semantics above the retained offline learned-search benchmark seam.");
	GeneratorSyncBoundary.RequiredPackageIds =
	{
		TEXT("package/yakupbilen-adi-train-utils"),
		TEXT("package/yakupbilen-modelpaper")
	};
	GeneratorSyncBoundary.SyncSurfaceTags =
	{
		TEXT("tau-weighted generator refresh"),
		TEXT("state-dict merge posture"),
		TEXT("device-aware parameter copy"),
		TEXT("generator reload-after-sync")
	};
	GeneratorSyncBoundary.ParameterSurfaceTags =
	{
		TEXT("online-to-generator parameter blend"),
		TEXT("per-parameter copy loop"),
		TEXT("generator return-on-device posture"),
		TEXT("offline sync-only refresh boundary")
	};
	GeneratorSyncBoundary.ProvenanceCaveats =
	{
		TEXT("generator sync remains benchmark-only and non-authoritative for deployed training services"),
		TEXT("tau blending does not supersede retained provider or model-host owners"),
		TEXT("parameter refresh is not a live session personalization claim")
	};
	GeneratorSyncBoundary.ExplicitExclusions =
	{
		TEXT("deployed training service ownership"),
		TEXT("provider-backed model lifecycle ownership"),
		TEXT("live user-memory personalization ownership"),
		TEXT("correctness/performance oracle ownership")
	};
	GeneratorSyncBoundary.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/learned-search-generator-sync"),
		TEXT("Reauthors the narrow generator refresh and tau-sync seam above retained learned-search benchmark surfaces while keeping deployed training services, provider lifecycle ownership, and oracle ownership elsewhere in the stack.")
	);
	Bundle.GeneratorSyncBoundaries = {GeneratorSyncBoundary};

	return Bundle;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetExperimentProfileContractById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingLearnedSearchExperimentProfileContract& OutContract
)
{
	for (const FHyperTwistTrainingLearnedSearchExperimentProfileContract& Contract : Bundle.ExperimentProfileContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingLearnedSearchExperimentProfileContract();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetAdiGenerationBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchAdiGenerationBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchAdiGenerationBoundary& Boundary : Bundle.AdiGenerationBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchAdiGenerationBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetSearchBenchmarkBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchSearchBenchmarkBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchSearchBenchmarkBoundary& Boundary : Bundle.SearchBenchmarkBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchSearchBenchmarkBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetAttributionBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchAttributionBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchAttributionBoundary& Boundary : Bundle.AttributionBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchAttributionBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetSequencePolicyContractById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingLearnedSearchSequencePolicyContract& OutContract
)
{
	for (const FHyperTwistTrainingLearnedSearchSequencePolicyContract& Contract : Bundle.SequencePolicyContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingLearnedSearchSequencePolicyContract();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetSearchBudgetBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchSearchBudgetBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchSearchBudgetBoundary& Boundary : Bundle.SearchBudgetBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchSearchBudgetBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetNodeIdentityContractById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingLearnedSearchNodeIdentityContract& OutContract
)
{
	for (const FHyperTwistTrainingLearnedSearchNodeIdentityContract& Contract : Bundle.NodeIdentityContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingLearnedSearchNodeIdentityContract();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetStateExpansionBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchStateExpansionBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchStateExpansionBoundary& Boundary : Bundle.StateExpansionBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchStateExpansionBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetFrontierScoringBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchFrontierScoringBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchFrontierScoringBoundary& Boundary : Bundle.FrontierScoringBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchFrontierScoringBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetSolutionUnwindBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchSolutionUnwindBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchSolutionUnwindBoundary& Boundary : Bundle.SolutionUnwindBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchSolutionUnwindBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetValueNetworkShapeBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchValueNetworkShapeBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchValueNetworkShapeBoundary& Boundary : Bundle.ValueNetworkShapeBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchValueNetworkShapeBoundary();
	return false;
}

bool UHyperTwistTrainingLearnedSearchLibrary::TryGetGeneratorSyncBoundaryById(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingLearnedSearchGeneratorSyncBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingLearnedSearchGeneratorSyncBoundary& Boundary : Bundle.GeneratorSyncBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingLearnedSearchGeneratorSyncBoundary();
	return false;
}

FString UHyperTwistTrainingLearnedSearchLibrary::BuildPackageChecklistTsv(
	const FHyperTwistTrainingLearnedSearchReferenceBundle& Bundle
)
{
	using namespace HyperTwistTrainingLearnedSearchLibraryInternal;

	FString Checklist = TEXT("PackageId\tLabel\tExportPath\tOwnershipRole\tLicensePosture\tRetainedSurfaceTags\tRequiredNoticeActions\tExplicitExclusions\n");
	for (const FHyperTwistTrainingLearnedSearchPackageReference& Reference : Bundle.PackageReferences)
	{
		FString RetainedSurfaceTags;
		AppendJoined(RetainedSurfaceTags, Reference.RetainedSurfaceTags);

		FString NoticeActions;
		AppendJoined(NoticeActions, Reference.RequiredNoticeActions);

		FString Exclusions;
		AppendJoined(Exclusions, Reference.ExplicitExclusions);

		Checklist += FString::Printf(
			TEXT("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"),
			*Reference.PackageId,
			*Reference.Label,
			*Reference.ExportPath,
			*Reference.OwnershipRole,
			*Reference.LicensePosture,
			*RetainedSurfaceTags,
			*NoticeActions,
			*Exclusions
		);
	}

	return Checklist;
}
