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