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