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