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