Skip to main content

converge_kernel/
lib.rs

1// Copyright 2024-2026 Reflective Labs
2// SPDX-License-Identifier: MIT
3
4//! # Converge Kernel
5//!
6//! This crate is the curated in-process execution API for Converge.
7//! Consumers embed the kernel here; they author packs in `converge-pack`
8//! and use `converge-model` for shared semantic types.
9
10pub mod formation {
11    //! Grouped offering API for self-assembling formations.
12    //!
13    //! The stable pattern is:
14    //! - semantics in `converge-model`
15    //! - authoring in `converge-pack`
16    //! - runnable machinery in `converge-kernel`
17
18    pub use converge_model::formation::{
19        DeliberatedFormationTemplate, FormationCatalog, FormationKind, FormationPlan,
20        FormationRequest, FormationTemplate, FormationTemplateMetadata, FormationTemplateQuery,
21        OpenClawFormationTemplate, ProfileSnapshot, RoleAssignment, ScoredFormationTemplate,
22        ScoringWeights, StaticFormationTemplate, SuggestorCapability, SuggestorProfile,
23        SuggestorRole,
24    };
25    pub use converge_optimization::suggestors::FormationAssemblySuggestor;
26    pub use converge_provider::ProviderSelectionSuggestor;
27    pub use converge_provider_api::{
28        Capability, CapabilityAssignment, CostClass, LatencyClass, ProviderAssignment,
29        ProviderRequest,
30    };
31}
32
33pub use converge_core::gates::hitl::{
34    ContextItem, GateDecision, GateEvent, GateEventKind, GateRequest, GateVerdict, HitlPolicy,
35    TimeoutAction, TimeoutPolicy,
36};
37pub use converge_core::gates::{
38    AuthorityLevel, FlowAction, FlowGateAuthorizer, FlowGateContext, FlowGateInput,
39    FlowGateOutcome, FlowGatePrincipal, FlowGateResource, FlowPhase, StopReason,
40};
41pub use converge_core::{
42    ApprovalPointId, BackendId, Budget, BudgetResource, ChainId, ConstraintName, ConstraintValue,
43    ContextState, ConvergeError, ConvergeResult, CorrelationId, Criterion, CriterionEvaluator,
44    CriterionId, CriterionOutcome, CriterionResult, DecisionStep, Engine, EngineHitlPolicy,
45    EventId, EventQuery, ExperienceEvent, ExperienceEventEnvelope, ExperienceEventKind,
46    ExperienceEventObserver, ExperienceStore, HitlPause, IntegrityProof, Invariant, InvariantClass,
47    InvariantResult, LamportClock, MerkleRoot, PackId, RunResult, StreamingCallback, SuggestorId,
48    TenantId, TraceLinkId, TruthId, TypesBudgets, TypesIntentId, TypesIntentKind, TypesRootIntent,
49    TypesRunHooks,
50};
51pub use converge_pack::{
52    AgentEffect, Context, ContextKey, Fact, ProposedFact, Suggestor, ValidationError,
53};
54
55#[cfg(test)]
56mod tests {
57    use super::{
58        BudgetResource, StopReason,
59        formation::{
60            Capability, FormationCatalog, FormationRequest, FormationTemplate,
61            FormationTemplateMetadata, ProviderRequest, StaticFormationTemplate, SuggestorRole,
62        },
63    };
64
65    #[test]
66    fn kernel_reexports_runtime_stop_and_budget_types() {
67        let stop = StopReason::converged();
68        assert!(matches!(stop, StopReason::Converged));
69        assert!(matches!(BudgetResource::Tokens, BudgetResource::Tokens));
70    }
71
72    #[test]
73    fn kernel_groups_formation_offering_api() {
74        let formation = FormationRequest {
75            id: "req-1".to_string(),
76            required_roles: vec![SuggestorRole::Analysis],
77            required_capabilities: vec![],
78        };
79        let provider = ProviderRequest {
80            id: "provider-1".to_string(),
81            required_capabilities: vec![Capability::Reasoning],
82            backend_requirements: None,
83        };
84
85        assert_eq!(formation.required_roles, vec![SuggestorRole::Analysis]);
86        assert_eq!(provider.required_capabilities, vec![Capability::Reasoning]);
87    }
88
89    #[test]
90    fn kernel_reexports_template_catalog_surface() {
91        let catalog = FormationCatalog::new().with_template(FormationTemplate::static_template(
92            StaticFormationTemplate::new(FormationTemplateMetadata::new(
93                "analysis-only",
94                "Single-role analysis formation",
95                [SuggestorRole::Analysis],
96            )),
97        ));
98
99        assert_eq!(catalog.len(), 1);
100        assert_eq!(
101            catalog.get("analysis-only").map(FormationTemplate::id),
102            Some("analysis-only")
103        );
104    }
105}