Skip to main content

khive_runtime/
lib.rs

1//! khive-runtime: composable Service API used by daemon, MCP server, and CLI.
2//!
3//! Wraps `StorageBackend` and query compilation into a single Rust API surface.
4
5#[cfg(test)]
6mod test_process;
7
8pub mod actor_identity;
9pub mod agent_lifecycle;
10#[doc(hidden)]
11pub use khive_retrieval::ann::registry as ann_registry;
12pub mod atomic_message;
13pub mod atomic_plan;
14pub mod atomic_prepare;
15pub mod atomic_runner;
16pub mod audit_batch;
17pub mod backend_handle;
18pub mod blob;
19pub mod bounded_read;
20pub mod build_info;
21mod code_map_runtime;
22pub mod comm_recipient;
23pub mod comm_transport;
24pub mod config;
25pub mod config_ledger;
26pub mod context;
27pub mod cost_unit;
28pub mod credentials;
29mod visibility_receipts;
30pub use visibility_receipts::AuthenticatedVisibilityReceipt;
31pub mod curation;
32pub mod daemon;
33pub mod email_message_id;
34pub mod embedder_registry;
35pub mod embedding;
36pub mod embedding_reranker;
37pub mod embedding_warning;
38pub mod engine_config;
39pub mod entity_write;
40pub mod error;
41mod error_projection;
42mod event_actor_scope;
43mod event_cursor_walk;
44mod event_page;
45mod event_store_guard;
46pub mod events_split;
47mod fence_identity;
48pub mod file_policy;
49pub mod fusion;
50pub mod graph_traversal;
51pub mod hooks;
52mod index_repair;
53pub use index_repair::IndexRepairReport;
54pub mod graph_lint;
55pub mod input_schema;
56pub mod keyed_memory;
57#[cfg(test)]
58mod keyed_memory_tests;
59pub mod keyed_message;
60mod kg_read;
61mod live_until;
62mod mailbox_view;
63mod note_create;
64mod note_index;
65mod note_read;
66pub mod note_search_ann;
67mod note_store_guard;
68mod note_validation;
69pub mod note_write;
70#[cfg(test)]
71mod note_write_tests;
72pub mod objectives;
73pub mod operations;
74mod outbound_email_policy;
75pub use outbound_email_policy::OutboundEmailPolicy;
76pub use outbound_email_policy::{
77    inbound_email_is_suppressed, outbound_email_is_suppressed, EmailSuppression,
78    EmailSuppressionKind, EmailSuppressionScope,
79};
80pub mod pack;
81pub mod pack_metadata;
82mod params;
83pub mod phase_events;
84pub mod portability;
85pub mod preference_verification;
86pub mod presentation;
87pub mod process_group;
88pub mod process_retry;
89pub mod reference_resolution;
90pub mod reference_ring;
91pub mod registry;
92pub mod resource;
93pub mod retrieval;
94pub mod runtime;
95pub mod secret_gate;
96pub(crate) mod secret_gate_finalizer;
97mod sql_include;
98#[cfg(test)]
99mod stage_overlap_tests;
100mod stage_seam;
101mod streams;
102pub mod telemetry_config;
103pub use streams::{
104    refusal_value, StreamAppendDisposition, StreamAppendFailure, StreamAppendSpec,
105    StreamBatchMember, StreamBatchRefusal, StreamObservation, StreamWriteSpec,
106};
107pub mod time_anchor;
108pub use khive_storage::usage;
109pub mod validation;
110
111pub use context::{ContextContributor, ContextRequest, ContextSlice, ScoreSemantics};
112
113pub use actor_identity::{actor_is_unattributed, resolve_actor, should_warn_unattributed_actor};
114pub use agent_lifecycle::{
115    apply_transition, spawn_fingerprint, AgentRecord, AgentState, IllegalTransition,
116    TerminalReason, Transition, Trigger,
117};
118pub use atomic_message::{create_notes_atomic_with_report, AtomicNoteSpec};
119pub use atomic_plan::{
120    AddEntityPlan, AddNotePlan, AffectedRowGuard, DeletePlan, GovernanceOp, GovernancePlan,
121    GtdCompletePlan, GtdTransitionPlan, LinkPlan, MergePlan, PlanPredicate, PlanStatement,
122    PostCommitEffect, UpdatePlan,
123};
124pub use atomic_runner::{
125    run_atomic_unit, AtomicOpFailure, AtomicOpPlan, AtomicRunOutcome, AtomicRunnerError,
126    CommittedPostCommitEffects,
127};
128pub use backend_handle::{BackendHandle, BackendHandleError, RetrievalTier};
129pub use blob::{
130    resolve_blob_store, resolve_blob_store_for_mode, BlobHydrator, GovernedBlobError, VerifiedBlob,
131    DEFAULT_BLOB_HYDRATION_BYTES,
132};
133pub use build_info::{BuildInfo, BUILD_INFO, BUILD_VERSION};
134pub use config::{ann_fresh_tail_enabled_from_env, process_ref_from_env, WalCeilingSource};
135pub use cost_unit::{base_resource_payload, cost_unit_for_dispatch, resource_payload};
136pub use curation::{
137    entity_embedding_text, entity_fts_document, entity_merge_guard_compared_values,
138    entity_merge_guard_error, entity_merge_guard_refusal_message, note_embedding_text,
139    note_fts_document, validate_entity_merge_floor, ContentMergeStrategy, EdgeListFilter,
140    EdgePatch, EntityDedupMergePolicy, EntityMergeGuard, EntityPatch, GuardedNoteMerge,
141    MergeAssertion, MergeEdgeConflictPreimage, MergeEdgePreimage, MergeSummary,
142    MergeTxBudgetReport, MergeTxLimits, NoteMergeGuard, NotePatch, NoteUpdatePolicy,
143};
144#[cfg(unix)]
145pub use daemon::{acquire_recovery_lock, pid_path, run_daemon, socket_path, DaemonDispatch};
146pub use daemon::{
147    active_phase_names, background_task_count, background_task_names, daemon_shutdown_token,
148    recall_ledger_snapshot, register_active_phase, spawn_named_tracked_task, track_background_task,
149    track_named_background_task, track_recall_ledger_task, DaemonRequestFrame, DaemonResponseFrame,
150    PhaseGuard, PROTOCOL_VERSION, UNNAMED_BACKGROUND_TASK,
151};
152pub use email_message_id::{EmailMessageIdDomains, HISTORICAL_DOMAINS_ENV};
153pub use embedder_registry::{EmbedderProvider, EmbedderRegistry, LatticeEmbedderProvider};
154pub use embedding::{EmbeddingModelRecord, EmbeddingModelStatus};
155pub use embedding_reranker::{EmbeddingCosineReranker, EmbeddingRerankHit};
156pub use engine_config::{
157    config_from_env, resolve_wal_ceiling, BackendConfig, BackendKind, BlobConfig,
158    BrainSectionConfig, ConfigError, EngineConfig, GateSectionConfig, GitWriteEntryConfig,
159    GitWriteSectionConfig, KhiveConfig, PackConfig, ResolvedWalCeiling, StorageSectionConfig,
160};
161pub use error::{
162    fts_text_leg_or_err, AdmissionFailureContext, AuditObligationFailure, AuditObligationReason,
163    ChannelIngestFailureClass, DenialAuditOutcome, DenialReceipt, DispatchError, DomainDisposition,
164    GuardedWriteFailure, ReceiptRefusal, RefusalEventContext, RefusalEventRecording,
165    RefusalRecordingErrorClass, RuntimeError, RuntimeResult, WriterPoolCheckoutTimeoutContext,
166    WriterTaskFailureContext, SQLITE_WAL_CAPACITY_REFUSED_STAGE,
167    SQLITE_WAL_CAPACITY_UNAVAILABLE_STAGE, WRITER_ADMISSION_SCOPE,
168    WRITER_POOL_CHECKOUT_TIMEOUT_STAGE, WRITER_QUEUE_SATURATED_STAGE,
169    WRITER_TASK_REQUEST_FAILED_STAGE, WRITER_TASK_TERMINATED_STAGE,
170};
171pub use error_projection::runtime_error_value;
172pub use event_actor_scope::{resolve_event_actor_read_scope, EventActorReadScope};
173pub use event_cursor_walk::{visit_events_cursor_walk, EventCursorWalkError};
174pub use event_page::{
175    page_budget_exceeded_error, row_exceeds_budget_error, EventReadPageRequest, EventReadPageResult,
176};
177pub use event_store_guard::EventAttribution;
178pub use fusion::FusionStrategy;
179pub use graph_traversal::PathNode;
180pub use kg_read::KgNeighborRead;
181pub use khive_db::env::{env_flag, env_parse_or};
182pub use khive_db::{
183    checkpoint_once, run_checkpoint_task, run_migrations, stores::event::event_insert_statements,
184    CheckpointConfig, CheckpointLifecycleOwner, CheckpointTick, ConnectionPool, StorageBackend,
185};
186pub use khive_gate::{
187    classify_operation, is_valid_mailbox_actor_label, split_stamped_label, ActorRef, AllowAllGate,
188    AuditDecision, AuditEvent, CallerEnrollmentGate, Gate, GateContext, GateDecision, GateError,
189    GateRef, GateRequest, MailboxPolicyError, MailboxReadGate, Obligation, OperationAccess,
190    CLASSIFIED_OPERATIONS, OPERATION_CLASSIFIER_VERSION, RUNTIME_STAMPED_ACTOR_KINDS,
191};
192pub use khive_storage::types::TraversalOptions;
193pub use khive_storage::{EventObservation, EventView, ObservationRole, ReferentKind};
194pub use khive_types::namespace::Namespace;
195pub use mailbox_view::MailboxView;
196pub use note_create::{effective_create_tags, EffectiveCreateTags};
197pub use objectives::{
198    AmplifiedDecayAwareSalienceObjective, DecayAwareSalienceObjective, GraphProximityObjective,
199    MemoryRecallPipeline, NoteCandidate, RerankerObjective, RetrievalCandidate, RrfFusionObjective,
200    TemporalRecencyObjective, TextRelevanceObjective, VectorSimilarityObjective,
201};
202#[cfg(any(test, feature = "fault-injection"))]
203pub use operations::{
204    arm_entity_compensation_fail_scoped, arm_fts_fail_many_partial_scoped,
205    arm_fts_fail_many_scoped, arm_fts_fail_scoped, arm_prefix_resolve_fail_scoped,
206    arm_rollback_cleanup_fail, arm_vector_fail_after, arm_vector_fail_scoped, FaultInjectionArm,
207};
208pub use operations::{
209    base_entity_endpoint_rules, base_entity_rule_allows, endpoint_matches,
210    hex_prefix_to_uuid_pattern, merge_entry_metadata, uuid_prefix_bounds, ConditionalInsertStage,
211    EdgeEndpointKind, EntityCreateSpec, LinkSpec, NoteCreateSpec, NoteSearchHit, NoteSearchOutcome,
212    PostCommitDegradation, PrefixScope, QueryResult, Resolved,
213};
214pub use pack::{
215    resolve_explicit_namespace, ChannelIngestCapability, DispatchHook, HandlerDef,
216    IdResolutionMode, IngestAuditStore, InterceptedDispatchResult, KindHook, NoteEmbeddingPolicy,
217    NoteEmbeddingPolicySpec, NoteKindSpec, NoteLifecycleSpec, NoteUpdateEffect, PackByIdResolver,
218    PackFactory, PackInstall, PackLoadError, PackMetadataRegistry, PackRegistration, PackRegistry,
219    PackRuntime, PackSchemaCollisionError, PackSchemaPlan, ParamDef, RequestIdentity, SchemaPlan,
220    VerbCategory, VerbPresentationPolicy, VerbRegistry, VerbRegistryBuilder, VerifiedActor,
221    Visibility, AUDIT_PERSISTENCE_SKIPPED_READ_ONLY,
222};
223pub use params::deser_params;
224pub use phase_events::{emit_phase_event, is_benign_shutdown_cancellation};
225pub use portability::{ImportSummary, KgArchive};
226pub use preference_verification::{LegacyPreferenceVerifier, VerifiedModelNetworkAttachment};
227pub use presentation::{
228    apply_redundancy_drop, micros_to_iso, prepare_format_value, present, present_with_policy,
229    render_format, rfc3339_to_utc_micros, OutputFormat, PresentationMode, RedundancyScope,
230};
231pub use reference_resolution::{
232    resolve_reference, resolve_reference_with_entity_type, ReferenceCandidate, ReferenceResolution,
233};
234pub use reference_ring::{ReferenceRing, RingEntry};
235pub use registry::{ObjectiveRegistry, RegisteredObjective};
236pub use resource::{cpu_delta_us, process_resource_usage, ProcessResourceUsage};
237pub use retrieval::{HybridSearchOutcome, RankScoreKind, SearchHit, SearchSignals, SearchSource};
238pub use runtime::{
239    assert_captured_db_anchor_consistent, assert_db_anchor_consistent, expand_tilde,
240    parse_pack_list, resolve_db_anchor, resolve_project_actor_id, runtime_config_from_khive_config,
241    BackendId, EntityTypeValidatorFn, KhiveRuntime, NamedVectorIdentity, NamespaceToken,
242    NoteMutationHookFn, NoteWriteValidatorFn, OpenedDiagnosticBackend, RuntimeConfig,
243};
244pub use secret_gate::SecretMatch;
245pub use secret_gate_finalizer::{
246    EntityCandidateAdmission, EntityCandidateContext, EntityCandidateMutation,
247    EntityCandidateOrigin, EntityCandidatePrepared, EntityFinalizationPlan,
248};
249pub use telemetry_config::{
250    TelemetryCarrier, TelemetryChannelConfig, TelemetryConfig, TelemetryFailurePosture,
251    TelemetryPolicy,
252};
253pub use validation::{
254    GraphPatch, GraphSnapshot, RuleFn, RuleId, Severity, ValidationContext, ValidationReport,
255    ValidationRule, Violation,
256};
257
258#[cfg(test)]
259mod mount_config_tests;
260
261pub mod mount_config;
262
263pub mod mounted_verb;