Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

The store of one checkout: the one place reasoning records are read from and written to.

It is a handle on a repository root and nothing more; constructing one touches no file. Records live under STATE_DIR, one directory per task and one JSON file per record.

use majordomus_cli::reasoning::store::{Store, STATE_DIR};

let dir = tempfile::tempdir().unwrap();
let store = Store::at(dir.path());
assert_eq!(store.dir(), dir.path().join(STATE_DIR));
assert!(store.load().records.is_empty(), "an absent store reads as empty");

Implementations§

Source§

impl Store

Source

pub fn at(root: &Path) -> Self

The store of the repository at root.

Nothing is read or created until the store is loaded or written.

use majordomus_cli::reasoning::store::Store;

let dir = tempfile::tempdir().unwrap();
let store = Store::at(dir.path());
assert!(store.dir().starts_with(dir.path()));
assert!(!store.dir().exists());
Source

pub fn dir(&self) -> PathBuf

The directory the records live in: STATE_DIR under the repository root.

use std::path::Path;
use majordomus_cli::reasoning::store::Store;

let store = Store::at(Path::new("/repo"));
assert_eq!(store.dir(), Path::new("/repo/.ai/local/state/reasoning"));
Source

pub fn current_task(&self) -> String

The task open in this checkout, from .ai/local/state/current.yaml, or UNTASKED.

The task id is the id: line of that file, quotes trimmed. A missing file, a file with no such line, or an empty id all mean no task is open.

use majordomus_cli::reasoning::store::{Store, UNTASKED};

let dir = tempfile::tempdir().unwrap();
let store = Store::at(dir.path());
assert_eq!(store.current_task(), UNTASKED);

let state = dir.path().join(".ai/local/state");
std::fs::create_dir_all(&state).unwrap();
std::fs::write(state.join("current.yaml"), "id: \"task-42\"\n").unwrap();
assert_eq!(store.current_task(), "task-42");
Source

pub fn load(&self) -> Loaded

Every record of every task, in canonical order.

Only .json files are read, so a temporary file of a write in progress is never met. An absent store is an empty one; a file that does not parse is reported in Loaded::unreadable.

use majordomus_cli::reasoning::record::*;
use majordomus_cli::reasoning::store::Store;

let dir = tempfile::tempdir().unwrap();
let store = Store::at(dir.path());
for (id, at) in [("attempt-b", "2026-10-01T00:00:02Z"), ("attempt-a", "2026-10-01T00:00:01Z")] {
    store.write(&ReasoningRecord {
        schema: RECORD_SCHEMA.into(),
        version: RECORD_VERSION,
        id: id.into(),
        task: "t".into(),
        recorded_at: at.into(),
        head: None,
        redacted: vec![],
        body: ReasoningBody::Attempt(AttemptInput {
            assessment: None,
            attempt: "x".into(),
            observed_failure: "y".into(),
            assumption_invalidated: None,
            evidence: vec![],
            updated_hypothesis: None,
        }),
    })
    .unwrap();
}
let ids: Vec<String> = store.load().records.into_iter().map(|r| r.id).collect();
assert_eq!(ids, ["attempt-a", "attempt-b"], "ordered by when, not by name");
Source

pub fn write(&self, record: &ReasoningRecord) -> Result<PathBuf>

Make a record durable: temporary name, then rename. Returns its path.

The file is <task>/<id>.json under the store. A record whose file already exists is refused with AlreadyExists: a record is written once and never overwritten.

use majordomus_cli::reasoning::record::*;
use majordomus_cli::reasoning::store::Store;

let dir = tempfile::tempdir().unwrap();
let store = Store::at(dir.path());
let record = ReasoningRecord {
    schema: RECORD_SCHEMA.into(),
    version: RECORD_VERSION,
    id: "assessment-1".into(),
    task: "t".into(),
    recorded_at: "2026-10-01T00:00:01Z".into(),
    head: None,
    redacted: vec![],
    body: ReasoningBody::Assessment(AssessmentInput::default()),
};
let path = store.write(&record).unwrap();
assert_eq!(path, store.dir().join("t/assessment-1.json"));
let again = store.write(&record).unwrap_err();
assert_eq!(again.kind(), std::io::ErrorKind::AlreadyExists);

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more