daemonic_error 0.1.2

Errors that compose, predict, and leave receipts - Compose: algebraic combination (in active development) - Predict: Glass/Severity - Receipts: audit trail, position, checksum - Reflection: Runtime Reflection through TopologySegment (in active development)
use crate::{
	daemonic::{
		AnchorDomainSet,
		PerceptualAnchor,
		RateAnchor,
		CausalAnchor,
		TemporalAnchor,
		Anchor,
		Daemonic,
		daemonic_contract::DaemonicContract,
	},
	Glass,
	DaemonicError,
};

/// Core Daemonic requirements.
///
/// Anything implementing Daemonic must implement both Core and Contract.
/// Core Daemonic requirements. Now includes Anchor.
///
/// Anything implementing DaemonicCore IS an anchor because
/// it has a clock (temporal anchor) and an observer
/// (perceptual + causal anchor).
pub(crate) trait DaemonicCore<GLASS: Glass<GLASS> + Iterator>: for<'core> DaemonicClock<'core, GLASS>
+ DaemonicObserver<GLASS>
+ Anchor
{
	type Clock: for<'clock> DaemonicClock<'clock, GLASS>
	+ TemporalAnchor
	+ RateAnchor;

	type Observer: DaemonicObserver<GLASS>
	+ PerceptualAnchor
	+ CausalAnchor;

	/// Anchor domains this core serves.
	/// Minimum: Temporal + Perceptual + Causal (from clock + observer).
	fn core_anchor_domains(&self) -> AnchorDomainSet {
		AnchorDomainSet::TEMPORAL
			.union(AnchorDomainSet::PERCEPTUAL)
			.union(AnchorDomainSet::CAUSAL)
	}
}


// pub(crate) mod observer {
// 	use crate::daemonic::{Daemonic, DaemonicID};
// 	use crate::daemonic::daemonic_contract::DaemonicContract;
// 	use crate::{DaemonicError, ErrorContext};
// 	use crate::daemonic::daemonic_core::DaemonicClock;
//
// 	/// Entity - Daemonic entity with self-aware death
// 	///
// 	/// Entities can declare their own death with context.
// 	pub(crate) trait DaemonicObserver<FORMAT, PARTIAL>: Daemonic<FORMAT, PARTIAL> {
// 		type Contract: DaemonicContract<FORMAT, PARTIAL>;
//
// 		type Clock: DaemonicClock<FORMAT, PARTIAL>;
//
// 		fn id(&self) -> DaemonicID<FORMAT, PARTIAL>;
//
// 		/// Declare entity death (Broken Sword)
// 		///
// 		/// Called when: Entity encounters unrecoverable error
// 		/// Returns: BrokenSwordContext error with full context
// 		/// # Broken Sword Semantics
// 		///
// 		/// "Broken Sword" is a self-aware death declaration by a Daemonic entity.
// 		/// The term originates from the Unification Wars Trilogy, where TCS Jericho,
// 		/// trapped and outnumbered, declared "Jericho is Broken Sword" - meaning:
// 		/// "We are dying, we will not surrender, rescue is impossible, recovery only."
// 		///
// 		/// In Daemonic context:
// 		/// - Entity encounters unrecoverable error
// 		/// - Entity declares its own death (not external kill)
// 		/// - Error propagates upstream to parent
// 		/// - Parent marks entity for reaping
// 		/// - Parent survives (no cascade failure)
// 		///
// 		/// ## Reap Strategy
// 		///
// 		/// **Default: Background reaping**
// 		/// - Entities queued for cleanup
// 		/// - Processed asynchronously
// 		/// - No blocking on parent
// 		///
// 		/// **System-level: Immediate reaping** (future)
// 		/// - Flagged for priority cleanup
// 		/// - Sudo privileges (future detection)
// 		/// - Processed before background queue
// 		///
// 		/// ## Reap Failure Handling
// 		///
// 		/// After 3 failed reap attempts:
// 		/// 1. **Map boundaries**: Identify affected symbols (event horizon)
// 		/// 2. **Establish orbit**: Mark symbols as orbiting black hole
// 		/// 3. **Force kill**: Topology unwrapped enough, safe to terminate
// 		///
// 		/// This prevents hard desync by maintaining topological awareness
// 		/// even when entity cannot be gracefully reaped.
// 		///
// 		/// ## Cascade Death
// 		///
// 		/// When parent dies:
// 		/// - Child with no external references → Dies with parent
// 		/// - Child with external references → Survives (orphaned)
// 		/// - Child with dependents → Survives (needed by others)
// 		///
// 		/// ## Mesh Awareness (future)
// 		///
// 		/// All entity deaths are broadcast to mesh peers (if configured):
// 		/// - Enables distributed reference tracking
// 		/// - Prevents dangling references
// 		/// - Maintains mesh consisten
// 		fn broken_sword<FORMAT, PARTAL>(&self, err: Box<dyn ErrorContext>) -> impl DaemonicError<FORMAT, PARTIAL> { None }
// 	}
// }

pub use clock::{DaemonicClock, SteerableClock, SteppableClock, UncertainClock};
use super::observation::observer::DaemonicObserver;

pub(crate) mod clock;