use serde_json::Value;
use lean_ctx_protocol::ContextCheckpointV1;
use crate::core::ccp_session_bundle::{
CcpSessionBundleV1, PolicyIdentityV1 as SessionPolicyIdentityV1,
ProjectIdentityV1 as SessionProjectIdentityV1, SessionExcerptV1,
};
use crate::core::context_snapshot::types::{
ContextSnapshotV1, GitAnchorV1, SnapshotLedgerV1, SnapshotLineageV1, SnapshotProjectV1,
SnapshotRoiV1, SnapshotSessionV1,
};
use crate::core::handoff_ledger::{
HandoffLedgerV1, KnowledgeExcerpt, SessionExcerpt as HandoffSessionExcerpt, ToolCallsSummary,
};
use crate::core::handoff_transfer_bundle::{
ArtifactsExcerptV1, HandoffTransferBundleV1, ProjectIdentityV1 as HandoffProjectIdentityV1,
};
use crate::core::session::{Decision, Finding, ProgressEntry, SessionStats, TaskInfo};
use super::projections::{
ContextCheckpointProjectionErrorV1, ContextCheckpointProjectionInputV1,
ContextCheckpointProjectionLossReasonV1, ContextCheckpointProjectionLossV1,
ContextCheckpointProjectionResultV1, ContextCheckpointProjectionTargetV1,
ContextCheckpointProjections,
};
use crate::core::contracts::{
CCP_SESSION_BUNDLE_V1_SCHEMA_VERSION, CONTEXT_PACKAGE_V1_SCHEMA_VERSION,
CONTEXT_PACKAGE_V2_SCHEMA_VERSION, CONTEXT_SNAPSHOT_V1_SCHEMA_VERSION,
HANDOFF_LEDGER_V1_SCHEMA_VERSION, HANDOFF_TRANSFER_BUNDLE_V1_SCHEMA_VERSION,
};
pub const CONTEXT_CHECKPOINT_ADAPTER_SCHEMA_VERSION: u32 = 1;
pub const MAX_CONTEXT_CHECKPOINT_LEGACY_PAYLOAD_BYTES: usize = 350_000;
pub const MAX_CONTEXT_CHECKPOINT_CARRIER_ENVELOPE_BYTES: usize = 262_144;
const LEGACY_HASH_HEX_LENGTH: usize = 64;
const MAX_LEGACY_LABEL_BYTES: usize = 64;
const SESSION_BUNDLE_MAX_NEXT_STEPS: usize = 25;
const HANDOFF_LEDGER_MAX_DECISIONS: usize = 10;
const HANDOFF_LEDGER_MAX_LIST: usize = 20;
const SNAPSHOT_MAX_SESSION_LIST: usize = 64;
const SESSION_BUNDLE_MAX_PAYLOAD_BYTES: usize = 250_000;
const MAX_CONTEXT_CHECKPOINT_LEGACY_LOSSES: usize = 128;
const MAX_CONTEXT_CHECKPOINT_REQUIRED_INPUTS: usize = 16;
macro_rules! validated_deserialize {
($target:ident { $($field:ident : $field_type:ty),+ $(,)? }) => {
impl<'de> Deserialize<'de> for $target {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Wire {
$($field: $field_type),+
}
let Wire { $($field),+ } = Wire::deserialize(deserializer)?;
let value = Self { $($field),+ };
value.validate().map_err(|error| {
DeError::custom(format!("{error:?}"))
})?;
Ok(value)
}
}
};
}
mod adoption;
mod context_snapshot;
mod contract;
mod ctxpkg;
mod forward;
mod handoff_bundle;
mod inputs;
mod session_bundle;
#[cfg(test)]
mod tests;
mod validation;
mod wire;
pub use adoption::*;
pub use contract::*;
pub use forward::*;
pub use inputs::*;
use context_snapshot::materialize_context_snapshot;
use ctxpkg::materialize_ctxpkg;
use forward::{refusal, required_inputs_from_plan, residual_losses};
use handoff_bundle::materialize_handoff_bundle;
use session_bundle::materialize_session_bundle;
use validation::{
projection_input_field_path, projection_input_target, require_arity, require_capacity,
validate_optional_label, validate_project_identity, validate_sorted_unique_timestamps,
validate_timestamp,
};
use wire::{
chrono_timestamp, compression_rate, encode_owner, parse_canonical_json, parse_json_object,
payload_from_value, progress_percent, source_identity, validate_carrier_envelope,
validate_legacy_target_value,
};