Skip to main content

khive_db/
lib.rs

1//! SQLite storage backend for the khive knowledge graph runtime.
2//!
3//! Provides entity, note, event, edge, FTS5 text search, and optional
4//! `sqlite-vec` vector storage over a WAL-mode connection pool.
5//!
6//! # Terminal write settlement
7//! Pooled, standalone, and lifetime write owners retain their volume lease
8//! through rollback or successful owned connection close. If a retired
9//! connection remains outside autocommit and close also fails, cleanup reports
10//! the path, volume, rollback and close errors, returns a terminal
11//! outcome-unknown error, and poisons the pool so it refuses every later write
12//! and releases the lease. The process keeps running: the host decides whether
13//! to exit.
14
15/// Transaction-scoped persistence for shared authority records.
16pub mod authority;
17/// Concrete storage backend providing capability-trait factories.
18pub mod backend;
19/// Periodic WAL checkpoint task.
20pub mod checkpoint;
21// Kept internal while the code-map constructor and SQLite callback wiring land.
22#[allow(dead_code)]
23mod code_map_vfs;
24mod connection_settlement;
25/// Durable database owner identity paired with the opened physical file.
26pub mod database_owner_identity;
27/// Read-only-by-intent database-integrity and WAL/checkpoint diagnostics.
28pub mod diagnostics;
29/// Physical-volume identity and bounded cooperative SQLite admission lease.
30mod disk_guard;
31mod disk_guard_config;
32/// Environment readers with explicit parse/default and boolean policies.
33pub mod env;
34/// Error types for the SQLite layer.
35pub mod error;
36
37/// Bounded prune of expendable polling-dispatch audit rows (ADR-212 §4, operator maintenance).
38pub mod events_prune;
39#[cfg(test)]
40mod events_prune_tests;
41/// SQLite extension registration (sqlite-vec auto-extension).
42pub mod extension;
43/// Physical file identity shared by pool admission and backend alias routing.
44#[cfg(any(unix, windows))]
45pub mod file_identity;
46mod fts_maintenance;
47/// Read predicates and transaction assertions for the graph-lint caller.
48pub mod graph_lint;
49/// Canonical physical store sets for cooperative maintenance metadata.
50#[cfg(unix)]
51pub mod maintenance;
52/// Schema migration system (versioned migrations).
53pub mod migrations;
54/// What a live store's schema says about `namespace` (ADR-189).
55pub mod namespace_census;
56/// Moving records between namespaces (ADR-189).
57pub mod namespace_move;
58/// A store fixture reproducing the namespace split, for the move's own arms.
59#[cfg(any(test, feature = "test-support"))]
60pub mod namespace_move_fixture;
61/// Feature-gated namespace-bounded FTS5 trigram prototype.
62#[cfg(feature = "namespace-trigram-proto")]
63pub mod namespace_trigram_proto;
64/// Durable deferred entity-index obligations (ADR-014 Amendment 7).
65pub mod pending_index;
66/// WAL-mode connection pool: one writer, N concurrent readers.
67pub mod pool;
68mod progress_conn;
69#[cfg(any(test, feature = "test-support"))]
70pub mod test_hooks;
71pub use progress_conn::ProgressConn;
72mod read_cancellation;
73/// `SqlAccess` trait bridge to `ConnectionPool`.
74pub mod sql_bridge;
75/// Pure statement-list builders for caller-owned SQL execution.
76pub mod statement_lists;
77#[cfg(any(test, feature = "test-support"))]
78mod statement_observer;
79/// Per-substrate store implementations (entity, note, graph, event, text, vectors, sparse).
80pub mod stores;
81/// Append-only NDJSON writer-timeout event sink (crate-internal).
82mod timeout_sink;
83/// Metadata-only copy-size estimate for guarded VACUUM admission.
84mod vacuum_capacity;
85/// Cross-process WAL-pin attribution sidecar (ADR-091 Amendment 2 Plank B).
86/// The sidecar write path (heartbeat/beacon) and identity primitives are
87/// portable; directory collection (`enumerate_live`/`housekeep_live`) is
88/// Unix-only — its only caller is the daemon's checkpoint task, and daemon
89/// mode itself requires Unix (see `khive-mcp/src/serve.rs`).
90pub mod walpin;
91/// Single-writer task and bounded write queue (ADR-067 Component A).
92mod writer_admission_metrics;
93pub mod writer_task;
94
95#[cfg(test)]
96mod writer_busy_fixture;
97
98#[cfg(test)]
99mod test_process;
100
101#[cfg(test)]
102mod lease_latency_tests;
103
104pub use backend::StorageBackend;
105pub use checkpoint::{
106    checkpoint_once, run_checkpoint_task, CheckpointConfig, CheckpointLifecycleOwner,
107    CheckpointTick,
108};
109pub use checkpoint::{run_session_sweep_task, SessionSweepConfig, SweepBackend};
110pub use database_owner_identity::{DatabaseOwnerIdentity, DatabaseOwnerIdentityError};
111pub use disk_guard::harness_scoped_process_leases;
112pub use disk_guard_config::{
113    default_volume_lock_dir, require_volume_lock_dir, resolve_disk_guard_config,
114    DiskGuardConfigSource, DiskGuardEnvironment, EffectiveDiskGuardConfig,
115};
116pub use error::{
117    SqliteError, SQLITE_WAL_CAPACITY_REFUSED_STAGE, SQLITE_WAL_CAPACITY_UNAVAILABLE_STAGE,
118};
119pub use fts_maintenance::{
120    fts_maintenance_counters, FtsIndexStructure, FtsLevelStructure, FtsMaintenanceCounters,
121    FtsSegmentDiagnostics,
122};
123pub use khive_storage::{
124    await_request_read_phase, effective_request_read_deadline, ensure_request_read_active,
125    inherit_request_read_cancellation, inherit_request_read_context, request_read_is_cancelled,
126    request_read_timeout_from_env, scope_request_read_cancellation, scope_request_read_deadline,
127    scope_request_read_deadline_at, wait_for_request_read_cancellation, RequestReadDeadline,
128    DEFAULT_REQUEST_READ_TIMEOUT_SECS,
129};
130pub use migrations::{
131    inspect_integrity, inspect_page_accounting, inspect_schema_is_current, inspect_schema_version,
132    query_embedding_models, read_schema_version, run_migrations, run_migrations_with_policy,
133    EmbeddingModelRegistryRecord, Migration, MigrationWritePolicy, PageAccounting,
134    ServiceSchemaPlan, VersionedMigration, MIGRATIONS,
135};
136pub use pool::{
137    CheckpointGuard, CheckpointResult, ConnectionPool, PoolConfig, ReaderGuard, ReaderRow,
138    StandaloneCheckpoint, WalCeilingPolicy, WalCeilingSource, WriterGuard,
139};
140#[cfg(any(test, feature = "test-support"))]
141pub use read_cancellation::scope_test_read_progress;
142pub use read_cancellation::{sqlite_interrupt_grace_from_env, DEFAULT_SQLITE_INTERRUPT_GRACE_MS};
143pub use sql_bridge::SqlBridge;
144#[cfg(any(test, feature = "test-support"))]
145pub use statement_observer::{StartedStatement, StatementStartObservation};
146pub use writer_task::WriterTaskHandle;
147
148#[cfg(test)]
149mod namespace_move_fixture_tests;
150#[cfg(test)]
151mod stream_schema_tests;
152
153#[cfg(test)]
154mod reader_lease_tests;
155
156#[cfg(test)]
157mod raw_sql_reader_admission_tests;