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