Skip to content

Commit ac2b1e6

Browse files
Contain the engine behind one module
Issue #18 §C1. Eighty-three files named the `tinycortex` crate, in two hundred and ninety-six places. That made the engine's shape an ambient fact of the whole crate rather than a dependency anyone had chosen, and made "what would a second engine have to provide?" a question nobody could answer without reading all of them. Every one now goes through `core/src/engine/backend.rs`, which re-exports the engine's memory surface and is the only file outside the seam that names it. Outside `core/src/engine/`, references to the crate are zero. Re-exporting rather than wrapping is deliberate. A wrapper over three hundred call sites would be a second surface to keep in step with the first, which is the failure §A1 had just finished deleting. What this buys is not insulation — the call sites use the engine's API verbatim — but a single enumerable place that names it. The seam is `engine`, not `tinycortex`. §C1's text says `core/src/tinycortex/`, but its own acceptance criterion asks that `grep -rl tinycortex core/src` match only files under that module, and those two cannot both hold: with the module named after the engine, every call site reads `crate::tinycortex::…` and matches. Naming the seam for its role rather than for one engine satisfies the criterion and is the better name regardless — a seam named after the thing it is meant to make replaceable is the coupling this section removes. The module was `pub` but had no consumer outside this crate, so the rename breaks nothing. The workspace root and the module crate each gain a `[patch]` for the contract's git dependency. Patch tables apply only from the root being built, and the module crate is its own root; without its own entry cargo resolves the git copy alongside the path copy and `MemoryTaint` from one is not the same type as from the other. Found by the compiler, not predicted. What is left matching `tinycortex` outside the seam is 82 log-message strings and a `tinycortex_kv` accessor name. Neither is a crate reference, and renaming the accessor is cosmetic churn §C1 does not ask for. Two stale doc comments describing a "thirteen-family `tinycortex_api` contract" are corrected — since §A1 the contract is `tinymemory-api`, and it has eighteen families. Acceptance, measured: 83 files naming the engine crate outside the seam, now 0. Refs #18 (§C1)
1 parent 2721f4c commit ac2b1e6

108 files changed

Lines changed: 500 additions & 406 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/conversations/blocking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Async wrappers that run the conversation store's **blocking** operations on
22
//! tokio's blocking pool (#5156).
33
//!
4-
//! Every `tinycortex::memory::conversations` entry point is synchronous, and
4+
//! Every `crate::engine::backend::conversations` entry point is synchronous, and
55
//! each one takes the process-global `CONVERSATION_STORE_LOCK` — a
66
//! `parking_lot::Mutex` — and then does fsync'd JSONL file IO while holding it.
77
//! Calling one directly from an `async fn` therefore parks a tokio **worker**
@@ -35,9 +35,9 @@
3535
3636
use std::path::PathBuf;
3737

38-
use tinycortex::memory::conversations as store;
38+
use crate::engine::backend::conversations as store;
3939

40-
use tinycortex::memory::conversations::{
40+
use crate::engine::backend::conversations::{
4141
ConversationMessage, ConversationMessagePatch, ConversationPurgeStats, ConversationStore,
4242
ConversationThread, CreateConversationThread, CrossThreadHit,
4343
};

core/src/conversations/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! append-only in `threads.jsonl`; each thread's messages in a dedicated JSONL
55
//! file). The store / inverted-index / tokenizer / types engine is the crate's
66
//! (a byte-identical port, incl. the D1 rank-before-materialize fix), and
7-
//! consumers name `tinycortex::memory::conversations` directly — this module no
7+
//! consumers name `crate::engine::backend::conversations` directly — this module no
88
//! longer re-exports that surface under a second path.
99
//!
1010
//! Host-retained:

core/src/diff/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
//! the ledger is a derived view used purely for change tracking.
1515
//!
1616
//! W7: the snapshot/diff/checkpoint/ledger engine is now
17-
//! `tinycortex::memory::diff::DiffEngine` (a byte-identical port over the same
17+
//! `crate::engine::backend::diff::DiffEngine` (a byte-identical port over the same
1818
//! `<workspace>/memory_diff/repo` git layout). This module is a thin host shim:
1919
//! [`ops`] async-wraps the engine, [`source`] supplies the chunk-store item
2020
//! seam (`DiffEngine`'s `SnapshotItemSource`), and `rpc`/`schemas`/`tools`
2121
//! keep the RPC + agent surface. The wire types are the crate's, named directly
22-
//! (`tinycortex::memory::diff::types`) rather than through a host re-export
22+
//! (`crate::engine::backend::diff::types`) rather than through a host re-export
2323
//! module.
2424
//!
2525
//! Features:
@@ -65,7 +65,7 @@ pub mod source;
6565
// `memory::diff::{types, source}` are serde-only wire types and stay compiled;
6666
// only the git-touching `ledger`/`DiffEngine` half sits behind `git-diff`. A
6767
// stub copy would be a second definition of one serde shape, free to drift.
68-
pub use tinycortex::memory::diff::types::{
68+
pub use crate::engine::backend::diff::types::{
6969
ChangeKind, Checkpoint, CrossSourceDiff, DiffResult, DiffSummary, ItemChange, Snapshot,
7070
SnapshotTrigger,
7171
};

core/src/diff/ops.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Business logic for memory diff — thin host async wrappers over
2-
//! `tinycortex::memory::diff::DiffEngine` (W7).
2+
//! `crate::engine::backend::diff::DiffEngine` (W7).
33
//!
44
//! The snapshot/diff/checkpoint/ledger engine is the crate's; the git ledger it
55
//! writes lives at the same `<workspace>/memory_diff/repo` path with the same
@@ -16,10 +16,10 @@ use tinymemory_api::host::test_support::TestHostConfig;
1616
use crate::sources::types::MemorySourceEntry;
1717
use crate::Config;
1818

19-
use tinycortex::memory::diff::{DiffEngine, SourceDescriptor};
19+
use crate::engine::backend::diff::{DiffEngine, SourceDescriptor};
2020

2121
use super::source::ChunkStoreItemSource;
22-
use tinycortex::memory::diff::types::*;
22+
use crate::engine::backend::diff::types::*;
2323

2424
/// A crate [`SourceDescriptor`] from a host source entry.
2525
fn descriptor(source: &MemorySourceEntry) -> SourceDescriptor {
@@ -101,7 +101,7 @@ pub async fn list_snapshots(
101101
let source_id = source_id.map(str::to_string);
102102

103103
tokio::task::spawn_blocking(move || -> anyhow::Result<Vec<Snapshot>> {
104-
let ledger = tinycortex::memory::diff::Ledger::open(&workspace_dir)?;
104+
let ledger = crate::engine::backend::diff::Ledger::open(&workspace_dir)?;
105105
ledger.list_snapshots(source_id.as_deref(), limit)
106106
})
107107
.await
@@ -310,7 +310,7 @@ pub async fn cleanup(config: &Config, older_than_days: u32) -> Result<u64, Strin
310310
#[cfg(test)]
311311
mod tests {
312312
use super::*;
313-
use tinycortex::memory::diff::{Ledger, SnapshotMeta};
313+
use crate::engine::backend::diff::{Ledger, SnapshotMeta};
314314

315315
fn test_config() -> TestHostConfig {
316316
crate::test_seams::init();

core/src/diff/source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The host implementation of the crate diff engine's chunk-source seam.
22
//!
3-
//! `tinycortex::memory::diff::DiffEngine` is generic over a
3+
//! `crate::engine::backend::diff::DiffEngine` is generic over a
44
//! [`SnapshotItemSource`]: during
55
//! `take_snapshot` (directly, and transitively from `create_checkpoint` for any
66
//! source lacking a baseline) it asks the source for a source's already-ingested
@@ -22,7 +22,7 @@
2222
use std::collections::HashMap;
2323
use std::sync::Arc;
2424

25-
use tinycortex::memory::diff::{extract_item_id, SnapshotItem, SnapshotItemSource};
25+
use crate::engine::backend::diff::{extract_item_id, SnapshotItem, SnapshotItemSource};
2626

2727
#[cfg(test)]
2828
use tinymemory_api::host::test_support::TestHostConfig;

core/src/diff/stub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use crate::sources::types::MemorySourceEntry;
2727
use crate::Config;
2828

29-
use tinycortex::memory::diff::types::{Checkpoint, CrossSourceDiff, Snapshot};
29+
use crate::engine::backend::diff::types::{Checkpoint, CrossSourceDiff, Snapshot};
3030

3131
/// The message every disabled entry point returns.
3232
///

core/src/engine/backend.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//! The engine's own memory surface, reached through one door.
2+
//!
3+
//! Issue #18 §C1 asks that nothing outside this module name the `tinycortex`
4+
//! crate. Eighty-three files did, in two hundred and ninety-six places, which
5+
//! made the engine's shape an ambient fact of the whole crate rather than a
6+
//! dependency anyone had chosen — and made "what would a second engine have to
7+
//! provide?" a question no one could answer without reading all of them.
8+
//!
9+
//! Re-exporting rather than wrapping is deliberate. A wrapper layer over three
10+
//! hundred call sites would be a second surface to keep in step with the first,
11+
//! which is the failure §A1 had just finished deleting. What this buys is not
12+
//! insulation from the engine's API — the call sites still use it verbatim —
13+
//! but a single place that *names* it, so the coupling is enumerable: this file
14+
//! is the list of everything `tinymemory-core` needs an engine to provide.
15+
//!
16+
//! # Why this is not `MemoryProvider`
17+
//!
18+
//! §A3 proposes routing these call sites through `&dyn MemoryProvider` instead.
19+
//! That is not possible, and the reason is worth recording where the next
20+
//! reader will find it. Core does not *consume* the engine's memory API; it
21+
//! shares the engine's SQLite database. Thirty-four files here hold a
22+
//! `rusqlite::Transaction` or a `Connection`, and the entry points they call
23+
//! take them:
24+
//!
25+
//! ```text
26+
//! upsert_buffer_tx(tx: &Transaction<'_>, buf: &Buffer) -> Result<()>
27+
//! shared_connection(config: &MemoryConfig) -> Result<Arc<PMutex<Connection>>>
28+
//! ```
29+
//!
30+
//! Serving those through the contract would put `rusqlite` in
31+
//! `tinymemory-api`, which its own manifest forbids and CI now enforces. The
32+
//! honest description is that core and the engine co-implement one store, and
33+
//! separating them is a decomposition rather than a routing change.
34+
//!
35+
//! Nested under a module rather than re-exported flat because the seam already
36+
//! has its own `ingest` and `sync` modules, which are host-side pieces and
37+
//! not the engine's.
38+
39+
// The engine's submodules.
40+
pub use tinycortex::memory::{
41+
archivist, chunks, conversations, diff, graph, health, ingest, people, queue, retrieval, score,
42+
sources, store, sync, tool_memory, tree, types,
43+
};
44+
45+
// …and the items it re-exports at its own top level, which call sites reach for
46+
// by the same short paths. Listed rather than globbed so this file stays the
47+
// enumerable answer to "what does core need an engine to provide".
48+
pub use tinycortex::memory::{
49+
GraphRelationRecord, InMemoryMemoryStore, MemoryCategory, MemoryConfig, MemoryEngineError,
50+
MemoryEngineResult, MemoryEntry, MemoryId, MemoryInput, MemoryItemKind, MemoryKvRecord,
51+
MemoryQuery, MemoryRecord, MemoryResult, MemoryStore, MemoryTaint, NamespaceDocumentInput,
52+
NamespaceMemoryHit, NamespaceQueryResult, NamespaceRetrievalContext, NamespaceSummary,
53+
RecallOpts, RetrievalScoreBreakdown, SearchHit, StoreError, StoredMemoryDocument,
54+
WeightProfile, GLOBAL_NAMESPACE,
55+
};
56+
57+
// The storage trait itself. Since §A2 this is the contract's trait, not the
58+
// engine's — the engine re-exports the same one.
59+
pub use tinycortex::memory::Memory;

0 commit comments

Comments
 (0)